Cleanup, a fix and txt representation for trust path finding
v4 cover Cleanup, a fix and txt representation for trust path finding
Hello,
This is v4 of the series that I called "Updates to wotmate, partly due to changed behaviour in gpg" before. Now it does some more things, so I renamed. The previous submission is available at
https://lore.kernel.org/tools/[email protected]/
While testing different things with the kernel pgpkeys data and trying to understand the path finding algorithm I wondered if that couldn't be done in a simpler and then also faster way.
It turned out that using Dijkstra's algorithm isn't faster (which I find surprising) but the algorithm I implemented finds some more valid paths. I didn't debug where the old algorithm prunes these, see the commit log of patch #3 for an example.
The first patch (as before) isn't needed for the fix in patch #3, but as it simplifies reviewing the emitted graphs, I kept it at the start. The only difference to v3 here is that the txt file also contains the certificate IDs now which was helpful while debugging the path finding procedure and which is also a useful information there.
The second patch is a new simplification.
Patch #3 contains the new path finding algorithm.
Patches #4 to #6 are just rebased and the commit log slightly improved. They were patches #2 to #4 before and care to follow GnuPG in not trusting SHA-1 based 3rd-party signatures any more.
Note this also supersedes
https://lore.kernel.org/tools/[email protected]/
which is a fix for the old algorithm.
For maximal transparency I suggest to do
touch empty
korg-update-pgpkeys empty
in the korg-pgpkeys repo after patches #1, #3 and #6 with the linter check dropped (just comment out the continue in the if not wotmate.lint(keydata) block. Short-cutting the linter has the effect that the txt files and svg updates are also done for keys with SHA-1 self signatures.
After #1 this is a noop to the keys but it introduces the trust path txt files which also regenerates the svg files. After #3 the fixed algorithm is used showing the paths missed before. After #6 the SHA-1 signatures are ignored which reduce the WoT considerably.
For reference I created
https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/pgpkeys.git wotmate-changes
where I implement these changes to the kernel pgpkeys repo.
Best regards
Uwe
Uwe Kleine-König (6):
Put a representation of the trust path in a txt file
get_all_signed_by: Return a plain list instead of a list of 1-tuples
get_key_paths: Fix path searching with an easier algorithm
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 ++ wotmate/__init__.py | 151 ++++++++++++++++-------------------------- 3 files changed, 160 insertions(+), 152 deletions(-)
base-commit: f146a1815ad93b2f318e0a5fa857b11814a78b8b
Signature · 1 line
2.47.2
PATCH v4 1/6 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 +++++++++++++++++++++++++++----------------- wotmate/__init__.py | 14 ++-- 2 files changed, 106 insertions(+), 63 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): + kid, kpuid = wotmate.get_pub_uid_by_pubrow(c, rowid) + kpblock += f' {lvl}' if lvl > 0 else f'from' + kpblock += f' {kid} {kpuid}\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 != 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)
wotmate/__init__.py +9 -5
@@ -31,15 +31,19 @@ logger = logging.getLogger(__name__) # convenience caching to avoid redundant look-ups _all_signed_by_cache = dict() _all_sigs_cache = dict() -_all_uiddata_cache = dict() +_all_pub_uiddata_cache = dict() _seenkeys = set() +def get_pub_uid_by_pubrow(c, p_rowid): + if p_rowid not in _all_pub_uiddata_cache: + c.execute('SELECT pub.keyid, uid.uiddata FROM uid JOIN pub ON uid.pubrowid = pub.rowid WHERE pubrowid=?', (p_rowid,)) + _all_pub_uiddata_cache[p_rowid] = c.fetchone() + return _all_pub_uiddata_cache[p_rowid] + + def get_uiddata_by_pubrow(c, p_rowid): - if p_rowid not in _all_uiddata_cache: - c.execute('SELECT uiddata FROM uid WHERE pubrowid=?', (p_rowid,)) - _all_uiddata_cache[p_rowid] = c.fetchone()[0] - return _all_uiddata_cache[p_rowid] + return get_pub_uid_by_pubrow(c, p_rowid)[1] def get_logger(quiet=False):
Signature · 1 line
2.47.2
PATCH v4 2/6 get_all_signed_by: Return a plain list instead of a list of 1-tuples
In reply to Uwe Kleine-KönigThis allows to simplify the callers accordingly.
--- wotmate/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
wotmate/__init__.py +5 -5
@@ -162,7 +162,7 @@ def get_all_signed_by(c, p_rowid): c.execute('''SELECT DISTINCT uid.pubrowid FROM uid JOIN sig ON sig.uidrowid = uid.rowid WHERE sig.pubrowid=?''', (p_rowid,)) - _all_signed_by_cache[p_rowid] = c.fetchall() + _all_signed_by_cache[p_rowid] = [pubrowid for (pubrowid,) in c.fetchall()] return _all_signed_by_cache[p_rowid]
@@ -263,7 +263,7 @@ def get_shortest_path(c, t_p_rowid, b_p_rowid, depth, maxdepth, ignorekeys): depth += 1 sigs = get_all_signed_by(c, t_p_rowid) - if (b_p_rowid,) in sigs: + if b_p_rowid in sigs: return [t_p_rowid, b_p_rowid] shortest = None
@@ -271,7 +271,7 @@ def get_shortest_path(c, t_p_rowid, b_p_rowid, depth, maxdepth, ignorekeys): if depth >= maxdepth: return None - for (s_p_rowid,) in sigs: + for s_p_rowid in sigs: if s_p_rowid in ignorekeys or (depth, s_p_rowid) in _seenkeys: continue
@@ -358,7 +358,7 @@ def get_key_paths(c, t_p_rowid, b_p_rowid, maxdepth=5, maxpaths=5): logger.critical('Top key did not sign any keys') sys.exit(1) - ignorekeys = [item for sublist in sigs for item in sublist] + [t_p_rowid] + ignorekeys = sigs + [t_p_rowid] if b_p_rowid in ignorekeys: logger.debug('Bottom key is signed directly by the top key')
@@ -369,7 +369,7 @@ def get_key_paths(c, t_p_rowid, b_p_rowid, maxdepth=5, maxpaths=5): paths = [] - for (s_p_rowid,) in sigs: + for s_p_rowid in sigs: lookedat += 1 # logger.debug('Trying "%s" (%s/%s)', get_uiddata_by_pubrow(c, s_p_rowid), lookedat, len(sigs)) path = get_shortest_path(c, s_p_rowid, b_p_rowid, 0, maxdepth-1, ignorekeys)
Signature · 1 line
2.47.2
PATCH v4 3/6 get_key_paths: Fix path searching with an easier algorithm
In reply to Uwe Kleine-KönigI didn't debug the old algorithm, but the new one finds more and shorter paths that are valid, so the path pruning was too aggressive it seems.
For example for Andreas Larsson it finds
from Linus Torvalds <[email protected]> 1 Junio C Hamano <[email protected]> 2 Geoff Levand <[email protected]> 3 Geert Uytterhoeven (Signing key) <[email protected]> 4 Andreas Larsson <[email protected]>
in the kernel keyring that the old algorithm didn't find.
The new algorithm is also more deterministic as it emits the paths in sort order (by certificate id). (Actually it's sorted by rowid of the public keys, but both gnupg and sqlite don't shuffle during import in practise.)
The new algorithm is also considerably simpler using
https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm
Runtime is comparable to the algorithm before.
One side effect is also that the graph for the root key is corrected, it was
from 79BE3E4300411886 Linus Torvalds <[email protected]> 1 79BE3E4300411886 Linus Torvalds <[email protected]>
before.
--- wotmate/__init__.py | 135 +++++++++++++++----------------------------- 1 file changed, 45 insertions(+), 90 deletions(-)
wotmate/__init__.py +45 -90
@@ -7,6 +7,7 @@ __author__ = 'Konstantin Ryabitsev <[email protected]>' import sys import subprocess import logging +import itertools from typing import Optional
@@ -232,68 +233,6 @@ def make_graph_node(c, p_rowid, show_trust=False): return anode -def cull_redundant_paths(paths, maxpaths=None): - paths.sort(key=len) - - culled = [] - chunks = [] - for path in paths: - redundant = False - pos = -2 - while pos > -len(path): - if path[pos:] in chunks: - redundant = True - break - chunks.append(path[pos:]) - pos -= 1 - - if not redundant: - culled.append(path) - if maxpaths and len(culled) >= maxpaths: - break - - return culled - - -def get_shortest_path(c, t_p_rowid, b_p_rowid, depth, maxdepth, ignorekeys): - global _seenkeys - # Zero out seenkeys at 0-depth - if depth == 0: - _seenkeys = set() - depth += 1 - sigs = get_all_signed_by(c, t_p_rowid) - - if b_p_rowid in sigs: - return [t_p_rowid, b_p_rowid] - - shortest = None - - if depth >= maxdepth: - return None - - for s_p_rowid in sigs: - if s_p_rowid in ignorekeys or (depth, s_p_rowid) in _seenkeys: - continue - - subchain = get_shortest_path(c, s_p_rowid, b_p_rowid, depth, maxdepth, ignorekeys) - if subchain: - if shortest is None or len(shortest) > len(subchain): - shortest = subchain - _seenkeys.add((depth, s_p_rowid)) - # no need to go any deeper than current shortest - maxdepth = depth - 1 + len(shortest) - else: - # if it returns with None, then this key is a dead-end at this and lower depths - for _d in range(depth, maxdepth): - _seenkeys.add((_d, s_p_rowid)) - - if shortest is not None: - _seenkeys.add((depth, t_p_rowid)) - return [t_p_rowid] + shortest - - return None - - def draw_key_paths(c, paths, graph, show_trust): seenactors = {} # make a subgraph for toplevel nodes
@@ -352,43 +291,59 @@ def get_pubrow_id(c, whatnot): def get_key_paths(c, t_p_rowid, b_p_rowid, maxdepth=5, maxpaths=5): - # Next, get rowids of all keys signed by top key - sigs = get_all_signed_by(c, t_p_rowid) - if not sigs: - logger.critical('Top key did not sign any keys') - sys.exit(1) - ignorekeys = sigs + [t_p_rowid] + def gen_uniq_paths(t_p_rowid, b_p_rowid, maxdepth): + logger.debug(f'search for {str(b_p_rowid) + " " + get_uiddata_by_pubrow(c, b_p_rowid)}') - if b_p_rowid in ignorekeys: - logger.debug('Bottom key is signed directly by the top key') - return [[t_p_rowid, b_p_rowid]] + # prioq tracks the pairs (depth, path) that need further inspection + prioq = [(0, [t_p_rowid])] - logger.debug('Found %s keys signed by top key' % len(sigs)) - lookedat = 0 + found = set() + used_keys = set() - paths = [] + while prioq: + depth, path = prioq.pop(0) - for s_p_rowid in sigs: - lookedat += 1 - # logger.debug('Trying "%s" (%s/%s)', get_uiddata_by_pubrow(c, s_p_rowid), lookedat, len(sigs)) - path = get_shortest_path(c, s_p_rowid, b_p_rowid, 0, maxdepth-1, ignorekeys) - if path: - logger.debug('`- found a path with %s members' % len(path)) - paths.append([t_p_rowid] + path) - if len(path) > 2: - ignorekeys += path[1:-2] + if path[-1] in found: + # We already know a path to `path[-1]` of depth <= `depth` + continue - if not paths: + if path[-1] == b_p_rowid: + logger.debug(f'found: {[str(p) + " " + get_uiddata_by_pubrow(c, p) for p in path]} @{depth=}') + yield path + + # if we found a path of length 1, this is good enough + if depth <= 1: + return + + new_used_keys = set(path[1:-1]) + used_keys.update(new_used_keys) + + # We might have pruned some paths that are interesting again now that there are new keys in used_keys + prioq = [(0, [t_p_rowid])] + found = set() + continue + + #logger.debug(f'consider: {[str(p) + " " + get_uiddata_by_pubrow(c, p) for p in path]} @{depth=}') + + # We found a shortest path to path[-1], so we don't need to consider further paths leading to it + found.add(path[-1]) + + if depth < maxdepth: + sigs = set(get_all_signed_by(c, path[-1])) - used_keys - found + + # If the cert to find a path for is reachable from path[-1], the other sigs are not interesting + if b_p_rowid in sigs: + prioq.append((depth + 1, path + [b_p_rowid])) + else: + prioq.extend((depth + 1, path + [s]) for s in sorted(sigs)) + + ret = list(itertools.islice(gen_uniq_paths(t_p_rowid, b_p_rowid, maxdepth), maxpaths)) + if not ret: logger.info('No valid paths between %s and %s', get_uiddata_by_pubrow(c, t_p_rowid), get_uiddata_by_pubrow(c, b_p_rowid)) - return [] - - culled = cull_redundant_paths(paths, maxpaths) - logger.debug('%s paths left after culling' % len(culled)) - - return culled + return ret def get_u_key(c): c.execute('''SELECT rowid
Signature · 1 line
2.47.2
PATCH v4 4/6 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 v4 5/6 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.
An arguable 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 v4 6/6 make-sqlitedb: Don't consider SHA-1 signatures for trust paths
In reply to Uwe Kleine-KönigGnuPG stopped trusting 3rd party signatures based on the SHA-1 hash algorithm. Follow that change and skip these signatures.
--- 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
Quoted 6 lines · Uwe Kleine-König
Hello,
This is v4 of the series that I called "Updates to wotmate, partly due to changed behaviour in gpg" before. Now it does some more things, so I renamed. The previous submission is available at
https://lore.kernel.org/tools/[email protected]/
Thank you for working on this! I've applied and run it in my test environment as you suggested (against an empty file). However, I see that it creates a bunch of zero-length graphs/*.txt files due to a lot of paths no longer working when we exclude sha1. That's something to improve, but can be done as a revision on top of this series.
For now, I've disabled the sha1 exclusion and rerun this on the keyring. Looks good to me, so the changes are in now.
I'll work with the top keyring introducers to strengthen some of the core paths before we try disabling sha1 again -- hopefully with less drastic results.
Best wishes,
-K
Hello Konstantin,
Quoted 11 lines · Konstantin Ryabitsev
Quoted 4 lines · Uwe Kleine-König
This is v4 of the series that I called "Updates to wotmate, partly due to changed behaviour in gpg" before. Now it does some more things, so I renamed. The previous submission is available at
https://lore.kernel.org/tools/[email protected]/Thank you for working on this! I've applied and run it in my test environment as you suggested (against an empty file). However, I see that it creates a bunch of zero-length graphs/*.txt files due to a lot of paths no longer working when we exclude sha1. That's something to improve, but can be done as a revision on top of this series.
What would you wish to have in the txt files for a key that has no more valid path from Linus? Maybe just don't create it? (Actually I like an empty file because then each .svg file has a .txt file and it's easy to determine with keys have no path.)
Quoted 2 lines
For now, I've disabled the sha1 exclusion and rerun this on the keyring. Looks good to me, so the changes are in now.
Looking at your change to the pgpkeys repo you still got rid of many SHA-1 signatures due to commit b088af1f40a5 ("export-keyring: Default to store \"clean\" public keys") as cleaning implies pruning weak signatures. The effect is only limited because the linter check prevents several keys from being updated. So because e.g. Greg's key (38DBBDC86092693E) uses a SHA-1 protected User ID, it doesn't lose Linus' signature.
I think if we want to keep the SHA-1 sigs for a while, we should do:
export-keyring.py +1 -1
@@ -101,7 +101,7 @@ if __name__ == '__main__': for (to_rowid, kid, uiddata) in c.fetchall(): kcount += 1 # First, export the key - args = ['-a', '--export', '--export-options', cmdargs.key_export_options, kid] + args = ['-a', '--export', '--allow-weak-digest-algos', '--export-options', cmdargs.key_export_options, kid] keydata = wotmate.gpg_run_command(args, with_colons=False) keyout = os.path.join(keydir, '%s.asc' % kid)
and maybe redo 89ce0eaa9633 ("Initial rerun after wotmate changes")[1]. Then Greg also gets a flattering 38DBBDC86092693E.txt and with him 280 others.
Quoted 3 lines
I'll work with the top keyring introducers to strengthen some of the core paths before we try disabling sha1 again -- hopefully with less drastic results.
We already talked about that via irc, just restating it here for public awareness:
This doesn't necessarily need a keysigning event. If Linus still remembers to have signed Greg's key 38DBBDC86092693E after carefully checking his ID and fingerprint, he can just resign it with more modern tools and settings.
This might work using:
gpg --force-sign-key --quick-sign-key 647F28654894E3BD457199BE38DBBDC86092693E "Greg Kroah-Hartman (Linux kernel stable release signing key) <[email protected]>"; gpg --keyserver "hkps://keyserver.ubuntu.com/" --send-key 647F28654894E3BD457199BE38DBBDC86092693E;
(Obviously I cannot test exactly that as I don't have access to Linus' private key. :-)
Best regards
Uwe
[1] e.g. by first debuffing the linter check (that's important!) and then with the above change do:
git checkout a0bc65fb27f5 -- keys korg-update-pgpkeys empty
Hello again,
Quoted 21 lines · Uwe Kleine-König
Quoted 11 lines · Konstantin Ryabitsev
Quoted 4 lines · Uwe Kleine-König
This is v4 of the series that I called "Updates to wotmate, partly due to changed behaviour in gpg" before. Now it does some more things, so I renamed. The previous submission is available at
https://lore.kernel.org/tools/[email protected]/Thank you for working on this! I've applied and run it in my test environment as you suggested (against an empty file). However, I see that it creates a bunch of zero-length graphs/*.txt files due to a lot of paths no longer working when we exclude sha1. That's something to improve, but can be done as a revision on top of this series.
What would you wish to have in the txt files for a key that has no more valid path from Linus? Maybe just don't create it? (Actually I like an empty file because then each .svg file has a .txt file and it's easy to determine with keys have no path.)
Quoted 2 lines
For now, I've disabled the sha1 exclusion and rerun this on the keyring. Looks good to me, so the changes are in now.
Quoted 7 lines
Looking at your change to the pgpkeys repo you still got rid of many SHA-1 signatures due to commit
b088af1f40a5("export-keyring: Default to store \"clean\" public keys") as cleaning implies pruning weak signatures. The effect is only limited because the linter check prevents several keys from being updated. So because e.g. Greg's key (38DBBDC86092693E) uses a SHA-1 protected User ID, it doesn't lose Linus' signature.
One side effect of how SHA-1 signatures got thrown away is that the graphs (both svg and txt) were generated with these SHA-1 signatures but they didn't make it into the updated keys. For example 8972F4DFDC6DC026.txt currently looks as follows:
from 79BE3E4300411886 Linus Torvalds <[email protected]> 1 8972F4DFDC6DC026 Kees Cook <[email protected]>
But keys/8972F4DFDC6DC026.asc doesn't have a signature by 79BE3E4300411886 any more. So if you run
korg-update-pgpkeys empty
once more, this signature isn't available any more and Kees' trust path degenerates to:
from 79BE3E4300411886 Linus Torvalds <[email protected]> 1 17212997986C5765 Benson Leung <[email protected]> 2 8972F4DFDC6DC026 Kees Cook <[email protected]>
from 79BE3E4300411886 Linus Torvalds <[email protected]> 1 7C56ACFE947897D8 Anibal Monsalve Salazar <[email protected]> 2 8972F4DFDC6DC026 Kees Cook <[email protected]>
from 79BE3E4300411886 Linus Torvalds <[email protected]> 1 80A77F6095CDE47E Stephen Hemminger (Microsoft corporate) <[email protected]> 2 8972F4DFDC6DC026 Kees Cook <[email protected]>
from 79BE3E4300411886 Linus Torvalds <[email protected]> 1 2EA76B9C2B466D9D John Hawley ("Warthog9") <[email protected]> 2 41633B9FE837F581 Mike Frysinger <[email protected]> 3 8972F4DFDC6DC026 Kees Cook <[email protected]>
Also there is another bug in export-keyring.py that prevented that a graph for 000E684119568215 (and several others) was generated. These will also appear if you rerun korg-update-pgpkeys empty without the linter check.
I'll prepare a patch for that later (maybe tomorrow).
export-keyring.py if __name__ == '__main__': · line 104
Quoted 12 lines
I think if we want to keep the SHA-1 sigs for a while, we should do:
export-keyring.py +1
-1@@ -101,7 +101,7 @@ if __name__ == '__main__': for (to_rowid, kid, uiddata) in c.fetchall(): kcount += 1 # First, export the key - args = ['-a', '--export', '--export-options', cmdargs.key_export_options, kid] + args = ['-a', '--export', '--allow-weak-digest-algos', '--export-options', cmdargs.key_export_options, kid]
Maybe we need --allow-weak-key-signatures here instead of (or additionally to) --allow-weak-digest-algos. That will be part of the next patch set, too---once I understood the effects completely.
export-keyring.py if __name__ == '__main__': · line 106
Quoted 2 lines
export-keyring.py +0
-0keydata = wotmate.gpg_run_command(args, with_colons=False) keyout = os.path.join(keydir, '%s.asc' % kid)
Best regards
Uwe
Quoted 8 lines · Uwe Kleine-König
Quoted 7 lines
Looking at your change to the pgpkeys repo you still got rid of many SHA-1 signatures due to commit
b088af1f40a5("export-keyring: Default to store \"clean\" public keys") as cleaning implies pruning weak signatures. The effect is only limited because the linter check prevents several keys from being updated. So because e.g. Greg's key (38DBBDC86092693E) uses a SHA-1 protected User ID, it doesn't lose Linus' signature.
Quoted 4 lines
One side effect of how SHA-1 signatures got thrown away is that the graphs (both svg and txt) were generated with these SHA-1 signatures but they didn't make it into the updated keys. For example 8972F4DFDC6DC026.txt currently looks as follows:
I just pushed a big update that adds a --use-weak-algos flag to two commands. It also adds a bunch of typing data, so we can use linters a bit better.
Quoted 9 lines
from 79BE3E4300411886 Linus Torvalds <[email protected]> 1 8972F4DFDC6DC026 Kees Cook <[email protected]>But keys/8972F4DFDC6DC026.asc doesn't have a signature by 79BE3E4300411886 any more. So if you run
korg-update-pgpkeys empty
once more, this signature isn't available any more
I think I fixed things up now to avoid this problem. It looks noisy, but for the end-users it won't make much difference, since their gnupg will be ignoring those signatures anyway.
Quoted 1 line
I'll prepare a patch for that later (maybe tomorrow).
Please grab the latest master! I think this is already in there, but feel free to build on top of that.
Thanks!
-K
Hello Konstantin,
Quoted 9 lines · Konstantin Ryabitsev
Quoted 8 lines · Uwe Kleine-König
Quoted 7 lines
Looking at your change to the pgpkeys repo you still got rid of many SHA-1 signatures due to commit
b088af1f40a5("export-keyring: Default to store \"clean\" public keys") as cleaning implies pruning weak signatures. The effect is only limited because the linter check prevents several keys from being updated. So because e.g. Greg's key (38DBBDC86092693E) uses a SHA-1 protected User ID, it doesn't lose Linus' signature.
Quoted 7 lines
Quoted 4 lines
One side effect of how SHA-1 signatures got thrown away is that the graphs (both svg and txt) were generated with these SHA-1 signatures but they didn't make it into the updated keys. For example 8972F4DFDC6DC026.txt currently looks as follows:
I just pushed a big update that adds a --use-weak-algos flag to two commands. It also adds a bunch of typing data, so we can use linters a bit better.
Would have been nice to split it into (at least) three commits, but *shrug*
Quoted 6 lines
Quoted 6 lines
from 79BE3E4300411886 Linus Torvalds <[email protected]> 1 8972F4DFDC6DC026 Kees Cook <[email protected]>But keys/8972F4DFDC6DC026.asc doesn't have a signature by 79BE3E4300411886 any more. So if you run
Quoted 7 lines
Quoted 3 lines
korg-update-pgpkeys empty
once more, this signature isn't available any more
I think I fixed things up now to avoid this problem. It looks noisy, but for the end-users it won't make much difference, since their gnupg will be ignoring those signatures anyway.
I looked into the pgpkeys repo changes and while I didn't check all changes, the ones I checked look sane. Thanks!
Quoted 4 lines
Quoted 1 line
I'll prepare a patch for that later (maybe tomorrow).
Please grab the latest master! I think this is already in there, but feel free to build on top of that.
Will do. I don't know yet how to address the shortcomings I'm still seeing. The procedure is probably:
- import keys/*.asc
- do updates (add new key material or gpg --refresh)
- clean all keys
- generate graphs from all signatures still in the gpg keyring
- update valid keys and write out graphs
Then the split into make-sqlitedb.py and export-keyring.py doesn't make much sense and maybe we can also strip out the sqlite stuff completely?! (I wonder if sqlite is a sensible option already now, I wouldn't have considered that at all but just pickled the signature info into a file.)
Best regards
Uwe
Quoted 5 lines · Uwe Kleine-König
Quoted 2 lines
I just pushed a big update that adds a --use-weak-algos flag to two commands. It also adds a bunch of typing data, so we can use linters a bit better.
Would have been nice to split it into (at least) three commits, but *shrug*
Yes, I know I could have done it cleaner, but I had limited time and didn't have a chance to work on properly staging the commits. Mea culpa.
Quoted 2 lines
Then the split into
make-sqlitedb.pyandexport-keyring.pydoesn't make much sense and maybe we can also strip out the sqlite stuff completely?!
I think the main reason it's there is because we issue a bunch of queries when looking for key relationships. The other reason is because I was planning to set up a web service that allowed generating graphs on the fly using the pre-generated sqlite db (i.e. "find a path between these two arbitrary keys in the keyring). However, that never ended up happening and definitely won't happen at this point.
Quoted 2 lines
(I wonder if sqlite is a sensible option already now, I wouldn't have considered that at all but just pickled the signature info into a file.)
I don't think replacing sqlite is worth the effort, but if you find a better option, I don't see why we have to keep it.
-K
Konstantin Ryabitsev
AppliedQuoted 10 lines · Uwe Kleine-König
This is v4 of the series that I called "Updates to wotmate, partly due to changed behaviour in gpg" before. Now it does some more things, so I renamed. The previous submission is available at
https://lore.kernel.org/tools/[email protected]/While testing different things with the kernel pgpkeys data and trying to understand the path finding algorithm I wondered if that couldn't be done in a simpler and then also faster way.
[...]
Applied, thanks!
[1/6] Put a representation of the trust path in a txt file
commit: 5dc1be5c03f06b0c508f4e41773092f8329d3915
[2/6] get_all_signed_by: Return a plain list instead of a list of 1-tuples
commit: 0b03c5aa1dfdb01eaae83a3388cf539cf601eb2e
[3/6] get_key_paths: Fix path searching with an easier algorithm
commit: 4c2269fea9b40134837cce046e8f2281e863b844
[4/6] export-keyring: Continue updating keys that lost all their trust paths
commit: 19dda191291ff897378f9924b5516318463d0ef8
[5/6] export-keyring: Default to store "clean" public keys
commit: b088af1f40a56644d260ab9e18085a1b6b5ae31e
[6/6] make-sqlitedb: Don't consider SHA-1 signatures for trust paths
commit: ece92eb6c5c33cf9981adad0b1c1b0f32621e189Best regards,
Signature · 1 line
Konstantin Ryabitsev <[email protected]>