Skip to content

Commit

Permalink
feature: Added GPG long keyid support
Browse files Browse the repository at this point in the history
Now, user input of a key is validated to see if it's 8 or 16 chars.
If it's 8 chars, it's assumed to be a short id, if 16 it's long.

From there the key ID matched against that in the local datastore.
  • Loading branch information
brianredbeard committed Jan 19, 2016
1 parent fc9118e commit 775567c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Below is a rough list of things to be resolved
* Improve in memory handling
* Improve filename handling
* Support Trust levels
* Add full public key id handling (the short id is only 8 chars long, even better to utilize the full id)
* Document exit codes and make them more explicit

### Bugs
Expand Down
29 changes: 24 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,31 @@ func checkGPG(file File) (state SigState, err error) {
fmt.Printf("Invalid signature or public key not present: %s\n", err)
os.Exit(2)
}
state.sig = signer.PrimaryKey.KeyIdShortString()

if len(*flagKeyid) > 0 {
keyid := strings.ToUpper(*flagKeyid)
if keyid != state.sig {
fmt.Printf("The remote file was not signed by the expected GPG Public key. Expected %s and got %s\n", keyid, state.sig)
state.sig = signer.PrimaryKey.KeyIdString()

l := len(*flagKeyid)
if l > 0 {
var rid string

// Force the local id to be all uppercase
lid := strings.ToUpper(*flagKeyid)

// check the number of chars on the remote id to see if it's a
// short or long id. If it's not 8 or 16, it's not valid.
switch l {
case 8:
rid = signer.PrimaryKey.KeyIdShortString()
case 16:
rid = signer.PrimaryKey.KeyIdString()
}
if len(rid) == 0 {
fmt.Printf("You did not specify a valid GPG keyid length. Must be 8 or 16 characters.")
os.Exit(2)
}

if lid != rid {
fmt.Printf("The remote file was not signed by the expected GPG Public key. Expected %s and got %s\n", lid, rid)
os.Exit(2)
}
}
Expand Down

0 comments on commit 775567c

Please sign in to comment.