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.

16033 lines
641 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992-1999.
  5. //
  6. // File: wincrypt.h
  7. //
  8. // Contents: Cryptographic API Prototypes and Definitions
  9. //
  10. //----------------------------------------------------------------------------
  11. #ifndef __WINCRYPT_H__
  12. #define __WINCRYPT_H__
  13. #if defined (_MSC_VER)
  14. #if ( _MSC_VER >= 800 )
  15. #if _MSC_VER >= 1200
  16. #pragma warning(push)
  17. #endif
  18. #pragma warning(disable:4201) /* Nameless struct/union */
  19. #endif
  20. #if (_MSC_VER > 1020)
  21. #pragma once
  22. #endif
  23. #endif
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #ifndef _HRESULT_DEFINED
  28. #define _HRESULT_DEFINED
  29. typedef LONG HRESULT;
  30. #endif // !_HRESULT_DEFINED
  31. #ifndef WINADVAPI
  32. #define WINADVAPI
  33. #endif
  34. #ifndef WINAPI
  35. #define WINAPI __stdcall
  36. #endif
  37. #ifndef CALLBACK
  38. #define CALLBACK __stdcall
  39. #endif
  40. #ifndef DECLSPEC_IMPORT
  41. #define DECLSPEC_IMPORT
  42. #endif
  43. #ifndef CONST
  44. #define CONST const
  45. #endif
  46. #ifndef IN
  47. #define IN
  48. #endif
  49. #ifndef OUT
  50. #define OUT
  51. #endif
  52. #ifndef OPTIONAL
  53. #define OPTIONAL
  54. #endif
  55. #if !defined(_CRYPT32_)
  56. #define WINCRYPT32API DECLSPEC_IMPORT
  57. #else
  58. #define WINCRYPT32API
  59. #endif
  60. #if !defined(_CRYPT32STRING_)
  61. # define WINCRYPT32STRINGAPI WINCRYPT32API
  62. #else
  63. # define WINCRYPT32STRINGAPI
  64. #endif
  65. //
  66. // Algorithm IDs and Flags
  67. //
  68. // ALG_ID crackers
  69. #define GET_ALG_CLASS(x) (x & (7 << 13))
  70. #define GET_ALG_TYPE(x) (x & (15 << 9))
  71. #define GET_ALG_SID(x) (x & (511))
  72. // Algorithm classes
  73. #define ALG_CLASS_ANY (0)
  74. #define ALG_CLASS_SIGNATURE (1 << 13)
  75. #define ALG_CLASS_MSG_ENCRYPT (2 << 13)
  76. #define ALG_CLASS_DATA_ENCRYPT (3 << 13)
  77. #define ALG_CLASS_HASH (4 << 13)
  78. #define ALG_CLASS_KEY_EXCHANGE (5 << 13)
  79. #define ALG_CLASS_ALL (7 << 13)
  80. // Algorithm types
  81. #define ALG_TYPE_ANY (0)
  82. #define ALG_TYPE_DSS (1 << 9)
  83. #define ALG_TYPE_RSA (2 << 9)
  84. #define ALG_TYPE_BLOCK (3 << 9)
  85. #define ALG_TYPE_STREAM (4 << 9)
  86. #define ALG_TYPE_DH (5 << 9)
  87. #define ALG_TYPE_SECURECHANNEL (6 << 9)
  88. // Generic sub-ids
  89. #define ALG_SID_ANY (0)
  90. // Some RSA sub-ids
  91. #define ALG_SID_RSA_ANY 0
  92. #define ALG_SID_RSA_PKCS 1
  93. #define ALG_SID_RSA_MSATWORK 2
  94. #define ALG_SID_RSA_ENTRUST 3
  95. #define ALG_SID_RSA_PGP 4
  96. // Some DSS sub-ids
  97. //
  98. #define ALG_SID_DSS_ANY 0
  99. #define ALG_SID_DSS_PKCS 1
  100. #define ALG_SID_DSS_DMS 2
  101. // Block cipher sub ids
  102. // DES sub_ids
  103. #define ALG_SID_DES 1
  104. #define ALG_SID_3DES 3
  105. #define ALG_SID_DESX 4
  106. #define ALG_SID_IDEA 5
  107. #define ALG_SID_CAST 6
  108. #define ALG_SID_SAFERSK64 7
  109. #define ALG_SID_SAFERSK128 8
  110. #define ALG_SID_3DES_112 9
  111. #define ALG_SID_CYLINK_MEK 12
  112. #define ALG_SID_RC5 13
  113. #define ALG_SID_AES_128 14
  114. #define ALG_SID_AES_192 15
  115. #define ALG_SID_AES_256 16
  116. #define ALG_SID_AES 17
  117. // Fortezza sub-ids
  118. #define ALG_SID_SKIPJACK 10
  119. #define ALG_SID_TEK 11
  120. // KP_MODE
  121. #define CRYPT_MODE_CBCI 6 // ANSI CBC Interleaved
  122. #define CRYPT_MODE_CFBP 7 // ANSI CFB Pipelined
  123. #define CRYPT_MODE_OFBP 8 // ANSI OFB Pipelined
  124. #define CRYPT_MODE_CBCOFM 9 // ANSI CBC + OF Masking
  125. #define CRYPT_MODE_CBCOFMI 10 // ANSI CBC + OFM Interleaved
  126. // RC2 sub-ids
  127. #define ALG_SID_RC2 2
  128. // Stream cipher sub-ids
  129. #define ALG_SID_RC4 1
  130. #define ALG_SID_SEAL 2
  131. // Diffie-Hellman sub-ids
  132. #define ALG_SID_DH_SANDF 1
  133. #define ALG_SID_DH_EPHEM 2
  134. #define ALG_SID_AGREED_KEY_ANY 3
  135. #define ALG_SID_KEA 4
  136. // Hash sub ids
  137. #define ALG_SID_MD2 1
  138. #define ALG_SID_MD4 2
  139. #define ALG_SID_MD5 3
  140. #define ALG_SID_SHA 4
  141. #define ALG_SID_SHA1 4
  142. #define ALG_SID_MAC 5
  143. #define ALG_SID_RIPEMD 6
  144. #define ALG_SID_RIPEMD160 7
  145. #define ALG_SID_SSL3SHAMD5 8
  146. #define ALG_SID_HMAC 9
  147. #define ALG_SID_TLS1PRF 10
  148. #define ALG_SID_HASH_REPLACE_OWF 11
  149. #define ALG_SID_SHA_256 12
  150. #define ALG_SID_SHA_384 13
  151. #define ALG_SID_SHA_512 14
  152. // secure channel sub ids
  153. #define ALG_SID_SSL3_MASTER 1
  154. #define ALG_SID_SCHANNEL_MASTER_HASH 2
  155. #define ALG_SID_SCHANNEL_MAC_KEY 3
  156. #define ALG_SID_PCT1_MASTER 4
  157. #define ALG_SID_SSL2_MASTER 5
  158. #define ALG_SID_TLS1_MASTER 6
  159. #define ALG_SID_SCHANNEL_ENC_KEY 7
  160. // Our silly example sub-id
  161. #define ALG_SID_EXAMPLE 80
  162. #ifndef ALGIDDEF
  163. #define ALGIDDEF
  164. typedef unsigned int ALG_ID;
  165. #endif
  166. // algorithm identifier definitions
  167. #define CALG_MD2 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD2)
  168. #define CALG_MD4 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD4)
  169. #define CALG_MD5 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD5)
  170. #define CALG_SHA (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA)
  171. #define CALG_SHA1 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA1)
  172. #define CALG_MAC (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MAC)
  173. #define CALG_RSA_SIGN (ALG_CLASS_SIGNATURE | ALG_TYPE_RSA | ALG_SID_RSA_ANY)
  174. #define CALG_DSS_SIGN (ALG_CLASS_SIGNATURE | ALG_TYPE_DSS | ALG_SID_DSS_ANY)
  175. #define CALG_NO_SIGN (ALG_CLASS_SIGNATURE | ALG_TYPE_ANY | ALG_SID_ANY)
  176. #define CALG_RSA_KEYX (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_RSA|ALG_SID_RSA_ANY)
  177. #define CALG_DES (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_DES)
  178. #define CALG_3DES_112 (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_3DES_112)
  179. #define CALG_3DES (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_3DES)
  180. #define CALG_DESX (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_DESX)
  181. #define CALG_RC2 (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_RC2)
  182. #define CALG_RC4 (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_STREAM|ALG_SID_RC4)
  183. #define CALG_SEAL (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_STREAM|ALG_SID_SEAL)
  184. #define CALG_DH_SF (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_DH_SANDF)
  185. #define CALG_DH_EPHEM (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_DH_EPHEM)
  186. #define CALG_AGREEDKEY_ANY (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_AGREED_KEY_ANY)
  187. #define CALG_KEA_KEYX (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_KEA)
  188. #define CALG_HUGHES_MD5 (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_ANY|ALG_SID_MD5)
  189. #define CALG_SKIPJACK (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_SKIPJACK)
  190. #define CALG_TEK (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_TEK)
  191. #define CALG_CYLINK_MEK (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_CYLINK_MEK)
  192. #define CALG_SSL3_SHAMD5 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SSL3SHAMD5)
  193. #define CALG_SSL3_MASTER (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SSL3_MASTER)
  194. #define CALG_SCHANNEL_MASTER_HASH (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SCHANNEL_MASTER_HASH)
  195. #define CALG_SCHANNEL_MAC_KEY (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SCHANNEL_MAC_KEY)
  196. #define CALG_SCHANNEL_ENC_KEY (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SCHANNEL_ENC_KEY)
  197. #define CALG_PCT1_MASTER (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_PCT1_MASTER)
  198. #define CALG_SSL2_MASTER (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SSL2_MASTER)
  199. #define CALG_TLS1_MASTER (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_TLS1_MASTER)
  200. #define CALG_RC5 (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_RC5)
  201. #define CALG_HMAC (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_HMAC)
  202. #define CALG_TLS1PRF (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_TLS1PRF)
  203. #define CALG_HASH_REPLACE_OWF (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_HASH_REPLACE_OWF)
  204. #define CALG_AES_128 (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_AES_128)
  205. #define CALG_AES_192 (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_AES_192)
  206. #define CALG_AES_256 (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_AES_256)
  207. #define CALG_AES (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_AES)
  208. #define CALG_SHA_256 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_256)
  209. #define CALG_SHA_384 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_384)
  210. #define CALG_SHA_512 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_512)
  211. typedef ULONG_PTR HCRYPTPROV;
  212. typedef ULONG_PTR HCRYPTKEY;
  213. typedef ULONG_PTR HCRYPTHASH;
  214. // dwFlags definitions for CryptAcquireContext
  215. #define CRYPT_VERIFYCONTEXT 0xF0000000
  216. #define CRYPT_NEWKEYSET 0x00000008
  217. #define CRYPT_DELETEKEYSET 0x00000010
  218. #define CRYPT_MACHINE_KEYSET 0x00000020
  219. #define CRYPT_SILENT 0x00000040
  220. // dwFlag definitions for CryptGenKey
  221. #define CRYPT_EXPORTABLE 0x00000001
  222. #define CRYPT_USER_PROTECTED 0x00000002
  223. #define CRYPT_CREATE_SALT 0x00000004
  224. #define CRYPT_UPDATE_KEY 0x00000008
  225. #define CRYPT_NO_SALT 0x00000010
  226. #define CRYPT_PREGEN 0x00000040
  227. #define CRYPT_RECIPIENT 0x00000010
  228. #define CRYPT_INITIATOR 0x00000040
  229. #define CRYPT_ONLINE 0x00000080
  230. #define CRYPT_SF 0x00000100
  231. #define CRYPT_CREATE_IV 0x00000200
  232. #define CRYPT_KEK 0x00000400
  233. #define CRYPT_DATA_KEY 0x00000800
  234. #define CRYPT_VOLATILE 0x00001000
  235. #define CRYPT_SGCKEY 0x00002000
  236. #define CRYPT_ARCHIVABLE 0x00004000
  237. #define RSA1024BIT_KEY 0x04000000
  238. // dwFlags definitions for CryptDeriveKey
  239. #define CRYPT_SERVER 0x00000400
  240. #define KEY_LENGTH_MASK 0xFFFF0000
  241. // dwFlag definitions for CryptExportKey
  242. #define CRYPT_Y_ONLY 0x00000001
  243. #define CRYPT_SSL2_FALLBACK 0x00000002
  244. #define CRYPT_DESTROYKEY 0x00000004
  245. #define CRYPT_OAEP 0x00000040 // used with RSA encryptions/decryptions
  246. // CryptExportKey, CryptImportKey,
  247. // CryptEncrypt and CryptDecrypt
  248. #define CRYPT_BLOB_VER3 0x00000080 // export version 3 of a blob type
  249. #define CRYPT_IPSEC_HMAC_KEY 0x00000100 // CryptImportKey only
  250. // dwFlags definitions for CryptDecrypt
  251. // See also CRYPT_OAEP, above.
  252. // Note, the following flag is not supported for CryptEncrypt
  253. #define CRYPT_DECRYPT_RSA_NO_PADDING_CHECK 0x00000020
  254. // dwFlags definitions for CryptCreateHash
  255. #define CRYPT_SECRETDIGEST 0x00000001
  256. // dwFlags definitions for CryptHashData
  257. #define CRYPT_OWF_REPL_LM_HASH 0x00000001 // this is only for the OWF replacement CSP
  258. // dwFlags definitions for CryptHashSessionKey
  259. #define CRYPT_LITTLE_ENDIAN 0x00000001
  260. // dwFlags definitions for CryptSignHash and CryptVerifySignature
  261. #define CRYPT_NOHASHOID 0x00000001
  262. #define CRYPT_TYPE2_FORMAT 0x00000002
  263. #define CRYPT_X931_FORMAT 0x00000004
  264. // dwFlag definitions for CryptSetProviderEx and CryptGetDefaultProvider
  265. #define CRYPT_MACHINE_DEFAULT 0x00000001
  266. #define CRYPT_USER_DEFAULT 0x00000002
  267. #define CRYPT_DELETE_DEFAULT 0x00000004
  268. // exported key blob definitions
  269. #define SIMPLEBLOB 0x1
  270. #define PUBLICKEYBLOB 0x6
  271. #define PRIVATEKEYBLOB 0x7
  272. #define PLAINTEXTKEYBLOB 0x8
  273. #define OPAQUEKEYBLOB 0x9
  274. #define PUBLICKEYBLOBEX 0xA
  275. #define SYMMETRICWRAPKEYBLOB 0xB
  276. #define AT_KEYEXCHANGE 1
  277. #define AT_SIGNATURE 2
  278. #define CRYPT_USERDATA 1
  279. // dwParam
  280. #define KP_IV 1 // Initialization vector
  281. #define KP_SALT 2 // Salt value
  282. #define KP_PADDING 3 // Padding values
  283. #define KP_MODE 4 // Mode of the cipher
  284. #define KP_MODE_BITS 5 // Number of bits to feedback
  285. #define KP_PERMISSIONS 6 // Key permissions DWORD
  286. #define KP_ALGID 7 // Key algorithm
  287. #define KP_BLOCKLEN 8 // Block size of the cipher
  288. #define KP_KEYLEN 9 // Length of key in bits
  289. #define KP_SALT_EX 10 // Length of salt in bytes
  290. #define KP_P 11 // DSS/Diffie-Hellman P value
  291. #define KP_G 12 // DSS/Diffie-Hellman G value
  292. #define KP_Q 13 // DSS Q value
  293. #define KP_X 14 // Diffie-Hellman X value
  294. #define KP_Y 15 // Y value
  295. #define KP_RA 16 // Fortezza RA value
  296. #define KP_RB 17 // Fortezza RB value
  297. #define KP_INFO 18 // for putting information into an RSA envelope
  298. #define KP_EFFECTIVE_KEYLEN 19 // setting and getting RC2 effective key length
  299. #define KP_SCHANNEL_ALG 20 // for setting the Secure Channel algorithms
  300. #define KP_CLIENT_RANDOM 21 // for setting the Secure Channel client random data
  301. #define KP_SERVER_RANDOM 22 // for setting the Secure Channel server random data
  302. #define KP_RP 23
  303. #define KP_PRECOMP_MD5 24
  304. #define KP_PRECOMP_SHA 25
  305. #define KP_CERTIFICATE 26 // for setting Secure Channel certificate data (PCT1)
  306. #define KP_CLEAR_KEY 27 // for setting Secure Channel clear key data (PCT1)
  307. #define KP_PUB_EX_LEN 28
  308. #define KP_PUB_EX_VAL 29
  309. #define KP_KEYVAL 30
  310. #define KP_ADMIN_PIN 31
  311. #define KP_KEYEXCHANGE_PIN 32
  312. #define KP_SIGNATURE_PIN 33
  313. #define KP_PREHASH 34
  314. #define KP_ROUNDS 35
  315. #define KP_OAEP_PARAMS 36 // for setting OAEP params on RSA keys
  316. #define KP_CMS_KEY_INFO 37
  317. #define KP_CMS_DH_KEY_INFO 38
  318. #define KP_PUB_PARAMS 39 // for setting public parameters
  319. #define KP_VERIFY_PARAMS 40 // for verifying DSA and DH parameters
  320. #define KP_HIGHEST_VERSION 41 // for TLS protocol version setting
  321. #define KP_GET_USE_COUNT 42 // for use with PP_CRYPT_COUNT_KEY_USE contexts
  322. // KP_PADDING
  323. #define PKCS5_PADDING 1 // PKCS 5 (sec 6.2) padding method
  324. #define RANDOM_PADDING 2
  325. #define ZERO_PADDING 3
  326. // KP_MODE
  327. #define CRYPT_MODE_CBC 1 // Cipher block chaining
  328. #define CRYPT_MODE_ECB 2 // Electronic code book
  329. #define CRYPT_MODE_OFB 3 // Output feedback mode
  330. #define CRYPT_MODE_CFB 4 // Cipher feedback mode
  331. #define CRYPT_MODE_CTS 5 // Ciphertext stealing mode
  332. // KP_PERMISSIONS
  333. #define CRYPT_ENCRYPT 0x0001 // Allow encryption
  334. #define CRYPT_DECRYPT 0x0002 // Allow decryption
  335. #define CRYPT_EXPORT 0x0004 // Allow key to be exported
  336. #define CRYPT_READ 0x0008 // Allow parameters to be read
  337. #define CRYPT_WRITE 0x0010 // Allow parameters to be set
  338. #define CRYPT_MAC 0x0020 // Allow MACs to be used with key
  339. #define CRYPT_EXPORT_KEY 0x0040 // Allow key to be used for exporting keys
  340. #define CRYPT_IMPORT_KEY 0x0080 // Allow key to be used for importing keys
  341. #define CRYPT_ARCHIVE 0x0100 // Allow key to be exported at creation only
  342. #define HP_ALGID 0x0001 // Hash algorithm
  343. #define HP_HASHVAL 0x0002 // Hash value
  344. #define HP_HASHSIZE 0x0004 // Hash value size
  345. #define HP_HMAC_INFO 0x0005 // information for creating an HMAC
  346. #define HP_TLS1PRF_LABEL 0x0006 // label for TLS1 PRF
  347. #define HP_TLS1PRF_SEED 0x0007 // seed for TLS1 PRF
  348. #define CRYPT_FAILED FALSE
  349. #define CRYPT_SUCCEED TRUE
  350. #define RCRYPT_SUCCEEDED(rt) ((rt) == CRYPT_SUCCEED)
  351. #define RCRYPT_FAILED(rt) ((rt) == CRYPT_FAILED)
  352. //
  353. // CryptGetProvParam
  354. //
  355. #define PP_ENUMALGS 1
  356. #define PP_ENUMCONTAINERS 2
  357. #define PP_IMPTYPE 3
  358. #define PP_NAME 4
  359. #define PP_VERSION 5
  360. #define PP_CONTAINER 6
  361. #define PP_CHANGE_PASSWORD 7
  362. #define PP_KEYSET_SEC_DESCR 8 // get/set security descriptor of keyset
  363. #define PP_CERTCHAIN 9 // for retrieving certificates from tokens
  364. #define PP_KEY_TYPE_SUBTYPE 10
  365. #define PP_PROVTYPE 16
  366. #define PP_KEYSTORAGE 17
  367. #define PP_APPLI_CERT 18
  368. #define PP_SYM_KEYSIZE 19
  369. #define PP_SESSION_KEYSIZE 20
  370. #define PP_UI_PROMPT 21
  371. #define PP_ENUMALGS_EX 22
  372. #define PP_ENUMMANDROOTS 25
  373. #define PP_ENUMELECTROOTS 26
  374. #define PP_KEYSET_TYPE 27
  375. #define PP_ADMIN_PIN 31
  376. #define PP_KEYEXCHANGE_PIN 32
  377. #define PP_SIGNATURE_PIN 33
  378. #define PP_SIG_KEYSIZE_INC 34
  379. #define PP_KEYX_KEYSIZE_INC 35
  380. #define PP_UNIQUE_CONTAINER 36
  381. #define PP_SGC_INFO 37
  382. #define PP_USE_HARDWARE_RNG 38
  383. #define PP_KEYSPEC 39
  384. #define PP_ENUMEX_SIGNING_PROT 40
  385. #define PP_CRYPT_COUNT_KEY_USE 41
  386. #define CRYPT_FIRST 1
  387. #define CRYPT_NEXT 2
  388. #define CRYPT_SGC_ENUM 4
  389. #define CRYPT_IMPL_HARDWARE 1
  390. #define CRYPT_IMPL_SOFTWARE 2
  391. #define CRYPT_IMPL_MIXED 3
  392. #define CRYPT_IMPL_UNKNOWN 4
  393. #define CRYPT_IMPL_REMOVABLE 8
  394. // key storage flags
  395. #define CRYPT_SEC_DESCR 0x00000001
  396. #define CRYPT_PSTORE 0x00000002
  397. #define CRYPT_UI_PROMPT 0x00000004
  398. // protocol flags
  399. #define CRYPT_FLAG_PCT1 0x0001
  400. #define CRYPT_FLAG_SSL2 0x0002
  401. #define CRYPT_FLAG_SSL3 0x0004
  402. #define CRYPT_FLAG_TLS1 0x0008
  403. #define CRYPT_FLAG_IPSEC 0x0010
  404. #define CRYPT_FLAG_SIGNING 0x0020
  405. // SGC flags
  406. #define CRYPT_SGC 0x0001
  407. #define CRYPT_FASTSGC 0x0002
  408. //
  409. // CryptSetProvParam
  410. //
  411. #define PP_CLIENT_HWND 1
  412. #define PP_CONTEXT_INFO 11
  413. #define PP_KEYEXCHANGE_KEYSIZE 12
  414. #define PP_SIGNATURE_KEYSIZE 13
  415. #define PP_KEYEXCHANGE_ALG 14
  416. #define PP_SIGNATURE_ALG 15
  417. #define PP_DELETEKEY 24
  418. #define PROV_RSA_FULL 1
  419. #define PROV_RSA_SIG 2
  420. #define PROV_DSS 3
  421. #define PROV_FORTEZZA 4
  422. #define PROV_MS_EXCHANGE 5
  423. #define PROV_SSL 6
  424. #define PROV_RSA_SCHANNEL 12
  425. #define PROV_DSS_DH 13
  426. #define PROV_EC_ECDSA_SIG 14
  427. #define PROV_EC_ECNRA_SIG 15
  428. #define PROV_EC_ECDSA_FULL 16
  429. #define PROV_EC_ECNRA_FULL 17
  430. #define PROV_DH_SCHANNEL 18
  431. #define PROV_SPYRUS_LYNKS 20
  432. #define PROV_RNG 21
  433. #define PROV_INTEL_SEC 22
  434. #define PROV_REPLACE_OWF 23
  435. #define PROV_RSA_AES 24
  436. //
  437. // Provider friendly names
  438. //
  439. #define MS_DEF_PROV_A "Microsoft Base Cryptographic Provider v1.0"
  440. #define MS_DEF_PROV_W L"Microsoft Base Cryptographic Provider v1.0"
  441. #ifdef UNICODE
  442. #define MS_DEF_PROV MS_DEF_PROV_W
  443. #else
  444. #define MS_DEF_PROV MS_DEF_PROV_A
  445. #endif
  446. #define MS_ENHANCED_PROV_A "Microsoft Enhanced Cryptographic Provider v1.0"
  447. #define MS_ENHANCED_PROV_W L"Microsoft Enhanced Cryptographic Provider v1.0"
  448. #ifdef UNICODE
  449. #define MS_ENHANCED_PROV MS_ENHANCED_PROV_W
  450. #else
  451. #define MS_ENHANCED_PROV MS_ENHANCED_PROV_A
  452. #endif
  453. #define MS_STRONG_PROV_A "Microsoft Strong Cryptographic Provider"
  454. #define MS_STRONG_PROV_W L"Microsoft Strong Cryptographic Provider"
  455. #ifdef UNICODE
  456. #define MS_STRONG_PROV MS_STRONG_PROV_W
  457. #else
  458. #define MS_STRONG_PROV MS_STRONG_PROV_A
  459. #endif
  460. #define MS_DEF_RSA_SIG_PROV_A "Microsoft RSA Signature Cryptographic Provider"
  461. #define MS_DEF_RSA_SIG_PROV_W L"Microsoft RSA Signature Cryptographic Provider"
  462. #ifdef UNICODE
  463. #define MS_DEF_RSA_SIG_PROV MS_DEF_RSA_SIG_PROV_W
  464. #else
  465. #define MS_DEF_RSA_SIG_PROV MS_DEF_RSA_SIG_PROV_A
  466. #endif
  467. #define MS_DEF_RSA_SCHANNEL_PROV_A "Microsoft RSA SChannel Cryptographic Provider"
  468. #define MS_DEF_RSA_SCHANNEL_PROV_W L"Microsoft RSA SChannel Cryptographic Provider"
  469. #ifdef UNICODE
  470. #define MS_DEF_RSA_SCHANNEL_PROV MS_DEF_RSA_SCHANNEL_PROV_W
  471. #else
  472. #define MS_DEF_RSA_SCHANNEL_PROV MS_DEF_RSA_SCHANNEL_PROV_A
  473. #endif
  474. #define MS_DEF_DSS_PROV_A "Microsoft Base DSS Cryptographic Provider"
  475. #define MS_DEF_DSS_PROV_W L"Microsoft Base DSS Cryptographic Provider"
  476. #ifdef UNICODE
  477. #define MS_DEF_DSS_PROV MS_DEF_DSS_PROV_W
  478. #else
  479. #define MS_DEF_DSS_PROV MS_DEF_DSS_PROV_A
  480. #endif
  481. #define MS_DEF_DSS_DH_PROV_A "Microsoft Base DSS and Diffie-Hellman Cryptographic Provider"
  482. #define MS_DEF_DSS_DH_PROV_W L"Microsoft Base DSS and Diffie-Hellman Cryptographic Provider"
  483. #ifdef UNICODE
  484. #define MS_DEF_DSS_DH_PROV MS_DEF_DSS_DH_PROV_W
  485. #else
  486. #define MS_DEF_DSS_DH_PROV MS_DEF_DSS_DH_PROV_A
  487. #endif
  488. #define MS_ENH_DSS_DH_PROV_A "Microsoft Enhanced DSS and Diffie-Hellman Cryptographic Provider"
  489. #define MS_ENH_DSS_DH_PROV_W L"Microsoft Enhanced DSS and Diffie-Hellman Cryptographic Provider"
  490. #ifdef UNICODE
  491. #define MS_ENH_DSS_DH_PROV MS_ENH_DSS_DH_PROV_W
  492. #else
  493. #define MS_ENH_DSS_DH_PROV MS_ENH_DSS_DH_PROV_A
  494. #endif
  495. #define MS_DEF_DH_SCHANNEL_PROV_A "Microsoft DH SChannel Cryptographic Provider"
  496. #define MS_DEF_DH_SCHANNEL_PROV_W L"Microsoft DH SChannel Cryptographic Provider"
  497. #ifdef UNICODE
  498. #define MS_DEF_DH_SCHANNEL_PROV MS_DEF_DH_SCHANNEL_PROV_W
  499. #else
  500. #define MS_DEF_DH_SCHANNEL_PROV MS_DEF_DH_SCHANNEL_PROV_A
  501. #endif
  502. #define MS_SCARD_PROV_A "Microsoft Base Smart Card Crypto Provider"
  503. #define MS_SCARD_PROV_W L"Microsoft Base Smart Card Crypto Provider"
  504. #ifdef UNICODE
  505. #define MS_SCARD_PROV MS_SCARD_PROV_W
  506. #else
  507. #define MS_SCARD_PROV MS_SCARD_PROV_A
  508. #endif
  509. #define MS_ENH_RSA_AES_PROV_A "Microsoft Enhanced RSA and AES Cryptographic Provider"
  510. #define MS_ENH_RSA_AES_PROV_W L"Microsoft Enhanced RSA and AES Cryptographic Provider"
  511. #ifdef UNICODE
  512. #define MS_ENH_RSA_AES_PROV MS_ENH_RSA_AES_PROV_W
  513. #else
  514. #define MS_ENH_RSA_AES_PROV MS_ENH_RSA_AES_PROV_A
  515. #endif
  516. #define MAXUIDLEN 64
  517. // Exponentiation Offload Reg Location
  518. #define EXPO_OFFLOAD_REG_VALUE "ExpoOffload"
  519. #define EXPO_OFFLOAD_FUNC_NAME "OffloadModExpo"
  520. //
  521. // Registry key in which the following private key-related
  522. // values are created.
  523. //
  524. #define szKEY_CRYPTOAPI_PRIVATE_KEY_OPTIONS \
  525. "Software\\Policies\\Microsoft\\Cryptography"
  526. //
  527. // Registry value for controlling Data Protection API (DPAPI) UI settings.
  528. //
  529. #define szFORCE_KEY_PROTECTION "ForceKeyProtection"
  530. #define dwFORCE_KEY_PROTECTION_DISABLED 0x0
  531. #define dwFORCE_KEY_PROTECTION_USER_SELECT 0x1
  532. #define dwFORCE_KEY_PROTECTION_HIGH 0x2
  533. //
  534. // Registry values for enabling and controlling the caching (and timeout)
  535. // of private keys. This feature is useful only for UI-protected private
  536. // keys.
  537. //
  538. // Note that in Windows 2000 and later, private keys, once read from storage,
  539. // are cached in the associated HCRYPTPROV structure for subsequent use.
  540. //
  541. // In Server 2003 and XP SP1, new key caching behavior is available. Keys
  542. // that have been read from storage and cached may now be considered "stale"
  543. // if a period of time has elapsed since the key was last used. This forces
  544. // the key to be re-read from storage (which will make the DPAPI UI appear
  545. // again).
  546. //
  547. // To enable the new behavior, create the registry DWORD value
  548. // szKEY_CACHE_ENABLED and set it to 1. The registry DWORD value
  549. // szKEY_CACHE_SECONDS must also be created and set to the number of seconds
  550. // that a cached private key may still be considered usable.
  551. //
  552. #define szKEY_CACHE_ENABLED "CachePrivateKeys"
  553. #define szKEY_CACHE_SECONDS "PrivateKeyLifetimeSeconds"
  554. #define CUR_BLOB_VERSION 2
  555. // structure for use with CryptSetKeyParam for CMS keys
  556. // DO NOT USE THIS STRUCTURE!!!!!
  557. typedef struct _CMS_KEY_INFO {
  558. DWORD dwVersion; // sizeof(CMS_KEY_INFO)
  559. ALG_ID Algid; // algorithmm id for the key to be converted
  560. BYTE *pbOID; // pointer to OID to hash in with Z
  561. DWORD cbOID; // length of OID to hash in with Z
  562. } CMS_KEY_INFO, *PCMS_KEY_INFO;
  563. // structure for use with CryptSetHashParam with CALG_HMAC
  564. typedef struct _HMAC_Info {
  565. ALG_ID HashAlgid;
  566. BYTE *pbInnerString;
  567. DWORD cbInnerString;
  568. BYTE *pbOuterString;
  569. DWORD cbOuterString;
  570. } HMAC_INFO, *PHMAC_INFO;
  571. // structure for use with CryptSetKeyParam with KP_SCHANNEL_ALG
  572. typedef struct _SCHANNEL_ALG {
  573. DWORD dwUse;
  574. ALG_ID Algid;
  575. DWORD cBits;
  576. DWORD dwFlags;
  577. DWORD dwReserved;
  578. } SCHANNEL_ALG, *PSCHANNEL_ALG;
  579. // uses of algortihms for SCHANNEL_ALG structure
  580. #define SCHANNEL_MAC_KEY 0x00000000
  581. #define SCHANNEL_ENC_KEY 0x00000001
  582. // uses of dwFlags SCHANNEL_ALG structure
  583. #define INTERNATIONAL_USAGE 0x00000001
  584. typedef struct _PROV_ENUMALGS {
  585. ALG_ID aiAlgid;
  586. DWORD dwBitLen;
  587. DWORD dwNameLen;
  588. CHAR szName[20];
  589. } PROV_ENUMALGS;
  590. typedef struct _PROV_ENUMALGS_EX {
  591. ALG_ID aiAlgid;
  592. DWORD dwDefaultLen;
  593. DWORD dwMinLen;
  594. DWORD dwMaxLen;
  595. DWORD dwProtocols;
  596. DWORD dwNameLen;
  597. CHAR szName[20];
  598. DWORD dwLongNameLen;
  599. CHAR szLongName[40];
  600. } PROV_ENUMALGS_EX;
  601. typedef struct _PUBLICKEYSTRUC {
  602. BYTE bType;
  603. BYTE bVersion;
  604. WORD reserved;
  605. ALG_ID aiKeyAlg;
  606. } BLOBHEADER, PUBLICKEYSTRUC;
  607. typedef struct _RSAPUBKEY {
  608. DWORD magic; // Has to be RSA1
  609. DWORD bitlen; // # of bits in modulus
  610. DWORD pubexp; // public exponent
  611. // Modulus data follows
  612. } RSAPUBKEY;
  613. typedef struct _PUBKEY {
  614. DWORD magic;
  615. DWORD bitlen; // # of bits in modulus
  616. } DHPUBKEY, DSSPUBKEY, KEAPUBKEY, TEKPUBKEY;
  617. typedef struct _DSSSEED {
  618. DWORD counter;
  619. BYTE seed[20];
  620. } DSSSEED;
  621. typedef struct _PUBKEYVER3 {
  622. DWORD magic;
  623. DWORD bitlenP; // # of bits in prime modulus
  624. DWORD bitlenQ; // # of bits in prime q, 0 if not available
  625. DWORD bitlenJ; // # of bits in (p-1)/q, 0 if not available
  626. DSSSEED DSSSeed;
  627. } DHPUBKEY_VER3, DSSPUBKEY_VER3;
  628. typedef struct _PRIVKEYVER3 {
  629. DWORD magic;
  630. DWORD bitlenP; // # of bits in prime modulus
  631. DWORD bitlenQ; // # of bits in prime q, 0 if not available
  632. DWORD bitlenJ; // # of bits in (p-1)/q, 0 if not available
  633. DWORD bitlenX; // # of bits in X
  634. DSSSEED DSSSeed;
  635. } DHPRIVKEY_VER3, DSSPRIVKEY_VER3;
  636. typedef struct _KEY_TYPE_SUBTYPE {
  637. DWORD dwKeySpec;
  638. GUID Type;
  639. GUID Subtype;
  640. } KEY_TYPE_SUBTYPE, *PKEY_TYPE_SUBTYPE;
  641. typedef struct _CERT_FORTEZZA_DATA_PROP {
  642. unsigned char SerialNumber[8];
  643. int CertIndex;
  644. unsigned char CertLabel[36];
  645. } CERT_FORTEZZA_DATA_PROP;
  646. //+-------------------------------------------------------------------------
  647. // CRYPTOAPI BLOB definitions
  648. //--------------------------------------------------------------------------
  649. typedef struct _CRYPTOAPI_BLOB {
  650. DWORD cbData;
  651. BYTE *pbData;
  652. } CRYPT_INTEGER_BLOB, *PCRYPT_INTEGER_BLOB,
  653. CRYPT_UINT_BLOB, *PCRYPT_UINT_BLOB,
  654. CRYPT_OBJID_BLOB, *PCRYPT_OBJID_BLOB,
  655. CERT_NAME_BLOB, *PCERT_NAME_BLOB,
  656. CERT_RDN_VALUE_BLOB, *PCERT_RDN_VALUE_BLOB,
  657. CERT_BLOB, *PCERT_BLOB,
  658. CRL_BLOB, *PCRL_BLOB,
  659. DATA_BLOB, *PDATA_BLOB,
  660. CRYPT_DATA_BLOB, *PCRYPT_DATA_BLOB,
  661. CRYPT_HASH_BLOB, *PCRYPT_HASH_BLOB,
  662. CRYPT_DIGEST_BLOB, *PCRYPT_DIGEST_BLOB,
  663. CRYPT_DER_BLOB, *PCRYPT_DER_BLOB,
  664. CRYPT_ATTR_BLOB, *PCRYPT_ATTR_BLOB;
  665. // structure for use with CryptSetKeyParam for CMS keys
  666. typedef struct _CMS_DH_KEY_INFO {
  667. DWORD dwVersion; // sizeof(CMS_DH_KEY_INFO)
  668. ALG_ID Algid; // algorithmm id for the key to be converted
  669. LPSTR pszContentEncObjId; // pointer to OID to hash in with Z
  670. CRYPT_DATA_BLOB PubInfo; // OPTIONAL - public information
  671. void *pReserved; // reserved - should be NULL
  672. } CMS_DH_KEY_INFO, *PCMS_DH_KEY_INFO;
  673. WINADVAPI
  674. BOOL
  675. WINAPI
  676. CryptAcquireContextA(
  677. HCRYPTPROV *phProv,
  678. LPCSTR szContainer,
  679. LPCSTR szProvider,
  680. DWORD dwProvType,
  681. DWORD dwFlags
  682. );
  683. WINADVAPI
  684. BOOL
  685. WINAPI
  686. CryptAcquireContextW(
  687. HCRYPTPROV *phProv,
  688. LPCWSTR szContainer,
  689. LPCWSTR szProvider,
  690. DWORD dwProvType,
  691. DWORD dwFlags
  692. );
  693. #ifdef UNICODE
  694. #define CryptAcquireContext CryptAcquireContextW
  695. #else
  696. #define CryptAcquireContext CryptAcquireContextA
  697. #endif // !UNICODE
  698. WINADVAPI
  699. BOOL
  700. WINAPI
  701. CryptReleaseContext(
  702. HCRYPTPROV hProv,
  703. DWORD dwFlags
  704. );
  705. WINADVAPI
  706. BOOL
  707. WINAPI
  708. CryptGenKey(
  709. HCRYPTPROV hProv,
  710. ALG_ID Algid,
  711. DWORD dwFlags,
  712. HCRYPTKEY *phKey
  713. );
  714. WINADVAPI
  715. BOOL
  716. WINAPI
  717. CryptDeriveKey(
  718. HCRYPTPROV hProv,
  719. ALG_ID Algid,
  720. HCRYPTHASH hBaseData,
  721. DWORD dwFlags,
  722. HCRYPTKEY *phKey
  723. );
  724. WINADVAPI
  725. BOOL
  726. WINAPI
  727. CryptDestroyKey(
  728. HCRYPTKEY hKey
  729. );
  730. WINADVAPI
  731. BOOL
  732. WINAPI
  733. CryptSetKeyParam(
  734. HCRYPTKEY hKey,
  735. DWORD dwParam,
  736. CONST BYTE *pbData,
  737. DWORD dwFlags
  738. );
  739. WINADVAPI
  740. BOOL
  741. WINAPI
  742. CryptGetKeyParam(
  743. HCRYPTKEY hKey,
  744. DWORD dwParam,
  745. BYTE *pbData,
  746. DWORD *pdwDataLen,
  747. DWORD dwFlags
  748. );
  749. WINADVAPI
  750. BOOL
  751. WINAPI
  752. CryptSetHashParam(
  753. HCRYPTHASH hHash,
  754. DWORD dwParam,
  755. CONST BYTE *pbData,
  756. DWORD dwFlags
  757. );
  758. WINADVAPI
  759. BOOL
  760. WINAPI
  761. CryptGetHashParam(
  762. HCRYPTHASH hHash,
  763. DWORD dwParam,
  764. BYTE *pbData,
  765. DWORD *pdwDataLen,
  766. DWORD dwFlags
  767. );
  768. WINADVAPI
  769. BOOL
  770. WINAPI
  771. CryptSetProvParam(
  772. HCRYPTPROV hProv,
  773. DWORD dwParam,
  774. CONST BYTE *pbData,
  775. DWORD dwFlags
  776. );
  777. WINADVAPI
  778. BOOL
  779. WINAPI
  780. CryptGetProvParam(
  781. HCRYPTPROV hProv,
  782. DWORD dwParam,
  783. BYTE *pbData,
  784. DWORD *pdwDataLen,
  785. DWORD dwFlags
  786. );
  787. WINADVAPI
  788. BOOL
  789. WINAPI
  790. CryptGenRandom(
  791. HCRYPTPROV hProv,
  792. DWORD dwLen,
  793. BYTE *pbBuffer
  794. );
  795. WINADVAPI
  796. BOOL
  797. WINAPI
  798. CryptGetUserKey(
  799. HCRYPTPROV hProv,
  800. DWORD dwKeySpec,
  801. HCRYPTKEY *phUserKey
  802. );
  803. WINADVAPI
  804. BOOL
  805. WINAPI
  806. CryptExportKey(
  807. HCRYPTKEY hKey,
  808. HCRYPTKEY hExpKey,
  809. DWORD dwBlobType,
  810. DWORD dwFlags,
  811. BYTE *pbData,
  812. DWORD *pdwDataLen
  813. );
  814. WINADVAPI
  815. BOOL
  816. WINAPI
  817. CryptImportKey(
  818. HCRYPTPROV hProv,
  819. CONST BYTE *pbData,
  820. DWORD dwDataLen,
  821. HCRYPTKEY hPubKey,
  822. DWORD dwFlags,
  823. HCRYPTKEY *phKey
  824. );
  825. WINADVAPI
  826. BOOL
  827. WINAPI
  828. CryptEncrypt(
  829. HCRYPTKEY hKey,
  830. HCRYPTHASH hHash,
  831. BOOL Final,
  832. DWORD dwFlags,
  833. BYTE *pbData,
  834. DWORD *pdwDataLen,
  835. DWORD dwBufLen
  836. );
  837. WINADVAPI
  838. BOOL
  839. WINAPI
  840. CryptDecrypt(
  841. HCRYPTKEY hKey,
  842. HCRYPTHASH hHash,
  843. BOOL Final,
  844. DWORD dwFlags,
  845. BYTE *pbData,
  846. DWORD *pdwDataLen
  847. );
  848. WINADVAPI
  849. BOOL
  850. WINAPI
  851. CryptCreateHash(
  852. HCRYPTPROV hProv,
  853. ALG_ID Algid,
  854. HCRYPTKEY hKey,
  855. DWORD dwFlags,
  856. HCRYPTHASH *phHash
  857. );
  858. WINADVAPI
  859. BOOL
  860. WINAPI
  861. CryptHashData(
  862. HCRYPTHASH hHash,
  863. CONST BYTE *pbData,
  864. DWORD dwDataLen,
  865. DWORD dwFlags
  866. );
  867. WINADVAPI
  868. BOOL
  869. WINAPI
  870. CryptHashSessionKey(
  871. HCRYPTHASH hHash,
  872. HCRYPTKEY hKey,
  873. DWORD dwFlags
  874. );
  875. WINADVAPI
  876. BOOL
  877. WINAPI
  878. CryptDestroyHash(
  879. HCRYPTHASH hHash
  880. );
  881. WINADVAPI
  882. BOOL
  883. WINAPI
  884. CryptSignHashA(
  885. HCRYPTHASH hHash,
  886. DWORD dwKeySpec,
  887. LPCSTR szDescription,
  888. DWORD dwFlags,
  889. BYTE *pbSignature,
  890. DWORD *pdwSigLen
  891. );
  892. WINADVAPI
  893. BOOL
  894. WINAPI
  895. CryptSignHashW(
  896. HCRYPTHASH hHash,
  897. DWORD dwKeySpec,
  898. LPCWSTR szDescription,
  899. DWORD dwFlags,
  900. BYTE *pbSignature,
  901. DWORD *pdwSigLen
  902. );
  903. #ifdef UNICODE
  904. #define CryptSignHash CryptSignHashW
  905. #else
  906. #define CryptSignHash CryptSignHashA
  907. #endif // !UNICODE
  908. WINADVAPI
  909. BOOL
  910. WINAPI
  911. CryptVerifySignatureA(
  912. HCRYPTHASH hHash,
  913. CONST BYTE *pbSignature,
  914. DWORD dwSigLen,
  915. HCRYPTKEY hPubKey,
  916. LPCSTR szDescription,
  917. DWORD dwFlags
  918. );
  919. WINADVAPI
  920. BOOL
  921. WINAPI
  922. CryptVerifySignatureW(
  923. HCRYPTHASH hHash,
  924. CONST BYTE *pbSignature,
  925. DWORD dwSigLen,
  926. HCRYPTKEY hPubKey,
  927. LPCWSTR szDescription,
  928. DWORD dwFlags
  929. );
  930. #ifdef UNICODE
  931. #define CryptVerifySignature CryptVerifySignatureW
  932. #else
  933. #define CryptVerifySignature CryptVerifySignatureA
  934. #endif // !UNICODE
  935. WINADVAPI
  936. BOOL
  937. WINAPI
  938. CryptSetProviderA(
  939. LPCSTR pszProvName,
  940. DWORD dwProvType
  941. );
  942. WINADVAPI
  943. BOOL
  944. WINAPI
  945. CryptSetProviderW(
  946. LPCWSTR pszProvName,
  947. DWORD dwProvType
  948. );
  949. #ifdef UNICODE
  950. #define CryptSetProvider CryptSetProviderW
  951. #else
  952. #define CryptSetProvider CryptSetProviderA
  953. #endif // !UNICODE
  954. WINADVAPI
  955. BOOL
  956. WINAPI
  957. CryptSetProviderExA(
  958. LPCSTR pszProvName,
  959. DWORD dwProvType,
  960. DWORD *pdwReserved,
  961. DWORD dwFlags
  962. );
  963. WINADVAPI
  964. BOOL
  965. WINAPI
  966. CryptSetProviderExW(
  967. LPCWSTR pszProvName,
  968. DWORD dwProvType,
  969. DWORD *pdwReserved,
  970. DWORD dwFlags
  971. );
  972. #ifdef UNICODE
  973. #define CryptSetProviderEx CryptSetProviderExW
  974. #else
  975. #define CryptSetProviderEx CryptSetProviderExA
  976. #endif // !UNICODE
  977. WINADVAPI
  978. BOOL
  979. WINAPI
  980. CryptGetDefaultProviderA(
  981. DWORD dwProvType,
  982. DWORD *pdwReserved,
  983. DWORD dwFlags,
  984. LPSTR pszProvName,
  985. DWORD *pcbProvName
  986. );
  987. WINADVAPI
  988. BOOL
  989. WINAPI
  990. CryptGetDefaultProviderW(
  991. DWORD dwProvType,
  992. DWORD *pdwReserved,
  993. DWORD dwFlags,
  994. LPWSTR pszProvName,
  995. DWORD *pcbProvName
  996. );
  997. #ifdef UNICODE
  998. #define CryptGetDefaultProvider CryptGetDefaultProviderW
  999. #else
  1000. #define CryptGetDefaultProvider CryptGetDefaultProviderA
  1001. #endif // !UNICODE
  1002. WINADVAPI
  1003. BOOL
  1004. WINAPI
  1005. CryptEnumProviderTypesA(
  1006. DWORD dwIndex,
  1007. DWORD *pdwReserved,
  1008. DWORD dwFlags,
  1009. DWORD *pdwProvType,
  1010. LPSTR szTypeName,
  1011. DWORD *pcbTypeName
  1012. );
  1013. WINADVAPI
  1014. BOOL
  1015. WINAPI
  1016. CryptEnumProviderTypesW(
  1017. DWORD dwIndex,
  1018. DWORD *pdwReserved,
  1019. DWORD dwFlags,
  1020. DWORD *pdwProvType,
  1021. LPWSTR szTypeName,
  1022. DWORD *pcbTypeName
  1023. );
  1024. #ifdef UNICODE
  1025. #define CryptEnumProviderTypes CryptEnumProviderTypesW
  1026. #else
  1027. #define CryptEnumProviderTypes CryptEnumProviderTypesA
  1028. #endif // !UNICODE
  1029. WINADVAPI
  1030. BOOL
  1031. WINAPI
  1032. CryptEnumProvidersA(
  1033. DWORD dwIndex,
  1034. DWORD *pdwReserved,
  1035. DWORD dwFlags,
  1036. DWORD *pdwProvType,
  1037. LPSTR szProvName,
  1038. DWORD *pcbProvName
  1039. );
  1040. WINADVAPI
  1041. BOOL
  1042. WINAPI
  1043. CryptEnumProvidersW(
  1044. DWORD dwIndex,
  1045. DWORD *pdwReserved,
  1046. DWORD dwFlags,
  1047. DWORD *pdwProvType,
  1048. LPWSTR szProvName,
  1049. DWORD *pcbProvName
  1050. );
  1051. #ifdef UNICODE
  1052. #define CryptEnumProviders CryptEnumProvidersW
  1053. #else
  1054. #define CryptEnumProviders CryptEnumProvidersA
  1055. #endif // !UNICODE
  1056. WINADVAPI
  1057. BOOL
  1058. WINAPI
  1059. CryptContextAddRef(
  1060. HCRYPTPROV hProv,
  1061. DWORD *pdwReserved,
  1062. DWORD dwFlags
  1063. );
  1064. WINADVAPI
  1065. BOOL
  1066. WINAPI
  1067. CryptDuplicateKey(
  1068. HCRYPTKEY hKey,
  1069. DWORD *pdwReserved,
  1070. DWORD dwFlags,
  1071. HCRYPTKEY *phKey
  1072. );
  1073. WINADVAPI
  1074. BOOL
  1075. WINAPI
  1076. CryptDuplicateHash(
  1077. HCRYPTHASH hHash,
  1078. DWORD *pdwReserved,
  1079. DWORD dwFlags,
  1080. HCRYPTHASH *phHash
  1081. );
  1082. //
  1083. // This function is provided in Microsoft Windows 2000 as a means of
  1084. // installing the 128-bit encryption provider. This function is unavailable
  1085. // in Microsoft Windows XP, because Windows XP ships with the 128-bit
  1086. // encryption provider.
  1087. //
  1088. BOOL
  1089. __cdecl
  1090. GetEncSChannel(
  1091. BYTE **pData,
  1092. DWORD *dwDecSize
  1093. );
  1094. //+-------------------------------------------------------------------------
  1095. // In a CRYPT_BIT_BLOB the last byte may contain 0-7 unused bits. Therefore, the
  1096. // overall bit length is cbData * 8 - cUnusedBits.
  1097. //--------------------------------------------------------------------------
  1098. typedef struct _CRYPT_BIT_BLOB {
  1099. DWORD cbData;
  1100. BYTE *pbData;
  1101. DWORD cUnusedBits;
  1102. } CRYPT_BIT_BLOB, *PCRYPT_BIT_BLOB;
  1103. //+-------------------------------------------------------------------------
  1104. // Type used for any algorithm
  1105. //
  1106. // Where the Parameters CRYPT_OBJID_BLOB is in its encoded representation. For most
  1107. // algorithm types, the Parameters CRYPT_OBJID_BLOB is NULL (Parameters.cbData = 0).
  1108. //--------------------------------------------------------------------------
  1109. typedef struct _CRYPT_ALGORITHM_IDENTIFIER {
  1110. LPSTR pszObjId;
  1111. CRYPT_OBJID_BLOB Parameters;
  1112. } CRYPT_ALGORITHM_IDENTIFIER, *PCRYPT_ALGORITHM_IDENTIFIER;
  1113. // Following are the definitions of various algorithm object identifiers
  1114. // RSA
  1115. #define szOID_RSA "1.2.840.113549"
  1116. #define szOID_PKCS "1.2.840.113549.1"
  1117. #define szOID_RSA_HASH "1.2.840.113549.2"
  1118. #define szOID_RSA_ENCRYPT "1.2.840.113549.3"
  1119. #define szOID_PKCS_1 "1.2.840.113549.1.1"
  1120. #define szOID_PKCS_2 "1.2.840.113549.1.2"
  1121. #define szOID_PKCS_3 "1.2.840.113549.1.3"
  1122. #define szOID_PKCS_4 "1.2.840.113549.1.4"
  1123. #define szOID_PKCS_5 "1.2.840.113549.1.5"
  1124. #define szOID_PKCS_6 "1.2.840.113549.1.6"
  1125. #define szOID_PKCS_7 "1.2.840.113549.1.7"
  1126. #define szOID_PKCS_8 "1.2.840.113549.1.8"
  1127. #define szOID_PKCS_9 "1.2.840.113549.1.9"
  1128. #define szOID_PKCS_10 "1.2.840.113549.1.10"
  1129. #define szOID_PKCS_12 "1.2.840.113549.1.12"
  1130. #define szOID_RSA_RSA "1.2.840.113549.1.1.1"
  1131. #define szOID_RSA_MD2RSA "1.2.840.113549.1.1.2"
  1132. #define szOID_RSA_MD4RSA "1.2.840.113549.1.1.3"
  1133. #define szOID_RSA_MD5RSA "1.2.840.113549.1.1.4"
  1134. #define szOID_RSA_SHA1RSA "1.2.840.113549.1.1.5"
  1135. #define szOID_RSA_SETOAEP_RSA "1.2.840.113549.1.1.6"
  1136. #define szOID_RSA_DH "1.2.840.113549.1.3.1"
  1137. #define szOID_RSA_data "1.2.840.113549.1.7.1"
  1138. #define szOID_RSA_signedData "1.2.840.113549.1.7.2"
  1139. #define szOID_RSA_envelopedData "1.2.840.113549.1.7.3"
  1140. #define szOID_RSA_signEnvData "1.2.840.113549.1.7.4"
  1141. #define szOID_RSA_digestedData "1.2.840.113549.1.7.5"
  1142. #define szOID_RSA_hashedData "1.2.840.113549.1.7.5"
  1143. #define szOID_RSA_encryptedData "1.2.840.113549.1.7.6"
  1144. #define szOID_RSA_emailAddr "1.2.840.113549.1.9.1"
  1145. #define szOID_RSA_unstructName "1.2.840.113549.1.9.2"
  1146. #define szOID_RSA_contentType "1.2.840.113549.1.9.3"
  1147. #define szOID_RSA_messageDigest "1.2.840.113549.1.9.4"
  1148. #define szOID_RSA_signingTime "1.2.840.113549.1.9.5"
  1149. #define szOID_RSA_counterSign "1.2.840.113549.1.9.6"
  1150. #define szOID_RSA_challengePwd "1.2.840.113549.1.9.7"
  1151. #define szOID_RSA_unstructAddr "1.2.840.113549.1.9.8"
  1152. #define szOID_RSA_extCertAttrs "1.2.840.113549.1.9.9"
  1153. #define szOID_RSA_certExtensions "1.2.840.113549.1.9.14"
  1154. #define szOID_RSA_SMIMECapabilities "1.2.840.113549.1.9.15"
  1155. #define szOID_RSA_preferSignedData "1.2.840.113549.1.9.15.1"
  1156. #define szOID_RSA_SMIMEalg "1.2.840.113549.1.9.16.3"
  1157. #define szOID_RSA_SMIMEalgESDH "1.2.840.113549.1.9.16.3.5"
  1158. #define szOID_RSA_SMIMEalgCMS3DESwrap "1.2.840.113549.1.9.16.3.6"
  1159. #define szOID_RSA_SMIMEalgCMSRC2wrap "1.2.840.113549.1.9.16.3.7"
  1160. #define szOID_RSA_MD2 "1.2.840.113549.2.2"
  1161. #define szOID_RSA_MD4 "1.2.840.113549.2.4"
  1162. #define szOID_RSA_MD5 "1.2.840.113549.2.5"
  1163. #define szOID_RSA_RC2CBC "1.2.840.113549.3.2"
  1164. #define szOID_RSA_RC4 "1.2.840.113549.3.4"
  1165. #define szOID_RSA_DES_EDE3_CBC "1.2.840.113549.3.7"
  1166. #define szOID_RSA_RC5_CBCPad "1.2.840.113549.3.9"
  1167. #define szOID_ANSI_X942 "1.2.840.10046"
  1168. #define szOID_ANSI_X942_DH "1.2.840.10046.2.1"
  1169. #define szOID_X957 "1.2.840.10040"
  1170. #define szOID_X957_DSA "1.2.840.10040.4.1"
  1171. #define szOID_X957_SHA1DSA "1.2.840.10040.4.3"
  1172. // ITU-T UsefulDefinitions
  1173. #define szOID_DS "2.5"
  1174. #define szOID_DSALG "2.5.8"
  1175. #define szOID_DSALG_CRPT "2.5.8.1"
  1176. #define szOID_DSALG_HASH "2.5.8.2"
  1177. #define szOID_DSALG_SIGN "2.5.8.3"
  1178. #define szOID_DSALG_RSA "2.5.8.1.1"
  1179. // NIST OSE Implementors' Workshop (OIW)
  1180. // http://nemo.ncsl.nist.gov/oiw/agreements/stable/OSI/12s_9506.w51
  1181. // http://nemo.ncsl.nist.gov/oiw/agreements/working/OSI/12w_9503.w51
  1182. #define szOID_OIW "1.3.14"
  1183. // NIST OSE Implementors' Workshop (OIW) Security SIG algorithm identifiers
  1184. #define szOID_OIWSEC "1.3.14.3.2"
  1185. #define szOID_OIWSEC_md4RSA "1.3.14.3.2.2"
  1186. #define szOID_OIWSEC_md5RSA "1.3.14.3.2.3"
  1187. #define szOID_OIWSEC_md4RSA2 "1.3.14.3.2.4"
  1188. #define szOID_OIWSEC_desECB "1.3.14.3.2.6"
  1189. #define szOID_OIWSEC_desCBC "1.3.14.3.2.7"
  1190. #define szOID_OIWSEC_desOFB "1.3.14.3.2.8"
  1191. #define szOID_OIWSEC_desCFB "1.3.14.3.2.9"
  1192. #define szOID_OIWSEC_desMAC "1.3.14.3.2.10"
  1193. #define szOID_OIWSEC_rsaSign "1.3.14.3.2.11"
  1194. #define szOID_OIWSEC_dsa "1.3.14.3.2.12"
  1195. #define szOID_OIWSEC_shaDSA "1.3.14.3.2.13"
  1196. #define szOID_OIWSEC_mdc2RSA "1.3.14.3.2.14"
  1197. #define szOID_OIWSEC_shaRSA "1.3.14.3.2.15"
  1198. #define szOID_OIWSEC_dhCommMod "1.3.14.3.2.16"
  1199. #define szOID_OIWSEC_desEDE "1.3.14.3.2.17"
  1200. #define szOID_OIWSEC_sha "1.3.14.3.2.18"
  1201. #define szOID_OIWSEC_mdc2 "1.3.14.3.2.19"
  1202. #define szOID_OIWSEC_dsaComm "1.3.14.3.2.20"
  1203. #define szOID_OIWSEC_dsaCommSHA "1.3.14.3.2.21"
  1204. #define szOID_OIWSEC_rsaXchg "1.3.14.3.2.22"
  1205. #define szOID_OIWSEC_keyHashSeal "1.3.14.3.2.23"
  1206. #define szOID_OIWSEC_md2RSASign "1.3.14.3.2.24"
  1207. #define szOID_OIWSEC_md5RSASign "1.3.14.3.2.25"
  1208. #define szOID_OIWSEC_sha1 "1.3.14.3.2.26"
  1209. #define szOID_OIWSEC_dsaSHA1 "1.3.14.3.2.27"
  1210. #define szOID_OIWSEC_dsaCommSHA1 "1.3.14.3.2.28"
  1211. #define szOID_OIWSEC_sha1RSASign "1.3.14.3.2.29"
  1212. // NIST OSE Implementors' Workshop (OIW) Directory SIG algorithm identifiers
  1213. #define szOID_OIWDIR "1.3.14.7.2"
  1214. #define szOID_OIWDIR_CRPT "1.3.14.7.2.1"
  1215. #define szOID_OIWDIR_HASH "1.3.14.7.2.2"
  1216. #define szOID_OIWDIR_SIGN "1.3.14.7.2.3"
  1217. #define szOID_OIWDIR_md2 "1.3.14.7.2.2.1"
  1218. #define szOID_OIWDIR_md2RSA "1.3.14.7.2.3.1"
  1219. // INFOSEC Algorithms
  1220. // joint-iso-ccitt(2) country(16) us(840) organization(1) us-government(101) dod(2) id-infosec(1)
  1221. #define szOID_INFOSEC "2.16.840.1.101.2.1"
  1222. #define szOID_INFOSEC_sdnsSignature "2.16.840.1.101.2.1.1.1"
  1223. #define szOID_INFOSEC_mosaicSignature "2.16.840.1.101.2.1.1.2"
  1224. #define szOID_INFOSEC_sdnsConfidentiality "2.16.840.1.101.2.1.1.3"
  1225. #define szOID_INFOSEC_mosaicConfidentiality "2.16.840.1.101.2.1.1.4"
  1226. #define szOID_INFOSEC_sdnsIntegrity "2.16.840.1.101.2.1.1.5"
  1227. #define szOID_INFOSEC_mosaicIntegrity "2.16.840.1.101.2.1.1.6"
  1228. #define szOID_INFOSEC_sdnsTokenProtection "2.16.840.1.101.2.1.1.7"
  1229. #define szOID_INFOSEC_mosaicTokenProtection "2.16.840.1.101.2.1.1.8"
  1230. #define szOID_INFOSEC_sdnsKeyManagement "2.16.840.1.101.2.1.1.9"
  1231. #define szOID_INFOSEC_mosaicKeyManagement "2.16.840.1.101.2.1.1.10"
  1232. #define szOID_INFOSEC_sdnsKMandSig "2.16.840.1.101.2.1.1.11"
  1233. #define szOID_INFOSEC_mosaicKMandSig "2.16.840.1.101.2.1.1.12"
  1234. #define szOID_INFOSEC_SuiteASignature "2.16.840.1.101.2.1.1.13"
  1235. #define szOID_INFOSEC_SuiteAConfidentiality "2.16.840.1.101.2.1.1.14"
  1236. #define szOID_INFOSEC_SuiteAIntegrity "2.16.840.1.101.2.1.1.15"
  1237. #define szOID_INFOSEC_SuiteATokenProtection "2.16.840.1.101.2.1.1.16"
  1238. #define szOID_INFOSEC_SuiteAKeyManagement "2.16.840.1.101.2.1.1.17"
  1239. #define szOID_INFOSEC_SuiteAKMandSig "2.16.840.1.101.2.1.1.18"
  1240. #define szOID_INFOSEC_mosaicUpdatedSig "2.16.840.1.101.2.1.1.19"
  1241. #define szOID_INFOSEC_mosaicKMandUpdSig "2.16.840.1.101.2.1.1.20"
  1242. #define szOID_INFOSEC_mosaicUpdatedInteg "2.16.840.1.101.2.1.1.21"
  1243. typedef struct _CRYPT_OBJID_TABLE {
  1244. DWORD dwAlgId;
  1245. LPCSTR pszObjId;
  1246. } CRYPT_OBJID_TABLE, *PCRYPT_OBJID_TABLE;
  1247. //+-------------------------------------------------------------------------
  1248. // PKCS #1 HashInfo (DigestInfo)
  1249. //--------------------------------------------------------------------------
  1250. typedef struct _CRYPT_HASH_INFO {
  1251. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  1252. CRYPT_HASH_BLOB Hash;
  1253. } CRYPT_HASH_INFO, *PCRYPT_HASH_INFO;
  1254. //+-------------------------------------------------------------------------
  1255. // Type used for an extension to an encoded content
  1256. //
  1257. // Where the Value's CRYPT_OBJID_BLOB is in its encoded representation.
  1258. //--------------------------------------------------------------------------
  1259. typedef struct _CERT_EXTENSION {
  1260. LPSTR pszObjId;
  1261. BOOL fCritical;
  1262. CRYPT_OBJID_BLOB Value;
  1263. } CERT_EXTENSION, *PCERT_EXTENSION;
  1264. //+-------------------------------------------------------------------------
  1265. // AttributeTypeValue
  1266. //
  1267. // Where the Value's CRYPT_OBJID_BLOB is in its encoded representation.
  1268. //--------------------------------------------------------------------------
  1269. typedef struct _CRYPT_ATTRIBUTE_TYPE_VALUE {
  1270. LPSTR pszObjId;
  1271. CRYPT_OBJID_BLOB Value;
  1272. } CRYPT_ATTRIBUTE_TYPE_VALUE, *PCRYPT_ATTRIBUTE_TYPE_VALUE;
  1273. //+-------------------------------------------------------------------------
  1274. // Attributes
  1275. //
  1276. // Where the Value's PATTR_BLOBs are in their encoded representation.
  1277. //--------------------------------------------------------------------------
  1278. typedef struct _CRYPT_ATTRIBUTE {
  1279. LPSTR pszObjId;
  1280. DWORD cValue;
  1281. PCRYPT_ATTR_BLOB rgValue;
  1282. } CRYPT_ATTRIBUTE, *PCRYPT_ATTRIBUTE;
  1283. typedef struct _CRYPT_ATTRIBUTES {
  1284. IN DWORD cAttr;
  1285. IN PCRYPT_ATTRIBUTE rgAttr;
  1286. } CRYPT_ATTRIBUTES, *PCRYPT_ATTRIBUTES;
  1287. //+-------------------------------------------------------------------------
  1288. // Attributes making up a Relative Distinguished Name (CERT_RDN)
  1289. //
  1290. // The interpretation of the Value depends on the dwValueType.
  1291. // See below for a list of the types.
  1292. //--------------------------------------------------------------------------
  1293. typedef struct _CERT_RDN_ATTR {
  1294. LPSTR pszObjId;
  1295. DWORD dwValueType;
  1296. CERT_RDN_VALUE_BLOB Value;
  1297. } CERT_RDN_ATTR, *PCERT_RDN_ATTR;
  1298. //+-------------------------------------------------------------------------
  1299. // CERT_RDN attribute Object Identifiers
  1300. //--------------------------------------------------------------------------
  1301. // Labeling attribute types:
  1302. #define szOID_COMMON_NAME "2.5.4.3" // case-ignore string
  1303. #define szOID_SUR_NAME "2.5.4.4" // case-ignore string
  1304. #define szOID_DEVICE_SERIAL_NUMBER "2.5.4.5" // printable string
  1305. // Geographic attribute types:
  1306. #define szOID_COUNTRY_NAME "2.5.4.6" // printable 2char string
  1307. #define szOID_LOCALITY_NAME "2.5.4.7" // case-ignore string
  1308. #define szOID_STATE_OR_PROVINCE_NAME "2.5.4.8" // case-ignore string
  1309. #define szOID_STREET_ADDRESS "2.5.4.9" // case-ignore string
  1310. // Organizational attribute types:
  1311. #define szOID_ORGANIZATION_NAME "2.5.4.10" // case-ignore string
  1312. #define szOID_ORGANIZATIONAL_UNIT_NAME "2.5.4.11" // case-ignore string
  1313. #define szOID_TITLE "2.5.4.12" // case-ignore string
  1314. // Explanatory attribute types:
  1315. #define szOID_DESCRIPTION "2.5.4.13" // case-ignore string
  1316. #define szOID_SEARCH_GUIDE "2.5.4.14"
  1317. #define szOID_BUSINESS_CATEGORY "2.5.4.15" // case-ignore string
  1318. // Postal addressing attribute types:
  1319. #define szOID_POSTAL_ADDRESS "2.5.4.16"
  1320. #define szOID_POSTAL_CODE "2.5.4.17" // case-ignore string
  1321. #define szOID_POST_OFFICE_BOX "2.5.4.18" // case-ignore string
  1322. #define szOID_PHYSICAL_DELIVERY_OFFICE_NAME "2.5.4.19" // case-ignore string
  1323. // Telecommunications addressing attribute types:
  1324. #define szOID_TELEPHONE_NUMBER "2.5.4.20" // telephone number
  1325. #define szOID_TELEX_NUMBER "2.5.4.21"
  1326. #define szOID_TELETEXT_TERMINAL_IDENTIFIER "2.5.4.22"
  1327. #define szOID_FACSIMILE_TELEPHONE_NUMBER "2.5.4.23"
  1328. #define szOID_X21_ADDRESS "2.5.4.24" // numeric string
  1329. #define szOID_INTERNATIONAL_ISDN_NUMBER "2.5.4.25" // numeric string
  1330. #define szOID_REGISTERED_ADDRESS "2.5.4.26"
  1331. #define szOID_DESTINATION_INDICATOR "2.5.4.27" // printable string
  1332. // Preference attribute types:
  1333. #define szOID_PREFERRED_DELIVERY_METHOD "2.5.4.28"
  1334. // OSI application attribute types:
  1335. #define szOID_PRESENTATION_ADDRESS "2.5.4.29"
  1336. #define szOID_SUPPORTED_APPLICATION_CONTEXT "2.5.4.30"
  1337. // Relational application attribute types:
  1338. #define szOID_MEMBER "2.5.4.31"
  1339. #define szOID_OWNER "2.5.4.32"
  1340. #define szOID_ROLE_OCCUPANT "2.5.4.33"
  1341. #define szOID_SEE_ALSO "2.5.4.34"
  1342. // Security attribute types:
  1343. #define szOID_USER_PASSWORD "2.5.4.35"
  1344. #define szOID_USER_CERTIFICATE "2.5.4.36"
  1345. #define szOID_CA_CERTIFICATE "2.5.4.37"
  1346. #define szOID_AUTHORITY_REVOCATION_LIST "2.5.4.38"
  1347. #define szOID_CERTIFICATE_REVOCATION_LIST "2.5.4.39"
  1348. #define szOID_CROSS_CERTIFICATE_PAIR "2.5.4.40"
  1349. // Undocumented attribute types???
  1350. //#define szOID_??? "2.5.4.41"
  1351. #define szOID_GIVEN_NAME "2.5.4.42" // case-ignore string
  1352. #define szOID_INITIALS "2.5.4.43" // case-ignore string
  1353. // The DN Qualifier attribute type specifies disambiguating information to add
  1354. // to the relative distinguished name of an entry. It is intended to be used
  1355. // for entries held in multiple DSAs which would otherwise have the same name,
  1356. // and that its value be the same in a given DSA for all entries to which
  1357. // the information has been added.
  1358. #define szOID_DN_QUALIFIER "2.5.4.46"
  1359. // Pilot user attribute types:
  1360. #define szOID_DOMAIN_COMPONENT "0.9.2342.19200300.100.1.25" // IA5, UTF8 string
  1361. // used for PKCS 12 attributes
  1362. #define szOID_PKCS_12_FRIENDLY_NAME_ATTR "1.2.840.113549.1.9.20"
  1363. #define szOID_PKCS_12_LOCAL_KEY_ID "1.2.840.113549.1.9.21"
  1364. #define szOID_PKCS_12_KEY_PROVIDER_NAME_ATTR "1.3.6.1.4.1.311.17.1"
  1365. #define szOID_LOCAL_MACHINE_KEYSET "1.3.6.1.4.1.311.17.2"
  1366. //+-------------------------------------------------------------------------
  1367. // Microsoft CERT_RDN attribute Object Identifiers
  1368. //--------------------------------------------------------------------------
  1369. // Special RDN containing the KEY_ID. Its value type is CERT_RDN_OCTET_STRING.
  1370. #define szOID_KEYID_RDN "1.3.6.1.4.1.311.10.7.1"
  1371. //+-------------------------------------------------------------------------
  1372. // CERT_RDN Attribute Value Types
  1373. //
  1374. // For RDN_ENCODED_BLOB, the Value's CERT_RDN_VALUE_BLOB is in its encoded
  1375. // representation. Otherwise, its an array of bytes.
  1376. //
  1377. // For all CERT_RDN types, Value.cbData is always the number of bytes, not
  1378. // necessarily the number of elements in the string. For instance,
  1379. // RDN_UNIVERSAL_STRING is an array of ints (cbData == intCnt * 4) and
  1380. // RDN_BMP_STRING is an array of unsigned shorts (cbData == ushortCnt * 2).
  1381. //
  1382. // A RDN_UTF8_STRING is an array of UNICODE characters (cbData == charCnt *2).
  1383. // These UNICODE characters are encoded as UTF8 8 bit characters.
  1384. //
  1385. // For CertDecodeName, two 0 bytes are always appended to the end of the
  1386. // string (ensures a CHAR or WCHAR string is null terminated).
  1387. // These added 0 bytes are't included in the BLOB.cbData.
  1388. //--------------------------------------------------------------------------
  1389. #define CERT_RDN_ANY_TYPE 0
  1390. #define CERT_RDN_ENCODED_BLOB 1
  1391. #define CERT_RDN_OCTET_STRING 2
  1392. #define CERT_RDN_NUMERIC_STRING 3
  1393. #define CERT_RDN_PRINTABLE_STRING 4
  1394. #define CERT_RDN_TELETEX_STRING 5
  1395. #define CERT_RDN_T61_STRING 5
  1396. #define CERT_RDN_VIDEOTEX_STRING 6
  1397. #define CERT_RDN_IA5_STRING 7
  1398. #define CERT_RDN_GRAPHIC_STRING 8
  1399. #define CERT_RDN_VISIBLE_STRING 9
  1400. #define CERT_RDN_ISO646_STRING 9
  1401. #define CERT_RDN_GENERAL_STRING 10
  1402. #define CERT_RDN_UNIVERSAL_STRING 11
  1403. #define CERT_RDN_INT4_STRING 11
  1404. #define CERT_RDN_BMP_STRING 12
  1405. #define CERT_RDN_UNICODE_STRING 12
  1406. #define CERT_RDN_UTF8_STRING 13
  1407. #define CERT_RDN_TYPE_MASK 0x000000FF
  1408. #define CERT_RDN_FLAGS_MASK 0xFF000000
  1409. //+-------------------------------------------------------------------------
  1410. // Flags that can be or'ed with the above Value Type when encoding/decoding
  1411. //--------------------------------------------------------------------------
  1412. // For encoding: when set, CERT_RDN_T61_STRING is selected instead of
  1413. // CERT_RDN_UNICODE_STRING if all the unicode characters are <= 0xFF
  1414. #define CERT_RDN_ENABLE_T61_UNICODE_FLAG 0x80000000
  1415. // For encoding: when set, CERT_RDN_UTF8_STRING is selected instead of
  1416. // CERT_RDN_UNICODE_STRING.
  1417. #define CERT_RDN_ENABLE_UTF8_UNICODE_FLAG 0x20000000
  1418. // For encoding: when set, the characters aren't checked to see if they
  1419. // are valid for the Value Type.
  1420. #define CERT_RDN_DISABLE_CHECK_TYPE_FLAG 0x40000000
  1421. // For decoding: by default, CERT_RDN_T61_STRING values are initially decoded
  1422. // as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  1423. // Setting this flag skips the initial attempt to decode as UTF8.
  1424. #define CERT_RDN_DISABLE_IE4_UTF8_FLAG 0x01000000
  1425. // Macro to check that the dwValueType is a character string and not an
  1426. // encoded blob or octet string
  1427. #define IS_CERT_RDN_CHAR_STRING(X) \
  1428. (((X) & CERT_RDN_TYPE_MASK) >= CERT_RDN_NUMERIC_STRING)
  1429. //+-------------------------------------------------------------------------
  1430. // A CERT_RDN consists of an array of the above attributes
  1431. //--------------------------------------------------------------------------
  1432. typedef struct _CERT_RDN {
  1433. DWORD cRDNAttr;
  1434. PCERT_RDN_ATTR rgRDNAttr;
  1435. } CERT_RDN, *PCERT_RDN;
  1436. //+-------------------------------------------------------------------------
  1437. // Information stored in a subject's or issuer's name. The information
  1438. // is represented as an array of the above RDNs.
  1439. //--------------------------------------------------------------------------
  1440. typedef struct _CERT_NAME_INFO {
  1441. DWORD cRDN;
  1442. PCERT_RDN rgRDN;
  1443. } CERT_NAME_INFO, *PCERT_NAME_INFO;
  1444. //+-------------------------------------------------------------------------
  1445. // Name attribute value without the Object Identifier
  1446. //
  1447. // The interpretation of the Value depends on the dwValueType.
  1448. // See above for a list of the types.
  1449. //--------------------------------------------------------------------------
  1450. typedef struct _CERT_NAME_VALUE {
  1451. DWORD dwValueType;
  1452. CERT_RDN_VALUE_BLOB Value;
  1453. } CERT_NAME_VALUE, *PCERT_NAME_VALUE;
  1454. //+-------------------------------------------------------------------------
  1455. // Public Key Info
  1456. //
  1457. // The PublicKey is the encoded representation of the information as it is
  1458. // stored in the bit string
  1459. //--------------------------------------------------------------------------
  1460. typedef struct _CERT_PUBLIC_KEY_INFO {
  1461. CRYPT_ALGORITHM_IDENTIFIER Algorithm;
  1462. CRYPT_BIT_BLOB PublicKey;
  1463. } CERT_PUBLIC_KEY_INFO, *PCERT_PUBLIC_KEY_INFO;
  1464. #define CERT_RSA_PUBLIC_KEY_OBJID szOID_RSA_RSA
  1465. #define CERT_DEFAULT_OID_PUBLIC_KEY_SIGN szOID_RSA_RSA
  1466. #define CERT_DEFAULT_OID_PUBLIC_KEY_XCHG szOID_RSA_RSA
  1467. //+-------------------------------------------------------------------------
  1468. // structure that contains all the information in a PKCS#8 PrivateKeyInfo
  1469. //--------------------------------------------------------------------------
  1470. typedef struct _CRYPT_PRIVATE_KEY_INFO{
  1471. DWORD Version;
  1472. CRYPT_ALGORITHM_IDENTIFIER Algorithm;
  1473. CRYPT_DER_BLOB PrivateKey;
  1474. PCRYPT_ATTRIBUTES pAttributes;
  1475. } CRYPT_PRIVATE_KEY_INFO, *PCRYPT_PRIVATE_KEY_INFO;
  1476. //+-------------------------------------------------------------------------
  1477. // structure that contains all the information in a PKCS#8
  1478. // EncryptedPrivateKeyInfo
  1479. //--------------------------------------------------------------------------
  1480. typedef struct _CRYPT_ENCRYPTED_PRIVATE_KEY_INFO{
  1481. CRYPT_ALGORITHM_IDENTIFIER EncryptionAlgorithm;
  1482. CRYPT_DATA_BLOB EncryptedPrivateKey;
  1483. } CRYPT_ENCRYPTED_PRIVATE_KEY_INFO, *PCRYPT_ENCRYPTED_PRIVATE_KEY_INFO;
  1484. //+-------------------------------------------------------------------------
  1485. // this callback is given when an EncryptedProvateKeyInfo structure is
  1486. // encountered during ImportPKCS8. the caller is then expected to decrypt
  1487. // the private key and hand back the decrypted contents.
  1488. //
  1489. // the parameters are:
  1490. // Algorithm - the algorithm used to encrypt the PrivateKeyInfo
  1491. // EncryptedPrivateKey - the encrypted private key blob
  1492. // pClearTextKey - a buffer to receive the clear text
  1493. // cbClearTextKey - the number of bytes of the pClearTextKey buffer
  1494. // note the if this is zero then this should be
  1495. // filled in with the size required to decrypt the
  1496. // key into, and pClearTextKey should be ignored
  1497. // pVoidDecryptFunc - this is the pVoid that was passed into the call
  1498. // and is preserved and passed back as context
  1499. //+-------------------------------------------------------------------------
  1500. typedef BOOL (CALLBACK *PCRYPT_DECRYPT_PRIVATE_KEY_FUNC)(
  1501. CRYPT_ALGORITHM_IDENTIFIER Algorithm,
  1502. CRYPT_DATA_BLOB EncryptedPrivateKey,
  1503. BYTE *pbClearTextKey,
  1504. DWORD *pcbClearTextKey,
  1505. LPVOID pVoidDecryptFunc);
  1506. //+-------------------------------------------------------------------------
  1507. // this callback is given when creating a PKCS8 EncryptedPrivateKeyInfo.
  1508. // The caller is then expected to encrypt the private key and hand back
  1509. // the encrypted contents.
  1510. //
  1511. // the parameters are:
  1512. // Algorithm - the algorithm used to encrypt the PrivateKeyInfo
  1513. // pClearTextPrivateKey - the cleartext private key to be encrypted
  1514. // pbEncryptedKey - the output encrypted private key blob
  1515. // cbEncryptedKey - the number of bytes of the pbEncryptedKey buffer
  1516. // note the if this is zero then this should be
  1517. // filled in with the size required to encrypt the
  1518. // key into, and pbEncryptedKey should be ignored
  1519. // pVoidEncryptFunc - this is the pVoid that was passed into the call
  1520. // and is preserved and passed back as context
  1521. //+-------------------------------------------------------------------------
  1522. typedef BOOL (CALLBACK *PCRYPT_ENCRYPT_PRIVATE_KEY_FUNC)(
  1523. CRYPT_ALGORITHM_IDENTIFIER* pAlgorithm,
  1524. CRYPT_DATA_BLOB* pClearTextPrivateKey,
  1525. BYTE *pbEncryptedKey,
  1526. DWORD *pcbEncryptedKey,
  1527. LPVOID pVoidEncryptFunc);
  1528. //+-------------------------------------------------------------------------
  1529. // this callback is given from the context of a ImportPKCS8 calls. the caller
  1530. // is then expected to hand back an HCRYPTPROV to receive the key being imported
  1531. //
  1532. // the parameters are:
  1533. // pPrivateKeyInfo - pointer to a CRYPT_PRIVATE_KEY_INFO structure which
  1534. // describes the key being imported
  1535. // EncryptedPrivateKey - the encrypted private key blob
  1536. // phCryptProv - a pointer to a HCRRYPTPROV to be filled in
  1537. // pVoidResolveFunc - this is the pVoidResolveFunc passed in by the caller in the
  1538. // CRYPT_PRIVATE_KEY_BLOB_AND_PARAMS struct
  1539. //+-------------------------------------------------------------------------
  1540. typedef BOOL (CALLBACK *PCRYPT_RESOLVE_HCRYPTPROV_FUNC)(
  1541. CRYPT_PRIVATE_KEY_INFO *pPrivateKeyInfo,
  1542. HCRYPTPROV *phCryptProv,
  1543. LPVOID pVoidResolveFunc);
  1544. //+-------------------------------------------------------------------------
  1545. // this struct contains a PKCS8 private key and two pointers to callback
  1546. // functions, with a corresponding pVoids. the first callback is used to give
  1547. // the caller the opportunity to specify where the key is imported to. the callback
  1548. // passes the caller the algoroithm OID and key size to use in making the decision.
  1549. // the other callback is used to decrypt the private key if the PKCS8 contains an
  1550. // EncryptedPrivateKeyInfo. both pVoids are preserved and passed back to the caller
  1551. // in the respective callback
  1552. //+-------------------------------------------------------------------------
  1553. typedef struct _CRYPT_PKCS8_IMPORT_PARAMS{
  1554. CRYPT_DIGEST_BLOB PrivateKey; // PKCS8 blob
  1555. PCRYPT_RESOLVE_HCRYPTPROV_FUNC pResolvehCryptProvFunc; // optional
  1556. LPVOID pVoidResolveFunc; // optional
  1557. PCRYPT_DECRYPT_PRIVATE_KEY_FUNC pDecryptPrivateKeyFunc;
  1558. LPVOID pVoidDecryptFunc;
  1559. } CRYPT_PKCS8_IMPORT_PARAMS, *PCRYPT_PKCS8_IMPORT_PARAMS, CRYPT_PRIVATE_KEY_BLOB_AND_PARAMS, *PCRYPT_PRIVATE_KEY_BLOB_AND_PARAMS;
  1560. //+-------------------------------------------------------------------------
  1561. // this struct contains information identifying a private key and a pointer
  1562. // to a callback function, with a corresponding pVoid. The callback is used
  1563. // to encrypt the private key. If the pEncryptPrivateKeyFunc is NULL, the
  1564. // key will not be encrypted and an EncryptedPrivateKeyInfo will not be generated.
  1565. // The pVoid is preserved and passed back to the caller in the respective callback
  1566. //+-------------------------------------------------------------------------
  1567. typedef struct _CRYPT_PKCS8_EXPORT_PARAMS{
  1568. HCRYPTPROV hCryptProv;
  1569. DWORD dwKeySpec;
  1570. LPSTR pszPrivateKeyObjId;
  1571. PCRYPT_ENCRYPT_PRIVATE_KEY_FUNC pEncryptPrivateKeyFunc;
  1572. LPVOID pVoidEncryptFunc;
  1573. } CRYPT_PKCS8_EXPORT_PARAMS, *PCRYPT_PKCS8_EXPORT_PARAMS;
  1574. //+-------------------------------------------------------------------------
  1575. // Information stored in a certificate
  1576. //
  1577. // The Issuer, Subject, Algorithm, PublicKey and Extension BLOBs are the
  1578. // encoded representation of the information.
  1579. //--------------------------------------------------------------------------
  1580. typedef struct _CERT_INFO {
  1581. DWORD dwVersion;
  1582. CRYPT_INTEGER_BLOB SerialNumber;
  1583. CRYPT_ALGORITHM_IDENTIFIER SignatureAlgorithm;
  1584. CERT_NAME_BLOB Issuer;
  1585. FILETIME NotBefore;
  1586. FILETIME NotAfter;
  1587. CERT_NAME_BLOB Subject;
  1588. CERT_PUBLIC_KEY_INFO SubjectPublicKeyInfo;
  1589. CRYPT_BIT_BLOB IssuerUniqueId;
  1590. CRYPT_BIT_BLOB SubjectUniqueId;
  1591. DWORD cExtension;
  1592. PCERT_EXTENSION rgExtension;
  1593. } CERT_INFO, *PCERT_INFO;
  1594. //+-------------------------------------------------------------------------
  1595. // Certificate versions
  1596. //--------------------------------------------------------------------------
  1597. #define CERT_V1 0
  1598. #define CERT_V2 1
  1599. #define CERT_V3 2
  1600. //+-------------------------------------------------------------------------
  1601. // Certificate Information Flags
  1602. //--------------------------------------------------------------------------
  1603. #define CERT_INFO_VERSION_FLAG 1
  1604. #define CERT_INFO_SERIAL_NUMBER_FLAG 2
  1605. #define CERT_INFO_SIGNATURE_ALGORITHM_FLAG 3
  1606. #define CERT_INFO_ISSUER_FLAG 4
  1607. #define CERT_INFO_NOT_BEFORE_FLAG 5
  1608. #define CERT_INFO_NOT_AFTER_FLAG 6
  1609. #define CERT_INFO_SUBJECT_FLAG 7
  1610. #define CERT_INFO_SUBJECT_PUBLIC_KEY_INFO_FLAG 8
  1611. #define CERT_INFO_ISSUER_UNIQUE_ID_FLAG 9
  1612. #define CERT_INFO_SUBJECT_UNIQUE_ID_FLAG 10
  1613. #define CERT_INFO_EXTENSION_FLAG 11
  1614. //+-------------------------------------------------------------------------
  1615. // An entry in a CRL
  1616. //
  1617. // The Extension BLOBs are the encoded representation of the information.
  1618. //--------------------------------------------------------------------------
  1619. typedef struct _CRL_ENTRY {
  1620. CRYPT_INTEGER_BLOB SerialNumber;
  1621. FILETIME RevocationDate;
  1622. DWORD cExtension;
  1623. PCERT_EXTENSION rgExtension;
  1624. } CRL_ENTRY, *PCRL_ENTRY;
  1625. //+-------------------------------------------------------------------------
  1626. // Information stored in a CRL
  1627. //
  1628. // The Issuer, Algorithm and Extension BLOBs are the encoded
  1629. // representation of the information.
  1630. //--------------------------------------------------------------------------
  1631. typedef struct _CRL_INFO {
  1632. DWORD dwVersion;
  1633. CRYPT_ALGORITHM_IDENTIFIER SignatureAlgorithm;
  1634. CERT_NAME_BLOB Issuer;
  1635. FILETIME ThisUpdate;
  1636. FILETIME NextUpdate;
  1637. DWORD cCRLEntry;
  1638. PCRL_ENTRY rgCRLEntry;
  1639. DWORD cExtension;
  1640. PCERT_EXTENSION rgExtension;
  1641. } CRL_INFO, *PCRL_INFO;
  1642. //+-------------------------------------------------------------------------
  1643. // CRL versions
  1644. //--------------------------------------------------------------------------
  1645. #define CRL_V1 0
  1646. #define CRL_V2 1
  1647. //+-------------------------------------------------------------------------
  1648. // Information stored in a certificate request
  1649. //
  1650. // The Subject, Algorithm, PublicKey and Attribute BLOBs are the encoded
  1651. // representation of the information.
  1652. //--------------------------------------------------------------------------
  1653. typedef struct _CERT_REQUEST_INFO {
  1654. DWORD dwVersion;
  1655. CERT_NAME_BLOB Subject;
  1656. CERT_PUBLIC_KEY_INFO SubjectPublicKeyInfo;
  1657. DWORD cAttribute;
  1658. PCRYPT_ATTRIBUTE rgAttribute;
  1659. } CERT_REQUEST_INFO, *PCERT_REQUEST_INFO;
  1660. //+-------------------------------------------------------------------------
  1661. // Certificate Request versions
  1662. //--------------------------------------------------------------------------
  1663. #define CERT_REQUEST_V1 0
  1664. //+-------------------------------------------------------------------------
  1665. // Information stored in Netscape's Keygen request
  1666. //--------------------------------------------------------------------------
  1667. typedef struct _CERT_KEYGEN_REQUEST_INFO {
  1668. DWORD dwVersion;
  1669. CERT_PUBLIC_KEY_INFO SubjectPublicKeyInfo;
  1670. LPWSTR pwszChallengeString; // encoded as IA5
  1671. } CERT_KEYGEN_REQUEST_INFO, *PCERT_KEYGEN_REQUEST_INFO;
  1672. #define CERT_KEYGEN_REQUEST_V1 0
  1673. //+-------------------------------------------------------------------------
  1674. // Certificate, CRL, Certificate Request or Keygen Request Signed Content
  1675. //
  1676. // The "to be signed" encoded content plus its signature. The ToBeSigned
  1677. // is the encoded CERT_INFO, CRL_INFO, CERT_REQUEST_INFO or
  1678. // CERT_KEYGEN_REQUEST_INFO.
  1679. //--------------------------------------------------------------------------
  1680. typedef struct _CERT_SIGNED_CONTENT_INFO {
  1681. CRYPT_DER_BLOB ToBeSigned;
  1682. CRYPT_ALGORITHM_IDENTIFIER SignatureAlgorithm;
  1683. CRYPT_BIT_BLOB Signature;
  1684. } CERT_SIGNED_CONTENT_INFO, *PCERT_SIGNED_CONTENT_INFO;
  1685. //+-------------------------------------------------------------------------
  1686. // Certificate Trust List (CTL)
  1687. //--------------------------------------------------------------------------
  1688. //+-------------------------------------------------------------------------
  1689. // CTL Usage. Also used for EnhancedKeyUsage extension.
  1690. //--------------------------------------------------------------------------
  1691. typedef struct _CTL_USAGE {
  1692. DWORD cUsageIdentifier;
  1693. LPSTR *rgpszUsageIdentifier; // array of pszObjId
  1694. } CTL_USAGE, *PCTL_USAGE,
  1695. CERT_ENHKEY_USAGE, *PCERT_ENHKEY_USAGE;
  1696. //+-------------------------------------------------------------------------
  1697. // An entry in a CTL
  1698. //--------------------------------------------------------------------------
  1699. typedef struct _CTL_ENTRY {
  1700. CRYPT_DATA_BLOB SubjectIdentifier; // For example, its hash
  1701. DWORD cAttribute;
  1702. PCRYPT_ATTRIBUTE rgAttribute; // OPTIONAL
  1703. } CTL_ENTRY, *PCTL_ENTRY;
  1704. //+-------------------------------------------------------------------------
  1705. // Information stored in a CTL
  1706. //--------------------------------------------------------------------------
  1707. typedef struct _CTL_INFO {
  1708. DWORD dwVersion;
  1709. CTL_USAGE SubjectUsage;
  1710. CRYPT_DATA_BLOB ListIdentifier; // OPTIONAL
  1711. CRYPT_INTEGER_BLOB SequenceNumber; // OPTIONAL
  1712. FILETIME ThisUpdate;
  1713. FILETIME NextUpdate; // OPTIONAL
  1714. CRYPT_ALGORITHM_IDENTIFIER SubjectAlgorithm;
  1715. DWORD cCTLEntry;
  1716. PCTL_ENTRY rgCTLEntry; // OPTIONAL
  1717. DWORD cExtension;
  1718. PCERT_EXTENSION rgExtension; // OPTIONAL
  1719. } CTL_INFO, *PCTL_INFO;
  1720. //+-------------------------------------------------------------------------
  1721. // CTL versions
  1722. //--------------------------------------------------------------------------
  1723. #define CTL_V1 0
  1724. //+-------------------------------------------------------------------------
  1725. // TimeStamp Request
  1726. //
  1727. // The pszTimeStamp is the OID for the Time type requested
  1728. // The pszContentType is the Content Type OID for the content, usually DATA
  1729. // The Content is a un-decoded blob
  1730. //--------------------------------------------------------------------------
  1731. typedef struct _CRYPT_TIME_STAMP_REQUEST_INFO {
  1732. LPSTR pszTimeStampAlgorithm; // pszObjId
  1733. LPSTR pszContentType; // pszObjId
  1734. CRYPT_OBJID_BLOB Content;
  1735. DWORD cAttribute;
  1736. PCRYPT_ATTRIBUTE rgAttribute;
  1737. } CRYPT_TIME_STAMP_REQUEST_INFO, *PCRYPT_TIME_STAMP_REQUEST_INFO;
  1738. //+-------------------------------------------------------------------------
  1739. // Name Value Attribute
  1740. //--------------------------------------------------------------------------
  1741. typedef struct _CRYPT_ENROLLMENT_NAME_VALUE_PAIR {
  1742. LPWSTR pwszName;
  1743. LPWSTR pwszValue;
  1744. } CRYPT_ENROLLMENT_NAME_VALUE_PAIR, * PCRYPT_ENROLLMENT_NAME_VALUE_PAIR;
  1745. //+-------------------------------------------------------------------------
  1746. // CSP Provider
  1747. //--------------------------------------------------------------------------
  1748. typedef struct _CRYPT_CSP_PROVIDER {
  1749. DWORD dwKeySpec;
  1750. LPWSTR pwszProviderName;
  1751. CRYPT_BIT_BLOB Signature;
  1752. } CRYPT_CSP_PROVIDER, * PCRYPT_CSP_PROVIDER;
  1753. //+-------------------------------------------------------------------------
  1754. // Certificate and Message encoding types
  1755. //
  1756. // The encoding type is a DWORD containing both the certificate and message
  1757. // encoding types. The certificate encoding type is stored in the LOWORD.
  1758. // The message encoding type is stored in the HIWORD. Some functions or
  1759. // structure fields require only one of the encoding types. The following
  1760. // naming convention is used to indicate which encoding type(s) are
  1761. // required:
  1762. // dwEncodingType (both encoding types are required)
  1763. // dwMsgAndCertEncodingType (both encoding types are required)
  1764. // dwMsgEncodingType (only msg encoding type is required)
  1765. // dwCertEncodingType (only cert encoding type is required)
  1766. //
  1767. // Its always acceptable to specify both.
  1768. //--------------------------------------------------------------------------
  1769. #define CERT_ENCODING_TYPE_MASK 0x0000FFFF
  1770. #define CMSG_ENCODING_TYPE_MASK 0xFFFF0000
  1771. #define GET_CERT_ENCODING_TYPE(X) (X & CERT_ENCODING_TYPE_MASK)
  1772. #define GET_CMSG_ENCODING_TYPE(X) (X & CMSG_ENCODING_TYPE_MASK)
  1773. #define CRYPT_ASN_ENCODING 0x00000001
  1774. #define CRYPT_NDR_ENCODING 0x00000002
  1775. #define X509_ASN_ENCODING 0x00000001
  1776. #define X509_NDR_ENCODING 0x00000002
  1777. #define PKCS_7_ASN_ENCODING 0x00010000
  1778. #define PKCS_7_NDR_ENCODING 0x00020000
  1779. //+-------------------------------------------------------------------------
  1780. // format the specified data structure according to the certificate
  1781. // encoding type.
  1782. //
  1783. // The default behavior of CryptFormatObject is to return single line
  1784. // display of the encoded data, that is, each subfield will be concatenated with
  1785. // a ", " on one line. If user prefers to display the data in multiple line,
  1786. // set the flag CRYPT_FORMAT_STR_MULTI_LINE, that is, each subfield will be displayed
  1787. // on a seperate line.
  1788. //
  1789. // If there is no formatting routine installed or registered
  1790. // for the lpszStructType, the hex dump of the encoded BLOB will be returned.
  1791. // User can set the flag CRYPT_FORMAT_STR_NO_HEX to disable the hex dump.
  1792. //--------------------------------------------------------------------------
  1793. WINCRYPT32API
  1794. BOOL
  1795. WINAPI
  1796. CryptFormatObject(
  1797. IN DWORD dwCertEncodingType,
  1798. IN DWORD dwFormatType,
  1799. IN DWORD dwFormatStrType,
  1800. IN void *pFormatStruct,
  1801. IN LPCSTR lpszStructType,
  1802. IN const BYTE *pbEncoded,
  1803. IN DWORD cbEncoded,
  1804. OUT void *pbFormat,
  1805. IN OUT DWORD *pcbFormat
  1806. );
  1807. //-------------------------------------------------------------------------
  1808. // constants for dwFormatStrType of function CryptFormatObject
  1809. //-------------------------------------------------------------------------
  1810. #define CRYPT_FORMAT_STR_MULTI_LINE 0x0001
  1811. #define CRYPT_FORMAT_STR_NO_HEX 0x0010
  1812. //-------------------------------------------------------------------------
  1813. // constants for dwFormatType of function CryptFormatObject
  1814. // when format X509_NAME or X509_UNICODE_NAME
  1815. //-------------------------------------------------------------------------
  1816. // Just get the simple string
  1817. #define CRYPT_FORMAT_SIMPLE 0x0001
  1818. //Put an attribute name infront of the attribute
  1819. //such as "O=Microsoft,DN=xiaohs"
  1820. #define CRYPT_FORMAT_X509 0x0002
  1821. //Put an OID infront of the simple string, such as
  1822. //"2.5.4.22=Microsoft,2.5.4.3=xiaohs"
  1823. #define CRYPT_FORMAT_OID 0x0004
  1824. //Put a ";" between each RDN. The default is ","
  1825. #define CRYPT_FORMAT_RDN_SEMICOLON 0x0100
  1826. //Put a "\n" between each RDN.
  1827. #define CRYPT_FORMAT_RDN_CRLF 0x0200
  1828. //Unquote the DN value, which is quoated by default va the following
  1829. //rules: if the DN contains leading or trailing
  1830. //white space or one of the following characters: ",", "+", "=",
  1831. //""", "\n", "<", ">", "#" or ";". The quoting character is ".
  1832. //If the DN Value contains a " it is double quoted ("").
  1833. #define CRYPT_FORMAT_RDN_UNQUOTE 0x0400
  1834. //reverse the order of the RDNs before converting to the string
  1835. #define CRYPT_FORMAT_RDN_REVERSE 0x0800
  1836. //-------------------------------------------------------------------------
  1837. // contants dwFormatType of function CryptFormatObject when format a DN.:
  1838. //
  1839. // The following three values are defined in the section above:
  1840. // CRYPT_FORMAT_SIMPLE: Just a simple string
  1841. // such as "Microsoft+xiaohs+NT"
  1842. // CRYPT_FORMAT_X509 Put an attribute name infront of the attribute
  1843. // such as "O=Microsoft+xiaohs+NT"
  1844. //
  1845. // CRYPT_FORMAT_OID Put an OID infront of the simple string,
  1846. // such as "2.5.4.22=Microsoft+xiaohs+NT"
  1847. //
  1848. // Additional values are defined as following:
  1849. //----------------------------------------------------------------------------
  1850. //Put a "," between each value. Default is "+"
  1851. #define CRYPT_FORMAT_COMMA 0x1000
  1852. //Put a ";" between each value
  1853. #define CRYPT_FORMAT_SEMICOLON CRYPT_FORMAT_RDN_SEMICOLON
  1854. //Put a "\n" between each value
  1855. #define CRYPT_FORMAT_CRLF CRYPT_FORMAT_RDN_CRLF
  1856. //+-------------------------------------------------------------------------
  1857. // Encode / decode the specified data structure according to the certificate
  1858. // encoding type.
  1859. //
  1860. // See below for a list of the predefined data structures.
  1861. //--------------------------------------------------------------------------
  1862. typedef LPVOID (WINAPI *PFN_CRYPT_ALLOC)(
  1863. IN size_t cbSize
  1864. );
  1865. typedef VOID (WINAPI *PFN_CRYPT_FREE)(
  1866. IN LPVOID pv
  1867. );
  1868. typedef struct _CRYPT_ENCODE_PARA {
  1869. DWORD cbSize;
  1870. PFN_CRYPT_ALLOC pfnAlloc; // OPTIONAL
  1871. PFN_CRYPT_FREE pfnFree; // OPTIONAL
  1872. } CRYPT_ENCODE_PARA, *PCRYPT_ENCODE_PARA;
  1873. WINCRYPT32API
  1874. BOOL
  1875. WINAPI
  1876. CryptEncodeObjectEx(
  1877. IN DWORD dwCertEncodingType,
  1878. IN LPCSTR lpszStructType,
  1879. IN const void *pvStructInfo,
  1880. IN DWORD dwFlags,
  1881. IN OPTIONAL PCRYPT_ENCODE_PARA pEncodePara,
  1882. OUT void *pvEncoded,
  1883. IN OUT DWORD *pcbEncoded
  1884. );
  1885. WINCRYPT32API
  1886. BOOL
  1887. WINAPI
  1888. CryptEncodeObject(
  1889. IN DWORD dwCertEncodingType,
  1890. IN LPCSTR lpszStructType,
  1891. IN const void *pvStructInfo,
  1892. OUT BYTE *pbEncoded,
  1893. IN OUT DWORD *pcbEncoded
  1894. );
  1895. // By default the signature bytes are reversed. The following flag can
  1896. // be set to inhibit the byte reversal.
  1897. //
  1898. // This flag is applicable to
  1899. // X509_CERT_TO_BE_SIGNED
  1900. #define CRYPT_ENCODE_NO_SIGNATURE_BYTE_REVERSAL_FLAG 0x8
  1901. // When the following flag is set the called encode function allocates
  1902. // memory for the encoded bytes. A pointer to the allocated bytes
  1903. // is returned in pvEncoded. If pEncodePara or pEncodePara->pfnAlloc is
  1904. // NULL, then, LocalAlloc is called for the allocation and LocalFree must
  1905. // be called to do the free. Otherwise, pEncodePara->pfnAlloc is called
  1906. // for the allocation.
  1907. //
  1908. // *pcbEncoded is ignored on input and updated with the length of the
  1909. // allocated, encoded bytes.
  1910. //
  1911. // If pfnAlloc is set, then, pfnFree should also be set.
  1912. #define CRYPT_ENCODE_ALLOC_FLAG 0x8000
  1913. // The following flag is applicable when encoding X509_UNICODE_NAME.
  1914. // When set, CERT_RDN_T61_STRING is selected instead of
  1915. // CERT_RDN_UNICODE_STRING if all the unicode characters are <= 0xFF
  1916. #define CRYPT_UNICODE_NAME_ENCODE_ENABLE_T61_UNICODE_FLAG \
  1917. CERT_RDN_ENABLE_T61_UNICODE_FLAG
  1918. // The following flag is applicable when encoding X509_UNICODE_NAME.
  1919. // When set, CERT_RDN_UTF8_STRING is selected instead of
  1920. // CERT_RDN_UNICODE_STRING.
  1921. #define CRYPT_UNICODE_NAME_ENCODE_ENABLE_UTF8_UNICODE_FLAG \
  1922. CERT_RDN_ENABLE_UTF8_UNICODE_FLAG
  1923. // The following flag is applicable when encoding X509_UNICODE_NAME,
  1924. // X509_UNICODE_NAME_VALUE or X509_UNICODE_ANY_STRING.
  1925. // When set, the characters aren't checked to see if they
  1926. // are valid for the specified Value Type.
  1927. #define CRYPT_UNICODE_NAME_ENCODE_DISABLE_CHECK_TYPE_FLAG \
  1928. CERT_RDN_DISABLE_CHECK_TYPE_FLAG
  1929. // The following flag is applicable when encoding the PKCS_SORTED_CTL. This
  1930. // flag should be set if the identifier for the TrustedSubjects is a hash,
  1931. // such as, MD5 or SHA1.
  1932. #define CRYPT_SORTED_CTL_ENCODE_HASHED_SUBJECT_IDENTIFIER_FLAG 0x10000
  1933. typedef struct _CRYPT_DECODE_PARA {
  1934. DWORD cbSize;
  1935. PFN_CRYPT_ALLOC pfnAlloc; // OPTIONAL
  1936. PFN_CRYPT_FREE pfnFree; // OPTIONAL
  1937. } CRYPT_DECODE_PARA, *PCRYPT_DECODE_PARA;
  1938. WINCRYPT32API
  1939. BOOL
  1940. WINAPI
  1941. CryptDecodeObjectEx(
  1942. IN DWORD dwCertEncodingType,
  1943. IN LPCSTR lpszStructType,
  1944. IN const BYTE *pbEncoded,
  1945. IN DWORD cbEncoded,
  1946. IN DWORD dwFlags,
  1947. IN OPTIONAL PCRYPT_DECODE_PARA pDecodePara,
  1948. OUT OPTIONAL void *pvStructInfo,
  1949. IN OUT DWORD *pcbStructInfo
  1950. );
  1951. WINCRYPT32API
  1952. BOOL
  1953. WINAPI
  1954. CryptDecodeObject(
  1955. IN DWORD dwCertEncodingType,
  1956. IN LPCSTR lpszStructType,
  1957. IN const BYTE *pbEncoded,
  1958. IN DWORD cbEncoded,
  1959. IN DWORD dwFlags,
  1960. OUT void *pvStructInfo,
  1961. IN OUT DWORD *pcbStructInfo
  1962. );
  1963. // When the following flag is set the nocopy optimization is enabled.
  1964. // This optimization where appropriate, updates the pvStructInfo fields
  1965. // to point to content residing within pbEncoded instead of making a copy
  1966. // of and appending to pvStructInfo.
  1967. //
  1968. // Note, when set, pbEncoded can't be freed until pvStructInfo is freed.
  1969. #define CRYPT_DECODE_NOCOPY_FLAG 0x1
  1970. // For CryptDecodeObject(), by default the pbEncoded is the "to be signed"
  1971. // plus its signature. Set the following flag, if pbEncoded points to only
  1972. // the "to be signed".
  1973. //
  1974. // This flag is applicable to
  1975. // X509_CERT_TO_BE_SIGNED
  1976. // X509_CERT_CRL_TO_BE_SIGNED
  1977. // X509_CERT_REQUEST_TO_BE_SIGNED
  1978. // X509_KEYGEN_REQUEST_TO_BE_SIGNED
  1979. #define CRYPT_DECODE_TO_BE_SIGNED_FLAG 0x2
  1980. // When the following flag is set, the OID strings are allocated in
  1981. // crypt32.dll and shared instead of being copied into the returned
  1982. // data structure. This flag may be set if crypt32.dll isn't unloaded
  1983. // before the caller is unloaded.
  1984. #define CRYPT_DECODE_SHARE_OID_STRING_FLAG 0x4
  1985. // By default the signature bytes are reversed. The following flag can
  1986. // be set to inhibit the byte reversal.
  1987. //
  1988. // This flag is applicable to
  1989. // X509_CERT_TO_BE_SIGNED
  1990. #define CRYPT_DECODE_NO_SIGNATURE_BYTE_REVERSAL_FLAG 0x8
  1991. // When the following flag is set the called decode function allocates
  1992. // memory for the decoded structure. A pointer to the allocated structure
  1993. // is returned in pvStructInfo. If pDecodePara or pDecodePara->pfnAlloc is
  1994. // NULL, then, LocalAlloc is called for the allocation and LocalFree must
  1995. // be called to do the free. Otherwise, pDecodePara->pfnAlloc is called
  1996. // for the allocation.
  1997. //
  1998. // *pcbStructInfo is ignored on input and updated with the length of the
  1999. // allocated, decoded structure.
  2000. //
  2001. // This flag may also be set in the CryptDecodeObject API. Since
  2002. // CryptDecodeObject doesn't take a pDecodePara, LocalAlloc is always
  2003. // called for the allocation which must be freed by calling LocalFree.
  2004. #define CRYPT_DECODE_ALLOC_FLAG 0x8000
  2005. // The following flag is applicable when decoding X509_UNICODE_NAME,
  2006. // X509_UNICODE_NAME_VALUE or X509_UNICODE_ANY_STRING.
  2007. // By default, CERT_RDN_T61_STRING values are initially decoded
  2008. // as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  2009. // Setting this flag skips the initial attempt to decode as UTF8.
  2010. #define CRYPT_UNICODE_NAME_DECODE_DISABLE_IE4_UTF8_FLAG \
  2011. CERT_RDN_DISABLE_IE4_UTF8_FLAG
  2012. //+-------------------------------------------------------------------------
  2013. // Predefined X509 certificate data structures that can be encoded / decoded.
  2014. //--------------------------------------------------------------------------
  2015. #define CRYPT_ENCODE_DECODE_NONE 0
  2016. #define X509_CERT ((LPCSTR) 1)
  2017. #define X509_CERT_TO_BE_SIGNED ((LPCSTR) 2)
  2018. #define X509_CERT_CRL_TO_BE_SIGNED ((LPCSTR) 3)
  2019. #define X509_CERT_REQUEST_TO_BE_SIGNED ((LPCSTR) 4)
  2020. #define X509_EXTENSIONS ((LPCSTR) 5)
  2021. #define X509_NAME_VALUE ((LPCSTR) 6)
  2022. #define X509_NAME ((LPCSTR) 7)
  2023. #define X509_PUBLIC_KEY_INFO ((LPCSTR) 8)
  2024. //+-------------------------------------------------------------------------
  2025. // Predefined X509 certificate extension data structures that can be
  2026. // encoded / decoded.
  2027. //--------------------------------------------------------------------------
  2028. #define X509_AUTHORITY_KEY_ID ((LPCSTR) 9)
  2029. #define X509_KEY_ATTRIBUTES ((LPCSTR) 10)
  2030. #define X509_KEY_USAGE_RESTRICTION ((LPCSTR) 11)
  2031. #define X509_ALTERNATE_NAME ((LPCSTR) 12)
  2032. #define X509_BASIC_CONSTRAINTS ((LPCSTR) 13)
  2033. #define X509_KEY_USAGE ((LPCSTR) 14)
  2034. #define X509_BASIC_CONSTRAINTS2 ((LPCSTR) 15)
  2035. #define X509_CERT_POLICIES ((LPCSTR) 16)
  2036. //+-------------------------------------------------------------------------
  2037. // Additional predefined data structures that can be encoded / decoded.
  2038. //--------------------------------------------------------------------------
  2039. #define PKCS_UTC_TIME ((LPCSTR) 17)
  2040. #define PKCS_TIME_REQUEST ((LPCSTR) 18)
  2041. #define RSA_CSP_PUBLICKEYBLOB ((LPCSTR) 19)
  2042. #define X509_UNICODE_NAME ((LPCSTR) 20)
  2043. #define X509_KEYGEN_REQUEST_TO_BE_SIGNED ((LPCSTR) 21)
  2044. #define PKCS_ATTRIBUTE ((LPCSTR) 22)
  2045. #define PKCS_CONTENT_INFO_SEQUENCE_OF_ANY ((LPCSTR) 23)
  2046. //+-------------------------------------------------------------------------
  2047. // Predefined primitive data structures that can be encoded / decoded.
  2048. //--------------------------------------------------------------------------
  2049. #define X509_UNICODE_NAME_VALUE ((LPCSTR) 24)
  2050. #define X509_ANY_STRING X509_NAME_VALUE
  2051. #define X509_UNICODE_ANY_STRING X509_UNICODE_NAME_VALUE
  2052. #define X509_OCTET_STRING ((LPCSTR) 25)
  2053. #define X509_BITS ((LPCSTR) 26)
  2054. #define X509_INTEGER ((LPCSTR) 27)
  2055. #define X509_MULTI_BYTE_INTEGER ((LPCSTR) 28)
  2056. #define X509_ENUMERATED ((LPCSTR) 29)
  2057. #define X509_CHOICE_OF_TIME ((LPCSTR) 30)
  2058. //+-------------------------------------------------------------------------
  2059. // More predefined X509 certificate extension data structures that can be
  2060. // encoded / decoded.
  2061. //--------------------------------------------------------------------------
  2062. #define X509_AUTHORITY_KEY_ID2 ((LPCSTR) 31)
  2063. #define X509_AUTHORITY_INFO_ACCESS ((LPCSTR) 32)
  2064. #define X509_CRL_REASON_CODE X509_ENUMERATED
  2065. #define PKCS_CONTENT_INFO ((LPCSTR) 33)
  2066. #define X509_SEQUENCE_OF_ANY ((LPCSTR) 34)
  2067. #define X509_CRL_DIST_POINTS ((LPCSTR) 35)
  2068. #define X509_ENHANCED_KEY_USAGE ((LPCSTR) 36)
  2069. #define PKCS_CTL ((LPCSTR) 37)
  2070. #define X509_MULTI_BYTE_UINT ((LPCSTR) 38)
  2071. #define X509_DSS_PUBLICKEY X509_MULTI_BYTE_UINT
  2072. #define X509_DSS_PARAMETERS ((LPCSTR) 39)
  2073. #define X509_DSS_SIGNATURE ((LPCSTR) 40)
  2074. #define PKCS_RC2_CBC_PARAMETERS ((LPCSTR) 41)
  2075. #define PKCS_SMIME_CAPABILITIES ((LPCSTR) 42)
  2076. //+-------------------------------------------------------------------------
  2077. // data structures for private keys
  2078. //--------------------------------------------------------------------------
  2079. #define PKCS_RSA_PRIVATE_KEY ((LPCSTR) 43)
  2080. #define PKCS_PRIVATE_KEY_INFO ((LPCSTR) 44)
  2081. #define PKCS_ENCRYPTED_PRIVATE_KEY_INFO ((LPCSTR) 45)
  2082. //+-------------------------------------------------------------------------
  2083. // certificate policy qualifier
  2084. //--------------------------------------------------------------------------
  2085. #define X509_PKIX_POLICY_QUALIFIER_USERNOTICE ((LPCSTR) 46)
  2086. //+-------------------------------------------------------------------------
  2087. // Diffie-Hellman Key Exchange
  2088. //--------------------------------------------------------------------------
  2089. #define X509_DH_PUBLICKEY X509_MULTI_BYTE_UINT
  2090. #define X509_DH_PARAMETERS ((LPCSTR) 47)
  2091. #define PKCS_ATTRIBUTES ((LPCSTR) 48)
  2092. #define PKCS_SORTED_CTL ((LPCSTR) 49)
  2093. //+-------------------------------------------------------------------------
  2094. // X942 Diffie-Hellman
  2095. //--------------------------------------------------------------------------
  2096. #define X942_DH_PARAMETERS ((LPCSTR) 50)
  2097. //+-------------------------------------------------------------------------
  2098. // The following is the same as X509_BITS, except before encoding,
  2099. // the bit length is decremented to exclude trailing zero bits.
  2100. //--------------------------------------------------------------------------
  2101. #define X509_BITS_WITHOUT_TRAILING_ZEROES ((LPCSTR) 51)
  2102. //+-------------------------------------------------------------------------
  2103. // X942 Diffie-Hellman Other Info
  2104. //--------------------------------------------------------------------------
  2105. #define X942_OTHER_INFO ((LPCSTR) 52)
  2106. #define X509_CERT_PAIR ((LPCSTR) 53)
  2107. #define X509_ISSUING_DIST_POINT ((LPCSTR) 54)
  2108. #define X509_NAME_CONSTRAINTS ((LPCSTR) 55)
  2109. #define X509_POLICY_MAPPINGS ((LPCSTR) 56)
  2110. #define X509_POLICY_CONSTRAINTS ((LPCSTR) 57)
  2111. #define X509_CROSS_CERT_DIST_POINTS ((LPCSTR) 58)
  2112. //+-------------------------------------------------------------------------
  2113. // Certificate Management Messages over CMS (CMC) Data Structures
  2114. //--------------------------------------------------------------------------
  2115. #define CMC_DATA ((LPCSTR) 59)
  2116. #define CMC_RESPONSE ((LPCSTR) 60)
  2117. #define CMC_STATUS ((LPCSTR) 61)
  2118. #define CMC_ADD_EXTENSIONS ((LPCSTR) 62)
  2119. #define CMC_ADD_ATTRIBUTES ((LPCSTR) 63)
  2120. //+-------------------------------------------------------------------------
  2121. // Certificate Template
  2122. //--------------------------------------------------------------------------
  2123. #define X509_CERTIFICATE_TEMPLATE ((LPCSTR) 64)
  2124. //+-------------------------------------------------------------------------
  2125. // Predefined PKCS #7 data structures that can be encoded / decoded.
  2126. //--------------------------------------------------------------------------
  2127. #define PKCS7_SIGNER_INFO ((LPCSTR) 500)
  2128. //+-------------------------------------------------------------------------
  2129. // Predefined PKCS #7 data structures that can be encoded / decoded.
  2130. //--------------------------------------------------------------------------
  2131. #define CMS_SIGNER_INFO ((LPCSTR) 501)
  2132. //+-------------------------------------------------------------------------
  2133. // Predefined Software Publishing Credential (SPC) data structures that
  2134. // can be encoded / decoded.
  2135. //
  2136. // Predefined values: 2000 .. 2999
  2137. //
  2138. // See spc.h for value and data structure definitions.
  2139. //--------------------------------------------------------------------------
  2140. //+-------------------------------------------------------------------------
  2141. // Extension Object Identifiers
  2142. //--------------------------------------------------------------------------
  2143. #define szOID_AUTHORITY_KEY_IDENTIFIER "2.5.29.1"
  2144. #define szOID_KEY_ATTRIBUTES "2.5.29.2"
  2145. #define szOID_CERT_POLICIES_95 "2.5.29.3"
  2146. #define szOID_KEY_USAGE_RESTRICTION "2.5.29.4"
  2147. #define szOID_SUBJECT_ALT_NAME "2.5.29.7"
  2148. #define szOID_ISSUER_ALT_NAME "2.5.29.8"
  2149. #define szOID_BASIC_CONSTRAINTS "2.5.29.10"
  2150. #define szOID_KEY_USAGE "2.5.29.15"
  2151. #define szOID_PRIVATEKEY_USAGE_PERIOD "2.5.29.16"
  2152. #define szOID_BASIC_CONSTRAINTS2 "2.5.29.19"
  2153. #define szOID_CERT_POLICIES "2.5.29.32"
  2154. #define szOID_ANY_CERT_POLICY "2.5.29.32.0"
  2155. #define szOID_AUTHORITY_KEY_IDENTIFIER2 "2.5.29.35"
  2156. #define szOID_SUBJECT_KEY_IDENTIFIER "2.5.29.14"
  2157. #define szOID_SUBJECT_ALT_NAME2 "2.5.29.17"
  2158. #define szOID_ISSUER_ALT_NAME2 "2.5.29.18"
  2159. #define szOID_CRL_REASON_CODE "2.5.29.21"
  2160. #define szOID_REASON_CODE_HOLD "2.5.29.23"
  2161. #define szOID_CRL_DIST_POINTS "2.5.29.31"
  2162. #define szOID_ENHANCED_KEY_USAGE "2.5.29.37"
  2163. // szOID_CRL_NUMBER -- Base CRLs only. Monotonically increasing sequence
  2164. // number for each CRL issued by a CA.
  2165. #define szOID_CRL_NUMBER "2.5.29.20"
  2166. // szOID_DELTA_CRL_INDICATOR -- Delta CRLs only. Marked critical.
  2167. // Contains the minimum base CRL Number that can be used with a delta CRL.
  2168. #define szOID_DELTA_CRL_INDICATOR "2.5.29.27"
  2169. #define szOID_ISSUING_DIST_POINT "2.5.29.28"
  2170. // szOID_FRESHEST_CRL -- Base CRLs only. Formatted identically to a CDP
  2171. // extension that holds URLs to fetch the delta CRL.
  2172. #define szOID_FRESHEST_CRL "2.5.29.46"
  2173. #define szOID_NAME_CONSTRAINTS "2.5.29.30"
  2174. // Note on 1/1/2000 szOID_POLICY_MAPPINGS was changed from "2.5.29.5"
  2175. #define szOID_POLICY_MAPPINGS "2.5.29.33"
  2176. #define szOID_LEGACY_POLICY_MAPPINGS "2.5.29.5"
  2177. #define szOID_POLICY_CONSTRAINTS "2.5.29.36"
  2178. // Microsoft PKCS10 Attributes
  2179. #define szOID_RENEWAL_CERTIFICATE "1.3.6.1.4.1.311.13.1"
  2180. #define szOID_ENROLLMENT_NAME_VALUE_PAIR "1.3.6.1.4.1.311.13.2.1"
  2181. #define szOID_ENROLLMENT_CSP_PROVIDER "1.3.6.1.4.1.311.13.2.2"
  2182. #define szOID_OS_VERSION "1.3.6.1.4.1.311.13.2.3"
  2183. //
  2184. // Extension contain certificate type
  2185. #define szOID_ENROLLMENT_AGENT "1.3.6.1.4.1.311.20.2.1"
  2186. // Internet Public Key Infrastructure (PKIX)
  2187. #define szOID_PKIX "1.3.6.1.5.5.7"
  2188. #define szOID_PKIX_PE "1.3.6.1.5.5.7.1"
  2189. #define szOID_AUTHORITY_INFO_ACCESS "1.3.6.1.5.5.7.1.1"
  2190. // Microsoft extensions or attributes
  2191. #define szOID_CERT_EXTENSIONS "1.3.6.1.4.1.311.2.1.14"
  2192. #define szOID_NEXT_UPDATE_LOCATION "1.3.6.1.4.1.311.10.2"
  2193. #define szOID_REMOVE_CERTIFICATE "1.3.6.1.4.1.311.10.8.1"
  2194. #define szOID_CROSS_CERT_DIST_POINTS "1.3.6.1.4.1.311.10.9.1"
  2195. // Microsoft PKCS #7 ContentType Object Identifiers
  2196. #define szOID_CTL "1.3.6.1.4.1.311.10.1"
  2197. // Microsoft Sorted CTL Extension Object Identifier
  2198. #define szOID_SORTED_CTL "1.3.6.1.4.1.311.10.1.1"
  2199. // serialized serial numbers for PRS
  2200. #ifndef szOID_SERIALIZED
  2201. #define szOID_SERIALIZED "1.3.6.1.4.1.311.10.3.3.1"
  2202. #endif
  2203. // UPN principal name in SubjectAltName
  2204. #ifndef szOID_NT_PRINCIPAL_NAME
  2205. #define szOID_NT_PRINCIPAL_NAME "1.3.6.1.4.1.311.20.2.3"
  2206. #endif
  2207. // Windows product update unauthenticated attribute
  2208. #ifndef szOID_PRODUCT_UPDATE
  2209. #define szOID_PRODUCT_UPDATE "1.3.6.1.4.1.311.31.1"
  2210. #endif
  2211. // CryptUI
  2212. #define szOID_ANY_APPLICATION_POLICY "1.3.6.1.4.1.311.10.12.1"
  2213. //+-------------------------------------------------------------------------
  2214. // Object Identifiers for use with Auto Enrollment
  2215. //--------------------------------------------------------------------------
  2216. #define szOID_AUTO_ENROLL_CTL_USAGE "1.3.6.1.4.1.311.20.1"
  2217. // Extension contain certificate type
  2218. #define szOID_ENROLL_CERTTYPE_EXTENSION "1.3.6.1.4.1.311.20.2"
  2219. #define szOID_CERT_MANIFOLD "1.3.6.1.4.1.311.20.3"
  2220. //+-------------------------------------------------------------------------
  2221. // Object Identifiers for use with the MS Certificate Server
  2222. //--------------------------------------------------------------------------
  2223. #ifndef szOID_CERTSRV_CA_VERSION
  2224. #define szOID_CERTSRV_CA_VERSION "1.3.6.1.4.1.311.21.1"
  2225. #endif
  2226. // szOID_CERTSRV_PREVIOUS_CERT_HASH -- Contains the sha1 hash of the previous
  2227. // version of the CA certificate.
  2228. #define szOID_CERTSRV_PREVIOUS_CERT_HASH "1.3.6.1.4.1.311.21.2"
  2229. // szOID_CRL_VIRTUAL_BASE -- Delta CRLs only. Contains the base CRL Number
  2230. // of the corresponding base CRL.
  2231. #define szOID_CRL_VIRTUAL_BASE "1.3.6.1.4.1.311.21.3"
  2232. // szOID_CRL_NEXT_PUBLISH -- Contains the time when the next CRL is expected
  2233. // to be published. This may be sooner than the CRL's NextUpdate field.
  2234. #define szOID_CRL_NEXT_PUBLISH "1.3.6.1.4.1.311.21.4"
  2235. // Enhanced Key Usage for CA encryption certificate
  2236. #define szOID_KP_CA_EXCHANGE "1.3.6.1.4.1.311.21.5"
  2237. // Enhanced Key Usage for key recovery agent certificate
  2238. #define szOID_KP_KEY_RECOVERY_AGENT "1.3.6.1.4.1.311.21.6"
  2239. // Certificate template extension (v2)
  2240. #define szOID_CERTIFICATE_TEMPLATE "1.3.6.1.4.1.311.21.7"
  2241. // The root oid for all enterprise specific oids
  2242. #define szOID_ENTERPRISE_OID_ROOT "1.3.6.1.4.1.311.21.8"
  2243. // Dummy signing Subject RDN
  2244. #define szOID_RDN_DUMMY_SIGNER "1.3.6.1.4.1.311.21.9"
  2245. // Application Policies extension -- same encoding as szOID_CERT_POLICIES
  2246. #define szOID_APPLICATION_CERT_POLICIES "1.3.6.1.4.1.311.21.10"
  2247. // Application Policy Mappings -- same encoding as szOID_POLICY_MAPPINGS
  2248. #define szOID_APPLICATION_POLICY_MAPPINGS "1.3.6.1.4.1.311.21.11"
  2249. // Application Policy Constraints -- same encoding as szOID_POLICY_CONSTRAINTS
  2250. #define szOID_APPLICATION_POLICY_CONSTRAINTS "1.3.6.1.4.1.311.21.12"
  2251. #define szOID_ARCHIVED_KEY_ATTR "1.3.6.1.4.1.311.21.13"
  2252. #define szOID_CRL_SELF_CDP "1.3.6.1.4.1.311.21.14"
  2253. // Requires all certificates below the root to have a non-empty intersecting
  2254. // issuance certificate policy usage.
  2255. #define szOID_REQUIRE_CERT_CHAIN_POLICY "1.3.6.1.4.1.311.21.15"
  2256. #define szOID_ARCHIVED_KEY_CERT_HASH "1.3.6.1.4.1.311.21.16"
  2257. #define szOID_ISSUED_CERT_HASH "1.3.6.1.4.1.311.21.17"
  2258. // Enhanced key usage for DS email replication
  2259. #define szOID_DS_EMAIL_REPLICATION "1.3.6.1.4.1.311.21.19"
  2260. #define szOID_REQUEST_CLIENT_INFO "1.3.6.1.4.1.311.21.20"
  2261. #define szOID_ENCRYPTED_KEY_HASH "1.3.6.1.4.1.311.21.21"
  2262. #define szOID_CERTSRV_CROSSCA_VERSION "1.3.6.1.4.1.311.21.22"
  2263. //+-------------------------------------------------------------------------
  2264. // Object Identifiers for use with the MS Directory Service
  2265. //--------------------------------------------------------------------------
  2266. #define szOID_NTDS_REPLICATION "1.3.6.1.4.1.311.25.1"
  2267. //+-------------------------------------------------------------------------
  2268. // Extension Object Identifiers (currently not implemented)
  2269. //--------------------------------------------------------------------------
  2270. #define szOID_SUBJECT_DIR_ATTRS "2.5.29.9"
  2271. //+-------------------------------------------------------------------------
  2272. // Enhanced Key Usage (Purpose) Object Identifiers
  2273. //--------------------------------------------------------------------------
  2274. #define szOID_PKIX_KP "1.3.6.1.5.5.7.3"
  2275. // Consistent key usage bits: DIGITAL_SIGNATURE, KEY_ENCIPHERMENT
  2276. // or KEY_AGREEMENT
  2277. #define szOID_PKIX_KP_SERVER_AUTH "1.3.6.1.5.5.7.3.1"
  2278. // Consistent key usage bits: DIGITAL_SIGNATURE
  2279. #define szOID_PKIX_KP_CLIENT_AUTH "1.3.6.1.5.5.7.3.2"
  2280. // Consistent key usage bits: DIGITAL_SIGNATURE
  2281. #define szOID_PKIX_KP_CODE_SIGNING "1.3.6.1.5.5.7.3.3"
  2282. // Consistent key usage bits: DIGITAL_SIGNATURE, NON_REPUDIATION and/or
  2283. // (KEY_ENCIPHERMENT or KEY_AGREEMENT)
  2284. #define szOID_PKIX_KP_EMAIL_PROTECTION "1.3.6.1.5.5.7.3.4"
  2285. // Consistent key usage bits: DIGITAL_SIGNATURE and/or
  2286. // (KEY_ENCIPHERMENT or KEY_AGREEMENT)
  2287. #define szOID_PKIX_KP_IPSEC_END_SYSTEM "1.3.6.1.5.5.7.3.5"
  2288. // Consistent key usage bits: DIGITAL_SIGNATURE and/or
  2289. // (KEY_ENCIPHERMENT or KEY_AGREEMENT)
  2290. #define szOID_PKIX_KP_IPSEC_TUNNEL "1.3.6.1.5.5.7.3.6"
  2291. // Consistent key usage bits: DIGITAL_SIGNATURE and/or
  2292. // (KEY_ENCIPHERMENT or KEY_AGREEMENT)
  2293. #define szOID_PKIX_KP_IPSEC_USER "1.3.6.1.5.5.7.3.7"
  2294. // Consistent key usage bits: DIGITAL_SIGNATURE or NON_REPUDIATION
  2295. #define szOID_PKIX_KP_TIMESTAMP_SIGNING "1.3.6.1.5.5.7.3.8"
  2296. // IKE (Internet Key Exchange) Intermediate KP for an IPsec end entity.
  2297. // Defined in draft-ietf-ipsec-pki-req-04.txt, December 14, 1999.
  2298. #define szOID_IPSEC_KP_IKE_INTERMEDIATE "1.3.6.1.5.5.8.2.2"
  2299. //+-------------------------------------------------------------------------
  2300. // Microsoft Enhanced Key Usage (Purpose) Object Identifiers
  2301. //+-------------------------------------------------------------------------
  2302. // Signer of CTLs
  2303. #define szOID_KP_CTL_USAGE_SIGNING "1.3.6.1.4.1.311.10.3.1"
  2304. // Signer of TimeStamps
  2305. #define szOID_KP_TIME_STAMP_SIGNING "1.3.6.1.4.1.311.10.3.2"
  2306. #ifndef szOID_SERVER_GATED_CRYPTO
  2307. #define szOID_SERVER_GATED_CRYPTO "1.3.6.1.4.1.311.10.3.3"
  2308. #endif
  2309. #ifndef szOID_SGC_NETSCAPE
  2310. #define szOID_SGC_NETSCAPE "2.16.840.1.113730.4.1"
  2311. #endif
  2312. #define szOID_KP_EFS "1.3.6.1.4.1.311.10.3.4"
  2313. #define szOID_EFS_RECOVERY "1.3.6.1.4.1.311.10.3.4.1"
  2314. // Can use Windows Hardware Compatible (WHQL)
  2315. #define szOID_WHQL_CRYPTO "1.3.6.1.4.1.311.10.3.5"
  2316. // Signed by the NT5 build lab
  2317. #define szOID_NT5_CRYPTO "1.3.6.1.4.1.311.10.3.6"
  2318. // Signed by and OEM of WHQL
  2319. #define szOID_OEM_WHQL_CRYPTO "1.3.6.1.4.1.311.10.3.7"
  2320. // Signed by the Embedded NT
  2321. #define szOID_EMBEDDED_NT_CRYPTO "1.3.6.1.4.1.311.10.3.8"
  2322. // Signer of a CTL containing trusted roots
  2323. #define szOID_ROOT_LIST_SIGNER "1.3.6.1.4.1.311.10.3.9"
  2324. // Can sign cross-cert and subordinate CA requests with qualified
  2325. // subordination (name constraints, policy mapping, etc.)
  2326. #define szOID_KP_QUALIFIED_SUBORDINATION "1.3.6.1.4.1.311.10.3.10"
  2327. // Can be used to encrypt/recover escrowed keys
  2328. #define szOID_KP_KEY_RECOVERY "1.3.6.1.4.1.311.10.3.11"
  2329. // Signer of documents
  2330. #define szOID_KP_DOCUMENT_SIGNING "1.3.6.1.4.1.311.10.3.12"
  2331. // The default WinVerifyTrust Authenticode policy is to treat all time stamped
  2332. // signatures as being valid forever. This OID limits the valid lifetime of the
  2333. // signature to the lifetime of the certificate. This allows timestamped
  2334. // signatures to expire. Normally this OID will be used in conjunction with
  2335. // szOID_PKIX_KP_CODE_SIGNING to indicate new time stamp semantics should be
  2336. // used. Support for this OID was added in WXP.
  2337. #define szOID_KP_LIFETIME_SIGNING "1.3.6.1.4.1.311.10.3.13"
  2338. #define szOID_KP_MOBILE_DEVICE_SOFTWARE "1.3.6.1.4.1.311.10.3.14"
  2339. #ifndef szOID_DRM
  2340. #define szOID_DRM "1.3.6.1.4.1.311.10.5.1"
  2341. #endif
  2342. // Microsoft DRM EKU
  2343. #ifndef szOID_DRM_INDIVIDUALIZATION
  2344. #define szOID_DRM_INDIVIDUALIZATION "1.3.6.1.4.1.311.10.5.2"
  2345. #endif
  2346. #ifndef szOID_LICENSES
  2347. #define szOID_LICENSES "1.3.6.1.4.1.311.10.6.1"
  2348. #endif
  2349. #ifndef szOID_LICENSE_SERVER
  2350. #define szOID_LICENSE_SERVER "1.3.6.1.4.1.311.10.6.2"
  2351. #endif
  2352. #ifndef szOID_KP_SMARTCARD_LOGON
  2353. #define szOID_KP_SMARTCARD_LOGON "1.3.6.1.4.1.311.20.2.2"
  2354. #endif
  2355. //+-------------------------------------------------------------------------
  2356. // Microsoft Attribute Object Identifiers
  2357. //+-------------------------------------------------------------------------
  2358. #define szOID_YESNO_TRUST_ATTR "1.3.6.1.4.1.311.10.4.1"
  2359. //+-------------------------------------------------------------------------
  2360. // Qualifiers that may be part of the szOID_CERT_POLICIES and
  2361. // szOID_CERT_POLICIES95 extensions
  2362. //+-------------------------------------------------------------------------
  2363. #define szOID_PKIX_POLICY_QUALIFIER_CPS "1.3.6.1.5.5.7.2.1"
  2364. #define szOID_PKIX_POLICY_QUALIFIER_USERNOTICE "1.3.6.1.5.5.7.2.2"
  2365. // OID for old qualifer
  2366. #define szOID_CERT_POLICIES_95_QUALIFIER1 "2.16.840.1.113733.1.7.1.1"
  2367. //+-------------------------------------------------------------------------
  2368. // X509_CERT
  2369. //
  2370. // The "to be signed" encoded content plus its signature. The ToBeSigned
  2371. // content is the CryptEncodeObject() output for one of the following:
  2372. // X509_CERT_TO_BE_SIGNED, X509_CERT_CRL_TO_BE_SIGNED or
  2373. // X509_CERT_REQUEST_TO_BE_SIGNED.
  2374. //
  2375. // pvStructInfo points to CERT_SIGNED_CONTENT_INFO.
  2376. //--------------------------------------------------------------------------
  2377. //+-------------------------------------------------------------------------
  2378. // X509_CERT_TO_BE_SIGNED
  2379. //
  2380. // pvStructInfo points to CERT_INFO.
  2381. //
  2382. // For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  2383. // signature (output of a X509_CERT CryptEncodeObject()).
  2384. //
  2385. // For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  2386. //--------------------------------------------------------------------------
  2387. //+-------------------------------------------------------------------------
  2388. // X509_CERT_CRL_TO_BE_SIGNED
  2389. //
  2390. // pvStructInfo points to CRL_INFO.
  2391. //
  2392. // For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  2393. // signature (output of a X509_CERT CryptEncodeObject()).
  2394. //
  2395. // For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  2396. //--------------------------------------------------------------------------
  2397. //+-------------------------------------------------------------------------
  2398. // X509_CERT_REQUEST_TO_BE_SIGNED
  2399. //
  2400. // pvStructInfo points to CERT_REQUEST_INFO.
  2401. //
  2402. // For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  2403. // signature (output of a X509_CERT CryptEncodeObject()).
  2404. //
  2405. // For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  2406. //--------------------------------------------------------------------------
  2407. //+-------------------------------------------------------------------------
  2408. // X509_EXTENSIONS
  2409. // szOID_CERT_EXTENSIONS
  2410. //
  2411. // pvStructInfo points to following CERT_EXTENSIONS.
  2412. //--------------------------------------------------------------------------
  2413. typedef struct _CERT_EXTENSIONS {
  2414. DWORD cExtension;
  2415. PCERT_EXTENSION rgExtension;
  2416. } CERT_EXTENSIONS, *PCERT_EXTENSIONS;
  2417. //+-------------------------------------------------------------------------
  2418. // X509_NAME_VALUE
  2419. // X509_ANY_STRING
  2420. //
  2421. // pvStructInfo points to CERT_NAME_VALUE.
  2422. //--------------------------------------------------------------------------
  2423. //+-------------------------------------------------------------------------
  2424. // X509_UNICODE_NAME_VALUE
  2425. // X509_UNICODE_ANY_STRING
  2426. //
  2427. // pvStructInfo points to CERT_NAME_VALUE.
  2428. //
  2429. // The name values are unicode strings.
  2430. //
  2431. // For CryptEncodeObject:
  2432. // Value.pbData points to the unicode string.
  2433. // If Value.cbData = 0, then, the unicode string is NULL terminated.
  2434. // Otherwise, Value.cbData is the unicode string byte count. The byte count
  2435. // is twice the character count.
  2436. //
  2437. // If the unicode string contains an invalid character for the specified
  2438. // dwValueType, then, *pcbEncoded is updated with the unicode character
  2439. // index of the first invalid character. LastError is set to:
  2440. // CRYPT_E_INVALID_NUMERIC_STRING, CRYPT_E_INVALID_PRINTABLE_STRING or
  2441. // CRYPT_E_INVALID_IA5_STRING.
  2442. //
  2443. // To disable the above check, either set CERT_RDN_DISABLE_CHECK_TYPE_FLAG
  2444. // in dwValueType or set CRYPT_UNICODE_NAME_ENCODE_DISABLE_CHECK_TYPE_FLAG
  2445. // in dwFlags passed to CryptEncodeObjectEx.
  2446. //
  2447. // The unicode string is converted before being encoded according to
  2448. // the specified dwValueType. If dwValueType is set to 0, LastError
  2449. // is set to E_INVALIDARG.
  2450. //
  2451. // If the dwValueType isn't one of the character strings (its a
  2452. // CERT_RDN_ENCODED_BLOB or CERT_RDN_OCTET_STRING), then, CryptEncodeObject
  2453. // will return FALSE with LastError set to CRYPT_E_NOT_CHAR_STRING.
  2454. //
  2455. // For CryptDecodeObject:
  2456. // Value.pbData points to a NULL terminated unicode string. Value.cbData
  2457. // contains the byte count of the unicode string excluding the NULL
  2458. // terminator. dwValueType contains the type used in the encoded object.
  2459. // Its not forced to CERT_RDN_UNICODE_STRING. The encoded value is
  2460. // converted to the unicode string according to the dwValueType.
  2461. //
  2462. // If the encoded object isn't one of the character string types, then,
  2463. // CryptDecodeObject will return FALSE with LastError set to
  2464. // CRYPT_E_NOT_CHAR_STRING. For a non character string, decode using
  2465. // X509_NAME_VALUE or X509_ANY_STRING.
  2466. //
  2467. // By default, CERT_RDN_T61_STRING values are initially decoded
  2468. // as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  2469. // Set CRYPT_UNICODE_NAME_DECODE_DISABLE_IE4_UTF8_FLAG in dwFlags
  2470. // passed to either CryptDecodeObject or CryptDecodeObjectEx to
  2471. // skip the initial attempt to decode as UTF8.
  2472. //--------------------------------------------------------------------------
  2473. //+-------------------------------------------------------------------------
  2474. // X509_NAME
  2475. //
  2476. // pvStructInfo points to CERT_NAME_INFO.
  2477. //--------------------------------------------------------------------------
  2478. //+-------------------------------------------------------------------------
  2479. // X509_UNICODE_NAME
  2480. //
  2481. // pvStructInfo points to CERT_NAME_INFO.
  2482. //
  2483. // The RDN attribute values are unicode strings except for the dwValueTypes of
  2484. // CERT_RDN_ENCODED_BLOB or CERT_RDN_OCTET_STRING. These dwValueTypes are
  2485. // the same as for a X509_NAME. Their values aren't converted to/from unicode.
  2486. //
  2487. // For CryptEncodeObject:
  2488. // Value.pbData points to the unicode string.
  2489. // If Value.cbData = 0, then, the unicode string is NULL terminated.
  2490. // Otherwise, Value.cbData is the unicode string byte count. The byte count
  2491. // is twice the character count.
  2492. //
  2493. // If dwValueType = 0 (CERT_RDN_ANY_TYPE), the pszObjId is used to find
  2494. // an acceptable dwValueType. If the unicode string contains an
  2495. // invalid character for the found or specified dwValueType, then,
  2496. // *pcbEncoded is updated with the error location of the invalid character.
  2497. // See below for details. LastError is set to:
  2498. // CRYPT_E_INVALID_NUMERIC_STRING, CRYPT_E_INVALID_PRINTABLE_STRING or
  2499. // CRYPT_E_INVALID_IA5_STRING.
  2500. //
  2501. // To disable the above check, either set CERT_RDN_DISABLE_CHECK_TYPE_FLAG
  2502. // in dwValueType or set CRYPT_UNICODE_NAME_ENCODE_DISABLE_CHECK_TYPE_FLAG
  2503. // in dwFlags passed to CryptEncodeObjectEx.
  2504. //
  2505. // Set CERT_RDN_UNICODE_STRING in dwValueType or set
  2506. // CRYPT_UNICODE_NAME_ENCODE_ENABLE_T61_UNICODE_FLAG in dwFlags passed
  2507. // to CryptEncodeObjectEx to select CERT_RDN_T61_STRING instead of
  2508. // CERT_RDN_UNICODE_STRING if all the unicode characters are <= 0xFF.
  2509. //
  2510. // Set CERT_RDN_ENABLE_UTF8_UNICODE_STRING in dwValueType or set
  2511. // CRYPT_UNICODE_NAME_ENCODE_ENABLE_UTF8_UNICODE_FLAG in dwFlags passed
  2512. // to CryptEncodeObjectEx to select CERT_RDN_UTF8_STRING instead of
  2513. // CERT_RDN_UNICODE_STRING.
  2514. //
  2515. // The unicode string is converted before being encoded according to
  2516. // the specified or ObjId matching dwValueType.
  2517. //
  2518. // For CryptDecodeObject:
  2519. // Value.pbData points to a NULL terminated unicode string. Value.cbData
  2520. // contains the byte count of the unicode string excluding the NULL
  2521. // terminator. dwValueType contains the type used in the encoded object.
  2522. // Its not forced to CERT_RDN_UNICODE_STRING. The encoded value is
  2523. // converted to the unicode string according to the dwValueType.
  2524. //
  2525. // If the dwValueType of the encoded value isn't a character string
  2526. // type, then, it isn't converted to UNICODE. Use the
  2527. // IS_CERT_RDN_CHAR_STRING() macro on the dwValueType to check
  2528. // that Value.pbData points to a converted unicode string.
  2529. //
  2530. // By default, CERT_RDN_T61_STRING values are initially decoded
  2531. // as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  2532. // Set CRYPT_UNICODE_NAME_DECODE_DISABLE_IE4_UTF8_FLAG in dwFlags
  2533. // passed to either CryptDecodeObject or CryptDecodeObjectEx to
  2534. // skip the initial attempt to decode as UTF8.
  2535. //--------------------------------------------------------------------------
  2536. //+-------------------------------------------------------------------------
  2537. // Unicode Name Value Error Location Definitions
  2538. //
  2539. // Error location is returned in *pcbEncoded by
  2540. // CryptEncodeObject(X509_UNICODE_NAME)
  2541. //
  2542. // Error location consists of:
  2543. // RDN_INDEX - 10 bits << 22
  2544. // ATTR_INDEX - 6 bits << 16
  2545. // VALUE_INDEX - 16 bits (unicode character index)
  2546. //--------------------------------------------------------------------------
  2547. #define CERT_UNICODE_RDN_ERR_INDEX_MASK 0x3FF
  2548. #define CERT_UNICODE_RDN_ERR_INDEX_SHIFT 22
  2549. #define CERT_UNICODE_ATTR_ERR_INDEX_MASK 0x003F
  2550. #define CERT_UNICODE_ATTR_ERR_INDEX_SHIFT 16
  2551. #define CERT_UNICODE_VALUE_ERR_INDEX_MASK 0x0000FFFF
  2552. #define CERT_UNICODE_VALUE_ERR_INDEX_SHIFT 0
  2553. #define GET_CERT_UNICODE_RDN_ERR_INDEX(X) \
  2554. ((X >> CERT_UNICODE_RDN_ERR_INDEX_SHIFT) & CERT_UNICODE_RDN_ERR_INDEX_MASK)
  2555. #define GET_CERT_UNICODE_ATTR_ERR_INDEX(X) \
  2556. ((X >> CERT_UNICODE_ATTR_ERR_INDEX_SHIFT) & CERT_UNICODE_ATTR_ERR_INDEX_MASK)
  2557. #define GET_CERT_UNICODE_VALUE_ERR_INDEX(X) \
  2558. (X & CERT_UNICODE_VALUE_ERR_INDEX_MASK)
  2559. //+-------------------------------------------------------------------------
  2560. // X509_PUBLIC_KEY_INFO
  2561. //
  2562. // pvStructInfo points to CERT_PUBLIC_KEY_INFO.
  2563. //--------------------------------------------------------------------------
  2564. //+-------------------------------------------------------------------------
  2565. // X509_AUTHORITY_KEY_ID
  2566. // szOID_AUTHORITY_KEY_IDENTIFIER
  2567. //
  2568. // pvStructInfo points to following CERT_AUTHORITY_KEY_ID_INFO.
  2569. //--------------------------------------------------------------------------
  2570. typedef struct _CERT_AUTHORITY_KEY_ID_INFO {
  2571. CRYPT_DATA_BLOB KeyId;
  2572. CERT_NAME_BLOB CertIssuer;
  2573. CRYPT_INTEGER_BLOB CertSerialNumber;
  2574. } CERT_AUTHORITY_KEY_ID_INFO, *PCERT_AUTHORITY_KEY_ID_INFO;
  2575. //+-------------------------------------------------------------------------
  2576. // X509_KEY_ATTRIBUTES
  2577. // szOID_KEY_ATTRIBUTES
  2578. //
  2579. // pvStructInfo points to following CERT_KEY_ATTRIBUTES_INFO.
  2580. //--------------------------------------------------------------------------
  2581. typedef struct _CERT_PRIVATE_KEY_VALIDITY {
  2582. FILETIME NotBefore;
  2583. FILETIME NotAfter;
  2584. } CERT_PRIVATE_KEY_VALIDITY, *PCERT_PRIVATE_KEY_VALIDITY;
  2585. typedef struct _CERT_KEY_ATTRIBUTES_INFO {
  2586. CRYPT_DATA_BLOB KeyId;
  2587. CRYPT_BIT_BLOB IntendedKeyUsage;
  2588. PCERT_PRIVATE_KEY_VALIDITY pPrivateKeyUsagePeriod; // OPTIONAL
  2589. } CERT_KEY_ATTRIBUTES_INFO, *PCERT_KEY_ATTRIBUTES_INFO;
  2590. // Byte[0]
  2591. #define CERT_DIGITAL_SIGNATURE_KEY_USAGE 0x80
  2592. #define CERT_NON_REPUDIATION_KEY_USAGE 0x40
  2593. #define CERT_KEY_ENCIPHERMENT_KEY_USAGE 0x20
  2594. #define CERT_DATA_ENCIPHERMENT_KEY_USAGE 0x10
  2595. #define CERT_KEY_AGREEMENT_KEY_USAGE 0x08
  2596. #define CERT_KEY_CERT_SIGN_KEY_USAGE 0x04
  2597. #define CERT_OFFLINE_CRL_SIGN_KEY_USAGE 0x02
  2598. #define CERT_CRL_SIGN_KEY_USAGE 0x02
  2599. #define CERT_ENCIPHER_ONLY_KEY_USAGE 0x01
  2600. // Byte[1]
  2601. #define CERT_DECIPHER_ONLY_KEY_USAGE 0x80
  2602. //+-------------------------------------------------------------------------
  2603. // X509_KEY_USAGE_RESTRICTION
  2604. // szOID_KEY_USAGE_RESTRICTION
  2605. //
  2606. // pvStructInfo points to following CERT_KEY_USAGE_RESTRICTION_INFO.
  2607. //--------------------------------------------------------------------------
  2608. typedef struct _CERT_POLICY_ID {
  2609. DWORD cCertPolicyElementId;
  2610. LPSTR *rgpszCertPolicyElementId; // pszObjId
  2611. } CERT_POLICY_ID, *PCERT_POLICY_ID;
  2612. typedef struct _CERT_KEY_USAGE_RESTRICTION_INFO {
  2613. DWORD cCertPolicyId;
  2614. PCERT_POLICY_ID rgCertPolicyId;
  2615. CRYPT_BIT_BLOB RestrictedKeyUsage;
  2616. } CERT_KEY_USAGE_RESTRICTION_INFO, *PCERT_KEY_USAGE_RESTRICTION_INFO;
  2617. // See CERT_KEY_ATTRIBUTES_INFO for definition of the RestrictedKeyUsage bits
  2618. //+-------------------------------------------------------------------------
  2619. // X509_ALTERNATE_NAME
  2620. // szOID_SUBJECT_ALT_NAME
  2621. // szOID_ISSUER_ALT_NAME
  2622. // szOID_SUBJECT_ALT_NAME2
  2623. // szOID_ISSUER_ALT_NAME2
  2624. //
  2625. // pvStructInfo points to following CERT_ALT_NAME_INFO.
  2626. //--------------------------------------------------------------------------
  2627. typedef struct _CERT_OTHER_NAME {
  2628. LPSTR pszObjId;
  2629. CRYPT_OBJID_BLOB Value;
  2630. } CERT_OTHER_NAME, *PCERT_OTHER_NAME;
  2631. typedef struct _CERT_ALT_NAME_ENTRY {
  2632. DWORD dwAltNameChoice;
  2633. union {
  2634. PCERT_OTHER_NAME pOtherName; // 1
  2635. LPWSTR pwszRfc822Name; // 2 (encoded IA5)
  2636. LPWSTR pwszDNSName; // 3 (encoded IA5)
  2637. // Not implemented x400Address; // 4
  2638. CERT_NAME_BLOB DirectoryName; // 5
  2639. // Not implemented pEdiPartyName; // 6
  2640. LPWSTR pwszURL; // 7 (encoded IA5)
  2641. CRYPT_DATA_BLOB IPAddress; // 8 (Octet String)
  2642. LPSTR pszRegisteredID; // 9 (Object Identifer)
  2643. };
  2644. } CERT_ALT_NAME_ENTRY, *PCERT_ALT_NAME_ENTRY;
  2645. #define CERT_ALT_NAME_OTHER_NAME 1
  2646. #define CERT_ALT_NAME_RFC822_NAME 2
  2647. #define CERT_ALT_NAME_DNS_NAME 3
  2648. #define CERT_ALT_NAME_X400_ADDRESS 4
  2649. #define CERT_ALT_NAME_DIRECTORY_NAME 5
  2650. #define CERT_ALT_NAME_EDI_PARTY_NAME 6
  2651. #define CERT_ALT_NAME_URL 7
  2652. #define CERT_ALT_NAME_IP_ADDRESS 8
  2653. #define CERT_ALT_NAME_REGISTERED_ID 9
  2654. typedef struct _CERT_ALT_NAME_INFO {
  2655. DWORD cAltEntry;
  2656. PCERT_ALT_NAME_ENTRY rgAltEntry;
  2657. } CERT_ALT_NAME_INFO, *PCERT_ALT_NAME_INFO;
  2658. //+-------------------------------------------------------------------------
  2659. // Alternate name IA5 Error Location Definitions for
  2660. // CRYPT_E_INVALID_IA5_STRING.
  2661. //
  2662. // Error location is returned in *pcbEncoded by
  2663. // CryptEncodeObject(X509_ALTERNATE_NAME)
  2664. //
  2665. // Error location consists of:
  2666. // ENTRY_INDEX - 8 bits << 16
  2667. // VALUE_INDEX - 16 bits (unicode character index)
  2668. //--------------------------------------------------------------------------
  2669. #define CERT_ALT_NAME_ENTRY_ERR_INDEX_MASK 0xFF
  2670. #define CERT_ALT_NAME_ENTRY_ERR_INDEX_SHIFT 16
  2671. #define CERT_ALT_NAME_VALUE_ERR_INDEX_MASK 0x0000FFFF
  2672. #define CERT_ALT_NAME_VALUE_ERR_INDEX_SHIFT 0
  2673. #define GET_CERT_ALT_NAME_ENTRY_ERR_INDEX(X) \
  2674. ((X >> CERT_ALT_NAME_ENTRY_ERR_INDEX_SHIFT) & \
  2675. CERT_ALT_NAME_ENTRY_ERR_INDEX_MASK)
  2676. #define GET_CERT_ALT_NAME_VALUE_ERR_INDEX(X) \
  2677. (X & CERT_ALT_NAME_VALUE_ERR_INDEX_MASK)
  2678. //+-------------------------------------------------------------------------
  2679. // X509_BASIC_CONSTRAINTS
  2680. // szOID_BASIC_CONSTRAINTS
  2681. //
  2682. // pvStructInfo points to following CERT_BASIC_CONSTRAINTS_INFO.
  2683. //--------------------------------------------------------------------------
  2684. typedef struct _CERT_BASIC_CONSTRAINTS_INFO {
  2685. CRYPT_BIT_BLOB SubjectType;
  2686. BOOL fPathLenConstraint;
  2687. DWORD dwPathLenConstraint;
  2688. DWORD cSubtreesConstraint;
  2689. CERT_NAME_BLOB *rgSubtreesConstraint;
  2690. } CERT_BASIC_CONSTRAINTS_INFO, *PCERT_BASIC_CONSTRAINTS_INFO;
  2691. #define CERT_CA_SUBJECT_FLAG 0x80
  2692. #define CERT_END_ENTITY_SUBJECT_FLAG 0x40
  2693. //+-------------------------------------------------------------------------
  2694. // X509_BASIC_CONSTRAINTS2
  2695. // szOID_BASIC_CONSTRAINTS2
  2696. //
  2697. // pvStructInfo points to following CERT_BASIC_CONSTRAINTS2_INFO.
  2698. //--------------------------------------------------------------------------
  2699. typedef struct _CERT_BASIC_CONSTRAINTS2_INFO {
  2700. BOOL fCA;
  2701. BOOL fPathLenConstraint;
  2702. DWORD dwPathLenConstraint;
  2703. } CERT_BASIC_CONSTRAINTS2_INFO, *PCERT_BASIC_CONSTRAINTS2_INFO;
  2704. //+-------------------------------------------------------------------------
  2705. // X509_KEY_USAGE
  2706. // szOID_KEY_USAGE
  2707. //
  2708. // pvStructInfo points to a CRYPT_BIT_BLOB. Has same bit definitions as
  2709. // CERT_KEY_ATTRIBUTES_INFO's IntendedKeyUsage.
  2710. //--------------------------------------------------------------------------
  2711. //+-------------------------------------------------------------------------
  2712. // X509_CERT_POLICIES
  2713. // szOID_CERT_POLICIES
  2714. // szOID_CERT_POLICIES_95 NOTE--Only allowed for decoding!!!
  2715. //
  2716. // pvStructInfo points to following CERT_POLICIES_INFO.
  2717. //
  2718. // NOTE: when decoding using szOID_CERT_POLICIES_95 the pszPolicyIdentifier
  2719. // may contain an empty string
  2720. //--------------------------------------------------------------------------
  2721. typedef struct _CERT_POLICY_QUALIFIER_INFO {
  2722. LPSTR pszPolicyQualifierId; // pszObjId
  2723. CRYPT_OBJID_BLOB Qualifier; // optional
  2724. } CERT_POLICY_QUALIFIER_INFO, *PCERT_POLICY_QUALIFIER_INFO;
  2725. typedef struct _CERT_POLICY_INFO {
  2726. LPSTR pszPolicyIdentifier; // pszObjId
  2727. DWORD cPolicyQualifier; // optional
  2728. CERT_POLICY_QUALIFIER_INFO *rgPolicyQualifier;
  2729. } CERT_POLICY_INFO, *PCERT_POLICY_INFO;
  2730. typedef struct _CERT_POLICIES_INFO {
  2731. DWORD cPolicyInfo;
  2732. CERT_POLICY_INFO *rgPolicyInfo;
  2733. } CERT_POLICIES_INFO, *PCERT_POLICIES_INFO;
  2734. //+-------------------------------------------------------------------------
  2735. // X509_PKIX_POLICY_QUALIFIER_USERNOTICE
  2736. // szOID_PKIX_POLICY_QUALIFIER_USERNOTICE
  2737. //
  2738. // pvStructInfo points to following CERT_POLICY_QUALIFIER_USER_NOTICE.
  2739. //
  2740. //--------------------------------------------------------------------------
  2741. typedef struct _CERT_POLICY_QUALIFIER_NOTICE_REFERENCE {
  2742. LPSTR pszOrganization;
  2743. DWORD cNoticeNumbers;
  2744. int *rgNoticeNumbers;
  2745. } CERT_POLICY_QUALIFIER_NOTICE_REFERENCE, *PCERT_POLICY_QUALIFIER_NOTICE_REFERENCE;
  2746. typedef struct _CERT_POLICY_QUALIFIER_USER_NOTICE {
  2747. CERT_POLICY_QUALIFIER_NOTICE_REFERENCE *pNoticeReference; // optional
  2748. LPWSTR pszDisplayText; // optional
  2749. } CERT_POLICY_QUALIFIER_USER_NOTICE, *PCERT_POLICY_QUALIFIER_USER_NOTICE;
  2750. //+-------------------------------------------------------------------------
  2751. // szOID_CERT_POLICIES_95_QUALIFIER1 - Decode Only!!!!
  2752. //
  2753. // pvStructInfo points to following CERT_POLICY95_QUALIFIER1.
  2754. //
  2755. //--------------------------------------------------------------------------
  2756. typedef struct _CPS_URLS {
  2757. LPWSTR pszURL;
  2758. CRYPT_ALGORITHM_IDENTIFIER *pAlgorithm; // optional
  2759. CRYPT_DATA_BLOB *pDigest; // optional
  2760. } CPS_URLS, *PCPS_URLS;
  2761. typedef struct _CERT_POLICY95_QUALIFIER1 {
  2762. LPWSTR pszPracticesReference; // optional
  2763. LPSTR pszNoticeIdentifier; // optional
  2764. LPSTR pszNSINoticeIdentifier; // optional
  2765. DWORD cCPSURLs;
  2766. CPS_URLS *rgCPSURLs; // optional
  2767. } CERT_POLICY95_QUALIFIER1, *PCERT_POLICY95_QUALIFIER1;
  2768. //+-------------------------------------------------------------------------
  2769. // X509_POLICY_MAPPINGS
  2770. // szOID_POLICY_MAPPINGS
  2771. // szOID_LEGACY_POLICY_MAPPINGS
  2772. //
  2773. // pvStructInfo points to following CERT_POLICY_MAPPINGS_INFO.
  2774. //--------------------------------------------------------------------------
  2775. typedef struct _CERT_POLICY_MAPPING {
  2776. LPSTR pszIssuerDomainPolicy; // pszObjId
  2777. LPSTR pszSubjectDomainPolicy; // pszObjId
  2778. } CERT_POLICY_MAPPING, *PCERT_POLICY_MAPPING;
  2779. typedef struct _CERT_POLICY_MAPPINGS_INFO {
  2780. DWORD cPolicyMapping;
  2781. PCERT_POLICY_MAPPING rgPolicyMapping;
  2782. } CERT_POLICY_MAPPINGS_INFO, *PCERT_POLICY_MAPPINGS_INFO;
  2783. //+-------------------------------------------------------------------------
  2784. // X509_POLICY_CONSTRAINTS
  2785. // szOID_POLICY_CONSTRAINTS
  2786. //
  2787. // pvStructInfo points to following CERT_POLICY_CONSTRAINTS_INFO.
  2788. //--------------------------------------------------------------------------
  2789. typedef struct _CERT_POLICY_CONSTRAINTS_INFO {
  2790. BOOL fRequireExplicitPolicy;
  2791. DWORD dwRequireExplicitPolicySkipCerts;
  2792. BOOL fInhibitPolicyMapping;
  2793. DWORD dwInhibitPolicyMappingSkipCerts;
  2794. } CERT_POLICY_CONSTRAINTS_INFO, *PCERT_POLICY_CONSTRAINTS_INFO;
  2795. //+-------------------------------------------------------------------------
  2796. // RSA_CSP_PUBLICKEYBLOB
  2797. //
  2798. // pvStructInfo points to a PUBLICKEYSTRUC immediately followed by a
  2799. // RSAPUBKEY and the modulus bytes.
  2800. //
  2801. // CryptExportKey outputs the above StructInfo for a dwBlobType of
  2802. // PUBLICKEYBLOB. CryptImportKey expects the above StructInfo when
  2803. // importing a public key.
  2804. //
  2805. // For dwCertEncodingType = X509_ASN_ENCODING, the RSA_CSP_PUBLICKEYBLOB is
  2806. // encoded as a PKCS #1 RSAPublicKey consisting of a SEQUENCE of a
  2807. // modulus INTEGER and a publicExponent INTEGER. The modulus is encoded
  2808. // as being a unsigned integer. When decoded, if the modulus was encoded
  2809. // as unsigned integer with a leading 0 byte, the 0 byte is removed before
  2810. // converting to the CSP modulus bytes.
  2811. //
  2812. // For decode, the aiKeyAlg field of PUBLICKEYSTRUC is always set to
  2813. // CALG_RSA_KEYX.
  2814. //--------------------------------------------------------------------------
  2815. //+-------------------------------------------------------------------------
  2816. // X509_KEYGEN_REQUEST_TO_BE_SIGNED
  2817. //
  2818. // pvStructInfo points to CERT_KEYGEN_REQUEST_INFO.
  2819. //
  2820. // For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  2821. // signature (output of a X509_CERT CryptEncodeObject()).
  2822. //
  2823. // For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  2824. //--------------------------------------------------------------------------
  2825. //+-------------------------------------------------------------------------
  2826. // PKCS_ATTRIBUTE data structure
  2827. //
  2828. // pvStructInfo points to a CRYPT_ATTRIBUTE.
  2829. //--------------------------------------------------------------------------
  2830. //+-------------------------------------------------------------------------
  2831. // PKCS_ATTRIBUTES data structure
  2832. //
  2833. // pvStructInfo points to a CRYPT_ATTRIBUTES.
  2834. //--------------------------------------------------------------------------
  2835. //+-------------------------------------------------------------------------
  2836. // PKCS_CONTENT_INFO_SEQUENCE_OF_ANY data structure
  2837. //
  2838. // pvStructInfo points to following CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY.
  2839. //
  2840. // For X509_ASN_ENCODING: encoded as a PKCS#7 ContentInfo structure wrapping
  2841. // a sequence of ANY. The value of the contentType field is pszObjId,
  2842. // while the content field is the following structure:
  2843. // SequenceOfAny ::= SEQUENCE OF ANY
  2844. //
  2845. // The CRYPT_DER_BLOBs point to the already encoded ANY content.
  2846. //--------------------------------------------------------------------------
  2847. typedef struct _CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY {
  2848. LPSTR pszObjId;
  2849. DWORD cValue;
  2850. PCRYPT_DER_BLOB rgValue;
  2851. } CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY, *PCRYPT_CONTENT_INFO_SEQUENCE_OF_ANY;
  2852. //+-------------------------------------------------------------------------
  2853. // PKCS_CONTENT_INFO data structure
  2854. //
  2855. // pvStructInfo points to following CRYPT_CONTENT_INFO.
  2856. //
  2857. // For X509_ASN_ENCODING: encoded as a PKCS#7 ContentInfo structure.
  2858. // The CRYPT_DER_BLOB points to the already encoded ANY content.
  2859. //--------------------------------------------------------------------------
  2860. typedef struct _CRYPT_CONTENT_INFO {
  2861. LPSTR pszObjId;
  2862. CRYPT_DER_BLOB Content;
  2863. } CRYPT_CONTENT_INFO, *PCRYPT_CONTENT_INFO;
  2864. //+-------------------------------------------------------------------------
  2865. // X509_OCTET_STRING data structure
  2866. //
  2867. // pvStructInfo points to a CRYPT_DATA_BLOB.
  2868. //--------------------------------------------------------------------------
  2869. //+-------------------------------------------------------------------------
  2870. // X509_BITS data structure
  2871. //
  2872. // pvStructInfo points to a CRYPT_BIT_BLOB.
  2873. //--------------------------------------------------------------------------
  2874. //+-------------------------------------------------------------------------
  2875. // X509_BITS_WITHOUT_TRAILING_ZEROES data structure
  2876. //
  2877. // pvStructInfo points to a CRYPT_BIT_BLOB.
  2878. //
  2879. // The same as X509_BITS, except before encoding, the bit length is
  2880. // decremented to exclude trailing zero bits.
  2881. //--------------------------------------------------------------------------
  2882. //+-------------------------------------------------------------------------
  2883. // X509_INTEGER data structure
  2884. //
  2885. // pvStructInfo points to an int.
  2886. //--------------------------------------------------------------------------
  2887. //+-------------------------------------------------------------------------
  2888. // X509_MULTI_BYTE_INTEGER data structure
  2889. //
  2890. // pvStructInfo points to a CRYPT_INTEGER_BLOB.
  2891. //--------------------------------------------------------------------------
  2892. //+-------------------------------------------------------------------------
  2893. // X509_ENUMERATED data structure
  2894. //
  2895. // pvStructInfo points to an int containing the enumerated value
  2896. //--------------------------------------------------------------------------
  2897. //+-------------------------------------------------------------------------
  2898. // X509_CHOICE_OF_TIME data structure
  2899. //
  2900. // pvStructInfo points to a FILETIME.
  2901. //--------------------------------------------------------------------------
  2902. //+-------------------------------------------------------------------------
  2903. // X509_SEQUENCE_OF_ANY data structure
  2904. //
  2905. // pvStructInfo points to following CRYPT_SEQUENCE_OF_ANY.
  2906. //
  2907. // The CRYPT_DER_BLOBs point to the already encoded ANY content.
  2908. //--------------------------------------------------------------------------
  2909. typedef struct _CRYPT_SEQUENCE_OF_ANY {
  2910. DWORD cValue;
  2911. PCRYPT_DER_BLOB rgValue;
  2912. } CRYPT_SEQUENCE_OF_ANY, *PCRYPT_SEQUENCE_OF_ANY;
  2913. //+-------------------------------------------------------------------------
  2914. // X509_AUTHORITY_KEY_ID2
  2915. // szOID_AUTHORITY_KEY_IDENTIFIER2
  2916. //
  2917. // pvStructInfo points to following CERT_AUTHORITY_KEY_ID2_INFO.
  2918. //
  2919. // For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  2920. // *pcbEncoded by CryptEncodeObject(X509_AUTHORITY_KEY_ID2)
  2921. //
  2922. // See X509_ALTERNATE_NAME for error location defines.
  2923. //--------------------------------------------------------------------------
  2924. typedef struct _CERT_AUTHORITY_KEY_ID2_INFO {
  2925. CRYPT_DATA_BLOB KeyId;
  2926. CERT_ALT_NAME_INFO AuthorityCertIssuer; // Optional, set cAltEntry
  2927. // to 0 to omit.
  2928. CRYPT_INTEGER_BLOB AuthorityCertSerialNumber;
  2929. } CERT_AUTHORITY_KEY_ID2_INFO, *PCERT_AUTHORITY_KEY_ID2_INFO;
  2930. //+-------------------------------------------------------------------------
  2931. // szOID_SUBJECT_KEY_IDENTIFIER
  2932. //
  2933. // pvStructInfo points to a CRYPT_DATA_BLOB.
  2934. //--------------------------------------------------------------------------
  2935. //+-------------------------------------------------------------------------
  2936. // X509_AUTHORITY_INFO_ACCESS
  2937. // szOID_AUTHORITY_INFO_ACCESS
  2938. //
  2939. // pvStructInfo points to following CERT_AUTHORITY_INFO_ACCESS.
  2940. //
  2941. // For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  2942. // *pcbEncoded by CryptEncodeObject(X509_AUTHORITY_INFO_ACCESS)
  2943. //
  2944. // Error location consists of:
  2945. // ENTRY_INDEX - 8 bits << 16
  2946. // VALUE_INDEX - 16 bits (unicode character index)
  2947. //
  2948. // See X509_ALTERNATE_NAME for ENTRY_INDEX and VALUE_INDEX error location
  2949. // defines.
  2950. //--------------------------------------------------------------------------
  2951. typedef struct _CERT_ACCESS_DESCRIPTION {
  2952. LPSTR pszAccessMethod; // pszObjId
  2953. CERT_ALT_NAME_ENTRY AccessLocation;
  2954. } CERT_ACCESS_DESCRIPTION, *PCERT_ACCESS_DESCRIPTION;
  2955. typedef struct _CERT_AUTHORITY_INFO_ACCESS {
  2956. DWORD cAccDescr;
  2957. PCERT_ACCESS_DESCRIPTION rgAccDescr;
  2958. } CERT_AUTHORITY_INFO_ACCESS, *PCERT_AUTHORITY_INFO_ACCESS;
  2959. //+-------------------------------------------------------------------------
  2960. // PKIX Access Description: Access Method Object Identifiers
  2961. //--------------------------------------------------------------------------
  2962. #define szOID_PKIX_ACC_DESCR "1.3.6.1.5.5.7.48"
  2963. #define szOID_PKIX_OCSP "1.3.6.1.5.5.7.48.1"
  2964. #define szOID_PKIX_CA_ISSUERS "1.3.6.1.5.5.7.48.2"
  2965. //+-------------------------------------------------------------------------
  2966. // X509_CRL_REASON_CODE
  2967. // szOID_CRL_REASON_CODE
  2968. //
  2969. // pvStructInfo points to an int which can be set to one of the following
  2970. // enumerated values:
  2971. //--------------------------------------------------------------------------
  2972. #define CRL_REASON_UNSPECIFIED 0
  2973. #define CRL_REASON_KEY_COMPROMISE 1
  2974. #define CRL_REASON_CA_COMPROMISE 2
  2975. #define CRL_REASON_AFFILIATION_CHANGED 3
  2976. #define CRL_REASON_SUPERSEDED 4
  2977. #define CRL_REASON_CESSATION_OF_OPERATION 5
  2978. #define CRL_REASON_CERTIFICATE_HOLD 6
  2979. #define CRL_REASON_REMOVE_FROM_CRL 8
  2980. //+-------------------------------------------------------------------------
  2981. // X509_CRL_DIST_POINTS
  2982. // szOID_CRL_DIST_POINTS
  2983. //
  2984. // pvStructInfo points to following CRL_DIST_POINTS_INFO.
  2985. //
  2986. // For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  2987. // *pcbEncoded by CryptEncodeObject(X509_CRL_DIST_POINTS)
  2988. //
  2989. // Error location consists of:
  2990. // CRL_ISSUER_BIT - 1 bit << 31 (0 for FullName, 1 for CRLIssuer)
  2991. // POINT_INDEX - 7 bits << 24
  2992. // ENTRY_INDEX - 8 bits << 16
  2993. // VALUE_INDEX - 16 bits (unicode character index)
  2994. //
  2995. // See X509_ALTERNATE_NAME for ENTRY_INDEX and VALUE_INDEX error location
  2996. // defines.
  2997. //--------------------------------------------------------------------------
  2998. typedef struct _CRL_DIST_POINT_NAME {
  2999. DWORD dwDistPointNameChoice;
  3000. union {
  3001. CERT_ALT_NAME_INFO FullName; // 1
  3002. // Not implemented IssuerRDN; // 2
  3003. };
  3004. } CRL_DIST_POINT_NAME, *PCRL_DIST_POINT_NAME;
  3005. #define CRL_DIST_POINT_NO_NAME 0
  3006. #define CRL_DIST_POINT_FULL_NAME 1
  3007. #define CRL_DIST_POINT_ISSUER_RDN_NAME 2
  3008. typedef struct _CRL_DIST_POINT {
  3009. CRL_DIST_POINT_NAME DistPointName; // OPTIONAL
  3010. CRYPT_BIT_BLOB ReasonFlags; // OPTIONAL
  3011. CERT_ALT_NAME_INFO CRLIssuer; // OPTIONAL
  3012. } CRL_DIST_POINT, *PCRL_DIST_POINT;
  3013. #define CRL_REASON_UNUSED_FLAG 0x80
  3014. #define CRL_REASON_KEY_COMPROMISE_FLAG 0x40
  3015. #define CRL_REASON_CA_COMPROMISE_FLAG 0x20
  3016. #define CRL_REASON_AFFILIATION_CHANGED_FLAG 0x10
  3017. #define CRL_REASON_SUPERSEDED_FLAG 0x08
  3018. #define CRL_REASON_CESSATION_OF_OPERATION_FLAG 0x04
  3019. #define CRL_REASON_CERTIFICATE_HOLD_FLAG 0x02
  3020. typedef struct _CRL_DIST_POINTS_INFO {
  3021. DWORD cDistPoint;
  3022. PCRL_DIST_POINT rgDistPoint;
  3023. } CRL_DIST_POINTS_INFO, *PCRL_DIST_POINTS_INFO;
  3024. #define CRL_DIST_POINT_ERR_INDEX_MASK 0x7F
  3025. #define CRL_DIST_POINT_ERR_INDEX_SHIFT 24
  3026. #define GET_CRL_DIST_POINT_ERR_INDEX(X) \
  3027. ((X >> CRL_DIST_POINT_ERR_INDEX_SHIFT) & CRL_DIST_POINT_ERR_INDEX_MASK)
  3028. #define CRL_DIST_POINT_ERR_CRL_ISSUER_BIT 0x80000000L
  3029. #define IS_CRL_DIST_POINT_ERR_CRL_ISSUER(X) \
  3030. (0 != (X & CRL_DIST_POINT_ERR_CRL_ISSUER_BIT))
  3031. //+-------------------------------------------------------------------------
  3032. // X509_CROSS_CERT_DIST_POINTS
  3033. // szOID_CROSS_CERT_DIST_POINTS
  3034. //
  3035. // pvStructInfo points to following CROSS_CERT_DIST_POINTS_INFO.
  3036. //
  3037. // For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  3038. // *pcbEncoded by CryptEncodeObject(X509_CRL_DIST_POINTS)
  3039. //
  3040. // Error location consists of:
  3041. // POINT_INDEX - 8 bits << 24
  3042. // ENTRY_INDEX - 8 bits << 16
  3043. // VALUE_INDEX - 16 bits (unicode character index)
  3044. //
  3045. // See X509_ALTERNATE_NAME for ENTRY_INDEX and VALUE_INDEX error location
  3046. // defines.
  3047. //--------------------------------------------------------------------------
  3048. typedef struct _CROSS_CERT_DIST_POINTS_INFO {
  3049. // Seconds between syncs. 0 implies use client default.
  3050. DWORD dwSyncDeltaTime;
  3051. DWORD cDistPoint;
  3052. PCERT_ALT_NAME_INFO rgDistPoint;
  3053. } CROSS_CERT_DIST_POINTS_INFO, *PCROSS_CERT_DIST_POINTS_INFO;
  3054. #define CROSS_CERT_DIST_POINT_ERR_INDEX_MASK 0xFF
  3055. #define CROSS_CERT_DIST_POINT_ERR_INDEX_SHIFT 24
  3056. #define GET_CROSS_CERT_DIST_POINT_ERR_INDEX(X) \
  3057. ((X >> CROSS_CERT_DIST_POINT_ERR_INDEX_SHIFT) & \
  3058. CROSS_CERT_DIST_POINT_ERR_INDEX_MASK)
  3059. //+-------------------------------------------------------------------------
  3060. // X509_ENHANCED_KEY_USAGE
  3061. // szOID_ENHANCED_KEY_USAGE
  3062. //
  3063. // pvStructInfo points to a CERT_ENHKEY_USAGE, CTL_USAGE.
  3064. //--------------------------------------------------------------------------
  3065. //+-------------------------------------------------------------------------
  3066. // X509_CERT_PAIR
  3067. //
  3068. // pvStructInfo points to the following CERT_PAIR.
  3069. //--------------------------------------------------------------------------
  3070. typedef struct _CERT_PAIR {
  3071. CERT_BLOB Forward; // OPTIONAL, if Forward.cbData == 0, omitted
  3072. CERT_BLOB Reverse; // OPTIONAL, if Reverse.cbData == 0, omitted
  3073. } CERT_PAIR, *PCERT_PAIR;
  3074. //+-------------------------------------------------------------------------
  3075. // szOID_CRL_NUMBER
  3076. //
  3077. // pvStructInfo points to an int.
  3078. //--------------------------------------------------------------------------
  3079. //+-------------------------------------------------------------------------
  3080. // szOID_DELTA_CRL_INDICATOR
  3081. //
  3082. // pvStructInfo points to an int.
  3083. //--------------------------------------------------------------------------
  3084. //+-------------------------------------------------------------------------
  3085. // szOID_ISSUING_DIST_POINT
  3086. // X509_ISSUING_DIST_POINT
  3087. //
  3088. // pvStructInfo points to the following CRL_ISSUING_DIST_POINT.
  3089. //
  3090. // For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  3091. // *pcbEncoded by CryptEncodeObject(X509_ISSUING_DIST_POINT)
  3092. //
  3093. // Error location consists of:
  3094. // ENTRY_INDEX - 8 bits << 16
  3095. // VALUE_INDEX - 16 bits (unicode character index)
  3096. //
  3097. // See X509_ALTERNATE_NAME for ENTRY_INDEX and VALUE_INDEX error location
  3098. // defines.
  3099. //--------------------------------------------------------------------------
  3100. typedef struct _CRL_ISSUING_DIST_POINT {
  3101. CRL_DIST_POINT_NAME DistPointName; // OPTIONAL
  3102. BOOL fOnlyContainsUserCerts;
  3103. BOOL fOnlyContainsCACerts;
  3104. CRYPT_BIT_BLOB OnlySomeReasonFlags; // OPTIONAL
  3105. BOOL fIndirectCRL;
  3106. } CRL_ISSUING_DIST_POINT, *PCRL_ISSUING_DIST_POINT;
  3107. //+-------------------------------------------------------------------------
  3108. // szOID_FRESHEST_CRL
  3109. //
  3110. // pvStructInfo points to CRL_DIST_POINTS_INFO.
  3111. //--------------------------------------------------------------------------
  3112. //+-------------------------------------------------------------------------
  3113. // szOID_NAME_CONSTRAINTS
  3114. // X509_NAME_CONSTRAINTS
  3115. //
  3116. // pvStructInfo points to the following CERT_NAME_CONSTRAINTS_INFO
  3117. //
  3118. // For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  3119. // *pcbEncoded by CryptEncodeObject(X509_NAME_CONSTRAINTS)
  3120. //
  3121. // Error location consists of:
  3122. // EXCLUDED_SUBTREE_BIT - 1 bit << 31 (0 for permitted, 1 for excluded)
  3123. // ENTRY_INDEX - 8 bits << 16
  3124. // VALUE_INDEX - 16 bits (unicode character index)
  3125. //
  3126. // See X509_ALTERNATE_NAME for ENTRY_INDEX and VALUE_INDEX error location
  3127. // defines.
  3128. //--------------------------------------------------------------------------
  3129. typedef struct _CERT_GENERAL_SUBTREE {
  3130. CERT_ALT_NAME_ENTRY Base;
  3131. DWORD dwMinimum;
  3132. BOOL fMaximum;
  3133. DWORD dwMaximum;
  3134. } CERT_GENERAL_SUBTREE, *PCERT_GENERAL_SUBTREE;
  3135. typedef struct _CERT_NAME_CONSTRAINTS_INFO {
  3136. DWORD cPermittedSubtree;
  3137. PCERT_GENERAL_SUBTREE rgPermittedSubtree;
  3138. DWORD cExcludedSubtree;
  3139. PCERT_GENERAL_SUBTREE rgExcludedSubtree;
  3140. } CERT_NAME_CONSTRAINTS_INFO, *PCERT_NAME_CONSTRAINTS_INFO;
  3141. #define CERT_EXCLUDED_SUBTREE_BIT 0x80000000L
  3142. #define IS_CERT_EXCLUDED_SUBTREE(X) \
  3143. (0 != (X & CERT_EXCLUDED_SUBTREE_BIT))
  3144. //+-------------------------------------------------------------------------
  3145. // szOID_NEXT_UPDATE_LOCATION
  3146. //
  3147. // pvStructInfo points to a CERT_ALT_NAME_INFO.
  3148. //--------------------------------------------------------------------------
  3149. //+-------------------------------------------------------------------------
  3150. // szOID_REMOVE_CERTIFICATE
  3151. //
  3152. // pvStructInfo points to an int which can be set to one of the following
  3153. // 0 - Add certificate
  3154. // 1 - Remove certificate
  3155. //--------------------------------------------------------------------------
  3156. //+-------------------------------------------------------------------------
  3157. // PKCS_CTL
  3158. // szOID_CTL
  3159. //
  3160. // pvStructInfo points to a CTL_INFO.
  3161. //--------------------------------------------------------------------------
  3162. //+-------------------------------------------------------------------------
  3163. // PKCS_SORTED_CTL
  3164. //
  3165. // pvStructInfo points to a CTL_INFO.
  3166. //
  3167. // Same as for PKCS_CTL, except, the CTL entries are sorted. The following
  3168. // extension containing the sort information is inserted as the first
  3169. // extension in the encoded CTL.
  3170. //
  3171. // Only supported for Encoding. CRYPT_ENCODE_ALLOC_FLAG flag must be
  3172. // set.
  3173. //--------------------------------------------------------------------------
  3174. //+-------------------------------------------------------------------------
  3175. // Sorted CTL TrustedSubjects extension
  3176. //
  3177. // Array of little endian DWORDs:
  3178. // [0] - Flags
  3179. // [1] - Count of HashBucket entry offsets
  3180. // [2] - Maximum HashBucket entry collision count
  3181. // [3 ..] (Count + 1) HashBucket entry offsets
  3182. //
  3183. // When this extension is present in the CTL,
  3184. // the ASN.1 encoded sequence of TrustedSubjects are HashBucket ordered.
  3185. //
  3186. // The entry offsets point to the start of the first encoded TrustedSubject
  3187. // sequence for the HashBucket. The encoded TrustedSubjects for a HashBucket
  3188. // continue until the encoded offset of the next HashBucket. A HashBucket has
  3189. // no entries if HashBucket[N] == HashBucket[N + 1].
  3190. //
  3191. // The HashBucket offsets are from the start of the ASN.1 encoded CTL_INFO.
  3192. //--------------------------------------------------------------------------
  3193. #define SORTED_CTL_EXT_FLAGS_OFFSET (0*4)
  3194. #define SORTED_CTL_EXT_COUNT_OFFSET (1*4)
  3195. #define SORTED_CTL_EXT_MAX_COLLISION_OFFSET (2*4)
  3196. #define SORTED_CTL_EXT_HASH_BUCKET_OFFSET (3*4)
  3197. // If the SubjectIdentifiers are a MD5 or SHA1 hash, the following flag is
  3198. // set. When set, the first 4 bytes of the SubjectIdentifier are used as
  3199. // the dwhash. Otherwise, the SubjectIdentifier bytes are hashed into dwHash.
  3200. // In either case the HashBucket index = dwHash % cHashBucket.
  3201. #define SORTED_CTL_EXT_HASHED_SUBJECT_IDENTIFIER_FLAG 0x1
  3202. //+-------------------------------------------------------------------------
  3203. // X509_MULTI_BYTE_UINT
  3204. //
  3205. // pvStructInfo points to a CRYPT_UINT_BLOB. Before encoding, inserts a
  3206. // leading 0x00. After decoding, removes a leading 0x00.
  3207. //--------------------------------------------------------------------------
  3208. //+-------------------------------------------------------------------------
  3209. // X509_DSS_PUBLICKEY
  3210. //
  3211. // pvStructInfo points to a CRYPT_UINT_BLOB.
  3212. //--------------------------------------------------------------------------
  3213. //+-------------------------------------------------------------------------
  3214. // X509_DSS_PARAMETERS
  3215. //
  3216. // pvStructInfo points to following CERT_DSS_PARAMETERS data structure.
  3217. //--------------------------------------------------------------------------
  3218. typedef struct _CERT_DSS_PARAMETERS {
  3219. CRYPT_UINT_BLOB p;
  3220. CRYPT_UINT_BLOB q;
  3221. CRYPT_UINT_BLOB g;
  3222. } CERT_DSS_PARAMETERS, *PCERT_DSS_PARAMETERS;
  3223. //+-------------------------------------------------------------------------
  3224. // X509_DSS_SIGNATURE
  3225. //
  3226. // pvStructInfo is a BYTE rgbSignature[CERT_DSS_SIGNATURE_LEN]. The
  3227. // bytes are ordered as output by the DSS CSP's CryptSignHash().
  3228. //--------------------------------------------------------------------------
  3229. #define CERT_DSS_R_LEN 20
  3230. #define CERT_DSS_S_LEN 20
  3231. #define CERT_DSS_SIGNATURE_LEN (CERT_DSS_R_LEN + CERT_DSS_S_LEN)
  3232. // Sequence of 2 unsigned integers (the extra +1 is for a potential leading
  3233. // 0x00 to make the integer unsigned)
  3234. #define CERT_MAX_ASN_ENCODED_DSS_SIGNATURE_LEN (2 + 2*(2 + 20 +1))
  3235. //+-------------------------------------------------------------------------
  3236. // X509_DH_PUBLICKEY
  3237. //
  3238. // pvStructInfo points to a CRYPT_UINT_BLOB.
  3239. //--------------------------------------------------------------------------
  3240. //+-------------------------------------------------------------------------
  3241. // X509_DH_PARAMETERS
  3242. //
  3243. // pvStructInfo points to following CERT_DH_PARAMETERS data structure.
  3244. //--------------------------------------------------------------------------
  3245. typedef struct _CERT_DH_PARAMETERS {
  3246. CRYPT_UINT_BLOB p;
  3247. CRYPT_UINT_BLOB g;
  3248. } CERT_DH_PARAMETERS, *PCERT_DH_PARAMETERS;
  3249. //+-------------------------------------------------------------------------
  3250. // X942_DH_PARAMETERS
  3251. //
  3252. // pvStructInfo points to following CERT_X942_DH_PARAMETERS data structure.
  3253. //
  3254. // If q.cbData == 0, then, the following fields are zero'ed.
  3255. //--------------------------------------------------------------------------
  3256. typedef struct _CERT_X942_DH_VALIDATION_PARAMS {
  3257. CRYPT_BIT_BLOB seed;
  3258. DWORD pgenCounter;
  3259. } CERT_X942_DH_VALIDATION_PARAMS, *PCERT_X942_DH_VALIDATION_PARAMS;
  3260. typedef struct _CERT_X942_DH_PARAMETERS {
  3261. CRYPT_UINT_BLOB p; // odd prime, p = jq + 1
  3262. CRYPT_UINT_BLOB g; // generator, g
  3263. CRYPT_UINT_BLOB q; // factor of p - 1, OPTIONAL
  3264. CRYPT_UINT_BLOB j; // subgroup factor, OPTIONAL
  3265. PCERT_X942_DH_VALIDATION_PARAMS pValidationParams; // OPTIONAL
  3266. } CERT_X942_DH_PARAMETERS, *PCERT_X942_DH_PARAMETERS;
  3267. //+-------------------------------------------------------------------------
  3268. // X942_OTHER_INFO
  3269. //
  3270. // pvStructInfo points to following CRYPT_X942_OTHER_INFO data structure.
  3271. //
  3272. // rgbCounter and rgbKeyLength are in Little Endian order.
  3273. //--------------------------------------------------------------------------
  3274. #define CRYPT_X942_COUNTER_BYTE_LENGTH 4
  3275. #define CRYPT_X942_KEY_LENGTH_BYTE_LENGTH 4
  3276. #define CRYPT_X942_PUB_INFO_BYTE_LENGTH (512/8)
  3277. typedef struct _CRYPT_X942_OTHER_INFO {
  3278. LPSTR pszContentEncryptionObjId;
  3279. BYTE rgbCounter[CRYPT_X942_COUNTER_BYTE_LENGTH];
  3280. BYTE rgbKeyLength[CRYPT_X942_KEY_LENGTH_BYTE_LENGTH];
  3281. CRYPT_DATA_BLOB PubInfo; // OPTIONAL
  3282. } CRYPT_X942_OTHER_INFO, *PCRYPT_X942_OTHER_INFO;
  3283. //+-------------------------------------------------------------------------
  3284. // PKCS_RC2_CBC_PARAMETERS
  3285. // szOID_RSA_RC2CBC
  3286. //
  3287. // pvStructInfo points to following CRYPT_RC2_CBC_PARAMETERS data structure.
  3288. //--------------------------------------------------------------------------
  3289. typedef struct _CRYPT_RC2_CBC_PARAMETERS {
  3290. DWORD dwVersion;
  3291. BOOL fIV; // set if has following IV
  3292. BYTE rgbIV[8];
  3293. } CRYPT_RC2_CBC_PARAMETERS, *PCRYPT_RC2_CBC_PARAMETERS;
  3294. #define CRYPT_RC2_40BIT_VERSION 160
  3295. #define CRYPT_RC2_56BIT_VERSION 52
  3296. #define CRYPT_RC2_64BIT_VERSION 120
  3297. #define CRYPT_RC2_128BIT_VERSION 58
  3298. //+-------------------------------------------------------------------------
  3299. // PKCS_SMIME_CAPABILITIES
  3300. // szOID_RSA_SMIMECapabilities
  3301. //
  3302. // pvStructInfo points to following CRYPT_SMIME_CAPABILITIES data structure.
  3303. //
  3304. // Note, for CryptEncodeObject(X509_ASN_ENCODING), Parameters.cbData == 0
  3305. // causes the encoded parameters to be omitted and not encoded as a NULL
  3306. // (05 00) as is done when encoding a CRYPT_ALGORITHM_IDENTIFIER. This
  3307. // is per the SMIME specification for encoding capabilities.
  3308. //--------------------------------------------------------------------------
  3309. typedef struct _CRYPT_SMIME_CAPABILITY {
  3310. LPSTR pszObjId;
  3311. CRYPT_OBJID_BLOB Parameters;
  3312. } CRYPT_SMIME_CAPABILITY, *PCRYPT_SMIME_CAPABILITY;
  3313. typedef struct _CRYPT_SMIME_CAPABILITIES {
  3314. DWORD cCapability;
  3315. PCRYPT_SMIME_CAPABILITY rgCapability;
  3316. } CRYPT_SMIME_CAPABILITIES, *PCRYPT_SMIME_CAPABILITIES;
  3317. //+-------------------------------------------------------------------------
  3318. // PKCS7_SIGNER_INFO
  3319. //
  3320. // pvStructInfo points to CMSG_SIGNER_INFO.
  3321. //--------------------------------------------------------------------------
  3322. //+-------------------------------------------------------------------------
  3323. // CMS_SIGNER_INFO
  3324. //
  3325. // pvStructInfo points to CMSG_CMS_SIGNER_INFO.
  3326. //--------------------------------------------------------------------------
  3327. //+-------------------------------------------------------------------------
  3328. // Verisign Certificate Extension Object Identifiers
  3329. //--------------------------------------------------------------------------
  3330. // Octet String containing Boolean
  3331. #define szOID_VERISIGN_PRIVATE_6_9 "2.16.840.1.113733.1.6.9"
  3332. // Octet String containing IA5 string: lower case 32 char hex string
  3333. #define szOID_VERISIGN_ONSITE_JURISDICTION_HASH "2.16.840.1.113733.1.6.11"
  3334. // Octet String containing Bit string
  3335. #define szOID_VERISIGN_BITSTRING_6_13 "2.16.840.1.113733.1.6.13"
  3336. // EKU
  3337. #define szOID_VERISIGN_ISS_STRONG_CRYPTO "2.16.840.1.113733.1.8.1"
  3338. //+-------------------------------------------------------------------------
  3339. // Netscape Certificate Extension Object Identifiers
  3340. //--------------------------------------------------------------------------
  3341. #define szOID_NETSCAPE "2.16.840.1.113730"
  3342. #define szOID_NETSCAPE_CERT_EXTENSION "2.16.840.1.113730.1"
  3343. #define szOID_NETSCAPE_CERT_TYPE "2.16.840.1.113730.1.1"
  3344. #define szOID_NETSCAPE_BASE_URL "2.16.840.1.113730.1.2"
  3345. #define szOID_NETSCAPE_REVOCATION_URL "2.16.840.1.113730.1.3"
  3346. #define szOID_NETSCAPE_CA_REVOCATION_URL "2.16.840.1.113730.1.4"
  3347. #define szOID_NETSCAPE_CERT_RENEWAL_URL "2.16.840.1.113730.1.7"
  3348. #define szOID_NETSCAPE_CA_POLICY_URL "2.16.840.1.113730.1.8"
  3349. #define szOID_NETSCAPE_SSL_SERVER_NAME "2.16.840.1.113730.1.12"
  3350. #define szOID_NETSCAPE_COMMENT "2.16.840.1.113730.1.13"
  3351. //+-------------------------------------------------------------------------
  3352. // Netscape Certificate Data Type Object Identifiers
  3353. //--------------------------------------------------------------------------
  3354. #define szOID_NETSCAPE_DATA_TYPE "2.16.840.1.113730.2"
  3355. #define szOID_NETSCAPE_CERT_SEQUENCE "2.16.840.1.113730.2.5"
  3356. //+-------------------------------------------------------------------------
  3357. // szOID_NETSCAPE_CERT_TYPE extension
  3358. //
  3359. // Its value is a bit string. CryptDecodeObject/CryptEncodeObject using
  3360. // X509_BITS or X509_BITS_WITHOUT_TRAILING_ZEROES.
  3361. //
  3362. // The following bits are defined:
  3363. //--------------------------------------------------------------------------
  3364. #define NETSCAPE_SSL_CLIENT_AUTH_CERT_TYPE 0x80
  3365. #define NETSCAPE_SSL_SERVER_AUTH_CERT_TYPE 0x40
  3366. #define NETSCAPE_SMIME_CERT_TYPE 0x20
  3367. #define NETSCAPE_SIGN_CERT_TYPE 0x10
  3368. #define NETSCAPE_SSL_CA_CERT_TYPE 0x04
  3369. #define NETSCAPE_SMIME_CA_CERT_TYPE 0x02
  3370. #define NETSCAPE_SIGN_CA_CERT_TYPE 0x01
  3371. //+-------------------------------------------------------------------------
  3372. // szOID_NETSCAPE_BASE_URL extension
  3373. //
  3374. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3375. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3376. // dwValueType = CERT_RDN_IA5_STRING.
  3377. //
  3378. // When present this string is added to the beginning of all relative URLs
  3379. // in the certificate. This extension can be considered an optimization
  3380. // to reduce the size of the URL extensions.
  3381. //--------------------------------------------------------------------------
  3382. //+-------------------------------------------------------------------------
  3383. // szOID_NETSCAPE_REVOCATION_URL extension
  3384. //
  3385. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3386. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3387. // dwValueType = CERT_RDN_IA5_STRING.
  3388. //
  3389. // It is a relative or absolute URL that can be used to check the
  3390. // revocation status of a certificate. The revocation check will be
  3391. // performed as an HTTP GET method using a url that is the concatenation of
  3392. // revocation-url and certificate-serial-number.
  3393. // Where the certificate-serial-number is encoded as a string of
  3394. // ascii hexadecimal digits. For example, if the netscape-base-url is
  3395. // https://www.certs-r-us.com/, the netscape-revocation-url is
  3396. // cgi-bin/check-rev.cgi?, and the certificate serial number is 173420,
  3397. // the resulting URL would be:
  3398. // https://www.certs-r-us.com/cgi-bin/check-rev.cgi?02a56c
  3399. //
  3400. // The server should return a document with a Content-Type of
  3401. // application/x-netscape-revocation. The document should contain
  3402. // a single ascii digit, '1' if the certificate is not curently valid,
  3403. // and '0' if it is curently valid.
  3404. //
  3405. // Note: for all of the URLs that include the certificate serial number,
  3406. // the serial number will be encoded as a string which consists of an even
  3407. // number of hexadecimal digits. If the number of significant digits is odd,
  3408. // the string will have a single leading zero to ensure an even number of
  3409. // digits is generated.
  3410. //--------------------------------------------------------------------------
  3411. //+-------------------------------------------------------------------------
  3412. // szOID_NETSCAPE_CA_REVOCATION_URL extension
  3413. //
  3414. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3415. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3416. // dwValueType = CERT_RDN_IA5_STRING.
  3417. //
  3418. // It is a relative or absolute URL that can be used to check the
  3419. // revocation status of any certificates that are signed by the CA that
  3420. // this certificate belongs to. This extension is only valid in CA
  3421. // certificates. The use of this extension is the same as the above
  3422. // szOID_NETSCAPE_REVOCATION_URL extension.
  3423. //--------------------------------------------------------------------------
  3424. //+-------------------------------------------------------------------------
  3425. // szOID_NETSCAPE_CERT_RENEWAL_URL extension
  3426. //
  3427. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3428. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3429. // dwValueType = CERT_RDN_IA5_STRING.
  3430. //
  3431. // It is a relative or absolute URL that points to a certificate renewal
  3432. // form. The renewal form will be accessed with an HTTP GET method using a
  3433. // url that is the concatenation of renewal-url and
  3434. // certificate-serial-number. Where the certificate-serial-number is
  3435. // encoded as a string of ascii hexadecimal digits. For example, if the
  3436. // netscape-base-url is https://www.certs-r-us.com/, the
  3437. // netscape-cert-renewal-url is cgi-bin/check-renew.cgi?, and the
  3438. // certificate serial number is 173420, the resulting URL would be:
  3439. // https://www.certs-r-us.com/cgi-bin/check-renew.cgi?02a56c
  3440. // The document returned should be an HTML form that will allow the user
  3441. // to request a renewal of their certificate.
  3442. //--------------------------------------------------------------------------
  3443. //+-------------------------------------------------------------------------
  3444. // szOID_NETSCAPE_CA_POLICY_URL extension
  3445. //
  3446. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3447. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3448. // dwValueType = CERT_RDN_IA5_STRING.
  3449. //
  3450. // It is a relative or absolute URL that points to a web page that
  3451. // describes the policies under which the certificate was issued.
  3452. //--------------------------------------------------------------------------
  3453. //+-------------------------------------------------------------------------
  3454. // szOID_NETSCAPE_SSL_SERVER_NAME extension
  3455. //
  3456. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3457. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3458. // dwValueType = CERT_RDN_IA5_STRING.
  3459. //
  3460. // It is a "shell expression" that can be used to match the hostname of the
  3461. // SSL server that is using this certificate. It is recommended that if
  3462. // the server's hostname does not match this pattern the user be notified
  3463. // and given the option to terminate the SSL connection. If this extension
  3464. // is not present then the CommonName in the certificate subject's
  3465. // distinguished name is used for the same purpose.
  3466. //--------------------------------------------------------------------------
  3467. //+-------------------------------------------------------------------------
  3468. // szOID_NETSCAPE_COMMENT extension
  3469. //
  3470. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3471. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3472. // dwValueType = CERT_RDN_IA5_STRING.
  3473. //
  3474. // It is a comment that may be displayed to the user when the certificate
  3475. // is viewed.
  3476. //--------------------------------------------------------------------------
  3477. //+-------------------------------------------------------------------------
  3478. // szOID_NETSCAPE_CERT_SEQUENCE
  3479. //
  3480. // Its value is a PKCS#7 ContentInfo structure wrapping a sequence of
  3481. // certificates. The value of the contentType field is
  3482. // szOID_NETSCAPE_CERT_SEQUENCE, while the content field is the following
  3483. // structure:
  3484. // CertificateSequence ::= SEQUENCE OF Certificate.
  3485. //
  3486. // CryptDecodeObject/CryptEncodeObject using
  3487. // PKCS_CONTENT_INFO_SEQUENCE_OF_ANY, where,
  3488. // pszObjId = szOID_NETSCAPE_CERT_SEQUENCE and the CRYPT_DER_BLOBs point
  3489. // to encoded X509 certificates.
  3490. //--------------------------------------------------------------------------
  3491. //+=========================================================================
  3492. // Certificate Management Messages over CMS (CMC) Data Structures
  3493. //==========================================================================
  3494. // Content Type (request)
  3495. #define szOID_CT_PKI_DATA "1.3.6.1.5.5.7.12.2"
  3496. // Content Type (response)
  3497. #define szOID_CT_PKI_RESPONSE "1.3.6.1.5.5.7.12.3"
  3498. // Signature value that only contains the hash octets. The parameters for
  3499. // this algorithm must be present and must be encoded as NULL.
  3500. #define szOID_PKIX_NO_SIGNATURE "1.3.6.1.5.5.7.6.2"
  3501. #define szOID_CMC "1.3.6.1.5.5.7.7"
  3502. #define szOID_CMC_STATUS_INFO "1.3.6.1.5.5.7.7.1"
  3503. #define szOID_CMC_IDENTIFICATION "1.3.6.1.5.5.7.7.2"
  3504. #define szOID_CMC_IDENTITY_PROOF "1.3.6.1.5.5.7.7.3"
  3505. #define szOID_CMC_DATA_RETURN "1.3.6.1.5.5.7.7.4"
  3506. // Transaction Id (integer)
  3507. #define szOID_CMC_TRANSACTION_ID "1.3.6.1.5.5.7.7.5"
  3508. // Sender Nonce (octet string)
  3509. #define szOID_CMC_SENDER_NONCE "1.3.6.1.5.5.7.7.6"
  3510. // Recipient Nonce (octet string)
  3511. #define szOID_CMC_RECIPIENT_NONCE "1.3.6.1.5.5.7.7.7"
  3512. #define szOID_CMC_ADD_EXTENSIONS "1.3.6.1.5.5.7.7.8"
  3513. #define szOID_CMC_ENCRYPTED_POP "1.3.6.1.5.5.7.7.9"
  3514. #define szOID_CMC_DECRYPTED_POP "1.3.6.1.5.5.7.7.10"
  3515. #define szOID_CMC_LRA_POP_WITNESS "1.3.6.1.5.5.7.7.11"
  3516. // Issuer Name + Serial
  3517. #define szOID_CMC_GET_CERT "1.3.6.1.5.5.7.7.15"
  3518. // Issuer Name [+ CRL Name] + Time [+ Reasons]
  3519. #define szOID_CMC_GET_CRL "1.3.6.1.5.5.7.7.16"
  3520. // Issuer Name + Serial [+ Reason] [+ Effective Time] [+ Secret] [+ Comment]
  3521. #define szOID_CMC_REVOKE_REQUEST "1.3.6.1.5.5.7.7.17"
  3522. // (octet string) URL-style parameter list (IA5?)
  3523. #define szOID_CMC_REG_INFO "1.3.6.1.5.5.7.7.18"
  3524. #define szOID_CMC_RESPONSE_INFO "1.3.6.1.5.5.7.7.19"
  3525. // (octet string)
  3526. #define szOID_CMC_QUERY_PENDING "1.3.6.1.5.5.7.7.21"
  3527. #define szOID_CMC_ID_POP_LINK_RANDOM "1.3.6.1.5.5.7.7.22"
  3528. #define szOID_CMC_ID_POP_LINK_WITNESS "1.3.6.1.5.5.7.7.23"
  3529. // optional Name + Integer
  3530. #define szOID_CMC_ID_CONFIRM_CERT_ACCEPTANCE "1.3.6.1.5.5.7.7.24"
  3531. #define szOID_CMC_ADD_ATTRIBUTES "1.3.6.1.4.1.311.10.10.1"
  3532. //+-------------------------------------------------------------------------
  3533. // CMC_DATA
  3534. // CMC_RESPONSE
  3535. //
  3536. // Certificate Management Messages over CMS (CMC) PKIData and Response
  3537. // messages.
  3538. //
  3539. // For CMC_DATA, pvStructInfo points to a CMC_DATA_INFO.
  3540. // CMC_DATA_INFO contains optional arrays of tagged attributes, requests,
  3541. // content info and/or arbitrary other messages.
  3542. //
  3543. // For CMC_RESPONSE, pvStructInfo points to a CMC_RESPONSE_INFO.
  3544. // CMC_RESPONSE_INFO is the same as CMC_DATA_INFO without the tagged
  3545. // requests.
  3546. //--------------------------------------------------------------------------
  3547. typedef struct _CMC_TAGGED_ATTRIBUTE {
  3548. DWORD dwBodyPartID;
  3549. CRYPT_ATTRIBUTE Attribute;
  3550. } CMC_TAGGED_ATTRIBUTE, *PCMC_TAGGED_ATTRIBUTE;
  3551. typedef struct _CMC_TAGGED_CERT_REQUEST {
  3552. DWORD dwBodyPartID;
  3553. CRYPT_DER_BLOB SignedCertRequest;
  3554. } CMC_TAGGED_CERT_REQUEST, *PCMC_TAGGED_CERT_REQUEST;
  3555. typedef struct _CMC_TAGGED_REQUEST {
  3556. DWORD dwTaggedRequestChoice;
  3557. union {
  3558. // CMC_TAGGED_CERT_REQUEST_CHOICE
  3559. PCMC_TAGGED_CERT_REQUEST pTaggedCertRequest;
  3560. };
  3561. } CMC_TAGGED_REQUEST, *PCMC_TAGGED_REQUEST;
  3562. #define CMC_TAGGED_CERT_REQUEST_CHOICE 1
  3563. typedef struct _CMC_TAGGED_CONTENT_INFO {
  3564. DWORD dwBodyPartID;
  3565. CRYPT_DER_BLOB EncodedContentInfo;
  3566. } CMC_TAGGED_CONTENT_INFO, *PCMC_TAGGED_CONTENT_INFO;
  3567. typedef struct _CMC_TAGGED_OTHER_MSG {
  3568. DWORD dwBodyPartID;
  3569. LPSTR pszObjId;
  3570. CRYPT_OBJID_BLOB Value;
  3571. } CMC_TAGGED_OTHER_MSG, *PCMC_TAGGED_OTHER_MSG;
  3572. // All the tagged arrays are optional
  3573. typedef struct _CMC_DATA_INFO {
  3574. DWORD cTaggedAttribute;
  3575. PCMC_TAGGED_ATTRIBUTE rgTaggedAttribute;
  3576. DWORD cTaggedRequest;
  3577. PCMC_TAGGED_REQUEST rgTaggedRequest;
  3578. DWORD cTaggedContentInfo;
  3579. PCMC_TAGGED_CONTENT_INFO rgTaggedContentInfo;
  3580. DWORD cTaggedOtherMsg;
  3581. PCMC_TAGGED_OTHER_MSG rgTaggedOtherMsg;
  3582. } CMC_DATA_INFO, *PCMC_DATA_INFO;
  3583. // All the tagged arrays are optional
  3584. typedef struct _CMC_RESPONSE_INFO {
  3585. DWORD cTaggedAttribute;
  3586. PCMC_TAGGED_ATTRIBUTE rgTaggedAttribute;
  3587. DWORD cTaggedContentInfo;
  3588. PCMC_TAGGED_CONTENT_INFO rgTaggedContentInfo;
  3589. DWORD cTaggedOtherMsg;
  3590. PCMC_TAGGED_OTHER_MSG rgTaggedOtherMsg;
  3591. } CMC_RESPONSE_INFO, *PCMC_RESPONSE_INFO;
  3592. //+-------------------------------------------------------------------------
  3593. // CMC_STATUS
  3594. //
  3595. // Certificate Management Messages over CMS (CMC) Status.
  3596. //
  3597. // pvStructInfo points to a CMC_STATUS_INFO.
  3598. //--------------------------------------------------------------------------
  3599. typedef struct _CMC_PEND_INFO {
  3600. CRYPT_DATA_BLOB PendToken;
  3601. FILETIME PendTime;
  3602. } CMC_PEND_INFO, *PCMC_PEND_INFO;
  3603. typedef struct _CMC_STATUS_INFO {
  3604. DWORD dwStatus;
  3605. DWORD cBodyList;
  3606. DWORD *rgdwBodyList;
  3607. LPWSTR pwszStatusString; // OPTIONAL
  3608. DWORD dwOtherInfoChoice;
  3609. union {
  3610. // CMC_OTHER_INFO_NO_CHOICE
  3611. // none
  3612. // CMC_OTHER_INFO_FAIL_CHOICE
  3613. DWORD dwFailInfo;
  3614. // CMC_OTHER_INFO_PEND_CHOICE
  3615. PCMC_PEND_INFO pPendInfo;
  3616. };
  3617. } CMC_STATUS_INFO, *PCMC_STATUS_INFO;
  3618. #define CMC_OTHER_INFO_NO_CHOICE 0
  3619. #define CMC_OTHER_INFO_FAIL_CHOICE 1
  3620. #define CMC_OTHER_INFO_PEND_CHOICE 2
  3621. //
  3622. // dwStatus values
  3623. //
  3624. // Request was granted
  3625. #define CMC_STATUS_SUCCESS 0
  3626. // Request failed, more information elsewhere in the message
  3627. #define CMC_STATUS_FAILED 2
  3628. // The request body part has not yet been processed. Requester is responsible
  3629. // to poll back. May only be returned for certificate request operations.
  3630. #define CMC_STATUS_PENDING 3
  3631. // The requested operation is not supported
  3632. #define CMC_STATUS_NO_SUPPORT 4
  3633. // Confirmation using the idConfirmCertAcceptance control is required
  3634. // before use of certificate
  3635. #define CMC_STATUS_CONFIRM_REQUIRED 5
  3636. //
  3637. // dwFailInfo values
  3638. //
  3639. // Unrecognized or unsupported algorithm
  3640. #define CMC_FAIL_BAD_ALG 0
  3641. // Integrity check failed
  3642. #define CMC_FAIL_BAD_MESSAGE_CHECK 1
  3643. // Transaction not permitted or supported
  3644. #define CMC_FAIL_BAD_REQUEST 2
  3645. // Message time field was not sufficiently close to the system time
  3646. #define CMC_FAIL_BAD_TIME 3
  3647. // No certificate could be identified matching the provided criteria
  3648. #define CMC_FAIL_BAD_CERT_ID 4
  3649. // A requested X.509 extension is not supported by the recipient CA.
  3650. #define CMC_FAIL_UNSUPORTED_EXT 5
  3651. // Private key material must be supplied
  3652. #define CMC_FAIL_MUST_ARCHIVE_KEYS 6
  3653. // Identification Attribute failed to verify
  3654. #define CMC_FAIL_BAD_IDENTITY 7
  3655. // Server requires a POP proof before issuing certificate
  3656. #define CMC_FAIL_POP_REQUIRED 8
  3657. // POP processing failed
  3658. #define CMC_FAIL_POP_FAILED 9
  3659. // Server policy does not allow key re-use
  3660. #define CMC_FAIL_NO_KEY_REUSE 10
  3661. #define CMC_FAIL_INTERNAL_CA_ERROR 11
  3662. #define CMC_FAIL_TRY_LATER 12
  3663. //+-------------------------------------------------------------------------
  3664. // CMC_ADD_EXTENSIONS
  3665. //
  3666. // Certificate Management Messages over CMS (CMC) Add Extensions control
  3667. // attribute.
  3668. //
  3669. // pvStructInfo points to a CMC_ADD_EXTENSIONS_INFO.
  3670. //--------------------------------------------------------------------------
  3671. typedef struct _CMC_ADD_EXTENSIONS_INFO {
  3672. DWORD dwCmcDataReference;
  3673. DWORD cCertReference;
  3674. DWORD *rgdwCertReference;
  3675. DWORD cExtension;
  3676. PCERT_EXTENSION rgExtension;
  3677. } CMC_ADD_EXTENSIONS_INFO, *PCMC_ADD_EXTENSIONS_INFO;
  3678. //+-------------------------------------------------------------------------
  3679. // CMC_ADD_ATTRIBUTES
  3680. //
  3681. // Certificate Management Messages over CMS (CMC) Add Attributes control
  3682. // attribute.
  3683. //
  3684. // pvStructInfo points to a CMC_ADD_ATTRIBUTES_INFO.
  3685. //--------------------------------------------------------------------------
  3686. typedef struct _CMC_ADD_ATTRIBUTES_INFO {
  3687. DWORD dwCmcDataReference;
  3688. DWORD cCertReference;
  3689. DWORD *rgdwCertReference;
  3690. DWORD cAttribute;
  3691. PCRYPT_ATTRIBUTE rgAttribute;
  3692. } CMC_ADD_ATTRIBUTES_INFO, *PCMC_ADD_ATTRIBUTES_INFO;
  3693. //+-------------------------------------------------------------------------
  3694. // X509_CERTIFICATE_TEMPLATE
  3695. // szOID_CERTIFICATE_TEMPLATE
  3696. //
  3697. // pvStructInfo points to following CERT_TEMPLATE_EXT data structure.
  3698. //
  3699. //--------------------------------------------------------------------------
  3700. typedef struct _CERT_TEMPLATE_EXT {
  3701. LPSTR pszObjId;
  3702. DWORD dwMajorVersion;
  3703. BOOL fMinorVersion; // TRUE for a minor version
  3704. DWORD dwMinorVersion;
  3705. } CERT_TEMPLATE_EXT, *PCERT_TEMPLATE_EXT;
  3706. //+=========================================================================
  3707. // Object IDentifier (OID) Installable Functions: Data Structures and APIs
  3708. //==========================================================================
  3709. typedef void *HCRYPTOIDFUNCSET;
  3710. typedef void *HCRYPTOIDFUNCADDR;
  3711. // Predefined OID Function Names
  3712. #define CRYPT_OID_ENCODE_OBJECT_FUNC "CryptDllEncodeObject"
  3713. #define CRYPT_OID_DECODE_OBJECT_FUNC "CryptDllDecodeObject"
  3714. #define CRYPT_OID_ENCODE_OBJECT_EX_FUNC "CryptDllEncodeObjectEx"
  3715. #define CRYPT_OID_DECODE_OBJECT_EX_FUNC "CryptDllDecodeObjectEx"
  3716. #define CRYPT_OID_CREATE_COM_OBJECT_FUNC "CryptDllCreateCOMObject"
  3717. #define CRYPT_OID_VERIFY_REVOCATION_FUNC "CertDllVerifyRevocation"
  3718. #define CRYPT_OID_VERIFY_CTL_USAGE_FUNC "CertDllVerifyCTLUsage"
  3719. #define CRYPT_OID_FORMAT_OBJECT_FUNC "CryptDllFormatObject"
  3720. #define CRYPT_OID_FIND_OID_INFO_FUNC "CryptDllFindOIDInfo"
  3721. #define CRYPT_OID_FIND_LOCALIZED_NAME_FUNC "CryptDllFindLocalizedName"
  3722. // CryptDllEncodeObject has same function signature as CryptEncodeObject.
  3723. // CryptDllDecodeObject has same function signature as CryptDecodeObject.
  3724. // CryptDllEncodeObjectEx has same function signature as CryptEncodeObjectEx.
  3725. // The Ex version MUST support the CRYPT_ENCODE_ALLOC_FLAG option.
  3726. //
  3727. // If an Ex function isn't installed or registered, then, attempts to find
  3728. // a non-EX version. If the ALLOC flag is set, then, CryptEncodeObjectEx,
  3729. // does the allocation and calls the non-EX version twice.
  3730. // CryptDllDecodeObjectEx has same function signature as CryptDecodeObjectEx.
  3731. // The Ex version MUST support the CRYPT_DECODE_ALLOC_FLAG option.
  3732. //
  3733. // If an Ex function isn't installed or registered, then, attempts to find
  3734. // a non-EX version. If the ALLOC flag is set, then, CryptDecodeObjectEx,
  3735. // does the allocation and calls the non-EX version twice.
  3736. // CryptDllCreateCOMObject has the following signature:
  3737. // BOOL WINAPI CryptDllCreateCOMObject(
  3738. // IN DWORD dwEncodingType,
  3739. // IN LPCSTR pszOID,
  3740. // IN PCRYPT_DATA_BLOB pEncodedContent,
  3741. // IN DWORD dwFlags,
  3742. // IN REFIID riid,
  3743. // OUT void **ppvObj);
  3744. // CertDllVerifyRevocation has the same signature as CertVerifyRevocation
  3745. // (See CertVerifyRevocation for details on when called)
  3746. // CertDllVerifyCTLUsage has the same signature as CertVerifyCTLUsage
  3747. // CryptDllFindOIDInfo currently is only used to store values used by
  3748. // CryptFindOIDInfo. See CryptFindOIDInfo() for more details.
  3749. // CryptDllFindLocalizedName is only used to store localized string
  3750. // values used by CryptFindLocalizedName. See CryptFindLocalizedName() for
  3751. // more details.
  3752. // Example of a complete OID Function Registry Name:
  3753. // HKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography\OID
  3754. // Encoding Type 1\CryptDllEncodeObject\1.2.3
  3755. //
  3756. // The key's L"Dll" value contains the name of the Dll.
  3757. // The key's L"FuncName" value overrides the default function name
  3758. #define CRYPT_OID_REGPATH "Software\\Microsoft\\Cryptography\\OID"
  3759. #define CRYPT_OID_REG_ENCODING_TYPE_PREFIX "EncodingType "
  3760. #define CRYPT_OID_REG_DLL_VALUE_NAME L"Dll"
  3761. #define CRYPT_OID_REG_FUNC_NAME_VALUE_NAME L"FuncName"
  3762. #define CRYPT_OID_REG_FUNC_NAME_VALUE_NAME_A "FuncName"
  3763. // CRYPT_INSTALL_OID_FUNC_BEFORE_FLAG can be set in the key's L"CryptFlags"
  3764. // value to register the functions before the installed functions.
  3765. //
  3766. // CryptSetOIDFunctionValue must be called to set this value. L"CryptFlags"
  3767. // must be set using a dwValueType of REG_DWORD.
  3768. #define CRYPT_OID_REG_FLAGS_VALUE_NAME L"CryptFlags"
  3769. // OID used for Default OID functions
  3770. #define CRYPT_DEFAULT_OID "DEFAULT"
  3771. typedef struct _CRYPT_OID_FUNC_ENTRY {
  3772. LPCSTR pszOID;
  3773. void *pvFuncAddr;
  3774. } CRYPT_OID_FUNC_ENTRY, *PCRYPT_OID_FUNC_ENTRY;
  3775. #define CRYPT_INSTALL_OID_FUNC_BEFORE_FLAG 1
  3776. //+-------------------------------------------------------------------------
  3777. // Install a set of callable OID function addresses.
  3778. //
  3779. // By default the functions are installed at end of the list.
  3780. // Set CRYPT_INSTALL_OID_FUNC_BEFORE_FLAG to install at beginning of list.
  3781. //
  3782. // hModule should be updated with the hModule passed to DllMain to prevent
  3783. // the Dll containing the function addresses from being unloaded by
  3784. // CryptGetOIDFuncAddress/CryptFreeOIDFunctionAddress. This would be the
  3785. // case when the Dll has also regsvr32'ed OID functions via
  3786. // CryptRegisterOIDFunction.
  3787. //
  3788. // DEFAULT functions are installed by setting rgFuncEntry[].pszOID =
  3789. // CRYPT_DEFAULT_OID.
  3790. //--------------------------------------------------------------------------
  3791. WINCRYPT32API
  3792. BOOL
  3793. WINAPI
  3794. CryptInstallOIDFunctionAddress(
  3795. IN HMODULE hModule, // hModule passed to DllMain
  3796. IN DWORD dwEncodingType,
  3797. IN LPCSTR pszFuncName,
  3798. IN DWORD cFuncEntry,
  3799. IN const CRYPT_OID_FUNC_ENTRY rgFuncEntry[],
  3800. IN DWORD dwFlags
  3801. );
  3802. //+-------------------------------------------------------------------------
  3803. // Initialize and return handle to the OID function set identified by its
  3804. // function name.
  3805. //
  3806. // If the set already exists, a handle to the existing set is returned.
  3807. //--------------------------------------------------------------------------
  3808. WINCRYPT32API
  3809. HCRYPTOIDFUNCSET
  3810. WINAPI
  3811. CryptInitOIDFunctionSet(
  3812. IN LPCSTR pszFuncName,
  3813. IN DWORD dwFlags
  3814. );
  3815. //+-------------------------------------------------------------------------
  3816. // Search the list of installed functions for an encoding type and OID match.
  3817. // If not found, search the registry.
  3818. //
  3819. // For success, returns TRUE with *ppvFuncAddr updated with the function's
  3820. // address and *phFuncAddr updated with the function address's handle.
  3821. // The function's handle is AddRef'ed. CryptFreeOIDFunctionAddress needs to
  3822. // be called to release it.
  3823. //
  3824. // For a registry match, the Dll containing the function is loaded.
  3825. //
  3826. // By default, both the registered and installed function lists are searched.
  3827. // Set CRYPT_GET_INSTALLED_OID_FUNC_FLAG to only search the installed list
  3828. // of functions. This flag would be set by a registered function to get
  3829. // the address of a pre-installed function it was replacing. For example,
  3830. // the registered function might handle a new special case and call the
  3831. // pre-installed function to handle the remaining cases.
  3832. //--------------------------------------------------------------------------
  3833. WINCRYPT32API
  3834. BOOL
  3835. WINAPI
  3836. CryptGetOIDFunctionAddress(
  3837. IN HCRYPTOIDFUNCSET hFuncSet,
  3838. IN DWORD dwEncodingType,
  3839. IN LPCSTR pszOID,
  3840. IN DWORD dwFlags,
  3841. OUT void **ppvFuncAddr,
  3842. OUT HCRYPTOIDFUNCADDR *phFuncAddr
  3843. );
  3844. #define CRYPT_GET_INSTALLED_OID_FUNC_FLAG 0x1
  3845. //+-------------------------------------------------------------------------
  3846. // Get the list of registered default Dll entries for the specified
  3847. // function set and encoding type.
  3848. //
  3849. // The returned list consists of none, one or more null terminated Dll file
  3850. // names. The list is terminated with an empty (L"\0") Dll file name.
  3851. // For example: L"first.dll" L"\0" L"second.dll" L"\0" L"\0"
  3852. //--------------------------------------------------------------------------
  3853. WINCRYPT32API
  3854. BOOL
  3855. WINAPI
  3856. CryptGetDefaultOIDDllList(
  3857. IN HCRYPTOIDFUNCSET hFuncSet,
  3858. IN DWORD dwEncodingType,
  3859. OUT LPWSTR pwszDllList,
  3860. IN OUT DWORD *pcchDllList
  3861. );
  3862. //+-------------------------------------------------------------------------
  3863. // Either: get the first or next installed DEFAULT function OR
  3864. // load the Dll containing the DEFAULT function.
  3865. //
  3866. // If pwszDll is NULL, search the list of installed DEFAULT functions.
  3867. // *phFuncAddr must be set to NULL to get the first installed function.
  3868. // Successive installed functions are returned by setting *phFuncAddr
  3869. // to the hFuncAddr returned by the previous call.
  3870. //
  3871. // If pwszDll is NULL, the input *phFuncAddr
  3872. // is always CryptFreeOIDFunctionAddress'ed by this function, even for
  3873. // an error.
  3874. //
  3875. // If pwszDll isn't NULL, then, attempts to load the Dll and the DEFAULT
  3876. // function. *phFuncAddr is ignored upon entry and isn't
  3877. // CryptFreeOIDFunctionAddress'ed.
  3878. //
  3879. // For success, returns TRUE with *ppvFuncAddr updated with the function's
  3880. // address and *phFuncAddr updated with the function address's handle.
  3881. // The function's handle is AddRef'ed. CryptFreeOIDFunctionAddress needs to
  3882. // be called to release it or CryptGetDefaultOIDFunctionAddress can also
  3883. // be called for a NULL pwszDll.
  3884. //--------------------------------------------------------------------------
  3885. WINCRYPT32API
  3886. BOOL
  3887. WINAPI
  3888. CryptGetDefaultOIDFunctionAddress(
  3889. IN HCRYPTOIDFUNCSET hFuncSet,
  3890. IN DWORD dwEncodingType,
  3891. IN OPTIONAL LPCWSTR pwszDll,
  3892. IN DWORD dwFlags,
  3893. OUT void **ppvFuncAddr,
  3894. IN OUT HCRYPTOIDFUNCADDR *phFuncAddr
  3895. );
  3896. //+-------------------------------------------------------------------------
  3897. // Releases the handle AddRef'ed and returned by CryptGetOIDFunctionAddress
  3898. // or CryptGetDefaultOIDFunctionAddress.
  3899. //
  3900. // If a Dll was loaded for the function its unloaded. However, before doing
  3901. // the unload, the DllCanUnloadNow function exported by the loaded Dll is
  3902. // called. It should return S_FALSE to inhibit the unload or S_TRUE to enable
  3903. // the unload. If the Dll doesn't export DllCanUnloadNow, the Dll is unloaded.
  3904. //
  3905. // DllCanUnloadNow has the following signature:
  3906. // STDAPI DllCanUnloadNow(void);
  3907. //--------------------------------------------------------------------------
  3908. WINCRYPT32API
  3909. BOOL
  3910. WINAPI
  3911. CryptFreeOIDFunctionAddress(
  3912. IN HCRYPTOIDFUNCADDR hFuncAddr,
  3913. IN DWORD dwFlags
  3914. );
  3915. //+-------------------------------------------------------------------------
  3916. // Register the Dll containing the function to be called for the specified
  3917. // encoding type, function name and OID.
  3918. //
  3919. // pwszDll may contain environment-variable strings
  3920. // which are ExpandEnvironmentStrings()'ed before loading the Dll.
  3921. //
  3922. // In addition to registering the DLL, you may override the
  3923. // name of the function to be called. For example,
  3924. // pszFuncName = "CryptDllEncodeObject",
  3925. // pszOverrideFuncName = "MyEncodeXyz".
  3926. // This allows a Dll to export multiple OID functions for the same
  3927. // function name without needing to interpose its own OID dispatcher function.
  3928. //--------------------------------------------------------------------------
  3929. WINCRYPT32API
  3930. BOOL
  3931. WINAPI
  3932. CryptRegisterOIDFunction(
  3933. IN DWORD dwEncodingType,
  3934. IN LPCSTR pszFuncName,
  3935. IN LPCSTR pszOID,
  3936. IN OPTIONAL LPCWSTR pwszDll,
  3937. IN OPTIONAL LPCSTR pszOverrideFuncName
  3938. );
  3939. //+-------------------------------------------------------------------------
  3940. // Unregister the Dll containing the function to be called for the specified
  3941. // encoding type, function name and OID.
  3942. //--------------------------------------------------------------------------
  3943. WINCRYPT32API
  3944. BOOL
  3945. WINAPI
  3946. CryptUnregisterOIDFunction(
  3947. IN DWORD dwEncodingType,
  3948. IN LPCSTR pszFuncName,
  3949. IN LPCSTR pszOID
  3950. );
  3951. //+-------------------------------------------------------------------------
  3952. // Register the Dll containing the default function to be called for the
  3953. // specified encoding type and function name.
  3954. //
  3955. // Unlike CryptRegisterOIDFunction, you can't override the function name
  3956. // needing to be exported by the Dll.
  3957. //
  3958. // The Dll is inserted before the entry specified by dwIndex.
  3959. // dwIndex == 0, inserts at the beginning.
  3960. // dwIndex == CRYPT_REGISTER_LAST_INDEX, appends at the end.
  3961. //
  3962. // pwszDll may contain environment-variable strings
  3963. // which are ExpandEnvironmentStrings()'ed before loading the Dll.
  3964. //--------------------------------------------------------------------------
  3965. WINCRYPT32API
  3966. BOOL
  3967. WINAPI
  3968. CryptRegisterDefaultOIDFunction(
  3969. IN DWORD dwEncodingType,
  3970. IN LPCSTR pszFuncName,
  3971. IN DWORD dwIndex,
  3972. IN LPCWSTR pwszDll
  3973. );
  3974. #define CRYPT_REGISTER_FIRST_INDEX 0
  3975. #define CRYPT_REGISTER_LAST_INDEX 0xFFFFFFFF
  3976. //+-------------------------------------------------------------------------
  3977. // Unregister the Dll containing the default function to be called for
  3978. // the specified encoding type and function name.
  3979. //--------------------------------------------------------------------------
  3980. WINCRYPT32API
  3981. BOOL
  3982. WINAPI
  3983. CryptUnregisterDefaultOIDFunction(
  3984. IN DWORD dwEncodingType,
  3985. IN LPCSTR pszFuncName,
  3986. IN LPCWSTR pwszDll
  3987. );
  3988. //+-------------------------------------------------------------------------
  3989. // Set the value for the specified encoding type, function name, OID and
  3990. // value name.
  3991. //
  3992. // See RegSetValueEx for the possible value types.
  3993. //
  3994. // String types are UNICODE.
  3995. //--------------------------------------------------------------------------
  3996. WINCRYPT32API
  3997. BOOL
  3998. WINAPI
  3999. CryptSetOIDFunctionValue(
  4000. IN DWORD dwEncodingType,
  4001. IN LPCSTR pszFuncName,
  4002. IN LPCSTR pszOID,
  4003. IN LPCWSTR pwszValueName,
  4004. IN DWORD dwValueType,
  4005. IN const BYTE *pbValueData,
  4006. IN DWORD cbValueData
  4007. );
  4008. //+-------------------------------------------------------------------------
  4009. // Get the value for the specified encoding type, function name, OID and
  4010. // value name.
  4011. //
  4012. // See RegEnumValue for the possible value types.
  4013. //
  4014. // String types are UNICODE.
  4015. //--------------------------------------------------------------------------
  4016. WINCRYPT32API
  4017. BOOL
  4018. WINAPI
  4019. CryptGetOIDFunctionValue(
  4020. IN DWORD dwEncodingType,
  4021. IN LPCSTR pszFuncName,
  4022. IN LPCSTR pszOID,
  4023. IN LPCWSTR pwszValueName,
  4024. OUT DWORD *pdwValueType,
  4025. OUT BYTE *pbValueData,
  4026. IN OUT DWORD *pcbValueData
  4027. );
  4028. typedef BOOL (WINAPI *PFN_CRYPT_ENUM_OID_FUNC)(
  4029. IN DWORD dwEncodingType,
  4030. IN LPCSTR pszFuncName,
  4031. IN LPCSTR pszOID,
  4032. IN DWORD cValue,
  4033. IN const DWORD rgdwValueType[],
  4034. IN LPCWSTR const rgpwszValueName[],
  4035. IN const BYTE * const rgpbValueData[],
  4036. IN const DWORD rgcbValueData[],
  4037. IN void *pvArg
  4038. );
  4039. //+-------------------------------------------------------------------------
  4040. // Enumerate the OID functions identified by their encoding type,
  4041. // function name and OID.
  4042. //
  4043. // pfnEnumOIDFunc is called for each registry key matching the input
  4044. // parameters. Setting dwEncodingType to CRYPT_MATCH_ANY_ENCODING_TYPE matches
  4045. // any. Setting pszFuncName or pszOID to NULL matches any.
  4046. //
  4047. // Set pszOID == CRYPT_DEFAULT_OID to restrict the enumeration to only the
  4048. // DEFAULT functions
  4049. //
  4050. // String types are UNICODE.
  4051. //--------------------------------------------------------------------------
  4052. WINCRYPT32API
  4053. BOOL
  4054. WINAPI
  4055. CryptEnumOIDFunction(
  4056. IN DWORD dwEncodingType,
  4057. IN OPTIONAL LPCSTR pszFuncName,
  4058. IN OPTIONAL LPCSTR pszOID,
  4059. IN DWORD dwFlags,
  4060. IN void *pvArg,
  4061. IN PFN_CRYPT_ENUM_OID_FUNC pfnEnumOIDFunc
  4062. );
  4063. #define CRYPT_MATCH_ANY_ENCODING_TYPE 0xFFFFFFFF
  4064. //+=========================================================================
  4065. // Object IDentifier (OID) Information: Data Structures and APIs
  4066. //==========================================================================
  4067. //+-------------------------------------------------------------------------
  4068. // OID Information
  4069. //--------------------------------------------------------------------------
  4070. typedef struct _CRYPT_OID_INFO {
  4071. DWORD cbSize;
  4072. LPCSTR pszOID;
  4073. LPCWSTR pwszName;
  4074. DWORD dwGroupId;
  4075. union {
  4076. DWORD dwValue;
  4077. ALG_ID Algid;
  4078. DWORD dwLength;
  4079. };
  4080. CRYPT_DATA_BLOB ExtraInfo;
  4081. } CRYPT_OID_INFO, *PCRYPT_OID_INFO;
  4082. typedef const CRYPT_OID_INFO CCRYPT_OID_INFO, *PCCRYPT_OID_INFO;
  4083. //+-------------------------------------------------------------------------
  4084. // OID Group IDs
  4085. //--------------------------------------------------------------------------
  4086. #define CRYPT_HASH_ALG_OID_GROUP_ID 1
  4087. #define CRYPT_ENCRYPT_ALG_OID_GROUP_ID 2
  4088. #define CRYPT_PUBKEY_ALG_OID_GROUP_ID 3
  4089. #define CRYPT_SIGN_ALG_OID_GROUP_ID 4
  4090. #define CRYPT_RDN_ATTR_OID_GROUP_ID 5
  4091. #define CRYPT_EXT_OR_ATTR_OID_GROUP_ID 6
  4092. #define CRYPT_ENHKEY_USAGE_OID_GROUP_ID 7
  4093. #define CRYPT_POLICY_OID_GROUP_ID 8
  4094. #define CRYPT_TEMPLATE_OID_GROUP_ID 9
  4095. #define CRYPT_LAST_OID_GROUP_ID 9
  4096. #define CRYPT_FIRST_ALG_OID_GROUP_ID CRYPT_HASH_ALG_OID_GROUP_ID
  4097. #define CRYPT_LAST_ALG_OID_GROUP_ID CRYPT_SIGN_ALG_OID_GROUP_ID
  4098. // The CRYPT_*_ALG_OID_GROUP_ID's have an Algid. The CRYPT_RDN_ATTR_OID_GROUP_ID
  4099. // has a dwLength. The CRYPT_EXT_OR_ATTR_OID_GROUP_ID,
  4100. // CRYPT_ENHKEY_USAGE_OID_GROUP_ID, CRYPT_POLICY_OID_GROUP_ID or
  4101. // CRYPT_TEMPLATE_OID_GROUP_ID don't have a dwValue.
  4102. //
  4103. // CRYPT_PUBKEY_ALG_OID_GROUP_ID has the following optional ExtraInfo:
  4104. // DWORD[0] - Flags. CRYPT_OID_INHIBIT_SIGNATURE_FORMAT_FLAG can be set to
  4105. // inhibit the reformatting of the signature before
  4106. // CryptVerifySignature is called or after CryptSignHash
  4107. // is called. CRYPT_OID_USE_PUBKEY_PARA_FOR_PKCS7_FLAG can
  4108. // be set to include the public key algorithm's parameters
  4109. // in the PKCS7's digestEncryptionAlgorithm's parameters.
  4110. // CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG can be set to omit
  4111. // NULL parameters when encoding.
  4112. #define CRYPT_OID_INHIBIT_SIGNATURE_FORMAT_FLAG 0x1
  4113. #define CRYPT_OID_USE_PUBKEY_PARA_FOR_PKCS7_FLAG 0x2
  4114. #define CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG 0x4
  4115. // CRYPT_SIGN_ALG_OID_GROUP_ID has the following optional ExtraInfo:
  4116. // DWORD[0] - Public Key Algid.
  4117. // DWORD[1] - Flags. Same as above for CRYPT_PUBKEY_ALG_OID_GROUP_ID.
  4118. // DWORD[2] - Optional CryptAcquireContext(CRYPT_VERIFYCONTEXT)'s dwProvType.
  4119. // If omitted or 0, uses Public Key Algid to select
  4120. // appropriate dwProvType for signature verification.
  4121. // CRYPT_RDN_ATTR_OID_GROUP_ID has the following optional ExtraInfo:
  4122. // Array of DWORDs:
  4123. // [0 ..] - Null terminated list of acceptable RDN attribute
  4124. // value types. An empty list implies CERT_RDN_PRINTABLE_STRING,
  4125. // CERT_RDN_UNICODE_STRING, 0.
  4126. //+-------------------------------------------------------------------------
  4127. // Find OID information. Returns NULL if unable to find any information
  4128. // for the specified key and group. Note, returns a pointer to a constant
  4129. // data structure. The returned pointer MUST NOT be freed.
  4130. //
  4131. // dwKeyType's:
  4132. // CRYPT_OID_INFO_OID_KEY, pvKey points to a szOID
  4133. // CRYPT_OID_INFO_NAME_KEY, pvKey points to a wszName
  4134. // CRYPT_OID_INFO_ALGID_KEY, pvKey points to an ALG_ID
  4135. // CRYPT_OID_INFO_SIGN_KEY, pvKey points to an array of two ALG_ID's:
  4136. // ALG_ID[0] - Hash Algid
  4137. // ALG_ID[1] - PubKey Algid
  4138. //
  4139. // Setting dwGroupId to 0, searches all groups according to the dwKeyType.
  4140. // Otherwise, only the dwGroupId is searched.
  4141. //--------------------------------------------------------------------------
  4142. WINCRYPT32API
  4143. PCCRYPT_OID_INFO
  4144. WINAPI
  4145. CryptFindOIDInfo(
  4146. IN DWORD dwKeyType,
  4147. IN void *pvKey,
  4148. IN DWORD dwGroupId
  4149. );
  4150. #define CRYPT_OID_INFO_OID_KEY 1
  4151. #define CRYPT_OID_INFO_NAME_KEY 2
  4152. #define CRYPT_OID_INFO_ALGID_KEY 3
  4153. #define CRYPT_OID_INFO_SIGN_KEY 4
  4154. //+-------------------------------------------------------------------------
  4155. // Register OID information. The OID information specified in the
  4156. // CCRYPT_OID_INFO structure is persisted to the registry.
  4157. //
  4158. // crypt32.dll contains information for the commonly known OIDs. This function
  4159. // allows applications to augment crypt32.dll's OID information. During
  4160. // CryptFindOIDInfo's first call, the registered OID information is installed.
  4161. //
  4162. // By default the registered OID information is installed after crypt32.dll's
  4163. // OID entries. Set CRYPT_INSTALL_OID_INFO_BEFORE_FLAG to install before.
  4164. //--------------------------------------------------------------------------
  4165. WINCRYPT32API
  4166. BOOL
  4167. WINAPI
  4168. CryptRegisterOIDInfo(
  4169. IN PCCRYPT_OID_INFO pInfo,
  4170. IN DWORD dwFlags
  4171. );
  4172. #define CRYPT_INSTALL_OID_INFO_BEFORE_FLAG 1
  4173. //+-------------------------------------------------------------------------
  4174. // Unregister OID information. Only the pszOID and dwGroupId fields are
  4175. // used to identify the OID information to be unregistered.
  4176. //--------------------------------------------------------------------------
  4177. WINCRYPT32API
  4178. BOOL
  4179. WINAPI
  4180. CryptUnregisterOIDInfo(
  4181. IN PCCRYPT_OID_INFO pInfo
  4182. );
  4183. // If the callback returns FALSE, stops the enumeration.
  4184. typedef BOOL (WINAPI *PFN_CRYPT_ENUM_OID_INFO)(
  4185. IN PCCRYPT_OID_INFO pInfo,
  4186. IN void *pvArg
  4187. );
  4188. //+-------------------------------------------------------------------------
  4189. // Enumerate the OID information.
  4190. //
  4191. // pfnEnumOIDInfo is called for each OID information entry.
  4192. //
  4193. // Setting dwGroupId to 0 matches all groups. Otherwise, only enumerates
  4194. // entries in the specified group.
  4195. //
  4196. // dwFlags currently isn't used and must be set to 0.
  4197. //--------------------------------------------------------------------------
  4198. WINCRYPT32API
  4199. BOOL
  4200. WINAPI
  4201. CryptEnumOIDInfo(
  4202. IN DWORD dwGroupId,
  4203. IN DWORD dwFlags,
  4204. IN void *pvArg,
  4205. IN PFN_CRYPT_ENUM_OID_INFO pfnEnumOIDInfo
  4206. );
  4207. //+-------------------------------------------------------------------------
  4208. // Find the localized name for the specified name. For example, find the
  4209. // localized name for the "Root" system store name. A case insensitive
  4210. // string comparison is done.
  4211. //
  4212. // Returns NULL if unable to find the the specified name.
  4213. //
  4214. // Localized names for the predefined system stores ("Root", "My") and
  4215. // predefined physical stores (".Default", ".LocalMachine") are pre-installed
  4216. // as resource strings in crypt32.dll. CryptSetOIDFunctionValue can be called
  4217. // as follows to register additional localized strings:
  4218. // dwEncodingType = CRYPT_LOCALIZED_NAME_ENCODING_TYPE
  4219. // pszFuncName = CRYPT_OID_FIND_LOCALIZED_NAME_FUNC
  4220. // pszOID = CRYPT_LOCALIZED_NAME_OID
  4221. // pwszValueName = Name to be localized, for example, L"ApplicationStore"
  4222. // dwValueType = REG_SZ
  4223. // pbValueData = pointer to the UNICODE localized string
  4224. // cbValueData = (wcslen(UNICODE localized string) + 1) * sizeof(WCHAR)
  4225. //
  4226. // To unregister, set pbValueData to NULL and cbValueData to 0.
  4227. //
  4228. // The registered names are searched before the pre-installed names.
  4229. //--------------------------------------------------------------------------
  4230. WINCRYPT32API
  4231. LPCWSTR
  4232. WINAPI
  4233. CryptFindLocalizedName(
  4234. IN LPCWSTR pwszCryptName
  4235. );
  4236. #define CRYPT_LOCALIZED_NAME_ENCODING_TYPE 0
  4237. #define CRYPT_LOCALIZED_NAME_OID "LocalizedNames"
  4238. //+=========================================================================
  4239. // Low Level Cryptographic Message Data Structures and APIs
  4240. //==========================================================================
  4241. typedef void *HCRYPTMSG;
  4242. #define szOID_PKCS_7_DATA "1.2.840.113549.1.7.1"
  4243. #define szOID_PKCS_7_SIGNED "1.2.840.113549.1.7.2"
  4244. #define szOID_PKCS_7_ENVELOPED "1.2.840.113549.1.7.3"
  4245. #define szOID_PKCS_7_SIGNEDANDENVELOPED "1.2.840.113549.1.7.4"
  4246. #define szOID_PKCS_7_DIGESTED "1.2.840.113549.1.7.5"
  4247. #define szOID_PKCS_7_ENCRYPTED "1.2.840.113549.1.7.6"
  4248. #define szOID_PKCS_9_CONTENT_TYPE "1.2.840.113549.1.9.3"
  4249. #define szOID_PKCS_9_MESSAGE_DIGEST "1.2.840.113549.1.9.4"
  4250. //+-------------------------------------------------------------------------
  4251. // Message types
  4252. //--------------------------------------------------------------------------
  4253. #define CMSG_DATA 1
  4254. #define CMSG_SIGNED 2
  4255. #define CMSG_ENVELOPED 3
  4256. #define CMSG_SIGNED_AND_ENVELOPED 4
  4257. #define CMSG_HASHED 5
  4258. #define CMSG_ENCRYPTED 6
  4259. //+-------------------------------------------------------------------------
  4260. // Message Type Bit Flags
  4261. //--------------------------------------------------------------------------
  4262. #define CMSG_ALL_FLAGS (~0UL)
  4263. #define CMSG_DATA_FLAG (1 << CMSG_DATA)
  4264. #define CMSG_SIGNED_FLAG (1 << CMSG_SIGNED)
  4265. #define CMSG_ENVELOPED_FLAG (1 << CMSG_ENVELOPED)
  4266. #define CMSG_SIGNED_AND_ENVELOPED_FLAG (1 << CMSG_SIGNED_AND_ENVELOPED)
  4267. #define CMSG_HASHED_FLAG (1 << CMSG_HASHED)
  4268. #define CMSG_ENCRYPTED_FLAG (1 << CMSG_ENCRYPTED)
  4269. //+-------------------------------------------------------------------------
  4270. // Certificate Issuer and SerialNumber
  4271. //--------------------------------------------------------------------------
  4272. typedef struct _CERT_ISSUER_SERIAL_NUMBER {
  4273. CERT_NAME_BLOB Issuer;
  4274. CRYPT_INTEGER_BLOB SerialNumber;
  4275. } CERT_ISSUER_SERIAL_NUMBER, *PCERT_ISSUER_SERIAL_NUMBER;
  4276. //+-------------------------------------------------------------------------
  4277. // Certificate Identifier
  4278. //--------------------------------------------------------------------------
  4279. typedef struct _CERT_ID {
  4280. DWORD dwIdChoice;
  4281. union {
  4282. // CERT_ID_ISSUER_SERIAL_NUMBER
  4283. CERT_ISSUER_SERIAL_NUMBER IssuerSerialNumber;
  4284. // CERT_ID_KEY_IDENTIFIER
  4285. CRYPT_HASH_BLOB KeyId;
  4286. // CERT_ID_SHA1_HASH
  4287. CRYPT_HASH_BLOB HashId;
  4288. };
  4289. } CERT_ID, *PCERT_ID;
  4290. #define CERT_ID_ISSUER_SERIAL_NUMBER 1
  4291. #define CERT_ID_KEY_IDENTIFIER 2
  4292. #define CERT_ID_SHA1_HASH 3
  4293. //+-------------------------------------------------------------------------
  4294. // The message encode information (pvMsgEncodeInfo) is message type dependent
  4295. //--------------------------------------------------------------------------
  4296. //+-------------------------------------------------------------------------
  4297. // CMSG_DATA: pvMsgEncodeInfo = NULL
  4298. //--------------------------------------------------------------------------
  4299. //+-------------------------------------------------------------------------
  4300. // CMSG_SIGNED
  4301. //
  4302. // The pCertInfo in the CMSG_SIGNER_ENCODE_INFO provides the Issuer, SerialNumber
  4303. // and PublicKeyInfo.Algorithm. The PublicKeyInfo.Algorithm implicitly
  4304. // specifies the HashEncryptionAlgorithm to be used.
  4305. //
  4306. // If the SignerId is present with a nonzero dwIdChoice its used instead
  4307. // of the Issuer and SerialNumber in pCertInfo.
  4308. //
  4309. // CMS supports the KEY_IDENTIFIER and ISSUER_SERIAL_NUMBER CERT_IDs. PKCS #7
  4310. // version 1.5 only supports the ISSUER_SERIAL_NUMBER CERT_ID choice.
  4311. //
  4312. // If HashEncryptionAlgorithm is present and not NULL its used instead of
  4313. // the PublicKeyInfo.Algorithm.
  4314. //
  4315. // Note, for RSA, the hash encryption algorithm is normally the same as
  4316. // the public key algorithm. For DSA, the hash encryption algorithm is
  4317. // normally a DSS signature algorithm.
  4318. //
  4319. // pvHashEncryptionAuxInfo currently isn't used and must be set to NULL if
  4320. // present in the data structure.
  4321. //
  4322. // The hCryptProv and dwKeySpec specify the private key to use. If dwKeySpec
  4323. // == 0, then, defaults to AT_SIGNATURE.
  4324. //
  4325. // If the HashEncryptionAlgorithm is set to szOID_PKIX_NO_SIGNATURE, then,
  4326. // the signature value only contains the hash octets. hCryptProv must still
  4327. // be specified. However, since a private key isn't used the hCryptProv can be
  4328. // acquired using CRYPT_VERIFYCONTEXT.
  4329. //
  4330. // If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  4331. // passed to CryptMsgOpenToEncode(), the signer hCryptProv's are released.
  4332. //
  4333. // pvHashAuxInfo currently isn't used and must be set to NULL.
  4334. //
  4335. // CMS signed messages allow the inclusion of Attribute Certs.
  4336. //--------------------------------------------------------------------------
  4337. typedef struct _CMSG_SIGNER_ENCODE_INFO {
  4338. DWORD cbSize;
  4339. PCERT_INFO pCertInfo;
  4340. HCRYPTPROV hCryptProv;
  4341. DWORD dwKeySpec;
  4342. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  4343. void *pvHashAuxInfo;
  4344. DWORD cAuthAttr;
  4345. PCRYPT_ATTRIBUTE rgAuthAttr;
  4346. DWORD cUnauthAttr;
  4347. PCRYPT_ATTRIBUTE rgUnauthAttr;
  4348. #ifdef CMSG_SIGNER_ENCODE_INFO_HAS_CMS_FIELDS
  4349. CERT_ID SignerId;
  4350. CRYPT_ALGORITHM_IDENTIFIER HashEncryptionAlgorithm;
  4351. void *pvHashEncryptionAuxInfo;
  4352. #endif
  4353. } CMSG_SIGNER_ENCODE_INFO, *PCMSG_SIGNER_ENCODE_INFO;
  4354. typedef struct _CMSG_SIGNED_ENCODE_INFO {
  4355. DWORD cbSize;
  4356. DWORD cSigners;
  4357. PCMSG_SIGNER_ENCODE_INFO rgSigners;
  4358. DWORD cCertEncoded;
  4359. PCERT_BLOB rgCertEncoded;
  4360. DWORD cCrlEncoded;
  4361. PCRL_BLOB rgCrlEncoded;
  4362. #ifdef CMSG_SIGNED_ENCODE_INFO_HAS_CMS_FIELDS
  4363. DWORD cAttrCertEncoded;
  4364. PCERT_BLOB rgAttrCertEncoded;
  4365. #endif
  4366. } CMSG_SIGNED_ENCODE_INFO, *PCMSG_SIGNED_ENCODE_INFO;
  4367. //+-------------------------------------------------------------------------
  4368. // CMSG_ENVELOPED
  4369. //
  4370. // The PCERT_INFO for the rgRecipients provides the Issuer, SerialNumber
  4371. // and PublicKeyInfo. The PublicKeyInfo.Algorithm implicitly
  4372. // specifies the KeyEncryptionAlgorithm to be used.
  4373. //
  4374. // The PublicKeyInfo.PublicKey in PCERT_INFO is used to encrypt the content
  4375. // encryption key for the recipient.
  4376. //
  4377. // hCryptProv is used to do the content encryption, recipient key encryption
  4378. // and export. The hCryptProv's private keys aren't used. If hCryptProv
  4379. // is NULL, a default hCryptProv is chosen according to the
  4380. // ContentEncryptionAlgorithm and the first recipient KeyEncryptionAlgorithm.
  4381. //
  4382. // If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  4383. // passed to CryptMsgOpenToEncode(), the envelope's hCryptProv is released.
  4384. //
  4385. // Note: CAPI currently doesn't support more than one KeyEncryptionAlgorithm
  4386. // per provider. This will need to be fixed.
  4387. //
  4388. // Currently, pvEncryptionAuxInfo is only defined for RC2 or RC4 encryption
  4389. // algorithms. Otherwise, its not used and must be set to NULL.
  4390. // See CMSG_RC2_AUX_INFO for the RC2 encryption algorithms.
  4391. // See CMSG_RC4_AUX_INFO for the RC4 encryption algorithms.
  4392. //
  4393. // To enable SP3 compatible encryption, pvEncryptionAuxInfo should point to
  4394. // a CMSG_SP3_COMPATIBLE_AUX_INFO data structure.
  4395. //
  4396. // To enable the CMS envelope enhancements, rgpRecipients must be set to
  4397. // NULL, and rgCmsRecipients updated to point to an array of
  4398. // CMSG_RECIPIENT_ENCODE_INFO's.
  4399. //
  4400. // Also, CMS envelope enhancements support the inclusion of a bag of
  4401. // Certs, CRLs, Attribute Certs and/or Unprotected Attributes.
  4402. //--------------------------------------------------------------------------
  4403. typedef struct _CMSG_RECIPIENT_ENCODE_INFO CMSG_RECIPIENT_ENCODE_INFO,
  4404. *PCMSG_RECIPIENT_ENCODE_INFO;
  4405. typedef struct _CMSG_ENVELOPED_ENCODE_INFO {
  4406. DWORD cbSize;
  4407. HCRYPTPROV hCryptProv;
  4408. CRYPT_ALGORITHM_IDENTIFIER ContentEncryptionAlgorithm;
  4409. void *pvEncryptionAuxInfo;
  4410. DWORD cRecipients;
  4411. // The following array may only be used for transport recipients identified
  4412. // by their IssuereAndSerialNumber. If rgpRecipients != NULL, then,
  4413. // the rgCmsRecipients must be NULL.
  4414. PCERT_INFO *rgpRecipients;
  4415. #ifdef CMSG_ENVELOPED_ENCODE_INFO_HAS_CMS_FIELDS
  4416. // If rgCmsRecipients != NULL, then, the above rgpRecipients must be
  4417. // NULL.
  4418. PCMSG_RECIPIENT_ENCODE_INFO rgCmsRecipients;
  4419. DWORD cCertEncoded;
  4420. PCERT_BLOB rgCertEncoded;
  4421. DWORD cCrlEncoded;
  4422. PCRL_BLOB rgCrlEncoded;
  4423. DWORD cAttrCertEncoded;
  4424. PCERT_BLOB rgAttrCertEncoded;
  4425. DWORD cUnprotectedAttr;
  4426. PCRYPT_ATTRIBUTE rgUnprotectedAttr;
  4427. #endif
  4428. } CMSG_ENVELOPED_ENCODE_INFO, *PCMSG_ENVELOPED_ENCODE_INFO;
  4429. //+-------------------------------------------------------------------------
  4430. // Key Transport Recipient Encode Info
  4431. //
  4432. // hCryptProv is used to do the recipient key encryption
  4433. // and export. The hCryptProv's private keys aren't used.
  4434. //
  4435. // If hCryptProv is NULL, then, the hCryptProv specified in
  4436. // CMSG_ENVELOPED_ENCODE_INFO is used.
  4437. //
  4438. // Note, even if CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  4439. // passed to CryptMsgOpenToEncode(), this hCryptProv isn't released.
  4440. //
  4441. // CMS supports the KEY_IDENTIFIER and ISSUER_SERIAL_NUMBER CERT_IDs. PKCS #7
  4442. // version 1.5 only supports the ISSUER_SERIAL_NUMBER CERT_ID choice.
  4443. //--------------------------------------------------------------------------
  4444. typedef struct _CMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO {
  4445. DWORD cbSize;
  4446. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  4447. void *pvKeyEncryptionAuxInfo;
  4448. HCRYPTPROV hCryptProv;
  4449. CRYPT_BIT_BLOB RecipientPublicKey;
  4450. CERT_ID RecipientId;
  4451. } CMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO, *PCMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO;
  4452. //+-------------------------------------------------------------------------
  4453. // Key Agreement Recipient Encode Info
  4454. //
  4455. // If hCryptProv is NULL, then, the hCryptProv specified in
  4456. // CMSG_ENVELOPED_ENCODE_INFO is used.
  4457. //
  4458. // For the CMSG_KEY_AGREE_STATIC_KEY_CHOICE, both the hCryptProv and
  4459. // dwKeySpec must be specified to select the sender's private key.
  4460. //
  4461. // Note, even if CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  4462. // passed to CryptMsgOpenToEncode(), this hCryptProv isn't released.
  4463. //
  4464. // CMS supports the KEY_IDENTIFIER and ISSUER_SERIAL_NUMBER CERT_IDs.
  4465. //
  4466. // There is 1 key choice, ephemeral originator. The originator's ephemeral
  4467. // key is generated using the public key algorithm parameters shared
  4468. // amongst all the recipients.
  4469. //
  4470. // There are 2 key choices: ephemeral originator or static sender. The
  4471. // originator's ephemeral key is generated using the public key algorithm
  4472. // parameters shared amongst all the recipients. For the static sender its
  4473. // private key is used. The hCryptProv and dwKeySpec specify the private key.
  4474. // The pSenderId identifies the certificate containing the sender's public key.
  4475. //
  4476. // Currently, pvKeyEncryptionAuxInfo isn't used and must be set to NULL.
  4477. //
  4478. // If KeyEncryptionAlgorithm.Parameters.cbData == 0, then, its Parameters
  4479. // are updated with the encoded KeyWrapAlgorithm.
  4480. //
  4481. // Currently, pvKeyWrapAuxInfo is only defined for algorithms with
  4482. // RC2. Otherwise, its not used and must be set to NULL.
  4483. // When set for RC2 algorithms, points to a CMSG_RC2_AUX_INFO containing
  4484. // the RC2 effective key length.
  4485. //
  4486. // Note, key agreement recipients are not supported in PKCS #7 version 1.5.
  4487. //--------------------------------------------------------------------------
  4488. typedef struct _CMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO {
  4489. DWORD cbSize;
  4490. CRYPT_BIT_BLOB RecipientPublicKey;
  4491. CERT_ID RecipientId;
  4492. // Following fields are optional and only applicable to KEY_IDENTIFIER
  4493. // CERT_IDs.
  4494. FILETIME Date;
  4495. PCRYPT_ATTRIBUTE_TYPE_VALUE pOtherAttr;
  4496. } CMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO,
  4497. *PCMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO;
  4498. typedef struct _CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO {
  4499. DWORD cbSize;
  4500. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  4501. void *pvKeyEncryptionAuxInfo;
  4502. CRYPT_ALGORITHM_IDENTIFIER KeyWrapAlgorithm;
  4503. void *pvKeyWrapAuxInfo;
  4504. // The following hCryptProv and dwKeySpec must be specified for the
  4505. // CMSG_KEY_AGREE_STATIC_KEY_CHOICE.
  4506. //
  4507. // For CMSG_KEY_AGREE_EPHEMERAL_KEY_CHOICE, dwKeySpec isn't applicable
  4508. // and hCryptProv is optional.
  4509. HCRYPTPROV hCryptProv;
  4510. DWORD dwKeySpec;
  4511. DWORD dwKeyChoice;
  4512. union {
  4513. // CMSG_KEY_AGREE_EPHEMERAL_KEY_CHOICE
  4514. //
  4515. // The ephemeral public key algorithm and parameters.
  4516. PCRYPT_ALGORITHM_IDENTIFIER pEphemeralAlgorithm;
  4517. // CMSG_KEY_AGREE_STATIC_KEY_CHOICE
  4518. //
  4519. // The CertId of the sender's certificate
  4520. PCERT_ID pSenderId;
  4521. };
  4522. CRYPT_DATA_BLOB UserKeyingMaterial; // OPTIONAL
  4523. DWORD cRecipientEncryptedKeys;
  4524. PCMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO *rgpRecipientEncryptedKeys;
  4525. } CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO, *PCMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO;
  4526. #define CMSG_KEY_AGREE_EPHEMERAL_KEY_CHOICE 1
  4527. #define CMSG_KEY_AGREE_STATIC_KEY_CHOICE 2
  4528. //+-------------------------------------------------------------------------
  4529. // Mail List Recipient Encode Info
  4530. //
  4531. // There is 1 choice for the KeyEncryptionKey: an already created CSP key
  4532. // handle. For the key handle choice, hCryptProv must be nonzero. This key
  4533. // handle isn't destroyed.
  4534. //
  4535. // Note, even if CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  4536. // passed to CryptMsgOpenToEncode(), this hCryptProv isn't released.
  4537. //
  4538. // Currently, pvKeyEncryptionAuxInfo is only defined for RC2 key wrap
  4539. // algorithms. Otherwise, its not used and must be set to NULL.
  4540. // When set for RC2 algorithms, points to a CMSG_RC2_AUX_INFO containing
  4541. // the RC2 effective key length.
  4542. //
  4543. // Note, mail list recipients are not supported in PKCS #7 version 1.5.
  4544. //--------------------------------------------------------------------------
  4545. typedef struct _CMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO {
  4546. DWORD cbSize;
  4547. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  4548. void *pvKeyEncryptionAuxInfo;
  4549. HCRYPTPROV hCryptProv;
  4550. DWORD dwKeyChoice;
  4551. union {
  4552. // CMSG_MAIL_LIST_HANDLE_KEY_CHOICE
  4553. HCRYPTKEY hKeyEncryptionKey;
  4554. // Reserve space for a potential pointer choice
  4555. void *pvKeyEncryptionKey;
  4556. };
  4557. CRYPT_DATA_BLOB KeyId;
  4558. // Following fields are optional.
  4559. FILETIME Date;
  4560. PCRYPT_ATTRIBUTE_TYPE_VALUE pOtherAttr;
  4561. } CMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO, *PCMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO;
  4562. #define CMSG_MAIL_LIST_HANDLE_KEY_CHOICE 1
  4563. //+-------------------------------------------------------------------------
  4564. // Recipient Encode Info
  4565. //
  4566. // Note, only key transport recipients are supported in PKCS #7 version 1.5.
  4567. //--------------------------------------------------------------------------
  4568. struct _CMSG_RECIPIENT_ENCODE_INFO {
  4569. DWORD dwRecipientChoice;
  4570. union {
  4571. // CMSG_KEY_TRANS_RECIPIENT
  4572. PCMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO pKeyTrans;
  4573. // CMSG_KEY_AGREE_RECIPIENT
  4574. PCMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO pKeyAgree;
  4575. // CMSG_MAIL_LIST_RECIPIENT
  4576. PCMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO pMailList;
  4577. };
  4578. };
  4579. #define CMSG_KEY_TRANS_RECIPIENT 1
  4580. #define CMSG_KEY_AGREE_RECIPIENT 2
  4581. #define CMSG_MAIL_LIST_RECIPIENT 3
  4582. //+-------------------------------------------------------------------------
  4583. // CMSG_RC2_AUX_INFO
  4584. //
  4585. // AuxInfo for RC2 encryption algorithms. The pvEncryptionAuxInfo field
  4586. // in CMSG_ENCRYPTED_ENCODE_INFO should be updated to point to this
  4587. // structure. If not specified, defaults to 40 bit.
  4588. //
  4589. // Note, this AuxInfo is only used when, the ContentEncryptionAlgorithm's
  4590. // Parameter.cbData is zero. Otherwise, the Parameters is decoded to
  4591. // get the bit length.
  4592. //
  4593. // If CMSG_SP3_COMPATIBLE_ENCRYPT_FLAG is set in dwBitLen, then, SP3
  4594. // compatible encryption is done and the bit length is ignored.
  4595. //--------------------------------------------------------------------------
  4596. typedef struct _CMSG_RC2_AUX_INFO {
  4597. DWORD cbSize;
  4598. DWORD dwBitLen;
  4599. } CMSG_RC2_AUX_INFO, *PCMSG_RC2_AUX_INFO;
  4600. //+-------------------------------------------------------------------------
  4601. // CMSG_SP3_COMPATIBLE_AUX_INFO
  4602. //
  4603. // AuxInfo for enabling SP3 compatible encryption.
  4604. //
  4605. // The CMSG_SP3_COMPATIBLE_ENCRYPT_FLAG is set in dwFlags to enable SP3
  4606. // compatible encryption. When set, uses zero salt instead of no salt,
  4607. // the encryption algorithm parameters are NULL instead of containing the
  4608. // encoded RC2 parameters or encoded IV octet string and the encrypted
  4609. // symmetric key is encoded little endian instead of big endian.
  4610. //--------------------------------------------------------------------------
  4611. typedef struct _CMSG_SP3_COMPATIBLE_AUX_INFO {
  4612. DWORD cbSize;
  4613. DWORD dwFlags;
  4614. } CMSG_SP3_COMPATIBLE_AUX_INFO, *PCMSG_SP3_COMPATIBLE_AUX_INFO;
  4615. #define CMSG_SP3_COMPATIBLE_ENCRYPT_FLAG 0x80000000
  4616. //+-------------------------------------------------------------------------
  4617. // CMSG_RC4_AUX_INFO
  4618. //
  4619. // AuxInfo for RC4 encryption algorithms. The pvEncryptionAuxInfo field
  4620. // in CMSG_ENCRYPTED_ENCODE_INFO should be updated to point to this
  4621. // structure. If not specified, uses the CSP's default bit length with no
  4622. // salt. Note, the base CSP has a 40 bit default and the enhanced CSP has
  4623. // a 128 bit default.
  4624. //
  4625. // If CMSG_RC4_NO_SALT_FLAG is set in dwBitLen, then, no salt is generated.
  4626. // Otherwise, (128 - dwBitLen)/8 bytes of salt are generated and encoded
  4627. // as an OCTET STRING in the algorithm parameters field.
  4628. //--------------------------------------------------------------------------
  4629. typedef struct _CMSG_RC4_AUX_INFO {
  4630. DWORD cbSize;
  4631. DWORD dwBitLen;
  4632. } CMSG_RC4_AUX_INFO, *PCMSG_RC4_AUX_INFO;
  4633. #define CMSG_RC4_NO_SALT_FLAG 0x40000000
  4634. //+-------------------------------------------------------------------------
  4635. // CMSG_SIGNED_AND_ENVELOPED
  4636. //
  4637. // For PKCS #7, a signed and enveloped message doesn't have the
  4638. // signer's authenticated or unauthenticated attributes. Otherwise, a
  4639. // combination of the CMSG_SIGNED_ENCODE_INFO and CMSG_ENVELOPED_ENCODE_INFO.
  4640. //--------------------------------------------------------------------------
  4641. typedef struct _CMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO {
  4642. DWORD cbSize;
  4643. CMSG_SIGNED_ENCODE_INFO SignedInfo;
  4644. CMSG_ENVELOPED_ENCODE_INFO EnvelopedInfo;
  4645. } CMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO, *PCMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO;
  4646. //+-------------------------------------------------------------------------
  4647. // CMSG_HASHED
  4648. //
  4649. // hCryptProv is used to do the hash. Doesn't need to use a private key.
  4650. //
  4651. // If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  4652. // passed to CryptMsgOpenToEncode(), the hCryptProv is released.
  4653. //
  4654. // If fDetachedHash is set, then, the encoded message doesn't contain
  4655. // any content (its treated as NULL Data)
  4656. //
  4657. // pvHashAuxInfo currently isn't used and must be set to NULL.
  4658. //--------------------------------------------------------------------------
  4659. typedef struct _CMSG_HASHED_ENCODE_INFO {
  4660. DWORD cbSize;
  4661. HCRYPTPROV hCryptProv;
  4662. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  4663. void *pvHashAuxInfo;
  4664. } CMSG_HASHED_ENCODE_INFO, *PCMSG_HASHED_ENCODE_INFO;
  4665. //+-------------------------------------------------------------------------
  4666. // CMSG_ENCRYPTED
  4667. //
  4668. // The key used to encrypt the message is identified outside of the message
  4669. // content (for example, password).
  4670. //
  4671. // The content input to CryptMsgUpdate has already been encrypted.
  4672. //
  4673. // pvEncryptionAuxInfo currently isn't used and must be set to NULL.
  4674. //--------------------------------------------------------------------------
  4675. typedef struct _CMSG_ENCRYPTED_ENCODE_INFO {
  4676. DWORD cbSize;
  4677. CRYPT_ALGORITHM_IDENTIFIER ContentEncryptionAlgorithm;
  4678. void *pvEncryptionAuxInfo;
  4679. } CMSG_ENCRYPTED_ENCODE_INFO, *PCMSG_ENCRYPTED_ENCODE_INFO;
  4680. //+-------------------------------------------------------------------------
  4681. // This parameter allows messages to be of variable length with streamed
  4682. // output.
  4683. //
  4684. // By default, messages are of a definite length and
  4685. // CryptMsgGetParam(CMSG_CONTENT_PARAM) is
  4686. // called to get the cryptographically processed content. Until closed,
  4687. // the handle keeps a copy of the processed content.
  4688. //
  4689. // With streamed output, the processed content can be freed as its streamed.
  4690. //
  4691. // If the length of the content to be updated is known at the time of the
  4692. // open, then, ContentLength should be set to that length. Otherwise, it
  4693. // should be set to CMSG_INDEFINITE_LENGTH.
  4694. //--------------------------------------------------------------------------
  4695. typedef BOOL (WINAPI *PFN_CMSG_STREAM_OUTPUT)(
  4696. IN const void *pvArg,
  4697. IN BYTE *pbData,
  4698. IN DWORD cbData,
  4699. IN BOOL fFinal
  4700. );
  4701. #define CMSG_INDEFINITE_LENGTH (0xFFFFFFFF)
  4702. typedef struct _CMSG_STREAM_INFO {
  4703. DWORD cbContent;
  4704. PFN_CMSG_STREAM_OUTPUT pfnStreamOutput;
  4705. void *pvArg;
  4706. } CMSG_STREAM_INFO, *PCMSG_STREAM_INFO;
  4707. //+-------------------------------------------------------------------------
  4708. // Open dwFlags
  4709. //--------------------------------------------------------------------------
  4710. #define CMSG_BARE_CONTENT_FLAG 0x00000001
  4711. #define CMSG_LENGTH_ONLY_FLAG 0x00000002
  4712. #define CMSG_DETACHED_FLAG 0x00000004
  4713. #define CMSG_AUTHENTICATED_ATTRIBUTES_FLAG 0x00000008
  4714. #define CMSG_CONTENTS_OCTETS_FLAG 0x00000010
  4715. #define CMSG_MAX_LENGTH_FLAG 0x00000020
  4716. // When set, nonData type inner content is encapsulated within an
  4717. // OCTET STRING. Applicable to both Signed and Enveloped messages.
  4718. #define CMSG_CMS_ENCAPSULATED_CONTENT_FLAG 0x00000040
  4719. // If set, then, the hCryptProv passed to CryptMsgOpenToEncode or
  4720. // CryptMsgOpenToDecode is released on the final CryptMsgClose.
  4721. // Not released if CryptMsgOpenToEncode or CryptMsgOpenToDecode fails.
  4722. //
  4723. // Note, the envelope recipient hCryptProv's aren't released.
  4724. #define CMSG_CRYPT_RELEASE_CONTEXT_FLAG 0x00008000
  4725. //+-------------------------------------------------------------------------
  4726. // Open a cryptographic message for encoding
  4727. //
  4728. // If CMSG_BARE_CONTENT_FLAG is specified for a streamed message,
  4729. // the streamed output will not have an outer ContentInfo wrapper. This
  4730. // makes it suitable to be streamed into an enclosing message.
  4731. //
  4732. // The pStreamInfo parameter needs to be set to stream the encoded message
  4733. // output.
  4734. //--------------------------------------------------------------------------
  4735. WINCRYPT32API
  4736. HCRYPTMSG
  4737. WINAPI
  4738. CryptMsgOpenToEncode(
  4739. IN DWORD dwMsgEncodingType,
  4740. IN DWORD dwFlags,
  4741. IN DWORD dwMsgType,
  4742. IN void const *pvMsgEncodeInfo,
  4743. IN OPTIONAL LPSTR pszInnerContentObjID,
  4744. IN OPTIONAL PCMSG_STREAM_INFO pStreamInfo
  4745. );
  4746. //+-------------------------------------------------------------------------
  4747. // Calculate the length of an encoded cryptographic message.
  4748. //
  4749. // Calculates the length of the encoded message given the
  4750. // message type, encoding parameters and total length of
  4751. // the data to be updated. Note, this might not be the exact length. However,
  4752. // it will always be greater than or equal to the actual length.
  4753. //--------------------------------------------------------------------------
  4754. WINCRYPT32API
  4755. DWORD
  4756. WINAPI
  4757. CryptMsgCalculateEncodedLength(
  4758. IN DWORD dwMsgEncodingType,
  4759. IN DWORD dwFlags,
  4760. IN DWORD dwMsgType,
  4761. IN void const *pvMsgEncodeInfo,
  4762. IN OPTIONAL LPSTR pszInnerContentObjID,
  4763. IN DWORD cbData
  4764. );
  4765. //+-------------------------------------------------------------------------
  4766. // Open a cryptographic message for decoding
  4767. //
  4768. // hCryptProv specifies the crypto provider to use for hashing and/or
  4769. // decrypting the message. If hCryptProv is NULL, a default crypt provider
  4770. // is used.
  4771. //
  4772. // Currently pRecipientInfo isn't used and should be set to NULL.
  4773. //
  4774. // The pStreamInfo parameter needs to be set to stream the decoded content
  4775. // output.
  4776. //--------------------------------------------------------------------------
  4777. WINCRYPT32API
  4778. HCRYPTMSG
  4779. WINAPI
  4780. CryptMsgOpenToDecode(
  4781. IN DWORD dwMsgEncodingType,
  4782. IN DWORD dwFlags,
  4783. IN DWORD dwMsgType,
  4784. IN HCRYPTPROV hCryptProv,
  4785. IN OPTIONAL PCERT_INFO pRecipientInfo,
  4786. IN OPTIONAL PCMSG_STREAM_INFO pStreamInfo
  4787. );
  4788. //+-------------------------------------------------------------------------
  4789. // Duplicate a cryptographic message handle
  4790. //--------------------------------------------------------------------------
  4791. WINCRYPT32API
  4792. HCRYPTMSG
  4793. WINAPI
  4794. CryptMsgDuplicate(
  4795. IN HCRYPTMSG hCryptMsg
  4796. );
  4797. //+-------------------------------------------------------------------------
  4798. // Close a cryptographic message handle
  4799. //
  4800. // LastError is preserved unless FALSE is returned.
  4801. //--------------------------------------------------------------------------
  4802. WINCRYPT32API
  4803. BOOL
  4804. WINAPI
  4805. CryptMsgClose(
  4806. IN HCRYPTMSG hCryptMsg
  4807. );
  4808. //+-------------------------------------------------------------------------
  4809. // Update the content of a cryptographic message. Depending on how the
  4810. // message was opened, the content is either encoded or decoded.
  4811. //
  4812. // This function is repetitively called to append to the message content.
  4813. // fFinal is set to identify the last update. On fFinal, the encode/decode
  4814. // is completed. The encoded/decoded content and the decoded parameters
  4815. // are valid until the open and all duplicated handles are closed.
  4816. //--------------------------------------------------------------------------
  4817. WINCRYPT32API
  4818. BOOL
  4819. WINAPI
  4820. CryptMsgUpdate(
  4821. IN HCRYPTMSG hCryptMsg,
  4822. IN const BYTE *pbData,
  4823. IN DWORD cbData,
  4824. IN BOOL fFinal
  4825. );
  4826. //+-------------------------------------------------------------------------
  4827. // Get a parameter after encoding/decoding a cryptographic message. Called
  4828. // after the final CryptMsgUpdate. Only the CMSG_CONTENT_PARAM and
  4829. // CMSG_COMPUTED_HASH_PARAM are valid for an encoded message.
  4830. //
  4831. // For an encoded HASHED message, the CMSG_COMPUTED_HASH_PARAM can be got
  4832. // before any CryptMsgUpdates to get its length.
  4833. //
  4834. // The pvData type definition depends on the dwParamType value.
  4835. //
  4836. // Elements pointed to by fields in the pvData structure follow the
  4837. // structure. Therefore, *pcbData may exceed the size of the structure.
  4838. //
  4839. // Upon input, if *pcbData == 0, then, *pcbData is updated with the length
  4840. // of the data and the pvData parameter is ignored.
  4841. //
  4842. // Upon return, *pcbData is updated with the length of the data.
  4843. //
  4844. // The OBJID BLOBs returned in the pvData structures point to
  4845. // their still encoded representation. The appropriate functions
  4846. // must be called to decode the information.
  4847. //
  4848. // See below for a list of the parameters to get.
  4849. //--------------------------------------------------------------------------
  4850. WINCRYPT32API
  4851. BOOL
  4852. WINAPI
  4853. CryptMsgGetParam(
  4854. IN HCRYPTMSG hCryptMsg,
  4855. IN DWORD dwParamType,
  4856. IN DWORD dwIndex,
  4857. OUT void *pvData,
  4858. IN OUT DWORD *pcbData
  4859. );
  4860. //+-------------------------------------------------------------------------
  4861. // Get parameter types and their corresponding data structure definitions.
  4862. //--------------------------------------------------------------------------
  4863. #define CMSG_TYPE_PARAM 1
  4864. #define CMSG_CONTENT_PARAM 2
  4865. #define CMSG_BARE_CONTENT_PARAM 3
  4866. #define CMSG_INNER_CONTENT_TYPE_PARAM 4
  4867. #define CMSG_SIGNER_COUNT_PARAM 5
  4868. #define CMSG_SIGNER_INFO_PARAM 6
  4869. #define CMSG_SIGNER_CERT_INFO_PARAM 7
  4870. #define CMSG_SIGNER_HASH_ALGORITHM_PARAM 8
  4871. #define CMSG_SIGNER_AUTH_ATTR_PARAM 9
  4872. #define CMSG_SIGNER_UNAUTH_ATTR_PARAM 10
  4873. #define CMSG_CERT_COUNT_PARAM 11
  4874. #define CMSG_CERT_PARAM 12
  4875. #define CMSG_CRL_COUNT_PARAM 13
  4876. #define CMSG_CRL_PARAM 14
  4877. #define CMSG_ENVELOPE_ALGORITHM_PARAM 15
  4878. #define CMSG_RECIPIENT_COUNT_PARAM 17
  4879. #define CMSG_RECIPIENT_INDEX_PARAM 18
  4880. #define CMSG_RECIPIENT_INFO_PARAM 19
  4881. #define CMSG_HASH_ALGORITHM_PARAM 20
  4882. #define CMSG_HASH_DATA_PARAM 21
  4883. #define CMSG_COMPUTED_HASH_PARAM 22
  4884. #define CMSG_ENCRYPT_PARAM 26
  4885. #define CMSG_ENCRYPTED_DIGEST 27
  4886. #define CMSG_ENCODED_SIGNER 28
  4887. #define CMSG_ENCODED_MESSAGE 29
  4888. #define CMSG_VERSION_PARAM 30
  4889. #define CMSG_ATTR_CERT_COUNT_PARAM 31
  4890. #define CMSG_ATTR_CERT_PARAM 32
  4891. #define CMSG_CMS_RECIPIENT_COUNT_PARAM 33
  4892. #define CMSG_CMS_RECIPIENT_INDEX_PARAM 34
  4893. #define CMSG_CMS_RECIPIENT_ENCRYPTED_KEY_INDEX_PARAM 35
  4894. #define CMSG_CMS_RECIPIENT_INFO_PARAM 36
  4895. #define CMSG_UNPROTECTED_ATTR_PARAM 37
  4896. #define CMSG_SIGNER_CERT_ID_PARAM 38
  4897. #define CMSG_CMS_SIGNER_INFO_PARAM 39
  4898. //+-------------------------------------------------------------------------
  4899. // CMSG_TYPE_PARAM
  4900. //
  4901. // The type of the decoded message.
  4902. //
  4903. // pvData points to a DWORD
  4904. //--------------------------------------------------------------------------
  4905. //+-------------------------------------------------------------------------
  4906. // CMSG_CONTENT_PARAM
  4907. //
  4908. // The encoded content of a cryptographic message. Depending on how the
  4909. // message was opened, the content is either the whole PKCS#7
  4910. // message (opened to encode) or the inner content (opened to decode).
  4911. // In the decode case, the decrypted content is returned, if enveloped.
  4912. // If not enveloped, and if the inner content is of type DATA, the returned
  4913. // data is the contents octets of the inner content.
  4914. //
  4915. // pvData points to the buffer receiving the content bytes
  4916. //--------------------------------------------------------------------------
  4917. //+-------------------------------------------------------------------------
  4918. // CMSG_BARE_CONTENT_PARAM
  4919. //
  4920. // The encoded content of an encoded cryptographic message, without the
  4921. // outer layer of ContentInfo. That is, only the encoding of the
  4922. // ContentInfo.content field is returned.
  4923. //
  4924. // pvData points to the buffer receiving the content bytes
  4925. //--------------------------------------------------------------------------
  4926. //+-------------------------------------------------------------------------
  4927. // CMSG_INNER_CONTENT_TYPE_PARAM
  4928. //
  4929. // The type of the inner content of a decoded cryptographic message,
  4930. // in the form of a NULL-terminated object identifier string
  4931. // (eg. "1.2.840.113549.1.7.1").
  4932. //
  4933. // pvData points to the buffer receiving the object identifier string
  4934. //--------------------------------------------------------------------------
  4935. //+-------------------------------------------------------------------------
  4936. // CMSG_SIGNER_COUNT_PARAM
  4937. //
  4938. // Count of signers in a SIGNED or SIGNED_AND_ENVELOPED message
  4939. //
  4940. // pvData points to a DWORD
  4941. //--------------------------------------------------------------------------
  4942. //+-------------------------------------------------------------------------
  4943. // CMSG_SIGNER_CERT_INFO_PARAM
  4944. //
  4945. // To get all the signers, repetitively call CryptMsgGetParam, with
  4946. // dwIndex set to 0 .. SignerCount - 1.
  4947. //
  4948. // pvData points to a CERT_INFO struct.
  4949. //
  4950. // Only the following fields have been updated in the CERT_INFO struct:
  4951. // Issuer and SerialNumber.
  4952. //
  4953. // Note, if the KEYID choice was selected for a CMS SignerId, then, the
  4954. // SerialNumber is 0 and the Issuer is encoded containing a single RDN with a
  4955. // single Attribute whose OID is szOID_KEYID_RDN, value type is
  4956. // CERT_RDN_OCTET_STRING and value is the KEYID. When the
  4957. // CertGetSubjectCertificateFromStore and
  4958. // CertFindCertificateInStore(CERT_FIND_SUBJECT_CERT) APIs see this
  4959. // special KEYID Issuer and SerialNumber, they do a KEYID match.
  4960. //--------------------------------------------------------------------------
  4961. //+-------------------------------------------------------------------------
  4962. // CMSG_SIGNER_INFO_PARAM
  4963. //
  4964. // To get all the signers, repetitively call CryptMsgGetParam, with
  4965. // dwIndex set to 0 .. SignerCount - 1.
  4966. //
  4967. // pvData points to a CMSG_SIGNER_INFO struct.
  4968. //
  4969. // Note, if the KEYID choice was selected for a CMS SignerId, then, the
  4970. // SerialNumber is 0 and the Issuer is encoded containing a single RDN with a
  4971. // single Attribute whose OID is szOID_KEYID_RDN, value type is
  4972. // CERT_RDN_OCTET_STRING and value is the KEYID. When the
  4973. // CertGetSubjectCertificateFromStore and
  4974. // CertFindCertificateInStore(CERT_FIND_SUBJECT_CERT) APIs see this
  4975. // special KEYID Issuer and SerialNumber, they do a KEYID match.
  4976. //--------------------------------------------------------------------------
  4977. typedef struct _CMSG_SIGNER_INFO {
  4978. DWORD dwVersion;
  4979. CERT_NAME_BLOB Issuer;
  4980. CRYPT_INTEGER_BLOB SerialNumber;
  4981. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  4982. CRYPT_ALGORITHM_IDENTIFIER HashEncryptionAlgorithm;
  4983. CRYPT_DATA_BLOB EncryptedHash;
  4984. CRYPT_ATTRIBUTES AuthAttrs;
  4985. CRYPT_ATTRIBUTES UnauthAttrs;
  4986. } CMSG_SIGNER_INFO, *PCMSG_SIGNER_INFO;
  4987. //+-------------------------------------------------------------------------
  4988. // CMSG_SIGNER_CERT_ID_PARAM
  4989. //
  4990. // To get all the signers, repetitively call CryptMsgGetParam, with
  4991. // dwIndex set to 0 .. SignerCount - 1.
  4992. //
  4993. // pvData points to a CERT_ID struct.
  4994. //--------------------------------------------------------------------------
  4995. //+-------------------------------------------------------------------------
  4996. // CMSG_CMS_SIGNER_INFO_PARAM
  4997. //
  4998. // Same as CMSG_SIGNER_INFO_PARAM, except, contains SignerId instead of
  4999. // Issuer and SerialNumber.
  5000. //
  5001. // To get all the signers, repetitively call CryptMsgGetParam, with
  5002. // dwIndex set to 0 .. SignerCount - 1.
  5003. //
  5004. // pvData points to a CMSG_CMS_SIGNER_INFO struct.
  5005. //--------------------------------------------------------------------------
  5006. typedef struct _CMSG_CMS_SIGNER_INFO {
  5007. DWORD dwVersion;
  5008. CERT_ID SignerId;
  5009. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  5010. CRYPT_ALGORITHM_IDENTIFIER HashEncryptionAlgorithm;
  5011. CRYPT_DATA_BLOB EncryptedHash;
  5012. CRYPT_ATTRIBUTES AuthAttrs;
  5013. CRYPT_ATTRIBUTES UnauthAttrs;
  5014. } CMSG_CMS_SIGNER_INFO, *PCMSG_CMS_SIGNER_INFO;
  5015. //+-------------------------------------------------------------------------
  5016. // CMSG_SIGNER_HASH_ALGORITHM_PARAM
  5017. //
  5018. // This parameter specifies the HashAlgorithm that was used for the signer.
  5019. //
  5020. // Set dwIndex to iterate through all the signers.
  5021. //
  5022. // pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  5023. //--------------------------------------------------------------------------
  5024. //+-------------------------------------------------------------------------
  5025. // CMSG_SIGNER_AUTH_ATTR_PARAM
  5026. //
  5027. // The authenticated attributes for the signer.
  5028. //
  5029. // Set dwIndex to iterate through all the signers.
  5030. //
  5031. // pvData points to a CMSG_ATTR struct.
  5032. //--------------------------------------------------------------------------
  5033. typedef CRYPT_ATTRIBUTES CMSG_ATTR;
  5034. typedef CRYPT_ATTRIBUTES *PCMSG_ATTR;
  5035. //+-------------------------------------------------------------------------
  5036. // CMSG_SIGNER_UNAUTH_ATTR_PARAM
  5037. //
  5038. // The unauthenticated attributes for the signer.
  5039. //
  5040. // Set dwIndex to iterate through all the signers.
  5041. //
  5042. // pvData points to a CMSG_ATTR struct.
  5043. //--------------------------------------------------------------------------
  5044. //+-------------------------------------------------------------------------
  5045. // CMSG_CERT_COUNT_PARAM
  5046. //
  5047. // Count of certificates in a SIGNED or SIGNED_AND_ENVELOPED message.
  5048. //
  5049. // CMS, also supports certificates in an ENVELOPED message.
  5050. //
  5051. // pvData points to a DWORD
  5052. //--------------------------------------------------------------------------
  5053. //+-------------------------------------------------------------------------
  5054. // CMSG_CERT_PARAM
  5055. //
  5056. // To get all the certificates, repetitively call CryptMsgGetParam, with
  5057. // dwIndex set to 0 .. CertCount - 1.
  5058. //
  5059. // pvData points to an array of the certificate's encoded bytes.
  5060. //--------------------------------------------------------------------------
  5061. //+-------------------------------------------------------------------------
  5062. // CMSG_CRL_COUNT_PARAM
  5063. //
  5064. // Count of CRLs in a SIGNED or SIGNED_AND_ENVELOPED message.
  5065. //
  5066. // CMS, also supports CRLs in an ENVELOPED message.
  5067. //
  5068. // pvData points to a DWORD
  5069. //--------------------------------------------------------------------------
  5070. //+-------------------------------------------------------------------------
  5071. // CMSG_CRL_PARAM
  5072. //
  5073. // To get all the CRLs, repetitively call CryptMsgGetParam, with
  5074. // dwIndex set to 0 .. CrlCount - 1.
  5075. //
  5076. // pvData points to an array of the CRL's encoded bytes.
  5077. //--------------------------------------------------------------------------
  5078. //+-------------------------------------------------------------------------
  5079. // CMSG_ENVELOPE_ALGORITHM_PARAM
  5080. //
  5081. // The ContentEncryptionAlgorithm that was used in
  5082. // an ENVELOPED or SIGNED_AND_ENVELOPED message.
  5083. //
  5084. // For streaming you must be able to successfully get this parameter before
  5085. // doing a CryptMsgControl decrypt.
  5086. //
  5087. // pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  5088. //--------------------------------------------------------------------------
  5089. //+-------------------------------------------------------------------------
  5090. // CMSG_RECIPIENT_COUNT_PARAM
  5091. //
  5092. // Count of recipients in an ENVELOPED or SIGNED_AND_ENVELOPED message.
  5093. //
  5094. // Count of key transport recepients.
  5095. //
  5096. // The CMSG_CMS_RECIPIENT_COUNT_PARAM has the total count of
  5097. // recipients (it also includes key agree and mail list recipients).
  5098. //
  5099. // pvData points to a DWORD
  5100. //--------------------------------------------------------------------------
  5101. //+-------------------------------------------------------------------------
  5102. // CMSG_RECIPIENT_INDEX_PARAM
  5103. //
  5104. // Index of the recipient used to decrypt an ENVELOPED or SIGNED_AND_ENVELOPED
  5105. // message.
  5106. //
  5107. // Index of a key transport recipient. If a non key transport
  5108. // recipient was used to decrypt, fails with LastError set to
  5109. // CRYPT_E_INVALID_INDEX.
  5110. //
  5111. // pvData points to a DWORD
  5112. //--------------------------------------------------------------------------
  5113. //+-------------------------------------------------------------------------
  5114. // CMSG_RECIPIENT_INFO_PARAM
  5115. //
  5116. // To get all the recipients, repetitively call CryptMsgGetParam, with
  5117. // dwIndex set to 0 .. RecipientCount - 1.
  5118. //
  5119. // Only returns the key transport recepients.
  5120. //
  5121. // The CMSG_CMS_RECIPIENT_INFO_PARAM returns all recipients.
  5122. //
  5123. // pvData points to a CERT_INFO struct.
  5124. //
  5125. // Only the following fields have been updated in the CERT_INFO struct:
  5126. // Issuer, SerialNumber and PublicKeyAlgorithm. The PublicKeyAlgorithm
  5127. // specifies the KeyEncryptionAlgorithm that was used.
  5128. //
  5129. // Note, if the KEYID choice was selected for a key transport recipient, then,
  5130. // the SerialNumber is 0 and the Issuer is encoded containing a single RDN
  5131. // with a single Attribute whose OID is szOID_KEYID_RDN, value type is
  5132. // CERT_RDN_OCTET_STRING and value is the KEYID. When the
  5133. // CertGetSubjectCertificateFromStore and
  5134. // CertFindCertificateInStore(CERT_FIND_SUBJECT_CERT) APIs see this
  5135. // special KEYID Issuer and SerialNumber, they do a KEYID match.
  5136. //--------------------------------------------------------------------------
  5137. //+-------------------------------------------------------------------------
  5138. // CMSG_HASH_ALGORITHM_PARAM
  5139. //
  5140. // The HashAlgorithm in a HASHED message.
  5141. //
  5142. // pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  5143. //--------------------------------------------------------------------------
  5144. //+-------------------------------------------------------------------------
  5145. // CMSG_HASH_DATA_PARAM
  5146. //
  5147. // The hash in a HASHED message.
  5148. //
  5149. // pvData points to an array of bytes.
  5150. //--------------------------------------------------------------------------
  5151. //+-------------------------------------------------------------------------
  5152. // CMSG_COMPUTED_HASH_PARAM
  5153. //
  5154. // The computed hash for a HASHED message.
  5155. // This may be called for either an encoded or decoded message.
  5156. //
  5157. // Also, the computed hash for one of the signer's in a SIGNED message.
  5158. // It may be called for either an encoded or decoded message after the
  5159. // final update. Set dwIndex to iterate through all the signers.
  5160. //
  5161. // pvData points to an array of bytes.
  5162. //--------------------------------------------------------------------------
  5163. //+-------------------------------------------------------------------------
  5164. // CMSG_ENCRYPT_PARAM
  5165. //
  5166. // The ContentEncryptionAlgorithm that was used in an ENCRYPTED message.
  5167. //
  5168. // pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  5169. //--------------------------------------------------------------------------
  5170. //+-------------------------------------------------------------------------
  5171. // CMSG_ENCODED_MESSAGE
  5172. //
  5173. // The full encoded message. This is useful in the case of a decoded
  5174. // message which has been modified (eg. a signed-data or
  5175. // signed-and-enveloped-data message which has been countersigned).
  5176. //
  5177. // pvData points to an array of the message's encoded bytes.
  5178. //--------------------------------------------------------------------------
  5179. //+-------------------------------------------------------------------------
  5180. // CMSG_VERSION_PARAM
  5181. //
  5182. // The version of the decoded message.
  5183. //
  5184. // pvData points to a DWORD
  5185. //--------------------------------------------------------------------------
  5186. #define CMSG_SIGNED_DATA_V1 1
  5187. #define CMSG_SIGNED_DATA_V3 3
  5188. #define CMSG_SIGNED_DATA_PKCS_1_5_VERSION CMSG_SIGNED_DATA_V1
  5189. #define CMSG_SIGNED_DATA_CMS_VERSION CMSG_SIGNED_DATA_V3
  5190. #define CMSG_SIGNER_INFO_V1 1
  5191. #define CMSG_SIGNER_INFO_V3 3
  5192. #define CMSG_SIGNER_INFO_PKCS_1_5_VERSION CMSG_SIGNER_INFO_V1
  5193. #define CMSG_SIGNER_INFO_CMS_VERSION CMSG_SIGNER_INFO_V3
  5194. #define CMSG_HASHED_DATA_V0 0
  5195. #define CMSG_HASHED_DATA_V2 2
  5196. #define CMSG_HASHED_DATA_PKCS_1_5_VERSION CMSG_HASHED_DATA_V0
  5197. #define CMSG_HASHED_DATA_CMS_VERSION CMSG_HASHED_DATA_V2
  5198. #define CMSG_ENVELOPED_DATA_V0 0
  5199. #define CMSG_ENVELOPED_DATA_V2 2
  5200. #define CMSG_ENVELOPED_DATA_PKCS_1_5_VERSION CMSG_ENVELOPED_DATA_V0
  5201. #define CMSG_ENVELOPED_DATA_CMS_VERSION CMSG_ENVELOPED_DATA_V2
  5202. //+-------------------------------------------------------------------------
  5203. // CMSG_ATTR_CERT_COUNT_PARAM
  5204. //
  5205. // Count of attribute certificates in a SIGNED or ENVELOPED message.
  5206. //
  5207. // pvData points to a DWORD
  5208. //--------------------------------------------------------------------------
  5209. //+-------------------------------------------------------------------------
  5210. // CMSG_ATTR_CERT_PARAM
  5211. //
  5212. // To get all the attribute certificates, repetitively call CryptMsgGetParam,
  5213. // with dwIndex set to 0 .. AttrCertCount - 1.
  5214. //
  5215. // pvData points to an array of the attribute certificate's encoded bytes.
  5216. //--------------------------------------------------------------------------
  5217. //+-------------------------------------------------------------------------
  5218. // CMSG_CMS_RECIPIENT_COUNT_PARAM
  5219. //
  5220. // Count of all CMS recipients in an ENVELOPED message.
  5221. //
  5222. // pvData points to a DWORD
  5223. //--------------------------------------------------------------------------
  5224. //+-------------------------------------------------------------------------
  5225. // CMSG_CMS_RECIPIENT_INDEX_PARAM
  5226. //
  5227. // Index of the CMS recipient used to decrypt an ENVELOPED message.
  5228. //
  5229. // pvData points to a DWORD
  5230. //--------------------------------------------------------------------------
  5231. //+-------------------------------------------------------------------------
  5232. // CMSG_CMS_RECIPIENT_ENCRYPTED_KEY_INDEX_PARAM
  5233. //
  5234. // For a CMS key agreement recipient, the index of the encrypted key
  5235. // used to decrypt an ENVELOPED message.
  5236. //
  5237. // pvData points to a DWORD
  5238. //--------------------------------------------------------------------------
  5239. //+-------------------------------------------------------------------------
  5240. // CMSG_CMS_RECIPIENT_INFO_PARAM
  5241. //
  5242. // To get all the CMS recipients, repetitively call CryptMsgGetParam, with
  5243. // dwIndex set to 0 .. CmsRecipientCount - 1.
  5244. //
  5245. // pvData points to a CMSG_CMS_RECIPIENT_INFO struct.
  5246. //--------------------------------------------------------------------------
  5247. typedef struct _CMSG_KEY_TRANS_RECIPIENT_INFO {
  5248. DWORD dwVersion;
  5249. // Currently, only ISSUER_SERIAL_NUMBER or KEYID choices
  5250. CERT_ID RecipientId;
  5251. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  5252. CRYPT_DATA_BLOB EncryptedKey;
  5253. } CMSG_KEY_TRANS_RECIPIENT_INFO, *PCMSG_KEY_TRANS_RECIPIENT_INFO;
  5254. typedef struct _CMSG_RECIPIENT_ENCRYPTED_KEY_INFO {
  5255. // Currently, only ISSUER_SERIAL_NUMBER or KEYID choices
  5256. CERT_ID RecipientId;
  5257. CRYPT_DATA_BLOB EncryptedKey;
  5258. // The following optional fields are only applicable to KEYID choice
  5259. FILETIME Date;
  5260. PCRYPT_ATTRIBUTE_TYPE_VALUE pOtherAttr;
  5261. } CMSG_RECIPIENT_ENCRYPTED_KEY_INFO, *PCMSG_RECIPIENT_ENCRYPTED_KEY_INFO;
  5262. typedef struct _CMSG_KEY_AGREE_RECIPIENT_INFO {
  5263. DWORD dwVersion;
  5264. DWORD dwOriginatorChoice;
  5265. union {
  5266. // CMSG_KEY_AGREE_ORIGINATOR_CERT
  5267. CERT_ID OriginatorCertId;
  5268. // CMSG_KEY_AGREE_ORIGINATOR_PUBLIC_KEY
  5269. CERT_PUBLIC_KEY_INFO OriginatorPublicKeyInfo;
  5270. };
  5271. CRYPT_DATA_BLOB UserKeyingMaterial;
  5272. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  5273. DWORD cRecipientEncryptedKeys;
  5274. PCMSG_RECIPIENT_ENCRYPTED_KEY_INFO *rgpRecipientEncryptedKeys;
  5275. } CMSG_KEY_AGREE_RECIPIENT_INFO, *PCMSG_KEY_AGREE_RECIPIENT_INFO;
  5276. #define CMSG_KEY_AGREE_ORIGINATOR_CERT 1
  5277. #define CMSG_KEY_AGREE_ORIGINATOR_PUBLIC_KEY 2
  5278. typedef struct _CMSG_MAIL_LIST_RECIPIENT_INFO {
  5279. DWORD dwVersion;
  5280. CRYPT_DATA_BLOB KeyId;
  5281. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  5282. CRYPT_DATA_BLOB EncryptedKey;
  5283. // The following fields are optional
  5284. FILETIME Date;
  5285. PCRYPT_ATTRIBUTE_TYPE_VALUE pOtherAttr;
  5286. } CMSG_MAIL_LIST_RECIPIENT_INFO, *PCMSG_MAIL_LIST_RECIPIENT_INFO;
  5287. typedef struct _CMSG_CMS_RECIPIENT_INFO {
  5288. DWORD dwRecipientChoice;
  5289. union {
  5290. // CMSG_KEY_TRANS_RECIPIENT
  5291. PCMSG_KEY_TRANS_RECIPIENT_INFO pKeyTrans;
  5292. // CMSG_KEY_AGREE_RECIPIENT
  5293. PCMSG_KEY_AGREE_RECIPIENT_INFO pKeyAgree;
  5294. // CMSG_MAIL_LIST_RECIPIENT
  5295. PCMSG_MAIL_LIST_RECIPIENT_INFO pMailList;
  5296. };
  5297. } CMSG_CMS_RECIPIENT_INFO, *PCMSG_CMS_RECIPIENT_INFO;
  5298. // dwVersion numbers for the KeyTrans, KeyAgree and MailList recipients
  5299. #define CMSG_ENVELOPED_RECIPIENT_V0 0
  5300. #define CMSG_ENVELOPED_RECIPIENT_V2 2
  5301. #define CMSG_ENVELOPED_RECIPIENT_V3 3
  5302. #define CMSG_ENVELOPED_RECIPIENT_V4 4
  5303. #define CMSG_KEY_TRANS_PKCS_1_5_VERSION CMSG_ENVELOPED_RECIPIENT_V0
  5304. #define CMSG_KEY_TRANS_CMS_VERSION CMSG_ENVELOPED_RECIPIENT_V2
  5305. #define CMSG_KEY_AGREE_VERSION CMSG_ENVELOPED_RECIPIENT_V3
  5306. #define CMSG_MAIL_LIST_VERSION CMSG_ENVELOPED_RECIPIENT_V4
  5307. //+-------------------------------------------------------------------------
  5308. // CMSG_UNPROTECTED_ATTR_PARAM
  5309. //
  5310. // The unprotected attributes in the envelped message.
  5311. //
  5312. // pvData points to a CMSG_ATTR struct.
  5313. //--------------------------------------------------------------------------
  5314. //+-------------------------------------------------------------------------
  5315. // Perform a special "control" function after the final CryptMsgUpdate of a
  5316. // encoded/decoded cryptographic message.
  5317. //
  5318. // The dwCtrlType parameter specifies the type of operation to be performed.
  5319. //
  5320. // The pvCtrlPara definition depends on the dwCtrlType value.
  5321. //
  5322. // See below for a list of the control operations and their pvCtrlPara
  5323. // type definition.
  5324. //--------------------------------------------------------------------------
  5325. WINCRYPT32API
  5326. BOOL
  5327. WINAPI
  5328. CryptMsgControl(
  5329. IN HCRYPTMSG hCryptMsg,
  5330. IN DWORD dwFlags,
  5331. IN DWORD dwCtrlType,
  5332. IN void const *pvCtrlPara
  5333. );
  5334. //+-------------------------------------------------------------------------
  5335. // Message control types
  5336. //--------------------------------------------------------------------------
  5337. #define CMSG_CTRL_VERIFY_SIGNATURE 1
  5338. #define CMSG_CTRL_DECRYPT 2
  5339. #define CMSG_CTRL_VERIFY_HASH 5
  5340. #define CMSG_CTRL_ADD_SIGNER 6
  5341. #define CMSG_CTRL_DEL_SIGNER 7
  5342. #define CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR 8
  5343. #define CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR 9
  5344. #define CMSG_CTRL_ADD_CERT 10
  5345. #define CMSG_CTRL_DEL_CERT 11
  5346. #define CMSG_CTRL_ADD_CRL 12
  5347. #define CMSG_CTRL_DEL_CRL 13
  5348. #define CMSG_CTRL_ADD_ATTR_CERT 14
  5349. #define CMSG_CTRL_DEL_ATTR_CERT 15
  5350. #define CMSG_CTRL_KEY_TRANS_DECRYPT 16
  5351. #define CMSG_CTRL_KEY_AGREE_DECRYPT 17
  5352. #define CMSG_CTRL_MAIL_LIST_DECRYPT 18
  5353. #define CMSG_CTRL_VERIFY_SIGNATURE_EX 19
  5354. #define CMSG_CTRL_ADD_CMS_SIGNER_INFO 20
  5355. //+-------------------------------------------------------------------------
  5356. // CMSG_CTRL_VERIFY_SIGNATURE
  5357. //
  5358. // Verify the signature of a SIGNED or SIGNED_AND_ENVELOPED
  5359. // message after it has been decoded.
  5360. //
  5361. // For a SIGNED_AND_ENVELOPED message, called after
  5362. // CryptMsgControl(CMSG_CTRL_DECRYPT), if CryptMsgOpenToDecode was called
  5363. // with a NULL pRecipientInfo.
  5364. //
  5365. // pvCtrlPara points to a CERT_INFO struct.
  5366. //
  5367. // The CERT_INFO contains the Issuer and SerialNumber identifying
  5368. // the Signer of the message. The CERT_INFO also contains the
  5369. // PublicKeyInfo
  5370. // used to verify the signature. The cryptographic provider specified
  5371. // in CryptMsgOpenToDecode is used.
  5372. //
  5373. // Note, if the message contains CMS signers identified by KEYID, then,
  5374. // the CERT_INFO's Issuer and SerialNumber is ignored and only the public
  5375. // key is used to find a signer whose signature verifies.
  5376. //
  5377. // The following CMSG_CTRL_VERIFY_SIGNATURE_EX should be used instead.
  5378. //--------------------------------------------------------------------------
  5379. //+-------------------------------------------------------------------------
  5380. // CMSG_CTRL_VERIFY_SIGNATURE_EX
  5381. //
  5382. // Verify the signature of a SIGNED message after it has been decoded.
  5383. //
  5384. // pvCtrlPara points to the following CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA.
  5385. //
  5386. // If hCryptProv is NULL, uses the cryptographic provider specified in
  5387. // CryptMsgOpenToDecode. If CryptMsgOpenToDecode's hCryptProv is also NULL,
  5388. // gets default provider according to the signer's public key OID.
  5389. //
  5390. // dwSignerIndex is the index of the signer to use to verify the signature.
  5391. //
  5392. // The signer can be a pointer to a CERT_PUBLIC_KEY_INFO, certificate
  5393. // context or a chain context.
  5394. //
  5395. // If the signer's HashEncryptionAlgorithm is szOID_PKIX_NO_SIGNATURE, then,
  5396. // the signature is expected to contain the hash octets. Only dwSignerType
  5397. // of CMSG_VERIFY_SIGNER_NULL may be specified to verify this no signature
  5398. // case.
  5399. //--------------------------------------------------------------------------
  5400. typedef struct _CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA {
  5401. DWORD cbSize;
  5402. HCRYPTPROV hCryptProv;
  5403. DWORD dwSignerIndex;
  5404. DWORD dwSignerType;
  5405. void *pvSigner;
  5406. } CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA, *PCMSG_CTRL_VERIFY_SIGNATURE_EX_PARA;
  5407. // Signer Types
  5408. #define CMSG_VERIFY_SIGNER_PUBKEY 1
  5409. // pvSigner :: PCERT_PUBLIC_KEY_INFO
  5410. #define CMSG_VERIFY_SIGNER_CERT 2
  5411. // pvSigner :: PCCERT_CONTEXT
  5412. #define CMSG_VERIFY_SIGNER_CHAIN 3
  5413. // pvSigner :: PCCERT_CHAIN_CONTEXT
  5414. #define CMSG_VERIFY_SIGNER_NULL 4
  5415. // pvSigner :: NULL
  5416. //+-------------------------------------------------------------------------
  5417. // CMSG_CTRL_DECRYPT
  5418. //
  5419. // Decrypt an ENVELOPED or SIGNED_AND_ENVELOPED message after it has been
  5420. // decoded.
  5421. //
  5422. // This decrypt is only applicable to key transport recipients.
  5423. //
  5424. // hCryptProv and dwKeySpec specify the private key to use. For dwKeySpec ==
  5425. // 0, defaults to AT_KEYEXCHANGE.
  5426. //
  5427. // If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags passed
  5428. // to CryptMsgControl, then, the hCryptProv is released on the final
  5429. // CryptMsgClose. Not released if CryptMsgControl fails.
  5430. //
  5431. // dwRecipientIndex is the index of the recipient in the message associated
  5432. // with the hCryptProv's private key.
  5433. //
  5434. // The dwRecipientIndex is the index of a key transport recipient.
  5435. //
  5436. // Note, the message can only be decrypted once.
  5437. //--------------------------------------------------------------------------
  5438. typedef struct _CMSG_CTRL_DECRYPT_PARA {
  5439. DWORD cbSize;
  5440. HCRYPTPROV hCryptProv;
  5441. DWORD dwKeySpec;
  5442. DWORD dwRecipientIndex;
  5443. } CMSG_CTRL_DECRYPT_PARA, *PCMSG_CTRL_DECRYPT_PARA;
  5444. //+-------------------------------------------------------------------------
  5445. // CMSG_CTRL_KEY_TRANS_DECRYPT
  5446. //
  5447. // Decrypt an ENVELOPED message after it has been decoded for a key
  5448. // transport recipient.
  5449. //
  5450. // hCryptProv and dwKeySpec specify the private key to use. For dwKeySpec ==
  5451. // 0, defaults to AT_KEYEXCHANGE.
  5452. //
  5453. // If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags passed
  5454. // to CryptMsgControl, then, the hCryptProv is released on the final
  5455. // CryptMsgClose. Not released if CryptMsgControl fails.
  5456. //
  5457. // pKeyTrans points to the CMSG_KEY_TRANS_RECIPIENT_INFO obtained via
  5458. // CryptMsgGetParam(CMSG_CMS_RECIPIENT_INFO_PARAM)
  5459. //
  5460. // dwRecipientIndex is the index of the recipient in the message associated
  5461. // with the hCryptProv's private key.
  5462. //
  5463. // Note, the message can only be decrypted once.
  5464. //--------------------------------------------------------------------------
  5465. typedef struct _CMSG_CTRL_KEY_TRANS_DECRYPT_PARA {
  5466. DWORD cbSize;
  5467. HCRYPTPROV hCryptProv;
  5468. DWORD dwKeySpec;
  5469. PCMSG_KEY_TRANS_RECIPIENT_INFO pKeyTrans;
  5470. DWORD dwRecipientIndex;
  5471. } CMSG_CTRL_KEY_TRANS_DECRYPT_PARA, *PCMSG_CTRL_KEY_TRANS_DECRYPT_PARA;
  5472. //+-------------------------------------------------------------------------
  5473. // CMSG_CTRL_KEY_AGREE_DECRYPT
  5474. //
  5475. // Decrypt an ENVELOPED message after it has been decoded for a key
  5476. // agreement recipient.
  5477. //
  5478. // hCryptProv and dwKeySpec specify the private key to use. For dwKeySpec ==
  5479. // 0, defaults to AT_KEYEXCHANGE.
  5480. //
  5481. // If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags passed
  5482. // to CryptMsgControl, then, the hCryptProv is released on the final
  5483. // CryptMsgClose. Not released if CryptMsgControl fails.
  5484. //
  5485. // pKeyAgree points to the CMSG_KEY_AGREE_RECIPIENT_INFO obtained via
  5486. // CryptMsgGetParam(CMSG_CMS_RECIPIENT_INFO_PARAM) for dwRecipientIndex.
  5487. //
  5488. // dwRecipientIndex, dwRecipientEncryptedKeyIndex are the indices of the
  5489. // recipient's encrypted key in the message associated with the hCryptProv's
  5490. // private key.
  5491. //
  5492. // OriginatorPublicKey is the originator's public key obtained from either
  5493. // the originator's certificate or the CMSG_KEY_AGREE_RECIPIENT_INFO obtained
  5494. // via the CMSG_CMS_RECIPIENT_INFO_PARAM.
  5495. //
  5496. // Note, the message can only be decrypted once.
  5497. //--------------------------------------------------------------------------
  5498. typedef struct _CMSG_CTRL_KEY_AGREE_DECRYPT_PARA {
  5499. DWORD cbSize;
  5500. HCRYPTPROV hCryptProv;
  5501. DWORD dwKeySpec;
  5502. PCMSG_KEY_AGREE_RECIPIENT_INFO pKeyAgree;
  5503. DWORD dwRecipientIndex;
  5504. DWORD dwRecipientEncryptedKeyIndex;
  5505. CRYPT_BIT_BLOB OriginatorPublicKey;
  5506. } CMSG_CTRL_KEY_AGREE_DECRYPT_PARA, *PCMSG_CTRL_KEY_AGREE_DECRYPT_PARA;
  5507. //+-------------------------------------------------------------------------
  5508. // CMSG_CTRL_MAIL_LIST_DECRYPT
  5509. //
  5510. // Decrypt an ENVELOPED message after it has been decoded for a mail
  5511. // list recipient.
  5512. //
  5513. // pMailList points to the CMSG_MAIL_LIST_RECIPIENT_INFO obtained via
  5514. // CryptMsgGetParam(CMSG_CMS_RECIPIENT_INFO_PARAM) for dwRecipientIndex.
  5515. //
  5516. // There is 1 choice for the KeyEncryptionKey: an already created CSP key
  5517. // handle. For the key handle choice, hCryptProv must be nonzero. This key
  5518. // handle isn't destroyed.
  5519. //
  5520. // If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags passed
  5521. // to CryptMsgControl, then, the hCryptProv is released on the final
  5522. // CryptMsgClose. Not released if CryptMsgControl fails.
  5523. //
  5524. // For RC2 wrap, the effective key length is obtained from the
  5525. // KeyEncryptionAlgorithm parameters and set on the hKeyEncryptionKey before
  5526. // decrypting.
  5527. //
  5528. // Note, the message can only be decrypted once.
  5529. //--------------------------------------------------------------------------
  5530. typedef struct _CMSG_CTRL_MAIL_LIST_DECRYPT_PARA {
  5531. DWORD cbSize;
  5532. HCRYPTPROV hCryptProv;
  5533. PCMSG_MAIL_LIST_RECIPIENT_INFO pMailList;
  5534. DWORD dwRecipientIndex;
  5535. DWORD dwKeyChoice;
  5536. union {
  5537. // CMSG_MAIL_LIST_HANDLE_KEY_CHOICE
  5538. HCRYPTKEY hKeyEncryptionKey;
  5539. // Reserve space for a potential pointer choice
  5540. void *pvKeyEncryptionKey;
  5541. };
  5542. } CMSG_CTRL_MAIL_LIST_DECRYPT_PARA, *PCMSG_CTRL_MAIL_LIST_DECRYPT_PARA;
  5543. //+-------------------------------------------------------------------------
  5544. // CMSG_CTRL_VERIFY_HASH
  5545. //
  5546. // Verify the hash of a HASHED message after it has been decoded.
  5547. //
  5548. // Only the hCryptMsg parameter is used, to specify the message whose
  5549. // hash is being verified.
  5550. //--------------------------------------------------------------------------
  5551. //+-------------------------------------------------------------------------
  5552. // CMSG_CTRL_ADD_SIGNER
  5553. //
  5554. // Add a signer to a signed-data message.
  5555. //
  5556. // pvCtrlPara points to a CMSG_SIGNER_ENCODE_INFO.
  5557. //--------------------------------------------------------------------------
  5558. //+-------------------------------------------------------------------------
  5559. // CMSG_CTRL_ADD_CMS_SIGNER_INFO
  5560. //
  5561. // Add a signer to a signed-data message.
  5562. //
  5563. // Differs from the above, CMSG_CTRL_ADD_SIGNER, wherein, the signer info
  5564. // already contains the signature.
  5565. //
  5566. // pvCtrlPara points to a CMSG_CMS_SIGNER_INFO.
  5567. //--------------------------------------------------------------------------
  5568. //+-------------------------------------------------------------------------
  5569. // CMSG_CTRL_DEL_SIGNER
  5570. //
  5571. // Remove a signer from a signed-data or signed-and-enveloped-data message.
  5572. //
  5573. // pvCtrlPara points to a DWORD containing the 0-based index of the
  5574. // signer to be removed.
  5575. //--------------------------------------------------------------------------
  5576. //+-------------------------------------------------------------------------
  5577. // CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR
  5578. //
  5579. // Add an unauthenticated attribute to the SignerInfo of a signed-data or
  5580. // signed-and-enveloped-data message.
  5581. //
  5582. // The unauthenticated attribute is input in the form of an encoded blob.
  5583. //--------------------------------------------------------------------------
  5584. typedef struct _CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA {
  5585. DWORD cbSize;
  5586. DWORD dwSignerIndex;
  5587. CRYPT_DATA_BLOB blob;
  5588. } CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA, *PCMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA;
  5589. //+-------------------------------------------------------------------------
  5590. // CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR
  5591. //
  5592. // Delete an unauthenticated attribute from the SignerInfo of a signed-data
  5593. // or signed-and-enveloped-data message.
  5594. //
  5595. // The unauthenticated attribute to be removed is specified by
  5596. // a 0-based index.
  5597. //--------------------------------------------------------------------------
  5598. typedef struct _CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA {
  5599. DWORD cbSize;
  5600. DWORD dwSignerIndex;
  5601. DWORD dwUnauthAttrIndex;
  5602. } CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA, *PCMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA;
  5603. //+-------------------------------------------------------------------------
  5604. // CMSG_CTRL_ADD_CERT
  5605. //
  5606. // Add a certificate to a signed-data or signed-and-enveloped-data message.
  5607. //
  5608. // pvCtrlPara points to a CRYPT_DATA_BLOB containing the certificate's
  5609. // encoded bytes.
  5610. //--------------------------------------------------------------------------
  5611. //+-------------------------------------------------------------------------
  5612. // CMSG_CTRL_DEL_CERT
  5613. //
  5614. // Delete a certificate from a signed-data or signed-and-enveloped-data
  5615. // message.
  5616. //
  5617. // pvCtrlPara points to a DWORD containing the 0-based index of the
  5618. // certificate to be removed.
  5619. //--------------------------------------------------------------------------
  5620. //+-------------------------------------------------------------------------
  5621. // CMSG_CTRL_ADD_CRL
  5622. //
  5623. // Add a CRL to a signed-data or signed-and-enveloped-data message.
  5624. //
  5625. // pvCtrlPara points to a CRYPT_DATA_BLOB containing the CRL's
  5626. // encoded bytes.
  5627. //--------------------------------------------------------------------------
  5628. //+-------------------------------------------------------------------------
  5629. // CMSG_CTRL_DEL_CRL
  5630. //
  5631. // Delete a CRL from a signed-data or signed-and-enveloped-data message.
  5632. //
  5633. // pvCtrlPara points to a DWORD containing the 0-based index of the CRL
  5634. // to be removed.
  5635. //--------------------------------------------------------------------------
  5636. //+-------------------------------------------------------------------------
  5637. // CMSG_CTRL_ADD_ATTR_CERT
  5638. //
  5639. // Add an attribute certificate to a signed-data message.
  5640. //
  5641. // pvCtrlPara points to a CRYPT_DATA_BLOB containing the attribute
  5642. // certificate's encoded bytes.
  5643. //--------------------------------------------------------------------------
  5644. //+-------------------------------------------------------------------------
  5645. // CMSG_CTRL_DEL_ATTR_CERT
  5646. //
  5647. // Delete an attribute certificate from a signed-data message.
  5648. //
  5649. // pvCtrlPara points to a DWORD containing the 0-based index of the
  5650. // attribute certificate to be removed.
  5651. //--------------------------------------------------------------------------
  5652. //+-------------------------------------------------------------------------
  5653. // Verify a countersignature, at the SignerInfo level.
  5654. // ie. verify that pbSignerInfoCountersignature contains the encrypted
  5655. // hash of the encryptedDigest field of pbSignerInfo.
  5656. //
  5657. // hCryptProv is used to hash the encryptedDigest field of pbSignerInfo.
  5658. // The only fields referenced from pciCountersigner are SerialNumber, Issuer,
  5659. // and SubjectPublicKeyInfo.
  5660. //--------------------------------------------------------------------------
  5661. BOOL
  5662. WINAPI
  5663. CryptMsgVerifyCountersignatureEncoded(
  5664. IN HCRYPTPROV hCryptProv,
  5665. IN DWORD dwEncodingType,
  5666. IN PBYTE pbSignerInfo,
  5667. IN DWORD cbSignerInfo,
  5668. IN PBYTE pbSignerInfoCountersignature,
  5669. IN DWORD cbSignerInfoCountersignature,
  5670. IN PCERT_INFO pciCountersigner
  5671. );
  5672. //+-------------------------------------------------------------------------
  5673. // Verify a countersignature, at the SignerInfo level.
  5674. // ie. verify that pbSignerInfoCountersignature contains the encrypted
  5675. // hash of the encryptedDigest field of pbSignerInfo.
  5676. //
  5677. // hCryptProv is used to hash the encryptedDigest field of pbSignerInfo.
  5678. //
  5679. // The signer can be a CERT_PUBLIC_KEY_INFO, certificate context or a
  5680. // chain context.
  5681. //--------------------------------------------------------------------------
  5682. BOOL
  5683. WINAPI
  5684. CryptMsgVerifyCountersignatureEncodedEx(
  5685. IN HCRYPTPROV hCryptProv,
  5686. IN DWORD dwEncodingType,
  5687. IN PBYTE pbSignerInfo,
  5688. IN DWORD cbSignerInfo,
  5689. IN PBYTE pbSignerInfoCountersignature,
  5690. IN DWORD cbSignerInfoCountersignature,
  5691. IN DWORD dwSignerType,
  5692. IN void *pvSigner,
  5693. IN DWORD dwFlags,
  5694. IN OPTIONAL void *pvReserved
  5695. );
  5696. // See CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA for dwSignerType definitions
  5697. //+-------------------------------------------------------------------------
  5698. // Countersign an already-existing signature in a message
  5699. //
  5700. // dwIndex is a zero-based index of the SignerInfo to be countersigned.
  5701. //--------------------------------------------------------------------------
  5702. BOOL
  5703. WINAPI
  5704. CryptMsgCountersign(
  5705. IN OUT HCRYPTMSG hCryptMsg,
  5706. IN DWORD dwIndex,
  5707. IN DWORD cCountersigners,
  5708. IN PCMSG_SIGNER_ENCODE_INFO rgCountersigners
  5709. );
  5710. //+-------------------------------------------------------------------------
  5711. // Countersign an already-existing signature (encoded SignerInfo).
  5712. // Output an encoded SignerInfo blob, suitable for use as a countersignature
  5713. // attribute in the unauthenticated attributes of a signed-data or
  5714. // signed-and-enveloped-data message.
  5715. //--------------------------------------------------------------------------
  5716. BOOL
  5717. WINAPI
  5718. CryptMsgCountersignEncoded(
  5719. IN DWORD dwEncodingType,
  5720. IN PBYTE pbSignerInfo,
  5721. IN DWORD cbSignerInfo,
  5722. IN DWORD cCountersigners,
  5723. IN PCMSG_SIGNER_ENCODE_INFO rgCountersigners,
  5724. OUT PBYTE pbCountersignature,
  5725. IN OUT PDWORD pcbCountersignature
  5726. );
  5727. //+-------------------------------------------------------------------------
  5728. // CryptMsg OID installable functions
  5729. //--------------------------------------------------------------------------
  5730. typedef void * (WINAPI *PFN_CMSG_ALLOC) (
  5731. IN size_t cb
  5732. );
  5733. typedef void (WINAPI *PFN_CMSG_FREE)(
  5734. IN void *pv
  5735. );
  5736. // Note, the following 3 installable functions are obsolete and have been
  5737. // replaced with GenContentEncryptKey, ExportKeyTrans, ExportKeyAgree,
  5738. // ExportMailList, ImportKeyTrans, ImportKeyAgree and ImportMailList
  5739. // installable functions.
  5740. // If *phCryptProv is NULL upon entry, then, if supported, the installable
  5741. // function should acquire a default provider and return. Note, its up
  5742. // to the installable function to release at process detach.
  5743. //
  5744. // If paiEncrypt->Parameters.cbData is 0, then, the callback may optionally
  5745. // return default encoded parameters in *ppbEncryptParameters and
  5746. // *pcbEncryptParameters. pfnAlloc must be called for the allocation.
  5747. #define CMSG_OID_GEN_ENCRYPT_KEY_FUNC "CryptMsgDllGenEncryptKey"
  5748. typedef BOOL (WINAPI *PFN_CMSG_GEN_ENCRYPT_KEY) (
  5749. IN OUT HCRYPTPROV *phCryptProv,
  5750. IN PCRYPT_ALGORITHM_IDENTIFIER paiEncrypt,
  5751. IN PVOID pvEncryptAuxInfo,
  5752. IN PCERT_PUBLIC_KEY_INFO pPublicKeyInfo,
  5753. IN PFN_CMSG_ALLOC pfnAlloc,
  5754. OUT HCRYPTKEY *phEncryptKey,
  5755. OUT PBYTE *ppbEncryptParameters,
  5756. OUT PDWORD pcbEncryptParameters
  5757. );
  5758. #define CMSG_OID_EXPORT_ENCRYPT_KEY_FUNC "CryptMsgDllExportEncryptKey"
  5759. typedef BOOL (WINAPI *PFN_CMSG_EXPORT_ENCRYPT_KEY) (
  5760. IN HCRYPTPROV hCryptProv,
  5761. IN HCRYPTKEY hEncryptKey,
  5762. IN PCERT_PUBLIC_KEY_INFO pPublicKeyInfo,
  5763. OUT PBYTE pbData,
  5764. IN OUT PDWORD pcbData
  5765. );
  5766. #define CMSG_OID_IMPORT_ENCRYPT_KEY_FUNC "CryptMsgDllImportEncryptKey"
  5767. typedef BOOL (WINAPI *PFN_CMSG_IMPORT_ENCRYPT_KEY) (
  5768. IN HCRYPTPROV hCryptProv,
  5769. IN DWORD dwKeySpec,
  5770. IN PCRYPT_ALGORITHM_IDENTIFIER paiEncrypt,
  5771. IN PCRYPT_ALGORITHM_IDENTIFIER paiPubKey,
  5772. IN PBYTE pbEncodedKey,
  5773. IN DWORD cbEncodedKey,
  5774. OUT HCRYPTKEY *phEncryptKey
  5775. );
  5776. // To get the default installable function for GenContentEncryptKey,
  5777. // ExportKeyTrans, ExportKeyAgree, ExportMailList, ImportKeyTrans,
  5778. // ImportKeyAgree or ImportMailList call CryptGetOIDFunctionAddress()
  5779. // with the pszOID argument set to the following constant. dwEncodingType
  5780. // should be set to CRYPT_ASN_ENCODING or X509_ASN_ENCODING.
  5781. #define CMSG_DEFAULT_INSTALLABLE_FUNC_OID ((LPCSTR) 1)
  5782. //+-------------------------------------------------------------------------
  5783. // Content Encrypt Info
  5784. //
  5785. // The following data structure contains the information shared between
  5786. // the GenContentEncryptKey and the ExportKeyTrans, ExportKeyAgree and
  5787. // ExportMailList installable functions.
  5788. //--------------------------------------------------------------------------
  5789. typedef struct _CMSG_CONTENT_ENCRYPT_INFO {
  5790. DWORD cbSize;
  5791. HCRYPTPROV hCryptProv;
  5792. CRYPT_ALGORITHM_IDENTIFIER ContentEncryptionAlgorithm;
  5793. void *pvEncryptionAuxInfo;
  5794. DWORD cRecipients;
  5795. PCMSG_RECIPIENT_ENCODE_INFO rgCmsRecipients;
  5796. PFN_CMSG_ALLOC pfnAlloc;
  5797. PFN_CMSG_FREE pfnFree;
  5798. DWORD dwEncryptFlags;
  5799. HCRYPTKEY hContentEncryptKey;
  5800. DWORD dwFlags;
  5801. } CMSG_CONTENT_ENCRYPT_INFO, *PCMSG_CONTENT_ENCRYPT_INFO;
  5802. #define CMSG_CONTENT_ENCRYPT_PAD_ENCODED_LEN_FLAG 0x00000001
  5803. #define CMSG_CONTENT_ENCRYPT_FREE_PARA_FLAG 0x00000001
  5804. #define CMSG_CONTENT_ENCRYPT_RELEASE_CONTEXT_FLAG 0x00008000
  5805. //+-------------------------------------------------------------------------
  5806. // Upon input, ContentEncryptInfo has been initialized from the
  5807. // EnvelopedEncodeInfo.
  5808. //
  5809. // Note, if rgpRecipients instead of rgCmsRecipients are set in the
  5810. // EnvelopedEncodeInfo, then, the rgpRecipients have been converted
  5811. // to rgCmsRecipients in the ContentEncryptInfo.
  5812. //
  5813. // The following fields may be changed in ContentEncryptInfo:
  5814. // hContentEncryptKey
  5815. // hCryptProv
  5816. // ContentEncryptionAlgorithm.Parameters
  5817. // dwFlags
  5818. //
  5819. // All other fields in the ContentEncryptInfo are READONLY.
  5820. //
  5821. // If CMSG_CONTENT_ENCRYPT_PAD_ENCODED_LEN_FLAG is set upon entry
  5822. // in dwEncryptFlags, then, any potentially variable length encoded
  5823. // output should be padded with zeroes to always obtain the
  5824. // same maximum encoded length. This is necessary for
  5825. // CryptMsgCalculateEncodedLength() or CryptMsgOpenToEncode() with
  5826. // definite length streaming.
  5827. //
  5828. // The hContentEncryptKey must be updated.
  5829. //
  5830. // If hCryptProv is NULL upon input, then, it must be updated.
  5831. // If a HCRYPTPROV is acquired that must be released, then, the
  5832. // CMSG_CONTENT_ENCRYPT_RELEASE_CONTEXT_FLAG must be set in dwFlags.
  5833. //
  5834. // If ContentEncryptionAlgorithm.Parameters is updated, then, the
  5835. // CMSG_CONTENT_ENCRYPT_FREE_PARA_FLAG must be set in dwFlags. pfnAlloc and
  5836. // pfnFree must be used for doing the allocation.
  5837. //
  5838. // ContentEncryptionAlgorithm.pszObjId is used to get the OIDFunctionAddress.
  5839. //--------------------------------------------------------------------------
  5840. #define CMSG_OID_GEN_CONTENT_ENCRYPT_KEY_FUNC "CryptMsgDllGenContentEncryptKey"
  5841. typedef BOOL (WINAPI *PFN_CMSG_GEN_CONTENT_ENCRYPT_KEY) (
  5842. IN OUT PCMSG_CONTENT_ENCRYPT_INFO pContentEncryptInfo,
  5843. IN DWORD dwFlags,
  5844. IN OPTIONAL void *pvReserved
  5845. );
  5846. //+-------------------------------------------------------------------------
  5847. // Key Transport Encrypt Info
  5848. //
  5849. // The following data structure contains the information updated by the
  5850. // ExportKeyTrans installable function.
  5851. //--------------------------------------------------------------------------
  5852. typedef struct _CMSG_KEY_TRANS_ENCRYPT_INFO {
  5853. DWORD cbSize;
  5854. DWORD dwRecipientIndex;
  5855. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  5856. CRYPT_DATA_BLOB EncryptedKey;
  5857. DWORD dwFlags;
  5858. } CMSG_KEY_TRANS_ENCRYPT_INFO, *PCMSG_KEY_TRANS_ENCRYPT_INFO;
  5859. #define CMSG_KEY_TRANS_ENCRYPT_FREE_PARA_FLAG 0x00000001
  5860. //+-------------------------------------------------------------------------
  5861. // Upon input, KeyTransEncryptInfo has been initialized from the
  5862. // KeyTransEncodeInfo.
  5863. //
  5864. // The following fields may be changed in KeyTransEncryptInfo:
  5865. // EncryptedKey
  5866. // KeyEncryptionAlgorithm.Parameters
  5867. // dwFlags
  5868. //
  5869. // All other fields in the KeyTransEncryptInfo are READONLY.
  5870. //
  5871. // The EncryptedKey must be updated. The pfnAlloc and pfnFree specified in
  5872. // ContentEncryptInfo must be used for doing the allocation.
  5873. //
  5874. // If the KeyEncryptionAlgorithm.Parameters is updated, then, the
  5875. // CMSG_KEY_TRANS_ENCRYPT_FREE_PARA_FLAG must be set in dwFlags.
  5876. // The pfnAlloc and pfnFree specified in ContentEncryptInfo must be used
  5877. // for doing the allocation.
  5878. //
  5879. // KeyEncryptionAlgorithm.pszObjId is used to get the OIDFunctionAddress.
  5880. //--------------------------------------------------------------------------
  5881. #define CMSG_OID_EXPORT_KEY_TRANS_FUNC "CryptMsgDllExportKeyTrans"
  5882. typedef BOOL (WINAPI *PFN_CMSG_EXPORT_KEY_TRANS) (
  5883. IN PCMSG_CONTENT_ENCRYPT_INFO pContentEncryptInfo,
  5884. IN PCMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO pKeyTransEncodeInfo,
  5885. IN OUT PCMSG_KEY_TRANS_ENCRYPT_INFO pKeyTransEncryptInfo,
  5886. IN DWORD dwFlags,
  5887. IN OPTIONAL void *pvReserved
  5888. );
  5889. //+-------------------------------------------------------------------------
  5890. // Key Agree Key Encrypt Info
  5891. //
  5892. // The following data structure contains the information updated by the
  5893. // ExportKeyAgree installable function for each encrypted key agree
  5894. // recipient.
  5895. //--------------------------------------------------------------------------
  5896. typedef struct _CMSG_KEY_AGREE_KEY_ENCRYPT_INFO {
  5897. DWORD cbSize;
  5898. CRYPT_DATA_BLOB EncryptedKey;
  5899. } CMSG_KEY_AGREE_KEY_ENCRYPT_INFO, *PCMSG_KEY_AGREE_KEY_ENCRYPT_INFO;
  5900. //+-------------------------------------------------------------------------
  5901. // Key Agree Encrypt Info
  5902. //
  5903. // The following data structure contains the information applicable to
  5904. // all recipients. Its updated by the ExportKeyAgree installable function.
  5905. //--------------------------------------------------------------------------
  5906. typedef struct _CMSG_KEY_AGREE_ENCRYPT_INFO {
  5907. DWORD cbSize;
  5908. DWORD dwRecipientIndex;
  5909. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  5910. CRYPT_DATA_BLOB UserKeyingMaterial;
  5911. DWORD dwOriginatorChoice;
  5912. union {
  5913. // CMSG_KEY_AGREE_ORIGINATOR_CERT
  5914. CERT_ID OriginatorCertId;
  5915. // CMSG_KEY_AGREE_ORIGINATOR_PUBLIC_KEY
  5916. CERT_PUBLIC_KEY_INFO OriginatorPublicKeyInfo;
  5917. };
  5918. DWORD cKeyAgreeKeyEncryptInfo;
  5919. PCMSG_KEY_AGREE_KEY_ENCRYPT_INFO *rgpKeyAgreeKeyEncryptInfo;
  5920. DWORD dwFlags;
  5921. } CMSG_KEY_AGREE_ENCRYPT_INFO, *PCMSG_KEY_AGREE_ENCRYPT_INFO;
  5922. #define CMSG_KEY_AGREE_ENCRYPT_FREE_PARA_FLAG 0x00000001
  5923. #define CMSG_KEY_AGREE_ENCRYPT_FREE_MATERIAL_FLAG 0x00000002
  5924. #define CMSG_KEY_AGREE_ENCRYPT_FREE_PUBKEY_ALG_FLAG 0x00000004
  5925. #define CMSG_KEY_AGREE_ENCRYPT_FREE_PUBKEY_PARA_FLAG 0x00000008
  5926. #define CMSG_KEY_AGREE_ENCRYPT_FREE_PUBKEY_BITS_FLAG 0x00000010
  5927. //+-------------------------------------------------------------------------
  5928. // Upon input, KeyAgreeEncryptInfo has been initialized from the
  5929. // KeyAgreeEncodeInfo.
  5930. //
  5931. // The following fields may be changed in KeyAgreeEncryptInfo:
  5932. // KeyEncryptionAlgorithm.Parameters
  5933. // UserKeyingMaterial
  5934. // dwOriginatorChoice
  5935. // OriginatorCertId
  5936. // OriginatorPublicKeyInfo
  5937. // dwFlags
  5938. //
  5939. // All other fields in the KeyAgreeEncryptInfo are READONLY.
  5940. //
  5941. // If the KeyEncryptionAlgorithm.Parameters is updated, then, the
  5942. // CMSG_KEY_AGREE_ENCRYPT_FREE_PARA_FLAG must be set in dwFlags.
  5943. // The pfnAlloc and pfnFree specified in ContentEncryptInfo must be used
  5944. // for doing the allocation.
  5945. //
  5946. // If the UserKeyingMaterial is updated, then, the
  5947. // CMSG_KEY_AGREE_ENCRYPT_FREE_MATERIAL_FLAG must be set in dwFlags.
  5948. // pfnAlloc and pfnFree must be used for doing the allocation.
  5949. //
  5950. // The dwOriginatorChoice must be updated to either
  5951. // CMSG_KEY_AGREE_ORIGINATOR_CERT or CMSG_KEY_AGREE_ORIGINATOR_PUBLIC_KEY.
  5952. //
  5953. // If the OriginatorPublicKeyInfo is updated, then, the appropriate
  5954. // CMSG_KEY_AGREE_ENCRYPT_FREE_PUBKEY_*_FLAG must be set in dwFlags and
  5955. // pfnAlloc and pfnFree must be used for doing the allocation.
  5956. //
  5957. // If CMSG_CONTENT_ENCRYPT_PAD_ENCODED_LEN_FLAG is set upon entry
  5958. // in pContentEncryptInfo->dwEncryptFlags, then, the OriginatorPublicKeyInfo's
  5959. // Ephemeral PublicKey should be padded with zeroes to always obtain the
  5960. // same maximum encoded length. Note, the length of the generated ephemeral Y
  5961. // public key can vary depending on the number of leading zero bits.
  5962. //
  5963. // Upon input, the array of *rgpKeyAgreeKeyEncryptInfo has been initialized.
  5964. // The EncryptedKey must be updated for each recipient key.
  5965. // The pfnAlloc and pfnFree specified in
  5966. // ContentEncryptInfo must be used for doing the allocation.
  5967. //
  5968. // KeyEncryptionAlgorithm.pszObjId is used to get the OIDFunctionAddress.
  5969. //--------------------------------------------------------------------------
  5970. #define CMSG_OID_EXPORT_KEY_AGREE_FUNC "CryptMsgDllExportKeyAgree"
  5971. typedef BOOL (WINAPI *PFN_CMSG_EXPORT_KEY_AGREE) (
  5972. IN PCMSG_CONTENT_ENCRYPT_INFO pContentEncryptInfo,
  5973. IN PCMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO pKeyAgreeEncodeInfo,
  5974. IN OUT PCMSG_KEY_AGREE_ENCRYPT_INFO pKeyAgreeEncryptInfo,
  5975. IN DWORD dwFlags,
  5976. IN OPTIONAL void *pvReserved
  5977. );
  5978. //+-------------------------------------------------------------------------
  5979. // Mail List Encrypt Info
  5980. //
  5981. // The following data structure contains the information updated by the
  5982. // ExportMailList installable function.
  5983. //--------------------------------------------------------------------------
  5984. typedef struct _CMSG_MAIL_LIST_ENCRYPT_INFO {
  5985. DWORD cbSize;
  5986. DWORD dwRecipientIndex;
  5987. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  5988. CRYPT_DATA_BLOB EncryptedKey;
  5989. DWORD dwFlags;
  5990. } CMSG_MAIL_LIST_ENCRYPT_INFO, *PCMSG_MAIL_LIST_ENCRYPT_INFO;
  5991. #define CMSG_MAIL_LIST_ENCRYPT_FREE_PARA_FLAG 0x00000001
  5992. //+-------------------------------------------------------------------------
  5993. // Upon input, MailListEncryptInfo has been initialized from the
  5994. // MailListEncodeInfo.
  5995. //
  5996. // The following fields may be changed in MailListEncryptInfo:
  5997. // EncryptedKey
  5998. // KeyEncryptionAlgorithm.Parameters
  5999. // dwFlags
  6000. //
  6001. // All other fields in the MailListEncryptInfo are READONLY.
  6002. //
  6003. // The EncryptedKey must be updated. The pfnAlloc and pfnFree specified in
  6004. // ContentEncryptInfo must be used for doing the allocation.
  6005. //
  6006. // If the KeyEncryptionAlgorithm.Parameters is updated, then, the
  6007. // CMSG_MAIL_LIST_ENCRYPT_FREE_PARA_FLAG must be set in dwFlags.
  6008. // The pfnAlloc and pfnFree specified in ContentEncryptInfo must be used
  6009. // for doing the allocation.
  6010. //
  6011. // KeyEncryptionAlgorithm.pszObjId is used to get the OIDFunctionAddress.
  6012. //--------------------------------------------------------------------------
  6013. #define CMSG_OID_EXPORT_MAIL_LIST_FUNC "CryptMsgDllExportMailList"
  6014. typedef BOOL (WINAPI *PFN_CMSG_EXPORT_MAIL_LIST) (
  6015. IN PCMSG_CONTENT_ENCRYPT_INFO pContentEncryptInfo,
  6016. IN PCMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO pMailListEncodeInfo,
  6017. IN OUT PCMSG_MAIL_LIST_ENCRYPT_INFO pMailListEncryptInfo,
  6018. IN DWORD dwFlags,
  6019. IN OPTIONAL void *pvReserved
  6020. );
  6021. //+-------------------------------------------------------------------------
  6022. // OID Installable functions for importing an encoded and encrypted content
  6023. // encryption key.
  6024. //
  6025. // There's a different installable function for each CMS Recipient choice:
  6026. // ImportKeyTrans
  6027. // ImportKeyAgree
  6028. // ImportMailList
  6029. //
  6030. // Iterates through the following OIDs to get the OID installable function:
  6031. // KeyEncryptionOID!ContentEncryptionOID
  6032. // KeyEncryptionOID
  6033. // ContentEncryptionOID
  6034. //
  6035. // If the OID installable function doesn't support the specified
  6036. // KeyEncryption and ContentEncryption OIDs, then, return FALSE with
  6037. // LastError set to E_NOTIMPL.
  6038. //--------------------------------------------------------------------------
  6039. #define CMSG_OID_IMPORT_KEY_TRANS_FUNC "CryptMsgDllImportKeyTrans"
  6040. typedef BOOL (WINAPI *PFN_CMSG_IMPORT_KEY_TRANS) (
  6041. IN PCRYPT_ALGORITHM_IDENTIFIER pContentEncryptionAlgorithm,
  6042. IN PCMSG_CTRL_KEY_TRANS_DECRYPT_PARA pKeyTransDecryptPara,
  6043. IN DWORD dwFlags,
  6044. IN OPTIONAL void *pvReserved,
  6045. OUT HCRYPTKEY *phContentEncryptKey
  6046. );
  6047. #define CMSG_OID_IMPORT_KEY_AGREE_FUNC "CryptMsgDllImportKeyAgree"
  6048. typedef BOOL (WINAPI *PFN_CMSG_IMPORT_KEY_AGREE) (
  6049. IN PCRYPT_ALGORITHM_IDENTIFIER pContentEncryptionAlgorithm,
  6050. IN PCMSG_CTRL_KEY_AGREE_DECRYPT_PARA pKeyAgreeDecryptPara,
  6051. IN DWORD dwFlags,
  6052. IN OPTIONAL void *pvReserved,
  6053. OUT HCRYPTKEY *phContentEncryptKey
  6054. );
  6055. #define CMSG_OID_IMPORT_MAIL_LIST_FUNC "CryptMsgDllImportMailList"
  6056. typedef BOOL (WINAPI *PFN_CMSG_IMPORT_MAIL_LIST) (
  6057. IN PCRYPT_ALGORITHM_IDENTIFIER pContentEncryptionAlgorithm,
  6058. IN PCMSG_CTRL_MAIL_LIST_DECRYPT_PARA pMailListDecryptPara,
  6059. IN DWORD dwFlags,
  6060. IN OPTIONAL void *pvReserved,
  6061. OUT HCRYPTKEY *phContentEncryptKey
  6062. );
  6063. //+=========================================================================
  6064. // Certificate Store Data Structures and APIs
  6065. //==========================================================================
  6066. //+-------------------------------------------------------------------------
  6067. // In its most basic implementation, a cert store is simply a
  6068. // collection of certificates and/or CRLs. This is the case when
  6069. // a cert store is opened with all of its certificates and CRLs
  6070. // coming from a PKCS #7 encoded cryptographic message.
  6071. //
  6072. // Nonetheless, all cert stores have the following properties:
  6073. // - A public key may have more than one certificate in the store.
  6074. // For example, a private/public key used for signing may have a
  6075. // certificate issued for VISA and another issued for
  6076. // Mastercard. Also, when a certificate is renewed there might
  6077. // be more than one certificate with the same subject and
  6078. // issuer.
  6079. // - However, each certificate in the store is uniquely
  6080. // identified by its Issuer and SerialNumber.
  6081. // - There's an issuer of subject certificate relationship. A
  6082. // certificate's issuer is found by doing a match of
  6083. // pSubjectCert->Issuer with pIssuerCert->Subject.
  6084. // The relationship is verified by using
  6085. // the issuer's public key to verify the subject certificate's
  6086. // signature. Note, there might be X.509 v3 extensions
  6087. // to assist in finding the issuer certificate.
  6088. // - Since issuer certificates might be renewed, a subject
  6089. // certificate might have more than one issuer certificate.
  6090. // - There's an issuer of CRL relationship. An
  6091. // issuer's CRL is found by doing a match of
  6092. // pIssuerCert->Subject with pCrl->Issuer.
  6093. // The relationship is verified by using
  6094. // the issuer's public key to verify the CRL's
  6095. // signature. Note, there might be X.509 v3 extensions
  6096. // to assist in finding the CRL.
  6097. // - Since some issuers might support the X.509 v3 delta CRL
  6098. // extensions, an issuer might have more than one CRL.
  6099. // - The store shouldn't have any redundant certificates or
  6100. // CRLs. There shouldn't be two certificates with the same
  6101. // Issuer and SerialNumber. There shouldn't be two CRLs with
  6102. // the same Issuer, ThisUpdate and NextUpdate.
  6103. // - The store has NO policy or trust information. No
  6104. // certificates are tagged as being "root". Its up to
  6105. // the application to maintain a list of CertIds (Issuer +
  6106. // SerialNumber) for certificates it trusts.
  6107. // - The store might contain bad certificates and/or CRLs.
  6108. // The issuer's signature of a subject certificate or CRL may
  6109. // not verify. Certificates or CRLs may not satisfy their
  6110. // time validity requirements. Certificates may be
  6111. // revoked.
  6112. //
  6113. // In addition to the certificates and CRLs, properties can be
  6114. // stored. There are two predefined property IDs for a user
  6115. // certificate: CERT_KEY_PROV_HANDLE_PROP_ID and
  6116. // CERT_KEY_PROV_INFO_PROP_ID. The CERT_KEY_PROV_HANDLE_PROP_ID
  6117. // is a HCRYPTPROV handle to the private key assoicated
  6118. // with the certificate. The CERT_KEY_PROV_INFO_PROP_ID contains
  6119. // information to be used to call
  6120. // CryptAcquireContext and CryptSetProvParam to get a handle
  6121. // to the private key associated with the certificate.
  6122. //
  6123. // There exists two more predefined property IDs for certificates
  6124. // and CRLs, CERT_SHA1_HASH_PROP_ID and CERT_MD5_HASH_PROP_ID.
  6125. // If these properties don't already exist, then, a hash of the
  6126. // content is computed. (CERT_HASH_PROP_ID maps to the default
  6127. // hash algorithm, currently, CERT_SHA1_HASH_PROP_ID).
  6128. //
  6129. // There are additional APIs for creating certificate and CRL
  6130. // contexts not in a store (CertCreateCertificateContext and
  6131. // CertCreateCRLContext).
  6132. //
  6133. //--------------------------------------------------------------------------
  6134. typedef void *HCERTSTORE;
  6135. //+-------------------------------------------------------------------------
  6136. // Certificate context.
  6137. //
  6138. // A certificate context contains both the encoded and decoded representation
  6139. // of a certificate. A certificate context returned by a cert store function
  6140. // must be freed by calling the CertFreeCertificateContext function. The
  6141. // CertDuplicateCertificateContext function can be called to make a duplicate
  6142. // copy (which also must be freed by calling CertFreeCertificateContext).
  6143. //--------------------------------------------------------------------------
  6144. typedef struct _CERT_CONTEXT {
  6145. DWORD dwCertEncodingType;
  6146. BYTE *pbCertEncoded;
  6147. DWORD cbCertEncoded;
  6148. PCERT_INFO pCertInfo;
  6149. HCERTSTORE hCertStore;
  6150. } CERT_CONTEXT, *PCERT_CONTEXT;
  6151. typedef const CERT_CONTEXT *PCCERT_CONTEXT;
  6152. //+-------------------------------------------------------------------------
  6153. // CRL context.
  6154. //
  6155. // A CRL context contains both the encoded and decoded representation
  6156. // of a CRL. A CRL context returned by a cert store function
  6157. // must be freed by calling the CertFreeCRLContext function. The
  6158. // CertDuplicateCRLContext function can be called to make a duplicate
  6159. // copy (which also must be freed by calling CertFreeCRLContext).
  6160. //--------------------------------------------------------------------------
  6161. typedef struct _CRL_CONTEXT {
  6162. DWORD dwCertEncodingType;
  6163. BYTE *pbCrlEncoded;
  6164. DWORD cbCrlEncoded;
  6165. PCRL_INFO pCrlInfo;
  6166. HCERTSTORE hCertStore;
  6167. } CRL_CONTEXT, *PCRL_CONTEXT;
  6168. typedef const CRL_CONTEXT *PCCRL_CONTEXT;
  6169. //+-------------------------------------------------------------------------
  6170. // Certificate Trust List (CTL) context.
  6171. //
  6172. // A CTL context contains both the encoded and decoded representation
  6173. // of a CTL. Also contains an opened HCRYPTMSG handle to the decoded
  6174. // cryptographic signed message containing the CTL_INFO as its inner content.
  6175. // pbCtlContent is the encoded inner content of the signed message.
  6176. //
  6177. // The CryptMsg APIs can be used to extract additional signer information.
  6178. //--------------------------------------------------------------------------
  6179. typedef struct _CTL_CONTEXT {
  6180. DWORD dwMsgAndCertEncodingType;
  6181. BYTE *pbCtlEncoded;
  6182. DWORD cbCtlEncoded;
  6183. PCTL_INFO pCtlInfo;
  6184. HCERTSTORE hCertStore;
  6185. HCRYPTMSG hCryptMsg;
  6186. BYTE *pbCtlContent;
  6187. DWORD cbCtlContent;
  6188. } CTL_CONTEXT, *PCTL_CONTEXT;
  6189. typedef const CTL_CONTEXT *PCCTL_CONTEXT;
  6190. //+-------------------------------------------------------------------------
  6191. // Certificate, CRL and CTL property IDs
  6192. //
  6193. // See CertSetCertificateContextProperty or CertGetCertificateContextProperty
  6194. // for usage information.
  6195. //--------------------------------------------------------------------------
  6196. #define CERT_KEY_PROV_HANDLE_PROP_ID 1
  6197. #define CERT_KEY_PROV_INFO_PROP_ID 2
  6198. #define CERT_SHA1_HASH_PROP_ID 3
  6199. #define CERT_MD5_HASH_PROP_ID 4
  6200. #define CERT_HASH_PROP_ID CERT_SHA1_HASH_PROP_ID
  6201. #define CERT_KEY_CONTEXT_PROP_ID 5
  6202. #define CERT_KEY_SPEC_PROP_ID 6
  6203. #define CERT_IE30_RESERVED_PROP_ID 7
  6204. #define CERT_PUBKEY_HASH_RESERVED_PROP_ID 8
  6205. #define CERT_ENHKEY_USAGE_PROP_ID 9
  6206. #define CERT_CTL_USAGE_PROP_ID CERT_ENHKEY_USAGE_PROP_ID
  6207. #define CERT_NEXT_UPDATE_LOCATION_PROP_ID 10
  6208. #define CERT_FRIENDLY_NAME_PROP_ID 11
  6209. #define CERT_PVK_FILE_PROP_ID 12
  6210. #define CERT_DESCRIPTION_PROP_ID 13
  6211. #define CERT_ACCESS_STATE_PROP_ID 14
  6212. #define CERT_SIGNATURE_HASH_PROP_ID 15
  6213. #define CERT_SMART_CARD_DATA_PROP_ID 16
  6214. #define CERT_EFS_PROP_ID 17
  6215. #define CERT_FORTEZZA_DATA_PROP_ID 18
  6216. #define CERT_ARCHIVED_PROP_ID 19
  6217. #define CERT_KEY_IDENTIFIER_PROP_ID 20
  6218. #define CERT_AUTO_ENROLL_PROP_ID 21
  6219. #define CERT_PUBKEY_ALG_PARA_PROP_ID 22
  6220. #define CERT_CROSS_CERT_DIST_POINTS_PROP_ID 23
  6221. #define CERT_ISSUER_PUBLIC_KEY_MD5_HASH_PROP_ID 24
  6222. #define CERT_SUBJECT_PUBLIC_KEY_MD5_HASH_PROP_ID 25
  6223. #define CERT_ENROLLMENT_PROP_ID 26
  6224. #define CERT_DATE_STAMP_PROP_ID 27
  6225. #define CERT_ISSUER_SERIAL_NUMBER_MD5_HASH_PROP_ID 28
  6226. #define CERT_SUBJECT_NAME_MD5_HASH_PROP_ID 29
  6227. #define CERT_EXTENDED_ERROR_INFO_PROP_ID 30
  6228. // Note, 32 - 35 are reserved for the CERT, CRL, CTL and KeyId file element IDs.
  6229. // 36 - 63 are reserved for future element IDs.
  6230. #define CERT_RENEWAL_PROP_ID 64
  6231. #define CERT_ARCHIVED_KEY_HASH_PROP_ID 65
  6232. #define CERT_AUTO_ENROLL_RETRY_PROP_ID 66
  6233. #define CERT_AIA_URL_RETRIEVED_PROP_ID 67
  6234. #define CERT_FIRST_RESERVED_PROP_ID 68
  6235. #define CERT_LAST_RESERVED_PROP_ID 0x00007FFF
  6236. #define CERT_FIRST_USER_PROP_ID 0x00008000
  6237. #define CERT_LAST_USER_PROP_ID 0x0000FFFF
  6238. #define IS_CERT_HASH_PROP_ID(X) (CERT_SHA1_HASH_PROP_ID == (X) || \
  6239. CERT_MD5_HASH_PROP_ID == (X) || \
  6240. CERT_SIGNATURE_HASH_PROP_ID == (X))
  6241. #define IS_PUBKEY_HASH_PROP_ID(X) (CERT_ISSUER_PUBLIC_KEY_MD5_HASH_PROP_ID == (X) || \
  6242. CERT_SUBJECT_PUBLIC_KEY_MD5_HASH_PROP_ID == (X))
  6243. #define IS_CHAIN_HASH_PROP_ID(X) (CERT_ISSUER_PUBLIC_KEY_MD5_HASH_PROP_ID == (X) || \
  6244. CERT_SUBJECT_PUBLIC_KEY_MD5_HASH_PROP_ID == (X) || \
  6245. CERT_ISSUER_SERIAL_NUMBER_MD5_HASH_PROP_ID == (X) || \
  6246. CERT_SUBJECT_NAME_MD5_HASH_PROP_ID == (X))
  6247. //+-------------------------------------------------------------------------
  6248. // Property OIDs
  6249. //--------------------------------------------------------------------------
  6250. // The OID component following the prefix contains the PROP_ID (decimal)
  6251. #define szOID_CERT_PROP_ID_PREFIX "1.3.6.1.4.1.311.10.11."
  6252. #define szOID_CERT_KEY_IDENTIFIER_PROP_ID "1.3.6.1.4.1.311.10.11.20"
  6253. #define szOID_CERT_ISSUER_SERIAL_NUMBER_MD5_HASH_PROP_ID \
  6254. "1.3.6.1.4.1.311.10.11.28"
  6255. #define szOID_CERT_SUBJECT_NAME_MD5_HASH_PROP_ID \
  6256. "1.3.6.1.4.1.311.10.11.29"
  6257. //+-------------------------------------------------------------------------
  6258. // Access State flags returned by CERT_ACCESS_STATE_PROP_ID. Note,
  6259. // CERT_ACCESS_PROP_ID is read only.
  6260. //--------------------------------------------------------------------------
  6261. // Set if context property writes are persisted. For instance, not set for
  6262. // memory store contexts. Set for registry based stores opened as read or write.
  6263. // Not set for registry based stores opened as read only.
  6264. #define CERT_ACCESS_STATE_WRITE_PERSIST_FLAG 0x1
  6265. // Set if context resides in a SYSTEM or SYSTEM_REGISTRY store.
  6266. #define CERT_ACCESS_STATE_SYSTEM_STORE_FLAG 0x2
  6267. // Set if context resides in a LocalMachine SYSTEM or SYSTEM_REGISTRY store.
  6268. #define CERT_ACCESS_STATE_LM_SYSTEM_STORE_FLAG 0x4
  6269. //+-------------------------------------------------------------------------
  6270. // Cryptographic Key Provider Information
  6271. //
  6272. // CRYPT_KEY_PROV_INFO defines the CERT_KEY_PROV_INFO_PROP_ID's pvData.
  6273. //
  6274. // The CRYPT_KEY_PROV_INFO fields are passed to CryptAcquireContext
  6275. // to get a HCRYPTPROV handle. The optional CRYPT_KEY_PROV_PARAM fields are
  6276. // passed to CryptSetProvParam to further initialize the provider.
  6277. //
  6278. // The dwKeySpec field identifies the private key to use from the container
  6279. // For example, AT_KEYEXCHANGE or AT_SIGNATURE.
  6280. //--------------------------------------------------------------------------
  6281. typedef struct _CRYPT_KEY_PROV_PARAM {
  6282. DWORD dwParam;
  6283. BYTE *pbData;
  6284. DWORD cbData;
  6285. DWORD dwFlags;
  6286. } CRYPT_KEY_PROV_PARAM, *PCRYPT_KEY_PROV_PARAM;
  6287. typedef struct _CRYPT_KEY_PROV_INFO {
  6288. LPWSTR pwszContainerName;
  6289. LPWSTR pwszProvName;
  6290. DWORD dwProvType;
  6291. DWORD dwFlags;
  6292. DWORD cProvParam;
  6293. PCRYPT_KEY_PROV_PARAM rgProvParam;
  6294. DWORD dwKeySpec;
  6295. } CRYPT_KEY_PROV_INFO, *PCRYPT_KEY_PROV_INFO;
  6296. //+-------------------------------------------------------------------------
  6297. // The following flag should be set in the above dwFlags to enable
  6298. // a CertSetCertificateContextProperty(CERT_KEY_CONTEXT_PROP_ID) after a
  6299. // CryptAcquireContext is done in the Sign or Decrypt Message functions.
  6300. //
  6301. // The following define must not collide with any of the
  6302. // CryptAcquireContext dwFlag defines.
  6303. //--------------------------------------------------------------------------
  6304. #define CERT_SET_KEY_PROV_HANDLE_PROP_ID 0x00000001
  6305. #define CERT_SET_KEY_CONTEXT_PROP_ID 0x00000001
  6306. //+-------------------------------------------------------------------------
  6307. // Certificate Key Context
  6308. //
  6309. // CERT_KEY_CONTEXT defines the CERT_KEY_CONTEXT_PROP_ID's pvData.
  6310. //--------------------------------------------------------------------------
  6311. typedef struct _CERT_KEY_CONTEXT {
  6312. DWORD cbSize; // sizeof(CERT_KEY_CONTEXT)
  6313. HCRYPTPROV hCryptProv;
  6314. DWORD dwKeySpec;
  6315. } CERT_KEY_CONTEXT, *PCERT_KEY_CONTEXT;
  6316. //+-------------------------------------------------------------------------
  6317. // Certificate Store Provider Types
  6318. //--------------------------------------------------------------------------
  6319. #define CERT_STORE_PROV_MSG ((LPCSTR) 1)
  6320. #define CERT_STORE_PROV_MEMORY ((LPCSTR) 2)
  6321. #define CERT_STORE_PROV_FILE ((LPCSTR) 3)
  6322. #define CERT_STORE_PROV_REG ((LPCSTR) 4)
  6323. #define CERT_STORE_PROV_PKCS7 ((LPCSTR) 5)
  6324. #define CERT_STORE_PROV_SERIALIZED ((LPCSTR) 6)
  6325. #define CERT_STORE_PROV_FILENAME_A ((LPCSTR) 7)
  6326. #define CERT_STORE_PROV_FILENAME_W ((LPCSTR) 8)
  6327. #define CERT_STORE_PROV_FILENAME CERT_STORE_PROV_FILENAME_W
  6328. #define CERT_STORE_PROV_SYSTEM_A ((LPCSTR) 9)
  6329. #define CERT_STORE_PROV_SYSTEM_W ((LPCSTR) 10)
  6330. #define CERT_STORE_PROV_SYSTEM CERT_STORE_PROV_SYSTEM_W
  6331. #define CERT_STORE_PROV_COLLECTION ((LPCSTR) 11)
  6332. #define CERT_STORE_PROV_SYSTEM_REGISTRY_A ((LPCSTR) 12)
  6333. #define CERT_STORE_PROV_SYSTEM_REGISTRY_W ((LPCSTR) 13)
  6334. #define CERT_STORE_PROV_SYSTEM_REGISTRY CERT_STORE_PROV_SYSTEM_REGISTRY_W
  6335. #define CERT_STORE_PROV_PHYSICAL_W ((LPCSTR) 14)
  6336. #define CERT_STORE_PROV_PHYSICAL CERT_STORE_PROV_PHYSICAL_W
  6337. #define CERT_STORE_PROV_SMART_CARD_W ((LPCSTR) 15)
  6338. #define CERT_STORE_PROV_SMART_CARD CERT_STORE_PROV_SMART_CARD_W
  6339. #define CERT_STORE_PROV_LDAP_W ((LPCSTR) 16)
  6340. #define CERT_STORE_PROV_LDAP CERT_STORE_PROV_LDAP_W
  6341. #define sz_CERT_STORE_PROV_MEMORY "Memory"
  6342. #define sz_CERT_STORE_PROV_FILENAME_W "File"
  6343. #define sz_CERT_STORE_PROV_FILENAME sz_CERT_STORE_PROV_FILENAME_W
  6344. #define sz_CERT_STORE_PROV_SYSTEM_W "System"
  6345. #define sz_CERT_STORE_PROV_SYSTEM sz_CERT_STORE_PROV_SYSTEM_W
  6346. #define sz_CERT_STORE_PROV_PKCS7 "PKCS7"
  6347. #define sz_CERT_STORE_PROV_SERIALIZED "Serialized"
  6348. #define sz_CERT_STORE_PROV_COLLECTION "Collection"
  6349. #define sz_CERT_STORE_PROV_SYSTEM_REGISTRY_W "SystemRegistry"
  6350. #define sz_CERT_STORE_PROV_SYSTEM_REGISTRY sz_CERT_STORE_PROV_SYSTEM_REGISTRY_W
  6351. #define sz_CERT_STORE_PROV_PHYSICAL_W "Physical"
  6352. #define sz_CERT_STORE_PROV_PHYSICAL sz_CERT_STORE_PROV_PHYSICAL_W
  6353. #define sz_CERT_STORE_PROV_SMART_CARD_W "SmartCard"
  6354. #define sz_CERT_STORE_PROV_SMART_CARD sz_CERT_STORE_PROV_SMART_CARD_W
  6355. #define sz_CERT_STORE_PROV_LDAP_W "Ldap"
  6356. #define sz_CERT_STORE_PROV_LDAP sz_CERT_STORE_PROV_LDAP_W
  6357. //+-------------------------------------------------------------------------
  6358. // Certificate Store verify/results flags
  6359. //--------------------------------------------------------------------------
  6360. #define CERT_STORE_SIGNATURE_FLAG 0x00000001
  6361. #define CERT_STORE_TIME_VALIDITY_FLAG 0x00000002
  6362. #define CERT_STORE_REVOCATION_FLAG 0x00000004
  6363. #define CERT_STORE_NO_CRL_FLAG 0x00010000
  6364. #define CERT_STORE_NO_ISSUER_FLAG 0x00020000
  6365. #define CERT_STORE_BASE_CRL_FLAG 0x00000100
  6366. #define CERT_STORE_DELTA_CRL_FLAG 0x00000200
  6367. //+-------------------------------------------------------------------------
  6368. // Certificate Store open/property flags
  6369. //--------------------------------------------------------------------------
  6370. #define CERT_STORE_NO_CRYPT_RELEASE_FLAG 0x00000001
  6371. #define CERT_STORE_SET_LOCALIZED_NAME_FLAG 0x00000002
  6372. #define CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG 0x00000004
  6373. #define CERT_STORE_DELETE_FLAG 0x00000010
  6374. #define CERT_STORE_UNSAFE_PHYSICAL_FLAG 0x00000020
  6375. #define CERT_STORE_SHARE_STORE_FLAG 0x00000040
  6376. #define CERT_STORE_SHARE_CONTEXT_FLAG 0x00000080
  6377. #define CERT_STORE_MANIFOLD_FLAG 0x00000100
  6378. #define CERT_STORE_ENUM_ARCHIVED_FLAG 0x00000200
  6379. #define CERT_STORE_UPDATE_KEYID_FLAG 0x00000400
  6380. #define CERT_STORE_BACKUP_RESTORE_FLAG 0x00000800
  6381. #define CERT_STORE_READONLY_FLAG 0x00008000
  6382. #define CERT_STORE_OPEN_EXISTING_FLAG 0x00004000
  6383. #define CERT_STORE_CREATE_NEW_FLAG 0x00002000
  6384. #define CERT_STORE_MAXIMUM_ALLOWED_FLAG 0x00001000
  6385. //+-------------------------------------------------------------------------
  6386. // Certificate Store Provider flags are in the HiWord (0xFFFF0000)
  6387. //--------------------------------------------------------------------------
  6388. //+-------------------------------------------------------------------------
  6389. // Certificate System Store Flag Values
  6390. //--------------------------------------------------------------------------
  6391. // Includes flags and location
  6392. #define CERT_SYSTEM_STORE_MASK 0xFFFF0000
  6393. // Set if pvPara points to a CERT_SYSTEM_STORE_RELOCATE_PARA structure
  6394. #define CERT_SYSTEM_STORE_RELOCATE_FLAG 0x80000000
  6395. typedef struct _CERT_SYSTEM_STORE_RELOCATE_PARA {
  6396. union {
  6397. HKEY hKeyBase;
  6398. void *pvBase;
  6399. };
  6400. union {
  6401. void *pvSystemStore;
  6402. LPCSTR pszSystemStore;
  6403. LPCWSTR pwszSystemStore;
  6404. };
  6405. } CERT_SYSTEM_STORE_RELOCATE_PARA, *PCERT_SYSTEM_STORE_RELOCATE_PARA;
  6406. // By default, when the CurrentUser "Root" store is opened, any SystemRegistry
  6407. // roots not also on the protected root list are deleted from the cache before
  6408. // CertOpenStore() returns. Set the following flag to return all the roots
  6409. // in the SystemRegistry without checking the protected root list.
  6410. #define CERT_SYSTEM_STORE_UNPROTECTED_FLAG 0x40000000
  6411. // Location of the system store:
  6412. #define CERT_SYSTEM_STORE_LOCATION_MASK 0x00FF0000
  6413. #define CERT_SYSTEM_STORE_LOCATION_SHIFT 16
  6414. // Registry: HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE
  6415. #define CERT_SYSTEM_STORE_CURRENT_USER_ID 1
  6416. #define CERT_SYSTEM_STORE_LOCAL_MACHINE_ID 2
  6417. // Registry: HKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography\Services
  6418. #define CERT_SYSTEM_STORE_CURRENT_SERVICE_ID 4
  6419. #define CERT_SYSTEM_STORE_SERVICES_ID 5
  6420. // Registry: HKEY_USERS
  6421. #define CERT_SYSTEM_STORE_USERS_ID 6
  6422. // Registry: HKEY_CURRENT_USER\Software\Policies\Microsoft\SystemCertificates
  6423. #define CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY_ID 7
  6424. // Registry: HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\SystemCertificates
  6425. #define CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY_ID 8
  6426. // Registry: HKEY_LOCAL_MACHINE\Software\Microsoft\EnterpriseCertificates
  6427. #define CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE_ID 9
  6428. #define CERT_SYSTEM_STORE_CURRENT_USER \
  6429. (CERT_SYSTEM_STORE_CURRENT_USER_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6430. #define CERT_SYSTEM_STORE_LOCAL_MACHINE \
  6431. (CERT_SYSTEM_STORE_LOCAL_MACHINE_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6432. #define CERT_SYSTEM_STORE_CURRENT_SERVICE \
  6433. (CERT_SYSTEM_STORE_CURRENT_SERVICE_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6434. #define CERT_SYSTEM_STORE_SERVICES \
  6435. (CERT_SYSTEM_STORE_SERVICES_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6436. #define CERT_SYSTEM_STORE_USERS \
  6437. (CERT_SYSTEM_STORE_USERS_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6438. #define CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY \
  6439. (CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY_ID << \
  6440. CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6441. #define CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY \
  6442. (CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY_ID << \
  6443. CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6444. #define CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE \
  6445. (CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE_ID << \
  6446. CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6447. //+-------------------------------------------------------------------------
  6448. // Group Policy Store Defines
  6449. //--------------------------------------------------------------------------
  6450. // Registry path to the Group Policy system stores
  6451. #define CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH \
  6452. L"Software\\Policies\\Microsoft\\SystemCertificates"
  6453. //+-------------------------------------------------------------------------
  6454. // EFS Defines
  6455. //--------------------------------------------------------------------------
  6456. // Registry path to the EFS EFSBlob SubKey - Value type is REG_BINARY
  6457. #define CERT_EFSBLOB_REGPATH \
  6458. CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH L"\\EFS"
  6459. #define CERT_EFSBLOB_VALUE_NAME L"EFSBlob"
  6460. //+-------------------------------------------------------------------------
  6461. // Protected Root Defines
  6462. //--------------------------------------------------------------------------
  6463. // Registry path to the Protected Roots Flags SubKey
  6464. #define CERT_PROT_ROOT_FLAGS_REGPATH \
  6465. CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH L"\\Root\\ProtectedRoots"
  6466. #define CERT_PROT_ROOT_FLAGS_VALUE_NAME L"Flags"
  6467. // Set the following flag to inhibit the opening of the CurrentUser's
  6468. // .Default physical store when opening the CurrentUser's "Root" system store.
  6469. // The .Default physical store open's the CurrentUser SystemRegistry "Root"
  6470. // store.
  6471. #define CERT_PROT_ROOT_DISABLE_CURRENT_USER_FLAG 0x1
  6472. // Set the following flag to inhibit the adding of roots from the
  6473. // CurrentUser SystemRegistry "Root" store to the protected root list
  6474. // when the "Root" store is initially protected.
  6475. #define CERT_PROT_ROOT_INHIBIT_ADD_AT_INIT_FLAG 0x2
  6476. // Set the following flag to inhibit the purging of protected roots from the
  6477. // CurrentUser SystemRegistry "Root" store that are
  6478. // also in the LocalMachine SystemRegistry "Root" store. Note, when not
  6479. // disabled, the purging is done silently without UI.
  6480. #define CERT_PROT_ROOT_INHIBIT_PURGE_LM_FLAG 0x4
  6481. // Set the following flag to inhibit the opening of the LocalMachine's
  6482. // .AuthRoot physical store when opening the LocalMachine's "Root" system store.
  6483. // The .AuthRoot physical store open's the LocalMachine SystemRegistry
  6484. // "AuthRoot" store. The "AuthRoot" store contains the pre-installed
  6485. // SSL ServerAuth and the ActiveX Authenticode "root" certificates.
  6486. #define CERT_PROT_ROOT_DISABLE_LM_AUTH_FLAG 0x8
  6487. // The semantics for the following legacy definition has been changed to be
  6488. // the same as for the CERT_PROT_ROOT_DISABLE_LM_AUTH_FLAG.
  6489. #define CERT_PROT_ROOT_ONLY_LM_GPT_FLAG 0x8
  6490. // Set the following flag to disable the requiring of the issuing CA
  6491. // certificate being in the "NTAuth" system registry store found in the
  6492. // CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE store location.
  6493. //
  6494. // When set, CertVerifyCertificateChainPolicy(CERT_CHAIN_POLICY_NT_AUTH)
  6495. // will check that the chain has a valid name constraint for all name
  6496. // spaces, including UPN if the issuing CA isn't in the "NTAuth" store.
  6497. #define CERT_PROT_ROOT_DISABLE_NT_AUTH_REQUIRED_FLAG 0x10
  6498. // Set the following flag to disable checking for not defined name
  6499. // constraints.
  6500. //
  6501. // When set, CertGetCertificateChain won't check for or set the following
  6502. // dwErrorStatus: CERT_TRUST_HAS_NOT_DEFINED_NAME_CONSTRAINT.
  6503. #define CERT_PROT_ROOT_DISABLE_NOT_DEFINED_NAME_CONSTRAINT_FLAG 0x20
  6504. //+-------------------------------------------------------------------------
  6505. // Trusted Publisher Definitions
  6506. //--------------------------------------------------------------------------
  6507. // Registry path to the trusted publisher "Safer" group policy subkey
  6508. #define CERT_TRUST_PUB_SAFER_GROUP_POLICY_REGPATH \
  6509. CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH L"\\TrustedPublisher\\Safer"
  6510. // Registry path to the Local Machine system stores
  6511. #define CERT_LOCAL_MACHINE_SYSTEM_STORE_REGPATH \
  6512. L"Software\\Microsoft\\SystemCertificates"
  6513. // Registry path to the trusted publisher "Safer" local machine subkey
  6514. #define CERT_TRUST_PUB_SAFER_LOCAL_MACHINE_REGPATH \
  6515. CERT_LOCAL_MACHINE_SYSTEM_STORE_REGPATH L"\\TrustedPublisher\\Safer"
  6516. // "Safer" subkey value names. All values are DWORDs.
  6517. #define CERT_TRUST_PUB_AUTHENTICODE_FLAGS_VALUE_NAME L"AuthenticodeFlags"
  6518. // AuthenticodeFlags definitions
  6519. // Definition of who is allowed to trust publishers
  6520. //
  6521. // Setting allowed trust to MACHINE_ADMIN or ENTERPRISE_ADMIN disables UI,
  6522. // only trusts publishers in the "TrustedPublisher" system store and
  6523. // inhibits the opening of the CurrentUser's .Default physical store when
  6524. // opening the CurrentUsers's "TrustedPublisher" system store.
  6525. //
  6526. // The .Default physical store open's the CurrentUser SystemRegistry
  6527. // "TrustedPublisher" store.
  6528. //
  6529. // Setting allowed trust to ENTERPRISE_ADMIN only opens the
  6530. // LocalMachine's .GroupPolicy and .Enterprise physical stores when opening
  6531. // the CurrentUser's "TrustedPublisher" system store or when opening the
  6532. // LocalMachine's "TrustedPublisher" system store.
  6533. #define CERT_TRUST_PUB_ALLOW_TRUST_MASK 0x00000003
  6534. #define CERT_TRUST_PUB_ALLOW_END_USER_TRUST 0x00000000
  6535. #define CERT_TRUST_PUB_ALLOW_MACHINE_ADMIN_TRUST 0x00000001
  6536. #define CERT_TRUST_PUB_ALLOW_ENTERPRISE_ADMIN_TRUST 0x00000002
  6537. // Set the following flag to enable revocation checking of the publisher
  6538. // chain.
  6539. #define CERT_TRUST_PUB_CHECK_PUBLISHER_REV_FLAG 0x00000100
  6540. // Set the following flag to enable revocation checking of the time stamp
  6541. // chain.
  6542. #define CERT_TRUST_PUB_CHECK_TIMESTAMP_REV_FLAG 0x00000200
  6543. //+-------------------------------------------------------------------------
  6544. // OCM Subcomponents Definitions
  6545. //--------------------------------------------------------------------------
  6546. // Registry path to the OCM Subcomponents local machine subkey
  6547. #define CERT_OCM_SUBCOMPONENTS_LOCAL_MACHINE_REGPATH \
  6548. L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\OC Manager\\Subcomponents"
  6549. // REG_DWORD, 1 is installed, 0 is NOT installed
  6550. #define CERT_OCM_SUBCOMPONENTS_ROOT_AUTO_UPDATE_VALUE_NAME L"RootAutoUpdate"
  6551. //+-------------------------------------------------------------------------
  6552. // AuthRoot Auto Update Definitions
  6553. //--------------------------------------------------------------------------
  6554. // Registry path to the AuthRoot "Auto Update" local machine subkey
  6555. #define CERT_AUTH_ROOT_AUTO_UPDATE_LOCAL_MACHINE_REGPATH \
  6556. CERT_LOCAL_MACHINE_SYSTEM_STORE_REGPATH L"\\AuthRoot\\AutoUpdate"
  6557. // AuthRoot Auto Update subkey value names.
  6558. // REG_SZ, URL to the directory containing the AuthRoots, CTL and Seq files
  6559. #define CERT_AUTH_ROOT_AUTO_UPDATE_ROOT_DIR_URL_VALUE_NAME L"RootDirUrl"
  6560. // REG_DWORD, seconds between syncs. 0 implies use default.
  6561. #define CERT_AUTH_ROOT_AUTO_UPDATE_SYNC_DELTA_TIME_VALUE_NAME L"SyncDeltaTime"
  6562. // REG_DWORD, misc flags
  6563. #define CERT_AUTH_ROOT_AUTO_UPDATE_FLAGS_VALUE_NAME L"Flags"
  6564. #define CERT_AUTH_ROOT_AUTO_UPDATE_DISABLE_UNTRUSTED_ROOT_LOGGING_FLAG 0x1
  6565. #define CERT_AUTH_ROOT_AUTO_UPDATE_DISABLE_PARTIAL_CHAIN_LOGGING_FLAG 0x2
  6566. // AuthRoot Auto Update filenames
  6567. // CTL containing the list of certs in the AuthRoot store
  6568. #define CERT_AUTH_ROOT_CTL_FILENAME L"authroot.stl"
  6569. #define CERT_AUTH_ROOT_CTL_FILENAME_A "authroot.stl"
  6570. // Cab containing the above CTL
  6571. #define CERT_AUTH_ROOT_CAB_FILENAME L"authrootstl.cab"
  6572. // SequenceNumber (Formatted as big endian ascii hex)
  6573. #define CERT_AUTH_ROOT_SEQ_FILENAME L"authrootseq.txt"
  6574. // Root certs extension
  6575. #define CERT_AUTH_ROOT_CERT_EXT L".crt"
  6576. //+-------------------------------------------------------------------------
  6577. // Certificate Registry Store Flag Values (CERT_STORE_REG)
  6578. //--------------------------------------------------------------------------
  6579. // Set this flag if the HKEY passed in pvPara points to a remote computer
  6580. // registry key.
  6581. #define CERT_REGISTRY_STORE_REMOTE_FLAG 0x10000
  6582. // Set this flag if the contexts are to be persisted as a single serialized
  6583. // store in the registry. Mainly used for stores downloaded from the GPT.
  6584. // Such as the CurrentUserGroupPolicy or LocalMachineGroupPolicy stores.
  6585. #define CERT_REGISTRY_STORE_SERIALIZED_FLAG 0x20000
  6586. // The following flags are for internal use. When set, the
  6587. // pvPara parameter passed to CertOpenStore is a pointer to the following
  6588. // data structure and not the HKEY. The above CERT_REGISTRY_STORE_REMOTE_FLAG
  6589. // is also set if hKeyBase was obtained via RegConnectRegistry().
  6590. #define CERT_REGISTRY_STORE_CLIENT_GPT_FLAG 0x80000000
  6591. #define CERT_REGISTRY_STORE_LM_GPT_FLAG 0x01000000
  6592. typedef struct _CERT_REGISTRY_STORE_CLIENT_GPT_PARA {
  6593. HKEY hKeyBase;
  6594. LPWSTR pwszRegPath;
  6595. } CERT_REGISTRY_STORE_CLIENT_GPT_PARA, *PCERT_REGISTRY_STORE_CLIENT_GPT_PARA;
  6596. // The following flag is for internal use. When set, the contexts are
  6597. // persisted into roaming files instead of the registry. Such as, the
  6598. // CurrentUser "My" store. When this flag is set, the following data structure
  6599. // is passed to CertOpenStore instead of HKEY.
  6600. #define CERT_REGISTRY_STORE_ROAMING_FLAG 0x40000
  6601. // hKey may be NULL or non-NULL. When non-NULL, existing contexts are
  6602. // moved from the registry to roaming files.
  6603. typedef struct _CERT_REGISTRY_STORE_ROAMING_PARA {
  6604. HKEY hKey;
  6605. LPWSTR pwszStoreDirectory;
  6606. } CERT_REGISTRY_STORE_ROAMING_PARA, *PCERT_REGISTRY_STORE_ROAMING_PARA;
  6607. // The following flag is for internal use. When set, the "My" DWORD value
  6608. // at HKLM\Software\Microsoft\Cryptography\IEDirtyFlags is set to 0x1
  6609. // whenever a certificate is added to the registry store.
  6610. //
  6611. // Legacy definition, no longer supported after 01-May-02 (Server 2003)
  6612. #define CERT_REGISTRY_STORE_MY_IE_DIRTY_FLAG 0x80000
  6613. // Registry path to the subkey containing the "My" DWORD value to be set
  6614. //
  6615. // Legacy definition, no longer supported after 01-May-02 (Server 2003)
  6616. #define CERT_IE_DIRTY_FLAGS_REGPATH \
  6617. L"Software\\Microsoft\\Cryptography\\IEDirtyFlags"
  6618. //+-------------------------------------------------------------------------
  6619. // Certificate File Store Flag Values for the providers:
  6620. // CERT_STORE_PROV_FILE
  6621. // CERT_STORE_PROV_FILENAME
  6622. // CERT_STORE_PROV_FILENAME_A
  6623. // CERT_STORE_PROV_FILENAME_W
  6624. // sz_CERT_STORE_PROV_FILENAME_W
  6625. //--------------------------------------------------------------------------
  6626. // Set this flag if any store changes are to be committed to the file.
  6627. // The changes are committed at CertCloseStore or by calling
  6628. // CertControlStore(CERT_STORE_CTRL_COMMIT).
  6629. //
  6630. // The open fails with E_INVALIDARG if both CERT_FILE_STORE_COMMIT_ENABLE_FLAG
  6631. // and CERT_STORE_READONLY_FLAG are set in dwFlags.
  6632. //
  6633. // For the FILENAME providers: if the file contains an X509 encoded
  6634. // certificate, the open fails with ERROR_ACCESS_DENIED.
  6635. //
  6636. // For the FILENAME providers: if CERT_STORE_CREATE_NEW_FLAG is set, the
  6637. // CreateFile uses CREATE_NEW. If CERT_STORE_OPEN_EXISTING is set, uses
  6638. // OPEN_EXISTING. Otherwise, defaults to OPEN_ALWAYS.
  6639. //
  6640. // For the FILENAME providers: the file is committed as either a PKCS7 or
  6641. // serialized store depending on the type read at open. However, if the
  6642. // file is empty then, if the filename has either a ".p7c" or ".spc"
  6643. // extension its committed as a PKCS7. Otherwise, its committed as a
  6644. // serialized store.
  6645. //
  6646. // For CERT_STORE_PROV_FILE, the file handle is duplicated. Its always
  6647. // committed as a serialized store.
  6648. //
  6649. #define CERT_FILE_STORE_COMMIT_ENABLE_FLAG 0x10000
  6650. //+-------------------------------------------------------------------------
  6651. // Certificate LDAP Store Flag Values for the providers:
  6652. // CERT_STORE_PROV_LDAP
  6653. // CERT_STORE_PROV_LDAP_W
  6654. // sz_CERT_STORE_PROV_LDAP_W
  6655. // sz_CERT_STORE_PROV_LDAP
  6656. //--------------------------------------------------------------------------
  6657. // Set this flag to digitally sign all of the ldap traffic to and from a
  6658. // Windows 2000 LDAP server using the Kerberos authentication protocol.
  6659. // This feature provides integrity required by some applications.
  6660. //
  6661. #define CERT_LDAP_STORE_SIGN_FLAG 0x10000
  6662. // Performs an A-Record only DNS lookup on the supplied host string.
  6663. // This prevents bogus DNS queries from being generated when resolving host
  6664. // names. Use this flag whenever passing a hostname as opposed to a
  6665. // domain name for the hostname parameter.
  6666. //
  6667. // See LDAP_OPT_AREC_EXCLUSIVE defined in winldap.h for more details.
  6668. #define CERT_LDAP_STORE_AREC_EXCLUSIVE_FLAG 0x20000
  6669. // Set this flag if the LDAP session handle has already been opened. When
  6670. // set, pvPara points to the following CERT_LDAP_STORE_OPENED_PARA structure.
  6671. #define CERT_LDAP_STORE_OPENED_FLAG 0x40000
  6672. typedef struct _CERT_LDAP_STORE_OPENED_PARA {
  6673. void *pvLdapSessionHandle; // The (LDAP *) handle returned by
  6674. // ldap_init
  6675. LPCWSTR pwszLdapUrl;
  6676. } CERT_LDAP_STORE_OPENED_PARA, *PCERT_LDAP_STORE_OPENED_PARA;
  6677. // Set this flag if the above CERT_LDAP_STORE_OPENED_FLAG is set and
  6678. // you want an ldap_unbind() of the above pvLdapSessionHandle when the
  6679. // store is closed. Note, if CertOpenStore() fails, then, ldap_unbind()
  6680. // isn't called.
  6681. #define CERT_LDAP_STORE_UNBIND_FLAG 0x80000
  6682. //+-------------------------------------------------------------------------
  6683. // Open the cert store using the specified store provider.
  6684. //
  6685. // If CERT_STORE_DELETE_FLAG is set, then, the store is deleted. NULL is
  6686. // returned for both success and failure. However, GetLastError() returns 0
  6687. // for success and nonzero for failure.
  6688. //
  6689. // If CERT_STORE_SET_LOCALIZED_NAME_FLAG is set, then, if supported, the
  6690. // provider sets the store's CERT_STORE_LOCALIZED_NAME_PROP_ID property.
  6691. // The store's localized name can be retrieved by calling
  6692. // CertSetStoreProperty(dwPropID = CERT_STORE_LOCALIZED_NAME_PROP_ID).
  6693. // This flag is supported by the following providers (and their sz_
  6694. // equivalent):
  6695. // CERT_STORE_PROV_FILENAME_A
  6696. // CERT_STORE_PROV_FILENAME_W
  6697. // CERT_STORE_PROV_SYSTEM_A
  6698. // CERT_STORE_PROV_SYSTEM_W
  6699. // CERT_STORE_PROV_SYSTEM_REGISTRY_A
  6700. // CERT_STORE_PROV_SYSTEM_REGISTRY_W
  6701. // CERT_STORE_PROV_PHYSICAL_W
  6702. //
  6703. // If CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG is set, then, the
  6704. // closing of the store's provider is deferred until all certificate,
  6705. // CRL and CTL contexts obtained from the store are freed. Also,
  6706. // if a non NULL HCRYPTPROV was passed, then, it will continue to be used.
  6707. // By default, the store's provider is closed on the final CertCloseStore.
  6708. // If this flag isn't set, then, any property changes made to previously
  6709. // duplicated contexts after the final CertCloseStore will not be persisted.
  6710. // By setting this flag, property changes made
  6711. // after the CertCloseStore will be persisted. Note, setting this flag
  6712. // causes extra overhead in doing context duplicates and frees.
  6713. // If CertCloseStore is called with CERT_CLOSE_STORE_FORCE_FLAG, then,
  6714. // the CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG flag is ignored.
  6715. //
  6716. // CERT_STORE_MANIFOLD_FLAG can be set to check for certificates having the
  6717. // manifold extension and archive the "older" certificates with the same
  6718. // manifold extension value. A certificate is archived by setting the
  6719. // CERT_ARCHIVED_PROP_ID.
  6720. //
  6721. // By default, contexts having the CERT_ARCHIVED_PROP_ID, are skipped
  6722. // during enumeration. CERT_STORE_ENUM_ARCHIVED_FLAG can be set to include
  6723. // archived contexts when enumerating. Note, contexts having the
  6724. // CERT_ARCHIVED_PROP_ID are still found for explicit finds, such as,
  6725. // finding a context with a specific hash or finding a certificate having
  6726. // a specific issuer and serial number.
  6727. //
  6728. // CERT_STORE_UPDATE_KEYID_FLAG can be set to also update the Key Identifier's
  6729. // CERT_KEY_PROV_INFO_PROP_ID property whenever a certificate's
  6730. // CERT_KEY_IDENTIFIER_PROP_ID or CERT_KEY_PROV_INFO_PROP_ID property is set
  6731. // and the other property already exists. If the Key Identifier's
  6732. // CERT_KEY_PROV_INFO_PROP_ID already exists, it isn't updated. Any
  6733. // errors encountered are silently ignored.
  6734. //
  6735. // By default, this flag is implicitly set for the "My\.Default" CurrentUser
  6736. // and LocalMachine physical stores.
  6737. //
  6738. // CERT_STORE_READONLY_FLAG can be set to open the store as read only.
  6739. // Otherwise, the store is opened as read/write.
  6740. //
  6741. // CERT_STORE_OPEN_EXISTING_FLAG can be set to only open an existing
  6742. // store. CERT_STORE_CREATE_NEW_FLAG can be set to create a new store and
  6743. // fail if the store already exists. Otherwise, the default is to open
  6744. // an existing store or create a new store if it doesn't already exist.
  6745. //
  6746. // hCryptProv specifies the crypto provider to use to create the hash
  6747. // properties or verify the signature of a subject certificate or CRL.
  6748. // The store doesn't need to use a private
  6749. // key. If the CERT_STORE_NO_CRYPT_RELEASE_FLAG isn't set, hCryptProv is
  6750. // CryptReleaseContext'ed on the final CertCloseStore.
  6751. //
  6752. // Note, if the open fails, hCryptProv is released if it would have been
  6753. // released when the store was closed.
  6754. //
  6755. // If hCryptProv is zero, then, the default provider and container for the
  6756. // PROV_RSA_FULL provider type is CryptAcquireContext'ed with
  6757. // CRYPT_VERIFYCONTEXT access. The CryptAcquireContext is deferred until
  6758. // the first create hash or verify signature. In addition, once acquired,
  6759. // the default provider isn't released until process exit when crypt32.dll
  6760. // is unloaded. The acquired default provider is shared across all stores
  6761. // and threads.
  6762. //
  6763. // After initializing the store's data structures and optionally acquiring a
  6764. // default crypt provider, CertOpenStore calls CryptGetOIDFunctionAddress to
  6765. // get the address of the CRYPT_OID_OPEN_STORE_PROV_FUNC specified by
  6766. // lpszStoreProvider. Since a store can contain certificates with different
  6767. // encoding types, CryptGetOIDFunctionAddress is called with dwEncodingType
  6768. // set to 0 and not the dwEncodingType passed to CertOpenStore.
  6769. // PFN_CERT_DLL_OPEN_STORE_FUNC specifies the signature of the provider's
  6770. // open function. This provider open function is called to load the
  6771. // store's certificates and CRLs. Optionally, the provider may return an
  6772. // array of functions called before a certificate or CRL is added or deleted
  6773. // or has a property that is set.
  6774. //
  6775. // Use of the dwEncodingType parameter is provider dependent. The type
  6776. // definition for pvPara also depends on the provider.
  6777. //
  6778. // Store providers are installed or registered via
  6779. // CryptInstallOIDFunctionAddress or CryptRegisterOIDFunction, where,
  6780. // dwEncodingType is 0 and pszFuncName is CRYPT_OID_OPEN_STORE_PROV_FUNC.
  6781. //
  6782. // Here's a list of the predefined provider types (implemented in crypt32.dll):
  6783. //
  6784. // CERT_STORE_PROV_MSG:
  6785. // Gets the certificates and CRLs from the specified cryptographic message.
  6786. // dwEncodingType contains the message and certificate encoding types.
  6787. // The message's handle is passed in pvPara. Given,
  6788. // HCRYPTMSG hCryptMsg; pvPara = (const void *) hCryptMsg;
  6789. //
  6790. // CERT_STORE_PROV_MEMORY
  6791. // sz_CERT_STORE_PROV_MEMORY:
  6792. // Opens a store without any initial certificates or CRLs. pvPara
  6793. // isn't used.
  6794. //
  6795. // CERT_STORE_PROV_FILE:
  6796. // Reads the certificates and CRLs from the specified file. The file's
  6797. // handle is passed in pvPara. Given,
  6798. // HANDLE hFile; pvPara = (const void *) hFile;
  6799. //
  6800. // For a successful open, the file pointer is advanced past
  6801. // the certificates and CRLs and their properties read from the file.
  6802. // Note, only expects a serialized store and not a file containing
  6803. // either a PKCS #7 signed message or a single encoded certificate.
  6804. //
  6805. // The hFile isn't closed.
  6806. //
  6807. // CERT_STORE_PROV_REG:
  6808. // Reads the certificates and CRLs from the registry. The registry's
  6809. // key handle is passed in pvPara. Given,
  6810. // HKEY hKey; pvPara = (const void *) hKey;
  6811. //
  6812. // The input hKey isn't closed by the provider. Before returning, the
  6813. // provider opens it own copy of the hKey.
  6814. //
  6815. // If CERT_STORE_READONLY_FLAG is set, then, the registry subkeys are
  6816. // RegOpenKey'ed with KEY_READ_ACCESS. Otherwise, the registry subkeys
  6817. // are RegCreateKey'ed with KEY_ALL_ACCESS.
  6818. //
  6819. // This provider returns the array of functions for reading, writing,
  6820. // deleting and property setting certificates and CRLs.
  6821. // Any changes to the opened store are immediately pushed through to
  6822. // the registry. However, if CERT_STORE_READONLY_FLAG is set, then,
  6823. // writing, deleting or property setting results in a
  6824. // SetLastError(E_ACCESSDENIED).
  6825. //
  6826. // Note, all the certificates and CRLs are read from the registry
  6827. // when the store is opened. The opened store serves as a write through
  6828. // cache.
  6829. //
  6830. // If CERT_REGISTRY_STORE_SERIALIZED_FLAG is set, then, the
  6831. // contexts are persisted as a single serialized store subkey in the
  6832. // registry.
  6833. //
  6834. // CERT_STORE_PROV_PKCS7:
  6835. // sz_CERT_STORE_PROV_PKCS7:
  6836. // Gets the certificates and CRLs from the encoded PKCS #7 signed message.
  6837. // dwEncodingType specifies the message and certificate encoding types.
  6838. // The pointer to the encoded message's blob is passed in pvPara. Given,
  6839. // CRYPT_DATA_BLOB EncodedMsg; pvPara = (const void *) &EncodedMsg;
  6840. //
  6841. // Note, also supports the IE3.0 special version of a
  6842. // PKCS #7 signed message referred to as a "SPC" formatted message.
  6843. //
  6844. // CERT_STORE_PROV_SERIALIZED:
  6845. // sz_CERT_STORE_PROV_SERIALIZED:
  6846. // Gets the certificates and CRLs from memory containing a serialized
  6847. // store. The pointer to the serialized memory blob is passed in pvPara.
  6848. // Given,
  6849. // CRYPT_DATA_BLOB Serialized; pvPara = (const void *) &Serialized;
  6850. //
  6851. // CERT_STORE_PROV_FILENAME_A:
  6852. // CERT_STORE_PROV_FILENAME_W:
  6853. // CERT_STORE_PROV_FILENAME:
  6854. // sz_CERT_STORE_PROV_FILENAME_W:
  6855. // sz_CERT_STORE_PROV_FILENAME:
  6856. // Opens the file and first attempts to read as a serialized store. Then,
  6857. // as a PKCS #7 signed message. Finally, as a single encoded certificate.
  6858. // The filename is passed in pvPara. The filename is UNICODE for the
  6859. // "_W" provider and ASCII for the "_A" provider. For "_W": given,
  6860. // LPCWSTR pwszFilename; pvPara = (const void *) pwszFilename;
  6861. // For "_A": given,
  6862. // LPCSTR pszFilename; pvPara = (const void *) pszFilename;
  6863. //
  6864. // Note, the default (without "_A" or "_W") is unicode.
  6865. //
  6866. // Note, also supports the reading of the IE3.0 special version of a
  6867. // PKCS #7 signed message file referred to as a "SPC" formatted file.
  6868. //
  6869. // CERT_STORE_PROV_SYSTEM_A:
  6870. // CERT_STORE_PROV_SYSTEM_W:
  6871. // CERT_STORE_PROV_SYSTEM:
  6872. // sz_CERT_STORE_PROV_SYSTEM_W:
  6873. // sz_CERT_STORE_PROV_SYSTEM:
  6874. // Opens the specified logical "System" store. The upper word of the
  6875. // dwFlags parameter is used to specify the location of the system store.
  6876. //
  6877. // A "System" store is a collection consisting of one or more "Physical"
  6878. // stores. A "Physical" store is registered via the
  6879. // CertRegisterPhysicalStore API. Each of the registered physical stores
  6880. // is CertStoreOpen'ed and added to the collection via
  6881. // CertAddStoreToCollection.
  6882. //
  6883. // The CERT_SYSTEM_STORE_CURRENT_USER, CERT_SYSTEM_STORE_LOCAL_MACHINE,
  6884. // CERT_SYSTEM_STORE_CURRENT_SERVICE, CERT_SYSTEM_STORE_SERVICES,
  6885. // CERT_SYSTEM_STORE_USERS, CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY,
  6886. // CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY and
  6887. // CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRSE
  6888. // system stores by default have a "SystemRegistry" store that is
  6889. // opened and added to the collection.
  6890. //
  6891. // The system store name is passed in pvPara. The name is UNICODE for the
  6892. // "_W" provider and ASCII for the "_A" provider. For "_W": given,
  6893. // LPCWSTR pwszSystemName; pvPara = (const void *) pwszSystemName;
  6894. // For "_A": given,
  6895. // LPCSTR pszSystemName; pvPara = (const void *) pszSystemName;
  6896. //
  6897. // Note, the default (without "_A" or "_W") is UNICODE.
  6898. //
  6899. // The system store name can't contain any backslashes.
  6900. //
  6901. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvPara
  6902. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure instead
  6903. // of pointing to a null terminated UNICODE or ASCII string.
  6904. // Sibling physical stores are also opened as relocated using
  6905. // pvPara's hKeyBase.
  6906. //
  6907. // The CERT_SYSTEM_STORE_SERVICES or CERT_SYSTEM_STORE_USERS system
  6908. // store name must be prefixed with the ServiceName or UserName.
  6909. // For example, "ServiceName\Trust".
  6910. //
  6911. // Stores on remote computers can be accessed for the
  6912. // CERT_SYSTEM_STORE_LOCAL_MACHINE, CERT_SYSTEM_STORE_SERVICES,
  6913. // CERT_SYSTEM_STORE_USERS, CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY
  6914. // or CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE
  6915. // locations by prepending the computer name. For example, a remote
  6916. // local machine store is accessed via "\\ComputerName\Trust" or
  6917. // "ComputerName\Trust". A remote service store is accessed via
  6918. // "\\ComputerName\ServiceName\Trust". The leading "\\" backslashes are
  6919. // optional in the ComputerName.
  6920. //
  6921. // If CERT_STORE_READONLY_FLAG is set, then, the registry is
  6922. // RegOpenKey'ed with KEY_READ_ACCESS. Otherwise, the registry is
  6923. // RegCreateKey'ed with KEY_ALL_ACCESS.
  6924. //
  6925. // The "root" store is treated differently from the other system
  6926. // stores. Before a certificate is added to or deleted from the "root"
  6927. // store, a pop up message box is displayed. The certificate's subject,
  6928. // issuer, serial number, time validity, sha1 and md5 thumbprints are
  6929. // displayed. The user is given the option to do the add or delete.
  6930. // If they don't allow the operation, LastError is set to E_ACCESSDENIED.
  6931. //
  6932. // CERT_STORE_PROV_SYSTEM_REGISTRY_A
  6933. // CERT_STORE_PROV_SYSTEM_REGISTRY_W
  6934. // CERT_STORE_PROV_SYSTEM_REGISTRY
  6935. // sz_CERT_STORE_PROV_SYSTEM_REGISTRY_W
  6936. // sz_CERT_STORE_PROV_SYSTEM_REGISTRY
  6937. // Opens the "System" store's default "Physical" store residing in the
  6938. // registry. The upper word of the dwFlags
  6939. // parameter is used to specify the location of the system store.
  6940. //
  6941. // After opening the registry key associated with the system name,
  6942. // the CERT_STORE_PROV_REG provider is called to complete the open.
  6943. //
  6944. // The system store name is passed in pvPara. The name is UNICODE for the
  6945. // "_W" provider and ASCII for the "_A" provider. For "_W": given,
  6946. // LPCWSTR pwszSystemName; pvPara = (const void *) pwszSystemName;
  6947. // For "_A": given,
  6948. // LPCSTR pszSystemName; pvPara = (const void *) pszSystemName;
  6949. //
  6950. // Note, the default (without "_A" or "_W") is UNICODE.
  6951. //
  6952. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvPara
  6953. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure instead
  6954. // of pointing to a null terminated UNICODE or ASCII string.
  6955. //
  6956. // See above for details on prepending a ServiceName and/or ComputerName
  6957. // to the store name.
  6958. //
  6959. // If CERT_STORE_READONLY_FLAG is set, then, the registry is
  6960. // RegOpenKey'ed with KEY_READ_ACCESS. Otherwise, the registry is
  6961. // RegCreateKey'ed with KEY_ALL_ACCESS.
  6962. //
  6963. // The "root" store is treated differently from the other system
  6964. // stores. Before a certificate is added to or deleted from the "root"
  6965. // store, a pop up message box is displayed. The certificate's subject,
  6966. // issuer, serial number, time validity, sha1 and md5 thumbprints are
  6967. // displayed. The user is given the option to do the add or delete.
  6968. // If they don't allow the operation, LastError is set to E_ACCESSDENIED.
  6969. //
  6970. // CERT_STORE_PROV_PHYSICAL_W
  6971. // CERT_STORE_PROV_PHYSICAL
  6972. // sz_CERT_STORE_PROV_PHYSICAL_W
  6973. // sz_CERT_STORE_PROV_PHYSICAL
  6974. // Opens the specified "Physical" store in the "System" store.
  6975. //
  6976. // Both the system store and physical names are passed in pvPara. The
  6977. // names are separated with an intervening "\". For example,
  6978. // "Root\.Default". The string is UNICODE.
  6979. //
  6980. // The system and physical store names can't contain any backslashes.
  6981. //
  6982. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvPara
  6983. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure instead
  6984. // of pointing to a null terminated UNICODE string.
  6985. // The specified physical store is opened as relocated using pvPara's
  6986. // hKeyBase.
  6987. //
  6988. // For CERT_SYSTEM_STORE_SERVICES or CERT_SYSTEM_STORE_USERS,
  6989. // the system and physical store names
  6990. // must be prefixed with the ServiceName or UserName. For example,
  6991. // "ServiceName\Root\.Default".
  6992. //
  6993. // Physical stores on remote computers can be accessed for the
  6994. // CERT_SYSTEM_STORE_LOCAL_MACHINE, CERT_SYSTEM_STORE_SERVICES,
  6995. // CERT_SYSTEM_STORE_USERS, CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY
  6996. // or CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE
  6997. // locations by prepending the computer name. For example, a remote
  6998. // local machine store is accessed via "\\ComputerName\Root\.Default"
  6999. // or "ComputerName\Root\.Default". A remote service store is
  7000. // accessed via "\\ComputerName\ServiceName\Root\.Default". The
  7001. // leading "\\" backslashes are optional in the ComputerName.
  7002. //
  7003. // CERT_STORE_PROV_COLLECTION
  7004. // sz_CERT_STORE_PROV_COLLECTION
  7005. // Opens a store that is a collection of other stores. Stores are
  7006. // added or removed to/from the collection via the CertAddStoreToCollection
  7007. // and CertRemoveStoreFromCollection APIs.
  7008. //
  7009. // CERT_STORE_PROV_SMART_CARD_W
  7010. // CERT_STORE_PROV_SMART_CARD
  7011. // sz_CERT_STORE_PROV_SMART_CARD_W
  7012. // sz_CERT_STORE_PROV_SMART_CARD
  7013. // Opens a store instantiated over a particular smart card storage. pvPara
  7014. // identifies where on the card the store is located and is of the
  7015. // following format:
  7016. //
  7017. // Card Name\Provider Name\Provider Type[\Container Name]
  7018. //
  7019. // Container Name is optional and if NOT specified the Card Name is used
  7020. // as the Container Name. Future versions of the provider will support
  7021. // instantiating the store over the entire card in which case just
  7022. // Card Name ( or id ) will be sufficient.
  7023. //
  7024. // Here's a list of the predefined provider types (implemented in
  7025. // cryptnet.dll):
  7026. //
  7027. // CERT_STORE_PROV_LDAP_W
  7028. // CERT_STORE_PROV_LDAP
  7029. // sz_CERT_STORE_PROV_LDAP_W
  7030. // sz_CERT_STORE_PROV_LDAP
  7031. // Opens a store over the results of the query specified by and LDAP
  7032. // URL which is passed in via pvPara. In order to do writes to the
  7033. // store the URL must specify a BASE query, no filter and a single
  7034. // attribute.
  7035. //
  7036. //--------------------------------------------------------------------------
  7037. WINCRYPT32API
  7038. HCERTSTORE
  7039. WINAPI
  7040. CertOpenStore(
  7041. IN LPCSTR lpszStoreProvider,
  7042. IN DWORD dwEncodingType,
  7043. IN HCRYPTPROV hCryptProv,
  7044. IN DWORD dwFlags,
  7045. IN const void *pvPara
  7046. );
  7047. //+-------------------------------------------------------------------------
  7048. // OID Installable Certificate Store Provider Data Structures
  7049. //--------------------------------------------------------------------------
  7050. // Handle returned by the store provider when opened.
  7051. typedef void *HCERTSTOREPROV;
  7052. // Store Provider OID function's pszFuncName.
  7053. #define CRYPT_OID_OPEN_STORE_PROV_FUNC "CertDllOpenStoreProv"
  7054. // Note, the Store Provider OID function's dwEncodingType is always 0.
  7055. // The following information is returned by the provider when opened. Its
  7056. // zeroed with cbSize set before the provider is called. If the provider
  7057. // doesn't need to be called again after the open it doesn't need to
  7058. // make any updates to the CERT_STORE_PROV_INFO.
  7059. typedef struct _CERT_STORE_PROV_INFO {
  7060. DWORD cbSize;
  7061. DWORD cStoreProvFunc;
  7062. void **rgpvStoreProvFunc;
  7063. HCERTSTOREPROV hStoreProv;
  7064. DWORD dwStoreProvFlags;
  7065. HCRYPTOIDFUNCADDR hStoreProvFuncAddr2;
  7066. } CERT_STORE_PROV_INFO, *PCERT_STORE_PROV_INFO;
  7067. // Definition of the store provider's open function.
  7068. //
  7069. // *pStoreProvInfo has been zeroed before the call.
  7070. //
  7071. // Note, pStoreProvInfo->cStoreProvFunc should be set last. Once set,
  7072. // all subsequent store calls, such as CertAddSerializedElementToStore will
  7073. // call the appropriate provider callback function.
  7074. typedef BOOL (WINAPI *PFN_CERT_DLL_OPEN_STORE_PROV_FUNC)(
  7075. IN LPCSTR lpszStoreProvider,
  7076. IN DWORD dwEncodingType,
  7077. IN HCRYPTPROV hCryptProv,
  7078. IN DWORD dwFlags,
  7079. IN const void *pvPara,
  7080. IN HCERTSTORE hCertStore,
  7081. IN OUT PCERT_STORE_PROV_INFO pStoreProvInfo
  7082. );
  7083. // The open callback sets the following flag, if it maintains its
  7084. // contexts externally and not in the cached store.
  7085. #define CERT_STORE_PROV_EXTERNAL_FLAG 0x1
  7086. // The open callback sets the following flag for a successful delete.
  7087. // When set, the close callback isn't called.
  7088. #define CERT_STORE_PROV_DELETED_FLAG 0x2
  7089. // The open callback sets the following flag if it doesn't persist store
  7090. // changes.
  7091. #define CERT_STORE_PROV_NO_PERSIST_FLAG 0x4
  7092. // The open callback sets the following flag if the contexts are persisted
  7093. // to a system store.
  7094. #define CERT_STORE_PROV_SYSTEM_STORE_FLAG 0x8
  7095. // The open callback sets the following flag if the contexts are persisted
  7096. // to a LocalMachine system store.
  7097. #define CERT_STORE_PROV_LM_SYSTEM_STORE_FLAG 0x10
  7098. // Indices into the store provider's array of callback functions.
  7099. //
  7100. // The provider can implement any subset of the following functions. It
  7101. // sets pStoreProvInfo->cStoreProvFunc to the last index + 1 and any
  7102. // preceding not implemented functions to NULL.
  7103. #define CERT_STORE_PROV_CLOSE_FUNC 0
  7104. #define CERT_STORE_PROV_READ_CERT_FUNC 1
  7105. #define CERT_STORE_PROV_WRITE_CERT_FUNC 2
  7106. #define CERT_STORE_PROV_DELETE_CERT_FUNC 3
  7107. #define CERT_STORE_PROV_SET_CERT_PROPERTY_FUNC 4
  7108. #define CERT_STORE_PROV_READ_CRL_FUNC 5
  7109. #define CERT_STORE_PROV_WRITE_CRL_FUNC 6
  7110. #define CERT_STORE_PROV_DELETE_CRL_FUNC 7
  7111. #define CERT_STORE_PROV_SET_CRL_PROPERTY_FUNC 8
  7112. #define CERT_STORE_PROV_READ_CTL_FUNC 9
  7113. #define CERT_STORE_PROV_WRITE_CTL_FUNC 10
  7114. #define CERT_STORE_PROV_DELETE_CTL_FUNC 11
  7115. #define CERT_STORE_PROV_SET_CTL_PROPERTY_FUNC 12
  7116. #define CERT_STORE_PROV_CONTROL_FUNC 13
  7117. #define CERT_STORE_PROV_FIND_CERT_FUNC 14
  7118. #define CERT_STORE_PROV_FREE_FIND_CERT_FUNC 15
  7119. #define CERT_STORE_PROV_GET_CERT_PROPERTY_FUNC 16
  7120. #define CERT_STORE_PROV_FIND_CRL_FUNC 17
  7121. #define CERT_STORE_PROV_FREE_FIND_CRL_FUNC 18
  7122. #define CERT_STORE_PROV_GET_CRL_PROPERTY_FUNC 19
  7123. #define CERT_STORE_PROV_FIND_CTL_FUNC 20
  7124. #define CERT_STORE_PROV_FREE_FIND_CTL_FUNC 21
  7125. #define CERT_STORE_PROV_GET_CTL_PROPERTY_FUNC 22
  7126. // Called by CertCloseStore when the store's reference count is
  7127. // decremented to 0.
  7128. typedef void (WINAPI *PFN_CERT_STORE_PROV_CLOSE)(
  7129. IN HCERTSTOREPROV hStoreProv,
  7130. IN DWORD dwFlags
  7131. );
  7132. // Currently not called directly by the store APIs. However, may be exported
  7133. // to support other providers based on it.
  7134. //
  7135. // Reads the provider's copy of the certificate context. If it exists,
  7136. // creates a new certificate context.
  7137. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_READ_CERT)(
  7138. IN HCERTSTOREPROV hStoreProv,
  7139. IN PCCERT_CONTEXT pStoreCertContext,
  7140. IN DWORD dwFlags,
  7141. OUT PCCERT_CONTEXT *ppProvCertContext
  7142. );
  7143. #define CERT_STORE_PROV_WRITE_ADD_FLAG 0x1
  7144. // Called by CertAddEncodedCertificateToStore,
  7145. // CertAddCertificateContextToStore or CertAddSerializedElementToStore before
  7146. // adding to the store. The CERT_STORE_PROV_WRITE_ADD_FLAG is set. In
  7147. // addition to the encoded certificate, the added pCertContext might also
  7148. // have properties.
  7149. //
  7150. // Returns TRUE if its OK to update the the store.
  7151. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_WRITE_CERT)(
  7152. IN HCERTSTOREPROV hStoreProv,
  7153. IN PCCERT_CONTEXT pCertContext,
  7154. IN DWORD dwFlags
  7155. );
  7156. // Called by CertDeleteCertificateFromStore before deleting from the
  7157. // store.
  7158. //
  7159. // Returns TRUE if its OK to delete from the store.
  7160. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_DELETE_CERT)(
  7161. IN HCERTSTOREPROV hStoreProv,
  7162. IN PCCERT_CONTEXT pCertContext,
  7163. IN DWORD dwFlags
  7164. );
  7165. // Called by CertSetCertificateContextProperty before setting the
  7166. // certificate's property. Also called by CertGetCertificateContextProperty,
  7167. // when getting a hash property that needs to be created and then persisted
  7168. // via the set.
  7169. //
  7170. // Upon input, the property hasn't been set for the pCertContext parameter.
  7171. //
  7172. // Returns TRUE if its OK to set the property.
  7173. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_SET_CERT_PROPERTY)(
  7174. IN HCERTSTOREPROV hStoreProv,
  7175. IN PCCERT_CONTEXT pCertContext,
  7176. IN DWORD dwPropId,
  7177. IN DWORD dwFlags,
  7178. IN const void *pvData
  7179. );
  7180. // Currently not called directly by the store APIs. However, may be exported
  7181. // to support other providers based on it.
  7182. //
  7183. // Reads the provider's copy of the CRL context. If it exists,
  7184. // creates a new CRL context.
  7185. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_READ_CRL)(
  7186. IN HCERTSTOREPROV hStoreProv,
  7187. IN PCCRL_CONTEXT pStoreCrlContext,
  7188. IN DWORD dwFlags,
  7189. OUT PCCRL_CONTEXT *ppProvCrlContext
  7190. );
  7191. // Called by CertAddEncodedCRLToStore,
  7192. // CertAddCRLContextToStore or CertAddSerializedElementToStore before
  7193. // adding to the store. The CERT_STORE_PROV_WRITE_ADD_FLAG is set. In
  7194. // addition to the encoded CRL, the added pCertContext might also
  7195. // have properties.
  7196. //
  7197. // Returns TRUE if its OK to update the the store.
  7198. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_WRITE_CRL)(
  7199. IN HCERTSTOREPROV hStoreProv,
  7200. IN PCCRL_CONTEXT pCrlContext,
  7201. IN DWORD dwFlags
  7202. );
  7203. // Called by CertDeleteCRLFromStore before deleting from the store.
  7204. //
  7205. // Returns TRUE if its OK to delete from the store.
  7206. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_DELETE_CRL)(
  7207. IN HCERTSTOREPROV hStoreProv,
  7208. IN PCCRL_CONTEXT pCrlContext,
  7209. IN DWORD dwFlags
  7210. );
  7211. // Called by CertSetCRLContextProperty before setting the
  7212. // CRL's property. Also called by CertGetCRLContextProperty,
  7213. // when getting a hash property that needs to be created and then persisted
  7214. // via the set.
  7215. //
  7216. // Upon input, the property hasn't been set for the pCrlContext parameter.
  7217. //
  7218. // Returns TRUE if its OK to set the property.
  7219. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_SET_CRL_PROPERTY)(
  7220. IN HCERTSTOREPROV hStoreProv,
  7221. IN PCCRL_CONTEXT pCrlContext,
  7222. IN DWORD dwPropId,
  7223. IN DWORD dwFlags,
  7224. IN const void *pvData
  7225. );
  7226. // Currently not called directly by the store APIs. However, may be exported
  7227. // to support other providers based on it.
  7228. //
  7229. // Reads the provider's copy of the CTL context. If it exists,
  7230. // creates a new CTL context.
  7231. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_READ_CTL)(
  7232. IN HCERTSTOREPROV hStoreProv,
  7233. IN PCCTL_CONTEXT pStoreCtlContext,
  7234. IN DWORD dwFlags,
  7235. OUT PCCTL_CONTEXT *ppProvCtlContext
  7236. );
  7237. // Called by CertAddEncodedCTLToStore,
  7238. // CertAddCTLContextToStore or CertAddSerializedElementToStore before
  7239. // adding to the store. The CERT_STORE_PROV_WRITE_ADD_FLAG is set. In
  7240. // addition to the encoded CTL, the added pCertContext might also
  7241. // have properties.
  7242. //
  7243. // Returns TRUE if its OK to update the the store.
  7244. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_WRITE_CTL)(
  7245. IN HCERTSTOREPROV hStoreProv,
  7246. IN PCCTL_CONTEXT pCtlContext,
  7247. IN DWORD dwFlags
  7248. );
  7249. // Called by CertDeleteCTLFromStore before deleting from the store.
  7250. //
  7251. // Returns TRUE if its OK to delete from the store.
  7252. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_DELETE_CTL)(
  7253. IN HCERTSTOREPROV hStoreProv,
  7254. IN PCCTL_CONTEXT pCtlContext,
  7255. IN DWORD dwFlags
  7256. );
  7257. // Called by CertSetCTLContextProperty before setting the
  7258. // CTL's property. Also called by CertGetCTLContextProperty,
  7259. // when getting a hash property that needs to be created and then persisted
  7260. // via the set.
  7261. //
  7262. // Upon input, the property hasn't been set for the pCtlContext parameter.
  7263. //
  7264. // Returns TRUE if its OK to set the property.
  7265. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_SET_CTL_PROPERTY)(
  7266. IN HCERTSTOREPROV hStoreProv,
  7267. IN PCCTL_CONTEXT pCtlContext,
  7268. IN DWORD dwPropId,
  7269. IN DWORD dwFlags,
  7270. IN const void *pvData
  7271. );
  7272. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_CONTROL)(
  7273. IN HCERTSTOREPROV hStoreProv,
  7274. IN DWORD dwFlags,
  7275. IN DWORD dwCtrlType,
  7276. IN void const *pvCtrlPara
  7277. );
  7278. typedef struct _CERT_STORE_PROV_FIND_INFO {
  7279. DWORD cbSize;
  7280. DWORD dwMsgAndCertEncodingType;
  7281. DWORD dwFindFlags;
  7282. DWORD dwFindType;
  7283. const void *pvFindPara;
  7284. } CERT_STORE_PROV_FIND_INFO, *PCERT_STORE_PROV_FIND_INFO;
  7285. typedef const CERT_STORE_PROV_FIND_INFO CCERT_STORE_PROV_FIND_INFO,
  7286. *PCCERT_STORE_PROV_FIND_INFO;
  7287. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_FIND_CERT)(
  7288. IN HCERTSTOREPROV hStoreProv,
  7289. IN PCCERT_STORE_PROV_FIND_INFO pFindInfo,
  7290. IN PCCERT_CONTEXT pPrevCertContext,
  7291. IN DWORD dwFlags,
  7292. IN OUT void **ppvStoreProvFindInfo,
  7293. OUT PCCERT_CONTEXT *ppProvCertContext
  7294. );
  7295. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_FREE_FIND_CERT)(
  7296. IN HCERTSTOREPROV hStoreProv,
  7297. IN PCCERT_CONTEXT pCertContext,
  7298. IN void *pvStoreProvFindInfo,
  7299. IN DWORD dwFlags
  7300. );
  7301. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_GET_CERT_PROPERTY)(
  7302. IN HCERTSTOREPROV hStoreProv,
  7303. IN PCCERT_CONTEXT pCertContext,
  7304. IN DWORD dwPropId,
  7305. IN DWORD dwFlags,
  7306. OUT void *pvData,
  7307. IN OUT DWORD *pcbData
  7308. );
  7309. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_FIND_CRL)(
  7310. IN HCERTSTOREPROV hStoreProv,
  7311. IN PCCERT_STORE_PROV_FIND_INFO pFindInfo,
  7312. IN PCCRL_CONTEXT pPrevCrlContext,
  7313. IN DWORD dwFlags,
  7314. IN OUT void **ppvStoreProvFindInfo,
  7315. OUT PCCRL_CONTEXT *ppProvCrlContext
  7316. );
  7317. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_FREE_FIND_CRL)(
  7318. IN HCERTSTOREPROV hStoreProv,
  7319. IN PCCRL_CONTEXT pCrlContext,
  7320. IN void *pvStoreProvFindInfo,
  7321. IN DWORD dwFlags
  7322. );
  7323. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_GET_CRL_PROPERTY)(
  7324. IN HCERTSTOREPROV hStoreProv,
  7325. IN PCCRL_CONTEXT pCrlContext,
  7326. IN DWORD dwPropId,
  7327. IN DWORD dwFlags,
  7328. OUT void *pvData,
  7329. IN OUT DWORD *pcbData
  7330. );
  7331. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_FIND_CTL)(
  7332. IN HCERTSTOREPROV hStoreProv,
  7333. IN PCCERT_STORE_PROV_FIND_INFO pFindInfo,
  7334. IN PCCTL_CONTEXT pPrevCtlContext,
  7335. IN DWORD dwFlags,
  7336. IN OUT void **ppvStoreProvFindInfo,
  7337. OUT PCCTL_CONTEXT *ppProvCtlContext
  7338. );
  7339. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_FREE_FIND_CTL)(
  7340. IN HCERTSTOREPROV hStoreProv,
  7341. IN PCCTL_CONTEXT pCtlContext,
  7342. IN void *pvStoreProvFindInfo,
  7343. IN DWORD dwFlags
  7344. );
  7345. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_GET_CTL_PROPERTY)(
  7346. IN HCERTSTOREPROV hStoreProv,
  7347. IN PCCTL_CONTEXT pCtlContext,
  7348. IN DWORD dwPropId,
  7349. IN DWORD dwFlags,
  7350. OUT void *pvData,
  7351. IN OUT DWORD *pcbData
  7352. );
  7353. //+-------------------------------------------------------------------------
  7354. // Duplicate a cert store handle
  7355. //--------------------------------------------------------------------------
  7356. WINCRYPT32API
  7357. HCERTSTORE
  7358. WINAPI
  7359. CertDuplicateStore(
  7360. IN HCERTSTORE hCertStore
  7361. );
  7362. #define CERT_STORE_SAVE_AS_STORE 1
  7363. #define CERT_STORE_SAVE_AS_PKCS7 2
  7364. #define CERT_STORE_SAVE_TO_FILE 1
  7365. #define CERT_STORE_SAVE_TO_MEMORY 2
  7366. #define CERT_STORE_SAVE_TO_FILENAME_A 3
  7367. #define CERT_STORE_SAVE_TO_FILENAME_W 4
  7368. #define CERT_STORE_SAVE_TO_FILENAME CERT_STORE_SAVE_TO_FILENAME_W
  7369. //+-------------------------------------------------------------------------
  7370. // Save the cert store. Extended version with lots of options.
  7371. //
  7372. // According to the dwSaveAs parameter, the store can be saved as a
  7373. // serialized store (CERT_STORE_SAVE_AS_STORE) containing properties in
  7374. // addition to encoded certificates, CRLs and CTLs or the store can be saved
  7375. // as a PKCS #7 signed message (CERT_STORE_SAVE_AS_PKCS7) which doesn't
  7376. // include the properties or CTLs.
  7377. //
  7378. // Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  7379. // CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't saved into
  7380. // a serialized store.
  7381. //
  7382. // For CERT_STORE_SAVE_AS_PKCS7, the dwEncodingType specifies the message
  7383. // encoding type. The dwEncodingType parameter isn't used for
  7384. // CERT_STORE_SAVE_AS_STORE.
  7385. //
  7386. // The dwFlags parameter currently isn't used and should be set to 0.
  7387. //
  7388. // The dwSaveTo and pvSaveToPara parameters specify where to save the
  7389. // store as follows:
  7390. // CERT_STORE_SAVE_TO_FILE:
  7391. // Saves to the specified file. The file's handle is passed in
  7392. // pvSaveToPara. Given,
  7393. // HANDLE hFile; pvSaveToPara = (void *) hFile;
  7394. //
  7395. // For a successful save, the file pointer is positioned after the
  7396. // last write.
  7397. //
  7398. // CERT_STORE_SAVE_TO_MEMORY:
  7399. // Saves to the specified memory blob. The pointer to
  7400. // the memory blob is passed in pvSaveToPara. Given,
  7401. // CRYPT_DATA_BLOB SaveBlob; pvSaveToPara = (void *) &SaveBlob;
  7402. // Upon entry, the SaveBlob's pbData and cbData need to be initialized.
  7403. // Upon return, cbData is updated with the actual length.
  7404. // For a length only calculation, pbData should be set to NULL. If
  7405. // pbData is non-NULL and cbData isn't large enough, FALSE is returned
  7406. // with a last error of ERRROR_MORE_DATA.
  7407. //
  7408. // CERT_STORE_SAVE_TO_FILENAME_A:
  7409. // CERT_STORE_SAVE_TO_FILENAME_W:
  7410. // CERT_STORE_SAVE_TO_FILENAME:
  7411. // Opens the file and saves to it. The filename is passed in pvSaveToPara.
  7412. // The filename is UNICODE for the "_W" option and ASCII for the "_A"
  7413. // option. For "_W": given,
  7414. // LPCWSTR pwszFilename; pvSaveToPara = (void *) pwszFilename;
  7415. // For "_A": given,
  7416. // LPCSTR pszFilename; pvSaveToPara = (void *) pszFilename;
  7417. //
  7418. // Note, the default (without "_A" or "_W") is UNICODE.
  7419. //
  7420. //--------------------------------------------------------------------------
  7421. WINCRYPT32API
  7422. BOOL
  7423. WINAPI
  7424. CertSaveStore(
  7425. IN HCERTSTORE hCertStore,
  7426. IN DWORD dwEncodingType,
  7427. IN DWORD dwSaveAs,
  7428. IN DWORD dwSaveTo,
  7429. IN OUT void *pvSaveToPara,
  7430. IN DWORD dwFlags
  7431. );
  7432. //+-------------------------------------------------------------------------
  7433. // Certificate Store close flags
  7434. //--------------------------------------------------------------------------
  7435. #define CERT_CLOSE_STORE_FORCE_FLAG 0x00000001
  7436. #define CERT_CLOSE_STORE_CHECK_FLAG 0x00000002
  7437. //+-------------------------------------------------------------------------
  7438. // Close a cert store handle.
  7439. //
  7440. // There needs to be a corresponding close for each open and duplicate.
  7441. //
  7442. // Even on the final close, the cert store isn't freed until all of its
  7443. // certificate and CRL contexts have also been freed.
  7444. //
  7445. // On the final close, the hCryptProv passed to CertStoreOpen is
  7446. // CryptReleaseContext'ed.
  7447. //
  7448. // To force the closure of the store with all of its memory freed, set the
  7449. // CERT_STORE_CLOSE_FORCE_FLAG. This flag should be set when the caller does
  7450. // its own reference counting and wants everything to vanish.
  7451. //
  7452. // To check if all the store's certificates and CRLs have been freed and that
  7453. // this is the last CertCloseStore, set the CERT_CLOSE_STORE_CHECK_FLAG. If
  7454. // set and certs, CRLs or stores still need to be freed/closed, FALSE is
  7455. // returned with LastError set to CRYPT_E_PENDING_CLOSE. Note, for FALSE,
  7456. // the store is still closed. This is a diagnostic flag.
  7457. //
  7458. // LastError is preserved unless CERT_CLOSE_STORE_CHECK_FLAG is set and FALSE
  7459. // is returned.
  7460. //--------------------------------------------------------------------------
  7461. WINCRYPT32API
  7462. BOOL
  7463. WINAPI
  7464. CertCloseStore(
  7465. IN HCERTSTORE hCertStore,
  7466. DWORD dwFlags
  7467. );
  7468. //+-------------------------------------------------------------------------
  7469. // Get the subject certificate context uniquely identified by its Issuer and
  7470. // SerialNumber from the store.
  7471. //
  7472. // If the certificate isn't found, NULL is returned. Otherwise, a pointer to
  7473. // a read only CERT_CONTEXT is returned. CERT_CONTEXT must be freed by calling
  7474. // CertFreeCertificateContext. CertDuplicateCertificateContext can be called to make a
  7475. // duplicate.
  7476. //
  7477. // The returned certificate might not be valid. Normally, it would be
  7478. // verified when getting its issuer certificate (CertGetIssuerCertificateFromStore).
  7479. //--------------------------------------------------------------------------
  7480. WINCRYPT32API
  7481. PCCERT_CONTEXT
  7482. WINAPI
  7483. CertGetSubjectCertificateFromStore(
  7484. IN HCERTSTORE hCertStore,
  7485. IN DWORD dwCertEncodingType,
  7486. IN PCERT_INFO pCertId // Only the Issuer and SerialNumber
  7487. // fields are used
  7488. );
  7489. //+-------------------------------------------------------------------------
  7490. // Enumerate the certificate contexts in the store.
  7491. //
  7492. // If a certificate isn't found, NULL is returned.
  7493. // Otherwise, a pointer to a read only CERT_CONTEXT is returned. CERT_CONTEXT
  7494. // must be freed by calling CertFreeCertificateContext or is freed when passed as the
  7495. // pPrevCertContext on a subsequent call. CertDuplicateCertificateContext
  7496. // can be called to make a duplicate.
  7497. //
  7498. // pPrevCertContext MUST BE NULL to enumerate the first
  7499. // certificate in the store. Successive certificates are enumerated by setting
  7500. // pPrevCertContext to the CERT_CONTEXT returned by a previous call.
  7501. //
  7502. // NOTE: a NON-NULL pPrevCertContext is always CertFreeCertificateContext'ed by
  7503. // this function, even for an error.
  7504. //--------------------------------------------------------------------------
  7505. WINCRYPT32API
  7506. PCCERT_CONTEXT
  7507. WINAPI
  7508. CertEnumCertificatesInStore(
  7509. IN HCERTSTORE hCertStore,
  7510. IN PCCERT_CONTEXT pPrevCertContext
  7511. );
  7512. //+-------------------------------------------------------------------------
  7513. // Find the first or next certificate context in the store.
  7514. //
  7515. // The certificate is found according to the dwFindType and its pvFindPara.
  7516. // See below for a list of the find types and its parameters.
  7517. //
  7518. // Currently dwFindFlags is only used for CERT_FIND_SUBJECT_ATTR,
  7519. // CERT_FIND_ISSUER_ATTR or CERT_FIND_CTL_USAGE. Otherwise, must be set to 0.
  7520. //
  7521. // Usage of dwCertEncodingType depends on the dwFindType.
  7522. //
  7523. // If the first or next certificate isn't found, NULL is returned.
  7524. // Otherwise, a pointer to a read only CERT_CONTEXT is returned. CERT_CONTEXT
  7525. // must be freed by calling CertFreeCertificateContext or is freed when passed as the
  7526. // pPrevCertContext on a subsequent call. CertDuplicateCertificateContext
  7527. // can be called to make a duplicate.
  7528. //
  7529. // pPrevCertContext MUST BE NULL on the first
  7530. // call to find the certificate. To find the next certificate, the
  7531. // pPrevCertContext is set to the CERT_CONTEXT returned by a previous call.
  7532. //
  7533. // NOTE: a NON-NULL pPrevCertContext is always CertFreeCertificateContext'ed by
  7534. // this function, even for an error.
  7535. //--------------------------------------------------------------------------
  7536. WINCRYPT32API
  7537. PCCERT_CONTEXT
  7538. WINAPI
  7539. CertFindCertificateInStore(
  7540. IN HCERTSTORE hCertStore,
  7541. IN DWORD dwCertEncodingType,
  7542. IN DWORD dwFindFlags,
  7543. IN DWORD dwFindType,
  7544. IN const void *pvFindPara,
  7545. IN PCCERT_CONTEXT pPrevCertContext
  7546. );
  7547. //+-------------------------------------------------------------------------
  7548. // Certificate comparison functions
  7549. //--------------------------------------------------------------------------
  7550. #define CERT_COMPARE_MASK 0xFFFF
  7551. #define CERT_COMPARE_SHIFT 16
  7552. #define CERT_COMPARE_ANY 0
  7553. #define CERT_COMPARE_SHA1_HASH 1
  7554. #define CERT_COMPARE_NAME 2
  7555. #define CERT_COMPARE_ATTR 3
  7556. #define CERT_COMPARE_MD5_HASH 4
  7557. #define CERT_COMPARE_PROPERTY 5
  7558. #define CERT_COMPARE_PUBLIC_KEY 6
  7559. #define CERT_COMPARE_HASH CERT_COMPARE_SHA1_HASH
  7560. #define CERT_COMPARE_NAME_STR_A 7
  7561. #define CERT_COMPARE_NAME_STR_W 8
  7562. #define CERT_COMPARE_KEY_SPEC 9
  7563. #define CERT_COMPARE_ENHKEY_USAGE 10
  7564. #define CERT_COMPARE_CTL_USAGE CERT_COMPARE_ENHKEY_USAGE
  7565. #define CERT_COMPARE_SUBJECT_CERT 11
  7566. #define CERT_COMPARE_ISSUER_OF 12
  7567. #define CERT_COMPARE_EXISTING 13
  7568. #define CERT_COMPARE_SIGNATURE_HASH 14
  7569. #define CERT_COMPARE_KEY_IDENTIFIER 15
  7570. #define CERT_COMPARE_CERT_ID 16
  7571. #define CERT_COMPARE_CROSS_CERT_DIST_POINTS 17
  7572. #define CERT_COMPARE_PUBKEY_MD5_HASH 18
  7573. //+-------------------------------------------------------------------------
  7574. // dwFindType
  7575. //
  7576. // The dwFindType definition consists of two components:
  7577. // - comparison function
  7578. // - certificate information flag
  7579. //--------------------------------------------------------------------------
  7580. #define CERT_FIND_ANY (CERT_COMPARE_ANY << CERT_COMPARE_SHIFT)
  7581. #define CERT_FIND_SHA1_HASH (CERT_COMPARE_SHA1_HASH << CERT_COMPARE_SHIFT)
  7582. #define CERT_FIND_MD5_HASH (CERT_COMPARE_MD5_HASH << CERT_COMPARE_SHIFT)
  7583. #define CERT_FIND_SIGNATURE_HASH (CERT_COMPARE_SIGNATURE_HASH << CERT_COMPARE_SHIFT)
  7584. #define CERT_FIND_KEY_IDENTIFIER (CERT_COMPARE_KEY_IDENTIFIER << CERT_COMPARE_SHIFT)
  7585. #define CERT_FIND_HASH CERT_FIND_SHA1_HASH
  7586. #define CERT_FIND_PROPERTY (CERT_COMPARE_PROPERTY << CERT_COMPARE_SHIFT)
  7587. #define CERT_FIND_PUBLIC_KEY (CERT_COMPARE_PUBLIC_KEY << CERT_COMPARE_SHIFT)
  7588. #define CERT_FIND_SUBJECT_NAME (CERT_COMPARE_NAME << CERT_COMPARE_SHIFT | \
  7589. CERT_INFO_SUBJECT_FLAG)
  7590. #define CERT_FIND_SUBJECT_ATTR (CERT_COMPARE_ATTR << CERT_COMPARE_SHIFT | \
  7591. CERT_INFO_SUBJECT_FLAG)
  7592. #define CERT_FIND_ISSUER_NAME (CERT_COMPARE_NAME << CERT_COMPARE_SHIFT | \
  7593. CERT_INFO_ISSUER_FLAG)
  7594. #define CERT_FIND_ISSUER_ATTR (CERT_COMPARE_ATTR << CERT_COMPARE_SHIFT | \
  7595. CERT_INFO_ISSUER_FLAG)
  7596. #define CERT_FIND_SUBJECT_STR_A (CERT_COMPARE_NAME_STR_A << CERT_COMPARE_SHIFT | \
  7597. CERT_INFO_SUBJECT_FLAG)
  7598. #define CERT_FIND_SUBJECT_STR_W (CERT_COMPARE_NAME_STR_W << CERT_COMPARE_SHIFT | \
  7599. CERT_INFO_SUBJECT_FLAG)
  7600. #define CERT_FIND_SUBJECT_STR CERT_FIND_SUBJECT_STR_W
  7601. #define CERT_FIND_ISSUER_STR_A (CERT_COMPARE_NAME_STR_A << CERT_COMPARE_SHIFT | \
  7602. CERT_INFO_ISSUER_FLAG)
  7603. #define CERT_FIND_ISSUER_STR_W (CERT_COMPARE_NAME_STR_W << CERT_COMPARE_SHIFT | \
  7604. CERT_INFO_ISSUER_FLAG)
  7605. #define CERT_FIND_ISSUER_STR CERT_FIND_ISSUER_STR_W
  7606. #define CERT_FIND_KEY_SPEC (CERT_COMPARE_KEY_SPEC << CERT_COMPARE_SHIFT)
  7607. #define CERT_FIND_ENHKEY_USAGE (CERT_COMPARE_ENHKEY_USAGE << CERT_COMPARE_SHIFT)
  7608. #define CERT_FIND_CTL_USAGE CERT_FIND_ENHKEY_USAGE
  7609. #define CERT_FIND_SUBJECT_CERT (CERT_COMPARE_SUBJECT_CERT << CERT_COMPARE_SHIFT)
  7610. #define CERT_FIND_ISSUER_OF (CERT_COMPARE_ISSUER_OF << CERT_COMPARE_SHIFT)
  7611. #define CERT_FIND_EXISTING (CERT_COMPARE_EXISTING << CERT_COMPARE_SHIFT)
  7612. #define CERT_FIND_CERT_ID (CERT_COMPARE_CERT_ID << CERT_COMPARE_SHIFT)
  7613. #define CERT_FIND_CROSS_CERT_DIST_POINTS \
  7614. (CERT_COMPARE_CROSS_CERT_DIST_POINTS << CERT_COMPARE_SHIFT)
  7615. #define CERT_FIND_PUBKEY_MD5_HASH \
  7616. (CERT_COMPARE_PUBKEY_MD5_HASH << CERT_COMPARE_SHIFT)
  7617. //+-------------------------------------------------------------------------
  7618. // CERT_FIND_ANY
  7619. //
  7620. // Find any certificate.
  7621. //
  7622. // pvFindPara isn't used.
  7623. //--------------------------------------------------------------------------
  7624. //+-------------------------------------------------------------------------
  7625. // CERT_FIND_HASH
  7626. //
  7627. // Find a certificate with the specified hash.
  7628. //
  7629. // pvFindPara points to a CRYPT_HASH_BLOB.
  7630. //--------------------------------------------------------------------------
  7631. //+-------------------------------------------------------------------------
  7632. // CERT_FIND_KEY_IDENTIFIER
  7633. //
  7634. // Find a certificate with the specified KeyIdentifier. Gets the
  7635. // CERT_KEY_IDENTIFIER_PROP_ID property and compares with the input
  7636. // CRYPT_HASH_BLOB.
  7637. //
  7638. // pvFindPara points to a CRYPT_HASH_BLOB.
  7639. //--------------------------------------------------------------------------
  7640. //+-------------------------------------------------------------------------
  7641. // CERT_FIND_PROPERTY
  7642. //
  7643. // Find a certificate having the specified property.
  7644. //
  7645. // pvFindPara points to a DWORD containing the PROP_ID
  7646. //--------------------------------------------------------------------------
  7647. //+-------------------------------------------------------------------------
  7648. // CERT_FIND_PUBLIC_KEY
  7649. //
  7650. // Find a certificate matching the specified public key.
  7651. //
  7652. // pvFindPara points to a CERT_PUBLIC_KEY_INFO containing the public key
  7653. //--------------------------------------------------------------------------
  7654. //+-------------------------------------------------------------------------
  7655. // CERT_FIND_SUBJECT_NAME
  7656. // CERT_FIND_ISSUER_NAME
  7657. //
  7658. // Find a certificate with the specified subject/issuer name. Does an exact
  7659. // match of the entire name.
  7660. //
  7661. // Restricts search to certificates matching the dwCertEncodingType.
  7662. //
  7663. // pvFindPara points to a CERT_NAME_BLOB.
  7664. //--------------------------------------------------------------------------
  7665. //+-------------------------------------------------------------------------
  7666. // CERT_FIND_SUBJECT_ATTR
  7667. // CERT_FIND_ISSUER_ATTR
  7668. //
  7669. // Find a certificate with the specified subject/issuer attributes.
  7670. //
  7671. // Compares the attributes in the subject/issuer name with the
  7672. // Relative Distinguished Name's (CERT_RDN) array of attributes specified in
  7673. // pvFindPara. The comparison iterates through the CERT_RDN attributes and looks
  7674. // for an attribute match in any of the subject/issuer's RDNs.
  7675. //
  7676. // The CERT_RDN_ATTR fields can have the following special values:
  7677. // pszObjId == NULL - ignore the attribute object identifier
  7678. // dwValueType == RDN_ANY_TYPE - ignore the value type
  7679. // Value.pbData == NULL - match any value
  7680. //
  7681. // CERT_CASE_INSENSITIVE_IS_RDN_ATTRS_FLAG should be set in dwFindFlags to do
  7682. // a case insensitive match. Otherwise, defaults to an exact, case sensitive
  7683. // match.
  7684. //
  7685. // CERT_UNICODE_IS_RDN_ATTRS_FLAG should be set in dwFindFlags if the RDN was
  7686. // initialized with unicode strings as for
  7687. // CryptEncodeObject(X509_UNICODE_NAME).
  7688. //
  7689. // Restricts search to certificates matching the dwCertEncodingType.
  7690. //
  7691. // pvFindPara points to a CERT_RDN (defined in wincert.h).
  7692. //--------------------------------------------------------------------------
  7693. //+-------------------------------------------------------------------------
  7694. // CERT_FIND_SUBJECT_STR_A
  7695. // CERT_FIND_SUBJECT_STR_W | CERT_FIND_SUBJECT_STR
  7696. // CERT_FIND_ISSUER_STR_A
  7697. // CERT_FIND_ISSUER_STR_W | CERT_FIND_ISSUER_STR
  7698. //
  7699. // Find a certificate containing the specified subject/issuer name string.
  7700. //
  7701. // First, the certificate's subject/issuer is converted to a name string
  7702. // via CertNameToStrA/CertNameToStrW(CERT_SIMPLE_NAME_STR). Then, a
  7703. // case insensitive substring within string match is performed.
  7704. //
  7705. // Restricts search to certificates matching the dwCertEncodingType.
  7706. //
  7707. // For *_STR_A, pvFindPara points to a null terminated character string.
  7708. // For *_STR_W, pvFindPara points to a null terminated wide character string.
  7709. //--------------------------------------------------------------------------
  7710. //+-------------------------------------------------------------------------
  7711. // CERT_FIND_KEY_SPEC
  7712. //
  7713. // Find a certificate having a CERT_KEY_SPEC_PROP_ID property matching
  7714. // the specified KeySpec.
  7715. //
  7716. // pvFindPara points to a DWORD containing the KeySpec.
  7717. //--------------------------------------------------------------------------
  7718. //+-------------------------------------------------------------------------
  7719. // CERT_FIND_ENHKEY_USAGE
  7720. //
  7721. // Find a certificate having the szOID_ENHANCED_KEY_USAGE extension or
  7722. // the CERT_ENHKEY_USAGE_PROP_ID and matching the specified pszUsageIdentifers.
  7723. //
  7724. // pvFindPara points to a CERT_ENHKEY_USAGE data structure. If pvFindPara
  7725. // is NULL or CERT_ENHKEY_USAGE's cUsageIdentifier is 0, then, matches any
  7726. // certificate having enhanced key usage.
  7727. //
  7728. // If the CERT_FIND_VALID_ENHKEY_USAGE_FLAG is set, then, only does a match
  7729. // for certificates that are valid for the specified usages. By default,
  7730. // the ceriticate must be valid for all usages. CERT_FIND_OR_ENHKEY_USAGE_FLAG
  7731. // can be set, if the certificate only needs to be valid for one of the
  7732. // specified usages. Note, CertGetValidUsages() is called to get the
  7733. // certificate's list of valid usages. Only the CERT_FIND_OR_ENHKEY_USAGE_FLAG
  7734. // is applicable when this flag is set.
  7735. //
  7736. // The CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG can be set in dwFindFlags to
  7737. // also match a certificate without either the extension or property.
  7738. //
  7739. // If CERT_FIND_NO_ENHKEY_USAGE_FLAG is set in dwFindFlags, finds
  7740. // certificates without the key usage extension or property. Setting this
  7741. // flag takes precedence over pvFindPara being NULL.
  7742. //
  7743. // If the CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG is set, then, only does a match
  7744. // using the extension. If pvFindPara is NULL or cUsageIdentifier is set to
  7745. // 0, finds certificates having the extension. If
  7746. // CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG is set, also matches a certificate
  7747. // without the extension. If CERT_FIND_NO_ENHKEY_USAGE_FLAG is set, finds
  7748. // certificates without the extension.
  7749. //
  7750. // If the CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG is set, then, only does a match
  7751. // using the property. If pvFindPara is NULL or cUsageIdentifier is set to
  7752. // 0, finds certificates having the property. If
  7753. // CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG is set, also matches a certificate
  7754. // without the property. If CERT_FIND_NO_ENHKEY_USAGE_FLAG is set, finds
  7755. // certificates without the property.
  7756. //
  7757. // If CERT_FIND_OR_ENHKEY_USAGE_FLAG is set, does an "OR" match of any of
  7758. // the specified pszUsageIdentifiers. If not set, then, does an "AND" match
  7759. // of all of the specified pszUsageIdentifiers.
  7760. //--------------------------------------------------------------------------
  7761. #define CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG 0x1
  7762. #define CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG 0x2
  7763. #define CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG 0x4
  7764. #define CERT_FIND_NO_ENHKEY_USAGE_FLAG 0x8
  7765. #define CERT_FIND_OR_ENHKEY_USAGE_FLAG 0x10
  7766. #define CERT_FIND_VALID_ENHKEY_USAGE_FLAG 0x20
  7767. #define CERT_FIND_OPTIONAL_CTL_USAGE_FLAG CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG
  7768. #define CERT_FIND_EXT_ONLY_CTL_USAGE_FLAG \
  7769. CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG
  7770. #define CERT_FIND_PROP_ONLY_CTL_USAGE_FLAG \
  7771. CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG
  7772. #define CERT_FIND_NO_CTL_USAGE_FLAG CERT_FIND_NO_ENHKEY_USAGE_FLAG
  7773. #define CERT_FIND_OR_CTL_USAGE_FLAG CERT_FIND_OR_ENHKEY_USAGE_FLAG
  7774. #define CERT_FIND_VALID_CTL_USAGE_FLAG CERT_FIND_VALID_ENHKEY_USAGE_FLAG
  7775. //+-------------------------------------------------------------------------
  7776. // CERT_FIND_CERT_ID
  7777. //
  7778. // Find a certificate with the specified CERT_ID.
  7779. //
  7780. // pvFindPara points to a CERT_ID.
  7781. //--------------------------------------------------------------------------
  7782. //+-------------------------------------------------------------------------
  7783. // CERT_FIND_CROSS_CERT_DIST_POINTS
  7784. //
  7785. // Find a certificate having either a cross certificate distribution
  7786. // point extension or property.
  7787. //
  7788. // pvFindPara isn't used.
  7789. //--------------------------------------------------------------------------
  7790. //+-------------------------------------------------------------------------
  7791. // Get the certificate context from the store for the first or next issuer
  7792. // of the specified subject certificate. Perform the enabled
  7793. // verification checks on the subject. (Note, the checks are on the subject
  7794. // using the returned issuer certificate.)
  7795. //
  7796. // If the first or next issuer certificate isn't found, NULL is returned.
  7797. // Otherwise, a pointer to a read only CERT_CONTEXT is returned. CERT_CONTEXT
  7798. // must be freed by calling CertFreeCertificateContext or is freed when passed as the
  7799. // pPrevIssuerContext on a subsequent call. CertDuplicateCertificateContext
  7800. // can be called to make a duplicate.
  7801. //
  7802. // For a self signed subject certificate, NULL is returned with LastError set
  7803. // to CERT_STORE_SELF_SIGNED. The enabled verification checks are still done.
  7804. //
  7805. // The pSubjectContext may have been obtained from this store, another store
  7806. // or created by the caller application. When created by the caller, the
  7807. // CertCreateCertificateContext function must have been called.
  7808. //
  7809. // An issuer may have multiple certificates. This may occur when the validity
  7810. // period is about to change. pPrevIssuerContext MUST BE NULL on the first
  7811. // call to get the issuer. To get the next certificate for the issuer, the
  7812. // pPrevIssuerContext is set to the CERT_CONTEXT returned by a previous call.
  7813. //
  7814. // NOTE: a NON-NULL pPrevIssuerContext is always CertFreeCertificateContext'ed by
  7815. // this function, even for an error.
  7816. //
  7817. // The following flags can be set in *pdwFlags to enable verification checks
  7818. // on the subject certificate context:
  7819. // CERT_STORE_SIGNATURE_FLAG - use the public key in the returned
  7820. // issuer certificate to verify the
  7821. // signature on the subject certificate.
  7822. // Note, if pSubjectContext->hCertStore ==
  7823. // hCertStore, the store provider might
  7824. // be able to eliminate a redo of
  7825. // the signature verify.
  7826. // CERT_STORE_TIME_VALIDITY_FLAG - get the current time and verify that
  7827. // its within the subject certificate's
  7828. // validity period
  7829. // CERT_STORE_REVOCATION_FLAG - check if the subject certificate is on
  7830. // the issuer's revocation list
  7831. //
  7832. // If an enabled verification check fails, then, its flag is set upon return.
  7833. // If CERT_STORE_REVOCATION_FLAG was enabled and the issuer doesn't have a
  7834. // CRL in the store, then, CERT_STORE_NO_CRL_FLAG is set in addition to
  7835. // the CERT_STORE_REVOCATION_FLAG.
  7836. //
  7837. // If CERT_STORE_SIGNATURE_FLAG or CERT_STORE_REVOCATION_FLAG is set, then,
  7838. // CERT_STORE_NO_ISSUER_FLAG is set if it doesn't have an issuer certificate
  7839. // in the store.
  7840. //
  7841. // For a verification check failure, a pointer to the issuer's CERT_CONTEXT
  7842. // is still returned and SetLastError isn't updated.
  7843. //--------------------------------------------------------------------------
  7844. WINCRYPT32API
  7845. PCCERT_CONTEXT
  7846. WINAPI
  7847. CertGetIssuerCertificateFromStore(
  7848. IN HCERTSTORE hCertStore,
  7849. IN PCCERT_CONTEXT pSubjectContext,
  7850. IN OPTIONAL PCCERT_CONTEXT pPrevIssuerContext,
  7851. IN OUT DWORD *pdwFlags
  7852. );
  7853. //+-------------------------------------------------------------------------
  7854. // Perform the enabled verification checks on the subject certificate
  7855. // using the issuer. Same checks and flags definitions as for the above
  7856. // CertGetIssuerCertificateFromStore.
  7857. //
  7858. // If you are only checking CERT_STORE_TIME_VALIDITY_FLAG, then, the
  7859. // issuer can be NULL.
  7860. //
  7861. // For a verification check failure, SUCCESS is still returned.
  7862. //--------------------------------------------------------------------------
  7863. WINCRYPT32API
  7864. BOOL
  7865. WINAPI
  7866. CertVerifySubjectCertificateContext(
  7867. IN PCCERT_CONTEXT pSubject,
  7868. IN OPTIONAL PCCERT_CONTEXT pIssuer,
  7869. IN OUT DWORD *pdwFlags
  7870. );
  7871. //+-------------------------------------------------------------------------
  7872. // Duplicate a certificate context
  7873. //--------------------------------------------------------------------------
  7874. WINCRYPT32API
  7875. PCCERT_CONTEXT
  7876. WINAPI
  7877. CertDuplicateCertificateContext(
  7878. IN PCCERT_CONTEXT pCertContext
  7879. );
  7880. //+-------------------------------------------------------------------------
  7881. // Create a certificate context from the encoded certificate. The created
  7882. // context isn't put in a store.
  7883. //
  7884. // Makes a copy of the encoded certificate in the created context.
  7885. //
  7886. // If unable to decode and create the certificate context, NULL is returned.
  7887. // Otherwise, a pointer to a read only CERT_CONTEXT is returned.
  7888. // CERT_CONTEXT must be freed by calling CertFreeCertificateContext.
  7889. // CertDuplicateCertificateContext can be called to make a duplicate.
  7890. //
  7891. // CertSetCertificateContextProperty and CertGetCertificateContextProperty can be called
  7892. // to store properties for the certificate.
  7893. //--------------------------------------------------------------------------
  7894. WINCRYPT32API
  7895. PCCERT_CONTEXT
  7896. WINAPI
  7897. CertCreateCertificateContext(
  7898. IN DWORD dwCertEncodingType,
  7899. IN const BYTE *pbCertEncoded,
  7900. IN DWORD cbCertEncoded
  7901. );
  7902. //+-------------------------------------------------------------------------
  7903. // Free a certificate context
  7904. //
  7905. // There needs to be a corresponding free for each context obtained by a
  7906. // get, find, duplicate or create.
  7907. //--------------------------------------------------------------------------
  7908. WINCRYPT32API
  7909. BOOL
  7910. WINAPI
  7911. CertFreeCertificateContext(
  7912. IN PCCERT_CONTEXT pCertContext
  7913. );
  7914. //+-------------------------------------------------------------------------
  7915. // Set the property for the specified certificate context.
  7916. //
  7917. // The type definition for pvData depends on the dwPropId value. There are
  7918. // five predefined types:
  7919. // CERT_KEY_PROV_HANDLE_PROP_ID - a HCRYPTPROV for the certificate's
  7920. // private key is passed in pvData. Updates the hCryptProv field
  7921. // of the CERT_KEY_CONTEXT_PROP_ID. If the CERT_KEY_CONTEXT_PROP_ID
  7922. // doesn't exist, its created with all the other fields zeroed out. If
  7923. // CERT_STORE_NO_CRYPT_RELEASE_FLAG isn't set, HCRYPTPROV is implicitly
  7924. // released when either the property is set to NULL or on the final
  7925. // free of the CertContext.
  7926. //
  7927. // CERT_KEY_PROV_INFO_PROP_ID - a PCRYPT_KEY_PROV_INFO for the certificate's
  7928. // private key is passed in pvData.
  7929. //
  7930. // CERT_SHA1_HASH_PROP_ID -
  7931. // CERT_MD5_HASH_PROP_ID -
  7932. // CERT_SIGNATURE_HASH_PROP_ID - normally, a hash property is implicitly
  7933. // set by doing a CertGetCertificateContextProperty. pvData points to a
  7934. // CRYPT_HASH_BLOB.
  7935. //
  7936. // CERT_KEY_CONTEXT_PROP_ID - a PCERT_KEY_CONTEXT for the certificate's
  7937. // private key is passed in pvData. The CERT_KEY_CONTEXT contains both the
  7938. // hCryptProv and dwKeySpec for the private key.
  7939. // See the CERT_KEY_PROV_HANDLE_PROP_ID for more information about
  7940. // the hCryptProv field and dwFlags settings. Note, more fields may
  7941. // be added for this property. The cbSize field value will be adjusted
  7942. // accordingly.
  7943. //
  7944. // CERT_KEY_SPEC_PROP_ID - the dwKeySpec for the private key. pvData
  7945. // points to a DWORD containing the KeySpec
  7946. //
  7947. // CERT_ENHKEY_USAGE_PROP_ID - enhanced key usage definition for the
  7948. // certificate. pvData points to a CRYPT_DATA_BLOB containing an
  7949. // ASN.1 encoded CERT_ENHKEY_USAGE (encoded via
  7950. // CryptEncodeObject(X509_ENHANCED_KEY_USAGE).
  7951. //
  7952. // CERT_NEXT_UPDATE_LOCATION_PROP_ID - location of the next update.
  7953. // Currently only applicable to CTLs. pvData points to a CRYPT_DATA_BLOB
  7954. // containing an ASN.1 encoded CERT_ALT_NAME_INFO (encoded via
  7955. // CryptEncodeObject(X509_ALTERNATE_NAME)).
  7956. //
  7957. // CERT_FRIENDLY_NAME_PROP_ID - friendly name for the cert, CRL or CTL.
  7958. // pvData points to a CRYPT_DATA_BLOB. pbData is a pointer to a NULL
  7959. // terminated unicode, wide character string.
  7960. // cbData = (wcslen((LPWSTR) pbData) + 1) * sizeof(WCHAR).
  7961. //
  7962. // CERT_DESCRIPTION_PROP_ID - description for the cert, CRL or CTL.
  7963. // pvData points to a CRYPT_DATA_BLOB. pbData is a pointer to a NULL
  7964. // terminated unicode, wide character string.
  7965. // cbData = (wcslen((LPWSTR) pbData) + 1) * sizeof(WCHAR).
  7966. //
  7967. // CERT_ARCHIVED_PROP_ID - when this property is set, the certificate
  7968. // is skipped during enumeration. Note, certificates having this property
  7969. // are still found for explicit finds, such as, finding a certificate
  7970. // with a specific hash or finding a certificate having a specific issuer
  7971. // and serial number. pvData points to a CRYPT_DATA_BLOB. This blob
  7972. // can be NULL (pbData = NULL, cbData = 0).
  7973. //
  7974. // CERT_PUBKEY_ALG_PARA_PROP_ID - for public keys supporting
  7975. // algorithm parameter inheritance. pvData points to a CRYPT_OBJID_BLOB
  7976. // containing the ASN.1 encoded PublicKey Algorithm Parameters. For
  7977. // DSS this would be the parameters encoded via
  7978. // CryptEncodeObject(X509_DSS_PARAMETERS). This property may be set
  7979. // by CryptVerifyCertificateSignatureEx().
  7980. //
  7981. // CERT_CROSS_CERT_DIST_POINTS_PROP_ID - location of the cross certs.
  7982. // Currently only applicable to certs. pvData points to a CRYPT_DATA_BLOB
  7983. // containing an ASN.1 encoded CROSS_CERT_DIST_POINTS_INFO (encoded via
  7984. // CryptEncodeObject(X509_CROSS_CERT_DIST_POINTS)).
  7985. //
  7986. // CERT_ENROLLMENT_PROP_ID - enrollment information of the pending request.
  7987. // It contains RequestID, CADNSName, CAName, and FriendlyName.
  7988. // The data format is defined as, the first 4 bytes - pending request ID,
  7989. // next 4 bytes - CADNSName size in characters including null-terminator
  7990. // followed by CADNSName string with null-terminator,
  7991. // next 4 bytes - CAName size in characters including null-terminator
  7992. // followed by CAName string with null-terminator,
  7993. // next 4 bytes - FriendlyName size in characters including null-terminator
  7994. // followed by FriendlyName string with null-terminator.
  7995. //
  7996. // CERT_DATE_STAMP_PROP_ID - contains the time when added to the store
  7997. // by an admin tool. pvData points to a CRYPT_DATA_BLOB containing
  7998. // the FILETIME.
  7999. //
  8000. // CERT_RENEWAL_PROP_ID - contains the hash of renewed certificate
  8001. //
  8002. // For all the other PROP_IDs: an encoded PCRYPT_DATA_BLOB is passed in pvData.
  8003. //
  8004. // If the property already exists, then, the old value is deleted and silently
  8005. // replaced. Setting, pvData to NULL, deletes the property.
  8006. //
  8007. // CERT_SET_PROPERTY_IGNORE_PERSIST_ERROR_FLAG can be set to ignore any
  8008. // provider write errors and always update the cached context's property.
  8009. //--------------------------------------------------------------------------
  8010. WINCRYPT32API
  8011. BOOL
  8012. WINAPI
  8013. CertSetCertificateContextProperty(
  8014. IN PCCERT_CONTEXT pCertContext,
  8015. IN DWORD dwPropId,
  8016. IN DWORD dwFlags,
  8017. IN const void *pvData
  8018. );
  8019. // Set this flag to ignore any store provider write errors and always update
  8020. // the cached context's property
  8021. #define CERT_SET_PROPERTY_IGNORE_PERSIST_ERROR_FLAG 0x80000000
  8022. // Set this flag to inhibit the persisting of this property
  8023. #define CERT_SET_PROPERTY_INHIBIT_PERSIST_FLAG 0x40000000
  8024. //+-------------------------------------------------------------------------
  8025. // Get the property for the specified certificate context.
  8026. //
  8027. // For CERT_KEY_PROV_HANDLE_PROP_ID, pvData points to a HCRYPTPROV.
  8028. //
  8029. // For CERT_KEY_PROV_INFO_PROP_ID, pvData points to a CRYPT_KEY_PROV_INFO structure.
  8030. // Elements pointed to by fields in the pvData structure follow the
  8031. // structure. Therefore, *pcbData may exceed the size of the structure.
  8032. //
  8033. // For CERT_KEY_CONTEXT_PROP_ID, pvData points to a CERT_KEY_CONTEXT structure.
  8034. //
  8035. // For CERT_KEY_SPEC_PROP_ID, pvData points to a DWORD containing the KeySpec.
  8036. // If the CERT_KEY_CONTEXT_PROP_ID exists, the KeySpec is obtained from there.
  8037. // Otherwise, if the CERT_KEY_PROV_INFO_PROP_ID exists, its the source
  8038. // of the KeySpec.
  8039. //
  8040. // For CERT_SHA1_HASH_PROP_ID or CERT_MD5_HASH_PROP_ID, if the hash
  8041. // doesn't already exist, then, its computed via CryptHashCertificate()
  8042. // and then set. pvData points to the computed hash. Normally, the length
  8043. // is 20 bytes for SHA and 16 for MD5.
  8044. //
  8045. // For CERT_SIGNATURE_HASH_PROP_ID, if the hash
  8046. // doesn't already exist, then, its computed via CryptHashToBeSigned()
  8047. // and then set. pvData points to the computed hash. Normally, the length
  8048. // is 20 bytes for SHA and 16 for MD5.
  8049. //
  8050. // For CERT_ACCESS_STATE_PROP_ID, pvData points to a DWORD containing the
  8051. // access state flags. The appropriate CERT_ACCESS_STATE_*_FLAG's are set
  8052. // in the returned DWORD. See the CERT_ACCESS_STATE_*_FLAG definitions
  8053. // above. Note, this property is read only. It can't be set.
  8054. //
  8055. // For CERT_KEY_IDENTIFIER_PROP_ID, if property doesn't already exist,
  8056. // first searches for the szOID_SUBJECT_KEY_IDENTIFIER extension. Next,
  8057. // does SHA1 hash of the certficate's SubjectPublicKeyInfo. pvData
  8058. // points to the key identifier bytes. Normally, the length is 20 bytes.
  8059. //
  8060. // For CERT_PUBKEY_ALG_PARA_PROP_ID, pvPara points to the ASN.1 encoded
  8061. // PublicKey Algorithm Parameters. This property will only be set
  8062. // for public keys supporting algorithm parameter inheritance and when the
  8063. // parameters have been omitted from the encoded and signed certificate.
  8064. //
  8065. // For CERT_DATE_STAMP_PROP_ID, pvPara points to a FILETIME updated by
  8066. // an admin tool to indicate when the certificate was added to the store.
  8067. //
  8068. // For all other PROP_IDs, pvData points to an encoded array of bytes.
  8069. //--------------------------------------------------------------------------
  8070. WINCRYPT32API
  8071. BOOL
  8072. WINAPI
  8073. CertGetCertificateContextProperty(
  8074. IN PCCERT_CONTEXT pCertContext,
  8075. IN DWORD dwPropId,
  8076. OUT void *pvData,
  8077. IN OUT DWORD *pcbData
  8078. );
  8079. //+-------------------------------------------------------------------------
  8080. // Enumerate the properties for the specified certificate context.
  8081. //
  8082. // To get the first property, set dwPropId to 0. The ID of the first
  8083. // property is returned. To get the next property, set dwPropId to the
  8084. // ID returned by the last call. To enumerate all the properties continue
  8085. // until 0 is returned.
  8086. //
  8087. // CertGetCertificateContextProperty is called to get the property's data.
  8088. //
  8089. // Note, since, the CERT_KEY_PROV_HANDLE_PROP_ID and CERT_KEY_SPEC_PROP_ID
  8090. // properties are stored as fields in the CERT_KEY_CONTEXT_PROP_ID
  8091. // property, they aren't enumerated individually.
  8092. //--------------------------------------------------------------------------
  8093. WINCRYPT32API
  8094. DWORD
  8095. WINAPI
  8096. CertEnumCertificateContextProperties(
  8097. IN PCCERT_CONTEXT pCertContext,
  8098. IN DWORD dwPropId
  8099. );
  8100. //+-------------------------------------------------------------------------
  8101. // Creates a CTL entry whose attributes are the certificate context's
  8102. // properties.
  8103. //
  8104. // The SubjectIdentifier in the CTL entry is the SHA1 hash of the certificate.
  8105. //
  8106. // The certificate properties are added as attributes. The property attribute
  8107. // OID is the decimal PROP_ID preceded by szOID_CERT_PROP_ID_PREFIX. Each
  8108. // property value is copied as a single attribute value.
  8109. //
  8110. // Any additional attributes to be included in the CTL entry can be passed
  8111. // in via the cOptAttr and rgOptAttr parameters.
  8112. //
  8113. // CTL_ENTRY_FROM_PROP_CHAIN_FLAG can be set in dwFlags, to force the
  8114. // inclusion of the chain building hash properties as attributes.
  8115. //--------------------------------------------------------------------------
  8116. WINCRYPT32API
  8117. BOOL
  8118. WINAPI
  8119. CertCreateCTLEntryFromCertificateContextProperties(
  8120. IN PCCERT_CONTEXT pCertContext,
  8121. IN DWORD cOptAttr,
  8122. IN OPTIONAL PCRYPT_ATTRIBUTE rgOptAttr,
  8123. IN DWORD dwFlags,
  8124. IN OPTIONAL void *pvReserved,
  8125. OUT OPTIONAL PCTL_ENTRY pCtlEntry,
  8126. IN OUT DWORD *pcbCtlEntry
  8127. );
  8128. // Set this flag to get and include the chain building hash properties
  8129. // as attributes in the CTL entry
  8130. #define CTL_ENTRY_FROM_PROP_CHAIN_FLAG 0x1
  8131. //+-------------------------------------------------------------------------
  8132. // Sets properties on the certificate context using the attributes in
  8133. // the CTL entry.
  8134. //
  8135. // The property attribute OID is the decimal PROP_ID preceded by
  8136. // szOID_CERT_PROP_ID_PREFIX. Only attributes containing such an OID are
  8137. // copied.
  8138. //
  8139. // CERT_SET_PROPERTY_IGNORE_PERSIST_ERROR_FLAG may be set in dwFlags.
  8140. //--------------------------------------------------------------------------
  8141. WINCRYPT32API
  8142. BOOL
  8143. WINAPI
  8144. CertSetCertificateContextPropertiesFromCTLEntry(
  8145. IN PCCERT_CONTEXT pCertContext,
  8146. IN PCTL_ENTRY pCtlEntry,
  8147. IN DWORD dwFlags
  8148. );
  8149. //+-------------------------------------------------------------------------
  8150. // Get the first or next CRL context from the store for the specified
  8151. // issuer certificate. Perform the enabled verification checks on the CRL.
  8152. //
  8153. // If the first or next CRL isn't found, NULL is returned.
  8154. // Otherwise, a pointer to a read only CRL_CONTEXT is returned. CRL_CONTEXT
  8155. // must be freed by calling CertFreeCRLContext. However, the free must be
  8156. // pPrevCrlContext on a subsequent call. CertDuplicateCRLContext
  8157. // can be called to make a duplicate.
  8158. //
  8159. // The pIssuerContext may have been obtained from this store, another store
  8160. // or created by the caller application. When created by the caller, the
  8161. // CertCreateCertificateContext function must have been called.
  8162. //
  8163. // If pIssuerContext == NULL, finds all the CRLs in the store.
  8164. //
  8165. // An issuer may have multiple CRLs. For example, it generates delta CRLs
  8166. // using a X.509 v3 extension. pPrevCrlContext MUST BE NULL on the first
  8167. // call to get the CRL. To get the next CRL for the issuer, the
  8168. // pPrevCrlContext is set to the CRL_CONTEXT returned by a previous call.
  8169. //
  8170. // NOTE: a NON-NULL pPrevCrlContext is always CertFreeCRLContext'ed by
  8171. // this function, even for an error.
  8172. //
  8173. // The following flags can be set in *pdwFlags to enable verification checks
  8174. // on the returned CRL:
  8175. // CERT_STORE_SIGNATURE_FLAG - use the public key in the
  8176. // issuer's certificate to verify the
  8177. // signature on the returned CRL.
  8178. // Note, if pIssuerContext->hCertStore ==
  8179. // hCertStore, the store provider might
  8180. // be able to eliminate a redo of
  8181. // the signature verify.
  8182. // CERT_STORE_TIME_VALIDITY_FLAG - get the current time and verify that
  8183. // its within the CRL's ThisUpdate and
  8184. // NextUpdate validity period.
  8185. // CERT_STORE_BASE_CRL_FLAG - get base CRL.
  8186. // CERT_STORE_DELTA_CRL_FLAG - get delta CRL.
  8187. //
  8188. // If only one of CERT_STORE_BASE_CRL_FLAG or CERT_STORE_DELTA_CRL_FLAG is
  8189. // set, then, only returns either a base or delta CRL. In any case, the
  8190. // appropriate base or delta flag will be cleared upon returned. If both
  8191. // flags are set, then, only one of flags will be cleared.
  8192. //
  8193. // If an enabled verification check fails, then, its flag is set upon return.
  8194. //
  8195. // If pIssuerContext == NULL, then, an enabled CERT_STORE_SIGNATURE_FLAG
  8196. // always fails and the CERT_STORE_NO_ISSUER_FLAG is also set.
  8197. //
  8198. // For a verification check failure, a pointer to the first or next
  8199. // CRL_CONTEXT is still returned and SetLastError isn't updated.
  8200. //--------------------------------------------------------------------------
  8201. WINCRYPT32API
  8202. PCCRL_CONTEXT
  8203. WINAPI
  8204. CertGetCRLFromStore(
  8205. IN HCERTSTORE hCertStore,
  8206. IN OPTIONAL PCCERT_CONTEXT pIssuerContext,
  8207. IN PCCRL_CONTEXT pPrevCrlContext,
  8208. IN OUT DWORD *pdwFlags
  8209. );
  8210. //+-------------------------------------------------------------------------
  8211. // Enumerate the CRL contexts in the store.
  8212. //
  8213. // If a CRL isn't found, NULL is returned.
  8214. // Otherwise, a pointer to a read only CRL_CONTEXT is returned. CRL_CONTEXT
  8215. // must be freed by calling CertFreeCRLContext or is freed when passed as the
  8216. // pPrevCrlContext on a subsequent call. CertDuplicateCRLContext
  8217. // can be called to make a duplicate.
  8218. //
  8219. // pPrevCrlContext MUST BE NULL to enumerate the first
  8220. // CRL in the store. Successive CRLs are enumerated by setting
  8221. // pPrevCrlContext to the CRL_CONTEXT returned by a previous call.
  8222. //
  8223. // NOTE: a NON-NULL pPrevCrlContext is always CertFreeCRLContext'ed by
  8224. // this function, even for an error.
  8225. //--------------------------------------------------------------------------
  8226. WINCRYPT32API
  8227. PCCRL_CONTEXT
  8228. WINAPI
  8229. CertEnumCRLsInStore(
  8230. IN HCERTSTORE hCertStore,
  8231. IN PCCRL_CONTEXT pPrevCrlContext
  8232. );
  8233. //+-------------------------------------------------------------------------
  8234. // Find the first or next CRL context in the store.
  8235. //
  8236. // The CRL is found according to the dwFindType and its pvFindPara.
  8237. // See below for a list of the find types and its parameters.
  8238. //
  8239. // Currently dwFindFlags isn't used and must be set to 0.
  8240. //
  8241. // Usage of dwCertEncodingType depends on the dwFindType.
  8242. //
  8243. // If the first or next CRL isn't found, NULL is returned.
  8244. // Otherwise, a pointer to a read only CRL_CONTEXT is returned. CRL_CONTEXT
  8245. // must be freed by calling CertFreeCRLContext or is freed when passed as the
  8246. // pPrevCrlContext on a subsequent call. CertDuplicateCRLContext
  8247. // can be called to make a duplicate.
  8248. //
  8249. // pPrevCrlContext MUST BE NULL on the first
  8250. // call to find the CRL. To find the next CRL, the
  8251. // pPrevCrlContext is set to the CRL_CONTEXT returned by a previous call.
  8252. //
  8253. // NOTE: a NON-NULL pPrevCrlContext is always CertFreeCRLContext'ed by
  8254. // this function, even for an error.
  8255. //--------------------------------------------------------------------------
  8256. WINCRYPT32API
  8257. PCCRL_CONTEXT
  8258. WINAPI
  8259. CertFindCRLInStore(
  8260. IN HCERTSTORE hCertStore,
  8261. IN DWORD dwCertEncodingType,
  8262. IN DWORD dwFindFlags,
  8263. IN DWORD dwFindType,
  8264. IN const void *pvFindPara,
  8265. IN PCCRL_CONTEXT pPrevCrlContext
  8266. );
  8267. #define CRL_FIND_ANY 0
  8268. #define CRL_FIND_ISSUED_BY 1
  8269. #define CRL_FIND_EXISTING 2
  8270. #define CRL_FIND_ISSUED_FOR 3
  8271. //+-------------------------------------------------------------------------
  8272. // CRL_FIND_ANY
  8273. //
  8274. // Find any CRL.
  8275. //
  8276. // pvFindPara isn't used.
  8277. //--------------------------------------------------------------------------
  8278. //+-------------------------------------------------------------------------
  8279. // CRL_FIND_ISSUED_BY
  8280. //
  8281. // Find CRL matching the specified issuer.
  8282. //
  8283. // pvFindPara is the PCCERT_CONTEXT of the CRL issuer. May be NULL to
  8284. // match any issuer.
  8285. //
  8286. // By default, only does issuer name matching. The following flags can be
  8287. // set in dwFindFlags to do additional filtering.
  8288. //
  8289. // If CRL_FIND_ISSUED_BY_AKI_FLAG is set in dwFindFlags, then, checks if the
  8290. // CRL has an Authority Key Identifier (AKI) extension. If the CRL has an
  8291. // AKI, then, only returns a CRL whose AKI matches the issuer.
  8292. //
  8293. // Note, the AKI extension has the following OID:
  8294. // szOID_AUTHORITY_KEY_IDENTIFIER2 and its corresponding data structure.
  8295. //
  8296. // If CRL_FIND_ISSUED_BY_SIGNATURE_FLAG is set in dwFindFlags, then,
  8297. // uses the public key in the issuer's certificate to verify the
  8298. // signature on the CRL. Only returns a CRL having a valid signature.
  8299. //
  8300. // If CRL_FIND_ISSUED_BY_DELTA_FLAG is set in dwFindFlags, then, only
  8301. // returns a delta CRL.
  8302. //
  8303. // If CRL_FIND_ISSUED_BY_BASE_FLAG is set in dwFindFlags, then, only
  8304. // returns a base CRL.
  8305. //--------------------------------------------------------------------------
  8306. #define CRL_FIND_ISSUED_BY_AKI_FLAG 0x1
  8307. #define CRL_FIND_ISSUED_BY_SIGNATURE_FLAG 0x2
  8308. #define CRL_FIND_ISSUED_BY_DELTA_FLAG 0x4
  8309. #define CRL_FIND_ISSUED_BY_BASE_FLAG 0x8
  8310. //+-------------------------------------------------------------------------
  8311. // CRL_FIND_EXISTING
  8312. //
  8313. // Find existing CRL in the store.
  8314. //
  8315. // pvFindPara is the PCCRL_CONTEXT of the CRL to check if it already
  8316. // exists in the store.
  8317. //--------------------------------------------------------------------------
  8318. //+-------------------------------------------------------------------------
  8319. // CRL_FIND_ISSUED_FOR
  8320. //
  8321. // Find CRL for the specified subject and its issuer.
  8322. //
  8323. // pvFindPara points to the following CRL_FIND_ISSUED_FOR_PARA which contains
  8324. // both the subject and issuer certificates. Not optional.
  8325. //
  8326. // The subject's issuer name is used to match the CRL's issuer name. Otherwise,
  8327. // the issuer's certificate is used the same as in the above
  8328. // CRL_FIND_ISSUED_BY.
  8329. //
  8330. // Note, when cross certificates are used, the subject name in the issuer's
  8331. // certificate may not match the issuer name in the subject certificate and
  8332. // its corresponding CRL.
  8333. //
  8334. // All of the above CRL_FIND_ISSUED_BY_*_FLAGS apply to this find type.
  8335. //--------------------------------------------------------------------------
  8336. typedef struct _CRL_FIND_ISSUED_FOR_PARA {
  8337. PCCERT_CONTEXT pSubjectCert;
  8338. PCCERT_CONTEXT pIssuerCert;
  8339. } CRL_FIND_ISSUED_FOR_PARA, *PCRL_FIND_ISSUED_FOR_PARA;
  8340. //+-------------------------------------------------------------------------
  8341. // Duplicate a CRL context
  8342. //--------------------------------------------------------------------------
  8343. WINCRYPT32API
  8344. PCCRL_CONTEXT
  8345. WINAPI
  8346. CertDuplicateCRLContext(
  8347. IN PCCRL_CONTEXT pCrlContext
  8348. );
  8349. //+-------------------------------------------------------------------------
  8350. // Create a CRL context from the encoded CRL. The created
  8351. // context isn't put in a store.
  8352. //
  8353. // Makes a copy of the encoded CRL in the created context.
  8354. //
  8355. // If unable to decode and create the CRL context, NULL is returned.
  8356. // Otherwise, a pointer to a read only CRL_CONTEXT is returned.
  8357. // CRL_CONTEXT must be freed by calling CertFreeCRLContext.
  8358. // CertDuplicateCRLContext can be called to make a duplicate.
  8359. //
  8360. // CertSetCRLContextProperty and CertGetCRLContextProperty can be called
  8361. // to store properties for the CRL.
  8362. //--------------------------------------------------------------------------
  8363. WINCRYPT32API
  8364. PCCRL_CONTEXT
  8365. WINAPI
  8366. CertCreateCRLContext(
  8367. IN DWORD dwCertEncodingType,
  8368. IN const BYTE *pbCrlEncoded,
  8369. IN DWORD cbCrlEncoded
  8370. );
  8371. //+-------------------------------------------------------------------------
  8372. // Free a CRL context
  8373. //
  8374. // There needs to be a corresponding free for each context obtained by a
  8375. // get, duplicate or create.
  8376. //--------------------------------------------------------------------------
  8377. WINCRYPT32API
  8378. BOOL
  8379. WINAPI
  8380. CertFreeCRLContext(
  8381. IN PCCRL_CONTEXT pCrlContext
  8382. );
  8383. //+-------------------------------------------------------------------------
  8384. // Set the property for the specified CRL context.
  8385. //
  8386. // Same Property Ids and semantics as CertSetCertificateContextProperty.
  8387. //--------------------------------------------------------------------------
  8388. WINCRYPT32API
  8389. BOOL
  8390. WINAPI
  8391. CertSetCRLContextProperty(
  8392. IN PCCRL_CONTEXT pCrlContext,
  8393. IN DWORD dwPropId,
  8394. IN DWORD dwFlags,
  8395. IN const void *pvData
  8396. );
  8397. //+-------------------------------------------------------------------------
  8398. // Get the property for the specified CRL context.
  8399. //
  8400. // Same Property Ids and semantics as CertGetCertificateContextProperty.
  8401. //
  8402. // CERT_SHA1_HASH_PROP_ID, CERT_MD5_HASH_PROP_ID or
  8403. // CERT_SIGNATURE_HASH_PROP_ID is the predefined property of most interest.
  8404. //--------------------------------------------------------------------------
  8405. WINCRYPT32API
  8406. BOOL
  8407. WINAPI
  8408. CertGetCRLContextProperty(
  8409. IN PCCRL_CONTEXT pCrlContext,
  8410. IN DWORD dwPropId,
  8411. OUT void *pvData,
  8412. IN OUT DWORD *pcbData
  8413. );
  8414. //+-------------------------------------------------------------------------
  8415. // Enumerate the properties for the specified CRL context.
  8416. //
  8417. // To get the first property, set dwPropId to 0. The ID of the first
  8418. // property is returned. To get the next property, set dwPropId to the
  8419. // ID returned by the last call. To enumerate all the properties continue
  8420. // until 0 is returned.
  8421. //
  8422. // CertGetCRLContextProperty is called to get the property's data.
  8423. //--------------------------------------------------------------------------
  8424. WINCRYPT32API
  8425. DWORD
  8426. WINAPI
  8427. CertEnumCRLContextProperties(
  8428. IN PCCRL_CONTEXT pCrlContext,
  8429. IN DWORD dwPropId
  8430. );
  8431. //+-------------------------------------------------------------------------
  8432. // Search the CRL's list of entries for the specified certificate.
  8433. //
  8434. // TRUE is returned if we were able to search the list. Otherwise, FALSE is
  8435. // returned,
  8436. //
  8437. // For success, if the certificate was found in the list, *ppCrlEntry is
  8438. // updated with a pointer to the entry. Otherwise, *ppCrlEntry is set to NULL.
  8439. // The returned entry isn't allocated and must not be freed.
  8440. //
  8441. // dwFlags and pvReserved currently aren't used and must be set to 0 or NULL.
  8442. //--------------------------------------------------------------------------
  8443. WINCRYPT32API
  8444. BOOL
  8445. WINAPI
  8446. CertFindCertificateInCRL(
  8447. IN PCCERT_CONTEXT pCert,
  8448. IN PCCRL_CONTEXT pCrlContext,
  8449. IN DWORD dwFlags,
  8450. IN OPTIONAL void *pvReserved,
  8451. OUT PCRL_ENTRY *ppCrlEntry
  8452. );
  8453. //+-------------------------------------------------------------------------
  8454. // Is the specified CRL valid for the certificate.
  8455. //
  8456. // Returns TRUE if the CRL's list of entries would contain the certificate
  8457. // if it was revoked. Note, doesn't check that the certificate is in the
  8458. // list of entries.
  8459. //
  8460. // If the CRL has an Issuing Distribution Point (IDP) extension, checks
  8461. // that it's valid for the subject certificate.
  8462. //
  8463. // dwFlags and pvReserved currently aren't used and must be set to 0 and NULL.
  8464. //--------------------------------------------------------------------------
  8465. WINCRYPT32API
  8466. BOOL
  8467. WINAPI
  8468. CertIsValidCRLForCertificate(
  8469. IN PCCERT_CONTEXT pCert,
  8470. IN PCCRL_CONTEXT pCrl,
  8471. IN DWORD dwFlags,
  8472. IN void *pvReserved
  8473. );
  8474. //+-------------------------------------------------------------------------
  8475. // Add certificate/CRL, encoded, context or element disposition values.
  8476. //--------------------------------------------------------------------------
  8477. #define CERT_STORE_ADD_NEW 1
  8478. #define CERT_STORE_ADD_USE_EXISTING 2
  8479. #define CERT_STORE_ADD_REPLACE_EXISTING 3
  8480. #define CERT_STORE_ADD_ALWAYS 4
  8481. #define CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES 5
  8482. #define CERT_STORE_ADD_NEWER 6
  8483. #define CERT_STORE_ADD_NEWER_INHERIT_PROPERTIES 7
  8484. //+-------------------------------------------------------------------------
  8485. // Add the encoded certificate to the store according to the specified
  8486. // disposition action.
  8487. //
  8488. // Makes a copy of the encoded certificate before adding to the store.
  8489. //
  8490. // dwAddDispostion specifies the action to take if the certificate
  8491. // already exists in the store. This parameter must be one of the following
  8492. // values:
  8493. // CERT_STORE_ADD_NEW
  8494. // Fails if the certificate already exists in the store. LastError
  8495. // is set to CRYPT_E_EXISTS.
  8496. // CERT_STORE_ADD_USE_EXISTING
  8497. // If the certifcate already exists, then, its used and if ppCertContext
  8498. // is non-NULL, the existing context is duplicated.
  8499. // CERT_STORE_ADD_REPLACE_EXISTING
  8500. // If the certificate already exists, then, the existing certificate
  8501. // context is deleted before creating and adding the new context.
  8502. // CERT_STORE_ADD_ALWAYS
  8503. // No check is made to see if the certificate already exists. A
  8504. // new certificate context is always created. This may lead to
  8505. // duplicates in the store.
  8506. // CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES
  8507. // If the certificate already exists, then, its used.
  8508. // CERT_STORE_ADD_NEWER
  8509. // Fails if the certificate already exists in the store AND the NotBefore
  8510. // time of the existing certificate is equal to or greater than the
  8511. // NotBefore time of the new certificate being added. LastError
  8512. // is set to CRYPT_E_EXISTS.
  8513. //
  8514. // If an older certificate is replaced, same as
  8515. // CERT_STORE_ADD_REPLACE_EXISTING.
  8516. //
  8517. // For CRLs or CTLs compares the ThisUpdate times.
  8518. //
  8519. // CERT_STORE_ADD_NEWER_INHERIT_PROPERTIES
  8520. // Same as CERT_STORE_ADD_NEWER. However, if an older certificate is
  8521. // replaced, same as CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES.
  8522. //
  8523. // CertGetSubjectCertificateFromStore is called to determine if the
  8524. // certificate already exists in the store.
  8525. //
  8526. // ppCertContext can be NULL, indicating the caller isn't interested
  8527. // in getting the CERT_CONTEXT of the added or existing certificate.
  8528. //--------------------------------------------------------------------------
  8529. WINCRYPT32API
  8530. BOOL
  8531. WINAPI
  8532. CertAddEncodedCertificateToStore(
  8533. IN HCERTSTORE hCertStore,
  8534. IN DWORD dwCertEncodingType,
  8535. IN const BYTE *pbCertEncoded,
  8536. IN DWORD cbCertEncoded,
  8537. IN DWORD dwAddDisposition,
  8538. OUT OPTIONAL PCCERT_CONTEXT *ppCertContext
  8539. );
  8540. //+-------------------------------------------------------------------------
  8541. // Add the certificate context to the store according to the specified
  8542. // disposition action.
  8543. //
  8544. // In addition to the encoded certificate, the context's properties are
  8545. // also copied. Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  8546. // CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't copied.
  8547. //
  8548. // Makes a copy of the certificate context before adding to the store.
  8549. //
  8550. // dwAddDispostion specifies the action to take if the certificate
  8551. // already exists in the store. This parameter must be one of the following
  8552. // values:
  8553. // CERT_STORE_ADD_NEW
  8554. // Fails if the certificate already exists in the store. LastError
  8555. // is set to CRYPT_E_EXISTS.
  8556. // CERT_STORE_ADD_USE_EXISTING
  8557. // If the certifcate already exists, then, its used and if ppStoreContext
  8558. // is non-NULL, the existing context is duplicated. Iterates
  8559. // through pCertContext's properties and only copies the properties
  8560. // that don't already exist. The SHA1 and MD5 hash properties aren't
  8561. // copied.
  8562. // CERT_STORE_ADD_REPLACE_EXISTING
  8563. // If the certificate already exists, then, the existing certificate
  8564. // context is deleted before creating and adding a new context.
  8565. // Properties are copied before doing the add.
  8566. // CERT_STORE_ADD_ALWAYS
  8567. // No check is made to see if the certificate already exists. A
  8568. // new certificate context is always created and added. This may lead to
  8569. // duplicates in the store. Properties are
  8570. // copied before doing the add.
  8571. // CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES
  8572. // If the certificate already exists, then, the existing certificate
  8573. // context is used. Properties from the added context are copied and
  8574. // replace existing properties. However, any existing properties not
  8575. // in the added context remain and aren't deleted.
  8576. // CERT_STORE_ADD_NEWER
  8577. // Fails if the certificate already exists in the store AND the NotBefore
  8578. // time of the existing context is equal to or greater than the
  8579. // NotBefore time of the new context being added. LastError
  8580. // is set to CRYPT_E_EXISTS.
  8581. //
  8582. // If an older context is replaced, same as
  8583. // CERT_STORE_ADD_REPLACE_EXISTING.
  8584. //
  8585. // For CRLs or CTLs compares the ThisUpdate times.
  8586. //
  8587. // CERT_STORE_ADD_NEWER_INHERIT_PROPERTIES
  8588. // Same as CERT_STORE_ADD_NEWER. However, if an older context is
  8589. // replaced, same as CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES.
  8590. //
  8591. // CertGetSubjectCertificateFromStore is called to determine if the
  8592. // certificate already exists in the store.
  8593. //
  8594. // ppStoreContext can be NULL, indicating the caller isn't interested
  8595. // in getting the CERT_CONTEXT of the added or existing certificate.
  8596. //--------------------------------------------------------------------------
  8597. WINCRYPT32API
  8598. BOOL
  8599. WINAPI
  8600. CertAddCertificateContextToStore(
  8601. IN HCERTSTORE hCertStore,
  8602. IN PCCERT_CONTEXT pCertContext,
  8603. IN DWORD dwAddDisposition,
  8604. OUT OPTIONAL PCCERT_CONTEXT *ppStoreContext
  8605. );
  8606. //+-------------------------------------------------------------------------
  8607. // Certificate Store Context Types
  8608. //--------------------------------------------------------------------------
  8609. #define CERT_STORE_CERTIFICATE_CONTEXT 1
  8610. #define CERT_STORE_CRL_CONTEXT 2
  8611. #define CERT_STORE_CTL_CONTEXT 3
  8612. //+-------------------------------------------------------------------------
  8613. // Certificate Store Context Bit Flags
  8614. //--------------------------------------------------------------------------
  8615. #define CERT_STORE_ALL_CONTEXT_FLAG (~0UL)
  8616. #define CERT_STORE_CERTIFICATE_CONTEXT_FLAG \
  8617. (1 << CERT_STORE_CERTIFICATE_CONTEXT)
  8618. #define CERT_STORE_CRL_CONTEXT_FLAG \
  8619. (1 << CERT_STORE_CRL_CONTEXT)
  8620. #define CERT_STORE_CTL_CONTEXT_FLAG \
  8621. (1 << CERT_STORE_CTL_CONTEXT)
  8622. //+-------------------------------------------------------------------------
  8623. // Add the serialized certificate or CRL element to the store.
  8624. //
  8625. // The serialized element contains the encoded certificate, CRL or CTL and
  8626. // its properties, such as, CERT_KEY_PROV_INFO_PROP_ID.
  8627. //
  8628. // If hCertStore is NULL, creates a certificate, CRL or CTL context not
  8629. // residing in any store.
  8630. //
  8631. // dwAddDispostion specifies the action to take if the certificate or CRL
  8632. // already exists in the store. See CertAddCertificateContextToStore for a
  8633. // list of and actions taken.
  8634. //
  8635. // dwFlags currently isn't used and should be set to 0.
  8636. //
  8637. // dwContextTypeFlags specifies the set of allowable contexts. For example, to
  8638. // add either a certificate or CRL, set dwContextTypeFlags to:
  8639. // CERT_STORE_CERTIFICATE_CONTEXT_FLAG | CERT_STORE_CRL_CONTEXT_FLAG
  8640. //
  8641. // *pdwContextType is updated with the type of the context returned in
  8642. // *ppvContxt. pdwContextType or ppvContext can be NULL, indicating the
  8643. // caller isn't interested in getting the output. If *ppvContext is
  8644. // returned it must be freed by calling CertFreeCertificateContext or
  8645. // CertFreeCRLContext.
  8646. //--------------------------------------------------------------------------
  8647. WINCRYPT32API
  8648. BOOL
  8649. WINAPI
  8650. CertAddSerializedElementToStore(
  8651. IN HCERTSTORE hCertStore,
  8652. IN const BYTE *pbElement,
  8653. IN DWORD cbElement,
  8654. IN DWORD dwAddDisposition,
  8655. IN DWORD dwFlags,
  8656. IN DWORD dwContextTypeFlags,
  8657. OUT OPTIONAL DWORD *pdwContextType,
  8658. OUT OPTIONAL const void **ppvContext
  8659. );
  8660. //+-------------------------------------------------------------------------
  8661. // Delete the specified certificate from the store.
  8662. //
  8663. // All subsequent gets or finds for the certificate will fail. However,
  8664. // memory allocated for the certificate isn't freed until all of its contexts
  8665. // have also been freed.
  8666. //
  8667. // The pCertContext is obtained from a get, enum, find or duplicate.
  8668. //
  8669. // Some store provider implementations might also delete the issuer's CRLs
  8670. // if this is the last certificate for the issuer in the store.
  8671. //
  8672. // NOTE: the pCertContext is always CertFreeCertificateContext'ed by
  8673. // this function, even for an error.
  8674. //--------------------------------------------------------------------------
  8675. WINCRYPT32API
  8676. BOOL
  8677. WINAPI
  8678. CertDeleteCertificateFromStore(
  8679. IN PCCERT_CONTEXT pCertContext
  8680. );
  8681. //+-------------------------------------------------------------------------
  8682. // Add the encoded CRL to the store according to the specified
  8683. // disposition option.
  8684. //
  8685. // Makes a copy of the encoded CRL before adding to the store.
  8686. //
  8687. // dwAddDispostion specifies the action to take if the CRL
  8688. // already exists in the store. See CertAddEncodedCertificateToStore for a
  8689. // list of and actions taken.
  8690. //
  8691. // Compares the CRL's Issuer to determine if the CRL already exists in the
  8692. // store.
  8693. //
  8694. // ppCrlContext can be NULL, indicating the caller isn't interested
  8695. // in getting the CRL_CONTEXT of the added or existing CRL.
  8696. //--------------------------------------------------------------------------
  8697. WINCRYPT32API
  8698. BOOL
  8699. WINAPI
  8700. CertAddEncodedCRLToStore(
  8701. IN HCERTSTORE hCertStore,
  8702. IN DWORD dwCertEncodingType,
  8703. IN const BYTE *pbCrlEncoded,
  8704. IN DWORD cbCrlEncoded,
  8705. IN DWORD dwAddDisposition,
  8706. OUT OPTIONAL PCCRL_CONTEXT *ppCrlContext
  8707. );
  8708. //+-------------------------------------------------------------------------
  8709. // Add the CRL context to the store according to the specified
  8710. // disposition option.
  8711. //
  8712. // In addition to the encoded CRL, the context's properties are
  8713. // also copied. Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  8714. // CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't copied.
  8715. //
  8716. // Makes a copy of the encoded CRL before adding to the store.
  8717. //
  8718. // dwAddDispostion specifies the action to take if the CRL
  8719. // already exists in the store. See CertAddCertificateContextToStore for a
  8720. // list of and actions taken.
  8721. //
  8722. // Compares the CRL's Issuer, ThisUpdate and NextUpdate to determine
  8723. // if the CRL already exists in the store.
  8724. //
  8725. // ppStoreContext can be NULL, indicating the caller isn't interested
  8726. // in getting the CRL_CONTEXT of the added or existing CRL.
  8727. //--------------------------------------------------------------------------
  8728. WINCRYPT32API
  8729. BOOL
  8730. WINAPI
  8731. CertAddCRLContextToStore(
  8732. IN HCERTSTORE hCertStore,
  8733. IN PCCRL_CONTEXT pCrlContext,
  8734. IN DWORD dwAddDisposition,
  8735. OUT OPTIONAL PCCRL_CONTEXT *ppStoreContext
  8736. );
  8737. //+-------------------------------------------------------------------------
  8738. // Delete the specified CRL from the store.
  8739. //
  8740. // All subsequent gets for the CRL will fail. However,
  8741. // memory allocated for the CRL isn't freed until all of its contexts
  8742. // have also been freed.
  8743. //
  8744. // The pCrlContext is obtained from a get or duplicate.
  8745. //
  8746. // NOTE: the pCrlContext is always CertFreeCRLContext'ed by
  8747. // this function, even for an error.
  8748. //--------------------------------------------------------------------------
  8749. WINCRYPT32API
  8750. BOOL
  8751. WINAPI
  8752. CertDeleteCRLFromStore(
  8753. IN PCCRL_CONTEXT pCrlContext
  8754. );
  8755. //+-------------------------------------------------------------------------
  8756. // Serialize the certificate context's encoded certificate and its
  8757. // properties.
  8758. //--------------------------------------------------------------------------
  8759. WINCRYPT32API
  8760. BOOL
  8761. WINAPI
  8762. CertSerializeCertificateStoreElement(
  8763. IN PCCERT_CONTEXT pCertContext,
  8764. IN DWORD dwFlags,
  8765. OUT BYTE *pbElement,
  8766. IN OUT DWORD *pcbElement
  8767. );
  8768. //+-------------------------------------------------------------------------
  8769. // Serialize the CRL context's encoded CRL and its properties.
  8770. //--------------------------------------------------------------------------
  8771. WINCRYPT32API
  8772. BOOL
  8773. WINAPI
  8774. CertSerializeCRLStoreElement(
  8775. IN PCCRL_CONTEXT pCrlContext,
  8776. IN DWORD dwFlags,
  8777. OUT BYTE *pbElement,
  8778. IN OUT DWORD *pcbElement
  8779. );
  8780. //+=========================================================================
  8781. // Certificate Trust List (CTL) Store Data Structures and APIs
  8782. //==========================================================================
  8783. //+-------------------------------------------------------------------------
  8784. // Duplicate a CTL context
  8785. //--------------------------------------------------------------------------
  8786. WINCRYPT32API
  8787. PCCTL_CONTEXT
  8788. WINAPI
  8789. CertDuplicateCTLContext(
  8790. IN PCCTL_CONTEXT pCtlContext
  8791. );
  8792. //+-------------------------------------------------------------------------
  8793. // Create a CTL context from the encoded CTL. The created
  8794. // context isn't put in a store.
  8795. //
  8796. // Makes a copy of the encoded CTL in the created context.
  8797. //
  8798. // If unable to decode and create the CTL context, NULL is returned.
  8799. // Otherwise, a pointer to a read only CTL_CONTEXT is returned.
  8800. // CTL_CONTEXT must be freed by calling CertFreeCTLContext.
  8801. // CertDuplicateCTLContext can be called to make a duplicate.
  8802. //
  8803. // CertSetCTLContextProperty and CertGetCTLContextProperty can be called
  8804. // to store properties for the CTL.
  8805. //--------------------------------------------------------------------------
  8806. WINCRYPT32API
  8807. PCCTL_CONTEXT
  8808. WINAPI
  8809. CertCreateCTLContext(
  8810. IN DWORD dwMsgAndCertEncodingType,
  8811. IN const BYTE *pbCtlEncoded,
  8812. IN DWORD cbCtlEncoded
  8813. );
  8814. //+-------------------------------------------------------------------------
  8815. // Free a CTL context
  8816. //
  8817. // There needs to be a corresponding free for each context obtained by a
  8818. // get, duplicate or create.
  8819. //--------------------------------------------------------------------------
  8820. WINCRYPT32API
  8821. BOOL
  8822. WINAPI
  8823. CertFreeCTLContext(
  8824. IN PCCTL_CONTEXT pCtlContext
  8825. );
  8826. //+-------------------------------------------------------------------------
  8827. // Set the property for the specified CTL context.
  8828. //
  8829. // Same Property Ids and semantics as CertSetCertificateContextProperty.
  8830. //--------------------------------------------------------------------------
  8831. WINCRYPT32API
  8832. BOOL
  8833. WINAPI
  8834. CertSetCTLContextProperty(
  8835. IN PCCTL_CONTEXT pCtlContext,
  8836. IN DWORD dwPropId,
  8837. IN DWORD dwFlags,
  8838. IN const void *pvData
  8839. );
  8840. //+-------------------------------------------------------------------------
  8841. // Get the property for the specified CTL context.
  8842. //
  8843. // Same Property Ids and semantics as CertGetCertificateContextProperty.
  8844. //
  8845. // CERT_SHA1_HASH_PROP_ID or CERT_NEXT_UPDATE_LOCATION_PROP_ID are the
  8846. // predefined properties of most interest.
  8847. //--------------------------------------------------------------------------
  8848. WINCRYPT32API
  8849. BOOL
  8850. WINAPI
  8851. CertGetCTLContextProperty(
  8852. IN PCCTL_CONTEXT pCtlContext,
  8853. IN DWORD dwPropId,
  8854. OUT void *pvData,
  8855. IN OUT DWORD *pcbData
  8856. );
  8857. //+-------------------------------------------------------------------------
  8858. // Enumerate the properties for the specified CTL context.
  8859. //--------------------------------------------------------------------------
  8860. WINCRYPT32API
  8861. DWORD
  8862. WINAPI
  8863. CertEnumCTLContextProperties(
  8864. IN PCCTL_CONTEXT pCtlContext,
  8865. IN DWORD dwPropId
  8866. );
  8867. //+-------------------------------------------------------------------------
  8868. // Enumerate the CTL contexts in the store.
  8869. //
  8870. // If a CTL isn't found, NULL is returned.
  8871. // Otherwise, a pointer to a read only CTL_CONTEXT is returned. CTL_CONTEXT
  8872. // must be freed by calling CertFreeCTLContext or is freed when passed as the
  8873. // pPrevCtlContext on a subsequent call. CertDuplicateCTLContext
  8874. // can be called to make a duplicate.
  8875. //
  8876. // pPrevCtlContext MUST BE NULL to enumerate the first
  8877. // CTL in the store. Successive CTLs are enumerated by setting
  8878. // pPrevCtlContext to the CTL_CONTEXT returned by a previous call.
  8879. //
  8880. // NOTE: a NON-NULL pPrevCtlContext is always CertFreeCTLContext'ed by
  8881. // this function, even for an error.
  8882. //--------------------------------------------------------------------------
  8883. WINCRYPT32API
  8884. PCCTL_CONTEXT
  8885. WINAPI
  8886. CertEnumCTLsInStore(
  8887. IN HCERTSTORE hCertStore,
  8888. IN PCCTL_CONTEXT pPrevCtlContext
  8889. );
  8890. //+-------------------------------------------------------------------------
  8891. // Attempt to find the specified subject in the CTL.
  8892. //
  8893. // For CTL_CERT_SUBJECT_TYPE, pvSubject points to a CERT_CONTEXT. The CTL's
  8894. // SubjectAlgorithm is examined to determine the representation of the
  8895. // subject's identity. Initially, only SHA1 or MD5 hash will be supported.
  8896. // The appropriate hash property is obtained from the CERT_CONTEXT.
  8897. //
  8898. // For CTL_ANY_SUBJECT_TYPE, pvSubject points to the CTL_ANY_SUBJECT_INFO
  8899. // structure which contains the SubjectAlgorithm to be matched in the CTL
  8900. // and the SubjectIdentifer to be matched in one of the CTL entries.
  8901. //
  8902. // The certificate's hash or the CTL_ANY_SUBJECT_INFO's SubjectIdentifier
  8903. // is used as the key in searching the subject entries. A binary
  8904. // memory comparison is done between the key and the entry's SubjectIdentifer.
  8905. //
  8906. // dwEncodingType isn't used for either of the above SubjectTypes.
  8907. //--------------------------------------------------------------------------
  8908. WINCRYPT32API
  8909. PCTL_ENTRY
  8910. WINAPI
  8911. CertFindSubjectInCTL(
  8912. IN DWORD dwEncodingType,
  8913. IN DWORD dwSubjectType,
  8914. IN void *pvSubject,
  8915. IN PCCTL_CONTEXT pCtlContext,
  8916. IN DWORD dwFlags
  8917. );
  8918. // Subject Types:
  8919. // CTL_ANY_SUBJECT_TYPE, pvSubject points to following CTL_ANY_SUBJECT_INFO.
  8920. // CTL_CERT_SUBJECT_TYPE, pvSubject points to CERT_CONTEXT.
  8921. #define CTL_ANY_SUBJECT_TYPE 1
  8922. #define CTL_CERT_SUBJECT_TYPE 2
  8923. typedef struct _CTL_ANY_SUBJECT_INFO {
  8924. CRYPT_ALGORITHM_IDENTIFIER SubjectAlgorithm;
  8925. CRYPT_DATA_BLOB SubjectIdentifier;
  8926. } CTL_ANY_SUBJECT_INFO, *PCTL_ANY_SUBJECT_INFO;
  8927. //+-------------------------------------------------------------------------
  8928. // Find the first or next CTL context in the store.
  8929. //
  8930. // The CTL is found according to the dwFindType and its pvFindPara.
  8931. // See below for a list of the find types and its parameters.
  8932. //
  8933. // Currently dwFindFlags isn't used and must be set to 0.
  8934. //
  8935. // Usage of dwMsgAndCertEncodingType depends on the dwFindType.
  8936. //
  8937. // If the first or next CTL isn't found, NULL is returned.
  8938. // Otherwise, a pointer to a read only CTL_CONTEXT is returned. CTL_CONTEXT
  8939. // must be freed by calling CertFreeCTLContext or is freed when passed as the
  8940. // pPrevCtlContext on a subsequent call. CertDuplicateCTLContext
  8941. // can be called to make a duplicate.
  8942. //
  8943. // pPrevCtlContext MUST BE NULL on the first
  8944. // call to find the CTL. To find the next CTL, the
  8945. // pPrevCtlContext is set to the CTL_CONTEXT returned by a previous call.
  8946. //
  8947. // NOTE: a NON-NULL pPrevCtlContext is always CertFreeCTLContext'ed by
  8948. // this function, even for an error.
  8949. //--------------------------------------------------------------------------
  8950. WINCRYPT32API
  8951. PCCTL_CONTEXT
  8952. WINAPI
  8953. CertFindCTLInStore(
  8954. IN HCERTSTORE hCertStore,
  8955. IN DWORD dwMsgAndCertEncodingType,
  8956. IN DWORD dwFindFlags,
  8957. IN DWORD dwFindType,
  8958. IN const void *pvFindPara,
  8959. IN PCCTL_CONTEXT pPrevCtlContext
  8960. );
  8961. #define CTL_FIND_ANY 0
  8962. #define CTL_FIND_SHA1_HASH 1
  8963. #define CTL_FIND_MD5_HASH 2
  8964. #define CTL_FIND_USAGE 3
  8965. #define CTL_FIND_SUBJECT 4
  8966. #define CTL_FIND_EXISTING 5
  8967. typedef struct _CTL_FIND_USAGE_PARA {
  8968. DWORD cbSize;
  8969. CTL_USAGE SubjectUsage; // optional
  8970. CRYPT_DATA_BLOB ListIdentifier; // optional
  8971. PCERT_INFO pSigner; // optional
  8972. } CTL_FIND_USAGE_PARA, *PCTL_FIND_USAGE_PARA;
  8973. #define CTL_FIND_NO_LIST_ID_CBDATA 0xFFFFFFFF
  8974. #define CTL_FIND_NO_SIGNER_PTR ((PCERT_INFO) -1)
  8975. #define CTL_FIND_SAME_USAGE_FLAG 0x1
  8976. typedef struct _CTL_FIND_SUBJECT_PARA {
  8977. DWORD cbSize;
  8978. PCTL_FIND_USAGE_PARA pUsagePara; // optional
  8979. DWORD dwSubjectType;
  8980. void *pvSubject;
  8981. } CTL_FIND_SUBJECT_PARA, *PCTL_FIND_SUBJECT_PARA;
  8982. //+-------------------------------------------------------------------------
  8983. // CTL_FIND_ANY
  8984. //
  8985. // Find any CTL.
  8986. //
  8987. // pvFindPara isn't used.
  8988. //--------------------------------------------------------------------------
  8989. //+-------------------------------------------------------------------------
  8990. // CTL_FIND_SHA1_HASH
  8991. // CTL_FIND_MD5_HASH
  8992. //
  8993. // Find a CTL with the specified hash.
  8994. //
  8995. // pvFindPara points to a CRYPT_HASH_BLOB.
  8996. //--------------------------------------------------------------------------
  8997. //+-------------------------------------------------------------------------
  8998. // CTL_FIND_USAGE
  8999. //
  9000. // Find a CTL having the specified usage identifiers, list identifier or
  9001. // signer. The CertEncodingType of the signer is obtained from the
  9002. // dwMsgAndCertEncodingType parameter.
  9003. //
  9004. // pvFindPara points to a CTL_FIND_USAGE_PARA data structure. The
  9005. // SubjectUsage.cUsageIdentifer can be 0 to match any usage. The
  9006. // ListIdentifier.cbData can be 0 to match any list identifier. To only match
  9007. // CTLs without a ListIdentifier, cbData must be set to
  9008. // CTL_FIND_NO_LIST_ID_CBDATA. pSigner can be NULL to match any signer. Only
  9009. // the Issuer and SerialNumber fields of the pSigner's PCERT_INFO are used.
  9010. // To only match CTLs without a signer, pSigner must be set to
  9011. // CTL_FIND_NO_SIGNER_PTR.
  9012. //
  9013. // The CTL_FIND_SAME_USAGE_FLAG can be set in dwFindFlags to
  9014. // only match CTLs with the same usage identifiers. CTLs having additional
  9015. // usage identifiers aren't matched. For example, if only "1.2.3" is specified
  9016. // in CTL_FIND_USAGE_PARA, then, for a match, the CTL must only contain
  9017. // "1.2.3" and not any additional usage identifers.
  9018. //--------------------------------------------------------------------------
  9019. //+-------------------------------------------------------------------------
  9020. // CTL_FIND_SUBJECT
  9021. //
  9022. // Find a CTL having the specified subject. CertFindSubjectInCTL can be
  9023. // called to get a pointer to the subject's entry in the CTL. pUsagePara can
  9024. // optionally be set to enable the above CTL_FIND_USAGE matching.
  9025. //
  9026. // pvFindPara points to a CTL_FIND_SUBJECT_PARA data structure.
  9027. //--------------------------------------------------------------------------
  9028. //+-------------------------------------------------------------------------
  9029. // Add the encoded CTL to the store according to the specified
  9030. // disposition option.
  9031. //
  9032. // Makes a copy of the encoded CTL before adding to the store.
  9033. //
  9034. // dwAddDispostion specifies the action to take if the CTL
  9035. // already exists in the store. See CertAddEncodedCertificateToStore for a
  9036. // list of and actions taken.
  9037. //
  9038. // Compares the CTL's SubjectUsage, ListIdentifier and any of its signers
  9039. // to determine if the CTL already exists in the store.
  9040. //
  9041. // ppCtlContext can be NULL, indicating the caller isn't interested
  9042. // in getting the CTL_CONTEXT of the added or existing CTL.
  9043. //--------------------------------------------------------------------------
  9044. WINCRYPT32API
  9045. BOOL
  9046. WINAPI
  9047. CertAddEncodedCTLToStore(
  9048. IN HCERTSTORE hCertStore,
  9049. IN DWORD dwMsgAndCertEncodingType,
  9050. IN const BYTE *pbCtlEncoded,
  9051. IN DWORD cbCtlEncoded,
  9052. IN DWORD dwAddDisposition,
  9053. OUT OPTIONAL PCCTL_CONTEXT *ppCtlContext
  9054. );
  9055. //+-------------------------------------------------------------------------
  9056. // Add the CTL context to the store according to the specified
  9057. // disposition option.
  9058. //
  9059. // In addition to the encoded CTL, the context's properties are
  9060. // also copied. Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  9061. // CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't copied.
  9062. //
  9063. // Makes a copy of the encoded CTL before adding to the store.
  9064. //
  9065. // dwAddDispostion specifies the action to take if the CTL
  9066. // already exists in the store. See CertAddCertificateContextToStore for a
  9067. // list of and actions taken.
  9068. //
  9069. // Compares the CTL's SubjectUsage, ListIdentifier and any of its signers
  9070. // to determine if the CTL already exists in the store.
  9071. //
  9072. // ppStoreContext can be NULL, indicating the caller isn't interested
  9073. // in getting the CTL_CONTEXT of the added or existing CTL.
  9074. //--------------------------------------------------------------------------
  9075. WINCRYPT32API
  9076. BOOL
  9077. WINAPI
  9078. CertAddCTLContextToStore(
  9079. IN HCERTSTORE hCertStore,
  9080. IN PCCTL_CONTEXT pCtlContext,
  9081. IN DWORD dwAddDisposition,
  9082. OUT OPTIONAL PCCTL_CONTEXT *ppStoreContext
  9083. );
  9084. //+-------------------------------------------------------------------------
  9085. // Serialize the CTL context's encoded CTL and its properties.
  9086. //--------------------------------------------------------------------------
  9087. WINCRYPT32API
  9088. BOOL
  9089. WINAPI
  9090. CertSerializeCTLStoreElement(
  9091. IN PCCTL_CONTEXT pCtlContext,
  9092. IN DWORD dwFlags,
  9093. OUT BYTE *pbElement,
  9094. IN OUT DWORD *pcbElement
  9095. );
  9096. //+-------------------------------------------------------------------------
  9097. // Delete the specified CTL from the store.
  9098. //
  9099. // All subsequent gets for the CTL will fail. However,
  9100. // memory allocated for the CTL isn't freed until all of its contexts
  9101. // have also been freed.
  9102. //
  9103. // The pCtlContext is obtained from a get or duplicate.
  9104. //
  9105. // NOTE: the pCtlContext is always CertFreeCTLContext'ed by
  9106. // this function, even for an error.
  9107. //--------------------------------------------------------------------------
  9108. WINCRYPT32API
  9109. BOOL
  9110. WINAPI
  9111. CertDeleteCTLFromStore(
  9112. IN PCCTL_CONTEXT pCtlContext
  9113. );
  9114. WINCRYPT32API
  9115. BOOL
  9116. WINAPI
  9117. CertAddCertificateLinkToStore(
  9118. IN HCERTSTORE hCertStore,
  9119. IN PCCERT_CONTEXT pCertContext,
  9120. IN DWORD dwAddDisposition,
  9121. OUT OPTIONAL PCCERT_CONTEXT *ppStoreContext
  9122. );
  9123. WINCRYPT32API
  9124. BOOL
  9125. WINAPI
  9126. CertAddCRLLinkToStore(
  9127. IN HCERTSTORE hCertStore,
  9128. IN PCCRL_CONTEXT pCrlContext,
  9129. IN DWORD dwAddDisposition,
  9130. OUT OPTIONAL PCCRL_CONTEXT *ppStoreContext
  9131. );
  9132. WINCRYPT32API
  9133. BOOL
  9134. WINAPI
  9135. CertAddCTLLinkToStore(
  9136. IN HCERTSTORE hCertStore,
  9137. IN PCCTL_CONTEXT pCtlContext,
  9138. IN DWORD dwAddDisposition,
  9139. OUT OPTIONAL PCCTL_CONTEXT *ppStoreContext
  9140. );
  9141. WINCRYPT32API
  9142. BOOL
  9143. WINAPI
  9144. CertAddStoreToCollection(
  9145. IN HCERTSTORE hCollectionStore,
  9146. IN OPTIONAL HCERTSTORE hSiblingStore,
  9147. IN DWORD dwUpdateFlags,
  9148. IN DWORD dwPriority
  9149. );
  9150. WINCRYPT32API
  9151. void
  9152. WINAPI
  9153. CertRemoveStoreFromCollection(
  9154. IN HCERTSTORE hCollectionStore,
  9155. IN HCERTSTORE hSiblingStore
  9156. );
  9157. WINCRYPT32API
  9158. BOOL
  9159. WINAPI
  9160. CertControlStore(
  9161. IN HCERTSTORE hCertStore,
  9162. IN DWORD dwFlags,
  9163. IN DWORD dwCtrlType,
  9164. IN void const *pvCtrlPara
  9165. );
  9166. //+-------------------------------------------------------------------------
  9167. // Certificate Store control types
  9168. //--------------------------------------------------------------------------
  9169. #define CERT_STORE_CTRL_RESYNC 1
  9170. #define CERT_STORE_CTRL_NOTIFY_CHANGE 2
  9171. #define CERT_STORE_CTRL_COMMIT 3
  9172. #define CERT_STORE_CTRL_AUTO_RESYNC 4
  9173. #define CERT_STORE_CTRL_CANCEL_NOTIFY 5
  9174. #define CERT_STORE_CTRL_INHIBIT_DUPLICATE_HANDLE_FLAG 0x1
  9175. //+-------------------------------------------------------------------------
  9176. // CERT_STORE_CTRL_RESYNC
  9177. //
  9178. // Re-synchronize the store.
  9179. //
  9180. // The pvCtrlPara points to the event HANDLE to be signaled on
  9181. // the next store change. Normally, this would be the same
  9182. // event HANDLE passed to CERT_STORE_CTRL_NOTIFY_CHANGE during initialization.
  9183. //
  9184. // If pvCtrlPara is NULL, no events are re-armed.
  9185. //
  9186. // By default the event HANDLE is DuplicateHandle'd.
  9187. // CERT_STORE_CTRL_INHIBIT_DUPLICATE_HANDLE_FLAG can be set in dwFlags
  9188. // to inhibit a DupicateHandle of the event HANDLE. If this flag
  9189. // is set, then, CertControlStore(CERT_STORE_CTRL_CANCEL_NOTIFY) must be
  9190. // called for this event HANDLE before closing the hCertStore.
  9191. //--------------------------------------------------------------------------
  9192. //+-------------------------------------------------------------------------
  9193. // CERT_STORE_CTRL_NOTIFY_CHANGE
  9194. //
  9195. // Signal the event when the underlying store is changed.
  9196. //
  9197. // pvCtrlPara points to the event HANDLE to be signaled.
  9198. //
  9199. // pvCtrlPara can be NULL to inform the store of a subsequent
  9200. // CERT_STORE_CTRL_RESYNC and allow it to optimize by only doing a resync
  9201. // if the store has changed. For the registry based stores, an internal
  9202. // notify change event is created and registered to be signaled.
  9203. //
  9204. // Recommend calling CERT_STORE_CTRL_NOTIFY_CHANGE once for each event to
  9205. // be passed to CERT_STORE_CTRL_RESYNC. This should only happen after
  9206. // the event has been created. Not after each time the event is signaled.
  9207. //
  9208. // By default the event HANDLE is DuplicateHandle'd.
  9209. // CERT_STORE_CTRL_INHIBIT_DUPLICATE_HANDLE_FLAG can be set in dwFlags
  9210. // to inhibit a DupicateHandle of the event HANDLE. If this flag
  9211. // is set, then, CertControlStore(CERT_STORE_CTRL_CANCEL_NOTIFY) must be
  9212. // called for this event HANDLE before closing the hCertStore.
  9213. //--------------------------------------------------------------------------
  9214. //+-------------------------------------------------------------------------
  9215. // CERT_STORE_CTRL_CANCEL_NOTIFY
  9216. //
  9217. // Cancel notification signaling of the event HANDLE passed in a previous
  9218. // CERT_STORE_CTRL_NOTIFY_CHANGE or CERT_STORE_CTRL_RESYNC.
  9219. //
  9220. // pvCtrlPara points to the event HANDLE to be canceled.
  9221. //--------------------------------------------------------------------------
  9222. //+-------------------------------------------------------------------------
  9223. // CERT_STORE_CTRL_AUTO_RESYNC
  9224. //
  9225. // At the start of every enumeration or find store API call, check if the
  9226. // underlying store has changed. If it has changed, re-synchronize.
  9227. //
  9228. // This check is only done in the enumeration or find APIs when the
  9229. // pPrevContext is NULL.
  9230. //
  9231. // The pvCtrlPara isn't used and must be set to NULL.
  9232. //--------------------------------------------------------------------------
  9233. //+-------------------------------------------------------------------------
  9234. // CERT_STORE_CTRL_COMMIT
  9235. //
  9236. // If any changes have been to the cached store, they are committed to
  9237. // persisted storage. If no changes have been made since the store was
  9238. // opened or the last commit, this call is ignored. May also be ignored by
  9239. // store providers that persist changes immediately.
  9240. //
  9241. // CERT_STORE_CTRL_COMMIT_FORCE_FLAG can be set to force the store
  9242. // to be committed even if it hasn't been touched.
  9243. //
  9244. // CERT_STORE_CTRL_COMMIT_CLEAR_FLAG can be set to inhibit a commit on
  9245. // store close.
  9246. //--------------------------------------------------------------------------
  9247. #define CERT_STORE_CTRL_COMMIT_FORCE_FLAG 0x1
  9248. #define CERT_STORE_CTRL_COMMIT_CLEAR_FLAG 0x2
  9249. //+=========================================================================
  9250. // Cert Store Property Defines and APIs
  9251. //==========================================================================
  9252. //+-------------------------------------------------------------------------
  9253. // Store property IDs. This is a property applicable to the entire store.
  9254. // Its not a property on an individual certificate, CRL or CTL context.
  9255. //
  9256. // Currently, no store properties are persisted. (This differs from
  9257. // most context properties which are persisted.)
  9258. //
  9259. // See CertSetStoreProperty or CertGetStoreProperty for usage information.
  9260. //
  9261. // Note, the range for predefined store properties should be outside
  9262. // the range of predefined context properties. We will start at 4096.
  9263. //--------------------------------------------------------------------------
  9264. #define CERT_STORE_LOCALIZED_NAME_PROP_ID 0x1000
  9265. //+-------------------------------------------------------------------------
  9266. // Set a store property.
  9267. //
  9268. // The type definition for pvData depends on the dwPropId value.
  9269. // CERT_STORE_LOCALIZED_NAME_PROP_ID - localized name of the store.
  9270. // pvData points to a CRYPT_DATA_BLOB. pbData is a pointer to a NULL
  9271. // terminated unicode, wide character string.
  9272. // cbData = (wcslen((LPWSTR) pbData) + 1) * sizeof(WCHAR).
  9273. //
  9274. // For all the other PROP_IDs: an encoded PCRYPT_DATA_BLOB is passed in pvData.
  9275. //
  9276. // If the property already exists, then, the old value is deleted and silently
  9277. // replaced. Setting, pvData to NULL, deletes the property.
  9278. //--------------------------------------------------------------------------
  9279. WINCRYPT32API
  9280. BOOL
  9281. WINAPI
  9282. CertSetStoreProperty(
  9283. IN HCERTSTORE hCertStore,
  9284. IN DWORD dwPropId,
  9285. IN DWORD dwFlags,
  9286. IN const void *pvData
  9287. );
  9288. //+-------------------------------------------------------------------------
  9289. // Get a store property.
  9290. //
  9291. // The type definition for pvData depends on the dwPropId value.
  9292. // CERT_STORE_LOCALIZED_NAME_PROP_ID - localized name of the store.
  9293. // pvData points to a NULL terminated unicode, wide character string.
  9294. // cbData = (wcslen((LPWSTR) pvData) + 1) * sizeof(WCHAR).
  9295. //
  9296. // For all other PROP_IDs, pvData points to an array of bytes.
  9297. //
  9298. // If the property doesn't exist, returns FALSE and sets LastError to
  9299. // CRYPT_E_NOT_FOUND.
  9300. //--------------------------------------------------------------------------
  9301. WINCRYPT32API
  9302. BOOL
  9303. WINAPI
  9304. CertGetStoreProperty(
  9305. IN HCERTSTORE hCertStore,
  9306. IN DWORD dwPropId,
  9307. OUT void *pvData,
  9308. IN OUT DWORD *pcbData
  9309. );
  9310. typedef struct _CERT_CREATE_CONTEXT_PARA {
  9311. DWORD cbSize;
  9312. PFN_CRYPT_FREE pfnFree; // OPTIONAL
  9313. void *pvFree; // OPTIONAL
  9314. } CERT_CREATE_CONTEXT_PARA, *PCERT_CREATE_CONTEXT_PARA;
  9315. //+-------------------------------------------------------------------------
  9316. // Creates the specified context from the encoded bytes. The created
  9317. // context isn't put in a store.
  9318. //
  9319. // dwContextType values:
  9320. // CERT_STORE_CERTIFICATE_CONTEXT
  9321. // CERT_STORE_CRL_CONTEXT
  9322. // CERT_STORE_CTL_CONTEXT
  9323. //
  9324. // If CERT_CREATE_CONTEXT_NOCOPY_FLAG is set, the created context points
  9325. // directly to the pbEncoded instead of an allocated copy. See flag
  9326. // definition for more details.
  9327. //
  9328. // If CERT_CREATE_CONTEXT_SORTED_FLAG is set, the context is created
  9329. // with sorted entries. This flag may only be set for CERT_STORE_CTL_CONTEXT.
  9330. // Setting this flag implicitly sets CERT_CREATE_CONTEXT_NO_HCRYPTMSG_FLAG and
  9331. // CERT_CREATE_CONTEXT_NO_ENTRY_FLAG. See flag definition for
  9332. // more details.
  9333. //
  9334. // If CERT_CREATE_CONTEXT_NO_HCRYPTMSG_FLAG is set, the context is created
  9335. // without creating a HCRYPTMSG handle for the context. This flag may only be
  9336. // set for CERT_STORE_CTL_CONTEXT. See flag definition for more details.
  9337. //
  9338. // If CERT_CREATE_CONTEXT_NO_ENTRY_FLAG is set, the context is created
  9339. // without decoding the entries. This flag may only be set for
  9340. // CERT_STORE_CTL_CONTEXT. See flag definition for more details.
  9341. //
  9342. // If unable to decode and create the context, NULL is returned.
  9343. // Otherwise, a pointer to a read only CERT_CONTEXT, CRL_CONTEXT or
  9344. // CTL_CONTEXT is returned. The context must be freed by the appropriate
  9345. // free context API. The context can be duplicated by calling the
  9346. // appropriate duplicate context API.
  9347. //--------------------------------------------------------------------------
  9348. WINCRYPT32API
  9349. const void *
  9350. WINAPI
  9351. CertCreateContext(
  9352. IN DWORD dwContextType,
  9353. IN DWORD dwEncodingType,
  9354. IN const BYTE *pbEncoded,
  9355. IN DWORD cbEncoded,
  9356. IN DWORD dwFlags,
  9357. IN OPTIONAL PCERT_CREATE_CONTEXT_PARA pCreatePara
  9358. );
  9359. // When the following flag is set, the created context points directly to the
  9360. // pbEncoded instead of an allocated copy. If pCreatePara and
  9361. // pCreatePara->pfnFree are non-NULL, then, pfnFree is called to free
  9362. // the pbEncoded when the context is last freed. Otherwise, no attempt is
  9363. // made to free the pbEncoded. If pCreatePara->pvFree is non-NULL, then its
  9364. // passed to pfnFree instead of pbEncoded.
  9365. //
  9366. // Note, if CertCreateContext fails, pfnFree is still called.
  9367. #define CERT_CREATE_CONTEXT_NOCOPY_FLAG 0x1
  9368. // When the following flag is set, a context with sorted entries is created.
  9369. // Currently only applicable to a CTL context.
  9370. //
  9371. // For CTLs: the cCTLEntry in the returned CTL_INFO is always
  9372. // 0. CertFindSubjectInSortedCTL and CertEnumSubjectInSortedCTL must be called
  9373. // to find or enumerate the CTL entries.
  9374. //
  9375. // The Sorted CTL TrustedSubjects extension isn't returned in the created
  9376. // context's CTL_INFO.
  9377. #define CERT_CREATE_CONTEXT_SORTED_FLAG 0x2
  9378. // By default when a CTL context is created, a HCRYPTMSG handle to its
  9379. // SignedData message is created. This flag can be set to improve performance
  9380. // by not creating the HCRYPTMSG handle.
  9381. //
  9382. // This flag is only applicable to a CTL context.
  9383. #define CERT_CREATE_CONTEXT_NO_HCRYPTMSG_FLAG 0x4
  9384. // By default when a CTL context is created, its entries are decoded.
  9385. // This flag can be set to improve performance by not decoding the
  9386. // entries.
  9387. //
  9388. // This flag is only applicable to a CTL context.
  9389. #define CERT_CREATE_CONTEXT_NO_ENTRY_FLAG 0x8
  9390. //+=========================================================================
  9391. // Certificate System Store Data Structures and APIs
  9392. //==========================================================================
  9393. //+-------------------------------------------------------------------------
  9394. // System Store Information
  9395. //
  9396. // Currently, no system store information is persisted.
  9397. //--------------------------------------------------------------------------
  9398. typedef struct _CERT_SYSTEM_STORE_INFO {
  9399. DWORD cbSize;
  9400. } CERT_SYSTEM_STORE_INFO, *PCERT_SYSTEM_STORE_INFO;
  9401. //+-------------------------------------------------------------------------
  9402. // Physical Store Information
  9403. //
  9404. // The Open fields are passed directly to CertOpenStore() to open
  9405. // the physical store.
  9406. //
  9407. // By default all system stores located in the registry have an
  9408. // implicit SystemRegistry physical store that is opened. To disable the
  9409. // opening of this store, the SystemRegistry
  9410. // physical store corresponding to the System store must be registered with
  9411. // CERT_PHYSICAL_STORE_OPEN_DISABLE_FLAG set in dwFlags. Alternatively,
  9412. // a physical store with the name of ".Default" may be registered.
  9413. //
  9414. // Depending on the store location and store name, additional predefined
  9415. // physical stores may be opened. For example, system stores in
  9416. // CURRENT_USER have the predefined physical store, .LocalMachine.
  9417. // To disable the opening of these predefined physical stores, the
  9418. // corresponding physical store must be registered with
  9419. // CERT_PHYSICAL_STORE_OPEN_DISABLE_FLAG set in dwFlags.
  9420. //
  9421. // The CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG must be set in dwFlags
  9422. // to enable the adding of a context to the store.
  9423. //
  9424. // When a system store is opened via the SERVICES or USERS store location,
  9425. // the ServiceName\ is prepended to the OpenParameters
  9426. // for CERT_SYSTEM_STORE_CURRENT_USER or CERT_SYSTEM_STORE_CURRENT_SERVICE
  9427. // physical stores and the dwOpenFlags store location is changed to
  9428. // CERT_SYSTEM_STORE_USERS or CERT_SYSTEM_STORE_SERVICES.
  9429. //
  9430. // By default the SYSTEM, SYSTEM_REGISTRY and PHYSICAL provider
  9431. // stores are also opened remotely when the outer system store is opened.
  9432. // The CERT_PHYSICAL_STORE_REMOTE_OPEN_DISABLE_FLAG may be set in dwFlags
  9433. // to disable remote opens.
  9434. //
  9435. // When opened remotely, the \\ComputerName is implicitly prepended to the
  9436. // OpenParameters for the SYSTEM, SYSTEM_REGISTRY and PHYSICAL provider types.
  9437. // To also prepend the \\ComputerName to other provider types, set the
  9438. // CERT_PHYSICAL_STORE_INSERT_COMPUTER_NAME_ENABLE_FLAG in dwFlags.
  9439. //
  9440. // When the system store is opened, its physical stores are ordered
  9441. // according to the dwPriority. A larger dwPriority indicates higher priority.
  9442. //--------------------------------------------------------------------------
  9443. typedef struct _CERT_PHYSICAL_STORE_INFO {
  9444. DWORD cbSize;
  9445. LPSTR pszOpenStoreProvider; // REG_SZ
  9446. DWORD dwOpenEncodingType; // REG_DWORD
  9447. DWORD dwOpenFlags; // REG_DWORD
  9448. CRYPT_DATA_BLOB OpenParameters; // REG_BINARY
  9449. DWORD dwFlags; // REG_DWORD
  9450. DWORD dwPriority; // REG_DWORD
  9451. } CERT_PHYSICAL_STORE_INFO, *PCERT_PHYSICAL_STORE_INFO;
  9452. //+-------------------------------------------------------------------------
  9453. // Physical Store Information dwFlags
  9454. //--------------------------------------------------------------------------
  9455. #define CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG 0x1
  9456. #define CERT_PHYSICAL_STORE_OPEN_DISABLE_FLAG 0x2
  9457. #define CERT_PHYSICAL_STORE_REMOTE_OPEN_DISABLE_FLAG 0x4
  9458. #define CERT_PHYSICAL_STORE_INSERT_COMPUTER_NAME_ENABLE_FLAG 0x8
  9459. //+-------------------------------------------------------------------------
  9460. // Register a system store.
  9461. //
  9462. // The upper word of the dwFlags parameter is used to specify the location of
  9463. // the system store.
  9464. //
  9465. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvSystemStore
  9466. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure. Otherwise,
  9467. // pvSystemStore points to a null terminated UNICODE string.
  9468. //
  9469. // The CERT_SYSTEM_STORE_SERVICES or CERT_SYSTEM_STORE_USERS system store
  9470. // name must be prefixed with the ServiceName or UserName. For example,
  9471. // "ServiceName\Trust".
  9472. //
  9473. // Stores on remote computers can be registered for the
  9474. // CERT_SYSTEM_STORE_LOCAL_MACHINE, CERT_SYSTEM_STORE_SERVICES,
  9475. // CERT_SYSTEM_STORE_USERS, CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY
  9476. // or CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE
  9477. // locations by prepending the computer name. For example, a remote
  9478. // local machine store is registered via "\\ComputerName\Trust" or
  9479. // "ComputerName\Trust". A remote service store is registered via
  9480. // "\\ComputerName\ServiceName\Trust". The leading "\\" backslashes are
  9481. // optional in the ComputerName.
  9482. //
  9483. // Set CERT_STORE_CREATE_NEW_FLAG to cause a failure if the system store
  9484. // already exists in the store location.
  9485. //--------------------------------------------------------------------------
  9486. WINCRYPT32API
  9487. BOOL
  9488. WINAPI
  9489. CertRegisterSystemStore(
  9490. IN const void *pvSystemStore,
  9491. IN DWORD dwFlags,
  9492. IN PCERT_SYSTEM_STORE_INFO pStoreInfo,
  9493. IN OPTIONAL void *pvReserved
  9494. );
  9495. //+-------------------------------------------------------------------------
  9496. // Register a physical store for the specified system store.
  9497. //
  9498. // The upper word of the dwFlags parameter is used to specify the location of
  9499. // the system store.
  9500. //
  9501. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvSystemStore
  9502. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure. Otherwise,
  9503. // pvSystemStore points to a null terminated UNICODE string.
  9504. //
  9505. // See CertRegisterSystemStore for details on prepending a ServiceName
  9506. // and/or ComputerName to the system store name.
  9507. //
  9508. // Set CERT_STORE_CREATE_NEW_FLAG to cause a failure if the physical store
  9509. // already exists in the system store.
  9510. //--------------------------------------------------------------------------
  9511. WINCRYPT32API
  9512. BOOL
  9513. WINAPI
  9514. CertRegisterPhysicalStore(
  9515. IN const void *pvSystemStore,
  9516. IN DWORD dwFlags,
  9517. IN LPCWSTR pwszStoreName,
  9518. IN PCERT_PHYSICAL_STORE_INFO pStoreInfo,
  9519. IN OPTIONAL void *pvReserved
  9520. );
  9521. //+-------------------------------------------------------------------------
  9522. // Unregister the specified system store.
  9523. //
  9524. // The upper word of the dwFlags parameter is used to specify the location of
  9525. // the system store.
  9526. //
  9527. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvSystemStore
  9528. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure. Otherwise,
  9529. // pvSystemStore points to a null terminated UNICODE string.
  9530. //
  9531. // See CertRegisterSystemStore for details on prepending a ServiceName
  9532. // and/or ComputerName to the system store name.
  9533. //
  9534. // CERT_STORE_DELETE_FLAG can optionally be set in dwFlags.
  9535. //--------------------------------------------------------------------------
  9536. WINCRYPT32API
  9537. BOOL
  9538. WINAPI
  9539. CertUnregisterSystemStore(
  9540. IN const void *pvSystemStore,
  9541. IN DWORD dwFlags
  9542. );
  9543. //+-------------------------------------------------------------------------
  9544. // Unregister the physical store from the specified system store.
  9545. //
  9546. // The upper word of the dwFlags parameter is used to specify the location of
  9547. // the system store.
  9548. //
  9549. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvSystemStore
  9550. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure. Otherwise,
  9551. // pvSystemStore points to a null terminated UNICODE string.
  9552. //
  9553. // See CertRegisterSystemStore for details on prepending a ServiceName
  9554. // and/or ComputerName to the system store name.
  9555. //
  9556. // CERT_STORE_DELETE_FLAG can optionally be set in dwFlags.
  9557. //--------------------------------------------------------------------------
  9558. WINCRYPT32API
  9559. BOOL
  9560. WINAPI
  9561. CertUnregisterPhysicalStore(
  9562. IN const void *pvSystemStore,
  9563. IN DWORD dwFlags,
  9564. IN LPCWSTR pwszStoreName
  9565. );
  9566. //+-------------------------------------------------------------------------
  9567. // Enum callbacks
  9568. //
  9569. // The CERT_SYSTEM_STORE_LOCATION_MASK bits in the dwFlags parameter
  9570. // specifies the location of the system store
  9571. //
  9572. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvSystemStore
  9573. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure. Otherwise,
  9574. // pvSystemStore points to a null terminated UNICODE string.
  9575. //
  9576. // The callback returns FALSE and sets LAST_ERROR to stop the enumeration.
  9577. // The LAST_ERROR is returned to the caller of the enumeration.
  9578. //
  9579. // The pvSystemStore passed to the callback has leading ComputerName and/or
  9580. // ServiceName prefixes where appropriate.
  9581. //--------------------------------------------------------------------------
  9582. typedef BOOL (WINAPI *PFN_CERT_ENUM_SYSTEM_STORE_LOCATION)(
  9583. IN LPCWSTR pwszStoreLocation,
  9584. IN DWORD dwFlags,
  9585. IN OPTIONAL void *pvReserved,
  9586. IN OPTIONAL void *pvArg
  9587. );
  9588. typedef BOOL (WINAPI *PFN_CERT_ENUM_SYSTEM_STORE)(
  9589. IN const void *pvSystemStore,
  9590. IN DWORD dwFlags,
  9591. IN PCERT_SYSTEM_STORE_INFO pStoreInfo,
  9592. IN OPTIONAL void *pvReserved,
  9593. IN OPTIONAL void *pvArg
  9594. );
  9595. typedef BOOL (WINAPI *PFN_CERT_ENUM_PHYSICAL_STORE)(
  9596. IN const void *pvSystemStore,
  9597. IN DWORD dwFlags,
  9598. IN LPCWSTR pwszStoreName,
  9599. IN PCERT_PHYSICAL_STORE_INFO pStoreInfo,
  9600. IN OPTIONAL void *pvReserved,
  9601. IN OPTIONAL void *pvArg
  9602. );
  9603. // In the PFN_CERT_ENUM_PHYSICAL_STORE callback the following flag is
  9604. // set if the physical store wasn't registered and is an implicitly created
  9605. // predefined physical store.
  9606. #define CERT_PHYSICAL_STORE_PREDEFINED_ENUM_FLAG 0x1
  9607. // Names of implicitly created predefined physical stores
  9608. #define CERT_PHYSICAL_STORE_DEFAULT_NAME L".Default"
  9609. #define CERT_PHYSICAL_STORE_GROUP_POLICY_NAME L".GroupPolicy"
  9610. #define CERT_PHYSICAL_STORE_LOCAL_MACHINE_NAME L".LocalMachine"
  9611. #define CERT_PHYSICAL_STORE_DS_USER_CERTIFICATE_NAME L".UserCertificate"
  9612. #define CERT_PHYSICAL_STORE_LOCAL_MACHINE_GROUP_POLICY_NAME \
  9613. L".LocalMachineGroupPolicy"
  9614. #define CERT_PHYSICAL_STORE_ENTERPRISE_NAME L".Enterprise"
  9615. #define CERT_PHYSICAL_STORE_AUTH_ROOT_NAME L".AuthRoot"
  9616. //+-------------------------------------------------------------------------
  9617. // Enumerate the system store locations.
  9618. //--------------------------------------------------------------------------
  9619. WINCRYPT32API
  9620. BOOL
  9621. WINAPI
  9622. CertEnumSystemStoreLocation(
  9623. IN DWORD dwFlags,
  9624. IN void *pvArg,
  9625. IN PFN_CERT_ENUM_SYSTEM_STORE_LOCATION pfnEnum
  9626. );
  9627. //+-------------------------------------------------------------------------
  9628. // Enumerate the system stores.
  9629. //
  9630. // The upper word of the dwFlags parameter is used to specify the location of
  9631. // the system store.
  9632. //
  9633. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags,
  9634. // pvSystemStoreLocationPara points to a CERT_SYSTEM_STORE_RELOCATE_PARA
  9635. // data structure. Otherwise, pvSystemStoreLocationPara points to a null
  9636. // terminated UNICODE string.
  9637. //
  9638. // For CERT_SYSTEM_STORE_LOCAL_MACHINE,
  9639. // CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY or
  9640. // CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE, pvSystemStoreLocationPara can
  9641. // optionally be set to a unicode computer name for enumerating local machine
  9642. // stores on a remote computer. For example, "\\ComputerName" or
  9643. // "ComputerName". The leading "\\" backslashes are optional in the
  9644. // ComputerName.
  9645. //
  9646. // For CERT_SYSTEM_STORE_SERVICES or CERT_SYSTEM_STORE_USERS,
  9647. // if pvSystemStoreLocationPara is NULL, then,
  9648. // enumerates both the service/user names and the stores for each service/user
  9649. // name. Otherwise, pvSystemStoreLocationPara is a unicode string specifying a
  9650. // remote computer name and/or service/user name. For example:
  9651. // "ServiceName"
  9652. // "\\ComputerName" or "ComputerName\"
  9653. // "ComputerName\ServiceName"
  9654. // Note, if only the ComputerName is specified, then, it must have either
  9655. // the leading "\\" backslashes or a trailing backslash. Otherwise, its
  9656. // interpretted as the ServiceName or UserName.
  9657. //--------------------------------------------------------------------------
  9658. WINCRYPT32API
  9659. BOOL
  9660. WINAPI
  9661. CertEnumSystemStore(
  9662. IN DWORD dwFlags,
  9663. IN OPTIONAL void *pvSystemStoreLocationPara,
  9664. IN void *pvArg,
  9665. IN PFN_CERT_ENUM_SYSTEM_STORE pfnEnum
  9666. );
  9667. //+-------------------------------------------------------------------------
  9668. // Enumerate the physical stores for the specified system store.
  9669. //
  9670. // The upper word of the dwFlags parameter is used to specify the location of
  9671. // the system store.
  9672. //
  9673. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvSystemStore
  9674. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure. Otherwise,
  9675. // pvSystemStore points to a null terminated UNICODE string.
  9676. //
  9677. // See CertRegisterSystemStore for details on prepending a ServiceName
  9678. // and/or ComputerName to the system store name.
  9679. //
  9680. // If the system store location only supports system stores and doesn't
  9681. // support physical stores, LastError is set to ERROR_CALL_NOT_IMPLEMENTED.
  9682. //--------------------------------------------------------------------------
  9683. WINCRYPT32API
  9684. BOOL
  9685. WINAPI
  9686. CertEnumPhysicalStore(
  9687. IN const void *pvSystemStore,
  9688. IN DWORD dwFlags,
  9689. IN void *pvArg,
  9690. IN PFN_CERT_ENUM_PHYSICAL_STORE pfnEnum
  9691. );
  9692. //+-------------------------------------------------------------------------
  9693. // Certificate System Store Installable Functions
  9694. //
  9695. // The CERT_SYSTEM_STORE_LOCATION_MASK bits in the dwFlags parameter passed
  9696. // to the CertOpenStore(for "System", "SystemRegistry" or "Physical"
  9697. // Provider), CertRegisterSystemStore,
  9698. // CertUnregisterSystemStore, CertEnumSystemStore, CertRegisterPhysicalStore,
  9699. // CertUnregisterPhysicalStore and CertEnumPhysicalStore APIs is used as the
  9700. // constant pszOID value passed to the OID installable functions.
  9701. // Therefore, the pszOID is restricted to a constant <= (LPCSTR) 0x0FFF.
  9702. //
  9703. // The EncodingType is 0.
  9704. //--------------------------------------------------------------------------
  9705. // Installable System Store Provider OID pszFuncNames.
  9706. #define CRYPT_OID_OPEN_SYSTEM_STORE_PROV_FUNC "CertDllOpenSystemStoreProv"
  9707. #define CRYPT_OID_REGISTER_SYSTEM_STORE_FUNC "CertDllRegisterSystemStore"
  9708. #define CRYPT_OID_UNREGISTER_SYSTEM_STORE_FUNC "CertDllUnregisterSystemStore"
  9709. #define CRYPT_OID_ENUM_SYSTEM_STORE_FUNC "CertDllEnumSystemStore"
  9710. #define CRYPT_OID_REGISTER_PHYSICAL_STORE_FUNC "CertDllRegisterPhysicalStore"
  9711. #define CRYPT_OID_UNREGISTER_PHYSICAL_STORE_FUNC "CertDllUnregisterPhysicalStore"
  9712. #define CRYPT_OID_ENUM_PHYSICAL_STORE_FUNC "CertDllEnumPhysicalStore"
  9713. // CertDllOpenSystemStoreProv has the same function signature as the
  9714. // installable "CertDllOpenStoreProv" function. See CertOpenStore for
  9715. // more details.
  9716. // CertDllRegisterSystemStore has the same function signature as
  9717. // CertRegisterSystemStore.
  9718. //
  9719. // The "SystemStoreLocation" REG_SZ value must also be set for registered
  9720. // CertDllEnumSystemStore OID functions.
  9721. #define CRYPT_OID_SYSTEM_STORE_LOCATION_VALUE_NAME L"SystemStoreLocation"
  9722. // The remaining Register, Enum and Unregister OID installable functions
  9723. // have the same signature as their Cert Store API counterpart.
  9724. //+=========================================================================
  9725. // Enhanced Key Usage Helper Functions
  9726. //==========================================================================
  9727. //+-------------------------------------------------------------------------
  9728. // Get the enhanced key usage extension or property from the certificate
  9729. // and decode.
  9730. //
  9731. // If the CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG is set, then, only get the
  9732. // extension.
  9733. //
  9734. // If the CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG is set, then, only get the
  9735. // property.
  9736. //--------------------------------------------------------------------------
  9737. WINCRYPT32API
  9738. BOOL
  9739. WINAPI
  9740. CertGetEnhancedKeyUsage(
  9741. IN PCCERT_CONTEXT pCertContext,
  9742. IN DWORD dwFlags,
  9743. OUT PCERT_ENHKEY_USAGE pUsage,
  9744. IN OUT DWORD *pcbUsage
  9745. );
  9746. //+-------------------------------------------------------------------------
  9747. // Set the enhanced key usage property for the certificate.
  9748. //--------------------------------------------------------------------------
  9749. WINCRYPT32API
  9750. BOOL
  9751. WINAPI
  9752. CertSetEnhancedKeyUsage(
  9753. IN PCCERT_CONTEXT pCertContext,
  9754. IN PCERT_ENHKEY_USAGE pUsage
  9755. );
  9756. //+-------------------------------------------------------------------------
  9757. // Add the usage identifier to the certificate's enhanced key usage property.
  9758. //--------------------------------------------------------------------------
  9759. WINCRYPT32API
  9760. BOOL
  9761. WINAPI
  9762. CertAddEnhancedKeyUsageIdentifier(
  9763. IN PCCERT_CONTEXT pCertContext,
  9764. IN LPCSTR pszUsageIdentifier
  9765. );
  9766. //+-------------------------------------------------------------------------
  9767. // Remove the usage identifier from the certificate's enhanced key usage
  9768. // property.
  9769. //--------------------------------------------------------------------------
  9770. WINCRYPT32API
  9771. BOOL
  9772. WINAPI
  9773. CertRemoveEnhancedKeyUsageIdentifier(
  9774. IN PCCERT_CONTEXT pCertContext,
  9775. IN LPCSTR pszUsageIdentifier
  9776. );
  9777. //+---------------------------------------------------------------------------
  9778. //
  9779. //
  9780. // Takes an array of certs and returns an array of usages
  9781. // which consists of the intersection of the valid usages for each cert.
  9782. // If each cert is good for all possible usages then the cNumOIDs is set to -1.
  9783. //
  9784. //----------------------------------------------------------------------------
  9785. WINCRYPT32API
  9786. BOOL
  9787. WINAPI
  9788. CertGetValidUsages(
  9789. IN DWORD cCerts,
  9790. IN PCCERT_CONTEXT *rghCerts,
  9791. OUT int *cNumOIDs,
  9792. OUT LPSTR *rghOIDs,
  9793. IN OUT DWORD *pcbOIDs);
  9794. //+=========================================================================
  9795. // Cryptographic Message helper functions for verifying and signing a
  9796. // CTL.
  9797. //==========================================================================
  9798. //+-------------------------------------------------------------------------
  9799. // Get and verify the signer of a cryptographic message.
  9800. //
  9801. // To verify a CTL, the hCryptMsg is obtained from the CTL_CONTEXT's
  9802. // hCryptMsg field.
  9803. //
  9804. // If CMSG_TRUSTED_SIGNER_FLAG is set, then, treat the Signer stores as being
  9805. // trusted and only search them to find the certificate corresponding to the
  9806. // signer's issuer and serial number. Otherwise, the SignerStores are
  9807. // optionally provided to supplement the message's store of certificates.
  9808. // If a signer certificate is found, its public key is used to verify
  9809. // the message signature. The CMSG_SIGNER_ONLY_FLAG can be set to
  9810. // return the signer without doing the signature verify.
  9811. //
  9812. // If CMSG_USE_SIGNER_INDEX_FLAG is set, then, only get the signer specified
  9813. // by *pdwSignerIndex. Otherwise, iterate through all the signers
  9814. // until a signer verifies or no more signers.
  9815. //
  9816. // For a verified signature, *ppSigner is updated with certificate context
  9817. // of the signer and *pdwSignerIndex is updated with the index of the signer.
  9818. // ppSigner and/or pdwSignerIndex can be NULL, indicating the caller isn't
  9819. // interested in getting the CertContext and/or index of the signer.
  9820. //--------------------------------------------------------------------------
  9821. WINCRYPT32API
  9822. BOOL
  9823. WINAPI
  9824. CryptMsgGetAndVerifySigner(
  9825. IN HCRYPTMSG hCryptMsg,
  9826. IN DWORD cSignerStore,
  9827. IN OPTIONAL HCERTSTORE *rghSignerStore,
  9828. IN DWORD dwFlags,
  9829. OUT OPTIONAL PCCERT_CONTEXT *ppSigner,
  9830. IN OUT OPTIONAL DWORD *pdwSignerIndex
  9831. );
  9832. #define CMSG_TRUSTED_SIGNER_FLAG 0x1
  9833. #define CMSG_SIGNER_ONLY_FLAG 0x2
  9834. #define CMSG_USE_SIGNER_INDEX_FLAG 0x4
  9835. //+-------------------------------------------------------------------------
  9836. // Sign an encoded CTL.
  9837. //
  9838. // The pbCtlContent can be obtained via a CTL_CONTEXT's pbCtlContent
  9839. // field or via a CryptEncodeObject(PKCS_CTL or PKCS_SORTED_CTL).
  9840. //
  9841. // CMSG_CMS_ENCAPSULATED_CTL_FLAG can be set to encode a CMS compatible
  9842. // V3 SignedData message.
  9843. //--------------------------------------------------------------------------
  9844. WINCRYPT32API
  9845. BOOL
  9846. WINAPI
  9847. CryptMsgSignCTL(
  9848. IN DWORD dwMsgEncodingType,
  9849. IN BYTE *pbCtlContent,
  9850. IN DWORD cbCtlContent,
  9851. IN PCMSG_SIGNED_ENCODE_INFO pSignInfo,
  9852. IN DWORD dwFlags,
  9853. OUT BYTE *pbEncoded,
  9854. IN OUT DWORD *pcbEncoded
  9855. );
  9856. // When set, CTL inner content is encapsulated within an OCTET STRING
  9857. #define CMSG_CMS_ENCAPSULATED_CTL_FLAG 0x00008000
  9858. //+-------------------------------------------------------------------------
  9859. // Encode the CTL and create a signed message containing the encoded CTL.
  9860. //
  9861. // Set CMSG_ENCODE_SORTED_CTL_FLAG if the CTL entries are to be sorted
  9862. // before encoding. This flag should be set, if the
  9863. // CertFindSubjectInSortedCTL or CertEnumSubjectInSortedCTL APIs will
  9864. // be called. If the identifier for the CTL entries is a hash, such as,
  9865. // MD5 or SHA1, then, CMSG_ENCODE_HASHED_SUBJECT_IDENTIFIER_FLAG should
  9866. // also be set.
  9867. //
  9868. // CMSG_CMS_ENCAPSULATED_CTL_FLAG can be set to encode a CMS compatible
  9869. // V3 SignedData message.
  9870. //--------------------------------------------------------------------------
  9871. WINCRYPT32API
  9872. BOOL
  9873. WINAPI
  9874. CryptMsgEncodeAndSignCTL(
  9875. IN DWORD dwMsgEncodingType,
  9876. IN PCTL_INFO pCtlInfo,
  9877. IN PCMSG_SIGNED_ENCODE_INFO pSignInfo,
  9878. IN DWORD dwFlags,
  9879. OUT BYTE *pbEncoded,
  9880. IN OUT DWORD *pcbEncoded
  9881. );
  9882. // The following flag is set if the CTL is to be encoded with sorted
  9883. // trusted subjects and the szOID_SORTED_CTL extension is inserted containing
  9884. // sorted offsets to the encoded subjects.
  9885. #define CMSG_ENCODE_SORTED_CTL_FLAG 0x1
  9886. // If the above sorted flag is set, then, the following flag should also
  9887. // be set if the identifier for the TrustedSubjects is a hash,
  9888. // such as, MD5 or SHA1.
  9889. #define CMSG_ENCODE_HASHED_SUBJECT_IDENTIFIER_FLAG 0x2
  9890. //+-------------------------------------------------------------------------
  9891. // Returns TRUE if the SubjectIdentifier exists in the CTL. Optionally
  9892. // returns a pointer to and byte count of the Subject's encoded attributes.
  9893. //--------------------------------------------------------------------------
  9894. WINCRYPT32API
  9895. BOOL
  9896. WINAPI
  9897. CertFindSubjectInSortedCTL(
  9898. IN PCRYPT_DATA_BLOB pSubjectIdentifier,
  9899. IN PCCTL_CONTEXT pCtlContext,
  9900. IN DWORD dwFlags,
  9901. IN void *pvReserved,
  9902. OUT OPTIONAL PCRYPT_DER_BLOB pEncodedAttributes
  9903. );
  9904. //+-------------------------------------------------------------------------
  9905. // Enumerates through the sequence of TrustedSubjects in a CTL context
  9906. // created with CERT_CREATE_CONTEXT_SORTED_FLAG set.
  9907. //
  9908. // To start the enumeration, *ppvNextSubject must be NULL. Upon return,
  9909. // *ppvNextSubject is updated to point to the next TrustedSubject in
  9910. // the encoded sequence.
  9911. //
  9912. // Returns FALSE for no more subjects or invalid arguments.
  9913. //
  9914. // Note, the returned DER_BLOBs point directly into the encoded
  9915. // bytes (not allocated, and must not be freed).
  9916. //--------------------------------------------------------------------------
  9917. WINCRYPT32API
  9918. BOOL
  9919. WINAPI
  9920. CertEnumSubjectInSortedCTL(
  9921. IN PCCTL_CONTEXT pCtlContext,
  9922. IN OUT void **ppvNextSubject,
  9923. OUT OPTIONAL PCRYPT_DER_BLOB pSubjectIdentifier,
  9924. OUT OPTIONAL PCRYPT_DER_BLOB pEncodedAttributes
  9925. );
  9926. //+=========================================================================
  9927. // Certificate Verify CTL Usage Data Structures and APIs
  9928. //==========================================================================
  9929. typedef struct _CTL_VERIFY_USAGE_PARA {
  9930. DWORD cbSize;
  9931. CRYPT_DATA_BLOB ListIdentifier; // OPTIONAL
  9932. DWORD cCtlStore;
  9933. HCERTSTORE *rghCtlStore; // OPTIONAL
  9934. DWORD cSignerStore;
  9935. HCERTSTORE *rghSignerStore; // OPTIONAL
  9936. } CTL_VERIFY_USAGE_PARA, *PCTL_VERIFY_USAGE_PARA;
  9937. typedef struct _CTL_VERIFY_USAGE_STATUS {
  9938. DWORD cbSize;
  9939. DWORD dwError;
  9940. DWORD dwFlags;
  9941. PCCTL_CONTEXT *ppCtl; // IN OUT OPTIONAL
  9942. DWORD dwCtlEntryIndex;
  9943. PCCERT_CONTEXT *ppSigner; // IN OUT OPTIONAL
  9944. DWORD dwSignerIndex;
  9945. } CTL_VERIFY_USAGE_STATUS, *PCTL_VERIFY_USAGE_STATUS;
  9946. #define CERT_VERIFY_INHIBIT_CTL_UPDATE_FLAG 0x1
  9947. #define CERT_VERIFY_TRUSTED_SIGNERS_FLAG 0x2
  9948. #define CERT_VERIFY_NO_TIME_CHECK_FLAG 0x4
  9949. #define CERT_VERIFY_ALLOW_MORE_USAGE_FLAG 0x8
  9950. #define CERT_VERIFY_UPDATED_CTL_FLAG 0x1
  9951. //+-------------------------------------------------------------------------
  9952. // Verify that a subject is trusted for the specified usage by finding a
  9953. // signed and time valid CTL with the usage identifiers and containing the
  9954. // the subject. A subject can be identified by either its certificate context
  9955. // or any identifier such as its SHA1 hash.
  9956. //
  9957. // See CertFindSubjectInCTL for definition of dwSubjectType and pvSubject
  9958. // parameters.
  9959. //
  9960. // Via pVerifyUsagePara, the caller can specify the stores to be searched
  9961. // to find the CTL. The caller can also specify the stores containing
  9962. // acceptable CTL signers. By setting the ListIdentifier, the caller
  9963. // can also restrict to a particular signer CTL list.
  9964. //
  9965. // Via pVerifyUsageStatus, the CTL containing the subject, the subject's
  9966. // index into the CTL's array of entries, and the signer of the CTL
  9967. // are returned. If the caller is not interested, ppCtl and ppSigner can be set
  9968. // to NULL. Returned contexts must be freed via the store's free context APIs.
  9969. //
  9970. // If the CERT_VERIFY_INHIBIT_CTL_UPDATE_FLAG isn't set, then, a time
  9971. // invalid CTL in one of the CtlStores may be replaced. When replaced, the
  9972. // CERT_VERIFY_UPDATED_CTL_FLAG is set in pVerifyUsageStatus->dwFlags.
  9973. //
  9974. // If the CERT_VERIFY_TRUSTED_SIGNERS_FLAG is set, then, only the
  9975. // SignerStores specified in pVerifyUsageStatus are searched to find
  9976. // the signer. Otherwise, the SignerStores provide additional sources
  9977. // to find the signer's certificate.
  9978. //
  9979. // If CERT_VERIFY_NO_TIME_CHECK_FLAG is set, then, the CTLs aren't checked
  9980. // for time validity.
  9981. //
  9982. // If CERT_VERIFY_ALLOW_MORE_USAGE_FLAG is set, then, the CTL may contain
  9983. // additional usage identifiers than specified by pSubjectUsage. Otherwise,
  9984. // the found CTL will contain the same usage identifers and no more.
  9985. //
  9986. // CertVerifyCTLUsage will be implemented as a dispatcher to OID installable
  9987. // functions. First, it will try to find an OID function matching the first
  9988. // usage object identifier in the pUsage sequence. Next, it will dispatch
  9989. // to the default CertDllVerifyCTLUsage functions.
  9990. //
  9991. // If the subject is trusted for the specified usage, then, TRUE is
  9992. // returned. Otherwise, FALSE is returned with dwError set to one of the
  9993. // following:
  9994. // CRYPT_E_NO_VERIFY_USAGE_DLL
  9995. // CRYPT_E_NO_VERIFY_USAGE_CHECK
  9996. // CRYPT_E_VERIFY_USAGE_OFFLINE
  9997. // CRYPT_E_NOT_IN_CTL
  9998. // CRYPT_E_NO_TRUSTED_SIGNER
  9999. //--------------------------------------------------------------------------
  10000. WINCRYPT32API
  10001. BOOL
  10002. WINAPI
  10003. CertVerifyCTLUsage(
  10004. IN DWORD dwEncodingType,
  10005. IN DWORD dwSubjectType,
  10006. IN void *pvSubject,
  10007. IN PCTL_USAGE pSubjectUsage,
  10008. IN DWORD dwFlags,
  10009. IN OPTIONAL PCTL_VERIFY_USAGE_PARA pVerifyUsagePara,
  10010. IN OUT PCTL_VERIFY_USAGE_STATUS pVerifyUsageStatus
  10011. );
  10012. //+=========================================================================
  10013. // Certificate Revocation Data Structures and APIs
  10014. //==========================================================================
  10015. //+-------------------------------------------------------------------------
  10016. // This data structure is updated by a CRL revocation type handler
  10017. // with the base and possibly the delta CRL used.
  10018. //--------------------------------------------------------------------------
  10019. typedef struct _CERT_REVOCATION_CRL_INFO {
  10020. DWORD cbSize;
  10021. PCCRL_CONTEXT pBaseCrlContext;
  10022. PCCRL_CONTEXT pDeltaCrlContext;
  10023. // When revoked, points to entry in either of the above CRL contexts.
  10024. // Don't free.
  10025. PCRL_ENTRY pCrlEntry;
  10026. BOOL fDeltaCrlEntry; // TRUE if in pDeltaCrlContext
  10027. } CERT_REVOCATION_CRL_INFO, *PCERT_REVOCATION_CRL_INFO;
  10028. //+-------------------------------------------------------------------------
  10029. // The following data structure may be passed to CertVerifyRevocation to
  10030. // assist in finding the issuer of the context to be verified.
  10031. //
  10032. // When pIssuerCert is specified, pIssuerCert is the issuer of
  10033. // rgpvContext[cContext - 1].
  10034. //
  10035. // When cCertStore and rgCertStore are specified, these stores may contain
  10036. // an issuer certificate.
  10037. //
  10038. // When hCrlStore is specified then a handler which uses CRLs can search this
  10039. // store for them
  10040. //
  10041. // When pftTimeToUse is specified then the handler (if possible) must determine
  10042. // revocation status relative to the time given otherwise the answer may be
  10043. // independent of time or relative to current time
  10044. //--------------------------------------------------------------------------
  10045. typedef struct _CERT_REVOCATION_PARA {
  10046. DWORD cbSize;
  10047. PCCERT_CONTEXT pIssuerCert;
  10048. DWORD cCertStore;
  10049. HCERTSTORE *rgCertStore;
  10050. HCERTSTORE hCrlStore;
  10051. LPFILETIME pftTimeToUse;
  10052. #ifdef CERT_REVOCATION_PARA_HAS_EXTRA_FIELDS
  10053. // Note, if you #define CERT_REVOCATION_PARA_HAS_EXTRA_FIELDS, then, you
  10054. // must zero all unused fields in this data structure.
  10055. // More fields could be added in a future release.
  10056. // 0 uses revocation handler's default timeout.
  10057. DWORD dwUrlRetrievalTimeout; // milliseconds
  10058. // When set, checks and attempts to retrieve a CRL where
  10059. // ThisUpdate >= (CurrentTime - dwFreshnessTime). Otherwise, defaults
  10060. // to using the CRL's NextUpdate.
  10061. BOOL fCheckFreshnessTime;
  10062. DWORD dwFreshnessTime; // seconds
  10063. // If NULL, revocation handler gets the current time
  10064. LPFILETIME pftCurrentTime;
  10065. // If nonNULL, a CRL revocation type handler updates with the base and
  10066. // possibly the delta CRL used. Note, *pCrlInfo must be initialized
  10067. // by the caller. Any nonNULL CRL contexts are freed. Any updated
  10068. // CRL contexts must be freed by the caller.
  10069. //
  10070. // The CRL info is only applicable to the last context checked. If
  10071. // interested in this information, then, CertVerifyRevocation should be
  10072. // called with cContext = 1.
  10073. PCERT_REVOCATION_CRL_INFO pCrlInfo;
  10074. #endif
  10075. } CERT_REVOCATION_PARA, *PCERT_REVOCATION_PARA;
  10076. //+-------------------------------------------------------------------------
  10077. // The following data structure is returned by CertVerifyRevocation to
  10078. // specify the status of the revoked or unchecked context. Review the
  10079. // following CertVerifyRevocation comments for details.
  10080. //
  10081. // Upon input to CertVerifyRevocation, cbSize must be set to a size
  10082. // >= (offsetof(CERT_REVOCATION_STATUS, dwReason) + sizeof(DWORD) ).
  10083. // Otherwise, CertVerifyRevocation returns FALSE and sets LastError to
  10084. // E_INVALIDARG.
  10085. //
  10086. // Upon input to the installed or registered CRYPT_OID_VERIFY_REVOCATION_FUNC
  10087. // functions, the dwIndex, dwError and dwReason have been zero'ed.
  10088. // If present, fHasFreshnessTime and dwFreshnessTime have been zero'ed.
  10089. //--------------------------------------------------------------------------
  10090. typedef struct _CERT_REVOCATION_STATUS {
  10091. DWORD cbSize;
  10092. DWORD dwIndex;
  10093. DWORD dwError;
  10094. DWORD dwReason;
  10095. // Depending on cbSize, the following fields may optionally be returned.
  10096. // The Freshness time is only applicable to the last context checked. If
  10097. // interested in this information, then, CertVerifyRevocation should be
  10098. // called with cContext = 1.
  10099. //
  10100. // fHasFreshnessTime is only set if we are able to retrieve revocation
  10101. // information. For a CRL its CurrentTime - ThisUpdate.
  10102. BOOL fHasFreshnessTime;
  10103. DWORD dwFreshnessTime; // seconds
  10104. } CERT_REVOCATION_STATUS, *PCERT_REVOCATION_STATUS;
  10105. //+-------------------------------------------------------------------------
  10106. // Verifies the array of contexts for revocation. The dwRevType parameter
  10107. // indicates the type of the context data structure passed in rgpvContext.
  10108. // Currently only the revocation of certificates is defined.
  10109. //
  10110. // If the CERT_VERIFY_REV_CHAIN_FLAG flag is set, then, CertVerifyRevocation
  10111. // is verifying a chain of certs where, rgpvContext[i + 1] is the issuer
  10112. // of rgpvContext[i]. Otherwise, CertVerifyRevocation makes no assumptions
  10113. // about the order of the contexts.
  10114. //
  10115. // To assist in finding the issuer, the pRevPara may optionally be set. See
  10116. // the CERT_REVOCATION_PARA data structure for details.
  10117. //
  10118. // The contexts must contain enough information to allow the
  10119. // installable or registered revocation DLLs to find the revocation server. For
  10120. // certificates, this information would normally be conveyed in an
  10121. // extension such as the IETF's AuthorityInfoAccess extension.
  10122. //
  10123. // CertVerifyRevocation returns TRUE if all of the contexts were successfully
  10124. // checked and none were revoked. Otherwise, returns FALSE and updates the
  10125. // returned pRevStatus data structure as follows:
  10126. // dwIndex
  10127. // Index of the first context that was revoked or unable to
  10128. // be checked for revocation
  10129. // dwError
  10130. // Error status. LastError is also set to this error status.
  10131. // dwError can be set to one of the following error codes defined
  10132. // in winerror.h:
  10133. // ERROR_SUCCESS - good context
  10134. // CRYPT_E_REVOKED - context was revoked. dwReason contains the
  10135. // reason for revocation
  10136. // CRYPT_E_REVOCATION_OFFLINE - unable to connect to the
  10137. // revocation server
  10138. // CRYPT_E_NOT_IN_REVOCATION_DATABASE - the context to be checked
  10139. // was not found in the revocation server's database.
  10140. // CRYPT_E_NO_REVOCATION_CHECK - the called revocation function
  10141. // wasn't able to do a revocation check on the context
  10142. // CRYPT_E_NO_REVOCATION_DLL - no installed or registered Dll was
  10143. // found to verify revocation
  10144. // dwReason
  10145. // The dwReason is currently only set for CRYPT_E_REVOKED and contains
  10146. // the reason why the context was revoked. May be one of the following
  10147. // CRL reasons defined by the CRL Reason Code extension ("2.5.29.21")
  10148. // CRL_REASON_UNSPECIFIED 0
  10149. // CRL_REASON_KEY_COMPROMISE 1
  10150. // CRL_REASON_CA_COMPROMISE 2
  10151. // CRL_REASON_AFFILIATION_CHANGED 3
  10152. // CRL_REASON_SUPERSEDED 4
  10153. // CRL_REASON_CESSATION_OF_OPERATION 5
  10154. // CRL_REASON_CERTIFICATE_HOLD 6
  10155. //
  10156. // For each entry in rgpvContext, CertVerifyRevocation iterates
  10157. // through the CRYPT_OID_VERIFY_REVOCATION_FUNC
  10158. // function set's list of installed DEFAULT functions.
  10159. // CryptGetDefaultOIDFunctionAddress is called with pwszDll = NULL. If no
  10160. // installed functions are found capable of doing the revocation verification,
  10161. // CryptVerifyRevocation iterates through CRYPT_OID_VERIFY_REVOCATION_FUNC's
  10162. // list of registered DEFAULT Dlls. CryptGetDefaultOIDDllList is called to
  10163. // get the list. CryptGetDefaultOIDFunctionAddress is called to load the Dll.
  10164. //
  10165. // The called functions have the same signature as CertVerifyRevocation. A
  10166. // called function returns TRUE if it was able to successfully check all of
  10167. // the contexts and none were revoked. Otherwise, the called function returns
  10168. // FALSE and updates pRevStatus. dwIndex is set to the index of
  10169. // the first context that was found to be revoked or unable to be checked.
  10170. // dwError and LastError are updated. For CRYPT_E_REVOKED, dwReason
  10171. // is updated. Upon input to the called function, dwIndex, dwError and
  10172. // dwReason have been zero'ed. cbSize has been checked to be >=
  10173. // sizeof(CERT_REVOCATION_STATUS).
  10174. //
  10175. // If the called function returns FALSE, and dwError isn't set to
  10176. // CRYPT_E_REVOKED, then, CertVerifyRevocation either continues on to the
  10177. // next DLL in the list for a returned dwIndex of 0 or for a returned
  10178. // dwIndex > 0, restarts the process of finding a verify function by
  10179. // advancing the start of the context array to the returned dwIndex and
  10180. // decrementing the count of remaining contexts.
  10181. //--------------------------------------------------------------------------
  10182. WINCRYPT32API
  10183. BOOL
  10184. WINAPI
  10185. CertVerifyRevocation(
  10186. IN DWORD dwEncodingType,
  10187. IN DWORD dwRevType,
  10188. IN DWORD cContext,
  10189. IN PVOID rgpvContext[],
  10190. IN DWORD dwFlags,
  10191. IN OPTIONAL PCERT_REVOCATION_PARA pRevPara,
  10192. IN OUT PCERT_REVOCATION_STATUS pRevStatus
  10193. );
  10194. //+-------------------------------------------------------------------------
  10195. // Revocation types
  10196. //--------------------------------------------------------------------------
  10197. #define CERT_CONTEXT_REVOCATION_TYPE 1
  10198. //+-------------------------------------------------------------------------
  10199. // When the following flag is set, rgpvContext[] consists of a chain
  10200. // of certificates, where rgpvContext[i + 1] is the issuer of rgpvContext[i].
  10201. //--------------------------------------------------------------------------
  10202. #define CERT_VERIFY_REV_CHAIN_FLAG 0x00000001
  10203. //+-------------------------------------------------------------------------
  10204. // CERT_VERIFY_CACHE_ONLY_BASED_REVOCATION prevents the revocation handler from
  10205. // accessing any network based resources for revocation checking
  10206. //--------------------------------------------------------------------------
  10207. #define CERT_VERIFY_CACHE_ONLY_BASED_REVOCATION 0x00000002
  10208. //+-------------------------------------------------------------------------
  10209. // By default, the dwUrlRetrievalTimeout in pRevPara is the timeout used
  10210. // for each URL wire retrieval. When the following flag is set,
  10211. // dwUrlRetrievalTimeout is the accumulative timeout across all URL wire
  10212. // retrievals.
  10213. //--------------------------------------------------------------------------
  10214. #define CERT_VERIFY_REV_ACCUMULATIVE_TIMEOUT_FLAG 0x00000004
  10215. //+-------------------------------------------------------------------------
  10216. // CERT_CONTEXT_REVOCATION_TYPE
  10217. //
  10218. // pvContext points to a const CERT_CONTEXT.
  10219. //--------------------------------------------------------------------------
  10220. //+=========================================================================
  10221. // Certificate Helper APIs
  10222. //==========================================================================
  10223. //+-------------------------------------------------------------------------
  10224. // Compare two multiple byte integer blobs to see if they are identical.
  10225. //
  10226. // Before doing the comparison, leading zero bytes are removed from a
  10227. // positive number and leading 0xFF bytes are removed from a negative
  10228. // number.
  10229. //
  10230. // The multiple byte integers are treated as Little Endian. pbData[0] is the
  10231. // least significant byte and pbData[cbData - 1] is the most significant
  10232. // byte.
  10233. //
  10234. // Returns TRUE if the integer blobs are identical after removing leading
  10235. // 0 or 0xFF bytes.
  10236. //--------------------------------------------------------------------------
  10237. BOOL
  10238. WINAPI
  10239. CertCompareIntegerBlob(
  10240. IN PCRYPT_INTEGER_BLOB pInt1,
  10241. IN PCRYPT_INTEGER_BLOB pInt2
  10242. );
  10243. //+-------------------------------------------------------------------------
  10244. // Compare two certificates to see if they are identical.
  10245. //
  10246. // Since a certificate is uniquely identified by its Issuer and SerialNumber,
  10247. // these are the only fields needing to be compared.
  10248. //
  10249. // Returns TRUE if the certificates are identical.
  10250. //--------------------------------------------------------------------------
  10251. WINCRYPT32API
  10252. BOOL
  10253. WINAPI
  10254. CertCompareCertificate(
  10255. IN DWORD dwCertEncodingType,
  10256. IN PCERT_INFO pCertId1,
  10257. IN PCERT_INFO pCertId2
  10258. );
  10259. //+-------------------------------------------------------------------------
  10260. // Compare two certificate names to see if they are identical.
  10261. //
  10262. // Returns TRUE if the names are identical.
  10263. //--------------------------------------------------------------------------
  10264. WINCRYPT32API
  10265. BOOL
  10266. WINAPI
  10267. CertCompareCertificateName(
  10268. IN DWORD dwCertEncodingType,
  10269. IN PCERT_NAME_BLOB pCertName1,
  10270. IN PCERT_NAME_BLOB pCertName2
  10271. );
  10272. //+-------------------------------------------------------------------------
  10273. // Compare the attributes in the certificate name with the specified
  10274. // Relative Distinguished Name's (CERT_RDN) array of attributes.
  10275. // The comparison iterates through the CERT_RDN attributes and looks for an
  10276. // attribute match in any of the certificate name's RDNs.
  10277. // Returns TRUE if all the attributes are found and match.
  10278. //
  10279. // The CERT_RDN_ATTR fields can have the following special values:
  10280. // pszObjId == NULL - ignore the attribute object identifier
  10281. // dwValueType == RDN_ANY_TYPE - ignore the value type
  10282. //
  10283. // CERT_CASE_INSENSITIVE_IS_RDN_ATTRS_FLAG should be set to do
  10284. // a case insensitive match. Otherwise, defaults to an exact, case sensitive
  10285. // match.
  10286. //
  10287. // CERT_UNICODE_IS_RDN_ATTRS_FLAG should be set if the pRDN was initialized
  10288. // with unicode strings as for CryptEncodeObject(X509_UNICODE_NAME).
  10289. //--------------------------------------------------------------------------
  10290. WINCRYPT32API
  10291. BOOL
  10292. WINAPI
  10293. CertIsRDNAttrsInCertificateName(
  10294. IN DWORD dwCertEncodingType,
  10295. IN DWORD dwFlags,
  10296. IN PCERT_NAME_BLOB pCertName,
  10297. IN PCERT_RDN pRDN
  10298. );
  10299. #define CERT_UNICODE_IS_RDN_ATTRS_FLAG 0x1
  10300. #define CERT_CASE_INSENSITIVE_IS_RDN_ATTRS_FLAG 0x2
  10301. //+-------------------------------------------------------------------------
  10302. // Compare two public keys to see if they are identical.
  10303. //
  10304. // Returns TRUE if the keys are identical.
  10305. //--------------------------------------------------------------------------
  10306. WINCRYPT32API
  10307. BOOL
  10308. WINAPI
  10309. CertComparePublicKeyInfo(
  10310. IN DWORD dwCertEncodingType,
  10311. IN PCERT_PUBLIC_KEY_INFO pPublicKey1,
  10312. IN PCERT_PUBLIC_KEY_INFO pPublicKey2
  10313. );
  10314. //+-------------------------------------------------------------------------
  10315. // Get the public/private key's bit length.
  10316. //
  10317. // Returns 0 if unable to determine the key's length.
  10318. //--------------------------------------------------------------------------
  10319. WINCRYPT32API
  10320. DWORD
  10321. WINAPI
  10322. CertGetPublicKeyLength(
  10323. IN DWORD dwCertEncodingType,
  10324. IN PCERT_PUBLIC_KEY_INFO pPublicKey
  10325. );
  10326. //+-------------------------------------------------------------------------
  10327. // Verify the signature of a subject certificate or a CRL using the
  10328. // public key info
  10329. //
  10330. // Returns TRUE for a valid signature.
  10331. //
  10332. // hCryptProv specifies the crypto provider to use to verify the signature.
  10333. // It doesn't need to use a private key.
  10334. //--------------------------------------------------------------------------
  10335. WINCRYPT32API
  10336. BOOL
  10337. WINAPI
  10338. CryptVerifyCertificateSignature(
  10339. IN HCRYPTPROV hCryptProv,
  10340. IN DWORD dwCertEncodingType,
  10341. IN const BYTE * pbEncoded,
  10342. IN DWORD cbEncoded,
  10343. IN PCERT_PUBLIC_KEY_INFO pPublicKey
  10344. );
  10345. //+-------------------------------------------------------------------------
  10346. // Verify the signature of a subject certificate, CRL, certificate request
  10347. // or keygen request using the issuer's public key.
  10348. //
  10349. // Returns TRUE for a valid signature.
  10350. //
  10351. // The subject can be an encoded blob or a context for a certificate or CRL.
  10352. // For a subject certificate context, if the certificate is missing
  10353. // inheritable PublicKey Algorithm Parameters, the context's
  10354. // CERT_PUBKEY_ALG_PARA_PROP_ID is updated with the issuer's public key
  10355. // algorithm parameters for a valid signature.
  10356. //
  10357. // The issuer can be a pointer to a CERT_PUBLIC_KEY_INFO, certificate
  10358. // context or a chain context.
  10359. //
  10360. // hCryptProv specifies the crypto provider to use to verify the signature.
  10361. // Its private key isn't used. If hCryptProv is NULL, a default
  10362. // provider is picked according to the PublicKey Algorithm OID.
  10363. //
  10364. // If the signature algorithm is a hashing algorithm, then, the
  10365. // signature is expected to contain the hash octets. Only dwIssuerType
  10366. // of CRYPT_VERIFY_CERT_SIGN_ISSUER_NULL may be specified
  10367. // to verify this no signature case. If any other dwIssuerType is
  10368. // specified, the verify will fail with LastError set to E_INVALIDARG.
  10369. //--------------------------------------------------------------------------
  10370. WINCRYPT32API
  10371. BOOL
  10372. WINAPI
  10373. CryptVerifyCertificateSignatureEx(
  10374. IN OPTIONAL HCRYPTPROV hCryptProv,
  10375. IN DWORD dwCertEncodingType,
  10376. IN DWORD dwSubjectType,
  10377. IN void *pvSubject,
  10378. IN DWORD dwIssuerType,
  10379. IN void *pvIssuer,
  10380. IN DWORD dwFlags,
  10381. IN OPTIONAL void *pvReserved
  10382. );
  10383. // Subject Types
  10384. #define CRYPT_VERIFY_CERT_SIGN_SUBJECT_BLOB 1
  10385. // pvSubject :: PCRYPT_DATA_BLOB
  10386. #define CRYPT_VERIFY_CERT_SIGN_SUBJECT_CERT 2
  10387. // pvSubject :: PCCERT_CONTEXT
  10388. #define CRYPT_VERIFY_CERT_SIGN_SUBJECT_CRL 3
  10389. // pvSubject :: PCCRL_CONTEXT
  10390. // Issuer Types
  10391. #define CRYPT_VERIFY_CERT_SIGN_ISSUER_PUBKEY 1
  10392. // pvIssuer :: PCERT_PUBLIC_KEY_INFO
  10393. #define CRYPT_VERIFY_CERT_SIGN_ISSUER_CERT 2
  10394. // pvIssuer :: PCCERT_CONTEXT
  10395. #define CRYPT_VERIFY_CERT_SIGN_ISSUER_CHAIN 3
  10396. // pvIssuer :: PCCERT_CHAIN_CONTEXT
  10397. #define CRYPT_VERIFY_CERT_SIGN_ISSUER_NULL 4
  10398. // pvIssuer :: NULL
  10399. //+-------------------------------------------------------------------------
  10400. // Compute the hash of the "to be signed" information in the encoded
  10401. // signed content (CERT_SIGNED_CONTENT_INFO).
  10402. //
  10403. // hCryptProv specifies the crypto provider to use to compute the hash.
  10404. // It doesn't need to use a private key.
  10405. //--------------------------------------------------------------------------
  10406. WINCRYPT32API
  10407. BOOL
  10408. WINAPI
  10409. CryptHashToBeSigned(
  10410. IN HCRYPTPROV hCryptProv,
  10411. IN DWORD dwCertEncodingType,
  10412. IN const BYTE *pbEncoded,
  10413. IN DWORD cbEncoded,
  10414. OUT BYTE *pbComputedHash,
  10415. IN OUT DWORD *pcbComputedHash
  10416. );
  10417. //+-------------------------------------------------------------------------
  10418. // Hash the encoded content.
  10419. //
  10420. // hCryptProv specifies the crypto provider to use to compute the hash.
  10421. // It doesn't need to use a private key.
  10422. //
  10423. // Algid specifies the CAPI hash algorithm to use. If Algid is 0, then, the
  10424. // default hash algorithm (currently SHA1) is used.
  10425. //--------------------------------------------------------------------------
  10426. WINCRYPT32API
  10427. BOOL
  10428. WINAPI
  10429. CryptHashCertificate(
  10430. IN HCRYPTPROV hCryptProv,
  10431. IN ALG_ID Algid,
  10432. IN DWORD dwFlags,
  10433. IN const BYTE *pbEncoded,
  10434. IN DWORD cbEncoded,
  10435. OUT BYTE *pbComputedHash,
  10436. IN OUT DWORD *pcbComputedHash
  10437. );
  10438. //+-------------------------------------------------------------------------
  10439. // Sign the "to be signed" information in the encoded signed content.
  10440. //
  10441. // hCryptProv specifies the crypto provider to use to do the signature.
  10442. // It uses the specified private key.
  10443. //
  10444. // If the SignatureAlgorithm is a hash algorithm, then, the signature
  10445. // contains the hash octets. A private key isn't used to encrypt the hash.
  10446. // dwKeySpec isn't used and hCryptProv can be NULL where an appropriate
  10447. // default provider will be used for hashing.
  10448. //--------------------------------------------------------------------------
  10449. WINCRYPT32API
  10450. BOOL
  10451. WINAPI
  10452. CryptSignCertificate(
  10453. IN HCRYPTPROV hCryptProv,
  10454. IN DWORD dwKeySpec,
  10455. IN DWORD dwCertEncodingType,
  10456. IN const BYTE *pbEncodedToBeSigned,
  10457. IN DWORD cbEncodedToBeSigned,
  10458. IN PCRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm,
  10459. IN OPTIONAL const void *pvHashAuxInfo,
  10460. OUT BYTE *pbSignature,
  10461. IN OUT DWORD *pcbSignature
  10462. );
  10463. //+-------------------------------------------------------------------------
  10464. // Encode the "to be signed" information. Sign the encoded "to be signed".
  10465. // Encode the "to be signed" and the signature.
  10466. //
  10467. // hCryptProv specifies the crypto provider to use to do the signature.
  10468. // It uses the specified private key.
  10469. //
  10470. // If the SignatureAlgorithm is a hash algorithm, then, the signature
  10471. // contains the hash octets. A private key isn't used to encrypt the hash.
  10472. // dwKeySpec isn't used and hCryptProv can be NULL where an appropriate
  10473. // default provider will be used for hashing.
  10474. //--------------------------------------------------------------------------
  10475. WINCRYPT32API
  10476. BOOL
  10477. WINAPI
  10478. CryptSignAndEncodeCertificate(
  10479. IN HCRYPTPROV hCryptProv,
  10480. IN DWORD dwKeySpec,
  10481. IN DWORD dwCertEncodingType,
  10482. IN LPCSTR lpszStructType, // "to be signed"
  10483. IN const void *pvStructInfo,
  10484. IN PCRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm,
  10485. IN OPTIONAL const void *pvHashAuxInfo,
  10486. OUT PBYTE pbEncoded,
  10487. IN OUT DWORD *pcbEncoded
  10488. );
  10489. //+-------------------------------------------------------------------------
  10490. // Verify the time validity of a certificate.
  10491. //
  10492. // Returns -1 if before NotBefore, +1 if after NotAfter and otherwise 0 for
  10493. // a valid certificate
  10494. //
  10495. // If pTimeToVerify is NULL, uses the current time.
  10496. //--------------------------------------------------------------------------
  10497. WINCRYPT32API
  10498. LONG
  10499. WINAPI
  10500. CertVerifyTimeValidity(
  10501. IN LPFILETIME pTimeToVerify,
  10502. IN PCERT_INFO pCertInfo
  10503. );
  10504. //+-------------------------------------------------------------------------
  10505. // Verify the time validity of a CRL.
  10506. //
  10507. // Returns -1 if before ThisUpdate, +1 if after NextUpdate and otherwise 0 for
  10508. // a valid CRL
  10509. //
  10510. // If pTimeToVerify is NULL, uses the current time.
  10511. //--------------------------------------------------------------------------
  10512. WINCRYPT32API
  10513. LONG
  10514. WINAPI
  10515. CertVerifyCRLTimeValidity(
  10516. IN LPFILETIME pTimeToVerify,
  10517. IN PCRL_INFO pCrlInfo
  10518. );
  10519. //+-------------------------------------------------------------------------
  10520. // Verify that the subject's time validity nests within the issuer's time
  10521. // validity.
  10522. //
  10523. // Returns TRUE if it nests. Otherwise, returns FALSE.
  10524. //--------------------------------------------------------------------------
  10525. WINCRYPT32API
  10526. BOOL
  10527. WINAPI
  10528. CertVerifyValidityNesting(
  10529. IN PCERT_INFO pSubjectInfo,
  10530. IN PCERT_INFO pIssuerInfo
  10531. );
  10532. //+-------------------------------------------------------------------------
  10533. // Verify that the subject certificate isn't on its issuer CRL.
  10534. //
  10535. // Returns true if the certificate isn't on the CRL.
  10536. //--------------------------------------------------------------------------
  10537. WINCRYPT32API
  10538. BOOL
  10539. WINAPI
  10540. CertVerifyCRLRevocation(
  10541. IN DWORD dwCertEncodingType,
  10542. IN PCERT_INFO pCertId, // Only the Issuer and SerialNumber
  10543. // fields are used
  10544. IN DWORD cCrlInfo,
  10545. IN PCRL_INFO rgpCrlInfo[]
  10546. );
  10547. //+-------------------------------------------------------------------------
  10548. // Convert the CAPI AlgId to the ASN.1 Object Identifier string
  10549. //
  10550. // Returns NULL if there isn't an ObjId corresponding to the AlgId.
  10551. //--------------------------------------------------------------------------
  10552. WINCRYPT32API
  10553. LPCSTR
  10554. WINAPI
  10555. CertAlgIdToOID(
  10556. IN DWORD dwAlgId
  10557. );
  10558. //+-------------------------------------------------------------------------
  10559. // Convert the ASN.1 Object Identifier string to the CAPI AlgId.
  10560. //
  10561. // Returns 0 if there isn't an AlgId corresponding to the ObjId.
  10562. //--------------------------------------------------------------------------
  10563. WINCRYPT32API
  10564. DWORD
  10565. WINAPI
  10566. CertOIDToAlgId(
  10567. IN LPCSTR pszObjId
  10568. );
  10569. //+-------------------------------------------------------------------------
  10570. // Find an extension identified by its Object Identifier.
  10571. //
  10572. // If found, returns pointer to the extension. Otherwise, returns NULL.
  10573. //--------------------------------------------------------------------------
  10574. WINCRYPT32API
  10575. PCERT_EXTENSION
  10576. WINAPI
  10577. CertFindExtension(
  10578. IN LPCSTR pszObjId,
  10579. IN DWORD cExtensions,
  10580. IN CERT_EXTENSION rgExtensions[]
  10581. );
  10582. //+-------------------------------------------------------------------------
  10583. // Find the first attribute identified by its Object Identifier.
  10584. //
  10585. // If found, returns pointer to the attribute. Otherwise, returns NULL.
  10586. //--------------------------------------------------------------------------
  10587. WINCRYPT32API
  10588. PCRYPT_ATTRIBUTE
  10589. WINAPI
  10590. CertFindAttribute(
  10591. IN LPCSTR pszObjId,
  10592. IN DWORD cAttr,
  10593. IN CRYPT_ATTRIBUTE rgAttr[]
  10594. );
  10595. //+-------------------------------------------------------------------------
  10596. // Find the first CERT_RDN attribute identified by its Object Identifier in
  10597. // the name's list of Relative Distinguished Names.
  10598. //
  10599. // If found, returns pointer to the attribute. Otherwise, returns NULL.
  10600. //--------------------------------------------------------------------------
  10601. WINCRYPT32API
  10602. PCERT_RDN_ATTR
  10603. WINAPI
  10604. CertFindRDNAttr(
  10605. IN LPCSTR pszObjId,
  10606. IN PCERT_NAME_INFO pName
  10607. );
  10608. //+-------------------------------------------------------------------------
  10609. // Get the intended key usage bytes from the certificate.
  10610. //
  10611. // If the certificate doesn't have any intended key usage bytes, returns FALSE
  10612. // and *pbKeyUsage is zeroed. Otherwise, returns TRUE and up through
  10613. // cbKeyUsage bytes are copied into *pbKeyUsage. Any remaining uncopied
  10614. // bytes are zeroed.
  10615. //--------------------------------------------------------------------------
  10616. WINCRYPT32API
  10617. BOOL
  10618. WINAPI
  10619. CertGetIntendedKeyUsage(
  10620. IN DWORD dwCertEncodingType,
  10621. IN PCERT_INFO pCertInfo,
  10622. OUT BYTE *pbKeyUsage,
  10623. IN DWORD cbKeyUsage
  10624. );
  10625. typedef void *HCRYPTDEFAULTCONTEXT;
  10626. //+-------------------------------------------------------------------------
  10627. // Install a previously CryptAcquiredContext'ed HCRYPTPROV to be used as
  10628. // a default context.
  10629. //
  10630. // dwDefaultType and pvDefaultPara specify where the default context is used.
  10631. // For example, install the HCRYPTPROV to be used to verify certificate's
  10632. // having szOID_OIWSEC_md5RSA signatures.
  10633. //
  10634. // By default, the installed HCRYPTPROV is only applicable to the current
  10635. // thread. Set CRYPT_DEFAULT_CONTEXT_PROCESS_FLAG to allow the HCRYPTPROV
  10636. // to be used by all threads in the current process.
  10637. //
  10638. // For a successful install, TRUE is returned and *phDefaultContext is
  10639. // updated with the HANDLE to be passed to CryptUninstallDefaultContext.
  10640. //
  10641. // The installed HCRYPTPROVs are stack ordered (the last installed
  10642. // HCRYPTPROV is checked first). All thread installed HCRYPTPROVs are
  10643. // checked before any process HCRYPTPROVs.
  10644. //
  10645. // The installed HCRYPTPROV remains available for default usage until
  10646. // CryptUninstallDefaultContext is called or the thread or process exits.
  10647. //
  10648. // If CRYPT_DEFAULT_CONTEXT_AUTO_RELEASE_FLAG is set, then, the HCRYPTPROV
  10649. // is CryptReleaseContext'ed at thread or process exit. However,
  10650. // not CryptReleaseContext'ed if CryptUninstallDefaultContext is
  10651. // called.
  10652. //--------------------------------------------------------------------------
  10653. WINCRYPT32API
  10654. BOOL
  10655. WINAPI
  10656. CryptInstallDefaultContext(
  10657. IN HCRYPTPROV hCryptProv,
  10658. IN DWORD dwDefaultType,
  10659. IN const void *pvDefaultPara,
  10660. IN DWORD dwFlags,
  10661. IN void *pvReserved,
  10662. OUT HCRYPTDEFAULTCONTEXT *phDefaultContext
  10663. );
  10664. // dwFlags
  10665. #define CRYPT_DEFAULT_CONTEXT_AUTO_RELEASE_FLAG 0x00000001
  10666. #define CRYPT_DEFAULT_CONTEXT_PROCESS_FLAG 0x00000002
  10667. // List of dwDefaultType's
  10668. #define CRYPT_DEFAULT_CONTEXT_CERT_SIGN_OID 1
  10669. #define CRYPT_DEFAULT_CONTEXT_MULTI_CERT_SIGN_OID 2
  10670. //+-------------------------------------------------------------------------
  10671. // CRYPT_DEFAULT_CONTEXT_CERT_SIGN_OID
  10672. //
  10673. // Install a default HCRYPTPROV used to verify a certificate
  10674. // signature. pvDefaultPara points to the szOID of the certificate
  10675. // signature algorithm, for example, szOID_OIWSEC_md5RSA. If
  10676. // pvDefaultPara is NULL, then, the HCRYPTPROV is used to verify all
  10677. // certificate signatures. Note, pvDefaultPara can't be NULL when
  10678. // CRYPT_DEFAULT_CONTEXT_PROCESS_FLAG is set.
  10679. //--------------------------------------------------------------------------
  10680. //+-------------------------------------------------------------------------
  10681. // CRYPT_DEFAULT_CONTEXT_MULTI_CERT_SIGN_OID
  10682. //
  10683. // Same as CRYPT_DEFAULT_CONTEXT_CERT_SIGN_OID. However, the default
  10684. // HCRYPTPROV is to be used for multiple signature szOIDs. pvDefaultPara
  10685. // points to a CRYPT_DEFAULT_CONTEXT_MULTI_OID_PARA structure containing
  10686. // an array of szOID pointers.
  10687. //--------------------------------------------------------------------------
  10688. typedef struct _CRYPT_DEFAULT_CONTEXT_MULTI_OID_PARA {
  10689. DWORD cOID;
  10690. LPSTR *rgpszOID;
  10691. } CRYPT_DEFAULT_CONTEXT_MULTI_OID_PARA, *PCRYPT_DEFAULT_CONTEXT_MULTI_OID_PARA;
  10692. //+-------------------------------------------------------------------------
  10693. // Uninstall a default context previously installed by
  10694. // CryptInstallDefaultContext.
  10695. //
  10696. // For a default context installed with CRYPT_DEFAULT_CONTEXT_PROCESS_FLAG
  10697. // set, if any other threads are currently using this context,
  10698. // this function will block until they finish.
  10699. //--------------------------------------------------------------------------
  10700. WINCRYPT32API
  10701. BOOL
  10702. WINAPI
  10703. CryptUninstallDefaultContext(
  10704. HCRYPTDEFAULTCONTEXT hDefaultContext,
  10705. IN DWORD dwFlags,
  10706. IN void *pvReserved
  10707. );
  10708. //+-------------------------------------------------------------------------
  10709. // Export the public key info associated with the provider's corresponding
  10710. // private key.
  10711. //
  10712. // Calls CryptExportPublicKeyInfoEx with pszPublicKeyObjId = NULL,
  10713. // dwFlags = 0 and pvAuxInfo = NULL.
  10714. //--------------------------------------------------------------------------
  10715. WINCRYPT32API
  10716. BOOL
  10717. WINAPI
  10718. CryptExportPublicKeyInfo(
  10719. IN HCRYPTPROV hCryptProv,
  10720. IN DWORD dwKeySpec,
  10721. IN DWORD dwCertEncodingType,
  10722. OUT PCERT_PUBLIC_KEY_INFO pInfo,
  10723. IN OUT DWORD *pcbInfo
  10724. );
  10725. //+-------------------------------------------------------------------------
  10726. // Export the public key info associated with the provider's corresponding
  10727. // private key.
  10728. //
  10729. // Uses the dwCertEncodingType and pszPublicKeyObjId to call the
  10730. // installable CRYPT_OID_EXPORT_PUBLIC_KEY_INFO_FUNC. The called function
  10731. // has the same signature as CryptExportPublicKeyInfoEx.
  10732. //
  10733. // If unable to find an installable OID function for the pszPublicKeyObjId,
  10734. // attempts to export as a RSA Public Key (szOID_RSA_RSA).
  10735. //
  10736. // The dwFlags and pvAuxInfo aren't used for szOID_RSA_RSA.
  10737. //--------------------------------------------------------------------------
  10738. #define CRYPT_OID_EXPORT_PUBLIC_KEY_INFO_FUNC "CryptDllExportPublicKeyInfoEx"
  10739. WINCRYPT32API
  10740. BOOL
  10741. WINAPI
  10742. CryptExportPublicKeyInfoEx(
  10743. IN HCRYPTPROV hCryptProv,
  10744. IN DWORD dwKeySpec,
  10745. IN DWORD dwCertEncodingType,
  10746. IN LPSTR pszPublicKeyObjId,
  10747. IN DWORD dwFlags,
  10748. IN OPTIONAL void *pvAuxInfo,
  10749. OUT PCERT_PUBLIC_KEY_INFO pInfo,
  10750. IN OUT DWORD *pcbInfo
  10751. );
  10752. //+-------------------------------------------------------------------------
  10753. // Convert and import the public key info into the provider and return a
  10754. // handle to the public key.
  10755. //
  10756. // Calls CryptImportPublicKeyInfoEx with aiKeyAlg = 0, dwFlags = 0 and
  10757. // pvAuxInfo = NULL.
  10758. //--------------------------------------------------------------------------
  10759. WINCRYPT32API
  10760. BOOL
  10761. WINAPI
  10762. CryptImportPublicKeyInfo(
  10763. IN HCRYPTPROV hCryptProv,
  10764. IN DWORD dwCertEncodingType,
  10765. IN PCERT_PUBLIC_KEY_INFO pInfo,
  10766. OUT HCRYPTKEY *phKey
  10767. );
  10768. //+-------------------------------------------------------------------------
  10769. // Convert and import the public key info into the provider and return a
  10770. // handle to the public key.
  10771. //
  10772. // Uses the dwCertEncodingType and pInfo->Algorithm.pszObjId to call the
  10773. // installable CRYPT_OID_IMPORT_PUBLIC_KEY_INFO_FUNC. The called function
  10774. // has the same signature as CryptImportPublicKeyInfoEx.
  10775. //
  10776. // If unable to find an installable OID function for the pszObjId,
  10777. // attempts to import as a RSA Public Key (szOID_RSA_RSA).
  10778. //
  10779. // For szOID_RSA_RSA: aiKeyAlg may be set to CALG_RSA_SIGN or CALG_RSA_KEYX.
  10780. // Defaults to CALG_RSA_KEYX. The dwFlags and pvAuxInfo aren't used.
  10781. //--------------------------------------------------------------------------
  10782. #define CRYPT_OID_IMPORT_PUBLIC_KEY_INFO_FUNC "CryptDllImportPublicKeyInfoEx"
  10783. WINCRYPT32API
  10784. BOOL
  10785. WINAPI
  10786. CryptImportPublicKeyInfoEx(
  10787. IN HCRYPTPROV hCryptProv,
  10788. IN DWORD dwCertEncodingType,
  10789. IN PCERT_PUBLIC_KEY_INFO pInfo,
  10790. IN ALG_ID aiKeyAlg,
  10791. IN DWORD dwFlags,
  10792. IN OPTIONAL void *pvAuxInfo,
  10793. OUT HCRYPTKEY *phKey
  10794. );
  10795. //+-------------------------------------------------------------------------
  10796. // Acquire a HCRYPTPROV handle and dwKeySpec for the specified certificate
  10797. // context. Uses the certificate's CERT_KEY_PROV_INFO_PROP_ID property.
  10798. // The returned HCRYPTPROV handle may optionally be cached using the
  10799. // certificate's CERT_KEY_CONTEXT_PROP_ID property.
  10800. //
  10801. // If CRYPT_ACQUIRE_CACHE_FLAG is set, then, if an already acquired and
  10802. // cached HCRYPTPROV exists for the certificate, its returned. Otherwise,
  10803. // a HCRYPTPROV is acquired and then cached via the certificate's
  10804. // CERT_KEY_CONTEXT_PROP_ID.
  10805. //
  10806. // The CRYPT_ACQUIRE_USE_PROV_INFO_FLAG can be set to use the dwFlags field of
  10807. // the certificate's CERT_KEY_PROV_INFO_PROP_ID property's CRYPT_KEY_PROV_INFO
  10808. // data structure to determine if the returned HCRYPTPROV should be cached.
  10809. // HCRYPTPROV caching is enabled if the CERT_SET_KEY_CONTEXT_PROP_ID flag was
  10810. // set.
  10811. //
  10812. // If CRYPT_ACQUIRE_COMPARE_KEY_FLAG is set, then,
  10813. // the public key in the certificate is compared with the public
  10814. // key returned by the cryptographic provider. If the keys don't match, the
  10815. // acquire fails and LastError is set to NTE_BAD_PUBLIC_KEY. Note, if
  10816. // a cached HCRYPTPROV is returned, the comparison isn't done. We assume the
  10817. // comparison was done on the initial acquire.
  10818. //
  10819. // The CRYPT_ACQUIRE_SILENT_FLAG can be set to suppress any UI by the CSP.
  10820. // See CryptAcquireContext's CRYPT_SILENT flag for more details.
  10821. //
  10822. // *pfCallerFreeProv is returned set to FALSE for:
  10823. // - Acquire or public key comparison fails.
  10824. // - CRYPT_ACQUIRE_CACHE_FLAG is set.
  10825. // - CRYPT_ACQUIRE_USE_PROV_INFO_FLAG is set AND
  10826. // CERT_SET_KEY_CONTEXT_PROP_ID flag is set in the dwFlags field of the
  10827. // certificate's CERT_KEY_PROV_INFO_PROP_ID property's
  10828. // CRYPT_KEY_PROV_INFO data structure.
  10829. // When *pfCallerFreeProv is FALSE, the caller must not release. The
  10830. // returned HCRYPTPROV will be released on the last free of the certificate
  10831. // context.
  10832. //
  10833. // Otherwise, *pfCallerFreeProv is TRUE and the returned HCRYPTPROV must
  10834. // be released by the caller by calling CryptReleaseContext.
  10835. //--------------------------------------------------------------------------
  10836. WINCRYPT32API
  10837. BOOL
  10838. WINAPI
  10839. CryptAcquireCertificatePrivateKey(
  10840. IN PCCERT_CONTEXT pCert,
  10841. IN DWORD dwFlags,
  10842. IN void *pvReserved,
  10843. OUT HCRYPTPROV *phCryptProv,
  10844. OUT OPTIONAL DWORD *pdwKeySpec,
  10845. OUT OPTIONAL BOOL *pfCallerFreeProv
  10846. );
  10847. #define CRYPT_ACQUIRE_CACHE_FLAG 0x00000001
  10848. #define CRYPT_ACQUIRE_USE_PROV_INFO_FLAG 0x00000002
  10849. #define CRYPT_ACQUIRE_COMPARE_KEY_FLAG 0x00000004
  10850. #define CRYPT_ACQUIRE_SILENT_FLAG 0x00000040
  10851. //+-------------------------------------------------------------------------
  10852. // Enumerates the cryptographic providers and their containers to find the
  10853. // private key corresponding to the certificate's public key. For a match,
  10854. // the certificate's CERT_KEY_PROV_INFO_PROP_ID property is updated.
  10855. //
  10856. // If the CERT_KEY_PROV_INFO_PROP_ID is already set, then, its checked to
  10857. // see if it matches the provider's public key. For a match, the above
  10858. // enumeration is skipped.
  10859. //
  10860. // By default both the user and machine key containers are searched.
  10861. // The CRYPT_FIND_USER_KEYSET_FLAG or CRYPT_FIND_MACHINE_KEYSET_FLAG
  10862. // can be set in dwFlags to restrict the search to either of the containers.
  10863. //
  10864. // The CRYPT_FIND_SILENT_KEYSET_FLAG can be set to suppress any UI by the CSP.
  10865. // See CryptAcquireContext's CRYPT_SILENT flag for more details.
  10866. //
  10867. // If a container isn't found, returns FALSE with LastError set to
  10868. // NTE_NO_KEY.
  10869. //--------------------------------------------------------------------------
  10870. WINCRYPT32API
  10871. BOOL
  10872. WINAPI
  10873. CryptFindCertificateKeyProvInfo(
  10874. IN PCCERT_CONTEXT pCert,
  10875. IN DWORD dwFlags,
  10876. IN void *pvReserved
  10877. );
  10878. #define CRYPT_FIND_USER_KEYSET_FLAG 0x00000001
  10879. #define CRYPT_FIND_MACHINE_KEYSET_FLAG 0x00000002
  10880. #define CRYPT_FIND_SILENT_KEYSET_FLAG 0x00000040
  10881. //+-------------------------------------------------------------------------
  10882. // This is the prototype for the installable function which is called to
  10883. // actually import a key into a CSP. an installable of this type is called
  10884. // from CryptImportPKCS8. the algorithm OID of the private key is used
  10885. // to look up the proper installable function to call.
  10886. //
  10887. // hCryptProv - the provider to import the key to
  10888. // pPrivateKeyInfo - describes the key to be imported
  10889. // dwFlags - The available flags are:
  10890. // CRYPT_EXPORTABLE
  10891. // this flag is used when importing private keys, for a full
  10892. // explanation please see the documentation for CryptImportKey.
  10893. // pvAuxInfo - reserved for future, must be NULL
  10894. //--------------------------------------------------------------------------
  10895. typedef BOOL (WINAPI *PFN_IMPORT_PRIV_KEY_FUNC) (
  10896. HCRYPTPROV hCryptProv, // in
  10897. CRYPT_PRIVATE_KEY_INFO *pPrivateKeyInfo, // in
  10898. DWORD dwFlags, // in, optional
  10899. void *pvAuxInfo // in, optional
  10900. );
  10901. #define CRYPT_OID_IMPORT_PRIVATE_KEY_INFO_FUNC "CryptDllImportPrivateKeyInfoEx"
  10902. //+-------------------------------------------------------------------------
  10903. // Convert (from PKCS8 format) and import the private key into a provider
  10904. // and return a handle to the provider as well as the KeySpec used to import to.
  10905. //
  10906. // This function will call the PRESOLVE_HCRYPTPROV_FUNC in the
  10907. // privateKeyAndParams to obtain a handle of provider to import the key to.
  10908. // if the PRESOLVE_HCRYPTPROV_FUNC is NULL then the default provider will be used.
  10909. //
  10910. // privateKeyAndParams - private key blob and corresponding parameters
  10911. // dwFlags - The available flags are:
  10912. // CRYPT_EXPORTABLE
  10913. // this flag is used when importing private keys, for a full
  10914. // explanation please see the documentation for CryptImportKey.
  10915. // phCryptProv - filled in with the handle of the provider the key was
  10916. // imported to, the caller is responsible for freeing it
  10917. // pvAuxInfo - This parameter is reserved for future use and should be set
  10918. // to NULL in the interim.
  10919. //--------------------------------------------------------------------------
  10920. WINCRYPT32API
  10921. BOOL
  10922. WINAPI
  10923. CryptImportPKCS8(
  10924. CRYPT_PKCS8_IMPORT_PARAMS sImportParams, // in
  10925. DWORD dwFlags, // in, optional
  10926. HCRYPTPROV *phCryptProv, // out, optional
  10927. void *pvAuxInfo // in, optional
  10928. );
  10929. //+-------------------------------------------------------------------------
  10930. // this is the prototype for installable functions for exporting the private key
  10931. //--------------------------------------------------------------------------
  10932. typedef BOOL (WINAPI *PFN_EXPORT_PRIV_KEY_FUNC) (
  10933. HCRYPTPROV hCryptProv, // in
  10934. DWORD dwKeySpec, // in
  10935. LPSTR pszPrivateKeyObjId, // in
  10936. DWORD dwFlags, // in
  10937. void *pvAuxInfo, // in
  10938. CRYPT_PRIVATE_KEY_INFO *pPrivateKeyInfo, // out
  10939. DWORD *pcbPrivateKeyBlob // in, out
  10940. );
  10941. #define CRYPT_OID_EXPORT_PRIVATE_KEY_INFO_FUNC "CryptDllExportPrivateKeyInfoEx"
  10942. #define CRYPT_DELETE_KEYSET 0x0001
  10943. //+-------------------------------------------------------------------------
  10944. // CryptExportPKCS8 -- superseded by CryptExportPKCS8Ex
  10945. //
  10946. // Export the private key in PKCS8 format
  10947. //--------------------------------------------------------------------------
  10948. WINCRYPT32API
  10949. BOOL
  10950. WINAPI
  10951. CryptExportPKCS8(
  10952. HCRYPTPROV hCryptProv, // in
  10953. DWORD dwKeySpec, // in
  10954. LPSTR pszPrivateKeyObjId, // in
  10955. DWORD dwFlags, // in
  10956. void *pvAuxInfo, // in
  10957. BYTE *pbPrivateKeyBlob, // out
  10958. DWORD *pcbPrivateKeyBlob // in, out
  10959. );
  10960. //+-------------------------------------------------------------------------
  10961. // CryptExportPKCS8Ex
  10962. //
  10963. // Export the private key in PKCS8 format
  10964. //
  10965. //
  10966. // Uses the pszPrivateKeyObjId to call the
  10967. // installable CRYPT_OID_EXPORT_PRIVATE_KEY_INFO_FUNC. The called function
  10968. // has the signature defined by PFN_EXPORT_PRIV_KEY_FUNC.
  10969. //
  10970. // If unable to find an installable OID function for the pszPrivateKeyObjId,
  10971. // attempts to export as a RSA Private Key (szOID_RSA_RSA).
  10972. //
  10973. // psExportParams - specifies information about the key to export
  10974. // dwFlags - The flag values. None currently supported
  10975. // pvAuxInfo - This parameter is reserved for future use and should be set to
  10976. // NULL in the interim.
  10977. // pbPrivateKeyBlob - A pointer to the private key blob. It will be encoded
  10978. // as a PKCS8 PrivateKeyInfo.
  10979. // pcbPrivateKeyBlob - A pointer to a DWORD that contains the size, in bytes,
  10980. // of the private key blob being exported.
  10981. //+-------------------------------------------------------------------------
  10982. WINCRYPT32API
  10983. BOOL
  10984. WINAPI
  10985. CryptExportPKCS8Ex(
  10986. CRYPT_PKCS8_EXPORT_PARAMS* psExportParams, // in
  10987. DWORD dwFlags, // in
  10988. void *pvAuxInfo, // in
  10989. BYTE *pbPrivateKeyBlob, // out
  10990. DWORD *pcbPrivateKeyBlob // in, out
  10991. );
  10992. //+-------------------------------------------------------------------------
  10993. // Compute the hash of the encoded public key info.
  10994. //
  10995. // The public key info is encoded and then hashed.
  10996. //--------------------------------------------------------------------------
  10997. WINCRYPT32API
  10998. BOOL
  10999. WINAPI
  11000. CryptHashPublicKeyInfo(
  11001. IN HCRYPTPROV hCryptProv,
  11002. IN ALG_ID Algid,
  11003. IN DWORD dwFlags,
  11004. IN DWORD dwCertEncodingType,
  11005. IN PCERT_PUBLIC_KEY_INFO pInfo,
  11006. OUT BYTE *pbComputedHash,
  11007. IN OUT DWORD *pcbComputedHash
  11008. );
  11009. //+-------------------------------------------------------------------------
  11010. // Convert a Name Value to a null terminated char string
  11011. //
  11012. // Returns the number of characters converted including the terminating null
  11013. // character. If psz is NULL or csz is 0, returns the required size of the
  11014. // destination string (including the terminating null char).
  11015. //
  11016. // If psz != NULL && csz != 0, returned psz is always NULL terminated.
  11017. //
  11018. // Note: csz includes the NULL char.
  11019. //--------------------------------------------------------------------------
  11020. WINCRYPT32API
  11021. DWORD
  11022. WINAPI
  11023. CertRDNValueToStrA(
  11024. IN DWORD dwValueType,
  11025. IN PCERT_RDN_VALUE_BLOB pValue,
  11026. OUT OPTIONAL LPSTR psz,
  11027. IN DWORD csz
  11028. );
  11029. //+-------------------------------------------------------------------------
  11030. // Convert a Name Value to a null terminated char string
  11031. //
  11032. // Returns the number of characters converted including the terminating null
  11033. // character. If psz is NULL or csz is 0, returns the required size of the
  11034. // destination string (including the terminating null char).
  11035. //
  11036. // If psz != NULL && csz != 0, returned psz is always NULL terminated.
  11037. //
  11038. // Note: csz includes the NULL char.
  11039. //--------------------------------------------------------------------------
  11040. WINCRYPT32API
  11041. DWORD
  11042. WINAPI
  11043. CertRDNValueToStrW(
  11044. IN DWORD dwValueType,
  11045. IN PCERT_RDN_VALUE_BLOB pValue,
  11046. OUT OPTIONAL LPWSTR psz,
  11047. IN DWORD csz
  11048. );
  11049. #ifdef UNICODE
  11050. #define CertRDNValueToStr CertRDNValueToStrW
  11051. #else
  11052. #define CertRDNValueToStr CertRDNValueToStrA
  11053. #endif // !UNICODE
  11054. //+-------------------------------------------------------------------------
  11055. // Convert the certificate name blob to a null terminated char string.
  11056. //
  11057. // Follows the string representation of distinguished names specified in
  11058. // RFC 1779. (Note, added double quoting "" for embedded quotes, quote
  11059. // empty strings and don't quote strings containing consecutive spaces).
  11060. // RDN values of type CERT_RDN_ENCODED_BLOB or CERT_RDN_OCTET_STRING are
  11061. // formatted in hexadecimal (e.g. #0A56CF).
  11062. //
  11063. // The name string is formatted according to the dwStrType:
  11064. // CERT_SIMPLE_NAME_STR
  11065. // The object identifiers are discarded. CERT_RDN entries are separated
  11066. // by ", ". Multiple attributes per CERT_RDN are separated by " + ".
  11067. // For example:
  11068. // Microsoft, Joe Cool + Programmer
  11069. // CERT_OID_NAME_STR
  11070. // The object identifiers are included with a "=" separator from their
  11071. // attribute value. CERT_RDN entries are separated by ", ".
  11072. // Multiple attributes per CERT_RDN are separated by " + ". For example:
  11073. // 2.5.4.11=Microsoft, 2.5.4.3=Joe Cool + 2.5.4.12=Programmer
  11074. // CERT_X500_NAME_STR
  11075. // The object identifiers are converted to their X500 key name. Otherwise,
  11076. // same as CERT_OID_NAME_STR. If the object identifier doesn't have
  11077. // a corresponding X500 key name, then, the object identifier is used with
  11078. // a "OID." prefix. For example:
  11079. // OU=Microsoft, CN=Joe Cool + T=Programmer, OID.1.2.3.4.5.6=Unknown
  11080. //
  11081. // We quote the RDN value if it contains leading or trailing whitespace
  11082. // or one of the following characters: ",", "+", "=", """, "\n", "<", ">",
  11083. // "#" or ";". The quoting character is ". If the the RDN Value contains
  11084. // a " it is double quoted (""). For example:
  11085. // OU=" Microsoft", CN="Joe ""Cool""" + T="Programmer, Manager"
  11086. //
  11087. // CERT_NAME_STR_SEMICOLON_FLAG can be or'ed into dwStrType to replace
  11088. // the ", " separator with a "; " separator.
  11089. //
  11090. // CERT_NAME_STR_CRLF_FLAG can be or'ed into dwStrType to replace
  11091. // the ", " separator with a "\r\n" separator.
  11092. //
  11093. // CERT_NAME_STR_NO_PLUS_FLAG can be or'ed into dwStrType to replace the
  11094. // " + " separator with a single space, " ".
  11095. //
  11096. // CERT_NAME_STR_NO_QUOTING_FLAG can be or'ed into dwStrType to inhibit
  11097. // the above quoting.
  11098. //
  11099. // CERT_NAME_STR_REVERSE_FLAG can be or'ed into dwStrType to reverse the
  11100. // order of the RDNs before converting to the string.
  11101. //
  11102. // By default, CERT_RDN_T61_STRING encoded values are initially decoded
  11103. // as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  11104. // CERT_NAME_STR_DISABLE_IE4_UTF8_FLAG can be or'ed into dwStrType to
  11105. // skip the initial attempt to decode as UTF8.
  11106. //
  11107. // Returns the number of characters converted including the terminating null
  11108. // character. If psz is NULL or csz is 0, returns the required size of the
  11109. // destination string (including the terminating null char).
  11110. //
  11111. // If psz != NULL && csz != 0, returned psz is always NULL terminated.
  11112. //
  11113. // Note: csz includes the NULL char.
  11114. //--------------------------------------------------------------------------
  11115. //+-------------------------------------------------------------------------
  11116. //--------------------------------------------------------------------------
  11117. WINCRYPT32API
  11118. DWORD
  11119. WINAPI
  11120. CertNameToStrA(
  11121. IN DWORD dwCertEncodingType,
  11122. IN PCERT_NAME_BLOB pName,
  11123. IN DWORD dwStrType,
  11124. OUT OPTIONAL LPSTR psz,
  11125. IN DWORD csz
  11126. );
  11127. //+-------------------------------------------------------------------------
  11128. //--------------------------------------------------------------------------
  11129. WINCRYPT32API
  11130. DWORD
  11131. WINAPI
  11132. CertNameToStrW(
  11133. IN DWORD dwCertEncodingType,
  11134. IN PCERT_NAME_BLOB pName,
  11135. IN DWORD dwStrType,
  11136. OUT OPTIONAL LPWSTR psz,
  11137. IN DWORD csz
  11138. );
  11139. #ifdef UNICODE
  11140. #define CertNameToStr CertNameToStrW
  11141. #else
  11142. #define CertNameToStr CertNameToStrA
  11143. #endif // !UNICODE
  11144. //+-------------------------------------------------------------------------
  11145. // Certificate name string types
  11146. //--------------------------------------------------------------------------
  11147. #define CERT_SIMPLE_NAME_STR 1
  11148. #define CERT_OID_NAME_STR 2
  11149. #define CERT_X500_NAME_STR 3
  11150. //+-------------------------------------------------------------------------
  11151. // Certificate name string type flags OR'ed with the above types
  11152. //--------------------------------------------------------------------------
  11153. #define CERT_NAME_STR_SEMICOLON_FLAG 0x40000000
  11154. #define CERT_NAME_STR_NO_PLUS_FLAG 0x20000000
  11155. #define CERT_NAME_STR_NO_QUOTING_FLAG 0x10000000
  11156. #define CERT_NAME_STR_CRLF_FLAG 0x08000000
  11157. #define CERT_NAME_STR_COMMA_FLAG 0x04000000
  11158. #define CERT_NAME_STR_REVERSE_FLAG 0x02000000
  11159. #define CERT_NAME_STR_DISABLE_IE4_UTF8_FLAG 0x00010000
  11160. #define CERT_NAME_STR_ENABLE_T61_UNICODE_FLAG 0x00020000
  11161. #define CERT_NAME_STR_ENABLE_UTF8_UNICODE_FLAG 0x00040000
  11162. //+-------------------------------------------------------------------------
  11163. // Convert the null terminated X500 string to an encoded certificate name.
  11164. //
  11165. // The input string is expected to be formatted the same as the output
  11166. // from the above CertNameToStr API.
  11167. //
  11168. // The CERT_SIMPLE_NAME_STR type isn't supported. Otherwise, when dwStrType
  11169. // is set to 0, CERT_OID_NAME_STR or CERT_X500_NAME_STR, allow either a
  11170. // case insensitive X500 key (CN=), case insensitive "OID." prefixed
  11171. // object identifier (OID.1.2.3.4.5.6=) or an object identifier (1.2.3.4=).
  11172. //
  11173. // If no flags are OR'ed into dwStrType, then, allow "," or ";" as RDN
  11174. // separators and "+" as the multiple RDN value separator. Quoting is
  11175. // supported. A quote may be included in a quoted value by double quoting,
  11176. // for example (CN="Joe ""Cool"""). A value starting with a "#" is treated
  11177. // as ascii hex and converted to a CERT_RDN_OCTET_STRING. Embedded whitespace
  11178. // is skipped (1.2.3 = # AB CD 01 is the same as 1.2.3=#ABCD01).
  11179. //
  11180. // Whitespace surrounding the keys, object identifers and values is removed.
  11181. //
  11182. // CERT_NAME_STR_COMMA_FLAG can be or'ed into dwStrType to only allow the
  11183. // "," as the RDN separator.
  11184. //
  11185. // CERT_NAME_STR_SEMICOLON_FLAG can be or'ed into dwStrType to only allow the
  11186. // ";" as the RDN separator.
  11187. //
  11188. // CERT_NAME_STR_CRLF_FLAG can be or'ed into dwStrType to only allow
  11189. // "\r" or "\n" as the RDN separator.
  11190. //
  11191. // CERT_NAME_STR_NO_PLUS_FLAG can be or'ed into dwStrType to ignore "+"
  11192. // as a separator and not allow multiple values per RDN.
  11193. //
  11194. // CERT_NAME_STR_NO_QUOTING_FLAG can be or'ed into dwStrType to inhibit
  11195. // quoting.
  11196. //
  11197. // CERT_NAME_STR_REVERSE_FLAG can be or'ed into dwStrType to reverse the
  11198. // order of the RDNs after converting from the string and before encoding.
  11199. //
  11200. // CERT_NAME_STR_ENABLE_T61_UNICODE_FLAG can be or'ed into dwStrType to
  11201. // to select the CERT_RDN_T61_STRING encoded value type instead of
  11202. // CERT_RDN_UNICODE_STRING if all the UNICODE characters are <= 0xFF.
  11203. //
  11204. // CERT_NAME_STR_ENABLE_UTF8_UNICODE_FLAG can be or'ed into dwStrType to
  11205. // to select the CERT_RDN_UTF8_STRING encoded value type instead of
  11206. // CERT_RDN_UNICODE_STRING.
  11207. //
  11208. // Support the following X500 Keys:
  11209. //
  11210. // Key Object Identifier RDN Value Type(s)
  11211. // --- ----------------- -----------------
  11212. // CN szOID_COMMON_NAME Printable, Unicode
  11213. // L szOID_LOCALITY_NAME Printable, Unicode
  11214. // O szOID_ORGANIZATION_NAME Printable, Unicode
  11215. // OU szOID_ORGANIZATIONAL_UNIT_NAME Printable, Unicode
  11216. // E szOID_RSA_emailAddr Only IA5
  11217. // Email szOID_RSA_emailAddr Only IA5
  11218. // C szOID_COUNTRY_NAME Only Printable
  11219. // S szOID_STATE_OR_PROVINCE_NAME Printable, Unicode
  11220. // ST szOID_STATE_OR_PROVINCE_NAME Printable, Unicode
  11221. // STREET szOID_STREET_ADDRESS Printable, Unicode
  11222. // T szOID_TITLE Printable, Unicode
  11223. // Title szOID_TITLE Printable, Unicode
  11224. // G szOID_GIVEN_NAME Printable, Unicode
  11225. // GivenName szOID_GIVEN_NAME Printable, Unicode
  11226. // I szOID_INITIALS Printable, Unicode
  11227. // Initials szOID_INITIALS Printable, Unicode
  11228. // SN szOID_SUR_NAME Printable, Unicode
  11229. // DC szOID_DOMAIN_COMPONENT IA5, UTF8
  11230. //
  11231. // Note, T61 is selected instead of Unicode if
  11232. // CERT_NAME_STR_ENABLE_T61_UNICODE_FLAG is set and all the unicode
  11233. // characters are <= 0xFF.
  11234. //
  11235. // Note, UTF8 is selected instead of Unicode if
  11236. // CERT_NAME_STR_ENABLE_UTF8_UNICODE_FLAG is set.
  11237. //
  11238. // Returns TRUE if successfully parsed the input string and encoded
  11239. // the name.
  11240. //
  11241. // If the input string is detected to be invalid, *ppszError is updated
  11242. // to point to the beginning of the invalid character sequence. Otherwise,
  11243. // *ppszError is set to NULL. *ppszError is updated with a non-NULL pointer
  11244. // for the following errors:
  11245. // CRYPT_E_INVALID_X500_STRING
  11246. // CRYPT_E_INVALID_NUMERIC_STRING
  11247. // CRYPT_E_INVALID_PRINTABLE_STRING
  11248. // CRYPT_E_INVALID_IA5_STRING
  11249. //
  11250. // ppszError can be set to NULL if not interested in getting a pointer
  11251. // to the invalid character sequence.
  11252. //--------------------------------------------------------------------------
  11253. //+-------------------------------------------------------------------------
  11254. //--------------------------------------------------------------------------
  11255. WINCRYPT32API
  11256. BOOL
  11257. WINAPI
  11258. CertStrToNameA(
  11259. IN DWORD dwCertEncodingType,
  11260. IN LPCSTR pszX500,
  11261. IN DWORD dwStrType,
  11262. IN OPTIONAL void *pvReserved,
  11263. OUT BYTE *pbEncoded,
  11264. IN OUT DWORD *pcbEncoded,
  11265. OUT OPTIONAL LPCSTR *ppszError
  11266. );
  11267. //+-------------------------------------------------------------------------
  11268. //--------------------------------------------------------------------------
  11269. WINCRYPT32API
  11270. BOOL
  11271. WINAPI
  11272. CertStrToNameW(
  11273. IN DWORD dwCertEncodingType,
  11274. IN LPCWSTR pszX500,
  11275. IN DWORD dwStrType,
  11276. IN OPTIONAL void *pvReserved,
  11277. OUT BYTE *pbEncoded,
  11278. IN OUT DWORD *pcbEncoded,
  11279. OUT OPTIONAL LPCWSTR *ppszError
  11280. );
  11281. #ifdef UNICODE
  11282. #define CertStrToName CertStrToNameW
  11283. #else
  11284. #define CertStrToName CertStrToNameA
  11285. #endif // !UNICODE
  11286. //+-------------------------------------------------------------------------
  11287. // Get the subject or issuer name from the certificate and
  11288. // according to the specified format type, convert to a null terminated
  11289. // character string.
  11290. //
  11291. // CERT_NAME_ISSUER_FLAG can be set to get the issuer's name. Otherwise,
  11292. // gets the subject's name.
  11293. //
  11294. // By default, CERT_RDN_T61_STRING encoded values are initially decoded
  11295. // as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  11296. // CERT_NAME_DISABLE_IE4_UTF8_FLAG can be set in dwFlags to
  11297. // skip the initial attempt to decode as UTF8.
  11298. //
  11299. // The name string is formatted according to the dwType:
  11300. // CERT_NAME_EMAIL_TYPE
  11301. // If the certificate has a Subject Alternative Name extension (for
  11302. // issuer, Issuer Alternative Name), searches for first rfc822Name choice.
  11303. // If the rfc822Name choice isn't found in the extension, searches the
  11304. // Subject Name field for the Email OID, "1.2.840.113549.1.9.1".
  11305. // If the rfc822Name or Email OID is found, returns the string. Otherwise,
  11306. // returns an empty string (returned character count is 1).
  11307. // CERT_NAME_DNS_TYPE
  11308. // If the certificate has a Subject Alternative Name extension (for
  11309. // issuer, Issuer Alternative Name), searches for first DNSName choice.
  11310. // If the DNSName choice isn't found in the extension, searches the
  11311. // Subject Name field for the CN OID, "2.5.4.3".
  11312. // If the DNSName or CN OID is found, returns the string. Otherwise,
  11313. // returns an empty string.
  11314. // CERT_NAME_URL_TYPE
  11315. // If the certificate has a Subject Alternative Name extension (for
  11316. // issuer, Issuer Alternative Name), searches for first URL choice.
  11317. // If the URL choice is found, returns the string. Otherwise,
  11318. // returns an empty string.
  11319. // CERT_NAME_UPN_TYPE
  11320. // If the certificate has a Subject Alternative Name extension,
  11321. // searches the OtherName choices looking for a
  11322. // pszObjId == szOID_NT_PRINCIPAL_NAME, "1.3.6.1.4.1.311.20.2.3".
  11323. // If the UPN OID is found, the blob is decoded as a
  11324. // X509_UNICODE_ANY_STRING and the decoded string is returned.
  11325. // Otherwise, returns an empty string.
  11326. // CERT_NAME_RDN_TYPE
  11327. // Converts the Subject Name blob by calling CertNameToStr. pvTypePara
  11328. // points to a DWORD containing the dwStrType passed to CertNameToStr.
  11329. // If the Subject Name field is empty and the certificate has a
  11330. // Subject Alternative Name extension, searches for and converts
  11331. // the first directoryName choice.
  11332. // CERT_NAME_ATTR_TYPE
  11333. // pvTypePara points to the Object Identifier specifying the name attribute
  11334. // to be returned. For example, to get the CN,
  11335. // pvTypePara = szOID_COMMON_NAME ("2.5.4.3"). Searches, the Subject Name
  11336. // field for the attribute.
  11337. // If the Subject Name field is empty and the certificate has a
  11338. // Subject Alternative Name extension, checks for
  11339. // the first directoryName choice and searches it.
  11340. //
  11341. // Note, searches the RDNs in reverse order.
  11342. //
  11343. // CERT_NAME_SIMPLE_DISPLAY_TYPE
  11344. // Iterates through the following list of name attributes and searches
  11345. // the Subject Name and then the Subject Alternative Name extension
  11346. // for the first occurrence of:
  11347. // szOID_COMMON_NAME ("2.5.4.3")
  11348. // szOID_ORGANIZATIONAL_UNIT_NAME ("2.5.4.11")
  11349. // szOID_ORGANIZATION_NAME ("2.5.4.10")
  11350. // szOID_RSA_emailAddr ("1.2.840.113549.1.9.1")
  11351. //
  11352. // If none of the above attributes is found, then, searches the
  11353. // Subject Alternative Name extension for a rfc822Name choice.
  11354. //
  11355. // If still no match, then, returns the first attribute.
  11356. //
  11357. // Note, like CERT_NAME_ATTR_TYPE, searches the RDNs in reverse order.
  11358. //
  11359. // CERT_NAME_FRIENDLY_DISPLAY_TYPE
  11360. // First checks if the certificate has a CERT_FRIENDLY_NAME_PROP_ID
  11361. // property. If it does, then, this property is returned. Otherwise,
  11362. // returns the above CERT_NAME_SIMPLE_DISPLAY_TYPE.
  11363. //
  11364. // Returns the number of characters converted including the terminating null
  11365. // character. If pwszNameString is NULL or cchNameString is 0, returns the
  11366. // required size of the destination string (including the terminating null
  11367. // char). If the specified name type isn't found. returns an empty string
  11368. // with a returned character count of 1.
  11369. //
  11370. // If pwszNameString != NULL && cwszNameString != 0, returned pwszNameString
  11371. // is always NULL terminated.
  11372. //
  11373. // Note: cchNameString includes the NULL char.
  11374. //--------------------------------------------------------------------------
  11375. //+-------------------------------------------------------------------------
  11376. //--------------------------------------------------------------------------
  11377. WINCRYPT32API
  11378. DWORD
  11379. WINAPI
  11380. CertGetNameStringA(
  11381. IN PCCERT_CONTEXT pCertContext,
  11382. IN DWORD dwType,
  11383. IN DWORD dwFlags,
  11384. IN void *pvTypePara,
  11385. OUT OPTIONAL LPSTR pszNameString,
  11386. IN DWORD cchNameString
  11387. );
  11388. //+-------------------------------------------------------------------------
  11389. //--------------------------------------------------------------------------
  11390. WINCRYPT32API
  11391. DWORD
  11392. WINAPI
  11393. CertGetNameStringW(
  11394. IN PCCERT_CONTEXT pCertContext,
  11395. IN DWORD dwType,
  11396. IN DWORD dwFlags,
  11397. IN void *pvTypePara,
  11398. OUT OPTIONAL LPWSTR pszNameString,
  11399. IN DWORD cchNameString
  11400. );
  11401. #ifdef UNICODE
  11402. #define CertGetNameString CertGetNameStringW
  11403. #else
  11404. #define CertGetNameString CertGetNameStringA
  11405. #endif // !UNICODE
  11406. //+-------------------------------------------------------------------------
  11407. // Certificate name types
  11408. //--------------------------------------------------------------------------
  11409. #define CERT_NAME_EMAIL_TYPE 1
  11410. #define CERT_NAME_RDN_TYPE 2
  11411. #define CERT_NAME_ATTR_TYPE 3
  11412. #define CERT_NAME_SIMPLE_DISPLAY_TYPE 4
  11413. #define CERT_NAME_FRIENDLY_DISPLAY_TYPE 5
  11414. #define CERT_NAME_DNS_TYPE 6
  11415. #define CERT_NAME_URL_TYPE 7
  11416. #define CERT_NAME_UPN_TYPE 8
  11417. //+-------------------------------------------------------------------------
  11418. // Certificate name flags
  11419. //--------------------------------------------------------------------------
  11420. #define CERT_NAME_ISSUER_FLAG 0x1
  11421. #define CERT_NAME_DISABLE_IE4_UTF8_FLAG 0x00010000
  11422. //+=========================================================================
  11423. // Simplified Cryptographic Message Data Structures and APIs
  11424. //==========================================================================
  11425. //+-------------------------------------------------------------------------
  11426. // Conventions for the *pb and *pcb output parameters:
  11427. //
  11428. // Upon entry to the function:
  11429. // if pcb is OPTIONAL && pcb == NULL, then,
  11430. // No output is returned
  11431. // else if pb == NULL && pcb != NULL, then,
  11432. // Length only determination. No length error is
  11433. // returned.
  11434. // otherwise where (pb != NULL && pcb != NULL && *pcb != 0)
  11435. // Output is returned. If *pcb isn't big enough a
  11436. // length error is returned. In all cases *pcb is updated
  11437. // with the actual length needed/returned.
  11438. //--------------------------------------------------------------------------
  11439. //+-------------------------------------------------------------------------
  11440. // Type definitions of the parameters used for doing the cryptographic
  11441. // operations.
  11442. //--------------------------------------------------------------------------
  11443. //+-------------------------------------------------------------------------
  11444. // Callback to get and verify the signer's certificate.
  11445. //
  11446. // Passed the CertId of the signer (its Issuer and SerialNumber) and a
  11447. // handle to its cryptographic signed message's cert store.
  11448. //
  11449. // For CRYPT_E_NO_SIGNER, called with pSignerId == NULL.
  11450. //
  11451. // For a valid signer certificate, returns a pointer to a read only
  11452. // CERT_CONTEXT. The returned CERT_CONTEXT is either obtained from a
  11453. // cert store or was created via CertCreateCertificateContext. For either case,
  11454. // its freed via CertFreeCertificateContext.
  11455. //
  11456. // If a valid certificate isn't found, this callback returns NULL with
  11457. // LastError set via SetLastError().
  11458. //
  11459. // The NULL implementation tries to get the Signer certificate from the
  11460. // message cert store. It doesn't verify the certificate.
  11461. //
  11462. // Note, if the KEYID choice was selected for a CMS SignerId, then, the
  11463. // SerialNumber is 0 and the Issuer is encoded containing a single RDN with a
  11464. // single Attribute whose OID is szOID_KEYID_RDN, value type is
  11465. // CERT_RDN_OCTET_STRING and value is the KEYID. When the
  11466. // CertGetSubjectCertificateFromStore and
  11467. // CertFindCertificateInStore(CERT_FIND_SUBJECT_CERT) APIs see this
  11468. // special KEYID Issuer and SerialNumber, they do a KEYID match.
  11469. //--------------------------------------------------------------------------
  11470. typedef PCCERT_CONTEXT (WINAPI *PFN_CRYPT_GET_SIGNER_CERTIFICATE)(
  11471. IN void *pvGetArg,
  11472. IN DWORD dwCertEncodingType,
  11473. IN PCERT_INFO pSignerId, // Only the Issuer and SerialNumber
  11474. // fields have been updated
  11475. IN HCERTSTORE hMsgCertStore
  11476. );
  11477. //+-------------------------------------------------------------------------
  11478. // The CRYPT_SIGN_MESSAGE_PARA are used for signing messages using the
  11479. // specified signing certificate context.
  11480. //
  11481. // Either the CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_PROV_INFO_PROP_ID must
  11482. // be set for each rgpSigningCert[]. Either one specifies the private
  11483. // signature key to use.
  11484. //
  11485. // If any certificates and/or CRLs are to be included in the signed message,
  11486. // then, the MsgCert and MsgCrl parameters need to be updated. If the
  11487. // rgpSigningCerts are to be included, then, they must also be in the
  11488. // rgpMsgCert array.
  11489. //
  11490. // cbSize must be set to the sizeof(CRYPT_SIGN_MESSAGE_PARA) or else
  11491. // LastError will be updated with E_INVALIDARG.
  11492. //
  11493. // pvHashAuxInfo currently isn't used and must be set to NULL.
  11494. //
  11495. // dwFlags normally is set to 0. However, if the encoded output
  11496. // is to be a CMSG_SIGNED inner content of an outer cryptographic message,
  11497. // such as a CMSG_ENVELOPED, then, the CRYPT_MESSAGE_BARE_CONTENT_OUT_FLAG
  11498. // should be set. If not set, then it would be encoded as an inner content
  11499. // type of CMSG_DATA.
  11500. //
  11501. // dwInnerContentType is normally set to 0. It needs to be set if the
  11502. // ToBeSigned input is the encoded output of another cryptographic
  11503. // message, such as, an CMSG_ENVELOPED. When set, it's one of the cryptographic
  11504. // message types, for example, CMSG_ENVELOPED.
  11505. //
  11506. // If the inner content of a nested cryptographic message is data (CMSG_DATA
  11507. // the default), then, neither dwFlags or dwInnerContentType need to be set.
  11508. //
  11509. // For CMS messages, CRYPT_MESSAGE_ENCAPSULATED_CONTENT_OUT_FLAG may be
  11510. // set to encapsulate nonData inner content within an OCTET STRING.
  11511. //
  11512. // For CMS messages, CRYPT_MESSAGE_KEYID_SIGNER_FLAG may be set to identify
  11513. // signers by their Key Identifier and not their Issuer and Serial Number.
  11514. //
  11515. // The CRYPT_MESSAGE_SILENT_KEYSET_FLAG can be set to suppress any UI by the
  11516. // CSP. See CryptAcquireContext's CRYPT_SILENT flag for more details.
  11517. //
  11518. // If HashEncryptionAlgorithm is present and not NULL its used instead of
  11519. // the SigningCert's PublicKeyInfo.Algorithm.
  11520. //
  11521. // Note, for RSA, the hash encryption algorithm is normally the same as
  11522. // the public key algorithm. For DSA, the hash encryption algorithm is
  11523. // normally a DSS signature algorithm.
  11524. //
  11525. // pvHashEncryptionAuxInfo currently isn't used and must be set to NULL if
  11526. // present in the data structure.
  11527. //--------------------------------------------------------------------------
  11528. typedef struct _CRYPT_SIGN_MESSAGE_PARA {
  11529. DWORD cbSize;
  11530. DWORD dwMsgEncodingType;
  11531. PCCERT_CONTEXT pSigningCert;
  11532. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  11533. void *pvHashAuxInfo;
  11534. DWORD cMsgCert;
  11535. PCCERT_CONTEXT *rgpMsgCert;
  11536. DWORD cMsgCrl;
  11537. PCCRL_CONTEXT *rgpMsgCrl;
  11538. DWORD cAuthAttr;
  11539. PCRYPT_ATTRIBUTE rgAuthAttr;
  11540. DWORD cUnauthAttr;
  11541. PCRYPT_ATTRIBUTE rgUnauthAttr;
  11542. DWORD dwFlags;
  11543. DWORD dwInnerContentType;
  11544. #ifdef CRYPT_SIGN_MESSAGE_PARA_HAS_CMS_FIELDS
  11545. CRYPT_ALGORITHM_IDENTIFIER HashEncryptionAlgorithm;
  11546. void *pvHashEncryptionAuxInfo;
  11547. #endif
  11548. } CRYPT_SIGN_MESSAGE_PARA, *PCRYPT_SIGN_MESSAGE_PARA;
  11549. #define CRYPT_MESSAGE_BARE_CONTENT_OUT_FLAG 0x00000001
  11550. // When set, nonData type inner content is encapsulated within an
  11551. // OCTET STRING
  11552. #define CRYPT_MESSAGE_ENCAPSULATED_CONTENT_OUT_FLAG 0x00000002
  11553. // When set, signers are identified by their Key Identifier and not
  11554. // their Issuer and Serial Number.
  11555. #define CRYPT_MESSAGE_KEYID_SIGNER_FLAG 0x00000004
  11556. // When set, suppresses any UI by the CSP.
  11557. // See CryptAcquireContext's CRYPT_SILENT flag for more details.
  11558. #define CRYPT_MESSAGE_SILENT_KEYSET_FLAG 0x00000040
  11559. //+-------------------------------------------------------------------------
  11560. // The CRYPT_VERIFY_MESSAGE_PARA are used to verify signed messages.
  11561. //
  11562. // hCryptProv is used to do hashing and signature verification.
  11563. //
  11564. // The dwCertEncodingType specifies the encoding type of the certificates
  11565. // and/or CRLs in the message.
  11566. //
  11567. // pfnGetSignerCertificate is called to get and verify the message signer's
  11568. // certificate.
  11569. //
  11570. // cbSize must be set to the sizeof(CRYPT_VERIFY_MESSAGE_PARA) or else
  11571. // LastError will be updated with E_INVALIDARG.
  11572. //--------------------------------------------------------------------------
  11573. typedef struct _CRYPT_VERIFY_MESSAGE_PARA {
  11574. DWORD cbSize;
  11575. DWORD dwMsgAndCertEncodingType;
  11576. HCRYPTPROV hCryptProv;
  11577. PFN_CRYPT_GET_SIGNER_CERTIFICATE pfnGetSignerCertificate;
  11578. void *pvGetArg;
  11579. } CRYPT_VERIFY_MESSAGE_PARA, *PCRYPT_VERIFY_MESSAGE_PARA;
  11580. //+-------------------------------------------------------------------------
  11581. // The CRYPT_ENCRYPT_MESSAGE_PARA are used for encrypting messages.
  11582. //
  11583. // hCryptProv is used to do content encryption, recipient key
  11584. // encryption, and recipient key export. Its private key
  11585. // isn't used.
  11586. //
  11587. // Currently, pvEncryptionAuxInfo is only defined for RC2 or RC4 encryption
  11588. // algorithms. Otherwise, its not used and must be set to NULL.
  11589. // See CMSG_RC2_AUX_INFO for the RC2 encryption algorithms.
  11590. // See CMSG_RC4_AUX_INFO for the RC4 encryption algorithms.
  11591. //
  11592. // To enable SP3 compatible encryption, pvEncryptionAuxInfo should point to
  11593. // a CMSG_SP3_COMPATIBLE_AUX_INFO data structure.
  11594. //
  11595. // cbSize must be set to the sizeof(CRYPT_ENCRYPT_MESSAGE_PARA) or else
  11596. // LastError will be updated with E_INVALIDARG.
  11597. //
  11598. // dwFlags normally is set to 0. However, if the encoded output
  11599. // is to be a CMSG_ENVELOPED inner content of an outer cryptographic message,
  11600. // such as a CMSG_SIGNED, then, the CRYPT_MESSAGE_BARE_CONTENT_OUT_FLAG
  11601. // should be set. If not set, then it would be encoded as an inner content
  11602. // type of CMSG_DATA.
  11603. //
  11604. // dwInnerContentType is normally set to 0. It needs to be set if the
  11605. // ToBeEncrypted input is the encoded output of another cryptographic
  11606. // message, such as, an CMSG_SIGNED. When set, it's one of the cryptographic
  11607. // message types, for example, CMSG_SIGNED.
  11608. //
  11609. // If the inner content of a nested cryptographic message is data (CMSG_DATA
  11610. // the default), then, neither dwFlags or dwInnerContentType need to be set.
  11611. //
  11612. // For CMS messages, CRYPT_MESSAGE_ENCAPSULATED_CONTENT_OUT_FLAG may be
  11613. // set to encapsulate nonData inner content within an OCTET STRING before
  11614. // encrypting.
  11615. //
  11616. // For CMS messages, CRYPT_MESSAGE_KEYID_RECIPIENT_FLAG may be set to identify
  11617. // recipients by their Key Identifier and not their Issuer and Serial Number.
  11618. //--------------------------------------------------------------------------
  11619. typedef struct _CRYPT_ENCRYPT_MESSAGE_PARA {
  11620. DWORD cbSize;
  11621. DWORD dwMsgEncodingType;
  11622. HCRYPTPROV hCryptProv;
  11623. CRYPT_ALGORITHM_IDENTIFIER ContentEncryptionAlgorithm;
  11624. void *pvEncryptionAuxInfo;
  11625. DWORD dwFlags;
  11626. DWORD dwInnerContentType;
  11627. } CRYPT_ENCRYPT_MESSAGE_PARA, *PCRYPT_ENCRYPT_MESSAGE_PARA;
  11628. // When set, recipients are identified by their Key Identifier and not
  11629. // their Issuer and Serial Number.
  11630. #define CRYPT_MESSAGE_KEYID_RECIPIENT_FLAG 0x4
  11631. //+-------------------------------------------------------------------------
  11632. // The CRYPT_DECRYPT_MESSAGE_PARA are used for decrypting messages.
  11633. //
  11634. // The CertContext to use for decrypting a message is obtained from one
  11635. // of the specified cert stores. An encrypted message can have one or
  11636. // more recipients. The recipients are identified by their CertId (Issuer
  11637. // and SerialNumber). The cert stores are searched to find the CertContext
  11638. // corresponding to the CertId.
  11639. //
  11640. // For CMS, the recipients may also be identified by their KeyId.
  11641. // CMS also allows Key Agreement (Diffie Hellman) in addition to
  11642. // Key Transport (RSA) recipients.
  11643. //
  11644. // Only CertContexts in the store with either
  11645. // the CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_PROV_INFO_PROP_ID set
  11646. // can be used. Either property specifies the private exchange key to use.
  11647. //
  11648. // cbSize must be set to the sizeof(CRYPT_DECRYPT_MESSAGE_PARA) or else
  11649. // LastError will be updated with E_INVALIDARG.
  11650. //--------------------------------------------------------------------------
  11651. typedef struct _CRYPT_DECRYPT_MESSAGE_PARA {
  11652. DWORD cbSize;
  11653. DWORD dwMsgAndCertEncodingType;
  11654. DWORD cCertStore;
  11655. HCERTSTORE *rghCertStore;
  11656. #ifdef CRYPT_DECRYPT_MESSAGE_PARA_HAS_EXTRA_FIELDS
  11657. // The above defined, CRYPT_MESSAGE_SILENT_KEYSET_FLAG, can be set to
  11658. // suppress UI by the CSP. See CryptAcquireContext's CRYPT_SILENT
  11659. // flag for more details.
  11660. DWORD dwFlags;
  11661. #endif
  11662. } CRYPT_DECRYPT_MESSAGE_PARA, *PCRYPT_DECRYPT_MESSAGE_PARA;
  11663. //+-------------------------------------------------------------------------
  11664. // The CRYPT_HASH_MESSAGE_PARA are used for hashing or unhashing
  11665. // messages.
  11666. //
  11667. // hCryptProv is used to compute the hash.
  11668. //
  11669. // pvHashAuxInfo currently isn't used and must be set to NULL.
  11670. //
  11671. // cbSize must be set to the sizeof(CRYPT_HASH_MESSAGE_PARA) or else
  11672. // LastError will be updated with E_INVALIDARG.
  11673. //--------------------------------------------------------------------------
  11674. typedef struct _CRYPT_HASH_MESSAGE_PARA {
  11675. DWORD cbSize;
  11676. DWORD dwMsgEncodingType;
  11677. HCRYPTPROV hCryptProv;
  11678. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  11679. void *pvHashAuxInfo;
  11680. } CRYPT_HASH_MESSAGE_PARA, *PCRYPT_HASH_MESSAGE_PARA;
  11681. //+-------------------------------------------------------------------------
  11682. // The CRYPT_KEY_SIGN_MESSAGE_PARA are used for signing messages until a
  11683. // certificate has been created for the signature key.
  11684. //
  11685. // pvHashAuxInfo currently isn't used and must be set to NULL.
  11686. //
  11687. // If PubKeyAlgorithm isn't set, defaults to szOID_RSA_RSA.
  11688. //
  11689. // cbSize must be set to the sizeof(CRYPT_KEY_SIGN_MESSAGE_PARA) or else
  11690. // LastError will be updated with E_INVALIDARG.
  11691. //--------------------------------------------------------------------------
  11692. typedef struct _CRYPT_KEY_SIGN_MESSAGE_PARA {
  11693. DWORD cbSize;
  11694. DWORD dwMsgAndCertEncodingType;
  11695. HCRYPTPROV hCryptProv;
  11696. DWORD dwKeySpec;
  11697. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  11698. void *pvHashAuxInfo;
  11699. CRYPT_ALGORITHM_IDENTIFIER PubKeyAlgorithm;
  11700. } CRYPT_KEY_SIGN_MESSAGE_PARA, *PCRYPT_KEY_SIGN_MESSAGE_PARA;
  11701. //+-------------------------------------------------------------------------
  11702. // The CRYPT_KEY_VERIFY_MESSAGE_PARA are used to verify signed messages without
  11703. // a certificate for the signer.
  11704. //
  11705. // Normally used until a certificate has been created for the key.
  11706. //
  11707. // hCryptProv is used to do hashing and signature verification.
  11708. //
  11709. // cbSize must be set to the sizeof(CRYPT_KEY_VERIFY_MESSAGE_PARA) or else
  11710. // LastError will be updated with E_INVALIDARG.
  11711. //--------------------------------------------------------------------------
  11712. typedef struct _CRYPT_KEY_VERIFY_MESSAGE_PARA {
  11713. DWORD cbSize;
  11714. DWORD dwMsgEncodingType;
  11715. HCRYPTPROV hCryptProv;
  11716. } CRYPT_KEY_VERIFY_MESSAGE_PARA, *PCRYPT_KEY_VERIFY_MESSAGE_PARA;
  11717. //+-------------------------------------------------------------------------
  11718. // Sign the message.
  11719. //
  11720. // If fDetachedSignature is TRUE, the "to be signed" content isn't included
  11721. // in the encoded signed blob.
  11722. //--------------------------------------------------------------------------
  11723. WINCRYPT32API
  11724. BOOL
  11725. WINAPI
  11726. CryptSignMessage(
  11727. IN PCRYPT_SIGN_MESSAGE_PARA pSignPara,
  11728. IN BOOL fDetachedSignature,
  11729. IN DWORD cToBeSigned,
  11730. IN const BYTE *rgpbToBeSigned[],
  11731. IN DWORD rgcbToBeSigned[],
  11732. OUT BYTE *pbSignedBlob,
  11733. IN OUT DWORD *pcbSignedBlob
  11734. );
  11735. //+-------------------------------------------------------------------------
  11736. // Verify a signed message.
  11737. //
  11738. // If pbDecoded == NULL, then, *pcbDecoded is implicitly set to 0 on input.
  11739. // For *pcbDecoded == 0 && ppSignerCert == NULL on input, the signer isn't
  11740. // verified.
  11741. //
  11742. // A message might have more than one signer. Set dwSignerIndex to iterate
  11743. // through all the signers. dwSignerIndex == 0 selects the first signer.
  11744. //
  11745. // pVerifyPara's pfnGetSignerCertificate is called to get the signer's
  11746. // certificate.
  11747. //
  11748. // For a verified signer and message, *ppSignerCert is updated
  11749. // with the CertContext of the signer. It must be freed by calling
  11750. // CertFreeCertificateContext. Otherwise, *ppSignerCert is set to NULL.
  11751. //
  11752. // ppSignerCert can be NULL, indicating the caller isn't interested
  11753. // in getting the CertContext of the signer.
  11754. //
  11755. // pcbDecoded can be NULL, indicating the caller isn't interested in getting
  11756. // the decoded content. Furthermore, if the message doesn't contain any
  11757. // content or signers, then, pcbDecoded must be set to NULL, to allow the
  11758. // pVerifyPara->pfnGetCertificate to be called. Normally, this would be
  11759. // the case when the signed message contains only certficates and CRLs.
  11760. // If pcbDecoded is NULL and the message doesn't have the indicated signer,
  11761. // pfnGetCertificate is called with pSignerId set to NULL.
  11762. //
  11763. // If the message doesn't contain any signers || dwSignerIndex > message's
  11764. // SignerCount, then, an error is returned with LastError set to
  11765. // CRYPT_E_NO_SIGNER. Also, for CRYPT_E_NO_SIGNER, pfnGetSignerCertificate
  11766. // is still called with pSignerId set to NULL.
  11767. //
  11768. // Note, an alternative way to get the certificates and CRLs from a
  11769. // signed message is to call CryptGetMessageCertificates.
  11770. //--------------------------------------------------------------------------
  11771. WINCRYPT32API
  11772. BOOL
  11773. WINAPI
  11774. CryptVerifyMessageSignature(
  11775. IN PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara,
  11776. IN DWORD dwSignerIndex,
  11777. IN const BYTE *pbSignedBlob,
  11778. IN DWORD cbSignedBlob,
  11779. OUT BYTE OPTIONAL *pbDecoded,
  11780. IN OUT OPTIONAL DWORD *pcbDecoded,
  11781. OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert
  11782. );
  11783. //+-------------------------------------------------------------------------
  11784. // Returns the count of signers in the signed message. For no signers, returns
  11785. // 0. For an error returns -1 with LastError updated accordingly.
  11786. //--------------------------------------------------------------------------
  11787. WINCRYPT32API
  11788. LONG
  11789. WINAPI
  11790. CryptGetMessageSignerCount(
  11791. IN DWORD dwMsgEncodingType,
  11792. IN const BYTE *pbSignedBlob,
  11793. IN DWORD cbSignedBlob
  11794. );
  11795. //+-------------------------------------------------------------------------
  11796. // Returns the cert store containing the message's certs and CRLs.
  11797. // For an error, returns NULL with LastError updated.
  11798. //--------------------------------------------------------------------------
  11799. WINCRYPT32API
  11800. HCERTSTORE
  11801. WINAPI
  11802. CryptGetMessageCertificates(
  11803. IN DWORD dwMsgAndCertEncodingType,
  11804. IN HCRYPTPROV hCryptProv, // passed to CertOpenStore
  11805. IN DWORD dwFlags, // passed to CertOpenStore
  11806. IN const BYTE *pbSignedBlob,
  11807. IN DWORD cbSignedBlob
  11808. );
  11809. //+-------------------------------------------------------------------------
  11810. // Verify a signed message containing detached signature(s).
  11811. // The "to be signed" content is passed in separately. No
  11812. // decoded output. Otherwise, identical to CryptVerifyMessageSignature.
  11813. //--------------------------------------------------------------------------
  11814. WINCRYPT32API
  11815. BOOL
  11816. WINAPI
  11817. CryptVerifyDetachedMessageSignature(
  11818. IN PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara,
  11819. IN DWORD dwSignerIndex,
  11820. IN const BYTE *pbDetachedSignBlob,
  11821. IN DWORD cbDetachedSignBlob,
  11822. IN DWORD cToBeSigned,
  11823. IN const BYTE *rgpbToBeSigned[],
  11824. IN DWORD rgcbToBeSigned[],
  11825. OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert
  11826. );
  11827. //+-------------------------------------------------------------------------
  11828. // Encrypts the message for the recipient(s).
  11829. //--------------------------------------------------------------------------
  11830. WINCRYPT32API
  11831. BOOL
  11832. WINAPI
  11833. CryptEncryptMessage(
  11834. IN PCRYPT_ENCRYPT_MESSAGE_PARA pEncryptPara,
  11835. IN DWORD cRecipientCert,
  11836. IN PCCERT_CONTEXT rgpRecipientCert[],
  11837. IN const BYTE *pbToBeEncrypted,
  11838. IN DWORD cbToBeEncrypted,
  11839. OUT BYTE *pbEncryptedBlob,
  11840. IN OUT DWORD *pcbEncryptedBlob
  11841. );
  11842. //+-------------------------------------------------------------------------
  11843. // Decrypts the message.
  11844. //
  11845. // If pbDecrypted == NULL, then, *pcbDecrypted is implicitly set to 0 on input.
  11846. // For *pcbDecrypted == 0 && ppXchgCert == NULL on input, the message isn't
  11847. // decrypted.
  11848. //
  11849. // For a successfully decrypted message, *ppXchgCert is updated
  11850. // with the CertContext used to decrypt. It must be freed by calling
  11851. // CertStoreFreeCert. Otherwise, *ppXchgCert is set to NULL.
  11852. //
  11853. // ppXchgCert can be NULL, indicating the caller isn't interested
  11854. // in getting the CertContext used to decrypt.
  11855. //--------------------------------------------------------------------------
  11856. WINCRYPT32API
  11857. BOOL
  11858. WINAPI
  11859. CryptDecryptMessage(
  11860. IN PCRYPT_DECRYPT_MESSAGE_PARA pDecryptPara,
  11861. IN const BYTE *pbEncryptedBlob,
  11862. IN DWORD cbEncryptedBlob,
  11863. OUT OPTIONAL BYTE *pbDecrypted,
  11864. IN OUT OPTIONAL DWORD *pcbDecrypted,
  11865. OUT OPTIONAL PCCERT_CONTEXT *ppXchgCert
  11866. );
  11867. //+-------------------------------------------------------------------------
  11868. // Sign the message and encrypt for the recipient(s). Does a CryptSignMessage
  11869. // followed with a CryptEncryptMessage.
  11870. //
  11871. // Note: this isn't the CMSG_SIGNED_AND_ENVELOPED. Its a CMSG_SIGNED
  11872. // inside of an CMSG_ENVELOPED.
  11873. //--------------------------------------------------------------------------
  11874. WINCRYPT32API
  11875. BOOL
  11876. WINAPI
  11877. CryptSignAndEncryptMessage(
  11878. IN PCRYPT_SIGN_MESSAGE_PARA pSignPara,
  11879. IN PCRYPT_ENCRYPT_MESSAGE_PARA pEncryptPara,
  11880. IN DWORD cRecipientCert,
  11881. IN PCCERT_CONTEXT rgpRecipientCert[],
  11882. IN const BYTE *pbToBeSignedAndEncrypted,
  11883. IN DWORD cbToBeSignedAndEncrypted,
  11884. OUT BYTE *pbSignedAndEncryptedBlob,
  11885. IN OUT DWORD *pcbSignedAndEncryptedBlob
  11886. );
  11887. //+-------------------------------------------------------------------------
  11888. // Decrypts the message and verifies the signer. Does a CryptDecryptMessage
  11889. // followed with a CryptVerifyMessageSignature.
  11890. //
  11891. // If pbDecrypted == NULL, then, *pcbDecrypted is implicitly set to 0 on input.
  11892. // For *pcbDecrypted == 0 && ppSignerCert == NULL on input, the signer isn't
  11893. // verified.
  11894. //
  11895. // A message might have more than one signer. Set dwSignerIndex to iterate
  11896. // through all the signers. dwSignerIndex == 0 selects the first signer.
  11897. //
  11898. // The pVerifyPara's VerifySignerPolicy is called to verify the signer's
  11899. // certificate.
  11900. //
  11901. // For a successfully decrypted and verified message, *ppXchgCert and
  11902. // *ppSignerCert are updated. They must be freed by calling
  11903. // CertStoreFreeCert. Otherwise, they are set to NULL.
  11904. //
  11905. // ppXchgCert and/or ppSignerCert can be NULL, indicating the
  11906. // caller isn't interested in getting the CertContext.
  11907. //
  11908. // Note: this isn't the CMSG_SIGNED_AND_ENVELOPED. Its a CMSG_SIGNED
  11909. // inside of an CMSG_ENVELOPED.
  11910. //
  11911. // The message always needs to be decrypted to allow access to the
  11912. // signed message. Therefore, if ppXchgCert != NULL, its always updated.
  11913. //--------------------------------------------------------------------------
  11914. WINCRYPT32API
  11915. BOOL
  11916. WINAPI
  11917. CryptDecryptAndVerifyMessageSignature(
  11918. IN PCRYPT_DECRYPT_MESSAGE_PARA pDecryptPara,
  11919. IN PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara,
  11920. IN DWORD dwSignerIndex,
  11921. IN const BYTE *pbEncryptedBlob,
  11922. IN DWORD cbEncryptedBlob,
  11923. OUT OPTIONAL BYTE *pbDecrypted,
  11924. IN OUT OPTIONAL DWORD *pcbDecrypted,
  11925. OUT OPTIONAL PCCERT_CONTEXT *ppXchgCert,
  11926. OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert
  11927. );
  11928. //+-------------------------------------------------------------------------
  11929. // Decodes a cryptographic message which may be one of the following types:
  11930. // CMSG_DATA
  11931. // CMSG_SIGNED
  11932. // CMSG_ENVELOPED
  11933. // CMSG_SIGNED_AND_ENVELOPED
  11934. // CMSG_HASHED
  11935. //
  11936. // dwMsgTypeFlags specifies the set of allowable messages. For example, to
  11937. // decode either SIGNED or ENVELOPED messages, set dwMsgTypeFlags to:
  11938. // CMSG_SIGNED_FLAG | CMSG_ENVELOPED_FLAG.
  11939. //
  11940. // dwProvInnerContentType is only applicable when processing nested
  11941. // crytographic messages. When processing an outer crytographic message
  11942. // it must be set to 0. When decoding a nested cryptographic message
  11943. // its the dwInnerContentType returned by a previous CryptDecodeMessage
  11944. // of the outer message. The InnerContentType can be any of the CMSG types,
  11945. // for example, CMSG_DATA, CMSG_SIGNED, ...
  11946. //
  11947. // The optional *pdwMsgType is updated with the type of message.
  11948. //
  11949. // The optional *pdwInnerContentType is updated with the type of the inner
  11950. // message. Unless there is cryptographic message nesting, CMSG_DATA
  11951. // is returned.
  11952. //
  11953. // For CMSG_DATA: returns decoded content.
  11954. // For CMSG_SIGNED: same as CryptVerifyMessageSignature.
  11955. // For CMSG_ENVELOPED: same as CryptDecryptMessage.
  11956. // For CMSG_SIGNED_AND_ENVELOPED: same as CryptDecryptMessage plus
  11957. // CryptVerifyMessageSignature.
  11958. // For CMSG_HASHED: verifies the hash and returns decoded content.
  11959. //--------------------------------------------------------------------------
  11960. WINCRYPT32API
  11961. BOOL
  11962. WINAPI
  11963. CryptDecodeMessage(
  11964. IN DWORD dwMsgTypeFlags,
  11965. IN PCRYPT_DECRYPT_MESSAGE_PARA pDecryptPara,
  11966. IN PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara,
  11967. IN DWORD dwSignerIndex,
  11968. IN const BYTE *pbEncodedBlob,
  11969. IN DWORD cbEncodedBlob,
  11970. IN DWORD dwPrevInnerContentType,
  11971. OUT OPTIONAL DWORD *pdwMsgType,
  11972. OUT OPTIONAL DWORD *pdwInnerContentType,
  11973. OUT OPTIONAL BYTE *pbDecoded,
  11974. IN OUT OPTIONAL DWORD *pcbDecoded,
  11975. OUT OPTIONAL PCCERT_CONTEXT *ppXchgCert,
  11976. OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert
  11977. );
  11978. //+-------------------------------------------------------------------------
  11979. // Hash the message.
  11980. //
  11981. // If fDetachedHash is TRUE, only the ComputedHash is encoded in the
  11982. // pbHashedBlob. Otherwise, both the ToBeHashed and ComputedHash
  11983. // are encoded.
  11984. //
  11985. // pcbHashedBlob or pcbComputedHash can be NULL, indicating the caller
  11986. // isn't interested in getting the output.
  11987. //--------------------------------------------------------------------------
  11988. WINCRYPT32API
  11989. BOOL
  11990. WINAPI
  11991. CryptHashMessage(
  11992. IN PCRYPT_HASH_MESSAGE_PARA pHashPara,
  11993. IN BOOL fDetachedHash,
  11994. IN DWORD cToBeHashed,
  11995. IN const BYTE *rgpbToBeHashed[],
  11996. IN DWORD rgcbToBeHashed[],
  11997. OUT OPTIONAL BYTE *pbHashedBlob,
  11998. IN OUT OPTIONAL DWORD *pcbHashedBlob,
  11999. OUT OPTIONAL BYTE *pbComputedHash,
  12000. IN OUT OPTIONAL DWORD *pcbComputedHash
  12001. );
  12002. //+-------------------------------------------------------------------------
  12003. // Verify a hashed message.
  12004. //
  12005. // pcbToBeHashed or pcbComputedHash can be NULL,
  12006. // indicating the caller isn't interested in getting the output.
  12007. //--------------------------------------------------------------------------
  12008. WINCRYPT32API
  12009. BOOL
  12010. WINAPI
  12011. CryptVerifyMessageHash(
  12012. IN PCRYPT_HASH_MESSAGE_PARA pHashPara,
  12013. IN BYTE *pbHashedBlob,
  12014. IN DWORD cbHashedBlob,
  12015. OUT OPTIONAL BYTE *pbToBeHashed,
  12016. IN OUT OPTIONAL DWORD *pcbToBeHashed,
  12017. OUT OPTIONAL BYTE *pbComputedHash,
  12018. IN OUT OPTIONAL DWORD *pcbComputedHash
  12019. );
  12020. //+-------------------------------------------------------------------------
  12021. // Verify a hashed message containing a detached hash.
  12022. // The "to be hashed" content is passed in separately. No
  12023. // decoded output. Otherwise, identical to CryptVerifyMessageHash.
  12024. //
  12025. // pcbComputedHash can be NULL, indicating the caller isn't interested
  12026. // in getting the output.
  12027. //--------------------------------------------------------------------------
  12028. WINCRYPT32API
  12029. BOOL
  12030. WINAPI
  12031. CryptVerifyDetachedMessageHash(
  12032. IN PCRYPT_HASH_MESSAGE_PARA pHashPara,
  12033. IN BYTE *pbDetachedHashBlob,
  12034. IN DWORD cbDetachedHashBlob,
  12035. IN DWORD cToBeHashed,
  12036. IN const BYTE *rgpbToBeHashed[],
  12037. IN DWORD rgcbToBeHashed[],
  12038. OUT OPTIONAL BYTE *pbComputedHash,
  12039. IN OUT OPTIONAL DWORD *pcbComputedHash
  12040. );
  12041. //+-------------------------------------------------------------------------
  12042. // Sign the message using the provider's private key specified in the
  12043. // parameters. A dummy SignerId is created and stored in the message.
  12044. //
  12045. // Normally used until a certificate has been created for the key.
  12046. //--------------------------------------------------------------------------
  12047. WINCRYPT32API
  12048. BOOL
  12049. WINAPI
  12050. CryptSignMessageWithKey(
  12051. IN PCRYPT_KEY_SIGN_MESSAGE_PARA pSignPara,
  12052. IN const BYTE *pbToBeSigned,
  12053. IN DWORD cbToBeSigned,
  12054. OUT BYTE *pbSignedBlob,
  12055. IN OUT DWORD *pcbSignedBlob
  12056. );
  12057. //+-------------------------------------------------------------------------
  12058. // Verify a signed message using the specified public key info.
  12059. //
  12060. // Normally called by a CA until it has created a certificate for the
  12061. // key.
  12062. //
  12063. // pPublicKeyInfo contains the public key to use to verify the signed
  12064. // message. If NULL, the signature isn't verified (for instance, the decoded
  12065. // content may contain the PublicKeyInfo).
  12066. //
  12067. // pcbDecoded can be NULL, indicating the caller isn't interested
  12068. // in getting the decoded content.
  12069. //--------------------------------------------------------------------------
  12070. WINCRYPT32API
  12071. BOOL
  12072. WINAPI
  12073. CryptVerifyMessageSignatureWithKey(
  12074. IN PCRYPT_KEY_VERIFY_MESSAGE_PARA pVerifyPara,
  12075. IN OPTIONAL PCERT_PUBLIC_KEY_INFO pPublicKeyInfo,
  12076. IN const BYTE *pbSignedBlob,
  12077. IN DWORD cbSignedBlob,
  12078. OUT OPTIONAL BYTE *pbDecoded,
  12079. IN OUT OPTIONAL DWORD *pcbDecoded
  12080. );
  12081. //+=========================================================================
  12082. // System Certificate Store Data Structures and APIs
  12083. //==========================================================================
  12084. //+-------------------------------------------------------------------------
  12085. // Get a system certificate store based on a subsystem protocol.
  12086. //
  12087. // Current examples of subsystems protocols are:
  12088. // "MY" Cert Store hold certs with associated Private Keys
  12089. // "CA" Certifying Authority certs
  12090. // "ROOT" Root Certs
  12091. // "SPC" Software publisher certs
  12092. //
  12093. //
  12094. // If hProv is NULL the default provider "1" is opened for you.
  12095. // When the store is closed the provider is release. Otherwise
  12096. // if hProv is not NULL, no provider is created or released.
  12097. //
  12098. // The returned Cert Store can be searched for an appropriate Cert
  12099. // using the Cert Store API's (see certstor.h)
  12100. //
  12101. // When done, the cert store should be closed using CertStoreClose
  12102. //--------------------------------------------------------------------------
  12103. WINCRYPT32API
  12104. HCERTSTORE
  12105. WINAPI
  12106. CertOpenSystemStoreA(
  12107. HCRYPTPROV hProv,
  12108. LPCSTR szSubsystemProtocol
  12109. );
  12110. WINCRYPT32API
  12111. HCERTSTORE
  12112. WINAPI
  12113. CertOpenSystemStoreW(
  12114. HCRYPTPROV hProv,
  12115. LPCWSTR szSubsystemProtocol
  12116. );
  12117. #ifdef UNICODE
  12118. #define CertOpenSystemStore CertOpenSystemStoreW
  12119. #else
  12120. #define CertOpenSystemStore CertOpenSystemStoreA
  12121. #endif // !UNICODE
  12122. WINCRYPT32API
  12123. BOOL
  12124. WINAPI
  12125. CertAddEncodedCertificateToSystemStoreA(
  12126. LPCSTR szCertStoreName,
  12127. const BYTE * pbCertEncoded,
  12128. DWORD cbCertEncoded
  12129. );
  12130. WINCRYPT32API
  12131. BOOL
  12132. WINAPI
  12133. CertAddEncodedCertificateToSystemStoreW(
  12134. LPCWSTR szCertStoreName,
  12135. const BYTE * pbCertEncoded,
  12136. DWORD cbCertEncoded
  12137. );
  12138. #ifdef UNICODE
  12139. #define CertAddEncodedCertificateToSystemStore CertAddEncodedCertificateToSystemStoreW
  12140. #else
  12141. #define CertAddEncodedCertificateToSystemStore CertAddEncodedCertificateToSystemStoreA
  12142. #endif // !UNICODE
  12143. //+-------------------------------------------------------------------------
  12144. // Find all certificate chains tying the given issuer name to any certificate
  12145. // that the current user has a private key for.
  12146. //
  12147. // If no certificate chain is found, FALSE is returned with LastError set
  12148. // to CRYPT_E_NOT_FOUND and the counts zeroed.
  12149. //
  12150. // IE 3.0 ASSUMPTION:
  12151. // The client certificates are in the "My" system store. The issuer
  12152. // cerificates may be in the "Root", "CA" or "My" system stores.
  12153. //--------------------------------------------------------------------------
  12154. typedef struct _CERT_CHAIN {
  12155. DWORD cCerts; // number of certs in chain
  12156. PCERT_BLOB certs; // pointer to array of cert chain blobs
  12157. // representing the certs
  12158. CRYPT_KEY_PROV_INFO keyLocatorInfo; // key locator for cert
  12159. } CERT_CHAIN, *PCERT_CHAIN;
  12160. // WINCRYPT32API This is not exported by crypt32, it is exported by softpub
  12161. HRESULT
  12162. WINAPI
  12163. FindCertsByIssuer(
  12164. OUT PCERT_CHAIN pCertChains,
  12165. IN OUT DWORD *pcbCertChains,
  12166. OUT DWORD *pcCertChains, // count of certificates chains returned
  12167. IN BYTE* pbEncodedIssuerName, // DER encoded issuer name
  12168. IN DWORD cbEncodedIssuerName, // count in bytes of encoded issuer name
  12169. IN LPCWSTR pwszPurpose, // "ClientAuth" or "CodeSigning"
  12170. IN DWORD dwKeySpec // only return signers supporting this
  12171. // keyspec
  12172. );
  12173. //-------------------------------------------------------------------------
  12174. //
  12175. // CryptQueryObject takes a CERT_BLOB or a file name and returns the
  12176. // information about the content in the blob or in the file.
  12177. //
  12178. // Parameters:
  12179. // INPUT dwObjectType:
  12180. // Indicate the type of the object. Should be one of the
  12181. // following:
  12182. // CERT_QUERY_OBJECT_FILE
  12183. // CERT_QUERY_OBJECT_BLOB
  12184. //
  12185. // INPUT pvObject:
  12186. // If dwObjectType == CERT_QUERY_OBJECT_FILE, it is a
  12187. // LPWSTR, that is, the pointer to a wchar file name
  12188. // if dwObjectType == CERT_QUERY_OBJECT_BLOB, it is a
  12189. // PCERT_BLOB, that is, a pointer to a CERT_BLOB
  12190. //
  12191. // INPUT dwExpectedContentTypeFlags:
  12192. // Indicate the expected contenet type.
  12193. // Can be one of the following:
  12194. // CERT_QUERY_CONTENT_FLAG_ALL (the content can be any type)
  12195. // CERT_QUERY_CONTENT_FLAG_CERT
  12196. // CERT_QUERY_CONTENT_FLAG_CTL
  12197. // CERT_QUERY_CONTENT_FLAG_CRL
  12198. // CERT_QUERY_CONTENT_FLAG_SERIALIZED_STORE
  12199. // CERT_QUERY_CONTENT_FLAG_SERIALIZED_CERT
  12200. // CERT_QUERY_CONTENT_FLAG_SERIALIZED_CTL
  12201. // CERT_QUERY_CONTENT_FLAG_SERIALIZED_CRL
  12202. // CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED
  12203. // CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED
  12204. // CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED
  12205. // CERT_QUERY_CONTENT_FLAG_PKCS10
  12206. // CERT_QUERY_CONTENT_FLAG_PFX
  12207. // CERT_QUERY_CONTENT_FLAG_CERT_PAIR
  12208. //
  12209. // INPUT dwExpectedFormatTypeFlags:
  12210. // Indicate the expected format type.
  12211. // Can be one of the following:
  12212. // CERT_QUERY_FORMAT_FLAG_ALL (the content can be any format)
  12213. // CERT_QUERY_FORMAT_FLAG_BINARY
  12214. // CERT_QUERY_FORMAT_FLAG_BASE64_ENCODED
  12215. // CERT_QUERY_FORMAT_FLAG_ASN_ASCII_HEX_ENCODED
  12216. //
  12217. //
  12218. // INPUT dwFlags
  12219. // Reserved flag. Should always set to 0
  12220. //
  12221. // OUTPUT pdwMsgAndCertEncodingType
  12222. // Optional output. If NULL != pdwMsgAndCertEncodingType,
  12223. // it contains the encoding type of the content as any
  12224. // combination of the following:
  12225. // X509_ASN_ENCODING
  12226. // PKCS_7_ASN_ENCODING
  12227. //
  12228. // OUTPUT pdwContentType
  12229. // Optional output. If NULL!=pdwContentType, it contains
  12230. // the content type as one of the the following:
  12231. // CERT_QUERY_CONTENT_CERT
  12232. // CERT_QUERY_CONTENT_CTL
  12233. // CERT_QUERY_CONTENT_CRL
  12234. // CERT_QUERY_CONTENT_SERIALIZED_STORE
  12235. // CERT_QUERY_CONTENT_SERIALIZED_CERT
  12236. // CERT_QUERY_CONTENT_SERIALIZED_CTL
  12237. // CERT_QUERY_CONTENT_SERIALIZED_CRL
  12238. // CERT_QUERY_CONTENT_PKCS7_SIGNED
  12239. // CERT_QUERY_CONTENT_PKCS7_UNSIGNED
  12240. // CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED
  12241. // CERT_QUERY_CONTENT_PKCS10
  12242. // CERT_QUERY_CONTENT_PFX
  12243. // CERT_QUERY_CONTENT_CERT_PAIR
  12244. //
  12245. // OUTPUT pdwFormatType
  12246. // Optional output. If NULL !=pdwFormatType, it
  12247. // contains the format type of the content as one of the
  12248. // following:
  12249. // CERT_QUERY_FORMAT_BINARY
  12250. // CERT_QUERY_FORMAT_BASE64_ENCODED
  12251. // CERT_QUERY_FORMAT_ASN_ASCII_HEX_ENCODED
  12252. //
  12253. //
  12254. // OUTPUT phCertStore
  12255. // Optional output. If NULL !=phStore,
  12256. // it contains a cert store that includes all of certificates,
  12257. // CRL, and CTL in the object if the object content type is
  12258. // one of the following:
  12259. // CERT_QUERY_CONTENT_CERT
  12260. // CERT_QUERY_CONTENT_CTL
  12261. // CERT_QUERY_CONTENT_CRL
  12262. // CERT_QUERY_CONTENT_SERIALIZED_STORE
  12263. // CERT_QUERY_CONTENT_SERIALIZED_CERT
  12264. // CERT_QUERY_CONTENT_SERIALIZED_CTL
  12265. // CERT_QUERY_CONTENT_SERIALIZED_CRL
  12266. // CERT_QUERY_CONTENT_PKCS7_SIGNED
  12267. // CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED
  12268. // CERT_QUERY_CONTENT_CERT_PAIR
  12269. //
  12270. // Caller should free *phCertStore via CertCloseStore.
  12271. //
  12272. //
  12273. // OUTPUT phMsg Optional output. If NULL != phMsg,
  12274. // it contains a handle to a opened message if
  12275. // the content type is one of the following:
  12276. // CERT_QUERY_CONTENT_PKCS7_SIGNED
  12277. // CERT_QUERY_CONTENT_PKCS7_UNSIGNED
  12278. // CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED
  12279. //
  12280. // Caller should free *phMsg via CryptMsgClose.
  12281. //
  12282. // OUTPUT pContext Optional output. If NULL != pContext,
  12283. // it contains either a PCCERT_CONTEXT or PCCRL_CONTEXT,
  12284. // or PCCTL_CONTEXT based on the content type.
  12285. //
  12286. // If the content type is CERT_QUERY_CONTENT_CERT or
  12287. // CERT_QUERY_CONTENT_SERIALIZED_CERT, it is a PCCERT_CONTEXT;
  12288. // Caller should free the pContext via CertFreeCertificateContext.
  12289. //
  12290. // If the content type is CERT_QUERY_CONTENT_CRL or
  12291. // CERT_QUERY_CONTENT_SERIALIZED_CRL, it is a PCCRL_CONTEXT;
  12292. // Caller should free the pContext via CertFreeCRLContext.
  12293. //
  12294. // If the content type is CERT_QUERY_CONTENT_CTL or
  12295. // CERT_QUERY_CONTENT_SERIALIZED_CTL, it is a PCCTL_CONTEXT;
  12296. // Caller should free the pContext via CertFreeCTLContext.
  12297. //
  12298. // If the *pbObject is of type CERT_QUERY_CONTENT_PKCS10 or CERT_QUERY_CONTENT_PFX, CryptQueryObject
  12299. // will not return anything in *phCertstore, *phMsg, or *ppvContext.
  12300. //--------------------------------------------------------------------------
  12301. WINCRYPT32API
  12302. BOOL
  12303. WINAPI
  12304. CryptQueryObject(
  12305. DWORD dwObjectType,
  12306. const void *pvObject,
  12307. DWORD dwExpectedContentTypeFlags,
  12308. DWORD dwExpectedFormatTypeFlags,
  12309. DWORD dwFlags,
  12310. DWORD *pdwMsgAndCertEncodingType,
  12311. DWORD *pdwContentType,
  12312. DWORD *pdwFormatType,
  12313. HCERTSTORE *phCertStore,
  12314. HCRYPTMSG *phMsg,
  12315. const void **ppvContext
  12316. );
  12317. //-------------------------------------------------------------------------
  12318. //dwObjectType for CryptQueryObject
  12319. //-------------------------------------------------------------------------
  12320. #define CERT_QUERY_OBJECT_FILE 0x00000001
  12321. #define CERT_QUERY_OBJECT_BLOB 0x00000002
  12322. //-------------------------------------------------------------------------
  12323. //dwContentType for CryptQueryObject
  12324. //-------------------------------------------------------------------------
  12325. //encoded single certificate
  12326. #define CERT_QUERY_CONTENT_CERT 1
  12327. //encoded single CTL
  12328. #define CERT_QUERY_CONTENT_CTL 2
  12329. //encoded single CRL
  12330. #define CERT_QUERY_CONTENT_CRL 3
  12331. //serialized store
  12332. #define CERT_QUERY_CONTENT_SERIALIZED_STORE 4
  12333. //serialized single certificate
  12334. #define CERT_QUERY_CONTENT_SERIALIZED_CERT 5
  12335. //serialized single CTL
  12336. #define CERT_QUERY_CONTENT_SERIALIZED_CTL 6
  12337. //serialized single CRL
  12338. #define CERT_QUERY_CONTENT_SERIALIZED_CRL 7
  12339. //a PKCS#7 signed message
  12340. #define CERT_QUERY_CONTENT_PKCS7_SIGNED 8
  12341. //a PKCS#7 message, such as enveloped message. But it is not a signed message,
  12342. #define CERT_QUERY_CONTENT_PKCS7_UNSIGNED 9
  12343. //a PKCS7 signed message embedded in a file
  12344. #define CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED 10
  12345. //an encoded PKCS#10
  12346. #define CERT_QUERY_CONTENT_PKCS10 11
  12347. //an encoded PKX BLOB
  12348. #define CERT_QUERY_CONTENT_PFX 12
  12349. //an encoded CertificatePair (contains forward and/or reverse cross certs)
  12350. #define CERT_QUERY_CONTENT_CERT_PAIR 13
  12351. //-------------------------------------------------------------------------
  12352. //dwExpectedConentTypeFlags for CryptQueryObject
  12353. //-------------------------------------------------------------------------
  12354. //encoded single certificate
  12355. #define CERT_QUERY_CONTENT_FLAG_CERT \
  12356. ( 1 << CERT_QUERY_CONTENT_CERT)
  12357. //encoded single CTL
  12358. #define CERT_QUERY_CONTENT_FLAG_CTL \
  12359. ( 1 << CERT_QUERY_CONTENT_CTL)
  12360. //encoded single CRL
  12361. #define CERT_QUERY_CONTENT_FLAG_CRL \
  12362. ( 1 << CERT_QUERY_CONTENT_CRL)
  12363. //serialized store
  12364. #define CERT_QUERY_CONTENT_FLAG_SERIALIZED_STORE \
  12365. ( 1 << CERT_QUERY_CONTENT_SERIALIZED_STORE)
  12366. //serialized single certificate
  12367. #define CERT_QUERY_CONTENT_FLAG_SERIALIZED_CERT \
  12368. ( 1 << CERT_QUERY_CONTENT_SERIALIZED_CERT)
  12369. //serialized single CTL
  12370. #define CERT_QUERY_CONTENT_FLAG_SERIALIZED_CTL \
  12371. ( 1 << CERT_QUERY_CONTENT_SERIALIZED_CTL)
  12372. //serialized single CRL
  12373. #define CERT_QUERY_CONTENT_FLAG_SERIALIZED_CRL \
  12374. ( 1 << CERT_QUERY_CONTENT_SERIALIZED_CRL)
  12375. //an encoded PKCS#7 signed message
  12376. #define CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED \
  12377. ( 1 << CERT_QUERY_CONTENT_PKCS7_SIGNED)
  12378. //an encoded PKCS#7 message. But it is not a signed message
  12379. #define CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED \
  12380. ( 1 << CERT_QUERY_CONTENT_PKCS7_UNSIGNED)
  12381. //the content includes an embedded PKCS7 signed message
  12382. #define CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED \
  12383. ( 1 << CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED)
  12384. //an encoded PKCS#10
  12385. #define CERT_QUERY_CONTENT_FLAG_PKCS10 \
  12386. ( 1 << CERT_QUERY_CONTENT_PKCS10)
  12387. //an encoded PFX BLOB
  12388. #define CERT_QUERY_CONTENT_FLAG_PFX \
  12389. ( 1 << CERT_QUERY_CONTENT_PFX)
  12390. //an encoded CertificatePair (contains forward and/or reverse cross certs)
  12391. #define CERT_QUERY_CONTENT_FLAG_CERT_PAIR \
  12392. ( 1 << CERT_QUERY_CONTENT_CERT_PAIR)
  12393. //content can be any type
  12394. #define CERT_QUERY_CONTENT_FLAG_ALL \
  12395. CERT_QUERY_CONTENT_FLAG_CERT | \
  12396. CERT_QUERY_CONTENT_FLAG_CTL | \
  12397. CERT_QUERY_CONTENT_FLAG_CRL | \
  12398. CERT_QUERY_CONTENT_FLAG_SERIALIZED_STORE | \
  12399. CERT_QUERY_CONTENT_FLAG_SERIALIZED_CERT | \
  12400. CERT_QUERY_CONTENT_FLAG_SERIALIZED_CTL | \
  12401. CERT_QUERY_CONTENT_FLAG_SERIALIZED_CRL | \
  12402. CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED | \
  12403. CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED | \
  12404. CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED | \
  12405. CERT_QUERY_CONTENT_FLAG_PKCS10 | \
  12406. CERT_QUERY_CONTENT_FLAG_PFX | \
  12407. CERT_QUERY_CONTENT_FLAG_CERT_PAIR
  12408. //-------------------------------------------------------------------------
  12409. //dwFormatType for CryptQueryObject
  12410. //-------------------------------------------------------------------------
  12411. //the content is in binary format
  12412. #define CERT_QUERY_FORMAT_BINARY 1
  12413. //the content is base64 encoded
  12414. #define CERT_QUERY_FORMAT_BASE64_ENCODED 2
  12415. //the content is ascii hex encoded with "{ASN}" prefix
  12416. #define CERT_QUERY_FORMAT_ASN_ASCII_HEX_ENCODED 3
  12417. //-------------------------------------------------------------------------
  12418. //dwExpectedFormatTypeFlags for CryptQueryObject
  12419. //-------------------------------------------------------------------------
  12420. //the content is in binary format
  12421. #define CERT_QUERY_FORMAT_FLAG_BINARY \
  12422. ( 1 << CERT_QUERY_FORMAT_BINARY)
  12423. //the content is base64 encoded
  12424. #define CERT_QUERY_FORMAT_FLAG_BASE64_ENCODED \
  12425. ( 1 << CERT_QUERY_FORMAT_BASE64_ENCODED)
  12426. //the content is ascii hex encoded with "{ASN}" prefix
  12427. #define CERT_QUERY_FORMAT_FLAG_ASN_ASCII_HEX_ENCODED \
  12428. ( 1 << CERT_QUERY_FORMAT_ASN_ASCII_HEX_ENCODED)
  12429. //the content can be of any format
  12430. #define CERT_QUERY_FORMAT_FLAG_ALL \
  12431. CERT_QUERY_FORMAT_FLAG_BINARY | \
  12432. CERT_QUERY_FORMAT_FLAG_BASE64_ENCODED | \
  12433. CERT_QUERY_FORMAT_FLAG_ASN_ASCII_HEX_ENCODED
  12434. //
  12435. // Crypt32 Memory Management Routines. All Crypt32 API which return allocated
  12436. // buffers will do so via CryptMemAlloc, CryptMemRealloc. Clients can free
  12437. // those buffers using CryptMemFree. Also included is CryptMemSize
  12438. //
  12439. WINCRYPT32API
  12440. LPVOID
  12441. WINAPI
  12442. CryptMemAlloc (
  12443. IN ULONG cbSize
  12444. );
  12445. WINCRYPT32API
  12446. LPVOID
  12447. WINAPI
  12448. CryptMemRealloc (
  12449. IN LPVOID pv,
  12450. IN ULONG cbSize
  12451. );
  12452. WINCRYPT32API
  12453. VOID
  12454. WINAPI
  12455. CryptMemFree (
  12456. IN LPVOID pv
  12457. );
  12458. //
  12459. // Crypt32 Asynchronous Parameter Management Routines. All Crypt32 API which
  12460. // expose asynchronous mode operation use a Crypt32 Async Handle to pass
  12461. // around information about the operation e.g. callback routines. The
  12462. // following API are used for manipulation of the async handle
  12463. //
  12464. typedef HANDLE HCRYPTASYNC, *PHCRYPTASYNC;
  12465. typedef VOID (WINAPI *PFN_CRYPT_ASYNC_PARAM_FREE_FUNC) (
  12466. LPSTR pszParamOid,
  12467. LPVOID pvParam
  12468. );
  12469. WINCRYPT32API
  12470. BOOL
  12471. WINAPI
  12472. CryptCreateAsyncHandle (
  12473. IN DWORD dwFlags,
  12474. OUT PHCRYPTASYNC phAsync
  12475. );
  12476. WINCRYPT32API
  12477. BOOL
  12478. WINAPI
  12479. CryptSetAsyncParam (
  12480. IN HCRYPTASYNC hAsync,
  12481. IN LPSTR pszParamOid,
  12482. IN LPVOID pvParam,
  12483. IN OPTIONAL PFN_CRYPT_ASYNC_PARAM_FREE_FUNC pfnFree
  12484. );
  12485. WINCRYPT32API
  12486. BOOL
  12487. WINAPI
  12488. CryptGetAsyncParam (
  12489. IN HCRYPTASYNC hAsync,
  12490. IN LPSTR pszParamOid,
  12491. OUT LPVOID* ppvParam,
  12492. OUT OPTIONAL PFN_CRYPT_ASYNC_PARAM_FREE_FUNC* ppfnFree
  12493. );
  12494. WINCRYPT32API
  12495. BOOL
  12496. WINAPI
  12497. CryptCloseAsyncHandle (
  12498. IN HCRYPTASYNC hAsync
  12499. );
  12500. //
  12501. // Crypt32 Remote Object Retrieval Routines. This API allows retrieval of
  12502. // remote PKI objects where the location is given by an URL. The remote
  12503. // object retrieval manager exposes two provider models. One is the "Scheme
  12504. // Provider" model which allows for installable protocol providers as defined
  12505. // by the URL scheme e.g. ldap, http, ftp. The scheme provider entry point is
  12506. // the same as the CryptRetrieveObjectByUrl however the *ppvObject returned
  12507. // is ALWAYS a counted array of encoded bits (one per object retrieved). The
  12508. // second provider model is the "Context Provider" model which allows for
  12509. // installable creators of CAPI2 context handles (objects) based on the
  12510. // retrieved encoded bits. These are dispatched based on the object OID given
  12511. // in the call to CryptRetrieveObjectByUrl.
  12512. //
  12513. typedef struct _CRYPT_BLOB_ARRAY {
  12514. DWORD cBlob;
  12515. PCRYPT_DATA_BLOB rgBlob;
  12516. } CRYPT_BLOB_ARRAY, *PCRYPT_BLOB_ARRAY;
  12517. typedef struct _CRYPT_CREDENTIALS {
  12518. DWORD cbSize;
  12519. LPCSTR pszCredentialsOid;
  12520. LPVOID pvCredentials;
  12521. } CRYPT_CREDENTIALS, *PCRYPT_CREDENTIALS;
  12522. #define CREDENTIAL_OID_PASSWORD_CREDENTIALS_A ((LPCSTR)1)
  12523. #define CREDENTIAL_OID_PASSWORD_CREDENTIALS_W ((LPCSTR)2)
  12524. #ifdef UNICODE
  12525. #define CREDENTIAL_OID_PASSWORD_CREDENTIALS CREDENTIAL_OID_PASSWORD_CREDENTIALS_W
  12526. #else
  12527. #define CREDENTIAL_OID_PASSWORD_CREDENTIALS CREDENTIAL_OID_PASSWORD_CREDENTIALS_A
  12528. #endif //UNICODE
  12529. typedef struct _CRYPT_PASSWORD_CREDENTIALSA {
  12530. DWORD cbSize;
  12531. LPSTR pszUsername;
  12532. LPSTR pszPassword;
  12533. } CRYPT_PASSWORD_CREDENTIALSA, *PCRYPT_PASSWORD_CREDENTIALSA;
  12534. typedef struct _CRYPT_PASSWORD_CREDENTIALSW {
  12535. DWORD cbSize;
  12536. LPWSTR pszUsername;
  12537. LPWSTR pszPassword;
  12538. } CRYPT_PASSWORD_CREDENTIALSW, *PCRYPT_PASSWORD_CREDENTIALSW;
  12539. #ifdef UNICODE
  12540. typedef CRYPT_PASSWORD_CREDENTIALSW CRYPT_PASSWORD_CREDENTIALS;
  12541. typedef PCRYPT_PASSWORD_CREDENTIALSW PCRYPT_PASSWORD_CREDENTIALS;
  12542. #else
  12543. typedef CRYPT_PASSWORD_CREDENTIALSA CRYPT_PASSWORD_CREDENTIALS;
  12544. typedef PCRYPT_PASSWORD_CREDENTIALSA PCRYPT_PASSWORD_CREDENTIALS;
  12545. #endif // UNICODE
  12546. //
  12547. // Scheme Provider Signatures
  12548. //
  12549. // The following is obsolete and has been replaced with the following
  12550. // definition
  12551. #define SCHEME_OID_RETRIEVE_ENCODED_OBJECT_FUNC "SchemeDllRetrieveEncodedObject"
  12552. // 2-8-02 Server 2003 changed to use UNICODE Url strings instead of multibyte
  12553. #define SCHEME_OID_RETRIEVE_ENCODED_OBJECTW_FUNC "SchemeDllRetrieveEncodedObjectW"
  12554. typedef VOID (WINAPI *PFN_FREE_ENCODED_OBJECT_FUNC) (
  12555. LPCSTR pszObjectOid,
  12556. PCRYPT_BLOB_ARRAY pObject,
  12557. LPVOID pvFreeContext
  12558. );
  12559. //
  12560. // SchemeDllRetrieveEncodedObject was replaced in Server 2003 with
  12561. // the following. (Changed to use UNICODE Url Strings.)
  12562. //
  12563. //
  12564. // SchemeDllRetrieveEncodedObjectW has the following signature:
  12565. //
  12566. // BOOL WINAPI SchemeDllRetrieveEncodedObjectW (
  12567. // IN LPCWSTR pwszUrl,
  12568. // IN LPCSTR pszObjectOid,
  12569. // IN DWORD dwRetrievalFlags,
  12570. // IN DWORD dwTimeout, // milliseconds
  12571. // OUT PCRYPT_BLOB_ARRAY pObject,
  12572. // OUT PFN_FREE_ENCODED_OBJECT_FUNC* ppfnFreeObject,
  12573. // OUT LPVOID* ppvFreeContext,
  12574. // IN HCRYPTASYNC hAsyncRetrieve,
  12575. // IN PCRYPT_CREDENTIALS pCredentials,
  12576. // IN PCRYPT_RETRIEVE_AUX_INFO pAuxInfo
  12577. // )
  12578. //
  12579. //
  12580. // Context Provider Signatures
  12581. //
  12582. #define CONTEXT_OID_CREATE_OBJECT_CONTEXT_FUNC "ContextDllCreateObjectContext"
  12583. #define CONTEXT_OID_CERTIFICATE ((LPCSTR)1)
  12584. #define CONTEXT_OID_CRL ((LPCSTR)2)
  12585. #define CONTEXT_OID_CTL ((LPCSTR)3)
  12586. #define CONTEXT_OID_PKCS7 ((LPCSTR)4)
  12587. #define CONTEXT_OID_CAPI2_ANY ((LPCSTR)5)
  12588. //
  12589. // ContextDllCreateObjectContext has the following signature:
  12590. //
  12591. // BOOL WINAPI ContextDllCreateObjectContext (
  12592. // IN LPCSTR pszObjectOid,
  12593. // IN DWORD dwRetrievalFlags,
  12594. // IN PCRYPT_BLOB_ARRAY pObject,
  12595. // OUT LPVOID* ppvContext
  12596. // )
  12597. //
  12598. //
  12599. // Remote Object Retrieval API
  12600. //
  12601. //
  12602. // Retrieval flags
  12603. //
  12604. #define CRYPT_RETRIEVE_MULTIPLE_OBJECTS 0x00000001
  12605. #define CRYPT_CACHE_ONLY_RETRIEVAL 0x00000002
  12606. #define CRYPT_WIRE_ONLY_RETRIEVAL 0x00000004
  12607. #define CRYPT_DONT_CACHE_RESULT 0x00000008
  12608. #define CRYPT_ASYNC_RETRIEVAL 0x00000010
  12609. #define CRYPT_STICKY_CACHE_RETRIEVAL 0x00001000
  12610. #define CRYPT_LDAP_SCOPE_BASE_ONLY_RETRIEVAL 0x00002000
  12611. #define CRYPT_OFFLINE_CHECK_RETRIEVAL 0x00004000
  12612. // When the following flag is set, the following 2 NULL terminated ascii
  12613. // strings are inserted at the beginning of each returned blob:
  12614. // "%d\0%s\0", dwEntryIndex, pszAttribute
  12615. //
  12616. // The first dwEntryIndex is 0, "0\0".
  12617. //
  12618. // When set, pszObjectOid must be NULL, so that a PCRYPT_BLOB_ARRAY is returned.
  12619. #define CRYPT_LDAP_INSERT_ENTRY_ATTRIBUTE 0x00008000
  12620. // Set this flag to digitally sign all of the ldap traffic to and from a
  12621. // Windows 2000 LDAP server using the Kerberos authentication protocol.
  12622. // This feature provides integrity required by some applications.
  12623. #define CRYPT_LDAP_SIGN_RETRIEVAL 0x00010000
  12624. // Set this flag to inhibit automatic authentication handling. See the
  12625. // wininet flag, INTERNET_FLAG_NO_AUTH, for more details.
  12626. #define CRYPT_NO_AUTH_RETRIEVAL 0x00020000
  12627. // Performs an A-Record only DNS lookup on the supplied host string.
  12628. // This prevents bogus DNS queries from being generated when resolving host
  12629. // names. Use this flag whenever passing a hostname as opposed to a
  12630. // domain name for the hostname parameter.
  12631. //
  12632. // See LDAP_OPT_AREC_EXCLUSIVE defined in winldap.h for more details.
  12633. #define CRYPT_LDAP_AREC_EXCLUSIVE_RETRIEVAL 0x00040000
  12634. // Apply AIA URL restrictions, such as, validate retrieved content before
  12635. // writing to cache.
  12636. #define CRYPT_AIA_RETRIEVAL 0x00080000
  12637. //
  12638. // Data verification retrieval flags
  12639. //
  12640. // CRYPT_VERIFY_CONTEXT_SIGNATURE is used to get signature verification
  12641. // on the context created. In this case pszObjectOid must be non-NULL and
  12642. // pvVerify points to the signer certificate context
  12643. //
  12644. // CRYPT_VERIFY_DATA_HASH is used to get verification of the blob data
  12645. // retrieved by the protocol. The pvVerify points to an URL_DATA_HASH
  12646. // structure (TBD)
  12647. //
  12648. #define CRYPT_VERIFY_CONTEXT_SIGNATURE 0x00000020
  12649. #define CRYPT_VERIFY_DATA_HASH 0x00000040
  12650. //
  12651. // Time Valid Object flags
  12652. //
  12653. #define CRYPT_KEEP_TIME_VALID 0x00000080
  12654. #define CRYPT_DONT_VERIFY_SIGNATURE 0x00000100
  12655. #define CRYPT_DONT_CHECK_TIME_VALIDITY 0x00000200
  12656. // The default checks if ftNextUpdate >= ftValidFor. Set this flag to
  12657. // check if ftThisUpdate >= ftValidFor.
  12658. #define CRYPT_CHECK_FRESHNESS_TIME_VALIDITY 0x00000400
  12659. #define CRYPT_ACCUMULATIVE_TIMEOUT 0x00000800
  12660. typedef struct _CRYPT_RETRIEVE_AUX_INFO {
  12661. DWORD cbSize;
  12662. FILETIME *pLastSyncTime;
  12663. DWORD dwMaxUrlRetrievalByteCount; // 0 => implies no limit
  12664. } CRYPT_RETRIEVE_AUX_INFO, *PCRYPT_RETRIEVE_AUX_INFO;
  12665. WINCRYPT32API
  12666. BOOL
  12667. WINAPI
  12668. CryptRetrieveObjectByUrlA (
  12669. IN LPCSTR pszUrl,
  12670. IN LPCSTR pszObjectOid,
  12671. IN DWORD dwRetrievalFlags,
  12672. IN DWORD dwTimeout, // milliseconds
  12673. OUT LPVOID* ppvObject,
  12674. IN HCRYPTASYNC hAsyncRetrieve,
  12675. IN OPTIONAL PCRYPT_CREDENTIALS pCredentials,
  12676. IN OPTIONAL LPVOID pvVerify,
  12677. IN OPTIONAL PCRYPT_RETRIEVE_AUX_INFO pAuxInfo
  12678. );
  12679. WINCRYPT32API
  12680. BOOL
  12681. WINAPI
  12682. CryptRetrieveObjectByUrlW (
  12683. IN LPCWSTR pszUrl,
  12684. IN LPCSTR pszObjectOid,
  12685. IN DWORD dwRetrievalFlags,
  12686. IN DWORD dwTimeout, // milliseconds
  12687. OUT LPVOID* ppvObject,
  12688. IN HCRYPTASYNC hAsyncRetrieve,
  12689. IN OPTIONAL PCRYPT_CREDENTIALS pCredentials,
  12690. IN OPTIONAL LPVOID pvVerify,
  12691. IN OPTIONAL PCRYPT_RETRIEVE_AUX_INFO pAuxInfo
  12692. );
  12693. #ifdef UNICODE
  12694. #define CryptRetrieveObjectByUrl CryptRetrieveObjectByUrlW
  12695. #else
  12696. #define CryptRetrieveObjectByUrl CryptRetrieveObjectByUrlA
  12697. #endif // !UNICODE
  12698. //
  12699. // Call back function to cancel object retrieval
  12700. //
  12701. // The function can be installed on a per thread basis.
  12702. // If CryptInstallCancelRetrieval is called for multiple times, only the most recent
  12703. // installation will be kept.
  12704. //
  12705. // This is only effective for http, https, gopher, and ftp protocol.
  12706. // It is ignored by the rest of the protocols.
  12707. typedef BOOL (WINAPI *PFN_CRYPT_CANCEL_RETRIEVAL)(
  12708. IN DWORD dwFlags,
  12709. IN void *pvArg
  12710. );
  12711. //
  12712. // PFN_CRYPT_CANCEL_RETRIEVAL
  12713. //
  12714. // This function should return FALSE when the object retrieval should be continued
  12715. // and return TRUE when the object retrieval should be cancelled.
  12716. //
  12717. WINCRYPT32API
  12718. BOOL
  12719. WINAPI
  12720. CryptInstallCancelRetrieval(
  12721. IN PFN_CRYPT_CANCEL_RETRIEVAL pfnCancel,
  12722. IN const void *pvArg,
  12723. IN DWORD dwFlags,
  12724. IN void *pvReserved
  12725. );
  12726. WINCRYPT32API
  12727. BOOL
  12728. WINAPI
  12729. CryptUninstallCancelRetrieval(
  12730. IN DWORD dwFlags,
  12731. IN void *pvReserved
  12732. );
  12733. WINCRYPT32API
  12734. BOOL
  12735. WINAPI
  12736. CryptCancelAsyncRetrieval (
  12737. HCRYPTASYNC hAsyncRetrieval
  12738. );
  12739. //
  12740. // Remote Object Async Retrieval parameters
  12741. //
  12742. //
  12743. // A client that wants to be notified of asynchronous object retrieval
  12744. // completion sets this parameter on the async handle
  12745. //
  12746. #define CRYPT_PARAM_ASYNC_RETRIEVAL_COMPLETION ((LPCSTR)1)
  12747. typedef VOID (WINAPI *PFN_CRYPT_ASYNC_RETRIEVAL_COMPLETION_FUNC) (
  12748. IN LPVOID pvCompletion,
  12749. IN DWORD dwCompletionCode,
  12750. IN LPCSTR pszUrl,
  12751. IN LPSTR pszObjectOid,
  12752. IN LPVOID pvObject
  12753. );
  12754. typedef struct _CRYPT_ASYNC_RETRIEVAL_COMPLETION {
  12755. PFN_CRYPT_ASYNC_RETRIEVAL_COMPLETION_FUNC pfnCompletion;
  12756. LPVOID pvCompletion;
  12757. } CRYPT_ASYNC_RETRIEVAL_COMPLETION, *PCRYPT_ASYNC_RETRIEVAL_COMPLETION;
  12758. //
  12759. // This function is set on the async handle by a scheme provider that
  12760. // supports asynchronous retrieval
  12761. //
  12762. #define CRYPT_PARAM_CANCEL_ASYNC_RETRIEVAL ((LPCSTR)2)
  12763. typedef BOOL (WINAPI *PFN_CANCEL_ASYNC_RETRIEVAL_FUNC) (
  12764. HCRYPTASYNC hAsyncRetrieve
  12765. );
  12766. //
  12767. // Get the locator for a CAPI object
  12768. //
  12769. #define CRYPT_GET_URL_FROM_PROPERTY 0x00000001
  12770. #define CRYPT_GET_URL_FROM_EXTENSION 0x00000002
  12771. #define CRYPT_GET_URL_FROM_UNAUTH_ATTRIBUTE 0x00000004
  12772. #define CRYPT_GET_URL_FROM_AUTH_ATTRIBUTE 0x00000008
  12773. typedef struct _CRYPT_URL_ARRAY {
  12774. DWORD cUrl;
  12775. LPWSTR* rgwszUrl;
  12776. } CRYPT_URL_ARRAY, *PCRYPT_URL_ARRAY;
  12777. typedef struct _CRYPT_URL_INFO {
  12778. DWORD cbSize;
  12779. // Seconds between syncs
  12780. DWORD dwSyncDeltaTime;
  12781. // Returned URLs may be grouped. For instance, groups of cross cert
  12782. // distribution points. Each distribution point may have multiple
  12783. // URLs, (LDAP and HTTP scheme).
  12784. DWORD cGroup;
  12785. DWORD *rgcGroupEntry;
  12786. } CRYPT_URL_INFO, *PCRYPT_URL_INFO;
  12787. WINCRYPT32API
  12788. BOOL
  12789. WINAPI
  12790. CryptGetObjectUrl (
  12791. IN LPCSTR pszUrlOid,
  12792. IN LPVOID pvPara,
  12793. IN DWORD dwFlags,
  12794. OUT OPTIONAL PCRYPT_URL_ARRAY pUrlArray,
  12795. IN OUT DWORD* pcbUrlArray,
  12796. OUT OPTIONAL PCRYPT_URL_INFO pUrlInfo,
  12797. IN OUT OPTIONAL DWORD* pcbUrlInfo,
  12798. IN OPTIONAL LPVOID pvReserved
  12799. );
  12800. #define URL_OID_GET_OBJECT_URL_FUNC "UrlDllGetObjectUrl"
  12801. //
  12802. // UrlDllGetObjectUrl has the same signature as CryptGetObjectUrl
  12803. //
  12804. //
  12805. // URL_OID_CERTIFICATE_ISSUER
  12806. //
  12807. // pvPara == PCCERT_CONTEXT, certificate whose issuer's URL is being requested
  12808. //
  12809. // This will be retrieved from the authority info access extension or property
  12810. // on the certificate
  12811. //
  12812. // URL_OID_CERTIFICATE_CRL_DIST_POINT
  12813. //
  12814. // pvPara == PCCERT_CONTEXT, certificate whose CRL distribution point is being
  12815. // requested
  12816. //
  12817. // This will be retrieved from the CRL distribution point extension or property
  12818. // on the certificate
  12819. //
  12820. // URL_OID_CTL_ISSUER
  12821. //
  12822. // pvPara == PCCTL_CONTEXT, Signer Index, CTL whose issuer's URL (identified
  12823. // by the signer index) is being requested
  12824. //
  12825. // This will be retrieved from an authority info access attribute method encoded
  12826. // in each signer info in the PKCS7 (CTL)
  12827. //
  12828. // URL_OID_CTL_NEXT_UPDATE
  12829. //
  12830. // pvPara == PCCTL_CONTEXT, Signer Index, CTL whose next update URL is being
  12831. // requested and an optional signer index in case we need to check signer
  12832. // info attributes
  12833. //
  12834. // This will be retrieved from an authority info access CTL extension, property,
  12835. // or signer info attribute method
  12836. //
  12837. // URL_OID_CRL_ISSUER
  12838. //
  12839. // pvPara == PCCRL_CONTEXT, CRL whose issuer's URL is being requested
  12840. //
  12841. // This will be retrieved from a property on the CRL which has been inherited
  12842. // from the subject cert (either from the subject cert issuer or the subject
  12843. // cert distribution point extension). It will be encoded as an authority
  12844. // info access extension method.
  12845. //
  12846. // URL_OID_CERTIFICATE_FRESHEST_CRL
  12847. //
  12848. // pvPara == PCCERT_CONTEXT, certificate whose freshest CRL distribution point
  12849. // is being requested
  12850. //
  12851. // This will be retrieved from the freshest CRL extension or property
  12852. // on the certificate
  12853. //
  12854. // URL_OID_CRL_FRESHEST_CRL
  12855. //
  12856. // pvPara == PCCERT_CRL_CONTEXT_PAIR, certificate's base CRL whose
  12857. // freshest CRL distribution point is being requested
  12858. //
  12859. // This will be retrieved from the freshest CRL extension or property
  12860. // on the CRL
  12861. //
  12862. // URL_OID_CROSS_CERT_DIST_POINT
  12863. //
  12864. // pvPara == PCCERT_CONTEXT, certificate whose cross certificate distribution
  12865. // point is being requested
  12866. //
  12867. // This will be retrieved from the cross certificate distribution point
  12868. // extension or property on the certificate
  12869. //
  12870. #define URL_OID_CERTIFICATE_ISSUER ((LPCSTR)1)
  12871. #define URL_OID_CERTIFICATE_CRL_DIST_POINT ((LPCSTR)2)
  12872. #define URL_OID_CTL_ISSUER ((LPCSTR)3)
  12873. #define URL_OID_CTL_NEXT_UPDATE ((LPCSTR)4)
  12874. #define URL_OID_CRL_ISSUER ((LPCSTR)5)
  12875. #define URL_OID_CERTIFICATE_FRESHEST_CRL ((LPCSTR)6)
  12876. #define URL_OID_CRL_FRESHEST_CRL ((LPCSTR)7)
  12877. #define URL_OID_CROSS_CERT_DIST_POINT ((LPCSTR)8)
  12878. typedef struct _CERT_CRL_CONTEXT_PAIR {
  12879. PCCERT_CONTEXT pCertContext;
  12880. PCCRL_CONTEXT pCrlContext;
  12881. } CERT_CRL_CONTEXT_PAIR, *PCERT_CRL_CONTEXT_PAIR;
  12882. typedef const CERT_CRL_CONTEXT_PAIR *PCCERT_CRL_CONTEXT_PAIR;
  12883. //
  12884. // Get a time valid CAPI2 object
  12885. //
  12886. WINCRYPT32API
  12887. BOOL
  12888. WINAPI
  12889. CryptGetTimeValidObject (
  12890. IN LPCSTR pszTimeValidOid,
  12891. IN LPVOID pvPara,
  12892. IN PCCERT_CONTEXT pIssuer,
  12893. IN OPTIONAL LPFILETIME pftValidFor,
  12894. IN DWORD dwFlags,
  12895. IN DWORD dwTimeout, // milliseconds
  12896. OUT OPTIONAL LPVOID* ppvObject,
  12897. IN OPTIONAL PCRYPT_CREDENTIALS pCredentials,
  12898. IN OPTIONAL LPVOID pvReserved
  12899. );
  12900. #define TIME_VALID_OID_GET_OBJECT_FUNC "TimeValidDllGetObject"
  12901. //
  12902. // TimeValidDllGetObject has the same signature as CryptGetTimeValidObject
  12903. //
  12904. //
  12905. // TIME_VALID_OID_GET_CTL
  12906. //
  12907. // pvPara == PCCTL_CONTEXT, the current CTL
  12908. //
  12909. // TIME_VALID_OID_GET_CRL
  12910. //
  12911. // pvPara == PCCRL_CONTEXT, the current CRL
  12912. //
  12913. // TIME_VALID_OID_GET_CRL_FROM_CERT
  12914. //
  12915. // pvPara == PCCERT_CONTEXT, the subject cert
  12916. //
  12917. // TIME_VALID_OID_GET_FRESHEST_CRL_FROM_CERT
  12918. //
  12919. // pvPara == PCCERT_CONTEXT, the subject cert
  12920. //
  12921. // TIME_VALID_OID_GET_FRESHEST_CRL_FROM_CRL
  12922. //
  12923. // pvPara == PCCERT_CRL_CONTEXT_PAIR, the subject cert and its base CRL
  12924. //
  12925. #define TIME_VALID_OID_GET_CTL ((LPCSTR)1)
  12926. #define TIME_VALID_OID_GET_CRL ((LPCSTR)2)
  12927. #define TIME_VALID_OID_GET_CRL_FROM_CERT ((LPCSTR)3)
  12928. #define TIME_VALID_OID_GET_FRESHEST_CRL_FROM_CERT ((LPCSTR)4)
  12929. #define TIME_VALID_OID_GET_FRESHEST_CRL_FROM_CRL ((LPCSTR)5)
  12930. WINCRYPT32API
  12931. BOOL
  12932. WINAPI
  12933. CryptFlushTimeValidObject (
  12934. IN LPCSTR pszFlushTimeValidOid,
  12935. IN LPVOID pvPara,
  12936. IN PCCERT_CONTEXT pIssuer,
  12937. IN DWORD dwFlags,
  12938. IN LPVOID pvReserved
  12939. );
  12940. #define TIME_VALID_OID_FLUSH_OBJECT_FUNC "TimeValidDllFlushObject"
  12941. //
  12942. // TimeValidDllFlushObject has the same signature as CryptFlushTimeValidObject
  12943. //
  12944. //
  12945. // TIME_VALID_OID_FLUSH_CTL
  12946. //
  12947. // pvPara == PCCTL_CONTEXT, the CTL to flush
  12948. //
  12949. // TIME_VALID_OID_FLUSH_CRL
  12950. //
  12951. // pvPara == PCCRL_CONTEXT, the CRL to flush
  12952. //
  12953. // TIME_VALID_OID_FLUSH_CRL_FROM_CERT
  12954. //
  12955. // pvPara == PCCERT_CONTEXT, the subject cert's CRL to flush
  12956. //
  12957. // TIME_VALID_OID_FLUSH_FRESHEST_CRL_FROM_CERT
  12958. //
  12959. // pvPara == PCCERT_CONTEXT, the subject cert's freshest CRL to flush
  12960. //
  12961. // TIME_VALID_OID_FLUSH_FRESHEST_CRL_FROM_CRL
  12962. //
  12963. // pvPara == PCCERT_CRL_CONTEXT_PAIR, the subject cert and its base CRL's
  12964. // freshest CRL to flush
  12965. //
  12966. #define TIME_VALID_OID_FLUSH_CTL ((LPCSTR)1)
  12967. #define TIME_VALID_OID_FLUSH_CRL ((LPCSTR)2)
  12968. #define TIME_VALID_OID_FLUSH_CRL_FROM_CERT ((LPCSTR)3)
  12969. #define TIME_VALID_OID_FLUSH_FRESHEST_CRL_FROM_CERT ((LPCSTR)4)
  12970. #define TIME_VALID_OID_FLUSH_FRESHEST_CRL_FROM_CRL ((LPCSTR)5)
  12971. //-------------------------------------------------------------------------
  12972. // Data Protection APIs
  12973. //-------------------------------------------------------------------------
  12974. //
  12975. // Data protection APIs enable applications to easily secure data.
  12976. //
  12977. // The base provider provides protection based on the users' logon
  12978. // credentials. The data secured with these APIs follow the same
  12979. // roaming characteristics as HKCU -- if HKCU roams, the data
  12980. // protected by the base provider may roam as well. This makes
  12981. // the API ideal for the munging of data stored in the registry.
  12982. //
  12983. //
  12984. // Prompt struct -- what to tell users about the access
  12985. //
  12986. typedef struct _CRYPTPROTECT_PROMPTSTRUCT
  12987. {
  12988. DWORD cbSize;
  12989. DWORD dwPromptFlags;
  12990. HWND hwndApp;
  12991. LPCWSTR szPrompt;
  12992. } CRYPTPROTECT_PROMPTSTRUCT, *PCRYPTPROTECT_PROMPTSTRUCT;
  12993. //
  12994. // base provider action
  12995. //
  12996. #define CRYPTPROTECT_DEFAULT_PROVIDER { 0xdf9d8cd0, 0x1501, 0x11d1, {0x8c, 0x7a, 0x00, 0xc0, 0x4f, 0xc2, 0x97, 0xeb} }
  12997. //
  12998. // CryptProtect PromptStruct dwPromtFlags
  12999. //
  13000. //
  13001. // prompt on unprotect
  13002. #define CRYPTPROTECT_PROMPT_ON_UNPROTECT 0x1 // 1<<0
  13003. //
  13004. // prompt on protect
  13005. #define CRYPTPROTECT_PROMPT_ON_PROTECT 0x2 // 1<<1
  13006. #define CRYPTPROTECT_PROMPT_RESERVED 0x04 // reserved, do not use.
  13007. //
  13008. // default to strong variant UI protection (user supplied password currently).
  13009. #define CRYPTPROTECT_PROMPT_STRONG 0x08 // 1<<3
  13010. //
  13011. // require strong variant UI protection (user supplied password currently).
  13012. #define CRYPTPROTECT_PROMPT_REQUIRE_STRONG 0x10 // 1<<4
  13013. //
  13014. // CryptProtectData and CryptUnprotectData dwFlags
  13015. //
  13016. // for remote-access situations where ui is not an option
  13017. // if UI was specified on protect or unprotect operation, the call
  13018. // will fail and GetLastError() will indicate ERROR_PASSWORD_RESTRICTION
  13019. #define CRYPTPROTECT_UI_FORBIDDEN 0x1
  13020. //
  13021. // per machine protected data -- any user on machine where CryptProtectData
  13022. // took place may CryptUnprotectData
  13023. #define CRYPTPROTECT_LOCAL_MACHINE 0x4
  13024. //
  13025. // force credential synchronize during CryptProtectData()
  13026. // Synchronize is only operation that occurs during this operation
  13027. #define CRYPTPROTECT_CRED_SYNC 0x8
  13028. //
  13029. // Generate an Audit on protect and unprotect operations
  13030. //
  13031. #define CRYPTPROTECT_AUDIT 0x10
  13032. //
  13033. // Protect data with a non-recoverable key
  13034. //
  13035. #define CRYPTPROTECT_NO_RECOVERY 0x20
  13036. //
  13037. // Verify the protection of a protected blob
  13038. //
  13039. #define CRYPTPROTECT_VERIFY_PROTECTION 0x40
  13040. //
  13041. // Regenerate the local machine protection
  13042. //
  13043. #define CRYPTPROTECT_CRED_REGENERATE 0x80
  13044. // flags reserved for system use
  13045. #define CRYPTPROTECT_FIRST_RESERVED_FLAGVAL 0x0FFFFFFF
  13046. #define CRYPTPROTECT_LAST_RESERVED_FLAGVAL 0xFFFFFFFF
  13047. //
  13048. // flags specific to base provider
  13049. //
  13050. WINCRYPT32API
  13051. BOOL
  13052. WINAPI
  13053. CryptProtectData(
  13054. IN DATA_BLOB* pDataIn,
  13055. IN LPCWSTR szDataDescr,
  13056. IN OPTIONAL DATA_BLOB* pOptionalEntropy,
  13057. IN PVOID pvReserved,
  13058. IN OPTIONAL CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct,
  13059. IN DWORD dwFlags,
  13060. OUT DATA_BLOB* pDataOut // out encr blob
  13061. );
  13062. WINCRYPT32API
  13063. BOOL
  13064. WINAPI
  13065. CryptUnprotectData(
  13066. IN DATA_BLOB* pDataIn, // in encr blob
  13067. OUT OPTIONAL LPWSTR* ppszDataDescr, // out
  13068. IN OPTIONAL DATA_BLOB* pOptionalEntropy,
  13069. IN PVOID pvReserved,
  13070. IN OPTIONAL CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct,
  13071. IN DWORD dwFlags,
  13072. OUT DATA_BLOB* pDataOut
  13073. );
  13074. //
  13075. // The buffer length passed into CryptProtectMemory and CryptUnprotectMemory
  13076. // must be a multiple of this length (or zero).
  13077. //
  13078. #define CRYPTPROTECTMEMORY_BLOCK_SIZE 16
  13079. //
  13080. // CryptProtectMemory/CryptUnprotectMemory dwFlags
  13081. //
  13082. //
  13083. // Encrypt/Decrypt within current process context.
  13084. //
  13085. #define CRYPTPROTECTMEMORY_SAME_PROCESS 0x00
  13086. //
  13087. // Encrypt/Decrypt across process boundaries.
  13088. // eg: encrypted buffer passed across LPC to another process which calls CryptUnprotectMemory.
  13089. //
  13090. #define CRYPTPROTECTMEMORY_CROSS_PROCESS 0x01
  13091. //
  13092. // Encrypt/Decrypt across callers with same LogonId.
  13093. // eg: encrypted buffer passed across LPC to another process which calls CryptUnprotectMemory whilst impersonating.
  13094. //
  13095. #define CRYPTPROTECTMEMORY_SAME_LOGON 0x02
  13096. WINCRYPT32API
  13097. BOOL
  13098. WINAPI
  13099. CryptProtectMemory(
  13100. IN OUT LPVOID pDataIn, // in out data to encrypt
  13101. IN DWORD cbDataIn, // multiple of CRYPTPROTECTMEMORY_BLOCK_SIZE
  13102. IN DWORD dwFlags
  13103. );
  13104. WINCRYPT32API
  13105. BOOL
  13106. WINAPI
  13107. CryptUnprotectMemory(
  13108. IN OUT LPVOID pDataIn, // in out data to decrypt
  13109. IN DWORD cbDataIn, // multiple of CRYPTPROTECTMEMORY_BLOCK_SIZE
  13110. IN DWORD dwFlags
  13111. );
  13112. //+=========================================================================
  13113. // Helper functions to build certificates
  13114. //==========================================================================
  13115. //+-------------------------------------------------------------------------
  13116. //
  13117. // Builds a self-signed certificate and returns a PCCERT_CONTEXT representing
  13118. // the certificate. A hProv must be specified to build the cert context.
  13119. //
  13120. // pSubjectIssuerBlob is the DN for the certifcate. If an alternate subject
  13121. // name is desired it must be specified as an extension in the pExtensions
  13122. // parameter. pSubjectIssuerBlob can NOT be NULL, so minimually an empty DN
  13123. // must be specified.
  13124. //
  13125. // By default:
  13126. // pKeyProvInfo - The CSP is queried for the KeyProvInfo parameters. Only the Provider,
  13127. // Provider Type and Container is queried. Many CSPs don't support these
  13128. // queries and will cause a failure. In such cases the pKeyProvInfo
  13129. // must be specified (RSA BASE works fine).
  13130. //
  13131. // pSignatureAlgorithm - will default to SHA1RSA
  13132. // pStartTime will default to the current time
  13133. // pEndTime will default to 1 year
  13134. // pEntensions will be empty.
  13135. //
  13136. // The returned PCCERT_CONTEXT will reference the private keys by setting the
  13137. // CERT_KEY_PROV_INFO_PROP_ID. However, if this property is not desired specify the
  13138. // CERT_CREATE_SELFSIGN_NO_KEY_INFO in dwFlags.
  13139. //
  13140. // If the cert being built is only a dummy placeholder cert for speed it may not
  13141. // need to be signed. Signing of the cert is skipped if CERT_CREATE_SELFSIGN_NO_SIGN
  13142. // is specified in dwFlags.
  13143. //
  13144. //--------------------------------------------------------------------------
  13145. WINCRYPT32API
  13146. PCCERT_CONTEXT
  13147. WINAPI
  13148. CertCreateSelfSignCertificate(
  13149. IN HCRYPTPROV hProv,
  13150. IN PCERT_NAME_BLOB pSubjectIssuerBlob,
  13151. IN DWORD dwFlags,
  13152. OPTIONAL PCRYPT_KEY_PROV_INFO pKeyProvInfo,
  13153. OPTIONAL PCRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm,
  13154. OPTIONAL PSYSTEMTIME pStartTime,
  13155. OPTIONAL PSYSTEMTIME pEndTime,
  13156. OPTIONAL PCERT_EXTENSIONS pExtensions
  13157. );
  13158. #define CERT_CREATE_SELFSIGN_NO_SIGN 1
  13159. #define CERT_CREATE_SELFSIGN_NO_KEY_INFO 2
  13160. //+=========================================================================
  13161. // Key Identifier Property Data Structures and APIs
  13162. //==========================================================================
  13163. //+-------------------------------------------------------------------------
  13164. // Get the property for the specified Key Identifier.
  13165. //
  13166. // The Key Identifier is the SHA1 hash of the encoded CERT_PUBLIC_KEY_INFO.
  13167. // The Key Identifier for a certificate can be obtained by getting the
  13168. // certificate's CERT_KEY_IDENTIFIER_PROP_ID. The
  13169. // CryptCreateKeyIdentifierFromCSP API can be called to create the Key
  13170. // Identifier from a CSP Public Key Blob.
  13171. //
  13172. // A Key Identifier can have the same properties as a certificate context.
  13173. // CERT_KEY_PROV_INFO_PROP_ID is the property of most interest.
  13174. // For CERT_KEY_PROV_INFO_PROP_ID, pvData points to a CRYPT_KEY_PROV_INFO
  13175. // structure. Elements pointed to by fields in the pvData structure follow the
  13176. // structure. Therefore, *pcbData will exceed the size of the structure.
  13177. //
  13178. // If CRYPT_KEYID_ALLOC_FLAG is set, then, *pvData is updated with a
  13179. // pointer to allocated memory. LocalFree() must be called to free the
  13180. // allocated memory.
  13181. //
  13182. // By default, searches the CurrentUser's list of Key Identifiers.
  13183. // CRYPT_KEYID_MACHINE_FLAG can be set to search the LocalMachine's list
  13184. // of Key Identifiers. When CRYPT_KEYID_MACHINE_FLAG is set, pwszComputerName
  13185. // can also be set to specify the name of a remote computer to be searched
  13186. // instead of the local machine.
  13187. //--------------------------------------------------------------------------
  13188. WINCRYPT32API
  13189. BOOL
  13190. WINAPI
  13191. CryptGetKeyIdentifierProperty(
  13192. IN const CRYPT_HASH_BLOB *pKeyIdentifier,
  13193. IN DWORD dwPropId,
  13194. IN DWORD dwFlags,
  13195. IN OPTIONAL LPCWSTR pwszComputerName,
  13196. IN OPTIONAL void *pvReserved,
  13197. OUT void *pvData,
  13198. IN OUT DWORD *pcbData
  13199. );
  13200. // When the following flag is set, searches the LocalMachine instead of the
  13201. // CurrentUser. This flag is applicable to all the KeyIdentifierProperty APIs.
  13202. #define CRYPT_KEYID_MACHINE_FLAG 0x00000020
  13203. // When the following flag is set, *pvData is updated with a pointer to
  13204. // allocated memory. LocalFree() must be called to free the allocated memory.
  13205. #define CRYPT_KEYID_ALLOC_FLAG 0x00008000
  13206. //+-------------------------------------------------------------------------
  13207. // Set the property for the specified Key Identifier.
  13208. //
  13209. // For CERT_KEY_PROV_INFO_PROP_ID pvData points to the
  13210. // CRYPT_KEY_PROV_INFO data structure. For all other properties, pvData
  13211. // points to a CRYPT_DATA_BLOB.
  13212. //
  13213. // Setting pvData == NULL, deletes the property.
  13214. //
  13215. // Set CRYPT_KEYID_MACHINE_FLAG to set the property for a LocalMachine
  13216. // Key Identifier. Set pwszComputerName, to select a remote computer.
  13217. //
  13218. // If CRYPT_KEYID_DELETE_FLAG is set, the Key Identifier and all its
  13219. // properties is deleted.
  13220. //
  13221. // If CRYPT_KEYID_SET_NEW_FLAG is set, the set fails if the property already
  13222. // exists. For an existing property, FALSE is returned with LastError set to
  13223. // CRYPT_E_EXISTS.
  13224. //--------------------------------------------------------------------------
  13225. WINCRYPT32API
  13226. BOOL
  13227. WINAPI
  13228. CryptSetKeyIdentifierProperty(
  13229. IN const CRYPT_HASH_BLOB *pKeyIdentifier,
  13230. IN DWORD dwPropId,
  13231. IN DWORD dwFlags,
  13232. IN OPTIONAL LPCWSTR pwszComputerName,
  13233. IN OPTIONAL void *pvReserved,
  13234. IN const void *pvData
  13235. );
  13236. // When the following flag is set, the Key Identifier and all its properties
  13237. // are deleted.
  13238. #define CRYPT_KEYID_DELETE_FLAG 0x00000010
  13239. // When the following flag is set, the set fails if the property already
  13240. // exists.
  13241. #define CRYPT_KEYID_SET_NEW_FLAG 0x00002000
  13242. //+-------------------------------------------------------------------------
  13243. // For CERT_KEY_PROV_INFO_PROP_ID, rgppvData[] points to a
  13244. // CRYPT_KEY_PROV_INFO.
  13245. //
  13246. // Return FALSE to stop the enumeration.
  13247. //--------------------------------------------------------------------------
  13248. typedef BOOL (WINAPI *PFN_CRYPT_ENUM_KEYID_PROP)(
  13249. IN const CRYPT_HASH_BLOB *pKeyIdentifier,
  13250. IN DWORD dwFlags,
  13251. IN void *pvReserved,
  13252. IN void *pvArg,
  13253. IN DWORD cProp,
  13254. IN DWORD *rgdwPropId,
  13255. IN void **rgpvData,
  13256. IN DWORD *rgcbData
  13257. );
  13258. //+-------------------------------------------------------------------------
  13259. // Enumerate the Key Identifiers.
  13260. //
  13261. // If pKeyIdentifier is NULL, enumerates all Key Identifers. Otherwise,
  13262. // calls the callback for the specified KeyIdentifier. If dwPropId is
  13263. // 0, calls the callback with all the properties. Otherwise, only calls
  13264. // the callback with the specified property (cProp = 1).
  13265. // Furthermore, when dwPropId is specified, skips KeyIdentifiers not
  13266. // having the property.
  13267. //
  13268. // Set CRYPT_KEYID_MACHINE_FLAG to enumerate the LocalMachine
  13269. // Key Identifiers. Set pwszComputerName, to enumerate Key Identifiers on
  13270. // a remote computer.
  13271. //--------------------------------------------------------------------------
  13272. WINCRYPT32API
  13273. BOOL
  13274. WINAPI
  13275. CryptEnumKeyIdentifierProperties(
  13276. IN OPTIONAL const CRYPT_HASH_BLOB *pKeyIdentifier,
  13277. IN DWORD dwPropId,
  13278. IN DWORD dwFlags,
  13279. IN OPTIONAL LPCWSTR pwszComputerName,
  13280. IN OPTIONAL void *pvReserved,
  13281. IN OPTIONAL void *pvArg,
  13282. IN PFN_CRYPT_ENUM_KEYID_PROP pfnEnum
  13283. );
  13284. //+-------------------------------------------------------------------------
  13285. // Create a KeyIdentifier from the CSP Public Key Blob.
  13286. //
  13287. // Converts the CSP PUBLICKEYSTRUC into a X.509 CERT_PUBLIC_KEY_INFO and
  13288. // encodes. The encoded CERT_PUBLIC_KEY_INFO is SHA1 hashed to obtain
  13289. // the Key Identifier.
  13290. //
  13291. // By default, the pPubKeyStruc->aiKeyAlg is used to find the appropriate
  13292. // public key Object Identifier. pszPubKeyOID can be set to override
  13293. // the default OID obtained from the aiKeyAlg.
  13294. //--------------------------------------------------------------------------
  13295. WINCRYPT32API
  13296. BOOL
  13297. WINAPI
  13298. CryptCreateKeyIdentifierFromCSP(
  13299. IN DWORD dwCertEncodingType,
  13300. IN OPTIONAL LPCSTR pszPubKeyOID,
  13301. IN const PUBLICKEYSTRUC *pPubKeyStruc,
  13302. IN DWORD cbPubKeyStruc,
  13303. IN DWORD dwFlags,
  13304. IN OPTIONAL void *pvReserved,
  13305. OUT BYTE *pbHash,
  13306. IN OUT DWORD *pcbHash
  13307. );
  13308. //+=========================================================================
  13309. // Certificate Chaining Infrastructure
  13310. //==========================================================================
  13311. #define CERT_CHAIN_CONFIG_REGPATH \
  13312. L"Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CertDllCreateCertificateChainEngine\\Config"
  13313. // The following are REG_DWORD's. These configuration parameters are used
  13314. // to restrict Authority Info Access (AIA) URL retrieval.
  13315. #define CERT_CHAIN_DISABLE_AIA_URL_RETRIEVAL_VALUE_NAME \
  13316. L"DisableAIAUrlRetrieval"
  13317. // By default AIA Url Retrieval is enabled. Set this registry value to nonzero
  13318. // to disable
  13319. #define CERT_CHAIN_MAX_AIA_URL_COUNT_IN_CERT_VALUE_NAME \
  13320. L"MaxAIAUrlCountInCert"
  13321. #define CERT_CHAIN_MAX_AIA_URL_COUNT_IN_CERT_DEFAULT 5
  13322. #define CERT_CHAIN_MAX_AIA_URL_RETRIEVAL_COUNT_PER_CHAIN_VALUE_NAME \
  13323. L"MaxAIAUrlRetrievalCountPerChain"
  13324. #define CERT_CHAIN_MAX_AIA_URL_RETRIEVAL_COUNT_PER_CHAIN_DEFAULT 10
  13325. #define CERT_CHAIN_MAX_AIA_URL_RETRIEVAL_BYTE_COUNT_VALUE_NAME \
  13326. L"MaxAIAUrlRetrievalByteCount"
  13327. #define CERT_CHAIN_MAX_AIA_URL_RETRIEVAL_BYTE_COUNT_DEFAULT 100000
  13328. #define CERT_CHAIN_MAX_AIA_URL_RETRIEVAL_CERT_COUNT_VALUE_NAME \
  13329. L"MaxAIAUrlRetrievalCertCount"
  13330. #define CERT_CHAIN_MAX_AIA_URL_RETRIEVAL_CERT_COUNT_DEFAULT 10
  13331. //
  13332. // The chain engine defines the store namespace and cache partitioning for
  13333. // the Certificate Chaining infrastructure. A default chain engine
  13334. // is defined for the process which uses all default system stores e.g.
  13335. // Root, CA, Trust, for chain building and caching. If an application
  13336. // wishes to define its own store namespace or have its own partitioned
  13337. // cache then it can create its own chain engine. It is advisable to create
  13338. // a chain engine at application startup and use it throughout the lifetime
  13339. // of the application in order to get optimal caching behavior
  13340. //
  13341. typedef HANDLE HCERTCHAINENGINE;
  13342. #define HCCE_CURRENT_USER ((HCERTCHAINENGINE)NULL)
  13343. #define HCCE_LOCAL_MACHINE ((HCERTCHAINENGINE)0x1)
  13344. //
  13345. // Create a certificate chain engine.
  13346. //
  13347. //
  13348. // Configuration parameters for the certificate chain engine
  13349. //
  13350. // hRestrictedRoot - restrict the root store (must be a subset of "Root")
  13351. //
  13352. // hRestrictedTrust - restrict the store for CTLs
  13353. //
  13354. // hRestrictedOther - restrict the store for certs and CRLs
  13355. //
  13356. // cAdditionalStore, rghAdditionalStore - additional stores
  13357. //
  13358. // NOTE: The algorithm used to define the stores for the engine is as
  13359. // follows:
  13360. //
  13361. // hRoot = hRestrictedRoot or System Store "Root"
  13362. //
  13363. // hTrust = hRestrictedTrust or hWorld (defined later)
  13364. //
  13365. // hOther = hRestrictedOther or (hRestrictedTrust == NULL) ? hWorld :
  13366. // hRestrictedTrust + hWorld
  13367. //
  13368. // hWorld = hRoot + "CA" + "My" + "Trust" + rghAdditionalStore
  13369. //
  13370. // dwFlags - flags
  13371. //
  13372. // CERT_CHAIN_CACHE_END_CERT - information will be cached on
  13373. // the end cert as well as the other
  13374. // certs in the chain
  13375. //
  13376. // CERT_CHAIN_THREAD_STORE_SYNC - use separate thread for store syncs
  13377. // and related cache updates
  13378. //
  13379. // CERT_CHAIN_CACHE_ONLY_URL_RETRIEVAL - don't hit the wire to get
  13380. // URL based objects
  13381. //
  13382. // dwUrlRetrievalTimeout - timeout for wire based URL object retrievals
  13383. // (milliseconds)
  13384. //
  13385. #define CERT_CHAIN_CACHE_END_CERT 0x00000001
  13386. #define CERT_CHAIN_THREAD_STORE_SYNC 0x00000002
  13387. #define CERT_CHAIN_CACHE_ONLY_URL_RETRIEVAL 0x00000004
  13388. #define CERT_CHAIN_USE_LOCAL_MACHINE_STORE 0x00000008
  13389. #define CERT_CHAIN_ENABLE_CACHE_AUTO_UPDATE 0x00000010
  13390. #define CERT_CHAIN_ENABLE_SHARE_STORE 0x00000020
  13391. typedef struct _CERT_CHAIN_ENGINE_CONFIG {
  13392. DWORD cbSize;
  13393. HCERTSTORE hRestrictedRoot;
  13394. HCERTSTORE hRestrictedTrust;
  13395. HCERTSTORE hRestrictedOther;
  13396. DWORD cAdditionalStore;
  13397. HCERTSTORE* rghAdditionalStore;
  13398. DWORD dwFlags;
  13399. DWORD dwUrlRetrievalTimeout; // milliseconds
  13400. DWORD MaximumCachedCertificates;
  13401. DWORD CycleDetectionModulus;
  13402. } CERT_CHAIN_ENGINE_CONFIG, *PCERT_CHAIN_ENGINE_CONFIG;
  13403. WINCRYPT32API
  13404. BOOL
  13405. WINAPI
  13406. CertCreateCertificateChainEngine (
  13407. IN PCERT_CHAIN_ENGINE_CONFIG pConfig,
  13408. OUT HCERTCHAINENGINE* phChainEngine
  13409. );
  13410. //
  13411. // Free a certificate trust engine
  13412. //
  13413. WINCRYPT32API
  13414. VOID
  13415. WINAPI
  13416. CertFreeCertificateChainEngine (
  13417. IN HCERTCHAINENGINE hChainEngine
  13418. );
  13419. //
  13420. // Resync the certificate chain engine. This resync's the stores backing
  13421. // the engine and updates the engine caches.
  13422. //
  13423. WINCRYPT32API
  13424. BOOL
  13425. WINAPI
  13426. CertResyncCertificateChainEngine (
  13427. IN HCERTCHAINENGINE hChainEngine
  13428. );
  13429. //
  13430. // When an application requests a certificate chain, the data structure
  13431. // returned is in the form of a CERT_CHAIN_CONTEXT. This contains
  13432. // an array of CERT_SIMPLE_CHAIN where each simple chain goes from
  13433. // an end cert to a self signed cert and the chain context connects simple
  13434. // chains via trust lists. Each simple chain contains the chain of
  13435. // certificates, summary trust information about the chain and trust information
  13436. // about each certificate element in the chain.
  13437. //
  13438. //
  13439. // Trust status bits
  13440. //
  13441. typedef struct _CERT_TRUST_STATUS {
  13442. DWORD dwErrorStatus;
  13443. DWORD dwInfoStatus;
  13444. } CERT_TRUST_STATUS, *PCERT_TRUST_STATUS;
  13445. //
  13446. // The following are error status bits
  13447. //
  13448. // These can be applied to certificates and chains
  13449. #define CERT_TRUST_NO_ERROR 0x00000000
  13450. #define CERT_TRUST_IS_NOT_TIME_VALID 0x00000001
  13451. #define CERT_TRUST_IS_NOT_TIME_NESTED 0x00000002
  13452. #define CERT_TRUST_IS_REVOKED 0x00000004
  13453. #define CERT_TRUST_IS_NOT_SIGNATURE_VALID 0x00000008
  13454. #define CERT_TRUST_IS_NOT_VALID_FOR_USAGE 0x00000010
  13455. #define CERT_TRUST_IS_UNTRUSTED_ROOT 0x00000020
  13456. #define CERT_TRUST_REVOCATION_STATUS_UNKNOWN 0x00000040
  13457. #define CERT_TRUST_IS_CYCLIC 0x00000080
  13458. #define CERT_TRUST_INVALID_EXTENSION 0x00000100
  13459. #define CERT_TRUST_INVALID_POLICY_CONSTRAINTS 0x00000200
  13460. #define CERT_TRUST_INVALID_BASIC_CONSTRAINTS 0x00000400
  13461. #define CERT_TRUST_INVALID_NAME_CONSTRAINTS 0x00000800
  13462. #define CERT_TRUST_HAS_NOT_SUPPORTED_NAME_CONSTRAINT 0x00001000
  13463. #define CERT_TRUST_HAS_NOT_DEFINED_NAME_CONSTRAINT 0x00002000
  13464. #define CERT_TRUST_HAS_NOT_PERMITTED_NAME_CONSTRAINT 0x00004000
  13465. #define CERT_TRUST_HAS_EXCLUDED_NAME_CONSTRAINT 0x00008000
  13466. #define CERT_TRUST_IS_OFFLINE_REVOCATION 0x01000000
  13467. #define CERT_TRUST_NO_ISSUANCE_CHAIN_POLICY 0x02000000
  13468. // These can be applied to chains only
  13469. #define CERT_TRUST_IS_PARTIAL_CHAIN 0x00010000
  13470. #define CERT_TRUST_CTL_IS_NOT_TIME_VALID 0x00020000
  13471. #define CERT_TRUST_CTL_IS_NOT_SIGNATURE_VALID 0x00040000
  13472. #define CERT_TRUST_CTL_IS_NOT_VALID_FOR_USAGE 0x00080000
  13473. //
  13474. // The following are info status bits
  13475. //
  13476. // These can be applied to certificates only
  13477. #define CERT_TRUST_HAS_EXACT_MATCH_ISSUER 0x00000001
  13478. #define CERT_TRUST_HAS_KEY_MATCH_ISSUER 0x00000002
  13479. #define CERT_TRUST_HAS_NAME_MATCH_ISSUER 0x00000004
  13480. #define CERT_TRUST_IS_SELF_SIGNED 0x00000008
  13481. // These can be applied to certificates and chains
  13482. #define CERT_TRUST_HAS_PREFERRED_ISSUER 0x00000100
  13483. #define CERT_TRUST_HAS_ISSUANCE_CHAIN_POLICY 0x00000200
  13484. #define CERT_TRUST_HAS_VALID_NAME_CONSTRAINTS 0x00000400
  13485. // These can be applied to chains only
  13486. #define CERT_TRUST_IS_COMPLEX_CHAIN 0x00010000
  13487. //
  13488. // Each certificate context in a simple chain has a corresponding chain element
  13489. // in the simple chain context
  13490. //
  13491. // dwErrorStatus has CERT_TRUST_IS_REVOKED, pRevocationInfo set
  13492. // dwErrorStatus has CERT_TRUST_REVOCATION_STATUS_UNKNOWN, pRevocationInfo set
  13493. //
  13494. // Note that the post processing revocation supported in the first
  13495. // version only sets cbSize and dwRevocationResult. Everything else
  13496. // is NULL
  13497. //
  13498. //
  13499. // Revocation Information
  13500. //
  13501. typedef struct _CERT_REVOCATION_INFO {
  13502. DWORD cbSize;
  13503. DWORD dwRevocationResult;
  13504. LPCSTR pszRevocationOid;
  13505. LPVOID pvOidSpecificInfo;
  13506. // fHasFreshnessTime is only set if we are able to retrieve revocation
  13507. // information. For a CRL its CurrentTime - ThisUpdate.
  13508. BOOL fHasFreshnessTime;
  13509. DWORD dwFreshnessTime; // seconds
  13510. // NonNULL for CRL base revocation checking
  13511. PCERT_REVOCATION_CRL_INFO pCrlInfo;
  13512. } CERT_REVOCATION_INFO, *PCERT_REVOCATION_INFO;
  13513. //
  13514. // Trust List Information
  13515. //
  13516. typedef struct _CERT_TRUST_LIST_INFO {
  13517. DWORD cbSize;
  13518. PCTL_ENTRY pCtlEntry;
  13519. PCCTL_CONTEXT pCtlContext;
  13520. } CERT_TRUST_LIST_INFO, *PCERT_TRUST_LIST_INFO;
  13521. //
  13522. // Chain Element
  13523. //
  13524. typedef struct _CERT_CHAIN_ELEMENT {
  13525. DWORD cbSize;
  13526. PCCERT_CONTEXT pCertContext;
  13527. CERT_TRUST_STATUS TrustStatus;
  13528. PCERT_REVOCATION_INFO pRevocationInfo;
  13529. PCERT_ENHKEY_USAGE pIssuanceUsage; // If NULL, any
  13530. PCERT_ENHKEY_USAGE pApplicationUsage; // If NULL, any
  13531. LPCWSTR pwszExtendedErrorInfo; // If NULL, none
  13532. } CERT_CHAIN_ELEMENT, *PCERT_CHAIN_ELEMENT;
  13533. //
  13534. // The simple chain is an array of chain elements and a summary trust status
  13535. // for the chain
  13536. //
  13537. // rgpElements[0] is the end certificate chain element
  13538. //
  13539. // rgpElements[cElement-1] is the self-signed "root" certificate chain element
  13540. //
  13541. typedef struct _CERT_SIMPLE_CHAIN {
  13542. DWORD cbSize;
  13543. CERT_TRUST_STATUS TrustStatus;
  13544. DWORD cElement;
  13545. PCERT_CHAIN_ELEMENT* rgpElement;
  13546. PCERT_TRUST_LIST_INFO pTrustListInfo;
  13547. // fHasRevocationFreshnessTime is only set if we are able to retrieve
  13548. // revocation information for all elements checked for revocation.
  13549. // For a CRL its CurrentTime - ThisUpdate.
  13550. //
  13551. // dwRevocationFreshnessTime is the largest time across all elements
  13552. // checked.
  13553. BOOL fHasRevocationFreshnessTime;
  13554. DWORD dwRevocationFreshnessTime; // seconds
  13555. } CERT_SIMPLE_CHAIN, *PCERT_SIMPLE_CHAIN;
  13556. //
  13557. // And the chain context contains an array of simple chains and summary trust
  13558. // status for all the connected simple chains
  13559. //
  13560. // rgpChains[0] is the end certificate simple chain
  13561. //
  13562. // rgpChains[cChain-1] is the final (possibly trust list signer) chain which
  13563. // ends in a certificate which is contained in the root store
  13564. //
  13565. typedef struct _CERT_CHAIN_CONTEXT CERT_CHAIN_CONTEXT, *PCERT_CHAIN_CONTEXT;
  13566. typedef const CERT_CHAIN_CONTEXT *PCCERT_CHAIN_CONTEXT;
  13567. struct _CERT_CHAIN_CONTEXT {
  13568. DWORD cbSize;
  13569. CERT_TRUST_STATUS TrustStatus;
  13570. DWORD cChain;
  13571. PCERT_SIMPLE_CHAIN* rgpChain;
  13572. // Following is returned when CERT_CHAIN_RETURN_LOWER_QUALITY_CONTEXTS
  13573. // is set in dwFlags
  13574. DWORD cLowerQualityChainContext;
  13575. PCCERT_CHAIN_CONTEXT* rgpLowerQualityChainContext;
  13576. // fHasRevocationFreshnessTime is only set if we are able to retrieve
  13577. // revocation information for all elements checked for revocation.
  13578. // For a CRL its CurrentTime - ThisUpdate.
  13579. //
  13580. // dwRevocationFreshnessTime is the largest time across all elements
  13581. // checked.
  13582. BOOL fHasRevocationFreshnessTime;
  13583. DWORD dwRevocationFreshnessTime; // seconds
  13584. };
  13585. //
  13586. // When building a chain, the there are various parameters used for finding
  13587. // issuing certificates and trust lists. They are identified in the
  13588. // following structure
  13589. //
  13590. // Default usage match type is AND with value zero
  13591. #define USAGE_MATCH_TYPE_AND 0x00000000
  13592. #define USAGE_MATCH_TYPE_OR 0x00000001
  13593. typedef struct _CERT_USAGE_MATCH {
  13594. DWORD dwType;
  13595. CERT_ENHKEY_USAGE Usage;
  13596. } CERT_USAGE_MATCH, *PCERT_USAGE_MATCH;
  13597. typedef struct _CTL_USAGE_MATCH {
  13598. DWORD dwType;
  13599. CTL_USAGE Usage;
  13600. } CTL_USAGE_MATCH, *PCTL_USAGE_MATCH;
  13601. typedef struct _CERT_CHAIN_PARA {
  13602. DWORD cbSize;
  13603. CERT_USAGE_MATCH RequestedUsage;
  13604. #ifdef CERT_CHAIN_PARA_HAS_EXTRA_FIELDS
  13605. // Note, if you #define CERT_CHAIN_PARA_HAS_EXTRA_FIELDS, then, you
  13606. // must zero all unused fields in this data structure.
  13607. // More fields could be added in a future release.
  13608. CERT_USAGE_MATCH RequestedIssuancePolicy;
  13609. DWORD dwUrlRetrievalTimeout; // milliseconds
  13610. BOOL fCheckRevocationFreshnessTime;
  13611. DWORD dwRevocationFreshnessTime; // seconds
  13612. #endif
  13613. } CERT_CHAIN_PARA, *PCERT_CHAIN_PARA;
  13614. //
  13615. // The following API is used for retrieving certificate chains
  13616. //
  13617. // Parameters:
  13618. //
  13619. // hChainEngine - the chain engine (namespace and cache) to use, NULL
  13620. // mean use the default chain engine
  13621. //
  13622. // pCertContext - the context we are retrieving the chain for, it
  13623. // will be the zero index element in the chain
  13624. //
  13625. // pTime - the point in time that we want the chain validated
  13626. // for. Note that the time does not affect trust list,
  13627. // revocation, or root store checking. NULL means use
  13628. // the current system time
  13629. //
  13630. // hAdditionalStore - additional store to use when looking up objects
  13631. //
  13632. // pChainPara - parameters for chain building
  13633. //
  13634. // dwFlags - flags such as should revocation checking be done
  13635. // on the chain?
  13636. //
  13637. // pvReserved - reserved parameter, must be NULL
  13638. //
  13639. // ppChainContext - chain context returned
  13640. //
  13641. // CERT_CHAIN_CACHE_END_CERT can be used here as well
  13642. // Revocation flags are in the high nibble
  13643. #define CERT_CHAIN_REVOCATION_CHECK_END_CERT 0x10000000
  13644. #define CERT_CHAIN_REVOCATION_CHECK_CHAIN 0x20000000
  13645. #define CERT_CHAIN_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT 0x40000000
  13646. #define CERT_CHAIN_REVOCATION_CHECK_CACHE_ONLY 0x80000000
  13647. // By default, the dwUrlRetrievalTimeout in pChainPara is the timeout used
  13648. // for each revocation URL wire retrieval. When the following flag is set,
  13649. // dwUrlRetrievalTimeout is the accumulative timeout across all
  13650. // revocation URL wire retrievals.
  13651. #define CERT_CHAIN_REVOCATION_ACCUMULATIVE_TIMEOUT 0x08000000
  13652. // First pass determines highest quality based upon:
  13653. // - Chain signature valid (higest quality bit of this set)
  13654. // - Complete chain
  13655. // - Trusted root (lowestest quality bit of this set)
  13656. // By default, second pass only considers paths >= highest first pass quality
  13657. #define CERT_CHAIN_DISABLE_PASS1_QUALITY_FILTERING 0x00000040
  13658. #define CERT_CHAIN_RETURN_LOWER_QUALITY_CONTEXTS 0x00000080
  13659. #define CERT_CHAIN_DISABLE_AUTH_ROOT_AUTO_UPDATE 0x00000100
  13660. // When this flag is set, pTime will be used as the timestamp time.
  13661. // pTime will be used to determine if the end certificate was valid at this
  13662. // time. Revocation checking will be relative to pTime.
  13663. // In addition, current time will also be used
  13664. // to determine if the certificate is still time valid. All remaining
  13665. // CA and root certificates will be checked using current time and not pTime.
  13666. //
  13667. // This flag was added 4/5/01 in WXP.
  13668. #define CERT_CHAIN_TIMESTAMP_TIME 0x00000200
  13669. WINCRYPT32API
  13670. BOOL
  13671. WINAPI
  13672. CertGetCertificateChain (
  13673. IN OPTIONAL HCERTCHAINENGINE hChainEngine,
  13674. IN PCCERT_CONTEXT pCertContext,
  13675. IN OPTIONAL LPFILETIME pTime,
  13676. IN OPTIONAL HCERTSTORE hAdditionalStore,
  13677. IN PCERT_CHAIN_PARA pChainPara,
  13678. IN DWORD dwFlags,
  13679. IN LPVOID pvReserved,
  13680. OUT PCCERT_CHAIN_CONTEXT* ppChainContext
  13681. );
  13682. //
  13683. // Free a certificate chain
  13684. //
  13685. WINCRYPT32API
  13686. VOID
  13687. WINAPI
  13688. CertFreeCertificateChain (
  13689. IN PCCERT_CHAIN_CONTEXT pChainContext
  13690. );
  13691. //
  13692. // Duplicate (add a reference to) a certificate chain
  13693. //
  13694. WINCRYPT32API
  13695. PCCERT_CHAIN_CONTEXT
  13696. WINAPI
  13697. CertDuplicateCertificateChain (
  13698. IN PCCERT_CHAIN_CONTEXT pChainContext
  13699. );
  13700. //
  13701. // Specific Revocation Type OID and structure definitions
  13702. //
  13703. //
  13704. // CRL Revocation OID
  13705. //
  13706. #define REVOCATION_OID_CRL_REVOCATION ((LPCSTR)1)
  13707. //
  13708. // For the CRL revocation OID the pvRevocationPara is NULL
  13709. //
  13710. //
  13711. // CRL Revocation Info
  13712. //
  13713. typedef struct _CRL_REVOCATION_INFO {
  13714. PCRL_ENTRY pCrlEntry;
  13715. PCCRL_CONTEXT pCrlContext;
  13716. PCCERT_CHAIN_CONTEXT pCrlIssuerChain;
  13717. } CRL_REVOCATION_INFO, *PCRL_REVOCATION_INFO;
  13718. //+-------------------------------------------------------------------------
  13719. // Find the first or next certificate chain context in the store.
  13720. //
  13721. // The chain context is found according to the dwFindFlags, dwFindType and
  13722. // its pvFindPara. See below for a list of the find types and its parameters.
  13723. //
  13724. // If the first or next chain context isn't found, NULL is returned.
  13725. // Otherwise, a pointer to a read only CERT_CHAIN_CONTEXT is returned.
  13726. // CERT_CHAIN_CONTEXT must be freed by calling CertFreeCertificateChain
  13727. // or is freed when passed as the
  13728. // pPrevChainContext on a subsequent call. CertDuplicateCertificateChain
  13729. // can be called to make a duplicate.
  13730. //
  13731. // pPrevChainContext MUST BE NULL on the first
  13732. // call to find the chain context. To find the next chain context, the
  13733. // pPrevChainContext is set to the CERT_CHAIN_CONTEXT returned by a previous
  13734. // call.
  13735. //
  13736. // NOTE: a NON-NULL pPrevChainContext is always CertFreeCertificateChain'ed by
  13737. // this function, even for an error.
  13738. //--------------------------------------------------------------------------
  13739. WINCRYPT32API
  13740. PCCERT_CHAIN_CONTEXT
  13741. WINAPI
  13742. CertFindChainInStore(
  13743. IN HCERTSTORE hCertStore,
  13744. IN DWORD dwCertEncodingType,
  13745. IN DWORD dwFindFlags,
  13746. IN DWORD dwFindType,
  13747. IN const void *pvFindPara,
  13748. IN PCCERT_CHAIN_CONTEXT pPrevChainContext
  13749. );
  13750. #define CERT_CHAIN_FIND_BY_ISSUER 1
  13751. //+-------------------------------------------------------------------------
  13752. // CERT_CHAIN_FIND_BY_ISSUER
  13753. //
  13754. // Find a certificate chain having a private key for the end certificate and
  13755. // matching one of the given issuer names. A matching dwKeySpec and
  13756. // enhanced key usage can also be specified. Additionally a callback can
  13757. // be provided for even more caller provided filtering before building the
  13758. // chain.
  13759. //
  13760. // By default, only the issuers in the first simple chain are compared
  13761. // for a name match. CERT_CHAIN_FIND_BY_ISSUER_COMPLEX_CHAIN_FLAG can
  13762. // be set in dwFindFlags to match issuers in all the simple chains.
  13763. //
  13764. // CERT_CHAIN_FIND_BY_ISSUER_NO_KEY_FLAG can be set in dwFindFlags to
  13765. // not check if the end certificate has a private key.
  13766. //
  13767. // CERT_CHAIN_FIND_BY_ISSUER_COMPARE_KEY_FLAG can be set in dwFindFlags
  13768. // to compare the public key in the end certificate with the crypto
  13769. // provider's public key. The dwAcquirePrivateKeyFlags can be set
  13770. // in CERT_CHAIN_FIND_BY_ISSUER_PARA to enable caching of the private key's
  13771. // HKEY returned by the CSP.
  13772. //
  13773. // If dwCertEncodingType == 0, defaults to X509_ASN_ENCODING for the
  13774. // array of encoded issuer names.
  13775. //
  13776. // By default, the hCertStore passed to CertFindChainInStore, is passed
  13777. // as an additional store to CertGetCertificateChain.
  13778. // CERT_CHAIN_FIND_BY_ISSUER_CACHE_ONLY_FLAG can be set in dwFindFlags
  13779. // to improve performance by only searching the cached system stores
  13780. // (root, my, ca, trust) to find the issuer certificates. If you are doing
  13781. // a find in the "my" system store, than, this flag should be set to
  13782. // improve performance.
  13783. //
  13784. // Setting CERT_CHAIN_FIND_BY_ISSUER_LOCAL_MACHINE_FLAG in dwFindFlags
  13785. // restricts CertGetCertificateChain to search the Local Machine
  13786. // cached system stores instead of the Current User's.
  13787. //
  13788. // Setting CERT_CHAIN_FIND_BY_ISSUER_CACHE_ONLY_URL_FLAG in dwFindFlags
  13789. // restricts CertGetCertificateChain to only search the URL cache
  13790. // and not hit the wire.
  13791. //--------------------------------------------------------------------------
  13792. // Returns FALSE to skip this certificate. Otherwise, returns TRUE to
  13793. // build a chain for this certificate.
  13794. typedef BOOL (WINAPI *PFN_CERT_CHAIN_FIND_BY_ISSUER_CALLBACK)(
  13795. IN PCCERT_CONTEXT pCert,
  13796. IN void *pvFindArg
  13797. );
  13798. typedef struct _CERT_CHAIN_FIND_BY_ISSUER_PARA {
  13799. DWORD cbSize;
  13800. // If pszUsageIdentifier == NULL, matches any usage.
  13801. LPCSTR pszUsageIdentifier;
  13802. // If dwKeySpec == 0, matches any KeySpec
  13803. DWORD dwKeySpec;
  13804. // When CERT_CHAIN_FIND_BY_ISSUER_COMPARE_KEY_FLAG is set in dwFindFlags,
  13805. // CryptAcquireCertificatePrivateKey is called to do the public key
  13806. // comparison. The following flags can be set to enable caching
  13807. // of the acquired private key or suppress CSP UI. See the API for more
  13808. // details on these flags.
  13809. DWORD dwAcquirePrivateKeyFlags;
  13810. // Pointer to an array of X509, ASN.1 encoded issuer name blobs. If
  13811. // cIssuer == 0, matches any issuer
  13812. DWORD cIssuer;
  13813. CERT_NAME_BLOB *rgIssuer;
  13814. // If NULL or Callback returns TRUE, builds the chain for the end
  13815. // certificate having a private key with the specified KeySpec and
  13816. // enhanced key usage.
  13817. PFN_CERT_CHAIN_FIND_BY_ISSUER_CALLBACK pfnFindCallback;
  13818. void *pvFindArg;
  13819. #ifdef CERT_CHAIN_FIND_BY_ISSUER_PARA_HAS_EXTRA_FIELDS
  13820. // Note, if you #define CERT_CHAIN_FIND_BY_ISSUER_PARA_HAS_EXTRA_FIELDS,
  13821. // then, you must zero all unused fields in this data structure.
  13822. // More fields could be added in a future release.
  13823. // If the following pointers are nonNull, returns the index of the
  13824. // matching issuer certificate, which is at:
  13825. // pChainContext->
  13826. // rgpChain[*pdwIssuerChainIndex]->rgpElement[*pdwIssuerElementIndex].
  13827. //
  13828. // The issuer name blob is compared against the Issuer field in the
  13829. // certificate. The *pdwIssuerElementIndex is set to the index of this
  13830. // subject certificate + 1. Therefore, its possible for a partial chain or
  13831. // a self signed certificate matching the name blob, where
  13832. // *pdwIssuerElementIndex points past the last certificate in the chain.
  13833. //
  13834. // Note, not updated if the above cIssuer == 0.
  13835. DWORD *pdwIssuerChainIndex;
  13836. DWORD *pdwIssuerElementIndex;
  13837. #endif
  13838. } CERT_CHAIN_FIND_ISSUER_PARA, *PCERT_CHAIN_FIND_ISSUER_PARA,
  13839. CERT_CHAIN_FIND_BY_ISSUER_PARA, *PCERT_CHAIN_FIND_BY_ISSUER_PARA;
  13840. // The following dwFindFlags can be set for CERT_CHAIN_FIND_BY_ISSUER
  13841. // If set, compares the public key in the end certificate with the crypto
  13842. // provider's public key. This comparison is the last check made on the
  13843. // build chain.
  13844. #define CERT_CHAIN_FIND_BY_ISSUER_COMPARE_KEY_FLAG 0x0001
  13845. // If not set, only checks the first simple chain for an issuer name match.
  13846. // When set, also checks second and subsequent simple chains.
  13847. #define CERT_CHAIN_FIND_BY_ISSUER_COMPLEX_CHAIN_FLAG 0x0002
  13848. // If set, CertGetCertificateChain only searches the URL cache and
  13849. // doesn't hit the wire.
  13850. #define CERT_CHAIN_FIND_BY_ISSUER_CACHE_ONLY_URL_FLAG 0x0004
  13851. // If set, CertGetCertificateChain only opens the Local Machine
  13852. // certificate stores instead of the Current User's.
  13853. #define CERT_CHAIN_FIND_BY_ISSUER_LOCAL_MACHINE_FLAG 0x0008
  13854. // If set, no check is made to see if the end certificate has a private
  13855. // key associated with it.
  13856. #define CERT_CHAIN_FIND_BY_ISSUER_NO_KEY_FLAG 0x4000
  13857. // By default, the hCertStore passed to CertFindChainInStore, is passed
  13858. // as the additional store to CertGetCertificateChain. This flag can be
  13859. // set to improve performance by only searching the cached system stores
  13860. // (root, my, ca, trust) to find the issuer certificates. If not set, then,
  13861. // the hCertStore is always searched in addition to the cached system
  13862. // stores.
  13863. #define CERT_CHAIN_FIND_BY_ISSUER_CACHE_ONLY_FLAG 0x8000
  13864. //+=========================================================================
  13865. // Certificate Chain Policy Data Structures and APIs
  13866. //==========================================================================
  13867. typedef struct _CERT_CHAIN_POLICY_PARA {
  13868. DWORD cbSize;
  13869. DWORD dwFlags;
  13870. void *pvExtraPolicyPara; // pszPolicyOID specific
  13871. } CERT_CHAIN_POLICY_PARA, *PCERT_CHAIN_POLICY_PARA;
  13872. // If both lChainIndex and lElementIndex are set to -1, the dwError applies
  13873. // to the whole chain context. If only lElementIndex is set to -1, the
  13874. // dwError applies to the lChainIndex'ed chain. Otherwise, the dwError applies
  13875. // to the certificate element at
  13876. // pChainContext->rgpChain[lChainIndex]->rgpElement[lElementIndex].
  13877. typedef struct _CERT_CHAIN_POLICY_STATUS {
  13878. DWORD cbSize;
  13879. DWORD dwError;
  13880. LONG lChainIndex;
  13881. LONG lElementIndex;
  13882. void *pvExtraPolicyStatus; // pszPolicyOID specific
  13883. } CERT_CHAIN_POLICY_STATUS, *PCERT_CHAIN_POLICY_STATUS;
  13884. // Common chain policy flags
  13885. #define CERT_CHAIN_POLICY_IGNORE_NOT_TIME_VALID_FLAG 0x00000001
  13886. #define CERT_CHAIN_POLICY_IGNORE_CTL_NOT_TIME_VALID_FLAG 0x00000002
  13887. #define CERT_CHAIN_POLICY_IGNORE_NOT_TIME_NESTED_FLAG 0x00000004
  13888. #define CERT_CHAIN_POLICY_IGNORE_INVALID_BASIC_CONSTRAINTS_FLAG 0x00000008
  13889. #define CERT_CHAIN_POLICY_IGNORE_ALL_NOT_TIME_VALID_FLAGS ( \
  13890. CERT_CHAIN_POLICY_IGNORE_NOT_TIME_VALID_FLAG | \
  13891. CERT_CHAIN_POLICY_IGNORE_CTL_NOT_TIME_VALID_FLAG | \
  13892. CERT_CHAIN_POLICY_IGNORE_NOT_TIME_NESTED_FLAG \
  13893. )
  13894. #define CERT_CHAIN_POLICY_ALLOW_UNKNOWN_CA_FLAG 0x00000010
  13895. #define CERT_CHAIN_POLICY_IGNORE_WRONG_USAGE_FLAG 0x00000020
  13896. #define CERT_CHAIN_POLICY_IGNORE_INVALID_NAME_FLAG 0x00000040
  13897. #define CERT_CHAIN_POLICY_IGNORE_INVALID_POLICY_FLAG 0x00000080
  13898. #define CERT_CHAIN_POLICY_IGNORE_END_REV_UNKNOWN_FLAG 0x00000100
  13899. #define CERT_CHAIN_POLICY_IGNORE_CTL_SIGNER_REV_UNKNOWN_FLAG 0x00000200
  13900. #define CERT_CHAIN_POLICY_IGNORE_CA_REV_UNKNOWN_FLAG 0x00000400
  13901. #define CERT_CHAIN_POLICY_IGNORE_ROOT_REV_UNKNOWN_FLAG 0x00000800
  13902. #define CERT_CHAIN_POLICY_IGNORE_ALL_REV_UNKNOWN_FLAGS ( \
  13903. CERT_CHAIN_POLICY_IGNORE_END_REV_UNKNOWN_FLAG | \
  13904. CERT_CHAIN_POLICY_IGNORE_CTL_SIGNER_REV_UNKNOWN_FLAG | \
  13905. CERT_CHAIN_POLICY_IGNORE_CA_REV_UNKNOWN_FLAG | \
  13906. CERT_CHAIN_POLICY_IGNORE_ROOT_REV_UNKNOWN_FLAG \
  13907. )
  13908. #define CERT_CHAIN_POLICY_ALLOW_TESTROOT_FLAG 0x00008000
  13909. #define CERT_CHAIN_POLICY_TRUST_TESTROOT_FLAG 0x00004000
  13910. //+-------------------------------------------------------------------------
  13911. // Verify that the certificate chain satisfies the specified policy
  13912. // requirements. If we were able to verify the chain policy, TRUE is returned
  13913. // and the dwError field of the pPolicyStatus is updated. A dwError of 0
  13914. // (ERROR_SUCCESS, S_OK) indicates the chain satisfies the specified policy.
  13915. //
  13916. // If dwError applies to the entire chain context, both lChainIndex and
  13917. // lElementIndex are set to -1. If dwError applies to a simple chain,
  13918. // lElementIndex is set to -1 and lChainIndex is set to the index of the
  13919. // first offending chain having the error. If dwError applies to a
  13920. // certificate element, lChainIndex and lElementIndex are updated to
  13921. // index the first offending certificate having the error, where, the
  13922. // the certificate element is at:
  13923. // pChainContext->rgpChain[lChainIndex]->rgpElement[lElementIndex].
  13924. //
  13925. // The dwFlags in pPolicyPara can be set to change the default policy checking
  13926. // behaviour. In addition, policy specific parameters can be passed in
  13927. // the pvExtraPolicyPara field of pPolicyPara.
  13928. //
  13929. // In addition to returning dwError, in pPolicyStatus, policy OID specific
  13930. // extra status may be returned via pvExtraPolicyStatus.
  13931. //--------------------------------------------------------------------------
  13932. WINCRYPT32API
  13933. BOOL
  13934. WINAPI
  13935. CertVerifyCertificateChainPolicy(
  13936. IN LPCSTR pszPolicyOID,
  13937. IN PCCERT_CHAIN_CONTEXT pChainContext,
  13938. IN PCERT_CHAIN_POLICY_PARA pPolicyPara,
  13939. IN OUT PCERT_CHAIN_POLICY_STATUS pPolicyStatus
  13940. );
  13941. // Predefined OID Function Names
  13942. #define CRYPT_OID_VERIFY_CERTIFICATE_CHAIN_POLICY_FUNC \
  13943. "CertDllVerifyCertificateChainPolicy"
  13944. // CertDllVerifyCertificateChainPolicy has same function signature as
  13945. // CertVerifyCertificateChainPolicy.
  13946. //+-------------------------------------------------------------------------
  13947. // Predefined verify chain policies
  13948. //--------------------------------------------------------------------------
  13949. #define CERT_CHAIN_POLICY_BASE ((LPCSTR) 1)
  13950. #define CERT_CHAIN_POLICY_AUTHENTICODE ((LPCSTR) 2)
  13951. #define CERT_CHAIN_POLICY_AUTHENTICODE_TS ((LPCSTR) 3)
  13952. #define CERT_CHAIN_POLICY_SSL ((LPCSTR) 4)
  13953. #define CERT_CHAIN_POLICY_BASIC_CONSTRAINTS ((LPCSTR) 5)
  13954. #define CERT_CHAIN_POLICY_NT_AUTH ((LPCSTR) 6)
  13955. #define CERT_CHAIN_POLICY_MICROSOFT_ROOT ((LPCSTR) 7)
  13956. //+-------------------------------------------------------------------------
  13957. // CERT_CHAIN_POLICY_BASE
  13958. //
  13959. // Implements the base chain policy verification checks. dwFlags can
  13960. // be set in pPolicyPara to alter the default policy checking behaviour.
  13961. //--------------------------------------------------------------------------
  13962. //+-------------------------------------------------------------------------
  13963. // CERT_CHAIN_POLICY_AUTHENTICODE
  13964. //
  13965. // Implements the Authenticode chain policy verification checks.
  13966. //
  13967. // pvExtraPolicyPara may optionally be set to point to the following
  13968. // AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_PARA.
  13969. //
  13970. // pvExtraPolicyStatus may optionally be set to point to the following
  13971. // AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_STATUS.
  13972. //--------------------------------------------------------------------------
  13973. // dwRegPolicySettings are defined in wintrust.h
  13974. typedef struct _AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_PARA {
  13975. DWORD cbSize;
  13976. DWORD dwRegPolicySettings;
  13977. PCMSG_SIGNER_INFO pSignerInfo; // optional
  13978. } AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_PARA,
  13979. *PAUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_PARA;
  13980. typedef struct _AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_STATUS {
  13981. DWORD cbSize;
  13982. BOOL fCommercial; // obtained from signer statement
  13983. } AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_STATUS,
  13984. *PAUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_STATUS;
  13985. //+-------------------------------------------------------------------------
  13986. // CERT_CHAIN_POLICY_AUTHENTICODE_TS
  13987. //
  13988. // Implements the Authenticode Time Stamp chain policy verification checks.
  13989. //
  13990. // pvExtraPolicyPara may optionally be set to point to the following
  13991. // AUTHENTICODE_TS_EXTRA_CERT_CHAIN_POLICY_PARA.
  13992. //
  13993. // pvExtraPolicyStatus isn't used and must be set to NULL.
  13994. //--------------------------------------------------------------------------
  13995. // dwRegPolicySettings are defined in wintrust.h
  13996. typedef struct _AUTHENTICODE_TS_EXTRA_CERT_CHAIN_POLICY_PARA {
  13997. DWORD cbSize;
  13998. DWORD dwRegPolicySettings;
  13999. BOOL fCommercial;
  14000. } AUTHENTICODE_TS_EXTRA_CERT_CHAIN_POLICY_PARA,
  14001. *PAUTHENTICODE_TS_EXTRA_CERT_CHAIN_POLICY_PARA;
  14002. //+-------------------------------------------------------------------------
  14003. // CERT_CHAIN_POLICY_SSL
  14004. //
  14005. // Implements the SSL client/server chain policy verification checks.
  14006. //
  14007. // pvExtraPolicyPara may optionally be set to point to the following
  14008. // SSL_EXTRA_CERT_CHAIN_POLICY_PARA data structure
  14009. //--------------------------------------------------------------------------
  14010. // fdwChecks flags are defined in wininet.h
  14011. typedef struct _HTTPSPolicyCallbackData
  14012. {
  14013. union {
  14014. DWORD cbStruct; // sizeof(HTTPSPolicyCallbackData);
  14015. DWORD cbSize; // sizeof(HTTPSPolicyCallbackData);
  14016. };
  14017. DWORD dwAuthType;
  14018. # define AUTHTYPE_CLIENT 1
  14019. # define AUTHTYPE_SERVER 2
  14020. DWORD fdwChecks;
  14021. WCHAR *pwszServerName; // used to check against CN=xxxx
  14022. } HTTPSPolicyCallbackData, *PHTTPSPolicyCallbackData,
  14023. SSL_EXTRA_CERT_CHAIN_POLICY_PARA, *PSSL_EXTRA_CERT_CHAIN_POLICY_PARA;
  14024. //+-------------------------------------------------------------------------
  14025. // CERT_CHAIN_POLICY_BASIC_CONSTRAINTS
  14026. //
  14027. // Implements the basic constraints chain policy.
  14028. //
  14029. // Iterates through all the certificates in the chain checking for either
  14030. // a szOID_BASIC_CONSTRAINTS or a szOID_BASIC_CONSTRAINTS2 extension. If
  14031. // neither extension is present, the certificate is assumed to have
  14032. // valid policy. Otherwise, for the first certificate element, checks if
  14033. // it matches the expected CA_FLAG or END_ENTITY_FLAG specified in
  14034. // pPolicyPara->dwFlags. If neither or both flags are set, then, the first
  14035. // element can be either a CA or END_ENTITY. All other elements must be
  14036. // a CA. If the PathLenConstraint is present in the extension, its
  14037. // checked.
  14038. //
  14039. // The first elements in the remaining simple chains (ie, the certificate
  14040. // used to sign the CTL) are checked to be an END_ENTITY.
  14041. //
  14042. // If this verification fails, dwError will be set to
  14043. // TRUST_E_BASIC_CONSTRAINTS.
  14044. //--------------------------------------------------------------------------
  14045. #define BASIC_CONSTRAINTS_CERT_CHAIN_POLICY_CA_FLAG 0x80000000
  14046. #define BASIC_CONSTRAINTS_CERT_CHAIN_POLICY_END_ENTITY_FLAG 0x40000000
  14047. //+-------------------------------------------------------------------------
  14048. // CERT_CHAIN_POLICY_NT_AUTH
  14049. //
  14050. // Implements the NT Authentication chain policy.
  14051. //
  14052. // The NT Authentication chain policy consists of 3 distinct chain
  14053. // verifications in the following order:
  14054. // [1] CERT_CHAIN_POLICY_BASE - Implements the base chain policy
  14055. // verification checks. The LOWORD of dwFlags can be set in
  14056. // pPolicyPara to alter the default policy checking behaviour. See
  14057. // CERT_CHAIN_POLICY_BASE for more details.
  14058. //
  14059. // [2] CERT_CHAIN_POLICY_BASIC_CONSTRAINTS - Implements the basic
  14060. // constraints chain policy. The HIWORD of dwFlags can be set
  14061. // to specify if the first element must be either a CA or END_ENTITY.
  14062. // See CERT_CHAIN_POLICY_BASIC_CONSTRAINTS for more details.
  14063. //
  14064. // [3] Checks if the second element in the chain, the CA that issued
  14065. // the end certificate, is a trusted CA for NT
  14066. // Authentication. A CA is considered to be trusted if it exists in
  14067. // the "NTAuth" system registry store found in the
  14068. // CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE store location.
  14069. // If this verification fails, whereby the CA isn't trusted,
  14070. // dwError is set to CERT_E_UNTRUSTEDCA.
  14071. //
  14072. // If CERT_PROT_ROOT_DISABLE_NT_AUTH_REQUIRED_FLAG is set
  14073. // in the "Flags" value of the HKLM policy "ProtectedRoots" subkey
  14074. // defined by CERT_PROT_ROOT_FLAGS_REGPATH, then,
  14075. // if the above check fails, checks if the chain
  14076. // has CERT_TRUST_HAS_VALID_NAME_CONSTRAINTS set in dwInfoStatus. This
  14077. // will only be set if there was a valid name constraint for all
  14078. // name spaces including UPN. If the chain doesn't have this info
  14079. // status set, dwError is set to CERT_E_UNTRUSTEDCA.
  14080. //--------------------------------------------------------------------------
  14081. //+-------------------------------------------------------------------------
  14082. // CERT_CHAIN_POLICY_MICROSOFT_ROOT
  14083. //
  14084. // Checks if the last element of the first simple chain contains a
  14085. // Microsoft root public key. If it doesn't contain a Microsoft root
  14086. // public key, dwError is set to CERT_E_UNTRUSTEDROOT.
  14087. //
  14088. // pPolicyPara is optional. However,
  14089. // MICROSOFT_ROOT_CERT_CHAIN_POLICY_ENABLE_TEST_ROOT_FLAG can be set in
  14090. // the dwFlags in pPolicyPara to also check for the Microsoft Test Roots.
  14091. //
  14092. // pvExtraPolicyPara and pvExtraPolicyStatus aren't used and must be set
  14093. // to NULL.
  14094. //--------------------------------------------------------------------------
  14095. #define MICROSOFT_ROOT_CERT_CHAIN_POLICY_ENABLE_TEST_ROOT_FLAG 0x00010000
  14096. //+-------------------------------------------------------------------------
  14097. // convert formatted string to binary
  14098. // If cchString is 0, then pszString is NULL terminated and
  14099. // cchString is obtained via strlen() + 1.
  14100. // dwFlags defines string format
  14101. // if pbBinary is NULL, *pcbBinary returns the size of required memory
  14102. // *pdwSkip returns the character count of skipped strings, optional
  14103. // *pdwFlags returns the actual format used in the conversion, optional
  14104. //--------------------------------------------------------------------------
  14105. WINCRYPT32STRINGAPI
  14106. BOOL
  14107. WINAPI
  14108. CryptStringToBinaryA(
  14109. IN LPCSTR pszString,
  14110. IN DWORD cchString,
  14111. IN DWORD dwFlags,
  14112. IN BYTE *pbBinary,
  14113. IN OUT DWORD *pcbBinary,
  14114. OUT DWORD *pdwSkip, //OPTIONAL
  14115. OUT DWORD *pdwFlags //OPTIONAL
  14116. );
  14117. //+-------------------------------------------------------------------------
  14118. // convert formatted string to binary
  14119. // If cchString is 0, then pszString is NULL terminated and
  14120. // cchString is obtained via strlen() + 1.
  14121. // dwFlags defines string format
  14122. // if pbBinary is NULL, *pcbBinary returns the size of required memory
  14123. // *pdwSkip returns the character count of skipped strings, optional
  14124. // *pdwFlags returns the actual format used in the conversion, optional
  14125. //--------------------------------------------------------------------------
  14126. WINCRYPT32STRINGAPI
  14127. BOOL
  14128. WINAPI
  14129. CryptStringToBinaryW(
  14130. IN LPCWSTR pszString,
  14131. IN DWORD cchString,
  14132. IN DWORD dwFlags,
  14133. IN BYTE *pbBinary,
  14134. IN OUT DWORD *pcbBinary,
  14135. OUT DWORD *pdwSkip, //OPTIONAL
  14136. OUT DWORD *pdwFlags //OPTIONAL
  14137. );
  14138. #ifdef UNICODE
  14139. #define CryptStringToBinary CryptStringToBinaryW
  14140. #else
  14141. #define CryptStringToBinary CryptStringToBinaryA
  14142. #endif // !UNICODE
  14143. //+-------------------------------------------------------------------------
  14144. // convert binary to formatted string
  14145. // dwFlags defines string format
  14146. // if pszString is NULL, *pcchString returns size in characters
  14147. // including null-terminator
  14148. //--------------------------------------------------------------------------
  14149. WINCRYPT32STRINGAPI
  14150. BOOL
  14151. WINAPI
  14152. CryptBinaryToStringA(
  14153. IN CONST BYTE *pbBinary,
  14154. IN DWORD cbBinary,
  14155. IN DWORD dwFlags,
  14156. IN LPSTR pszString,
  14157. IN OUT DWORD *pcchString
  14158. );
  14159. //+-------------------------------------------------------------------------
  14160. // convert binary to formatted string
  14161. // dwFlags defines string format
  14162. // if pszString is NULL, *pcchString returns size in characters
  14163. // including null-terminator
  14164. //--------------------------------------------------------------------------
  14165. WINCRYPT32STRINGAPI
  14166. BOOL
  14167. WINAPI
  14168. CryptBinaryToStringW(
  14169. IN CONST BYTE *pbBinary,
  14170. IN DWORD cbBinary,
  14171. IN DWORD dwFlags,
  14172. IN LPWSTR pszString,
  14173. IN OUT DWORD *pcchString
  14174. );
  14175. #ifdef UNICODE
  14176. #define CryptBinaryToString CryptBinaryToStringW
  14177. #else
  14178. #define CryptBinaryToString CryptBinaryToStringA
  14179. #endif // !UNICODE
  14180. // dwFlags has the following defines
  14181. #define CRYPT_STRING_BASE64HEADER 0x00000000
  14182. #define CRYPT_STRING_BASE64 0x00000001
  14183. #define CRYPT_STRING_BINARY 0x00000002
  14184. #define CRYPT_STRING_BASE64REQUESTHEADER 0x00000003
  14185. #define CRYPT_STRING_HEX 0x00000004
  14186. #define CRYPT_STRING_HEXASCII 0x00000005
  14187. #define CRYPT_STRING_BASE64_ANY 0x00000006
  14188. #define CRYPT_STRING_ANY 0x00000007
  14189. #define CRYPT_STRING_HEX_ANY 0x00000008
  14190. #define CRYPT_STRING_BASE64X509CRLHEADER 0x00000009
  14191. #define CRYPT_STRING_HEXADDR 0x0000000a
  14192. #define CRYPT_STRING_HEXASCIIADDR 0x0000000b
  14193. #define CRYPT_STRING_NOCR 0x80000000
  14194. // CryptBinaryToString uses the following flags
  14195. // CRYPT_STRING_BASE64HEADER - base64 format with certificate begin
  14196. // and end headers
  14197. // CRYPT_STRING_BASE64 - only base64 without headers
  14198. // CRYPT_STRING_BINARY - pure binary copy
  14199. // CRYPT_STRING_BASE64REQUESTHEADER - base64 format with request begin
  14200. // and end headers
  14201. // CRYPT_STRING_BASE64X509CRLHEADER - base64 format with x509 crl begin
  14202. // and end headers
  14203. // CRYPT_STRING_HEX - only hex format
  14204. // CRYPT_STRING_HEXASCII - hex format with ascii char display
  14205. // CRYPT_STRING_HEXADDR - hex format with address display
  14206. // CRYPT_STRING_HEXASCIIADDR - hex format with ascii char and address display
  14207. //
  14208. // CryptBinaryToString accepts CRYPT_STRING_NOCR or'd into one of the above.
  14209. // When set, line breaks contain only LF, instead of CR-LF pairs.
  14210. // CryptStringToBinary uses the following flags
  14211. // CRYPT_STRING_BASE64_ANY tries the following, in order:
  14212. // CRYPT_STRING_BASE64HEADER
  14213. // CRYPT_STRING_BASE64
  14214. // CRYPT_STRING_ANY tries the following, in order:
  14215. // CRYPT_STRING_BASE64_ANY
  14216. // CRYPT_STRING_BINARY -- should always succeed
  14217. // CRYPT_STRING_HEX_ANY tries the following, in order:
  14218. // CRYPT_STRING_HEXADDR
  14219. // CRYPT_STRING_HEXASCIIADDR
  14220. // CRYPT_STRING_HEXASCII
  14221. // CRYPT_STRING_HEX
  14222. //+=========================================================================
  14223. // PFX (PKCS #12) function defintions and types
  14224. //==========================================================================
  14225. //+-------------------------------------------------------------------------
  14226. // PFXImportCertStore
  14227. //
  14228. // Import the PFX blob and return a store containing certificates
  14229. //
  14230. // If the password parameter is incorrect or any other problems decoding
  14231. // the PFX blob are encountered, the function will return NULL and the
  14232. // error code can be found from GetLastError().
  14233. //
  14234. // The dwFlags parameter may be set to the following:
  14235. // CRYPT_EXPORTABLE - specify that any imported keys should be marked as
  14236. // exportable (see documentation on CryptImportKey)
  14237. // CRYPT_USER_PROTECTED - (see documentation on CryptImportKey)
  14238. // CRYPT_MACHINE_KEYSET - used to force the private key to be stored in the
  14239. // the local machine and not the current user.
  14240. // CRYPT_USER_KEYSET - used to force the private key to be stored in the
  14241. // the current user and not the local machine, even if
  14242. // the pfx blob specifies that it should go into local
  14243. // machine.
  14244. //--------------------------------------------------------------------------
  14245. WINCRYPT32API
  14246. HCERTSTORE
  14247. WINAPI
  14248. PFXImportCertStore(
  14249. IN CRYPT_DATA_BLOB* pPFX,
  14250. IN LPCWSTR szPassword,
  14251. IN DWORD dwFlags);
  14252. // dwFlags definitions for PFXImportCertStore
  14253. //#define CRYPT_EXPORTABLE 0x00000001 // CryptImportKey dwFlags
  14254. //#define CRYPT_USER_PROTECTED 0x00000002 // CryptImportKey dwFlags
  14255. //#define CRYPT_MACHINE_KEYSET 0x00000020 // CryptAcquireContext dwFlags
  14256. #define CRYPT_USER_KEYSET 0x00001000
  14257. #define PKCS12_IMPORT_RESERVED_MASK 0xffff0000
  14258. //+-------------------------------------------------------------------------
  14259. // PFXIsPFXBlob
  14260. //
  14261. // This function will try to decode the outer layer of the blob as a pfx
  14262. // blob, and if that works it will return TRUE, it will return FALSE otherwise
  14263. //
  14264. //--------------------------------------------------------------------------
  14265. WINCRYPT32API
  14266. BOOL
  14267. WINAPI
  14268. PFXIsPFXBlob(
  14269. IN CRYPT_DATA_BLOB* pPFX);
  14270. //+-------------------------------------------------------------------------
  14271. // PFXVerifyPassword
  14272. //
  14273. // This function will attempt to decode the outer layer of the blob as a pfx
  14274. // blob and decrypt with the given password. No data from the blob will be
  14275. // imported.
  14276. //
  14277. // Return value is TRUE if password appears correct, FALSE otherwise.
  14278. //
  14279. //--------------------------------------------------------------------------
  14280. WINCRYPT32API
  14281. BOOL
  14282. WINAPI
  14283. PFXVerifyPassword(
  14284. IN CRYPT_DATA_BLOB* pPFX,
  14285. IN LPCWSTR szPassword,
  14286. IN DWORD dwFlags);
  14287. //+-------------------------------------------------------------------------
  14288. // PFXExportCertStoreEx
  14289. //
  14290. // Export the certificates and private keys referenced in the passed-in store
  14291. //
  14292. // This API encodes the blob under a stronger algorithm. The resulting
  14293. // PKCS12 blobs are incompatible with the earlier PFXExportCertStore API.
  14294. //
  14295. // The value passed in the password parameter will be used to encrypt and
  14296. // verify the integrity of the PFX packet. If any problems encoding the store
  14297. // are encountered, the function will return FALSE and the error code can
  14298. // be found from GetLastError().
  14299. //
  14300. // The dwFlags parameter may be set to any combination of
  14301. // EXPORT_PRIVATE_KEYS
  14302. // REPORT_NO_PRIVATE_KEY
  14303. // REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY
  14304. //
  14305. // The encoded PFX blob is returned in *pPFX. If pPFX->pbData is NULL upon
  14306. // input, this is a length only calculation, whereby, pPFX->cbData is updated
  14307. // with the number of bytes required for the encoded blob. Otherwise,
  14308. // the memory pointed to by pPFX->pbData is updated with the encoded bytes
  14309. // and pPFX->cbData is updated with the encoded byte length.
  14310. //--------------------------------------------------------------------------
  14311. WINCRYPT32API
  14312. BOOL
  14313. WINAPI
  14314. PFXExportCertStoreEx(
  14315. IN HCERTSTORE hStore,
  14316. IN OUT CRYPT_DATA_BLOB* pPFX,
  14317. IN LPCWSTR szPassword,
  14318. IN void* pvReserved,
  14319. IN DWORD dwFlags);
  14320. // dwFlags definitions for PFXExportCertStoreEx
  14321. #define REPORT_NO_PRIVATE_KEY 0x0001
  14322. #define REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY 0x0002
  14323. #define EXPORT_PRIVATE_KEYS 0x0004
  14324. #define PKCS12_EXPORT_RESERVED_MASK 0xffff0000
  14325. //+-------------------------------------------------------------------------
  14326. // PFXExportCertStore
  14327. //
  14328. // Export the certificates and private keys referenced in the passed-in store
  14329. //
  14330. // This is an old API kept for compatibility with IE4 clients. New applications
  14331. // should call the above PfxExportCertStoreEx for enhanced security.
  14332. //--------------------------------------------------------------------------
  14333. WINCRYPT32API
  14334. BOOL
  14335. WINAPI
  14336. PFXExportCertStore(
  14337. IN HCERTSTORE hStore,
  14338. IN OUT CRYPT_DATA_BLOB* pPFX,
  14339. IN LPCWSTR szPassword,
  14340. IN DWORD dwFlags);
  14341. #ifdef __cplusplus
  14342. } // Balance extern "C" above
  14343. #endif
  14344. #if defined (_MSC_VER)
  14345. #if ( _MSC_VER >= 800 )
  14346. #if _MSC_VER >= 1200
  14347. #pragma warning(pop)
  14348. #else
  14349. #pragma warning(default:4201)
  14350. #endif
  14351. #endif
  14352. #endif
  14353. #endif // __WINCRYPT_H__