-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_mega_chain.py
More file actions
29 lines (25 loc) · 1.1 KB
/
create_mega_chain.py
File metadata and controls
29 lines (25 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os
import subprocess
def create_chain():
outfile = "DoD_Mega_Chain.pem"
with open(outfile, "w") as f_out:
for root, dirs, files in os.walk("."):
for file in files:
if file.endswith(".p7b"):
path = os.path.join(root, file)
print(f"Processing {path}...")
# Try PEM
cmd = ["openssl", "pkcs7", "-in", path, "-print_certs"]
res = subprocess.run(cmd, capture_output=True, text=True)
if res.returncode == 0:
f_out.write(res.stdout)
continue
# Try DER
cmd = ["openssl", "pkcs7", "-in", path, "-inform", "DER", "-print_certs"]
res = subprocess.run(cmd, capture_output=True, text=True)
if res.returncode == 0:
f_out.write(res.stdout)
else:
print(f"Failed to process {path}")
if __name__ == "__main__":
create_chain()