11package org .logstash .plugins .inputs .http .util ;
22
3- import io .netty .handler .ssl .OpenSsl ;
43import io .netty .handler .ssl .SslContext ;
54import io .netty .handler .ssl .SslContextBuilder ;
65import org .apache .logging .log4j .LogManager ;
1817import java .util .ArrayList ;
1918import java .util .Arrays ;
2019import java .util .List ;
20+ import javax .crypto .Cipher ;
21+ import javax .net .ssl .SSLServerSocketFactory ;
2122
2223public class SslSimpleBuilder implements SslBuilder {
2324
@@ -26,9 +27,8 @@ public class SslSimpleBuilder implements SslBuilder {
2627 /*
2728 Modern Ciphers Compatibility List from
2829 https://wiki.mozilla.org/Security/Server_Side_TLS
29- This list require the OpenSSl engine for netty.
3030 */
31- public final static String [] DEFAULT_CIPHERS = new String [] {
31+ private final static String [] DEFAULT_CIPHERS = new String [] {
3232 "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384" ,
3333 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384" ,
3434 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256" ,
@@ -39,25 +39,40 @@ public class SslSimpleBuilder implements SslBuilder {
3939 "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256"
4040 };
4141
42- private String [] ciphers = DEFAULT_CIPHERS ;
42+ private final static String [] DEFAULT_CIPHERS_LIMITED = new String [] {
43+ "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384" ,
44+ "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384" ,
45+ "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256" ,
46+ "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" ,
47+ "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384" ,
48+ "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384" ,
49+ "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256" ,
50+ "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256"
51+ };
52+
53+ private String [] ciphers = getDefaultCiphers ();
4354 private File sslKeyFile ;
4455 private File sslCertificateFile ;
4556 private String [] certificateAuthorities ;
4657 private String passPhrase ;
58+ private String [] supportedCiphers = ((SSLServerSocketFactory )SSLServerSocketFactory
59+ .getDefault ()).getSupportedCipherSuites ();
4760
4861 public SslSimpleBuilder (String sslCertificateFilePath , String sslKeyFilePath , String pass ) throws FileNotFoundException {
4962 sslCertificateFile = new File (sslCertificateFilePath );
5063 sslKeyFile = new File (sslKeyFilePath );
5164 passPhrase = pass ;
52- ciphers = DEFAULT_CIPHERS ;
5365 }
5466
5567 public SslSimpleBuilder setCipherSuites (String [] ciphersSuite ) throws IllegalArgumentException {
5668 for (String cipher : ciphersSuite ) {
57- if (!OpenSsl .isCipherSuiteAvailable (cipher )) {
69+ if (Arrays .asList (supportedCiphers ).contains (cipher )) {
70+ logger .debug ("Cipher is supported: {}" , cipher );
71+ }else {
72+ if (!isUnlimitedJCEAvailable ()) {
73+ logger .warn ("JCE Unlimited Strength Jurisdiction Policy not installed" );
74+ }
5875 throw new IllegalArgumentException ("Cipher `" + cipher + "` is not available" );
59- } else {
60- logger .debug ("Cipher is supported: " + cipher );
6176 }
6277 }
6378
@@ -74,7 +89,7 @@ public SslContext build() throws IOException, NoSuchAlgorithmException, Certific
7489 SslContextBuilder builder = SslContextBuilder .forServer (sslCertificateFile , sslKeyFile , passPhrase );
7590
7691 if (logger .isDebugEnabled ()) {
77- logger .debug ("Available ciphers:" + Arrays .toString (OpenSsl . availableOpenSslCipherSuites (). toArray () ));
92+ logger .debug ("Available ciphers: " + Arrays .toString (supportedCiphers ));
7893 logger .debug ("Ciphers: " + Arrays .toString (ciphers ));
7994 }
8095
@@ -116,4 +131,24 @@ private boolean requireClientAuth() {
116131
117132 return false ;
118133 }
134+
135+ public static String [] getDefaultCiphers (){
136+ if (isUnlimitedJCEAvailable ()){
137+ return DEFAULT_CIPHERS ;
138+ } else {
139+ logger .warn ("JCE Unlimited Strength Jurisdiction Policy not installed - max key length is 128 bits" );
140+ return DEFAULT_CIPHERS_LIMITED ;
141+ }
142+ }
143+
144+
145+ public static boolean isUnlimitedJCEAvailable (){
146+ try {
147+ return (Cipher .getMaxAllowedKeyLength ("AES" ) > 128 );
148+ } catch (NoSuchAlgorithmException e ) {
149+ logger .warn ("AES not available" , e );
150+ return false ;
151+ }
152+ }
153+
119154}
0 commit comments