/** * Test #1 for <code>PKIXCertPathBuilderResult(CertPath, TrustAnchor, * PolicyNode, PublicKey)</code> constructor<br> * Assertion: Creates an instance of <code>PKIXCertPathBuilderResult</code> * @throws NoSuchAlgorithmException * @throws InvalidKeySpecException */ @TestTargetNew( level = TestLevel.PARTIAL_COMPLETE, method = "PKIXCertPathBuilderResult", args = {java.security.cert.CertPath.class, java.security.cert.TrustAnchor.class, java.security.cert.PolicyNode.class, java.security.PublicKey.class} ) public final void testPKIXCertPathBuilderResult01() throws InvalidKeySpecException, NoSuchAlgorithmException { TrustAnchor ta = TestUtils.getTrustAnchor(); if (ta == null) { fail(getName() + ": not performed (could not create test TrustAnchor)"); } CertPathBuilderResult r = new PKIXCertPathBuilderResult( new MyCertPath(testEncoding), ta, TestUtils.getPolicyTree(), testPublicKey); assertTrue(r instanceof PKIXCertPathBuilderResult); }
/** * Test #2 for <code>PKIXCertPathBuilderResult(CertPath, TrustAnchor, * PolicyNode, PublicKey)</code> constructor<br> * Assertion: policy tree parameter may be <code>null</code> * @throws NoSuchAlgorithmException * @throws InvalidKeySpecException */ @TestTargetNew( level = TestLevel.PARTIAL_COMPLETE, method = "PKIXCertPathBuilderResult", args = {java.security.cert.CertPath.class, java.security.cert.TrustAnchor.class, java.security.cert.PolicyNode.class, java.security.PublicKey.class} ) public final void testPKIXCertPathBuilderResult02() throws InvalidKeySpecException, NoSuchAlgorithmException { TrustAnchor ta = TestUtils.getTrustAnchor(); if (ta == null) { fail(getName() + ": not performed (could not create test TrustAnchor)"); } CertPathBuilderResult r = new PKIXCertPathBuilderResult( new MyCertPath(testEncoding), ta, null, testPublicKey); assertTrue(r instanceof PKIXCertPathBuilderResult); }
/** * Test for <code>getCertPath()</code> method<br> * Assertion: the built and validated <code>CertPath</code> * (never <code>null</code>) * @throws NoSuchAlgorithmException * @throws InvalidKeySpecException */ @TestTargetNew( level = TestLevel.COMPLETE, notes = "", method = "getCertPath", args = {} ) 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()); }
/** * Test for <code>toString()</code> method<br> * Assertion: the printable representation of this object * @throws NoSuchAlgorithmException * @throws InvalidKeySpecException */ @TestTargetNew( level = TestLevel.COMPLETE, notes = "", method = "toString", args = {} ) public final void testToString() throws InvalidKeySpecException, NoSuchAlgorithmException { TrustAnchor ta = TestUtils.getTrustAnchor(); if (ta == null) { fail(getName() + ": not performed (could not create test TrustAnchor)"); } CertPathBuilderResult r = new PKIXCertPathBuilderResult( new MyCertPath(testEncoding), ta, TestUtils.getPolicyTree(), testPublicKey); assertNotNull(r.toString()); }
@TestTargetNew( level=TestLevel.PARTIAL_COMPLETE, notes = "Verifies normal case", method="build", args={CertPathParameters.class} ) // Test passed on RI @KnownFailure(value="expired certificate bug 2322662") public void testBuild() throws Exception { TestUtils.initCertPathSSCertChain(); CertPathParameters params = TestUtils.getCertPathParameters(); CertPathBuilder builder = TestUtils.getCertPathBuilder(); try { CertPathBuilderResult result = builder.build(params); assertNotNull("builder result is null", result); CertPath certPath = result.getCertPath(); assertNotNull("certpath of builder result is null", certPath); } catch (InvalidAlgorithmParameterException e) { fail("unexpected Exception: " + e); } }
private void checkResult(CertPathBuilder certBuild) throws InvalidAlgorithmParameterException, CertPathBuilderException { String dt = CertPathBuilder.getDefaultType(); String propName = CertPathBuilder1Test.DEFAULT_TYPE_PROPERTY; String dtN; for (int i = 0; i <invalidValues.length; i++) { Security.setProperty(propName, invalidValues[i]); dtN = CertPathBuilder.getDefaultType(); if (!dtN.equals(invalidValues[i]) && !dtN.equals(dt)) { fail("Incorrect default type: ".concat(dtN)); } } Security.setProperty(propName, dt); assertEquals("Incorrect default type", CertPathBuilder.getDefaultType(), dt); try { certBuild.build(null); fail("CertPathBuilderException must be thrown"); } catch (CertPathBuilderException e) { } CertPathBuilderResult cpbResult = certBuild.build(null); assertNull("Not null CertPathBuilderResult", cpbResult); }
/** * Test #1 for <code>PKIXCertPathBuilderResult(CertPath, TrustAnchor, * PolicyNode, PublicKey)</code> constructor<br> * Assertion: Creates an instance of <code>PKIXCertPathBuilderResult</code> * @throws NoSuchAlgorithmException * @throws InvalidKeySpecException */ public final void testPKIXCertPathBuilderResult01() throws InvalidKeySpecException, NoSuchAlgorithmException { TrustAnchor ta = TestUtils.getTrustAnchor(); if (ta == null) { fail(getName() + ": not performed (could not create test TrustAnchor)"); } CertPathBuilderResult r = new PKIXCertPathBuilderResult( new MyCertPath(testEncoding), ta, TestUtils.getPolicyTree(), testPublicKey); assertTrue(r instanceof PKIXCertPathBuilderResult); }
/** * Test #2 for <code>PKIXCertPathBuilderResult(CertPath, TrustAnchor, * PolicyNode, PublicKey)</code> constructor<br> * Assertion: policy tree parameter may be <code>null</code> * @throws NoSuchAlgorithmException * @throws InvalidKeySpecException */ public final void testPKIXCertPathBuilderResult02() throws InvalidKeySpecException, NoSuchAlgorithmException { TrustAnchor ta = TestUtils.getTrustAnchor(); if (ta == null) { fail(getName() + ": not performed (could not create test TrustAnchor)"); } CertPathBuilderResult r = new PKIXCertPathBuilderResult( new MyCertPath(testEncoding), ta, null, testPublicKey); assertTrue(r instanceof PKIXCertPathBuilderResult); }
/** * 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()); }
/** * Test for <code>toString()</code> method<br> * Assertion: the printable representation of this object * @throws NoSuchAlgorithmException * @throws InvalidKeySpecException */ public final void testToString() throws InvalidKeySpecException, NoSuchAlgorithmException { TrustAnchor ta = TestUtils.getTrustAnchor(); if (ta == null) { fail(getName() + ": not performed (could not create test TrustAnchor)"); } CertPathBuilderResult r = new PKIXCertPathBuilderResult( new MyCertPath(testEncoding), ta, TestUtils.getPolicyTree(), testPublicKey); assertNotNull(r.toString()); }
private void doBuild(X509Certificate userCert) throws Exception { // get the set of trusted CA certificates (only one in this instance) HashSet trustAnchors = new HashSet(); X509Certificate trustedCert = getTrustedCertificate(); trustAnchors.add(new TrustAnchor(trustedCert, null)); // put together a CertStore (repository of the certificates and CRLs) ArrayList certs = new ArrayList(); certs.add(trustedCert); certs.add(userCert); CollectionCertStoreParameters certStoreParams = new CollectionCertStoreParameters(certs); CertStore certStore = CertStore.getInstance("Collection", certStoreParams); // specify the target certificate via a CertSelector X509CertSelector certSelector = new X509CertSelector(); certSelector.setCertificate(userCert); certSelector.setSubject(userCert.getSubjectDN().getName()); // seems to be required // build a valid cerificate path CertPathBuilder certPathBuilder = CertPathBuilder.getInstance("PKIX", "SUN"); PKIXBuilderParameters certPathBuilderParams = new PKIXBuilderParameters(trustAnchors, certSelector); certPathBuilderParams.addCertStore(certStore); certPathBuilderParams.setRevocationEnabled(false); CertPathBuilderResult result = certPathBuilder.build(certPathBuilderParams); // get and show cert path CertPath certPath = result.getCertPath(); // System.out.println(certPath.toString()); }
/** * Perform a PKIX build. * * @param params PKIXBuilderParameters to use in building * @throws Exception on error */ public static void build(PKIXBuilderParameters params) throws Exception { CertPathBuilder builder = CertPathBuilder.getInstance("PKIX"); CertPathBuilderResult cpbr = builder.build(params); }
/** * Perform a PKIX build. * * @param params PKIXBuilderParameters to use in the build * @throws Exception on error */ public static void build(PKIXBuilderParameters params) throws Exception { CertPathBuilder builder = CertPathBuilder.getInstance("PKIX", "SUN"); CertPathBuilderResult cpbr = builder.build(params); }