use of javax.security.auth.x500.X500Principal in project robovm by robovm.
the class AttributeCertificateIssuer method getNames.
private Object[] getNames() {
GeneralNames name;
if (form instanceof V2Form) {
name = ((V2Form) form).getIssuerName();
} else {
name = (GeneralNames) form;
}
GeneralName[] names = name.getNames();
List l = new ArrayList(names.length);
for (int i = 0; i != names.length; i++) {
if (names[i].getTagNo() == GeneralName.directoryName) {
try {
l.add(new X500Principal(((ASN1Encodable) names[i].getName()).toASN1Primitive().getEncoded()));
} catch (IOException e) {
throw new RuntimeException("badly formed Name object");
}
}
}
return l.toArray(new Object[l.size()]);
}
use of javax.security.auth.x500.X500Principal in project robovm by robovm.
the class DefaultHostnameVerifier method verifyHostName.
/**
* Returns true if {@code certificate} matches {@code hostName}.
*/
private boolean verifyHostName(String hostName, X509Certificate certificate) {
hostName = hostName.toLowerCase(Locale.US);
boolean hasDns = false;
for (String altName : getSubjectAltNames(certificate, ALT_DNS_NAME)) {
hasDns = true;
if (verifyHostName(hostName, altName)) {
return true;
}
}
if (!hasDns) {
X500Principal principal = certificate.getSubjectX500Principal();
// RFC 2818 advises using the most specific name for matching.
String cn = new DistinguishedNameParser(principal).findMostSpecific("cn");
if (cn != null) {
return verifyHostName(hostName, cn);
}
}
return false;
}
use of javax.security.auth.x500.X500Principal in project robovm by robovm.
the class JarEntry method getCodeSigners.
private CodeSigner[] getCodeSigners(Certificate[] certs) {
if (certs == null) {
return null;
}
X500Principal prevIssuer = null;
ArrayList<Certificate> list = new ArrayList<Certificate>(certs.length);
ArrayList<CodeSigner> asigners = new ArrayList<CodeSigner>();
for (Certificate element : certs) {
if (!(element instanceof X509Certificate)) {
// Only X509Certificate-s are taken into account - see API spec.
continue;
}
X509Certificate x509 = (X509Certificate) element;
if (prevIssuer != null) {
X500Principal subj = x509.getSubjectX500Principal();
if (!prevIssuer.equals(subj)) {
// Ok, this ends the previous chain,
// so transform this one into CertPath ...
addCodeSigner(asigners, list);
// ... and start a new one
list.clear();
}
// else { it's still the same chain }
}
prevIssuer = x509.getIssuerX500Principal();
list.add(x509);
}
if (!list.isEmpty()) {
addCodeSigner(asigners, list);
}
if (asigners.isEmpty()) {
// 'signers' is 'null' already
return null;
}
CodeSigner[] tmp = new CodeSigner[asigners.size()];
asigners.toArray(tmp);
return tmp;
}
use of javax.security.auth.x500.X500Principal in project robovm by robovm.
the class X500PrincipalTest method test_X500Principal_03.
/**
* javax.security.auth.x500.X500Principal#X500Principal(byte[] name)
*/
public void test_X500Principal_03() {
String name = "CN=Duke,OU=JavaSoft,O=Sun Microsystems,C=US";
byte[] ba = getByteArray(TestUtils.getX509Certificate_v1());
byte[] baNull = null;
try {
X500Principal xpr = new X500Principal(ba);
assertNotNull("Null object returned", xpr);
byte[] resArray = xpr.getEncoded();
assertEquals(ba.length, resArray.length);
} catch (Exception e) {
fail("Unexpected exception: " + e);
}
try {
X500Principal xpr = new X500Principal(baNull);
fail("IllegalArgumentException wasn't thrown");
} catch (IllegalArgumentException npe) {
} catch (Exception e) {
fail(e + " was thrown instead of IllegalArgumentException");
}
ba = name.getBytes();
try {
X500Principal xpr = new X500Principal(ba);
fail("IllegalArgumentException wasn't thrown");
} catch (IllegalArgumentException npe) {
} catch (Exception e) {
fail(e + " was thrown instead of IllegalArgumentException");
}
}
use of javax.security.auth.x500.X500Principal in project robovm by robovm.
the class X500PrincipalTest method test_X500Principal_02.
/**
* javax.security.auth.x500.X500Principal#X500Principal(InputStream is)
*/
public void test_X500Principal_02() {
String name = "CN=Duke,OU=JavaSoft,O=Sun Microsystems,C=US";
byte[] ba = getByteArray(TestUtils.getX509Certificate_v1());
ByteArrayInputStream is = new ByteArrayInputStream(ba);
InputStream isNull = null;
try {
X500Principal xpr = new X500Principal(is);
assertNotNull("Null object returned", xpr);
byte[] resArray = xpr.getEncoded();
assertEquals(ba.length, resArray.length);
} catch (Exception e) {
fail("Unexpected exception: " + e);
}
try {
X500Principal xpr = new X500Principal(isNull);
fail("NullPointerException wasn't thrown");
} catch (NullPointerException npe) {
} catch (Exception e) {
fail(e + " was thrown instead of NullPointerException");
}
is = new ByteArrayInputStream(name.getBytes());
try {
X500Principal xpr = new X500Principal(is);
fail("IllegalArgumentException wasn't thrown");
} catch (IllegalArgumentException npe) {
} catch (Exception e) {
fail(e + " was thrown instead of IllegalArgumentException");
}
}
Aggregations