Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jumpserver.chen.modules.base.ssl;

import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.io.FileWriter;
Expand All @@ -27,6 +28,10 @@ public class SSLCertManager {

// 获取 CA 证书的路径
public String getCaCertPath() throws IOException {
if (StringUtils.isEmpty(caCert)) {
return null;
}

if (caCertFile == null) {
caCertFile = createTempFile("ca-cert", caCert);
}
Expand All @@ -35,6 +40,10 @@ public String getCaCertPath() throws IOException {

// 获取客户端私钥的路径,并将 PEM 格式的私钥转换为 DER 格式
public String getClientCertKeyPath() throws Exception {
if (StringUtils.isEmpty(clientCertKey)) {
return null;
}

if (clientCertKeyFile == null) {
// 检查 clientCertKey 是否是 PEM 格式并转换为 DER
clientCertKeyFile = createTempFile("client-cert-key", convertPEMToDER(clientCertKey));
Expand All @@ -44,6 +53,11 @@ public String getClientCertKeyPath() throws Exception {

// 获取客户端证书的路径
public String getClientCertPath() throws IOException {

if (StringUtils.isEmpty(clientCert)) {
return null;
}

if (clientCertFile == null) {
clientCertFile = createTempFile("client-cert", clientCert);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jumpserver.chen.modules.postgresql;

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


try {
var sslCaCertPath = sslManager.getCaCertPath();
var sslClientCertPath = sslManager.getClientCertPath();
var sslClientCertKeyPath = sslManager.getClientCertKeyPath();

props.setProperty("ssl", "true");
props.setProperty("sslmode", sslMode);
props.setProperty("sslrootcert", sslManager.getCaCertPath());
props.setProperty("sslcert", sslManager.getClientCertPath());
props.setProperty("sslkey", sslManager.getClientCertKeyPath());

if (StringUtils.isNotEmpty(sslCaCertPath)) {
props.setProperty("sslrootcert", sslManager.getCaCertPath());
}

if (StringUtils.isNotEmpty(sslClientCertPath)) {
props.setProperty("sslcert", sslManager.getClientCertPath());
}

if (StringUtils.isNotEmpty(sslClientCertKeyPath)) {
props.setProperty("sslkey", sslManager.getClientCertKeyPath());
}
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down