e44aba00f1
- modifiche per prima versione chiave di rete.
172 lines
4.7 KiB
C++
172 lines
4.7 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2015-2022
|
|
//----------------------------------------------------------------------------
|
|
// File : ProtectionId.cpp Data : 16.05.22 Versione : 2.4e3
|
|
// Contenuto : Funzioni per gestione/calcolo Id protezione.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 28.07.15 DS Creazione modulo.
|
|
// 16.05.22 DS Aggiunta gestione chiave di rete.
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//------------------ Include -------------------------------------------------
|
|
#include "stdafx.h"
|
|
#include "MachineId.h"
|
|
#include "DongleId.h"
|
|
#include "NetDongleId.h"
|
|
#include "DongleSN.h"
|
|
#include "Obfuscate.h"
|
|
#include "/EgtDev/Include/EgtBase64.h"
|
|
#include "/EgtDev/Include/EgtCrc32.h"
|
|
#include "/EgtDev/Include/SELkLockId.h"
|
|
|
|
using namespace std ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int s_nLockType = KEY_LOCK_TYPE_ANY ;
|
|
static bool s_bNetHwKey = false ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SetLockType( int nType)
|
|
{
|
|
if ( nType != KEY_LOCK_TYPE_ANY &&
|
|
nType != KEY_LOCK_TYPE_SW &&
|
|
nType != KEY_LOCK_TYPE_HW)
|
|
return false ;
|
|
s_nLockType = nType ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
SetNetHwKey( bool bNetHwKey)
|
|
{
|
|
s_bNetHwKey = bNetHwKey ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GetLockId( string& sLockId)
|
|
{
|
|
switch ( s_nLockType) {
|
|
default : // KEY_LOCK_TYPE_ANY
|
|
if ( ! s_bNetHwKey) {
|
|
if ( GetDongleId( sLockId))
|
|
return true ;
|
|
}
|
|
else {
|
|
if ( GetNetDongleId( sLockId))
|
|
return true ;
|
|
}
|
|
return GetMachineId( sLockId) ;
|
|
case KEY_LOCK_TYPE_SW :
|
|
return GetMachineId( sLockId) ;
|
|
case KEY_LOCK_TYPE_HW :
|
|
if ( ! s_bNetHwKey) {
|
|
if ( GetDongleId( sLockId))
|
|
return true ;
|
|
}
|
|
else {
|
|
if ( GetNetDongleId( sLockId))
|
|
return true ;
|
|
}
|
|
return false ;
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GetLockId2( string& sLockId)
|
|
{
|
|
string sTmp ;
|
|
if ( ! GetLockId( sTmp))
|
|
return false ;
|
|
return ConvertLockIdToLockId2( sTmp, sLockId) ;
|
|
}
|
|
|
|
//------------------------------------------------------------------------------------
|
|
bool
|
|
ConvertLockIdToLockId2( const string& sLockId, string& sLockId2)
|
|
{
|
|
// eseguo Mix + CRC32 + Base64
|
|
string sAux = sLockId ;
|
|
if ( ! MixLockId( sAux))
|
|
return false ;
|
|
AddCrc32ToString( sAux) ;
|
|
return B64Encode( sAux, sLockId2) ;
|
|
}
|
|
|
|
//------------------------------------------------------------------------------------
|
|
bool
|
|
ConvertLockId2ToLockId( const string& sLockId2, string& sLockId)
|
|
{
|
|
// eseguo decodifica da Base64
|
|
if ( ! B64Decode( sLockId2, sLockId))
|
|
return false ;
|
|
// eseguo test e rimozione CRC32
|
|
if ( ! TestCrc32AndRemoveFromString( sLockId))
|
|
return false ;
|
|
// eseguo demixing
|
|
if ( ! MixLockId( sLockId))
|
|
return false ;
|
|
return true ;
|
|
}
|
|
|
|
//------------------------------------------------------------------------------------
|
|
bool
|
|
ConvertLockIdToScramKey( const string& sLockId, string& sScramKey)
|
|
{
|
|
// eseguo Mix
|
|
sScramKey = sLockId ;
|
|
if ( ! MixLockId( sScramKey))
|
|
return false ;
|
|
// eseguo scramble
|
|
if ( ! ScrambleLockId( sScramKey))
|
|
return false ;
|
|
// aggiungo CRC32
|
|
AddCrc32ToString( sScramKey) ;
|
|
return true ;
|
|
}
|
|
|
|
//------------------------------------------------------------------------------------
|
|
bool
|
|
ConvertLockId2ToScramKey( const string& sLockId2, string& sScramKey)
|
|
{
|
|
// eseguo decodifica da Base64
|
|
if ( ! B64Decode( sLockId2, sScramKey))
|
|
return false ;
|
|
// eseguo test e rimozione CRC32
|
|
if ( ! TestCrc32AndRemoveFromString( sScramKey))
|
|
return false ;
|
|
// eseguo scramble
|
|
if ( ! ScrambleLockId( sScramKey))
|
|
return false ;
|
|
// aggiungo CRC32
|
|
AddCrc32ToString( sScramKey) ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GetLockSN( int& nLockSN)
|
|
{
|
|
switch ( s_nLockType) {
|
|
default : // KEY_LOCK_TYPE_ANY
|
|
if ( GetDongleSN( nLockSN))
|
|
return true ;
|
|
else {
|
|
nLockSN = 0 ;
|
|
return false ;
|
|
}
|
|
case KEY_LOCK_TYPE_SW :
|
|
nLockSN = 0 ;
|
|
return false ;
|
|
case KEY_LOCK_TYPE_HW :
|
|
return GetDongleSN( nLockSN) ;
|
|
}
|
|
}
|