@@ -190,14 +190,12 @@ public void configure(Map<String, ?> configs) {
190190 (Password ) configs .get (SslConfigs .SSL_KEYSTORE_PASSWORD_CONFIG ),
191191 (Password ) configs .get (SslConfigs .SSL_KEY_PASSWORD_CONFIG ),
192192 (Password ) configs .get (SslConfigs .SSL_KEYSTORE_KEY_CONFIG ),
193- (Password ) configs .get (SslConfigs .SSL_KEYSTORE_CERTIFICATE_CHAIN_CONFIG )),
194- Boolean .parseBoolean ((String ) configs .get (SslConfigs .SSL_KEYSTORE_AS_STRING )));
193+ (Password ) configs .get (SslConfigs .SSL_KEYSTORE_CERTIFICATE_CHAIN_CONFIG ));
195194
196195 this .truststore = createTruststore ((String ) configs .get (SslConfigs .SSL_TRUSTSTORE_TYPE_CONFIG ),
197196 (String ) configs .get (SslConfigs .SSL_TRUSTSTORE_LOCATION_CONFIG ),
198197 (Password ) configs .get (SslConfigs .SSL_TRUSTSTORE_PASSWORD_CONFIG ),
199- (Password ) configs .get (SslConfigs .SSL_TRUSTSTORE_CERTIFICATES_CONFIG )),
200- Boolean .parseBoolean ((String ) configs .get (SslConfigs .SSL_TRUSTSTORE_AS_STRING )));
198+ (Password ) configs .get (SslConfigs .SSL_TRUSTSTORE_CERTIFICATES_CONFIG ));
201199
202200 this .sslContext = createSSLContext (keystore , truststore , configs );
203201 }
@@ -360,7 +358,7 @@ protected TrustManager[] getTrustManagers(SecurityStore truststore, String tmfAl
360358 }
361359
362360 // Visibility to override for testing
363- protected SecurityStore createKeystore (String type , String path , Password password , Password keyPassword , Password privateKey , Password certificateChain , boolean pathAsBase64EncodedString ) {
361+ protected SecurityStore createKeystore (String type , String path , Password password , Password keyPassword , Password privateKey , Password certificateChain ) {
364362 if (privateKey != null ) {
365363 if (!PEM_TYPE .equals (type ))
366364 throw new InvalidConfigurationException ("SSL private key can be specified only for PEM, but key store type is " + type + "." );
@@ -384,12 +382,12 @@ else if (password != null)
384382 } else if (path != null && password == null ) {
385383 throw new InvalidConfigurationException ("SSL key store is specified, but key store password is not specified." );
386384 } else if (path != null && password != null ) {
387- return new FileBasedStore (type , path , password , keyPassword , true , pathAsBase64EncodedString );
385+ return new FileBasedStore (type , path , password , keyPassword , true );
388386 } else
389387 return null ; // path == null, clients may use this path with brokers that don't require client auth
390388 }
391389
392- private static SecurityStore createTruststore (String type , String path , Password password , Password trustStoreCerts , boolean pathAsBase64EncodedString ) {
390+ private static SecurityStore createTruststore (String type , String path , Password password , Password trustStoreCerts ) {
393391 if (trustStoreCerts != null ) {
394392 if (!PEM_TYPE .equals (type ))
395393 throw new InvalidConfigurationException ("SSL trust store certs can be specified only for PEM, but trust store type is " + type + "." );
@@ -407,7 +405,7 @@ else if (password != null)
407405 } else if (path == null && password != null ) {
408406 throw new InvalidConfigurationException ("SSL trust store is not specified, but trust store password is specified." );
409407 } else if (path != null ) {
410- return new FileBasedStore (type , path , password , null , false , pathAsBase64EncodedString );
408+ return new FileBasedStore (type , path , password , null , false );
411409 } else
412410 return null ;
413411 }
@@ -428,15 +426,14 @@ static class FileBasedStore implements SecurityStore {
428426 private final KeyStore keyStore ;
429427 private final boolean pathAsBase64EncodedString ;
430428
431- FileBasedStore (String type , String path , Password password , Password keyPassword , boolean isKeyStore , boolean pathAsBase64EncodedString ) {
429+ FileBasedStore (String type , String path , Password password , Password keyPassword , boolean isKeyStore ) {
432430 Objects .requireNonNull (type , "type must not be null" );
433431 this .type = type ;
434432 this .path = path ;
435433 this .password = password ;
436434 this .keyPassword = keyPassword ;
437435 fileLastModifiedMs = lastModifiedMs (path );
438436 this .keyStore = load (isKeyStore );
439- this .pathAsBase64EncodedString = pathAsBase64EncodedString ;
440437 }
441438
442439 @ Override
@@ -457,28 +454,15 @@ public char[] keyPassword() {
457454 * using the specified configs (e.g. if the password or keystore type is invalid)
458455 */
459456 protected KeyStore load (boolean isKeyStore ) {
460- if (path == null ) {
461- throw new KafkaException ("Failed to load SSL keystore: path was null" );
462- }
463- InputStream in ;
464- try {
465- if (pathAsBase64EncodedString ) {
466- String encodedKeyStore = System .getenv (path );
467- in = new ByteArrayInputStream (Base64 .decoder ().decode (encodedKeyStore ));
468- } else if (type .equalsIgnoreCase (TruststoreUtility .CRT )) {
469- return TruststoreUtility .createTrustStore (path , password .value ());
470- } else {
471- in = new FileInputStream (path );
457+ try (InputStream in = Files .newInputStream (Paths .get (path ))) {
458+ KeyStore ks = KeyStore .getInstance (type );
459+ // If a password is not set access to the truststore is still available, but integrity checking is disabled.
460+ char [] passwordChars = password != null ? password .value ().toCharArray () : null ;
461+ ks .load (in , passwordChars );
462+ return ks ;
463+ } catch (GeneralSecurityException | IOException e ) {
464+ throw new KafkaException ("Failed to load SSL keystore " + path + " of type " + type , e );
472465 }
473- KeyStore ks = KeyStore .getInstance (type );
474- // If a password is not set access to the truststore is still available, but integrity checking is disabled.
475- char [] passwordChars = password != null ? password .value ().toCharArray () : null ;
476- ks .load (in , passwordChars );
477- in .close ();
478- return ks ;
479- } catch (GeneralSecurityException | IOException e ) {
480- throw new KafkaException ("Failed to load SSL keystore " + path + " of type " + type , e );
481- }
482466 }
483467
484468 private Long lastModifiedMs (String path ) {
0 commit comments