feat: 实现 shadowTls v2;修订示例,文档,代码; 添加shadowTls的示例文件

shadowTls v2时客户端自动使用utls,且增强了探测防御

proxy.SetCommonReadTimeout -> netLayer.SetCommonReadTimeout

tlsLayer 配置也使用Extra,目前用于 shadowTls
This commit is contained in:
e1732a364fed
2000-01-01 00:00:00 +00:00
parent 99f875de06
commit 3c754a0a89
26 changed files with 540 additions and 105 deletions

View File

@@ -1,6 +1,73 @@
package utils
import "runtime"
import (
"crypto/hmac"
"crypto/sha1"
"hash"
"io"
"runtime"
)
//有些系统对aes支持不好有些支持好。SystemAutoUseAes若为true则说明支持很好使用aes作为加密算法速度最佳。
// 有些系统对aes支持不好有些支持好。SystemAutoUseAes若为true则说明支持很好使用aes作为加密算法速度最佳。
const SystemAutoUseAes = runtime.GOARCH == "amd64" || runtime.GOARCH == "s390x" || runtime.GOARCH == "arm64"
type HashReader struct {
io.Reader
hmac hash.Hash
}
func NewHashReader(conn io.Reader, key []byte) *HashReader {
return &HashReader{
conn,
hmac.New(sha1.New, key),
}
}
func (c *HashReader) Read(b []byte) (n int, err error) {
n, err = c.Reader.Read(b)
if err != nil {
return
}
_, err = c.hmac.Write(b[:n])
return
}
func (c *HashReader) Sum() []byte {
return c.hmac.Sum(nil)[:8]
}
type HashWriter struct {
io.Writer
hmac hash.Hash
written bool
}
func NewHashWriter(conn io.Writer, key []byte) *HashWriter {
return &HashWriter{
Writer: conn,
hmac: hmac.New(sha1.New, key),
}
}
func (c *HashWriter) Write(p []byte) (n int, err error) {
if c.hmac != nil {
c.hmac.Write(p)
c.written = true
}
return c.Writer.Write(p)
}
func (c *HashWriter) Sum() []byte {
return c.hmac.Sum(nil)[:8]
}
func (c *HashWriter) StopHashing() {
c.hmac = nil
c.written = false
}
// Has the hash been written
func (c *HashWriter) Written() bool {
return c.written
}