Skip to content

Commit 775567c

Browse files
committed
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.
1 parent fc9118e commit 775567c

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

TODO.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ Below is a rough list of things to be resolved
66
* Improve in memory handling
77
* Improve filename handling
88
* Support Trust levels
9-
* Add full public key id handling (the short id is only 8 chars long, even better to utilize the full id)
109
* Document exit codes and make them more explicit
1110

1211
### Bugs

main.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,31 @@ func checkGPG(file File) (state SigState, err error) {
210210
fmt.Printf("Invalid signature or public key not present: %s\n", err)
211211
os.Exit(2)
212212
}
213-
state.sig = signer.PrimaryKey.KeyIdShortString()
214213

215-
if len(*flagKeyid) > 0 {
216-
keyid := strings.ToUpper(*flagKeyid)
217-
if keyid != state.sig {
218-
fmt.Printf("The remote file was not signed by the expected GPG Public key. Expected %s and got %s\n", keyid, state.sig)
214+
state.sig = signer.PrimaryKey.KeyIdString()
215+
216+
l := len(*flagKeyid)
217+
if l > 0 {
218+
var rid string
219+
220+
// Force the local id to be all uppercase
221+
lid := strings.ToUpper(*flagKeyid)
222+
223+
// check the number of chars on the remote id to see if it's a
224+
// short or long id. If it's not 8 or 16, it's not valid.
225+
switch l {
226+
case 8:
227+
rid = signer.PrimaryKey.KeyIdShortString()
228+
case 16:
229+
rid = signer.PrimaryKey.KeyIdString()
230+
}
231+
if len(rid) == 0 {
232+
fmt.Printf("You did not specify a valid GPG keyid length. Must be 8 or 16 characters.")
233+
os.Exit(2)
234+
}
235+
236+
if lid != rid {
237+
fmt.Printf("The remote file was not signed by the expected GPG Public key. Expected %s and got %s\n", lid, rid)
219238
os.Exit(2)
220239
}
221240
}

0 commit comments

Comments
 (0)