Implementing OpenSSL into TGEA
by Robert Fritzen · 01/27/2011 (4:11 pm) · 4 comments
As mentioned I would be resourcing my C++ based authentication system (x509). This will be the first step of implementing it bear with me, we are currently trying to fix up what seems to be our last issue.
First off, a little bit of information:
http://www.openssl.org/
Open SSL is an open source SSL/TLS toolkit that contains a huge variety of advanced and powerful cryptography functions used for SSL transmissions. I've been using it for a few months now in creating an authentication system that runs like that of an x509 certificate scheme. It contains a huge list of functions to help you keep all of your data secure, so systems like rank/progression are tougher to break. One could even implement secure data transmission if you were clever enough with the C++.
Anyways, onto implementation.
I currently am using TGEA 1.8.1, I am sure it can run on TGEA 1.8.2, and just changing around a few of the definitions of your console functions should be all you need to do to use it with T3D.
So, first off, you will need to install openSSL. This can be quite a hassle if you have no idea what you are doing, so I have pre-compiled the openSSL files you will be needing to use it.
http://www.phantomdev.net/staff/phantom139/public/OpenSSL_requires.zip
I only know how to do this with visual studio, so if you are using a different compiler, you will need to find out how to implement this on your compiler.
extract the contents of that .zip to Program Files/Microsoft Visual Studio 9.0/VC/ (wherever your visual studio is installed)
once you have completed this, you will now need to set the linker to use openSSL's two .lib files: libeay32.lib and ssleay32.lib. to do so, open up your project, and go to the project properties, you will find this under input in the linker section.
Now that all of openSSL's files are implemented, let's get a hashing function into our project, let's use a simple one, SHA1.
Create a new .cpp file and add it to your project.
Once you are ready to send out a "release" version of your project, you will need to add two .dll files to your game's folder: ssleay32.dll and libeay32.dll, these are found in the /bin/ folder of that OpenSSL_Requires.zip you downloaded earlier.
I hope this helps! and good luck with openSSL. I will be adding the rest of this resource which is implementing my x509 authentication system as soon as we get it running without errors!
First off, a little bit of information:
http://www.openssl.org/
Open SSL is an open source SSL/TLS toolkit that contains a huge variety of advanced and powerful cryptography functions used for SSL transmissions. I've been using it for a few months now in creating an authentication system that runs like that of an x509 certificate scheme. It contains a huge list of functions to help you keep all of your data secure, so systems like rank/progression are tougher to break. One could even implement secure data transmission if you were clever enough with the C++.
Anyways, onto implementation.
I currently am using TGEA 1.8.1, I am sure it can run on TGEA 1.8.2, and just changing around a few of the definitions of your console functions should be all you need to do to use it with T3D.
So, first off, you will need to install openSSL. This can be quite a hassle if you have no idea what you are doing, so I have pre-compiled the openSSL files you will be needing to use it.
http://www.phantomdev.net/staff/phantom139/public/OpenSSL_requires.zip
I only know how to do this with visual studio, so if you are using a different compiler, you will need to find out how to implement this on your compiler.
extract the contents of that .zip to Program Files/Microsoft Visual Studio 9.0/VC/ (wherever your visual studio is installed)
once you have completed this, you will now need to set the linker to use openSSL's two .lib files: libeay32.lib and ssleay32.lib. to do so, open up your project, and go to the project properties, you will find this under input in the linker section.
Now that all of openSSL's files are implemented, let's get a hashing function into our project, let's use a simple one, SHA1.
Create a new .cpp file and add it to your project.
// for torque's console
#include "platform/platform.h"
#include "console/console.h"
#include "console/consoleInternal.h"
#include "console/ast.h"
#include "core/resManager.h"
#include "core/stream/fileStream.h"
#include "console/compiler.h"
#include "platform/event.h"
#include "platform/platformInput.h"
#include "core/util/journal/journal.h"
//
#include <openssl/sha.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;
doSHA1(const char * inputText);
std::string doSHA1(const char * inputText) {
unsigned char hash[SHA_DIGEST_LENGTH];
SHA_CTX sha;
SHA1_Init(&sha);
SHA1_Update(&sha, inputText, strlen(inputText));
SHA1_Final(hash, &sha);
char * outBuf = (char *)malloc(512);
for(int i = 0; i < SHA_DIGEST_LENGTH; i++) {
sprintf(outBuf + (i * 2), "%02x", hash[i]);
}
return string(outBuf);
}
ConsoleFunction(sha1, const char *, 2, 2, "(string) returns the SHA1 hash of a string") {
argc;
std::string output_hash = doSHA1(argv[1]);
const char * done = (const char *)malloc(256); //you can use the SHA_DIGEST_LENGTH, I just stick with powers of 2 over 128...
strcpy((char *)done, output_hash.c_str());
return done;
}
//Please correct any of my silly errors if you find them, thanks!Once you are ready to send out a "release" version of your project, you will need to add two .dll files to your game's folder: ssleay32.dll and libeay32.dll, these are found in the /bin/ folder of that OpenSSL_Requires.zip you downloaded earlier.
I hope this helps! and good luck with openSSL. I will be adding the rest of this resource which is implementing my x509 authentication system as soon as we get it running without errors!
About the author
Illinois Grad. Retired T3D Developer / Pack Dev.
#2
01/29/2011 (11:29 am)
Yeah, OpenSSL was a hard one to build, I'm currently trying to build the CryptoPP 5.6.1 library under TGEA 1.8.1, it looks like a better choice for the high level RSA encryption functions I need for my authentication system.
#3
Will they be useable with the Express versions of Visual studio you think?
02/03/2011 (10:04 am)
Thanks for this resource, and for including your OpenSSL builds. Will they be useable with the Express versions of Visual studio you think?
#4
I'm sure there are tutorials out there to get them working if this setup does not.
And sure thing, I'll do the same for the Crypto++ library when I finish implementation of it into torque.
02/03/2011 (10:06 am)
As far as I know they work fine with the express versions of visual studio.I'm sure there are tutorials out there to get them working if this setup does not.
And sure thing, I'll do the same for the Crypto++ library when I finish implementation of it into torque.

Associate James Urquhart
char *ptr = str_digest; for (U32 i=0; i<SHA_DIGEST_LENGTH; i++, ptr += 2) dSprintf(ptr, 3, "%02x", (U32)digest[i]);With the string digest being allocated by:
... though i did put everything in an ConsoleFunction.
Building OpenSSL was a pain. Had to follow the docs at http://www.devside.net/guides/windows/openssl . On osx or linux, its bundled with the system.