diff --git a/src/main/java/cn/wowspeeder/encryption/CryptBase.java b/src/main/java/cn/wowspeeder/encryption/CryptBase.java index 42fe77c..827317b 100644 --- a/src/main/java/cn/wowspeeder/encryption/CryptBase.java +++ b/src/main/java/cn/wowspeeder/encryption/CryptBase.java @@ -45,9 +45,9 @@ protected void setIV(byte[] iv, boolean isEncrypt) { } if (isEncrypt) { - _encryptIV = new byte[_ivLength]; - System.arraycopy(iv, 0, _encryptIV, 0, _ivLength); try { + _encryptIV = new byte[_ivLength]; + System.arraycopy(iv, 0, _encryptIV, 0, _ivLength); encCipher = getCipher(isEncrypt); ParametersWithIV parameterIV = new ParametersWithIV( new KeyParameter(_key.getEncoded()), _encryptIV); @@ -56,9 +56,9 @@ protected void setIV(byte[] iv, boolean isEncrypt) { logger.info(e.toString()); } } else { - _decryptIV = new byte[_ivLength]; - System.arraycopy(iv, 0, _decryptIV, 0, _ivLength); try { + _decryptIV = new byte[_ivLength]; + System.arraycopy(iv, 0, _decryptIV, 0, _ivLength); decCipher = getCipher(isEncrypt); ParametersWithIV parameterIV = new ParametersWithIV( new KeyParameter(_key.getEncoded()), _decryptIV); diff --git a/src/main/java/cn/wowspeeder/ss/SSCipherDecoder.java b/src/main/java/cn/wowspeeder/ss/SSCipherDecoder.java index f75cf89..2bf9e14 100644 --- a/src/main/java/cn/wowspeeder/ss/SSCipherDecoder.java +++ b/src/main/java/cn/wowspeeder/ss/SSCipherDecoder.java @@ -19,7 +19,9 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List list) ICrypt _crypt = ctx.channel().attr(SSCommon.CIPHER).get(); byte[] data = CryptUtil.decrypt(_crypt, msg); if (data == null) { - ctx.close(); + if (!ctx.channel().attr(SSCommon.IS_UDP).get()) { + ctx.close(); + } return; } list.add(msg.retain().clear().writeBytes(data));// diff --git a/src/main/java/cn/wowspeeder/ss/SSProtocolDecoder.java b/src/main/java/cn/wowspeeder/ss/SSProtocolDecoder.java index ff7b13e..614134f 100644 --- a/src/main/java/cn/wowspeeder/ss/SSProtocolDecoder.java +++ b/src/main/java/cn/wowspeeder/ss/SSProtocolDecoder.java @@ -41,7 +41,9 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List out) SSAddrRequest addrRequest = SSAddrRequest.getAddrRequest(msg); if (addrRequest == null) { logger.error("failed to get address request from {}", ctx.channel().attr(SSCommon.CLIENT).get().getHostString()); - ctx.close(); + if (!ctx.channel().attr(SSCommon.IS_UDP).get()) { + ctx.close(); + } return; } logger.debug(ctx.channel().id().toString() + " addressType = " + addrRequest.addressType() + ",host = " + addrRequest.host() + ",port = " + addrRequest.port() + ",dataBuff = " diff --git a/src/main/java/cn/wowspeeder/ss/SSTcpProxyHandler.java b/src/main/java/cn/wowspeeder/ss/SSTcpProxyHandler.java index e4b8023..9a0b920 100644 --- a/src/main/java/cn/wowspeeder/ss/SSTcpProxyHandler.java +++ b/src/main/java/cn/wowspeeder/ss/SSTcpProxyHandler.java @@ -97,8 +97,8 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E proxyClient .connect(clientRecipient) .addListener((ChannelFutureListener) future -> { - if (future.isSuccess()) { - try { + try { + if (future.isSuccess()) { logger.debug("channel id {}, {}<->{}<->{} connect {}", clientCtx.channel().id().toString(), clientCtx.channel().remoteAddress().toString(), future.channel().localAddress().toString(), clientRecipient.toString(), future.isSuccess()); remoteChannel = future.channel(); if (clientBuffs != null) { @@ -108,11 +108,11 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E } clientBuffs = null; } - } catch (Exception e) { + } else { + logger.error("channel id {}, {}<->{} connect {},cause {}", clientCtx.channel().id().toString(), clientCtx.channel().remoteAddress().toString(), clientRecipient.toString(), future.isSuccess(), future.cause()); proxyChannelClose(); } - } else { - logger.error("channel id {}, {}<->{} connect {},cause {}", clientCtx.channel().id().toString(), clientCtx.channel().remoteAddress().toString(), clientRecipient.toString(), future.isSuccess(), future.cause()); + } catch (Exception e) { proxyChannelClose(); } }); @@ -169,7 +169,7 @@ private void proxyChannelClose() { clientChannel = null; } } catch (Exception e) { - logger.error("close channel error", e); +// logger.error("close channel error", e); } } }