forked from fizzed/cloudhopper-smpp
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathSslConfiguration.java
More file actions
609 lines (526 loc) · 17.6 KB
/
SslConfiguration.java
File metadata and controls
609 lines (526 loc) · 17.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
package com.cloudhopper.smpp.ssl;
/*
* #%L
* ch-smpp
* %%
* Copyright (C) 2009 - 2013 Cloudhopper by Twitter
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import java.security.SecureRandom;
import java.security.Security;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.TrustManagerFactory;
/**
* Configuration for SSL.
*
* @author garth
*/
public class SslConfiguration
{
public static final String DEFAULT_KEYMANAGERFACTORY_ALGORITHM =
(Security.getProperty("ssl.KeyManagerFactory.algorithm") == null ?
"SunX509" : Security.getProperty("ssl.KeyManagerFactory.algorithm"));
public static final String DEFAULT_TRUSTMANAGERFACTORY_ALGORITHM =
(Security.getProperty("ssl.TrustManagerFactory.algorithm") == null ?
"SunX509" : Security.getProperty("ssl.TrustManagerFactory.algorithm"));
private final Set<String> excludeProtocols = new HashSet<>();
private Set<String> includeProtocols = null;
private final Set<String> excludeCipherSuites = new HashSet<>();
private Set<String> includeCipherSuites = null;
private String keyStorePath;
private String keyStoreProvider;
private String keyStoreType = "JKS";
private String trustStorePath;
private String trustStoreProvider;
private String trustStoreType = "JKS";
private transient String keyStorePassword;
private transient String trustStorePassword;
private transient String keyManagerPassword;
private String certAlias;
private boolean needClientAuth = false;
private boolean wantClientAuth = false;
private boolean allowRenegotiate = true;
private String sslProvider;
private String sslProtocol = "TLS";
private String secureRandomAlgorithm;
private String keyManagerFactoryAlgorithm = DEFAULT_KEYMANAGERFACTORY_ALGORITHM;
private String trustManagerFactoryAlgorithm = DEFAULT_TRUSTMANAGERFACTORY_ALGORITHM;
private boolean validateCerts;
private boolean validatePeerCerts;
private int maxCertPathLength = -1;
private String crlPath;
private boolean enableCRLDP = false;
private boolean enableOCSP = false;
private String ocspResponderURL;
private boolean sessionCachingEnabled = true;
private int sslSessionCacheSize;
private int sslSessionTimeout;
private boolean trustAll = true;
/**
* @return The array of protocol names to exclude from
* {@link SSLEngine#setEnabledProtocols(String[])}
*/
public String[] getExcludeProtocols() {
return this.excludeProtocols == null ? null :
this.excludeProtocols.toArray(new String[this.excludeProtocols.size()]);
}
/**
* @param protocols The array of protocol names to exclude from
* {@link SSLEngine#setEnabledProtocols(String[])}
*/
public void setExcludeProtocols(String... protocols) {
this.excludeProtocols.clear();
this.excludeProtocols.addAll(Arrays.asList(protocols));
}
/**
* @param protocol Protocol names to add to {@link SSLEngine#setEnabledProtocols(String[])}
*/
public void addExcludeProtocols(String... protocol) {
this.excludeProtocols.addAll(Arrays.asList(protocol));
}
/**
* @return The array of protocol names to include in
* {@link SSLEngine#setEnabledProtocols(String[])}
*/
public String[] getIncludeProtocols() {
return this.includeProtocols == null ? null :
this.includeProtocols.toArray(new String[this.includeProtocols.size()]);
}
/**
* @param protocols The array of protocol names to include in
* {@link SSLEngine#setEnabledProtocols(String[])}
*/
public void setIncludeProtocols(String... protocols) {
this.includeProtocols = new HashSet<>(Arrays.asList(protocols));
}
/**
* @return The array of cipher suite names to exclude from
* {@link SSLEngine#setEnabledCipherSuites(String[])}
*/
public String[] getExcludeCipherSuites() {
return this.excludeCipherSuites == null ? null :
this.excludeCipherSuites.toArray(new String[this.excludeCipherSuites.size()]);
}
/**
* @param cipherSuites The array of cipher suite names to exclude from
* {@link SSLEngine#setEnabledCipherSuites(String[])}
*/
public void setExcludeCipherSuites(String... cipherSuites) {
this.excludeCipherSuites.clear();
this.excludeCipherSuites.addAll(Arrays.asList(cipherSuites));
}
/**
* @param cipher Cipher names to add to {@link SSLEngine#setEnabledCipherSuites(String[])}
*/
public void addExcludeCipherSuites(String... cipher) {
this.excludeCipherSuites.addAll(Arrays.asList(cipher));
}
/**
* @return The array of cipher suite names to include in
* {@link SSLEngine#setEnabledCipherSuites(String[])}
*/
public String[] getIncludeCipherSuites() {
return this.includeCipherSuites == null ? null:
this.includeCipherSuites.toArray(new String[this.includeCipherSuites.size()]);
}
/**
* @param cipherSuites The array of cipher suite names to include in
* {@link SSLEngine#setEnabledCipherSuites(String[])}
*/
public void setIncludeCipherSuites(String... cipherSuites) {
this.includeCipherSuites = new HashSet<>(Arrays.asList(cipherSuites));
}
/**
* @return The file or URL of the SSL Key store.
*/
public String getKeyStorePath() {
return this.keyStorePath;
}
/**
* @param keyStorePath The file or URL of the SSL Key store.
*/
public void setKeyStorePath(String keyStorePath) {
this.keyStorePath = keyStorePath;
}
/**
* @return The provider of the key store
*/
public String getKeyStoreProvider() {
return this.keyStoreProvider;
}
/**
* @param keyStoreProvider The provider of the key store
*/
public void setKeyStoreProvider(String keyStoreProvider) {
this.keyStoreProvider = keyStoreProvider;
}
/**
* @return The type of the key store (default "JKS")
*/
public String getKeyStoreType() {
return this.keyStoreType;
}
/**
* @param keyStoreType The type of the key store (default "JKS")
*/
public void setKeyStoreType(String keyStoreType) {
this.keyStoreType = keyStoreType;
}
/**
* @return Alias of SSL certificate for the connector
*/
public String getCertAlias() {
return this.certAlias;
}
/**
* @param certAlias Alias of SSL certificate for the connector
*/
public void setCertAlias(String certAlias) {
this.certAlias = certAlias;
}
/**
* @return The file name or URL of the trust store location
*/
public String getTrustStorePath() {
return this.trustStorePath;
}
/**
* @param trustStorePath The file name or URL of the trust store location
*/
public void setTrustStorePath(String trustStorePath) {
this.trustStorePath = trustStorePath;
}
/**
* @return The provider of the trust store
*/
public String getTrustStoreProvider() {
return this.trustStoreProvider;
}
/**
* @param trustStoreProvider The provider of the trust store
*/
public void setTrustStoreProvider(String trustStoreProvider) {
this.trustStoreProvider = trustStoreProvider;
}
/**
* @return The type of the trust store (default "JKS")
*/
public String getTrustStoreType() {
return this.trustStoreType;
}
/**
* @param trustStoreType The type of the trust store (default "JKS")
*/
public void setTrustStoreType(String trustStoreType) {
this.trustStoreType = trustStoreType;
}
/**
* @return True if SSL needs client authentication.
* @see SSLEngine#getNeedClientAuth()
*/
public boolean getNeedClientAuth() {
return this.needClientAuth;
}
/**
* @param needClientAuth True if SSL needs client authentication.
*/
public void setNeedClientAuth(boolean needClientAuth) {
this.needClientAuth = needClientAuth;
}
/**
* @return True if SSL wants client authentication.
* @see SSLEngine#getWantClientAuth()
*/
public boolean getWantClientAuth() {
return this.wantClientAuth;
}
/**
* @param wantClientAuth True if SSL wants client authentication.
*/
public void setWantClientAuth(boolean wantClientAuth) {
this.wantClientAuth = wantClientAuth;
}
/**
* @return true if SSL certificate has to be validated
*/
public boolean isValidateCerts() {
return this.validateCerts;
}
/**
* @param validateCerts true if SSL certificates have to be validated
*/
public void setValidateCerts(boolean validateCerts) {
this.validateCerts = validateCerts;
}
/**
* @return true if SSL certificates of the peer have to be validated
*/
public boolean isValidatePeerCerts() {
return this.validatePeerCerts;
}
/**
* @param validatePeerCerts true if SSL certificates of the peer have to be validated
*/
public void setValidatePeerCerts(boolean validatePeerCerts) {
this.validatePeerCerts = validatePeerCerts;
}
/**
* @return True if SSL re-negotiation is allowed (default false)
*/
public boolean isAllowRenegotiate() {
return this.allowRenegotiate;
}
/**
* Set if SSL re-negotiation is allowed. CVE-2009-3555 discovered
* a vulnerability in SSL/TLS with re-negotiation. If your JVM
* does not have CVE-2009-3555 fixed, then re-negotiation should
* not be allowed. CVE-2009-3555 was fixed in Sun java 1.6 with a ban
* of renegotiates in u19 and with RFC5746 in u22.
*
* @param allowRenegotiate
* true if re-negotiation is allowed (default false)
*/
public void setAllowRenegotiate(boolean allowRenegotiate) {
this.allowRenegotiate = allowRenegotiate;
}
/**
* @param password The password for the key store
*/
public void setKeyStorePassword(String password) {
this.keyStorePassword = password;
}
/**
* @return The password for the key store
*/
public String getKeyStorePassword() {
return this.keyStorePassword;
}
/**
* @param password The password (if any) for the specific key within the key store
*/
public void setKeyManagerPassword(String password) {
this.keyManagerPassword = password;
}
/**
* @return The password (if any) for the specific key within the key store
*/
public String getKeyManagerPassword() {
return this.keyManagerPassword;
}
/**
* @param password The password for the trust store
*/
public void setTrustStorePassword(String password) {
this.trustStorePassword = password;
}
/**
* @return The password for the trust store
*/
public String getTrustStorePassword() {
return this.trustStorePassword;
}
/**
* @return The SSL provider name, which if set is passed to
* {@link SSLContext#getInstance(String, String)}
*/
public String getProvider() {
return this.sslProvider;
}
/**
* @param provider The SSL provider name, which if set is passed to
* {@link SSLContext#getInstance(String, String)}
*/
public void setProvider(String provider) {
this.sslProvider = provider;
}
/**
* @return The SSL protocol (default "TLS") passed to
* {@link SSLContext#getInstance(String, String)}
*/
public String getProtocol() {
return this.sslProtocol;
}
/**
* @param protocol The SSL protocol (default "TLS") passed to
* {@link SSLContext#getInstance(String, String)}
*/
public void setProtocol(String protocol) {
this.sslProtocol = protocol;
}
/**
* @return The algorithm name, which if set is passed to
* {@link SecureRandom#getInstance(String)} to obtain the {@link SecureRandom} instance passed to
* {@link SSLContext#init(javax.net.ssl.KeyManager[], javax.net.ssl.TrustManager[], SecureRandom)}
*/
public String getSecureRandomAlgorithm() {
return this.secureRandomAlgorithm;
}
/**
* @param algorithm The algorithm name, which if set is passed to
* {@link SecureRandom#getInstance(String)} to obtain the {@link SecureRandom} instance passed to
* {@link SSLContext#init(javax.net.ssl.KeyManager[], javax.net.ssl.TrustManager[], SecureRandom)}
*/
public void setSecureRandomAlgorithm(String algorithm) {
this.secureRandomAlgorithm = algorithm;
}
/**
* @return The algorithm name (default "SunX509") used by the {@link KeyManagerFactory}
*/
public String getKeyManagerFactoryAlgorithm() {
return this.keyManagerFactoryAlgorithm;
}
/**
* @param algorithm The algorithm name (default "SunX509") used by the {@link KeyManagerFactory}
*/
public void setKeyManagerFactoryAlgorithm(String algorithm) {
this.keyManagerFactoryAlgorithm = algorithm;
}
/**
* @return The algorithm name (default "SunX509") used by the {@link TrustManagerFactory}
*/
public String getTrustManagerFactoryAlgorithm() {
return this.trustManagerFactoryAlgorithm;
}
/**
* @return True if all certificates should be trusted if there is no KeyStore or TrustStore
*/
public boolean isTrustAll() {
return this.trustAll;
}
/**
* @param trustAll True if all certificates should be trusted if there is no KeyStore or TrustStore
*/
public void setTrustAll(boolean trustAll) {
this.trustAll = trustAll;
}
/**
* @param algorithm The algorithm name (default "SunX509") used by the {@link TrustManagerFactory}
* Use the string "TrustAll" to install a trust manager that trusts all.
*/
public void setTrustManagerFactoryAlgorithm(String algorithm) {
this.trustManagerFactoryAlgorithm = algorithm;
}
/**
* @return Path to file that contains Certificate Revocation List
*/
public String getCrlPath() {
return this.crlPath;
}
/**
* @param crlPath Path to file that contains Certificate Revocation List
*/
public void setCrlPath(String crlPath) {
this.crlPath = crlPath;
}
/**
* @return Maximum number of intermediate certificates in
* the certification path (-1 for unlimited)
*/
public int getMaxCertPathLength() {
return this.maxCertPathLength;
}
/**
* @param maxCertPathLength maximum number of intermediate certificates in
* the certification path (-1 for unlimited)
*/
public void setMaxCertPathLength(int maxCertPathLength) {
this.maxCertPathLength = maxCertPathLength;
}
/**
* @return true if CRL Distribution Points support is enabled
*/
public boolean isEnableCRLDP() {
return this.enableCRLDP;
}
/**
* Enables CRL Distribution Points Support
* @param enableCRLDP true - turn on, false - turns off
*/
public void setEnableCRLDP(boolean enableCRLDP) {
this.enableCRLDP = enableCRLDP;
}
/**
* @return true if On-Line Certificate Status Protocol support is enabled
*/
public boolean isEnableOCSP() {
return this.enableOCSP;
}
/**
* Enables On-Line Certificate Status Protocol support
* @param enableOCSP true - turn on, false - turn off
*/
public void setEnableOCSP(boolean enableOCSP) {
this.enableOCSP = enableOCSP;
}
/**
* @return Location of the OCSP Responder
*/
public String getOcspResponderURL() {
return this.ocspResponderURL;
}
/**
* Set the location of the OCSP Responder.
* @param ocspResponderURL location of the OCSP Responder
*/
public void setOcspResponderURL(String ocspResponderURL) {
this.ocspResponderURL = ocspResponderURL;
}
/**
* @return true if SSL Session caching is enabled
*/
public boolean isSessionCachingEnabled() {
return this.sessionCachingEnabled;
}
/**
* Set the flag to enable SSL Session caching.
* @param enableSessionCaching the value of the flag
*/
public void setSessionCachingEnabled(boolean enableSessionCaching) {
this.sessionCachingEnabled = enableSessionCaching;
}
/**
* Get SSL session cache size.
* @return SSL session cache size
*/
public int getSslSessionCacheSize() {
return this.sslSessionCacheSize;
}
/**
* Set SSL session cache size.
* @param sslSessionCacheSize SSL session cache size to set
*/
public void setSslSessionCacheSize(int sslSessionCacheSize) {
this.sslSessionCacheSize = sslSessionCacheSize;
}
/**
* Get SSL session timeout.
* @return SSL session timeout
*/
public int getSslSessionTimeout() {
return this.sslSessionTimeout;
}
/**
* Set SSL session timeout.
* @param sslSessionTimeout SSL session timeout to set
*/
public void setSslSessionTimeout(int sslSessionTimeout) {
this.sslSessionTimeout = sslSessionTimeout;
}
}