Files
EgtLock/NetDongleId.cpp
T
DarioS e44aba00f1 EgtLock 2.4e3 :
- modifiche per prima versione chiave di rete.
2022-05-17 08:27:01 +02:00

141 lines
4.3 KiB
C++

//----------------------------------------------------------------------------
// 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 ;
}