Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a definitive check for possible password errors. #121

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Exported special value to check for when decrypting.
  • Loading branch information
Skarlso committed Oct 6, 2018
commit b7a48d9855b96d222d5978e03081c938b6564e62
11 changes: 7 additions & 4 deletions security/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import (
)

const (
vaultName = ".gaia_vault"
vaultName = ".gaia_vault"
secretCheckKey = "GAIA_CHECK_SECRET"
secretCheckValue = "!CHECK_ME!"
)

// VaultAPI defines a set of apis that a Vault must provide in order to be a Gaia Vault.
Expand Down Expand Up @@ -190,7 +192,8 @@ func (v *Vault) encrypt(data []byte) (string, error) {
// User has deleted all the secrets. the file will be empty.
return "", nil
}
data = append(data, []byte("\nGAIA_CHECK=!CHECK_ME!")...)
secretCheck := fmt.Sprintf("\n%s=%s", secretCheckKey, secretCheckValue)
data = append(data, []byte(secretCheck)...)
paddedPassword := v.pad(v.cert)
ci := base64.URLEncoding.EncodeToString(paddedPassword)
block, err := aes.NewCipher([]byte(ci[:aes.BlockSize]))
Expand Down Expand Up @@ -243,7 +246,7 @@ func (v *Vault) decrypt(data []byte) ([]byte, error) {
return []byte{}, err
}

if !bytes.Contains(unpadMsg, []byte("!CHECK_ME!")) {
if !bytes.Contains(unpadMsg, []byte(secretCheckValue)) {
return []byte{}, errors.New("possible mistyped password")
}
return unpadMsg, nil
Expand All @@ -258,7 +261,7 @@ func (v *Vault) parseToMap(data []byte) error {
row := bytes.Split(data, []byte("\n"))
for _, r := range row {
d := bytes.Split(r, []byte("="))
if bytes.Equal(d[0], []byte("GAIA_CHECK")) {
if bytes.Equal(d[0], []byte(secretCheckKey)) {
continue
}
v.data[string(d[0])] = d[1]
Expand Down