コード例 #1
0
        public override PipeFilterResult AfterReading(PipeFilterContext filterContext)
        {
            PipeFilterResult r = new PipeFilterResult(this.Client, null, false);

            if (null != _aead)
            {
                if (!filterContext.Memory.IsEmpty)
                {
                    var cipher = _aead.DecryptTcp(filterContext.Memory.Slice(0, filterContext.MemoryLength));
                    if (null != cipher && cipher.SignificantLength > 0)
                    {
                        r = new PipeFilterResult(this.Client, cipher, true);
                    }
                    else
                    {
                        _logger?.LogError($"AeadCipherTcpFilter AfterReading no cipher data.");
                    }
                }
                else
                {
                    _logger?.LogError($"AeadCipherTcpFilter AfterReading filterContext.Memory.IsEmpty");
                }
            }
            return(r);
        }
コード例 #2
0
        public override PipeFilterResult BeforeWriting(PipeFilterContext ctx)
        {
            if (!ctx.Memory.IsEmpty)
            {
                var bufferCipher = _cipher.EncryptUdp(ctx.Memory);
                return(new PipeFilterResult(this.Client, bufferCipher, true));
            }
            else
            {
                _logger?.LogError($"CipherUdpFilter BeforeWriting filterContext.Memory.IsEmpty");
            }

            return(new PipeFilterResult(this.Client, null, false));
        }
コード例 #3
0
        public override PipeFilterResult BeforeWriting(PipeFilterContext ctx)
        {
            SmartBuffer toTarget = SmartBuffer.Rent(ctx.Memory.Length);

            if (ShadowsocksAddress.TryResolveLength(ctx.Memory, out int targetAddrLen))
            {
                ctx.Memory.Slice(targetAddrLen).CopyTo(toTarget.Memory);
                toTarget.SignificantLength = ctx.Memory.Length - targetAddrLen;
                return(new PipeFilterResult(ctx.Client, toTarget, true));
            }
            else
            {
                return(new PipeFilterResult(ctx.Client, toTarget, false));
            }
        }
コード例 #4
0
        public override PipeFilterResult BeforeWriting(PipeFilterContext ctx)
        {
            if (!ctx.Memory.IsEmpty)
            {
                SmartBuffer toRemote = SmartBuffer.Rent(1500);
                ctx.Memory.Slice(3).CopyTo(toRemote.Memory);
                toRemote.SignificantLength = ctx.Memory.Length - 3;
                return(new PipeFilterResult(ctx.Client, toRemote, true));
            }
            else
            {
                _logger?.LogError($"LocalUdpRelayPackingFilter BeforeWriting filterContext.Memory.IsEmpty");
            }

            return(new PipeFilterResult(this.Client, null, false));
        }
コード例 #5
0
        public override PipeFilterResult AfterReading(PipeFilterContext ctx)
        {
            SmartBuffer bufferPlain = null;

            if (null != _cipher)
            {
                if (!ctx.Memory.IsEmpty)//TODO 1
                {
                    bufferPlain = _cipher.DecryptTcp(ctx.Memory);
                }
                else
                {
                    _logger?.LogError($"AeadCipherTcpFilter AfterReading filterContext.Memory.IsEmpty");
                }
            }
            return(new PipeFilterResult(this.Client, bufferPlain, true));//TODO 2
        }
コード例 #6
0
        public override PipeFilterResult AfterReading(PipeFilterContext ctx)
        {
            if (!ctx.Memory.IsEmpty)
            {
                SmartBuffer toApplication = SmartBuffer.Rent(1500);
                ctx.Memory.CopyTo(toApplication.Memory.Slice(2 + 1));
                var p = toApplication.Memory.Span;
                p.Slice(0, 3).Fill(0x0);
                toApplication.SignificantLength = ctx.Memory.Length + 2 + 1;
                return(new PipeFilterResult(ctx.Client, toApplication, true));
            }
            else
            {
                _logger?.LogError($"LocalUdpRelayPackingFilter AfterReading filterContext.Memory.IsEmpty");
            }

            return(new PipeFilterResult(this.Client, null, false));
        }
コード例 #7
0
        public override PipeFilterResult BeforeWriting(PipeFilterContext filterContext)
        {
            PipeFilterResult r = new PipeFilterResult(this.Client, null, false);

            if (null != _aead)
            {
                if (!filterContext.Memory.IsEmpty)
                {
                    var cipher = _aead.EncryptTcp(filterContext.Memory.Slice(0, filterContext.MemoryLength));
                    r = new PipeFilterResult(this.Client, cipher, true);
                }
                else
                {
                    _logger?.LogError($"AeadCipherTcpFilter BeforeWriting filterContext.Memory.IsEmpty");
                }
            }
            return(r);
        }
コード例 #8
0
        public override PipeFilterResult BeforeWriting(PipeFilterContext ctx)
        {
            PipeFilterResult r = new PipeFilterResult(this.Client, null, false);

            if (null != _cipher)
            {
                if (!ctx.Memory.IsEmpty)
                {
                    var bufferCipher = _cipher.EncryptTcp(ctx.Memory);
                    r = new PipeFilterResult(this.Client, bufferCipher, true);
                }
                else
                {
                    _logger?.LogError($"AeadCipherTcpFilter BeforeWriting filterContext.Memory.IsEmpty");
                }
            }
            return(r);
        }
コード例 #9
0
        public override PipeFilterResult AfterReading(PipeFilterContext ctx)
        {
            if (!ctx.Memory.IsEmpty)
            {
                var bufferPlain = _cipher.DecryptUdp(ctx.Memory);
                if (null != bufferPlain && bufferPlain.SignificantLength > 0)
                {
                    return(new PipeFilterResult(this.Client, bufferPlain, true));
                }
                else
                {
                    _logger?.LogError($"CipherUdpFilter AfterReading no plain data.");
                }
            }
            else
            {
                _logger?.LogError($"CipherUdpFilter AfterReading filterContext.Memory.IsEmpty");
            }

            return(new PipeFilterResult(this.Client, null, false));
        }
コード例 #10
0
        public override PipeFilterResult AfterReading(PipeFilterContext ctx)
        {
            SmartBuffer toSsLocal = SmartBuffer.Rent(1500);//TODO what if exceeds 1500? fragments or not?

            if (ShadowsocksAddress.TrySerailizeTo(
                    (byte)(AddressFamily.InterNetworkV6 == ctx.Client.EndPoint.AddressFamily ? 0x4 : 0x1),
                    ctx.Client.EndPoint.Address.GetAddressBytes(),
                    (ushort)ctx.Client.EndPoint.Port,
                    toSsLocal.Memory,
                    out int written))
            {
                toSsLocal.SignificantLength = written;
                int payloadToCopy = Math.Min(toSsLocal.FreeSpace, ctx.Memory.Length);
                ctx.Memory.Slice(0, payloadToCopy).CopyTo(toSsLocal.FreeMemory);
                toSsLocal.SignificantLength += payloadToCopy;

                return(new PipeFilterResult(ctx.Client, toSsLocal, true));;
            }

            return(new PipeFilterResult(ctx.Client, null, false));;
        }
コード例 #11
0
 public override PipeFilterResult BeforeWriting(PipeFilterContext filterContext)
 {
     throw new NotImplementedException();
 }
コード例 #12
0
 public override PipeFilterResult AfterReading(PipeFilterContext filterContext)
 {
     throw new NotImplementedException();
 }