author | xuelei |
Fri, 08 Apr 2011 02:00:09 -0700 | |
changeset 9246 | c459f79af46b |
parent 5506 | 202f599c92aa |
child 13815 | 2de30ecf335e |
permissions | -rw-r--r-- |
2 | 1 |
/* |
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
5506
diff
changeset
|
2 |
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.security.ssl; |
|
27 |
||
28 |
import java.io.*; |
|
29 |
import java.net.*; |
|
30 |
import javax.net.ssl.SSLSocketFactory; |
|
31 |
import javax.net.ssl.SSLSocket; |
|
32 |
||
33 |
||
34 |
/** |
|
35 |
* Implementation of an SSL socket factory. This provides the public |
|
36 |
* hooks to create SSL sockets, using a "high level" programming |
|
37 |
* interface which encapsulates system security policy defaults rather than |
|
38 |
* offering application flexibility. In particular, it uses a configurable |
|
39 |
* authentication context (and the keys held there) rather than offering |
|
40 |
* any flexibility about which keys to use; that context defaults to the |
|
41 |
* process-default context, but may be explicitly specified. |
|
42 |
* |
|
43 |
* @author David Brownell |
|
44 |
*/ |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
5506
diff
changeset
|
45 |
final public class SSLSocketFactoryImpl extends SSLSocketFactory { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
5506
diff
changeset
|
46 |
|
2 | 47 |
private static SSLContextImpl defaultContext; |
48 |
private SSLContextImpl context; |
|
49 |
||
50 |
/** |
|
51 |
* Constructor used to instantiate the default factory. This method is |
|
52 |
* only called if the old "ssl.SocketFactory.provider" property in the |
|
53 |
* java.security file is set. |
|
54 |
*/ |
|
55 |
public SSLSocketFactoryImpl() throws Exception { |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
5506
diff
changeset
|
56 |
this.context = SSLContextImpl.DefaultSSLContext.getDefaultImpl(); |
2 | 57 |
} |
58 |
||
59 |
/** |
|
60 |
* Constructs an SSL socket factory. |
|
61 |
*/ |
|
62 |
SSLSocketFactoryImpl(SSLContextImpl context) { |
|
63 |
this.context = context; |
|
64 |
} |
|
65 |
||
66 |
/** |
|
67 |
* Creates an unconnected socket. |
|
68 |
* |
|
69 |
* @return the unconnected socket |
|
70 |
* @see java.net.Socket#connect(java.net.SocketAddress, int) |
|
71 |
*/ |
|
72 |
public Socket createSocket() { |
|
73 |
return new SSLSocketImpl(context); |
|
74 |
} |
|
75 |
||
76 |
/** |
|
77 |
* Constructs an SSL connection to a named host at a specified port. |
|
78 |
* This acts as the SSL client, and may authenticate itself or rejoin |
|
79 |
* existing SSL sessions allowed by the authentication context which |
|
80 |
* has been configured. |
|
81 |
* |
|
82 |
* @param host name of the host with which to connect |
|
83 |
* @param port number of the server's port |
|
84 |
*/ |
|
85 |
public Socket createSocket(String host, int port) |
|
86 |
throws IOException, UnknownHostException |
|
87 |
{ |
|
88 |
return new SSLSocketImpl(context, host, port); |
|
89 |
} |
|
90 |
||
91 |
/** |
|
92 |
* Returns a socket layered over an existing socket to a |
|
93 |
* ServerSocket on the named host, at the given port. This |
|
94 |
* constructor can be used when tunneling SSL through a proxy. The |
|
95 |
* host and port refer to the logical destination server. This |
|
96 |
* socket is configured using the socket options established for |
|
97 |
* this factory. |
|
98 |
* |
|
99 |
* @param s the existing socket |
|
100 |
* @param host the server host |
|
101 |
* @param port the server port |
|
102 |
* @param autoClose close the underlying socket when this socket is closed |
|
103 |
* |
|
104 |
* @exception IOException if the connection can't be established |
|
105 |
* @exception UnknownHostException if the host is not known |
|
106 |
*/ |
|
107 |
public Socket createSocket(Socket s, String host, int port, |
|
108 |
boolean autoClose) throws IOException { |
|
109 |
return new SSLSocketImpl(context, s, host, port, autoClose); |
|
110 |
} |
|
111 |
||
112 |
||
113 |
/** |
|
114 |
* Constructs an SSL connection to a server at a specified address |
|
115 |
* and TCP port. This acts as the SSL client, and may authenticate |
|
116 |
* itself or rejoin existing SSL sessions allowed by the authentication |
|
117 |
* context which has been configured. |
|
118 |
* |
|
119 |
* @param address the server's host |
|
120 |
* @param port its port |
|
121 |
*/ |
|
122 |
public Socket createSocket(InetAddress address, int port) |
|
123 |
throws IOException |
|
124 |
{ |
|
125 |
return new SSLSocketImpl(context, address, port); |
|
126 |
} |
|
127 |
||
128 |
||
129 |
/** |
|
130 |
* Constructs an SSL connection to a named host at a specified port. |
|
131 |
* This acts as the SSL client, and may authenticate itself or rejoin |
|
132 |
* existing SSL sessions allowed by the authentication context which |
|
133 |
* has been configured. The socket will also bind() to the local |
|
134 |
* address and port supplied. |
|
135 |
*/ |
|
136 |
public Socket createSocket(String host, int port, |
|
137 |
InetAddress clientAddress, int clientPort) |
|
138 |
throws IOException |
|
139 |
{ |
|
140 |
return new SSLSocketImpl(context, host, port, |
|
141 |
clientAddress, clientPort); |
|
142 |
} |
|
143 |
||
144 |
/** |
|
145 |
* Constructs an SSL connection to a server at a specified address |
|
146 |
* and TCP port. This acts as the SSL client, and may authenticate |
|
147 |
* itself or rejoin existing SSL sessions allowed by the authentication |
|
148 |
* context which has been configured. The socket will also bind() to |
|
149 |
* the local address and port supplied. |
|
150 |
*/ |
|
151 |
public Socket createSocket(InetAddress address, int port, |
|
152 |
InetAddress clientAddress, int clientPort) |
|
153 |
throws IOException |
|
154 |
{ |
|
155 |
return new SSLSocketImpl(context, address, port, |
|
156 |
clientAddress, clientPort); |
|
157 |
} |
|
158 |
||
159 |
||
160 |
/** |
|
161 |
* Returns the subset of the supported cipher suites which are |
|
162 |
* enabled by default. These cipher suites all provide a minimum |
|
163 |
* quality of service whereby the server authenticates itself |
|
164 |
* (preventing person-in-the-middle attacks) and where traffic |
|
165 |
* is encrypted to provide confidentiality. |
|
166 |
*/ |
|
167 |
public String[] getDefaultCipherSuites() { |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
5506
diff
changeset
|
168 |
return context.getDefaultCipherSuiteList(false).toStringArray(); |
2 | 169 |
} |
170 |
||
171 |
/** |
|
172 |
* Returns the names of the cipher suites which could be enabled for use |
|
173 |
* on an SSL connection. Normally, only a subset of these will actually |
|
174 |
* be enabled by default, since this list may include cipher suites which |
|
175 |
* do not support the mutual authentication of servers and clients, or |
|
176 |
* which do not protect data confidentiality. Servers may also need |
|
177 |
* certain kinds of certificates to use certain cipher suites. |
|
178 |
*/ |
|
179 |
public String[] getSupportedCipherSuites() { |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
5506
diff
changeset
|
180 |
return context.getSuportedCipherSuiteList().toStringArray(); |
2 | 181 |
} |
182 |
} |