forked from cwtch.im/cwtch
move server auto keygen to app/main
This commit is contained in:
parent
fffe18344e
commit
13eaa3a684
|
@ -11,14 +11,14 @@ import (
|
|||
const privateKeyFile = "./private_key"
|
||||
|
||||
func checkAndGenPrivateKey(privateKeyFile string) {
|
||||
if _, err := os.Stat(privateKeyFile); os.IsNotExist(err) {
|
||||
if _, err := os.Stat(privateKeyFile); os.IsNotExist(err) {
|
||||
log.Printf("no private key found!")
|
||||
log.Printf("generating new private key...")
|
||||
pk, err := utils.GeneratePrivateKey()
|
||||
if err != nil {
|
||||
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)
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -9,8 +9,6 @@ import (
|
|||
"github.com/s-rah/go-ricochet/channels"
|
||||
"github.com/s-rah/go-ricochet/utils"
|
||||
"log"
|
||||
"os"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
// Server encapsulates a complete, compliant Cwtch server.
|
||||
|
@ -23,16 +21,6 @@ type Server struct {
|
|||
func (s *Server) Run(privateKeyFile string) {
|
||||
cwtchserver := new(application.RicochetApplication)
|
||||
|
||||
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", err)
|
||||
}
|
||||
ioutil.WriteFile(privateKeyFile, []byte(utils.PrivateKeyToString(pk)), 0400)
|
||||
}
|
||||
|
||||
pk, err := utils.LoadPrivateKeyFromFile(privateKeyFile)
|
||||
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue