isislovecruft / python-gnupg

A modified version of python-gnupg, including security patches, extensive documentation, and extra features.
Other
424 stars 172 forks source link

GPG().list_sigs() fails with KeyError #158

Open heartsucker opened 8 years ago

heartsucker commented 8 years ago

Possibly related to #142.

Python:

from gnupg import GPG
print(GPG(homedir='~/.gnupg').list_sigs())

Output:

  File "./test.py", line 2, in <module>
    print(GPG(homedir='~/.gnupg').list_sigs())
  File "/home/heartsucker/code/heartsucker/python-gpg-spider/venv/lib/python3.4/site-packages/gnupg/gnupg.py", line 525, in list_sigs
    self._parse_keys(result)
  File "/home/heartsucker/code/heartsucker/python-gpg-spider/venv/lib/python3.4/site-packages/gnupg/gnupg.py", line 543, in _parse_keys
    getattr(result, keyword)(L)
  File "/home/heartsucker/code/heartsucker/python-gpg-spider/venv/lib/python3.4/site-packages/gnupg/_parsers.py", line 1023, in sig
    self.curkey['sigs'][self.curuid].append(sig)
KeyError: 'Canary <canary@heartsucker.com>'

This output is the same for listing signatures for all keys or listing signatures for one key. The output is the same for both gpg and gpg2 binaries.

Output from matching gpg commands:

heartsucker@pythagoras:~/code/heartsucker/python-gpg-spider/gpg_spider$ gpg2 --with-colons --fixed-list-mode --list-sigs canary@heartsucker.com
tru::1:1471722346:1484145775:3:1:5
pub:f:4096:1:9C02F7D8345FA1CA:1471423655:::-:::scSC:
fpr:::::::::3F3371F05A137C1F0F3FF3EC9C02F7D8345FA1CA:
uid:f::::1471423655::0F7C180FFFCC7E33395C12BC497DD957F5A82694::Canary <canary@heartsucker.com>:
sig:::1:9C02F7D8345FA1CA:1471423655::::Canary <canary@heartsucker.com>:13x:::::10:
sig:::1:C0A2586F09D77C82:1471423769::::heartsucker <heartsucker@autistici.org>:13x:::::10:
sub:f:4096:1:8EA402228B4D3F51:1471423683:1479199683:::::s:
sig:::1:9C02F7D8345FA1CA:1471423683::::Canary <canary@heartsucker.com>:18x:::::10:

heartsucker@pythagoras:~/code/heartsucker/python-gpg-spider/gpg_spider$ gpg2 --with-colons --fixed-list-mode --list-sigs heartsucker@autistici.org
tru::1:1471722346:1484145775:3:1:5
pub:u:4096:1:C0A2586F09D77C82:1465922491:1497458491::u:::cESCA:
fpr:::::::::0CEC936888A60171461174C5C0A2586F09D77C82:
uid:u::::1471424169::A0F54BDFEE3849D534ED4CF302D48C66ACA64FB9::heartsucker <heartsucker@autistici.org>:
sig:::1:C0A2586F09D77C82:1465922491::::heartsucker <heartsucker@autistici.org>:13x:::::10:
sig:::1:19DA2F588D28CCF4:1465924060::::Eric Hartsuyker <ehartsuyker@gmail.com>:13x:::::10:
sig:::1:B75811F71EED3B6B:1471362271::::cvoelcker <claas@voelcker.net>:13x:::::8:
sig:::1:61B904B99DCED43B:1467145816::::BerlinLeaks Admin <berlinleaks@riseup.net>:13x:::::10:
sig:::1:C0A2586F09D77C82:1471424169::::heartsucker <heartsucker@autistici.org>:13x:::::10:
sig:::1:9C02F7D8345FA1CA:1471423819::::Canary <canary@heartsucker.com>:13x:::::10:
sig:::1:7635A367EFF7BB6E:1471644582::::info post <virtuellepoststelle@gmail.com>:13x:::::10:
uid:u::::1467920257::DDE05E2A5FFC2C415BCDE68F2CB00A481E989C11::heartsucker <eric@srlabs.de>:
sig:::1:C0A2586F09D77C82:1467920257::::heartsucker <heartsucker@autistici.org>:13x:::::10:
sig:::1:9C02F7D8345FA1CA:1471423819::::Canary <canary@heartsucker.com>:13x:::::10:
sig:::1:7635A367EFF7BB6E:1471644582::::info post <virtuellepoststelle@gmail.com>:13x:::::10:
uid:u::::1467921473::947C48EBFEBF47BD4B8E7ADA7C583AA0DD284C12::heartsucker <ehartsuyker@gmail.com>:
sig:::1:C0A2586F09D77C82:1467921473::::heartsucker <heartsucker@autistici.org>:13x:::::10:
sig:::1:9C02F7D8345FA1CA:1471423819::::Canary <canary@heartsucker.com>:13x:::::10:
sig:::1:7635A367EFF7BB6E:1471644582::::info post <virtuellepoststelle@gmail.com>:13x:::::10:
sub:u:4096:1:9185CF2739FE46AC:1465922612:1481474612:::::e:
sig:::1:C0A2586F09D77C82:1465922612::::heartsucker <heartsucker@autistici.org>:18x:::::10:
sub:u:4096:1:F56D44B40ED536A6:1465922653:1481474653:::::s:
sig:::1:C0A2586F09D77C82:1465922653::::heartsucker <heartsucker@autistici.org>:18x:::::10:
sub:u:4096:1:5A104FF068225CA5:1465922687:1481474687:::::a:
sig:::1:C0A2586F09D77C82:1465922687::::heartsucker <heartsucker@autistici.org>:18x:::::10:
sub:r:4096:1:7F1B42C99DFA4D2B:1465923509:1473699509:::::s:
sig:::1:C0A2586F09D77C82:1465923509::::heartsucker <heartsucker@autistici.org>:18x:::::10:
rev:::1:C0A2586F09D77C82:1471422777::::heartsucker <heartsucker@autistici.org>:28x:::::10:

My env:

(venv) heartsucker@pythagoras:~/code/heartsucker/python-gpg-spider/gpg_spider$ python --version
Python 3.4.2
(venv) heartsucker@pythagoras:~/code/heartsucker/python-gpg-spider/gpg_spider$ pip freeze
gnupg==2.0.2
psutil==4.3.0
(venv) heartsucker@pythagoras:~/code/heartsucker/python-gpg-spider/gpg_spider$ uname -a
Linux pythagoras 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt25-2+deb8u3 (2016-07-02) x86_64 GNU/Linux
heartsucker@pythagoras:~/code/heartsucker/python-gpg-spider/gpg_spider$ gpg --version
gpg (GnuPG) 1.4.18
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Home: ~/.gnupg
Supported algorithms:
Pubkey: RSA, RSA-E, RSA-S, ELG-E, DSA
Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,
        CAMELLIA128, CAMELLIA192, CAMELLIA256
Hash: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
Compression: Uncompressed, ZIP, ZLIB, BZIP2
heartsucker@pythagoras:~/code/heartsucker/python-gpg-spider/gpg_spider$ gpg2 --version
gpg (GnuPG) 2.0.26
libgcrypt 1.6.3
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Home: ~/.gnupg
Supported algorithms:
Pubkey: RSA, RSA, RSA, ELG, DSA
Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,
        CAMELLIA128, CAMELLIA192, CAMELLIA256
Hash: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
Compression: Uncompressed, ZIP, ZLIB, BZIP2
heartsucker commented 8 years ago

In the event someone gets to this before I solve it all the way, the problem is the ListKeys object is not having the uid field called which resets the self.curuid. This causes the KeyError on a subsequent call to sig.

isislovecruft commented 7 years ago

@meskio and I have some questions about the patch for this, in the review which was started for the patch in #159.