Search in sources :

Example 76 with TrustAnchor

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

the class TrustAnchorTest method testTrustAnchorX500PrincipalPublicKeybyteArray01.

/**
     * Test #1 for <code>TrustAnchor(X500Principal, PublicKey, byte[])</code> constructor<br>
     * Assertion: creates <code>TrustAnchor</code> instance<br>
     * Test preconditions: valid parameters passed<br>
     * Expected: must pass without any exceptions
     * @throws InvalidKeySpecException
     */
public final void testTrustAnchorX500PrincipalPublicKeybyteArray01() throws Exception {
    PublicKey pk = new TestKeyPair(keyAlg).getPublic();
    X500Principal x500p = new X500Principal(validCaNameRfc2253);
    // sub testcase 1
    new TrustAnchor(x500p, pk, getFullEncoding());
    // sub testcase 2
    new TrustAnchor(x500p, pk, getEncodingPSOnly());
    // sub testcase 3
    new TrustAnchor(x500p, pk, getEncodingESOnly());
    // sub testcase 4
    new TrustAnchor(x500p, pk, getEncodingNoMinMax());
}
Also used : TestKeyPair(org.apache.harmony.security.tests.support.TestKeyPair) PublicKey(java.security.PublicKey) X500Principal(javax.security.auth.x500.X500Principal) TrustAnchor(java.security.cert.TrustAnchor)

Example 77 with TrustAnchor

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

the class TrustAnchorTest method testTrustAnchorStringPublicKeybyteArray01.

/**
     * Test #1 for <code>TrustAnchor(String, PublicKey, byte[])</code> constructor<br>
     * Assertion: creates <code>TrustAnchor</code> instance<br>
     * Test preconditions: valid parameters passed<br>
     * Expected: must pass without any exceptions
     * @throws InvalidKeySpecException
     */
public final void testTrustAnchorStringPublicKeybyteArray01() throws Exception {
    PublicKey pk = new TestKeyPair(keyAlg).getPublic();
    // sub testcase 1
    new TrustAnchor(validCaNameRfc2253, pk, getFullEncoding());
    // sub testcase 2
    new TrustAnchor(validCaNameRfc2253, pk, getEncodingPSOnly());
    // sub testcase 3
    new TrustAnchor(validCaNameRfc2253, pk, getEncodingESOnly());
    // sub testcase 4
    new TrustAnchor(validCaNameRfc2253, pk, getEncodingNoMinMax());
}
Also used : TestKeyPair(org.apache.harmony.security.tests.support.TestKeyPair) PublicKey(java.security.PublicKey) TrustAnchor(java.security.cert.TrustAnchor)

Example 78 with TrustAnchor

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

the class TrustAnchorTest method testTrustAnchorStringPublicKeybyteArray03.

/**
     * Test #3 for <code>TrustAnchor(String, PublicKey, byte[])</code> constructor<br>
     * Assertion: nameConstraints cloned by the constructor<br>
     * Test preconditions: modify passed nameConstraints<br>
     * Expected: modification must not change object internal state
     * @throws InvalidKeySpecException
     */
public final void testTrustAnchorStringPublicKeybyteArray03() throws Exception {
    PublicKey pk = new TestKeyPair(keyAlg).getPublic();
    byte[] nc = getEncodingPSOnly();
    byte[] ncCopy = nc.clone();
    // sub testcase 5 - nameConstraints can be null
    TrustAnchor ta = new TrustAnchor(validCaNameRfc2253, pk, ncCopy);
    // modify
    ncCopy[0] = (byte) 0;
    // check that above modification did not change
    // object internal state
    assertTrue(Arrays.equals(nc, ta.getNameConstraints()));
}
Also used : TestKeyPair(org.apache.harmony.security.tests.support.TestKeyPair) PublicKey(java.security.PublicKey) TrustAnchor(java.security.cert.TrustAnchor)

Example 79 with TrustAnchor

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

the class TrustAnchorTest method testGetNameConstraints01.

/**
     * Test #1 for <code>getNameConstraints()</code> method<br>
     *
     * Assertion: Returns the name constraints parameter.<br>
     * Test preconditions: valid parameters are passed to the constructors<br>
     * Expected: the valid parameters must be returned by the method<br>
     */
public final void testGetNameConstraints01() throws Exception {
    PublicKey pk = new TestKeyPair(keyAlg).getPublic();
    TrustAnchor ta1 = new TrustAnchor(validCaNameRfc2253, pk, getFullEncoding());
    assertTrue(Arrays.equals(getFullEncoding(), ta1.getNameConstraints()));
    X500Principal x500p = new X500Principal(validCaNameRfc2253);
    TrustAnchor ta2 = new TrustAnchor(x500p, pk, getEncodingNoMinMax());
    assertTrue(Arrays.equals(getEncodingNoMinMax(), ta2.getNameConstraints()));
    CertificateFactory certFact = CertificateFactory.getInstance("X509");
    X509Certificate pemCert = (X509Certificate) certFact.generateCertificate(new ByteArrayInputStream(TestUtils.getX509Certificate_v3()));
    TrustAnchor ta3 = new TrustAnchor(pemCert, getEncodingPSOnly());
    assertTrue(Arrays.equals(getEncodingPSOnly(), ta3.getNameConstraints()));
}
Also used : TestKeyPair(org.apache.harmony.security.tests.support.TestKeyPair) ByteArrayInputStream(java.io.ByteArrayInputStream) PublicKey(java.security.PublicKey) X500Principal(javax.security.auth.x500.X500Principal) TrustAnchor(java.security.cert.TrustAnchor) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate)

Example 80 with TrustAnchor

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

the class TrustAnchorTest method testGetNameConstraints02.

/**
     * Test #2 for <code>getNameConstraints()</code> method<br>
     *
     * Assertion: Returns the name constraints parameter.<br>
     * Test preconditions: null parameters are passed to the constructors<br>
     * Expected: the null parameters must be returned by the method<br>
     */
public final void testGetNameConstraints02() throws Exception {
    PublicKey pk = new TestKeyPair(keyAlg).getPublic();
    TrustAnchor ta1 = new TrustAnchor(validCaNameRfc2253, pk, null);
    assertNull(ta1.getNameConstraints());
    X500Principal x500p = new X500Principal(validCaNameRfc2253);
    TrustAnchor ta2 = new TrustAnchor(x500p, pk, null);
    assertNull(ta2.getNameConstraints());
    CertificateFactory certFact = CertificateFactory.getInstance("X509");
    X509Certificate pemCert = (X509Certificate) certFact.generateCertificate(new ByteArrayInputStream(TestUtils.getX509Certificate_v3()));
    TrustAnchor ta3 = new TrustAnchor(pemCert, null);
    assertNull(ta3.getNameConstraints());
}
Also used : TestKeyPair(org.apache.harmony.security.tests.support.TestKeyPair) ByteArrayInputStream(java.io.ByteArrayInputStream) PublicKey(java.security.PublicKey) X500Principal(javax.security.auth.x500.X500Principal) TrustAnchor(java.security.cert.TrustAnchor) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate)

Aggregations

TrustAnchor (java.security.cert.TrustAnchor)103 X509Certificate (java.security.cert.X509Certificate)47 PublicKey (java.security.PublicKey)26 HashSet (java.util.HashSet)25 X500Principal (javax.security.auth.x500.X500Principal)23 PKIXParameters (java.security.cert.PKIXParameters)20 PKIXBuilderParameters (java.security.cert.PKIXBuilderParameters)19 X509CertSelector (java.security.cert.X509CertSelector)18 TestKeyPair (org.apache.harmony.security.tests.support.TestKeyPair)16 CertificateFactory (java.security.cert.CertificateFactory)15 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)14 CertPathValidatorException (java.security.cert.CertPathValidatorException)14 PKIXCertPathValidatorResult (java.security.cert.PKIXCertPathValidatorResult)14 ArrayList (java.util.ArrayList)14 CollectionCertStoreParameters (java.security.cert.CollectionCertStoreParameters)13 PKIXCertPathBuilderResult (java.security.cert.PKIXCertPathBuilderResult)13 IOException (java.io.IOException)12 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)10 CertPathBuilder (java.security.cert.CertPathBuilder)10 CertificateException (java.security.cert.CertificateException)10