2 # SPDX-License-Identifier: LGPL-2.1-or-later
7 chain_path = sys.argv[1]
8 new_root_path = sys.argv[2]
10 sys.exit('USAGE: update-chain-with-new-root.py ca-file.pem new-ca.pem')
12 with open(new_root_path, 'rb') as new_file:
13 new_cert_lines = new_file.readlines()
15 with open(chain_path, 'rb+') as chain_file:
16 chain_file_lines = chain_file.readlines()
17 new_chain_file_lines = []
19 # Replace the lines of the old root with the new cert
20 for i, line in enumerate(chain_file_lines):
21 if b'BEGIN CERTIFICATE' in line:
22 new_chain_file_lines += chain_file_lines[:i]
23 new_chain_file_lines += new_cert_lines
25 if b'END CERTIFICATE' in line:
26 new_chain_file_lines += chain_file_lines[i + 1:]
31 chain_file.writelines(new_chain_file_lines)