Skip to content

Commit

Permalink
fixup! Add first cut of git-credential-fdoss
Browse files Browse the repository at this point in the history
Rename: s/makeSecretVal/formatSecretVal/

Addresses: #3 (comment)
  • Loading branch information
camh- committed Aug 27, 2024
1 parent 2577651 commit 197f504
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (cmd *CmdStore) AfterApply(gc *GitCredential) error {
//
// [gitcredentials]: https://git-scm.com/docs/gitcredentials
func (cmd *CmdStore) Run(gc *GitCredential, ss *SecretService) error {
return ss.Store(makeLabel(gc), makeAttrs(gc), makeSecretVal(gc))
return ss.Store(makeLabel(gc), makeAttrs(gc), formatSecretVal(gc))
}

// AfterApply validates the input credential fields for a erase command.
Expand All @@ -182,7 +182,7 @@ func (cmd *CmdErase) AfterApply(gc *GitCredential) error {
//
// [gitcredentials]: https://git-scm.com/docs/gitcredentials
func (cmd *CmdErase) Run(gc *GitCredential, ss *SecretService) error {
return ss.Delete(makeAttrs(gc), makeSecretVal(gc))
return ss.Delete(makeAttrs(gc), formatSecretVal(gc))
}

// makeLabel returns a string describing the given GitCredential, used as a
Expand Down Expand Up @@ -225,7 +225,7 @@ func makeAttrs(gc *GitCredential) map[string]string {
return attrs
}

// makeSecretVal encodes the secret and/or variable parts of a GitCredential
// formatSecretVal encodes the secret and/or variable parts of a GitCredential
// into a string suitable for storing with the secret service. Variable parts,
// such as the password expiry time, cannot be encoded as an attribute as they
// need to match when looking up and such variable parts cannot be used for
Expand All @@ -234,16 +234,15 @@ func makeAttrs(gc *GitCredential) map[string]string {
// The format for encoding multiple values is the same as used by
// git-credential-libsecret so as to be compatible with it.
//
// Note: This format is not compatible with the unencrypted keyring format
// of gnome-keyring as it does not escape the newlines when storing them
// in an ini-like file, and those newlines break the file (the extra fields
// added here appear as different values that do not get retrieved with
// the secret). This really should be fixed in gnome-keyring, but is not
// much of a concern as if you are going to store your passwords in plain
// text, you may as well use git-credential-store. However, one may want
// all their credentials together in one place stored in plain text for
// easier exploitation.
func makeSecretVal(gc *GitCredential) string {
// Note: This format is not compatible with the unencrypted keyring format of
// gnome-keyring as it does not escape the newlines when storing them in an
// ini-like file, and those newlines break the file (the extra fields added
// here appear as different values that do not get retrieved with the secret).
// This really should be fixed in gnome-keyring, but is not much of a concern
// as if you are going to store your passwords in plain text, you may as well
// use git-credential-store. However, one may want all their credentials
// together in one place stored in plain text for easier exploitation.
func formatSecretVal(gc *GitCredential) string {
secret := gc.Password
if gc.PasswordExpiryUTC != "" {
secret += "\npassword_expiry_utc=" + gc.PasswordExpiryUTC
Expand Down

0 comments on commit 197f504

Please sign in to comment.