From e44aba00f12bdf3f8ec0c7c6be221f05126ddbae Mon Sep 17 00:00:00 2001 From: DarioS Date: Tue, 17 May 2022 08:27:01 +0200 Subject: [PATCH] EgtLock 2.4e3 : - modifiche per prima versione chiave di rete. --- EgtLock.vcxproj | 1 + EgtLock.vcxproj.filters | 3 + LockId.cpp | 39 +++++++---- NetDongleId.cpp | 140 ++++++++++++++++++++++++++++++++++++++++ NetDongleId.h | 21 ++++++ 5 files changed, 193 insertions(+), 11 deletions(-) create mode 100644 NetDongleId.cpp create mode 100644 NetDongleId.h diff --git a/EgtLock.vcxproj b/EgtLock.vcxproj index 534d375..c7849f8 100644 --- a/EgtLock.vcxproj +++ b/EgtLock.vcxproj @@ -198,6 +198,7 @@ copy $(TargetDir)$(TargetName).lib \EgtDev\Lib\ + diff --git a/EgtLock.vcxproj.filters b/EgtLock.vcxproj.filters index 0a6ecbc..f4db985 100644 --- a/EgtLock.vcxproj.filters +++ b/EgtLock.vcxproj.filters @@ -74,5 +74,8 @@ File di origine + + File di origine + \ No newline at end of file diff --git a/LockId.cpp b/LockId.cpp index 8a4d47b..78be3a6 100644 --- a/LockId.cpp +++ b/LockId.cpp @@ -1,13 +1,13 @@ //---------------------------------------------------------------------------- -// EgalTech 2015-2015 +// EgalTech 2015-2022 //---------------------------------------------------------------------------- -// File : ProtectionId.cpp Data : 28.07.15 Versione : 1.6g8 +// 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. // //---------------------------------------------------------------------------- @@ -15,6 +15,7 @@ #include "stdafx.h" #include "MachineId.h" #include "DongleId.h" +#include "NetDongleId.h" #include "DongleSN.h" #include "Obfuscate.h" #include "/EgtDev/Include/EgtBase64.h" @@ -24,7 +25,8 @@ using namespace std ; //---------------------------------------------------------------------------- -static int s_nLockType = KEY_LOCK_TYPE_ANY ; +static int s_nLockType = KEY_LOCK_TYPE_ANY ; +static bool s_bNetHwKey = false ; //---------------------------------------------------------------------------- bool @@ -39,10 +41,11 @@ SetLockType( int nType) } //---------------------------------------------------------------------------- -int -GetLockType( void) +bool +SetNetHwKey( bool bNetHwKey) { - return s_nLockType ; + s_bNetHwKey = bNetHwKey ; + return true ; } //---------------------------------------------------------------------------- @@ -50,14 +53,28 @@ bool GetLockId( string& sLockId) { switch ( s_nLockType) { - default : // KEY_LOCK_TYPE_ANY - if ( GetDongleId( sLockId)) - return true ; + 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 : - return GetDongleId( sLockId) ; + if ( ! s_bNetHwKey) { + if ( GetDongleId( sLockId)) + return true ; + } + else { + if ( GetNetDongleId( sLockId)) + return true ; + } + return false ; } } diff --git a/NetDongleId.cpp b/NetDongleId.cpp new file mode 100644 index 0000000..3c659f9 --- /dev/null +++ b/NetDongleId.cpp @@ -0,0 +1,140 @@ +//---------------------------------------------------------------------------- +// EgalTech 2022-2022 +//---------------------------------------------------------------------------- +// File : NetDongleId.cpp Data : 16.05.22 Versione : 2.4e3 +// Contenuto : Funzioni per gestione/calcolo Id chiave di rete OxySec. +// +// +// +// Modifiche : 16.05.22 DS Creazione modulo. +// +// +// +//---------------------------------------------------------------------------- + +//------------------ Include ------------------------------------------------- +#include "stdafx.h" +#include "Obfuscate.h" +#include "NetDongleId.h" +#include "/EgtDev/Extern/OxySec/Include/xnd.h" + +using namespace std ; + +//---------------------------------------------------------------------------- +static XND_XLT_ENV s_env = nullptr ; +static XND_NET_DATA s_net_data = nullptr ; +static XND_DEVICE_CONTEXT s_dev_ctx = nullptr ; + +//---------------------------------------------------------------------------- +static const char* xnodus_key_blob = "WE5LAQAAAACW6vKd80xDCR_n4048UsW88BFhwxU0vBdAv-SmgK3VJczR_YqmsCTxpcVTqk3LKU3KCTkAWN"\ + "u5BgL4VU6WM-JvxW-eZHNWaiy5gfNPBVFyoMTI0BbfOF_gQDKe-nvdlMyCZW5gWL6CPUvr3ejSPkyl8atj"\ + "OZrUUzGSbHuig27z_6NVb2gyVFZJrUUioApP6b96qMIwQS2ME2v99w84pMSids1Okcrl3_aKHRwAH0hMJQ" ; + +//---------------------------------------------------------------------------- +bool +GetNetDongleId( string& sDongleId) +{ + if ( s_env == nullptr) { + if ( ! NetDongleConnect()) + return false ; + } + // richiamo funzioni di verifica chiave con decifratura RSA 512 di dati generati al volo + // ... DA FARE ... + // leggo l'identificativo della chiave dal banco 0 + unsigned char pwd[XLT_PASSWORD_SIZE] ; + unsigned char data[XLT_BANK_SIZE] ; + // M0nt3ReC@st3llo1985 + pwd[ 0] = 'M' ; + pwd[ 2] = 'n' ; + pwd[ 4] = '3' ; + pwd[ 6] = 'e' ; + pwd[ 8] = '@' ; + pwd[10] = 't' ; + pwd[12] = 'l' ; + pwd[14] = 'o' ; + pwd[16] = '9' ; + pwd[18] = '5' ; + pwd[20] = '\0' ; + pwd[22] = '\0' ; + pwd[24] = '\0' ; + pwd[26] = '\0' ; + pwd[28] = '\0' ; + pwd[30] = '\0' ; + pwd[ 1] = '0' ; + pwd[ 3] = 't' ; + pwd[ 5] = 'R' ; + pwd[ 7] = 'C' ; + pwd[ 9] = 's' ; + pwd[11] = '3' ; + pwd[13] = 'l' ; + pwd[15] = '1' ; + pwd[17] = '8' ; + pwd[19] = '\0' ; + pwd[21] = '\0' ; + pwd[23] = '\0' ; + pwd[25] = '\0' ; + pwd[27] = '\0' ; + pwd[29] = '\0' ; + pwd[31] = '\0' ; + int nRes = xnd_xlt_read( s_dev_ctx, pwd, 0, data) ; + bool bOk = ( nRes == XLT_ERROR_SUCCESS) ; + if ( bOk) + sDongleId = (char*) data ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +NetDongleConnect( void) +{ + // se connessione già aperta, la chiudo per poi riaprirla + if ( s_env != nullptr) + NetDongleClose() ; + // creo ambiente + s_env = xnd_xlt_env_create() ; + if ( s_env == nullptr) + return false ; + // cerco la chiave di rete + unsigned char label[XLT_LABEL_SIZE] ; + string sLabel = "EgalTech s.r.l. - CAD/CAM/CIM Software Solutions" ; + strcpy_s( (char*)label, XLT_LABEL_SIZE, sLabel.c_str()) ; + memset( label + sLabel.size(), 0x00, sizeof( label) - sLabel.size()) ; + int nStatusND = 0 ; + s_net_data = xnd_net_data_create_resolving_local_search( s_env, XND_DEFAULT_PORT, label, 30000, 0, 0, &nStatusND) ; + if ( s_net_data == nullptr) { + xnd_xlt_env_release( s_env) ; + return false ; + } + // cerco la chiave Xlight virtuale dell'utente anonimo + int nStatusDC = 0 ; + s_dev_ctx = xnd_xlt_devctx_xnodus_create2( s_env, s_net_data, xnodus_key_blob, nullptr, 0, XND_XLT_DEVCTX_FLAG_XNODUS_MULTI_INSTANCE, 0, &nStatusDC) ; + if ( s_dev_ctx == nullptr) { + xnd_xlt_env_release( s_env) ; + s_env = nullptr ; + s_net_data = nullptr ; + return false ; + } + // apro la sessione + int nStatOP = xnd_xlt_session_open( s_dev_ctx, 0) ; + if ( nStatOP != 0) { + xnd_xlt_devctx_release( s_dev_ctx) ; + xnd_xlt_env_release( s_env) ; + s_env = nullptr ; + s_net_data = nullptr ; + s_dev_ctx = nullptr ; + return false ; + } + return true ; +} + +//---------------------------------------------------------------------------- +bool +NetDongleClose( void) +{ + xnd_xlt_devctx_release( s_dev_ctx) ; // this close also the session! + xnd_xlt_env_free( s_env) ; + s_dev_ctx = nullptr ; + s_net_data = nullptr ; + s_env = nullptr ; + return true ; +} diff --git a/NetDongleId.h b/NetDongleId.h new file mode 100644 index 0000000..3820aa1 --- /dev/null +++ b/NetDongleId.h @@ -0,0 +1,21 @@ +//---------------------------------------------------------------------------- +// EgalTech 2022-2022 +//---------------------------------------------------------------------------- +// File : NetDongleId.h Data : 16.05.22 Versione : 2.4e3 +// Contenuto : Dichiarazione funzioni locali per gestione/calcolo Id chiave. +// +// +// +// Modifiche : 16.05.22 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include + +//------------------------------------------------------------------------------- +bool GetNetDongleId( std::string& sDongleId) ; +bool NetDongleConnect( void) ; +bool NetDongleClose( void) ;