Skip to content

Commit f75a24c

Browse files
committed
Add separate cert path/test for aria2c. Prefer linux cert if available.
1 parent a03333b commit f75a24c

File tree

2 files changed

+53
-14
lines changed

2 files changed

+53
-14
lines changed

common.py

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,9 @@ class Globals:
187187

188188
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"
189189

190-
CA_CERT_PATH = None
190+
LINUX_CERT_PATH_TO_TEST = None
191+
CURL_CERT_PATH = None
192+
ARIA2_CERT_PATH = None
191193
URLOPEN_CERT_PATH = None
192194
URLOPEN_IS_BROKEN = False
193195

@@ -230,26 +232,63 @@ def testCurlHeaders(url, certPath):
230232

231233
args += ['-I', url]
232234

235+
print("Testing Curl: [{}]".format(args))
233236
with NullOrTemp.open() as os_devnull:
234237
return subprocess.call(args, stdout=os_devnull, stderr=os_devnull) == 0
235238

236239
# Try:
237-
# 1. Default Cert (whatever CURL uses when you don't specify argument)
238-
# 2. On Linux, we scan for certs on the user's computer and store the first found one. Try this.
240+
# 1. On Linux, we scan for certs on the user's computer and store the first found one. Try this.
241+
# 2. Default Cert (whatever CURL uses when you don't specify argument)
239242
# 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.
240-
paths_to_try = [None, Globals.CA_CERT_PATH, "curl-ca-bundle.crt"]
243+
paths_to_try = [Globals.LINUX_CERT_PATH_TO_TEST, None, "curl-ca-bundle.crt"]
241244

242245
for certificate_path in paths_to_try:
243246
if not testCurlHeaders('https://github.com/', certificate_path):
244247
print("chooseCurlCertificate(): Failed to download headers using CURL from github.com using cert [{}]".format(certificate_path))
245248
continue
246249

247250
print("chooseCurlCertificate(): Will use certificate [{}] when using cURL".format(certificate_path))
248-
Globals.CA_CERT_PATH = certificate_path
251+
Globals.CURL_CERT_PATH = certificate_path
249252
return
250253

251254
print("chooseCurlCertificate(): ERROR: No certificates were found to work, tried [{}] Probably can't use installer!".format(paths_to_try))
252255

256+
# this function must be run AFTER scanCertLocation()
257+
@staticmethod
258+
def chooseAria2Certificate():
259+
def testAria2c(url, certPath):
260+
try:
261+
command = [Globals.ARIA_EXECUTABLE, url, '--dry-run=true']
262+
if certPath is not None:
263+
command.append("--ca-certificate=" + certPath)
264+
265+
print("Testing Aria2C: [{}]".format(command))
266+
with NullOrTemp.open() as os_devnull:
267+
subprocess.check_call(command, stdout=os_devnull, stderr=os_devnull)
268+
269+
return True
270+
except Exception as error:
271+
print("Error: testAria2c() Failed: {}".format(error))
272+
return False
273+
274+
# Try:
275+
# 1. On Linux, we scan for certs on the user's computer and store the first found one. Try this.
276+
# 2. Default Cert (whatever CURL uses when you don't specify argument)
277+
# 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.
278+
paths_to_try = [Globals.LINUX_CERT_PATH_TO_TEST, None, "curl-ca-bundle.crt"]
279+
280+
for certificate_path in paths_to_try:
281+
if not testAria2c('https://github.com/', certificate_path):
282+
print("chooseAria2Certificate(): Failed to download from github.com using cert [{}]".format(certificate_path))
283+
continue
284+
285+
print("chooseAria2Certificate(): Will use certificate [{}] when using Aria2C".format(certificate_path))
286+
Globals.ARIA2_CERT_PATH = certificate_path
287+
return
288+
289+
print("chooseAria2Certificate(): ERROR: No certificates were found to work, tried [{}] Probably can't use installer!".format(paths_to_try))
290+
291+
253292
# this function must be run AFTER scanCertLocation()
254293
@staticmethod
255294
def chooseURLOpenCertificate():
@@ -265,7 +304,7 @@ def testURLOpenHeaders(url, certPath):
265304
# 1. Default Cert (whatever CURL uses when you don't specify argument)
266305
# 2. On Linux, we scan for certs on the user's computer and store the first found one. Try this.
267306
# 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.
268-
paths_to_try = [None, Globals.CA_CERT_PATH, "curl-ca-bundle.crt"]
307+
paths_to_try = [Globals.LINUX_CERT_PATH_TO_TEST, None, "curl-ca-bundle.crt"]
269308

270309
for certificate_path in paths_to_try:
271310
if not testURLOpenHeaders(Request('https://github.com/', headers={"User-Agent": ""}), certificate_path):
@@ -278,14 +317,13 @@ def testURLOpenHeaders(url, certPath):
278317

279318
print("chooseURLOpenCertificate(): ERROR: No certificates were found to work, tried [{}] Probably can't use installer!".format(paths_to_try))
280319

281-
282320
@staticmethod
283321
def scanForAria():
284322
ariaSearchPaths = ["./aria2c", "./.aria2c", "aria2c"]
285323
Globals.ARIA_EXECUTABLE = findWorkingExecutablePath(ariaSearchPaths, ['https://github.com/', '--dry-run=true'])
286324

287325
if Globals.ARIA_EXECUTABLE is None:
288-
print("\nWARNING: aria2 failed to download 07th-mod website. Using fallback detection method.")
326+
print("\nWARNING: aria2 failed to download 07th-mod website. Try using fallback detection method (call Aria2c with -h).")
289327
Globals.ARIA_EXECUTABLE = findWorkingExecutablePath(ariaSearchPaths, ['-h'])
290328

291329
if Globals.ARIA_EXECUTABLE is None:
@@ -424,8 +462,8 @@ def scanCertLocation():
424462
"/etc/ssl/cert.pem", # Alpine Linux
425463
]:
426464
if os.path.exists(possibleCertLocation):
427-
Globals.CA_CERT_PATH = possibleCertLocation
428-
print("[Linux] CA Cert - found at: {}".format(Globals.CA_CERT_PATH))
465+
Globals.LINUX_CERT_PATH_TO_TEST = possibleCertLocation
466+
print("[Linux] CA Cert - found at: {}".format(Globals.LINUX_CERT_PATH_TO_TEST))
429467
return
430468

431469
@staticmethod
@@ -624,8 +662,8 @@ def aria(downloadDir=None, inputFile=None, url=None, followMetaLink=False, useIP
624662
if outputFile:
625663
arguments.append("--out=" + outputFile)
626664

627-
if Globals.CA_CERT_PATH is not None:
628-
arguments.append("--ca-certificate=" + Globals.CA_CERT_PATH)
665+
if Globals.ARIA2_CERT_PATH is not None:
666+
arguments.append("--ca-certificate=" + Globals.ARIA2_CERT_PATH)
629667

630668
# On linux, there is some problem where the console buffer is not read by runProcessOutputToTempFile(...) until
631669
# a newline is printed. I was unable to fix this properly, however setting 'summary-interval' (default 60s) lower will
@@ -1250,8 +1288,8 @@ def queryUsingCURL(queryUrl):
12501288
with NullOrTemp.open() as os_devnull:
12511289
# Build CURL arguments
12521290
subprocess_args = [Globals.CURL_EXECUTABLE]
1253-
if Globals.CA_CERT_PATH is not None:
1254-
subprocess_args += ['--cacert', Globals.CA_CERT_PATH]
1291+
if Globals.CURL_CERT_PATH is not None:
1292+
subprocess_args += ['--cacert', Globals.CURL_CERT_PATH]
12551293
subprocess_args += ["-fILX", "GET", queryUrl]
12561294

12571295
print("queryUsingCURL(): Using args {}".format(subprocess_args))

main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ def doInstallerInit():
239239
common.Globals.scanCertLocation()
240240
common.Globals.chooseCurlCertificate()
241241
common.Globals.chooseURLOpenCertificate()
242+
common.Globals.chooseAria2Certificate()
242243

243244
# Run remaining init tasks concurrently
244245
t_getSubModConfig = common.makeThread(thread_getSubModConfigList)

0 commit comments

Comments
 (0)