|
| 1 | +package all |
| 2 | + |
| 3 | +import ( |
| 4 | + "encoding/base64" |
| 5 | + "fmt" |
| 6 | + "strings" |
| 7 | + |
| 8 | + "github.com/xtls/xray-core/main/commands/base" |
| 9 | +) |
| 10 | + |
| 11 | +var cmdVLESSEnc = &base.Command{ |
| 12 | + UsageLine: `{{.Exec}} vlessenc`, |
| 13 | + Short: `Generate decryption/encryption json pair (VLESS Encryption)`, |
| 14 | + Long: ` |
| 15 | +Generate decryption/encryption json pair (VLESS Encryption). |
| 16 | +`, |
| 17 | +} |
| 18 | + |
| 19 | +func init() { |
| 20 | + cmdVLESSEnc.Run = executeVLESSEnc // break init loop |
| 21 | +} |
| 22 | + |
| 23 | +func executeVLESSEnc(cmd *base.Command, args []string) { |
| 24 | + privateKey, password, _, _ := genCurve25519(nil) |
| 25 | + serverKey := base64.RawURLEncoding.EncodeToString(privateKey) |
| 26 | + clientKey := base64.RawURLEncoding.EncodeToString(password) |
| 27 | + decryption := generateDotConfig("mlkem768x25519plus", "native", "600s", serverKey) |
| 28 | + encryption := generateDotConfig("mlkem768x25519plus", "native", "0rtt", clientKey) |
| 29 | + seed, client, _ := genMLKEM768(nil) |
| 30 | + serverKeyPQ := base64.RawURLEncoding.EncodeToString(seed[:]) |
| 31 | + clientKeyPQ := base64.RawURLEncoding.EncodeToString(client) |
| 32 | + decryptionPQ := generateDotConfig("mlkem768x25519plus", "native", "600s", serverKeyPQ) |
| 33 | + encryptionPQ := generateDotConfig("mlkem768x25519plus", "native", "0rtt", clientKeyPQ) |
| 34 | + fmt.Printf("Choose one Authentication to use, do not mix them. Ephemeral key exchange is Post-Quantum safe anyway.\n\n") |
| 35 | + fmt.Printf("Authentication: X25519, not Post-Quantum\n\"decryption\": \"%v\"\n\"encryption\": \"%v\"\n\n", decryption, encryption) |
| 36 | + fmt.Printf("Authentication: ML-KEM-768, Post-Quantum\n\"decryption\": \"%v\"\n\"encryption\": \"%v\"\n", decryptionPQ, encryptionPQ) |
| 37 | +} |
| 38 | + |
| 39 | +func generateDotConfig(fields ...string) string { |
| 40 | + return strings.Join(fields, ".") |
| 41 | +} |
0 commit comments