Search in sources :

Example 11 with TestKeyPair

use of org.apache.harmony.security.tests.support.TestKeyPair in project robovm by robovm.

the class TrustAnchorTest method testGetCAName01.

/**
     * Test #1 for <code>getCAName()</code> method<br>
     *
     * Assertion: returns most trusted CA name as <code>String</code><br>
     * Test preconditions: valid name passed to the constructor<br>
     * Expected: the same name must be returned by the method<br>
     * @throws InvalidKeySpecException
     */
public final void testGetCAName01() throws Exception {
    PublicKey pk = new TestKeyPair(keyAlg).getPublic();
    // sub testcase 1
    TrustAnchor ta = new TrustAnchor(validCaNameRfc2253, pk, null);
    assertEquals("equals1", validCaNameRfc2253, ta.getCAName());
    // sub testcase 2
    X500Principal x500p = new X500Principal(validCaNameRfc2253);
    ta = new TrustAnchor(x500p, pk, null);
    assertEquals("equals2", validCaNameRfc2253, ta.getCAName());
}
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 12 with TestKeyPair

use of org.apache.harmony.security.tests.support.TestKeyPair in project robovm by robovm.

the class TrustAnchorTest method testTrustAnchorX500PrincipalPublicKeybyteArray03.

/**
     * Test #3 for <code>TrustAnchor(X500Principal, 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 testTrustAnchorX500PrincipalPublicKeybyteArray03() 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(new X500Principal(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) X500Principal(javax.security.auth.x500.X500Principal) TrustAnchor(java.security.cert.TrustAnchor)

Example 13 with TestKeyPair

use of org.apache.harmony.security.tests.support.TestKeyPair in project robovm by robovm.

the class X509CertSelectorTest method test_setSubjectPublicKeyLjava_security_PublicKey.

/**
     * java.security.cert.X509CertSelector#setSubjectPublicKey(java.security.PublicKey key)
     */
public void test_setSubjectPublicKeyLjava_security_PublicKey() throws Exception {
    PublicKey pkey1 = new TestKeyPair("RSA").getPublic();
    PublicKey pkey2 = new TestKeyPair("DSA").getPublic();
    TestCert cert1 = new TestCert(pkey1);
    TestCert cert2 = new TestCert(pkey2);
    X509CertSelector selector = new X509CertSelector();
    selector.setSubjectPublicKey((PublicKey) null);
    assertTrue("Any certificate should match in the case of null " + "subjectPublicKey criteria.", selector.match(cert1) && selector.match(cert2));
    selector.setSubjectPublicKey(pkey1);
    assertTrue("The certificate should match the selection criteria.", selector.match(cert1));
    assertFalse("The certificate should not match the selection criteria.", selector.match(cert2));
    selector.setSubjectPublicKey(pkey2);
    assertTrue("The certificate should match the selection criteria.", selector.match(cert2));
}
Also used : TestKeyPair(org.apache.harmony.security.tests.support.TestKeyPair) PublicKey(java.security.PublicKey) X509CertSelector(java.security.cert.X509CertSelector)

Example 14 with TestKeyPair

use of org.apache.harmony.security.tests.support.TestKeyPair 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 15 with TestKeyPair

use of org.apache.harmony.security.tests.support.TestKeyPair 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)

Aggregations

TestKeyPair (org.apache.harmony.security.tests.support.TestKeyPair)20 PublicKey (java.security.PublicKey)18 TrustAnchor (java.security.cert.TrustAnchor)16 X500Principal (javax.security.auth.x500.X500Principal)11 X509Certificate (java.security.cert.X509Certificate)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 CertificateFactory (java.security.cert.CertificateFactory)3 X509CertSelector (java.security.cert.X509CertSelector)3 IOException (java.io.IOException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 KnownFailure (dalvik.annotation.KnownFailure)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 KeyStore (java.security.KeyStore)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchProviderException (java.security.NoSuchProviderException)1 Signature (java.security.Signature)1 SignedObject (java.security.SignedObject)1 CertificateException (java.security.cert.CertificateException)1 PKIXBuilderParameters (java.security.cert.PKIXBuilderParameters)1 HashSet (java.util.HashSet)1