static { try { msg = SMIMETestUtil.makeMimeBodyPart("Hello world!\n"); msgR = SMIMETestUtil.makeMimeBodyPart("Hello world!\r"); msgRN = SMIMETestUtil.makeMimeBodyPart("Hello world!\r\n"); _origDN = "O=Bouncy Castle, C=AU"; _origKP = CMSTestUtil.makeKeyPair(); _origCert = CMSTestUtil.makeCertificate(_origKP, _origDN, _origKP, _origDN); _signDN = "CN=Eric H. Echidna, [email protected], O=Bouncy Castle, C=AU"; _signKP = CMSTestUtil.makeKeyPair(); _signCert = CMSTestUtil.makeCertificate(_signKP, _signDN, _origKP, _origDN); _signGostKP = CMSTestUtil.makeGostKeyPair(); _signGostCert = CMSTestUtil.makeCertificate(_signGostKP, _signDN, _origKP, _origDN); _signEcDsaKP = CMSTestUtil.makeEcDsaKeyPair(); _signEcDsaCert = CMSTestUtil.makeCertificate(_signEcDsaKP, _signDN, _origKP, _origDN); _signEcGostKP = CMSTestUtil.makeEcGostKeyPair(); _signEcGostCert = CMSTestUtil.makeCertificate(_signEcGostKP, _signDN, _origKP, _origDN); } catch (Exception e) { throw new RuntimeException("problem setting up signed test class: " + e); } }
public void testIDEAEncrypted() throws Exception { if (isPresent("IDEA")) { MimeBodyPart msg = SMIMETestUtil.makeMimeBodyPart("WallaWallaWashington"); String algorithm = SMIMEEnvelopedGenerator.IDEA_CBC; verifyAlgorithm(algorithm, msg); } }
public SMIMECompressedTest(String name) throws Exception { super(name); msg = SMIMETestUtil.makeMimeBodyPart("Hello world!"); signDN = "O=Bouncy Castle, C=AU"; signKP = CMSTestUtil.makeKeyPair(); signCert = CMSTestUtil.makeCertificate(signKP, signDN, signKP, signDN); origDN = "CN=Eric H. Echidna, [email protected], O=Bouncy Castle, C=AU"; origKP = CMSTestUtil.makeKeyPair(); origCert = CMSTestUtil.makeCertificate(origKP, origDN, signKP, signDN); }
public void testTwoRecipients() throws Exception { MimeBodyPart _msg = SMIMETestUtil.makeMimeBodyPart("WallaWallaWashington"); SMIMEEnvelopedGenerator gen = new SMIMEEnvelopedGenerator(); gen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(_reciCert).setProvider(BC)); gen.addRecipientInfoGenerator( new JceKeyTransRecipientInfoGenerator(_reciCert2).setProvider(BC)); // // generate a MimeBodyPart object which encapsulates the content // we want encrypted. // MimeBodyPart mp = gen.generate( _msg, new JceCMSContentEncryptorBuilder(CMSAlgorithm.RC2_CBC, 40).setProvider(BC).build()); SMIMEEnvelopedParser m = new SMIMEEnvelopedParser(mp); RecipientId recId = getRecipientId(_reciCert2); RecipientInformationStore recipients = m.getRecipientInfos(); RecipientInformation recipient = recipients.get(recId); FileBackedMimeBodyPart res = SMIMEUtil.toMimeBodyPart( recipient.getContentStream( new JceKeyTransEnvelopedRecipient(_reciKP2.getPrivate()).setProvider(BC))); verifyMessageBytes(_msg, res); m = new SMIMEEnvelopedParser(mp); res.dispose(); recId = getRecipientId(_reciCert); recipients = m.getRecipientInfos(); recipient = recipients.get(recId); res = SMIMEUtil.toMimeBodyPart( recipient.getContentStream( new JceKeyTransEnvelopedRecipient(_reciKP.getPrivate()).setProvider(BC))); verifyMessageBytes(_msg, res); res.dispose(); }
public void testSubKeyId() throws Exception { MimeBodyPart msg = SMIMETestUtil.makeMimeBodyPart("WallaWallaWashington"); SMIMEEnvelopedGenerator gen = new SMIMEEnvelopedGenerator(); // // create a subject key id - this has to be done the same way as // it is done in the certificate associated with the private key // MessageDigest dig = MessageDigest.getInstance("SHA1", BC); dig.update( SubjectPublicKeyInfo.getInstance(_reciCert.getPublicKey().getEncoded()) .getPublicKeyData() .getBytes()); gen.addRecipientInfoGenerator( new JceKeyTransRecipientInfoGenerator(dig.digest(), _reciCert.getPublicKey()) .setProvider(BC)); // // generate a MimeBodyPart object which encapsulates the content // we want encrypted. // MimeBodyPart mp = gen.generate( msg, new JceCMSContentEncryptorBuilder(CMSAlgorithm.DES_EDE3_CBC).setProvider(BC).build()); SMIMEEnveloped m = new SMIMEEnveloped(mp); dig.update( SubjectPublicKeyInfo.getInstance(_reciCert.getPublicKey().getEncoded()) .getPublicKeyData() .getBytes()); RecipientId recId = new KeyTransRecipientId(dig.digest()); RecipientInformationStore recipients = m.getRecipientInfos(); RecipientInformation recipient = recipients.get(recId); MimeBodyPart res = SMIMEUtil.toMimeBodyPart( recipient.getContent( new JceKeyTransEnvelopedRecipient(_reciKP.getPrivate()).setProvider(BC))); verifyMessageBytes(msg, res); }
public void testHeaders() throws Exception { MimeBodyPart msg = SMIMETestUtil.makeMimeBodyPart("WallaWallaWashington"); SMIMEEnvelopedGenerator gen = new SMIMEEnvelopedGenerator(); gen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(_reciCert).setProvider(BC)); // // generate a MimeBodyPart object which encapsulates the content // we want encrypted. // MimeBodyPart mp = gen.generate( msg, new JceCMSContentEncryptorBuilder(CMSAlgorithm.DES_EDE3_CBC).setProvider(BC).build()); assertEquals( "application/pkcs7-mime; name=\"smime.p7m\"; smime-type=enveloped-data", mp.getHeader("Content-Type")[0]); assertEquals("attachment; filename=\"smime.p7m\"", mp.getHeader("Content-Disposition")[0]); assertEquals("S/MIME Encrypted Message", mp.getHeader("Content-Description")[0]); }
public void testAES256Encrypted() throws Exception { MimeBodyPart msg = SMIMETestUtil.makeMimeBodyPart("WallaWallaWashington"); String algorithm = SMIMEEnvelopedGenerator.AES256_CBC; verifyAlgorithm(algorithm, msg); }
public void testParserDESEDE3Encrypted() throws Exception { MimeBodyPart msg = SMIMETestUtil.makeMimeBodyPart("WallaWallaWashington"); String algorithm = SMIMEEnvelopedGenerator.DES_EDE3_CBC; verifyParserAlgorithm(algorithm, msg); }