VladNitu

script py certif

Mar 26th, 2023
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. # install_certifi.py
  2. #
  3. # sample script to install or update a set of default Root Certificates
  4. # for the ssl module. Uses the certificates provided by the certifi package:
  5. # https://pypi.python.org/pypi/certifi
  6.  
  7. import os
  8. import os.path
  9. import ssl
  10. import stat
  11. import subprocess
  12. import sys
  13.  
  14. STAT_0o775 = ( stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
  15. | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP
  16. | stat.S_IROTH | stat.S_IXOTH )
  17.  
  18.  
  19. def main():
  20. openssl_dir, openssl_cafile = os.path.split(
  21. ssl.get_default_verify_paths().openssl_cafile)
  22.  
  23. print(" -- pip install --upgrade certifi")
  24. subprocess.check_call([sys.executable,
  25. "-E", "-s", "-m", "pip", "install", "--upgrade", "certifi"])
  26.  
  27. import certifi
  28.  
  29. # change working directory to the default SSL directory
  30. os.chdir(openssl_dir)
  31. relpath_to_certifi_cafile = os.path.relpath(certifi.where())
  32. print(" -- removing any existing file or link")
  33. try:
  34. os.remove(openssl_cafile)
  35. except FileNotFoundError:
  36. pass
  37. print(" -- creating symlink to certifi certificate bundle")
  38. os.symlink(relpath_to_certifi_cafile, openssl_cafile)
  39. print(" -- setting permissions")
  40. os.chmod(openssl_cafile, STAT_0o775)
  41. print(" -- update complete")
  42.  
  43. if __name__ == '__main__':
  44. main()
Add Comment
Please, Sign In to add comment