Skip to content

Commit 12234a4

Browse files
zhuxiaolong37huiguangjun
authored andcommitted
Add Keystore to Configuration Class
1 parent 34b1c8c commit 12234a4

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/main/java/com/aliyun/oss/ClientConfiguration.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package com.aliyun.oss;
2121

22+
import java.security.KeyStore;
2223
import java.util.ArrayList;
2324
import java.util.Collections;
2425
import java.util.LinkedHashMap;
@@ -129,6 +130,8 @@ public class ClientConfiguration {
129130

130131
private boolean enableAutoCorrectClockSkew = false;
131132

133+
private KeyStore keyStore = null;
134+
132135
public ClientConfiguration() {
133136
super();
134137
AppendDefaultExcludeList(this.cnameExcludeList);
@@ -1017,4 +1020,35 @@ public boolean isEnableAutoCorrectClockSkew() {
10171020
public void setEnableAutoCorrectClockSkew(boolean enableAutoCorrectClockSkew) {
10181021
this.enableAutoCorrectClockSkew = enableAutoCorrectClockSkew;
10191022
}
1023+
1024+
/**
1025+
* Gets the KeyStore currently configured for SSL/TLS operations.
1026+
* <p>
1027+
* This KeyStore typically contains trusted certificates (for server verification)
1028+
* or client certificates (for mutual authentication). The returned KeyStore is
1029+
* the same instance that was set via {@link #setKeyStore(KeyStore)}.
1030+
* <p>
1031+
* Note: If no KeyStore has been explicitly set, this method may return `null`.
1032+
* Applications should ensure the KeyStore is properly initialized and configured
1033+
* before use in SSL/TLS contexts.
1034+
*
1035+
* @return the KeyStore instance (e.g., JKS or PKCS12 format), or `null` if not set.
1036+
*/
1037+
public KeyStore getKeyStore() {
1038+
return keyStore;
1039+
}
1040+
1041+
/**
1042+
* Sets the KeyStore to be used for SSL/TLS operations.
1043+
* <p>
1044+
* This KeyStore typically contains trusted certificates (for server verification)
1045+
* or client certificates (for mutual authentication). The KeyStore must be
1046+
* pre-initialized and populated with the necessary certificates/keys before being set.
1047+
*
1048+
* @param keyStore the KeyStore instance (e.g., JKS or PKCS12 format) to be used.
1049+
* Must not be null.
1050+
*/
1051+
public void setKeyStore(KeyStore keyStore) {
1052+
this.keyStore = keyStore;
1053+
}
10201054
}

src/main/java/com/aliyun/oss/common/comm/DefaultServiceClient.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,11 @@ protected HttpClientConnectionManager createHttpClientConnectionManager() {
248248

249249
// get trustManager using default certification from jdk
250250
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
251-
tmf.init((KeyStore) null);
251+
if (config.getKeyStore() != null){
252+
tmf.init(config.getKeyStore());
253+
} else {
254+
tmf.init((KeyStore) null);
255+
}
252256
trustManagerList.addAll(Arrays.asList(tmf.getTrustManagers()));
253257

254258
final List<X509TrustManager> finalTrustManagerList = new ArrayList<X509TrustManager>();

0 commit comments

Comments
 (0)