Generate encryption keys in configured directory
This makes --gen-keys respect the keys_parent_dir config value
This commit is contained in:
parent
1c40103fbf
commit
5de193a64d
16
app.go
16
app.go
|
@ -256,6 +256,21 @@ func Serve() {
|
||||||
} else if *genKeys {
|
} else if *genKeys {
|
||||||
errStatus := 0
|
errStatus := 0
|
||||||
|
|
||||||
|
// Read keys path from config
|
||||||
|
loadConfig(app)
|
||||||
|
|
||||||
|
// Create keys dir if it doesn't exist yet
|
||||||
|
fullKeysDir := filepath.Join(app.cfg.Server.KeysParentDir, keysDir)
|
||||||
|
if _, err := os.Stat(fullKeysDir); os.IsNotExist(err) {
|
||||||
|
err = os.Mkdir(fullKeysDir, 0700)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("%s", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate keys
|
||||||
|
initKeyPaths(app)
|
||||||
err := generateKey(emailKeyPath)
|
err := generateKey(emailKeyPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errStatus = 1
|
errStatus = 1
|
||||||
|
@ -345,6 +360,7 @@ func Serve() {
|
||||||
|
|
||||||
// Load keys
|
// Load keys
|
||||||
log.Info("Loading encryption keys...")
|
log.Info("Loading encryption keys...")
|
||||||
|
initKeyPaths(app)
|
||||||
err = initKeys(app)
|
err = initKeys(app)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("\n%s\n", err)
|
log.Error("\n%s\n", err)
|
||||||
|
|
9
keys.go
9
keys.go
|
@ -34,11 +34,16 @@ type keychain struct {
|
||||||
emailKey, cookieAuthKey, cookieKey []byte
|
emailKey, cookieAuthKey, cookieKey []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func initKeyPaths(app *app) {
|
||||||
|
emailKeyPath = filepath.Join(app.cfg.Server.KeysParentDir, emailKeyPath)
|
||||||
|
cookieAuthKeyPath = filepath.Join(app.cfg.Server.KeysParentDir, cookieAuthKeyPath)
|
||||||
|
cookieKeyPath = filepath.Join(app.cfg.Server.KeysParentDir, cookieKeyPath)
|
||||||
|
}
|
||||||
|
|
||||||
func initKeys(app *app) error {
|
func initKeys(app *app) error {
|
||||||
var err error
|
var err error
|
||||||
app.keys = &keychain{}
|
app.keys = &keychain{}
|
||||||
|
|
||||||
emailKeyPath = filepath.Join(app.cfg.Server.KeysParentDir, emailKeyPath)
|
|
||||||
if debugging {
|
if debugging {
|
||||||
log.Info(" %s", emailKeyPath)
|
log.Info(" %s", emailKeyPath)
|
||||||
}
|
}
|
||||||
|
@ -47,7 +52,6 @@ func initKeys(app *app) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
cookieAuthKeyPath = filepath.Join(app.cfg.Server.KeysParentDir, cookieAuthKeyPath)
|
|
||||||
if debugging {
|
if debugging {
|
||||||
log.Info(" %s", cookieAuthKeyPath)
|
log.Info(" %s", cookieAuthKeyPath)
|
||||||
}
|
}
|
||||||
|
@ -56,7 +60,6 @@ func initKeys(app *app) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
cookieKeyPath = filepath.Join(app.cfg.Server.KeysParentDir, cookieKeyPath)
|
|
||||||
if debugging {
|
if debugging {
|
||||||
log.Info(" %s", cookieKeyPath)
|
log.Info(" %s", cookieKeyPath)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue