diff --git a/common/common.go b/common/common.go index a7d06d5..b7a8d38 100644 --- a/common/common.go +++ b/common/common.go @@ -1,2 +1,36 @@ // Package common contains common utilities that are shared among other packages. package common + +import ( + "crypto/rand" + "encoding/base64" + "fmt" + + "golang.org/x/crypto/curve25519" +) + +func X25519() { + var publicKey []byte + privateKey := make([]byte, curve25519.ScalarSize) + if _, err := rand.Read(privateKey); err != nil { + fmt.Println(err) + return + } + + // Modify random bytes using algorithm described at: + // https://cr.yp.to/ecdh.html. + privateKey[0] &= 248 + privateKey[31] &= 127 + privateKey[31] |= 64 + + publicKey, err := curve25519.X25519(privateKey, curve25519.Basepoint) + if err != nil { + fmt.Println(err) + return + } + + output := fmt.Sprintf("Private key: %v\nPublic key: %v", + base64.RawURLEncoding.EncodeToString(privateKey), + base64.RawURLEncoding.EncodeToString(publicKey)) + fmt.Println(output) +} diff --git a/main/config.yml.example b/main/config.yml.example index b16de6c..d424d10 100644 --- a/main/config.yml.example +++ b/main/config.yml.example @@ -53,14 +53,14 @@ Nodes: Dest: 80 # Required, Destination of fallback, check https://xtls.github.io/config/features/fallback.html for details. ProxyProtocolVer: 0 # Send PROXY protocol version, 0 for disable DisableLocalREALITYConfig: false # disable local reality config - EnableREALITY: true # Enable REALITY + EnableREALITY: false # Enable REALITY REALITYConfigs: Show: true # Show REALITY debug Dest: www.smzdm.com:443 # Required, Same as fallback ProxyProtocolVer: 0 # Send PROXY protocol version, 0 for disable ServerNames: # Required, list of available serverNames for the client, * wildcard is not supported at the moment. - www.smzdm.com - PrivateKey: YOUR_PRIVATE_KEY # Required, execute './xray x25519' to generate. + PrivateKey: YOUR_PRIVATE_KEY # Required, execute './XrayR -x25519' to generate. MinClientVer: # Optional, minimum version of Xray client, format is x.y.z. MaxClientVer: # Optional, maximum version of Xray client, format is x.y.z. MaxTimeDiff: 0 # Optional, maximum allowed time difference, unit is in milliseconds. diff --git a/main/main.go b/main/main.go index eac73d8..03fb3e4 100644 --- a/main/main.go +++ b/main/main.go @@ -15,12 +15,14 @@ import ( "github.com/fsnotify/fsnotify" "github.com/spf13/viper" + "github.com/XrayR-project/XrayR/common" "github.com/XrayR-project/XrayR/panel" ) var ( configFile = flag.String("config", "", "Config file for XrayR.") printVersion = flag.Bool("version", false, "show version") + x25519 = flag.Bool("x25519", false, "Generate key pair for x25519 key exchange") ) var ( @@ -71,6 +73,10 @@ func main() { if *printVersion { return } + if *x25519 { + common.X25519() + return + } config := getConfig() panelConfig := &panel.Config{}