1
0
mirror of https://github.com/MetaCubeX/mihomo.git synced 2025-09-21 04:55:57 +08:00
Files
mihomo/component/generator/cmd.go

73 lines
1.9 KiB
Go
Raw Normal View History

2025-08-21 16:02:17 +08:00
package generator
2025-02-04 00:44:18 +08:00
import (
"encoding/base64"
"fmt"
2025-05-17 20:50:21 +08:00
"github.com/metacubex/mihomo/component/ech"
2025-08-10 22:16:25 +08:00
"github.com/metacubex/mihomo/transport/vless/encryption"
2025-05-17 20:50:21 +08:00
2025-02-04 00:44:18 +08:00
"github.com/gofrs/uuid/v5"
)
func Main(args []string) {
if len(args) < 1 {
2025-08-21 08:33:44 +08:00
panic("Using: generate uuid/reality-keypair/wg-keypair/ech-keypair/vless-mlkem768/vless-x25519")
2025-02-04 00:44:18 +08:00
}
switch args[0] {
case "uuid":
newUUID, err := uuid.NewV4()
if err != nil {
panic(err)
}
fmt.Println(newUUID.String())
case "reality-keypair":
2025-08-21 16:02:17 +08:00
privateKey, err := GenX25519PrivateKey()
2025-02-04 00:44:18 +08:00
if err != nil {
panic(err)
}
2025-08-21 16:02:17 +08:00
fmt.Println("PrivateKey: " + base64.RawURLEncoding.EncodeToString(privateKey.Bytes()))
fmt.Println("PublicKey: " + base64.RawURLEncoding.EncodeToString(privateKey.PublicKey().Bytes()))
2025-02-04 00:44:18 +08:00
case "wg-keypair":
2025-08-21 16:02:17 +08:00
privateKey, err := GenX25519PrivateKey()
2025-02-04 00:44:18 +08:00
if err != nil {
panic(err)
}
2025-08-21 16:02:17 +08:00
fmt.Println("PrivateKey: " + base64.StdEncoding.EncodeToString(privateKey.Bytes()))
fmt.Println("PublicKey: " + base64.StdEncoding.EncodeToString(privateKey.PublicKey().Bytes()))
2025-05-17 20:50:21 +08:00
case "ech-keypair":
if len(args) < 2 {
panic("Using: generate ech-keypair <plain_server_name>")
}
configBase64, keyPem, err := ech.GenECHConfig(args[1])
if err != nil {
panic(err)
}
fmt.Println("Config:", configBase64)
fmt.Println("Key:", keyPem)
2025-08-10 22:16:25 +08:00
case "vless-mlkem768":
var seed string
if len(args) > 1 {
seed = args[1]
}
seedBase64, clientBase64, hash11Base64, err := encryption.GenMLKEM768(seed)
2025-08-10 22:16:25 +08:00
if err != nil {
panic(err)
}
fmt.Println("Seed: " + seedBase64)
2025-08-11 11:29:51 +08:00
fmt.Println("Client: " + clientBase64)
fmt.Println("Hash11: " + hash11Base64)
2025-08-21 08:33:44 +08:00
case "vless-x25519":
var privateKey string
if len(args) > 1 {
privateKey = args[1]
}
privateKeyBase64, passwordBase64, err := encryption.GenX25519(privateKey)
if err != nil {
panic(err)
}
fmt.Println("PrivateKey: " + privateKeyBase64)
fmt.Println("Password: " + passwordBase64)
2025-02-04 00:44:18 +08:00
}
}