Search in sources :

Example 91 with Signature

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

the class TBSCertificate method toASN1Primitive.

public ASN1Primitive toASN1Primitive() {
    if (Properties.getPropertyValue("com.github.zhenwei.provider.x509.allow_non-der_tbscert") != null) {
        if (Properties.isOverrideSet("com.github.zhenwei.provider.x509.allow_non-der_tbscert")) {
            return seq;
        }
    } else {
        return seq;
    }
    ASN1EncodableVector v = new ASN1EncodableVector();
    // DEFAULT Zero
    if (!version.hasValue(0)) {
        v.add(new DERTaggedObject(true, 0, version));
    }
    v.add(serialNumber);
    v.add(signature);
    v.add(issuer);
    // 
    // before and after dates
    // 
    {
        ASN1EncodableVector validity = new ASN1EncodableVector(2);
        validity.add(startDate);
        validity.add(endDate);
        v.add(new DERSequence(validity));
    }
    if (subject != null) {
        v.add(subject);
    } else {
        v.add(new DERSequence());
    }
    v.add(subjectPublicKeyInfo);
    // Note: implicit tag
    if (issuerUniqueId != null) {
        v.add(new DERTaggedObject(false, 1, issuerUniqueId));
    }
    // Note: implicit tag
    if (subjectUniqueId != null) {
        v.add(new DERTaggedObject(false, 2, subjectUniqueId));
    }
    if (extensions != null) {
        v.add(new DERTaggedObject(true, 3, extensions));
    }
    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 92 with Signature

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

the class V1TBSCertificateGenerator method generateTBSCertificate.

public TBSCertificate generateTBSCertificate() {
    if ((serialNumber == null) || (signature == null) || (issuer == null) || (startDate == null) || (endDate == null) || (subject == null) || (subjectPublicKeyInfo == null)) {
        throw new IllegalStateException("not all mandatory fields set in V1 TBScertificate generator");
    }
    ASN1EncodableVector seq = new ASN1EncodableVector(6);
    // seq.add(version); - not required as default value.
    seq.add(serialNumber);
    seq.add(signature);
    seq.add(issuer);
    // 
    // before and after dates
    // 
    {
        ASN1EncodableVector validity = new ASN1EncodableVector(2);
        validity.add(startDate);
        validity.add(endDate);
        seq.add(new DERSequence(validity));
    }
    seq.add(subject);
    seq.add(subjectPublicKeyInfo);
    return TBSCertificate.getInstance(new DERSequence(seq));
}
Also used : DERSequence(com.github.zhenwei.core.asn1.DERSequence) ASN1EncodableVector(com.github.zhenwei.core.asn1.ASN1EncodableVector)

Example 93 with Signature

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

the class V2TBSCertListGenerator method generateTBSCertList.

public TBSCertList generateTBSCertList() {
    if ((signature == null) || (issuer == null) || (thisUpdate == null)) {
        throw new IllegalStateException("Not all mandatory fields set in V2 TBSCertList generator.");
    }
    ASN1EncodableVector v = new ASN1EncodableVector(7);
    v.add(version);
    v.add(signature);
    v.add(issuer);
    v.add(thisUpdate);
    if (nextUpdate != null) {
        v.add(nextUpdate);
    }
    // Add CRLEntries if they exist
    if (crlentries.size() != 0) {
        v.add(new DERSequence(crlentries));
    }
    if (extensions != null) {
        v.add(new DERTaggedObject(0, extensions));
    }
    return new TBSCertList(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 94 with Signature

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

the class Signature method toASN1Primitive.

/**
 * Produce an object suitable for an ASN1OutputStream.
 * <pre>
 * Signature       ::=     SEQUENCE {
 *     signatureAlgorithm      AlgorithmIdentifier,
 *     signature               BIT STRING,
 *     certs               [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL}
 * </pre>
 */
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector(3);
    v.add(signatureAlgorithm);
    v.add(signature);
    if (certs != null) {
        v.add(new DERTaggedObject(true, 0, certs));
    }
    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 95 with Signature

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

the class BasicOCSPResponse method toASN1Primitive.

/**
 * Produce an object suitable for an ASN1OutputStream.
 * <pre>
 * BasicOCSPResponse       ::= SEQUENCE {
 *      tbsResponseData      ResponseData,
 *      signatureAlgorithm   AlgorithmIdentifier,
 *      signature            BIT STRING,
 *      certs                [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL }
 * </pre>
 */
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector(4);
    v.add(tbsResponseData);
    v.add(signatureAlgorithm);
    v.add(signature);
    if (certs != null) {
        v.add(new DERTaggedObject(true, 0, certs));
    }
    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)

Aggregations

IOException (java.io.IOException)44 ASN1EncodableVector (com.github.zhenwei.core.asn1.ASN1EncodableVector)34 DERSequence (com.github.zhenwei.core.asn1.DERSequence)29 DERBitString (com.github.zhenwei.core.asn1.DERBitString)21 AlgorithmIdentifier (com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)20 OutputStream (java.io.OutputStream)20 SignatureException (java.security.SignatureException)20 GeneralSecurityException (java.security.GeneralSecurityException)15 Signature (java.security.Signature)15 ASN1ObjectIdentifier (com.github.zhenwei.core.asn1.ASN1ObjectIdentifier)14 DEROctetString (com.github.zhenwei.core.asn1.DEROctetString)14 InvalidKeyException (java.security.InvalidKeyException)13 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)13 Iterator (java.util.Iterator)13 OperatorCreationException (com.github.zhenwei.pkix.operator.OperatorCreationException)11 CertificateEncodingException (java.security.cert.CertificateEncodingException)11 NoSuchProviderException (java.security.NoSuchProviderException)10 ASN1OctetString (com.github.zhenwei.core.asn1.ASN1OctetString)9 ASN1Sequence (com.github.zhenwei.core.asn1.ASN1Sequence)9 List (java.util.List)9