gpg key version attribute

72 views
Skip to first unread message

nello

unread,
Mar 6, 2019, 5:11:24 PM3/6/19
to python-gnupg
Hi everybody,

im trying to understand if I can grab the 'key version' attribute for a given public key using python-gpg.  

Eg. calling gpg bynary I would specify:

gpg --list-packets, which outputs

having returned something like:

:pubkey enc packet: version 4, algo 1, keyid 08D014DED0B337AA
        data: [4095 bits]
:pubkey enc packet: version 4, algo 16, keyid 921EB6497074473C
        data: [1024 bits]
        data
: [1021 bits]
:encrypted data packet:
        length: 69
        mdc_method
: 2
:compressed packet: algo=2
:literal data packet:
        mode b (62), created 1305194688, name="foo.txt",
        raw data
: 4 bytes
What im interested in,  is the version number (version 4 in this example), I have a working script which is validating the version and some other parameters and rejecting keys which are not on version 4.

Tried to check list_keys() scan_keys() methods looking for this parameter but with no luck.


Following the documentation I decided then to try to include in the gpg object instantation within the 'option' attribute the '--list-packets' str eg.

        gpg_object = gnupg.GPG(gnupghome=tempdir, options='--list-packets')

and then calling scan_keys for a given key, but the result is null, pretty sure im doing this workaround not in the correct way, tried to debug and I see the option passed to self.option but can't see scan_keys doing anything with that info, could It be in collision with some other parameters already?

    key_info = gpg_object.scan_keys(key_file)



Looking for some help, thanks!



Vinay Sajip

unread,
Mar 7, 2019, 12:38:17 AM3/7/19
to python-gnupg
Dear nello,

The list-packets command is a different command from list-keys - one is not an option for the other. The list-packets command isn't supported, as it's meant to be used for debugging only, and is subject to change without notice (as per my understanding).

Regards,

Vinay Sajip

Antonio Cascella

unread,
Mar 7, 2019, 4:19:03 AM3/7/19
to python...@googlegroups.com
Hi Vinay,
Thanks for your answer.

Any other possibility to retrieve the 'key version' attribute using python-gnupg library?

--

---
You received this message because you are subscribed to the Google Groups "python-gnupg" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-gnupg...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vinay Sajip

unread,
Mar 8, 2019, 5:05:04 AM3/8/19
to python-gnupg
Dear nello,

On Thursday, 7 March 2019 09:19:03 UTC, nello wrote:
Any other possibility to retrieve the 'key version' attribute using python-gnupg library?

Not at the moment, though I will consider PRs to add this functionality in a general way. I've no time presently to look into this myself.

Regards,

Vinay

Vinay Sajip

unread,
Mar 8, 2019, 5:50:10 AM3/8/19
to python-gnupg
Note that currently, you get quite a bit of information from list_keys():

$ python3
Python 3.5.2 (default, Nov 12 2018, 13:43:14) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gnupg; gpg = gnupg.GPG(gnupghome='keys')
>>> data = gpg.list_keys()
>>> import pprint; pprint.pprint(data)
[{'algo': '1',
  'cap': 'escaESCA',
  'compliance': 'unavailable',
  'curve': 'unavailable',
  'date': '1552039936',
  'dummy': '',
  'expires': '',
  'fingerprint': '855E489E51680C5456A6EE9B331348300BBF5B9E',
  'flag': 'unavailable',
  'hash': 'unavailable',
  'issuer': '',
  'keyid': '331348300BBF5B9E',
  'length': '2048',
  'origin': 'unavailable',
  'ownertrust': 'u',
  'sig': '',
  'sigs': [],
  'subkeys': [],
  'token': 'unavailable',
  'trust': 'u',
  'type': 'pub',
  'uids': ['Autogenerated Key <vinay@ubuntu>'],
  'updated': 'unavailable'}]

Antonio Cascella

unread,
Mar 8, 2019, 6:16:46 AM3/8/19
to python...@googlegroups.com
Thats true, im already using some useful informations returned by the key_list() function like algo,type used within my script validation - However I'm in the need also to validate the 'version' of the key 


--
Reply all
Reply to author
Forward
0 new messages