diff --git a/.gitignore b/.gitignore index fe1528e..7f017d5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ .venv __pycache__ gen -original \ No newline at end of file +original +out +*pb2.py \ No newline at end of file diff --git a/Makefile b/Makefile index caa0832..d4150d5 100644 --- a/Makefile +++ b/Makefile @@ -4,4 +4,5 @@ setup-venv: setup-python: mkdir -p gen/python protoc --python_out=gen/python crs.proto - exit \ No newline at end of file + cp gen/python/crs_pb2.py src/root_store_gen + exit diff --git a/generate_new_pbs.py b/generate_new_pbs.py deleted file mode 100644 index da4ab3d..0000000 --- a/generate_new_pbs.py +++ /dev/null @@ -1,16 +0,0 @@ -import sys -import os.path as path -import pathlib -import importlib.util -import sys -import crs_pb2 -def usage(): - print("Usage: ") -cwd = path.dirname(path.abspath(sys.argv[0])) -if len(sys.argv) < 2: - usage() - exit(-1) -buf= open(sys.argv[1], 'rb') -rs = crs_pb2.RootStore() -rs.ParseFromString(buf.read()) -print(rs.trust_anchors[0]) \ No newline at end of file diff --git a/myCA.der b/myCA.der new file mode 100644 index 0000000..46da4a5 Binary files /dev/null and b/myCA.der differ diff --git a/src/root_store_gen/generate_new_pbs.py b/src/root_store_gen/generate_new_pbs.py new file mode 100644 index 0000000..d7f9f53 --- /dev/null +++ b/src/root_store_gen/generate_new_pbs.py @@ -0,0 +1,34 @@ +import sys +import os.path as path +import pathlib +import importlib.util +import sys +import crs_pb2 +def usage(): + print("Usage: ... ") +cwd = path.dirname(path.abspath(sys.argv[0])) +if len(sys.argv) < 4: + usage() + exit(-1) +cas = [] +for a in sys.argv[2:-1:]: + print(f"Registering CA from {a}") + cas.append(a) +outfile = sys.argv[-1] +print(f"Outputing to: {outfile}") +out = open(outfile, 'wb') +buf= open(sys.argv[1], 'rb') +rs = crs_pb2.RootStore() +rs.ParseFromString(buf.read()) +for ca in cas: + with open(ca, 'rb') as file: + print(f"Loading Certificate Authority {ca} into rootstore") + der = file.read() + next_trust_anchor = crs_pb2.TrustAnchor() + next_trust_anchor.Clear() + next_trust_anchor.der = der + next_trust_anchor.display_name = "Success!" + print(next_trust_anchor.constraints) + rs.trust_anchors.append(next_trust_anchor) +out.write(rs.SerializeToString()) +out.close() \ No newline at end of file diff --git a/src/root_store_gen/print_pb.py b/src/root_store_gen/print_pb.py new file mode 100644 index 0000000..634305a --- /dev/null +++ b/src/root_store_gen/print_pb.py @@ -0,0 +1,9 @@ +import crs_pb2 +import sys +if (len(sys.argv) < 2): + print("Usage: ") + exit(-1) +rs = crs_pb2.RootStore() +with open(sys.argv[1], 'rb') as f: + rs.ParseFromString(f.read()) + print(rs)