Java 类org.bouncycastle.asn1.cmp.CertConfirmContent 实例源码

项目:ipack    文件:CertificateConfirmationContentBuilder.java   
public CertificateConfirmationContent build(DigestCalculatorProvider digesterProvider)
    throws CMPException
{
    ASN1EncodableVector v = new ASN1EncodableVector();

    for (int i = 0; i != acceptedCerts.size(); i++)
    {
        X509CertificateHolder certHolder = (X509CertificateHolder)acceptedCerts.get(i);
        BigInteger reqID = (BigInteger)acceptedReqIds.get(i);

        AlgorithmIdentifier digAlg = digestAlgFinder.find(certHolder.toASN1Structure().getSignatureAlgorithm());
        if (digAlg == null)
        {
            throw new CMPException("cannot find algorithm for digest from signature");
        }

        DigestCalculator digester;

        try
        {
            digester = digesterProvider.get(digAlg);
        }
        catch (OperatorCreationException e)
        {
            throw new CMPException("unable to create digest: " + e.getMessage(), e);
        }

        CMPUtil.derEncodeToStream(certHolder.toASN1Structure(), digester.getOutputStream());

        v.add(new CertStatus(digester.getDigest(), reqID));
    }

    return new CertificateConfirmationContent(CertConfirmContent.getInstance(new DERSequence(v)), digestAlgFinder);
}
项目:gwt-crypto    文件:CertificateConfirmationContentBuilder.java   
public CertificateConfirmationContent build(DigestCalculatorProvider digesterProvider)
    throws CMPException
{
    ASN1EncodableVector v = new ASN1EncodableVector();

    for (int i = 0; i != acceptedCerts.size(); i++)
    {
        X509CertificateHolder certHolder = (X509CertificateHolder)acceptedCerts.get(i);
        BigInteger reqID = (BigInteger)acceptedReqIds.get(i);

        AlgorithmIdentifier digAlg = digestAlgFinder.find(certHolder.toASN1Structure().getSignatureAlgorithm());
        if (digAlg == null)
        {
            throw new CMPException("cannot find algorithm for digest from signature");
        }

        DigestCalculator digester;

        try
        {
            digester = digesterProvider.get(digAlg);
        }
        catch (OperatorCreationException e)
        {
            throw new CMPException("unable to create digest: " + e.getMessage(), e);
        }

        CMPUtil.derEncodeToStream(certHolder.toASN1Structure(), digester.getOutputStream());

        v.add(new CertStatus(digester.getDigest(), reqID));
    }

    return new CertificateConfirmationContent(CertConfirmContent.getInstance(new DERSequence(v)), digestAlgFinder);
}
项目:Aki-SSL    文件:CertificateConfirmationContentBuilder.java   
public CertificateConfirmationContent build(DigestCalculatorProvider digesterProvider)
    throws CMPException
{
    ASN1EncodableVector v = new ASN1EncodableVector();

    for (int i = 0; i != acceptedCerts.size(); i++)
    {
        X509CertificateHolder certHolder = (X509CertificateHolder)acceptedCerts.get(i);
        BigInteger reqID = (BigInteger)acceptedReqIds.get(i);

        AlgorithmIdentifier digAlg = digestAlgFinder.find(certHolder.toASN1Structure().getSignatureAlgorithm());
        if (digAlg == null)
        {
            throw new CMPException("cannot find algorithm for digest from signature");
        }

        DigestCalculator digester;

        try
        {
            digester = digesterProvider.get(digAlg);
        }
        catch (OperatorCreationException e)
        {
            throw new CMPException("unable to create digest: " + e.getMessage(), e);
        }

        CMPUtil.derEncodeToStream(certHolder.toASN1Structure(), digester.getOutputStream());

        v.add(new CertStatus(digester.getDigest(), reqID));
    }

    return new CertificateConfirmationContent(CertConfirmContent.getInstance(new DERSequence(v)), digestAlgFinder);
}
项目:irma_future_id    文件:CertificateConfirmationContentBuilder.java   
public CertificateConfirmationContent build(DigestCalculatorProvider digesterProvider)
    throws CMPException
{
    ASN1EncodableVector v = new ASN1EncodableVector();

    for (int i = 0; i != acceptedCerts.size(); i++)
    {
        X509CertificateHolder certHolder = (X509CertificateHolder)acceptedCerts.get(i);
        BigInteger reqID = (BigInteger)acceptedReqIds.get(i);

        AlgorithmIdentifier digAlg = digestAlgFinder.find(certHolder.toASN1Structure().getSignatureAlgorithm());
        if (digAlg == null)
        {
            throw new CMPException("cannot find algorithm for digest from signature");
        }

        DigestCalculator digester;

        try
        {
            digester = digesterProvider.get(digAlg);
        }
        catch (OperatorCreationException e)
        {
            throw new CMPException("unable to create digest: " + e.getMessage(), e);
        }

        CMPUtil.derEncodeToStream(certHolder.toASN1Structure(), digester.getOutputStream());

        v.add(new CertStatus(digester.getDigest(), reqID));
    }

    return new CertificateConfirmationContent(CertConfirmContent.getInstance(new DERSequence(v)), digestAlgFinder);
}
项目:irma_future_id    文件:AllTests.java   
public void testConfirmationMessage()
    throws Exception
{
    KeyPairGenerator kGen = KeyPairGenerator.getInstance("RSA", BC);

    kGen.initialize(512);

    KeyPair kp = kGen.generateKeyPair();
    X509CertificateHolder cert = makeV3Certificate(kp, "CN=Test", kp, "CN=Test");

    GeneralName sender = new GeneralName(new X500Name("CN=Sender"));
    GeneralName recipient = new GeneralName(new X500Name("CN=Recip"));

    CertificateConfirmationContent content = new CertificateConfirmationContentBuilder()
                         .addAcceptedCertificate(cert, BigInteger.valueOf(1))
                         .build(new JcaDigestCalculatorProviderBuilder().build());

    ContentSigner signer = new JcaContentSignerBuilder("MD5WithRSAEncryption").setProvider(BC).build(kp.getPrivate());
    ProtectedPKIMessage message = new ProtectedPKIMessageBuilder(sender, recipient)
                                              .setBody(new PKIBody(PKIBody.TYPE_CERT_CONFIRM, content.toASN1Structure()))
                                              .addCMPCertificate(cert)
                                              .build(signer);

    X509Certificate jcaCert = new JcaX509CertificateConverter().setProvider(BC).getCertificate(message.getCertificates()[0]);
    ContentVerifierProvider verifierProvider = new JcaContentVerifierProviderBuilder().setProvider(BC).build(jcaCert.getPublicKey());

    assertTrue(message.verify(verifierProvider));

    assertEquals(sender, message.getHeader().getSender());
    assertEquals(recipient, message.getHeader().getRecipient());

    content = new CertificateConfirmationContent(CertConfirmContent.getInstance(message.getBody().getContent()));

    CertificateStatus[] statusList = content.getStatusMessages();

    assertEquals(1, statusList.length);
    assertTrue(statusList[0].isVerified(cert, new JcaDigestCalculatorProviderBuilder().setProvider(BC).build()));
}
项目:bc-java    文件:CertificateConfirmationContentBuilder.java   
public CertificateConfirmationContent build(DigestCalculatorProvider digesterProvider)
    throws CMPException
{
    ASN1EncodableVector v = new ASN1EncodableVector();

    for (int i = 0; i != acceptedCerts.size(); i++)
    {
        X509CertificateHolder certHolder = (X509CertificateHolder)acceptedCerts.get(i);
        BigInteger reqID = (BigInteger)acceptedReqIds.get(i);

        AlgorithmIdentifier digAlg = digestAlgFinder.find(certHolder.toASN1Structure().getSignatureAlgorithm());
        if (digAlg == null)
        {
            throw new CMPException("cannot find algorithm for digest from signature");
        }

        DigestCalculator digester;

        try
        {
            digester = digesterProvider.get(digAlg);
        }
        catch (OperatorCreationException e)
        {
            throw new CMPException("unable to create digest: " + e.getMessage(), e);
        }

        CMPUtil.derEncodeToStream(certHolder.toASN1Structure(), digester.getOutputStream());

        v.add(new CertStatus(digester.getDigest(), reqID));
    }

    return new CertificateConfirmationContent(CertConfirmContent.getInstance(new DERSequence(v)), digestAlgFinder);
}
项目:bc-java    文件:AllTests.java   
public void testConfirmationMessage()
    throws Exception
{
    KeyPairGenerator kGen = KeyPairGenerator.getInstance("RSA", BC);

    kGen.initialize(512);

    KeyPair kp = kGen.generateKeyPair();
    X509CertificateHolder cert = makeV3Certificate(kp, "CN=Test", kp, "CN=Test");

    GeneralName sender = new GeneralName(new X500Name("CN=Sender"));
    GeneralName recipient = new GeneralName(new X500Name("CN=Recip"));

    CertificateConfirmationContent content = new CertificateConfirmationContentBuilder()
                         .addAcceptedCertificate(cert, BigInteger.valueOf(1))
                         .build(new JcaDigestCalculatorProviderBuilder().build());

    ContentSigner signer = new JcaContentSignerBuilder("MD5WithRSAEncryption").setProvider(BC).build(kp.getPrivate());
    ProtectedPKIMessage message = new ProtectedPKIMessageBuilder(sender, recipient)
                                              .setBody(new PKIBody(PKIBody.TYPE_CERT_CONFIRM, content.toASN1Structure()))
                                              .addCMPCertificate(cert)
                                              .build(signer);

    X509Certificate jcaCert = new JcaX509CertificateConverter().setProvider(BC).getCertificate(message.getCertificates()[0]);
    ContentVerifierProvider verifierProvider = new JcaContentVerifierProviderBuilder().setProvider(BC).build(jcaCert.getPublicKey());

    assertTrue(message.verify(verifierProvider));

    assertEquals(sender, message.getHeader().getSender());
    assertEquals(recipient, message.getHeader().getRecipient());

    content = new CertificateConfirmationContent(CertConfirmContent.getInstance(message.getBody().getContent()));

    CertificateStatus[] statusList = content.getStatusMessages();

    assertEquals(1, statusList.length);
    assertTrue(statusList[0].isVerified(cert, new JcaDigestCalculatorProviderBuilder().setProvider(BC).build()));
}
项目:ipack    文件:CertificateConfirmationContent.java   
public CertificateConfirmationContent(CertConfirmContent content)
{
    this(content, new DefaultDigestAlgorithmIdentifierFinder());
}
项目:ipack    文件:CertificateConfirmationContent.java   
public CertificateConfirmationContent(CertConfirmContent content, DigestAlgorithmIdentifierFinder digestAlgFinder)
{
    this.digestAlgFinder = digestAlgFinder;
    this.content = content;
}
项目:ipack    文件:CertificateConfirmationContent.java   
public CertConfirmContent toASN1Structure()
{
    return content;
}
项目:gwt-crypto    文件:CertificateConfirmationContent.java   
public CertificateConfirmationContent(CertConfirmContent content)
{
    this(content, new DefaultDigestAlgorithmIdentifierFinder());
}
项目:gwt-crypto    文件:CertificateConfirmationContent.java   
public CertificateConfirmationContent(CertConfirmContent content, DigestAlgorithmIdentifierFinder digestAlgFinder)
{
    this.digestAlgFinder = digestAlgFinder;
    this.content = content;
}
项目:gwt-crypto    文件:CertificateConfirmationContent.java   
public CertConfirmContent toASN1Structure()
{
    return content;
}
项目:Aki-SSL    文件:CertificateConfirmationContent.java   
public CertificateConfirmationContent(CertConfirmContent content)
{
    this(content, new DefaultDigestAlgorithmIdentifierFinder());
}
项目:Aki-SSL    文件:CertificateConfirmationContent.java   
public CertificateConfirmationContent(CertConfirmContent content, DigestAlgorithmIdentifierFinder digestAlgFinder)
{
    this.digestAlgFinder = digestAlgFinder;
    this.content = content;
}
项目:Aki-SSL    文件:CertificateConfirmationContent.java   
public CertConfirmContent toASN1Structure()
{
    return content;
}
项目:xipki    文件:X509CaCmpResponderImpl.java   
private PKIBody confirmCertificates(ASN1OctetString transactionId, CertConfirmContent certConf,
        String msgId) {
    CertStatus[] certStatuses = certConf.toCertStatusArray();

    boolean successful = true;
    for (CertStatus certStatus : certStatuses) {
        ASN1Integer certReqId = certStatus.getCertReqId();
        byte[] certHash = certStatus.getCertHash().getOctets();
        X509CertificateInfo certInfo = pendingCertPool.removeCertificate(
                transactionId.getOctets(), certReqId.getPositiveValue(), certHash);
        if (certInfo == null) {
            if (LOG.isWarnEnabled()) {
                LOG.warn("no cert under transactionId={}, certReqId={} and certHash=0X{}",
                        transactionId, certReqId.getPositiveValue(),
                        Hex.encode(certHash));
            }
            continue;
        }

        PKIStatusInfo statusInfo = certStatus.getStatusInfo();
        boolean accept = true;
        if (statusInfo != null) {
            int status = statusInfo.getStatus().intValue();
            if (PKIStatus.GRANTED != status && PKIStatus.GRANTED_WITH_MODS != status) {
                accept = false;
            }
        }

        if (accept) {
            continue;
        }

        BigInteger serialNumber = certInfo.cert().cert().getSerialNumber();
        X509Ca ca = getCa();
        try {
            ca.revokeCertificate(serialNumber, CrlReason.CESSATION_OF_OPERATION, new Date(),
                    msgId);
        } catch (OperationException ex) {
            LogUtil.warn(LOG, ex,
                    "could not revoke certificate ca=" + ca.caInfo().ident()
                    + " serialNumber=" + LogUtil.formatCsn(serialNumber));
        }

        successful = false;
    }

    // all other certificates should be revoked
    if (revokePendingCertificates(transactionId, msgId)) {
        successful = false;
    }

    if (successful) {
        return new PKIBody(PKIBody.TYPE_CONFIRM, DERNull.INSTANCE);
    }

    ErrorMsgContent emc = new ErrorMsgContent(
            new PKIStatusInfo(PKIStatus.rejection, null,
                    new PKIFailureInfo(PKIFailureInfo.systemFailure)));

    return new PKIBody(PKIBody.TYPE_ERROR, emc);
}
项目:irma_future_id    文件:CertificateConfirmationContent.java   
public CertificateConfirmationContent(CertConfirmContent content)
{
    this(content, new DefaultDigestAlgorithmIdentifierFinder());
}
项目:irma_future_id    文件:CertificateConfirmationContent.java   
public CertificateConfirmationContent(CertConfirmContent content, DigestAlgorithmIdentifierFinder digestAlgFinder)
{
    this.digestAlgFinder = digestAlgFinder;
    this.content = content;
}
项目:irma_future_id    文件:CertificateConfirmationContent.java   
public CertConfirmContent toASN1Structure()
{
    return content;
}
项目:bc-java    文件:CertificateConfirmationContent.java   
public CertificateConfirmationContent(CertConfirmContent content)
{
    this(content, new DefaultDigestAlgorithmIdentifierFinder());
}
项目:bc-java    文件:CertificateConfirmationContent.java   
public CertificateConfirmationContent(CertConfirmContent content, DigestAlgorithmIdentifierFinder digestAlgFinder)
{
    this.digestAlgFinder = digestAlgFinder;
    this.content = content;
}
项目:bc-java    文件:CertificateConfirmationContent.java   
public CertConfirmContent toASN1Structure()
{
    return content;
}