Frames | No Frames |
1: /* SSLSocketFactoryImpl.java -- 2: Copyright (C) 2006, 2007 Free Software Foundation, Inc. 3: 4: This file is a part of GNU Classpath. 5: 6: GNU Classpath is free software; you can redistribute it and/or modify 7: it under the terms of the GNU General Public License as published by 8: the Free Software Foundation; either version 2 of the License, or (at 9: your option) any later version. 10: 11: GNU Classpath is distributed in the hope that it will be useful, but 12: WITHOUT ANY WARRANTY; without even the implied warranty of 13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14: General Public License for more details. 15: 16: You should have received a copy of the GNU General Public License 17: along with GNU Classpath; if not, write to the Free Software 18: Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 19: USA 20: 21: Linking this library statically or dynamically with other modules is 22: making a combined work based on this library. Thus, the terms and 23: conditions of the GNU General Public License cover the whole 24: combination. 25: 26: As a special exception, the copyright holders of this library give you 27: permission to link this library with independent modules to produce an 28: executable, regardless of the license terms of these independent 29: modules, and to copy and distribute the resulting executable under 30: terms of your choice, provided that you also meet, for each linked 31: independent module, the terms and conditions of the license of that 32: module. An independent module is a module which is not derived from 33: or based on this library. If you modify this library, you may extend 34: this exception to your version of the library, but you are not 35: obligated to do so. If you do not wish to do so, delete this 36: exception statement from your version. */ 37: 38: 39: package gnu.javax.net.ssl.provider; 40: 41: import java.io.IOException; 42: import java.net.InetAddress; 43: import java.net.InetSocketAddress; 44: import java.net.Socket; 45: import java.net.UnknownHostException; 46: 47: import javax.net.ssl.SSLSocketFactory; 48: 49: /** 50: * @author Casey Marshall (csm@gnu.org) 51: */ 52: public class SSLSocketFactoryImpl extends SSLSocketFactory 53: { 54: /** 55: * The SSLContextImpl that created us. 56: */ 57: private final SSLContextImpl contextImpl; 58: 59: public SSLSocketFactoryImpl(SSLContextImpl contextImpl) 60: { 61: this.contextImpl = contextImpl; 62: } 63: 64: /* (non-Javadoc) 65: * @see javax.net.ssl.SSLSocketFactory#createSocket(java.net.Socket, java.lang.String, int, boolean) 66: */ 67: @Override public Socket createSocket(Socket socket, String host, int port, 68: boolean autoClose) 69: throws IOException 70: { 71: return new SSLSocketImpl(contextImpl, host, port, socket, autoClose); 72: } 73: 74: /* (non-Javadoc) 75: * @see javax.net.ssl.SSLSocketFactory#getDefaultCipherSuites() 76: */ 77: @Override public String[] getDefaultCipherSuites() 78: { 79: return SSLEngineImpl.defaultSuites(); 80: } 81: 82: /* (non-Javadoc) 83: * @see javax.net.ssl.SSLSocketFactory#getSupportedCipherSuites() 84: */ 85: @Override public String[] getSupportedCipherSuites() 86: { 87: return CipherSuite.availableSuiteNames().toArray(new String[0]); 88: } 89: 90: /* (non-Javadoc) 91: * @see javax.net.SocketFactory#createSocket(java.lang.String, int) 92: */ 93: @Override public SSLSocketImpl createSocket(String host, int port) 94: throws IOException, UnknownHostException 95: { 96: return createSocket(host, port, null, 0); 97: } 98: 99: /* (non-Javadoc) 100: * @see javax.net.SocketFactory#createSocket(java.lang.String, int, java.net.InetAddress, int) 101: */ 102: @Override public SSLSocketImpl createSocket(String host, int port, 103: InetAddress localHost, int localPort) 104: throws IOException, UnknownHostException 105: { 106: SSLSocketImpl socket = new SSLSocketImpl(contextImpl, host, port); 107: InetSocketAddress endpoint = new InetSocketAddress(host, port); 108: socket.bind(new InetSocketAddress(localHost, localPort)); 109: socket.connect(endpoint); 110: return socket; 111: } 112: 113: /* (non-Javadoc) 114: * @see javax.net.SocketFactory#createSocket(java.net.InetAddress, int) 115: */ 116: @Override public SSLSocketImpl createSocket(InetAddress host, int port) 117: throws IOException 118: { 119: return createSocket(host, port, null, 0); 120: } 121: 122: /* (non-Javadoc) 123: * @see javax.net.SocketFactory#createSocket(java.net.InetAddress, int, java.net.InetAddress, int) 124: */ 125: @Override public SSLSocketImpl createSocket(InetAddress host, int port, 126: InetAddress localHost, int localPort) 127: throws IOException 128: { 129: SSLSocketImpl socket = new SSLSocketImpl(contextImpl, 130: host.getCanonicalHostName(), port); 131: socket.bind(new InetSocketAddress(localHost, localPort)); 132: socket.connect(new InetSocketAddress(host, port)); 133: return socket; 134: } 135: 136: /* (non-Javadoc) 137: * @see javax.net.SocketFactory#createSocket() 138: */ 139: @Override public Socket createSocket() throws IOException 140: { 141: return new SSLSocketImpl(contextImpl, null, -1, new Socket(), true); 142: } 143: }