summaryrefslogtreecommitdiff
path: root/utils/codegen/gen-ipa-pub-key.py
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2024-08-08 18:13:00 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2024-08-15 23:59:08 +0300
commit50c92cc7e2924009ecab3e4004448b01d687707c (patch)
treec22b49816a3c79dae4727780962aa0928df42b52 /utils/codegen/gen-ipa-pub-key.py
parentd3bf27180ef1d91b86b7b87a2378e559eaff5455 (diff)
meson: Move all code generation scripts to utils/codegen/
We have multiple code generation scripts in utils/, mixed with other miscellaneous utilities, as well as a larger code base based on mojom in utils/ipc/. To make code sharing easier between the generator scripts, without creating a mess in the utils/ directory, move all the code generation code to utils/codegen/. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Diffstat (limited to 'utils/codegen/gen-ipa-pub-key.py')
-rwxr-xr-xutils/codegen/gen-ipa-pub-key.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/utils/codegen/gen-ipa-pub-key.py b/utils/codegen/gen-ipa-pub-key.py
new file mode 100755
index 00000000..dc3e7d5f
--- /dev/null
+++ b/utils/codegen/gen-ipa-pub-key.py
@@ -0,0 +1,48 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2020, Google Inc.
+#
+# Author: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+#
+# Generate the IPA module signing public key
+
+import string
+import subprocess
+import sys
+
+
+def main(argv):
+ if len(argv) != 4:
+ print('Usage: %s priv-key template output' % argv[0])
+ return 1
+
+ priv_key = argv[1]
+ template = argv[2]
+ output = argv[3]
+
+ try:
+ ret = subprocess.run(['openssl', 'rsa', '-pubout', '-in', priv_key,
+ '-outform', 'DER'],
+ stdout=subprocess.PIPE)
+ except FileNotFoundError:
+ print('Please install openssl to sign IPA modules')
+ return 1
+
+ ipa_key = ['0x%02x' % c for c in ret.stdout]
+ ipa_key = [', '.join(ipa_key[bound:bound + 8]) for bound in range(0, len(ipa_key), 8)]
+ ipa_key = ',\n\t'.join(ipa_key)
+ data = {'ipa_key': ipa_key}
+
+ template = open(template, 'rb').read()
+ template = template.decode('utf-8')
+ template = string.Template(template)
+
+ f = open(output, 'wb')
+ f.write(template.substitute(data).encode('utf-8'))
+ f.close()
+
+ return 0
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))