Skip to content

Commit 75b4265

Browse files
committed
fix: fix postgre sql ssl error
1 parent ec0ce3a commit 75b4265

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

backend/modules/src/main/java/org.jumpserver.chen.modules/base/ssl/SSLCertManager.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.jumpserver.chen.modules.base.ssl;
22

33
import lombok.Setter;
4+
import org.apache.commons.lang3.StringUtils;
45

56
import java.io.File;
67
import java.io.FileWriter;
@@ -27,6 +28,10 @@ public class SSLCertManager {
2728

2829
// 获取 CA 证书的路径
2930
public String getCaCertPath() throws IOException {
31+
if (StringUtils.isEmpty(caCert)) {
32+
return null;
33+
}
34+
3035
if (caCertFile == null) {
3136
caCertFile = createTempFile("ca-cert", caCert);
3237
}
@@ -35,6 +40,10 @@ public String getCaCertPath() throws IOException {
3540

3641
// 获取客户端私钥的路径,并将 PEM 格式的私钥转换为 DER 格式
3742
public String getClientCertKeyPath() throws Exception {
43+
if (StringUtils.isEmpty(clientCertKey)) {
44+
return null;
45+
}
46+
3847
if (clientCertKeyFile == null) {
3948
// 检查 clientCertKey 是否是 PEM 格式并转换为 DER
4049
clientCertKeyFile = createTempFile("client-cert-key", convertPEMToDER(clientCertKey));
@@ -44,6 +53,11 @@ public String getClientCertKeyPath() throws Exception {
4453

4554
// 获取客户端证书的路径
4655
public String getClientCertPath() throws IOException {
56+
57+
if (StringUtils.isEmpty(clientCert)) {
58+
return null;
59+
}
60+
4761
if (clientCertFile == null) {
4862
clientCertFile = createTempFile("client-cert", clientCert);
4963
}

backend/modules/src/main/java/org.jumpserver.chen.modules/postgresql/PostgresqlConnectionManager.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.jumpserver.chen.modules.postgresql;
22

3+
import org.apache.commons.lang3.StringUtils;
34
import org.jumpserver.chen.framework.datasource.Datasource;
45
import org.jumpserver.chen.framework.datasource.base.BaseConnectionManager;
56
import org.jumpserver.chen.framework.datasource.entity.DBConnectInfo;
@@ -48,11 +49,24 @@ protected void setSSLProps(Properties props) {
4849

4950

5051
try {
52+
var sslCaCertPath = sslManager.getCaCertPath();
53+
var sslClientCertPath = sslManager.getClientCertPath();
54+
var sslClientCertKeyPath = sslManager.getClientCertKeyPath();
55+
5156
props.setProperty("ssl", "true");
5257
props.setProperty("sslmode", sslMode);
53-
props.setProperty("sslrootcert", sslManager.getCaCertPath());
54-
props.setProperty("sslcert", sslManager.getClientCertPath());
55-
props.setProperty("sslkey", sslManager.getClientCertKeyPath());
58+
59+
if (StringUtils.isNotEmpty(sslCaCertPath)) {
60+
props.setProperty("sslrootcert", sslManager.getCaCertPath());
61+
}
62+
63+
if (StringUtils.isNotEmpty(sslClientCertPath)) {
64+
props.setProperty("sslcert", sslManager.getClientCertPath());
65+
}
66+
67+
if (StringUtils.isNotEmpty(sslClientCertKeyPath)) {
68+
props.setProperty("sslkey", sslManager.getClientCertKeyPath());
69+
}
5670
} catch (Exception e) {
5771
throw new RuntimeException(e);
5872
}

0 commit comments

Comments
 (0)