create keypair on startup if one doesn't already exist
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
#include "CryptManager.h"
|
#include "CryptManager.h"
|
||||||
#include "RageUtil.h"
|
#include "RageUtil.h"
|
||||||
#include "CryptHelpers.h"
|
#include "CryptHelpers.h"
|
||||||
|
#include "RageLog.h"
|
||||||
|
|
||||||
// crypt headers
|
// crypt headers
|
||||||
#include "sha.h"
|
#include "sha.h"
|
||||||
@@ -9,7 +10,7 @@
|
|||||||
#include "channels.h"
|
#include "channels.h"
|
||||||
#include "rsa.h"
|
#include "rsa.h"
|
||||||
#include "md5.h"
|
#include "md5.h"
|
||||||
#include "randpool.h"
|
#include "osrng.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
using namespace CryptoPP;
|
using namespace CryptoPP;
|
||||||
@@ -18,21 +19,33 @@ using namespace std;
|
|||||||
static const CString SIGNATURE_POSPEND = ".sig.rsa";
|
static const CString SIGNATURE_POSPEND = ".sig.rsa";
|
||||||
static const CString PRIVATE_KEY_PATH = "private.rsa";
|
static const CString PRIVATE_KEY_PATH = "private.rsa";
|
||||||
static const CString PUBLIC_KEY_PATH = "public.rsa";
|
static const CString PUBLIC_KEY_PATH = "public.rsa";
|
||||||
|
static const int KEY_LENGTH = 1024;
|
||||||
|
|
||||||
|
CryptManager* CRYPTMAN = NULL; // global and accessable from anywhere in our program
|
||||||
|
|
||||||
|
CryptManager::CryptManager()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void CryptManager::GenerateRSAKey(unsigned int keyLength, const char *privFilename, const char *pubFilename, const char *seed)
|
|
||||||
{
|
{
|
||||||
RandomPool randPool;
|
//
|
||||||
randPool.Put((byte *)seed, strlen(seed));
|
// generate keys if none are available
|
||||||
|
//
|
||||||
|
if( !DoesFileExist(PRIVATE_KEY_PATH) || !DoesFileExist(PUBLIC_KEY_PATH) )
|
||||||
|
{
|
||||||
|
LOG->Warn( "Keys missing. Generating new keys" );
|
||||||
|
GenerateRSAKey( KEY_LENGTH, PRIVATE_KEY_PATH, PUBLIC_KEY_PATH, "aoksdjaksd" );
|
||||||
|
FlushDirCache();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
RSAES_OAEP_SHA_Decryptor priv(randPool, keyLength);
|
CryptManager::~CryptManager()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CryptManager::GenerateRSAKey(unsigned int keyLength, const char *privFilename, const char *pubFilename, const char *seed )
|
||||||
|
{
|
||||||
|
AutoSeededRandomPool rng;
|
||||||
|
|
||||||
|
RSAES_OAEP_SHA_Decryptor priv(rng, keyLength);
|
||||||
HexEncoder privFile(new RageFileSink(privFilename));
|
HexEncoder privFile(new RageFileSink(privFilename));
|
||||||
priv.DEREncode(privFile);
|
priv.DEREncode(privFile);
|
||||||
privFile.MessageEnd();
|
privFile.MessageEnd();
|
||||||
@@ -49,16 +62,17 @@ void CryptManager::SignFile( CString sPath )
|
|||||||
CString sMessageFilename = sPath;;
|
CString sMessageFilename = sPath;;
|
||||||
CString sSignatureFilename = sPath + SIGNATURE_POSPEND;
|
CString sSignatureFilename = sPath + SIGNATURE_POSPEND;
|
||||||
|
|
||||||
if( !IsAFile(sMessageFilename) || !IsAFile(sPrivFilename) )
|
ASSERT( IsAFile(sPrivFilename) );
|
||||||
|
|
||||||
|
if( !IsAFile(sMessageFilename) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// CAREFUL: These classes can throw all kinds of exceptions. Should this
|
// CAREFUL: These classes can throw all kinds of exceptions. Should this
|
||||||
// be wrapped in a try catch?
|
// be wrapped in a try catch?
|
||||||
|
|
||||||
// TODO: use RageFile here
|
|
||||||
RageFileSource privFile(sPrivFilename, true, new HexDecoder);
|
RageFileSource privFile(sPrivFilename, true, new HexDecoder);
|
||||||
RSASSA_PKCS1v15_SHA_Signer priv(privFile);
|
RSASSA_PKCS1v15_SHA_Signer priv(privFile);
|
||||||
RandomNumberGenerator &rng = RandomPool();
|
AutoSeededRandomPool rng;
|
||||||
RageFileSource f(sMessageFilename, true, new SignerFilter(rng, priv, new HexEncoder(new RageFileSink(sSignatureFilename))));
|
RageFileSource f(sMessageFilename, true, new SignerFilter(rng, priv, new HexEncoder(new RageFileSink(sSignatureFilename))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,13 +82,14 @@ bool CryptManager::VerifyFile( CString sPath )
|
|||||||
CString sMessageFilename = sPath;;
|
CString sMessageFilename = sPath;;
|
||||||
CString sSignatureFilename = sPath + SIGNATURE_POSPEND;
|
CString sSignatureFilename = sPath + SIGNATURE_POSPEND;
|
||||||
|
|
||||||
if( !IsAFile(sSignatureFilename) || !IsAFile(sPubFilename) )
|
ASSERT( IsAFile(sPubFilename) );
|
||||||
|
|
||||||
|
if( !IsAFile(sSignatureFilename) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// CAREFUL: These classes can throw all kinds of exceptions. Should this
|
// CAREFUL: These classes can throw all kinds of exceptions. Should this
|
||||||
// be wrapped in a try catch?
|
// be wrapped in a try catch?
|
||||||
|
|
||||||
// TODO: use RageFile here
|
|
||||||
RageFileSource pubFile(sPubFilename, true, new HexDecoder);
|
RageFileSource pubFile(sPubFilename, true, new HexDecoder);
|
||||||
RSASSA_PKCS1v15_SHA_Verifier pub(pubFile);
|
RSASSA_PKCS1v15_SHA_Verifier pub(pubFile);
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,10 @@
|
|||||||
class CryptManager
|
class CryptManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void GenerateRSAKey(unsigned int keyLength, const char *privFilename, const char *pubFilename, const char *seed);
|
CryptManager();
|
||||||
|
~CryptManager();
|
||||||
|
|
||||||
|
static void GenerateRSAKey(unsigned int keyLength, const char *privFilename, const char *pubFilename, const char *seed );
|
||||||
|
|
||||||
static void SignFile( CString sPath );
|
static void SignFile( CString sPath );
|
||||||
static bool VerifyFile( CString sPath );
|
static bool VerifyFile( CString sPath );
|
||||||
@@ -12,4 +15,6 @@ public:
|
|||||||
static void DigestFile(const char *filename);
|
static void DigestFile(const char *filename);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern CryptManager* CRYPTMAN; // global and accessable from anywhere in our program
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
#include "RageException.h"
|
#include "RageException.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
FontManager* FONT = NULL;
|
FontManager* FONT = NULL; // global and accessable from anywhere in our program
|
||||||
|
|
||||||
// map from file name to a texture holder
|
// map from file name to a texture holder
|
||||||
typedef pair<CString,CString> FontName;
|
typedef pair<CString,CString> FontName;
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ ProfileManager.cpp ProfileManager.h ScreenManager.cpp ScreenManager.h SongManage
|
|||||||
UnlockSystem.cpp UnlockSystem.h
|
UnlockSystem.cpp UnlockSystem.h
|
||||||
|
|
||||||
cryptlib = \
|
cryptlib = \
|
||||||
crypto51/algparam.cpp crypto51/asn.cpp crypto51/basecode.cpp crypto51/channels.cpp crypto51/cryptlib.cpp crypto51/des.cpp crypto51/dessp.cpp crypto51/files.cpp crypto51/filters.cpp crypto51/fips140.cpp crypto51/hex.cpp crypto51/integer.cpp crypto51/iterhash.cpp crypto51/md5.cpp crypto51/misc.cpp crypto51/modes.cpp crypto51/mqueue.cpp crypto51/nbtheory.cpp crypto51/pkcspad.cpp crypto51/pssr.cpp crypto51/pubkey.cpp crypto51/queue.cpp crypto51/randpool.cpp crypto51/rsa.cpp crypto51/sha.cpp crypto51/strciphr.cpp
|
crypto51/algparam.cpp crypto51/asn.cpp crypto51/basecode.cpp crypto51/channels.cpp crypto51/cryptlib.cpp crypto51/des.cpp crypto51/dessp.cpp crypto51/files.cpp crypto51/filters.cpp crypto51/fips140.cpp crypto51/hex.cpp crypto51/integer.cpp crypto51/iterhash.cpp crypto51/md5.cpp crypto51/misc.cpp crypto51/modes.cpp crypto51/mqueue.cpp crypto51/nbtheory.cpp crypto51/osrng.cpp crypto51/pkcspad.cpp crypto51/pssr.cpp crypto51/pubkey.cpp crypto51/queue.cpp crypto51/randpool.cpp crypto51/rsa.cpp crypto51/sha.cpp crypto51/strciphr.cpp
|
||||||
|
|
||||||
stepmania_SOURCES = $(Screens) $(DataStructures) $(FileTypes) $(StepMania) $(Arch) \
|
stepmania_SOURCES = $(Screens) $(DataStructures) $(FileTypes) $(StepMania) $(Arch) \
|
||||||
$(ActorsInGameplayAndMenus) $(ActorsInMenus) $(ActorsInGameplay) \
|
$(ActorsInGameplayAndMenus) $(ActorsInMenus) $(ActorsInGameplay) \
|
||||||
|
|||||||
@@ -32,7 +32,6 @@
|
|||||||
#include "SDL_utils.h"
|
#include "SDL_utils.h"
|
||||||
|
|
||||||
#include "CodeDetector.h"
|
#include "CodeDetector.h"
|
||||||
#include "CryptManager.h"
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// StepMania global classes
|
// StepMania global classes
|
||||||
@@ -59,6 +58,7 @@
|
|||||||
#include "Bookkeeper.h"
|
#include "Bookkeeper.h"
|
||||||
#include "LightsManager.h"
|
#include "LightsManager.h"
|
||||||
#include "ModelManager.h"
|
#include "ModelManager.h"
|
||||||
|
#include "CryptManager.h"
|
||||||
|
|
||||||
|
|
||||||
#if defined(_XBOX)
|
#if defined(_XBOX)
|
||||||
@@ -960,6 +960,7 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
/* depends on SONGINDEX: */
|
/* depends on SONGINDEX: */
|
||||||
SONGMAN = new SongManager( loading_window ); // this takes a long time to load
|
SONGMAN = new SongManager( loading_window ); // this takes a long time to load
|
||||||
|
CRYPTMAN = new CryptManager; // need to do this before ProfileMan
|
||||||
MEMCARDMAN = new MemoryCardManager;
|
MEMCARDMAN = new MemoryCardManager;
|
||||||
PROFILEMAN = new ProfileManager; // must load after SONGMAN
|
PROFILEMAN = new ProfileManager; // must load after SONGMAN
|
||||||
UNLOCKSYS = new UnlockSystem;
|
UNLOCKSYS = new UnlockSystem;
|
||||||
@@ -1044,6 +1045,7 @@ int main(int argc, char* argv[])
|
|||||||
SAFE_DELETE( UNLOCKSYS );
|
SAFE_DELETE( UNLOCKSYS );
|
||||||
SAFE_DELETE( MODELMAN );
|
SAFE_DELETE( MODELMAN );
|
||||||
SAFE_DELETE( PROFILEMAN ); // PROFILEMAN needs the songs still loaded
|
SAFE_DELETE( PROFILEMAN ); // PROFILEMAN needs the songs still loaded
|
||||||
|
SAFE_DELETE( CRYPTMAN );
|
||||||
SAFE_DELETE( MEMCARDMAN );
|
SAFE_DELETE( MEMCARDMAN );
|
||||||
SAFE_DELETE( SONGMAN );
|
SAFE_DELETE( SONGMAN );
|
||||||
SAFE_DELETE( BANNERCACHE );
|
SAFE_DELETE( BANNERCACHE );
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ IntDir=.\../Debug6
|
|||||||
TargetDir=\stepmania\stepmania\Program
|
TargetDir=\stepmania\stepmania\Program
|
||||||
TargetName=StepMania-debug
|
TargetName=StepMania-debug
|
||||||
SOURCE="$(InputPath)"
|
SOURCE="$(InputPath)"
|
||||||
PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\
|
PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\
|
||||||
PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi
|
PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi
|
||||||
# End Special Build Tool
|
# End Special Build Tool
|
||||||
|
|
||||||
@@ -142,7 +142,7 @@ IntDir=.\../Release6
|
|||||||
TargetDir=\stepmania\stepmania\Program
|
TargetDir=\stepmania\stepmania\Program
|
||||||
TargetName=StepMania
|
TargetName=StepMania
|
||||||
SOURCE="$(InputPath)"
|
SOURCE="$(InputPath)"
|
||||||
PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\
|
PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\
|
||||||
PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi
|
PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi
|
||||||
# End Special Build Tool
|
# End Special Build Tool
|
||||||
|
|
||||||
@@ -6416,6 +6416,21 @@ SOURCE=.\crypto51\nbtheory.cpp
|
|||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\crypto51\osrng.cpp
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "StepMania - Win32 Debug"
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "StepMania - Xbox Debug"
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "StepMania - Win32 Release"
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "StepMania - Xbox Release"
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=.\crypto51\pkcspad.cpp
|
SOURCE=.\crypto51\pkcspad.cpp
|
||||||
|
|
||||||
!IF "$(CFG)" == "StepMania - Win32 Debug"
|
!IF "$(CFG)" == "StepMania - Win32 Debug"
|
||||||
|
|||||||
@@ -2141,6 +2141,9 @@ cl /Zl /nologo /c verstub.cpp /Fo"$(IntDir)"\
|
|||||||
<File
|
<File
|
||||||
RelativePath="crypto51\nbtheory.cpp">
|
RelativePath="crypto51\nbtheory.cpp">
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="crypto51\osrng.cpp">
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="crypto51\pkcspad.cpp">
|
RelativePath="crypto51\pkcspad.cpp">
|
||||||
</File>
|
</File>
|
||||||
|
|||||||
Reference in New Issue
Block a user