From 402c7ee440bfd04d1ef62118addc22a251c17ed9 Mon Sep 17 00:00:00 2001 From: Oleh Date: Tue, 16 Aug 2022 13:32:24 +0300 Subject: [PATCH 1/3] add doc and script to check certificates --- docs/grep-certificates.md | 6 ++++++ scripts/grep_certificates.py | 37 ++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 docs/grep-certificates.md create mode 100644 scripts/grep_certificates.py diff --git a/docs/grep-certificates.md b/docs/grep-certificates.md new file mode 100644 index 00000000..f3c529c1 --- /dev/null +++ b/docs/grep-certificates.md @@ -0,0 +1,6 @@ +# How to check when the certificates stored on sgxwallet were created +- Go to sgxwallet repository directory. +- Run `python3 scripts/grep_certificates.py PATH_TO_SGXWALLET_DB_FOLDER`. PATH_TO_SGXWALLET_DB_FOLDER - full path to the `sgx_data` directory where sgxwallet db is stored. For example, `root/sgxwallet/run_sgx/sgx_data` +- The script will output the dates when every certificate was created. +- Go to skale-node and run `cat .skale/node_data/sgx_certs/sgx.crt | grep "Not Before"`. +- Ensure that the output of the last command exists in the list from step 3 and it is the latest certificate there! \ No newline at end of file diff --git a/scripts/grep_certificates.py b/scripts/grep_certificates.py new file mode 100644 index 00000000..8ec74f66 --- /dev/null +++ b/scripts/grep_certificates.py @@ -0,0 +1,37 @@ +import os +import re +import sys + +def main(): + if len(sys.argv) != 2: + print("Wrong number of command line arguments: need exactly one") + exit(1) + + path = sys.argv[1] + if not os.path.exists(path): + print("No such file or directory: ", path) + exit(2) + + certs_path = os.path.join(path, "cert_data", "new_certs") + if len(os.listdir(certs_path)) == 0: + print("Empty certificates directory. Nothing to review.") + return + + for entity in os.listdir(certs_path): + entity_path = os.path.join(certs_path, entity) + if not os.path.isfile(entity_path): + print("Not a regular file. Skipping.") + continue + _, extension = os.path.splitext(entity_path) + if extension != '.pem': + print("Not a ssl certificate file. Skipping.") + continue + with open(entity_path,"r") as file_one: + pattern = "Not Before" + for line in file_one: + if re.search(pattern, line): + print(line) + + +if __name__ == '__main__': + main() \ No newline at end of file From 931578ba8d8bf2058cd84032641026c57d88c25f Mon Sep 17 00:00:00 2001 From: Oleh Date: Tue, 16 Aug 2022 14:28:18 +0300 Subject: [PATCH 2/3] add doc and script to check certificates --- docs/grep-certificates.md | 3 ++- scripts/grep_certificates.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/grep-certificates.md b/docs/grep-certificates.md index f3c529c1..4a6c6893 100644 --- a/docs/grep-certificates.md +++ b/docs/grep-certificates.md @@ -1,6 +1,7 @@ # How to check when the certificates stored on sgxwallet were created +- Download file `scripts/grep_certificates.py` from the sgxwallet repository and put it in sgxwallet repository directory on your machine. - Go to sgxwallet repository directory. -- Run `python3 scripts/grep_certificates.py PATH_TO_SGXWALLET_DB_FOLDER`. PATH_TO_SGXWALLET_DB_FOLDER - full path to the `sgx_data` directory where sgxwallet db is stored. For example, `root/sgxwallet/run_sgx/sgx_data` +- Run `python3 grep_certificates.py PATH_TO_SGXWALLET_DB_FOLDER`. PATH_TO_SGXWALLET_DB_FOLDER - path (either absolute or relative) to the `sgx_data` directory where sgxwallet db is stored. For example, `/root/sgxwallet/run_sgx/sgx_data` or `run_sgx/sgx_data` - The script will output the dates when every certificate was created. - Go to skale-node and run `cat .skale/node_data/sgx_certs/sgx.crt | grep "Not Before"`. - Ensure that the output of the last command exists in the list from step 3 and it is the latest certificate there! \ No newline at end of file diff --git a/scripts/grep_certificates.py b/scripts/grep_certificates.py index 8ec74f66..b03c5899 100644 --- a/scripts/grep_certificates.py +++ b/scripts/grep_certificates.py @@ -31,6 +31,7 @@ def main(): for line in file_one: if re.search(pattern, line): print(line) + break if __name__ == '__main__': From 102d07845c808a3fd91a0e776eae9aa5b40bd851 Mon Sep 17 00:00:00 2001 From: Oleh Date: Tue, 16 Aug 2022 14:42:07 +0300 Subject: [PATCH 3/3] add doc and script to check certificates --- scripts/grep_certificates.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/grep_certificates.py b/scripts/grep_certificates.py index b03c5899..89d93003 100644 --- a/scripts/grep_certificates.py +++ b/scripts/grep_certificates.py @@ -13,11 +13,17 @@ def main(): exit(2) certs_path = os.path.join(path, "cert_data", "new_certs") + if not os.path.exists(certs_path): + print("No such file or directory: ", certs_path) + exit(3) + if len(os.listdir(certs_path)) == 0: print("Empty certificates directory. Nothing to review.") return + print("Total number of elements in folder:", len(os.listdir(certs_path))) for entity in os.listdir(certs_path): + print("Reviewing", entity) entity_path = os.path.join(certs_path, entity) if not os.path.isfile(entity_path): print("Not a regular file. Skipping.") @@ -33,6 +39,5 @@ def main(): print(line) break - if __name__ == '__main__': main() \ No newline at end of file