2
2
3
3
import java .io .IOException ;
4
4
import java .io .InputStream ;
5
+ import java .nio .charset .StandardCharsets ;
5
6
import java .security .KeyStore ;
6
7
import java .security .KeyStoreException ;
7
8
import java .security .NoSuchAlgorithmException ;
16
17
import javax .net .ssl .TrustManagerFactory ;
17
18
import javax .net .ssl .X509TrustManager ;
18
19
20
+ import com .google .common .io .ByteStreams ;
19
21
import org .slf4j .Logger ;
20
22
import org .slf4j .LoggerFactory ;
21
23
22
24
final class YandexTrustManagersProvider {
23
25
private static final Logger logger = LoggerFactory .getLogger (YandexTrustManagerFactory .class );
24
26
25
- private static final String YANDEX_CA_STORE = "certificates/YandexAllCAs.pkcs" ;
26
- private static final String STORE_PASSWORD = "yandex " ;
27
+ private static final String CA_STORE = "certificates/YandexAllCAs.pkcs" ;
28
+ private static final String CA_KEYPHRASE = "certificates/YandexAllCAs.password " ;
27
29
28
30
private final TrustManager [] trustManagers ;
29
31
@@ -45,8 +47,8 @@ private YandexTrustManagersProvider() {
45
47
allTrustManagers .add (composite );
46
48
trustManagers = allTrustManagers .toArray (new TrustManager [0 ]);
47
49
} catch (NoSuchAlgorithmException | KeyStoreException | CertificateException | IOException e ) {
48
- logger .debug ("Can't init yandex root CA settings" , e );
49
50
String msg = "Can't init yandex root CA setting" ;
51
+ logger .debug (msg , e );
50
52
throw new RuntimeException (msg , e );
51
53
}
52
54
}
@@ -55,11 +57,14 @@ private List<TrustManager> getDefaultTrustManagers() throws NoSuchAlgorithmExcep
55
57
return getTrustManagersFromKeyStore (null );
56
58
}
57
59
58
- private List <TrustManager > getCustomTrustManagers ()
59
- throws KeyStoreException , IOException , NoSuchAlgorithmException , CertificateException {
60
+ private List <TrustManager > getCustomTrustManagers () throws KeyStoreException , IOException , NoSuchAlgorithmException ,
61
+ CertificateException {
60
62
KeyStore keyStore = KeyStore .getInstance ("PKCS12" );
61
- try (InputStream is = YandexTrustManagersProvider .class .getClassLoader ().getResourceAsStream (YANDEX_CA_STORE )) {
62
- keyStore .load (is , STORE_PASSWORD .toCharArray ());
63
+ try (InputStream pis = YandexTrustManagersProvider .class .getClassLoader ().getResourceAsStream (CA_KEYPHRASE )) {
64
+ String passPhrase = new String (ByteStreams .toByteArray (pis ), StandardCharsets .UTF_8 );
65
+ try (InputStream is = YandexTrustManagersProvider .class .getClassLoader ().getResourceAsStream (CA_STORE )) {
66
+ keyStore .load (is , passPhrase .toCharArray ());
67
+ }
63
68
}
64
69
return getTrustManagersFromKeyStore (keyStore );
65
70
}
0 commit comments