From 5d1158860b6e0a7275f77264e519958bf76b009a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20B=C3=A5ngens?= Date: Wed, 14 Aug 2024 16:25:42 +0200 Subject: [PATCH] simplify ssl ca-certificates --- README.md | 59 ++++++++++++++++++++++++++++++++++++++++-------- utils/addData.py | 2 +- utils/getData.py | 36 +++++++++++++++++++++-------- 3 files changed, 76 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 55ebd73..5d7a8e7 100644 --- a/README.md +++ b/README.md @@ -30,9 +30,9 @@ manipulation configuration files. Bash for launching with Steam or Lutris or jus * [Delca - Kitten Adventure](https://www.trle.net/sc/levelfeatures.php?lid=3379) -# test +# Prepare This install the program in you're ".local" home directory -You need those, should be installed an desktop linux +You need those, should be installed on a desktop linux * curl * Qt5 @@ -41,26 +41,65 @@ To ensure that our application works properly right now, you need to download th required certificates from Firefox and add them to your system’s certificate store. Unfortunately, I cannot share these certificates directly. +Open Firefox go to trle.net and click the lock icon in the URL bar. +Click more info, click View Certificate then in the new window +there is a Miscellaneous section and 2 download links. + +Change the name from +trle-net".pem" to trle-net".crt" so you'll have to + ``` -/etc/ssl/certs/trle-net-chain.pem -/etc/ssl/certs/trle-net.pem +/usr/share/ca-certificates/mozilla/trle-net-chain.crt +/usr/share/ca-certificates/mozilla/trle-net.crt +``` +then add to /etc/ca-certificates.conf +``` +mozilla/trle-net.crt +mozilla/trle-net-chain.crt ``` -Something like that should work on you're system +you'll run: + +``` +update-ca-certificates +``` +and you should see that you have those files as symbolic links. +Then it should work with curl. ``` -sudo update-ca-certificates +/etc/ssl/certs/trle-net-chain.pem +/etc/ssl/certs/trle-net.pem ``` +# Build + ```shell cmake -DCMAKE_INSTALL_PREFIX=~/.local . make install ``` -You can add maps to the database if you cd into utils -This should add Kitten Adventure Demo, but there is a bug -because the download link is not a zip file its a another html page. +# Use database + +You can add maps to the database if you cd into utils. +This should add Kitten Adventure Demo. + If it don't work try installing the -python3 module from the error. +python3 module from the error, with pip + +```shell +python3 getData.py https://www.trle.net/sc/levelfeatures.php?lid=3379 + +``` + +It will show +``` +ERROR:The file at https://www.trle.net/scadm/trle_dl.php?lid=3379 is not a ZIP file. Content-Type: text/html +``` +This means that you have to open the data.json file and add those values +``` + "zipFileName": "", + "zipFileMd5": "", + "download_url": "" +``` ```shell python3 getData.py https://www.trle.net/sc/levelfeatures.php?lid=3379 diff --git a/utils/addData.py b/utils/addData.py index 7732d8d..5c45e7c 100644 --- a/utils/addData.py +++ b/utils/addData.py @@ -60,8 +60,8 @@ def download_file(url, cert, file_name): file_info = json.load(json_file) zip_url = file_info.get('download_url') -cert = '/home/noisecode3/mySecretVirusFolder/trle-net-chain.pem' +cert = ('/etc/ssl/certs/ca-certificates.crt') response = requests.get(zip_url, verify=cert) zip_content = response.content diff --git a/utils/getData.py b/utils/getData.py index c0aa1cd..11924ce 100644 --- a/utils/getData.py +++ b/utils/getData.py @@ -14,7 +14,7 @@ # Set up logging logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s:%(message)s') logging.getLogger("requests").setLevel(logging.DEBUG) -logging.getLogger("urllib3").setLevel(logging.DEBUG) +#logging.getLogger("urllib3").setLevel(logging.DEBUG) if __name__ == "__main__": if len(sys.argv) != 2: @@ -32,10 +32,8 @@ sys.exit(1) time.sleep(2) -# test url -# url = 'https://www.trle.net/sc/levelfeatures.php?lid=3573' -cert = '/home/noisecode3/mySecretVirusFolder/trle-net-chain.pem' +cert = ('/etc/ssl/certs/ca-certificates.crt') try: response = requests.get(url, verify=cert) @@ -79,7 +77,7 @@ duration = "missing" else: duration = "missing" - + specific_tags = soup.find_all('td', class_='medGText', align='left', valign='top') body = specific_tags[1] if len(specific_tags) >= 2 else "missing" @@ -98,11 +96,29 @@ try: response2 = requests.head(url, verify=cert, allow_redirects=True) response2.raise_for_status() - download_url = response2.url - file_name = response2.url.split('/')[-1] - zipFileName = file_name - md5_checksum = hashlib.md5(requests.get(url, verify=cert).content).hexdigest() - zipFileMd5 = md5_checksum + + # Check if the content type is a zip file + if 'Content-Type' in response2.headers and response2.headers['Content-Type'] == 'application/zip': + download_url = response2.url + file_name = response2.url.split('/')[-1] + zipFileName = file_name + + # Download the file and calculate its MD5 checksum + response3 = requests.get(url, verify=cert) + response3.raise_for_status() # Check again to ensure the GET request is successful + md5_checksum = hashlib.md5(response3.content).hexdigest() + zipFileMd5 = md5_checksum + + # Do something with the download URL, file name, and MD5 checksum + print(f"Download URL: {download_url}") + print(f"File Name: {zipFileName}") + print(f"MD5 Checksum: {zipFileMd5}") + else: + logging.error(f"The file at {url} is not a ZIP file. Content-Type: {response2.headers.get('Content-Type')}") + download_url = '' + zipFileName = '' + zipFileMd5 = '' + except requests.exceptions.RequestException as e: logging.error(f"Failed to retrieve file information from {url}: {e}")