Kms sources from google.init.
This commit is contained in:
1 parent
47778e32f0
commit
4e22666689
58 files changed
+6752
No files matched your search
@@ -0,0 +1,166 @@
|
||||
//---------------------------------------------------------------------------
|
||||
// Header Guard
|
||||
#pragma once
|
||||
|
||||
// Includes and Namespaces
|
||||
#include <windows.h>
|
||||
//---------------------------------------------------------------------------
|
||||
// Defines
|
||||
#define MAX_RESPONSE_SIZE 512
|
||||
#define MAX_REQUEST_SIZE 256 // 260
|
||||
#define PID_BUFFER_SIZE 64
|
||||
#define PORT_BUFFER_SIZE 6
|
||||
#define GUID_BUFFER_SIZE 37
|
||||
#define HASH_SIZE 16
|
||||
#define HASH_SIZE_SHA256 32
|
||||
#define HASH_SIZE_HMAC_SHA256 16
|
||||
//---------------------------------------------------------------------------
|
||||
// Typdefs
|
||||
typedef unsigned long long QWORD;
|
||||
typedef unsigned long long *PQWORD;
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
// Struct Prototypes
|
||||
#pragma warning( disable: 4201 ) // Disable warning C4201: nonstandard extension used : nameless struct/union
|
||||
// Base Properties for KMS Client Request
|
||||
struct REQUEST
|
||||
{
|
||||
union
|
||||
{
|
||||
DWORD Version; // KMS Protocol Version
|
||||
struct
|
||||
{
|
||||
WORD MinorVer; // KMS Protocol Minor Version
|
||||
WORD MajorVer; // KMS Protocol Major Version
|
||||
};
|
||||
};
|
||||
|
||||
DWORD IsClientVM; // Whether or not the KMS Client is a Virtual Machine
|
||||
DWORD LicenseStatus; // Microsoft Licensing Status Code
|
||||
DWORD GraceTime; // The time in Minutes of the KMS Client's Licensing Grace Period
|
||||
GUID ApplicationId; // Microsoft Product Application ID
|
||||
GUID SkuId; // Microsoft Product SKU ID
|
||||
GUID KmsCountedId; // Microsoft Identifier for KMS Client Request Counting and Activation
|
||||
GUID ClientMachineId; // Unique Identifier to Distinguish KMS Clients
|
||||
DWORD RequiredClientCount; // Number of KMS Clients that must have requested KMS Server Activation
|
||||
FILETIME RequestTime; // Time of KMS Client Request
|
||||
GUID PreviousClientMachineId; // Previous Client Machine ID
|
||||
WCHAR MachineName[64]; // KMS Client Network DNS Name
|
||||
};
|
||||
|
||||
// Base Properties for KMS Server Response
|
||||
struct RESPONSE
|
||||
{
|
||||
union
|
||||
{
|
||||
DWORD Version; // KMS Protocol Version
|
||||
struct
|
||||
{
|
||||
WORD MinorVer; // KMS Protocol Minor Version
|
||||
WORD MajorVer; // KMS Protocol Major Version
|
||||
};
|
||||
};
|
||||
|
||||
DWORD KMSPIDLength; // Length of KMS PID
|
||||
WCHAR KMSPID[PID_BUFFER_SIZE]; // Microsoft Product Key ID for KMS Server Activated Product Key
|
||||
GUID ClientMachineId; // Unique Identifier of KMS Client
|
||||
FILETIME RequestTime; // Time of KMS Client Request
|
||||
DWORD KMSCurrentCount; // Number of KMS Clients that currently have requested KMS Server Activation
|
||||
DWORD VLActivationInterval; // The time in Minutes that Unactivated KMS Clients will wait before requesting Activation
|
||||
DWORD VLRenewalInterval; // The time in Minutes that Activated KMS Clients will wait before requesting Reactivation
|
||||
};
|
||||
|
||||
// KMS Client Request V4 Object
|
||||
struct REQUEST_V4
|
||||
{
|
||||
REQUEST RequestBase; // Unhashed KMS Client Request Data
|
||||
BYTE Hash[HASH_SIZE]; // MAC Hash of KMS Client Request Data
|
||||
};
|
||||
|
||||
// KMS Server Response V4 Object
|
||||
struct RESPONSE_V4
|
||||
{
|
||||
RESPONSE ResponseBase; // Unhashed KMS Server Response Data
|
||||
BYTE Hash[HASH_SIZE]; // MAC Hash of KMS Server Response Data
|
||||
};
|
||||
|
||||
// KMS Client Request V5 Object
|
||||
struct REQUEST_V5
|
||||
{
|
||||
union
|
||||
{
|
||||
DWORD Version; // KMS Protocol Version
|
||||
struct
|
||||
{
|
||||
WORD MinorVer; // KMS Protocol Minor Version
|
||||
WORD MajorVer; // KMS Protocol Major Version
|
||||
};
|
||||
};
|
||||
|
||||
BYTE Salt[16]; // KMS Client AES Initialization Vector (Salt)
|
||||
REQUEST RequestBase; // Unhashed KMS Client Request Data
|
||||
BYTE Pad[4]; // Padding - Fill Message, so that encryptSize is divisible by blocklength
|
||||
};
|
||||
|
||||
// KMS Server Response V5 Object
|
||||
struct RESPONSE_V5
|
||||
{
|
||||
union
|
||||
{
|
||||
DWORD Version; // KMS Protocol Version
|
||||
struct
|
||||
{
|
||||
WORD MinorVer; // KMS Protocol Minor Version
|
||||
WORD MajorVer; // KMS Protocol Major Version
|
||||
};
|
||||
};
|
||||
|
||||
BYTE RequestSalt[16]; // KMS Client AES Initialization Vector (Salt)
|
||||
RESPONSE ResponseBase; // Unhashed KMS Server Response Data
|
||||
BYTE Salt[16]; // KMS Server AES Initialization Vector (Salt) : Not Used. Possible MS Bug: The Request IV is used instead.
|
||||
BYTE Hash[HASH_SIZE_SHA256]; // Hash of KMS Server Response Data
|
||||
BYTE Pad[2]; // PKCS5 Padding
|
||||
};
|
||||
|
||||
// KMS Client Request V6 Object
|
||||
struct REQUEST_V6
|
||||
{
|
||||
union
|
||||
{
|
||||
DWORD Version; // KMS Protocol Version
|
||||
struct
|
||||
{
|
||||
WORD MinorVer; // KMS Protocol Minor Version
|
||||
WORD MajorVer; // KMS Protocol Major Version
|
||||
};
|
||||
};
|
||||
|
||||
BYTE Salt[16]; // KMS Client AES Initialization Vector (Salt)
|
||||
REQUEST RequestBase; // Unhashed KMS Client Request Data
|
||||
BYTE Pad[4]; // Padding - Fill Message, so that encryptSize is divisible by blocklength
|
||||
};
|
||||
|
||||
// KMS Server Response V6 Object
|
||||
struct RESPONSE_V6
|
||||
{
|
||||
union
|
||||
{
|
||||
DWORD Version; // KMS Protocol Version
|
||||
struct
|
||||
{
|
||||
WORD MinorVer; // KMS Protocol Minor Version
|
||||
WORD MajorVer; // KMS Protocol Major Version
|
||||
};
|
||||
};
|
||||
|
||||
BYTE RequestSalt[16]; // KMS Client AES Initialization Vector (Salt)
|
||||
RESPONSE ResponseBase; // Unhashed KMS Server Response Data
|
||||
BYTE Salt[16]; // KMS Server AES Initialization Vector (Salt) : Not Used. Possible MS Bug: The Request IV is used instead.
|
||||
BYTE Hash[HASH_SIZE_SHA256]; // Hash of KMS Server Response Data
|
||||
BYTE MachineHardwareHash[8]; // Most likely the machine hardware hash of the server
|
||||
BYTE Xor2[16]; // Xor2 ???
|
||||
BYTE HMAC_SHA256[HASH_SIZE_HMAC_SHA256]; // HMAC-SHA256 (RFC 2104)
|
||||
BYTE Pad[10]; // PKCS5 Padding
|
||||
};
|
||||
#pragma warning( default: 4201 ) // Enable warning C4201: nonstandard extension used : nameless struct/union
|
||||
//---------------------------------------------------------------------------
|
||||
@@ -0,0 +1,30 @@
|
||||
//---------------------------------------------------------------------------
|
||||
// Header Guard
|
||||
#pragma once
|
||||
|
||||
// Includes and Namespaces
|
||||
#include <windows.h>
|
||||
|
||||
// Constants
|
||||
#define AES_TYPE_128 0
|
||||
#define AES_TYPE_192 1
|
||||
#define AES_TYPE_256 2
|
||||
|
||||
#define AES_MODE_ECB 0
|
||||
#define AES_MODE_CBC 1
|
||||
#define AES_MODE_CFB 2
|
||||
#define AES_MODE_OFB 3
|
||||
#define AES_MODE_CTR 4
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Function Prototypes
|
||||
void AESDecryptMessage(PBYTE const IV, PBYTE const Message, PDWORD const MessageSize);
|
||||
void AESEncryptMessage(PBYTE const IV, PBYTE const Message, PDWORD const MessageSize, DWORD BufferLen);
|
||||
|
||||
BYTE MULx2(BYTE bIn);
|
||||
BYTE MULx3(BYTE bIn);
|
||||
DWORD AesInit(DWORD dwType, DWORD dwMode, BYTE bPadding, PBYTE pbKey, PBYTE pbIV);
|
||||
DWORD AesClear(void);
|
||||
void DecryptMessage(int MessageSize, PBYTE Message);
|
||||
void EncryptMessage(int MessageSize, PBYTE Message);
|
||||
//---------------------------------------------------------------------------
|
||||
@@ -0,0 +1,21 @@
|
||||
//---------------------------------------------------------------------------
|
||||
// Header Guard
|
||||
#pragma once
|
||||
|
||||
// Includes and Namespaces
|
||||
#include <windows.h>
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
// HMAC-SHA256 key blob structure
|
||||
struct HMAC_KEYBLOB {
|
||||
BLOBHEADER hdr;
|
||||
DWORD dwKeySize;
|
||||
BYTE rgbKeyData[16];
|
||||
};
|
||||
|
||||
// Function Prototypes
|
||||
void GetHash(DWORD MessageSize, PBYTE const Message, PBYTE const hash);
|
||||
void GetHashSHA256(DWORD dataSize, PBYTE const data, PBYTE const Hash);
|
||||
void GetHmacKey(FILETIME* timestamp, PBYTE hmackey);
|
||||
void GetHmacSHA256(DWORD dwDataLen, PBYTE const pbData, PBYTE const pbHash);
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -0,0 +1,6 @@
|
||||
//---------------------------------------------------------------------------
|
||||
// Header Guard
|
||||
#pragma once
|
||||
|
||||
// Includes and Namespaces
|
||||
#include "KMSClientLogic.h"
|
||||
@@ -0,0 +1,29 @@
|
||||
//---------------------------------------------------------------------------
|
||||
// Header Guard
|
||||
#pragma once
|
||||
|
||||
// Includes and Namespaces
|
||||
#include <windows.h>
|
||||
#include <Strsafe.h>
|
||||
#include "CoreKMS.h"
|
||||
//---------------------------------------------------------------------------
|
||||
// Function Prototypes
|
||||
void LoadClientParameters(int argc, wchar_t *argv[], bool RunAsService);
|
||||
void StartKMSClient();
|
||||
PBYTE CreateRequest();
|
||||
void CreateRequestBase(REQUEST* const Request);
|
||||
PBYTE CreateRequestV4();
|
||||
PBYTE CreateRequestV5();
|
||||
PBYTE CreateRequestV6();
|
||||
void ReadResponseV4(RESPONSE_V4& Response_v4, int responseSize, PBYTE response);
|
||||
void ReadResponseV5(RESPONSE_V5& Response_v5, int responseSize, PBYTE response);
|
||||
void ReadResponseV6(RESPONSE_V6& Response_v5, int responseSize, PBYTE response);
|
||||
int SendRequest(PBYTE request, const int requestsSent, int* const requestsNeeded);
|
||||
void ClientValidateKMSPort(WCHAR* KMSPort);
|
||||
void ClientValidateKMSHost(WCHAR* KMSHost);
|
||||
void ClientValidateKMSClientMode(WCHAR* KMSClientMode);
|
||||
void ClientWriteLogInformation(WCHAR* const Message);
|
||||
void ClientWriteLogError(WCHAR* const Message);
|
||||
void ClientWriteLogErrorTerminate(WCHAR* const Message, int ExitCode);
|
||||
void ClientWriteEventLogEntry(DWORD dwIdentifier, WCHAR* const lpszMessage, WORD wType);
|
||||
//---------------------------------------------------------------------------
|
||||
@@ -0,0 +1,36 @@
|
||||
//---------------------------------------------------------------------------
|
||||
// Header Guard
|
||||
#pragma once
|
||||
|
||||
// Includes and Namespaces
|
||||
#include <windows.h>
|
||||
#include <Strsafe.h>
|
||||
#include "CoreKMS.h"
|
||||
//---------------------------------------------------------------------------
|
||||
// Class Prototypes
|
||||
|
||||
// Contain all KMS Client Parameters and Settings.
|
||||
class KMSClientSettings
|
||||
{
|
||||
public:
|
||||
// KMS Client Parameters
|
||||
static WCHAR KMSHost[256];
|
||||
static WCHAR KMSPort[PORT_BUFFER_SIZE];
|
||||
static WCHAR KMSClientMode[256];
|
||||
|
||||
// KMS Client Identification Data
|
||||
static DWORD RequiredClientCount;
|
||||
static WORD KMSProtocolMajorVersion;
|
||||
static WORD KMSProtocolMinorVersion;
|
||||
static DWORD KMSClientLicenseStatus;
|
||||
static WCHAR KMSClientAppID[GUID_BUFFER_SIZE];
|
||||
static WCHAR KMSClientSkuID[GUID_BUFFER_SIZE];
|
||||
static WCHAR KMSClientKMSCountedID[GUID_BUFFER_SIZE];
|
||||
|
||||
// KMS Client Program Control
|
||||
static bool RunAsService;
|
||||
|
||||
// Set Default Settings
|
||||
static void Initialize();
|
||||
};
|
||||
//---------------------------------------------------------------------------
|
||||
@@ -0,0 +1,14 @@
|
||||
//---------------------------------------------------------------------------
|
||||
// Header Guard
|
||||
#pragma once
|
||||
|
||||
// Includes and Namespaces
|
||||
#include <windows.h>
|
||||
#include <regex>
|
||||
#include <Strsafe.h>
|
||||
#include <string>
|
||||
#include "CoreKMS.h"
|
||||
|
||||
// Function Prototypes
|
||||
void GetKMSHWID(PQWORD KMSHWID, REQUEST* const Request);
|
||||
//---------------------------------------------------------------------------
|
||||
@@ -0,0 +1,15 @@
|
||||
//---------------------------------------------------------------------------
|
||||
// Header Guard
|
||||
#pragma once
|
||||
|
||||
// Includes and Namespaces
|
||||
#include <windows.h>
|
||||
#include <regex>
|
||||
#include <Strsafe.h>
|
||||
#include <string>
|
||||
#include "CoreKMS.h"
|
||||
|
||||
// Function Prototypes
|
||||
void CreateKMSPID(WCHAR* const KMSPID, REQUEST* const Request);
|
||||
void GetKMSPID(WCHAR* const KMSPID, REQUEST* const Request);
|
||||
//---------------------------------------------------------------------------
|
||||
@@ -0,0 +1,85 @@
|
||||
|
||||
|
||||
/* this ALWAYS GENERATED file contains the definitions for the interfaces */
|
||||
|
||||
|
||||
/* File created by MIDL compiler version 8.00.0595 */
|
||||
/* at Thu Oct 18 15:24:14 2012
|
||||
*/
|
||||
/* Compiler settings for KMSServer.idl:
|
||||
Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 8.00.0595
|
||||
protocol : dce , ms_ext, c_ext, robust
|
||||
error checks: allocation ref bounds_check enum stub_data
|
||||
VC __declspec() decoration level:
|
||||
__declspec(uuid()), __declspec(selectany), __declspec(novtable)
|
||||
DECLSPEC_UUID(), MIDL_INTERFACE()
|
||||
*/
|
||||
/* @@MIDL_FILE_HEADING( ) */
|
||||
|
||||
#pragma warning( disable: 4049 ) /* more than 64k source lines */
|
||||
|
||||
|
||||
/* verify that the <rpcndr.h> version is high enough to compile this file*/
|
||||
#ifndef __REQUIRED_RPCNDR_H_VERSION__
|
||||
#define __REQUIRED_RPCNDR_H_VERSION__ 475
|
||||
#endif
|
||||
|
||||
#include "rpc.h"
|
||||
#include "rpcndr.h"
|
||||
|
||||
#ifndef __RPCNDR_H_VERSION__
|
||||
#error this stub requires an updated version of <rpcndr.h>
|
||||
#endif // __RPCNDR_H_VERSION__
|
||||
|
||||
|
||||
#ifndef __KMSServer_h_h__
|
||||
#define __KMSServer_h_h__
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
/* Forward Declarations */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef __KMSServer_INTERFACE_DEFINED__
|
||||
#define __KMSServer_INTERFACE_DEFINED__
|
||||
|
||||
/* interface KMSServer */
|
||||
/* [version][uuid] */
|
||||
|
||||
int ActivationRequest(
|
||||
/* [in] */ handle_t IDL_handle,
|
||||
/* [in] */ int requestSize,
|
||||
/* [size_is][in] */ unsigned char *request,
|
||||
/* [out] */ int *responseSize,
|
||||
/* [size_is][size_is][out] */ unsigned char **response);
|
||||
|
||||
int ActivationResponse(
|
||||
/* [in] */ handle_t IDL_handle,
|
||||
/* [in] */ int requestSize,
|
||||
/* [size_is][in] */ unsigned char *request,
|
||||
/* [out] */ int *responseSize,
|
||||
/* [size_is][size_is][out] */ unsigned char **response);
|
||||
|
||||
|
||||
|
||||
extern RPC_IF_HANDLE KMSServer_v1_0_c_ifspec;
|
||||
extern RPC_IF_HANDLE KMSServer_v1_0_s_ifspec;
|
||||
#endif /* __KMSServer_INTERFACE_DEFINED__ */
|
||||
|
||||
/* Additional Prototypes for ALL interfaces */
|
||||
|
||||
/* end of Additional Prototypes */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
//---------------------------------------------------------------------------
|
||||
// Header Guard
|
||||
#pragma once
|
||||
|
||||
// Includes and Namespaces
|
||||
#include "KMSServerLogic.h"
|
||||
@@ -0,0 +1,29 @@
|
||||
//---------------------------------------------------------------------------
|
||||
// Header Guard
|
||||
#pragma once
|
||||
|
||||
// Includes and Namespaces
|
||||
#include <windows.h>
|
||||
#include <Strsafe.h>
|
||||
#include "CoreKMS.h"
|
||||
//---------------------------------------------------------------------------
|
||||
// Function Prototypes
|
||||
void LoadServerParameters(int argc, wchar_t* argv[], bool RunAsService);
|
||||
void StartKMSServer();
|
||||
void StopKMSServer();
|
||||
DWORD CreateResponseBase(REQUEST* const Request, PBYTE const Response);
|
||||
PBYTE CreateResponseV4(REQUEST_V4* const Request, int* const responseSize);
|
||||
PBYTE CreateResponseV5(REQUEST_V5* const Request, int* const responseSize);
|
||||
PBYTE CreateResponseV6(REQUEST_V6* const Request, int* const responseSize);
|
||||
void ServerValidateKMSPort(WCHAR* KMSPort);
|
||||
void ServerValidateKMSPID(WCHAR* KMSPID);
|
||||
void ServerValidateKMSHWID(WCHAR* KMSHWID);
|
||||
void ServerValidateVLActivationInterval(int VLActivationInterval);
|
||||
void ServerValidateVLRenewalInterval(int VLRenewalInterval);
|
||||
void ServerWriteLogInformation(WCHAR* const Message);
|
||||
void ServerWriteLogError(WCHAR* const Message);
|
||||
void ServerWriteLogErrorTerminate(WCHAR* const Message, int ExitCode);
|
||||
void ServerWriteEventLogEntry(DWORD dwIdentifier, WCHAR* const lpszMessage, WORD wType);
|
||||
void GetHmacKey(FILETIME* timestamp, PBYTE hmackey);
|
||||
void GetHmacSHA256(DWORD dwDataLen, PBYTE const pbData, PBYTE const pbHash);
|
||||
//---------------------------------------------------------------------------
|
||||
@@ -0,0 +1,34 @@
|
||||
//---------------------------------------------------------------------------
|
||||
// Header Guard
|
||||
#pragma once
|
||||
|
||||
// Includes and Namespaces
|
||||
#include <windows.h>
|
||||
#include <Strsafe.h>
|
||||
#include "CoreKMS.h"
|
||||
//---------------------------------------------------------------------------
|
||||
// Class Prototypes
|
||||
|
||||
// Contains all KMS Server Parameters and Settings.
|
||||
class KMSServerSettings
|
||||
{
|
||||
public:
|
||||
// KMS Server Parameters
|
||||
static WCHAR KMSPID[PID_BUFFER_SIZE];
|
||||
static QWORD KMSHWID;
|
||||
static WCHAR KMSPort[PORT_BUFFER_SIZE];
|
||||
static DWORD CurrentClientCount;
|
||||
static DWORD VLActivationInterval;
|
||||
static DWORD VLRenewalInterval;
|
||||
|
||||
// KMS Server Program Control
|
||||
static bool GenerateRandomKMSPID;
|
||||
static bool RunAsService;
|
||||
|
||||
// Process Termination Control Variables
|
||||
static bool KillProcesses;
|
||||
|
||||
// Set Default Settings
|
||||
static void Initialize();
|
||||
};
|
||||
//---------------------------------------------------------------------------
|
||||
Reference in new issue
Block a user