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

Do not enforce lower case keys #2489

Merged
merged 2 commits into from
Dec 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion internal/action/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func (s *Action) binaryGet(ctx context.Context, name string) ([]byte, error) {
return nil, fmt.Errorf("failed to read %q from the store: %w", name, err)
}

if cte, _ := sec.Get("content-transfer-encoding"); cte != "Base64" {
if cte, _ := sec.Get("Content-Transfer-Encoding"); cte != "Base64" {
// need to use sec.Bytes() otherwise the first line is missing.
return sec.Bytes(), nil
}
Expand Down
27 changes: 14 additions & 13 deletions internal/action/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,19 @@ func (s *Action) parseRevision(ctx context.Context, name, revision string) (stri
return revision, nil
}

func (s *Action) showHandleOutputChars(ctx context.Context, pw string, chars []int) error {
for _, c := range chars {
if c > len(pw) || c-1 < 0 {
debug.Log("Invalid char: %d", c)

continue
}
out.Printf(ctx, "%d: %s", c, out.Secret(pw[c-1]))
}

return nil
}

// showHandleOutput displays a secret.
func (s *Action) showHandleOutput(ctx context.Context, name string, sec gopass.Secret) error {
pw, body, err := s.showGetContent(ctx, sec)
Expand All @@ -169,16 +182,7 @@ func (s *Action) showHandleOutput(ctx context.Context, name string, sec gopass.S
}

if chars := GetPrintChars(ctx); len(chars) > 0 {
for _, c := range chars {
if c > len(pw) || c-1 < 0 {
debug.Log("Invalid char: %d", c)

continue
}
out.Printf(ctx, "%d: %s", c, out.Secret(pw[c-1]))
}

return nil
return s.showHandleOutputChars(ctx, pw, chars)
}

if pw == "" && body == "" {
Expand Down Expand Up @@ -231,9 +235,6 @@ func (s *Action) showGetContent(ctx context.Context, sec gopass.Secret) (string,
val := strings.Join(values, "\n")

return val, val, nil
} else if HasKey(ctx) {
out.Warning(ctx, "Parsing is disabled but a key was provided.")
debug.Log("attempting to parse key %s with parsing disabled", GetKey(ctx))
}

pw := sec.Password()
Expand Down
11 changes: 0 additions & 11 deletions pkg/gopass/secrets/akv.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ func (a *AKV) Keys() []string {

// Get returns the value of the requested key, if found.
func (a *AKV) Get(key string) (string, bool) {
key = strings.ToLower(key)

if v, found := a.kvp[key]; found {
return v[0], true
}
Expand All @@ -74,17 +72,13 @@ func (a *AKV) Get(key string) (string, bool) {

// Values returns all values for that key.
func (a *AKV) Values(key string) ([]string, bool) {
key = strings.ToLower(key)

v, found := a.kvp[key]

return v, found
}

// Set writes a single key.
func (a *AKV) Set(key string, value any) error {
key = strings.ToLower(key)

// if it's new key we can just append it at the end
if _, found := a.kvp[key]; !found {
return a.Add(key, value)
Expand Down Expand Up @@ -146,8 +140,6 @@ func (a *AKV) Set(key string, value any) error {

// Add appends data to a given key.
func (a *AKV) Add(key string, value any) error {
key = strings.ToLower(key)

sv := fmt.Sprintf("%s", value)
a.kvp[key] = append(a.kvp[key], sv)

Expand All @@ -158,8 +150,6 @@ func (a *AKV) Add(key string, value any) error {

// Del removes a given key and all of its values.
func (a *AKV) Del(key string) bool {
key = strings.ToLower(key)

_, found := a.kvp[key]
if !found {
return false
Expand Down Expand Up @@ -270,7 +260,6 @@ func ParseAKV(in []byte) *AKV {
key = strings.TrimSpace(key)
val = strings.TrimSpace(val)
// we only store lower case keys for KV
key = strings.ToLower(key)
a.kvp[key] = append(a.kvp[key], val)
}

Expand Down