@@ -188,6 +188,7 @@ class Globals:
188
188
PROTON_WITH_ASSETS_OVERRIDE_MESSAGE = "NOTE: Game is running under Proton/Wine, but user has deliberately selected which OS's assets to install, so it is OK"
189
189
190
190
CA_CERT_PATH = None
191
+ URLOPEN_CERT_PATH = None
191
192
URLOPEN_IS_BROKEN = False
192
193
193
194
NATIVE_LAUNCHER_PATH = None
@@ -240,11 +241,11 @@ def testCurlHeaders(url, certPath):
240
241
241
242
for certificate_path in paths_to_try :
242
243
if not testCurlHeaders ('https://07th-mod.com/' , certificate_path ):
243
- print ("chooseCurlCertificate(): Failed to download headers using CURL from 07th-mod.com using cert {} " .format (certificate_path ))
244
+ print ("chooseCurlCertificate(): Failed to download headers using CURL from 07th-mod.com using cert [{}] " .format (certificate_path ))
244
245
continue
245
246
246
247
if not testCurlHeaders ('https://github.com/' , certificate_path ):
247
- print ("chooseCurlCertificate(): Failed to download headers using CURL from github.com using cert {} " .format (certificate_path ))
248
+ print ("chooseCurlCertificate(): Failed to download headers using CURL from github.com using cert [{}] " .format (certificate_path ))
248
249
continue
249
250
250
251
print ("chooseCurlCertificate(): Successfully used certificate {} to download from 07th-mod and github" .format (certificate_path ))
@@ -253,6 +254,39 @@ def testCurlHeaders(url, certPath):
253
254
254
255
print ("chooseCurlCertificate(): ERROR: No certificates were found to work, tried {} Probably can't use installer!" .format (paths_to_try ))
255
256
257
+ # this function must be run AFTER scanCertLocation()
258
+ @staticmethod
259
+ def chooseURLOpenCertificate ():
260
+ def testURLOpenHeaders (url , certPath ):
261
+ try :
262
+ urlopen (url , context = ssl .create_default_context (cafile = certPath ))
263
+ return True
264
+ except Exception as error :
265
+ print ("Error: chooseURLOpenCertificate() Failed: {}" .format (error ))
266
+ return False
267
+
268
+ # Try:
269
+ # 1. Default Cert (whatever CURL uses when you don't specify argument)
270
+ # 2. On Linux, we scan for certs on the user's computer and store the first found one. Try this.
271
+ # 3. Try the certificate we bundle with the installer. We try this last becuase it might be out of date, depending on when the installer was last released.
272
+ paths_to_try = [None , Globals .CA_CERT_PATH , "curl-ca-bundle.crt" ]
273
+
274
+ for certificate_path in paths_to_try :
275
+ if not testURLOpenHeaders (Request ('https://07th-mod.com/' , headers = {"User-Agent" : "" }), certificate_path ):
276
+ print ("chooseURLOpenCertificate(): Failed to download headers using urlOpen from 07th-mod.com using cert [{}]" .format (certificate_path ))
277
+ continue
278
+
279
+ if not testURLOpenHeaders (Request ('https://github.com/' , headers = {"User-Agent" : "" }), certificate_path ):
280
+ print ("chooseURLOpenCertificate(): Failed to download headers using urlOpen from github.com using cert [{}]" .format (certificate_path ))
281
+ continue
282
+
283
+ print ("chooseURLOpenCertificate(): Successfully used certificate {} to download from 07th-mod and github" .format (certificate_path ))
284
+ Globals .URLOPEN_CERT_PATH = certificate_path
285
+ return
286
+
287
+ print ("chooseURLOpenCertificate(): ERROR: No certificates were found to work, tried {} Probably can't use installer!" .format (paths_to_try ))
288
+
289
+
256
290
@staticmethod
257
291
def scanForAria ():
258
292
ariaSearchPaths = ["./aria2c" , "./.aria2c" , "aria2c" ]
@@ -402,6 +436,13 @@ def scanCertLocation():
402
436
print ("[Linux] CA Cert - found at: {}" .format (Globals .CA_CERT_PATH ))
403
437
return
404
438
439
+ @staticmethod
440
+ def getURLOpenContext ():
441
+ context = None
442
+ if Globals .URLOPEN_CERT_PATH :
443
+ context = ssl .create_default_context (cafile = Globals .URLOPEN_CERT_PATH )
444
+ return context
445
+
405
446
# You can use the 'exist_ok' of python3 to do this already, but not in python 2
406
447
def makeDirsExistOK (directoryToMake ):
407
448
if os .path .exists (directoryToMake ):
@@ -1258,7 +1299,7 @@ def queryUsingCURL(queryUrl):
1258
1299
return contentDisposition , remoteLastModified , responseURL , lengthString
1259
1300
1260
1301
def queryUsingURLOpen (queryUrl ):
1261
- httpResponse = urlopen (Request (queryUrl , headers = {"User-Agent" : "" }))
1302
+ httpResponse = urlopen (Request (queryUrl , headers = {"User-Agent" : "" }), context = Globals . getURLOpenContext () )
1262
1303
1263
1304
try :
1264
1305
contentDisposition = httpResponse .getheader ("Content-Disposition" ) # python 3
@@ -1431,7 +1472,7 @@ def downloadFile(url, is_text):
1431
1472
:return:
1432
1473
"""
1433
1474
def downloadUsingURLOpen (download_url ):
1434
- file = urlopen (Request (download_url , headers = {"User-Agent" : "" }))
1475
+ file = urlopen (Request (download_url , headers = {"User-Agent" : "" }), context = Globals . getURLOpenContext () )
1435
1476
data = file .read ()
1436
1477
file .close ()
1437
1478
return data
0 commit comments