Search in sources :

Example 31 with TrustAnchor

use of java.security.cert.TrustAnchor in project robovm by robovm.

the class PKIXCertPathValidatorResultTest method testToString01.

/**
     * Test #1 for <code>toString()</code> method<br>
     * Assertion: Returns a formatted string describing this object
     * @throws NoSuchAlgorithmException
     * @throws InvalidKeySpecException
     */
public final void testToString01() throws Exception {
    TrustAnchor ta = TestUtils.getTrustAnchor();
    if (ta == null) {
        fail(getName() + ": not performed (could not create test TrustAnchor)");
    }
    PKIXCertPathValidatorResult vr = new PKIXCertPathValidatorResult(ta, TestUtils.getPolicyTree(), testPublicKey);
    assertNotNull(vr.toString());
}
Also used : PKIXCertPathValidatorResult(java.security.cert.PKIXCertPathValidatorResult) TrustAnchor(java.security.cert.TrustAnchor)

Example 32 with TrustAnchor

use of java.security.cert.TrustAnchor in project robovm by robovm.

the class PKIXCertPathValidatorResultTest method testGetPolicyTree02.

/**
     * Test for <code>getPolicyTree()</code> method<br>
     * Assertion: returns the root node of the valid
     * policy tree or <code>null</code> if there are
     * no valid policies
     * @throws NoSuchAlgorithmException
     * @throws InvalidKeySpecException
     */
public final void testGetPolicyTree02() throws Exception {
    TrustAnchor ta = TestUtils.getTrustAnchor();
    if (ta == null) {
        fail(getName() + ": not performed (could not create test TrustAnchor)");
    }
    // no valid policy tree case (null)
    PKIXCertPathValidatorResult vr = new PKIXCertPathValidatorResult(ta, null, testPublicKey);
    // must return the same reference passed
    // as a parameter to the constructor
    assertNull(vr.getPolicyTree());
}
Also used : PKIXCertPathValidatorResult(java.security.cert.PKIXCertPathValidatorResult) TrustAnchor(java.security.cert.TrustAnchor)

Example 33 with TrustAnchor

use of java.security.cert.TrustAnchor in project robovm by robovm.

the class PKIXCertPathValidatorResultTest method testPKIXCertPathValidatorResult03.

/**
     * Test #3 for <code>PKIXCertPathValidatorResult(TrustAnchor,
     * PolicyNode, PublicKey)</code> constructor<br>
     * Assertion: <code>NullPointerException</code> if
     * <code>PublicKey</code> parameter is <code>null</code>
     */
public final void testPKIXCertPathValidatorResult03() {
    TrustAnchor ta = TestUtils.getTrustAnchor();
    if (ta == null) {
        fail(getName() + ": not performed (could not create test TrustAnchor)");
    }
    try {
        // pass null
        new PKIXCertPathValidatorResult(ta, TestUtils.getPolicyTree(), null);
        fail("NPE expected");
    } catch (NullPointerException e) {
    }
}
Also used : PKIXCertPathValidatorResult(java.security.cert.PKIXCertPathValidatorResult) TrustAnchor(java.security.cert.TrustAnchor)

Example 34 with TrustAnchor

use of java.security.cert.TrustAnchor in project robovm by robovm.

the class OldPKIXParametersTest method testClone.

public final void testClone() throws InvalidAlgorithmParameterException {
    Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet();
    if (taSet == null) {
        fail(getName() + ": not performed (could not create test TrustAnchor set)");
    }
    PKIXParameters cpp = new PKIXParameters(taSet);
    PKIXParameters cppc = (PKIXParameters) cpp.clone();
    assertEquals(cpp.getPolicyQualifiersRejected(), cppc.getPolicyQualifiersRejected());
    assertEquals(cpp.getCertPathCheckers(), cppc.getCertPathCheckers());
    assertEquals(cpp.getCertStores(), cppc.getCertStores());
    assertEquals(cpp.getDate(), cppc.getDate());
    assertEquals(cpp.getInitialPolicies(), cppc.getInitialPolicies());
    assertEquals(cpp.getSigProvider(), cppc.getSigProvider());
    assertEquals(cpp.getTargetCertConstraints(), cppc.getTargetCertConstraints());
    assertEquals(cpp.getTrustAnchors(), cppc.getTrustAnchors());
    assertEquals(cpp.isAnyPolicyInhibited(), cppc.isAnyPolicyInhibited());
    assertEquals(cpp.isExplicitPolicyRequired(), cppc.isExplicitPolicyRequired());
    assertEquals(cpp.isPolicyMappingInhibited(), cppc.isPolicyMappingInhibited());
    assertEquals(cpp.isRevocationEnabled(), cppc.isRevocationEnabled());
    cpp.setDate(Calendar.getInstance().getTime());
    cpp.setPolicyQualifiersRejected(!cppc.getPolicyQualifiersRejected());
    assertFalse(cpp.getDate().equals(cppc.getDate()));
    assertFalse(cpp.getPolicyQualifiersRejected() == cppc.getPolicyQualifiersRejected());
    cppc.setExplicitPolicyRequired(!cpp.isExplicitPolicyRequired());
    cppc.setRevocationEnabled(!cpp.isRevocationEnabled());
    assertFalse(cpp.isExplicitPolicyRequired() == cppc.isExplicitPolicyRequired());
    assertFalse(cpp.isRevocationEnabled() == cppc.isRevocationEnabled());
    PKIXParameters cpp1 = null;
    try {
        cpp1.clone();
    } catch (NullPointerException e) {
    // expected
    }
}
Also used : PKIXParameters(java.security.cert.PKIXParameters) TrustAnchor(java.security.cert.TrustAnchor)

Example 35 with TrustAnchor

use of java.security.cert.TrustAnchor in project robovm by robovm.

the class ExtendedPKIXParameters method setTrustedACIssuers.

/**
     * Sets the trusted attribute certificate issuers. If attribute certificates
     * is verified the trusted AC issuers must be set.
     * <p>
     * The <code>trustedACIssuers</code> must be a <code>Set</code> of
     * <code>TrustAnchor</code>
     * <p>
     * The given set is cloned.
     * 
     * @param trustedACIssuers The trusted AC issuers to set. Is never
     *            <code>null</code>.
     * @throws ClassCastException if an element of <code>stores</code> is not
     *             a <code>TrustAnchor</code>.
     */
public void setTrustedACIssuers(Set trustedACIssuers) {
    if (trustedACIssuers == null) {
        this.trustedACIssuers.clear();
        return;
    }
    for (Iterator it = trustedACIssuers.iterator(); it.hasNext(); ) {
        if (!(it.next() instanceof TrustAnchor)) {
            throw new ClassCastException("All elements of set must be " + "of type " + TrustAnchor.class.getName() + ".");
        }
    }
    this.trustedACIssuers.clear();
    this.trustedACIssuers.addAll(trustedACIssuers);
}
Also used : Iterator(java.util.Iterator) TrustAnchor(java.security.cert.TrustAnchor)

Aggregations

TrustAnchor (java.security.cert.TrustAnchor)86 X509Certificate (java.security.cert.X509Certificate)35 PublicKey (java.security.PublicKey)24 X500Principal (javax.security.auth.x500.X500Principal)21 PKIXParameters (java.security.cert.PKIXParameters)17 TestKeyPair (org.apache.harmony.security.tests.support.TestKeyPair)16 HashSet (java.util.HashSet)15 CertificateFactory (java.security.cert.CertificateFactory)14 PKIXBuilderParameters (java.security.cert.PKIXBuilderParameters)14 PKIXCertPathValidatorResult (java.security.cert.PKIXCertPathValidatorResult)13 X509CertSelector (java.security.cert.X509CertSelector)13 CertPathValidatorException (java.security.cert.CertPathValidatorException)12 PKIXCertPathBuilderResult (java.security.cert.PKIXCertPathBuilderResult)12 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)11 ArrayList (java.util.ArrayList)11 ByteArrayInputStream (java.io.ByteArrayInputStream)8 CertPath (java.security.cert.CertPath)8 IOException (java.io.IOException)7 CertificateException (java.security.cert.CertificateException)7 CollectionCertStoreParameters (java.security.cert.CollectionCertStoreParameters)7