author | ascarpino |
Fri, 25 May 2018 12:43:45 -0700 | |
branch | JDK-8145252-TLS13-branch |
changeset 56611 | f8f7e604e1f8 |
parent 56542 | 56aaa6cb3693 |
child 56718 | da9979451b7a |
permissions | -rw-r--r-- |
2 | 1 |
/* |
56542 | 2 |
* Copyright (c) 1996, 2018, 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.IOException; |
|
29 |
import java.net.InetAddress; |
|
30 |
import java.net.Socket; |
|
56542 | 31 |
import javax.net.ssl.SSLParameters; |
2 | 32 |
import javax.net.ssl.SSLServerSocket; |
33 |
||
34 |
/** |
|
35 |
* This class provides a simple way for servers to support conventional |
|
36 |
* use of the Secure Sockets Layer (SSL). Application code uses an |
|
37 |
* SSLServerSocketImpl exactly like it uses a regular TCP ServerSocket; the |
|
38 |
* difference is that the connections established are secured using SSL. |
|
39 |
* |
|
40 |
* <P> Also, the constructors take an explicit authentication context |
|
41 |
* parameter, giving flexibility with respect to how the server socket |
|
42 |
* authenticates itself. That policy flexibility is not exposed through |
|
43 |
* the standard SSLServerSocketFactory API. |
|
44 |
* |
|
45 |
* <P> System security defaults prevent server sockets from accepting |
|
46 |
* connections if they the authentication context has not been given |
|
47 |
* a certificate chain and its matching private key. If the clients |
|
48 |
* of your application support "anonymous" cipher suites, you may be |
|
49 |
* able to configure a server socket to accept those suites. |
|
50 |
* |
|
51 |
* @see SSLSocketImpl |
|
52 |
* @see SSLServerSocketFactoryImpl |
|
53 |
* |
|
54 |
* @author David Brownell |
|
55 |
*/ |
|
56542 | 56 |
final class SSLServerSocketImpl extends SSLServerSocket { |
57 |
private final SSLContextImpl sslContext; |
|
58 |
private final SSLConfiguration sslConfig; |
|
2 | 59 |
|
56542 | 60 |
SSLServerSocketImpl(SSLContextImpl sslContext) throws IOException { |
7043 | 61 |
|
56542 | 62 |
super(); |
63 |
this.sslContext = sslContext; |
|
64 |
this.sslConfig = new SSLConfiguration(sslContext, false); |
|
65 |
this.sslConfig.isClientMode = false; |
|
66 |
} |
|
19823
f0fd09e20528
7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
14665
diff
changeset
|
67 |
|
56542 | 68 |
SSLServerSocketImpl(SSLContextImpl sslContext, |
69 |
int port, int backlog) throws IOException { |
|
70 |
||
2 | 71 |
super(port, backlog); |
56542 | 72 |
this.sslContext = sslContext; |
73 |
this.sslConfig = new SSLConfiguration(sslContext, false); |
|
74 |
this.sslConfig.isClientMode = false; |
|
2 | 75 |
} |
76 |
||
56542 | 77 |
SSLServerSocketImpl(SSLContextImpl sslContext, |
78 |
int port, int backlog, InetAddress address) throws IOException { |
|
2 | 79 |
|
80 |
super(port, backlog, address); |
|
56542 | 81 |
this.sslContext = sslContext; |
82 |
this.sslConfig = new SSLConfiguration(sslContext, false); |
|
83 |
this.sslConfig.isClientMode = false; |
|
2 | 84 |
} |
85 |
||
56542 | 86 |
@Override |
87 |
public synchronized String[] getEnabledCipherSuites() { |
|
88 |
return CipherSuite.namesOf(sslConfig.enabledCipherSuites); |
|
2 | 89 |
} |
90 |
||
56542 | 91 |
@Override |
92 |
public synchronized void setEnabledCipherSuites(String[] suites) { |
|
93 |
if (suites == null) { |
|
94 |
throw new IllegalArgumentException("CipherSuites cannot be null"); |
|
95 |
} |
|
2 | 96 |
|
56542 | 97 |
sslConfig.enabledCipherSuites = |
98 |
CipherSuite.validValuesOf(suites); |
|
2 | 99 |
} |
100 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
14194
diff
changeset
|
101 |
@Override |
2 | 102 |
public String[] getSupportedCipherSuites() { |
56542 | 103 |
return CipherSuite.namesOf(sslContext.getSupportedCipherSuites()); |
2 | 104 |
} |
105 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
14194
diff
changeset
|
106 |
@Override |
2 | 107 |
public String[] getSupportedProtocols() { |
56542 | 108 |
return ProtocolVersion.toStringArray( |
56611 | 109 |
sslContext.getSupportedProtocolVersions()); |
2 | 110 |
} |
111 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
14194
diff
changeset
|
112 |
@Override |
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
30904
diff
changeset
|
113 |
public synchronized String[] getEnabledProtocols() { |
56542 | 114 |
return ProtocolVersion.toStringArray(sslConfig.enabledProtocols); |
2 | 115 |
} |
116 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
14194
diff
changeset
|
117 |
@Override |
56542 | 118 |
public synchronized void setEnabledProtocols(String[] protocols) { |
119 |
if (protocols == null) { |
|
120 |
throw new IllegalArgumentException("Protocols cannot be null"); |
|
121 |
} |
|
122 |
||
123 |
sslConfig.enabledProtocols = ProtocolVersion.namesOf(protocols); |
|
2 | 124 |
} |
125 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
14194
diff
changeset
|
126 |
@Override |
56542 | 127 |
public synchronized void setNeedClientAuth(boolean need) { |
128 |
sslConfig.clientAuthType = |
|
129 |
(need ? ClientAuthType.CLIENT_AUTH_REQUIRED : |
|
130 |
ClientAuthType.CLIENT_AUTH_NONE); |
|
2 | 131 |
} |
132 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
14194
diff
changeset
|
133 |
@Override |
56542 | 134 |
public synchronized boolean getNeedClientAuth() { |
135 |
return (sslConfig.clientAuthType == |
|
136 |
ClientAuthType.CLIENT_AUTH_REQUIRED); |
|
2 | 137 |
} |
138 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
14194
diff
changeset
|
139 |
@Override |
56542 | 140 |
public synchronized void setWantClientAuth(boolean want) { |
141 |
sslConfig.clientAuthType = |
|
142 |
(want ? ClientAuthType.CLIENT_AUTH_REQUESTED : |
|
143 |
ClientAuthType.CLIENT_AUTH_NONE); |
|
144 |
} |
|
7039 | 145 |
|
56542 | 146 |
@Override |
147 |
public synchronized boolean getWantClientAuth() { |
|
148 |
return (sslConfig.clientAuthType == |
|
149 |
ClientAuthType.CLIENT_AUTH_REQUESTED); |
|
2 | 150 |
} |
151 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
14194
diff
changeset
|
152 |
@Override |
56542 | 153 |
public synchronized void setUseClientMode(boolean useClientMode) { |
154 |
/* |
|
155 |
* If we need to change the client mode and the enabled |
|
156 |
* protocols and cipher suites haven't specifically been |
|
157 |
* set by the user, change them to the corresponding |
|
158 |
* default ones. |
|
159 |
*/ |
|
160 |
if (sslConfig.isClientMode != useClientMode) { |
|
161 |
if (sslContext.isDefaultProtocolVesions( |
|
162 |
sslConfig.enabledProtocols)) { |
|
163 |
sslConfig.enabledProtocols = |
|
164 |
sslContext.getDefaultProtocolVersions(!useClientMode); |
|
165 |
} |
|
166 |
||
167 |
if (sslContext.isDefaultCipherSuiteList( |
|
168 |
sslConfig.enabledCipherSuites)) { |
|
169 |
sslConfig.enabledCipherSuites = |
|
170 |
sslContext.getDefaultCipherSuites(!useClientMode); |
|
171 |
} |
|
172 |
||
173 |
sslConfig.isClientMode = useClientMode; |
|
174 |
} |
|
2 | 175 |
} |
176 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
14194
diff
changeset
|
177 |
@Override |
56542 | 178 |
public synchronized boolean getUseClientMode() { |
179 |
return sslConfig.isClientMode; |
|
2 | 180 |
} |
181 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
14194
diff
changeset
|
182 |
@Override |
56542 | 183 |
public synchronized void setEnableSessionCreation(boolean flag) { |
184 |
sslConfig.enableSessionCreation = flag; |
|
2 | 185 |
} |
186 |
||
56542 | 187 |
@Override |
188 |
public synchronized boolean getEnableSessionCreation() { |
|
189 |
return sslConfig.enableSessionCreation; |
|
190 |
} |
|
191 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
14194
diff
changeset
|
192 |
@Override |
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
30904
diff
changeset
|
193 |
public synchronized SSLParameters getSSLParameters() { |
56542 | 194 |
return sslConfig.getSSLParameters(); |
7043 | 195 |
} |
196 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
14194
diff
changeset
|
197 |
@Override |
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
30904
diff
changeset
|
198 |
public synchronized void setSSLParameters(SSLParameters params) { |
56542 | 199 |
sslConfig.setSSLParameters(params); |
7043 | 200 |
} |
201 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
14194
diff
changeset
|
202 |
@Override |
2 | 203 |
public Socket accept() throws IOException { |
56542 | 204 |
SSLSocketImpl s = new SSLSocketImpl(sslContext, sslConfig); |
2 | 205 |
|
206 |
implAccept(s); |
|
207 |
s.doneConnect(); |
|
208 |
return s; |
|
209 |
} |
|
210 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
14194
diff
changeset
|
211 |
@Override |
2 | 212 |
public String toString() { |
213 |
return "[SSL: "+ super.toString() + "]"; |
|
214 |
} |
|
215 |
} |