Search in sources :

Example 16 with ASN1Set

use of com.github.zhenwei.core.asn1.ASN1Set in project AttestationServer by GrapheneOS.

the class AttestationApplicationId method parseAttestationPackageInfos.

private List<AttestationPackageInfo> parseAttestationPackageInfos(ASN1Encodable asn1Encodable) throws CertificateParsingException {
    if (!(asn1Encodable instanceof ASN1Set)) {
        throw new CertificateParsingException("Expected set for AttestationApplicationsInfos, found " + asn1Encodable.getClass().getName());
    }
    ASN1Set set = (ASN1Set) asn1Encodable;
    List<AttestationPackageInfo> result = new ArrayList<>();
    for (ASN1Encodable e : set) {
        result.add(new AttestationPackageInfo(e));
    }
    return result;
}
Also used : CertificateParsingException(java.security.cert.CertificateParsingException) ASN1Set(org.bouncycastle.asn1.ASN1Set) ArrayList(java.util.ArrayList) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable)

Example 17 with ASN1Set

use of com.github.zhenwei.core.asn1.ASN1Set in project gdmatrix by gdmatrix.

the class P7MUtils method printAttribute.

public static void printAttribute(Attribute attribute) throws Exception {
    ASN1Set set = attribute.getAttrValues();
    ASN1Primitive der = set.getObjectAt(0).toASN1Primitive();
    System.out.println(der.getClass());
    if (der instanceof DEROctetString) {
        DEROctetString octet = (DEROctetString) der;
        byte[] data = octet.getOctets();
        System.out.println(new String(data, "UTF-16LE"));
    } else if (der instanceof ASN1UTCTime) {
        ASN1UTCTime utcTime = (ASN1UTCTime) der;
        String time = utcTime.getAdjustedTime();
        System.out.println(time);
    } else if (der instanceof ASN1ObjectIdentifier) {
        ASN1ObjectIdentifier id = (ASN1ObjectIdentifier) der;
        System.out.println(id.getId());
    }
}
Also used : ASN1Set(org.bouncycastle.asn1.ASN1Set) ASN1UTCTime(org.bouncycastle.asn1.ASN1UTCTime) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) DEROctetString(org.bouncycastle.asn1.DEROctetString) ASN1Primitive(org.bouncycastle.asn1.ASN1Primitive) DEROctetString(org.bouncycastle.asn1.DEROctetString) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 18 with ASN1Set

use of com.github.zhenwei.core.asn1.ASN1Set in project ca3sCore by kuehne-trustable-de.

the class CertificateUtil method getSANList.

public Set<GeneralName> getSANList(Pkcs10RequestHolder p10ReqHolder) {
    Set<GeneralName> generalNameSet = new HashSet<>();
    for (Attribute attr : p10ReqHolder.getReqAttributes()) {
        if (PKCSObjectIdentifiers.pkcs_9_at_extensionRequest.equals(attr.getAttrType())) {
            ASN1Set valueSet = attr.getAttrValues();
            LOG.debug("ExtensionRequest / AttrValues has {} elements", valueSet.size());
            for (ASN1Encodable asn1Enc : valueSet) {
                DERSequence derSeq = (DERSequence) asn1Enc;
                LOG.debug("ExtensionRequest / DERSequence has {} elements", derSeq.size());
                LOG.debug("ExtensionRequest / DERSequence[0] is a  {}", derSeq.getObjectAt(0).getClass().getName());
                DERSequence derSeq2 = (DERSequence) derSeq.getObjectAt(0);
                LOG.debug("ExtensionRequest / DERSequence2 has {} elements", derSeq2.size());
                LOG.debug("ExtensionRequest / DERSequence2[0] is a  {}", derSeq2.getObjectAt(0).getClass().getName());
                ASN1ObjectIdentifier objId = (ASN1ObjectIdentifier) (derSeq2.getObjectAt(0));
                if (Extension.subjectAlternativeName.equals(objId)) {
                    DEROctetString derStr = (DEROctetString) derSeq2.getObjectAt(1);
                    GeneralNames names = GeneralNames.getInstance(derStr.getOctets());
                    LOG.debug("Attribute value SAN" + names);
                    LOG.debug("SAN values #" + names.getNames().length);
                    for (GeneralName gnSAN : names.getNames()) {
                        LOG.debug("GN " + gnSAN.toString());
                        generalNameSet.add(gnSAN);
                    }
                } else {
                    LOG.info("Unexpected Extensions Attribute value " + objId.getId());
                }
            }
        }
    }
    return generalNameSet;
}
Also used : DERSequence(org.bouncycastle.asn1.DERSequence) ASN1Set(org.bouncycastle.asn1.ASN1Set) Attribute(org.bouncycastle.asn1.pkcs.Attribute) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier) DEROctetString(org.bouncycastle.asn1.DEROctetString)

Example 19 with ASN1Set

use of com.github.zhenwei.core.asn1.ASN1Set in project Auditor by GrapheneOS.

the class AttestationApplicationId method parseAttestationPackageInfos.

private List<AttestationPackageInfo> parseAttestationPackageInfos(ASN1Encodable asn1Encodable) throws CertificateParsingException {
    if (!(asn1Encodable instanceof ASN1Set)) {
        throw new CertificateParsingException("Expected set for AttestationApplicationsInfos, found " + asn1Encodable.getClass().getName());
    }
    ASN1Set set = (ASN1Set) asn1Encodable;
    List<AttestationPackageInfo> result = new ArrayList<>();
    for (ASN1Encodable e : set) {
        result.add(new AttestationPackageInfo(e));
    }
    return result;
}
Also used : CertificateParsingException(java.security.cert.CertificateParsingException) ASN1Set(org.bouncycastle.asn1.ASN1Set) ArrayList(java.util.ArrayList) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable)

Example 20 with ASN1Set

use of com.github.zhenwei.core.asn1.ASN1Set in project Falcon-File-Transfer-Optimizer by arif-zaman.

the class X509NameHelper method toString.

private static String toString(ASN1Sequence seq) {
    if (seq == null) {
        return null;
    }
    Enumeration e = seq.getObjects();
    StringBuffer buf = new StringBuffer();
    while (e.hasMoreElements()) {
        ASN1Set set = (ASN1Set) e.nextElement();
        Enumeration ee = set.getObjects();
        buf.append('/');
        while (ee.hasMoreElements()) {
            ASN1Sequence s = (ASN1Sequence) ee.nextElement();
            ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) s.getObjectAt(0);
            String sym = (String) X509Name.DefaultSymbols.get(oid);
            if (sym == null) {
                buf.append(oid.getId());
            } else {
                buf.append(sym);
            }
            buf.append('=');
            buf.append(((ASN1String) s.getObjectAt(1)).getString());
            if (ee.hasMoreElements()) {
                buf.append('+');
            }
        }
    }
    return buf.toString();
}
Also used : Enumeration(java.util.Enumeration) ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) ASN1Set(org.bouncycastle.asn1.ASN1Set) DERPrintableString(org.bouncycastle.asn1.DERPrintableString) ASN1String(org.bouncycastle.asn1.ASN1String) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Aggregations

ASN1Set (org.bouncycastle.asn1.ASN1Set)67 ArrayList (java.util.ArrayList)51 IOException (java.io.IOException)34 ASN1Set (com.unboundid.asn1.ASN1Set)33 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)30 ASN1Sequence (com.unboundid.asn1.ASN1Sequence)30 ASN1Set (com.github.zhenwei.core.asn1.ASN1Set)26 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)22 ASN1Element (com.unboundid.asn1.ASN1Element)21 NotNull (com.unboundid.util.NotNull)21 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)19 List (java.util.List)17 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)17 DEROctetString (org.bouncycastle.asn1.DEROctetString)16 Enumeration (java.util.Enumeration)15 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)14 OutputStream (java.io.OutputStream)12 Test (org.testng.annotations.Test)12 AlgorithmIdentifier (com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)11 ASN1Enumerated (com.unboundid.asn1.ASN1Enumerated)11