• Main Page
  • Classes
  • Files
  • File List

Swiften/Base/WindowsRegistry.h

00001 /*
00002  * Copyright (c) 2012 Kevin Smith
00003  * Licensed under the GNU General Public License v3.
00004  * See Documentation/Licenses/GPLv3.txt for more information.
00005  */
00006 
00007 #pragma once
00008 
00009 #include <windows.h>
00010 
00011 namespace Swift {
00012   class WindowsRegistry {
00013     public:
00014       static bool isFIPSEnabled() {
00015         char* pathForXP = "System\\CurrentControlSet\\Control\\Lsa";
00016         char* pathSinceVista = "System\\CurrentControlSet\\Control\\Lsa\\FIPSAlgorithmPolicy";
00017         char* keyForXP = "FIPSAlgorithmPolicy";
00018         char* keySinceVista = "Enabled";
00019 
00020         OSVERSIONINFO osvi;
00021         ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
00022         osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
00023         GetVersionEx(&osvi);
00024 
00025         char* keyForOS = osvi.dwMajorVersion < 6 ? keyForXP : keySinceVista;
00026         char* pathForOS = osvi.dwMajorVersion < 6 ? pathForXP : pathSinceVista;
00027 
00028         /* http://support.microsoft.com/kb/811833 */
00029         /* http://msdn.microsoft.com/en-us/library/ms724911%28VS.85%29.aspx */
00030         HKEY key;
00031         bool result = false;
00032         if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
00033               pathForOS,
00034               0,
00035               KEY_READ,
00036               &key) != ERROR_SUCCESS) {
00037           /* If we can't find the key that says we're FIPS, we're not FIPS */
00038           return result;
00039         }
00040         DWORD keyType = REG_DWORD;
00041         DWORD data;
00042         DWORD length = sizeof(data);
00043 
00044         if (RegQueryValueEx(key,
00045             keyForOS,
00046             NULL,
00047             &keyType,
00048             (LPBYTE)&data,
00049             &length) == ERROR_SUCCESS) {
00050           result = data != 0;
00051         }
00052 
00053         RegCloseKey(key);
00054         return result;
00055       }
00056   };
00057 }

Generated on Fri Oct 12 2012 21:00:19 for Swiften by  doxygen 1.7.1