Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
2.4 KiB

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