|
|
@ -8,65 +8,66 @@ import ( |
|
|
|
"fmt" |
|
|
|
"git.openprivacy.ca/openprivacy/libricochet-go/utils" |
|
|
|
|
|
|
|
"github.com/sethvargo/go-diceware/diceware" |
|
|
|
"errors" |
|
|
|
"git.openprivacy.ca/openprivacy/libricochet-go/log" |
|
|
|
"golang.org/x/crypto/ed25519" |
|
|
|
"io/ioutil" |
|
|
|
"log" |
|
|
|
"os" |
|
|
|
"strconv" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
) |
|
|
|
|
|
|
|
func convertCwtchFile(filename string, password string) { |
|
|
|
func convertCwtchFile(filename string, password string) error { |
|
|
|
fileStore := storage2.CreateFileProfileStore(filename, password) |
|
|
|
peer, err := fileStore.Load() |
|
|
|
if err != nil { |
|
|
|
log.Fatalf("%v", err) |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
b := []byte("== ed25519v1-secret: type0 ==") |
|
|
|
b = append(b, peer.GetProfile().Ed25519PrivateKey...) |
|
|
|
err = ioutil.WriteFile("hs_ed25519_secret_key", b, 0600) |
|
|
|
if err != nil { |
|
|
|
log.Fatalf("%v", err) |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
b = []byte("== ed25519v1-public: type0 ==") |
|
|
|
b = append(b, peer.GetProfile().Ed25519PublicKey...) |
|
|
|
err = ioutil.WriteFile("hs_ed25519_public_key", b, 0600) |
|
|
|
if err != nil { |
|
|
|
log.Fatalf("%v", err) |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
b = []byte(peer.GetProfile().Onion + ".onion\n") |
|
|
|
err = ioutil.WriteFile("hostname", b, 0600) |
|
|
|
if err != nil { |
|
|
|
log.Fatalf("%v", err) |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
fmt.Println("success!") |
|
|
|
log.Infoln("success!") |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
func convertTorFile(filename string, password string) { |
|
|
|
log.Fatalf("this code doesn't work and can never work :( it's a math thing") |
|
|
|
func convertTorFile(filename string, password string) error { |
|
|
|
return errors.New("this code doesn't work and can never work :( it's a math thing") |
|
|
|
|
|
|
|
name, _ := diceware.Generate(2) |
|
|
|
/*name, _ := diceware.Generate(2) |
|
|
|
sk, err := ioutil.ReadFile("hs_ed25519_secret_key") |
|
|
|
if err != nil { |
|
|
|
log.Fatalf("%v", err) |
|
|
|
return err |
|
|
|
} |
|
|
|
sk = sk[32:] |
|
|
|
|
|
|
|
pk, err := ioutil.ReadFile("hs_ed25519_public_key") |
|
|
|
if err != nil { |
|
|
|
log.Fatalf("%v", err) |
|
|
|
return err |
|
|
|
} |
|
|
|
pk = pk[32:] |
|
|
|
|
|
|
|
onion, err := ioutil.ReadFile("hostname") |
|
|
|
if err != nil { |
|
|
|
log.Fatalf("%v", err) |
|
|
|
return err |
|
|
|
} |
|
|
|
onion = onion[:56] |
|
|
|
|
|
|
@ -79,13 +80,14 @@ func convertTorFile(filename string, password string) { |
|
|
|
fileStore := storage2.CreateFileProfileStore(filename, password) |
|
|
|
err = fileStore.Save(peer) |
|
|
|
if err != nil { |
|
|
|
log.Fatalf("%v", err) |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
log.Printf("success! loaded %d byte pk and %d byte sk for %s.onion\n", len(pk), len(sk), onion) |
|
|
|
log.Infof("success! loaded %d byte pk and %d byte sk for %s.onion\n", len(pk), len(sk), onion) |
|
|
|
return nil*/ |
|
|
|
} |
|
|
|
|
|
|
|
func vanity() { |
|
|
|
func vanity() error { |
|
|
|
for { |
|
|
|
pk, sk, err := ed25519.GenerateKey(rand.Reader) |
|
|
|
if err != nil { |
|
|
@ -101,19 +103,20 @@ func vanity() { |
|
|
|
fileStore := storage2.CreateFileProfileStore(os.Args[3], onion+".cwtch") |
|
|
|
err := fileStore.Save(peer) |
|
|
|
if err != nil { |
|
|
|
log.Fatalf("%v", err) |
|
|
|
return err |
|
|
|
} |
|
|
|
log.Printf("found %s.onion\n", onion) |
|
|
|
log.Infof("found %s.onion\n", onion) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func printHelp() { |
|
|
|
log.Println("usage: cwtchutil {help, convert-cwtch-file, convert-tor-file, changepw, vanity}") |
|
|
|
log.Infoln("usage: cwtchutil {help, convert-cwtch-file, convert-tor-file, changepw, vanity}") |
|
|
|
} |
|
|
|
|
|
|
|
func main() { |
|
|
|
log.SetLevel(log.LevelInfo) |
|
|
|
if len(os.Args) < 2 { |
|
|
|
printHelp() |
|
|
|
os.Exit(1) |
|
|
@ -126,28 +129,34 @@ func main() { |
|
|
|
printHelp() |
|
|
|
case "convert-cwtch-file": |
|
|
|
if len(os.Args) != 4 { |
|
|
|
log.Println("example: cwtchutil convert-cwtch-file ~/.cwtch/profiles/11ddd78a9918c064e742d5e36a8b8fd4 passw0rd") |
|
|
|
fmt.Println("example: cwtchutil convert-cwtch-file ~/.cwtch/profiles/11ddd78a9918c064e742d5e36a8b8fd4 passw0rd") |
|
|
|
os.Exit(1) |
|
|
|
} |
|
|
|
convertCwtchFile(os.Args[2], os.Args[3]) |
|
|
|
err := convertCwtchFile(os.Args[2], os.Args[3]) |
|
|
|
if err != nil { |
|
|
|
log.Errorln(err) |
|
|
|
} |
|
|
|
case "convert-tor-file": |
|
|
|
if len(os.Args) != 4 { |
|
|
|
log.Println("example: cwtchutil convert-tor-file /var/lib/tor/hs1 passw0rd") |
|
|
|
fmt.Println("example: cwtchutil convert-tor-file /var/lib/tor/hs1 passw0rd") |
|
|
|
os.Exit(1) |
|
|
|
} |
|
|
|
convertTorFile(os.Args[2], os.Args[3]) |
|
|
|
err := convertTorFile(os.Args[2], os.Args[3]) |
|
|
|
if err != nil { |
|
|
|
log.Errorln(err) |
|
|
|
} |
|
|
|
case "vanity": |
|
|
|
if len(os.Args) < 5 { |
|
|
|
log.Println("example: cwtchutil vanity 4 passw0rd erinn openpriv") |
|
|
|
fmt.Println("example: cwtchutil vanity 4 passw0rd erinn openpriv") |
|
|
|
os.Exit(1) |
|
|
|
} |
|
|
|
|
|
|
|
goroutines, err := strconv.Atoi(os.Args[2]) |
|
|
|
if err != nil { |
|
|
|
log.Printf("first parameter after vanity should be a number\n") |
|
|
|
log.Errorf("first parameter after vanity should be a number\n") |
|
|
|
os.Exit(1) |
|
|
|
} |
|
|
|
log.Println("searching. press ctrl+c to stop") |
|
|
|
log.Infoln("searching. press ctrl+c to stop") |
|
|
|
for i := 0; i < goroutines; i++ { |
|
|
|
go vanity() |
|
|
|
} |
|
|
@ -157,14 +166,16 @@ func main() { |
|
|
|
} |
|
|
|
case "changepw": |
|
|
|
if len(os.Args) != 3 { |
|
|
|
log.Fatalf("example: cwtch changepw ~/.cwtch/profiles/XXX") |
|
|
|
fmt.Println("example: cwtch changepw ~/.cwtch/profiles/XXX") |
|
|
|
os.Exit(1) |
|
|
|
} |
|
|
|
|
|
|
|
fmt.Printf("old password: ") |
|
|
|
reader := bufio.NewReader(os.Stdin) |
|
|
|
pw, err := reader.ReadString('\n') |
|
|
|
if err != nil { |
|
|
|
log.Fatalf("%v", err) |
|
|
|
log.Errorln(err) |
|
|
|
os.Exit(1) |
|
|
|
} |
|
|
|
pw = pw[:len(pw)-1] |
|
|
|
|
|
|
@ -172,23 +183,25 @@ func main() { |
|
|
|
|
|
|
|
peer, err := fileStore.Load() |
|
|
|
if err != nil { |
|
|
|
log.Fatalf("%v", err) |
|
|
|
log.Errorln(err) |
|
|
|
os.Exit(1) |
|
|
|
} |
|
|
|
|
|
|
|
fmt.Printf("new password: ") |
|
|
|
newpw1, err := reader.ReadString('\n') |
|
|
|
if err != nil { |
|
|
|
log.Fatalf("%v", err) |
|
|
|
log.Errorln(err) |
|
|
|
os.Exit(1) |
|
|
|
} |
|
|
|
newpw1 = newpw1[:len(newpw1)-1] // fuck go with this linebreak shit ^ea
|
|
|
|
|
|
|
|
fileStore2 := storage2.CreateFileProfileStore(os.Args[2], newpw1) |
|
|
|
err = fileStore2.Save(peer) |
|
|
|
if err != nil { |
|
|
|
log.Fatalf("%v", err) |
|
|
|
log.Errorln(err) |
|
|
|
os.Exit(1) |
|
|
|
} |
|
|
|
|
|
|
|
log.Println("success!") |
|
|
|
|
|
|
|
log.Infoln("success!") |
|
|
|
} |
|
|
|
} |
|
|
|