Search in sources :

Example 81 with ASN1Encodable

use of com.github.zhenwei.core.asn1.ASN1Encodable in project pdfbox by apache.

the class CertInformationHelper method getAuthorityInfoExtensionValue.

/**
 * Extracts authority information access extension values from the given data. The Data
 * structure has to be implemented as described in RFC 2459, 4.2.2.1.
 *
 * @param extensionValue byte[] of the extension value.
 * @param certInfo where to put the found values
 * @throws IOException when there is a problem with the extensionValue
 */
protected static void getAuthorityInfoExtensionValue(byte[] extensionValue, CertSignatureInformation certInfo) throws IOException {
    ASN1Sequence asn1Seq = (ASN1Sequence) JcaX509ExtensionUtils.parseExtensionValue(extensionValue);
    Enumeration<?> objects = asn1Seq.getObjects();
    while (objects.hasMoreElements()) {
        // AccessDescription
        ASN1Sequence obj = (ASN1Sequence) objects.nextElement();
        ASN1Encodable oid = obj.getObjectAt(0);
        // accessLocation
        ASN1TaggedObject location = (ASN1TaggedObject) obj.getObjectAt(1);
        if (X509ObjectIdentifiers.id_ad_ocsp.equals(oid) && location.getTagNo() == GeneralName.uniformResourceIdentifier) {
            ASN1OctetString url = (ASN1OctetString) location.getBaseObject();
            certInfo.setOcspUrl(new String(url.getOctets()));
        } else if (X509ObjectIdentifiers.id_ad_caIssuers.equals(oid)) {
            ASN1OctetString uri = (ASN1OctetString) location.getBaseObject();
            certInfo.setIssuerUrl(new String(uri.getOctets()));
        }
    }
}
Also used : ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) ASN1TaggedObject(org.bouncycastle.asn1.ASN1TaggedObject) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString)

Example 82 with ASN1Encodable

use of com.github.zhenwei.core.asn1.ASN1Encodable in project keystore-explorer by kaikramer.

the class Pkcs10Util method getExtensions.

/**
 * Extract sequence with extensions from CSR
 *
 * @param pkcs10Csr The CSR
 * @return Extensions from that CSR (if any)
 */
public static X509ExtensionSet getExtensions(PKCS10CertificationRequest pkcs10Csr) {
    Attribute[] attributes = pkcs10Csr.getAttributes(pkcs_9_at_extensionRequest);
    X509ExtensionSet x509ExtensionSet = new X509ExtensionSet();
    if ((attributes != null) && (attributes.length > 0)) {
        ASN1Encodable[] attributeValues = attributes[0].getAttributeValues();
        if (attributeValues.length > 0) {
            ASN1Sequence asn1Sequence = ASN1Sequence.getInstance(attributeValues[0]);
            x509ExtensionSet = new X509ExtensionSet(asn1Sequence);
        }
    }
    return x509ExtensionSet;
}
Also used : X509ExtensionSet(org.kse.crypto.x509.X509ExtensionSet) ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) Attribute(org.bouncycastle.asn1.pkcs.Attribute) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable)

Example 83 with ASN1Encodable

use of com.github.zhenwei.core.asn1.ASN1Encodable in project keystore-explorer by kaikramer.

the class EccUtil method convertToECPrivateKeyStructure.

/**
 * Converts PKCS#8 EC private key (RFC 5208/5958 ASN.1 PrivateKeyInfo structure) to "traditional" OpenSSL
 * ASN.1 structure ECPrivateKey from RFC 5915. As ECPrivateKey is already in the PrivateKey field of PrivateKeyInfo,
 * this must only be extracted:
 * <p>
 * SEQUENCE {
 * INTEGER 0
 * SEQUENCE {
 * OBJECT IDENTIFIER ecPublicKey (1 2 840 10045 2 1)
 * OBJECT IDENTIFIER prime256v1 (1 2 840 10045 3 1 7)
 * }
 * OCTET STRING, encapsulates {
 * SEQUENCE {
 * INTEGER 1
 * OCTET STRING
 * 17 12 CA 42 16 79 1B 45    ...B.y.E
 * ...
 * C8 B2 66 0A E5 60 50 0B
 * [0] {
 * OBJECT IDENTIFIER prime256v1 (1 2 840 10045 3 1 7)
 * }
 * [1] {
 * BIT STRING
 * 04 61 C0 08 B4 89 A0 50    .a.....P
 * ...
 * AE D5 ED C3 4D 0E 47 91    ....M.G.
 * 89                         .
 * }
 * }
 * }
 * }
 *
 * @param ecPrivateKey An EC key
 * @return Object holding ASN1 ECPrivateKey structure
 * @throws IOException When ECPrivateKey structure in PrivateKeyInfo's PrivateKey field cannot be parsed
 */
public static org.bouncycastle.asn1.sec.ECPrivateKey convertToECPrivateKeyStructure(ECPrivateKey ecPrivateKey) throws IOException {
    PrivateKeyInfo privateKeyInfo = PrivateKeyInfo.getInstance(ecPrivateKey.getEncoded());
    ASN1Encodable privateKey = privateKeyInfo.parsePrivateKey();
    return org.bouncycastle.asn1.sec.ECPrivateKey.getInstance(privateKey);
}
Also used : ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) PrivateKeyInfo(org.bouncycastle.asn1.pkcs.PrivateKeyInfo)

Example 84 with ASN1Encodable

use of com.github.zhenwei.core.asn1.ASN1Encodable in project keystore-explorer by kaikramer.

the class RdnPanelList method getRdns.

public List<RDN> getRdns(boolean noEmptyRdns) {
    List<RDN> rdns = new ArrayList<>();
    for (RdnPanel rdnPanel : entries) {
        ASN1ObjectIdentifier attrType = OidDisplayNameMapping.getOidForDisplayName(rdnPanel.getAttributeName());
        if (noEmptyRdns && StringUtils.trimAndConvertEmptyToNull(rdnPanel.getAttributeValue()) == null) {
            continue;
        }
        ASN1Encodable attrValue = KseX500NameStyle.INSTANCE.stringToValue(attrType, rdnPanel.getAttributeValue());
        rdns.add(new RDN(new AttributeTypeAndValue(attrType, attrValue)));
    }
    return rdns;
}
Also used : ArrayList(java.util.ArrayList) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) RDN(org.bouncycastle.asn1.x500.RDN) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier) AttributeTypeAndValue(org.bouncycastle.asn1.x500.AttributeTypeAndValue)

Example 85 with ASN1Encodable

use of com.github.zhenwei.core.asn1.ASN1Encodable in project keystore-explorer by kaikramer.

the class DPolicyQualifierInfoChooser method populate.

private void populate(PolicyQualifierInfo policyQualifierInfo) throws IOException {
    if (policyQualifierInfo == null) {
        jrbCps.setSelected(true);
    } else {
        ASN1ObjectIdentifier policyQualifierId = policyQualifierInfo.getPolicyQualifierId();
        if (policyQualifierId.equals(new ASN1ObjectIdentifier(PKIX_CPS_POINTER_QUALIFIER.oid()))) {
            jrbCps.setSelected(true);
            jtfCps.setText(((DERIA5String) policyQualifierInfo.getQualifier()).getString());
            jtfCps.setCaretPosition(0);
        } else if (policyQualifierId.equals(new ASN1ObjectIdentifier(PKIX_USER_NOTICE_QUALIFIER.oid()))) {
            jrbUserNotice.setSelected(true);
            ASN1Encodable userNoticeObj = policyQualifierInfo.getQualifier();
            UserNotice userNotice = UserNotice.getInstance(userNoticeObj);
            junUserNotice.setUserNotice(userNotice);
        } else {
            jrbCps.setSelected(true);
        }
    }
}
Also used : UserNotice(org.bouncycastle.asn1.x509.UserNotice) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Aggregations

ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)209 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)89 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)76 IOException (java.io.IOException)72 ASN1Encodable (com.github.zhenwei.core.asn1.ASN1Encodable)58 ArrayList (java.util.ArrayList)45 DEROctetString (org.bouncycastle.asn1.DEROctetString)43 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)42 DERSequence (org.bouncycastle.asn1.DERSequence)35 BigInteger (java.math.BigInteger)31 ASN1Primitive (org.bouncycastle.asn1.ASN1Primitive)30 DERIA5String (org.bouncycastle.asn1.DERIA5String)30 X509Certificate (java.security.cert.X509Certificate)29 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)29 DERUTF8String (org.bouncycastle.asn1.DERUTF8String)29 GeneralName (org.bouncycastle.asn1.x509.GeneralName)26 List (java.util.List)25 ASN1ObjectIdentifier (com.github.zhenwei.core.asn1.ASN1ObjectIdentifier)24 HashSet (java.util.HashSet)24 ASN1TaggedObject (org.bouncycastle.asn1.ASN1TaggedObject)23