예제 #1
0
  public void testSignAttachmentOnly() throws Exception {
    MimeMessage m = loadMessage("attachonly.eml");

    List certList = new ArrayList();

    certList.add(_signCert);
    certList.add(_origCert);

    Store certs = new JcaCertStore(certList);

    ASN1EncodableVector signedAttrs = generateSignedAttributes();

    SMIMESignedGenerator gen = new SMIMESignedGenerator("binary");

    gen.addSignerInfoGenerator(
        new JcaSimpleSignerInfoGeneratorBuilder()
            .setProvider(BC)
            .setSignedAttributeGenerator(new AttributeTable(signedAttrs))
            .build("SHA1withRSA", _signKP.getPrivate(), _signCert));
    gen.addCertificates(certs);

    MimeMultipart mm = gen.generate(m);

    SMIMESigned s = new SMIMESigned(mm);

    verifySigners(s.getCertificates(), s.getSignerInfos());

    SMIMESignedParser sp =
        new SMIMESignedParser(new JcaDigestCalculatorProviderBuilder().setProvider(BC).build(), mm);

    verifySigners(sp.getCertificates(), sp.getSignerInfos());
  }
예제 #2
0
  public void testSHA224WithRSAParserEncryptedWithDES() throws Exception {
    List certList = new ArrayList();

    certList.add(_signCert);
    certList.add(_origCert);

    Store certs = new JcaCertStore(certList);

    ASN1EncodableVector signedAttrs = generateSignedAttributes();

    SMIMESignedGenerator gen = new SMIMESignedGenerator();

    gen.addSignerInfoGenerator(
        new JcaSimpleSignerInfoGeneratorBuilder()
            .setProvider(BC)
            .setSignedAttributeGenerator(
                new DefaultSignedAttributeTableGenerator(new AttributeTable(signedAttrs)))
            .build("SHA224withRSA", _signKP.getPrivate(), _signCert));
    gen.addCertificates(certs);

    MimeMultipart smm = gen.generate(msg);
    SMIMESignedParser s =
        new SMIMESignedParser(
            new JcaDigestCalculatorProviderBuilder().setProvider(BC).build(), smm);

    certs = s.getCertificates();

    assertEquals(getDigestOid(s.getSignerInfos()), NISTObjectIdentifiers.id_sha224.toString());

    verifyMessageBytes(msg, s.getContent());

    verifySigners(certs, s.getSignerInfos());
  }
예제 #3
0
  public void testMimeMultipartBinaryParserGetMimeContent() throws Exception {
    MimeBodyPart m = createMultipartMessage();

    List certList = new ArrayList();

    certList.add(_signCert);
    certList.add(_origCert);

    Store certs = new JcaCertStore(certList);

    ASN1EncodableVector signedAttrs = generateSignedAttributes();

    SMIMESignedGenerator gen = new SMIMESignedGenerator("binary");

    gen.addSignerInfoGenerator(
        new JcaSimpleSignerInfoGeneratorBuilder()
            .setProvider(BC)
            .setSignedAttributeGenerator(new AttributeTable(signedAttrs))
            .build("SHA1withRSA", _signKP.getPrivate(), _signCert));
    gen.addCertificates(certs);

    MimeMultipart mm = gen.generate(m);

    SMIMESignedParser s =
        new SMIMESignedParser(
            new JcaDigestCalculatorProviderBuilder().setProvider(BC).build(), mm, "binary");

    verifySigners(s.getCertificates(), s.getSignerInfos());

    MimeMessage bp = s.getContentAsMimeMessage(Session.getDefaultInstance(new Properties()));
  }
예제 #4
0
  public void testRawAS2Parser() throws Exception {
    MimeMessage message = loadMessage("rawAS2.message");

    SMIMESignedParser s =
        new SMIMESignedParser(
            new JcaDigestCalculatorProviderBuilder().setProvider(BC).build(),
            (MimeMultipart) message.getContent());

    verifySigners(s.getCertificates(), s.getSignerInfos());
  }
예제 #5
0
  public void testSHA256WithRSABinaryWithParser() throws Exception {
    MimeBodyPart msg = generateBinaryPart();
    MimeMultipart smm =
        generateMultiPartRsa("SHA256withRSA", msg, SMIMESignedGenerator.RFC3851_MICALGS);
    SMIMESignedParser s =
        new SMIMESignedParser(
            new JcaDigestCalculatorProviderBuilder().setProvider(BC).build(), smm);

    verifyMessageBytes(msg, s.getContent());

    verifySigners(s.getCertificates(), s.getSignerInfos());
  }
예제 #6
0
  private void rsaPSSTest(String digest, String digestOID) throws Exception {
    MimeMultipart smm = generateMultiPartRsaPSS(digest, msg, null);
    SMIMESignedParser s =
        new SMIMESignedParser(
            new JcaDigestCalculatorProviderBuilder().setProvider(BC).build(), smm);
    Store certs = s.getCertificates();

    assertEquals(getDigestOid(s.getSignerInfos()), digestOID);

    verifyMessageBytes(msg, s.getContent());

    verifySigners(certs, s.getSignerInfos());
  }
예제 #7
0
  public void testSHA224WithRSAParser() throws Exception {
    MimeMultipart smm =
        generateMultiPartRsa("SHA224withRSA", msg, SMIMESignedGenerator.RFC3851_MICALGS);
    SMIMESignedParser s =
        new SMIMESignedParser(
            new JcaDigestCalculatorProviderBuilder().setProvider(BC).build(), smm);
    Store certs = s.getCertificates();

    assertEquals(getDigestOid(s.getSignerInfos()), NISTObjectIdentifiers.id_sha224.toString());

    verifyMessageBytes(msg, s.getContent());

    verifySigners(certs, s.getSignerInfos());
  }
예제 #8
0
  public void testSHA1WithRSAEncapsulatedParser() throws Exception {
    MimeBodyPart res = generateEncapsulatedRsa("SHA1withRSA", msg);
    SMIMESignedParser s =
        new SMIMESignedParser(
            new JcaDigestCalculatorProviderBuilder().setProvider(BC).build(), res);

    FileBackedMimeBodyPart content = (FileBackedMimeBodyPart) s.getContent();

    verifyMessageBytes(msg, content);

    content.dispose();

    verifySigners(s.getCertificates(), s.getSignerInfos());

    s.close();
  }
예제 #9
0
  public void testSHA1WithRSAEncapsulatedParserAndFile() throws Exception {
    File tmp = File.createTempFile("bcTest", ".mime");
    MimeBodyPart res = generateEncapsulatedRsa("SHA1withRSA", msg);
    SMIMESignedParser s =
        new SMIMESignedParser(
            new JcaDigestCalculatorProviderBuilder().setProvider(BC).build(), res, tmp);
    FileBackedMimeBodyPart content = (FileBackedMimeBodyPart) s.getContent();

    verifyMessageBytes(msg, s.getContent());

    verifySigners(s.getCertificates(), s.getSignerInfos());

    assertTrue(tmp.exists());

    s.close();

    content.dispose();

    assertFalse(tmp.exists());
  }