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.

606 lines
17 KiB

  1. //--------------------------------------------------------------
  2. // Copyright (C) Microsoft Corporation, 1996 - 1997
  3. //
  4. // File: private.h
  5. //
  6. // Contents: The private include file for cryptext.dll.
  7. //
  8. // History: May-13-1999 xiaohs Created
  9. //
  10. //--------------------------------------------------------------
  11. #ifndef CEP_PRIVATE_H
  12. #define CEP_PRIVATE_H
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. #define GET_TAG_OP "operation="
  17. #define GET_TAG_MSG "&message="
  18. #define GET_OP_CA "GetCACert"
  19. #define GET_OP_PKI "PKIOperation"
  20. #define CONTENT_TYPE_CA_RA "application/x-x509-ca-ra-cert"
  21. #define CONTENT_TYPE_PKI "application/x-pki-message"
  22. #define CONTENT_TYPE_HTML "text/html"
  23. #define ACCESS_MESSAGE "401 You do not have permission to enroll for an IPSEC intermediate offline certificate template for SCEP"
  24. #define OPERATION_GET_CACERT 1
  25. #define OPERATION_GET_PKI 2
  26. #define MESSAGE_TYPE_CERT_RESPONSE 3
  27. #define MESSAGE_TYPE_CERT_REQUEST 19
  28. #define MESSAGE_TYPE_GET_CERT_INITIAL 20
  29. #define MESSAGE_TYPE_GET_CERT 21
  30. #define MESSAGE_TYPE_GET_CRL 22
  31. #define MESSAGE_STATUS_SUCCESS 0
  32. #define MESSAGE_STATUS_FAILURE 2
  33. #define MESSAGE_STATUS_PENDING 3
  34. #define MESSAGE_FAILURE_BAD_ALG_ID 0
  35. #define MESSAGE_FAILURE_BAD_MESSAGE_CHECK 1
  36. #define MESSAGE_FAILURE_BAD_REQUEST 2
  37. #define MESSAGE_FAILURE_BAD_TIME 3
  38. #define MESSAGE_FAILURE_BAD_CERT_ID 4
  39. #define CEP_CONTEXT_CERT 1
  40. #define CEP_CONTEXT_CRL 2
  41. //together we should have 6 attributes: TransactionID, MessageType, PkiStatus,
  42. //ErrorInfo, senderNonce, and recipientNonce
  43. #define CEP_RESPONSE_AUTH_ATTR_COUNT 6
  44. #define szOIDVerisign_MessageType "2.16.840.1.113733.1.9.2"
  45. #define szOIDVerisign_PkiStatus "2.16.840.1.113733.1.9.3"
  46. #define szOIDVerisign_FailInfo "2.16.840.1.113733.1.9.4"
  47. #define szOIDVerisign_SenderNonce "2.16.840.1.113733.1.9.5"
  48. #define szOIDVerisign_RecipientNonce "2.16.840.1.113733.1.9.6"
  49. #define szOIDVerisign_TransactionID "2.16.840.1.113733.1.9.7"
  50. #define MAX_STRING_SIZE 512
  51. #define PENDING_ALLOC_SIZE 20
  52. #define FILETIME_TICKS_PER_SECOND 10000000
  53. #define OVERLAP_TWO_WEEKS 60*60*24*14
  54. #define OVERLAP_ONE_HOUR 60*60*1
  55. #define CEP_REQUEST_SIGNATURE 0x01
  56. #define CEP_REQUEST_EXCHANGE 0x02
  57. #define CEP_TEMPLATE_ATTR L"CertificateTemplate:"
  58. //-----------------------------------------------------------------------
  59. // Externs
  60. //
  61. //------------------------------------------------------------------------
  62. extern CRITICAL_SECTION CriticalSec;
  63. extern CRITICAL_SECTION PasswordCriticalSec;
  64. //need for the web page display
  65. extern DWORD g_dwPasswordValidity;
  66. //needed for the pending retrieval table
  67. extern DWORD g_dwRequestDuration;
  68. extern LPWSTR g_pwszComputerName;
  69. //**************************************************************************
  70. //
  71. // The defines for the transactionID and requestID mapping table
  72. //
  73. struct _CEP_TIME_ENTRY;
  74. //-----------------------------------------------------------------------
  75. // CEP_HASH_ENTRY
  76. //
  77. //------------------------------------------------------------------------
  78. typedef struct _CEP_HASH_ENTRY
  79. {
  80. LPSTR pszTransactionID;
  81. DWORD dwRequestID;
  82. BOOL fFinished;
  83. _CEP_TIME_ENTRY *pTimeEntry;
  84. _CEP_HASH_ENTRY *pNext;
  85. _CEP_HASH_ENTRY *pPrevious;
  86. }CEP_HASH_ENTRY;
  87. //-----------------------------------------------------------------------
  88. // CEP_TIME_ENTRY
  89. //
  90. //------------------------------------------------------------------------
  91. typedef struct _CEP_TIME_ENTRY
  92. {
  93. FILETIME TimeStamp;
  94. CEP_HASH_ENTRY *pHashEntry;
  95. _CEP_TIME_ENTRY *pNext;
  96. _CEP_TIME_ENTRY *pPrevious;
  97. }CEP_TIME_ENTRY;
  98. //-----------------------------------------------------------------------
  99. // CEP_HASH_TABLE_INFO
  100. //
  101. //------------------------------------------------------------------------
  102. //we hash based on the 1st byte
  103. #define CEP_HASH_TABLE_SIZE 256
  104. #define CEP_REFRESH_DAY 7
  105. typedef struct _CEP_HASH_TABLE_INFO
  106. {
  107. CEP_HASH_ENTRY *rgHashEntry[CEP_HASH_TABLE_SIZE]; //the hash table
  108. CEP_TIME_ENTRY *pTimeOld; //the list of hash entry with its timestamp
  109. CEP_TIME_ENTRY *pTimeNew;
  110. }CEP_HASH_TABLE_INFO;
  111. //**************************************************************************
  112. //
  113. // The defines for the password hash table
  114. //
  115. //-----------------------------------------------------------------------
  116. // CEP_PASSWORD_TABLE
  117. //
  118. //------------------------------------------------------------------------
  119. #define CEP_PASSWORD_LENGTH 8
  120. #define CEP_MAX_PASSWORD 1000
  121. #define CEP_PASSWORD_VALIDITY 60 //in minutes
  122. #define UPPER_BITS 0xF0
  123. #define LOWER_BITS 0x0F
  124. struct _CEP_PASSWORD_VALIDITY_ENTRY;
  125. //-----------------------------------------------------------------------
  126. // CEP_PASSWORD_ENTRY
  127. //
  128. //------------------------------------------------------------------------
  129. typedef struct _CEP_PASSWORD_ENTRY
  130. {
  131. LPWSTR pwszPassword;
  132. DWORD dwUsageRequested;
  133. _CEP_PASSWORD_VALIDITY_ENTRY *pValidityEntry;
  134. _CEP_PASSWORD_ENTRY *pNext;
  135. _CEP_PASSWORD_ENTRY *pPrevious;
  136. }CEP_PASSWORD_ENTRY;
  137. //-----------------------------------------------------------------------
  138. // CEP_PASSWORD_VALIDITY_ENTRY
  139. //
  140. //------------------------------------------------------------------------
  141. typedef struct _CEP_PASSWORD_VALIDITY_ENTRY
  142. {
  143. FILETIME TimeStamp;
  144. CEP_PASSWORD_ENTRY *pPasswordEntry;
  145. _CEP_PASSWORD_VALIDITY_ENTRY *pNext;
  146. _CEP_PASSWORD_VALIDITY_ENTRY *pPrevious;
  147. }CEP_PASSWORD_VALIDITY_ENTRY;
  148. //-----------------------------------------------------------------------
  149. // CEP_PASSWORD_TABLE_INFO
  150. //
  151. //------------------------------------------------------------------------
  152. typedef struct _CEP_PASSWORD_TABLE_INFO
  153. {
  154. CEP_PASSWORD_ENTRY *rgPasswordEntry[CEP_HASH_TABLE_SIZE]; //the hash table
  155. CEP_PASSWORD_VALIDITY_ENTRY *pTimeOld; //the list of hash entry with its timestamp
  156. CEP_PASSWORD_VALIDITY_ENTRY *pTimeNew;
  157. }CEP_PASSWORD_TABLE_INFO;
  158. //**************************************************************************
  159. //
  160. // The defines for the request hash table
  161. //
  162. //**************************************************************************
  163. #define CEP_MD5_HASH_SIZE 16
  164. #define CEP_REQUEST_DURATION 20
  165. struct _CEP_REQUEST_VALIDITY_ENTRY;
  166. //-----------------------------------------------------------------------
  167. // CEP_REQUEST_ENTRY
  168. //
  169. //------------------------------------------------------------------------
  170. typedef struct _CEP_REQUEST_ENTRY
  171. {
  172. BYTE pbHash[CEP_MD5_HASH_SIZE];
  173. DWORD dwRequestID;
  174. _CEP_REQUEST_VALIDITY_ENTRY *pValidityEntry;
  175. _CEP_REQUEST_ENTRY *pNext;
  176. _CEP_REQUEST_ENTRY *pPrevious;
  177. }CEP_REQUEST_ENTRY;
  178. //-----------------------------------------------------------------------
  179. // CEP_REQUEST_VALIDITY_ENTRY
  180. //
  181. //------------------------------------------------------------------------
  182. typedef struct _CEP_REQUEST_VALIDITY_ENTRY
  183. {
  184. FILETIME TimeStamp;
  185. CEP_REQUEST_ENTRY *pRequestEntry;
  186. _CEP_REQUEST_VALIDITY_ENTRY *pNext;
  187. _CEP_REQUEST_VALIDITY_ENTRY *pPrevious;
  188. }CEP_REQUEST_VALIDITY_ENTRY;
  189. //-----------------------------------------------------------------------
  190. // CEP_REQUEST_TABLE_INFO
  191. //
  192. //------------------------------------------------------------------------
  193. typedef struct _CEP_REQUEST_TABLE_INFO
  194. {
  195. CEP_REQUEST_ENTRY *rgRequestEntry[CEP_HASH_TABLE_SIZE]; //the hash table
  196. CEP_REQUEST_VALIDITY_ENTRY *pTimeOld; //the list of hash entry with its timestamp
  197. CEP_REQUEST_VALIDITY_ENTRY *pTimeNew;
  198. }CEP_REQUEST_TABLE_INFO;
  199. //
  200. // The defines for CA and RA message
  201. //
  202. //-----------------------------------------------------------------------
  203. // CEP_CA_INFO
  204. //
  205. //------------------------------------------------------------------------
  206. typedef struct _CEP_CA_INFO
  207. {
  208. BSTR bstrCAMachine;
  209. BSTR bstrCAName;
  210. BSTR bstrCAConfig;
  211. BSTR bstrDSName;
  212. LPWSTR pwszCAHash;
  213. HCRYPTPROV hProv;
  214. BOOL fEnterpriseCA;
  215. ICertRequest *pICertRequest;
  216. LPWSTR pwszTemplateSig;
  217. LPWSTR pwszTemplateEnt;
  218. }CEP_CA_INFO;
  219. //-----------------------------------------------------------------------
  220. // CEP_RA_INFO
  221. //
  222. //------------------------------------------------------------------------
  223. typedef struct _CEP_RA_INFO
  224. {
  225. HCRYPTPROV hRAProv;
  226. DWORD dwKeySpec;
  227. PCCERT_CONTEXT pRACert;
  228. PCCERT_CONTEXT pRASign;
  229. BOOL fFree;
  230. HCRYPTPROV hSignProv;
  231. DWORD dwSignKeySpec;
  232. BOOL fSignFree;
  233. DWORD dwRefreshDays;
  234. BOOL fPassword;
  235. }CEP_RA_INFO;
  236. //-----------------------------------------------------------------------
  237. // CEP_MESSAGE_INFO
  238. //
  239. //------------------------------------------------------------------------
  240. typedef struct _CEP_MESSAGE_INFO
  241. {
  242. CERT_BLOB TransactionID; //internally a string
  243. DWORD dwMessageType;
  244. DWORD dwStatus;
  245. DWORD dwErrorInfo;
  246. CERT_BLOB SenderNonce;
  247. CERT_BLOB RecipientNonce;
  248. CERT_BLOB SerialNumber;
  249. PCCERT_CONTEXT pSigningCert;
  250. }CEP_MESSAGE_INFO;
  251. //-----------------------------------------------------------------------
  252. //
  253. // Function prototypes
  254. //
  255. //------------------------------------------------------------------------
  256. BOOL WINAPI InitRequestTable();
  257. BOOL WINAPI ReleaseRequestTable();
  258. BOOL WINAPI CEPRequestRetrieveRequestIDFromHash(BYTE *pbHash,
  259. DWORD *pdwRequestID);
  260. BOOL WINAPI CEPRequestAddHashAndRequestID(BYTE *pbHash,
  261. DWORD dwRequestID);
  262. BOOL WINAPI InitPasswordTable();
  263. BOOL WINAPI ReleasePasswordTable();
  264. BOOL WINAPI CEPAddPasswordToTable(LPWSTR pwszPassword);
  265. BOOL WINAPI CEPVerifyPasswordAndDeleteFromTable(LPWSTR pwszPassword, DWORD dwUsage);
  266. BOOL InitHashTable();
  267. BOOL ReleaseHashTable();
  268. BOOL GetRAInfo(CEP_RA_INFO *pRAInfo);
  269. BOOL GetCACertFromInfo(CEP_CA_INFO *pCAInfo, HCERTSTORE *pHCACertStore);
  270. BOOL InitCAInformation(CEP_CA_INFO *pCAInfo);
  271. BOOL FreeCAInformation(CEP_CA_INFO *pCAInfo);
  272. BOOL FreeRAInformation(CEP_RA_INFO *pRAInfo);
  273. LPSTR GetTagValue(LPSTR szString, LPSTR szTag);
  274. BOOL OperationGetCACert(HCERTSTORE hCACertStore,
  275. LPSTR szMsg,
  276. BYTE **ppbData,
  277. DWORD *pcbData);
  278. BOOL OperationGetPKI( CEP_RA_INFO *pRAInfo,
  279. CEP_CA_INFO *pCAInfo,
  280. LPSTR szMsg,
  281. BYTE **ppbData,
  282. DWORD *pcbData);
  283. BOOL WINAPI GetSerialNumberFromBlob(BYTE *pbEncoded,
  284. DWORD cbEncoded,
  285. CRYPT_INTEGER_BLOB *pSerialNumber);
  286. BOOL GetReturnInfoAndContent(CEP_RA_INFO *pRAInfo,
  287. CEP_CA_INFO *pCAInfo,
  288. LPSTR szMsg,
  289. BYTE **ppbData,
  290. DWORD *pcbData,
  291. CEP_MESSAGE_INFO *pMsgInfo);
  292. BOOL WINAPI DecryptMsg(CEP_RA_INFO *pRAInfo,
  293. BYTE *pbReqEnv,
  294. DWORD cbReqEnv,
  295. BYTE **ppbReqDecrypt,
  296. DWORD *pcbReqDecrypt);
  297. BOOL WINAPI GetContentFromPKCS7(BYTE *pbMessage,
  298. DWORD cbMessage,
  299. BYTE **ppbContent,
  300. DWORD *pbContent,
  301. CEP_MESSAGE_INFO *pMsgInfo);
  302. void WINAPI FreeMessageInfo(CEP_MESSAGE_INFO *pMsgInfo);
  303. BOOL WINAPI AllocAndCopyBlob(CERT_BLOB *pDestBlob,
  304. CERT_BLOB *pSrcBlob);
  305. BOOL WINAPI CEPAllocAndDecode( LPCSTR lpszStructType,
  306. BYTE *pbEncoded,
  307. DWORD cbEncoded,
  308. void **ppb,
  309. DWORD *pcb);
  310. BOOL WINAPI CEPRetrievePasswordFromRequest(BYTE *pbRequest,
  311. DWORD cbRequest,
  312. LPWSTR *ppwszPassword,
  313. DWORD *pdwUsage);
  314. BOOL WINAPI AltNameExist(BYTE *pbRequest, DWORD cbRequest);
  315. BOOL WINAPI SameCert(CERT_INFO *pCertInfoOne, CERT_INFO *pCertInfoTwo);
  316. BOOL WINAPI SameBlob(CRYPT_INTEGER_BLOB *pBlobOne, CRYPT_INTEGER_BLOB *pBlobTwo);
  317. BOOL EnvelopData(PCCERT_CONTEXT pSigningCert,
  318. BYTE *pbContent,
  319. DWORD cbContent,
  320. BYTE **ppbEnvelop,
  321. DWORD *pcbEnvelop);
  322. BOOL CEPHashGetRequestID( DWORD dwRefreshDays,
  323. CERT_BLOB *pTrasactionID,
  324. DWORD *pdwRequestID);
  325. BOOL CEPHashMarkTransactionFinished(DWORD dwRequestID, CERT_BLOB *pTransactionID);
  326. BOOL CEPHashAddRequestAndTransaction(DWORD dwRefreshDays,
  327. DWORD dwRequestID,
  328. CERT_BLOB *pTransactionID);
  329. BOOL CEPHashIsCurrentTimeEntry(FILETIME *pTimeStamp, DWORD dwRefreshDays, DWORD dwMinutes);
  330. BOOL WINAPI ProcessGetCRL(CEP_CA_INFO *pCAInfo,
  331. BYTE *pbRequest,
  332. DWORD cbRequest,
  333. BYTE **ppbData,
  334. DWORD *pcbData,
  335. CEP_MESSAGE_INFO *pMsgInfo);
  336. BOOL WINAPI ProcessGetCert(CEP_CA_INFO *pCAInfo,
  337. BYTE *pbRequest,
  338. DWORD cbRequest,
  339. BYTE **ppbData,
  340. DWORD *pcbData,
  341. CEP_MESSAGE_INFO *pMsgInfo);
  342. BOOL ProcessCertInitial( DWORD dwRefreshDays,
  343. CEP_CA_INFO *pCAInfo,
  344. BYTE *pbRequest,
  345. DWORD cbRequest,
  346. BYTE **ppbData,
  347. DWORD *pcbData,
  348. CEP_MESSAGE_INFO *pMsgInfo);
  349. BOOL ProcessCertRequest( DWORD dwRefreshDays,
  350. BOOL fPassword,
  351. PCCERT_CONTEXT pRAEncrypt,
  352. PCCERT_CONTEXT pRACert,
  353. CEP_CA_INFO *pCAInfo,
  354. BYTE *pbRequest,
  355. DWORD cbRequest,
  356. BYTE **ppbData,
  357. DWORD *pcbData,
  358. CEP_MESSAGE_INFO *pMsgInfo);
  359. BOOL PackageBlobToPKCS7(DWORD dwCEP_Context,
  360. BYTE *pbEncoded,
  361. DWORD cbEncoded,
  362. BYTE **ppbData,
  363. DWORD *pcbData);
  364. BOOL GenerateSenderNonce(CRYPT_INTEGER_BLOB *pBlob);
  365. BOOL SignData(CEP_MESSAGE_INFO *pMsgInfo,
  366. CEP_RA_INFO *pRAInfo,
  367. BYTE *pbEnvelop,
  368. DWORD cbEnvelop,
  369. BYTE **ppbData,
  370. DWORD *pcbData);
  371. BOOL CEPAllocAndEncodeName(DWORD dwValueType,
  372. BYTE *pbData,
  373. DWORD cbData,
  374. BYTE **ppbEncoded,
  375. DWORD *pcbEncoded);
  376. BOOL CEPAllocAndEncodeDword(DWORD dwValueType,
  377. DWORD dwData,
  378. BYTE **ppbEncoded,
  379. DWORD *pcbEncoded);
  380. BOOL WINAPI CEPAllocAndEncode(LPCSTR lpszStructType,
  381. void *pStructInfo,
  382. BYTE **ppbEncoded,
  383. DWORD *pcbEncoded);
  384. BOOL WINAPI AddAltNameInRequest(PCCERT_CONTEXT pRACert,
  385. BYTE *pb10,
  386. DWORD cb10,
  387. LPWSTR pwszDNS,
  388. CRYPT_DATA_BLOB *pIPAddress,
  389. BYTE **ppb7,
  390. DWORD *pcb7);
  391. BOOL WINAPI CreateAltNameExtenions(LPWSTR pwszDNS,
  392. CRYPT_DATA_BLOB *pIPAddress,
  393. BYTE **pbExt,
  394. DWORD *pcbExt);
  395. BOOL WINAPI GetAltNameElement(BYTE *pb10,
  396. DWORD cb10,
  397. LPWSTR *ppwszDNS,
  398. CRYPT_DATA_BLOB *pIPAddress);
  399. BOOL ConvertIPStringToBinary(LPWSTR pwszIP,
  400. CRYPT_DATA_BLOB *pIPAddress);
  401. BOOL WINAPI AllocAndCopyString(CERT_BLOB *pDestBlob,
  402. LPSTR psz);
  403. BOOL WINAPI RetrieveContextFromSerialNumber(CEP_CA_INFO *pCAInfo,
  404. CERT_BLOB *pSerialNumber,
  405. PCCERT_CONTEXT *ppCertContext);
  406. BOOL WINAPI GetConfigInfo(DWORD *pdwRefreshDays, BOOL *pfPassword);
  407. BOOL CEPGetTokenFromPKCS10(BOOL fPassword,
  408. PCCERT_CONTEXT pRAEncrypt,
  409. BYTE *pbRequest,
  410. DWORD cbRequest,
  411. HANDLE *phToken);
  412. BOOL GetLogonInfoFromValue(PCCERT_CONTEXT pRAEncrypt,
  413. LPWSTR pwszString,
  414. LPWSTR *ppwszDomain,
  415. LPWSTR *ppwszUser,
  416. LPWSTR *ppwszPassword);
  417. BOOL CEPDecryptPassword(PCCERT_CONTEXT pRAEncrypt,
  418. LPWSTR pwszEncrypt,
  419. LPWSTR *ppwszDecrypt);
  420. BOOL WINAPI IsAnonymousAccess(EXTENSION_CONTROL_BLOCK *pECB);
  421. HRESULT WINAPI CheckACLOnCertTemplate(BOOL fSelf, LPWSTR pwszCAName, LPWSTR pwszCertType);
  422. BOOL WINAPI OperationDisplayAccessHTML(BYTE **ppbData, DWORD *pcbData);
  423. BOOL WINAPI OperationGetDisplayInfoForCEP(LPWSTR pwszCAHash,
  424. HCRYPTPROV hProv,
  425. BOOL fPassword,
  426. BYTE **ppbData,
  427. DWORD *pcbData);
  428. BOOL WINAPI LoadIDToTemplate(UINT idsMsg,
  429. BYTE **ppbData,
  430. DWORD *pcbData);
  431. BOOL WINAPI LoadWZToTemplate(LPWSTR pwsz,
  432. BYTE **ppbData,
  433. DWORD *pcbData);
  434. BOOL WINAPI FormatMessageUnicode(LPWSTR *ppwszFormat,UINT ids,...);
  435. BOOL WINAPI CopyWZToBuffer( LPWSTR pwszData,
  436. BYTE **ppbData,
  437. DWORD *pcbData);
  438. BOOL WINAPI LoadIDAndHRToTempalte(UINT idsMsg,
  439. HRESULT hr,
  440. BYTE **ppbData,
  441. DWORD *pcbData);
  442. BOOL WINAPI ConvertByteToWstr(BYTE *pbData,
  443. DWORD cbData,
  444. LPWSTR *ppwsz,
  445. BOOL fSpace);
  446. BOOL WINAPI CEPGetCertFromPKCS10(CEP_CA_INFO *pCAInfo,
  447. BYTE *pbRequest,
  448. DWORD cbRequest,
  449. BYTE **ppbData,
  450. DWORD *pcbData,
  451. CEP_MESSAGE_INFO *pMsgInfo);
  452. void WINAPI LogSCEPEvent(IN DWORD dwLogLevel,
  453. IN BOOL fError,
  454. IN HRESULT hr,
  455. IN DWORD dwEventId,
  456. IN DWORD dwParamCount,
  457. ...
  458. );
  459. #ifdef __cplusplus
  460. } // Balance extern "C" above
  461. #endif
  462. #endif //CEP_PRIVATE_H