Search in sources :

Example 66 with DEROctetString

use of org.spongycastle.asn1.DEROctetString in project signer by demoiselle.

the class BasicCertificate method getExtensionValue.

/**
 * Gets the contents of a given OID
 *
 * @param oid Object Identifier (OID)
 *
 * @return org.bouncycastle.asn1.ASN1Primitive Content related to the reported OID
 */
public ASN1Primitive getExtensionValue(String oid) {
    byte[] extensionValue = certificate.getExtensionValue(oid);
    if (extensionValue == null) {
        return null;
    }
    try {
        varASN1InputStream = new ASN1InputStream(extensionValue);
        DEROctetString oct = (DEROctetString) varASN1InputStream.readObject();
        varASN1InputStream = new ASN1InputStream(oct.getOctets());
        return varASN1InputStream.readObject();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : ASN1InputStream(org.bouncycastle.asn1.ASN1InputStream) IOException(java.io.IOException) DEROctetString(org.bouncycastle.asn1.DEROctetString)

Example 67 with DEROctetString

use of org.spongycastle.asn1.DEROctetString in project signer by demoiselle.

the class PolicyIssuerName method parse.

@Override
public void parse(ASN1Primitive primitive) {
    if (primitive instanceof DLSequence) {
        DLSequence sequence = (DLSequence) primitive;
        ASN1Encodable asn1Encodable = sequence.getObjectAt(0);
        if (asn1Encodable instanceof DERTaggedObject) {
            DERTaggedObject derTaggedObject = (DERTaggedObject) asn1Encodable;
            ASN1Primitive object = derTaggedObject.getObject();
            if (object instanceof DEROctetString) {
                OctetString octetString = new OctetString();
                octetString.parse(object);
                this.issuerName = octetString.getValueUTF8();
            } else if (object instanceof DERSequence) {
                DERSequence sequence2 = (DERSequence) object;
                for (int i = 0; i < sequence2.size(); i++) {
                    ASN1Encodable obj = sequence2.getObjectAt(i);
                    if (obj instanceof DERSet) {
                        DERSet set = (DERSet) obj;
                        ASN1Encodable object2 = set.getObjectAt(0);
                        if (object2 instanceof DERSequence) {
                            DERSequence sequence3 = (DERSequence) object2;
                            ObjectIdentifier objectIdendifier = new ObjectIdentifier();
                            objectIdendifier.parse(sequence3.getObjectAt(0).toASN1Primitive());
                            String name = null;
                            ASN1Encodable object3 = sequence3.getObjectAt(1);
                            if (object3 instanceof DERPrintableString) {
                                name = ((DERPrintableString) object3).getString();
                            } else if (object3 instanceof DERUTF8String) {
                                name = ((DERUTF8String) object3).getString();
                            } else {
                                System.out.println(policyMessagesBundle.getString("error.not.recognized.object", object3.getClass(), object3.toString()));
                            }
                            if (this.issuerNames == null) {
                                this.issuerNames = new HashMap<ObjectIdentifier, String>();
                            }
                            this.issuerNames.put(objectIdendifier, name);
                        }
                    }
                }
            }
        }
    }
}
Also used : DEROctetString(org.bouncycastle.asn1.DEROctetString) DERUTF8String(org.bouncycastle.asn1.DERUTF8String) HashMap(java.util.HashMap) DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) DERUTF8String(org.bouncycastle.asn1.DERUTF8String) DEROctetString(org.bouncycastle.asn1.DEROctetString) DERPrintableString(org.bouncycastle.asn1.DERPrintableString) DERSet(org.bouncycastle.asn1.DERSet) DEROctetString(org.bouncycastle.asn1.DEROctetString) DERSequence(org.bouncycastle.asn1.DERSequence) DLSequence(org.bouncycastle.asn1.DLSequence) DERPrintableString(org.bouncycastle.asn1.DERPrintableString) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) ASN1Primitive(org.bouncycastle.asn1.ASN1Primitive)

Example 68 with DEROctetString

use of org.spongycastle.asn1.DEROctetString in project signer by demoiselle.

the class SignaturePolicy method parse.

public void parse(ASN1Primitive derObject) {
    ASN1Sequence derSequence = ASN1Object.getDERSequence(derObject);
    this.signPolicyHashAlg = new AlgorithmIdentifier();
    this.signPolicyHashAlg.parse(derSequence.getObjectAt(0).toASN1Primitive());
    this.signPolicyInfo = new SignPolicyInfo();
    this.signPolicyInfo.parse(derSequence.getObjectAt(1).toASN1Primitive());
    if (derSequence.size() == 3) {
        this.signPolicyHash = new SignPolicyHash((DEROctetString) derSequence.getObjectAt(2));
    }
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) DEROctetString(org.bouncycastle.asn1.DEROctetString)

Example 69 with DEROctetString

use of org.spongycastle.asn1.DEROctetString in project signer by demoiselle.

the class OctetString method parse.

@Override
public void parse(ASN1Primitive derObject) {
    if (derObject instanceof DEROctetString) {
        this.derOctetString = (DEROctetString) derObject;
        String octetString = derOctetString.toString();
        octetString = octetString.substring(1);
        this.setValue(octetString);
    }
}
Also used : DEROctetString(org.bouncycastle.asn1.DEROctetString) DEROctetString(org.bouncycastle.asn1.DEROctetString)

Example 70 with DEROctetString

use of org.spongycastle.asn1.DEROctetString in project signer by demoiselle.

the class PolicyInfo method parse.

@Override
public void parse(ASN1Primitive primitive) {
    ASN1Sequence sequence1 = ASN1Object.getDERSequence(primitive);
    this.signingPeriod = new SigningPeriod();
    this.signingPeriod.parse(sequence1.getObjectAt(0).toASN1Primitive());
    int indice = 2;
    ASN1Primitive secondObject = sequence1.getObjectAt(1).toASN1Primitive();
    if (secondObject instanceof ASN1ObjectIdentifier) {
        indice = 1;
    }
    if (indice == 2) {
        this.revocationDate = new GeneralizedTime();
        this.revocationDate.parse(secondObject);
    }
    this.policyOID = new ObjectIdentifier();
    this.policyOID.parse(sequence1.getObjectAt(indice).toASN1Primitive());
    DERIA5String policyURI = (DERIA5String) sequence1.getObjectAt(indice + 1);
    this.policyURI = policyURI.getString();
    ASN1Primitive policyDigest = sequence1.getObjectAt(indice + 2).toASN1Primitive();
    ASN1Sequence sequence2 = ASN1Sequence.getInstance(policyDigest);
    DEROctetString derOctetString = (DEROctetString) sequence2.getObjectAt(1).toASN1Primitive();
    ASN1Sequence sequence3 = ASN1Object.getDERSequence(sequence2.getObjectAt(0).toASN1Primitive());
    ASN1ObjectIdentifier objectIdentifier = (ASN1ObjectIdentifier) sequence3.getObjectAt(0).toASN1Primitive();
    AlgorithmIdentifier algorithmIdentifier = new AlgorithmIdentifier(objectIdentifier);
    this.policyDigest = new OtherHashAlgAndValue(algorithmIdentifier, derOctetString);
}
Also used : SigningPeriod(org.demoiselle.signer.policy.engine.asn1.etsi.SigningPeriod) ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) DERIA5String(org.bouncycastle.asn1.DERIA5String) GeneralizedTime(org.demoiselle.signer.policy.engine.asn1.GeneralizedTime) ASN1Primitive(org.bouncycastle.asn1.ASN1Primitive) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier) DEROctetString(org.bouncycastle.asn1.DEROctetString) OtherHashAlgAndValue(org.bouncycastle.asn1.esf.OtherHashAlgAndValue) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier) ObjectIdentifier(org.demoiselle.signer.policy.engine.asn1.etsi.ObjectIdentifier) AlgorithmIdentifier(org.bouncycastle.asn1.x509.AlgorithmIdentifier)

Aggregations

DEROctetString (org.bouncycastle.asn1.DEROctetString)84 IOException (java.io.IOException)38 DERSequence (org.bouncycastle.asn1.DERSequence)29 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)28 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)26 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)21 DERTaggedObject (org.bouncycastle.asn1.DERTaggedObject)19 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)18 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)16 AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)16 Extension (org.bouncycastle.asn1.x509.Extension)16 BigInteger (java.math.BigInteger)13 Date (java.util.Date)11 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)11 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)11 DERSet (org.bouncycastle.asn1.DERSet)10 DERUTF8String (org.bouncycastle.asn1.DERUTF8String)10 Extensions (org.bouncycastle.asn1.x509.Extensions)10 X509Certificate (java.security.cert.X509Certificate)8 ArrayList (java.util.ArrayList)8