use of java.security.cert.X509CRLSelector in project robovm by robovm.
the class X509CRLSelector2Test method testMatchLjava_security_cert_X509CRL.
/**
* match(CRL crl) method testing. Tests if the null object matches to the
* selector or not.
*/
public void testMatchLjava_security_cert_X509CRL() {
X509CRLSelector selector = new X509CRLSelector();
assertFalse("The null object should not match", selector.match((X509CRL) null));
}
use of java.security.cert.X509CRLSelector in project robovm by robovm.
the class X509CRLSelector2Test method testToString.
public void testToString() {
X509CRLSelector selector = new X509CRLSelector();
X500Principal iss1 = new X500Principal("O=First Org.");
X500Principal iss2 = new X500Principal("O=Second Org.");
BigInteger minCRL = new BigInteger("10000");
BigInteger maxCRL = new BigInteger("10000");
Date date = new Date(200);
selector.addIssuer(iss1);
selector.addIssuer(iss2);
selector.setMinCRLNumber(minCRL);
selector.setMaxCRLNumber(maxCRL);
selector.setDateAndTime(date);
assertNotNull("The result should not be null.", selector.toString());
}
use of java.security.cert.X509CRLSelector in project robovm by robovm.
the class X509CRLSelector2Test method testSetIssuersLjava_util_Collection.
/**
* setIssuers(Collection <X500Principal> issuers) method testing. Tests if
* CRLs with any issuers match the selector in the case of null issuerNames
* criteria, if specified issuers match the selector, and if not specified
* issuer does not match the selector.
*/
public void testSetIssuersLjava_util_Collection() {
X509CRLSelector selector = new X509CRLSelector();
X500Principal iss1 = new X500Principal("O=First Org.");
X500Principal iss2 = new X500Principal("O=Second Org.");
X500Principal iss3 = new X500Principal("O=Third Org.");
TestCRL crl1 = new TestCRL(iss1);
TestCRL crl2 = new TestCRL(iss2);
TestCRL crl3 = new TestCRL(iss3);
selector.setIssuers(null);
assertTrue("Any CRL issuers should match in the case of null issuers.", selector.match(crl1) && selector.match(crl2));
ArrayList<X500Principal> issuers = new ArrayList<X500Principal>(2);
issuers.add(iss1);
issuers.add(iss2);
selector.setIssuers(issuers);
assertTrue("The CRL should match the selection criteria.", selector.match(crl1) && selector.match(crl2));
assertFalse("The CRL should not match the selection criteria.", selector.match(crl3));
issuers.add(iss3);
assertFalse("The internal issuer collection is not protected " + "against the modifications.", selector.match(crl3));
}
use of java.security.cert.X509CRLSelector in project jdk8u_jdk by JetBrains.
the class Pair method loadCRLs.
/**
* Loads CRLs from a source. This method is also called in JarSigner.
* @param src the source, which means System.in if null, or a URI,
* or a bare file path name
*/
public static Collection<? extends CRL> loadCRLs(String src) throws Exception {
InputStream in = null;
URI uri = null;
if (src == null) {
in = System.in;
} else {
try {
uri = new URI(src);
if (uri.getScheme().equals("ldap")) {
// No input stream for LDAP
} else {
in = uri.toURL().openStream();
}
} catch (Exception e) {
try {
in = new FileInputStream(src);
} catch (Exception e2) {
if (uri == null || uri.getScheme() == null) {
// More likely a bare file path
throw e2;
} else {
// More likely a protocol or network problem
throw e;
}
}
}
}
if (in != null) {
try {
// Read the full stream before feeding to X509Factory,
// otherwise, keytool -gencrl | keytool -printcrl
// might not work properly, since -gencrl is slow
// and there's no data in the pipe at the beginning.
ByteArrayOutputStream bout = new ByteArrayOutputStream();
byte[] b = new byte[4096];
while (true) {
int len = in.read(b);
if (len < 0)
break;
bout.write(b, 0, len);
}
return CertificateFactory.getInstance("X509").generateCRLs(new ByteArrayInputStream(bout.toByteArray()));
} finally {
if (in != System.in) {
in.close();
}
}
} else {
// must be LDAP, and uri is not null
// Lazily load LDAPCertStoreHelper if present
CertStoreHelper helper = CertStoreHelper.getInstance("LDAP");
String path = uri.getPath();
if (path.charAt(0) == '/')
path = path.substring(1);
CertStore s = helper.getCertStore(uri);
X509CRLSelector sel = helper.wrap(new X509CRLSelector(), null, path);
return s.getCRLs(sel);
}
}
Aggregations