Search in sources :

Example 11 with DEROutputStream

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

the class X509CRLObject method getSigAlgParams.

@Override
public byte[] getSigAlgParams() {
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    if (c.getSignatureAlgorithm().getParameters() != null) {
        try {
            DEROutputStream dOut = new DEROutputStream(bOut);
            dOut.writeObject(c.getSignatureAlgorithm().getParameters());
        } catch (Exception e) {
            throw new RuntimeException("exception getting sig parameters " + e);
        }
        return bOut.toByteArray();
    }
    return null;
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) DEROutputStream(org.gudy.bouncycastle.asn1.DEROutputStream)

Example 12 with DEROutputStream

use of org.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 13 with DEROutputStream

use of org.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 14 with DEROutputStream

use of org.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 15 with DEROutputStream

use of org.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)

Aggregations

IOException (java.io.IOException)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)14 DEROutputStream (org.bouncycastle.asn1.DEROutputStream)12 DEROutputStream (org.gudy.bouncycastle.asn1.DEROutputStream)9 X509Certificate (java.security.cert.X509Certificate)6 OutputStream (java.io.OutputStream)4 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)4 ArrayList (java.util.ArrayList)3 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)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 KeyStoreException (java.security.KeyStoreException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 PrivateKey (java.security.PrivateKey)2