aboutsummaryrefslogtreecommitdiff
path: root/src/crypto.cc
diff options
context:
space:
mode:
authorfusion32 <marcopuzziello@gmail.com>2025-07-16 17:22:39 -0300
committerfusion32 <marcopuzziello@gmail.com>2025-07-16 17:22:39 -0300
commit6d498fe17dab48cfd8fc8a4da62a573b799e10ba (patch)
tree1c8d55bd907b35abf014385dbedb90b2ae98f96a /src/crypto.cc
parente65dc561acab7a9e49f59777f16cb040c574c64d (diff)
downloadgame-6d498fe17dab48cfd8fc8a4da62a573b799e10ba.tar.gz
game-6d498fe17dab48cfd8fc8a4da62a573b799e10ba.zip
fix most init and parsing bugs + critical bug with dynamic strings
With an appropriate query manager, the server now starts up and seems to work but won't properly handle connections until we fix the problem with threads and signals described in `TODO.md`.
Diffstat (limited to 'src/crypto.cc')
-rw-r--r--src/crypto.cc15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/crypto.cc b/src/crypto.cc
index aa53dc3..1559999 100644
--- a/src/crypto.cc
+++ b/src/crypto.cc
@@ -27,16 +27,16 @@ TRSAPrivateKey::~TRSAPrivateKey(void){
}
}
-void TRSAPrivateKey::initFromFile(const char *FileName){
+bool TRSAPrivateKey::initFromFile(const char *FileName){
if(m_RSA != NULL){
error("TRSAPrivateKey::init: Key already initialized.\n");
- return;
+ return false;
}
FILE *File = fopen(FileName, "rb");
if(File == NULL){
error("TRSAPrivateKey::initFromFile: Failed to open \"%s\".\n", FileName);
- return;
+ return false;
}
m_RSA = PEM_read_RSAPrivateKey(File, NULL, NULL, NULL);
@@ -50,12 +50,14 @@ void TRSAPrivateKey::initFromFile(const char *FileName){
RSA_free(m_RSA);
m_RSA = NULL;
}
+
+ return (m_RSA != NULL);
}
-void TRSAPrivateKey::decrypt(uint8 *Data){
+bool TRSAPrivateKey::decrypt(uint8 *Data){
if(m_RSA == NULL){
error("TRSAPrivateKey::decrypt: Key not initialized.\n");
- return;
+ return false;
}
// TODO(fusion): Pass in the length of `Data` for checking.
@@ -63,7 +65,10 @@ void TRSAPrivateKey::decrypt(uint8 *Data){
if(RSA_private_decrypt(128, Data, Data, m_RSA, RSA_NO_PADDING) == -1){
DumpOpenSSLErrors("TRSAPrivateKey::decrypt", "RSA_private_decrypt");
+ return false;
}
+
+ return true;
}
// TXTEASymmetricKey