Skip to content

Commit

Permalink
initial commit for gpg key checking
Browse files Browse the repository at this point in the history
better attempt at gpg version checking

adding in key length warning

removing version check, adding key check

adding tests
  • Loading branch information
tphoney committed Mar 11, 2015
1 parent b473af1 commit 55e3119
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/puppet/provider/apt_key/apt_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ def tempfile(content)
file = Tempfile.new('apt_key')
file.write content
file.close
#we now need to confirm that the fingerprint in this file, matches the long key that the user has given in the manifest
if name.size == 40
if File.executable? "/usr/bin/gpg"
extractedKey = execute(["/usr/bin/gpg --with-fingerprint --with-colons #{file.path} | awk -F: '/^fpr:/ { print $10 }'"], :failonfail => false)
extractedKey = extractedKey.chomp
if extractedKey != name
fail ("The id in your manifest and the fingerprint from content/source do not match. Please check the content/source is legitimate.")
end
end
end
file.path
end

Expand Down
3 changes: 3 additions & 0 deletions lib/puppet/type/apt_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
if self[:content] and self[:source]
fail('The properties content and source are mutually exclusive.')
end
if self[:id].length < 40
warning('The key should be at least a full fingerprint.')
end
end

newparam(:id, :namevar => true) do
Expand Down
34 changes: 34 additions & 0 deletions spec/acceptance/apt_key_provider_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -520,4 +520,38 @@
end
end
end

describe 'fingerprint validation against source/content' do
context 'fingerprint in id matches fingerprint from remote key' do
it 'works' do
pp = <<-EOS
apt_key { 'puppetlabs':
id => '#{PUPPETLABS_GPG_KEY_FINGERPRINT}',
ensure => 'present',
source => 'https://#{PUPPETLABS_APT_URL}/#{PUPPETLABS_GPG_KEY_FILE}',
}
EOS

apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_failures => true)
end
end

context 'fingerprint in id does NOT match fingerprint from remote key' do
it 'works' do
pp = <<-EOS
apt_key { 'puppetlabs':
id => '47B320EB4C7C375AA9DAE1A01054B7A24BD6E666',
ensure => 'present',
source => 'https://#{PUPPETLABS_APT_URL}/#{PUPPETLABS_GPG_KEY_FILE}',
}
EOS

apply_manifest(pp, :expect_failures => true) do |r|
expect(r.stderr).to match(/do not match/)
end
end
end
end

end

0 comments on commit 55e3119

Please sign in to comment.