mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-06-13 21:54:13 +08:00
Renames
This commit is contained in:
parent
a742922c17
commit
849c6a2d22
@ -12,8 +12,8 @@ var commandGenerate = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
commandGenerate.AddCommand(generate.CommandGeneratePSK)
|
commandGenerate.AddCommand(generate.CommandGenerateRandom)
|
||||||
commandGenerate.AddCommand(generate.CommandGenerateUUID)
|
commandGenerate.AddCommand(generate.CommandGenerateUUID)
|
||||||
commandGenerate.AddCommand(generate.CommandGenerateX25519)
|
commandGenerate.AddCommand(generate.CommandGenerateReality)
|
||||||
mainCommand.AddCommand(commandGenerate)
|
mainCommand.AddCommand(commandGenerate)
|
||||||
}
|
}
|
||||||
|
@ -1,42 +0,0 @@
|
|||||||
package generate
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/rand"
|
|
||||||
"encoding/base64"
|
|
||||||
"encoding/hex"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/sagernet/sing-box/log"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
|
||||||
|
|
||||||
var CommandGeneratePSK = &cobra.Command{
|
|
||||||
Use: "psk",
|
|
||||||
Short: "Generate a random PSK",
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
|
||||||
if size > 0 {
|
|
||||||
encoder := base64.StdEncoding.EncodeToString
|
|
||||||
if outputHex {
|
|
||||||
encoder = hex.EncodeToString
|
|
||||||
}
|
|
||||||
|
|
||||||
psk := make([]byte, size)
|
|
||||||
_, err := rand.Read(psk)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
os.Stdout.WriteString(encoder(psk) + "\n")
|
|
||||||
} else {
|
|
||||||
cmd.Help()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
var size int
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
CommandGeneratePSK.Flags().BoolVarP(&outputHex, "hex", "H", false, "print hex format")
|
|
||||||
CommandGeneratePSK.Flags().IntVarP(&size, "size", "s", 0, "PSK size")
|
|
||||||
}
|
|
42
cmd/sing-box/internal/generate/rand.go
Normal file
42
cmd/sing-box/internal/generate/rand.go
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package generate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/rand"
|
||||||
|
"encoding/base64"
|
||||||
|
"encoding/hex"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/sagernet/sing-box/log"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var CommandGenerateRandom = &cobra.Command{
|
||||||
|
Use: "rand",
|
||||||
|
Short: "Generate random bytes",
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
length, err := strconv.Atoi(args[0])
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
encoder := base64.StdEncoding.EncodeToString
|
||||||
|
if outputHex {
|
||||||
|
encoder = hex.EncodeToString
|
||||||
|
}
|
||||||
|
|
||||||
|
bs := make([]byte, length)
|
||||||
|
_, err = rand.Read(bs)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Stdout.WriteString(encoder(bs) + "\n")
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
CommandGenerateRandom.Flags().BoolVarP(&outputHex, "hex", "H", false, "print hex format")
|
||||||
|
}
|
@ -13,9 +13,10 @@ import (
|
|||||||
"golang.org/x/crypto/curve25519"
|
"golang.org/x/crypto/curve25519"
|
||||||
)
|
)
|
||||||
|
|
||||||
var CommandGenerateX25519 = &cobra.Command{
|
var CommandGenerateReality = &cobra.Command{
|
||||||
Use: "x25519",
|
Use: "reality-key",
|
||||||
Short: "Generate a X25519 key pair",
|
Short: "Generate a REALITY protocol X25519 key pair",
|
||||||
|
Args: cobra.NoArgs,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
encoder := base64.RawURLEncoding.EncodeToString
|
encoder := base64.RawURLEncoding.EncodeToString
|
||||||
if outputHex {
|
if outputHex {
|
||||||
@ -51,6 +52,6 @@ var CommandGenerateX25519 = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
CommandGenerateX25519.Flags().BoolVarP(&outputHex, "hex", "H", false, "print hex format")
|
CommandGenerateReality.Flags().BoolVarP(&outputHex, "hex", "H", false, "print hex format")
|
||||||
CommandGenerateX25519.Flags().StringVarP(&input, "input", "i", "", "generate from specified private key")
|
CommandGenerateReality.Flags().StringVarP(&input, "input", "i", "", "generate from specified private key")
|
||||||
}
|
}
|
@ -12,6 +12,7 @@ import (
|
|||||||
var CommandGenerateUUID = &cobra.Command{
|
var CommandGenerateUUID = &cobra.Command{
|
||||||
Use: "uuid",
|
Use: "uuid",
|
||||||
Short: "Generate a UUID",
|
Short: "Generate a UUID",
|
||||||
|
Args: cobra.NoArgs,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
var (
|
var (
|
||||||
newUUID uuid.UUID
|
newUUID uuid.UUID
|
||||||
|
@ -78,9 +78,9 @@ Both if empty.
|
|||||||
==Required==
|
==Required==
|
||||||
|
|
||||||
| Method | Password Format |
|
| Method | Password Format |
|
||||||
|---------------|-----------------------------------------|
|
|---------------|---------------------------------------|
|
||||||
| none | / |
|
| none | / |
|
||||||
| 2022 methods | `sing-box generate psk -s <Key Length>` |
|
| 2022 methods | `sing-box generate rand <Key Length>` |
|
||||||
| other methods | any string |
|
| other methods | any string |
|
||||||
|
|
||||||
### Listen Fields
|
### Listen Fields
|
||||||
|
@ -78,7 +78,7 @@ See [Listen Fields](/configuration/shared/listen) for details.
|
|||||||
==必填==
|
==必填==
|
||||||
|
|
||||||
| 方法 | 密码格式 |
|
| 方法 | 密码格式 |
|
||||||
|---------------|-----------------------------------|
|
|---------------|---------------------------------|
|
||||||
| none | / |
|
| none | / |
|
||||||
| 2022 methods | `sing-box generate psk -s <密钥长度>` |
|
| 2022 methods | `sing-box generate rand <密钥长度>` |
|
||||||
| other methods | 任意字符串 |
|
| other methods | 任意字符串 |
|
@ -319,7 +319,7 @@ Handshake server address and [Dial options](/configuration/shared/dial).
|
|||||||
|
|
||||||
==Required==
|
==Required==
|
||||||
|
|
||||||
Private key, generated by `sing-box generate x25519`.
|
Private key, generated by `sing-box generate reality-key`.
|
||||||
|
|
||||||
#### public_key
|
#### public_key
|
||||||
|
|
||||||
@ -327,7 +327,7 @@ Private key, generated by `sing-box generate x25519`.
|
|||||||
|
|
||||||
==Required==
|
==Required==
|
||||||
|
|
||||||
Public key, generated by `sing-box generate x25519`.
|
Public key, generated by `sing-box generate reality-key`.
|
||||||
|
|
||||||
#### short_id
|
#### short_id
|
||||||
|
|
||||||
|
@ -315,7 +315,7 @@ MAC 密钥。
|
|||||||
|
|
||||||
==必填==
|
==必填==
|
||||||
|
|
||||||
私钥,由 `sing-box generate x25519` 生成。
|
私钥,由 `sing-box generate reality-key` 生成。
|
||||||
|
|
||||||
#### public_key
|
#### public_key
|
||||||
|
|
||||||
@ -323,7 +323,7 @@ MAC 密钥。
|
|||||||
|
|
||||||
==必填==
|
==必填==
|
||||||
|
|
||||||
公钥,由 `sing-box generate x25519` 生成。
|
公钥,由 `sing-box generate reality-key` 生成。
|
||||||
|
|
||||||
#### short_id
|
#### short_id
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user