Search in sources :

Example 6 with CertID

use of com.github.zhenwei.core.asn1.ocsp.CertID in project jruby-openssl by jruby.

the class OCSPCertificateId method cmp_issuer.

@JRubyMethod(name = "cmp_issuer")
public IRubyObject cmp_issuer(IRubyObject other) {
    Ruby runtime = getRuntime();
    if (equals(other)) {
        return RubyFixnum.zero(runtime);
    }
    if (other instanceof OCSPCertificateId) {
        OCSPCertificateId that = (OCSPCertificateId) other;
        CertID thisCert = this.getCertID();
        CertID thatCert = that.getCertID();
        int ret = thisCert.getHashAlgorithm().getAlgorithm().toString().compareTo(thatCert.getHashAlgorithm().getAlgorithm().toString());
        if (ret != 0)
            return RubyFixnum.newFixnum(runtime, ret);
        ret = thisCert.getIssuerNameHash().toString().compareTo(thatCert.getIssuerNameHash().toString());
        if (ret != 0)
            return RubyFixnum.newFixnum(runtime, ret);
        return RubyFixnum.newFixnum(runtime, thisCert.getIssuerKeyHash().toString().compareTo(thatCert.getIssuerKeyHash().toString()));
    } else {
        return runtime.getCurrentContext().nil;
    }
}
Also used : CertID(org.bouncycastle.asn1.ocsp.CertID) Ruby(org.jruby.Ruby) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 7 with CertID

use of com.github.zhenwei.core.asn1.ocsp.CertID in project xipki by xipki.

the class OcspBenchRequestor method buildRequest.

// method ask
private byte[] buildRequest(BigInteger[] serialNumbers) throws OcspRequestorException {
    boolean canCache = (serialNumbers.length == 1) && !requestOptions.isUseNonce();
    if (canCache) {
        byte[] request = requests.get(serialNumbers[0]);
        if (request != null) {
            return request;
        }
    }
    OCSPReqBuilder reqBuilder = new OCSPReqBuilder();
    if (requestOptions.isUseNonce() || extensions != null) {
        List<Extension> extns = new ArrayList<>(2);
        if (requestOptions.isUseNonce()) {
            Extension extn = new Extension(OCSPObjectIdentifiers.id_pkix_ocsp_nonce, false, new DEROctetString(nextNonce(requestOptions.getNonceLen())));
            extns.add(extn);
        }
        if (extensions != null) {
            extns.addAll(Arrays.asList(extensions));
        }
        reqBuilder.setRequestExtensions(new Extensions(extns.toArray(extnType)));
    }
    try {
        for (BigInteger serialNumber : serialNumbers) {
            CertID certId = new CertID(issuerhashAlg.getAlgorithmIdentifier(), issuerNameHash, issuerKeyHash, new ASN1Integer(serialNumber));
            reqBuilder.addRequest(new CertificateID(certId));
        }
        byte[] request = reqBuilder.build().getEncoded();
        if (canCache) {
            requests.put(serialNumbers[0], request);
        }
        return request;
    } catch (OCSPException | IOException ex) {
        throw new OcspRequestorException(ex.getMessage(), ex);
    }
}
Also used : OcspRequestorException(org.xipki.ocsp.client.OcspRequestorException) CertID(org.bouncycastle.asn1.ocsp.CertID) CertificateID(org.bouncycastle.cert.ocsp.CertificateID) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Extensions(org.bouncycastle.asn1.x509.Extensions) Extension(org.bouncycastle.asn1.x509.Extension) OCSPException(org.bouncycastle.cert.ocsp.OCSPException) BigInteger(java.math.BigInteger) OCSPReqBuilder(org.bouncycastle.cert.ocsp.OCSPReqBuilder)

Example 8 with CertID

use of com.github.zhenwei.core.asn1.ocsp.CertID in project LinLong-Java by zhenwei1108.

the class SingleResponse method toASN1Primitive.

/**
 * Produce an object suitable for an ASN1OutputStream.
 * <pre>
 *  SingleResponse ::= SEQUENCE {
 *          certID                       CertID,
 *          certStatus                   CertStatus,
 *          thisUpdate                   GeneralizedTime,
 *          nextUpdate         [0]       EXPLICIT GeneralizedTime OPTIONAL,
 *          singleExtensions   [1]       EXPLICIT Extensions OPTIONAL }
 * </pre>
 */
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector(5);
    v.add(certID);
    v.add(certStatus);
    v.add(thisUpdate);
    if (nextUpdate != null) {
        v.add(new DERTaggedObject(true, 0, nextUpdate));
    }
    if (singleExtensions != null) {
        v.add(new DERTaggedObject(true, 1, singleExtensions));
    }
    return new DERSequence(v);
}
Also used : DERSequence(com.github.zhenwei.core.asn1.DERSequence) DERTaggedObject(com.github.zhenwei.core.asn1.DERTaggedObject) ASN1EncodableVector(com.github.zhenwei.core.asn1.ASN1EncodableVector)

Example 9 with CertID

use of com.github.zhenwei.core.asn1.ocsp.CertID in project LinLong-Java by zhenwei1108.

the class Request method toASN1Primitive.

/**
 * Produce an object suitable for an ASN1OutputStream.
 * <pre>
 * Request         ::=     SEQUENCE {
 *     reqCert                     CertID,
 *     singleRequestExtensions     [0] EXPLICIT Extensions OPTIONAL }
 * </pre>
 */
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector(2);
    v.add(reqCert);
    if (singleRequestExtensions != null) {
        v.add(new DERTaggedObject(true, 0, singleRequestExtensions));
    }
    return new DERSequence(v);
}
Also used : DERSequence(com.github.zhenwei.core.asn1.DERSequence) DERTaggedObject(com.github.zhenwei.core.asn1.DERTaggedObject) ASN1EncodableVector(com.github.zhenwei.core.asn1.ASN1EncodableVector)

Example 10 with CertID

use of com.github.zhenwei.core.asn1.ocsp.CertID in project LinLong-Java by zhenwei1108.

the class OOBCertHash method toASN1Primitive.

/**
 * <pre>
 * OOBCertHash ::= SEQUENCE {
 *                      hashAlg     [0] AlgorithmIdentifier     OPTIONAL,
 *                      certId      [1] CertId                  OPTIONAL,
 *                      hashVal         BIT STRING
 *                      -- hashVal is calculated over the DER encoding of the
 *                      -- self-signed certificate with the identifier certID.
 *       }
 * </pre>
 *
 * @return a basic ASN.1 object representation.
 */
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector(3);
    addOptional(v, 0, hashAlg);
    addOptional(v, 1, certId);
    v.add(hashVal);
    return new DERSequence(v);
}
Also used : DERSequence(com.github.zhenwei.core.asn1.DERSequence) ASN1EncodableVector(com.github.zhenwei.core.asn1.ASN1EncodableVector)

Aggregations

IOException (java.io.IOException)19 CertID (org.bouncycastle.asn1.ocsp.CertID)15 ASN1EncodableVector (com.github.zhenwei.core.asn1.ASN1EncodableVector)13 DERSequence (com.github.zhenwei.core.asn1.DERSequence)11 CertificateException (java.security.cert.CertificateException)7 X509Certificate (java.security.cert.X509Certificate)7 ASN1OctetString (com.github.zhenwei.core.asn1.ASN1OctetString)6 DEROctetString (com.github.zhenwei.core.asn1.DEROctetString)6 BigInteger (java.math.BigInteger)6 CertificateEncodingException (java.security.cert.CertificateEncodingException)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 NoSuchProviderException (java.security.NoSuchProviderException)5 ASN1BMPString (com.github.zhenwei.core.asn1.ASN1BMPString)4 ASN1ObjectIdentifier (com.github.zhenwei.core.asn1.ASN1ObjectIdentifier)4 DERBMPString (com.github.zhenwei.core.asn1.DERBMPString)4 Extension (org.bouncycastle.asn1.x509.Extension)4 ASN1Sequence (com.github.zhenwei.core.asn1.ASN1Sequence)3 BEROctetString (com.github.zhenwei.core.asn1.BEROctetString)3 DERTaggedObject (com.github.zhenwei.core.asn1.DERTaggedObject)3 CertID (com.github.zhenwei.core.asn1.ocsp.CertID)3