添加输出信息
This commit is contained in:
+1
@@ -16,6 +16,7 @@ import org.noear.solon.annotation.Component;
|
||||
public class ProxyMessageSecureKeyHandler implements ProxyMessageHandler {
|
||||
@Override
|
||||
public void handle(ChannelHandlerContext ctx, ProxyMessage proxyMessage) {
|
||||
log.info("收到服务端的加密确认");
|
||||
Attribute<byte[]> secureKeyAttr = ctx.attr(Constants.SECURE_KEY);
|
||||
byte[] secureKey = secureKeyAttr.get();
|
||||
byte[] data = proxyMessage.getData();
|
||||
|
||||
@@ -23,7 +23,7 @@ neutrino:
|
||||
|
||||
proxy:
|
||||
protocol:
|
||||
max-frame-length: 104857600
|
||||
max-frame-length: 1048576000
|
||||
length-field-offset: 0
|
||||
length-field-length: 4
|
||||
initial-bytes-to-strip: 0
|
||||
@@ -42,7 +42,7 @@ neutrino:
|
||||
# 服务端端口(对应服务端app.yml中的tunnel.port、tunnel.ssl-port)
|
||||
server-port: ${SERVER_PORT:9000}
|
||||
# 是否启用SSL(注意:该配置必须和server-port对应上)
|
||||
ssl-enable: ${SSL_ENABLE:true}
|
||||
ssl-enable: ${SSL_ENABLE:false}
|
||||
# 客户端连接唯一凭证
|
||||
license-key: ${LICENSE_KEY:b0a907332b474b25897c4dcb31fc7eb6}
|
||||
# 客户端唯一身份标识(可忽略,若不设置首次启动会自动生成)
|
||||
|
||||
@@ -64,7 +64,6 @@ public interface Constants {
|
||||
interface ProxyDataTypeName {
|
||||
String HEARTBEAT = "HEARTBEAT";
|
||||
String SECURE_KEY = "SECURE_KEY";
|
||||
String IS_SECURITY = "IS_SECURITY";
|
||||
String AUTH = "AUTH";
|
||||
String CONNECT = "CONNECT";
|
||||
String DISCONNECT = "DISCONNECT";
|
||||
|
||||
+5
-1
@@ -27,10 +27,12 @@ import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
|
||||
import io.netty.util.Attribute;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.neutrinoproxy.core.util.SmEncryptUtil;
|
||||
|
||||
import static org.dromara.neutrinoproxy.core.Constants.*;
|
||||
|
||||
@Slf4j
|
||||
/**
|
||||
*
|
||||
* @author: aoshiguchen
|
||||
@@ -80,7 +82,8 @@ public class ProxyMessageDecoder extends LengthFieldBasedFrameDecoder {
|
||||
ByteBuf buf;
|
||||
|
||||
// 考虑isSecurity为null的情况,null的情况也为false
|
||||
if (isSecurity == true) {
|
||||
if (isSecurity != null && isSecurity) {
|
||||
log.info("执行解密逻辑");
|
||||
int packageLength = in.readInt();
|
||||
if (in.readableBytes() < packageLength) {
|
||||
return null;
|
||||
@@ -100,6 +103,7 @@ public class ProxyMessageDecoder extends LengthFieldBasedFrameDecoder {
|
||||
buf = Unpooled.wrappedBuffer(decryptedData);
|
||||
} else {
|
||||
buf = in;
|
||||
log.info("链路不加密解码");
|
||||
}
|
||||
|
||||
ProxyMessage proxyMessage = new ProxyMessage();
|
||||
|
||||
+6
-2
@@ -27,6 +27,7 @@ import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToByteEncoder;
|
||||
import io.netty.util.Attribute;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.neutrinoproxy.core.util.SmEncryptUtil;
|
||||
|
||||
import static org.dromara.neutrinoproxy.core.Constants.*;
|
||||
@@ -36,6 +37,7 @@ import static org.dromara.neutrinoproxy.core.Constants.*;
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/16
|
||||
*/
|
||||
@Slf4j
|
||||
public class ProxyMessageEncoder extends MessageToByteEncoder<ProxyMessage> {
|
||||
|
||||
public ProxyMessageEncoder() {
|
||||
@@ -62,9 +64,11 @@ public class ProxyMessageEncoder extends MessageToByteEncoder<ProxyMessage> {
|
||||
ByteBuf buf;
|
||||
|
||||
// 考虑isSecurity为null的情况,null的情况也为false
|
||||
if (isSecurity == true) {
|
||||
if (isSecurity != null && isSecurity) {
|
||||
log.info("执行加密逻辑");
|
||||
buf = Unpooled.buffer(bodyLength);
|
||||
} else {
|
||||
log.info("不执行加密的链路编码");
|
||||
buf = out;
|
||||
}
|
||||
|
||||
@@ -86,7 +90,7 @@ public class ProxyMessageEncoder extends MessageToByteEncoder<ProxyMessage> {
|
||||
}
|
||||
|
||||
// 考虑isSecurity为null的情况,null的情况也为false
|
||||
if (isSecurity == true) {
|
||||
if (isSecurity != null && isSecurity) {
|
||||
// 执行加密
|
||||
byte[] data = new byte[bodyLength];
|
||||
buf.readBytes(data);
|
||||
|
||||
+5
-3
@@ -77,6 +77,8 @@ 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();
|
||||
|
||||
@@ -105,7 +107,7 @@ public class ProxyMessageAuthHandler implements ProxyMessageHandler {
|
||||
}
|
||||
LicenseDO licenseDO = licenseService.findByKey(licenseKey);
|
||||
if (null == licenseDO) {
|
||||
log.warn("[client connection] license notfound info:{} ", info);
|
||||
log.warn("[client connection] license not found info:{} ", info);
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildAuthResultMessage(ExceptionEnum.AUTH_FAILED.getCode(), "license不存在!", licenseKey, null));
|
||||
ctx.channel().close();
|
||||
clientConnectRecordService.add(new ClientConnectRecordDO()
|
||||
@@ -113,7 +115,7 @@ public class ProxyMessageAuthHandler implements ProxyMessageHandler {
|
||||
.setType(ClientConnectTypeEnum.CONNECT.getType())
|
||||
.setMsg(licenseKey)
|
||||
.setCode(SuccessCodeEnum.FAIL.getCode())
|
||||
.setErr("license notfound!")
|
||||
.setErr("license not found!")
|
||||
.setCreateTime(now)
|
||||
);
|
||||
return;
|
||||
@@ -175,7 +177,7 @@ public class ProxyMessageAuthHandler implements ProxyMessageHandler {
|
||||
|
||||
// 私钥存入ctx
|
||||
Attribute<String> attr = ctx.attr(Constants.SECURE_PRIVATE_KEY);
|
||||
attr.setIfAbsent(record.privateKey());
|
||||
attr.set(record.privateKey());
|
||||
|
||||
// 发送认证成功消息
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildAuthResultMessage(ExceptionEnum.SUCCESS.getCode(), "auth success!", licenseKey, record.publicKey()));
|
||||
|
||||
+2
@@ -21,6 +21,8 @@ public class ProxyMessageSecureKeyHandler implements ProxyMessageHandler {
|
||||
@Override
|
||||
public void handle(ChannelHandlerContext ctx, ProxyMessage proxyMessage) {
|
||||
|
||||
log.info("收到客户端的加密信息");
|
||||
|
||||
// data为加密后的密码,info为加密密码的摘要
|
||||
byte[] data = proxyMessage.getData();
|
||||
String receivedDigest = proxyMessage.getInfo();
|
||||
|
||||
Reference in New Issue
Block a user