diff --git a/main.go b/main.go index 1b11f2a..7dc008d 100644 --- a/main.go +++ b/main.go @@ -3,14 +3,10 @@ package main import ( "errors" "fmt" - "io/ioutil" - "math/rand" "os" - "path" "strings" "time" - homedir "github.com/mitchellh/go-homedir" croc "github.com/schollz/croc/src" "github.com/urfave/cli" ) @@ -33,7 +29,7 @@ func main() { app.UsageText = "croc allows any two computers to directly and securely transfer files" // app.ArgsUsage = "[args and such]" app.Commands = []cli.Command{ - cli.Command{ + { Name: "send", Usage: "send a file", Description: "send a file over the relay", @@ -47,34 +43,7 @@ func main() { return send(c) }, }, - cli.Command{ - Name: "gen", - Usage: "generate a permanent key", - Description: "generates a permanent key that is used each time", - HelpName: "croc gen", - ArgsUsage: "[key]", - Flags: []cli.Flag{ - cli.BoolFlag{Name: "new", Usage: "overwrite key if it exists"}, - }, - Action: func(c *cli.Context) error { - homedir, err := homedir.Dir() - if err != nil { - return err - } - if codePhrase == "" || c.Bool("new") { - codePhrase = randStringBytesMaskImprSrc(50) - if c.Args().First() != "" { - codePhrase = c.Args().First() - } - os.MkdirAll(path.Join(homedir, ".config", "croc"), 0644) - err = ioutil.WriteFile(path.Join(homedir, ".config", "croc", "key"), []byte(codePhrase), 0644) - } - fmt.Printf("your permanent key: %s\n", codePhrase) - fmt.Println("use -new if you want to regenerate your key") - return err - }, - }, - cli.Command{ + { Name: "receive", Usage: "receive a file", Description: "receve a file over the relay", @@ -83,7 +52,7 @@ func main() { return receive(c) }, }, - cli.Command{ + { Name: "relay", Usage: "start a croc relay", Description: "the croc relay will handle websocket and TCP connections", @@ -125,20 +94,6 @@ func main() { cr.Stdout = c.GlobalBool("stdout") cr.LocalOnly = c.GlobalBool("local") cr.NoLocal = c.GlobalBool("no-local") - - // check if permanent code phrase is here - homedir, err := homedir.Dir() - if err != nil { - return err - } - keyFile := path.Join(homedir, ".config", "croc", "key") - if _, err := os.Stat(keyFile); err == nil { - codePhraseBytes, err := ioutil.ReadFile(keyFile) - if err == nil { - codePhrase = string(codePhraseBytes) - } - } - return nil } @@ -183,31 +138,3 @@ func relay(c *cli.Context) error { cr.CurveType = c.String("curve") return cr.Relay() } - -// needed for croc gen -const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" -const ( - letterIdxBits = 6 // 6 bits to represent a letter index - letterIdxMask = 1<= 0; { - if remain == 0 { - cache, remain = src.Int63(), letterIdxMax - } - if idx := int(cache & letterIdxMask); idx < len(letterBytes) { - b[i] = letterBytes[idx] - i-- - } - cache >>= letterIdxBits - remain-- - } - - return string(b) -}