diff --git a/stepmania/src/CryptManager.cpp b/stepmania/src/CryptManager.cpp index 922b07b904..8807b63f7b 100644 --- a/stepmania/src/CryptManager.cpp +++ b/stepmania/src/CryptManager.cpp @@ -14,7 +14,7 @@ static const CString PRIVATE_KEY_PATH = "Data/private.rsa"; static const CString PUBLIC_KEY_PATH = "Data/public.rsa"; static const CString ALTERNATE_PUBLIC_KEY_DIR = "Data/keys/"; -#if !defined(XHAVE_CRYPTOPP) +#if !defined(HAVE_CRYPTOPP) CryptManager::CryptManager() { } CryptManager::~CryptManager() { } void CryptManager::GenerateRSAKey( unsigned int keyLength, CString privFilename, CString pubFilename, CString seed ) { } @@ -137,19 +137,39 @@ void CryptManager::SignFileToFile( CString sPath, CString sSignatureFile ) return; } + RageFile file; + if( !file.Open(sMessageFilename) ) + { + LOG->Warn( "VerifyFileWithFile: open(%s) failed: %s", sPath.c_str(), file.GetError().c_str() ); + return; + } + CString sSignature; + CString sError; + if( !SignFile(file, sPrivKey, sSignature, sError) ) + { + LOG->Warn( "SignFileToFile failed: %s", sError.c_str() ); + return; + } + + WriteFile( sSignatureFile, sSignature ); +} + +bool CryptManager::SignFile( RageFileBasic &file, CString sPrivKey, CString &sSignatureOut, CString &sError ) +{ try { StringSource privFile( sPrivKey, true ); RSASSA_PKCS1v15_SHA_Signer priv(privFile); NonblockingRng rng; - RageFileSource f(sMessageFilename, true, new SignerFilter(rng, priv, new StringSink(sSignature))); + /* RageFileSource will delete the file we give to it, so make a copy. */ + RageFileSource f( file.Copy(), true, new SignerFilter(rng, priv, new StringSink(sSignatureOut)) ); } catch( const CryptoPP::Exception &s ) { LOG->Warn( "SignFileToFile failed: %s", s.what() ); - return; + return false; } - WriteFile( sSignatureFile, sSignature ); + return true; } bool CryptManager::VerifyFileWithFile( CString sPath, CString sSignatureFile ) diff --git a/stepmania/src/CryptManager.h b/stepmania/src/CryptManager.h index 829e88ae41..c2ac2c3bc4 100644 --- a/stepmania/src/CryptManager.h +++ b/stepmania/src/CryptManager.h @@ -14,6 +14,7 @@ public: static void GenerateRSAKey( unsigned int keyLength, CString privFilename, CString pubFilename, CString seed ); static void SignFileToFile( CString sPath, CString sSignatureFile = "" ); + static bool SignFile( RageFileBasic &file, CString sPrivKey, CString &sSignatureOut, CString &sError ); static bool VerifyFile( RageFileBasic &file, CString sSignature, CString sPublicKey, CString &sError ); static bool VerifyFileWithFile( CString sPath, CString sSignatureFile = "" ); static bool VerifyFileWithFile( CString sPath, CString sSignatureFile, CString sPublicKeyFile );