From 775567c197b142b759da96ff5764b2915434be3d Mon Sep 17 00:00:00 2001 From: Brian 'Redbeard' Harrington Date: Tue, 19 Jan 2016 11:47:00 -0800 Subject: [PATCH] feature: Added GPG long keyid support 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. --- TODO.md | 1 - main.go | 29 ++++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) 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) } }