Fix shadowtls server detection

This commit is contained in:
世界
2022-11-22 22:11:09 +08:00
parent ffd54eef6c
commit a401828ed5
2 changed files with 30 additions and 8 deletions

View File

@@ -34,19 +34,25 @@ func (c *HashReadConn) Sum() []byte {
type HashWriteConn struct {
net.Conn
hmac hash.Hash
hmac hash.Hash
hasContent bool
lastSum []byte
}
func NewHashWriteConn(conn net.Conn, password string) *HashWriteConn {
return &HashWriteConn{
conn,
hmac.New(sha1.New, []byte(password)),
Conn: conn,
hmac: hmac.New(sha1.New, []byte(password)),
}
}
func (c *HashWriteConn) Write(p []byte) (n int, err error) {
if c.hmac != nil {
if c.hasContent {
c.lastSum = c.Sum()
}
c.hmac.Write(p)
c.hasContent = true
}
return c.Conn.Write(p)
}
@@ -55,6 +61,14 @@ func (c *HashWriteConn) Sum() []byte {
return c.hmac.Sum(nil)[:8]
}
func (c *HashWriteConn) LastSum() []byte {
return c.lastSum
}
func (c *HashWriteConn) Fallback() {
c.hmac = nil
}
func (c *HashWriteConn) HasContent() bool {
return c.hasContent
}