Skip to content

Commit 3eae9d7

Browse files
authored
Merge pull request #447 from Iamrodos/master
fix: Improve CA certificate detection with fallback chain
2 parents 1ec0820 + 90ba839 commit 3eae9d7

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

github_backup/github_backup.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,33 @@
3737
FILE_URI_PREFIX = "file://"
3838
logger = logging.getLogger(__name__)
3939

40+
# Setup SSL context with fallback chain
4041
https_ctx = ssl.create_default_context()
41-
if not https_ctx.get_ca_certs():
42-
import warnings
43-
44-
warnings.warn(
45-
"\n\nYOUR DEFAULT CA CERTS ARE EMPTY.\n"
46-
+ "PLEASE POPULATE ANY OF:"
47-
+ "".join(
48-
["\n - " + x for x in ssl.get_default_verify_paths() if type(x) is str]
49-
)
50-
+ "\n",
51-
stacklevel=2,
52-
)
53-
import certifi
54-
55-
https_ctx = ssl.create_default_context(cafile=certifi.where())
42+
if https_ctx.get_ca_certs():
43+
# Layer 1: Certificates pre-loaded from system (file-based)
44+
pass
45+
else:
46+
paths = ssl.get_default_verify_paths()
47+
if (paths.cafile and os.path.exists(paths.cafile)) or (
48+
paths.capath and os.path.exists(paths.capath)
49+
):
50+
# Layer 2: Cert paths exist, will be lazy-loaded on first use (directory-based)
51+
pass
52+
else:
53+
# Layer 3: Try certifi package as optional fallback
54+
try:
55+
import certifi
56+
57+
https_ctx = ssl.create_default_context(cafile=certifi.where())
58+
except ImportError:
59+
# All layers failed - no certificates available anywhere
60+
sys.exit(
61+
"\nERROR: No CA certificates found. Cannot connect to GitHub over SSL.\n\n"
62+
"Solutions you can explore:\n"
63+
" 1. pip install certifi\n"
64+
" 2. Alpine: apk add ca-certificates\n"
65+
" 3. Debian/Ubuntu: apt-get install ca-certificates\n\n"
66+
)
5667

5768

5869
def logging_subprocess(

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-

0 commit comments

Comments
 (0)