Skip to content

Commit 1ae050c

Browse files
committed
chore: sync vless encryption code
1 parent 7f38763 commit 1ae050c

File tree

12 files changed

+614
-748
lines changed

12 files changed

+614
-748
lines changed

component/generator/cmd.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,24 @@ func Main(args []string) {
5050
if len(args) > 1 {
5151
seed = args[1]
5252
}
53-
seedBase64, clientBase64, hash11Base64, err := encryption.GenMLKEM768(seed)
53+
seedBase64, clientBase64, hash32Base64, err := encryption.GenMLKEM768(seed)
5454
if err != nil {
5555
panic(err)
5656
}
5757
fmt.Println("Seed: " + seedBase64)
5858
fmt.Println("Client: " + clientBase64)
59-
fmt.Println("Hash11: " + hash11Base64)
59+
fmt.Println("Hash32: " + hash32Base64)
6060
case "vless-x25519":
6161
var privateKey string
6262
if len(args) > 1 {
6363
privateKey = args[1]
6464
}
65-
privateKeyBase64, passwordBase64, err := encryption.GenX25519(privateKey)
65+
privateKeyBase64, passwordBase64, hash32Base64, err := encryption.GenX25519(privateKey)
6666
if err != nil {
6767
panic(err)
6868
}
6969
fmt.Println("PrivateKey: " + privateKeyBase64)
7070
fmt.Println("Password: " + passwordBase64)
71+
fmt.Println("Hash32: " + hash32Base64)
7172
}
7273
}

docs/config.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -640,10 +640,10 @@ proxies: # socks5
640640
network: tcp
641641
# -------------------------
642642
# vless encryption客户端配置:
643-
# (只使用 1-RTT 模式 / 复用八分钟后协商新的 baseKey,周期需小于服务端的值
644-
# / 是只能选一个,后面是 base64RawURLEncoding,使用 mihomo generate vless-x25519 和 mihomo generate vless-mlkem768 生成,替换值时需去掉括号
643+
#native/xorpub 的 XTLS 可以 Splice。只使用 1-RTT 模式 / 若服务端发的 ticket 中秒数不为零则 0-RTT 复用
644+
# / 是只能选一个,后面 base64 至少一个,无限串联,使用 mihomo generate vless-x25519 和 mihomo generate vless-mlkem768 生成,替换值时需去掉括号
645645
# -------------------------
646-
encryption: "1rtt/8min.native/divide/random.mlkem768Client.(X25519 Password).(ML-KEM-768 Client)"
646+
encryption: "mlkem768x25519plus.native/xorpub/random.1rtt/0rtt.(X25519 Password).(ML-KEM-768 Client)..."
647647
tls: false #可以不开启tls
648648
udp: true
649649

@@ -1365,10 +1365,10 @@ listeners:
13651365
# grpc-service-name: "GunService" # 如果不为空则开启 grpc 传输层
13661366
# -------------------------
13671367
# vless encryption服务端配置:
1368-
# (只允许 1-RTT 模式 / 同时允许 1-RTT 模式与十分钟复用的 0-RTT 模式;原生外观 / ECH 式 XOR / 全随机数
1369-
# / 是只能选一个,后面是 base64RawURLEncoding,使用 mihomo generate vless-x25519 和 mihomo generate vless-mlkem768 生成,替换值时需去掉括号
1368+
#原生外观 / 只 XOR 公钥 / 全随机数。只允许 1-RTT 模式 / 同时允许 1-RTT 模式与 600 秒复用的 0-RTT 模式)
1369+
# / 是只能选一个,后面 base64 至少一个,无限串联,使用 mihomo generate vless-x25519 和 mihomo generate vless-mlkem768 生成,替换值时需去掉括号
13701370
# -------------------------
1371-
# decryption: "1rtt/10min.native/divide/random.mlkem768Seed.(X25519 PrivateKey).(ML-KEM-768 Seed)"
1371+
# decryption: "mlkem768x25519plus.native/xorpub/random.1rtt/600s.(X25519 PrivateKey).(ML-KEM-768 Seed)..."
13721372
# 下面两项如果填写则开启 tls(需要同时填写)
13731373
# certificate: ./server.crt
13741374
# private-key: ./server.key

listener/inbound/vless_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,24 +94,24 @@ func TestInboundVless_Encryption(t *testing.T) {
9494
t.Fatal(err)
9595
return
9696
}
97-
privateKeyBase64, passwordBase64, err := encryption.GenX25519("")
97+
privateKeyBase64, passwordBase64, _, err := encryption.GenX25519("")
9898
if err != nil {
9999
t.Fatal(err)
100100
return
101101
}
102102
var modes = []string{
103103
"native",
104-
"divide",
104+
"xorpub",
105105
"random",
106106
}
107107
for i := range modes {
108108
mode := modes[i]
109109
t.Run(mode, func(t *testing.T) {
110110
inboundOptions := inbound.VlessOption{
111-
Decryption: "10min." + mode + ".mlkem768Seed." + privateKeyBase64 + "." + seedBase64,
111+
Decryption: "mlkem768x25519plus." + mode + ".600s." + privateKeyBase64 + "." + seedBase64,
112112
}
113113
outboundOptions := outbound.VlessOption{
114-
Encryption: "8min." + mode + ".mlkem768Client." + passwordBase64 + "." + clientBase64,
114+
Encryption: "mlkem768x25519plus." + mode + ".0rtt." + passwordBase64 + "." + clientBase64,
115115
}
116116
testInboundVless(t, inboundOptions, outboundOptions)
117117
t.Run("xtls-rprx-vision", func(t *testing.T) {

listener/sing_vless/server.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,7 @@ func init() {
4646
})
4747

4848
vless.RegisterTLS(func(conn net.Conn) (loaded bool, netConn net.Conn, reflectType reflect.Type, reflectPointer unsafe.Pointer) {
49-
tlsConn, loaded := network.CastReader[*encryption.ClientConn](conn)
50-
if !loaded {
51-
return
52-
}
53-
return true, tlsConn.Conn, reflect.TypeOf(tlsConn).Elem(), unsafe.Pointer(tlsConn)
54-
})
55-
56-
vless.RegisterTLS(func(conn net.Conn) (loaded bool, netConn net.Conn, reflectType reflect.Type, reflectPointer unsafe.Pointer) {
57-
tlsConn, loaded := network.CastReader[*encryption.ServerConn](conn)
49+
tlsConn, loaded := network.CastReader[*encryption.CommonConn](conn)
5850
if !loaded {
5951
return
6052
}

0 commit comments

Comments
 (0)