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:
parent
e0f0c4db18
commit
481055d5cf
3 changed files with 12 additions and 28 deletions
|
@ -33,7 +33,6 @@ func newCentralAuth(configuration *Configuration, errorKernel *errorKernel) *cen
|
||||||
databaseFilepath := filepath.Join(configuration.DatabaseFolder, "auth.db")
|
databaseFilepath := filepath.Join(configuration.DatabaseFolder, "auth.db")
|
||||||
|
|
||||||
// Open the database file for persistent storage of public keys.
|
// Open the database file for persistent storage of public keys.
|
||||||
|
|
||||||
db, err := bolt.Open(databaseFilepath, 0600, nil)
|
db, err := bolt.Open(databaseFilepath, 0600, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error: failed to open db: %v\n", err)
|
log.Printf("error: failed to open db: %v\n", err)
|
||||||
|
@ -42,13 +41,19 @@ func newCentralAuth(configuration *Configuration, errorKernel *errorKernel) *cen
|
||||||
|
|
||||||
c.db = db
|
c.db = db
|
||||||
|
|
||||||
|
// Get public keys from db storage.
|
||||||
keys, err := c.dbDumpPublicKey()
|
keys, err := c.dbDumpPublicKey()
|
||||||
if err != nil {
|
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
|
// Only assign from storage to in memory map if the storage contained any values.
|
||||||
fmt.Printf(" * keyDump: %v\n ", keys)
|
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
|
return &c
|
||||||
}
|
}
|
||||||
|
@ -75,12 +80,12 @@ func (c *centralAuth) addPublicKey(proc process, msg Message) {
|
||||||
c.dbUpdatePublicKey(string(msg.FromNode), msg.Data)
|
c.dbUpdatePublicKey(string(msg.FromNode), msg.Data)
|
||||||
|
|
||||||
if ok {
|
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)
|
fmt.Printf(" * %v\n", er)
|
||||||
c.errorKernel.infoSend(proc, msg, er)
|
c.errorKernel.infoSend(proc, msg, er)
|
||||||
}
|
}
|
||||||
if !ok {
|
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)
|
fmt.Printf(" * %v\n", er)
|
||||||
c.errorKernel.infoSend(proc, msg, er)
|
c.errorKernel.infoSend(proc, msg, er)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ package steward
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -266,7 +266,7 @@ func (s startup) pubREQHello(p process) {
|
||||||
for {
|
for {
|
||||||
|
|
||||||
// d := fmt.Sprintf("Hello from %v\n", p.node)
|
// d := fmt.Sprintf("Hello from %v\n", p.node)
|
||||||
d := proc.configuration.NkeyPublicKey
|
d := s.server.signatures.SignPublicKey
|
||||||
|
|
||||||
m := Message{
|
m := Message{
|
||||||
FileName: "hello.log",
|
FileName: "hello.log",
|
||||||
|
|
Loading…
Add table
Reference in a new issue