@@ -53,14 +53,13 @@ public static boolean isNotNullOrEmpty(String val) {
53
53
return val != null && val .length () > 0 ;
54
54
}
55
55
56
- public static KeyManager [] keyManagers (String certData , String certFile , String keyData , String keyFile ,
56
+ public static KeyManager [] keyManagers (byte [] certData , byte [] keyData ,
57
57
String algo , String passphrase , String keyStoreFile , String keyStorePassphrase )
58
58
throws NoSuchAlgorithmException , UnrecoverableKeyException , KeyStoreException , CertificateException ,
59
59
InvalidKeySpecException , IOException {
60
60
KeyManager [] keyManagers = null ;
61
- if ((isNotNullOrEmpty (certData ) || isNotNullOrEmpty (certFile ))
62
- && (isNotNullOrEmpty (keyData ) || isNotNullOrEmpty (keyFile ))) {
63
- KeyStore keyStore = createKeyStore (certData , certFile , keyData , keyFile , algo , passphrase , keyStoreFile ,
61
+ if (certData != null && keyData != null ) {
62
+ KeyStore keyStore = createKeyStore (certData , keyData , algo , passphrase , keyStoreFile ,
64
63
keyStorePassphrase );
65
64
KeyManagerFactory kmf = KeyManagerFactory .getInstance (KeyManagerFactory .getDefaultAlgorithm ());
66
65
kmf .init (keyStore , passphrase .toCharArray ());
@@ -69,12 +68,11 @@ public static KeyManager[] keyManagers(String certData, String certFile, String
69
68
return keyManagers ;
70
69
}
71
70
72
- public static KeyStore createKeyStore (String clientCertData , String clientCertFile , String clientKeyData ,
73
- String clientKeyFile , String clientKeyAlgo , String clientKeyPassphrase , String keyStoreFile ,
74
- String keyStorePassphrase ) throws IOException , CertificateException , NoSuchAlgorithmException ,
75
- InvalidKeySpecException , KeyStoreException {
76
- try (InputStream certInputStream = getInputStreamFromDataOrFile (clientCertData , clientCertFile );
77
- InputStream keyInputStream = getInputStreamFromDataOrFile (clientKeyData , clientKeyFile )) {
71
+ public static KeyStore createKeyStore (byte [] clientCertData , byte [] clientKeyData , String clientKeyAlgo ,
72
+ String clientKeyPassphrase , String keyStoreFile , String keyStorePassphrase ) throws IOException ,
73
+ CertificateException , NoSuchAlgorithmException , InvalidKeySpecException , KeyStoreException {
74
+ try (InputStream certInputStream = new ByteArrayInputStream (clientCertData );
75
+ InputStream keyInputStream = new ByteArrayInputStream (clientKeyData )) {
78
76
return createKeyStore (certInputStream , keyInputStream , clientKeyAlgo ,
79
77
clientKeyPassphrase != null ? clientKeyPassphrase .toCharArray () : null ,
80
78
keyStoreFile , getKeyStorePassphrase (keyStorePassphrase ));
@@ -264,18 +262,6 @@ private static boolean loadDefaultStoreFile(KeyStore keyStore, File fileToLoad,
264
262
return false ;
265
263
}
266
264
267
- public static InputStream getInputStreamFromDataOrFile (String data , String file ) throws FileNotFoundException {
268
- if (data != null ) {
269
- byte [] bytes = Base64 .decodeBase64 (data );
270
- // TODO handle non-base64 here?
271
- return new ByteArrayInputStream (bytes );
272
- }
273
- if (file != null ) {
274
- return new FileInputStream (file );
275
- }
276
- return null ;
277
- }
278
-
279
265
private static char [] getKeyStorePassphrase (String keyStorePassphrase ) {
280
266
if (keyStorePassphrase == null || keyStorePassphrase .length () == 0 ) {
281
267
return System .getProperty ("javax.net.ssl.keyStorePassword" , "changeit" ).toCharArray ();
0 commit comments