Example usage for org.bouncycastle.asn1 BERTags OBJECT_IDENTIFIER

List of usage examples for org.bouncycastle.asn1 BERTags OBJECT_IDENTIFIER

Introduction

In this page you can find the example usage for org.bouncycastle.asn1 BERTags OBJECT_IDENTIFIER.

Prototype

int OBJECT_IDENTIFIER

To view the source code for org.bouncycastle.asn1 BERTags OBJECT_IDENTIFIER.

Click Source Link

Usage

From source file:io.netty.example.ocsp.OcspUtils.java

License:Apache License

/**
 * Returns the OCSP responder {@link URI} or {@code null} if it doesn't have one.
 *//*from  w ww .ja v  a  2s . co  m*/
public static URI ocspUri(X509Certificate certificate) throws IOException {
    byte[] value = certificate.getExtensionValue(Extension.authorityInfoAccess.getId());
    if (value == null) {
        return null;
    }

    ASN1Primitive authorityInfoAccess = X509ExtensionUtil.fromExtensionValue(value);
    if (!(authorityInfoAccess instanceof DLSequence)) {
        return null;
    }

    DLSequence aiaSequence = (DLSequence) authorityInfoAccess;
    DERTaggedObject taggedObject = findObject(aiaSequence, OCSP_RESPONDER_OID, DERTaggedObject.class);
    if (taggedObject == null) {
        return null;
    }

    if (taggedObject.getTagNo() != BERTags.OBJECT_IDENTIFIER) {
        return null;
    }

    byte[] encoded = taggedObject.getEncoded();
    int length = (int) encoded[1] & 0xFF;
    String uri = new String(encoded, 2, length, CharsetUtil.UTF_8);
    return URI.create(uri);
}