forked from cwtch.im/cwtch
Merge branch 'autogen-missing-key' of dan/cwtch into master
This commit is contained in:
commit
e01a4b2018
|
@ -3,11 +3,33 @@ package main
|
|||
import (
|
||||
cwtchserver "git.mascherari.press/cwtch/server"
|
||||
"log"
|
||||
"os"
|
||||
"github.com/s-rah/go-ricochet/utils"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
const privateKeyFile = "./private_key"
|
||||
|
||||
func checkAndGenPrivateKey(privateKeyFile string) {
|
||||
if _, err := os.Stat(privateKeyFile); os.IsNotExist(err) {
|
||||
log.Printf("no private key found!")
|
||||
log.Printf("generating new private key...")
|
||||
pk, pk_err := utils.GeneratePrivateKey()
|
||||
if pk_err != nil {
|
||||
log.Fatalf("error generating new private key: %v\n", err)
|
||||
}
|
||||
err := ioutil.WriteFile(privateKeyFile, []byte(utils.PrivateKeyToString(pk)), 0400)
|
||||
if err != nil {
|
||||
log.Fatalf("error writing new private key to file %s: %v\n", privateKeyFile, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
checkAndGenPrivateKey(privateKeyFile)
|
||||
|
||||
server := new(cwtchserver.Server)
|
||||
log.Printf("starting cwtch server...")
|
||||
|
||||
server.Run("./private_key")
|
||||
server.Run(privateKeyFile)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
//"crypto/rsa"
|
||||
"git.mascherari.press/cwtch/server/fetch"
|
||||
"git.mascherari.press/cwtch/server/listen"
|
||||
"git.mascherari.press/cwtch/server/send"
|
||||
|
@ -10,7 +9,7 @@ import (
|
|||
"github.com/s-rah/go-ricochet/channels"
|
||||
"github.com/s-rah/go-ricochet/utils"
|
||||
"log"
|
||||
//"time"
|
||||
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
|
@ -18,6 +17,7 @@ type Server struct {
|
|||
|
||||
func (s *Server) Run(privateKeyFile string) {
|
||||
cwtchserver := new(application.RicochetApplication)
|
||||
|
||||
pk, err := utils.LoadPrivateKeyFromFile(privateKeyFile)
|
||||
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue