aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/pluginloader/meson.build3
-rwxr-xr-xlib/pluginloader/ssl-keygen.py58
2 files changed, 60 insertions, 1 deletions
diff --git a/lib/pluginloader/meson.build b/lib/pluginloader/meson.build
index b93bf42..cbca725 100644
--- a/lib/pluginloader/meson.build
+++ b/lib/pluginloader/meson.build
@@ -5,8 +5,9 @@ private_pem = meson.build_root() / get_option('ssl_private_pem')
public_pem = meson.build_root() / get_option('ssl_public_pem')
publicKey_h = custom_target('publicKey_h',
+ input: files('ssl-keygen.py'),
output: 'publicKey.h',
- command: [python3, meson.source_root() / 'tools/ssl-keygen.py',
+ command: [python3, '@INPUT@',
'--private=' + private_pem, '--public=' + public_pem,
'--output=@OUTPUT@', '--array-name=publicKey_pem']
)
diff --git a/lib/pluginloader/ssl-keygen.py b/lib/pluginloader/ssl-keygen.py
new file mode 100755
index 0000000..7feaf1a
--- /dev/null
+++ b/lib/pluginloader/ssl-keygen.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python3
+
+import argparse
+import sys
+import os.path
+import subprocess
+from functools import partial
+
+def generate_private_key(out_pem='privateKey.pem'):
+ subprocess.run(['openssl', 'genrsa', '-out', out_pem, '4096'], check=True)
+
+def generate_public_key(in_pem='privateKey.pem', out_pem='publicKey.pem'):
+ subprocess.run(['openssl', 'rsa', '-in', in_pem, '-pubout', '-out', out_pem], check=True)
+
+def hexdump(array_type, array_name, length_type, in_pem, out_h):
+ array_len = 0
+
+ print("// Autogenerated hex dump of OpenSSL public key, do not edit", file=out_h)
+ print("{} {}[] = {{".format(array_type, array_name), file=out_h)
+
+ for line in iter(partial(in_pem.read, 16), b''):
+ array_len += len(line)
+ l = list(line)
+ for n, i in enumerate(l):
+ l[n] = '0x{:02X}'.format(i)
+
+ print(" {},".format(", ".join(l)), file=out_h)
+
+ print("};", file=out_h)
+ print("{} {}_len = {};".format(length_type, array_name, array_len), file=out_h)
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser(description='Generate OpenSSL key and hexdump')
+
+ parser.add_argument('--private', default='privateKey.pem', type=str, help='Private key input')
+ parser.add_argument('--public', default='publicKey.pem', type=str, help='Public key input')
+
+ parser.add_argument('--output', type=argparse.FileType('wt'), default=sys.stdout, help='Output file')
+
+ parser.add_argument('--array-type', type=str, default='const unsigned char', help='Array type')
+ parser.add_argument('--length-type', type=str, default='const unsigned int', help='Length type')
+ parser.add_argument('--array-name', type=str, default='a', help='Array name')
+
+ args=parser.parse_args()
+
+ # check if public key exists
+ if not os.path.isfile(args.public):
+ # if there is no private key, generate one
+ if not os.path.isfile(args.private):
+ generate_private_key(args.private)
+
+ # export public key from private
+ generate_public_key(args.private, args.public)
+
+ with open(args.public, "rb") as public_pem:
+ hexdump(args.array_type, args.array_name, args.length_type, public_pem, args.output)
+
+