Skip to content

Commit 00dd1a3

Browse files
authored
[fix](bdbje)fix bdbje can't set truststore password (#347)
1 parent 473ae0a commit 00dd1a3

File tree

5 files changed

+99
-4
lines changed

5 files changed

+99
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## bdbje-18.3.15-doris-SNAPSHOT (20250813)
4+
5+
1. fix TrustStore can't set password
6+
37
## bdbje-18.3.14-doris-SNAPSHOT (20221116)
48

59
1. support ipv6 address parsing

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111
<groupId>org.apache.doris</groupId>
1212
<artifactId>je</artifactId>
13-
<version>18.3.14-doris-SNAPSHOT</version>
13+
<version>18.3.15-doris-SNAPSHOT</version>
1414
<name>bdb-je apache doris release</name>
1515
<url>https://doris.apache.org/</url>
1616
<description>fork from bdb-je 18.3.12 from maven with starrocks bdbje patches</description>

src/main/java/com/sleepycat/je/rep/ReplicationSSLConfig.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public class ReplicationSSLConfig extends ReplicationNetworkConfig {
9696
* {@link #SSL_SERVER_KEY_ALIAS je.rep.ssl.serverKeyAlias}
9797
* {@link #SSL_TRUSTSTORE_FILE je.rep.ssl.trustStoreFile}
9898
* {@link #SSL_TRUSTSTORE_TYPE je.rep.ssl.trustStoreType}
99+
* {@link #SSL_KEYSTORE_PASSWORD je.rep.ssl.keyStorePassword}
99100
* {@link #SSL_CIPHER_SUITES je.rep.ssl.cipherSuites}
100101
* {@link #SSL_PROTOCOLS je.rep.ssl.protocols}
101102
* {@link #SSL_AUTHENTICATOR je.rep.ssl.authenticator}
@@ -243,6 +244,25 @@ public class ReplicationSSLConfig extends ReplicationNetworkConfig {
243244
public static final String SSL_CLIENT_KEY_ALIAS =
244245
EnvironmentParams.REP_PARAM_PREFIX + "ssl.clientKeyAlias";
245246

247+
/**
248+
* The password for accessing the Java truststore file for SSL data channnel
249+
* factories. If this parameter is not set or has an empty value, the Java
250+
* system property <code>javax.net.ssl.trustStorePassword</code> is used.
251+
*
252+
* <p><table border="1"
253+
* summary="Information about configuration option">
254+
* <tr><td>Name</td><td>Type</td><td>Mutable</td><td>Default</td></tr>
255+
* <tr>
256+
* <td>{@value}</td>
257+
* <td>String</td>
258+
* <td>No</td>
259+
* <td>""</td>
260+
* </tr>
261+
* </table>
262+
*/
263+
public static final String SSL_TRUSTSTORE_PASSWORD =
264+
EnvironmentParams.REP_PARAM_PREFIX + "ssl.trustStorePassword";
265+
246266
/**
247267
* The path to the Java truststore file for SSL data channel factories.
248268
* The specified path must be absolute.
@@ -501,6 +521,7 @@ public class ReplicationSSLConfig extends ReplicationNetworkConfig {
501521
repSSLProperties.add(SSL_KEYSTORE_TYPE);
502522
repSSLProperties.add(SSL_SERVER_KEY_ALIAS);
503523
repSSLProperties.add(SSL_CLIENT_KEY_ALIAS);
524+
repSSLProperties.add(SSL_TRUSTSTORE_PASSWORD);
504525
repSSLProperties.add(SSL_TRUSTSTORE_FILE);
505526
repSSLProperties.add(SSL_TRUSTSTORE_TYPE);
506527
repSSLProperties.add(SSL_CIPHER_SUITES);
@@ -806,6 +827,40 @@ public void setSSLClientKeyAliasVoid(String alias) {
806827
validateParams);
807828
}
808829

830+
/**
831+
* Returns the password for the Java TrustStore file to be used for SSL key
832+
* pair retrieval.
833+
*
834+
* @return the TrustStore password
835+
*/
836+
public String getSSLTrustStorePassword() {
837+
return DbConfigManager.getVal(props, RepParams.SSL_TRUSTSTORE_PASSWORD);
838+
}
839+
840+
/**
841+
* Sets the password for the Java TrustStore file to be used when creating
842+
* SSL connections.
843+
*
844+
* @param password the TrustStore password
845+
*
846+
* @return this
847+
*/
848+
public ReplicationNetworkConfig setSSLTrustStorePassword(String password) {
849+
850+
setSSLTrustStorePasswordVoid(password);
851+
return this;
852+
}
853+
854+
/**
855+
* @hidden
856+
* The void return setter for use by Bean editors.
857+
*/
858+
public void setSSLTrustStorePasswordVoid(String password) {
859+
860+
DbConfigManager.setVal(props, RepParams.SSL_TRUSTSTORE_PASSWORD, password,
861+
validateParams);
862+
}
863+
809864
/**
810865
* Returns the name of the Java TrustStore file to be used for SSL
811866
* certificate validation.

src/main/java/com/sleepycat/je/rep/impl/RepParams.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,16 @@ public void validateValue(String value) {
13821382
false, // mutable
13831383
true); // forReplication
13841384

1385+
/**
1386+
* SSL TrustStore password
1387+
* @see ReplicationSSLConfig#SSL_TRUSTSTORE_PASSWORD
1388+
*/
1389+
public static final ConfigParam SSL_TRUSTSTORE_PASSWORD =
1390+
new ConfigParam(ReplicationSSLConfig.SSL_TRUSTSTORE_PASSWORD,
1391+
"", // default
1392+
false, // mutable
1393+
true); // forReplication
1394+
13851395
/**
13861396
* SSL TrustStore file
13871397
* @see ReplicationSSLConfig#SSL_TRUSTSTORE_FILE

src/main/java/com/sleepycat/je/rep/utilint/net/SSLChannelFactory.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,32 @@ private static TrustManager[] buildTrustManagerList(KeyStoreInfo tsInfo) {
526526
return tmf.getTrustManagers();
527527
}
528528

529+
/**
530+
* Finds the truststore password based on the input config.
531+
*/
532+
private static char[] getTrustStorePassword(InstanceContext context) {
533+
534+
final ReplicationSSLConfig config =
535+
(ReplicationSSLConfig) context.getRepNetConfig();
536+
537+
char[] ksPw = null;
538+
539+
String ksPwProp = config.getSSLTrustStorePassword();
540+
if (ksPwProp == null || ksPwProp.isEmpty()) {
541+
/*
542+
* Finally, consider the standard Java Keystore
543+
* password system property
544+
*/
545+
ksPwProp =
546+
System.getProperty("javax.net.ssl.trustStorePassword");
547+
}
548+
if (ksPwProp != null) {
549+
ksPw = ksPwProp.toCharArray();
550+
}
551+
552+
return ksPw;
553+
}
554+
529555
/**
530556
* Based on the input config, read the configured TrustStore into memory.
531557
*/
@@ -553,12 +579,12 @@ private static KeyStoreInfo readTrustStoreInfo(InstanceContext context) {
553579
/*
554580
* Build a TrustStore, if specified
555581
*/
582+
final char[] tsPw = getTrustStorePassword(context);
556583

557584
if (tsProp != null) {
558-
final KeyStore ts =
559-
loadStore(tsProp, null, "truststore", tsTypeProp);
585+
final KeyStore ts = loadStore(tsProp, tsPw, "truststore", tsTypeProp);
560586

561-
return new KeyStoreInfo(tsProp, ts, null);
587+
return new KeyStoreInfo(tsProp, ts, tsPw);
562588
}
563589

564590
return null;

0 commit comments

Comments
 (0)