Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apt_key: fix parsing invalid dates when using GnuPG 2.x #465

Merged
merged 2 commits into from
Mar 16, 2015

Conversation

bootc
Copy link

@bootc bootc commented Mar 15, 2015

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.

It's likely that GnuPG 2.x will replace GnuPG 1.x as the default version of GnuPG in Debian fairly soon, so I think it will pay to be forward-compatible. I also know I'm not the only person to have made the switch already, though this is currently a manual process so this will be uncommon still.

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)

The second commit also sneaks in some unrelated whitespace fixes within the same file.

bootc added 2 commits March 15, 2015 22:33
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)
underscorgan pushed a commit that referenced this pull request Mar 16, 2015
apt_key: fix parsing invalid dates when using GnuPG 2.x
@underscorgan underscorgan merged commit be54e18 into puppetlabs:master Mar 16, 2015
@underscorgan
Copy link

Great, thanks @bootc

@bootc bootc deleted the fixes/gpg2_date_parsing branch March 16, 2015 18:09
@LukasAud LukasAud added the bugfix label Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants