| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
/Library/Frameworks/Python.framework/Versions/@PYVER@/bin/python@PYVER@ << "EOF" |
| 4 |
|
| 5 |
# install_certifi.py |
| 6 |
# |
| 7 |
# sample script to install or update a set of default Root Certificates |
| 8 |
# for the ssl module. Uses the certificates provided by the certifi package: |
| 9 |
# https://pypi.org/project/certifi/ |
| 10 |
|
| 11 |
import os |
| 12 |
import os.path |
| 13 |
import ssl |
| 14 |
import stat |
| 15 |
import subprocess |
| 16 |
import sys |
| 17 |
|
| 18 |
STAT_0o775 = ( stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
| 19 |
| stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP |
| 20 |
| stat.S_IROTH | stat.S_IXOTH ) |
| 21 |
|
| 22 |
def main(): |
| 23 |
openssl_dir, openssl_cafile = os.path.split( |
| 24 |
ssl.get_default_verify_paths().openssl_cafile) |
| 25 |
|
| 26 |
print(" -- pip install --upgrade certifi") |
| 27 |
subprocess.check_call([sys.executable, |
| 28 |
"-E", "-s", "-m", "pip", "install", "--upgrade", "certifi", |
| 29 |
"--disable-pip-version-check"]) |
| 30 |
|
| 31 |
import certifi |
| 32 |
|
| 33 |
# change working directory to the default SSL directory |
| 34 |
os.chdir(openssl_dir) |
| 35 |
relpath_to_certifi_cafile = os.path.relpath(certifi.where()) |
| 36 |
print(" -- removing any existing file or link") |
| 37 |
try: |
| 38 |
os.remove(openssl_cafile) |
| 39 |
except FileNotFoundError: |
| 40 |
pass |
| 41 |
print(" -- creating symlink to certifi certificate bundle") |
| 42 |
os.symlink(relpath_to_certifi_cafile, openssl_cafile) |
| 43 |
print(" -- setting permissions") |
| 44 |
os.chmod(openssl_cafile, STAT_0o775) |
| 45 |
print(" -- update complete") |
| 46 |
|
| 47 |
if __name__ == '__main__': |
| 48 |
main() |
| 49 |
EOF |