diff --git a/client/main.go b/client/main.go index 28f8e3f..ae7eaff 100644 --- a/client/main.go +++ b/client/main.go @@ -1,5 +1,5 @@ // TODO: -// +// * Board UI? package main import ( @@ -7,6 +7,7 @@ import ( "crypto/ed25519" "encoding/hex" "errors" + "flag" "fmt" "io/ioutil" "net/http" @@ -40,11 +41,12 @@ func validKey() (ed25519.PublicKey, ed25519.PrivateKey) { var waitGroup sync.WaitGroup var once sync.Once - fmt.Printf(" - looking for a key that ends in %s using %d routines\n", + fmt.Printf(" - looking for a key that ends in 8%s using %d routines\n", keyEnd, nRoutines) var publicKey ed25519.PublicKey var privateKey ed25519.PrivateKey + start := time.Now() waitGroup.Add(nRoutines) for i := 0; i < nRoutines; i++ { @@ -59,7 +61,7 @@ func validKey() (ed25519.PublicKey, ed25519.PrivateKey) { // bytes.Equal to keep the hot loop fast if bytes.Equal(pub[29:32], target) && pub[28]&0x0F == 0x08 { once.Do(func() { - fmt.Printf("found %x\n", pub) + fmt.Printf("found %x in %f minutes\n", pub, time.Since(start).Minutes()) publicKey = pub privateKey = priv }) @@ -81,30 +83,41 @@ func fileExists(name string) bool { return true } -func getKeys() (ed25519.PublicKey, ed25519.PrivateKey) { - user, err := user.Current() - if err != nil { - panic(err) - } +func getKeys(folder string) (ed25519.PublicKey, ed25519.PrivateKey) { + // get the expected public key file and private key file paths + var pubfile, privfile string + if len(folder) == 0 { + user, err := user.Current() + if err != nil { + panic(err) + } - configPath := os.Getenv("XDG_CONFIG_HOME") - if configPath == "" { - configPath = filepath.Join(user.HomeDir, ".config", "spring83") - } + configPath := os.Getenv("XDG_CONFIG_HOME") + if configPath == "" { + configPath = filepath.Join(user.HomeDir, ".config", "spring83") + } - if err = os.MkdirAll(configPath, os.ModePerm); err != nil { - panic(err) + if err = os.MkdirAll(configPath, os.ModePerm); err != nil { + panic(err) + } + + pubfile = filepath.Join(configPath, "key.pub") + privfile = filepath.Join(configPath, "key.priv") + } else { + pubfile = filepath.Join(folder, "key.pub") + privfile = filepath.Join(folder, "key.priv") } - pubfile := filepath.Join(configPath, "key.pub") - privfile := filepath.Join(configPath, "key.priv") + // try to load the public and private key files as ed25519 keys var pubkey ed25519.PublicKey var privkey ed25519.PrivateKey + var err error if fileExists(pubfile) && fileExists(privfile) { pubkey, err = ioutil.ReadFile(pubfile) if err != nil { panic(err) } + privkey, err = ioutil.ReadFile(privfile) if err != nil { panic(err) @@ -120,17 +133,22 @@ func getKeys() (ed25519.PublicKey, ed25519.PrivateKey) { return pubkey, privkey } -func main() { - pubkey, privkey := getKeys() - - client := &http.Client{} - - body, err := ioutil.ReadAll(os.Stdin) - if err != nil { - panic(err) +func getBody(inputFile string) []byte { + var body []byte + var err error + if inputFile == "-" { + body, err = ioutil.ReadAll(os.Stdin) + if err != nil { + panic(err) + } + } else { + body, err = ioutil.ReadFile(inputFile) + if err != nil { + panic(err) + } } - // Prepoend a time element. Maybe we should check to see if it's already + // Prepend a time element. Maybe we should check to see if it's already // been provided? timeElt := []byte(fmt.Sprintf("