35 __THIS_FILE_ALGORITHM_VERSION =
'hc1'
37 __cfp_json_path__ =
'/../cFp.json'
38 __shell_type_key__ =
'cFpSRAtype'
39 __mod_type_key__ =
'cFpMOD'
40 __dcps_folder_name__ =
'/dcps/'
41 __sig_file_ending__ =
'sig'
42 __admin_sig_file_name__ =
'admin'
48 sha256_hash = hashlib.sha256()
49 with open(file_path,
'rb')
as f:
51 for byte_block
in iter(
lambda: f.read(4096), b
""):
52 sha256_hash.update(byte_block)
53 return sha256_hash.hexdigest()
59 sha256_hash = hashlib.sha256(inp_string.encode(
'utf-8'))
60 return sha256_hash.hexdigest()
66 new_cert_string =
'new_pl:' +
str(dcp_hash) +
str(mcs_hash) +
str(bit_hash) +
str(rpt_hash)
67 cert = hashlib.sha384(new_cert_string.encode(
'utf-8')).hexdigest()
68 if debugging_flow
is not None:
69 print(
"\tnew_cert_string: {}".format(new_cert_string))
73 def main(new_mcs_file_name, new_bit_file_name, pr_verify_rpt_file_name):
75 me_abs_dir = os.path.dirname(os.path.realpath(__file__))
76 me_abs_file = os.path.abspath(os.path.realpath(__file__))
77 cfp_json_file = me_abs_dir + __cfp_json_path__
78 debugging_flow = os.environ.get(
'CFP_DEBUGGING')
79 if debugging_flow
is not None:
80 cfp_json_file = me_abs_dir + debugging_flow +
'/cFp.json'
81 with open(cfp_json_file,
'r')
as json_file:
82 cFp_data = json.load(json_file)
85 root_abs = os.path.realpath(me_abs_dir+
"/../")
86 if debugging_flow
is not None:
87 root_abs = os.path.realpath(me_abs_dir + debugging_flow +
"/env/" +
"/../")
88 cFp_data[
'abs_path'] = root_abs
89 dcps_folder = root_abs + __dcps_folder_name__
91 dcp_file_name =
"3_top{}_STATIC.dcp".format(cFp_data[__mod_type_key__])
92 target_file_name = os.path.abspath(dcps_folder +
"/" + dcp_file_name)
96 new_mcs_file_path = os.path.abspath(dcps_folder +
'/' + new_mcs_file_name)
97 if not os.path.isfile(new_mcs_file_path):
98 print(
"[cFBuild] ERROR: {} is not a file. STOP.".format(new_mcs_file_path))
101 new_bit_file_path = os.path.abspath(dcps_folder +
'/' + new_bit_file_name)
102 if not os.path.isfile(new_bit_file_path):
103 print(
"[cFBuild] ERROR: {} is not a file. STOP.".format(new_bit_file_path))
106 pr_verify_rpt_file_path = os.path.abspath(dcps_folder +
'/' + pr_verify_rpt_file_name)
107 if not os.path.isfile(pr_verify_rpt_file_path):
108 print(
"[cFBuild] ERROR: {} is not a file. STOP.".format(pr_verify_rpt_file_path))
111 with open(pr_verify_rpt_file_path)
as rpt_in:
113 rpt_file_lines.append(line.rstrip())
114 pr_verify_str =
''.join(rpt_file_lines)
116 sig_file_path = os.path.abspath(dcps_folder +
'/' + __admin_sig_file_name__ +
'.' + __sig_file_ending__)
118 new_sig = {
'build_id': __admin_sig_file_name__,
'algorithm': __admin_sig_file_name__,
119 'file': __admin_sig_file_name__,
'pl_id':
'new_pl',
'hash':
'ignore'}
138 if debugging_flow
is not None:
139 print(
"\tdcp hash: {}".format(dcp_hash))
140 print(
"\trpt hash: {}".format(rpt_hash))
141 print(
"\tbit hash: {}".format(bit_hash))
142 print(
"\tmcs hash: {}".format(mcs_hash))
145 new_sig[
'sig'] =
get_admin_sig_string(dcp_hash, mcs_hash, bit_hash, rpt_hash, debugging_flow=debugging_flow)
146 new_sig[
'dcp_hash'] = dcp_hash
147 new_sig[
'mcs_hash'] = mcs_hash
148 new_sig[
'bit_hash'] = bit_hash
149 new_sig[
'rpt_hash'] = rpt_hash
151 rpt_sum_line = rpt_file_lines[-1]
152 new_sig[
'verify_rpt'] = rpt_sum_line
153 if dcp_file_name
in rpt_sum_line:
154 new_sig[
'verify'] =
'OK'
156 new_sig[
'verify'] =
'NOK'
158 with open(sig_file_path,
'w')
as outfile:
159 json.dump(new_sig, outfile)
164 if __name__ ==
'__main__':
166 if len(sys.argv) != 4:
167 print(
'ERROR: Usage is {} <new-mcs-file-name> <new-bit-file-name> <pr-verify-rpt-file-name>. STOP'
168 .format(sys.argv[0]))
170 main(sys.argv[1], sys.argv[2], sys.argv[3])
def get_string_hash(inp_string)
def main(new_mcs_file_name, new_bit_file_name, pr_verify_rpt_file_name)
def get_admin_sig_string(dcp_hash, mcs_hash, bit_hash, rpt_hash, debugging_flow=None)
def get_file_hash(file_path)