Modify sp and services to use the protobuf module

This commit is contained in:
mitchell 2019-07-11 21:02:46 -04:00
parent 66ec035ee0
commit 4fc74b0994
23 changed files with 59 additions and 1025 deletions

View file

@ -12,7 +12,7 @@ import (
"github.com/mitchell/selfpass/services/credentials/types"
)
type CredentialClientInit func(ctx context.Context) (c types.CredentialClient)
type CredentialsClientInit func(ctx context.Context) (c types.CredentialsClient)
func check(err error) {
if err != nil {
@ -21,7 +21,7 @@ func check(err error) {
}
}
func selectCredential(client types.CredentialClient) types.Credential {
func selectCredential(client types.CredentialsClient) types.Credential {
var (
idKey string
source string

View file

@ -17,7 +17,7 @@ import (
clitypes "github.com/mitchell/selfpass/sp/types"
)
func makeCreate(repo clitypes.ConfigRepo, initClient CredentialClientInit) *cobra.Command {
func makeCreate(repo clitypes.ConfigRepo, initClient CredentialsClientInit) *cobra.Command {
var length uint
var numbers bool
var specials bool

View file

@ -9,7 +9,7 @@ import (
"gopkg.in/AlecAivazis/survey.v1"
)
func makeDelete(initClient CredentialClientInit) *cobra.Command {
func makeDelete(initClient CredentialsClientInit) *cobra.Command {
deleteCmd := &cobra.Command{
Use: "delete",
Short: "Delete a credential using the given ID",

View file

@ -14,7 +14,7 @@ import (
clitypes "github.com/mitchell/selfpass/sp/types"
)
func makeGCMToCBC(repo clitypes.ConfigRepo, initClient CredentialClientInit) *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 CredentialClientInit) *cobra.Command {
func makeGet(repo clitypes.ConfigRepo, initClient CredentialsClientInit) *cobra.Command {
getCmd := &cobra.Command{
Use: "get",
Short: "Get a credential info and copy password to clipboard",

View file

@ -30,7 +30,8 @@ the users private key, and server certificates. (All of which will be encrypted)
prompt survey.Prompt
privateKey = strings.Replace(uuid.New().String(), "-", "", -1)
)
_, cfg, _ := repo.OpenConfig()
_, cfg, err := repo.OpenConfig()
check(err)
prompt = &survey.Password{Message: "New master password:"}
check(survey.AskOne(prompt, &masterpass, nil))

View file

@ -12,7 +12,7 @@ import (
"github.com/mitchell/selfpass/services/credentials/types"
)
func makeList(initClient CredentialClientInit) *cobra.Command {
func makeList(initClient CredentialsClientInit) *cobra.Command {
var sourceHost string
listCmd := &cobra.Command{

View file

@ -23,7 +23,7 @@ can interact with the entire Selfpass API.`,
cfgFile := rootCmd.PersistentFlags().String("config", "", "config file (default is $HOME/.sp.toml)")
mgr := repositories.NewConfigManager(cfgFile)
clientInit := credrepos.NewCredentialServiceClient
clientInit := credrepos.NewCredentialsClient
rootCmd.AddCommand(
makeInit(mgr),
@ -41,8 +41,8 @@ can interact with the entire Selfpass API.`,
check(rootCmd.Execute())
}
func makeInitClient(repo types.ConfigRepo, initClient credtypes.CredentialClientInit) CredentialClientInit {
return func(ctx context.Context) credtypes.CredentialClient {
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 CredentialClientInit) *cobra.Command {
func makeUpdate(repo clitypes.ConfigRepo, initClient CredentialsClientInit) *cobra.Command {
var length uint
var numbers bool
var specials bool

View file

@ -9,6 +9,8 @@ import (
"io"
)
var ErrAuthenticationFailed = errors.New("cipher: message authentication failed")
func GCMEncrypt(key []byte, plaintext []byte) ([]byte, error) {
if len(key) != 32 {
return nil, fmt.Errorf("key is not 32 bytes")

View file

@ -4,6 +4,7 @@ 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
@ -16,3 +17,5 @@ require (
)
replace github.com/mitchell/selfpass/services => ../services
replace github.com/mitchell/selfpass/protobuf/go => ../protobuf/go

View file

@ -7,7 +7,6 @@ import (
"fmt"
"io/ioutil"
"os"
"strings"
"github.com/mitchellh/go-homedir"
"github.com/spf13/viper"
@ -67,15 +66,15 @@ func (mgr *ConfigManager) OpenConfig() (output string, v *viper.Viper, err error
}
contents, err = decryptConfig(mgr.masterpass, cfg)
if err != nil && err == errConfigDecrypted {
if err == errConfigDecrypted {
configDecrypted = true
} else if err != nil && err.Error() == crypto.ErrAuthenticationFailed.Error() {
return output, nil, errors.New("incorrect masterpass")
} else if err != nil {
return output, nil, err
}
if err = mgr.v.ReadConfig(bytes.NewBuffer(contents)); err != nil && strings.HasPrefix(err.Error(), "While parsing config") {
return output, nil, fmt.Errorf("incorrect master password")
} else if err != nil {
if err = mgr.v.ReadConfig(bytes.NewBuffer(contents)); err != nil {
return output, nil, err
}