11package com .bettercloud .vault ;
22
33import com .bettercloud .vault .api .Auth ;
4- import lombok .AccessLevel ;
5- import lombok .Getter ;
64
75import javax .net .ssl .KeyManager ;
86import javax .net .ssl .KeyManagerFactory ;
97import javax .net .ssl .SSLContext ;
108import javax .net .ssl .TrustManager ;
119import javax .net .ssl .TrustManagerFactory ;
12- import javax .xml .bind .DatatypeConverter ;
1310import java .io .BufferedReader ;
1411import java .io .ByteArrayInputStream ;
1512import java .io .File ;
3330import java .security .cert .X509Certificate ;
3431import java .security .spec .InvalidKeySpecException ;
3532import java .security .spec .PKCS8EncodedKeySpec ;
33+ import java .util .Base64 ;
3634
3735/**
3836 * <p>A container for SSL-related configuration options, meant to be stored within a {@link VaultConfig} instance.</p>
@@ -47,12 +45,12 @@ public class SslConfig implements Serializable {
4745 private static final String VAULT_SSL_VERIFY = "VAULT_SSL_VERIFY" ;
4846 private static final String VAULT_SSL_CERT = "VAULT_SSL_CERT" ;
4947
50- @ Getter private boolean verify ;
51- @ Getter private transient SSLContext sslContext ;
48+ private boolean verify ;
49+ private transient SSLContext sslContext ;
5250 private transient KeyStore trustStore ;
5351 private transient KeyStore keyStore ;
5452 private String keyStorePassword ;
55- @ Getter ( AccessLevel . PROTECTED ) private String pemUTF8 ; // exposed to unit tests
53+ private String pemUTF8 ; // exposed to unit tests
5654 private String clientPemUTF8 ;
5755 private String clientKeyPemUTF8 ;
5856 private Boolean verifyObject ;
@@ -464,6 +462,18 @@ public SslConfig build() throws VaultException {
464462 return this ;
465463 }
466464
465+ public boolean isVerify () {
466+ return verify ;
467+ }
468+
469+ public SSLContext getSslContext () {
470+ return sslContext ;
471+ }
472+
473+ protected String getPemUTF8 () {
474+ return pemUTF8 ;
475+ }
476+
467477 /**
468478 * <p>Constructs the {@link this#sslContext} member field, if SSL verification is enabled and any JKS or PEM-based
469479 * data was populated. This method is broken off from {@link this#build()}, because the same process must
@@ -561,7 +571,7 @@ private SSLContext buildSslContextFromPem() throws VaultException {
561571 // Convert the client private key into a PrivateKey
562572 final String strippedKey = clientKeyPemUTF8 .replace ("-----BEGIN PRIVATE KEY-----" , "" )
563573 .replace ("-----END PRIVATE KEY-----" , "" );
564- final byte [] keyBytes = DatatypeConverter . parseBase64Binary (strippedKey );
574+ final byte [] keyBytes = Base64 . getDecoder (). decode (strippedKey );
565575 final PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec (keyBytes );
566576 final KeyFactory factory = KeyFactory .getInstance ("RSA" );
567577 final PrivateKey privateKey = factory .generatePrivate (pkcs8EncodedKeySpec );
0 commit comments