Search in sources :

Example 81 with DEROctetString

use of org.spongycastle.asn1.DEROctetString 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 82 with DEROctetString

use of org.spongycastle.asn1.DEROctetString 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 83 with DEROctetString

use of org.spongycastle.asn1.DEROctetString in project jmulticard by ctt-gob-es.

the class DO97 method fromByteArray.

void fromByteArray(final byte[] encodedData) throws SecureMessagingException {
    try (final ASN1InputStream asn1in = new ASN1InputStream(encodedData)) {
        this.to = (DERTaggedObject) asn1in.readObject();
    } catch (final IOException e) {
        throw new SecureMessagingException(e);
    }
    final DEROctetString ocs = (DEROctetString) this.to.getObject();
    this.data = ocs.getOctets();
}
Also used : ASN1InputStream(org.spongycastle.asn1.ASN1InputStream) IOException(java.io.IOException) DEROctetString(org.spongycastle.asn1.DEROctetString)

Example 84 with DEROctetString

use of org.spongycastle.asn1.DEROctetString in project jmulticard by ctt-gob-es.

the class DO99 method fromByteArray.

void fromByteArray(final byte[] encodedData) throws SecureMessagingException {
    try (final ASN1InputStream asn1in = new ASN1InputStream(encodedData)) {
        this.to = (DERTaggedObject) asn1in.readObject();
        asn1in.close();
    } catch (final IOException e) {
        throw new SecureMessagingException(e);
    }
    final DEROctetString ocs = (DEROctetString) this.to.getObject();
    this.data = ocs.getOctets();
}
Also used : ASN1InputStream(org.spongycastle.asn1.ASN1InputStream) IOException(java.io.IOException) DEROctetString(org.spongycastle.asn1.DEROctetString)

Example 85 with DEROctetString

use of org.spongycastle.asn1.DEROctetString in project jmulticard by ctt-gob-es.

the class DO87 method fromByteArray.

void fromByteArray(final byte[] encodedData) throws SecureMessagingException {
    try (final ASN1InputStream asn1in = new ASN1InputStream(encodedData)) {
        this.to = (DERTaggedObject) asn1in.readObject();
    } catch (final IOException e) {
        throw new SecureMessagingException(e);
    }
    final DEROctetString ocs = (DEROctetString) this.to.getObject();
    this.value_ = ocs.getOctets();
    this.data = removeOne(this.value_);
}
Also used : ASN1InputStream(org.spongycastle.asn1.ASN1InputStream) IOException(java.io.IOException) DEROctetString(org.spongycastle.asn1.DEROctetString)

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