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.

393 lines
14 KiB

  1. //+--------------------------------------------------------------------------
  2. // FILE : autoenro.h
  3. // DESCRIPTION : Private Auto Enrollment functions
  4. //
  5. //
  6. // Copyright (C) 1993-2000 Microsoft Corporation All Rights Reserved
  7. //+--------------------------------------------------------------------------
  8. #ifndef __AUTOENRO_H__
  9. #define __AUTOENRO_H__
  10. #if _MSC_VER > 1000
  11. #pragma once
  12. #endif
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. //--------------------------------------------------------------------------
  17. // Globals
  18. //--------------------------------------------------------------------------
  19. extern HINSTANCE g_hmodThisDll;
  20. //--------------------------------------------------------------------------
  21. // contant defines
  22. //--------------------------------------------------------------------------
  23. #define AE_PENDING_REQUEST_ACTIVE_PERIOD 60 //60 days
  24. #define AE_RETRY_LIMIT 3 //retry 3 times for machine DNS error
  25. #define SHA1_HASH_LENGTH 20
  26. #define ENCODING_TYPE X509_ASN_ENCODING | PKCS_7_ASN_ENCODING
  27. #define MY_STORE L"MY"
  28. #define REQUEST_STORE L"REQUEST"
  29. #define ACRS_STORE L"ACRS"
  30. //possible status for the request tree
  31. #define CERT_REQUEST_STATUS_ACTIVE 0x01
  32. #define CERT_REQUEST_STATUS_OBTAINED 0x02
  33. #define CERT_REQUEST_STATUS_PENDING 0x03
  34. #define CERT_REQUEST_STATUS_SUPERSEDE_ACTIVE 0x04
  35. // Time skew margin for fast CA's
  36. #define FILETIME_TICKS_PER_SECOND 10000000
  37. #define AE_DEFAULT_SKEW 60*60*1 // 1 hour
  38. #define MAX_DN_SIZE 256
  39. #define AE_SUMMARY_COLUMN_SIZE 100
  40. #define PENDING_ALLOC_SIZE 20
  41. #define USER_AUTOENROLL_DELAY_FOR_MACHINE 70 //70 seconds to wait
  42. //defines for autoenrollment event log
  43. #define EVENT_AUTO_NAME L"AutoEnrollment"
  44. #define AUTO_ENROLLMENT_EVENT_LEVEL_KEY TEXT("SOFTWARE\\Microsoft\\Cryptography\\AutoEnrollment")
  45. #define AUTO_ENROLLMENT_EVENT_LEVEL TEXT("AEEventLogLevel")
  46. //defines for autoenrollment disable key
  47. #define AUTO_ENROLLMENT_DISABLE_KEY L"SOFTWARE\\Microsoft\\Cryptography\\AutoEnrollment\\AEDisable"
  48. //defines for autoenrollment user no wait for 60 seconds key
  49. #define AUTO_ENROLLMENT_EXPRESS_KEY L"SOFTWARE\\Microsoft\\Cryptography\\AutoEnrollment\\AEExpress"
  50. //defines for autoenrollment directory cache information
  51. #define AUTO_ENROLLMENT_DS_KEY L"SOFTWARE\\Microsoft\\Cryptography\\AutoEnrollment\\AEDirectoryCache"
  52. #define AUTO_ENROLLMENT_DS_USN L"AEMaxUSN"
  53. #define AUTO_ENROLLMENT_DS_OBJECT L"AEObjectCount"
  54. #define AUTO_ENROLLMENT_TEMPLATE_KEY L"SOFTWARE\\Microsoft\\Cryptography\\CertificateTemplateCache"
  55. #define AUTO_ENROLLMENT_USN_ATTR L"uSNChanged"
  56. //defines for the UI component
  57. #define AUTO_ENROLLMENT_SHOW_TIME 15 //show the balloon for 15 seconds
  58. #define AUTO_ENROLLMENT_INTERVAL 7 * 60 * 30 //show the icon for 7 hours 7* 3600
  59. #define AUTO_ENROLLMENT_RETRIAL 2
  60. #define AUTO_ENROLLMENT_QUERY_INTERVAL 30 //query continue every 30 seconds
  61. #define AUTO_ENROLLMENT_BALLOON_LENGTH 7 * 60 * 60 //keep the balloon for 7 hours
  62. #define AE_DEFAULT_POSTPONE 1 //we relaunch autoenrollment for 1 hour
  63. //define used for sorting of columns in the list view
  64. #define AE_SUMMARY_COLUMN_TYPE 1
  65. #define AE_SUMMARY_COLUMN_REASON 2
  66. #define SORT_COLUMN_ASCEND 0x00010000
  67. #define SORT_COLUMN_DESCEND 0x00020000
  68. //--------------------------------------------------------------------------
  69. // struct defines
  70. //--------------------------------------------------------------------------
  71. //struct for retry property on the certificate due to DNS error
  72. typedef struct _AE_RETRY_INFO_
  73. {
  74. DWORD cbSize;
  75. DWORD dwRetry;
  76. ULARGE_INTEGER dueTime;
  77. } AE_RETRY_INFO;
  78. //struct for autoenrollment main thread
  79. typedef struct _AE_MAIN_THREAD_INFO_
  80. {
  81. HWND hwndParent;
  82. DWORD dwStatus;
  83. } AE_MAIN_THREAD_INFO;
  84. //struct for updating certificate store from AD
  85. typedef struct _AE_STORE_INFO_
  86. {
  87. LPWSTR pwszStoreName;
  88. LPWSTR pwszLdapPath;
  89. } AE_STORE_INFO;
  90. //struct for the information we compute from DS
  91. typedef struct _AE_DS_INFO_
  92. {
  93. BOOL fValidData;
  94. DWORD dwObjects;
  95. ULARGE_INTEGER maxUSN;
  96. } AE_DS_INFO;
  97. //struct for param of view RA certificate dialogue
  98. typedef struct _AE_VIEW_RA_INFO_
  99. {
  100. PCERT_CONTEXT pRAContext;
  101. LPWSTR pwszRATemplate;
  102. } AE_VIEW_RA_INFO;
  103. //struct for individual certifcate information
  104. typedef struct _AE_CERT_INFO_
  105. {
  106. BOOL fValid;
  107. BOOL fRenewal;
  108. } AE_CERT_INFO;
  109. //strcut for certificate's template information
  110. typedef struct _AE_TEMPLATE_INFO_
  111. {
  112. LPWSTR pwszName;
  113. LPWSTR pwszOid;
  114. DWORD dwVersion;
  115. } AE_TEMPLATE_INFO;
  116. //struct for certificate authority information
  117. typedef struct _AE_CA_INFO_
  118. {
  119. HCAINFO hCAInfo;
  120. LPWSTR *awszCertificateTemplate;
  121. LPWSTR *awszCAName;
  122. LPWSTR *awszCADNS;
  123. LPWSTR *awszCADisplay;
  124. } AE_CA_INFO;
  125. //struct for keeping the issued pending certificates
  126. typedef struct _AE_PEND_INFO_
  127. {
  128. CRYPT_DATA_BLOB blobPKCS7; //the issued pending certificate for UI installation
  129. CRYPT_DATA_BLOB blobHash; //the hash of the certificate request to be removed from the request store
  130. }AE_PEND_INFO;
  131. //struct for certificate template information
  132. typedef struct _AE_CERTTYPE_INFO_
  133. {
  134. HCERTTYPE hCertType;
  135. DWORD dwSchemaVersion;
  136. DWORD dwVersion;
  137. LPWSTR *awszName;
  138. LPWSTR *awszDisplay;
  139. LPWSTR *awszOID;
  140. LPWSTR *awszSupersede;
  141. DWORD dwEnrollmentFlag;
  142. DWORD dwPrivateKeyFlag;
  143. LARGE_INTEGER ftExpirationOffset;
  144. DWORD dwStatus;
  145. BOOL fCheckMyStore;
  146. BOOL fRenewal;
  147. BOOL fNeedRA; //the request needs to be signed by itself or another certificate
  148. BOOL fCrossRA; //the request is cross RAed.
  149. BOOL fSupersedeVisited; //the flag to prevent infinite loop in superseding relationship
  150. BOOL fUIActive;
  151. DWORD dwActive;
  152. DWORD *prgActive;
  153. DWORD dwRandomCAIndex;
  154. PCERT_CONTEXT pOldCert; //for renewal case managing MY store
  155. HCERTSTORE hArchiveStore; //contains the certificates to be archived
  156. HCERTSTORE hObtainedStore; //for supersede relation ships
  157. HCERTSTORE hIssuedStore; //keep issued certificates for re-publishing
  158. DWORD dwPendCount; //the count of pending issued certs
  159. AE_PEND_INFO *rgPendInfo; //the point to the struct array
  160. DWORD idsSummary; //the summary string ID
  161. } AE_CERTTYPE_INFO;
  162. //struct for the autoenrollment process
  163. typedef struct _AE_GENERAL_INFO_
  164. {
  165. HWND hwndParent;
  166. LDAP * pld;
  167. HANDLE hToken;
  168. BOOL fMachine;
  169. DWORD dwPolicy;
  170. DWORD dwLogLevel;
  171. WCHAR wszMachineName[MAX_COMPUTERNAME_LENGTH + 2];
  172. HCERTSTORE hMyStore;
  173. HCERTSTORE hRequestStore;
  174. DWORD dwCertType;
  175. AE_CERTTYPE_INFO *rgCertTypeInfo;
  176. DWORD dwCA;
  177. AE_CA_INFO *rgCAInfo;
  178. HMODULE hXenroll;
  179. BOOL fUIProcess; //whether we are doing interactive enrollment
  180. HANDLE hCancelEvent;
  181. HANDLE hCompleteEvent;
  182. HANDLE hThread;
  183. HWND hwndDlg; //the dialogue window handle of the UI window
  184. DWORD dwUIPendCount; //the count of UI required pending requests
  185. DWORD dwUIEnrollCount; //the count of UI requires new requests
  186. DWORD dwUIProgressCount; //the count of active working items
  187. BOOL fSmartcardSystem; //whether a smart card reader is installed
  188. LPWSTR pwszDns; //the DNS name of the local computer
  189. LPWSTR pwszNetBIOS; //the NetBios name of the local computer
  190. } AE_GENERAL_INFO;
  191. //--------------------------------------------------------------------------
  192. // Class definition
  193. //--------------------------------------------------------------------------
  194. class CQueryContinue : IQueryContinue
  195. {
  196. public:
  197. CQueryContinue();
  198. ~CQueryContinue();
  199. // IUnknown
  200. STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
  201. STDMETHODIMP_(ULONG) AddRef();
  202. STDMETHODIMP_(ULONG) Release();
  203. // IQueryContinue
  204. STDMETHODIMP QueryContinue(); // S_OK -> Continue, other
  205. // DoBalloon
  206. HRESULT DoBalloon();
  207. private:
  208. LONG m_cRef;
  209. IUserNotification *m_pIUserNotification;
  210. HANDLE m_hTimer;
  211. };
  212. //--------------------------------------------------------------------------
  213. // function prototype
  214. //--------------------------------------------------------------------------
  215. HRESULT
  216. AEGetConfigDN(
  217. IN LDAP *pld,
  218. OUT LPWSTR *pwszConfigDn
  219. );
  220. HRESULT
  221. AERobustLdapBind(
  222. OUT LDAP ** ppldap);
  223. BOOL AERetrieveGeneralInfo(AE_GENERAL_INFO *pAE_General_Info);
  224. BOOL AEFreeGeneralInfo(AE_GENERAL_INFO *pAE_General_Info);
  225. BOOL AERetrieveCAInfo(LDAP *pld, BOOL fMachine, HANDLE hToken, DWORD *pdwCA, AE_CA_INFO **prgCAInfo);
  226. BOOL AEFreeCAInfo(DWORD dwCA, AE_CA_INFO *rgCAInfo);
  227. BOOL AEFreeCAStruct(AE_CA_INFO *pCAInfo);
  228. BOOL AERetrieveCertTypeInfo(LDAP *pld, BOOL fMachine, DWORD *pdwCertType, AE_CERTTYPE_INFO **prgCertType);
  229. BOOL AEFreeCertTypeInfo(DWORD dwCertType, AE_CERTTYPE_INFO *rgCertTypeInfo);
  230. BOOL AEFreeCertTypeStruct(AE_CERTTYPE_INFO *pCertTypeInfo);
  231. BOOL AEAllocAndCopy(LPWSTR pwszSrc, LPWSTR *ppwszDest);
  232. BOOL AEIfSupersede(LPWSTR pwsz, LPWSTR *awsz, AE_GENERAL_INFO *pAE_General_Info);
  233. BOOL AEClearVistedFlag(AE_GENERAL_INFO *pAE_General_Info);
  234. BOOL AECopyCertStore(HCERTSTORE hSrcStore, HCERTSTORE hDesStore);
  235. BOOL AEIsAnElement(LPWSTR pwsz, LPWSTR *awsz);
  236. BOOL AECancelled(HANDLE hCancelEvent);
  237. BOOL AERetrieveTemplateInfo(PCCERT_CONTEXT pCertCurrent,
  238. AE_TEMPLATE_INFO *pTemplateInfo);
  239. BOOL AEFreeTemplateInfo(AE_TEMPLATE_INFO *pAETemplateInfo);
  240. AE_CERTTYPE_INFO *AEFindTemplateInRequestTree(AE_TEMPLATE_INFO *pTemplateInfo,
  241. AE_GENERAL_INFO *pAE_General_Info);
  242. BOOL AEUIProgressAdvance(AE_GENERAL_INFO *pAE_General_Info);
  243. BOOL AEUIProgressReport(BOOL fPending, AE_CERTTYPE_INFO *pCertType, HWND hwndDlg, HANDLE hCancelEvent);
  244. BOOL FormatMessageUnicode(LPWSTR * ppwszFormat, UINT ids, ...);
  245. void AELogAutoEnrollmentEvent(IN DWORD dwLogLevel,
  246. IN BOOL fError,
  247. IN HRESULT hr,
  248. IN DWORD dwEventId,
  249. IN BOOL fMachine,
  250. IN HANDLE hToken,
  251. IN DWORD dwParamCount,
  252. ...
  253. );
  254. BOOL AENetLogonUser(
  255. LPTSTR UserName,
  256. LPTSTR DomainName,
  257. LPTSTR Password,
  258. PHANDLE phToken
  259. );
  260. BOOL AEIsEmptyStore(HCERTSTORE hCertStore);
  261. BOOL AEIsSameDNS(PCCERT_CONTEXT pFirstCert, PCCERT_CONTEXT pSecondCert);
  262. BOOL AEGetDNSNameFromCertificate(PCCERT_CONTEXT pCertContext,
  263. LPWSTR *ppwszDnsName);
  264. BOOL AEGetRetryProperty(PCCERT_CONTEXT pCertContext,
  265. AE_RETRY_INFO **ppAE_Retry_Info);
  266. BOOL AEUpdateRetryProperty(AE_GENERAL_INFO *pAE_General_Info,
  267. LPWSTR pwszTemplateDisplay,
  268. PCCERT_CONTEXT pNewContext,
  269. PCCERT_CONTEXT pOldContext);
  270. BOOL AEFasterRetrialSchedule(PCCERT_CONTEXT pFirstContext,
  271. PCCERT_CONTEXT pSecondContext);
  272. //--------------------------------------------------------------------------
  273. // Debug prints
  274. //--------------------------------------------------------------------------
  275. #if DBG
  276. #define AE_ERROR 0x0001
  277. #define AE_WARNING 0x0002
  278. #define AE_INFO 0x0004
  279. #define AE_TRACE 0x0008
  280. #define AE_ALLOC 0x0010
  281. #define AE_RES 0x0020
  282. #define AE_DEBUG(x) AEDebugLog x
  283. #define AE_BEGIN(x) AEDebugLog(AE_TRACE, L"BEGIN:" x L"\n");
  284. #define AE_RETURN(x) { AEDebugLog(AE_TRACE, L"RETURN (%lx) Line %d\n",(x), __LINE__); return (x); }
  285. #define AE_END() { AEDebugLog(AE_TRACE, L"END:Line %d\n", __LINE__); }
  286. #define AE_BREAK() { AEDebugLog(AE_TRACE, L"BREAK Line %d\n", __LINE__); }
  287. void AEDebugLog(long Mask, LPCWSTR Format, ...);
  288. #define MAX_DEBUG_BUFFER 256
  289. #else
  290. #define AE_DEBUG(x)
  291. #define AE_BEGIN(x)
  292. #define AE_RETURN(x) return (x)
  293. #define AE_END()
  294. #define AE_BREAK()
  295. #endif
  296. #ifdef __cplusplus
  297. } // Balance extern "C" above
  298. #endif
  299. #endif // __AUTOENRO_H__