Migliorato server delle chiavi di rete

git-svn-id: svn://10.65.10.50/trunk@6600 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1998-05-04 10:09:51 +00:00
parent cde8a89ecb
commit 6d14e30178
11 changed files with 316 additions and 127 deletions

View File

@ -11,20 +11,31 @@ int f_DongleHasModule(TConnection& conn, void* pJolly)
if (argc > 0)
{
const int n = atoi(argv[0]) - 1;
const unsigned short* int_tab = GetServer().Authorizations();
if (int_tab)
ok = (int_tab[n / 16] >> (n % 16)) & 0x1;
if (n >= 0)
{
unsigned short nSize;
const unsigned short* int_tab = GetServer().Authorizations(nSize);
if (int_tab)
{
const unsigned short index = n / 16;
if (index < (nSize/2))
ok = (int_tab[index] >> (n % 16)) & 0x1;
}
}
else
ok = TRUE;
}
return conn.ReturnBool(ok);
}
int f_DongleModules(TConnection& conn, void* pJolly)
{
const unsigned short* int_tab = GetServer().Authorizations();
unsigned short nSize;
const unsigned short* int_tab = GetServer().Authorizations(nSize);
if (int_tab)
{
BYTE* buff = GetServer().GetBuffer(8);
memcpy(buff, int_tab, 8);
BYTE* buff = GetServer().GetBuffer(nSize);
memcpy(buff, int_tab, nSize);
}
return int_tab != NULL;
}

Binary file not shown.

View File

@ -121,10 +121,9 @@ CommandCount=6
[DLG:IDD_STATUS]
Type=1
Class=CStatusDlg
ControlCount=3
ControlCount=2
Control1=IDOK,button,1342242817
Control2=IDC_STATIC,static,1342308352
Control3=IDC_USERS,edit,1350633600
Control2=IDC_GRID,{A8C3B720-0B5A-101B-B22E-00AA0037B2FC},1342242816
[CLS:CStatusDlg]
Type=0

View File

@ -60,6 +60,7 @@ BOOL CFrontEndApp::InitInstance()
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
AfxEnableControlContainer();
LoadStdProfileSettings(0); // Load standard INI file options (including MRU)

View File

@ -168,15 +168,14 @@ BEGIN
LTEXT "Physical memory",IDC_PHYSICAL_MEM,49,38,119,9,SS_SUNKEN
END
IDD_STATUS DIALOGEX 0, 0, 186, 69
IDD_STATUS DIALOG DISCARDABLE 0, 0, 186, 122
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Stato del sistema"
CAPTION "Utenti del sistema"
FONT 8, "MS Sans Serif"
BEGIN
DEFPUSHBUTTON "OK",IDOK,68,48,50,14
LTEXT "Numero di utenti",IDC_STATIC,7,7,111,8
EDITTEXT IDC_USERS,136,7,43,12,ES_AUTOHSCROLL | ES_READONLY,
WS_EX_RIGHT
DEFPUSHBUTTON "OK",IDOK,68,101,50,14
CONTROL "",IDC_GRID,"{A8C3B720-0B5A-101B-B22E-00AA0037B2FC}",
WS_TABSTOP,7,7,172,84
END
@ -244,12 +243,34 @@ BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 179
TOPMARGIN, 7
BOTTOMMARGIN, 62
BOTTOMMARGIN, 115
END
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Dialog Info
//
IDD_STATUS DLGINIT
BEGIN
IDC_GRID, 0x376, 164, 0
0x0024, 0x0000, 0x0041, 0x0036, 0x0044, 0x0041, 0x0038, 0x0035, 0x0038,
0x0030, 0x002d, 0x0035, 0x0039, 0x0044, 0x0036, 0x002d, 0x0031, 0x0030,
0x0031, 0x0042, 0x002d, 0x0041, 0x0033, 0x0043, 0x0039, 0x002d, 0x0030,
0x0038, 0x0030, 0x0030, 0x0032, 0x0042, 0x0032, 0x0046, 0x0034, 0x0039,
0x0046, 0x0042, 0x0000, 0x0001, 0x1aaa, 0x0000, 0x0e29, 0x0000, 0x004d,
0x0000, 0x0000, 0x0080, 0xffff, 0x00ff, 0x0300, 0xe352, 0x910b, 0xce8f,
0x9d11, 0x00e3, 0x00aa, 0xb84b, 0x0151, 0x0000, 0x9000, 0x4401, 0x0142,
0x0d00, 0x534d, 0x5320, 0x6e61, 0x2073, 0x6553, 0x6972, 0x0166, 0x0001,
0x0002, 0x0002, 0x0001, 0x0001, 0x0002, 0x0101, 0x0000, 0x0100, 0x0000,
0x00ff,
0
END
/////////////////////////////////////////////////////////////////////////////
//
// String Table

View File

@ -6,7 +6,6 @@
#include "FrontEnd.h"
#include "FrontDoc.h"
#include "FrontVw.h"
#include "Server.h"
#include "StatDlg.h"
#include "Tracing.h"
@ -121,7 +120,6 @@ void CFrontEndView::OnUpdateViewTrace(CCmdUI* pCmdUI)
void CFrontEndView::OnViewStatus()
{
CStatusDlg dlg(this);
dlg.m_nUsers = GetServer().Connections();
dlg.DoModal();
}

View File

@ -13,6 +13,7 @@
#define IDC_PHYSICAL_MEM 1005
#define IDC_DISK_SPACE 1006
#define IDC_USERS 1008
#define IDC_GRID 1009
#define stc32 0x045f
#define ID_BUTTON32772 32772
#define ID_VIEW_TRACE 32773
@ -23,9 +24,9 @@
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 133
#define _APS_NEXT_RESOURCE_VALUE 134
#define _APS_NEXT_COMMAND_VALUE 32778
#define _APS_NEXT_CONTROL_VALUE 1009
#define _APS_NEXT_CONTROL_VALUE 1010
#define _APS_NEXT_SYMED_VALUE 105
#endif
#endif

View File

@ -3,6 +3,24 @@
#include "hlapi_c.h"
#define EYECAST (Word DATAFAR_ *)
extern "C"
{
#include "skeytsr.h"
}
static KEY_NET _Eutron;
#pragma pack(1)
struct TEutronHeader
{
char _serno[8];
unsigned short _year_assist;
unsigned short _max_users;
unsigned long _last_date;
unsigned long _scad_date;
unsigned long _checksum; // Must be the last item!
};
#pragma pack()
#include "connect.h"
#include "server.h"
#include "tracing.h"
@ -13,6 +31,8 @@
static char THIS_FILE[] = __FILE__;
#endif
// @doc INTERNAL
// @rdesc Ritorna il valore corrispondente alla chiave appartenente
@ -45,83 +65,58 @@ static CString GetIniString(LPCSTR sec, // @parm Sezione
return tmp;
}
#define HLBLOCK 1
// @doc EXTERNAL
unsigned short THardlockServer::GetSer()
// @func Permette di criptare una parola
//
// @rdesc Ritorna la stringa criptata
const char* Encode(
const char* strin, // @parm Stringa da criptare
char* strout) // @parm Stringa criptata
// @xref <f decode>
{
_SerNo = 0xFFFF;
if (HL_AVAIL() == STATUS_OK)
{
Word Val[4] = { 0, 0, 0, 0 };
HL_READ(0, EYECAST &Val[0]);
HL_READ(1, EYECAST &Val[1]);
HL_READ(2, EYECAST &Val[2]);
HL_READ(3, EYECAST &Val[3]);
HL_CODE(EYECAST Val, HLBLOCK);
if (Val[0] == 0xFAE8)
_SerNo = Val[1];
else
_SerNo = 0;
}
Trace(-1, "Hardlock serial number is %s: %d",
(_SerNo == 0xFFFF) ? "Bad" : "OK", (int)_SerNo);
return _SerNo;
const char * const encryption_key = "QSECOFR-";
for (int i = 0; strin[i]; i++)
strout[i] = strin[i] + (i < 8 ? encryption_key[i] : strin[i-8]);
strout[i] = '\0';
return strout;
}
unsigned short THardlockServer::GetUsers()
BOOL TDongleServer::ReadEutronWords(unsigned short reg,
unsigned short num,
unsigned short* data)
{
_Users = 0;
_AssistanceYear = 0;
if (_SerNo == 0)
{
_Users = 4;
_AssistanceYear = 1998;
}
else
{
if (_SerNo != 0xFFFF)
{
Word Val[4] = { 0, 0, 0, 0 };
HL_READ(60, EYECAST &Val[0]);
HL_READ(61, EYECAST &Val[1]);
HL_READ(62, EYECAST &Val[2]);
HL_READ(63, EYECAST &Val[3]);
HL_CODE(Val, HLBLOCK);
_AssistanceYear = Val[0];
_Users = Val[1];
}
}
Trace(-1, "Assistance Year is %d", (int)_AssistanceYear);
Trace(-1, "Maximum number of users is %d", (int)_Users);
return _Users;
ASSERT(num > 0 && num <= 16);
_Eutron.net_command = NET_KEY_ACCESS;
memcpy(&_Eutron.command, BLOCK_READING_MODE, 2);
unsigned short* pointer = (unsigned short*)(&_Eutron.data[0]);
unsigned short* number = (unsigned short*)(&_Eutron.data[2]);
*pointer = reg;
*number = num;
smartlink(&_Eutron);
BOOL ok = _Eutron.status == ST_OK;
if (ok)
memcpy(data, &_Eutron.data[4], num*2);
return ok;
}
BOOL THardlockServer::GetAut()
BOOL TDongleServer::ReadHardlockWords(unsigned short reg,
unsigned short num,
unsigned short* data)
{
if (_SerNo == 0xFFFF)
return FALSE;
if (_SerNo == 0)
return TRUE;
HL_READ(48, EYECAST &_int_tab[0]);
HL_READ(49, EYECAST &_int_tab[1]);
HL_READ(50, EYECAST &_int_tab[2]);
HL_READ(51, EYECAST &_int_tab[3]);
HL_CODE(_int_tab, HLBLOCK);
for (int i = 0; i < 4; i++)
_int_tab[i] ^= _SerNo;
if (_int_tab[3])
return(FALSE);
return TRUE;
BOOL ok = HL_AVAIL() == STATUS_OK;
if (ok)
{
for (unsigned short n = 0; n < num; n++)
HL_READ(reg+n, EYECAST &data[n]);
}
return ok;
}
BOOL THardlockServer::Login() const
BOOL TDongleServer::HardlockLogin()
{
const char* const REFKEY = "CAMPOKEY";
const char* const VERKEY = "ìpÙˆ¬cê<";
@ -131,18 +126,139 @@ BOOL THardlockServer::Login() const
const int status = HL_LOGIN(26952, LOCAL_DEVICE, ref, ver);
Trace(-1, "Hardlock login %s: %d",
status == STATUS_OK ? "OK" : "Failed", status);
Trace(-1, "Login Hardlock %s: %d",
status == STATUS_OK ? "OK" : "FALLITO", status);
_SerNo = 0xFFFF;
if (status == STATUS_OK)
{
Word Val[4] = { 0, 0, 0, 0 };
ReadHardlockWords(0, 4, Val);
HL_CODE(EYECAST Val, 1);
if (Val[0] == 0xFAE8)
_SerNo = Val[1];
else
_SerNo = 0;
if (_SerNo != 0)
{
ReadHardlockWords(60, 4, Val);
HL_CODE(EYECAST Val, 1);
_AssistanceYear = Val[0];
_Users = Val[1];
int index = 0;
for (unsigned short reg = 48; reg < 60; reg += 4)
{
ReadHardlockWords(reg, 4, Val);
HL_CODE(EYECAST Val, 1);
memcpy(&_int_tab[index], Val, 3);
index += 3;
}
}
}
return status == STATUS_OK;
}
void THardlockServer::Logout() const
BOOL TDongleServer::EutronLogin()
{
HL_LOGOUT();
BOOL ok = FALSE;
memset(&_Eutron, 0, sizeof(_Eutron));
_Eutron.net_command = NET_KEY_OPEN;
const char* labels[2] = { "AGA.CAMPO", "2699DP" };
for (int k = 0; k < 2; k++)
{
memset(_Eutron.label, 0, LABEL_LENGTH);
memcpy(_Eutron.label, labels[k], strlen(labels[k]));
memset(_Eutron.password, 0, PASSWORD_LENGTH);
if (k == 0)
{
char pwd[PASSWORD_LENGTH];
Encode(labels[k], pwd);
memcpy(_Eutron.password, pwd, strlen(pwd));
}
smartlink(&_Eutron);
ok = _Eutron.status == ST_OK;
if (ok)
{
if (k == 1)
_SerNo = 0;
break;
}
}
Trace(-1, "Login Eutron %s: %d",
ok ? "OK" : "FALLITO", _Eutron.status);
if (ok && _SerNo != 0)
{
TEutronHeader eh;
if (ReadEutronWords(0, sizeof(TEutronHeader)/2, (unsigned short*)&eh))
{
char serno[16];
strncpy(serno, eh._serno, 8);
serno[8] = '\0';
_SerNo = (unsigned long)atol(serno);
if (eh._max_users > 0)
{
_Users = eh._max_users;
_AssistanceYear = eh._year_assist;
ReadEutronWords(16, 16, _int_tab);
}
}
}
return _Eutron.status == ST_OK;
}
BOOL THardlockServer::OnConnect(const CString& topic)
BOOL TDongleServer::Login()
{
BOOL ok = HardlockLogin() || EutronLogin();
if (ok)
{
if (_SerNo == 0 || _Users == 0)
{
const CTime tNow = CTime::GetCurrentTime();
_AssistanceYear = tNow.GetYear();
if (_SerNo == 0)
{
_Users = 4;
memset(_int_tab, 0xFF, sizeof(_int_tab));
}
else
{
_Users = 1;
memset(_int_tab, 0x00, sizeof(_int_tab));
}
}
Trace(-1, "Numero di serie %u", _SerNo);
Trace(-1, "Anno assistenza %u", _AssistanceYear);
Trace(-1, "Numero utenti %u", _Users);
}
return ok;
}
void TDongleServer::Logout()
{
if (_Eutron.label[0])
{
_Eutron.net_command = NET_KEY_CLOSE;
smartlink(&_Eutron);
}
else
{
HL_LOGOUT();
}
_SerNo = 0xFFFF;
_Users = 0;
_AssistanceYear = 0;
memset(_int_tab, 0, sizeof(_int_tab));
}
BOOL TDongleServer::OnConnect(const CString& topic)
{
BOOL ok = Connections() <= MaxUsers();
if (!ok)
@ -151,7 +267,7 @@ BOOL THardlockServer::OnConnect(const CString& topic)
}
TConnection* THardlockServer::OnCreateConnection(DWORD id)
TConnection* TDongleServer::OnCreateConnection(DWORD id)
{
TConnection* c = NULL;
if (Connections() <= MaxUsers())
@ -164,36 +280,33 @@ TConnection* THardlockServer::OnCreateConnection(DWORD id)
return c;
}
BOOL THardlockServer::OnRemoveConnection(DWORD id)
BOOL TDongleServer::OnRemoveConnection(DWORD id)
{
Trace(0, "Disconnecting %lu", id);
return BASE_SERVER::OnRemoveConnection(id);
}
THardlockServer::THardlockServer()
: BASE_SERVER("HARDLOCK")
TDongleServer::TDongleServer()
: BASE_SERVER("DONGLE")
{
_SerNo = 0xFFFF;
_int_tab[0] = 0xFFFF;
_int_tab[1] = 0xFFFF;
_int_tab[2] = 0xFFFF;
_int_tab[3] = 0x0000;
_Users = 0;
_AssistanceYear = 0;
memset(_int_tab, 0, sizeof(_int_tab));
Login();
GetSer();
GetUsers();
}
THardlockServer::~THardlockServer()
TDongleServer::~TDongleServer()
{
Logout();
if (_SerNo != 0xFFFF)
Logout();
}
///////////////////////////////////////////////////////////
// Start/Stop server
static THardlockServer* pDDE = NULL;
static TDongleServer* pDDE = NULL;
BOOL StopServer()
{
@ -206,7 +319,7 @@ BOOL StopServer()
return ok;
}
THardlockServer& GetServer()
TDongleServer& GetServer()
{
ASSERT(pDDE);
return *pDDE;
@ -216,7 +329,7 @@ BOOL StartServer()
{
BOOL ok = pDDE == NULL;
if (ok)
pDDE = new THardlockServer;
pDDE = new TDongleServer;
return ok;
}

View File

@ -14,24 +14,27 @@
#endif
/////////////////////////////////////////////////////////////////////////////
// THardlockServer
// TDongleServer
class THardlockServer : public BASE_SERVER
class TDongleServer : public BASE_SERVER
{
enum { MAX_MODULES = 48 };
enum { MAX_MODULES = 256 };
unsigned short _SerNo, _Users, _AssistanceYear, _int_tab[4];
unsigned int _SerNo, _Users, _AssistanceYear;
unsigned short _int_tab[MAX_MODULES/16];
protected:
virtual BOOL OnConnect(const CString& topic);
virtual TConnection* OnCreateConnection(DWORD id);
virtual BOOL OnRemoveConnection(DWORD id);
BOOL Login() const;
void Logout() const;
unsigned short GetSer();
unsigned short GetUsers();
BOOL GetAut();
BOOL HardlockLogin();
BOOL EutronLogin();
BOOL Login();
void Logout();
BOOL ReadHardlockWords(unsigned short reg, unsigned short num, unsigned short* data);
BOOL ReadEutronWords(unsigned short reg, unsigned short num, unsigned short* data);
public:
unsigned short SerialNumber() const
@ -40,18 +43,18 @@ public:
unsigned short AssistanceYear() const
{ return _AssistanceYear; }
const unsigned short* Authorizations()
{ return GetAut() ? _int_tab : NULL; }
const unsigned short* Authorizations(unsigned short& nSize) const
{ nSize = sizeof(_int_tab); return _int_tab; }
unsigned short MaxUsers() const
{ return _Users; }
THardlockServer();
virtual ~THardlockServer();
TDongleServer();
virtual ~TDongleServer();
};
BOOL StartServer();
THardlockServer& GetServer();
TDongleServer& GetServer();
BOOL StopServer();
#endif

View File

@ -2,8 +2,10 @@
//
#include "stdafx.h"
#include "Connect.h"
#include "FrontEnd.h"
#include "StatDlg.h"
#include "Server.h"
#ifdef _DEBUG
#define new DEBUG_NEW
@ -19,7 +21,6 @@ CStatusDlg::CStatusDlg(CWnd* pParent /*=NULL*/)
: CDialog(CStatusDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CStatusDlg)
m_nUsers = 0;
//}}AFX_DATA_INIT
}
@ -28,16 +29,54 @@ void CStatusDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CStatusDlg)
DDX_Text(pDX, IDC_USERS, m_nUsers);
DDX_Control(pDX, IDC_GRID, m_grid);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CStatusDlg, CDialog)
//{{AFX_MSG_MAP(CStatusDlg)
// NOTE: the ClassWizard will add message map macros here
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStatusDlg message handlers
static int AddConnectionToGrid(TConnection& conn, void* pJolly)
{
const TPrassiConnection& user = (const TPrassiConnection&)conn;
CGridCtrl* pGrid = (CGridCtrl*)pJolly;
int nPos = pGrid->GetRow()+1;
pGrid->SetRow(nPos);
pGrid->SetCol(0);
CString str; str.Format("%d", nPos);
pGrid->SetText(str);
pGrid->SetCol(1);
pGrid->SetText(user.User());
return 1;
}
BOOL CStatusDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_grid.SetColWidth(1, 4100);
m_grid.SetRow(0);
m_grid.SetCol(0);
m_grid.SetText("N.");
m_grid.SetCol(1);
m_grid.SetText("Name");
TDongleServer& srv = GetServer();
const int nUsers = srv.Connections();
if (nUsers > 0)
{
m_grid.SetRows(nUsers+1);
srv.ForEachConnection(AddConnectionToGrid, &m_grid);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}

View File

@ -3,6 +3,9 @@
/////////////////////////////////////////////////////////////////////////////
// CStatusDlg dialog
//{{AFX_INCLUDES()
#include "gridctrl.h"
//}}AFX_INCLUDES
class CStatusDlg : public CDialog
{
@ -13,7 +16,7 @@ public:
// Dialog Data
//{{AFX_DATA(CStatusDlg)
enum { IDD = IDD_STATUS };
UINT m_nUsers;
CGridCtrl m_grid;
//}}AFX_DATA
@ -29,7 +32,7 @@ protected:
// Generated message map functions
//{{AFX_MSG(CStatusDlg)
// NOTE: the ClassWizard will add member functions here
virtual BOOL OnInitDialog();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};