1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2025-01-18 21:59:30 +00:00

reading correct key

This commit is contained in:
postmannen 2022-04-05 12:02:45 +02:00
parent e0f0c4db18
commit 481055d5cf
3 changed files with 12 additions and 28 deletions

View file

@ -33,7 +33,6 @@ func newCentralAuth(configuration *Configuration, errorKernel *errorKernel) *cen
databaseFilepath := filepath.Join(configuration.DatabaseFolder, "auth.db")
// Open the database file for persistent storage of public keys.
db, err := bolt.Open(databaseFilepath, 0600, nil)
if err != nil {
log.Printf("error: failed to open db: %v\n", err)
@ -42,13 +41,19 @@ func newCentralAuth(configuration *Configuration, errorKernel *errorKernel) *cen
c.db = db
// Get public keys from db storage.
keys, err := c.dbDumpPublicKey()
if err != nil {
fmt.Printf(" * DEBUG: dbPublicKeyDump failed: %v\n", err)
log.Printf("debug: dbPublicKeyDump failed, probably empty db: %v\n", err)
}
c.nodePublicKeys.keyMap = keys
fmt.Printf(" * keyDump: %v\n ", keys)
// Only assign from storage to in memory map if the storage contained any values.
if keys != nil {
c.nodePublicKeys.keyMap = keys
for k, v := range keys {
log.Printf("info: public keys db contains: %v, %v\n", k, []byte(v))
}
}
return &c
}
@ -75,12 +80,12 @@ func (c *centralAuth) addPublicKey(proc process, msg Message) {
c.dbUpdatePublicKey(string(msg.FromNode), msg.Data)
if ok {
er := fmt.Errorf("updated public key for node: %v", msg.FromNode)
er := fmt.Errorf("info: updated public key for node: %v", msg.FromNode)
fmt.Printf(" * %v\n", er)
c.errorKernel.infoSend(proc, msg, er)
}
if !ok {
er := fmt.Errorf("added new node with public key: %v", msg.FromNode)
er := fmt.Errorf("info: added new node with public key: %v", msg.FromNode)
fmt.Printf(" * %v\n", er)
c.errorKernel.infoSend(proc, msg, er)
}

View file

@ -3,7 +3,6 @@ package steward
import (
"flag"
"fmt"
"io"
"log"
"os"
"path/filepath"
@ -607,26 +606,6 @@ func (c *Configuration) CheckFlags() error {
}
// Get the nkey user file content.
if c.NkeySeedFile != "" {
userFileDir := filepath.Dir(c.NkeySeedFile)
userFile := filepath.Join(userFileDir, "user.txt")
uFh, err := os.Open(userFile)
if err != nil {
log.Printf("error: unable to open %v file: %v\n", userFile, err)
os.Exit(1)
}
userFileContent, err := io.ReadAll(uFh)
if err != nil {
log.Printf("error: unable to read %v file: %v\n", userFile, err)
os.Exit(1)
}
c.NkeyPublicKey = string(userFileContent)
}
return nil
}

View file

@ -266,7 +266,7 @@ func (s startup) pubREQHello(p process) {
for {
// d := fmt.Sprintf("Hello from %v\n", p.node)
d := proc.configuration.NkeyPublicKey
d := s.server.signatures.SignPublicKey
m := Message{
FileName: "hello.log",