Search in sources :

Example 16 with DEROutputStream

use of org.gudy.bouncycastle.asn1.DEROutputStream 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 17 with DEROutputStream

use of org.gudy.bouncycastle.asn1.DEROutputStream in project robovm by robovm.

the class X509CertificateHolder method isSignatureValid.

/**
     * Validate the signature on the certificate in this holder.
     *
     * @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 {
    TBSCertificate tbsCert = x509Certificate.getTBSCertificate();
    if (!CertUtils.isAlgIdEqual(tbsCert.getSignature(), x509Certificate.getSignatureAlgorithm())) {
        throw new CertException("signature invalid - algorithm identifier mismatch");
    }
    ContentVerifier verifier;
    try {
        verifier = verifierProvider.get((tbsCert.getSignature()));
        OutputStream sOut = verifier.getOutputStream();
        DEROutputStream dOut = new DEROutputStream(sOut);
        dOut.writeObject(tbsCert);
        sOut.close();
    } catch (Exception e) {
        throw new CertException("unable to process signature: " + e.getMessage(), e);
    }
    return verifier.verify(x509Certificate.getSignature().getBytes());
}
Also used : ContentVerifier(org.bouncycastle.operator.ContentVerifier) OutputStream(java.io.OutputStream) DEROutputStream(org.bouncycastle.asn1.DEROutputStream) TBSCertificate(org.bouncycastle.asn1.x509.TBSCertificate) IOException(java.io.IOException) DEROutputStream(org.bouncycastle.asn1.DEROutputStream)

Example 18 with DEROutputStream

use of org.gudy.bouncycastle.asn1.DEROutputStream in project BiglyBT by BiglySoftware.

the class X509CRLEntryObject method getEncoded.

@Override
public byte[] getEncoded() throws CRLException {
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    DEROutputStream dOut = new DEROutputStream(bOut);
    try {
        dOut.writeObject(c);
        return bOut.toByteArray();
    } catch (IOException e) {
        throw new CRLException(e.toString());
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) CRLException(java.security.cert.CRLException) DEROutputStream(org.gudy.bouncycastle.asn1.DEROutputStream)

Example 19 with DEROutputStream

use of org.gudy.bouncycastle.asn1.DEROutputStream in project BiglyBT by BiglySoftware.

the class X509CRLObject method getEncoded.

@Override
public byte[] getEncoded() throws CRLException {
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    DEROutputStream dOut = new DEROutputStream(bOut);
    try {
        dOut.writeObject(c);
        return bOut.toByteArray();
    } catch (IOException e) {
        throw new CRLException(e.toString());
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) DEROutputStream(org.gudy.bouncycastle.asn1.DEROutputStream)

Example 20 with DEROutputStream

use of org.gudy.bouncycastle.asn1.DEROutputStream in project BiglyBT by BiglySoftware.

the class X509CRLObject method getTBSCertList.

@Override
public byte[] getTBSCertList() throws CRLException {
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    DEROutputStream dOut = new DEROutputStream(bOut);
    try {
        dOut.writeObject(c.getTBSCertList());
        return bOut.toByteArray();
    } catch (IOException e) {
        throw new CRLException(e.toString());
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) DEROutputStream(org.gudy.bouncycastle.asn1.DEROutputStream)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)20 IOException (java.io.IOException)20 DEROutputStream (org.bouncycastle.asn1.DEROutputStream)13 DEROutputStream (org.gudy.bouncycastle.asn1.DEROutputStream)9 X509Certificate (java.security.cert.X509Certificate)7 OutputStream (java.io.OutputStream)4 AlgorithmIdentifier (org.gudy.bouncycastle.asn1.x509.AlgorithmIdentifier)4 CertificateException (java.security.cert.CertificateException)3 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)3 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)3 DEROctetString (org.bouncycastle.asn1.DEROctetString)3 DERSequence (org.bouncycastle.asn1.DERSequence)3 JcaCertStore (org.bouncycastle.cert.jcajce.JcaCertStore)3 CMSSignedData (org.bouncycastle.cms.CMSSignedData)3 CMSSignedDataGenerator (org.bouncycastle.cms.CMSSignedDataGenerator)3 ContentSigner (org.bouncycastle.operator.ContentSigner)3 JcaContentSignerBuilder (org.bouncycastle.operator.jcajce.JcaContentSignerBuilder)3 JcaDigestCalculatorProviderBuilder (org.bouncycastle.operator.jcajce.JcaDigestCalculatorProviderBuilder)3 X509Extension (org.gudy.bouncycastle.asn1.x509.X509Extension)3 KeyStoreException (java.security.KeyStoreException)2