use of org.apache.harmony.security.x509.GeneralName 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.apache.harmony.security.x509.GeneralName in project ddf by codice.
the class PkiToolsTest method testMakeGeneralNameForEmail.
@Test
public void testMakeGeneralNameForEmail() {
final String value = "a@host.com";
final GeneralName gname = PkiTools.makeGeneralName("email:" + value);
assertThat(gname.getTagNo(), equalTo(GeneralName.rfc822Name));
assertThat(gname.getName().toString(), equalTo(value));
}
use of org.apache.harmony.security.x509.GeneralName in project ddf by codice.
the class PkiToolsTest method testMakeGeneralNameForRID.
@Test
public void testMakeGeneralNameForRID() {
final String value = "0.2.1.4";
final GeneralName gname = PkiTools.makeGeneralName("RID:" + value);
assertThat(gname.getTagNo(), equalTo(GeneralName.registeredID));
assertThat(gname.getName().toString(), equalTo(value));
}
use of org.apache.harmony.security.x509.GeneralName in project ddf by codice.
the class PkiToolsTest method testMakeGeneralNameForDirName.
@Test
public void testMakeGeneralNameForDirName() {
final String value = "C=UK+CN=My Name+OU=My Unit+O=My Organization";
final GeneralName gname = PkiTools.makeGeneralName("dirName:" + value);
assertThat(gname.getTagNo(), equalTo(GeneralName.directoryName));
assertThat(gname.getName().toString(), equalTo(value));
}
use of org.apache.harmony.security.x509.GeneralName in project robovm by robovm.
the class AuthorityKeyIdentifierStructure method fromCertificate.
private static ASN1Sequence fromCertificate(X509Certificate certificate) throws CertificateParsingException {
try {
if (certificate.getVersion() != 3) {
GeneralName genName = new GeneralName(PrincipalUtil.getIssuerX509Principal(certificate));
SubjectPublicKeyInfo info = new SubjectPublicKeyInfo((ASN1Sequence) new ASN1InputStream(certificate.getPublicKey().getEncoded()).readObject());
return (ASN1Sequence) new AuthorityKeyIdentifier(info, new GeneralNames(genName), certificate.getSerialNumber()).toASN1Object();
} else {
GeneralName genName = new GeneralName(PrincipalUtil.getIssuerX509Principal(certificate));
byte[] ext = certificate.getExtensionValue(X509Extensions.SubjectKeyIdentifier.getId());
if (ext != null) {
ASN1OctetString str = (ASN1OctetString) X509ExtensionUtil.fromExtensionValue(ext);
return (ASN1Sequence) new AuthorityKeyIdentifier(str.getOctets(), new GeneralNames(genName), certificate.getSerialNumber()).toASN1Object();
} else {
SubjectPublicKeyInfo info = new SubjectPublicKeyInfo((ASN1Sequence) new ASN1InputStream(certificate.getPublicKey().getEncoded()).readObject());
return (ASN1Sequence) new AuthorityKeyIdentifier(info, new GeneralNames(genName), certificate.getSerialNumber()).toASN1Object();
}
}
} catch (Exception e) {
throw new CertificateParsingException("Exception extracting certificate details: " + e.toString());
}
}
Aggregations