Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

15895 lines
620 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. // secure channel sub ids
  150. #define ALG_SID_SSL3_MASTER 1
  151. #define ALG_SID_SCHANNEL_MASTER_HASH 2
  152. #define ALG_SID_SCHANNEL_MAC_KEY 3
  153. #define ALG_SID_PCT1_MASTER 4
  154. #define ALG_SID_SSL2_MASTER 5
  155. #define ALG_SID_TLS1_MASTER 6
  156. #define ALG_SID_SCHANNEL_ENC_KEY 7
  157. // Our silly example sub-id
  158. #define ALG_SID_EXAMPLE 80
  159. #ifndef ALGIDDEF
  160. #define ALGIDDEF
  161. typedef unsigned int ALG_ID;
  162. #endif
  163. // algorithm identifier definitions
  164. #define CALG_MD2 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD2)
  165. #define CALG_MD4 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD4)
  166. #define CALG_MD5 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD5)
  167. #define CALG_SHA (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA)
  168. #define CALG_SHA1 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA1)
  169. #define CALG_MAC (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MAC)
  170. #define CALG_RSA_SIGN (ALG_CLASS_SIGNATURE | ALG_TYPE_RSA | ALG_SID_RSA_ANY)
  171. #define CALG_DSS_SIGN (ALG_CLASS_SIGNATURE | ALG_TYPE_DSS | ALG_SID_DSS_ANY)
  172. #define CALG_NO_SIGN (ALG_CLASS_SIGNATURE | ALG_TYPE_ANY | ALG_SID_ANY)
  173. #define CALG_RSA_KEYX (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_RSA|ALG_SID_RSA_ANY)
  174. #define CALG_DES (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_DES)
  175. #define CALG_3DES_112 (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_3DES_112)
  176. #define CALG_3DES (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_3DES)
  177. #define CALG_DESX (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_DESX)
  178. #define CALG_RC2 (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_RC2)
  179. #define CALG_RC4 (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_STREAM|ALG_SID_RC4)
  180. #define CALG_SEAL (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_STREAM|ALG_SID_SEAL)
  181. #define CALG_DH_SF (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_DH_SANDF)
  182. #define CALG_DH_EPHEM (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_DH_EPHEM)
  183. #define CALG_AGREEDKEY_ANY (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_AGREED_KEY_ANY)
  184. #define CALG_KEA_KEYX (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_KEA)
  185. #define CALG_HUGHES_MD5 (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_ANY|ALG_SID_MD5)
  186. #define CALG_SKIPJACK (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_SKIPJACK)
  187. #define CALG_TEK (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_TEK)
  188. #define CALG_CYLINK_MEK (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_CYLINK_MEK)
  189. #define CALG_SSL3_SHAMD5 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SSL3SHAMD5)
  190. #define CALG_SSL3_MASTER (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SSL3_MASTER)
  191. #define CALG_SCHANNEL_MASTER_HASH (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SCHANNEL_MASTER_HASH)
  192. #define CALG_SCHANNEL_MAC_KEY (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SCHANNEL_MAC_KEY)
  193. #define CALG_SCHANNEL_ENC_KEY (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SCHANNEL_ENC_KEY)
  194. #define CALG_PCT1_MASTER (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_PCT1_MASTER)
  195. #define CALG_SSL2_MASTER (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SSL2_MASTER)
  196. #define CALG_TLS1_MASTER (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_TLS1_MASTER)
  197. #define CALG_RC5 (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_RC5)
  198. #define CALG_HMAC (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_HMAC)
  199. #define CALG_TLS1PRF (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_TLS1PRF)
  200. #define CALG_HASH_REPLACE_OWF (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_HASH_REPLACE_OWF)
  201. #define CALG_AES_128 (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_AES_128)
  202. #define CALG_AES_192 (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_AES_192)
  203. #define CALG_AES_256 (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_AES_256)
  204. #define CALG_AES (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_AES)
  205. typedef ULONG_PTR HCRYPTPROV;
  206. typedef ULONG_PTR HCRYPTKEY;
  207. typedef ULONG_PTR HCRYPTHASH;
  208. // dwFlags definitions for CryptAcquireContext
  209. #define CRYPT_VERIFYCONTEXT 0xF0000000
  210. #define CRYPT_NEWKEYSET 0x00000008
  211. #define CRYPT_DELETEKEYSET 0x00000010
  212. #define CRYPT_MACHINE_KEYSET 0x00000020
  213. #define CRYPT_SILENT 0x00000040
  214. // dwFlag definitions for CryptGenKey
  215. #define CRYPT_EXPORTABLE 0x00000001
  216. #define CRYPT_USER_PROTECTED 0x00000002
  217. #define CRYPT_CREATE_SALT 0x00000004
  218. #define CRYPT_UPDATE_KEY 0x00000008
  219. #define CRYPT_NO_SALT 0x00000010
  220. #define CRYPT_PREGEN 0x00000040
  221. #define CRYPT_RECIPIENT 0x00000010
  222. #define CRYPT_INITIATOR 0x00000040
  223. #define CRYPT_ONLINE 0x00000080
  224. #define CRYPT_SF 0x00000100
  225. #define CRYPT_CREATE_IV 0x00000200
  226. #define CRYPT_KEK 0x00000400
  227. #define CRYPT_DATA_KEY 0x00000800
  228. #define CRYPT_VOLATILE 0x00001000
  229. #define CRYPT_SGCKEY 0x00002000
  230. #define CRYPT_ARCHIVABLE 0x00004000
  231. #define RSA1024BIT_KEY 0x04000000
  232. // dwFlags definitions for CryptDeriveKey
  233. #define CRYPT_SERVER 0x00000400
  234. #define KEY_LENGTH_MASK 0xFFFF0000
  235. // dwFlag definitions for CryptExportKey
  236. #define CRYPT_Y_ONLY 0x00000001
  237. #define CRYPT_SSL2_FALLBACK 0x00000002
  238. #define CRYPT_DESTROYKEY 0x00000004
  239. #define CRYPT_OAEP 0x00000040 // used with RSA encryptions/decryptions
  240. // CryptExportKey, CryptImportKey,
  241. // CryptEncrypt and CryptDecrypt
  242. #define CRYPT_BLOB_VER3 0x00000080 // export version 3 of a blob type
  243. #define CRYPT_IPSEC_HMAC_KEY 0x00000100 // CryptImportKey only
  244. // dwFlags definitions for CryptCreateHash
  245. #define CRYPT_SECRETDIGEST 0x00000001
  246. // dwFlags definitions for CryptHashData
  247. #define CRYPT_OWF_REPL_LM_HASH 0x00000001 // this is only for the OWF replacement CSP
  248. // dwFlags definitions for CryptHashSessionKey
  249. #define CRYPT_LITTLE_ENDIAN 0x00000001
  250. // dwFlags definitions for CryptSignHash and CryptVerifySignature
  251. #define CRYPT_NOHASHOID 0x00000001
  252. #define CRYPT_TYPE2_FORMAT 0x00000002
  253. #define CRYPT_X931_FORMAT 0x00000004
  254. // dwFlag definitions for CryptSetProviderEx and CryptGetDefaultProvider
  255. #define CRYPT_MACHINE_DEFAULT 0x00000001
  256. #define CRYPT_USER_DEFAULT 0x00000002
  257. #define CRYPT_DELETE_DEFAULT 0x00000004
  258. // exported key blob definitions
  259. #define SIMPLEBLOB 0x1
  260. #define PUBLICKEYBLOB 0x6
  261. #define PRIVATEKEYBLOB 0x7
  262. #define PLAINTEXTKEYBLOB 0x8
  263. #define OPAQUEKEYBLOB 0x9
  264. #define PUBLICKEYBLOBEX 0xA
  265. #define SYMMETRICWRAPKEYBLOB 0xB
  266. #define AT_KEYEXCHANGE 1
  267. #define AT_SIGNATURE 2
  268. #define CRYPT_USERDATA 1
  269. // dwParam
  270. #define KP_IV 1 // Initialization vector
  271. #define KP_SALT 2 // Salt value
  272. #define KP_PADDING 3 // Padding values
  273. #define KP_MODE 4 // Mode of the cipher
  274. #define KP_MODE_BITS 5 // Number of bits to feedback
  275. #define KP_PERMISSIONS 6 // Key permissions DWORD
  276. #define KP_ALGID 7 // Key algorithm
  277. #define KP_BLOCKLEN 8 // Block size of the cipher
  278. #define KP_KEYLEN 9 // Length of key in bits
  279. #define KP_SALT_EX 10 // Length of salt in bytes
  280. #define KP_P 11 // DSS/Diffie-Hellman P value
  281. #define KP_G 12 // DSS/Diffie-Hellman G value
  282. #define KP_Q 13 // DSS Q value
  283. #define KP_X 14 // Diffie-Hellman X value
  284. #define KP_Y 15 // Y value
  285. #define KP_RA 16 // Fortezza RA value
  286. #define KP_RB 17 // Fortezza RB value
  287. #define KP_INFO 18 // for putting information into an RSA envelope
  288. #define KP_EFFECTIVE_KEYLEN 19 // setting and getting RC2 effective key length
  289. #define KP_SCHANNEL_ALG 20 // for setting the Secure Channel algorithms
  290. #define KP_CLIENT_RANDOM 21 // for setting the Secure Channel client random data
  291. #define KP_SERVER_RANDOM 22 // for setting the Secure Channel server random data
  292. #define KP_RP 23
  293. #define KP_PRECOMP_MD5 24
  294. #define KP_PRECOMP_SHA 25
  295. #define KP_CERTIFICATE 26 // for setting Secure Channel certificate data (PCT1)
  296. #define KP_CLEAR_KEY 27 // for setting Secure Channel clear key data (PCT1)
  297. #define KP_PUB_EX_LEN 28
  298. #define KP_PUB_EX_VAL 29
  299. #define KP_KEYVAL 30
  300. #define KP_ADMIN_PIN 31
  301. #define KP_KEYEXCHANGE_PIN 32
  302. #define KP_SIGNATURE_PIN 33
  303. #define KP_PREHASH 34
  304. #define KP_OAEP_PARAMS 36 // for setting OAEP params on RSA keys
  305. #define KP_CMS_KEY_INFO 37
  306. #define KP_CMS_DH_KEY_INFO 38
  307. #define KP_PUB_PARAMS 39 // for setting public parameters
  308. #define KP_VERIFY_PARAMS 40 // for verifying DSA and DH parameters
  309. #define KP_HIGHEST_VERSION 41 // for TLS protocol version setting
  310. // KP_PADDING
  311. #define PKCS5_PADDING 1 // PKCS 5 (sec 6.2) padding method
  312. #define RANDOM_PADDING 2
  313. #define ZERO_PADDING 3
  314. // KP_MODE
  315. #define CRYPT_MODE_CBC 1 // Cipher block chaining
  316. #define CRYPT_MODE_ECB 2 // Electronic code book
  317. #define CRYPT_MODE_OFB 3 // Output feedback mode
  318. #define CRYPT_MODE_CFB 4 // Cipher feedback mode
  319. #define CRYPT_MODE_CTS 5 // Ciphertext stealing mode
  320. // KP_PERMISSIONS
  321. #define CRYPT_ENCRYPT 0x0001 // Allow encryption
  322. #define CRYPT_DECRYPT 0x0002 // Allow decryption
  323. #define CRYPT_EXPORT 0x0004 // Allow key to be exported
  324. #define CRYPT_READ 0x0008 // Allow parameters to be read
  325. #define CRYPT_WRITE 0x0010 // Allow parameters to be set
  326. #define CRYPT_MAC 0x0020 // Allow MACs to be used with key
  327. #define CRYPT_EXPORT_KEY 0x0040 // Allow key to be used for exporting keys
  328. #define CRYPT_IMPORT_KEY 0x0080 // Allow key to be used for importing keys
  329. #define CRYPT_ARCHIVE 0x0100 // Allow key to be exported at creation only
  330. #define HP_ALGID 0x0001 // Hash algorithm
  331. #define HP_HASHVAL 0x0002 // Hash value
  332. #define HP_HASHSIZE 0x0004 // Hash value size
  333. #define HP_HMAC_INFO 0x0005 // information for creating an HMAC
  334. #define HP_TLS1PRF_LABEL 0x0006 // label for TLS1 PRF
  335. #define HP_TLS1PRF_SEED 0x0007 // seed for TLS1 PRF
  336. #define CRYPT_FAILED FALSE
  337. #define CRYPT_SUCCEED TRUE
  338. #define RCRYPT_SUCCEEDED(rt) ((rt) == CRYPT_SUCCEED)
  339. #define RCRYPT_FAILED(rt) ((rt) == CRYPT_FAILED)
  340. //
  341. // CryptGetProvParam
  342. //
  343. #define PP_ENUMALGS 1
  344. #define PP_ENUMCONTAINERS 2
  345. #define PP_IMPTYPE 3
  346. #define PP_NAME 4
  347. #define PP_VERSION 5
  348. #define PP_CONTAINER 6
  349. #define PP_CHANGE_PASSWORD 7
  350. #define PP_KEYSET_SEC_DESCR 8 // get/set security descriptor of keyset
  351. #define PP_CERTCHAIN 9 // for retrieving certificates from tokens
  352. #define PP_KEY_TYPE_SUBTYPE 10
  353. #define PP_PROVTYPE 16
  354. #define PP_KEYSTORAGE 17
  355. #define PP_APPLI_CERT 18
  356. #define PP_SYM_KEYSIZE 19
  357. #define PP_SESSION_KEYSIZE 20
  358. #define PP_UI_PROMPT 21
  359. #define PP_ENUMALGS_EX 22
  360. #define PP_ENUMMANDROOTS 25
  361. #define PP_ENUMELECTROOTS 26
  362. #define PP_KEYSET_TYPE 27
  363. #define PP_ADMIN_PIN 31
  364. #define PP_KEYEXCHANGE_PIN 32
  365. #define PP_SIGNATURE_PIN 33
  366. #define PP_SIG_KEYSIZE_INC 34
  367. #define PP_KEYX_KEYSIZE_INC 35
  368. #define PP_UNIQUE_CONTAINER 36
  369. #define PP_SGC_INFO 37
  370. #define PP_USE_HARDWARE_RNG 38
  371. #define PP_KEYSPEC 39
  372. #define PP_ENUMEX_SIGNING_PROT 40
  373. #define CRYPT_FIRST 1
  374. #define CRYPT_NEXT 2
  375. #define CRYPT_SGC_ENUM 4
  376. #define CRYPT_IMPL_HARDWARE 1
  377. #define CRYPT_IMPL_SOFTWARE 2
  378. #define CRYPT_IMPL_MIXED 3
  379. #define CRYPT_IMPL_UNKNOWN 4
  380. #define CRYPT_IMPL_REMOVABLE 8
  381. // key storage flags
  382. #define CRYPT_SEC_DESCR 0x00000001
  383. #define CRYPT_PSTORE 0x00000002
  384. #define CRYPT_UI_PROMPT 0x00000004
  385. // protocol flags
  386. #define CRYPT_FLAG_PCT1 0x0001
  387. #define CRYPT_FLAG_SSL2 0x0002
  388. #define CRYPT_FLAG_SSL3 0x0004
  389. #define CRYPT_FLAG_TLS1 0x0008
  390. #define CRYPT_FLAG_IPSEC 0x0010
  391. #define CRYPT_FLAG_SIGNING 0x0020
  392. // SGC flags
  393. #define CRYPT_SGC 0x0001
  394. #define CRYPT_FASTSGC 0x0002
  395. //
  396. // CryptSetProvParam
  397. //
  398. #define PP_CLIENT_HWND 1
  399. #define PP_CONTEXT_INFO 11
  400. #define PP_KEYEXCHANGE_KEYSIZE 12
  401. #define PP_SIGNATURE_KEYSIZE 13
  402. #define PP_KEYEXCHANGE_ALG 14
  403. #define PP_SIGNATURE_ALG 15
  404. #define PP_DELETEKEY 24
  405. #define PROV_RSA_FULL 1
  406. #define PROV_RSA_SIG 2
  407. #define PROV_DSS 3
  408. #define PROV_FORTEZZA 4
  409. #define PROV_MS_EXCHANGE 5
  410. #define PROV_SSL 6
  411. #define PROV_RSA_SCHANNEL 12
  412. #define PROV_DSS_DH 13
  413. #define PROV_EC_ECDSA_SIG 14
  414. #define PROV_EC_ECNRA_SIG 15
  415. #define PROV_EC_ECDSA_FULL 16
  416. #define PROV_EC_ECNRA_FULL 17
  417. #define PROV_DH_SCHANNEL 18
  418. #define PROV_SPYRUS_LYNKS 20
  419. #define PROV_RNG 21
  420. #define PROV_INTEL_SEC 22
  421. #define PROV_REPLACE_OWF 23
  422. #define PROV_RSA_AES 24
  423. //
  424. // STT defined Providers
  425. //
  426. #define PROV_STT_MER 7
  427. #define PROV_STT_ACQ 8
  428. #define PROV_STT_BRND 9
  429. #define PROV_STT_ROOT 10
  430. #define PROV_STT_ISS 11
  431. //
  432. // Provider friendly names
  433. //
  434. #define MS_DEF_PROV_A "Microsoft Base Cryptographic Provider v1.0"
  435. #define MS_DEF_PROV_W L"Microsoft Base Cryptographic Provider v1.0"
  436. #ifdef UNICODE
  437. #define MS_DEF_PROV MS_DEF_PROV_W
  438. #else
  439. #define MS_DEF_PROV MS_DEF_PROV_A
  440. #endif
  441. #define MS_ENHANCED_PROV_A "Microsoft Enhanced Cryptographic Provider v1.0"
  442. #define MS_ENHANCED_PROV_W L"Microsoft Enhanced Cryptographic Provider v1.0"
  443. #ifdef UNICODE
  444. #define MS_ENHANCED_PROV MS_ENHANCED_PROV_W
  445. #else
  446. #define MS_ENHANCED_PROV MS_ENHANCED_PROV_A
  447. #endif
  448. #define MS_STRONG_PROV_A "Microsoft Strong Cryptographic Provider"
  449. #define MS_STRONG_PROV_W L"Microsoft Strong Cryptographic Provider"
  450. #ifdef UNICODE
  451. #define MS_STRONG_PROV MS_STRONG_PROV_W
  452. #else
  453. #define MS_STRONG_PROV MS_STRONG_PROV_A
  454. #endif
  455. #define MS_DEF_RSA_SIG_PROV_A "Microsoft RSA Signature Cryptographic Provider"
  456. #define MS_DEF_RSA_SIG_PROV_W L"Microsoft RSA Signature Cryptographic Provider"
  457. #ifdef UNICODE
  458. #define MS_DEF_RSA_SIG_PROV MS_DEF_RSA_SIG_PROV_W
  459. #else
  460. #define MS_DEF_RSA_SIG_PROV MS_DEF_RSA_SIG_PROV_A
  461. #endif
  462. #define MS_DEF_RSA_SCHANNEL_PROV_A "Microsoft RSA SChannel Cryptographic Provider"
  463. #define MS_DEF_RSA_SCHANNEL_PROV_W L"Microsoft RSA SChannel Cryptographic Provider"
  464. #ifdef UNICODE
  465. #define MS_DEF_RSA_SCHANNEL_PROV MS_DEF_RSA_SCHANNEL_PROV_W
  466. #else
  467. #define MS_DEF_RSA_SCHANNEL_PROV MS_DEF_RSA_SCHANNEL_PROV_A
  468. #endif
  469. #define MS_DEF_DSS_PROV_A "Microsoft Base DSS Cryptographic Provider"
  470. #define MS_DEF_DSS_PROV_W L"Microsoft Base DSS Cryptographic Provider"
  471. #ifdef UNICODE
  472. #define MS_DEF_DSS_PROV MS_DEF_DSS_PROV_W
  473. #else
  474. #define MS_DEF_DSS_PROV MS_DEF_DSS_PROV_A
  475. #endif
  476. #define MS_DEF_DSS_DH_PROV_A "Microsoft Base DSS and Diffie-Hellman Cryptographic Provider"
  477. #define MS_DEF_DSS_DH_PROV_W L"Microsoft Base DSS and Diffie-Hellman Cryptographic Provider"
  478. #ifdef UNICODE
  479. #define MS_DEF_DSS_DH_PROV MS_DEF_DSS_DH_PROV_W
  480. #else
  481. #define MS_DEF_DSS_DH_PROV MS_DEF_DSS_DH_PROV_A
  482. #endif
  483. #define MS_ENH_DSS_DH_PROV_A "Microsoft Enhanced DSS and Diffie-Hellman Cryptographic Provider"
  484. #define MS_ENH_DSS_DH_PROV_W L"Microsoft Enhanced DSS and Diffie-Hellman Cryptographic Provider"
  485. #ifdef UNICODE
  486. #define MS_ENH_DSS_DH_PROV MS_ENH_DSS_DH_PROV_W
  487. #else
  488. #define MS_ENH_DSS_DH_PROV MS_ENH_DSS_DH_PROV_A
  489. #endif
  490. #define MS_DEF_DH_SCHANNEL_PROV_A "Microsoft DH SChannel Cryptographic Provider"
  491. #define MS_DEF_DH_SCHANNEL_PROV_W L"Microsoft DH SChannel Cryptographic Provider"
  492. #ifdef UNICODE
  493. #define MS_DEF_DH_SCHANNEL_PROV MS_DEF_DH_SCHANNEL_PROV_W
  494. #else
  495. #define MS_DEF_DH_SCHANNEL_PROV MS_DEF_DH_SCHANNEL_PROV_A
  496. #endif
  497. #define MS_SCARD_PROV_A "Microsoft Base Smart Card Crypto Provider"
  498. #define MS_SCARD_PROV_W L"Microsoft Base Smart Card Crypto Provider"
  499. #ifdef UNICODE
  500. #define MS_SCARD_PROV MS_SCARD_PROV_W
  501. #else
  502. #define MS_SCARD_PROV MS_SCARD_PROV_A
  503. #endif
  504. #define MS_ENH_RSA_AES_PROV_A "Microsoft Enhanced RSA and AES Cryptographic Provider (Prototype)"
  505. #define MS_ENH_RSA_AES_PROV_W L"Microsoft Enhanced RSA and AES Cryptographic Provider (Prototype)"
  506. #ifdef UNICODE
  507. #define MS_ENH_RSA_AES_PROV MS_ENH_RSA_AES_PROV_W
  508. #else
  509. #define MS_ENH_RSA_AES_PROV MS_ENH_RSA_AES_PROV_A
  510. #endif
  511. #define MAXUIDLEN 64
  512. // Exponentiation Offload Reg Location
  513. #define EXPO_OFFLOAD_REG_VALUE "ExpoOffload"
  514. #define EXPO_OFFLOAD_FUNC_NAME "OffloadModExpo"
  515. //
  516. // Registry key in which the following private key-related
  517. // values are created.
  518. //
  519. #define szKEY_CRYPTOAPI_PRIVATE_KEY_OPTIONS \
  520. "Software\\Policies\\Microsoft\\Cryptography"
  521. //
  522. // Registry value for controlling Data Protection API (DPAPI) UI settings.
  523. //
  524. #define szFORCE_KEY_PROTECTION "ForceKeyProtection"
  525. #define dwFORCE_KEY_PROTECTION_DISABLED 0x0
  526. #define dwFORCE_KEY_PROTECTION_USER_SELECT 0x1
  527. #define dwFORCE_KEY_PROTECTION_HIGH 0x2
  528. //
  529. // Registry values for enabling and controlling the caching (and timeout)
  530. // of private keys. This feature is useful only for UI-protected private
  531. // keys.
  532. //
  533. // Note that in Windows 2000 and later, private keys, once read from storage,
  534. // are cached in the associated HCRYPTPROV structure for subsequent use.
  535. //
  536. // In .NET Server and XP SP1, new key caching behavior is available. Keys
  537. // that have been read from storage and cached may now be considered "stale"
  538. // if a period of time has elapsed since the key was last used. This forces
  539. // the key to be re-read from storage (which will make the DPAPI UI appear
  540. // again).
  541. //
  542. // To enable the new behavior, create the registry DWORD value
  543. // szKEY_CACHE_ENABLED and set it to 1. The registry DWORD value
  544. // szKEY_CACHE_SECONDS must also be created and set to the number of seconds
  545. // that a cached private key may still be considered usable.
  546. //
  547. #define szKEY_CACHE_ENABLED "CachePrivateKeys"
  548. #define szKEY_CACHE_SECONDS "PrivateKeyLifetimeSeconds"
  549. #define CUR_BLOB_VERSION 2
  550. // structure for use with CryptSetKeyParam for CMS keys
  551. // DO NOT USE THIS STRUCTURE!!!!!
  552. typedef struct _CMS_KEY_INFO {
  553. DWORD dwVersion; // sizeof(CMS_KEY_INFO)
  554. ALG_ID Algid; // algorithmm id for the key to be converted
  555. BYTE *pbOID; // pointer to OID to hash in with Z
  556. DWORD cbOID; // length of OID to hash in with Z
  557. } CMS_KEY_INFO, *PCMS_KEY_INFO;
  558. // structure for use with CryptSetHashParam with CALG_HMAC
  559. typedef struct _HMAC_Info {
  560. ALG_ID HashAlgid;
  561. BYTE *pbInnerString;
  562. DWORD cbInnerString;
  563. BYTE *pbOuterString;
  564. DWORD cbOuterString;
  565. } HMAC_INFO, *PHMAC_INFO;
  566. // structure for use with CryptSetKeyParam with KP_SCHANNEL_ALG
  567. typedef struct _SCHANNEL_ALG {
  568. DWORD dwUse;
  569. ALG_ID Algid;
  570. DWORD cBits;
  571. DWORD dwFlags;
  572. DWORD dwReserved;
  573. } SCHANNEL_ALG, *PSCHANNEL_ALG;
  574. // uses of algortihms for SCHANNEL_ALG structure
  575. #define SCHANNEL_MAC_KEY 0x00000000
  576. #define SCHANNEL_ENC_KEY 0x00000001
  577. // uses of dwFlags SCHANNEL_ALG structure
  578. #define INTERNATIONAL_USAGE 0x00000001
  579. typedef struct _PROV_ENUMALGS {
  580. ALG_ID aiAlgid;
  581. DWORD dwBitLen;
  582. DWORD dwNameLen;
  583. CHAR szName[20];
  584. } PROV_ENUMALGS;
  585. typedef struct _PROV_ENUMALGS_EX {
  586. ALG_ID aiAlgid;
  587. DWORD dwDefaultLen;
  588. DWORD dwMinLen;
  589. DWORD dwMaxLen;
  590. DWORD dwProtocols;
  591. DWORD dwNameLen;
  592. CHAR szName[20];
  593. DWORD dwLongNameLen;
  594. CHAR szLongName[40];
  595. } PROV_ENUMALGS_EX;
  596. typedef struct _PUBLICKEYSTRUC {
  597. BYTE bType;
  598. BYTE bVersion;
  599. WORD reserved;
  600. ALG_ID aiKeyAlg;
  601. } BLOBHEADER, PUBLICKEYSTRUC;
  602. typedef struct _RSAPUBKEY {
  603. DWORD magic; // Has to be RSA1
  604. DWORD bitlen; // # of bits in modulus
  605. DWORD pubexp; // public exponent
  606. // Modulus data follows
  607. } RSAPUBKEY;
  608. typedef struct _PUBKEY {
  609. DWORD magic;
  610. DWORD bitlen; // # of bits in modulus
  611. } DHPUBKEY, DSSPUBKEY, KEAPUBKEY, TEKPUBKEY;
  612. typedef struct _DSSSEED {
  613. DWORD counter;
  614. BYTE seed[20];
  615. } DSSSEED;
  616. typedef struct _PUBKEYVER3 {
  617. DWORD magic;
  618. DWORD bitlenP; // # of bits in prime modulus
  619. DWORD bitlenQ; // # of bits in prime q, 0 if not available
  620. DWORD bitlenJ; // # of bits in (p-1)/q, 0 if not available
  621. DSSSEED DSSSeed;
  622. } DHPUBKEY_VER3, DSSPUBKEY_VER3;
  623. typedef struct _PRIVKEYVER3 {
  624. DWORD magic;
  625. DWORD bitlenP; // # of bits in prime modulus
  626. DWORD bitlenQ; // # of bits in prime q, 0 if not available
  627. DWORD bitlenJ; // # of bits in (p-1)/q, 0 if not available
  628. DWORD bitlenX; // # of bits in X
  629. DSSSEED DSSSeed;
  630. } DHPRIVKEY_VER3, DSSPRIVKEY_VER3;
  631. typedef struct _KEY_TYPE_SUBTYPE {
  632. DWORD dwKeySpec;
  633. GUID Type;
  634. GUID Subtype;
  635. } KEY_TYPE_SUBTYPE, *PKEY_TYPE_SUBTYPE;
  636. typedef struct _CERT_FORTEZZA_DATA_PROP {
  637. unsigned char SerialNumber[8];
  638. int CertIndex;
  639. unsigned char CertLabel[36];
  640. } CERT_FORTEZZA_DATA_PROP;
  641. //+-------------------------------------------------------------------------
  642. // CRYPTOAPI BLOB definitions
  643. //--------------------------------------------------------------------------
  644. typedef struct _CRYPTOAPI_BLOB {
  645. DWORD cbData;
  646. BYTE *pbData;
  647. } CRYPT_INTEGER_BLOB, *PCRYPT_INTEGER_BLOB,
  648. CRYPT_UINT_BLOB, *PCRYPT_UINT_BLOB,
  649. CRYPT_OBJID_BLOB, *PCRYPT_OBJID_BLOB,
  650. CERT_NAME_BLOB, *PCERT_NAME_BLOB,
  651. CERT_RDN_VALUE_BLOB, *PCERT_RDN_VALUE_BLOB,
  652. CERT_BLOB, *PCERT_BLOB,
  653. CRL_BLOB, *PCRL_BLOB,
  654. DATA_BLOB, *PDATA_BLOB,
  655. CRYPT_DATA_BLOB, *PCRYPT_DATA_BLOB,
  656. CRYPT_HASH_BLOB, *PCRYPT_HASH_BLOB,
  657. CRYPT_DIGEST_BLOB, *PCRYPT_DIGEST_BLOB,
  658. CRYPT_DER_BLOB, *PCRYPT_DER_BLOB,
  659. CRYPT_ATTR_BLOB, *PCRYPT_ATTR_BLOB;
  660. // structure for use with CryptSetKeyParam for CMS keys
  661. typedef struct _CMS_DH_KEY_INFO {
  662. DWORD dwVersion; // sizeof(CMS_DH_KEY_INFO)
  663. ALG_ID Algid; // algorithmm id for the key to be converted
  664. LPSTR pszContentEncObjId; // pointer to OID to hash in with Z
  665. CRYPT_DATA_BLOB PubInfo; // OPTIONAL - public information
  666. void *pReserved; // reserved - should be NULL
  667. } CMS_DH_KEY_INFO, *PCMS_DH_KEY_INFO;
  668. WINADVAPI
  669. BOOL
  670. WINAPI
  671. CryptAcquireContextA(
  672. HCRYPTPROV *phProv,
  673. LPCSTR szContainer,
  674. LPCSTR szProvider,
  675. DWORD dwProvType,
  676. DWORD dwFlags
  677. );
  678. WINADVAPI
  679. BOOL
  680. WINAPI
  681. CryptAcquireContextW(
  682. HCRYPTPROV *phProv,
  683. LPCWSTR szContainer,
  684. LPCWSTR szProvider,
  685. DWORD dwProvType,
  686. DWORD dwFlags
  687. );
  688. #ifdef UNICODE
  689. #define CryptAcquireContext CryptAcquireContextW
  690. #else
  691. #define CryptAcquireContext CryptAcquireContextA
  692. #endif // !UNICODE
  693. WINADVAPI
  694. BOOL
  695. WINAPI
  696. CryptReleaseContext(
  697. HCRYPTPROV hProv,
  698. DWORD dwFlags
  699. );
  700. WINADVAPI
  701. BOOL
  702. WINAPI
  703. CryptGenKey(
  704. HCRYPTPROV hProv,
  705. ALG_ID Algid,
  706. DWORD dwFlags,
  707. HCRYPTKEY *phKey
  708. );
  709. WINADVAPI
  710. BOOL
  711. WINAPI
  712. CryptDeriveKey(
  713. HCRYPTPROV hProv,
  714. ALG_ID Algid,
  715. HCRYPTHASH hBaseData,
  716. DWORD dwFlags,
  717. HCRYPTKEY *phKey
  718. );
  719. WINADVAPI
  720. BOOL
  721. WINAPI
  722. CryptDestroyKey(
  723. HCRYPTKEY hKey
  724. );
  725. WINADVAPI
  726. BOOL
  727. WINAPI
  728. CryptSetKeyParam(
  729. HCRYPTKEY hKey,
  730. DWORD dwParam,
  731. CONST BYTE *pbData,
  732. DWORD dwFlags
  733. );
  734. WINADVAPI
  735. BOOL
  736. WINAPI
  737. CryptGetKeyParam(
  738. HCRYPTKEY hKey,
  739. DWORD dwParam,
  740. BYTE *pbData,
  741. DWORD *pdwDataLen,
  742. DWORD dwFlags
  743. );
  744. WINADVAPI
  745. BOOL
  746. WINAPI
  747. CryptSetHashParam(
  748. HCRYPTHASH hHash,
  749. DWORD dwParam,
  750. CONST BYTE *pbData,
  751. DWORD dwFlags
  752. );
  753. WINADVAPI
  754. BOOL
  755. WINAPI
  756. CryptGetHashParam(
  757. HCRYPTHASH hHash,
  758. DWORD dwParam,
  759. BYTE *pbData,
  760. DWORD *pdwDataLen,
  761. DWORD dwFlags
  762. );
  763. WINADVAPI
  764. BOOL
  765. WINAPI
  766. CryptSetProvParam(
  767. HCRYPTPROV hProv,
  768. DWORD dwParam,
  769. CONST BYTE *pbData,
  770. DWORD dwFlags
  771. );
  772. WINADVAPI
  773. BOOL
  774. WINAPI
  775. CryptGetProvParam(
  776. HCRYPTPROV hProv,
  777. DWORD dwParam,
  778. BYTE *pbData,
  779. DWORD *pdwDataLen,
  780. DWORD dwFlags
  781. );
  782. WINADVAPI
  783. BOOL
  784. WINAPI
  785. CryptGenRandom(
  786. HCRYPTPROV hProv,
  787. DWORD dwLen,
  788. BYTE *pbBuffer
  789. );
  790. WINADVAPI
  791. BOOL
  792. WINAPI
  793. CryptGetUserKey(
  794. HCRYPTPROV hProv,
  795. DWORD dwKeySpec,
  796. HCRYPTKEY *phUserKey
  797. );
  798. WINADVAPI
  799. BOOL
  800. WINAPI
  801. CryptExportKey(
  802. HCRYPTKEY hKey,
  803. HCRYPTKEY hExpKey,
  804. DWORD dwBlobType,
  805. DWORD dwFlags,
  806. BYTE *pbData,
  807. DWORD *pdwDataLen
  808. );
  809. WINADVAPI
  810. BOOL
  811. WINAPI
  812. CryptImportKey(
  813. HCRYPTPROV hProv,
  814. CONST BYTE *pbData,
  815. DWORD dwDataLen,
  816. HCRYPTKEY hPubKey,
  817. DWORD dwFlags,
  818. HCRYPTKEY *phKey
  819. );
  820. WINADVAPI
  821. BOOL
  822. WINAPI
  823. CryptEncrypt(
  824. HCRYPTKEY hKey,
  825. HCRYPTHASH hHash,
  826. BOOL Final,
  827. DWORD dwFlags,
  828. BYTE *pbData,
  829. DWORD *pdwDataLen,
  830. DWORD dwBufLen
  831. );
  832. WINADVAPI
  833. BOOL
  834. WINAPI
  835. CryptDecrypt(
  836. HCRYPTKEY hKey,
  837. HCRYPTHASH hHash,
  838. BOOL Final,
  839. DWORD dwFlags,
  840. BYTE *pbData,
  841. DWORD *pdwDataLen
  842. );
  843. WINADVAPI
  844. BOOL
  845. WINAPI
  846. CryptCreateHash(
  847. HCRYPTPROV hProv,
  848. ALG_ID Algid,
  849. HCRYPTKEY hKey,
  850. DWORD dwFlags,
  851. HCRYPTHASH *phHash
  852. );
  853. WINADVAPI
  854. BOOL
  855. WINAPI
  856. CryptHashData(
  857. HCRYPTHASH hHash,
  858. CONST BYTE *pbData,
  859. DWORD dwDataLen,
  860. DWORD dwFlags
  861. );
  862. WINADVAPI
  863. BOOL
  864. WINAPI
  865. CryptHashSessionKey(
  866. HCRYPTHASH hHash,
  867. HCRYPTKEY hKey,
  868. DWORD dwFlags
  869. );
  870. WINADVAPI
  871. BOOL
  872. WINAPI
  873. CryptDestroyHash(
  874. HCRYPTHASH hHash
  875. );
  876. WINADVAPI
  877. BOOL
  878. WINAPI
  879. CryptSignHashA(
  880. HCRYPTHASH hHash,
  881. DWORD dwKeySpec,
  882. LPCSTR szDescription,
  883. DWORD dwFlags,
  884. BYTE *pbSignature,
  885. DWORD *pdwSigLen
  886. );
  887. WINADVAPI
  888. BOOL
  889. WINAPI
  890. CryptSignHashW(
  891. HCRYPTHASH hHash,
  892. DWORD dwKeySpec,
  893. LPCWSTR szDescription,
  894. DWORD dwFlags,
  895. BYTE *pbSignature,
  896. DWORD *pdwSigLen
  897. );
  898. #ifdef UNICODE
  899. #define CryptSignHash CryptSignHashW
  900. #else
  901. #define CryptSignHash CryptSignHashA
  902. #endif // !UNICODE
  903. WINADVAPI
  904. BOOL
  905. WINAPI
  906. CryptVerifySignatureA(
  907. HCRYPTHASH hHash,
  908. CONST BYTE *pbSignature,
  909. DWORD dwSigLen,
  910. HCRYPTKEY hPubKey,
  911. LPCSTR szDescription,
  912. DWORD dwFlags
  913. );
  914. WINADVAPI
  915. BOOL
  916. WINAPI
  917. CryptVerifySignatureW(
  918. HCRYPTHASH hHash,
  919. CONST BYTE *pbSignature,
  920. DWORD dwSigLen,
  921. HCRYPTKEY hPubKey,
  922. LPCWSTR szDescription,
  923. DWORD dwFlags
  924. );
  925. #ifdef UNICODE
  926. #define CryptVerifySignature CryptVerifySignatureW
  927. #else
  928. #define CryptVerifySignature CryptVerifySignatureA
  929. #endif // !UNICODE
  930. WINADVAPI
  931. BOOL
  932. WINAPI
  933. CryptSetProviderA(
  934. LPCSTR pszProvName,
  935. DWORD dwProvType
  936. );
  937. WINADVAPI
  938. BOOL
  939. WINAPI
  940. CryptSetProviderW(
  941. LPCWSTR pszProvName,
  942. DWORD dwProvType
  943. );
  944. #ifdef UNICODE
  945. #define CryptSetProvider CryptSetProviderW
  946. #else
  947. #define CryptSetProvider CryptSetProviderA
  948. #endif // !UNICODE
  949. WINADVAPI
  950. BOOL
  951. WINAPI
  952. CryptSetProviderExA(
  953. LPCSTR pszProvName,
  954. DWORD dwProvType,
  955. DWORD *pdwReserved,
  956. DWORD dwFlags
  957. );
  958. WINADVAPI
  959. BOOL
  960. WINAPI
  961. CryptSetProviderExW(
  962. LPCWSTR pszProvName,
  963. DWORD dwProvType,
  964. DWORD *pdwReserved,
  965. DWORD dwFlags
  966. );
  967. #ifdef UNICODE
  968. #define CryptSetProviderEx CryptSetProviderExW
  969. #else
  970. #define CryptSetProviderEx CryptSetProviderExA
  971. #endif // !UNICODE
  972. WINADVAPI
  973. BOOL
  974. WINAPI
  975. CryptGetDefaultProviderA(
  976. DWORD dwProvType,
  977. DWORD *pdwReserved,
  978. DWORD dwFlags,
  979. LPSTR pszProvName,
  980. DWORD *pcbProvName
  981. );
  982. WINADVAPI
  983. BOOL
  984. WINAPI
  985. CryptGetDefaultProviderW(
  986. DWORD dwProvType,
  987. DWORD *pdwReserved,
  988. DWORD dwFlags,
  989. LPWSTR pszProvName,
  990. DWORD *pcbProvName
  991. );
  992. #ifdef UNICODE
  993. #define CryptGetDefaultProvider CryptGetDefaultProviderW
  994. #else
  995. #define CryptGetDefaultProvider CryptGetDefaultProviderA
  996. #endif // !UNICODE
  997. WINADVAPI
  998. BOOL
  999. WINAPI
  1000. CryptEnumProviderTypesA(
  1001. DWORD dwIndex,
  1002. DWORD *pdwReserved,
  1003. DWORD dwFlags,
  1004. DWORD *pdwProvType,
  1005. LPSTR szTypeName,
  1006. DWORD *pcbTypeName
  1007. );
  1008. WINADVAPI
  1009. BOOL
  1010. WINAPI
  1011. CryptEnumProviderTypesW(
  1012. DWORD dwIndex,
  1013. DWORD *pdwReserved,
  1014. DWORD dwFlags,
  1015. DWORD *pdwProvType,
  1016. LPWSTR szTypeName,
  1017. DWORD *pcbTypeName
  1018. );
  1019. #ifdef UNICODE
  1020. #define CryptEnumProviderTypes CryptEnumProviderTypesW
  1021. #else
  1022. #define CryptEnumProviderTypes CryptEnumProviderTypesA
  1023. #endif // !UNICODE
  1024. WINADVAPI
  1025. BOOL
  1026. WINAPI
  1027. CryptEnumProvidersA(
  1028. DWORD dwIndex,
  1029. DWORD *pdwReserved,
  1030. DWORD dwFlags,
  1031. DWORD *pdwProvType,
  1032. LPSTR szProvName,
  1033. DWORD *pcbProvName
  1034. );
  1035. WINADVAPI
  1036. BOOL
  1037. WINAPI
  1038. CryptEnumProvidersW(
  1039. DWORD dwIndex,
  1040. DWORD *pdwReserved,
  1041. DWORD dwFlags,
  1042. DWORD *pdwProvType,
  1043. LPWSTR szProvName,
  1044. DWORD *pcbProvName
  1045. );
  1046. #ifdef UNICODE
  1047. #define CryptEnumProviders CryptEnumProvidersW
  1048. #else
  1049. #define CryptEnumProviders CryptEnumProvidersA
  1050. #endif // !UNICODE
  1051. WINADVAPI
  1052. BOOL
  1053. WINAPI
  1054. CryptContextAddRef(
  1055. HCRYPTPROV hProv,
  1056. DWORD *pdwReserved,
  1057. DWORD dwFlags
  1058. );
  1059. WINADVAPI
  1060. BOOL
  1061. WINAPI
  1062. CryptDuplicateKey(
  1063. HCRYPTKEY hKey,
  1064. DWORD *pdwReserved,
  1065. DWORD dwFlags,
  1066. HCRYPTKEY *phKey
  1067. );
  1068. WINADVAPI
  1069. BOOL
  1070. WINAPI
  1071. CryptDuplicateHash(
  1072. HCRYPTHASH hHash,
  1073. DWORD *pdwReserved,
  1074. DWORD dwFlags,
  1075. HCRYPTHASH *phHash
  1076. );
  1077. typedef struct {
  1078. DWORD dwVersion;
  1079. ALG_ID algId;
  1080. DWORD dwMinKeyLength;
  1081. DWORD dwMaxKeyLength;
  1082. DWORD dwRequiredFlags;
  1083. DWORD dwDisallowedFlags;
  1084. } _CRYPT_KEY_LIMITS_V01;
  1085. typedef _CRYPT_KEY_LIMITS_V01 CRYPT_KEY_LIMITS, *PCRYPT_KEY_LIMITS;
  1086. // Request Flag definitions
  1087. #define CRYPTLIMIT_USING_PCT 0x0001
  1088. #define CRYPTLIMIT_USING_SGC 0x0002
  1089. WINADVAPI
  1090. BOOL
  1091. WINAPI
  1092. CryptGetLocalKeyLimits(
  1093. IN ALG_ID algId,
  1094. IN DWORD dwFlags,
  1095. OUT PCRYPT_KEY_LIMITS pLimits,
  1096. IN OUT LPDWORD cbLimitLength);
  1097. //+-------------------------------------------------------------------------
  1098. // In a CRYPT_BIT_BLOB the last byte may contain 0-7 unused bits. Therefore, the
  1099. // overall bit length is cbData * 8 - cUnusedBits.
  1100. //--------------------------------------------------------------------------
  1101. typedef struct _CRYPT_BIT_BLOB {
  1102. DWORD cbData;
  1103. BYTE *pbData;
  1104. DWORD cUnusedBits;
  1105. } CRYPT_BIT_BLOB, *PCRYPT_BIT_BLOB;
  1106. //+-------------------------------------------------------------------------
  1107. // Type used for any algorithm
  1108. //
  1109. // Where the Parameters CRYPT_OBJID_BLOB is in its encoded representation. For most
  1110. // algorithm types, the Parameters CRYPT_OBJID_BLOB is NULL (Parameters.cbData = 0).
  1111. //--------------------------------------------------------------------------
  1112. typedef struct _CRYPT_ALGORITHM_IDENTIFIER {
  1113. LPSTR pszObjId;
  1114. CRYPT_OBJID_BLOB Parameters;
  1115. } CRYPT_ALGORITHM_IDENTIFIER, *PCRYPT_ALGORITHM_IDENTIFIER;
  1116. // Following are the definitions of various algorithm object identifiers
  1117. // RSA
  1118. #define szOID_RSA "1.2.840.113549"
  1119. #define szOID_PKCS "1.2.840.113549.1"
  1120. #define szOID_RSA_HASH "1.2.840.113549.2"
  1121. #define szOID_RSA_ENCRYPT "1.2.840.113549.3"
  1122. #define szOID_PKCS_1 "1.2.840.113549.1.1"
  1123. #define szOID_PKCS_2 "1.2.840.113549.1.2"
  1124. #define szOID_PKCS_3 "1.2.840.113549.1.3"
  1125. #define szOID_PKCS_4 "1.2.840.113549.1.4"
  1126. #define szOID_PKCS_5 "1.2.840.113549.1.5"
  1127. #define szOID_PKCS_6 "1.2.840.113549.1.6"
  1128. #define szOID_PKCS_7 "1.2.840.113549.1.7"
  1129. #define szOID_PKCS_8 "1.2.840.113549.1.8"
  1130. #define szOID_PKCS_9 "1.2.840.113549.1.9"
  1131. #define szOID_PKCS_10 "1.2.840.113549.1.10"
  1132. #define szOID_PKCS_12 "1.2.840.113549.1.12"
  1133. #define szOID_RSA_RSA "1.2.840.113549.1.1.1"
  1134. #define szOID_RSA_MD2RSA "1.2.840.113549.1.1.2"
  1135. #define szOID_RSA_MD4RSA "1.2.840.113549.1.1.3"
  1136. #define szOID_RSA_MD5RSA "1.2.840.113549.1.1.4"
  1137. #define szOID_RSA_SHA1RSA "1.2.840.113549.1.1.5"
  1138. #define szOID_RSA_SETOAEP_RSA "1.2.840.113549.1.1.6"
  1139. #define szOID_RSA_DH "1.2.840.113549.1.3.1"
  1140. #define szOID_RSA_data "1.2.840.113549.1.7.1"
  1141. #define szOID_RSA_signedData "1.2.840.113549.1.7.2"
  1142. #define szOID_RSA_envelopedData "1.2.840.113549.1.7.3"
  1143. #define szOID_RSA_signEnvData "1.2.840.113549.1.7.4"
  1144. #define szOID_RSA_digestedData "1.2.840.113549.1.7.5"
  1145. #define szOID_RSA_hashedData "1.2.840.113549.1.7.5"
  1146. #define szOID_RSA_encryptedData "1.2.840.113549.1.7.6"
  1147. #define szOID_RSA_emailAddr "1.2.840.113549.1.9.1"
  1148. #define szOID_RSA_unstructName "1.2.840.113549.1.9.2"
  1149. #define szOID_RSA_contentType "1.2.840.113549.1.9.3"
  1150. #define szOID_RSA_messageDigest "1.2.840.113549.1.9.4"
  1151. #define szOID_RSA_signingTime "1.2.840.113549.1.9.5"
  1152. #define szOID_RSA_counterSign "1.2.840.113549.1.9.6"
  1153. #define szOID_RSA_challengePwd "1.2.840.113549.1.9.7"
  1154. #define szOID_RSA_unstructAddr "1.2.840.113549.1.9.8"
  1155. #define szOID_RSA_extCertAttrs "1.2.840.113549.1.9.9"
  1156. #define szOID_RSA_certExtensions "1.2.840.113549.1.9.14"
  1157. #define szOID_RSA_SMIMECapabilities "1.2.840.113549.1.9.15"
  1158. #define szOID_RSA_preferSignedData "1.2.840.113549.1.9.15.1"
  1159. #define szOID_RSA_SMIMEalg "1.2.840.113549.1.9.16.3"
  1160. #define szOID_RSA_SMIMEalgESDH "1.2.840.113549.1.9.16.3.5"
  1161. #define szOID_RSA_SMIMEalgCMS3DESwrap "1.2.840.113549.1.9.16.3.6"
  1162. #define szOID_RSA_SMIMEalgCMSRC2wrap "1.2.840.113549.1.9.16.3.7"
  1163. #define szOID_RSA_MD2 "1.2.840.113549.2.2"
  1164. #define szOID_RSA_MD4 "1.2.840.113549.2.4"
  1165. #define szOID_RSA_MD5 "1.2.840.113549.2.5"
  1166. #define szOID_RSA_RC2CBC "1.2.840.113549.3.2"
  1167. #define szOID_RSA_RC4 "1.2.840.113549.3.4"
  1168. #define szOID_RSA_DES_EDE3_CBC "1.2.840.113549.3.7"
  1169. #define szOID_RSA_RC5_CBCPad "1.2.840.113549.3.9"
  1170. #define szOID_ANSI_X942 "1.2.840.10046"
  1171. #define szOID_ANSI_X942_DH "1.2.840.10046.2.1"
  1172. #define szOID_X957 "1.2.840.10040"
  1173. #define szOID_X957_DSA "1.2.840.10040.4.1"
  1174. #define szOID_X957_SHA1DSA "1.2.840.10040.4.3"
  1175. // ITU-T UsefulDefinitions
  1176. #define szOID_DS "2.5"
  1177. #define szOID_DSALG "2.5.8"
  1178. #define szOID_DSALG_CRPT "2.5.8.1"
  1179. #define szOID_DSALG_HASH "2.5.8.2"
  1180. #define szOID_DSALG_SIGN "2.5.8.3"
  1181. #define szOID_DSALG_RSA "2.5.8.1.1"
  1182. // NIST OSE Implementors' Workshop (OIW)
  1183. // http://nemo.ncsl.nist.gov/oiw/agreements/stable/OSI/12s_9506.w51
  1184. // http://nemo.ncsl.nist.gov/oiw/agreements/working/OSI/12w_9503.w51
  1185. #define szOID_OIW "1.3.14"
  1186. // NIST OSE Implementors' Workshop (OIW) Security SIG algorithm identifiers
  1187. #define szOID_OIWSEC "1.3.14.3.2"
  1188. #define szOID_OIWSEC_md4RSA "1.3.14.3.2.2"
  1189. #define szOID_OIWSEC_md5RSA "1.3.14.3.2.3"
  1190. #define szOID_OIWSEC_md4RSA2 "1.3.14.3.2.4"
  1191. #define szOID_OIWSEC_desECB "1.3.14.3.2.6"
  1192. #define szOID_OIWSEC_desCBC "1.3.14.3.2.7"
  1193. #define szOID_OIWSEC_desOFB "1.3.14.3.2.8"
  1194. #define szOID_OIWSEC_desCFB "1.3.14.3.2.9"
  1195. #define szOID_OIWSEC_desMAC "1.3.14.3.2.10"
  1196. #define szOID_OIWSEC_rsaSign "1.3.14.3.2.11"
  1197. #define szOID_OIWSEC_dsa "1.3.14.3.2.12"
  1198. #define szOID_OIWSEC_shaDSA "1.3.14.3.2.13"
  1199. #define szOID_OIWSEC_mdc2RSA "1.3.14.3.2.14"
  1200. #define szOID_OIWSEC_shaRSA "1.3.14.3.2.15"
  1201. #define szOID_OIWSEC_dhCommMod "1.3.14.3.2.16"
  1202. #define szOID_OIWSEC_desEDE "1.3.14.3.2.17"
  1203. #define szOID_OIWSEC_sha "1.3.14.3.2.18"
  1204. #define szOID_OIWSEC_mdc2 "1.3.14.3.2.19"
  1205. #define szOID_OIWSEC_dsaComm "1.3.14.3.2.20"
  1206. #define szOID_OIWSEC_dsaCommSHA "1.3.14.3.2.21"
  1207. #define szOID_OIWSEC_rsaXchg "1.3.14.3.2.22"
  1208. #define szOID_OIWSEC_keyHashSeal "1.3.14.3.2.23"
  1209. #define szOID_OIWSEC_md2RSASign "1.3.14.3.2.24"
  1210. #define szOID_OIWSEC_md5RSASign "1.3.14.3.2.25"
  1211. #define szOID_OIWSEC_sha1 "1.3.14.3.2.26"
  1212. #define szOID_OIWSEC_dsaSHA1 "1.3.14.3.2.27"
  1213. #define szOID_OIWSEC_dsaCommSHA1 "1.3.14.3.2.28"
  1214. #define szOID_OIWSEC_sha1RSASign "1.3.14.3.2.29"
  1215. // NIST OSE Implementors' Workshop (OIW) Directory SIG algorithm identifiers
  1216. #define szOID_OIWDIR "1.3.14.7.2"
  1217. #define szOID_OIWDIR_CRPT "1.3.14.7.2.1"
  1218. #define szOID_OIWDIR_HASH "1.3.14.7.2.2"
  1219. #define szOID_OIWDIR_SIGN "1.3.14.7.2.3"
  1220. #define szOID_OIWDIR_md2 "1.3.14.7.2.2.1"
  1221. #define szOID_OIWDIR_md2RSA "1.3.14.7.2.3.1"
  1222. // INFOSEC Algorithms
  1223. // joint-iso-ccitt(2) country(16) us(840) organization(1) us-government(101) dod(2) id-infosec(1)
  1224. #define szOID_INFOSEC "2.16.840.1.101.2.1"
  1225. #define szOID_INFOSEC_sdnsSignature "2.16.840.1.101.2.1.1.1"
  1226. #define szOID_INFOSEC_mosaicSignature "2.16.840.1.101.2.1.1.2"
  1227. #define szOID_INFOSEC_sdnsConfidentiality "2.16.840.1.101.2.1.1.3"
  1228. #define szOID_INFOSEC_mosaicConfidentiality "2.16.840.1.101.2.1.1.4"
  1229. #define szOID_INFOSEC_sdnsIntegrity "2.16.840.1.101.2.1.1.5"
  1230. #define szOID_INFOSEC_mosaicIntegrity "2.16.840.1.101.2.1.1.6"
  1231. #define szOID_INFOSEC_sdnsTokenProtection "2.16.840.1.101.2.1.1.7"
  1232. #define szOID_INFOSEC_mosaicTokenProtection "2.16.840.1.101.2.1.1.8"
  1233. #define szOID_INFOSEC_sdnsKeyManagement "2.16.840.1.101.2.1.1.9"
  1234. #define szOID_INFOSEC_mosaicKeyManagement "2.16.840.1.101.2.1.1.10"
  1235. #define szOID_INFOSEC_sdnsKMandSig "2.16.840.1.101.2.1.1.11"
  1236. #define szOID_INFOSEC_mosaicKMandSig "2.16.840.1.101.2.1.1.12"
  1237. #define szOID_INFOSEC_SuiteASignature "2.16.840.1.101.2.1.1.13"
  1238. #define szOID_INFOSEC_SuiteAConfidentiality "2.16.840.1.101.2.1.1.14"
  1239. #define szOID_INFOSEC_SuiteAIntegrity "2.16.840.1.101.2.1.1.15"
  1240. #define szOID_INFOSEC_SuiteATokenProtection "2.16.840.1.101.2.1.1.16"
  1241. #define szOID_INFOSEC_SuiteAKeyManagement "2.16.840.1.101.2.1.1.17"
  1242. #define szOID_INFOSEC_SuiteAKMandSig "2.16.840.1.101.2.1.1.18"
  1243. #define szOID_INFOSEC_mosaicUpdatedSig "2.16.840.1.101.2.1.1.19"
  1244. #define szOID_INFOSEC_mosaicKMandUpdSig "2.16.840.1.101.2.1.1.20"
  1245. #define szOID_INFOSEC_mosaicUpdatedInteg "2.16.840.1.101.2.1.1.21"
  1246. typedef struct _CRYPT_OBJID_TABLE {
  1247. DWORD dwAlgId;
  1248. LPCSTR pszObjId;
  1249. } CRYPT_OBJID_TABLE, *PCRYPT_OBJID_TABLE;
  1250. //+-------------------------------------------------------------------------
  1251. // PKCS #1 HashInfo (DigestInfo)
  1252. //--------------------------------------------------------------------------
  1253. typedef struct _CRYPT_HASH_INFO {
  1254. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  1255. CRYPT_HASH_BLOB Hash;
  1256. } CRYPT_HASH_INFO, *PCRYPT_HASH_INFO;
  1257. //+-------------------------------------------------------------------------
  1258. // Type used for an extension to an encoded content
  1259. //
  1260. // Where the Value's CRYPT_OBJID_BLOB is in its encoded representation.
  1261. //--------------------------------------------------------------------------
  1262. typedef struct _CERT_EXTENSION {
  1263. LPSTR pszObjId;
  1264. BOOL fCritical;
  1265. CRYPT_OBJID_BLOB Value;
  1266. } CERT_EXTENSION, *PCERT_EXTENSION;
  1267. //+-------------------------------------------------------------------------
  1268. // AttributeTypeValue
  1269. //
  1270. // Where the Value's CRYPT_OBJID_BLOB is in its encoded representation.
  1271. //--------------------------------------------------------------------------
  1272. typedef struct _CRYPT_ATTRIBUTE_TYPE_VALUE {
  1273. LPSTR pszObjId;
  1274. CRYPT_OBJID_BLOB Value;
  1275. } CRYPT_ATTRIBUTE_TYPE_VALUE, *PCRYPT_ATTRIBUTE_TYPE_VALUE;
  1276. //+-------------------------------------------------------------------------
  1277. // Attributes
  1278. //
  1279. // Where the Value's PATTR_BLOBs are in their encoded representation.
  1280. //--------------------------------------------------------------------------
  1281. typedef struct _CRYPT_ATTRIBUTE {
  1282. LPSTR pszObjId;
  1283. DWORD cValue;
  1284. PCRYPT_ATTR_BLOB rgValue;
  1285. } CRYPT_ATTRIBUTE, *PCRYPT_ATTRIBUTE;
  1286. typedef struct _CRYPT_ATTRIBUTES {
  1287. IN DWORD cAttr;
  1288. IN PCRYPT_ATTRIBUTE rgAttr;
  1289. } CRYPT_ATTRIBUTES, *PCRYPT_ATTRIBUTES;
  1290. //+-------------------------------------------------------------------------
  1291. // Attributes making up a Relative Distinguished Name (CERT_RDN)
  1292. //
  1293. // The interpretation of the Value depends on the dwValueType.
  1294. // See below for a list of the types.
  1295. //--------------------------------------------------------------------------
  1296. typedef struct _CERT_RDN_ATTR {
  1297. LPSTR pszObjId;
  1298. DWORD dwValueType;
  1299. CERT_RDN_VALUE_BLOB Value;
  1300. } CERT_RDN_ATTR, *PCERT_RDN_ATTR;
  1301. //+-------------------------------------------------------------------------
  1302. // CERT_RDN attribute Object Identifiers
  1303. //--------------------------------------------------------------------------
  1304. // Labeling attribute types:
  1305. #define szOID_COMMON_NAME "2.5.4.3" // case-ignore string
  1306. #define szOID_SUR_NAME "2.5.4.4" // case-ignore string
  1307. #define szOID_DEVICE_SERIAL_NUMBER "2.5.4.5" // printable string
  1308. // Geographic attribute types:
  1309. #define szOID_COUNTRY_NAME "2.5.4.6" // printable 2char string
  1310. #define szOID_LOCALITY_NAME "2.5.4.7" // case-ignore string
  1311. #define szOID_STATE_OR_PROVINCE_NAME "2.5.4.8" // case-ignore string
  1312. #define szOID_STREET_ADDRESS "2.5.4.9" // case-ignore string
  1313. // Organizational attribute types:
  1314. #define szOID_ORGANIZATION_NAME "2.5.4.10" // case-ignore string
  1315. #define szOID_ORGANIZATIONAL_UNIT_NAME "2.5.4.11" // case-ignore string
  1316. #define szOID_TITLE "2.5.4.12" // case-ignore string
  1317. // Explanatory attribute types:
  1318. #define szOID_DESCRIPTION "2.5.4.13" // case-ignore string
  1319. #define szOID_SEARCH_GUIDE "2.5.4.14"
  1320. #define szOID_BUSINESS_CATEGORY "2.5.4.15" // case-ignore string
  1321. // Postal addressing attribute types:
  1322. #define szOID_POSTAL_ADDRESS "2.5.4.16"
  1323. #define szOID_POSTAL_CODE "2.5.4.17" // case-ignore string
  1324. #define szOID_POST_OFFICE_BOX "2.5.4.18" // case-ignore string
  1325. #define szOID_PHYSICAL_DELIVERY_OFFICE_NAME "2.5.4.19" // case-ignore string
  1326. // Telecommunications addressing attribute types:
  1327. #define szOID_TELEPHONE_NUMBER "2.5.4.20" // telephone number
  1328. #define szOID_TELEX_NUMBER "2.5.4.21"
  1329. #define szOID_TELETEXT_TERMINAL_IDENTIFIER "2.5.4.22"
  1330. #define szOID_FACSIMILE_TELEPHONE_NUMBER "2.5.4.23"
  1331. #define szOID_X21_ADDRESS "2.5.4.24" // numeric string
  1332. #define szOID_INTERNATIONAL_ISDN_NUMBER "2.5.4.25" // numeric string
  1333. #define szOID_REGISTERED_ADDRESS "2.5.4.26"
  1334. #define szOID_DESTINATION_INDICATOR "2.5.4.27" // printable string
  1335. // Preference attribute types:
  1336. #define szOID_PREFERRED_DELIVERY_METHOD "2.5.4.28"
  1337. // OSI application attribute types:
  1338. #define szOID_PRESENTATION_ADDRESS "2.5.4.29"
  1339. #define szOID_SUPPORTED_APPLICATION_CONTEXT "2.5.4.30"
  1340. // Relational application attribute types:
  1341. #define szOID_MEMBER "2.5.4.31"
  1342. #define szOID_OWNER "2.5.4.32"
  1343. #define szOID_ROLE_OCCUPANT "2.5.4.33"
  1344. #define szOID_SEE_ALSO "2.5.4.34"
  1345. // Security attribute types:
  1346. #define szOID_USER_PASSWORD "2.5.4.35"
  1347. #define szOID_USER_CERTIFICATE "2.5.4.36"
  1348. #define szOID_CA_CERTIFICATE "2.5.4.37"
  1349. #define szOID_AUTHORITY_REVOCATION_LIST "2.5.4.38"
  1350. #define szOID_CERTIFICATE_REVOCATION_LIST "2.5.4.39"
  1351. #define szOID_CROSS_CERTIFICATE_PAIR "2.5.4.40"
  1352. // Undocumented attribute types???
  1353. //#define szOID_??? "2.5.4.41"
  1354. #define szOID_GIVEN_NAME "2.5.4.42" // case-ignore string
  1355. #define szOID_INITIALS "2.5.4.43" // case-ignore string
  1356. // The DN Qualifier attribute type specifies disambiguating information to add
  1357. // to the relative distinguished name of an entry. It is intended to be used
  1358. // for entries held in multiple DSAs which would otherwise have the same name,
  1359. // and that its value be the same in a given DSA for all entries to which
  1360. // the information has been added.
  1361. #define szOID_DN_QUALIFIER "2.5.4.46"
  1362. // Pilot user attribute types:
  1363. #define szOID_DOMAIN_COMPONENT "0.9.2342.19200300.100.1.25" // IA5, UTF8 string
  1364. // used for PKCS 12 attributes
  1365. #define szOID_PKCS_12_FRIENDLY_NAME_ATTR "1.2.840.113549.1.9.20"
  1366. #define szOID_PKCS_12_LOCAL_KEY_ID "1.2.840.113549.1.9.21"
  1367. #define szOID_PKCS_12_KEY_PROVIDER_NAME_ATTR "1.3.6.1.4.1.311.17.1"
  1368. #define szOID_LOCAL_MACHINE_KEYSET "1.3.6.1.4.1.311.17.2"
  1369. //+-------------------------------------------------------------------------
  1370. // Microsoft CERT_RDN attribute Object Identifiers
  1371. //--------------------------------------------------------------------------
  1372. // Special RDN containing the KEY_ID. Its value type is CERT_RDN_OCTET_STRING.
  1373. #define szOID_KEYID_RDN "1.3.6.1.4.1.311.10.7.1"
  1374. //+-------------------------------------------------------------------------
  1375. // CERT_RDN Attribute Value Types
  1376. //
  1377. // For RDN_ENCODED_BLOB, the Value's CERT_RDN_VALUE_BLOB is in its encoded
  1378. // representation. Otherwise, its an array of bytes.
  1379. //
  1380. // For all CERT_RDN types, Value.cbData is always the number of bytes, not
  1381. // necessarily the number of elements in the string. For instance,
  1382. // RDN_UNIVERSAL_STRING is an array of ints (cbData == intCnt * 4) and
  1383. // RDN_BMP_STRING is an array of unsigned shorts (cbData == ushortCnt * 2).
  1384. //
  1385. // A RDN_UTF8_STRING is an array of UNICODE characters (cbData == charCnt *2).
  1386. // These UNICODE characters are encoded as UTF8 8 bit characters.
  1387. //
  1388. // For CertDecodeName, two 0 bytes are always appended to the end of the
  1389. // string (ensures a CHAR or WCHAR string is null terminated).
  1390. // These added 0 bytes are't included in the BLOB.cbData.
  1391. //--------------------------------------------------------------------------
  1392. #define CERT_RDN_ANY_TYPE 0
  1393. #define CERT_RDN_ENCODED_BLOB 1
  1394. #define CERT_RDN_OCTET_STRING 2
  1395. #define CERT_RDN_NUMERIC_STRING 3
  1396. #define CERT_RDN_PRINTABLE_STRING 4
  1397. #define CERT_RDN_TELETEX_STRING 5
  1398. #define CERT_RDN_T61_STRING 5
  1399. #define CERT_RDN_VIDEOTEX_STRING 6
  1400. #define CERT_RDN_IA5_STRING 7
  1401. #define CERT_RDN_GRAPHIC_STRING 8
  1402. #define CERT_RDN_VISIBLE_STRING 9
  1403. #define CERT_RDN_ISO646_STRING 9
  1404. #define CERT_RDN_GENERAL_STRING 10
  1405. #define CERT_RDN_UNIVERSAL_STRING 11
  1406. #define CERT_RDN_INT4_STRING 11
  1407. #define CERT_RDN_BMP_STRING 12
  1408. #define CERT_RDN_UNICODE_STRING 12
  1409. #define CERT_RDN_UTF8_STRING 13
  1410. #define CERT_RDN_TYPE_MASK 0x000000FF
  1411. #define CERT_RDN_FLAGS_MASK 0xFF000000
  1412. //+-------------------------------------------------------------------------
  1413. // Flags that can be or'ed with the above Value Type when encoding/decoding
  1414. //--------------------------------------------------------------------------
  1415. // For encoding: when set, CERT_RDN_T61_STRING is selected instead of
  1416. // CERT_RDN_UNICODE_STRING if all the unicode characters are <= 0xFF
  1417. #define CERT_RDN_ENABLE_T61_UNICODE_FLAG 0x80000000
  1418. // For encoding: when set, CERT_RDN_UTF8_STRING is selected instead of
  1419. // CERT_RDN_UNICODE_STRING.
  1420. #define CERT_RDN_ENABLE_UTF8_UNICODE_FLAG 0x20000000
  1421. // For encoding: when set, the characters aren't checked to see if they
  1422. // are valid for the Value Type.
  1423. #define CERT_RDN_DISABLE_CHECK_TYPE_FLAG 0x40000000
  1424. // For decoding: by default, CERT_RDN_T61_STRING values are initially decoded
  1425. // as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  1426. // Setting this flag skips the initial attempt to decode as UTF8.
  1427. #define CERT_RDN_DISABLE_IE4_UTF8_FLAG 0x01000000
  1428. // Macro to check that the dwValueType is a character string and not an
  1429. // encoded blob or octet string
  1430. #define IS_CERT_RDN_CHAR_STRING(X) \
  1431. (((X) & CERT_RDN_TYPE_MASK) >= CERT_RDN_NUMERIC_STRING)
  1432. //+-------------------------------------------------------------------------
  1433. // A CERT_RDN consists of an array of the above attributes
  1434. //--------------------------------------------------------------------------
  1435. typedef struct _CERT_RDN {
  1436. DWORD cRDNAttr;
  1437. PCERT_RDN_ATTR rgRDNAttr;
  1438. } CERT_RDN, *PCERT_RDN;
  1439. //+-------------------------------------------------------------------------
  1440. // Information stored in a subject's or issuer's name. The information
  1441. // is represented as an array of the above RDNs.
  1442. //--------------------------------------------------------------------------
  1443. typedef struct _CERT_NAME_INFO {
  1444. DWORD cRDN;
  1445. PCERT_RDN rgRDN;
  1446. } CERT_NAME_INFO, *PCERT_NAME_INFO;
  1447. //+-------------------------------------------------------------------------
  1448. // Name attribute value without the Object Identifier
  1449. //
  1450. // The interpretation of the Value depends on the dwValueType.
  1451. // See above for a list of the types.
  1452. //--------------------------------------------------------------------------
  1453. typedef struct _CERT_NAME_VALUE {
  1454. DWORD dwValueType;
  1455. CERT_RDN_VALUE_BLOB Value;
  1456. } CERT_NAME_VALUE, *PCERT_NAME_VALUE;
  1457. //+-------------------------------------------------------------------------
  1458. // Public Key Info
  1459. //
  1460. // The PublicKey is the encoded representation of the information as it is
  1461. // stored in the bit string
  1462. //--------------------------------------------------------------------------
  1463. typedef struct _CERT_PUBLIC_KEY_INFO {
  1464. CRYPT_ALGORITHM_IDENTIFIER Algorithm;
  1465. CRYPT_BIT_BLOB PublicKey;
  1466. } CERT_PUBLIC_KEY_INFO, *PCERT_PUBLIC_KEY_INFO;
  1467. #define CERT_RSA_PUBLIC_KEY_OBJID szOID_RSA_RSA
  1468. #define CERT_DEFAULT_OID_PUBLIC_KEY_SIGN szOID_RSA_RSA
  1469. #define CERT_DEFAULT_OID_PUBLIC_KEY_XCHG szOID_RSA_RSA
  1470. //+-------------------------------------------------------------------------
  1471. // structure that contains all the information in a PKCS#8 PrivateKeyInfo
  1472. //--------------------------------------------------------------------------
  1473. typedef struct _CRYPT_PRIVATE_KEY_INFO{
  1474. DWORD Version;
  1475. CRYPT_ALGORITHM_IDENTIFIER Algorithm;
  1476. CRYPT_DER_BLOB PrivateKey;
  1477. PCRYPT_ATTRIBUTES pAttributes;
  1478. } CRYPT_PRIVATE_KEY_INFO, *PCRYPT_PRIVATE_KEY_INFO;
  1479. //+-------------------------------------------------------------------------
  1480. // structure that contains all the information in a PKCS#8
  1481. // EncryptedPrivateKeyInfo
  1482. //--------------------------------------------------------------------------
  1483. typedef struct _CRYPT_ENCRYPTED_PRIVATE_KEY_INFO{
  1484. CRYPT_ALGORITHM_IDENTIFIER EncryptionAlgorithm;
  1485. CRYPT_DATA_BLOB EncryptedPrivateKey;
  1486. } CRYPT_ENCRYPTED_PRIVATE_KEY_INFO, *PCRYPT_ENCRYPTED_PRIVATE_KEY_INFO;
  1487. //+-------------------------------------------------------------------------
  1488. // this callback is given when an EncryptedProvateKeyInfo structure is
  1489. // encountered during ImportPKCS8. the caller is then expected to decrypt
  1490. // the private key and hand back the decrypted contents.
  1491. //
  1492. // the parameters are:
  1493. // Algorithm - the algorithm used to encrypt the PrivateKeyInfo
  1494. // EncryptedPrivateKey - the encrypted private key blob
  1495. // pClearTextKey - a buffer to receive the clear text
  1496. // cbClearTextKey - the number of bytes of the pClearTextKey buffer
  1497. // note the if this is zero then this should be
  1498. // filled in with the size required to decrypt the
  1499. // key into, and pClearTextKey should be ignored
  1500. // pVoidDecryptFunc - this is the pVoid that was passed into the call
  1501. // and is preserved and passed back as context
  1502. //+-------------------------------------------------------------------------
  1503. typedef BOOL (CALLBACK *PCRYPT_DECRYPT_PRIVATE_KEY_FUNC)(
  1504. CRYPT_ALGORITHM_IDENTIFIER Algorithm,
  1505. CRYPT_DATA_BLOB EncryptedPrivateKey,
  1506. BYTE *pbClearTextKey,
  1507. DWORD *pcbClearTextKey,
  1508. LPVOID pVoidDecryptFunc);
  1509. //+-------------------------------------------------------------------------
  1510. // this callback is given when creating a PKCS8 EncryptedPrivateKeyInfo.
  1511. // The caller is then expected to encrypt the private key and hand back
  1512. // the encrypted contents.
  1513. //
  1514. // the parameters are:
  1515. // Algorithm - the algorithm used to encrypt the PrivateKeyInfo
  1516. // pClearTextPrivateKey - the cleartext private key to be encrypted
  1517. // pbEncryptedKey - the output encrypted private key blob
  1518. // cbEncryptedKey - the number of bytes of the pbEncryptedKey buffer
  1519. // note the if this is zero then this should be
  1520. // filled in with the size required to encrypt the
  1521. // key into, and pbEncryptedKey should be ignored
  1522. // pVoidEncryptFunc - this is the pVoid that was passed into the call
  1523. // and is preserved and passed back as context
  1524. //+-------------------------------------------------------------------------
  1525. typedef BOOL (CALLBACK *PCRYPT_ENCRYPT_PRIVATE_KEY_FUNC)(
  1526. CRYPT_ALGORITHM_IDENTIFIER* pAlgorithm,
  1527. CRYPT_DATA_BLOB* pClearTextPrivateKey,
  1528. BYTE *pbEncryptedKey,
  1529. DWORD *pcbEncryptedKey,
  1530. LPVOID pVoidEncryptFunc);
  1531. //+-------------------------------------------------------------------------
  1532. // this callback is given from the context of a ImportPKCS8 calls. the caller
  1533. // is then expected to hand back an HCRYPTPROV to receive the key being imported
  1534. //
  1535. // the parameters are:
  1536. // pPrivateKeyInfo - pointer to a CRYPT_PRIVATE_KEY_INFO structure which
  1537. // describes the key being imported
  1538. // EncryptedPrivateKey - the encrypted private key blob
  1539. // phCryptProv - a pointer to a HCRRYPTPROV to be filled in
  1540. // pVoidResolveFunc - this is the pVoidResolveFunc passed in by the caller in the
  1541. // CRYPT_PRIVATE_KEY_BLOB_AND_PARAMS struct
  1542. //+-------------------------------------------------------------------------
  1543. typedef BOOL (CALLBACK *PCRYPT_RESOLVE_HCRYPTPROV_FUNC)(
  1544. CRYPT_PRIVATE_KEY_INFO *pPrivateKeyInfo,
  1545. HCRYPTPROV *phCryptProv,
  1546. LPVOID pVoidResolveFunc);
  1547. //+-------------------------------------------------------------------------
  1548. // this struct contains a PKCS8 private key and two pointers to callback
  1549. // functions, with a corresponding pVoids. the first callback is used to give
  1550. // the caller the opportunity to specify where the key is imported to. the callback
  1551. // passes the caller the algoroithm OID and key size to use in making the decision.
  1552. // the other callback is used to decrypt the private key if the PKCS8 contains an
  1553. // EncryptedPrivateKeyInfo. both pVoids are preserved and passed back to the caller
  1554. // in the respective callback
  1555. //+-------------------------------------------------------------------------
  1556. typedef struct _CRYPT_PKCS8_IMPORT_PARAMS{
  1557. CRYPT_DIGEST_BLOB PrivateKey; // PKCS8 blob
  1558. PCRYPT_RESOLVE_HCRYPTPROV_FUNC pResolvehCryptProvFunc; // optional
  1559. LPVOID pVoidResolveFunc; // optional
  1560. PCRYPT_DECRYPT_PRIVATE_KEY_FUNC pDecryptPrivateKeyFunc;
  1561. LPVOID pVoidDecryptFunc;
  1562. } CRYPT_PKCS8_IMPORT_PARAMS, *PCRYPT_PKCS8_IMPORT_PARAMS, CRYPT_PRIVATE_KEY_BLOB_AND_PARAMS, *PCRYPT_PRIVATE_KEY_BLOB_AND_PARAMS;
  1563. //+-------------------------------------------------------------------------
  1564. // this struct contains information identifying a private key and a pointer
  1565. // to a callback function, with a corresponding pVoid. The callback is used
  1566. // to encrypt the private key. If the pEncryptPrivateKeyFunc is NULL, the
  1567. // key will not be encrypted and an EncryptedPrivateKeyInfo will not be generated.
  1568. // The pVoid is preserved and passed back to the caller in the respective callback
  1569. //+-------------------------------------------------------------------------
  1570. typedef struct _CRYPT_PKCS8_EXPORT_PARAMS{
  1571. HCRYPTPROV hCryptProv;
  1572. DWORD dwKeySpec;
  1573. LPSTR pszPrivateKeyObjId;
  1574. PCRYPT_ENCRYPT_PRIVATE_KEY_FUNC pEncryptPrivateKeyFunc;
  1575. LPVOID pVoidEncryptFunc;
  1576. } CRYPT_PKCS8_EXPORT_PARAMS, *PCRYPT_PKCS8_EXPORT_PARAMS;
  1577. //+-------------------------------------------------------------------------
  1578. // Information stored in a certificate
  1579. //
  1580. // The Issuer, Subject, Algorithm, PublicKey and Extension BLOBs are the
  1581. // encoded representation of the information.
  1582. //--------------------------------------------------------------------------
  1583. typedef struct _CERT_INFO {
  1584. DWORD dwVersion;
  1585. CRYPT_INTEGER_BLOB SerialNumber;
  1586. CRYPT_ALGORITHM_IDENTIFIER SignatureAlgorithm;
  1587. CERT_NAME_BLOB Issuer;
  1588. FILETIME NotBefore;
  1589. FILETIME NotAfter;
  1590. CERT_NAME_BLOB Subject;
  1591. CERT_PUBLIC_KEY_INFO SubjectPublicKeyInfo;
  1592. CRYPT_BIT_BLOB IssuerUniqueId;
  1593. CRYPT_BIT_BLOB SubjectUniqueId;
  1594. DWORD cExtension;
  1595. PCERT_EXTENSION rgExtension;
  1596. } CERT_INFO, *PCERT_INFO;
  1597. //+-------------------------------------------------------------------------
  1598. // Certificate versions
  1599. //--------------------------------------------------------------------------
  1600. #define CERT_V1 0
  1601. #define CERT_V2 1
  1602. #define CERT_V3 2
  1603. //+-------------------------------------------------------------------------
  1604. // Certificate Information Flags
  1605. //--------------------------------------------------------------------------
  1606. #define CERT_INFO_VERSION_FLAG 1
  1607. #define CERT_INFO_SERIAL_NUMBER_FLAG 2
  1608. #define CERT_INFO_SIGNATURE_ALGORITHM_FLAG 3
  1609. #define CERT_INFO_ISSUER_FLAG 4
  1610. #define CERT_INFO_NOT_BEFORE_FLAG 5
  1611. #define CERT_INFO_NOT_AFTER_FLAG 6
  1612. #define CERT_INFO_SUBJECT_FLAG 7
  1613. #define CERT_INFO_SUBJECT_PUBLIC_KEY_INFO_FLAG 8
  1614. #define CERT_INFO_ISSUER_UNIQUE_ID_FLAG 9
  1615. #define CERT_INFO_SUBJECT_UNIQUE_ID_FLAG 10
  1616. #define CERT_INFO_EXTENSION_FLAG 11
  1617. //+-------------------------------------------------------------------------
  1618. // An entry in a CRL
  1619. //
  1620. // The Extension BLOBs are the encoded representation of the information.
  1621. //--------------------------------------------------------------------------
  1622. typedef struct _CRL_ENTRY {
  1623. CRYPT_INTEGER_BLOB SerialNumber;
  1624. FILETIME RevocationDate;
  1625. DWORD cExtension;
  1626. PCERT_EXTENSION rgExtension;
  1627. } CRL_ENTRY, *PCRL_ENTRY;
  1628. //+-------------------------------------------------------------------------
  1629. // Information stored in a CRL
  1630. //
  1631. // The Issuer, Algorithm and Extension BLOBs are the encoded
  1632. // representation of the information.
  1633. //--------------------------------------------------------------------------
  1634. typedef struct _CRL_INFO {
  1635. DWORD dwVersion;
  1636. CRYPT_ALGORITHM_IDENTIFIER SignatureAlgorithm;
  1637. CERT_NAME_BLOB Issuer;
  1638. FILETIME ThisUpdate;
  1639. FILETIME NextUpdate;
  1640. DWORD cCRLEntry;
  1641. PCRL_ENTRY rgCRLEntry;
  1642. DWORD cExtension;
  1643. PCERT_EXTENSION rgExtension;
  1644. } CRL_INFO, *PCRL_INFO;
  1645. //+-------------------------------------------------------------------------
  1646. // CRL versions
  1647. //--------------------------------------------------------------------------
  1648. #define CRL_V1 0
  1649. #define CRL_V2 1
  1650. //+-------------------------------------------------------------------------
  1651. // Information stored in a certificate request
  1652. //
  1653. // The Subject, Algorithm, PublicKey and Attribute BLOBs are the encoded
  1654. // representation of the information.
  1655. //--------------------------------------------------------------------------
  1656. typedef struct _CERT_REQUEST_INFO {
  1657. DWORD dwVersion;
  1658. CERT_NAME_BLOB Subject;
  1659. CERT_PUBLIC_KEY_INFO SubjectPublicKeyInfo;
  1660. DWORD cAttribute;
  1661. PCRYPT_ATTRIBUTE rgAttribute;
  1662. } CERT_REQUEST_INFO, *PCERT_REQUEST_INFO;
  1663. //+-------------------------------------------------------------------------
  1664. // Certificate Request versions
  1665. //--------------------------------------------------------------------------
  1666. #define CERT_REQUEST_V1 0
  1667. //+-------------------------------------------------------------------------
  1668. // Information stored in Netscape's Keygen request
  1669. //--------------------------------------------------------------------------
  1670. typedef struct _CERT_KEYGEN_REQUEST_INFO {
  1671. DWORD dwVersion;
  1672. CERT_PUBLIC_KEY_INFO SubjectPublicKeyInfo;
  1673. LPWSTR pwszChallengeString; // encoded as IA5
  1674. } CERT_KEYGEN_REQUEST_INFO, *PCERT_KEYGEN_REQUEST_INFO;
  1675. #define CERT_KEYGEN_REQUEST_V1 0
  1676. //+-------------------------------------------------------------------------
  1677. // Certificate, CRL, Certificate Request or Keygen Request Signed Content
  1678. //
  1679. // The "to be signed" encoded content plus its signature. The ToBeSigned
  1680. // is the encoded CERT_INFO, CRL_INFO, CERT_REQUEST_INFO or
  1681. // CERT_KEYGEN_REQUEST_INFO.
  1682. //--------------------------------------------------------------------------
  1683. typedef struct _CERT_SIGNED_CONTENT_INFO {
  1684. CRYPT_DER_BLOB ToBeSigned;
  1685. CRYPT_ALGORITHM_IDENTIFIER SignatureAlgorithm;
  1686. CRYPT_BIT_BLOB Signature;
  1687. } CERT_SIGNED_CONTENT_INFO, *PCERT_SIGNED_CONTENT_INFO;
  1688. //+-------------------------------------------------------------------------
  1689. // Certificate Trust List (CTL)
  1690. //--------------------------------------------------------------------------
  1691. //+-------------------------------------------------------------------------
  1692. // CTL Usage. Also used for EnhancedKeyUsage extension.
  1693. //--------------------------------------------------------------------------
  1694. typedef struct _CTL_USAGE {
  1695. DWORD cUsageIdentifier;
  1696. LPSTR *rgpszUsageIdentifier; // array of pszObjId
  1697. } CTL_USAGE, *PCTL_USAGE,
  1698. CERT_ENHKEY_USAGE, *PCERT_ENHKEY_USAGE;
  1699. //+-------------------------------------------------------------------------
  1700. // An entry in a CTL
  1701. //--------------------------------------------------------------------------
  1702. typedef struct _CTL_ENTRY {
  1703. CRYPT_DATA_BLOB SubjectIdentifier; // For example, its hash
  1704. DWORD cAttribute;
  1705. PCRYPT_ATTRIBUTE rgAttribute; // OPTIONAL
  1706. } CTL_ENTRY, *PCTL_ENTRY;
  1707. //+-------------------------------------------------------------------------
  1708. // Information stored in a CTL
  1709. //--------------------------------------------------------------------------
  1710. typedef struct _CTL_INFO {
  1711. DWORD dwVersion;
  1712. CTL_USAGE SubjectUsage;
  1713. CRYPT_DATA_BLOB ListIdentifier; // OPTIONAL
  1714. CRYPT_INTEGER_BLOB SequenceNumber; // OPTIONAL
  1715. FILETIME ThisUpdate;
  1716. FILETIME NextUpdate; // OPTIONAL
  1717. CRYPT_ALGORITHM_IDENTIFIER SubjectAlgorithm;
  1718. DWORD cCTLEntry;
  1719. PCTL_ENTRY rgCTLEntry; // OPTIONAL
  1720. DWORD cExtension;
  1721. PCERT_EXTENSION rgExtension; // OPTIONAL
  1722. } CTL_INFO, *PCTL_INFO;
  1723. //+-------------------------------------------------------------------------
  1724. // CTL versions
  1725. //--------------------------------------------------------------------------
  1726. #define CTL_V1 0
  1727. //+-------------------------------------------------------------------------
  1728. // TimeStamp Request
  1729. //
  1730. // The pszTimeStamp is the OID for the Time type requested
  1731. // The pszContentType is the Content Type OID for the content, usually DATA
  1732. // The Content is a un-decoded blob
  1733. //--------------------------------------------------------------------------
  1734. typedef struct _CRYPT_TIME_STAMP_REQUEST_INFO {
  1735. LPSTR pszTimeStampAlgorithm; // pszObjId
  1736. LPSTR pszContentType; // pszObjId
  1737. CRYPT_OBJID_BLOB Content;
  1738. DWORD cAttribute;
  1739. PCRYPT_ATTRIBUTE rgAttribute;
  1740. } CRYPT_TIME_STAMP_REQUEST_INFO, *PCRYPT_TIME_STAMP_REQUEST_INFO;
  1741. //+-------------------------------------------------------------------------
  1742. // Name Value Attribute
  1743. //--------------------------------------------------------------------------
  1744. typedef struct _CRYPT_ENROLLMENT_NAME_VALUE_PAIR {
  1745. LPWSTR pwszName;
  1746. LPWSTR pwszValue;
  1747. } CRYPT_ENROLLMENT_NAME_VALUE_PAIR, * PCRYPT_ENROLLMENT_NAME_VALUE_PAIR;
  1748. //+-------------------------------------------------------------------------
  1749. // CSP Provider
  1750. //--------------------------------------------------------------------------
  1751. typedef struct _CRYPT_CSP_PROVIDER {
  1752. DWORD dwKeySpec;
  1753. LPWSTR pwszProviderName;
  1754. CRYPT_BIT_BLOB Signature;
  1755. } CRYPT_CSP_PROVIDER, * PCRYPT_CSP_PROVIDER;
  1756. //+-------------------------------------------------------------------------
  1757. // Certificate and Message encoding types
  1758. //
  1759. // The encoding type is a DWORD containing both the certificate and message
  1760. // encoding types. The certificate encoding type is stored in the LOWORD.
  1761. // The message encoding type is stored in the HIWORD. Some functions or
  1762. // structure fields require only one of the encoding types. The following
  1763. // naming convention is used to indicate which encoding type(s) are
  1764. // required:
  1765. // dwEncodingType (both encoding types are required)
  1766. // dwMsgAndCertEncodingType (both encoding types are required)
  1767. // dwMsgEncodingType (only msg encoding type is required)
  1768. // dwCertEncodingType (only cert encoding type is required)
  1769. //
  1770. // Its always acceptable to specify both.
  1771. //--------------------------------------------------------------------------
  1772. #define CERT_ENCODING_TYPE_MASK 0x0000FFFF
  1773. #define CMSG_ENCODING_TYPE_MASK 0xFFFF0000
  1774. #define GET_CERT_ENCODING_TYPE(X) (X & CERT_ENCODING_TYPE_MASK)
  1775. #define GET_CMSG_ENCODING_TYPE(X) (X & CMSG_ENCODING_TYPE_MASK)
  1776. #define CRYPT_ASN_ENCODING 0x00000001
  1777. #define CRYPT_NDR_ENCODING 0x00000002
  1778. #define X509_ASN_ENCODING 0x00000001
  1779. #define X509_NDR_ENCODING 0x00000002
  1780. #define PKCS_7_ASN_ENCODING 0x00010000
  1781. #define PKCS_7_NDR_ENCODING 0x00020000
  1782. //+-------------------------------------------------------------------------
  1783. // format the specified data structure according to the certificate
  1784. // encoding type.
  1785. //
  1786. // The default behavior of CryptFormatObject is to return single line
  1787. // display of the encoded data, that is, each subfield will be concatenated with
  1788. // a ", " on one line. If user prefers to display the data in multiple line,
  1789. // set the flag CRYPT_FORMAT_STR_MULTI_LINE, that is, each subfield will be displayed
  1790. // on a seperate line.
  1791. //
  1792. // If there is no formatting routine installed or registered
  1793. // for the lpszStructType, the hex dump of the encoded BLOB will be returned.
  1794. // User can set the flag CRYPT_FORMAT_STR_NO_HEX to disable the hex dump.
  1795. //--------------------------------------------------------------------------
  1796. WINCRYPT32API
  1797. BOOL
  1798. WINAPI
  1799. CryptFormatObject(
  1800. IN DWORD dwCertEncodingType,
  1801. IN DWORD dwFormatType,
  1802. IN DWORD dwFormatStrType,
  1803. IN void *pFormatStruct,
  1804. IN LPCSTR lpszStructType,
  1805. IN const BYTE *pbEncoded,
  1806. IN DWORD cbEncoded,
  1807. OUT void *pbFormat,
  1808. IN OUT DWORD *pcbFormat
  1809. );
  1810. //-------------------------------------------------------------------------
  1811. // constants for dwFormatStrType of function CryptFormatObject
  1812. //-------------------------------------------------------------------------
  1813. #define CRYPT_FORMAT_STR_MULTI_LINE 0x0001
  1814. #define CRYPT_FORMAT_STR_NO_HEX 0x0010
  1815. //-------------------------------------------------------------------------
  1816. // constants for dwFormatType of function CryptFormatObject
  1817. // when format X509_NAME or X509_UNICODE_NAME
  1818. //-------------------------------------------------------------------------
  1819. // Just get the simple string
  1820. #define CRYPT_FORMAT_SIMPLE 0x0001
  1821. //Put an attribute name infront of the attribute
  1822. //such as "O=Microsoft,DN=xiaohs"
  1823. #define CRYPT_FORMAT_X509 0x0002
  1824. //Put an OID infront of the simple string, such as
  1825. //"2.5.4.22=Microsoft,2.5.4.3=xiaohs"
  1826. #define CRYPT_FORMAT_OID 0x0004
  1827. //Put a ";" between each RDN. The default is ","
  1828. #define CRYPT_FORMAT_RDN_SEMICOLON 0x0100
  1829. //Put a "\n" between each RDN.
  1830. #define CRYPT_FORMAT_RDN_CRLF 0x0200
  1831. //Unquote the DN value, which is quoated by default va the following
  1832. //rules: if the DN contains leading or trailing
  1833. //white space or one of the following characters: ",", "+", "=",
  1834. //""", "\n", "<", ">", "#" or ";". The quoting character is ".
  1835. //If the DN Value contains a " it is double quoted ("").
  1836. #define CRYPT_FORMAT_RDN_UNQUOTE 0x0400
  1837. //reverse the order of the RDNs before converting to the string
  1838. #define CRYPT_FORMAT_RDN_REVERSE 0x0800
  1839. //-------------------------------------------------------------------------
  1840. // contants dwFormatType of function CryptFormatObject when format a DN.:
  1841. //
  1842. // The following three values are defined in the section above:
  1843. // CRYPT_FORMAT_SIMPLE: Just a simple string
  1844. // such as "Microsoft+xiaohs+NT"
  1845. // CRYPT_FORMAT_X509 Put an attribute name infront of the attribute
  1846. // such as "O=Microsoft+xiaohs+NT"
  1847. //
  1848. // CRYPT_FORMAT_OID Put an OID infront of the simple string,
  1849. // such as "2.5.4.22=Microsoft+xiaohs+NT"
  1850. //
  1851. // Additional values are defined as following:
  1852. //----------------------------------------------------------------------------
  1853. //Put a "," between each value. Default is "+"
  1854. #define CRYPT_FORMAT_COMMA 0x1000
  1855. //Put a ";" between each value
  1856. #define CRYPT_FORMAT_SEMICOLON CRYPT_FORMAT_RDN_SEMICOLON
  1857. //Put a "\n" between each value
  1858. #define CRYPT_FORMAT_CRLF CRYPT_FORMAT_RDN_CRLF
  1859. //+-------------------------------------------------------------------------
  1860. // Encode / decode the specified data structure according to the certificate
  1861. // encoding type.
  1862. //
  1863. // See below for a list of the predefined data structures.
  1864. //--------------------------------------------------------------------------
  1865. typedef LPVOID (WINAPI *PFN_CRYPT_ALLOC)(
  1866. IN size_t cbSize
  1867. );
  1868. typedef VOID (WINAPI *PFN_CRYPT_FREE)(
  1869. IN LPVOID pv
  1870. );
  1871. typedef struct _CRYPT_ENCODE_PARA {
  1872. DWORD cbSize;
  1873. PFN_CRYPT_ALLOC pfnAlloc; // OPTIONAL
  1874. PFN_CRYPT_FREE pfnFree; // OPTIONAL
  1875. } CRYPT_ENCODE_PARA, *PCRYPT_ENCODE_PARA;
  1876. WINCRYPT32API
  1877. BOOL
  1878. WINAPI
  1879. CryptEncodeObjectEx(
  1880. IN DWORD dwCertEncodingType,
  1881. IN LPCSTR lpszStructType,
  1882. IN const void *pvStructInfo,
  1883. IN DWORD dwFlags,
  1884. IN OPTIONAL PCRYPT_ENCODE_PARA pEncodePara,
  1885. OUT void *pvEncoded,
  1886. IN OUT DWORD *pcbEncoded
  1887. );
  1888. WINCRYPT32API
  1889. BOOL
  1890. WINAPI
  1891. CryptEncodeObject(
  1892. IN DWORD dwCertEncodingType,
  1893. IN LPCSTR lpszStructType,
  1894. IN const void *pvStructInfo,
  1895. OUT BYTE *pbEncoded,
  1896. IN OUT DWORD *pcbEncoded
  1897. );
  1898. // By default the signature bytes are reversed. The following flag can
  1899. // be set to inhibit the byte reversal.
  1900. //
  1901. // This flag is applicable to
  1902. // X509_CERT_TO_BE_SIGNED
  1903. #define CRYPT_ENCODE_NO_SIGNATURE_BYTE_REVERSAL_FLAG 0x8
  1904. // When the following flag is set the called encode function allocates
  1905. // memory for the encoded bytes. A pointer to the allocated bytes
  1906. // is returned in pvEncoded. If pEncodePara or pEncodePara->pfnAlloc is
  1907. // NULL, then, LocalAlloc is called for the allocation and LocalFree must
  1908. // be called to do the free. Otherwise, pEncodePara->pfnAlloc is called
  1909. // for the allocation.
  1910. //
  1911. // *pcbEncoded is ignored on input and updated with the length of the
  1912. // allocated, encoded bytes.
  1913. //
  1914. // If pfnAlloc is set, then, pfnFree should also be set.
  1915. #define CRYPT_ENCODE_ALLOC_FLAG 0x8000
  1916. // The following flag is applicable when encoding X509_UNICODE_NAME.
  1917. // When set, CERT_RDN_T61_STRING is selected instead of
  1918. // CERT_RDN_UNICODE_STRING if all the unicode characters are <= 0xFF
  1919. #define CRYPT_UNICODE_NAME_ENCODE_ENABLE_T61_UNICODE_FLAG \
  1920. CERT_RDN_ENABLE_T61_UNICODE_FLAG
  1921. // The following flag is applicable when encoding X509_UNICODE_NAME.
  1922. // When set, CERT_RDN_UTF8_STRING is selected instead of
  1923. // CERT_RDN_UNICODE_STRING.
  1924. #define CRYPT_UNICODE_NAME_ENCODE_ENABLE_UTF8_UNICODE_FLAG \
  1925. CERT_RDN_ENABLE_UTF8_UNICODE_FLAG
  1926. // The following flag is applicable when encoding X509_UNICODE_NAME,
  1927. // X509_UNICODE_NAME_VALUE or X509_UNICODE_ANY_STRING.
  1928. // When set, the characters aren't checked to see if they
  1929. // are valid for the specified Value Type.
  1930. #define CRYPT_UNICODE_NAME_ENCODE_DISABLE_CHECK_TYPE_FLAG \
  1931. CERT_RDN_DISABLE_CHECK_TYPE_FLAG
  1932. // The following flag is applicable when encoding the PKCS_SORTED_CTL. This
  1933. // flag should be set if the identifier for the TrustedSubjects is a hash,
  1934. // such as, MD5 or SHA1.
  1935. #define CRYPT_SORTED_CTL_ENCODE_HASHED_SUBJECT_IDENTIFIER_FLAG 0x10000
  1936. typedef struct _CRYPT_DECODE_PARA {
  1937. DWORD cbSize;
  1938. PFN_CRYPT_ALLOC pfnAlloc; // OPTIONAL
  1939. PFN_CRYPT_FREE pfnFree; // OPTIONAL
  1940. } CRYPT_DECODE_PARA, *PCRYPT_DECODE_PARA;
  1941. WINCRYPT32API
  1942. BOOL
  1943. WINAPI
  1944. CryptDecodeObjectEx(
  1945. IN DWORD dwCertEncodingType,
  1946. IN LPCSTR lpszStructType,
  1947. IN const BYTE *pbEncoded,
  1948. IN DWORD cbEncoded,
  1949. IN DWORD dwFlags,
  1950. IN OPTIONAL PCRYPT_DECODE_PARA pDecodePara,
  1951. OUT OPTIONAL void *pvStructInfo,
  1952. IN OUT DWORD *pcbStructInfo
  1953. );
  1954. WINCRYPT32API
  1955. BOOL
  1956. WINAPI
  1957. CryptDecodeObject(
  1958. IN DWORD dwCertEncodingType,
  1959. IN LPCSTR lpszStructType,
  1960. IN const BYTE *pbEncoded,
  1961. IN DWORD cbEncoded,
  1962. IN DWORD dwFlags,
  1963. OUT void *pvStructInfo,
  1964. IN OUT DWORD *pcbStructInfo
  1965. );
  1966. // When the following flag is set the nocopy optimization is enabled.
  1967. // This optimization where appropriate, updates the pvStructInfo fields
  1968. // to point to content residing within pbEncoded instead of making a copy
  1969. // of and appending to pvStructInfo.
  1970. //
  1971. // Note, when set, pbEncoded can't be freed until pvStructInfo is freed.
  1972. #define CRYPT_DECODE_NOCOPY_FLAG 0x1
  1973. // For CryptDecodeObject(), by default the pbEncoded is the "to be signed"
  1974. // plus its signature. Set the following flag, if pbEncoded points to only
  1975. // the "to be signed".
  1976. //
  1977. // This flag is applicable to
  1978. // X509_CERT_TO_BE_SIGNED
  1979. // X509_CERT_CRL_TO_BE_SIGNED
  1980. // X509_CERT_REQUEST_TO_BE_SIGNED
  1981. // X509_KEYGEN_REQUEST_TO_BE_SIGNED
  1982. #define CRYPT_DECODE_TO_BE_SIGNED_FLAG 0x2
  1983. // When the following flag is set, the OID strings are allocated in
  1984. // crypt32.dll and shared instead of being copied into the returned
  1985. // data structure. This flag may be set if crypt32.dll isn't unloaded
  1986. // before the caller is unloaded.
  1987. #define CRYPT_DECODE_SHARE_OID_STRING_FLAG 0x4
  1988. // By default the signature bytes are reversed. The following flag can
  1989. // be set to inhibit the byte reversal.
  1990. //
  1991. // This flag is applicable to
  1992. // X509_CERT_TO_BE_SIGNED
  1993. #define CRYPT_DECODE_NO_SIGNATURE_BYTE_REVERSAL_FLAG 0x8
  1994. // When the following flag is set the called decode function allocates
  1995. // memory for the decoded structure. A pointer to the allocated structure
  1996. // is returned in pvStructInfo. If pDecodePara or pDecodePara->pfnAlloc is
  1997. // NULL, then, LocalAlloc is called for the allocation and LocalFree must
  1998. // be called to do the free. Otherwise, pDecodePara->pfnAlloc is called
  1999. // for the allocation.
  2000. //
  2001. // *pcbStructInfo is ignored on input and updated with the length of the
  2002. // allocated, decoded structure.
  2003. //
  2004. // This flag may also be set in the CryptDecodeObject API. Since
  2005. // CryptDecodeObject doesn't take a pDecodePara, LocalAlloc is always
  2006. // called for the allocation which must be freed by calling LocalFree.
  2007. #define CRYPT_DECODE_ALLOC_FLAG 0x8000
  2008. // The following flag is applicable when decoding X509_UNICODE_NAME,
  2009. // X509_UNICODE_NAME_VALUE or X509_UNICODE_ANY_STRING.
  2010. // By default, CERT_RDN_T61_STRING values are initially decoded
  2011. // as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  2012. // Setting this flag skips the initial attempt to decode as UTF8.
  2013. #define CRYPT_UNICODE_NAME_DECODE_DISABLE_IE4_UTF8_FLAG \
  2014. CERT_RDN_DISABLE_IE4_UTF8_FLAG
  2015. //+-------------------------------------------------------------------------
  2016. // Predefined X509 certificate data structures that can be encoded / decoded.
  2017. //--------------------------------------------------------------------------
  2018. #define CRYPT_ENCODE_DECODE_NONE 0
  2019. #define X509_CERT ((LPCSTR) 1)
  2020. #define X509_CERT_TO_BE_SIGNED ((LPCSTR) 2)
  2021. #define X509_CERT_CRL_TO_BE_SIGNED ((LPCSTR) 3)
  2022. #define X509_CERT_REQUEST_TO_BE_SIGNED ((LPCSTR) 4)
  2023. #define X509_EXTENSIONS ((LPCSTR) 5)
  2024. #define X509_NAME_VALUE ((LPCSTR) 6)
  2025. #define X509_NAME ((LPCSTR) 7)
  2026. #define X509_PUBLIC_KEY_INFO ((LPCSTR) 8)
  2027. //+-------------------------------------------------------------------------
  2028. // Predefined X509 certificate extension data structures that can be
  2029. // encoded / decoded.
  2030. //--------------------------------------------------------------------------
  2031. #define X509_AUTHORITY_KEY_ID ((LPCSTR) 9)
  2032. #define X509_KEY_ATTRIBUTES ((LPCSTR) 10)
  2033. #define X509_KEY_USAGE_RESTRICTION ((LPCSTR) 11)
  2034. #define X509_ALTERNATE_NAME ((LPCSTR) 12)
  2035. #define X509_BASIC_CONSTRAINTS ((LPCSTR) 13)
  2036. #define X509_KEY_USAGE ((LPCSTR) 14)
  2037. #define X509_BASIC_CONSTRAINTS2 ((LPCSTR) 15)
  2038. #define X509_CERT_POLICIES ((LPCSTR) 16)
  2039. //+-------------------------------------------------------------------------
  2040. // Additional predefined data structures that can be encoded / decoded.
  2041. //--------------------------------------------------------------------------
  2042. #define PKCS_UTC_TIME ((LPCSTR) 17)
  2043. #define PKCS_TIME_REQUEST ((LPCSTR) 18)
  2044. #define RSA_CSP_PUBLICKEYBLOB ((LPCSTR) 19)
  2045. #define X509_UNICODE_NAME ((LPCSTR) 20)
  2046. #define X509_KEYGEN_REQUEST_TO_BE_SIGNED ((LPCSTR) 21)
  2047. #define PKCS_ATTRIBUTE ((LPCSTR) 22)
  2048. #define PKCS_CONTENT_INFO_SEQUENCE_OF_ANY ((LPCSTR) 23)
  2049. //+-------------------------------------------------------------------------
  2050. // Predefined primitive data structures that can be encoded / decoded.
  2051. //--------------------------------------------------------------------------
  2052. #define X509_UNICODE_NAME_VALUE ((LPCSTR) 24)
  2053. #define X509_ANY_STRING X509_NAME_VALUE
  2054. #define X509_UNICODE_ANY_STRING X509_UNICODE_NAME_VALUE
  2055. #define X509_OCTET_STRING ((LPCSTR) 25)
  2056. #define X509_BITS ((LPCSTR) 26)
  2057. #define X509_INTEGER ((LPCSTR) 27)
  2058. #define X509_MULTI_BYTE_INTEGER ((LPCSTR) 28)
  2059. #define X509_ENUMERATED ((LPCSTR) 29)
  2060. #define X509_CHOICE_OF_TIME ((LPCSTR) 30)
  2061. //+-------------------------------------------------------------------------
  2062. // More predefined X509 certificate extension data structures that can be
  2063. // encoded / decoded.
  2064. //--------------------------------------------------------------------------
  2065. #define X509_AUTHORITY_KEY_ID2 ((LPCSTR) 31)
  2066. #define X509_AUTHORITY_INFO_ACCESS ((LPCSTR) 32)
  2067. #define X509_CRL_REASON_CODE X509_ENUMERATED
  2068. #define PKCS_CONTENT_INFO ((LPCSTR) 33)
  2069. #define X509_SEQUENCE_OF_ANY ((LPCSTR) 34)
  2070. #define X509_CRL_DIST_POINTS ((LPCSTR) 35)
  2071. #define X509_ENHANCED_KEY_USAGE ((LPCSTR) 36)
  2072. #define PKCS_CTL ((LPCSTR) 37)
  2073. #define X509_MULTI_BYTE_UINT ((LPCSTR) 38)
  2074. #define X509_DSS_PUBLICKEY X509_MULTI_BYTE_UINT
  2075. #define X509_DSS_PARAMETERS ((LPCSTR) 39)
  2076. #define X509_DSS_SIGNATURE ((LPCSTR) 40)
  2077. #define PKCS_RC2_CBC_PARAMETERS ((LPCSTR) 41)
  2078. #define PKCS_SMIME_CAPABILITIES ((LPCSTR) 42)
  2079. //+-------------------------------------------------------------------------
  2080. // data structures for private keys
  2081. //--------------------------------------------------------------------------
  2082. #define PKCS_RSA_PRIVATE_KEY ((LPCSTR) 43)
  2083. #define PKCS_PRIVATE_KEY_INFO ((LPCSTR) 44)
  2084. #define PKCS_ENCRYPTED_PRIVATE_KEY_INFO ((LPCSTR) 45)
  2085. //+-------------------------------------------------------------------------
  2086. // certificate policy qualifier
  2087. //--------------------------------------------------------------------------
  2088. #define X509_PKIX_POLICY_QUALIFIER_USERNOTICE ((LPCSTR) 46)
  2089. //+-------------------------------------------------------------------------
  2090. // Diffie-Hellman Key Exchange
  2091. //--------------------------------------------------------------------------
  2092. #define X509_DH_PUBLICKEY X509_MULTI_BYTE_UINT
  2093. #define X509_DH_PARAMETERS ((LPCSTR) 47)
  2094. #define PKCS_ATTRIBUTES ((LPCSTR) 48)
  2095. #define PKCS_SORTED_CTL ((LPCSTR) 49)
  2096. //+-------------------------------------------------------------------------
  2097. // X942 Diffie-Hellman
  2098. //--------------------------------------------------------------------------
  2099. #define X942_DH_PARAMETERS ((LPCSTR) 50)
  2100. //+-------------------------------------------------------------------------
  2101. // The following is the same as X509_BITS, except before encoding,
  2102. // the bit length is decremented to exclude trailing zero bits.
  2103. //--------------------------------------------------------------------------
  2104. #define X509_BITS_WITHOUT_TRAILING_ZEROES ((LPCSTR) 51)
  2105. //+-------------------------------------------------------------------------
  2106. // X942 Diffie-Hellman Other Info
  2107. //--------------------------------------------------------------------------
  2108. #define X942_OTHER_INFO ((LPCSTR) 52)
  2109. #define X509_CERT_PAIR ((LPCSTR) 53)
  2110. #define X509_ISSUING_DIST_POINT ((LPCSTR) 54)
  2111. #define X509_NAME_CONSTRAINTS ((LPCSTR) 55)
  2112. #define X509_POLICY_MAPPINGS ((LPCSTR) 56)
  2113. #define X509_POLICY_CONSTRAINTS ((LPCSTR) 57)
  2114. #define X509_CROSS_CERT_DIST_POINTS ((LPCSTR) 58)
  2115. //+-------------------------------------------------------------------------
  2116. // Certificate Management Messages over CMS (CMC) Data Structures
  2117. //--------------------------------------------------------------------------
  2118. #define CMC_DATA ((LPCSTR) 59)
  2119. #define CMC_RESPONSE ((LPCSTR) 60)
  2120. #define CMC_STATUS ((LPCSTR) 61)
  2121. #define CMC_ADD_EXTENSIONS ((LPCSTR) 62)
  2122. #define CMC_ADD_ATTRIBUTES ((LPCSTR) 63)
  2123. //+-------------------------------------------------------------------------
  2124. // Certificate Template
  2125. //--------------------------------------------------------------------------
  2126. #define X509_CERTIFICATE_TEMPLATE ((LPCSTR) 64)
  2127. //+-------------------------------------------------------------------------
  2128. // Predefined PKCS #7 data structures that can be encoded / decoded.
  2129. //--------------------------------------------------------------------------
  2130. #define PKCS7_SIGNER_INFO ((LPCSTR) 500)
  2131. //+-------------------------------------------------------------------------
  2132. // Predefined PKCS #7 data structures that can be encoded / decoded.
  2133. //--------------------------------------------------------------------------
  2134. #define CMS_SIGNER_INFO ((LPCSTR) 501)
  2135. //+-------------------------------------------------------------------------
  2136. // Predefined Software Publishing Credential (SPC) data structures that
  2137. // can be encoded / decoded.
  2138. //
  2139. // Predefined values: 2000 .. 2999
  2140. //
  2141. // See spc.h for value and data structure definitions.
  2142. //--------------------------------------------------------------------------
  2143. //+-------------------------------------------------------------------------
  2144. // Extension Object Identifiers
  2145. //--------------------------------------------------------------------------
  2146. #define szOID_AUTHORITY_KEY_IDENTIFIER "2.5.29.1"
  2147. #define szOID_KEY_ATTRIBUTES "2.5.29.2"
  2148. #define szOID_CERT_POLICIES_95 "2.5.29.3"
  2149. #define szOID_KEY_USAGE_RESTRICTION "2.5.29.4"
  2150. #define szOID_SUBJECT_ALT_NAME "2.5.29.7"
  2151. #define szOID_ISSUER_ALT_NAME "2.5.29.8"
  2152. #define szOID_BASIC_CONSTRAINTS "2.5.29.10"
  2153. #define szOID_KEY_USAGE "2.5.29.15"
  2154. #define szOID_PRIVATEKEY_USAGE_PERIOD "2.5.29.16"
  2155. #define szOID_BASIC_CONSTRAINTS2 "2.5.29.19"
  2156. #define szOID_CERT_POLICIES "2.5.29.32"
  2157. #define szOID_ANY_CERT_POLICY "2.5.29.32.0"
  2158. #define szOID_AUTHORITY_KEY_IDENTIFIER2 "2.5.29.35"
  2159. #define szOID_SUBJECT_KEY_IDENTIFIER "2.5.29.14"
  2160. #define szOID_SUBJECT_ALT_NAME2 "2.5.29.17"
  2161. #define szOID_ISSUER_ALT_NAME2 "2.5.29.18"
  2162. #define szOID_CRL_REASON_CODE "2.5.29.21"
  2163. #define szOID_REASON_CODE_HOLD "2.5.29.23"
  2164. #define szOID_CRL_DIST_POINTS "2.5.29.31"
  2165. #define szOID_ENHANCED_KEY_USAGE "2.5.29.37"
  2166. // szOID_CRL_NUMBER -- Base CRLs only. Monotonically increasing sequence
  2167. // number for each CRL issued by a CA.
  2168. #define szOID_CRL_NUMBER "2.5.29.20"
  2169. // szOID_DELTA_CRL_INDICATOR -- Delta CRLs only. Marked critical.
  2170. // Contains the minimum base CRL Number that can be used with a delta CRL.
  2171. #define szOID_DELTA_CRL_INDICATOR "2.5.29.27"
  2172. #define szOID_ISSUING_DIST_POINT "2.5.29.28"
  2173. // szOID_FRESHEST_CRL -- Base CRLs only. Formatted identically to a CDP
  2174. // extension that holds URLs to fetch the delta CRL.
  2175. #define szOID_FRESHEST_CRL "2.5.29.46"
  2176. #define szOID_NAME_CONSTRAINTS "2.5.29.30"
  2177. // Note on 1/1/2000 szOID_POLICY_MAPPINGS was changed from "2.5.29.5"
  2178. #define szOID_POLICY_MAPPINGS "2.5.29.33"
  2179. #define szOID_LEGACY_POLICY_MAPPINGS "2.5.29.5"
  2180. #define szOID_POLICY_CONSTRAINTS "2.5.29.36"
  2181. // Microsoft PKCS10 Attributes
  2182. #define szOID_RENEWAL_CERTIFICATE "1.3.6.1.4.1.311.13.1"
  2183. #define szOID_ENROLLMENT_NAME_VALUE_PAIR "1.3.6.1.4.1.311.13.2.1"
  2184. #define szOID_ENROLLMENT_CSP_PROVIDER "1.3.6.1.4.1.311.13.2.2"
  2185. #define szOID_OS_VERSION "1.3.6.1.4.1.311.13.2.3"
  2186. //
  2187. // Extension contain certificate type
  2188. #define szOID_ENROLLMENT_AGENT "1.3.6.1.4.1.311.20.2.1"
  2189. // Internet Public Key Infrastructure (PKIX)
  2190. #define szOID_PKIX "1.3.6.1.5.5.7"
  2191. #define szOID_PKIX_PE "1.3.6.1.5.5.7.1"
  2192. #define szOID_AUTHORITY_INFO_ACCESS "1.3.6.1.5.5.7.1.1"
  2193. // Microsoft extensions or attributes
  2194. #define szOID_CERT_EXTENSIONS "1.3.6.1.4.1.311.2.1.14"
  2195. #define szOID_NEXT_UPDATE_LOCATION "1.3.6.1.4.1.311.10.2"
  2196. #define szOID_REMOVE_CERTIFICATE "1.3.6.1.4.1.311.10.8.1"
  2197. #define szOID_CROSS_CERT_DIST_POINTS "1.3.6.1.4.1.311.10.9.1"
  2198. // Microsoft PKCS #7 ContentType Object Identifiers
  2199. #define szOID_CTL "1.3.6.1.4.1.311.10.1"
  2200. // Microsoft Sorted CTL Extension Object Identifier
  2201. #define szOID_SORTED_CTL "1.3.6.1.4.1.311.10.1.1"
  2202. // serialized serial numbers for PRS
  2203. #ifndef szOID_SERIALIZED
  2204. #define szOID_SERIALIZED "1.3.6.1.4.1.311.10.3.3.1"
  2205. #endif
  2206. // UPN principal name in SubjectAltName
  2207. #ifndef szOID_NT_PRINCIPAL_NAME
  2208. #define szOID_NT_PRINCIPAL_NAME "1.3.6.1.4.1.311.20.2.3"
  2209. #endif
  2210. // Windows product update unauthenticated attribute
  2211. #ifndef szOID_PRODUCT_UPDATE
  2212. #define szOID_PRODUCT_UPDATE "1.3.6.1.4.1.311.31.1"
  2213. #endif
  2214. // CryptUI
  2215. #define szOID_ANY_APPLICATION_POLICY "1.3.6.1.4.1.311.10.12.1"
  2216. //+-------------------------------------------------------------------------
  2217. // Object Identifiers for use with Auto Enrollment
  2218. //--------------------------------------------------------------------------
  2219. #define szOID_AUTO_ENROLL_CTL_USAGE "1.3.6.1.4.1.311.20.1"
  2220. // Extension contain certificate type
  2221. #define szOID_ENROLL_CERTTYPE_EXTENSION "1.3.6.1.4.1.311.20.2"
  2222. #define szOID_CERT_MANIFOLD "1.3.6.1.4.1.311.20.3"
  2223. //+-------------------------------------------------------------------------
  2224. // Object Identifiers for use with the MS Certificate Server
  2225. //--------------------------------------------------------------------------
  2226. #ifndef szOID_CERTSRV_CA_VERSION
  2227. #define szOID_CERTSRV_CA_VERSION "1.3.6.1.4.1.311.21.1"
  2228. #endif
  2229. // szOID_CERTSRV_PREVIOUS_CERT_HASH -- Contains the sha1 hash of the previous
  2230. // version of the CA certificate.
  2231. #define szOID_CERTSRV_PREVIOUS_CERT_HASH "1.3.6.1.4.1.311.21.2"
  2232. // szOID_CRL_VIRTUAL_BASE -- Delta CRLs only. Contains the base CRL Number
  2233. // of the corresponding base CRL.
  2234. #define szOID_CRL_VIRTUAL_BASE "1.3.6.1.4.1.311.21.3"
  2235. // szOID_CRL_NEXT_PUBLISH -- Contains the time when the next CRL is expected
  2236. // to be published. This may be sooner than the CRL's NextUpdate field.
  2237. #define szOID_CRL_NEXT_PUBLISH "1.3.6.1.4.1.311.21.4"
  2238. // Enhanced Key Usage for CA encryption certificate
  2239. #define szOID_KP_CA_EXCHANGE "1.3.6.1.4.1.311.21.5"
  2240. // Enhanced Key Usage for key recovery agent certificate
  2241. #define szOID_KP_KEY_RECOVERY_AGENT "1.3.6.1.4.1.311.21.6"
  2242. // Certificate template extension (v2)
  2243. #define szOID_CERTIFICATE_TEMPLATE "1.3.6.1.4.1.311.21.7"
  2244. // The root oid for all enterprise specific oids
  2245. #define szOID_ENTERPRISE_OID_ROOT "1.3.6.1.4.1.311.21.8"
  2246. // Dummy signing Subject RDN
  2247. #define szOID_RDN_DUMMY_SIGNER "1.3.6.1.4.1.311.21.9"
  2248. // Application Policies extension -- same encoding as szOID_CERT_POLICIES
  2249. #define szOID_APPLICATION_CERT_POLICIES "1.3.6.1.4.1.311.21.10"
  2250. // Application Policy Mappings -- same encoding as szOID_POLICY_MAPPINGS
  2251. #define szOID_APPLICATION_POLICY_MAPPINGS "1.3.6.1.4.1.311.21.11"
  2252. // Application Policy Constraints -- same encoding as szOID_POLICY_CONSTRAINTS
  2253. #define szOID_APPLICATION_POLICY_CONSTRAINTS "1.3.6.1.4.1.311.21.12"
  2254. #define szOID_ARCHIVED_KEY_ATTR "1.3.6.1.4.1.311.21.13"
  2255. #define szOID_CRL_SELF_CDP "1.3.6.1.4.1.311.21.14"
  2256. // Requires all certificates below the root to have a non-empty intersecting
  2257. // issuance certificate policy usage.
  2258. #define szOID_REQUIRE_CERT_CHAIN_POLICY "1.3.6.1.4.1.311.21.15"
  2259. #define szOID_ARCHIVED_KEY_CERT_HASH "1.3.6.1.4.1.311.21.16"
  2260. #define szOID_ISSUED_CERT_HASH "1.3.6.1.4.1.311.21.17"
  2261. // Enhanced key usage for DS email replication
  2262. #define szOID_DS_EMAIL_REPLICATION "1.3.6.1.4.1.311.21.19"
  2263. #define szOID_REQUEST_CLIENT_INFO "1.3.6.1.4.1.311.21.20"
  2264. #define szOID_ENCRYPTED_KEY_HASH "1.3.6.1.4.1.311.21.21"
  2265. //+-------------------------------------------------------------------------
  2266. // Object Identifiers for use with the MS Directory Service
  2267. //--------------------------------------------------------------------------
  2268. #define szOID_NTDS_REPLICATION "1.3.6.1.4.1.311.25.1"
  2269. //+-------------------------------------------------------------------------
  2270. // Extension Object Identifiers (currently not implemented)
  2271. //--------------------------------------------------------------------------
  2272. #define szOID_SUBJECT_DIR_ATTRS "2.5.29.9"
  2273. //+-------------------------------------------------------------------------
  2274. // Enhanced Key Usage (Purpose) Object Identifiers
  2275. //--------------------------------------------------------------------------
  2276. #define szOID_PKIX_KP "1.3.6.1.5.5.7.3"
  2277. // Consistent key usage bits: DIGITAL_SIGNATURE, KEY_ENCIPHERMENT
  2278. // or KEY_AGREEMENT
  2279. #define szOID_PKIX_KP_SERVER_AUTH "1.3.6.1.5.5.7.3.1"
  2280. // Consistent key usage bits: DIGITAL_SIGNATURE
  2281. #define szOID_PKIX_KP_CLIENT_AUTH "1.3.6.1.5.5.7.3.2"
  2282. // Consistent key usage bits: DIGITAL_SIGNATURE
  2283. #define szOID_PKIX_KP_CODE_SIGNING "1.3.6.1.5.5.7.3.3"
  2284. // Consistent key usage bits: DIGITAL_SIGNATURE, NON_REPUDIATION and/or
  2285. // (KEY_ENCIPHERMENT or KEY_AGREEMENT)
  2286. #define szOID_PKIX_KP_EMAIL_PROTECTION "1.3.6.1.5.5.7.3.4"
  2287. // Consistent key usage bits: DIGITAL_SIGNATURE and/or
  2288. // (KEY_ENCIPHERMENT or KEY_AGREEMENT)
  2289. #define szOID_PKIX_KP_IPSEC_END_SYSTEM "1.3.6.1.5.5.7.3.5"
  2290. // Consistent key usage bits: DIGITAL_SIGNATURE and/or
  2291. // (KEY_ENCIPHERMENT or KEY_AGREEMENT)
  2292. #define szOID_PKIX_KP_IPSEC_TUNNEL "1.3.6.1.5.5.7.3.6"
  2293. // Consistent key usage bits: DIGITAL_SIGNATURE and/or
  2294. // (KEY_ENCIPHERMENT or KEY_AGREEMENT)
  2295. #define szOID_PKIX_KP_IPSEC_USER "1.3.6.1.5.5.7.3.7"
  2296. // Consistent key usage bits: DIGITAL_SIGNATURE or NON_REPUDIATION
  2297. #define szOID_PKIX_KP_TIMESTAMP_SIGNING "1.3.6.1.5.5.7.3.8"
  2298. // IKE (Internet Key Exchange) Intermediate KP for an IPsec end entity.
  2299. // Defined in draft-ietf-ipsec-pki-req-04.txt, December 14, 1999.
  2300. #define szOID_IPSEC_KP_IKE_INTERMEDIATE "1.3.6.1.5.5.8.2.2"
  2301. //+-------------------------------------------------------------------------
  2302. // Microsoft Enhanced Key Usage (Purpose) Object Identifiers
  2303. //+-------------------------------------------------------------------------
  2304. // Signer of CTLs
  2305. #define szOID_KP_CTL_USAGE_SIGNING "1.3.6.1.4.1.311.10.3.1"
  2306. // Signer of TimeStamps
  2307. #define szOID_KP_TIME_STAMP_SIGNING "1.3.6.1.4.1.311.10.3.2"
  2308. #ifndef szOID_SERVER_GATED_CRYPTO
  2309. #define szOID_SERVER_GATED_CRYPTO "1.3.6.1.4.1.311.10.3.3"
  2310. #endif
  2311. #ifndef szOID_SGC_NETSCAPE
  2312. #define szOID_SGC_NETSCAPE "2.16.840.1.113730.4.1"
  2313. #endif
  2314. #define szOID_KP_EFS "1.3.6.1.4.1.311.10.3.4"
  2315. #define szOID_EFS_RECOVERY "1.3.6.1.4.1.311.10.3.4.1"
  2316. // Can use Windows Hardware Compatible (WHQL)
  2317. #define szOID_WHQL_CRYPTO "1.3.6.1.4.1.311.10.3.5"
  2318. // Signed by the NT5 build lab
  2319. #define szOID_NT5_CRYPTO "1.3.6.1.4.1.311.10.3.6"
  2320. // Signed by and OEM of WHQL
  2321. #define szOID_OEM_WHQL_CRYPTO "1.3.6.1.4.1.311.10.3.7"
  2322. // Signed by the Embedded NT
  2323. #define szOID_EMBEDDED_NT_CRYPTO "1.3.6.1.4.1.311.10.3.8"
  2324. // Signer of a CTL containing trusted roots
  2325. #define szOID_ROOT_LIST_SIGNER "1.3.6.1.4.1.311.10.3.9"
  2326. // Can sign cross-cert and subordinate CA requests with qualified
  2327. // subordination (name constraints, policy mapping, etc.)
  2328. #define szOID_KP_QUALIFIED_SUBORDINATION "1.3.6.1.4.1.311.10.3.10"
  2329. // Can be used to encrypt/recover escrowed keys
  2330. #define szOID_KP_KEY_RECOVERY "1.3.6.1.4.1.311.10.3.11"
  2331. // Signer of documents
  2332. #define szOID_KP_DOCUMENT_SIGNING "1.3.6.1.4.1.311.10.3.12"
  2333. // The default WinVerifyTrust Authenticode policy is to treat all time stamped
  2334. // signatures as being valid forever. This OID limits the valid lifetime of the
  2335. // signature to the lifetime of the certificate. This allows timestamped
  2336. // signatures to expire. Normally this OID will be used in conjunction with
  2337. // szOID_PKIX_KP_CODE_SIGNING to indicate new time stamp semantics should be
  2338. // used. Support for this OID was added in WXP.
  2339. #define szOID_KP_LIFETIME_SIGNING "1.3.6.1.4.1.311.10.3.13"
  2340. #ifndef szOID_DRM
  2341. #define szOID_DRM "1.3.6.1.4.1.311.10.5.1"
  2342. #endif
  2343. // Microsoft DRM EKU
  2344. #ifndef szOID_DRM_INDIVIDUALIZATION
  2345. #define szOID_DRM_INDIVIDUALIZATION "1.3.6.1.4.1.311.10.5.2"
  2346. #endif
  2347. #ifndef szOID_LICENSES
  2348. #define szOID_LICENSES "1.3.6.1.4.1.311.10.6.1"
  2349. #endif
  2350. #ifndef szOID_LICENSE_SERVER
  2351. #define szOID_LICENSE_SERVER "1.3.6.1.4.1.311.10.6.2"
  2352. #endif
  2353. #ifndef szOID_KP_SMARTCARD_LOGON
  2354. #define szOID_KP_SMARTCARD_LOGON "1.3.6.1.4.1.311.20.2.2"
  2355. #endif
  2356. //+-------------------------------------------------------------------------
  2357. // Microsoft Attribute Object Identifiers
  2358. //+-------------------------------------------------------------------------
  2359. #define szOID_YESNO_TRUST_ATTR "1.3.6.1.4.1.311.10.4.1"
  2360. //+-------------------------------------------------------------------------
  2361. // Qualifiers that may be part of the szOID_CERT_POLICIES and
  2362. // szOID_CERT_POLICIES95 extensions
  2363. //+-------------------------------------------------------------------------
  2364. #define szOID_PKIX_POLICY_QUALIFIER_CPS "1.3.6.1.5.5.7.2.1"
  2365. #define szOID_PKIX_POLICY_QUALIFIER_USERNOTICE "1.3.6.1.5.5.7.2.2"
  2366. // OID for old qualifer
  2367. #define szOID_CERT_POLICIES_95_QUALIFIER1 "2.16.840.1.113733.1.7.1.1"
  2368. //+-------------------------------------------------------------------------
  2369. // X509_CERT
  2370. //
  2371. // The "to be signed" encoded content plus its signature. The ToBeSigned
  2372. // content is the CryptEncodeObject() output for one of the following:
  2373. // X509_CERT_TO_BE_SIGNED, X509_CERT_CRL_TO_BE_SIGNED or
  2374. // X509_CERT_REQUEST_TO_BE_SIGNED.
  2375. //
  2376. // pvStructInfo points to CERT_SIGNED_CONTENT_INFO.
  2377. //--------------------------------------------------------------------------
  2378. //+-------------------------------------------------------------------------
  2379. // X509_CERT_TO_BE_SIGNED
  2380. //
  2381. // pvStructInfo points to CERT_INFO.
  2382. //
  2383. // For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  2384. // signature (output of a X509_CERT CryptEncodeObject()).
  2385. //
  2386. // For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  2387. //--------------------------------------------------------------------------
  2388. //+-------------------------------------------------------------------------
  2389. // X509_CERT_CRL_TO_BE_SIGNED
  2390. //
  2391. // pvStructInfo points to CRL_INFO.
  2392. //
  2393. // For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  2394. // signature (output of a X509_CERT CryptEncodeObject()).
  2395. //
  2396. // For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  2397. //--------------------------------------------------------------------------
  2398. //+-------------------------------------------------------------------------
  2399. // X509_CERT_REQUEST_TO_BE_SIGNED
  2400. //
  2401. // pvStructInfo points to CERT_REQUEST_INFO.
  2402. //
  2403. // For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  2404. // signature (output of a X509_CERT CryptEncodeObject()).
  2405. //
  2406. // For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  2407. //--------------------------------------------------------------------------
  2408. //+-------------------------------------------------------------------------
  2409. // X509_EXTENSIONS
  2410. // szOID_CERT_EXTENSIONS
  2411. //
  2412. // pvStructInfo points to following CERT_EXTENSIONS.
  2413. //--------------------------------------------------------------------------
  2414. typedef struct _CERT_EXTENSIONS {
  2415. DWORD cExtension;
  2416. PCERT_EXTENSION rgExtension;
  2417. } CERT_EXTENSIONS, *PCERT_EXTENSIONS;
  2418. //+-------------------------------------------------------------------------
  2419. // X509_NAME_VALUE
  2420. // X509_ANY_STRING
  2421. //
  2422. // pvStructInfo points to CERT_NAME_VALUE.
  2423. //--------------------------------------------------------------------------
  2424. //+-------------------------------------------------------------------------
  2425. // X509_UNICODE_NAME_VALUE
  2426. // X509_UNICODE_ANY_STRING
  2427. //
  2428. // pvStructInfo points to CERT_NAME_VALUE.
  2429. //
  2430. // The name values are unicode strings.
  2431. //
  2432. // For CryptEncodeObject:
  2433. // Value.pbData points to the unicode string.
  2434. // If Value.cbData = 0, then, the unicode string is NULL terminated.
  2435. // Otherwise, Value.cbData is the unicode string byte count. The byte count
  2436. // is twice the character count.
  2437. //
  2438. // If the unicode string contains an invalid character for the specified
  2439. // dwValueType, then, *pcbEncoded is updated with the unicode character
  2440. // index of the first invalid character. LastError is set to:
  2441. // CRYPT_E_INVALID_NUMERIC_STRING, CRYPT_E_INVALID_PRINTABLE_STRING or
  2442. // CRYPT_E_INVALID_IA5_STRING.
  2443. //
  2444. // To disable the above check, either set CERT_RDN_DISABLE_CHECK_TYPE_FLAG
  2445. // in dwValueType or set CRYPT_UNICODE_NAME_ENCODE_DISABLE_CHECK_TYPE_FLAG
  2446. // in dwFlags passed to CryptEncodeObjectEx.
  2447. //
  2448. // The unicode string is converted before being encoded according to
  2449. // the specified dwValueType. If dwValueType is set to 0, LastError
  2450. // is set to E_INVALIDARG.
  2451. //
  2452. // If the dwValueType isn't one of the character strings (its a
  2453. // CERT_RDN_ENCODED_BLOB or CERT_RDN_OCTET_STRING), then, CryptEncodeObject
  2454. // will return FALSE with LastError set to CRYPT_E_NOT_CHAR_STRING.
  2455. //
  2456. // For CryptDecodeObject:
  2457. // Value.pbData points to a NULL terminated unicode string. Value.cbData
  2458. // contains the byte count of the unicode string excluding the NULL
  2459. // terminator. dwValueType contains the type used in the encoded object.
  2460. // Its not forced to CERT_RDN_UNICODE_STRING. The encoded value is
  2461. // converted to the unicode string according to the dwValueType.
  2462. //
  2463. // If the encoded object isn't one of the character string types, then,
  2464. // CryptDecodeObject will return FALSE with LastError set to
  2465. // CRYPT_E_NOT_CHAR_STRING. For a non character string, decode using
  2466. // X509_NAME_VALUE or X509_ANY_STRING.
  2467. //
  2468. // By default, CERT_RDN_T61_STRING values are initially decoded
  2469. // as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  2470. // Set CRYPT_UNICODE_NAME_DECODE_DISABLE_IE4_UTF8_FLAG in dwFlags
  2471. // passed to either CryptDecodeObject or CryptDecodeObjectEx to
  2472. // skip the initial attempt to decode as UTF8.
  2473. //--------------------------------------------------------------------------
  2474. //+-------------------------------------------------------------------------
  2475. // X509_NAME
  2476. //
  2477. // pvStructInfo points to CERT_NAME_INFO.
  2478. //--------------------------------------------------------------------------
  2479. //+-------------------------------------------------------------------------
  2480. // X509_UNICODE_NAME
  2481. //
  2482. // pvStructInfo points to CERT_NAME_INFO.
  2483. //
  2484. // The RDN attribute values are unicode strings except for the dwValueTypes of
  2485. // CERT_RDN_ENCODED_BLOB or CERT_RDN_OCTET_STRING. These dwValueTypes are
  2486. // the same as for a X509_NAME. Their values aren't converted to/from unicode.
  2487. //
  2488. // For CryptEncodeObject:
  2489. // Value.pbData points to the unicode string.
  2490. // If Value.cbData = 0, then, the unicode string is NULL terminated.
  2491. // Otherwise, Value.cbData is the unicode string byte count. The byte count
  2492. // is twice the character count.
  2493. //
  2494. // If dwValueType = 0 (CERT_RDN_ANY_TYPE), the pszObjId is used to find
  2495. // an acceptable dwValueType. If the unicode string contains an
  2496. // invalid character for the found or specified dwValueType, then,
  2497. // *pcbEncoded is updated with the error location of the invalid character.
  2498. // See below for details. LastError is set to:
  2499. // CRYPT_E_INVALID_NUMERIC_STRING, CRYPT_E_INVALID_PRINTABLE_STRING or
  2500. // CRYPT_E_INVALID_IA5_STRING.
  2501. //
  2502. // To disable the above check, either set CERT_RDN_DISABLE_CHECK_TYPE_FLAG
  2503. // in dwValueType or set CRYPT_UNICODE_NAME_ENCODE_DISABLE_CHECK_TYPE_FLAG
  2504. // in dwFlags passed to CryptEncodeObjectEx.
  2505. //
  2506. // Set CERT_RDN_UNICODE_STRING in dwValueType or set
  2507. // CRYPT_UNICODE_NAME_ENCODE_ENABLE_T61_UNICODE_FLAG in dwFlags passed
  2508. // to CryptEncodeObjectEx to select CERT_RDN_T61_STRING instead of
  2509. // CERT_RDN_UNICODE_STRING if all the unicode characters are <= 0xFF.
  2510. //
  2511. // Set CERT_RDN_ENABLE_UTF8_UNICODE_STRING in dwValueType or set
  2512. // CRYPT_UNICODE_NAME_ENCODE_ENABLE_UTF8_UNICODE_FLAG in dwFlags passed
  2513. // to CryptEncodeObjectEx to select CERT_RDN_UTF8_STRING instead of
  2514. // CERT_RDN_UNICODE_STRING.
  2515. //
  2516. // The unicode string is converted before being encoded according to
  2517. // the specified or ObjId matching dwValueType.
  2518. //
  2519. // For CryptDecodeObject:
  2520. // Value.pbData points to a NULL terminated unicode string. Value.cbData
  2521. // contains the byte count of the unicode string excluding the NULL
  2522. // terminator. dwValueType contains the type used in the encoded object.
  2523. // Its not forced to CERT_RDN_UNICODE_STRING. The encoded value is
  2524. // converted to the unicode string according to the dwValueType.
  2525. //
  2526. // If the dwValueType of the encoded value isn't a character string
  2527. // type, then, it isn't converted to UNICODE. Use the
  2528. // IS_CERT_RDN_CHAR_STRING() macro on the dwValueType to check
  2529. // that Value.pbData points to a converted unicode string.
  2530. //
  2531. // By default, CERT_RDN_T61_STRING values are initially decoded
  2532. // as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  2533. // Set CRYPT_UNICODE_NAME_DECODE_DISABLE_IE4_UTF8_FLAG in dwFlags
  2534. // passed to either CryptDecodeObject or CryptDecodeObjectEx to
  2535. // skip the initial attempt to decode as UTF8.
  2536. //--------------------------------------------------------------------------
  2537. //+-------------------------------------------------------------------------
  2538. // Unicode Name Value Error Location Definitions
  2539. //
  2540. // Error location is returned in *pcbEncoded by
  2541. // CryptEncodeObject(X509_UNICODE_NAME)
  2542. //
  2543. // Error location consists of:
  2544. // RDN_INDEX - 10 bits << 22
  2545. // ATTR_INDEX - 6 bits << 16
  2546. // VALUE_INDEX - 16 bits (unicode character index)
  2547. //--------------------------------------------------------------------------
  2548. #define CERT_UNICODE_RDN_ERR_INDEX_MASK 0x3FF
  2549. #define CERT_UNICODE_RDN_ERR_INDEX_SHIFT 22
  2550. #define CERT_UNICODE_ATTR_ERR_INDEX_MASK 0x003F
  2551. #define CERT_UNICODE_ATTR_ERR_INDEX_SHIFT 16
  2552. #define CERT_UNICODE_VALUE_ERR_INDEX_MASK 0x0000FFFF
  2553. #define CERT_UNICODE_VALUE_ERR_INDEX_SHIFT 0
  2554. #define GET_CERT_UNICODE_RDN_ERR_INDEX(X) \
  2555. ((X >> CERT_UNICODE_RDN_ERR_INDEX_SHIFT) & CERT_UNICODE_RDN_ERR_INDEX_MASK)
  2556. #define GET_CERT_UNICODE_ATTR_ERR_INDEX(X) \
  2557. ((X >> CERT_UNICODE_ATTR_ERR_INDEX_SHIFT) & CERT_UNICODE_ATTR_ERR_INDEX_MASK)
  2558. #define GET_CERT_UNICODE_VALUE_ERR_INDEX(X) \
  2559. (X & CERT_UNICODE_VALUE_ERR_INDEX_MASK)
  2560. //+-------------------------------------------------------------------------
  2561. // X509_PUBLIC_KEY_INFO
  2562. //
  2563. // pvStructInfo points to CERT_PUBLIC_KEY_INFO.
  2564. //--------------------------------------------------------------------------
  2565. //+-------------------------------------------------------------------------
  2566. // X509_AUTHORITY_KEY_ID
  2567. // szOID_AUTHORITY_KEY_IDENTIFIER
  2568. //
  2569. // pvStructInfo points to following CERT_AUTHORITY_KEY_ID_INFO.
  2570. //--------------------------------------------------------------------------
  2571. typedef struct _CERT_AUTHORITY_KEY_ID_INFO {
  2572. CRYPT_DATA_BLOB KeyId;
  2573. CERT_NAME_BLOB CertIssuer;
  2574. CRYPT_INTEGER_BLOB CertSerialNumber;
  2575. } CERT_AUTHORITY_KEY_ID_INFO, *PCERT_AUTHORITY_KEY_ID_INFO;
  2576. //+-------------------------------------------------------------------------
  2577. // X509_KEY_ATTRIBUTES
  2578. // szOID_KEY_ATTRIBUTES
  2579. //
  2580. // pvStructInfo points to following CERT_KEY_ATTRIBUTES_INFO.
  2581. //--------------------------------------------------------------------------
  2582. typedef struct _CERT_PRIVATE_KEY_VALIDITY {
  2583. FILETIME NotBefore;
  2584. FILETIME NotAfter;
  2585. } CERT_PRIVATE_KEY_VALIDITY, *PCERT_PRIVATE_KEY_VALIDITY;
  2586. typedef struct _CERT_KEY_ATTRIBUTES_INFO {
  2587. CRYPT_DATA_BLOB KeyId;
  2588. CRYPT_BIT_BLOB IntendedKeyUsage;
  2589. PCERT_PRIVATE_KEY_VALIDITY pPrivateKeyUsagePeriod; // OPTIONAL
  2590. } CERT_KEY_ATTRIBUTES_INFO, *PCERT_KEY_ATTRIBUTES_INFO;
  2591. // Byte[0]
  2592. #define CERT_DIGITAL_SIGNATURE_KEY_USAGE 0x80
  2593. #define CERT_NON_REPUDIATION_KEY_USAGE 0x40
  2594. #define CERT_KEY_ENCIPHERMENT_KEY_USAGE 0x20
  2595. #define CERT_DATA_ENCIPHERMENT_KEY_USAGE 0x10
  2596. #define CERT_KEY_AGREEMENT_KEY_USAGE 0x08
  2597. #define CERT_KEY_CERT_SIGN_KEY_USAGE 0x04
  2598. #define CERT_OFFLINE_CRL_SIGN_KEY_USAGE 0x02
  2599. #define CERT_CRL_SIGN_KEY_USAGE 0x02
  2600. #define CERT_ENCIPHER_ONLY_KEY_USAGE 0x01
  2601. // Byte[1]
  2602. #define CERT_DECIPHER_ONLY_KEY_USAGE 0x80
  2603. //+-------------------------------------------------------------------------
  2604. // X509_KEY_USAGE_RESTRICTION
  2605. // szOID_KEY_USAGE_RESTRICTION
  2606. //
  2607. // pvStructInfo points to following CERT_KEY_USAGE_RESTRICTION_INFO.
  2608. //--------------------------------------------------------------------------
  2609. typedef struct _CERT_POLICY_ID {
  2610. DWORD cCertPolicyElementId;
  2611. LPSTR *rgpszCertPolicyElementId; // pszObjId
  2612. } CERT_POLICY_ID, *PCERT_POLICY_ID;
  2613. typedef struct _CERT_KEY_USAGE_RESTRICTION_INFO {
  2614. DWORD cCertPolicyId;
  2615. PCERT_POLICY_ID rgCertPolicyId;
  2616. CRYPT_BIT_BLOB RestrictedKeyUsage;
  2617. } CERT_KEY_USAGE_RESTRICTION_INFO, *PCERT_KEY_USAGE_RESTRICTION_INFO;
  2618. // See CERT_KEY_ATTRIBUTES_INFO for definition of the RestrictedKeyUsage bits
  2619. //+-------------------------------------------------------------------------
  2620. // X509_ALTERNATE_NAME
  2621. // szOID_SUBJECT_ALT_NAME
  2622. // szOID_ISSUER_ALT_NAME
  2623. // szOID_SUBJECT_ALT_NAME2
  2624. // szOID_ISSUER_ALT_NAME2
  2625. //
  2626. // pvStructInfo points to following CERT_ALT_NAME_INFO.
  2627. //--------------------------------------------------------------------------
  2628. typedef struct _CERT_OTHER_NAME {
  2629. LPSTR pszObjId;
  2630. CRYPT_OBJID_BLOB Value;
  2631. } CERT_OTHER_NAME, *PCERT_OTHER_NAME;
  2632. typedef struct _CERT_ALT_NAME_ENTRY {
  2633. DWORD dwAltNameChoice;
  2634. union {
  2635. PCERT_OTHER_NAME pOtherName; // 1
  2636. LPWSTR pwszRfc822Name; // 2 (encoded IA5)
  2637. LPWSTR pwszDNSName; // 3 (encoded IA5)
  2638. // Not implemented x400Address; // 4
  2639. CERT_NAME_BLOB DirectoryName; // 5
  2640. // Not implemented pEdiPartyName; // 6
  2641. LPWSTR pwszURL; // 7 (encoded IA5)
  2642. CRYPT_DATA_BLOB IPAddress; // 8 (Octet String)
  2643. LPSTR pszRegisteredID; // 9 (Object Identifer)
  2644. };
  2645. } CERT_ALT_NAME_ENTRY, *PCERT_ALT_NAME_ENTRY;
  2646. #define CERT_ALT_NAME_OTHER_NAME 1
  2647. #define CERT_ALT_NAME_RFC822_NAME 2
  2648. #define CERT_ALT_NAME_DNS_NAME 3
  2649. #define CERT_ALT_NAME_X400_ADDRESS 4
  2650. #define CERT_ALT_NAME_DIRECTORY_NAME 5
  2651. #define CERT_ALT_NAME_EDI_PARTY_NAME 6
  2652. #define CERT_ALT_NAME_URL 7
  2653. #define CERT_ALT_NAME_IP_ADDRESS 8
  2654. #define CERT_ALT_NAME_REGISTERED_ID 9
  2655. typedef struct _CERT_ALT_NAME_INFO {
  2656. DWORD cAltEntry;
  2657. PCERT_ALT_NAME_ENTRY rgAltEntry;
  2658. } CERT_ALT_NAME_INFO, *PCERT_ALT_NAME_INFO;
  2659. //+-------------------------------------------------------------------------
  2660. // Alternate name IA5 Error Location Definitions for
  2661. // CRYPT_E_INVALID_IA5_STRING.
  2662. //
  2663. // Error location is returned in *pcbEncoded by
  2664. // CryptEncodeObject(X509_ALTERNATE_NAME)
  2665. //
  2666. // Error location consists of:
  2667. // ENTRY_INDEX - 8 bits << 16
  2668. // VALUE_INDEX - 16 bits (unicode character index)
  2669. //--------------------------------------------------------------------------
  2670. #define CERT_ALT_NAME_ENTRY_ERR_INDEX_MASK 0xFF
  2671. #define CERT_ALT_NAME_ENTRY_ERR_INDEX_SHIFT 16
  2672. #define CERT_ALT_NAME_VALUE_ERR_INDEX_MASK 0x0000FFFF
  2673. #define CERT_ALT_NAME_VALUE_ERR_INDEX_SHIFT 0
  2674. #define GET_CERT_ALT_NAME_ENTRY_ERR_INDEX(X) \
  2675. ((X >> CERT_ALT_NAME_ENTRY_ERR_INDEX_SHIFT) & \
  2676. CERT_ALT_NAME_ENTRY_ERR_INDEX_MASK)
  2677. #define GET_CERT_ALT_NAME_VALUE_ERR_INDEX(X) \
  2678. (X & CERT_ALT_NAME_VALUE_ERR_INDEX_MASK)
  2679. //+-------------------------------------------------------------------------
  2680. // X509_BASIC_CONSTRAINTS
  2681. // szOID_BASIC_CONSTRAINTS
  2682. //
  2683. // pvStructInfo points to following CERT_BASIC_CONSTRAINTS_INFO.
  2684. //--------------------------------------------------------------------------
  2685. typedef struct _CERT_BASIC_CONSTRAINTS_INFO {
  2686. CRYPT_BIT_BLOB SubjectType;
  2687. BOOL fPathLenConstraint;
  2688. DWORD dwPathLenConstraint;
  2689. DWORD cSubtreesConstraint;
  2690. CERT_NAME_BLOB *rgSubtreesConstraint;
  2691. } CERT_BASIC_CONSTRAINTS_INFO, *PCERT_BASIC_CONSTRAINTS_INFO;
  2692. #define CERT_CA_SUBJECT_FLAG 0x80
  2693. #define CERT_END_ENTITY_SUBJECT_FLAG 0x40
  2694. //+-------------------------------------------------------------------------
  2695. // X509_BASIC_CONSTRAINTS2
  2696. // szOID_BASIC_CONSTRAINTS2
  2697. //
  2698. // pvStructInfo points to following CERT_BASIC_CONSTRAINTS2_INFO.
  2699. //--------------------------------------------------------------------------
  2700. typedef struct _CERT_BASIC_CONSTRAINTS2_INFO {
  2701. BOOL fCA;
  2702. BOOL fPathLenConstraint;
  2703. DWORD dwPathLenConstraint;
  2704. } CERT_BASIC_CONSTRAINTS2_INFO, *PCERT_BASIC_CONSTRAINTS2_INFO;
  2705. //+-------------------------------------------------------------------------
  2706. // X509_KEY_USAGE
  2707. // szOID_KEY_USAGE
  2708. //
  2709. // pvStructInfo points to a CRYPT_BIT_BLOB. Has same bit definitions as
  2710. // CERT_KEY_ATTRIBUTES_INFO's IntendedKeyUsage.
  2711. //--------------------------------------------------------------------------
  2712. //+-------------------------------------------------------------------------
  2713. // X509_CERT_POLICIES
  2714. // szOID_CERT_POLICIES
  2715. // szOID_CERT_POLICIES_95 NOTE--Only allowed for decoding!!!
  2716. //
  2717. // pvStructInfo points to following CERT_POLICIES_INFO.
  2718. //
  2719. // NOTE: when decoding using szOID_CERT_POLICIES_95 the pszPolicyIdentifier
  2720. // may contain an empty string
  2721. //--------------------------------------------------------------------------
  2722. typedef struct _CERT_POLICY_QUALIFIER_INFO {
  2723. LPSTR pszPolicyQualifierId; // pszObjId
  2724. CRYPT_OBJID_BLOB Qualifier; // optional
  2725. } CERT_POLICY_QUALIFIER_INFO, *PCERT_POLICY_QUALIFIER_INFO;
  2726. typedef struct _CERT_POLICY_INFO {
  2727. LPSTR pszPolicyIdentifier; // pszObjId
  2728. DWORD cPolicyQualifier; // optional
  2729. CERT_POLICY_QUALIFIER_INFO *rgPolicyQualifier;
  2730. } CERT_POLICY_INFO, *PCERT_POLICY_INFO;
  2731. typedef struct _CERT_POLICIES_INFO {
  2732. DWORD cPolicyInfo;
  2733. CERT_POLICY_INFO *rgPolicyInfo;
  2734. } CERT_POLICIES_INFO, *PCERT_POLICIES_INFO;
  2735. //+-------------------------------------------------------------------------
  2736. // X509_PKIX_POLICY_QUALIFIER_USERNOTICE
  2737. // szOID_PKIX_POLICY_QUALIFIER_USERNOTICE
  2738. //
  2739. // pvStructInfo points to following CERT_POLICY_QUALIFIER_USER_NOTICE.
  2740. //
  2741. //--------------------------------------------------------------------------
  2742. typedef struct _CERT_POLICY_QUALIFIER_NOTICE_REFERENCE {
  2743. LPSTR pszOrganization;
  2744. DWORD cNoticeNumbers;
  2745. int *rgNoticeNumbers;
  2746. } CERT_POLICY_QUALIFIER_NOTICE_REFERENCE, *PCERT_POLICY_QUALIFIER_NOTICE_REFERENCE;
  2747. typedef struct _CERT_POLICY_QUALIFIER_USER_NOTICE {
  2748. CERT_POLICY_QUALIFIER_NOTICE_REFERENCE *pNoticeReference; // optional
  2749. LPWSTR pszDisplayText; // optional
  2750. } CERT_POLICY_QUALIFIER_USER_NOTICE, *PCERT_POLICY_QUALIFIER_USER_NOTICE;
  2751. //+-------------------------------------------------------------------------
  2752. // szOID_CERT_POLICIES_95_QUALIFIER1 - Decode Only!!!!
  2753. //
  2754. // pvStructInfo points to following CERT_POLICY95_QUALIFIER1.
  2755. //
  2756. //--------------------------------------------------------------------------
  2757. typedef struct _CPS_URLS {
  2758. LPWSTR pszURL;
  2759. CRYPT_ALGORITHM_IDENTIFIER *pAlgorithm; // optional
  2760. CRYPT_DATA_BLOB *pDigest; // optional
  2761. } CPS_URLS, *PCPS_URLS;
  2762. typedef struct _CERT_POLICY95_QUALIFIER1 {
  2763. LPWSTR pszPracticesReference; // optional
  2764. LPSTR pszNoticeIdentifier; // optional
  2765. LPSTR pszNSINoticeIdentifier; // optional
  2766. DWORD cCPSURLs;
  2767. CPS_URLS *rgCPSURLs; // optional
  2768. } CERT_POLICY95_QUALIFIER1, *PCERT_POLICY95_QUALIFIER1;
  2769. //+-------------------------------------------------------------------------
  2770. // X509_POLICY_MAPPINGS
  2771. // szOID_POLICY_MAPPINGS
  2772. // szOID_LEGACY_POLICY_MAPPINGS
  2773. //
  2774. // pvStructInfo points to following CERT_POLICY_MAPPINGS_INFO.
  2775. //--------------------------------------------------------------------------
  2776. typedef struct _CERT_POLICY_MAPPING {
  2777. LPSTR pszIssuerDomainPolicy; // pszObjId
  2778. LPSTR pszSubjectDomainPolicy; // pszObjId
  2779. } CERT_POLICY_MAPPING, *PCERT_POLICY_MAPPING;
  2780. typedef struct _CERT_POLICY_MAPPINGS_INFO {
  2781. DWORD cPolicyMapping;
  2782. PCERT_POLICY_MAPPING rgPolicyMapping;
  2783. } CERT_POLICY_MAPPINGS_INFO, *PCERT_POLICY_MAPPINGS_INFO;
  2784. //+-------------------------------------------------------------------------
  2785. // X509_POLICY_CONSTRAINTS
  2786. // szOID_POLICY_CONSTRAINTS
  2787. //
  2788. // pvStructInfo points to following CERT_POLICY_CONSTRAINTS_INFO.
  2789. //--------------------------------------------------------------------------
  2790. typedef struct _CERT_POLICY_CONSTRAINTS_INFO {
  2791. BOOL fRequireExplicitPolicy;
  2792. DWORD dwRequireExplicitPolicySkipCerts;
  2793. BOOL fInhibitPolicyMapping;
  2794. DWORD dwInhibitPolicyMappingSkipCerts;
  2795. } CERT_POLICY_CONSTRAINTS_INFO, *PCERT_POLICY_CONSTRAINTS_INFO;
  2796. //+-------------------------------------------------------------------------
  2797. // RSA_CSP_PUBLICKEYBLOB
  2798. //
  2799. // pvStructInfo points to a PUBLICKEYSTRUC immediately followed by a
  2800. // RSAPUBKEY and the modulus bytes.
  2801. //
  2802. // CryptExportKey outputs the above StructInfo for a dwBlobType of
  2803. // PUBLICKEYBLOB. CryptImportKey expects the above StructInfo when
  2804. // importing a public key.
  2805. //
  2806. // For dwCertEncodingType = X509_ASN_ENCODING, the RSA_CSP_PUBLICKEYBLOB is
  2807. // encoded as a PKCS #1 RSAPublicKey consisting of a SEQUENCE of a
  2808. // modulus INTEGER and a publicExponent INTEGER. The modulus is encoded
  2809. // as being a unsigned integer. When decoded, if the modulus was encoded
  2810. // as unsigned integer with a leading 0 byte, the 0 byte is removed before
  2811. // converting to the CSP modulus bytes.
  2812. //
  2813. // For decode, the aiKeyAlg field of PUBLICKEYSTRUC is always set to
  2814. // CALG_RSA_KEYX.
  2815. //--------------------------------------------------------------------------
  2816. //+-------------------------------------------------------------------------
  2817. // X509_KEYGEN_REQUEST_TO_BE_SIGNED
  2818. //
  2819. // pvStructInfo points to CERT_KEYGEN_REQUEST_INFO.
  2820. //
  2821. // For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  2822. // signature (output of a X509_CERT CryptEncodeObject()).
  2823. //
  2824. // For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  2825. //--------------------------------------------------------------------------
  2826. //+-------------------------------------------------------------------------
  2827. // PKCS_ATTRIBUTE data structure
  2828. //
  2829. // pvStructInfo points to a CRYPT_ATTRIBUTE.
  2830. //--------------------------------------------------------------------------
  2831. //+-------------------------------------------------------------------------
  2832. // PKCS_ATTRIBUTES data structure
  2833. //
  2834. // pvStructInfo points to a CRYPT_ATTRIBUTES.
  2835. //--------------------------------------------------------------------------
  2836. //+-------------------------------------------------------------------------
  2837. // PKCS_CONTENT_INFO_SEQUENCE_OF_ANY data structure
  2838. //
  2839. // pvStructInfo points to following CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY.
  2840. //
  2841. // For X509_ASN_ENCODING: encoded as a PKCS#7 ContentInfo structure wrapping
  2842. // a sequence of ANY. The value of the contentType field is pszObjId,
  2843. // while the content field is the following structure:
  2844. // SequenceOfAny ::= SEQUENCE OF ANY
  2845. //
  2846. // The CRYPT_DER_BLOBs point to the already encoded ANY content.
  2847. //--------------------------------------------------------------------------
  2848. typedef struct _CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY {
  2849. LPSTR pszObjId;
  2850. DWORD cValue;
  2851. PCRYPT_DER_BLOB rgValue;
  2852. } CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY, *PCRYPT_CONTENT_INFO_SEQUENCE_OF_ANY;
  2853. //+-------------------------------------------------------------------------
  2854. // PKCS_CONTENT_INFO data structure
  2855. //
  2856. // pvStructInfo points to following CRYPT_CONTENT_INFO.
  2857. //
  2858. // For X509_ASN_ENCODING: encoded as a PKCS#7 ContentInfo structure.
  2859. // The CRYPT_DER_BLOB points to the already encoded ANY content.
  2860. //--------------------------------------------------------------------------
  2861. typedef struct _CRYPT_CONTENT_INFO {
  2862. LPSTR pszObjId;
  2863. CRYPT_DER_BLOB Content;
  2864. } CRYPT_CONTENT_INFO, *PCRYPT_CONTENT_INFO;
  2865. //+-------------------------------------------------------------------------
  2866. // X509_OCTET_STRING data structure
  2867. //
  2868. // pvStructInfo points to a CRYPT_DATA_BLOB.
  2869. //--------------------------------------------------------------------------
  2870. //+-------------------------------------------------------------------------
  2871. // X509_BITS data structure
  2872. //
  2873. // pvStructInfo points to a CRYPT_BIT_BLOB.
  2874. //--------------------------------------------------------------------------
  2875. //+-------------------------------------------------------------------------
  2876. // X509_BITS_WITHOUT_TRAILING_ZEROES data structure
  2877. //
  2878. // pvStructInfo points to a CRYPT_BIT_BLOB.
  2879. //
  2880. // The same as X509_BITS, except before encoding, the bit length is
  2881. // decremented to exclude trailing zero bits.
  2882. //--------------------------------------------------------------------------
  2883. //+-------------------------------------------------------------------------
  2884. // X509_INTEGER data structure
  2885. //
  2886. // pvStructInfo points to an int.
  2887. //--------------------------------------------------------------------------
  2888. //+-------------------------------------------------------------------------
  2889. // X509_MULTI_BYTE_INTEGER data structure
  2890. //
  2891. // pvStructInfo points to a CRYPT_INTEGER_BLOB.
  2892. //--------------------------------------------------------------------------
  2893. //+-------------------------------------------------------------------------
  2894. // X509_ENUMERATED data structure
  2895. //
  2896. // pvStructInfo points to an int containing the enumerated value
  2897. //--------------------------------------------------------------------------
  2898. //+-------------------------------------------------------------------------
  2899. // X509_CHOICE_OF_TIME data structure
  2900. //
  2901. // pvStructInfo points to a FILETIME.
  2902. //--------------------------------------------------------------------------
  2903. //+-------------------------------------------------------------------------
  2904. // X509_SEQUENCE_OF_ANY data structure
  2905. //
  2906. // pvStructInfo points to following CRYPT_SEQUENCE_OF_ANY.
  2907. //
  2908. // The CRYPT_DER_BLOBs point to the already encoded ANY content.
  2909. //--------------------------------------------------------------------------
  2910. typedef struct _CRYPT_SEQUENCE_OF_ANY {
  2911. DWORD cValue;
  2912. PCRYPT_DER_BLOB rgValue;
  2913. } CRYPT_SEQUENCE_OF_ANY, *PCRYPT_SEQUENCE_OF_ANY;
  2914. //+-------------------------------------------------------------------------
  2915. // X509_AUTHORITY_KEY_ID2
  2916. // szOID_AUTHORITY_KEY_IDENTIFIER2
  2917. //
  2918. // pvStructInfo points to following CERT_AUTHORITY_KEY_ID2_INFO.
  2919. //
  2920. // For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  2921. // *pcbEncoded by CryptEncodeObject(X509_AUTHORITY_KEY_ID2)
  2922. //
  2923. // See X509_ALTERNATE_NAME for error location defines.
  2924. //--------------------------------------------------------------------------
  2925. typedef struct _CERT_AUTHORITY_KEY_ID2_INFO {
  2926. CRYPT_DATA_BLOB KeyId;
  2927. CERT_ALT_NAME_INFO AuthorityCertIssuer; // Optional, set cAltEntry
  2928. // to 0 to omit.
  2929. CRYPT_INTEGER_BLOB AuthorityCertSerialNumber;
  2930. } CERT_AUTHORITY_KEY_ID2_INFO, *PCERT_AUTHORITY_KEY_ID2_INFO;
  2931. //+-------------------------------------------------------------------------
  2932. // szOID_SUBJECT_KEY_IDENTIFIER
  2933. //
  2934. // pvStructInfo points to a CRYPT_DATA_BLOB.
  2935. //--------------------------------------------------------------------------
  2936. //+-------------------------------------------------------------------------
  2937. // X509_AUTHORITY_INFO_ACCESS
  2938. // szOID_AUTHORITY_INFO_ACCESS
  2939. //
  2940. // pvStructInfo points to following CERT_AUTHORITY_INFO_ACCESS.
  2941. //
  2942. // For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  2943. // *pcbEncoded by CryptEncodeObject(X509_AUTHORITY_INFO_ACCESS)
  2944. //
  2945. // Error location consists of:
  2946. // ENTRY_INDEX - 8 bits << 16
  2947. // VALUE_INDEX - 16 bits (unicode character index)
  2948. //
  2949. // See X509_ALTERNATE_NAME for ENTRY_INDEX and VALUE_INDEX error location
  2950. // defines.
  2951. //--------------------------------------------------------------------------
  2952. typedef struct _CERT_ACCESS_DESCRIPTION {
  2953. LPSTR pszAccessMethod; // pszObjId
  2954. CERT_ALT_NAME_ENTRY AccessLocation;
  2955. } CERT_ACCESS_DESCRIPTION, *PCERT_ACCESS_DESCRIPTION;
  2956. typedef struct _CERT_AUTHORITY_INFO_ACCESS {
  2957. DWORD cAccDescr;
  2958. PCERT_ACCESS_DESCRIPTION rgAccDescr;
  2959. } CERT_AUTHORITY_INFO_ACCESS, *PCERT_AUTHORITY_INFO_ACCESS;
  2960. //+-------------------------------------------------------------------------
  2961. // PKIX Access Description: Access Method Object Identifiers
  2962. //--------------------------------------------------------------------------
  2963. #define szOID_PKIX_ACC_DESCR "1.3.6.1.5.5.7.48"
  2964. #define szOID_PKIX_OCSP "1.3.6.1.5.5.7.48.1"
  2965. #define szOID_PKIX_CA_ISSUERS "1.3.6.1.5.5.7.48.2"
  2966. //+-------------------------------------------------------------------------
  2967. // X509_CRL_REASON_CODE
  2968. // szOID_CRL_REASON_CODE
  2969. //
  2970. // pvStructInfo points to an int which can be set to one of the following
  2971. // enumerated values:
  2972. //--------------------------------------------------------------------------
  2973. #define CRL_REASON_UNSPECIFIED 0
  2974. #define CRL_REASON_KEY_COMPROMISE 1
  2975. #define CRL_REASON_CA_COMPROMISE 2
  2976. #define CRL_REASON_AFFILIATION_CHANGED 3
  2977. #define CRL_REASON_SUPERSEDED 4
  2978. #define CRL_REASON_CESSATION_OF_OPERATION 5
  2979. #define CRL_REASON_CERTIFICATE_HOLD 6
  2980. #define CRL_REASON_REMOVE_FROM_CRL 8
  2981. //+-------------------------------------------------------------------------
  2982. // X509_CRL_DIST_POINTS
  2983. // szOID_CRL_DIST_POINTS
  2984. //
  2985. // pvStructInfo points to following CRL_DIST_POINTS_INFO.
  2986. //
  2987. // For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  2988. // *pcbEncoded by CryptEncodeObject(X509_CRL_DIST_POINTS)
  2989. //
  2990. // Error location consists of:
  2991. // CRL_ISSUER_BIT - 1 bit << 31 (0 for FullName, 1 for CRLIssuer)
  2992. // POINT_INDEX - 7 bits << 24
  2993. // ENTRY_INDEX - 8 bits << 16
  2994. // VALUE_INDEX - 16 bits (unicode character index)
  2995. //
  2996. // See X509_ALTERNATE_NAME for ENTRY_INDEX and VALUE_INDEX error location
  2997. // defines.
  2998. //--------------------------------------------------------------------------
  2999. typedef struct _CRL_DIST_POINT_NAME {
  3000. DWORD dwDistPointNameChoice;
  3001. union {
  3002. CERT_ALT_NAME_INFO FullName; // 1
  3003. // Not implemented IssuerRDN; // 2
  3004. };
  3005. } CRL_DIST_POINT_NAME, *PCRL_DIST_POINT_NAME;
  3006. #define CRL_DIST_POINT_NO_NAME 0
  3007. #define CRL_DIST_POINT_FULL_NAME 1
  3008. #define CRL_DIST_POINT_ISSUER_RDN_NAME 2
  3009. typedef struct _CRL_DIST_POINT {
  3010. CRL_DIST_POINT_NAME DistPointName; // OPTIONAL
  3011. CRYPT_BIT_BLOB ReasonFlags; // OPTIONAL
  3012. CERT_ALT_NAME_INFO CRLIssuer; // OPTIONAL
  3013. } CRL_DIST_POINT, *PCRL_DIST_POINT;
  3014. #define CRL_REASON_UNUSED_FLAG 0x80
  3015. #define CRL_REASON_KEY_COMPROMISE_FLAG 0x40
  3016. #define CRL_REASON_CA_COMPROMISE_FLAG 0x20
  3017. #define CRL_REASON_AFFILIATION_CHANGED_FLAG 0x10
  3018. #define CRL_REASON_SUPERSEDED_FLAG 0x08
  3019. #define CRL_REASON_CESSATION_OF_OPERATION_FLAG 0x04
  3020. #define CRL_REASON_CERTIFICATE_HOLD_FLAG 0x02
  3021. typedef struct _CRL_DIST_POINTS_INFO {
  3022. DWORD cDistPoint;
  3023. PCRL_DIST_POINT rgDistPoint;
  3024. } CRL_DIST_POINTS_INFO, *PCRL_DIST_POINTS_INFO;
  3025. #define CRL_DIST_POINT_ERR_INDEX_MASK 0x7F
  3026. #define CRL_DIST_POINT_ERR_INDEX_SHIFT 24
  3027. #define GET_CRL_DIST_POINT_ERR_INDEX(X) \
  3028. ((X >> CRL_DIST_POINT_ERR_INDEX_SHIFT) & CRL_DIST_POINT_ERR_INDEX_MASK)
  3029. #define CRL_DIST_POINT_ERR_CRL_ISSUER_BIT 0x80000000L
  3030. #define IS_CRL_DIST_POINT_ERR_CRL_ISSUER(X) \
  3031. (0 != (X & CRL_DIST_POINT_ERR_CRL_ISSUER_BIT))
  3032. //+-------------------------------------------------------------------------
  3033. // X509_CROSS_CERT_DIST_POINTS
  3034. // szOID_CROSS_CERT_DIST_POINTS
  3035. //
  3036. // pvStructInfo points to following CROSS_CERT_DIST_POINTS_INFO.
  3037. //
  3038. // For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  3039. // *pcbEncoded by CryptEncodeObject(X509_CRL_DIST_POINTS)
  3040. //
  3041. // Error location consists of:
  3042. // POINT_INDEX - 8 bits << 24
  3043. // ENTRY_INDEX - 8 bits << 16
  3044. // VALUE_INDEX - 16 bits (unicode character index)
  3045. //
  3046. // See X509_ALTERNATE_NAME for ENTRY_INDEX and VALUE_INDEX error location
  3047. // defines.
  3048. //--------------------------------------------------------------------------
  3049. typedef struct _CROSS_CERT_DIST_POINTS_INFO {
  3050. // Seconds between syncs. 0 implies use client default.
  3051. DWORD dwSyncDeltaTime;
  3052. DWORD cDistPoint;
  3053. PCERT_ALT_NAME_INFO rgDistPoint;
  3054. } CROSS_CERT_DIST_POINTS_INFO, *PCROSS_CERT_DIST_POINTS_INFO;
  3055. #define CROSS_CERT_DIST_POINT_ERR_INDEX_MASK 0xFF
  3056. #define CROSS_CERT_DIST_POINT_ERR_INDEX_SHIFT 24
  3057. #define GET_CROSS_CERT_DIST_POINT_ERR_INDEX(X) \
  3058. ((X >> CROSS_CERT_DIST_POINT_ERR_INDEX_SHIFT) & \
  3059. CROSS_CERT_DIST_POINT_ERR_INDEX_MASK)
  3060. //+-------------------------------------------------------------------------
  3061. // X509_ENHANCED_KEY_USAGE
  3062. // szOID_ENHANCED_KEY_USAGE
  3063. //
  3064. // pvStructInfo points to a CERT_ENHKEY_USAGE, CTL_USAGE.
  3065. //--------------------------------------------------------------------------
  3066. //+-------------------------------------------------------------------------
  3067. // X509_CERT_PAIR
  3068. //
  3069. // pvStructInfo points to the following CERT_PAIR.
  3070. //--------------------------------------------------------------------------
  3071. typedef struct _CERT_PAIR {
  3072. CERT_BLOB Forward; // OPTIONAL, if Forward.cbData == 0, omitted
  3073. CERT_BLOB Reverse; // OPTIONAL, if Reverse.cbData == 0, omitted
  3074. } CERT_PAIR, *PCERT_PAIR;
  3075. //+-------------------------------------------------------------------------
  3076. // szOID_CRL_NUMBER
  3077. //
  3078. // pvStructInfo points to an int.
  3079. //--------------------------------------------------------------------------
  3080. //+-------------------------------------------------------------------------
  3081. // szOID_DELTA_CRL_INDICATOR
  3082. //
  3083. // pvStructInfo points to an int.
  3084. //--------------------------------------------------------------------------
  3085. //+-------------------------------------------------------------------------
  3086. // szOID_ISSUING_DIST_POINT
  3087. // X509_ISSUING_DIST_POINT
  3088. //
  3089. // pvStructInfo points to the following CRL_ISSUING_DIST_POINT.
  3090. //
  3091. // For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  3092. // *pcbEncoded by CryptEncodeObject(X509_ISSUING_DIST_POINT)
  3093. //
  3094. // Error location consists of:
  3095. // ENTRY_INDEX - 8 bits << 16
  3096. // VALUE_INDEX - 16 bits (unicode character index)
  3097. //
  3098. // See X509_ALTERNATE_NAME for ENTRY_INDEX and VALUE_INDEX error location
  3099. // defines.
  3100. //--------------------------------------------------------------------------
  3101. typedef struct _CRL_ISSUING_DIST_POINT {
  3102. CRL_DIST_POINT_NAME DistPointName; // OPTIONAL
  3103. BOOL fOnlyContainsUserCerts;
  3104. BOOL fOnlyContainsCACerts;
  3105. CRYPT_BIT_BLOB OnlySomeReasonFlags; // OPTIONAL
  3106. BOOL fIndirectCRL;
  3107. } CRL_ISSUING_DIST_POINT, *PCRL_ISSUING_DIST_POINT;
  3108. //+-------------------------------------------------------------------------
  3109. // szOID_FRESHEST_CRL
  3110. //
  3111. // pvStructInfo points to CRL_DIST_POINTS_INFO.
  3112. //--------------------------------------------------------------------------
  3113. //+-------------------------------------------------------------------------
  3114. // szOID_NAME_CONSTRAINTS
  3115. // X509_NAME_CONSTRAINTS
  3116. //
  3117. // pvStructInfo points to the following CERT_NAME_CONSTRAINTS_INFO
  3118. //
  3119. // For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  3120. // *pcbEncoded by CryptEncodeObject(X509_NAME_CONSTRAINTS)
  3121. //
  3122. // Error location consists of:
  3123. // EXCLUDED_SUBTREE_BIT - 1 bit << 31 (0 for permitted, 1 for excluded)
  3124. // ENTRY_INDEX - 8 bits << 16
  3125. // VALUE_INDEX - 16 bits (unicode character index)
  3126. //
  3127. // See X509_ALTERNATE_NAME for ENTRY_INDEX and VALUE_INDEX error location
  3128. // defines.
  3129. //--------------------------------------------------------------------------
  3130. typedef struct _CERT_GENERAL_SUBTREE {
  3131. CERT_ALT_NAME_ENTRY Base;
  3132. DWORD dwMinimum;
  3133. BOOL fMaximum;
  3134. DWORD dwMaximum;
  3135. } CERT_GENERAL_SUBTREE, *PCERT_GENERAL_SUBTREE;
  3136. typedef struct _CERT_NAME_CONSTRAINTS_INFO {
  3137. DWORD cPermittedSubtree;
  3138. PCERT_GENERAL_SUBTREE rgPermittedSubtree;
  3139. DWORD cExcludedSubtree;
  3140. PCERT_GENERAL_SUBTREE rgExcludedSubtree;
  3141. } CERT_NAME_CONSTRAINTS_INFO, *PCERT_NAME_CONSTRAINTS_INFO;
  3142. #define CERT_EXCLUDED_SUBTREE_BIT 0x80000000L
  3143. #define IS_CERT_EXCLUDED_SUBTREE(X) \
  3144. (0 != (X & CERT_EXCLUDED_SUBTREE_BIT))
  3145. //+-------------------------------------------------------------------------
  3146. // szOID_NEXT_UPDATE_LOCATION
  3147. //
  3148. // pvStructInfo points to a CERT_ALT_NAME_INFO.
  3149. //--------------------------------------------------------------------------
  3150. //+-------------------------------------------------------------------------
  3151. // szOID_REMOVE_CERTIFICATE
  3152. //
  3153. // pvStructInfo points to an int which can be set to one of the following
  3154. // 0 - Add certificate
  3155. // 1 - Remove certificate
  3156. //--------------------------------------------------------------------------
  3157. //+-------------------------------------------------------------------------
  3158. // PKCS_CTL
  3159. // szOID_CTL
  3160. //
  3161. // pvStructInfo points to a CTL_INFO.
  3162. //--------------------------------------------------------------------------
  3163. //+-------------------------------------------------------------------------
  3164. // PKCS_SORTED_CTL
  3165. //
  3166. // pvStructInfo points to a CTL_INFO.
  3167. //
  3168. // Same as for PKCS_CTL, except, the CTL entries are sorted. The following
  3169. // extension containing the sort information is inserted as the first
  3170. // extension in the encoded CTL.
  3171. //
  3172. // Only supported for Encoding. CRYPT_ENCODE_ALLOC_FLAG flag must be
  3173. // set.
  3174. //--------------------------------------------------------------------------
  3175. //+-------------------------------------------------------------------------
  3176. // Sorted CTL TrustedSubjects extension
  3177. //
  3178. // Array of little endian DWORDs:
  3179. // [0] - Flags
  3180. // [1] - Count of HashBucket entry offsets
  3181. // [2] - Maximum HashBucket entry collision count
  3182. // [3 ..] (Count + 1) HashBucket entry offsets
  3183. //
  3184. // When this extension is present in the CTL,
  3185. // the ASN.1 encoded sequence of TrustedSubjects are HashBucket ordered.
  3186. //
  3187. // The entry offsets point to the start of the first encoded TrustedSubject
  3188. // sequence for the HashBucket. The encoded TrustedSubjects for a HashBucket
  3189. // continue until the encoded offset of the next HashBucket. A HashBucket has
  3190. // no entries if HashBucket[N] == HashBucket[N + 1].
  3191. //
  3192. // The HashBucket offsets are from the start of the ASN.1 encoded CTL_INFO.
  3193. //--------------------------------------------------------------------------
  3194. #define SORTED_CTL_EXT_FLAGS_OFFSET (0*4)
  3195. #define SORTED_CTL_EXT_COUNT_OFFSET (1*4)
  3196. #define SORTED_CTL_EXT_MAX_COLLISION_OFFSET (2*4)
  3197. #define SORTED_CTL_EXT_HASH_BUCKET_OFFSET (3*4)
  3198. // If the SubjectIdentifiers are a MD5 or SHA1 hash, the following flag is
  3199. // set. When set, the first 4 bytes of the SubjectIdentifier are used as
  3200. // the dwhash. Otherwise, the SubjectIdentifier bytes are hashed into dwHash.
  3201. // In either case the HashBucket index = dwHash % cHashBucket.
  3202. #define SORTED_CTL_EXT_HASHED_SUBJECT_IDENTIFIER_FLAG 0x1
  3203. //+-------------------------------------------------------------------------
  3204. // X509_MULTI_BYTE_UINT
  3205. //
  3206. // pvStructInfo points to a CRYPT_UINT_BLOB. Before encoding, inserts a
  3207. // leading 0x00. After decoding, removes a leading 0x00.
  3208. //--------------------------------------------------------------------------
  3209. //+-------------------------------------------------------------------------
  3210. // X509_DSS_PUBLICKEY
  3211. //
  3212. // pvStructInfo points to a CRYPT_UINT_BLOB.
  3213. //--------------------------------------------------------------------------
  3214. //+-------------------------------------------------------------------------
  3215. // X509_DSS_PARAMETERS
  3216. //
  3217. // pvStructInfo points to following CERT_DSS_PARAMETERS data structure.
  3218. //--------------------------------------------------------------------------
  3219. typedef struct _CERT_DSS_PARAMETERS {
  3220. CRYPT_UINT_BLOB p;
  3221. CRYPT_UINT_BLOB q;
  3222. CRYPT_UINT_BLOB g;
  3223. } CERT_DSS_PARAMETERS, *PCERT_DSS_PARAMETERS;
  3224. //+-------------------------------------------------------------------------
  3225. // X509_DSS_SIGNATURE
  3226. //
  3227. // pvStructInfo is a BYTE rgbSignature[CERT_DSS_SIGNATURE_LEN]. The
  3228. // bytes are ordered as output by the DSS CSP's CryptSignHash().
  3229. //--------------------------------------------------------------------------
  3230. #define CERT_DSS_R_LEN 20
  3231. #define CERT_DSS_S_LEN 20
  3232. #define CERT_DSS_SIGNATURE_LEN (CERT_DSS_R_LEN + CERT_DSS_S_LEN)
  3233. // Sequence of 2 unsigned integers (the extra +1 is for a potential leading
  3234. // 0x00 to make the integer unsigned)
  3235. #define CERT_MAX_ASN_ENCODED_DSS_SIGNATURE_LEN (2 + 2*(2 + 20 +1))
  3236. //+-------------------------------------------------------------------------
  3237. // X509_DH_PUBLICKEY
  3238. //
  3239. // pvStructInfo points to a CRYPT_UINT_BLOB.
  3240. //--------------------------------------------------------------------------
  3241. //+-------------------------------------------------------------------------
  3242. // X509_DH_PARAMETERS
  3243. //
  3244. // pvStructInfo points to following CERT_DH_PARAMETERS data structure.
  3245. //--------------------------------------------------------------------------
  3246. typedef struct _CERT_DH_PARAMETERS {
  3247. CRYPT_UINT_BLOB p;
  3248. CRYPT_UINT_BLOB g;
  3249. } CERT_DH_PARAMETERS, *PCERT_DH_PARAMETERS;
  3250. //+-------------------------------------------------------------------------
  3251. // X942_DH_PARAMETERS
  3252. //
  3253. // pvStructInfo points to following CERT_X942_DH_PARAMETERS data structure.
  3254. //
  3255. // If q.cbData == 0, then, the following fields are zero'ed.
  3256. //--------------------------------------------------------------------------
  3257. typedef struct _CERT_X942_DH_VALIDATION_PARAMS {
  3258. CRYPT_BIT_BLOB seed;
  3259. DWORD pgenCounter;
  3260. } CERT_X942_DH_VALIDATION_PARAMS, *PCERT_X942_DH_VALIDATION_PARAMS;
  3261. typedef struct _CERT_X942_DH_PARAMETERS {
  3262. CRYPT_UINT_BLOB p; // odd prime, p = jq + 1
  3263. CRYPT_UINT_BLOB g; // generator, g
  3264. CRYPT_UINT_BLOB q; // factor of p - 1, OPTIONAL
  3265. CRYPT_UINT_BLOB j; // subgroup factor, OPTIONAL
  3266. PCERT_X942_DH_VALIDATION_PARAMS pValidationParams; // OPTIONAL
  3267. } CERT_X942_DH_PARAMETERS, *PCERT_X942_DH_PARAMETERS;
  3268. //+-------------------------------------------------------------------------
  3269. // X942_OTHER_INFO
  3270. //
  3271. // pvStructInfo points to following CRYPT_X942_OTHER_INFO data structure.
  3272. //
  3273. // rgbCounter and rgbKeyLength are in Little Endian order.
  3274. //--------------------------------------------------------------------------
  3275. #define CRYPT_X942_COUNTER_BYTE_LENGTH 4
  3276. #define CRYPT_X942_KEY_LENGTH_BYTE_LENGTH 4
  3277. #define CRYPT_X942_PUB_INFO_BYTE_LENGTH (512/8)
  3278. typedef struct _CRYPT_X942_OTHER_INFO {
  3279. LPSTR pszContentEncryptionObjId;
  3280. BYTE rgbCounter[CRYPT_X942_COUNTER_BYTE_LENGTH];
  3281. BYTE rgbKeyLength[CRYPT_X942_KEY_LENGTH_BYTE_LENGTH];
  3282. CRYPT_DATA_BLOB PubInfo; // OPTIONAL
  3283. } CRYPT_X942_OTHER_INFO, *PCRYPT_X942_OTHER_INFO;
  3284. //+-------------------------------------------------------------------------
  3285. // PKCS_RC2_CBC_PARAMETERS
  3286. // szOID_RSA_RC2CBC
  3287. //
  3288. // pvStructInfo points to following CRYPT_RC2_CBC_PARAMETERS data structure.
  3289. //--------------------------------------------------------------------------
  3290. typedef struct _CRYPT_RC2_CBC_PARAMETERS {
  3291. DWORD dwVersion;
  3292. BOOL fIV; // set if has following IV
  3293. BYTE rgbIV[8];
  3294. } CRYPT_RC2_CBC_PARAMETERS, *PCRYPT_RC2_CBC_PARAMETERS;
  3295. #define CRYPT_RC2_40BIT_VERSION 160
  3296. #define CRYPT_RC2_56BIT_VERSION 52
  3297. #define CRYPT_RC2_64BIT_VERSION 120
  3298. #define CRYPT_RC2_128BIT_VERSION 58
  3299. //+-------------------------------------------------------------------------
  3300. // PKCS_SMIME_CAPABILITIES
  3301. // szOID_RSA_SMIMECapabilities
  3302. //
  3303. // pvStructInfo points to following CRYPT_SMIME_CAPABILITIES data structure.
  3304. //
  3305. // Note, for CryptEncodeObject(X509_ASN_ENCODING), Parameters.cbData == 0
  3306. // causes the encoded parameters to be omitted and not encoded as a NULL
  3307. // (05 00) as is done when encoding a CRYPT_ALGORITHM_IDENTIFIER. This
  3308. // is per the SMIME specification for encoding capabilities.
  3309. //--------------------------------------------------------------------------
  3310. typedef struct _CRYPT_SMIME_CAPABILITY {
  3311. LPSTR pszObjId;
  3312. CRYPT_OBJID_BLOB Parameters;
  3313. } CRYPT_SMIME_CAPABILITY, *PCRYPT_SMIME_CAPABILITY;
  3314. typedef struct _CRYPT_SMIME_CAPABILITIES {
  3315. DWORD cCapability;
  3316. PCRYPT_SMIME_CAPABILITY rgCapability;
  3317. } CRYPT_SMIME_CAPABILITIES, *PCRYPT_SMIME_CAPABILITIES;
  3318. //+-------------------------------------------------------------------------
  3319. // PKCS7_SIGNER_INFO
  3320. //
  3321. // pvStructInfo points to CMSG_SIGNER_INFO.
  3322. //--------------------------------------------------------------------------
  3323. //+-------------------------------------------------------------------------
  3324. // CMS_SIGNER_INFO
  3325. //
  3326. // pvStructInfo points to CMSG_CMS_SIGNER_INFO.
  3327. //--------------------------------------------------------------------------
  3328. //+-------------------------------------------------------------------------
  3329. // Verisign Certificate Extension Object Identifiers
  3330. //--------------------------------------------------------------------------
  3331. // Octet String containing Boolean
  3332. #define szOID_VERISIGN_PRIVATE_6_9 "2.16.840.1.113733.1.6.9"
  3333. // Octet String containing IA5 string: lower case 32 char hex string
  3334. #define szOID_VERISIGN_ONSITE_JURISDICTION_HASH "2.16.840.1.113733.1.6.11"
  3335. // Octet String containing Bit string
  3336. #define szOID_VERISIGN_BITSTRING_6_13 "2.16.840.1.113733.1.6.13"
  3337. // EKU
  3338. #define szOID_VERISIGN_ISS_STRONG_CRYPTO "2.16.840.1.113733.1.8.1"
  3339. //+-------------------------------------------------------------------------
  3340. // Netscape Certificate Extension Object Identifiers
  3341. //--------------------------------------------------------------------------
  3342. #define szOID_NETSCAPE "2.16.840.1.113730"
  3343. #define szOID_NETSCAPE_CERT_EXTENSION "2.16.840.1.113730.1"
  3344. #define szOID_NETSCAPE_CERT_TYPE "2.16.840.1.113730.1.1"
  3345. #define szOID_NETSCAPE_BASE_URL "2.16.840.1.113730.1.2"
  3346. #define szOID_NETSCAPE_REVOCATION_URL "2.16.840.1.113730.1.3"
  3347. #define szOID_NETSCAPE_CA_REVOCATION_URL "2.16.840.1.113730.1.4"
  3348. #define szOID_NETSCAPE_CERT_RENEWAL_URL "2.16.840.1.113730.1.7"
  3349. #define szOID_NETSCAPE_CA_POLICY_URL "2.16.840.1.113730.1.8"
  3350. #define szOID_NETSCAPE_SSL_SERVER_NAME "2.16.840.1.113730.1.12"
  3351. #define szOID_NETSCAPE_COMMENT "2.16.840.1.113730.1.13"
  3352. //+-------------------------------------------------------------------------
  3353. // Netscape Certificate Data Type Object Identifiers
  3354. //--------------------------------------------------------------------------
  3355. #define szOID_NETSCAPE_DATA_TYPE "2.16.840.1.113730.2"
  3356. #define szOID_NETSCAPE_CERT_SEQUENCE "2.16.840.1.113730.2.5"
  3357. //+-------------------------------------------------------------------------
  3358. // szOID_NETSCAPE_CERT_TYPE extension
  3359. //
  3360. // Its value is a bit string. CryptDecodeObject/CryptEncodeObject using
  3361. // X509_BITS or X509_BITS_WITHOUT_TRAILING_ZEROES.
  3362. //
  3363. // The following bits are defined:
  3364. //--------------------------------------------------------------------------
  3365. #define NETSCAPE_SSL_CLIENT_AUTH_CERT_TYPE 0x80
  3366. #define NETSCAPE_SSL_SERVER_AUTH_CERT_TYPE 0x40
  3367. #define NETSCAPE_SMIME_CERT_TYPE 0x20
  3368. #define NETSCAPE_SIGN_CERT_TYPE 0x10
  3369. #define NETSCAPE_SSL_CA_CERT_TYPE 0x04
  3370. #define NETSCAPE_SMIME_CA_CERT_TYPE 0x02
  3371. #define NETSCAPE_SIGN_CA_CERT_TYPE 0x01
  3372. //+-------------------------------------------------------------------------
  3373. // szOID_NETSCAPE_BASE_URL extension
  3374. //
  3375. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3376. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3377. // dwValueType = CERT_RDN_IA5_STRING.
  3378. //
  3379. // When present this string is added to the beginning of all relative URLs
  3380. // in the certificate. This extension can be considered an optimization
  3381. // to reduce the size of the URL extensions.
  3382. //--------------------------------------------------------------------------
  3383. //+-------------------------------------------------------------------------
  3384. // szOID_NETSCAPE_REVOCATION_URL extension
  3385. //
  3386. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3387. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3388. // dwValueType = CERT_RDN_IA5_STRING.
  3389. //
  3390. // It is a relative or absolute URL that can be used to check the
  3391. // revocation status of a certificate. The revocation check will be
  3392. // performed as an HTTP GET method using a url that is the concatenation of
  3393. // revocation-url and certificate-serial-number.
  3394. // Where the certificate-serial-number is encoded as a string of
  3395. // ascii hexadecimal digits. For example, if the netscape-base-url is
  3396. // https://www.certs-r-us.com/, the netscape-revocation-url is
  3397. // cgi-bin/check-rev.cgi?, and the certificate serial number is 173420,
  3398. // the resulting URL would be:
  3399. // https://www.certs-r-us.com/cgi-bin/check-rev.cgi?02a56c
  3400. //
  3401. // The server should return a document with a Content-Type of
  3402. // application/x-netscape-revocation. The document should contain
  3403. // a single ascii digit, '1' if the certificate is not curently valid,
  3404. // and '0' if it is curently valid.
  3405. //
  3406. // Note: for all of the URLs that include the certificate serial number,
  3407. // the serial number will be encoded as a string which consists of an even
  3408. // number of hexadecimal digits. If the number of significant digits is odd,
  3409. // the string will have a single leading zero to ensure an even number of
  3410. // digits is generated.
  3411. //--------------------------------------------------------------------------
  3412. //+-------------------------------------------------------------------------
  3413. // szOID_NETSCAPE_CA_REVOCATION_URL extension
  3414. //
  3415. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3416. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3417. // dwValueType = CERT_RDN_IA5_STRING.
  3418. //
  3419. // It is a relative or absolute URL that can be used to check the
  3420. // revocation status of any certificates that are signed by the CA that
  3421. // this certificate belongs to. This extension is only valid in CA
  3422. // certificates. The use of this extension is the same as the above
  3423. // szOID_NETSCAPE_REVOCATION_URL extension.
  3424. //--------------------------------------------------------------------------
  3425. //+-------------------------------------------------------------------------
  3426. // szOID_NETSCAPE_CERT_RENEWAL_URL extension
  3427. //
  3428. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3429. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3430. // dwValueType = CERT_RDN_IA5_STRING.
  3431. //
  3432. // It is a relative or absolute URL that points to a certificate renewal
  3433. // form. The renewal form will be accessed with an HTTP GET method using a
  3434. // url that is the concatenation of renewal-url and
  3435. // certificate-serial-number. Where the certificate-serial-number is
  3436. // encoded as a string of ascii hexadecimal digits. For example, if the
  3437. // netscape-base-url is https://www.certs-r-us.com/, the
  3438. // netscape-cert-renewal-url is cgi-bin/check-renew.cgi?, and the
  3439. // certificate serial number is 173420, the resulting URL would be:
  3440. // https://www.certs-r-us.com/cgi-bin/check-renew.cgi?02a56c
  3441. // The document returned should be an HTML form that will allow the user
  3442. // to request a renewal of their certificate.
  3443. //--------------------------------------------------------------------------
  3444. //+-------------------------------------------------------------------------
  3445. // szOID_NETSCAPE_CA_POLICY_URL extension
  3446. //
  3447. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3448. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3449. // dwValueType = CERT_RDN_IA5_STRING.
  3450. //
  3451. // It is a relative or absolute URL that points to a web page that
  3452. // describes the policies under which the certificate was issued.
  3453. //--------------------------------------------------------------------------
  3454. //+-------------------------------------------------------------------------
  3455. // szOID_NETSCAPE_SSL_SERVER_NAME extension
  3456. //
  3457. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3458. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3459. // dwValueType = CERT_RDN_IA5_STRING.
  3460. //
  3461. // It is a "shell expression" that can be used to match the hostname of the
  3462. // SSL server that is using this certificate. It is recommended that if
  3463. // the server's hostname does not match this pattern the user be notified
  3464. // and given the option to terminate the SSL connection. If this extension
  3465. // is not present then the CommonName in the certificate subject's
  3466. // distinguished name is used for the same purpose.
  3467. //--------------------------------------------------------------------------
  3468. //+-------------------------------------------------------------------------
  3469. // szOID_NETSCAPE_COMMENT extension
  3470. //
  3471. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3472. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3473. // dwValueType = CERT_RDN_IA5_STRING.
  3474. //
  3475. // It is a comment that may be displayed to the user when the certificate
  3476. // is viewed.
  3477. //--------------------------------------------------------------------------
  3478. //+-------------------------------------------------------------------------
  3479. // szOID_NETSCAPE_CERT_SEQUENCE
  3480. //
  3481. // Its value is a PKCS#7 ContentInfo structure wrapping a sequence of
  3482. // certificates. The value of the contentType field is
  3483. // szOID_NETSCAPE_CERT_SEQUENCE, while the content field is the following
  3484. // structure:
  3485. // CertificateSequence ::= SEQUENCE OF Certificate.
  3486. //
  3487. // CryptDecodeObject/CryptEncodeObject using
  3488. // PKCS_CONTENT_INFO_SEQUENCE_OF_ANY, where,
  3489. // pszObjId = szOID_NETSCAPE_CERT_SEQUENCE and the CRYPT_DER_BLOBs point
  3490. // to encoded X509 certificates.
  3491. //--------------------------------------------------------------------------
  3492. //+=========================================================================
  3493. // Certificate Management Messages over CMS (CMC) Data Structures
  3494. //==========================================================================
  3495. // Content Type (request)
  3496. #define szOID_CT_PKI_DATA "1.3.6.1.5.5.7.12.2"
  3497. // Content Type (response)
  3498. #define szOID_CT_PKI_RESPONSE "1.3.6.1.5.5.7.12.3"
  3499. // Signature value that only contains the hash octets. The parameters for
  3500. // this algorithm must be present and must be encoded as NULL.
  3501. #define szOID_PKIX_NO_SIGNATURE "1.3.6.1.5.5.7.6.2"
  3502. #define szOID_CMC "1.3.6.1.5.5.7.7"
  3503. #define szOID_CMC_STATUS_INFO "1.3.6.1.5.5.7.7.1"
  3504. #define szOID_CMC_IDENTIFICATION "1.3.6.1.5.5.7.7.2"
  3505. #define szOID_CMC_IDENTITY_PROOF "1.3.6.1.5.5.7.7.3"
  3506. #define szOID_CMC_DATA_RETURN "1.3.6.1.5.5.7.7.4"
  3507. // Transaction Id (integer)
  3508. #define szOID_CMC_TRANSACTION_ID "1.3.6.1.5.5.7.7.5"
  3509. // Sender Nonce (octet string)
  3510. #define szOID_CMC_SENDER_NONCE "1.3.6.1.5.5.7.7.6"
  3511. // Recipient Nonce (octet string)
  3512. #define szOID_CMC_RECIPIENT_NONCE "1.3.6.1.5.5.7.7.7"
  3513. #define szOID_CMC_ADD_EXTENSIONS "1.3.6.1.5.5.7.7.8"
  3514. #define szOID_CMC_ENCRYPTED_POP "1.3.6.1.5.5.7.7.9"
  3515. #define szOID_CMC_DECRYPTED_POP "1.3.6.1.5.5.7.7.10"
  3516. #define szOID_CMC_LRA_POP_WITNESS "1.3.6.1.5.5.7.7.11"
  3517. // Issuer Name + Serial
  3518. #define szOID_CMC_GET_CERT "1.3.6.1.5.5.7.7.15"
  3519. // Issuer Name [+ CRL Name] + Time [+ Reasons]
  3520. #define szOID_CMC_GET_CRL "1.3.6.1.5.5.7.7.16"
  3521. // Issuer Name + Serial [+ Reason] [+ Effective Time] [+ Secret] [+ Comment]
  3522. #define szOID_CMC_REVOKE_REQUEST "1.3.6.1.5.5.7.7.17"
  3523. // (octet string) URL-style parameter list (IA5?)
  3524. #define szOID_CMC_REG_INFO "1.3.6.1.5.5.7.7.18"
  3525. #define szOID_CMC_RESPONSE_INFO "1.3.6.1.5.5.7.7.19"
  3526. // (octet string)
  3527. #define szOID_CMC_QUERY_PENDING "1.3.6.1.5.5.7.7.21"
  3528. #define szOID_CMC_ID_POP_LINK_RANDOM "1.3.6.1.5.5.7.7.22"
  3529. #define szOID_CMC_ID_POP_LINK_WITNESS "1.3.6.1.5.5.7.7.23"
  3530. // optional Name + Integer
  3531. #define szOID_CMC_ID_CONFIRM_CERT_ACCEPTANCE "1.3.6.1.5.5.7.7.24"
  3532. #define szOID_CMC_ADD_ATTRIBUTES "1.3.6.1.4.1.311.10.10.1"
  3533. //+-------------------------------------------------------------------------
  3534. // CMC_DATA
  3535. // CMC_RESPONSE
  3536. //
  3537. // Certificate Management Messages over CMS (CMC) PKIData and Response
  3538. // messages.
  3539. //
  3540. // For CMC_DATA, pvStructInfo points to a CMC_DATA_INFO.
  3541. // CMC_DATA_INFO contains optional arrays of tagged attributes, requests,
  3542. // content info and/or arbitrary other messages.
  3543. //
  3544. // For CMC_RESPONSE, pvStructInfo points to a CMC_RESPONSE_INFO.
  3545. // CMC_RESPONSE_INFO is the same as CMC_DATA_INFO without the tagged
  3546. // requests.
  3547. //--------------------------------------------------------------------------
  3548. typedef struct _CMC_TAGGED_ATTRIBUTE {
  3549. DWORD dwBodyPartID;
  3550. CRYPT_ATTRIBUTE Attribute;
  3551. } CMC_TAGGED_ATTRIBUTE, *PCMC_TAGGED_ATTRIBUTE;
  3552. typedef struct _CMC_TAGGED_CERT_REQUEST {
  3553. DWORD dwBodyPartID;
  3554. CRYPT_DER_BLOB SignedCertRequest;
  3555. } CMC_TAGGED_CERT_REQUEST, *PCMC_TAGGED_CERT_REQUEST;
  3556. typedef struct _CMC_TAGGED_REQUEST {
  3557. DWORD dwTaggedRequestChoice;
  3558. union {
  3559. // CMC_TAGGED_CERT_REQUEST_CHOICE
  3560. PCMC_TAGGED_CERT_REQUEST pTaggedCertRequest;
  3561. };
  3562. } CMC_TAGGED_REQUEST, *PCMC_TAGGED_REQUEST;
  3563. #define CMC_TAGGED_CERT_REQUEST_CHOICE 1
  3564. typedef struct _CMC_TAGGED_CONTENT_INFO {
  3565. DWORD dwBodyPartID;
  3566. CRYPT_DER_BLOB EncodedContentInfo;
  3567. } CMC_TAGGED_CONTENT_INFO, *PCMC_TAGGED_CONTENT_INFO;
  3568. typedef struct _CMC_TAGGED_OTHER_MSG {
  3569. DWORD dwBodyPartID;
  3570. LPSTR pszObjId;
  3571. CRYPT_OBJID_BLOB Value;
  3572. } CMC_TAGGED_OTHER_MSG, *PCMC_TAGGED_OTHER_MSG;
  3573. // All the tagged arrays are optional
  3574. typedef struct _CMC_DATA_INFO {
  3575. DWORD cTaggedAttribute;
  3576. PCMC_TAGGED_ATTRIBUTE rgTaggedAttribute;
  3577. DWORD cTaggedRequest;
  3578. PCMC_TAGGED_REQUEST rgTaggedRequest;
  3579. DWORD cTaggedContentInfo;
  3580. PCMC_TAGGED_CONTENT_INFO rgTaggedContentInfo;
  3581. DWORD cTaggedOtherMsg;
  3582. PCMC_TAGGED_OTHER_MSG rgTaggedOtherMsg;
  3583. } CMC_DATA_INFO, *PCMC_DATA_INFO;
  3584. // All the tagged arrays are optional
  3585. typedef struct _CMC_RESPONSE_INFO {
  3586. DWORD cTaggedAttribute;
  3587. PCMC_TAGGED_ATTRIBUTE rgTaggedAttribute;
  3588. DWORD cTaggedContentInfo;
  3589. PCMC_TAGGED_CONTENT_INFO rgTaggedContentInfo;
  3590. DWORD cTaggedOtherMsg;
  3591. PCMC_TAGGED_OTHER_MSG rgTaggedOtherMsg;
  3592. } CMC_RESPONSE_INFO, *PCMC_RESPONSE_INFO;
  3593. //+-------------------------------------------------------------------------
  3594. // CMC_STATUS
  3595. //
  3596. // Certificate Management Messages over CMS (CMC) Status.
  3597. //
  3598. // pvStructInfo points to a CMC_STATUS_INFO.
  3599. //--------------------------------------------------------------------------
  3600. typedef struct _CMC_PEND_INFO {
  3601. CRYPT_DATA_BLOB PendToken;
  3602. FILETIME PendTime;
  3603. } CMC_PEND_INFO, *PCMC_PEND_INFO;
  3604. typedef struct _CMC_STATUS_INFO {
  3605. DWORD dwStatus;
  3606. DWORD cBodyList;
  3607. DWORD *rgdwBodyList;
  3608. LPWSTR pwszStatusString; // OPTIONAL
  3609. DWORD dwOtherInfoChoice;
  3610. union {
  3611. // CMC_OTHER_INFO_NO_CHOICE
  3612. // none
  3613. // CMC_OTHER_INFO_FAIL_CHOICE
  3614. DWORD dwFailInfo;
  3615. // CMC_OTHER_INFO_PEND_CHOICE
  3616. PCMC_PEND_INFO pPendInfo;
  3617. };
  3618. } CMC_STATUS_INFO, *PCMC_STATUS_INFO;
  3619. #define CMC_OTHER_INFO_NO_CHOICE 0
  3620. #define CMC_OTHER_INFO_FAIL_CHOICE 1
  3621. #define CMC_OTHER_INFO_PEND_CHOICE 2
  3622. //
  3623. // dwStatus values
  3624. //
  3625. // Request was granted
  3626. #define CMC_STATUS_SUCCESS 0
  3627. // Request failed, more information elsewhere in the message
  3628. #define CMC_STATUS_FAILED 2
  3629. // The request body part has not yet been processed. Requester is responsible
  3630. // to poll back. May only be returned for certificate request operations.
  3631. #define CMC_STATUS_PENDING 3
  3632. // The requested operation is not supported
  3633. #define CMC_STATUS_NO_SUPPORT 4
  3634. // Confirmation using the idConfirmCertAcceptance control is required
  3635. // before use of certificate
  3636. #define CMC_STATUS_CONFIRM_REQUIRED 5
  3637. //
  3638. // dwFailInfo values
  3639. //
  3640. // Unrecognized or unsupported algorithm
  3641. #define CMC_FAIL_BAD_ALG 0
  3642. // Integrity check failed
  3643. #define CMC_FAIL_BAD_MESSAGE_CHECK 1
  3644. // Transaction not permitted or supported
  3645. #define CMC_FAIL_BAD_REQUEST 2
  3646. // Message time field was not sufficiently close to the system time
  3647. #define CMC_FAIL_BAD_TIME 3
  3648. // No certificate could be identified matching the provided criteria
  3649. #define CMC_FAIL_BAD_CERT_ID 4
  3650. // A requested X.509 extension is not supported by the recipient CA.
  3651. #define CMC_FAIL_UNSUPORTED_EXT 5
  3652. // Private key material must be supplied
  3653. #define CMC_FAIL_MUST_ARCHIVE_KEYS 6
  3654. // Identification Attribute failed to verify
  3655. #define CMC_FAIL_BAD_IDENTITY 7
  3656. // Server requires a POP proof before issuing certificate
  3657. #define CMC_FAIL_POP_REQUIRED 8
  3658. // POP processing failed
  3659. #define CMC_FAIL_POP_FAILED 9
  3660. // Server policy does not allow key re-use
  3661. #define CMC_FAIL_NO_KEY_REUSE 10
  3662. #define CMC_FAIL_INTERNAL_CA_ERROR 11
  3663. #define CMC_FAIL_TRY_LATER 12
  3664. //+-------------------------------------------------------------------------
  3665. // CMC_ADD_EXTENSIONS
  3666. //
  3667. // Certificate Management Messages over CMS (CMC) Add Extensions control
  3668. // attribute.
  3669. //
  3670. // pvStructInfo points to a CMC_ADD_EXTENSIONS_INFO.
  3671. //--------------------------------------------------------------------------
  3672. typedef struct _CMC_ADD_EXTENSIONS_INFO {
  3673. DWORD dwCmcDataReference;
  3674. DWORD cCertReference;
  3675. DWORD *rgdwCertReference;
  3676. DWORD cExtension;
  3677. PCERT_EXTENSION rgExtension;
  3678. } CMC_ADD_EXTENSIONS_INFO, *PCMC_ADD_EXTENSIONS_INFO;
  3679. //+-------------------------------------------------------------------------
  3680. // CMC_ADD_ATTRIBUTES
  3681. //
  3682. // Certificate Management Messages over CMS (CMC) Add Attributes control
  3683. // attribute.
  3684. //
  3685. // pvStructInfo points to a CMC_ADD_ATTRIBUTES_INFO.
  3686. //--------------------------------------------------------------------------
  3687. typedef struct _CMC_ADD_ATTRIBUTES_INFO {
  3688. DWORD dwCmcDataReference;
  3689. DWORD cCertReference;
  3690. DWORD *rgdwCertReference;
  3691. DWORD cAttribute;
  3692. PCRYPT_ATTRIBUTE rgAttribute;
  3693. } CMC_ADD_ATTRIBUTES_INFO, *PCMC_ADD_ATTRIBUTES_INFO;
  3694. //+-------------------------------------------------------------------------
  3695. // X509_CERTIFICATE_TEMPLATE
  3696. // szOID_CERTIFICATE_TEMPLATE
  3697. //
  3698. // pvStructInfo points to following CERT_TEMPLATE_EXT data structure.
  3699. //
  3700. //--------------------------------------------------------------------------
  3701. typedef struct _CERT_TEMPLATE_EXT {
  3702. LPSTR pszObjId;
  3703. DWORD dwMajorVersion;
  3704. BOOL fMinorVersion; // TRUE for a minor version
  3705. DWORD dwMinorVersion;
  3706. } CERT_TEMPLATE_EXT, *PCERT_TEMPLATE_EXT;
  3707. //+=========================================================================
  3708. // Object IDentifier (OID) Installable Functions: Data Structures and APIs
  3709. //==========================================================================
  3710. typedef void *HCRYPTOIDFUNCSET;
  3711. typedef void *HCRYPTOIDFUNCADDR;
  3712. // Predefined OID Function Names
  3713. #define CRYPT_OID_ENCODE_OBJECT_FUNC "CryptDllEncodeObject"
  3714. #define CRYPT_OID_DECODE_OBJECT_FUNC "CryptDllDecodeObject"
  3715. #define CRYPT_OID_ENCODE_OBJECT_EX_FUNC "CryptDllEncodeObjectEx"
  3716. #define CRYPT_OID_DECODE_OBJECT_EX_FUNC "CryptDllDecodeObjectEx"
  3717. #define CRYPT_OID_CREATE_COM_OBJECT_FUNC "CryptDllCreateCOMObject"
  3718. #define CRYPT_OID_VERIFY_REVOCATION_FUNC "CertDllVerifyRevocation"
  3719. #define CRYPT_OID_VERIFY_CTL_USAGE_FUNC "CertDllVerifyCTLUsage"
  3720. #define CRYPT_OID_FORMAT_OBJECT_FUNC "CryptDllFormatObject"
  3721. #define CRYPT_OID_FIND_OID_INFO_FUNC "CryptDllFindOIDInfo"
  3722. #define CRYPT_OID_FIND_LOCALIZED_NAME_FUNC "CryptDllFindLocalizedName"
  3723. // CryptDllEncodeObject has same function signature as CryptEncodeObject.
  3724. // CryptDllDecodeObject has same function signature as CryptDecodeObject.
  3725. // CryptDllEncodeObjectEx has same function signature as CryptEncodeObjectEx.
  3726. // The Ex version MUST support the CRYPT_ENCODE_ALLOC_FLAG option.
  3727. //
  3728. // If an Ex function isn't installed or registered, then, attempts to find
  3729. // a non-EX version. If the ALLOC flag is set, then, CryptEncodeObjectEx,
  3730. // does the allocation and calls the non-EX version twice.
  3731. // CryptDllDecodeObjectEx has same function signature as CryptDecodeObjectEx.
  3732. // The Ex version MUST support the CRYPT_DECODE_ALLOC_FLAG option.
  3733. //
  3734. // If an Ex function isn't installed or registered, then, attempts to find
  3735. // a non-EX version. If the ALLOC flag is set, then, CryptDecodeObjectEx,
  3736. // does the allocation and calls the non-EX version twice.
  3737. // CryptDllCreateCOMObject has the following signature:
  3738. // BOOL WINAPI CryptDllCreateCOMObject(
  3739. // IN DWORD dwEncodingType,
  3740. // IN LPCSTR pszOID,
  3741. // IN PCRYPT_DATA_BLOB pEncodedContent,
  3742. // IN DWORD dwFlags,
  3743. // IN REFIID riid,
  3744. // OUT void **ppvObj);
  3745. // CertDllVerifyRevocation has the same signature as CertVerifyRevocation
  3746. // (See CertVerifyRevocation for details on when called)
  3747. // CertDllVerifyCTLUsage has the same signature as CertVerifyCTLUsage
  3748. // CryptDllFindOIDInfo currently is only used to store values used by
  3749. // CryptFindOIDInfo. See CryptFindOIDInfo() for more details.
  3750. // CryptDllFindLocalizedName is only used to store localized string
  3751. // values used by CryptFindLocalizedName. See CryptFindLocalizedName() for
  3752. // more details.
  3753. // Example of a complete OID Function Registry Name:
  3754. // HKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography\OID
  3755. // Encoding Type 1\CryptDllEncodeObject\1.2.3
  3756. //
  3757. // The key's L"Dll" value contains the name of the Dll.
  3758. // The key's L"FuncName" value overrides the default function name
  3759. #define CRYPT_OID_REGPATH "Software\\Microsoft\\Cryptography\\OID"
  3760. #define CRYPT_OID_REG_ENCODING_TYPE_PREFIX "EncodingType "
  3761. #define CRYPT_OID_REG_DLL_VALUE_NAME L"Dll"
  3762. #define CRYPT_OID_REG_FUNC_NAME_VALUE_NAME L"FuncName"
  3763. #define CRYPT_OID_REG_FUNC_NAME_VALUE_NAME_A "FuncName"
  3764. // CRYPT_INSTALL_OID_FUNC_BEFORE_FLAG can be set in the key's L"CryptFlags"
  3765. // value to register the functions before the installed functions.
  3766. //
  3767. // CryptSetOIDFunctionValue must be called to set this value. L"CryptFlags"
  3768. // must be set using a dwValueType of REG_DWORD.
  3769. #define CRYPT_OID_REG_FLAGS_VALUE_NAME L"CryptFlags"
  3770. // OID used for Default OID functions
  3771. #define CRYPT_DEFAULT_OID "DEFAULT"
  3772. typedef struct _CRYPT_OID_FUNC_ENTRY {
  3773. LPCSTR pszOID;
  3774. void *pvFuncAddr;
  3775. } CRYPT_OID_FUNC_ENTRY, *PCRYPT_OID_FUNC_ENTRY;
  3776. #define CRYPT_INSTALL_OID_FUNC_BEFORE_FLAG 1
  3777. //+-------------------------------------------------------------------------
  3778. // Install a set of callable OID function addresses.
  3779. //
  3780. // By default the functions are installed at end of the list.
  3781. // Set CRYPT_INSTALL_OID_FUNC_BEFORE_FLAG to install at beginning of list.
  3782. //
  3783. // hModule should be updated with the hModule passed to DllMain to prevent
  3784. // the Dll containing the function addresses from being unloaded by
  3785. // CryptGetOIDFuncAddress/CryptFreeOIDFunctionAddress. This would be the
  3786. // case when the Dll has also regsvr32'ed OID functions via
  3787. // CryptRegisterOIDFunction.
  3788. //
  3789. // DEFAULT functions are installed by setting rgFuncEntry[].pszOID =
  3790. // CRYPT_DEFAULT_OID.
  3791. //--------------------------------------------------------------------------
  3792. WINCRYPT32API
  3793. BOOL
  3794. WINAPI
  3795. CryptInstallOIDFunctionAddress(
  3796. IN HMODULE hModule, // hModule passed to DllMain
  3797. IN DWORD dwEncodingType,
  3798. IN LPCSTR pszFuncName,
  3799. IN DWORD cFuncEntry,
  3800. IN const CRYPT_OID_FUNC_ENTRY rgFuncEntry[],
  3801. IN DWORD dwFlags
  3802. );
  3803. //+-------------------------------------------------------------------------
  3804. // Initialize and return handle to the OID function set identified by its
  3805. // function name.
  3806. //
  3807. // If the set already exists, a handle to the existing set is returned.
  3808. //--------------------------------------------------------------------------
  3809. WINCRYPT32API
  3810. HCRYPTOIDFUNCSET
  3811. WINAPI
  3812. CryptInitOIDFunctionSet(
  3813. IN LPCSTR pszFuncName,
  3814. IN DWORD dwFlags
  3815. );
  3816. //+-------------------------------------------------------------------------
  3817. // Search the list of installed functions for an encoding type and OID match.
  3818. // If not found, search the registry.
  3819. //
  3820. // For success, returns TRUE with *ppvFuncAddr updated with the function's
  3821. // address and *phFuncAddr updated with the function address's handle.
  3822. // The function's handle is AddRef'ed. CryptFreeOIDFunctionAddress needs to
  3823. // be called to release it.
  3824. //
  3825. // For a registry match, the Dll containing the function is loaded.
  3826. //
  3827. // By default, both the registered and installed function lists are searched.
  3828. // Set CRYPT_GET_INSTALLED_OID_FUNC_FLAG to only search the installed list
  3829. // of functions. This flag would be set by a registered function to get
  3830. // the address of a pre-installed function it was replacing. For example,
  3831. // the registered function might handle a new special case and call the
  3832. // pre-installed function to handle the remaining cases.
  3833. //--------------------------------------------------------------------------
  3834. WINCRYPT32API
  3835. BOOL
  3836. WINAPI
  3837. CryptGetOIDFunctionAddress(
  3838. IN HCRYPTOIDFUNCSET hFuncSet,
  3839. IN DWORD dwEncodingType,
  3840. IN LPCSTR pszOID,
  3841. IN DWORD dwFlags,
  3842. OUT void **ppvFuncAddr,
  3843. OUT HCRYPTOIDFUNCADDR *phFuncAddr
  3844. );
  3845. #define CRYPT_GET_INSTALLED_OID_FUNC_FLAG 0x1
  3846. //+-------------------------------------------------------------------------
  3847. // Get the list of registered default Dll entries for the specified
  3848. // function set and encoding type.
  3849. //
  3850. // The returned list consists of none, one or more null terminated Dll file
  3851. // names. The list is terminated with an empty (L"\0") Dll file name.
  3852. // For example: L"first.dll" L"\0" L"second.dll" L"\0" L"\0"
  3853. //--------------------------------------------------------------------------
  3854. WINCRYPT32API
  3855. BOOL
  3856. WINAPI
  3857. CryptGetDefaultOIDDllList(
  3858. IN HCRYPTOIDFUNCSET hFuncSet,
  3859. IN DWORD dwEncodingType,
  3860. OUT LPWSTR pwszDllList,
  3861. IN OUT DWORD *pcchDllList
  3862. );
  3863. //+-------------------------------------------------------------------------
  3864. // Either: get the first or next installed DEFAULT function OR
  3865. // load the Dll containing the DEFAULT function.
  3866. //
  3867. // If pwszDll is NULL, search the list of installed DEFAULT functions.
  3868. // *phFuncAddr must be set to NULL to get the first installed function.
  3869. // Successive installed functions are returned by setting *phFuncAddr
  3870. // to the hFuncAddr returned by the previous call.
  3871. //
  3872. // If pwszDll is NULL, the input *phFuncAddr
  3873. // is always CryptFreeOIDFunctionAddress'ed by this function, even for
  3874. // an error.
  3875. //
  3876. // If pwszDll isn't NULL, then, attempts to load the Dll and the DEFAULT
  3877. // function. *phFuncAddr is ignored upon entry and isn't
  3878. // CryptFreeOIDFunctionAddress'ed.
  3879. //
  3880. // For success, returns TRUE with *ppvFuncAddr updated with the function's
  3881. // address and *phFuncAddr updated with the function address's handle.
  3882. // The function's handle is AddRef'ed. CryptFreeOIDFunctionAddress needs to
  3883. // be called to release it or CryptGetDefaultOIDFunctionAddress can also
  3884. // be called for a NULL pwszDll.
  3885. //--------------------------------------------------------------------------
  3886. WINCRYPT32API
  3887. BOOL
  3888. WINAPI
  3889. CryptGetDefaultOIDFunctionAddress(
  3890. IN HCRYPTOIDFUNCSET hFuncSet,
  3891. IN DWORD dwEncodingType,
  3892. IN OPTIONAL LPCWSTR pwszDll,
  3893. IN DWORD dwFlags,
  3894. OUT void **ppvFuncAddr,
  3895. IN OUT HCRYPTOIDFUNCADDR *phFuncAddr
  3896. );
  3897. //+-------------------------------------------------------------------------
  3898. // Releases the handle AddRef'ed and returned by CryptGetOIDFunctionAddress
  3899. // or CryptGetDefaultOIDFunctionAddress.
  3900. //
  3901. // If a Dll was loaded for the function its unloaded. However, before doing
  3902. // the unload, the DllCanUnloadNow function exported by the loaded Dll is
  3903. // called. It should return S_FALSE to inhibit the unload or S_TRUE to enable
  3904. // the unload. If the Dll doesn't export DllCanUnloadNow, the Dll is unloaded.
  3905. //
  3906. // DllCanUnloadNow has the following signature:
  3907. // STDAPI DllCanUnloadNow(void);
  3908. //--------------------------------------------------------------------------
  3909. WINCRYPT32API
  3910. BOOL
  3911. WINAPI
  3912. CryptFreeOIDFunctionAddress(
  3913. IN HCRYPTOIDFUNCADDR hFuncAddr,
  3914. IN DWORD dwFlags
  3915. );
  3916. //+-------------------------------------------------------------------------
  3917. // Register the Dll containing the function to be called for the specified
  3918. // encoding type, function name and OID.
  3919. //
  3920. // pwszDll may contain environment-variable strings
  3921. // which are ExpandEnvironmentStrings()'ed before loading the Dll.
  3922. //
  3923. // In addition to registering the DLL, you may override the
  3924. // name of the function to be called. For example,
  3925. // pszFuncName = "CryptDllEncodeObject",
  3926. // pszOverrideFuncName = "MyEncodeXyz".
  3927. // This allows a Dll to export multiple OID functions for the same
  3928. // function name without needing to interpose its own OID dispatcher function.
  3929. //--------------------------------------------------------------------------
  3930. WINCRYPT32API
  3931. BOOL
  3932. WINAPI
  3933. CryptRegisterOIDFunction(
  3934. IN DWORD dwEncodingType,
  3935. IN LPCSTR pszFuncName,
  3936. IN LPCSTR pszOID,
  3937. IN OPTIONAL LPCWSTR pwszDll,
  3938. IN OPTIONAL LPCSTR pszOverrideFuncName
  3939. );
  3940. //+-------------------------------------------------------------------------
  3941. // Unregister the Dll containing the function to be called for the specified
  3942. // encoding type, function name and OID.
  3943. //--------------------------------------------------------------------------
  3944. WINCRYPT32API
  3945. BOOL
  3946. WINAPI
  3947. CryptUnregisterOIDFunction(
  3948. IN DWORD dwEncodingType,
  3949. IN LPCSTR pszFuncName,
  3950. IN LPCSTR pszOID
  3951. );
  3952. //+-------------------------------------------------------------------------
  3953. // Register the Dll containing the default function to be called for the
  3954. // specified encoding type and function name.
  3955. //
  3956. // Unlike CryptRegisterOIDFunction, you can't override the function name
  3957. // needing to be exported by the Dll.
  3958. //
  3959. // The Dll is inserted before the entry specified by dwIndex.
  3960. // dwIndex == 0, inserts at the beginning.
  3961. // dwIndex == CRYPT_REGISTER_LAST_INDEX, appends at the end.
  3962. //
  3963. // pwszDll may contain environment-variable strings
  3964. // which are ExpandEnvironmentStrings()'ed before loading the Dll.
  3965. //--------------------------------------------------------------------------
  3966. WINCRYPT32API
  3967. BOOL
  3968. WINAPI
  3969. CryptRegisterDefaultOIDFunction(
  3970. IN DWORD dwEncodingType,
  3971. IN LPCSTR pszFuncName,
  3972. IN DWORD dwIndex,
  3973. IN LPCWSTR pwszDll
  3974. );
  3975. #define CRYPT_REGISTER_FIRST_INDEX 0
  3976. #define CRYPT_REGISTER_LAST_INDEX 0xFFFFFFFF
  3977. //+-------------------------------------------------------------------------
  3978. // Unregister the Dll containing the default function to be called for
  3979. // the specified encoding type and function name.
  3980. //--------------------------------------------------------------------------
  3981. WINCRYPT32API
  3982. BOOL
  3983. WINAPI
  3984. CryptUnregisterDefaultOIDFunction(
  3985. IN DWORD dwEncodingType,
  3986. IN LPCSTR pszFuncName,
  3987. IN LPCWSTR pwszDll
  3988. );
  3989. //+-------------------------------------------------------------------------
  3990. // Set the value for the specified encoding type, function name, OID and
  3991. // value name.
  3992. //
  3993. // See RegSetValueEx for the possible value types.
  3994. //
  3995. // String types are UNICODE.
  3996. //--------------------------------------------------------------------------
  3997. WINCRYPT32API
  3998. BOOL
  3999. WINAPI
  4000. CryptSetOIDFunctionValue(
  4001. IN DWORD dwEncodingType,
  4002. IN LPCSTR pszFuncName,
  4003. IN LPCSTR pszOID,
  4004. IN LPCWSTR pwszValueName,
  4005. IN DWORD dwValueType,
  4006. IN const BYTE *pbValueData,
  4007. IN DWORD cbValueData
  4008. );
  4009. //+-------------------------------------------------------------------------
  4010. // Get the value for the specified encoding type, function name, OID and
  4011. // value name.
  4012. //
  4013. // See RegEnumValue for the possible value types.
  4014. //
  4015. // String types are UNICODE.
  4016. //--------------------------------------------------------------------------
  4017. WINCRYPT32API
  4018. BOOL
  4019. WINAPI
  4020. CryptGetOIDFunctionValue(
  4021. IN DWORD dwEncodingType,
  4022. IN LPCSTR pszFuncName,
  4023. IN LPCSTR pszOID,
  4024. IN LPCWSTR pwszValueName,
  4025. OUT DWORD *pdwValueType,
  4026. OUT BYTE *pbValueData,
  4027. IN OUT DWORD *pcbValueData
  4028. );
  4029. typedef BOOL (WINAPI *PFN_CRYPT_ENUM_OID_FUNC)(
  4030. IN DWORD dwEncodingType,
  4031. IN LPCSTR pszFuncName,
  4032. IN LPCSTR pszOID,
  4033. IN DWORD cValue,
  4034. IN const DWORD rgdwValueType[],
  4035. IN LPCWSTR const rgpwszValueName[],
  4036. IN const BYTE * const rgpbValueData[],
  4037. IN const DWORD rgcbValueData[],
  4038. IN void *pvArg
  4039. );
  4040. //+-------------------------------------------------------------------------
  4041. // Enumerate the OID functions identified by their encoding type,
  4042. // function name and OID.
  4043. //
  4044. // pfnEnumOIDFunc is called for each registry key matching the input
  4045. // parameters. Setting dwEncodingType to CRYPT_MATCH_ANY_ENCODING_TYPE matches
  4046. // any. Setting pszFuncName or pszOID to NULL matches any.
  4047. //
  4048. // Set pszOID == CRYPT_DEFAULT_OID to restrict the enumeration to only the
  4049. // DEFAULT functions
  4050. //
  4051. // String types are UNICODE.
  4052. //--------------------------------------------------------------------------
  4053. WINCRYPT32API
  4054. BOOL
  4055. WINAPI
  4056. CryptEnumOIDFunction(
  4057. IN DWORD dwEncodingType,
  4058. IN OPTIONAL LPCSTR pszFuncName,
  4059. IN OPTIONAL LPCSTR pszOID,
  4060. IN DWORD dwFlags,
  4061. IN void *pvArg,
  4062. IN PFN_CRYPT_ENUM_OID_FUNC pfnEnumOIDFunc
  4063. );
  4064. #define CRYPT_MATCH_ANY_ENCODING_TYPE 0xFFFFFFFF
  4065. //+=========================================================================
  4066. // Object IDentifier (OID) Information: Data Structures and APIs
  4067. //==========================================================================
  4068. //+-------------------------------------------------------------------------
  4069. // OID Information
  4070. //--------------------------------------------------------------------------
  4071. typedef struct _CRYPT_OID_INFO {
  4072. DWORD cbSize;
  4073. LPCSTR pszOID;
  4074. LPCWSTR pwszName;
  4075. DWORD dwGroupId;
  4076. union {
  4077. DWORD dwValue;
  4078. ALG_ID Algid;
  4079. DWORD dwLength;
  4080. };
  4081. CRYPT_DATA_BLOB ExtraInfo;
  4082. } CRYPT_OID_INFO, *PCRYPT_OID_INFO;
  4083. typedef const CRYPT_OID_INFO CCRYPT_OID_INFO, *PCCRYPT_OID_INFO;
  4084. //+-------------------------------------------------------------------------
  4085. // OID Group IDs
  4086. //--------------------------------------------------------------------------
  4087. #define CRYPT_HASH_ALG_OID_GROUP_ID 1
  4088. #define CRYPT_ENCRYPT_ALG_OID_GROUP_ID 2
  4089. #define CRYPT_PUBKEY_ALG_OID_GROUP_ID 3
  4090. #define CRYPT_SIGN_ALG_OID_GROUP_ID 4
  4091. #define CRYPT_RDN_ATTR_OID_GROUP_ID 5
  4092. #define CRYPT_EXT_OR_ATTR_OID_GROUP_ID 6
  4093. #define CRYPT_ENHKEY_USAGE_OID_GROUP_ID 7
  4094. #define CRYPT_POLICY_OID_GROUP_ID 8
  4095. #define CRYPT_TEMPLATE_OID_GROUP_ID 9
  4096. #define CRYPT_LAST_OID_GROUP_ID 9
  4097. #define CRYPT_FIRST_ALG_OID_GROUP_ID CRYPT_HASH_ALG_OID_GROUP_ID
  4098. #define CRYPT_LAST_ALG_OID_GROUP_ID CRYPT_SIGN_ALG_OID_GROUP_ID
  4099. // The CRYPT_*_ALG_OID_GROUP_ID's have an Algid. The CRYPT_RDN_ATTR_OID_GROUP_ID
  4100. // has a dwLength. The CRYPT_EXT_OR_ATTR_OID_GROUP_ID,
  4101. // CRYPT_ENHKEY_USAGE_OID_GROUP_ID, CRYPT_POLICY_OID_GROUP_ID or
  4102. // CRYPT_TEMPLATE_OID_GROUP_ID don't have a dwValue.
  4103. //
  4104. // CRYPT_PUBKEY_ALG_OID_GROUP_ID has the following optional ExtraInfo:
  4105. // DWORD[0] - Flags. CRYPT_OID_INHIBIT_SIGNATURE_FORMAT_FLAG can be set to
  4106. // inhibit the reformatting of the signature before
  4107. // CryptVerifySignature is called or after CryptSignHash
  4108. // is called. CRYPT_OID_USE_PUBKEY_PARA_FOR_PKCS7_FLAG can
  4109. // be set to include the public key algorithm's parameters
  4110. // in the PKCS7's digestEncryptionAlgorithm's parameters.
  4111. // CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG can be set to omit
  4112. // NULL parameters when encoding.
  4113. #define CRYPT_OID_INHIBIT_SIGNATURE_FORMAT_FLAG 0x1
  4114. #define CRYPT_OID_USE_PUBKEY_PARA_FOR_PKCS7_FLAG 0x2
  4115. #define CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG 0x4
  4116. // CRYPT_SIGN_ALG_OID_GROUP_ID has the following optional ExtraInfo:
  4117. // DWORD[0] - Public Key Algid.
  4118. // DWORD[1] - Flags. Same as above for CRYPT_PUBKEY_ALG_OID_GROUP_ID.
  4119. // DWORD[2] - Optional CryptAcquireContext(CRYPT_VERIFYCONTEXT)'s dwProvType.
  4120. // If omitted or 0, uses Public Key Algid to select
  4121. // appropriate dwProvType for signature verification.
  4122. // CRYPT_RDN_ATTR_OID_GROUP_ID has the following optional ExtraInfo:
  4123. // Array of DWORDs:
  4124. // [0 ..] - Null terminated list of acceptable RDN attribute
  4125. // value types. An empty list implies CERT_RDN_PRINTABLE_STRING,
  4126. // CERT_RDN_UNICODE_STRING, 0.
  4127. //+-------------------------------------------------------------------------
  4128. // Find OID information. Returns NULL if unable to find any information
  4129. // for the specified key and group. Note, returns a pointer to a constant
  4130. // data structure. The returned pointer MUST NOT be freed.
  4131. //
  4132. // dwKeyType's:
  4133. // CRYPT_OID_INFO_OID_KEY, pvKey points to a szOID
  4134. // CRYPT_OID_INFO_NAME_KEY, pvKey points to a wszName
  4135. // CRYPT_OID_INFO_ALGID_KEY, pvKey points to an ALG_ID
  4136. // CRYPT_OID_INFO_SIGN_KEY, pvKey points to an array of two ALG_ID's:
  4137. // ALG_ID[0] - Hash Algid
  4138. // ALG_ID[1] - PubKey Algid
  4139. //
  4140. // Setting dwGroupId to 0, searches all groups according to the dwKeyType.
  4141. // Otherwise, only the dwGroupId is searched.
  4142. //--------------------------------------------------------------------------
  4143. WINCRYPT32API
  4144. PCCRYPT_OID_INFO
  4145. WINAPI
  4146. CryptFindOIDInfo(
  4147. IN DWORD dwKeyType,
  4148. IN void *pvKey,
  4149. IN DWORD dwGroupId
  4150. );
  4151. #define CRYPT_OID_INFO_OID_KEY 1
  4152. #define CRYPT_OID_INFO_NAME_KEY 2
  4153. #define CRYPT_OID_INFO_ALGID_KEY 3
  4154. #define CRYPT_OID_INFO_SIGN_KEY 4
  4155. //+-------------------------------------------------------------------------
  4156. // Register OID information. The OID information specified in the
  4157. // CCRYPT_OID_INFO structure is persisted to the registry.
  4158. //
  4159. // crypt32.dll contains information for the commonly known OIDs. This function
  4160. // allows applications to augment crypt32.dll's OID information. During
  4161. // CryptFindOIDInfo's first call, the registered OID information is installed.
  4162. //
  4163. // By default the registered OID information is installed after crypt32.dll's
  4164. // OID entries. Set CRYPT_INSTALL_OID_INFO_BEFORE_FLAG to install before.
  4165. //--------------------------------------------------------------------------
  4166. WINCRYPT32API
  4167. BOOL
  4168. WINAPI
  4169. CryptRegisterOIDInfo(
  4170. IN PCCRYPT_OID_INFO pInfo,
  4171. IN DWORD dwFlags
  4172. );
  4173. #define CRYPT_INSTALL_OID_INFO_BEFORE_FLAG 1
  4174. //+-------------------------------------------------------------------------
  4175. // Unregister OID information. Only the pszOID and dwGroupId fields are
  4176. // used to identify the OID information to be unregistered.
  4177. //--------------------------------------------------------------------------
  4178. WINCRYPT32API
  4179. BOOL
  4180. WINAPI
  4181. CryptUnregisterOIDInfo(
  4182. IN PCCRYPT_OID_INFO pInfo
  4183. );
  4184. // If the callback returns FALSE, stops the enumeration.
  4185. typedef BOOL (WINAPI *PFN_CRYPT_ENUM_OID_INFO)(
  4186. IN PCCRYPT_OID_INFO pInfo,
  4187. IN void *pvArg
  4188. );
  4189. //+-------------------------------------------------------------------------
  4190. // Enumerate the OID information.
  4191. //
  4192. // pfnEnumOIDInfo is called for each OID information entry.
  4193. //
  4194. // Setting dwGroupId to 0 matches all groups. Otherwise, only enumerates
  4195. // entries in the specified group.
  4196. //
  4197. // dwFlags currently isn't used and must be set to 0.
  4198. //--------------------------------------------------------------------------
  4199. WINCRYPT32API
  4200. BOOL
  4201. WINAPI
  4202. CryptEnumOIDInfo(
  4203. IN DWORD dwGroupId,
  4204. IN DWORD dwFlags,
  4205. IN void *pvArg,
  4206. IN PFN_CRYPT_ENUM_OID_INFO pfnEnumOIDInfo
  4207. );
  4208. //+-------------------------------------------------------------------------
  4209. // Find the localized name for the specified name. For example, find the
  4210. // localized name for the "Root" system store name. A case insensitive
  4211. // string comparison is done.
  4212. //
  4213. // Returns NULL if unable to find the the specified name.
  4214. //
  4215. // Localized names for the predefined system stores ("Root", "My") and
  4216. // predefined physical stores (".Default", ".LocalMachine") are pre-installed
  4217. // as resource strings in crypt32.dll. CryptSetOIDFunctionValue can be called
  4218. // as follows to register additional localized strings:
  4219. // dwEncodingType = CRYPT_LOCALIZED_NAME_ENCODING_TYPE
  4220. // pszFuncName = CRYPT_OID_FIND_LOCALIZED_NAME_FUNC
  4221. // pszOID = CRYPT_LOCALIZED_NAME_OID
  4222. // pwszValueName = Name to be localized, for example, L"ApplicationStore"
  4223. // dwValueType = REG_SZ
  4224. // pbValueData = pointer to the UNICODE localized string
  4225. // cbValueData = (wcslen(UNICODE localized string) + 1) * sizeof(WCHAR)
  4226. //
  4227. // To unregister, set pbValueData to NULL and cbValueData to 0.
  4228. //
  4229. // The registered names are searched before the pre-installed names.
  4230. //--------------------------------------------------------------------------
  4231. WINCRYPT32API
  4232. LPCWSTR
  4233. WINAPI
  4234. CryptFindLocalizedName(
  4235. IN LPCWSTR pwszCryptName
  4236. );
  4237. #define CRYPT_LOCALIZED_NAME_ENCODING_TYPE 0
  4238. #define CRYPT_LOCALIZED_NAME_OID "LocalizedNames"
  4239. //+=========================================================================
  4240. // Low Level Cryptographic Message Data Structures and APIs
  4241. //==========================================================================
  4242. typedef void *HCRYPTMSG;
  4243. #define szOID_PKCS_7_DATA "1.2.840.113549.1.7.1"
  4244. #define szOID_PKCS_7_SIGNED "1.2.840.113549.1.7.2"
  4245. #define szOID_PKCS_7_ENVELOPED "1.2.840.113549.1.7.3"
  4246. #define szOID_PKCS_7_SIGNEDANDENVELOPED "1.2.840.113549.1.7.4"
  4247. #define szOID_PKCS_7_DIGESTED "1.2.840.113549.1.7.5"
  4248. #define szOID_PKCS_7_ENCRYPTED "1.2.840.113549.1.7.6"
  4249. #define szOID_PKCS_9_CONTENT_TYPE "1.2.840.113549.1.9.3"
  4250. #define szOID_PKCS_9_MESSAGE_DIGEST "1.2.840.113549.1.9.4"
  4251. //+-------------------------------------------------------------------------
  4252. // Message types
  4253. //--------------------------------------------------------------------------
  4254. #define CMSG_DATA 1
  4255. #define CMSG_SIGNED 2
  4256. #define CMSG_ENVELOPED 3
  4257. #define CMSG_SIGNED_AND_ENVELOPED 4
  4258. #define CMSG_HASHED 5
  4259. #define CMSG_ENCRYPTED 6
  4260. //+-------------------------------------------------------------------------
  4261. // Message Type Bit Flags
  4262. //--------------------------------------------------------------------------
  4263. #define CMSG_ALL_FLAGS (~0UL)
  4264. #define CMSG_DATA_FLAG (1 << CMSG_DATA)
  4265. #define CMSG_SIGNED_FLAG (1 << CMSG_SIGNED)
  4266. #define CMSG_ENVELOPED_FLAG (1 << CMSG_ENVELOPED)
  4267. #define CMSG_SIGNED_AND_ENVELOPED_FLAG (1 << CMSG_SIGNED_AND_ENVELOPED)
  4268. #define CMSG_HASHED_FLAG (1 << CMSG_HASHED)
  4269. #define CMSG_ENCRYPTED_FLAG (1 << CMSG_ENCRYPTED)
  4270. //+-------------------------------------------------------------------------
  4271. // Certificate Issuer and SerialNumber
  4272. //--------------------------------------------------------------------------
  4273. typedef struct _CERT_ISSUER_SERIAL_NUMBER {
  4274. CERT_NAME_BLOB Issuer;
  4275. CRYPT_INTEGER_BLOB SerialNumber;
  4276. } CERT_ISSUER_SERIAL_NUMBER, *PCERT_ISSUER_SERIAL_NUMBER;
  4277. //+-------------------------------------------------------------------------
  4278. // Certificate Identifier
  4279. //--------------------------------------------------------------------------
  4280. typedef struct _CERT_ID {
  4281. DWORD dwIdChoice;
  4282. union {
  4283. // CERT_ID_ISSUER_SERIAL_NUMBER
  4284. CERT_ISSUER_SERIAL_NUMBER IssuerSerialNumber;
  4285. // CERT_ID_KEY_IDENTIFIER
  4286. CRYPT_HASH_BLOB KeyId;
  4287. // CERT_ID_SHA1_HASH
  4288. CRYPT_HASH_BLOB HashId;
  4289. };
  4290. } CERT_ID, *PCERT_ID;
  4291. #define CERT_ID_ISSUER_SERIAL_NUMBER 1
  4292. #define CERT_ID_KEY_IDENTIFIER 2
  4293. #define CERT_ID_SHA1_HASH 3
  4294. //+-------------------------------------------------------------------------
  4295. // The message encode information (pvMsgEncodeInfo) is message type dependent
  4296. //--------------------------------------------------------------------------
  4297. //+-------------------------------------------------------------------------
  4298. // CMSG_DATA: pvMsgEncodeInfo = NULL
  4299. //--------------------------------------------------------------------------
  4300. //+-------------------------------------------------------------------------
  4301. // CMSG_SIGNED
  4302. //
  4303. // The pCertInfo in the CMSG_SIGNER_ENCODE_INFO provides the Issuer, SerialNumber
  4304. // and PublicKeyInfo.Algorithm. The PublicKeyInfo.Algorithm implicitly
  4305. // specifies the HashEncryptionAlgorithm to be used.
  4306. //
  4307. // If the SignerId is present with a nonzero dwIdChoice its used instead
  4308. // of the Issuer and SerialNumber in pCertInfo.
  4309. //
  4310. // CMS supports the KEY_IDENTIFIER and ISSUER_SERIAL_NUMBER CERT_IDs. PKCS #7
  4311. // version 1.5 only supports the ISSUER_SERIAL_NUMBER CERT_ID choice.
  4312. //
  4313. // If HashEncryptionAlgorithm is present and not NULL its used instead of
  4314. // the PublicKeyInfo.Algorithm.
  4315. //
  4316. // Note, for RSA, the hash encryption algorithm is normally the same as
  4317. // the public key algorithm. For DSA, the hash encryption algorithm is
  4318. // normally a DSS signature algorithm.
  4319. //
  4320. // pvHashEncryptionAuxInfo currently isn't used and must be set to NULL if
  4321. // present in the data structure.
  4322. //
  4323. // The hCryptProv and dwKeySpec specify the private key to use. If dwKeySpec
  4324. // == 0, then, defaults to AT_SIGNATURE.
  4325. //
  4326. // If the HashEncryptionAlgorithm is set to szOID_PKIX_NO_SIGNATURE, then,
  4327. // the signature value only contains the hash octets. hCryptProv must still
  4328. // be specified. However, since a private key isn't used the hCryptProv can be
  4329. // acquired using CRYPT_VERIFYCONTEXT.
  4330. //
  4331. // If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  4332. // passed to CryptMsgOpenToEncode(), the signer hCryptProv's are released.
  4333. //
  4334. // pvHashAuxInfo currently isn't used and must be set to NULL.
  4335. //
  4336. // CMS signed messages allow the inclusion of Attribute Certs.
  4337. //--------------------------------------------------------------------------
  4338. typedef struct _CMSG_SIGNER_ENCODE_INFO {
  4339. DWORD cbSize;
  4340. PCERT_INFO pCertInfo;
  4341. HCRYPTPROV hCryptProv;
  4342. DWORD dwKeySpec;
  4343. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  4344. void *pvHashAuxInfo;
  4345. DWORD cAuthAttr;
  4346. PCRYPT_ATTRIBUTE rgAuthAttr;
  4347. DWORD cUnauthAttr;
  4348. PCRYPT_ATTRIBUTE rgUnauthAttr;
  4349. #ifdef CMSG_SIGNER_ENCODE_INFO_HAS_CMS_FIELDS
  4350. CERT_ID SignerId;
  4351. CRYPT_ALGORITHM_IDENTIFIER HashEncryptionAlgorithm;
  4352. void *pvHashEncryptionAuxInfo;
  4353. #endif
  4354. } CMSG_SIGNER_ENCODE_INFO, *PCMSG_SIGNER_ENCODE_INFO;
  4355. typedef struct _CMSG_SIGNED_ENCODE_INFO {
  4356. DWORD cbSize;
  4357. DWORD cSigners;
  4358. PCMSG_SIGNER_ENCODE_INFO rgSigners;
  4359. DWORD cCertEncoded;
  4360. PCERT_BLOB rgCertEncoded;
  4361. DWORD cCrlEncoded;
  4362. PCRL_BLOB rgCrlEncoded;
  4363. #ifdef CMSG_SIGNED_ENCODE_INFO_HAS_CMS_FIELDS
  4364. DWORD cAttrCertEncoded;
  4365. PCERT_BLOB rgAttrCertEncoded;
  4366. #endif
  4367. } CMSG_SIGNED_ENCODE_INFO, *PCMSG_SIGNED_ENCODE_INFO;
  4368. //+-------------------------------------------------------------------------
  4369. // CMSG_ENVELOPED
  4370. //
  4371. // The PCERT_INFO for the rgRecipients provides the Issuer, SerialNumber
  4372. // and PublicKeyInfo. The PublicKeyInfo.Algorithm implicitly
  4373. // specifies the KeyEncryptionAlgorithm to be used.
  4374. //
  4375. // The PublicKeyInfo.PublicKey in PCERT_INFO is used to encrypt the content
  4376. // encryption key for the recipient.
  4377. //
  4378. // hCryptProv is used to do the content encryption, recipient key encryption
  4379. // and export. The hCryptProv's private keys aren't used. If hCryptProv
  4380. // is NULL, a default hCryptProv is chosen according to the
  4381. // ContentEncryptionAlgorithm and the first recipient KeyEncryptionAlgorithm.
  4382. //
  4383. // If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  4384. // passed to CryptMsgOpenToEncode(), the envelope's hCryptProv is released.
  4385. //
  4386. // Note: CAPI currently doesn't support more than one KeyEncryptionAlgorithm
  4387. // per provider. This will need to be fixed.
  4388. //
  4389. // Currently, pvEncryptionAuxInfo is only defined for RC2 or RC4 encryption
  4390. // algorithms. Otherwise, its not used and must be set to NULL.
  4391. // See CMSG_RC2_AUX_INFO for the RC2 encryption algorithms.
  4392. // See CMSG_RC4_AUX_INFO for the RC4 encryption algorithms.
  4393. //
  4394. // To enable SP3 compatible encryption, pvEncryptionAuxInfo should point to
  4395. // a CMSG_SP3_COMPATIBLE_AUX_INFO data structure.
  4396. //
  4397. // To enable the CMS envelope enhancements, rgpRecipients must be set to
  4398. // NULL, and rgCmsRecipients updated to point to an array of
  4399. // CMSG_RECIPIENT_ENCODE_INFO's.
  4400. //
  4401. // Also, CMS envelope enhancements support the inclusion of a bag of
  4402. // Certs, CRLs, Attribute Certs and/or Unprotected Attributes.
  4403. //--------------------------------------------------------------------------
  4404. typedef struct _CMSG_RECIPIENT_ENCODE_INFO CMSG_RECIPIENT_ENCODE_INFO,
  4405. *PCMSG_RECIPIENT_ENCODE_INFO;
  4406. typedef struct _CMSG_ENVELOPED_ENCODE_INFO {
  4407. DWORD cbSize;
  4408. HCRYPTPROV hCryptProv;
  4409. CRYPT_ALGORITHM_IDENTIFIER ContentEncryptionAlgorithm;
  4410. void *pvEncryptionAuxInfo;
  4411. DWORD cRecipients;
  4412. // The following array may only be used for transport recipients identified
  4413. // by their IssuereAndSerialNumber. If rgpRecipients != NULL, then,
  4414. // the rgCmsRecipients must be NULL.
  4415. PCERT_INFO *rgpRecipients;
  4416. #ifdef CMSG_ENVELOPED_ENCODE_INFO_HAS_CMS_FIELDS
  4417. // If rgCmsRecipients != NULL, then, the above rgpRecipients must be
  4418. // NULL.
  4419. PCMSG_RECIPIENT_ENCODE_INFO rgCmsRecipients;
  4420. DWORD cCertEncoded;
  4421. PCERT_BLOB rgCertEncoded;
  4422. DWORD cCrlEncoded;
  4423. PCRL_BLOB rgCrlEncoded;
  4424. DWORD cAttrCertEncoded;
  4425. PCERT_BLOB rgAttrCertEncoded;
  4426. DWORD cUnprotectedAttr;
  4427. PCRYPT_ATTRIBUTE rgUnprotectedAttr;
  4428. #endif
  4429. } CMSG_ENVELOPED_ENCODE_INFO, *PCMSG_ENVELOPED_ENCODE_INFO;
  4430. //+-------------------------------------------------------------------------
  4431. // Key Transport Recipient Encode Info
  4432. //
  4433. // hCryptProv is used to do the recipient key encryption
  4434. // and export. The hCryptProv's private keys aren't used.
  4435. //
  4436. // If hCryptProv is NULL, then, the hCryptProv specified in
  4437. // CMSG_ENVELOPED_ENCODE_INFO is used.
  4438. //
  4439. // Note, even if CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  4440. // passed to CryptMsgOpenToEncode(), this hCryptProv isn't released.
  4441. //
  4442. // CMS supports the KEY_IDENTIFIER and ISSUER_SERIAL_NUMBER CERT_IDs. PKCS #7
  4443. // version 1.5 only supports the ISSUER_SERIAL_NUMBER CERT_ID choice.
  4444. //--------------------------------------------------------------------------
  4445. typedef struct _CMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO {
  4446. DWORD cbSize;
  4447. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  4448. void *pvKeyEncryptionAuxInfo;
  4449. HCRYPTPROV hCryptProv;
  4450. CRYPT_BIT_BLOB RecipientPublicKey;
  4451. CERT_ID RecipientId;
  4452. } CMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO, *PCMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO;
  4453. //+-------------------------------------------------------------------------
  4454. // Key Agreement Recipient Encode Info
  4455. //
  4456. // If hCryptProv is NULL, then, the hCryptProv specified in
  4457. // CMSG_ENVELOPED_ENCODE_INFO is used.
  4458. //
  4459. // For the CMSG_KEY_AGREE_STATIC_KEY_CHOICE, both the hCryptProv and
  4460. // dwKeySpec must be specified to select the sender's private key.
  4461. //
  4462. // Note, even if CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  4463. // passed to CryptMsgOpenToEncode(), this hCryptProv isn't released.
  4464. //
  4465. // CMS supports the KEY_IDENTIFIER and ISSUER_SERIAL_NUMBER CERT_IDs.
  4466. //
  4467. // There is 1 key choice, ephemeral originator. The originator's ephemeral
  4468. // key is generated using the public key algorithm parameters shared
  4469. // amongst all the recipients.
  4470. //
  4471. // There are 2 key choices: ephemeral originator or static sender. The
  4472. // originator's ephemeral key is generated using the public key algorithm
  4473. // parameters shared amongst all the recipients. For the static sender its
  4474. // private key is used. The hCryptProv and dwKeySpec specify the private key.
  4475. // The pSenderId identifies the certificate containing the sender's public key.
  4476. //
  4477. // Currently, pvKeyEncryptionAuxInfo isn't used and must be set to NULL.
  4478. //
  4479. // If KeyEncryptionAlgorithm.Parameters.cbData == 0, then, its Parameters
  4480. // are updated with the encoded KeyWrapAlgorithm.
  4481. //
  4482. // Currently, pvKeyWrapAuxInfo is only defined for algorithms with
  4483. // RC2. Otherwise, its not used and must be set to NULL.
  4484. // When set for RC2 algorithms, points to a CMSG_RC2_AUX_INFO containing
  4485. // the RC2 effective key length.
  4486. //
  4487. // Note, key agreement recipients are not supported in PKCS #7 version 1.5.
  4488. //--------------------------------------------------------------------------
  4489. typedef struct _CMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO {
  4490. DWORD cbSize;
  4491. CRYPT_BIT_BLOB RecipientPublicKey;
  4492. CERT_ID RecipientId;
  4493. // Following fields are optional and only applicable to KEY_IDENTIFIER
  4494. // CERT_IDs.
  4495. FILETIME Date;
  4496. PCRYPT_ATTRIBUTE_TYPE_VALUE pOtherAttr;
  4497. } CMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO,
  4498. *PCMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO;
  4499. typedef struct _CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO {
  4500. DWORD cbSize;
  4501. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  4502. void *pvKeyEncryptionAuxInfo;
  4503. CRYPT_ALGORITHM_IDENTIFIER KeyWrapAlgorithm;
  4504. void *pvKeyWrapAuxInfo;
  4505. // The following hCryptProv and dwKeySpec must be specified for the
  4506. // CMSG_KEY_AGREE_STATIC_KEY_CHOICE.
  4507. //
  4508. // For CMSG_KEY_AGREE_EPHEMERAL_KEY_CHOICE, dwKeySpec isn't applicable
  4509. // and hCryptProv is optional.
  4510. HCRYPTPROV hCryptProv;
  4511. DWORD dwKeySpec;
  4512. DWORD dwKeyChoice;
  4513. union {
  4514. // CMSG_KEY_AGREE_EPHEMERAL_KEY_CHOICE
  4515. //
  4516. // The ephemeral public key algorithm and parameters.
  4517. PCRYPT_ALGORITHM_IDENTIFIER pEphemeralAlgorithm;
  4518. // CMSG_KEY_AGREE_STATIC_KEY_CHOICE
  4519. //
  4520. // The CertId of the sender's certificate
  4521. PCERT_ID pSenderId;
  4522. };
  4523. CRYPT_DATA_BLOB UserKeyingMaterial; // OPTIONAL
  4524. DWORD cRecipientEncryptedKeys;
  4525. PCMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO *rgpRecipientEncryptedKeys;
  4526. } CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO, *PCMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO;
  4527. #define CMSG_KEY_AGREE_EPHEMERAL_KEY_CHOICE 1
  4528. #define CMSG_KEY_AGREE_STATIC_KEY_CHOICE 2
  4529. //+-------------------------------------------------------------------------
  4530. // Mail List Recipient Encode Info
  4531. //
  4532. // There is 1 choice for the KeyEncryptionKey: an already created CSP key
  4533. // handle. For the key handle choice, hCryptProv must be nonzero. This key
  4534. // handle isn't destroyed.
  4535. //
  4536. // Note, even if CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  4537. // passed to CryptMsgOpenToEncode(), this hCryptProv isn't released.
  4538. //
  4539. // Currently, pvKeyEncryptionAuxInfo is only defined for RC2 key wrap
  4540. // algorithms. Otherwise, its not used and must be set to NULL.
  4541. // When set for RC2 algorithms, points to a CMSG_RC2_AUX_INFO containing
  4542. // the RC2 effective key length.
  4543. //
  4544. // Note, mail list recipients are not supported in PKCS #7 version 1.5.
  4545. //--------------------------------------------------------------------------
  4546. typedef struct _CMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO {
  4547. DWORD cbSize;
  4548. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  4549. void *pvKeyEncryptionAuxInfo;
  4550. HCRYPTPROV hCryptProv;
  4551. DWORD dwKeyChoice;
  4552. union {
  4553. // CMSG_MAIL_LIST_HANDLE_KEY_CHOICE
  4554. HCRYPTKEY hKeyEncryptionKey;
  4555. // Reserve space for a potential pointer choice
  4556. void *pvKeyEncryptionKey;
  4557. };
  4558. CRYPT_DATA_BLOB KeyId;
  4559. // Following fields are optional.
  4560. FILETIME Date;
  4561. PCRYPT_ATTRIBUTE_TYPE_VALUE pOtherAttr;
  4562. } CMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO, *PCMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO;
  4563. #define CMSG_MAIL_LIST_HANDLE_KEY_CHOICE 1
  4564. //+-------------------------------------------------------------------------
  4565. // Recipient Encode Info
  4566. //
  4567. // Note, only key transport recipients are supported in PKCS #7 version 1.5.
  4568. //--------------------------------------------------------------------------
  4569. struct _CMSG_RECIPIENT_ENCODE_INFO {
  4570. DWORD dwRecipientChoice;
  4571. union {
  4572. // CMSG_KEY_TRANS_RECIPIENT
  4573. PCMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO pKeyTrans;
  4574. // CMSG_KEY_AGREE_RECIPIENT
  4575. PCMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO pKeyAgree;
  4576. // CMSG_MAIL_LIST_RECIPIENT
  4577. PCMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO pMailList;
  4578. };
  4579. };
  4580. #define CMSG_KEY_TRANS_RECIPIENT 1
  4581. #define CMSG_KEY_AGREE_RECIPIENT 2
  4582. #define CMSG_MAIL_LIST_RECIPIENT 3
  4583. //+-------------------------------------------------------------------------
  4584. // CMSG_RC2_AUX_INFO
  4585. //
  4586. // AuxInfo for RC2 encryption algorithms. The pvEncryptionAuxInfo field
  4587. // in CMSG_ENCRYPTED_ENCODE_INFO should be updated to point to this
  4588. // structure. If not specified, defaults to 40 bit.
  4589. //
  4590. // Note, this AuxInfo is only used when, the ContentEncryptionAlgorithm's
  4591. // Parameter.cbData is zero. Otherwise, the Parameters is decoded to
  4592. // get the bit length.
  4593. //
  4594. // If CMSG_SP3_COMPATIBLE_ENCRYPT_FLAG is set in dwBitLen, then, SP3
  4595. // compatible encryption is done and the bit length is ignored.
  4596. //--------------------------------------------------------------------------
  4597. typedef struct _CMSG_RC2_AUX_INFO {
  4598. DWORD cbSize;
  4599. DWORD dwBitLen;
  4600. } CMSG_RC2_AUX_INFO, *PCMSG_RC2_AUX_INFO;
  4601. //+-------------------------------------------------------------------------
  4602. // CMSG_SP3_COMPATIBLE_AUX_INFO
  4603. //
  4604. // AuxInfo for enabling SP3 compatible encryption.
  4605. //
  4606. // The CMSG_SP3_COMPATIBLE_ENCRYPT_FLAG is set in dwFlags to enable SP3
  4607. // compatible encryption. When set, uses zero salt instead of no salt,
  4608. // the encryption algorithm parameters are NULL instead of containing the
  4609. // encoded RC2 parameters or encoded IV octet string and the encrypted
  4610. // symmetric key is encoded little endian instead of big endian.
  4611. //--------------------------------------------------------------------------
  4612. typedef struct _CMSG_SP3_COMPATIBLE_AUX_INFO {
  4613. DWORD cbSize;
  4614. DWORD dwFlags;
  4615. } CMSG_SP3_COMPATIBLE_AUX_INFO, *PCMSG_SP3_COMPATIBLE_AUX_INFO;
  4616. #define CMSG_SP3_COMPATIBLE_ENCRYPT_FLAG 0x80000000
  4617. //+-------------------------------------------------------------------------
  4618. // CMSG_RC4_AUX_INFO
  4619. //
  4620. // AuxInfo for RC4 encryption algorithms. The pvEncryptionAuxInfo field
  4621. // in CMSG_ENCRYPTED_ENCODE_INFO should be updated to point to this
  4622. // structure. If not specified, uses the CSP's default bit length with no
  4623. // salt. Note, the base CSP has a 40 bit default and the enhanced CSP has
  4624. // a 128 bit default.
  4625. //
  4626. // If CMSG_RC4_NO_SALT_FLAG is set in dwBitLen, then, no salt is generated.
  4627. // Otherwise, (128 - dwBitLen)/8 bytes of salt are generated and encoded
  4628. // as an OCTET STRING in the algorithm parameters field.
  4629. //--------------------------------------------------------------------------
  4630. typedef struct _CMSG_RC4_AUX_INFO {
  4631. DWORD cbSize;
  4632. DWORD dwBitLen;
  4633. } CMSG_RC4_AUX_INFO, *PCMSG_RC4_AUX_INFO;
  4634. #define CMSG_RC4_NO_SALT_FLAG 0x40000000
  4635. //+-------------------------------------------------------------------------
  4636. // CMSG_SIGNED_AND_ENVELOPED
  4637. //
  4638. // For PKCS #7, a signed and enveloped message doesn't have the
  4639. // signer's authenticated or unauthenticated attributes. Otherwise, a
  4640. // combination of the CMSG_SIGNED_ENCODE_INFO and CMSG_ENVELOPED_ENCODE_INFO.
  4641. //--------------------------------------------------------------------------
  4642. typedef struct _CMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO {
  4643. DWORD cbSize;
  4644. CMSG_SIGNED_ENCODE_INFO SignedInfo;
  4645. CMSG_ENVELOPED_ENCODE_INFO EnvelopedInfo;
  4646. } CMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO, *PCMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO;
  4647. //+-------------------------------------------------------------------------
  4648. // CMSG_HASHED
  4649. //
  4650. // hCryptProv is used to do the hash. Doesn't need to use a private key.
  4651. //
  4652. // If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  4653. // passed to CryptMsgOpenToEncode(), the hCryptProv is released.
  4654. //
  4655. // If fDetachedHash is set, then, the encoded message doesn't contain
  4656. // any content (its treated as NULL Data)
  4657. //
  4658. // pvHashAuxInfo currently isn't used and must be set to NULL.
  4659. //--------------------------------------------------------------------------
  4660. typedef struct _CMSG_HASHED_ENCODE_INFO {
  4661. DWORD cbSize;
  4662. HCRYPTPROV hCryptProv;
  4663. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  4664. void *pvHashAuxInfo;
  4665. } CMSG_HASHED_ENCODE_INFO, *PCMSG_HASHED_ENCODE_INFO;
  4666. //+-------------------------------------------------------------------------
  4667. // CMSG_ENCRYPTED
  4668. //
  4669. // The key used to encrypt the message is identified outside of the message
  4670. // content (for example, password).
  4671. //
  4672. // The content input to CryptMsgUpdate has already been encrypted.
  4673. //
  4674. // pvEncryptionAuxInfo currently isn't used and must be set to NULL.
  4675. //--------------------------------------------------------------------------
  4676. typedef struct _CMSG_ENCRYPTED_ENCODE_INFO {
  4677. DWORD cbSize;
  4678. CRYPT_ALGORITHM_IDENTIFIER ContentEncryptionAlgorithm;
  4679. void *pvEncryptionAuxInfo;
  4680. } CMSG_ENCRYPTED_ENCODE_INFO, *PCMSG_ENCRYPTED_ENCODE_INFO;
  4681. //+-------------------------------------------------------------------------
  4682. // This parameter allows messages to be of variable length with streamed
  4683. // output.
  4684. //
  4685. // By default, messages are of a definite length and
  4686. // CryptMsgGetParam(CMSG_CONTENT_PARAM) is
  4687. // called to get the cryptographically processed content. Until closed,
  4688. // the handle keeps a copy of the processed content.
  4689. //
  4690. // With streamed output, the processed content can be freed as its streamed.
  4691. //
  4692. // If the length of the content to be updated is known at the time of the
  4693. // open, then, ContentLength should be set to that length. Otherwise, it
  4694. // should be set to CMSG_INDEFINITE_LENGTH.
  4695. //--------------------------------------------------------------------------
  4696. typedef BOOL (WINAPI *PFN_CMSG_STREAM_OUTPUT)(
  4697. IN const void *pvArg,
  4698. IN BYTE *pbData,
  4699. IN DWORD cbData,
  4700. IN BOOL fFinal
  4701. );
  4702. #define CMSG_INDEFINITE_LENGTH (0xFFFFFFFF)
  4703. typedef struct _CMSG_STREAM_INFO {
  4704. DWORD cbContent;
  4705. PFN_CMSG_STREAM_OUTPUT pfnStreamOutput;
  4706. void *pvArg;
  4707. } CMSG_STREAM_INFO, *PCMSG_STREAM_INFO;
  4708. //+-------------------------------------------------------------------------
  4709. // Open dwFlags
  4710. //--------------------------------------------------------------------------
  4711. #define CMSG_BARE_CONTENT_FLAG 0x00000001
  4712. #define CMSG_LENGTH_ONLY_FLAG 0x00000002
  4713. #define CMSG_DETACHED_FLAG 0x00000004
  4714. #define CMSG_AUTHENTICATED_ATTRIBUTES_FLAG 0x00000008
  4715. #define CMSG_CONTENTS_OCTETS_FLAG 0x00000010
  4716. #define CMSG_MAX_LENGTH_FLAG 0x00000020
  4717. // When set, nonData type inner content is encapsulated within an
  4718. // OCTET STRING. Applicable to both Signed and Enveloped messages.
  4719. #define CMSG_CMS_ENCAPSULATED_CONTENT_FLAG 0x00000040
  4720. // If set, then, the hCryptProv passed to CryptMsgOpenToEncode or
  4721. // CryptMsgOpenToDecode is released on the final CryptMsgClose.
  4722. // Not released if CryptMsgOpenToEncode or CryptMsgOpenToDecode fails.
  4723. //
  4724. // Note, the envelope recipient hCryptProv's aren't released.
  4725. #define CMSG_CRYPT_RELEASE_CONTEXT_FLAG 0x00008000
  4726. //+-------------------------------------------------------------------------
  4727. // Open a cryptographic message for encoding
  4728. //
  4729. // If CMSG_BARE_CONTENT_FLAG is specified for a streamed message,
  4730. // the streamed output will not have an outer ContentInfo wrapper. This
  4731. // makes it suitable to be streamed into an enclosing message.
  4732. //
  4733. // The pStreamInfo parameter needs to be set to stream the encoded message
  4734. // output.
  4735. //--------------------------------------------------------------------------
  4736. WINCRYPT32API
  4737. HCRYPTMSG
  4738. WINAPI
  4739. CryptMsgOpenToEncode(
  4740. IN DWORD dwMsgEncodingType,
  4741. IN DWORD dwFlags,
  4742. IN DWORD dwMsgType,
  4743. IN void const *pvMsgEncodeInfo,
  4744. IN OPTIONAL LPSTR pszInnerContentObjID,
  4745. IN OPTIONAL PCMSG_STREAM_INFO pStreamInfo
  4746. );
  4747. //+-------------------------------------------------------------------------
  4748. // Calculate the length of an encoded cryptographic message.
  4749. //
  4750. // Calculates the length of the encoded message given the
  4751. // message type, encoding parameters and total length of
  4752. // the data to be updated. Note, this might not be the exact length. However,
  4753. // it will always be greater than or equal to the actual length.
  4754. //--------------------------------------------------------------------------
  4755. WINCRYPT32API
  4756. DWORD
  4757. WINAPI
  4758. CryptMsgCalculateEncodedLength(
  4759. IN DWORD dwMsgEncodingType,
  4760. IN DWORD dwFlags,
  4761. IN DWORD dwMsgType,
  4762. IN void const *pvMsgEncodeInfo,
  4763. IN OPTIONAL LPSTR pszInnerContentObjID,
  4764. IN DWORD cbData
  4765. );
  4766. //+-------------------------------------------------------------------------
  4767. // Open a cryptographic message for decoding
  4768. //
  4769. // hCryptProv specifies the crypto provider to use for hashing and/or
  4770. // decrypting the message. If hCryptProv is NULL, a default crypt provider
  4771. // is used.
  4772. //
  4773. // Currently pRecipientInfo isn't used and should be set to NULL.
  4774. //
  4775. // The pStreamInfo parameter needs to be set to stream the decoded content
  4776. // output.
  4777. //--------------------------------------------------------------------------
  4778. WINCRYPT32API
  4779. HCRYPTMSG
  4780. WINAPI
  4781. CryptMsgOpenToDecode(
  4782. IN DWORD dwMsgEncodingType,
  4783. IN DWORD dwFlags,
  4784. IN DWORD dwMsgType,
  4785. IN HCRYPTPROV hCryptProv,
  4786. IN OPTIONAL PCERT_INFO pRecipientInfo,
  4787. IN OPTIONAL PCMSG_STREAM_INFO pStreamInfo
  4788. );
  4789. //+-------------------------------------------------------------------------
  4790. // Duplicate a cryptographic message handle
  4791. //--------------------------------------------------------------------------
  4792. WINCRYPT32API
  4793. HCRYPTMSG
  4794. WINAPI
  4795. CryptMsgDuplicate(
  4796. IN HCRYPTMSG hCryptMsg
  4797. );
  4798. //+-------------------------------------------------------------------------
  4799. // Close a cryptographic message handle
  4800. //
  4801. // LastError is preserved unless FALSE is returned.
  4802. //--------------------------------------------------------------------------
  4803. WINCRYPT32API
  4804. BOOL
  4805. WINAPI
  4806. CryptMsgClose(
  4807. IN HCRYPTMSG hCryptMsg
  4808. );
  4809. //+-------------------------------------------------------------------------
  4810. // Update the content of a cryptographic message. Depending on how the
  4811. // message was opened, the content is either encoded or decoded.
  4812. //
  4813. // This function is repetitively called to append to the message content.
  4814. // fFinal is set to identify the last update. On fFinal, the encode/decode
  4815. // is completed. The encoded/decoded content and the decoded parameters
  4816. // are valid until the open and all duplicated handles are closed.
  4817. //--------------------------------------------------------------------------
  4818. WINCRYPT32API
  4819. BOOL
  4820. WINAPI
  4821. CryptMsgUpdate(
  4822. IN HCRYPTMSG hCryptMsg,
  4823. IN const BYTE *pbData,
  4824. IN DWORD cbData,
  4825. IN BOOL fFinal
  4826. );
  4827. //+-------------------------------------------------------------------------
  4828. // Get a parameter after encoding/decoding a cryptographic message. Called
  4829. // after the final CryptMsgUpdate. Only the CMSG_CONTENT_PARAM and
  4830. // CMSG_COMPUTED_HASH_PARAM are valid for an encoded message.
  4831. //
  4832. // For an encoded HASHED message, the CMSG_COMPUTED_HASH_PARAM can be got
  4833. // before any CryptMsgUpdates to get its length.
  4834. //
  4835. // The pvData type definition depends on the dwParamType value.
  4836. //
  4837. // Elements pointed to by fields in the pvData structure follow the
  4838. // structure. Therefore, *pcbData may exceed the size of the structure.
  4839. //
  4840. // Upon input, if *pcbData == 0, then, *pcbData is updated with the length
  4841. // of the data and the pvData parameter is ignored.
  4842. //
  4843. // Upon return, *pcbData is updated with the length of the data.
  4844. //
  4845. // The OBJID BLOBs returned in the pvData structures point to
  4846. // their still encoded representation. The appropriate functions
  4847. // must be called to decode the information.
  4848. //
  4849. // See below for a list of the parameters to get.
  4850. //--------------------------------------------------------------------------
  4851. WINCRYPT32API
  4852. BOOL
  4853. WINAPI
  4854. CryptMsgGetParam(
  4855. IN HCRYPTMSG hCryptMsg,
  4856. IN DWORD dwParamType,
  4857. IN DWORD dwIndex,
  4858. OUT void *pvData,
  4859. IN OUT DWORD *pcbData
  4860. );
  4861. //+-------------------------------------------------------------------------
  4862. // Get parameter types and their corresponding data structure definitions.
  4863. //--------------------------------------------------------------------------
  4864. #define CMSG_TYPE_PARAM 1
  4865. #define CMSG_CONTENT_PARAM 2
  4866. #define CMSG_BARE_CONTENT_PARAM 3
  4867. #define CMSG_INNER_CONTENT_TYPE_PARAM 4
  4868. #define CMSG_SIGNER_COUNT_PARAM 5
  4869. #define CMSG_SIGNER_INFO_PARAM 6
  4870. #define CMSG_SIGNER_CERT_INFO_PARAM 7
  4871. #define CMSG_SIGNER_HASH_ALGORITHM_PARAM 8
  4872. #define CMSG_SIGNER_AUTH_ATTR_PARAM 9
  4873. #define CMSG_SIGNER_UNAUTH_ATTR_PARAM 10
  4874. #define CMSG_CERT_COUNT_PARAM 11
  4875. #define CMSG_CERT_PARAM 12
  4876. #define CMSG_CRL_COUNT_PARAM 13
  4877. #define CMSG_CRL_PARAM 14
  4878. #define CMSG_ENVELOPE_ALGORITHM_PARAM 15
  4879. #define CMSG_RECIPIENT_COUNT_PARAM 17
  4880. #define CMSG_RECIPIENT_INDEX_PARAM 18
  4881. #define CMSG_RECIPIENT_INFO_PARAM 19
  4882. #define CMSG_HASH_ALGORITHM_PARAM 20
  4883. #define CMSG_HASH_DATA_PARAM 21
  4884. #define CMSG_COMPUTED_HASH_PARAM 22
  4885. #define CMSG_ENCRYPT_PARAM 26
  4886. #define CMSG_ENCRYPTED_DIGEST 27
  4887. #define CMSG_ENCODED_SIGNER 28
  4888. #define CMSG_ENCODED_MESSAGE 29
  4889. #define CMSG_VERSION_PARAM 30
  4890. #define CMSG_ATTR_CERT_COUNT_PARAM 31
  4891. #define CMSG_ATTR_CERT_PARAM 32
  4892. #define CMSG_CMS_RECIPIENT_COUNT_PARAM 33
  4893. #define CMSG_CMS_RECIPIENT_INDEX_PARAM 34
  4894. #define CMSG_CMS_RECIPIENT_ENCRYPTED_KEY_INDEX_PARAM 35
  4895. #define CMSG_CMS_RECIPIENT_INFO_PARAM 36
  4896. #define CMSG_UNPROTECTED_ATTR_PARAM 37
  4897. #define CMSG_SIGNER_CERT_ID_PARAM 38
  4898. #define CMSG_CMS_SIGNER_INFO_PARAM 39
  4899. //+-------------------------------------------------------------------------
  4900. // CMSG_TYPE_PARAM
  4901. //
  4902. // The type of the decoded message.
  4903. //
  4904. // pvData points to a DWORD
  4905. //--------------------------------------------------------------------------
  4906. //+-------------------------------------------------------------------------
  4907. // CMSG_CONTENT_PARAM
  4908. //
  4909. // The encoded content of a cryptographic message. Depending on how the
  4910. // message was opened, the content is either the whole PKCS#7
  4911. // message (opened to encode) or the inner content (opened to decode).
  4912. // In the decode case, the decrypted content is returned, if enveloped.
  4913. // If not enveloped, and if the inner content is of type DATA, the returned
  4914. // data is the contents octets of the inner content.
  4915. //
  4916. // pvData points to the buffer receiving the content bytes
  4917. //--------------------------------------------------------------------------
  4918. //+-------------------------------------------------------------------------
  4919. // CMSG_BARE_CONTENT_PARAM
  4920. //
  4921. // The encoded content of an encoded cryptographic message, without the
  4922. // outer layer of ContentInfo. That is, only the encoding of the
  4923. // ContentInfo.content field is returned.
  4924. //
  4925. // pvData points to the buffer receiving the content bytes
  4926. //--------------------------------------------------------------------------
  4927. //+-------------------------------------------------------------------------
  4928. // CMSG_INNER_CONTENT_TYPE_PARAM
  4929. //
  4930. // The type of the inner content of a decoded cryptographic message,
  4931. // in the form of a NULL-terminated object identifier string
  4932. // (eg. "1.2.840.113549.1.7.1").
  4933. //
  4934. // pvData points to the buffer receiving the object identifier string
  4935. //--------------------------------------------------------------------------
  4936. //+-------------------------------------------------------------------------
  4937. // CMSG_SIGNER_COUNT_PARAM
  4938. //
  4939. // Count of signers in a SIGNED or SIGNED_AND_ENVELOPED message
  4940. //
  4941. // pvData points to a DWORD
  4942. //--------------------------------------------------------------------------
  4943. //+-------------------------------------------------------------------------
  4944. // CMSG_SIGNER_CERT_INFO_PARAM
  4945. //
  4946. // To get all the signers, repetitively call CryptMsgGetParam, with
  4947. // dwIndex set to 0 .. SignerCount - 1.
  4948. //
  4949. // pvData points to a CERT_INFO struct.
  4950. //
  4951. // Only the following fields have been updated in the CERT_INFO struct:
  4952. // Issuer and SerialNumber.
  4953. //
  4954. // Note, if the KEYID choice was selected for a CMS SignerId, then, the
  4955. // SerialNumber is 0 and the Issuer is encoded containing a single RDN with a
  4956. // single Attribute whose OID is szOID_KEYID_RDN, value type is
  4957. // CERT_RDN_OCTET_STRING and value is the KEYID. When the
  4958. // CertGetSubjectCertificateFromStore and
  4959. // CertFindCertificateInStore(CERT_FIND_SUBJECT_CERT) APIs see this
  4960. // special KEYID Issuer and SerialNumber, they do a KEYID match.
  4961. //--------------------------------------------------------------------------
  4962. //+-------------------------------------------------------------------------
  4963. // CMSG_SIGNER_INFO_PARAM
  4964. //
  4965. // To get all the signers, repetitively call CryptMsgGetParam, with
  4966. // dwIndex set to 0 .. SignerCount - 1.
  4967. //
  4968. // pvData points to a CMSG_SIGNER_INFO struct.
  4969. //
  4970. // Note, if the KEYID choice was selected for a CMS SignerId, then, the
  4971. // SerialNumber is 0 and the Issuer is encoded containing a single RDN with a
  4972. // single Attribute whose OID is szOID_KEYID_RDN, value type is
  4973. // CERT_RDN_OCTET_STRING and value is the KEYID. When the
  4974. // CertGetSubjectCertificateFromStore and
  4975. // CertFindCertificateInStore(CERT_FIND_SUBJECT_CERT) APIs see this
  4976. // special KEYID Issuer and SerialNumber, they do a KEYID match.
  4977. //--------------------------------------------------------------------------
  4978. typedef struct _CMSG_SIGNER_INFO {
  4979. DWORD dwVersion;
  4980. CERT_NAME_BLOB Issuer;
  4981. CRYPT_INTEGER_BLOB SerialNumber;
  4982. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  4983. CRYPT_ALGORITHM_IDENTIFIER HashEncryptionAlgorithm;
  4984. CRYPT_DATA_BLOB EncryptedHash;
  4985. CRYPT_ATTRIBUTES AuthAttrs;
  4986. CRYPT_ATTRIBUTES UnauthAttrs;
  4987. } CMSG_SIGNER_INFO, *PCMSG_SIGNER_INFO;
  4988. //+-------------------------------------------------------------------------
  4989. // CMSG_SIGNER_CERT_ID_PARAM
  4990. //
  4991. // To get all the signers, repetitively call CryptMsgGetParam, with
  4992. // dwIndex set to 0 .. SignerCount - 1.
  4993. //
  4994. // pvData points to a CERT_ID struct.
  4995. //--------------------------------------------------------------------------
  4996. //+-------------------------------------------------------------------------
  4997. // CMSG_CMS_SIGNER_INFO_PARAM
  4998. //
  4999. // Same as CMSG_SIGNER_INFO_PARAM, except, contains SignerId instead of
  5000. // Issuer and SerialNumber.
  5001. //
  5002. // To get all the signers, repetitively call CryptMsgGetParam, with
  5003. // dwIndex set to 0 .. SignerCount - 1.
  5004. //
  5005. // pvData points to a CMSG_CMS_SIGNER_INFO struct.
  5006. //--------------------------------------------------------------------------
  5007. typedef struct _CMSG_CMS_SIGNER_INFO {
  5008. DWORD dwVersion;
  5009. CERT_ID SignerId;
  5010. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  5011. CRYPT_ALGORITHM_IDENTIFIER HashEncryptionAlgorithm;
  5012. CRYPT_DATA_BLOB EncryptedHash;
  5013. CRYPT_ATTRIBUTES AuthAttrs;
  5014. CRYPT_ATTRIBUTES UnauthAttrs;
  5015. } CMSG_CMS_SIGNER_INFO, *PCMSG_CMS_SIGNER_INFO;
  5016. //+-------------------------------------------------------------------------
  5017. // CMSG_SIGNER_HASH_ALGORITHM_PARAM
  5018. //
  5019. // This parameter specifies the HashAlgorithm that was used for the signer.
  5020. //
  5021. // Set dwIndex to iterate through all the signers.
  5022. //
  5023. // pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  5024. //--------------------------------------------------------------------------
  5025. //+-------------------------------------------------------------------------
  5026. // CMSG_SIGNER_AUTH_ATTR_PARAM
  5027. //
  5028. // The authenticated attributes for the signer.
  5029. //
  5030. // Set dwIndex to iterate through all the signers.
  5031. //
  5032. // pvData points to a CMSG_ATTR struct.
  5033. //--------------------------------------------------------------------------
  5034. typedef CRYPT_ATTRIBUTES CMSG_ATTR;
  5035. typedef CRYPT_ATTRIBUTES *PCMSG_ATTR;
  5036. //+-------------------------------------------------------------------------
  5037. // CMSG_SIGNER_UNAUTH_ATTR_PARAM
  5038. //
  5039. // The unauthenticated attributes for the signer.
  5040. //
  5041. // Set dwIndex to iterate through all the signers.
  5042. //
  5043. // pvData points to a CMSG_ATTR struct.
  5044. //--------------------------------------------------------------------------
  5045. //+-------------------------------------------------------------------------
  5046. // CMSG_CERT_COUNT_PARAM
  5047. //
  5048. // Count of certificates in a SIGNED or SIGNED_AND_ENVELOPED message.
  5049. //
  5050. // CMS, also supports certificates in an ENVELOPED message.
  5051. //
  5052. // pvData points to a DWORD
  5053. //--------------------------------------------------------------------------
  5054. //+-------------------------------------------------------------------------
  5055. // CMSG_CERT_PARAM
  5056. //
  5057. // To get all the certificates, repetitively call CryptMsgGetParam, with
  5058. // dwIndex set to 0 .. CertCount - 1.
  5059. //
  5060. // pvData points to an array of the certificate's encoded bytes.
  5061. //--------------------------------------------------------------------------
  5062. //+-------------------------------------------------------------------------
  5063. // CMSG_CRL_COUNT_PARAM
  5064. //
  5065. // Count of CRLs in a SIGNED or SIGNED_AND_ENVELOPED message.
  5066. //
  5067. // CMS, also supports CRLs in an ENVELOPED message.
  5068. //
  5069. // pvData points to a DWORD
  5070. //--------------------------------------------------------------------------
  5071. //+-------------------------------------------------------------------------
  5072. // CMSG_CRL_PARAM
  5073. //
  5074. // To get all the CRLs, repetitively call CryptMsgGetParam, with
  5075. // dwIndex set to 0 .. CrlCount - 1.
  5076. //
  5077. // pvData points to an array of the CRL's encoded bytes.
  5078. //--------------------------------------------------------------------------
  5079. //+-------------------------------------------------------------------------
  5080. // CMSG_ENVELOPE_ALGORITHM_PARAM
  5081. //
  5082. // The ContentEncryptionAlgorithm that was used in
  5083. // an ENVELOPED or SIGNED_AND_ENVELOPED message.
  5084. //
  5085. // For streaming you must be able to successfully get this parameter before
  5086. // doing a CryptMsgControl decrypt.
  5087. //
  5088. // pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  5089. //--------------------------------------------------------------------------
  5090. //+-------------------------------------------------------------------------
  5091. // CMSG_RECIPIENT_COUNT_PARAM
  5092. //
  5093. // Count of recipients in an ENVELOPED or SIGNED_AND_ENVELOPED message.
  5094. //
  5095. // Count of key transport recepients.
  5096. //
  5097. // The CMSG_CMS_RECIPIENT_COUNT_PARAM has the total count of
  5098. // recipients (it also includes key agree and mail list recipients).
  5099. //
  5100. // pvData points to a DWORD
  5101. //--------------------------------------------------------------------------
  5102. //+-------------------------------------------------------------------------
  5103. // CMSG_RECIPIENT_INDEX_PARAM
  5104. //
  5105. // Index of the recipient used to decrypt an ENVELOPED or SIGNED_AND_ENVELOPED
  5106. // message.
  5107. //
  5108. // Index of a key transport recipient. If a non key transport
  5109. // recipient was used to decrypt, fails with LastError set to
  5110. // CRYPT_E_INVALID_INDEX.
  5111. //
  5112. // pvData points to a DWORD
  5113. //--------------------------------------------------------------------------
  5114. //+-------------------------------------------------------------------------
  5115. // CMSG_RECIPIENT_INFO_PARAM
  5116. //
  5117. // To get all the recipients, repetitively call CryptMsgGetParam, with
  5118. // dwIndex set to 0 .. RecipientCount - 1.
  5119. //
  5120. // Only returns the key transport recepients.
  5121. //
  5122. // The CMSG_CMS_RECIPIENT_INFO_PARAM returns all recipients.
  5123. //
  5124. // pvData points to a CERT_INFO struct.
  5125. //
  5126. // Only the following fields have been updated in the CERT_INFO struct:
  5127. // Issuer, SerialNumber and PublicKeyAlgorithm. The PublicKeyAlgorithm
  5128. // specifies the KeyEncryptionAlgorithm that was used.
  5129. //
  5130. // Note, if the KEYID choice was selected for a key transport recipient, then,
  5131. // the SerialNumber is 0 and the Issuer is encoded containing a single RDN
  5132. // with a single Attribute whose OID is szOID_KEYID_RDN, value type is
  5133. // CERT_RDN_OCTET_STRING and value is the KEYID. When the
  5134. // CertGetSubjectCertificateFromStore and
  5135. // CertFindCertificateInStore(CERT_FIND_SUBJECT_CERT) APIs see this
  5136. // special KEYID Issuer and SerialNumber, they do a KEYID match.
  5137. //--------------------------------------------------------------------------
  5138. //+-------------------------------------------------------------------------
  5139. // CMSG_HASH_ALGORITHM_PARAM
  5140. //
  5141. // The HashAlgorithm in a HASHED message.
  5142. //
  5143. // pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  5144. //--------------------------------------------------------------------------
  5145. //+-------------------------------------------------------------------------
  5146. // CMSG_HASH_DATA_PARAM
  5147. //
  5148. // The hash in a HASHED message.
  5149. //
  5150. // pvData points to an array of bytes.
  5151. //--------------------------------------------------------------------------
  5152. //+-------------------------------------------------------------------------
  5153. // CMSG_COMPUTED_HASH_PARAM
  5154. //
  5155. // The computed hash for a HASHED message.
  5156. // This may be called for either an encoded or decoded message.
  5157. //
  5158. // Also, the computed hash for one of the signer's in a SIGNED message.
  5159. // It may be called for either an encoded or decoded message after the
  5160. // final update. Set dwIndex to iterate through all the signers.
  5161. //
  5162. // pvData points to an array of bytes.
  5163. //--------------------------------------------------------------------------
  5164. //+-------------------------------------------------------------------------
  5165. // CMSG_ENCRYPT_PARAM
  5166. //
  5167. // The ContentEncryptionAlgorithm that was used in an ENCRYPTED message.
  5168. //
  5169. // pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  5170. //--------------------------------------------------------------------------
  5171. //+-------------------------------------------------------------------------
  5172. // CMSG_ENCODED_MESSAGE
  5173. //
  5174. // The full encoded message. This is useful in the case of a decoded
  5175. // message which has been modified (eg. a signed-data or
  5176. // signed-and-enveloped-data message which has been countersigned).
  5177. //
  5178. // pvData points to an array of the message's encoded bytes.
  5179. //--------------------------------------------------------------------------
  5180. //+-------------------------------------------------------------------------
  5181. // CMSG_VERSION_PARAM
  5182. //
  5183. // The version of the decoded message.
  5184. //
  5185. // pvData points to a DWORD
  5186. //--------------------------------------------------------------------------
  5187. #define CMSG_SIGNED_DATA_V1 1
  5188. #define CMSG_SIGNED_DATA_V3 3
  5189. #define CMSG_SIGNED_DATA_PKCS_1_5_VERSION CMSG_SIGNED_DATA_V1
  5190. #define CMSG_SIGNED_DATA_CMS_VERSION CMSG_SIGNED_DATA_V3
  5191. #define CMSG_SIGNER_INFO_V1 1
  5192. #define CMSG_SIGNER_INFO_V3 3
  5193. #define CMSG_SIGNER_INFO_PKCS_1_5_VERSION CMSG_SIGNER_INFO_V1
  5194. #define CMSG_SIGNER_INFO_CMS_VERSION CMSG_SIGNER_INFO_V3
  5195. #define CMSG_HASHED_DATA_V0 0
  5196. #define CMSG_HASHED_DATA_V2 2
  5197. #define CMSG_HASHED_DATA_PKCS_1_5_VERSION CMSG_HASHED_DATA_V0
  5198. #define CMSG_HASHED_DATA_CMS_VERSION CMSG_HASHED_DATA_V2
  5199. #define CMSG_ENVELOPED_DATA_V0 0
  5200. #define CMSG_ENVELOPED_DATA_V2 2
  5201. #define CMSG_ENVELOPED_DATA_PKCS_1_5_VERSION CMSG_ENVELOPED_DATA_V0
  5202. #define CMSG_ENVELOPED_DATA_CMS_VERSION CMSG_ENVELOPED_DATA_V2
  5203. //+-------------------------------------------------------------------------
  5204. // CMSG_ATTR_CERT_COUNT_PARAM
  5205. //
  5206. // Count of attribute certificates in a SIGNED or ENVELOPED message.
  5207. //
  5208. // pvData points to a DWORD
  5209. //--------------------------------------------------------------------------
  5210. //+-------------------------------------------------------------------------
  5211. // CMSG_ATTR_CERT_PARAM
  5212. //
  5213. // To get all the attribute certificates, repetitively call CryptMsgGetParam,
  5214. // with dwIndex set to 0 .. AttrCertCount - 1.
  5215. //
  5216. // pvData points to an array of the attribute certificate's encoded bytes.
  5217. //--------------------------------------------------------------------------
  5218. //+-------------------------------------------------------------------------
  5219. // CMSG_CMS_RECIPIENT_COUNT_PARAM
  5220. //
  5221. // Count of all CMS recipients in an ENVELOPED message.
  5222. //
  5223. // pvData points to a DWORD
  5224. //--------------------------------------------------------------------------
  5225. //+-------------------------------------------------------------------------
  5226. // CMSG_CMS_RECIPIENT_INDEX_PARAM
  5227. //
  5228. // Index of the CMS recipient used to decrypt an ENVELOPED message.
  5229. //
  5230. // pvData points to a DWORD
  5231. //--------------------------------------------------------------------------
  5232. //+-------------------------------------------------------------------------
  5233. // CMSG_CMS_RECIPIENT_ENCRYPTED_KEY_INDEX_PARAM
  5234. //
  5235. // For a CMS key agreement recipient, the index of the encrypted key
  5236. // used to decrypt an ENVELOPED message.
  5237. //
  5238. // pvData points to a DWORD
  5239. //--------------------------------------------------------------------------
  5240. //+-------------------------------------------------------------------------
  5241. // CMSG_CMS_RECIPIENT_INFO_PARAM
  5242. //
  5243. // To get all the CMS recipients, repetitively call CryptMsgGetParam, with
  5244. // dwIndex set to 0 .. CmsRecipientCount - 1.
  5245. //
  5246. // pvData points to a CMSG_CMS_RECIPIENT_INFO struct.
  5247. //--------------------------------------------------------------------------
  5248. typedef struct _CMSG_KEY_TRANS_RECIPIENT_INFO {
  5249. DWORD dwVersion;
  5250. // Currently, only ISSUER_SERIAL_NUMBER or KEYID choices
  5251. CERT_ID RecipientId;
  5252. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  5253. CRYPT_DATA_BLOB EncryptedKey;
  5254. } CMSG_KEY_TRANS_RECIPIENT_INFO, *PCMSG_KEY_TRANS_RECIPIENT_INFO;
  5255. typedef struct _CMSG_RECIPIENT_ENCRYPTED_KEY_INFO {
  5256. // Currently, only ISSUER_SERIAL_NUMBER or KEYID choices
  5257. CERT_ID RecipientId;
  5258. CRYPT_DATA_BLOB EncryptedKey;
  5259. // The following optional fields are only applicable to KEYID choice
  5260. FILETIME Date;
  5261. PCRYPT_ATTRIBUTE_TYPE_VALUE pOtherAttr;
  5262. } CMSG_RECIPIENT_ENCRYPTED_KEY_INFO, *PCMSG_RECIPIENT_ENCRYPTED_KEY_INFO;
  5263. typedef struct _CMSG_KEY_AGREE_RECIPIENT_INFO {
  5264. DWORD dwVersion;
  5265. DWORD dwOriginatorChoice;
  5266. union {
  5267. // CMSG_KEY_AGREE_ORIGINATOR_CERT
  5268. CERT_ID OriginatorCertId;
  5269. // CMSG_KEY_AGREE_ORIGINATOR_PUBLIC_KEY
  5270. CERT_PUBLIC_KEY_INFO OriginatorPublicKeyInfo;
  5271. };
  5272. CRYPT_DATA_BLOB UserKeyingMaterial;
  5273. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  5274. DWORD cRecipientEncryptedKeys;
  5275. PCMSG_RECIPIENT_ENCRYPTED_KEY_INFO *rgpRecipientEncryptedKeys;
  5276. } CMSG_KEY_AGREE_RECIPIENT_INFO, *PCMSG_KEY_AGREE_RECIPIENT_INFO;
  5277. #define CMSG_KEY_AGREE_ORIGINATOR_CERT 1
  5278. #define CMSG_KEY_AGREE_ORIGINATOR_PUBLIC_KEY 2
  5279. typedef struct _CMSG_MAIL_LIST_RECIPIENT_INFO {
  5280. DWORD dwVersion;
  5281. CRYPT_DATA_BLOB KeyId;
  5282. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  5283. CRYPT_DATA_BLOB EncryptedKey;
  5284. // The following fields are optional
  5285. FILETIME Date;
  5286. PCRYPT_ATTRIBUTE_TYPE_VALUE pOtherAttr;
  5287. } CMSG_MAIL_LIST_RECIPIENT_INFO, *PCMSG_MAIL_LIST_RECIPIENT_INFO;
  5288. typedef struct _CMSG_CMS_RECIPIENT_INFO {
  5289. DWORD dwRecipientChoice;
  5290. union {
  5291. // CMSG_KEY_TRANS_RECIPIENT
  5292. PCMSG_KEY_TRANS_RECIPIENT_INFO pKeyTrans;
  5293. // CMSG_KEY_AGREE_RECIPIENT
  5294. PCMSG_KEY_AGREE_RECIPIENT_INFO pKeyAgree;
  5295. // CMSG_MAIL_LIST_RECIPIENT
  5296. PCMSG_MAIL_LIST_RECIPIENT_INFO pMailList;
  5297. };
  5298. } CMSG_CMS_RECIPIENT_INFO, *PCMSG_CMS_RECIPIENT_INFO;
  5299. // dwVersion numbers for the KeyTrans, KeyAgree and MailList recipients
  5300. #define CMSG_ENVELOPED_RECIPIENT_V0 0
  5301. #define CMSG_ENVELOPED_RECIPIENT_V2 2
  5302. #define CMSG_ENVELOPED_RECIPIENT_V3 3
  5303. #define CMSG_ENVELOPED_RECIPIENT_V4 4
  5304. #define CMSG_KEY_TRANS_PKCS_1_5_VERSION CMSG_ENVELOPED_RECIPIENT_V0
  5305. #define CMSG_KEY_TRANS_CMS_VERSION CMSG_ENVELOPED_RECIPIENT_V2
  5306. #define CMSG_KEY_AGREE_VERSION CMSG_ENVELOPED_RECIPIENT_V3
  5307. #define CMSG_MAIL_LIST_VERSION CMSG_ENVELOPED_RECIPIENT_V4
  5308. //+-------------------------------------------------------------------------
  5309. // CMSG_UNPROTECTED_ATTR_PARAM
  5310. //
  5311. // The unprotected attributes in the envelped message.
  5312. //
  5313. // pvData points to a CMSG_ATTR struct.
  5314. //--------------------------------------------------------------------------
  5315. //+-------------------------------------------------------------------------
  5316. // Perform a special "control" function after the final CryptMsgUpdate of a
  5317. // encoded/decoded cryptographic message.
  5318. //
  5319. // The dwCtrlType parameter specifies the type of operation to be performed.
  5320. //
  5321. // The pvCtrlPara definition depends on the dwCtrlType value.
  5322. //
  5323. // See below for a list of the control operations and their pvCtrlPara
  5324. // type definition.
  5325. //--------------------------------------------------------------------------
  5326. WINCRYPT32API
  5327. BOOL
  5328. WINAPI
  5329. CryptMsgControl(
  5330. IN HCRYPTMSG hCryptMsg,
  5331. IN DWORD dwFlags,
  5332. IN DWORD dwCtrlType,
  5333. IN void const *pvCtrlPara
  5334. );
  5335. //+-------------------------------------------------------------------------
  5336. // Message control types
  5337. //--------------------------------------------------------------------------
  5338. #define CMSG_CTRL_VERIFY_SIGNATURE 1
  5339. #define CMSG_CTRL_DECRYPT 2
  5340. #define CMSG_CTRL_VERIFY_HASH 5
  5341. #define CMSG_CTRL_ADD_SIGNER 6
  5342. #define CMSG_CTRL_DEL_SIGNER 7
  5343. #define CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR 8
  5344. #define CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR 9
  5345. #define CMSG_CTRL_ADD_CERT 10
  5346. #define CMSG_CTRL_DEL_CERT 11
  5347. #define CMSG_CTRL_ADD_CRL 12
  5348. #define CMSG_CTRL_DEL_CRL 13
  5349. #define CMSG_CTRL_ADD_ATTR_CERT 14
  5350. #define CMSG_CTRL_DEL_ATTR_CERT 15
  5351. #define CMSG_CTRL_KEY_TRANS_DECRYPT 16
  5352. #define CMSG_CTRL_KEY_AGREE_DECRYPT 17
  5353. #define CMSG_CTRL_MAIL_LIST_DECRYPT 18
  5354. #define CMSG_CTRL_VERIFY_SIGNATURE_EX 19
  5355. #define CMSG_CTRL_ADD_CMS_SIGNER_INFO 20
  5356. //+-------------------------------------------------------------------------
  5357. // CMSG_CTRL_VERIFY_SIGNATURE
  5358. //
  5359. // Verify the signature of a SIGNED or SIGNED_AND_ENVELOPED
  5360. // message after it has been decoded.
  5361. //
  5362. // For a SIGNED_AND_ENVELOPED message, called after
  5363. // CryptMsgControl(CMSG_CTRL_DECRYPT), if CryptMsgOpenToDecode was called
  5364. // with a NULL pRecipientInfo.
  5365. //
  5366. // pvCtrlPara points to a CERT_INFO struct.
  5367. //
  5368. // The CERT_INFO contains the Issuer and SerialNumber identifying
  5369. // the Signer of the message. The CERT_INFO also contains the
  5370. // PublicKeyInfo
  5371. // used to verify the signature. The cryptographic provider specified
  5372. // in CryptMsgOpenToDecode is used.
  5373. //
  5374. // Note, if the message contains CMS signers identified by KEYID, then,
  5375. // the CERT_INFO's Issuer and SerialNumber is ignored and only the public
  5376. // key is used to find a signer whose signature verifies.
  5377. //
  5378. // The following CMSG_CTRL_VERIFY_SIGNATURE_EX should be used instead.
  5379. //--------------------------------------------------------------------------
  5380. //+-------------------------------------------------------------------------
  5381. // CMSG_CTRL_VERIFY_SIGNATURE_EX
  5382. //
  5383. // Verify the signature of a SIGNED message after it has been decoded.
  5384. //
  5385. // pvCtrlPara points to the following CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA.
  5386. //
  5387. // If hCryptProv is NULL, uses the cryptographic provider specified in
  5388. // CryptMsgOpenToDecode. If CryptMsgOpenToDecode's hCryptProv is also NULL,
  5389. // gets default provider according to the signer's public key OID.
  5390. //
  5391. // dwSignerIndex is the index of the signer to use to verify the signature.
  5392. //
  5393. // The signer can be a pointer to a CERT_PUBLIC_KEY_INFO, certificate
  5394. // context or a chain context.
  5395. //
  5396. // If the signer's HashEncryptionAlgorithm is szOID_PKIX_NO_SIGNATURE, then,
  5397. // the signature is expected to contain the hash octets. Only dwSignerType
  5398. // of CMSG_VERIFY_SIGNER_NULL may be specified to verify this no signature
  5399. // case.
  5400. //--------------------------------------------------------------------------
  5401. typedef struct _CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA {
  5402. DWORD cbSize;
  5403. HCRYPTPROV hCryptProv;
  5404. DWORD dwSignerIndex;
  5405. DWORD dwSignerType;
  5406. void *pvSigner;
  5407. } CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA, *PCMSG_CTRL_VERIFY_SIGNATURE_EX_PARA;
  5408. // Signer Types
  5409. #define CMSG_VERIFY_SIGNER_PUBKEY 1
  5410. // pvSigner :: PCERT_PUBLIC_KEY_INFO
  5411. #define CMSG_VERIFY_SIGNER_CERT 2
  5412. // pvSigner :: PCCERT_CONTEXT
  5413. #define CMSG_VERIFY_SIGNER_CHAIN 3
  5414. // pvSigner :: PCCERT_CHAIN_CONTEXT
  5415. #define CMSG_VERIFY_SIGNER_NULL 4
  5416. // pvSigner :: NULL
  5417. //+-------------------------------------------------------------------------
  5418. // CMSG_CTRL_DECRYPT
  5419. //
  5420. // Decrypt an ENVELOPED or SIGNED_AND_ENVELOPED message after it has been
  5421. // decoded.
  5422. //
  5423. // This decrypt is only applicable to key transport recipients.
  5424. //
  5425. // hCryptProv and dwKeySpec specify the private key to use. For dwKeySpec ==
  5426. // 0, defaults to AT_KEYEXCHANGE.
  5427. //
  5428. // If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags passed
  5429. // to CryptMsgControl, then, the hCryptProv is released on the final
  5430. // CryptMsgClose. Not released if CryptMsgControl fails.
  5431. //
  5432. // dwRecipientIndex is the index of the recipient in the message associated
  5433. // with the hCryptProv's private key.
  5434. //
  5435. // The dwRecipientIndex is the index of a key transport recipient.
  5436. //
  5437. // Note, the message can only be decrypted once.
  5438. //--------------------------------------------------------------------------
  5439. typedef struct _CMSG_CTRL_DECRYPT_PARA {
  5440. DWORD cbSize;
  5441. HCRYPTPROV hCryptProv;
  5442. DWORD dwKeySpec;
  5443. DWORD dwRecipientIndex;
  5444. } CMSG_CTRL_DECRYPT_PARA, *PCMSG_CTRL_DECRYPT_PARA;
  5445. //+-------------------------------------------------------------------------
  5446. // CMSG_CTRL_KEY_TRANS_DECRYPT
  5447. //
  5448. // Decrypt an ENVELOPED message after it has been decoded for a key
  5449. // transport recipient.
  5450. //
  5451. // hCryptProv and dwKeySpec specify the private key to use. For dwKeySpec ==
  5452. // 0, defaults to AT_KEYEXCHANGE.
  5453. //
  5454. // If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags passed
  5455. // to CryptMsgControl, then, the hCryptProv is released on the final
  5456. // CryptMsgClose. Not released if CryptMsgControl fails.
  5457. //
  5458. // pKeyTrans points to the CMSG_KEY_TRANS_RECIPIENT_INFO obtained via
  5459. // CryptMsgGetParam(CMSG_CMS_RECIPIENT_INFO_PARAM)
  5460. //
  5461. // dwRecipientIndex is the index of the recipient in the message associated
  5462. // with the hCryptProv's private key.
  5463. //
  5464. // Note, the message can only be decrypted once.
  5465. //--------------------------------------------------------------------------
  5466. typedef struct _CMSG_CTRL_KEY_TRANS_DECRYPT_PARA {
  5467. DWORD cbSize;
  5468. HCRYPTPROV hCryptProv;
  5469. DWORD dwKeySpec;
  5470. PCMSG_KEY_TRANS_RECIPIENT_INFO pKeyTrans;
  5471. DWORD dwRecipientIndex;
  5472. } CMSG_CTRL_KEY_TRANS_DECRYPT_PARA, *PCMSG_CTRL_KEY_TRANS_DECRYPT_PARA;
  5473. //+-------------------------------------------------------------------------
  5474. // CMSG_CTRL_KEY_AGREE_DECRYPT
  5475. //
  5476. // Decrypt an ENVELOPED message after it has been decoded for a key
  5477. // agreement recipient.
  5478. //
  5479. // hCryptProv and dwKeySpec specify the private key to use. For dwKeySpec ==
  5480. // 0, defaults to AT_KEYEXCHANGE.
  5481. //
  5482. // If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags passed
  5483. // to CryptMsgControl, then, the hCryptProv is released on the final
  5484. // CryptMsgClose. Not released if CryptMsgControl fails.
  5485. //
  5486. // pKeyAgree points to the CMSG_KEY_AGREE_RECIPIENT_INFO obtained via
  5487. // CryptMsgGetParam(CMSG_CMS_RECIPIENT_INFO_PARAM) for dwRecipientIndex.
  5488. //
  5489. // dwRecipientIndex, dwRecipientEncryptedKeyIndex are the indices of the
  5490. // recipient's encrypted key in the message associated with the hCryptProv's
  5491. // private key.
  5492. //
  5493. // OriginatorPublicKey is the originator's public key obtained from either
  5494. // the originator's certificate or the CMSG_KEY_AGREE_RECIPIENT_INFO obtained
  5495. // via the CMSG_CMS_RECIPIENT_INFO_PARAM.
  5496. //
  5497. // Note, the message can only be decrypted once.
  5498. //--------------------------------------------------------------------------
  5499. typedef struct _CMSG_CTRL_KEY_AGREE_DECRYPT_PARA {
  5500. DWORD cbSize;
  5501. HCRYPTPROV hCryptProv;
  5502. DWORD dwKeySpec;
  5503. PCMSG_KEY_AGREE_RECIPIENT_INFO pKeyAgree;
  5504. DWORD dwRecipientIndex;
  5505. DWORD dwRecipientEncryptedKeyIndex;
  5506. CRYPT_BIT_BLOB OriginatorPublicKey;
  5507. } CMSG_CTRL_KEY_AGREE_DECRYPT_PARA, *PCMSG_CTRL_KEY_AGREE_DECRYPT_PARA;
  5508. //+-------------------------------------------------------------------------
  5509. // CMSG_CTRL_MAIL_LIST_DECRYPT
  5510. //
  5511. // Decrypt an ENVELOPED message after it has been decoded for a mail
  5512. // list recipient.
  5513. //
  5514. // pMailList points to the CMSG_MAIL_LIST_RECIPIENT_INFO obtained via
  5515. // CryptMsgGetParam(CMSG_CMS_RECIPIENT_INFO_PARAM) for dwRecipientIndex.
  5516. //
  5517. // There is 1 choice for the KeyEncryptionKey: an already created CSP key
  5518. // handle. For the key handle choice, hCryptProv must be nonzero. This key
  5519. // handle isn't destroyed.
  5520. //
  5521. // If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags passed
  5522. // to CryptMsgControl, then, the hCryptProv is released on the final
  5523. // CryptMsgClose. Not released if CryptMsgControl fails.
  5524. //
  5525. // For RC2 wrap, the effective key length is obtained from the
  5526. // KeyEncryptionAlgorithm parameters and set on the hKeyEncryptionKey before
  5527. // decrypting.
  5528. //
  5529. // Note, the message can only be decrypted once.
  5530. //--------------------------------------------------------------------------
  5531. typedef struct _CMSG_CTRL_MAIL_LIST_DECRYPT_PARA {
  5532. DWORD cbSize;
  5533. HCRYPTPROV hCryptProv;
  5534. PCMSG_MAIL_LIST_RECIPIENT_INFO pMailList;
  5535. DWORD dwRecipientIndex;
  5536. DWORD dwKeyChoice;
  5537. union {
  5538. // CMSG_MAIL_LIST_HANDLE_KEY_CHOICE
  5539. HCRYPTKEY hKeyEncryptionKey;
  5540. // Reserve space for a potential pointer choice
  5541. void *pvKeyEncryptionKey;
  5542. };
  5543. } CMSG_CTRL_MAIL_LIST_DECRYPT_PARA, *PCMSG_CTRL_MAIL_LIST_DECRYPT_PARA;
  5544. //+-------------------------------------------------------------------------
  5545. // CMSG_CTRL_VERIFY_HASH
  5546. //
  5547. // Verify the hash of a HASHED message after it has been decoded.
  5548. //
  5549. // Only the hCryptMsg parameter is used, to specify the message whose
  5550. // hash is being verified.
  5551. //--------------------------------------------------------------------------
  5552. //+-------------------------------------------------------------------------
  5553. // CMSG_CTRL_ADD_SIGNER
  5554. //
  5555. // Add a signer to a signed-data message.
  5556. //
  5557. // pvCtrlPara points to a CMSG_SIGNER_ENCODE_INFO.
  5558. //--------------------------------------------------------------------------
  5559. //+-------------------------------------------------------------------------
  5560. // CMSG_CTRL_ADD_CMS_SIGNER_INFO
  5561. //
  5562. // Add a signer to a signed-data message.
  5563. //
  5564. // Differs from the above, CMSG_CTRL_ADD_SIGNER, wherein, the signer info
  5565. // already contains the signature.
  5566. //
  5567. // pvCtrlPara points to a CMSG_CMS_SIGNER_INFO.
  5568. //--------------------------------------------------------------------------
  5569. //+-------------------------------------------------------------------------
  5570. // CMSG_CTRL_DEL_SIGNER
  5571. //
  5572. // Remove a signer from a signed-data or signed-and-enveloped-data message.
  5573. //
  5574. // pvCtrlPara points to a DWORD containing the 0-based index of the
  5575. // signer to be removed.
  5576. //--------------------------------------------------------------------------
  5577. //+-------------------------------------------------------------------------
  5578. // CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR
  5579. //
  5580. // Add an unauthenticated attribute to the SignerInfo of a signed-data or
  5581. // signed-and-enveloped-data message.
  5582. //
  5583. // The unauthenticated attribute is input in the form of an encoded blob.
  5584. //--------------------------------------------------------------------------
  5585. typedef struct _CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA {
  5586. DWORD cbSize;
  5587. DWORD dwSignerIndex;
  5588. CRYPT_DATA_BLOB blob;
  5589. } CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA, *PCMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA;
  5590. //+-------------------------------------------------------------------------
  5591. // CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR
  5592. //
  5593. // Delete an unauthenticated attribute from the SignerInfo of a signed-data
  5594. // or signed-and-enveloped-data message.
  5595. //
  5596. // The unauthenticated attribute to be removed is specified by
  5597. // a 0-based index.
  5598. //--------------------------------------------------------------------------
  5599. typedef struct _CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA {
  5600. DWORD cbSize;
  5601. DWORD dwSignerIndex;
  5602. DWORD dwUnauthAttrIndex;
  5603. } CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA, *PCMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA;
  5604. //+-------------------------------------------------------------------------
  5605. // CMSG_CTRL_ADD_CERT
  5606. //
  5607. // Add a certificate to a signed-data or signed-and-enveloped-data message.
  5608. //
  5609. // pvCtrlPara points to a CRYPT_DATA_BLOB containing the certificate's
  5610. // encoded bytes.
  5611. //--------------------------------------------------------------------------
  5612. //+-------------------------------------------------------------------------
  5613. // CMSG_CTRL_DEL_CERT
  5614. //
  5615. // Delete a certificate from a signed-data or signed-and-enveloped-data
  5616. // message.
  5617. //
  5618. // pvCtrlPara points to a DWORD containing the 0-based index of the
  5619. // certificate to be removed.
  5620. //--------------------------------------------------------------------------
  5621. //+-------------------------------------------------------------------------
  5622. // CMSG_CTRL_ADD_CRL
  5623. //
  5624. // Add a CRL to a signed-data or signed-and-enveloped-data message.
  5625. //
  5626. // pvCtrlPara points to a CRYPT_DATA_BLOB containing the CRL's
  5627. // encoded bytes.
  5628. //--------------------------------------------------------------------------
  5629. //+-------------------------------------------------------------------------
  5630. // CMSG_CTRL_DEL_CRL
  5631. //
  5632. // Delete a CRL from a signed-data or signed-and-enveloped-data message.
  5633. //
  5634. // pvCtrlPara points to a DWORD containing the 0-based index of the CRL
  5635. // to be removed.
  5636. //--------------------------------------------------------------------------
  5637. //+-------------------------------------------------------------------------
  5638. // CMSG_CTRL_ADD_ATTR_CERT
  5639. //
  5640. // Add an attribute certificate to a signed-data message.
  5641. //
  5642. // pvCtrlPara points to a CRYPT_DATA_BLOB containing the attribute
  5643. // certificate's encoded bytes.
  5644. //--------------------------------------------------------------------------
  5645. //+-------------------------------------------------------------------------
  5646. // CMSG_CTRL_DEL_ATTR_CERT
  5647. //
  5648. // Delete an attribute certificate from a signed-data message.
  5649. //
  5650. // pvCtrlPara points to a DWORD containing the 0-based index of the
  5651. // attribute certificate to be removed.
  5652. //--------------------------------------------------------------------------
  5653. //+-------------------------------------------------------------------------
  5654. // Verify a countersignature, at the SignerInfo level.
  5655. // ie. verify that pbSignerInfoCountersignature contains the encrypted
  5656. // hash of the encryptedDigest field of pbSignerInfo.
  5657. //
  5658. // hCryptProv is used to hash the encryptedDigest field of pbSignerInfo.
  5659. // The only fields referenced from pciCountersigner are SerialNumber, Issuer,
  5660. // and SubjectPublicKeyInfo.
  5661. //--------------------------------------------------------------------------
  5662. BOOL
  5663. WINAPI
  5664. CryptMsgVerifyCountersignatureEncoded(
  5665. IN HCRYPTPROV hCryptProv,
  5666. IN DWORD dwEncodingType,
  5667. IN PBYTE pbSignerInfo,
  5668. IN DWORD cbSignerInfo,
  5669. IN PBYTE pbSignerInfoCountersignature,
  5670. IN DWORD cbSignerInfoCountersignature,
  5671. IN PCERT_INFO pciCountersigner
  5672. );
  5673. //+-------------------------------------------------------------------------
  5674. // Verify a countersignature, at the SignerInfo level.
  5675. // ie. verify that pbSignerInfoCountersignature contains the encrypted
  5676. // hash of the encryptedDigest field of pbSignerInfo.
  5677. //
  5678. // hCryptProv is used to hash the encryptedDigest field of pbSignerInfo.
  5679. //
  5680. // The signer can be a CERT_PUBLIC_KEY_INFO, certificate context or a
  5681. // chain context.
  5682. //--------------------------------------------------------------------------
  5683. BOOL
  5684. WINAPI
  5685. CryptMsgVerifyCountersignatureEncodedEx(
  5686. IN HCRYPTPROV hCryptProv,
  5687. IN DWORD dwEncodingType,
  5688. IN PBYTE pbSignerInfo,
  5689. IN DWORD cbSignerInfo,
  5690. IN PBYTE pbSignerInfoCountersignature,
  5691. IN DWORD cbSignerInfoCountersignature,
  5692. IN DWORD dwSignerType,
  5693. IN void *pvSigner,
  5694. IN DWORD dwFlags,
  5695. IN OPTIONAL void *pvReserved
  5696. );
  5697. // See CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA for dwSignerType definitions
  5698. //+-------------------------------------------------------------------------
  5699. // Countersign an already-existing signature in a message
  5700. //
  5701. // dwIndex is a zero-based index of the SignerInfo to be countersigned.
  5702. //--------------------------------------------------------------------------
  5703. BOOL
  5704. WINAPI
  5705. CryptMsgCountersign(
  5706. IN OUT HCRYPTMSG hCryptMsg,
  5707. IN DWORD dwIndex,
  5708. IN DWORD cCountersigners,
  5709. IN PCMSG_SIGNER_ENCODE_INFO rgCountersigners
  5710. );
  5711. //+-------------------------------------------------------------------------
  5712. // Countersign an already-existing signature (encoded SignerInfo).
  5713. // Output an encoded SignerInfo blob, suitable for use as a countersignature
  5714. // attribute in the unauthenticated attributes of a signed-data or
  5715. // signed-and-enveloped-data message.
  5716. //--------------------------------------------------------------------------
  5717. BOOL
  5718. WINAPI
  5719. CryptMsgCountersignEncoded(
  5720. IN DWORD dwEncodingType,
  5721. IN PBYTE pbSignerInfo,
  5722. IN DWORD cbSignerInfo,
  5723. IN DWORD cCountersigners,
  5724. IN PCMSG_SIGNER_ENCODE_INFO rgCountersigners,
  5725. OUT PBYTE pbCountersignature,
  5726. IN OUT PDWORD pcbCountersignature
  5727. );
  5728. //+-------------------------------------------------------------------------
  5729. // CryptMsg OID installable functions
  5730. //--------------------------------------------------------------------------
  5731. typedef void * (WINAPI *PFN_CMSG_ALLOC) (
  5732. IN size_t cb
  5733. );
  5734. typedef void (WINAPI *PFN_CMSG_FREE)(
  5735. IN void *pv
  5736. );
  5737. // Note, the following 3 installable functions are obsolete and have been
  5738. // replaced with GenContentEncryptKey, ExportKeyTrans, ExportKeyAgree,
  5739. // ExportMailList, ImportKeyTrans, ImportKeyAgree and ImportMailList
  5740. // installable functions.
  5741. // If *phCryptProv is NULL upon entry, then, if supported, the installable
  5742. // function should acquire a default provider and return. Note, its up
  5743. // to the installable function to release at process detach.
  5744. //
  5745. // If paiEncrypt->Parameters.cbData is 0, then, the callback may optionally
  5746. // return default encoded parameters in *ppbEncryptParameters and
  5747. // *pcbEncryptParameters. pfnAlloc must be called for the allocation.
  5748. #define CMSG_OID_GEN_ENCRYPT_KEY_FUNC "CryptMsgDllGenEncryptKey"
  5749. typedef BOOL (WINAPI *PFN_CMSG_GEN_ENCRYPT_KEY) (
  5750. IN OUT HCRYPTPROV *phCryptProv,
  5751. IN PCRYPT_ALGORITHM_IDENTIFIER paiEncrypt,
  5752. IN PVOID pvEncryptAuxInfo,
  5753. IN PCERT_PUBLIC_KEY_INFO pPublicKeyInfo,
  5754. IN PFN_CMSG_ALLOC pfnAlloc,
  5755. OUT HCRYPTKEY *phEncryptKey,
  5756. OUT PBYTE *ppbEncryptParameters,
  5757. OUT PDWORD pcbEncryptParameters
  5758. );
  5759. #define CMSG_OID_EXPORT_ENCRYPT_KEY_FUNC "CryptMsgDllExportEncryptKey"
  5760. typedef BOOL (WINAPI *PFN_CMSG_EXPORT_ENCRYPT_KEY) (
  5761. IN HCRYPTPROV hCryptProv,
  5762. IN HCRYPTKEY hEncryptKey,
  5763. IN PCERT_PUBLIC_KEY_INFO pPublicKeyInfo,
  5764. OUT PBYTE pbData,
  5765. IN OUT PDWORD pcbData
  5766. );
  5767. #define CMSG_OID_IMPORT_ENCRYPT_KEY_FUNC "CryptMsgDllImportEncryptKey"
  5768. typedef BOOL (WINAPI *PFN_CMSG_IMPORT_ENCRYPT_KEY) (
  5769. IN HCRYPTPROV hCryptProv,
  5770. IN DWORD dwKeySpec,
  5771. IN PCRYPT_ALGORITHM_IDENTIFIER paiEncrypt,
  5772. IN PCRYPT_ALGORITHM_IDENTIFIER paiPubKey,
  5773. IN PBYTE pbEncodedKey,
  5774. IN DWORD cbEncodedKey,
  5775. OUT HCRYPTKEY *phEncryptKey
  5776. );
  5777. // To get the default installable function for GenContentEncryptKey,
  5778. // ExportKeyTrans, ExportKeyAgree, ExportMailList, ImportKeyTrans,
  5779. // ImportKeyAgree or ImportMailList call CryptGetOIDFunctionAddress()
  5780. // with the pszOID argument set to the following constant. dwEncodingType
  5781. // should be set to CRYPT_ASN_ENCODING or X509_ASN_ENCODING.
  5782. #define CMSG_DEFAULT_INSTALLABLE_FUNC_OID ((LPCSTR) 1)
  5783. //+-------------------------------------------------------------------------
  5784. // Content Encrypt Info
  5785. //
  5786. // The following data structure contains the information shared between
  5787. // the GenContentEncryptKey and the ExportKeyTrans, ExportKeyAgree and
  5788. // ExportMailList installable functions.
  5789. //--------------------------------------------------------------------------
  5790. typedef struct _CMSG_CONTENT_ENCRYPT_INFO {
  5791. DWORD cbSize;
  5792. HCRYPTPROV hCryptProv;
  5793. CRYPT_ALGORITHM_IDENTIFIER ContentEncryptionAlgorithm;
  5794. void *pvEncryptionAuxInfo;
  5795. DWORD cRecipients;
  5796. PCMSG_RECIPIENT_ENCODE_INFO rgCmsRecipients;
  5797. PFN_CMSG_ALLOC pfnAlloc;
  5798. PFN_CMSG_FREE pfnFree;
  5799. DWORD dwEncryptFlags;
  5800. HCRYPTKEY hContentEncryptKey;
  5801. DWORD dwFlags;
  5802. } CMSG_CONTENT_ENCRYPT_INFO, *PCMSG_CONTENT_ENCRYPT_INFO;
  5803. #define CMSG_CONTENT_ENCRYPT_PAD_ENCODED_LEN_FLAG 0x00000001
  5804. #define CMSG_CONTENT_ENCRYPT_FREE_PARA_FLAG 0x00000001
  5805. #define CMSG_CONTENT_ENCRYPT_RELEASE_CONTEXT_FLAG 0x00008000
  5806. //+-------------------------------------------------------------------------
  5807. // Upon input, ContentEncryptInfo has been initialized from the
  5808. // EnvelopedEncodeInfo.
  5809. //
  5810. // Note, if rgpRecipients instead of rgCmsRecipients are set in the
  5811. // EnvelopedEncodeInfo, then, the rgpRecipients have been converted
  5812. // to rgCmsRecipients in the ContentEncryptInfo.
  5813. //
  5814. // The following fields may be changed in ContentEncryptInfo:
  5815. // hContentEncryptKey
  5816. // hCryptProv
  5817. // ContentEncryptionAlgorithm.Parameters
  5818. // dwFlags
  5819. //
  5820. // All other fields in the ContentEncryptInfo are READONLY.
  5821. //
  5822. // If CMSG_CONTENT_ENCRYPT_PAD_ENCODED_LEN_FLAG is set upon entry
  5823. // in dwEncryptFlags, then, any potentially variable length encoded
  5824. // output should be padded with zeroes to always obtain the
  5825. // same maximum encoded length. This is necessary for
  5826. // CryptMsgCalculateEncodedLength() or CryptMsgOpenToEncode() with
  5827. // definite length streaming.
  5828. //
  5829. // The hContentEncryptKey must be updated.
  5830. //
  5831. // If hCryptProv is NULL upon input, then, it must be updated.
  5832. // If a HCRYPTPROV is acquired that must be released, then, the
  5833. // CMSG_CONTENT_ENCRYPT_RELEASE_CONTEXT_FLAG must be set in dwFlags.
  5834. //
  5835. // If ContentEncryptionAlgorithm.Parameters is updated, then, the
  5836. // CMSG_CONTENT_ENCRYPT_FREE_PARA_FLAG must be set in dwFlags. pfnAlloc and
  5837. // pfnFree must be used for doing the allocation.
  5838. //
  5839. // ContentEncryptionAlgorithm.pszObjId is used to get the OIDFunctionAddress.
  5840. //--------------------------------------------------------------------------
  5841. #define CMSG_OID_GEN_CONTENT_ENCRYPT_KEY_FUNC "CryptMsgDllGenContentEncryptKey"
  5842. typedef BOOL (WINAPI *PFN_CMSG_GEN_CONTENT_ENCRYPT_KEY) (
  5843. IN OUT PCMSG_CONTENT_ENCRYPT_INFO pContentEncryptInfo,
  5844. IN DWORD dwFlags,
  5845. IN OPTIONAL void *pvReserved
  5846. );
  5847. //+-------------------------------------------------------------------------
  5848. // Key Transport Encrypt Info
  5849. //
  5850. // The following data structure contains the information updated by the
  5851. // ExportKeyTrans installable function.
  5852. //--------------------------------------------------------------------------
  5853. typedef struct _CMSG_KEY_TRANS_ENCRYPT_INFO {
  5854. DWORD cbSize;
  5855. DWORD dwRecipientIndex;
  5856. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  5857. CRYPT_DATA_BLOB EncryptedKey;
  5858. DWORD dwFlags;
  5859. } CMSG_KEY_TRANS_ENCRYPT_INFO, *PCMSG_KEY_TRANS_ENCRYPT_INFO;
  5860. #define CMSG_KEY_TRANS_ENCRYPT_FREE_PARA_FLAG 0x00000001
  5861. //+-------------------------------------------------------------------------
  5862. // Upon input, KeyTransEncryptInfo has been initialized from the
  5863. // KeyTransEncodeInfo.
  5864. //
  5865. // The following fields may be changed in KeyTransEncryptInfo:
  5866. // EncryptedKey
  5867. // KeyEncryptionAlgorithm.Parameters
  5868. // dwFlags
  5869. //
  5870. // All other fields in the KeyTransEncryptInfo are READONLY.
  5871. //
  5872. // The EncryptedKey must be updated. The pfnAlloc and pfnFree specified in
  5873. // ContentEncryptInfo must be used for doing the allocation.
  5874. //
  5875. // If the KeyEncryptionAlgorithm.Parameters is updated, then, the
  5876. // CMSG_KEY_TRANS_ENCRYPT_FREE_PARA_FLAG must be set in dwFlags.
  5877. // The pfnAlloc and pfnFree specified in ContentEncryptInfo must be used
  5878. // for doing the allocation.
  5879. //
  5880. // KeyEncryptionAlgorithm.pszObjId is used to get the OIDFunctionAddress.
  5881. //--------------------------------------------------------------------------
  5882. #define CMSG_OID_EXPORT_KEY_TRANS_FUNC "CryptMsgDllExportKeyTrans"
  5883. typedef BOOL (WINAPI *PFN_CMSG_EXPORT_KEY_TRANS) (
  5884. IN PCMSG_CONTENT_ENCRYPT_INFO pContentEncryptInfo,
  5885. IN PCMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO pKeyTransEncodeInfo,
  5886. IN OUT PCMSG_KEY_TRANS_ENCRYPT_INFO pKeyTransEncryptInfo,
  5887. IN DWORD dwFlags,
  5888. IN OPTIONAL void *pvReserved
  5889. );
  5890. //+-------------------------------------------------------------------------
  5891. // Key Agree Key Encrypt Info
  5892. //
  5893. // The following data structure contains the information updated by the
  5894. // ExportKeyAgree installable function for each encrypted key agree
  5895. // recipient.
  5896. //--------------------------------------------------------------------------
  5897. typedef struct _CMSG_KEY_AGREE_KEY_ENCRYPT_INFO {
  5898. DWORD cbSize;
  5899. CRYPT_DATA_BLOB EncryptedKey;
  5900. } CMSG_KEY_AGREE_KEY_ENCRYPT_INFO, *PCMSG_KEY_AGREE_KEY_ENCRYPT_INFO;
  5901. //+-------------------------------------------------------------------------
  5902. // Key Agree Encrypt Info
  5903. //
  5904. // The following data structure contains the information applicable to
  5905. // all recipients. Its updated by the ExportKeyAgree installable function.
  5906. //--------------------------------------------------------------------------
  5907. typedef struct _CMSG_KEY_AGREE_ENCRYPT_INFO {
  5908. DWORD cbSize;
  5909. DWORD dwRecipientIndex;
  5910. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  5911. CRYPT_DATA_BLOB UserKeyingMaterial;
  5912. DWORD dwOriginatorChoice;
  5913. union {
  5914. // CMSG_KEY_AGREE_ORIGINATOR_CERT
  5915. CERT_ID OriginatorCertId;
  5916. // CMSG_KEY_AGREE_ORIGINATOR_PUBLIC_KEY
  5917. CERT_PUBLIC_KEY_INFO OriginatorPublicKeyInfo;
  5918. };
  5919. DWORD cKeyAgreeKeyEncryptInfo;
  5920. PCMSG_KEY_AGREE_KEY_ENCRYPT_INFO *rgpKeyAgreeKeyEncryptInfo;
  5921. DWORD dwFlags;
  5922. } CMSG_KEY_AGREE_ENCRYPT_INFO, *PCMSG_KEY_AGREE_ENCRYPT_INFO;
  5923. #define CMSG_KEY_AGREE_ENCRYPT_FREE_PARA_FLAG 0x00000001
  5924. #define CMSG_KEY_AGREE_ENCRYPT_FREE_MATERIAL_FLAG 0x00000002
  5925. #define CMSG_KEY_AGREE_ENCRYPT_FREE_PUBKEY_ALG_FLAG 0x00000004
  5926. #define CMSG_KEY_AGREE_ENCRYPT_FREE_PUBKEY_PARA_FLAG 0x00000008
  5927. #define CMSG_KEY_AGREE_ENCRYPT_FREE_PUBKEY_BITS_FLAG 0x00000010
  5928. //+-------------------------------------------------------------------------
  5929. // Upon input, KeyAgreeEncryptInfo has been initialized from the
  5930. // KeyAgreeEncodeInfo.
  5931. //
  5932. // The following fields may be changed in KeyAgreeEncryptInfo:
  5933. // KeyEncryptionAlgorithm.Parameters
  5934. // UserKeyingMaterial
  5935. // dwOriginatorChoice
  5936. // OriginatorCertId
  5937. // OriginatorPublicKeyInfo
  5938. // dwFlags
  5939. //
  5940. // All other fields in the KeyAgreeEncryptInfo are READONLY.
  5941. //
  5942. // If the KeyEncryptionAlgorithm.Parameters is updated, then, the
  5943. // CMSG_KEY_AGREE_ENCRYPT_FREE_PARA_FLAG must be set in dwFlags.
  5944. // The pfnAlloc and pfnFree specified in ContentEncryptInfo must be used
  5945. // for doing the allocation.
  5946. //
  5947. // If the UserKeyingMaterial is updated, then, the
  5948. // CMSG_KEY_AGREE_ENCRYPT_FREE_MATERIAL_FLAG must be set in dwFlags.
  5949. // pfnAlloc and pfnFree must be used for doing the allocation.
  5950. //
  5951. // The dwOriginatorChoice must be updated to either
  5952. // CMSG_KEY_AGREE_ORIGINATOR_CERT or CMSG_KEY_AGREE_ORIGINATOR_PUBLIC_KEY.
  5953. //
  5954. // If the OriginatorPublicKeyInfo is updated, then, the appropriate
  5955. // CMSG_KEY_AGREE_ENCRYPT_FREE_PUBKEY_*_FLAG must be set in dwFlags and
  5956. // pfnAlloc and pfnFree must be used for doing the allocation.
  5957. //
  5958. // If CMSG_CONTENT_ENCRYPT_PAD_ENCODED_LEN_FLAG is set upon entry
  5959. // in pContentEncryptInfo->dwEncryptFlags, then, the OriginatorPublicKeyInfo's
  5960. // Ephemeral PublicKey should be padded with zeroes to always obtain the
  5961. // same maximum encoded length. Note, the length of the generated ephemeral Y
  5962. // public key can vary depending on the number of leading zero bits.
  5963. //
  5964. // Upon input, the array of *rgpKeyAgreeKeyEncryptInfo has been initialized.
  5965. // The EncryptedKey must be updated for each recipient key.
  5966. // The pfnAlloc and pfnFree specified in
  5967. // ContentEncryptInfo must be used for doing the allocation.
  5968. //
  5969. // KeyEncryptionAlgorithm.pszObjId is used to get the OIDFunctionAddress.
  5970. //--------------------------------------------------------------------------
  5971. #define CMSG_OID_EXPORT_KEY_AGREE_FUNC "CryptMsgDllExportKeyAgree"
  5972. typedef BOOL (WINAPI *PFN_CMSG_EXPORT_KEY_AGREE) (
  5973. IN PCMSG_CONTENT_ENCRYPT_INFO pContentEncryptInfo,
  5974. IN PCMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO pKeyAgreeEncodeInfo,
  5975. IN OUT PCMSG_KEY_AGREE_ENCRYPT_INFO pKeyAgreeEncryptInfo,
  5976. IN DWORD dwFlags,
  5977. IN OPTIONAL void *pvReserved
  5978. );
  5979. //+-------------------------------------------------------------------------
  5980. // Mail List Encrypt Info
  5981. //
  5982. // The following data structure contains the information updated by the
  5983. // ExportMailList installable function.
  5984. //--------------------------------------------------------------------------
  5985. typedef struct _CMSG_MAIL_LIST_ENCRYPT_INFO {
  5986. DWORD cbSize;
  5987. DWORD dwRecipientIndex;
  5988. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  5989. CRYPT_DATA_BLOB EncryptedKey;
  5990. DWORD dwFlags;
  5991. } CMSG_MAIL_LIST_ENCRYPT_INFO, *PCMSG_MAIL_LIST_ENCRYPT_INFO;
  5992. #define CMSG_MAIL_LIST_ENCRYPT_FREE_PARA_FLAG 0x00000001
  5993. //+-------------------------------------------------------------------------
  5994. // Upon input, MailListEncryptInfo has been initialized from the
  5995. // MailListEncodeInfo.
  5996. //
  5997. // The following fields may be changed in MailListEncryptInfo:
  5998. // EncryptedKey
  5999. // KeyEncryptionAlgorithm.Parameters
  6000. // dwFlags
  6001. //
  6002. // All other fields in the MailListEncryptInfo are READONLY.
  6003. //
  6004. // The EncryptedKey must be updated. The pfnAlloc and pfnFree specified in
  6005. // ContentEncryptInfo must be used for doing the allocation.
  6006. //
  6007. // If the KeyEncryptionAlgorithm.Parameters is updated, then, the
  6008. // CMSG_MAIL_LIST_ENCRYPT_FREE_PARA_FLAG must be set in dwFlags.
  6009. // The pfnAlloc and pfnFree specified in ContentEncryptInfo must be used
  6010. // for doing the allocation.
  6011. //
  6012. // KeyEncryptionAlgorithm.pszObjId is used to get the OIDFunctionAddress.
  6013. //--------------------------------------------------------------------------
  6014. #define CMSG_OID_EXPORT_MAIL_LIST_FUNC "CryptMsgDllExportMailList"
  6015. typedef BOOL (WINAPI *PFN_CMSG_EXPORT_MAIL_LIST) (
  6016. IN PCMSG_CONTENT_ENCRYPT_INFO pContentEncryptInfo,
  6017. IN PCMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO pMailListEncodeInfo,
  6018. IN OUT PCMSG_MAIL_LIST_ENCRYPT_INFO pMailListEncryptInfo,
  6019. IN DWORD dwFlags,
  6020. IN OPTIONAL void *pvReserved
  6021. );
  6022. //+-------------------------------------------------------------------------
  6023. // OID Installable functions for importing an encoded and encrypted content
  6024. // encryption key.
  6025. //
  6026. // There's a different installable function for each CMS Recipient choice:
  6027. // ImportKeyTrans
  6028. // ImportKeyAgree
  6029. // ImportMailList
  6030. //
  6031. // Iterates through the following OIDs to get the OID installable function:
  6032. // KeyEncryptionOID!ContentEncryptionOID
  6033. // KeyEncryptionOID
  6034. // ContentEncryptionOID
  6035. //
  6036. // If the OID installable function doesn't support the specified
  6037. // KeyEncryption and ContentEncryption OIDs, then, return FALSE with
  6038. // LastError set to E_NOTIMPL.
  6039. //--------------------------------------------------------------------------
  6040. #define CMSG_OID_IMPORT_KEY_TRANS_FUNC "CryptMsgDllImportKeyTrans"
  6041. typedef BOOL (WINAPI *PFN_CMSG_IMPORT_KEY_TRANS) (
  6042. IN PCRYPT_ALGORITHM_IDENTIFIER pContentEncryptionAlgorithm,
  6043. IN PCMSG_CTRL_KEY_TRANS_DECRYPT_PARA pKeyTransDecryptPara,
  6044. IN DWORD dwFlags,
  6045. IN OPTIONAL void *pvReserved,
  6046. OUT HCRYPTKEY *phContentEncryptKey
  6047. );
  6048. #define CMSG_OID_IMPORT_KEY_AGREE_FUNC "CryptMsgDllImportKeyAgree"
  6049. typedef BOOL (WINAPI *PFN_CMSG_IMPORT_KEY_AGREE) (
  6050. IN PCRYPT_ALGORITHM_IDENTIFIER pContentEncryptionAlgorithm,
  6051. IN PCMSG_CTRL_KEY_AGREE_DECRYPT_PARA pKeyAgreeDecryptPara,
  6052. IN DWORD dwFlags,
  6053. IN OPTIONAL void *pvReserved,
  6054. OUT HCRYPTKEY *phContentEncryptKey
  6055. );
  6056. #define CMSG_OID_IMPORT_MAIL_LIST_FUNC "CryptMsgDllImportMailList"
  6057. typedef BOOL (WINAPI *PFN_CMSG_IMPORT_MAIL_LIST) (
  6058. IN PCRYPT_ALGORITHM_IDENTIFIER pContentEncryptionAlgorithm,
  6059. IN PCMSG_CTRL_MAIL_LIST_DECRYPT_PARA pMailListDecryptPara,
  6060. IN DWORD dwFlags,
  6061. IN OPTIONAL void *pvReserved,
  6062. OUT HCRYPTKEY *phContentEncryptKey
  6063. );
  6064. //+=========================================================================
  6065. // Certificate Store Data Structures and APIs
  6066. //==========================================================================
  6067. //+-------------------------------------------------------------------------
  6068. // In its most basic implementation, a cert store is simply a
  6069. // collection of certificates and/or CRLs. This is the case when
  6070. // a cert store is opened with all of its certificates and CRLs
  6071. // coming from a PKCS #7 encoded cryptographic message.
  6072. //
  6073. // Nonetheless, all cert stores have the following properties:
  6074. // - A public key may have more than one certificate in the store.
  6075. // For example, a private/public key used for signing may have a
  6076. // certificate issued for VISA and another issued for
  6077. // Mastercard. Also, when a certificate is renewed there might
  6078. // be more than one certificate with the same subject and
  6079. // issuer.
  6080. // - However, each certificate in the store is uniquely
  6081. // identified by its Issuer and SerialNumber.
  6082. // - There's an issuer of subject certificate relationship. A
  6083. // certificate's issuer is found by doing a match of
  6084. // pSubjectCert->Issuer with pIssuerCert->Subject.
  6085. // The relationship is verified by using
  6086. // the issuer's public key to verify the subject certificate's
  6087. // signature. Note, there might be X.509 v3 extensions
  6088. // to assist in finding the issuer certificate.
  6089. // - Since issuer certificates might be renewed, a subject
  6090. // certificate might have more than one issuer certificate.
  6091. // - There's an issuer of CRL relationship. An
  6092. // issuer's CRL is found by doing a match of
  6093. // pIssuerCert->Subject with pCrl->Issuer.
  6094. // The relationship is verified by using
  6095. // the issuer's public key to verify the CRL's
  6096. // signature. Note, there might be X.509 v3 extensions
  6097. // to assist in finding the CRL.
  6098. // - Since some issuers might support the X.509 v3 delta CRL
  6099. // extensions, an issuer might have more than one CRL.
  6100. // - The store shouldn't have any redundant certificates or
  6101. // CRLs. There shouldn't be two certificates with the same
  6102. // Issuer and SerialNumber. There shouldn't be two CRLs with
  6103. // the same Issuer, ThisUpdate and NextUpdate.
  6104. // - The store has NO policy or trust information. No
  6105. // certificates are tagged as being "root". Its up to
  6106. // the application to maintain a list of CertIds (Issuer +
  6107. // SerialNumber) for certificates it trusts.
  6108. // - The store might contain bad certificates and/or CRLs.
  6109. // The issuer's signature of a subject certificate or CRL may
  6110. // not verify. Certificates or CRLs may not satisfy their
  6111. // time validity requirements. Certificates may be
  6112. // revoked.
  6113. //
  6114. // In addition to the certificates and CRLs, properties can be
  6115. // stored. There are two predefined property IDs for a user
  6116. // certificate: CERT_KEY_PROV_HANDLE_PROP_ID and
  6117. // CERT_KEY_PROV_INFO_PROP_ID. The CERT_KEY_PROV_HANDLE_PROP_ID
  6118. // is a HCRYPTPROV handle to the private key assoicated
  6119. // with the certificate. The CERT_KEY_PROV_INFO_PROP_ID contains
  6120. // information to be used to call
  6121. // CryptAcquireContext and CryptSetProvParam to get a handle
  6122. // to the private key associated with the certificate.
  6123. //
  6124. // There exists two more predefined property IDs for certificates
  6125. // and CRLs, CERT_SHA1_HASH_PROP_ID and CERT_MD5_HASH_PROP_ID.
  6126. // If these properties don't already exist, then, a hash of the
  6127. // content is computed. (CERT_HASH_PROP_ID maps to the default
  6128. // hash algorithm, currently, CERT_SHA1_HASH_PROP_ID).
  6129. //
  6130. // There are additional APIs for creating certificate and CRL
  6131. // contexts not in a store (CertCreateCertificateContext and
  6132. // CertCreateCRLContext).
  6133. //
  6134. //--------------------------------------------------------------------------
  6135. typedef void *HCERTSTORE;
  6136. //+-------------------------------------------------------------------------
  6137. // Certificate context.
  6138. //
  6139. // A certificate context contains both the encoded and decoded representation
  6140. // of a certificate. A certificate context returned by a cert store function
  6141. // must be freed by calling the CertFreeCertificateContext function. The
  6142. // CertDuplicateCertificateContext function can be called to make a duplicate
  6143. // copy (which also must be freed by calling CertFreeCertificateContext).
  6144. //--------------------------------------------------------------------------
  6145. typedef struct _CERT_CONTEXT {
  6146. DWORD dwCertEncodingType;
  6147. BYTE *pbCertEncoded;
  6148. DWORD cbCertEncoded;
  6149. PCERT_INFO pCertInfo;
  6150. HCERTSTORE hCertStore;
  6151. } CERT_CONTEXT, *PCERT_CONTEXT;
  6152. typedef const CERT_CONTEXT *PCCERT_CONTEXT;
  6153. //+-------------------------------------------------------------------------
  6154. // CRL context.
  6155. //
  6156. // A CRL context contains both the encoded and decoded representation
  6157. // of a CRL. A CRL context returned by a cert store function
  6158. // must be freed by calling the CertFreeCRLContext function. The
  6159. // CertDuplicateCRLContext function can be called to make a duplicate
  6160. // copy (which also must be freed by calling CertFreeCRLContext).
  6161. //--------------------------------------------------------------------------
  6162. typedef struct _CRL_CONTEXT {
  6163. DWORD dwCertEncodingType;
  6164. BYTE *pbCrlEncoded;
  6165. DWORD cbCrlEncoded;
  6166. PCRL_INFO pCrlInfo;
  6167. HCERTSTORE hCertStore;
  6168. } CRL_CONTEXT, *PCRL_CONTEXT;
  6169. typedef const CRL_CONTEXT *PCCRL_CONTEXT;
  6170. //+-------------------------------------------------------------------------
  6171. // Certificate Trust List (CTL) context.
  6172. //
  6173. // A CTL context contains both the encoded and decoded representation
  6174. // of a CTL. Also contains an opened HCRYPTMSG handle to the decoded
  6175. // cryptographic signed message containing the CTL_INFO as its inner content.
  6176. // pbCtlContent is the encoded inner content of the signed message.
  6177. //
  6178. // The CryptMsg APIs can be used to extract additional signer information.
  6179. //--------------------------------------------------------------------------
  6180. typedef struct _CTL_CONTEXT {
  6181. DWORD dwMsgAndCertEncodingType;
  6182. BYTE *pbCtlEncoded;
  6183. DWORD cbCtlEncoded;
  6184. PCTL_INFO pCtlInfo;
  6185. HCERTSTORE hCertStore;
  6186. HCRYPTMSG hCryptMsg;
  6187. BYTE *pbCtlContent;
  6188. DWORD cbCtlContent;
  6189. } CTL_CONTEXT, *PCTL_CONTEXT;
  6190. typedef const CTL_CONTEXT *PCCTL_CONTEXT;
  6191. //+-------------------------------------------------------------------------
  6192. // Certificate, CRL and CTL property IDs
  6193. //
  6194. // See CertSetCertificateContextProperty or CertGetCertificateContextProperty
  6195. // for usage information.
  6196. //--------------------------------------------------------------------------
  6197. #define CERT_KEY_PROV_HANDLE_PROP_ID 1
  6198. #define CERT_KEY_PROV_INFO_PROP_ID 2
  6199. #define CERT_SHA1_HASH_PROP_ID 3
  6200. #define CERT_MD5_HASH_PROP_ID 4
  6201. #define CERT_HASH_PROP_ID CERT_SHA1_HASH_PROP_ID
  6202. #define CERT_KEY_CONTEXT_PROP_ID 5
  6203. #define CERT_KEY_SPEC_PROP_ID 6
  6204. #define CERT_IE30_RESERVED_PROP_ID 7
  6205. #define CERT_PUBKEY_HASH_RESERVED_PROP_ID 8
  6206. #define CERT_ENHKEY_USAGE_PROP_ID 9
  6207. #define CERT_CTL_USAGE_PROP_ID CERT_ENHKEY_USAGE_PROP_ID
  6208. #define CERT_NEXT_UPDATE_LOCATION_PROP_ID 10
  6209. #define CERT_FRIENDLY_NAME_PROP_ID 11
  6210. #define CERT_PVK_FILE_PROP_ID 12
  6211. #define CERT_DESCRIPTION_PROP_ID 13
  6212. #define CERT_ACCESS_STATE_PROP_ID 14
  6213. #define CERT_SIGNATURE_HASH_PROP_ID 15
  6214. #define CERT_SMART_CARD_DATA_PROP_ID 16
  6215. #define CERT_EFS_PROP_ID 17
  6216. #define CERT_FORTEZZA_DATA_PROP_ID 18
  6217. #define CERT_ARCHIVED_PROP_ID 19
  6218. #define CERT_KEY_IDENTIFIER_PROP_ID 20
  6219. #define CERT_AUTO_ENROLL_PROP_ID 21
  6220. #define CERT_PUBKEY_ALG_PARA_PROP_ID 22
  6221. #define CERT_CROSS_CERT_DIST_POINTS_PROP_ID 23
  6222. #define CERT_ISSUER_PUBLIC_KEY_MD5_HASH_PROP_ID 24
  6223. #define CERT_SUBJECT_PUBLIC_KEY_MD5_HASH_PROP_ID 25
  6224. #define CERT_ENROLLMENT_PROP_ID 26
  6225. #define CERT_DATE_STAMP_PROP_ID 27
  6226. #define CERT_ISSUER_SERIAL_NUMBER_MD5_HASH_PROP_ID 28
  6227. #define CERT_SUBJECT_NAME_MD5_HASH_PROP_ID 29
  6228. #define CERT_EXTENDED_ERROR_INFO_PROP_ID 30
  6229. // Note, 32 - 35 are reserved for the CERT, CRL, CTL and KeyId file element IDs.
  6230. // 36 - 63 are reserved for future element IDs.
  6231. #define CERT_RENEWAL_PROP_ID 64
  6232. #define CERT_ARCHIVED_KEY_HASH_PROP_ID 65
  6233. #define CERT_FIRST_RESERVED_PROP_ID 66
  6234. #define CERT_LAST_RESERVED_PROP_ID 0x00007FFF
  6235. #define CERT_FIRST_USER_PROP_ID 0x00008000
  6236. #define CERT_LAST_USER_PROP_ID 0x0000FFFF
  6237. #define IS_CERT_HASH_PROP_ID(X) (CERT_SHA1_HASH_PROP_ID == (X) || \
  6238. CERT_MD5_HASH_PROP_ID == (X) || \
  6239. CERT_SIGNATURE_HASH_PROP_ID == (X))
  6240. #define IS_PUBKEY_HASH_PROP_ID(X) (CERT_ISSUER_PUBLIC_KEY_MD5_HASH_PROP_ID == (X) || \
  6241. CERT_SUBJECT_PUBLIC_KEY_MD5_HASH_PROP_ID == (X))
  6242. #define IS_CHAIN_HASH_PROP_ID(X) (CERT_ISSUER_PUBLIC_KEY_MD5_HASH_PROP_ID == (X) || \
  6243. CERT_SUBJECT_PUBLIC_KEY_MD5_HASH_PROP_ID == (X) || \
  6244. CERT_ISSUER_SERIAL_NUMBER_MD5_HASH_PROP_ID == (X) || \
  6245. CERT_SUBJECT_NAME_MD5_HASH_PROP_ID == (X))
  6246. //+-------------------------------------------------------------------------
  6247. // Property OIDs
  6248. //--------------------------------------------------------------------------
  6249. // The OID component following the prefix contains the PROP_ID (decimal)
  6250. #define szOID_CERT_PROP_ID_PREFIX "1.3.6.1.4.1.311.10.11."
  6251. #define szOID_CERT_KEY_IDENTIFIER_PROP_ID "1.3.6.1.4.1.311.10.11.20"
  6252. #define szOID_CERT_ISSUER_SERIAL_NUMBER_MD5_HASH_PROP_ID \
  6253. "1.3.6.1.4.1.311.10.11.28"
  6254. #define szOID_CERT_SUBJECT_NAME_MD5_HASH_PROP_ID \
  6255. "1.3.6.1.4.1.311.10.11.29"
  6256. //+-------------------------------------------------------------------------
  6257. // Access State flags returned by CERT_ACCESS_STATE_PROP_ID. Note,
  6258. // CERT_ACCESS_PROP_ID is read only.
  6259. //--------------------------------------------------------------------------
  6260. // Set if context property writes are persisted. For instance, not set for
  6261. // memory store contexts. Set for registry based stores opened as read or write.
  6262. // Not set for registry based stores opened as read only.
  6263. #define CERT_ACCESS_STATE_WRITE_PERSIST_FLAG 0x1
  6264. // Set if context resides in a SYSTEM or SYSTEM_REGISTRY store.
  6265. #define CERT_ACCESS_STATE_SYSTEM_STORE_FLAG 0x2
  6266. //+-------------------------------------------------------------------------
  6267. // Cryptographic Key Provider Information
  6268. //
  6269. // CRYPT_KEY_PROV_INFO defines the CERT_KEY_PROV_INFO_PROP_ID's pvData.
  6270. //
  6271. // The CRYPT_KEY_PROV_INFO fields are passed to CryptAcquireContext
  6272. // to get a HCRYPTPROV handle. The optional CRYPT_KEY_PROV_PARAM fields are
  6273. // passed to CryptSetProvParam to further initialize the provider.
  6274. //
  6275. // The dwKeySpec field identifies the private key to use from the container
  6276. // For example, AT_KEYEXCHANGE or AT_SIGNATURE.
  6277. //--------------------------------------------------------------------------
  6278. typedef struct _CRYPT_KEY_PROV_PARAM {
  6279. DWORD dwParam;
  6280. BYTE *pbData;
  6281. DWORD cbData;
  6282. DWORD dwFlags;
  6283. } CRYPT_KEY_PROV_PARAM, *PCRYPT_KEY_PROV_PARAM;
  6284. typedef struct _CRYPT_KEY_PROV_INFO {
  6285. LPWSTR pwszContainerName;
  6286. LPWSTR pwszProvName;
  6287. DWORD dwProvType;
  6288. DWORD dwFlags;
  6289. DWORD cProvParam;
  6290. PCRYPT_KEY_PROV_PARAM rgProvParam;
  6291. DWORD dwKeySpec;
  6292. } CRYPT_KEY_PROV_INFO, *PCRYPT_KEY_PROV_INFO;
  6293. //+-------------------------------------------------------------------------
  6294. // The following flag should be set in the above dwFlags to enable
  6295. // a CertSetCertificateContextProperty(CERT_KEY_CONTEXT_PROP_ID) after a
  6296. // CryptAcquireContext is done in the Sign or Decrypt Message functions.
  6297. //
  6298. // The following define must not collide with any of the
  6299. // CryptAcquireContext dwFlag defines.
  6300. //--------------------------------------------------------------------------
  6301. #define CERT_SET_KEY_PROV_HANDLE_PROP_ID 0x00000001
  6302. #define CERT_SET_KEY_CONTEXT_PROP_ID 0x00000001
  6303. //+-------------------------------------------------------------------------
  6304. // Certificate Key Context
  6305. //
  6306. // CERT_KEY_CONTEXT defines the CERT_KEY_CONTEXT_PROP_ID's pvData.
  6307. //--------------------------------------------------------------------------
  6308. typedef struct _CERT_KEY_CONTEXT {
  6309. DWORD cbSize; // sizeof(CERT_KEY_CONTEXT)
  6310. HCRYPTPROV hCryptProv;
  6311. DWORD dwKeySpec;
  6312. } CERT_KEY_CONTEXT, *PCERT_KEY_CONTEXT;
  6313. //+-------------------------------------------------------------------------
  6314. // Certificate Store Provider Types
  6315. //--------------------------------------------------------------------------
  6316. #define CERT_STORE_PROV_MSG ((LPCSTR) 1)
  6317. #define CERT_STORE_PROV_MEMORY ((LPCSTR) 2)
  6318. #define CERT_STORE_PROV_FILE ((LPCSTR) 3)
  6319. #define CERT_STORE_PROV_REG ((LPCSTR) 4)
  6320. #define CERT_STORE_PROV_PKCS7 ((LPCSTR) 5)
  6321. #define CERT_STORE_PROV_SERIALIZED ((LPCSTR) 6)
  6322. #define CERT_STORE_PROV_FILENAME_A ((LPCSTR) 7)
  6323. #define CERT_STORE_PROV_FILENAME_W ((LPCSTR) 8)
  6324. #define CERT_STORE_PROV_FILENAME CERT_STORE_PROV_FILENAME_W
  6325. #define CERT_STORE_PROV_SYSTEM_A ((LPCSTR) 9)
  6326. #define CERT_STORE_PROV_SYSTEM_W ((LPCSTR) 10)
  6327. #define CERT_STORE_PROV_SYSTEM CERT_STORE_PROV_SYSTEM_W
  6328. #define CERT_STORE_PROV_COLLECTION ((LPCSTR) 11)
  6329. #define CERT_STORE_PROV_SYSTEM_REGISTRY_A ((LPCSTR) 12)
  6330. #define CERT_STORE_PROV_SYSTEM_REGISTRY_W ((LPCSTR) 13)
  6331. #define CERT_STORE_PROV_SYSTEM_REGISTRY CERT_STORE_PROV_SYSTEM_REGISTRY_W
  6332. #define CERT_STORE_PROV_PHYSICAL_W ((LPCSTR) 14)
  6333. #define CERT_STORE_PROV_PHYSICAL CERT_STORE_PROV_PHYSICAL_W
  6334. #define CERT_STORE_PROV_SMART_CARD_W ((LPCSTR) 15)
  6335. #define CERT_STORE_PROV_SMART_CARD CERT_STORE_PROV_SMART_CARD_W
  6336. #define CERT_STORE_PROV_LDAP_W ((LPCSTR) 16)
  6337. #define CERT_STORE_PROV_LDAP CERT_STORE_PROV_LDAP_W
  6338. #define sz_CERT_STORE_PROV_MEMORY "Memory"
  6339. #define sz_CERT_STORE_PROV_FILENAME_W "File"
  6340. #define sz_CERT_STORE_PROV_FILENAME sz_CERT_STORE_PROV_FILENAME_W
  6341. #define sz_CERT_STORE_PROV_SYSTEM_W "System"
  6342. #define sz_CERT_STORE_PROV_SYSTEM sz_CERT_STORE_PROV_SYSTEM_W
  6343. #define sz_CERT_STORE_PROV_PKCS7 "PKCS7"
  6344. #define sz_CERT_STORE_PROV_SERIALIZED "Serialized"
  6345. #define sz_CERT_STORE_PROV_COLLECTION "Collection"
  6346. #define sz_CERT_STORE_PROV_SYSTEM_REGISTRY_W "SystemRegistry"
  6347. #define sz_CERT_STORE_PROV_SYSTEM_REGISTRY sz_CERT_STORE_PROV_SYSTEM_REGISTRY_W
  6348. #define sz_CERT_STORE_PROV_PHYSICAL_W "Physical"
  6349. #define sz_CERT_STORE_PROV_PHYSICAL sz_CERT_STORE_PROV_PHYSICAL_W
  6350. #define sz_CERT_STORE_PROV_SMART_CARD_W "SmartCard"
  6351. #define sz_CERT_STORE_PROV_SMART_CARD sz_CERT_STORE_PROV_SMART_CARD_W
  6352. #define sz_CERT_STORE_PROV_LDAP_W "Ldap"
  6353. #define sz_CERT_STORE_PROV_LDAP sz_CERT_STORE_PROV_LDAP_W
  6354. //+-------------------------------------------------------------------------
  6355. // Certificate Store verify/results flags
  6356. //--------------------------------------------------------------------------
  6357. #define CERT_STORE_SIGNATURE_FLAG 0x00000001
  6358. #define CERT_STORE_TIME_VALIDITY_FLAG 0x00000002
  6359. #define CERT_STORE_REVOCATION_FLAG 0x00000004
  6360. #define CERT_STORE_NO_CRL_FLAG 0x00010000
  6361. #define CERT_STORE_NO_ISSUER_FLAG 0x00020000
  6362. #define CERT_STORE_BASE_CRL_FLAG 0x00000100
  6363. #define CERT_STORE_DELTA_CRL_FLAG 0x00000200
  6364. //+-------------------------------------------------------------------------
  6365. // Certificate Store open/property flags
  6366. //--------------------------------------------------------------------------
  6367. #define CERT_STORE_NO_CRYPT_RELEASE_FLAG 0x00000001
  6368. #define CERT_STORE_SET_LOCALIZED_NAME_FLAG 0x00000002
  6369. #define CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG 0x00000004
  6370. #define CERT_STORE_DELETE_FLAG 0x00000010
  6371. #define CERT_STORE_SHARE_STORE_FLAG 0x00000040
  6372. #define CERT_STORE_SHARE_CONTEXT_FLAG 0x00000080
  6373. #define CERT_STORE_MANIFOLD_FLAG 0x00000100
  6374. #define CERT_STORE_ENUM_ARCHIVED_FLAG 0x00000200
  6375. #define CERT_STORE_UPDATE_KEYID_FLAG 0x00000400
  6376. #define CERT_STORE_BACKUP_RESTORE_FLAG 0x00000800
  6377. #define CERT_STORE_READONLY_FLAG 0x00008000
  6378. #define CERT_STORE_OPEN_EXISTING_FLAG 0x00004000
  6379. #define CERT_STORE_CREATE_NEW_FLAG 0x00002000
  6380. #define CERT_STORE_MAXIMUM_ALLOWED_FLAG 0x00001000
  6381. //+-------------------------------------------------------------------------
  6382. // Certificate Store Provider flags are in the HiWord (0xFFFF0000)
  6383. //--------------------------------------------------------------------------
  6384. //+-------------------------------------------------------------------------
  6385. // Certificate System Store Flag Values
  6386. //--------------------------------------------------------------------------
  6387. // Includes flags and location
  6388. #define CERT_SYSTEM_STORE_MASK 0xFFFF0000
  6389. // Set if pvPara points to a CERT_SYSTEM_STORE_RELOCATE_PARA structure
  6390. #define CERT_SYSTEM_STORE_RELOCATE_FLAG 0x80000000
  6391. typedef struct _CERT_SYSTEM_STORE_RELOCATE_PARA {
  6392. union {
  6393. HKEY hKeyBase;
  6394. void *pvBase;
  6395. };
  6396. union {
  6397. void *pvSystemStore;
  6398. LPCSTR pszSystemStore;
  6399. LPCWSTR pwszSystemStore;
  6400. };
  6401. } CERT_SYSTEM_STORE_RELOCATE_PARA, *PCERT_SYSTEM_STORE_RELOCATE_PARA;
  6402. // By default, when the CurrentUser "Root" store is opened, any SystemRegistry
  6403. // roots not also on the protected root list are deleted from the cache before
  6404. // CertOpenStore() returns. Set the following flag to return all the roots
  6405. // in the SystemRegistry without checking the protected root list.
  6406. #define CERT_SYSTEM_STORE_UNPROTECTED_FLAG 0x40000000
  6407. // Location of the system store:
  6408. #define CERT_SYSTEM_STORE_LOCATION_MASK 0x00FF0000
  6409. #define CERT_SYSTEM_STORE_LOCATION_SHIFT 16
  6410. // Registry: HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE
  6411. #define CERT_SYSTEM_STORE_CURRENT_USER_ID 1
  6412. #define CERT_SYSTEM_STORE_LOCAL_MACHINE_ID 2
  6413. // Registry: HKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography\Services
  6414. #define CERT_SYSTEM_STORE_CURRENT_SERVICE_ID 4
  6415. #define CERT_SYSTEM_STORE_SERVICES_ID 5
  6416. // Registry: HKEY_USERS
  6417. #define CERT_SYSTEM_STORE_USERS_ID 6
  6418. // Registry: HKEY_CURRENT_USER\Software\Policies\Microsoft\SystemCertificates
  6419. #define CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY_ID 7
  6420. // Registry: HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\SystemCertificates
  6421. #define CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY_ID 8
  6422. // Registry: HKEY_LOCAL_MACHINE\Software\Microsoft\EnterpriseCertificates
  6423. #define CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE_ID 9
  6424. #define CERT_SYSTEM_STORE_CURRENT_USER \
  6425. (CERT_SYSTEM_STORE_CURRENT_USER_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6426. #define CERT_SYSTEM_STORE_LOCAL_MACHINE \
  6427. (CERT_SYSTEM_STORE_LOCAL_MACHINE_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6428. #define CERT_SYSTEM_STORE_CURRENT_SERVICE \
  6429. (CERT_SYSTEM_STORE_CURRENT_SERVICE_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6430. #define CERT_SYSTEM_STORE_SERVICES \
  6431. (CERT_SYSTEM_STORE_SERVICES_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6432. #define CERT_SYSTEM_STORE_USERS \
  6433. (CERT_SYSTEM_STORE_USERS_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6434. #define CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY \
  6435. (CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY_ID << \
  6436. CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6437. #define CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY \
  6438. (CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY_ID << \
  6439. CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6440. #define CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE \
  6441. (CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE_ID << \
  6442. CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6443. //+-------------------------------------------------------------------------
  6444. // Group Policy Store Defines
  6445. //--------------------------------------------------------------------------
  6446. // Registry path to the Group Policy system stores
  6447. #define CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH \
  6448. L"Software\\Policies\\Microsoft\\SystemCertificates"
  6449. //+-------------------------------------------------------------------------
  6450. // EFS Defines
  6451. //--------------------------------------------------------------------------
  6452. // Registry path to the EFS EFSBlob SubKey - Value type is REG_BINARY
  6453. #define CERT_EFSBLOB_REGPATH \
  6454. CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH L"\\EFS"
  6455. #define CERT_EFSBLOB_VALUE_NAME L"EFSBlob"
  6456. //+-------------------------------------------------------------------------
  6457. // Protected Root Defines
  6458. //--------------------------------------------------------------------------
  6459. // Registry path to the Protected Roots Flags SubKey
  6460. #define CERT_PROT_ROOT_FLAGS_REGPATH \
  6461. CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH L"\\Root\\ProtectedRoots"
  6462. #define CERT_PROT_ROOT_FLAGS_VALUE_NAME L"Flags"
  6463. // Set the following flag to inhibit the opening of the CurrentUser's
  6464. // .Default physical store when opening the CurrentUser's "Root" system store.
  6465. // The .Default physical store open's the CurrentUser SystemRegistry "Root"
  6466. // store.
  6467. #define CERT_PROT_ROOT_DISABLE_CURRENT_USER_FLAG 0x1
  6468. // Set the following flag to inhibit the adding of roots from the
  6469. // CurrentUser SystemRegistry "Root" store to the protected root list
  6470. // when the "Root" store is initially protected.
  6471. #define CERT_PROT_ROOT_INHIBIT_ADD_AT_INIT_FLAG 0x2
  6472. // Set the following flag to inhibit the purging of protected roots from the
  6473. // CurrentUser SystemRegistry "Root" store that are
  6474. // also in the LocalMachine SystemRegistry "Root" store. Note, when not
  6475. // disabled, the purging is done silently without UI.
  6476. #define CERT_PROT_ROOT_INHIBIT_PURGE_LM_FLAG 0x4
  6477. // Set the following flag to inhibit the opening of the LocalMachine's
  6478. // .AuthRoot physical store when opening the LocalMachine's "Root" system store.
  6479. // The .AuthRoot physical store open's the LocalMachine SystemRegistry
  6480. // "AuthRoot" store. The "AuthRoot" store contains the pre-installed
  6481. // SSL ServerAuth and the ActiveX Authenticode "root" certificates.
  6482. #define CERT_PROT_ROOT_DISABLE_LM_AUTH_FLAG 0x8
  6483. // The semantics for the following legacy definition has been changed to be
  6484. // the same as for the CERT_PROT_ROOT_DISABLE_LM_AUTH_FLAG.
  6485. #define CERT_PROT_ROOT_ONLY_LM_GPT_FLAG 0x8
  6486. // Set the following flag to disable the requiring of the issuing CA
  6487. // certificate being in the "NTAuth" system registry store found in the
  6488. // CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE store location.
  6489. //
  6490. // When set, CertVerifyCertificateChainPolicy(CERT_CHAIN_POLICY_NT_AUTH)
  6491. // will check that the chain has a valid name constraint for all name
  6492. // spaces, including UPN if the issuing CA isn't in the "NTAuth" store.
  6493. #define CERT_PROT_ROOT_DISABLE_NT_AUTH_REQUIRED_FLAG 0x10
  6494. //+-------------------------------------------------------------------------
  6495. // Trusted Publisher Definitions
  6496. //--------------------------------------------------------------------------
  6497. // Registry path to the trusted publisher "Safer" group policy subkey
  6498. #define CERT_TRUST_PUB_SAFER_GROUP_POLICY_REGPATH \
  6499. CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH L"\\TrustedPublisher\\Safer"
  6500. // Registry path to the Local Machine system stores
  6501. #define CERT_LOCAL_MACHINE_SYSTEM_STORE_REGPATH \
  6502. L"Software\\Microsoft\\SystemCertificates"
  6503. // Registry path to the trusted publisher "Safer" local machine subkey
  6504. #define CERT_TRUST_PUB_SAFER_LOCAL_MACHINE_REGPATH \
  6505. CERT_LOCAL_MACHINE_SYSTEM_STORE_REGPATH L"\\TrustedPublisher\\Safer"
  6506. // "Safer" subkey value names. All values are DWORDs.
  6507. #define CERT_TRUST_PUB_AUTHENTICODE_FLAGS_VALUE_NAME L"AuthenticodeFlags"
  6508. // AuthenticodeFlags definitions
  6509. // Definition of who is allowed to trust publishers
  6510. //
  6511. // Setting allowed trust to MACHINE_ADMIN or ENTERPRISE_ADMIN disables UI,
  6512. // only trusts publishers in the "TrustedPublisher" system store and
  6513. // inhibits the opening of the CurrentUser's .Default physical store when
  6514. // opening the CurrentUsers's "TrustedPublisher" system store.
  6515. //
  6516. // The .Default physical store open's the CurrentUser SystemRegistry
  6517. // "TrustedPublisher" store.
  6518. //
  6519. // Setting allowed trust to ENTERPRISE_ADMIN only opens the
  6520. // LocalMachine's .GroupPolicy and .Enterprise physical stores when opening
  6521. // the CurrentUser's "TrustedPublisher" system store or when opening the
  6522. // LocalMachine's "TrustedPublisher" system store.
  6523. #define CERT_TRUST_PUB_ALLOW_TRUST_MASK 0x00000003
  6524. #define CERT_TRUST_PUB_ALLOW_END_USER_TRUST 0x00000000
  6525. #define CERT_TRUST_PUB_ALLOW_MACHINE_ADMIN_TRUST 0x00000001
  6526. #define CERT_TRUST_PUB_ALLOW_ENTERPRISE_ADMIN_TRUST 0x00000002
  6527. // Set the following flag to enable revocation checking of the publisher
  6528. // chain.
  6529. #define CERT_TRUST_PUB_CHECK_PUBLISHER_REV_FLAG 0x00000100
  6530. // Set the following flag to enable revocation checking of the time stamp
  6531. // chain.
  6532. #define CERT_TRUST_PUB_CHECK_TIMESTAMP_REV_FLAG 0x00000200
  6533. //+-------------------------------------------------------------------------
  6534. // OCM Subcomponents Definitions
  6535. //--------------------------------------------------------------------------
  6536. // Registry path to the OCM Subcomponents local machine subkey
  6537. #define CERT_OCM_SUBCOMPONENTS_LOCAL_MACHINE_REGPATH \
  6538. L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\OC Manager\\Subcomponents"
  6539. // REG_DWORD, 1 is installed, 0 is NOT installed
  6540. #define CERT_OCM_SUBCOMPONENTS_ROOT_AUTO_UPDATE_VALUE_NAME L"RootAutoUpdate"
  6541. //+-------------------------------------------------------------------------
  6542. // AuthRoot Auto Update Definitions
  6543. //--------------------------------------------------------------------------
  6544. // Registry path to the AuthRoot "Auto Update" local machine subkey
  6545. #define CERT_AUTH_ROOT_AUTO_UPDATE_LOCAL_MACHINE_REGPATH \
  6546. CERT_LOCAL_MACHINE_SYSTEM_STORE_REGPATH L"\\AuthRoot\\AutoUpdate"
  6547. // AuthRoot Auto Update subkey value names.
  6548. // REG_SZ, URL to the directory containing the AuthRoots, CTL and Seq files
  6549. #define CERT_AUTH_ROOT_AUTO_UPDATE_ROOT_DIR_URL_VALUE_NAME L"RootDirUrl"
  6550. // REG_DWORD, seconds between syncs. 0 implies use default.
  6551. #define CERT_AUTH_ROOT_AUTO_UPDATE_SYNC_DELTA_TIME_VALUE_NAME L"SyncDeltaTime"
  6552. // REG_DWORD, misc flags
  6553. #define CERT_AUTH_ROOT_AUTO_UPDATE_FLAGS_VALUE_NAME L"Flags"
  6554. #define CERT_AUTH_ROOT_AUTO_UPDATE_DISABLE_UNTRUSTED_ROOT_LOGGING_FLAG 0x1
  6555. #define CERT_AUTH_ROOT_AUTO_UPDATE_DISABLE_PARTIAL_CHAIN_LOGGING_FLAG 0x2
  6556. // AuthRoot Auto Update filenames
  6557. // CTL containing the list of certs in the AuthRoot store
  6558. #define CERT_AUTH_ROOT_CTL_FILENAME L"authroot.stl"
  6559. #define CERT_AUTH_ROOT_CTL_FILENAME_A "authroot.stl"
  6560. // Cab containing the above CTL
  6561. #define CERT_AUTH_ROOT_CAB_FILENAME L"authrootstl.cab"
  6562. // SequenceNumber (Formatted as big endian ascii hex)
  6563. #define CERT_AUTH_ROOT_SEQ_FILENAME L"authrootseq.txt"
  6564. // Root certs extension
  6565. #define CERT_AUTH_ROOT_CERT_EXT L".crt"
  6566. //+-------------------------------------------------------------------------
  6567. // Certificate Registry Store Flag Values (CERT_STORE_REG)
  6568. //--------------------------------------------------------------------------
  6569. // Set this flag if the HKEY passed in pvPara points to a remote computer
  6570. // registry key.
  6571. #define CERT_REGISTRY_STORE_REMOTE_FLAG 0x10000
  6572. // Set this flag if the contexts are to be persisted as a single serialized
  6573. // store in the registry. Mainly used for stores downloaded from the GPT.
  6574. // Such as the CurrentUserGroupPolicy or LocalMachineGroupPolicy stores.
  6575. #define CERT_REGISTRY_STORE_SERIALIZED_FLAG 0x20000
  6576. // The following flags are for internal use. When set, the
  6577. // pvPara parameter passed to CertOpenStore is a pointer to the following
  6578. // data structure and not the HKEY. The above CERT_REGISTRY_STORE_REMOTE_FLAG
  6579. // is also set if hKeyBase was obtained via RegConnectRegistry().
  6580. #define CERT_REGISTRY_STORE_CLIENT_GPT_FLAG 0x80000000
  6581. #define CERT_REGISTRY_STORE_LM_GPT_FLAG 0x01000000
  6582. typedef struct _CERT_REGISTRY_STORE_CLIENT_GPT_PARA {
  6583. HKEY hKeyBase;
  6584. LPWSTR pwszRegPath;
  6585. } CERT_REGISTRY_STORE_CLIENT_GPT_PARA, *PCERT_REGISTRY_STORE_CLIENT_GPT_PARA;
  6586. // The following flag is for internal use. When set, the contexts are
  6587. // persisted into roaming files instead of the registry. Such as, the
  6588. // CurrentUser "My" store. When this flag is set, the following data structure
  6589. // is passed to CertOpenStore instead of HKEY.
  6590. #define CERT_REGISTRY_STORE_ROAMING_FLAG 0x40000
  6591. // hKey may be NULL or non-NULL. When non-NULL, existing contexts are
  6592. // moved from the registry to roaming files.
  6593. typedef struct _CERT_REGISTRY_STORE_ROAMING_PARA {
  6594. HKEY hKey;
  6595. LPWSTR pwszStoreDirectory;
  6596. } CERT_REGISTRY_STORE_ROAMING_PARA, *PCERT_REGISTRY_STORE_ROAMING_PARA;
  6597. // The following flag is for internal use. When set, the "My" DWORD value
  6598. // at HKLM\Software\Microsoft\Cryptography\IEDirtyFlags is set to 0x1
  6599. // whenever a certificate is added to the registry store.
  6600. #define CERT_REGISTRY_STORE_MY_IE_DIRTY_FLAG 0x80000
  6601. // Registry path to the subkey containing the "My" DWORD value to be set
  6602. #define CERT_IE_DIRTY_FLAGS_REGPATH \
  6603. L"Software\\Microsoft\\Cryptography\\IEDirtyFlags"
  6604. //+-------------------------------------------------------------------------
  6605. // Certificate File Store Flag Values for the providers:
  6606. // CERT_STORE_PROV_FILE
  6607. // CERT_STORE_PROV_FILENAME
  6608. // CERT_STORE_PROV_FILENAME_A
  6609. // CERT_STORE_PROV_FILENAME_W
  6610. // sz_CERT_STORE_PROV_FILENAME_W
  6611. //--------------------------------------------------------------------------
  6612. // Set this flag if any store changes are to be committed to the file.
  6613. // The changes are committed at CertCloseStore or by calling
  6614. // CertControlStore(CERT_STORE_CTRL_COMMIT).
  6615. //
  6616. // The open fails with E_INVALIDARG if both CERT_FILE_STORE_COMMIT_ENABLE_FLAG
  6617. // and CERT_STORE_READONLY_FLAG are set in dwFlags.
  6618. //
  6619. // For the FILENAME providers: if the file contains an X509 encoded
  6620. // certificate, the open fails with ERROR_ACCESS_DENIED.
  6621. //
  6622. // For the FILENAME providers: if CERT_STORE_CREATE_NEW_FLAG is set, the
  6623. // CreateFile uses CREATE_NEW. If CERT_STORE_OPEN_EXISTING is set, uses
  6624. // OPEN_EXISTING. Otherwise, defaults to OPEN_ALWAYS.
  6625. //
  6626. // For the FILENAME providers: the file is committed as either a PKCS7 or
  6627. // serialized store depending on the type read at open. However, if the
  6628. // file is empty then, if the filename has either a ".p7c" or ".spc"
  6629. // extension its committed as a PKCS7. Otherwise, its committed as a
  6630. // serialized store.
  6631. //
  6632. // For CERT_STORE_PROV_FILE, the file handle is duplicated. Its always
  6633. // committed as a serialized store.
  6634. //
  6635. #define CERT_FILE_STORE_COMMIT_ENABLE_FLAG 0x10000
  6636. //+-------------------------------------------------------------------------
  6637. // Certificate LDAP Store Flag Values for the providers:
  6638. // CERT_STORE_PROV_LDAP
  6639. // CERT_STORE_PROV_LDAP_W
  6640. // sz_CERT_STORE_PROV_LDAP_W
  6641. // sz_CERT_STORE_PROV_LDAP
  6642. //--------------------------------------------------------------------------
  6643. // Set this flag to digitally sign all of the ldap traffic to and from a
  6644. // Windows 2000 LDAP server using the Kerberos authentication protocol.
  6645. // This feature provides integrity required by some applications.
  6646. //
  6647. #define CERT_LDAP_STORE_SIGN_FLAG 0x10000
  6648. // Performs an A-Record only DNS lookup on the supplied host string.
  6649. // This prevents bogus DNS queries from being generated when resolving host
  6650. // names. Use this flag whenever passing a hostname as opposed to a
  6651. // domain name for the hostname parameter.
  6652. //
  6653. // See LDAP_OPT_AREC_EXCLUSIVE defined in winldap.h for more details.
  6654. #define CERT_LDAP_STORE_AREC_EXCLUSIVE_FLAG 0x20000
  6655. //+-------------------------------------------------------------------------
  6656. // Open the cert store using the specified store provider.
  6657. //
  6658. // If CERT_STORE_DELETE_FLAG is set, then, the store is deleted. NULL is
  6659. // returned for both success and failure. However, GetLastError() returns 0
  6660. // for success and nonzero for failure.
  6661. //
  6662. // If CERT_STORE_SET_LOCALIZED_NAME_FLAG is set, then, if supported, the
  6663. // provider sets the store's CERT_STORE_LOCALIZED_NAME_PROP_ID property.
  6664. // The store's localized name can be retrieved by calling
  6665. // CertSetStoreProperty(dwPropID = CERT_STORE_LOCALIZED_NAME_PROP_ID).
  6666. // This flag is supported by the following providers (and their sz_
  6667. // equivalent):
  6668. // CERT_STORE_PROV_FILENAME_A
  6669. // CERT_STORE_PROV_FILENAME_W
  6670. // CERT_STORE_PROV_SYSTEM_A
  6671. // CERT_STORE_PROV_SYSTEM_W
  6672. // CERT_STORE_PROV_SYSTEM_REGISTRY_A
  6673. // CERT_STORE_PROV_SYSTEM_REGISTRY_W
  6674. // CERT_STORE_PROV_PHYSICAL_W
  6675. //
  6676. // If CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG is set, then, the
  6677. // closing of the store's provider is deferred until all certificate,
  6678. // CRL and CTL contexts obtained from the store are freed. Also,
  6679. // if a non NULL HCRYPTPROV was passed, then, it will continue to be used.
  6680. // By default, the store's provider is closed on the final CertCloseStore.
  6681. // If this flag isn't set, then, any property changes made to previously
  6682. // duplicated contexts after the final CertCloseStore will not be persisted.
  6683. // By setting this flag, property changes made
  6684. // after the CertCloseStore will be persisted. Note, setting this flag
  6685. // causes extra overhead in doing context duplicates and frees.
  6686. // If CertCloseStore is called with CERT_CLOSE_STORE_FORCE_FLAG, then,
  6687. // the CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG flag is ignored.
  6688. //
  6689. // CERT_STORE_MANIFOLD_FLAG can be set to check for certificates having the
  6690. // manifold extension and archive the "older" certificates with the same
  6691. // manifold extension value. A certificate is archived by setting the
  6692. // CERT_ARCHIVED_PROP_ID.
  6693. //
  6694. // By default, contexts having the CERT_ARCHIVED_PROP_ID, are skipped
  6695. // during enumeration. CERT_STORE_ENUM_ARCHIVED_FLAG can be set to include
  6696. // archived contexts when enumerating. Note, contexts having the
  6697. // CERT_ARCHIVED_PROP_ID are still found for explicit finds, such as,
  6698. // finding a context with a specific hash or finding a certificate having
  6699. // a specific issuer and serial number.
  6700. //
  6701. // CERT_STORE_UPDATE_KEYID_FLAG can be set to also update the Key Identifier's
  6702. // CERT_KEY_PROV_INFO_PROP_ID property whenever a certificate's
  6703. // CERT_KEY_IDENTIFIER_PROP_ID or CERT_KEY_PROV_INFO_PROP_ID property is set
  6704. // and the other property already exists. If the Key Identifier's
  6705. // CERT_KEY_PROV_INFO_PROP_ID already exists, it isn't updated. Any
  6706. // errors encountered are silently ignored.
  6707. //
  6708. // By default, this flag is implicitly set for the "My\.Default" CurrentUser
  6709. // and LocalMachine physical stores.
  6710. //
  6711. // CERT_STORE_READONLY_FLAG can be set to open the store as read only.
  6712. // Otherwise, the store is opened as read/write.
  6713. //
  6714. // CERT_STORE_OPEN_EXISTING_FLAG can be set to only open an existing
  6715. // store. CERT_STORE_CREATE_NEW_FLAG can be set to create a new store and
  6716. // fail if the store already exists. Otherwise, the default is to open
  6717. // an existing store or create a new store if it doesn't already exist.
  6718. //
  6719. // hCryptProv specifies the crypto provider to use to create the hash
  6720. // properties or verify the signature of a subject certificate or CRL.
  6721. // The store doesn't need to use a private
  6722. // key. If the CERT_STORE_NO_CRYPT_RELEASE_FLAG isn't set, hCryptProv is
  6723. // CryptReleaseContext'ed on the final CertCloseStore.
  6724. //
  6725. // Note, if the open fails, hCryptProv is released if it would have been
  6726. // released when the store was closed.
  6727. //
  6728. // If hCryptProv is zero, then, the default provider and container for the
  6729. // PROV_RSA_FULL provider type is CryptAcquireContext'ed with
  6730. // CRYPT_VERIFYCONTEXT access. The CryptAcquireContext is deferred until
  6731. // the first create hash or verify signature. In addition, once acquired,
  6732. // the default provider isn't released until process exit when crypt32.dll
  6733. // is unloaded. The acquired default provider is shared across all stores
  6734. // and threads.
  6735. //
  6736. // After initializing the store's data structures and optionally acquiring a
  6737. // default crypt provider, CertOpenStore calls CryptGetOIDFunctionAddress to
  6738. // get the address of the CRYPT_OID_OPEN_STORE_PROV_FUNC specified by
  6739. // lpszStoreProvider. Since a store can contain certificates with different
  6740. // encoding types, CryptGetOIDFunctionAddress is called with dwEncodingType
  6741. // set to 0 and not the dwEncodingType passed to CertOpenStore.
  6742. // PFN_CERT_DLL_OPEN_STORE_FUNC specifies the signature of the provider's
  6743. // open function. This provider open function is called to load the
  6744. // store's certificates and CRLs. Optionally, the provider may return an
  6745. // array of functions called before a certificate or CRL is added or deleted
  6746. // or has a property that is set.
  6747. //
  6748. // Use of the dwEncodingType parameter is provider dependent. The type
  6749. // definition for pvPara also depends on the provider.
  6750. //
  6751. // Store providers are installed or registered via
  6752. // CryptInstallOIDFunctionAddress or CryptRegisterOIDFunction, where,
  6753. // dwEncodingType is 0 and pszFuncName is CRYPT_OID_OPEN_STORE_PROV_FUNC.
  6754. //
  6755. // Here's a list of the predefined provider types (implemented in crypt32.dll):
  6756. //
  6757. // CERT_STORE_PROV_MSG:
  6758. // Gets the certificates and CRLs from the specified cryptographic message.
  6759. // dwEncodingType contains the message and certificate encoding types.
  6760. // The message's handle is passed in pvPara. Given,
  6761. // HCRYPTMSG hCryptMsg; pvPara = (const void *) hCryptMsg;
  6762. //
  6763. // CERT_STORE_PROV_MEMORY
  6764. // sz_CERT_STORE_PROV_MEMORY:
  6765. // Opens a store without any initial certificates or CRLs. pvPara
  6766. // isn't used.
  6767. //
  6768. // CERT_STORE_PROV_FILE:
  6769. // Reads the certificates and CRLs from the specified file. The file's
  6770. // handle is passed in pvPara. Given,
  6771. // HANDLE hFile; pvPara = (const void *) hFile;
  6772. //
  6773. // For a successful open, the file pointer is advanced past
  6774. // the certificates and CRLs and their properties read from the file.
  6775. // Note, only expects a serialized store and not a file containing
  6776. // either a PKCS #7 signed message or a single encoded certificate.
  6777. //
  6778. // The hFile isn't closed.
  6779. //
  6780. // CERT_STORE_PROV_REG:
  6781. // Reads the certificates and CRLs from the registry. The registry's
  6782. // key handle is passed in pvPara. Given,
  6783. // HKEY hKey; pvPara = (const void *) hKey;
  6784. //
  6785. // The input hKey isn't closed by the provider. Before returning, the
  6786. // provider opens it own copy of the hKey.
  6787. //
  6788. // If CERT_STORE_READONLY_FLAG is set, then, the registry subkeys are
  6789. // RegOpenKey'ed with KEY_READ_ACCESS. Otherwise, the registry subkeys
  6790. // are RegCreateKey'ed with KEY_ALL_ACCESS.
  6791. //
  6792. // This provider returns the array of functions for reading, writing,
  6793. // deleting and property setting certificates and CRLs.
  6794. // Any changes to the opened store are immediately pushed through to
  6795. // the registry. However, if CERT_STORE_READONLY_FLAG is set, then,
  6796. // writing, deleting or property setting results in a
  6797. // SetLastError(E_ACCESSDENIED).
  6798. //
  6799. // Note, all the certificates and CRLs are read from the registry
  6800. // when the store is opened. The opened store serves as a write through
  6801. // cache.
  6802. //
  6803. // If CERT_REGISTRY_STORE_SERIALIZED_FLAG is set, then, the
  6804. // contexts are persisted as a single serialized store subkey in the
  6805. // registry.
  6806. //
  6807. // CERT_STORE_PROV_PKCS7:
  6808. // sz_CERT_STORE_PROV_PKCS7:
  6809. // Gets the certificates and CRLs from the encoded PKCS #7 signed message.
  6810. // dwEncodingType specifies the message and certificate encoding types.
  6811. // The pointer to the encoded message's blob is passed in pvPara. Given,
  6812. // CRYPT_DATA_BLOB EncodedMsg; pvPara = (const void *) &EncodedMsg;
  6813. //
  6814. // Note, also supports the IE3.0 special version of a
  6815. // PKCS #7 signed message referred to as a "SPC" formatted message.
  6816. //
  6817. // CERT_STORE_PROV_SERIALIZED:
  6818. // sz_CERT_STORE_PROV_SERIALIZED:
  6819. // Gets the certificates and CRLs from memory containing a serialized
  6820. // store. The pointer to the serialized memory blob is passed in pvPara.
  6821. // Given,
  6822. // CRYPT_DATA_BLOB Serialized; pvPara = (const void *) &Serialized;
  6823. //
  6824. // CERT_STORE_PROV_FILENAME_A:
  6825. // CERT_STORE_PROV_FILENAME_W:
  6826. // CERT_STORE_PROV_FILENAME:
  6827. // sz_CERT_STORE_PROV_FILENAME_W:
  6828. // sz_CERT_STORE_PROV_FILENAME:
  6829. // Opens the file and first attempts to read as a serialized store. Then,
  6830. // as a PKCS #7 signed message. Finally, as a single encoded certificate.
  6831. // The filename is passed in pvPara. The filename is UNICODE for the
  6832. // "_W" provider and ASCII for the "_A" provider. For "_W": given,
  6833. // LPCWSTR pwszFilename; pvPara = (const void *) pwszFilename;
  6834. // For "_A": given,
  6835. // LPCSTR pszFilename; pvPara = (const void *) pszFilename;
  6836. //
  6837. // Note, the default (without "_A" or "_W") is unicode.
  6838. //
  6839. // Note, also supports the reading of the IE3.0 special version of a
  6840. // PKCS #7 signed message file referred to as a "SPC" formatted file.
  6841. //
  6842. // CERT_STORE_PROV_SYSTEM_A:
  6843. // CERT_STORE_PROV_SYSTEM_W:
  6844. // CERT_STORE_PROV_SYSTEM:
  6845. // sz_CERT_STORE_PROV_SYSTEM_W:
  6846. // sz_CERT_STORE_PROV_SYSTEM:
  6847. // Opens the specified logical "System" store. The upper word of the
  6848. // dwFlags parameter is used to specify the location of the system store.
  6849. //
  6850. // A "System" store is a collection consisting of one or more "Physical"
  6851. // stores. A "Physical" store is registered via the
  6852. // CertRegisterPhysicalStore API. Each of the registered physical stores
  6853. // is CertStoreOpen'ed and added to the collection via
  6854. // CertAddStoreToCollection.
  6855. //
  6856. // The CERT_SYSTEM_STORE_CURRENT_USER, CERT_SYSTEM_STORE_LOCAL_MACHINE,
  6857. // CERT_SYSTEM_STORE_CURRENT_SERVICE, CERT_SYSTEM_STORE_SERVICES,
  6858. // CERT_SYSTEM_STORE_USERS, CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY,
  6859. // CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY and
  6860. // CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRSE
  6861. // system stores by default have a "SystemRegistry" store that is
  6862. // opened and added to the collection.
  6863. //
  6864. // The system store name is passed in pvPara. The name is UNICODE for the
  6865. // "_W" provider and ASCII for the "_A" provider. For "_W": given,
  6866. // LPCWSTR pwszSystemName; pvPara = (const void *) pwszSystemName;
  6867. // For "_A": given,
  6868. // LPCSTR pszSystemName; pvPara = (const void *) pszSystemName;
  6869. //
  6870. // Note, the default (without "_A" or "_W") is UNICODE.
  6871. //
  6872. // The system store name can't contain any backslashes.
  6873. //
  6874. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvPara
  6875. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure instead
  6876. // of pointing to a null terminated UNICODE or ASCII string.
  6877. // Sibling physical stores are also opened as relocated using
  6878. // pvPara's hKeyBase.
  6879. //
  6880. // The CERT_SYSTEM_STORE_SERVICES or CERT_SYSTEM_STORE_USERS system
  6881. // store name must be prefixed with the ServiceName or UserName.
  6882. // For example, "ServiceName\Trust".
  6883. //
  6884. // Stores on remote computers can be accessed for the
  6885. // CERT_SYSTEM_STORE_LOCAL_MACHINE, CERT_SYSTEM_STORE_SERVICES,
  6886. // CERT_SYSTEM_STORE_USERS, CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY
  6887. // or CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE
  6888. // locations by prepending the computer name. For example, a remote
  6889. // local machine store is accessed via "\\ComputerName\Trust" or
  6890. // "ComputerName\Trust". A remote service store is accessed via
  6891. // "\\ComputerName\ServiceName\Trust". The leading "\\" backslashes are
  6892. // optional in the ComputerName.
  6893. //
  6894. // If CERT_STORE_READONLY_FLAG is set, then, the registry is
  6895. // RegOpenKey'ed with KEY_READ_ACCESS. Otherwise, the registry is
  6896. // RegCreateKey'ed with KEY_ALL_ACCESS.
  6897. //
  6898. // The "root" store is treated differently from the other system
  6899. // stores. Before a certificate is added to or deleted from the "root"
  6900. // store, a pop up message box is displayed. The certificate's subject,
  6901. // issuer, serial number, time validity, sha1 and md5 thumbprints are
  6902. // displayed. The user is given the option to do the add or delete.
  6903. // If they don't allow the operation, LastError is set to E_ACCESSDENIED.
  6904. //
  6905. // CERT_STORE_PROV_SYSTEM_REGISTRY_A
  6906. // CERT_STORE_PROV_SYSTEM_REGISTRY_W
  6907. // CERT_STORE_PROV_SYSTEM_REGISTRY
  6908. // sz_CERT_STORE_PROV_SYSTEM_REGISTRY_W
  6909. // sz_CERT_STORE_PROV_SYSTEM_REGISTRY
  6910. // Opens the "System" store's default "Physical" store residing in the
  6911. // registry. The upper word of the dwFlags
  6912. // parameter is used to specify the location of the system store.
  6913. //
  6914. // After opening the registry key associated with the system name,
  6915. // the CERT_STORE_PROV_REG provider is called to complete the open.
  6916. //
  6917. // The system store name is passed in pvPara. The name is UNICODE for the
  6918. // "_W" provider and ASCII for the "_A" provider. For "_W": given,
  6919. // LPCWSTR pwszSystemName; pvPara = (const void *) pwszSystemName;
  6920. // For "_A": given,
  6921. // LPCSTR pszSystemName; pvPara = (const void *) pszSystemName;
  6922. //
  6923. // Note, the default (without "_A" or "_W") is UNICODE.
  6924. //
  6925. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvPara
  6926. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure instead
  6927. // of pointing to a null terminated UNICODE or ASCII string.
  6928. //
  6929. // See above for details on prepending a ServiceName and/or ComputerName
  6930. // to the store name.
  6931. //
  6932. // If CERT_STORE_READONLY_FLAG is set, then, the registry is
  6933. // RegOpenKey'ed with KEY_READ_ACCESS. Otherwise, the registry is
  6934. // RegCreateKey'ed with KEY_ALL_ACCESS.
  6935. //
  6936. // The "root" store is treated differently from the other system
  6937. // stores. Before a certificate is added to or deleted from the "root"
  6938. // store, a pop up message box is displayed. The certificate's subject,
  6939. // issuer, serial number, time validity, sha1 and md5 thumbprints are
  6940. // displayed. The user is given the option to do the add or delete.
  6941. // If they don't allow the operation, LastError is set to E_ACCESSDENIED.
  6942. //
  6943. // CERT_STORE_PROV_PHYSICAL_W
  6944. // CERT_STORE_PROV_PHYSICAL
  6945. // sz_CERT_STORE_PROV_PHYSICAL_W
  6946. // sz_CERT_STORE_PROV_PHYSICAL
  6947. // Opens the specified "Physical" store in the "System" store.
  6948. //
  6949. // Both the system store and physical names are passed in pvPara. The
  6950. // names are separated with an intervening "\". For example,
  6951. // "Root\.Default". The string is UNICODE.
  6952. //
  6953. // The system and physical store names can't contain any backslashes.
  6954. //
  6955. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvPara
  6956. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure instead
  6957. // of pointing to a null terminated UNICODE string.
  6958. // The specified physical store is opened as relocated using pvPara's
  6959. // hKeyBase.
  6960. //
  6961. // For CERT_SYSTEM_STORE_SERVICES or CERT_SYSTEM_STORE_USERS,
  6962. // the system and physical store names
  6963. // must be prefixed with the ServiceName or UserName. For example,
  6964. // "ServiceName\Root\.Default".
  6965. //
  6966. // Physical stores on remote computers can be accessed for the
  6967. // CERT_SYSTEM_STORE_LOCAL_MACHINE, CERT_SYSTEM_STORE_SERVICES,
  6968. // CERT_SYSTEM_STORE_USERS, CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY
  6969. // or CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE
  6970. // locations by prepending the computer name. For example, a remote
  6971. // local machine store is accessed via "\\ComputerName\Root\.Default"
  6972. // or "ComputerName\Root\.Default". A remote service store is
  6973. // accessed via "\\ComputerName\ServiceName\Root\.Default". The
  6974. // leading "\\" backslashes are optional in the ComputerName.
  6975. //
  6976. // CERT_STORE_PROV_COLLECTION
  6977. // sz_CERT_STORE_PROV_COLLECTION
  6978. // Opens a store that is a collection of other stores. Stores are
  6979. // added or removed to/from the collection via the CertAddStoreToCollection
  6980. // and CertRemoveStoreFromCollection APIs.
  6981. //
  6982. // CERT_STORE_PROV_SMART_CARD_W
  6983. // CERT_STORE_PROV_SMART_CARD
  6984. // sz_CERT_STORE_PROV_SMART_CARD_W
  6985. // sz_CERT_STORE_PROV_SMART_CARD
  6986. // Opens a store instantiated over a particular smart card storage. pvPara
  6987. // identifies where on the card the store is located and is of the
  6988. // following format:
  6989. //
  6990. // Card Name\Provider Name\Provider Type[\Container Name]
  6991. //
  6992. // Container Name is optional and if NOT specified the Card Name is used
  6993. // as the Container Name. Future versions of the provider will support
  6994. // instantiating the store over the entire card in which case just
  6995. // Card Name ( or id ) will be sufficient.
  6996. //
  6997. // Here's a list of the predefined provider types (implemented in
  6998. // cryptnet.dll):
  6999. //
  7000. // CERT_STORE_PROV_LDAP_W
  7001. // CERT_STORE_PROV_LDAP
  7002. // sz_CERT_STORE_PROV_LDAP_W
  7003. // sz_CERT_STORE_PROV_LDAP
  7004. // Opens a store over the results of the query specified by and LDAP
  7005. // URL which is passed in via pvPara. In order to do writes to the
  7006. // store the URL must specify a BASE query, no filter and a single
  7007. // attribute.
  7008. //
  7009. //--------------------------------------------------------------------------
  7010. WINCRYPT32API
  7011. HCERTSTORE
  7012. WINAPI
  7013. CertOpenStore(
  7014. IN LPCSTR lpszStoreProvider,
  7015. IN DWORD dwEncodingType,
  7016. IN HCRYPTPROV hCryptProv,
  7017. IN DWORD dwFlags,
  7018. IN const void *pvPara
  7019. );
  7020. //+-------------------------------------------------------------------------
  7021. // OID Installable Certificate Store Provider Data Structures
  7022. //--------------------------------------------------------------------------
  7023. // Handle returned by the store provider when opened.
  7024. typedef void *HCERTSTOREPROV;
  7025. // Store Provider OID function's pszFuncName.
  7026. #define CRYPT_OID_OPEN_STORE_PROV_FUNC "CertDllOpenStoreProv"
  7027. // Note, the Store Provider OID function's dwEncodingType is always 0.
  7028. // The following information is returned by the provider when opened. Its
  7029. // zeroed with cbSize set before the provider is called. If the provider
  7030. // doesn't need to be called again after the open it doesn't need to
  7031. // make any updates to the CERT_STORE_PROV_INFO.
  7032. typedef struct _CERT_STORE_PROV_INFO {
  7033. DWORD cbSize;
  7034. DWORD cStoreProvFunc;
  7035. void **rgpvStoreProvFunc;
  7036. HCERTSTOREPROV hStoreProv;
  7037. DWORD dwStoreProvFlags;
  7038. HCRYPTOIDFUNCADDR hStoreProvFuncAddr2;
  7039. } CERT_STORE_PROV_INFO, *PCERT_STORE_PROV_INFO;
  7040. // Definition of the store provider's open function.
  7041. //
  7042. // *pStoreProvInfo has been zeroed before the call.
  7043. //
  7044. // Note, pStoreProvInfo->cStoreProvFunc should be set last. Once set,
  7045. // all subsequent store calls, such as CertAddSerializedElementToStore will
  7046. // call the appropriate provider callback function.
  7047. typedef BOOL (WINAPI *PFN_CERT_DLL_OPEN_STORE_PROV_FUNC)(
  7048. IN LPCSTR lpszStoreProvider,
  7049. IN DWORD dwEncodingType,
  7050. IN HCRYPTPROV hCryptProv,
  7051. IN DWORD dwFlags,
  7052. IN const void *pvPara,
  7053. IN HCERTSTORE hCertStore,
  7054. IN OUT PCERT_STORE_PROV_INFO pStoreProvInfo
  7055. );
  7056. // The open callback sets the following flag, if it maintains its
  7057. // contexts externally and not in the cached store.
  7058. #define CERT_STORE_PROV_EXTERNAL_FLAG 0x1
  7059. // The open callback sets the following flag for a successful delete.
  7060. // When set, the close callback isn't called.
  7061. #define CERT_STORE_PROV_DELETED_FLAG 0x2
  7062. // The open callback sets the following flag if it doesn't persist store
  7063. // changes.
  7064. #define CERT_STORE_PROV_NO_PERSIST_FLAG 0x4
  7065. // The open callback sets the following flag if the contexts are persisted
  7066. // to a system store.
  7067. #define CERT_STORE_PROV_SYSTEM_STORE_FLAG 0x8
  7068. // Indices into the store provider's array of callback functions.
  7069. //
  7070. // The provider can implement any subset of the following functions. It
  7071. // sets pStoreProvInfo->cStoreProvFunc to the last index + 1 and any
  7072. // preceding not implemented functions to NULL.
  7073. #define CERT_STORE_PROV_CLOSE_FUNC 0
  7074. #define CERT_STORE_PROV_READ_CERT_FUNC 1
  7075. #define CERT_STORE_PROV_WRITE_CERT_FUNC 2
  7076. #define CERT_STORE_PROV_DELETE_CERT_FUNC 3
  7077. #define CERT_STORE_PROV_SET_CERT_PROPERTY_FUNC 4
  7078. #define CERT_STORE_PROV_READ_CRL_FUNC 5
  7079. #define CERT_STORE_PROV_WRITE_CRL_FUNC 6
  7080. #define CERT_STORE_PROV_DELETE_CRL_FUNC 7
  7081. #define CERT_STORE_PROV_SET_CRL_PROPERTY_FUNC 8
  7082. #define CERT_STORE_PROV_READ_CTL_FUNC 9
  7083. #define CERT_STORE_PROV_WRITE_CTL_FUNC 10
  7084. #define CERT_STORE_PROV_DELETE_CTL_FUNC 11
  7085. #define CERT_STORE_PROV_SET_CTL_PROPERTY_FUNC 12
  7086. #define CERT_STORE_PROV_CONTROL_FUNC 13
  7087. #define CERT_STORE_PROV_FIND_CERT_FUNC 14
  7088. #define CERT_STORE_PROV_FREE_FIND_CERT_FUNC 15
  7089. #define CERT_STORE_PROV_GET_CERT_PROPERTY_FUNC 16
  7090. #define CERT_STORE_PROV_FIND_CRL_FUNC 17
  7091. #define CERT_STORE_PROV_FREE_FIND_CRL_FUNC 18
  7092. #define CERT_STORE_PROV_GET_CRL_PROPERTY_FUNC 19
  7093. #define CERT_STORE_PROV_FIND_CTL_FUNC 20
  7094. #define CERT_STORE_PROV_FREE_FIND_CTL_FUNC 21
  7095. #define CERT_STORE_PROV_GET_CTL_PROPERTY_FUNC 22
  7096. // Called by CertCloseStore when the store's reference count is
  7097. // decremented to 0.
  7098. typedef void (WINAPI *PFN_CERT_STORE_PROV_CLOSE)(
  7099. IN HCERTSTOREPROV hStoreProv,
  7100. IN DWORD dwFlags
  7101. );
  7102. // Currently not called directly by the store APIs. However, may be exported
  7103. // to support other providers based on it.
  7104. //
  7105. // Reads the provider's copy of the certificate context. If it exists,
  7106. // creates a new certificate context.
  7107. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_READ_CERT)(
  7108. IN HCERTSTOREPROV hStoreProv,
  7109. IN PCCERT_CONTEXT pStoreCertContext,
  7110. IN DWORD dwFlags,
  7111. OUT PCCERT_CONTEXT *ppProvCertContext
  7112. );
  7113. #define CERT_STORE_PROV_WRITE_ADD_FLAG 0x1
  7114. // Called by CertAddEncodedCertificateToStore,
  7115. // CertAddCertificateContextToStore or CertAddSerializedElementToStore before
  7116. // adding to the store. The CERT_STORE_PROV_WRITE_ADD_FLAG is set. In
  7117. // addition to the encoded certificate, the added pCertContext might also
  7118. // have properties.
  7119. //
  7120. // Returns TRUE if its OK to update the the store.
  7121. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_WRITE_CERT)(
  7122. IN HCERTSTOREPROV hStoreProv,
  7123. IN PCCERT_CONTEXT pCertContext,
  7124. IN DWORD dwFlags
  7125. );
  7126. // Called by CertDeleteCertificateFromStore before deleting from the
  7127. // store.
  7128. //
  7129. // Returns TRUE if its OK to delete from the store.
  7130. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_DELETE_CERT)(
  7131. IN HCERTSTOREPROV hStoreProv,
  7132. IN PCCERT_CONTEXT pCertContext,
  7133. IN DWORD dwFlags
  7134. );
  7135. // Called by CertSetCertificateContextProperty before setting the
  7136. // certificate's property. Also called by CertGetCertificateContextProperty,
  7137. // when getting a hash property that needs to be created and then persisted
  7138. // via the set.
  7139. //
  7140. // Upon input, the property hasn't been set for the pCertContext parameter.
  7141. //
  7142. // Returns TRUE if its OK to set the property.
  7143. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_SET_CERT_PROPERTY)(
  7144. IN HCERTSTOREPROV hStoreProv,
  7145. IN PCCERT_CONTEXT pCertContext,
  7146. IN DWORD dwPropId,
  7147. IN DWORD dwFlags,
  7148. IN const void *pvData
  7149. );
  7150. // Currently not called directly by the store APIs. However, may be exported
  7151. // to support other providers based on it.
  7152. //
  7153. // Reads the provider's copy of the CRL context. If it exists,
  7154. // creates a new CRL context.
  7155. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_READ_CRL)(
  7156. IN HCERTSTOREPROV hStoreProv,
  7157. IN PCCRL_CONTEXT pStoreCrlContext,
  7158. IN DWORD dwFlags,
  7159. OUT PCCRL_CONTEXT *ppProvCrlContext
  7160. );
  7161. // Called by CertAddEncodedCRLToStore,
  7162. // CertAddCRLContextToStore or CertAddSerializedElementToStore before
  7163. // adding to the store. The CERT_STORE_PROV_WRITE_ADD_FLAG is set. In
  7164. // addition to the encoded CRL, the added pCertContext might also
  7165. // have properties.
  7166. //
  7167. // Returns TRUE if its OK to update the the store.
  7168. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_WRITE_CRL)(
  7169. IN HCERTSTOREPROV hStoreProv,
  7170. IN PCCRL_CONTEXT pCrlContext,
  7171. IN DWORD dwFlags
  7172. );
  7173. // Called by CertDeleteCRLFromStore before deleting from the store.
  7174. //
  7175. // Returns TRUE if its OK to delete from the store.
  7176. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_DELETE_CRL)(
  7177. IN HCERTSTOREPROV hStoreProv,
  7178. IN PCCRL_CONTEXT pCrlContext,
  7179. IN DWORD dwFlags
  7180. );
  7181. // Called by CertSetCRLContextProperty before setting the
  7182. // CRL's property. Also called by CertGetCRLContextProperty,
  7183. // when getting a hash property that needs to be created and then persisted
  7184. // via the set.
  7185. //
  7186. // Upon input, the property hasn't been set for the pCrlContext parameter.
  7187. //
  7188. // Returns TRUE if its OK to set the property.
  7189. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_SET_CRL_PROPERTY)(
  7190. IN HCERTSTOREPROV hStoreProv,
  7191. IN PCCRL_CONTEXT pCrlContext,
  7192. IN DWORD dwPropId,
  7193. IN DWORD dwFlags,
  7194. IN const void *pvData
  7195. );
  7196. // Currently not called directly by the store APIs. However, may be exported
  7197. // to support other providers based on it.
  7198. //
  7199. // Reads the provider's copy of the CTL context. If it exists,
  7200. // creates a new CTL context.
  7201. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_READ_CTL)(
  7202. IN HCERTSTOREPROV hStoreProv,
  7203. IN PCCTL_CONTEXT pStoreCtlContext,
  7204. IN DWORD dwFlags,
  7205. OUT PCCTL_CONTEXT *ppProvCtlContext
  7206. );
  7207. // Called by CertAddEncodedCTLToStore,
  7208. // CertAddCTLContextToStore or CertAddSerializedElementToStore before
  7209. // adding to the store. The CERT_STORE_PROV_WRITE_ADD_FLAG is set. In
  7210. // addition to the encoded CTL, the added pCertContext might also
  7211. // have properties.
  7212. //
  7213. // Returns TRUE if its OK to update the the store.
  7214. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_WRITE_CTL)(
  7215. IN HCERTSTOREPROV hStoreProv,
  7216. IN PCCTL_CONTEXT pCtlContext,
  7217. IN DWORD dwFlags
  7218. );
  7219. // Called by CertDeleteCTLFromStore before deleting from the store.
  7220. //
  7221. // Returns TRUE if its OK to delete from the store.
  7222. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_DELETE_CTL)(
  7223. IN HCERTSTOREPROV hStoreProv,
  7224. IN PCCTL_CONTEXT pCtlContext,
  7225. IN DWORD dwFlags
  7226. );
  7227. // Called by CertSetCTLContextProperty before setting the
  7228. // CTL's property. Also called by CertGetCTLContextProperty,
  7229. // when getting a hash property that needs to be created and then persisted
  7230. // via the set.
  7231. //
  7232. // Upon input, the property hasn't been set for the pCtlContext parameter.
  7233. //
  7234. // Returns TRUE if its OK to set the property.
  7235. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_SET_CTL_PROPERTY)(
  7236. IN HCERTSTOREPROV hStoreProv,
  7237. IN PCCTL_CONTEXT pCtlContext,
  7238. IN DWORD dwPropId,
  7239. IN DWORD dwFlags,
  7240. IN const void *pvData
  7241. );
  7242. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_CONTROL)(
  7243. IN HCERTSTOREPROV hStoreProv,
  7244. IN DWORD dwFlags,
  7245. IN DWORD dwCtrlType,
  7246. IN void const *pvCtrlPara
  7247. );
  7248. typedef struct _CERT_STORE_PROV_FIND_INFO {
  7249. DWORD cbSize;
  7250. DWORD dwMsgAndCertEncodingType;
  7251. DWORD dwFindFlags;
  7252. DWORD dwFindType;
  7253. const void *pvFindPara;
  7254. } CERT_STORE_PROV_FIND_INFO, *PCERT_STORE_PROV_FIND_INFO;
  7255. typedef const CERT_STORE_PROV_FIND_INFO CCERT_STORE_PROV_FIND_INFO,
  7256. *PCCERT_STORE_PROV_FIND_INFO;
  7257. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_FIND_CERT)(
  7258. IN HCERTSTOREPROV hStoreProv,
  7259. IN PCCERT_STORE_PROV_FIND_INFO pFindInfo,
  7260. IN PCCERT_CONTEXT pPrevCertContext,
  7261. IN DWORD dwFlags,
  7262. IN OUT void **ppvStoreProvFindInfo,
  7263. OUT PCCERT_CONTEXT *ppProvCertContext
  7264. );
  7265. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_FREE_FIND_CERT)(
  7266. IN HCERTSTOREPROV hStoreProv,
  7267. IN PCCERT_CONTEXT pCertContext,
  7268. IN void *pvStoreProvFindInfo,
  7269. IN DWORD dwFlags
  7270. );
  7271. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_GET_CERT_PROPERTY)(
  7272. IN HCERTSTOREPROV hStoreProv,
  7273. IN PCCERT_CONTEXT pCertContext,
  7274. IN DWORD dwPropId,
  7275. IN DWORD dwFlags,
  7276. OUT void *pvData,
  7277. IN OUT DWORD *pcbData
  7278. );
  7279. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_FIND_CRL)(
  7280. IN HCERTSTOREPROV hStoreProv,
  7281. IN PCCERT_STORE_PROV_FIND_INFO pFindInfo,
  7282. IN PCCRL_CONTEXT pPrevCrlContext,
  7283. IN DWORD dwFlags,
  7284. IN OUT void **ppvStoreProvFindInfo,
  7285. OUT PCCRL_CONTEXT *ppProvCrlContext
  7286. );
  7287. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_FREE_FIND_CRL)(
  7288. IN HCERTSTOREPROV hStoreProv,
  7289. IN PCCRL_CONTEXT pCrlContext,
  7290. IN void *pvStoreProvFindInfo,
  7291. IN DWORD dwFlags
  7292. );
  7293. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_GET_CRL_PROPERTY)(
  7294. IN HCERTSTOREPROV hStoreProv,
  7295. IN PCCRL_CONTEXT pCrlContext,
  7296. IN DWORD dwPropId,
  7297. IN DWORD dwFlags,
  7298. OUT void *pvData,
  7299. IN OUT DWORD *pcbData
  7300. );
  7301. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_FIND_CTL)(
  7302. IN HCERTSTOREPROV hStoreProv,
  7303. IN PCCERT_STORE_PROV_FIND_INFO pFindInfo,
  7304. IN PCCTL_CONTEXT pPrevCtlContext,
  7305. IN DWORD dwFlags,
  7306. IN OUT void **ppvStoreProvFindInfo,
  7307. OUT PCCTL_CONTEXT *ppProvCtlContext
  7308. );
  7309. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_FREE_FIND_CTL)(
  7310. IN HCERTSTOREPROV hStoreProv,
  7311. IN PCCTL_CONTEXT pCtlContext,
  7312. IN void *pvStoreProvFindInfo,
  7313. IN DWORD dwFlags
  7314. );
  7315. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_GET_CTL_PROPERTY)(
  7316. IN HCERTSTOREPROV hStoreProv,
  7317. IN PCCTL_CONTEXT pCtlContext,
  7318. IN DWORD dwPropId,
  7319. IN DWORD dwFlags,
  7320. OUT void *pvData,
  7321. IN OUT DWORD *pcbData
  7322. );
  7323. //+-------------------------------------------------------------------------
  7324. // Duplicate a cert store handle
  7325. //--------------------------------------------------------------------------
  7326. WINCRYPT32API
  7327. HCERTSTORE
  7328. WINAPI
  7329. CertDuplicateStore(
  7330. IN HCERTSTORE hCertStore
  7331. );
  7332. #define CERT_STORE_SAVE_AS_STORE 1
  7333. #define CERT_STORE_SAVE_AS_PKCS7 2
  7334. #define CERT_STORE_SAVE_TO_FILE 1
  7335. #define CERT_STORE_SAVE_TO_MEMORY 2
  7336. #define CERT_STORE_SAVE_TO_FILENAME_A 3
  7337. #define CERT_STORE_SAVE_TO_FILENAME_W 4
  7338. #define CERT_STORE_SAVE_TO_FILENAME CERT_STORE_SAVE_TO_FILENAME_W
  7339. //+-------------------------------------------------------------------------
  7340. // Save the cert store. Extended version with lots of options.
  7341. //
  7342. // According to the dwSaveAs parameter, the store can be saved as a
  7343. // serialized store (CERT_STORE_SAVE_AS_STORE) containing properties in
  7344. // addition to encoded certificates, CRLs and CTLs or the store can be saved
  7345. // as a PKCS #7 signed message (CERT_STORE_SAVE_AS_PKCS7) which doesn't
  7346. // include the properties or CTLs.
  7347. //
  7348. // Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  7349. // CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't saved into
  7350. // a serialized store.
  7351. //
  7352. // For CERT_STORE_SAVE_AS_PKCS7, the dwEncodingType specifies the message
  7353. // encoding type. The dwEncodingType parameter isn't used for
  7354. // CERT_STORE_SAVE_AS_STORE.
  7355. //
  7356. // The dwFlags parameter currently isn't used and should be set to 0.
  7357. //
  7358. // The dwSaveTo and pvSaveToPara parameters specify where to save the
  7359. // store as follows:
  7360. // CERT_STORE_SAVE_TO_FILE:
  7361. // Saves to the specified file. The file's handle is passed in
  7362. // pvSaveToPara. Given,
  7363. // HANDLE hFile; pvSaveToPara = (void *) hFile;
  7364. //
  7365. // For a successful save, the file pointer is positioned after the
  7366. // last write.
  7367. //
  7368. // CERT_STORE_SAVE_TO_MEMORY:
  7369. // Saves to the specified memory blob. The pointer to
  7370. // the memory blob is passed in pvSaveToPara. Given,
  7371. // CRYPT_DATA_BLOB SaveBlob; pvSaveToPara = (void *) &SaveBlob;
  7372. // Upon entry, the SaveBlob's pbData and cbData need to be initialized.
  7373. // Upon return, cbData is updated with the actual length.
  7374. // For a length only calculation, pbData should be set to NULL. If
  7375. // pbData is non-NULL and cbData isn't large enough, FALSE is returned
  7376. // with a last error of ERRROR_MORE_DATA.
  7377. //
  7378. // CERT_STORE_SAVE_TO_FILENAME_A:
  7379. // CERT_STORE_SAVE_TO_FILENAME_W:
  7380. // CERT_STORE_SAVE_TO_FILENAME:
  7381. // Opens the file and saves to it. The filename is passed in pvSaveToPara.
  7382. // The filename is UNICODE for the "_W" option and ASCII for the "_A"
  7383. // option. For "_W": given,
  7384. // LPCWSTR pwszFilename; pvSaveToPara = (void *) pwszFilename;
  7385. // For "_A": given,
  7386. // LPCSTR pszFilename; pvSaveToPara = (void *) pszFilename;
  7387. //
  7388. // Note, the default (without "_A" or "_W") is UNICODE.
  7389. //
  7390. //--------------------------------------------------------------------------
  7391. WINCRYPT32API
  7392. BOOL
  7393. WINAPI
  7394. CertSaveStore(
  7395. IN HCERTSTORE hCertStore,
  7396. IN DWORD dwEncodingType,
  7397. IN DWORD dwSaveAs,
  7398. IN DWORD dwSaveTo,
  7399. IN OUT void *pvSaveToPara,
  7400. IN DWORD dwFlags
  7401. );
  7402. //+-------------------------------------------------------------------------
  7403. // Certificate Store close flags
  7404. //--------------------------------------------------------------------------
  7405. #define CERT_CLOSE_STORE_FORCE_FLAG 0x00000001
  7406. #define CERT_CLOSE_STORE_CHECK_FLAG 0x00000002
  7407. //+-------------------------------------------------------------------------
  7408. // Close a cert store handle.
  7409. //
  7410. // There needs to be a corresponding close for each open and duplicate.
  7411. //
  7412. // Even on the final close, the cert store isn't freed until all of its
  7413. // certificate and CRL contexts have also been freed.
  7414. //
  7415. // On the final close, the hCryptProv passed to CertStoreOpen is
  7416. // CryptReleaseContext'ed.
  7417. //
  7418. // To force the closure of the store with all of its memory freed, set the
  7419. // CERT_STORE_CLOSE_FORCE_FLAG. This flag should be set when the caller does
  7420. // its own reference counting and wants everything to vanish.
  7421. //
  7422. // To check if all the store's certificates and CRLs have been freed and that
  7423. // this is the last CertCloseStore, set the CERT_CLOSE_STORE_CHECK_FLAG. If
  7424. // set and certs, CRLs or stores still need to be freed/closed, FALSE is
  7425. // returned with LastError set to CRYPT_E_PENDING_CLOSE. Note, for FALSE,
  7426. // the store is still closed. This is a diagnostic flag.
  7427. //
  7428. // LastError is preserved unless CERT_CLOSE_STORE_CHECK_FLAG is set and FALSE
  7429. // is returned.
  7430. //--------------------------------------------------------------------------
  7431. WINCRYPT32API
  7432. BOOL
  7433. WINAPI
  7434. CertCloseStore(
  7435. IN HCERTSTORE hCertStore,
  7436. DWORD dwFlags
  7437. );
  7438. //+-------------------------------------------------------------------------
  7439. // Get the subject certificate context uniquely identified by its Issuer and
  7440. // SerialNumber from the store.
  7441. //
  7442. // If the certificate isn't found, NULL is returned. Otherwise, a pointer to
  7443. // a read only CERT_CONTEXT is returned. CERT_CONTEXT must be freed by calling
  7444. // CertFreeCertificateContext. CertDuplicateCertificateContext can be called to make a
  7445. // duplicate.
  7446. //
  7447. // The returned certificate might not be valid. Normally, it would be
  7448. // verified when getting its issuer certificate (CertGetIssuerCertificateFromStore).
  7449. //--------------------------------------------------------------------------
  7450. WINCRYPT32API
  7451. PCCERT_CONTEXT
  7452. WINAPI
  7453. CertGetSubjectCertificateFromStore(
  7454. IN HCERTSTORE hCertStore,
  7455. IN DWORD dwCertEncodingType,
  7456. IN PCERT_INFO pCertId // Only the Issuer and SerialNumber
  7457. // fields are used
  7458. );
  7459. //+-------------------------------------------------------------------------
  7460. // Enumerate the certificate contexts in the store.
  7461. //
  7462. // If a certificate isn't found, NULL is returned.
  7463. // Otherwise, a pointer to a read only CERT_CONTEXT is returned. CERT_CONTEXT
  7464. // must be freed by calling CertFreeCertificateContext or is freed when passed as the
  7465. // pPrevCertContext on a subsequent call. CertDuplicateCertificateContext
  7466. // can be called to make a duplicate.
  7467. //
  7468. // pPrevCertContext MUST BE NULL to enumerate the first
  7469. // certificate in the store. Successive certificates are enumerated by setting
  7470. // pPrevCertContext to the CERT_CONTEXT returned by a previous call.
  7471. //
  7472. // NOTE: a NON-NULL pPrevCertContext is always CertFreeCertificateContext'ed by
  7473. // this function, even for an error.
  7474. //--------------------------------------------------------------------------
  7475. WINCRYPT32API
  7476. PCCERT_CONTEXT
  7477. WINAPI
  7478. CertEnumCertificatesInStore(
  7479. IN HCERTSTORE hCertStore,
  7480. IN PCCERT_CONTEXT pPrevCertContext
  7481. );
  7482. //+-------------------------------------------------------------------------
  7483. // Find the first or next certificate context in the store.
  7484. //
  7485. // The certificate is found according to the dwFindType and its pvFindPara.
  7486. // See below for a list of the find types and its parameters.
  7487. //
  7488. // Currently dwFindFlags is only used for CERT_FIND_SUBJECT_ATTR,
  7489. // CERT_FIND_ISSUER_ATTR or CERT_FIND_CTL_USAGE. Otherwise, must be set to 0.
  7490. //
  7491. // Usage of dwCertEncodingType depends on the dwFindType.
  7492. //
  7493. // If the first or next certificate isn't found, NULL is returned.
  7494. // Otherwise, a pointer to a read only CERT_CONTEXT is returned. CERT_CONTEXT
  7495. // must be freed by calling CertFreeCertificateContext or is freed when passed as the
  7496. // pPrevCertContext on a subsequent call. CertDuplicateCertificateContext
  7497. // can be called to make a duplicate.
  7498. //
  7499. // pPrevCertContext MUST BE NULL on the first
  7500. // call to find the certificate. To find the next certificate, the
  7501. // pPrevCertContext is set to the CERT_CONTEXT returned by a previous call.
  7502. //
  7503. // NOTE: a NON-NULL pPrevCertContext is always CertFreeCertificateContext'ed by
  7504. // this function, even for an error.
  7505. //--------------------------------------------------------------------------
  7506. WINCRYPT32API
  7507. PCCERT_CONTEXT
  7508. WINAPI
  7509. CertFindCertificateInStore(
  7510. IN HCERTSTORE hCertStore,
  7511. IN DWORD dwCertEncodingType,
  7512. IN DWORD dwFindFlags,
  7513. IN DWORD dwFindType,
  7514. IN const void *pvFindPara,
  7515. IN PCCERT_CONTEXT pPrevCertContext
  7516. );
  7517. //+-------------------------------------------------------------------------
  7518. // Certificate comparison functions
  7519. //--------------------------------------------------------------------------
  7520. #define CERT_COMPARE_MASK 0xFFFF
  7521. #define CERT_COMPARE_SHIFT 16
  7522. #define CERT_COMPARE_ANY 0
  7523. #define CERT_COMPARE_SHA1_HASH 1
  7524. #define CERT_COMPARE_NAME 2
  7525. #define CERT_COMPARE_ATTR 3
  7526. #define CERT_COMPARE_MD5_HASH 4
  7527. #define CERT_COMPARE_PROPERTY 5
  7528. #define CERT_COMPARE_PUBLIC_KEY 6
  7529. #define CERT_COMPARE_HASH CERT_COMPARE_SHA1_HASH
  7530. #define CERT_COMPARE_NAME_STR_A 7
  7531. #define CERT_COMPARE_NAME_STR_W 8
  7532. #define CERT_COMPARE_KEY_SPEC 9
  7533. #define CERT_COMPARE_ENHKEY_USAGE 10
  7534. #define CERT_COMPARE_CTL_USAGE CERT_COMPARE_ENHKEY_USAGE
  7535. #define CERT_COMPARE_SUBJECT_CERT 11
  7536. #define CERT_COMPARE_ISSUER_OF 12
  7537. #define CERT_COMPARE_EXISTING 13
  7538. #define CERT_COMPARE_SIGNATURE_HASH 14
  7539. #define CERT_COMPARE_KEY_IDENTIFIER 15
  7540. #define CERT_COMPARE_CERT_ID 16
  7541. #define CERT_COMPARE_CROSS_CERT_DIST_POINTS 17
  7542. #define CERT_COMPARE_PUBKEY_MD5_HASH 18
  7543. //+-------------------------------------------------------------------------
  7544. // dwFindType
  7545. //
  7546. // The dwFindType definition consists of two components:
  7547. // - comparison function
  7548. // - certificate information flag
  7549. //--------------------------------------------------------------------------
  7550. #define CERT_FIND_ANY (CERT_COMPARE_ANY << CERT_COMPARE_SHIFT)
  7551. #define CERT_FIND_SHA1_HASH (CERT_COMPARE_SHA1_HASH << CERT_COMPARE_SHIFT)
  7552. #define CERT_FIND_MD5_HASH (CERT_COMPARE_MD5_HASH << CERT_COMPARE_SHIFT)
  7553. #define CERT_FIND_SIGNATURE_HASH (CERT_COMPARE_SIGNATURE_HASH << CERT_COMPARE_SHIFT)
  7554. #define CERT_FIND_KEY_IDENTIFIER (CERT_COMPARE_KEY_IDENTIFIER << CERT_COMPARE_SHIFT)
  7555. #define CERT_FIND_HASH CERT_FIND_SHA1_HASH
  7556. #define CERT_FIND_PROPERTY (CERT_COMPARE_PROPERTY << CERT_COMPARE_SHIFT)
  7557. #define CERT_FIND_PUBLIC_KEY (CERT_COMPARE_PUBLIC_KEY << CERT_COMPARE_SHIFT)
  7558. #define CERT_FIND_SUBJECT_NAME (CERT_COMPARE_NAME << CERT_COMPARE_SHIFT | \
  7559. CERT_INFO_SUBJECT_FLAG)
  7560. #define CERT_FIND_SUBJECT_ATTR (CERT_COMPARE_ATTR << CERT_COMPARE_SHIFT | \
  7561. CERT_INFO_SUBJECT_FLAG)
  7562. #define CERT_FIND_ISSUER_NAME (CERT_COMPARE_NAME << CERT_COMPARE_SHIFT | \
  7563. CERT_INFO_ISSUER_FLAG)
  7564. #define CERT_FIND_ISSUER_ATTR (CERT_COMPARE_ATTR << CERT_COMPARE_SHIFT | \
  7565. CERT_INFO_ISSUER_FLAG)
  7566. #define CERT_FIND_SUBJECT_STR_A (CERT_COMPARE_NAME_STR_A << CERT_COMPARE_SHIFT | \
  7567. CERT_INFO_SUBJECT_FLAG)
  7568. #define CERT_FIND_SUBJECT_STR_W (CERT_COMPARE_NAME_STR_W << CERT_COMPARE_SHIFT | \
  7569. CERT_INFO_SUBJECT_FLAG)
  7570. #define CERT_FIND_SUBJECT_STR CERT_FIND_SUBJECT_STR_W
  7571. #define CERT_FIND_ISSUER_STR_A (CERT_COMPARE_NAME_STR_A << CERT_COMPARE_SHIFT | \
  7572. CERT_INFO_ISSUER_FLAG)
  7573. #define CERT_FIND_ISSUER_STR_W (CERT_COMPARE_NAME_STR_W << CERT_COMPARE_SHIFT | \
  7574. CERT_INFO_ISSUER_FLAG)
  7575. #define CERT_FIND_ISSUER_STR CERT_FIND_ISSUER_STR_W
  7576. #define CERT_FIND_KEY_SPEC (CERT_COMPARE_KEY_SPEC << CERT_COMPARE_SHIFT)
  7577. #define CERT_FIND_ENHKEY_USAGE (CERT_COMPARE_ENHKEY_USAGE << CERT_COMPARE_SHIFT)
  7578. #define CERT_FIND_CTL_USAGE CERT_FIND_ENHKEY_USAGE
  7579. #define CERT_FIND_SUBJECT_CERT (CERT_COMPARE_SUBJECT_CERT << CERT_COMPARE_SHIFT)
  7580. #define CERT_FIND_ISSUER_OF (CERT_COMPARE_ISSUER_OF << CERT_COMPARE_SHIFT)
  7581. #define CERT_FIND_EXISTING (CERT_COMPARE_EXISTING << CERT_COMPARE_SHIFT)
  7582. #define CERT_FIND_CERT_ID (CERT_COMPARE_CERT_ID << CERT_COMPARE_SHIFT)
  7583. #define CERT_FIND_CROSS_CERT_DIST_POINTS \
  7584. (CERT_COMPARE_CROSS_CERT_DIST_POINTS << CERT_COMPARE_SHIFT)
  7585. #define CERT_FIND_PUBKEY_MD5_HASH \
  7586. (CERT_COMPARE_PUBKEY_MD5_HASH << CERT_COMPARE_SHIFT)
  7587. //+-------------------------------------------------------------------------
  7588. // CERT_FIND_ANY
  7589. //
  7590. // Find any certificate.
  7591. //
  7592. // pvFindPara isn't used.
  7593. //--------------------------------------------------------------------------
  7594. //+-------------------------------------------------------------------------
  7595. // CERT_FIND_HASH
  7596. //
  7597. // Find a certificate with the specified hash.
  7598. //
  7599. // pvFindPara points to a CRYPT_HASH_BLOB.
  7600. //--------------------------------------------------------------------------
  7601. //+-------------------------------------------------------------------------
  7602. // CERT_FIND_KEY_IDENTIFIER
  7603. //
  7604. // Find a certificate with the specified KeyIdentifier. Gets the
  7605. // CERT_KEY_IDENTIFIER_PROP_ID property and compares with the input
  7606. // CRYPT_HASH_BLOB.
  7607. //
  7608. // pvFindPara points to a CRYPT_HASH_BLOB.
  7609. //--------------------------------------------------------------------------
  7610. //+-------------------------------------------------------------------------
  7611. // CERT_FIND_PROPERTY
  7612. //
  7613. // Find a certificate having the specified property.
  7614. //
  7615. // pvFindPara points to a DWORD containing the PROP_ID
  7616. //--------------------------------------------------------------------------
  7617. //+-------------------------------------------------------------------------
  7618. // CERT_FIND_PUBLIC_KEY
  7619. //
  7620. // Find a certificate matching the specified public key.
  7621. //
  7622. // pvFindPara points to a CERT_PUBLIC_KEY_INFO containing the public key
  7623. //--------------------------------------------------------------------------
  7624. //+-------------------------------------------------------------------------
  7625. // CERT_FIND_SUBJECT_NAME
  7626. // CERT_FIND_ISSUER_NAME
  7627. //
  7628. // Find a certificate with the specified subject/issuer name. Does an exact
  7629. // match of the entire name.
  7630. //
  7631. // Restricts search to certificates matching the dwCertEncodingType.
  7632. //
  7633. // pvFindPara points to a CERT_NAME_BLOB.
  7634. //--------------------------------------------------------------------------
  7635. //+-------------------------------------------------------------------------
  7636. // CERT_FIND_SUBJECT_ATTR
  7637. // CERT_FIND_ISSUER_ATTR
  7638. //
  7639. // Find a certificate with the specified subject/issuer attributes.
  7640. //
  7641. // Compares the attributes in the subject/issuer name with the
  7642. // Relative Distinguished Name's (CERT_RDN) array of attributes specified in
  7643. // pvFindPara. The comparison iterates through the CERT_RDN attributes and looks
  7644. // for an attribute match in any of the subject/issuer's RDNs.
  7645. //
  7646. // The CERT_RDN_ATTR fields can have the following special values:
  7647. // pszObjId == NULL - ignore the attribute object identifier
  7648. // dwValueType == RDN_ANY_TYPE - ignore the value type
  7649. // Value.pbData == NULL - match any value
  7650. //
  7651. // CERT_CASE_INSENSITIVE_IS_RDN_ATTRS_FLAG should be set in dwFindFlags to do
  7652. // a case insensitive match. Otherwise, defaults to an exact, case sensitive
  7653. // match.
  7654. //
  7655. // CERT_UNICODE_IS_RDN_ATTRS_FLAG should be set in dwFindFlags if the RDN was
  7656. // initialized with unicode strings as for
  7657. // CryptEncodeObject(X509_UNICODE_NAME).
  7658. //
  7659. // Restricts search to certificates matching the dwCertEncodingType.
  7660. //
  7661. // pvFindPara points to a CERT_RDN (defined in wincert.h).
  7662. //--------------------------------------------------------------------------
  7663. //+-------------------------------------------------------------------------
  7664. // CERT_FIND_SUBJECT_STR_A
  7665. // CERT_FIND_SUBJECT_STR_W | CERT_FIND_SUBJECT_STR
  7666. // CERT_FIND_ISSUER_STR_A
  7667. // CERT_FIND_ISSUER_STR_W | CERT_FIND_ISSUER_STR
  7668. //
  7669. // Find a certificate containing the specified subject/issuer name string.
  7670. //
  7671. // First, the certificate's subject/issuer is converted to a name string
  7672. // via CertNameToStrA/CertNameToStrW(CERT_SIMPLE_NAME_STR). Then, a
  7673. // case insensitive substring within string match is performed.
  7674. //
  7675. // Restricts search to certificates matching the dwCertEncodingType.
  7676. //
  7677. // For *_STR_A, pvFindPara points to a null terminated character string.
  7678. // For *_STR_W, pvFindPara points to a null terminated wide character string.
  7679. //--------------------------------------------------------------------------
  7680. //+-------------------------------------------------------------------------
  7681. // CERT_FIND_KEY_SPEC
  7682. //
  7683. // Find a certificate having a CERT_KEY_SPEC_PROP_ID property matching
  7684. // the specified KeySpec.
  7685. //
  7686. // pvFindPara points to a DWORD containing the KeySpec.
  7687. //--------------------------------------------------------------------------
  7688. //+-------------------------------------------------------------------------
  7689. // CERT_FIND_ENHKEY_USAGE
  7690. //
  7691. // Find a certificate having the szOID_ENHANCED_KEY_USAGE extension or
  7692. // the CERT_ENHKEY_USAGE_PROP_ID and matching the specified pszUsageIdentifers.
  7693. //
  7694. // pvFindPara points to a CERT_ENHKEY_USAGE data structure. If pvFindPara
  7695. // is NULL or CERT_ENHKEY_USAGE's cUsageIdentifier is 0, then, matches any
  7696. // certificate having enhanced key usage.
  7697. //
  7698. // If the CERT_FIND_VALID_ENHKEY_USAGE_FLAG is set, then, only does a match
  7699. // for certificates that are valid for the specified usages. By default,
  7700. // the ceriticate must be valid for all usages. CERT_FIND_OR_ENHKEY_USAGE_FLAG
  7701. // can be set, if the certificate only needs to be valid for one of the
  7702. // specified usages. Note, CertGetValidUsages() is called to get the
  7703. // certificate's list of valid usages. Only the CERT_FIND_OR_ENHKEY_USAGE_FLAG
  7704. // is applicable when this flag is set.
  7705. //
  7706. // The CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG can be set in dwFindFlags to
  7707. // also match a certificate without either the extension or property.
  7708. //
  7709. // If CERT_FIND_NO_ENHKEY_USAGE_FLAG is set in dwFindFlags, finds
  7710. // certificates without the key usage extension or property. Setting this
  7711. // flag takes precedence over pvFindPara being NULL.
  7712. //
  7713. // If the CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG is set, then, only does a match
  7714. // using the extension. If pvFindPara is NULL or cUsageIdentifier is set to
  7715. // 0, finds certificates having the extension. If
  7716. // CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG is set, also matches a certificate
  7717. // without the extension. If CERT_FIND_NO_ENHKEY_USAGE_FLAG is set, finds
  7718. // certificates without the extension.
  7719. //
  7720. // If the CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG is set, then, only does a match
  7721. // using the property. If pvFindPara is NULL or cUsageIdentifier is set to
  7722. // 0, finds certificates having the property. If
  7723. // CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG is set, also matches a certificate
  7724. // without the property. If CERT_FIND_NO_ENHKEY_USAGE_FLAG is set, finds
  7725. // certificates without the property.
  7726. //
  7727. // If CERT_FIND_OR_ENHKEY_USAGE_FLAG is set, does an "OR" match of any of
  7728. // the specified pszUsageIdentifiers. If not set, then, does an "AND" match
  7729. // of all of the specified pszUsageIdentifiers.
  7730. //--------------------------------------------------------------------------
  7731. #define CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG 0x1
  7732. #define CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG 0x2
  7733. #define CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG 0x4
  7734. #define CERT_FIND_NO_ENHKEY_USAGE_FLAG 0x8
  7735. #define CERT_FIND_OR_ENHKEY_USAGE_FLAG 0x10
  7736. #define CERT_FIND_VALID_ENHKEY_USAGE_FLAG 0x20
  7737. #define CERT_FIND_OPTIONAL_CTL_USAGE_FLAG CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG
  7738. #define CERT_FIND_EXT_ONLY_CTL_USAGE_FLAG \
  7739. CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG
  7740. #define CERT_FIND_PROP_ONLY_CTL_USAGE_FLAG \
  7741. CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG
  7742. #define CERT_FIND_NO_CTL_USAGE_FLAG CERT_FIND_NO_ENHKEY_USAGE_FLAG
  7743. #define CERT_FIND_OR_CTL_USAGE_FLAG CERT_FIND_OR_ENHKEY_USAGE_FLAG
  7744. #define CERT_FIND_VALID_CTL_USAGE_FLAG CERT_FIND_VALID_ENHKEY_USAGE_FLAG
  7745. //+-------------------------------------------------------------------------
  7746. // CERT_FIND_CERT_ID
  7747. //
  7748. // Find a certificate with the specified CERT_ID.
  7749. //
  7750. // pvFindPara points to a CERT_ID.
  7751. //--------------------------------------------------------------------------
  7752. //+-------------------------------------------------------------------------
  7753. // CERT_FIND_CROSS_CERT_DIST_POINTS
  7754. //
  7755. // Find a certificate having either a cross certificate distribution
  7756. // point extension or property.
  7757. //
  7758. // pvFindPara isn't used.
  7759. //--------------------------------------------------------------------------
  7760. //+-------------------------------------------------------------------------
  7761. // Get the certificate context from the store for the first or next issuer
  7762. // of the specified subject certificate. Perform the enabled
  7763. // verification checks on the subject. (Note, the checks are on the subject
  7764. // using the returned issuer certificate.)
  7765. //
  7766. // If the first or next issuer certificate isn't found, NULL is returned.
  7767. // Otherwise, a pointer to a read only CERT_CONTEXT is returned. CERT_CONTEXT
  7768. // must be freed by calling CertFreeCertificateContext or is freed when passed as the
  7769. // pPrevIssuerContext on a subsequent call. CertDuplicateCertificateContext
  7770. // can be called to make a duplicate.
  7771. //
  7772. // For a self signed subject certificate, NULL is returned with LastError set
  7773. // to CERT_STORE_SELF_SIGNED. The enabled verification checks are still done.
  7774. //
  7775. // The pSubjectContext may have been obtained from this store, another store
  7776. // or created by the caller application. When created by the caller, the
  7777. // CertCreateCertificateContext function must have been called.
  7778. //
  7779. // An issuer may have multiple certificates. This may occur when the validity
  7780. // period is about to change. pPrevIssuerContext MUST BE NULL on the first
  7781. // call to get the issuer. To get the next certificate for the issuer, the
  7782. // pPrevIssuerContext is set to the CERT_CONTEXT returned by a previous call.
  7783. //
  7784. // NOTE: a NON-NULL pPrevIssuerContext is always CertFreeCertificateContext'ed by
  7785. // this function, even for an error.
  7786. //
  7787. // The following flags can be set in *pdwFlags to enable verification checks
  7788. // on the subject certificate context:
  7789. // CERT_STORE_SIGNATURE_FLAG - use the public key in the returned
  7790. // issuer certificate to verify the
  7791. // signature on the subject certificate.
  7792. // Note, if pSubjectContext->hCertStore ==
  7793. // hCertStore, the store provider might
  7794. // be able to eliminate a redo of
  7795. // the signature verify.
  7796. // CERT_STORE_TIME_VALIDITY_FLAG - get the current time and verify that
  7797. // its within the subject certificate's
  7798. // validity period
  7799. // CERT_STORE_REVOCATION_FLAG - check if the subject certificate is on
  7800. // the issuer's revocation list
  7801. //
  7802. // If an enabled verification check fails, then, its flag is set upon return.
  7803. // If CERT_STORE_REVOCATION_FLAG was enabled and the issuer doesn't have a
  7804. // CRL in the store, then, CERT_STORE_NO_CRL_FLAG is set in addition to
  7805. // the CERT_STORE_REVOCATION_FLAG.
  7806. //
  7807. // If CERT_STORE_SIGNATURE_FLAG or CERT_STORE_REVOCATION_FLAG is set, then,
  7808. // CERT_STORE_NO_ISSUER_FLAG is set if it doesn't have an issuer certificate
  7809. // in the store.
  7810. //
  7811. // For a verification check failure, a pointer to the issuer's CERT_CONTEXT
  7812. // is still returned and SetLastError isn't updated.
  7813. //--------------------------------------------------------------------------
  7814. WINCRYPT32API
  7815. PCCERT_CONTEXT
  7816. WINAPI
  7817. CertGetIssuerCertificateFromStore(
  7818. IN HCERTSTORE hCertStore,
  7819. IN PCCERT_CONTEXT pSubjectContext,
  7820. IN OPTIONAL PCCERT_CONTEXT pPrevIssuerContext,
  7821. IN OUT DWORD *pdwFlags
  7822. );
  7823. //+-------------------------------------------------------------------------
  7824. // Perform the enabled verification checks on the subject certificate
  7825. // using the issuer. Same checks and flags definitions as for the above
  7826. // CertGetIssuerCertificateFromStore.
  7827. //
  7828. // If you are only checking CERT_STORE_TIME_VALIDITY_FLAG, then, the
  7829. // issuer can be NULL.
  7830. //
  7831. // For a verification check failure, SUCCESS is still returned.
  7832. //--------------------------------------------------------------------------
  7833. WINCRYPT32API
  7834. BOOL
  7835. WINAPI
  7836. CertVerifySubjectCertificateContext(
  7837. IN PCCERT_CONTEXT pSubject,
  7838. IN OPTIONAL PCCERT_CONTEXT pIssuer,
  7839. IN OUT DWORD *pdwFlags
  7840. );
  7841. //+-------------------------------------------------------------------------
  7842. // Duplicate a certificate context
  7843. //--------------------------------------------------------------------------
  7844. WINCRYPT32API
  7845. PCCERT_CONTEXT
  7846. WINAPI
  7847. CertDuplicateCertificateContext(
  7848. IN PCCERT_CONTEXT pCertContext
  7849. );
  7850. //+-------------------------------------------------------------------------
  7851. // Create a certificate context from the encoded certificate. The created
  7852. // context isn't put in a store.
  7853. //
  7854. // Makes a copy of the encoded certificate in the created context.
  7855. //
  7856. // If unable to decode and create the certificate context, NULL is returned.
  7857. // Otherwise, a pointer to a read only CERT_CONTEXT is returned.
  7858. // CERT_CONTEXT must be freed by calling CertFreeCertificateContext.
  7859. // CertDuplicateCertificateContext can be called to make a duplicate.
  7860. //
  7861. // CertSetCertificateContextProperty and CertGetCertificateContextProperty can be called
  7862. // to store properties for the certificate.
  7863. //--------------------------------------------------------------------------
  7864. WINCRYPT32API
  7865. PCCERT_CONTEXT
  7866. WINAPI
  7867. CertCreateCertificateContext(
  7868. IN DWORD dwCertEncodingType,
  7869. IN const BYTE *pbCertEncoded,
  7870. IN DWORD cbCertEncoded
  7871. );
  7872. //+-------------------------------------------------------------------------
  7873. // Free a certificate context
  7874. //
  7875. // There needs to be a corresponding free for each context obtained by a
  7876. // get, find, duplicate or create.
  7877. //--------------------------------------------------------------------------
  7878. WINCRYPT32API
  7879. BOOL
  7880. WINAPI
  7881. CertFreeCertificateContext(
  7882. IN PCCERT_CONTEXT pCertContext
  7883. );
  7884. //+-------------------------------------------------------------------------
  7885. // Set the property for the specified certificate context.
  7886. //
  7887. // The type definition for pvData depends on the dwPropId value. There are
  7888. // five predefined types:
  7889. // CERT_KEY_PROV_HANDLE_PROP_ID - a HCRYPTPROV for the certificate's
  7890. // private key is passed in pvData. Updates the hCryptProv field
  7891. // of the CERT_KEY_CONTEXT_PROP_ID. If the CERT_KEY_CONTEXT_PROP_ID
  7892. // doesn't exist, its created with all the other fields zeroed out. If
  7893. // CERT_STORE_NO_CRYPT_RELEASE_FLAG isn't set, HCRYPTPROV is implicitly
  7894. // released when either the property is set to NULL or on the final
  7895. // free of the CertContext.
  7896. //
  7897. // CERT_KEY_PROV_INFO_PROP_ID - a PCRYPT_KEY_PROV_INFO for the certificate's
  7898. // private key is passed in pvData.
  7899. //
  7900. // CERT_SHA1_HASH_PROP_ID -
  7901. // CERT_MD5_HASH_PROP_ID -
  7902. // CERT_SIGNATURE_HASH_PROP_ID - normally, a hash property is implicitly
  7903. // set by doing a CertGetCertificateContextProperty. pvData points to a
  7904. // CRYPT_HASH_BLOB.
  7905. //
  7906. // CERT_KEY_CONTEXT_PROP_ID - a PCERT_KEY_CONTEXT for the certificate's
  7907. // private key is passed in pvData. The CERT_KEY_CONTEXT contains both the
  7908. // hCryptProv and dwKeySpec for the private key.
  7909. // See the CERT_KEY_PROV_HANDLE_PROP_ID for more information about
  7910. // the hCryptProv field and dwFlags settings. Note, more fields may
  7911. // be added for this property. The cbSize field value will be adjusted
  7912. // accordingly.
  7913. //
  7914. // CERT_KEY_SPEC_PROP_ID - the dwKeySpec for the private key. pvData
  7915. // points to a DWORD containing the KeySpec
  7916. //
  7917. // CERT_ENHKEY_USAGE_PROP_ID - enhanced key usage definition for the
  7918. // certificate. pvData points to a CRYPT_DATA_BLOB containing an
  7919. // ASN.1 encoded CERT_ENHKEY_USAGE (encoded via
  7920. // CryptEncodeObject(X509_ENHANCED_KEY_USAGE).
  7921. //
  7922. // CERT_NEXT_UPDATE_LOCATION_PROP_ID - location of the next update.
  7923. // Currently only applicable to CTLs. pvData points to a CRYPT_DATA_BLOB
  7924. // containing an ASN.1 encoded CERT_ALT_NAME_INFO (encoded via
  7925. // CryptEncodeObject(X509_ALTERNATE_NAME)).
  7926. //
  7927. // CERT_FRIENDLY_NAME_PROP_ID - friendly name for the cert, CRL or CTL.
  7928. // pvData points to a CRYPT_DATA_BLOB. pbData is a pointer to a NULL
  7929. // terminated unicode, wide character string.
  7930. // cbData = (wcslen((LPWSTR) pbData) + 1) * sizeof(WCHAR).
  7931. //
  7932. // CERT_DESCRIPTION_PROP_ID - description for the cert, CRL or CTL.
  7933. // pvData points to a CRYPT_DATA_BLOB. pbData is a pointer to a NULL
  7934. // terminated unicode, wide character string.
  7935. // cbData = (wcslen((LPWSTR) pbData) + 1) * sizeof(WCHAR).
  7936. //
  7937. // CERT_ARCHIVED_PROP_ID - when this property is set, the certificate
  7938. // is skipped during enumeration. Note, certificates having this property
  7939. // are still found for explicit finds, such as, finding a certificate
  7940. // with a specific hash or finding a certificate having a specific issuer
  7941. // and serial number. pvData points to a CRYPT_DATA_BLOB. This blob
  7942. // can be NULL (pbData = NULL, cbData = 0).
  7943. //
  7944. // CERT_PUBKEY_ALG_PARA_PROP_ID - for public keys supporting
  7945. // algorithm parameter inheritance. pvData points to a CRYPT_OBJID_BLOB
  7946. // containing the ASN.1 encoded PublicKey Algorithm Parameters. For
  7947. // DSS this would be the parameters encoded via
  7948. // CryptEncodeObject(X509_DSS_PARAMETERS). This property may be set
  7949. // by CryptVerifyCertificateSignatureEx().
  7950. //
  7951. // CERT_CROSS_CERT_DIST_POINTS_PROP_ID - location of the cross certs.
  7952. // Currently only applicable to certs. pvData points to a CRYPT_DATA_BLOB
  7953. // containing an ASN.1 encoded CROSS_CERT_DIST_POINTS_INFO (encoded via
  7954. // CryptEncodeObject(X509_CROSS_CERT_DIST_POINTS)).
  7955. //
  7956. // CERT_ENROLLMENT_PROP_ID - enrollment information of the pending request.
  7957. // It contains RequestID, CADNSName, CAName, and FriendlyName.
  7958. // The data format is defined as, the first 4 bytes - pending request ID,
  7959. // next 4 bytes - CADNSName size in characters including null-terminator
  7960. // followed by CADNSName string with null-terminator,
  7961. // next 4 bytes - CAName size in characters including null-terminator
  7962. // followed by CAName string with null-terminator,
  7963. // next 4 bytes - FriendlyName size in characters including null-terminator
  7964. // followed by FriendlyName string with null-terminator.
  7965. //
  7966. // CERT_DATE_STAMP_PROP_ID - contains the time when added to the store
  7967. // by an admin tool. pvData points to a CRYPT_DATA_BLOB containing
  7968. // the FILETIME.
  7969. //
  7970. // CERT_RENEWAL_PROP_ID - contains the hash of renewed certificate
  7971. //
  7972. // For all the other PROP_IDs: an encoded PCRYPT_DATA_BLOB is passed in pvData.
  7973. //
  7974. // If the property already exists, then, the old value is deleted and silently
  7975. // replaced. Setting, pvData to NULL, deletes the property.
  7976. //
  7977. // CERT_SET_PROPERTY_IGNORE_PERSIST_ERROR_FLAG can be set to ignore any
  7978. // provider write errors and always update the cached context's property.
  7979. //--------------------------------------------------------------------------
  7980. WINCRYPT32API
  7981. BOOL
  7982. WINAPI
  7983. CertSetCertificateContextProperty(
  7984. IN PCCERT_CONTEXT pCertContext,
  7985. IN DWORD dwPropId,
  7986. IN DWORD dwFlags,
  7987. IN const void *pvData
  7988. );
  7989. // Set this flag to ignore any store provider write errors and always update
  7990. // the cached context's property
  7991. #define CERT_SET_PROPERTY_IGNORE_PERSIST_ERROR_FLAG 0x80000000
  7992. // Set this flag to inhibit the persisting of this property
  7993. #define CERT_SET_PROPERTY_INHIBIT_PERSIST_FLAG 0x40000000
  7994. //+-------------------------------------------------------------------------
  7995. // Get the property for the specified certificate context.
  7996. //
  7997. // For CERT_KEY_PROV_HANDLE_PROP_ID, pvData points to a HCRYPTPROV.
  7998. //
  7999. // For CERT_KEY_PROV_INFO_PROP_ID, pvData points to a CRYPT_KEY_PROV_INFO structure.
  8000. // Elements pointed to by fields in the pvData structure follow the
  8001. // structure. Therefore, *pcbData may exceed the size of the structure.
  8002. //
  8003. // For CERT_KEY_CONTEXT_PROP_ID, pvData points to a CERT_KEY_CONTEXT structure.
  8004. //
  8005. // For CERT_KEY_SPEC_PROP_ID, pvData points to a DWORD containing the KeySpec.
  8006. // If the CERT_KEY_CONTEXT_PROP_ID exists, the KeySpec is obtained from there.
  8007. // Otherwise, if the CERT_KEY_PROV_INFO_PROP_ID exists, its the source
  8008. // of the KeySpec.
  8009. //
  8010. // For CERT_SHA1_HASH_PROP_ID or CERT_MD5_HASH_PROP_ID, if the hash
  8011. // doesn't already exist, then, its computed via CryptHashCertificate()
  8012. // and then set. pvData points to the computed hash. Normally, the length
  8013. // is 20 bytes for SHA and 16 for MD5.
  8014. //
  8015. // For CERT_SIGNATURE_HASH_PROP_ID, if the hash
  8016. // doesn't already exist, then, its computed via CryptHashToBeSigned()
  8017. // and then set. pvData points to the computed hash. Normally, the length
  8018. // is 20 bytes for SHA and 16 for MD5.
  8019. //
  8020. // For CERT_ACCESS_STATE_PROP_ID, pvData points to a DWORD containing the
  8021. // access state flags. The appropriate CERT_ACCESS_STATE_*_FLAG's are set
  8022. // in the returned DWORD. See the CERT_ACCESS_STATE_*_FLAG definitions
  8023. // above. Note, this property is read only. It can't be set.
  8024. //
  8025. // For CERT_KEY_IDENTIFIER_PROP_ID, if property doesn't already exist,
  8026. // first searches for the szOID_SUBJECT_KEY_IDENTIFIER extension. Next,
  8027. // does SHA1 hash of the certficate's SubjectPublicKeyInfo. pvData
  8028. // points to the key identifier bytes. Normally, the length is 20 bytes.
  8029. //
  8030. // For CERT_PUBKEY_ALG_PARA_PROP_ID, pvPara points to the ASN.1 encoded
  8031. // PublicKey Algorithm Parameters. This property will only be set
  8032. // for public keys supporting algorithm parameter inheritance and when the
  8033. // parameters have been omitted from the encoded and signed certificate.
  8034. //
  8035. // For CERT_DATE_STAMP_PROP_ID, pvPara points to a FILETIME updated by
  8036. // an admin tool to indicate when the certificate was added to the store.
  8037. //
  8038. // For all other PROP_IDs, pvData points to an encoded array of bytes.
  8039. //--------------------------------------------------------------------------
  8040. WINCRYPT32API
  8041. BOOL
  8042. WINAPI
  8043. CertGetCertificateContextProperty(
  8044. IN PCCERT_CONTEXT pCertContext,
  8045. IN DWORD dwPropId,
  8046. OUT void *pvData,
  8047. IN OUT DWORD *pcbData
  8048. );
  8049. //+-------------------------------------------------------------------------
  8050. // Enumerate the properties for the specified certificate context.
  8051. //
  8052. // To get the first property, set dwPropId to 0. The ID of the first
  8053. // property is returned. To get the next property, set dwPropId to the
  8054. // ID returned by the last call. To enumerate all the properties continue
  8055. // until 0 is returned.
  8056. //
  8057. // CertGetCertificateContextProperty is called to get the property's data.
  8058. //
  8059. // Note, since, the CERT_KEY_PROV_HANDLE_PROP_ID and CERT_KEY_SPEC_PROP_ID
  8060. // properties are stored as fields in the CERT_KEY_CONTEXT_PROP_ID
  8061. // property, they aren't enumerated individually.
  8062. //--------------------------------------------------------------------------
  8063. WINCRYPT32API
  8064. DWORD
  8065. WINAPI
  8066. CertEnumCertificateContextProperties(
  8067. IN PCCERT_CONTEXT pCertContext,
  8068. IN DWORD dwPropId
  8069. );
  8070. //+-------------------------------------------------------------------------
  8071. // Creates a CTL entry whose attributes are the certificate context's
  8072. // properties.
  8073. //
  8074. // The SubjectIdentifier in the CTL entry is the SHA1 hash of the certificate.
  8075. //
  8076. // The certificate properties are added as attributes. The property attribute
  8077. // OID is the decimal PROP_ID preceded by szOID_CERT_PROP_ID_PREFIX. Each
  8078. // property value is copied as a single attribute value.
  8079. //
  8080. // Any additional attributes to be included in the CTL entry can be passed
  8081. // in via the cOptAttr and rgOptAttr parameters.
  8082. //
  8083. // CTL_ENTRY_FROM_PROP_CHAIN_FLAG can be set in dwFlags, to force the
  8084. // inclusion of the chain building hash properties as attributes.
  8085. //--------------------------------------------------------------------------
  8086. WINCRYPT32API
  8087. BOOL
  8088. WINAPI
  8089. CertCreateCTLEntryFromCertificateContextProperties(
  8090. IN PCCERT_CONTEXT pCertContext,
  8091. IN DWORD cOptAttr,
  8092. IN OPTIONAL PCRYPT_ATTRIBUTE rgOptAttr,
  8093. IN DWORD dwFlags,
  8094. IN OPTIONAL void *pvReserved,
  8095. OUT OPTIONAL PCTL_ENTRY pCtlEntry,
  8096. IN OUT DWORD *pcbCtlEntry
  8097. );
  8098. // Set this flag to get and include the chain building hash properties
  8099. // as attributes in the CTL entry
  8100. #define CTL_ENTRY_FROM_PROP_CHAIN_FLAG 0x1
  8101. //+-------------------------------------------------------------------------
  8102. // Sets properties on the certificate context using the attributes in
  8103. // the CTL entry.
  8104. //
  8105. // The property attribute OID is the decimal PROP_ID preceded by
  8106. // szOID_CERT_PROP_ID_PREFIX. Only attributes containing such an OID are
  8107. // copied.
  8108. //
  8109. // CERT_SET_PROPERTY_IGNORE_PERSIST_ERROR_FLAG may be set in dwFlags.
  8110. //--------------------------------------------------------------------------
  8111. WINCRYPT32API
  8112. BOOL
  8113. WINAPI
  8114. CertSetCertificateContextPropertiesFromCTLEntry(
  8115. IN PCCERT_CONTEXT pCertContext,
  8116. IN PCTL_ENTRY pCtlEntry,
  8117. IN DWORD dwFlags
  8118. );
  8119. //+-------------------------------------------------------------------------
  8120. // Get the first or next CRL context from the store for the specified
  8121. // issuer certificate. Perform the enabled verification checks on the CRL.
  8122. //
  8123. // If the first or next CRL isn't found, NULL is returned.
  8124. // Otherwise, a pointer to a read only CRL_CONTEXT is returned. CRL_CONTEXT
  8125. // must be freed by calling CertFreeCRLContext. However, the free must be
  8126. // pPrevCrlContext on a subsequent call. CertDuplicateCRLContext
  8127. // can be called to make a duplicate.
  8128. //
  8129. // The pIssuerContext may have been obtained from this store, another store
  8130. // or created by the caller application. When created by the caller, the
  8131. // CertCreateCertificateContext function must have been called.
  8132. //
  8133. // If pIssuerContext == NULL, finds all the CRLs in the store.
  8134. //
  8135. // An issuer may have multiple CRLs. For example, it generates delta CRLs
  8136. // using a X.509 v3 extension. pPrevCrlContext MUST BE NULL on the first
  8137. // call to get the CRL. To get the next CRL for the issuer, the
  8138. // pPrevCrlContext is set to the CRL_CONTEXT returned by a previous call.
  8139. //
  8140. // NOTE: a NON-NULL pPrevCrlContext is always CertFreeCRLContext'ed by
  8141. // this function, even for an error.
  8142. //
  8143. // The following flags can be set in *pdwFlags to enable verification checks
  8144. // on the returned CRL:
  8145. // CERT_STORE_SIGNATURE_FLAG - use the public key in the
  8146. // issuer's certificate to verify the
  8147. // signature on the returned CRL.
  8148. // Note, if pIssuerContext->hCertStore ==
  8149. // hCertStore, the store provider might
  8150. // be able to eliminate a redo of
  8151. // the signature verify.
  8152. // CERT_STORE_TIME_VALIDITY_FLAG - get the current time and verify that
  8153. // its within the CRL's ThisUpdate and
  8154. // NextUpdate validity period.
  8155. // CERT_STORE_BASE_CRL_FLAG - get base CRL.
  8156. // CERT_STORE_DELTA_CRL_FLAG - get delta CRL.
  8157. //
  8158. // If only one of CERT_STORE_BASE_CRL_FLAG or CERT_STORE_DELTA_CRL_FLAG is
  8159. // set, then, only returns either a base or delta CRL. In any case, the
  8160. // appropriate base or delta flag will be cleared upon returned. If both
  8161. // flags are set, then, only one of flags will be cleared.
  8162. //
  8163. // If an enabled verification check fails, then, its flag is set upon return.
  8164. //
  8165. // If pIssuerContext == NULL, then, an enabled CERT_STORE_SIGNATURE_FLAG
  8166. // always fails and the CERT_STORE_NO_ISSUER_FLAG is also set.
  8167. //
  8168. // For a verification check failure, a pointer to the first or next
  8169. // CRL_CONTEXT is still returned and SetLastError isn't updated.
  8170. //--------------------------------------------------------------------------
  8171. WINCRYPT32API
  8172. PCCRL_CONTEXT
  8173. WINAPI
  8174. CertGetCRLFromStore(
  8175. IN HCERTSTORE hCertStore,
  8176. IN OPTIONAL PCCERT_CONTEXT pIssuerContext,
  8177. IN PCCRL_CONTEXT pPrevCrlContext,
  8178. IN OUT DWORD *pdwFlags
  8179. );
  8180. //+-------------------------------------------------------------------------
  8181. // Enumerate the CRL contexts in the store.
  8182. //
  8183. // If a CRL isn't found, NULL is returned.
  8184. // Otherwise, a pointer to a read only CRL_CONTEXT is returned. CRL_CONTEXT
  8185. // must be freed by calling CertFreeCRLContext or is freed when passed as the
  8186. // pPrevCrlContext on a subsequent call. CertDuplicateCRLContext
  8187. // can be called to make a duplicate.
  8188. //
  8189. // pPrevCrlContext MUST BE NULL to enumerate the first
  8190. // CRL in the store. Successive CRLs are enumerated by setting
  8191. // pPrevCrlContext to the CRL_CONTEXT returned by a previous call.
  8192. //
  8193. // NOTE: a NON-NULL pPrevCrlContext is always CertFreeCRLContext'ed by
  8194. // this function, even for an error.
  8195. //--------------------------------------------------------------------------
  8196. WINCRYPT32API
  8197. PCCRL_CONTEXT
  8198. WINAPI
  8199. CertEnumCRLsInStore(
  8200. IN HCERTSTORE hCertStore,
  8201. IN PCCRL_CONTEXT pPrevCrlContext
  8202. );
  8203. //+-------------------------------------------------------------------------
  8204. // Find the first or next CRL context in the store.
  8205. //
  8206. // The CRL is found according to the dwFindType and its pvFindPara.
  8207. // See below for a list of the find types and its parameters.
  8208. //
  8209. // Currently dwFindFlags isn't used and must be set to 0.
  8210. //
  8211. // Usage of dwCertEncodingType depends on the dwFindType.
  8212. //
  8213. // If the first or next 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 on the first
  8220. // call to find the CRL. To find the next CRL, the
  8221. // pPrevCrlContext is set 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. CertFindCRLInStore(
  8230. IN HCERTSTORE hCertStore,
  8231. IN DWORD dwCertEncodingType,
  8232. IN DWORD dwFindFlags,
  8233. IN DWORD dwFindType,
  8234. IN const void *pvFindPara,
  8235. IN PCCRL_CONTEXT pPrevCrlContext
  8236. );
  8237. #define CRL_FIND_ANY 0
  8238. #define CRL_FIND_ISSUED_BY 1
  8239. #define CRL_FIND_EXISTING 2
  8240. #define CRL_FIND_ISSUED_FOR 3
  8241. //+-------------------------------------------------------------------------
  8242. // CRL_FIND_ANY
  8243. //
  8244. // Find any CRL.
  8245. //
  8246. // pvFindPara isn't used.
  8247. //--------------------------------------------------------------------------
  8248. //+-------------------------------------------------------------------------
  8249. // CRL_FIND_ISSUED_BY
  8250. //
  8251. // Find CRL matching the specified issuer.
  8252. //
  8253. // pvFindPara is the PCCERT_CONTEXT of the CRL issuer. May be NULL to
  8254. // match any issuer.
  8255. //
  8256. // By default, only does issuer name matching. The following flags can be
  8257. // set in dwFindFlags to do additional filtering.
  8258. //
  8259. // If CRL_FIND_ISSUED_BY_AKI_FLAG is set in dwFindFlags, then, checks if the
  8260. // CRL has an Authority Key Identifier (AKI) extension. If the CRL has an
  8261. // AKI, then, only returns a CRL whose AKI matches the issuer.
  8262. //
  8263. // Note, the AKI extension has the following OID:
  8264. // szOID_AUTHORITY_KEY_IDENTIFIER2 and its corresponding data structure.
  8265. //
  8266. // If CRL_FIND_ISSUED_BY_SIGNATURE_FLAG is set in dwFindFlags, then,
  8267. // uses the public key in the issuer's certificate to verify the
  8268. // signature on the CRL. Only returns a CRL having a valid signature.
  8269. //
  8270. // If CRL_FIND_ISSUED_BY_DELTA_FLAG is set in dwFindFlags, then, only
  8271. // returns a delta CRL.
  8272. //
  8273. // If CRL_FIND_ISSUED_BY_BASE_FLAG is set in dwFindFlags, then, only
  8274. // returns a base CRL.
  8275. //--------------------------------------------------------------------------
  8276. #define CRL_FIND_ISSUED_BY_AKI_FLAG 0x1
  8277. #define CRL_FIND_ISSUED_BY_SIGNATURE_FLAG 0x2
  8278. #define CRL_FIND_ISSUED_BY_DELTA_FLAG 0x4
  8279. #define CRL_FIND_ISSUED_BY_BASE_FLAG 0x8
  8280. //+-------------------------------------------------------------------------
  8281. // CRL_FIND_EXISTING
  8282. //
  8283. // Find existing CRL in the store.
  8284. //
  8285. // pvFindPara is the PCCRL_CONTEXT of the CRL to check if it already
  8286. // exists in the store.
  8287. //--------------------------------------------------------------------------
  8288. //+-------------------------------------------------------------------------
  8289. // CRL_FIND_ISSUED_FOR
  8290. //
  8291. // Find CRL for the specified subject and its issuer.
  8292. //
  8293. // pvFindPara points to the following CRL_FIND_ISSUED_FOR_PARA which contains
  8294. // both the subject and issuer certificates. Not optional.
  8295. //
  8296. // The subject's issuer name is used to match the CRL's issuer name. Otherwise,
  8297. // the issuer's certificate is used the same as in the above
  8298. // CRL_FIND_ISSUED_BY.
  8299. //
  8300. // Note, when cross certificates are used, the subject name in the issuer's
  8301. // certificate may not match the issuer name in the subject certificate and
  8302. // its corresponding CRL.
  8303. //
  8304. // All of the above CRL_FIND_ISSUED_BY_*_FLAGS apply to this find type.
  8305. //--------------------------------------------------------------------------
  8306. typedef struct _CRL_FIND_ISSUED_FOR_PARA {
  8307. PCCERT_CONTEXT pSubjectCert;
  8308. PCCERT_CONTEXT pIssuerCert;
  8309. } CRL_FIND_ISSUED_FOR_PARA, *PCRL_FIND_ISSUED_FOR_PARA;
  8310. //+-------------------------------------------------------------------------
  8311. // Duplicate a CRL context
  8312. //--------------------------------------------------------------------------
  8313. WINCRYPT32API
  8314. PCCRL_CONTEXT
  8315. WINAPI
  8316. CertDuplicateCRLContext(
  8317. IN PCCRL_CONTEXT pCrlContext
  8318. );
  8319. //+-------------------------------------------------------------------------
  8320. // Create a CRL context from the encoded CRL. The created
  8321. // context isn't put in a store.
  8322. //
  8323. // Makes a copy of the encoded CRL in the created context.
  8324. //
  8325. // If unable to decode and create the CRL context, NULL is returned.
  8326. // Otherwise, a pointer to a read only CRL_CONTEXT is returned.
  8327. // CRL_CONTEXT must be freed by calling CertFreeCRLContext.
  8328. // CertDuplicateCRLContext can be called to make a duplicate.
  8329. //
  8330. // CertSetCRLContextProperty and CertGetCRLContextProperty can be called
  8331. // to store properties for the CRL.
  8332. //--------------------------------------------------------------------------
  8333. WINCRYPT32API
  8334. PCCRL_CONTEXT
  8335. WINAPI
  8336. CertCreateCRLContext(
  8337. IN DWORD dwCertEncodingType,
  8338. IN const BYTE *pbCrlEncoded,
  8339. IN DWORD cbCrlEncoded
  8340. );
  8341. //+-------------------------------------------------------------------------
  8342. // Free a CRL context
  8343. //
  8344. // There needs to be a corresponding free for each context obtained by a
  8345. // get, duplicate or create.
  8346. //--------------------------------------------------------------------------
  8347. WINCRYPT32API
  8348. BOOL
  8349. WINAPI
  8350. CertFreeCRLContext(
  8351. IN PCCRL_CONTEXT pCrlContext
  8352. );
  8353. //+-------------------------------------------------------------------------
  8354. // Set the property for the specified CRL context.
  8355. //
  8356. // Same Property Ids and semantics as CertSetCertificateContextProperty.
  8357. //--------------------------------------------------------------------------
  8358. WINCRYPT32API
  8359. BOOL
  8360. WINAPI
  8361. CertSetCRLContextProperty(
  8362. IN PCCRL_CONTEXT pCrlContext,
  8363. IN DWORD dwPropId,
  8364. IN DWORD dwFlags,
  8365. IN const void *pvData
  8366. );
  8367. //+-------------------------------------------------------------------------
  8368. // Get the property for the specified CRL context.
  8369. //
  8370. // Same Property Ids and semantics as CertGetCertificateContextProperty.
  8371. //
  8372. // CERT_SHA1_HASH_PROP_ID, CERT_MD5_HASH_PROP_ID or
  8373. // CERT_SIGNATURE_HASH_PROP_ID is the predefined property of most interest.
  8374. //--------------------------------------------------------------------------
  8375. WINCRYPT32API
  8376. BOOL
  8377. WINAPI
  8378. CertGetCRLContextProperty(
  8379. IN PCCRL_CONTEXT pCrlContext,
  8380. IN DWORD dwPropId,
  8381. OUT void *pvData,
  8382. IN OUT DWORD *pcbData
  8383. );
  8384. //+-------------------------------------------------------------------------
  8385. // Enumerate the properties for the specified CRL context.
  8386. //
  8387. // To get the first property, set dwPropId to 0. The ID of the first
  8388. // property is returned. To get the next property, set dwPropId to the
  8389. // ID returned by the last call. To enumerate all the properties continue
  8390. // until 0 is returned.
  8391. //
  8392. // CertGetCRLContextProperty is called to get the property's data.
  8393. //--------------------------------------------------------------------------
  8394. WINCRYPT32API
  8395. DWORD
  8396. WINAPI
  8397. CertEnumCRLContextProperties(
  8398. IN PCCRL_CONTEXT pCrlContext,
  8399. IN DWORD dwPropId
  8400. );
  8401. //+-------------------------------------------------------------------------
  8402. // Search the CRL's list of entries for the specified certificate.
  8403. //
  8404. // TRUE is returned if we were able to search the list. Otherwise, FALSE is
  8405. // returned,
  8406. //
  8407. // For success, if the certificate was found in the list, *ppCrlEntry is
  8408. // updated with a pointer to the entry. Otherwise, *ppCrlEntry is set to NULL.
  8409. // The returned entry isn't allocated and must not be freed.
  8410. //
  8411. // dwFlags and pvReserved currently aren't used and must be set to 0 or NULL.
  8412. //--------------------------------------------------------------------------
  8413. WINCRYPT32API
  8414. BOOL
  8415. WINAPI
  8416. CertFindCertificateInCRL(
  8417. IN PCCERT_CONTEXT pCert,
  8418. IN PCCRL_CONTEXT pCrlContext,
  8419. IN DWORD dwFlags,
  8420. IN OPTIONAL void *pvReserved,
  8421. OUT PCRL_ENTRY *ppCrlEntry
  8422. );
  8423. //+-------------------------------------------------------------------------
  8424. // Is the specified CRL valid for the certificate.
  8425. //
  8426. // Returns TRUE if the CRL's list of entries would contain the certificate
  8427. // if it was revoked. Note, doesn't check that the certificate is in the
  8428. // list of entries.
  8429. //
  8430. // If the CRL has an Issuing Distribution Point (IDP) extension, checks
  8431. // that it's valid for the subject certificate.
  8432. //
  8433. // dwFlags and pvReserved currently aren't used and must be set to 0 and NULL.
  8434. //--------------------------------------------------------------------------
  8435. WINCRYPT32API
  8436. BOOL
  8437. WINAPI
  8438. CertIsValidCRLForCertificate(
  8439. IN PCCERT_CONTEXT pCert,
  8440. IN PCCRL_CONTEXT pCrl,
  8441. IN DWORD dwFlags,
  8442. IN void *pvReserved
  8443. );
  8444. //+-------------------------------------------------------------------------
  8445. // Add certificate/CRL, encoded, context or element disposition values.
  8446. //--------------------------------------------------------------------------
  8447. #define CERT_STORE_ADD_NEW 1
  8448. #define CERT_STORE_ADD_USE_EXISTING 2
  8449. #define CERT_STORE_ADD_REPLACE_EXISTING 3
  8450. #define CERT_STORE_ADD_ALWAYS 4
  8451. #define CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES 5
  8452. #define CERT_STORE_ADD_NEWER 6
  8453. #define CERT_STORE_ADD_NEWER_INHERIT_PROPERTIES 7
  8454. //+-------------------------------------------------------------------------
  8455. // Add the encoded certificate to the store according to the specified
  8456. // disposition action.
  8457. //
  8458. // Makes a copy of the encoded certificate before adding to the store.
  8459. //
  8460. // dwAddDispostion specifies the action to take if the certificate
  8461. // already exists in the store. This parameter must be one of the following
  8462. // values:
  8463. // CERT_STORE_ADD_NEW
  8464. // Fails if the certificate already exists in the store. LastError
  8465. // is set to CRYPT_E_EXISTS.
  8466. // CERT_STORE_ADD_USE_EXISTING
  8467. // If the certifcate already exists, then, its used and if ppCertContext
  8468. // is non-NULL, the existing context is duplicated.
  8469. // CERT_STORE_ADD_REPLACE_EXISTING
  8470. // If the certificate already exists, then, the existing certificate
  8471. // context is deleted before creating and adding the new context.
  8472. // CERT_STORE_ADD_ALWAYS
  8473. // No check is made to see if the certificate already exists. A
  8474. // new certificate context is always created. This may lead to
  8475. // duplicates in the store.
  8476. // CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES
  8477. // If the certificate already exists, then, its used.
  8478. // CERT_STORE_ADD_NEWER
  8479. // Fails if the certificate already exists in the store AND the NotBefore
  8480. // time of the existing certificate is equal to or greater than the
  8481. // NotBefore time of the new certificate being added. LastError
  8482. // is set to CRYPT_E_EXISTS.
  8483. //
  8484. // If an older certificate is replaced, same as
  8485. // CERT_STORE_ADD_REPLACE_EXISTING.
  8486. //
  8487. // For CRLs or CTLs compares the ThisUpdate times.
  8488. //
  8489. // CERT_STORE_ADD_NEWER_INHERIT_PROPERTIES
  8490. // Same as CERT_STORE_ADD_NEWER. However, if an older certificate is
  8491. // replaced, same as CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES.
  8492. //
  8493. // CertGetSubjectCertificateFromStore is called to determine if the
  8494. // certificate already exists in the store.
  8495. //
  8496. // ppCertContext can be NULL, indicating the caller isn't interested
  8497. // in getting the CERT_CONTEXT of the added or existing certificate.
  8498. //--------------------------------------------------------------------------
  8499. WINCRYPT32API
  8500. BOOL
  8501. WINAPI
  8502. CertAddEncodedCertificateToStore(
  8503. IN HCERTSTORE hCertStore,
  8504. IN DWORD dwCertEncodingType,
  8505. IN const BYTE *pbCertEncoded,
  8506. IN DWORD cbCertEncoded,
  8507. IN DWORD dwAddDisposition,
  8508. OUT OPTIONAL PCCERT_CONTEXT *ppCertContext
  8509. );
  8510. //+-------------------------------------------------------------------------
  8511. // Add the certificate context to the store according to the specified
  8512. // disposition action.
  8513. //
  8514. // In addition to the encoded certificate, the context's properties are
  8515. // also copied. Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  8516. // CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't copied.
  8517. //
  8518. // Makes a copy of the certificate context before adding to the store.
  8519. //
  8520. // dwAddDispostion specifies the action to take if the certificate
  8521. // already exists in the store. This parameter must be one of the following
  8522. // values:
  8523. // CERT_STORE_ADD_NEW
  8524. // Fails if the certificate already exists in the store. LastError
  8525. // is set to CRYPT_E_EXISTS.
  8526. // CERT_STORE_ADD_USE_EXISTING
  8527. // If the certifcate already exists, then, its used and if ppStoreContext
  8528. // is non-NULL, the existing context is duplicated. Iterates
  8529. // through pCertContext's properties and only copies the properties
  8530. // that don't already exist. The SHA1 and MD5 hash properties aren't
  8531. // copied.
  8532. // CERT_STORE_ADD_REPLACE_EXISTING
  8533. // If the certificate already exists, then, the existing certificate
  8534. // context is deleted before creating and adding a new context.
  8535. // Properties are copied before doing the add.
  8536. // CERT_STORE_ADD_ALWAYS
  8537. // No check is made to see if the certificate already exists. A
  8538. // new certificate context is always created and added. This may lead to
  8539. // duplicates in the store. Properties are
  8540. // copied before doing the add.
  8541. // CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES
  8542. // If the certificate already exists, then, the existing certificate
  8543. // context is used. Properties from the added context are copied and
  8544. // replace existing properties. However, any existing properties not
  8545. // in the added context remain and aren't deleted.
  8546. // CERT_STORE_ADD_NEWER
  8547. // Fails if the certificate already exists in the store AND the NotBefore
  8548. // time of the existing context is equal to or greater than the
  8549. // NotBefore time of the new context being added. LastError
  8550. // is set to CRYPT_E_EXISTS.
  8551. //
  8552. // If an older context is replaced, same as
  8553. // CERT_STORE_ADD_REPLACE_EXISTING.
  8554. //
  8555. // For CRLs or CTLs compares the ThisUpdate times.
  8556. //
  8557. // CERT_STORE_ADD_NEWER_INHERIT_PROPERTIES
  8558. // Same as CERT_STORE_ADD_NEWER. However, if an older context is
  8559. // replaced, same as CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES.
  8560. //
  8561. // CertGetSubjectCertificateFromStore is called to determine if the
  8562. // certificate already exists in the store.
  8563. //
  8564. // ppStoreContext can be NULL, indicating the caller isn't interested
  8565. // in getting the CERT_CONTEXT of the added or existing certificate.
  8566. //--------------------------------------------------------------------------
  8567. WINCRYPT32API
  8568. BOOL
  8569. WINAPI
  8570. CertAddCertificateContextToStore(
  8571. IN HCERTSTORE hCertStore,
  8572. IN PCCERT_CONTEXT pCertContext,
  8573. IN DWORD dwAddDisposition,
  8574. OUT OPTIONAL PCCERT_CONTEXT *ppStoreContext
  8575. );
  8576. //+-------------------------------------------------------------------------
  8577. // Certificate Store Context Types
  8578. //--------------------------------------------------------------------------
  8579. #define CERT_STORE_CERTIFICATE_CONTEXT 1
  8580. #define CERT_STORE_CRL_CONTEXT 2
  8581. #define CERT_STORE_CTL_CONTEXT 3
  8582. //+-------------------------------------------------------------------------
  8583. // Certificate Store Context Bit Flags
  8584. //--------------------------------------------------------------------------
  8585. #define CERT_STORE_ALL_CONTEXT_FLAG (~0UL)
  8586. #define CERT_STORE_CERTIFICATE_CONTEXT_FLAG \
  8587. (1 << CERT_STORE_CERTIFICATE_CONTEXT)
  8588. #define CERT_STORE_CRL_CONTEXT_FLAG \
  8589. (1 << CERT_STORE_CRL_CONTEXT)
  8590. #define CERT_STORE_CTL_CONTEXT_FLAG \
  8591. (1 << CERT_STORE_CTL_CONTEXT)
  8592. //+-------------------------------------------------------------------------
  8593. // Add the serialized certificate or CRL element to the store.
  8594. //
  8595. // The serialized element contains the encoded certificate, CRL or CTL and
  8596. // its properties, such as, CERT_KEY_PROV_INFO_PROP_ID.
  8597. //
  8598. // If hCertStore is NULL, creates a certificate, CRL or CTL context not
  8599. // residing in any store.
  8600. //
  8601. // dwAddDispostion specifies the action to take if the certificate or CRL
  8602. // already exists in the store. See CertAddCertificateContextToStore for a
  8603. // list of and actions taken.
  8604. //
  8605. // dwFlags currently isn't used and should be set to 0.
  8606. //
  8607. // dwContextTypeFlags specifies the set of allowable contexts. For example, to
  8608. // add either a certificate or CRL, set dwContextTypeFlags to:
  8609. // CERT_STORE_CERTIFICATE_CONTEXT_FLAG | CERT_STORE_CRL_CONTEXT_FLAG
  8610. //
  8611. // *pdwContextType is updated with the type of the context returned in
  8612. // *ppvContxt. pdwContextType or ppvContext can be NULL, indicating the
  8613. // caller isn't interested in getting the output. If *ppvContext is
  8614. // returned it must be freed by calling CertFreeCertificateContext or
  8615. // CertFreeCRLContext.
  8616. //--------------------------------------------------------------------------
  8617. WINCRYPT32API
  8618. BOOL
  8619. WINAPI
  8620. CertAddSerializedElementToStore(
  8621. IN HCERTSTORE hCertStore,
  8622. IN const BYTE *pbElement,
  8623. IN DWORD cbElement,
  8624. IN DWORD dwAddDisposition,
  8625. IN DWORD dwFlags,
  8626. IN DWORD dwContextTypeFlags,
  8627. OUT OPTIONAL DWORD *pdwContextType,
  8628. OUT OPTIONAL const void **ppvContext
  8629. );
  8630. //+-------------------------------------------------------------------------
  8631. // Delete the specified certificate from the store.
  8632. //
  8633. // All subsequent gets or finds for the certificate will fail. However,
  8634. // memory allocated for the certificate isn't freed until all of its contexts
  8635. // have also been freed.
  8636. //
  8637. // The pCertContext is obtained from a get, enum, find or duplicate.
  8638. //
  8639. // Some store provider implementations might also delete the issuer's CRLs
  8640. // if this is the last certificate for the issuer in the store.
  8641. //
  8642. // NOTE: the pCertContext is always CertFreeCertificateContext'ed by
  8643. // this function, even for an error.
  8644. //--------------------------------------------------------------------------
  8645. WINCRYPT32API
  8646. BOOL
  8647. WINAPI
  8648. CertDeleteCertificateFromStore(
  8649. IN PCCERT_CONTEXT pCertContext
  8650. );
  8651. //+-------------------------------------------------------------------------
  8652. // Add the encoded CRL to the store according to the specified
  8653. // disposition option.
  8654. //
  8655. // Makes a copy of the encoded CRL before adding to the store.
  8656. //
  8657. // dwAddDispostion specifies the action to take if the CRL
  8658. // already exists in the store. See CertAddEncodedCertificateToStore for a
  8659. // list of and actions taken.
  8660. //
  8661. // Compares the CRL's Issuer to determine if the CRL already exists in the
  8662. // store.
  8663. //
  8664. // ppCrlContext can be NULL, indicating the caller isn't interested
  8665. // in getting the CRL_CONTEXT of the added or existing CRL.
  8666. //--------------------------------------------------------------------------
  8667. WINCRYPT32API
  8668. BOOL
  8669. WINAPI
  8670. CertAddEncodedCRLToStore(
  8671. IN HCERTSTORE hCertStore,
  8672. IN DWORD dwCertEncodingType,
  8673. IN const BYTE *pbCrlEncoded,
  8674. IN DWORD cbCrlEncoded,
  8675. IN DWORD dwAddDisposition,
  8676. OUT OPTIONAL PCCRL_CONTEXT *ppCrlContext
  8677. );
  8678. //+-------------------------------------------------------------------------
  8679. // Add the CRL context to the store according to the specified
  8680. // disposition option.
  8681. //
  8682. // In addition to the encoded CRL, the context's properties are
  8683. // also copied. Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  8684. // CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't copied.
  8685. //
  8686. // Makes a copy of the encoded CRL before adding to the store.
  8687. //
  8688. // dwAddDispostion specifies the action to take if the CRL
  8689. // already exists in the store. See CertAddCertificateContextToStore for a
  8690. // list of and actions taken.
  8691. //
  8692. // Compares the CRL's Issuer, ThisUpdate and NextUpdate to determine
  8693. // if the CRL already exists in the store.
  8694. //
  8695. // ppStoreContext can be NULL, indicating the caller isn't interested
  8696. // in getting the CRL_CONTEXT of the added or existing CRL.
  8697. //--------------------------------------------------------------------------
  8698. WINCRYPT32API
  8699. BOOL
  8700. WINAPI
  8701. CertAddCRLContextToStore(
  8702. IN HCERTSTORE hCertStore,
  8703. IN PCCRL_CONTEXT pCrlContext,
  8704. IN DWORD dwAddDisposition,
  8705. OUT OPTIONAL PCCRL_CONTEXT *ppStoreContext
  8706. );
  8707. //+-------------------------------------------------------------------------
  8708. // Delete the specified CRL from the store.
  8709. //
  8710. // All subsequent gets for the CRL will fail. However,
  8711. // memory allocated for the CRL isn't freed until all of its contexts
  8712. // have also been freed.
  8713. //
  8714. // The pCrlContext is obtained from a get or duplicate.
  8715. //
  8716. // NOTE: the pCrlContext is always CertFreeCRLContext'ed by
  8717. // this function, even for an error.
  8718. //--------------------------------------------------------------------------
  8719. WINCRYPT32API
  8720. BOOL
  8721. WINAPI
  8722. CertDeleteCRLFromStore(
  8723. IN PCCRL_CONTEXT pCrlContext
  8724. );
  8725. //+-------------------------------------------------------------------------
  8726. // Serialize the certificate context's encoded certificate and its
  8727. // properties.
  8728. //--------------------------------------------------------------------------
  8729. WINCRYPT32API
  8730. BOOL
  8731. WINAPI
  8732. CertSerializeCertificateStoreElement(
  8733. IN PCCERT_CONTEXT pCertContext,
  8734. IN DWORD dwFlags,
  8735. OUT BYTE *pbElement,
  8736. IN OUT DWORD *pcbElement
  8737. );
  8738. //+-------------------------------------------------------------------------
  8739. // Serialize the CRL context's encoded CRL and its properties.
  8740. //--------------------------------------------------------------------------
  8741. WINCRYPT32API
  8742. BOOL
  8743. WINAPI
  8744. CertSerializeCRLStoreElement(
  8745. IN PCCRL_CONTEXT pCrlContext,
  8746. IN DWORD dwFlags,
  8747. OUT BYTE *pbElement,
  8748. IN OUT DWORD *pcbElement
  8749. );
  8750. //+=========================================================================
  8751. // Certificate Trust List (CTL) Store Data Structures and APIs
  8752. //==========================================================================
  8753. //+-------------------------------------------------------------------------
  8754. // Duplicate a CTL context
  8755. //--------------------------------------------------------------------------
  8756. WINCRYPT32API
  8757. PCCTL_CONTEXT
  8758. WINAPI
  8759. CertDuplicateCTLContext(
  8760. IN PCCTL_CONTEXT pCtlContext
  8761. );
  8762. //+-------------------------------------------------------------------------
  8763. // Create a CTL context from the encoded CTL. The created
  8764. // context isn't put in a store.
  8765. //
  8766. // Makes a copy of the encoded CTL in the created context.
  8767. //
  8768. // If unable to decode and create the CTL context, NULL is returned.
  8769. // Otherwise, a pointer to a read only CTL_CONTEXT is returned.
  8770. // CTL_CONTEXT must be freed by calling CertFreeCTLContext.
  8771. // CertDuplicateCTLContext can be called to make a duplicate.
  8772. //
  8773. // CertSetCTLContextProperty and CertGetCTLContextProperty can be called
  8774. // to store properties for the CTL.
  8775. //--------------------------------------------------------------------------
  8776. WINCRYPT32API
  8777. PCCTL_CONTEXT
  8778. WINAPI
  8779. CertCreateCTLContext(
  8780. IN DWORD dwMsgAndCertEncodingType,
  8781. IN const BYTE *pbCtlEncoded,
  8782. IN DWORD cbCtlEncoded
  8783. );
  8784. //+-------------------------------------------------------------------------
  8785. // Free a CTL context
  8786. //
  8787. // There needs to be a corresponding free for each context obtained by a
  8788. // get, duplicate or create.
  8789. //--------------------------------------------------------------------------
  8790. WINCRYPT32API
  8791. BOOL
  8792. WINAPI
  8793. CertFreeCTLContext(
  8794. IN PCCTL_CONTEXT pCtlContext
  8795. );
  8796. //+-------------------------------------------------------------------------
  8797. // Set the property for the specified CTL context.
  8798. //
  8799. // Same Property Ids and semantics as CertSetCertificateContextProperty.
  8800. //--------------------------------------------------------------------------
  8801. WINCRYPT32API
  8802. BOOL
  8803. WINAPI
  8804. CertSetCTLContextProperty(
  8805. IN PCCTL_CONTEXT pCtlContext,
  8806. IN DWORD dwPropId,
  8807. IN DWORD dwFlags,
  8808. IN const void *pvData
  8809. );
  8810. //+-------------------------------------------------------------------------
  8811. // Get the property for the specified CTL context.
  8812. //
  8813. // Same Property Ids and semantics as CertGetCertificateContextProperty.
  8814. //
  8815. // CERT_SHA1_HASH_PROP_ID or CERT_NEXT_UPDATE_LOCATION_PROP_ID are the
  8816. // predefined properties of most interest.
  8817. //--------------------------------------------------------------------------
  8818. WINCRYPT32API
  8819. BOOL
  8820. WINAPI
  8821. CertGetCTLContextProperty(
  8822. IN PCCTL_CONTEXT pCtlContext,
  8823. IN DWORD dwPropId,
  8824. OUT void *pvData,
  8825. IN OUT DWORD *pcbData
  8826. );
  8827. //+-------------------------------------------------------------------------
  8828. // Enumerate the properties for the specified CTL context.
  8829. //--------------------------------------------------------------------------
  8830. WINCRYPT32API
  8831. DWORD
  8832. WINAPI
  8833. CertEnumCTLContextProperties(
  8834. IN PCCTL_CONTEXT pCtlContext,
  8835. IN DWORD dwPropId
  8836. );
  8837. //+-------------------------------------------------------------------------
  8838. // Enumerate the CTL contexts in the store.
  8839. //
  8840. // If a CTL isn't found, NULL is returned.
  8841. // Otherwise, a pointer to a read only CTL_CONTEXT is returned. CTL_CONTEXT
  8842. // must be freed by calling CertFreeCTLContext or is freed when passed as the
  8843. // pPrevCtlContext on a subsequent call. CertDuplicateCTLContext
  8844. // can be called to make a duplicate.
  8845. //
  8846. // pPrevCtlContext MUST BE NULL to enumerate the first
  8847. // CTL in the store. Successive CTLs are enumerated by setting
  8848. // pPrevCtlContext to the CTL_CONTEXT returned by a previous call.
  8849. //
  8850. // NOTE: a NON-NULL pPrevCtlContext is always CertFreeCTLContext'ed by
  8851. // this function, even for an error.
  8852. //--------------------------------------------------------------------------
  8853. WINCRYPT32API
  8854. PCCTL_CONTEXT
  8855. WINAPI
  8856. CertEnumCTLsInStore(
  8857. IN HCERTSTORE hCertStore,
  8858. IN PCCTL_CONTEXT pPrevCtlContext
  8859. );
  8860. //+-------------------------------------------------------------------------
  8861. // Attempt to find the specified subject in the CTL.
  8862. //
  8863. // For CTL_CERT_SUBJECT_TYPE, pvSubject points to a CERT_CONTEXT. The CTL's
  8864. // SubjectAlgorithm is examined to determine the representation of the
  8865. // subject's identity. Initially, only SHA1 or MD5 hash will be supported.
  8866. // The appropriate hash property is obtained from the CERT_CONTEXT.
  8867. //
  8868. // For CTL_ANY_SUBJECT_TYPE, pvSubject points to the CTL_ANY_SUBJECT_INFO
  8869. // structure which contains the SubjectAlgorithm to be matched in the CTL
  8870. // and the SubjectIdentifer to be matched in one of the CTL entries.
  8871. //
  8872. // The certificate's hash or the CTL_ANY_SUBJECT_INFO's SubjectIdentifier
  8873. // is used as the key in searching the subject entries. A binary
  8874. // memory comparison is done between the key and the entry's SubjectIdentifer.
  8875. //
  8876. // dwEncodingType isn't used for either of the above SubjectTypes.
  8877. //--------------------------------------------------------------------------
  8878. WINCRYPT32API
  8879. PCTL_ENTRY
  8880. WINAPI
  8881. CertFindSubjectInCTL(
  8882. IN DWORD dwEncodingType,
  8883. IN DWORD dwSubjectType,
  8884. IN void *pvSubject,
  8885. IN PCCTL_CONTEXT pCtlContext,
  8886. IN DWORD dwFlags
  8887. );
  8888. // Subject Types:
  8889. // CTL_ANY_SUBJECT_TYPE, pvSubject points to following CTL_ANY_SUBJECT_INFO.
  8890. // CTL_CERT_SUBJECT_TYPE, pvSubject points to CERT_CONTEXT.
  8891. #define CTL_ANY_SUBJECT_TYPE 1
  8892. #define CTL_CERT_SUBJECT_TYPE 2
  8893. typedef struct _CTL_ANY_SUBJECT_INFO {
  8894. CRYPT_ALGORITHM_IDENTIFIER SubjectAlgorithm;
  8895. CRYPT_DATA_BLOB SubjectIdentifier;
  8896. } CTL_ANY_SUBJECT_INFO, *PCTL_ANY_SUBJECT_INFO;
  8897. //+-------------------------------------------------------------------------
  8898. // Find the first or next CTL context in the store.
  8899. //
  8900. // The CTL is found according to the dwFindType and its pvFindPara.
  8901. // See below for a list of the find types and its parameters.
  8902. //
  8903. // Currently dwFindFlags isn't used and must be set to 0.
  8904. //
  8905. // Usage of dwMsgAndCertEncodingType depends on the dwFindType.
  8906. //
  8907. // If the first or next CTL isn't found, NULL is returned.
  8908. // Otherwise, a pointer to a read only CTL_CONTEXT is returned. CTL_CONTEXT
  8909. // must be freed by calling CertFreeCTLContext or is freed when passed as the
  8910. // pPrevCtlContext on a subsequent call. CertDuplicateCTLContext
  8911. // can be called to make a duplicate.
  8912. //
  8913. // pPrevCtlContext MUST BE NULL on the first
  8914. // call to find the CTL. To find the next CTL, the
  8915. // pPrevCtlContext is set to the CTL_CONTEXT returned by a previous call.
  8916. //
  8917. // NOTE: a NON-NULL pPrevCtlContext is always CertFreeCTLContext'ed by
  8918. // this function, even for an error.
  8919. //--------------------------------------------------------------------------
  8920. WINCRYPT32API
  8921. PCCTL_CONTEXT
  8922. WINAPI
  8923. CertFindCTLInStore(
  8924. IN HCERTSTORE hCertStore,
  8925. IN DWORD dwMsgAndCertEncodingType,
  8926. IN DWORD dwFindFlags,
  8927. IN DWORD dwFindType,
  8928. IN const void *pvFindPara,
  8929. IN PCCTL_CONTEXT pPrevCtlContext
  8930. );
  8931. #define CTL_FIND_ANY 0
  8932. #define CTL_FIND_SHA1_HASH 1
  8933. #define CTL_FIND_MD5_HASH 2
  8934. #define CTL_FIND_USAGE 3
  8935. #define CTL_FIND_SUBJECT 4
  8936. #define CTL_FIND_EXISTING 5
  8937. typedef struct _CTL_FIND_USAGE_PARA {
  8938. DWORD cbSize;
  8939. CTL_USAGE SubjectUsage; // optional
  8940. CRYPT_DATA_BLOB ListIdentifier; // optional
  8941. PCERT_INFO pSigner; // optional
  8942. } CTL_FIND_USAGE_PARA, *PCTL_FIND_USAGE_PARA;
  8943. #define CTL_FIND_NO_LIST_ID_CBDATA 0xFFFFFFFF
  8944. #define CTL_FIND_NO_SIGNER_PTR ((PCERT_INFO) -1)
  8945. #define CTL_FIND_SAME_USAGE_FLAG 0x1
  8946. typedef struct _CTL_FIND_SUBJECT_PARA {
  8947. DWORD cbSize;
  8948. PCTL_FIND_USAGE_PARA pUsagePara; // optional
  8949. DWORD dwSubjectType;
  8950. void *pvSubject;
  8951. } CTL_FIND_SUBJECT_PARA, *PCTL_FIND_SUBJECT_PARA;
  8952. //+-------------------------------------------------------------------------
  8953. // CTL_FIND_ANY
  8954. //
  8955. // Find any CTL.
  8956. //
  8957. // pvFindPara isn't used.
  8958. //--------------------------------------------------------------------------
  8959. //+-------------------------------------------------------------------------
  8960. // CTL_FIND_SHA1_HASH
  8961. // CTL_FIND_MD5_HASH
  8962. //
  8963. // Find a CTL with the specified hash.
  8964. //
  8965. // pvFindPara points to a CRYPT_HASH_BLOB.
  8966. //--------------------------------------------------------------------------
  8967. //+-------------------------------------------------------------------------
  8968. // CTL_FIND_USAGE
  8969. //
  8970. // Find a CTL having the specified usage identifiers, list identifier or
  8971. // signer. The CertEncodingType of the signer is obtained from the
  8972. // dwMsgAndCertEncodingType parameter.
  8973. //
  8974. // pvFindPara points to a CTL_FIND_USAGE_PARA data structure. The
  8975. // SubjectUsage.cUsageIdentifer can be 0 to match any usage. The
  8976. // ListIdentifier.cbData can be 0 to match any list identifier. To only match
  8977. // CTLs without a ListIdentifier, cbData must be set to
  8978. // CTL_FIND_NO_LIST_ID_CBDATA. pSigner can be NULL to match any signer. Only
  8979. // the Issuer and SerialNumber fields of the pSigner's PCERT_INFO are used.
  8980. // To only match CTLs without a signer, pSigner must be set to
  8981. // CTL_FIND_NO_SIGNER_PTR.
  8982. //
  8983. // The CTL_FIND_SAME_USAGE_FLAG can be set in dwFindFlags to
  8984. // only match CTLs with the same usage identifiers. CTLs having additional
  8985. // usage identifiers aren't matched. For example, if only "1.2.3" is specified
  8986. // in CTL_FIND_USAGE_PARA, then, for a match, the CTL must only contain
  8987. // "1.2.3" and not any additional usage identifers.
  8988. //--------------------------------------------------------------------------
  8989. //+-------------------------------------------------------------------------
  8990. // CTL_FIND_SUBJECT
  8991. //
  8992. // Find a CTL having the specified subject. CertFindSubjectInCTL can be
  8993. // called to get a pointer to the subject's entry in the CTL. pUsagePara can
  8994. // optionally be set to enable the above CTL_FIND_USAGE matching.
  8995. //
  8996. // pvFindPara points to a CTL_FIND_SUBJECT_PARA data structure.
  8997. //--------------------------------------------------------------------------
  8998. //+-------------------------------------------------------------------------
  8999. // Add the encoded CTL to the store according to the specified
  9000. // disposition option.
  9001. //
  9002. // Makes a copy of the encoded CTL before adding to the store.
  9003. //
  9004. // dwAddDispostion specifies the action to take if the CTL
  9005. // already exists in the store. See CertAddEncodedCertificateToStore for a
  9006. // list of and actions taken.
  9007. //
  9008. // Compares the CTL's SubjectUsage, ListIdentifier and any of its signers
  9009. // to determine if the CTL already exists in the store.
  9010. //
  9011. // ppCtlContext can be NULL, indicating the caller isn't interested
  9012. // in getting the CTL_CONTEXT of the added or existing CTL.
  9013. //--------------------------------------------------------------------------
  9014. WINCRYPT32API
  9015. BOOL
  9016. WINAPI
  9017. CertAddEncodedCTLToStore(
  9018. IN HCERTSTORE hCertStore,
  9019. IN DWORD dwMsgAndCertEncodingType,
  9020. IN const BYTE *pbCtlEncoded,
  9021. IN DWORD cbCtlEncoded,
  9022. IN DWORD dwAddDisposition,
  9023. OUT OPTIONAL PCCTL_CONTEXT *ppCtlContext
  9024. );
  9025. //+-------------------------------------------------------------------------
  9026. // Add the CTL context to the store according to the specified
  9027. // disposition option.
  9028. //
  9029. // In addition to the encoded CTL, the context's properties are
  9030. // also copied. Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  9031. // CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't copied.
  9032. //
  9033. // Makes a copy of the encoded CTL before adding to the store.
  9034. //
  9035. // dwAddDispostion specifies the action to take if the CTL
  9036. // already exists in the store. See CertAddCertificateContextToStore for a
  9037. // list of and actions taken.
  9038. //
  9039. // Compares the CTL's SubjectUsage, ListIdentifier and any of its signers
  9040. // to determine if the CTL already exists in the store.
  9041. //
  9042. // ppStoreContext can be NULL, indicating the caller isn't interested
  9043. // in getting the CTL_CONTEXT of the added or existing CTL.
  9044. //--------------------------------------------------------------------------
  9045. WINCRYPT32API
  9046. BOOL
  9047. WINAPI
  9048. CertAddCTLContextToStore(
  9049. IN HCERTSTORE hCertStore,
  9050. IN PCCTL_CONTEXT pCtlContext,
  9051. IN DWORD dwAddDisposition,
  9052. OUT OPTIONAL PCCTL_CONTEXT *ppStoreContext
  9053. );
  9054. //+-------------------------------------------------------------------------
  9055. // Serialize the CTL context's encoded CTL and its properties.
  9056. //--------------------------------------------------------------------------
  9057. WINCRYPT32API
  9058. BOOL
  9059. WINAPI
  9060. CertSerializeCTLStoreElement(
  9061. IN PCCTL_CONTEXT pCtlContext,
  9062. IN DWORD dwFlags,
  9063. OUT BYTE *pbElement,
  9064. IN OUT DWORD *pcbElement
  9065. );
  9066. //+-------------------------------------------------------------------------
  9067. // Delete the specified CTL from the store.
  9068. //
  9069. // All subsequent gets for the CTL will fail. However,
  9070. // memory allocated for the CTL isn't freed until all of its contexts
  9071. // have also been freed.
  9072. //
  9073. // The pCtlContext is obtained from a get or duplicate.
  9074. //
  9075. // NOTE: the pCtlContext is always CertFreeCTLContext'ed by
  9076. // this function, even for an error.
  9077. //--------------------------------------------------------------------------
  9078. WINCRYPT32API
  9079. BOOL
  9080. WINAPI
  9081. CertDeleteCTLFromStore(
  9082. IN PCCTL_CONTEXT pCtlContext
  9083. );
  9084. WINCRYPT32API
  9085. BOOL
  9086. WINAPI
  9087. CertAddCertificateLinkToStore(
  9088. IN HCERTSTORE hCertStore,
  9089. IN PCCERT_CONTEXT pCertContext,
  9090. IN DWORD dwAddDisposition,
  9091. OUT OPTIONAL PCCERT_CONTEXT *ppStoreContext
  9092. );
  9093. WINCRYPT32API
  9094. BOOL
  9095. WINAPI
  9096. CertAddCRLLinkToStore(
  9097. IN HCERTSTORE hCertStore,
  9098. IN PCCRL_CONTEXT pCrlContext,
  9099. IN DWORD dwAddDisposition,
  9100. OUT OPTIONAL PCCRL_CONTEXT *ppStoreContext
  9101. );
  9102. WINCRYPT32API
  9103. BOOL
  9104. WINAPI
  9105. CertAddCTLLinkToStore(
  9106. IN HCERTSTORE hCertStore,
  9107. IN PCCTL_CONTEXT pCtlContext,
  9108. IN DWORD dwAddDisposition,
  9109. OUT OPTIONAL PCCTL_CONTEXT *ppStoreContext
  9110. );
  9111. WINCRYPT32API
  9112. BOOL
  9113. WINAPI
  9114. CertAddStoreToCollection(
  9115. IN HCERTSTORE hCollectionStore,
  9116. IN OPTIONAL HCERTSTORE hSiblingStore,
  9117. IN DWORD dwUpdateFlags,
  9118. IN DWORD dwPriority
  9119. );
  9120. WINCRYPT32API
  9121. void
  9122. WINAPI
  9123. CertRemoveStoreFromCollection(
  9124. IN HCERTSTORE hCollectionStore,
  9125. IN HCERTSTORE hSiblingStore
  9126. );
  9127. WINCRYPT32API
  9128. BOOL
  9129. WINAPI
  9130. CertControlStore(
  9131. IN HCERTSTORE hCertStore,
  9132. IN DWORD dwFlags,
  9133. IN DWORD dwCtrlType,
  9134. IN void const *pvCtrlPara
  9135. );
  9136. //+-------------------------------------------------------------------------
  9137. // Certificate Store control types
  9138. //--------------------------------------------------------------------------
  9139. #define CERT_STORE_CTRL_RESYNC 1
  9140. #define CERT_STORE_CTRL_NOTIFY_CHANGE 2
  9141. #define CERT_STORE_CTRL_COMMIT 3
  9142. #define CERT_STORE_CTRL_AUTO_RESYNC 4
  9143. #define CERT_STORE_CTRL_CANCEL_NOTIFY 5
  9144. #define CERT_STORE_CTRL_INHIBIT_DUPLICATE_HANDLE_FLAG 0x1
  9145. //+-------------------------------------------------------------------------
  9146. // CERT_STORE_CTRL_RESYNC
  9147. //
  9148. // Re-synchronize the store.
  9149. //
  9150. // The pvCtrlPara points to the event HANDLE to be signaled on
  9151. // the next store change. Normally, this would be the same
  9152. // event HANDLE passed to CERT_STORE_CTRL_NOTIFY_CHANGE during initialization.
  9153. //
  9154. // If pvCtrlPara is NULL, no events are re-armed.
  9155. //
  9156. // By default the event HANDLE is DuplicateHandle'd.
  9157. // CERT_STORE_CTRL_INHIBIT_DUPLICATE_HANDLE_FLAG can be set in dwFlags
  9158. // to inhibit a DupicateHandle of the event HANDLE. If this flag
  9159. // is set, then, CertControlStore(CERT_STORE_CTRL_CANCEL_NOTIFY) must be
  9160. // called for this event HANDLE before closing the hCertStore.
  9161. //--------------------------------------------------------------------------
  9162. //+-------------------------------------------------------------------------
  9163. // CERT_STORE_CTRL_NOTIFY_CHANGE
  9164. //
  9165. // Signal the event when the underlying store is changed.
  9166. //
  9167. // pvCtrlPara points to the event HANDLE to be signaled.
  9168. //
  9169. // pvCtrlPara can be NULL to inform the store of a subsequent
  9170. // CERT_STORE_CTRL_RESYNC and allow it to optimize by only doing a resync
  9171. // if the store has changed. For the registry based stores, an internal
  9172. // notify change event is created and registered to be signaled.
  9173. //
  9174. // Recommend calling CERT_STORE_CTRL_NOTIFY_CHANGE once for each event to
  9175. // be passed to CERT_STORE_CTRL_RESYNC. This should only happen after
  9176. // the event has been created. Not after each time the event is signaled.
  9177. //
  9178. // By default the event HANDLE is DuplicateHandle'd.
  9179. // CERT_STORE_CTRL_INHIBIT_DUPLICATE_HANDLE_FLAG can be set in dwFlags
  9180. // to inhibit a DupicateHandle of the event HANDLE. If this flag
  9181. // is set, then, CertControlStore(CERT_STORE_CTRL_CANCEL_NOTIFY) must be
  9182. // called for this event HANDLE before closing the hCertStore.
  9183. //--------------------------------------------------------------------------
  9184. //+-------------------------------------------------------------------------
  9185. // CERT_STORE_CTRL_CANCEL_NOTIFY
  9186. //
  9187. // Cancel notification signaling of the event HANDLE passed in a previous
  9188. // CERT_STORE_CTRL_NOTIFY_CHANGE or CERT_STORE_CTRL_RESYNC.
  9189. //
  9190. // pvCtrlPara points to the event HANDLE to be canceled.
  9191. //--------------------------------------------------------------------------
  9192. //+-------------------------------------------------------------------------
  9193. // CERT_STORE_CTRL_AUTO_RESYNC
  9194. //
  9195. // At the start of every enumeration or find store API call, check if the
  9196. // underlying store has changed. If it has changed, re-synchronize.
  9197. //
  9198. // This check is only done in the enumeration or find APIs when the
  9199. // pPrevContext is NULL.
  9200. //
  9201. // The pvCtrlPara isn't used and must be set to NULL.
  9202. //--------------------------------------------------------------------------
  9203. //+-------------------------------------------------------------------------
  9204. // CERT_STORE_CTRL_COMMIT
  9205. //
  9206. // If any changes have been to the cached store, they are committed to
  9207. // persisted storage. If no changes have been made since the store was
  9208. // opened or the last commit, this call is ignored. May also be ignored by
  9209. // store providers that persist changes immediately.
  9210. //
  9211. // CERT_STORE_CTRL_COMMIT_FORCE_FLAG can be set to force the store
  9212. // to be committed even if it hasn't been touched.
  9213. //
  9214. // CERT_STORE_CTRL_COMMIT_CLEAR_FLAG can be set to inhibit a commit on
  9215. // store close.
  9216. //--------------------------------------------------------------------------
  9217. #define CERT_STORE_CTRL_COMMIT_FORCE_FLAG 0x1
  9218. #define CERT_STORE_CTRL_COMMIT_CLEAR_FLAG 0x2
  9219. //+=========================================================================
  9220. // Cert Store Property Defines and APIs
  9221. //==========================================================================
  9222. //+-------------------------------------------------------------------------
  9223. // Store property IDs. This is a property applicable to the entire store.
  9224. // Its not a property on an individual certificate, CRL or CTL context.
  9225. //
  9226. // Currently, no store properties are persisted. (This differs from
  9227. // most context properties which are persisted.)
  9228. //
  9229. // See CertSetStoreProperty or CertGetStoreProperty for usage information.
  9230. //
  9231. // Note, the range for predefined store properties should be outside
  9232. // the range of predefined context properties. We will start at 4096.
  9233. //--------------------------------------------------------------------------
  9234. #define CERT_STORE_LOCALIZED_NAME_PROP_ID 0x1000
  9235. //+-------------------------------------------------------------------------
  9236. // Set a store property.
  9237. //
  9238. // The type definition for pvData depends on the dwPropId value.
  9239. // CERT_STORE_LOCALIZED_NAME_PROP_ID - localized name of the store.
  9240. // pvData points to a CRYPT_DATA_BLOB. pbData is a pointer to a NULL
  9241. // terminated unicode, wide character string.
  9242. // cbData = (wcslen((LPWSTR) pbData) + 1) * sizeof(WCHAR).
  9243. //
  9244. // For all the other PROP_IDs: an encoded PCRYPT_DATA_BLOB is passed in pvData.
  9245. //
  9246. // If the property already exists, then, the old value is deleted and silently
  9247. // replaced. Setting, pvData to NULL, deletes the property.
  9248. //--------------------------------------------------------------------------
  9249. WINCRYPT32API
  9250. BOOL
  9251. WINAPI
  9252. CertSetStoreProperty(
  9253. IN HCERTSTORE hCertStore,
  9254. IN DWORD dwPropId,
  9255. IN DWORD dwFlags,
  9256. IN const void *pvData
  9257. );
  9258. //+-------------------------------------------------------------------------
  9259. // Get a store property.
  9260. //
  9261. // The type definition for pvData depends on the dwPropId value.
  9262. // CERT_STORE_LOCALIZED_NAME_PROP_ID - localized name of the store.
  9263. // pvData points to a NULL terminated unicode, wide character string.
  9264. // cbData = (wcslen((LPWSTR) pvData) + 1) * sizeof(WCHAR).
  9265. //
  9266. // For all other PROP_IDs, pvData points to an array of bytes.
  9267. //
  9268. // If the property doesn't exist, returns FALSE and sets LastError to
  9269. // CRYPT_E_NOT_FOUND.
  9270. //--------------------------------------------------------------------------
  9271. WINCRYPT32API
  9272. BOOL
  9273. WINAPI
  9274. CertGetStoreProperty(
  9275. IN HCERTSTORE hCertStore,
  9276. IN DWORD dwPropId,
  9277. OUT void *pvData,
  9278. IN OUT DWORD *pcbData
  9279. );
  9280. typedef struct _CERT_CREATE_CONTEXT_PARA {
  9281. DWORD cbSize;
  9282. PFN_CRYPT_FREE pfnFree; // OPTIONAL
  9283. void *pvFree; // OPTIONAL
  9284. } CERT_CREATE_CONTEXT_PARA, *PCERT_CREATE_CONTEXT_PARA;
  9285. //+-------------------------------------------------------------------------
  9286. // Creates the specified context from the encoded bytes. The created
  9287. // context isn't put in a store.
  9288. //
  9289. // dwContextType values:
  9290. // CERT_STORE_CERTIFICATE_CONTEXT
  9291. // CERT_STORE_CRL_CONTEXT
  9292. // CERT_STORE_CTL_CONTEXT
  9293. //
  9294. // If CERT_CREATE_CONTEXT_NOCOPY_FLAG is set, the created context points
  9295. // directly to the pbEncoded instead of an allocated copy. See flag
  9296. // definition for more details.
  9297. //
  9298. // If CERT_CREATE_CONTEXT_SORTED_FLAG is set, the context is created
  9299. // with sorted entries. This flag may only be set for CERT_STORE_CTL_CONTEXT.
  9300. // Setting this flag implicitly sets CERT_CREATE_CONTEXT_NO_HCRYPTMSG_FLAG and
  9301. // CERT_CREATE_CONTEXT_NO_ENTRY_FLAG. See flag definition for
  9302. // more details.
  9303. //
  9304. // If CERT_CREATE_CONTEXT_NO_HCRYPTMSG_FLAG is set, the context is created
  9305. // without creating a HCRYPTMSG handle for the context. This flag may only be
  9306. // set for CERT_STORE_CTL_CONTEXT. See flag definition for more details.
  9307. //
  9308. // If CERT_CREATE_CONTEXT_NO_ENTRY_FLAG is set, the context is created
  9309. // without decoding the entries. This flag may only be set for
  9310. // CERT_STORE_CTL_CONTEXT. See flag definition for more details.
  9311. //
  9312. // If unable to decode and create the context, NULL is returned.
  9313. // Otherwise, a pointer to a read only CERT_CONTEXT, CRL_CONTEXT or
  9314. // CTL_CONTEXT is returned. The context must be freed by the appropriate
  9315. // free context API. The context can be duplicated by calling the
  9316. // appropriate duplicate context API.
  9317. //--------------------------------------------------------------------------
  9318. WINCRYPT32API
  9319. const void *
  9320. WINAPI
  9321. CertCreateContext(
  9322. IN DWORD dwContextType,
  9323. IN DWORD dwEncodingType,
  9324. IN const BYTE *pbEncoded,
  9325. IN DWORD cbEncoded,
  9326. IN DWORD dwFlags,
  9327. IN OPTIONAL PCERT_CREATE_CONTEXT_PARA pCreatePara
  9328. );
  9329. // When the following flag is set, the created context points directly to the
  9330. // pbEncoded instead of an allocated copy. If pCreatePara and
  9331. // pCreatePara->pfnFree are non-NULL, then, pfnFree is called to free
  9332. // the pbEncoded when the context is last freed. Otherwise, no attempt is
  9333. // made to free the pbEncoded. If pCreatePara->pvFree is non-NULL, then its
  9334. // passed to pfnFree instead of pbEncoded.
  9335. //
  9336. // Note, if CertCreateContext fails, pfnFree is still called.
  9337. #define CERT_CREATE_CONTEXT_NOCOPY_FLAG 0x1
  9338. // When the following flag is set, a context with sorted entries is created.
  9339. // Currently only applicable to a CTL context.
  9340. //
  9341. // For CTLs: the cCTLEntry in the returned CTL_INFO is always
  9342. // 0. CertFindSubjectInSortedCTL and CertEnumSubjectInSortedCTL must be called
  9343. // to find or enumerate the CTL entries.
  9344. //
  9345. // The Sorted CTL TrustedSubjects extension isn't returned in the created
  9346. // context's CTL_INFO.
  9347. #define CERT_CREATE_CONTEXT_SORTED_FLAG 0x2
  9348. // By default when a CTL context is created, a HCRYPTMSG handle to its
  9349. // SignedData message is created. This flag can be set to improve performance
  9350. // by not creating the HCRYPTMSG handle.
  9351. //
  9352. // This flag is only applicable to a CTL context.
  9353. #define CERT_CREATE_CONTEXT_NO_HCRYPTMSG_FLAG 0x4
  9354. // By default when a CTL context is created, its entries are decoded.
  9355. // This flag can be set to improve performance by not decoding the
  9356. // entries.
  9357. //
  9358. // This flag is only applicable to a CTL context.
  9359. #define CERT_CREATE_CONTEXT_NO_ENTRY_FLAG 0x8
  9360. //+=========================================================================
  9361. // Certificate System Store Data Structures and APIs
  9362. //==========================================================================
  9363. //+-------------------------------------------------------------------------
  9364. // System Store Information
  9365. //
  9366. // Currently, no system store information is persisted.
  9367. //--------------------------------------------------------------------------
  9368. typedef struct _CERT_SYSTEM_STORE_INFO {
  9369. DWORD cbSize;
  9370. } CERT_SYSTEM_STORE_INFO, *PCERT_SYSTEM_STORE_INFO;
  9371. //+-------------------------------------------------------------------------
  9372. // Physical Store Information
  9373. //
  9374. // The Open fields are passed directly to CertOpenStore() to open
  9375. // the physical store.
  9376. //
  9377. // By default all system stores located in the registry have an
  9378. // implicit SystemRegistry physical store that is opened. To disable the
  9379. // opening of this store, the SystemRegistry
  9380. // physical store corresponding to the System store must be registered with
  9381. // CERT_PHYSICAL_STORE_OPEN_DISABLE_FLAG set in dwFlags. Alternatively,
  9382. // a physical store with the name of ".Default" may be registered.
  9383. //
  9384. // Depending on the store location and store name, additional predefined
  9385. // physical stores may be opened. For example, system stores in
  9386. // CURRENT_USER have the predefined physical store, .LocalMachine.
  9387. // To disable the opening of these predefined physical stores, the
  9388. // corresponding physical store must be registered with
  9389. // CERT_PHYSICAL_STORE_OPEN_DISABLE_FLAG set in dwFlags.
  9390. //
  9391. // The CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG must be set in dwFlags
  9392. // to enable the adding of a context to the store.
  9393. //
  9394. // When a system store is opened via the SERVICES or USERS store location,
  9395. // the ServiceName\ is prepended to the OpenParameters
  9396. // for CERT_SYSTEM_STORE_CURRENT_USER or CERT_SYSTEM_STORE_CURRENT_SERVICE
  9397. // physical stores and the dwOpenFlags store location is changed to
  9398. // CERT_SYSTEM_STORE_USERS or CERT_SYSTEM_STORE_SERVICES.
  9399. //
  9400. // By default the SYSTEM, SYSTEM_REGISTRY and PHYSICAL provider
  9401. // stores are also opened remotely when the outer system store is opened.
  9402. // The CERT_PHYSICAL_STORE_REMOTE_OPEN_DISABLE_FLAG may be set in dwFlags
  9403. // to disable remote opens.
  9404. //
  9405. // When opened remotely, the \\ComputerName is implicitly prepended to the
  9406. // OpenParameters for the SYSTEM, SYSTEM_REGISTRY and PHYSICAL provider types.
  9407. // To also prepend the \\ComputerName to other provider types, set the
  9408. // CERT_PHYSICAL_STORE_INSERT_COMPUTER_NAME_ENABLE_FLAG in dwFlags.
  9409. //
  9410. // When the system store is opened, its physical stores are ordered
  9411. // according to the dwPriority. A larger dwPriority indicates higher priority.
  9412. //--------------------------------------------------------------------------
  9413. typedef struct _CERT_PHYSICAL_STORE_INFO {
  9414. DWORD cbSize;
  9415. LPSTR pszOpenStoreProvider; // REG_SZ
  9416. DWORD dwOpenEncodingType; // REG_DWORD
  9417. DWORD dwOpenFlags; // REG_DWORD
  9418. CRYPT_DATA_BLOB OpenParameters; // REG_BINARY
  9419. DWORD dwFlags; // REG_DWORD
  9420. DWORD dwPriority; // REG_DWORD
  9421. } CERT_PHYSICAL_STORE_INFO, *PCERT_PHYSICAL_STORE_INFO;
  9422. //+-------------------------------------------------------------------------
  9423. // Physical Store Information dwFlags
  9424. //--------------------------------------------------------------------------
  9425. #define CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG 0x1
  9426. #define CERT_PHYSICAL_STORE_OPEN_DISABLE_FLAG 0x2
  9427. #define CERT_PHYSICAL_STORE_REMOTE_OPEN_DISABLE_FLAG 0x4
  9428. #define CERT_PHYSICAL_STORE_INSERT_COMPUTER_NAME_ENABLE_FLAG 0x8
  9429. //+-------------------------------------------------------------------------
  9430. // Register a system store.
  9431. //
  9432. // The upper word of the dwFlags parameter is used to specify the location of
  9433. // the system store.
  9434. //
  9435. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvSystemStore
  9436. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure. Otherwise,
  9437. // pvSystemStore points to a null terminated UNICODE string.
  9438. //
  9439. // The CERT_SYSTEM_STORE_SERVICES or CERT_SYSTEM_STORE_USERS system store
  9440. // name must be prefixed with the ServiceName or UserName. For example,
  9441. // "ServiceName\Trust".
  9442. //
  9443. // Stores on remote computers can be registered for the
  9444. // CERT_SYSTEM_STORE_LOCAL_MACHINE, CERT_SYSTEM_STORE_SERVICES,
  9445. // CERT_SYSTEM_STORE_USERS, CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY
  9446. // or CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE
  9447. // locations by prepending the computer name. For example, a remote
  9448. // local machine store is registered via "\\ComputerName\Trust" or
  9449. // "ComputerName\Trust". A remote service store is registered via
  9450. // "\\ComputerName\ServiceName\Trust". The leading "\\" backslashes are
  9451. // optional in the ComputerName.
  9452. //
  9453. // Set CERT_STORE_CREATE_NEW_FLAG to cause a failure if the system store
  9454. // already exists in the store location.
  9455. //--------------------------------------------------------------------------
  9456. WINCRYPT32API
  9457. BOOL
  9458. WINAPI
  9459. CertRegisterSystemStore(
  9460. IN const void *pvSystemStore,
  9461. IN DWORD dwFlags,
  9462. IN PCERT_SYSTEM_STORE_INFO pStoreInfo,
  9463. IN OPTIONAL void *pvReserved
  9464. );
  9465. //+-------------------------------------------------------------------------
  9466. // Register a physical store for the specified system store.
  9467. //
  9468. // The upper word of the dwFlags parameter is used to specify the location of
  9469. // the system store.
  9470. //
  9471. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvSystemStore
  9472. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure. Otherwise,
  9473. // pvSystemStore points to a null terminated UNICODE string.
  9474. //
  9475. // See CertRegisterSystemStore for details on prepending a ServiceName
  9476. // and/or ComputerName to the system store name.
  9477. //
  9478. // Set CERT_STORE_CREATE_NEW_FLAG to cause a failure if the physical store
  9479. // already exists in the system store.
  9480. //--------------------------------------------------------------------------
  9481. WINCRYPT32API
  9482. BOOL
  9483. WINAPI
  9484. CertRegisterPhysicalStore(
  9485. IN const void *pvSystemStore,
  9486. IN DWORD dwFlags,
  9487. IN LPCWSTR pwszStoreName,
  9488. IN PCERT_PHYSICAL_STORE_INFO pStoreInfo,
  9489. IN OPTIONAL void *pvReserved
  9490. );
  9491. //+-------------------------------------------------------------------------
  9492. // Unregister the specified system store.
  9493. //
  9494. // The upper word of the dwFlags parameter is used to specify the location of
  9495. // the system store.
  9496. //
  9497. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvSystemStore
  9498. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure. Otherwise,
  9499. // pvSystemStore points to a null terminated UNICODE string.
  9500. //
  9501. // See CertRegisterSystemStore for details on prepending a ServiceName
  9502. // and/or ComputerName to the system store name.
  9503. //
  9504. // CERT_STORE_DELETE_FLAG can optionally be set in dwFlags.
  9505. //--------------------------------------------------------------------------
  9506. WINCRYPT32API
  9507. BOOL
  9508. WINAPI
  9509. CertUnregisterSystemStore(
  9510. IN const void *pvSystemStore,
  9511. IN DWORD dwFlags
  9512. );
  9513. //+-------------------------------------------------------------------------
  9514. // Unregister the physical store from the specified system store.
  9515. //
  9516. // The upper word of the dwFlags parameter is used to specify the location of
  9517. // the system store.
  9518. //
  9519. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvSystemStore
  9520. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure. Otherwise,
  9521. // pvSystemStore points to a null terminated UNICODE string.
  9522. //
  9523. // See CertRegisterSystemStore for details on prepending a ServiceName
  9524. // and/or ComputerName to the system store name.
  9525. //
  9526. // CERT_STORE_DELETE_FLAG can optionally be set in dwFlags.
  9527. //--------------------------------------------------------------------------
  9528. WINCRYPT32API
  9529. BOOL
  9530. WINAPI
  9531. CertUnregisterPhysicalStore(
  9532. IN const void *pvSystemStore,
  9533. IN DWORD dwFlags,
  9534. IN LPCWSTR pwszStoreName
  9535. );
  9536. //+-------------------------------------------------------------------------
  9537. // Enum callbacks
  9538. //
  9539. // The CERT_SYSTEM_STORE_LOCATION_MASK bits in the dwFlags parameter
  9540. // specifies the location of the system store
  9541. //
  9542. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvSystemStore
  9543. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure. Otherwise,
  9544. // pvSystemStore points to a null terminated UNICODE string.
  9545. //
  9546. // The callback returns FALSE and sets LAST_ERROR to stop the enumeration.
  9547. // The LAST_ERROR is returned to the caller of the enumeration.
  9548. //
  9549. // The pvSystemStore passed to the callback has leading ComputerName and/or
  9550. // ServiceName prefixes where appropriate.
  9551. //--------------------------------------------------------------------------
  9552. typedef BOOL (WINAPI *PFN_CERT_ENUM_SYSTEM_STORE_LOCATION)(
  9553. IN LPCWSTR pwszStoreLocation,
  9554. IN DWORD dwFlags,
  9555. IN OPTIONAL void *pvReserved,
  9556. IN OPTIONAL void *pvArg
  9557. );
  9558. typedef BOOL (WINAPI *PFN_CERT_ENUM_SYSTEM_STORE)(
  9559. IN const void *pvSystemStore,
  9560. IN DWORD dwFlags,
  9561. IN PCERT_SYSTEM_STORE_INFO pStoreInfo,
  9562. IN OPTIONAL void *pvReserved,
  9563. IN OPTIONAL void *pvArg
  9564. );
  9565. typedef BOOL (WINAPI *PFN_CERT_ENUM_PHYSICAL_STORE)(
  9566. IN const void *pvSystemStore,
  9567. IN DWORD dwFlags,
  9568. IN LPCWSTR pwszStoreName,
  9569. IN PCERT_PHYSICAL_STORE_INFO pStoreInfo,
  9570. IN OPTIONAL void *pvReserved,
  9571. IN OPTIONAL void *pvArg
  9572. );
  9573. // In the PFN_CERT_ENUM_PHYSICAL_STORE callback the following flag is
  9574. // set if the physical store wasn't registered and is an implicitly created
  9575. // predefined physical store.
  9576. #define CERT_PHYSICAL_STORE_PREDEFINED_ENUM_FLAG 0x1
  9577. // Names of implicitly created predefined physical stores
  9578. #define CERT_PHYSICAL_STORE_DEFAULT_NAME L".Default"
  9579. #define CERT_PHYSICAL_STORE_GROUP_POLICY_NAME L".GroupPolicy"
  9580. #define CERT_PHYSICAL_STORE_LOCAL_MACHINE_NAME L".LocalMachine"
  9581. #define CERT_PHYSICAL_STORE_DS_USER_CERTIFICATE_NAME L".UserCertificate"
  9582. #define CERT_PHYSICAL_STORE_LOCAL_MACHINE_GROUP_POLICY_NAME \
  9583. L".LocalMachineGroupPolicy"
  9584. #define CERT_PHYSICAL_STORE_ENTERPRISE_NAME L".Enterprise"
  9585. #define CERT_PHYSICAL_STORE_AUTH_ROOT_NAME L".AuthRoot"
  9586. //+-------------------------------------------------------------------------
  9587. // Enumerate the system store locations.
  9588. //--------------------------------------------------------------------------
  9589. WINCRYPT32API
  9590. BOOL
  9591. WINAPI
  9592. CertEnumSystemStoreLocation(
  9593. IN DWORD dwFlags,
  9594. IN void *pvArg,
  9595. IN PFN_CERT_ENUM_SYSTEM_STORE_LOCATION pfnEnum
  9596. );
  9597. //+-------------------------------------------------------------------------
  9598. // Enumerate the system stores.
  9599. //
  9600. // The upper word of the dwFlags parameter is used to specify the location of
  9601. // the system store.
  9602. //
  9603. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags,
  9604. // pvSystemStoreLocationPara points to a CERT_SYSTEM_STORE_RELOCATE_PARA
  9605. // data structure. Otherwise, pvSystemStoreLocationPara points to a null
  9606. // terminated UNICODE string.
  9607. //
  9608. // For CERT_SYSTEM_STORE_LOCAL_MACHINE,
  9609. // CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY or
  9610. // CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE, pvSystemStoreLocationPara can
  9611. // optionally be set to a unicode computer name for enumerating local machine
  9612. // stores on a remote computer. For example, "\\ComputerName" or
  9613. // "ComputerName". The leading "\\" backslashes are optional in the
  9614. // ComputerName.
  9615. //
  9616. // For CERT_SYSTEM_STORE_SERVICES or CERT_SYSTEM_STORE_USERS,
  9617. // if pvSystemStoreLocationPara is NULL, then,
  9618. // enumerates both the service/user names and the stores for each service/user
  9619. // name. Otherwise, pvSystemStoreLocationPara is a unicode string specifying a
  9620. // remote computer name and/or service/user name. For example:
  9621. // "ServiceName"
  9622. // "\\ComputerName" or "ComputerName\"
  9623. // "ComputerName\ServiceName"
  9624. // Note, if only the ComputerName is specified, then, it must have either
  9625. // the leading "\\" backslashes or a trailing backslash. Otherwise, its
  9626. // interpretted as the ServiceName or UserName.
  9627. //--------------------------------------------------------------------------
  9628. WINCRYPT32API
  9629. BOOL
  9630. WINAPI
  9631. CertEnumSystemStore(
  9632. IN DWORD dwFlags,
  9633. IN OPTIONAL void *pvSystemStoreLocationPara,
  9634. IN void *pvArg,
  9635. IN PFN_CERT_ENUM_SYSTEM_STORE pfnEnum
  9636. );
  9637. //+-------------------------------------------------------------------------
  9638. // Enumerate the physical stores for the specified system store.
  9639. //
  9640. // The upper word of the dwFlags parameter is used to specify the location of
  9641. // the system store.
  9642. //
  9643. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvSystemStore
  9644. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure. Otherwise,
  9645. // pvSystemStore points to a null terminated UNICODE string.
  9646. //
  9647. // See CertRegisterSystemStore for details on prepending a ServiceName
  9648. // and/or ComputerName to the system store name.
  9649. //
  9650. // If the system store location only supports system stores and doesn't
  9651. // support physical stores, LastError is set to ERROR_CALL_NOT_IMPLEMENTED.
  9652. //--------------------------------------------------------------------------
  9653. WINCRYPT32API
  9654. BOOL
  9655. WINAPI
  9656. CertEnumPhysicalStore(
  9657. IN const void *pvSystemStore,
  9658. IN DWORD dwFlags,
  9659. IN void *pvArg,
  9660. IN PFN_CERT_ENUM_PHYSICAL_STORE pfnEnum
  9661. );
  9662. //+-------------------------------------------------------------------------
  9663. // Certificate System Store Installable Functions
  9664. //
  9665. // The CERT_SYSTEM_STORE_LOCATION_MASK bits in the dwFlags parameter passed
  9666. // to the CertOpenStore(for "System", "SystemRegistry" or "Physical"
  9667. // Provider), CertRegisterSystemStore,
  9668. // CertUnregisterSystemStore, CertEnumSystemStore, CertRegisterPhysicalStore,
  9669. // CertUnregisterPhysicalStore and CertEnumPhysicalStore APIs is used as the
  9670. // constant pszOID value passed to the OID installable functions.
  9671. // Therefore, the pszOID is restricted to a constant <= (LPCSTR) 0x0FFF.
  9672. //
  9673. // The EncodingType is 0.
  9674. //--------------------------------------------------------------------------
  9675. // Installable System Store Provider OID pszFuncNames.
  9676. #define CRYPT_OID_OPEN_SYSTEM_STORE_PROV_FUNC "CertDllOpenSystemStoreProv"
  9677. #define CRYPT_OID_REGISTER_SYSTEM_STORE_FUNC "CertDllRegisterSystemStore"
  9678. #define CRYPT_OID_UNREGISTER_SYSTEM_STORE_FUNC "CertDllUnregisterSystemStore"
  9679. #define CRYPT_OID_ENUM_SYSTEM_STORE_FUNC "CertDllEnumSystemStore"
  9680. #define CRYPT_OID_REGISTER_PHYSICAL_STORE_FUNC "CertDllRegisterPhysicalStore"
  9681. #define CRYPT_OID_UNREGISTER_PHYSICAL_STORE_FUNC "CertDllUnregisterPhysicalStore"
  9682. #define CRYPT_OID_ENUM_PHYSICAL_STORE_FUNC "CertDllEnumPhysicalStore"
  9683. // CertDllOpenSystemStoreProv has the same function signature as the
  9684. // installable "CertDllOpenStoreProv" function. See CertOpenStore for
  9685. // more details.
  9686. // CertDllRegisterSystemStore has the same function signature as
  9687. // CertRegisterSystemStore.
  9688. //
  9689. // The "SystemStoreLocation" REG_SZ value must also be set for registered
  9690. // CertDllEnumSystemStore OID functions.
  9691. #define CRYPT_OID_SYSTEM_STORE_LOCATION_VALUE_NAME L"SystemStoreLocation"
  9692. // The remaining Register, Enum and Unregister OID installable functions
  9693. // have the same signature as their Cert Store API counterpart.
  9694. //+=========================================================================
  9695. // Enhanced Key Usage Helper Functions
  9696. //==========================================================================
  9697. //+-------------------------------------------------------------------------
  9698. // Get the enhanced key usage extension or property from the certificate
  9699. // and decode.
  9700. //
  9701. // If the CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG is set, then, only get the
  9702. // extension.
  9703. //
  9704. // If the CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG is set, then, only get the
  9705. // property.
  9706. //--------------------------------------------------------------------------
  9707. WINCRYPT32API
  9708. BOOL
  9709. WINAPI
  9710. CertGetEnhancedKeyUsage(
  9711. IN PCCERT_CONTEXT pCertContext,
  9712. IN DWORD dwFlags,
  9713. OUT PCERT_ENHKEY_USAGE pUsage,
  9714. IN OUT DWORD *pcbUsage
  9715. );
  9716. //+-------------------------------------------------------------------------
  9717. // Set the enhanced key usage property for the certificate.
  9718. //--------------------------------------------------------------------------
  9719. WINCRYPT32API
  9720. BOOL
  9721. WINAPI
  9722. CertSetEnhancedKeyUsage(
  9723. IN PCCERT_CONTEXT pCertContext,
  9724. IN PCERT_ENHKEY_USAGE pUsage
  9725. );
  9726. //+-------------------------------------------------------------------------
  9727. // Add the usage identifier to the certificate's enhanced key usage property.
  9728. //--------------------------------------------------------------------------
  9729. WINCRYPT32API
  9730. BOOL
  9731. WINAPI
  9732. CertAddEnhancedKeyUsageIdentifier(
  9733. IN PCCERT_CONTEXT pCertContext,
  9734. IN LPCSTR pszUsageIdentifier
  9735. );
  9736. //+-------------------------------------------------------------------------
  9737. // Remove the usage identifier from the certificate's enhanced key usage
  9738. // property.
  9739. //--------------------------------------------------------------------------
  9740. WINCRYPT32API
  9741. BOOL
  9742. WINAPI
  9743. CertRemoveEnhancedKeyUsageIdentifier(
  9744. IN PCCERT_CONTEXT pCertContext,
  9745. IN LPCSTR pszUsageIdentifier
  9746. );
  9747. //+---------------------------------------------------------------------------
  9748. //
  9749. //
  9750. // Takes an array of certs and returns an array of usages
  9751. // which consists of the intersection of the valid usages for each cert.
  9752. // If each cert is good for all possible usages then the cNumOIDs is set to -1.
  9753. //
  9754. //----------------------------------------------------------------------------
  9755. WINCRYPT32API
  9756. BOOL
  9757. WINAPI
  9758. CertGetValidUsages(
  9759. IN DWORD cCerts,
  9760. IN PCCERT_CONTEXT *rghCerts,
  9761. OUT int *cNumOIDs,
  9762. OUT LPSTR *rghOIDs,
  9763. IN OUT DWORD *pcbOIDs);
  9764. //+=========================================================================
  9765. // Cryptographic Message helper functions for verifying and signing a
  9766. // CTL.
  9767. //==========================================================================
  9768. //+-------------------------------------------------------------------------
  9769. // Get and verify the signer of a cryptographic message.
  9770. //
  9771. // To verify a CTL, the hCryptMsg is obtained from the CTL_CONTEXT's
  9772. // hCryptMsg field.
  9773. //
  9774. // If CMSG_TRUSTED_SIGNER_FLAG is set, then, treat the Signer stores as being
  9775. // trusted and only search them to find the certificate corresponding to the
  9776. // signer's issuer and serial number. Otherwise, the SignerStores are
  9777. // optionally provided to supplement the message's store of certificates.
  9778. // If a signer certificate is found, its public key is used to verify
  9779. // the message signature. The CMSG_SIGNER_ONLY_FLAG can be set to
  9780. // return the signer without doing the signature verify.
  9781. //
  9782. // If CMSG_USE_SIGNER_INDEX_FLAG is set, then, only get the signer specified
  9783. // by *pdwSignerIndex. Otherwise, iterate through all the signers
  9784. // until a signer verifies or no more signers.
  9785. //
  9786. // For a verified signature, *ppSigner is updated with certificate context
  9787. // of the signer and *pdwSignerIndex is updated with the index of the signer.
  9788. // ppSigner and/or pdwSignerIndex can be NULL, indicating the caller isn't
  9789. // interested in getting the CertContext and/or index of the signer.
  9790. //--------------------------------------------------------------------------
  9791. WINCRYPT32API
  9792. BOOL
  9793. WINAPI
  9794. CryptMsgGetAndVerifySigner(
  9795. IN HCRYPTMSG hCryptMsg,
  9796. IN DWORD cSignerStore,
  9797. IN OPTIONAL HCERTSTORE *rghSignerStore,
  9798. IN DWORD dwFlags,
  9799. OUT OPTIONAL PCCERT_CONTEXT *ppSigner,
  9800. IN OUT OPTIONAL DWORD *pdwSignerIndex
  9801. );
  9802. #define CMSG_TRUSTED_SIGNER_FLAG 0x1
  9803. #define CMSG_SIGNER_ONLY_FLAG 0x2
  9804. #define CMSG_USE_SIGNER_INDEX_FLAG 0x4
  9805. //+-------------------------------------------------------------------------
  9806. // Sign an encoded CTL.
  9807. //
  9808. // The pbCtlContent can be obtained via a CTL_CONTEXT's pbCtlContent
  9809. // field or via a CryptEncodeObject(PKCS_CTL or PKCS_SORTED_CTL).
  9810. //
  9811. // CMSG_CMS_ENCAPSULATED_CTL_FLAG can be set to encode a CMS compatible
  9812. // V3 SignedData message.
  9813. //--------------------------------------------------------------------------
  9814. WINCRYPT32API
  9815. BOOL
  9816. WINAPI
  9817. CryptMsgSignCTL(
  9818. IN DWORD dwMsgEncodingType,
  9819. IN BYTE *pbCtlContent,
  9820. IN DWORD cbCtlContent,
  9821. IN PCMSG_SIGNED_ENCODE_INFO pSignInfo,
  9822. IN DWORD dwFlags,
  9823. OUT BYTE *pbEncoded,
  9824. IN OUT DWORD *pcbEncoded
  9825. );
  9826. // When set, CTL inner content is encapsulated within an OCTET STRING
  9827. #define CMSG_CMS_ENCAPSULATED_CTL_FLAG 0x00008000
  9828. //+-------------------------------------------------------------------------
  9829. // Encode the CTL and create a signed message containing the encoded CTL.
  9830. //
  9831. // Set CMSG_ENCODE_SORTED_CTL_FLAG if the CTL entries are to be sorted
  9832. // before encoding. This flag should be set, if the
  9833. // CertFindSubjectInSortedCTL or CertEnumSubjectInSortedCTL APIs will
  9834. // be called. If the identifier for the CTL entries is a hash, such as,
  9835. // MD5 or SHA1, then, CMSG_ENCODE_HASHED_SUBJECT_IDENTIFIER_FLAG should
  9836. // also be set.
  9837. //
  9838. // CMSG_CMS_ENCAPSULATED_CTL_FLAG can be set to encode a CMS compatible
  9839. // V3 SignedData message.
  9840. //--------------------------------------------------------------------------
  9841. WINCRYPT32API
  9842. BOOL
  9843. WINAPI
  9844. CryptMsgEncodeAndSignCTL(
  9845. IN DWORD dwMsgEncodingType,
  9846. IN PCTL_INFO pCtlInfo,
  9847. IN PCMSG_SIGNED_ENCODE_INFO pSignInfo,
  9848. IN DWORD dwFlags,
  9849. OUT BYTE *pbEncoded,
  9850. IN OUT DWORD *pcbEncoded
  9851. );
  9852. // The following flag is set if the CTL is to be encoded with sorted
  9853. // trusted subjects and the szOID_SORTED_CTL extension is inserted containing
  9854. // sorted offsets to the encoded subjects.
  9855. #define CMSG_ENCODE_SORTED_CTL_FLAG 0x1
  9856. // If the above sorted flag is set, then, the following flag should also
  9857. // be set if the identifier for the TrustedSubjects is a hash,
  9858. // such as, MD5 or SHA1.
  9859. #define CMSG_ENCODE_HASHED_SUBJECT_IDENTIFIER_FLAG 0x2
  9860. //+-------------------------------------------------------------------------
  9861. // Returns TRUE if the SubjectIdentifier exists in the CTL. Optionally
  9862. // returns a pointer to and byte count of the Subject's encoded attributes.
  9863. //--------------------------------------------------------------------------
  9864. WINCRYPT32API
  9865. BOOL
  9866. WINAPI
  9867. CertFindSubjectInSortedCTL(
  9868. IN PCRYPT_DATA_BLOB pSubjectIdentifier,
  9869. IN PCCTL_CONTEXT pCtlContext,
  9870. IN DWORD dwFlags,
  9871. IN void *pvReserved,
  9872. OUT OPTIONAL PCRYPT_DER_BLOB pEncodedAttributes
  9873. );
  9874. //+-------------------------------------------------------------------------
  9875. // Enumerates through the sequence of TrustedSubjects in a CTL context
  9876. // created with CERT_CREATE_CONTEXT_SORTED_FLAG set.
  9877. //
  9878. // To start the enumeration, *ppvNextSubject must be NULL. Upon return,
  9879. // *ppvNextSubject is updated to point to the next TrustedSubject in
  9880. // the encoded sequence.
  9881. //
  9882. // Returns FALSE for no more subjects or invalid arguments.
  9883. //
  9884. // Note, the returned DER_BLOBs point directly into the encoded
  9885. // bytes (not allocated, and must not be freed).
  9886. //--------------------------------------------------------------------------
  9887. WINCRYPT32API
  9888. BOOL
  9889. WINAPI
  9890. CertEnumSubjectInSortedCTL(
  9891. IN PCCTL_CONTEXT pCtlContext,
  9892. IN OUT void **ppvNextSubject,
  9893. OUT OPTIONAL PCRYPT_DER_BLOB pSubjectIdentifier,
  9894. OUT OPTIONAL PCRYPT_DER_BLOB pEncodedAttributes
  9895. );
  9896. //+=========================================================================
  9897. // Certificate Verify CTL Usage Data Structures and APIs
  9898. //==========================================================================
  9899. typedef struct _CTL_VERIFY_USAGE_PARA {
  9900. DWORD cbSize;
  9901. CRYPT_DATA_BLOB ListIdentifier; // OPTIONAL
  9902. DWORD cCtlStore;
  9903. HCERTSTORE *rghCtlStore; // OPTIONAL
  9904. DWORD cSignerStore;
  9905. HCERTSTORE *rghSignerStore; // OPTIONAL
  9906. } CTL_VERIFY_USAGE_PARA, *PCTL_VERIFY_USAGE_PARA;
  9907. typedef struct _CTL_VERIFY_USAGE_STATUS {
  9908. DWORD cbSize;
  9909. DWORD dwError;
  9910. DWORD dwFlags;
  9911. PCCTL_CONTEXT *ppCtl; // IN OUT OPTIONAL
  9912. DWORD dwCtlEntryIndex;
  9913. PCCERT_CONTEXT *ppSigner; // IN OUT OPTIONAL
  9914. DWORD dwSignerIndex;
  9915. } CTL_VERIFY_USAGE_STATUS, *PCTL_VERIFY_USAGE_STATUS;
  9916. #define CERT_VERIFY_INHIBIT_CTL_UPDATE_FLAG 0x1
  9917. #define CERT_VERIFY_TRUSTED_SIGNERS_FLAG 0x2
  9918. #define CERT_VERIFY_NO_TIME_CHECK_FLAG 0x4
  9919. #define CERT_VERIFY_ALLOW_MORE_USAGE_FLAG 0x8
  9920. #define CERT_VERIFY_UPDATED_CTL_FLAG 0x1
  9921. //+-------------------------------------------------------------------------
  9922. // Verify that a subject is trusted for the specified usage by finding a
  9923. // signed and time valid CTL with the usage identifiers and containing the
  9924. // the subject. A subject can be identified by either its certificate context
  9925. // or any identifier such as its SHA1 hash.
  9926. //
  9927. // See CertFindSubjectInCTL for definition of dwSubjectType and pvSubject
  9928. // parameters.
  9929. //
  9930. // Via pVerifyUsagePara, the caller can specify the stores to be searched
  9931. // to find the CTL. The caller can also specify the stores containing
  9932. // acceptable CTL signers. By setting the ListIdentifier, the caller
  9933. // can also restrict to a particular signer CTL list.
  9934. //
  9935. // Via pVerifyUsageStatus, the CTL containing the subject, the subject's
  9936. // index into the CTL's array of entries, and the signer of the CTL
  9937. // are returned. If the caller is not interested, ppCtl and ppSigner can be set
  9938. // to NULL. Returned contexts must be freed via the store's free context APIs.
  9939. //
  9940. // If the CERT_VERIFY_INHIBIT_CTL_UPDATE_FLAG isn't set, then, a time
  9941. // invalid CTL in one of the CtlStores may be replaced. When replaced, the
  9942. // CERT_VERIFY_UPDATED_CTL_FLAG is set in pVerifyUsageStatus->dwFlags.
  9943. //
  9944. // If the CERT_VERIFY_TRUSTED_SIGNERS_FLAG is set, then, only the
  9945. // SignerStores specified in pVerifyUsageStatus are searched to find
  9946. // the signer. Otherwise, the SignerStores provide additional sources
  9947. // to find the signer's certificate.
  9948. //
  9949. // If CERT_VERIFY_NO_TIME_CHECK_FLAG is set, then, the CTLs aren't checked
  9950. // for time validity.
  9951. //
  9952. // If CERT_VERIFY_ALLOW_MORE_USAGE_FLAG is set, then, the CTL may contain
  9953. // additional usage identifiers than specified by pSubjectUsage. Otherwise,
  9954. // the found CTL will contain the same usage identifers and no more.
  9955. //
  9956. // CertVerifyCTLUsage will be implemented as a dispatcher to OID installable
  9957. // functions. First, it will try to find an OID function matching the first
  9958. // usage object identifier in the pUsage sequence. Next, it will dispatch
  9959. // to the default CertDllVerifyCTLUsage functions.
  9960. //
  9961. // If the subject is trusted for the specified usage, then, TRUE is
  9962. // returned. Otherwise, FALSE is returned with dwError set to one of the
  9963. // following:
  9964. // CRYPT_E_NO_VERIFY_USAGE_DLL
  9965. // CRYPT_E_NO_VERIFY_USAGE_CHECK
  9966. // CRYPT_E_VERIFY_USAGE_OFFLINE
  9967. // CRYPT_E_NOT_IN_CTL
  9968. // CRYPT_E_NO_TRUSTED_SIGNER
  9969. //--------------------------------------------------------------------------
  9970. WINCRYPT32API
  9971. BOOL
  9972. WINAPI
  9973. CertVerifyCTLUsage(
  9974. IN DWORD dwEncodingType,
  9975. IN DWORD dwSubjectType,
  9976. IN void *pvSubject,
  9977. IN PCTL_USAGE pSubjectUsage,
  9978. IN DWORD dwFlags,
  9979. IN OPTIONAL PCTL_VERIFY_USAGE_PARA pVerifyUsagePara,
  9980. IN OUT PCTL_VERIFY_USAGE_STATUS pVerifyUsageStatus
  9981. );
  9982. //+=========================================================================
  9983. // Certificate Revocation Data Structures and APIs
  9984. //==========================================================================
  9985. //+-------------------------------------------------------------------------
  9986. // This data structure is updated by a CRL revocation type handler
  9987. // with the base and possibly the delta CRL used.
  9988. //--------------------------------------------------------------------------
  9989. typedef struct _CERT_REVOCATION_CRL_INFO {
  9990. DWORD cbSize;
  9991. PCCRL_CONTEXT pBaseCrlContext;
  9992. PCCRL_CONTEXT pDeltaCrlContext;
  9993. // When revoked, points to entry in either of the above CRL contexts.
  9994. // Don't free.
  9995. PCRL_ENTRY pCrlEntry;
  9996. BOOL fDeltaCrlEntry; // TRUE if in pDeltaCrlContext
  9997. } CERT_REVOCATION_CRL_INFO, *PCERT_REVOCATION_CRL_INFO;
  9998. //+-------------------------------------------------------------------------
  9999. // The following data structure may be passed to CertVerifyRevocation to
  10000. // assist in finding the issuer of the context to be verified.
  10001. //
  10002. // When pIssuerCert is specified, pIssuerCert is the issuer of
  10003. // rgpvContext[cContext - 1].
  10004. //
  10005. // When cCertStore and rgCertStore are specified, these stores may contain
  10006. // an issuer certificate.
  10007. //
  10008. // When hCrlStore is specified then a handler which uses CRLs can search this
  10009. // store for them
  10010. //
  10011. // When pftTimeToUse is specified then the handler (if possible) must determine
  10012. // revocation status relative to the time given otherwise the answer may be
  10013. // independent of time or relative to current time
  10014. //--------------------------------------------------------------------------
  10015. typedef struct _CERT_REVOCATION_PARA {
  10016. DWORD cbSize;
  10017. PCCERT_CONTEXT pIssuerCert;
  10018. DWORD cCertStore;
  10019. HCERTSTORE *rgCertStore;
  10020. HCERTSTORE hCrlStore;
  10021. LPFILETIME pftTimeToUse;
  10022. #ifdef CERT_REVOCATION_PARA_HAS_EXTRA_FIELDS
  10023. // Note, if you #define CERT_REVOCATION_PARA_HAS_EXTRA_FIELDS, then, you
  10024. // must zero all unused fields in this data structure.
  10025. // More fields could be added in a future release.
  10026. // 0 uses revocation handler's default timeout.
  10027. DWORD dwUrlRetrievalTimeout; // milliseconds
  10028. // When set, checks and attempts to retrieve a CRL where
  10029. // ThisUpdate >= (CurrentTime - dwFreshnessTime). Otherwise, defaults
  10030. // to using the CRL's NextUpdate.
  10031. BOOL fCheckFreshnessTime;
  10032. DWORD dwFreshnessTime; // seconds
  10033. // If NULL, revocation handler gets the current time
  10034. LPFILETIME pftCurrentTime;
  10035. // If nonNULL, a CRL revocation type handler updates with the base and
  10036. // possibly the delta CRL used. Note, *pCrlInfo must be initialized
  10037. // by the caller. Any nonNULL CRL contexts are freed. Any updated
  10038. // CRL contexts must be freed by the caller.
  10039. //
  10040. // The CRL info is only applicable to the last context checked. If
  10041. // interested in this information, then, CertVerifyRevocation should be
  10042. // called with cContext = 1.
  10043. PCERT_REVOCATION_CRL_INFO pCrlInfo;
  10044. #endif
  10045. } CERT_REVOCATION_PARA, *PCERT_REVOCATION_PARA;
  10046. //+-------------------------------------------------------------------------
  10047. // The following data structure is returned by CertVerifyRevocation to
  10048. // specify the status of the revoked or unchecked context. Review the
  10049. // following CertVerifyRevocation comments for details.
  10050. //
  10051. // Upon input to CertVerifyRevocation, cbSize must be set to a size
  10052. // >= (offsetof(CERT_REVOCATION_STATUS, dwReason) + sizeof(DWORD) ).
  10053. // Otherwise, CertVerifyRevocation returns FALSE and sets LastError to
  10054. // E_INVALIDARG.
  10055. //
  10056. // Upon input to the installed or registered CRYPT_OID_VERIFY_REVOCATION_FUNC
  10057. // functions, the dwIndex, dwError and dwReason have been zero'ed.
  10058. // If present, fHasFreshnessTime and dwFreshnessTime have been zero'ed.
  10059. //--------------------------------------------------------------------------
  10060. typedef struct _CERT_REVOCATION_STATUS {
  10061. DWORD cbSize;
  10062. DWORD dwIndex;
  10063. DWORD dwError;
  10064. DWORD dwReason;
  10065. // Depending on cbSize, the following fields may optionally be returned.
  10066. // The Freshness time is only applicable to the last context checked. If
  10067. // interested in this information, then, CertVerifyRevocation should be
  10068. // called with cContext = 1.
  10069. //
  10070. // fHasFreshnessTime is only set if we are able to retrieve revocation
  10071. // information. For a CRL its CurrentTime - ThisUpdate.
  10072. BOOL fHasFreshnessTime;
  10073. DWORD dwFreshnessTime; // seconds
  10074. } CERT_REVOCATION_STATUS, *PCERT_REVOCATION_STATUS;
  10075. //+-------------------------------------------------------------------------
  10076. // Verifies the array of contexts for revocation. The dwRevType parameter
  10077. // indicates the type of the context data structure passed in rgpvContext.
  10078. // Currently only the revocation of certificates is defined.
  10079. //
  10080. // If the CERT_VERIFY_REV_CHAIN_FLAG flag is set, then, CertVerifyRevocation
  10081. // is verifying a chain of certs where, rgpvContext[i + 1] is the issuer
  10082. // of rgpvContext[i]. Otherwise, CertVerifyRevocation makes no assumptions
  10083. // about the order of the contexts.
  10084. //
  10085. // To assist in finding the issuer, the pRevPara may optionally be set. See
  10086. // the CERT_REVOCATION_PARA data structure for details.
  10087. //
  10088. // The contexts must contain enough information to allow the
  10089. // installable or registered revocation DLLs to find the revocation server. For
  10090. // certificates, this information would normally be conveyed in an
  10091. // extension such as the IETF's AuthorityInfoAccess extension.
  10092. //
  10093. // CertVerifyRevocation returns TRUE if all of the contexts were successfully
  10094. // checked and none were revoked. Otherwise, returns FALSE and updates the
  10095. // returned pRevStatus data structure as follows:
  10096. // dwIndex
  10097. // Index of the first context that was revoked or unable to
  10098. // be checked for revocation
  10099. // dwError
  10100. // Error status. LastError is also set to this error status.
  10101. // dwError can be set to one of the following error codes defined
  10102. // in winerror.h:
  10103. // ERROR_SUCCESS - good context
  10104. // CRYPT_E_REVOKED - context was revoked. dwReason contains the
  10105. // reason for revocation
  10106. // CRYPT_E_REVOCATION_OFFLINE - unable to connect to the
  10107. // revocation server
  10108. // CRYPT_E_NOT_IN_REVOCATION_DATABASE - the context to be checked
  10109. // was not found in the revocation server's database.
  10110. // CRYPT_E_NO_REVOCATION_CHECK - the called revocation function
  10111. // wasn't able to do a revocation check on the context
  10112. // CRYPT_E_NO_REVOCATION_DLL - no installed or registered Dll was
  10113. // found to verify revocation
  10114. // dwReason
  10115. // The dwReason is currently only set for CRYPT_E_REVOKED and contains
  10116. // the reason why the context was revoked. May be one of the following
  10117. // CRL reasons defined by the CRL Reason Code extension ("2.5.29.21")
  10118. // CRL_REASON_UNSPECIFIED 0
  10119. // CRL_REASON_KEY_COMPROMISE 1
  10120. // CRL_REASON_CA_COMPROMISE 2
  10121. // CRL_REASON_AFFILIATION_CHANGED 3
  10122. // CRL_REASON_SUPERSEDED 4
  10123. // CRL_REASON_CESSATION_OF_OPERATION 5
  10124. // CRL_REASON_CERTIFICATE_HOLD 6
  10125. //
  10126. // For each entry in rgpvContext, CertVerifyRevocation iterates
  10127. // through the CRYPT_OID_VERIFY_REVOCATION_FUNC
  10128. // function set's list of installed DEFAULT functions.
  10129. // CryptGetDefaultOIDFunctionAddress is called with pwszDll = NULL. If no
  10130. // installed functions are found capable of doing the revocation verification,
  10131. // CryptVerifyRevocation iterates through CRYPT_OID_VERIFY_REVOCATION_FUNC's
  10132. // list of registered DEFAULT Dlls. CryptGetDefaultOIDDllList is called to
  10133. // get the list. CryptGetDefaultOIDFunctionAddress is called to load the Dll.
  10134. //
  10135. // The called functions have the same signature as CertVerifyRevocation. A
  10136. // called function returns TRUE if it was able to successfully check all of
  10137. // the contexts and none were revoked. Otherwise, the called function returns
  10138. // FALSE and updates pRevStatus. dwIndex is set to the index of
  10139. // the first context that was found to be revoked or unable to be checked.
  10140. // dwError and LastError are updated. For CRYPT_E_REVOKED, dwReason
  10141. // is updated. Upon input to the called function, dwIndex, dwError and
  10142. // dwReason have been zero'ed. cbSize has been checked to be >=
  10143. // sizeof(CERT_REVOCATION_STATUS).
  10144. //
  10145. // If the called function returns FALSE, and dwError isn't set to
  10146. // CRYPT_E_REVOKED, then, CertVerifyRevocation either continues on to the
  10147. // next DLL in the list for a returned dwIndex of 0 or for a returned
  10148. // dwIndex > 0, restarts the process of finding a verify function by
  10149. // advancing the start of the context array to the returned dwIndex and
  10150. // decrementing the count of remaining contexts.
  10151. //--------------------------------------------------------------------------
  10152. WINCRYPT32API
  10153. BOOL
  10154. WINAPI
  10155. CertVerifyRevocation(
  10156. IN DWORD dwEncodingType,
  10157. IN DWORD dwRevType,
  10158. IN DWORD cContext,
  10159. IN PVOID rgpvContext[],
  10160. IN DWORD dwFlags,
  10161. IN OPTIONAL PCERT_REVOCATION_PARA pRevPara,
  10162. IN OUT PCERT_REVOCATION_STATUS pRevStatus
  10163. );
  10164. //+-------------------------------------------------------------------------
  10165. // Revocation types
  10166. //--------------------------------------------------------------------------
  10167. #define CERT_CONTEXT_REVOCATION_TYPE 1
  10168. //+-------------------------------------------------------------------------
  10169. // When the following flag is set, rgpvContext[] consists of a chain
  10170. // of certificates, where rgpvContext[i + 1] is the issuer of rgpvContext[i].
  10171. //--------------------------------------------------------------------------
  10172. #define CERT_VERIFY_REV_CHAIN_FLAG 0x00000001
  10173. //+-------------------------------------------------------------------------
  10174. // CERT_VERIFY_CACHE_ONLY_BASED_REVOCATION prevents the revocation handler from
  10175. // accessing any network based resources for revocation checking
  10176. //--------------------------------------------------------------------------
  10177. #define CERT_VERIFY_CACHE_ONLY_BASED_REVOCATION 0x00000002
  10178. //+-------------------------------------------------------------------------
  10179. // By default, the dwUrlRetrievalTimeout in pRevPara is the timeout used
  10180. // for each URL wire retrieval. When the following flag is set,
  10181. // dwUrlRetrievalTimeout is the accumulative timeout across all URL wire
  10182. // retrievals.
  10183. //--------------------------------------------------------------------------
  10184. #define CERT_VERIFY_REV_ACCUMULATIVE_TIMEOUT_FLAG 0x00000004
  10185. //+-------------------------------------------------------------------------
  10186. // CERT_CONTEXT_REVOCATION_TYPE
  10187. //
  10188. // pvContext points to a const CERT_CONTEXT.
  10189. //--------------------------------------------------------------------------
  10190. //+=========================================================================
  10191. // Certificate Helper APIs
  10192. //==========================================================================
  10193. //+-------------------------------------------------------------------------
  10194. // Compare two multiple byte integer blobs to see if they are identical.
  10195. //
  10196. // Before doing the comparison, leading zero bytes are removed from a
  10197. // positive number and leading 0xFF bytes are removed from a negative
  10198. // number.
  10199. //
  10200. // The multiple byte integers are treated as Little Endian. pbData[0] is the
  10201. // least significant byte and pbData[cbData - 1] is the most significant
  10202. // byte.
  10203. //
  10204. // Returns TRUE if the integer blobs are identical after removing leading
  10205. // 0 or 0xFF bytes.
  10206. //--------------------------------------------------------------------------
  10207. BOOL
  10208. WINAPI
  10209. CertCompareIntegerBlob(
  10210. IN PCRYPT_INTEGER_BLOB pInt1,
  10211. IN PCRYPT_INTEGER_BLOB pInt2
  10212. );
  10213. //+-------------------------------------------------------------------------
  10214. // Compare two certificates to see if they are identical.
  10215. //
  10216. // Since a certificate is uniquely identified by its Issuer and SerialNumber,
  10217. // these are the only fields needing to be compared.
  10218. //
  10219. // Returns TRUE if the certificates are identical.
  10220. //--------------------------------------------------------------------------
  10221. WINCRYPT32API
  10222. BOOL
  10223. WINAPI
  10224. CertCompareCertificate(
  10225. IN DWORD dwCertEncodingType,
  10226. IN PCERT_INFO pCertId1,
  10227. IN PCERT_INFO pCertId2
  10228. );
  10229. //+-------------------------------------------------------------------------
  10230. // Compare two certificate names to see if they are identical.
  10231. //
  10232. // Returns TRUE if the names are identical.
  10233. //--------------------------------------------------------------------------
  10234. WINCRYPT32API
  10235. BOOL
  10236. WINAPI
  10237. CertCompareCertificateName(
  10238. IN DWORD dwCertEncodingType,
  10239. IN PCERT_NAME_BLOB pCertName1,
  10240. IN PCERT_NAME_BLOB pCertName2
  10241. );
  10242. //+-------------------------------------------------------------------------
  10243. // Compare the attributes in the certificate name with the specified
  10244. // Relative Distinguished Name's (CERT_RDN) array of attributes.
  10245. // The comparison iterates through the CERT_RDN attributes and looks for an
  10246. // attribute match in any of the certificate name's RDNs.
  10247. // Returns TRUE if all the attributes are found and match.
  10248. //
  10249. // The CERT_RDN_ATTR fields can have the following special values:
  10250. // pszObjId == NULL - ignore the attribute object identifier
  10251. // dwValueType == RDN_ANY_TYPE - ignore the value type
  10252. //
  10253. // CERT_CASE_INSENSITIVE_IS_RDN_ATTRS_FLAG should be set to do
  10254. // a case insensitive match. Otherwise, defaults to an exact, case sensitive
  10255. // match.
  10256. //
  10257. // CERT_UNICODE_IS_RDN_ATTRS_FLAG should be set if the pRDN was initialized
  10258. // with unicode strings as for CryptEncodeObject(X509_UNICODE_NAME).
  10259. //--------------------------------------------------------------------------
  10260. WINCRYPT32API
  10261. BOOL
  10262. WINAPI
  10263. CertIsRDNAttrsInCertificateName(
  10264. IN DWORD dwCertEncodingType,
  10265. IN DWORD dwFlags,
  10266. IN PCERT_NAME_BLOB pCertName,
  10267. IN PCERT_RDN pRDN
  10268. );
  10269. #define CERT_UNICODE_IS_RDN_ATTRS_FLAG 0x1
  10270. #define CERT_CASE_INSENSITIVE_IS_RDN_ATTRS_FLAG 0x2
  10271. //+-------------------------------------------------------------------------
  10272. // Compare two public keys to see if they are identical.
  10273. //
  10274. // Returns TRUE if the keys are identical.
  10275. //--------------------------------------------------------------------------
  10276. WINCRYPT32API
  10277. BOOL
  10278. WINAPI
  10279. CertComparePublicKeyInfo(
  10280. IN DWORD dwCertEncodingType,
  10281. IN PCERT_PUBLIC_KEY_INFO pPublicKey1,
  10282. IN PCERT_PUBLIC_KEY_INFO pPublicKey2
  10283. );
  10284. //+-------------------------------------------------------------------------
  10285. // Get the public/private key's bit length.
  10286. //
  10287. // Returns 0 if unable to determine the key's length.
  10288. //--------------------------------------------------------------------------
  10289. WINCRYPT32API
  10290. DWORD
  10291. WINAPI
  10292. CertGetPublicKeyLength(
  10293. IN DWORD dwCertEncodingType,
  10294. IN PCERT_PUBLIC_KEY_INFO pPublicKey
  10295. );
  10296. //+-------------------------------------------------------------------------
  10297. // Verify the signature of a subject certificate or a CRL using the
  10298. // public key info
  10299. //
  10300. // Returns TRUE for a valid signature.
  10301. //
  10302. // hCryptProv specifies the crypto provider to use to verify the signature.
  10303. // It doesn't need to use a private key.
  10304. //--------------------------------------------------------------------------
  10305. WINCRYPT32API
  10306. BOOL
  10307. WINAPI
  10308. CryptVerifyCertificateSignature(
  10309. IN HCRYPTPROV hCryptProv,
  10310. IN DWORD dwCertEncodingType,
  10311. IN const BYTE * pbEncoded,
  10312. IN DWORD cbEncoded,
  10313. IN PCERT_PUBLIC_KEY_INFO pPublicKey
  10314. );
  10315. //+-------------------------------------------------------------------------
  10316. // Verify the signature of a subject certificate, CRL, certificate request
  10317. // or keygen request using the issuer's public key.
  10318. //
  10319. // Returns TRUE for a valid signature.
  10320. //
  10321. // The subject can be an encoded blob or a context for a certificate or CRL.
  10322. // For a subject certificate context, if the certificate is missing
  10323. // inheritable PublicKey Algorithm Parameters, the context's
  10324. // CERT_PUBKEY_ALG_PARA_PROP_ID is updated with the issuer's public key
  10325. // algorithm parameters for a valid signature.
  10326. //
  10327. // The issuer can be a pointer to a CERT_PUBLIC_KEY_INFO, certificate
  10328. // context or a chain context.
  10329. //
  10330. // hCryptProv specifies the crypto provider to use to verify the signature.
  10331. // Its private key isn't used. If hCryptProv is NULL, a default
  10332. // provider is picked according to the PublicKey Algorithm OID.
  10333. //
  10334. // If the signature algorithm is a hashing algorithm, then, the
  10335. // signature is expected to contain the hash octets. Only dwIssuerType
  10336. // of CRYPT_VERIFY_CERT_SIGN_ISSUER_NULL may be specified
  10337. // to verify this no signature case. If any other dwIssuerType is
  10338. // specified, the verify will fail with LastError set to E_INVALIDARG.
  10339. //--------------------------------------------------------------------------
  10340. WINCRYPT32API
  10341. BOOL
  10342. WINAPI
  10343. CryptVerifyCertificateSignatureEx(
  10344. IN OPTIONAL HCRYPTPROV hCryptProv,
  10345. IN DWORD dwCertEncodingType,
  10346. IN DWORD dwSubjectType,
  10347. IN void *pvSubject,
  10348. IN DWORD dwIssuerType,
  10349. IN void *pvIssuer,
  10350. IN DWORD dwFlags,
  10351. IN OPTIONAL void *pvReserved
  10352. );
  10353. // Subject Types
  10354. #define CRYPT_VERIFY_CERT_SIGN_SUBJECT_BLOB 1
  10355. // pvSubject :: PCRYPT_DATA_BLOB
  10356. #define CRYPT_VERIFY_CERT_SIGN_SUBJECT_CERT 2
  10357. // pvSubject :: PCCERT_CONTEXT
  10358. #define CRYPT_VERIFY_CERT_SIGN_SUBJECT_CRL 3
  10359. // pvSubject :: PCCRL_CONTEXT
  10360. // Issuer Types
  10361. #define CRYPT_VERIFY_CERT_SIGN_ISSUER_PUBKEY 1
  10362. // pvIssuer :: PCERT_PUBLIC_KEY_INFO
  10363. #define CRYPT_VERIFY_CERT_SIGN_ISSUER_CERT 2
  10364. // pvIssuer :: PCCERT_CONTEXT
  10365. #define CRYPT_VERIFY_CERT_SIGN_ISSUER_CHAIN 3
  10366. // pvIssuer :: PCCERT_CHAIN_CONTEXT
  10367. #define CRYPT_VERIFY_CERT_SIGN_ISSUER_NULL 4
  10368. // pvIssuer :: NULL
  10369. //+-------------------------------------------------------------------------
  10370. // Compute the hash of the "to be signed" information in the encoded
  10371. // signed content (CERT_SIGNED_CONTENT_INFO).
  10372. //
  10373. // hCryptProv specifies the crypto provider to use to compute the hash.
  10374. // It doesn't need to use a private key.
  10375. //--------------------------------------------------------------------------
  10376. WINCRYPT32API
  10377. BOOL
  10378. WINAPI
  10379. CryptHashToBeSigned(
  10380. IN HCRYPTPROV hCryptProv,
  10381. IN DWORD dwCertEncodingType,
  10382. IN const BYTE *pbEncoded,
  10383. IN DWORD cbEncoded,
  10384. OUT BYTE *pbComputedHash,
  10385. IN OUT DWORD *pcbComputedHash
  10386. );
  10387. //+-------------------------------------------------------------------------
  10388. // Hash the encoded content.
  10389. //
  10390. // hCryptProv specifies the crypto provider to use to compute the hash.
  10391. // It doesn't need to use a private key.
  10392. //
  10393. // Algid specifies the CAPI hash algorithm to use. If Algid is 0, then, the
  10394. // default hash algorithm (currently SHA1) is used.
  10395. //--------------------------------------------------------------------------
  10396. WINCRYPT32API
  10397. BOOL
  10398. WINAPI
  10399. CryptHashCertificate(
  10400. IN HCRYPTPROV hCryptProv,
  10401. IN ALG_ID Algid,
  10402. IN DWORD dwFlags,
  10403. IN const BYTE *pbEncoded,
  10404. IN DWORD cbEncoded,
  10405. OUT BYTE *pbComputedHash,
  10406. IN OUT DWORD *pcbComputedHash
  10407. );
  10408. //+-------------------------------------------------------------------------
  10409. // Sign the "to be signed" information in the encoded signed content.
  10410. //
  10411. // hCryptProv specifies the crypto provider to use to do the signature.
  10412. // It uses the specified private key.
  10413. //
  10414. // If the SignatureAlgorithm is a hash algorithm, then, the signature
  10415. // contains the hash octets. A private key isn't used to encrypt the hash.
  10416. // dwKeySpec isn't used and hCryptProv can be NULL where an appropriate
  10417. // default provider will be used for hashing.
  10418. //--------------------------------------------------------------------------
  10419. WINCRYPT32API
  10420. BOOL
  10421. WINAPI
  10422. CryptSignCertificate(
  10423. IN HCRYPTPROV hCryptProv,
  10424. IN DWORD dwKeySpec,
  10425. IN DWORD dwCertEncodingType,
  10426. IN const BYTE *pbEncodedToBeSigned,
  10427. IN DWORD cbEncodedToBeSigned,
  10428. IN PCRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm,
  10429. IN OPTIONAL const void *pvHashAuxInfo,
  10430. OUT BYTE *pbSignature,
  10431. IN OUT DWORD *pcbSignature
  10432. );
  10433. //+-------------------------------------------------------------------------
  10434. // Encode the "to be signed" information. Sign the encoded "to be signed".
  10435. // Encode the "to be signed" and the signature.
  10436. //
  10437. // hCryptProv specifies the crypto provider to use to do the signature.
  10438. // It uses the specified private key.
  10439. //
  10440. // If the SignatureAlgorithm is a hash algorithm, then, the signature
  10441. // contains the hash octets. A private key isn't used to encrypt the hash.
  10442. // dwKeySpec isn't used and hCryptProv can be NULL where an appropriate
  10443. // default provider will be used for hashing.
  10444. //--------------------------------------------------------------------------
  10445. WINCRYPT32API
  10446. BOOL
  10447. WINAPI
  10448. CryptSignAndEncodeCertificate(
  10449. IN HCRYPTPROV hCryptProv,
  10450. IN DWORD dwKeySpec,
  10451. IN DWORD dwCertEncodingType,
  10452. IN LPCSTR lpszStructType, // "to be signed"
  10453. IN const void *pvStructInfo,
  10454. IN PCRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm,
  10455. IN OPTIONAL const void *pvHashAuxInfo,
  10456. OUT PBYTE pbEncoded,
  10457. IN OUT DWORD *pcbEncoded
  10458. );
  10459. //+-------------------------------------------------------------------------
  10460. // Verify the time validity of a certificate.
  10461. //
  10462. // Returns -1 if before NotBefore, +1 if after NotAfter and otherwise 0 for
  10463. // a valid certificate
  10464. //
  10465. // If pTimeToVerify is NULL, uses the current time.
  10466. //--------------------------------------------------------------------------
  10467. WINCRYPT32API
  10468. LONG
  10469. WINAPI
  10470. CertVerifyTimeValidity(
  10471. IN LPFILETIME pTimeToVerify,
  10472. IN PCERT_INFO pCertInfo
  10473. );
  10474. //+-------------------------------------------------------------------------
  10475. // Verify the time validity of a CRL.
  10476. //
  10477. // Returns -1 if before ThisUpdate, +1 if after NextUpdate and otherwise 0 for
  10478. // a valid CRL
  10479. //
  10480. // If pTimeToVerify is NULL, uses the current time.
  10481. //--------------------------------------------------------------------------
  10482. WINCRYPT32API
  10483. LONG
  10484. WINAPI
  10485. CertVerifyCRLTimeValidity(
  10486. IN LPFILETIME pTimeToVerify,
  10487. IN PCRL_INFO pCrlInfo
  10488. );
  10489. //+-------------------------------------------------------------------------
  10490. // Verify that the subject's time validity nests within the issuer's time
  10491. // validity.
  10492. //
  10493. // Returns TRUE if it nests. Otherwise, returns FALSE.
  10494. //--------------------------------------------------------------------------
  10495. WINCRYPT32API
  10496. BOOL
  10497. WINAPI
  10498. CertVerifyValidityNesting(
  10499. IN PCERT_INFO pSubjectInfo,
  10500. IN PCERT_INFO pIssuerInfo
  10501. );
  10502. //+-------------------------------------------------------------------------
  10503. // Verify that the subject certificate isn't on its issuer CRL.
  10504. //
  10505. // Returns true if the certificate isn't on the CRL.
  10506. //--------------------------------------------------------------------------
  10507. WINCRYPT32API
  10508. BOOL
  10509. WINAPI
  10510. CertVerifyCRLRevocation(
  10511. IN DWORD dwCertEncodingType,
  10512. IN PCERT_INFO pCertId, // Only the Issuer and SerialNumber
  10513. // fields are used
  10514. IN DWORD cCrlInfo,
  10515. IN PCRL_INFO rgpCrlInfo[]
  10516. );
  10517. //+-------------------------------------------------------------------------
  10518. // Convert the CAPI AlgId to the ASN.1 Object Identifier string
  10519. //
  10520. // Returns NULL if there isn't an ObjId corresponding to the AlgId.
  10521. //--------------------------------------------------------------------------
  10522. WINCRYPT32API
  10523. LPCSTR
  10524. WINAPI
  10525. CertAlgIdToOID(
  10526. IN DWORD dwAlgId
  10527. );
  10528. //+-------------------------------------------------------------------------
  10529. // Convert the ASN.1 Object Identifier string to the CAPI AlgId.
  10530. //
  10531. // Returns 0 if there isn't an AlgId corresponding to the ObjId.
  10532. //--------------------------------------------------------------------------
  10533. WINCRYPT32API
  10534. DWORD
  10535. WINAPI
  10536. CertOIDToAlgId(
  10537. IN LPCSTR pszObjId
  10538. );
  10539. //+-------------------------------------------------------------------------
  10540. // Find an extension identified by its Object Identifier.
  10541. //
  10542. // If found, returns pointer to the extension. Otherwise, returns NULL.
  10543. //--------------------------------------------------------------------------
  10544. WINCRYPT32API
  10545. PCERT_EXTENSION
  10546. WINAPI
  10547. CertFindExtension(
  10548. IN LPCSTR pszObjId,
  10549. IN DWORD cExtensions,
  10550. IN CERT_EXTENSION rgExtensions[]
  10551. );
  10552. //+-------------------------------------------------------------------------
  10553. // Find the first attribute identified by its Object Identifier.
  10554. //
  10555. // If found, returns pointer to the attribute. Otherwise, returns NULL.
  10556. //--------------------------------------------------------------------------
  10557. WINCRYPT32API
  10558. PCRYPT_ATTRIBUTE
  10559. WINAPI
  10560. CertFindAttribute(
  10561. IN LPCSTR pszObjId,
  10562. IN DWORD cAttr,
  10563. IN CRYPT_ATTRIBUTE rgAttr[]
  10564. );
  10565. //+-------------------------------------------------------------------------
  10566. // Find the first CERT_RDN attribute identified by its Object Identifier in
  10567. // the name's list of Relative Distinguished Names.
  10568. //
  10569. // If found, returns pointer to the attribute. Otherwise, returns NULL.
  10570. //--------------------------------------------------------------------------
  10571. WINCRYPT32API
  10572. PCERT_RDN_ATTR
  10573. WINAPI
  10574. CertFindRDNAttr(
  10575. IN LPCSTR pszObjId,
  10576. IN PCERT_NAME_INFO pName
  10577. );
  10578. //+-------------------------------------------------------------------------
  10579. // Get the intended key usage bytes from the certificate.
  10580. //
  10581. // If the certificate doesn't have any intended key usage bytes, returns FALSE
  10582. // and *pbKeyUsage is zeroed. Otherwise, returns TRUE and up through
  10583. // cbKeyUsage bytes are copied into *pbKeyUsage. Any remaining uncopied
  10584. // bytes are zeroed.
  10585. //--------------------------------------------------------------------------
  10586. WINCRYPT32API
  10587. BOOL
  10588. WINAPI
  10589. CertGetIntendedKeyUsage(
  10590. IN DWORD dwCertEncodingType,
  10591. IN PCERT_INFO pCertInfo,
  10592. OUT BYTE *pbKeyUsage,
  10593. IN DWORD cbKeyUsage
  10594. );
  10595. typedef void *HCRYPTDEFAULTCONTEXT;
  10596. //+-------------------------------------------------------------------------
  10597. // Install a previously CryptAcquiredContext'ed HCRYPTPROV to be used as
  10598. // a default context.
  10599. //
  10600. // dwDefaultType and pvDefaultPara specify where the default context is used.
  10601. // For example, install the HCRYPTPROV to be used to verify certificate's
  10602. // having szOID_OIWSEC_md5RSA signatures.
  10603. //
  10604. // By default, the installed HCRYPTPROV is only applicable to the current
  10605. // thread. Set CRYPT_DEFAULT_CONTEXT_PROCESS_FLAG to allow the HCRYPTPROV
  10606. // to be used by all threads in the current process.
  10607. //
  10608. // For a successful install, TRUE is returned and *phDefaultContext is
  10609. // updated with the HANDLE to be passed to CryptUninstallDefaultContext.
  10610. //
  10611. // The installed HCRYPTPROVs are stack ordered (the last installed
  10612. // HCRYPTPROV is checked first). All thread installed HCRYPTPROVs are
  10613. // checked before any process HCRYPTPROVs.
  10614. //
  10615. // The installed HCRYPTPROV remains available for default usage until
  10616. // CryptUninstallDefaultContext is called or the thread or process exits.
  10617. //
  10618. // If CRYPT_DEFAULT_CONTEXT_AUTO_RELEASE_FLAG is set, then, the HCRYPTPROV
  10619. // is CryptReleaseContext'ed at thread or process exit. However,
  10620. // not CryptReleaseContext'ed if CryptUninstallDefaultContext is
  10621. // called.
  10622. //--------------------------------------------------------------------------
  10623. WINCRYPT32API
  10624. BOOL
  10625. WINAPI
  10626. CryptInstallDefaultContext(
  10627. IN HCRYPTPROV hCryptProv,
  10628. IN DWORD dwDefaultType,
  10629. IN const void *pvDefaultPara,
  10630. IN DWORD dwFlags,
  10631. IN void *pvReserved,
  10632. OUT HCRYPTDEFAULTCONTEXT *phDefaultContext
  10633. );
  10634. // dwFlags
  10635. #define CRYPT_DEFAULT_CONTEXT_AUTO_RELEASE_FLAG 0x00000001
  10636. #define CRYPT_DEFAULT_CONTEXT_PROCESS_FLAG 0x00000002
  10637. // List of dwDefaultType's
  10638. #define CRYPT_DEFAULT_CONTEXT_CERT_SIGN_OID 1
  10639. #define CRYPT_DEFAULT_CONTEXT_MULTI_CERT_SIGN_OID 2
  10640. //+-------------------------------------------------------------------------
  10641. // CRYPT_DEFAULT_CONTEXT_CERT_SIGN_OID
  10642. //
  10643. // Install a default HCRYPTPROV used to verify a certificate
  10644. // signature. pvDefaultPara points to the szOID of the certificate
  10645. // signature algorithm, for example, szOID_OIWSEC_md5RSA. If
  10646. // pvDefaultPara is NULL, then, the HCRYPTPROV is used to verify all
  10647. // certificate signatures. Note, pvDefaultPara can't be NULL when
  10648. // CRYPT_DEFAULT_CONTEXT_PROCESS_FLAG is set.
  10649. //--------------------------------------------------------------------------
  10650. //+-------------------------------------------------------------------------
  10651. // CRYPT_DEFAULT_CONTEXT_MULTI_CERT_SIGN_OID
  10652. //
  10653. // Same as CRYPT_DEFAULT_CONTEXT_CERT_SIGN_OID. However, the default
  10654. // HCRYPTPROV is to be used for multiple signature szOIDs. pvDefaultPara
  10655. // points to a CRYPT_DEFAULT_CONTEXT_MULTI_OID_PARA structure containing
  10656. // an array of szOID pointers.
  10657. //--------------------------------------------------------------------------
  10658. typedef struct _CRYPT_DEFAULT_CONTEXT_MULTI_OID_PARA {
  10659. DWORD cOID;
  10660. LPSTR *rgpszOID;
  10661. } CRYPT_DEFAULT_CONTEXT_MULTI_OID_PARA, *PCRYPT_DEFAULT_CONTEXT_MULTI_OID_PARA;
  10662. //+-------------------------------------------------------------------------
  10663. // Uninstall a default context previously installed by
  10664. // CryptInstallDefaultContext.
  10665. //
  10666. // For a default context installed with CRYPT_DEFAULT_CONTEXT_PROCESS_FLAG
  10667. // set, if any other threads are currently using this context,
  10668. // this function will block until they finish.
  10669. //--------------------------------------------------------------------------
  10670. WINCRYPT32API
  10671. BOOL
  10672. WINAPI
  10673. CryptUninstallDefaultContext(
  10674. HCRYPTDEFAULTCONTEXT hDefaultContext,
  10675. IN DWORD dwFlags,
  10676. IN void *pvReserved
  10677. );
  10678. //+-------------------------------------------------------------------------
  10679. // Export the public key info associated with the provider's corresponding
  10680. // private key.
  10681. //
  10682. // Calls CryptExportPublicKeyInfoEx with pszPublicKeyObjId = NULL,
  10683. // dwFlags = 0 and pvAuxInfo = NULL.
  10684. //--------------------------------------------------------------------------
  10685. WINCRYPT32API
  10686. BOOL
  10687. WINAPI
  10688. CryptExportPublicKeyInfo(
  10689. IN HCRYPTPROV hCryptProv,
  10690. IN DWORD dwKeySpec,
  10691. IN DWORD dwCertEncodingType,
  10692. OUT PCERT_PUBLIC_KEY_INFO pInfo,
  10693. IN OUT DWORD *pcbInfo
  10694. );
  10695. //+-------------------------------------------------------------------------
  10696. // Export the public key info associated with the provider's corresponding
  10697. // private key.
  10698. //
  10699. // Uses the dwCertEncodingType and pszPublicKeyObjId to call the
  10700. // installable CRYPT_OID_EXPORT_PUBLIC_KEY_INFO_FUNC. The called function
  10701. // has the same signature as CryptExportPublicKeyInfoEx.
  10702. //
  10703. // If unable to find an installable OID function for the pszPublicKeyObjId,
  10704. // attempts to export as a RSA Public Key (szOID_RSA_RSA).
  10705. //
  10706. // The dwFlags and pvAuxInfo aren't used for szOID_RSA_RSA.
  10707. //--------------------------------------------------------------------------
  10708. #define CRYPT_OID_EXPORT_PUBLIC_KEY_INFO_FUNC "CryptDllExportPublicKeyInfoEx"
  10709. WINCRYPT32API
  10710. BOOL
  10711. WINAPI
  10712. CryptExportPublicKeyInfoEx(
  10713. IN HCRYPTPROV hCryptProv,
  10714. IN DWORD dwKeySpec,
  10715. IN DWORD dwCertEncodingType,
  10716. IN LPSTR pszPublicKeyObjId,
  10717. IN DWORD dwFlags,
  10718. IN OPTIONAL void *pvAuxInfo,
  10719. OUT PCERT_PUBLIC_KEY_INFO pInfo,
  10720. IN OUT DWORD *pcbInfo
  10721. );
  10722. //+-------------------------------------------------------------------------
  10723. // Convert and import the public key info into the provider and return a
  10724. // handle to the public key.
  10725. //
  10726. // Calls CryptImportPublicKeyInfoEx with aiKeyAlg = 0, dwFlags = 0 and
  10727. // pvAuxInfo = NULL.
  10728. //--------------------------------------------------------------------------
  10729. WINCRYPT32API
  10730. BOOL
  10731. WINAPI
  10732. CryptImportPublicKeyInfo(
  10733. IN HCRYPTPROV hCryptProv,
  10734. IN DWORD dwCertEncodingType,
  10735. IN PCERT_PUBLIC_KEY_INFO pInfo,
  10736. OUT HCRYPTKEY *phKey
  10737. );
  10738. //+-------------------------------------------------------------------------
  10739. // Convert and import the public key info into the provider and return a
  10740. // handle to the public key.
  10741. //
  10742. // Uses the dwCertEncodingType and pInfo->Algorithm.pszObjId to call the
  10743. // installable CRYPT_OID_IMPORT_PUBLIC_KEY_INFO_FUNC. The called function
  10744. // has the same signature as CryptImportPublicKeyInfoEx.
  10745. //
  10746. // If unable to find an installable OID function for the pszObjId,
  10747. // attempts to import as a RSA Public Key (szOID_RSA_RSA).
  10748. //
  10749. // For szOID_RSA_RSA: aiKeyAlg may be set to CALG_RSA_SIGN or CALG_RSA_KEYX.
  10750. // Defaults to CALG_RSA_KEYX. The dwFlags and pvAuxInfo aren't used.
  10751. //--------------------------------------------------------------------------
  10752. #define CRYPT_OID_IMPORT_PUBLIC_KEY_INFO_FUNC "CryptDllImportPublicKeyInfoEx"
  10753. WINCRYPT32API
  10754. BOOL
  10755. WINAPI
  10756. CryptImportPublicKeyInfoEx(
  10757. IN HCRYPTPROV hCryptProv,
  10758. IN DWORD dwCertEncodingType,
  10759. IN PCERT_PUBLIC_KEY_INFO pInfo,
  10760. IN ALG_ID aiKeyAlg,
  10761. IN DWORD dwFlags,
  10762. IN OPTIONAL void *pvAuxInfo,
  10763. OUT HCRYPTKEY *phKey
  10764. );
  10765. //+-------------------------------------------------------------------------
  10766. // Acquire a HCRYPTPROV handle and dwKeySpec for the specified certificate
  10767. // context. Uses the certificate's CERT_KEY_PROV_INFO_PROP_ID property.
  10768. // The returned HCRYPTPROV handle may optionally be cached using the
  10769. // certificate's CERT_KEY_CONTEXT_PROP_ID property.
  10770. //
  10771. // If CRYPT_ACQUIRE_CACHE_FLAG is set, then, if an already acquired and
  10772. // cached HCRYPTPROV exists for the certificate, its returned. Otherwise,
  10773. // a HCRYPTPROV is acquired and then cached via the certificate's
  10774. // CERT_KEY_CONTEXT_PROP_ID.
  10775. //
  10776. // The CRYPT_ACQUIRE_USE_PROV_INFO_FLAG can be set to use the dwFlags field of
  10777. // the certificate's CERT_KEY_PROV_INFO_PROP_ID property's CRYPT_KEY_PROV_INFO
  10778. // data structure to determine if the returned HCRYPTPROV should be cached.
  10779. // HCRYPTPROV caching is enabled if the CERT_SET_KEY_CONTEXT_PROP_ID flag was
  10780. // set.
  10781. //
  10782. // If CRYPT_ACQUIRE_COMPARE_KEY_FLAG is set, then,
  10783. // the public key in the certificate is compared with the public
  10784. // key returned by the cryptographic provider. If the keys don't match, the
  10785. // acquire fails and LastError is set to NTE_BAD_PUBLIC_KEY. Note, if
  10786. // a cached HCRYPTPROV is returned, the comparison isn't done. We assume the
  10787. // comparison was done on the initial acquire.
  10788. //
  10789. // The CRYPT_ACQUIRE_SILENT_FLAG can be set to suppress any UI by the CSP.
  10790. // See CryptAcquireContext's CRYPT_SILENT flag for more details.
  10791. //
  10792. // *pfCallerFreeProv is returned set to FALSE for:
  10793. // - Acquire or public key comparison fails.
  10794. // - CRYPT_ACQUIRE_CACHE_FLAG is set.
  10795. // - CRYPT_ACQUIRE_USE_PROV_INFO_FLAG is set AND
  10796. // CERT_SET_KEY_CONTEXT_PROP_ID flag is set in the dwFlags field of the
  10797. // certificate's CERT_KEY_PROV_INFO_PROP_ID property's
  10798. // CRYPT_KEY_PROV_INFO data structure.
  10799. // When *pfCallerFreeProv is FALSE, the caller must not release. The
  10800. // returned HCRYPTPROV will be released on the last free of the certificate
  10801. // context.
  10802. //
  10803. // Otherwise, *pfCallerFreeProv is TRUE and the returned HCRYPTPROV must
  10804. // be released by the caller by calling CryptReleaseContext.
  10805. //--------------------------------------------------------------------------
  10806. WINCRYPT32API
  10807. BOOL
  10808. WINAPI
  10809. CryptAcquireCertificatePrivateKey(
  10810. IN PCCERT_CONTEXT pCert,
  10811. IN DWORD dwFlags,
  10812. IN void *pvReserved,
  10813. OUT HCRYPTPROV *phCryptProv,
  10814. OUT OPTIONAL DWORD *pdwKeySpec,
  10815. OUT OPTIONAL BOOL *pfCallerFreeProv
  10816. );
  10817. #define CRYPT_ACQUIRE_CACHE_FLAG 0x00000001
  10818. #define CRYPT_ACQUIRE_USE_PROV_INFO_FLAG 0x00000002
  10819. #define CRYPT_ACQUIRE_COMPARE_KEY_FLAG 0x00000004
  10820. #define CRYPT_ACQUIRE_SILENT_FLAG 0x00000040
  10821. //+-------------------------------------------------------------------------
  10822. // Enumerates the cryptographic providers and their containers to find the
  10823. // private key corresponding to the certificate's public key. For a match,
  10824. // the certificate's CERT_KEY_PROV_INFO_PROP_ID property is updated.
  10825. //
  10826. // If the CERT_KEY_PROV_INFO_PROP_ID is already set, then, its checked to
  10827. // see if it matches the provider's public key. For a match, the above
  10828. // enumeration is skipped.
  10829. //
  10830. // By default both the user and machine key containers are searched.
  10831. // The CRYPT_FIND_USER_KEYSET_FLAG or CRYPT_FIND_MACHINE_KEYSET_FLAG
  10832. // can be set in dwFlags to restrict the search to either of the containers.
  10833. //
  10834. // The CRYPT_FIND_SILENT_KEYSET_FLAG can be set to suppress any UI by the CSP.
  10835. // See CryptAcquireContext's CRYPT_SILENT flag for more details.
  10836. //
  10837. // If a container isn't found, returns FALSE with LastError set to
  10838. // NTE_NO_KEY.
  10839. //--------------------------------------------------------------------------
  10840. WINCRYPT32API
  10841. BOOL
  10842. WINAPI
  10843. CryptFindCertificateKeyProvInfo(
  10844. IN PCCERT_CONTEXT pCert,
  10845. IN DWORD dwFlags,
  10846. IN void *pvReserved
  10847. );
  10848. #define CRYPT_FIND_USER_KEYSET_FLAG 0x00000001
  10849. #define CRYPT_FIND_MACHINE_KEYSET_FLAG 0x00000002
  10850. #define CRYPT_FIND_SILENT_KEYSET_FLAG 0x00000040
  10851. //+-------------------------------------------------------------------------
  10852. // This is the prototype for the installable function which is called to
  10853. // actually import a key into a CSP. an installable of this type is called
  10854. // from CryptImportPKCS8. the algorithm OID of the private key is used
  10855. // to look up the proper installable function to call.
  10856. //
  10857. // hCryptProv - the provider to import the key to
  10858. // pPrivateKeyInfo - describes the key to be imported
  10859. // dwFlags - The available flags are:
  10860. // CRYPT_EXPORTABLE
  10861. // this flag is used when importing private keys, for a full
  10862. // explanation please see the documentation for CryptImportKey.
  10863. // pvAuxInfo - reserved for future, must be NULL
  10864. //--------------------------------------------------------------------------
  10865. typedef BOOL (WINAPI *PFN_IMPORT_PRIV_KEY_FUNC) (
  10866. HCRYPTPROV hCryptProv, // in
  10867. CRYPT_PRIVATE_KEY_INFO *pPrivateKeyInfo, // in
  10868. DWORD dwFlags, // in, optional
  10869. void *pvAuxInfo // in, optional
  10870. );
  10871. #define CRYPT_OID_IMPORT_PRIVATE_KEY_INFO_FUNC "CryptDllImportPrivateKeyInfoEx"
  10872. //+-------------------------------------------------------------------------
  10873. // Convert (from PKCS8 format) and import the private key into a provider
  10874. // and return a handle to the provider as well as the KeySpec used to import to.
  10875. //
  10876. // This function will call the PRESOLVE_HCRYPTPROV_FUNC in the
  10877. // privateKeyAndParams to obtain a handle of provider to import the key to.
  10878. // if the PRESOLVE_HCRYPTPROV_FUNC is NULL then the default provider will be used.
  10879. //
  10880. // privateKeyAndParams - private key blob and corresponding parameters
  10881. // dwFlags - The available flags are:
  10882. // CRYPT_EXPORTABLE
  10883. // this flag is used when importing private keys, for a full
  10884. // explanation please see the documentation for CryptImportKey.
  10885. // phCryptProv - filled in with the handle of the provider the key was
  10886. // imported to, the caller is responsible for freeing it
  10887. // pvAuxInfo - This parameter is reserved for future use and should be set
  10888. // to NULL in the interim.
  10889. //--------------------------------------------------------------------------
  10890. WINCRYPT32API
  10891. BOOL
  10892. WINAPI
  10893. CryptImportPKCS8(
  10894. CRYPT_PKCS8_IMPORT_PARAMS sImportParams, // in
  10895. DWORD dwFlags, // in, optional
  10896. HCRYPTPROV *phCryptProv, // out, optional
  10897. void *pvAuxInfo // in, optional
  10898. );
  10899. //+-------------------------------------------------------------------------
  10900. // this is the prototype for installable functions for exporting the private key
  10901. //--------------------------------------------------------------------------
  10902. typedef BOOL (WINAPI *PFN_EXPORT_PRIV_KEY_FUNC) (
  10903. HCRYPTPROV hCryptProv, // in
  10904. DWORD dwKeySpec, // in
  10905. LPSTR pszPrivateKeyObjId, // in
  10906. DWORD dwFlags, // in
  10907. void *pvAuxInfo, // in
  10908. CRYPT_PRIVATE_KEY_INFO *pPrivateKeyInfo, // out
  10909. DWORD *pcbPrivateKeyBlob // in, out
  10910. );
  10911. #define CRYPT_OID_EXPORT_PRIVATE_KEY_INFO_FUNC "CryptDllExportPrivateKeyInfoEx"
  10912. #define CRYPT_DELETE_KEYSET 0x0001
  10913. //+-------------------------------------------------------------------------
  10914. // CryptExportPKCS8 -- superseded by CryptExportPKCS8Ex
  10915. //
  10916. // Export the private key in PKCS8 format
  10917. //--------------------------------------------------------------------------
  10918. WINCRYPT32API
  10919. BOOL
  10920. WINAPI
  10921. CryptExportPKCS8(
  10922. HCRYPTPROV hCryptProv, // in
  10923. DWORD dwKeySpec, // in
  10924. LPSTR pszPrivateKeyObjId, // in
  10925. DWORD dwFlags, // in
  10926. void *pvAuxInfo, // in
  10927. BYTE *pbPrivateKeyBlob, // out
  10928. DWORD *pcbPrivateKeyBlob // in, out
  10929. );
  10930. //+-------------------------------------------------------------------------
  10931. // CryptExportPKCS8Ex
  10932. //
  10933. // Export the private key in PKCS8 format
  10934. //
  10935. //
  10936. // Uses the pszPrivateKeyObjId to call the
  10937. // installable CRYPT_OID_EXPORT_PRIVATE_KEY_INFO_FUNC. The called function
  10938. // has the signature defined by PFN_EXPORT_PRIV_KEY_FUNC.
  10939. //
  10940. // If unable to find an installable OID function for the pszPrivateKeyObjId,
  10941. // attempts to export as a RSA Private Key (szOID_RSA_RSA).
  10942. //
  10943. // psExportParams - specifies information about the key to export
  10944. // dwFlags - The flag values. None currently supported
  10945. // pvAuxInfo - This parameter is reserved for future use and should be set to
  10946. // NULL in the interim.
  10947. // pbPrivateKeyBlob - A pointer to the private key blob. It will be encoded
  10948. // as a PKCS8 PrivateKeyInfo.
  10949. // pcbPrivateKeyBlob - A pointer to a DWORD that contains the size, in bytes,
  10950. // of the private key blob being exported.
  10951. //+-------------------------------------------------------------------------
  10952. WINCRYPT32API
  10953. BOOL
  10954. WINAPI
  10955. CryptExportPKCS8Ex(
  10956. CRYPT_PKCS8_EXPORT_PARAMS* psExportParams, // in
  10957. DWORD dwFlags, // in
  10958. void *pvAuxInfo, // in
  10959. BYTE *pbPrivateKeyBlob, // out
  10960. DWORD *pcbPrivateKeyBlob // in, out
  10961. );
  10962. //+-------------------------------------------------------------------------
  10963. // Compute the hash of the encoded public key info.
  10964. //
  10965. // The public key info is encoded and then hashed.
  10966. //--------------------------------------------------------------------------
  10967. WINCRYPT32API
  10968. BOOL
  10969. WINAPI
  10970. CryptHashPublicKeyInfo(
  10971. IN HCRYPTPROV hCryptProv,
  10972. IN ALG_ID Algid,
  10973. IN DWORD dwFlags,
  10974. IN DWORD dwCertEncodingType,
  10975. IN PCERT_PUBLIC_KEY_INFO pInfo,
  10976. OUT BYTE *pbComputedHash,
  10977. IN OUT DWORD *pcbComputedHash
  10978. );
  10979. //+-------------------------------------------------------------------------
  10980. // Convert a Name Value to a null terminated char string
  10981. //
  10982. // Returns the number of characters converted including the terminating null
  10983. // character. If psz is NULL or csz is 0, returns the required size of the
  10984. // destination string (including the terminating null char).
  10985. //
  10986. // If psz != NULL && csz != 0, returned psz is always NULL terminated.
  10987. //
  10988. // Note: csz includes the NULL char.
  10989. //--------------------------------------------------------------------------
  10990. WINCRYPT32API
  10991. DWORD
  10992. WINAPI
  10993. CertRDNValueToStrA(
  10994. IN DWORD dwValueType,
  10995. IN PCERT_RDN_VALUE_BLOB pValue,
  10996. OUT OPTIONAL LPSTR psz,
  10997. IN DWORD csz
  10998. );
  10999. //+-------------------------------------------------------------------------
  11000. // Convert a Name Value to a null terminated char string
  11001. //
  11002. // Returns the number of characters converted including the terminating null
  11003. // character. If psz is NULL or csz is 0, returns the required size of the
  11004. // destination string (including the terminating null char).
  11005. //
  11006. // If psz != NULL && csz != 0, returned psz is always NULL terminated.
  11007. //
  11008. // Note: csz includes the NULL char.
  11009. //--------------------------------------------------------------------------
  11010. WINCRYPT32API
  11011. DWORD
  11012. WINAPI
  11013. CertRDNValueToStrW(
  11014. IN DWORD dwValueType,
  11015. IN PCERT_RDN_VALUE_BLOB pValue,
  11016. OUT OPTIONAL LPWSTR psz,
  11017. IN DWORD csz
  11018. );
  11019. #ifdef UNICODE
  11020. #define CertRDNValueToStr CertRDNValueToStrW
  11021. #else
  11022. #define CertRDNValueToStr CertRDNValueToStrA
  11023. #endif // !UNICODE
  11024. //+-------------------------------------------------------------------------
  11025. // Convert the certificate name blob to a null terminated char string.
  11026. //
  11027. // Follows the string representation of distinguished names specified in
  11028. // RFC 1779. (Note, added double quoting "" for embedded quotes, quote
  11029. // empty strings and don't quote strings containing consecutive spaces).
  11030. // RDN values of type CERT_RDN_ENCODED_BLOB or CERT_RDN_OCTET_STRING are
  11031. // formatted in hexadecimal (e.g. #0A56CF).
  11032. //
  11033. // The name string is formatted according to the dwStrType:
  11034. // CERT_SIMPLE_NAME_STR
  11035. // The object identifiers are discarded. CERT_RDN entries are separated
  11036. // by ", ". Multiple attributes per CERT_RDN are separated by " + ".
  11037. // For example:
  11038. // Microsoft, Joe Cool + Programmer
  11039. // CERT_OID_NAME_STR
  11040. // The object identifiers are included with a "=" separator from their
  11041. // attribute value. CERT_RDN entries are separated by ", ".
  11042. // Multiple attributes per CERT_RDN are separated by " + ". For example:
  11043. // 2.5.4.11=Microsoft, 2.5.4.3=Joe Cool + 2.5.4.12=Programmer
  11044. // CERT_X500_NAME_STR
  11045. // The object identifiers are converted to their X500 key name. Otherwise,
  11046. // same as CERT_OID_NAME_STR. If the object identifier doesn't have
  11047. // a corresponding X500 key name, then, the object identifier is used with
  11048. // a "OID." prefix. For example:
  11049. // OU=Microsoft, CN=Joe Cool + T=Programmer, OID.1.2.3.4.5.6=Unknown
  11050. //
  11051. // We quote the RDN value if it contains leading or trailing whitespace
  11052. // or one of the following characters: ",", "+", "=", """, "\n", "<", ">",
  11053. // "#" or ";". The quoting character is ". If the the RDN Value contains
  11054. // a " it is double quoted (""). For example:
  11055. // OU=" Microsoft", CN="Joe ""Cool""" + T="Programmer, Manager"
  11056. //
  11057. // CERT_NAME_STR_SEMICOLON_FLAG can be or'ed into dwStrType to replace
  11058. // the ", " separator with a "; " separator.
  11059. //
  11060. // CERT_NAME_STR_CRLF_FLAG can be or'ed into dwStrType to replace
  11061. // the ", " separator with a "\r\n" separator.
  11062. //
  11063. // CERT_NAME_STR_NO_PLUS_FLAG can be or'ed into dwStrType to replace the
  11064. // " + " separator with a single space, " ".
  11065. //
  11066. // CERT_NAME_STR_NO_QUOTING_FLAG can be or'ed into dwStrType to inhibit
  11067. // the above quoting.
  11068. //
  11069. // CERT_NAME_STR_REVERSE_FLAG can be or'ed into dwStrType to reverse the
  11070. // order of the RDNs before converting to the string.
  11071. //
  11072. // By default, CERT_RDN_T61_STRING encoded values are initially decoded
  11073. // as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  11074. // CERT_NAME_STR_DISABLE_IE4_UTF8_FLAG can be or'ed into dwStrType to
  11075. // skip the initial attempt to decode as UTF8.
  11076. //
  11077. // Returns the number of characters converted including the terminating null
  11078. // character. If psz is NULL or csz is 0, returns the required size of the
  11079. // destination string (including the terminating null char).
  11080. //
  11081. // If psz != NULL && csz != 0, returned psz is always NULL terminated.
  11082. //
  11083. // Note: csz includes the NULL char.
  11084. //--------------------------------------------------------------------------
  11085. //+-------------------------------------------------------------------------
  11086. //--------------------------------------------------------------------------
  11087. WINCRYPT32API
  11088. DWORD
  11089. WINAPI
  11090. CertNameToStrA(
  11091. IN DWORD dwCertEncodingType,
  11092. IN PCERT_NAME_BLOB pName,
  11093. IN DWORD dwStrType,
  11094. OUT OPTIONAL LPSTR psz,
  11095. IN DWORD csz
  11096. );
  11097. //+-------------------------------------------------------------------------
  11098. //--------------------------------------------------------------------------
  11099. WINCRYPT32API
  11100. DWORD
  11101. WINAPI
  11102. CertNameToStrW(
  11103. IN DWORD dwCertEncodingType,
  11104. IN PCERT_NAME_BLOB pName,
  11105. IN DWORD dwStrType,
  11106. OUT OPTIONAL LPWSTR psz,
  11107. IN DWORD csz
  11108. );
  11109. #ifdef UNICODE
  11110. #define CertNameToStr CertNameToStrW
  11111. #else
  11112. #define CertNameToStr CertNameToStrA
  11113. #endif // !UNICODE
  11114. //+-------------------------------------------------------------------------
  11115. // Certificate name string types
  11116. //--------------------------------------------------------------------------
  11117. #define CERT_SIMPLE_NAME_STR 1
  11118. #define CERT_OID_NAME_STR 2
  11119. #define CERT_X500_NAME_STR 3
  11120. //+-------------------------------------------------------------------------
  11121. // Certificate name string type flags OR'ed with the above types
  11122. //--------------------------------------------------------------------------
  11123. #define CERT_NAME_STR_SEMICOLON_FLAG 0x40000000
  11124. #define CERT_NAME_STR_NO_PLUS_FLAG 0x20000000
  11125. #define CERT_NAME_STR_NO_QUOTING_FLAG 0x10000000
  11126. #define CERT_NAME_STR_CRLF_FLAG 0x08000000
  11127. #define CERT_NAME_STR_COMMA_FLAG 0x04000000
  11128. #define CERT_NAME_STR_REVERSE_FLAG 0x02000000
  11129. #define CERT_NAME_STR_DISABLE_IE4_UTF8_FLAG 0x00010000
  11130. #define CERT_NAME_STR_ENABLE_T61_UNICODE_FLAG 0x00020000
  11131. #define CERT_NAME_STR_ENABLE_UTF8_UNICODE_FLAG 0x00040000
  11132. //+-------------------------------------------------------------------------
  11133. // Convert the null terminated X500 string to an encoded certificate name.
  11134. //
  11135. // The input string is expected to be formatted the same as the output
  11136. // from the above CertNameToStr API.
  11137. //
  11138. // The CERT_SIMPLE_NAME_STR type isn't supported. Otherwise, when dwStrType
  11139. // is set to 0, CERT_OID_NAME_STR or CERT_X500_NAME_STR, allow either a
  11140. // case insensitive X500 key (CN=), case insensitive "OID." prefixed
  11141. // object identifier (OID.1.2.3.4.5.6=) or an object identifier (1.2.3.4=).
  11142. //
  11143. // If no flags are OR'ed into dwStrType, then, allow "," or ";" as RDN
  11144. // separators and "+" as the multiple RDN value separator. Quoting is
  11145. // supported. A quote may be included in a quoted value by double quoting,
  11146. // for example (CN="Joe ""Cool"""). A value starting with a "#" is treated
  11147. // as ascii hex and converted to a CERT_RDN_OCTET_STRING. Embedded whitespace
  11148. // is skipped (1.2.3 = # AB CD 01 is the same as 1.2.3=#ABCD01).
  11149. //
  11150. // Whitespace surrounding the keys, object identifers and values is removed.
  11151. //
  11152. // CERT_NAME_STR_COMMA_FLAG can be or'ed into dwStrType to only allow the
  11153. // "," as the RDN separator.
  11154. //
  11155. // CERT_NAME_STR_SEMICOLON_FLAG can be or'ed into dwStrType to only allow the
  11156. // ";" as the RDN separator.
  11157. //
  11158. // CERT_NAME_STR_CRLF_FLAG can be or'ed into dwStrType to only allow
  11159. // "\r" or "\n" as the RDN separator.
  11160. //
  11161. // CERT_NAME_STR_NO_PLUS_FLAG can be or'ed into dwStrType to ignore "+"
  11162. // as a separator and not allow multiple values per RDN.
  11163. //
  11164. // CERT_NAME_STR_NO_QUOTING_FLAG can be or'ed into dwStrType to inhibit
  11165. // quoting.
  11166. //
  11167. // CERT_NAME_STR_REVERSE_FLAG can be or'ed into dwStrType to reverse the
  11168. // order of the RDNs after converting from the string and before encoding.
  11169. //
  11170. // CERT_NAME_STR_ENABLE_T61_UNICODE_FLAG can be or'ed into dwStrType to
  11171. // to select the CERT_RDN_T61_STRING encoded value type instead of
  11172. // CERT_RDN_UNICODE_STRING if all the UNICODE characters are <= 0xFF.
  11173. //
  11174. // CERT_NAME_STR_ENABLE_UTF8_UNICODE_FLAG can be or'ed into dwStrType to
  11175. // to select the CERT_RDN_UTF8_STRING encoded value type instead of
  11176. // CERT_RDN_UNICODE_STRING.
  11177. //
  11178. // Support the following X500 Keys:
  11179. //
  11180. // Key Object Identifier RDN Value Type(s)
  11181. // --- ----------------- -----------------
  11182. // CN szOID_COMMON_NAME Printable, Unicode
  11183. // L szOID_LOCALITY_NAME Printable, Unicode
  11184. // O szOID_ORGANIZATION_NAME Printable, Unicode
  11185. // OU szOID_ORGANIZATIONAL_UNIT_NAME Printable, Unicode
  11186. // E szOID_RSA_emailAddr Only IA5
  11187. // Email szOID_RSA_emailAddr Only IA5
  11188. // C szOID_COUNTRY_NAME Only Printable
  11189. // S szOID_STATE_OR_PROVINCE_NAME Printable, Unicode
  11190. // ST szOID_STATE_OR_PROVINCE_NAME Printable, Unicode
  11191. // STREET szOID_STREET_ADDRESS Printable, Unicode
  11192. // T szOID_TITLE Printable, Unicode
  11193. // Title szOID_TITLE Printable, Unicode
  11194. // G szOID_GIVEN_NAME Printable, Unicode
  11195. // GivenName szOID_GIVEN_NAME Printable, Unicode
  11196. // I szOID_INITIALS Printable, Unicode
  11197. // Initials szOID_INITIALS Printable, Unicode
  11198. // SN szOID_SUR_NAME Printable, Unicode
  11199. // DC szOID_DOMAIN_COMPONENT IA5, UTF8
  11200. //
  11201. // Note, T61 is selected instead of Unicode if
  11202. // CERT_NAME_STR_ENABLE_T61_UNICODE_FLAG is set and all the unicode
  11203. // characters are <= 0xFF.
  11204. //
  11205. // Note, UTF8 is selected instead of Unicode if
  11206. // CERT_NAME_STR_ENABLE_UTF8_UNICODE_FLAG is set.
  11207. //
  11208. // Returns TRUE if successfully parsed the input string and encoded
  11209. // the name.
  11210. //
  11211. // If the input string is detected to be invalid, *ppszError is updated
  11212. // to point to the beginning of the invalid character sequence. Otherwise,
  11213. // *ppszError is set to NULL. *ppszError is updated with a non-NULL pointer
  11214. // for the following errors:
  11215. // CRYPT_E_INVALID_X500_STRING
  11216. // CRYPT_E_INVALID_NUMERIC_STRING
  11217. // CRYPT_E_INVALID_PRINTABLE_STRING
  11218. // CRYPT_E_INVALID_IA5_STRING
  11219. //
  11220. // ppszError can be set to NULL if not interested in getting a pointer
  11221. // to the invalid character sequence.
  11222. //--------------------------------------------------------------------------
  11223. //+-------------------------------------------------------------------------
  11224. //--------------------------------------------------------------------------
  11225. WINCRYPT32API
  11226. BOOL
  11227. WINAPI
  11228. CertStrToNameA(
  11229. IN DWORD dwCertEncodingType,
  11230. IN LPCSTR pszX500,
  11231. IN DWORD dwStrType,
  11232. IN OPTIONAL void *pvReserved,
  11233. OUT BYTE *pbEncoded,
  11234. IN OUT DWORD *pcbEncoded,
  11235. OUT OPTIONAL LPCSTR *ppszError
  11236. );
  11237. //+-------------------------------------------------------------------------
  11238. //--------------------------------------------------------------------------
  11239. WINCRYPT32API
  11240. BOOL
  11241. WINAPI
  11242. CertStrToNameW(
  11243. IN DWORD dwCertEncodingType,
  11244. IN LPCWSTR pszX500,
  11245. IN DWORD dwStrType,
  11246. IN OPTIONAL void *pvReserved,
  11247. OUT BYTE *pbEncoded,
  11248. IN OUT DWORD *pcbEncoded,
  11249. OUT OPTIONAL LPCWSTR *ppszError
  11250. );
  11251. #ifdef UNICODE
  11252. #define CertStrToName CertStrToNameW
  11253. #else
  11254. #define CertStrToName CertStrToNameA
  11255. #endif // !UNICODE
  11256. //+-------------------------------------------------------------------------
  11257. // Get the subject or issuer name from the certificate and
  11258. // according to the specified format type, convert to a null terminated
  11259. // character string.
  11260. //
  11261. // CERT_NAME_ISSUER_FLAG can be set to get the issuer's name. Otherwise,
  11262. // gets the subject's name.
  11263. //
  11264. // By default, CERT_RDN_T61_STRING encoded values are initially decoded
  11265. // as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  11266. // CERT_NAME_DISABLE_IE4_UTF8_FLAG can be set in dwFlags to
  11267. // skip the initial attempt to decode as UTF8.
  11268. //
  11269. // The name string is formatted according to the dwType:
  11270. // CERT_NAME_EMAIL_TYPE
  11271. // If the certificate has a Subject Alternative Name extension (for
  11272. // issuer, Issuer Alternative Name), searches for first rfc822Name choice.
  11273. // If the rfc822Name choice isn't found in the extension, searches the
  11274. // Subject Name field for the Email OID, "1.2.840.113549.1.9.1".
  11275. // If the rfc822Name or Email OID is found, returns the string. Otherwise,
  11276. // returns an empty string (returned character count is 1).
  11277. // CERT_NAME_DNS_TYPE
  11278. // If the certificate has a Subject Alternative Name extension (for
  11279. // issuer, Issuer Alternative Name), searches for first DNSName choice.
  11280. // If the DNSName choice isn't found in the extension, searches the
  11281. // Subject Name field for the CN OID, "2.5.4.3".
  11282. // If the DNSName or CN OID is found, returns the string. Otherwise,
  11283. // returns an empty string.
  11284. // CERT_NAME_URL_TYPE
  11285. // If the certificate has a Subject Alternative Name extension (for
  11286. // issuer, Issuer Alternative Name), searches for first URL choice.
  11287. // If the URL choice is found, returns the string. Otherwise,
  11288. // returns an empty string.
  11289. // CERT_NAME_UPN_TYPE
  11290. // If the certificate has a Subject Alternative Name extension,
  11291. // searches the OtherName choices looking for a
  11292. // pszObjId == szOID_NT_PRINCIPAL_NAME, "1.3.6.1.4.1.311.20.2.3".
  11293. // If the UPN OID is found, the blob is decoded as a
  11294. // X509_UNICODE_ANY_STRING and the decoded string is returned.
  11295. // Otherwise, returns an empty string.
  11296. // CERT_NAME_RDN_TYPE
  11297. // Converts the Subject Name blob by calling CertNameToStr. pvTypePara
  11298. // points to a DWORD containing the dwStrType passed to CertNameToStr.
  11299. // If the Subject Name field is empty and the certificate has a
  11300. // Subject Alternative Name extension, searches for and converts
  11301. // the first directoryName choice.
  11302. // CERT_NAME_ATTR_TYPE
  11303. // pvTypePara points to the Object Identifier specifying the name attribute
  11304. // to be returned. For example, to get the CN,
  11305. // pvTypePara = szOID_COMMON_NAME ("2.5.4.3"). Searches, the Subject Name
  11306. // field for the attribute.
  11307. // If the Subject Name field is empty and the certificate has a
  11308. // Subject Alternative Name extension, checks for
  11309. // the first directoryName choice and searches it.
  11310. //
  11311. // Note, searches the RDNs in reverse order.
  11312. //
  11313. // CERT_NAME_SIMPLE_DISPLAY_TYPE
  11314. // Iterates through the following list of name attributes and searches
  11315. // the Subject Name and then the Subject Alternative Name extension
  11316. // for the first occurrence of:
  11317. // szOID_COMMON_NAME ("2.5.4.3")
  11318. // szOID_ORGANIZATIONAL_UNIT_NAME ("2.5.4.11")
  11319. // szOID_ORGANIZATION_NAME ("2.5.4.10")
  11320. // szOID_RSA_emailAddr ("1.2.840.113549.1.9.1")
  11321. //
  11322. // If none of the above attributes is found, then, searches the
  11323. // Subject Alternative Name extension for a rfc822Name choice.
  11324. //
  11325. // If still no match, then, returns the first attribute.
  11326. //
  11327. // Note, like CERT_NAME_ATTR_TYPE, searches the RDNs in reverse order.
  11328. //
  11329. // CERT_NAME_FRIENDLY_DISPLAY_TYPE
  11330. // First checks if the certificate has a CERT_FRIENDLY_NAME_PROP_ID
  11331. // property. If it does, then, this property is returned. Otherwise,
  11332. // returns the above CERT_NAME_SIMPLE_DISPLAY_TYPE.
  11333. //
  11334. // Returns the number of characters converted including the terminating null
  11335. // character. If pwszNameString is NULL or cchNameString is 0, returns the
  11336. // required size of the destination string (including the terminating null
  11337. // char). If the specified name type isn't found. returns an empty string
  11338. // with a returned character count of 1.
  11339. //
  11340. // If pwszNameString != NULL && cwszNameString != 0, returned pwszNameString
  11341. // is always NULL terminated.
  11342. //
  11343. // Note: cchNameString includes the NULL char.
  11344. //--------------------------------------------------------------------------
  11345. //+-------------------------------------------------------------------------
  11346. //--------------------------------------------------------------------------
  11347. WINCRYPT32API
  11348. DWORD
  11349. WINAPI
  11350. CertGetNameStringA(
  11351. IN PCCERT_CONTEXT pCertContext,
  11352. IN DWORD dwType,
  11353. IN DWORD dwFlags,
  11354. IN void *pvTypePara,
  11355. OUT OPTIONAL LPSTR pszNameString,
  11356. IN DWORD cchNameString
  11357. );
  11358. //+-------------------------------------------------------------------------
  11359. //--------------------------------------------------------------------------
  11360. WINCRYPT32API
  11361. DWORD
  11362. WINAPI
  11363. CertGetNameStringW(
  11364. IN PCCERT_CONTEXT pCertContext,
  11365. IN DWORD dwType,
  11366. IN DWORD dwFlags,
  11367. IN void *pvTypePara,
  11368. OUT OPTIONAL LPWSTR pszNameString,
  11369. IN DWORD cchNameString
  11370. );
  11371. #ifdef UNICODE
  11372. #define CertGetNameString CertGetNameStringW
  11373. #else
  11374. #define CertGetNameString CertGetNameStringA
  11375. #endif // !UNICODE
  11376. //+-------------------------------------------------------------------------
  11377. // Certificate name types
  11378. //--------------------------------------------------------------------------
  11379. #define CERT_NAME_EMAIL_TYPE 1
  11380. #define CERT_NAME_RDN_TYPE 2
  11381. #define CERT_NAME_ATTR_TYPE 3
  11382. #define CERT_NAME_SIMPLE_DISPLAY_TYPE 4
  11383. #define CERT_NAME_FRIENDLY_DISPLAY_TYPE 5
  11384. #define CERT_NAME_DNS_TYPE 6
  11385. #define CERT_NAME_URL_TYPE 7
  11386. #define CERT_NAME_UPN_TYPE 8
  11387. //+-------------------------------------------------------------------------
  11388. // Certificate name flags
  11389. //--------------------------------------------------------------------------
  11390. #define CERT_NAME_ISSUER_FLAG 0x1
  11391. #define CERT_NAME_DISABLE_IE4_UTF8_FLAG 0x00010000
  11392. //+=========================================================================
  11393. // Simplified Cryptographic Message Data Structures and APIs
  11394. //==========================================================================
  11395. //+-------------------------------------------------------------------------
  11396. // Conventions for the *pb and *pcb output parameters:
  11397. //
  11398. // Upon entry to the function:
  11399. // if pcb is OPTIONAL && pcb == NULL, then,
  11400. // No output is returned
  11401. // else if pb == NULL && pcb != NULL, then,
  11402. // Length only determination. No length error is
  11403. // returned.
  11404. // otherwise where (pb != NULL && pcb != NULL && *pcb != 0)
  11405. // Output is returned. If *pcb isn't big enough a
  11406. // length error is returned. In all cases *pcb is updated
  11407. // with the actual length needed/returned.
  11408. //--------------------------------------------------------------------------
  11409. //+-------------------------------------------------------------------------
  11410. // Type definitions of the parameters used for doing the cryptographic
  11411. // operations.
  11412. //--------------------------------------------------------------------------
  11413. //+-------------------------------------------------------------------------
  11414. // Callback to get and verify the signer's certificate.
  11415. //
  11416. // Passed the CertId of the signer (its Issuer and SerialNumber) and a
  11417. // handle to its cryptographic signed message's cert store.
  11418. //
  11419. // For CRYPT_E_NO_SIGNER, called with pSignerId == NULL.
  11420. //
  11421. // For a valid signer certificate, returns a pointer to a read only
  11422. // CERT_CONTEXT. The returned CERT_CONTEXT is either obtained from a
  11423. // cert store or was created via CertCreateCertificateContext. For either case,
  11424. // its freed via CertFreeCertificateContext.
  11425. //
  11426. // If a valid certificate isn't found, this callback returns NULL with
  11427. // LastError set via SetLastError().
  11428. //
  11429. // The NULL implementation tries to get the Signer certificate from the
  11430. // message cert store. It doesn't verify the certificate.
  11431. //
  11432. // Note, if the KEYID choice was selected for a CMS SignerId, then, the
  11433. // SerialNumber is 0 and the Issuer is encoded containing a single RDN with a
  11434. // single Attribute whose OID is szOID_KEYID_RDN, value type is
  11435. // CERT_RDN_OCTET_STRING and value is the KEYID. When the
  11436. // CertGetSubjectCertificateFromStore and
  11437. // CertFindCertificateInStore(CERT_FIND_SUBJECT_CERT) APIs see this
  11438. // special KEYID Issuer and SerialNumber, they do a KEYID match.
  11439. //--------------------------------------------------------------------------
  11440. typedef PCCERT_CONTEXT (WINAPI *PFN_CRYPT_GET_SIGNER_CERTIFICATE)(
  11441. IN void *pvGetArg,
  11442. IN DWORD dwCertEncodingType,
  11443. IN PCERT_INFO pSignerId, // Only the Issuer and SerialNumber
  11444. // fields have been updated
  11445. IN HCERTSTORE hMsgCertStore
  11446. );
  11447. //+-------------------------------------------------------------------------
  11448. // The CRYPT_SIGN_MESSAGE_PARA are used for signing messages using the
  11449. // specified signing certificate context.
  11450. //
  11451. // Either the CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_PROV_INFO_PROP_ID must
  11452. // be set for each rgpSigningCert[]. Either one specifies the private
  11453. // signature key to use.
  11454. //
  11455. // If any certificates and/or CRLs are to be included in the signed message,
  11456. // then, the MsgCert and MsgCrl parameters need to be updated. If the
  11457. // rgpSigningCerts are to be included, then, they must also be in the
  11458. // rgpMsgCert array.
  11459. //
  11460. // cbSize must be set to the sizeof(CRYPT_SIGN_MESSAGE_PARA) or else
  11461. // LastError will be updated with E_INVALIDARG.
  11462. //
  11463. // pvHashAuxInfo currently isn't used and must be set to NULL.
  11464. //
  11465. // dwFlags normally is set to 0. However, if the encoded output
  11466. // is to be a CMSG_SIGNED inner content of an outer cryptographic message,
  11467. // such as a CMSG_ENVELOPED, then, the CRYPT_MESSAGE_BARE_CONTENT_OUT_FLAG
  11468. // should be set. If not set, then it would be encoded as an inner content
  11469. // type of CMSG_DATA.
  11470. //
  11471. // dwInnerContentType is normally set to 0. It needs to be set if the
  11472. // ToBeSigned input is the encoded output of another cryptographic
  11473. // message, such as, an CMSG_ENVELOPED. When set, it's one of the cryptographic
  11474. // message types, for example, CMSG_ENVELOPED.
  11475. //
  11476. // If the inner content of a nested cryptographic message is data (CMSG_DATA
  11477. // the default), then, neither dwFlags or dwInnerContentType need to be set.
  11478. //
  11479. // For CMS messages, CRYPT_MESSAGE_ENCAPSULATED_CONTENT_OUT_FLAG may be
  11480. // set to encapsulate nonData inner content within an OCTET STRING.
  11481. //
  11482. // For CMS messages, CRYPT_MESSAGE_KEYID_SIGNER_FLAG may be set to identify
  11483. // signers by their Key Identifier and not their Issuer and Serial Number.
  11484. //
  11485. // The CRYPT_MESSAGE_SILENT_KEYSET_FLAG can be set to suppress any UI by the
  11486. // CSP. See CryptAcquireContext's CRYPT_SILENT flag for more details.
  11487. //
  11488. // If HashEncryptionAlgorithm is present and not NULL its used instead of
  11489. // the SigningCert's PublicKeyInfo.Algorithm.
  11490. //
  11491. // Note, for RSA, the hash encryption algorithm is normally the same as
  11492. // the public key algorithm. For DSA, the hash encryption algorithm is
  11493. // normally a DSS signature algorithm.
  11494. //
  11495. // pvHashEncryptionAuxInfo currently isn't used and must be set to NULL if
  11496. // present in the data structure.
  11497. //--------------------------------------------------------------------------
  11498. typedef struct _CRYPT_SIGN_MESSAGE_PARA {
  11499. DWORD cbSize;
  11500. DWORD dwMsgEncodingType;
  11501. PCCERT_CONTEXT pSigningCert;
  11502. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  11503. void *pvHashAuxInfo;
  11504. DWORD cMsgCert;
  11505. PCCERT_CONTEXT *rgpMsgCert;
  11506. DWORD cMsgCrl;
  11507. PCCRL_CONTEXT *rgpMsgCrl;
  11508. DWORD cAuthAttr;
  11509. PCRYPT_ATTRIBUTE rgAuthAttr;
  11510. DWORD cUnauthAttr;
  11511. PCRYPT_ATTRIBUTE rgUnauthAttr;
  11512. DWORD dwFlags;
  11513. DWORD dwInnerContentType;
  11514. #ifdef CRYPT_SIGN_MESSAGE_PARA_HAS_CMS_FIELDS
  11515. CRYPT_ALGORITHM_IDENTIFIER HashEncryptionAlgorithm;
  11516. void *pvHashEncryptionAuxInfo;
  11517. #endif
  11518. } CRYPT_SIGN_MESSAGE_PARA, *PCRYPT_SIGN_MESSAGE_PARA;
  11519. #define CRYPT_MESSAGE_BARE_CONTENT_OUT_FLAG 0x00000001
  11520. // When set, nonData type inner content is encapsulated within an
  11521. // OCTET STRING
  11522. #define CRYPT_MESSAGE_ENCAPSULATED_CONTENT_OUT_FLAG 0x00000002
  11523. // When set, signers are identified by their Key Identifier and not
  11524. // their Issuer and Serial Number.
  11525. #define CRYPT_MESSAGE_KEYID_SIGNER_FLAG 0x00000004
  11526. // When set, suppresses any UI by the CSP.
  11527. // See CryptAcquireContext's CRYPT_SILENT flag for more details.
  11528. #define CRYPT_MESSAGE_SILENT_KEYSET_FLAG 0x00000040
  11529. //+-------------------------------------------------------------------------
  11530. // The CRYPT_VERIFY_MESSAGE_PARA are used to verify signed messages.
  11531. //
  11532. // hCryptProv is used to do hashing and signature verification.
  11533. //
  11534. // The dwCertEncodingType specifies the encoding type of the certificates
  11535. // and/or CRLs in the message.
  11536. //
  11537. // pfnGetSignerCertificate is called to get and verify the message signer's
  11538. // certificate.
  11539. //
  11540. // cbSize must be set to the sizeof(CRYPT_VERIFY_MESSAGE_PARA) or else
  11541. // LastError will be updated with E_INVALIDARG.
  11542. //--------------------------------------------------------------------------
  11543. typedef struct _CRYPT_VERIFY_MESSAGE_PARA {
  11544. DWORD cbSize;
  11545. DWORD dwMsgAndCertEncodingType;
  11546. HCRYPTPROV hCryptProv;
  11547. PFN_CRYPT_GET_SIGNER_CERTIFICATE pfnGetSignerCertificate;
  11548. void *pvGetArg;
  11549. } CRYPT_VERIFY_MESSAGE_PARA, *PCRYPT_VERIFY_MESSAGE_PARA;
  11550. //+-------------------------------------------------------------------------
  11551. // The CRYPT_ENCRYPT_MESSAGE_PARA are used for encrypting messages.
  11552. //
  11553. // hCryptProv is used to do content encryption, recipient key
  11554. // encryption, and recipient key export. Its private key
  11555. // isn't used.
  11556. //
  11557. // Currently, pvEncryptionAuxInfo is only defined for RC2 or RC4 encryption
  11558. // algorithms. Otherwise, its not used and must be set to NULL.
  11559. // See CMSG_RC2_AUX_INFO for the RC2 encryption algorithms.
  11560. // See CMSG_RC4_AUX_INFO for the RC4 encryption algorithms.
  11561. //
  11562. // To enable SP3 compatible encryption, pvEncryptionAuxInfo should point to
  11563. // a CMSG_SP3_COMPATIBLE_AUX_INFO data structure.
  11564. //
  11565. // cbSize must be set to the sizeof(CRYPT_ENCRYPT_MESSAGE_PARA) or else
  11566. // LastError will be updated with E_INVALIDARG.
  11567. //
  11568. // dwFlags normally is set to 0. However, if the encoded output
  11569. // is to be a CMSG_ENVELOPED inner content of an outer cryptographic message,
  11570. // such as a CMSG_SIGNED, then, the CRYPT_MESSAGE_BARE_CONTENT_OUT_FLAG
  11571. // should be set. If not set, then it would be encoded as an inner content
  11572. // type of CMSG_DATA.
  11573. //
  11574. // dwInnerContentType is normally set to 0. It needs to be set if the
  11575. // ToBeEncrypted input is the encoded output of another cryptographic
  11576. // message, such as, an CMSG_SIGNED. When set, it's one of the cryptographic
  11577. // message types, for example, CMSG_SIGNED.
  11578. //
  11579. // If the inner content of a nested cryptographic message is data (CMSG_DATA
  11580. // the default), then, neither dwFlags or dwInnerContentType need to be set.
  11581. //
  11582. // For CMS messages, CRYPT_MESSAGE_ENCAPSULATED_CONTENT_OUT_FLAG may be
  11583. // set to encapsulate nonData inner content within an OCTET STRING before
  11584. // encrypting.
  11585. //
  11586. // For CMS messages, CRYPT_MESSAGE_KEYID_RECIPIENT_FLAG may be set to identify
  11587. // recipients by their Key Identifier and not their Issuer and Serial Number.
  11588. //--------------------------------------------------------------------------
  11589. typedef struct _CRYPT_ENCRYPT_MESSAGE_PARA {
  11590. DWORD cbSize;
  11591. DWORD dwMsgEncodingType;
  11592. HCRYPTPROV hCryptProv;
  11593. CRYPT_ALGORITHM_IDENTIFIER ContentEncryptionAlgorithm;
  11594. void *pvEncryptionAuxInfo;
  11595. DWORD dwFlags;
  11596. DWORD dwInnerContentType;
  11597. } CRYPT_ENCRYPT_MESSAGE_PARA, *PCRYPT_ENCRYPT_MESSAGE_PARA;
  11598. // When set, recipients are identified by their Key Identifier and not
  11599. // their Issuer and Serial Number.
  11600. #define CRYPT_MESSAGE_KEYID_RECIPIENT_FLAG 0x4
  11601. //+-------------------------------------------------------------------------
  11602. // The CRYPT_DECRYPT_MESSAGE_PARA are used for decrypting messages.
  11603. //
  11604. // The CertContext to use for decrypting a message is obtained from one
  11605. // of the specified cert stores. An encrypted message can have one or
  11606. // more recipients. The recipients are identified by their CertId (Issuer
  11607. // and SerialNumber). The cert stores are searched to find the CertContext
  11608. // corresponding to the CertId.
  11609. //
  11610. // For CMS, the recipients may also be identified by their KeyId.
  11611. // CMS also allows Key Agreement (Diffie Hellman) in addition to
  11612. // Key Transport (RSA) recipients.
  11613. //
  11614. // Only CertContexts in the store with either
  11615. // the CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_PROV_INFO_PROP_ID set
  11616. // can be used. Either property specifies the private exchange key to use.
  11617. //
  11618. // cbSize must be set to the sizeof(CRYPT_DECRYPT_MESSAGE_PARA) or else
  11619. // LastError will be updated with E_INVALIDARG.
  11620. //--------------------------------------------------------------------------
  11621. typedef struct _CRYPT_DECRYPT_MESSAGE_PARA {
  11622. DWORD cbSize;
  11623. DWORD dwMsgAndCertEncodingType;
  11624. DWORD cCertStore;
  11625. HCERTSTORE *rghCertStore;
  11626. #ifdef CRYPT_DECRYPT_MESSAGE_PARA_HAS_EXTRA_FIELDS
  11627. // The above defined, CRYPT_MESSAGE_SILENT_KEYSET_FLAG, can be set to
  11628. // suppress UI by the CSP. See CryptAcquireContext's CRYPT_SILENT
  11629. // flag for more details.
  11630. DWORD dwFlags;
  11631. #endif
  11632. } CRYPT_DECRYPT_MESSAGE_PARA, *PCRYPT_DECRYPT_MESSAGE_PARA;
  11633. //+-------------------------------------------------------------------------
  11634. // The CRYPT_HASH_MESSAGE_PARA are used for hashing or unhashing
  11635. // messages.
  11636. //
  11637. // hCryptProv is used to compute the hash.
  11638. //
  11639. // pvHashAuxInfo currently isn't used and must be set to NULL.
  11640. //
  11641. // cbSize must be set to the sizeof(CRYPT_HASH_MESSAGE_PARA) or else
  11642. // LastError will be updated with E_INVALIDARG.
  11643. //--------------------------------------------------------------------------
  11644. typedef struct _CRYPT_HASH_MESSAGE_PARA {
  11645. DWORD cbSize;
  11646. DWORD dwMsgEncodingType;
  11647. HCRYPTPROV hCryptProv;
  11648. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  11649. void *pvHashAuxInfo;
  11650. } CRYPT_HASH_MESSAGE_PARA, *PCRYPT_HASH_MESSAGE_PARA;
  11651. //+-------------------------------------------------------------------------
  11652. // The CRYPT_KEY_SIGN_MESSAGE_PARA are used for signing messages until a
  11653. // certificate has been created for the signature key.
  11654. //
  11655. // pvHashAuxInfo currently isn't used and must be set to NULL.
  11656. //
  11657. // If PubKeyAlgorithm isn't set, defaults to szOID_RSA_RSA.
  11658. //
  11659. // cbSize must be set to the sizeof(CRYPT_KEY_SIGN_MESSAGE_PARA) or else
  11660. // LastError will be updated with E_INVALIDARG.
  11661. //--------------------------------------------------------------------------
  11662. typedef struct _CRYPT_KEY_SIGN_MESSAGE_PARA {
  11663. DWORD cbSize;
  11664. DWORD dwMsgAndCertEncodingType;
  11665. HCRYPTPROV hCryptProv;
  11666. DWORD dwKeySpec;
  11667. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  11668. void *pvHashAuxInfo;
  11669. CRYPT_ALGORITHM_IDENTIFIER PubKeyAlgorithm;
  11670. } CRYPT_KEY_SIGN_MESSAGE_PARA, *PCRYPT_KEY_SIGN_MESSAGE_PARA;
  11671. //+-------------------------------------------------------------------------
  11672. // The CRYPT_KEY_VERIFY_MESSAGE_PARA are used to verify signed messages without
  11673. // a certificate for the signer.
  11674. //
  11675. // Normally used until a certificate has been created for the key.
  11676. //
  11677. // hCryptProv is used to do hashing and signature verification.
  11678. //
  11679. // cbSize must be set to the sizeof(CRYPT_KEY_VERIFY_MESSAGE_PARA) or else
  11680. // LastError will be updated with E_INVALIDARG.
  11681. //--------------------------------------------------------------------------
  11682. typedef struct _CRYPT_KEY_VERIFY_MESSAGE_PARA {
  11683. DWORD cbSize;
  11684. DWORD dwMsgEncodingType;
  11685. HCRYPTPROV hCryptProv;
  11686. } CRYPT_KEY_VERIFY_MESSAGE_PARA, *PCRYPT_KEY_VERIFY_MESSAGE_PARA;
  11687. //+-------------------------------------------------------------------------
  11688. // Sign the message.
  11689. //
  11690. // If fDetachedSignature is TRUE, the "to be signed" content isn't included
  11691. // in the encoded signed blob.
  11692. //--------------------------------------------------------------------------
  11693. WINCRYPT32API
  11694. BOOL
  11695. WINAPI
  11696. CryptSignMessage(
  11697. IN PCRYPT_SIGN_MESSAGE_PARA pSignPara,
  11698. IN BOOL fDetachedSignature,
  11699. IN DWORD cToBeSigned,
  11700. IN const BYTE *rgpbToBeSigned[],
  11701. IN DWORD rgcbToBeSigned[],
  11702. OUT BYTE *pbSignedBlob,
  11703. IN OUT DWORD *pcbSignedBlob
  11704. );
  11705. //+-------------------------------------------------------------------------
  11706. // Verify a signed message.
  11707. //
  11708. // If pbDecoded == NULL, then, *pcbDecoded is implicitly set to 0 on input.
  11709. // For *pcbDecoded == 0 && ppSignerCert == NULL on input, the signer isn't
  11710. // verified.
  11711. //
  11712. // A message might have more than one signer. Set dwSignerIndex to iterate
  11713. // through all the signers. dwSignerIndex == 0 selects the first signer.
  11714. //
  11715. // pVerifyPara's pfnGetSignerCertificate is called to get the signer's
  11716. // certificate.
  11717. //
  11718. // For a verified signer and message, *ppSignerCert is updated
  11719. // with the CertContext of the signer. It must be freed by calling
  11720. // CertFreeCertificateContext. Otherwise, *ppSignerCert is set to NULL.
  11721. //
  11722. // ppSignerCert can be NULL, indicating the caller isn't interested
  11723. // in getting the CertContext of the signer.
  11724. //
  11725. // pcbDecoded can be NULL, indicating the caller isn't interested in getting
  11726. // the decoded content. Furthermore, if the message doesn't contain any
  11727. // content or signers, then, pcbDecoded must be set to NULL, to allow the
  11728. // pVerifyPara->pfnGetCertificate to be called. Normally, this would be
  11729. // the case when the signed message contains only certficates and CRLs.
  11730. // If pcbDecoded is NULL and the message doesn't have the indicated signer,
  11731. // pfnGetCertificate is called with pSignerId set to NULL.
  11732. //
  11733. // If the message doesn't contain any signers || dwSignerIndex > message's
  11734. // SignerCount, then, an error is returned with LastError set to
  11735. // CRYPT_E_NO_SIGNER. Also, for CRYPT_E_NO_SIGNER, pfnGetSignerCertificate
  11736. // is still called with pSignerId set to NULL.
  11737. //
  11738. // Note, an alternative way to get the certificates and CRLs from a
  11739. // signed message is to call CryptGetMessageCertificates.
  11740. //--------------------------------------------------------------------------
  11741. WINCRYPT32API
  11742. BOOL
  11743. WINAPI
  11744. CryptVerifyMessageSignature(
  11745. IN PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara,
  11746. IN DWORD dwSignerIndex,
  11747. IN const BYTE *pbSignedBlob,
  11748. IN DWORD cbSignedBlob,
  11749. OUT BYTE OPTIONAL *pbDecoded,
  11750. IN OUT OPTIONAL DWORD *pcbDecoded,
  11751. OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert
  11752. );
  11753. //+-------------------------------------------------------------------------
  11754. // Returns the count of signers in the signed message. For no signers, returns
  11755. // 0. For an error returns -1 with LastError updated accordingly.
  11756. //--------------------------------------------------------------------------
  11757. WINCRYPT32API
  11758. LONG
  11759. WINAPI
  11760. CryptGetMessageSignerCount(
  11761. IN DWORD dwMsgEncodingType,
  11762. IN const BYTE *pbSignedBlob,
  11763. IN DWORD cbSignedBlob
  11764. );
  11765. //+-------------------------------------------------------------------------
  11766. // Returns the cert store containing the message's certs and CRLs.
  11767. // For an error, returns NULL with LastError updated.
  11768. //--------------------------------------------------------------------------
  11769. WINCRYPT32API
  11770. HCERTSTORE
  11771. WINAPI
  11772. CryptGetMessageCertificates(
  11773. IN DWORD dwMsgAndCertEncodingType,
  11774. IN HCRYPTPROV hCryptProv, // passed to CertOpenStore
  11775. IN DWORD dwFlags, // passed to CertOpenStore
  11776. IN const BYTE *pbSignedBlob,
  11777. IN DWORD cbSignedBlob
  11778. );
  11779. //+-------------------------------------------------------------------------
  11780. // Verify a signed message containing detached signature(s).
  11781. // The "to be signed" content is passed in separately. No
  11782. // decoded output. Otherwise, identical to CryptVerifyMessageSignature.
  11783. //--------------------------------------------------------------------------
  11784. WINCRYPT32API
  11785. BOOL
  11786. WINAPI
  11787. CryptVerifyDetachedMessageSignature(
  11788. IN PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara,
  11789. IN DWORD dwSignerIndex,
  11790. IN const BYTE *pbDetachedSignBlob,
  11791. IN DWORD cbDetachedSignBlob,
  11792. IN DWORD cToBeSigned,
  11793. IN const BYTE *rgpbToBeSigned[],
  11794. IN DWORD rgcbToBeSigned[],
  11795. OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert
  11796. );
  11797. //+-------------------------------------------------------------------------
  11798. // Encrypts the message for the recipient(s).
  11799. //--------------------------------------------------------------------------
  11800. WINCRYPT32API
  11801. BOOL
  11802. WINAPI
  11803. CryptEncryptMessage(
  11804. IN PCRYPT_ENCRYPT_MESSAGE_PARA pEncryptPara,
  11805. IN DWORD cRecipientCert,
  11806. IN PCCERT_CONTEXT rgpRecipientCert[],
  11807. IN const BYTE *pbToBeEncrypted,
  11808. IN DWORD cbToBeEncrypted,
  11809. OUT BYTE *pbEncryptedBlob,
  11810. IN OUT DWORD *pcbEncryptedBlob
  11811. );
  11812. //+-------------------------------------------------------------------------
  11813. // Decrypts the message.
  11814. //
  11815. // If pbDecrypted == NULL, then, *pcbDecrypted is implicitly set to 0 on input.
  11816. // For *pcbDecrypted == 0 && ppXchgCert == NULL on input, the message isn't
  11817. // decrypted.
  11818. //
  11819. // For a successfully decrypted message, *ppXchgCert is updated
  11820. // with the CertContext used to decrypt. It must be freed by calling
  11821. // CertStoreFreeCert. Otherwise, *ppXchgCert is set to NULL.
  11822. //
  11823. // ppXchgCert can be NULL, indicating the caller isn't interested
  11824. // in getting the CertContext used to decrypt.
  11825. //--------------------------------------------------------------------------
  11826. WINCRYPT32API
  11827. BOOL
  11828. WINAPI
  11829. CryptDecryptMessage(
  11830. IN PCRYPT_DECRYPT_MESSAGE_PARA pDecryptPara,
  11831. IN const BYTE *pbEncryptedBlob,
  11832. IN DWORD cbEncryptedBlob,
  11833. OUT OPTIONAL BYTE *pbDecrypted,
  11834. IN OUT OPTIONAL DWORD *pcbDecrypted,
  11835. OUT OPTIONAL PCCERT_CONTEXT *ppXchgCert
  11836. );
  11837. //+-------------------------------------------------------------------------
  11838. // Sign the message and encrypt for the recipient(s). Does a CryptSignMessage
  11839. // followed with a CryptEncryptMessage.
  11840. //
  11841. // Note: this isn't the CMSG_SIGNED_AND_ENVELOPED. Its a CMSG_SIGNED
  11842. // inside of an CMSG_ENVELOPED.
  11843. //--------------------------------------------------------------------------
  11844. WINCRYPT32API
  11845. BOOL
  11846. WINAPI
  11847. CryptSignAndEncryptMessage(
  11848. IN PCRYPT_SIGN_MESSAGE_PARA pSignPara,
  11849. IN PCRYPT_ENCRYPT_MESSAGE_PARA pEncryptPara,
  11850. IN DWORD cRecipientCert,
  11851. IN PCCERT_CONTEXT rgpRecipientCert[],
  11852. IN const BYTE *pbToBeSignedAndEncrypted,
  11853. IN DWORD cbToBeSignedAndEncrypted,
  11854. OUT BYTE *pbSignedAndEncryptedBlob,
  11855. IN OUT DWORD *pcbSignedAndEncryptedBlob
  11856. );
  11857. //+-------------------------------------------------------------------------
  11858. // Decrypts the message and verifies the signer. Does a CryptDecryptMessage
  11859. // followed with a CryptVerifyMessageSignature.
  11860. //
  11861. // If pbDecrypted == NULL, then, *pcbDecrypted is implicitly set to 0 on input.
  11862. // For *pcbDecrypted == 0 && ppSignerCert == NULL on input, the signer isn't
  11863. // verified.
  11864. //
  11865. // A message might have more than one signer. Set dwSignerIndex to iterate
  11866. // through all the signers. dwSignerIndex == 0 selects the first signer.
  11867. //
  11868. // The pVerifyPara's VerifySignerPolicy is called to verify the signer's
  11869. // certificate.
  11870. //
  11871. // For a successfully decrypted and verified message, *ppXchgCert and
  11872. // *ppSignerCert are updated. They must be freed by calling
  11873. // CertStoreFreeCert. Otherwise, they are set to NULL.
  11874. //
  11875. // ppXchgCert and/or ppSignerCert can be NULL, indicating the
  11876. // caller isn't interested in getting the CertContext.
  11877. //
  11878. // Note: this isn't the CMSG_SIGNED_AND_ENVELOPED. Its a CMSG_SIGNED
  11879. // inside of an CMSG_ENVELOPED.
  11880. //
  11881. // The message always needs to be decrypted to allow access to the
  11882. // signed message. Therefore, if ppXchgCert != NULL, its always updated.
  11883. //--------------------------------------------------------------------------
  11884. WINCRYPT32API
  11885. BOOL
  11886. WINAPI
  11887. CryptDecryptAndVerifyMessageSignature(
  11888. IN PCRYPT_DECRYPT_MESSAGE_PARA pDecryptPara,
  11889. IN PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara,
  11890. IN DWORD dwSignerIndex,
  11891. IN const BYTE *pbEncryptedBlob,
  11892. IN DWORD cbEncryptedBlob,
  11893. OUT OPTIONAL BYTE *pbDecrypted,
  11894. IN OUT OPTIONAL DWORD *pcbDecrypted,
  11895. OUT OPTIONAL PCCERT_CONTEXT *ppXchgCert,
  11896. OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert
  11897. );
  11898. //+-------------------------------------------------------------------------
  11899. // Decodes a cryptographic message which may be one of the following types:
  11900. // CMSG_DATA
  11901. // CMSG_SIGNED
  11902. // CMSG_ENVELOPED
  11903. // CMSG_SIGNED_AND_ENVELOPED
  11904. // CMSG_HASHED
  11905. //
  11906. // dwMsgTypeFlags specifies the set of allowable messages. For example, to
  11907. // decode either SIGNED or ENVELOPED messages, set dwMsgTypeFlags to:
  11908. // CMSG_SIGNED_FLAG | CMSG_ENVELOPED_FLAG.
  11909. //
  11910. // dwProvInnerContentType is only applicable when processing nested
  11911. // crytographic messages. When processing an outer crytographic message
  11912. // it must be set to 0. When decoding a nested cryptographic message
  11913. // its the dwInnerContentType returned by a previous CryptDecodeMessage
  11914. // of the outer message. The InnerContentType can be any of the CMSG types,
  11915. // for example, CMSG_DATA, CMSG_SIGNED, ...
  11916. //
  11917. // The optional *pdwMsgType is updated with the type of message.
  11918. //
  11919. // The optional *pdwInnerContentType is updated with the type of the inner
  11920. // message. Unless there is cryptographic message nesting, CMSG_DATA
  11921. // is returned.
  11922. //
  11923. // For CMSG_DATA: returns decoded content.
  11924. // For CMSG_SIGNED: same as CryptVerifyMessageSignature.
  11925. // For CMSG_ENVELOPED: same as CryptDecryptMessage.
  11926. // For CMSG_SIGNED_AND_ENVELOPED: same as CryptDecryptMessage plus
  11927. // CryptVerifyMessageSignature.
  11928. // For CMSG_HASHED: verifies the hash and returns decoded content.
  11929. //--------------------------------------------------------------------------
  11930. WINCRYPT32API
  11931. BOOL
  11932. WINAPI
  11933. CryptDecodeMessage(
  11934. IN DWORD dwMsgTypeFlags,
  11935. IN PCRYPT_DECRYPT_MESSAGE_PARA pDecryptPara,
  11936. IN PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara,
  11937. IN DWORD dwSignerIndex,
  11938. IN const BYTE *pbEncodedBlob,
  11939. IN DWORD cbEncodedBlob,
  11940. IN DWORD dwPrevInnerContentType,
  11941. OUT OPTIONAL DWORD *pdwMsgType,
  11942. OUT OPTIONAL DWORD *pdwInnerContentType,
  11943. OUT OPTIONAL BYTE *pbDecoded,
  11944. IN OUT OPTIONAL DWORD *pcbDecoded,
  11945. OUT OPTIONAL PCCERT_CONTEXT *ppXchgCert,
  11946. OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert
  11947. );
  11948. //+-------------------------------------------------------------------------
  11949. // Hash the message.
  11950. //
  11951. // If fDetachedHash is TRUE, only the ComputedHash is encoded in the
  11952. // pbHashedBlob. Otherwise, both the ToBeHashed and ComputedHash
  11953. // are encoded.
  11954. //
  11955. // pcbHashedBlob or pcbComputedHash can be NULL, indicating the caller
  11956. // isn't interested in getting the output.
  11957. //--------------------------------------------------------------------------
  11958. WINCRYPT32API
  11959. BOOL
  11960. WINAPI
  11961. CryptHashMessage(
  11962. IN PCRYPT_HASH_MESSAGE_PARA pHashPara,
  11963. IN BOOL fDetachedHash,
  11964. IN DWORD cToBeHashed,
  11965. IN const BYTE *rgpbToBeHashed[],
  11966. IN DWORD rgcbToBeHashed[],
  11967. OUT OPTIONAL BYTE *pbHashedBlob,
  11968. IN OUT OPTIONAL DWORD *pcbHashedBlob,
  11969. OUT OPTIONAL BYTE *pbComputedHash,
  11970. IN OUT OPTIONAL DWORD *pcbComputedHash
  11971. );
  11972. //+-------------------------------------------------------------------------
  11973. // Verify a hashed message.
  11974. //
  11975. // pcbToBeHashed or pcbComputedHash can be NULL,
  11976. // indicating the caller isn't interested in getting the output.
  11977. //--------------------------------------------------------------------------
  11978. WINCRYPT32API
  11979. BOOL
  11980. WINAPI
  11981. CryptVerifyMessageHash(
  11982. IN PCRYPT_HASH_MESSAGE_PARA pHashPara,
  11983. IN BYTE *pbHashedBlob,
  11984. IN DWORD cbHashedBlob,
  11985. OUT OPTIONAL BYTE *pbToBeHashed,
  11986. IN OUT OPTIONAL DWORD *pcbToBeHashed,
  11987. OUT OPTIONAL BYTE *pbComputedHash,
  11988. IN OUT OPTIONAL DWORD *pcbComputedHash
  11989. );
  11990. //+-------------------------------------------------------------------------
  11991. // Verify a hashed message containing a detached hash.
  11992. // The "to be hashed" content is passed in separately. No
  11993. // decoded output. Otherwise, identical to CryptVerifyMessageHash.
  11994. //
  11995. // pcbComputedHash can be NULL, indicating the caller isn't interested
  11996. // in getting the output.
  11997. //--------------------------------------------------------------------------
  11998. WINCRYPT32API
  11999. BOOL
  12000. WINAPI
  12001. CryptVerifyDetachedMessageHash(
  12002. IN PCRYPT_HASH_MESSAGE_PARA pHashPara,
  12003. IN BYTE *pbDetachedHashBlob,
  12004. IN DWORD cbDetachedHashBlob,
  12005. IN DWORD cToBeHashed,
  12006. IN const BYTE *rgpbToBeHashed[],
  12007. IN DWORD rgcbToBeHashed[],
  12008. OUT OPTIONAL BYTE *pbComputedHash,
  12009. IN OUT OPTIONAL DWORD *pcbComputedHash
  12010. );
  12011. //+-------------------------------------------------------------------------
  12012. // Sign the message using the provider's private key specified in the
  12013. // parameters. A dummy SignerId is created and stored in the message.
  12014. //
  12015. // Normally used until a certificate has been created for the key.
  12016. //--------------------------------------------------------------------------
  12017. WINCRYPT32API
  12018. BOOL
  12019. WINAPI
  12020. CryptSignMessageWithKey(
  12021. IN PCRYPT_KEY_SIGN_MESSAGE_PARA pSignPara,
  12022. IN const BYTE *pbToBeSigned,
  12023. IN DWORD cbToBeSigned,
  12024. OUT BYTE *pbSignedBlob,
  12025. IN OUT DWORD *pcbSignedBlob
  12026. );
  12027. //+-------------------------------------------------------------------------
  12028. // Verify a signed message using the specified public key info.
  12029. //
  12030. // Normally called by a CA until it has created a certificate for the
  12031. // key.
  12032. //
  12033. // pPublicKeyInfo contains the public key to use to verify the signed
  12034. // message. If NULL, the signature isn't verified (for instance, the decoded
  12035. // content may contain the PublicKeyInfo).
  12036. //
  12037. // pcbDecoded can be NULL, indicating the caller isn't interested
  12038. // in getting the decoded content.
  12039. //--------------------------------------------------------------------------
  12040. WINCRYPT32API
  12041. BOOL
  12042. WINAPI
  12043. CryptVerifyMessageSignatureWithKey(
  12044. IN PCRYPT_KEY_VERIFY_MESSAGE_PARA pVerifyPara,
  12045. IN OPTIONAL PCERT_PUBLIC_KEY_INFO pPublicKeyInfo,
  12046. IN const BYTE *pbSignedBlob,
  12047. IN DWORD cbSignedBlob,
  12048. OUT OPTIONAL BYTE *pbDecoded,
  12049. IN OUT OPTIONAL DWORD *pcbDecoded
  12050. );
  12051. //+=========================================================================
  12052. // System Certificate Store Data Structures and APIs
  12053. //==========================================================================
  12054. //+-------------------------------------------------------------------------
  12055. // Get a system certificate store based on a subsystem protocol.
  12056. //
  12057. // Current examples of subsystems protocols are:
  12058. // "MY" Cert Store hold certs with associated Private Keys
  12059. // "CA" Certifying Authority certs
  12060. // "ROOT" Root Certs
  12061. // "SPC" Software publisher certs
  12062. //
  12063. //
  12064. // If hProv is NULL the default provider "1" is opened for you.
  12065. // When the store is closed the provider is release. Otherwise
  12066. // if hProv is not NULL, no provider is created or released.
  12067. //
  12068. // The returned Cert Store can be searched for an appropriate Cert
  12069. // using the Cert Store API's (see certstor.h)
  12070. //
  12071. // When done, the cert store should be closed using CertStoreClose
  12072. //--------------------------------------------------------------------------
  12073. WINCRYPT32API
  12074. HCERTSTORE
  12075. WINAPI
  12076. CertOpenSystemStoreA(
  12077. HCRYPTPROV hProv,
  12078. LPCSTR szSubsystemProtocol
  12079. );
  12080. WINCRYPT32API
  12081. HCERTSTORE
  12082. WINAPI
  12083. CertOpenSystemStoreW(
  12084. HCRYPTPROV hProv,
  12085. LPCWSTR szSubsystemProtocol
  12086. );
  12087. #ifdef UNICODE
  12088. #define CertOpenSystemStore CertOpenSystemStoreW
  12089. #else
  12090. #define CertOpenSystemStore CertOpenSystemStoreA
  12091. #endif // !UNICODE
  12092. WINCRYPT32API
  12093. BOOL
  12094. WINAPI
  12095. CertAddEncodedCertificateToSystemStoreA(
  12096. LPCSTR szCertStoreName,
  12097. const BYTE * pbCertEncoded,
  12098. DWORD cbCertEncoded
  12099. );
  12100. WINCRYPT32API
  12101. BOOL
  12102. WINAPI
  12103. CertAddEncodedCertificateToSystemStoreW(
  12104. LPCWSTR szCertStoreName,
  12105. const BYTE * pbCertEncoded,
  12106. DWORD cbCertEncoded
  12107. );
  12108. #ifdef UNICODE
  12109. #define CertAddEncodedCertificateToSystemStore CertAddEncodedCertificateToSystemStoreW
  12110. #else
  12111. #define CertAddEncodedCertificateToSystemStore CertAddEncodedCertificateToSystemStoreA
  12112. #endif // !UNICODE
  12113. //+-------------------------------------------------------------------------
  12114. // Find all certificate chains tying the given issuer name to any certificate
  12115. // that the current user has a private key for.
  12116. //
  12117. // If no certificate chain is found, FALSE is returned with LastError set
  12118. // to CRYPT_E_NOT_FOUND and the counts zeroed.
  12119. //
  12120. // IE 3.0 ASSUMPTION:
  12121. // The client certificates are in the "My" system store. The issuer
  12122. // cerificates may be in the "Root", "CA" or "My" system stores.
  12123. //--------------------------------------------------------------------------
  12124. typedef struct _CERT_CHAIN {
  12125. DWORD cCerts; // number of certs in chain
  12126. PCERT_BLOB certs; // pointer to array of cert chain blobs
  12127. // representing the certs
  12128. CRYPT_KEY_PROV_INFO keyLocatorInfo; // key locator for cert
  12129. } CERT_CHAIN, *PCERT_CHAIN;
  12130. // WINCRYPT32API This is not exported by crypt32, it is exported by softpub
  12131. HRESULT
  12132. WINAPI
  12133. FindCertsByIssuer(
  12134. OUT PCERT_CHAIN pCertChains,
  12135. IN OUT DWORD *pcbCertChains,
  12136. OUT DWORD *pcCertChains, // count of certificates chains returned
  12137. IN BYTE* pbEncodedIssuerName, // DER encoded issuer name
  12138. IN DWORD cbEncodedIssuerName, // count in bytes of encoded issuer name
  12139. IN LPCWSTR pwszPurpose, // "ClientAuth" or "CodeSigning"
  12140. IN DWORD dwKeySpec // only return signers supporting this
  12141. // keyspec
  12142. );
  12143. //-------------------------------------------------------------------------
  12144. //
  12145. // CryptQueryObject takes a CERT_BLOB or a file name and returns the
  12146. // information about the content in the blob or in the file.
  12147. //
  12148. // Parameters:
  12149. // INPUT dwObjectType:
  12150. // Indicate the type of the object. Should be one of the
  12151. // following:
  12152. // CERT_QUERY_OBJECT_FILE
  12153. // CERT_QUERY_OBJECT_BLOB
  12154. //
  12155. // INPUT pvObject:
  12156. // If dwObjectType == CERT_QUERY_OBJECT_FILE, it is a
  12157. // LPWSTR, that is, the pointer to a wchar file name
  12158. // if dwObjectType == CERT_QUERY_OBJECT_BLOB, it is a
  12159. // PCERT_BLOB, that is, a pointer to a CERT_BLOB
  12160. //
  12161. // INPUT dwExpectedContentTypeFlags:
  12162. // Indicate the expected contenet type.
  12163. // Can be one of the following:
  12164. // CERT_QUERY_CONTENT_FLAG_ALL (the content can be any type)
  12165. // CERT_QUERY_CONTENT_FLAG_CERT
  12166. // CERT_QUERY_CONTENT_FLAG_CTL
  12167. // CERT_QUERY_CONTENT_FLAG_CRL
  12168. // CERT_QUERY_CONTENT_FLAG_SERIALIZED_STORE
  12169. // CERT_QUERY_CONTENT_FLAG_SERIALIZED_CERT
  12170. // CERT_QUERY_CONTENT_FLAG_SERIALIZED_CTL
  12171. // CERT_QUERY_CONTENT_FLAG_SERIALIZED_CRL
  12172. // CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED
  12173. // CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED
  12174. // CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED
  12175. // CERT_QUERY_CONTENT_FLAG_PKCS10
  12176. // CERT_QUERY_CONTENT_FLAG_PFX
  12177. // CERT_QUERY_CONTENT_FLAG_CERT_PAIR
  12178. //
  12179. // INPUT dwExpectedFormatTypeFlags:
  12180. // Indicate the expected format type.
  12181. // Can be one of the following:
  12182. // CERT_QUERY_FORMAT_FLAG_ALL (the content can be any format)
  12183. // CERT_QUERY_FORMAT_FLAG_BINARY
  12184. // CERT_QUERY_FORMAT_FLAG_BASE64_ENCODED
  12185. // CERT_QUERY_FORMAT_FLAG_ASN_ASCII_HEX_ENCODED
  12186. //
  12187. //
  12188. // INPUT dwFlags
  12189. // Reserved flag. Should always set to 0
  12190. //
  12191. // OUTPUT pdwMsgAndCertEncodingType
  12192. // Optional output. If NULL != pdwMsgAndCertEncodingType,
  12193. // it contains the encoding type of the content as any
  12194. // combination of the following:
  12195. // X509_ASN_ENCODING
  12196. // PKCS_7_ASN_ENCODING
  12197. //
  12198. // OUTPUT pdwContentType
  12199. // Optional output. If NULL!=pdwContentType, it contains
  12200. // the content type as one of the the following:
  12201. // CERT_QUERY_CONTENT_CERT
  12202. // CERT_QUERY_CONTENT_CTL
  12203. // CERT_QUERY_CONTENT_CRL
  12204. // CERT_QUERY_CONTENT_SERIALIZED_STORE
  12205. // CERT_QUERY_CONTENT_SERIALIZED_CERT
  12206. // CERT_QUERY_CONTENT_SERIALIZED_CTL
  12207. // CERT_QUERY_CONTENT_SERIALIZED_CRL
  12208. // CERT_QUERY_CONTENT_PKCS7_SIGNED
  12209. // CERT_QUERY_CONTENT_PKCS7_UNSIGNED
  12210. // CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED
  12211. // CERT_QUERY_CONTENT_PKCS10
  12212. // CERT_QUERY_CONTENT_PFX
  12213. // CERT_QUERY_CONTENT_CERT_PAIR
  12214. //
  12215. // OUTPUT pdwFormatType
  12216. // Optional output. If NULL !=pdwFormatType, it
  12217. // contains the format type of the content as one of the
  12218. // following:
  12219. // CERT_QUERY_FORMAT_BINARY
  12220. // CERT_QUERY_FORMAT_BASE64_ENCODED
  12221. // CERT_QUERY_FORMAT_ASN_ASCII_HEX_ENCODED
  12222. //
  12223. //
  12224. // OUTPUT phCertStore
  12225. // Optional output. If NULL !=phStore,
  12226. // it contains a cert store that includes all of certificates,
  12227. // CRL, and CTL in the object if the object content type is
  12228. // one of the following:
  12229. // CERT_QUERY_CONTENT_CERT
  12230. // CERT_QUERY_CONTENT_CTL
  12231. // CERT_QUERY_CONTENT_CRL
  12232. // CERT_QUERY_CONTENT_SERIALIZED_STORE
  12233. // CERT_QUERY_CONTENT_SERIALIZED_CERT
  12234. // CERT_QUERY_CONTENT_SERIALIZED_CTL
  12235. // CERT_QUERY_CONTENT_SERIALIZED_CRL
  12236. // CERT_QUERY_CONTENT_PKCS7_SIGNED
  12237. // CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED
  12238. // CERT_QUERY_CONTENT_CERT_PAIR
  12239. //
  12240. // Caller should free *phCertStore via CertCloseStore.
  12241. //
  12242. //
  12243. // OUTPUT phMsg Optional output. If NULL != phMsg,
  12244. // it contains a handle to a opened message if
  12245. // the content type is one of the following:
  12246. // CERT_QUERY_CONTENT_PKCS7_SIGNED
  12247. // CERT_QUERY_CONTENT_PKCS7_UNSIGNED
  12248. // CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED
  12249. //
  12250. // Caller should free *phMsg via CryptMsgClose.
  12251. //
  12252. // OUTPUT pContext Optional output. If NULL != pContext,
  12253. // it contains either a PCCERT_CONTEXT or PCCRL_CONTEXT,
  12254. // or PCCTL_CONTEXT based on the content type.
  12255. //
  12256. // If the content type is CERT_QUERY_CONTENT_CERT or
  12257. // CERT_QUERY_CONTENT_SERIALIZED_CERT, it is a PCCERT_CONTEXT;
  12258. // Caller should free the pContext via CertFreeCertificateContext.
  12259. //
  12260. // If the content type is CERT_QUERY_CONTENT_CRL or
  12261. // CERT_QUERY_CONTENT_SERIALIZED_CRL, it is a PCCRL_CONTEXT;
  12262. // Caller should free the pContext via CertFreeCRLContext.
  12263. //
  12264. // If the content type is CERT_QUERY_CONTENT_CTL or
  12265. // CERT_QUERY_CONTENT_SERIALIZED_CTL, it is a PCCTL_CONTEXT;
  12266. // Caller should free the pContext via CertFreeCTLContext.
  12267. //
  12268. // If the *pbObject is of type CERT_QUERY_CONTENT_PKCS10 or CERT_QUERY_CONTENT_PFX, CryptQueryObject
  12269. // will not return anything in *phCertstore, *phMsg, or *ppvContext.
  12270. //--------------------------------------------------------------------------
  12271. WINCRYPT32API
  12272. BOOL
  12273. WINAPI
  12274. CryptQueryObject(
  12275. DWORD dwObjectType,
  12276. const void *pvObject,
  12277. DWORD dwExpectedContentTypeFlags,
  12278. DWORD dwExpectedFormatTypeFlags,
  12279. DWORD dwFlags,
  12280. DWORD *pdwMsgAndCertEncodingType,
  12281. DWORD *pdwContentType,
  12282. DWORD *pdwFormatType,
  12283. HCERTSTORE *phCertStore,
  12284. HCRYPTMSG *phMsg,
  12285. const void **ppvContext
  12286. );
  12287. //-------------------------------------------------------------------------
  12288. //dwObjectType for CryptQueryObject
  12289. //-------------------------------------------------------------------------
  12290. #define CERT_QUERY_OBJECT_FILE 0x00000001
  12291. #define CERT_QUERY_OBJECT_BLOB 0x00000002
  12292. //-------------------------------------------------------------------------
  12293. //dwContentType for CryptQueryObject
  12294. //-------------------------------------------------------------------------
  12295. //encoded single certificate
  12296. #define CERT_QUERY_CONTENT_CERT 1
  12297. //encoded single CTL
  12298. #define CERT_QUERY_CONTENT_CTL 2
  12299. //encoded single CRL
  12300. #define CERT_QUERY_CONTENT_CRL 3
  12301. //serialized store
  12302. #define CERT_QUERY_CONTENT_SERIALIZED_STORE 4
  12303. //serialized single certificate
  12304. #define CERT_QUERY_CONTENT_SERIALIZED_CERT 5
  12305. //serialized single CTL
  12306. #define CERT_QUERY_CONTENT_SERIALIZED_CTL 6
  12307. //serialized single CRL
  12308. #define CERT_QUERY_CONTENT_SERIALIZED_CRL 7
  12309. //a PKCS#7 signed message
  12310. #define CERT_QUERY_CONTENT_PKCS7_SIGNED 8
  12311. //a PKCS#7 message, such as enveloped message. But it is not a signed message,
  12312. #define CERT_QUERY_CONTENT_PKCS7_UNSIGNED 9
  12313. //a PKCS7 signed message embedded in a file
  12314. #define CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED 10
  12315. //an encoded PKCS#10
  12316. #define CERT_QUERY_CONTENT_PKCS10 11
  12317. //an encoded PKX BLOB
  12318. #define CERT_QUERY_CONTENT_PFX 12
  12319. //an encoded CertificatePair (contains forward and/or reverse cross certs)
  12320. #define CERT_QUERY_CONTENT_CERT_PAIR 13
  12321. //-------------------------------------------------------------------------
  12322. //dwExpectedConentTypeFlags for CryptQueryObject
  12323. //-------------------------------------------------------------------------
  12324. //encoded single certificate
  12325. #define CERT_QUERY_CONTENT_FLAG_CERT \
  12326. ( 1 << CERT_QUERY_CONTENT_CERT)
  12327. //encoded single CTL
  12328. #define CERT_QUERY_CONTENT_FLAG_CTL \
  12329. ( 1 << CERT_QUERY_CONTENT_CTL)
  12330. //encoded single CRL
  12331. #define CERT_QUERY_CONTENT_FLAG_CRL \
  12332. ( 1 << CERT_QUERY_CONTENT_CRL)
  12333. //serialized store
  12334. #define CERT_QUERY_CONTENT_FLAG_SERIALIZED_STORE \
  12335. ( 1 << CERT_QUERY_CONTENT_SERIALIZED_STORE)
  12336. //serialized single certificate
  12337. #define CERT_QUERY_CONTENT_FLAG_SERIALIZED_CERT \
  12338. ( 1 << CERT_QUERY_CONTENT_SERIALIZED_CERT)
  12339. //serialized single CTL
  12340. #define CERT_QUERY_CONTENT_FLAG_SERIALIZED_CTL \
  12341. ( 1 << CERT_QUERY_CONTENT_SERIALIZED_CTL)
  12342. //serialized single CRL
  12343. #define CERT_QUERY_CONTENT_FLAG_SERIALIZED_CRL \
  12344. ( 1 << CERT_QUERY_CONTENT_SERIALIZED_CRL)
  12345. //an encoded PKCS#7 signed message
  12346. #define CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED \
  12347. ( 1 << CERT_QUERY_CONTENT_PKCS7_SIGNED)
  12348. //an encoded PKCS#7 message. But it is not a signed message
  12349. #define CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED \
  12350. ( 1 << CERT_QUERY_CONTENT_PKCS7_UNSIGNED)
  12351. //the content includes an embedded PKCS7 signed message
  12352. #define CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED \
  12353. ( 1 << CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED)
  12354. //an encoded PKCS#10
  12355. #define CERT_QUERY_CONTENT_FLAG_PKCS10 \
  12356. ( 1 << CERT_QUERY_CONTENT_PKCS10)
  12357. //an encoded PFX BLOB
  12358. #define CERT_QUERY_CONTENT_FLAG_PFX \
  12359. ( 1 << CERT_QUERY_CONTENT_PFX)
  12360. //an encoded CertificatePair (contains forward and/or reverse cross certs)
  12361. #define CERT_QUERY_CONTENT_FLAG_CERT_PAIR \
  12362. ( 1 << CERT_QUERY_CONTENT_CERT_PAIR)
  12363. //content can be any type
  12364. #define CERT_QUERY_CONTENT_FLAG_ALL \
  12365. CERT_QUERY_CONTENT_FLAG_CERT | \
  12366. CERT_QUERY_CONTENT_FLAG_CTL | \
  12367. CERT_QUERY_CONTENT_FLAG_CRL | \
  12368. CERT_QUERY_CONTENT_FLAG_SERIALIZED_STORE | \
  12369. CERT_QUERY_CONTENT_FLAG_SERIALIZED_CERT | \
  12370. CERT_QUERY_CONTENT_FLAG_SERIALIZED_CTL | \
  12371. CERT_QUERY_CONTENT_FLAG_SERIALIZED_CRL | \
  12372. CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED | \
  12373. CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED | \
  12374. CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED | \
  12375. CERT_QUERY_CONTENT_FLAG_PKCS10 | \
  12376. CERT_QUERY_CONTENT_FLAG_PFX | \
  12377. CERT_QUERY_CONTENT_FLAG_CERT_PAIR
  12378. //-------------------------------------------------------------------------
  12379. //dwFormatType for CryptQueryObject
  12380. //-------------------------------------------------------------------------
  12381. //the content is in binary format
  12382. #define CERT_QUERY_FORMAT_BINARY 1
  12383. //the content is base64 encoded
  12384. #define CERT_QUERY_FORMAT_BASE64_ENCODED 2
  12385. //the content is ascii hex encoded with "{ASN}" prefix
  12386. #define CERT_QUERY_FORMAT_ASN_ASCII_HEX_ENCODED 3
  12387. //-------------------------------------------------------------------------
  12388. //dwExpectedFormatTypeFlags for CryptQueryObject
  12389. //-------------------------------------------------------------------------
  12390. //the content is in binary format
  12391. #define CERT_QUERY_FORMAT_FLAG_BINARY \
  12392. ( 1 << CERT_QUERY_FORMAT_BINARY)
  12393. //the content is base64 encoded
  12394. #define CERT_QUERY_FORMAT_FLAG_BASE64_ENCODED \
  12395. ( 1 << CERT_QUERY_FORMAT_BASE64_ENCODED)
  12396. //the content is ascii hex encoded with "{ASN}" prefix
  12397. #define CERT_QUERY_FORMAT_FLAG_ASN_ASCII_HEX_ENCODED \
  12398. ( 1 << CERT_QUERY_FORMAT_ASN_ASCII_HEX_ENCODED)
  12399. //the content can be of any format
  12400. #define CERT_QUERY_FORMAT_FLAG_ALL \
  12401. CERT_QUERY_FORMAT_FLAG_BINARY | \
  12402. CERT_QUERY_FORMAT_FLAG_BASE64_ENCODED | \
  12403. CERT_QUERY_FORMAT_FLAG_ASN_ASCII_HEX_ENCODED
  12404. //
  12405. // Crypt32 Memory Management Routines. All Crypt32 API which return allocated
  12406. // buffers will do so via CryptMemAlloc, CryptMemRealloc. Clients can free
  12407. // those buffers using CryptMemFree. Also included is CryptMemSize
  12408. //
  12409. WINCRYPT32API
  12410. LPVOID
  12411. WINAPI
  12412. CryptMemAlloc (
  12413. IN ULONG cbSize
  12414. );
  12415. WINCRYPT32API
  12416. LPVOID
  12417. WINAPI
  12418. CryptMemRealloc (
  12419. IN LPVOID pv,
  12420. IN ULONG cbSize
  12421. );
  12422. WINCRYPT32API
  12423. VOID
  12424. WINAPI
  12425. CryptMemFree (
  12426. IN LPVOID pv
  12427. );
  12428. //
  12429. // Crypt32 Asynchronous Parameter Management Routines. All Crypt32 API which
  12430. // expose asynchronous mode operation use a Crypt32 Async Handle to pass
  12431. // around information about the operation e.g. callback routines. The
  12432. // following API are used for manipulation of the async handle
  12433. //
  12434. typedef HANDLE HCRYPTASYNC, *PHCRYPTASYNC;
  12435. typedef VOID (WINAPI *PFN_CRYPT_ASYNC_PARAM_FREE_FUNC) (
  12436. LPSTR pszParamOid,
  12437. LPVOID pvParam
  12438. );
  12439. WINCRYPT32API
  12440. BOOL
  12441. WINAPI
  12442. CryptCreateAsyncHandle (
  12443. IN DWORD dwFlags,
  12444. OUT PHCRYPTASYNC phAsync
  12445. );
  12446. WINCRYPT32API
  12447. BOOL
  12448. WINAPI
  12449. CryptSetAsyncParam (
  12450. IN HCRYPTASYNC hAsync,
  12451. IN LPSTR pszParamOid,
  12452. IN LPVOID pvParam,
  12453. IN OPTIONAL PFN_CRYPT_ASYNC_PARAM_FREE_FUNC pfnFree
  12454. );
  12455. WINCRYPT32API
  12456. BOOL
  12457. WINAPI
  12458. CryptGetAsyncParam (
  12459. IN HCRYPTASYNC hAsync,
  12460. IN LPSTR pszParamOid,
  12461. OUT LPVOID* ppvParam,
  12462. OUT OPTIONAL PFN_CRYPT_ASYNC_PARAM_FREE_FUNC* ppfnFree
  12463. );
  12464. WINCRYPT32API
  12465. BOOL
  12466. WINAPI
  12467. CryptCloseAsyncHandle (
  12468. IN HCRYPTASYNC hAsync
  12469. );
  12470. //
  12471. // Crypt32 Remote Object Retrieval Routines. This API allows retrieval of
  12472. // remote PKI objects where the location is given by an URL. The remote
  12473. // object retrieval manager exposes two provider models. One is the "Scheme
  12474. // Provider" model which allows for installable protocol providers as defined
  12475. // by the URL scheme e.g. ldap, http, ftp. The scheme provider entry point is
  12476. // the same as the CryptRetrieveObjectByUrl however the *ppvObject returned
  12477. // is ALWAYS a counted array of encoded bits (one per object retrieved). The
  12478. // second provider model is the "Context Provider" model which allows for
  12479. // installable creators of CAPI2 context handles (objects) based on the
  12480. // retrieved encoded bits. These are dispatched based on the object OID given
  12481. // in the call to CryptRetrieveObjectByUrl.
  12482. //
  12483. typedef struct _CRYPT_BLOB_ARRAY {
  12484. DWORD cBlob;
  12485. PCRYPT_DATA_BLOB rgBlob;
  12486. } CRYPT_BLOB_ARRAY, *PCRYPT_BLOB_ARRAY;
  12487. typedef struct _CRYPT_CREDENTIALS {
  12488. DWORD cbSize;
  12489. LPCSTR pszCredentialsOid;
  12490. LPVOID pvCredentials;
  12491. } CRYPT_CREDENTIALS, *PCRYPT_CREDENTIALS;
  12492. #define CREDENTIAL_OID_PASSWORD_CREDENTIALS_A ((LPCSTR)1)
  12493. #define CREDENTIAL_OID_PASSWORD_CREDENTIALS_W ((LPCSTR)2)
  12494. #ifdef UNICODE
  12495. #define CREDENTIAL_OID_PASSWORD_CREDENTIALS CREDENTIAL_OID_PASSWORD_CREDENTIALS_W
  12496. #else
  12497. #define CREDENTIAL_OID_PASSWORD_CREDENTIALS CREDENTIAL_OID_PASSWORD_CREDENTIALS_A
  12498. #endif //UNICODE
  12499. typedef struct _CRYPT_PASSWORD_CREDENTIALSA {
  12500. DWORD cbSize;
  12501. LPSTR pszUsername;
  12502. LPSTR pszPassword;
  12503. } CRYPT_PASSWORD_CREDENTIALSA, *PCRYPT_PASSWORD_CREDENTIALSA;
  12504. typedef struct _CRYPT_PASSWORD_CREDENTIALSW {
  12505. DWORD cbSize;
  12506. LPWSTR pszUsername;
  12507. LPWSTR pszPassword;
  12508. } CRYPT_PASSWORD_CREDENTIALSW, *PCRYPT_PASSWORD_CREDENTIALSW;
  12509. #ifdef UNICODE
  12510. typedef CRYPT_PASSWORD_CREDENTIALSW CRYPT_PASSWORD_CREDENTIALS;
  12511. typedef PCRYPT_PASSWORD_CREDENTIALSW PCRYPT_PASSWORD_CREDENTIALS;
  12512. #else
  12513. typedef CRYPT_PASSWORD_CREDENTIALSA CRYPT_PASSWORD_CREDENTIALS;
  12514. typedef PCRYPT_PASSWORD_CREDENTIALSA PCRYPT_PASSWORD_CREDENTIALS;
  12515. #endif // UNICODE
  12516. //
  12517. // Scheme Provider Signatures
  12518. //
  12519. #define SCHEME_OID_RETRIEVE_ENCODED_OBJECT_FUNC "SchemeDllRetrieveEncodedObject"
  12520. typedef VOID (WINAPI *PFN_FREE_ENCODED_OBJECT_FUNC) (
  12521. LPCSTR pszObjectOid,
  12522. PCRYPT_BLOB_ARRAY pObject,
  12523. LPVOID pvFreeContext
  12524. );
  12525. //
  12526. // SchemeDllRetrieveEncodedObject has the following signature:
  12527. //
  12528. // BOOL WINAPI SchemeDllRetrieveEncodedObject (
  12529. // IN LPCSTR pszUrl,
  12530. // IN LPCSTR pszObjectOid,
  12531. // IN DWORD dwRetrievalFlags,
  12532. // IN DWORD dwTimeout, // milliseconds
  12533. // OUT PCRYPT_BLOB_ARRAY pObject,
  12534. // OUT PFN_FREE_ENCODED_OBJECT_FUNC* ppfnFreeObject,
  12535. // OUT LPVOID* ppvFreeContext,
  12536. // IN HCRYPTASYNC hAsyncRetrieve,
  12537. // IN PCRYPT_CREDENTIALS pCredentials,
  12538. // IN PCRYPT_RETRIEVE_AUX_INFO pAuxInfo
  12539. // )
  12540. //
  12541. //
  12542. // Context Provider Signatures
  12543. //
  12544. #define CONTEXT_OID_CREATE_OBJECT_CONTEXT_FUNC "ContextDllCreateObjectContext"
  12545. #define CONTEXT_OID_CERTIFICATE ((LPCSTR)1)
  12546. #define CONTEXT_OID_CRL ((LPCSTR)2)
  12547. #define CONTEXT_OID_CTL ((LPCSTR)3)
  12548. #define CONTEXT_OID_PKCS7 ((LPCSTR)4)
  12549. #define CONTEXT_OID_CAPI2_ANY ((LPCSTR)5)
  12550. //
  12551. // ContextDllCreateObjectContext has the following signature:
  12552. //
  12553. // BOOL WINAPI ContextDllCreateObjectContext (
  12554. // IN LPCSTR pszObjectOid,
  12555. // IN DWORD dwRetrievalFlags,
  12556. // IN PCRYPT_BLOB_ARRAY pObject,
  12557. // OUT LPVOID* ppvContext
  12558. // )
  12559. //
  12560. //
  12561. // Remote Object Retrieval API
  12562. //
  12563. //
  12564. // Retrieval flags
  12565. //
  12566. #define CRYPT_RETRIEVE_MULTIPLE_OBJECTS 0x00000001
  12567. #define CRYPT_CACHE_ONLY_RETRIEVAL 0x00000002
  12568. #define CRYPT_WIRE_ONLY_RETRIEVAL 0x00000004
  12569. #define CRYPT_DONT_CACHE_RESULT 0x00000008
  12570. #define CRYPT_ASYNC_RETRIEVAL 0x00000010
  12571. #define CRYPT_STICKY_CACHE_RETRIEVAL 0x00001000
  12572. #define CRYPT_LDAP_SCOPE_BASE_ONLY_RETRIEVAL 0x00002000
  12573. #define CRYPT_OFFLINE_CHECK_RETRIEVAL 0x00004000
  12574. // When the following flag is set, the following 2 NULL terminated ascii
  12575. // strings are inserted at the beginning of each returned blob:
  12576. // "%d\0%s\0", dwEntryIndex, pszAttribute
  12577. //
  12578. // The first dwEntryIndex is 0, "0\0".
  12579. //
  12580. // When set, pszObjectOid must be NULL, so that a PCRYPT_BLOB_ARRAY is returned.
  12581. #define CRYPT_LDAP_INSERT_ENTRY_ATTRIBUTE 0x00008000
  12582. // Set this flag to digitally sign all of the ldap traffic to and from a
  12583. // Windows 2000 LDAP server using the Kerberos authentication protocol.
  12584. // This feature provides integrity required by some applications.
  12585. #define CRYPT_LDAP_SIGN_RETRIEVAL 0x00010000
  12586. // Set this flag to inhibit automatic authentication handling. See the
  12587. // wininet flag, INTERNET_FLAG_NO_AUTH, for more details.
  12588. #define CRYPT_NO_AUTH_RETRIEVAL 0x00020000
  12589. // Performs an A-Record only DNS lookup on the supplied host string.
  12590. // This prevents bogus DNS queries from being generated when resolving host
  12591. // names. Use this flag whenever passing a hostname as opposed to a
  12592. // domain name for the hostname parameter.
  12593. //
  12594. // See LDAP_OPT_AREC_EXCLUSIVE defined in winldap.h for more details.
  12595. #define CRYPT_LDAP_AREC_EXCLUSIVE_RETRIEVAL 0x00040000
  12596. //
  12597. // Data verification retrieval flags
  12598. //
  12599. // CRYPT_VERIFY_CONTEXT_SIGNATURE is used to get signature verification
  12600. // on the context created. In this case pszObjectOid must be non-NULL and
  12601. // pvVerify points to the signer certificate context
  12602. //
  12603. // CRYPT_VERIFY_DATA_HASH is used to get verification of the blob data
  12604. // retrieved by the protocol. The pvVerify points to an URL_DATA_HASH
  12605. // structure (TBD)
  12606. //
  12607. #define CRYPT_VERIFY_CONTEXT_SIGNATURE 0x00000020
  12608. #define CRYPT_VERIFY_DATA_HASH 0x00000040
  12609. //
  12610. // Time Valid Object flags
  12611. //
  12612. #define CRYPT_KEEP_TIME_VALID 0x00000080
  12613. #define CRYPT_DONT_VERIFY_SIGNATURE 0x00000100
  12614. #define CRYPT_DONT_CHECK_TIME_VALIDITY 0x00000200
  12615. // The default checks if ftNextUpdate >= ftValidFor. Set this flag to
  12616. // check if ftThisUpdate >= ftValidFor.
  12617. #define CRYPT_CHECK_FRESHNESS_TIME_VALIDITY 0x00000400
  12618. #define CRYPT_ACCUMULATIVE_TIMEOUT 0x00000800
  12619. typedef struct _CRYPT_RETRIEVE_AUX_INFO {
  12620. DWORD cbSize;
  12621. FILETIME *pLastSyncTime;
  12622. } CRYPT_RETRIEVE_AUX_INFO, *PCRYPT_RETRIEVE_AUX_INFO;
  12623. WINCRYPT32API
  12624. BOOL
  12625. WINAPI
  12626. CryptRetrieveObjectByUrlA (
  12627. IN LPCSTR pszUrl,
  12628. IN LPCSTR pszObjectOid,
  12629. IN DWORD dwRetrievalFlags,
  12630. IN DWORD dwTimeout, // milliseconds
  12631. OUT LPVOID* ppvObject,
  12632. IN HCRYPTASYNC hAsyncRetrieve,
  12633. IN OPTIONAL PCRYPT_CREDENTIALS pCredentials,
  12634. IN OPTIONAL LPVOID pvVerify,
  12635. IN OPTIONAL PCRYPT_RETRIEVE_AUX_INFO pAuxInfo
  12636. );
  12637. WINCRYPT32API
  12638. BOOL
  12639. WINAPI
  12640. CryptRetrieveObjectByUrlW (
  12641. IN LPCWSTR pszUrl,
  12642. IN LPCSTR pszObjectOid,
  12643. IN DWORD dwRetrievalFlags,
  12644. IN DWORD dwTimeout, // milliseconds
  12645. OUT LPVOID* ppvObject,
  12646. IN HCRYPTASYNC hAsyncRetrieve,
  12647. IN OPTIONAL PCRYPT_CREDENTIALS pCredentials,
  12648. IN OPTIONAL LPVOID pvVerify,
  12649. IN OPTIONAL PCRYPT_RETRIEVE_AUX_INFO pAuxInfo
  12650. );
  12651. #ifdef UNICODE
  12652. #define CryptRetrieveObjectByUrl CryptRetrieveObjectByUrlW
  12653. #else
  12654. #define CryptRetrieveObjectByUrl CryptRetrieveObjectByUrlA
  12655. #endif // !UNICODE
  12656. //
  12657. // Call back function to cancel object retrieval
  12658. //
  12659. // The function can be installed on a per thread basis.
  12660. // If CryptInstallCancelRetrieval is called for multiple times, only the most recent
  12661. // installation will be kept.
  12662. //
  12663. // This is only effective for http, https, gopher, and ftp protocol.
  12664. // It is ignored by the rest of the protocols.
  12665. typedef BOOL (WINAPI *PFN_CRYPT_CANCEL_RETRIEVAL)(
  12666. IN DWORD dwFlags,
  12667. IN void *pvArg
  12668. );
  12669. //
  12670. // PFN_CRYPT_CANCEL_RETRIEVAL
  12671. //
  12672. // This function should return FALSE when the object retrieval should be continued
  12673. // and return TRUE when the object retrieval should be cancelled.
  12674. //
  12675. WINCRYPT32API
  12676. BOOL
  12677. WINAPI
  12678. CryptInstallCancelRetrieval(
  12679. IN PFN_CRYPT_CANCEL_RETRIEVAL pfnCancel,
  12680. IN const void *pvArg,
  12681. IN DWORD dwFlags,
  12682. IN void *pvReserved
  12683. );
  12684. WINCRYPT32API
  12685. BOOL
  12686. WINAPI
  12687. CryptUninstallCancelRetrieval(
  12688. IN DWORD dwFlags,
  12689. IN void *pvReserved
  12690. );
  12691. WINCRYPT32API
  12692. BOOL
  12693. WINAPI
  12694. CryptCancelAsyncRetrieval (
  12695. HCRYPTASYNC hAsyncRetrieval
  12696. );
  12697. //
  12698. // Remote Object Async Retrieval parameters
  12699. //
  12700. //
  12701. // A client that wants to be notified of asynchronous object retrieval
  12702. // completion sets this parameter on the async handle
  12703. //
  12704. #define CRYPT_PARAM_ASYNC_RETRIEVAL_COMPLETION ((LPCSTR)1)
  12705. typedef VOID (WINAPI *PFN_CRYPT_ASYNC_RETRIEVAL_COMPLETION_FUNC) (
  12706. IN LPVOID pvCompletion,
  12707. IN DWORD dwCompletionCode,
  12708. IN LPCSTR pszUrl,
  12709. IN LPSTR pszObjectOid,
  12710. IN LPVOID pvObject
  12711. );
  12712. typedef struct _CRYPT_ASYNC_RETRIEVAL_COMPLETION {
  12713. PFN_CRYPT_ASYNC_RETRIEVAL_COMPLETION_FUNC pfnCompletion;
  12714. LPVOID pvCompletion;
  12715. } CRYPT_ASYNC_RETRIEVAL_COMPLETION, *PCRYPT_ASYNC_RETRIEVAL_COMPLETION;
  12716. //
  12717. // This function is set on the async handle by a scheme provider that
  12718. // supports asynchronous retrieval
  12719. //
  12720. #define CRYPT_PARAM_CANCEL_ASYNC_RETRIEVAL ((LPCSTR)2)
  12721. typedef BOOL (WINAPI *PFN_CANCEL_ASYNC_RETRIEVAL_FUNC) (
  12722. HCRYPTASYNC hAsyncRetrieve
  12723. );
  12724. //
  12725. // Get the locator for a CAPI object
  12726. //
  12727. #define CRYPT_GET_URL_FROM_PROPERTY 0x00000001
  12728. #define CRYPT_GET_URL_FROM_EXTENSION 0x00000002
  12729. #define CRYPT_GET_URL_FROM_UNAUTH_ATTRIBUTE 0x00000004
  12730. #define CRYPT_GET_URL_FROM_AUTH_ATTRIBUTE 0x00000008
  12731. typedef struct _CRYPT_URL_ARRAY {
  12732. DWORD cUrl;
  12733. LPWSTR* rgwszUrl;
  12734. } CRYPT_URL_ARRAY, *PCRYPT_URL_ARRAY;
  12735. typedef struct _CRYPT_URL_INFO {
  12736. DWORD cbSize;
  12737. // Seconds between syncs
  12738. DWORD dwSyncDeltaTime;
  12739. // Returned URLs may be grouped. For instance, groups of cross cert
  12740. // distribution points. Each distribution point may have multiple
  12741. // URLs, (LDAP and HTTP scheme).
  12742. DWORD cGroup;
  12743. DWORD *rgcGroupEntry;
  12744. } CRYPT_URL_INFO, *PCRYPT_URL_INFO;
  12745. WINCRYPT32API
  12746. BOOL
  12747. WINAPI
  12748. CryptGetObjectUrl (
  12749. IN LPCSTR pszUrlOid,
  12750. IN LPVOID pvPara,
  12751. IN DWORD dwFlags,
  12752. OUT OPTIONAL PCRYPT_URL_ARRAY pUrlArray,
  12753. IN OUT DWORD* pcbUrlArray,
  12754. OUT OPTIONAL PCRYPT_URL_INFO pUrlInfo,
  12755. IN OUT OPTIONAL DWORD* pcbUrlInfo,
  12756. IN OPTIONAL LPVOID pvReserved
  12757. );
  12758. #define URL_OID_GET_OBJECT_URL_FUNC "UrlDllGetObjectUrl"
  12759. //
  12760. // UrlDllGetObjectUrl has the same signature as CryptGetObjectUrl
  12761. //
  12762. //
  12763. // URL_OID_CERTIFICATE_ISSUER
  12764. //
  12765. // pvPara == PCCERT_CONTEXT, certificate whose issuer's URL is being requested
  12766. //
  12767. // This will be retrieved from the authority info access extension or property
  12768. // on the certificate
  12769. //
  12770. // URL_OID_CERTIFICATE_CRL_DIST_POINT
  12771. //
  12772. // pvPara == PCCERT_CONTEXT, certificate whose CRL distribution point is being
  12773. // requested
  12774. //
  12775. // This will be retrieved from the CRL distribution point extension or property
  12776. // on the certificate
  12777. //
  12778. // URL_OID_CTL_ISSUER
  12779. //
  12780. // pvPara == PCCTL_CONTEXT, Signer Index, CTL whose issuer's URL (identified
  12781. // by the signer index) is being requested
  12782. //
  12783. // This will be retrieved from an authority info access attribute method encoded
  12784. // in each signer info in the PKCS7 (CTL)
  12785. //
  12786. // URL_OID_CTL_NEXT_UPDATE
  12787. //
  12788. // pvPara == PCCTL_CONTEXT, Signer Index, CTL whose next update URL is being
  12789. // requested and an optional signer index in case we need to check signer
  12790. // info attributes
  12791. //
  12792. // This will be retrieved from an authority info access CTL extension, property,
  12793. // or signer info attribute method
  12794. //
  12795. // URL_OID_CRL_ISSUER
  12796. //
  12797. // pvPara == PCCRL_CONTEXT, CRL whose issuer's URL is being requested
  12798. //
  12799. // This will be retrieved from a property on the CRL which has been inherited
  12800. // from the subject cert (either from the subject cert issuer or the subject
  12801. // cert distribution point extension). It will be encoded as an authority
  12802. // info access extension method.
  12803. //
  12804. // URL_OID_CERTIFICATE_FRESHEST_CRL
  12805. //
  12806. // pvPara == PCCERT_CONTEXT, certificate whose freshest CRL distribution point
  12807. // is being requested
  12808. //
  12809. // This will be retrieved from the freshest CRL extension or property
  12810. // on the certificate
  12811. //
  12812. // URL_OID_CRL_FRESHEST_CRL
  12813. //
  12814. // pvPara == PCCERT_CRL_CONTEXT_PAIR, certificate's base CRL whose
  12815. // freshest CRL distribution point is being requested
  12816. //
  12817. // This will be retrieved from the freshest CRL extension or property
  12818. // on the CRL
  12819. //
  12820. // URL_OID_CROSS_CERT_DIST_POINT
  12821. //
  12822. // pvPara == PCCERT_CONTEXT, certificate whose cross certificate distribution
  12823. // point is being requested
  12824. //
  12825. // This will be retrieved from the cross certificate distribution point
  12826. // extension or property on the certificate
  12827. //
  12828. #define URL_OID_CERTIFICATE_ISSUER ((LPCSTR)1)
  12829. #define URL_OID_CERTIFICATE_CRL_DIST_POINT ((LPCSTR)2)
  12830. #define URL_OID_CTL_ISSUER ((LPCSTR)3)
  12831. #define URL_OID_CTL_NEXT_UPDATE ((LPCSTR)4)
  12832. #define URL_OID_CRL_ISSUER ((LPCSTR)5)
  12833. #define URL_OID_CERTIFICATE_FRESHEST_CRL ((LPCSTR)6)
  12834. #define URL_OID_CRL_FRESHEST_CRL ((LPCSTR)7)
  12835. #define URL_OID_CROSS_CERT_DIST_POINT ((LPCSTR)8)
  12836. typedef struct _CERT_CRL_CONTEXT_PAIR {
  12837. PCCERT_CONTEXT pCertContext;
  12838. PCCRL_CONTEXT pCrlContext;
  12839. } CERT_CRL_CONTEXT_PAIR, *PCERT_CRL_CONTEXT_PAIR;
  12840. typedef const CERT_CRL_CONTEXT_PAIR *PCCERT_CRL_CONTEXT_PAIR;
  12841. //
  12842. // Get a time valid CAPI2 object
  12843. //
  12844. WINCRYPT32API
  12845. BOOL
  12846. WINAPI
  12847. CryptGetTimeValidObject (
  12848. IN LPCSTR pszTimeValidOid,
  12849. IN LPVOID pvPara,
  12850. IN PCCERT_CONTEXT pIssuer,
  12851. IN OPTIONAL LPFILETIME pftValidFor,
  12852. IN DWORD dwFlags,
  12853. IN DWORD dwTimeout, // milliseconds
  12854. OUT OPTIONAL LPVOID* ppvObject,
  12855. IN OPTIONAL PCRYPT_CREDENTIALS pCredentials,
  12856. IN OPTIONAL LPVOID pvReserved
  12857. );
  12858. #define TIME_VALID_OID_GET_OBJECT_FUNC "TimeValidDllGetObject"
  12859. //
  12860. // TimeValidDllGetObject has the same signature as CryptGetTimeValidObject
  12861. //
  12862. //
  12863. // TIME_VALID_OID_GET_CTL
  12864. //
  12865. // pvPara == PCCTL_CONTEXT, the current CTL
  12866. //
  12867. // TIME_VALID_OID_GET_CRL
  12868. //
  12869. // pvPara == PCCRL_CONTEXT, the current CRL
  12870. //
  12871. // TIME_VALID_OID_GET_CRL_FROM_CERT
  12872. //
  12873. // pvPara == PCCERT_CONTEXT, the subject cert
  12874. //
  12875. // TIME_VALID_OID_GET_FRESHEST_CRL_FROM_CERT
  12876. //
  12877. // pvPara == PCCERT_CONTEXT, the subject cert
  12878. //
  12879. // TIME_VALID_OID_GET_FRESHEST_CRL_FROM_CRL
  12880. //
  12881. // pvPara == PCCERT_CRL_CONTEXT_PAIR, the subject cert and its base CRL
  12882. //
  12883. #define TIME_VALID_OID_GET_CTL ((LPCSTR)1)
  12884. #define TIME_VALID_OID_GET_CRL ((LPCSTR)2)
  12885. #define TIME_VALID_OID_GET_CRL_FROM_CERT ((LPCSTR)3)
  12886. #define TIME_VALID_OID_GET_FRESHEST_CRL_FROM_CERT ((LPCSTR)4)
  12887. #define TIME_VALID_OID_GET_FRESHEST_CRL_FROM_CRL ((LPCSTR)5)
  12888. WINCRYPT32API
  12889. BOOL
  12890. WINAPI
  12891. CryptFlushTimeValidObject (
  12892. IN LPCSTR pszFlushTimeValidOid,
  12893. IN LPVOID pvPara,
  12894. IN PCCERT_CONTEXT pIssuer,
  12895. IN DWORD dwFlags,
  12896. IN LPVOID pvReserved
  12897. );
  12898. #define TIME_VALID_OID_FLUSH_OBJECT_FUNC "TimeValidDllFlushObject"
  12899. //
  12900. // TimeValidDllFlushObject has the same signature as CryptFlushTimeValidObject
  12901. //
  12902. //
  12903. // TIME_VALID_OID_FLUSH_CTL
  12904. //
  12905. // pvPara == PCCTL_CONTEXT, the CTL to flush
  12906. //
  12907. // TIME_VALID_OID_FLUSH_CRL
  12908. //
  12909. // pvPara == PCCRL_CONTEXT, the CRL to flush
  12910. //
  12911. // TIME_VALID_OID_FLUSH_CRL_FROM_CERT
  12912. //
  12913. // pvPara == PCCERT_CONTEXT, the subject cert's CRL to flush
  12914. //
  12915. // TIME_VALID_OID_FLUSH_FRESHEST_CRL_FROM_CERT
  12916. //
  12917. // pvPara == PCCERT_CONTEXT, the subject cert's freshest CRL to flush
  12918. //
  12919. // TIME_VALID_OID_FLUSH_FRESHEST_CRL_FROM_CRL
  12920. //
  12921. // pvPara == PCCERT_CRL_CONTEXT_PAIR, the subject cert and its base CRL's
  12922. // freshest CRL to flush
  12923. //
  12924. #define TIME_VALID_OID_FLUSH_CTL ((LPCSTR)1)
  12925. #define TIME_VALID_OID_FLUSH_CRL ((LPCSTR)2)
  12926. #define TIME_VALID_OID_FLUSH_CRL_FROM_CERT ((LPCSTR)3)
  12927. #define TIME_VALID_OID_FLUSH_FRESHEST_CRL_FROM_CERT ((LPCSTR)4)
  12928. #define TIME_VALID_OID_FLUSH_FRESHEST_CRL_FROM_CRL ((LPCSTR)5)
  12929. //-------------------------------------------------------------------------
  12930. // Data Protection APIs
  12931. //-------------------------------------------------------------------------
  12932. //
  12933. // Data protection APIs enable applications to easily secure data.
  12934. //
  12935. // The base provider provides protection based on the users' logon
  12936. // credentials. The data secured with these APIs follow the same
  12937. // roaming characteristics as HKCU -- if HKCU roams, the data
  12938. // protected by the base provider may roam as well. This makes
  12939. // the API ideal for the munging of data stored in the registry.
  12940. //
  12941. //
  12942. // Prompt struct -- what to tell users about the access
  12943. //
  12944. typedef struct _CRYPTPROTECT_PROMPTSTRUCT
  12945. {
  12946. DWORD cbSize;
  12947. DWORD dwPromptFlags;
  12948. HWND hwndApp;
  12949. LPCWSTR szPrompt;
  12950. } CRYPTPROTECT_PROMPTSTRUCT, *PCRYPTPROTECT_PROMPTSTRUCT;
  12951. //
  12952. // base provider action
  12953. //
  12954. #define CRYPTPROTECT_DEFAULT_PROVIDER { 0xdf9d8cd0, 0x1501, 0x11d1, {0x8c, 0x7a, 0x00, 0xc0, 0x4f, 0xc2, 0x97, 0xeb} }
  12955. //
  12956. // CryptProtect PromptStruct dwPromtFlags
  12957. //
  12958. //
  12959. // prompt on unprotect
  12960. #define CRYPTPROTECT_PROMPT_ON_UNPROTECT 0x1 // 1<<0
  12961. //
  12962. // prompt on protect
  12963. #define CRYPTPROTECT_PROMPT_ON_PROTECT 0x2 // 1<<1
  12964. #define CRYPTPROTECT_PROMPT_RESERVED 0x04 // reserved, do not use.
  12965. //
  12966. // default to strong variant UI protection (user supplied password currently).
  12967. #define CRYPTPROTECT_PROMPT_STRONG 0x08 // 1<<3
  12968. //
  12969. // require strong variant UI protection (user supplied password currently).
  12970. #define CRYPTPROTECT_PROMPT_REQUIRE_STRONG 0x10 // 1<<4
  12971. //
  12972. // CryptProtectData and CryptUnprotectData dwFlags
  12973. //
  12974. // for remote-access situations where ui is not an option
  12975. // if UI was specified on protect or unprotect operation, the call
  12976. // will fail and GetLastError() will indicate ERROR_PASSWORD_RESTRICTION
  12977. #define CRYPTPROTECT_UI_FORBIDDEN 0x1
  12978. //
  12979. // per machine protected data -- any user on machine where CryptProtectData
  12980. // took place may CryptUnprotectData
  12981. #define CRYPTPROTECT_LOCAL_MACHINE 0x4
  12982. //
  12983. // force credential synchronize during CryptProtectData()
  12984. // Synchronize is only operation that occurs during this operation
  12985. #define CRYPTPROTECT_CRED_SYNC 0x8
  12986. //
  12987. // Generate an Audit on protect and unprotect operations
  12988. //
  12989. #define CRYPTPROTECT_AUDIT 0x10
  12990. //
  12991. // Protect data with a non-recoverable key
  12992. //
  12993. #define CRYPTPROTECT_NO_RECOVERY 0x20
  12994. //
  12995. // Verify the protection of a protected blob
  12996. //
  12997. #define CRYPTPROTECT_VERIFY_PROTECTION 0x40
  12998. //
  12999. // Regenerate the local machine protection
  13000. //
  13001. #define CRYPTPROTECT_CRED_REGENERATE 0x80
  13002. // flags reserved for system use
  13003. #define CRYPTPROTECT_FIRST_RESERVED_FLAGVAL 0x0FFFFFFF
  13004. #define CRYPTPROTECT_LAST_RESERVED_FLAGVAL 0xFFFFFFFF
  13005. //
  13006. // flags specific to base provider
  13007. //
  13008. WINCRYPT32API
  13009. BOOL
  13010. WINAPI
  13011. CryptProtectData(
  13012. IN DATA_BLOB* pDataIn,
  13013. IN LPCWSTR szDataDescr,
  13014. IN OPTIONAL DATA_BLOB* pOptionalEntropy,
  13015. IN PVOID pvReserved,
  13016. IN OPTIONAL CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct,
  13017. IN DWORD dwFlags,
  13018. OUT DATA_BLOB* pDataOut // out encr blob
  13019. );
  13020. WINCRYPT32API
  13021. BOOL
  13022. WINAPI
  13023. CryptUnprotectData(
  13024. IN DATA_BLOB* pDataIn, // in encr blob
  13025. OUT OPTIONAL LPWSTR* ppszDataDescr, // out
  13026. IN OPTIONAL DATA_BLOB* pOptionalEntropy,
  13027. IN PVOID pvReserved,
  13028. IN OPTIONAL CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct,
  13029. IN DWORD dwFlags,
  13030. OUT DATA_BLOB* pDataOut
  13031. );
  13032. //+=========================================================================
  13033. // Helper functions to build certificates
  13034. //==========================================================================
  13035. //+-------------------------------------------------------------------------
  13036. //
  13037. // Builds a self-signed certificate and returns a PCCERT_CONTEXT representing
  13038. // the certificate. A hProv must be specified to build the cert context.
  13039. //
  13040. // pSubjectIssuerBlob is the DN for the certifcate. If an alternate subject
  13041. // name is desired it must be specified as an extension in the pExtensions
  13042. // parameter. pSubjectIssuerBlob can NOT be NULL, so minimually an empty DN
  13043. // must be specified.
  13044. //
  13045. // By default:
  13046. // pKeyProvInfo - The CSP is queried for the KeyProvInfo parameters. Only the Provider,
  13047. // Provider Type and Container is queried. Many CSPs don't support these
  13048. // queries and will cause a failure. In such cases the pKeyProvInfo
  13049. // must be specified (RSA BASE works fine).
  13050. //
  13051. // pSignatureAlgorithm - will default to SHA1RSA
  13052. // pStartTime will default to the current time
  13053. // pEndTime will default to 1 year
  13054. // pEntensions will be empty.
  13055. //
  13056. // The returned PCCERT_CONTEXT will reference the private keys by setting the
  13057. // CERT_KEY_PROV_INFO_PROP_ID. However, if this property is not desired specify the
  13058. // CERT_CREATE_SELFSIGN_NO_KEY_INFO in dwFlags.
  13059. //
  13060. // If the cert being built is only a dummy placeholder cert for speed it may not
  13061. // need to be signed. Signing of the cert is skipped if CERT_CREATE_SELFSIGN_NO_SIGN
  13062. // is specified in dwFlags.
  13063. //
  13064. //--------------------------------------------------------------------------
  13065. WINCRYPT32API
  13066. PCCERT_CONTEXT
  13067. WINAPI
  13068. CertCreateSelfSignCertificate(
  13069. IN HCRYPTPROV hProv,
  13070. IN PCERT_NAME_BLOB pSubjectIssuerBlob,
  13071. IN DWORD dwFlags,
  13072. OPTIONAL PCRYPT_KEY_PROV_INFO pKeyProvInfo,
  13073. OPTIONAL PCRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm,
  13074. OPTIONAL PSYSTEMTIME pStartTime,
  13075. OPTIONAL PSYSTEMTIME pEndTime,
  13076. OPTIONAL PCERT_EXTENSIONS pExtensions
  13077. );
  13078. #define CERT_CREATE_SELFSIGN_NO_SIGN 1
  13079. #define CERT_CREATE_SELFSIGN_NO_KEY_INFO 2
  13080. //+=========================================================================
  13081. // Key Identifier Property Data Structures and APIs
  13082. //==========================================================================
  13083. //+-------------------------------------------------------------------------
  13084. // Get the property for the specified Key Identifier.
  13085. //
  13086. // The Key Identifier is the SHA1 hash of the encoded CERT_PUBLIC_KEY_INFO.
  13087. // The Key Identifier for a certificate can be obtained by getting the
  13088. // certificate's CERT_KEY_IDENTIFIER_PROP_ID. The
  13089. // CryptCreateKeyIdentifierFromCSP API can be called to create the Key
  13090. // Identifier from a CSP Public Key Blob.
  13091. //
  13092. // A Key Identifier can have the same properties as a certificate context.
  13093. // CERT_KEY_PROV_INFO_PROP_ID is the property of most interest.
  13094. // For CERT_KEY_PROV_INFO_PROP_ID, pvData points to a CRYPT_KEY_PROV_INFO
  13095. // structure. Elements pointed to by fields in the pvData structure follow the
  13096. // structure. Therefore, *pcbData will exceed the size of the structure.
  13097. //
  13098. // If CRYPT_KEYID_ALLOC_FLAG is set, then, *pvData is updated with a
  13099. // pointer to allocated memory. LocalFree() must be called to free the
  13100. // allocated memory.
  13101. //
  13102. // By default, searches the CurrentUser's list of Key Identifiers.
  13103. // CRYPT_KEYID_MACHINE_FLAG can be set to search the LocalMachine's list
  13104. // of Key Identifiers. When CRYPT_KEYID_MACHINE_FLAG is set, pwszComputerName
  13105. // can also be set to specify the name of a remote computer to be searched
  13106. // instead of the local machine.
  13107. //--------------------------------------------------------------------------
  13108. WINCRYPT32API
  13109. BOOL
  13110. WINAPI
  13111. CryptGetKeyIdentifierProperty(
  13112. IN const CRYPT_HASH_BLOB *pKeyIdentifier,
  13113. IN DWORD dwPropId,
  13114. IN DWORD dwFlags,
  13115. IN OPTIONAL LPCWSTR pwszComputerName,
  13116. IN OPTIONAL void *pvReserved,
  13117. OUT void *pvData,
  13118. IN OUT DWORD *pcbData
  13119. );
  13120. // When the following flag is set, searches the LocalMachine instead of the
  13121. // CurrentUser. This flag is applicable to all the KeyIdentifierProperty APIs.
  13122. #define CRYPT_KEYID_MACHINE_FLAG 0x00000020
  13123. // When the following flag is set, *pvData is updated with a pointer to
  13124. // allocated memory. LocalFree() must be called to free the allocated memory.
  13125. #define CRYPT_KEYID_ALLOC_FLAG 0x00008000
  13126. //+-------------------------------------------------------------------------
  13127. // Set the property for the specified Key Identifier.
  13128. //
  13129. // For CERT_KEY_PROV_INFO_PROP_ID pvData points to the
  13130. // CRYPT_KEY_PROV_INFO data structure. For all other properties, pvData
  13131. // points to a CRYPT_DATA_BLOB.
  13132. //
  13133. // Setting pvData == NULL, deletes the property.
  13134. //
  13135. // Set CRYPT_KEYID_MACHINE_FLAG to set the property for a LocalMachine
  13136. // Key Identifier. Set pwszComputerName, to select a remote computer.
  13137. //
  13138. // If CRYPT_KEYID_DELETE_FLAG is set, the Key Identifier and all its
  13139. // properties is deleted.
  13140. //
  13141. // If CRYPT_KEYID_SET_NEW_FLAG is set, the set fails if the property already
  13142. // exists. For an existing property, FALSE is returned with LastError set to
  13143. // CRYPT_E_EXISTS.
  13144. //--------------------------------------------------------------------------
  13145. WINCRYPT32API
  13146. BOOL
  13147. WINAPI
  13148. CryptSetKeyIdentifierProperty(
  13149. IN const CRYPT_HASH_BLOB *pKeyIdentifier,
  13150. IN DWORD dwPropId,
  13151. IN DWORD dwFlags,
  13152. IN OPTIONAL LPCWSTR pwszComputerName,
  13153. IN OPTIONAL void *pvReserved,
  13154. IN const void *pvData
  13155. );
  13156. // When the following flag is set, the Key Identifier and all its properties
  13157. // are deleted.
  13158. #define CRYPT_KEYID_DELETE_FLAG 0x00000010
  13159. // When the following flag is set, the set fails if the property already
  13160. // exists.
  13161. #define CRYPT_KEYID_SET_NEW_FLAG 0x00002000
  13162. //+-------------------------------------------------------------------------
  13163. // For CERT_KEY_PROV_INFO_PROP_ID, rgppvData[] points to a
  13164. // CRYPT_KEY_PROV_INFO.
  13165. //
  13166. // Return FALSE to stop the enumeration.
  13167. //--------------------------------------------------------------------------
  13168. typedef BOOL (WINAPI *PFN_CRYPT_ENUM_KEYID_PROP)(
  13169. IN const CRYPT_HASH_BLOB *pKeyIdentifier,
  13170. IN DWORD dwFlags,
  13171. IN void *pvReserved,
  13172. IN void *pvArg,
  13173. IN DWORD cProp,
  13174. IN DWORD *rgdwPropId,
  13175. IN void **rgpvData,
  13176. IN DWORD *rgcbData
  13177. );
  13178. //+-------------------------------------------------------------------------
  13179. // Enumerate the Key Identifiers.
  13180. //
  13181. // If pKeyIdentifier is NULL, enumerates all Key Identifers. Otherwise,
  13182. // calls the callback for the specified KeyIdentifier. If dwPropId is
  13183. // 0, calls the callback with all the properties. Otherwise, only calls
  13184. // the callback with the specified property (cProp = 1).
  13185. // Furthermore, when dwPropId is specified, skips KeyIdentifiers not
  13186. // having the property.
  13187. //
  13188. // Set CRYPT_KEYID_MACHINE_FLAG to enumerate the LocalMachine
  13189. // Key Identifiers. Set pwszComputerName, to enumerate Key Identifiers on
  13190. // a remote computer.
  13191. //--------------------------------------------------------------------------
  13192. WINCRYPT32API
  13193. BOOL
  13194. WINAPI
  13195. CryptEnumKeyIdentifierProperties(
  13196. IN OPTIONAL const CRYPT_HASH_BLOB *pKeyIdentifier,
  13197. IN DWORD dwPropId,
  13198. IN DWORD dwFlags,
  13199. IN OPTIONAL LPCWSTR pwszComputerName,
  13200. IN OPTIONAL void *pvReserved,
  13201. IN OPTIONAL void *pvArg,
  13202. IN PFN_CRYPT_ENUM_KEYID_PROP pfnEnum
  13203. );
  13204. //+-------------------------------------------------------------------------
  13205. // Create a KeyIdentifier from the CSP Public Key Blob.
  13206. //
  13207. // Converts the CSP PUBLICKEYSTRUC into a X.509 CERT_PUBLIC_KEY_INFO and
  13208. // encodes. The encoded CERT_PUBLIC_KEY_INFO is SHA1 hashed to obtain
  13209. // the Key Identifier.
  13210. //
  13211. // By default, the pPubKeyStruc->aiKeyAlg is used to find the appropriate
  13212. // public key Object Identifier. pszPubKeyOID can be set to override
  13213. // the default OID obtained from the aiKeyAlg.
  13214. //--------------------------------------------------------------------------
  13215. WINCRYPT32API
  13216. BOOL
  13217. WINAPI
  13218. CryptCreateKeyIdentifierFromCSP(
  13219. IN DWORD dwCertEncodingType,
  13220. IN OPTIONAL LPCSTR pszPubKeyOID,
  13221. IN const PUBLICKEYSTRUC *pPubKeyStruc,
  13222. IN DWORD cbPubKeyStruc,
  13223. IN DWORD dwFlags,
  13224. IN OPTIONAL void *pvReserved,
  13225. OUT BYTE *pbHash,
  13226. IN OUT DWORD *pcbHash
  13227. );
  13228. //+=========================================================================
  13229. // Certificate Chaining Infrastructure
  13230. //==========================================================================
  13231. //
  13232. // The chain engine defines the store namespace and cache partitioning for
  13233. // the Certificate Chaining infrastructure. A default chain engine
  13234. // is defined for the process which uses all default system stores e.g.
  13235. // Root, CA, Trust, for chain building and caching. If an application
  13236. // wishes to define its own store namespace or have its own partitioned
  13237. // cache then it can create its own chain engine. It is advisable to create
  13238. // a chain engine at application startup and use it throughout the lifetime
  13239. // of the application in order to get optimal caching behavior
  13240. //
  13241. typedef HANDLE HCERTCHAINENGINE;
  13242. #define HCCE_CURRENT_USER ((HCERTCHAINENGINE)NULL)
  13243. #define HCCE_LOCAL_MACHINE ((HCERTCHAINENGINE)0x1)
  13244. //
  13245. // Create a certificate chain engine.
  13246. //
  13247. //
  13248. // Configuration parameters for the certificate chain engine
  13249. //
  13250. // hRestrictedRoot - restrict the root store (must be a subset of "Root")
  13251. //
  13252. // hRestrictedTrust - restrict the store for CTLs
  13253. //
  13254. // hRestrictedOther - restrict the store for certs and CRLs
  13255. //
  13256. // cAdditionalStore, rghAdditionalStore - additional stores
  13257. //
  13258. // NOTE: The algorithm used to define the stores for the engine is as
  13259. // follows:
  13260. //
  13261. // hRoot = hRestrictedRoot or System Store "Root"
  13262. //
  13263. // hTrust = hRestrictedTrust or hWorld (defined later)
  13264. //
  13265. // hOther = hRestrictedOther or (hRestrictedTrust == NULL) ? hWorld :
  13266. // hRestrictedTrust + hWorld
  13267. //
  13268. // hWorld = hRoot + "CA" + "My" + "Trust" + rghAdditionalStore
  13269. //
  13270. // dwFlags - flags
  13271. //
  13272. // CERT_CHAIN_CACHE_END_CERT - information will be cached on
  13273. // the end cert as well as the other
  13274. // certs in the chain
  13275. //
  13276. // CERT_CHAIN_THREAD_STORE_SYNC - use separate thread for store syncs
  13277. // and related cache updates
  13278. //
  13279. // CERT_CHAIN_CACHE_ONLY_URL_RETRIEVAL - don't hit the wire to get
  13280. // URL based objects
  13281. //
  13282. // dwUrlRetrievalTimeout - timeout for wire based URL object retrievals
  13283. // (milliseconds)
  13284. //
  13285. #define CERT_CHAIN_CACHE_END_CERT 0x00000001
  13286. #define CERT_CHAIN_THREAD_STORE_SYNC 0x00000002
  13287. #define CERT_CHAIN_CACHE_ONLY_URL_RETRIEVAL 0x00000004
  13288. #define CERT_CHAIN_USE_LOCAL_MACHINE_STORE 0x00000008
  13289. #define CERT_CHAIN_ENABLE_CACHE_AUTO_UPDATE 0x00000010
  13290. #define CERT_CHAIN_ENABLE_SHARE_STORE 0x00000020
  13291. typedef struct _CERT_CHAIN_ENGINE_CONFIG {
  13292. DWORD cbSize;
  13293. HCERTSTORE hRestrictedRoot;
  13294. HCERTSTORE hRestrictedTrust;
  13295. HCERTSTORE hRestrictedOther;
  13296. DWORD cAdditionalStore;
  13297. HCERTSTORE* rghAdditionalStore;
  13298. DWORD dwFlags;
  13299. DWORD dwUrlRetrievalTimeout; // milliseconds
  13300. DWORD MaximumCachedCertificates;
  13301. DWORD CycleDetectionModulus;
  13302. } CERT_CHAIN_ENGINE_CONFIG, *PCERT_CHAIN_ENGINE_CONFIG;
  13303. WINCRYPT32API
  13304. BOOL
  13305. WINAPI
  13306. CertCreateCertificateChainEngine (
  13307. IN PCERT_CHAIN_ENGINE_CONFIG pConfig,
  13308. OUT HCERTCHAINENGINE* phChainEngine
  13309. );
  13310. //
  13311. // Free a certificate trust engine
  13312. //
  13313. WINCRYPT32API
  13314. VOID
  13315. WINAPI
  13316. CertFreeCertificateChainEngine (
  13317. IN HCERTCHAINENGINE hChainEngine
  13318. );
  13319. //
  13320. // Resync the certificate chain engine. This resync's the stores backing
  13321. // the engine and updates the engine caches.
  13322. //
  13323. WINCRYPT32API
  13324. BOOL
  13325. WINAPI
  13326. CertResyncCertificateChainEngine (
  13327. IN HCERTCHAINENGINE hChainEngine
  13328. );
  13329. //
  13330. // When an application requests a certificate chain, the data structure
  13331. // returned is in the form of a CERT_CHAIN_CONTEXT. This contains
  13332. // an array of CERT_SIMPLE_CHAIN where each simple chain goes from
  13333. // an end cert to a self signed cert and the chain context connects simple
  13334. // chains via trust lists. Each simple chain contains the chain of
  13335. // certificates, summary trust information about the chain and trust information
  13336. // about each certificate element in the chain.
  13337. //
  13338. //
  13339. // Trust status bits
  13340. //
  13341. typedef struct _CERT_TRUST_STATUS {
  13342. DWORD dwErrorStatus;
  13343. DWORD dwInfoStatus;
  13344. } CERT_TRUST_STATUS, *PCERT_TRUST_STATUS;
  13345. //
  13346. // The following are error status bits
  13347. //
  13348. // These can be applied to certificates and chains
  13349. #define CERT_TRUST_NO_ERROR 0x00000000
  13350. #define CERT_TRUST_IS_NOT_TIME_VALID 0x00000001
  13351. #define CERT_TRUST_IS_NOT_TIME_NESTED 0x00000002
  13352. #define CERT_TRUST_IS_REVOKED 0x00000004
  13353. #define CERT_TRUST_IS_NOT_SIGNATURE_VALID 0x00000008
  13354. #define CERT_TRUST_IS_NOT_VALID_FOR_USAGE 0x00000010
  13355. #define CERT_TRUST_IS_UNTRUSTED_ROOT 0x00000020
  13356. #define CERT_TRUST_REVOCATION_STATUS_UNKNOWN 0x00000040
  13357. #define CERT_TRUST_IS_CYCLIC 0x00000080
  13358. #define CERT_TRUST_INVALID_EXTENSION 0x00000100
  13359. #define CERT_TRUST_INVALID_POLICY_CONSTRAINTS 0x00000200
  13360. #define CERT_TRUST_INVALID_BASIC_CONSTRAINTS 0x00000400
  13361. #define CERT_TRUST_INVALID_NAME_CONSTRAINTS 0x00000800
  13362. #define CERT_TRUST_HAS_NOT_SUPPORTED_NAME_CONSTRAINT 0x00001000
  13363. #define CERT_TRUST_HAS_NOT_DEFINED_NAME_CONSTRAINT 0x00002000
  13364. #define CERT_TRUST_HAS_NOT_PERMITTED_NAME_CONSTRAINT 0x00004000
  13365. #define CERT_TRUST_HAS_EXCLUDED_NAME_CONSTRAINT 0x00008000
  13366. #define CERT_TRUST_IS_OFFLINE_REVOCATION 0x01000000
  13367. #define CERT_TRUST_NO_ISSUANCE_CHAIN_POLICY 0x02000000
  13368. // These can be applied to chains only
  13369. #define CERT_TRUST_IS_PARTIAL_CHAIN 0x00010000
  13370. #define CERT_TRUST_CTL_IS_NOT_TIME_VALID 0x00020000
  13371. #define CERT_TRUST_CTL_IS_NOT_SIGNATURE_VALID 0x00040000
  13372. #define CERT_TRUST_CTL_IS_NOT_VALID_FOR_USAGE 0x00080000
  13373. //
  13374. // The following are info status bits
  13375. //
  13376. // These can be applied to certificates only
  13377. #define CERT_TRUST_HAS_EXACT_MATCH_ISSUER 0x00000001
  13378. #define CERT_TRUST_HAS_KEY_MATCH_ISSUER 0x00000002
  13379. #define CERT_TRUST_HAS_NAME_MATCH_ISSUER 0x00000004
  13380. #define CERT_TRUST_IS_SELF_SIGNED 0x00000008
  13381. // These can be applied to certificates and chains
  13382. #define CERT_TRUST_HAS_PREFERRED_ISSUER 0x00000100
  13383. #define CERT_TRUST_HAS_ISSUANCE_CHAIN_POLICY 0x00000200
  13384. #define CERT_TRUST_HAS_VALID_NAME_CONSTRAINTS 0x00000400
  13385. // These can be applied to chains only
  13386. #define CERT_TRUST_IS_COMPLEX_CHAIN 0x00010000
  13387. //
  13388. // Each certificate context in a simple chain has a corresponding chain element
  13389. // in the simple chain context
  13390. //
  13391. // dwErrorStatus has CERT_TRUST_IS_REVOKED, pRevocationInfo set
  13392. // dwErrorStatus has CERT_TRUST_REVOCATION_STATUS_UNKNOWN, pRevocationInfo set
  13393. //
  13394. // Note that the post processing revocation supported in the first
  13395. // version only sets cbSize and dwRevocationResult. Everything else
  13396. // is NULL
  13397. //
  13398. //
  13399. // Revocation Information
  13400. //
  13401. typedef struct _CERT_REVOCATION_INFO {
  13402. DWORD cbSize;
  13403. DWORD dwRevocationResult;
  13404. LPCSTR pszRevocationOid;
  13405. LPVOID pvOidSpecificInfo;
  13406. // fHasFreshnessTime is only set if we are able to retrieve revocation
  13407. // information. For a CRL its CurrentTime - ThisUpdate.
  13408. BOOL fHasFreshnessTime;
  13409. DWORD dwFreshnessTime; // seconds
  13410. // NonNULL for CRL base revocation checking
  13411. PCERT_REVOCATION_CRL_INFO pCrlInfo;
  13412. } CERT_REVOCATION_INFO, *PCERT_REVOCATION_INFO;
  13413. //
  13414. // Trust List Information
  13415. //
  13416. typedef struct _CERT_TRUST_LIST_INFO {
  13417. DWORD cbSize;
  13418. PCTL_ENTRY pCtlEntry;
  13419. PCCTL_CONTEXT pCtlContext;
  13420. } CERT_TRUST_LIST_INFO, *PCERT_TRUST_LIST_INFO;
  13421. //
  13422. // Chain Element
  13423. //
  13424. typedef struct _CERT_CHAIN_ELEMENT {
  13425. DWORD cbSize;
  13426. PCCERT_CONTEXT pCertContext;
  13427. CERT_TRUST_STATUS TrustStatus;
  13428. PCERT_REVOCATION_INFO pRevocationInfo;
  13429. PCERT_ENHKEY_USAGE pIssuanceUsage; // If NULL, any
  13430. PCERT_ENHKEY_USAGE pApplicationUsage; // If NULL, any
  13431. LPCWSTR pwszExtendedErrorInfo; // If NULL, none
  13432. } CERT_CHAIN_ELEMENT, *PCERT_CHAIN_ELEMENT;
  13433. //
  13434. // The simple chain is an array of chain elements and a summary trust status
  13435. // for the chain
  13436. //
  13437. // rgpElements[0] is the end certificate chain element
  13438. //
  13439. // rgpElements[cElement-1] is the self-signed "root" certificate chain element
  13440. //
  13441. typedef struct _CERT_SIMPLE_CHAIN {
  13442. DWORD cbSize;
  13443. CERT_TRUST_STATUS TrustStatus;
  13444. DWORD cElement;
  13445. PCERT_CHAIN_ELEMENT* rgpElement;
  13446. PCERT_TRUST_LIST_INFO pTrustListInfo;
  13447. // fHasRevocationFreshnessTime is only set if we are able to retrieve
  13448. // revocation information for all elements checked for revocation.
  13449. // For a CRL its CurrentTime - ThisUpdate.
  13450. //
  13451. // dwRevocationFreshnessTime is the largest time across all elements
  13452. // checked.
  13453. BOOL fHasRevocationFreshnessTime;
  13454. DWORD dwRevocationFreshnessTime; // seconds
  13455. } CERT_SIMPLE_CHAIN, *PCERT_SIMPLE_CHAIN;
  13456. //
  13457. // And the chain context contains an array of simple chains and summary trust
  13458. // status for all the connected simple chains
  13459. //
  13460. // rgpChains[0] is the end certificate simple chain
  13461. //
  13462. // rgpChains[cChain-1] is the final (possibly trust list signer) chain which
  13463. // ends in a certificate which is contained in the root store
  13464. //
  13465. typedef struct _CERT_CHAIN_CONTEXT CERT_CHAIN_CONTEXT, *PCERT_CHAIN_CONTEXT;
  13466. typedef const CERT_CHAIN_CONTEXT *PCCERT_CHAIN_CONTEXT;
  13467. struct _CERT_CHAIN_CONTEXT {
  13468. DWORD cbSize;
  13469. CERT_TRUST_STATUS TrustStatus;
  13470. DWORD cChain;
  13471. PCERT_SIMPLE_CHAIN* rgpChain;
  13472. // Following is returned when CERT_CHAIN_RETURN_LOWER_QUALITY_CONTEXTS
  13473. // is set in dwFlags
  13474. DWORD cLowerQualityChainContext;
  13475. PCCERT_CHAIN_CONTEXT* rgpLowerQualityChainContext;
  13476. // fHasRevocationFreshnessTime is only set if we are able to retrieve
  13477. // revocation information for all elements checked for revocation.
  13478. // For a CRL its CurrentTime - ThisUpdate.
  13479. //
  13480. // dwRevocationFreshnessTime is the largest time across all elements
  13481. // checked.
  13482. BOOL fHasRevocationFreshnessTime;
  13483. DWORD dwRevocationFreshnessTime; // seconds
  13484. };
  13485. //
  13486. // When building a chain, the there are various parameters used for finding
  13487. // issuing certificates and trust lists. They are identified in the
  13488. // following structure
  13489. //
  13490. // Default usage match type is AND with value zero
  13491. #define USAGE_MATCH_TYPE_AND 0x00000000
  13492. #define USAGE_MATCH_TYPE_OR 0x00000001
  13493. typedef struct _CERT_USAGE_MATCH {
  13494. DWORD dwType;
  13495. CERT_ENHKEY_USAGE Usage;
  13496. } CERT_USAGE_MATCH, *PCERT_USAGE_MATCH;
  13497. typedef struct _CTL_USAGE_MATCH {
  13498. DWORD dwType;
  13499. CTL_USAGE Usage;
  13500. } CTL_USAGE_MATCH, *PCTL_USAGE_MATCH;
  13501. typedef struct _CERT_CHAIN_PARA {
  13502. DWORD cbSize;
  13503. CERT_USAGE_MATCH RequestedUsage;
  13504. #ifdef CERT_CHAIN_PARA_HAS_EXTRA_FIELDS
  13505. // Note, if you #define CERT_CHAIN_PARA_HAS_EXTRA_FIELDS, then, you
  13506. // must zero all unused fields in this data structure.
  13507. // More fields could be added in a future release.
  13508. CERT_USAGE_MATCH RequestedIssuancePolicy;
  13509. DWORD dwUrlRetrievalTimeout; // milliseconds
  13510. BOOL fCheckRevocationFreshnessTime;
  13511. DWORD dwRevocationFreshnessTime; // seconds
  13512. #endif
  13513. } CERT_CHAIN_PARA, *PCERT_CHAIN_PARA;
  13514. //
  13515. // The following API is used for retrieving certificate chains
  13516. //
  13517. // Parameters:
  13518. //
  13519. // hChainEngine - the chain engine (namespace and cache) to use, NULL
  13520. // mean use the default chain engine
  13521. //
  13522. // pCertContext - the context we are retrieving the chain for, it
  13523. // will be the zero index element in the chain
  13524. //
  13525. // pTime - the point in time that we want the chain validated
  13526. // for. Note that the time does not affect trust list,
  13527. // revocation, or root store checking. NULL means use
  13528. // the current system time
  13529. //
  13530. // hAdditionalStore - additional store to use when looking up objects
  13531. //
  13532. // pChainPara - parameters for chain building
  13533. //
  13534. // dwFlags - flags such as should revocation checking be done
  13535. // on the chain?
  13536. //
  13537. // pvReserved - reserved parameter, must be NULL
  13538. //
  13539. // ppChainContext - chain context returned
  13540. //
  13541. // CERT_CHAIN_CACHE_END_CERT can be used here as well
  13542. // Revocation flags are in the high nibble
  13543. #define CERT_CHAIN_REVOCATION_CHECK_END_CERT 0x10000000
  13544. #define CERT_CHAIN_REVOCATION_CHECK_CHAIN 0x20000000
  13545. #define CERT_CHAIN_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT 0x40000000
  13546. #define CERT_CHAIN_REVOCATION_CHECK_CACHE_ONLY 0x80000000
  13547. // By default, the dwUrlRetrievalTimeout in pChainPara is the timeout used
  13548. // for each revocation URL wire retrieval. When the following flag is set,
  13549. // dwUrlRetrievalTimeout is the accumulative timeout across all
  13550. // revocation URL wire retrievals.
  13551. #define CERT_CHAIN_REVOCATION_ACCUMULATIVE_TIMEOUT 0x08000000
  13552. // First pass determines highest quality based upon:
  13553. // - Chain signature valid (higest quality bit of this set)
  13554. // - Complete chain
  13555. // - Trusted root (lowestest quality bit of this set)
  13556. // By default, second pass only considers paths >= highest first pass quality
  13557. #define CERT_CHAIN_DISABLE_PASS1_QUALITY_FILTERING 0x00000040
  13558. #define CERT_CHAIN_RETURN_LOWER_QUALITY_CONTEXTS 0x00000080
  13559. #define CERT_CHAIN_DISABLE_AUTH_ROOT_AUTO_UPDATE 0x00000100
  13560. // When this flag is set, pTime will be used as the timestamp time.
  13561. // pTime will be used to determine if the end certificate was valid at this
  13562. // time. Revocation checking will be relative to pTime.
  13563. // In addition, current time will also be used
  13564. // to determine if the certificate is still time valid. All remaining
  13565. // CA and root certificates will be checked using current time and not pTime.
  13566. //
  13567. // This flag was added 4/5/01 in WXP.
  13568. #define CERT_CHAIN_TIMESTAMP_TIME 0x00000200
  13569. WINCRYPT32API
  13570. BOOL
  13571. WINAPI
  13572. CertGetCertificateChain (
  13573. IN OPTIONAL HCERTCHAINENGINE hChainEngine,
  13574. IN PCCERT_CONTEXT pCertContext,
  13575. IN OPTIONAL LPFILETIME pTime,
  13576. IN OPTIONAL HCERTSTORE hAdditionalStore,
  13577. IN PCERT_CHAIN_PARA pChainPara,
  13578. IN DWORD dwFlags,
  13579. IN LPVOID pvReserved,
  13580. OUT PCCERT_CHAIN_CONTEXT* ppChainContext
  13581. );
  13582. //
  13583. // Free a certificate chain
  13584. //
  13585. WINCRYPT32API
  13586. VOID
  13587. WINAPI
  13588. CertFreeCertificateChain (
  13589. IN PCCERT_CHAIN_CONTEXT pChainContext
  13590. );
  13591. //
  13592. // Duplicate (add a reference to) a certificate chain
  13593. //
  13594. WINCRYPT32API
  13595. PCCERT_CHAIN_CONTEXT
  13596. WINAPI
  13597. CertDuplicateCertificateChain (
  13598. IN PCCERT_CHAIN_CONTEXT pChainContext
  13599. );
  13600. //
  13601. // Specific Revocation Type OID and structure definitions
  13602. //
  13603. //
  13604. // CRL Revocation OID
  13605. //
  13606. #define REVOCATION_OID_CRL_REVOCATION ((LPCSTR)1)
  13607. //
  13608. // For the CRL revocation OID the pvRevocationPara is NULL
  13609. //
  13610. //
  13611. // CRL Revocation Info
  13612. //
  13613. typedef struct _CRL_REVOCATION_INFO {
  13614. PCRL_ENTRY pCrlEntry;
  13615. PCCRL_CONTEXT pCrlContext;
  13616. PCCERT_CHAIN_CONTEXT pCrlIssuerChain;
  13617. } CRL_REVOCATION_INFO, *PCRL_REVOCATION_INFO;
  13618. //+-------------------------------------------------------------------------
  13619. // Find the first or next certificate chain context in the store.
  13620. //
  13621. // The chain context is found according to the dwFindFlags, dwFindType and
  13622. // its pvFindPara. See below for a list of the find types and its parameters.
  13623. //
  13624. // If the first or next chain context isn't found, NULL is returned.
  13625. // Otherwise, a pointer to a read only CERT_CHAIN_CONTEXT is returned.
  13626. // CERT_CHAIN_CONTEXT must be freed by calling CertFreeCertificateChain
  13627. // or is freed when passed as the
  13628. // pPrevChainContext on a subsequent call. CertDuplicateCertificateChain
  13629. // can be called to make a duplicate.
  13630. //
  13631. // pPrevChainContext MUST BE NULL on the first
  13632. // call to find the chain context. To find the next chain context, the
  13633. // pPrevChainContext is set to the CERT_CHAIN_CONTEXT returned by a previous
  13634. // call.
  13635. //
  13636. // NOTE: a NON-NULL pPrevChainContext is always CertFreeCertificateChain'ed by
  13637. // this function, even for an error.
  13638. //--------------------------------------------------------------------------
  13639. WINCRYPT32API
  13640. PCCERT_CHAIN_CONTEXT
  13641. WINAPI
  13642. CertFindChainInStore(
  13643. IN HCERTSTORE hCertStore,
  13644. IN DWORD dwCertEncodingType,
  13645. IN DWORD dwFindFlags,
  13646. IN DWORD dwFindType,
  13647. IN const void *pvFindPara,
  13648. IN PCCERT_CHAIN_CONTEXT pPrevChainContext
  13649. );
  13650. #define CERT_CHAIN_FIND_BY_ISSUER 1
  13651. //+-------------------------------------------------------------------------
  13652. // CERT_CHAIN_FIND_BY_ISSUER
  13653. //
  13654. // Find a certificate chain having a private key for the end certificate and
  13655. // matching one of the given issuer names. A matching dwKeySpec and
  13656. // enhanced key usage can also be specified. Additionally a callback can
  13657. // be provided for even more caller provided filtering before building the
  13658. // chain.
  13659. //
  13660. // By default, only the issuers in the first simple chain are compared
  13661. // for a name match. CERT_CHAIN_FIND_BY_ISSUER_COMPLEX_CHAIN_FLAG can
  13662. // be set in dwFindFlags to match issuers in all the simple chains.
  13663. //
  13664. // CERT_CHAIN_FIND_BY_ISSUER_NO_KEY_FLAG can be set in dwFindFlags to
  13665. // not check if the end certificate has a private key.
  13666. //
  13667. // CERT_CHAIN_FIND_BY_ISSUER_COMPARE_KEY_FLAG can be set in dwFindFlags
  13668. // to compare the public key in the end certificate with the crypto
  13669. // provider's public key. The dwAcquirePrivateKeyFlags can be set
  13670. // in CERT_CHAIN_FIND_BY_ISSUER_PARA to enable caching of the private key's
  13671. // HKEY returned by the CSP.
  13672. //
  13673. // If dwCertEncodingType == 0, defaults to X509_ASN_ENCODING for the
  13674. // array of encoded issuer names.
  13675. //
  13676. // By default, the hCertStore passed to CertFindChainInStore, is passed
  13677. // as an additional store to CertGetCertificateChain.
  13678. // CERT_CHAIN_FIND_BY_ISSUER_CACHE_ONLY_FLAG can be set in dwFindFlags
  13679. // to improve performance by only searching the cached system stores
  13680. // (root, my, ca, trust) to find the issuer certificates. If you are doing
  13681. // a find in the "my" system store, than, this flag should be set to
  13682. // improve performance.
  13683. //
  13684. // Setting CERT_CHAIN_FIND_BY_ISSUER_LOCAL_MACHINE_FLAG in dwFindFlags
  13685. // restricts CertGetCertificateChain to search the Local Machine
  13686. // cached system stores instead of the Current User's.
  13687. //
  13688. // Setting CERT_CHAIN_FIND_BY_ISSUER_CACHE_ONLY_URL_FLAG in dwFindFlags
  13689. // restricts CertGetCertificateChain to only search the URL cache
  13690. // and not hit the wire.
  13691. //--------------------------------------------------------------------------
  13692. // Returns FALSE to skip this certificate. Otherwise, returns TRUE to
  13693. // build a chain for this certificate.
  13694. typedef BOOL (WINAPI *PFN_CERT_CHAIN_FIND_BY_ISSUER_CALLBACK)(
  13695. IN PCCERT_CONTEXT pCert,
  13696. IN void *pvFindArg
  13697. );
  13698. typedef struct _CERT_CHAIN_FIND_BY_ISSUER_PARA {
  13699. DWORD cbSize;
  13700. // If pszUsageIdentifier == NULL, matches any usage.
  13701. LPCSTR pszUsageIdentifier;
  13702. // If dwKeySpec == 0, matches any KeySpec
  13703. DWORD dwKeySpec;
  13704. // When CERT_CHAIN_FIND_BY_ISSUER_COMPARE_KEY_FLAG is set in dwFindFlags,
  13705. // CryptAcquireCertificatePrivateKey is called to do the public key
  13706. // comparison. The following flags can be set to enable caching
  13707. // of the acquired private key or suppress CSP UI. See the API for more
  13708. // details on these flags.
  13709. DWORD dwAcquirePrivateKeyFlags;
  13710. // Pointer to an array of X509, ASN.1 encoded issuer name blobs. If
  13711. // cIssuer == 0, matches any issuer
  13712. DWORD cIssuer;
  13713. CERT_NAME_BLOB *rgIssuer;
  13714. // If NULL or Callback returns TRUE, builds the chain for the end
  13715. // certificate having a private key with the specified KeySpec and
  13716. // enhanced key usage.
  13717. PFN_CERT_CHAIN_FIND_BY_ISSUER_CALLBACK pfnFindCallback;
  13718. void *pvFindArg;
  13719. #ifdef CERT_CHAIN_FIND_BY_ISSUER_PARA_HAS_EXTRA_FIELDS
  13720. // Note, if you #define CERT_CHAIN_FIND_BY_ISSUER_PARA_HAS_EXTRA_FIELDS,
  13721. // then, you must zero all unused fields in this data structure.
  13722. // More fields could be added in a future release.
  13723. // If the following pointers are nonNull, returns the index of the
  13724. // matching issuer certificate, which is at:
  13725. // pChainContext->
  13726. // rgpChain[*pdwIssuerChainIndex]->rgpElement[*pdwIssuerElementIndex].
  13727. //
  13728. // The issuer name blob is compared against the Issuer field in the
  13729. // certificate. The *pdwIssuerElementIndex is set to the index of this
  13730. // subject certificate + 1. Therefore, its possible for a partial chain or
  13731. // a self signed certificate matching the name blob, where
  13732. // *pdwIssuerElementIndex points past the last certificate in the chain.
  13733. //
  13734. // Note, not updated if the above cIssuer == 0.
  13735. DWORD *pdwIssuerChainIndex;
  13736. DWORD *pdwIssuerElementIndex;
  13737. #endif
  13738. } CERT_CHAIN_FIND_ISSUER_PARA, *PCERT_CHAIN_FIND_ISSUER_PARA,
  13739. CERT_CHAIN_FIND_BY_ISSUER_PARA, *PCERT_CHAIN_FIND_BY_ISSUER_PARA;
  13740. // The following dwFindFlags can be set for CERT_CHAIN_FIND_BY_ISSUER
  13741. // If set, compares the public key in the end certificate with the crypto
  13742. // provider's public key. This comparison is the last check made on the
  13743. // build chain.
  13744. #define CERT_CHAIN_FIND_BY_ISSUER_COMPARE_KEY_FLAG 0x0001
  13745. // If not set, only checks the first simple chain for an issuer name match.
  13746. // When set, also checks second and subsequent simple chains.
  13747. #define CERT_CHAIN_FIND_BY_ISSUER_COMPLEX_CHAIN_FLAG 0x0002
  13748. // If set, CertGetCertificateChain only searches the URL cache and
  13749. // doesn't hit the wire.
  13750. #define CERT_CHAIN_FIND_BY_ISSUER_CACHE_ONLY_URL_FLAG 0x0004
  13751. // If set, CertGetCertificateChain only opens the Local Machine
  13752. // certificate stores instead of the Current User's.
  13753. #define CERT_CHAIN_FIND_BY_ISSUER_LOCAL_MACHINE_FLAG 0x0008
  13754. // If set, no check is made to see if the end certificate has a private
  13755. // key associated with it.
  13756. #define CERT_CHAIN_FIND_BY_ISSUER_NO_KEY_FLAG 0x4000
  13757. // By default, the hCertStore passed to CertFindChainInStore, is passed
  13758. // as the additional store to CertGetCertificateChain. This flag can be
  13759. // set to improve performance by only searching the cached system stores
  13760. // (root, my, ca, trust) to find the issuer certificates. If not set, then,
  13761. // the hCertStore is always searched in addition to the cached system
  13762. // stores.
  13763. #define CERT_CHAIN_FIND_BY_ISSUER_CACHE_ONLY_FLAG 0x8000
  13764. //+=========================================================================
  13765. // Certificate Chain Policy Data Structures and APIs
  13766. //==========================================================================
  13767. typedef struct _CERT_CHAIN_POLICY_PARA {
  13768. DWORD cbSize;
  13769. DWORD dwFlags;
  13770. void *pvExtraPolicyPara; // pszPolicyOID specific
  13771. } CERT_CHAIN_POLICY_PARA, *PCERT_CHAIN_POLICY_PARA;
  13772. // If both lChainIndex and lElementIndex are set to -1, the dwError applies
  13773. // to the whole chain context. If only lElementIndex is set to -1, the
  13774. // dwError applies to the lChainIndex'ed chain. Otherwise, the dwError applies
  13775. // to the certificate element at
  13776. // pChainContext->rgpChain[lChainIndex]->rgpElement[lElementIndex].
  13777. typedef struct _CERT_CHAIN_POLICY_STATUS {
  13778. DWORD cbSize;
  13779. DWORD dwError;
  13780. LONG lChainIndex;
  13781. LONG lElementIndex;
  13782. void *pvExtraPolicyStatus; // pszPolicyOID specific
  13783. } CERT_CHAIN_POLICY_STATUS, *PCERT_CHAIN_POLICY_STATUS;
  13784. // Common chain policy flags
  13785. #define CERT_CHAIN_POLICY_IGNORE_NOT_TIME_VALID_FLAG 0x00000001
  13786. #define CERT_CHAIN_POLICY_IGNORE_CTL_NOT_TIME_VALID_FLAG 0x00000002
  13787. #define CERT_CHAIN_POLICY_IGNORE_NOT_TIME_NESTED_FLAG 0x00000004
  13788. #define CERT_CHAIN_POLICY_IGNORE_INVALID_BASIC_CONSTRAINTS_FLAG 0x00000008
  13789. #define CERT_CHAIN_POLICY_IGNORE_ALL_NOT_TIME_VALID_FLAGS ( \
  13790. CERT_CHAIN_POLICY_IGNORE_NOT_TIME_VALID_FLAG | \
  13791. CERT_CHAIN_POLICY_IGNORE_CTL_NOT_TIME_VALID_FLAG | \
  13792. CERT_CHAIN_POLICY_IGNORE_NOT_TIME_NESTED_FLAG \
  13793. )
  13794. #define CERT_CHAIN_POLICY_ALLOW_UNKNOWN_CA_FLAG 0x00000010
  13795. #define CERT_CHAIN_POLICY_IGNORE_WRONG_USAGE_FLAG 0x00000020
  13796. #define CERT_CHAIN_POLICY_IGNORE_INVALID_NAME_FLAG 0x00000040
  13797. #define CERT_CHAIN_POLICY_IGNORE_INVALID_POLICY_FLAG 0x00000080
  13798. #define CERT_CHAIN_POLICY_IGNORE_END_REV_UNKNOWN_FLAG 0x00000100
  13799. #define CERT_CHAIN_POLICY_IGNORE_CTL_SIGNER_REV_UNKNOWN_FLAG 0x00000200
  13800. #define CERT_CHAIN_POLICY_IGNORE_CA_REV_UNKNOWN_FLAG 0x00000400
  13801. #define CERT_CHAIN_POLICY_IGNORE_ROOT_REV_UNKNOWN_FLAG 0x00000800
  13802. #define CERT_CHAIN_POLICY_IGNORE_ALL_REV_UNKNOWN_FLAGS ( \
  13803. CERT_CHAIN_POLICY_IGNORE_END_REV_UNKNOWN_FLAG | \
  13804. CERT_CHAIN_POLICY_IGNORE_CTL_SIGNER_REV_UNKNOWN_FLAG | \
  13805. CERT_CHAIN_POLICY_IGNORE_CA_REV_UNKNOWN_FLAG | \
  13806. CERT_CHAIN_POLICY_IGNORE_ROOT_REV_UNKNOWN_FLAG \
  13807. )
  13808. #define CERT_CHAIN_POLICY_ALLOW_TESTROOT_FLAG 0x00008000
  13809. #define CERT_CHAIN_POLICY_TRUST_TESTROOT_FLAG 0x00004000
  13810. //+-------------------------------------------------------------------------
  13811. // Verify that the certificate chain satisfies the specified policy
  13812. // requirements. If we were able to verify the chain policy, TRUE is returned
  13813. // and the dwError field of the pPolicyStatus is updated. A dwError of 0
  13814. // (ERROR_SUCCESS, S_OK) indicates the chain satisfies the specified policy.
  13815. //
  13816. // If dwError applies to the entire chain context, both lChainIndex and
  13817. // lElementIndex are set to -1. If dwError applies to a simple chain,
  13818. // lElementIndex is set to -1 and lChainIndex is set to the index of the
  13819. // first offending chain having the error. If dwError applies to a
  13820. // certificate element, lChainIndex and lElementIndex are updated to
  13821. // index the first offending certificate having the error, where, the
  13822. // the certificate element is at:
  13823. // pChainContext->rgpChain[lChainIndex]->rgpElement[lElementIndex].
  13824. //
  13825. // The dwFlags in pPolicyPara can be set to change the default policy checking
  13826. // behaviour. In addition, policy specific parameters can be passed in
  13827. // the pvExtraPolicyPara field of pPolicyPara.
  13828. //
  13829. // In addition to returning dwError, in pPolicyStatus, policy OID specific
  13830. // extra status may be returned via pvExtraPolicyStatus.
  13831. //--------------------------------------------------------------------------
  13832. WINCRYPT32API
  13833. BOOL
  13834. WINAPI
  13835. CertVerifyCertificateChainPolicy(
  13836. IN LPCSTR pszPolicyOID,
  13837. IN PCCERT_CHAIN_CONTEXT pChainContext,
  13838. IN PCERT_CHAIN_POLICY_PARA pPolicyPara,
  13839. IN OUT PCERT_CHAIN_POLICY_STATUS pPolicyStatus
  13840. );
  13841. // Predefined OID Function Names
  13842. #define CRYPT_OID_VERIFY_CERTIFICATE_CHAIN_POLICY_FUNC \
  13843. "CertDllVerifyCertificateChainPolicy"
  13844. // CertDllVerifyCertificateChainPolicy has same function signature as
  13845. // CertVerifyCertificateChainPolicy.
  13846. //+-------------------------------------------------------------------------
  13847. // Predefined verify chain policies
  13848. //--------------------------------------------------------------------------
  13849. #define CERT_CHAIN_POLICY_BASE ((LPCSTR) 1)
  13850. #define CERT_CHAIN_POLICY_AUTHENTICODE ((LPCSTR) 2)
  13851. #define CERT_CHAIN_POLICY_AUTHENTICODE_TS ((LPCSTR) 3)
  13852. #define CERT_CHAIN_POLICY_SSL ((LPCSTR) 4)
  13853. #define CERT_CHAIN_POLICY_BASIC_CONSTRAINTS ((LPCSTR) 5)
  13854. #define CERT_CHAIN_POLICY_NT_AUTH ((LPCSTR) 6)
  13855. #define CERT_CHAIN_POLICY_MICROSOFT_ROOT ((LPCSTR) 7)
  13856. //+-------------------------------------------------------------------------
  13857. // CERT_CHAIN_POLICY_BASE
  13858. //
  13859. // Implements the base chain policy verification checks. dwFlags can
  13860. // be set in pPolicyPara to alter the default policy checking behaviour.
  13861. //--------------------------------------------------------------------------
  13862. //+-------------------------------------------------------------------------
  13863. // CERT_CHAIN_POLICY_AUTHENTICODE
  13864. //
  13865. // Implements the Authenticode chain policy verification checks.
  13866. //
  13867. // pvExtraPolicyPara may optionally be set to point to the following
  13868. // AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_PARA.
  13869. //
  13870. // pvExtraPolicyStatus may optionally be set to point to the following
  13871. // AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_STATUS.
  13872. //--------------------------------------------------------------------------
  13873. // dwRegPolicySettings are defined in wintrust.h
  13874. typedef struct _AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_PARA {
  13875. DWORD cbSize;
  13876. DWORD dwRegPolicySettings;
  13877. PCMSG_SIGNER_INFO pSignerInfo; // optional
  13878. } AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_PARA,
  13879. *PAUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_PARA;
  13880. typedef struct _AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_STATUS {
  13881. DWORD cbSize;
  13882. BOOL fCommercial; // obtained from signer statement
  13883. } AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_STATUS,
  13884. *PAUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_STATUS;
  13885. //+-------------------------------------------------------------------------
  13886. // CERT_CHAIN_POLICY_AUTHENTICODE_TS
  13887. //
  13888. // Implements the Authenticode Time Stamp chain policy verification checks.
  13889. //
  13890. // pvExtraPolicyPara may optionally be set to point to the following
  13891. // AUTHENTICODE_TS_EXTRA_CERT_CHAIN_POLICY_PARA.
  13892. //
  13893. // pvExtraPolicyStatus isn't used and must be set to NULL.
  13894. //--------------------------------------------------------------------------
  13895. // dwRegPolicySettings are defined in wintrust.h
  13896. typedef struct _AUTHENTICODE_TS_EXTRA_CERT_CHAIN_POLICY_PARA {
  13897. DWORD cbSize;
  13898. DWORD dwRegPolicySettings;
  13899. BOOL fCommercial;
  13900. } AUTHENTICODE_TS_EXTRA_CERT_CHAIN_POLICY_PARA,
  13901. *PAUTHENTICODE_TS_EXTRA_CERT_CHAIN_POLICY_PARA;
  13902. //+-------------------------------------------------------------------------
  13903. // CERT_CHAIN_POLICY_SSL
  13904. //
  13905. // Implements the SSL client/server chain policy verification checks.
  13906. //
  13907. // pvExtraPolicyPara may optionally be set to point to the following
  13908. // SSL_EXTRA_CERT_CHAIN_POLICY_PARA data structure
  13909. //--------------------------------------------------------------------------
  13910. // fdwChecks flags are defined in wininet.h
  13911. typedef struct _HTTPSPolicyCallbackData
  13912. {
  13913. union {
  13914. DWORD cbStruct; // sizeof(HTTPSPolicyCallbackData);
  13915. DWORD cbSize; // sizeof(HTTPSPolicyCallbackData);
  13916. };
  13917. DWORD dwAuthType;
  13918. # define AUTHTYPE_CLIENT 1
  13919. # define AUTHTYPE_SERVER 2
  13920. DWORD fdwChecks;
  13921. WCHAR *pwszServerName; // used to check against CN=xxxx
  13922. } HTTPSPolicyCallbackData, *PHTTPSPolicyCallbackData,
  13923. SSL_EXTRA_CERT_CHAIN_POLICY_PARA, *PSSL_EXTRA_CERT_CHAIN_POLICY_PARA;
  13924. //+-------------------------------------------------------------------------
  13925. // CERT_CHAIN_POLICY_BASIC_CONSTRAINTS
  13926. //
  13927. // Implements the basic constraints chain policy.
  13928. //
  13929. // Iterates through all the certificates in the chain checking for either
  13930. // a szOID_BASIC_CONSTRAINTS or a szOID_BASIC_CONSTRAINTS2 extension. If
  13931. // neither extension is present, the certificate is assumed to have
  13932. // valid policy. Otherwise, for the first certificate element, checks if
  13933. // it matches the expected CA_FLAG or END_ENTITY_FLAG specified in
  13934. // pPolicyPara->dwFlags. If neither or both flags are set, then, the first
  13935. // element can be either a CA or END_ENTITY. All other elements must be
  13936. // a CA. If the PathLenConstraint is present in the extension, its
  13937. // checked.
  13938. //
  13939. // The first elements in the remaining simple chains (ie, the certificate
  13940. // used to sign the CTL) are checked to be an END_ENTITY.
  13941. //
  13942. // If this verification fails, dwError will be set to
  13943. // TRUST_E_BASIC_CONSTRAINTS.
  13944. //--------------------------------------------------------------------------
  13945. #define BASIC_CONSTRAINTS_CERT_CHAIN_POLICY_CA_FLAG 0x80000000
  13946. #define BASIC_CONSTRAINTS_CERT_CHAIN_POLICY_END_ENTITY_FLAG 0x40000000
  13947. //+-------------------------------------------------------------------------
  13948. // CERT_CHAIN_POLICY_NT_AUTH
  13949. //
  13950. // Implements the NT Authentication chain policy.
  13951. //
  13952. // The NT Authentication chain policy consists of 3 distinct chain
  13953. // verifications in the following order:
  13954. // [1] CERT_CHAIN_POLICY_BASE - Implements the base chain policy
  13955. // verification checks. The LOWORD of dwFlags can be set in
  13956. // pPolicyPara to alter the default policy checking behaviour. See
  13957. // CERT_CHAIN_POLICY_BASE for more details.
  13958. //
  13959. // [2] CERT_CHAIN_POLICY_BASIC_CONSTRAINTS - Implements the basic
  13960. // constraints chain policy. The HIWORD of dwFlags can be set
  13961. // to specify if the first element must be either a CA or END_ENTITY.
  13962. // See CERT_CHAIN_POLICY_BASIC_CONSTRAINTS for more details.
  13963. //
  13964. // [3] Checks if the second element in the chain, the CA that issued
  13965. // the end certificate, is a trusted CA for NT
  13966. // Authentication. A CA is considered to be trusted if it exists in
  13967. // the "NTAuth" system registry store found in the
  13968. // CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE store location.
  13969. // If this verification fails, whereby the CA isn't trusted,
  13970. // dwError is set to CERT_E_UNTRUSTEDCA.
  13971. //
  13972. // If CERT_PROT_ROOT_DISABLE_NT_AUTH_REQUIRED_FLAG is set
  13973. // in the "Flags" value of the HKLM policy "ProtectedRoots" subkey
  13974. // defined by CERT_PROT_ROOT_FLAGS_REGPATH, then,
  13975. // if the above check fails, checks if the chain
  13976. // has CERT_TRUST_HAS_VALID_NAME_CONSTRAINTS set in dwInfoStatus. This
  13977. // will only be set if there was a valid name constraint for all
  13978. // name spaces including UPN. If the chain doesn't have this info
  13979. // status set, dwError is set to CERT_E_UNTRUSTEDCA.
  13980. //--------------------------------------------------------------------------
  13981. //+-------------------------------------------------------------------------
  13982. // CERT_CHAIN_POLICY_MICROSOFT_ROOT
  13983. //
  13984. // Checks if the last element of the first simple chain contains a
  13985. // Microsoft root public key. If it doesn't contain a Microsoft root
  13986. // public key, dwError is set to CERT_E_UNTRUSTEDROOT.
  13987. //
  13988. // pvExtraPolicyPara and pvExtraPolicyStatus aren't used and must be set
  13989. // to NULL.
  13990. //--------------------------------------------------------------------------
  13991. //+-------------------------------------------------------------------------
  13992. // convert formatted string to binary
  13993. // If cchString is 0, then pszString is NULL terminated and
  13994. // cchString is obtained via strlen() + 1.
  13995. // dwFlags defines string format
  13996. // if pbBinary is NULL, *pcbBinary returns the size of required memory
  13997. // *pdwSkip returns the character count of skipped strings, optional
  13998. // *pdwFlags returns the actual format used in the conversion, optional
  13999. //--------------------------------------------------------------------------
  14000. WINCRYPT32STRINGAPI
  14001. BOOL
  14002. WINAPI
  14003. CryptStringToBinaryA(
  14004. IN LPCSTR pszString,
  14005. IN DWORD cchString,
  14006. IN DWORD dwFlags,
  14007. IN BYTE *pbBinary,
  14008. IN OUT DWORD *pcbBinary,
  14009. OUT DWORD *pdwSkip, //OPTIONAL
  14010. OUT DWORD *pdwFlags //OPTIONAL
  14011. );
  14012. //+-------------------------------------------------------------------------
  14013. // convert formatted string to binary
  14014. // If cchString is 0, then pszString is NULL terminated and
  14015. // cchString is obtained via strlen() + 1.
  14016. // dwFlags defines string format
  14017. // if pbBinary is NULL, *pcbBinary returns the size of required memory
  14018. // *pdwSkip returns the character count of skipped strings, optional
  14019. // *pdwFlags returns the actual format used in the conversion, optional
  14020. //--------------------------------------------------------------------------
  14021. WINCRYPT32STRINGAPI
  14022. BOOL
  14023. WINAPI
  14024. CryptStringToBinaryW(
  14025. IN LPCWSTR pszString,
  14026. IN DWORD cchString,
  14027. IN DWORD dwFlags,
  14028. IN BYTE *pbBinary,
  14029. IN OUT DWORD *pcbBinary,
  14030. OUT DWORD *pdwSkip, //OPTIONAL
  14031. OUT DWORD *pdwFlags //OPTIONAL
  14032. );
  14033. #ifdef UNICODE
  14034. #define CryptStringToBinary CryptStringToBinaryW
  14035. #else
  14036. #define CryptStringToBinary CryptStringToBinaryA
  14037. #endif // !UNICODE
  14038. //+-------------------------------------------------------------------------
  14039. // convert binary to formatted string
  14040. // dwFlags defines string format
  14041. // if pszString is NULL, *pcchString returns the size of required memory in byte
  14042. //--------------------------------------------------------------------------
  14043. WINCRYPT32STRINGAPI
  14044. BOOL
  14045. WINAPI
  14046. CryptBinaryToStringA(
  14047. IN CONST BYTE *pbBinary,
  14048. IN DWORD cbBinary,
  14049. IN DWORD dwFlags,
  14050. IN LPSTR pszString,
  14051. IN OUT DWORD *pcchString
  14052. );
  14053. //+-------------------------------------------------------------------------
  14054. // convert binary to formatted string
  14055. // dwFlags defines string format
  14056. // if pszString is NULL, *pcchString returns the size of required memory in byte
  14057. //--------------------------------------------------------------------------
  14058. WINCRYPT32STRINGAPI
  14059. BOOL
  14060. WINAPI
  14061. CryptBinaryToStringW(
  14062. IN CONST BYTE *pbBinary,
  14063. IN DWORD cbBinary,
  14064. IN DWORD dwFlags,
  14065. IN LPWSTR pszString,
  14066. IN OUT DWORD *pcchString
  14067. );
  14068. #ifdef UNICODE
  14069. #define CryptBinaryToString CryptBinaryToStringW
  14070. #else
  14071. #define CryptBinaryToString CryptBinaryToStringA
  14072. #endif // !UNICODE
  14073. // dwFlags has the following defines
  14074. #define CRYPT_STRING_BASE64HEADER 0x00000000
  14075. #define CRYPT_STRING_BASE64 0x00000001
  14076. #define CRYPT_STRING_BINARY 0x00000002
  14077. #define CRYPT_STRING_BASE64REQUESTHEADER 0x00000003
  14078. #define CRYPT_STRING_HEX 0x00000004
  14079. #define CRYPT_STRING_HEXASCII 0x00000005
  14080. #define CRYPT_STRING_BASE64_ANY 0x00000006
  14081. #define CRYPT_STRING_ANY 0x00000007
  14082. #define CRYPT_STRING_HEX_ANY 0x00000008
  14083. #define CRYPT_STRING_BASE64X509CRLHEADER 0x00000009
  14084. #define CRYPT_STRING_HEXADDR 0x0000000a
  14085. #define CRYPT_STRING_HEXASCIIADDR 0x0000000b
  14086. #define CRYPT_STRING_NOCR 0x80000000
  14087. // CryptBinaryToString uses the following flags
  14088. // CRYPT_STRING_BASE64HEADER - base64 format with certificate begin
  14089. // and end headers
  14090. // CRYPT_STRING_BASE64 - only base64 without headers
  14091. // CRYPT_STRING_BINARY - pure binary copy
  14092. // CRYPT_STRING_BASE64REQUESTHEADER - base64 format with request begin
  14093. // and end headers
  14094. // CRYPT_STRING_BASE64X509CRLHEADER - base64 format with x509 crl begin
  14095. // and end headers
  14096. // CRYPT_STRING_HEX - only hex format
  14097. // CRYPT_STRING_HEXASCII - hex format with ascii char display
  14098. // CRYPT_STRING_HEXADDR - hex format with address display
  14099. // CRYPT_STRING_HEXASCIIADDR - hex format with ascii char and address display
  14100. //
  14101. // CryptBinaryToString accepts CRYPT_STRING_NOCR or'd into one of the above.
  14102. // When set, line breaks contain only LF, instead of CR-LF pairs.
  14103. // CryptStringToBinary uses the following flags
  14104. // CRYPT_STRING_BASE64_ANY tries the following, in order:
  14105. // CRYPT_STRING_BASE64HEADER
  14106. // CRYPT_STRING_BASE64
  14107. // CRYPT_STRING_ANY tries the following, in order:
  14108. // CRYPT_STRING_BASE64_ANY
  14109. // CRYPT_STRING_BINARY -- should always succeed
  14110. // CRYPT_STRING_HEX_ANY tries the following, in order:
  14111. // CRYPT_STRING_HEXADDR
  14112. // CRYPT_STRING_HEXASCIIADDR
  14113. // CRYPT_STRING_HEXASCII
  14114. // CRYPT_STRING_HEX
  14115. //+=========================================================================
  14116. // PFX (PKCS #12) function defintions and types
  14117. //==========================================================================
  14118. //+-------------------------------------------------------------------------
  14119. // PFXImportCertStore
  14120. //
  14121. // Import the PFX blob and return a store containing certificates
  14122. //
  14123. // If the password parameter is incorrect or any other problems decoding
  14124. // the PFX blob are encountered, the function will return NULL and the
  14125. // error code can be found from GetLastError().
  14126. //
  14127. // The dwFlags parameter may be set to the following:
  14128. // CRYPT_EXPORTABLE - specify that any imported keys should be marked as
  14129. // exportable (see documentation on CryptImportKey)
  14130. // CRYPT_USER_PROTECTED - (see documentation on CryptImportKey)
  14131. // CRYPT_MACHINE_KEYSET - used to force the private key to be stored in the
  14132. // the local machine and not the current user.
  14133. // CRYPT_USER_KEYSET - used to force the private key to be stored in the
  14134. // the current user and not the local machine, even if
  14135. // the pfx blob specifies that it should go into local
  14136. // machine.
  14137. //--------------------------------------------------------------------------
  14138. WINCRYPT32API
  14139. HCERTSTORE
  14140. WINAPI
  14141. PFXImportCertStore(
  14142. IN CRYPT_DATA_BLOB* pPFX,
  14143. IN LPCWSTR szPassword,
  14144. IN DWORD dwFlags);
  14145. // dwFlags definitions for PFXImportCertStore
  14146. //#define CRYPT_EXPORTABLE 0x00000001 // CryptImportKey dwFlags
  14147. //#define CRYPT_USER_PROTECTED 0x00000002 // CryptImportKey dwFlags
  14148. //#define CRYPT_MACHINE_KEYSET 0x00000020 // CryptAcquireContext dwFlags
  14149. #define CRYPT_USER_KEYSET 0x00001000
  14150. #define PKCS12_IMPORT_RESERVED_MASK 0xffff0000
  14151. //+-------------------------------------------------------------------------
  14152. // PFXIsPFXBlob
  14153. //
  14154. // This function will try to decode the outer layer of the blob as a pfx
  14155. // blob, and if that works it will return TRUE, it will return FALSE otherwise
  14156. //
  14157. //--------------------------------------------------------------------------
  14158. WINCRYPT32API
  14159. BOOL
  14160. WINAPI
  14161. PFXIsPFXBlob(
  14162. IN CRYPT_DATA_BLOB* pPFX);
  14163. //+-------------------------------------------------------------------------
  14164. // PFXVerifyPassword
  14165. //
  14166. // This function will attempt to decode the outer layer of the blob as a pfx
  14167. // blob and decrypt with the given password. No data from the blob will be
  14168. // imported.
  14169. //
  14170. // Return value is TRUE if password appears correct, FALSE otherwise.
  14171. //
  14172. //--------------------------------------------------------------------------
  14173. WINCRYPT32API
  14174. BOOL
  14175. WINAPI
  14176. PFXVerifyPassword(
  14177. IN CRYPT_DATA_BLOB* pPFX,
  14178. IN LPCWSTR szPassword,
  14179. IN DWORD dwFlags);
  14180. //+-------------------------------------------------------------------------
  14181. // PFXExportCertStoreEx
  14182. //
  14183. // Export the certificates and private keys referenced in the passed-in store
  14184. //
  14185. // This API encodes the blob under a stronger algorithm. The resulting
  14186. // PKCS12 blobs are incompatible with the earlier PFXExportCertStore API.
  14187. //
  14188. // The value passed in the password parameter will be used to encrypt and
  14189. // verify the integrity of the PFX packet. If any problems encoding the store
  14190. // are encountered, the function will return FALSE and the error code can
  14191. // be found from GetLastError().
  14192. //
  14193. // The dwFlags parameter may be set to any combination of
  14194. // EXPORT_PRIVATE_KEYS
  14195. // REPORT_NO_PRIVATE_KEY
  14196. // REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY
  14197. //
  14198. // The encoded PFX blob is returned in *pPFX. If pPFX->pbData is NULL upon
  14199. // input, this is a length only calculation, whereby, pPFX->cbData is updated
  14200. // with the number of bytes required for the encoded blob. Otherwise,
  14201. // the memory pointed to by pPFX->pbData is updated with the encoded bytes
  14202. // and pPFX->cbData is updated with the encoded byte length.
  14203. //--------------------------------------------------------------------------
  14204. WINCRYPT32API
  14205. BOOL
  14206. WINAPI
  14207. PFXExportCertStoreEx(
  14208. IN HCERTSTORE hStore,
  14209. IN OUT CRYPT_DATA_BLOB* pPFX,
  14210. IN LPCWSTR szPassword,
  14211. IN void* pvReserved,
  14212. IN DWORD dwFlags);
  14213. // dwFlags definitions for PFXExportCertStoreEx
  14214. #define REPORT_NO_PRIVATE_KEY 0x0001
  14215. #define REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY 0x0002
  14216. #define EXPORT_PRIVATE_KEYS 0x0004
  14217. #define PKCS12_EXPORT_RESERVED_MASK 0xffff0000
  14218. //+-------------------------------------------------------------------------
  14219. // PFXExportCertStore
  14220. //
  14221. // Export the certificates and private keys referenced in the passed-in store
  14222. //
  14223. // This is an old API kept for compatibility with IE4 clients. New applications
  14224. // should call the above PfxExportCertStoreEx for enhanced security.
  14225. //--------------------------------------------------------------------------
  14226. WINCRYPT32API
  14227. BOOL
  14228. WINAPI
  14229. PFXExportCertStore(
  14230. IN HCERTSTORE hStore,
  14231. IN OUT CRYPT_DATA_BLOB* pPFX,
  14232. IN LPCWSTR szPassword,
  14233. IN DWORD dwFlags);
  14234. #ifdef __cplusplus
  14235. } // Balance extern "C" above
  14236. #endif
  14237. #if defined (_MSC_VER)
  14238. #if ( _MSC_VER >= 800 )
  14239. #if _MSC_VER >= 1200
  14240. #pragma warning(pop)
  14241. #else
  14242. #pragma warning(default:4201)
  14243. #endif
  14244. #endif
  14245. #endif
  14246. #endif // __WINCRYPT_H__