Search in sources :

Example 96 with ASN1Sequence

use of com.android.org.bouncycastle.asn1.ASN1Sequence in project xipki by xipki.

the class ProxyP11Module method refresh.

public void refresh() throws P11TokenException {
    byte[] resp = send(P11ProxyConstants.ACTION_GET_SERVER_CAPS, null);
    Asn1ServerCaps caps;
    try {
        caps = Asn1ServerCaps.getInstance(resp);
    } catch (BadAsn1ObjectException ex) {
        throw new P11TokenException("response is a valid Asn1ServerCaps", ex);
    }
    if (!caps.getVersions().contains(version)) {
        throw new P11TokenException("Server does not support any version supported by the client");
    }
    this.readOnly = caps.isReadOnly();
    resp = send(P11ProxyConstants.ACTION_GET_SLOT_IDS, null);
    ASN1Sequence seq;
    try {
        seq = ASN1Sequence.getInstance(resp);
    } catch (IllegalArgumentException ex) {
        throw new P11TokenException("response is not ASN1Sequence", ex);
    }
    final int n = seq.size();
    Set<P11Slot> slots = new HashSet<>();
    for (int i = 0; i < n; i++) {
        Asn1P11SlotIdentifier asn1SlotId;
        try {
            ASN1Encodable obj = seq.getObjectAt(i);
            asn1SlotId = Asn1P11SlotIdentifier.getInstance(obj);
        } catch (Exception ex) {
            throw new P11TokenException(ex.getMessage(), ex);
        }
        P11SlotIdentifier slotId = asn1SlotId.getSlotId();
        if (!conf.isSlotIncluded(slotId)) {
            continue;
        }
        if (!conf.isSlotIncluded(slotId)) {
            LOG.info("skipped slot {}", slotId);
            continue;
        }
        P11Slot slot = new ProxyP11Slot(this, slotId, conf.isReadOnly(), conf.getP11MechanismFilter());
        slots.add(slot);
    }
    setSlots(slots);
}
Also used : Asn1ServerCaps(org.xipki.p11proxy.msg.Asn1ServerCaps) Asn1P11SlotIdentifier(org.xipki.p11proxy.msg.Asn1P11SlotIdentifier) P11SlotIdentifier(org.xipki.security.pkcs11.P11SlotIdentifier) P11TokenException(org.xipki.security.exception.P11TokenException) P11Slot(org.xipki.security.pkcs11.P11Slot) P11TokenException(org.xipki.security.exception.P11TokenException) BadAsn1ObjectException(org.xipki.security.exception.BadAsn1ObjectException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) BadAsn1ObjectException(org.xipki.security.exception.BadAsn1ObjectException) HashSet(java.util.HashSet) Asn1P11SlotIdentifier(org.xipki.p11proxy.msg.Asn1P11SlotIdentifier)

Example 97 with ASN1Sequence

use of com.android.org.bouncycastle.asn1.ASN1Sequence in project signer by demoiselle.

the class SignPolicyInfo method parse.

@Override
public void parse(ASN1Primitive derObject) {
    ASN1Sequence derSequence = ASN1Object.getDERSequence(derObject);
    this.signPolicyIdentifier = new SignPolicyId();
    this.signPolicyIdentifier.parse(derSequence.getObjectAt(0).toASN1Primitive());
    this.dateOfIssue = new GeneralizedTime();
    this.dateOfIssue.parse(derSequence.getObjectAt(1).toASN1Primitive());
    this.policyIssuerName = new PolicyIssuerName();
    this.policyIssuerName.parse(derSequence.getObjectAt(2).toASN1Primitive());
    this.fieldOfApplication = new FieldOfApplication();
    this.fieldOfApplication.parse(derSequence.getObjectAt(3).toASN1Primitive());
    this.signatureValidationPolicy = new SignatureValidationPolicy();
    this.signatureValidationPolicy.parse(derSequence.getObjectAt(4).toASN1Primitive());
    if (derSequence.size() == 6) {
        this.signPolExtensions = new SignPolExtensions();
        this.signPolExtensions.parse(derSequence.getObjectAt(5).toASN1Primitive());
    }
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) GeneralizedTime(org.demoiselle.signer.policy.engine.asn1.GeneralizedTime)

Example 98 with ASN1Sequence

use of com.android.org.bouncycastle.asn1.ASN1Sequence in project signer by demoiselle.

the class SignerRules method parse.

@Override
public void parse(ASN1Primitive primitive) {
    ASN1Sequence derSequence = ASN1Object.getDERSequence(primitive);
    int total = derSequence.size();
    if (total > 0) {
        for (int i = 0; i < total; i++) {
            ASN1Primitive object = derSequence.getObjectAt(i).toASN1Primitive();
            if (object instanceof DERTaggedObject) {
                DERTaggedObject derTaggedObject = (DERTaggedObject) object;
                TAG tag = TAG.getTag(derTaggedObject.getTagNo());
                switch(tag) {
                    case mandatedCertificateRef:
                        this.mandatedCertificateRef = CertRefReq.parse(object);
                        break;
                    case mandatedCertificateInfo:
                        this.mandatedCertificateInfo = CertInfoReq.parse(object);
                        break;
                    case signPolExtensions:
                        this.signPolExtensions = new SignPolExtensions();
                        this.signPolExtensions.parse(object);
                        break;
                    default:
                        break;
                }
            }
        }
    }
    int i = 0;
    ASN1Encodable object = derSequence.getObjectAt(i);
    if (!(object instanceof DERSequence)) {
        if (object instanceof ASN1Boolean) {
            this.externalSignedData = ((ASN1Boolean) object).isTrue();
        }
        i++;
    }
    this.mandatedSignedAttr = new CMSAttrs();
    this.mandatedSignedAttr.parse(derSequence.getObjectAt(i).toASN1Primitive());
    i++;
    this.mandatedUnsignedAttr = new CMSAttrs();
    this.mandatedUnsignedAttr.parse(derSequence.getObjectAt(i).toASN1Primitive());
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) DERSequence(org.bouncycastle.asn1.DERSequence) DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) ASN1Boolean(org.bouncycastle.asn1.ASN1Boolean) ASN1Primitive(org.bouncycastle.asn1.ASN1Primitive)

Example 99 with ASN1Sequence

use of com.android.org.bouncycastle.asn1.ASN1Sequence in project signer by demoiselle.

the class SigningPeriod method parse.

@Override
public void parse(ASN1Primitive derObject) {
    ASN1Sequence derSequence = ASN1Object.getDERSequence(derObject);
    this.notBefore = new GeneralizedTime();
    this.notBefore.parse(derSequence.getObjectAt(0).toASN1Primitive());
    if (derSequence.size() == 2) {
        this.notAfter = new GeneralizedTime();
        this.notAfter.parse(derSequence.getObjectAt(1).toASN1Primitive());
    }
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) GeneralizedTime(org.demoiselle.signer.policy.engine.asn1.GeneralizedTime)

Example 100 with ASN1Sequence

use of com.android.org.bouncycastle.asn1.ASN1Sequence in project signer by demoiselle.

the class LPA method parse.

@Override
public void parse(ASN1Primitive derObject) {
    ASN1Sequence sequence = ASN1Object.getDERSequence(derObject);
    ASN1Primitive policyInfos = sequence.getObjectAt(0).toASN1Primitive();
    DLSequence policyInfosSequence = (DLSequence) policyInfos;
    if (policyInfosSequence != null && policyInfosSequence.size() > 0) {
        this.policyInfos = new ArrayList<>();
        for (int i = 0; i < policyInfosSequence.size(); i++) {
            PolicyInfo policyInfo = new PolicyInfo();
            policyInfo.parse(policyInfosSequence.getObjectAt(i).toASN1Primitive());
            this.policyInfos.add(policyInfo);
        }
    }
    this.nextUpdate = new Time();
    this.nextUpdate.parse(sequence.getObjectAt(1).toASN1Primitive());
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) DLSequence(org.bouncycastle.asn1.DLSequence) ASN1Primitive(org.bouncycastle.asn1.ASN1Primitive)

Aggregations

ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)202 IOException (java.io.IOException)70 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)56 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)49 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)41 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)36 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)36 ArrayList (java.util.ArrayList)35 DEROctetString (org.bouncycastle.asn1.DEROctetString)35 CRLDistPoint (org.bouncycastle.asn1.x509.CRLDistPoint)32 X509Certificate (java.security.cert.X509Certificate)31 ASN1Primitive (org.bouncycastle.asn1.ASN1Primitive)31 DERSequence (org.bouncycastle.asn1.DERSequence)30 Enumeration (java.util.Enumeration)29 BigInteger (java.math.BigInteger)28 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)28 DERIA5String (org.bouncycastle.asn1.DERIA5String)28 DistributionPoint (org.bouncycastle.asn1.x509.DistributionPoint)28 DERUTF8String (org.bouncycastle.asn1.DERUTF8String)26 List (java.util.List)25