Skip to contentSkip to conversation

Some wotmate updates

PATCH Applied Uwe Kleine-König 2 participants 5 messages Feb 28, 2025

lore
Share & tools
lore
#0 lore raw

cover Some wotmate updates

Hello,

this series consists of one minor fix, an addition of comments to improve readability and a tighter check for key updates.

The fix ("Fix foreign key references in sig table") has little practical relevance. But it helps a bit if you look at the generated database with sqlitebrowser.

The stricter check for key updates relates to
https://lore.kernel.org/keys/c7klbj6xvzcfx63gid5iancjg6cv4krgm2wk6wfijwebq7bxtr@songleund4fm/
. The TL;DR; is: In the past SHA-1 hashes were used to bind subkeys and uids to the master key. Cryptologists consider SHA-1 broken since 20 years[1]. Keys making use of SHA-1 in that way can be repaired. The procedure is explained in a follow-up to the above mail.

Note that this check also fails if you don't have Sequoia sq installed, which is IMHO fine.

Best regards
Uwe

[1] https://www.schneier.com/blog/archives/2005/02/sha1_broken.html

Uwe Kleine-König (3):
Fix foreign key references in sig table
maks-sqlitedb: Annotate fields from gpg --with-colons for feeding in
the db
export-keyring: Only accept changes that please the Sequoia linter

 export-keyring.py   |  4 ++++
 make-sqlitedb.py    | 22 +++++++++++-----------
 wotmate/__init__.py | 11 +++++++++--
 3 files changed, 24 insertions(+), 13 deletions(-)

base-commit: a9716d31c7f8f2419d2a88c69dfedf9cda3e80c0

Signature · 1 line
2.47.1
#1 lore raw

PATCH 1/3 Fix foreign key references in sig table

uidrowid references the rowid of to uid table, not the pub table. Similar for pubrowid.

---
 wotmate/__init__.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
wotmate/__init__.py +2 -2
index b947a41e7eb2..402e9dd735ba 100644
@@ -140,8 +140,8 @@ def init_sqlite_db(c):
                   created TEXT,
                   expires TEXT,
                   sigtype INTEGER,
-                  FOREIGN KEY(uidrowid) REFERENCES pub(rowid),
-                  FOREIGN KEY(pubrowid) REFERENCES uid(rowid),
+                  FOREIGN KEY(uidrowid) REFERENCES uid(rowid),
+                  FOREIGN KEY(pubrowid) REFERENCES pub(rowid),
                   PRIMARY KEY (uidrowid, pubrowid)
                  ) WITHOUT ROWID''')
 
Signature · 1 line
2.47.1
#2 lore raw

PATCH 2/3 maks-sqlitedb: Annotate fields from gpg --with-colons for feeding in the db

In reply to Uwe Kleine-König

This change helped me to understand what happens when working with the code.

---
 make-sqlitedb.py | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
make-sqlitedb.py +11 -11
index 6a4999b636a5..fec199def51d 100755
@@ -32,13 +32,13 @@ def keyring_load_pub_uid(c, use_weak):
                 continue
 
             data = (
-                    fields[4],
-                    fields[1],
-                    fields[2],
-                    fields[3],
-                    fields[5],
-                    fields[6],
-                    fields[8],
+                    fields[4], # KeyID
+                    fields[1], # Validity
+                    fields[2], # Key length
+                    fields[3], # Public key algorithm
+                    fields[5], # Creation date
+                    fields[6], # Expiration date
+                    fields[8], # Ownertrust
                    )
             c.execute('INSERT INTO pub VALUES (?,?,?,?,?,?,?)', data)
             current_pubkey = fields[4]
@@ -53,10 +53,10 @@ def keyring_load_pub_uid(c, use_weak):
             if current_pubrowid is not None:
                 data = (
                     current_pubrowid,
-                    fields[1],
-                    fields[5],
-                    fields[6],
-                    fields[9],
+                    fields[1], # Validity
+                    fields[5], # Creation date
+                    fields[6], # Expiration date
+                    fields[9], # User-ID
                     is_primary,
                 )
                 c.execute('INSERT INTO uid VALUES (?,?,?,?,?,?)', data)
Signature · 1 line
2.47.1
#3 lore raw

PATCH 3/3 export-keyring: Only accept changes that please the Sequoia linter

In reply to Uwe Kleine-König

As of Sequoia sq 1.2.0 the linter criticizes the usage of SHA-1 that affects quite a lot of keys already in the keyring. To ensure the problem doesn't get worse, only accept updates and new keys that don't make use of that hash algo that is considered unsecure since 20 years.

---
 export-keyring.py   | 4 ++++
 wotmate/__init__.py | 7 +++++++
 2 files changed, 11 insertions(+)
export-keyring.py +4 -0
index abd15b3ffb39..6cf95f99738d 100755
@@ -119,6 +119,10 @@ if __name__ == '__main__':
         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)
wotmate/__init__.py +7 -0
index 402e9dd735ba..128a183f2c9a 100644
@@ -78,6 +78,13 @@ def gpg_run_command(args: list, with_colons: bool = True, stdin: Optional[bytes]
     return output
 
 
+def lint(keydata: bytes) -> bool:
+    sp = subprocess.Popen('sq cert -q lint'.split(), stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE, env=None)
+    sp.communicate(input=keydata)
+
+    return sp.returncode == 0
+
+
 def gpg_get_lines(args, matchonly=()):
     output = gpg_run_command(args)
     lines = []
Signature · 1 line
2.47.1
#4 lore raw
In reply to Uwe Kleine-König
Quoted 8 lines · Uwe Kleine-König

this series consists of one minor fix, an addition of comments to improve readability and a tighter check for key updates.

The fix ("Fix foreign key references in sig table") has little practical relevance. But it helps a bit if you look at the generated database with sqlitebrowser.

[...]

Applied, thanks!

[1/3] Fix foreign key references in sig table

      commit: c29a88449fb90a776f30cca4bf57f8ab1707e0db
[2/3] maks-sqlitedb: Annotate fields from gpg --with-colons for feeding in the db
      commit: d644b413b1f6e1606e9f4b8eae92538e738efa39
[3/3] export-keyring: Only accept changes that please the Sequoia linter
      commit: 11543a5fad7831a8802e99106f6be7cef94b5476

Best regards,

Signature · 1 line
Konstantin Ryabitsev <[email protected]>