2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2005, 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 javax.net.ssl;
|
|
27 |
|
|
28 |
/**
|
|
29 |
* Encapsulates parameters for an SSL/TLS connection. The parameters
|
|
30 |
* are the list of ciphersuites to be accepted in an SSL/TLS handshake,
|
|
31 |
* the list of protocols to be allowed, and whether SSL/TLS servers should
|
|
32 |
* request or require client authentication.
|
|
33 |
*
|
|
34 |
* <p>SSLParameters can be created via the constructors in this class.
|
|
35 |
* Objects can also be obtained using the <code>getSSLParameters()</code>
|
|
36 |
* methods in
|
|
37 |
* {@link SSLSocket#getSSLParameters SSLSocket} and
|
|
38 |
* {@link SSLEngine#getSSLParameters SSLEngine} or the
|
|
39 |
* {@link SSLContext#getDefaultSSLParameters getDefaultSSLParameters()} and
|
|
40 |
* {@link SSLContext#getSupportedSSLParameters getSupportedSSLParameters()}
|
|
41 |
* methods in <code>SSLContext</code>.
|
|
42 |
*
|
|
43 |
* <P>SSLParameters can be applied to a connection via the methods
|
|
44 |
* {@link SSLSocket#setSSLParameters SSLSocket.setSSLParameters()} and
|
|
45 |
* {@link SSLEngine#setSSLParameters SSLEngine.getSSLParameters()}.
|
|
46 |
*
|
|
47 |
* @see SSLSocket
|
|
48 |
* @see SSLEngine
|
|
49 |
* @see SSLContext
|
|
50 |
*
|
|
51 |
* @since 1.6
|
|
52 |
*/
|
|
53 |
public class SSLParameters {
|
|
54 |
|
|
55 |
private String[] cipherSuites;
|
|
56 |
private String[] protocols;
|
|
57 |
private boolean wantClientAuth;
|
|
58 |
private boolean needClientAuth;
|
|
59 |
|
|
60 |
/**
|
|
61 |
* Constructs SSLParameters.
|
|
62 |
*
|
|
63 |
* <p>The cipherSuites and protocols values are set to <code>null</code>,
|
|
64 |
* wantClientAuth and needClientAuth are set to <code>false</code>.
|
|
65 |
*/
|
|
66 |
public SSLParameters() {
|
|
67 |
// empty
|
|
68 |
}
|
|
69 |
|
|
70 |
/**
|
|
71 |
* Constructs SSLParameters from the specified array of ciphersuites.
|
|
72 |
* Calling this constructor is equivalent to calling the no-args
|
|
73 |
* constructor followed by
|
|
74 |
* <code>setCipherSuites(cipherSuites);</code>.
|
|
75 |
*
|
|
76 |
* @param cipherSuites the array of ciphersuites (or null)
|
|
77 |
*/
|
|
78 |
public SSLParameters(String[] cipherSuites) {
|
|
79 |
setCipherSuites(cipherSuites);
|
|
80 |
}
|
|
81 |
|
|
82 |
/**
|
|
83 |
* Constructs SSLParameters from the specified array of ciphersuites
|
|
84 |
* and protocols.
|
|
85 |
* Calling this constructor is equivalent to calling the no-args
|
|
86 |
* constructor followed by
|
|
87 |
* <code>setCipherSuites(cipherSuites); setProtocols(protocols);</code>.
|
|
88 |
*
|
|
89 |
* @param cipherSuites the array of ciphersuites (or null)
|
|
90 |
* @param protocols the array of protocols (or null)
|
|
91 |
*/
|
|
92 |
public SSLParameters(String[] cipherSuites, String[] protocols) {
|
|
93 |
setCipherSuites(cipherSuites);
|
|
94 |
setProtocols(protocols);
|
|
95 |
}
|
|
96 |
|
|
97 |
private static String[] clone(String[] s) {
|
|
98 |
return (s == null) ? null : s.clone();
|
|
99 |
}
|
|
100 |
|
|
101 |
/**
|
|
102 |
* Returns a copy of the array of ciphersuites or null if none
|
|
103 |
* have been set.
|
|
104 |
*
|
|
105 |
* @return a copy of the array of ciphersuites or null if none
|
|
106 |
* have been set.
|
|
107 |
*/
|
|
108 |
public String[] getCipherSuites() {
|
|
109 |
return clone(cipherSuites);
|
|
110 |
}
|
|
111 |
|
|
112 |
/**
|
|
113 |
* Sets the array of ciphersuites.
|
|
114 |
*
|
|
115 |
* @param cipherSuites the array of ciphersuites (or null)
|
|
116 |
*/
|
|
117 |
public void setCipherSuites(String[] cipherSuites) {
|
|
118 |
this.cipherSuites = clone(cipherSuites);
|
|
119 |
}
|
|
120 |
|
|
121 |
/**
|
|
122 |
* Returns a copy of the array of protocols or null if none
|
|
123 |
* have been set.
|
|
124 |
*
|
|
125 |
* @return a copy of the array of protocols or null if none
|
|
126 |
* have been set.
|
|
127 |
*/
|
|
128 |
public String[] getProtocols() {
|
|
129 |
return clone(protocols);
|
|
130 |
}
|
|
131 |
|
|
132 |
/**
|
|
133 |
* Sets the array of protocols.
|
|
134 |
*
|
|
135 |
* @param protocols the array of protocols (or null)
|
|
136 |
*/
|
|
137 |
public void setProtocols(String[] protocols) {
|
|
138 |
this.protocols = clone(protocols);
|
|
139 |
}
|
|
140 |
|
|
141 |
/**
|
|
142 |
* Returns whether client authentication should be requested.
|
|
143 |
*
|
|
144 |
* @return whether client authentication should be requested.
|
|
145 |
*/
|
|
146 |
public boolean getWantClientAuth() {
|
|
147 |
return wantClientAuth;
|
|
148 |
}
|
|
149 |
|
|
150 |
/**
|
|
151 |
* Sets whether client authentication should be requested. Calling
|
|
152 |
* this method clears the <code>needClientAuth</code> flag.
|
|
153 |
*
|
|
154 |
* @param wantClientAuth whether client authentication should be requested
|
|
155 |
*/
|
|
156 |
public void setWantClientAuth(boolean wantClientAuth) {
|
|
157 |
this.wantClientAuth = wantClientAuth;
|
|
158 |
this.needClientAuth = false;
|
|
159 |
}
|
|
160 |
|
|
161 |
/**
|
|
162 |
* Returns whether client authentication should be required.
|
|
163 |
*
|
|
164 |
* @return whether client authentication should be required.
|
|
165 |
*/
|
|
166 |
public boolean getNeedClientAuth() {
|
|
167 |
return needClientAuth;
|
|
168 |
}
|
|
169 |
|
|
170 |
/**
|
|
171 |
* Sets whether client authentication should be required. Calling
|
|
172 |
* this method clears the <code>wantClientAuth</code> flag.
|
|
173 |
*
|
|
174 |
* @param needClientAuth whether client authentication should be required
|
|
175 |
*/
|
|
176 |
public void setNeedClientAuth(boolean needClientAuth) {
|
|
177 |
this.wantClientAuth = false;
|
|
178 |
this.needClientAuth = needClientAuth;
|
|
179 |
}
|
|
180 |
|
|
181 |
}
|