@ -23,8 +23,9 @@
# include "crypt.h"
# include "crypt.h"
# include <framework/stdext/math.h>
# include <framework/stdext/math.h>
# include <framework/core/logger.h>
# include <framework/core/logger.h>
# include <framework/core/resourcemanager.h>
# include <framework/platform/platform.h>
# include <boost/uuid/uuid.hpp>
# include <boost/uuid/uuid_generators.hpp>
# include <boost/uuid/uuid_generators.hpp>
# include <boost/uuid/uuid_io.hpp>
# include <boost/uuid/uuid_io.hpp>
@ -157,10 +158,28 @@ std::string Crypt::genUUID()
return boost : : uuids : : to_string ( u ) ;
return boost : : uuids : : to_string ( u ) ;
}
}
std : : string Crypt : : genUUIDKey ( )
bool Crypt : : setMachineUUID ( const std : : string & uuidstr )
{
if ( uuidstr . empty ( ) )
return false ;
std : : stringstream ss ;
ss < < uuidstr ;
ss > > m_machineUUID ;
return ! m_machineUUID . is_nil ( ) ;
}
std : : string Crypt : : getMachineUUID ( )
{
return boost : : uuids : : to_string ( m_machineUUID ) ;
}
std : : string Crypt : : getMachineKey ( )
{
{
boost : : hash < boost : : uuids : : uuid > uuid_hasher ;
boost : : hash < boost : : uuids : : uuid > uuid_hasher ;
std : : size_t hash = uuid_hasher ( boost : : uuids : : uuid ( ) ) ;
boost : : uuids : : name_generator gen ( m_machineUUID ) ;
boost : : uuids : : uuid u = gen ( g_platform . getCPUName ( ) + g_platform . getOSName ( ) + g_resources . getUserDir ( ) ) ;
std : : size_t hash = uuid_hasher ( u ) ;
std : : string key ;
std : : string key ;
key . assign ( ( const char * ) & hash , sizeof ( hash ) ) ;
key . assign ( ( const char * ) & hash , sizeof ( hash ) ) ;
return key ;
return key ;
@ -171,14 +190,14 @@ std::string Crypt::encrypt(const std::string& decrypted_string)
std : : string tmp = " 0000 " + decrypted_string ;
std : : string tmp = " 0000 " + decrypted_string ;
uint32 sum = stdext : : adler32 ( ( const uint8 * ) decrypted_string . c_str ( ) , decrypted_string . size ( ) ) ;
uint32 sum = stdext : : adler32 ( ( const uint8 * ) decrypted_string . c_str ( ) , decrypted_string . size ( ) ) ;
stdext : : writeLE32 ( ( uint8 * ) & tmp [ 0 ] , sum ) ;
stdext : : writeLE32 ( ( uint8 * ) & tmp [ 0 ] , sum ) ;
std : : string encrypted = base64Encode ( xorCrypt ( tmp , ge nUUID Key( ) ) ) ;
std : : string encrypted = base64Encode ( xorCrypt ( tmp , ge tMachine Key( ) ) ) ;
return encrypted ;
return encrypted ;
}
}
std : : string Crypt : : decrypt ( const std : : string & encrypted_string )
std : : string Crypt : : decrypt ( const std : : string & encrypted_string )
{
{
std : : string decoded = base64Decode ( encrypted_string ) ;
std : : string decoded = base64Decode ( encrypted_string ) ;
std : : string tmp = xorCrypt ( base64Decode ( encrypted_string ) , ge nUUID Key( ) ) ;
std : : string tmp = xorCrypt ( base64Decode ( encrypted_string ) , ge tMachine Key( ) ) ;
if ( tmp . length ( ) > = 4 ) {
if ( tmp . length ( ) > = 4 ) {
uint32 readsum = stdext : : readLE32 ( ( const uint8 * ) tmp . c_str ( ) ) ;
uint32 readsum = stdext : : readLE32 ( ( const uint8 * ) tmp . c_str ( ) ) ;
std : : string decrypted_string = tmp . substr ( 4 ) ;
std : : string decrypted_string = tmp . substr ( 4 ) ;