-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathinstall_certs.py
More file actions
35 lines (29 loc) · 1.17 KB
/
install_certs.py
File metadata and controls
35 lines (29 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import os
import ssl
import subprocess
import sys
def install_certificates():
print("Installing/Upgrading certifi...")
subprocess.check_call([sys.executable, "-m", "pip", "install", "--upgrade", "certifi"])
import certifi
openssl_dir, openssl_cafile = os.path.split(ssl.get_default_verify_paths().openssl_cafile)
print(f"Target CA file: {openssl_cafile}")
relpath_to_certifi_cafile = os.path.relpath(certifi.where(), openssl_dir)
print("Removing any existing file or link...")
try:
os.remove(openssl_cafile)
except FileNotFoundError:
pass
except PermissionError:
print(f"Permission error removing {openssl_cafile}. Try running with sudo.")
return
print("Creating symlink to certifi certificate bundle...")
try:
os.chdir(openssl_dir)
os.symlink(relpath_to_certifi_cafile, openssl_cafile)
print("Update complete. SSL certificates installed successfully!")
except Exception as e:
print(f"Error creating symlink: {e}")
print("If you see a permission error, you might need to run this script with sudo.")
if __name__ == '__main__':
install_certificates()