Skip to content

Commit 761b20c

Browse files
authored
Merge pull request #514 from alex268/master
Fixed low security warnings
2 parents ad72de8 + d754510 commit 761b20c

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
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/MultiX509TrustManager.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88

99
import javax.net.ssl.X509TrustManager;
1010

11+
import org.slf4j.Logger;
12+
import org.slf4j.LoggerFactory;
13+
1114
final class MultiX509TrustManager implements X509TrustManager {
15+
private static final Logger logger = LoggerFactory.getLogger(MultiX509TrustManager.class);
16+
1217
final List<X509TrustManager> trustManagers;
1318

1419
MultiX509TrustManager(final List<X509TrustManager> trustManagers) {
@@ -23,6 +28,7 @@ public void checkClientTrusted(final X509Certificate[] x509Certificates, final S
2328
trustManager.checkClientTrusted(x509Certificates, authType);
2429
return;
2530
} catch (CertificateException ignored) {
31+
logger.trace("cannot use trust manager {}", trustManager, ignored);
2632
}
2733
}
2834
throw new CertificateException("No trust manager trusts this certificates");
@@ -36,6 +42,7 @@ public void checkServerTrusted(final X509Certificate[] x509Certificates, final S
3642
trustManager.checkServerTrusted(x509Certificates, authType);
3743
return;
3844
} catch (CertificateException ignored) {
45+
logger.trace("cannot use trust manager {}", trustManager, ignored);
3946
}
4047
}
4148
throw new CertificateException("No trust manager trusts this certificates");

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

Lines changed: 17 additions & 6 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,9 +17,15 @@
1617
import javax.net.ssl.TrustManagerFactory;
1718
import javax.net.ssl.X509TrustManager;
1819

20+
import com.google.common.io.ByteStreams;
21+
import org.slf4j.Logger;
22+
import org.slf4j.LoggerFactory;
23+
1924
final class YandexTrustManagersProvider {
20-
private static final String YANDEX_CA_STORE = "certificates/YandexAllCAs.pkcs";
21-
private static final String STORE_PASSWORD = "yandex";
25+
private static final Logger logger = LoggerFactory.getLogger(YandexTrustManagerFactory.class);
26+
27+
private static final String CA_STORE = "certificates/YandexAllCAs.pkcs";
28+
private static final String CA_KEYPHRASE = "certificates/YandexAllCAs.password";
2229

2330
private final TrustManager[] trustManagers;
2431

@@ -41,6 +48,7 @@ private YandexTrustManagersProvider() {
4148
trustManagers = allTrustManagers.toArray(new TrustManager[0]);
4249
} catch (NoSuchAlgorithmException | KeyStoreException | CertificateException | IOException e) {
4350
String msg = "Can't init yandex root CA setting";
51+
logger.debug(msg, e);
4452
throw new RuntimeException(msg, e);
4553
}
4654
}
@@ -49,11 +57,14 @@ private List<TrustManager> getDefaultTrustManagers() throws NoSuchAlgorithmExcep
4957
return getTrustManagersFromKeyStore(null);
5058
}
5159

52-
private List<TrustManager> getCustomTrustManagers()
53-
throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException {
60+
private List<TrustManager> getCustomTrustManagers() throws KeyStoreException, IOException, NoSuchAlgorithmException,
61+
CertificateException {
5462
KeyStore keyStore = KeyStore.getInstance("PKCS12");
55-
try (InputStream is = YandexTrustManagersProvider.class.getClassLoader().getResourceAsStream(YANDEX_CA_STORE)) {
56-
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+
}
5768
}
5869
return getTrustManagersFromKeyStore(keyStore);
5970
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
yandex

0 commit comments

Comments
 (0)