better api
This commit is contained in:
@@ -14,7 +14,7 @@ static const RString PRIVATE_KEY_PATH = "Data/private.rsa";
|
|||||||
static const RString PUBLIC_KEY_PATH = "Data/public.rsa";
|
static const RString PUBLIC_KEY_PATH = "Data/public.rsa";
|
||||||
static const RString ALTERNATE_PUBLIC_KEY_DIR = "Data/keys/";
|
static const RString ALTERNATE_PUBLIC_KEY_DIR = "Data/keys/";
|
||||||
|
|
||||||
static bool HashFile( RageFile &f, unsigned char buf_hash[20], int iHash )
|
static bool HashFile( RageFileBasic &f, unsigned char buf_hash[20], int iHash )
|
||||||
{
|
{
|
||||||
hash_state hash;
|
hash_state hash;
|
||||||
int iRet = hash_descriptor[iHash].init( &hash );
|
int iRet = hash_descriptor[iHash].init( &hash );
|
||||||
@@ -25,7 +25,7 @@ static bool HashFile( RageFile &f, unsigned char buf_hash[20], int iHash )
|
|||||||
{
|
{
|
||||||
if( f.Read(s, 1024*4) == -1 )
|
if( f.Read(s, 1024*4) == -1 )
|
||||||
{
|
{
|
||||||
LOG->Warn( "Error reading %s: %s", f.GetPath().c_str(), f.GetError().c_str() );
|
LOG->Warn( "Error reading %s: %s", f.GetDisplayPath().c_str(), f.GetError().c_str() );
|
||||||
hash_descriptor[iHash].done( &hash, buf_hash );
|
hash_descriptor[iHash].done( &hash, buf_hash );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -358,11 +358,6 @@ bool CryptManager::VerifyFileWithFile( RString sPath, RString sSignatureFile, RS
|
|||||||
if( !GetFileContents(sSignatureFile, sSignature) )
|
if( !GetFileContents(sSignatureFile, sSignature) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return Verify( sPath, sSignature, sPublicKey );
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CryptManager::Verify( RString sPath, RString sSignature, RString sPublicKey )
|
|
||||||
{
|
|
||||||
RageFile file;
|
RageFile file;
|
||||||
if( !file.Open(sPath) )
|
if( !file.Open(sPath) )
|
||||||
{
|
{
|
||||||
@@ -370,6 +365,11 @@ bool CryptManager::Verify( RString sPath, RString sSignature, RString sPublicKey
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Verify( file, sSignature, sPublicKey );
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CryptManager::Verify( RageFileBasic &file, RString sSignature, RString sPublicKey )
|
||||||
|
{
|
||||||
RSAKeyWrapper key;
|
RSAKeyWrapper key;
|
||||||
if( !key.Load(sPublicKey) )
|
if( !key.Load(sPublicKey) )
|
||||||
return false;
|
return false;
|
||||||
@@ -387,13 +387,13 @@ bool CryptManager::Verify( RString sPath, RString sSignature, RString sPublicKey
|
|||||||
|
|
||||||
if( iRet != CRYPT_OK )
|
if( iRet != CRYPT_OK )
|
||||||
{
|
{
|
||||||
LOG->Warn( "Verify(%s) failed: %s", sPath.c_str(), error_to_string(iRet) );
|
LOG->Warn( "Verify(%s) failed: %s", file.GetDisplayPath().c_str(), error_to_string(iRet) );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !iMatch )
|
if( !iMatch )
|
||||||
{
|
{
|
||||||
LOG->Warn( "Verify(%s) failed: signature mismatch", sPath.c_str() );
|
LOG->Warn( "Verify(%s) failed: signature mismatch", file.GetDisplayPath().c_str() );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public:
|
|||||||
static bool Sign( RString sPath, RString &sSignatureOut, RString sPrivateKey );
|
static bool Sign( RString sPath, RString &sSignatureOut, RString sPrivateKey );
|
||||||
static bool VerifyFileWithFile( RString sPath, RString sSignatureFile = "" );
|
static bool VerifyFileWithFile( RString sPath, RString sSignatureFile = "" );
|
||||||
static bool VerifyFileWithFile( RString sPath, RString sSignatureFile, RString sPublicKeyFile );
|
static bool VerifyFileWithFile( RString sPath, RString sSignatureFile, RString sPublicKeyFile );
|
||||||
static bool Verify( RString sPath, RString sSignature, RString sPublicKey );
|
static bool Verify( RageFileBasic &file, RString sSignature, RString sPublicKey );
|
||||||
|
|
||||||
static void GetRandomBytes( void *pData, int iBytes );
|
static void GetRandomBytes( void *pData, int iBytes );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user