|
|
@@ -30,12 +30,16 @@ import (
|
|
|
"github.com/xtls/xray-core/common/net"
|
|
|
"github.com/xtls/xray-core/core"
|
|
|
"github.com/xtls/xray-core/transport/internet/tls"
|
|
|
+ "golang.org/x/crypto/chacha20poly1305"
|
|
|
"golang.org/x/crypto/hkdf"
|
|
|
"golang.org/x/net/http2"
|
|
|
)
|
|
|
|
|
|
//go:generate go run github.com/xtls/xray-core/common/errors/errorgen
|
|
|
|
|
|
+//go:linkname aesgcmPreferred github.com/refraction-networking/utls.aesgcmPreferred
|
|
|
+func aesgcmPreferred(ciphers []uint16) bool
|
|
|
+
|
|
|
type Conn struct {
|
|
|
*reality.Conn
|
|
|
}
|
|
|
@@ -136,11 +140,16 @@ func UClient(c net.Conn, config *Config, ctx context.Context, dest net.Destinati
|
|
|
if _, err := hkdf.New(sha256.New, uConn.AuthKey, hello.Random[:20], []byte("REALITY")).Read(uConn.AuthKey); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
+ var aead cipher.AEAD
|
|
|
+ if aesgcmPreferred(hello.CipherSuites) {
|
|
|
+ block, _ := aes.NewCipher(uConn.AuthKey)
|
|
|
+ aead, _ = cipher.NewGCM(block)
|
|
|
+ } else {
|
|
|
+ aead, _ = chacha20poly1305.New(uConn.AuthKey)
|
|
|
+ }
|
|
|
if config.Show {
|
|
|
- fmt.Printf("REALITY localAddr: %v\tuConn.AuthKey[:16]: %v\n", localAddr, uConn.AuthKey[:16])
|
|
|
+ fmt.Printf("REALITY localAddr: %v\tuConn.AuthKey[:16]: %v\tAEAD: %T\n", localAddr, uConn.AuthKey[:16], aead)
|
|
|
}
|
|
|
- block, _ := aes.NewCipher(uConn.AuthKey)
|
|
|
- aead, _ := cipher.NewGCM(block)
|
|
|
aead.Seal(hello.SessionId[:0], hello.Random[20:], hello.SessionId[:16], hello.Raw)
|
|
|
copy(hello.Raw[39:], hello.SessionId)
|
|
|
}
|