SMIMESignedTestpublic class SMIMESignedTest extends TestCase
Fields Summary |
---|
static MimeBodyPart | msg | static MimeBodyPart | msgR | static MimeBodyPart | msgRN | static String | _origDN | static KeyPair | _origKP | static X509Certificate | _origCert | static String | _signDN | static KeyPair | _signKP | static X509Certificate | _signCert | static String | reciDN | static KeyPair | reciKP | static X509Certificate | reciCert | private static KeyPair | _signGostKP | private static X509Certificate | _signGostCert | private static KeyPair | _signEcDsaKP | private static X509Certificate | _signEcDsaCert | private static KeyPair | _signEcGostKP | private static X509Certificate | _signEcGostCert | KeyPair | dsaSignKP | X509Certificate | dsaSignCert | KeyPair | dsaOrigKP | X509Certificate | dsaOrigCert |
Constructors Summary |
---|
public SMIMESignedTest(String name)
super(name);
|
Methods Summary |
---|
private javax.mail.internet.MimeBodyPart | createMultipartMessage()
MimeBodyPart msg1 = new MimeBodyPart();
msg1.setText("Hello part 1!\n");
MimeBodyPart msg2 = new MimeBodyPart();
msg2.setText("Hello part 2!\n");
MimeMultipart mp = new MimeMultipart();
mp.addBodyPart(msg1);
mp.addBodyPart(msg2);
MimeBodyPart m = new MimeBodyPart();
m.setContent(mp);
return m;
| private javax.mail.internet.MimeBodyPart | createTemplate(java.lang.String contentType, java.lang.String contentTransferEncoding)
byte[] content = "<?xml version=\"1.0\"?>\n<INVOICE_CENTER>\n <CONTENT_FRAME>\n</CONTENT_FRAME>\n</INVOICE_CENTER>\n".getBytes("US-ASCII");
InternetHeaders ih = new InternetHeaders();
ih.setHeader("Content-Type", contentType);
ih.setHeader("Content-Transfer-Encoding", contentTransferEncoding);
return new MimeBodyPart(ih, content);
| private javax.mail.internet.MimeBodyPart | generateBinaryPart()
byte[] content = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 10, 10, 15, 16 };
InternetHeaders ih = new InternetHeaders();
ih.setHeader("Content-Transfer-Encoding", "binary");
return new MimeBodyPart(ih, content);
| private javax.mail.internet.MimeBodyPart | generateEncapsulatedRsa(java.lang.String digestOid, javax.mail.internet.MimeBodyPart msg)
List certList = new ArrayList();
certList.add(_signCert);
certList.add(_origCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), "BC");
ASN1EncodableVector signedAttrs = generateSignedAttributes();
SMIMESignedGenerator gen = new SMIMESignedGenerator();
gen.addSigner(_signKP.getPrivate(), _signCert, digestOid, new AttributeTable(signedAttrs), null);
gen.addCertificatesAndCRLs(certs);
return gen.generateEncapsulated(msg, "BC");
| private javax.mail.internet.MimeMultipart | generateMultiPartECGost(javax.mail.internet.MimeBodyPart msg)
List certList = new ArrayList();
certList.add(_signCert);
certList.add(_signEcGostCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), "BC");
SMIMESignedGenerator gen = new SMIMESignedGenerator();
gen.addSigner(_signEcGostKP.getPrivate(), _signEcGostCert, SMIMESignedGenerator.DIGEST_GOST3411);
gen.addCertificatesAndCRLs(certs);
return gen.generate(msg, "BC");
| private javax.mail.internet.MimeMultipart | generateMultiPartGost(javax.mail.internet.MimeBodyPart msg)
List certList = new ArrayList();
certList.add(_signCert);
certList.add(_signGostCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), "BC");
SMIMESignedGenerator gen = new SMIMESignedGenerator();
gen.addSigner(_signGostKP.getPrivate(), _signGostCert, SMIMESignedGenerator.DIGEST_GOST3411);
gen.addCertificatesAndCRLs(certs);
return gen.generate(msg, "BC");
| private javax.mail.internet.MimeMultipart | generateMultiPartRsa(java.lang.String digestOid, javax.mail.internet.MimeBodyPart msg, java.util.Date signingTime)
List certList = new ArrayList();
certList.add(_signCert);
certList.add(_origCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), "BC");
ASN1EncodableVector signedAttrs = generateSignedAttributes();
if (signingTime != null)
{
signedAttrs.add(new Attribute(CMSAttributes.signingTime, new DERSet(new Time(signingTime))));
}
SMIMESignedGenerator gen = new SMIMESignedGenerator();
gen.addSigner(_signKP.getPrivate(), _signCert, digestOid, new AttributeTable(signedAttrs), null);
gen.addCertificatesAndCRLs(certs);
return gen.generate(msg, "BC");
| private javax.mail.internet.MimeMultipart | generateMultiPartRsa(java.lang.String digestOid, javax.mail.internet.MimeBodyPart msg)
return generateMultiPartRsa(digestOid, msg, null);
| private org.bouncycastle.asn1.ASN1EncodableVector | generateSignedAttributes()
ASN1EncodableVector signedAttrs = new ASN1EncodableVector();
SMIMECapabilityVector caps = new SMIMECapabilityVector();
caps.addCapability(SMIMECapability.dES_EDE3_CBC);
caps.addCapability(SMIMECapability.rC2_CBC, 128);
caps.addCapability(SMIMECapability.dES_CBC);
signedAttrs.add(new SMIMECapabilitiesAttribute(caps));
return signedAttrs;
| private java.lang.String | getDigestOid(org.bouncycastle.cms.SignerInformationStore s)
return ((SignerInformation)s.getSigners().iterator().next()).getDigestAlgOID();
| private byte[] | getEncodedStream(javax.mail.internet.MimeMultipart smm)
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
smm.getBodyPart(1).writeTo(bOut);
return bOut.toByteArray();
| private java.lang.String | getMicAlg(javax.mail.internet.MimeMultipart mm)
String contentType = mm.getContentType();
String micAlg = contentType.substring(contentType.indexOf("micalg=") + 7);
return micAlg.substring(0, micAlg.indexOf(';"));
| private javax.mail.internet.MimeMessage | loadMessage(java.lang.String name)
Session session = Session.getDefaultInstance(System.getProperties(), null);
return new MimeMessage(session, getClass().getResourceAsStream(name));
| public static void | main(java.lang.String[] args)
junit.textui.TestRunner.run(SMIMESignedTest.class);
| public void | multipartMixedTest(javax.mail.internet.MimeBodyPart part1, javax.mail.internet.MimeBodyPart part2)
MimeMultipart mp = new MimeMultipart();
mp.addBodyPart(part1);
mp.addBodyPart(part2);
MimeBodyPart m = new MimeBodyPart();
m.setContent(mp);
MimeMultipart smm = generateMultiPartRsa(SMIMESignedGenerator.DIGEST_SHA1, m);
SMIMESigned s = new SMIMESigned(smm);
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
AttributeTable attr = ((SignerInformation)s.getSignerInfos().getSigners().iterator().next()).getSignedAttributes();
Attribute a = attr.get(CMSAttributes.messageDigest);
byte[] contentDigest = ASN1OctetString.getInstance(a.getAttrValues().getObjectAt(0)).getOctets();
mp = (MimeMultipart)m.getContent();
ContentType contentType = new ContentType(mp.getContentType());
String boundary = "--" + contentType.getParameter("boundary");
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
LineOutputStream lOut = new LineOutputStream(bOut);
Enumeration headers = m.getAllHeaderLines();
while (headers.hasMoreElements())
{
lOut.writeln((String)headers.nextElement());
}
lOut.writeln(); // CRLF separator
lOut.writeln(boundary);
writePart(mp.getBodyPart(0), bOut);
lOut.writeln(); // CRLF terminator
lOut.writeln(boundary);
writePart(mp.getBodyPart(1), bOut);
lOut.writeln();
lOut.writeln(boundary + "--");
MessageDigest dig = MessageDigest.getInstance("SHA1", "BC");
assertTrue(Arrays.equals(contentDigest, dig.digest(bOut.toByteArray())));
| public static junit.framework.Test | suite()
return new SMIMETestSetup(new TestSuite(SMIMESignedTest.class));
| public void | testBasicAS2()
MimeMessage message = loadMessage("basicAS2.message");
SMIMESigned s = new SMIMESigned((MimeMultipart)message.getContent());
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
| public void | testBasicAS2Parser()
MimeMessage message = loadMessage("basicAS2.message");
SMIMESignedParser s = new SMIMESignedParser((MimeMultipart)message.getContent());
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
| public void | testCertificateManagement()
List certList = new ArrayList();
certList.add(_signCert);
certList.add(_origCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), "BC");
SMIMESignedGenerator gen = new SMIMESignedGenerator();
gen.addCertificatesAndCRLs(certs);
MimeBodyPart smm = gen.generateCertificateManagement("BC");
SMIMESigned s = new SMIMESigned(smm);
certs = s.getCertificatesAndCRLs("Collection", "BC");
assertEquals(2, certs.getCertificates(null).size());
| public void | testEmbeddedMulti()
MimeMessage message = loadMessage("embeddedmulti.message");
SMIMESigned s = new SMIMESigned((MimeMultipart)message.getContent());
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
| public void | testEmbeddedMultiParser()
MimeMessage message = loadMessage("embeddedmulti.message");
SMIMESignedParser s = new SMIMESignedParser((MimeMultipart)message.getContent());
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
| public void | testGOST3411WithECGOST3410()
MimeMultipart smm = generateMultiPartECGost(msg);
SMIMESigned s = new SMIMESigned(smm);
assertEquals("gostr3411-94", getMicAlg(smm));
assertEquals(getDigestOid(s.getSignerInfos()), CryptoProObjectIdentifiers.gostR3411.getId());
verifyMessageBytes(msg, s.getContent());
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
| public void | testGOST3411WithGOST3410()
MimeMultipart smm = generateMultiPartGost(msg);
SMIMESigned s = new SMIMESigned(smm);
assertEquals("gostr3411-94", getMicAlg(smm));
assertEquals(getDigestOid(s.getSignerInfos()), CryptoProObjectIdentifiers.gostR3411.getId());
verifyMessageBytes(msg, s.getContent());
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
| public void | testHeaders()
MimeMultipart smm = generateMultiPartRsa(SMIMESignedGenerator.DIGEST_SHA1, msg);
BodyPart bp = smm.getBodyPart(1);
assertEquals("application/pkcs7-signature; name=smime.p7s; smime-type=signed-data", bp.getHeader("Content-Type")[0]);
assertEquals("attachment; filename=\"smime.p7s\"", bp.getHeader("Content-Disposition")[0]);
assertEquals("S/MIME Cryptographic Signature", bp.getHeader("Content-Description")[0]);
| public void | testHeadersEncapsulated()
List certList = new ArrayList();
certList.add(_signCert);
certList.add(_origCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), "BC");
ASN1EncodableVector signedAttrs = generateSignedAttributes();
SMIMESignedGenerator gen = new SMIMESignedGenerator();
gen.addSigner(_signKP.getPrivate(), _signCert, SMIMESignedGenerator.DIGEST_SHA1, new AttributeTable(signedAttrs), null);
gen.addCertificatesAndCRLs(certs);
MimeBodyPart res = gen.generateEncapsulated(msg, "BC");
assertEquals("application/pkcs7-mime; name=smime.p7m; smime-type=signed-data", res.getHeader("Content-Type")[0]);
assertEquals("attachment; filename=\"smime.p7m\"", res.getHeader("Content-Disposition")[0]);
assertEquals("S/MIME Cryptographic Signed Data", res.getHeader("Content-Description")[0]);
| public void | testMD5WithRSA()
MimeMultipart smm = generateMultiPartRsa(SMIMESignedGenerator.DIGEST_MD5, msg);
SMIMESigned s = new SMIMESigned(smm);
assertEquals("md5", getMicAlg(smm));
assertEquals(getDigestOid(s.getSignerInfos()), PKCSObjectIdentifiers.md5.toString());
verifyMessageBytes(msg, s.getContent());
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
| public void | testMimeMultipart()
MimeBodyPart m = createMultipartMessage();
List certList = new ArrayList();
certList.add(_signCert);
certList.add(_origCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), "BC");
ASN1EncodableVector signedAttrs = generateSignedAttributes();
SMIMESignedGenerator gen = new SMIMESignedGenerator("binary");
gen.addSigner(_signKP.getPrivate(), _signCert, SMIMESignedGenerator.DIGEST_SHA1, new AttributeTable(signedAttrs), null);
gen.addCertificatesAndCRLs(certs);
MimeMultipart mm = gen.generate(m, "BC");
SMIMESigned s = new SMIMESigned(mm);
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
byte[] contentDigest = (byte[])gen.getGeneratedDigests().get(SMIMESignedGenerator.DIGEST_SHA1);
AttributeTable table = ((SignerInformation)s.getSignerInfos().getSigners().iterator().next()).getSignedAttributes();
Attribute hash = table.get(CMSAttributes.messageDigest);
assertTrue(MessageDigest.isEqual(contentDigest, ((ASN1OctetString)hash.getAttrValues().getObjectAt(0)).getOctets()));
| public void | testMimeMultipartBinaryParser()
MimeBodyPart m = createMultipartMessage();
List certList = new ArrayList();
certList.add(_signCert);
certList.add(_origCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), "BC");
ASN1EncodableVector signedAttrs = generateSignedAttributes();
SMIMESignedGenerator gen = new SMIMESignedGenerator("binary");
gen.addSigner(_signKP.getPrivate(), _signCert, SMIMESignedGenerator.DIGEST_SHA1, new AttributeTable(signedAttrs), null);
gen.addCertificatesAndCRLs(certs);
MimeMultipart mm = gen.generate(m, "BC");
SMIMESignedParser s = new SMIMESignedParser(mm, "binary");
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
| public void | testMimeMultipartBinaryParserGetMimeContent()
MimeBodyPart m = createMultipartMessage();
List certList = new ArrayList();
certList.add(_signCert);
certList.add(_origCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), "BC");
ASN1EncodableVector signedAttrs = generateSignedAttributes();
SMIMESignedGenerator gen = new SMIMESignedGenerator("binary");
gen.addSigner(_signKP.getPrivate(), _signCert, SMIMESignedGenerator.DIGEST_SHA1, new AttributeTable(signedAttrs), null);
gen.addCertificatesAndCRLs(certs);
MimeMultipart mm = gen.generate(m, "BC");
SMIMESignedParser s = new SMIMESignedParser(mm, "binary");
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
MimeMessage bp = s.getContentAsMimeMessage(Session.getDefaultInstance(new Properties()));
| public void | testMimeMultipartBinaryReader()
MimeBodyPart m = createMultipartMessage();
List certList = new ArrayList();
certList.add(_signCert);
certList.add(_origCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), "BC");
ASN1EncodableVector signedAttrs = generateSignedAttributes();
SMIMESignedGenerator gen = new SMIMESignedGenerator("binary");
gen.addSigner(_signKP.getPrivate(), _signCert, SMIMESignedGenerator.DIGEST_SHA1, new AttributeTable(signedAttrs), null);
gen.addCertificatesAndCRLs(certs);
MimeMultipart mm = gen.generate(m, "BC");
SMIMESigned s = new SMIMESigned(mm, "binary");
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
| public void | testMultiAlternative()
MimeMessage message = loadMessage("multi-alternative.eml");
SMIMESigned s = new SMIMESigned((MimeMultipart)message.getContent());
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
| public void | testMultiAlternativeParser()
MimeMessage message = loadMessage("multi-alternative.eml");
SMIMESignedParser s = new SMIMESignedParser((MimeMultipart)message.getContent());
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
| public void | testMultipartBinaryBinary()
MimeBodyPart part1 = createTemplate("text/xml", "binary");
MimeBodyPart part2 = createTemplate("text/html", "binary");
multipartMixedTest(part1, part2);
| public void | testMultipartBinaryText()
MimeBodyPart part1 = createTemplate("text/xml", "binary");
MimeBodyPart part2 = createTemplate("text/html", "7bit");
multipartMixedTest(part1, part2);
| public void | testMultipartTextBinary()
MimeBodyPart part1 = createTemplate("text/html", "7bit");
MimeBodyPart part2 = createTemplate("text/xml", "binary");
multipartMixedTest(part1, part2);
| public void | testMultipartTextText()
MimeBodyPart part1 = createTemplate("text/html", "7bit");
MimeBodyPart part2 = createTemplate("text/xml", "7bit");
multipartMixedTest(part1, part2);
| public void | testQuotable()
MimeMessage message = loadMessage("quotable.message");
SMIMESigned s = new SMIMESigned((MimeMultipart)message.getContent());
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
| public void | testQuotableParser()
MimeMessage message = loadMessage("quotable.message");
SMIMESignedParser s = new SMIMESignedParser((MimeMultipart)message.getContent());
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
| public void | testRIPEMD160WithRSA()
MimeMultipart smm = generateMultiPartRsa(SMIMESignedGenerator.DIGEST_RIPEMD160, msg);
SMIMESigned s = new SMIMESigned(smm);
assertEquals("unknown", getMicAlg(smm));
assertEquals(getDigestOid(s.getSignerInfos()), TeleTrusTObjectIdentifiers.ripemd160.toString());
verifyMessageBytes(msg, s.getContent());
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
| public void | testSHA1WithRSA()
MimeMultipart smm = generateMultiPartRsa(SMIMESignedGenerator.DIGEST_SHA1, msg);
SMIMESigned s = new SMIMESigned(smm);
verifyMessageBytes(msg, s.getContent());
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
| public void | testSHA1WithRSAAddSigners()
MimeMultipart smm = generateMultiPartRsa(SMIMESignedGenerator.DIGEST_SHA1, msg);
SMIMESigned s = new SMIMESigned(smm);
List certList = new ArrayList();
certList.add(_signCert);
certList.add(_origCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), "BC");
SMIMESignedGenerator gen = new SMIMESignedGenerator();
gen.addSigners(s.getSignerInfos());
gen.addCertificatesAndCRLs(certs);
SMIMESigned newS = new SMIMESigned(gen.generate(msg, "BC"));
verifyMessageBytes(msg, newS.getContent());
verifySigners(newS.getCertificatesAndCRLs("Collection", "BC"), newS.getSignerInfos());
| public void | testSHA1WithRSACanonicalization()
Date testTime = new Date();
MimeMultipart smm = generateMultiPartRsa(SMIMESignedGenerator.DIGEST_SHA1, msg, testTime);
byte[] sig1 = getEncodedStream(smm);
smm = generateMultiPartRsa(SMIMESignedGenerator.DIGEST_SHA1, msgR, testTime);
byte[] sig2 = getEncodedStream(smm);
assertTrue(Arrays.equals(sig1, sig2));
smm = generateMultiPartRsa(SMIMESignedGenerator.DIGEST_SHA1, msgRN, testTime);
byte[] sig3 = getEncodedStream(smm);
assertTrue(Arrays.equals(sig1, sig3));
| public void | testSHA1WithRSAEncapsulated()
MimeBodyPart res = generateEncapsulatedRsa(SMIMESignedGenerator.DIGEST_SHA1, msg);
SMIMESigned s = new SMIMESigned(res);
verifyMessageBytes(msg, s.getContent());
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
| public void | testSHA1WithRSAEncapsulatedParser()
MimeBodyPart res = generateEncapsulatedRsa(SMIMESignedGenerator.DIGEST_SHA1, msg);
SMIMESignedParser s = new SMIMESignedParser(res);
FileBackedMimeBodyPart content = (FileBackedMimeBodyPart)s.getContent();
verifyMessageBytes(msg, content);
content.dispose();
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
s.close();
| public void | testSHA1WithRSAEncapsulatedParserAndFile()
File tmp = File.createTempFile("bcTest", ".mime");
MimeBodyPart res = generateEncapsulatedRsa(SMIMESignedGenerator.DIGEST_SHA1, msg);
SMIMESignedParser s = new SMIMESignedParser(res, tmp);
FileBackedMimeBodyPart content = (FileBackedMimeBodyPart)s.getContent();
verifyMessageBytes(msg, s.getContent());
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
assertTrue(tmp.exists());
s.close();
content.dispose();
assertFalse(tmp.exists());
| public void | testSHA1withDSA()
dsaSignKP = CMSTestUtil.makeDsaKeyPair();
dsaSignCert = CMSTestUtil.makeCertificate(dsaSignKP, _origDN, dsaSignKP, _origDN);
dsaOrigKP = CMSTestUtil.makeDsaKeyPair();
dsaOrigCert = CMSTestUtil.makeCertificate(dsaOrigKP, _signDN, dsaSignKP, _origDN);
List certList = new ArrayList();
certList.add(dsaOrigCert);
certList.add(dsaSignCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), "BC");
SMIMESignedGenerator gen = new SMIMESignedGenerator();
gen.addSigner(dsaOrigKP.getPrivate(), dsaOrigCert, SMIMESignedGenerator.DIGEST_SHA1);
gen.addCertificatesAndCRLs(certs);
MimeMultipart smm = gen.generate(msg, "BC");
SMIMESigned s = new SMIMESigned(smm);
verifyMessageBytes(msg, s.getContent());
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
| public void | testSHA224WithRSA()
MimeMultipart smm = generateMultiPartRsa(SMIMESignedGenerator.DIGEST_SHA224, msg);
SMIMESigned s = new SMIMESigned(smm);
assertEquals("sha224", getMicAlg(smm));
assertEquals(getDigestOid(s.getSignerInfos()), NISTObjectIdentifiers.id_sha224.toString());
verifyMessageBytes(msg, s.getContent());
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
| public void | testSHA224WithRSAParser()
MimeMultipart smm = generateMultiPartRsa(SMIMESignedGenerator.DIGEST_SHA224, msg);
SMIMESignedParser s = new SMIMESignedParser(smm);
CertStore certs = s.getCertificatesAndCRLs("Collection", "BC");
assertEquals(getDigestOid(s.getSignerInfos()), NISTObjectIdentifiers.id_sha224.toString());
verifyMessageBytes(msg, s.getContent());
verifySigners(certs, s.getSignerInfos());
| public void | testSHA224WithRSAParserEncryptedWithDES()
List certList = new ArrayList();
certList.add(_signCert);
certList.add(_origCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), "BC");
ASN1EncodableVector signedAttrs = generateSignedAttributes();
SMIMESignedGenerator gen = new SMIMESignedGenerator();
gen.addSigner(_signKP.getPrivate(), _signCert, SMIMESignedGenerator.DIGEST_SHA224, new AttributeTable(signedAttrs), null);
gen.addCertificatesAndCRLs(certs);
MimeMultipart smm = gen.generate(msg, "BC");
SMIMESignedParser s = new SMIMESignedParser(smm);
certs = s.getCertificatesAndCRLs("Collection", "BC");
assertEquals(getDigestOid(s.getSignerInfos()), NISTObjectIdentifiers.id_sha224.toString());
verifyMessageBytes(msg, s.getContent());
verifySigners(certs, s.getSignerInfos());
| public void | testSHA256WithRSA()
MimeMultipart smm = generateMultiPartRsa(SMIMESignedGenerator.DIGEST_SHA256, msg);
SMIMESigned s = new SMIMESigned(smm);
assertEquals("sha256", getMicAlg(smm));
assertEquals(getDigestOid(s.getSignerInfos()), NISTObjectIdentifiers.id_sha256.toString());
verifyMessageBytes(msg, s.getContent());
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
| public void | testSHA256WithRSABinary()
MimeBodyPart msg = generateBinaryPart();
MimeMultipart smm = generateMultiPartRsa(SMIMESignedGenerator.DIGEST_SHA256, msg);
SMIMESigned s = new SMIMESigned(smm);
verifyMessageBytes(msg, s.getContent());
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
| public void | testSHA256WithRSABinaryWithParser()
MimeBodyPart msg = generateBinaryPart();
MimeMultipart smm = generateMultiPartRsa(SMIMESignedGenerator.DIGEST_SHA256, msg);
SMIMESignedParser s = new SMIMESignedParser(smm);
verifyMessageBytes(msg, s.getContent());
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
| public void | testSHA384WithRSA()
MimeMultipart smm = generateMultiPartRsa(SMIMESignedGenerator.DIGEST_SHA384, msg);
SMIMESigned s = new SMIMESigned(smm);
assertEquals("sha384", getMicAlg(smm));
assertEquals(getDigestOid(s.getSignerInfos()), NISTObjectIdentifiers.id_sha384.toString());
verifyMessageBytes(msg, s.getContent());
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
| public void | testSHA512WithRSA()
MimeMultipart smm = generateMultiPartRsa(SMIMESignedGenerator.DIGEST_SHA512, msg);
SMIMESigned s = new SMIMESigned(smm);
assertEquals("sha512", getMicAlg(smm));
assertEquals(getDigestOid(s.getSignerInfos()), NISTObjectIdentifiers.id_sha512.toString());
verifyMessageBytes(msg, s.getContent());
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
| public void | testWithAttributeCertificate()
List certList = new ArrayList();
certList.add(_signCert);
certList.add(_origCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), "BC");
ASN1EncodableVector signedAttrs = generateSignedAttributes();
SMIMESignedGenerator gen = new SMIMESignedGenerator();
gen.addSigner(_signKP.getPrivate(), _signCert, SMIMESignedGenerator.DIGEST_SHA256, new AttributeTable(signedAttrs), null);
gen.addCertificatesAndCRLs(certs);
X509AttributeCertificate attrCert = CMSTestUtil.getAttributeCertificate();
X509Store store = X509Store.getInstance("AttributeCertificate/Collection",
new X509CollectionStoreParameters(Collections.singleton(attrCert)), "BC");
gen.addAttributeCertificates(store);
SMIMESigned s = new SMIMESigned(gen.generateEncapsulated(msg, "BC"));
verifyMessageBytes(msg, s.getContent());
verifySigners(s.getCertificatesAndCRLs("Collection", "BC"), s.getSignerInfos());
X509Store attrCerts = s.getAttributeCertificates("Collection", "BC");
assertTrue(attrCerts.getMatches(null).contains(attrCert));
| private void | verifyMessageBytes(javax.mail.internet.MimeBodyPart a, javax.mail.internet.MimeBodyPart b)
ByteArrayOutputStream bOut1 = new ByteArrayOutputStream();
a.writeTo(bOut1);
bOut1.close();
ByteArrayOutputStream bOut2 = new ByteArrayOutputStream();
b.writeTo(bOut2);
bOut2.close();
assertEquals(true, Arrays.equals(bOut1.toByteArray(), bOut2.toByteArray()));
| private void | verifySigners(java.security.cert.CertStore certs, org.bouncycastle.cms.SignerInformationStore signers)
Collection c = signers.getSigners();
Iterator it = c.iterator();
while (it.hasNext())
{
SignerInformation signer = (SignerInformation)it.next();
Collection certCollection = certs.getCertificates(signer.getSID());
Iterator certIt = certCollection.iterator();
X509Certificate cert = (X509Certificate)certIt.next();
assertEquals(true, signer.verify(cert, "BC"));
}
| private void | writePart(javax.mail.BodyPart part, java.io.ByteArrayOutputStream bOut)
if (part.getHeader("Content-Transfer-Encoding")[0].equals("binary"))
{
part.writeTo(bOut);
}
else
{
part.writeTo(new CRLFOutputStream(bOut));
}
|
|