-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathca_bundle.py
31 lines (25 loc) · 1011 Bytes
/
ca_bundle.py
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
from os import environ
from pathlib import Path
from sys import platform
from typing import Optional
def install(path: Optional[str] = None):
'''Search through common locations of SSL / TLS certificates on linux and
set the first existing location to REQUESTS_CA_BUNDLE and HTTPLIB2_CA_CERTS
environment variables.
'''
if platform != 'linux':
return
if path is None:
certs = [
'/etc/ssl/certs/ca-certificates.crt', # Debian/Ubuntu/Gentoo etc.
'/etc/pki/tls/certs/ca-bundle.crt', # Fedora/RHEL 6
'/etc/ssl/ca-bundle.pem', # OpenSUSE
'/etc/pki/tls/cacert.pem', # OpenELEC
'/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem', # CentOS/RHEL 7
'/etc/ssl/cert.pem', # Alpine Linux
]
valid = [cert for cert in certs if Path(cert).is_file()]
if not valid:
return
path = valid[0]
environ['REQUESTS_CA_BUNDLE'] = environ['HTTPLIB2_CA_CERTS'] = path