-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_keystore_file.py
57 lines (39 loc) · 2.25 KB
/
gen_keystore_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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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 fetch_pubkey_info(pub_key_file):
with open(pub_key_file) as f:
pub_key_data = f.read()
pub_key_info_start = pub_key_data.find("-----BEGIN PUBLIC KEY-----")
pub_key_info_end = pub_key_data.find("------END PUBLIC KEY-----")
return pub_key_data[pub_key_info_start + len("------BEGIN PUBLIC KEY-----"):pub_key_info_end - len("------END PUBLIC KEY-----")]
def fetch_privkey_info(priv_key_file):
with open(priv_key_file) as f:
priv_key_data = f.read()
priv_key_info_start = priv_key_data.find("-----BEGIN EC PRIVATE KEY-----")
priv_key_info_end = priv_key_data.find("------END EC PRIVATE KEY-----")
return priv_key_data[priv_key_info_start + len("-----BEGIN EC PRIVATE KEY-----")+1:priv_key_info_end - len("------END EC PRIVATE KEY-----")]
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>')
pub_key_info = fetch_pubkey_info(pub_key_file)
xml_data = xml_data.replace('add_data_here</public-key>', pub_key_info + '</public-key>')
priv_key_info = fetch_privkey_info(priv_key_file)
xml_data = xml_data.replace('add_data_here</private-key>', priv_key_info + '</private-key>')
new_file_name = "keystore.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/keystore_template.xml"
crt_file = "/home/amal/Desktop/workspace/certs/IDevID_stage_automation/certs/IDevID_ee_ser.crt"
pub_key_file = "/home/amal/Desktop/workspace/certs/IDevID_stage_automation/certs/IDevID_ee_ser_pub_key.pub"
priv_key_file = "/home/amal/Desktop/workspace/certs/IDevID_stage_automation/certs/IDevID_ee_ser_key.key"
process_xml_file(xml_file)
print("Processed XML file saved as: keystore.xml")