Search in sources :

Example 1 with TBSCertificateStructure

use of org.gudy.bouncycastle.asn1.x509.TBSCertificateStructure in project XobotOS by xamarin.

the class X509V3CertificateGenerator method generateJcaObject.

private X509Certificate generateJcaObject(TBSCertificateStructure tbsCert, byte[] signature) throws CertificateParsingException {
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(tbsCert);
    v.add(sigAlgId);
    v.add(new DERBitString(signature));
    return new X509CertificateObject(new X509CertificateStructure(new DERSequence(v)));
}
Also used : DERSequence(org.bouncycastle.asn1.DERSequence) X509CertificateObject(org.bouncycastle.jce.provider.X509CertificateObject) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) DERBitString(org.bouncycastle.asn1.DERBitString) X509CertificateStructure(org.bouncycastle.asn1.x509.X509CertificateStructure)

Example 2 with TBSCertificateStructure

use of org.gudy.bouncycastle.asn1.x509.TBSCertificateStructure in project XobotOS by xamarin.

the class X509V1CertificateGenerator method generate.

/**
     * generate an X509 certificate, based on the current issuer and subject
     * using the default provider and the passed in source of randomness
     * <p>
     * <b>Note:</b> this differs from the deprecated method in that the default provider is
     * used - not "BC".
     * </p>
     */
public X509Certificate generate(PrivateKey key, SecureRandom random) throws CertificateEncodingException, IllegalStateException, NoSuchAlgorithmException, SignatureException, InvalidKeyException {
    TBSCertificateStructure tbsCert = tbsGen.generateTBSCertificate();
    byte[] signature;
    try {
        signature = X509Util.calculateSignature(sigOID, signatureAlgorithm, key, random, tbsCert);
    } catch (IOException e) {
        throw new ExtCertificateEncodingException("exception encoding TBS cert", e);
    }
    return generateJcaObject(tbsCert, signature);
}
Also used : TBSCertificateStructure(org.bouncycastle.asn1.x509.TBSCertificateStructure) IOException(java.io.IOException)

Example 3 with TBSCertificateStructure

use of org.gudy.bouncycastle.asn1.x509.TBSCertificateStructure in project XobotOS by xamarin.

the class X509V1CertificateGenerator method generateJcaObject.

private X509Certificate generateJcaObject(TBSCertificateStructure tbsCert, byte[] signature) throws CertificateEncodingException {
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(tbsCert);
    v.add(sigAlgId);
    v.add(new DERBitString(signature));
    try {
        return new X509CertificateObject(new X509CertificateStructure(new DERSequence(v)));
    } catch (CertificateParsingException e) {
        throw new ExtCertificateEncodingException("exception producing certificate object", e);
    }
}
Also used : DERSequence(org.bouncycastle.asn1.DERSequence) CertificateParsingException(java.security.cert.CertificateParsingException) X509CertificateObject(org.bouncycastle.jce.provider.X509CertificateObject) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) DERBitString(org.bouncycastle.asn1.DERBitString) X509CertificateStructure(org.bouncycastle.asn1.x509.X509CertificateStructure)

Example 4 with TBSCertificateStructure

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

the class PrincipalUtil method getSubjectX509Principal.

/**
 * return the subject of the given cert as an X509PrincipalObject.
 */
public static X509Principal getSubjectX509Principal(X509Certificate cert) throws CertificateEncodingException {
    try {
        ByteArrayInputStream bIn = new ByteArrayInputStream(cert.getTBSCertificate());
        ASN1InputStream aIn = new ASN1InputStream(bIn);
        TBSCertificateStructure tbsCert = new TBSCertificateStructure((ASN1Sequence) aIn.readObject());
        return new X509Principal(tbsCert.getSubject());
    } catch (IOException e) {
        throw new CertificateEncodingException(e.toString());
    }
}
Also used : ASN1InputStream(org.gudy.bouncycastle.asn1.ASN1InputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) TBSCertificateStructure(org.gudy.bouncycastle.asn1.x509.TBSCertificateStructure) CertificateEncodingException(java.security.cert.CertificateEncodingException) IOException(java.io.IOException)

Example 5 with TBSCertificateStructure

use of org.gudy.bouncycastle.asn1.x509.TBSCertificateStructure in project XobotOS by xamarin.

the class X509V3CertificateGenerator method generate.

/**
     * generate an X509 certificate, based on the current issuer and subject,
     * using the passed in provider for the signing and the supplied source
     * of randomness, if required.
     */
public X509Certificate generate(PrivateKey key, String provider, SecureRandom random) throws CertificateEncodingException, IllegalStateException, NoSuchProviderException, NoSuchAlgorithmException, SignatureException, InvalidKeyException {
    TBSCertificateStructure tbsCert = generateTbsCert();
    byte[] signature;
    try {
        signature = X509Util.calculateSignature(sigOID, signatureAlgorithm, provider, key, random, tbsCert);
    } catch (IOException e) {
        throw new ExtCertificateEncodingException("exception encoding TBS cert", e);
    }
    try {
        return generateJcaObject(tbsCert, signature);
    } catch (CertificateParsingException e) {
        throw new ExtCertificateEncodingException("exception producing certificate object", e);
    }
}
Also used : CertificateParsingException(java.security.cert.CertificateParsingException) TBSCertificateStructure(org.bouncycastle.asn1.x509.TBSCertificateStructure) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)6 TBSCertificateStructure (org.bouncycastle.asn1.x509.TBSCertificateStructure)6 CertificateParsingException (java.security.cert.CertificateParsingException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 CertificateEncodingException (java.security.cert.CertificateEncodingException)2 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)2 DERBitString (org.bouncycastle.asn1.DERBitString)2 DERObject (org.bouncycastle.asn1.DERObject)2 DERSequence (org.bouncycastle.asn1.DERSequence)2 X509CertificateStructure (org.bouncycastle.asn1.x509.X509CertificateStructure)2 X509CertificateObject (org.bouncycastle.jce.provider.X509CertificateObject)2 ASN1InputStream (org.gudy.bouncycastle.asn1.ASN1InputStream)2 TBSCertificateStructure (org.gudy.bouncycastle.asn1.x509.TBSCertificateStructure)2 PolicyProcessException (org.nhindirect.policy.PolicyProcessException)2 DERObjectIdentifier (org.bouncycastle.asn1.DERObjectIdentifier)1 X509Name (org.bouncycastle.asn1.x509.X509Name)1 PolicyRequiredException (org.nhindirect.policy.PolicyRequiredException)1