Skip to content

Commit d754510

Browse files
committed
Hard-coded password was moved to resource file
1 parent 806b13f commit d754510

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

core/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
<directory>src/main/resources</directory>
8888
<includes>
8989
<include>**/*.pkcs</include>
90+
<include>**/*.password</include>
9091
</includes>
9192
<filtering>false</filtering>
9293
</resource>

core/src/main/java/tech/ydb/core/ssl/YandexTrustManagersProvider.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.IOException;
44
import java.io.InputStream;
5+
import java.nio.charset.StandardCharsets;
56
import java.security.KeyStore;
67
import java.security.KeyStoreException;
78
import java.security.NoSuchAlgorithmException;
@@ -16,14 +17,15 @@
1617
import javax.net.ssl.TrustManagerFactory;
1718
import javax.net.ssl.X509TrustManager;
1819

20+
import com.google.common.io.ByteStreams;
1921
import org.slf4j.Logger;
2022
import org.slf4j.LoggerFactory;
2123

2224
final class YandexTrustManagersProvider {
2325
private static final Logger logger = LoggerFactory.getLogger(YandexTrustManagerFactory.class);
2426

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";
2729

2830
private final TrustManager[] trustManagers;
2931

@@ -45,8 +47,8 @@ private YandexTrustManagersProvider() {
4547
allTrustManagers.add(composite);
4648
trustManagers = allTrustManagers.toArray(new TrustManager[0]);
4749
} catch (NoSuchAlgorithmException | KeyStoreException | CertificateException | IOException e) {
48-
logger.debug("Can't init yandex root CA settings", e);
4950
String msg = "Can't init yandex root CA setting";
51+
logger.debug(msg, e);
5052
throw new RuntimeException(msg, e);
5153
}
5254
}
@@ -55,11 +57,14 @@ private List<TrustManager> getDefaultTrustManagers() throws NoSuchAlgorithmExcep
5557
return getTrustManagersFromKeyStore(null);
5658
}
5759

58-
private List<TrustManager> getCustomTrustManagers()
59-
throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException {
60+
private List<TrustManager> getCustomTrustManagers() throws KeyStoreException, IOException, NoSuchAlgorithmException,
61+
CertificateException {
6062
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+
}
6368
}
6469
return getTrustManagersFromKeyStore(keyStore);
6570
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
yandex

0 commit comments

Comments
 (0)