From 8e50b59671ed8f611b89e330cfe18cdd83ed078a Mon Sep 17 00:00:00 2001 From: "Khang. Nguyen Khac Nguyen" Date: Thu, 22 Oct 2020 13:37:32 +0700 Subject: [PATCH 1/2] fix(cli): show passphrase when user indicate --pass + when user indicate --pass when sending file, indicate --pass flag in recommended receive command. --- src/cli/cli.go | 2 +- src/croc/croc.go | 10 ++++++++-- src/models/constants.go | 9 ++++++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/cli/cli.go b/src/cli/cli.go index 4564d7b1..76b2c58a 100644 --- a/src/cli/cli.go +++ b/src/cli/cli.go @@ -88,7 +88,7 @@ func Run() (err error) { &cli.StringFlag{Name: "relay", Value: models.DEFAULT_RELAY, Usage: "address of the relay", EnvVars: []string{"CROC_RELAY"}}, &cli.StringFlag{Name: "relay6", Value: models.DEFAULT_RELAY6, Usage: "ipv6 address of the relay", EnvVars: []string{"CROC_RELAY6"}}, &cli.StringFlag{Name: "out", Value: ".", Usage: "specify an output folder to receive the file"}, - &cli.StringFlag{Name: "pass", Value: "pass123", Usage: "password for the relay", EnvVars: []string{"CROC_PASS"}}, + &cli.StringFlag{Name: "pass", Value: models.DEFAULT_PASSPHRASE, Usage: "password for the relay", EnvVars: []string{"CROC_PASS"}}, &cli.StringFlag{Name: "socks5", Value: "", Usage: "add a socks5 proxy", EnvVars: []string{"SOCKS5_PROXY"}}, } app.EnableBashCompletion = true diff --git a/src/croc/croc.go b/src/croc/croc.go index d6046f70..6397e41e 100644 --- a/src/croc/croc.go +++ b/src/croc/croc.go @@ -347,11 +347,17 @@ func (c *Client) Send(options TransferOptions) (err error) { if err != nil { return } - otherRelay := "" + var ( + otherRelay string + otherPassphrase string + ) if c.Options.RelayAddress != models.DEFAULT_RELAY { otherRelay = "--relay " + c.Options.RelayAddress + " " } - fmt.Fprintf(os.Stderr, "Code is: %s\nOn the other computer run\n\ncroc %s%s\n", c.Options.SharedSecret, otherRelay, c.Options.SharedSecret) + if c.Options.RelayPassword != models.DEFAULT_PASSPHRASE { + otherPassphrase = "--pass " + c.Options.RelayPassword + " " + } + fmt.Fprintf(os.Stderr, "Code is: %s\nOn the other computer run\n\ncroc %s%s%s\n", c.Options.SharedSecret, otherPassphrase, otherRelay, c.Options.SharedSecret) if c.Options.Ask { machid, _ := machineid.ID() fmt.Fprintf(os.Stderr, "\rYour machine ID is '%s'\n", machid) diff --git a/src/models/constants.go b/src/models/constants.go index 283730b7..1c412190 100644 --- a/src/models/constants.go +++ b/src/models/constants.go @@ -6,9 +6,12 @@ import "net" const TCP_BUFFER_SIZE = 1024 * 64 // DEFAULT_RELAY is the default relay used (can be set using --relay) -var DEFAULT_RELAY = "croc.schollz.com" -var DEFAULT_RELAY6 = "croc6.schollz.com" -var DEFAULT_PORT = "9009" +var ( + DEFAULT_RELAY = "croc.schollz.com" + DEFAULT_RELAY6 = "croc6.schollz.com" + DEFAULT_PORT = "9009" + DEFAULT_PASSPHRASE = "pass123" +) func init() { iprecords, _ := net.LookupIP(DEFAULT_RELAY) From 4070f12cbf81147da147ff06eaf7f0db50354dca Mon Sep 17 00:00:00 2001 From: "Khang. Nguyen Khac Nguyen" Date: Thu, 22 Oct 2020 14:06:54 +0700 Subject: [PATCH 2/2] change(croc): shorten flag with builder --- src/croc/croc.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/croc/croc.go b/src/croc/croc.go index 6397e41e..b11e7e59 100644 --- a/src/croc/croc.go +++ b/src/croc/croc.go @@ -347,17 +347,14 @@ func (c *Client) Send(options TransferOptions) (err error) { if err != nil { return } - var ( - otherRelay string - otherPassphrase string - ) + flags := &strings.Builder{} if c.Options.RelayAddress != models.DEFAULT_RELAY { - otherRelay = "--relay " + c.Options.RelayAddress + " " + flags.WriteString("--relay " + c.Options.RelayAddress + " ") } if c.Options.RelayPassword != models.DEFAULT_PASSPHRASE { - otherPassphrase = "--pass " + c.Options.RelayPassword + " " + flags.WriteString("--pass " + c.Options.RelayPassword + " ") } - fmt.Fprintf(os.Stderr, "Code is: %s\nOn the other computer run\n\ncroc %s%s%s\n", c.Options.SharedSecret, otherPassphrase, otherRelay, c.Options.SharedSecret) + fmt.Fprintf(os.Stderr, "Code is: %[1]s\nOn the other computer run\n\ncroc %[2]s%[1]s\n", c.Options.SharedSecret, flags.String()) if c.Options.Ask { machid, _ := machineid.ID() fmt.Fprintf(os.Stderr, "\rYour machine ID is '%s'\n", machid)