use of sun.security.x509.GeneralName in project nhin-d by DirectProject.
the class SubjectAltNameExtensionField 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> emptyList = Collections.emptyList();
this.policyValue = PolicyValueFactory.getInstance(emptyList);
return;
}
}
final Collection<String> names = new ArrayList<String>();
final GeneralNames generalNames = GeneralNames.getInstance(exValue);
for (GeneralName name : generalNames.getNames()) {
final GeneralNameType type = GeneralNameType.fromTag(name.getTagNo());
if (type != null) {
names.add(type.getDisplay() + ":" + name.getName().toString());
}
}
this.policyValue = PolicyValueFactory.getInstance(names);
}
use of sun.security.x509.GeneralName in project poi by apache.
the class PkiTestUtils method generateCertificate.
static X509Certificate generateCertificate(PublicKey subjectPublicKey, String subjectDn, Date notBefore, Date notAfter, X509Certificate issuerCertificate, PrivateKey issuerPrivateKey, boolean caFlag, int pathLength, String crlUri, String ocspUri, KeyUsage keyUsage) throws IOException, OperatorCreationException, CertificateException {
String signatureAlgorithm = "SHA1withRSA";
X500Name issuerName;
if (issuerCertificate != null) {
issuerName = new X509CertificateHolder(issuerCertificate.getEncoded()).getIssuer();
} else {
issuerName = new X500Name(subjectDn);
}
RSAPublicKey rsaPubKey = (RSAPublicKey) subjectPublicKey;
RSAKeyParameters rsaSpec = new RSAKeyParameters(false, rsaPubKey.getModulus(), rsaPubKey.getPublicExponent());
SubjectPublicKeyInfo subjectPublicKeyInfo = SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(rsaSpec);
DigestCalculator digestCalc = new JcaDigestCalculatorProviderBuilder().setProvider("BC").build().get(CertificateID.HASH_SHA1);
X509v3CertificateBuilder certificateGenerator = new X509v3CertificateBuilder(issuerName, new BigInteger(128, new SecureRandom()), notBefore, notAfter, new X500Name(subjectDn), subjectPublicKeyInfo);
X509ExtensionUtils exUtils = new X509ExtensionUtils(digestCalc);
SubjectKeyIdentifier subKeyId = exUtils.createSubjectKeyIdentifier(subjectPublicKeyInfo);
AuthorityKeyIdentifier autKeyId = (issuerCertificate != null) ? exUtils.createAuthorityKeyIdentifier(new X509CertificateHolder(issuerCertificate.getEncoded())) : exUtils.createAuthorityKeyIdentifier(subjectPublicKeyInfo);
certificateGenerator.addExtension(Extension.subjectKeyIdentifier, false, subKeyId);
certificateGenerator.addExtension(Extension.authorityKeyIdentifier, false, autKeyId);
if (caFlag) {
BasicConstraints bc;
if (-1 == pathLength) {
bc = new BasicConstraints(true);
} else {
bc = new BasicConstraints(pathLength);
}
certificateGenerator.addExtension(Extension.basicConstraints, false, bc);
}
if (null != crlUri) {
int uri = GeneralName.uniformResourceIdentifier;
DERIA5String crlUriDer = new DERIA5String(crlUri);
GeneralName gn = new GeneralName(uri, crlUriDer);
DERSequence gnDer = new DERSequence(gn);
GeneralNames gns = GeneralNames.getInstance(gnDer);
DistributionPointName dpn = new DistributionPointName(0, gns);
DistributionPoint distp = new DistributionPoint(dpn, null, null);
DERSequence distpDer = new DERSequence(distp);
certificateGenerator.addExtension(Extension.cRLDistributionPoints, false, distpDer);
}
if (null != ocspUri) {
int uri = GeneralName.uniformResourceIdentifier;
GeneralName ocspName = new GeneralName(uri, ocspUri);
AuthorityInformationAccess authorityInformationAccess = new AuthorityInformationAccess(X509ObjectIdentifiers.ocspAccessMethod, ocspName);
certificateGenerator.addExtension(Extension.authorityInfoAccess, false, authorityInformationAccess);
}
if (null != keyUsage) {
certificateGenerator.addExtension(Extension.keyUsage, true, keyUsage);
}
JcaContentSignerBuilder signerBuilder = new JcaContentSignerBuilder(signatureAlgorithm);
signerBuilder.setProvider("BC");
X509CertificateHolder certHolder = certificateGenerator.build(signerBuilder.build(issuerPrivateKey));
// .getEncoded()));
return new JcaX509CertificateConverter().getCertificate(certHolder);
}
use of sun.security.x509.GeneralName in project cas by apereo.
the class DefaultSamlIdPCertificateAndKeyWriter method buildSubjectAltNames.
private ASN1Encodable[] buildSubjectAltNames() {
final ArrayList<ASN1Encodable> subjectAltNames = new ArrayList<>();
subjectAltNames.add(new GeneralName(GeneralName.dNSName, hostname));
if (uriSubjectAltNames != null) {
uriSubjectAltNames.forEach(subjectAltName -> subjectAltNames.add(new GeneralName(GeneralName.uniformResourceIdentifier, subjectAltName)));
}
return subjectAltNames.toArray(new ASN1Encodable[0]);
}
use of sun.security.x509.GeneralName in project athenz by yahoo.
the class InstanceClientRefresh method generateCSR.
public static String generateCSR(String domainName, String serviceName, String instanceId, String dnsSuffix, PrivateKey key) {
final String dn = "cn=" + domainName + "." + serviceName + ",o=Athenz";
// now let's generate our dsnName field based on our principal's details
StringBuilder dnsName = new StringBuilder(128);
dnsName.append(serviceName);
dnsName.append('.');
dnsName.append(domainName.replace('.', '-'));
dnsName.append('.');
dnsName.append(dnsSuffix);
GeneralName[] sanArray = new GeneralName[2];
sanArray[0] = new GeneralName(GeneralName.dNSName, new DERIA5String(dnsName.toString()));
// next we include our instance id
StringBuilder dnsInstance = new StringBuilder(128);
dnsInstance.append(instanceId);
dnsInstance.append(".instanceid.athenz.");
dnsInstance.append(dnsSuffix);
sanArray[1] = new GeneralName(GeneralName.dNSName, new DERIA5String(dnsInstance.toString()));
String csr = null;
try {
csr = Crypto.generateX509CSR(key, dn, sanArray);
} catch (OperatorCreationException | IOException ex) {
System.err.println(ex.getMessage());
}
return csr;
}
use of sun.security.x509.GeneralName in project athenz by yahoo.
the class InstanceClientRegister method generateCSR.
public static String generateCSR(String domainName, String serviceName, String instanceId, String dnsSuffix, PrivateKey key) {
final String dn = "cn=" + domainName + "." + serviceName + ",o=Athenz";
// now let's generate our dsnName field based on our principal's details
StringBuilder dnsName = new StringBuilder(128);
dnsName.append(serviceName);
dnsName.append('.');
dnsName.append(domainName.replace('.', '-'));
dnsName.append('.');
dnsName.append(dnsSuffix);
GeneralName[] sanArray = new GeneralName[2];
sanArray[0] = new GeneralName(GeneralName.dNSName, new DERIA5String(dnsName.toString()));
// next we include our instance id
StringBuilder dnsInstance = new StringBuilder(128);
dnsInstance.append(instanceId);
dnsInstance.append(".instanceid.athenz.");
dnsInstance.append(dnsSuffix);
sanArray[1] = new GeneralName(GeneralName.dNSName, new DERIA5String(dnsInstance.toString()));
String csr = null;
try {
csr = Crypto.generateX509CSR(key, dn, sanArray);
} catch (OperatorCreationException | IOException ex) {
System.err.println(ex.getMessage());
}
return csr;
}
Aggregations