Skip to content

Commit ff91ee2

Browse files
Merge pull request #397 from skalenetwork/sgx-certs-script
add doc and script to check certificates
2 parents 6e01842 + 102d078 commit ff91ee2

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

docs/grep-certificates.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# How to check when the certificates stored on sgxwallet were created
2+
- Download file `scripts/grep_certificates.py` from the sgxwallet repository and put it in sgxwallet repository directory on your machine.
3+
- Go to sgxwallet repository directory.
4+
- 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`
5+
- The script will output the dates when every certificate was created.
6+
- Go to skale-node and run `cat .skale/node_data/sgx_certs/sgx.crt | grep "Not Before"`.
7+
- Ensure that the output of the last command exists in the list from step 3 and it is the latest certificate there!

scripts/grep_certificates.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import os
2+
import re
3+
import sys
4+
5+
def main():
6+
if len(sys.argv) != 2:
7+
print("Wrong number of command line arguments: need exactly one")
8+
exit(1)
9+
10+
path = sys.argv[1]
11+
if not os.path.exists(path):
12+
print("No such file or directory: ", path)
13+
exit(2)
14+
15+
certs_path = os.path.join(path, "cert_data", "new_certs")
16+
if not os.path.exists(certs_path):
17+
print("No such file or directory: ", certs_path)
18+
exit(3)
19+
20+
if len(os.listdir(certs_path)) == 0:
21+
print("Empty certificates directory. Nothing to review.")
22+
return
23+
24+
print("Total number of elements in folder:", len(os.listdir(certs_path)))
25+
for entity in os.listdir(certs_path):
26+
print("Reviewing", entity)
27+
entity_path = os.path.join(certs_path, entity)
28+
if not os.path.isfile(entity_path):
29+
print("Not a regular file. Skipping.")
30+
continue
31+
_, extension = os.path.splitext(entity_path)
32+
if extension != '.pem':
33+
print("Not a ssl certificate file. Skipping.")
34+
continue
35+
with open(entity_path,"r") as file_one:
36+
pattern = "Not Before"
37+
for line in file_one:
38+
if re.search(pattern, line):
39+
print(line)
40+
break
41+
42+
if __name__ == '__main__':
43+
main()

0 commit comments

Comments
 (0)