forked from cwtch.im/cwtch
move server auto keygen to app/main
This commit is contained in:
parent
4b27e95c26
commit
aab5996971
|
@ -3,11 +3,33 @@ package main
|
||||||
import (
|
import (
|
||||||
cwtchserver "git.mascherari.press/cwtch/server"
|
cwtchserver "git.mascherari.press/cwtch/server"
|
||||||
"log"
|
"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() {
|
func main() {
|
||||||
|
checkAndGenPrivateKey(privateKeyFile)
|
||||||
|
|
||||||
server := new(cwtchserver.Server)
|
server := new(cwtchserver.Server)
|
||||||
log.Printf("starting cwtch server...")
|
log.Printf("starting cwtch server...")
|
||||||
|
|
||||||
server.Run("./private_key")
|
server.Run(privateKeyFile)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,6 @@ import (
|
||||||
"github.com/s-rah/go-ricochet/utils"
|
"github.com/s-rah/go-ricochet/utils"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"os"
|
|
||||||
"io/ioutil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
|
@ -20,16 +18,6 @@ type Server struct {
|
||||||
func (s *Server) Run(privateKeyFile string) {
|
func (s *Server) Run(privateKeyFile string) {
|
||||||
cwtchserver := new(application.RicochetApplication)
|
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)
|
pk, err := utils.LoadPrivateKeyFromFile(privateKeyFile)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue