From a732a13d3da8aa8fb68bcc57b7c97c1f78f07717 Mon Sep 17 00:00:00 2001 From: Tomasz Swierczek Date: Mon, 15 Jan 2024 13:25:08 +0100 Subject: [PATCH] Optimize cert merging script No need to check if file is a cert AND separately calculate SHA1 Change-Id: I031d674ff35db828e9afce6dff2e47edb2742add --- scripts/merge-certs-info.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/scripts/merge-certs-info.py b/scripts/merge-certs-info.py index e7ab2b8..c6b105b 100755 --- a/scripts/merge-certs-info.py +++ b/scripts/merge-certs-info.py @@ -1,6 +1,6 @@ #################################################### # -# Copyright (c) 2018 - 2023 Samsung Electronics Co., Ltd All Rights Reserved +# Copyright (c) 2018 - 2024 Samsung Electronics Co., Ltd All Rights Reserved # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -66,12 +66,6 @@ def getEndDate(path): return output[0].strip() return "" -#################################################### -# Returns true if path points to certificate file -#################################################### -def isCert(path): - return len(consoleCommand("openssl x509 -in " + path + " -subject_hash_old -noout")) > 0; - #################################################### # Returns true if certificate under path is not expired #################################################### @@ -80,7 +74,7 @@ def isCertValid(path): return endDate > datetime.now() #################################################### -# Returns sha1 fingerprint of DER or PEM cert, empty string on error +# Returns sha1 fingerprint of DER or PEM cert, empty string on error (ie. file is not a certificate) #################################################### def calculateCertSHA1(path): output = consoleCommand("openssl x509 -noout -fingerprint -sha1 -inform pem -in " + path + " | sed -e 's/Fingerprint=//g'") @@ -154,11 +148,11 @@ for directory in directories: files = consoleCommand("ls -1 " + directory) for f in files: f = f.strip() - if isCert(directory + "/" + f): - sha1 = calculateCertSHA1(directory + "/" + f) - if len(sha1) > 0: - sha1ToName[sha1] = f; - allSha1ToAnyPath[sha1] = directory + "/" + f + path = directory + "/" + f + sha1 = calculateCertSHA1(path) + if len(sha1) > 0: + sha1ToName[sha1] = f; + allSha1ToAnyPath[sha1] = path dirToSha1ToName[directory] = sha1ToName; if outputDir != "": -- 2.34.1