2 # ============LICENSE_START=======================================================
3 # Copyright (C) 2019 Nordix Foundation.
4 # ================================================================================
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # SPDX-License-Identifier: Apache-2.0
18 # ============LICENSE_END=========================================================
24 cafile = certifi.where()
25 number_of_lines_to_delete = 39
27 dr_cert_exists = False
29 with open(cafile, 'r+b', buffering=0) as outfile:
30 for line in outfile.readlines()[-35:-34]:
31 if "# Serial: 0x9EAEEDC0A7CEB59D" in line:
34 outfile.seek(0, os.SEEK_END)
36 while outfile.tell() > 0:
37 outfile.seek(-1, os.SEEK_CUR)
38 char = outfile.read(1)
41 if count == number_of_lines_to_delete:
43 print("Removed " + str(number_of_lines_to_delete) + " lines from end of CA File")
45 outfile.seek(-1, os.SEEK_CUR)
47 print("No DR cert in CA File to remove")
49 if count < number_of_lines_to_delete + 1:
50 print("Number of lines in file less than number of lines to delete. Exiting...")