harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r503371 [5/5] - in /harmony/enhanced/classlib/trunk/modules/x-net: ./ META-INF/ src/main/java/org/apache/harmony/xnet/provider/jsse/ src/test/api/java/org/apache/harmony/xnet/tests/javax/net/ssl/ src/test/impl/java.injected/org/apache/harmo...
Date Sun, 04 Feb 2007 08:10:11 GMT
Added: harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/ServerHandshakeImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/ServerHandshakeImplTest.java?view=auto&rev=503371
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/ServerHandshakeImplTest.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/ServerHandshakeImplTest.java
Sun Feb  4 00:10:09 2007
@@ -0,0 +1,139 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.xnet.provider.jsse;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.security.KeyStore;
+import java.security.SecureRandom;
+
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.TrustManagerFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for <code>ServerHandshakeImpl</code> constructor and methods
+ *  
+ */
+public class ServerHandshakeImplTest extends TestCase {
+  // to store initialization Exception
+  private static Exception initException;
+
+  
+  private SSLParameters sslParameters;
+  private ServerHandshakeImpl server;
+
+  public void setUp() throws Exception {
+        char[] pwd = JSSETestData.KS_PASSWORD;
+        KeyStore ks = JSSETestData.getKeyStore();
+
+        KeyManagerFactory kmf = KeyManagerFactory.getInstance("X509");
+        kmf.init(ks, pwd);
+
+        TrustManagerFactory tmf = TrustManagerFactory.getInstance("X509");
+        tmf.init(ks);
+
+        sslParameters = new SSLParameters(kmf.getKeyManagers(), tmf
+                .getTrustManagers(), new SecureRandom(),
+                new SSLSessionContextImpl(), new SSLSessionContextImpl());
+
+        server = new ServerHandshakeImpl(new SSLEngineImpl(sslParameters));
+
+        SSLEngineAppData appData = new SSLEngineAppData();
+        AlertProtocol alertProtocol = new AlertProtocol();
+        SSLBufferedInput recProtIS = new SSLBufferedInput();
+        SSLRecordProtocol recordProtocol = new SSLRecordProtocol(server,
+                alertProtocol, recProtIS, appData);
+    }
+
+    public void testUnwrap() {
+        byte[] ses_id = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
+        byte[] version = new byte[] { 3, 1 };
+        CipherSuite[] cipher_suite = new CipherSuite[] { 
+                CipherSuite.TLS_RSA_WITH_RC4_128_MD5 };
+        ClientHello message = new ClientHello(new SecureRandom(), version,
+                ses_id, cipher_suite);
+        HandshakeIODataStream out = new HandshakeIODataStream();
+        out.writeUint8(message.getType());
+        out.writeUint24(message.length());
+        message.send(out);
+        byte[] encodedClientHello = out.getData(1000);
+        
+        // ----------------------------------------
+        // unwrap client hello (full handshake)
+        // precondition: session hash does not contains requested sesssion        
+        server.unwrap(encodedClientHello);
+        server.getTask().run(); // process client hello in delegated task
+        server.wrap(); // modelling of server respond sending
+        
+        assertFalse(server.isResuming);
+
+        // unwrap unexpected second client hello
+        try {
+            server.unwrap(encodedClientHello);
+            fail("No expected AlertException");
+        } catch (AlertException e) {
+        }
+        
+        // unexpected ChangeCipherSpec
+        try {
+            server.receiveChangeCipherSpec();
+            fail("No expected AlertException");
+        } catch (AlertException e) {
+        }
+        
+        // ----------------------------------------
+        // unwrap client hello (abbreviated handshake)
+        // precondition: session hash contains requested sesssion
+        clearServerData();
+        SSLSessionImpl session = new SSLSessionImpl(
+                CipherSuite.TLS_RSA_WITH_RC4_128_MD5, new SecureRandom());
+        session.id = ses_id;
+        // put session to hash
+        server.parameters.getServerSessionContext().putSession(session);
+        
+        server.unwrap(encodedClientHello);
+        server.getTask().run(); // process client hello in delegated task
+        server.wrap(); // modelling of server respond sending
+        
+        assertTrue(server.isResuming);
+        
+        server.makeFinished(); // complete handshake
+        
+        // expected ChangeCipherSpec
+        server.receiveChangeCipherSpec();      
+    }
+
+    public void testServerHandshakeImpl() {
+        assertEquals(server.status, HandshakeProtocol.NEED_UNWRAP);
+        assertTrue(server.nonBlocking);
+        assertSame(server.parameters.getKeyManager(), sslParameters
+                .getKeyManager());
+        assertSame(server.parameters.getTrustManager(), sslParameters
+                .getTrustManager());
+        assertNotNull(server.engineOwner);
+        assertNull(server.socketOwner);
+    }
+
+    private void clearServerData() {
+        server.clearMessages();
+        server.io_stream = new HandshakeIODataStream();
+        server.status = HandshakeProtocol.NEED_UNWRAP;
+    }
+}
\ No newline at end of file

Propchange: harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/ServerHandshakeImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/TrustManagerImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/TrustManagerImplTest.java?view=auto&rev=503371
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/TrustManagerImplTest.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/TrustManagerImplTest.java
Sun Feb  4 00:10:09 2007
@@ -0,0 +1,127 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.xnet.provider.jsse;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.security.KeyStore;
+import java.security.cert.CertificateException;
+import java.security.cert.CertificateFactory;
+import java.security.cert.X509Certificate;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for <code>TrustManagerImpl</code> constructor and methods
+ *  
+ */
+public class TrustManagerImplTest extends TestCase {
+
+    // Cert. encoding.was generated by using of classes
+    // from org.apache.harmony.security.asn1 package and encoded
+    // by org.apache.harmony.misc.Base64 class.
+    // Source:
+    // org.apache.harmony.security.tests.support.provider.cert.CertFactoryTestData
+    private static String base64certEncoding = 
+        "-----BEGIN CERTIFICATE-----\n" +
+        "MIIC+jCCAragAwIBAgICAiswDAYHKoZIzjgEAwEBADAdMRswGQYDVQQKExJDZXJ0a" +
+        "WZpY2F0ZSBJc3N1ZXIwIhgPMTk3MDAxMTIxMzQ2NDBaGA8xOTcwMDEyNDAzMzMyMF" +
+        "owHzEdMBsGA1UEChMUU3ViamVjdCBPcmdhbml6YXRpb24wGTAMBgcqhkjOOAQDAQE" +
+        "AAwkAAQIDBAUGBwiBAgCqggIAVaOCAhQwggIQMA8GA1UdDwEB/wQFAwMBqoAwEgYD" +
+        "VR0TAQH/BAgwBgEB/wIBBTAUBgNVHSABAf8ECjAIMAYGBFUdIAAwZwYDVR0RAQH/B" +
+        "F0wW4EMcmZjQDgyMi5OYW1lggdkTlNOYW1lpBcxFTATBgNVBAoTDE9yZ2FuaXphdG" +
+        "lvboYaaHR0cDovL3VuaWZvcm0uUmVzb3VyY2UuSWSHBP///wCIByoDolyDsgMwDAY" +
+        "DVR0eAQH/BAIwADAMBgNVHSQBAf8EAjAAMIGZBgNVHSUBAf8EgY4wgYsGBFUdJQAG" +
+        "CCsGAQUFBwMBBggrBgEFBQcDAQYIKwYBBQUHAwIGCCsGAQUFBwMDBggrBgEFBQcDB" +
+        "AYIKwYBBQUHAwUGCCsGAQUFBwMGBggrBgEFBQcDBwYIKwYBBQUHAwgGCCsGAQUFBw" +
+        "MJBggrBgEFBQgCAgYKKwYBBAGCNwoDAwYJYIZIAYb4QgQBMA0GA1UdNgEB/wQDAgE" +
+        "BMA4GBCpNhgkBAf8EAwEBATBkBgNVHRIEXTBbgQxyZmNAODIyLk5hbWWCB2ROU05h" +
+        "bWWkFzEVMBMGA1UEChMMT3JnYW5pemF0aW9uhhpodHRwOi8vdW5pZm9ybS5SZXNvd" +
+        "XJjZS5JZIcE////AIgHKgOiXIOyAzAJBgNVHR8EAjAAMAoGA1UdIwQDAQEBMAoGA1" +
+        "UdDgQDAQEBMAoGA1UdIQQDAQEBMAwGByqGSM44BAMBAQADMAAwLQIUAL4QvoazNWP" +
+        "7jrj84/GZlhm09DsCFQCBKGKCGbrP64VtUt4JPmLjW1VxQA==\n" +
+        "-----END CERTIFICATE-----\n";
+
+    private X509Certificate[] untrustedChain;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        CertificateFactory certFactory = CertificateFactory.getInstance("X509");
+        ByteArrayInputStream bais = new ByteArrayInputStream(base64certEncoding
+                .getBytes());
+        X509Certificate cert = (X509Certificate) certFactory
+                .generateCertificate(bais);
+        untrustedChain = new X509Certificate[] { cert };
+    }
+
+    public void testTrustManagerImpl_1() throws Exception {
+        KeyStore ks =  KeyStore.getInstance("BKS");
+        ks.load(null, null);
+
+        TrustManagerImpl tm = new TrustManagerImpl(ks);
+        assertEquals(tm.getAcceptedIssuers().length, 0);
+        checkTrustManager(tm);
+    }
+
+    public void testTrustManagerImpl_2() throws Exception {
+        KeyStore ks = JSSETestData.getKeyStore();
+
+        TrustManagerImpl tm = new TrustManagerImpl(ks);
+        assertEquals(tm.getAcceptedIssuers().length, 1);
+        checkTrustManager(tm);
+    }
+
+    private void checkTrustManager(TrustManagerImpl tm) throws Exception {
+        try {
+            tm.checkClientTrusted(null, "RSA");
+            fail("No expected IllegalArgumentException ");
+        } catch (IllegalArgumentException e) {
+        }
+
+        try {
+            tm.checkClientTrusted(new X509Certificate[0], "RSA");
+            fail("No expected IllegalArgumentException ");
+        } catch (IllegalArgumentException e) {
+        }
+
+        try {
+            tm.checkClientTrusted(untrustedChain, "RSA");
+            fail("No expected CertificateException ");
+        } catch (CertificateException e) {
+        }
+
+        try {
+            tm.checkServerTrusted(null, "RSA");
+            fail("No expected IllegalArgumentException ");
+        } catch (IllegalArgumentException e) {
+        }
+
+        try {
+            tm.checkServerTrusted(new X509Certificate[0], "RSA");
+            fail("No expected IllegalArgumentException ");
+        } catch (IllegalArgumentException e) {
+        }
+
+        try {
+            tm.checkServerTrusted(untrustedChain, "RSA");
+            fail("No expected CertificateException ");
+        } catch (CertificateException e) {
+        }
+    }
+}
\ No newline at end of file

Propchange: harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/TrustManagerImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java/org/apache/harmony/xnet/tests/provider/jsse/KeyManagerFactoryImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java/org/apache/harmony/xnet/tests/provider/jsse/KeyManagerFactoryImplTest.java?view=auto&rev=503371
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java/org/apache/harmony/xnet/tests/provider/jsse/KeyManagerFactoryImplTest.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java/org/apache/harmony/xnet/tests/provider/jsse/KeyManagerFactoryImplTest.java
Sun Feb  4 00:10:09 2007
@@ -0,0 +1,92 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.xnet.tests.provider.jsse;
+
+import java.security.InvalidAlgorithmParameterException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+
+import javax.net.ssl.KeyManager;
+
+import org.apache.harmony.xnet.provider.jsse.KeyManagerFactoryImpl;
+import org.apache.harmony.xnet.provider.jsse.KeyManagerImpl;
+import org.apache.harmony.xnet.provider.jsse.TrustManagerImpl;
+import junit.framework.TestCase;
+
+/**
+ * Tests for <code>KeyManagerFactoryImpl</code> constructor and methods
+ *  
+ */
+public class KeyManagerFactoryImplTest extends TestCase {
+
+    /*
+     * Class under test for void engineInit(KeyStore, char[])
+     */
+    public void testEngineInitKeyStorecharArray() throws Exception {
+        KeyManagerFactoryImpl kmf = new KeyManagerFactoryImpl();
+        kmf.engineInit(null, null);
+
+        String def_keystore = System.getProperty("javax.net.ssl.keyStore");
+        try {
+            System.setProperty("javax.net.ssl.keyStore", "abc");
+            kmf.engineInit(null, null);
+            fail("No expected KeyStoreException");
+        } catch (KeyStoreException e) {
+        } finally {
+            if (def_keystore == null) {
+                 System.clearProperty("javax.net.ssl.keyStore");
+            } else {
+                System.setProperty("javax.net.ssl.keyStore", def_keystore);
+            }
+        }
+      
+    }
+
+    /*
+     * Class under test for void engineInit(ManagerFactoryParameters)
+     */
+    public void testEngineInitManagerFactoryParameters() {
+        KeyManagerFactoryImpl kmf = new KeyManagerFactoryImpl();
+        try {
+            kmf.engineInit(null);
+            fail("No expected InvalidAlgorithmParameterException");
+        } catch (InvalidAlgorithmParameterException e) {
+            // expected
+        }
+    }
+
+    public void testEngineGetKeyManagers() throws Exception {
+        KeyManagerFactoryImpl kmf = new KeyManagerFactoryImpl();
+        try {
+            kmf.engineGetKeyManagers();
+            fail("No expected IllegalStateException");
+        } catch (IllegalStateException e) {
+            // expected
+        }
+        KeyStore ks;
+        ks = KeyStore.getInstance("BKS");
+        ks.load(null, null);
+        kmf.engineInit(ks, null);
+
+        KeyManager[] kma = kmf.engineGetKeyManagers();
+        assertTrue("Incorrect array length", kma.length == 1);
+        assertTrue("Incorrect KeyManager type",
+                kma[0] instanceof KeyManagerImpl);
+    }
+
+}
\ No newline at end of file

Propchange: harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java/org/apache/harmony/xnet/tests/provider/jsse/KeyManagerFactoryImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java/org/apache/harmony/xnet/tests/provider/jsse/ProtocolVersionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java/org/apache/harmony/xnet/tests/provider/jsse/ProtocolVersionTest.java?view=auto&rev=503371
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java/org/apache/harmony/xnet/tests/provider/jsse/ProtocolVersionTest.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java/org/apache/harmony/xnet/tests/provider/jsse/ProtocolVersionTest.java
Sun Feb  4 00:10:09 2007
@@ -0,0 +1,85 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.xnet.tests.provider.jsse;
+
+import org.apache.harmony.xnet.provider.jsse.ProtocolVersion;
+import junit.framework.TestCase;
+
+/**
+ * Tests for <code>ProtocolVersion</code> constructor and methods
+ *  
+ */
+public class ProtocolVersionTest extends TestCase {
+
+    public void testEquals() {
+        assertEquals(ProtocolVersion.getByVersion(new byte[] { 3, 0 }),
+                ProtocolVersion.getByName("SSLv3"));
+        assertEquals(ProtocolVersion.getByVersion(new byte[] { 3, 1 }),
+                ProtocolVersion.getByName("TLSv1"));
+        assertFalse(ProtocolVersion.getByVersion(new byte[] { 3, 0 }).equals(
+                ProtocolVersion.getByName("TLSv1")));
+
+    }
+
+    /*
+     * Class under test for boolean isSupported(byte[])
+     */
+    public void testIsSupportedbyteArray() {
+        assertTrue(ProtocolVersion.isSupported(new byte[] { 3, 0 }));
+        assertTrue(ProtocolVersion.isSupported(new byte[] { 3, 1 }));
+        assertFalse(ProtocolVersion.isSupported(new byte[] { 3, 2 }));
+    }
+
+    public void testGetByVersion() {
+        assertEquals(ProtocolVersion.getByVersion(new byte[] { 2, 1 }), null);
+        assertEquals(ProtocolVersion.getByVersion(new byte[] { 3, 0 }).name,
+                "SSLv3");
+        assertEquals(ProtocolVersion.getByVersion(new byte[] { 3, 1 }).name,
+                "TLSv1");
+    }
+
+    /*
+     * Class under test for boolean isSupported(String)
+     */
+    public void testIsSupportedString() {
+        assertTrue(ProtocolVersion.isSupported("SSLv3"));
+        assertTrue(ProtocolVersion.isSupported("SSL"));
+        assertTrue(ProtocolVersion.isSupported("TLSv1"));
+        assertTrue(ProtocolVersion.isSupported("TLS"));
+        assertFalse(ProtocolVersion.isSupported("SSLv4"));
+    }
+
+    public void testGetByName() {
+        assertEquals(ProtocolVersion.getByName("SSLv2"), null);
+        assertEquals(ProtocolVersion.getByName("SSLv3").name, "SSLv3");
+        assertEquals(ProtocolVersion.getByName("TLSv1").name, "TLSv1");
+    }
+
+    public void testGetLatestVersion() {
+        ProtocolVersion ver = ProtocolVersion.getLatestVersion(new String[] {
+                "SSLv2", "TLSv1", "SSLv3" });
+        assertTrue("Incorrect protocol version " + ver.name, ver.name
+                .equals("TLSv1"));
+
+        ver = ProtocolVersion.getLatestVersion(new String[] {"SSLv3",
+                "unknown", "SSLv2" });
+        assertEquals("Incorrect protocol version " + ver.name, ver.name,
+                "SSLv3");
+    }
+
+}
\ No newline at end of file

Propchange: harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java/org/apache/harmony/xnet/tests/provider/jsse/ProtocolVersionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java/org/apache/harmony/xnet/tests/provider/jsse/TrustManagerFactoryImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java/org/apache/harmony/xnet/tests/provider/jsse/TrustManagerFactoryImplTest.java?view=auto&rev=503371
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java/org/apache/harmony/xnet/tests/provider/jsse/TrustManagerFactoryImplTest.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java/org/apache/harmony/xnet/tests/provider/jsse/TrustManagerFactoryImplTest.java
Sun Feb  4 00:10:09 2007
@@ -0,0 +1,94 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.xnet.tests.provider.jsse;
+
+import java.security.InvalidAlgorithmParameterException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+
+import javax.net.ssl.ManagerFactoryParameters;
+import javax.net.ssl.TrustManager;
+
+import org.apache.harmony.xnet.provider.jsse.TrustManagerFactoryImpl;
+import org.apache.harmony.xnet.provider.jsse.TrustManagerImpl;
+import junit.framework.TestCase;
+
+/**
+ * Tests for <code>TrustManagerFactoryImpl</code> constructor and methods
+ *  
+ */
+public class TrustManagerFactoryImplTest extends TestCase {
+
+    /*
+     * Class under test for void engineInit(KeyStore)
+     */
+    public void testEngineInitKeyStore() throws Exception {
+        TrustManagerFactoryImpl tmf = new TrustManagerFactoryImpl();
+        tmf.engineInit((KeyStore) null);
+
+        String def_keystore = System.getProperty("javax.net.ssl.trustStore");
+        System.setProperty("javax.net.ssl.trustStore", "abc");
+        try {
+            tmf.engineInit((KeyStore) null);
+            fail("No expected KeyStoreException");
+        } catch (KeyStoreException e) {
+        } finally {
+            if (def_keystore == null) {
+                System.clearProperty("javax.net.ssl.trustStore");
+            } else {
+                System.setProperty("javax.net.ssl.trustStore", def_keystore);
+            }
+        }
+    }
+
+    /*
+     * Class under test for void engineInit(ManagerFactoryParameters)
+     */
+    public void testEngineInitManagerFactoryParameters() {
+        TrustManagerFactoryImpl tmf = new TrustManagerFactoryImpl();
+
+        try {
+            tmf.engineInit((ManagerFactoryParameters) null);
+            fail("No expected InvalidAlgorithmParameterException");
+        } catch (InvalidAlgorithmParameterException e) {
+        }
+    }
+
+    public void testEngineGetTrustManagers() {
+        TrustManagerFactoryImpl tmf = new TrustManagerFactoryImpl();
+        try {
+            tmf.engineGetTrustManagers();
+            fail("No expected IllegalStateException");
+        } catch (IllegalStateException e) {
+            // expected
+        }
+        KeyStore ks;
+        try {
+            ks = KeyStore.getInstance("BKS");
+            ks.load(null, null);
+            tmf.engineInit(ks);
+        } catch (Exception e) {
+            fail(e.toString());
+        }
+        TrustManager[] tma = tmf.engineGetTrustManagers();
+        assertTrue("Incorrect array length", tma.length == 1);
+        assertTrue("Incorrect KeyManager type",
+                tma[0] instanceof TrustManagerImpl);
+    }
+
+}
\ No newline at end of file

Propchange: harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java/org/apache/harmony/xnet/tests/provider/jsse/TrustManagerFactoryImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/x-net/src/test/resources/key_store.bks
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/x-net/src/test/resources/key_store.bks?view=auto&rev=503371
==============================================================================
Binary file - no diff available.

Propchange: harmony/enhanced/classlib/trunk/modules/x-net/src/test/resources/key_store.bks
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: harmony/enhanced/classlib/trunk/modules/x-net/src/test/support/common/java/org/apache/harmony/xnet/provider/jsse/JSSETestData.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/x-net/src/test/support/common/java/org/apache/harmony/xnet/provider/jsse/JSSETestData.java?view=auto&rev=503371
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/x-net/src/test/support/common/java/org/apache/harmony/xnet/provider/jsse/JSSETestData.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/x-net/src/test/support/common/java/org/apache/harmony/xnet/provider/jsse/JSSETestData.java
Sun Feb  4 00:10:09 2007
@@ -0,0 +1,92 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.xnet.provider.jsse;
+
+import java.io.InputStream;
+import java.security.KeyStore;
+import java.security.SecureRandom;
+
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManagerFactory;
+
+import tests.support.resource.Support_Resources;
+
+/**
+ * JSSETestData
+ */
+public class JSSETestData {
+
+    private static Exception initException;
+
+    // the password to the store
+    public static final char[] KS_PASSWORD = "password".toCharArray();
+
+    private static SSLContext context;
+    private static KeyStore keyStore;
+    private static SSLParameters sslParameters;
+
+    static {
+        try {
+            String ksDefaultType = KeyStore.getDefaultType();
+            InputStream is = Support_Resources.getResourceStream(
+                    "key_store." + ksDefaultType.toLowerCase());
+
+            keyStore = KeyStore.getInstance(ksDefaultType);
+            keyStore.load(is, KS_PASSWORD);
+
+            KeyManagerFactory kmf = KeyManagerFactory.getInstance("X509");
+            kmf.init(keyStore, KS_PASSWORD);
+
+            TrustManagerFactory tmf = TrustManagerFactory.getInstance("X509");
+            tmf.init(keyStore);
+
+            sslParameters = new SSLParameters(kmf.getKeyManagers(), tmf
+                    .getTrustManagers(), new SecureRandom(),
+                    new SSLSessionContextImpl(), new SSLSessionContextImpl());
+
+            context = SSLContext.getInstance("TLSv1");
+            context.init(kmf.getKeyManagers(),
+                    tmf.getTrustManagers(), new SecureRandom());
+        } catch (Exception e) {
+            e.printStackTrace();
+            initException = e;
+        }
+    }
+
+    public static SSLContext getContext() throws Exception {
+        if (initException != null) {
+            throw initException;
+        }
+        return context;
+    }
+
+    public static SSLParameters getSSLParameters() throws Exception {
+        if (initException != null) {
+            throw initException;
+        }
+        return sslParameters;
+    }
+
+    public static KeyStore getKeyStore() throws Exception {
+        if (initException != null) {
+            throw initException;
+        }
+        return keyStore;
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/x-net/src/test/support/common/java/org/apache/harmony/xnet/provider/jsse/JSSETestData.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/x-net/src/test/support/common/java/org/apache/harmony/xnet/tests/support/MyKeyManagerFactorySpi.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/x-net/src/test/support/common/java/org/apache/harmony/xnet/tests/support/MyKeyManagerFactorySpi.java?view=auto&rev=503371
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/x-net/src/test/support/common/java/org/apache/harmony/xnet/tests/support/MyKeyManagerFactorySpi.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/x-net/src/test/support/common/java/org/apache/harmony/xnet/tests/support/MyKeyManagerFactorySpi.java
Sun Feb  4 00:10:09 2007
@@ -0,0 +1,82 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.xnet.tests.support;
+
+import java.security.InvalidAlgorithmParameterException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.UnrecoverableKeyException;
+
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.KeyManagerFactorySpi;
+import javax.net.ssl.ManagerFactoryParameters;
+
+/**
+ * Class for verification KeyManagerFactorySpi and KeyManagerFactory
+ * functionality
+ * 
+ */
+
+public class MyKeyManagerFactorySpi extends KeyManagerFactorySpi {
+    
+    protected void engineInit(KeyStore ks, char[] password)
+            throws KeyStoreException, NoSuchAlgorithmException,
+            UnrecoverableKeyException {
+        if (password == null) {
+            throw new KeyStoreException("Incorrect password");            
+        }
+        if (ks == null) {
+            throw new UnrecoverableKeyException("Incorrect keystore");
+        }
+    }
+
+    protected void engineInit(ManagerFactoryParameters spec)
+            throws InvalidAlgorithmParameterException {
+        if (spec == null) {
+            throw new InvalidAlgorithmParameterException("Incorrect parameter");
+        }
+        if (spec instanceof Parameters) {
+            try {
+                engineInit(((Parameters)spec).getKeyStore(),
+                        ((Parameters)spec).getPassword());
+            } catch (Exception e) {
+                throw new InvalidAlgorithmParameterException(e.toString()); 
+            }
+        } else {
+            throw new InvalidAlgorithmParameterException("Invalid parameter");
+        }
+    }
+
+    protected KeyManager[] engineGetKeyManagers() {
+        return null;
+    }
+    public static class Parameters implements ManagerFactoryParameters {
+        private KeyStore keyStore;
+        private char[] passWD;
+        public Parameters (KeyStore ks, char[] pass) {
+            this.keyStore = ks;
+            this.passWD = pass; 
+        }
+        public KeyStore getKeyStore() {
+            return keyStore;
+        }
+        public char[] getPassword() {
+            return passWD;
+        }
+    }}

Propchange: harmony/enhanced/classlib/trunk/modules/x-net/src/test/support/common/java/org/apache/harmony/xnet/tests/support/MyKeyManagerFactorySpi.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/x-net/src/test/support/common/java/org/apache/harmony/xnet/tests/support/MySSLContextSpi.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/x-net/src/test/support/common/java/org/apache/harmony/xnet/tests/support/MySSLContextSpi.java?view=auto&rev=503371
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/x-net/src/test/support/common/java/org/apache/harmony/xnet/tests/support/MySSLContextSpi.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/x-net/src/test/support/common/java/org/apache/harmony/xnet/tests/support/MySSLContextSpi.java
Sun Feb  4 00:10:09 2007
@@ -0,0 +1,145 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.xnet.tests.support;
+
+import java.nio.ByteBuffer;
+import java.security.KeyManagementException;
+import java.security.SecureRandom;
+
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.SSLContextSpi;
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.SSLEngineResult;
+import javax.net.ssl.SSLException;
+import javax.net.ssl.SSLSession;
+import javax.net.ssl.SSLSessionContext;
+import javax.net.ssl.SSLServerSocketFactory;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManager;
+
+/**
+ * Additional class for verification of SSLContextSpi and SSLContext
+ * functionality
+ * 
+ */
+
+public class MySSLContextSpi extends SSLContextSpi {
+    private boolean init = false;
+    protected void engineInit(KeyManager[] km, TrustManager[] tm,
+            SecureRandom sr) throws KeyManagementException {
+        if (sr == null) {
+            throw new KeyManagementException(
+                    "secureRandom is null");
+        }
+        init = true;
+    }
+
+    protected SSLSocketFactory engineGetSocketFactory() {
+        if (!init) {
+            throw new RuntimeException("Not initialiazed");
+        };   
+        return null;
+    }
+
+    protected SSLServerSocketFactory engineGetServerSocketFactory() {
+        if (!init) {
+            throw new RuntimeException("Not initialiazed");
+        }
+        return null;
+    }
+
+    protected SSLSessionContext engineGetServerSessionContext() {
+        if (!init) {
+            throw new RuntimeException("Not initialiazed");
+        }
+        return null;
+    }
+
+    protected SSLSessionContext engineGetClientSessionContext() {
+        if (!init) {
+            throw new RuntimeException("Not initialiazed");
+        }
+        return null;
+    }
+
+    /*
+     * FIXME: add these methods
+     */   
+    protected SSLEngine engineCreateSSLEngine(String host, int port) {
+        if (!init) {
+            throw new RuntimeException("Not initialiazed");
+        }
+        return new tmpSSLEngine(host, port);
+    }
+
+    protected SSLEngine engineCreateSSLEngine() {
+        if (!init) {
+            throw new RuntimeException("Not initialiazed");
+        }
+        return new tmpSSLEngine();
+    }
+    
+    public class tmpSSLEngine extends SSLEngine {
+        String tmpHost;
+        int tmpPort;
+        public tmpSSLEngine() {
+            tmpHost = null;
+            tmpPort = 0;        
+        }
+        public tmpSSLEngine(String host, int port) {
+            tmpHost = host;
+            tmpPort = port;        
+        }
+        public String getPeerHost() {
+            return tmpHost;        
+        }
+        public int getPeerPort() {
+            return tmpPort;
+        }
+        public void beginHandshake() throws SSLException { }
+        public void closeInbound() throws SSLException { }
+        public void closeOutbound() {}
+        public Runnable getDelegatedTask() { return null; }
+        public String[] getEnabledCipherSuites() { return null; }
+        public String[] getEnabledProtocols() {return null; }
+        public boolean getEnableSessionCreation() { return true; }
+        public SSLEngineResult.HandshakeStatus getHandshakeStatus() { return null; };
+        public boolean getNeedClientAuth() { return true; }
+        public SSLSession getSession() { return null; }
+        public String[] getSupportedCipherSuites()  { return null; }
+        public String[] getSupportedProtocols()  { return null; }
+        public boolean getUseClientMode()  { return true; }
+        public boolean getWantClientAuth()  { return true; }
+        public boolean isInboundDone()  { return true; }
+        public boolean isOutboundDone()  { return true; }
+        public void setEnabledCipherSuites(String[] suites) { }
+        public void setEnabledProtocols(String[] protocols) { }
+        public void setEnableSessionCreation(boolean flag) { }
+        public void setNeedClientAuth(boolean need) { }
+        public void setUseClientMode(boolean mode) { }
+        public void setWantClientAuth(boolean want) { }        
+        public SSLEngineResult unwrap(ByteBuffer src, ByteBuffer[] dsts,
+                int offset, int length) throws SSLException {
+            return null;
+        }        
+        public SSLEngineResult wrap(ByteBuffer[] srcs, int offset,
+                int length, ByteBuffer dst) throws SSLException { 
+            return null;
+        }
+    }
+}
\ No newline at end of file

Propchange: harmony/enhanced/classlib/trunk/modules/x-net/src/test/support/common/java/org/apache/harmony/xnet/tests/support/MySSLContextSpi.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/x-net/src/test/support/common/java/org/apache/harmony/xnet/tests/support/MyTrustManagerFactorySpi.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/x-net/src/test/support/common/java/org/apache/harmony/xnet/tests/support/MyTrustManagerFactorySpi.java?view=auto&rev=503371
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/x-net/src/test/support/common/java/org/apache/harmony/xnet/tests/support/MyTrustManagerFactorySpi.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/x-net/src/test/support/common/java/org/apache/harmony/xnet/tests/support/MyTrustManagerFactorySpi.java
Sun Feb  4 00:10:09 2007
@@ -0,0 +1,71 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.xnet.tests.support;
+
+import java.security.InvalidAlgorithmParameterException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+
+import javax.net.ssl.ManagerFactoryParameters;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactorySpi;
+
+/**
+ * Class for vertifying TrustManagerFactorySpi and TrustManagerFactory 
+ * functionality
+ * 
+ */
+
+public class MyTrustManagerFactorySpi extends TrustManagerFactorySpi {
+    protected void engineInit(KeyStore ks) throws KeyStoreException {
+        if (ks == null) {
+            throw new KeyStoreException("Not supported operation for null KeyStore");
+        }
+    }
+
+    protected void engineInit(ManagerFactoryParameters spec)
+            throws InvalidAlgorithmParameterException {
+        if (spec == null) {
+            throw new InvalidAlgorithmParameterException("Null parameter");
+        }
+        if (spec instanceof Parameters) {
+            try {
+                engineInit(((Parameters)spec).getKeyStore());
+            } catch (KeyStoreException e) {
+                throw new RuntimeException(e);
+            }
+        } else {
+            throw new InvalidAlgorithmParameterException("Invalid parameter");
+        }
+    }
+
+    protected TrustManager[] engineGetTrustManagers() {
+        return null;
+    }
+    
+    
+    public static class Parameters implements ManagerFactoryParameters {
+        private KeyStore keyStore;
+        public Parameters (KeyStore ks) {
+            this.keyStore = ks;
+        }
+        public KeyStore getKeyStore() {
+            return keyStore;
+        }
+    }
+}
\ No newline at end of file

Propchange: harmony/enhanced/classlib/trunk/modules/x-net/src/test/support/common/java/org/apache/harmony/xnet/tests/support/MyTrustManagerFactorySpi.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message