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 (
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"
|
||||||
|
@ -10,7 +9,7 @@ import (
|
||||||
"github.com/s-rah/go-ricochet/channels"
|
"github.com/s-rah/go-ricochet/channels"
|
||||||
"github.com/s-rah/go-ricochet/utils"
|
"github.com/s-rah/go-ricochet/utils"
|
||||||
"log"
|
"log"
|
||||||
//"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
|
@ -18,6 +17,7 @@ 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)
|
pk, err := utils.LoadPrivateKeyFromFile(privateKeyFile)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue