Search in sources :

Example 6 with TBSCertList

use of com.github.zhenwei.core.asn1.x509.TBSCertList in project LinLong-Java by zhenwei1108.

the class X509V2CRLGenerator method generateJcaObject.

private X509CRL generateJcaObject(TBSCertList tbsCrl, byte[] signature) throws CRLException {
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(tbsCrl);
    v.add(sigAlgId);
    v.add(new DERBitString(signature));
    return new X509CRLObject(CertificateList.getInstance(new DERSequence(v)));
}
Also used : X509CRLObject(com.github.zhenwei.provider.jce.provider.X509CRLObject) DERSequence(com.github.zhenwei.core.asn1.DERSequence) ASN1EncodableVector(com.github.zhenwei.core.asn1.ASN1EncodableVector) DERBitString(com.github.zhenwei.core.asn1.DERBitString)

Example 7 with TBSCertList

use of com.github.zhenwei.core.asn1.x509.TBSCertList in project robovm by robovm.

the class X509CRLHolder method isSignatureValid.

/**
     * Validate the signature on the CRL.
     *
     * @param verifierProvider a ContentVerifierProvider that can generate a verifier for the signature.
     * @return true if the signature is valid, false otherwise.
     * @throws CertException if the signature cannot be processed or is inappropriate.
     */
public boolean isSignatureValid(ContentVerifierProvider verifierProvider) throws CertException {
    TBSCertList tbsCRL = x509CRL.getTBSCertList();
    if (!CertUtils.isAlgIdEqual(tbsCRL.getSignature(), x509CRL.getSignatureAlgorithm())) {
        throw new CertException("signature invalid - algorithm identifier mismatch");
    }
    ContentVerifier verifier;
    try {
        verifier = verifierProvider.get((tbsCRL.getSignature()));
        OutputStream sOut = verifier.getOutputStream();
        DEROutputStream dOut = new DEROutputStream(sOut);
        dOut.writeObject(tbsCRL);
        sOut.close();
    } catch (Exception e) {
        throw new CertException("unable to process signature: " + e.getMessage(), e);
    }
    return verifier.verify(x509CRL.getSignature().getBytes());
}
Also used : ContentVerifier(org.bouncycastle.operator.ContentVerifier) OutputStream(java.io.OutputStream) DEROutputStream(org.bouncycastle.asn1.DEROutputStream) TBSCertList(org.bouncycastle.asn1.x509.TBSCertList) IOException(java.io.IOException) DEROutputStream(org.bouncycastle.asn1.DEROutputStream)

Example 8 with TBSCertList

use of com.github.zhenwei.core.asn1.x509.TBSCertList in project robovm by robovm.

the class X509CRLImpl method retrieveEntries.

/*
     * Retrieves the crl entries (TBSCertList.RevokedCertificate objects)
     * from the TBSCertList structure and converts them to the
     * X509CRLEntryImpl objects
     */
private void retrieveEntries() {
    entriesRetrieved = true;
    List rcerts = tbsCertList.getRevokedCertificates();
    if (rcerts == null) {
        return;
    }
    entriesSize = rcerts.size();
    entries = new ArrayList(entriesSize);
    // null means that revoked certificate issuer is the same as CRL issuer
    X500Principal rcertIssuer = null;
    for (int i = 0; i < entriesSize; i++) {
        TBSCertList.RevokedCertificate rcert = (TBSCertList.RevokedCertificate) rcerts.get(i);
        X500Principal iss = rcert.getIssuer();
        if (iss != null) {
            // certificate issuer differs from CRL issuer
            // and CRL is indirect.
            rcertIssuer = iss;
            isIndirectCRL = true;
            // remember how many leading revoked certificates in the
            // list are issued by the same issuer as issuer of CRL
            // (these certificates are first in the list)
            nonIndirectEntriesSize = i;
        }
        entries.add(new X509CRLEntryImpl(rcert, rcertIssuer));
    }
}
Also used : ArrayList(java.util.ArrayList) X500Principal(javax.security.auth.x500.X500Principal) ArrayList(java.util.ArrayList) TBSCertList(org.apache.harmony.security.x509.TBSCertList) CertificateList(org.apache.harmony.security.x509.CertificateList) List(java.util.List) TBSCertList(org.apache.harmony.security.x509.TBSCertList)

Example 9 with TBSCertList

use of com.github.zhenwei.core.asn1.x509.TBSCertList in project BiglyBT by BiglySoftware.

the class PrincipalUtil method getIssuerX509Principal.

/**
 * return the issuer of the given CRL as an X509PrincipalObject.
 */
public static X509Principal getIssuerX509Principal(X509CRL crl) throws CRLException {
    try {
        ByteArrayInputStream bIn = new ByteArrayInputStream(crl.getTBSCertList());
        ASN1InputStream aIn = new ASN1InputStream(bIn);
        TBSCertList tbsCertList = new TBSCertList((ASN1Sequence) aIn.readObject());
        return new X509Principal(tbsCertList.getIssuer());
    } catch (IOException e) {
        throw new CRLException(e.toString());
    }
}
Also used : ASN1InputStream(org.gudy.bouncycastle.asn1.ASN1InputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) TBSCertList(org.gudy.bouncycastle.asn1.x509.TBSCertList) IOException(java.io.IOException) CRLException(java.security.cert.CRLException)

Example 10 with TBSCertList

use of com.github.zhenwei.core.asn1.x509.TBSCertList in project LinLong-Java by zhenwei1108.

the class X509V2CRLGenerator method generate.

/**
 * generate an X509 CRL, based on the current issuer and subject, using the passed in provider for
 * the signing.
 */
public X509CRL generate(PrivateKey key, String provider, SecureRandom random) throws CRLException, IllegalStateException, NoSuchProviderException, NoSuchAlgorithmException, SignatureException, InvalidKeyException {
    TBSCertList tbsCrl = generateCertList();
    byte[] signature;
    try {
        signature = X509Util.calculateSignature(sigOID, signatureAlgorithm, provider, key, random, tbsCrl);
    } catch (IOException e) {
        throw new ExtCRLException("cannot generate CRL encoding", e);
    }
    return generateJcaObject(tbsCrl, signature);
}
Also used : TBSCertList(com.github.zhenwei.core.asn1.x509.TBSCertList) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)8 ASN1EncodableVector (com.github.zhenwei.core.asn1.ASN1EncodableVector)4 DERSequence (com.github.zhenwei.core.asn1.DERSequence)4 DERBitString (com.github.zhenwei.core.asn1.DERBitString)3 TBSCertList (com.github.zhenwei.core.asn1.x509.TBSCertList)3 OutputStream (java.io.OutputStream)3 CRLException (java.security.cert.CRLException)3 ObjectOutputStream (java.io.ObjectOutputStream)2 Signature (java.security.Signature)2 SignatureException (java.security.SignatureException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 X500Principal (javax.security.auth.x500.X500Principal)2 CertificateList (org.apache.harmony.security.x509.CertificateList)2 TBSCertList (org.apache.harmony.security.x509.TBSCertList)2 TBSCertList (org.bouncycastle.asn1.x509.TBSCertList)2 ContentVerifier (org.bouncycastle.operator.ContentVerifier)2 ASN1OctetString (com.github.zhenwei.core.asn1.ASN1OctetString)1 ASN1Sequence (com.github.zhenwei.core.asn1.ASN1Sequence)1 DERTaggedObject (com.github.zhenwei.core.asn1.DERTaggedObject)1