-
Notifications
You must be signed in to change notification settings - Fork 270
/
Copy pathsecurity.cpp
111 lines (92 loc) · 2.33 KB
/
security.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Platform level security functions.
//
//=============================================================================//
// Uncomment the following line to require the prescence of a hardware key.
//#define REQUIRE_HARDWARE_KEY
#include "pch_tier0.h"
#if defined( _WIN32 ) && !defined( _X360 )
#define WIN_32_LEAN_AND_MEAN
#include <windows.h>
#endif
#include "tier0/platform.h"
#include "tier0/vcrmode.h"
#include "tier0/memalloc.h"
#ifdef REQUIRE_HARDWARE_KEY
// This is the previous key, which was compromised.
//#define VALVE_DESKEY_ID "uW" // Identity Password, Uniquely identifies HL2 keys
#define VALVE_DESKEY_ID "u$" // Identity Password, Uniquely identifies HL2 keys
// Include the key's API:
#include "DESKey/algo.h"
#include "DESKey/dk2win32.h"
#pragma comment(lib, "DESKey/algo32.lib" )
#pragma comment(lib, "DESKey/dk2win32.lib" )
#endif
bool Plat_VerifyHardwareKey()
{
#ifdef REQUIRE_HARDWARE_KEY
// Ensure that a key with our ID exists:
if ( FindDK2( VALVE_DESKEY_ID, NULL ) )
return true;
return false;
#else
return true;
#endif
}
bool Plat_VerifyHardwareKeyDriver()
{
#ifdef REQUIRE_HARDWARE_KEY
// Ensure that the driver is at least installed:
return DK2DriverInstalled() != 0;
#else
return true;
#endif
}
bool Plat_VerifyHardwareKeyPrompt()
{
#ifdef REQUIRE_HARDWARE_KEY
if ( !DK2DriverInstalled() )
{
if( IDCANCEL == MessageBox( NULL, "No drivers detected for the hardware key, please install them and re-run the application.\n", "No Driver Detected", MB_OKCANCEL ) )
{
return false;
}
}
while ( !Plat_VerifyHardwareKey() )
{
if ( IDCANCEL == MessageBox( NULL, "Please insert the hardware key and hit 'ok'.\n", "Insert Hardware Key", MB_OKCANCEL ) )
{
return false;
}
for ( int i=0; i < 2; i++ )
{
// Is the key in now?
if( Plat_VerifyHardwareKey() )
{
return true;
}
// Sleep 2 / 3 of a second before trying again, in case the os recognizes the key slightly after it's being inserted:
Sleep(666);
}
}
return true;
#else
return true;
#endif
}
bool Plat_FastVerifyHardwareKey()
{
#ifdef REQUIRE_HARDWARE_KEY
static int nIterations = 0;
nIterations++;
if( nIterations > 100 )
{
nIterations = 0;
return Plat_VerifyHardwareKey();
}
return true;
#else
return true;
#endif
}