Skip to content

Commit

Permalink
Change how the database should work
Browse files Browse the repository at this point in the history
Nothing new but changes starting to pileup
  • Loading branch information
noisecode3 committed Oct 12, 2024
1 parent 8bbbbfb commit e79019f
Show file tree
Hide file tree
Showing 28 changed files with 2,082 additions and 1,779 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ install(TARGETS ${PROJECT_NAME}
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
)

install(FILES ${CMAKE_SOURCE_DIR}/utils/tombll.db
install(FILES ${CMAKE_SOURCE_DIR}/database/tombll.db
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}
)

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ make install

## Use database

You can add maps to the database if you cd into utils.
You can add maps to the database if you cd into database.
This should add Kitten Adventure Demo.

If it don't work try installing the
python3 module from the error, with pip, you'll need, beautifulsoup4 and tqdm

```shell
python3 get_data.py https://www.trle.net/sc/levelfeatures.php?lid=3379
python3 tombll_get_data.py https://www.trle.net/sc/levelfeatures.php?lid=3379

```

Expand All @@ -112,7 +112,7 @@ This means that you have to open the data.json file and add those values
```

```shell
python3 add_data.py data.json
python3 tombll_add_data.py data.json

```

Expand Down
1 change: 1 addition & 0 deletions utils/.gitignore → database/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
data.json
file_info.json
__pycache__
3 changes: 3 additions & 0 deletions utils/README → database/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,6 @@ get new level id numbers from trcustoms.org or trle.net with very minimal traffi
https://trcustoms.org/levels/3305
have not played through all of the game
background audio seem to have broke


![screenshot1](https://raw.githubusercontent.com/noisecode3/TombRaiderLinuxLauncher/main/database/screenshot1.jpg)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
126 changes: 126 additions & 0 deletions database/ideas.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
how to check for host main certificate
#### Bash ####
echo | openssl s_client -connect www.trle.net:443 -servername www.trle.net 2>/dev/null\
| openssl x509 -fingerprint -noout -serial -text

#### Python ####
"""xxx"""
import ssl
import socket
from cryptography import x509
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes, serialization

def get_certificate(hostname, port=443):
"""xxx"""
context = ssl.create_default_context()
# Disable certificate verification for the first connection
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE

with socket.create_connection((hostname, port)) as sock:
with context.wrap_socket(sock, server_hostname=hostname) as ssock:
# Get certificate info
cert_der = ssock.getpeercert(True)
if cert_der:
return x509.load_der_x509_certificate(cert_der, default_backend())
return None

def get_sha256_fingerprint(cert):
"""xxx"""
cert_der = cert.public_bytes(serialization.Encoding.DER)
digest = hashes.Hash(hashes.SHA256(), backend=default_backend())
digest.update(cert_der)
return digest.finalize()

def get_serial_number_hex(cert):
"""xxx"""
# Get the serial number in a byte format
serial_number_bytes = cert.serial_number \
.to_bytes((cert.serial_number.bit_length() + 7) // 8, 'big')
# Format it as a hex string
return ':'.join(f'{b:02X}' for b in serial_number_bytes)

def print_certificate_details(cert):
"""xxx"""
fingerprint = get_sha256_fingerprint(cert)
fingerprint_hex = ':'.join(f'{b:02X}' for b in fingerprint)
serial_number_hex = get_serial_number_hex(cert)

print(f"SHA-256 fingerprint: {fingerprint_hex}")
print(f"Serial number: {serial_number_hex}")
print(f"Subject: {cert.subject}")
print(f"Issuer: {cert.issuer}")
print()

certificate = get_certificate('trle.net')
print_certificate_details(certificate)

#### C++ ####
And this is how we can ask the server to just give the certificate right there in c++
This is how we should have done this from the start, this is the normal way...

#include <iostream>
#include <boost/asio.hpp>
#include <boost/asio/ssl.hpp>
#include <openssl/x509.h>
#include <openssl/pem.h>
#include <openssl/bio.h>

namespace ssl = boost::asio::ssl;
using boost::asio::ip::tcp;

void get_ssl_certificate(const std::string& host) {
boost::asio::io_context io_context;

// Create SSL context
ssl::context ssl_context(ssl::context::sslv23);

// Create a TCP socket
tcp::resolver resolver(io_context);
tcp::resolver::results_type endpoints = resolver.resolve(host, "https");

// Create SSL stream using the socket and the SSL context
ssl::stream<tcp::socket> stream(io_context, ssl_context);

// Set SNI (Server Name Indication)
SSL_set_tlsext_host_name(stream.native_handle(), host.c_str());

// Connect the socket to the resolved endpoint
boost::asio::connect(stream.lowest_layer(), endpoints);

// Perform SSL handshake
stream.handshake(ssl::stream_base::client);

// Retrieve and display the SSL certificate
X509* cert = SSL_get_peer_certificate(stream.native_handle());
if (cert) {
std::cout << "SSL Certificate retrieved successfully!" << std::endl;

// Convert X509* certificate to string using BIO
BIO* bio = BIO_new(BIO_s_mem());
PEM_write_bio_X509(bio, cert);

char* cert_str = nullptr;
long cert_len = BIO_get_mem_data(bio, &cert_str);

// Print the certificate as a string
std::cout << std::string(cert_str, cert_len) << std::endl;

// Clean up
BIO_free(bio);
X509_free(cert);
} else {
std::cout << "No certificate found." << std::endl;
}
}

int main() {
std::string host = "www.trle.net";
get_ssl_certificate(host);
return 0;
}

Never forget how we can test one function in python:
python3 -c "from index_scrape import get_trle_page; print(get_trle_page(0, True))"

File renamed without changes.
49 changes: 49 additions & 0 deletions database/index_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""Index dictionary data definitions"""
def make_trle_page_data():
"""trle.net page, represents the same data as a page on the site"""
return {
"offset": 0,
"records_total": 0,
"levels": [],
}


def make_trle_level_data():
"""trle.net record data"""
return {
"trle_id": 0,
"author": "",
"title": "",
"difficulty": "",
"duration": "",
"class": "",
"type": "",
"release": "",
}


def make_trcustoms_page_data():
"""trcustoms.org page, represents the same data as a page on the site"""
return {
"current_page": 0,
"total_pages": 0,
"records_total": 0,
"levels": [],
}


def make_trcustoms_level_data():
"""trcustoms.org record data"""
return {
"trcustoms_id": 0,
"authors": [],
"title": "",
"tags": [],
"genres": [],
"type": "",
"release": "",
"difficulty": "",
"duration": "",
"cover": "",
"cover_md5sum": "",
}
Loading

0 comments on commit e79019f

Please sign in to comment.