use of com.github.zhenwei.core.asn1.x509.AuthorityInformationAccess 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.AuthorityInformationAccess 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.AuthorityInformationAccess 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.AuthorityInformationAccess 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.AuthorityInformationAccess in project nhin-d by DirectProject.
the class AuthorityInfoAccessOCSPLocExtentionField method injectReferenceValue.
/**
* {@inheritDoc}
*/
@Override
public void injectReferenceValue(X509Certificate value) throws PolicyProcessException {
this.certificate = value;
final DERObject exValue = getExtensionValue(value);
if (exValue == null) {
if (isRequired())
throw new PolicyRequiredException("Extention " + getExtentionIdentifier().getDisplay() + " is marked as required by is not present.");
else {
final Collection<String> coll = Collections.emptyList();
this.policyValue = PolicyValueFactory.getInstance(coll);
return;
}
}
final AuthorityInformationAccess aia = AuthorityInformationAccess.getInstance(exValue);
final Collection<String> retVal = new ArrayList<String>();
for (AccessDescription accessDescription : aia.getAccessDescriptions()) {
if (accessDescription.getAccessMethod().equals(AccessDescription.id_ad_ocsp))
retVal.add(accessDescription.getAccessLocation().getName().toString());
}
if (retVal.isEmpty() && isRequired())
throw new PolicyRequiredException("Extention " + getExtentionIdentifier().getDisplay() + " is marked as required by is not present.");
this.policyValue = PolicyValueFactory.getInstance(retVal);
}
Aggregations