1ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom/* 2ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom * Copyright (C) 2010 The Android Open Source Project 3ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom * 4ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom * Licensed under the Apache License, Version 2.0 (the "License"); 5ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom * you may not use this file except in compliance with the License. 6ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom * You may obtain a copy of the License at 7ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom * 8ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom * http://www.apache.org/licenses/LICENSE-2.0 9ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom * 10ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom * Unless required by applicable law or agreed to in writing, software 11ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom * distributed under the License is distributed on an "AS IS" BASIS, 12ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom * See the License for the specific language governing permissions and 14ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom * limitations under the License. 15ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom */ 16ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom 174557728efb66c455a52b7669a8eefef7a9e54854Jesse Wilsonpackage libcore.javax.net.ssl; 18ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom 197fdd2c384f5b419e360017ffe640af1246123534Ed Heylimport java.lang.reflect.Field; 207fdd2c384f5b419e360017ffe640af1246123534Ed Heylimport java.lang.reflect.Method; 21ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstromimport java.net.InetAddress; 22ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstromimport java.net.InetSocketAddress; 230c131a2ca38465b7d1df4eaee63ac73ce4d5986dBrian Carlstromimport java.net.ServerSocket; 240c131a2ca38465b7d1df4eaee63ac73ce4d5986dBrian Carlstromimport java.net.Socket; 250c131a2ca38465b7d1df4eaee63ac73ce4d5986dBrian Carlstromimport java.net.SocketException; 267fdd2c384f5b419e360017ffe640af1246123534Ed Heylimport java.security.KeyManagementException; 277fdd2c384f5b419e360017ffe640af1246123534Ed Heylimport java.security.Provider; 287fdd2c384f5b419e360017ffe640af1246123534Ed Heylimport java.security.SecureRandom; 297fdd2c384f5b419e360017ffe640af1246123534Ed Heylimport java.security.Security; 307fdd2c384f5b419e360017ffe640af1246123534Ed Heylimport java.util.Properties; 31ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstromimport javax.net.ServerSocketFactory; 32ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstromimport javax.net.SocketFactory; 337fdd2c384f5b419e360017ffe640af1246123534Ed Heylimport javax.net.ssl.KeyManager; 347fdd2c384f5b419e360017ffe640af1246123534Ed Heylimport javax.net.ssl.SSLContext; 357fdd2c384f5b419e360017ffe640af1246123534Ed Heylimport javax.net.ssl.SSLContextSpi; 367fdd2c384f5b419e360017ffe640af1246123534Ed Heylimport javax.net.ssl.SSLEngine; 377fdd2c384f5b419e360017ffe640af1246123534Ed Heylimport javax.net.ssl.SSLServerSocketFactory; 387fdd2c384f5b419e360017ffe640af1246123534Ed Heylimport javax.net.ssl.SSLSessionContext; 394557728efb66c455a52b7669a8eefef7a9e54854Jesse Wilsonimport javax.net.ssl.SSLSocket; 404557728efb66c455a52b7669a8eefef7a9e54854Jesse Wilsonimport javax.net.ssl.SSLSocketFactory; 417fdd2c384f5b419e360017ffe640af1246123534Ed Heylimport javax.net.ssl.TrustManager; 42ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstromimport junit.framework.TestCase; 437fdd2c384f5b419e360017ffe640af1246123534Ed Heylimport libcore.java.security.StandardNames; 44ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom 45ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrompublic class SSLSocketFactoryTest extends TestCase { 467fdd2c384f5b419e360017ffe640af1246123534Ed Heyl private static final String SSL_PROPERTY = "ssl.SocketFactory.provider"; 477fdd2c384f5b419e360017ffe640af1246123534Ed Heyl 48ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom public void test_SSLSocketFactory_getDefault() { 49ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom SocketFactory sf = SSLSocketFactory.getDefault(); 50ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom assertNotNull(sf); 51ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom assertTrue(SSLSocketFactory.class.isAssignableFrom(sf.getClass())); 52ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom } 53ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom 547fdd2c384f5b419e360017ffe640af1246123534Ed Heyl public static class FakeSSLSocketProvider extends Provider { 557fdd2c384f5b419e360017ffe640af1246123534Ed Heyl public FakeSSLSocketProvider() { 567fdd2c384f5b419e360017ffe640af1246123534Ed Heyl super("FakeSSLSocketProvider", 1.0, "Testing provider"); 577fdd2c384f5b419e360017ffe640af1246123534Ed Heyl put("SSLContext.Default", FakeSSLContextSpi.class.getName()); 587fdd2c384f5b419e360017ffe640af1246123534Ed Heyl } 597fdd2c384f5b419e360017ffe640af1246123534Ed Heyl } 607fdd2c384f5b419e360017ffe640af1246123534Ed Heyl 617fdd2c384f5b419e360017ffe640af1246123534Ed Heyl public static final class FakeSSLContextSpi extends SSLContextSpi { 627fdd2c384f5b419e360017ffe640af1246123534Ed Heyl @Override 637fdd2c384f5b419e360017ffe640af1246123534Ed Heyl protected void engineInit(KeyManager[] keyManagers, TrustManager[] trustManagers, 647fdd2c384f5b419e360017ffe640af1246123534Ed Heyl SecureRandom secureRandom) throws KeyManagementException { 657fdd2c384f5b419e360017ffe640af1246123534Ed Heyl throw new UnsupportedOperationException(); 667fdd2c384f5b419e360017ffe640af1246123534Ed Heyl } 677fdd2c384f5b419e360017ffe640af1246123534Ed Heyl 687fdd2c384f5b419e360017ffe640af1246123534Ed Heyl @Override 697fdd2c384f5b419e360017ffe640af1246123534Ed Heyl protected SSLSocketFactory engineGetSocketFactory() { 707fdd2c384f5b419e360017ffe640af1246123534Ed Heyl return new FakeSSLSocketFactory(); 717fdd2c384f5b419e360017ffe640af1246123534Ed Heyl } 727fdd2c384f5b419e360017ffe640af1246123534Ed Heyl 737fdd2c384f5b419e360017ffe640af1246123534Ed Heyl @Override 747fdd2c384f5b419e360017ffe640af1246123534Ed Heyl protected SSLServerSocketFactory engineGetServerSocketFactory() { 757fdd2c384f5b419e360017ffe640af1246123534Ed Heyl throw new UnsupportedOperationException(); 767fdd2c384f5b419e360017ffe640af1246123534Ed Heyl } 777fdd2c384f5b419e360017ffe640af1246123534Ed Heyl 787fdd2c384f5b419e360017ffe640af1246123534Ed Heyl @Override 797fdd2c384f5b419e360017ffe640af1246123534Ed Heyl protected SSLEngine engineCreateSSLEngine(String s, int i) { 807fdd2c384f5b419e360017ffe640af1246123534Ed Heyl throw new UnsupportedOperationException(); 817fdd2c384f5b419e360017ffe640af1246123534Ed Heyl } 827fdd2c384f5b419e360017ffe640af1246123534Ed Heyl 837fdd2c384f5b419e360017ffe640af1246123534Ed Heyl @Override 847fdd2c384f5b419e360017ffe640af1246123534Ed Heyl protected SSLEngine engineCreateSSLEngine() { 857fdd2c384f5b419e360017ffe640af1246123534Ed Heyl throw new UnsupportedOperationException(); 867fdd2c384f5b419e360017ffe640af1246123534Ed Heyl } 877fdd2c384f5b419e360017ffe640af1246123534Ed Heyl 887fdd2c384f5b419e360017ffe640af1246123534Ed Heyl @Override 897fdd2c384f5b419e360017ffe640af1246123534Ed Heyl protected SSLSessionContext engineGetServerSessionContext() { 907fdd2c384f5b419e360017ffe640af1246123534Ed Heyl throw new UnsupportedOperationException(); 917fdd2c384f5b419e360017ffe640af1246123534Ed Heyl } 927fdd2c384f5b419e360017ffe640af1246123534Ed Heyl 937fdd2c384f5b419e360017ffe640af1246123534Ed Heyl @Override 947fdd2c384f5b419e360017ffe640af1246123534Ed Heyl protected SSLSessionContext engineGetClientSessionContext() { 957fdd2c384f5b419e360017ffe640af1246123534Ed Heyl throw new UnsupportedOperationException(); 967fdd2c384f5b419e360017ffe640af1246123534Ed Heyl } 977fdd2c384f5b419e360017ffe640af1246123534Ed Heyl } 987fdd2c384f5b419e360017ffe640af1246123534Ed Heyl 997fdd2c384f5b419e360017ffe640af1246123534Ed Heyl public static class FakeSSLSocketFactory extends SSLSocketFactory { 1007fdd2c384f5b419e360017ffe640af1246123534Ed Heyl public FakeSSLSocketFactory() { 1017fdd2c384f5b419e360017ffe640af1246123534Ed Heyl } 1027fdd2c384f5b419e360017ffe640af1246123534Ed Heyl 1037fdd2c384f5b419e360017ffe640af1246123534Ed Heyl @Override 1047fdd2c384f5b419e360017ffe640af1246123534Ed Heyl public String[] getDefaultCipherSuites() { 1057fdd2c384f5b419e360017ffe640af1246123534Ed Heyl throw new UnsupportedOperationException(); 1067fdd2c384f5b419e360017ffe640af1246123534Ed Heyl } 1077fdd2c384f5b419e360017ffe640af1246123534Ed Heyl 1087fdd2c384f5b419e360017ffe640af1246123534Ed Heyl @Override 1097fdd2c384f5b419e360017ffe640af1246123534Ed Heyl public String[] getSupportedCipherSuites() { 1107fdd2c384f5b419e360017ffe640af1246123534Ed Heyl throw new UnsupportedOperationException(); 1117fdd2c384f5b419e360017ffe640af1246123534Ed Heyl } 1127fdd2c384f5b419e360017ffe640af1246123534Ed Heyl 1137fdd2c384f5b419e360017ffe640af1246123534Ed Heyl @Override 1147fdd2c384f5b419e360017ffe640af1246123534Ed Heyl public Socket createSocket(Socket s, String host, int port, boolean autoClose) { 1157fdd2c384f5b419e360017ffe640af1246123534Ed Heyl throw new UnsupportedOperationException(); 1167fdd2c384f5b419e360017ffe640af1246123534Ed Heyl } 1177fdd2c384f5b419e360017ffe640af1246123534Ed Heyl 1187fdd2c384f5b419e360017ffe640af1246123534Ed Heyl @Override 1197fdd2c384f5b419e360017ffe640af1246123534Ed Heyl public Socket createSocket(InetAddress address, int port, InetAddress localAddress, 1207fdd2c384f5b419e360017ffe640af1246123534Ed Heyl int localPort) { 1217fdd2c384f5b419e360017ffe640af1246123534Ed Heyl throw new UnsupportedOperationException(); 1227fdd2c384f5b419e360017ffe640af1246123534Ed Heyl } 1237fdd2c384f5b419e360017ffe640af1246123534Ed Heyl 1247fdd2c384f5b419e360017ffe640af1246123534Ed Heyl @Override 1257fdd2c384f5b419e360017ffe640af1246123534Ed Heyl public Socket createSocket(InetAddress host, int port) { 1267fdd2c384f5b419e360017ffe640af1246123534Ed Heyl throw new UnsupportedOperationException(); 1277fdd2c384f5b419e360017ffe640af1246123534Ed Heyl } 1287fdd2c384f5b419e360017ffe640af1246123534Ed Heyl 1297fdd2c384f5b419e360017ffe640af1246123534Ed Heyl @Override 1307fdd2c384f5b419e360017ffe640af1246123534Ed Heyl public Socket createSocket(String host, int port, InetAddress localHost, int localPort) { 1317fdd2c384f5b419e360017ffe640af1246123534Ed Heyl throw new UnsupportedOperationException(); 1327fdd2c384f5b419e360017ffe640af1246123534Ed Heyl } 1337fdd2c384f5b419e360017ffe640af1246123534Ed Heyl 1347fdd2c384f5b419e360017ffe640af1246123534Ed Heyl @Override 1357fdd2c384f5b419e360017ffe640af1246123534Ed Heyl public Socket createSocket(String host, int port) { 1367fdd2c384f5b419e360017ffe640af1246123534Ed Heyl throw new UnsupportedOperationException(); 1377fdd2c384f5b419e360017ffe640af1246123534Ed Heyl } 1387fdd2c384f5b419e360017ffe640af1246123534Ed Heyl } 1397fdd2c384f5b419e360017ffe640af1246123534Ed Heyl 1407fdd2c384f5b419e360017ffe640af1246123534Ed Heyl public void test_SSLSocketFactory_getDefault_cacheInvalidate() throws Exception { 1417fdd2c384f5b419e360017ffe640af1246123534Ed Heyl String origProvider = resetSslProvider(); 1427fdd2c384f5b419e360017ffe640af1246123534Ed Heyl try { 1437fdd2c384f5b419e360017ffe640af1246123534Ed Heyl SocketFactory sf1 = SSLSocketFactory.getDefault(); 1447fdd2c384f5b419e360017ffe640af1246123534Ed Heyl assertNotNull(sf1); 1457fdd2c384f5b419e360017ffe640af1246123534Ed Heyl assertTrue(SSLSocketFactory.class.isAssignableFrom(sf1.getClass())); 1467fdd2c384f5b419e360017ffe640af1246123534Ed Heyl 1477fdd2c384f5b419e360017ffe640af1246123534Ed Heyl Provider fakeProvider = new FakeSSLSocketProvider(); 1487fdd2c384f5b419e360017ffe640af1246123534Ed Heyl SocketFactory sf4 = null; 1497fdd2c384f5b419e360017ffe640af1246123534Ed Heyl SSLContext origContext = null; 1507fdd2c384f5b419e360017ffe640af1246123534Ed Heyl try { 1517fdd2c384f5b419e360017ffe640af1246123534Ed Heyl origContext = SSLContext.getDefault(); 1527fdd2c384f5b419e360017ffe640af1246123534Ed Heyl Security.insertProviderAt(fakeProvider, 1); 1537fdd2c384f5b419e360017ffe640af1246123534Ed Heyl SSLContext.setDefault(SSLContext.getInstance("Default", fakeProvider)); 1547fdd2c384f5b419e360017ffe640af1246123534Ed Heyl 1557fdd2c384f5b419e360017ffe640af1246123534Ed Heyl sf4 = SSLSocketFactory.getDefault(); 1567fdd2c384f5b419e360017ffe640af1246123534Ed Heyl assertNotNull(sf4); 1577fdd2c384f5b419e360017ffe640af1246123534Ed Heyl assertTrue(SSLSocketFactory.class.isAssignableFrom(sf4.getClass())); 1587fdd2c384f5b419e360017ffe640af1246123534Ed Heyl 1597fdd2c384f5b419e360017ffe640af1246123534Ed Heyl assertFalse(sf1.getClass() + " should not be " + sf4.getClass(), 1607fdd2c384f5b419e360017ffe640af1246123534Ed Heyl sf1.getClass().equals(sf4.getClass())); 1617fdd2c384f5b419e360017ffe640af1246123534Ed Heyl } finally { 1627fdd2c384f5b419e360017ffe640af1246123534Ed Heyl SSLContext.setDefault(origContext); 1637fdd2c384f5b419e360017ffe640af1246123534Ed Heyl Security.removeProvider(fakeProvider.getName()); 1647fdd2c384f5b419e360017ffe640af1246123534Ed Heyl } 1657fdd2c384f5b419e360017ffe640af1246123534Ed Heyl 1667fdd2c384f5b419e360017ffe640af1246123534Ed Heyl SocketFactory sf3 = SSLSocketFactory.getDefault(); 1677fdd2c384f5b419e360017ffe640af1246123534Ed Heyl assertNotNull(sf3); 1687fdd2c384f5b419e360017ffe640af1246123534Ed Heyl assertTrue(SSLSocketFactory.class.isAssignableFrom(sf3.getClass())); 1697fdd2c384f5b419e360017ffe640af1246123534Ed Heyl 1707fdd2c384f5b419e360017ffe640af1246123534Ed Heyl assertTrue(sf1.getClass() + " should be " + sf3.getClass(), 1717fdd2c384f5b419e360017ffe640af1246123534Ed Heyl sf1.getClass().equals(sf3.getClass())); 1727fdd2c384f5b419e360017ffe640af1246123534Ed Heyl 1737fdd2c384f5b419e360017ffe640af1246123534Ed Heyl if (!StandardNames.IS_RI) { 1747fdd2c384f5b419e360017ffe640af1246123534Ed Heyl Security.setProperty(SSL_PROPERTY, FakeSSLSocketFactory.class.getName()); 1757fdd2c384f5b419e360017ffe640af1246123534Ed Heyl SocketFactory sf2 = SSLSocketFactory.getDefault(); 1767fdd2c384f5b419e360017ffe640af1246123534Ed Heyl assertNotNull(sf2); 1777fdd2c384f5b419e360017ffe640af1246123534Ed Heyl assertTrue(SSLSocketFactory.class.isAssignableFrom(sf2.getClass())); 1787fdd2c384f5b419e360017ffe640af1246123534Ed Heyl 1797fdd2c384f5b419e360017ffe640af1246123534Ed Heyl assertFalse(sf2.getClass().getName() + " should not be " + Security.getProperty(SSL_PROPERTY), 1807fdd2c384f5b419e360017ffe640af1246123534Ed Heyl sf1.getClass().equals(sf2.getClass())); 1817fdd2c384f5b419e360017ffe640af1246123534Ed Heyl assertTrue(sf2.getClass().equals(sf4.getClass())); 1827fdd2c384f5b419e360017ffe640af1246123534Ed Heyl 1837fdd2c384f5b419e360017ffe640af1246123534Ed Heyl resetSslProvider(); 1847fdd2c384f5b419e360017ffe640af1246123534Ed Heyl } 1857fdd2c384f5b419e360017ffe640af1246123534Ed Heyl } finally { 1867fdd2c384f5b419e360017ffe640af1246123534Ed Heyl Security.setProperty(SSL_PROPERTY, origProvider); 1877fdd2c384f5b419e360017ffe640af1246123534Ed Heyl } 1887fdd2c384f5b419e360017ffe640af1246123534Ed Heyl } 1897fdd2c384f5b419e360017ffe640af1246123534Ed Heyl 1902ac945d29ed72c3fa31494bba328087313a5d54dKenny Root /** 1912ac945d29ed72c3fa31494bba328087313a5d54dKenny Root * Should only run on Android. 1922ac945d29ed72c3fa31494bba328087313a5d54dKenny Root */ 1937fdd2c384f5b419e360017ffe640af1246123534Ed Heyl private String resetSslProvider() { 1947fdd2c384f5b419e360017ffe640af1246123534Ed Heyl String origProvider = Security.getProperty(SSL_PROPERTY); 1957fdd2c384f5b419e360017ffe640af1246123534Ed Heyl 1967fdd2c384f5b419e360017ffe640af1246123534Ed Heyl try { 1974c475e686706baa722f061d191bfe57d7dac9022Narayan Kamath Field field_secprops = Security.class.getDeclaredField("props"); 1987fdd2c384f5b419e360017ffe640af1246123534Ed Heyl field_secprops.setAccessible(true); 1997fdd2c384f5b419e360017ffe640af1246123534Ed Heyl Properties secprops = (Properties) field_secprops.get(null); 2007fdd2c384f5b419e360017ffe640af1246123534Ed Heyl secprops.remove(SSL_PROPERTY); 2012ac945d29ed72c3fa31494bba328087313a5d54dKenny Root Method m_increaseVersion = Security.class.getDeclaredMethod("increaseVersion"); 2022ac945d29ed72c3fa31494bba328087313a5d54dKenny Root m_increaseVersion.invoke(null); 2037fdd2c384f5b419e360017ffe640af1246123534Ed Heyl } catch (Exception e) { 2047fdd2c384f5b419e360017ffe640af1246123534Ed Heyl e.printStackTrace(); 2054c475e686706baa722f061d191bfe57d7dac9022Narayan Kamath throw new RuntimeException("Could not clear security provider", e); 2067fdd2c384f5b419e360017ffe640af1246123534Ed Heyl } 2077fdd2c384f5b419e360017ffe640af1246123534Ed Heyl 208fa7f9bad0ae25224a366828c538bd1f0c179b56bKenny Root assertNull(Security.getProperty(SSL_PROPERTY)); 2097fdd2c384f5b419e360017ffe640af1246123534Ed Heyl return origProvider; 2107fdd2c384f5b419e360017ffe640af1246123534Ed Heyl } 2117fdd2c384f5b419e360017ffe640af1246123534Ed Heyl 212f605c6822da13b32cd3643415a707882b62a3e91Alex Klyubin public void test_SSLSocketFactory_defaultConfiguration() throws Exception { 213782740701db73dd2dc4fef9df8cde270b0e631a4Alex Klyubin SSLConfigurationAsserts.assertSSLSocketFactoryDefaultConfiguration( 214f605c6822da13b32cd3643415a707882b62a3e91Alex Klyubin (SSLSocketFactory) SSLSocketFactory.getDefault()); 215f605c6822da13b32cd3643415a707882b62a3e91Alex Klyubin } 216f605c6822da13b32cd3643415a707882b62a3e91Alex Klyubin 217f605c6822da13b32cd3643415a707882b62a3e91Alex Klyubin public void test_SSLSocketFactory_getDefaultCipherSuitesReturnsCopies() { 218ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom SSLSocketFactory sf = (SSLSocketFactory) SSLSocketFactory.getDefault(); 219f605c6822da13b32cd3643415a707882b62a3e91Alex Klyubin assertNotSame(sf.getDefaultCipherSuites(), sf.getDefaultCipherSuites()); 220ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom } 221ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom 222f605c6822da13b32cd3643415a707882b62a3e91Alex Klyubin public void test_SSLSocketFactory_getSupportedCipherSuitesReturnsCopies() { 223ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom SSLSocketFactory sf = (SSLSocketFactory) SSLSocketFactory.getDefault(); 224f605c6822da13b32cd3643415a707882b62a3e91Alex Klyubin assertNotSame(sf.getSupportedCipherSuites(), sf.getSupportedCipherSuites()); 225ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom } 226ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom 227ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom public void test_SSLSocketFactory_createSocket() throws Exception { 228ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom try { 229ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom SSLSocketFactory sf = (SSLSocketFactory) SSLSocketFactory.getDefault(); 230ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom Socket s = sf.createSocket(null, null, -1, false); 231ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom fail(); 232e9505132a9a878aa77b0fb40a40dd55c9e6affe7Brian Carlstrom } catch (NullPointerException expected) { 233ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom } 234ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom 235ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom try { 236ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom SSLSocketFactory sf = (SSLSocketFactory) SSLSocketFactory.getDefault(); 237ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom Socket ssl = sf.createSocket(new Socket(), null, -1, false); 238ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom fail(); 239e9505132a9a878aa77b0fb40a40dd55c9e6affe7Brian Carlstrom } catch (SocketException expected) { 240ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom } 241ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom 242ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom ServerSocket ss = ServerSocketFactory.getDefault().createServerSocket(0); 243ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom InetSocketAddress sa = (InetSocketAddress) ss.getLocalSocketAddress(); 244ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom InetAddress host = sa.getAddress(); 245ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom int port = sa.getPort(); 246ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom Socket s = new Socket(host, port); 247ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom SSLSocketFactory sf = (SSLSocketFactory) SSLSocketFactory.getDefault(); 248ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom Socket ssl = sf.createSocket(s, null, -1, false); 249ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom assertNotNull(ssl); 250ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom assertTrue(SSLSocket.class.isAssignableFrom(ssl.getClass())); 251ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom } 252ebabb91c8c87ac2be2dca70ae343130f9755047fBrian Carlstrom} 253