forked from cwtch.im/cwtch
only generate private key if keyfile is missing, not on other errors: possible corrupt and loss
This commit is contained in:
parent
a1f0ee7b9f
commit
4b27e95c26
|
@ -1,7 +1,6 @@
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
//"crypto/rsa"
|
|
||||||
"git.mascherari.press/cwtch/server/fetch"
|
"git.mascherari.press/cwtch/server/fetch"
|
||||||
"git.mascherari.press/cwtch/server/listen"
|
"git.mascherari.press/cwtch/server/listen"
|
||||||
"git.mascherari.press/cwtch/server/send"
|
"git.mascherari.press/cwtch/server/send"
|
||||||
|
@ -11,6 +10,7 @@ import (
|
||||||
"github.com/s-rah/go-ricochet/utils"
|
"github.com/s-rah/go-ricochet/utils"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
|
"os"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -19,19 +19,23 @@ type Server struct {
|
||||||
|
|
||||||
func (s *Server) Run(privateKeyFile string) {
|
func (s *Server) Run(privateKeyFile string) {
|
||||||
cwtchserver := new(application.RicochetApplication)
|
cwtchserver := new(application.RicochetApplication)
|
||||||
pk, err := utils.LoadPrivateKeyFromFile(privateKeyFile)
|
|
||||||
|
|
||||||
if err != nil {
|
if _, err := os.Stat(privateKeyFile); os.IsNotExist(err) {
|
||||||
log.Printf("no private key found!")
|
log.Printf("no private key found!")
|
||||||
log.Printf("generating new private key...")
|
log.Printf("generating new private key...")
|
||||||
var pk_err error = nil
|
pk, pk_err := utils.GeneratePrivateKey()
|
||||||
pk, pk_err = utils.GeneratePrivateKey()
|
|
||||||
if pk_err != nil {
|
if pk_err != nil {
|
||||||
log.Fatalf("error generating new private key: %v", err)
|
log.Fatalf("error generating new private key: %v", err)
|
||||||
}
|
}
|
||||||
ioutil.WriteFile(privateKeyFile, []byte(utils.PrivateKeyToString(pk)), 0400)
|
ioutil.WriteFile(privateKeyFile, []byte(utils.PrivateKeyToString(pk)), 0400)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pk, err := utils.LoadPrivateKeyFromFile(privateKeyFile)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("error reading private key file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
l, err := application.SetupOnion("127.0.0.1:9051", "tcp4", "", pk, 9878)
|
l, err := application.SetupOnion("127.0.0.1:9051", "tcp4", "", pk, 9878)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue