use of com.github.zhenwei.core.asn1.x509.AccessDescription in project ddf by codice.
the class OcspChecker method getOcspUrlsFromCert.
/**
* Attempts to grab additional OCSP server urls off of the given {@param cert}.
*
* @param - the {@link X509Certificate} to check.
* @return {@link List} of additional OCSP server urls found on the given {@param cert}.
*/
private List<URI> getOcspUrlsFromCert(X509Certificate cert) {
List<URI> ocspUrls = new ArrayList<>();
try {
byte[] authorityInfoAccess = cert.getExtensionValue(Extension.authorityInfoAccess.getId());
if (authorityInfoAccess == null) {
return ocspUrls;
}
AuthorityInformationAccess authorityInformationAccess = AuthorityInformationAccess.getInstance(X509ExtensionUtil.fromExtensionValue(authorityInfoAccess));
if (authorityInformationAccess == null) {
return ocspUrls;
}
for (AccessDescription description : authorityInformationAccess.getAccessDescriptions()) {
GeneralName accessLocation = description.getAccessLocation();
if (accessLocation.getTagNo() == GeneralName.uniformResourceIdentifier)
try {
ocspUrls.add(new URI(((DERIA5String) accessLocation.getName()).getString()));
} catch (URISyntaxException e) {
LOGGER.debug("Location is not a URI.", e);
}
}
} catch (IOException e) {
LOGGER.debug("Problem retrieving the OCSP server url(s) from the certificate." + CONTINUING_MSG, e);
}
return ocspUrls;
}
use of com.github.zhenwei.core.asn1.x509.AccessDescription in project pri-fidoiot by secure-device-onboard.
the class OnDieCertSignatureFunction method getIssuingCertificate.
private String getIssuingCertificate(Certificate cert) throws IllegalArgumentException, IOException, CertificateEncodingException {
X509CertificateHolder certholder = new X509CertificateHolder(cert.getEncoded());
AuthorityInformationAccess aia = AuthorityInformationAccess.fromExtensions(certholder.getExtensions());
if (aia == null) {
throw new IllegalArgumentException("AuthorityInformationAccess Extension missing from device certificate.");
}
AccessDescription[] descs = aia.getAccessDescriptions();
if (descs.length != 1) {
throw new IllegalArgumentException("Too many descriptions in AIA certificate extension: " + descs.length);
}
return descs[0].getAccessLocation().getName().toString();
}
use of com.github.zhenwei.core.asn1.x509.AccessDescription in project LinLong-Java by zhenwei1108.
the class AccessDescription method toASN1Primitive.
public ASN1Primitive toASN1Primitive() {
ASN1EncodableVector accessDescription = new ASN1EncodableVector(2);
accessDescription.add(accessMethod);
accessDescription.add(accessLocation);
return new DERSequence(accessDescription);
}
use of com.github.zhenwei.core.asn1.x509.AccessDescription in project LinLong-Java by zhenwei1108.
the class PKIXCertPathReviewer method getOCSPUrls.
protected Vector getOCSPUrls(AuthorityInformationAccess authInfoAccess) {
Vector urls = new Vector();
if (authInfoAccess != null) {
AccessDescription[] ads = authInfoAccess.getAccessDescriptions();
for (int i = 0; i < ads.length; i++) {
if (ads[i].getAccessMethod().equals(AccessDescription.id_ad_ocsp)) {
GeneralName name = ads[i].getAccessLocation();
if (name.getTagNo() == GeneralName.uniformResourceIdentifier) {
String url = ((ASN1IA5String) name.getName()).getString();
urls.add(url);
}
}
}
}
return urls;
}
use of com.github.zhenwei.core.asn1.x509.AccessDescription in project module-ballerina-http by ballerina-platform.
the class OCSPVerifier method getAIALocations.
/**
* Authority Information Access (AIA) is a non-critical extension in an X509 Certificate. This contains the
* URL of the OCSP endpoint if one is available.
*
* @param cert is the certificate
* @return a lit of URLs in AIA extension of the certificate which will hopefully contain an OCSP endpoint.
* @throws CertificateVerificationException if any error occurs while retrieving authority access points from the
* certificate.
*/
public static List<String> getAIALocations(X509Certificate cert) throws CertificateVerificationException {
// Gets the DER-encoded OCTET string for the extension value for Authority information access points.
byte[] aiaExtensionValue = cert.getExtensionValue(Extension.authorityInfoAccess.getId());
if (aiaExtensionValue == null) {
throw new CertificateVerificationException("Certificate doesn't have Authority Information Access points");
}
AuthorityInformationAccess authorityInformationAccess;
ASN1InputStream asn1InputStream = null;
try {
DEROctetString oct = (DEROctetString) (new ASN1InputStream(new ByteArrayInputStream(aiaExtensionValue)).readObject());
asn1InputStream = new ASN1InputStream(oct.getOctets());
authorityInformationAccess = AuthorityInformationAccess.getInstance(asn1InputStream.readObject());
} catch (IOException e) {
throw new CertificateVerificationException("Cannot read certificate to get OSCP urls", e);
} finally {
try {
if (asn1InputStream != null) {
asn1InputStream.close();
}
} catch (IOException e) {
LOG.error("Cannot close ASN1InputStream", e);
}
}
List<String> ocspUrlList = new ArrayList<>();
AccessDescription[] accessDescriptions = authorityInformationAccess.getAccessDescriptions();
for (AccessDescription accessDescription : accessDescriptions) {
GeneralName gn = accessDescription.getAccessLocation();
if (gn.getTagNo() == GeneralName.uniformResourceIdentifier) {
DERIA5String str = DERIA5String.getInstance(gn.getName());
String accessLocation = str.getString();
ocspUrlList.add(accessLocation);
}
}
if (ocspUrlList.isEmpty()) {
throw new CertificateVerificationException("Cannot get OCSP urls from certificate");
}
return ocspUrlList;
}
Aggregations