mirror of
https://github.com/mitchell/selfpass.git
synced 2025-12-14 05:17:22 +00:00
Major refactor of config encryption strategy
This commit is contained in:
parent
e404a7ab31
commit
cde1d118fc
10 changed files with 91 additions and 101 deletions
|
|
@ -9,7 +9,6 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/mitchell/selfpass/cli/types"
|
||||
"github.com/mitchell/selfpass/credentials/commands"
|
||||
"github.com/mitchell/selfpass/crypto"
|
||||
)
|
||||
|
||||
|
|
@ -35,7 +34,7 @@ the new file.`,
|
|||
contents, err := ioutil.ReadFile(file)
|
||||
check(err)
|
||||
|
||||
key, err := hex.DecodeString(cfg.GetString(commands.KeyPrivateKey))
|
||||
key, err := hex.DecodeString(cfg.GetString(types.KeyPrivateKey))
|
||||
check(err)
|
||||
|
||||
passkey, err := crypto.CombinePasswordAndKey([]byte(masterpass), []byte(key))
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/mitchell/selfpass/cli/types"
|
||||
|
|
@ -16,7 +18,9 @@ func makeDecryptCfg(repo types.ConfigRepo) *cobra.Command {
|
|||
_, _, err := repo.OpenConfig()
|
||||
check(err)
|
||||
|
||||
repo.DecryptConfig()
|
||||
check(repo.DecryptConfig())
|
||||
|
||||
fmt.Println("Config decrypted. It will automatically encrypt next run of spc.")
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/mitchell/selfpass/cli/types"
|
||||
"github.com/mitchell/selfpass/credentials/commands"
|
||||
"github.com/mitchell/selfpass/crypto"
|
||||
)
|
||||
|
||||
|
|
@ -31,7 +30,7 @@ new file.`,
|
|||
contents, err := ioutil.ReadFile(file)
|
||||
check(err)
|
||||
|
||||
key, err := hex.DecodeString(cfg.GetString(commands.KeyPrivateKey))
|
||||
key, err := hex.DecodeString(cfg.GetString(types.KeyPrivateKey))
|
||||
check(err)
|
||||
|
||||
passkey, err := crypto.CombinePasswordAndKey([]byte(masterpass), []byte(key))
|
||||
|
|
|
|||
|
|
@ -6,12 +6,10 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/mitchellh/go-homedir"
|
||||
"github.com/spf13/cobra"
|
||||
"gopkg.in/AlecAivazis/survey.v1"
|
||||
|
||||
"github.com/mitchell/selfpass/cli/types"
|
||||
"github.com/mitchell/selfpass/credentials/commands"
|
||||
)
|
||||
|
||||
func makeInit(repo types.ConfigRepo) *cobra.Command {
|
||||
|
|
@ -72,23 +70,16 @@ the users private key, and server certificates. (All of which will be encrypted)
|
|||
key, err := ioutil.ReadFile(keyFile)
|
||||
check(err)
|
||||
|
||||
cfg.Set(keyConnConfig, map[string]string{
|
||||
cfg.Set(types.KeyConnConfig, map[string]string{
|
||||
"target": target,
|
||||
"ca": string(ca),
|
||||
"cert": string(cert),
|
||||
"key": string(key),
|
||||
})
|
||||
|
||||
cfg.Set(commands.KeyPrivateKey, privateKey)
|
||||
cfg.Set(types.KeyPrivateKey, privateKey)
|
||||
|
||||
if err := cfg.WriteConfig(); err != nil {
|
||||
home, err := homedir.Dir()
|
||||
check(err)
|
||||
|
||||
check(cfg.WriteConfigAs(home + "/.spc.toml"))
|
||||
cfg.SetConfigFile(home + "/.spc.toml")
|
||||
fmt.Println("Wrote new config to: " + home + "/.spc.toml")
|
||||
}
|
||||
check(repo.WriteConfig())
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,8 +26,6 @@ can interact with the entire Selfpass API.`,
|
|||
cfgFile := rootCmd.PersistentFlags().String("config", "", "config file (default is $HOME/.spc.toml)")
|
||||
|
||||
mgr := repositories.NewConfigManager(cfgFile)
|
||||
defer mgr.CloseConfig()
|
||||
|
||||
clientInit := credrepos.NewCredentialServiceClient
|
||||
|
||||
rootCmd.AddCommand(makeInit(mgr))
|
||||
|
|
@ -47,7 +45,7 @@ func makeInitClient(repo types.ConfigRepo, initClient credtypes.CredentialClient
|
|||
_, cfg, err := repo.OpenConfig()
|
||||
check(err)
|
||||
|
||||
connConfig := cfg.GetStringMapString(keyConnConfig)
|
||||
connConfig := cfg.GetStringMapString(types.KeyConnConfig)
|
||||
|
||||
client, err := initClient(
|
||||
ctx,
|
||||
|
|
@ -68,5 +66,3 @@ func check(err error) {
|
|||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
const keyConnConfig = "connection"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue