Skip to content

Commit

Permalink
base64-encode username to allow / in username
Browse files Browse the repository at this point in the history
This commit breaks backwards compability, as it will fail on all
non-base64 encoded usernames.
Fixes docker#162
  • Loading branch information
sebageek committed Sep 23, 2020
1 parent f78081d commit 56487ff
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pass/pass_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ func (h Pass) Add(creds *credentials.Credentials) error {
}

encoded := base64.URLEncoding.EncodeToString([]byte(creds.ServerURL))
encodedUsername := base64.URLEncoding.EncodeToString([]byte(creds.Username))

_, err := h.runPass(creds.Secret, "insert", "-f", "-m", path.Join(PASS_FOLDER, encoded, creds.Username))
_, err := h.runPass(creds.Secret, "insert", "-f", "-m", path.Join(PASS_FOLDER, encoded, encodedUsername))
return err
}

Expand Down Expand Up @@ -153,8 +154,12 @@ func (h Pass) Get(serverURL string) (string, string, error) {
}

actual := strings.TrimSuffix(usernames[0].Name(), ".gpg")
decodedUsername, err := base64.URLEncoding.DecodeString(actual)
if err != nil {
return "", "", err
}
secret, err := h.runPass("", "show", path.Join(PASS_FOLDER, encoded, actual))
return actual, secret, err
return string(decodedUsername), secret, err
}

// List returns the stored URLs and corresponding usernames for a given credentials label
Expand Down Expand Up @@ -185,7 +190,11 @@ func (h Pass) List() (map[string]string, error) {
return nil, fmt.Errorf("no usernames for %s", serverURL)
}

resp[string(serverURL)] = strings.TrimSuffix(usernames[0].Name(), ".gpg")
decodedUsername, err := base64.URLEncoding.DecodeString(strings.TrimSuffix(usernames[0].Name(), ".gpg"))
if err != nil {
return nil, err
}
resp[string(serverURL)] = string(decodedUsername)
}

return resp, nil
Expand Down

0 comments on commit 56487ff

Please sign in to comment.