canonical / craft-archives

A library for handling archives/repositories in Craft applications
https://canonical-craft-archives.readthedocs-hosted.com
GNU Lesser General Public License v3.0
0 stars 7 forks source link

keys: make AptKeyManager.install_key() more robust #86

Closed tigarmo closed 1 year ago

tigarmo commented 1 year ago

This commit relaxes the restriction of the provided key contents having only a single (primary) key, and makes AptKeyManager better handle the fact that "gpg import" might print out useful diagnostics messages even if the key contents are imported "successfully".

To do this, we capture gpg's output and add a new optional parameter for the desired "target" key fingerprint (the key that we desire to import even if other keys exist in the contents). This fingerprint is used when naming the imported file, and then:

1) If we don't have a desired fingerprint, proceed as before. 2) If we have a desired fingerprint, check for it in the imported file, failing if it's not there.

The motivation for this change is that there are keys "in the wild" that generate gpg error messages but still contain a valid, non-expired desired key. This was supported before but regressed when we moved away from apt-key.

This commit is the second one on the road to fixing the "multiple keys in the same file" regression.


codecov[bot] commented 1 year ago

Codecov Report

Merging #86 (c65a965) into hotfix/1.1.1 (b1c20e2) will decrease coverage by 0.58%. The diff coverage is 82.85%.

:exclamation: Current head c65a965 differs from pull request most recent head d7fef04. Consider uploading reports for the commit d7fef04 to get more accurate results

@@               Coverage Diff                @@
##           hotfix/1.1.1      #86      +/-   ##
================================================
- Coverage         90.51%   89.94%   -0.58%     
================================================
  Files                13       13              
  Lines               664      686      +22     
  Branches            133      140       +7     
================================================
+ Hits                601      617      +16     
- Misses               47       51       +4     
- Partials             16       18       +2     
Impacted Files Coverage Δ
craft_archives/repo/apt_key_manager.py 94.44% <82.85%> (-3.92%) :arrow_down: