Source code of Windows XP (NT5)
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.

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