+++ /dev/null
-package org.apache.harmony.xnet.tests.support;
-
-import java.util.*;
-import javax.net.ssl.SSLSession;
-import javax.net.ssl.SSLSessionContext;
-
-public class SSLSessionContextImpl implements SSLSessionContext {
-
- private int cashSize;
- private long sessionTimeout;
-
- public SSLSessionContextImpl() {
- cashSize = 0;
- sessionTimeout = 0;
- }
-
- public int getSessionCacheSize() {
- return cashSize;
- }
-
- public void setSessionCacheSize(int newSize) throws IllegalArgumentException {
- if(newSize < 0) throw new IllegalArgumentException();
- if (newSize < cashSize) {
- System.out.println("<--- Number of sessions will be changed");
- }
- cashSize = newSize;
- }
-
- public int getSessionTimeout()
- {
- return (int)(sessionTimeout / 1000L);
- }
-
- public void setSessionTimeout(int seconds) throws IllegalArgumentException {
- if(seconds < 0) {
- throw new IllegalArgumentException();
- } else {
- sessionTimeout = (long)seconds * 1000L;
- }
- }
-
- public SSLSession getSession(byte abyte0[])
- {
- return null;
- }
-
- public Enumeration getIds()
- {
- return null;
- }
-
-}
public class TrustManagerFactorySpiImpl extends MyTrustManagerFactorySpi {
- private boolean isInitialized = false;
+ private static boolean isengineInitCalled = false;
+ private static boolean isEngineGetTrustManagersCalled = false;
+ private static KeyStore ks = null;
+ private static ManagerFactoryParameters spec = null;
public void engineInit(KeyStore ks) throws KeyStoreException {
- if (ks == null) {
- throw new KeyStoreException("Not supported operation for null KeyStore");
- }
- isInitialized = true;
+ isengineInitCalled = true;
+ this.ks = ks;
}
public void engineInit(ManagerFactoryParameters spec) throws InvalidAlgorithmParameterException {
- if (spec == null) {
- throw new InvalidAlgorithmParameterException("Null parameter");
- }
- if (spec instanceof Parameters) {
- try {
- engineInit(((Parameters)spec).getKeyStore());
- } catch (KeyStoreException e) {
- throw new RuntimeException(e);
- }
- } else {
- throw new InvalidAlgorithmParameterException("Invalid parameter");
- }
- isInitialized = true;
+ isengineInitCalled = true;
+ this.spec = spec;
}
public TrustManager[] engineGetTrustManagers() {
- if(!isInitialized)
- throw new IllegalStateException("TrustManagerFactorySpi is not initialized");
- else
- return null;
+ isEngineGetTrustManagersCalled = true;
+ return null;
}
+ public void reset() {
+ isengineInitCalled = false;
+ isEngineGetTrustManagersCalled = false;
+ }
+
+ public boolean isEngineGetTrustManagersCalled() {
+ return isEngineGetTrustManagersCalled;
+ }
+
+ public boolean isEngineInitCalled() {
+ return isengineInitCalled;
+ }
+
+ public Object getKs() {
+ return ks;
+ }
+
+ public Object getSpec() {
+ return spec;
+ }
}
import java.security.Principal;
import java.security.cert.Certificate;
+import java.security.cert.CertificateEncodingException;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
import javax.net.ssl.SSLSessionBindingEvent;
import javax.net.ssl.SSLSessionBindingListener;
import javax.net.ssl.SSLSessionContext;
+import javax.security.cert.CertificateException;
import javax.security.cert.X509Certificate;
import javax.net.ssl.SSLSession;
xCerts = xc;
}
+ public mySSLSession(Certificate[] xc) throws CertificateEncodingException, CertificateException {
+ certs = xc;
+ xCerts = new X509Certificate[xc.length];
+ int i = 0;
+ for (Certificate cert : xc) {
+ xCerts[i++] = X509Certificate.getInstance(cert.getEncoded());
+ }
+ }
+
+ public mySSLSession() {
+ }
+
public int getApplicationBufferSize() {
return 1234567;
}
+++ /dev/null
-package org.apache.harmony.xnet.tests.support;
-
-import javax.net.ssl.SSLSession;
-import javax.net.ssl.SSLSocket;
-import javax.net.ssl.HandshakeCompletedListener;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-
-/**
- * Additional class for SSLSocket constructor verification
- */
-public class mySSLSocket extends SSLSocket {
-
- private boolean init = false;
- private boolean sslFlag = true;
- private boolean sslNeed = false;
- private boolean sslWant = false;
- private int sslMode;
- private String[] supportProtocol = null;
- private String[] supportSuites = null;
-
- public mySSLSocket(int mode){
- super();
- sslMode = mode;
- }
- public mySSLSocket(String[] protocol, String[] suites){
- super();
- supportProtocol = protocol;
- supportSuites = suites;
- }
- public mySSLSocket(int mode, String[] protocol, String[] suites){
- super();
- sslMode = mode;
- supportProtocol = protocol;
- supportSuites = suites;
- }
- public mySSLSocket(){
- super();
- }
- public mySSLSocket(InetAddress address, int port) throws IOException{
- super(address, port);
- }
- public mySSLSocket(InetAddress address, int port,
- InetAddress clientAddress, int clientPort) throws IOException{
- super(address, port, clientAddress, clientPort);
- }
- public mySSLSocket(String host, int port) throws IOException, UnknownHostException{
- super(host, port);
- }
- public mySSLSocket(String host, int port, InetAddress clientAddress,
- int clientPort) throws IOException, UnknownHostException{
- super(host, port, clientAddress, clientPort);
- }
-
- public void addHandshakeCompletedListener(HandshakeCompletedListener listener) {
- if(listener == null) throw new IllegalArgumentException("listener is null");
- }
- public String[] getEnabledCipherSuites() {
- return supportSuites;
- }
- public String[] getEnabledProtocols() {
- return supportProtocol;
- }
- public boolean getEnableSessionCreation() {
- return sslFlag;
- }
- public boolean getNeedClientAuth() {
- if (sslMode == 1) {
- throw new IllegalStateException("Incorrect mode");
- } else return sslNeed;
- }
- public SSLSession getSession() {
- return null;
- }
- public String[] getSupportedCipherSuites() {
- if (supportSuites == null) {
- throw new NullPointerException();
- }
- if (supportSuites.length == 0) {
- return null;
- } else return supportSuites;
- }
- public String[] getSupportedProtocols() {
- if (supportProtocol == null) {
- throw new NullPointerException();
- }
- if (supportProtocol.length == 0) {
- return null;
- } else return supportProtocol;
- }
- public boolean getUseClientMode() {
- if (sslMode == 1) {
- return true;
- } else return false;
- }
- public boolean getWantClientAuth() {
- if (sslMode == 1) {
- throw new IllegalStateException("Incorrect mode");
- } else return sslWant;
- }
- public void removeHandshakeCompletedListener(HandshakeCompletedListener listener) {
- if(listener == null) throw new IllegalArgumentException("listener is null");
- }
- public void setEnabledCipherSuites(String[] suites) {
- if (suites == null) {
- throw new IllegalArgumentException("null parameter");
- }
- if (!suites.equals(supportSuites)) {
- throw new IllegalArgumentException("incorrect suite");
- }
- }
- 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 void setNeedClientAuth(boolean need) {
- if (sslMode == 0) {
- sslNeed = need;
- } else {
- throw new IllegalStateException("Incorrect mode");
- }
- }
- public void setUseClientMode(boolean mode) {
- if (!init) {
- if (mode && sslMode == 0) {
- sslMode = 1;
- } else if (!mode && sslMode == 1) {
- sslMode = 0;
- }
- } else {
- throw new IllegalArgumentException();
- }
- }
- public void setWantClientAuth(boolean want) {
- if (sslMode == 0) {
- sslWant = want;
- } else {
- throw new IllegalStateException("Incorrect mode");
- }
- }
- public void startHandshake() throws IOException {
- for (int i = 0; i < supportProtocol.length; i++) {
- if (supportProtocol[i] == "Protocol_2") {
- throw new IOException();
- }
- }
- init = true;
- }
-}
-
)
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());
}
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());
args = {int.class}
)
public final void test_createServerSocket_02() {
- MyServerSocketFactory sf = new MyServerSocketFactory();
+ ServerSocketFactory sf = ServerSocketFactory.getDefault();
int portNumber = Support_PortManager.getNextPort();
try {
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 {
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");
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 {
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");
}
}
}
-
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
public void test_Constructor() {
try {
MySocketFactory sf = new MySocketFactory();
- assertNotNull(sf);
- assertTrue(sf instanceof SocketFactory);
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
}
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};
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};
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};
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};
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;
}
}
suite.addTestSuite(X509KeyManagerTest.class);
suite.addTestSuite(SSLSessionTest.class);
suite.addTestSuite(SSLSessionBindingListenerTest.class);
- suite.addTestSuite(HandshakeCompletedListenerTest.class);
suite.addTestSuite(HostnameVerifierTest.class);
// $JUnit-END$
--- /dev/null
+/*
+ * $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 花子.co.jp. So would the CN in the certificate contain
+ * "xn--i8s592g.co.jp" in ASCII, or "花子.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" +
+ "aXVzZGF2aWVzQGdtYWlsLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC\n" +
+ "ggEBAMhjr5aCPoyp0R1iroWAfnEyBMGYWoCidH96yGPFjYLowez5aYKY1IOKTY2B\n" +
+ "lYho4O84X244QrZTRl8kQbYtxnGh4gSCD+Z8gjZ/gMvLUlhqOb+WXPAUHMB39GRy\n" +
+ "zerA/ZtrlUqf+lKo0uWcocxeRc771KN8cPH3nHZ0rV0Hx4ZAZy6U4xxObe4rtSVY\n" +
+ "07hNKXAb2odnVqgzcYiDkLV8ilvEmoNWMWrp8UBqkTcpEhYhCYp3cTkgJwMSuqv8\n" +
+ "BqnGd87xQU3FVZI4tbtkB+KzjD9zz8QCDJAfDjZHR03KNQ5mxOgXwxwKw6lGMaiV\n" +
+ "JTxpTKqym93whYk93l3ocEe55c0CAwEAAaN7MHkwCQYDVR0TBAIwADAsBglghkgB\n" +
+ "hvhCAQ0EHxYdT3BlblNTTCBHZW5lcmF0ZWQgQ2VydGlmaWNhdGUwHQYDVR0OBBYE\n" +
+ "FJ8Ud78/OrbKOIJCSBYs2tDLXofYMB8GA1UdIwQYMBaAFHua2o+QmU5S0qzbswNS\n" +
+ "yoemDT4NMA0GCSqGSIb3DQEBBQUAA4IBAQC3jRmEya6sQCkmieULcvx8zz1euCk9\n" +
+ "fSez7BEtki8+dmfMXe3K7sH0lI8f4jJR0rbSCjpmCQLYmzC3NxBKeJOW0RcjNBpO\n" +
+ "c2JlGO9auXv2GDP4IYiXElLJ6VSqc8WvDikv0JmCCWm0Zga+bZbR/EWN5DeEtFdF\n" +
+ "815CLpJZNcYwiYwGy/CVQ7w2TnXlG+mraZOz+owr+cL6J/ZesbdEWfjoS1+cUEhE\n" +
+ "HwlNrAu8jlZ2UqSgskSWlhYdMTAP9CPHiUv9N7FcT58Itv/I4fKREINQYjDpvQcx\n" +
+ "SaTYb9dr5sB4WLNglk7zxDtM80H518VvihTcP7FHL+Gn6g4j5fkI98+S\n" +
+ "-----END CERTIFICATE-----\n").getBytes();
+
+ /**
+ * CN=花子.co.jp
+ */
+ public final static byte[] X509_HANAKO = (
+ "-----BEGIN CERTIFICATE-----\n" +
+ "MIIESzCCAzOgAwIBAgIJAIz+EYMBU6aTMA0GCSqGSIb3DQEBBQUAMIGiMQswCQYD\n" +
+ "VQQGEwJDQTELMAkGA1UECBMCQkMxEjAQBgNVBAcTCVZhbmNvdXZlcjEWMBQGA1UE\n" +
+ "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VR0jBBgwFoAUe5raj5CZTlLS\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" +
+ "FGRlbW9faW50ZXJtZWRpYXRlX2NhMSUwIwYJKoZIhvcNAQkBFhZqdWxpdXNkYXZp\n" +
+ "ZXNAZ21haWwuY29tMB4XDTA2MTIxMTE1MzYyOVoXDTI4MTEwNTE1MzYyOVowgaQx\n" +
+ "CzAJBgNVBAYTAlVTMREwDwYDVQQIEwhNYXJ5bGFuZDEUMBIGA1UEBxMLRm9yZXN0\n" +
+ "IEhpbGwxFzAVBgNVBAoTDmh0dHBjb21wb25lbnRzMRowGAYDVQQLExF0ZXN0IGN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MPpj/+XRK9/42\n" +
+ "2xq+8bc6HojdtbCyug/fvBZvZqQXSmU8m8IVcMmWMz0ZQO8ee3QkBHMZfCy7P/kr\n" +
+ "VbWx/uETImUu+NZg22ewEw==\n" +
+ "-----END CERTIFICATE-----\n").getBytes();
+
+ /**
+ * CN=foo.com, subjectAlt=bar.com, subjectAlt=花子.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" +
+ "cnRpZmljYXRlczEQMA4GA1UEAxMHZm9vLmNvbTElMCMGCSqGSIb3DQEJARYWanVs\n" +
+ "aXVzZGF2aWVzQGdtYWlsLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC\n" +
+ "ggEBAMhjr5aCPoyp0R1iroWAfnEyBMGYWoCidH96yGPFjYLowez5aYKY1IOKTY2B\n" +
+ "lYho4O84X244QrZTRl8kQbYtxnGh4gSCD+Z8gjZ/gMvLUlhqOb+WXPAUHMB39GRy\n" +
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YcIpaGpiYraBLx3Tadih39QN65CnAh/zRDhLCUzKyt9l\n" +
+ "UGPLEUDzRHMPHLnSqT1n5UU5UDRytbjJPXzF+l/+WZIsanefWLsxnkgAuZe/oMMF\n" +
+ "EJMryEzOjg4Tfuc5qM0EXoPcQ/JlheaxZ40p2IyHqbsWV4MRYuFH4bkM\n" +
+ "-----END CERTIFICATE-----\n").getBytes();
+
+ /**
+ * CN=*.foo.com, subjectAlt=*.bar.com, subjectAlt=*.花子.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" +
+ "IEhpbGwxFzAVBgNVBAoTDmh0dHBjb21wb25lbnRzMRowGAYDVQQLExF0ZXN0IGNl\n" +
+ "cnRpZmljYXRlczESMBAGA1UEAxQJKi5mb28uY29tMSUwIwYJKoZIhvcNAQkBFhZq\n" +
+ "dWxpdXNkYXZpZXNAZ21haWwuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB\n" +
+ "CgKCAQEAyGOvloI+jKnRHWKuhYB+cTIEwZhagKJ0f3rIY8WNgujB7PlpgpjUg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GqRNykSFiEJindxOSAnAxK6q/wGqcZ3zvFB\n" +
+ "TcVVkji1u2QH4rOMP3PPxAIMkB8ONkdHTco1DmbE6BfDHArDqUYxqJUlPGlMqrKb\n" +
+ "3fCFiT3eXehwR7nlzQIDAQABo3sweTAJBgNVHRMEAjAAMCwGCWCGSAGG+EIBDQQf\n" +
+ "Fh1PcGVuU1NMIEdlbmVyYXRlZCBDZXJ0aWZpY2F0ZTAdBgNVHQ4EFgQUnxR3vz86\n" +
+ "tso4gkJIFiza0Mteh9gwHwYDVR0jBBgwFoAUe5raj5CZTlLSrNuzA1LKh6YNPg0w\n" +
+ "DQYJKoZIhvcNAQEFBQADggEBAGuZb8ai1NO2j4v3y9TLZvd5s0vh5/TE7n7RX+8U\n" +
+ "y37OL5k7x9nt0mM1TyAKxlCcY+9h6frue8MemZIILSIvMrtzccqNz0V1WKgA+Orf\n" +
+ "uUrabmn+CxHF5gpy6g1Qs2IjVYWA5f7FROn/J+Ad8gJYc1azOWCLQqSyfpNRLSvY\n" +
+ "EriQFEV63XvkJ8JrG62b+2OT2lqT4OO07gSPetppdlSa8NBSKP6Aro9RIX1ZjUZQ\n" +
+ "SpQFCfo02NO0uNRDPUdJx2huycdNb+AXHaO7eXevDLJ+QnqImIzxWiY6zLOdzjjI\n" +
+ "VBMkLHmnP7SjGSQ3XA4ByrQOxfOUTyLyE7NuemhHppuQPxE=\n" +
+ "-----END CERTIFICATE-----\n").getBytes();
+
+ /**
+ * subjectAlt=foo.com
+ */
+ public final static byte[] X509_NO_CNS_FOO = (
+ "-----BEGIN CERTIFICATE-----\n" +
+ "MIIESjCCAzKgAwIBAgIJAIz+EYMBU6aYMA0GCSqGSIb3DQEBBQUAMIGiMQswCQYD\n" +
+ "VQQGEwJDQTELMAkGA1UECBMCQkMxEjAQBgNVBAcTCVZhbmNvdXZlcjEWMBQGA1UE\n" +
+ "ChMNd3d3LmN1Y2JjLmNvbTEUMBIGA1UECxQLY29tbW9uc19zc2wxHTAbBgNVBAM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EAjl78oMjzFdsMy6F1sGg/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" +
+ "WhcNMDcxMTA1MjE0OTMxWjCBojELMAkGA1UEBhMCQ0ExCzAJBgNVBAgTAkJDMRIw\n" +
+ "EAYDVQQHEwlWYW5jb3V2ZXIxFjAUBgNVBAoTDXd3dy5jdWNiYy5jb20xFDASBgNV\n" +
+ "BAsUC2NvbW1vbnNfc3NsMR0wGwYDVQQDFBRkZW1vX2ludGVybWVkaWF0ZV9jYTEl\n" +
+ "MCMGCSqGSIb3DQEJARYWanVsaXVzZGF2aWVzQGdtY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QallE0KfGRiOIWPrPj/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" +
+ "Z21haWwuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAv+OnocmJ\n" +
+ "79UeO2hlCwK+Cle5uZWnU6uwJl+08z5cvebb5tT64WL9+psDbfgUH/Gm9JsuxKTg\n" +
+ "w1tZO/4duIgnaLNSx4HoqaTjwigd/hR3TsoGEPXTCkz1ikgTCOEDvl+iMid6aOrd\n" +
+ "mViE8HhscxKZ+h5FE7oHZyuT6gFoiaIXhFq+xK2w4ZwDz9L+paiwqywyUJJMnh9U\n" +
+ "jKorY+nua81N0oxpIhHPspCanDU4neMzCzYOZyLR/LqV5xORvHcFY84GWMz5hI25\n" +
+ "JbgaWJsYKuCAvNsnQwVoqKPGa7x1fn7x6oGsXJaCVt8weUwIj2xwg1lxMhrNaisH\n" +
+ "EvKpEAEnGGwWKQIDAQABo4HuMIHrMB0GA1UdDgQWBBSs3x4Ui8yJEVdeAOoq6ZLT\n" +
+ "9bYCEzCBuwYDVR0jBIGzMIGwgBSs3x4Ui8yJEVdeAOoq6ZLT9bYCE6GBjKSBiTCB\n" +
+ "hjELMAkGA1UEBhMCQ0ExCzAJBgNVBAgTAkJDMRYwFAYDVQQKEw13d3cuY3VjYmMu\n" +
+ "Y29tMRQwEgYDVQQLFAtjb21tb25zX3NzbDEVMBMGA1UEAxQMZGVtb19yb290X2Nh\n" +
+ "MSUwIwYJKoZIhvcNAQkBFhZqdWxpdXNkYXZpZXNAZ21haWwuY29tggkAlM3BnrI1\n" +
+ "rlswDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOCAQEAlPl3/8h1LttR1svC\n" +
+ "S8RXbHpAWIT2BEDhGHUNjSmgDQNkE/itf/FCEXh0tlU4bYdtBSOHzflbnzOyIPId\n" +
+ "VZeSWs33V38xDFy6KoVg1gT8JxkLmE5S1vWkpsHIlpw/U6r7KD0Kx9FYx5AiXjw0\n" +
+ "lzz/zlVNuO2U09KIDwDPVG1mBzQiMiSWj1U1pM4KxINkWQwDy/fvu/I983s8lW5z\n" +
+ "hf2WuFNzQN3fcMK5dpBE9NVIu27oYuGYh2sak34v+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" +
+ "MIIDcTCCAtqgAwIBAgIBATANBgkqhkiG9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tYWluMA0GCSqGSIb3DQEBBQUAA4GBAIgEwIoCSRkU3O7K\n" +
+ "USYaOYyfJB9hsvs6YpClvYXiQ/5kPGARP60pM62v4wC7wI9shEizokIAxY2+O3cC\n" +
+ "vwuJhNYaa2FJMELIwRN3XES8X8R6JHWbPaRjaAAPhczuEd8SZYy8yiVLmJTgw0gH\n" +
+ "BSW775NHlkjsscFVgXkNf0PobqJ9\n" +
+ "-----END CERTIFICATE-----").getBytes();
+
+}
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;
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;
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.
/**
+ * @throws IOException
* @tests javax.net.ssl.HandshakeCompletedEvent#HandshakeCompletedEvent(SSLSocket sock, SSLSession s)
*/
@TestTargetNew(
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);
}
}
/**
+ * @throws IOException
* @tests javax.net.ssl.HandshakeCompletedEvent#getCipherSuite()
*/
@TestTargetNew(
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(
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());
}
/**
+ * @throws IOException
* @tests javax.net.ssl.HandshakeCompletedEvent#getLocalPrincipal()
*/
@TestTargetNew(
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());
}
/**
+ * @throws IOException
* @tests javax.net.ssl.HandshakeCompletedEvent#getPeerCertificateChain()
*/
@TestTargetNew(
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();
}
/**
+ * @throws IOException
* @tests javax.net.ssl.HandshakeCompletedEvent#getPeerCertificates()
*/
@TestTargetNew(
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();
//expected
}
- session = new mySSLSession(null);
+ session = new mySSLSession((X509Certificate[]) null);
event = new HandshakeCompletedEvent(socket, session);
try {
Certificate[] res = event.getPeerCertificates();
}
/**
+ * @throws IOException
* @tests javax.net.ssl.HandshakeCompletedEvent#getPeerPrincipal()
*/
@TestTargetNew(
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());
}
/**
+ * @throws IOException
* @tests javax.net.ssl.HandshakeCompletedEvent#getSession()
*/
@TestTargetNew(
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();
}
/**
+ * @throws IOException
* @tests javax.net.ssl.HandshakeCompletedEvent#getSocket()
*/
@TestTargetNew(
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);
SSLSocket socket;
SSLSocket serverSocket;
MyHandshakeListener listener;
- int port = 1081;
+ int port = Support_PortManager.getNextPort();
String host = "localhost";
private String PASSWORD = "android";
* 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);
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;
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");
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();
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");
+++ /dev/null
-/*
- * 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);
- }
- }
-
-}
/*
- * 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));
+
+ }
}
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;
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());
}
} catch (IllegalArgumentException e) {
}
try {
- SSLSocketFactoryImpl ssf = new SSLSocketFactoryImpl();
+ SSLSocketFactory ssf = (SSLSocketFactory) SSLSocketFactory
+ .getDefault();
HttpsURLConnection.setDefaultSSLSocketFactory(ssf);
} catch (Exception e) {
fail("Unexpected exception " + e);
} catch (IllegalArgumentException e) {
}
try {
- SSLSocketFactoryImpl ssf = new SSLSocketFactoryImpl();
+ SSLSocketFactory ssf = (SSLSocketFactory) SSLSocketFactory
+ .getDefault();
con.setSSLSocketFactory(ssf);
} catch (Exception e) {
fail("Unexpected exception " + e);
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.KnownFailure;
import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
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]);
}
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(),
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);
}
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;
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);
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
}
}
*/
@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 {
}
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);
}
/**
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);
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(),
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);
public void test_Constructor02() {
//Null parameter
- List ls = null;
+ List<String> ls = null;
try {
KeyStoreBuilderParameters ksp = new KeyStoreBuilderParameters(ls);
fail("NullPointerException should be thrown");
}
//Empty parameter
- List lsEmpty = new ArrayList();
+ List<String> lsEmpty = new ArrayList<String>();
try {
KeyStoreBuilderParameters ksp = new KeyStoreBuilderParameters(lsEmpty);
fail("IllegalArgumentException should be thrown");
}
//Not null parameter
- List lsFiled = new ArrayList();;
+ List<String> lsFiled = new ArrayList<String>();;
lsFiled.add("Parameter1");
lsFiled.add("Parameter2");
try {
)
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++) {
package tests.api.javax.net.ssl;
+import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
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;
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 {
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;
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());
}
}
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
+ notes = "checks valid protocol values",
method = "getInstance",
args = {java.lang.String.class}
)
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());
}
}
*/
@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) {
}
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;
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;
/**
* Test for <code>SSLEngine()</code> constructor Assertion: creates
* SSLEngine object with null host and -1 port
+ * @throws NoSuchAlgorithmException
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
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,
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,
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);
/**
* Test for <code>getPeerHost()</code> method
+ * @throws NoSuchAlgorithmException
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
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,
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(
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()
*/
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);
}
}
/**
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.SSLEngine#getSupportedCipherSuites()
*/
@TestTargetNew(
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()
*/
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);
}
}
/**
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.SSLEngine#setEnableSessionCreation(boolean flag)
* @tests javax.net.ssl.SSLEngine#getEnableSessionCreation()
*/
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);
}
/**
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.SSLEngine#setNeedClientAuth(boolean need)
* @tests javax.net.ssl.SSLEngine#getNeedClientAuth()
*/
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());
}
/**
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.SSLEngine#setWantClientAuth(boolean want)
* @tests javax.net.ssl.SSLEngine#getWantClientAuth()
*/
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());
}
/**
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.SSLEngine#beginHandshake()
*/
@TestTargetNew(
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");
} 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);
}
/**
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.SSLEngine#setUseClientMode(boolean mode)
* @tests javax.net.ssl.SSLEngine#getUseClientMode()
*/
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());
}
try {
- sse = new mySSLEngine("new host", 1080);
+ sse = getEngine(null, 1080);
sse.setUseClientMode(true);
sse.beginHandshake();
try {
}
/**
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.SSLEngine#getSession()
*/
@TestTargetNew(
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(
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(
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) {
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
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 {
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;
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 {
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;
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 {
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);
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);
}
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
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 {
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 {
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;
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 {
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);
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 {
}
/**
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.SSLEngine#closeOutbound()
* @tests javax.net.ssl.SSLEngine#isOutboundDone()
*/
args = {}
)
})
- public void test_closeOutbound() {
- SSLEngine sse = new mySSLEngine();
+ public void test_closeOutbound() throws NoSuchAlgorithmException {
+ SSLEngine sse = getEngine();
try {
assertFalse(sse.isOutboundDone());
}
/**
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.SSLEngine#closeInbound()
* @tests javax.net.ssl.SSLEngine#isInboundDone()
*/
args = {}
)
})
- public void test_closeInbound() {
- SSLEngine sse = new mySSLEngine();
+ public void test_closeInbound() throws NoSuchAlgorithmException {
+ SSLEngine sse = getEngine();
try {
assertFalse(sse.isInboundDone());
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 {
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 {
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;
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 {
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);
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);
}
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 {
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 {
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;
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 {
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);
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);
}
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 {
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 {
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;
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 {
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);
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);
}
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 {
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 {
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;
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 {
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);
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
* 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;
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()
*/
public void test_Constructor() {
try {
MockSSLServerSocketFactory ssf = new MockSSLServerSocketFactory();
- assertTrue(ssf instanceof SSLServerSocketFactory);
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
}
assertNotNull("Incorrect default socket factory",
SSLServerSocketFactory.getDefault());
}
-
+
/**
* @tests javax.net.ssl.SSLServerSocketFactory#getDefaultCipherSuites()
*/
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()
*/
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);
}
* 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;
+
}
}
)
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);
}
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);
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);
}
try {
ssl = new mySSLServerSocket(portNumber, 1);
- assertNotNull(ssl);
assertEquals(portNumber, ssl.getLocalPort());
} catch (Exception ex) {
fail("Unexpected exception was thrown");
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");
}
try {
ssl = new mySSLServerSocket(portNumber, 0, ia);
- assertNotNull(ssl);
assertEquals(portNumber, ssl.getLocalPort());
} catch (Exception ex) {
fail("Unexpected exception was thrown");
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");
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");
}
}
/**
+ * @throws Exception
* @tests javax.net.ssl.SSLServerSocket#getSupportedCipherSuites()
*/
@TestTargetNew(
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)
*/
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(
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)
*/
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()
*/
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()
*/
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)
*/
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()
*/
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" +
+ "BAsTB0F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8EPceWF3dweoUT76+jEZx8lV2dapR+CmczQI43tV9btsd1xiBbBHAKvymm9Ep9bPzM" +
+ "J0MQi+OtURL9Lxke/70/MRueqbPeUlOaGvANTmXQD2OnW7PISwJ9lpeLfTG0LcqkoqkbtLKQLYHI" +
+ "rQfV5j0j+wmvmpMxzjN3uvNajLa4zQ8l0Eok9SFaRr2RL0gN8Q2JegfOL4pUiHPsh64WWya2NB7f" +
+ "V+1s65eA5ospXYsShRjo046QhGTmymwXXzdzuxu8IlnTEont6P4+J+GsWk6cldGbl20hctuUKzyx" +
+ "OptjEPOKejV60iDCYGmHbCWAzQ8h5MILV82IclzNViZmzAapeeCnexhpXhWTs+xDEYSKEiG/camt" +
+ "bhmZc3BcyVJrW23PktSfpBQ6D8ZxoMfF0L7V2GQMaUg+3r7ucrx82kpqotjv0xHghNIm95aBr1Qw" +
+ "1gaEjsC/0wGmmBDg1dTDH+F1p9TInzr3EFuYD0YiQ7YlAHq3cPuyGoLXJ5dXYuSBfhDXJSeddUkl" +
+ "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+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BAsTB0FuZHJvaWQxFDASBgNVBAMTC1Rlc3QgU2VydmVyMIGf" +
+ "MA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCwoC6chqCI84rj1PrXuJgbiit4EV909zR6N0jNlYfg" +
+ "itwB39bP39wH03rFm8T59b3mbSptnGmCIpLZn25KPPFsYD3JJ+wFlmiUdEP9H05flfwtFQJnw9uT" +
+ "3rRIdYVMPcQ3RoZzwAMliGr882I2thIDbA6xjGU/1nRIdvk0LtxH3QIDAQABMA0GCSqGSIb3DQEB" +
+ "BAUAA4GBAJn+6YgUlY18Ie+0+Vt8oEi81DNi/bfPrAUAh63fhhBikx/3R9dl3wh09Z6p7cIdNxjW" +
+ "n2ll+cRW9eqF7z75F0Omm0C7/KAEPjukVbszmzeU5VqzkpSt0j84YWi+TfcHRrfvhLbrlmGITVpY" +
+ "ol5pHLDyqGmDs53pgwipWqsn/nEXEBgj3EoqPeqHbDf7YaP8h/5BSt0=";
+
+ private String PASSWORD = "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;
}
}
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;
public class mySSLSessionBindingListener implements SSLSessionBindingListener {
- private boolean boundDone = false;
- private boolean unboundDone = false;
+ public boolean boundDone = false;
+ public boolean unboundDone = false;
mySSLSessionBindingListener() {
}
}
/**
+ * @throws IOException
+ * @throws UnknownHostException
+ * @throws InterruptedException
* @tests javax.net.ssl.SSLSessionBindingListener#valueBound(SSLSessionBindingEvent event)
*/
@TestTargetNew(
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(
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);
}
-
}
package tests.api.javax.net.ssl;
+import dalvik.annotation.BrokenTest;
import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
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.
public class SSLSessionContextTest extends TestCase {
/**
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.SSLSessionContex#getSessionCacheSize()
* @tests javax.net.ssl.SSLSessionContex#setSessionCacheSize(int size)
*/
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);
}
/**
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.SSLSessionContex#getSessionTimeout()
* @tests javax.net.ssl.SSLSessionContex#setSessionTimeout(int seconds)
*/
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);
}
/**
+ * @throws NoSuchAlgorithmException
* @tests javax.net.ssl.SSLSessionContex#getSession(byte[] sessionId)
*/
@TestTargetNew(
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(
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
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
*/
@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()
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
* @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);
}
* @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);
}
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);
}
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);
}
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());
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 {
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) {}
}
+
+ 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" +
+ "DPMF9ZqEDOaL6DJuu0colSBBBQ85hQTPa9m9nyJoN3pEi1hgamqOvQIWcXBk+SOpUGRZZFXwniJV" +
+ "zDKU5nE9MYgn2B9AoiH3CSuMz6HRqgVaqtppIe1jhukMc/kHVJvlKRNy9XMCAwEAATANBgkqhkiG" +
+ "9w0BAQUFAAOBgQC7yBmJ9O/eWDGtSH9BH0R3dh2NdST3W9hNZ8hIa8U8klhNHbUCSSktZmZkvbPU" +
+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mKg3U94r+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/NFAs4ObV8CAwEAATANBgkqhkiG" +
+ "9w0BAQUFAAOBgQCJrCr3hZQFDlLIfsSKI1/w+BLvyf4fubOid0pBxfklR8KBNPTiqjSmu7pd/C/F" +
+ "1FR8CdZUDoPflZHCOU+fj5r5KUC1HyigY/tEUvlforBpfB0uCF+tXW4DbUfOWhfMtLV4nCOJOOZg" +
+ "awfZLJWBJouLKOp427vDftxTSB+Ks8YjlgAAAqwAAA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ystore 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/kR0Sqz2WTGDoSoq" +
+ "ewuPRU5bzQs/b9daq3mXrnPtRBL6HfSDAdpTK76iHqLCGdqx3avHjVSBm4zFvEuYBCev+3iKOBmg" +
+ "yh7eQRTjz4UOWfy85omMBr7lK8PtfVBDzOXpasxS0uBgdUyBDX4tO6k9jZ8a1kmQRQAAAAEABVgu" +
+ "NTA5AAACSDCCAkQwggGtAgRIR8SKMA0GCSqGSIb3DQEBBAUAMGkxCzAJBgNVBAYTAlVTMRMwEQYD" +
+ "VQQIEwpDYWxpZm9ybmlhMQwwCgYDVQQHEwNNVFYxDzANBgNVBAoTBkdvb2dsZTEQMA4GA1UECxMH" +
+ "QW5kcm9pZDEUMBIGA1UEAxMLVGVzdCBTZXJ2ZXIwHhcNMDgwNjA1MTA0ODQyWhcNMDgwOTAzMTA0" +
+ "ODQyWjBpMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEMMAoGA1UEBxMDTVRWMQ8w" +
+ "DQYDVQQKEwZHb29nbGUxEDAOBgNVBAsTB0FuZHJvaWQxFDASBgNVBAMTC1Rlc3QgU2VydmVyMIGf" +
+ "MA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCwoC6chqCI84rj1PrXuJgbiit4EV909zR6N0jNlYfg" +
+ "itwB39bP39wH03rFm8T59b3mbSptnGmCIpLZn25KPPFsYD3JJ+wFlmiUdEP9H05flfwtFQJnw9uT" +
+ "3rRIdYVMPcQ3RoZzwAMliGr882I2thIDbA6xjGU/1nRIdvk0LtxH3QIDAQABMA0GCSqGSIb3DQEB" +
+ "BAUAA4GBAJn+6YgUlY18Ie+0+Vt8oEi81DNi/bfPrAUAh63fhhBikx/3R9dl3wh09Z6p7cIdNxjW" +
+ "n2ll+cRW9eqF7z75F0Omm0C7/KAEPjukVbszmzeU5VqzkpSt0j84YWi+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+7QAAAAIAAAABAAAAAQAFbXlrZ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BQAwaTELMAkGA1UEBhMCVVMxEzARBgNV" +
+ "BAgTCkNhbGlmb3JuaWExDDAKBgNVBAcTA01UVjEPMA0GA1UEChMGR29vZ2xlMRAwDgYDVQQLEwdB" +
+ "bmRyb2lkMRQwEgYDVQQDEwtUZXN0IENsaWVudDAeFw0wODA2MDUxMDQ5MjhaFw0wODA5MDMxMDQ5" +
+ "MjhaMGkxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMQwwCgYDVQQHEwNNVFYxDzAN" +
+ "BgNVBAoTBkdvb2dsZTEQMA4GA1UECxMHQW5kcm9pZDEUMBIGA1UEAxMLVGVzdCBDbGllbnQwgZ8w" +
+ "DQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAIK3Q+KiFbmCGg422TAo4gggdhMH6FJhiuz8DxRyeMKR" +
+ "UAfP4MK0wtc8N42waZ6OKvxpBFUy0BRfBsX0GD4Ku99yu9/tavSigTraeJtwV3WWRRjIqk7L3wX5" +
+ "cmgS2KSD43Y0rNUKrko26lnt9N4qiYRBSj+tcAN3Lx9+ptqk1LApAgMBAAEwDQYJKoZIhvcNAQEE" +
+ "BQADgYEANb7Q1GVSuy1RPJ0FmiXoMYCCtvlRLkmJphwxovK0cAQK12Vll+yAzBhHiQHy/RA11mng" +
+ "wYudC7u3P8X/tBT8GR1Yk7QW3KgFyPafp3lQBBCraSsfrjKj+dCLig1uBLUr4f68W8VFWZWWTHqp" +
+ "NMGpCX6qmjbkJQLVK/Yfo1ePaUexPSOX0G9m8+DoV3iyNw6at01NRw==";
+
+
+ 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();
+ }
}
*/
package tests.api.javax.net.ssl;
+import dalvik.annotation.BrokenTest;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
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)
)
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());
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, ""};
)
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());
}
)
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());
}
*/
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)
)
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(
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
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]);
}
}
/**
+ * @throws IOException
+ * @throws UnknownHostException
* @tests javax.net.ssl.SSLSocket#SSLSocket(InetAddress address, int port,
* InetAddress clientAddress, int clientPort)
*/
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(
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
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)
*/
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
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]);
}
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(
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);
}
/**
+ * @throws IOException
* @tests javax.net.ssl.SSLSocket#removeHandshakeCompletedListener(HandshakeCompletedListener listener)
*/
@TestTargetNew(
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);
} 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) {
}
/**
+ * @throws IOException
* @tests javax.net.ssl.SSLSocket#setEnableSessionCreation(boolean flag)
* @tests javax.net.ssl.SSLSocket#getEnableSessionCreation()
*/
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()
*/
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()
*/
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(
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)
*/
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(
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(
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)
*/
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)
*/
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");
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" +
+ "BAsTB0FuZHJvaWQxFDASBgNVBAMTC1Rlc3QgU2VydmVyMB4XDTA4MDYwNTExNTgxNFoX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" +
+ "J0MQi+OtURL9Lxke/70/MRueqbPeUlOaGvANTmXQD2OnW7PISwJ9lpeLfTG0LcqkoqkbtLKQLYHI" +
+ "rQfV5j0j+wmvmpMxzjN3uvNajLa4zQ8l0Eok9SFaRr2RL0gN8Q2JegfOL4pUiHPsh64WWya2NB7f" +
+ "V+1s65eA5ospXYsShRjo046QhGTmymwXXzdzuxu8IlnTEont6P4+J+GsWk6cldGbl20hctuUKzyx" +
+ "OptjEPOKejV60iDCYGmHbCWAzQ8h5MILV82IclzNViZmzAapeeCnexhpXhWTs+xDEYSKEiG/camt" +
+ "bhmZc3BcyVJrW23PktSfpBQ6D8ZxoMfF0L7V2GQMaUg+3r7ucrx82kpqotjv0xHghNIm95aBr1Qw" +
+ "1gaEjsC/0wGmmBDg1dTDH+F1p9TInzr3EFuYD0YiQ7YlAHq3cPuyGoLXJ5dXYuSBfhDXJSeddUkl" +
+ "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/mxlMTOs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qGSIb3DQEBAQUAA4GNADCBiQKBgQCwoC6chqCI84rj1PrXuJgbiit4EV909zR6N0jNlYfg" +
+ "itwB39bP39wH03rFm8T59b3mbSptnGmCIpLZn25KPPFsYD3JJ+wFlmiUdEP9H05flfwtFQJnw9uT" +
+ "3rRIdYVMPcQ3RoZzwAMliGr882I2thIDbA6xjGU/1nRIdvk0LtxH3QIDAQABMA0GCSqGSIb3DQEB" +
+ "BAUAA4GBAJn+6YgUlY18Ie+0+Vt8oEi81DNi/bfPrAUAh63fhhBikx/3R9dl3wh09Z6p7cIdNxjW" +
+ "n2ll+cRW9eqF7z75F0Omm0C7/KAEPjukVbszmzeU5VqzkpSt0j84YWi+TfcHRrfvhLbrlmGITVpY" +
+ "ol5pHLDyqGmDs53pgwipWqsn/nEXEBgj3EoqPeqHbDf7YaP8h/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;
+ }
+}
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);
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;
@TestTargetClass(TrustManagerFactorySpi.class)
public class TrustManagerFactorySpiTest extends TestCase {
+ private TrustManagerFactorySpiImpl factory = new TrustManagerFactorySpiImpl();
/**
* @tests javax.net.ssl.TrustManagerFactorySpi#TrustManagerFactorySpi()
*/
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(
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(
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(
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;
+ }
+ });
+ }
+}
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:c1:6f:6c:1c:1d:c3:61:34:30:07:34:4d:6a:8b:55:6f:
+ 75:55:6e:15:58:c5:f8:af:e0:be:73:ba:d9:a5:85:d7:b5:1a:
+ 85:44:2b:88:fd:cc:cb:d1:ed:46:69:43:ff:59:ae:9b:5c:17:
+ 26:da:ee:c8:bf:67:55:01:a0:0e:10:b9:85:49:54:d9:79:1e:
+ 7b:2e:6f:65:4f:d9:10:2e:9d:b8:92:63:67:74:8b:22:0d:6d:
+ d3:5d:9e:29:63:f9:36:93:1b:a7:80:e2:b1:f1:bf:29:19:81:
+ 3d:07
+ */
+ String certificate = "-----BEGIN CERTIFICATE-----\n"
+ + "MIIDPzCCAqigAwIBAgIBADANBgkqhkiG9w0BAQUFADB5MQswCQYDVQQGEwJBTjEQ\n"
+ + "MA4GA1UECBMHQW5kcm9pZDEQMA4GA1UEChMHQW5kc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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"
+ + "MA4GA1UECBMHQW5kcm9pZDEQMA4GA1UEChMHQW5kcm9pZDEQMA4GA1UECxMHQW5k\n"
+ + "cm9pZDEQMA4GA1UEAxMHQW5kcm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBh\n"
+ + "bmRyb2lkLmNvbTAeFw0wOTAzMjAxNzAwNDBaFw0xMDAzMjAxNzAwNDBaMIGLMQsw\n"
+ + "CQYDVQQGEwJBTjEQMA4GA1UECBMHQW5kcm9pZDEQMA4GA1UEBxMHQW5kcm9pZDEQ\n"
+ + "MA4GA1UEChMHQW5kcm9pZDEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5k\n"
+ + "cm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbTCBnzANBgkq\n"
+ + "hkiG9w0BAQEFAAOBjQAwgYkCgYEA0ERaxHbvrv+ZW8M3wQkzwZflZHqpfphLOqMz\n"
+ + "0FzHVqzYQuhKrJzZj4mEyEaVziL3agnekUecOCOlSvwIr1q0bjmO6fUORgBp4eXM\n"
+ + "TIG2gntW+/TcBP9h4n5f4vmXU5PUaZu6eSDNHj7VmkSVfM/BUfIi/OzMZhh0YCqi\n"
+ + "vgbCno0CAwEAAaN7MHkwCQYDVR0TBAIwADAsBglghkgBhvhCAQ0EHxYdT3BlblNT\n"
+ + "TCBHZW5lcmF0ZWQgQ2VydGlmaWNhdGUwHQYDVR0OBBYEFJU+w0ZpUngIBUa5AGnl\n"
+ + "56eZ48RnMB8GA1UdIwQYMBaAFOebfZAp6pALfwhBdk5BI+hDLKkDMA0GCSqGSIb3\n"
+ + "DQEBBQUAA4GBAKNbMPUoP4f2GzZqIm1mSPrL7kwEzxEU4h+1aAznYQ6802kZAovV\n"
+ + "0wVKyCno49DpMq1sfZzERmz5ZuZkYEdr747IHGdaWs9zo36dbokMZ5kXPbK4jkGV\n"
+ + "nISVv1eVJCKPGRLB/SNFdX9PYQbjnwXc5ymaaxfh4TfVi7q00Io83T9q\n\n"
+ + "-----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:9c:78:3a:88:3e:55:19:
+ 86:31:e8:53:3d:74:e2:4a:34:9f:92:17:4e:13:46:92:54:f8:
+ 43:eb:5e:03:4f:14:51:61:d2:04:b8:04:5a:31:eb:14:6a:18:
+ b0:20:03:92:0c:7f:07:c4:1b:f9:9e:7f:5f:ec:03:7a:c8:e3:
+ df:d3:94:6e:68:8a:3a:3d:e4:61:f3:e0:87:5d:40:d8:cb:99:
+ 4d:9a:7b:bc:95:7c:d2:9d:b7:04:9a:9a:63:89:cd:39:ec:32:
+ 60:0a:97:da:e9:50:a5:73:4a:a2:aa:9c:9b:a8:7f:5a:20:d6:
+ 48:bd
+ */
+ String certificate3 = "-----BEGIN CERTIFICATE-----\n"
+ + "MIIC9jCCAl+gAwIBAgIBAjANBgkqhkiG9w0BAQUFADB5MQswCQYDVQQGEwJBTjEQ\n"
+ + "MA4GA1U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ki9\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)
*/
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));
}
/**
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);
}
/**
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]);
}
/**
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);
}
/**
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"));
}
/**
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"));
}
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;
}
}