-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_truststore_file.py
32 lines (21 loc) · 1001 Bytes
/
gen_truststore_file.py
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
30
31
import subprocess
import os
def fetch_certificate_info(crt_file):
with open(crt_file) as f:
cert_data = f.read()
cert_info_start = cert_data.find("-----BEGIN CERTIFICATE-----")
cert_info_end = cert_data.find("-----END CERTIFICATE-----")
return cert_data[cert_info_start + len("-----BEGIN CERTIFICATE-----")+1:cert_info_end-1]
def process_xml_file(xml_file):
with open(xml_file) as f:
xml_data = f.read()
cert_info = fetch_certificate_info(crt_file)
xml_data = xml_data.replace('add_data_here</cert>', cert_info + '</cert>')
new_file_name = "truststore.xml"
with open(new_file_name, "w") as f:
f.write(xml_data)
if __name__ == "__main__":
xml_file = "/home/amal/Desktop/workspace/certs/IDevID_stage_automation/truststore_template.xml"
crt_file = "/home/amal/Desktop/workspace/certs/IDevID_stage_automation/certs/IDevID_ee_ser.crt"
process_xml_file(xml_file)
print("Processed XML file saved as: truststore.xml")