那执行器改成http,支付系统指定http调用和https调用,如果https,使用nginx转发,提供nginx配置文件。
This commit is contained in:
1 parent
ee9b209e3d
commit
cf68147d08
7 files changed
+60
-50
No files matched your search
@@ -9,6 +9,4 @@ CHAIN_EXECUTOR_PORT=9088
|
||||
CHAIN_EXECUTOR_ALLOWED_IPS=192.168.3.103,192.168.3.106
|
||||
CHAIN_EXECUTOR_CONFIGURATION_PASSWORD=lqj7667213.520
|
||||
CHAIN_EXECUTOR_ALLOWED_NETWORK=NILE
|
||||
CHAIN_EXECUTOR_BROADCAST_ENABLED=true
|
||||
CHAIN_EXECUTOR_TLS_KEYSTORE=/etc/nginx/certs/rent-truststore.p12
|
||||
CHAIN_EXECUTOR_TLS_PASSWORD=lqj7667213
|
||||
CHAIN_EXECUTOR_BROADCAST_ENABLED=true
|
||||
@@ -10,5 +10,3 @@ export CHAIN_EXECUTOR_ALLOWED_IPS=192.168.3.103,192.168.3.106
|
||||
export CHAIN_EXECUTOR_CONFIGURATION_PASSWORD=lqj7667213.520
|
||||
export CHAIN_EXECUTOR_ALLOWED_NETWORK=NILE
|
||||
export CHAIN_EXECUTOR_BROADCAST_ENABLED=true
|
||||
export CHAIN_EXECUTOR_TLS_KEYSTORE=/etc/nginx/certs/rent-truststore.p12
|
||||
export CHAIN_EXECUTOR_TLS_PASSWORD=lqj7667213
|
||||
@@ -0,0 +1,33 @@
|
||||
# usdt-chain-executor HTTPS 反向代理。
|
||||
# 执行器应监听 127.0.0.1:9089;Nginx 在内网地址 192.168.3.106:9088 提供 HTTPS。
|
||||
# 上线前按实际部署修改 listen、allow、证书路径,并确保防火墙不向公网开放 9088。
|
||||
server {
|
||||
listen 192.168.3.106:9088 ssl;
|
||||
server_name 192.168.3.106;
|
||||
|
||||
ssl_certificate /etc/nginx/certs/rent-cert.pem;
|
||||
ssl_certificate_key /etc/nginx/certs/rent-private.key;
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
ssl_session_cache shared:chain_executor_tls:10m;
|
||||
ssl_session_timeout 10m;
|
||||
|
||||
# 示例为支付系统所在内网地址;部署时必须改成实际来源IP。
|
||||
allow 192.168.3.106;
|
||||
deny all;
|
||||
|
||||
location /internal/v1/ {
|
||||
proxy_pass http://127.0.0.1:9089;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Connection "";
|
||||
proxy_set_header Authorization $http_authorization;
|
||||
proxy_set_header Host $host;
|
||||
proxy_connect_timeout 2s;
|
||||
proxy_read_timeout 5s;
|
||||
proxy_send_timeout 5s;
|
||||
proxy_buffering off;
|
||||
}
|
||||
|
||||
location / {
|
||||
return 404;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -9,24 +9,16 @@ import com.ruoyi.system.mapper.UsdtConfigMapper;
|
||||
import com.ruoyi.system.service.WalletSigningService;
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsServer;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.KeyStore;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -99,18 +91,13 @@ public class IntranetExecutionServer {
|
||||
checkReady();
|
||||
log.info("启动检查通过,网络={},允许来源数量={},广播已启用", network, allowed.size());
|
||||
InetSocketAddress address = new InetSocketAddress(bind, Integer.parseInt(required("CHAIN_EXECUTOR_PORT")));
|
||||
if (bind.isLoopbackAddress() && environment.get("CHAIN_EXECUTOR_TLS_KEYSTORE") == null) {
|
||||
server = HttpServer.create(address, 32);
|
||||
} else {
|
||||
HttpsServer https = HttpsServer.create(address, 32);
|
||||
https.setHttpsConfigurator(new HttpsConfigurator(tlsContext()));
|
||||
server = https;
|
||||
}
|
||||
// 执行器只提供HTTP。需要HTTPS时由同机Nginx终止TLS并转发到回环监听端口。
|
||||
server = HttpServer.create(address, 32);
|
||||
server.createContext("/", this::handle);
|
||||
server.setExecutor(httpThreads);
|
||||
server.start();
|
||||
log.info("内网执行服务已监听,地址={},端口={},传输协议={}", bind.getHostAddress(),
|
||||
server.getAddress().getPort(), server instanceof HttpsServer ? "HTTPS" : "HTTP-LOOPBACK");
|
||||
log.info("内网执行服务已监听,地址={},端口={},传输协议=HTTP", bind.getHostAddress(),
|
||||
server.getAddress().getPort());
|
||||
}
|
||||
|
||||
private void handle(HttpExchange exchange) throws java.io.IOException {
|
||||
@@ -131,7 +118,7 @@ public class IntranetExecutionServer {
|
||||
}
|
||||
String path = exchange.getRequestURI().getPath();
|
||||
if ("/internal/v1/connectivity".equals(path) && "GET".equals(exchange.getRequestMethod())) {
|
||||
// 联通测试只证明网络、TLS、来源白名单和服务令牌可用;业务就绪由 readiness 继续校验。
|
||||
// 联通测试只证明传输链路、来源白名单和服务令牌可用;业务就绪由 readiness 继续校验。
|
||||
log.info("执行器联通测试通过,来源={}", peer.getHostAddress());
|
||||
respond(exchange, 200, "CONNECTED");
|
||||
} else if ("/internal/v1/readiness".equals(path) && "GET".equals(exchange.getRequestMethod())) {
|
||||
@@ -218,21 +205,6 @@ public class IntranetExecutionServer {
|
||||
}
|
||||
}
|
||||
|
||||
private SSLContext tlsContext() throws Exception {
|
||||
char[] secret = required("CHAIN_EXECUTOR_TLS_PASSWORD").toCharArray();
|
||||
try (InputStream stream = Files.newInputStream(Paths.get(required("CHAIN_EXECUTOR_TLS_KEYSTORE")))) {
|
||||
KeyStore keys = KeyStore.getInstance("PKCS12");
|
||||
keys.load(stream, secret);
|
||||
KeyManagerFactory managers = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
managers.init(keys, secret);
|
||||
SSLContext context = SSLContext.getInstance("TLSv1.2");
|
||||
context.init(managers.getKeyManagers(), null, null);
|
||||
return context;
|
||||
} finally {
|
||||
Arrays.fill(secret, '\0');
|
||||
}
|
||||
}
|
||||
|
||||
private static void respond(HttpExchange exchange, int status, String message) throws java.io.IOException {
|
||||
byte[] bytes = message.getBytes(StandardCharsets.UTF_8);
|
||||
exchange.getResponseHeaders().set("Content-Type", "text/plain; charset=utf-8");
|
||||
|
||||
Reference in new issue
Block a user