small-package/v2ray-core/patches/0002-Feat-use-different-qtl...

153 lines
4.8 KiB
Diff

From 691abd3fdd0ec526dac81fcea81723f74f6cef46 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=A7=8B=E3=81=AE=E3=81=8B=E3=81=88=E3=81=A7?=
<autmaple@protonmail.com>
Date: Tue, 5 Apr 2022 14:17:19 +0800
Subject: [PATCH 2/2] Feat: use different qtls modules for different Go version
---
common/protocol/quic/qtls_go116.go | 19 +++++++++++++++++++
common/protocol/quic/qtls_go117.go | 19 +++++++++++++++++++
common/protocol/quic/qtls_go118.go | 19 +++++++++++++++++++
common/protocol/quic/sniff.go | 7 +++----
go.mod | 4 ++--
5 files changed, 62 insertions(+), 6 deletions(-)
create mode 100644 common/protocol/quic/qtls_go116.go
create mode 100644 common/protocol/quic/qtls_go117.go
create mode 100644 common/protocol/quic/qtls_go118.go
diff --git a/common/protocol/quic/qtls_go116.go b/common/protocol/quic/qtls_go116.go
new file mode 100644
index 00000000..da849ea3
--- /dev/null
+++ b/common/protocol/quic/qtls_go116.go
@@ -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)
+}
diff --git a/common/protocol/quic/qtls_go117.go b/common/protocol/quic/qtls_go117.go
new file mode 100644
index 00000000..08e8d483
--- /dev/null
+++ b/common/protocol/quic/qtls_go117.go
@@ -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)
+}
diff --git a/common/protocol/quic/qtls_go118.go b/common/protocol/quic/qtls_go118.go
new file mode 100644
index 00000000..0bcacff2
--- /dev/null
+++ b/common/protocol/quic/qtls_go118.go
@@ -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)
+}
diff --git a/common/protocol/quic/sniff.go b/common/protocol/quic/sniff.go
index 0a78050b..d0421309 100644
--- a/common/protocol/quic/sniff.go
+++ b/common/protocol/quic/sniff.go
@@ -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])
diff --git a/go.mod b/go.mod
index 87752bac..46a525bd 100644
--- a/go.mod
+++ b/go.mod
@@ -12,7 +12,9 @@ require (
github.com/gorilla/websocket v1.4.2
github.com/jhump/protoreflect v1.10.1
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.45
github.com/pelletier/go-toml v1.9.4
github.com/pires/go-proxyproto v0.6.1
@@ -44,8 +46,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
--
2.35.1