From 21bcb530623ff35b62538b173407b6ad4a8bfe85 Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Sat, 19 Dec 2020 15:24:25 +0000 Subject: [PATCH] Human friendly key and uid generators --- README.md | 7 +++---- cmd/ck-server/ck-server.go | 25 +++++++++++++++++++------ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index cd85a0d..044c144 100644 --- a/README.md +++ b/README.md @@ -165,9 +165,8 @@ is established. 0. Install at least one underlying proxy server (e.g. OpenVPN, Shadowsocks). 1. Download [the latest release](https://github.com/cbeuw/Cloak/releases) or clone and build this repo. -2. Run `ck-server -k`. The base64 string before the comma is the **public** key to be given to users, the one after the - comma is the **private** key to be kept secret. -3. Run `ck-server -u`. This will be used as the `AdminUID`. +2. Run `ck-server -key`. The **public** should be given to users, the **private** key should be kept secret. +3. Run `ck-server -uid`. The new UID will be used as `AdminUID`. 4. Copy example_config/ckserver.json into a desired location. Change `PrivateKey` to the private key you just obtained; change `AdminUID` to the UID you just obtained. 5. Configure your underlying proxy server so that they all listen on localhost. Edit `ProxyBook` in the configuration @@ -181,7 +180,7 @@ is established. ##### Unrestricted users -Run `ck-server -u` and add the UID into the `BypassUID` field in `ckserver.json` +Run `ck-server -uid` and add the UID into the `BypassUID` field in `ckserver.json` ##### Users subject to bandwidth and credit controls diff --git a/cmd/ck-server/ck-server.go b/cmd/ck-server/ck-server.go index e741149..b646232 100644 --- a/cmd/ck-server/ck-server.go +++ b/cmd/ck-server/ck-server.go @@ -80,8 +80,11 @@ func main() { askVersion := flag.Bool("v", false, "Print the version number") printUsage := flag.Bool("h", false, "Print this message") - genUID := flag.Bool("u", false, "Generate a UID") - genKeyPair := flag.Bool("k", false, "Generate a pair of public and private key, output in the format of pubkey,pvkey") + genUIDScript := flag.Bool("u", false, "Generate a UID to STDOUT") + genKeyPairScript := flag.Bool("k", false, "Generate a pair of public and private key and output to STDOUT in the format of ,") + + genUIDHuman := flag.Bool("uid", false, "Generate and print out a UID") + genKeyPairHuman := flag.Bool("key", false, "Generate and print out a public-private key pair") pprofAddr := flag.String("d", "", "debug use: ip:port to be listened by pprof profiler") verbosity := flag.String("verbosity", "info", "verbosity level") @@ -96,13 +99,23 @@ func main() { flag.Usage() return } - if *genUID { - fmt.Println(generateUID()) + if *genUIDScript || *genUIDHuman { + uid := generateUID() + if *genUIDScript { + fmt.Println(uid) + } else { + fmt.Printf("\x1B[35mYour UID is:\u001B[0m %s\n", uid) + } return } - if *genKeyPair { + if *genKeyPairScript || *genKeyPairHuman { pub, pv := generateKeyPair() - fmt.Printf("%v,%v", pub, pv) + if *genKeyPairScript { + fmt.Printf("%v,%v\n", pub, pv) + } else { + fmt.Printf("\x1B[36mYour PUBLIC key is:\x1B[0m %65s\n", pub) + fmt.Printf("\x1B[33mYour PRIVATE key is (keep it secret):\x1B[0m %47s\n", pv) + } return }