Skip to content

Commit

Permalink
Remove the optional 0x prefix from the keyID
Browse files Browse the repository at this point in the history
It is possible to invoke pinentry with different keyID formats via the
--keyid-format flag, for instance. This previously broke the length
validation for the keyID which should be either 8/short or 16/long bytes
without the 0x prefix.

Previous issue could be reproduced via:

echo 1234 | /usr/local/bin/gpg --default-key $TESTKEY --keyid-format 0xshort -as -

Extends the implementation from #16.
  • Loading branch information
jorgelbg committed Jan 10, 2022
1 parent bfb0055 commit 9ae08b5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,12 @@ func GetPIN(authFn AuthFunc, promptFn PromptFunc, logger *log.Logger) GetPinFunc

matches = keyIDRegex.FindStringSubmatch(s.Desc)
keyID := matches[1]
if len(keyID) != 8 && len(keyID) != 16 && len(keyID) != 18 {

// Drop the optional 0x prefix from keyID (--keyid-format)
// https://www.gnupg.org/documentation/manuals/gnupg/GPG-Configuration-Options.html
keyID = strings.TrimPrefix(keyID, "0x")

if len(keyID) != 8 && len(keyID) != 16 {
logger.Printf("Invalid keyID: %s", keyID)
return "", assuanError(fmt.Errorf("invalid keyID: %s", keyID))
}
Expand Down

0 comments on commit 9ae08b5

Please sign in to comment.