[PATCH] wireless-regdb: Replace M2Crypto with cryptography package

Ben Hutchings <[email protected]> Mon, 16 Feb 2026 21:03:34 +0100
Newsgroups org.infradead.lists.wireless-regdb,org.kernel.vger.linux-wireless
Message-ID <[email protected]>
--+uwxLKIdrtAFiZHR
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

M2Crypto is deprecated by its maintainers in favour of the
cryptography package.  Update db2bin.py to use that for signing
regulatory.bin.

Signed-off-by: Ben Hutchings <[email protected]>
---
This applies on top of the preceding fix for M2Crypto usage, but I can
squash them together if it's preferable to switch directly to
cryptography.

Ben.

--- a/db2bin.py
+++ b/db2bin.py
@@ -2,7 +2,6 @@
=20
 from io import BytesIO, open
 import struct
-import hashlib
 from dbparse import DBParser
 import sys
=20
@@ -125,19 +124,18 @@ if len(sys.argv) > 3:
     # Load RSA only now so people can use this script
     # without having those libraries installed to verify
     # their SQL changes
-    from M2Crypto import RSA
+    from cryptography.hazmat.primitives import hashes, serialization
+    from cryptography.hazmat.primitives.asymmetric import padding
=20
     # determine signature length
-    key =3D RSA.load_key(sys.argv[3])
-    hash =3D hashlib.sha1()
-    hash.update(output.getvalue())
-    sig =3D key.sign(hash.digest(), algo=3D'sha1')
+    with open(sys.argv[3], 'rb') as key_file:
+        key =3D serialization.load_pem_private_key(key_file.read(),
+                                                 password=3DNone)
+    sig =3D key.sign(output.getvalue(), padding.PKCS1v15(), hashes.SHA1())
     # write it to file
     siglen.set(len(sig))
     # sign again
-    hash =3D hashlib.sha1()
-    hash.update(output.getvalue())
-    sig =3D key.sign(hash.digest(), algo=3D'sha1')
+    sig =3D key.sign(output.getvalue(), padding.PKCS1v15(), hashes.SHA1())
=20
     output.write(sig)
 else:

--+uwxLKIdrtAFiZHR
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEErCspvTSmr92z9o8157/I7JWGEQkFAmmTeBYACgkQ57/I7JWG
EQmwUBAAsQYVWUgDmqv3A71GUQEC4GfToWFarALWU/0yTAVYeymowHPG6L+qR+Xo
sagMGKQS2dX65eVlk2ICVe8QW+dbApBPI/QjgXPW7rdP1I8BmT90x46NyG7IeQQV
ua0BruwReSyvD4RqsxRFo2gZ51OYJ7hcIqvYV3YgZ9jMWok0zHEa+uWo2Um8LDdS
A0iIdXDXob/bzcHOVTYgb21mrVXJBzOzQv4bmoxy0uO7CGgj7gOfchZblktRKym6
N6IMMBfvGxSjWsJokCVW/KnjNDbzTfr90lKoeSLYsY+6eVbNf+iclBP8VIkjkipI
eF5XIoL1wA+bAKfE7S+qVMdX73To+PQJOk+JOPau6y0tikhUzY83QM/IvvipPYjC
NDWivoZKcWWUJBXCmm+x4k6E3sY6G9lHD1mBGsWOwLetK1CYdjrDd664lnN6Z2Io
IMJ1iMG0fpanI/gIuo/rTcr/h17Qa9Qn50Vw4/EaU8u25kCixK+J+fzrPXdefudQ
EXY/DKJAId0oa5jIS0QBCWy5PU+kDJK8cZuWP2KyWvvsZZXeUO3j5o8B/a67WEso
aucCvVkC9s7KzQq9CVJJsXiWEHOUhT97yOAejYwZEdeZQHv+9iGHe1PNRU8PyVgE
KPkbZRAlA52VSfovUS/7ixM7LAUODieDiDSFtlkXN80GPPkAxbQ=
=MGXt
-----END PGP SIGNATURE-----

--+uwxLKIdrtAFiZHR--