diff --git a/TODO.md b/TODO.md index bd8af18..5252c40 100644 --- a/TODO.md +++ b/TODO.md @@ -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 diff --git a/main.go b/main.go index 3c19253..35f8d8d 100644 --- a/main.go +++ b/main.go @@ -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) } }