Skip to content

Commit 4094f97

Browse files
committed
Remove all the imported pubkeys from keyring
In case multiple GPG public keys are given, the current implementation only removes the first key after use and leaves the others, which will be used to verify subsequent downloads (insecure). This patch makes sure to remove all of them.
1 parent cf441e5 commit 4094f97

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/mini_portile2/mini_portile.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,18 @@ def verify_file(file)
270270
io.close_write
271271
io.read
272272
end
273-
raise "invalid gpg key provided" unless /\[GNUPG:\] IMPORT_OK \d+ (?<key_id>[0-9a-f]+)/i =~ gpg_status
273+
key_ids = gpg_status.scan(/\[GNUPG:\] IMPORT_OK \d+ (?<key_id>[0-9a-f]+)/i).map(&:first)
274+
raise "invalid gpg key provided" if key_ids.empty?
274275

275276
# verify the signature against our keyring
276277
gpg_status = IO.popen([gpg_exe, "--status-fd", "1", "--no-default-keyring", "--keyring", KEYRING_NAME, "--verify", signature_file, file[:local_path]], &:read)
277278

278279
# remove the key from our keyring
279-
IO.popen([gpg_exe, "--batch", "--yes", "--no-default-keyring", "--keyring", KEYRING_NAME, "--delete-keys", key_id], &:read)
280+
key_ids.each do |key_id|
281+
IO.popen([gpg_exe, "--batch", "--yes", "--no-default-keyring", "--keyring", KEYRING_NAME, "--delete-keys", key_id], &:read)
282+
raise "unable to delete the imported key" unless $?.exitstatus==0
283+
end
280284

281-
raise "unable to delete the imported key" unless $?.exitstatus==0
282285
raise "signature mismatch" unless gpg_status.match(/^\[GNUPG:\] VALIDSIG/)
283286

284287
else

0 commit comments

Comments
 (0)