mirror of
https://github.com/daeuniverse/dae.git
synced 2025-07-06 00:09:37 +07:00
fix(tls sniff): may be multiple types SNI in an extension
This commit is contained in:
@ -9,6 +9,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"github.com/v2rayA/dae/component/sniffing/internal/quicutils"
|
"github.com/v2rayA/dae/component/sniffing/internal/quicutils"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -114,22 +115,27 @@ func findSniExtension(search quicutils.Locator) (string, error) {
|
|||||||
return "", NotApplicableError
|
return "", NotApplicableError
|
||||||
}
|
}
|
||||||
if typ == TlsExtension_ServerName {
|
if typ == TlsExtension_ServerName {
|
||||||
b = search.Range(i+4, i+9)
|
b = search.Range(i+4, i+6)
|
||||||
sniLen := int(binary.BigEndian.Uint16(b))
|
sniLen := int(binary.BigEndian.Uint16(b))
|
||||||
if extLength != sniLen+2 {
|
if extLength < sniLen+2 {
|
||||||
return "", NotApplicableError
|
return "", NotApplicableError
|
||||||
}
|
}
|
||||||
// There may be multiple server names, we only pick the first.
|
// Search HostName type SNI.
|
||||||
if b[2] != TlsExtension_ServerNameType_HostName {
|
for j, indicatorLen := i+6, 0; j+3 <= iNextField; j += indicatorLen {
|
||||||
|
b = search.Range(j, j+3)
|
||||||
|
indicatorLen = int(binary.BigEndian.Uint16(b[1:]))
|
||||||
|
if b[0] != TlsExtension_ServerNameType_HostName {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if j+3+indicatorLen > iNextField {
|
||||||
return "", NotApplicableError
|
return "", NotApplicableError
|
||||||
}
|
}
|
||||||
snLen := int(binary.BigEndian.Uint16(b[3:]))
|
b = search.Range(j+3, j+3+indicatorLen)
|
||||||
if i+9+snLen > iNextField {
|
// An SNI value may not include a trailing dot.
|
||||||
return "", NotApplicableError
|
// https://tools.ietf.org/html/rfc6066#section-3
|
||||||
|
// But we accept it here.
|
||||||
|
return strings.TrimSuffix(string(b), "."), nil
|
||||||
}
|
}
|
||||||
b = search.Range(i+9, i+9+snLen)
|
|
||||||
sni := string(b)
|
|
||||||
return sni, nil
|
|
||||||
}
|
}
|
||||||
i = iNextField
|
i = iNextField
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user