Search in sources :

Example 61 with ASN1Primitive

use of com.github.zhenwei.core.asn1.ASN1Primitive in project jmulticard by ctt-gob-es.

the class McElieceCCA2KeyFactorySpi method generatePrivate.

public PrivateKey generatePrivate(PrivateKeyInfo pki) throws IOException {
    // get the inner type inside the BIT STRING
    ASN1Primitive innerType = pki.parsePrivateKey().toASN1Primitive();
    McElieceCCA2PrivateKey key = McElieceCCA2PrivateKey.getInstance(innerType);
    return new BCMcElieceCCA2PrivateKey(new McElieceCCA2PrivateKeyParameters(key.getN(), key.getK(), key.getField(), key.getGoppaPoly(), key.getP(), null));
}
Also used : McElieceCCA2PrivateKeyParameters(org.bouncycastle.pqc.crypto.mceliece.McElieceCCA2PrivateKeyParameters) McElieceCCA2PrivateKey(org.bouncycastle.pqc.asn1.McElieceCCA2PrivateKey) ASN1Primitive(org.bouncycastle.asn1.ASN1Primitive)

Example 62 with ASN1Primitive

use of com.github.zhenwei.core.asn1.ASN1Primitive in project jmulticard by ctt-gob-es.

the class McElieceKeyFactorySpi method generatePublic.

public PublicKey generatePublic(SubjectPublicKeyInfo pki) throws IOException {
    // get the inner type inside the BIT STRING
    ASN1Primitive innerType = pki.parsePublicKey();
    McEliecePublicKey key = McEliecePublicKey.getInstance(innerType);
    return new BCMcEliecePublicKey(new McEliecePublicKeyParameters(key.getN(), key.getT(), key.getG()));
}
Also used : McEliecePublicKeyParameters(org.bouncycastle.pqc.crypto.mceliece.McEliecePublicKeyParameters) ASN1Primitive(org.bouncycastle.asn1.ASN1Primitive) McEliecePublicKey(org.bouncycastle.pqc.asn1.McEliecePublicKey)

Example 63 with ASN1Primitive

use of com.github.zhenwei.core.asn1.ASN1Primitive in project signer by demoiselle.

the class CertificateTrustPoint method parse.

@Override
public void parse(ASN1Primitive derObject) {
    ASN1Sequence derSequence = ASN1Object.getDERSequence(derObject);
    DERSequence x509Sequence = (DERSequence) derSequence.getObjectAt(0).toASN1Primitive();
    try {
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(x509Sequence.getEncoded());
        this.trustpoint = (X509Certificate) CertificateFactory.getInstance("X509").generateCertificate(byteArrayInputStream);
    } catch (Throwable error) {
        error.printStackTrace();
    }
    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 pathLenConstraint:
                        this.pathLenConstraint = new PathLenConstraint();
                        this.pathLenConstraint.parse(object);
                        break;
                    case acceptablePolicySet:
                        this.acceptablePolicySet = new AcceptablePolicySet();
                        this.acceptablePolicySet.parse(object);
                        break;
                    case nameConstraints:
                        this.nameConstraints = new NameConstraints();
                        this.nameConstraints.parse(object);
                        break;
                    case policyConstraints:
                        this.policyConstraints = new PolicyConstraints();
                        this.policyConstraints.parse(object);
                        break;
                    default:
                        break;
                }
            }
        }
    }
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) DERSequence(org.bouncycastle.asn1.DERSequence) ByteArrayInputStream(java.io.ByteArrayInputStream) DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) ASN1Primitive(org.bouncycastle.asn1.ASN1Primitive)

Example 64 with ASN1Primitive

use of com.github.zhenwei.core.asn1.ASN1Primitive 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)

Example 65 with ASN1Primitive

use of com.github.zhenwei.core.asn1.ASN1Primitive in project signer by demoiselle.

the class PolicyFactory method loadLPAPAdESUrl.

/**
 * Load signature policy for PAdES standard (PDF) from url
 *
 * @return org.demoiselle.signer.policy.engine.asn1.icpb.v2.LPA
 */
public org.demoiselle.signer.policy.engine.asn1.icpb.v2.LPA loadLPAPAdESUrl() {
    org.demoiselle.signer.policy.engine.asn1.icpb.v2.LPA listaPoliticaAssinatura = new org.demoiselle.signer.policy.engine.asn1.icpb.v2.LPA();
    InputStream is;
    String conURL = ListOfSubscriptionPolicies.PAdES_ITI_URL.getUrl();
    try {
        LOGGER.info(policyMessagesBundle.getString("info.lpa.load.url", conURL));
        is = Downloads.getInputStreamFromURL(conURL);
        ASN1Primitive primitive = this.readANS1FromStream(is);
        is.close();
        if (!LPARepository.saveLocalLPA(conURL, "LPA_PAdES.der")) {
            LOGGER.error(policyMessagesBundle.getString("error.lpa.not.saved", "LPA_PAdES.der"));
            throw new RuntimeException(policyMessagesBundle.getString("error.lpa.not.saved", conURL));
        }
        listaPoliticaAssinatura.parse(primitive);
    } catch (IOException | RuntimeException e) {
        LOGGER.error(e.getMessage());
        LOGGER.error(policyMessagesBundle.getString("error.lpa.not.saved", conURL));
        listaPoliticaAssinatura = loadLocalLPAPAdESUrl();
        return listaPoliticaAssinatura;
    }
    return listaPoliticaAssinatura;
}
Also used : FileInputStream(java.io.FileInputStream) ASN1InputStream(org.bouncycastle.asn1.ASN1InputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) LPA(org.demoiselle.signer.policy.engine.asn1.icpb.LPA) ASN1Primitive(org.bouncycastle.asn1.ASN1Primitive)

Aggregations

ASN1EncodableVector (com.github.zhenwei.core.asn1.ASN1EncodableVector)253 DERSequence (com.github.zhenwei.core.asn1.DERSequence)231 ASN1Primitive (org.bouncycastle.asn1.ASN1Primitive)177 IOException (java.io.IOException)107 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)62 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)57 DERTaggedObject (com.github.zhenwei.core.asn1.DERTaggedObject)55 ASN1Integer (com.github.zhenwei.core.asn1.ASN1Integer)42 DEROctetString (com.github.zhenwei.core.asn1.DEROctetString)38 ByteArrayInputStream (java.io.ByteArrayInputStream)38 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)32 ASN1Primitive (com.github.zhenwei.core.asn1.ASN1Primitive)31 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)31 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)30 DEROctetString (org.bouncycastle.asn1.DEROctetString)28 BigInteger (java.math.BigInteger)24 GeneralSecurityException (java.security.GeneralSecurityException)24 X509Certificate (java.security.cert.X509Certificate)24 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)23 DERIA5String (org.bouncycastle.asn1.DERIA5String)22