use of org.bouncycastle.asn1.x509.GeneralNamesBuilder in project ddf by codice.
the class CertificateSigningRequestTest method testNewCertificateBuilderWithSan.
@Test
public void testNewCertificateBuilderWithSan() throws Exception {
final DateTime start = DateTime.now().minusDays(1);
final DateTime end = start.plusYears(100);
final KeyPair kp = makeKeyPair();
csr.setSerialNumber(1);
csr.setNotBefore(start);
csr.setNotAfter(end);
csr.setCommonName("A");
csr.setSubjectKeyPair(kp);
csr.addSubjectAlternativeNames("IP:1.2.3.4", "DNS:A");
final X509Certificate issuerCert = mock(X509Certificate.class);
doReturn(new X500Principal("CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US")).when(issuerCert).getSubjectX500Principal();
final JcaX509v3CertificateBuilder builder = csr.newCertificateBuilder(issuerCert);
final X509CertificateHolder holder = builder.build(new DemoCertificateAuthority().getContentSigner());
assertThat(holder.getSerialNumber(), equalTo(BigInteger.ONE));
assertThat(holder.getNotBefore(), equalTo(new Time(start.toDate()).getDate()));
assertThat(holder.getNotAfter(), equalTo(new Time(end.toDate()).getDate()));
assertThat(holder.getSubject().toString(), equalTo("cn=A"));
assertThat("Unable to validate public key", holder.getSubjectPublicKeyInfo(), equalTo(SubjectPublicKeyInfo.getInstance(kp.getPublic().getEncoded())));
final org.bouncycastle.asn1.x509.Extension csn = holder.getExtension(org.bouncycastle.asn1.x509.Extension.subjectAlternativeName);
assertThat(csn.getParsedValue().toASN1Primitive().getEncoded(ASN1Encoding.DER), equalTo(new GeneralNamesBuilder().addName(new GeneralName(GeneralName.iPAddress, "1.2.3.4")).addName(new GeneralName(GeneralName.dNSName, "A")).build().getEncoded(ASN1Encoding.DER)));
}
use of org.bouncycastle.asn1.x509.GeneralNamesBuilder in project credhub by cloudfoundry-incubator.
the class CertificateGenerationParameters method buildAlternativeNames.
private GeneralNames buildAlternativeNames(CertificateGenerationRequestParameters params) {
String[] alternativeNamesList = params.getAlternativeNames();
if (alternativeNamesList == null) {
return null;
}
GeneralNamesBuilder builder = new GeneralNamesBuilder();
for (String name : alternativeNamesList) {
if (InetAddresses.isInetAddress(name)) {
builder.addName(new GeneralName(GeneralName.iPAddress, name));
} else {
builder.addName(new GeneralName(GeneralName.dNSName, name));
}
}
return builder.build();
}
Aggregations