From dfd5e7eb36721032d6438b606a9a5acdbd196b34 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Sat, 14 Feb 2004 20:47:50 +0000 Subject: [PATCH] sign screenshots saved to a profile --- stepmania/src/CryptHelpers.cpp | 4 +-- stepmania/src/CryptHelpers.h | 4 +++ stepmania/src/ScreenEvaluation.cpp | 2 +- stepmania/src/StepMania.cpp | 47 +++++++++++++++++++++++------- stepmania/src/StepMania.h | 2 +- 5 files changed, 45 insertions(+), 14 deletions(-) diff --git a/stepmania/src/CryptHelpers.cpp b/stepmania/src/CryptHelpers.cpp index f0050c2da5..b44c12987a 100644 --- a/stepmania/src/CryptHelpers.cpp +++ b/stepmania/src/CryptHelpers.cpp @@ -30,8 +30,8 @@ void RSASignFile(const char *privFilename, const char *messageFilename, const ch { FileSource privFile(privFilename, true, new HexDecoder); RSASSA_PKCS1v15_SHA_Signer priv(privFile); - // RSASSA_PKCS1v15_SHA_Signer ignores the rng. Use a real RNG for other signature schemes! - FileSource f(messageFilename, true, new SignerFilter(NullRNG(), priv, new HexEncoder(new FileSink(signatureFilename)))); + RandomNumberGenerator &rng = RandomPool(); + FileSource f(messageFilename, true, new SignerFilter(rng, priv, new HexEncoder(new FileSink(signatureFilename)))); } bool RSAVerifyFile(const char *pubFilename, const char *messageFilename, const char *signatureFilename) diff --git a/stepmania/src/CryptHelpers.h b/stepmania/src/CryptHelpers.h index 4463315925..8065a116ab 100644 --- a/stepmania/src/CryptHelpers.h +++ b/stepmania/src/CryptHelpers.h @@ -1,6 +1,10 @@ #ifndef CryptHelpers_H #define CryptHelpers_H +void GenerateRSAKey(unsigned int keyLength, const char *privFilename, const char *pubFilename, const char *seed); +void RSASignFile(const char *privFilename, const char *messageFilename, const char *signatureFilename); +bool RSAVerifyFile(const char *pubFilename, const char *messageFilename, const char *signatureFilename); +void DigestFile(const char *filename); #endif diff --git a/stepmania/src/ScreenEvaluation.cpp b/stepmania/src/ScreenEvaluation.cpp index 737c0dd543..9e1b05939b 100644 --- a/stepmania/src/ScreenEvaluation.cpp +++ b/stepmania/src/ScreenEvaluation.cpp @@ -1322,7 +1322,7 @@ void ScreenEvaluation::Input( const DeviceInput& DeviceI, const InputEventType t /* StyleI won't be valid if it's a menu button that's pressed. * There's got to be a better way of doing this. -Chris */ CString sDir = PROFILEMAN->GetProfileDir((ProfileSlot)pn); - SaveScreenshot( sDir ); + SaveScreenshot( sDir, true, true ); m_bSavedScreenshot[pn] = true; return; // handled } diff --git a/stepmania/src/StepMania.cpp b/stepmania/src/StepMania.cpp index 05ac33a881..4e46f27f12 100644 --- a/stepmania/src/StepMania.cpp +++ b/stepmania/src/StepMania.cpp @@ -32,6 +32,7 @@ #include "SDL_utils.h" #include "CodeDetector.h" +#include "CryptHelpers.h" // // StepMania global classes @@ -791,6 +792,11 @@ void SaveGamePrefsToDisk() ini.WriteFile(); } +static void OnFirstRun() +{ + // TODO: generate a machine keypair here +} + static void MountTreeOfZips( const CString &dir ) { vector dirs; @@ -916,6 +922,9 @@ int main(int argc, char* argv[]) CheckSDLVersion( 1,2,6 ); + if( PREFSMAN->m_bFirstRun ) + OnFirstRun(); + /* This should be done after PREFSMAN is set up, so it can use HOOKS->MessageBoxOK, * but before we do more complex things that might crash. */ HOOKS->DumpDebugInfo(); @@ -1083,25 +1092,43 @@ int main(int argc, char* argv[]) return 0; } -bool SaveScreenshot( CString sDir, bool bSaveUncompressed ) +bool SaveScreenshot( CString sDir, bool bSaveCompressed, bool bMakeSignature ) { - // Save Screenshot. - CString sPath; - + // + // Find a file name for the screenshot + // FlushDirCache(); + CString sScreenshotPath; /* XXX slow? */ for( int i=0; i<10000; i++ ) { - sPath = ssprintf( sDir+"screen%04d.%s",i,bSaveUncompressed ? "bmp" : "jpg" ); - if( !DoesFileExist(sPath) ) + sScreenshotPath = ssprintf( sDir+"screen%04d.%s", i, bSaveCompressed ? "jpg" : "bmp" ); + if( !DoesFileExist(sScreenshotPath) ) break; } - bool bResult = DISPLAY->SaveScreenshot( sPath, bSaveUncompressed ? RageDisplay::bmp : RageDisplay::jpg ); + + // + // Save the screenshot + // + bool bResult = DISPLAY->SaveScreenshot( sScreenshotPath, bSaveCompressed ? RageDisplay::jpg : RageDisplay::bmp ); if( bResult ) SOUND->PlayOnce( THEME->GetPathToS("Common screenshot") ); else + { SOUND->PlayOnce( THEME->GetPathToS("Common invalid") ); + return false; + } + + // + // Write a signature + // + if( bMakeSignature ) + { + CString sSignaturePath = sScreenshotPath + ".sig.rsa"; + RSASignFile( "private.rsa", sScreenshotPath, sSignaturePath); + } + return bResult; } @@ -1203,9 +1230,9 @@ bool HandleGlobalInputs( DeviceInput DeviceI, InputEventType type, GameInput Gam (INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_RMETA)) || INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_LMETA))))) { - // If holding LShift save a BMP, else save a JPG - bool bSaveUncompressed = INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_LSHIFT) ); - SaveScreenshot( "Screenshots/", bSaveUncompressed ); + // If holding LShift save uncompressed, else save compressed + bool bSaveCompressed = !INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_LSHIFT) ); + SaveScreenshot( "Screenshots/", bSaveCompressed, false ); return true; // handled } diff --git a/stepmania/src/StepMania.h b/stepmania/src/StepMania.h index 9b858b1736..8e0cd7adc0 100644 --- a/stepmania/src/StepMania.h +++ b/stepmania/src/StepMania.h @@ -20,7 +20,7 @@ void ResetGame( bool ReturnToFirstScreen=true ); void ReadGamePrefsFromDisk( bool bSwitchToLastPlayedGame=true ); void SaveGamePrefsToDisk(); void ChangeCurrentGame( Game g ); -bool SaveScreenshot( CString sDir, bool bSaveUncompressed = false ); +bool SaveScreenshot( CString sDir, bool bSaveCompressed, bool bMakeSignature ); #if defined(_WINDOWS) #include "windows.h"