use of com.github.zhenwei.core.asn1.x509.AccessDescription in project eblocker by eblocker.
the class OcspCache method getOcspResponderUrl.
private String getOcspResponderUrl(X509Certificate certificate) throws IOException {
byte[] extensionValue = certificate.getExtensionValue(Extension.authorityInfoAccess.getId());
if (extensionValue == null) {
return null;
}
ASN1OctetString octetString = ASN1OctetString.getInstance(extensionValue);
ASN1Primitive primitive = ASN1Primitive.fromByteArray(octetString.getOctets());
AuthorityInformationAccess authorityInformationAccessExtension = AuthorityInformationAccess.getInstance(primitive);
for (AccessDescription i : authorityInformationAccessExtension.getAccessDescriptions()) {
if (i.getAccessMethod().equals(OCSPObjectIdentifiers.id_pkix_ocsp)) {
return i.getAccessLocation().getName().toString();
}
}
return null;
}
use of com.github.zhenwei.core.asn1.x509.AccessDescription in project supply-chain-tools by secure-device-onboard.
the class OnDieCertPath method getIssuingCertificate.
private String getIssuingCertificate(Certificate cert) throws IllegalArgumentException, CertificateEncodingException, IOException {
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 neo4j by neo4j.
the class CertificateChainFactory method generateCertificate.
private static X509Certificate generateCertificate(X509Certificate issuingCert, PrivateKey issuingPrivateKey, KeyPair certKeyPair, String certName, String ocspURL, Path certificatePath, Path keyPath, BouncyCastleProvider bouncyCastleProvider) throws Exception {
X509v3CertificateBuilder builder;
if (issuingCert == null) {
builder = new JcaX509v3CertificateBuilder(// issuer authority
new X500Name("CN=" + certName), // serial number of certificate
BigInteger.valueOf(new Random().nextInt()), // start of validity
NOT_BEFORE, // end of certificate validity
NOT_AFTER, // subject name of certificate
new X500Name("CN=" + certName), // public key of certificate
certKeyPair.getPublic());
} else {
builder = new JcaX509v3CertificateBuilder(// issuer authority
issuingCert, // serial number of certificate
BigInteger.valueOf(new Random().nextInt()), // start of validity
NOT_BEFORE, // end of certificate validity
NOT_AFTER, // subject name of certificate
new X500Name("CN=" + certName), // public key of certificate
certKeyPair.getPublic());
}
// key usage restrictions
builder.addExtension(Extension.keyUsage, true, new KeyUsage(KeyUsage.keyCertSign | KeyUsage.digitalSignature));
builder.addExtension(Extension.extendedKeyUsage, true, new ExtendedKeyUsage(KeyPurposeId.anyExtendedKeyUsage));
builder.addExtension(Extension.basicConstraints, false, new BasicConstraints(true));
// embed ocsp URI
builder.addExtension(Extension.authorityInfoAccess, false, new AuthorityInformationAccess(new AccessDescription(AccessDescription.id_ad_ocsp, new GeneralName(GeneralName.uniformResourceIdentifier, ocspURL + "/" + certName))));
X509Certificate certificate = new JcaX509CertificateConverter().getCertificate(builder.build(new JcaContentSignerBuilder("SHA1withRSA").setProvider(bouncyCastleProvider).build(// self sign if root cert
issuingPrivateKey == null ? certKeyPair.getPrivate() : issuingPrivateKey)));
writePem("CERTIFICATE", certificate.getEncoded(), certificatePath);
writePem("PRIVATE KEY", certKeyPair.getPrivate().getEncoded(), keyPath);
return certificate;
}
use of com.github.zhenwei.core.asn1.x509.AccessDescription in project oxAuth by GluuFederation.
the class OCSPCertificateVerifier method getOCSPUrl.
@SuppressWarnings({ "deprecation", "resource" })
private String getOCSPUrl(X509Certificate certificate) throws IOException {
ASN1Primitive obj;
try {
obj = getExtensionValue(certificate, Extension.authorityInfoAccess.getId());
} catch (IOException ex) {
log.error("Failed to get OCSP URL", ex);
return null;
}
if (obj == null) {
return null;
}
AuthorityInformationAccess authorityInformationAccess = AuthorityInformationAccess.getInstance(obj);
AccessDescription[] accessDescriptions = authorityInformationAccess.getAccessDescriptions();
for (AccessDescription accessDescription : accessDescriptions) {
boolean correctAccessMethod = accessDescription.getAccessMethod().equals(X509ObjectIdentifiers.ocspAccessMethod);
if (!correctAccessMethod) {
continue;
}
GeneralName name = accessDescription.getAccessLocation();
if (name.getTagNo() != GeneralName.uniformResourceIdentifier) {
continue;
}
DERIA5String derStr = DERIA5String.getInstance((ASN1TaggedObject) name.toASN1Primitive(), false);
return derStr.getString();
}
return null;
}
use of com.github.zhenwei.core.asn1.x509.AccessDescription in project j2objc by google.
the class ForwardBuilder method getCerts.
/**
* Download Certificates from the given AIA and add them to the
* specified Collection.
*/
// cs.getCertificates(caSelector) returns a collection of X509Certificate's
// because of the selector, so the cast is safe
@SuppressWarnings("unchecked")
private boolean getCerts(AuthorityInfoAccessExtension aiaExt, Collection<X509Certificate> certs) {
if (Builder.USE_AIA == false) {
return false;
}
List<AccessDescription> adList = aiaExt.getAccessDescriptions();
if (adList == null || adList.isEmpty()) {
return false;
}
boolean add = false;
for (AccessDescription ad : adList) {
CertStore cs = URICertStore.getInstance(ad);
if (cs != null) {
try {
if (certs.addAll((Collection<X509Certificate>) cs.getCertificates(caSelector))) {
add = true;
if (!searchAllCertStores) {
return true;
}
}
} catch (CertStoreException cse) {
if (debug != null) {
debug.println("exception getting certs from CertStore:");
cse.printStackTrace();
}
}
}
}
return add;
}
Aggregations