Search in sources :

Example 6 with TestKeyPair

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

the class TrustAnchorTest method testGetCAPublicKey01.

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

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

the class TrustAnchorTest method testTrustAnchorX500PrincipalPublicKeybyteArray04.

/**
     * Test #4 for <code>TrustAnchor(X500Principal, PublicKey, byte[])</code> constructor<br>
     * Assertion: <code>NullPointerException</code> if <code>caPrincipal</code>
     * or <code>caPublicKey</code> parameter is <code>null</code><br>
     * Test preconditions: pass <code>null</code> as mentioned parameter<br>
     * Expected: NullPointerException
     * @throws InvalidKeySpecException
     */
public final void testTrustAnchorX500PrincipalPublicKeybyteArray04() throws Exception {
    PublicKey pk = new TestKeyPair(keyAlg).getPublic();
    X500Principal x500p = new X500Principal(validCaNameRfc2253);
    // sub testcase 1
    try {
        new TrustAnchor((X500Principal) null, pk, getEncodingPSOnly());
        fail("NullPointerException has not been thrown");
    } catch (NullPointerException ok) {
    }
    // sub testcase 2
    try {
        new TrustAnchor(x500p, null, getEncodingPSOnly());
        fail("NullPointerException has not been thrown");
    } catch (NullPointerException ok) {
    }
    // sub testcase 3
    try {
        new TrustAnchor((X500Principal) null, null, getEncodingPSOnly());
        fail("NullPointerException has not been thrown");
    } catch (NullPointerException ok) {
    }
}
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 8 with TestKeyPair

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

the class TrustAnchorTest method testTrustAnchorStringPublicKeybyteArray02.

/**
     * Test #2 for <code>TrustAnchor(String, PublicKey, byte[])</code> constructor<br>
     * Assertion: creates <code>TrustAnchor</code> instance<br>
     * Test preconditions: <code>null</code> as nameConstraints passed<br>
     * Expected: must pass without any exceptions
     * @throws InvalidKeySpecException
     */
public final void testTrustAnchorStringPublicKeybyteArray02() throws Exception {
    PublicKey pk = new TestKeyPair(keyAlg).getPublic();
    new TrustAnchor(validCaNameRfc2253, pk, null);
}
Also used : TestKeyPair(org.apache.harmony.security.tests.support.TestKeyPair) PublicKey(java.security.PublicKey) TrustAnchor(java.security.cert.TrustAnchor)

Example 9 with TestKeyPair

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

the class TrustAnchorTest method testGetCA01.

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

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

the class myTrustManagerFactory method test_initLjavax_net_ssl_ManagerFactoryParameters.

/**
     * Test for <code>init(ManagerFactoryParameters params)</code>
     * Assertion:
     * throws InvalidAlgorithmParameterException when params is null
     */
@KnownFailure("ManagerFactoryParameters object is not supported " + "and InvalidAlgorithmParameterException was thrown.")
public void test_initLjavax_net_ssl_ManagerFactoryParameters() throws Exception {
    ManagerFactoryParameters par = null;
    TrustManagerFactory[] trustMF = createTMFac();
    assertNotNull("TrustManagerFactory objects were not created", trustMF);
    for (int i = 0; i < trustMF.length; i++) {
        try {
            trustMF[i].init(par);
            fail("InvalidAlgorithmParameterException must be thrown");
        } catch (InvalidAlgorithmParameterException e) {
        }
    }
    String keyAlg = "DSA";
    String validCaNameRfc2253 = ("CN=Test CA," + "OU=Testing Division," + "O=Test It All," + "L=Test Town," + "ST=Testifornia," + "C=Testland");
    try {
        KeyStore kStore = KeyStore.getInstance(KeyStore.getDefaultType());
        kStore.load(null, null);
        PublicKey pk = new TestKeyPair(keyAlg).getPublic();
        TrustAnchor ta = new TrustAnchor(validCaNameRfc2253, pk, getFullEncoding());
        Set<TrustAnchor> trustAnchors = new HashSet<TrustAnchor>();
        trustAnchors.add(ta);
        X509CertSelector xcs = new X509CertSelector();
        PKIXBuilderParameters pkixBP = new PKIXBuilderParameters(trustAnchors, xcs);
        CertPathTrustManagerParameters cptmp = new CertPathTrustManagerParameters(pkixBP);
        TrustManagerFactory tmf = TrustManagerFactory.getInstance(getDefaultAlgorithm());
        try {
            tmf.init(cptmp);
        } catch (Exception ex) {
            fail(ex + " was thrown for init(ManagerFactoryParameters spec)");
        }
    } catch (Exception e) {
        fail("Unexpected exception for configuration: " + e);
    }
}
Also used : TestKeyPair(org.apache.harmony.security.tests.support.TestKeyPair) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) PublicKey(java.security.PublicKey) PKIXBuilderParameters(java.security.cert.PKIXBuilderParameters) CertPathTrustManagerParameters(javax.net.ssl.CertPathTrustManagerParameters) TrustAnchor(java.security.cert.TrustAnchor) X509CertSelector(java.security.cert.X509CertSelector) KeyStore(java.security.KeyStore) KeyStoreException(java.security.KeyStoreException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NoSuchProviderException(java.security.NoSuchProviderException) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) ManagerFactoryParameters(javax.net.ssl.ManagerFactoryParameters) HashSet(java.util.HashSet) KnownFailure(dalvik.annotation.KnownFailure)

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