diff --git a/README.md b/README.md index 4ad504589b88..158487bf8315 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ - [iamybj/docker-xray](https://hub.docker.com/r/iamybj/docker-xray) - [teddysun/xray](https://hub.docker.com/r/teddysun/xray) - Web Panel - - [X-UI](https://github.com/FranzKafkaYu/x-ui), [X-UI-English](https://github.com/NidukaAkalanka/x-ui-english), [3X-UI](https://github.com/MHSanaei/3x-ui), [X-UI](https://github.com/alireza0/x-ui), [X-UI](https://github.com/diditra/x-ui) + - [X-UI-English](https://github.com/NidukaAkalanka/x-ui-english), [3X-UI](https://github.com/MHSanaei/3x-ui), [X-UI](https://github.com/alireza0/x-ui), [X-UI](https://github.com/diditra/x-ui) - [Xray-UI](https://github.com/qist/xray-ui), [X-UI](https://github.com/sing-web/x-ui) - [Hiddify](https://github.com/hiddify/hiddify-config) - [Marzban](https://github.com/Gozargah/Marzban) diff --git a/go.mod b/go.mod index 2c3b3f3e3f2a..6d5ab543a3a4 100644 --- a/go.mod +++ b/go.mod @@ -12,8 +12,8 @@ require ( github.com/pires/go-proxyproto v0.7.0 github.com/quic-go/quic-go v0.40.0 github.com/refraction-networking/utls v1.5.4 - github.com/sagernet/sing v0.2.18 - github.com/sagernet/sing-shadowsocks v0.2.5 + github.com/sagernet/sing v0.2.19 + github.com/sagernet/sing-shadowsocks v0.2.6 github.com/seiflotfy/cuckoofilter v0.0.0-20220411075957-e3b120b3f5fb github.com/stretchr/testify v1.8.4 github.com/v2fly/ss-bloomring v0.0.0-20210312155135-28617310f63e @@ -25,7 +25,7 @@ require ( golang.org/x/sync v0.5.0 golang.org/x/sys v0.15.0 golang.zx2c4.com/wireguard v0.0.0-20231022001213-2e0774f246fb - google.golang.org/grpc v1.59.0 + google.golang.org/grpc v1.60.0 google.golang.org/protobuf v1.31.0 gvisor.dev/gvisor v0.0.0-20231104011432-48a6d7d5bd0b h12.io/socks v1.0.3 diff --git a/go.sum b/go.sum index a68e1b771ac4..e00d5540f751 100644 --- a/go.sum +++ b/go.sum @@ -125,10 +125,10 @@ github.com/refraction-networking/utls v1.5.4/go.mod h1:SPuDbBmgLGp8s+HLNc83Fuavw github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 h1:f/FNXud6gA3MNr8meMVVGxhp+QBTqY91tM8HjEuMjGg= github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3/go.mod h1:HgjTstvQsPGkxUsCd2KWxErBblirPizecHcpD3ffK+s= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= -github.com/sagernet/sing v0.2.18 h1:2Ce4dl0pkWft+4914NGXPb8OiQpgA8UHQ9xFOmgvKuY= -github.com/sagernet/sing v0.2.18/go.mod h1:OL6k2F0vHmEzXz2KW19qQzu172FDgSbUSODylighuVo= -github.com/sagernet/sing-shadowsocks v0.2.5 h1:qxIttos4xu6ii7MTVJYA8EFQR7Q3KG6xMqmLJIFtBaY= -github.com/sagernet/sing-shadowsocks v0.2.5/go.mod h1:MGWGkcU2xW2G2mfArT9/QqpVLOGU+dBaahZCtPHdt7A= +github.com/sagernet/sing v0.2.19 h1:Mdj/YJ5TtEyG+eIZaAlvX8j2cHxMN6eW4RF6Xh9iWyg= +github.com/sagernet/sing v0.2.19/go.mod h1:Ce5LNojQOgOiWhiD8pPD6E9H7e2KgtOe3Zxx4Ou5u80= +github.com/sagernet/sing-shadowsocks v0.2.6 h1:xr7ylAS/q1cQYS8oxKKajhuQcchd5VJJ4K4UZrrpp0s= +github.com/sagernet/sing-shadowsocks v0.2.6/go.mod h1:j2YZBIpWIuElPFL/5sJAj470bcn/3QQ5lxZUNKLDNAM= github.com/seiflotfy/cuckoofilter v0.0.0-20220411075957-e3b120b3f5fb h1:XfLJSPIOUX+osiMraVgIrMR27uMXnRJWGm1+GL8/63U= github.com/seiflotfy/cuckoofilter v0.0.0-20220411075957-e3b120b3f5fb/go.mod h1:bR6DqgcAl1zTcOX8/pE2Qkj9XO00eCNqmKb7lXP8EAg= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= @@ -280,8 +280,8 @@ google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmE google.golang.org/grpc v1.16.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.59.0 h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk= -google.golang.org/grpc v1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9YtF98= +google.golang.org/grpc v1.60.0 h1:6FQAR0kM31P6MRdeluor2w2gPaS4SVNrD/DNTxrQ15k= +google.golang.org/grpc v1.60.0/go.mod h1:OlCHIeLYqSSsLi6i49B5QGdzaMZK9+M7LXN2FKz4eGM= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= diff --git a/main/commands/all/commands.go b/main/commands/all/commands.go index 9b8b49e0258a..41d0e0f12899 100644 --- a/main/commands/all/commands.go +++ b/main/commands/all/commands.go @@ -16,5 +16,6 @@ func init() { tls.CmdTLS, cmdUUID, cmdX25519, + cmdWG, ) } diff --git a/main/commands/all/curve25519.go b/main/commands/all/curve25519.go new file mode 100644 index 000000000000..25cc812ebad6 --- /dev/null +++ b/main/commands/all/curve25519.go @@ -0,0 +1,57 @@ +package all + +import ( + "crypto/rand" + "encoding/base64" + "fmt" + + "golang.org/x/crypto/curve25519" +) + +func Curve25519Genkey(StdEncoding bool, input_base64 string) { + var output string + var err error + var privateKey, publicKey []byte + var encoding *base64.Encoding + if *input_stdEncoding || StdEncoding { + encoding = base64.StdEncoding + } else { + encoding = base64.RawURLEncoding + } + + if len(input_base64) > 0 { + privateKey, err = encoding.DecodeString(input_base64) + if err != nil { + output = err.Error() + goto out + } + if len(privateKey) != curve25519.ScalarSize { + output = "Invalid length of private key." + goto out + } + } + + if privateKey == nil { + privateKey = make([]byte, curve25519.ScalarSize) + if _, err = rand.Read(privateKey); err != nil { + output = err.Error() + goto out + } + } + + // Modify random bytes using algorithm described at: + // https://cr.yp.to/ecdh.html. + privateKey[0] &= 248 + privateKey[31] &= 127 | 64 + + if publicKey, err = curve25519.X25519(privateKey, curve25519.Basepoint); err != nil { + output = err.Error() + goto out + } + + output = fmt.Sprintf("Private key: %v\nPublic key: %v", + encoding.EncodeToString(privateKey), + encoding.EncodeToString(publicKey)) +out: + fmt.Println(output) +} diff --git a/main/commands/all/wg.go b/main/commands/all/wg.go new file mode 100644 index 000000000000..70da46682b11 --- /dev/null +++ b/main/commands/all/wg.go @@ -0,0 +1,27 @@ +package all + +import ( + "github.com/xtls/xray-core/main/commands/base" +) + +var cmdWG = &base.Command{ + UsageLine: `{{.Exec}} wg [-i "private key (base64.StdEncoding)"]`, + Short: `Generate key pair for wireguard key exchange`, + Long: ` +Generate key pair for wireguard key exchange. + +Random: {{.Exec}} wg + +From private key: {{.Exec}} wg -i "private key (base64.StdEncoding)" +`, +} + +func init() { + cmdWG.Run = executeWG // break init loop +} + +var input_wireguard = cmdWG.Flag.String("i", "", "") + +func executeWG(cmd *base.Command, args []string) { + Curve25519Genkey(true, *input_wireguard) +} diff --git a/main/commands/all/x25519.go b/main/commands/all/x25519.go index 814cca7202b2..73f669b269f2 100644 --- a/main/commands/all/x25519.go +++ b/main/commands/all/x25519.go @@ -1,12 +1,7 @@ package all import ( - "crypto/rand" - "encoding/base64" - "fmt" - "github.com/xtls/xray-core/main/commands/base" - "golang.org/x/crypto/curve25519" ) var cmdX25519 = &base.Command{ @@ -26,55 +21,9 @@ func init() { cmdX25519.Run = executeX25519 // break init loop } -var input_base64 = cmdX25519.Flag.String("i", "", "") var input_stdEncoding = cmdX25519.Flag.Bool("std-encoding", false, "") +var input_x25519 = cmdX25519.Flag.String("i", "", "") func executeX25519(cmd *base.Command, args []string) { - var output string - var err error - var privateKey []byte - var publicKey []byte - var encoding *base64.Encoding - if len(*input_base64) > 0 { - privateKey, err = base64.RawURLEncoding.DecodeString(*input_base64) - if err != nil { - output = err.Error() - goto out - } - if len(privateKey) != curve25519.ScalarSize { - output = "Invalid length of private key." - goto out - } - } - - if privateKey == nil { - privateKey = make([]byte, curve25519.ScalarSize) - if _, err = rand.Read(privateKey); err != nil { - output = err.Error() - goto out - } - } - - // Modify random bytes using algorithm described at: - // https://cr.yp.to/ecdh.html. - privateKey[0] &= 248 - privateKey[31] &= 127 - privateKey[31] |= 64 - - if publicKey, err = curve25519.X25519(privateKey, curve25519.Basepoint); err != nil { - output = err.Error() - goto out - } - - if *input_stdEncoding { - encoding = base64.StdEncoding - } else { - encoding = base64.RawURLEncoding - } - - output = fmt.Sprintf("Private key: %v\nPublic key: %v", - encoding.EncodeToString(privateKey), - encoding.EncodeToString(publicKey)) -out: - fmt.Println(output) + Curve25519Genkey(false, *input_x25519) }