Search in sources :

Example 21 with DLSequence

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

the class LPA method parse.

public void parse(ASN1Primitive derObject) {
    ASN1Sequence sequence = ASN1Object.getDERSequence(derObject);
    ASN1Primitive firstObject = sequence.getObjectAt(0).toASN1Primitive();
    this.version = new Version();
    int indice = 0;
    if (firstObject instanceof ASN1Integer) {
        this.version.parse(firstObject);
        indice++;
    }
    ASN1Primitive policyInfos = sequence.getObjectAt(indice).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 GeneralizedTime();
    this.nextUpdate.parse(sequence.getObjectAt(indice + 1).toASN1Primitive());
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) DLSequence(org.bouncycastle.asn1.DLSequence) ASN1Integer(org.bouncycastle.asn1.ASN1Integer) GeneralizedTime(org.demoiselle.signer.policy.engine.asn1.GeneralizedTime) ASN1Primitive(org.bouncycastle.asn1.ASN1Primitive)

Example 22 with DLSequence

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

the class AlgorithmIdentifier method parse.

@Override
public void parse(ASN1Primitive derObject) {
    this.algorithm = new ObjectIdentifier();
    DLSequence derSequence = (DLSequence) derObject;
    this.algorithm.parse(derSequence.getObjectAt(0).toASN1Primitive());
}
Also used : DLSequence(org.bouncycastle.asn1.DLSequence)

Example 23 with DLSequence

use of org.spongycastle.asn1.DLSequence in project pdfbox by apache.

the class CertInformationHelper method getCrlUrlFromExtensionValue.

/**
 * Gets the first CRL Url from given extension value. Structure has to be build as in 4.2.1.14
 * CRL Distribution Points of RFC 2459.
 *
 * @param extensionValue to get the extension value from
 * @return first CRL- URL or null
 * @throws IOException when there is a problem with the extensionValue
 */
protected static String getCrlUrlFromExtensionValue(byte[] extensionValue) throws IOException {
    ASN1Sequence asn1Seq = (ASN1Sequence) X509ExtensionUtil.fromExtensionValue(extensionValue);
    Enumeration<?> objects = asn1Seq.getObjects();
    while (objects.hasMoreElements()) {
        DLSequence obj = (DLSequence) objects.nextElement();
        DERTaggedObject derTagged = (DERTaggedObject) obj.getObjectAt(0);
        derTagged = (DERTaggedObject) derTagged.getObject();
        derTagged = (DERTaggedObject) derTagged.getObject();
        DEROctetString uri = (DEROctetString) derTagged.getObject();
        String url = new String(uri.getOctets());
        // return first http(s)-Url for crl
        if (url.startsWith("http")) {
            return url;
        }
    }
    return null;
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) DLSequence(org.bouncycastle.asn1.DLSequence) DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) DEROctetString(org.bouncycastle.asn1.DEROctetString) DEROctetString(org.bouncycastle.asn1.DEROctetString)

Example 24 with DLSequence

use of org.spongycastle.asn1.DLSequence in project pdfbox by apache.

the class OcspHelper method generateOCSPRequest.

/**
 * Generates an OCSP request and generates the <code>CertificateID</code>.
 *
 * @return OCSP request, ready to fetch data
 * @throws OCSPException
 * @throws IOException
 */
private OCSPReq generateOCSPRequest() throws OCSPException, IOException {
    Security.addProvider(new BouncyCastleProvider());
    // Generate the ID for the certificate we are looking for
    CertificateID certId;
    try {
        certId = new CertificateID(new SHA1DigestCalculator(), new JcaX509CertificateHolder(issuerCertificate), certificateToCheck.getSerialNumber());
    } catch (CertificateEncodingException e) {
        throw new IOException("Error creating CertificateID with the Certificate encoding", e);
    }
    OCSPReqBuilder builder = new OCSPReqBuilder();
    Extension responseExtension = new Extension(OCSPObjectIdentifiers.id_pkix_ocsp_response, true, new DLSequence(OCSPObjectIdentifiers.id_pkix_ocsp_basic).getEncoded());
    Random rand = new Random();
    byte[] nonce = new byte[16];
    rand.nextBytes(nonce);
    encodedNonce = new DEROctetString(new DEROctetString(nonce));
    Extension nonceExtension = new Extension(OCSPObjectIdentifiers.id_pkix_ocsp_nonce, true, encodedNonce);
    builder.setRequestExtensions(new Extensions(new Extension[] { responseExtension, nonceExtension }));
    builder.addRequest(certId);
    System.out.println("Nonce: " + Hex.getString(nonceExtension.getExtnValue().getEncoded()));
    return builder.build();
}
Also used : CertificateID(org.bouncycastle.cert.ocsp.CertificateID) CertificateEncodingException(java.security.cert.CertificateEncodingException) IOException(java.io.IOException) Extensions(org.bouncycastle.asn1.x509.Extensions) JcaX509CertificateHolder(org.bouncycastle.cert.jcajce.JcaX509CertificateHolder) DEROctetString(org.bouncycastle.asn1.DEROctetString) Extension(org.bouncycastle.asn1.x509.Extension) DLSequence(org.bouncycastle.asn1.DLSequence) Random(java.util.Random) OCSPReqBuilder(org.bouncycastle.cert.ocsp.OCSPReqBuilder) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Example 25 with DLSequence

use of org.spongycastle.asn1.DLSequence in project jruby-openssl by jruby.

the class PEMInputOutput method writeDHParameters.

public static void writeDHParameters(Writer _out, DHParameterSpec params) throws IOException {
    final BufferedWriter out = makeBuffered(_out);
    ASN1EncodableVector v = new ASN1EncodableVector();
    BigInteger value;
    if ((value = params.getP()) != null) {
        v.add(new ASN1Integer(value));
    }
    if ((value = params.getG()) != null) {
        v.add(new ASN1Integer(value));
    }
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    ASN1OutputStream aOut = new ASN1OutputStream(bOut);
    aOut.writeObject(new DLSequence(v));
    out.write(BEF_G);
    out.write(PEM_STRING_DHPARAMS);
    out.write(AFT);
    out.newLine();
    writeEncoded(out, bOut.buffer(), bOut.size());
    out.write(BEF_E);
    out.write(PEM_STRING_DHPARAMS);
    out.write(AFT);
    out.newLine();
    out.flush();
}
Also used : DLSequence(org.bouncycastle.asn1.DLSequence) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) BigInteger(java.math.BigInteger) ASN1Integer(org.bouncycastle.asn1.ASN1Integer) ByteArrayOutputStream(org.jruby.ext.openssl.util.ByteArrayOutputStream) ASN1OutputStream(org.bouncycastle.asn1.ASN1OutputStream) BufferedWriter(java.io.BufferedWriter)

Aggregations

DLSequence (org.bouncycastle.asn1.DLSequence)35 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)21 IOException (java.io.IOException)13 DERTaggedObject (org.bouncycastle.asn1.DERTaggedObject)13 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)12 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)9 DEROctetString (org.bouncycastle.asn1.DEROctetString)9 ASN1Primitive (org.bouncycastle.asn1.ASN1Primitive)8 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)8 DERIA5String (org.bouncycastle.asn1.DERIA5String)6 DERUTF8String (org.bouncycastle.asn1.DERUTF8String)6 BigInteger (java.math.BigInteger)5 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)5 Pair (android.util.Pair)3 BufferedWriter (java.io.BufferedWriter)3 ASN1OutputStream (org.bouncycastle.asn1.ASN1OutputStream)3 JRubyMethod (org.jruby.anno.JRubyMethod)3 ByteArrayOutputStream (org.jruby.ext.openssl.util.ByteArrayOutputStream)3 CertificateEncodingException (java.security.cert.CertificateEncodingException)2 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)2