15
15
16
16
package net .lightbody .bmp .proxy .jetty .http ;
17
17
18
- import com .sun .net .ssl .*;
19
18
import net .lightbody .bmp .proxy .jetty .log .LogFactory ;
20
19
import net .lightbody .bmp .proxy .jetty .util .InetAddrPort ;
21
20
import net .lightbody .bmp .proxy .jetty .util .Password ;
22
21
import org .apache .commons .logging .Log ;
23
22
24
- import javax .net .ssl .SSLServerSocketFactory ;
23
+ import javax .net .ssl .* ;
25
24
import java .io .File ;
26
25
import java .io .FileInputStream ;
27
26
import java .security .KeyStore ;
30
29
31
30
32
31
/* ------------------------------------------------------------ */
33
- /** SSL Socket Listener for Sun's JSSE.
34
- *
32
+
33
+ /**
34
+ * SSL Socket Listener for Sun's JSSE.
35
+ * <p>
35
36
* This specialization of JsseListener is an specific listener
36
37
* using the Sun reference implementation.
37
- *
38
+ * <p>
38
39
* This is heavily based on the work from Court Demas, which in
39
40
* turn is based on the work from Forge Research.
40
41
*
41
- * @version $Id: SunJsseListener.java,v 1.20 2005/08/13 00:01:24 gregwilkins Exp $
42
- * @deprecated Use org.mortbay.http.SslListener
43
42
* @author Greg Wilkins (gregw@mortbay.com)
44
43
* @author Court Demas (court@kiwiconsulting.com)
45
44
* @author Forge Research Pty Ltd ACN 003 491 576
45
+ * @version $Id: SunJsseListener.java,v 1.20 2005/08/13 00:01:24 gregwilkins Exp $
46
+ * @deprecated Use org.mortbay.http.SslListener
46
47
**/
47
- public class SunJsseListener extends JsseListener
48
- {
48
+ public class SunJsseListener extends JsseListener {
49
49
private static Log log = LogFactory .getLog (SunJsseListener .class );
50
50
51
- private String _keystore = DEFAULT_KEYSTORE ;
51
+ private String _keystore = DEFAULT_KEYSTORE ;
52
52
private transient Password _password ;
53
53
private transient Password _keypassword ;
54
54
private String _keystore_type = DEFAULT_KEYSTORE_TYPE ;
55
55
private String _keystore_provider_name = DEFAULT_KEYSTORE_PROVIDER_NAME ;
56
56
private String _keystore_provider_class = DEFAULT_KEYSTORE_PROVIDER_CLASS ;
57
57
private boolean _useDefaultTrustStore = false ;
58
58
59
- /* ------------------------------------------------------------ */
60
- static
61
- {
62
- Security .addProvider (new com .sun .net .ssl .internal .ssl .Provider ());
63
- }
64
59
65
60
/* ------------------------------------------------------------ */
66
- public void setKeystore (String keystore )
67
- {
61
+ public void setKeystore (String keystore ) {
68
62
_keystore = keystore ;
69
63
}
70
-
64
+
71
65
/* ------------------------------------------------------------ */
72
- public String getKeystore ()
73
- {
66
+ public String getKeystore () {
74
67
return _keystore ;
75
68
}
76
-
69
+
77
70
/* ------------------------------------------------------------ */
78
- public void setPassword (String password )
79
- {
80
- _password = Password .getPassword (PASSWORD_PROPERTY ,password ,null );
71
+ public void setPassword (String password ) {
72
+ _password = Password .getPassword (PASSWORD_PROPERTY , password , null );
81
73
}
82
74
83
75
/* ------------------------------------------------------------ */
84
- public void setKeyPassword (String password )
85
- {
86
- _keypassword = Password .getPassword (KEYPASSWORD_PROPERTY ,password ,null );
76
+ public void setKeyPassword (String password ) {
77
+ _keypassword = Password .getPassword (KEYPASSWORD_PROPERTY , password , null );
87
78
}
88
-
89
-
79
+
80
+
90
81
/* ------------------------------------------------------------ */
91
- public void setKeystoreType (String keystore_type )
92
- {
82
+ public void setKeystoreType (String keystore_type ) {
93
83
_keystore_type = keystore_type ;
94
84
}
95
-
85
+
96
86
/* ------------------------------------------------------------ */
97
- public String getKeystoreType ()
98
- {
87
+ public String getKeystoreType () {
99
88
return _keystore_type ;
100
89
}
101
90
102
91
/* ------------------------------------------------------------ */
103
- public void setKeystoreProviderName (String name )
104
- {
92
+ public void setKeystoreProviderName (String name ) {
105
93
_keystore_provider_name = name ;
106
94
}
107
95
108
96
/* ------------------------------------------------------------ */
109
- public String getKeystoreProviderName ()
110
- {
97
+ public String getKeystoreProviderName () {
111
98
return _keystore_provider_name ;
112
99
}
113
100
114
101
/* ------------------------------------------------------------ */
115
- public String getKeystoreProviderClass ()
116
- {
102
+ public String getKeystoreProviderClass () {
117
103
return _keystore_provider_class ;
118
104
}
119
105
120
106
/* ------------------------------------------------------------ */
121
- public void setKeystoreProviderClass (String classname )
122
- {
107
+ public void setKeystoreProviderClass (String classname ) {
123
108
_keystore_provider_class = classname ;
124
109
}
125
110
126
111
/* ------------------------------------------------------------ */
112
+
127
113
/**
128
114
* Gets the default trust store flag.
129
115
*
130
116
* @return true if the default truststore will be used to initialize the
131
117
* TrustManager, false otherwise.
132
118
*/
133
- public boolean getUseDefaultTrustStore ()
134
- {
119
+ public boolean getUseDefaultTrustStore () {
135
120
return _useDefaultTrustStore ;
136
121
}
137
122
138
123
/* ------------------------------------------------------------ */
124
+
139
125
/**
140
126
* Set a flag to determine if the default truststore should be used to
141
127
* initialize the TrustManager. The default truststore will typically be
142
128
* the ${JAVA_HOME}/jre/lib/security/cacerts.
143
129
*
144
130
* @param flag if true, the default truststore will be used. If false, the
145
- * configured keystore will be used as the truststore.
131
+ * configured keystore will be used as the truststore.
146
132
*/
147
- public void setUseDefaultTrustStore (boolean flag )
148
- {
133
+ public void setUseDefaultTrustStore (boolean flag ) {
149
134
_useDefaultTrustStore = flag ;
150
135
}
151
136
152
137
/* ------------------------------------------------------------ */
153
- /** Constructor.
138
+
139
+ /**
140
+ * Constructor.
154
141
*/
155
- public SunJsseListener ()
156
- {
142
+ public SunJsseListener () {
157
143
super ();
158
144
}
159
145
160
146
/* ------------------------------------------------------------ */
161
- /** Constructor.
162
- * @param p_address
147
+
148
+ /**
149
+ * Constructor.
150
+ *
151
+ * @param p_address
163
152
*/
164
- public SunJsseListener (InetAddrPort p_address )
165
- {
166
- super ( p_address );
153
+ public SunJsseListener (InetAddrPort p_address ) {
154
+ super (p_address );
167
155
}
168
-
156
+
169
157
/* ------------------------------------------------------------ */
170
- /*
171
- * @return
172
- * @exception Exception
158
+ /*
159
+ * @return
160
+ * @exception Exception
173
161
*/
174
162
protected SSLServerSocketFactory createFactory ()
175
- throws Exception
176
- {
177
- _keystore = System .getProperty ( KEYSTORE_PROPERTY ,_keystore );
178
-
179
- log .info (KEYSTORE_PROPERTY +"=" +_keystore );
180
-
181
- if (_password ==null )
182
- _password = Password .getPassword (PASSWORD_PROPERTY ,null ,null );
183
- log .info (PASSWORD_PROPERTY +"=" +_password .toStarString ());
184
-
185
- if (_keypassword ==null )
163
+ throws Exception {
164
+ _keystore = System .getProperty (KEYSTORE_PROPERTY , _keystore );
165
+
166
+ log .info (KEYSTORE_PROPERTY + "=" + _keystore );
167
+
168
+ if (_password == null )
169
+ _password = Password .getPassword (PASSWORD_PROPERTY , null , null );
170
+ log .info (PASSWORD_PROPERTY + "=" + _password .toStarString ());
171
+
172
+ if (_keypassword == null )
186
173
_keypassword = Password .getPassword (KEYPASSWORD_PROPERTY ,
187
- null ,
188
- _password .toString ());
189
- log .info (KEYPASSWORD_PROPERTY + "=" + _keypassword .toStarString ());
174
+ null ,
175
+ _password .toString ());
176
+ log .info (KEYPASSWORD_PROPERTY + "=" + _keypassword .toStarString ());
190
177
191
178
192
179
KeyStore ks = null ;
193
180
194
- log .info (KEYSTORE_TYPE_PROPERTY + "=" + _keystore_type );
195
-
181
+ log .info (KEYSTORE_TYPE_PROPERTY + "=" + _keystore_type );
182
+
196
183
if (_keystore_provider_class != null ) {
197
184
// find provider.
198
185
// avoid creating another instance if already installed in Security.
199
186
java .security .Provider [] installed_providers = Security .getProviders ();
200
187
java .security .Provider myprovider = null ;
201
- for (int i = 0 ; i < installed_providers .length ; i ++) {
188
+ for (int i = 0 ; i < installed_providers .length ; i ++) {
202
189
if (installed_providers [i ].getClass ().getName ().equals (_keystore_provider_class )) {
203
190
myprovider = installed_providers [i ];
204
191
break ;
@@ -209,37 +196,37 @@ protected SSLServerSocketFactory createFactory()
209
196
myprovider = (java .security .Provider ) Class .forName (_keystore_provider_class ).newInstance ();
210
197
Security .addProvider (myprovider );
211
198
}
212
- log .info (KEYSTORE_PROVIDER_CLASS_PROPERTY + "=" + _keystore_provider_class );
213
- ks = KeyStore .getInstance (_keystore_type ,myprovider .getName ());
199
+ log .info (KEYSTORE_PROVIDER_CLASS_PROPERTY + "=" + _keystore_provider_class );
200
+ ks = KeyStore .getInstance (_keystore_type , myprovider .getName ());
214
201
} else if (_keystore_provider_name != null ) {
215
- log .info (KEYSTORE_PROVIDER_NAME_PROPERTY + "=" + _keystore_provider_name );
216
- ks = KeyStore .getInstance (_keystore_type ,_keystore_provider_name );
202
+ log .info (KEYSTORE_PROVIDER_NAME_PROPERTY + "=" + _keystore_provider_name );
203
+ ks = KeyStore .getInstance (_keystore_type , _keystore_provider_name );
217
204
} else {
218
205
ks = KeyStore .getInstance (_keystore_type );
219
- log .info (KEYSTORE_PROVIDER_NAME_PROPERTY + "=[DEFAULT]" );
206
+ log .info (KEYSTORE_PROVIDER_NAME_PROPERTY + "=[DEFAULT]" );
220
207
}
221
-
222
- ks .load ( new FileInputStream ( new File ( _keystore ) ),
223
- _password .toString ().toCharArray ());
224
-
225
- KeyManagerFactory km = KeyManagerFactory .getInstance ( "SunX509" ,"SunJSSE" );
226
- km .init ( ks , _keypassword .toString ().toCharArray () );
227
- KeyManager [] kma = km .getKeyManagers ();
228
-
229
- TrustManagerFactory tm = TrustManagerFactory .getInstance ("SunX509" ,"SunJSSE" );
208
+
209
+ ks .load (new FileInputStream (new File (_keystore ) ),
210
+ _password .toString ().toCharArray ());
211
+
212
+ KeyManagerFactory km = KeyManagerFactory .getInstance ("SunX509" , "SunJSSE" );
213
+ km .init (ks , _keypassword .toString ().toCharArray ());
214
+ KeyManager [] kma = km .getKeyManagers ();
215
+
216
+ TrustManagerFactory tm = TrustManagerFactory .getInstance ("SunX509" , "SunJSSE" );
230
217
if (_useDefaultTrustStore ) {
231
- tm .init ( (KeyStore )null );
218
+ tm .init ((KeyStore ) null );
232
219
} else {
233
- tm .init ( ks );
220
+ tm .init (ks );
234
221
}
235
222
236
223
TrustManager [] tma = tm .getTrustManagers ();
237
-
238
- SSLContext sslc = SSLContext .getInstance ( "SSL" );
239
- sslc .init ( kma , tma , SecureRandom .getInstance ("SHA1PRNG" ));
240
-
224
+
225
+ SSLContext sslc = SSLContext .getInstance ("SSL" );
226
+ sslc .init (kma , tma , SecureRandom .getInstance ("SHA1PRNG" ));
227
+
241
228
SSLServerSocketFactory ssfc = sslc .getServerSocketFactory ();
242
- log .info ("SSLServerSocketFactory=" + ssfc );
229
+ log .info ("SSLServerSocketFactory=" + ssfc );
243
230
return ssfc ;
244
231
}
245
232
}
0 commit comments