cc7630fa70
- aggiunta gestione chiavi di rete esposte su Internet (tramite inirizzo:porta).
186 lines
5.2 KiB
C++
186 lines
5.2 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2015-2023
|
|
//----------------------------------------------------------------------------
|
|
// File : ProtectionId.cpp Data : 30.05.23 Versione : 2.5e5
|
|
// Contenuto : Funzioni per gestione/calcolo Id protezione.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 28.07.15 DS Creazione modulo.
|
|
// 16.05.22 DS Aggiunta gestione chiave di rete.
|
|
// 30.05.23 DS Aggiunta gestione utente di rete.
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//------------------ Include -------------------------------------------------
|
|
#include "stdafx.h"
|
|
#include "MachineId.h"
|
|
#include "DongleId.h"
|
|
#include "NetDongleId.h"
|
|
#include "DongleSN.h"
|
|
#include "Obfuscate.h"
|
|
#include "/EgtDev/Include/EgtStringBase.h"
|
|
#include "/EgtDev/Include/EgtBase64.h"
|
|
#include "/EgtDev/Include/EgtCrc32.h"
|
|
#include "/EgtDev/Include/EgtNumUtils.h"
|
|
#include "/EgtDev/Include/SELkLockId.h"
|
|
|
|
using namespace std ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int s_nLockType = KEY_LOCK_TYPE_ANY ;
|
|
static bool s_bNetHwKey = false ;
|
|
static int s_nNetUserId = 0 ;
|
|
static string s_sAddrPort = "" ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
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, int nUserId, const std::string& sAddrPort)
|
|
{
|
|
s_bNetHwKey = bNetHwKey ;
|
|
if ( s_bNetHwKey) {
|
|
s_nLockType = KEY_LOCK_TYPE_HW ;
|
|
s_nNetUserId = Clamp( nUserId, 0, 9) ;
|
|
s_sAddrPort = sAddrPort ;
|
|
}
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
CloseNetHwKey( void)
|
|
{
|
|
return NetDongleClose() ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GetLockId( string& sLockId)
|
|
{
|
|
switch ( s_nLockType) {
|
|
default : // KEY_LOCK_TYPE_ANY
|
|
if ( s_bNetHwKey)
|
|
return GetNetDongleId( s_nNetUserId, s_sAddrPort, sLockId) ;
|
|
else if ( GetDongleId( sLockId))
|
|
return true ;
|
|
else
|
|
return GetMachineId( sLockId) ;
|
|
case KEY_LOCK_TYPE_SW :
|
|
return GetMachineId( sLockId) ;
|
|
case KEY_LOCK_TYPE_HW :
|
|
if ( ! s_bNetHwKey)
|
|
return GetDongleId( sLockId) ;
|
|
else
|
|
return GetNetDongleId( s_nNetUserId, s_sAddrPort, sLockId) ;
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
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 ( ! s_bNetHwKey && GetDongleSN( nLockSN))
|
|
return true ;
|
|
else {
|
|
nLockSN = 0 ;
|
|
return false ;
|
|
}
|
|
case KEY_LOCK_TYPE_SW :
|
|
nLockSN = 0 ;
|
|
return false ;
|
|
case KEY_LOCK_TYPE_HW :
|
|
if ( ! s_bNetHwKey)
|
|
return GetDongleSN( nLockSN) ;
|
|
else {
|
|
nLockSN = 0 ;
|
|
return false ;
|
|
}
|
|
}
|
|
}
|