cwtch/app/cwtchutil/main.go

160 lines
3.6 KiB
Go
Raw Normal View History

2018-10-15 00:59:53 +00:00
package main
import (
2018-12-04 02:52:11 +00:00
"errors"
2019-01-21 20:11:40 +00:00
"fmt"
"git.openprivacy.ca/openprivacy/log"
2018-10-15 00:59:53 +00:00
"os"
2019-01-21 20:11:40 +00:00
//"bufio"
//"cwtch.im/cwtch/storage"
2018-10-15 00:59:53 +00:00
)
2018-12-04 02:52:11 +00:00
func convertTorFile(filename string, password string) error {
return errors.New("this code doesn't work and can never work :( it's a math thing")
2018-10-15 00:59:53 +00:00
2018-12-04 02:52:11 +00:00
/*name, _ := diceware.Generate(2)
2018-10-15 00:59:53 +00:00
sk, err := ioutil.ReadFile("hs_ed25519_secret_key")
if err != nil {
2018-12-04 02:52:11 +00:00
return err
2018-10-15 00:59:53 +00:00
}
sk = sk[32:]
pk, err := ioutil.ReadFile("hs_ed25519_public_key")
if err != nil {
2018-12-04 02:52:11 +00:00
return err
2018-10-15 00:59:53 +00:00
}
pk = pk[32:]
onion, err := ioutil.ReadFile("hostname")
if err != nil {
2018-12-04 02:52:11 +00:00
return err
2018-10-15 00:59:53 +00:00
}
onion = onion[:56]
2018-10-06 03:50:55 +00:00
peer := libpeer.NewCwtchPeer(strings.Join(name, "-"))
2018-10-15 00:59:53 +00:00
fmt.Printf("%d %d %s\n", len(peer.GetProfile().Ed25519PublicKey), len(peer.GetProfile().Ed25519PrivateKey), peer.GetProfile().Onion)
peer.GetProfile().Ed25519PrivateKey = sk
peer.GetProfile().Ed25519PublicKey = pk
peer.GetProfile().Onion = string(onion)
fileStore := storage2.NewFileStore(filename, password)
err = fileStore.save(peer)
2018-10-06 03:50:55 +00:00
if err != nil {
2018-12-04 02:52:11 +00:00
return err
2018-10-06 03:50:55 +00:00
}
2018-10-15 00:59:53 +00:00
2018-12-04 02:52:11 +00:00
log.Infof("success! loaded %d byte pk and %d byte sk for %s.onion\n", len(pk), len(sk), onion)
return nil*/
2018-10-15 00:59:53 +00:00
}
2019-01-21 20:11:40 +00:00
/*
2018-12-04 02:52:11 +00:00
func vanity() error {
2018-10-15 00:59:53 +00:00
for {
pk, sk, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
continue
}
onion := utils.GetTorV3Hostname(pk)
for i := 4; i < len(os.Args); i++ {
if strings.HasPrefix(onion, os.Args[i]) {
2018-10-06 03:50:55 +00:00
peer := libpeer.NewCwtchPeer(os.Args[i])
2018-10-15 00:59:53 +00:00
peer.GetProfile().Ed25519PrivateKey = sk
peer.GetProfile().Ed25519PublicKey = pk
peer.GetProfile().Onion = onion
2019-01-21 20:11:40 +00:00
profileStore, _ := storage2.NewProfileStore(nil, os.Args[3], onion+".cwtch")
profileStore.Init("")
// need to signal new onion? impossible
2018-12-04 02:52:11 +00:00
log.Infof("found %s.onion\n", onion)
2018-10-15 00:59:53 +00:00
}
}
}
2019-01-21 20:11:40 +00:00
}*/
2018-10-15 00:59:53 +00:00
func printHelp() {
2018-12-04 02:52:11 +00:00
log.Infoln("usage: cwtchutil {help, convert-cwtch-file, convert-tor-file, changepw, vanity}")
2018-10-15 00:59:53 +00:00
}
func main() {
2018-12-04 02:52:11 +00:00
log.SetLevel(log.LevelInfo)
2018-10-15 00:59:53 +00:00
if len(os.Args) < 2 {
printHelp()
os.Exit(1)
}
switch os.Args[1] {
default:
printHelp()
case "help":
printHelp()
case "convert-tor-file":
if len(os.Args) != 4 {
2018-12-04 02:52:11 +00:00
fmt.Println("example: cwtchutil convert-tor-file /var/lib/tor/hs1 passw0rd")
2018-10-15 00:59:53 +00:00
os.Exit(1)
}
2018-12-04 02:52:11 +00:00
err := convertTorFile(os.Args[2], os.Args[3])
if err != nil {
log.Errorln(err)
}
2019-01-21 20:11:40 +00:00
/*case "vanity":
2018-10-15 00:59:53 +00:00
if len(os.Args) < 5 {
2018-12-04 02:52:11 +00:00
fmt.Println("example: cwtchutil vanity 4 passw0rd erinn openpriv")
2018-10-15 00:59:53 +00:00
os.Exit(1)
}
goroutines, err := strconv.Atoi(os.Args[2])
if err != nil {
2018-12-04 02:52:11 +00:00
log.Errorf("first parameter after vanity should be a number\n")
2018-10-15 00:59:53 +00:00
os.Exit(1)
}
2018-12-04 02:52:11 +00:00
log.Infoln("searching. press ctrl+c to stop")
2018-10-15 00:59:53 +00:00
for i := 0; i < goroutines; i++ {
go vanity()
}
for { // run until ctrl+c
time.Sleep(time.Hour * 24)
2019-01-21 20:11:40 +00:00
}*/
/*case "changepw":
2018-10-15 00:59:53 +00:00
if len(os.Args) != 3 {
2018-12-04 02:52:11 +00:00
fmt.Println("example: cwtch changepw ~/.cwtch/profiles/XXX")
os.Exit(1)
2018-10-15 00:59:53 +00:00
}
fmt.Printf("old password: ")
reader := bufio.NewReader(os.Stdin)
pw, err := reader.ReadString('\n')
if err != nil {
2018-12-04 02:52:11 +00:00
log.Errorln(err)
os.Exit(1)
2018-10-15 00:59:53 +00:00
}
pw = pw[:len(pw)-1]
2019-01-21 20:11:40 +00:00
profileStore, _ := storage.NewProfileStore(nil, os.Args[2], pw)
2018-10-06 03:50:55 +00:00
err = profileStore.Read()
2018-10-15 00:59:53 +00:00
if err != nil {
2018-12-04 02:52:11 +00:00
log.Errorln(err)
os.Exit(1)
2018-10-15 00:59:53 +00:00
}
fmt.Printf("new password: ")
newpw1, err := reader.ReadString('\n')
if err != nil {
2018-12-04 02:52:11 +00:00
log.Errorln(err)
os.Exit(1)
2018-10-15 00:59:53 +00:00
}
newpw1 = newpw1[:len(newpw1)-1] // fuck go with this linebreak shit ^ea
2019-01-21 20:11:40 +00:00
fileStore2, _ := storage.NewProfileStore(nil, os.Args[2], newpw1)
// No way to copy, populate this method
err = fileStore2.save(peer)
2018-10-15 00:59:53 +00:00
if err != nil {
2018-12-04 02:52:11 +00:00
log.Errorln(err)
os.Exit(1)
2018-10-15 00:59:53 +00:00
}
2018-12-04 02:52:11 +00:00
log.Infoln("success!")
2019-01-21 20:11:40 +00:00
*/
2018-10-15 00:59:53 +00:00
}
}