1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-02-20 23:47:21 -05:00

Feat: use different qtls modules for different Go version

This commit is contained in:
秋のかえで 2022-04-05 14:17:19 +08:00
parent 56371d87ef
commit e0df70b16d
5 changed files with 62 additions and 6 deletions

View File

@ -0,0 +1,19 @@
//go:build go1.16 && !go1.17
// +build go1.16,!go1.17
package quic
import (
"crypto/cipher"
"github.com/marten-seemann/qtls-go1-16"
)
type (
// A CipherSuiteTLS13 is a cipher suite for TLS 1.3
CipherSuiteTLS13 = qtls.CipherSuiteTLS13
)
func AEADAESGCMTLS13(key, fixedNonce []byte) cipher.AEAD {
return qtls.AEADAESGCMTLS13(key, fixedNonce)
}

View File

@ -0,0 +1,19 @@
//go:build go1.17 && !go1.18
// +build go1.17,!go1.18
package quic
import (
"crypto/cipher"
"github.com/marten-seemann/qtls-go1-17"
)
type (
// A CipherSuiteTLS13 is a cipher suite for TLS 1.3
CipherSuiteTLS13 = qtls.CipherSuiteTLS13
)
func AEADAESGCMTLS13(key, fixedNonce []byte) cipher.AEAD {
return qtls.AEADAESGCMTLS13(key, fixedNonce)
}

View File

@ -0,0 +1,19 @@
//go:build go1.18
// +build go1.18
package quic
import (
"crypto/cipher"
"github.com/marten-seemann/qtls-go1-18"
)
type (
// A CipherSuiteTLS13 is a cipher suite for TLS 1.3
CipherSuiteTLS13 = qtls.CipherSuiteTLS13
)
func AEADAESGCMTLS13(key, fixedNonce []byte) cipher.AEAD {
return qtls.AEADAESGCMTLS13(key, fixedNonce)
}

View File

@ -8,7 +8,6 @@ import (
"io"
"github.com/lucas-clemente/quic-go/quicvarint"
"github.com/marten-seemann/qtls-go1-17"
"golang.org/x/crypto/hkdf"
"github.com/v2fly/v2ray-core/v5/common"
@ -37,10 +36,10 @@ const (
var (
quicSaltOld = []byte{0xaf, 0xbf, 0xec, 0x28, 0x99, 0x93, 0xd2, 0x4c, 0x9e, 0x97, 0x86, 0xf1, 0x9c, 0x61, 0x11, 0xe0, 0x43, 0x90, 0xa8, 0x99}
quicSalt = []byte{0x38, 0x76, 0x2c, 0xf7, 0xf5, 0x59, 0x34, 0xb3, 0x4d, 0x17, 0x9a, 0xe6, 0xa4, 0xc8, 0x0c, 0xad, 0xcc, 0xbb, 0x7f, 0x0a}
initialSuite = &qtls.CipherSuiteTLS13{
initialSuite = &CipherSuiteTLS13{
ID: tls.TLS_AES_128_GCM_SHA256,
KeyLen: 16,
AEAD: qtls.AEADAESGCMTLS13,
AEAD: AEADAESGCMTLS13,
Hash: crypto.SHA256,
}
errNotQuic = errors.New("not quic")
@ -153,7 +152,7 @@ func SniffQUIC(b []byte) (*SniffHeader, error) {
key := hkdfExpandLabel(crypto.SHA256, secret, []byte{}, "quic key", 16)
iv := hkdfExpandLabel(crypto.SHA256, secret, []byte{}, "quic iv", 12)
cipher := qtls.AEADAESGCMTLS13(key, iv)
cipher := AEADAESGCMTLS13(key, iv)
nonce := cache.Extend(int32(cipher.NonceSize()))
binary.BigEndian.PutUint64(nonce[len(nonce)-8:], uint64(packetNumber))
decrypted, err := cipher.Open(b[extHdrLen:extHdrLen], nonce, data, b[:extHdrLen])

4
go.mod
View File

@ -13,7 +13,9 @@ require (
github.com/gorilla/websocket v1.5.0
github.com/jhump/protoreflect v1.12.0
github.com/lucas-clemente/quic-go v0.26.0
github.com/marten-seemann/qtls-go1-16 v0.1.5
github.com/marten-seemann/qtls-go1-17 v0.1.1
github.com/marten-seemann/qtls-go1-18 v0.1.1
github.com/miekg/dns v1.1.48
github.com/pelletier/go-toml v1.9.4
github.com/pires/go-proxyproto v0.6.2
@ -45,8 +47,6 @@ require (
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/lunixbochs/struc v0.0.0-20200707160740-784aaebc1d40 // indirect
github.com/marten-seemann/qtls-go1-16 v0.1.5 // indirect
github.com/marten-seemann/qtls-go1-18 v0.1.1 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/onsi/ginkgo v1.16.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect