@@ -24,6 +24,7 @@ public class ProxyClient {
|
||||
|
||||
setAlias("neutrino.proxy.tunnel.server-ip", "serverIp");
|
||||
setAlias("neutrino.proxy.tunnel.server-port", "serverPort");
|
||||
setAlias("neutrino.proxy.tunnel.sm2-encrypt-enable", "sm2EncryptEnable");
|
||||
setAlias("neutrino.proxy.tunnel.ssl-enable", "sslEnable");
|
||||
setAlias("neutrino.proxy.tunnel.jks-path", "jksPath");
|
||||
setAlias("neutrino.proxy.tunnel.key-store-password", "keyStorePassword");
|
||||
|
||||
+1
@@ -37,6 +37,7 @@ public class ProxyConfig {
|
||||
private String jksPath;
|
||||
private String serverIp;
|
||||
private Integer serverPort;
|
||||
private Boolean sm2EncryptEnable;
|
||||
private Boolean sslEnable;
|
||||
private Integer obtainLicenseInterval;
|
||||
private String licenseKey;
|
||||
|
||||
+6
-1
@@ -31,7 +31,7 @@ public class ProxyMessageAuthHandler implements ProxyMessageHandler {
|
||||
String info = proxyMessage.getInfo();
|
||||
ONode load = ONode.load(info);
|
||||
Integer code = load.get("code").getInt();
|
||||
log.info("Auth result:{}", info);
|
||||
log.info("Auth result: {}", load.get("msg").getString());
|
||||
if (ExceptionEnum.AUTH_FAILED.getCode().equals(code)) {
|
||||
// 客户端认证失败,直接停止服务
|
||||
log.info("client auth failed , client stop.");
|
||||
@@ -45,6 +45,11 @@ public class ProxyMessageAuthHandler implements ProxyMessageHandler {
|
||||
context.channel().close();
|
||||
}
|
||||
|
||||
// 是否进行通道加密
|
||||
if (!proxyConfig.getTunnel().getSm2EncryptEnable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 默认设置为非安全链路,需要服务端确认后,再设置为安全链路
|
||||
Attribute<Boolean> booleanAttribute = context.attr(Constants.IS_SECURITY);
|
||||
booleanAttribute.set(false);
|
||||
|
||||
+10
@@ -3,6 +3,7 @@ package org.dromara.neutrinoproxy.client.handler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.util.Attribute;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.neutrinoproxy.client.config.ProxyConfig;
|
||||
import org.dromara.neutrinoproxy.client.util.ProxyUtil;
|
||||
import org.dromara.neutrinoproxy.core.Constants;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessage;
|
||||
@@ -10,14 +11,23 @@ import org.dromara.neutrinoproxy.core.ProxyMessageHandler;
|
||||
import org.dromara.neutrinoproxy.core.dispatcher.Match;
|
||||
import org.dromara.neutrinoproxy.core.util.EncryptUtil;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
|
||||
@Slf4j
|
||||
@Match(type = Constants.ProxyDataTypeName.SECURE_KEY)
|
||||
@Component
|
||||
public class ProxyMessageSecureKeyHandler implements ProxyMessageHandler {
|
||||
|
||||
@Inject
|
||||
private ProxyConfig proxyConfig;
|
||||
@Override
|
||||
public void handle(ChannelHandlerContext ctx, ProxyMessage proxyMessage) {
|
||||
if (!proxyConfig.getTunnel().getSm2EncryptEnable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("收到服务端的加密确认");
|
||||
|
||||
Attribute<byte[]> secureKeyAttr = ctx.attr(Constants.SECURE_KEY);
|
||||
byte[] secureKey = secureKeyAttr.get();
|
||||
byte[] data = proxyMessage.getData();
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ public class ProxyUtil {
|
||||
private static String clientId;
|
||||
private static final String CLIENT_ID_FILE = ".NEUTRINO_PROXY_CLIENT_ID";
|
||||
|
||||
private static byte[] secureKey;
|
||||
private static byte[] secureKey = null;
|
||||
|
||||
public static void borrowTcpProxyChanel(Bootstrap tcpProxyTunnelBootstrap, final ProxyChannelBorrowListener borrowListener) {
|
||||
Channel channel = tcpProxyChannelPool.poll();
|
||||
|
||||
@@ -34,15 +34,16 @@ neutrino:
|
||||
tunnel:
|
||||
# 线程池相关配置,用于技术调优,可忽略
|
||||
thread-count: 50
|
||||
sm2-encrypt-enable: ${SM2_ENCRYPT_ENABLE:false}
|
||||
# 隧道SSL证书配置
|
||||
key-store-password: ${STORE_PASS:123456}
|
||||
jks-path: ${JKS_PATH:classpath:/test.jks}
|
||||
# 服务端IP
|
||||
server-ip: ${SERVER_IP:localhost}
|
||||
# 服务端端口(对应服务端app.yml中的tunnel.port、tunnel.ssl-port)
|
||||
server-port: ${SERVER_PORT:9000}
|
||||
server-port: ${SERVER_PORT:9002}
|
||||
# 是否启用SSL(注意:该配置必须和server-port对应上)
|
||||
ssl-enable: ${SSL_ENABLE:false}
|
||||
ssl-enable: ${SSL_ENABLE:true}
|
||||
# 客户端连接唯一凭证
|
||||
license-key: ${LICENSE_KEY:b0a907332b474b25897c4dcb31fc7eb6}
|
||||
# 客户端唯一身份标识(可忽略,若不设置首次启动会自动生成)
|
||||
|
||||
-2
@@ -77,8 +77,6 @@ public class ProxyMessageAuthHandler implements ProxyMessageHandler {
|
||||
|
||||
@Override
|
||||
public void handle(ChannelHandlerContext ctx, ProxyMessage proxyMessage) {
|
||||
log.info("收到客户端的认证连接信息");
|
||||
|
||||
String ip = ((InetSocketAddress)ctx.channel().remoteAddress()).getAddress().getHostAddress();
|
||||
Date now = new Date();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user