aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2019-10-13 18:25:49 +0300
committerAqua-sama <aqua@iserlohn-fortress.net>2019-10-13 18:25:49 +0300
commit22e4c0b2bfea51c9f48d0d84e527ffe4c8eb0e25 (patch)
tree296b8e0be37ffd3f46f1d66dcf7d3ffc6f0b6a8a /tools
parentAdd some cpp compiler options and warnings (diff)
downloadsmolbote-22e4c0b2bfea51c9f48d0d84e527ffe4c8eb0e25.tar.xz
Improve meson.build files
- meson should now properly create OpenSSL signing key and hexdump before trying to compile plugin loader
Diffstat (limited to 'tools')
-rwxr-xr-xtools/config.py20
-rwxr-xr-xtools/hexdump.py35
-rwxr-xr-xtools/ssl-keygen.py59
3 files changed, 59 insertions, 55 deletions
diff --git a/tools/config.py b/tools/config.py
deleted file mode 100755
index 11de99c..0000000
--- a/tools/config.py
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/usr/bin/env python3
-
-import os
-import argparse
-import subprocess
-
-if __name__ == "__main__":
- parser = argparse.ArgumentParser()
- parser.add_argument("--kconfig", metavar="Kconfig", nargs="?", default="Kconfig", help="Top-level Kconfig file (default: Kconfig)")
- parser.add_argument("--dotconfig", metavar="dotconfig", nargs="?", default=".config", help=".config")
- parser.add_argument("--generate", metavar="config_header", nargs="?", default="config.h", help="Generate config file")
-
- args = parser.parse_args()
-
- # set srctree, otherwise includes don't work
- os.environ["srctree"] = os.path.dirname(os.path.realpath(args.kconfig))
- os.environ["KCONFIG_CONFIG"] = os.path.realpath(args.dotconfig)
-
- subprocess.run(["genconfig", os.path.realpath(args.kconfig), "--header-path=" + args.generate], check=True)
-
diff --git a/tools/hexdump.py b/tools/hexdump.py
deleted file mode 100755
index c0ed2a3..0000000
--- a/tools/hexdump.py
+++ /dev/null
@@ -1,35 +0,0 @@
-#!/usr/bin/env python3
-
-import argparse
-import sys
-from functools import partial
-
-parser = argparse.ArgumentParser(description='Convert a file to C array')
-parser.add_argument('input', type=str, help='Input file')
-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('--name', type=str, default='a', help='Array name')
-
-args=parser.parse_args()
-
-print("{} {}[] = {{".format(args.array_type, args.name), file=args.output)
-
-n = 0
-
-with open(args.input, "rb") as in_file:
- for c in iter(partial(in_file.read, 1), b''):
- if n % 16 == 0:
- print(" ", end='', file=args.output)
-
- print("0x%02X," % ord(c), end='', file=args.output)
-
- n += 1
- if n % 16 == 0:
- print("", file=args.output)
- else:
- print(" ", end='', file=args.output)
-
-print("\n};", file=args.output)
-print("{} {}_len = {};".format(args.length_type, args.name, n), file=args.output)
-
diff --git a/tools/ssl-keygen.py b/tools/ssl-keygen.py
new file mode 100755
index 0000000..555b379
--- /dev/null
+++ b/tools/ssl-keygen.py
@@ -0,0 +1,59 @@
+#!/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):
+ n = 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''):
+ l = list(line)
+ for n, i in enumerate(l):
+ l[n] = '0x{:02X}'.format(i)
+
+ print(" {},".format(", ".join(l)), file=out_h)
+
+ n += 1
+
+ print("};", file=out_h)
+ print("{} {}_len = {};".format(length_type, array_name, n), 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)
+
+