当前位置: 首页>>代码示例>>Java>>正文


Java SMIMESigned.getSignerInfos方法代码示例

本文整理汇总了Java中org.bouncycastle.mail.smime.SMIMESigned.getSignerInfos方法的典型用法代码示例。如果您正苦于以下问题:Java SMIMESigned.getSignerInfos方法的具体用法?Java SMIMESigned.getSignerInfos怎么用?Java SMIMESigned.getSignerInfos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bouncycastle.mail.smime.SMIMESigned的用法示例。


在下文中一共展示了SMIMESigned.getSignerInfos方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: verify

import org.bouncycastle.mail.smime.SMIMESigned; //导入方法依赖的package包/类
public void verify(X509Certificate cert) throws SFRMException {
      try {
          SMIMESigned signed = new SMIMESigned((MimeMultipart)bodyPart.getContent());
          SignerInformationStore signers = signed.getSignerInfos();
          Iterator signerInfos = signers.getSigners().iterator();
      
          while (signerInfos.hasNext()) {
              SignerInformation signerInfo = (SignerInformation)signerInfos.next();
SignerInformationVerifier verifier =
    new BcRSASignerInfoVerifierBuilder(new DefaultCMSSignatureAlgorithmNameGenerator(),
				  new DefaultSignatureAlgorithmIdentifierFinder(),
				  new DefaultDigestAlgorithmIdentifierFinder(), 
				  new BcDigestCalculatorProvider())
    .build(new JcaX509CertificateHolder(cert));
              if (!signerInfo.verify(verifier)) {
                  throw new SFRMMessageException("Verification failed");
              }
          }
          
          MimeBodyPart signedPart = signed.getContent();
          if (signedPart == null) {
              throw new SFRMMessageException("Unable to extract signed part");
          }
          else {
          	this.bodyPart = signedPart;
          	this.setIsSigned(true);
          }
          
  	} catch (org.bouncycastle.cms.CMSException ex) {
  		throw new SFRMException("Unable to verify body part", ex.getUnderlyingException());
      } catch (Exception e) {
          throw new SFRMException("Unable to verify body part", e);
      }
  }
 
开发者ID:cecid,项目名称:hermes,代码行数:35,代码来源:SFRMMessage.java

示例2: verify

import org.bouncycastle.mail.smime.SMIMESigned; //导入方法依赖的package包/类
/**
   * Verifies the encapsulated MIME body part.
   * 
   * @param cert the certificate for verification.
   * @return an S/MIME message encapsulating the signed content. 
   * @throws SMimeException if unable to verify the body part.
   */
  public SMimeMessage verify(X509Certificate cert) throws SMimeException {
      try {
          if (cert == null) {
              throw new SMimeException("No certificate for verification");
          }

          setDefaults();

          SMIMESigned signed = new SMIMESigned((MimeMultipart)bodyPart.getContent());
          // CertStore cs = signed.getCertificatesAndCRLs("Collection", "BC");
          SignerInformationStore  signers = signed.getSignerInfos();
          Iterator signerInfos = signers.getSigners().iterator();
      
          while (signerInfos.hasNext()) {
              SignerInformation   signerInfo = (SignerInformation)signerInfos.next();
              // if (!signerInfo.verify(cert, "BC")) {  // Deprecated
// TODO: revise the choice of components
SignerInformationVerifier verifier =
    new BcRSASignerInfoVerifierBuilder(new DefaultCMSSignatureAlgorithmNameGenerator(),
				  new DefaultSignatureAlgorithmIdentifierFinder(),
				  new DefaultDigestAlgorithmIdentifierFinder(), 
				  new BcDigestCalculatorProvider())
    .build(new JcaX509CertificateHolder(cert));
if (!signerInfo.verify(verifier)) {		    
                  throw new SMimeException("Verification failed");
              }
          }
          
          MimeBodyPart signedPart = signed.getContent();
          if (signedPart == null) {
              throw new SMimeException("Unable to extract signed part");
          }
          else {
              return new SMimeMessage(signedPart, this);
          }
      }
      catch (Exception e) {
          if (e instanceof CMSException) {
              e = ((CMSException)e).getUnderlyingException();
          }
          throw new SMimeException("Unable to verify body part", e);
      }
  }
 
开发者ID:cecid,项目名称:hermes,代码行数:51,代码来源:SMimeMessage.java

示例3: testSignedAS2Message

import org.bouncycastle.mail.smime.SMIMESigned; //导入方法依赖的package包/类
@Test
public void testSignedAS2Message() throws Exception{
	InputStream ins = FIXTURE_LOADER.getResourceAsStream(MOCK_AS2_MSG);
	ByteArrayInputStream bIns = new ByteArrayInputStream(IOHandler.readBytes(ins));

	partnershipDVO.setIsOutboundSignRequired(true);
	String mid = RANDOM.toString();
	
	AS2Message as2Msg = TARGET.storeOutgoingMessage(
			mid, //MessageID
			"xml", 
			partnershipDVO,
			new InputStreamDataSource(bIns, "xml", MOCK_AS2_MSG));
	
	//Verify As2Signing Message
	try{
		SMIMESigned signed = new SMIMESigned((MimeMultipart)as2Msg.getBodyPart().getContent());
		SignerInformationStore  signers = signed.getSignerInfos();
		Iterator signerInfos = signers.getSigners().iterator();
		while (signerInfos.hasNext()) {
			SignerInformation   signerInfo = (SignerInformation)signerInfos.next();

			SignerInformationVerifier verifier =
			    new BcRSASignerInfoVerifierBuilder(new DefaultCMSSignatureAlgorithmNameGenerator(),
							       new DefaultSignatureAlgorithmIdentifierFinder(),
							       new DefaultDigestAlgorithmIdentifierFinder(), 
							       new BcDigestCalculatorProvider())
			    .build(new JcaX509CertificateHolder(partnershipDVO.getEffectiveVerifyCertificate()));
			
			if (!signerInfo.verify(verifier)) {
				Assert.fail("Signature Verfifcation Failed");
			}
		}
		
		//Assert the filename value
		MimeBodyPart signedPart = signed.getContent();
        String filenameHdr = signedPart.getHeader("Content-Disposition")[0];
        Assert.assertEquals("Lost Filename Header Information", MOCK_AS2_MSG, getFileName(filenameHdr));
        
        
        // Verify MIC Value
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        signedPart.writeTo(baos);
           byte[] content = (baos.toByteArray());
           String mic = calculateMIC(content);
           
           MessageDVO msgDVO = getStoredMessage(mid);
           Assert.assertEquals("MIC Value is not valid.", mic, msgDVO.getMicValue());
        
	}catch(Exception exp){
		Assert.fail("Signature Verfifcation Failed");
	}
       Assert.assertTrue(true);
	}
 
开发者ID:cecid,项目名称:hermes,代码行数:55,代码来源:OutgoingMessageProcessorTest.java

示例4: testSignedEncryptedAS2Message

import org.bouncycastle.mail.smime.SMIMESigned; //导入方法依赖的package包/类
@Test
public void testSignedEncryptedAS2Message() throws Exception {
    InputStream ins = FIXTURE_LOADER.getResourceAsStream(MOCK_AS2_MSG);
    ByteArrayInputStream bIns = new ByteArrayInputStream(IOHandler.readBytes(ins));
	
    // Prepare Data
    String mid = RANDOM.toString();
    partnershipDVO.setIsOutboundEncryptRequired(true);
    partnershipDVO.setIsOutboundSignRequired(true);
    //Encrypt message
    AS2Message as2Msg = TARGET.storeOutgoingMessage(
						    mid, //MessageID
						    "xml", 
						    partnershipDVO,
						    new InputStreamDataSource(bIns, "xml", MOCK_AS2_MSG));
	
    // Decrypt Message
    SMIMEEnveloped crypted = new SMIMEEnveloped(as2Msg.getBodyPart());

    RecipientId recId = new JceKeyTransRecipientId(partnershipDVO.getEncryptX509Certificate());
    
    RecipientInformationStore  recipientsInfo = crypted.getRecipientInfos();	
    RecipientInformation       recipientInfo = recipientsInfo.get(recId);

    KeyStoreManager keyMan = (KeyStoreManager)TARGET.getSystemModule().getComponent("keystore-manager");

    JceKeyTransEnvelopedRecipient recipient = new JceKeyTransEnvelopedRecipient(keyMan.getPrivateKey());	
    recipient.setProvider(SECURITY_PROVIDER);							
    
    MimeBodyPart  decrpted = SMIMEUtil.toMimeBodyPart(recipientInfo.getContent(recipient));
	
    //Verify Signature
    try{
	SMIMESigned signed = new SMIMESigned((MimeMultipart)decrpted.getContent());
	SignerInformationStore  signers = signed.getSignerInfos();
	Iterator signerInfos = signers.getSigners().iterator();

	while (signerInfos.hasNext()) {
	    SignerInformation   signerInfo = (SignerInformation)signerInfos.next();

	    SignerInformationVerifier verifier =
		new BcRSASignerInfoVerifierBuilder(new DefaultCMSSignatureAlgorithmNameGenerator(),
						   new DefaultSignatureAlgorithmIdentifierFinder(),
						   new DefaultDigestAlgorithmIdentifierFinder(), 
						   new BcDigestCalculatorProvider())
		.build(new JcaX509CertificateHolder(partnershipDVO.getEffectiveVerifyCertificate()));
	    if (!signerInfo.verify(verifier)) {
		Assert.fail("Signature Verfifcation Failed");
	    }
	}

	
		
	//Assert the filename value
	MimeBodyPart signedPart = signed.getContent();
        String filenameHdr = signedPart.getHeader("Content-Disposition")[0];
        Assert.assertEquals("Lost Filename Header Information", MOCK_AS2_MSG, getFileName(filenameHdr));
        
        
        // Verify MIC Value
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        signedPart.writeTo(baos);
	byte[] content = (baos.toByteArray());
	String mic = calculateMIC(content);
           
	MessageDVO msgDVO = getStoredMessage(mid);
	Assert.assertEquals("MIC Value is not valid.", mic, msgDVO.getMicValue());
        
    }catch(Exception exp){
	Assert.fail("Signature Verfifcation Failed");
    }
    Assert.assertTrue(true);
}
 
开发者ID:cecid,项目名称:hermes,代码行数:74,代码来源:OutgoingMessageProcessorTest.java

示例5: testSignedCommpressMessage

import org.bouncycastle.mail.smime.SMIMESigned; //导入方法依赖的package包/类
@Test
public void testSignedCommpressMessage() throws Exception{
	InputStream ins = FIXTURE_LOADER.getResourceAsStream(MOCK_AS2_MSG);
	ByteArrayInputStream bIns = new ByteArrayInputStream(IOHandler.readBytes(ins));
	
	// Prepare Data
	String mid = RANDOM.toString();
	partnershipDVO.setIsOutboundSignRequired(true);
	partnershipDVO.setIsOutboundCompressRequired(true);
	//Process message
	AS2Message as2Msg = TARGET.storeOutgoingMessage(
			mid, //MessageID
			"xml", 
			partnershipDVO,
			new InputStreamDataSource(bIns, "xml", MOCK_AS2_MSG));
       
       try{
       	//Verify Message Signature
		SMIMESigned signed = new SMIMESigned((MimeMultipart)as2Msg.getBodyPart().getContent());
		SignerInformationStore  signers = signed.getSignerInfos();
		Iterator signerInfos = signers.getSigners().iterator();
		while (signerInfos.hasNext()) {
			SignerInformation   signerInfo = (SignerInformation)signerInfos.next();

			SignerInformationVerifier verifier =
			    new BcRSASignerInfoVerifierBuilder(new DefaultCMSSignatureAlgorithmNameGenerator(),
							       new DefaultSignatureAlgorithmIdentifierFinder(),
							       new DefaultDigestAlgorithmIdentifierFinder(), 
							       new BcDigestCalculatorProvider())
			    .build(new JcaX509CertificateHolder(partnershipDVO.getEffectiveVerifyCertificate()));
			
			if (!signerInfo.verify(verifier)) {
				Assert.fail("Signature Verfifcation Failed");
			}
		}
		
		// Verify MIC Value
		MimeBodyPart signedPart = signed.getContent();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        signedPart.writeTo(baos);
        byte[] content = (baos.toByteArray());
        String mic = calculateMIC(content);
        MessageDVO msgDVO = getStoredMessage(mid);
        Assert.assertEquals("MIC Value is not valid.", mic, msgDVO.getMicValue());
		
		//Decompress Message
		SMIMECompressed compressed = new SMIMECompressed(signedPart);
		MimeBodyPart decompressedPart = SMIMEUtil.toMimeBodyPart(compressed.getContent(new ZlibExpanderProvider()));
		
		//Assert the filename value
        String filenameHdr = decompressedPart.getHeader("Content-Disposition")[0];
        Assert.assertEquals("Lost Filename Header Information", MOCK_AS2_MSG, getFileName(filenameHdr));
        
	}catch(Exception exp){
		Assert.fail("Signature Verfifcation Failed");
	}
	
}
 
开发者ID:cecid,项目名称:hermes,代码行数:59,代码来源:OutgoingMessageProcessorTest.java

示例6: verify

import org.bouncycastle.mail.smime.SMIMESigned; //导入方法依赖的package包/类
/**
 * verify the signature (assuming the cert is contained in the message)
 */
private static void verify(
    SMIMESigned s)
    throws Exception
{
    //
    // extract the information to verify the signatures.
    //

    //
    // certificates and crls passed in the signature
    //
    Store certs = s.getCertificates();

    //
    // SignerInfo blocks which contain the signatures
    //
    SignerInformationStore  signers = s.getSignerInfos();

    Collection              c = signers.getSigners();
    Iterator                it = c.iterator();

    //
    // check each signer
    //
    while (it.hasNext())
    {
        SignerInformation   signer = (SignerInformation)it.next();
        Collection          certCollection = certs.getMatches(signer.getSID());

        Iterator        certIt = certCollection.iterator();
        X509Certificate cert = new JcaX509CertificateConverter().setProvider(BC).getCertificate((X509CertificateHolder)certIt.next());

        //
        // verify that the sig is correct and that it was generated
        // when the certificate was current
        //
        if (signer.verify(new JcaSimpleSignerInfoVerifierBuilder().setProvider(BC).build(cert)))
        {
            System.out.println("signature verified");
        }
        else
        {
            System.out.println("signature failed!");
        }
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:50,代码来源:ReadSignedMail.java

示例7: testPythonSigned

import org.bouncycastle.mail.smime.SMIMESigned; //导入方法依赖的package包/类
@Test
public void testPythonSigned() throws Exception {
    final InputStream pythonIs = Thread.currentThread().getContextClassLoader().getResourceAsStream("python_signed.txt");

  /*
  Message message = new Message(pythonIs);
  Multipart multipart = (Multipart)message.getBody();
  System.out.println("count: " + multipart.getCount());
  */

    ByteArrayDataSource ds = new ByteArrayDataSource(pythonIs, "multipart/signed");
    MimeMultipart mm = new MimeMultipart(ds);

    System.out.println(mm.getContentType());

    System.out.println("Multipart.count(): " + mm.getCount());

    MimeBodyPart mbp = (MimeBodyPart) mm.getBodyPart(0);

    output(mbp);

    SMIMESigned signed = new SMIMESigned(mm);

    SignerInformationStore signers = signed.getSignerInfos();
    Assert.assertEquals(1, signers.size());
    SignerInformation signer = (SignerInformation) signers.getSigners().iterator().next();


    final CMSSignatureAlgorithmNameGenerator cmsSignatureAlgorithmNameGenerator = new DefaultCMSSignatureAlgorithmNameGenerator();
    final SignatureAlgorithmIdentifierFinder signatureAlgorithmIdentifierFinder = new DefaultSignatureAlgorithmIdentifierFinder();
    final JcaContentVerifierProviderBuilder jcaContentVerifierProviderBuilder = new JcaContentVerifierProviderBuilder();
    final ContentVerifierProvider contentVerifierProvider = jcaContentVerifierProviderBuilder.build(cert.getPublicKey());
    final DigestCalculatorProvider digestCalculatorProvider = new BcDigestCalculatorProvider();

    SignerInformationVerifier verifier = new SignerInformationVerifier(
            cmsSignatureAlgorithmNameGenerator,
            signatureAlgorithmIdentifierFinder,
            contentVerifierProvider,
            digestCalculatorProvider);

    Assert.assertTrue(signer.verify(verifier));
}
 
开发者ID:gini,项目名称:jersey-smime,代码行数:43,代码来源:SignedTest.java

示例8: verify

import org.bouncycastle.mail.smime.SMIMESigned; //导入方法依赖的package包/类
public boolean verify(PublicKey publicKey) throws CMSException, MessagingException, OperatorCreationException {
    SMIMESigned signed = new SMIMESigned(body);

    SignerInformationStore signers = signed.getSignerInfos();
    SignerInformation signer = (SignerInformation) signers.getSigners().iterator().next();

    JcaSimpleSignerInfoVerifierBuilder signerInfoVerifierBuilder = new JcaSimpleSignerInfoVerifierBuilder();

    return signer.verify(signerInfoVerifierBuilder.build(publicKey));
}
 
开发者ID:gini,项目名称:jersey-smime,代码行数:11,代码来源:SignedInputImpl.java

示例9: testCompressedSHA1WithRSA

import org.bouncycastle.mail.smime.SMIMESigned; //导入方法依赖的package包/类
public void testCompressedSHA1WithRSA()
    throws Exception
{
    List           certList = new ArrayList();

    certList.add(origCert);
    certList.add(signCert);

    CertStore      certs = CertStore.getInstance("Collection",
                                   new CollectionCertStoreParameters(certList), "BC");

    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));

    SMIMESignedGenerator gen = new SMIMESignedGenerator();

    gen.addSigner(origKP.getPrivate(), origCert, SMIMESignedGenerator.DIGEST_SHA1, new AttributeTable(signedAttrs), null);

    gen.addCertificatesAndCRLs(certs);

    MimeMultipart smp = gen.generate(msg, "BC");

    MimeMessage bp2 = new MimeMessage((Session)null);                          

    bp2.setContent(smp);

    bp2.saveChanges();

    SMIMECompressedGenerator    cgen = new SMIMECompressedGenerator();

    MimeBodyPart cbp = cgen.generate(bp2, SMIMECompressedGenerator.ZLIB);

    SMIMECompressed cm = new SMIMECompressed(cbp);

    MimeMultipart mm = (MimeMultipart)SMIMEUtil.toMimeBodyPart(cm.getContent()).getContent();
    
    SMIMESigned s = new SMIMESigned(mm);

    ByteArrayOutputStream _baos = new ByteArrayOutputStream();
    msg.writeTo(_baos);
    _baos.close();
    byte[] _msgBytes = _baos.toByteArray();
    _baos = new ByteArrayOutputStream();
    s.getContent().writeTo(_baos);
    _baos.close();
    byte[] _resBytes = _baos.toByteArray();
    
    assertEquals(true, Arrays.areEqual(_msgBytes, _resBytes));

    certs = s.getCertificatesAndCRLs("Collection", "BC");

    SignerInformationStore  signers = s.getSignerInfos();
    Collection              c = signers.getSigners();
    Iterator                it = c.iterator();

    while (it.hasNext())
    {
        SignerInformation   signer = (SignerInformation)it.next();
        Collection          certCollection = certs.getCertificates(selectorConverter.getCertSelector(signer.getSID()));

        Iterator            certIt = certCollection.iterator();
        X509Certificate     cert = (X509Certificate)certIt.next();

        assertEquals(true, signer.verify(cert, "BC"));
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:73,代码来源:SMIMECompressedTest.java


注:本文中的org.bouncycastle.mail.smime.SMIMESigned.getSignerInfos方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。