Skip to contentSkip to conversation

Updates to wotmate, partly due to changed behaviour in gpg

PATCH Superseded Uwe Kleine-König 1 participant 5 messages May 12, 2025

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover Updates to wotmate, partly due to changed behaviour in gpg

Hello,

there is only a single change since v2
(https://lore.kernel.org/tools/[email protected]):
The comparison between old and new txt representation of the trust path was using

if key_paths_repr not in old_key_paths_repr:
trust_changed = True

however that failed to detect a trust change if key_paths_repr became empty (or in general: smaller). Considering that in patches #3 and #4 quite some trust paths are ripped, this is a relevant change.

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
#1 lore raw

PATCH v3 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
index 6cf95f99738d..e5e6d3787774 100755
@@ -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 != 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
#2 lore raw

PATCH v3 2/4 export-keyring: Continue updating keys that lost all their trust paths

In reply to Uwe Kleine-König

With 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
index e5e6d3787774..5a30f3ff6927 100755
@@ -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
#3 lore raw

PATCH v3 3/4 export-keyring: Default to store "clean" public keys

In reply to Uwe Kleine-König

There 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
index 5a30f3ff6927..63e6a49b5f3a 100755
@@ -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
#4 lore raw

PATCH v3 4/4 make-sqlitedb: Don't consider SHA-1 signatures for trust paths

In reply to Uwe Kleine-König
---
 make-sqlitedb.py | 5 +++++
 1 file changed, 5 insertions(+)
make-sqlitedb.py +5 -0
index fec199def51d..e8c5969f4d50 100755
@@ -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