Search in sources :

Example 76 with ASN1Encodable

use of com.github.zhenwei.core.asn1.ASN1Encodable in project xades4j by luisgoncalves.

the class SignerSpecificTest method data.

@Parameterized.Parameters
public static Collection<ASN1Encodable[]> data() {
    ArrayList<ASN1Encodable[]> result = new ArrayList<ASN1Encodable[]>();
    result.add(new ASN1Encodable[] { new DERBMPString(NATIONAL_DN_CYRILLIC) });
    result.add(new ASN1Encodable[] { new DERUTF8String(NATIONAL_DN_CYRILLIC) });
    result.add(new ASN1Encodable[] { new DERBMPString(NATIONAL_DN_ARABIC) });
    result.add(new ASN1Encodable[] { new DERUTF8String(NATIONAL_DN_ARABIC) });
    return result;
}
Also used : DERUTF8String(org.bouncycastle.asn1.DERUTF8String) DERBMPString(org.bouncycastle.asn1.DERBMPString) ArrayList(java.util.ArrayList) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable)

Example 77 with ASN1Encodable

use of com.github.zhenwei.core.asn1.ASN1Encodable in project certmgr by hdecarne.

the class PKCS10CertificateRequest method fromPKCS10.

/**
 * Construct {@code PKCS10CertificateRequest} from a PKCS#10 object.
 *
 * @param pkcs10 The PCKS#10 object.
 * @return The constructed {@code PKCS10CertificateRequest}.
 * @throws IOException if an I/O error occurs while accessing the PKCS#10 object.
 */
public static PKCS10CertificateRequest fromPKCS10(PKCS10CertificationRequest pkcs10) throws IOException {
    JcaPKCS10CertificationRequest csr;
    X500Principal subject;
    PublicKey publicKey;
    Map<String, byte[]> criticalExtensions = new HashMap<>();
    Map<String, byte[]> nonCriticalExtensions = new HashMap<>();
    try {
        if (pkcs10 instanceof JcaPKCS10CertificationRequest) {
            csr = (JcaPKCS10CertificationRequest) pkcs10;
        } else {
            csr = new JcaPKCS10CertificationRequest(pkcs10);
        }
        subject = new X500Principal(csr.getSubject().getEncoded());
        publicKey = csr.getPublicKey();
        Attribute[] extensionAttributes = csr.getAttributes(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest);
        if (extensionAttributes != null) {
            for (Attribute extensionAttribute : extensionAttributes) {
                ASN1Encodable[] values = extensionAttribute.getAttributeValues();
                if (values != null) {
                    for (ASN1Encodable value : values) {
                        ASN1Primitive[] extensionPrimitives = decodeSequence(value.toASN1Primitive(), 0, Integer.MAX_VALUE);
                        for (ASN1Primitive extensionPrimitive : extensionPrimitives) {
                            ASN1Primitive[] sequence = decodeSequence(extensionPrimitive, 2, 3);
                            String extensionOID = decodePrimitive(sequence[0], ASN1ObjectIdentifier.class).getId();
                            boolean criticalFlag = true;
                            byte[] extensionData;
                            if (sequence.length == 3) {
                                criticalFlag = decodePrimitive(sequence[1], ASN1Boolean.class).isTrue();
                                extensionData = sequence[2].getEncoded();
                            } else {
                                extensionData = sequence[1].getEncoded();
                            }
                            if (criticalFlag) {
                                criticalExtensions.put(extensionOID, extensionData);
                            } else {
                                nonCriticalExtensions.put(extensionOID, extensionData);
                            }
                        }
                    }
                }
            }
        }
    } catch (GeneralSecurityException e) {
        throw new CertProviderException(e);
    }
    return new PKCS10CertificateRequest(csr, subject, publicKey, criticalExtensions, nonCriticalExtensions);
}
Also used : JcaPKCS10CertificationRequest(org.bouncycastle.pkcs.jcajce.JcaPKCS10CertificationRequest) HashMap(java.util.HashMap) Attribute(org.bouncycastle.asn1.pkcs.Attribute) PublicKey(java.security.PublicKey) GeneralSecurityException(java.security.GeneralSecurityException) CertProviderException(de.carne.certmgr.certs.CertProviderException) X500Principal(javax.security.auth.x500.X500Principal) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) ASN1Primitive(org.bouncycastle.asn1.ASN1Primitive) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 78 with ASN1Encodable

use of com.github.zhenwei.core.asn1.ASN1Encodable in project TLS-Scanner by RUB-NDS.

the class OcspProbe method prepareNonceExtension.

private byte[] prepareNonceExtension() {
    Asn1Sequence innerExtensionSequence = new Asn1Sequence();
    Asn1ObjectIdentifier oid = new Asn1ObjectIdentifier();
    oid.setValue(NONCE.getOID());
    Asn1Sequence extensionSequence = new Asn1Sequence();
    innerExtensionSequence.addChild(oid);
    Asn1EncapsulatingOctetString encapsulatingOctetString = new Asn1EncapsulatingOctetString();
    // Nonce
    Asn1PrimitiveOctetString nonceOctetString = new Asn1PrimitiveOctetString();
    Random rand = new Random(STAPLED_NONCE_RANDOM_SEED);
    BigInteger nonce = new BigInteger(STAPLED_NONCE_RANDOM_BIT_LENGTH, rand);
    nonceOctetString.setValue(nonce.toByteArray());
    encapsulatingOctetString.addChild(nonceOctetString);
    innerExtensionSequence.addChild(encapsulatingOctetString);
    extensionSequence.addChild(innerExtensionSequence);
    List<Asn1Encodable> asn1Encodables = new LinkedList<>();
    asn1Encodables.add(extensionSequence);
    Asn1Encoder asn1Encoder = new Asn1Encoder(asn1Encodables);
    return asn1Encoder.encode();
}
Also used : Random(java.util.Random) Asn1EncapsulatingOctetString(de.rub.nds.asn1.model.Asn1EncapsulatingOctetString) Asn1ObjectIdentifier(de.rub.nds.asn1.model.Asn1ObjectIdentifier) Asn1PrimitiveOctetString(de.rub.nds.asn1.model.Asn1PrimitiveOctetString) BigInteger(java.math.BigInteger) Asn1Sequence(de.rub.nds.asn1.model.Asn1Sequence) Asn1Encoder(de.rub.nds.asn1.encoder.Asn1Encoder) Asn1Encodable(de.rub.nds.asn1.Asn1Encodable) LinkedList(java.util.LinkedList)

Example 79 with ASN1Encodable

use of com.github.zhenwei.core.asn1.ASN1Encodable in project cloudbreak by hortonworks.

the class KrbKeySetEncoder method getASNEncodedKrbPrincipalKey.

public static String getASNEncodedKrbPrincipalKey(List<ActorKerberosKey> keys) throws IOException {
    ASN1Encodable[] asn1Encodables = new ASN1Encodable[keys.size()];
    for (int i = 0; i < keys.size(); i++) {
        ActorKerberosKey key = keys.get(i);
        byte[] byteValue = Base64.getDecoder().decode(key.getKeyValue().getBytes(StandardCharsets.UTF_8));
        asn1Encodables[i] = makeKrbKey(makeSalt(key.getSaltType(), key.getSaltValue()), makeEncryptionKey(key.getKeyType(), byteValue));
    }
    DERSequence krbKeys = new DERSequence(asn1Encodables);
    DERSequence krbKeySet = new DERSequence(new ASN1Encodable[] { // attribute-major-vno
    new DERTaggedObject(true, TAG_ATTRIBUTE_MAJOR_VNO, new ASN1Integer(1)), // attribute-minor-vno
    new DERTaggedObject(true, TAG_ATTRIBUTE_MINOR_VNO, new ASN1Integer(1)), // kvno
    new DERTaggedObject(true, TAG_KVNO, new ASN1Integer(1)), // mkvno
    new DERTaggedObject(true, TAG_MKVNO, new ASN1Integer(1)), new DERTaggedObject(true, TAG_KEYS, krbKeys) });
    return Base64.getEncoder().encodeToString(krbKeySet.getEncoded());
}
Also used : DERSequence(org.bouncycastle.asn1.DERSequence) DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) ActorKerberosKey(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ActorKerberosKey) ASN1Integer(org.bouncycastle.asn1.ASN1Integer)

Example 80 with ASN1Encodable

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

the class CertificateVerifier method extractOCSPURL.

/**
 * Extract the OCSP URL from an X.509 certificate if available.
 *
 * @param cert X.509 certificate
 * @return the URL of the OCSP validation service
 * @throws IOException
 */
private static String extractOCSPURL(X509Certificate cert) throws IOException {
    byte[] authorityExtensionValue = cert.getExtensionValue(Extension.authorityInfoAccess.getId());
    if (authorityExtensionValue != null) {
        // copied from CertInformationHelper.getAuthorityInfoExtensionValue()
        // DRY refactor should be done some day
        ASN1Sequence asn1Seq = (ASN1Sequence) JcaX509ExtensionUtils.parseExtensionValue(authorityExtensionValue);
        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();
                String ocspURL = new String(url.getOctets());
                LOG.info("OCSP URL: " + ocspURL);
                return ocspURL;
            }
        }
    }
    return null;
}
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)

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