use of javax.security.auth.x500.X500Principal in project robovm by robovm.
the class X509CertSelectorTest method test_setIssuerLjavax_security_auth_x500_X500Principal.
/**
* java.security.cert.X509CertSelector#setIssuer(javax.security.auth.x500.X500Principal)
*/
public void test_setIssuerLjavax_security_auth_x500_X500Principal() throws Exception {
X500Principal iss1 = new X500Principal("O=First Org.");
X500Principal iss2 = new X500Principal("O=Second Org.");
TestCert cert1 = new TestCert(iss1);
TestCert cert2 = new TestCert(iss2);
X509CertSelector selector = new X509CertSelector();
selector.setIssuer((X500Principal) null);
assertTrue("Any certificates should match " + "in the case of null issuer criteria.", selector.match(cert1) && selector.match(cert2));
selector.setIssuer(iss1);
assertTrue("The certificate should match the selection criteria.", selector.match(cert1));
assertFalse("The certificate should not match the selection criteria.", selector.match(cert2));
selector.setIssuer(iss2);
assertTrue("The certificate should match the selection criteria.", selector.match(cert2));
}
use of javax.security.auth.x500.X500Principal in project robovm by robovm.
the class X509CertSelectorTest method test_setSubjectLjavax_security_auth_x500_X500Principal.
/**
* java.security.cert.X509CertSelector#setSubject(javax.security.auth.x500.X500Principal)
*/
public void test_setSubjectLjavax_security_auth_x500_X500Principal() throws Exception {
X500Principal sub1 = new X500Principal("O=First Org.");
X500Principal sub2 = new X500Principal("O=Second Org.");
TestCert cert1 = new TestCert(sub1);
TestCert cert2 = new TestCert(sub2);
X509CertSelector selector = new X509CertSelector();
selector.setSubject((X500Principal) null);
assertTrue("Any certificates should match " + "in the case of null subjcet criteria.", selector.match(cert1) && selector.match(cert2));
selector.setSubject(sub1);
assertTrue("The certificate should match the selection criteria.", selector.match(cert1));
assertFalse("The certificate should not match the selection criteria.", selector.match(cert2));
selector.setSubject(sub2);
assertTrue("The certificate should match the selection criteria.", selector.match(cert2));
}
use of javax.security.auth.x500.X500Principal in project robovm by robovm.
the class X509CertSelectorTest method test_getIssuerAsString.
/**
* java.security.cert.X509CertSelector#getIssuerAsString()
*/
public void test_getIssuerAsString() {
String name1 = "O=First Org.";
String name2 = "O=Second Org.";
X500Principal iss1 = new X500Principal(name1);
X500Principal iss2 = new X500Principal(name2);
X509CertSelector selector = new X509CertSelector();
assertNull("Selector should return null", selector.getIssuerAsString());
selector.setIssuer(iss1);
assertEquals("The returned issuer should be equal to specified", name1, selector.getIssuerAsString());
assertFalse("The returned issuer should differ", name2.equals(selector.getIssuerAsString()));
selector.setIssuer(iss2);
assertEquals("The returned issuer should be equal to specified", name2, selector.getIssuerAsString());
}
use of javax.security.auth.x500.X500Principal in project robovm by robovm.
the class X509CRLSelector method addIssuer.
/**
* Adds an issuer to the criterion for the issuer distinguished names.
* <p>
* The CRL issuer must match at least one of the specified distinguished
* names.
*
* @param issuer
* the issuer to add to the criterion
*/
public void addIssuer(X500Principal issuer) {
if (issuer == null) {
throw new NullPointerException("issuer == null");
}
if (issuerNames == null) {
issuerNames = new ArrayList<String>();
}
String name = issuer.getName(X500Principal.CANONICAL);
if (!issuerNames.contains(name)) {
issuerNames.add(name);
}
if (issuerPrincipals == null) {
issuerPrincipals = new ArrayList<X500Principal>(issuerNames.size());
}
// extend the list of issuer Principals
int size = issuerNames.size() - 1;
for (int i = issuerPrincipals.size(); i < size; i++) {
issuerPrincipals.add(new X500Principal(issuerNames.get(i)));
}
issuerPrincipals.add(issuer);
}
use of javax.security.auth.x500.X500Principal in project robovm by robovm.
the class X509CertSelector method setIssuer.
/**
* Sets the issuer that a certificate must match.
*
* @param issuerDN
* the distinguished issuer name in ASN.1 DER encoded format, or
* {@code null} to not check the issuer.
* @throws IOException
* if decoding the issuer fail.
*/
public void setIssuer(byte[] issuerDN) throws IOException {
if (issuerDN == null) {
issuer = null;
return;
}
try {
issuer = new X500Principal(issuerDN);
this.issuerName = null;
this.issuerBytes = new byte[issuerDN.length];
System.arraycopy(issuerDN, 0, this.issuerBytes, 0, issuerDN.length);
} catch (IllegalArgumentException e) {
throw new IOException(e.getMessage());
}
}
Aggregations