Leaked source code of windows server 2003
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.

571 lines
15 KiB

  1. //Copyright (c) 1998 - 1999 Microsoft Corporation
  2. #ifndef _GLOBAL_H_
  3. #define _GLOBAL_H_
  4. #include "precomp.h"
  5. #if !defined(_WIN32_WINNT)
  6. #define _WIN32_WINNT 0x0400
  7. #endif
  8. #include <wininet.h>
  9. #include "wincrypt.h"
  10. #include "license.h"
  11. #include "tlsapip.h"
  12. #include "lrwizapi.h"
  13. #include "chstruct.h"
  14. #define szOID_GIVEN_NAME_W L"2.5.4.42"
  15. #define szOID_COMMON_NAME_W L"2.5.4.3"
  16. #define szOID_COUNTRY_NAME_W L"2.5.4.6"
  17. #define szOID_LOCALITY_NAME_W L"2.5.4.7"
  18. #define szOID_STATE_OR_PROVINCE_NAME_W L"2.5.4.8"
  19. #define szOID_STREET_ADDRESS_W L"2.5.4.9"
  20. #define szOID_POSTAL_CODE_W L"2.5.4.17"
  21. #define szOID_TELEPHONE_NUMBER_W L"2.5.4.20"
  22. #define szOID_FACSIMILE_TELEPHONE_NUMBER_W L"2.5.4.23"
  23. #define szOID_RSA_emailAddr_W L"1.2.840.113549.1.9.1"
  24. #define szCertEXTENSION_OID "1.3.6.1.4.1.311.18"
  25. #define szCertEXTENSION_VALUE_FMT _TEXT("TLS~%s")
  26. #define CH_ERROR_SUCCESS ERROR_SUCCESS
  27. #define CH_ERROR_BASE 0x3000
  28. #define CH_ERROR_BAD_DATA (CH_ERROR_BASE + 1)
  29. #define CH_ERROR_BAD_PARAM (CH_ERROR_BASE + 2)
  30. #define CH_ERROR_BAD_REQUEST (CH_ERROR_BASE + 3)
  31. #define CH_ERROR_NO_DATA (CH_ERROR_BASE + 4)
  32. #define CH_ERROR_OUT_OF_MEMORY (CH_ERROR_BASE + 5)
  33. #define CH_ERROR_EXCEPTION (CH_ERROR_BASE + 6)
  34. #define CH_ERROR_HTTPQRY_FAILED (CH_ERROR_BASE + 7)
  35. #define CH_ERROR_SERVER_ERROR (CH_ERROR_BASE + 8)
  36. #define CH_ERROR_SEND_FAILED (CH_ERROR_BASE + 9)
  37. #define CH_ERROR_BAD_MFBLOB (CH_ERROR_BASE + 10)
  38. #define NUMBER_OF_BATCHES 7
  39. #define CHARS_IN_BATCH 5
  40. #define REG_ICW_STATUS_PATH L"Software\\Microsoft\\Internet Connection Wizard"
  41. #define REG_ICW_COMPLETED L"Completed"
  42. #define RNC_NETWORKS 0x00000001
  43. #define MAX_URL_LENGTH 255
  44. #define RECTWIDTH( rc ) ((rc).right - (rc).left)
  45. #define RECTHEIGHT( rc ) ((rc).bottom - (rc).top)
  46. #define SIZE_OF_BUFFER( x ) sizeof( x ) / sizeof( TCHAR )
  47. #define PRODUCT_WINDOW_STRING_LENGTH 50
  48. #define PRODUCT_WINDOW_NUM_OFFSET_SPACES 5
  49. enum ProductType
  50. {
  51. UNKNOWN_PRODUCT_TYPE = 0,
  52. WIN2K_PERSEAT = 1,
  53. WIN2K_INTERNET = 2,
  54. WHISTLER_PERUSER = 3,
  55. WHISTLER_PERSEAT = 4,
  56. NUM_PRODUCT_TYPES = 5
  57. };
  58. enum ProductVersionType
  59. {
  60. PRODUCT_VERSION_UNDEFINED = 0,
  61. PRODUCT_VERSION_W2K = 1,
  62. PRODUCT_VERSION_WHISTLER = 2
  63. };
  64. typedef struct
  65. {
  66. TCHAR lpszSPK[ LR_RETAILSPK_LEN+1];
  67. TCHAR tcStatus;
  68. } RETAILSPK, *PRETAILSPK;
  69. typedef struct
  70. {
  71. LPWSTR lpszAttribute;
  72. LPWSTR lpszValue;
  73. DWORD dwValueLen;
  74. }REG_ATTR, * PREG_ATTR;
  75. typedef struct
  76. {
  77. LPCSTR lpszOID;
  78. LPSTR lpszValue;
  79. } REQ_ATTR, * PREQ_ATTR;
  80. typedef struct _Enveloped_Data
  81. {
  82. DWORD cbEncryptedKey;
  83. PBYTE pbEncryptedKey;
  84. DWORD cbEncryptedData;
  85. PBYTE pbEncryptedData;
  86. } EnvData, * PEnvData;
  87. typedef struct _CONTACT_INFO_TAG
  88. {
  89. //program related information
  90. CString sProgramName; //Can be Select, MOLP, Retail ...
  91. CString sCertType;
  92. //Contact information
  93. CString sCompanyName;
  94. CString sOrgUnit;
  95. CString sContactLName;
  96. CString sContactFName;
  97. CString sContactAddress;
  98. CString sContactPhone;
  99. CString sContactFax;
  100. CString sContactEmail;
  101. CString sEmailAddressConf;
  102. CString sCity;
  103. CString sCountryCode;
  104. CString sCountryDesc;
  105. CString sState;
  106. CString sZip;
  107. CString sReasonCode;
  108. CString sCSRFaxRegion;
  109. CString sCSRPhoneRegion;
  110. void Initialize()
  111. {
  112. sProgramName = sContactLName = sContactFName = sContactAddress =
  113. sContactPhone = sCity = sCountryCode = sCountryDesc = sState = sZip =
  114. sContactEmail = sCompanyName = sOrgUnit = sReasonCode = sContactFax =
  115. sEmailAddressConf = sCertType = sCSRFaxRegion = sCSRPhoneRegion =
  116. sCountryCode = sCountryDesc = "";
  117. };
  118. } CONTACTINFO, *PCONTACTINFO;
  119. // Formerly named "LICINFO", but that conflicts with ocidl.h
  120. typedef struct _LIC_INFO_TAG
  121. {
  122. //Select Information
  123. CString sSelMastAgrNumber;
  124. CString sSelEnrollmentNumber;
  125. CString sSelProductType;
  126. CString sSelProductDesc;
  127. CString sSelQty;
  128. //MOLP information
  129. CString sMOLPAuthNumber; //authorization number
  130. CString sMOLPAgreementNumber; //agreement number
  131. CString sMOLPProductType; //product type
  132. CString sMOLPProductDesc;
  133. CString sMOLPQty; //quantity
  134. void Initialize()
  135. {
  136. sSelMastAgrNumber = sSelEnrollmentNumber = sSelProductType = sSelProductDesc =
  137. sSelQty = sMOLPAuthNumber = sMOLPAgreementNumber = sMOLPProductType = sMOLPProductDesc =
  138. sMOLPQty = "";
  139. };
  140. } TSLICINFO, *PTSLICINFO;
  141. typedef struct FAX_DATA_TAG
  142. {
  143. CString sRequestType;
  144. CString sAgreementType;
  145. CString sProductId;
  146. CString sLSId;
  147. CString sFName;
  148. CString sLName;
  149. CString sCompanyName;
  150. CString sOrgUnit;
  151. CString sAddress;
  152. CString sCity;
  153. CString sState;
  154. CString sZip;
  155. CString sCountryCode;
  156. CString sCountryDesc;
  157. CString sPhoneNumber;
  158. CString sFaxNumber;
  159. CString sEmailAddress;
  160. CString sLicenseType;
  161. CString sQuantity;
  162. CString sSelEnrollNumber;
  163. CString sMolpAuthNumber;
  164. CString sMolpLicNumber;
  165. void Initialize()
  166. {
  167. sRequestType = "";
  168. sAgreementType = "";
  169. sProductId = "";
  170. sLSId = "";
  171. sCompanyName = "";
  172. sOrgUnit = "";
  173. sAddress = "";
  174. sCity = "";
  175. sState = "";
  176. sCountryCode = "";
  177. sCountryDesc = "";
  178. sZip = "";
  179. sLName = "";
  180. sFName = "";
  181. sPhoneNumber = "";
  182. sFaxNumber = "";
  183. sEmailAddress = "";
  184. sLicenseType = "";
  185. sQuantity = "";
  186. sSelEnrollNumber= "";
  187. sMolpAuthNumber = "";
  188. sMolpLicNumber = "";
  189. };
  190. }FAX_DATA, * PFAX_DATA;
  191. class CGlobal
  192. {
  193. public:
  194. CGlobal();
  195. ~CGlobal();
  196. void FreeGlobal(void);
  197. //Public Data Members
  198. public:
  199. //Public Member Functions
  200. public:
  201. DWORD PingCH(void);
  202. void SetInstanceHandle(HINSTANCE hInst);
  203. HINSTANCE GetInstanceHandle();
  204. void SetLSName(LPCTSTR lpwszLSName);
  205. DWORD InitGlobal();
  206. DWORD CheckRequieredFields();
  207. DWORD LRGetLastError();
  208. int LRMessageBox(HWND hWndParent,DWORD dwMsgId,DWORD dwCaptionID = 0, DWORD dwErrorCode = 0);
  209. DWORD AuthenticateLS();
  210. DWORD SetCHCert(LPTSTR lpstrRegKey, PBYTE pCert, DWORD dwLen);
  211. DWORD GetCHCert(LPTSTR lpstrRegKey, PBYTE * ppCert, DWORD * pdwLen );
  212. BOOL IsLSRunning();
  213. DWORD GetLSCertificates(PDWORD pdwLSStatus);
  214. DWORD IsLicenseServerRegistered(PDWORD pdwServerStatus);
  215. PCONTACTINFO GetContactDataObject();
  216. PTSLICINFO GetLicDataObject();
  217. DWORD GetRequestType();
  218. void SetRequestType(DWORD dwMode);
  219. DWORD ResetLSSPK(BOOL bGenKey = TRUE);
  220. TCHAR * GetRegistrationID(void);
  221. TCHAR * GetLicenseServerID(void);
  222. BOOL IsOnlineCertRequestCreated();
  223. DWORD SetLRState(DWORD dwState);
  224. DWORD ProcessRequest();
  225. DWORD SetCertificatePIN(LPTSTR lpszPIN);
  226. DWORD PopulateCountryComboBox(HWND hWndCmb);
  227. DWORD GetCountryCode(CString sDesc,LPTSTR szCode);
  228. DWORD GetCountryDesc(CString sCode,LPTSTR szDesc);
  229. DWORD PopulateProductComboBox(HWND hWndCmb, ProductVersionType VerType);
  230. DWORD GetProductCode(CString sDesc,LPTSTR szCode);
  231. DWORD PopulateReasonComboBox(HWND hWndCmb, DWORD dwType);
  232. DWORD GetReasonCode(CString sDesc,LPTSTR szCode, DWORD dwType);
  233. DWORD GetReasonDesc(CString sCode,LPTSTR szDesc, DWORD dwType);
  234. DWORD PopulateCountryRegionComboBox(HWND hWndCmb);
  235. DWORD PopulateCountryRegionListBox(HWND hWndCmb);
  236. void ReadPhoneNumberFromRegistry(LPCTSTR lpCountry, LPTSTR lpPhoneNumber, DWORD nBufferSize);
  237. DWORD CheckRegistryForPhoneNumbers();
  238. void LRSetLastRetCode(DWORD dwCode);
  239. DWORD LRGetLastRetCode();
  240. void SetCSRNumber(TCHAR *);
  241. TCHAR * GetCSRNumber(void);
  242. void SetWWWSite(TCHAR *);
  243. TCHAR * GetWWWSite(void);
  244. void LRPush(DWORD dwPageId);
  245. DWORD LRPop();
  246. void ClearWizStack();
  247. DWORD DepositLSSPK();
  248. DWORD SetLSLKP(TCHAR * tcLKP);
  249. DWORD SetLSSPK(TCHAR * tcLKP);
  250. BOOL ValidateEmailId(CString sEmailId);
  251. BOOL CheckProgramValidity(CString sProgramName);
  252. BOOL ValidateLRString(CString sStr);
  253. LPSTR UnicodeToAnsi( LPWSTR lpwszBuf);
  254. LPSTR UnicodeToAnsi( LPWSTR lpwszBuf, DWORD dwLength );
  255. LPWSTR AnsiToUnicode ( LPSTR lpszBuf );
  256. void SetReFresh(DWORD dw) { m_dwRefresh = dw; }
  257. DWORD GetReFresh(void)
  258. {
  259. return m_dwRefresh;
  260. }
  261. void DeleteRetailSPKFromList(TCHAR * lpszRetailSPK);
  262. DWORD AddRetailSPKToList(HWND hListView, TCHAR * lpszRetailSPK);
  263. void LoadUnfinishedFromList(HWND hListView);
  264. void LoadFinishedFromList(HWND hListView);
  265. void LoadFromList(HWND hListView);
  266. void UpdateSPKStatus(TCHAR * lpszRetailSPK, TCHAR tcStatus);
  267. DWORD SetConfirmationNumber(TCHAR * tcConf);
  268. void SetModifiedRetailSPK(CString sRetailSPK);
  269. void GetModifiedRetailSPK(CString &sRetailSPK);
  270. void ModifyRetailSPKFromList(TCHAR * lpszOldSPK,TCHAR * lpszNewSPK);
  271. DWORD ValidateRetailSPK(TCHAR * lpszRetailSPK);
  272. DWORD GetLSLangId();
  273. void SetLSLangId(DWORD dwLangId);
  274. void SetLSStatus(DWORD dwStatus);
  275. DWORD GetLSStatus(void);
  276. DWORD GetEntryPoint(void);
  277. WIZCONNECTION GetActivationMethod(void);
  278. void SetActivationMethod(WIZCONNECTION conn);
  279. WIZCONNECTION GetLSProp_ActivationMethod(void);
  280. void SetLSProp_ActivationMethod(WIZCONNECTION conn);
  281. WIZACTION GetWizAction(void);
  282. void SetWizAction(WIZACTION act);
  283. WIZTYPE GetWizType() {return m_WizType;}
  284. void SetWizType(WIZTYPE t) {m_WizType = t;}
  285. DWORD SetInRegistry(LPCSTR lpszOID, LPCTSTR lpszValue);
  286. DWORD GetFromRegistry(LPCSTR lpszOID, LPTSTR lpszBuffer, BOOL bConnect = TRUE);
  287. DWORD SetEncodedInRegistry(LPCSTR lpszOID, LPCTSTR lpszValue);
  288. DWORD TransmitLKPData(NewLKP_Request &lkpRequest, NewLKP_Response* lkpResponse);
  289. //Private Member functions
  290. protected:
  291. void LRSetLastError(DWORD dwErrorCode);
  292. DWORD GetTempCryptContext(HCRYPTPROV * phCryptProv);
  293. void DoneWithTempCryptContext(HCRYPTPROV hCryptProv);
  294. DWORD GetCryptContextWithLSKeys(HCRYPTPROV * lphCryptProv );
  295. void DoneWithCryptContextWithLSKeys(HCRYPTPROV hProv);
  296. DWORD LoadCountries();
  297. DWORD LoadReasons();
  298. DWORD LoadProducts();
  299. DWORD ConnectToLSRegistry();
  300. void DisconnectLSRegistry();
  301. DWORD ConnectToLS();
  302. void DisconnectLS();
  303. DWORD ProcessDownloadLKP();
  304. DWORD ProcessIRegRequest();
  305. DWORD ProcessCertDownload();
  306. DWORD ProcessCASignOnlyRequest();
  307. DWORD ProcessCHReissueLKPRequest();
  308. DWORD DepositLSLKP(void);
  309. DWORD ProcessCHRevokeCert(void);
  310. DWORD ProcessCHReissueCert(void);
  311. DWORD CreateLKPRequest(PBYTE * ppbLKPRequest, NewLKP_Request * newlkpp, DWORD &dwBufLen, ProductType productTypeFilter);
  312. DWORD DepositLKPResponse(PBYTE pbResponseData, DWORD dwResponseLen);
  313. DWORD CreateLSPKCS10(HCRYPTPROV hCryptProv,int nType, CHAR **lppszPKCS10);
  314. DWORD AskLSToCreatePKCS10(int nType, CHAR **lppszPKCS10);
  315. DWORD DepositLSCertificates(PBYTE pbExchangePKCS7,
  316. DWORD dwExchangePKCS7Len,
  317. PBYTE pbSignaturePKCS7,
  318. DWORD dwSignaturePKCS7Len,
  319. PBYTE pbRootCert,
  320. DWORD dwRootCertLen);
  321. DWORD SetCARequestAttributes();
  322. DWORD SetCHRequestAttributes();
  323. void ClearCHRequestAttributes();
  324. void ClearCARequestAttributes();
  325. DWORD SetRegistrationAttribute ( LPWSTR lpszAttribute, LPCWSTR lpszValue, DWORD dwLen );
  326. DWORD SetDNAttribute(LPCSTR lpszOID, LPSTR lpszValue);
  327. void PrepareLRString(CString &sStr);
  328. CERT_RDN_ATTR * CreateRDNAttr();
  329. //Crypto Related functions
  330. DWORD EnvelopeData(
  331. PCCERT_CONTEXT pCertContext,
  332. DWORD cbMessage,
  333. PBYTE pbMessage,
  334. PEnvData pEnvelopedData,
  335. HCRYPTPROV hCryptProv,
  336. HCERTSTORE hCertStore
  337. );
  338. DWORD PackEnvData(
  339. PEnvData pEnvelopedData,
  340. PDWORD pcbPacked,
  341. PBYTE *ppbPacked
  342. );
  343. DWORD GetCertforExtension ( HCRYPTPROV hCryptProv,
  344. HCERTSTORE hCertStore,
  345. LPSTR szOID_EXT,
  346. PCCERT_CONTEXT * ppCertContext);
  347. DWORD VerifyCertChain ( HCRYPTPROV hCryptProvider, //handle to crypt prov
  348. HCERTSTORE hCertStore, //HAndle to store for verification
  349. PBYTE pbRootCert, //Root cert
  350. DWORD dwcbRootCert
  351. );
  352. DWORD InitCHRequest(void);
  353. DWORD CloseCHRequest(void);
  354. DWORD Dispatch(BYTE * bpData, DWORD dwLen);
  355. DWORD FetchResponse(BYTE * bpResponse,
  356. DWORD dwMaxLength,
  357. PDWORD dwpDataLength);
  358. DWORD InitSPKList(void);
  359. DWORD InsertIntoSPKDisplayList(HWND hListView,
  360. TCHAR * lpszRetailSPK,
  361. TCHAR tcStatus);
  362. BOOL CheckIfICWCompleted();
  363. ProductType GetProductCodeFromKey(LPCTSTR lpLicenseKey);
  364. DWORD FilteredRetailSPKEntered(ProductType productTypeFilter);
  365. DWORD DownloadLKPBatch(ProductType productTypeFilter);
  366. int FindStringTruncationPoint(TCHAR* sOriginal, unsigned int nTruncationLength);
  367. void AddStringToProductWindow(HWND hListView, TCHAR* sProductInfo, int nCurrentPoint, int nTruncationPoint);
  368. int GetProductWindowMaxStringLength(HWND hListView);
  369. //Private Data members
  370. private:
  371. DWORD m_dwLSStatus;
  372. HWND m_hWndParent;
  373. HINSTANCE m_hInstance;
  374. LPTSTR m_lpstrLSName;
  375. LPWSTR m_lpwstrLSName;
  376. LPTSTR m_lpstrCHServer;
  377. LPTSTR m_lpstrCHExtension;
  378. DWORD m_dwErrorCode;
  379. HKEY m_hLSRegKey;
  380. DWORD m_dwExchangeCertificateLen;
  381. PBYTE m_pbExchangeCertificate;
  382. DWORD m_dwSignCertificateLen;
  383. PBYTE m_pbSignCertificate;
  384. DWORD m_dwExtenstionValueLen;
  385. PBYTE m_pbExtensionValue;
  386. PREQ_ATTR m_pReqAttr; //For the Cert Request
  387. DWORD m_dwReqAttrCount;
  388. PREG_ATTR m_pRegAttr; //For the LKP Request
  389. DWORD m_dwRegAttrCount;
  390. PCONTEXT_HANDLE m_phLSContext;
  391. BOOL m_fSupportConcurrent;
  392. BOOL m_fSupportWhistlerCAL;
  393. CONTACTINFO m_ContactData;
  394. TSLICINFO m_LicData;
  395. DWORD m_dwRequestType;
  396. DWORD m_dwLRState;
  397. DWORD m_dwLRCount; //LKP Request Count
  398. LPTSTR m_lpstrPIN;
  399. TCHAR m_lpCSRNumber[MAX_COUNTRY_NUMBER_LENGTH + 1];
  400. TCHAR m_lpWWWSite[MAX_URL_LENGTH];
  401. CStringArray m_csaCountryCode;
  402. CStringArray m_csaCountryDesc;
  403. CStringArray m_csaProductCode;
  404. CStringArray m_csaProductDesc;
  405. CStringArray m_csaDeactReasonCode;
  406. CStringArray m_csaDeactReasonDesc;
  407. CStringArray m_csaReactReasonCode;
  408. CStringArray m_csaReactReasonDesc;
  409. DWORD m_dwLastRetCode;
  410. DWORD m_dwRefresh;
  411. HINTERNET m_hOpenDirect;
  412. HINTERNET m_hConnect;
  413. HINTERNET m_hRequest;
  414. TCHAR m_pRegistrationID[ LR_REGISTRATIONID_LEN+1];
  415. TCHAR m_pLicenseServerID[ LR_LICENSESERVERID_LEN+1];
  416. TCHAR m_pLSLKP[ LR_REGISTRATIONID_LEN+1];
  417. TCHAR m_pLSSPK[ LR_REGISTRATIONID_LEN+1];
  418. //Stores page traversal order. Implemented as a stack
  419. DWORD m_dwWizStack[NO_OF_PAGES];
  420. DWORD m_dwTop;
  421. DWORD m_dwRetailSPKEntered;
  422. RETAILSPK m_listRetailSPK[ MAX_RETAILSPKS_IN_BATCH];
  423. DWORD m_ProductQuantity[NUM_PRODUCT_TYPES];
  424. CString m_sModifiedRetailsSPK;
  425. DWORD m_dwLangId;
  426. WIZCONNECTION m_ActivationMethod;
  427. WIZCONNECTION m_LSProp_ActivationMethod;
  428. WIZACTION m_WizAction;
  429. WIZTYPE m_WizType;
  430. };
  431. #endif