Discussion:
Get OCSP url from certificate
Valentin Ts. Ivanov
2014-07-24 10:16:21 UTC
Permalink
Hi.



I use BC 1.50.

I got ASN1Primitive, and toString() prints [[1.3.6.1.5.5.7.48.1, [6]#687474703a2f2f6f6373702e622d74727573742e6f7267]]

So how to parse this? I want to get the OCSP url. I see the bytes(in hex format) in the string, but how to parse this structure?

Or I just have to substring it?



Regards,

Valentin
Tomas Gustavsson
2014-07-25 10:17:41 UTC
Permalink
Here is my code from EJBCA to get it.

public static String
getAuthorityInformationAccessOcspUrl(Certificate cert) throws
CertificateParsingException {
String ret = null;
if (cert instanceof X509Certificate) {
X509Certificate x509cert = (X509Certificate) cert;
try {
ASN1Primitive obj = getExtensionValue(x509cert,
Extension.authorityInfoAccess.getId());
if (obj == null) {
return null;
}
AuthorityInformationAccess aia =
AuthorityInformationAccess.getInstance(obj);
AccessDescription[] ad = aia.getAccessDescriptions();
if ((ad != null) && (ad.length > 0)) {
for (int i = 0; i < ad.length; i++) {
if
(ad[i].getAccessMethod().equals(X509ObjectIdentifiers.ocspAccessMethod)) {
GeneralName gn = ad[i].getAccessLocation();
if (gn.getTagNo() ==
GeneralName.uniformResourceIdentifier) {
// After encoding in a cert, it is
tagged an extra time...
ASN1Primitive gnobj = gn.toASN1Primitive();
if (gnobj instanceof ASN1TaggedObject) {
gnobj =
ASN1TaggedObject.getInstance(gnobj).getObject();
}
final DERIA5String str =
DERIA5String.getInstance(gnobj);
ret = str.getString();
break; // no need to go on any further,
we got a value
}
}
}
}
} catch (Exception e) {
log.error("Error parsing AuthorityInformationAccess", e);
throw new CertificateParsingException(e.toString());
}
}
return ret;
}

Cheers,
Tomas
Post by Valentin Ts. Ivanov
Hi.
I use BC 1.50.
I got ASN1Primitive, and toString() prints [[1.3.6.1.5.5.7.48.1,
[6]#687474703a2f2f6f6373702e622d74727573742e6f7267]]
So how to parse this? I want to get the OCSP url. I see the bytes(in hex
format) in the string, but how to parse this structure?
Or I just have to substring it?
Regards,
Valentin
Continue reading on narkive:
Loading...