Updates to wotmate, partly due to changed behaviour in gpg
v2 cover Updates to wotmate, partly due to changed behaviour in gpg
Hello,
here comes v2 of the series previously posted at
https://lore.kernel.org/tools/[email protected]/
The effect of the first patch is that changes in the trust paths are easier to review and also that changes are correctly propagated. So if there is a trust path
Linus -> A -> B -> C -> D
and a signature A -> C is added, this is then also reflected in the trust graph of D.
Certificates can lose their trust path from Linus over time, e.g. because keys on the path expire or are revoked. Currently export-keyring stops updating these keys. However for keys that are already included in the keyring, it's sensible to keep updating despite being disconnected. This is addressed by patch #2. As of now this only affects 2 certificates, but with patch #3 or #4 applied it affects 485!
Patches #3 and #4 are similar in spirit. They result in wotmate follow GnuPG's policy to not trust SHA-1 3rd-party signatures any more. The effect on the Web of Trust is considerable:
- Among the 602 valid keys currently tracked, 2 are not transitively trusted by Linus' key, without SHA-1 there are 485.
- The size of the strong set is reduced from 359 certificates to 96 without SHA-1. At the same time the diameter of the strong set increases from 9 to 16.
This can be softened a bit by importing 3rd-party signatures from keyserver.ubuntu.com. On the updated keyring the statistic becomes:
- Among the 603 valid keys currently tracked, 6 are not transitively trusted by Linus' key, without SHA-1 there are 485
- strong set size reduces from 431 to 180 (affecting 2 people from the current strong set), the diameter still increases to 16.
Some more data can be read on
https://blog.kleine-koenig.org/ukl/the-linux-kernels-pgp-web-of-trust.html
Changes since v1 are:
- Drop an unintended change from patch #1. The change is good in general and now is included as patch #4.
- Add a note to patch #3 about the effect on the kernel keyring.
@Konstantin: IMHO patches #1 and #2 are ready to go in. I'm unsure about #3 and #4. While they are conceptually the right thing to do, the impact might be too big for now? On the other hand I think (and didn't check/test) Linus cannot verify a signature made by Greg without a warning with a recent gpg already now, so getting rid of SHA-1 can be considered to just match reality.
Best regards
Uwe
Uwe Kleine-König (4):
Put a representation of the trust path in a txt file
export-keyring: Continue updating keys that lost all their trust paths
export-keyring: Default to store "clean" public keys
make-sqlitedb: Don't consider SHA-1 signatures for trust paths
export-keyring.py | 156 +++++++++++++++++++++++++++++----------------- make-sqlitedb.py | 5 ++ 2 files changed, 105 insertions(+), 56 deletions(-)
base-commit: f146a1815ad93b2f318e0a5fa857b11814a78b8b
prerequisite-patch-id: 4b7e0866c7adc0d84eef602013fbe0fcab86b9e6
Signature · 1 line
2.47.2
PATCH v2 1/4 Put a representation of the trust path in a txt file
Up to now changes to the trust paths are hardly reviewable when looking at the git history because they only have an effect on the generated .svg. However these also change when the installed graphviz changes and the diffs are hardly understandable.
For that reason put a text representation of the graph into the key files.
A nice side effect of this change is that for a trust path
Linus -> A -> B -> C
the graph for C is regenerated if B's trust path was shortend to
Linus -> B
--- export-keyring.py | 155 +++++++++++++++++++++++++++++----------------- 1 file changed, 97 insertions(+), 58 deletions(-)
export-keyring.py +97 -58
@@ -104,75 +104,114 @@ if __name__ == '__main__': args = ['-a', '--export', '--export-options', cmdargs.key_export_options, kid] keydata = wotmate.gpg_run_command(args, with_colons=False) keyout = os.path.join(keydir, '%s.asc' % kid) - # Do we already have a file in place? - if os.path.exists(keyout): - # Load it up and see if it's different - with open(keyout, 'rb') as fin: - old_keyexport = fin.read() - if old_keyexport.find(keydata) > 0: - logger.debug('No changes for %s', kid) - continue - - # Now, export the header - args = ['--list-options', 'show-notations', '--list-options', - 'no-show-uid-validity', '--with-subkey-fingerprints', '--list-key', kid] - header = wotmate.gpg_run_command(args, with_colons=False) - keyexport = header + b'\n\n' + keydata + b'\n' - - if not wotmate.lint(keydata): - logger.debug('Skipping %s due to bad linter results', kid) - continue key_paths = wotmate.get_key_paths(c, from_rowid, to_rowid, cmdargs.maxdepth, cmdargs.maxpaths) if not len(key_paths): logger.debug('Skipping %s due to invalid WoT', kid) continue - with open(keyout, 'wb') as fout: - fout.write(keyexport) - logger.info('Wrote %s', keyout) + kpblock = '' + for kp in key_paths: + for lvl, rowid in enumerate(kp): + kpuid = wotmate.get_uiddata_by_pubrow(c, rowid) + kpblock += f' {lvl} {kpuid}' if lvl > 0 else f'from {kpuid}' + kpblock += '\n' + kpblock += '\n' + key_paths_repr = kpblock.encode() - if cmdargs.gen_b4_keyring: - # Grab all uid lines from the header - for line in header.split(b'\n'): - if not line.startswith(b'uid'): - continue - line = line[3:].decode('utf-8', 'ignore').strip() - if line: - parts = parseaddr(line) - if not len(parts[1]) or parts[1].count('@') != 1: + # Is there already a key file in place? + key_changed = False + if os.path.exists(keyout): + # Load it up and see if it's different + with open(keyout, 'rb') as fin: + old_keyexport = fin.read() + if keydata not in old_keyexport: + key_changed = True + logger.debug('Key changes detected for %s', kid) + else: + key_changed = True + + txtgraphout = os.path.join(graphdir, "%s.txt" % kid) + trust_changed = key_changed + if not os.path.exists(txtgraphout): + logger.debug('Forcing generation of the text graph for %s', kid) + trust_changed = True + elif not key_changed: + # Load it up and see if trust relationships changed + with open(txtgraphout, 'rb') as fin: + old_key_paths_repr = fin.read() + if key_paths_repr not in old_key_paths_repr: + trust_changed = True + logger.debug('Trust changes detected for %s', kid) + + if not (key_changed or trust_changed): + logger.debug('No changes detected for %s', kid) + continue + + if key_changed: + # Now, export the header + args = ['--list-options', 'show-notations', '--list-options', + 'no-show-uid-validity', '--with-subkey-fingerprints', '--list-key', kid] + header = wotmate.gpg_run_command(args, with_colons=False) + keyexport = header + b"\n\n" + keydata + b"\n" + + if not wotmate.lint(keydata): + logger.debug('Skipping %s due to bad linter results', kid) + continue + + with open(keyout, 'wb') as fout: + fout.write(keyexport) + logger.info('Wrote %s', keyout) + + if cmdargs.gen_b4_keyring: + # Grab all uid lines from the header + for line in header.split(b'\n'): + if not line.startswith(b'uid'): continue - local, domain = parts[1].split('@', 1) - kpath = os.path.join(cmdargs.outdir, '.keyring', 'openpgp', quote_plus(domain), quote_plus(local)) - pathlib.Path(kpath).mkdir(parents=True, exist_ok=True) - spath = os.path.join(kpath, 'default') - tpath = os.path.relpath(keyout, kpath) - if os.path.islink(spath): - if os.readlink(spath) == tpath: + line = line[3:].decode('utf-8', 'ignore').strip() + if line: + parts = parseaddr(line) + if not len(parts[1]) or parts[1].count('@') != 1: continue - if spath in my_symlinks: - # There's multiple keys with the same identity. First one wins, for the lack of a - # better solution that is also sane. - logger.info('Notice: multiple keys with the same UID %s', parts[1]) - continue - os.unlink(spath) - logger.info('Notice: fixing symlink for %s', parts[1]) - os.symlink(tpath, spath) - my_symlinks.add(spath) - logger.info('Symlinked %s to %s', kid, spath) + local, domain = parts[1].split('@', 1) + kpath = os.path.join(cmdargs.outdir, '.keyring', 'openpgp', quote_plus(domain), + quote_plus(local)) + pathlib.Path(kpath).mkdir(parents=True, exist_ok=True) + spath = os.path.join(kpath, 'default') + tpath = os.path.relpath(keyout, kpath) + if os.path.islink(spath): + if os.readlink(spath) == tpath: + continue + if spath in my_symlinks: + # There's multiple keys with the same identity. First one wins, for the lack of a + # better solution that is also sane. + logger.info('Notice: multiple keys with the same UID %s', parts[1]) + continue + os.unlink(spath) + logger.info('Notice: fixing symlink for %s', parts[1]) + os.symlink(tpath, spath) + my_symlinks.add(spath) + logger.info('Symlinked %s to %s', kid, spath) - graph = pd.Dot( - graph_type='digraph', - ) - graph.set_node_defaults( - fontname=cmdargs.font, - fontsize=cmdargs.fontsize, - ) + if trust_changed: + graph = pd.Dot( + graph_type='digraph', + ) + graph.set_node_defaults( + fontname=cmdargs.font, + fontsize=cmdargs.fontsize, + ) + + wotmate.draw_key_paths(c, key_paths, graph, cmdargs.show_trust) + graphout = os.path.join(graphdir, '%s.%s' % (kid, cmdargs.graph_out_format)) + graph.write(graphout, format=cmdargs.graph_out_format) + logger.info('Wrote %s', graphout) + + logger.debug('Writing out the text graph') + with open(txtgraphout, 'wb') as fout: + fout.write(key_paths_repr) + logger.info('Wrote %s', txtgraphout) - wotmate.draw_key_paths(c, key_paths, graph, cmdargs.show_trust) - graphout = os.path.join(graphdir, '%s.%s' % (kid, cmdargs.graph_out_format)) - graph.write(graphout, format=cmdargs.graph_out_format) - logger.info('Wrote %s', graphout) wcount += 1 logger.info('Processed %s keys, made %s changes', kcount, wcount)
Signature · 1 line
2.47.2
PATCH v2 2/4 export-keyring: Continue updating keys that lost all their trust paths
In reply to Uwe Kleine-KönigWith recent gpg not trusting third-party signatures based on SHA1 quite some public keys lost their trust paths in the kernel pgpkeys repo. It's still sensible to update these keys, so only skip new keys without a valid trust path.
--- export-keyring.py | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-)
export-keyring.py +19 -14
@@ -105,10 +105,27 @@ if __name__ == '__main__': keydata = wotmate.gpg_run_command(args, with_colons=False) keyout = os.path.join(keydir, '%s.asc' % kid) + # Is there already a key file in place? + key_changed = False + if os.path.exists(keyout): + key_already_exists = True + # Load it up and see if it's different + with open(keyout, 'rb') as fin: + old_keyexport = fin.read() + if keydata not in old_keyexport: + key_changed = True + logger.debug('Key changes detected for %s', kid) + else: + key_already_exists = False + key_changed = True + key_paths = wotmate.get_key_paths(c, from_rowid, to_rowid, cmdargs.maxdepth, cmdargs.maxpaths) if not len(key_paths): - logger.debug('Skipping %s due to invalid WoT', kid) - continue + if key_already_exists: + logger.debug('%s has an to invalid WoT, but already exists, so still update it', kid) + else: + logger.debug('Skipping %s due to invalid WoT', kid) + continue kpblock = '' for kp in key_paths:
@@ -119,18 +136,6 @@ if __name__ == '__main__': kpblock += '\n' key_paths_repr = kpblock.encode() - # Is there already a key file in place? - key_changed = False - if os.path.exists(keyout): - # Load it up and see if it's different - with open(keyout, 'rb') as fin: - old_keyexport = fin.read() - if keydata not in old_keyexport: - key_changed = True - logger.debug('Key changes detected for %s', kid) - else: - key_changed = True - txtgraphout = os.path.join(graphdir, "%s.txt" % kid) trust_changed = key_changed if not os.path.exists(txtgraphout):
Signature · 1 line
2.47.2
PATCH v2 3/4 export-keyring: Default to store "clean" public keys
In reply to Uwe Kleine-KönigThere is no need to keep duplicated self signatures and signatures by keys not in the keyring. The default behavior of gpg seems to have changed regarding the first type of signatures as commit 671a0c921fe0 ("Periodic update from keyservers") in the korg-pgpkeys repo introduced quite some of these.
New key material is also only added cleaned, so it's consequent to also let export-keyring clean the keys. A side effect is that signatures made by deleted keys are dropped, too, but I consider that an upside.
A downside of this change however is that not only duplicated data is dropped, but also 3rd-party signatures over SHA-1 hashes. While this is good in general, this will considerably damage the Web of Trust in the kernel keyring, disconnecting 483 keys from Linus POV.
--- export-keyring.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
export-keyring.py +1 -1
@@ -51,7 +51,7 @@ if __name__ == '__main__': ap.add_argument('--graph-out-format', dest='graph_out_format', default='svg', help='Export graphs in this format') ap.add_argument('--key-export-options', dest='key_export_options', - default='export-attributes', + default='export-attributes,export-clean', help='The value to pass to gpg --export-options') ap.add_argument('--gen-b4-keyring', action='store_true', dest='gen_b4_keyring', default=False,
Signature · 1 line
2.47.2
PATCH v2 4/4 make-sqlitedb: Don't consider SHA-1 signatures for trust paths
In reply to Uwe Kleine-KönigFollowing GnuPG (and other OpenPGP implementions, e.g. Sequoia) and stop trusting signatures based on SHA-1. While this modernizes wotmate, this has a considerable effect on the model of the kernel's WoT.
--- make-sqlitedb.py | 5 +++++ 1 file changed, 5 insertions(+)
make-sqlitedb.py +5 -0
@@ -163,6 +163,11 @@ def keyring_load_sig_data(c, pub_keyid_rowid_map, uid_hash_rowid_map): ignored_sigs += 1 continue + # skip SHA-1 based signatures + if fields[15] == "2": + ignored_sigs += 1 + continue + # do we have the key that signed it? if sigkeyid in pub_keyid_rowid_map.keys(): uidsigs[sigkeyid] = (
Signature · 1 line
2.47.2