create keypair on startup if one doesn't already exist

This commit is contained in:
Chris Danford
2004-02-15 05:45:18 +00:00
parent 0667124940
commit 5cc79c5f2b
7 changed files with 63 additions and 23 deletions
+32 -17
View File
@@ -2,6 +2,7 @@
#include "CryptManager.h"
#include "RageUtil.h"
#include "CryptHelpers.h"
#include "RageLog.h"
// crypt headers
#include "sha.h"
@@ -9,7 +10,7 @@
#include "channels.h"
#include "rsa.h"
#include "md5.h"
#include "randpool.h"
#include "osrng.h"
#include <memory>
using namespace CryptoPP;
@@ -18,21 +19,33 @@ using namespace std;
static const CString SIGNATURE_POSPEND = ".sig.rsa";
static const CString PRIVATE_KEY_PATH = "private.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
void CryptManager::GenerateRSAKey(unsigned int keyLength, const char *privFilename, const char *pubFilename, const char *seed)
CryptManager::CryptManager()
{
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));
priv.DEREncode(privFile);
privFile.MessageEnd();
@@ -49,16 +62,17 @@ void CryptManager::SignFile( CString sPath )
CString sMessageFilename = sPath;;
CString sSignatureFilename = sPath + SIGNATURE_POSPEND;
if( !IsAFile(sMessageFilename) || !IsAFile(sPrivFilename) )
ASSERT( IsAFile(sPrivFilename) );
if( !IsAFile(sMessageFilename) )
return;
// CAREFUL: These classes can throw all kinds of exceptions. Should this
// be wrapped in a try catch?
// TODO: use RageFile here
RageFileSource privFile(sPrivFilename, true, new HexDecoder);
RSASSA_PKCS1v15_SHA_Signer priv(privFile);
RandomNumberGenerator &rng = RandomPool();
AutoSeededRandomPool rng;
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 sSignatureFilename = sPath + SIGNATURE_POSPEND;
if( !IsAFile(sSignatureFilename) || !IsAFile(sPubFilename) )
ASSERT( IsAFile(sPubFilename) );
if( !IsAFile(sSignatureFilename) )
return false;
// CAREFUL: These classes can throw all kinds of exceptions. Should this
// be wrapped in a try catch?
// TODO: use RageFile here
RageFileSource pubFile(sPubFilename, true, new HexDecoder);
RSASSA_PKCS1v15_SHA_Verifier pub(pubFile);
+6 -1
View File
@@ -4,7 +4,10 @@
class CryptManager
{
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 bool VerifyFile( CString sPath );
@@ -12,4 +15,6 @@ public:
static void DigestFile(const char *filename);
};
extern CryptManager* CRYPTMAN; // global and accessable from anywhere in our program
#endif
+1 -1
View File
@@ -19,7 +19,7 @@
#include "RageException.h"
#include <map>
FontManager* FONT = NULL;
FontManager* FONT = NULL; // global and accessable from anywhere in our program
// map from file name to a texture holder
typedef pair<CString,CString> FontName;
+1 -1
View File
@@ -211,7 +211,7 @@ ProfileManager.cpp ProfileManager.h ScreenManager.cpp ScreenManager.h SongManage
UnlockSystem.cpp UnlockSystem.h
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) \
$(ActorsInGameplayAndMenus) $(ActorsInMenus) $(ActorsInGameplay) \
+3 -1
View File
@@ -32,7 +32,6 @@
#include "SDL_utils.h"
#include "CodeDetector.h"
#include "CryptManager.h"
//
// StepMania global classes
@@ -59,6 +58,7 @@
#include "Bookkeeper.h"
#include "LightsManager.h"
#include "ModelManager.h"
#include "CryptManager.h"
#if defined(_XBOX)
@@ -960,6 +960,7 @@ int main(int argc, char* argv[])
/* depends on SONGINDEX: */
SONGMAN = new SongManager( loading_window ); // this takes a long time to load
CRYPTMAN = new CryptManager; // need to do this before ProfileMan
MEMCARDMAN = new MemoryCardManager;
PROFILEMAN = new ProfileManager; // must load after SONGMAN
UNLOCKSYS = new UnlockSystem;
@@ -1044,6 +1045,7 @@ int main(int argc, char* argv[])
SAFE_DELETE( UNLOCKSYS );
SAFE_DELETE( MODELMAN );
SAFE_DELETE( PROFILEMAN ); // PROFILEMAN needs the songs still loaded
SAFE_DELETE( CRYPTMAN );
SAFE_DELETE( MEMCARDMAN );
SAFE_DELETE( SONGMAN );
SAFE_DELETE( BANNERCACHE );
+17 -2
View File
@@ -65,7 +65,7 @@ IntDir=.\../Debug6
TargetDir=\stepmania\stepmania\Program
TargetName=StepMania-debug
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
# End Special Build Tool
@@ -142,7 +142,7 @@ IntDir=.\../Release6
TargetDir=\stepmania\stepmania\Program
TargetName=StepMania
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
# End Special Build Tool
@@ -6416,6 +6416,21 @@ SOURCE=.\crypto51\nbtheory.cpp
# End 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
!IF "$(CFG)" == "StepMania - Win32 Debug"
+3
View File
@@ -2141,6 +2141,9 @@ cl /Zl /nologo /c verstub.cpp /Fo&quot;$(IntDir)&quot;\
<File
RelativePath="crypto51\nbtheory.cpp">
</File>
<File
RelativePath="crypto51\osrng.cpp">
</File>
<File
RelativePath="crypto51\pkcspad.cpp">
</File>