apt_key: fix parsing invalid dates when using GnuPG 2.x
authorChris Boot <bootc@bootc.net>
Sun, 15 Mar 2015 22:33:22 +0000 (22:33 +0000)
committerChris Boot <bootc@bootc.net>
Sun, 15 Mar 2015 22:33:22 +0000 (22:33 +0000)
commit42ab470d00ac45ceb5a4a5a9cec6260d7be98822
treea87c1fc63b43d040efdb693d3cfdf25e540aa404
parent7c48eb2f0e4bbd21933e57f4e06b73123ff3281c
apt_key: fix parsing invalid dates when using GnuPG 2.x

If one should happen to have redirected /usr/bin/gpg to run GnuPG 2.x
rather than the more usual GnuPG 1.x, the apt_key provider fails with
the following error:

Could not prefetch apt_key provider 'apt_key': invalid date

This is because the output of "--with-colons" defaults to using
"fixed-list-mode" in 2.x but did not do so for 1.x. This new format
gives much more information about keys and also uses timestamps in
seconds from 1970-01-01 (UNIX epoch) rather than dates in the format
YYYY-MM-DD.

This patch adds "--fixed-list-mode" when calling apt-key, and adjusts
the code to parse the timestamps instead. This actually has several
advantages:

- Works the same with GnuPG 1.x and 2.x.
- More accurate expiry time tracking, not just entire days.
- No need to require 'date' any longer.
- Will allow the provider to expose more key information in future.

Tested on:
- Debian Wheezy (Puppet 2.7.23, Ruby 1.8.7p358)
- Debian Jessie (Puppet 3.7.2, Ruby 2.1.5p273)
lib/puppet/provider/apt_key/apt_key.rb