summaryrefslogtreecommitdiffstats
path: root/x-net
diff options
context:
space:
mode:
authorUrs Grob <>2009-03-24 20:46:32 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-24 20:46:32 -0700
commiteff7bc0401e656948b0f491d88fe134843ef1573 (patch)
tree27b3d0840a99683a1034fda9ca460b00a3a519b6 /x-net
parentc3fbcf0d4fa86174f3f7fbf93f4a75d360fa7ca6 (diff)
downloadlibcore-eff7bc0401e656948b0f491d88fe134843ef1573.zip
libcore-eff7bc0401e656948b0f491d88fe134843ef1573.tar.gz
libcore-eff7bc0401e656948b0f491d88fe134843ef1573.tar.bz2
Automated import from //branches/donutburger/...@141709,141709
Diffstat (limited to 'x-net')
-rw-r--r--x-net/src/test/java/tests/api/javax/net/ServerSocketFactoryTest.java90
-rw-r--r--x-net/src/test/java/tests/api/javax/net/SocketFactoryTest.java46
-rw-r--r--x-net/src/test/java/tests/api/javax/net/ssl/AllTests.java1
-rw-r--r--x-net/src/test/java/tests/api/javax/net/ssl/CertificatesToPlayWith.java478
-rw-r--r--x-net/src/test/java/tests/api/javax/net/ssl/HandshakeCompletedEventTest.java105
-rw-r--r--x-net/src/test/java/tests/api/javax/net/ssl/HandshakeCompletedListenerTest.java74
-rw-r--r--x-net/src/test/java/tests/api/javax/net/ssl/HostnameVerifierTest.java217
-rw-r--r--x-net/src/test/java/tests/api/javax/net/ssl/HttpsURLConnectionTest.java10
-rw-r--r--x-net/src/test/java/tests/api/javax/net/ssl/KeyManagerFactory1Test.java16
-rw-r--r--x-net/src/test/java/tests/api/javax/net/ssl/KeyManagerFactory2Test.java10
-rw-r--r--x-net/src/test/java/tests/api/javax/net/ssl/KeyStoreBuilderParametersTest.java15
-rw-r--r--x-net/src/test/java/tests/api/javax/net/ssl/SSLContext1Test.java42
-rw-r--r--x-net/src/test/java/tests/api/javax/net/ssl/SSLEngineTest.java548
-rw-r--r--x-net/src/test/java/tests/api/javax/net/ssl/SSLServerSocketFactoryTest.java49
-rw-r--r--x-net/src/test/java/tests/api/javax/net/ssl/SSLServerSocketTest.java424
-rw-r--r--x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionBindingListenerTest.java50
-rw-r--r--x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionContextTest.java73
-rw-r--r--x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionTest.java569
-rw-r--r--x-net/src/test/java/tests/api/javax/net/ssl/SSLSocketFactoryTest.java19
-rw-r--r--x-net/src/test/java/tests/api/javax/net/ssl/SSLSocketTest.java731
-rw-r--r--x-net/src/test/java/tests/api/javax/net/ssl/TrustManagerFactory1Test.java1
-rw-r--r--x-net/src/test/java/tests/api/javax/net/ssl/TrustManagerFactorySpiTest.java102
-rw-r--r--x-net/src/test/java/tests/api/javax/net/ssl/X509KeyManagerTest.java444
23 files changed, 2690 insertions, 1424 deletions
diff --git a/x-net/src/test/java/tests/api/javax/net/ServerSocketFactoryTest.java b/x-net/src/test/java/tests/api/javax/net/ServerSocketFactoryTest.java
index 6044e2d..1876f22 100644
--- a/x-net/src/test/java/tests/api/javax/net/ServerSocketFactoryTest.java
+++ b/x-net/src/test/java/tests/api/javax/net/ServerSocketFactoryTest.java
@@ -54,9 +54,7 @@ public class ServerSocketFactoryTest extends TestCase {
)
public void test_Constructor() {
try {
- MyServerSocketFactory mssf = new MyServerSocketFactory();
- assertNotNull(mssf);
- assertTrue(mssf instanceof ServerSocketFactory);
+ ServerSocketFactory sf = new MyServerSocketFactory();
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
}
@@ -72,11 +70,10 @@ public class ServerSocketFactoryTest extends TestCase {
args = {}
)
public final void test_createServerSocket_01() {
- ServerSocketFactory sf = new MyServerSocketFactory();
+ ServerSocketFactory sf = ServerSocketFactory.getDefault();
try {
ServerSocket ss = sf.createServerSocket();
assertNotNull(ss);
- fail("No expected SocketException");
} catch (SocketException e) {
} catch (Exception e) {
fail(e.toString());
@@ -93,7 +90,7 @@ public class ServerSocketFactoryTest extends TestCase {
args = {int.class}
)
public final void test_createServerSocket_02() {
- MyServerSocketFactory sf = new MyServerSocketFactory();
+ ServerSocketFactory sf = ServerSocketFactory.getDefault();
int portNumber = Support_PortManager.getNextPort();
try {
@@ -132,7 +129,7 @@ public class ServerSocketFactoryTest extends TestCase {
args = {int.class, int.class}
)
public final void test_createServerSocket_03() {
- MyServerSocketFactory sf = new MyServerSocketFactory();
+ ServerSocketFactory sf = ServerSocketFactory.getDefault();
int portNumber = Support_PortManager.getNextPort();
try {
@@ -151,16 +148,6 @@ public class ServerSocketFactoryTest extends TestCase {
fail(ex + " was thrown instead of IOException");
}
- portNumber = Support_PortManager.getNextPort();
- try {
- sf.createServerSocket(portNumber, -1);
- fail("IOException wasn't thrown");
- } catch (IOException ioe) {
- //expected
- } catch (Exception ex) {
- fail(ex + " was thrown instead of IOException");
- }
-
try {
sf.createServerSocket(65536, 0);
fail("IllegalArgumentException wasn't thrown");
@@ -181,7 +168,7 @@ public class ServerSocketFactoryTest extends TestCase {
args = {int.class, int.class, InetAddress.class}
)
public final void test_createServerSocket_04() {
- MyServerSocketFactory sf = new MyServerSocketFactory();
+ ServerSocketFactory sf = ServerSocketFactory.getDefault();
int portNumber = Support_PortManager.getNextPort();
try {
@@ -200,16 +187,6 @@ public class ServerSocketFactoryTest extends TestCase {
fail(ex + " was thrown instead of IOException");
}
- portNumber = Support_PortManager.getNextPort();
- try {
- sf.createServerSocket(portNumber, -1, InetAddress.getLocalHost());
- fail("IOException wasn't thrown");
- } catch (IOException ioe) {
- //expected
- } catch (Exception ex) {
- fail(ex + " was thrown instead of IOException");
- }
-
try {
sf.createServerSocket(Integer.MAX_VALUE, 0, InetAddress.getLocalHost());
fail("IllegalArgumentException wasn't thrown");
@@ -249,53 +226,26 @@ public class ServerSocketFactoryTest extends TestCase {
}
}
}
-
class MyServerSocketFactory extends ServerSocketFactory {
public MyServerSocketFactory() {
super();
}
-
+
+ @Override
public ServerSocket createServerSocket(int port) throws IOException {
- ServerSocket ss = null;
- try {
- ss = new ServerSocket(port);
- } catch (java.net.BindException be) {
- throw new IOException("error occurs");
- } catch (IllegalArgumentException iae) {
- throw iae;
- }
- return ss;
+ return null;
}
-
- public ServerSocket createServerSocket(int port, int backlog) throws IOException {
- ServerSocket ss = null;
- if (backlog < 0) {
- throw new IOException("negative backlog parameter");
- }
- try {
- ss = new ServerSocket(port, backlog);
- } catch (java.net.BindException be) {
- throw new IOException("error occurs");
- } catch (IllegalArgumentException iae) {
- throw iae;
- }
- return ss;
+
+ @Override
+ public ServerSocket createServerSocket(int port, int backlog)
+ throws IOException {
+ return null;
}
-
- public ServerSocket createServerSocket(int port, int backlog, InetAddress ifAddress)
- throws IOException {
- ServerSocket ss = null;
- if (backlog < 0) {
- throw new IOException("negative backlog parameter");
- }
- try {
- ss = new ServerSocket(port, backlog, ifAddress);
- } catch (java.net.BindException be) {
- throw new IOException("error occurs");
- } catch (IllegalArgumentException iae) {
- throw iae;
- }
- return ss;
- }
-}
+
+ @Override
+ public ServerSocket createServerSocket(int port, int backlog,
+ InetAddress address) throws IOException {
+ return null;
+ }
+} \ No newline at end of file
diff --git a/x-net/src/test/java/tests/api/javax/net/SocketFactoryTest.java b/x-net/src/test/java/tests/api/javax/net/SocketFactoryTest.java
index 1d39a0c..05fee79 100644
--- a/x-net/src/test/java/tests/api/javax/net/SocketFactoryTest.java
+++ b/x-net/src/test/java/tests/api/javax/net/SocketFactoryTest.java
@@ -58,8 +58,6 @@ public class SocketFactoryTest extends TestCase {
public void test_Constructor() {
try {
MySocketFactory sf = new MySocketFactory();
- assertNotNull(sf);
- assertTrue(sf instanceof SocketFactory);
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
}
@@ -106,7 +104,7 @@ public class SocketFactoryTest extends TestCase {
args = {String.class, int.class}
)
public final void test_createSocket_02() {
- MySocketFactory sf = new MySocketFactory();
+ SocketFactory sf = SocketFactory.getDefault();
int portNumber = Support_PortManager.getNextPort();
int sport = startServer("Cons String,I");
int[] invalidPorts = {Integer.MIN_VALUE, -1, 65536, Integer.MAX_VALUE};
@@ -164,7 +162,7 @@ public class SocketFactoryTest extends TestCase {
args = {InetAddress.class, int.class}
)
public final void test_createSocket_03() {
- MySocketFactory sf = new MySocketFactory();
+ SocketFactory sf = SocketFactory.getDefault();
int portNumber = Support_PortManager.getNextPort();
int sport = startServer("Cons InetAddress,I");
int[] invalidPorts = {Integer.MIN_VALUE, -1, 65536, Integer.MAX_VALUE};
@@ -214,7 +212,7 @@ public class SocketFactoryTest extends TestCase {
args = {InetAddress.class, int.class, InetAddress.class, int.class}
)
public final void test_createSocket_04() {
- MySocketFactory sf = new MySocketFactory();
+ SocketFactory sf = SocketFactory.getDefault();
int portNumber = Support_PortManager.getNextPort();
int sport = startServer("Cons InetAddress,I,InetAddress,I");
int[] invalidPorts = {Integer.MIN_VALUE, -1, 65536, Integer.MAX_VALUE};
@@ -278,7 +276,7 @@ public class SocketFactoryTest extends TestCase {
args = {String.class, int.class, InetAddress.class, int.class}
)
public final void test_createSocket_05() {
- MySocketFactory sf = new MySocketFactory();
+ SocketFactory sf = SocketFactory.getDefault();
int portNumber = Support_PortManager.getNextPort();
int sport = startServer("Cons String,I,InetAddress,I");
int[] invalidPorts = {Integer.MIN_VALUE, -1, 65536, Integer.MAX_VALUE};
@@ -385,46 +383,26 @@ class MySocketFactory extends SocketFactory {
super();
}
+ @Override
public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
- Socket s = null;
- try {
- s = new Socket(host, port);
- } catch (java.net.ConnectException ce) {
- throw new IOException("error occurs");
- }
- return s;
+ return null;
}
+ @Override
public Socket createSocket(String host, int port, InetAddress localHost, int localPort)
throws IOException, UnknownHostException {
- Socket s = null;
- try {
- s = new Socket(host, port, localHost, localPort);
- } catch (java.net.ConnectException ce) {
- throw new IOException("error occurs");
- }
- return s;
+ return null;
}
+ @Override
public Socket createSocket(InetAddress host, int port) throws IOException {
- Socket s = null;
- try {
- s = new Socket(host, port);
- } catch (java.net.ConnectException ce) {
- throw new IOException("error occurs");
- }
- return s;
+ return null;
}
+ @Override
public Socket createSocket(InetAddress address, int port,
InetAddress localAddress, int localPort) throws IOException {
- Socket s = null;
- try {
- s = new Socket(address, port, localAddress, localPort);
- } catch (java.net.ConnectException ce) {
- throw new IOException("error occurs");
- }
- return s;
+ return null;
}
}
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/AllTests.java b/x-net/src/test/java/tests/api/javax/net/ssl/AllTests.java
index 69e75c6..ecfe83f 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/AllTests.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/AllTests.java
@@ -68,7 +68,6 @@ public class AllTests {
suite.addTestSuite(X509KeyManagerTest.class);
suite.addTestSuite(SSLSessionTest.class);
suite.addTestSuite(SSLSessionBindingListenerTest.class);
- suite.addTestSuite(HandshakeCompletedListenerTest.class);
suite.addTestSuite(HostnameVerifierTest.class);
// $JUnit-END$
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/CertificatesToPlayWith.java b/x-net/src/test/java/tests/api/javax/net/ssl/CertificatesToPlayWith.java
new file mode 100644
index 0000000..04a17b2
--- /dev/null
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/CertificatesToPlayWith.java
@@ -0,0 +1,478 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package tests.api.javax.net.ssl;
+
+/**
+ * Some X509 certificates to test against.
+ * <p/>
+ * Note: some of these certificates have Japanese Kanji in the "subjectAlt"
+ * field (UTF8). Not sure how realistic that is since international characters
+ * in DNS names usually get translated into ASCII using "xn--" style DNS
+ * entries. "xn--i8s592g.co.jp" is what FireFox actually uses when trying to
+ * find &#x82b1;&#x5b50;.co.jp. So would the CN in the certificate contain
+ * "xn--i8s592g.co.jp" in ASCII, or "&#x82b1;&#x5b50;.co.jp" in UTF8? (Both?)
+ *
+ * @since 11-Dec-2006
+ */
+public interface CertificatesToPlayWith {
+
+ /**
+ * CN=foo.com
+ */
+ public final static byte[] X509_FOO = (
+ "-----BEGIN CERTIFICATE-----\n" +
+ "MIIERjCCAy6gAwIBAgIJAIz+EYMBU6aQMA0GCSqGSIb3DQEBBQUAMIGiMQswCQYD\n" +
+ "VQQGEwJDQTELMAkGA1UECBMCQkMxEjAQBgNVBAcTCVZhbmNvdXZlcjEWMBQGA1UE\n" +
+ "ChMNd3d3LmN1Y2JjLmNvbTEUMBIGA1UECxQLY29tbW9uc19zc2wxHTAbBgNVBAMU\n" +
+ "FGRlbW9faW50ZXJtZWRpYXRlX2NhMSUwIwYJKoZIhvcNAQkBFhZqdWxpdXNkYXZp\n" +
+ "ZXNAZ21haWwuY29tMB4XDTA2MTIxMTE1MzE0MVoXDTI4MTEwNTE1MzE0MVowgaQx\n" +
+ "CzAJBgNVBAYTAlVTMREwDwYDVQQIEwhNYXJ5bGFuZDEUMBIGA1UEBxMLRm9yZXN0\n" +
+ "IEhpbGwxFzAVBgNVBAoTDmh0dHBjb21wb25lbnRzMRowGAYDVQQLExF0ZXN0IGNl\n" +
+ "cnRpZmljYXRlczEQMA4GA1UEAxMHZm9vLmNvbTElMCMGCSqGSIb3DQEJARYWanVs\n" +
+ "aXVzZGF2aWVzQGdtYWlsLmNvbTCCASIw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MP3PPxAIMkB8ONkdHTco1DmbE6BfDHArD\n" +
+ "qUYxqJUlPGlMqrKb3fCFiT3eXehwR7nlzQIDAQABo3sweTAJBgNVHRMEAjAAMCwG\n" +
+ "CWCGSAGG+EIBDQQfFh1PcGVuU1NMIEdlbmVyYXRlZCBDZXJ0aWZpY2F0ZTAdBgNV\n" +
+ "HQ4EFgQUnxR3vz86tso4gkJIFiza0Mteh9gwHwYDVR0jBBgwFoAUe5raj5CZTlLS\n" +
+ "rNuzA1LKh6YNPg0wDQYJKoZIhvcNAQEFBQADggEBALJ27i3okV/KvlDp6KMID3gd\n" +
+ "ITl68PyItzzx+SquF8gahMh016NX73z/oVZoVUNdftla8wPUB1GwIkAnGkhQ9LHK\n" +
+ "spBdbRiCj0gMmLCsX8SrjFvr7cYb2cK6J/fJe92l1tg/7Y4o7V/s4JBe/cy9U9w8\n" +
+ "a0ctuDmEBCgC784JMDtT67klRfr/2LlqWhlOEq7pUFxRLbhpquaAHSOjmIcWnVpw\n" +
+ "9BsO7qe46hidgn39hKh1WjKK2VcL/3YRsC4wUi0PBtFW6ScMCuMhgIRXSPU55Rae\n" +
+ "UIlOdPjjr1SUNWGId1rD7W16Scpwnknn310FNxFMHVI0GTGFkNdkilNCFJcIoRA=\n" +
+ "-----END CERTIFICATE-----\n").getBytes();
+
+ /**
+ * CN=foo.com, subjectAlt=bar.com
+ */
+ public final static byte[] X509_FOO_BAR = (
+ "-----BEGIN CERTIFICATE-----\n" +
+ "MIIEXDCCA0SgAwIBAgIJAIz+EYMBU6aRMA0GCSqGSIb3DQEBBQUAMIGiMQswCQYD\n" +
+ "VQQGEwJDQTELMAkGA1UECBMCQkMxEjAQBgNVBAcTCVZhbmNvdXZlcjEWMBQGA1UE\n" +
+ "ChMNd3d3LmN1Y2JjLmNvbTEUMBIGA1UECxQLY29tbW9uc19zc2wxHTAbBgNVBAMU\n" +
+ "FGRlbW9faW50ZXJtZWRpYXRlX2NhMSUwIwYJKoZIhvcNAQkBFhZqdW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/jcFZR/ypZUovpiHGDO1DgL3Y3IP\n" +
+ "zVQ26uhUsSw6G0gGRiaBDe/0LUclXZoJzXX1qpS55OadxW73brziS0sxRgGrZE/d\n" +
+ "3g5kkio6IED47OP6wYnlmZ7EKP9cqjWwlnvHnnUcZ2SscoLNYs9rN9ccp8tuq2by\n" +
+ "88OyhKwGjJfhOudqfTNZcDzRHx4Fzm7UsVaycVw4uDmhEHJrAsmMPpj/+XRK9/42\n" +
+ "2xq+8bc6HojdtbCyug/fvBZvZqQXSmU8m8IVcMmWMz0ZQO8ee3QkBHMZfCy7P/kr\n" +
+ "VbWx/uETImUu+NZg22ewEw==\n" +
+ "-----END CERTIFICATE-----\n").getBytes();
+
+ /**
+ * CN=foo.com, subjectAlt=bar.com, subjectAlt=&#x82b1;&#x5b50;.co.jp
+ * (hanako.co.jp in kanji)
+ */
+ public final static byte[] X509_FOO_BAR_HANAKO = (
+ "-----BEGIN CERTIFICATE-----\n" +
+ "MIIEajCCA1KgAwIBAgIJAIz+EYMBU6aSMA0GCSqGSIb3DQEBBQUAMIGiMQswCQYD\n" +
+ "VQQGEwJDQTELMAkGA1UECBMCQkMxEjAQBgNVBAcTCVZhbmNvdXZlcjEWMBQGA1UE\n" +
+ "ChMNd3d3LmN1Y2JjLmNvbTEUMBIGA1UECxQLY29tbW9uc19zc2wxHTAbBgNVBAMU\n" +
+ "FGRlbW9faW50ZXJtZWRpYXRlX2NhMSUwIwYJKoZIhvcNAQkBFhZqdWxpdXNkYXZp\n" +
+ "ZXNAZ21haWwuY29tMB4XDTA2MTIxMTE1MzgxM1oXDTI4MTEwNTE1MzgxM1owgaQx\n" +
+ "CzAJBgNVBAYTAlVTMREwDwYDVQQIEwhNYXJ5bGFuZDEUMBIGA1UEBxMLRm9yZXN0\n" +
+ "IEhpbGwxFzAVBgNVBAoTDmh0dHBjb21wb25lbnRzMRowGAYDVQQLExF0ZXN0IGNl\n" +
+ "cnRpZmljYXRlczEQMA4GA1UEAxMHZm9vLmNvbT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pTjHE5t7iu1\n" +
+ "JVjTuE0pcBvah2dWqDNxiIOQtXyKW8Sag1YxaunxQGqRNykSFiEJindxOSAnAxK6\n" +
+ "q/wGqcZ3zvFBTcVVkji1u2QH4rOMP3PPxAIMkB8ONkdHTco1DmbE6BfDHArDqUYx\n" +
+ "qJUlPGlMqrKb3fCFiT3eXehwR7nlzQIDAQABo3sweTAJBgNVHRMEAjAAMCwGCWCG\n" +
+ "SAGG+EIBDQQfFh1PcGVuU1NMIEdlbmVyYXRlZCBDZXJ0aWZpY2F0ZTAdBgNVHQ4E\n" +
+ "FgQUnxR3vz86tso4gkJIFiza0Mteh9gwHwYDVR0jBBgwFoAUe5raj5CZTlLSrNuz\n" +
+ "A1LKh6YNPg0wDQYJKoZIhvcNAQEFBQADggEBAH0ipG6J561UKUfgkeW7GvYwW98B\n" +
+ "N1ZooWX+JEEZK7+Pf/96d3Ij0rw9ACfN4bpfnCq0VUNZVSYB+GthQ2zYuz7tf/UY\n" +
+ "A6nxVgR/IjG69BmsBl92uFO7JTNtHztuiPqBn59pt+vNx4yPvno7zmxsfI7jv0ww\n" +
+ "yfs+0FNm7FwdsC1k47GBSOaGw38kuIVWqXSAbL4EX9GkryGGOKGNh0qvAENCdRSB\n" +
+ "G9Z6tyMbmfRY+dLSh3a9JwoEcBUso6EWYBakLbq4nG/nvYdYvG9ehrnLVwZFL82e\n" +
+ "l3Q/RK95bnA6cuRClGusLad0e6bjkBzx/VQ3VarDEpAkTLUGVAa0CLXtnyc=\n" +
+ "-----END CERTIFICATE-----\n").getBytes();
+
+ /**
+ * CN=*.co.jp
+ */
+ public final static byte[] X509_WILD_CO_JP = (
+ "-----BEGIN CERTIFICATE-----\n" +
+ "MIIERjCCAy6gAwIBAgIJAIz+EYMBU6aVMA0GCSqGSIb3DQEBBQUAMIGiMQswCQYD\n" +
+ "VQQGEwJDQTELMAkGA1UECBMCQkMxEjAQBgNVBAcTCVZhbmNvdXZlcjEWMBQGA1UE\n" +
+ "ChMNd3d3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S\n" +
+ "yoemDT4NMA0GCSqGSIb3DQEBBQUAA4IBAQA0sWglVlMx2zNGvUqFC73XtREwii53\n" +
+ "CfMM6mtf2+f3k/d8KXhLNySrg8RRlN11zgmpPaLtbdTLrmG4UdAHHYr8O4y2BBmE\n" +
+ "1cxNfGxxechgF8HX10QV4dkyzp6Z1cfwvCeMrT5G/V1pejago0ayXx+GPLbWlNeZ\n" +
+ "S+Kl0m3p+QplXujtwG5fYcIpaGpiYraBLx3Tadih39QN65CnAh/zRDhLCUzKyt9l\n" +
+ "UGPLEUDzRHMPHLnSqT1n5UU5UDRytbjJPXzF+l/+WZIsanefWLsxnkgAuZe/oMMF\n" +
+ "EJMryEzOjg4Tfuc5qM0EXoPcQ/JlheaxZ40p2IyHqbsWV4MRYuFH4bkM\n" +
+ "-----END CERTIFICATE-----\n").getBytes();
+
+ /**
+ * CN=*.foo.com, subjectAlt=*.bar.com, subjectAlt=*.&#x82b1;&#x5b50;.co.jp
+ * (*.hanako.co.jp in kanji)
+ */
+ public final static byte[] X509_WILD_FOO_BAR_HANAKO = (
+ "-----BEGIN CERTIFICATE-----\n" +
+ "MIIEcDCCA1igAwIBAgIJAIz+EYMBU6aWMA0GCSqGSIb3DQEBBQUAMIGiMQswCQYD\n" +
+ "VQQGEwJDQTELMAkGA1UECBMCQkMxEjAQBgNVBAcTCVZhbmNvdXZlcjEWMBQGA1UE\n" +
+ "ChMNd3d3LmN1Y2JjLmNvbTEUMBIGA1UECxQLY29tbW9uc19zc2wxHTAbBgNVBAMU\n" +
+ "FGRlbW9faW50ZXJtZWRpYXRlX2NhMSUwIwYJKoZIhvcNAQkBFhZqdWxpdXNkYXZp\n" +
+ "ZXNAZ21haWwuY29tMB4XDTA2MTIxMTE2MTczMVoXDTI4MTEwNTE2MTczMVowgaYx\n" +
+ "CzAJBgNVBAYTAlVTMREwDwYDVQQIEwhNYXJ5bGFuZDEUMBIGA1UEBxMLRm9yZXN0\n" +
+ "IEhpbGwxFzAVBgNVBAoTD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YNlknbUnR525ItosEVwXFBJTkZ3Yw8gg02c19yi8TAh5Li3Ad8XQmmSJMWBV4XK\n" +
+ "qFr0AIZKBlg6NZZFf/0dP9zcKhzSriW27bY0XfzA6GSiRDXrDjgXq6baRT6YwgIg\n" +
+ "pgJsDbJtZfHnV1nd3M6zOtQPm1TIQpNmMMMd/DPrGcUQerD3\n" +
+ "-----END CERTIFICATE-----\n").getBytes();
+
+ /**
+ * CN=foo.com, CN=bar.com, CN=&#x82b1;&#x5b50;.co.jp
+ */
+ public final static byte[] X509_THREE_CNS_FOO_BAR_HANAKO = (
+ "-----BEGIN CERTIFICATE-----\n" +
+ "MIIEbzCCA1egAwIBAgIJAIz+EYMBU6aXMA0GCSqGSIb3DQEBBQUAMIGiMQswCQYD\n" +
+ "VQQGEwJDQTELMAkGA1UECBMCQkMxEjAQBgNVBAcTCVZhbmNvdXZlcjEWMBQGA1UE\n" +
+ "ChMNd3d3LmN1Y2JjLmNvbTEUMBIGA1UECxQLY29tbW9uc19zc2wxHTAbBgNVBAMU\n" +
+ "FGRlbW9faW50ZXJtZWRpYXRlX2NhMSUwIwYJKoZIhvcNAQkBFhZqdWxpdXNkYXZp\n" +
+ "ZXNAZ21haWwuY29tMB4XDTA2MTIxMTE2MTk0NVoXDTI4MTEwNTE2MTk0NVowgc0x\n" +
+ "CzAJBgNVBAYTAlVTMREwDwYDVQQIDAhNYXJ5bGFuZDEUMBIGA1UEBwwLRm9yZXN0\n" +
+ "IEhpbGwxFzAVBgNVBAoMDmh0dHBjb21wb25lbnRzMRowGAYDVQQLDBF0ZXN0IGNl\n" +
+ "cnRpZmljYXRlczEQMA4GA1UEAwwHZm9vLmNvbTEQMA4GA1UEAwwHYmFyLmNvbTEV\n" +
+ "MBMGA1UEAwwM6Iqx5a2QLmNvLmpwMSUwIwYJKoZIhvcNAQkBFhZqdWxpdXNkYXZp\n" +
+ "ZXNAZ21haWwuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQ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
+ "5c0CAwEAAaOBkDCBjTAJBgNVHRMEAjAAMCwGCWCGSAGG+EIBDQQfFh1PcGVuU1NM\n" +
+ "IEdlbmVyYXRlZCBDZXJ0aWZpY2F0ZTAdBgNVHQ4EFgQUnxR3vz86tso4gkJIFiza\n" +
+ "0Mteh9gwHwYDVR0jBBgwFoAUe5raj5CZTlLSrNuzA1LKh6YNPg0wEgYDVR0RBAsw\n" +
+ "CYIHZm9vLmNvbTANBgkqhkiG9w0BAQUFAAOCAQEAjl78oMjzFdsMy6F1sGg/IkO8\n" +
+ "tF5yUgPgFYrs41yzAca7IQu6G9qtFDJz/7ehh/9HoG+oqCCIHPuIOmS7Sd0wnkyJ\n" +
+ "Y7Y04jVXIb3a6f6AgBkEFP1nOT0z6kjT7vkA5LJ2y3MiDcXuRNMSta5PYVnrX8aZ\n" +
+ "yiqVUNi40peuZ2R8mAUSBvWgD7z2qWhF8YgDb7wWaFjg53I36vWKn90ZEti3wNCw\n" +
+ "qAVqixM+J0qJmQStgAc53i2aTMvAQu3A3snvH/PHTBo+5UL72n9S1kZyNCsVf1Qo\n" +
+ "n8jKTiRriEM+fMFlcgQP284EBFzYHyCXFb9O/hMjK2+6mY9euMB1U1aFFzM/Bg==\n" +
+ "-----END CERTIFICATE-----\n").getBytes();
+
+ /**
+ * Intermediate CA for all of these.
+ */
+ public final static byte[] X509_INTERMEDIATE_CA = (
+ "-----BEGIN CERTIFICATE-----\n" +
+ "MIIEnDCCA4SgAwIBAgIJAJTNwZ6yNa5cMA0GCSqGSIb3DQEBBQUAMIGGMQswCQYD\n" +
+ "VQQGEwJDQTELMAkGA1UECBMCQkMxFjAUBgNVBAoTDXd3dy5jdWNiYy5jb20xFDAS\n" +
+ "BgNVBAsUC2NvbW1vbnNfc3NsMRUwEwYDVQQDFAxkZW1vX3Jvb3RfY2ExJTAjBgkq\n" +
+ "hkiG9w0BCQEWFmp1bGl1c2Rhdmllc0BnbWFpbC5jb20wHhcNMDYxMTA1MjE0OTMx\n" +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f8wDQYJ\n" +
+ "KoZIhvcNAQEFBQADggEBAIB4KMZvHD20pdKajFtMBpL7X4W4soq6EeTtjml3NYa9\n" +
+ "Qc52bsQEGNccKY9afYSBIndaQvFdtmz6HdoN+B8TjYShw2KhyjtKimGLpWYoi1YF\n" +
+ "e4aHdmA/Gp5xk8pZzR18FmooxC9RqBux+NAM2iTFSLgDtGIIj4sg2rbn6Bb6ZlQT\n" +
+ "1rg6VucXCA1629lNfMeNcu7CBNmUKIdaxHR/YJQallE0KfGRiOIWPrPj/VNk0YA6\n" +
+ "XFg0ocjqXJ2/N0N9rWVshMUaXgOh7m4D/5zga5/nuxDU+PoToA6mQ4bV6eCYqZbh\n" +
+ "aa1kQYtR9B4ZiG6pB82qVc2dCqStOH2FAEWos2gAVkQ=\n" +
+ "-----END CERTIFICATE-----\n").getBytes();
+
+ /**
+ * Root CA for all of these.
+ */
+ public final static byte[] X509_ROOT_CA = (
+ "-----BEGIN CERTIFICATE-----\n" +
+ "MIIEgDCCA2igAwIBAgIJAJTNwZ6yNa5bMA0GCSqGSIb3DQEBBQUAMIGGMQswCQYD\n" +
+ "VQQGEwJDQTELMAkGA1UECBMCQkMxFjAUBgNVBAoTDXd3dy5jdWNiYy5jb20xFDAS\n" +
+ "BgNVBAsUC2NvbW1vbnNfc3NsMRUwEwYDVQQDFAxkZW1vX3Jvb3RfY2ExJTAjBgkq\n" +
+ "hkiG9w0BCQEWFmp1bGl1c2Rhdmllc0BnbWFpbC5jb20wHhcNMDYxMTA1MjEzNjQz\n" +
+ "WhcNMjYxMTA1MjEzNjQzWjCBhjELMAkGA1UEBhMCQ0ExCzAJBgNVBAgTAkJDMRYw\n" +
+ "FAYDVQQKEw13d3cuY3VjYmMuY29tMRQwEgYDVQQLFAtjb21tb25zX3NzbDEVMBMG\n" +
+ "A1UEAxQMZGVtb19yb290X2NhMSUwIwYJKoZIhvcNAQkBFhZqdWxpdXNkYXZpZXNA\n" +
+ "Z21haWwuY29tMIIBIjANBgkqhkiG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QN3fcMK5dpBE9NVIu27oYuGYh2sak34v+7T700W2ooBB71qFXtm9P5rl\n" +
+ "Yp9RCEsg3KEEPNTtCBs8fROeXvLDrP0cmBIqwGYDuRNCxFDTOdjv6YGdA8nLOjaH\n" +
+ "2dDk0g==\n" +
+ "-----END CERTIFICATE-----\n").getBytes();
+
+ /**
+ * Below is the private key for all the server certificates above (but
+ * not the intermediate CA or the root CA). All of those server certs
+ * came from the same private key.
+ */
+ public final static String RSA_PUBLIC_MODULUS =
+ "00c863af96823e8ca9d11d62ae85807e713204c1985a80a2747f7ac863c5" +
+ "8d82e8c1ecf9698298d4838a4d8d81958868e0ef385f6e3842b653465f24" +
+ "41b62dc671a1e204820fe67c82367f80cbcb52586a39bf965cf0141cc077" +
+ "f46472cdeac0fd9b6b954a9ffa52a8d2e59ca1cc5e45cefbd4a37c70f1f7" +
+ "9c7674ad5d07c78640672e94e31c4e6dee2bb52558d3b84d29701bda8767" +
+ "56a83371888390b57c8a5bc49a8356316ae9f1406a913729121621098a77" +
+ "713920270312baabfc06a9c677cef1414dc5559238b5bb6407e2b38c3f73" +
+ "cfc4020c901f0e3647474dca350e66c4e817c31c0ac3a94631a895253c69" +
+ "4caab29bddf085893dde5de87047b9e5cd";
+
+ public final static String RSA_PUBLIC_EXPONENT = "65537";
+
+ public final static String RSA_PRIVATE_EXPONENT =
+ "577abd3295553d0efd4d38c13b62a6d03fa7b7e40cce4f1d5071877d96c6" +
+ "7a39a63f0f7ab21a89db8acae45587b3ef251309a70f74dc1ac02bde68f3" +
+ "8ed658e54e685ed370a18c054449512ea66a2252ed36e82b565b5159ec83" +
+ "f23df40ae189550a183865b25fd77789e960f0d8cedcd72f32d7a66edb4b" +
+ "a0a2baf3fbeb6c7d75f56ef0af9a7cff1c8c7f297d72eae7982164e50a89" +
+ "d450698cf598d39343201094241d2d180a95882a7111e58f4a5bdbc5c125" +
+ "a967dd6ed9ec614c5853e88e4c71e8b682a7cf89cb1d82b6fe78cc865084" +
+ "c8c5dfbb50c939df2b839c977b0245bfa3615e0592b527b1013d5b675ecb" +
+ "44e6b355c1df581f50997175166eef39";
+
+ public final static String RSA_PRIME1 =
+ "00fe759c4f0ce8b763880215e82767e7a937297668f4e4b1e119c6b22a3c" +
+ "a2c7b06c547d88d0aa45f645d7d3aeadaf7f8bc594deae0978529592977c" +
+ "b1ff890f05033a9e9e15551cad9fbf9c41d12139ccd99c1c3ac7b2197eff" +
+ "350d236bb900c1440953b64956e0a058ef824a2e16894af175177c77dbe1" +
+ "fef7d8b532608d2513";
+
+ public final static String RSA_PRIME2 =
+ "00c99a45878737a4cf73f9896680b75487f1b669b7686a6ba07103856f31" +
+ "db668c2c440c44cdd116f708f631c37a9adf119f5b5cb58ffe3dc62e20af" +
+ "af72693d936dc6bb3c5194996468389c1f094079b81522e94572b4ad7d39" +
+ "529178e9b8ebaeb1f0fdd83b8731c5223f1dea125341d1d64917f6b1a6ae" +
+ "c18d320510d79f859f";
+
+ public final static String RSA_EXPONENT1 =
+ "029febf0d4cd41b7011c2465b4a259bd6118486464c247236f44a169d61e" +
+ "47b9062508f674508d5031003ceabc57e714e600d71b2c75d5443db2da52" +
+ "6bb45a374f0537c5a1aab3150764ce93cf386c84346a6bd01f6732e42075" +
+ "c7a0e9e78a9e73b934e7d871d0f75673820089e129a1604438edcbbeb4e2" +
+ "106467da112ce389";
+
+ public final static String RSA_EXPONENT2 =
+ "00827e76650c946afcd170038d32e1f8386ab00d6be78d830efe382e45d4" +
+ "7ad4bd04e6231ee22e66740efbf52838134932c9f8c460cdccdec58a1424" +
+ "4427859192fd6ab6c58b74e97941b0eaf577f2a11713af5e5952af3ae124" +
+ "9a9a892e98410dfa2628d9af668a43b5302fb7d496c9b2fec69f595292b6" +
+ "e997f079b0f6314eb7";
+
+ public final static String RSA_COEFFICIENT =
+ "00e6b62add350f1a2a8968903ff76c31cf703b0d7326c4a620aef01225b7" +
+ "1640b3f2ec375208c5f7299863f6005b7799b6e529bb1133c8435bf5fdb5" +
+ "a786f6cd8a19ee7094a384e6557c600a38845a0960ddbfd1df18d0af5740" +
+ "001853788f1b5ccbf9affb4c52c9d2efdb8aab0183d86735b32737fb4e79" +
+ "2b8a9c7d91c7d175ae";
+
+ /**
+ * subjectAlt=IP Address:127.0.0.1, email:oleg@ural.ru, DNS:localhost.localdomain
+ */
+ public final static byte[] X509_MULTIPLE_SUBJECT_ALT = (
+ "-----BEGIN CERTIFICATE-----\n" +
+ "MIIDcTCCAtqgAwIBAgIBATANBgkqhkiG9w0BAQUFADBAMQswCQYDVQQGEwJDSDEL\n" +
+ "MAkGA1UECBMCWkgxDzANBgNVBAcTBlp1cmljaDETMBEGA1UEAxMKTXkgVGVzdCBD\n" +
+ "QTAeFw0wODEwMzExMTU3NDVaFw0wOTEwMzExMTU3NDVaMGkxCzAJBgNVBAYTAkNI\n" +
+ "MRAwDgYDVQQIEwdVbmtub3duMRAwDgYDVQQHEwdVbmtub3duMRAwDgYDVQQKEwdV\n" +
+ "bmtub3duMRAwDgYDVQQLEwdVbmtub3duMRIwEAYDVQQDEwlsb2NhbGhvc3QwggG4\n" +
+ "MIIBLAYHKoZIzjgEATCCAR8CgYEA/X9TgR11EilS30qcLuzk5/YRt1I870QAwx4/\n" +
+ "gLZRJmlFXUAiUftZPY1Y+r/F9bow9subVWzXgTuAHTRv8mZgt2uZUKWkn5/oBHsQ\n" +
+ "IsJPu6nX/rfGG/g7V+fGqKYVDwT7g/bTxR7DAjVUE1oWkTL2dfOuK2HXKu/yIgMZ\n" +
+ "ndFIAccCFQCXYFCPFSMLzLKSuYKi64QL8Fgc9QKBgQD34aCF1ps93su8q1w2uFe5\n" +
+ "eZSvu/o66oL5V0wLPQeCZ1FZV4661FlP5nEHEIGAtEkWcSPoTCgWE7fPCTKMyKbh\n" +
+ "PBZ6i1R8jSjgo64eK7OmdZFuo38L+iE1YvH7YnoBJDvMpPG+qFGQiaiD3+Fa5Z8G\n" +
+ "kotmXoB7VSVkAUw7/s9JKgOBhQACgYEA6ogAb/YLM1Rz9AoXKW4LA70VtFf7Mqqp\n" +
+ "divdu9f72WQc1vMKo1YMf3dQadkMfBYRvAAa1IXDnoiFCHhXnVRkWkoUBJyNebLB\n" +
+ "N92CZc0RVFZiMFgQMEh8UldnvAIi4cBk0/YuN3BGl4MzmquVIGrFovdWGqeaveOu\n" +
+ "Xcu4lKGJNiqjODA2MDQGA1UdEQQtMCuHBH8AAAGBDG9sZWdAdXJhbC5ydYIVbG9j\n" +
+ "YWxob3N0LmxvY2FsZG9tYWluMA0GCSqGSIb3DQEBBQUAA4GBAIgEwIoCSRkU3O7K\n" +
+ "USYaOYyfJB9hsvs6YpClvYXiQ/5kPGARP60pM62v4wC7wI9shEizokIAxY2+O3cC\n" +
+ "vwuJhNYaa2FJMELIwRN3XES8X8R6JHWbPaRjaAAPhczuEd8SZYy8yiVLmJTgw0gH\n" +
+ "BSW775NHlkjsscFVgXkNf0PobqJ9\n" +
+ "-----END CERTIFICATE-----").getBytes();
+
+}
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/HandshakeCompletedEventTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/HandshakeCompletedEventTest.java
index d21215b..fbbde69 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/HandshakeCompletedEventTest.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/HandshakeCompletedEventTest.java
@@ -17,11 +17,14 @@
package tests.api.javax.net.ssl;
+import dalvik.annotation.AndroidOnly;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
import java.io.ByteArrayInputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
@@ -38,6 +41,7 @@ import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLServerSocket;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;
+import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import javax.security.cert.X509Certificate;
@@ -46,7 +50,8 @@ import junit.framework.TestCase;
import org.apache.harmony.luni.util.Base64;
import org.apache.harmony.xnet.tests.support.mySSLSession;
-import org.apache.harmony.xnet.tests.support.mySSLSocket;
+
+import tests.support.Support_PortManager;
/**
* Tests for <code>HandshakeCompletedEvent</code> class constructors and methods.
@@ -73,6 +78,7 @@ public class HandshakeCompletedEventTest extends TestCase {
/**
+ * @throws IOException
* @tests javax.net.ssl.HandshakeCompletedEvent#HandshakeCompletedEvent(SSLSocket sock, SSLSession s)
*/
@TestTargetNew(
@@ -81,12 +87,11 @@ public class HandshakeCompletedEventTest extends TestCase {
method = "HandshakeCompletedEvent",
args = {javax.net.ssl.SSLSocket.class, javax.net.ssl.SSLSession.class}
)
- public final void test_Constructor() {
- mySSLSession session = new mySSLSession("localhost", 1080, null);
- mySSLSocket socket = new mySSLSocket();
+ public final void test_Constructor() throws IOException {
+ mySSLSession session = new mySSLSession();
+ SSLSocket socket = (SSLSocket) SSLSocketFactory.getDefault().createSocket();
try {
HandshakeCompletedEvent event = new HandshakeCompletedEvent(socket, session);
- assertNotNull(event);
} catch (Exception e) {
fail("Unexpected exception: " + e);
}
@@ -99,6 +104,7 @@ public class HandshakeCompletedEventTest extends TestCase {
}
/**
+ * @throws IOException
* @tests javax.net.ssl.HandshakeCompletedEvent#getCipherSuite()
*/
@TestTargetNew(
@@ -107,18 +113,19 @@ public class HandshakeCompletedEventTest extends TestCase {
method = "getCipherSuite",
args = {}
)
- public final void test_getCipherSuite() {
+ public final void test_getCipherSuite() throws IOException {
mySSLSession session = new mySSLSession("localhost", 1080, null);
- mySSLSocket socket = new mySSLSocket();
+ SSLSocket socket = (SSLSocket) SSLSocketFactory.getDefault().createSocket();
HandshakeCompletedEvent event = new HandshakeCompletedEvent(socket, session);
try {
- String name = event.getCipherSuite();
+ assertEquals("SuiteName", event.getCipherSuite());
} catch (Exception e) {
fail("Unexpected exception: " + e);
}
}
/**
+ * @throws IOException
* @tests javax.net.ssl.HandshakeCompletedEvent#getLocalCertificates()
*/
@TestTargetNew(
@@ -127,9 +134,9 @@ public class HandshakeCompletedEventTest extends TestCase {
method = "getLocalCertificates",
args = {}
)
- public final void test_getLocalCertificates() {
+ public final void test_getLocalCertificates() throws IOException {
mySSLSession session = new mySSLSession("localhost", 1080, null);
- mySSLSocket socket = new mySSLSocket();
+ SSLSocket socket = (SSLSocket) SSLSocketFactory.getDefault().createSocket();
HandshakeCompletedEvent event = new HandshakeCompletedEvent(socket, session);
try {
assertNull(event.getLocalCertificates());
@@ -139,6 +146,7 @@ public class HandshakeCompletedEventTest extends TestCase {
}
/**
+ * @throws IOException
* @tests javax.net.ssl.HandshakeCompletedEvent#getLocalPrincipal()
*/
@TestTargetNew(
@@ -147,9 +155,9 @@ public class HandshakeCompletedEventTest extends TestCase {
method = "getLocalPrincipal",
args = {}
)
- public final void test_getLocalPrincipal() {
+ public final void test_getLocalPrincipal() throws IOException {
mySSLSession session = new mySSLSession("localhost", 1080, null);
- mySSLSocket socket = new mySSLSocket();
+ SSLSocket socket = (SSLSocket) SSLSocketFactory.getDefault().createSocket();
HandshakeCompletedEvent event = new HandshakeCompletedEvent(socket, session);
try {
assertNull(event.getLocalPrincipal());
@@ -159,6 +167,7 @@ public class HandshakeCompletedEventTest extends TestCase {
}
/**
+ * @throws IOException
* @tests javax.net.ssl.HandshakeCompletedEvent#getPeerCertificateChain()
*/
@TestTargetNew(
@@ -167,10 +176,10 @@ public class HandshakeCompletedEventTest extends TestCase {
method = "getPeerCertificateChain",
args = {}
)
- public final void test_getPeerCertificateChain() {
+ public final void test_getPeerCertificateChain() throws IOException {
ByteArrayInputStream bis = new ByteArrayInputStream(certificate.getBytes());
- mySSLSession session = new mySSLSession(null);
- mySSLSocket socket = new mySSLSocket();
+ mySSLSession session = new mySSLSession((X509Certificate[]) null);
+ SSLSocket socket = (SSLSocket) SSLSocketFactory.getDefault().createSocket();
HandshakeCompletedEvent event = new HandshakeCompletedEvent(socket, session);
try {
X509Certificate[] res = event.getPeerCertificateChain();
@@ -196,6 +205,7 @@ public class HandshakeCompletedEventTest extends TestCase {
}
/**
+ * @throws IOException
* @tests javax.net.ssl.HandshakeCompletedEvent#getPeerCertificates()
*/
@TestTargetNew(
@@ -204,9 +214,9 @@ public class HandshakeCompletedEventTest extends TestCase {
method = "getPeerCertificates",
args = {}
)
- public final void test_getPeerCertificates() {
+ public final void test_getPeerCertificates() throws IOException {
mySSLSession session = new mySSLSession("localhost", 1080, null);
- mySSLSocket socket = new mySSLSocket();
+ SSLSocket socket = (SSLSocket) SSLSocketFactory.getDefault().createSocket();
HandshakeCompletedEvent event = new HandshakeCompletedEvent(socket, session);
try {
Certificate[] res = event.getPeerCertificates();
@@ -215,7 +225,7 @@ public class HandshakeCompletedEventTest extends TestCase {
//expected
}
- session = new mySSLSession(null);
+ session = new mySSLSession((X509Certificate[]) null);
event = new HandshakeCompletedEvent(socket, session);
try {
Certificate[] res = event.getPeerCertificates();
@@ -226,6 +236,7 @@ public class HandshakeCompletedEventTest extends TestCase {
}
/**
+ * @throws IOException
* @tests javax.net.ssl.HandshakeCompletedEvent#getPeerPrincipal()
*/
@TestTargetNew(
@@ -234,9 +245,9 @@ public class HandshakeCompletedEventTest extends TestCase {
method = "getPeerPrincipal",
args = {}
)
- public final void test_getPeerPrincipal() {
+ public final void test_getPeerPrincipal() throws IOException {
mySSLSession session = new mySSLSession("localhost", 1080, null);
- mySSLSocket socket = new mySSLSocket();
+ SSLSocket socket = (SSLSocket) SSLSocketFactory.getDefault().createSocket();
HandshakeCompletedEvent event = new HandshakeCompletedEvent(socket, session);
try {
assertNull(event.getPeerPrincipal());
@@ -246,6 +257,7 @@ public class HandshakeCompletedEventTest extends TestCase {
}
/**
+ * @throws IOException
* @tests javax.net.ssl.HandshakeCompletedEvent#getSession()
*/
@TestTargetNew(
@@ -254,9 +266,9 @@ public class HandshakeCompletedEventTest extends TestCase {
method = "getSession",
args = {}
)
- public final void test_getSession() {
+ public final void test_getSession() throws IOException {
mySSLSession session = new mySSLSession("localhost", 1080, null);
- mySSLSocket socket = new mySSLSocket();
+ SSLSocket socket = (SSLSocket) SSLSocketFactory.getDefault().createSocket();
HandshakeCompletedEvent event = new HandshakeCompletedEvent(socket, session);
try {
SSLSession ss = event.getSession();
@@ -268,6 +280,7 @@ public class HandshakeCompletedEventTest extends TestCase {
}
/**
+ * @throws IOException
* @tests javax.net.ssl.HandshakeCompletedEvent#getSocket()
*/
@TestTargetNew(
@@ -276,10 +289,9 @@ public class HandshakeCompletedEventTest extends TestCase {
method = "getSocket",
args = {}
)
- public final void test_getSocket() {
- mySSLSession session = new mySSLSession("localhost", 1080, null);
- mySSLSocket socket = new mySSLSocket();
- HandshakeCompletedEvent event = new HandshakeCompletedEvent(socket, session);
+ public final void test_getSocket() throws IOException {
+ SSLSocket socket = (SSLSocket) SSLSocketFactory.getDefault().createSocket();
+ HandshakeCompletedEvent event = new HandshakeCompletedEvent(socket, null);
try {
SSLSocket ss = event.getSocket();
assertNotNull(ss);
@@ -297,7 +309,7 @@ public class HandshakeCompletedEventTest extends TestCase {
SSLSocket socket;
SSLSocket serverSocket;
MyHandshakeListener listener;
- int port = 1081;
+ int port = Support_PortManager.getNextPort();
String host = "localhost";
private String PASSWORD = "android";
@@ -429,18 +441,35 @@ public class HandshakeCompletedEventTest extends TestCase {
* usual sense, we just make sure that we got the expected certificates,
* because our self-signed test certificates are not valid.)
*/
- @TestTargetNew(
+
+ @TestTargets({
+ @TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
clazz = SSLSocket.class,
method = "addHandshakeCompletedListener",
args = {HandshakeCompletedListener.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ clazz = HandshakeCompletedListener.class,
+ method = "handshakeCompleted",
+ args = {HandshakeCompletedEvent.class}
)
+ })
+ @AndroidOnly("Uses bks key store. Change useBKS to false to run on the RI")
public void testClientAuth() {
+
+ boolean useBKS = true;
+
listener = new MyHandshakeListener();
try {
- TestServer server = new TestServer(8088, true, TestServer.CLIENT_AUTH_WANTED);
- TestClient client = new TestClient(8088, true);
+ String serverKeys = (useBKS ? SERVER_KEYS_BKS : SERVER_KEYS_JKS);
+ String clientKeys = (useBKS ? CLIENT_KEYS_BKS : CLIENT_KEYS_JKS);
+ TestServer server = new TestServer(true,
+ TestServer.CLIENT_AUTH_WANTED, serverKeys);
+ TestClient client = new TestClient(true, clientKeys);
Thread serverThread = new Thread(server);
Thread clientThread = new Thread(client);
@@ -486,14 +515,14 @@ public class HandshakeCompletedEventTest extends TestCase {
private Exception exception;
- private int port;
+ String keys;
private int clientAuth;
private boolean provideKeys;
- public TestServer(int port, boolean provideKeys, int clientAuth) {
- this.port = port;
+ public TestServer(boolean provideKeys, int clientAuth, String keys) {
+ this.keys = keys;
this.clientAuth = clientAuth;
this.provideKeys = provideKeys;
@@ -502,7 +531,7 @@ public class HandshakeCompletedEventTest extends TestCase {
public void run() {
try {
- KeyManager[] keyManagers = provideKeys ? getKeyManagers(SERVER_KEYS_BKS) : null;
+ KeyManager[] keyManagers = provideKeys ? getKeyManagers(keys) : null;
TrustManager[] trustManagers = new TrustManager[] { trustManager };
SSLContext sslContext = SSLContext.getInstance("TLS");
@@ -560,12 +589,12 @@ public class HandshakeCompletedEventTest extends TestCase {
private Exception exception;
- private int port;
+ private String keys;
private boolean provideKeys;
- public TestClient(int port, boolean provideKeys) {
- this.port = port;
+ public TestClient(boolean provideKeys, String keys) {
+ this.keys = keys;
this.provideKeys = provideKeys;
trustManager = new TestTrustManager();
@@ -573,7 +602,7 @@ public class HandshakeCompletedEventTest extends TestCase {
public void run() {
try {
- KeyManager[] keyManagers = provideKeys ? getKeyManagers(CLIENT_KEYS_BKS) : null;
+ KeyManager[] keyManagers = provideKeys ? getKeyManagers(keys) : null;
TrustManager[] trustManagers = new TrustManager[] { trustManager };
SSLContext sslContext = SSLContext.getInstance("TLS");
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/HandshakeCompletedListenerTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/HandshakeCompletedListenerTest.java
deleted file mode 100644
index 83d63e3..0000000
--- a/x-net/src/test/java/tests/api/javax/net/ssl/HandshakeCompletedListenerTest.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * 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 tests.api.javax.net.ssl;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
-import javax.net.ssl.HandshakeCompletedEvent;
-import javax.net.ssl.HandshakeCompletedListener;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.xnet.tests.support.mySSLSession;
-import org.apache.harmony.xnet.tests.support.mySSLSocket;
-
-
-/**
- * Tests for <code>HandshakeCompletedListener</code> class constructors and methods.
- *
- */
-@TestTargetClass(HandshakeCompletedListener.class)
-public class HandshakeCompletedListenerTest extends TestCase {
-
- class myHandshakeCompletedListener implements HandshakeCompletedListener {
-
- private boolean completeDone;
-
- myHandshakeCompletedListener() {
- completeDone = false;
- }
-
- public void handshakeCompleted(HandshakeCompletedEvent event) {
- if (event != null) completeDone = true;
- }
- }
-
- /**
- * @tests javax.net.ssl.HandshakeCompletedListener#handshakeCompleted(HandshakeCompletedEvent event)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "handshakeCompleted",
- args = {HandshakeCompletedEvent.class}
- )
- public final void test_handshakeCompleted() {
- mySSLSession session = new mySSLSession("localhost", 1080, null);
- mySSLSocket socket = new mySSLSocket();
- HandshakeCompletedEvent event = new HandshakeCompletedEvent(socket, session);
- myHandshakeCompletedListener hcl = new myHandshakeCompletedListener();
- try {
- hcl.handshakeCompleted(event);
- } catch (Exception e) {
- fail("Unexpected exception: " + e);
- }
- }
-
-}
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/HostnameVerifierTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/HostnameVerifierTest.java
index b9a7487..19caa8f 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/HostnameVerifierTest.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/HostnameVerifierTest.java
@@ -1,70 +1,211 @@
/*
- * 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.
+ * 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 tests.api.javax.net.ssl;
-import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.AndroidOnly;
+import dalvik.annotation.BrokenTest;
+import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;
-import javax.net.ssl.SSLSession;
-import javax.net.ssl.HostnameVerifier;
-
import junit.framework.TestCase;
import org.apache.harmony.xnet.tests.support.mySSLSession;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.security.cert.CertificateFactory;
+import java.security.cert.X509Certificate;
+
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLSession;
+
/**
* Tests for <code>HostnameVerifier</code> class constructors and methods.
*
*/
-@TestTargetClass(HostnameVerifier.class)
-public class HostnameVerifierTest extends TestCase {
-
- class myHostnameVerifier implements HostnameVerifier {
-
- myHostnameVerifier() {
- }
-
- public boolean verify(String hostname, SSLSession session) {
- if (hostname == session.getPeerHost()) {
- return true;
- } else return false;
- }
- }
-
+@TestTargetClass(HostnameVerifier.class)
+public class HostnameVerifierTest extends TestCase implements
+ CertificatesToPlayWith {
+
/**
- * @tests javax.net.ssl.HostnameVerifier#verify(String hostname, SSLSession session)
+ * @tests javax.net.ssl.HostnameVerifier#verify(String hostname, SSLSession
+ * session)
*/
@TestTargetNew(
- level = TestLevel.COMPLETE,
+ level = TestLevel.PARTIAL_COMPLETE,
notes = "",
method = "verify",
args = {String.class, SSLSession.class}
)
+ @BrokenTest("Some side effect from other tests seems to make this test fail.")
public final void test_verify() {
mySSLSession session = new mySSLSession("localhost", 1080, null);
- myHostnameVerifier hv = new myHostnameVerifier();
+ HostnameVerifier hv = HttpsURLConnection.getDefaultHostnameVerifier();
try {
- assertFalse(hv.verify("hostname", session));
- assertTrue(hv.verify("localhost", session));
+ assertFalse(hv.verify("localhost", session));
} catch (Exception e) {
fail("Unexpected exception: " + e);
}
}
+
+ // copied and modified from apache http client test suite.
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "verify",
+ args = {String.class, SSLSession.class}
+ )
+ @AndroidOnly("DefaultHostnameVerifier on RI is weird and cannot be tested this way.")
+ @KnownFailure("DefaultHostnameVerifier is broken on Android, fixed in donutburger")
+ public void testVerify() throws Exception {
+ CertificateFactory cf = CertificateFactory.getInstance("X.509");
+ InputStream in;
+ X509Certificate x509;
+ in = new ByteArrayInputStream(X509_FOO);
+ x509 = (X509Certificate) cf.generateCertificate(in);
+ mySSLSession session = new mySSLSession(new X509Certificate[] {x509});
+
+ HostnameVerifier verifier = HttpsURLConnection
+ .getDefaultHostnameVerifier();
+
+ assertTrue(verifier.verify("foo.com", session));
+ assertFalse(verifier.verify("a.foo.com", session));
+ assertFalse(verifier.verify("bar.com", session));
+
+ in = new ByteArrayInputStream(X509_HANAKO);
+ x509 = (X509Certificate) cf.generateCertificate(in);
+ session = new mySSLSession(new X509Certificate[] {x509});
+ assertTrue(verifier.verify("\u82b1\u5b50.co.jp", session));
+ assertFalse(verifier.verify("a.\u82b1\u5b50.co.jp", session));
+
+ in = new ByteArrayInputStream(X509_FOO_BAR);
+ x509 = (X509Certificate) cf.generateCertificate(in);
+ session = new mySSLSession(new X509Certificate[] {x509});
+ assertTrue(verifier.verify("foo.com", session));
+ assertFalse(verifier.verify("a.foo.com", session));
+ assertTrue(verifier.verify("bar.com", session));
+ assertFalse(verifier.verify("a.bar.com", session));
+
+ in = new ByteArrayInputStream(X509_FOO_BAR_HANAKO);
+ x509 = (X509Certificate) cf.generateCertificate(in);
+ session = new mySSLSession(new X509Certificate[] {x509});
+ assertTrue(verifier.verify("foo.com", session));
+ assertFalse(verifier.verify("a.foo.com", session));
+ // these checks test alternative subjects. The test data contains an
+ // alternative subject starting with a japanese kanji character. This is
+ // not supported by Android because the underlying implementation from
+ // harmony follows the definition from rfc 1034 page 10 for alternative
+ // subject names. This causes the code to drop all alternative subjects.
+ // assertTrue(verifier.verify("bar.com", session));
+ // assertFalse(verifier.verify("a.bar.com", session));
+ // assertFalse(verifier.verify("a.\u82b1\u5b50.co.jp", session));
+
+ in = new ByteArrayInputStream(X509_NO_CNS_FOO);
+ x509 = (X509Certificate) cf.generateCertificate(in);
+ session = new mySSLSession(new X509Certificate[] {x509});
+ assertTrue(verifier.verify("foo.com", session));
+ assertFalse(verifier.verify("a.foo.com", session));
+
+ in = new ByteArrayInputStream(X509_NO_CNS_FOO);
+ x509 = (X509Certificate) cf.generateCertificate(in);
+ session = new mySSLSession(new X509Certificate[] {x509});
+ assertTrue(verifier.verify("foo.com", session));
+ assertFalse(verifier.verify("a.foo.com", session));
+
+ in = new ByteArrayInputStream(X509_THREE_CNS_FOO_BAR_HANAKO);
+ x509 = (X509Certificate) cf.generateCertificate(in);
+ session = new mySSLSession(new X509Certificate[] {x509});
+ assertFalse(verifier.verify("foo.com", session));
+ assertFalse(verifier.verify("a.foo.com", session));
+ assertFalse(verifier.verify("bar.com", session));
+ assertFalse(verifier.verify("a.bar.com", session));
+ assertTrue(verifier.verify("\u82b1\u5b50.co.jp", session));
+ assertFalse(verifier.verify("a.\u82b1\u5b50.co.jp", session));
+
+ in = new ByteArrayInputStream(X509_WILD_FOO);
+ x509 = (X509Certificate) cf.generateCertificate(in);
+ session = new mySSLSession(new X509Certificate[] {x509});
+ assertFalse(verifier.verify("foo.com", session));
+ assertTrue(verifier.verify("www.foo.com", session));
+ assertTrue(verifier.verify("\u82b1\u5b50.foo.com", session));
+ assertTrue(verifier.verify("a.b.foo.com", session));
+
+ in = new ByteArrayInputStream(X509_WILD_CO_JP);
+ x509 = (X509Certificate) cf.generateCertificate(in);
+ session = new mySSLSession(new X509Certificate[] {x509});
+ // Silly test because no-one would ever be able to lookup an IP address
+ // using "*.co.jp".
+ assertTrue(verifier.verify("*.co.jp", session));
+ assertFalse(verifier.verify("foo.co.jp", session));
+ assertFalse(verifier.verify("\u82b1\u5b50.co.jp", session));
+
+ in = new ByteArrayInputStream(X509_WILD_FOO_BAR_HANAKO);
+ x509 = (X509Certificate) cf.generateCertificate(in);
+ session = new mySSLSession(new X509Certificate[] {x509});
+ // try the foo.com variations
+ assertFalse(verifier.verify("foo.com", session));
+ assertTrue(verifier.verify("www.foo.com", session));
+ assertTrue(verifier.verify("\u82b1\u5b50.foo.com", session));
+ assertTrue(verifier.verify("a.b.foo.com", session));
+ // these checks test alternative subjects. The test data contains an
+ // alternative subject starting with a japanese kanji character. This is
+ // not supported by Android because the underlying implementation from
+ // harmony follows the definition from rfc 1034 page 10 for alternative
+ // subject names. This causes the code to drop all alternative subjects.
+ // assertFalse(verifier.verify("bar.com", session));
+ // assertTrue(verifier.verify("www.bar.com", session));
+ // assertTrue(verifier.verify("\u82b1\u5b50.bar.com", session));
+ // assertTrue(verifier.verify("a.b.bar.com", session));
+ }
+
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "verify",
+ args = {String.class, SSLSession.class}
+ )
+ @AndroidOnly("DefaultHostnameVerifier on RI is weird and cannot be tested this way.")
+ @KnownFailure("DefaultHostnameVerifier is broken on Android, fixed in donutburger")
+ public void testSubjectAlt() throws Exception {
+ CertificateFactory cf = CertificateFactory.getInstance("X.509");
+ InputStream in = new ByteArrayInputStream(X509_MULTIPLE_SUBJECT_ALT);
+ X509Certificate x509 = (X509Certificate) cf.generateCertificate(in);
+ mySSLSession session = new mySSLSession(new X509Certificate[] {x509});
+
+ HostnameVerifier verifier = HttpsURLConnection
+ .getDefaultHostnameVerifier();
+
+ // Whitespace differences between RI and Android are ignored by
+ // replacing ", " with ","
+ assertEquals(
+ "CN=localhost,OU=Unknown,O=Unknown,L=Unknown,ST=Unknown,C=CH",
+ x509.getSubjectDN().getName().replace(", ", ","));
+
+ assertTrue(verifier.verify("localhost", session));
+ assertTrue(verifier.verify("localhost.localdomain", session));
+ assertTrue(verifier.verify("127.0.0.1", session));
+
+ assertFalse(verifier.verify("local.host", session));
+ assertFalse(verifier.verify("127.0.0.2", session));
+
+ }
}
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/HttpsURLConnectionTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/HttpsURLConnectionTest.java
index 58177d7..067b2a9 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/HttpsURLConnectionTest.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/HttpsURLConnectionTest.java
@@ -36,7 +36,6 @@ import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;
import org.apache.harmony.security.tests.support.cert.TestUtils;
-import org.apache.harmony.xnet.tests.support.SSLSocketFactoryImpl;
import junit.framework.TestCase;
@@ -61,14 +60,11 @@ public class HttpsURLConnectionTest extends TestCase {
public final void test_Constructor() {
try {
MyHttpsURLConnection huc = new MyHttpsURLConnection(new URL("https://www.fortify.net/"));
- assertNotNull(huc);
- assertTrue(huc instanceof HttpsURLConnection);
} catch (Exception e) {
fail("Unexpected exception: " + e.toString());
}
try {
MyHttpsURLConnection huc = new MyHttpsURLConnection(null);
- assertNotNull(huc);
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
}
@@ -384,7 +380,8 @@ public class HttpsURLConnectionTest extends TestCase {
} catch (IllegalArgumentException e) {
}
try {
- SSLSocketFactoryImpl ssf = new SSLSocketFactoryImpl();
+ SSLSocketFactory ssf = (SSLSocketFactory) SSLSocketFactory
+ .getDefault();
HttpsURLConnection.setDefaultSSLSocketFactory(ssf);
} catch (Exception e) {
fail("Unexpected exception " + e);
@@ -408,7 +405,8 @@ public class HttpsURLConnectionTest extends TestCase {
} catch (IllegalArgumentException e) {
}
try {
- SSLSocketFactoryImpl ssf = new SSLSocketFactoryImpl();
+ SSLSocketFactory ssf = (SSLSocketFactory) SSLSocketFactory
+ .getDefault();
con.setSSLSocketFactory(ssf);
} catch (Exception e) {
fail("Unexpected exception " + e);
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/KeyManagerFactory1Test.java b/x-net/src/test/java/tests/api/javax/net/ssl/KeyManagerFactory1Test.java
index 2777a4a..421966b 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/KeyManagerFactory1Test.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/KeyManagerFactory1Test.java
@@ -20,7 +20,6 @@ package tests.api.javax.net.ssl;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.KnownFailure;
import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
@@ -180,8 +179,6 @@ public class KeyManagerFactory1Test extends TestCase {
KeyManagerFactory keyMF;
for (int i = 0; i < validValues.length; i++) {
keyMF = KeyManagerFactory.getInstance(validValues[i]);
- assertTrue("Not KeyManagerFactory object",
- keyMF instanceof KeyManagerFactory);
assertEquals("Invalid algorithm", keyMF.getAlgorithm(),
validValues[i]);
}
@@ -336,8 +333,6 @@ public class KeyManagerFactory1Test extends TestCase {
for (int i = 0; i < validValues.length; i++) {
kMF = KeyManagerFactory.getInstance(validValues[i],
defaultProviderName);
- assertTrue("Not KeyManagerFactory object",
- kMF instanceof KeyManagerFactory);
assertEquals("Incorrect algorithm", kMF.getAlgorithm(),
validValues[i]);
assertEquals("Incorrect provider", kMF.getProvider().getName(),
@@ -428,7 +423,6 @@ public class KeyManagerFactory1Test extends TestCase {
for (int i = 0; i < validValues.length; i++) {
kMF = KeyManagerFactory
.getInstance(validValues[i], defaultProvider);
- assertTrue(kMF instanceof KeyManagerFactory);
assertEquals(kMF.getAlgorithm(), validValues[i]);
assertEquals(kMF.getProvider(), defaultProvider);
}
@@ -444,7 +438,7 @@ public class KeyManagerFactory1Test extends TestCase {
method = "KeyManagerFactory",
args = {javax.net.ssl.KeyManagerFactorySpi.class, java.security.Provider.class, java.lang.String.class}
)
- public void test_Constructor() throws NoSuchAlgorithmException {
+ public void test_Constructor() {
if (!DEFSupported) {
fail(NotSupportedMsg);
return;
@@ -452,7 +446,6 @@ public class KeyManagerFactory1Test extends TestCase {
KeyManagerFactorySpi spi = new MyKeyManagerFactorySpi();
KeyManagerFactory keyMF = new myKeyManagerFactory(spi, defaultProvider,
defaultAlgorithm);
- assertTrue("Not CertStore object", keyMF instanceof KeyManagerFactory);
assertEquals("Incorrect algorithm", keyMF.getAlgorithm(),
defaultAlgorithm);
assertEquals("Incorrect provider", keyMF.getProvider(), defaultProvider);
@@ -464,12 +457,12 @@ public class KeyManagerFactory1Test extends TestCase {
fail("Unexpected: "+e.toString()+" was thrown");
}
keyMF = new myKeyManagerFactory(null, null, null);
- assertTrue("Not CertStore object", keyMF instanceof KeyManagerFactory);
assertNull("Aalgorithm must be null", keyMF.getAlgorithm());
assertNull("Provider must be null", keyMF.getProvider());
try {
keyMF.getKeyManagers();
} catch (NullPointerException e) {
+ // expected
}
}
@@ -585,13 +578,10 @@ public class KeyManagerFactory1Test extends TestCase {
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "functionality is not implemented in org.apache.harmony.xnet.provider.jsse.engineInit(ManagerFactoryParameters)",
+ notes = "",
method = "init",
args = {javax.net.ssl.ManagerFactoryParameters.class}
)
- @KnownFailure("ManagerFactoryParameters object is not supported " +
- "and InvalidAlgorithmParameterException was thrown." +
- "RI: functionality is not implemented, just exception.")
public void test_initLjavax_net_ssl_ManagerFactoryParameters()
throws NoSuchAlgorithmException {
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/KeyManagerFactory2Test.java b/x-net/src/test/java/tests/api/javax/net/ssl/KeyManagerFactory2Test.java
index 104b30b..f25b3ab 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/KeyManagerFactory2Test.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/KeyManagerFactory2Test.java
@@ -114,13 +114,13 @@ public class KeyManagerFactory2Test extends TestCase {
}
keyMF.init(kStore, pass);
- mfp = (ManagerFactoryParameters) new MyKeyManagerFactorySpi.Parameters(kStore, null);
+ mfp = new MyKeyManagerFactorySpi.Parameters(kStore, null);
try {
keyMF.init(mfp);
fail("InvalidAlgorithmParameterException must be thrown");
} catch (InvalidAlgorithmParameterException e) {
}
- mfp = (ManagerFactoryParameters) new MyKeyManagerFactorySpi.Parameters(kStore, pass);
+ mfp = new MyKeyManagerFactorySpi.Parameters(kStore, pass);
keyMF.init(mfp);
}
/**
@@ -154,8 +154,6 @@ public class KeyManagerFactory2Test extends TestCase {
KeyManagerFactory keyMF;
for (int i = 0; i < validValues.length; i++) {
keyMF = KeyManagerFactory.getInstance(validValues[i]);
- assertTrue("Not instanceof KeyManagerFactory object",
- keyMF instanceof KeyManagerFactory);
assertEquals("Incorrect algorithm", keyMF.getAlgorithm(),
validValues[i]);
assertEquals("Incorrect provider", keyMF.getProvider(), mProv);
@@ -228,8 +226,6 @@ public class KeyManagerFactory2Test extends TestCase {
for (int i = 0; i < validValues.length; i++) {
keyMF = KeyManagerFactory.getInstance(validValues[i], mProv
.getName());
- assertTrue("Not instanceof KeyManagerFactory object",
- keyMF instanceof KeyManagerFactory);
assertEquals("Incorrect algorithm", keyMF.getAlgorithm(),
validValues[i]);
assertEquals("Incorrect provider", keyMF.getProvider().getName(),
@@ -282,8 +278,6 @@ public class KeyManagerFactory2Test extends TestCase {
KeyManagerFactory keyMF;
for (int i = 0; i < validValues.length; i++) {
keyMF = KeyManagerFactory.getInstance(validValues[i], mProv);
- assertTrue("Not instanceof KeyManagerFactory object",
- keyMF instanceof KeyManagerFactory);
assertEquals("Incorrect algorithm", keyMF.getAlgorithm(),
validValues[i]);
assertEquals("Incorrect provider", keyMF.getProvider(), mProv);
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/KeyStoreBuilderParametersTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/KeyStoreBuilderParametersTest.java
index 6e1af6b..613e701 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/KeyStoreBuilderParametersTest.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/KeyStoreBuilderParametersTest.java
@@ -75,7 +75,7 @@ public class KeyStoreBuilderParametersTest extends TestCase {
public void test_Constructor02() {
//Null parameter
- List ls = null;
+ List<String> ls = null;
try {
KeyStoreBuilderParameters ksp = new KeyStoreBuilderParameters(ls);
fail("NullPointerException should be thrown");
@@ -84,7 +84,7 @@ public class KeyStoreBuilderParametersTest extends TestCase {
}
//Empty parameter
- List lsEmpty = new ArrayList();
+ List<String> lsEmpty = new ArrayList<String>();
try {
KeyStoreBuilderParameters ksp = new KeyStoreBuilderParameters(lsEmpty);
fail("IllegalArgumentException should be thrown");
@@ -93,7 +93,7 @@ public class KeyStoreBuilderParametersTest extends TestCase {
}
//Not null parameter
- List lsFiled = new ArrayList();;
+ List<String> lsFiled = new ArrayList<String>();;
lsFiled.add("Parameter1");
lsFiled.add("Parameter2");
try {
@@ -116,13 +116,18 @@ public class KeyStoreBuilderParametersTest extends TestCase {
)
public void test_getParameters() {
String[] param = {"Parameter1", "Parameter2", "Parameter3"};
- List ls = new ArrayList();
+ List<String> ls = new ArrayList<String>();
for (int i = 0; i < param.length; i++) {
ls.add(param[i]);
}
KeyStoreBuilderParameters ksp = new KeyStoreBuilderParameters(ls);
try {
- List res_list = ksp.getParameters();
+ List<String> res_list = ksp.getParameters();
+ try {
+ res_list.add("test");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
Object[] res = res_list.toArray();
if (res.length == param.length) {
for (int i = 0; i < res.length; i++) {
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/SSLContext1Test.java b/x-net/src/test/java/tests/api/javax/net/ssl/SSLContext1Test.java
index 1315b69..244d77b 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/SSLContext1Test.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/SSLContext1Test.java
@@ -17,6 +17,7 @@
package tests.api.javax.net.ssl;
+import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
@@ -107,8 +108,7 @@ public class SSLContext1Test extends TestCase {
args = {javax.net.ssl.SSLContextSpi.class, java.security.Provider.class, java.lang.String.class}
)
public void test_ConstructorLjavax_net_ssl_SSLContextSpiLjava_security_ProviderLjava_lang_String()
- throws NoSuchAlgorithmException,
- KeyManagementException {
+ throws KeyManagementException {
if (!DEFSupported) {
fail(NotSupportMsg);
return;
@@ -116,24 +116,22 @@ public class SSLContext1Test extends TestCase {
SSLContextSpi spi = new MySSLContextSpi();
SSLContext sslContext = new mySSLContext(spi, defaultProvider,
defaultProtocol);
- assertTrue("Not CertStore object", sslContext instanceof SSLContext);
- assertEquals("Incorrect protocol", sslContext.getProtocol(),
- defaultProtocol);
- assertEquals("Incorrect provider", sslContext.getProvider(),
- defaultProvider);
+ assertNotNull("Not CertStore object", sslContext);
+ assertEquals("Incorrect protocol", defaultProtocol,
+ sslContext.getProtocol());
+ assertEquals("Incorrect provider", defaultProvider,
+ sslContext.getProvider());
TrustManager[] tm = null;
KeyManager[] km = null;
sslContext.init(km, tm, new SecureRandom());
- assertTrue(sslContext.createSSLEngine() instanceof SSLEngine);
- assertTrue(sslContext.createSSLEngine("host host", 8888) instanceof SSLEngine);
try {
sslContext.init(km, tm, null);
fail("KeyManagementException should be thrown for null SEcureRandom");
} catch (KeyManagementException e) {
+ // expected
}
sslContext = new mySSLContext(null, null, null);
- assertTrue("Not CertStore object", sslContext instanceof SSLContext);
assertNull("Incorrect protocol", sslContext.getProtocol());
assertNull("Incorrect provider", sslContext.getProvider());
try {
@@ -200,7 +198,8 @@ public class SSLContext1Test extends TestCase {
method = "getClientSessionContext",
args = {}
)
- public void test_getClientSessionContext() throws NoSuchAlgorithmException {
+ @KnownFailure("Works on RI but throws NPE on Android, maybe related to SSLSessionContextTest issues")
+ public void test_getClientSessionContext() {
if (!DEFSupported) {
fail(NotSupportMsg);
return;
@@ -208,10 +207,10 @@ public class SSLContext1Test extends TestCase {
SSLContext[] sslC = createSSLCon();
assertNotNull("SSLContext objects were not created", sslC);
for (int i = 0; i < sslC.length; i++) {
- assertTrue("Client session is incorrectly instantiated",
- sslC[i].getClientSessionContext() instanceof SSLSessionContext);
- assertTrue("Server session is incorrectly instantiated",
- sslC[i].getServerSessionContext() instanceof SSLSessionContext);
+ assertNotNull("Client session is incorrectly instantiated",
+ sslC[i].getClientSessionContext());
+ assertNotNull("Server session is incorrectly instantiated",
+ sslC[i].getServerSessionContext());
}
}
@@ -221,7 +220,7 @@ public class SSLContext1Test extends TestCase {
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
+ notes = "checks valid protocol values",
method = "getInstance",
args = {java.lang.String.class}
)
@@ -233,10 +232,9 @@ public class SSLContext1Test extends TestCase {
SSLContext sslContext;
for (int i = 0; i < validValues.length; i++) {
sslContext = SSLContext.getInstance(validValues[i]);
- assertTrue("Not SSLContext object",
- sslContext instanceof SSLContext);
- assertEquals("Invalid protocol", sslContext.getProtocol(),
- validValues[i]);
+ assertNotNull("Not SSLContext object", sslContext);
+ assertEquals("Invalid protocol", validValues[i],
+ sslContext.getProtocol());
}
}
@@ -247,14 +245,14 @@ public class SSLContext1Test extends TestCase {
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
+ notes = "checks invalid protocol values",
method = "getInstance",
args = {java.lang.String.class}
)
public void test_getInstanceLjava_lang_String02() {
try {
SSLContext.getInstance(null);
- fail("NoSuchAlgorithmException or NullPointerException should be thrown (protocol is null");
+ fail("NoSuchAlgorithmException or NullPointerException should be thrown (protocol is null)");
} catch (NoSuchAlgorithmException e) {
} catch (NullPointerException e) {
}
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/SSLEngineTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/SSLEngineTest.java
index 94e384d..3f163c3 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/SSLEngineTest.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/SSLEngineTest.java
@@ -17,6 +17,8 @@
package tests.api.javax.net.ssl;
+import dalvik.annotation.BrokenTest;
+import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
@@ -25,11 +27,14 @@ import dalvik.annotation.AndroidOnly;
import java.nio.ByteBuffer;
+import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLException;
-import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLEngineResult;
import java.nio.ReadOnlyBufferException;
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
+import java.util.Arrays;
import junit.framework.TestCase;
@@ -48,6 +53,7 @@ public class SSLEngineTest extends TestCase {
/**
* Test for <code>SSLEngine()</code> constructor Assertion: creates
* SSLEngine object with null host and -1 port
+ * @throws NoSuchAlgorithmException
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
@@ -55,17 +61,18 @@ public class SSLEngineTest extends TestCase {
method = "SSLEngine",
args = {}
)
- public void test_Constructor() {
- SSLEngine e = new mySSLEngine();
+ public void test_Constructor() throws NoSuchAlgorithmException {
+ SSLEngine e = getEngine();
assertNull(e.getPeerHost());
assertEquals(-1, e.getPeerPort());
- String[] suites = { "a", "b", "c" };
+ String[] suites = e.getSupportedCipherSuites();
e.setEnabledCipherSuites(suites);
assertEquals(e.getEnabledCipherSuites().length, suites.length);
}
/**
* Test for <code>SSLEngine(String host, int port)</code> constructor
+ * @throws NoSuchAlgorithmException
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
@@ -73,19 +80,37 @@ public class SSLEngineTest extends TestCase {
method = "SSLEngine",
args = {java.lang.String.class, int.class}
)
- public void test_ConstructorLjava_lang_StringI01() throws SSLException {
+ public void test_ConstructorLjava_lang_StringI01() throws NoSuchAlgorithmException {
int port = 1010;
- SSLEngine e = new mySSLEngine(null, port);
+ SSLEngine e = getEngine(null, port);
assertNull(e.getPeerHost());
assertEquals(e.getPeerPort(), port);
try {
e.beginHandshake();
+ } catch (IllegalStateException ex) {
+ // expected
} catch (SSLException ex) {
+ fail("unexpected SSLException was thrown.");
+ }
+ e = getEngine(null, port);
+ e.setUseClientMode(true);
+ try {
+ e.beginHandshake();
+ } catch (SSLException ex) {
+ // expected
+ }
+ e = getEngine(null, port);
+ e.setUseClientMode(false);
+ try {
+ e.beginHandshake();
+ } catch (SSLException ex) {
+ // expected
}
}
/**
* Test for <code>SSLEngine(String host, int port)</code> constructor
+ * @throws NoSuchAlgorithmException
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
@@ -93,13 +118,13 @@ public class SSLEngineTest extends TestCase {
method = "SSLEngine",
args = {java.lang.String.class, int.class}
)
- public void test_ConstructorLjava_lang_StringI02() {
+ public void test_ConstructorLjava_lang_StringI02() throws NoSuchAlgorithmException {
String host = "new host";
int port = 8080;
- SSLEngine e = new mySSLEngine(host, port);
+ SSLEngine e = getEngine(host, port);
assertEquals(e.getPeerHost(), host);
assertEquals(e.getPeerPort(), port);
- String[] suites = { "a", "b", "c" };
+ String[] suites = e.getSupportedCipherSuites();
e.setEnabledCipherSuites(suites);
assertEquals(e.getEnabledCipherSuites().length, suites.length);
e.setUseClientMode(true);
@@ -108,6 +133,7 @@ public class SSLEngineTest extends TestCase {
/**
* Test for <code>getPeerHost()</code> method
+ * @throws NoSuchAlgorithmException
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
@@ -115,15 +141,16 @@ public class SSLEngineTest extends TestCase {
method = "getPeerHost",
args = {}
)
- public void test_getPeerHost() {
- SSLEngine e = new mySSLEngine();
+ public void test_getPeerHost() throws NoSuchAlgorithmException {
+ SSLEngine e = getEngine();
assertNull(e.getPeerHost());
- e = new mySSLEngine("www.fortify.net", 80);
+ e = getEngine("www.fortify.net", 80);
assertEquals("Incorrect host name", "www.fortify.net", e.getPeerHost());
}
/**
* Test for <code>getPeerPort()</code> method
+ * @throws NoSuchAlgorithmException
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
@@ -131,15 +158,16 @@ public class SSLEngineTest extends TestCase {
method = "getPeerPort",
args = {}
)
- public void test_getPeerPort() {
- SSLEngine e = new mySSLEngine();
+ public void test_getPeerPort() throws NoSuchAlgorithmException {
+ SSLEngine e = getEngine();
assertEquals("Incorrect default value of peer port",
-1 ,e.getPeerPort());
- e = new mySSLEngine("www.fortify.net", 80);
+ e = getEngine("www.fortify.net", 80);
assertEquals("Incorrect peer port", 80, e.getPeerPort());
}
/**
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.SSLEngine#getSupportedProtocols()
*/
@TestTargetNew(
@@ -148,18 +176,19 @@ public class SSLEngineTest extends TestCase {
method = "getSupportedProtocols",
args = {}
)
- public void test_getSupportedProtocols() {
- mySSLEngine sse = new mySSLEngine();
+ public void test_getSupportedProtocols() throws NoSuchAlgorithmException {
+ SSLEngine sse = getEngine();
try {
String[] res = sse.getSupportedProtocols();
assertNotNull(res);
- assertEquals(res.length, 0);
+ assertTrue(res.length > 0);
} catch (Exception ex) {
fail("Unexpected exception " + ex);
}
}
/**
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.SSLEngine#setEnabledProtocols(String[] protocols)
* @tests javax.net.ssl.SSLEngine#getEnabledProtocols()
*/
@@ -177,15 +206,15 @@ public class SSLEngineTest extends TestCase {
args = {String[].class}
)
})
- public void test_EnabledProtocols() {
- mySSLEngine sse = new mySSLEngine();
- String[] pr = {"Protocil_01", "Protocol_02"};
+ public void test_EnabledProtocols() throws NoSuchAlgorithmException {
+ SSLEngine sse = getEngine();
+ String[] pr = sse.getSupportedProtocols();
try {
sse.setEnabledProtocols(pr);
String[] res = sse.getEnabledProtocols();
assertNotNull("Null array was returned", res);
assertEquals("Incorrect array length", res.length, pr.length);
- assertEquals("Incorrect array was returned", res, pr);
+ assertTrue("Incorrect array was returned", Arrays.equals(res, pr));
} catch (Exception ex) {
fail("Unexpected exception " + ex);
}
@@ -198,6 +227,7 @@ public class SSLEngineTest extends TestCase {
}
/**
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.SSLEngine#getSupportedCipherSuites()
*/
@TestTargetNew(
@@ -206,18 +236,19 @@ public class SSLEngineTest extends TestCase {
method = "getSupportedCipherSuites",
args = {}
)
- public void test_getSupportedCipherSuites() {
- mySSLEngine sse = new mySSLEngine();
+ public void test_getSupportedCipherSuites() throws NoSuchAlgorithmException {
+ SSLEngine sse = getEngine();
try {
String[] res = sse.getSupportedCipherSuites();
assertNotNull(res);
- assertEquals(res.length, 0);
+ assertTrue(res.length > 0);
} catch (Exception ex) {
fail("Unexpected exception " + ex);
}
}
/**
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.SSLEngine#setEnabledCipherSuites(String[] suites)
* @tests javax.net.ssl.SSLEngine#getEnabledCipherSuites()
*/
@@ -235,15 +266,15 @@ public class SSLEngineTest extends TestCase {
args = {}
)
})
- public void test_EnabledCipherSuites() {
- mySSLEngine sse = new mySSLEngine();
- String[] st = {"Suite_01", "Suite_02"};
+ public void test_EnabledCipherSuites() throws NoSuchAlgorithmException {
+ SSLEngine sse = getEngine();
+ String[] st = sse.getSupportedCipherSuites();
try {
sse.setEnabledCipherSuites(st);
String[] res = sse.getEnabledCipherSuites();
assertNotNull("Null array was returned", res);
assertEquals("Incorrect array length", res.length, st.length);
- assertEquals("Incorrect array was returned", res, st);
+ assertTrue("Incorrect array was returned", Arrays.equals(res, st));
} catch (Exception ex) {
fail("Unexpected exception " + ex);
}
@@ -256,6 +287,7 @@ public class SSLEngineTest extends TestCase {
}
/**
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.SSLEngine#setEnableSessionCreation(boolean flag)
* @tests javax.net.ssl.SSLEngine#getEnableSessionCreation()
*/
@@ -273,8 +305,8 @@ public class SSLEngineTest extends TestCase {
args = {}
)
})
- public void test_EnableSessionCreation() {
- mySSLEngine sse = new mySSLEngine();
+ public void test_EnableSessionCreation() throws NoSuchAlgorithmException {
+ SSLEngine sse = getEngine();
try {
assertTrue(sse.getEnableSessionCreation());
sse.setEnableSessionCreation(false);
@@ -287,6 +319,7 @@ public class SSLEngineTest extends TestCase {
}
/**
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.SSLEngine#setNeedClientAuth(boolean need)
* @tests javax.net.ssl.SSLEngine#getNeedClientAuth()
*/
@@ -304,8 +337,8 @@ public class SSLEngineTest extends TestCase {
args = {}
)
})
- public void test_NeedClientAuth() {
- mySSLEngine sse = new mySSLEngine();
+ public void test_NeedClientAuth() throws NoSuchAlgorithmException {
+ SSLEngine sse = getEngine();
try {
sse.setNeedClientAuth(false);
assertFalse(sse.getNeedClientAuth());
@@ -317,6 +350,7 @@ public class SSLEngineTest extends TestCase {
}
/**
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.SSLEngine#setWantClientAuth(boolean want)
* @tests javax.net.ssl.SSLEngine#getWantClientAuth()
*/
@@ -334,8 +368,8 @@ public class SSLEngineTest extends TestCase {
args = {}
)
})
- public void test_WantClientAuth() {
- mySSLEngine sse = new mySSLEngine();
+ public void test_WantClientAuth() throws NoSuchAlgorithmException {
+ SSLEngine sse = getEngine();
try {
sse.setWantClientAuth(false);
assertFalse(sse.getWantClientAuth());
@@ -347,6 +381,7 @@ public class SSLEngineTest extends TestCase {
}
/**
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.SSLEngine#beginHandshake()
*/
@TestTargetNew(
@@ -355,15 +390,17 @@ public class SSLEngineTest extends TestCase {
method = "beginHandshake",
args = {}
)
- public void test_beginHandshake() {
- mySSLEngine sse = new mySSLEngine();
+ public void test_beginHandshake() throws NoSuchAlgorithmException {
+ SSLEngine sse = getEngine();
try {
sse.beginHandshake();
- fail("SSLException wasn't thrown");
- } catch (SSLException se) {
+ fail("IllegalStateException wasn't thrown");
+ } catch (IllegalStateException se) {
//expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalStateException");
}
- sse = new mySSLEngine("new host", 1080);
+ sse = getEngine("new host", 1080);
try {
sse.beginHandshake();
fail("IllegalStateException wasn't thrown");
@@ -372,9 +409,9 @@ public class SSLEngineTest extends TestCase {
} catch (Exception e) {
fail(e + " was thrown instead of IllegalStateException");
}
+ sse = getEngine();
try {
sse.setUseClientMode(true);
- System.out.println("<--- Client mode was set");
sse.beginHandshake();
} catch (Exception ex) {
fail("Unexpected exception " + ex);
@@ -382,6 +419,7 @@ public class SSLEngineTest extends TestCase {
}
/**
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.SSLEngine#setUseClientMode(boolean mode)
* @tests javax.net.ssl.SSLEngine#getUseClientMode()
*/
@@ -399,8 +437,9 @@ public class SSLEngineTest extends TestCase {
args = {}
)
})
- public void test_UseClientMode() {
- mySSLEngine sse = new mySSLEngine();
+ @AndroidOnly("The RI doesn't throw the expected IllegalStateException.")
+ public void test_UseClientMode() throws NoSuchAlgorithmException {
+ SSLEngine sse = getEngine();
try {
sse.setUseClientMode(false);
assertFalse(sse.getUseClientMode());
@@ -411,7 +450,7 @@ public class SSLEngineTest extends TestCase {
}
try {
- sse = new mySSLEngine("new host", 1080);
+ sse = getEngine(null, 1080);
sse.setUseClientMode(true);
sse.beginHandshake();
try {
@@ -426,6 +465,7 @@ public class SSLEngineTest extends TestCase {
}
/**
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.SSLEngine#getSession()
*/
@TestTargetNew(
@@ -434,16 +474,17 @@ public class SSLEngineTest extends TestCase {
method = "getSession",
args = {}
)
- public void test_getSession() {
- mySSLEngine sse = new mySSLEngine();
+ public void test_getSession() throws NoSuchAlgorithmException {
+ SSLEngine sse = getEngine();
try {
- assertNull(sse.getSession());
+ assertNotNull(sse.getSession());
} catch (Exception ex) {
fail("Unexpected exception " + ex);
}
}
/**
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.SSLEngine#getHandshakeStatus()
*/
@TestTargetNew(
@@ -452,16 +493,20 @@ public class SSLEngineTest extends TestCase {
method = "getHandshakeStatus",
args = {}
)
- public void test_getHandshakeStatus() {
- mySSLEngine sse = new mySSLEngine();
+ public void test_getHandshakeStatus() throws NoSuchAlgorithmException {
+ SSLEngine sse = getEngine();
try {
- assertEquals(sse.getHandshakeStatus().toString(), "FINISHED");
+ assertEquals(sse.getHandshakeStatus().toString(), "NOT_HANDSHAKING");
+ sse.setUseClientMode(true);
+ sse.beginHandshake();
+ assertEquals(sse.getHandshakeStatus().toString(), "NEED_WRAP");
} catch (Exception ex) {
fail("Unexpected exception " + ex);
}
}
/**
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.SSLEngine#getDelegatedTask()
*/
@TestTargetNew(
@@ -470,8 +515,9 @@ public class SSLEngineTest extends TestCase {
method = "getDelegatedTask",
args = {}
)
- public void test_getDelegatedTask() {
- mySSLEngine sse = new mySSLEngine();
+ @BrokenTest("Throws NPE because sse seems to be null")
+ public void test_getDelegatedTask() throws NoSuchAlgorithmException {
+ SSLEngine sse = getEngine();
try {
assertNull(sse.getDelegatedTask());
} catch (Exception ex) {
@@ -490,14 +536,14 @@ public class SSLEngineTest extends TestCase {
method = "unwrap",
args = {ByteBuffer.class, ByteBuffer[].class, int.class, int.class}
)
+ @BrokenTest("SSLException is not thrown")
public void test_unwrap_01() {
- ByteBuffer bbs = ByteBuffer.allocate(100);
- ByteBuffer bbd = ByteBuffer.allocate(10);
- SSLEngine sse = new mySSLEngine1();
+ ByteBuffer bbs = ByteBuffer.wrap(new byte[] {1,2,3,1,2,3,1,2,3,1,2,3});
+ ByteBuffer bbd = ByteBuffer.allocate(100);
+ SSLEngine sse = getEngine();
sse.setUseClientMode(true);
-
try {
- sse.unwrap(bbs, new ByteBuffer[] { bbd }, 0, 10);
+ sse.unwrap(bbs, new ByteBuffer[] { bbd }, 0, 1);
fail("SSLException wasn't thrown");
} catch (SSLException ex) {
//expected
@@ -515,13 +561,14 @@ public class SSLEngineTest extends TestCase {
method = "unwrap",
args = {ByteBuffer.class, ByteBuffer[].class, int.class, int.class}
)
+ @KnownFailure("Fixed in DonutBurger, boundary checks missing")
public void test_unwrap_02() throws SSLException {
String host = "new host";
int port = 8080;
ByteBuffer[] bbA = { ByteBuffer.allocate(100), ByteBuffer.allocate(10), ByteBuffer.allocate(100) };
ByteBuffer bb = ByteBuffer.allocate(10);
- SSLEngine sse = new mySSLEngine1(host, port);
+ SSLEngine sse = getEngine(host, port);
sse.setUseClientMode(true);
try {
@@ -561,6 +608,7 @@ public class SSLEngineTest extends TestCase {
method = "unwrap",
args = {ByteBuffer.class, ByteBuffer[].class, int.class, int.class}
)
+ @KnownFailure("Fixed on DonutBurger, Wrong Exception thrown")
public void test_unwrap_03() {
String host = "new host";
int port = 8080;
@@ -568,7 +616,7 @@ public class SSLEngineTest extends TestCase {
ByteBuffer[] bbA = { bbR, ByteBuffer.allocate(10), ByteBuffer.allocate(100) };
ByteBuffer bb = ByteBuffer.allocate(10);
- SSLEngine sse = new mySSLEngine1(host, port);
+ SSLEngine sse = getEngine(host, port);
sse.setUseClientMode(true);
try {
@@ -592,7 +640,7 @@ public class SSLEngineTest extends TestCase {
method = "unwrap",
args = {ByteBuffer.class, ByteBuffer[].class, int.class, int.class}
)
- @AndroidOnly("NullPointerException was thrown instead of IllegalArgumentException for null parameter.")
+ @KnownFailure("Fixed on DonutBurger, Wrong Exception thrown")
public void test_unwrap_04() {
String host = "new host";
int port = 8080;
@@ -601,7 +649,7 @@ public class SSLEngineTest extends TestCase {
ByteBuffer[] bbN = null;
ByteBuffer bb = ByteBuffer.allocate(10);
ByteBuffer bN = null;
- SSLEngine sse = new mySSLEngine1(host, port);
+ SSLEngine sse = getEngine(host, port);
sse.setUseClientMode(true);
try {
@@ -654,13 +702,14 @@ public class SSLEngineTest extends TestCase {
method = "unwrap",
args = {ByteBuffer.class, ByteBuffer[].class, int.class, int.class}
)
+ @AndroidOnly("The RI doesn't throw the IllegalStateException.")
public void test_unwrap_05() {
String host = "new host";
int port = 8080;
ByteBuffer[] bbA = { ByteBuffer.allocate(100), ByteBuffer.allocate(10), ByteBuffer.allocate(100) };
ByteBuffer bb = ByteBuffer.allocate(10);
- SSLEngine sse = new mySSLEngine1(host, port);
+ SSLEngine sse = getEngine(host, port);
try {
SSLEngineResult res = sse.unwrap(bb, bbA, 0, bbA.length);
@@ -688,13 +737,13 @@ public class SSLEngineTest extends TestCase {
ByteBuffer[] bbA = { ByteBuffer.allocate(100), ByteBuffer.allocate(10), ByteBuffer.allocate(100) };
ByteBuffer bb = ByteBuffer.allocate(10);
- SSLEngine sse = new mySSLEngine1(host, port);
+ SSLEngine sse = getEngine(host, port);
sse.setUseClientMode(true);
try {
SSLEngineResult res = sse.unwrap(bb, bbA, 0, bbA.length);
- assertEquals(1, res.bytesConsumed());
- assertEquals(2, res.bytesProduced());
+ assertEquals(0, res.bytesConsumed());
+ assertEquals(0, res.bytesProduced());
} catch (Exception ex) {
fail("Unexpected exception: " + ex);
}
@@ -711,14 +760,15 @@ public class SSLEngineTest extends TestCase {
method = "wrap",
args = {ByteBuffer[].class, int.class, int.class, ByteBuffer.class}
)
+ @BrokenTest("SSLException is not thrown")
public void test_wrap_01() {
ByteBuffer bbs = ByteBuffer.allocate(100);
ByteBuffer bbd = ByteBuffer.allocate(10);
- SSLEngine sse = new mySSLEngine1();
+ SSLEngine sse = getEngine();
sse.setUseClientMode(true);
try {
- sse.wrap(new ByteBuffer[] { bbs }, 0, 100, bbd);
+ sse.wrap(new ByteBuffer[] { bbs }, 0, 1, bbd);
fail("SSLException wasn't thrown");
} catch (SSLException ex) {
//expected
@@ -736,12 +786,13 @@ public class SSLEngineTest extends TestCase {
method = "wrap",
args = {ByteBuffer[].class, int.class, int.class, ByteBuffer.class}
)
+ @KnownFailure("Fixed in DonutBurger, boundary checks missing")
public void test_wrap_02() throws SSLException {
String host = "new host";
int port = 8080;
ByteBuffer bb = ByteBuffer.allocate(10);
ByteBuffer[] bbA = {ByteBuffer.allocate(5), ByteBuffer.allocate(10), ByteBuffer.allocate(5)};
- SSLEngine sse = new mySSLEngine1(host, port);
+ SSLEngine sse = getEngine(host, port);
sse.setUseClientMode(true);
try {
@@ -786,7 +837,7 @@ public class SSLEngineTest extends TestCase {
int port = 8080;
ByteBuffer bb = ByteBuffer.allocate(10).asReadOnlyBuffer();
ByteBuffer[] bbA = {ByteBuffer.allocate(5), ByteBuffer.allocate(10), ByteBuffer.allocate(5)};
- SSLEngine sse = new mySSLEngine1(host, port);
+ SSLEngine sse = getEngine(host, port);
sse.setUseClientMode(true);
try {
@@ -808,7 +859,7 @@ public class SSLEngineTest extends TestCase {
method = "wrap",
args = {ByteBuffer[].class, int.class, int.class, ByteBuffer.class}
)
- @AndroidOnly("NullPointerException was thrown instead of IllegalArgumentException for null parameter.")
+ @KnownFailure("Fixed on DonutBurger, Wrong Exception thrown")
public void test_wrap_04() {
String host = "new host";
int port = 8080;
@@ -817,7 +868,7 @@ public class SSLEngineTest extends TestCase {
ByteBuffer[] bbN = null;
ByteBuffer bb = ByteBuffer.allocate(10);
ByteBuffer bN = null;
- SSLEngine e = new mySSLEngine1(host, port);
+ SSLEngine e = getEngine(host, port);
e.setUseClientMode(true);
try {
@@ -850,12 +901,13 @@ public class SSLEngineTest extends TestCase {
method = "wrap",
args = {ByteBuffer[].class, int.class, int.class, ByteBuffer.class}
)
+ @AndroidOnly("The RI doesn't throw the IllegalStateException.")
public void test_wrap_05() throws SSLException {
String host = "new host";
int port = 8080;
ByteBuffer bb = ByteBuffer.allocate(10);
ByteBuffer[] bbA = {ByteBuffer.allocate(5), ByteBuffer.allocate(10), ByteBuffer.allocate(5)};
- SSLEngine sse = new mySSLEngine1(host, port);
+ SSLEngine sse = getEngine(host, port);
try {
SSLEngineResult res = sse.wrap(bbA, 0, bbA.length, bb);
@@ -880,7 +932,7 @@ public class SSLEngineTest extends TestCase {
int port = 8080;
ByteBuffer bb = ByteBuffer.allocate(10);
ByteBuffer[] bbA = {ByteBuffer.allocate(5), ByteBuffer.allocate(10), ByteBuffer.allocate(5)};
- SSLEngine sse = new mySSLEngine1(host, port);
+ SSLEngine sse = getEngine(host, port);
sse.setUseClientMode(true);
try {
@@ -891,6 +943,7 @@ public class SSLEngineTest extends TestCase {
}
/**
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.SSLEngine#closeOutbound()
* @tests javax.net.ssl.SSLEngine#isOutboundDone()
*/
@@ -908,8 +961,8 @@ public class SSLEngineTest extends TestCase {
args = {}
)
})
- public void test_closeOutbound() {
- SSLEngine sse = new mySSLEngine();
+ public void test_closeOutbound() throws NoSuchAlgorithmException {
+ SSLEngine sse = getEngine();
try {
assertFalse(sse.isOutboundDone());
@@ -921,6 +974,7 @@ public class SSLEngineTest extends TestCase {
}
/**
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.SSLEngine#closeInbound()
* @tests javax.net.ssl.SSLEngine#isInboundDone()
*/
@@ -938,8 +992,8 @@ public class SSLEngineTest extends TestCase {
args = {}
)
})
- public void test_closeInbound() {
- SSLEngine sse = new mySSLEngine();
+ public void test_closeInbound() throws NoSuchAlgorithmException {
+ SSLEngine sse = getEngine();
try {
assertFalse(sse.isInboundDone());
@@ -960,10 +1014,11 @@ public class SSLEngineTest extends TestCase {
method = "unwrap",
args = {ByteBuffer.class, ByteBuffer.class}
)
+ @BrokenTest("SSLException is not thrown")
public void test_unwrap_ByteBuffer_ByteBuffer_01() {
ByteBuffer bbs = ByteBuffer.allocate(100);
ByteBuffer bbd = ByteBuffer.allocate(10);
- SSLEngine sse = new mySSLEngine1();
+ SSLEngine sse = getEngine();
sse.setUseClientMode(true);
try {
@@ -984,12 +1039,13 @@ public class SSLEngineTest extends TestCase {
method = "unwrap",
args = {ByteBuffer.class, ByteBuffer.class}
)
+ @KnownFailure("Fixed on DonutBurger, Wrong Exception thrown")
public void test_unwrap_ByteBuffer_ByteBuffer_02() {
String host = "new host";
int port = 8080;
ByteBuffer bbs = ByteBuffer.allocate(10);
ByteBuffer bbd = ByteBuffer.allocate(100).asReadOnlyBuffer();
- SSLEngine sse = new mySSLEngine1(host, port);
+ SSLEngine sse = getEngine(host, port);
sse.setUseClientMode(true);
try {
@@ -1012,7 +1068,7 @@ public class SSLEngineTest extends TestCase {
method = "unwrap",
args = {ByteBuffer.class, ByteBuffer.class}
)
- @AndroidOnly("NullPointerException was thrown instead of IllegalArgumentException for null parameter.")
+ @KnownFailure("Fixed on DonutBurger, Wrong Exception thrown")
public void test_unwrap_ByteBuffer_ByteBuffer_03() {
String host = "new host";
int port = 8080;
@@ -1020,7 +1076,7 @@ public class SSLEngineTest extends TestCase {
ByteBuffer bbdN = null;
ByteBuffer bbs = ByteBuffer.allocate(10);
ByteBuffer bbd = ByteBuffer.allocate(100);
- SSLEngine sse = new mySSLEngine1(host, port);
+ SSLEngine sse = getEngine(host, port);
sse.setUseClientMode(true);
try {
@@ -1064,12 +1120,13 @@ public class SSLEngineTest extends TestCase {
method = "unwrap",
args = {ByteBuffer.class, ByteBuffer.class}
)
+ @AndroidOnly("The RI doesn't throw the IllegalStateException.")
public void test_unwrap_ByteBuffer_ByteBuffer_04() {
String host = "new host";
int port = 8080;
ByteBuffer bbs = ByteBuffer.allocate(10);
ByteBuffer bbd = ByteBuffer.allocate(100);
- SSLEngine sse = new mySSLEngine1(host, port);
+ SSLEngine sse = getEngine(host, port);
try {
SSLEngineResult res = sse.unwrap(bbs, bbd);
@@ -1095,13 +1152,13 @@ public class SSLEngineTest extends TestCase {
int port = 8080;
ByteBuffer bbs = ByteBuffer.allocate(10);
ByteBuffer bbd = ByteBuffer.allocate(100);
- SSLEngine sse = new mySSLEngine1(host, port);
+ SSLEngine sse = getEngine(host, port);
sse.setUseClientMode(true);
try {
SSLEngineResult res = sse.unwrap(bbs, bbd);
- assertEquals(1, res.bytesConsumed());
- assertEquals(2, res.bytesProduced());
+ assertEquals(0, res.bytesConsumed());
+ assertEquals(0, res.bytesProduced());
} catch (Exception e) {
fail("Unexpected exception: " + e);
}
@@ -1117,10 +1174,11 @@ public class SSLEngineTest extends TestCase {
method = "unwrap",
args = {ByteBuffer.class, ByteBuffer[].class}
)
+ @BrokenTest("SSLException is not thrown")
public void test_unwrap_ByteBuffer$ByteBuffer_01() {
ByteBuffer bbs = ByteBuffer.allocate(100);
ByteBuffer bbd = ByteBuffer.allocate(10);
- SSLEngine sse = new mySSLEngine1();
+ SSLEngine sse = getEngine();
sse.setUseClientMode(true);
try {
@@ -1141,13 +1199,14 @@ public class SSLEngineTest extends TestCase {
method = "unwrap",
args = {ByteBuffer.class, ByteBuffer[].class}
)
+ @KnownFailure("Fixed on DonutBurger, Wrong Exception thrown")
public void test_unwrap_ByteBuffer$ByteBuffer_02() {
String host = "new host";
int port = 8080;
ByteBuffer bbs = ByteBuffer.allocate(10);
ByteBuffer bbR = ByteBuffer.allocate(100).asReadOnlyBuffer();
ByteBuffer[] bbA = { bbR, ByteBuffer.allocate(10), ByteBuffer.allocate(100) };
- SSLEngine sse = new mySSLEngine1(host, port);
+ SSLEngine sse = getEngine(host, port);
sse.setUseClientMode(true);
try {
@@ -1170,7 +1229,7 @@ public class SSLEngineTest extends TestCase {
method = "unwrap",
args = {ByteBuffer.class, ByteBuffer[].class}
)
- @AndroidOnly("NullPointerException was thrown instead of IllegalArgumentException for null parameter.")
+ @KnownFailure("Fixed on DonutBurger, Wrong Exception thrown")
public void test_unwrap_ByteBuffer$ByteBuffer_03() {
String host = "new host";
int port = 8080;
@@ -1179,7 +1238,7 @@ public class SSLEngineTest extends TestCase {
ByteBuffer[] bbAN = null;
ByteBuffer bb = ByteBuffer.allocate(10);
ByteBuffer bN = null;
- SSLEngine sse = new mySSLEngine1(host, port);
+ SSLEngine sse = getEngine(host, port);
sse.setUseClientMode(true);
try {
@@ -1233,12 +1292,13 @@ public class SSLEngineTest extends TestCase {
method = "unwrap",
args = {ByteBuffer.class, ByteBuffer[].class}
)
+ @AndroidOnly("The RI doesn't throw the IllegalStateException.")
public void test_unwrap_ByteBuffer$ByteBuffer_04() {
String host = "new host";
int port = 8080;
ByteBuffer bbs = ByteBuffer.allocate(10);
ByteBuffer[] bbd = {ByteBuffer.allocate(100), ByteBuffer.allocate(10), ByteBuffer.allocate(100) };
- SSLEngine sse = new mySSLEngine1(host, port);
+ SSLEngine sse = getEngine(host, port);
try {
SSLEngineResult res = sse.unwrap(bbs, bbd);
@@ -1264,13 +1324,13 @@ public class SSLEngineTest extends TestCase {
int port = 8080;
ByteBuffer bbs = ByteBuffer.allocate(10);
ByteBuffer[] bbd = {ByteBuffer.allocate(100), ByteBuffer.allocate(10), ByteBuffer.allocate(100) };
- SSLEngine sse = new mySSLEngine1(host, port);
+ SSLEngine sse = getEngine(host, port);
sse.setUseClientMode(true);
try {
SSLEngineResult res = sse.unwrap(bbs, bbd);
- assertEquals(1, res.bytesConsumed());
- assertEquals(2, res.bytesProduced());
+ assertEquals(0, res.bytesConsumed());
+ assertEquals(0, res.bytesProduced());
} catch (Exception ex) {
fail("Unexpected exception: " + ex);
}
@@ -1286,10 +1346,11 @@ public class SSLEngineTest extends TestCase {
method = "wrap",
args = {ByteBuffer.class, ByteBuffer.class}
)
+ @BrokenTest("SSLException is not thrown")
public void test_wrap_ByteBuffer_ByteBuffer_01() {
ByteBuffer bbs = ByteBuffer.allocate(100);
ByteBuffer bbd = ByteBuffer.allocate(10);
- SSLEngine sse = new mySSLEngine1();
+ SSLEngine sse = getEngine();
sse.setUseClientMode(true);
try {
@@ -1315,7 +1376,7 @@ public class SSLEngineTest extends TestCase {
int port = 8080;
ByteBuffer bbs = ByteBuffer.allocate(10);
ByteBuffer bbd = ByteBuffer.allocate(100).asReadOnlyBuffer();
- SSLEngine sse = new mySSLEngine1(host, port);
+ SSLEngine sse = getEngine(host, port);
sse.setUseClientMode(true);
try {
@@ -1338,7 +1399,7 @@ public class SSLEngineTest extends TestCase {
method = "wrap",
args = {ByteBuffer.class, ByteBuffer.class}
)
- @AndroidOnly("NullPointerException was thrown instead of IllegalArgumentException for null parameter.")
+ @KnownFailure("Fixed on DonutBurger, Wrong Exception thrown")
public void test_wrap_ByteBuffer_ByteBuffer_03() {
String host = "new host";
int port = 8080;
@@ -1346,7 +1407,7 @@ public class SSLEngineTest extends TestCase {
ByteBuffer bbdN = null;
ByteBuffer bbs = ByteBuffer.allocate(10);
ByteBuffer bbd = ByteBuffer.allocate(100);
- SSLEngine sse = new mySSLEngine1(host, port);
+ SSLEngine sse = getEngine(host, port);
sse.setUseClientMode(true);
try {
@@ -1390,12 +1451,13 @@ public class SSLEngineTest extends TestCase {
method = "wrap",
args = {ByteBuffer.class, ByteBuffer.class}
)
+ @AndroidOnly("The RI doesn't throw the IllegalStateException.")
public void test_wrap_ByteBuffer_ByteBuffer_04() {
String host = "new host";
int port = 8080;
ByteBuffer bbs = ByteBuffer.allocate(10);
ByteBuffer bbd = ByteBuffer.allocate(10);
- SSLEngine sse = new mySSLEngine1(host, port);
+ SSLEngine sse = getEngine(host, port);
try {
SSLEngineResult res = sse.wrap(bbs, bbd);
@@ -1420,13 +1482,13 @@ public class SSLEngineTest extends TestCase {
String host = "new host";
int port = 8080;
ByteBuffer bb = ByteBuffer.allocate(10);
- SSLEngine sse = new mySSLEngine1(host, port);
+ SSLEngine sse = getEngine(host, port);
sse.setUseClientMode(true);
try {
SSLEngineResult res = sse.wrap(bb, ByteBuffer.allocate(10));
- assertEquals(10, res.bytesConsumed());
- assertEquals(20, res.bytesProduced());
+ assertEquals(0, res.bytesConsumed());
+ assertEquals(0, res.bytesProduced());
} catch (Exception e) {
fail("Unexpected exception: " + e);
}
@@ -1442,10 +1504,11 @@ public class SSLEngineTest extends TestCase {
method = "wrap",
args = {ByteBuffer[].class, ByteBuffer.class}
)
+ @BrokenTest("SSLException is not thrown")
public void test_wrap_ByteBuffer$ByteBuffer_01() {
ByteBuffer bbs = ByteBuffer.allocate(100);
ByteBuffer bbd = ByteBuffer.allocate(10);
- SSLEngine sse = new mySSLEngine1();
+ SSLEngine sse = getEngine();
sse.setUseClientMode(true);
try {
@@ -1471,7 +1534,7 @@ public class SSLEngineTest extends TestCase {
int port = 8080;
ByteBuffer bb = ByteBuffer.allocate(10).asReadOnlyBuffer();
ByteBuffer[] bbA = {ByteBuffer.allocate(5), ByteBuffer.allocate(10), ByteBuffer.allocate(5)};
- SSLEngine sse = new mySSLEngine1(host, port);
+ SSLEngine sse = getEngine(host, port);
sse.setUseClientMode(true);
try {
@@ -1494,7 +1557,7 @@ public class SSLEngineTest extends TestCase {
method = "wrap",
args = {ByteBuffer[].class, ByteBuffer.class}
)
- @AndroidOnly("NullPointerException was thrown instead of IllegalArgumentException for null parameter.")
+ @KnownFailure("Fixed on DonutBurger, Wrong Exception thrown")
public void test_wrap_ByteBuffer$ByteBuffer_03() {
String host = "new host";
int port = 8080;
@@ -1503,7 +1566,7 @@ public class SSLEngineTest extends TestCase {
ByteBuffer[] bbAN = null;
ByteBuffer bb = ByteBuffer.allocate(10);
ByteBuffer bN = null;
- SSLEngine sse = new mySSLEngine1(host, port);
+ SSLEngine sse = getEngine(host, port);
sse.setUseClientMode(true);
try {
@@ -1547,12 +1610,13 @@ public class SSLEngineTest extends TestCase {
method = "wrap",
args = {ByteBuffer[].class, ByteBuffer.class}
)
+ @AndroidOnly("The RI doesn't throw the IllegalStateException.")
public void test_wrap_ByteBuffer$ByteBuffer_04() {
String host = "new host";
int port = 8080;
ByteBuffer bb = ByteBuffer.allocate(10);
ByteBuffer[] bbA = { ByteBuffer.allocate(5), ByteBuffer.allocate(10), ByteBuffer.allocate(5) };
- SSLEngine sse = new mySSLEngine1(host, port);
+ SSLEngine sse = getEngine(host, port);
try {
SSLEngineResult res = sse.wrap(bbA, bb);
@@ -1578,265 +1642,43 @@ public class SSLEngineTest extends TestCase {
int port = 8080;
ByteBuffer bb = ByteBuffer.allocate(10);
ByteBuffer[] bbA = { ByteBuffer.allocate(5), ByteBuffer.allocate(10), ByteBuffer.allocate(5) };
- SSLEngine sse = new mySSLEngine1(host, port);
+ SSLEngine sse = getEngine(host, port);
sse.setUseClientMode(true);
try {
SSLEngineResult res = sse.wrap(bbA, bb);
- assertEquals(10, res.bytesConsumed());
- assertEquals(20, res.bytesProduced());
+ assertEquals(0, res.bytesConsumed());
+ assertEquals(0, res.bytesProduced());
} catch (Exception ex) {
fail("Unexpected exception: " + ex);
}
}
-}
-
-/*
- * Additional class for verification SSLEngine constructors
- */
-
-class mySSLEngine extends SSLEngine {
-
- private boolean useClientMode;
-
- private boolean needClientAuth;
-
- private boolean enableSessionCreation = true;
-
- private boolean wantClientAuth;
-
- private String[] enabledProtocols;
-
- private String[] enabledCipherSuites;
-
- public int mode = -1;
- private boolean init = false;
- private boolean inboundDone = false;
- private boolean outboundDone = false;
-
- public mySSLEngine() {
- super();
- }
-
- protected mySSLEngine(String host, int port) {
- super(host, port);
- }
-
- public void beginHandshake() throws SSLException {
- String host = super.getPeerHost();
- if ((host == null) || (host.length() == 0)) {
- throw new SSLException("");
- }
- if (mode == -1) {
- throw new IllegalStateException();
- }
- init = true;
- }
-
- public void closeInbound() throws SSLException {
- inboundDone = true;
- }
-
- public void closeOutbound() {
- outboundDone = true;
- }
-
- public Runnable getDelegatedTask() {
- return null;
- }
-
- public String[] getEnabledCipherSuites() {
- return enabledCipherSuites;
- }
-
- public String[] getEnabledProtocols() {
- return enabledProtocols;
- }
-
- public boolean getEnableSessionCreation() {
- return enableSessionCreation;
- }
-
- public SSLEngineResult.HandshakeStatus getHandshakeStatus() {
- return SSLEngineResult.HandshakeStatus.FINISHED;
- }
-
- public boolean getNeedClientAuth() {
- return needClientAuth;
- }
-
- public SSLSession getSession() {
- return null;
- }
-
- public String[] getSupportedCipherSuites() {
- return new String[0];
- }
-
- public String[] getSupportedProtocols() {
- return new String[0];
- }
- public boolean getUseClientMode() {
- return useClientMode;
- }
-
- public boolean getWantClientAuth() {
- return wantClientAuth;
- }
-
- public boolean isInboundDone() {
- return inboundDone;
- }
-
- public boolean isOutboundDone() {
- return outboundDone;
- }
-
- public void setEnabledCipherSuites(String[] suites) {
- if (suites == null) {
- throw new IllegalArgumentException();
- }
- enabledCipherSuites = suites;
- }
-
- public void setEnabledProtocols(String[] protocols) {
- if (protocols == null) {
- throw new IllegalArgumentException();
+ private SSLEngine getEngine() {
+ SSLContext context = null;
+ try {
+ context = SSLContext.getInstance("TLS");
+ context.init(null, null, null);
+ } catch (KeyManagementException e) {
+ fail("Could not get SSLEngine: key management exception "
+ + e.getMessage());
+ } catch (NoSuchAlgorithmException e) {
+ fail("Could not get SSLEngine: no such algorithm " + e.getMessage());
}
- enabledProtocols = protocols;
- }
-
- public void setEnableSessionCreation(boolean flag) {
- enableSessionCreation = flag;
- }
-
- public void setNeedClientAuth(boolean need) {
- needClientAuth = need;
+ return context.createSSLEngine();
}
- public void setUseClientMode(boolean mode) {
- if (init) {
- throw new IllegalArgumentException();
- }
- useClientMode = mode;
- if (useClientMode) {
- this.mode = 1;
- } else {
- this.mode = 0;
+ private SSLEngine getEngine(String host, int port) {
+ SSLContext context = null;
+ try {
+ context = SSLContext.getInstance("TLS");
+ context.init(null, null, null);
+ } catch (KeyManagementException e) {
+ fail("Could not get SSLEngine: key management exception "
+ + e.getMessage());
+ } catch (NoSuchAlgorithmException e) {
+ fail("Could not get SSLEngine: no such algorithm " + e.getMessage());
}
- }
-
- public void setWantClientAuth(boolean want) {
- wantClientAuth = want;
- }
-
- public SSLEngineResult unwrap(ByteBuffer src, ByteBuffer[] dsts,
- int offset, int length) throws SSLException {
- return new SSLEngineResult(SSLEngineResult.Status.OK,
- SSLEngineResult.HandshakeStatus.FINISHED, 1, 2);
- }
-
- public SSLEngineResult wrap(ByteBuffer[] srcs, int offset, int length,
- ByteBuffer dst) throws SSLException {
- return new SSLEngineResult(SSLEngineResult.Status.OK,
- SSLEngineResult.HandshakeStatus.FINISHED, 10, 20);
+ return context.createSSLEngine(host, port);
}
}
-
-class mySSLEngine1 extends mySSLEngine {
-
- public mySSLEngine1() {
- }
-
- public mySSLEngine1(String host, int port) {
- super(host, port);
- }
-
- public SSLEngineResult unwrap(ByteBuffer src, ByteBuffer dst)
- throws SSLException {
- if (src.limit() > dst.limit()) {
- throw new SSLException("incorrect limits");
- }
- return super.unwrap(src, dst);
- }
-
- public SSLEngineResult unwrap(ByteBuffer src, ByteBuffer[] dsts)
- throws SSLException {
- if (src.limit() > dsts[0].limit()) {
- throw new SSLException("incorrect limits");
- }
- return super.unwrap(src, dsts);
- }
-
- public SSLEngineResult wrap(ByteBuffer[] srcs, ByteBuffer dst)
- throws SSLException {
- if (srcs[0].limit() > dst.limit()) {
- throw new SSLException("incorrect limits");
- }
- return super.wrap(srcs, dst);
- }
-
- public SSLEngineResult wrap(ByteBuffer src, ByteBuffer dst)
- throws SSLException {
- if (src.limit() > dst.limit()) {
- throw new SSLException("incorrect limits");
- }
- return super.wrap(src, dst);
- }
-
- public SSLEngineResult unwrap(ByteBuffer src, ByteBuffer[] dsts,
- int offset, int length) throws SSLException {
- if (super.mode == -1) {
- throw new IllegalStateException("client/server mode has not yet been set");
- }
- if (src.limit() > dsts[0].limit()) {
- throw new SSLException("incorrect limits");
- }
- if (offset < 0 || length < 0) {
- throw new IndexOutOfBoundsException("negative parameter");
- }
- if (offset > length || length > dsts.length - offset) {
- throw new IndexOutOfBoundsException("negative parameter");
- }
- if (src.equals(null) || dsts.equals(null)) {
- throw new IllegalArgumentException("null parameter");
- }
- for (int i = 0; i < dsts.length; i++) {
- if (dsts[i].isReadOnly()) {
- throw new ReadOnlyBufferException();
- } else if (dsts[i].equals(null)) {
- throw new IllegalArgumentException("null parameter");
- }
- }
- return super.unwrap(src, dsts, offset, length);
- }
-
- public SSLEngineResult wrap(ByteBuffer[] srcs, int offset, int length, ByteBuffer dst)
- throws SSLException {
- if (super.mode == -1) {
- throw new IllegalStateException("client/server mode has not yet been set");
- }
- if (srcs[0].limit() > dst.limit()) {
- throw new SSLException("incorrect limits");
- }
- if (offset < 0 || length < 0) {
- throw new IndexOutOfBoundsException("negative parameter");
- }
- if (offset > length || length > srcs.length - offset) {
- throw new IndexOutOfBoundsException("negative parameter");
- }
- if (srcs.equals(null) || dst.equals(null)) {
- throw new IllegalArgumentException("null parameter");
- }
- for (int i = 0; i < srcs.length; i++) {
- if (srcs[i].equals(null)) {
- throw new IllegalArgumentException("null parameter");
- }
- }
- if (dst.isReadOnly()) {
- throw new ReadOnlyBufferException();
- }
- return super.wrap(srcs, offset, length, dst);
- }
-} \ No newline at end of file
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/SSLServerSocketFactoryTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/SSLServerSocketFactoryTest.java
index a702d56..979d574 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/SSLServerSocketFactoryTest.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/SSLServerSocketFactoryTest.java
@@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package tests.api.javax.net.ssl;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
@@ -28,60 +28,42 @@ import javax.net.ssl.SSLServerSocketFactory;
import junit.framework.TestCase;
-@TestTargetClass(SSLServerSocketFactory.class)
+@TestTargetClass(SSLServerSocketFactory.class)
public class SSLServerSocketFactoryTest extends TestCase {
-
+
private class MockSSLServerSocketFactory extends SSLServerSocketFactory {
public MockSSLServerSocketFactory() {
super();
}
- /**
- * @see javax.net.ssl.SSLServerSocketFactory#getDefaultCipherSuites()
- */
@Override
public String[] getDefaultCipherSuites() {
- // it is a fake
return null;
}
- /**
- * @see javax.net.ssl.SSLServerSocketFactory#getSupportedCipherSuites()
- */
@Override
public String[] getSupportedCipherSuites() {
- // it is a fake
return null;
}
- /**
- * @see javax.net.ServerSocketFactory#createServerSocket(int)
- */
@Override
public ServerSocket createServerSocket(int arg0) throws IOException {
- // it is a fake
return null;
}
- /**
- * @see javax.net.ServerSocketFactory#createServerSocket(int, int)
- */
@Override
- public ServerSocket createServerSocket(int arg0, int arg1) throws IOException {
- // it is a fake
+ public ServerSocket createServerSocket(int arg0, int arg1)
+ throws IOException {
return null;
}
- /**
- * @see javax.net.ServerSocketFactory#createServerSocket(int, int, java.net.InetAddress)
- */
@Override
- public ServerSocket createServerSocket(int arg0, int arg1, InetAddress arg2) throws IOException {
- // it is a fake
+ public ServerSocket createServerSocket(int arg0, int arg1,
+ InetAddress arg2) throws IOException {
return null;
}
}
-
+
/**
* @tests javax.net.ssl.SSLServerSocketFactory#SSLServerSocketFactory()
*/
@@ -94,7 +76,6 @@ public class SSLServerSocketFactoryTest extends TestCase {
public void test_Constructor() {
try {
MockSSLServerSocketFactory ssf = new MockSSLServerSocketFactory();
- assertTrue(ssf instanceof SSLServerSocketFactory);
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
}
@@ -113,7 +94,7 @@ public class SSLServerSocketFactoryTest extends TestCase {
assertNotNull("Incorrect default socket factory",
SSLServerSocketFactory.getDefault());
}
-
+
/**
* @tests javax.net.ssl.SSLServerSocketFactory#getDefaultCipherSuites()
*/
@@ -124,14 +105,15 @@ public class SSLServerSocketFactoryTest extends TestCase {
args = {}
)
public void test_getDefaultCipherSuites() {
- MockSSLServerSocketFactory ssf = new MockSSLServerSocketFactory();
+ SSLServerSocketFactory ssf = (SSLServerSocketFactory) SSLServerSocketFactory
+ .getDefault();
try {
- assertNull(ssf.getDefaultCipherSuites());
+ assertTrue(ssf.getDefaultCipherSuites().length > 0);
} catch (Exception e) {
fail("Unexpected exception " + e);
}
}
-
+
/**
* @tests javax.net.ssl.SSLServerSocketFactory#getSupportedCipherSuites()
*/
@@ -142,9 +124,10 @@ public class SSLServerSocketFactoryTest extends TestCase {
args = {}
)
public void test_getSupportedCipherSuites() {
- MockSSLServerSocketFactory ssf = new MockSSLServerSocketFactory();
+ SSLServerSocketFactory ssf = (SSLServerSocketFactory) SSLServerSocketFactory
+ .getDefault();
try {
- assertNull(ssf.getSupportedCipherSuites());
+ assertTrue(ssf.getSupportedCipherSuites().length > 0);
} catch (Exception e) {
fail("Unexpected exception " + e);
}
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/SSLServerSocketTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/SSLServerSocketTest.java
index 4007d92..bdb9bb1 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/SSLServerSocketTest.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/SSLServerSocketTest.java
@@ -13,122 +13,112 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package tests.api.javax.net.ssl;
-import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargets;
-import javax.net.ssl.*;
-
-import java.net.*;
-import java.io.*;
-import java.lang.String;
-
import junit.framework.TestCase;
+import org.apache.harmony.luni.util.Base64;
+
import tests.support.Support_PortManager;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.InetAddress;
+import java.security.KeyStore;
+
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLServerSocket;
+
@TestTargetClass(SSLServerSocket.class)
public class SSLServerSocketTest extends TestCase {
+ // set to true if on Android, false if on RI
+ boolean useBKS = true;
+
/**
* Additional class for SSLServerSocket constructor verification
*/
class mySSLServerSocket extends SSLServerSocket {
- private boolean sslFlag = true;
- private boolean sslNeed = false;
- private boolean sslWant = false;
- private boolean sslMode = true;
- private String[] supportProtocol = null;
- private String[] supportSuites = null;
-
- public mySSLServerSocket(String[] protocols, String[] suites) throws IOException {
- super();
- supportProtocol = protocols;
- supportSuites = suites;
- }
public mySSLServerSocket() throws IOException{
super();
}
+
public mySSLServerSocket(int port) throws IOException{
super(port);
}
+
public mySSLServerSocket(int port, int backlog) throws IOException{
super(port, backlog);
}
+
public mySSLServerSocket(int port, int backlog, InetAddress address) throws IOException{
super(port, backlog, address);
}
-
+
public String[] getSupportedCipherSuites() {
- if (supportSuites == null) {
- throw new NullPointerException();
- }
- if (supportSuites.length == 0) {
- return null;
- } else return supportSuites;
+ return null;
}
+
public void setEnabledCipherSuites(String[] suites) {
- if (suites == null) {
- throw new IllegalArgumentException("null parameter");
- }
- if (!suites.equals(supportSuites)) {
- throw new IllegalArgumentException("incorrect suite");
- }
+
}
+
public String[] getEnabledCipherSuites() {
- return supportSuites;
+ return null;
}
-
+
public String[] getSupportedProtocols() {
- if (supportProtocol == null) {
- throw new NullPointerException();
- }
- if (supportProtocol.length == 0) {
- return null;
- } else return supportProtocol;
+ return null;
}
+
public String[] getEnabledProtocols() {
- return supportProtocol;
+ return null;
}
+
public void setEnabledProtocols(String[] protocols) {
- if (protocols == null) {
- throw new IllegalArgumentException("null protocol");
- }
- if (!protocols.equals(supportProtocol)) {
- throw new IllegalArgumentException("incorrect protocol");
- }
+
}
public void setEnableSessionCreation(boolean flag) {
- sslFlag = flag;
+
}
+
public boolean getEnableSessionCreation() {
- return sslFlag;
+ return false;
}
public void setNeedClientAuth(boolean need) {
- sslNeed = need;
+
}
+
public boolean getNeedClientAuth() {
- return sslNeed;
+ return false;
}
public boolean getUseClientMode() {
- return sslMode;
+ return false;
}
+
public void setUseClientMode(boolean mode) {
- sslMode = mode;
+
}
public boolean getWantClientAuth() {
- return sslWant;
+ return false;
}
public void setWantClientAuth(boolean mode) {
- sslWant = mode;
+
}
}
@@ -143,9 +133,7 @@ public class SSLServerSocketTest extends TestCase {
)
public void testConstructor_01() {
try {
- mySSLServerSocket ssl = new mySSLServerSocket();
- assertNotNull(ssl);
- assertTrue(ssl instanceof SSLServerSocket);
+ SSLServerSocket ssl = new mySSLServerSocket();
} catch (Exception ex) {
fail("Unexpected exception was thrown " + ex);
}
@@ -161,13 +149,12 @@ public class SSLServerSocketTest extends TestCase {
args = {int.class}
)
public void testConstructor_02() {
- mySSLServerSocket ssl;
+ SSLServerSocket ssl;
int portNumber = Support_PortManager.getNextPort();
int[] port_invalid = {-1, 65536, Integer.MIN_VALUE, Integer.MAX_VALUE};
try {
ssl = new mySSLServerSocket(portNumber);
- assertNotNull(ssl);
assertEquals(portNumber, ssl.getLocalPort());
} catch (Exception ex) {
fail("Unexpected exception was thrown " + ex);
@@ -187,7 +174,9 @@ public class SSLServerSocketTest extends TestCase {
try {
ssl = new mySSLServerSocket(portNumber);
new mySSLServerSocket(portNumber);
+ fail("IOException Expected when opening an already opened port");
} catch (IOException ioe) {
+ // expected
} catch (Exception ex) {
fail("Unexpected exception was thrown " + ex);
}
@@ -209,7 +198,6 @@ public class SSLServerSocketTest extends TestCase {
try {
ssl = new mySSLServerSocket(portNumber, 1);
- assertNotNull(ssl);
assertEquals(portNumber, ssl.getLocalPort());
} catch (Exception ex) {
fail("Unexpected exception was thrown");
@@ -220,6 +208,7 @@ public class SSLServerSocketTest extends TestCase {
ssl = new mySSLServerSocket(port_invalid[i], 1);
fail("IllegalArgumentException should be thrown");
} catch (IllegalArgumentException iae) {
+ // expected
} catch (Exception e) {
fail(e + " was thrown instead of IllegalArgumentException");
}
@@ -251,7 +240,6 @@ public class SSLServerSocketTest extends TestCase {
try {
ssl = new mySSLServerSocket(portNumber, 0, ia);
- assertNotNull(ssl);
assertEquals(portNumber, ssl.getLocalPort());
} catch (Exception ex) {
fail("Unexpected exception was thrown");
@@ -260,7 +248,6 @@ public class SSLServerSocketTest extends TestCase {
portNumber = Support_PortManager.getNextPort();
try {
ssl = new mySSLServerSocket(portNumber, 0, InetAddress.getLocalHost());
- assertNotNull(ssl);
assertEquals(portNumber, ssl.getLocalPort());
} catch (Exception ex) {
fail("Unexpected exception was thrown");
@@ -271,6 +258,7 @@ public class SSLServerSocketTest extends TestCase {
ssl = new mySSLServerSocket(port_invalid[i], 1, InetAddress.getLocalHost());
fail("IllegalArgumentException should be thrown");
} catch (IllegalArgumentException iae) {
+ // expected
} catch (Exception e) {
fail(e + " was thrown instead of IllegalArgumentException");
}
@@ -286,6 +274,7 @@ public class SSLServerSocketTest extends TestCase {
}
/**
+ * @throws Exception
* @tests javax.net.ssl.SSLServerSocket#getSupportedCipherSuites()
*/
@TestTargetNew(
@@ -294,35 +283,15 @@ public class SSLServerSocketTest extends TestCase {
method = "getSupportedCipherSuites",
args = {}
)
- public void test_getSupportedCipherSuites() {
- String[] pr = {"Suite_1", "Suite_2", "Suite_3"};
- try {
- mySSLServerSocket sss = new mySSLServerSocket();
- try {
- sss.getSupportedCipherSuites();
- } catch (NullPointerException npe) {
- //expected
- }
- sss = new mySSLServerSocket(null, pr);
- try {
- sss.getSupportedCipherSuites();
- } catch (NullPointerException npe) {
- //expected
- }
- sss = new mySSLServerSocket(new String[0], new String[0]);
- assertNull("Not NULL result", sss.getSupportedCipherSuites());
- sss = new mySSLServerSocket(null, pr);
- String[] res = sss.getSupportedCipherSuites();
- assertNotNull("NULL result", res);
- if (!res.equals(pr)) {
- fail("Returned result was incorrect");
- }
- } catch (Exception e) {
- fail("Unexpected exception " + e);
- }
+ public void test_getSupportedCipherSuites() throws Exception {
+ SSLServerSocket sss = getSSLServerSocket();
+ String[] res = sss.getSupportedCipherSuites();
+ assertNotNull("NULL result", res);
+ assertTrue("no supported cipher suites available.", res.length > 0);
}
-
+
/**
+ * @throws IOException
* @tests javax.net.ssl.SSLServerSocket#getEnabledCipherSuites()
* @tests javax.net.ssl.SSLServerSocket#setEnabledCipherSuites(String[] suites)
*/
@@ -340,33 +309,29 @@ public class SSLServerSocketTest extends TestCase {
args = {String[].class}
)
})
- public void test_EnabledCipherSuites() {
- String[] pr1 = {"Suite_1", "Suite_2", "Suite_3"};
- String[] pr2 = {"Suite_1", "Suite_2"};
+ public void test_EnabledCipherSuites() throws Exception {
+ SSLServerSocket sss = getSSLServerSocket();
try {
- mySSLServerSocket sss = new mySSLServerSocket(null, pr1);
- try {
- sss.setEnabledCipherSuites(null);
- } catch (IllegalArgumentException iae) {
- //expected
- }
- try {
- sss.setEnabledCipherSuites(pr2);
- } catch (IllegalArgumentException iae) {
- //expected
- }
- sss.setEnabledCipherSuites(pr1);
- String[] res = sss.getEnabledCipherSuites();
- assertNotNull("NULL result", res);
- if (!res.equals(pr1)) {
- fail("Returned result was incorrect");
- }
- } catch (Exception e) {
- fail("Unexpected exception " + e);
+ sss.setEnabledCipherSuites(null);
+ } catch (IllegalArgumentException iae) {
+ //expected
}
+ String[] unsupportedCipherSuites = {"unsupported"};
+ try {
+ sss.setEnabledCipherSuites(unsupportedCipherSuites);
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
+ int count = sss.getSupportedCipherSuites().length;
+ assertTrue("No supported cipher suites", count > 0);
+ sss.setEnabledCipherSuites(sss.getSupportedCipherSuites());
+ String[] res = sss.getEnabledCipherSuites();
+ assertNotNull("NULL result", res);
+ assertTrue("No enabled cipher suites.", res.length == count);
}
/**
+ * @throws IOException
* @tests javax.net.ssl.SSLServerSocket#getSupportedProtocols()
*/
@TestTargetNew(
@@ -375,35 +340,15 @@ public class SSLServerSocketTest extends TestCase {
method = "getSupportedProtocols",
args = {}
)
- public void test_getSupportedProtocols() {
- String[] pr = {"Protocol_1", "Protocol_2", "Protocol_3"};
- try {
- mySSLServerSocket sss = new mySSLServerSocket();
- try {
- sss.getSupportedProtocols();
- } catch (NullPointerException npe) {
- //expected
- }
- sss = new mySSLServerSocket(null, null);
- try {
- sss.getSupportedProtocols();
- } catch (NullPointerException npe) {
- //expected
- }
- sss = new mySSLServerSocket(new String[0], null);
- assertNull("Not NULL result", sss.getSupportedProtocols());
- sss = new mySSLServerSocket(pr, null);
- String[] res = sss.getSupportedProtocols();
- assertNotNull("NULL result", res);
- if (!res.equals(pr)) {
- fail("Returned result was incorrect");
- }
- } catch (Exception e) {
- fail("Unexpected exception " + e);
- }
+ public void test_getSupportedProtocols() throws Exception {
+ SSLServerSocket sss = getSSLServerSocket();
+ String[] res = sss.getSupportedCipherSuites();
+ assertNotNull("NULL result", res);
+ assertTrue("no supported protocols available.", res.length > 0);
}
/**
+ * @throws IOException
* @tests javax.net.ssl.SSLServerSocket#getEnabledProtocols()
* @tests javax.net.ssl.SSLServerSocket#setEnabledProtocols(String[] protocols)
*/
@@ -420,34 +365,31 @@ public class SSLServerSocketTest extends TestCase {
method = "getEnabledProtocols",
args = {}
)
- })
- public void test_EnabledProtocols() {
- String[] pr1 = {"Protocol_1", "Protocol_2", "Protocol_3"};
- String[] pr2 = {"Protocol_1", "Protocol_2"};
+ })
+ @KnownFailure("Wrong check in SSLServerSocket. Has been fixed in Donutburger")
+ public void test_EnabledProtocols() throws Exception {
+ SSLServerSocket sss = getSSLServerSocket();
try {
- mySSLServerSocket sss = new mySSLServerSocket(pr1, null);
- try {
- sss.setEnabledProtocols(null);
- } catch (IllegalArgumentException iae) {
- //expected
- }
- try {
- sss.setEnabledProtocols(pr2);
- } catch (IllegalArgumentException iae) {
- //expected
- }
- sss.setEnabledProtocols(pr1);
- String[] res = sss.getEnabledProtocols();
- assertNotNull("NULL result", res);
- if (!res.equals(pr1)) {
- fail("Returned result was incorrect");
- }
- } catch (Exception e) {
- fail("Unexpected exception " + e);
+ sss.setEnabledProtocols(null);
+ } catch (IllegalArgumentException iae) {
+ //expected
}
+ String[] unsupportedProtocols = {"unsupported"};
+ try {
+ sss.setEnabledProtocols(unsupportedProtocols);
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
+ int count = sss.getSupportedProtocols().length;
+ assertTrue("No supported protocols", count > 0);
+ sss.setEnabledProtocols(sss.getSupportedProtocols());
+ String[] res = sss.getEnabledProtocols();
+ assertNotNull("NULL result", res);
+ assertTrue("no enabled protocols.", res.length == count);
}
/**
+ * @throws IOException
* @tests javax.net.ssl.SSLServerSocket#setEnableSessionCreation(boolean flag)
* @tests javax.net.ssl.SSLServerSocket#getEnableSessionCreation()
*/
@@ -465,20 +407,17 @@ public class SSLServerSocketTest extends TestCase {
args = {boolean.class}
)
})
- public void test_EnableSessionCreation() {
- try {
- mySSLServerSocket sss = new mySSLServerSocket();
- assertTrue(sss.getEnableSessionCreation());
- sss.setEnableSessionCreation(false);
- assertFalse(sss.getEnableSessionCreation());
- sss.setEnableSessionCreation(true);
- assertTrue(sss.getEnableSessionCreation());
- } catch (Exception e) {
- fail("Unexpected exception " + e);
- }
+ public void test_EnableSessionCreation() throws Exception {
+ SSLServerSocket sss = getSSLServerSocket();
+ assertTrue(sss.getEnableSessionCreation());
+ sss.setEnableSessionCreation(false);
+ assertFalse(sss.getEnableSessionCreation());
+ sss.setEnableSessionCreation(true);
+ assertTrue(sss.getEnableSessionCreation());
}
/**
+ * @throws IOException
* @tests javax.net.ssl.SSLServerSocket#setNeedClientAuth(boolean need)
* @tests javax.net.ssl.SSLServerSocket#getNeedClientAuthCreation()
*/
@@ -496,19 +435,16 @@ public class SSLServerSocketTest extends TestCase {
args = {}
)
})
- public void test_NeedClientAuth() {
- try {
- mySSLServerSocket sss = new mySSLServerSocket();
- sss.setNeedClientAuth(true);
- assertTrue(sss.getNeedClientAuth());
- sss.setNeedClientAuth(false);
- assertFalse(sss.getNeedClientAuth());
- } catch (Exception e) {
- fail("Unexpected exception " + e);
- }
+ public void test_NeedClientAuth() throws Exception {
+ SSLServerSocket sss = getSSLServerSocket();
+ sss.setNeedClientAuth(true);
+ assertTrue(sss.getNeedClientAuth());
+ sss.setNeedClientAuth(false);
+ assertFalse(sss.getNeedClientAuth());
}
/**
+ * @throws IOException
* @tests javax.net.ssl.SSLServerSocket#getUseClientMode()
* @tests javax.net.ssl.SSLServerSocket#setUseClientMode(boolean mode)
*/
@@ -526,19 +462,16 @@ public class SSLServerSocketTest extends TestCase {
args = {boolean.class}
)
})
- public void test_UseClientMode() {
- try {
- mySSLServerSocket sss = new mySSLServerSocket();
- sss.setUseClientMode(false);
- assertFalse(sss.getUseClientMode());
- sss.setUseClientMode(true);
- assertTrue(sss.getUseClientMode());
- } catch (Exception e) {
- fail("Unexpected exception " + e);
- }
+ public void test_UseClientMode() throws Exception {
+ SSLServerSocket sss = getSSLServerSocket();
+ sss.setUseClientMode(false);
+ assertFalse(sss.getUseClientMode());
+ sss.setUseClientMode(true);
+ assertTrue(sss.getUseClientMode());
}
/**
+ * @throws IOException
* @tests javax.net.ssl.SSLServerSocket#setWantClientAuth(boolean want)
* @tests javax.net.ssl.SSLServerSocket#getWantClientAuthCreation()
*/
@@ -556,15 +489,102 @@ public class SSLServerSocketTest extends TestCase {
args = {boolean.class}
)
})
- public void test_WantClientAuth() {
- try {
- mySSLServerSocket sss = new mySSLServerSocket();
- sss.setWantClientAuth(true);
- assertTrue(sss.getWantClientAuth());
- sss.setWantClientAuth(false);
- assertFalse(sss.getWantClientAuth());
- } catch (Exception e) {
- fail("Unexpected exception " + e);
- }
+ public void test_WantClientAuth() throws Exception {
+ SSLServerSocket sss = getSSLServerSocket();
+ sss.setWantClientAuth(true);
+ assertTrue(sss.getWantClientAuth());
+ sss.setWantClientAuth(false);
+ assertFalse(sss.getWantClientAuth());
+ }
+
+
+ /**
+ * Defines the keystore contents for the server, BKS version. Holds just a
+ * single self-generated key. The subject name is "Test Server".
+ */
+ private static final String SERVER_KEYS_BKS =
+ "AAAAAQAAABQDkebzoP1XwqyWKRCJEpn/t8dqIQAABDkEAAVteWtleQAAARpYl20nAAAAAQAFWC41" +
+ "MDkAAAJNMIICSTCCAbKgAwIBAgIESEfU1jANBgkqhkiG9w0BAQUFADBpMQswCQYDVQQGEwJVUzET" +
+ "MBEGA1UECBMKQ2FsaWZvcm5pYTEMMAoGA1UEBxMDTVRWMQ8wDQYDVQQKEwZHb29nbGUxEDAOBgNV" +
+ "BAsTB0FuZHJvaWQxFDASBgNVBAMTC1Rlc3QgU2VydmVyMB4XDTA4MDYwNTExNTgxNFoXDTA4MDkw" +
+ "MzExNTgxNFowaTELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExDDAKBgNVBAcTA01U" +
+ "VjEPMA0GA1UEChMGR29vZ2xlMRAwDgYDVQQLEwdBbmRyb2lkMRQwEgYDVQQDEwtUZXN0IFNlcnZl" +
+ "cjCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA0LIdKaIr9/vsTq8BZlA3R+NFWRaH4lGsTAQy" +
+ "DPMF9ZqEDOaL6DJuu0colSBBBQ85hQTPa9m9nyJoN3pEi1hgamqOvQIWcXBk+SOpUGRZZFXwniJV" +
+ "zDKU5nE9MYgn2B9AoiH3CSuMz6HRqgVaqtppIe1jhukMc/kHVJvlKRNy9XMCAwEAATANBgkqhkiG" +
+ "9w0BAQUFAAOBgQC7yBmJ9O/eWDGtSH9BH0R3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XYuSBfhDXJSeddUkl" +
+ "k1ufZyOOcskeInQge7jzaRfmKg3U94r+spMEvb0AzDQVOKvjjo1ivxMSgFRZaDb/4qw=";
+
+ /**
+ * Defines the keystore contents for the server, JKS version. Holds just a
+ * single self-generated key. The subject name is "Test Server".
+ */
+ private static final String SERVER_KEYS_JKS =
+ "/u3+7QAAAAIAAAABAAAAAQAFbXlrZXkAAAEaWFfBeAAAArowggK2MA4GCisGAQQBKgIRAQEFAASC" +
+ "AqI2kp5XjnF8YZkhcF92YsJNQkvsmH7zqMM87j23zSoV4DwyE3XeC/gZWq1ToScIhoqZkzlbWcu4" +
+ "T/Zfc/DrfGk/rKbBL1uWKGZ8fMtlZk8KoAhxZk1JSyJvdkyKxqmzUbxk1OFMlN2VJNu97FPVH+du" +
+ "dvjTvmpdoM81INWBW/1fZJeQeDvn4mMbbe0IxgpiLnI9WSevlaDP/sm1X3iO9yEyzHLL+M5Erspo" +
+ "Cwa558fOu5DdsICMXhvDQxjWFKFhPHnKtGe+VvwkG9/bAaDgx3kfhk0w5zvdnkKb+8Ed9ylNRzdk" +
+ "ocAa/mxlMTOsTvDKXjjsBupNPIIj7OP4GNnZaxkJjSs98pEO67op1GX2qhy6FSOPNuq8k/65HzUc" +
+ "PYn6voEeh6vm02U/sjEnzRevQ2+2wXoAdp0EwtQ/DlMe+NvcwPGWKuMgX4A4L93DZGb04N2VmAU3" +
+ "YLOtZwTO0LbuWrcCM/q99G/7LcczkxIVrO2I/rh8RXVczlf9QzcrFObFv4ATuspWJ8xG7DhsMbnk" +
+ "rT94Pq6TogYeoz8o8ZMykesAqN6mt/9+ToIemmXv+e+KU1hI5oLwWMnUG6dXM6hIvrULY6o+QCPH" +
+ "172YQJMa+68HAeS+itBTAF4Clm/bLn6reHCGGU6vNdwU0lYldpiOj9cB3t+u2UuLo6tiFWjLf5Zs" +
+ "EQJETd4g/EK9nHxJn0GAKrWnTw7pEHQJ08elzUuy04C/jEEG+4QXU1InzS4o/kR0Sqz2WTGD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D = "android";
+
+ /**
+ * Loads a keystore from a base64-encoded String. Returns the KeyManager[]
+ * for the result.
+ */
+ private KeyManager[] getKeyManagers() throws Exception {
+ String keys = (useBKS ? SERVER_KEYS_BKS : SERVER_KEYS_JKS);
+ byte[] bytes = new Base64().decode(keys.getBytes());
+ InputStream inputStream = new ByteArrayInputStream(bytes);
+
+ KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
+ keyStore.load(inputStream, PASSWORD.toCharArray());
+ inputStream.close();
+
+ String algorithm = KeyManagerFactory.getDefaultAlgorithm();
+ KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(algorithm);
+ keyManagerFactory.init(keyStore, PASSWORD.toCharArray());
+
+ return keyManagerFactory.getKeyManagers();
+ }
+
+ private SSLServerSocket getSSLServerSocket() throws Exception {
+ SSLContext context = SSLContext.getInstance("TLS");
+ context.init(getKeyManagers(), null, null);
+ SSLServerSocket sss = (SSLServerSocket) context.getServerSocketFactory()
+ .createServerSocket();
+ return sss;
}
}
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionBindingListenerTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionBindingListenerTest.java
index c640bd5..566ff3c 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionBindingListenerTest.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionBindingListenerTest.java
@@ -17,14 +17,21 @@
package tests.api.javax.net.ssl;
+import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
+import javax.net.ssl.SSLServerSocket;
+import javax.net.ssl.SSLServerSocketFactory;
+import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSessionBindingEvent;
import javax.net.ssl.SSLSessionBindingListener;
+import javax.net.ssl.SSLSocket;
+import javax.net.ssl.SSLSocketFactory;
-import org.apache.harmony.xnet.tests.support.mySSLSession;
+import java.io.IOException;
+import java.net.UnknownHostException;
import junit.framework.TestCase;
@@ -37,8 +44,8 @@ public class SSLSessionBindingListenerTest extends TestCase {
public class mySSLSessionBindingListener implements SSLSessionBindingListener {
- private boolean boundDone = false;
- private boolean unboundDone = false;
+ public boolean boundDone = false;
+ public boolean unboundDone = false;
mySSLSessionBindingListener() {
}
@@ -52,6 +59,9 @@ public class SSLSessionBindingListenerTest extends TestCase {
}
/**
+ * @throws IOException
+ * @throws UnknownHostException
+ * @throws InterruptedException
* @tests javax.net.ssl.SSLSessionBindingListener#valueBound(SSLSessionBindingEvent event)
*/
@TestTargetNew(
@@ -60,18 +70,19 @@ public class SSLSessionBindingListenerTest extends TestCase {
method = "valueBound",
args = {SSLSessionBindingEvent.class}
)
- public void test_valueBound() {
- mySSLSession ss = new mySSLSession("localhost", 1080, null);
+ public void test_valueBound() throws UnknownHostException, IOException,
+ InterruptedException {
+ SSLSocket sock = (SSLSocket) SSLSocketFactory.getDefault()
+ .createSocket();
+ SSLSession ss = sock.getSession();
mySSLSessionBindingListener sbl = new mySSLSessionBindingListener();
- SSLSessionBindingEvent event = new SSLSessionBindingEvent(ss, "Name_01");
- try {
- sbl.valueBound(event);
- } catch (Exception e) {
- fail("Unexpected exception: " + e);
- }
+ ss.putValue("test", sbl);
+ assertTrue("valueBound was not called.", sbl.boundDone);
}
/**
+ * @throws IOException
+ * @throws UnknownHostException
* @tests javax.net.ssl.SSLSessionBindingListener#valueUnbound(SSLSessionBindingEvent event)
*/
@TestTargetNew(
@@ -80,15 +91,14 @@ public class SSLSessionBindingListenerTest extends TestCase {
method = "valueUnbound",
args = {SSLSessionBindingEvent.class}
)
- public void test_valueUnbound() {
- mySSLSession ss = new mySSLSession("localhost", 1080, null);
+ @KnownFailure("this will be fixed in donutburger")
+ public void test_valueUnbound() throws UnknownHostException, IOException {
+ SSLSocket sock = (SSLSocket) SSLSocketFactory.getDefault()
+ .createSocket();
+ SSLSession ss = sock.getSession();
mySSLSessionBindingListener sbl = new mySSLSessionBindingListener();
- SSLSessionBindingEvent event = new SSLSessionBindingEvent(ss, "Name_01");
- try {
- sbl.valueUnbound(event);
- } catch (Exception e) {
- fail("Unexpected exception: " + e);
- }
+ ss.putValue("test", sbl);
+ ss.removeValue("test");
+ assertTrue("valueUnbound was not called.", sbl.unboundDone);
}
-
}
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionContextTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionContextTest.java
index 293f5b1..75f808b 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionContextTest.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionContextTest.java
@@ -1,5 +1,6 @@
package tests.api.javax.net.ssl;
+import dalvik.annotation.BrokenTest;
import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
@@ -7,8 +8,10 @@ import dalvik.annotation.TestTargetClass;
import junit.framework.TestCase;
+import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSessionContext;
-import org.apache.harmony.xnet.tests.support.SSLSessionContextImpl;
+
+import java.security.NoSuchAlgorithmException;
/**
* Tests for <code>SSLSessionContext</code> class constructors and methods.
@@ -17,6 +20,7 @@ import org.apache.harmony.xnet.tests.support.SSLSessionContextImpl;
public class SSLSessionContextTest extends TestCase {
/**
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.SSLSessionContex#getSessionCacheSize()
* @tests javax.net.ssl.SSLSessionContex#setSessionCacheSize(int size)
*/
@@ -34,17 +38,14 @@ public class SSLSessionContextTest extends TestCase {
args = {int.class}
)
})
- public final void test_sessionCacheSize() {
- SSLSessionContextImpl sc = new SSLSessionContextImpl();
- try {
- assertEquals("0 wasn't returned", 0, sc.getSessionCacheSize());
- sc.setSessionCacheSize(10);
- assertEquals("10 wasn't returned", 10, sc.getSessionCacheSize());
- sc.setSessionCacheSize(5);
- assertEquals("5 wasn't returned", 5, sc.getSessionCacheSize());
- } catch (Exception e) {
- fail("Unexpected exception");
- }
+ @BrokenTest("getClientSessionContext returns null on android but does not on RI")
+ public final void test_sessionCacheSize() throws NoSuchAlgorithmException {
+ SSLSessionContext sc = SSLContext.getInstance("TLS")
+ .getClientSessionContext();
+ sc.setSessionCacheSize(10);
+ assertEquals("10 wasn't returned", 10, sc.getSessionCacheSize());
+ sc.setSessionCacheSize(5);
+ assertEquals("5 wasn't returned", 5, sc.getSessionCacheSize());
try {
sc.setSessionCacheSize(-1);
@@ -55,6 +56,7 @@ public class SSLSessionContextTest extends TestCase {
}
/**
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.SSLSessionContex#getSessionTimeout()
* @tests javax.net.ssl.SSLSessionContex#setSessionTimeout(int seconds)
*/
@@ -72,17 +74,14 @@ public class SSLSessionContextTest extends TestCase {
args = {int.class}
)
})
- public final void test_sessionTimeout() {
- SSLSessionContextImpl sc = new SSLSessionContextImpl();
- try {
- assertEquals("0 wasn't returned", 0, sc.getSessionTimeout());
- sc.setSessionTimeout(100);
- assertEquals("100 wasn't returned", 100, sc.getSessionTimeout());
- sc.setSessionTimeout(5000);
- assertEquals("5000 wasn't returned", 5000, sc.getSessionTimeout());
- } catch (Exception e) {
- fail("Unexpected exception");
- }
+ @BrokenTest("getClientSessionContext returns null on android but does not on RI")
+ public final void test_sessionTimeout() throws NoSuchAlgorithmException {
+ SSLSessionContext sc = SSLContext.getInstance("TLS")
+ .getClientSessionContext();
+ sc.setSessionTimeout(100);
+ assertEquals("100 wasn't returned", 100, sc.getSessionTimeout());
+ sc.setSessionTimeout(5000);
+ assertEquals("5000 wasn't returned", 5000, sc.getSessionTimeout());
try {
sc.setSessionTimeout(-1);
@@ -93,6 +92,7 @@ public class SSLSessionContextTest extends TestCase {
}
/**
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.SSLSessionContex#getSession(byte[] sessionId)
*/
@TestTargetNew(
@@ -101,17 +101,20 @@ public class SSLSessionContextTest extends TestCase {
method = "getSession",
args = {byte[].class}
)
- public final void test_getSession() {
- SSLSessionContextImpl sc = new SSLSessionContextImpl();
+ @BrokenTest("getClientSessionContext returns null on android but does not on RI")
+ public final void test_getSession() throws NoSuchAlgorithmException {
+ SSLSessionContext sc = SSLContext.getInstance("TLS")
+ .getClientSessionContext();
try {
- assertNull(sc.getSession(null));
- assertNull(sc.getSession(new byte[5]));
- } catch (Exception e) {
- fail("Unexpected exception");
+ sc.getSession(null);
+ } catch (NullPointerException e) {
+ // expected
}
+ assertNull(sc.getSession(new byte[5]));
}
/**
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.SSLSessionContex#getIds()
*/
@TestTargetNew(
@@ -120,13 +123,11 @@ public class SSLSessionContextTest extends TestCase {
method = "getIds",
args = {}
)
- public final void test_getIds() {
- SSLSessionContextImpl sc = new SSLSessionContextImpl();
- try {
- assertNull(sc.getIds());
- } catch (Exception e) {
- fail("Unexpected exception");
- }
+ @BrokenTest("getClientSessionContext returns null on android but does not on RI")
+ public final void test_getIds() throws NoSuchAlgorithmException {
+ SSLSessionContext sc = SSLContext.getInstance("TLS")
+ .getClientSessionContext();
+ assertFalse(sc.getIds().hasMoreElements());
}
} \ No newline at end of file
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionTest.java
index 123998d..46ec1d2 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionTest.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionTest.java
@@ -17,23 +17,41 @@
package tests.api.javax.net.ssl;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
+import dalvik.annotation.AndroidOnly;
+import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
-import javax.net.ssl.SSLSession;
-import javax.net.ssl.SSLPeerUnverifiedException;
-import javax.net.ssl.SSLSessionBindingListener;
-import javax.net.ssl.SSLSessionBindingEvent;
+import junit.framework.TestCase;
+
+import org.apache.harmony.luni.util.Base64;
+
+import tests.api.javax.net.ssl.HandshakeCompletedEventTest.MyHandshakeListener;
+import tests.api.javax.net.ssl.HandshakeCompletedEventTest.TestTrustManager;
+import tests.support.Support_PortManager;
import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.security.KeyStore;
+import java.security.Principal;
import java.security.cert.Certificate;
-import javax.security.cert.X509Certificate;
+import java.util.Date;
-import junit.framework.TestCase;
-
-import org.apache.harmony.xnet.tests.support.mySSLSession;
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLPeerUnverifiedException;
+import javax.net.ssl.SSLServerSocket;
+import javax.net.ssl.SSLSession;
+import javax.net.ssl.SSLSocket;
+import javax.net.ssl.SSLSessionBindingEvent;
+import javax.net.ssl.SSLSessionBindingListener;
+import javax.net.ssl.TrustManager;
+import javax.security.cert.X509Certificate;
/**
* Tests for SSLSession class
@@ -41,23 +59,9 @@ import org.apache.harmony.xnet.tests.support.mySSLSession;
*/
@TestTargetClass(SSLSession.class)
public class SSLSessionTest extends TestCase {
-
- String certificate = "-----BEGIN CERTIFICATE-----\n"
- + "MIICZTCCAdICBQL3AAC2MA0GCSqGSIb3DQEBAgUAMF8xCzAJBgNVBAYTAlVTMSAw\n"
- + "HgYDVQQKExdSU0EgRGF0YSBTZWN1cml0eSwgSW5jLjEuMCwGA1UECxMlU2VjdXJl\n"
- + "IFNlcnZlciBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw05NzAyMjAwMDAwMDBa\n"
- + "Fw05ODAyMjAyMzU5NTlaMIGWMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZv\n"
- + "cm5pYTESMBAGA1UEBxMJUGFsbyBBbHRvMR8wHQYDVQQKExZTdW4gTWljcm9zeXN0\n"
- + "ZW1zLCBJbmMuMSEwHwYDVQQLExhUZXN0IGFuZCBFdmFsdWF0aW9uIE9ubHkxGjAY\n"
- + "BgNVBAMTEWFyZ29uLmVuZy5zdW4uY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB\n"
- + "iQKBgQCofmdY+PiUWN01FOzEewf+GaG+lFf132UpzATmYJkA4AEA/juW7jSi+LJk\n"
- + "wJKi5GO4RyZoyimAL/5yIWDV6l1KlvxyKslr0REhMBaD/3Z3EsLTTEf5gVrQS6sT\n"
- + "WMoSZAyzB39kFfsB6oUXNtV8+UKKxSxKbxvhQn267PeCz5VX2QIDAQABMA0GCSqG\n"
- + "SIb3DQEBAgUAA34AXl3at6luiV/7I9MN5CXYoPJYI8Bcdc1hBagJvTMcmlqL2uOZ\n"
- + "H9T5hNMEL9Tk6aI7yZPXcw/xI2K6pOR/FrMp0UwJmdxX7ljV6ZtUZf7pY492UqwC\n"
- + "1777XQ9UEZyrKJvF5ntleeO0ayBqLGVKCWzWZX9YsXCpv47FNLZbupE=\n"
- + "-----END CERTIFICATE-----\n";
-
+
+ // set to true if on Android, false if on RI
+ boolean useBKS = true;
/**
* @tests javax.net.ssl.SSLSession#getPeerHost()
@@ -77,11 +81,12 @@ public class SSLSessionTest extends TestCase {
args = {}
)
})
+ @AndroidOnly("Uses bks key store. Change useBKS to false to run on the RI")
public void test_getPeerHost() {
- mySSLSession s = new mySSLSession("localhost", 1080, null);
+ SSLSession s = clientSession;
try {
- assertEquals(s.getPeerHost(), "localhost");
- assertEquals(s.getPeerPort(), 1080);
+ assertEquals(s.getPeerHost(), InetAddress.getLocalHost().getHostName());
+ assertEquals(s.getPeerPort(), port);
} catch (Exception ex) {
fail("Unexpected exception " + ex);
}
@@ -105,12 +110,13 @@ public class SSLSessionTest extends TestCase {
args = {}
)
})
+ @AndroidOnly("Uses bks key store. Change useBKS to false to run on the RI")
public void test_invalidate() {
- mySSLSession s = new mySSLSession("localhost", 1080, null);
+ SSLSession s = clientSession;
try {
- assertFalse(s.isValid());
- s.invalidate();
assertTrue(s.isValid());
+ s.invalidate();
+ assertFalse(s.isValid());
} catch (Exception ex) {
fail("Unexpected exception " + ex);
}
@@ -125,10 +131,17 @@ public class SSLSessionTest extends TestCase {
method = "getPeerPrincipal",
args = {}
)
+ @AndroidOnly("Uses bks key store. Change useBKS to false to run on the RI")
public void test_getPeerPrincipal() {
- mySSLSession s = new mySSLSession("localhost", 1080, null);
try {
- assertNull(s.getPeerPrincipal());
+ Principal p1 = clientSession.getPeerPrincipal();
+ KeyStore store = server.getStore();
+ Certificate cert = store.getCertificate("mykey");
+ X509Certificate c = X509Certificate.getInstance(cert.getEncoded());
+ Principal p2 = c.getSubjectDN();
+ String name2 = p2.getName().replaceAll(" ", "");
+ String name1 = p1.getName().replaceAll(" ", "");
+ assertEquals(name2, name1);
} catch (Exception ex) {
fail("Unexpected exception " + ex);
}
@@ -143,10 +156,10 @@ public class SSLSessionTest extends TestCase {
method = "getApplicationBufferSize",
args = {}
)
+ @AndroidOnly("Uses bks key store. Change useBKS to false to run on the RI")
public void test_getApplicationBufferSize() {
- mySSLSession s = new mySSLSession("localhost", 1080, null);
try {
- assertEquals(s.getApplicationBufferSize(), 1234567);
+ assertTrue(clientSession.getApplicationBufferSize() > 0);
} catch (Exception ex) {
fail("Unexpected exception " + ex);
}
@@ -161,10 +174,10 @@ public class SSLSessionTest extends TestCase {
method = "getCipherSuite",
args = {}
)
+ @AndroidOnly("Uses bks key store. Change useBKS to false to run on the RI")
public void test_getCipherSuite() {
- mySSLSession s = new mySSLSession("localhost", 1080, null);
try {
- assertEquals(s.getCipherSuite(), "SuiteName");
+ assertEquals(cipherSuite, clientSession.getCipherSuite());
} catch (Exception ex) {
fail("Unexpected exception " + ex);
}
@@ -179,10 +192,13 @@ public class SSLSessionTest extends TestCase {
method = "getCreationTime",
args = {}
)
+ @KnownFailure("Time returned is corrupted")
+ @AndroidOnly("Uses bks key store. Change useBKS to false to run on the RI")
public void test_getCreationTime() {
- mySSLSession s = new mySSLSession("localhost", 1080, null);
try {
- assertEquals(s.getCreationTime(), 1000l);
+ // check if creation time was in the last 10 seconds
+ long diff = new Date().getTime() - clientSession.getCreationTime();
+ assertTrue (diff < 10000);
} catch (Exception ex) {
fail("Unexpected exception " + ex);
}
@@ -197,11 +213,13 @@ public class SSLSessionTest extends TestCase {
method = "getId",
args = {}
)
+ @AndroidOnly("Uses bks key store. Change useBKS to false to run on the RI")
public void test_getId() {
- byte[] data = {5, 10, 15};
- mySSLSession s = new mySSLSession("localhost", 1080, data);
+ byte[] id = clientSession.getId();
try {
- assertEquals(s.getId(), data);
+ SSLSession sess =
+ clientSslContext.getClientSessionContext().getSession(id);
+ assertEquals(clientSession, sess);
} catch (Exception ex) {
fail("Unexpected exception " + ex);
}
@@ -216,10 +234,13 @@ public class SSLSessionTest extends TestCase {
method = "getLastAccessedTime",
args = {}
)
+ @KnownFailure("Time returned is corrupted")
+ @AndroidOnly("Uses bks key store. Change useBKS to false to run on the RI")
public void test_getLastAccessedTime() {
- mySSLSession s = new mySSLSession("localhost", 1080, null);
try {
- assertEquals(s.getLastAccessedTime(), 2000l);
+ // check if last access time was in the last 10 seconds
+ long diff = new Date().getTime() - clientSession.getLastAccessedTime();
+ assertTrue (diff < 10000);
} catch (Exception ex) {
fail("Unexpected exception " + ex);
}
@@ -234,10 +255,13 @@ public class SSLSessionTest extends TestCase {
method = "getLocalCertificates",
args = {}
)
+ @AndroidOnly("Uses bks key store. Change useBKS to false to run on the RI")
public void test_getLocalCertificates() {
- mySSLSession s = new mySSLSession("localhost", 1080, null);
try {
- assertNull(s.getLocalCertificates());
+ KeyStore store = client.getStore();
+ Certificate cert = store.getCertificate("mykey");
+ Certificate[] certs = clientSession.getLocalCertificates();
+ assertEquals(cert, certs[0]);
} catch (Exception ex) {
fail("Unexpected exception " + ex);
}
@@ -252,10 +276,18 @@ public class SSLSessionTest extends TestCase {
method = "getLocalPrincipal",
args = {}
)
+ @KnownFailure("getLocalPrincipal returns null")
+ @AndroidOnly("Uses bks key store. Change useBKS to false to run on the RI")
public void test_getLocalPrincipal() {
- mySSLSession s = new mySSLSession("localhost", 1080, null);
try {
- assertNull(s.getLocalPrincipal());
+ Principal p1 = clientSession.getLocalPrincipal();
+ KeyStore store = client.getStore();
+ Certificate cert = store.getCertificate("mykey");
+ X509Certificate c = X509Certificate.getInstance(cert.getEncoded());
+ Principal p2 = c.getSubjectDN();
+ String name2 = p2.getName().replaceAll(" ", "");
+ String name1 = p1.getName().replaceAll(" ", "");
+ assertEquals(name2, name1);
} catch (Exception ex) {
fail("Unexpected exception " + ex);
}
@@ -270,10 +302,10 @@ public class SSLSessionTest extends TestCase {
method = "getPacketBufferSize",
args = {}
)
+ @AndroidOnly("Uses bks key store. Change useBKS to false to run on the RI")
public void test_getPacketBufferSize() {
- mySSLSession s = new mySSLSession("localhost", 1080, null);
try {
- assertEquals(s.getPacketBufferSize(), 12345);
+ assertTrue(clientSession.getPacketBufferSize() > 0);
} catch (Exception ex) {
fail("Unexpected exception " + ex);
}
@@ -283,23 +315,22 @@ public class SSLSessionTest extends TestCase {
* @tests javax.net.ssl.SSLSession#getPeerCertificates()
*/
@TestTargetNew(
- level = TestLevel.COMPLETE,
+ level = TestLevel.SUFFICIENT,
notes = "",
method = "getPeerCertificates",
args = {}
)
+ @AndroidOnly("Uses bks key store. Change useBKS to false to run on the RI")
public void test_getPeerCertificates() {
- mySSLSession s = new mySSLSession("localhost", 1080, null);
+// try {
+// Certificate[] res = clientSession.getPeerCertificates();
+// fail("SSLPeerUnverifiedException wasn't thrown");
+// } catch (SSLPeerUnverifiedException pue) {
+// //expected
+// }
try {
- Certificate[] res = s.getPeerCertificates();
- fail("SSLPeerUnverifiedException wasn't thrown");
- } catch (SSLPeerUnverifiedException pue) {
- //expected
- }
- s = new mySSLSession(null);
- try {
- Certificate[] res = s.getPeerCertificates();
- assertEquals(res.length, 3);
+ Certificate[] res = clientSession.getPeerCertificates();
+ assertTrue(res.length > 0);
} catch (Exception e) {
fail("Unexpected exception: " + e);
}
@@ -309,30 +340,22 @@ public class SSLSessionTest extends TestCase {
* @tests javax.net.ssl.SSLSession#getPeerCertificateChain()
*/
@TestTargetNew(
- level = TestLevel.COMPLETE,
+ level = TestLevel.SUFFICIENT,
notes = "",
method = "getPeerCertificateChain",
args = {}
)
+ @AndroidOnly("Uses bks key store. Change useBKS to false to run on the RI")
public void test_getPeerCertificateChain() {
- ByteArrayInputStream bis = new ByteArrayInputStream(certificate.getBytes());
- mySSLSession s = new mySSLSession("localhost", 1080, null);
- try {
- X509Certificate[] resN = s.getPeerCertificateChain();
- fail("SSLPeerUnverifiedException wasn't thrown");
- } catch (SSLPeerUnverifiedException pue) {
- //expected
- }
+// try {
+// X509Certificate[] resN = clientSession.getPeerCertificateChain();
+// fail("SSLPeerUnverifiedException wasn't thrown");
+// } catch (SSLPeerUnverifiedException pue) {
+// //expected
+// }
try {
- X509Certificate xc = X509Certificate.getInstance(bis);
- X509Certificate[] xcs = {xc};
- s = new mySSLSession(xcs);
- } catch (Exception e) {
- fail(e + " was thrown for configuration");
- }
- try {
- X509Certificate[] res = s.getPeerCertificateChain();
- assertEquals(res.length, 1);
+ X509Certificate[] res = clientSession.getPeerCertificateChain();
+ assertTrue(res.length > 0);
} catch (Exception e) {
fail("Unexpected exception: " + e);
}
@@ -347,10 +370,10 @@ public class SSLSessionTest extends TestCase {
method = "getProtocol",
args = {}
)
+ @AndroidOnly("Uses bks key store. Change useBKS to false to run on the RI")
public void test_getProtocol() {
- mySSLSession s = new mySSLSession("localhost", 1080, null);
try {
- assertEquals(s.getProtocol(), "ProtocolName");
+ assertEquals(clientSession.getProtocol(), "TLSv1");
} catch (Exception e) {
fail("Unexpected exception: " + e);
}
@@ -365,10 +388,11 @@ public class SSLSessionTest extends TestCase {
method = "getSessionContext",
args = {}
)
+ @AndroidOnly("Uses bks key store. Change useBKS to false to run on the RI")
public void test_getSessionContext() {
- mySSLSession s = new mySSLSession("localhost", 1080, null);
try {
- assertNull(s.getSessionContext());
+ assertEquals(clientSslContext.getClientSessionContext(),
+ clientSession.getSessionContext());
} catch (Exception e) {
fail("Unexpected exception: " + e);
}
@@ -399,8 +423,9 @@ public class SSLSessionTest extends TestCase {
args = {}
)
})
+ @AndroidOnly("Uses bks key store. Change useBKS to false to run on the RI")
public void test_putValue() {
- mySSLSession s = new mySSLSession("localhost", 1080, null);
+ SSLSession s = clientSession;
mySSLSessionBindingListener sbl = new mySSLSessionBindingListener();
try {
assertNotNull(s.getValueNames());
@@ -451,8 +476,9 @@ public class SSLSessionTest extends TestCase {
method = "getValue",
args = {String.class}
)
+ @AndroidOnly("Uses bks key store. Change useBKS to false to run on the RI")
public void test_getValue() {
- mySSLSession s = new mySSLSession("localhost", 1080, null);
+ SSLSession s = clientSession;
mySSLSessionBindingListener sbl = new mySSLSessionBindingListener();
try {
@@ -470,8 +496,71 @@ public class SSLSessionTest extends TestCase {
fail("Unexpected exception: " + e);
}
}
+
+ Thread serverThread, clientThread;
+ TestServer server;
+ TestClient client;
+
+ @Override
+ protected void setUp() {
+ port = Support_PortManager.getNextPort();
+ String serverKeys = (useBKS ? SERVER_KEYS_BKS : SERVER_KEYS_JKS);
+ String clientKeys = (useBKS ? CLIENT_KEYS_BKS : CLIENT_KEYS_JKS);
+ server = new TestServer(true,
+ TestServer.CLIENT_AUTH_WANTED, serverKeys);
+ client = new TestClient(true, clientKeys);
+
+ serverThread = new Thread(server);
+ clientThread = new Thread(client);
+
+ serverThread.start();
+ try {
+ Thread.currentThread().sleep(1000);
+ clientThread.start();
+ } catch (InterruptedException e) {
+ fail("Could not create server or cient " + e.getMessage());
+ }
+ while (clientSession == null
+ && server.exception == null
+ && client.exception == null) {
+ try {
+ Thread.currentThread().sleep(500);
+ } catch (InterruptedException e) {
+ fail("couldn't create session");
+ }
+ }
+ assertNull("server thread has a pending exception: " + server.exception,
+ server.exception);
+ assertNull("client thread has a pending exception: " + client.exception,
+ client.exception);
+ assertNotNull("Could not initialize session", clientSession);
+ }
+
+ @Override
+ protected void tearDown() {
+ notFinished = false;
+ try {
+ serverThread.join();
+ } catch (InterruptedException e) {
+ }
+ try {
+ clientThread.join();
+ } catch (InterruptedException e) {
+ }
+
+ // The server must have completed without an exception.
+ if (server.getException() != null) {
+ throw new RuntimeException(server.getException());
+ }
+
+ // The client must have completed without an exception.
+ if (client.getException() != null) {
+ throw new RuntimeException(client.getException());
+ }
+ }
- public class mySSLSessionBindingListener implements SSLSessionBindingListener {
+ public class mySSLSessionBindingListener implements
+ SSLSessionBindingListener {
mySSLSessionBindingListener() {
}
public void valueBound(SSLSessionBindingEvent event) {}
@@ -479,4 +568,308 @@ public class SSLSessionTest extends TestCase {
}
+
+ String cipherSuiteBKS = "AES256-SHA";
+ /**
+ * Defines the keystore contents for the server, BKS version. Holds just a
+ * single self-generated key. The subject name is "Test Server".
+ */
+ private static final String SERVER_KEYS_BKS =
+ "AAAAAQAAABQDkebzoP1XwqyWKRCJEpn/t8dqIQAABDkEAAVteWtleQAAARpYl20nAAAAAQAFWC41" +
+ "MDkAAAJNMIICSTCCAbKgAwIBAgIESEfU1jANBgkqhkiG9w0BAQUFADBpMQswCQYDVQQGEwJVUzET" +
+ "MBEGA1UECBMKQ2FsaWZvcm5pYTEMMAoGA1UEBxMDTVRWMQ8wDQYDVQQKEwZHb29nbGUxEDAOBgNV" +
+ "BAsTB0FuZHJvaWQxFDASBgNVBAMTC1Rlc3QgU2VydmVyMB4XDTA4MDYwNTExNTgxNFoXDTA4MDkw" +
+ "MzExNTgxNFowaTELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExDDAKBgNVBAcTA01U" +
+ "VjEPMA0GA1UEChMGR29vZ2xlMRAwDgYDVQQLEwdBbmRyb2lkMRQwEgYDVQQDEwtUZXN0IFNlcnZl" +
+ "cjCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA0LIdKaIr9/vsTq8BZlA3R+NFWRaH4lGsTAQy" +
+ "DPMF9ZqEDOaL6DJuu0colSB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AapeeCnexhpXhWTs+xDEYSKEiG/camt" +
+ "bhmZc3BcyVJrW23PktSfpBQ6D8ZxoMfF0L7V2GQMaUg+3r7ucrx82kpqotjv0xHghNIm95aBr1Qw" +
+ "1gaEjsC/0wGmmBDg1dTDH+F1p9TInzr3EFuYD0YiQ7YlAHq3cPuyGoLXJ5dXYuSBfhDXJSeddUkl" +
+ "k1ufZyOOcskeInQge7jzaRfmKg3U94r+spMEvb0AzDQVOKvjjo1ivxMSgFRZaDb/4qw=";
+
+ /**
+ * Defines the keystore contents for the client, BKS version. Holds just a
+ * single self-generated key. The subject name is "Test Client".
+ */
+ private static final String CLIENT_KEYS_BKS =
+ "AAAAAQAAABT4Rka6fxbFps98Y5k2VilmbibNkQAABfQEAAVteWtleQAAARpYl+POAAAAAQAFWC41" +
+ "MDkAAAJNMIICSTCCAbKgAwIBAgIESEfU9TANBgkqhkiG9w0BAQUFADBpMQswCQYDVQQGEwJVUzET" +
+ "MBEGA1UECBMKQ2FsaWZvcm5pYTEMMAoGA1UEBxMDTVRWMQ8wDQYDVQQKEwZHb29nbGUxEDAOBgNV" +
+ "BAsTB0FuZHJvaWQxFDASBgNVBAMTC1Rlc3QgQ2xpZW50MB4XDTA4MDYwNTExNTg0NVoXDTA4MDkw" +
+ "MzExNTg0NVowaTELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExDDAKBgNVBAcTA01U" +
+ "VjEPMA0GA1UEChMGR29vZ2xlMRAwDgYDVQQLEwdBbmRyb2lkMRQwEgYDVQQDEwtUZXN0IENsaWVu" +
+ "dDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEApUvmWsQDHPpbDKK13Yez2/q54tTOmRml/qva" +
+ "2K6dZjkjSTW0iRuk7ztaVEvdJpfVIDv1oBsCI51ttyLHROy1epjF+GoL74mJb7fkcd0VOoSOTjtD" +
+ "+3GgZkHPAm5YmUYxiJXqxKKJJqMCTIW46eJaA2nAep9QIwZ14/NFAs4ObV8CA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q5wno9" +
+ "uJk07h3IZnNxE+/IKgeMTP/H4+jmyT4mhsexJ2BFHeiKF1KT/FMcJdSi+ZK5yoNVcYuY8aZbx0Ef" +
+ "lHorCXAmLFB0W6Cz4KPP01nD9YBB4olxiK1t7m0AU9zscdivNiuUaB5OIEr+JuZ6dNw=";
+
+ String cipherSuiteJKS = "SSL_RSA_WITH_RC4_128_MD5";
+ /**
+ * Defines the keystore contents for the server, JKS version. Holds just a
+ * single self-generated key. The subject name is "Test Server".
+ */
+ private static final String SERVER_KEYS_JKS =
+ "/u3+7QAAAAIAAAABAAAAAQAFbXlrZXkAAAEaWFfBeAAAArowggK2MA4GCisGAQQBKgIRAQEFAASC" +
+ "AqI2kp5XjnF8YZkhcF92YsJNQkvsmH7zqMM87j23zSoV4DwyE3XeC/gZWq1ToScIhoqZkzlbWcu4" +
+ "T/Zfc/DrfGk/rKbBL1uWKGZ8fMtlZk8KoAhxZk1JSyJvdkyKxqmzUbxk1OFMlN2VJNu97FPVH+du" +
+ "dvjTvmpdoM81INWBW/1fZJeQeDvn4mMbbe0IxgpiLnI9WSevlaDP/sm1X3iO9yEyzHLL+M5Erspo" +
+ "Cwa558fOu5DdsICMXhvDQxjWFKFhPHnKtGe+VvwkG9/bAaDgx3kfhk0w5zvdnkKb+8Ed9ylNRzdk" +
+ "ocAa/mxlMTOsTvDKXjjsBupNPIIj7OP4GNnZaxkJjSs98pEO67op1GX2qhy6FSOPNuq8k/65HzUc" +
+ "PYn6voEeh6vm02U/sjEnzRevQ2+2wXoAdp0EwtQ/DlMe+NvcwPGWKuMgX4A4L93DZGb04N2VmAU3" +
+ "YLOtZwTO0LbuWrcCM/q99G/7LcczkxIVrO2I/rh8RXVczlf9QzcrFObFv4ATuspWJ8xG7DhsMbnk" +
+ "rT94Pq6TogYeoz8o8ZMykesAqN6mt/9+ToIemmXv+e+KU1hI5oLwWMnUG6dXM6hIvrULY6o+QCPH" +
+ "172YQJMa+68HAeS+itBTAF4Clm/bLn6reHCGGU6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szmzeU5VqzkpSt0j84YWi+TfcHRrfvhLbrlmGITVpY" +
+ "ol5pHLDyqGmDs53pgwipWqsn/nEXEBgj3EoqPeqHbDf7YaP8h/5BSt0=";
+
+ /**
+ * Defines the keystore contents for the client, JKS version. Holds just a
+ * single self-generated key. The subject name is "Test Client".
+ */
+ private static final String CLIENT_KEYS_JKS =
+ "/u3+7QAAAAIAAAABAAAAAQAFbXlrZXkAAAEaWFhyMAAAArkwggK1MA4GCisGAQQBKgIRAQEFAASC" +
+ "AqGVSfXolBStZy4nnRNn4fAr+S7kfU2BS23wwW8uB2Ru3GvtLzlK9q08Gvq/LNqBafjyFTVL5FV5" +
+ "SED/8YomO5a98GpskSeRvytCiTBLJdgGhws5TOGekgIAcBROPGIyOtJPQ0HfOQs+BqgzGDHzHQhw" +
+ "u/8Tm6yQwiP+W/1I9B1QnaEztZA3mhTyMMJsmsFTYroGgAog885D5Cmzd8sYGfxec3R6I+xcmBAY" +
+ "eibR5kGpWwt1R+qMvRrtBqh5r6WSKhCBNax+SJVbtUNRiKyjKccdJg6fGqIWWeivwYTy0OhjA6b4" +
+ "NiZ/ZZs5pxFGWUj/Rlp0RYy8fCF6aw5/5s4Bf4MI6dPSqMG8Hf7sJR91GbcELyzPdM0h5lNavgit" +
+ "QPEzKeuDrGxhY1frJThBsNsS0gxeu+OgfJPEb/H4lpYX5IvuIGbWKcxoO9zq4/fimIZkdA8A+3eY" +
+ "mfDaowvy65NBVQPJSxaOyFhLHfeLqOeCsVENAea02vA7andZHTZehvcrqyKtm+z8ncHGRC2H9H8O" +
+ "jKwKHfxxrYY/jMAKLl00+PBb3kspO+BHI2EcQnQuMw/zr83OR9Meq4TJ0TMuNkApZELAeFckIBbS" +
+ "rBr8NNjAIfjuCTuKHhsTFWiHfk9ZIzigxXagfeDRiyVc6khOuF/bGorj23N2o7Rf3uLoU6PyXWi4" +
+ "uhctR1aL6NzxDoK2PbYCeA9hxbDv8emaVPIzlVwpPK3Ruvv9mkjcOhZ74J8b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 int port;
+ SSLSocket serverSocket;
+ MyHandshakeListener listener;
+ String host = "localhost";
+ boolean notFinished = true;
+ SSLSession clientSession = null;
+ SSLContext clientSslContext = null;
+
+ private String PASSWORD = "android";
+
+ String cipherSuite = (useBKS ? cipherSuiteBKS : cipherSuiteJKS);
+
+ /**
+ * Implements a test SSL socket server. It wait for a connection on a given
+ * port, requests client authentication (if specified), and read 256 bytes
+ * from the socket.
+ */
+ class TestServer implements Runnable {
+
+ public static final int CLIENT_AUTH_NONE = 0;
+
+ public static final int CLIENT_AUTH_WANTED = 1;
+
+ public static final int CLIENT_AUTH_NEEDED = 2;
+
+ private TestTrustManager trustManager;
+
+ private Exception exception;
+
+ String keys;
+
+ private int clientAuth;
+
+ private boolean provideKeys;
+
+ private KeyStore store;
+
+ public TestServer(boolean provideKeys, int clientAuth, String keys) {
+ this.keys = keys;
+ this.clientAuth = clientAuth;
+ this.provideKeys = provideKeys;
+
+ trustManager = new TestTrustManager();
+ }
+
+ public void run() {
+ try {
+ store = provideKeys ? getKeyStore(keys) : null;
+ KeyManager[] keyManagers = store != null ? getKeyManagers(store) : null;
+ TrustManager[] trustManagers = new TrustManager[] { trustManager };
+
+ SSLContext sslContext = SSLContext.getInstance("TLS");
+ sslContext.init(keyManagers, trustManagers, null);
+
+ SSLServerSocket serverSocket = (SSLServerSocket)sslContext
+ .getServerSocketFactory().createServerSocket();
+
+ if (clientAuth == CLIENT_AUTH_WANTED) {
+ serverSocket.setWantClientAuth(true);
+ } else if (clientAuth == CLIENT_AUTH_NEEDED) {
+ serverSocket.setNeedClientAuth(true);
+ } else {
+ serverSocket.setWantClientAuth(false);
+ }
+
+ serverSocket.bind(new InetSocketAddress(port));
+
+ SSLSocket clientSocket = (SSLSocket)serverSocket.accept();
+
+ while (notFinished) {
+ clientSocket.getInputStream().read();
+ }
+
+ clientSocket.close();
+ serverSocket.close();
+
+ } catch (Exception ex) {
+ exception = ex;
+ }
+ }
+
+ public Exception getException() {
+ return exception;
+ }
+
+ public X509Certificate[] getChain() {
+ return trustManager.getChain();
+ }
+
+ public KeyStore getStore() {
+ return store;
+ }
+
+ }
+
+ /**
+ * Implements a test SSL socket client. It open a connection to localhost on
+ * a given port and writes 256 bytes to the socket.
+ */
+ class TestClient implements Runnable {
+
+ private TestTrustManager trustManager;
+
+ private Exception exception;
+
+ private String keys;
+
+ private boolean provideKeys;
+
+ private KeyStore store;
+
+ public TestClient(boolean provideKeys, String keys) {
+ this.keys = keys;
+ this.provideKeys = provideKeys;
+
+ trustManager = new TestTrustManager();
+ }
+
+ public void run() {
+ try {
+ store = provideKeys ? getKeyStore(keys) : null;
+ KeyManager[] keyManagers = store != null ? getKeyManagers(store) : null;
+ TrustManager[] trustManagers = new TrustManager[] { trustManager };
+
+ clientSslContext = SSLContext.getInstance("TLS");
+ clientSslContext.init(keyManagers, trustManagers, null);
+
+ SSLSocket socket = (SSLSocket)clientSslContext.getSocketFactory().createSocket();
+
+ socket.connect(new InetSocketAddress(port));
+
+ clientSession = socket.getSession();
+ while (notFinished) {
+ Thread.currentThread().sleep(500);
+ }
+ socket.close();
+
+ } catch (Exception ex) {
+ exception = ex;
+ }
+ }
+
+ public Exception getException() {
+ return exception;
+ }
+
+ public X509Certificate[] getChain() {
+ return trustManager.getChain();
+ }
+
+ public KeyStore getStore() {
+ return store;
+ }
+ }
+
+ /**
+ * Loads a keystore from a base64-encoded String. Returns the KeyManager[]
+ * for the result.
+ */
+ private KeyStore getKeyStore(String keys) throws Exception {
+ byte[] bytes = new Base64().decode(keys.getBytes());
+ InputStream inputStream = new ByteArrayInputStream(bytes);
+
+ KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
+ keyStore.load(inputStream, PASSWORD.toCharArray());
+ inputStream.close();
+ return keyStore;
+ }
+
+ /**
+ * Loads a keystore from a base64-encoded String. Returns the KeyManager[]
+ * for the result.
+ */
+ private KeyManager[] getKeyManagers(KeyStore keyStore) throws Exception {
+ String algorithm = KeyManagerFactory.getDefaultAlgorithm();
+ KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(algorithm);
+ keyManagerFactory.init(keyStore, PASSWORD.toCharArray());
+
+ return keyManagerFactory.getKeyManagers();
+ }
}
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/SSLSocketFactoryTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/SSLSocketFactoryTest.java
index 18b507e..32d775e 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/SSLSocketFactoryTest.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/SSLSocketFactoryTest.java
@@ -15,6 +15,7 @@
*/
package tests.api.javax.net.ssl;
+import dalvik.annotation.BrokenTest;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
@@ -24,12 +25,11 @@ import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
+import javax.net.SocketFactory;
import javax.net.ssl.SSLSocketFactory;
import junit.framework.TestCase;
-import org.apache.harmony.xnet.tests.support.SSLSocketFactoryImpl;
-
import tests.support.Support_PortManager;
@TestTargetClass(SSLSocketFactory.class)
@@ -57,7 +57,7 @@ public class SSLSocketFactoryTest extends TestCase {
)
public void test_Constructor() {
try {
- SSLSocketFactoryImpl sf = new SSLSocketFactoryImpl();
+ SocketFactory sf = SSLSocketFactory.getDefault();
assertTrue(sf instanceof SSLSocketFactory);
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
@@ -87,8 +87,9 @@ public class SSLSocketFactoryTest extends TestCase {
method = "createSocket",
args = {java.net.Socket.class, java.lang.String.class, int.class, boolean.class}
)
+ @BrokenTest("throws SocketException, socket not connected on both RI and Android")
public void test_createSocket() {
- SSLSocketFactoryImpl sf = new SSLSocketFactoryImpl();
+ SSLSocketFactory sf = (SSLSocketFactory) SSLSocketFactory.getDefault();
int sport = startServer("test_createSocket()");
int[] invalid = {Integer.MIN_VALUE, -1, 65536, Integer.MAX_VALUE};
String[] str = {null, ""};
@@ -141,8 +142,9 @@ public class SSLSocketFactoryTest extends TestCase {
)
public void test_getDefaultCipherSuites() {
try {
- SSLSocketFactoryImpl sf = new SSLSocketFactoryImpl();
- assertNull(sf.getDefaultCipherSuites());
+ SSLSocketFactory sf = (SSLSocketFactory) SSLSocketFactory.getDefault();
+ assertTrue("no default cipher suites returned",
+ sf.getDefaultCipherSuites().length > 0);
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
}
@@ -159,8 +161,9 @@ public class SSLSocketFactoryTest extends TestCase {
)
public void test_getSupportedCipherSuites() {
try {
- SSLSocketFactoryImpl sf = new SSLSocketFactoryImpl();
- assertNull(sf.getSupportedCipherSuites());
+ SSLSocketFactory sf = (SSLSocketFactory) SSLSocketFactory.getDefault();
+ assertTrue("no supported cipher suites returned",
+ sf.getSupportedCipherSuites().length > 0);
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
}
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/SSLSocketTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/SSLSocketTest.java
index 31b19fd..5e39cb1 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/SSLSocketTest.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/SSLSocketTest.java
@@ -15,21 +15,27 @@
*/
package tests.api.javax.net.ssl;
+import dalvik.annotation.AndroidOnly;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
import javax.net.ssl.*;
+import javax.security.cert.X509Certificate;
+
import java.net.*;
+import java.security.KeyStore;
import java.lang.String;
-import java.lang.IllegalStateException;
+import java.io.ByteArrayInputStream;
import java.io.IOException;
-
+import java.io.InputStream;
import junit.framework.TestCase;
-import org.apache.harmony.xnet.tests.support.mySSLSocket;
+import org.apache.harmony.luni.util.Base64;
+
+import tests.api.javax.net.ssl.HandshakeCompletedEventTest.TestTrustManager;
import tests.support.Support_PortManager;
@TestTargetClass(SSLSocket.class)
@@ -54,15 +60,15 @@ public class SSLSocketTest extends TestCase {
)
public void testConstructor_01() {
try {
- mySSLSocket ssl = new mySSLSocket();
- assertNotNull(ssl);
- assertTrue(ssl instanceof SSLSocket);
+ SSLSocket ssl = getSSLSocket();
} catch (Exception e) {
fail("Unexpected exception " + e);
}
}
/**
+ * @throws IOException
+ * @throws UnknownHostException
* @tests javax.net.ssl.SSLSocket#SSLSocket(InetAddress address, int port)
*/
@TestTargetNew(
@@ -71,21 +77,17 @@ public class SSLSocketTest extends TestCase {
method = "SSLSocket",
args = {java.net.InetAddress.class, int.class}
)
- public void testConstructor_02() {
- mySSLSocket ssl;
+ public void testConstructor_02() throws UnknownHostException, IOException {
+ SSLSocket ssl;
int sport = startServer("Cons InetAddress,I");
int[] invalidPort = {-1, Integer.MIN_VALUE, 65536, Integer.MAX_VALUE};
- try {
- ssl = new mySSLSocket(InetAddress.getLocalHost(), sport);
- assertNotNull(ssl);
- assertEquals(sport, ssl.getPort());
- } catch (Exception e) {
- fail("Unexpected exception: " + e);
- }
+ ssl = getSSLSocket(InetAddress.getLocalHost(), sport);
+ assertNotNull(ssl);
+ assertEquals(sport, ssl.getPort());
try {
- ssl = new mySSLSocket(InetAddress.getLocalHost(), 8081);
+ ssl = getSSLSocket(InetAddress.getLocalHost(), sport + 1);
fail("IOException wasn't thrown ...");
} catch (IOException e) {
//expected
@@ -93,9 +95,10 @@ public class SSLSocketTest extends TestCase {
for (int i = 0; i < invalidPort.length; i++) {
try {
- ssl = new mySSLSocket(InetAddress.getLocalHost(), invalidPort[i]);
+ ssl = getSSLSocket(InetAddress.getLocalHost(), invalidPort[i]);
fail("IllegalArgumentException wasn't thrown for " + invalidPort[i]);
} catch (IllegalArgumentException iae) {
+ // expected
} catch (Exception e) {
fail(e + " was thrown instead of IllegalArgumentException for " + invalidPort[i]);
}
@@ -103,6 +106,8 @@ public class SSLSocketTest extends TestCase {
}
/**
+ * @throws IOException
+ * @throws UnknownHostException
* @tests javax.net.ssl.SSLSocket#SSLSocket(InetAddress address, int port,
* InetAddress clientAddress, int clientPort)
*/
@@ -112,50 +117,116 @@ public class SSLSocketTest extends TestCase {
method = "SSLSocket",
args = {java.net.InetAddress.class, int.class, java.net.InetAddress.class, int.class}
)
- public void testConstructor_03() {
- mySSLSocket ssl;
+ public void testConstructor_03() throws UnknownHostException, IOException {
+ SSLSocket ssl;
int sport = startServer("Cons InetAddress,I,InetAddress,I");
int portNumber = Support_PortManager.getNextPort();
- int[] invalidPort = {-1, Integer.MIN_VALUE, 65536, Integer.MAX_VALUE};
- try {
- ssl = new mySSLSocket(InetAddress.getLocalHost(), sport,
- InetAddress.getLocalHost(), portNumber);
- assertNotNull(ssl);
- assertEquals(sport, ssl.getPort());
- assertEquals(portNumber, ssl.getLocalPort());
- } catch (Exception e) {
- fail("Unexpected exception: " + e);
- }
+ ssl = getSSLSocket(InetAddress.getLocalHost(), sport,
+ InetAddress.getLocalHost(), portNumber);
+ assertNotNull(ssl);
+ assertEquals(sport, ssl.getPort());
+ assertEquals(portNumber, ssl.getLocalPort());
try {
- ssl = new mySSLSocket(InetAddress.getLocalHost(), 8081, InetAddress.getLocalHost(), 8082);
+ ssl = getSSLSocket(InetAddress.getLocalHost(), 8081, InetAddress.getLocalHost(), 8082);
fail("IOException wasn't thrown ...");
} catch (IOException e) {
//expected
}
- for (int i = 0; i < invalidPort.length; i++) {
- try {
- ssl = new mySSLSocket(InetAddress.getLocalHost(), invalidPort[i],
- InetAddress.getLocalHost(), portNumber);
- fail("IllegalArgumentException wasn't thrown for " + invalidPort[i]);
- } catch (IllegalArgumentException iae) {
- } catch (Exception e) {
- fail(e + " was thrown instead of IllegalArgumentException for " + invalidPort[i]);
- }
- try {
- ssl = new mySSLSocket(InetAddress.getLocalHost(), sport,
- InetAddress.getLocalHost(), invalidPort[i]);
- fail("IllegalArgumentException wasn't thrown for " + invalidPort[i]);
- } catch (IllegalArgumentException iae) {
- } catch (Exception e) {
- fail(e + " was thrown instead of IllegalArgumentException for " + invalidPort[i]);
- }
+ try {
+ ssl = getSSLSocket(InetAddress.getLocalHost(), -1,
+ InetAddress.getLocalHost(), sport + 1);
+ fail("IllegalArgumentException wasn't thrown for -1");
+ } catch (IllegalArgumentException iae) {
+ // expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException for -1");
+ }
+ try {
+ ssl = getSSLSocket(InetAddress.getLocalHost(), sport,
+ InetAddress.getLocalHost(), -1);
+ fail("IllegalArgumentException wasn't thrown for -1");
+ } catch (IllegalArgumentException iae) {
+ // expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException for -1");
+ }
+
+ try {
+ ssl = getSSLSocket(InetAddress.getLocalHost(), Integer.MIN_VALUE,
+ InetAddress.getLocalHost(), sport + 1);
+ fail("IOException wasn't thrown for " + Integer.MIN_VALUE);
+ } catch (IOException ioe) {
+ // expected on RI
+ } catch (IllegalArgumentException iae) {
+ // expected on Android
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IOException for "
+ + Integer.MIN_VALUE);
+ }
+ try {
+ ssl = getSSLSocket(InetAddress.getLocalHost(), sport,
+ InetAddress.getLocalHost(), Integer.MIN_VALUE);
+ fail("IllegalArgumentException wasn't thrown for "
+ + Integer.MIN_VALUE);
+ } catch (IllegalArgumentException iae) {
+ // expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException for "
+ + Integer.MIN_VALUE);
+ }
+
+ try {
+ ssl = getSSLSocket(InetAddress.getLocalHost(), 65536,
+ InetAddress.getLocalHost(), sport + 1);
+ fail("IOException wasn't thrown for 65536");
+ } catch (IOException ioe) {
+ // expected on RI
+ } catch (IllegalArgumentException iae) {
+ // expected on Android
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IOException for 65536");
+ }
+ try {
+ ssl = getSSLSocket(InetAddress.getLocalHost(), sport,
+ InetAddress.getLocalHost(), 65536);
+ fail("IllegalArgumentException wasn't thrown for 65536");
+ } catch (IllegalArgumentException iae) {
+ // expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException for 65536");
+ }
+
+ try {
+ ssl = getSSLSocket(InetAddress.getLocalHost(), Integer.MAX_VALUE,
+ InetAddress.getLocalHost(), sport + 1);
+ fail("IOException wasn't thrown for " + Integer.MAX_VALUE);
+ } catch (IOException ioe) {
+ // expected on RI
+ } catch (IllegalArgumentException iae) {
+ // expected on Android
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IOException for "
+ + Integer.MAX_VALUE);
+ }
+ try {
+ ssl = getSSLSocket(InetAddress.getLocalHost(), sport,
+ InetAddress.getLocalHost(), Integer.MAX_VALUE);
+ fail("IllegalArgumentException wasn't thrown for "
+ + Integer.MAX_VALUE);
+ } catch (IllegalArgumentException iae) {
+ // expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException for "
+ + Integer.MAX_VALUE);
}
}
/**
+ * @throws IOException
+ * @throws UnknownHostException
* @tests javax.net.ssl.SSLSocket#SSLSocket(String host, int port)
*/
@TestTargetNew(
@@ -164,21 +235,17 @@ public class SSLSocketTest extends TestCase {
method = "SSLSocket",
args = {java.lang.String.class, int.class}
)
- public void testConstructor_04() {
- mySSLSocket ssl;
+ public void testConstructor_04() throws UnknownHostException, IOException {
+ SSLSocket ssl;
int sport = startServer("Cons String,I");
int[] invalidPort = {-1, Integer.MIN_VALUE, 65536, Integer.MAX_VALUE};
- try {
- ssl = new mySSLSocket(InetAddress.getLocalHost().getHostName(), sport);
- assertNotNull(ssl);
- assertEquals(sport, ssl.getPort());
- } catch (Exception e) {
- fail("Unexpected exception: " + e);
- }
+ ssl = getSSLSocket(InetAddress.getLocalHost().getHostName(), sport);
+ assertNotNull(ssl);
+ assertEquals(sport, ssl.getPort());
try {
- ssl = new mySSLSocket("localhost", 8082);
+ ssl = getSSLSocket("localhost", 8082);
fail("IOException wasn't thrown ...");
} catch (IOException e) {
//expected
@@ -186,24 +253,28 @@ public class SSLSocketTest extends TestCase {
for (int i = 0; i < invalidPort.length; i++) {
try {
- ssl = new mySSLSocket(InetAddress.getLocalHost().getHostName(), invalidPort[i]);
+ ssl = getSSLSocket(InetAddress.getLocalHost().getHostName(), invalidPort[i]);
fail("IllegalArgumentException wasn't thrown for " + invalidPort[i]);
} catch (IllegalArgumentException iae) {
+ // expected
} catch (Exception e) {
fail(e + " was thrown instead of IllegalArgumentException for " + invalidPort[i]);
}
}
try {
- ssl = new mySSLSocket("bla-bla", sport);
+ ssl = getSSLSocket("bla-bla", sport);
fail("UnknownHostException wasn't thrown");
} catch (UnknownHostException uhp) {
+ // expected
} catch (Exception e) {
fail(e + " was thrown instead of UnknownHostException");
}
}
/**
+ * @throws IOException
+ * @throws UnknownHostException
* @tests javax.net.ssl.SSLSocket#SSLSocket(String host, int port, InetAddress clientAddress,
* int clientPort)
*/
@@ -213,24 +284,20 @@ public class SSLSocketTest extends TestCase {
method = "SSLSocket",
args = {java.lang.String.class, int.class, java.net.InetAddress.class, int.class}
)
- public void testConstructor_05() {
- mySSLSocket ssl;
+ public void testConstructor_05() throws UnknownHostException, IOException {
+ SSLSocket ssl;
int sport = startServer("Cons String,I,InetAddress,I");
int portNumber = Support_PortManager.getNextPort();
int[] invalidPort = {-1, Integer.MIN_VALUE, 65536, Integer.MAX_VALUE};
- try {
- ssl = new mySSLSocket(InetAddress.getLocalHost().getHostName(), sport,
- InetAddress.getLocalHost(), portNumber);
- assertNotNull(ssl);
- assertEquals(sport, ssl.getPort());
- assertEquals(portNumber, ssl.getLocalPort());
- } catch (Exception e) {
- fail("Unexpected exception: " + e);
- }
+ ssl = getSSLSocket(InetAddress.getLocalHost().getHostName(), sport,
+ InetAddress.getLocalHost(), portNumber);
+ assertNotNull(ssl);
+ assertEquals(sport, ssl.getPort());
+ assertEquals(portNumber, ssl.getLocalPort());
try {
- ssl = new mySSLSocket("localhost", 8081, InetAddress.getLocalHost(), 8082);
+ ssl = getSSLSocket("localhost", 8081, InetAddress.getLocalHost(), 8082);
fail("IOException wasn't thrown ...");
} catch (IOException e) {
//expected
@@ -239,18 +306,20 @@ public class SSLSocketTest extends TestCase {
for (int i = 0; i < invalidPort.length; i++) {
portNumber = Support_PortManager.getNextPort();
try {
- ssl = new mySSLSocket(InetAddress.getLocalHost().getHostName(), invalidPort[i],
+ ssl = getSSLSocket(InetAddress.getLocalHost().getHostName(), invalidPort[i],
InetAddress.getLocalHost(), portNumber);
fail("IllegalArgumentException wasn't thrown for " + invalidPort[i]);
} catch (IllegalArgumentException iae) {
+ // expected
} catch (Exception e) {
fail(e + " was thrown instead of IllegalArgumentException for " + invalidPort[i]);
}
try {
- ssl = new mySSLSocket(InetAddress.getLocalHost().getHostName(), sport,
+ ssl = getSSLSocket(InetAddress.getLocalHost().getHostName(), sport,
InetAddress.getLocalHost(), invalidPort[i]);
fail("IllegalArgumentException wasn't thrown for " + invalidPort[i]);
} catch (IllegalArgumentException iae) {
+ // expected
} catch (Exception e) {
fail(e + " was thrown instead of IllegalArgumentException for " + invalidPort[i]);
}
@@ -258,15 +327,17 @@ public class SSLSocketTest extends TestCase {
portNumber = Support_PortManager.getNextPort();
try {
- ssl = new mySSLSocket("bla-bla", sport, InetAddress.getLocalHost(), portNumber);
+ ssl = getSSLSocket("bla-bla", sport, InetAddress.getLocalHost(), portNumber);
fail("UnknownHostException wasn't thrown");
} catch (UnknownHostException uhp) {
+ // expected
} catch (Exception e) {
fail(e + " was thrown instead of UnknownHostException");
}
}
/**
+ * @throws IOException
* @tests javax.net.ssl.SSLSocket#addHandshakeCompletedListener(HandshakeCompletedListener listener)
*/
@TestTargetNew(
@@ -275,8 +346,9 @@ public class SSLSocketTest extends TestCase {
method = "addHandshakeCompletedListener",
args = {javax.net.ssl.HandshakeCompletedListener.class}
)
- public void test_addHandshakeCompletedListener() {
- mySSLSocket ssl = new mySSLSocket();
+ @AndroidOnly("RI doesn't throw the specified IAE")
+ public void test_addHandshakeCompletedListener() throws IOException {
+ SSLSocket ssl = getSSLSocket();
HandshakeCompletedListener ls = new HandshakeCL();
try {
ssl.addHandshakeCompletedListener(null);
@@ -292,6 +364,7 @@ public class SSLSocketTest extends TestCase {
}
/**
+ * @throws IOException
* @tests javax.net.ssl.SSLSocket#removeHandshakeCompletedListener(HandshakeCompletedListener listener)
*/
@TestTargetNew(
@@ -300,8 +373,8 @@ public class SSLSocketTest extends TestCase {
method = "removeHandshakeCompletedListener",
args = {javax.net.ssl.HandshakeCompletedListener.class}
)
- public void test_removeHandshakeCompletedListener() {
- mySSLSocket ssl = new mySSLSocket();
+ public void test_removeHandshakeCompletedListener() throws IOException {
+ SSLSocket ssl = getSSLSocket();
HandshakeCompletedListener ls = new HandshakeCL();
try {
ssl.removeHandshakeCompletedListener(null);
@@ -309,6 +382,16 @@ public class SSLSocketTest extends TestCase {
} catch (IllegalArgumentException iae) {
//expected
}
+
+ try {
+ ssl.removeHandshakeCompletedListener(ls);
+ } catch (IllegalArgumentException iae) {
+ //expected
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+
+ ssl.addHandshakeCompletedListener(ls);
try {
ssl.removeHandshakeCompletedListener(ls);
} catch (Exception e) {
@@ -317,6 +400,7 @@ public class SSLSocketTest extends TestCase {
}
/**
+ * @throws IOException
* @tests javax.net.ssl.SSLSocket#setEnableSessionCreation(boolean flag)
* @tests javax.net.ssl.SSLSocket#getEnableSessionCreation()
*/
@@ -334,20 +418,18 @@ public class SSLSocketTest extends TestCase {
args = {boolean.class}
)
})
- public void test_EnableSessionCreation() {
- mySSLSocket ssl = new mySSLSocket();
- try {
- assertTrue(ssl.getEnableSessionCreation());
- ssl.setEnableSessionCreation(false);
- assertFalse(ssl.getEnableSessionCreation());
- ssl.setEnableSessionCreation(true);
- assertTrue(ssl.getEnableSessionCreation());
- } catch (Exception e) {
- fail("Unexpected exception " + e);
- }
+ public void test_EnableSessionCreation() throws IOException {
+ SSLSocket ssl = getSSLSocket();
+ assertTrue(ssl.getEnableSessionCreation());
+ ssl.setEnableSessionCreation(false);
+ assertFalse(ssl.getEnableSessionCreation());
+ ssl.setEnableSessionCreation(true);
+ assertTrue(ssl.getEnableSessionCreation());
}
/**
+ * @throws IOException
+ * @throws UnknownHostException
* @tests javax.net.ssl.SSLSocket#setNeedClientAuth(boolean need)
* @tests javax.net.ssl.SSLSocket#getNeedClientAuthCreation()
*/
@@ -365,33 +447,17 @@ public class SSLSocketTest extends TestCase {
args = {}
)
})
- public void test_NeedClientAuth() {
- mySSLSocket ssl = new mySSLSocket(1);
- try {
- try {
- ssl.setNeedClientAuth(true);
- fail("IllegalStateException wasn't thrown");
- } catch (IllegalStateException ise) {
- //expected
- }
-
- try {
- ssl.getNeedClientAuth();
- fail("IllegalStateException wasn't thrown");
- } catch (IllegalStateException ise) {
- //expected
- }
- ssl = new mySSLSocket(0);
- ssl.setNeedClientAuth(true);
- assertTrue(ssl.getNeedClientAuth());
- ssl.setNeedClientAuth(false);
- assertFalse(ssl.getNeedClientAuth());
- } catch (Exception e) {
- fail("Unexpected exception " + e);
- }
+ public void test_NeedClientAuth() throws UnknownHostException, IOException {
+ SSLSocket ssl = getSSLSocket();
+ ssl.setNeedClientAuth(true);
+ assertTrue(ssl.getNeedClientAuth());
+ ssl.setNeedClientAuth(false);
+ assertFalse(ssl.getNeedClientAuth());
}
/**
+ * @throws IOException
+ * @throws UnknownHostException
* @tests javax.net.ssl.SSLSocket#setWantClientAuth(boolean want)
* @tests javax.net.ssl.SSLSocket#getWantClientAuthCreation()
*/
@@ -409,33 +475,16 @@ public class SSLSocketTest extends TestCase {
args = {}
)
})
- public void test_WantClientAuth() {
- mySSLSocket ssl = new mySSLSocket(1);
- try {
- try {
- ssl.setWantClientAuth(true);
- fail("IllegalStateException wasn't thrown");
- } catch (IllegalStateException ise) {
- //expected
- }
-
- try {
- ssl.getWantClientAuth();
- fail("IllegalStateException wasn't thrown");
- } catch (IllegalStateException ise) {
- //expected
- }
- ssl = new mySSLSocket(0);
- ssl.setWantClientAuth(true);
- assertTrue(ssl.getWantClientAuth());
- ssl.setWantClientAuth(false);
- assertFalse(ssl.getWantClientAuth());
- } catch (Exception e) {
- fail("Unexpected exception " + e);
- }
+ public void test_WantClientAuth() throws UnknownHostException, IOException {
+ SSLSocket ssl = getSSLSocket();
+ ssl.setWantClientAuth(true);
+ assertTrue(ssl.getWantClientAuth());
+ ssl.setWantClientAuth(false);
+ assertFalse(ssl.getWantClientAuth());
}
/**
+ * @throws IOException
* @tests javax.net.ssl.SSLSocket#getSupportedProtocols()
*/
@TestTargetNew(
@@ -444,35 +493,14 @@ public class SSLSocketTest extends TestCase {
method = "getSupportedProtocols",
args = {}
)
- public void test_getSupportedProtocols() {
- String[] pr = {"Protocol_1", "Protocol_2", "Protocol_3"};
- mySSLSocket ssl = new mySSLSocket();
- try {
- try {
- ssl.getSupportedProtocols();
- } catch (NullPointerException npe) {
- //expected
- }
- ssl = new mySSLSocket(null, null);
- try {
- ssl.getSupportedProtocols();
- } catch (NullPointerException npe) {
- //expected
- }
- ssl = new mySSLSocket(new String[0], null);
- assertNull("Not NULL result", ssl.getSupportedProtocols());
- ssl = new mySSLSocket(pr, null);
- String[] res = ssl.getSupportedProtocols();
- assertNotNull("NULL result", res);
- if (!res.equals(pr)) {
- fail("Returned result was incorrect");
- }
- } catch (Exception e) {
- fail("Unexpected exception " + e);
- }
+ public void test_getSupportedProtocols() throws IOException {
+ SSLSocket ssl = getSSLSocket();
+ String[] res = ssl.getSupportedProtocols();
+ assertTrue("No supported protocols found", res.length > 0);
}
/**
+ * @throws IOException
* @tests javax.net.ssl.SSLSocket#getEnabledProtocols()
* @tests javax.net.ssl.SSLSocket#setEnabledProtocols(String[] protocols)
*/
@@ -490,33 +518,31 @@ public class SSLSocketTest extends TestCase {
args = {}
)
})
- public void test_EnabledProtocols() {
- String[] pr1 = {"Protocol_1", "Protocol_2", "Protocol_3"};
- String[] pr2 = {"Protocol_1", "Protocol_2"};
- mySSLSocket ssl = new mySSLSocket(pr1, null);
+ public void test_EnabledProtocols() throws IOException {
+ SSLSocket ssl = getSSLSocket();
try {
- try {
- ssl.setEnabledProtocols(null);
- } catch (IllegalArgumentException iae) {
- //expected
- }
- try {
- ssl.setEnabledProtocols(pr2);
- } catch (IllegalArgumentException iae) {
- //expected
- }
- ssl.setEnabledProtocols(pr1);
- String[] res = ssl.getEnabledProtocols();
- assertNotNull("NULL result", res);
- if (!res.equals(pr1)) {
- fail("Returned result was incorrect");
- }
- } catch (Exception e) {
- fail("Unexpected exception " + e);
+ ssl.setEnabledProtocols(null);
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
+ try {
+ ssl.setEnabledProtocols(new String[] {});
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
+ try {
+ ssl.setEnabledProtocols(new String[] {"blubb"});
+ } catch (IllegalArgumentException iae) {
+ //expected
}
+ ssl.setEnabledProtocols(ssl.getEnabledProtocols());
+ String[] res = ssl.getEnabledProtocols();
+ assertEquals("no enabled protocols set",
+ ssl.getEnabledProtocols().length, res.length);
}
/**
+ * @throws IOException
* @tests javax.net.ssl.SSLSocket#getSession()
*/
@TestTargetNew(
@@ -525,16 +551,17 @@ public class SSLSocketTest extends TestCase {
method = "getSession",
args = {}
)
- public void test_getSession() {
- mySSLSocket ssl = new mySSLSocket();
+ public void test_getSession() throws IOException {
+ SSLSocket ssl = getSSLSocket();
try {
- assertNull(ssl.getSession());
+ assertNotNull(ssl.getSession());
} catch (Exception e) {
fail("Unexpected exception " + e);
}
}
/**
+ * @throws IOException
* @tests javax.net.ssl.SSLSocket#getSupportedCipherSuites()
*/
@TestTargetNew(
@@ -543,35 +570,14 @@ public class SSLSocketTest extends TestCase {
method = "getSupportedCipherSuites",
args = {}
)
- public void test_getSupportedCipherSuites() {
- String[] pr = {"Suite_1", "Suite_2", "Suite_3"};
- mySSLSocket ssl = new mySSLSocket();
- try {
- try {
- ssl.getSupportedCipherSuites();
- } catch (NullPointerException npe) {
- //expected
- }
- ssl = new mySSLSocket(null, null);
- try {
- ssl.getSupportedCipherSuites();
- } catch (NullPointerException npe) {
- //expected
- }
- ssl = new mySSLSocket(new String[0], new String[0]);
- assertNull("Not NULL result", ssl.getSupportedCipherSuites());
- ssl = new mySSLSocket(null, pr);
- String[] res = ssl.getSupportedCipherSuites();
- assertNotNull("NULL result", res);
- if (!res.equals(pr)) {
- fail("Returned result was incorrect");
- }
- } catch (Exception e) {
- fail("Unexpected exception " + e);
- }
+ public void test_getSupportedCipherSuites() throws IOException {
+ SSLSocket ssl = getSSLSocket();
+ String[] res = ssl.getSupportedCipherSuites();
+ assertTrue("no supported cipher suites", res.length > 0);
}
/**
+ * @throws IOException
* @tests javax.net.ssl.SSLSocket#getEnabledCipherSuites()
* @tests javax.net.ssl.SSLSocket#setEnabledCipherSuites(String[] suites)
*/
@@ -589,33 +595,31 @@ public class SSLSocketTest extends TestCase {
args = {java.lang.String[].class}
)
})
- public void test_EnabledCipherSuites() {
- String[] pr1 = {"Suite_1", "Suite_2", "Suite_3"};
- String[] pr2 = {"Suite_1", "Suite_2"};
- mySSLSocket ssl = new mySSLSocket(null, pr1);
+ public void test_EnabledCipherSuites() throws IOException {
+ SSLSocket ssl = getSSLSocket();
try {
- try {
- ssl.setEnabledCipherSuites(null);
- } catch (IllegalArgumentException iae) {
- //expected
- }
- try {
- ssl.setEnabledCipherSuites(pr2);
- } catch (IllegalArgumentException iae) {
- //expected
- }
- ssl.setEnabledCipherSuites(pr1);
- String[] res = ssl.getEnabledCipherSuites();
- assertNotNull("NULL result", res);
- if (!res.equals(pr1)) {
- fail("Returned result was incorrect");
- }
- } catch (Exception e) {
- fail("Unexpected exception " + e);
+ ssl.setEnabledCipherSuites(null);
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
+ try {
+ ssl.setEnabledCipherSuites(new String[] {});
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
+ try {
+ ssl.setEnabledCipherSuites(new String[] {"blubb"});
+ } catch (IllegalArgumentException iae) {
+ //expected
}
+ ssl.setEnabledCipherSuites(ssl.getSupportedCipherSuites());
+ String[] res = ssl.getEnabledCipherSuites();
+ assertEquals("not all supported cipher suites where enabled",
+ ssl.getSupportedCipherSuites().length, res.length);
}
/**
+ * @throws IOException
* @tests javax.net.ssl.SSLSocket#getUseClientMode()
* @tests javax.net.ssl.SSLSocket#setUseClientMode(boolean mode)
*/
@@ -633,56 +637,40 @@ public class SSLSocketTest extends TestCase {
args = {boolean.class}
)
})
- public void test_UseClientMode() {
- String[] pr = {"Protocol_1", "Protocol_3"};
- mySSLSocket ssl = new mySSLSocket(0, pr, null);
- try {
- assertFalse(ssl.getUseClientMode());
- ssl.setUseClientMode(true);
- assertTrue(ssl.getUseClientMode());
- } catch (Exception e) {
- fail("Unexpected exception " + e);
- }
- ssl = new mySSLSocket(1, pr, null);
+ public void test_UseClientMode() throws IOException {
+ SSLSocket ssl = getSSLSocket();
+ assertTrue(ssl.getUseClientMode());
+ ssl.setUseClientMode(false);
+ assertFalse(ssl.getUseClientMode());
+
+ ssl = getSSLSocket("localhost", startServer("UseClientMode"));
try {
- assertTrue(ssl.getUseClientMode());
- ssl.setUseClientMode(false);
- assertFalse(ssl.getUseClientMode());
- } catch (Exception e) {
- fail("Unexpected exception " + e);
+ ssl.startHandshake();
+ } catch (IOException ioe) {
+ //fail(ioe + " was thrown for method startHandshake()");
}
try {
- ssl.startHandshake();
ssl.setUseClientMode(false);
fail("IllegalArgumentException wasn't thrown");
} catch (IllegalArgumentException iae) {
//expected
- } catch (IOException ioe) {
- fail(ioe + " was thrown for method startHandshake()");
} catch (Exception e) {
fail(e + " was thrown instead of IllegalArgumentException");
}
}
/**
+ * @throws IOException
* @tests javax.net.ssl.SSLSocket#startHandshake()
*/
@TestTargetNew(
- level = TestLevel.COMPLETE,
+ level = TestLevel.PARTIAL_COMPLETE,
notes = "",
method = "startHandshake",
args = {}
)
- public void test_startHandshake() {
- String[] pr = {"Protocol_1", "Protocol_3"};
- String[] pr1 = {"Protocol_1", "Protocol_3", "Protocol_2"};
- mySSLSocket ssl = new mySSLSocket(pr, null);
- try {
- ssl.startHandshake();
- } catch (Exception e) {
- fail("Unexpected exception " + e);
- }
- ssl = new mySSLSocket(pr1, null);
+ public void test_startHandshake() throws IOException {
+ SSLSocket ssl = getSSLSocket();
try {
ssl.startHandshake();
fail("IOException wasn't thrown");
@@ -692,16 +680,213 @@ public class SSLSocketTest extends TestCase {
fail(e + " was thrown instead of IOException");
}
}
+
+ // Change this to false if on RI
+ boolean useBKS = true;
+ private String PASSWORD = "android";
+
+ private int port = Support_PortManager.getNextPort();
+
+ private boolean serverReady = false;
+
+ /**
+ * Defines the keystore contents for the server, BKS version. Holds just a
+ * single self-generated key. The subject name is "Test Server".
+ */
+ private static final String SERVER_KEYS_BKS =
+ "AAAAAQAAABQDkebzoP1XwqyWKRCJEpn/t8dqIQAABDkEAAVteWtleQAAARpYl20nAAAAAQAFWC41" +
+ "MDkAAAJNMIICSTCCAbKgAwIBAgIESEfU1jANBgkqhkiG9w0BAQUFADBpMQswCQYDVQQGEwJVUzET" +
+ "MBEGA1UECBMKQ2FsaWZvcm5pYTEMMAoGA1UEBxMDTVRWMQ8wDQYDVQQKEwZHb29nbGUxEDAOBgNV" +
+ "BAsTB0FuZHJvaWQxFDASBgNVBAMTC1Rlc3QgU2VydmVyMB4XDTA4MDYwNTExNTgxNFoXDTA4MDkw" +
+ "MzExNTgxNFowaTELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExDDAKBgNVBAcTA01U" +
+ "VjEPMA0GA1UEChMGR29vZ2xlMRAwDgYDVQQLEwdBbmRyb2lkMRQwEgYDVQQDEwtUZXN0IFNlcnZl" +
+ "cjCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA0LIdKaIr9/vsTq8BZlA3R+NFWRaH4lGsTAQy" +
+ "DPMF9ZqEDOaL6DJuu0colSBBBQ85hQTPa9m9nyJoN3pEi1hgamqOvQIWcXBk+SOpUGRZZFXwniJV" +
+ "zDKU5nE9MYgn2B9AoiH3CSuMz6HRqgVaqtppIe1jhukMc/kHVJvlKRNy9XMCAwEAATANBgkqhkiG" +
+ "9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p9TInzr3EFuYD0YiQ7YlAHq3cPuyGoLXJ5dXYuSBfhDXJSeddUkl" +
+ "k1ufZyOOcskeInQge7jzaRfmKg3U94r+spMEvb0AzDQVOKvjjo1ivxMSgFRZaDb/4qw=";
+
+ /**
+ * Defines the keystore contents for the server, JKS version. Holds just a
+ * single self-generated key. The subject name is "Test Server".
+ */
+ private static final String SERVER_KEYS_JKS =
+ "/u3+7QAAAAIAAAABAAAAAQAFbXlrZXkAAAEaWFfBeAAAArowggK2MA4GCisGAQQBKgIRAQEFAASC" +
+ "AqI2kp5XjnF8YZkhcF92YsJNQkvsmH7zqMM87j23zSoV4DwyE3XeC/gZWq1ToScIhoqZkzlbWcu4" +
+ "T/Zfc/DrfGk/rKbBL1uWKGZ8fMtlZk8KoAhxZk1JSyJvdkyKxqmzUbxk1OFMlN2VJNu97FPVH+du" +
+ "dvjTvmpdoM81INWBW/1fZJeQeDvn4mMbbe0IxgpiLnI9WSevlaDP/sm1X3iO9yEyzHLL+M5Erspo" +
+ "Cwa558fOu5DdsICMXhvDQxjWFKFhPHnKtGe+VvwkG9/bAaDgx3kfhk0w5zvdnkKb+8Ed9ylNRzdk" +
+ "ocAa/mxlMTOsTvDKXjjsBupNPIIj7OP4GNnZaxkJjSs98pEO67op1GX2qhy6FSOPNuq8k/65HzUc" +
+ "PYn6voEeh6vm02U/sjEnzRevQ2+2wXoAdp0EwtQ/DlMe+NvcwPGWKuMgX4A4L93DZGb04N2VmAU3" +
+ "YLOtZwTO0LbuWrcCM/q99G/7LcczkxIVrO2I/rh8RXVczlf9QzcrFObFv4ATuspWJ8xG7DhsMbnk" +
+ "rT94Pq6TogYeoz8o8ZMykesAqN6mt/9+ToIemmXv+e+KU1hI5oLwWMnUG6dXM6hIvrULY6o+QCPH" +
+ "172YQJMa+68HAeS+itBTAF4Clm/bLn6reHCGGU6vNdwU0lYldpiOj9cB3t+u2UuLo6tiFWjLf5Zs" +
+ "EQJETd4g/EK9nHxJn0GAKrWnTw7pEHQJ08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EoqPeqHbDf7YaP8h/5BSt0=";
+
protected int startServer(String name) {
- int portNumber = Support_PortManager.getNextPort();
- ServerSocket ss = null;
+ String keys = useBKS ? SERVER_KEYS_BKS : SERVER_KEYS_JKS;
+ TestServer server = new TestServer(true, keys);
+ Thread serverThread = new Thread(server);
+ serverThread.start();
try {
- ss = new ServerSocket(portNumber);
- } catch (IOException e) {
- fail(name + ": " + e);
+ while (!serverReady) {
+ Thread.currentThread().sleep(50);
+ }
+ // give the server 100 millis to accept
+ Thread.currentThread().sleep(100);
+ } catch (InterruptedException e) {
+ // ignore
}
- return ss.getLocalPort();
+ return server.sport;
+ }
+
+ /**
+ * Implements a test SSL socket server. It wait for a connection on a given
+ * port, requests client authentication (if specified), and read 256 bytes
+ * from the socket.
+ */
+ class TestServer implements Runnable {
+
+ public static final int CLIENT_AUTH_NONE = 0;
+
+ public static final int CLIENT_AUTH_WANTED = 1;
+
+ public static final int CLIENT_AUTH_NEEDED = 2;
+
+ private TestTrustManager trustManager;
+
+ private Exception exception;
+
+ String keys;
+
+ private boolean provideKeys;
+
+ int sport;
+
+ public TestServer(boolean provideKeys, String keys) {
+ this.keys = keys;
+ this.provideKeys = provideKeys;
+
+ trustManager = new TestTrustManager();
+ }
+
+ public void run() {
+ try {
+ KeyManager[] keyManagers = provideKeys ? getKeyManagers(keys) : null;
+ TrustManager[] trustManagers = new TrustManager[] { trustManager };
+
+ SSLContext sslContext = SSLContext.getInstance("TLS");
+ sslContext.init(keyManagers, trustManagers, null);
+
+ SSLServerSocket serverSocket = (SSLServerSocket)sslContext.getServerSocketFactory().createServerSocket();
+
+ serverSocket.bind(new InetSocketAddress(port));
+ sport = serverSocket.getLocalPort();
+ serverReady = true;
+
+ SSLSocket clientSocket = (SSLSocket)serverSocket.accept();
+
+ InputStream stream = clientSocket.getInputStream();
+
+ for (int i = 0; i < 256; i++) {
+ int j = stream.read();
+ if (i != j) {
+ throw new RuntimeException("Error reading socket, expected " + i + ", got " + j);
+ }
+ }
+
+ stream.close();
+ clientSocket.close();
+ serverSocket.close();
+
+ } catch (Exception ex) {
+ exception = ex;
+ }
+ }
+
+ public Exception getException() {
+ return exception;
+ }
+
+ public X509Certificate[] getChain() {
+ return trustManager.getChain();
+ }
+
+ }
+
+ /**
+ * Loads a keystore from a base64-encoded String. Returns the KeyManager[]
+ * for the result.
+ */
+ private KeyManager[] getKeyManagers(String keys) throws Exception {
+ byte[] bytes = new Base64().decode(keys.getBytes());
+ InputStream inputStream = new ByteArrayInputStream(bytes);
+
+ KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
+ keyStore.load(inputStream, PASSWORD.toCharArray());
+ inputStream.close();
+
+ String algorithm = KeyManagerFactory.getDefaultAlgorithm();
+ KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(algorithm);
+ keyManagerFactory.init(keyStore, PASSWORD.toCharArray());
+
+ return keyManagerFactory.getKeyManagers();
+ }
+
+ private SSLSocket getSSLSocket() throws IOException {
+ SSLSocket ssl = null;
+ ssl = (SSLSocket) SSLSocketFactory.getDefault().createSocket();
+ return ssl;
}
-}
+ private SSLSocket getSSLSocket(InetAddress host, int port) throws IOException {
+ SSLSocket ssl = null;
+ ssl = (SSLSocket) SSLSocketFactory.getDefault().createSocket(host, port);
+ return ssl;
+ }
+
+ private SSLSocket getSSLSocket(String host, int port) throws UnknownHostException, IOException {
+ SSLSocket ssl = null;
+ ssl = (SSLSocket) SSLSocketFactory.getDefault().createSocket(host, port);
+ return ssl;
+ }
+
+ private SSLSocket getSSLSocket(InetAddress host, int port, InetAddress localHost, int localPort) throws IOException {
+ SSLSocket ssl = null;
+ ssl = (SSLSocket) SSLSocketFactory.getDefault().createSocket(host, port, localHost, localPort);
+ return ssl;
+ }
+
+ private SSLSocket getSSLSocket(String host, int port, InetAddress localHost, int localPort) throws UnknownHostException, IOException {
+ SSLSocket ssl = null;
+ ssl = (SSLSocket) SSLSocketFactory.getDefault().createSocket(host, port, localHost, localPort);
+ return ssl;
+ }
+}
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/TrustManagerFactory1Test.java b/x-net/src/test/java/tests/api/javax/net/ssl/TrustManagerFactory1Test.java
index 001b02f..a933288 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/TrustManagerFactory1Test.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/TrustManagerFactory1Test.java
@@ -550,7 +550,6 @@ public class TrustManagerFactory1Test extends TestCase {
method = "init",
args = {java.security.KeyStore.class}
)
- @KnownFailure("The RI doesn't throw any exception for null parameter.")
public void test_initLjava_security_KeyStore_01() {
if (!DEFSupported) {
fail(NotSupportedMsg);
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/TrustManagerFactorySpiTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/TrustManagerFactorySpiTest.java
index fcaf8c16..6c6d9aa 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/TrustManagerFactorySpiTest.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/TrustManagerFactorySpiTest.java
@@ -16,16 +16,19 @@
package tests.api.javax.net.ssl;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
+import java.security.AccessController;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyStore;
import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.Provider;
import javax.net.ssl.ManagerFactoryParameters;
import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.TrustManagerFactorySpi;
import junit.framework.TestCase;
@@ -35,6 +38,7 @@ import org.apache.harmony.xnet.tests.support.MyTrustManagerFactorySpi.Parameters
@TestTargetClass(TrustManagerFactorySpi.class)
public class TrustManagerFactorySpiTest extends TestCase {
+ private TrustManagerFactorySpiImpl factory = new TrustManagerFactorySpiImpl();
/**
* @tests javax.net.ssl.TrustManagerFactorySpi#TrustManagerFactorySpi()
*/
@@ -47,13 +51,14 @@ public class TrustManagerFactorySpiTest extends TestCase {
public void test_Constructor() {
try {
TrustManagerFactorySpiImpl tmf = new TrustManagerFactorySpiImpl();
- assertTrue(tmf instanceof TrustManagerFactorySpi);
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
}
}
/**
+ * @throws NoSuchAlgorithmException
+ * @throws KeyStoreException
* @tests javax.net.ssl.TrustManagerFactorySpi#engineInit(KeyStore ks)
*/
@TestTargetNew(
@@ -62,25 +67,31 @@ public class TrustManagerFactorySpiTest extends TestCase {
method = "engineInit",
args = {java.security.KeyStore.class}
)
- public void test_engineInit_01() {
- TrustManagerFactorySpiImpl tmf = new TrustManagerFactorySpiImpl();
+ public void test_engineInit_01() throws NoSuchAlgorithmException,
+ KeyStoreException {
+ factory.reset();
+ Provider provider = new MyProvider();
+ TrustManagerFactory tmf = TrustManagerFactory.getInstance("MyTMF",
+ provider);
+ KeyStore ks = null;
try {
- KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
+ ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(null, null);
- tmf.engineInit(ks);
+ tmf.init(ks);
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
}
- try {
- KeyStore ks = null;
- tmf.engineInit(ks);
- fail("KeyStoreException wasn't thrown");
- } catch (KeyStoreException kse) {
- //expected
- }
+ assertTrue(factory.isEngineInitCalled());
+ assertEquals(ks, factory.getKs());
+ factory.reset();
+ tmf.init((KeyStore) null);
+ assertTrue(factory.isEngineInitCalled());
+ assertNull(factory.getKs());
}
/**
+ * @throws InvalidAlgorithmParameterException
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.TrustManagerFactorySpi#engineInit(ManagerFactoryParameters spec)
*/
@TestTargetNew(
@@ -89,26 +100,31 @@ public class TrustManagerFactorySpiTest extends TestCase {
method = "engineInit",
args = {javax.net.ssl.ManagerFactoryParameters.class}
)
- public void test_engineInit_02() {
- TrustManagerFactorySpiImpl tmf = new TrustManagerFactorySpiImpl();
+ public void test_engineInit_02() throws InvalidAlgorithmParameterException,
+ NoSuchAlgorithmException {
+ factory.reset();
+ Provider provider = new MyProvider();
+ TrustManagerFactory tmf = TrustManagerFactory.getInstance("MyTMF",
+ provider);
+ Parameters pr = null;
try {
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(null, null);
- Parameters pr = new Parameters(ks);
- tmf.engineInit(pr);
+ pr = new Parameters(ks);
+ tmf.init(pr);
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
}
- try {
- ManagerFactoryParameters mfp = null;
- tmf.engineInit(mfp);
- fail("InvalidAlgorithmParameterException wasn't thrown");
- } catch (InvalidAlgorithmParameterException kse) {
- //expected
- }
+ assertTrue(factory.isEngineInitCalled());
+ assertEquals(pr, factory.getSpec());
+ factory.reset();
+ tmf.init((ManagerFactoryParameters) null);
+ assertTrue(factory.isEngineInitCalled());
+ assertNull(factory.getSpec());
}
/**
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.TrustManagerFactorySpi#engineGetTrustManagers()
*/
@TestTargetNew(
@@ -117,24 +133,36 @@ public class TrustManagerFactorySpiTest extends TestCase {
method = "engineGetTrustManagers",
args = {}
)
- public void test_engineGetTrustManagers() {
- TrustManagerFactorySpiImpl tmf = new TrustManagerFactorySpiImpl();
- try {
- TrustManager[] tm = tmf.engineGetTrustManagers();
- fail("IllegalStateException wasn't thrown");
- } catch (IllegalStateException ise) {
- //expected
- } catch (Exception e) {
- fail(e + " was thrown instead of IllegalStateException");
- }
+ public void test_engineGetTrustManagers() throws NoSuchAlgorithmException {
+ factory.reset();
+ Provider provider = new MyProvider();
+ TrustManagerFactory tmf = TrustManagerFactory.getInstance("MyTMF",
+ provider);
+ TrustManager[] tm = tmf.getTrustManagers();
+ assertTrue(factory.isEngineGetTrustManagersCalled());
+ factory.reset();
try {
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(null, null);
- tmf.engineInit(ks);
- TrustManager[] tm = tmf.engineGetTrustManagers();
- assertNull("Object is not NULL", tm);
+ tmf.init(ks);
+ tm = tmf.getTrustManagers();
+ assertTrue(factory.isEngineGetTrustManagersCalled());
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
}
}
}
+
+class MyProvider extends Provider {
+
+ public MyProvider() {
+ super("MyProvider", 1.0, "My Test Provider");
+ AccessController.doPrivileged(new java.security.PrivilegedAction<Void>() {
+ public Void run() {
+ put("TrustManagerFactory.MyTMF",
+ "org.apache.harmony.xnet.tests.support.TrustManagerFactorySpiImpl");
+ return null;
+ }
+ });
+ }
+}
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/X509KeyManagerTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/X509KeyManagerTest.java
index f9ffd96..ebd61fe 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/X509KeyManagerTest.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/X509KeyManagerTest.java
@@ -1,26 +1,358 @@
package tests.api.javax.net.ssl;
+import dalvik.annotation.BrokenTest;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
+import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.X509KeyManager;
-import java.security.cert.X509Certificate;
-import java.security.Principal;
+
+import java.security.KeyFactory;
+import java.security.KeyStore;
+import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
+import java.security.cert.CertificateFactory;
+import java.security.cert.X509Certificate;
+import java.security.spec.X509EncodedKeySpec;
+import java.io.ByteArrayInputStream;
import java.net.Socket;
import junit.framework.TestCase;
-import org.apache.harmony.xnet.tests.support.X509KeyManagerImpl;
-
/**
* Tests for <code>X509KeyManager</code> class constructors and methods.
*/
@TestTargetClass(X509KeyManager.class)
public class X509KeyManagerTest extends TestCase {
+ private X509KeyManager manager;
+ private KeyManagerFactory factory;
+
+ private String keyType;
+ private String client = "CLIENT";
+ private String server = "SERVER";
+ private String type = "RSA";
+ private KeyStore keyTest;
+ private X509Certificate[] cert = null;
+ private PrivateKey[] keys = null;
+ private String password = "1234";
+
+
+ /*
+ Certificate:
+ Data:
+ Version: 3 (0x2)
+ Serial Number: 0 (0x0)
+ Signature Algorithm: sha1WithRSAEncryption
+ Issuer: C=AN, ST=Android, O=Android, OU=Android, CN=Android/emailAddress=android@android.com
+ Validity
+ Not Before: Mar 20 17:00:06 2009 GMT
+ Not After : Mar 19 17:00:06 2012 GMT
+ Subject: C=AN, ST=Android, O=Android, OU=Android, CN=Android/emailAddress=android@android.com
+ Subject Public Key Info:
+ Public Key Algorithm: rsaEncryption
+ RSA Public Key: (1024 bit)
+ Modulus (1024 bit):
+ 00:aa:42:40:ed:92:21:17:99:5f:0e:e4:42:b8:cb:
+ 66:3d:63:2a:16:34:3c:7b:d3:3e:1f:a8:3f:bd:9a:
+ eb:b3:24:6b:8c:e4:da:2f:31:bc:61:07:27:2e:28:
+ 71:77:58:ae:b4:89:7c:eb:b0:06:24:07:57:3c:54:
+ 71:db:71:41:05:ab:3d:9f:05:d2:ca:cb:1c:bf:9d:
+ 8a:21:96:8f:13:61:25:69:12:3b:77:bd:f7:34:b2:
+ 09:a9:e0:52:94:44:31:ce:db:3d:eb:64:f1:d6:ca:
+ c5:7d:2f:d6:6f:8d:e4:29:8b:06:98:8a:95:3d:7a:
+ 97:41:9a:f1:66:c5:09:82:0d
+ Exponent: 65537 (0x10001)
+ X509v3 extensions:
+ X509v3 Subject Key Identifier:
+ E7:9B:7D:90:29:EA:90:0B:7F:08:41:76:4E:41:23:E8:43:2C:A9:03
+ X509v3 Authority Key Identifier:
+ keyid:E7:9B:7D:90:29:EA:90:0B:7F:08:41:76:4E:41:23:E8:43:2C:A9:03
+ DirName:/C=AN/ST=Android/O=Android/OU=Android/CN=Android/emailAddress=android@android.com
+ serial:00
+
+ X509v3 Basic Constraints:
+ CA:TRUE
+ Signature Algorithm: sha1WithRSAEncryption
+ 14:98:30:29:42:ef:ab:e6:b8:25:4b:55:85:04:a5:c4:dd:1d:
+ 8b:6a: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IHTMB0G\n"
+ + "A1UdDgQWBBTnm32QKeqQC38IQXZOQSPoQyypAzCBowYDVR0jBIGbMIGYgBTnm32Q\n"
+ + "KeqQC38IQXZOQSPoQyypA6F9pHsweTELMAkGA1UEBhMCQU4xEDAOBgNVBAgTB0Fu\n"
+ + "ZHJvaWQxEDAOBgNVBAoTB0FuZHJvaWQxEDAOBgNVBAsTB0FuZHJvaWQxEDAOBgNV\n"
+ + "BAMTB0FuZHJvaWQxIjAgBgkqhkiG9w0BCQEWE2FuZHJvaWRAYW5kcm9pZC5jb22C\n"
+ + "AQAwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOBgQAUmDApQu+r5rglS1WF\n"
+ + "BKXE3R2LasFvbBwdw2E0MAc0TWqLVW91VW4VWMX4r+C+c7rZpYXXtRqFRCuI/czL\n"
+ + "0e1GaUP/Wa6bXBcm2u7Iv2dVAaAOELmFSVTZeR57Lm9lT9kQLp24kmNndIsiDW3T\n"
+ + "XZ4pY/k2kxungOKx8b8pGYE9Bw==\n"
+ + "-----END CERTIFICATE-----";
+
+ ByteArrayInputStream certArray = new ByteArrayInputStream(certificate
+ .getBytes());
+
+ String key = "-----BEGIN RSA PRIVATE KEY-----\n"
+ + "Proc-Type: 4,ENCRYPTED\n"
+ + "DEK-Info: DES-EDE3-CBC,69E26FCC3A7F136E\n"
+ + "\n"
+ + "YKiLXOwf2teog4IoOvbbROy9vqp0EMt1KF9eNKeKFCWGCS4RFATaAGjKrdA26bOV\n"
+ + "MBdyB4V7qaxLC8/UwLlzFLpprouIfGqrEoR/NT0eKQ+4Pl25GlMvlPaR0pATBLZ2\n"
+ + "OEaB3zcNygOQ02Jdrmw2+CS9qVtGGXjn6Qp6TVFm6edNCoOVZODLP9kkzPLn8Mkm\n"
+ + "/isgsprwMELuth8Y5BC0brI5XYdMqZFI5dLz4wzVH81wBYbRmJqR7yOE1pzAJS9I\n"
+ + "gJ5YvcP7pSmoA2SHVN4v4qolM+GAM9YIp2bwEyWFRjbriNlF1yM+HflGMEZ1HNpZ\n"
+ + "FSFFA3G8EIH9ogbZ3j+7EujrndJC7GIibwiu5rd3eIHtcwrWprp+wEoPc/vM8OpR\n"
+ + "so9ms7iQYV6faYCWK4yeCfErYw7t+AhGqfLiqHO6bO2XAYJcD28RYV9gXmugZOhT\n"
+ + "9471MOw94HWF5tBVjgIkyNBcbRyMF9iyQKafbkHYpmxaB4s2EqQr1SNZl3SLEwhX\n"
+ + "MEGy3/tyveuMLAvdTlSDZbt6memWoXXEX4Ep/q6r0ErCTY31awdP/XaJcJBGb9ni\n"
+ + "Iai8DICaG1v4bUuBVgaiacZlgw1O4Hhj8D2DWfVZsgpx5y8tBRM2lGWvyzEi5n2F\n"
+ + "PiR2UlT0DjCD1ObjCpWJ5insX/w8dXSHGZLLb9ccGRUrw/+5Bptn+AoEfdP+8S3j\n"
+ + "UdMdxl6qt2gneCYu1Lr3cQ+qKPqikQty2UQ6Yp8dJkheLJ2Tr+rnaytOCp2dAT9K\n"
+ + "KXTimIcXV+ftvUMbDPXYu4LJBldr2VokD+k3QbHDgFnfHIiNkwiPzA==\n"
+ + "-----END RSA PRIVATE KEY-----";
+
+ ByteArrayInputStream keyArray = new ByteArrayInputStream(key.getBytes());
+
+ /*
+ Certificate:
+ Data:
+ Version: 3 (0x2)
+ Serial Number: 1 (0x1)
+ Signature Algorithm: sha1WithRSAEncryption
+ Issuer: C=AN, ST=Android, O=Android, OU=Android, CN=Android/emailAddress=android@android.com
+ Validity
+ Not Before: Mar 20 17:00:40 2009 GMT
+ Not After : Mar 20 17:00:40 2010 GMT
+ Subject: C=AN, ST=Android, L=Android, O=Android, OU=Android, CN=Android/emailAddress=android@android.com
+ Subject Public Key Info:
+ Public Key Algorithm: rsaEncryption
+ RSA Public Key: (1024 bit)
+ Modulus (1024 bit):
+ 00:d0:44:5a:c4:76:ef:ae:ff:99:5b:c3:37:c1:09:
+ 33:c1:97:e5:64:7a:a9:7e:98:4b:3a:a3:33:d0:5c:
+ c7:56:ac:d8:42:e8:4a:ac:9c:d9:8f:89:84:c8:46:
+ 95:ce:22:f7:6a:09:de:91:47:9c:38:23:a5:4a:fc:
+ 08:af:5a:b4:6e:39:8e:e9:f5:0e:46:00:69:e1:e5:
+ cc:4c:81:b6:82:7b:56:fb:f4:dc:04:ff:61:e2:7e:
+ 5f:e2:f9:97:53:93:d4:69:9b:ba:79:20:cd:1e:3e:
+ d5:9a:44:95:7c:cf:c1:51:f2:22:fc:ec:cc:66:18:
+ 74:60:2a:a2:be:06:c2:9e:8d
+ Exponent: 65537 (0x10001)
+ X509v3 extensions:
+ X509v3 Basic Constraints:
+ CA:FALSE
+ Netscape Comment:
+ OpenSSL Generated Certificate
+ X509v3 Subject Key Identifier:
+ 95:3E:C3:46:69:52:78:08:05:46:B9:00:69:E5:E7:A7:99:E3:C4:67
+ X509v3 Authority Key Identifier:
+ keyid:E7:9B:7D:90:29:EA:90:0B:7F:08:41:76:4E:41:23:E8:43:2C:A9:03
+
+ Signature Algorithm: sha1WithRSAEncryption
+ a3:5b:30:f5:28:3f:87:f6:1b:36:6a:22:6d:66:48:fa:cb:ee:
+ 4c:04:cf:11:14:e2:1f:b5:68:0c:e7:61:0e:bc:d3:69:19:02:
+ 8b:d5:d3:05:4a:c8:29:e8:e3:d0:e9:32:ad:6c:7d:9c:c4:46:
+ 6c:f9:66:e6:64:60:47:6b:ef:8e:c8:1c:67:5a:5a:cf:73:a3:
+ 7e:9d:6e:89:0c:67:99:17:3d:b2:b8:8e:41:95:9c:84:95:bf:
+ 57:95:24:22:8f:19:12:c1:fd:23:45:75:7f:4f:61:06:e3:9f:
+ 05:dc:e7:29:9a:6b:17:e1:e1:37:d5:8b:ba:b4:d0:8a:3c:dd:
+ 3f:6a
+ */
+ String certificate2 = "-----BEGIN CERTIFICATE-----\n"
+ + "MIIC9jCCAl+gAwIBAgIBATANBgkqhkiG9w0BAQUFADB5MQswCQYDVQQGEwJBTjEQ\n"
+ + "MA4GA1UECBMHQW5kcm9pZ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END CERTIFICATE-----";
+
+ ByteArrayInputStream certArray2 = new ByteArrayInputStream(certificate2
+ .getBytes());
+
+ String key2 = "-----BEGIN RSA PRIVATE KEY-----\n"
+ + "Proc-Type: 4,ENCRYPTED\n"
+ + "DEK-Info: DES-EDE3-CBC,370723FFDC1B1CFA\n"
+ + "\n"
+ + "KJ20ODBEQujoOpnzNfHNoo5DF/qENhw9IaApChGMj+WhqYuFfKfPQKuRli8sJSEk\n"
+ + "uoPmEqjJndHz5M5bI7wVxiafv/Up4+SaNKhn/vu6xjx/senJMX8HMUchqfvn0eCd\n"
+ + "31NHQeNbQ67O73xGIdltLzwTRsavTu/hwhnnJxiXzXnYtI5HTZUaRbVJQNpdlkNW\n"
+ + "H91u70lwlT8W2MATBhl3R3wIbRHQG1I0RQX12O04gMfK1PBl9d/tnFOi4ESfth1W\n"
+ + "e06XV0U12g06V5/UUuicJANvgyf0Pix0xxPr2tqibWeGpFwCvJpNHl4L3tUocydF\n"
+ + "HYoUKx/r3VSmesnZ1zUMsuO2zXOuLLcwCSFN+73GBLWocCxBvag6HFvCemy5Tuhs\n"
+ + "9MhfF+5lKER/9Ama/e7C61usaoUhR1OvpGWMfjewrFLCsyWlInscoZ1ad5YtcWGx\n"
+ + "MM7+BsTnK00fcXZuPHTPsiwQ0fMVeNM2a/e65aIivfzzHmb6gqUigNpfNYcqQsJJ\n"
+ + "Wwoc5hXVO92vugdHOHOiAUpfZZgNDZwgCTluMuI+KJ0QCb0dhF5w/TDA8z+vRwmW\n"
+ + "sz5WrA4F+T3LfwwLQfxJyHTnbAu38VlMMZP98iIobOX3AAkBw4+kTOCEedvmKt0f\n"
+ + "s7iSKrnnV6AyzRPEJUWknMF8xNFH7HDqkZf4Mv8cMM6e45K4kBGd17d3tcEFi2An\n"
+ + "5l6S9hHtoyMhHjnAcyuHJbD9rGRgyOlbhSYTcbX/gKiECZj0kf8xHi20qntO3c+p\n"
+ + "jdpp97fIMnQTl5IDNxOy5h9MDLs/SYAR7iyF19RkIGc=\n"
+ + "-----END RSA PRIVATE KEY-----";
+
+ ByteArrayInputStream keyArray2 = new ByteArrayInputStream(key2.getBytes());
+
+ /*
+ Certificate:
+ Data:
+ Version: 3 (0x2)
+ Serial Number: 2 (0x2)
+ Signature Algorithm: sha1WithRSAEncryption
+ Issuer: C=AN, ST=Android, O=Android, OU=Android, CN=Android/emailAddress=android@android.com
+ Validity
+ Not Before: Mar 20 17:02:32 2009 GMT
+ Not After : Mar 20 17:02:32 2010 GMT
+ Subject: C=AN, ST=Android, L=Android, O=Android, OU=Android, CN=Android/emailAddress=android@android.com
+ Subject Public Key Info:
+ Public Key Algorithm: rsaEncryption
+ RSA Public Key: (1024 bit)
+ Modulus (1024 bit):
+ 00:b4:c5:ed:df:30:42:6d:8b:af:4b:e4:9c:13:5e:
+ 83:23:cd:2f:ce:34:e2:43:d7:6c:72:bb:03:b3:b9:
+ 24:02:e0:cc:b5:8d:d6:92:41:04:2b:5c:94:b2:c3:
+ 9c:9d:56:f0:99:bc:0f:81:af:eb:54:ed:80:a6:a0:
+ c7:c2:43:05:04:7c:9c:7e:07:03:10:b9:bd:c5:16:
+ cf:19:dd:e3:4f:73:83:72:c5:66:e4:5b:14:c4:96:
+ d1:e3:24:0b:b6:d4:f7:84:2e:b1:e7:93:02:9d:f5:
+ da:aa:c1:d9:cc:5e:36:e9:8f:bf:8b:da:a7:45:82:
+ f2:b0:f5:a7:e4:e1:80:a3:17
+ Exponent: 65537 (0x10001)
+ X509v3 extensions:
+ X509v3 Basic Constraints:
+ CA:FALSE
+ Netscape Comment:
+ OpenSSL Generated Certificate
+ X509v3 Subject Key Identifier:
+ 3B:5B:3D:DB:45:F5:8F:58:70:0B:FC:70:3E:31:2B:43:63:A9:FE:2B
+ X509v3 Authority Key Identifier:
+ keyid:E7:9B:7D:90:29:EA:90:0B:7F:08:41:76:4E:41:23:E8:43:2C:A9:03
+
+ Signature Algorithm: sha1WithRSAEncryption
+ 1c:7f:93:1c:59:21:88:15:45:4b:e0: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T3hC6x55MCnfXaqsHZzF426Y+/i9qnRYLysPWn\n"
+ + "5OGAoxcCAwEAAaN7MHkwCQYDVR0TBAIwADAsBglghkgBhvhCAQ0EHxYdT3BlblNT\n"
+ + "TCBHZW5lcmF0ZWQgQ2VydGlmaWNhdGUwHQYDVR0OBBYEFDtbPdtF9Y9YcAv8cD4x\n"
+ + "K0Njqf4rMB8GA1UdIwQYMBaAFOebfZAp6pALfwhBdk5BI+hDLKkDMA0GCSqGSIb3\n"
+ + "DQEBBQUAA4GBABx/kxxZIYgVRUvgnHg6iD5VGYYx6FM9dOJKNJ+SF04TRpJU+EPr\n"
+ + "XgNPFFFh0gS4BFox6xRqGLAgA5IMfwfEG/mef1/sA3rI49/TlG5oijo95GHz4Idd\n"
+ + "QNjLmU2ae7yVfNKdtwSammOJzTnsMmAKl9rpUKVzSqKqnJuof1og1ki9\n"
+ + "-----END CERTIFICATE-----";
+
+ ByteArrayInputStream certArray3 = new ByteArrayInputStream(certificate3
+ .getBytes());
+
+ String key3 = "-----BEGIN RSA PRIVATE KEY-----\n"
+ + "Proc-Type: 4,ENCRYPTED\n"
+ + "DEK-Info: DES-EDE3-CBC,0EE6B33EC2D92297\n"
+ + "\n"
+ + "r7lbWwtlmubgMG020XiOStqgrvPkP1hTrbOV7Gh2IVNTyXWyA8UriQlPyqBQNzy2\n"
+ + "5+Z+JUqzYoLCGY0fQ95ck+ya/wHJQX4OSKFOZwQKpU7pEY9wN1YPa7U9ZnyCPGtB\n"
+ + "+ejvHuIMJhE5wq9Y1iEDIlON++onWTf4T36Sz3OQ8gEJbnx3x+UjcCINooj7kOeM\n"
+ + "giCi5yJEOJaf4fkRioUh6S7cm/msTH3ID33rrvTjk7cD8mGzzTy4hWyKaK4K9GbC\n"
+ + "dOvSORM9mVwTWMUdu1wJ5uyadwBhpSIhC/qpP8Je60nFy8YJlzB2FaMUpAuIOM7B\n"
+ + "EVN2uAMDNOpGzcOJPbLig8smk2lA4+y1T3gFd9paskSjD9B8+/3KuagWEEQQL7T4\n"
+ + "YK3xtjzXwEp6OdG2QjD4ZcK5D0MKuYPF3PszwzlCnBG/On6wIvIiTPWBn/G2u59D\n"
+ + "gJPV7V3Jipn0iYYN+i7T5TNoT7Vko8s3BRpVSrlFUFFhtQPad6NcxGNNH5L1g3fF\n"
+ + "+dp4TnG64PCQZtuu6I6gfuMXztOwQtEpxxHo9WktlCpwL0tT/tpx+zOVbLvgusjB\n"
+ + "QKYCIplbSI7VtpOfcJ3kTTAWSOGZli4FayB/Dplf/FXN6ZwwASw09ioVQc/CFdLk\n"
+ + "Xw05elxV8/AFvm+/VkUHK5JJSp32WMgAJA+XrUsOb5lw1Tl3Hlj9KHALp+Pt/i7N\n"
+ + "+LPnxrpuTry31APt8aRup/pWOLa+f97Hz+arp4wJa5LK+GtTTtoI4+QZp5qzR/jy\n"
+ + "oM+DoKtK+1WsCU7teJwEWXV/ayo1TEFEhcY0F7IAPCzDlG3XOFmulQ==\n"
+ + "-----END RSA PRIVATE KEY-----";
+
+ ByteArrayInputStream keyArray3 = new ByteArrayInputStream(key3.getBytes());
+
+ @Override
+ protected void setUp() {
+ String defAlg = KeyManagerFactory.getDefaultAlgorithm();
+ try {
+ factory = KeyManagerFactory.getInstance(defAlg);
+ } catch (NoSuchAlgorithmException e) {
+ fail("could not get default KeyManagerFactory");
+ }
+ }
+
+ void init(String name) {
+ keyType = name;
+ try {
+ CertificateFactory cf = CertificateFactory.getInstance("X.509");
+ KeyFactory kf = KeyFactory.getInstance("RSA");
+ keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+ keyTest.load(null, null);
+ if (keyType.equals(client)) {
+ keys = new PrivateKey[3];
+ keys[0] = kf.generatePrivate(new X509EncodedKeySpec(key.getBytes()));
+ keys[1] = kf.generatePrivate(new X509EncodedKeySpec(key2.getBytes()));
+ keys[2] = kf.generatePrivate(new X509EncodedKeySpec(key3.getBytes()));
+ cert = new X509Certificate[3];
+ cert[0] = (X509Certificate) cf.generateCertificate(certArray);
+ cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
+ cert[2] = (X509Certificate) cf.generateCertificate(certArray3);
+ keyTest.setKeyEntry("clientKey_01", keys[1], password.toCharArray(), new X509Certificate[] {cert[0], cert[1]});
+ keyTest.setKeyEntry("clientKey_02", keys[2], password.toCharArray(), new X509Certificate[] {cert[0], cert[2]});
+ keyTest.setCertificateEntry("clientAlias_01", cert[0]);
+ keyTest.setCertificateEntry("clientAlias_02", cert[0]);
+ keyTest.setCertificateEntry("clientAlias_03", cert[1]);
+ } else if (keyType.equals(server)) {
+ cert = new X509Certificate[1];
+ cert[0] = (X509Certificate) cf.generateCertificate(certArray3);
+ keyTest.setCertificateEntry("serverAlias_00", cert[0]);
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ throw new IllegalArgumentException(ex.getMessage());
+ }
+ try {
+ factory.init(keyTest, null);
+ } catch (Exception e) {
+ fail("Could't init the KeyManagerFactory");
+ }
+ manager = (X509KeyManager) factory.getKeyManagers()[0];
+ }
+
/**
* @tests X509KeyManager#getClientAliases(String keyType, Principal[] issuers)
*/
@@ -30,16 +362,14 @@ public class X509KeyManagerTest extends TestCase {
method = "getClientAliases",
args = {java.lang.String.class, java.security.Principal[].class}
)
+ @BrokenTest("Test needs to add PrivateKeys to the Store to work properly.")
public void test_getClientAliases() {
- try {
- X509KeyManagerImpl xkm = new X509KeyManagerImpl("CLIENT");
- assertNull(xkm.getClientAliases(null, null));
- assertNull(xkm.getClientAliases("", null));
- String[] resArray = xkm.getClientAliases("CLIENT", null);
- assertTrue("Incorrect result", compareC(resArray));
- } catch (Exception e) {
- fail("Unexpected exception " + e);
- }
+ init(client);
+ assertNull(manager.getClientAliases(null, null));
+ assertNull(manager.getClientAliases("", null));
+ String[] resArray = manager.getClientAliases(type, null);
+ assertNotNull(resArray);
+ assertTrue("Incorrect result", compareC(resArray));
}
/**
@@ -51,19 +381,16 @@ public class X509KeyManagerTest extends TestCase {
method = "chooseClientAlias",
args = {java.lang.String[].class, java.security.Principal[].class, java.net.Socket.class}
)
+ @BrokenTest("Test needs to add PrivateKeys to the Store to work properly.")
public void test_chooseClientAlias() {
- try {
- String[] ar = {"CLIENT"};
- X509KeyManagerImpl xkm = new X509KeyManagerImpl("CLIENT");
- assertNull(xkm.chooseClientAlias(null, null, new Socket()));
- assertNull(xkm.chooseClientAlias(new String[0], null, new Socket()));
- String res = xkm.chooseClientAlias(ar, null, new Socket());
- assertEquals(res, "clientalias_03");
- res = xkm.chooseClientAlias(ar, null, null);
- assertEquals(res, "clientalias_02");
- } catch (Exception e) {
- fail("Unexpected exception " + e);
- }
+ String[] ar = {client};
+ init(client);
+ assertNull(manager.chooseClientAlias(null, null, new Socket()));
+ assertNull(manager.chooseClientAlias(new String[0], null, new Socket()));
+ String res = manager.chooseClientAlias(ar, null, new Socket());
+ assertEquals("clientalias_03", res);
+ res = manager.chooseClientAlias(ar, null, null);
+ assertEquals("clientalias_02", res);
}
/**
@@ -75,17 +402,15 @@ public class X509KeyManagerTest extends TestCase {
method = "getServerAliases",
args = {java.lang.String.class, java.security.Principal[].class}
)
+ @BrokenTest("Test needs to add PrivateKeys to the Store to work properly.")
public void test_getServerAliases() {
- try {
- X509KeyManagerImpl xkm = new X509KeyManagerImpl("SERVER");
- assertNull(xkm.getServerAliases(null, null));
- assertNull(xkm.getServerAliases("", null));
- String[] resArray = xkm.getServerAliases("SERVER", null);
- assertEquals("Incorrect length", resArray.length, 1);
- assertEquals("Incorrect aliase", resArray[0], "serveralias_00");
- } catch (Exception e) {
- fail("Unexpected exception " + e);
- }
+ init(server);
+ assertNull(manager.getServerAliases(null, null));
+ assertNull(manager.getServerAliases("", null));
+ String[] resArray = manager.getServerAliases(type, null);
+ assertNotNull(resArray);
+ assertEquals("Incorrect length", 1, resArray.length);
+ assertEquals("Incorrect aliase", "serveralias_00", resArray[0]);
}
/**
@@ -97,17 +422,14 @@ public class X509KeyManagerTest extends TestCase {
method = "chooseServerAlias",
args = {java.lang.String.class, java.security.Principal[].class, java.net.Socket.class}
)
+ @BrokenTest("Test needs to add PrivateKeys to the Store to work properly.")
public void test_chooseServerAlias() {
- try {
- X509KeyManagerImpl xkm = new X509KeyManagerImpl("SERVER");
- assertNull(xkm.chooseServerAlias(null, null, new Socket()));
- assertNull(xkm.chooseServerAlias("", null, new Socket()));
- assertNull(xkm.chooseServerAlias("SERVER", null, null));
- String res = xkm.chooseServerAlias("SERVER", null, new Socket());
- assertEquals(res, "serveralias_00");
- } catch (Exception e) {
- fail("Unexpected exception " + e);
- }
+ init(server);
+ assertNull(manager.chooseServerAlias(null, null, new Socket()));
+ assertNull(manager.chooseServerAlias("", null, new Socket()));
+ assertNull(manager.chooseServerAlias(type, null, null));
+ String res = manager.chooseServerAlias(type, null, new Socket());
+ assertEquals("serveralias_00", res);
}
/**
@@ -119,16 +441,13 @@ public class X509KeyManagerTest extends TestCase {
method = "getCertificateChain",
args = {java.lang.String.class}
)
+ @BrokenTest("Test needs to add PrivateKeys to the Store to work properly.")
public void test_getCertificateChain() {
- try {
- X509KeyManagerImpl xkm = new X509KeyManagerImpl("SERVER");
- assertNull("Not NULL for NULL parameter", xkm.getCertificateChain(null));
- assertNull("Not NULL for empty parameter",xkm.getCertificateChain(""));
- assertNull("Not NULL for clientAlias_01 parameter", xkm.getCertificateChain("clientAlias_01"));
- assertNull("Not NULL for serverAlias_00 parameter", xkm.getCertificateChain("serverAlias_00"));
- } catch (Exception e) {
- fail("Unexpected exception " + e);
- }
+ init(server);
+ assertNull("Not NULL for NULL parameter", manager.getCertificateChain(null));
+ assertNull("Not NULL for empty parameter",manager.getCertificateChain(""));
+ assertNull("Not NULL for clientAlias_01 parameter", manager.getCertificateChain("clientAlias_01"));
+ assertNull("Not NULL for serverAlias_00 parameter", manager.getCertificateChain("serverAlias_00"));
}
/**
@@ -140,15 +459,12 @@ public class X509KeyManagerTest extends TestCase {
method = "getPrivateKey",
args = {java.lang.String.class}
)
+ @BrokenTest("Test needs to add PrivateKeys to the Store to work properly.")
public void test_getPrivateKey() {
- try {
- X509KeyManagerImpl xkm = new X509KeyManagerImpl("CLIENT");
- assertNull("Not NULL for NULL parameter", xkm.getPrivateKey(null));
- assertNull("Not NULL for serverAlias_00 parameter", xkm.getPrivateKey("serverAlias_00"));
- assertNull("Not NULL for clientAlias_02 parameter", xkm.getPrivateKey("clientAlias_02"));
- } catch (Exception e) {
- fail("Unexpected exception " + e);
- }
+ init(client);
+ assertNull("Not NULL for NULL parameter", manager.getPrivateKey(null));
+ assertNull("Not NULL for serverAlias_00 parameter", manager.getPrivateKey("serverAlias_00"));
+ assertNull("Not NULL for clientAlias_02 parameter", manager.getPrivateKey("clientAlias_02"));
}
@@ -157,7 +473,7 @@ public class X509KeyManagerTest extends TestCase {
return false;
}
for (int i = 0; i < ar.length; i++) {
- if (ar[i] != "clientalias_01" && ar[i] != "clientalias_02" && ar[i] != "clientalias_03") {
+ if (!ar[i].equals("clientalias_01") && !ar[i].equals("clientalias_02") && !ar[i].equals("clientalias_03")) {
return false;
}
}