Official cwtch.im peer and server implementations. https://cwtch.im
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
3.6KB

  1. package main
  2. import (
  3. "errors"
  4. "fmt"
  5. "git.openprivacy.ca/openprivacy/libricochet-go/log"
  6. "os"
  7. //"bufio"
  8. //"cwtch.im/cwtch/storage"
  9. )
  10. func convertTorFile(filename string, password string) error {
  11. return errors.New("this code doesn't work and can never work :( it's a math thing")
  12. /*name, _ := diceware.Generate(2)
  13. sk, err := ioutil.ReadFile("hs_ed25519_secret_key")
  14. if err != nil {
  15. return err
  16. }
  17. sk = sk[32:]
  18. pk, err := ioutil.ReadFile("hs_ed25519_public_key")
  19. if err != nil {
  20. return err
  21. }
  22. pk = pk[32:]
  23. onion, err := ioutil.ReadFile("hostname")
  24. if err != nil {
  25. return err
  26. }
  27. onion = onion[:56]
  28. peer := libpeer.NewCwtchPeer(strings.Join(name, "-"))
  29. fmt.Printf("%d %d %s\n", len(peer.GetProfile().Ed25519PublicKey), len(peer.GetProfile().Ed25519PrivateKey), peer.GetProfile().Onion)
  30. peer.GetProfile().Ed25519PrivateKey = sk
  31. peer.GetProfile().Ed25519PublicKey = pk
  32. peer.GetProfile().Onion = string(onion)
  33. fileStore := storage2.NewFileStore(filename, password)
  34. err = fileStore.save(peer)
  35. if err != nil {
  36. return err
  37. }
  38. log.Infof("success! loaded %d byte pk and %d byte sk for %s.onion\n", len(pk), len(sk), onion)
  39. return nil*/
  40. }
  41. /*
  42. func vanity() error {
  43. for {
  44. pk, sk, err := ed25519.GenerateKey(rand.Reader)
  45. if err != nil {
  46. continue
  47. }
  48. onion := utils.GetTorV3Hostname(pk)
  49. for i := 4; i < len(os.Args); i++ {
  50. if strings.HasPrefix(onion, os.Args[i]) {
  51. peer := libpeer.NewCwtchPeer(os.Args[i])
  52. peer.GetProfile().Ed25519PrivateKey = sk
  53. peer.GetProfile().Ed25519PublicKey = pk
  54. peer.GetProfile().Onion = onion
  55. profileStore, _ := storage2.NewProfileStore(nil, os.Args[3], onion+".cwtch")
  56. profileStore.Init("")
  57. // need to signal new onion? impossible
  58. log.Infof("found %s.onion\n", onion)
  59. }
  60. }
  61. }
  62. }*/
  63. func printHelp() {
  64. log.Infoln("usage: cwtchutil {help, convert-cwtch-file, convert-tor-file, changepw, vanity}")
  65. }
  66. func main() {
  67. log.SetLevel(log.LevelInfo)
  68. if len(os.Args) < 2 {
  69. printHelp()
  70. os.Exit(1)
  71. }
  72. switch os.Args[1] {
  73. default:
  74. printHelp()
  75. case "help":
  76. printHelp()
  77. case "convert-tor-file":
  78. if len(os.Args) != 4 {
  79. fmt.Println("example: cwtchutil convert-tor-file /var/lib/tor/hs1 passw0rd")
  80. os.Exit(1)
  81. }
  82. err := convertTorFile(os.Args[2], os.Args[3])
  83. if err != nil {
  84. log.Errorln(err)
  85. }
  86. /*case "vanity":
  87. if len(os.Args) < 5 {
  88. fmt.Println("example: cwtchutil vanity 4 passw0rd erinn openpriv")
  89. os.Exit(1)
  90. }
  91. goroutines, err := strconv.Atoi(os.Args[2])
  92. if err != nil {
  93. log.Errorf("first parameter after vanity should be a number\n")
  94. os.Exit(1)
  95. }
  96. log.Infoln("searching. press ctrl+c to stop")
  97. for i := 0; i < goroutines; i++ {
  98. go vanity()
  99. }
  100. for { // run until ctrl+c
  101. time.Sleep(time.Hour * 24)
  102. }*/
  103. /*case "changepw":
  104. if len(os.Args) != 3 {
  105. fmt.Println("example: cwtch changepw ~/.cwtch/profiles/XXX")
  106. os.Exit(1)
  107. }
  108. fmt.Printf("old password: ")
  109. reader := bufio.NewReader(os.Stdin)
  110. pw, err := reader.ReadString('\n')
  111. if err != nil {
  112. log.Errorln(err)
  113. os.Exit(1)
  114. }
  115. pw = pw[:len(pw)-1]
  116. profileStore, _ := storage.NewProfileStore(nil, os.Args[2], pw)
  117. err = profileStore.Read()
  118. if err != nil {
  119. log.Errorln(err)
  120. os.Exit(1)
  121. }
  122. fmt.Printf("new password: ")
  123. newpw1, err := reader.ReadString('\n')
  124. if err != nil {
  125. log.Errorln(err)
  126. os.Exit(1)
  127. }
  128. newpw1 = newpw1[:len(newpw1)-1] // fuck go with this linebreak shit ^ea
  129. fileStore2, _ := storage.NewProfileStore(nil, os.Args[2], newpw1)
  130. // No way to copy, populate this method
  131. err = fileStore2.save(peer)
  132. if err != nil {
  133. log.Errorln(err)
  134. os.Exit(1)
  135. }
  136. log.Infoln("success!")
  137. */
  138. }
  139. }