use of java.security.cert.CertPath in project robovm by robovm.
the class CertificateFactoryTest method testGenerateCertPath.
/* CertPath tests */
public void testGenerateCertPath() throws Exception {
KeyHolder ca = generateCertificate(true, null);
KeyHolder cert1 = generateCertificate(true, ca);
KeyHolder cert2 = generateCertificate(false, cert1);
KeyHolder cert3 = generateCertificate(false, cert2);
List<X509Certificate> certs = new ArrayList<X509Certificate>();
certs.add(cert3.certificate);
certs.add(cert2.certificate);
certs.add(cert1.certificate);
List<X509Certificate> duplicatedCerts = new ArrayList<X509Certificate>(certs);
duplicatedCerts.add(cert2.certificate);
Provider[] providers = Security.getProviders("CertificateFactory.X509");
for (Provider p : providers) {
final CertificateFactory cf = CertificateFactory.getInstance("X.509", p);
// Duplicate certificates can cause an exception.
{
final CertPath duplicatedPath = cf.generateCertPath(duplicatedCerts);
try {
duplicatedPath.getEncoded();
if (StandardNames.IS_RI) {
fail("duplicate certificates should cause failure: " + p.getName());
}
} catch (CertificateEncodingException expected) {
if (!StandardNames.IS_RI) {
fail("duplicate certificates should pass: " + p.getName());
}
}
}
testCertPathEncoding(cf, certs, null);
/* Make sure all encoding entries are the same. */
final Iterator<String> it1 = cf.getCertPathEncodings();
final Iterator<String> it2 = cf.generateCertPath(certs).getEncodings();
for (; ; ) {
assertEquals(p.getName(), it1.hasNext(), it2.hasNext());
if (!it1.hasNext()) {
break;
}
String encoding = it1.next();
assertEquals(p.getName(), encoding, it2.next());
try {
it1.remove();
fail("Should not be able to remove from iterator");
} catch (UnsupportedOperationException expected) {
}
try {
it2.remove();
fail("Should not be able to remove from iterator");
} catch (UnsupportedOperationException expected) {
}
/* Now test using this encoding. */
testCertPathEncoding(cf, certs, encoding);
}
}
}
use of java.security.cert.CertPath in project robovm by robovm.
the class CodeSignerTest method testEqualsObject.
/**
* Test various assertions about equals()
*/
public final void testEqualsObject() {
CodeSigner one = new CodeSigner(cpath, ts);
CodeSigner two = new CodeSigner(cpath, ts);
CodeSigner three = new CodeSigner(cpath, null);
CertPath cpath2 = TestCertUtils.genCertPath(5, 3);
CodeSigner four = new CodeSigner(cpath2, null);
assertTrue(one.equals(one));
assertTrue(one.equals(two));
assertTrue(two.equals(one));
assertFalse(one.equals(three));
assertFalse(three.equals(one));
assertTrue(three.equals(three));
// different CertPaths
assertFalse(three.equals(four));
// special cases
assertFalse(one.equals(null));
assertFalse(one.equals(new Object()));
}
use of java.security.cert.CertPath in project robovm by robovm.
the class CertificateFactory3Test method testGenerateCertPath02.
/**
* Test for
* <code>generateCertPath(InputStream inStream, String encoding)</code>
* method Assertion: returns CertPath with 1 Certificate
*/
public void testGenerateCertPath02() throws Exception {
CertificateFactory[] certFs = initCertFs();
assertNotNull("CertificateFactory objects were not created", certFs);
for (int i = 0; i < certFs.length; i++) {
CertPath certPath = null;
InputStream fis = Support_Resources.getResourceStream(fileCertPathPki);
certPath = certFs[i].generateCertPath(fis, "PkiPath");
fis.close();
assertEquals(defaultType, certPath.getType());
List<? extends Certificate> list1 = certPath.getCertificates();
assertFalse("Result list is empty", list1.isEmpty());
}
}
use of java.security.cert.CertPath in project robovm by robovm.
the class CertificateFactory3Test method testGenerateCertPath03.
/**
* Test for <code>generateCertPath(InputStream inStream)</code> method
* Assertion: returns CertPath with 1 Certificate
*/
public void testGenerateCertPath03() throws Exception {
String certPathEncoding = "PkiPath";
CertificateFactory[] certFs = initCertFs();
assertNotNull("CertificateFactory objects were not created", certFs);
for (int i = 0; i < certFs.length; i++) {
Iterator<String> it = certFs[0].getCertPathEncodings();
assertTrue("no CertPath encodings", it.hasNext());
assertEquals("Incorrect default encoding", certPathEncoding, it.next());
CertPath certPath = null;
InputStream fis = Support_Resources.getResourceStream(fileCertPathPki);
certPath = certFs[i].generateCertPath(fis);
fis.close();
assertEquals(defaultType, certPath.getType());
List<? extends Certificate> list1 = certPath.getCertificates();
assertFalse("Result list is empty", list1.isEmpty());
}
}
use of java.security.cert.CertPath in project robovm by robovm.
the class PKIXCertPathBuilderResultTest method testGetCertPath.
/**
* Test for <code>getCertPath()</code> method<br>
* Assertion: the built and validated <code>CertPath</code>
* (never <code>null</code>)
* @throws NoSuchAlgorithmException
* @throws InvalidKeySpecException
*/
public final void testGetCertPath() throws Exception {
TrustAnchor ta = TestUtils.getTrustAnchor();
if (ta == null) {
fail(getName() + ": not performed (could not create test TrustAnchor)");
}
CertPath cp = new MyCertPath(testEncoding);
CertPathBuilderResult r = new PKIXCertPathBuilderResult(cp, ta, TestUtils.getPolicyTree(), testPublicKey);
// must return the same reference
// as passed to the constructor
assertSame(cp, r.getCertPath());
}
Aggregations