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

Add auto locate key support #221

Closed
wants to merge 5 commits into from

Conversation

Myzel394
Copy link

@Myzel394 Myzel394 commented Apr 9, 2023

Hey @vsajip thanks for your awesome package! I'd like to add auto locate key support (retrieving keys from WKD for example).

I managed to add support for retrieving the fingerprint, but I'd like to include all the information gpg provides.
Here's an example of what gpg outputs to the console when autolocating a key:

$ gpg --auto-key-locate wkd --locate-key no-reply@protonmail.com
pub   rsa2048 2021-07-14 [SC]
      90E619A84E85330A692F6D81A655882018DBFA9D
uid           [ unknown] no-reply@protonmail.com <no-reply@protonmail.com>
sub   rsa2048 2021-07-14 [E]

You can see that it tells you when the key was generated and what type it is. I'll need some help from you regarding this information. How can I extract it? I'm using StatusHandler to extract the fingerprint and the email, but how do I find out the other stuff?

@Myzel394
Copy link
Author

Myzel394 commented Apr 9, 2023

will solve #117

@vsajip
Copy link
Owner

vsajip commented Apr 12, 2023

How can I extract it?

The same way that e.g. list_keys does. Note that any patch will need to check the gpg version and behave appropriately (see my above comment on the issue about key location) and work/be tested across platforms.

@Myzel394
Copy link
Author

Hey @vsajip by default you add --with-colons to the args. I noticed that this option changes the output drastically (stripping away lots of information), is there any particular reason why we need this?

@vsajip
Copy link
Owner

vsajip commented Apr 13, 2023

is there any particular reason why we need this? [--with-colons]

It's there to facilitate machine parsing of the information - as everything is delimited by colons, there's no need to guess how things are laid out.

@vsajip
Copy link
Owner

vsajip commented Apr 13, 2023

If information is lost when --with-colons is used for your use case, you might need to take it up with the GnuPG project.

@Myzel394
Copy link
Author

@vsajip after investigating the output a bit more, it seems as if the data is encoded into a different format (timestamp instead of human readable dates for example). I searched through the gnupg docs but I can't find any information on how the other data is encoded. What resources did you use to parse the output of the other functions from your library?

@vsajip
Copy link
Owner

vsajip commented Apr 13, 2023

What resources did you use to parse the output of the other functions from your library?

The DETAILS file from the GnuPG sources.

@Myzel394 Myzel394 marked this pull request as ready for review April 14, 2023 15:18
@Myzel394
Copy link
Author

@vsajip thank you, those docs helped very much. I've now added the parsers. However, I'm not a pgp keys expert myself, but it seems as if there are multiple different fingerprints returned for the same key - i decided to simply use the first key, as it seems to be the correct one. Can you take a look over the code?

@Myzel394
Copy link
Author

@vsajip Are there any news on this?

@vsajip
Copy link
Owner

vsajip commented Apr 22, 2023

Sorry, been busy on other things. Will get to it as soon as I can.

@codecov-commenter
Copy link

codecov-commenter commented Jan 23, 2024

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (2854b37) 96.55% compared to head (23a30a5) 96.53%.

Files Patch % Lines
gnupg.py 94.87% 1 Missing and 1 partial ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #221      +/-   ##
==========================================
- Coverage   96.55%   96.53%   -0.03%     
==========================================
  Files           2        2              
  Lines        1771     1816      +45     
  Branches      173      176       +3     
==========================================
+ Hits         1710     1753      +43     
- Misses         28       29       +1     
- Partials       33       34       +1     
Flag Coverage Δ
unittests 96.03% <95.55%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

gnupg.py Outdated Show resolved Hide resolved
@vsajip
Copy link
Owner

vsajip commented Jan 23, 2024

Still getting errors when testing locally. From my log:

2024-01-23 10:33:57,830 DEBUG gnupg      Thread-3   1235 gpg: error retrieving 'no-reply@protonmail.com' via WKD: Invalid URI
2024-01-23 10:33:58,026 DEBUG gnupg      Thread-3   1235 gpg: error retrieving 'no-reply@protonmail.com' via NTDS: No keyserver available
2024-01-23 10:33:58,026 DEBUG gnupg      Thread-3   1235 gpg: error retrieving 'no-reply@protonmail.com' via LDAP: Not implemented
2024-01-23 10:33:58,026 DEBUG gnupg      Thread-3   1235 gpg: error retrieving 'no-reply@protonmail.com' via DNS CERT: No name
2024-01-23 10:33:58,031 DEBUG gnupg      Thread-3   1235 gpg: error retrieving 'no-reply@protonmail.com' via DANE: No name

gnupg.py Outdated Show resolved Hide resolved
@vsajip
Copy link
Owner

vsajip commented Mar 13, 2024

Thanks very much for this patch. I've incorporated the changes but made some local edits to do with testing locally, so I won't merge this PR - but your changes are incorporated in 3df9074.

@vsajip vsajip closed this Mar 13, 2024
@Myzel394
Copy link
Author

No problem, I'm glad this feature got added!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants