Change update/create to give 2 OTP codes; minor rename

This commit is contained in:
mitchell 2019-08-12 14:51:39 -04:00
parent 2c50106082
commit 7a0ef6b71d
10 changed files with 37 additions and 17 deletions

View File

@ -13,7 +13,7 @@ import (
"github.com/mitchell/selfpass/services/credentials/types"
)
type CredentialsClientInit func(ctx context.Context) (c types.CredentialsClient)
type credentialsClientInit func(ctx context.Context) (c types.CredentialsClient)
var errSourceNotFound = errors.New("source host not found")

View File

@ -17,7 +17,7 @@ import (
clitypes "github.com/mitchell/selfpass/sp/types"
)
func makeCreate(repo clitypes.ConfigRepo, initClient CredentialsClientInit) *cobra.Command {
func makeCreate(repo clitypes.ConfigRepo, initClient credentialsClientInit) *cobra.Command {
flags := credentialFlagSet{}.withPasswordFlags()
createCmd := &cobra.Command{
@ -32,6 +32,7 @@ password.`,
cleancb bool
newpass bool
ci types.CredentialInput
prompt survey.Prompt
)
masterpass, cfg, err := repo.OpenConfig()
@ -71,7 +72,7 @@ password.`,
key := cfg.GetString(clitypes.KeyPrivateKey)
keypass := crypto.GeneratePBKDF2Key([]byte(masterpass), []byte(key))
prompt := &survey.Confirm{Message: "Do you want a random password?", Default: true}
prompt = &survey.Confirm{Message: "Do you want a random password?", Default: true}
check(survey.AskOne(prompt, &newpass, nil))
if newpass {
@ -108,7 +109,7 @@ password.`,
if otp {
var secret string
prompt := &survey.Password{Message: "OTP secret:"}
prompt = &survey.Password{Message: "OTP secret:"}
check(survey.AskOne(prompt, &secret, nil))
ciphersecret, err := crypto.CBCEncrypt(keypass, []byte(secret))
@ -117,14 +118,24 @@ password.`,
ci.OTPSecret = base64.StdEncoding.EncodeToString(ciphersecret)
var copyotp bool
prompt2 := &survey.Confirm{Message: "Copy new OTP to clipboard?", Default: true}
check(survey.AskOne(prompt2, &copyotp, nil))
prompt = &survey.Confirm{Message: "Copy new OTP to clipboard?", Default: true}
check(survey.AskOne(prompt, &copyotp, nil))
if copyotp {
otp, err := totp.GenerateCode(secret, time.Now())
check(err)
check(clipboard.WriteAll(otp))
prompt = &survey.Confirm{Message: "Anotha one?", Default: true}
check(survey.AskOne(prompt, &copyotp, nil))
if copyotp {
otp, err := totp.GenerateCode(secret, time.Now().Add(time.Second*30))
check(err)
check(clipboard.WriteAll(otp))
}
}
}

View File

@ -9,7 +9,7 @@ import (
"gopkg.in/AlecAivazis/survey.v1"
)
func makeDelete(initClient CredentialsClientInit) *cobra.Command {
func makeDelete(initClient credentialsClientInit) *cobra.Command {
flags := credentialFlagSet{}.withHostFlag()
deleteCmd := &cobra.Command{

View File

@ -14,7 +14,7 @@ import (
clitypes "github.com/mitchell/selfpass/sp/types"
)
func makeGCMToCBC(repo clitypes.ConfigRepo, initClient CredentialsClientInit) *cobra.Command {
func makeGCMToCBC(repo clitypes.ConfigRepo, initClient credentialsClientInit) *cobra.Command {
gcmToCBC := &cobra.Command{
Use: "gcm-to-cbc",
Hidden: true,

View File

@ -15,7 +15,7 @@ import (
clitypes "github.com/mitchell/selfpass/sp/types"
)
func makeGet(repo clitypes.ConfigRepo, initClient CredentialsClientInit) *cobra.Command {
func makeGet(repo clitypes.ConfigRepo, initClient credentialsClientInit) *cobra.Command {
flags := credentialFlagSet{}.withHostFlag()
getCmd := &cobra.Command{

View File

@ -11,7 +11,7 @@ import (
"github.com/mitchell/selfpass/services/credentials/types"
)
func makeList(initClient CredentialsClientInit) *cobra.Command {
func makeList(initClient credentialsClientInit) *cobra.Command {
flags := credentialFlagSet{}.withHostFlag()
listCmd := &cobra.Command{

View File

@ -11,6 +11,7 @@ import (
"github.com/mitchell/selfpass/sp/types"
)
// Execute is the main entrypoint for the `sp` CLI tool.
func Execute() {
rootCmd := &cobra.Command{
Use: "sp",
@ -41,7 +42,7 @@ can interact with the entire Selfpass API.`,
check(rootCmd.Execute())
}
func makeInitClient(repo types.ConfigRepo, initClient credtypes.CredentialsClientInit) CredentialsClientInit {
func makeInitClient(repo types.ConfigRepo, initClient credtypes.CredentialsClientInit) credentialsClientInit {
return func(ctx context.Context) credtypes.CredentialsClient {
_, cfg, err := repo.OpenConfig()
check(err)

View File

@ -17,7 +17,7 @@ import (
clitypes "github.com/mitchell/selfpass/sp/types"
)
func makeUpdate(repo clitypes.ConfigRepo, initClient CredentialsClientInit) *cobra.Command {
func makeUpdate(repo clitypes.ConfigRepo, initClient credentialsClientInit) *cobra.Command {
flags := credentialFlagSet{}.withHostFlag().withPasswordFlags()
updateCmd := &cobra.Command{
@ -143,7 +143,7 @@ password.`,
if otp {
var secret string
prompt := &survey.Password{Message: "OTP secret:"}
prompt = &survey.Password{Message: "OTP secret:"}
check(survey.AskOne(prompt, &secret, nil))
ciphersecret, err := crypto.CBCEncrypt(keypass, []byte(secret))
@ -152,14 +152,24 @@ password.`,
ci.OTPSecret = base64.StdEncoding.EncodeToString(ciphersecret)
var copyotp bool
prompt2 := &survey.Confirm{Message: "Copy new OTP to clipboard?", Default: true}
check(survey.AskOne(prompt2, &copyotp, nil))
prompt = &survey.Confirm{Message: "Copy new OTP to clipboard?", Default: true}
check(survey.AskOne(prompt, &copyotp, nil))
if copyotp {
otp, err := totp.GenerateCode(secret, time.Now())
check(err)
check(clipboard.WriteAll(otp))
prompt = &survey.Confirm{Message: "Anotha one?", Default: true}
check(survey.AskOne(prompt, &copyotp, nil))
if copyotp {
otp, err := totp.GenerateCode(secret, time.Now().Add(time.Second*30))
check(err)
check(clipboard.WriteAll(otp))
}
}
}

View File

@ -4,7 +4,6 @@ go 1.12
require (
github.com/atotto/clipboard v0.1.2
github.com/davecgh/go-spew v1.1.1
github.com/google/uuid v1.1.1
github.com/mitchell/selfpass/services v0.0.0-00010101000000-000000000000
github.com/mitchellh/go-homedir v1.1.0

View File

@ -48,7 +48,6 @@ github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5m
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g=
github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=