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());
}
use of java.security.cert.CertPath in project robovm by robovm.
the class CertificateTest method testVerifyMD2_chain.
public void testVerifyMD2_chain() throws Exception {
CertificateFactory certificateFactory = CertificateFactory.getInstance("X509");
// First check with the trust anchor not included in the chain
CertPath path = certificateFactory.generateCertPath(getCertList(true, false));
CertPathValidator certPathValidator = CertPathValidator.getInstance("PKIX");
PKIXParameters params = createPKIXParams();
CertPathValidatorResult res = certPathValidator.validate(path, params);
assertTrue("wrong result type", res instanceof PKIXCertPathValidatorResult);
PKIXCertPathValidatorResult r = (PKIXCertPathValidatorResult) res;
assertTrue("Wrong trust anchor returned", params.getTrustAnchors().contains(r.getTrustAnchor()));
// Now check with the trust anchor included in the chain
path = certificateFactory.generateCertPath(getCertList(true, true));
certPathValidator = CertPathValidator.getInstance("PKIX");
params = createPKIXParams();
if (StandardNames.IS_RI) {
res = certPathValidator.validate(path, params);
assertTrue("wrong result type", res instanceof PKIXCertPathValidatorResult);
r = (PKIXCertPathValidatorResult) res;
assertTrue("Wrong trust anchor returned", params.getTrustAnchors().contains(r.getTrustAnchor()));
} else {
try {
certPathValidator.validate(path, params);
fail();
} catch (CertPathValidatorException expected) {
}
}
}
use of java.security.cert.CertPath in project robovm by robovm.
the class CertificateTest method testVerifyMD5_chain.
public void testVerifyMD5_chain() throws Exception {
CertificateFactory certificateFactory = CertificateFactory.getInstance("X509");
// First check with the trust anchor not included in the chain
CertPath path = certificateFactory.generateCertPath(getCertList(false, false));
CertPathValidator certPathValidator = CertPathValidator.getInstance("PKIX");
PKIXParameters params = createPKIXParams();
CertPathValidatorResult res = certPathValidator.validate(path, params);
assertTrue("wrong result type", res instanceof PKIXCertPathValidatorResult);
PKIXCertPathValidatorResult r = (PKIXCertPathValidatorResult) res;
assertTrue("Wrong trust anchor returned", params.getTrustAnchors().contains(r.getTrustAnchor()));
// Now check with the trust anchor included in the chain
path = certificateFactory.generateCertPath(getCertList(false, true));
certPathValidator = CertPathValidator.getInstance("PKIX");
params = createPKIXParams();
res = certPathValidator.validate(path, params);
assertTrue("wrong result type", res instanceof PKIXCertPathValidatorResult);
r = (PKIXCertPathValidatorResult) res;
assertTrue("Wrong trust anchor returned", params.getTrustAnchors().contains(r.getTrustAnchor()));
}
Aggregations