Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

15731 lines
633 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992-1999.
  5. //
  6. // File: wincrypt.h
  7. //
  8. // Contents: Cryptographic API Prototypes and Definitions
  9. //
  10. //----------------------------------------------------------------------------
  11. #ifndef __WINCRYPT_H__
  12. #define __WINCRYPT_H__
  13. #if defined (_MSC_VER)
  14. #if ( _MSC_VER >= 800 )
  15. #if _MSC_VER >= 1200
  16. #pragma warning(push)
  17. #endif
  18. #pragma warning(disable:4201) /* Nameless struct/union */
  19. #endif
  20. #if (_MSC_VER > 1020)
  21. #pragma once
  22. #endif
  23. #endif
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #ifndef _HRESULT_DEFINED
  28. #define _HRESULT_DEFINED
  29. typedef LONG HRESULT;
  30. #endif // !_HRESULT_DEFINED
  31. #ifndef WINADVAPI
  32. #define WINADVAPI
  33. #endif
  34. #ifndef WINAPI
  35. #define WINAPI __stdcall
  36. #endif
  37. #ifndef CALLBACK
  38. #define CALLBACK __stdcall
  39. #endif
  40. #ifndef DECLSPEC_IMPORT
  41. #define DECLSPEC_IMPORT
  42. #endif
  43. #ifndef CONST
  44. #define CONST const
  45. #endif
  46. #ifndef IN
  47. #define IN
  48. #endif
  49. #ifndef OUT
  50. #define OUT
  51. #endif
  52. #ifndef OPTIONAL
  53. #define OPTIONAL
  54. #endif
  55. #if !defined(_CRYPT32_)
  56. #define WINCRYPT32API DECLSPEC_IMPORT
  57. #else
  58. #define WINCRYPT32API
  59. #endif
  60. #if !defined(_CRYPT32STRING_)
  61. # define WINCRYPT32STRINGAPI WINCRYPT32API
  62. #else
  63. # define WINCRYPT32STRINGAPI
  64. #endif
  65. //
  66. // Algorithm IDs and Flags
  67. //
  68. // ALG_ID crackers
  69. #define GET_ALG_CLASS(x) (x & (7 << 13))
  70. #define GET_ALG_TYPE(x) (x & (15 << 9))
  71. #define GET_ALG_SID(x) (x & (511))
  72. // Algorithm classes
  73. #define ALG_CLASS_ANY (0)
  74. #define ALG_CLASS_SIGNATURE (1 << 13)
  75. #define ALG_CLASS_MSG_ENCRYPT (2 << 13)
  76. #define ALG_CLASS_DATA_ENCRYPT (3 << 13)
  77. #define ALG_CLASS_HASH (4 << 13)
  78. #define ALG_CLASS_KEY_EXCHANGE (5 << 13)
  79. #define ALG_CLASS_ALL (7 << 13)
  80. // Algorithm types
  81. #define ALG_TYPE_ANY (0)
  82. #define ALG_TYPE_DSS (1 << 9)
  83. #define ALG_TYPE_RSA (2 << 9)
  84. #define ALG_TYPE_BLOCK (3 << 9)
  85. #define ALG_TYPE_STREAM (4 << 9)
  86. #define ALG_TYPE_DH (5 << 9)
  87. #define ALG_TYPE_SECURECHANNEL (6 << 9)
  88. // Generic sub-ids
  89. #define ALG_SID_ANY (0)
  90. // Some RSA sub-ids
  91. #define ALG_SID_RSA_ANY 0
  92. #define ALG_SID_RSA_PKCS 1
  93. #define ALG_SID_RSA_MSATWORK 2
  94. #define ALG_SID_RSA_ENTRUST 3
  95. #define ALG_SID_RSA_PGP 4
  96. // Some DSS sub-ids
  97. //
  98. #define ALG_SID_DSS_ANY 0
  99. #define ALG_SID_DSS_PKCS 1
  100. #define ALG_SID_DSS_DMS 2
  101. // Block cipher sub ids
  102. // DES sub_ids
  103. #define ALG_SID_DES 1
  104. #define ALG_SID_3DES 3
  105. #define ALG_SID_DESX 4
  106. #define ALG_SID_IDEA 5
  107. #define ALG_SID_CAST 6
  108. #define ALG_SID_SAFERSK64 7
  109. #define ALG_SID_SAFERSK128 8
  110. #define ALG_SID_3DES_112 9
  111. #define ALG_SID_CYLINK_MEK 12
  112. #define ALG_SID_RC5 13
  113. #define ALG_SID_AES_128 14
  114. #define ALG_SID_AES_192 15
  115. #define ALG_SID_AES_256 16
  116. #define ALG_SID_AES 17
  117. // Fortezza sub-ids
  118. #define ALG_SID_SKIPJACK 10
  119. #define ALG_SID_TEK 11
  120. // KP_MODE
  121. #define CRYPT_MODE_CBCI 6 // ANSI CBC Interleaved
  122. #define CRYPT_MODE_CFBP 7 // ANSI CFB Pipelined
  123. #define CRYPT_MODE_OFBP 8 // ANSI OFB Pipelined
  124. #define CRYPT_MODE_CBCOFM 9 // ANSI CBC + OF Masking
  125. #define CRYPT_MODE_CBCOFMI 10 // ANSI CBC + OFM Interleaved
  126. // RC2 sub-ids
  127. #define ALG_SID_RC2 2
  128. // Stream cipher sub-ids
  129. #define ALG_SID_RC4 1
  130. #define ALG_SID_SEAL 2
  131. // Diffie-Hellman sub-ids
  132. #define ALG_SID_DH_SANDF 1
  133. #define ALG_SID_DH_EPHEM 2
  134. #define ALG_SID_AGREED_KEY_ANY 3
  135. #define ALG_SID_KEA 4
  136. // Hash sub ids
  137. #define ALG_SID_MD2 1
  138. #define ALG_SID_MD4 2
  139. #define ALG_SID_MD5 3
  140. #define ALG_SID_SHA 4
  141. #define ALG_SID_SHA1 4
  142. #define ALG_SID_MAC 5
  143. #define ALG_SID_RIPEMD 6
  144. #define ALG_SID_RIPEMD160 7
  145. #define ALG_SID_SSL3SHAMD5 8
  146. #define ALG_SID_HMAC 9
  147. #define ALG_SID_TLS1PRF 10
  148. #define ALG_SID_HASH_REPLACE_OWF 11
  149. #define ALG_SID_SHA_256 12
  150. #define ALG_SID_SHA_384 13
  151. #define ALG_SID_SHA_512 14
  152. // secure channel sub ids
  153. #define ALG_SID_SSL3_MASTER 1
  154. #define ALG_SID_SCHANNEL_MASTER_HASH 2
  155. #define ALG_SID_SCHANNEL_MAC_KEY 3
  156. #define ALG_SID_PCT1_MASTER 4
  157. #define ALG_SID_SSL2_MASTER 5
  158. #define ALG_SID_TLS1_MASTER 6
  159. #define ALG_SID_SCHANNEL_ENC_KEY 7
  160. // Our silly example sub-id
  161. #define ALG_SID_EXAMPLE 80
  162. #ifndef ALGIDDEF
  163. #define ALGIDDEF
  164. typedef unsigned int ALG_ID;
  165. #endif
  166. // algorithm identifier definitions
  167. #define CALG_MD2 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD2)
  168. #define CALG_MD4 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD4)
  169. #define CALG_MD5 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD5)
  170. #define CALG_SHA (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA)
  171. #define CALG_SHA1 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA1)
  172. #define CALG_MAC (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MAC)
  173. #define CALG_RSA_SIGN (ALG_CLASS_SIGNATURE | ALG_TYPE_RSA | ALG_SID_RSA_ANY)
  174. #define CALG_DSS_SIGN (ALG_CLASS_SIGNATURE | ALG_TYPE_DSS | ALG_SID_DSS_ANY)
  175. #define CALG_NO_SIGN (ALG_CLASS_SIGNATURE | ALG_TYPE_ANY | ALG_SID_ANY)
  176. #define CALG_RSA_KEYX (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_RSA|ALG_SID_RSA_ANY)
  177. #define CALG_DES (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_DES)
  178. #define CALG_3DES_112 (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_3DES_112)
  179. #define CALG_3DES (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_3DES)
  180. #define CALG_DESX (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_DESX)
  181. #define CALG_RC2 (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_RC2)
  182. #define CALG_RC4 (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_STREAM|ALG_SID_RC4)
  183. #define CALG_SEAL (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_STREAM|ALG_SID_SEAL)
  184. #define CALG_DH_SF (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_DH_SANDF)
  185. #define CALG_DH_EPHEM (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_DH_EPHEM)
  186. #define CALG_AGREEDKEY_ANY (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_AGREED_KEY_ANY)
  187. #define CALG_KEA_KEYX (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_KEA)
  188. #define CALG_HUGHES_MD5 (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_ANY|ALG_SID_MD5)
  189. #define CALG_SKIPJACK (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_SKIPJACK)
  190. #define CALG_TEK (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_TEK)
  191. #define CALG_CYLINK_MEK (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_CYLINK_MEK)
  192. #define CALG_SSL3_SHAMD5 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SSL3SHAMD5)
  193. #define CALG_SSL3_MASTER (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SSL3_MASTER)
  194. #define CALG_SCHANNEL_MASTER_HASH (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SCHANNEL_MASTER_HASH)
  195. #define CALG_SCHANNEL_MAC_KEY (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SCHANNEL_MAC_KEY)
  196. #define CALG_SCHANNEL_ENC_KEY (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SCHANNEL_ENC_KEY)
  197. #define CALG_PCT1_MASTER (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_PCT1_MASTER)
  198. #define CALG_SSL2_MASTER (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SSL2_MASTER)
  199. #define CALG_TLS1_MASTER (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_TLS1_MASTER)
  200. #define CALG_RC5 (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_RC5)
  201. #define CALG_HMAC (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_HMAC)
  202. #define CALG_TLS1PRF (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_TLS1PRF)
  203. #define CALG_HASH_REPLACE_OWF (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_HASH_REPLACE_OWF)
  204. #define CALG_AES_128 (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_AES_128)
  205. #define CALG_AES_192 (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_AES_192)
  206. #define CALG_AES_256 (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_AES_256)
  207. #define CALG_AES (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_AES)
  208. #define CALG_SHA_256 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_256)
  209. #define CALG_SHA_384 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_384)
  210. #define CALG_SHA_512 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_512)
  211. typedef ULONG_PTR HCRYPTPROV;
  212. typedef ULONG_PTR HCRYPTKEY;
  213. typedef ULONG_PTR HCRYPTHASH;
  214. // dwFlags definitions for CryptAcquireContext
  215. #define CRYPT_VERIFYCONTEXT 0xF0000000
  216. #define CRYPT_NEWKEYSET 0x00000008
  217. #define CRYPT_DELETEKEYSET 0x00000010
  218. #define CRYPT_MACHINE_KEYSET 0x00000020
  219. #define CRYPT_SILENT 0x00000040
  220. // dwFlag definitions for CryptGenKey
  221. #define CRYPT_EXPORTABLE 0x00000001
  222. #define CRYPT_USER_PROTECTED 0x00000002
  223. #define CRYPT_CREATE_SALT 0x00000004
  224. #define CRYPT_UPDATE_KEY 0x00000008
  225. #define CRYPT_NO_SALT 0x00000010
  226. #define CRYPT_PREGEN 0x00000040
  227. #define CRYPT_RECIPIENT 0x00000010
  228. #define CRYPT_INITIATOR 0x00000040
  229. #define CRYPT_ONLINE 0x00000080
  230. #define CRYPT_SF 0x00000100
  231. #define CRYPT_CREATE_IV 0x00000200
  232. #define CRYPT_KEK 0x00000400
  233. #define CRYPT_DATA_KEY 0x00000800
  234. #define CRYPT_VOLATILE 0x00001000
  235. #define CRYPT_SGCKEY 0x00002000
  236. #define CRYPT_ARCHIVABLE 0x00004000
  237. #define RSA1024BIT_KEY 0x04000000
  238. // dwFlags definitions for CryptDeriveKey
  239. #define CRYPT_SERVER 0x00000400
  240. #define KEY_LENGTH_MASK 0xFFFF0000
  241. // dwFlag definitions for CryptExportKey
  242. #define CRYPT_Y_ONLY 0x00000001
  243. #define CRYPT_SSL2_FALLBACK 0x00000002
  244. #define CRYPT_DESTROYKEY 0x00000004
  245. #define CRYPT_OAEP 0x00000040 // used with RSA encryptions/decryptions
  246. // CryptExportKey, CryptImportKey,
  247. // CryptEncrypt and CryptDecrypt
  248. #define CRYPT_BLOB_VER3 0x00000080 // export version 3 of a blob type
  249. #define CRYPT_IPSEC_HMAC_KEY 0x00000100 // CryptImportKey only
  250. // dwFlags definitions for CryptDecrypt
  251. // See also CRYPT_OAEP, above.
  252. // Note, the following flag is not supported for CryptEncrypt
  253. #define CRYPT_DECRYPT_RSA_NO_PADDING_CHECK 0x00000020
  254. // dwFlags definitions for CryptCreateHash
  255. #define CRYPT_SECRETDIGEST 0x00000001
  256. // dwFlags definitions for CryptHashData
  257. #define CRYPT_OWF_REPL_LM_HASH 0x00000001 // this is only for the OWF replacement CSP
  258. // dwFlags definitions for CryptHashSessionKey
  259. #define CRYPT_LITTLE_ENDIAN 0x00000001
  260. // dwFlags definitions for CryptSignHash and CryptVerifySignature
  261. #define CRYPT_NOHASHOID 0x00000001
  262. #define CRYPT_TYPE2_FORMAT 0x00000002
  263. #define CRYPT_X931_FORMAT 0x00000004
  264. // dwFlag definitions for CryptSetProviderEx and CryptGetDefaultProvider
  265. #define CRYPT_MACHINE_DEFAULT 0x00000001
  266. #define CRYPT_USER_DEFAULT 0x00000002
  267. #define CRYPT_DELETE_DEFAULT 0x00000004
  268. // exported key blob definitions
  269. #define SIMPLEBLOB 0x1
  270. #define PUBLICKEYBLOB 0x6
  271. #define PRIVATEKEYBLOB 0x7
  272. #define PLAINTEXTKEYBLOB 0x8
  273. #define OPAQUEKEYBLOB 0x9
  274. #define PUBLICKEYBLOBEX 0xA
  275. #define SYMMETRICWRAPKEYBLOB 0xB
  276. #define AT_KEYEXCHANGE 1
  277. #define AT_SIGNATURE 2
  278. #define CRYPT_USERDATA 1
  279. // dwParam
  280. #define KP_IV 1 // Initialization vector
  281. #define KP_SALT 2 // Salt value
  282. #define KP_PADDING 3 // Padding values
  283. #define KP_MODE 4 // Mode of the cipher
  284. #define KP_MODE_BITS 5 // Number of bits to feedback
  285. #define KP_PERMISSIONS 6 // Key permissions DWORD
  286. #define KP_ALGID 7 // Key algorithm
  287. #define KP_BLOCKLEN 8 // Block size of the cipher
  288. #define KP_KEYLEN 9 // Length of key in bits
  289. #define KP_SALT_EX 10 // Length of salt in bytes
  290. #define KP_P 11 // DSS/Diffie-Hellman P value
  291. #define KP_G 12 // DSS/Diffie-Hellman G value
  292. #define KP_Q 13 // DSS Q value
  293. #define KP_X 14 // Diffie-Hellman X value
  294. #define KP_Y 15 // Y value
  295. #define KP_RA 16 // Fortezza RA value
  296. #define KP_RB 17 // Fortezza RB value
  297. #define KP_INFO 18 // for putting information into an RSA envelope
  298. #define KP_EFFECTIVE_KEYLEN 19 // setting and getting RC2 effective key length
  299. #define KP_SCHANNEL_ALG 20 // for setting the Secure Channel algorithms
  300. #define KP_CLIENT_RANDOM 21 // for setting the Secure Channel client random data
  301. #define KP_SERVER_RANDOM 22 // for setting the Secure Channel server random data
  302. #define KP_RP 23
  303. #define KP_PRECOMP_MD5 24
  304. #define KP_PRECOMP_SHA 25
  305. #define KP_CERTIFICATE 26 // for setting Secure Channel certificate data (PCT1)
  306. #define KP_CLEAR_KEY 27 // for setting Secure Channel clear key data (PCT1)
  307. #define KP_PUB_EX_LEN 28
  308. #define KP_PUB_EX_VAL 29
  309. #define KP_KEYVAL 30
  310. #define KP_ADMIN_PIN 31
  311. #define KP_KEYEXCHANGE_PIN 32
  312. #define KP_SIGNATURE_PIN 33
  313. #define KP_PREHASH 34
  314. #define KP_ROUNDS 35
  315. #define KP_OAEP_PARAMS 36 // for setting OAEP params on RSA keys
  316. #define KP_CMS_KEY_INFO 37
  317. #define KP_CMS_DH_KEY_INFO 38
  318. #define KP_PUB_PARAMS 39 // for setting public parameters
  319. #define KP_VERIFY_PARAMS 40 // for verifying DSA and DH parameters
  320. #define KP_HIGHEST_VERSION 41 // for TLS protocol version setting
  321. #define KP_GET_USE_COUNT 42 // for use with PP_CRYPT_COUNT_KEY_USE contexts
  322. // KP_PADDING
  323. #define PKCS5_PADDING 1 // PKCS 5 (sec 6.2) padding method
  324. #define RANDOM_PADDING 2
  325. #define ZERO_PADDING 3
  326. // KP_MODE
  327. #define CRYPT_MODE_CBC 1 // Cipher block chaining
  328. #define CRYPT_MODE_ECB 2 // Electronic code book
  329. #define CRYPT_MODE_OFB 3 // Output feedback mode
  330. #define CRYPT_MODE_CFB 4 // Cipher feedback mode
  331. #define CRYPT_MODE_CTS 5 // Ciphertext stealing mode
  332. // KP_PERMISSIONS
  333. #define CRYPT_ENCRYPT 0x0001 // Allow encryption
  334. #define CRYPT_DECRYPT 0x0002 // Allow decryption
  335. #define CRYPT_EXPORT 0x0004 // Allow key to be exported
  336. #define CRYPT_READ 0x0008 // Allow parameters to be read
  337. #define CRYPT_WRITE 0x0010 // Allow parameters to be set
  338. #define CRYPT_MAC 0x0020 // Allow MACs to be used with key
  339. #define CRYPT_EXPORT_KEY 0x0040 // Allow key to be used for exporting keys
  340. #define CRYPT_IMPORT_KEY 0x0080 // Allow key to be used for importing keys
  341. #define CRYPT_ARCHIVE 0x0100 // Allow key to be exported at creation only
  342. #define HP_ALGID 0x0001 // Hash algorithm
  343. #define HP_HASHVAL 0x0002 // Hash value
  344. #define HP_HASHSIZE 0x0004 // Hash value size
  345. #define HP_HMAC_INFO 0x0005 // information for creating an HMAC
  346. #define HP_TLS1PRF_LABEL 0x0006 // label for TLS1 PRF
  347. #define HP_TLS1PRF_SEED 0x0007 // seed for TLS1 PRF
  348. #define CRYPT_FAILED FALSE
  349. #define CRYPT_SUCCEED TRUE
  350. #define RCRYPT_SUCCEEDED(rt) ((rt) == CRYPT_SUCCEED)
  351. #define RCRYPT_FAILED(rt) ((rt) == CRYPT_FAILED)
  352. //
  353. // CryptGetProvParam
  354. //
  355. #define PP_ENUMALGS 1
  356. #define PP_ENUMCONTAINERS 2
  357. #define PP_IMPTYPE 3
  358. #define PP_NAME 4
  359. #define PP_VERSION 5
  360. #define PP_CONTAINER 6
  361. #define PP_CHANGE_PASSWORD 7
  362. #define PP_KEYSET_SEC_DESCR 8 // get/set security descriptor of keyset
  363. #define PP_CERTCHAIN 9 // for retrieving certificates from tokens
  364. #define PP_KEY_TYPE_SUBTYPE 10
  365. #define PP_PROVTYPE 16
  366. #define PP_KEYSTORAGE 17
  367. #define PP_APPLI_CERT 18
  368. #define PP_SYM_KEYSIZE 19
  369. #define PP_SESSION_KEYSIZE 20
  370. #define PP_UI_PROMPT 21
  371. #define PP_ENUMALGS_EX 22
  372. #define PP_ENUMMANDROOTS 25
  373. #define PP_ENUMELECTROOTS 26
  374. #define PP_KEYSET_TYPE 27
  375. #define PP_ADMIN_PIN 31
  376. #define PP_KEYEXCHANGE_PIN 32
  377. #define PP_SIGNATURE_PIN 33
  378. #define PP_SIG_KEYSIZE_INC 34
  379. #define PP_KEYX_KEYSIZE_INC 35
  380. #define PP_UNIQUE_CONTAINER 36
  381. #define PP_SGC_INFO 37
  382. #define PP_USE_HARDWARE_RNG 38
  383. #define PP_KEYSPEC 39
  384. #define PP_ENUMEX_SIGNING_PROT 40
  385. #define PP_CRYPT_COUNT_KEY_USE 41
  386. #define CRYPT_FIRST 1
  387. #define CRYPT_NEXT 2
  388. #define CRYPT_SGC_ENUM 4
  389. #define CRYPT_IMPL_HARDWARE 1
  390. #define CRYPT_IMPL_SOFTWARE 2
  391. #define CRYPT_IMPL_MIXED 3
  392. #define CRYPT_IMPL_UNKNOWN 4
  393. #define CRYPT_IMPL_REMOVABLE 8
  394. // key storage flags
  395. #define CRYPT_SEC_DESCR 0x00000001
  396. #define CRYPT_PSTORE 0x00000002
  397. #define CRYPT_UI_PROMPT 0x00000004
  398. // protocol flags
  399. #define CRYPT_FLAG_PCT1 0x0001
  400. #define CRYPT_FLAG_SSL2 0x0002
  401. #define CRYPT_FLAG_SSL3 0x0004
  402. #define CRYPT_FLAG_TLS1 0x0008
  403. #define CRYPT_FLAG_IPSEC 0x0010
  404. #define CRYPT_FLAG_SIGNING 0x0020
  405. // SGC flags
  406. #define CRYPT_SGC 0x0001
  407. #define CRYPT_FASTSGC 0x0002
  408. //
  409. // CryptSetProvParam
  410. //
  411. #define PP_CLIENT_HWND 1
  412. #define PP_CONTEXT_INFO 11
  413. #define PP_KEYEXCHANGE_KEYSIZE 12
  414. #define PP_SIGNATURE_KEYSIZE 13
  415. #define PP_KEYEXCHANGE_ALG 14
  416. #define PP_SIGNATURE_ALG 15
  417. #define PP_DELETEKEY 24
  418. #define PROV_RSA_FULL 1
  419. #define PROV_RSA_SIG 2
  420. #define PROV_DSS 3
  421. #define PROV_FORTEZZA 4
  422. #define PROV_MS_EXCHANGE 5
  423. #define PROV_SSL 6
  424. #define PROV_RSA_SCHANNEL 12
  425. #define PROV_DSS_DH 13
  426. #define PROV_EC_ECDSA_SIG 14
  427. #define PROV_EC_ECNRA_SIG 15
  428. #define PROV_EC_ECDSA_FULL 16
  429. #define PROV_EC_ECNRA_FULL 17
  430. #define PROV_DH_SCHANNEL 18
  431. #define PROV_SPYRUS_LYNKS 20
  432. #define PROV_RNG 21
  433. #define PROV_INTEL_SEC 22
  434. #define PROV_REPLACE_OWF 23
  435. #define PROV_RSA_AES 24
  436. //
  437. // Provider friendly names
  438. //
  439. #define MS_DEF_PROV_A "Microsoft Base Cryptographic Provider v1.0"
  440. #define MS_DEF_PROV_W L"Microsoft Base Cryptographic Provider v1.0"
  441. #ifdef UNICODE
  442. #define MS_DEF_PROV MS_DEF_PROV_W
  443. #else
  444. #define MS_DEF_PROV MS_DEF_PROV_A
  445. #endif
  446. #define MS_ENHANCED_PROV_A "Microsoft Enhanced Cryptographic Provider v1.0"
  447. #define MS_ENHANCED_PROV_W L"Microsoft Enhanced Cryptographic Provider v1.0"
  448. #ifdef UNICODE
  449. #define MS_ENHANCED_PROV MS_ENHANCED_PROV_W
  450. #else
  451. #define MS_ENHANCED_PROV MS_ENHANCED_PROV_A
  452. #endif
  453. #define MS_STRONG_PROV_A "Microsoft Strong Cryptographic Provider"
  454. #define MS_STRONG_PROV_W L"Microsoft Strong Cryptographic Provider"
  455. #ifdef UNICODE
  456. #define MS_STRONG_PROV MS_STRONG_PROV_W
  457. #else
  458. #define MS_STRONG_PROV MS_STRONG_PROV_A
  459. #endif
  460. #define MS_DEF_RSA_SIG_PROV_A "Microsoft RSA Signature Cryptographic Provider"
  461. #define MS_DEF_RSA_SIG_PROV_W L"Microsoft RSA Signature Cryptographic Provider"
  462. #ifdef UNICODE
  463. #define MS_DEF_RSA_SIG_PROV MS_DEF_RSA_SIG_PROV_W
  464. #else
  465. #define MS_DEF_RSA_SIG_PROV MS_DEF_RSA_SIG_PROV_A
  466. #endif
  467. #define MS_DEF_RSA_SCHANNEL_PROV_A "Microsoft RSA SChannel Cryptographic Provider"
  468. #define MS_DEF_RSA_SCHANNEL_PROV_W L"Microsoft RSA SChannel Cryptographic Provider"
  469. #ifdef UNICODE
  470. #define MS_DEF_RSA_SCHANNEL_PROV MS_DEF_RSA_SCHANNEL_PROV_W
  471. #else
  472. #define MS_DEF_RSA_SCHANNEL_PROV MS_DEF_RSA_SCHANNEL_PROV_A
  473. #endif
  474. #define MS_DEF_DSS_PROV_A "Microsoft Base DSS Cryptographic Provider"
  475. #define MS_DEF_DSS_PROV_W L"Microsoft Base DSS Cryptographic Provider"
  476. #ifdef UNICODE
  477. #define MS_DEF_DSS_PROV MS_DEF_DSS_PROV_W
  478. #else
  479. #define MS_DEF_DSS_PROV MS_DEF_DSS_PROV_A
  480. #endif
  481. #define MS_DEF_DSS_DH_PROV_A "Microsoft Base DSS and Diffie-Hellman Cryptographic Provider"
  482. #define MS_DEF_DSS_DH_PROV_W L"Microsoft Base DSS and Diffie-Hellman Cryptographic Provider"
  483. #ifdef UNICODE
  484. #define MS_DEF_DSS_DH_PROV MS_DEF_DSS_DH_PROV_W
  485. #else
  486. #define MS_DEF_DSS_DH_PROV MS_DEF_DSS_DH_PROV_A
  487. #endif
  488. #define MS_ENH_DSS_DH_PROV_A "Microsoft Enhanced DSS and Diffie-Hellman Cryptographic Provider"
  489. #define MS_ENH_DSS_DH_PROV_W L"Microsoft Enhanced DSS and Diffie-Hellman Cryptographic Provider"
  490. #ifdef UNICODE
  491. #define MS_ENH_DSS_DH_PROV MS_ENH_DSS_DH_PROV_W
  492. #else
  493. #define MS_ENH_DSS_DH_PROV MS_ENH_DSS_DH_PROV_A
  494. #endif
  495. #define MS_DEF_DH_SCHANNEL_PROV_A "Microsoft DH SChannel Cryptographic Provider"
  496. #define MS_DEF_DH_SCHANNEL_PROV_W L"Microsoft DH SChannel Cryptographic Provider"
  497. #ifdef UNICODE
  498. #define MS_DEF_DH_SCHANNEL_PROV MS_DEF_DH_SCHANNEL_PROV_W
  499. #else
  500. #define MS_DEF_DH_SCHANNEL_PROV MS_DEF_DH_SCHANNEL_PROV_A
  501. #endif
  502. #define MS_SCARD_PROV_A "Microsoft Base Smart Card Crypto Provider"
  503. #define MS_SCARD_PROV_W L"Microsoft Base Smart Card Crypto Provider"
  504. #ifdef UNICODE
  505. #define MS_SCARD_PROV MS_SCARD_PROV_W
  506. #else
  507. #define MS_SCARD_PROV MS_SCARD_PROV_A
  508. #endif
  509. #define MS_ENH_RSA_AES_PROV_A "Microsoft Enhanced RSA and AES Cryptographic Provider"
  510. #define MS_ENH_RSA_AES_PROV_W L"Microsoft Enhanced RSA and AES Cryptographic Provider"
  511. #ifdef UNICODE
  512. #define MS_ENH_RSA_AES_PROV MS_ENH_RSA_AES_PROV_W
  513. #else
  514. #define MS_ENH_RSA_AES_PROV MS_ENH_RSA_AES_PROV_A
  515. #endif
  516. #define MAXUIDLEN 64
  517. // Exponentiation Offload Reg Location
  518. #define EXPO_OFFLOAD_REG_VALUE "ExpoOffload"
  519. #define EXPO_OFFLOAD_FUNC_NAME "OffloadModExpo"
  520. //
  521. // Registry key in which the following private key-related
  522. // values are created.
  523. //
  524. #define szKEY_CRYPTOAPI_PRIVATE_KEY_OPTIONS \
  525. "Software\\Policies\\Microsoft\\Cryptography"
  526. //
  527. // Registry value for controlling Data Protection API (DPAPI) UI settings.
  528. //
  529. #define szFORCE_KEY_PROTECTION "ForceKeyProtection"
  530. #define dwFORCE_KEY_PROTECTION_DISABLED 0x0
  531. #define dwFORCE_KEY_PROTECTION_USER_SELECT 0x1
  532. #define dwFORCE_KEY_PROTECTION_HIGH 0x2
  533. //
  534. // Registry values for enabling and controlling the caching (and timeout)
  535. // of private keys. This feature is useful only for UI-protected private
  536. // keys.
  537. //
  538. // Note that in Windows 2000 and later, private keys, once read from storage,
  539. // are cached in the associated HCRYPTPROV structure for subsequent use.
  540. //
  541. // In Server 2003 and XP SP1, new key caching behavior is available. Keys
  542. // that have been read from storage and cached may now be considered "stale"
  543. // if a period of time has elapsed since the key was last used. This forces
  544. // the key to be re-read from storage (which will make the DPAPI UI appear
  545. // again).
  546. //
  547. // To enable the new behavior, create the registry DWORD value
  548. // szKEY_CACHE_ENABLED and set it to 1. The registry DWORD value
  549. // szKEY_CACHE_SECONDS must also be created and set to the number of seconds
  550. // that a cached private key may still be considered usable.
  551. //
  552. #define szKEY_CACHE_ENABLED "CachePrivateKeys"
  553. #define szKEY_CACHE_SECONDS "PrivateKeyLifetimeSeconds"
  554. #define CUR_BLOB_VERSION 2
  555. // structure for use with CryptSetKeyParam for CMS keys
  556. // DO NOT USE THIS STRUCTURE!!!!!
  557. typedef struct _CMS_KEY_INFO {
  558. DWORD dwVersion; // sizeof(CMS_KEY_INFO)
  559. ALG_ID Algid; // algorithmm id for the key to be converted
  560. BYTE *pbOID; // pointer to OID to hash in with Z
  561. DWORD cbOID; // length of OID to hash in with Z
  562. } CMS_KEY_INFO, *PCMS_KEY_INFO;
  563. // structure for use with CryptSetHashParam with CALG_HMAC
  564. typedef struct _HMAC_Info {
  565. ALG_ID HashAlgid;
  566. BYTE *pbInnerString;
  567. DWORD cbInnerString;
  568. BYTE *pbOuterString;
  569. DWORD cbOuterString;
  570. } HMAC_INFO, *PHMAC_INFO;
  571. // structure for use with CryptSetKeyParam with KP_SCHANNEL_ALG
  572. typedef struct _SCHANNEL_ALG {
  573. DWORD dwUse;
  574. ALG_ID Algid;
  575. DWORD cBits;
  576. DWORD dwFlags;
  577. DWORD dwReserved;
  578. } SCHANNEL_ALG, *PSCHANNEL_ALG;
  579. // uses of algortihms for SCHANNEL_ALG structure
  580. #define SCHANNEL_MAC_KEY 0x00000000
  581. #define SCHANNEL_ENC_KEY 0x00000001
  582. // uses of dwFlags SCHANNEL_ALG structure
  583. #define INTERNATIONAL_USAGE 0x00000001
  584. typedef struct _PROV_ENUMALGS {
  585. ALG_ID aiAlgid;
  586. DWORD dwBitLen;
  587. DWORD dwNameLen;
  588. CHAR szName[20];
  589. } PROV_ENUMALGS;
  590. typedef struct _PROV_ENUMALGS_EX {
  591. ALG_ID aiAlgid;
  592. DWORD dwDefaultLen;
  593. DWORD dwMinLen;
  594. DWORD dwMaxLen;
  595. DWORD dwProtocols;
  596. DWORD dwNameLen;
  597. CHAR szName[20];
  598. DWORD dwLongNameLen;
  599. CHAR szLongName[40];
  600. } PROV_ENUMALGS_EX;
  601. typedef struct _PUBLICKEYSTRUC {
  602. BYTE bType;
  603. BYTE bVersion;
  604. WORD reserved;
  605. ALG_ID aiKeyAlg;
  606. } BLOBHEADER, PUBLICKEYSTRUC;
  607. typedef struct _RSAPUBKEY {
  608. DWORD magic; // Has to be RSA1
  609. DWORD bitlen; // # of bits in modulus
  610. DWORD pubexp; // public exponent
  611. // Modulus data follows
  612. } RSAPUBKEY;
  613. typedef struct _PUBKEY {
  614. DWORD magic;
  615. DWORD bitlen; // # of bits in modulus
  616. } DHPUBKEY, DSSPUBKEY, KEAPUBKEY, TEKPUBKEY;
  617. typedef struct _DSSSEED {
  618. DWORD counter;
  619. BYTE seed[20];
  620. } DSSSEED;
  621. typedef struct _PUBKEYVER3 {
  622. DWORD magic;
  623. DWORD bitlenP; // # of bits in prime modulus
  624. DWORD bitlenQ; // # of bits in prime q, 0 if not available
  625. DWORD bitlenJ; // # of bits in (p-1)/q, 0 if not available
  626. DSSSEED DSSSeed;
  627. } DHPUBKEY_VER3, DSSPUBKEY_VER3;
  628. typedef struct _PRIVKEYVER3 {
  629. DWORD magic;
  630. DWORD bitlenP; // # of bits in prime modulus
  631. DWORD bitlenQ; // # of bits in prime q, 0 if not available
  632. DWORD bitlenJ; // # of bits in (p-1)/q, 0 if not available
  633. DWORD bitlenX; // # of bits in X
  634. DSSSEED DSSSeed;
  635. } DHPRIVKEY_VER3, DSSPRIVKEY_VER3;
  636. typedef struct _KEY_TYPE_SUBTYPE {
  637. DWORD dwKeySpec;
  638. GUID Type;
  639. GUID Subtype;
  640. } KEY_TYPE_SUBTYPE, *PKEY_TYPE_SUBTYPE;
  641. typedef struct _CERT_FORTEZZA_DATA_PROP {
  642. unsigned char SerialNumber[8];
  643. int CertIndex;
  644. unsigned char CertLabel[36];
  645. } CERT_FORTEZZA_DATA_PROP;
  646. //+-------------------------------------------------------------------------
  647. // CRYPTOAPI BLOB definitions
  648. //--------------------------------------------------------------------------
  649. typedef struct _CRYPTOAPI_BLOB {
  650. DWORD cbData;
  651. BYTE *pbData;
  652. } CRYPT_INTEGER_BLOB, *PCRYPT_INTEGER_BLOB,
  653. CRYPT_UINT_BLOB, *PCRYPT_UINT_BLOB,
  654. CRYPT_OBJID_BLOB, *PCRYPT_OBJID_BLOB,
  655. CERT_NAME_BLOB, *PCERT_NAME_BLOB,
  656. CERT_RDN_VALUE_BLOB, *PCERT_RDN_VALUE_BLOB,
  657. CERT_BLOB, *PCERT_BLOB,
  658. CRL_BLOB, *PCRL_BLOB,
  659. DATA_BLOB, *PDATA_BLOB,
  660. CRYPT_DATA_BLOB, *PCRYPT_DATA_BLOB,
  661. CRYPT_HASH_BLOB, *PCRYPT_HASH_BLOB,
  662. CRYPT_DIGEST_BLOB, *PCRYPT_DIGEST_BLOB,
  663. CRYPT_DER_BLOB, *PCRYPT_DER_BLOB,
  664. CRYPT_ATTR_BLOB, *PCRYPT_ATTR_BLOB;
  665. // structure for use with CryptSetKeyParam for CMS keys
  666. typedef struct _CMS_DH_KEY_INFO {
  667. DWORD dwVersion; // sizeof(CMS_DH_KEY_INFO)
  668. ALG_ID Algid; // algorithmm id for the key to be converted
  669. LPSTR pszContentEncObjId; // pointer to OID to hash in with Z
  670. CRYPT_DATA_BLOB PubInfo; // OPTIONAL - public information
  671. void *pReserved; // reserved - should be NULL
  672. } CMS_DH_KEY_INFO, *PCMS_DH_KEY_INFO;
  673. WINADVAPI
  674. BOOL
  675. WINAPI
  676. CryptAcquireContext%(
  677. HCRYPTPROV *phProv,
  678. LPCTSTR% szContainer,
  679. LPCTSTR% szProvider,
  680. DWORD dwProvType,
  681. DWORD dwFlags
  682. );
  683. WINADVAPI
  684. BOOL
  685. WINAPI
  686. CryptReleaseContext(
  687. HCRYPTPROV hProv,
  688. DWORD dwFlags
  689. );
  690. WINADVAPI
  691. BOOL
  692. WINAPI
  693. CryptGenKey(
  694. HCRYPTPROV hProv,
  695. ALG_ID Algid,
  696. DWORD dwFlags,
  697. HCRYPTKEY *phKey
  698. );
  699. WINADVAPI
  700. BOOL
  701. WINAPI
  702. CryptDeriveKey(
  703. HCRYPTPROV hProv,
  704. ALG_ID Algid,
  705. HCRYPTHASH hBaseData,
  706. DWORD dwFlags,
  707. HCRYPTKEY *phKey
  708. );
  709. WINADVAPI
  710. BOOL
  711. WINAPI
  712. CryptDestroyKey(
  713. HCRYPTKEY hKey
  714. );
  715. WINADVAPI
  716. BOOL
  717. WINAPI
  718. CryptSetKeyParam(
  719. HCRYPTKEY hKey,
  720. DWORD dwParam,
  721. CONST BYTE *pbData,
  722. DWORD dwFlags
  723. );
  724. WINADVAPI
  725. BOOL
  726. WINAPI
  727. CryptGetKeyParam(
  728. HCRYPTKEY hKey,
  729. DWORD dwParam,
  730. BYTE *pbData,
  731. DWORD *pdwDataLen,
  732. DWORD dwFlags
  733. );
  734. WINADVAPI
  735. BOOL
  736. WINAPI
  737. CryptSetHashParam(
  738. HCRYPTHASH hHash,
  739. DWORD dwParam,
  740. CONST BYTE *pbData,
  741. DWORD dwFlags
  742. );
  743. WINADVAPI
  744. BOOL
  745. WINAPI
  746. CryptGetHashParam(
  747. HCRYPTHASH hHash,
  748. DWORD dwParam,
  749. BYTE *pbData,
  750. DWORD *pdwDataLen,
  751. DWORD dwFlags
  752. );
  753. WINADVAPI
  754. BOOL
  755. WINAPI
  756. CryptSetProvParam(
  757. HCRYPTPROV hProv,
  758. DWORD dwParam,
  759. CONST BYTE *pbData,
  760. DWORD dwFlags
  761. );
  762. WINADVAPI
  763. BOOL
  764. WINAPI
  765. CryptGetProvParam(
  766. HCRYPTPROV hProv,
  767. DWORD dwParam,
  768. BYTE *pbData,
  769. DWORD *pdwDataLen,
  770. DWORD dwFlags
  771. );
  772. WINADVAPI
  773. BOOL
  774. WINAPI
  775. CryptGenRandom(
  776. HCRYPTPROV hProv,
  777. DWORD dwLen,
  778. BYTE *pbBuffer
  779. );
  780. WINADVAPI
  781. BOOL
  782. WINAPI
  783. CryptGetUserKey(
  784. HCRYPTPROV hProv,
  785. DWORD dwKeySpec,
  786. HCRYPTKEY *phUserKey
  787. );
  788. WINADVAPI
  789. BOOL
  790. WINAPI
  791. CryptExportKey(
  792. HCRYPTKEY hKey,
  793. HCRYPTKEY hExpKey,
  794. DWORD dwBlobType,
  795. DWORD dwFlags,
  796. BYTE *pbData,
  797. DWORD *pdwDataLen
  798. );
  799. WINADVAPI
  800. BOOL
  801. WINAPI
  802. CryptImportKey(
  803. HCRYPTPROV hProv,
  804. CONST BYTE *pbData,
  805. DWORD dwDataLen,
  806. HCRYPTKEY hPubKey,
  807. DWORD dwFlags,
  808. HCRYPTKEY *phKey
  809. );
  810. WINADVAPI
  811. BOOL
  812. WINAPI
  813. CryptEncrypt(
  814. HCRYPTKEY hKey,
  815. HCRYPTHASH hHash,
  816. BOOL Final,
  817. DWORD dwFlags,
  818. BYTE *pbData,
  819. DWORD *pdwDataLen,
  820. DWORD dwBufLen
  821. );
  822. WINADVAPI
  823. BOOL
  824. WINAPI
  825. CryptDecrypt(
  826. HCRYPTKEY hKey,
  827. HCRYPTHASH hHash,
  828. BOOL Final,
  829. DWORD dwFlags,
  830. BYTE *pbData,
  831. DWORD *pdwDataLen
  832. );
  833. WINADVAPI
  834. BOOL
  835. WINAPI
  836. CryptCreateHash(
  837. HCRYPTPROV hProv,
  838. ALG_ID Algid,
  839. HCRYPTKEY hKey,
  840. DWORD dwFlags,
  841. HCRYPTHASH *phHash
  842. );
  843. WINADVAPI
  844. BOOL
  845. WINAPI
  846. CryptHashData(
  847. HCRYPTHASH hHash,
  848. CONST BYTE *pbData,
  849. DWORD dwDataLen,
  850. DWORD dwFlags
  851. );
  852. WINADVAPI
  853. BOOL
  854. WINAPI
  855. CryptHashSessionKey(
  856. HCRYPTHASH hHash,
  857. HCRYPTKEY hKey,
  858. DWORD dwFlags
  859. );
  860. WINADVAPI
  861. BOOL
  862. WINAPI
  863. CryptDestroyHash(
  864. HCRYPTHASH hHash
  865. );
  866. WINADVAPI
  867. BOOL
  868. WINAPI
  869. CryptSignHash%(
  870. HCRYPTHASH hHash,
  871. DWORD dwKeySpec,
  872. LPCTSTR% szDescription,
  873. DWORD dwFlags,
  874. BYTE *pbSignature,
  875. DWORD *pdwSigLen
  876. );
  877. WINADVAPI
  878. BOOL
  879. WINAPI
  880. CryptVerifySignature%(
  881. HCRYPTHASH hHash,
  882. CONST BYTE *pbSignature,
  883. DWORD dwSigLen,
  884. HCRYPTKEY hPubKey,
  885. LPCTSTR% szDescription,
  886. DWORD dwFlags
  887. );
  888. WINADVAPI
  889. BOOL
  890. WINAPI
  891. CryptSetProvider%(
  892. LPCTSTR% pszProvName,
  893. DWORD dwProvType
  894. );
  895. WINADVAPI
  896. BOOL
  897. WINAPI
  898. CryptSetProviderEx%(
  899. LPCTSTR% pszProvName,
  900. DWORD dwProvType,
  901. DWORD *pdwReserved,
  902. DWORD dwFlags
  903. );
  904. WINADVAPI
  905. BOOL
  906. WINAPI
  907. CryptGetDefaultProvider%(
  908. DWORD dwProvType,
  909. DWORD *pdwReserved,
  910. DWORD dwFlags,
  911. LPTSTR% pszProvName,
  912. DWORD *pcbProvName
  913. );
  914. WINADVAPI
  915. BOOL
  916. WINAPI
  917. CryptEnumProviderTypes%(
  918. DWORD dwIndex,
  919. DWORD *pdwReserved,
  920. DWORD dwFlags,
  921. DWORD *pdwProvType,
  922. LPTSTR% szTypeName,
  923. DWORD *pcbTypeName
  924. );
  925. WINADVAPI
  926. BOOL
  927. WINAPI
  928. CryptEnumProviders%(
  929. DWORD dwIndex,
  930. DWORD *pdwReserved,
  931. DWORD dwFlags,
  932. DWORD *pdwProvType,
  933. LPTSTR% szProvName,
  934. DWORD *pcbProvName
  935. );
  936. WINADVAPI
  937. BOOL
  938. WINAPI
  939. CryptContextAddRef(
  940. HCRYPTPROV hProv,
  941. DWORD *pdwReserved,
  942. DWORD dwFlags
  943. );
  944. WINADVAPI
  945. BOOL
  946. WINAPI
  947. CryptDuplicateKey(
  948. HCRYPTKEY hKey,
  949. DWORD *pdwReserved,
  950. DWORD dwFlags,
  951. HCRYPTKEY *phKey
  952. );
  953. WINADVAPI
  954. BOOL
  955. WINAPI
  956. CryptDuplicateHash(
  957. HCRYPTHASH hHash,
  958. DWORD *pdwReserved,
  959. DWORD dwFlags,
  960. HCRYPTHASH *phHash
  961. );
  962. //
  963. // This function is provided in Microsoft Windows 2000 as a means of
  964. // installing the 128-bit encryption provider. This function is unavailable
  965. // in Microsoft Windows XP, because Windows XP ships with the 128-bit
  966. // encryption provider.
  967. //
  968. BOOL
  969. __cdecl
  970. GetEncSChannel(
  971. BYTE **pData,
  972. DWORD *dwDecSize
  973. );
  974. //+-------------------------------------------------------------------------
  975. // In a CRYPT_BIT_BLOB the last byte may contain 0-7 unused bits. Therefore, the
  976. // overall bit length is cbData * 8 - cUnusedBits.
  977. //--------------------------------------------------------------------------
  978. typedef struct _CRYPT_BIT_BLOB {
  979. DWORD cbData;
  980. BYTE *pbData;
  981. DWORD cUnusedBits;
  982. } CRYPT_BIT_BLOB, *PCRYPT_BIT_BLOB;
  983. //+-------------------------------------------------------------------------
  984. // Type used for any algorithm
  985. //
  986. // Where the Parameters CRYPT_OBJID_BLOB is in its encoded representation. For most
  987. // algorithm types, the Parameters CRYPT_OBJID_BLOB is NULL (Parameters.cbData = 0).
  988. //--------------------------------------------------------------------------
  989. typedef struct _CRYPT_ALGORITHM_IDENTIFIER {
  990. LPSTR pszObjId;
  991. CRYPT_OBJID_BLOB Parameters;
  992. } CRYPT_ALGORITHM_IDENTIFIER, *PCRYPT_ALGORITHM_IDENTIFIER;
  993. // Following are the definitions of various algorithm object identifiers
  994. // RSA
  995. #define szOID_RSA "1.2.840.113549"
  996. #define szOID_PKCS "1.2.840.113549.1"
  997. #define szOID_RSA_HASH "1.2.840.113549.2"
  998. #define szOID_RSA_ENCRYPT "1.2.840.113549.3"
  999. #define szOID_PKCS_1 "1.2.840.113549.1.1"
  1000. #define szOID_PKCS_2 "1.2.840.113549.1.2"
  1001. #define szOID_PKCS_3 "1.2.840.113549.1.3"
  1002. #define szOID_PKCS_4 "1.2.840.113549.1.4"
  1003. #define szOID_PKCS_5 "1.2.840.113549.1.5"
  1004. #define szOID_PKCS_6 "1.2.840.113549.1.6"
  1005. #define szOID_PKCS_7 "1.2.840.113549.1.7"
  1006. #define szOID_PKCS_8 "1.2.840.113549.1.8"
  1007. #define szOID_PKCS_9 "1.2.840.113549.1.9"
  1008. #define szOID_PKCS_10 "1.2.840.113549.1.10"
  1009. #define szOID_PKCS_12 "1.2.840.113549.1.12"
  1010. #define szOID_RSA_RSA "1.2.840.113549.1.1.1"
  1011. #define szOID_RSA_MD2RSA "1.2.840.113549.1.1.2"
  1012. #define szOID_RSA_MD4RSA "1.2.840.113549.1.1.3"
  1013. #define szOID_RSA_MD5RSA "1.2.840.113549.1.1.4"
  1014. #define szOID_RSA_SHA1RSA "1.2.840.113549.1.1.5"
  1015. #define szOID_RSA_SETOAEP_RSA "1.2.840.113549.1.1.6"
  1016. #define szOID_RSA_DH "1.2.840.113549.1.3.1"
  1017. #define szOID_RSA_data "1.2.840.113549.1.7.1"
  1018. #define szOID_RSA_signedData "1.2.840.113549.1.7.2"
  1019. #define szOID_RSA_envelopedData "1.2.840.113549.1.7.3"
  1020. #define szOID_RSA_signEnvData "1.2.840.113549.1.7.4"
  1021. #define szOID_RSA_digestedData "1.2.840.113549.1.7.5"
  1022. #define szOID_RSA_hashedData "1.2.840.113549.1.7.5"
  1023. #define szOID_RSA_encryptedData "1.2.840.113549.1.7.6"
  1024. #define szOID_RSA_emailAddr "1.2.840.113549.1.9.1"
  1025. #define szOID_RSA_unstructName "1.2.840.113549.1.9.2"
  1026. #define szOID_RSA_contentType "1.2.840.113549.1.9.3"
  1027. #define szOID_RSA_messageDigest "1.2.840.113549.1.9.4"
  1028. #define szOID_RSA_signingTime "1.2.840.113549.1.9.5"
  1029. #define szOID_RSA_counterSign "1.2.840.113549.1.9.6"
  1030. #define szOID_RSA_challengePwd "1.2.840.113549.1.9.7"
  1031. #define szOID_RSA_unstructAddr "1.2.840.113549.1.9.8"
  1032. #define szOID_RSA_extCertAttrs "1.2.840.113549.1.9.9"
  1033. #define szOID_RSA_certExtensions "1.2.840.113549.1.9.14"
  1034. #define szOID_RSA_SMIMECapabilities "1.2.840.113549.1.9.15"
  1035. #define szOID_RSA_preferSignedData "1.2.840.113549.1.9.15.1"
  1036. #define szOID_RSA_SMIMEalg "1.2.840.113549.1.9.16.3"
  1037. #define szOID_RSA_SMIMEalgESDH "1.2.840.113549.1.9.16.3.5"
  1038. #define szOID_RSA_SMIMEalgCMS3DESwrap "1.2.840.113549.1.9.16.3.6"
  1039. #define szOID_RSA_SMIMEalgCMSRC2wrap "1.2.840.113549.1.9.16.3.7"
  1040. #define szOID_RSA_MD2 "1.2.840.113549.2.2"
  1041. #define szOID_RSA_MD4 "1.2.840.113549.2.4"
  1042. #define szOID_RSA_MD5 "1.2.840.113549.2.5"
  1043. #define szOID_RSA_RC2CBC "1.2.840.113549.3.2"
  1044. #define szOID_RSA_RC4 "1.2.840.113549.3.4"
  1045. #define szOID_RSA_DES_EDE3_CBC "1.2.840.113549.3.7"
  1046. #define szOID_RSA_RC5_CBCPad "1.2.840.113549.3.9"
  1047. #define szOID_ANSI_X942 "1.2.840.10046"
  1048. #define szOID_ANSI_X942_DH "1.2.840.10046.2.1"
  1049. #define szOID_X957 "1.2.840.10040"
  1050. #define szOID_X957_DSA "1.2.840.10040.4.1"
  1051. #define szOID_X957_SHA1DSA "1.2.840.10040.4.3"
  1052. // ITU-T UsefulDefinitions
  1053. #define szOID_DS "2.5"
  1054. #define szOID_DSALG "2.5.8"
  1055. #define szOID_DSALG_CRPT "2.5.8.1"
  1056. #define szOID_DSALG_HASH "2.5.8.2"
  1057. #define szOID_DSALG_SIGN "2.5.8.3"
  1058. #define szOID_DSALG_RSA "2.5.8.1.1"
  1059. // NIST OSE Implementors' Workshop (OIW)
  1060. // http://nemo.ncsl.nist.gov/oiw/agreements/stable/OSI/12s_9506.w51
  1061. // http://nemo.ncsl.nist.gov/oiw/agreements/working/OSI/12w_9503.w51
  1062. #define szOID_OIW "1.3.14"
  1063. // NIST OSE Implementors' Workshop (OIW) Security SIG algorithm identifiers
  1064. #define szOID_OIWSEC "1.3.14.3.2"
  1065. #define szOID_OIWSEC_md4RSA "1.3.14.3.2.2"
  1066. #define szOID_OIWSEC_md5RSA "1.3.14.3.2.3"
  1067. #define szOID_OIWSEC_md4RSA2 "1.3.14.3.2.4"
  1068. #define szOID_OIWSEC_desECB "1.3.14.3.2.6"
  1069. #define szOID_OIWSEC_desCBC "1.3.14.3.2.7"
  1070. #define szOID_OIWSEC_desOFB "1.3.14.3.2.8"
  1071. #define szOID_OIWSEC_desCFB "1.3.14.3.2.9"
  1072. #define szOID_OIWSEC_desMAC "1.3.14.3.2.10"
  1073. #define szOID_OIWSEC_rsaSign "1.3.14.3.2.11"
  1074. #define szOID_OIWSEC_dsa "1.3.14.3.2.12"
  1075. #define szOID_OIWSEC_shaDSA "1.3.14.3.2.13"
  1076. #define szOID_OIWSEC_mdc2RSA "1.3.14.3.2.14"
  1077. #define szOID_OIWSEC_shaRSA "1.3.14.3.2.15"
  1078. #define szOID_OIWSEC_dhCommMod "1.3.14.3.2.16"
  1079. #define szOID_OIWSEC_desEDE "1.3.14.3.2.17"
  1080. #define szOID_OIWSEC_sha "1.3.14.3.2.18"
  1081. #define szOID_OIWSEC_mdc2 "1.3.14.3.2.19"
  1082. #define szOID_OIWSEC_dsaComm "1.3.14.3.2.20"
  1083. #define szOID_OIWSEC_dsaCommSHA "1.3.14.3.2.21"
  1084. #define szOID_OIWSEC_rsaXchg "1.3.14.3.2.22"
  1085. #define szOID_OIWSEC_keyHashSeal "1.3.14.3.2.23"
  1086. #define szOID_OIWSEC_md2RSASign "1.3.14.3.2.24"
  1087. #define szOID_OIWSEC_md5RSASign "1.3.14.3.2.25"
  1088. #define szOID_OIWSEC_sha1 "1.3.14.3.2.26"
  1089. #define szOID_OIWSEC_dsaSHA1 "1.3.14.3.2.27"
  1090. #define szOID_OIWSEC_dsaCommSHA1 "1.3.14.3.2.28"
  1091. #define szOID_OIWSEC_sha1RSASign "1.3.14.3.2.29"
  1092. // NIST OSE Implementors' Workshop (OIW) Directory SIG algorithm identifiers
  1093. #define szOID_OIWDIR "1.3.14.7.2"
  1094. #define szOID_OIWDIR_CRPT "1.3.14.7.2.1"
  1095. #define szOID_OIWDIR_HASH "1.3.14.7.2.2"
  1096. #define szOID_OIWDIR_SIGN "1.3.14.7.2.3"
  1097. #define szOID_OIWDIR_md2 "1.3.14.7.2.2.1"
  1098. #define szOID_OIWDIR_md2RSA "1.3.14.7.2.3.1"
  1099. // INFOSEC Algorithms
  1100. // joint-iso-ccitt(2) country(16) us(840) organization(1) us-government(101) dod(2) id-infosec(1)
  1101. #define szOID_INFOSEC "2.16.840.1.101.2.1"
  1102. #define szOID_INFOSEC_sdnsSignature "2.16.840.1.101.2.1.1.1"
  1103. #define szOID_INFOSEC_mosaicSignature "2.16.840.1.101.2.1.1.2"
  1104. #define szOID_INFOSEC_sdnsConfidentiality "2.16.840.1.101.2.1.1.3"
  1105. #define szOID_INFOSEC_mosaicConfidentiality "2.16.840.1.101.2.1.1.4"
  1106. #define szOID_INFOSEC_sdnsIntegrity "2.16.840.1.101.2.1.1.5"
  1107. #define szOID_INFOSEC_mosaicIntegrity "2.16.840.1.101.2.1.1.6"
  1108. #define szOID_INFOSEC_sdnsTokenProtection "2.16.840.1.101.2.1.1.7"
  1109. #define szOID_INFOSEC_mosaicTokenProtection "2.16.840.1.101.2.1.1.8"
  1110. #define szOID_INFOSEC_sdnsKeyManagement "2.16.840.1.101.2.1.1.9"
  1111. #define szOID_INFOSEC_mosaicKeyManagement "2.16.840.1.101.2.1.1.10"
  1112. #define szOID_INFOSEC_sdnsKMandSig "2.16.840.1.101.2.1.1.11"
  1113. #define szOID_INFOSEC_mosaicKMandSig "2.16.840.1.101.2.1.1.12"
  1114. #define szOID_INFOSEC_SuiteASignature "2.16.840.1.101.2.1.1.13"
  1115. #define szOID_INFOSEC_SuiteAConfidentiality "2.16.840.1.101.2.1.1.14"
  1116. #define szOID_INFOSEC_SuiteAIntegrity "2.16.840.1.101.2.1.1.15"
  1117. #define szOID_INFOSEC_SuiteATokenProtection "2.16.840.1.101.2.1.1.16"
  1118. #define szOID_INFOSEC_SuiteAKeyManagement "2.16.840.1.101.2.1.1.17"
  1119. #define szOID_INFOSEC_SuiteAKMandSig "2.16.840.1.101.2.1.1.18"
  1120. #define szOID_INFOSEC_mosaicUpdatedSig "2.16.840.1.101.2.1.1.19"
  1121. #define szOID_INFOSEC_mosaicKMandUpdSig "2.16.840.1.101.2.1.1.20"
  1122. #define szOID_INFOSEC_mosaicUpdatedInteg "2.16.840.1.101.2.1.1.21"
  1123. typedef struct _CRYPT_OBJID_TABLE {
  1124. DWORD dwAlgId;
  1125. LPCSTR pszObjId;
  1126. } CRYPT_OBJID_TABLE, *PCRYPT_OBJID_TABLE;
  1127. //+-------------------------------------------------------------------------
  1128. // PKCS #1 HashInfo (DigestInfo)
  1129. //--------------------------------------------------------------------------
  1130. typedef struct _CRYPT_HASH_INFO {
  1131. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  1132. CRYPT_HASH_BLOB Hash;
  1133. } CRYPT_HASH_INFO, *PCRYPT_HASH_INFO;
  1134. //+-------------------------------------------------------------------------
  1135. // Type used for an extension to an encoded content
  1136. //
  1137. // Where the Value's CRYPT_OBJID_BLOB is in its encoded representation.
  1138. //--------------------------------------------------------------------------
  1139. typedef struct _CERT_EXTENSION {
  1140. LPSTR pszObjId;
  1141. BOOL fCritical;
  1142. CRYPT_OBJID_BLOB Value;
  1143. } CERT_EXTENSION, *PCERT_EXTENSION;
  1144. //+-------------------------------------------------------------------------
  1145. // AttributeTypeValue
  1146. //
  1147. // Where the Value's CRYPT_OBJID_BLOB is in its encoded representation.
  1148. //--------------------------------------------------------------------------
  1149. typedef struct _CRYPT_ATTRIBUTE_TYPE_VALUE {
  1150. LPSTR pszObjId;
  1151. CRYPT_OBJID_BLOB Value;
  1152. } CRYPT_ATTRIBUTE_TYPE_VALUE, *PCRYPT_ATTRIBUTE_TYPE_VALUE;
  1153. //+-------------------------------------------------------------------------
  1154. // Attributes
  1155. //
  1156. // Where the Value's PATTR_BLOBs are in their encoded representation.
  1157. //--------------------------------------------------------------------------
  1158. typedef struct _CRYPT_ATTRIBUTE {
  1159. LPSTR pszObjId;
  1160. DWORD cValue;
  1161. PCRYPT_ATTR_BLOB rgValue;
  1162. } CRYPT_ATTRIBUTE, *PCRYPT_ATTRIBUTE;
  1163. typedef struct _CRYPT_ATTRIBUTES {
  1164. IN DWORD cAttr;
  1165. IN PCRYPT_ATTRIBUTE rgAttr;
  1166. } CRYPT_ATTRIBUTES, *PCRYPT_ATTRIBUTES;
  1167. //+-------------------------------------------------------------------------
  1168. // Attributes making up a Relative Distinguished Name (CERT_RDN)
  1169. //
  1170. // The interpretation of the Value depends on the dwValueType.
  1171. // See below for a list of the types.
  1172. //--------------------------------------------------------------------------
  1173. typedef struct _CERT_RDN_ATTR {
  1174. LPSTR pszObjId;
  1175. DWORD dwValueType;
  1176. CERT_RDN_VALUE_BLOB Value;
  1177. } CERT_RDN_ATTR, *PCERT_RDN_ATTR;
  1178. //+-------------------------------------------------------------------------
  1179. // CERT_RDN attribute Object Identifiers
  1180. //--------------------------------------------------------------------------
  1181. // Labeling attribute types:
  1182. #define szOID_COMMON_NAME "2.5.4.3" // case-ignore string
  1183. #define szOID_SUR_NAME "2.5.4.4" // case-ignore string
  1184. #define szOID_DEVICE_SERIAL_NUMBER "2.5.4.5" // printable string
  1185. // Geographic attribute types:
  1186. #define szOID_COUNTRY_NAME "2.5.4.6" // printable 2char string
  1187. #define szOID_LOCALITY_NAME "2.5.4.7" // case-ignore string
  1188. #define szOID_STATE_OR_PROVINCE_NAME "2.5.4.8" // case-ignore string
  1189. #define szOID_STREET_ADDRESS "2.5.4.9" // case-ignore string
  1190. // Organizational attribute types:
  1191. #define szOID_ORGANIZATION_NAME "2.5.4.10" // case-ignore string
  1192. #define szOID_ORGANIZATIONAL_UNIT_NAME "2.5.4.11" // case-ignore string
  1193. #define szOID_TITLE "2.5.4.12" // case-ignore string
  1194. // Explanatory attribute types:
  1195. #define szOID_DESCRIPTION "2.5.4.13" // case-ignore string
  1196. #define szOID_SEARCH_GUIDE "2.5.4.14"
  1197. #define szOID_BUSINESS_CATEGORY "2.5.4.15" // case-ignore string
  1198. // Postal addressing attribute types:
  1199. #define szOID_POSTAL_ADDRESS "2.5.4.16"
  1200. #define szOID_POSTAL_CODE "2.5.4.17" // case-ignore string
  1201. #define szOID_POST_OFFICE_BOX "2.5.4.18" // case-ignore string
  1202. #define szOID_PHYSICAL_DELIVERY_OFFICE_NAME "2.5.4.19" // case-ignore string
  1203. // Telecommunications addressing attribute types:
  1204. #define szOID_TELEPHONE_NUMBER "2.5.4.20" // telephone number
  1205. #define szOID_TELEX_NUMBER "2.5.4.21"
  1206. #define szOID_TELETEXT_TERMINAL_IDENTIFIER "2.5.4.22"
  1207. #define szOID_FACSIMILE_TELEPHONE_NUMBER "2.5.4.23"
  1208. #define szOID_X21_ADDRESS "2.5.4.24" // numeric string
  1209. #define szOID_INTERNATIONAL_ISDN_NUMBER "2.5.4.25" // numeric string
  1210. #define szOID_REGISTERED_ADDRESS "2.5.4.26"
  1211. #define szOID_DESTINATION_INDICATOR "2.5.4.27" // printable string
  1212. // Preference attribute types:
  1213. #define szOID_PREFERRED_DELIVERY_METHOD "2.5.4.28"
  1214. // OSI application attribute types:
  1215. #define szOID_PRESENTATION_ADDRESS "2.5.4.29"
  1216. #define szOID_SUPPORTED_APPLICATION_CONTEXT "2.5.4.30"
  1217. // Relational application attribute types:
  1218. #define szOID_MEMBER "2.5.4.31"
  1219. #define szOID_OWNER "2.5.4.32"
  1220. #define szOID_ROLE_OCCUPANT "2.5.4.33"
  1221. #define szOID_SEE_ALSO "2.5.4.34"
  1222. // Security attribute types:
  1223. #define szOID_USER_PASSWORD "2.5.4.35"
  1224. #define szOID_USER_CERTIFICATE "2.5.4.36"
  1225. #define szOID_CA_CERTIFICATE "2.5.4.37"
  1226. #define szOID_AUTHORITY_REVOCATION_LIST "2.5.4.38"
  1227. #define szOID_CERTIFICATE_REVOCATION_LIST "2.5.4.39"
  1228. #define szOID_CROSS_CERTIFICATE_PAIR "2.5.4.40"
  1229. // Undocumented attribute types???
  1230. //#define szOID_??? "2.5.4.41"
  1231. #define szOID_GIVEN_NAME "2.5.4.42" // case-ignore string
  1232. #define szOID_INITIALS "2.5.4.43" // case-ignore string
  1233. // The DN Qualifier attribute type specifies disambiguating information to add
  1234. // to the relative distinguished name of an entry. It is intended to be used
  1235. // for entries held in multiple DSAs which would otherwise have the same name,
  1236. // and that its value be the same in a given DSA for all entries to which
  1237. // the information has been added.
  1238. #define szOID_DN_QUALIFIER "2.5.4.46"
  1239. // Pilot user attribute types:
  1240. #define szOID_DOMAIN_COMPONENT "0.9.2342.19200300.100.1.25" // IA5, UTF8 string
  1241. // used for PKCS 12 attributes
  1242. #define szOID_PKCS_12_FRIENDLY_NAME_ATTR "1.2.840.113549.1.9.20"
  1243. #define szOID_PKCS_12_LOCAL_KEY_ID "1.2.840.113549.1.9.21"
  1244. #define szOID_PKCS_12_KEY_PROVIDER_NAME_ATTR "1.3.6.1.4.1.311.17.1"
  1245. #define szOID_LOCAL_MACHINE_KEYSET "1.3.6.1.4.1.311.17.2"
  1246. //+-------------------------------------------------------------------------
  1247. // Microsoft CERT_RDN attribute Object Identifiers
  1248. //--------------------------------------------------------------------------
  1249. // Special RDN containing the KEY_ID. Its value type is CERT_RDN_OCTET_STRING.
  1250. #define szOID_KEYID_RDN "1.3.6.1.4.1.311.10.7.1"
  1251. //+-------------------------------------------------------------------------
  1252. // CERT_RDN Attribute Value Types
  1253. //
  1254. // For RDN_ENCODED_BLOB, the Value's CERT_RDN_VALUE_BLOB is in its encoded
  1255. // representation. Otherwise, its an array of bytes.
  1256. //
  1257. // For all CERT_RDN types, Value.cbData is always the number of bytes, not
  1258. // necessarily the number of elements in the string. For instance,
  1259. // RDN_UNIVERSAL_STRING is an array of ints (cbData == intCnt * 4) and
  1260. // RDN_BMP_STRING is an array of unsigned shorts (cbData == ushortCnt * 2).
  1261. //
  1262. // A RDN_UTF8_STRING is an array of UNICODE characters (cbData == charCnt *2).
  1263. // These UNICODE characters are encoded as UTF8 8 bit characters.
  1264. //
  1265. // For CertDecodeName, two 0 bytes are always appended to the end of the
  1266. // string (ensures a CHAR or WCHAR string is null terminated).
  1267. // These added 0 bytes are't included in the BLOB.cbData.
  1268. //--------------------------------------------------------------------------
  1269. #define CERT_RDN_ANY_TYPE 0
  1270. #define CERT_RDN_ENCODED_BLOB 1
  1271. #define CERT_RDN_OCTET_STRING 2
  1272. #define CERT_RDN_NUMERIC_STRING 3
  1273. #define CERT_RDN_PRINTABLE_STRING 4
  1274. #define CERT_RDN_TELETEX_STRING 5
  1275. #define CERT_RDN_T61_STRING 5
  1276. #define CERT_RDN_VIDEOTEX_STRING 6
  1277. #define CERT_RDN_IA5_STRING 7
  1278. #define CERT_RDN_GRAPHIC_STRING 8
  1279. #define CERT_RDN_VISIBLE_STRING 9
  1280. #define CERT_RDN_ISO646_STRING 9
  1281. #define CERT_RDN_GENERAL_STRING 10
  1282. #define CERT_RDN_UNIVERSAL_STRING 11
  1283. #define CERT_RDN_INT4_STRING 11
  1284. #define CERT_RDN_BMP_STRING 12
  1285. #define CERT_RDN_UNICODE_STRING 12
  1286. #define CERT_RDN_UTF8_STRING 13
  1287. #define CERT_RDN_TYPE_MASK 0x000000FF
  1288. #define CERT_RDN_FLAGS_MASK 0xFF000000
  1289. //+-------------------------------------------------------------------------
  1290. // Flags that can be or'ed with the above Value Type when encoding/decoding
  1291. //--------------------------------------------------------------------------
  1292. // For encoding: when set, CERT_RDN_T61_STRING is selected instead of
  1293. // CERT_RDN_UNICODE_STRING if all the unicode characters are <= 0xFF
  1294. #define CERT_RDN_ENABLE_T61_UNICODE_FLAG 0x80000000
  1295. // For encoding: when set, CERT_RDN_UTF8_STRING is selected instead of
  1296. // CERT_RDN_UNICODE_STRING.
  1297. #define CERT_RDN_ENABLE_UTF8_UNICODE_FLAG 0x20000000
  1298. // For encoding: when set, the characters aren't checked to see if they
  1299. // are valid for the Value Type.
  1300. #define CERT_RDN_DISABLE_CHECK_TYPE_FLAG 0x40000000
  1301. // For decoding: by default, CERT_RDN_T61_STRING values are initially decoded
  1302. // as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  1303. // Setting this flag skips the initial attempt to decode as UTF8.
  1304. #define CERT_RDN_DISABLE_IE4_UTF8_FLAG 0x01000000
  1305. // Macro to check that the dwValueType is a character string and not an
  1306. // encoded blob or octet string
  1307. #define IS_CERT_RDN_CHAR_STRING(X) \
  1308. (((X) & CERT_RDN_TYPE_MASK) >= CERT_RDN_NUMERIC_STRING)
  1309. //+-------------------------------------------------------------------------
  1310. // A CERT_RDN consists of an array of the above attributes
  1311. //--------------------------------------------------------------------------
  1312. typedef struct _CERT_RDN {
  1313. DWORD cRDNAttr;
  1314. PCERT_RDN_ATTR rgRDNAttr;
  1315. } CERT_RDN, *PCERT_RDN;
  1316. //+-------------------------------------------------------------------------
  1317. // Information stored in a subject's or issuer's name. The information
  1318. // is represented as an array of the above RDNs.
  1319. //--------------------------------------------------------------------------
  1320. typedef struct _CERT_NAME_INFO {
  1321. DWORD cRDN;
  1322. PCERT_RDN rgRDN;
  1323. } CERT_NAME_INFO, *PCERT_NAME_INFO;
  1324. //+-------------------------------------------------------------------------
  1325. // Name attribute value without the Object Identifier
  1326. //
  1327. // The interpretation of the Value depends on the dwValueType.
  1328. // See above for a list of the types.
  1329. //--------------------------------------------------------------------------
  1330. typedef struct _CERT_NAME_VALUE {
  1331. DWORD dwValueType;
  1332. CERT_RDN_VALUE_BLOB Value;
  1333. } CERT_NAME_VALUE, *PCERT_NAME_VALUE;
  1334. //+-------------------------------------------------------------------------
  1335. // Public Key Info
  1336. //
  1337. // The PublicKey is the encoded representation of the information as it is
  1338. // stored in the bit string
  1339. //--------------------------------------------------------------------------
  1340. typedef struct _CERT_PUBLIC_KEY_INFO {
  1341. CRYPT_ALGORITHM_IDENTIFIER Algorithm;
  1342. CRYPT_BIT_BLOB PublicKey;
  1343. } CERT_PUBLIC_KEY_INFO, *PCERT_PUBLIC_KEY_INFO;
  1344. #define CERT_RSA_PUBLIC_KEY_OBJID szOID_RSA_RSA
  1345. #define CERT_DEFAULT_OID_PUBLIC_KEY_SIGN szOID_RSA_RSA
  1346. #define CERT_DEFAULT_OID_PUBLIC_KEY_XCHG szOID_RSA_RSA
  1347. //+-------------------------------------------------------------------------
  1348. // structure that contains all the information in a PKCS#8 PrivateKeyInfo
  1349. //--------------------------------------------------------------------------
  1350. typedef struct _CRYPT_PRIVATE_KEY_INFO{
  1351. DWORD Version;
  1352. CRYPT_ALGORITHM_IDENTIFIER Algorithm;
  1353. CRYPT_DER_BLOB PrivateKey;
  1354. PCRYPT_ATTRIBUTES pAttributes;
  1355. } CRYPT_PRIVATE_KEY_INFO, *PCRYPT_PRIVATE_KEY_INFO;
  1356. //+-------------------------------------------------------------------------
  1357. // structure that contains all the information in a PKCS#8
  1358. // EncryptedPrivateKeyInfo
  1359. //--------------------------------------------------------------------------
  1360. typedef struct _CRYPT_ENCRYPTED_PRIVATE_KEY_INFO{
  1361. CRYPT_ALGORITHM_IDENTIFIER EncryptionAlgorithm;
  1362. CRYPT_DATA_BLOB EncryptedPrivateKey;
  1363. } CRYPT_ENCRYPTED_PRIVATE_KEY_INFO, *PCRYPT_ENCRYPTED_PRIVATE_KEY_INFO;
  1364. //+-------------------------------------------------------------------------
  1365. // this callback is given when an EncryptedProvateKeyInfo structure is
  1366. // encountered during ImportPKCS8. the caller is then expected to decrypt
  1367. // the private key and hand back the decrypted contents.
  1368. //
  1369. // the parameters are:
  1370. // Algorithm - the algorithm used to encrypt the PrivateKeyInfo
  1371. // EncryptedPrivateKey - the encrypted private key blob
  1372. // pClearTextKey - a buffer to receive the clear text
  1373. // cbClearTextKey - the number of bytes of the pClearTextKey buffer
  1374. // note the if this is zero then this should be
  1375. // filled in with the size required to decrypt the
  1376. // key into, and pClearTextKey should be ignored
  1377. // pVoidDecryptFunc - this is the pVoid that was passed into the call
  1378. // and is preserved and passed back as context
  1379. //+-------------------------------------------------------------------------
  1380. typedef BOOL (CALLBACK *PCRYPT_DECRYPT_PRIVATE_KEY_FUNC)(
  1381. CRYPT_ALGORITHM_IDENTIFIER Algorithm,
  1382. CRYPT_DATA_BLOB EncryptedPrivateKey,
  1383. BYTE *pbClearTextKey,
  1384. DWORD *pcbClearTextKey,
  1385. LPVOID pVoidDecryptFunc);
  1386. //+-------------------------------------------------------------------------
  1387. // this callback is given when creating a PKCS8 EncryptedPrivateKeyInfo.
  1388. // The caller is then expected to encrypt the private key and hand back
  1389. // the encrypted contents.
  1390. //
  1391. // the parameters are:
  1392. // Algorithm - the algorithm used to encrypt the PrivateKeyInfo
  1393. // pClearTextPrivateKey - the cleartext private key to be encrypted
  1394. // pbEncryptedKey - the output encrypted private key blob
  1395. // cbEncryptedKey - the number of bytes of the pbEncryptedKey buffer
  1396. // note the if this is zero then this should be
  1397. // filled in with the size required to encrypt the
  1398. // key into, and pbEncryptedKey should be ignored
  1399. // pVoidEncryptFunc - this is the pVoid that was passed into the call
  1400. // and is preserved and passed back as context
  1401. //+-------------------------------------------------------------------------
  1402. typedef BOOL (CALLBACK *PCRYPT_ENCRYPT_PRIVATE_KEY_FUNC)(
  1403. CRYPT_ALGORITHM_IDENTIFIER* pAlgorithm,
  1404. CRYPT_DATA_BLOB* pClearTextPrivateKey,
  1405. BYTE *pbEncryptedKey,
  1406. DWORD *pcbEncryptedKey,
  1407. LPVOID pVoidEncryptFunc);
  1408. //+-------------------------------------------------------------------------
  1409. // this callback is given from the context of a ImportPKCS8 calls. the caller
  1410. // is then expected to hand back an HCRYPTPROV to receive the key being imported
  1411. //
  1412. // the parameters are:
  1413. // pPrivateKeyInfo - pointer to a CRYPT_PRIVATE_KEY_INFO structure which
  1414. // describes the key being imported
  1415. // EncryptedPrivateKey - the encrypted private key blob
  1416. // phCryptProv - a pointer to a HCRRYPTPROV to be filled in
  1417. // pVoidResolveFunc - this is the pVoidResolveFunc passed in by the caller in the
  1418. // CRYPT_PRIVATE_KEY_BLOB_AND_PARAMS struct
  1419. //+-------------------------------------------------------------------------
  1420. typedef BOOL (CALLBACK *PCRYPT_RESOLVE_HCRYPTPROV_FUNC)(
  1421. CRYPT_PRIVATE_KEY_INFO *pPrivateKeyInfo,
  1422. HCRYPTPROV *phCryptProv,
  1423. LPVOID pVoidResolveFunc);
  1424. //+-------------------------------------------------------------------------
  1425. // this struct contains a PKCS8 private key and two pointers to callback
  1426. // functions, with a corresponding pVoids. the first callback is used to give
  1427. // the caller the opportunity to specify where the key is imported to. the callback
  1428. // passes the caller the algoroithm OID and key size to use in making the decision.
  1429. // the other callback is used to decrypt the private key if the PKCS8 contains an
  1430. // EncryptedPrivateKeyInfo. both pVoids are preserved and passed back to the caller
  1431. // in the respective callback
  1432. //+-------------------------------------------------------------------------
  1433. typedef struct _CRYPT_PKCS8_IMPORT_PARAMS{
  1434. CRYPT_DIGEST_BLOB PrivateKey; // PKCS8 blob
  1435. PCRYPT_RESOLVE_HCRYPTPROV_FUNC pResolvehCryptProvFunc; // optional
  1436. LPVOID pVoidResolveFunc; // optional
  1437. PCRYPT_DECRYPT_PRIVATE_KEY_FUNC pDecryptPrivateKeyFunc;
  1438. LPVOID pVoidDecryptFunc;
  1439. } CRYPT_PKCS8_IMPORT_PARAMS, *PCRYPT_PKCS8_IMPORT_PARAMS, CRYPT_PRIVATE_KEY_BLOB_AND_PARAMS, *PCRYPT_PRIVATE_KEY_BLOB_AND_PARAMS;
  1440. //+-------------------------------------------------------------------------
  1441. // this struct contains information identifying a private key and a pointer
  1442. // to a callback function, with a corresponding pVoid. The callback is used
  1443. // to encrypt the private key. If the pEncryptPrivateKeyFunc is NULL, the
  1444. // key will not be encrypted and an EncryptedPrivateKeyInfo will not be generated.
  1445. // The pVoid is preserved and passed back to the caller in the respective callback
  1446. //+-------------------------------------------------------------------------
  1447. typedef struct _CRYPT_PKCS8_EXPORT_PARAMS{
  1448. HCRYPTPROV hCryptProv;
  1449. DWORD dwKeySpec;
  1450. LPSTR pszPrivateKeyObjId;
  1451. PCRYPT_ENCRYPT_PRIVATE_KEY_FUNC pEncryptPrivateKeyFunc;
  1452. LPVOID pVoidEncryptFunc;
  1453. } CRYPT_PKCS8_EXPORT_PARAMS, *PCRYPT_PKCS8_EXPORT_PARAMS;
  1454. //+-------------------------------------------------------------------------
  1455. // Information stored in a certificate
  1456. //
  1457. // The Issuer, Subject, Algorithm, PublicKey and Extension BLOBs are the
  1458. // encoded representation of the information.
  1459. //--------------------------------------------------------------------------
  1460. typedef struct _CERT_INFO {
  1461. DWORD dwVersion;
  1462. CRYPT_INTEGER_BLOB SerialNumber;
  1463. CRYPT_ALGORITHM_IDENTIFIER SignatureAlgorithm;
  1464. CERT_NAME_BLOB Issuer;
  1465. FILETIME NotBefore;
  1466. FILETIME NotAfter;
  1467. CERT_NAME_BLOB Subject;
  1468. CERT_PUBLIC_KEY_INFO SubjectPublicKeyInfo;
  1469. CRYPT_BIT_BLOB IssuerUniqueId;
  1470. CRYPT_BIT_BLOB SubjectUniqueId;
  1471. DWORD cExtension;
  1472. PCERT_EXTENSION rgExtension;
  1473. } CERT_INFO, *PCERT_INFO;
  1474. //+-------------------------------------------------------------------------
  1475. // Certificate versions
  1476. //--------------------------------------------------------------------------
  1477. #define CERT_V1 0
  1478. #define CERT_V2 1
  1479. #define CERT_V3 2
  1480. //+-------------------------------------------------------------------------
  1481. // Certificate Information Flags
  1482. //--------------------------------------------------------------------------
  1483. #define CERT_INFO_VERSION_FLAG 1
  1484. #define CERT_INFO_SERIAL_NUMBER_FLAG 2
  1485. #define CERT_INFO_SIGNATURE_ALGORITHM_FLAG 3
  1486. #define CERT_INFO_ISSUER_FLAG 4
  1487. #define CERT_INFO_NOT_BEFORE_FLAG 5
  1488. #define CERT_INFO_NOT_AFTER_FLAG 6
  1489. #define CERT_INFO_SUBJECT_FLAG 7
  1490. #define CERT_INFO_SUBJECT_PUBLIC_KEY_INFO_FLAG 8
  1491. #define CERT_INFO_ISSUER_UNIQUE_ID_FLAG 9
  1492. #define CERT_INFO_SUBJECT_UNIQUE_ID_FLAG 10
  1493. #define CERT_INFO_EXTENSION_FLAG 11
  1494. //+-------------------------------------------------------------------------
  1495. // An entry in a CRL
  1496. //
  1497. // The Extension BLOBs are the encoded representation of the information.
  1498. //--------------------------------------------------------------------------
  1499. typedef struct _CRL_ENTRY {
  1500. CRYPT_INTEGER_BLOB SerialNumber;
  1501. FILETIME RevocationDate;
  1502. DWORD cExtension;
  1503. PCERT_EXTENSION rgExtension;
  1504. } CRL_ENTRY, *PCRL_ENTRY;
  1505. //+-------------------------------------------------------------------------
  1506. // Information stored in a CRL
  1507. //
  1508. // The Issuer, Algorithm and Extension BLOBs are the encoded
  1509. // representation of the information.
  1510. //--------------------------------------------------------------------------
  1511. typedef struct _CRL_INFO {
  1512. DWORD dwVersion;
  1513. CRYPT_ALGORITHM_IDENTIFIER SignatureAlgorithm;
  1514. CERT_NAME_BLOB Issuer;
  1515. FILETIME ThisUpdate;
  1516. FILETIME NextUpdate;
  1517. DWORD cCRLEntry;
  1518. PCRL_ENTRY rgCRLEntry;
  1519. DWORD cExtension;
  1520. PCERT_EXTENSION rgExtension;
  1521. } CRL_INFO, *PCRL_INFO;
  1522. //+-------------------------------------------------------------------------
  1523. // CRL versions
  1524. //--------------------------------------------------------------------------
  1525. #define CRL_V1 0
  1526. #define CRL_V2 1
  1527. //+-------------------------------------------------------------------------
  1528. // Information stored in a certificate request
  1529. //
  1530. // The Subject, Algorithm, PublicKey and Attribute BLOBs are the encoded
  1531. // representation of the information.
  1532. //--------------------------------------------------------------------------
  1533. typedef struct _CERT_REQUEST_INFO {
  1534. DWORD dwVersion;
  1535. CERT_NAME_BLOB Subject;
  1536. CERT_PUBLIC_KEY_INFO SubjectPublicKeyInfo;
  1537. DWORD cAttribute;
  1538. PCRYPT_ATTRIBUTE rgAttribute;
  1539. } CERT_REQUEST_INFO, *PCERT_REQUEST_INFO;
  1540. //+-------------------------------------------------------------------------
  1541. // Certificate Request versions
  1542. //--------------------------------------------------------------------------
  1543. #define CERT_REQUEST_V1 0
  1544. //+-------------------------------------------------------------------------
  1545. // Information stored in Netscape's Keygen request
  1546. //--------------------------------------------------------------------------
  1547. typedef struct _CERT_KEYGEN_REQUEST_INFO {
  1548. DWORD dwVersion;
  1549. CERT_PUBLIC_KEY_INFO SubjectPublicKeyInfo;
  1550. LPWSTR pwszChallengeString; // encoded as IA5
  1551. } CERT_KEYGEN_REQUEST_INFO, *PCERT_KEYGEN_REQUEST_INFO;
  1552. #define CERT_KEYGEN_REQUEST_V1 0
  1553. //+-------------------------------------------------------------------------
  1554. // Certificate, CRL, Certificate Request or Keygen Request Signed Content
  1555. //
  1556. // The "to be signed" encoded content plus its signature. The ToBeSigned
  1557. // is the encoded CERT_INFO, CRL_INFO, CERT_REQUEST_INFO or
  1558. // CERT_KEYGEN_REQUEST_INFO.
  1559. //--------------------------------------------------------------------------
  1560. typedef struct _CERT_SIGNED_CONTENT_INFO {
  1561. CRYPT_DER_BLOB ToBeSigned;
  1562. CRYPT_ALGORITHM_IDENTIFIER SignatureAlgorithm;
  1563. CRYPT_BIT_BLOB Signature;
  1564. } CERT_SIGNED_CONTENT_INFO, *PCERT_SIGNED_CONTENT_INFO;
  1565. //+-------------------------------------------------------------------------
  1566. // Certificate Trust List (CTL)
  1567. //--------------------------------------------------------------------------
  1568. //+-------------------------------------------------------------------------
  1569. // CTL Usage. Also used for EnhancedKeyUsage extension.
  1570. //--------------------------------------------------------------------------
  1571. typedef struct _CTL_USAGE {
  1572. DWORD cUsageIdentifier;
  1573. LPSTR *rgpszUsageIdentifier; // array of pszObjId
  1574. } CTL_USAGE, *PCTL_USAGE,
  1575. CERT_ENHKEY_USAGE, *PCERT_ENHKEY_USAGE;
  1576. //+-------------------------------------------------------------------------
  1577. // An entry in a CTL
  1578. //--------------------------------------------------------------------------
  1579. typedef struct _CTL_ENTRY {
  1580. CRYPT_DATA_BLOB SubjectIdentifier; // For example, its hash
  1581. DWORD cAttribute;
  1582. PCRYPT_ATTRIBUTE rgAttribute; // OPTIONAL
  1583. } CTL_ENTRY, *PCTL_ENTRY;
  1584. //+-------------------------------------------------------------------------
  1585. // Information stored in a CTL
  1586. //--------------------------------------------------------------------------
  1587. typedef struct _CTL_INFO {
  1588. DWORD dwVersion;
  1589. CTL_USAGE SubjectUsage;
  1590. CRYPT_DATA_BLOB ListIdentifier; // OPTIONAL
  1591. CRYPT_INTEGER_BLOB SequenceNumber; // OPTIONAL
  1592. FILETIME ThisUpdate;
  1593. FILETIME NextUpdate; // OPTIONAL
  1594. CRYPT_ALGORITHM_IDENTIFIER SubjectAlgorithm;
  1595. DWORD cCTLEntry;
  1596. PCTL_ENTRY rgCTLEntry; // OPTIONAL
  1597. DWORD cExtension;
  1598. PCERT_EXTENSION rgExtension; // OPTIONAL
  1599. } CTL_INFO, *PCTL_INFO;
  1600. //+-------------------------------------------------------------------------
  1601. // CTL versions
  1602. //--------------------------------------------------------------------------
  1603. #define CTL_V1 0
  1604. //+-------------------------------------------------------------------------
  1605. // TimeStamp Request
  1606. //
  1607. // The pszTimeStamp is the OID for the Time type requested
  1608. // The pszContentType is the Content Type OID for the content, usually DATA
  1609. // The Content is a un-decoded blob
  1610. //--------------------------------------------------------------------------
  1611. typedef struct _CRYPT_TIME_STAMP_REQUEST_INFO {
  1612. LPSTR pszTimeStampAlgorithm; // pszObjId
  1613. LPSTR pszContentType; // pszObjId
  1614. CRYPT_OBJID_BLOB Content;
  1615. DWORD cAttribute;
  1616. PCRYPT_ATTRIBUTE rgAttribute;
  1617. } CRYPT_TIME_STAMP_REQUEST_INFO, *PCRYPT_TIME_STAMP_REQUEST_INFO;
  1618. //+-------------------------------------------------------------------------
  1619. // Name Value Attribute
  1620. //--------------------------------------------------------------------------
  1621. typedef struct _CRYPT_ENROLLMENT_NAME_VALUE_PAIR {
  1622. LPWSTR pwszName;
  1623. LPWSTR pwszValue;
  1624. } CRYPT_ENROLLMENT_NAME_VALUE_PAIR, * PCRYPT_ENROLLMENT_NAME_VALUE_PAIR;
  1625. //+-------------------------------------------------------------------------
  1626. // CSP Provider
  1627. //--------------------------------------------------------------------------
  1628. typedef struct _CRYPT_CSP_PROVIDER {
  1629. DWORD dwKeySpec;
  1630. LPWSTR pwszProviderName;
  1631. CRYPT_BIT_BLOB Signature;
  1632. } CRYPT_CSP_PROVIDER, * PCRYPT_CSP_PROVIDER;
  1633. //+-------------------------------------------------------------------------
  1634. // Certificate and Message encoding types
  1635. //
  1636. // The encoding type is a DWORD containing both the certificate and message
  1637. // encoding types. The certificate encoding type is stored in the LOWORD.
  1638. // The message encoding type is stored in the HIWORD. Some functions or
  1639. // structure fields require only one of the encoding types. The following
  1640. // naming convention is used to indicate which encoding type(s) are
  1641. // required:
  1642. // dwEncodingType (both encoding types are required)
  1643. // dwMsgAndCertEncodingType (both encoding types are required)
  1644. // dwMsgEncodingType (only msg encoding type is required)
  1645. // dwCertEncodingType (only cert encoding type is required)
  1646. //
  1647. // Its always acceptable to specify both.
  1648. //--------------------------------------------------------------------------
  1649. #define CERT_ENCODING_TYPE_MASK 0x0000FFFF
  1650. #define CMSG_ENCODING_TYPE_MASK 0xFFFF0000
  1651. #define GET_CERT_ENCODING_TYPE(X) (X & CERT_ENCODING_TYPE_MASK)
  1652. #define GET_CMSG_ENCODING_TYPE(X) (X & CMSG_ENCODING_TYPE_MASK)
  1653. #define CRYPT_ASN_ENCODING 0x00000001
  1654. #define CRYPT_NDR_ENCODING 0x00000002
  1655. #define X509_ASN_ENCODING 0x00000001
  1656. #define X509_NDR_ENCODING 0x00000002
  1657. #define PKCS_7_ASN_ENCODING 0x00010000
  1658. #define PKCS_7_NDR_ENCODING 0x00020000
  1659. //+-------------------------------------------------------------------------
  1660. // format the specified data structure according to the certificate
  1661. // encoding type.
  1662. //
  1663. // The default behavior of CryptFormatObject is to return single line
  1664. // display of the encoded data, that is, each subfield will be concatenated with
  1665. // a ", " on one line. If user prefers to display the data in multiple line,
  1666. // set the flag CRYPT_FORMAT_STR_MULTI_LINE, that is, each subfield will be displayed
  1667. // on a seperate line.
  1668. //
  1669. // If there is no formatting routine installed or registered
  1670. // for the lpszStructType, the hex dump of the encoded BLOB will be returned.
  1671. // User can set the flag CRYPT_FORMAT_STR_NO_HEX to disable the hex dump.
  1672. //--------------------------------------------------------------------------
  1673. WINCRYPT32API
  1674. BOOL
  1675. WINAPI
  1676. CryptFormatObject(
  1677. IN DWORD dwCertEncodingType,
  1678. IN DWORD dwFormatType,
  1679. IN DWORD dwFormatStrType,
  1680. IN void *pFormatStruct,
  1681. IN LPCSTR lpszStructType,
  1682. IN const BYTE *pbEncoded,
  1683. IN DWORD cbEncoded,
  1684. OUT void *pbFormat,
  1685. IN OUT DWORD *pcbFormat
  1686. );
  1687. //-------------------------------------------------------------------------
  1688. // constants for dwFormatStrType of function CryptFormatObject
  1689. //-------------------------------------------------------------------------
  1690. #define CRYPT_FORMAT_STR_MULTI_LINE 0x0001
  1691. #define CRYPT_FORMAT_STR_NO_HEX 0x0010
  1692. //-------------------------------------------------------------------------
  1693. // constants for dwFormatType of function CryptFormatObject
  1694. // when format X509_NAME or X509_UNICODE_NAME
  1695. //-------------------------------------------------------------------------
  1696. // Just get the simple string
  1697. #define CRYPT_FORMAT_SIMPLE 0x0001
  1698. //Put an attribute name infront of the attribute
  1699. //such as "O=Microsoft,DN=xiaohs"
  1700. #define CRYPT_FORMAT_X509 0x0002
  1701. //Put an OID infront of the simple string, such as
  1702. //"2.5.4.22=Microsoft,2.5.4.3=xiaohs"
  1703. #define CRYPT_FORMAT_OID 0x0004
  1704. //Put a ";" between each RDN. The default is ","
  1705. #define CRYPT_FORMAT_RDN_SEMICOLON 0x0100
  1706. //Put a "\n" between each RDN.
  1707. #define CRYPT_FORMAT_RDN_CRLF 0x0200
  1708. //Unquote the DN value, which is quoated by default va the following
  1709. //rules: if the DN contains leading or trailing
  1710. //white space or one of the following characters: ",", "+", "=",
  1711. //""", "\n", "<", ">", "#" or ";". The quoting character is ".
  1712. //If the DN Value contains a " it is double quoted ("").
  1713. #define CRYPT_FORMAT_RDN_UNQUOTE 0x0400
  1714. //reverse the order of the RDNs before converting to the string
  1715. #define CRYPT_FORMAT_RDN_REVERSE 0x0800
  1716. //-------------------------------------------------------------------------
  1717. // contants dwFormatType of function CryptFormatObject when format a DN.:
  1718. //
  1719. // The following three values are defined in the section above:
  1720. // CRYPT_FORMAT_SIMPLE: Just a simple string
  1721. // such as "Microsoft+xiaohs+NT"
  1722. // CRYPT_FORMAT_X509 Put an attribute name infront of the attribute
  1723. // such as "O=Microsoft+xiaohs+NT"
  1724. //
  1725. // CRYPT_FORMAT_OID Put an OID infront of the simple string,
  1726. // such as "2.5.4.22=Microsoft+xiaohs+NT"
  1727. //
  1728. // Additional values are defined as following:
  1729. //----------------------------------------------------------------------------
  1730. //Put a "," between each value. Default is "+"
  1731. #define CRYPT_FORMAT_COMMA 0x1000
  1732. //Put a ";" between each value
  1733. #define CRYPT_FORMAT_SEMICOLON CRYPT_FORMAT_RDN_SEMICOLON
  1734. //Put a "\n" between each value
  1735. #define CRYPT_FORMAT_CRLF CRYPT_FORMAT_RDN_CRLF
  1736. //+-------------------------------------------------------------------------
  1737. // Encode / decode the specified data structure according to the certificate
  1738. // encoding type.
  1739. //
  1740. // See below for a list of the predefined data structures.
  1741. //--------------------------------------------------------------------------
  1742. typedef LPVOID (WINAPI *PFN_CRYPT_ALLOC)(
  1743. IN size_t cbSize
  1744. );
  1745. typedef VOID (WINAPI *PFN_CRYPT_FREE)(
  1746. IN LPVOID pv
  1747. );
  1748. typedef struct _CRYPT_ENCODE_PARA {
  1749. DWORD cbSize;
  1750. PFN_CRYPT_ALLOC pfnAlloc; // OPTIONAL
  1751. PFN_CRYPT_FREE pfnFree; // OPTIONAL
  1752. } CRYPT_ENCODE_PARA, *PCRYPT_ENCODE_PARA;
  1753. WINCRYPT32API
  1754. BOOL
  1755. WINAPI
  1756. CryptEncodeObjectEx(
  1757. IN DWORD dwCertEncodingType,
  1758. IN LPCSTR lpszStructType,
  1759. IN const void *pvStructInfo,
  1760. IN DWORD dwFlags,
  1761. IN OPTIONAL PCRYPT_ENCODE_PARA pEncodePara,
  1762. OUT void *pvEncoded,
  1763. IN OUT DWORD *pcbEncoded
  1764. );
  1765. WINCRYPT32API
  1766. BOOL
  1767. WINAPI
  1768. CryptEncodeObject(
  1769. IN DWORD dwCertEncodingType,
  1770. IN LPCSTR lpszStructType,
  1771. IN const void *pvStructInfo,
  1772. OUT BYTE *pbEncoded,
  1773. IN OUT DWORD *pcbEncoded
  1774. );
  1775. // By default the signature bytes are reversed. The following flag can
  1776. // be set to inhibit the byte reversal.
  1777. //
  1778. // This flag is applicable to
  1779. // X509_CERT_TO_BE_SIGNED
  1780. #define CRYPT_ENCODE_NO_SIGNATURE_BYTE_REVERSAL_FLAG 0x8
  1781. // When the following flag is set the called encode function allocates
  1782. // memory for the encoded bytes. A pointer to the allocated bytes
  1783. // is returned in pvEncoded. If pEncodePara or pEncodePara->pfnAlloc is
  1784. // NULL, then, LocalAlloc is called for the allocation and LocalFree must
  1785. // be called to do the free. Otherwise, pEncodePara->pfnAlloc is called
  1786. // for the allocation.
  1787. //
  1788. // *pcbEncoded is ignored on input and updated with the length of the
  1789. // allocated, encoded bytes.
  1790. //
  1791. // If pfnAlloc is set, then, pfnFree should also be set.
  1792. #define CRYPT_ENCODE_ALLOC_FLAG 0x8000
  1793. // The following flag is applicable when encoding X509_UNICODE_NAME.
  1794. // When set, CERT_RDN_T61_STRING is selected instead of
  1795. // CERT_RDN_UNICODE_STRING if all the unicode characters are <= 0xFF
  1796. #define CRYPT_UNICODE_NAME_ENCODE_ENABLE_T61_UNICODE_FLAG \
  1797. CERT_RDN_ENABLE_T61_UNICODE_FLAG
  1798. // The following flag is applicable when encoding X509_UNICODE_NAME.
  1799. // When set, CERT_RDN_UTF8_STRING is selected instead of
  1800. // CERT_RDN_UNICODE_STRING.
  1801. #define CRYPT_UNICODE_NAME_ENCODE_ENABLE_UTF8_UNICODE_FLAG \
  1802. CERT_RDN_ENABLE_UTF8_UNICODE_FLAG
  1803. // The following flag is applicable when encoding X509_UNICODE_NAME,
  1804. // X509_UNICODE_NAME_VALUE or X509_UNICODE_ANY_STRING.
  1805. // When set, the characters aren't checked to see if they
  1806. // are valid for the specified Value Type.
  1807. #define CRYPT_UNICODE_NAME_ENCODE_DISABLE_CHECK_TYPE_FLAG \
  1808. CERT_RDN_DISABLE_CHECK_TYPE_FLAG
  1809. // The following flag is applicable when encoding the PKCS_SORTED_CTL. This
  1810. // flag should be set if the identifier for the TrustedSubjects is a hash,
  1811. // such as, MD5 or SHA1.
  1812. #define CRYPT_SORTED_CTL_ENCODE_HASHED_SUBJECT_IDENTIFIER_FLAG 0x10000
  1813. typedef struct _CRYPT_DECODE_PARA {
  1814. DWORD cbSize;
  1815. PFN_CRYPT_ALLOC pfnAlloc; // OPTIONAL
  1816. PFN_CRYPT_FREE pfnFree; // OPTIONAL
  1817. } CRYPT_DECODE_PARA, *PCRYPT_DECODE_PARA;
  1818. WINCRYPT32API
  1819. BOOL
  1820. WINAPI
  1821. CryptDecodeObjectEx(
  1822. IN DWORD dwCertEncodingType,
  1823. IN LPCSTR lpszStructType,
  1824. IN const BYTE *pbEncoded,
  1825. IN DWORD cbEncoded,
  1826. IN DWORD dwFlags,
  1827. IN OPTIONAL PCRYPT_DECODE_PARA pDecodePara,
  1828. OUT OPTIONAL void *pvStructInfo,
  1829. IN OUT DWORD *pcbStructInfo
  1830. );
  1831. WINCRYPT32API
  1832. BOOL
  1833. WINAPI
  1834. CryptDecodeObject(
  1835. IN DWORD dwCertEncodingType,
  1836. IN LPCSTR lpszStructType,
  1837. IN const BYTE *pbEncoded,
  1838. IN DWORD cbEncoded,
  1839. IN DWORD dwFlags,
  1840. OUT void *pvStructInfo,
  1841. IN OUT DWORD *pcbStructInfo
  1842. );
  1843. // When the following flag is set the nocopy optimization is enabled.
  1844. // This optimization where appropriate, updates the pvStructInfo fields
  1845. // to point to content residing within pbEncoded instead of making a copy
  1846. // of and appending to pvStructInfo.
  1847. //
  1848. // Note, when set, pbEncoded can't be freed until pvStructInfo is freed.
  1849. #define CRYPT_DECODE_NOCOPY_FLAG 0x1
  1850. // For CryptDecodeObject(), by default the pbEncoded is the "to be signed"
  1851. // plus its signature. Set the following flag, if pbEncoded points to only
  1852. // the "to be signed".
  1853. //
  1854. // This flag is applicable to
  1855. // X509_CERT_TO_BE_SIGNED
  1856. // X509_CERT_CRL_TO_BE_SIGNED
  1857. // X509_CERT_REQUEST_TO_BE_SIGNED
  1858. // X509_KEYGEN_REQUEST_TO_BE_SIGNED
  1859. #define CRYPT_DECODE_TO_BE_SIGNED_FLAG 0x2
  1860. // When the following flag is set, the OID strings are allocated in
  1861. // crypt32.dll and shared instead of being copied into the returned
  1862. // data structure. This flag may be set if crypt32.dll isn't unloaded
  1863. // before the caller is unloaded.
  1864. #define CRYPT_DECODE_SHARE_OID_STRING_FLAG 0x4
  1865. // By default the signature bytes are reversed. The following flag can
  1866. // be set to inhibit the byte reversal.
  1867. //
  1868. // This flag is applicable to
  1869. // X509_CERT_TO_BE_SIGNED
  1870. #define CRYPT_DECODE_NO_SIGNATURE_BYTE_REVERSAL_FLAG 0x8
  1871. // When the following flag is set the called decode function allocates
  1872. // memory for the decoded structure. A pointer to the allocated structure
  1873. // is returned in pvStructInfo. If pDecodePara or pDecodePara->pfnAlloc is
  1874. // NULL, then, LocalAlloc is called for the allocation and LocalFree must
  1875. // be called to do the free. Otherwise, pDecodePara->pfnAlloc is called
  1876. // for the allocation.
  1877. //
  1878. // *pcbStructInfo is ignored on input and updated with the length of the
  1879. // allocated, decoded structure.
  1880. //
  1881. // This flag may also be set in the CryptDecodeObject API. Since
  1882. // CryptDecodeObject doesn't take a pDecodePara, LocalAlloc is always
  1883. // called for the allocation which must be freed by calling LocalFree.
  1884. #define CRYPT_DECODE_ALLOC_FLAG 0x8000
  1885. // The following flag is applicable when decoding X509_UNICODE_NAME,
  1886. // X509_UNICODE_NAME_VALUE or X509_UNICODE_ANY_STRING.
  1887. // By default, CERT_RDN_T61_STRING values are initially decoded
  1888. // as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  1889. // Setting this flag skips the initial attempt to decode as UTF8.
  1890. #define CRYPT_UNICODE_NAME_DECODE_DISABLE_IE4_UTF8_FLAG \
  1891. CERT_RDN_DISABLE_IE4_UTF8_FLAG
  1892. //+-------------------------------------------------------------------------
  1893. // Predefined X509 certificate data structures that can be encoded / decoded.
  1894. //--------------------------------------------------------------------------
  1895. #define CRYPT_ENCODE_DECODE_NONE 0
  1896. #define X509_CERT ((LPCSTR) 1)
  1897. #define X509_CERT_TO_BE_SIGNED ((LPCSTR) 2)
  1898. #define X509_CERT_CRL_TO_BE_SIGNED ((LPCSTR) 3)
  1899. #define X509_CERT_REQUEST_TO_BE_SIGNED ((LPCSTR) 4)
  1900. #define X509_EXTENSIONS ((LPCSTR) 5)
  1901. #define X509_NAME_VALUE ((LPCSTR) 6)
  1902. #define X509_NAME ((LPCSTR) 7)
  1903. #define X509_PUBLIC_KEY_INFO ((LPCSTR) 8)
  1904. //+-------------------------------------------------------------------------
  1905. // Predefined X509 certificate extension data structures that can be
  1906. // encoded / decoded.
  1907. //--------------------------------------------------------------------------
  1908. #define X509_AUTHORITY_KEY_ID ((LPCSTR) 9)
  1909. #define X509_KEY_ATTRIBUTES ((LPCSTR) 10)
  1910. #define X509_KEY_USAGE_RESTRICTION ((LPCSTR) 11)
  1911. #define X509_ALTERNATE_NAME ((LPCSTR) 12)
  1912. #define X509_BASIC_CONSTRAINTS ((LPCSTR) 13)
  1913. #define X509_KEY_USAGE ((LPCSTR) 14)
  1914. #define X509_BASIC_CONSTRAINTS2 ((LPCSTR) 15)
  1915. #define X509_CERT_POLICIES ((LPCSTR) 16)
  1916. //+-------------------------------------------------------------------------
  1917. // Additional predefined data structures that can be encoded / decoded.
  1918. //--------------------------------------------------------------------------
  1919. #define PKCS_UTC_TIME ((LPCSTR) 17)
  1920. #define PKCS_TIME_REQUEST ((LPCSTR) 18)
  1921. #define RSA_CSP_PUBLICKEYBLOB ((LPCSTR) 19)
  1922. #define X509_UNICODE_NAME ((LPCSTR) 20)
  1923. #define X509_KEYGEN_REQUEST_TO_BE_SIGNED ((LPCSTR) 21)
  1924. #define PKCS_ATTRIBUTE ((LPCSTR) 22)
  1925. #define PKCS_CONTENT_INFO_SEQUENCE_OF_ANY ((LPCSTR) 23)
  1926. //+-------------------------------------------------------------------------
  1927. // Predefined primitive data structures that can be encoded / decoded.
  1928. //--------------------------------------------------------------------------
  1929. #define X509_UNICODE_NAME_VALUE ((LPCSTR) 24)
  1930. #define X509_ANY_STRING X509_NAME_VALUE
  1931. #define X509_UNICODE_ANY_STRING X509_UNICODE_NAME_VALUE
  1932. #define X509_OCTET_STRING ((LPCSTR) 25)
  1933. #define X509_BITS ((LPCSTR) 26)
  1934. #define X509_INTEGER ((LPCSTR) 27)
  1935. #define X509_MULTI_BYTE_INTEGER ((LPCSTR) 28)
  1936. #define X509_ENUMERATED ((LPCSTR) 29)
  1937. #define X509_CHOICE_OF_TIME ((LPCSTR) 30)
  1938. //+-------------------------------------------------------------------------
  1939. // More predefined X509 certificate extension data structures that can be
  1940. // encoded / decoded.
  1941. //--------------------------------------------------------------------------
  1942. #define X509_AUTHORITY_KEY_ID2 ((LPCSTR) 31)
  1943. #define X509_AUTHORITY_INFO_ACCESS ((LPCSTR) 32)
  1944. #define X509_CRL_REASON_CODE X509_ENUMERATED
  1945. #define PKCS_CONTENT_INFO ((LPCSTR) 33)
  1946. #define X509_SEQUENCE_OF_ANY ((LPCSTR) 34)
  1947. #define X509_CRL_DIST_POINTS ((LPCSTR) 35)
  1948. #define X509_ENHANCED_KEY_USAGE ((LPCSTR) 36)
  1949. #define PKCS_CTL ((LPCSTR) 37)
  1950. #define X509_MULTI_BYTE_UINT ((LPCSTR) 38)
  1951. #define X509_DSS_PUBLICKEY X509_MULTI_BYTE_UINT
  1952. #define X509_DSS_PARAMETERS ((LPCSTR) 39)
  1953. #define X509_DSS_SIGNATURE ((LPCSTR) 40)
  1954. #define PKCS_RC2_CBC_PARAMETERS ((LPCSTR) 41)
  1955. #define PKCS_SMIME_CAPABILITIES ((LPCSTR) 42)
  1956. //+-------------------------------------------------------------------------
  1957. // data structures for private keys
  1958. //--------------------------------------------------------------------------
  1959. #define PKCS_RSA_PRIVATE_KEY ((LPCSTR) 43)
  1960. #define PKCS_PRIVATE_KEY_INFO ((LPCSTR) 44)
  1961. #define PKCS_ENCRYPTED_PRIVATE_KEY_INFO ((LPCSTR) 45)
  1962. //+-------------------------------------------------------------------------
  1963. // certificate policy qualifier
  1964. //--------------------------------------------------------------------------
  1965. #define X509_PKIX_POLICY_QUALIFIER_USERNOTICE ((LPCSTR) 46)
  1966. //+-------------------------------------------------------------------------
  1967. // Diffie-Hellman Key Exchange
  1968. //--------------------------------------------------------------------------
  1969. #define X509_DH_PUBLICKEY X509_MULTI_BYTE_UINT
  1970. #define X509_DH_PARAMETERS ((LPCSTR) 47)
  1971. #define PKCS_ATTRIBUTES ((LPCSTR) 48)
  1972. #define PKCS_SORTED_CTL ((LPCSTR) 49)
  1973. //+-------------------------------------------------------------------------
  1974. // X942 Diffie-Hellman
  1975. //--------------------------------------------------------------------------
  1976. #define X942_DH_PARAMETERS ((LPCSTR) 50)
  1977. //+-------------------------------------------------------------------------
  1978. // The following is the same as X509_BITS, except before encoding,
  1979. // the bit length is decremented to exclude trailing zero bits.
  1980. //--------------------------------------------------------------------------
  1981. #define X509_BITS_WITHOUT_TRAILING_ZEROES ((LPCSTR) 51)
  1982. //+-------------------------------------------------------------------------
  1983. // X942 Diffie-Hellman Other Info
  1984. //--------------------------------------------------------------------------
  1985. #define X942_OTHER_INFO ((LPCSTR) 52)
  1986. #define X509_CERT_PAIR ((LPCSTR) 53)
  1987. #define X509_ISSUING_DIST_POINT ((LPCSTR) 54)
  1988. #define X509_NAME_CONSTRAINTS ((LPCSTR) 55)
  1989. #define X509_POLICY_MAPPINGS ((LPCSTR) 56)
  1990. #define X509_POLICY_CONSTRAINTS ((LPCSTR) 57)
  1991. #define X509_CROSS_CERT_DIST_POINTS ((LPCSTR) 58)
  1992. //+-------------------------------------------------------------------------
  1993. // Certificate Management Messages over CMS (CMC) Data Structures
  1994. //--------------------------------------------------------------------------
  1995. #define CMC_DATA ((LPCSTR) 59)
  1996. #define CMC_RESPONSE ((LPCSTR) 60)
  1997. #define CMC_STATUS ((LPCSTR) 61)
  1998. #define CMC_ADD_EXTENSIONS ((LPCSTR) 62)
  1999. #define CMC_ADD_ATTRIBUTES ((LPCSTR) 63)
  2000. //+-------------------------------------------------------------------------
  2001. // Certificate Template
  2002. //--------------------------------------------------------------------------
  2003. #define X509_CERTIFICATE_TEMPLATE ((LPCSTR) 64)
  2004. //+-------------------------------------------------------------------------
  2005. // Predefined PKCS #7 data structures that can be encoded / decoded.
  2006. //--------------------------------------------------------------------------
  2007. #define PKCS7_SIGNER_INFO ((LPCSTR) 500)
  2008. //+-------------------------------------------------------------------------
  2009. // Predefined PKCS #7 data structures that can be encoded / decoded.
  2010. //--------------------------------------------------------------------------
  2011. #define CMS_SIGNER_INFO ((LPCSTR) 501)
  2012. //+-------------------------------------------------------------------------
  2013. // Predefined Software Publishing Credential (SPC) data structures that
  2014. // can be encoded / decoded.
  2015. //
  2016. // Predefined values: 2000 .. 2999
  2017. //
  2018. // See spc.h for value and data structure definitions.
  2019. //--------------------------------------------------------------------------
  2020. //+-------------------------------------------------------------------------
  2021. // Extension Object Identifiers
  2022. //--------------------------------------------------------------------------
  2023. #define szOID_AUTHORITY_KEY_IDENTIFIER "2.5.29.1"
  2024. #define szOID_KEY_ATTRIBUTES "2.5.29.2"
  2025. #define szOID_CERT_POLICIES_95 "2.5.29.3"
  2026. #define szOID_KEY_USAGE_RESTRICTION "2.5.29.4"
  2027. #define szOID_SUBJECT_ALT_NAME "2.5.29.7"
  2028. #define szOID_ISSUER_ALT_NAME "2.5.29.8"
  2029. #define szOID_BASIC_CONSTRAINTS "2.5.29.10"
  2030. #define szOID_KEY_USAGE "2.5.29.15"
  2031. #define szOID_PRIVATEKEY_USAGE_PERIOD "2.5.29.16"
  2032. #define szOID_BASIC_CONSTRAINTS2 "2.5.29.19"
  2033. #define szOID_CERT_POLICIES "2.5.29.32"
  2034. #define szOID_ANY_CERT_POLICY "2.5.29.32.0"
  2035. #define szOID_AUTHORITY_KEY_IDENTIFIER2 "2.5.29.35"
  2036. #define szOID_SUBJECT_KEY_IDENTIFIER "2.5.29.14"
  2037. #define szOID_SUBJECT_ALT_NAME2 "2.5.29.17"
  2038. #define szOID_ISSUER_ALT_NAME2 "2.5.29.18"
  2039. #define szOID_CRL_REASON_CODE "2.5.29.21"
  2040. #define szOID_REASON_CODE_HOLD "2.5.29.23"
  2041. #define szOID_CRL_DIST_POINTS "2.5.29.31"
  2042. #define szOID_ENHANCED_KEY_USAGE "2.5.29.37"
  2043. // szOID_CRL_NUMBER -- Base CRLs only. Monotonically increasing sequence
  2044. // number for each CRL issued by a CA.
  2045. #define szOID_CRL_NUMBER "2.5.29.20"
  2046. // szOID_DELTA_CRL_INDICATOR -- Delta CRLs only. Marked critical.
  2047. // Contains the minimum base CRL Number that can be used with a delta CRL.
  2048. #define szOID_DELTA_CRL_INDICATOR "2.5.29.27"
  2049. #define szOID_ISSUING_DIST_POINT "2.5.29.28"
  2050. // szOID_FRESHEST_CRL -- Base CRLs only. Formatted identically to a CDP
  2051. // extension that holds URLs to fetch the delta CRL.
  2052. #define szOID_FRESHEST_CRL "2.5.29.46"
  2053. #define szOID_NAME_CONSTRAINTS "2.5.29.30"
  2054. // Note on 1/1/2000 szOID_POLICY_MAPPINGS was changed from "2.5.29.5"
  2055. #define szOID_POLICY_MAPPINGS "2.5.29.33"
  2056. #define szOID_LEGACY_POLICY_MAPPINGS "2.5.29.5"
  2057. #define szOID_POLICY_CONSTRAINTS "2.5.29.36"
  2058. // Microsoft PKCS10 Attributes
  2059. #define szOID_RENEWAL_CERTIFICATE "1.3.6.1.4.1.311.13.1"
  2060. #define szOID_ENROLLMENT_NAME_VALUE_PAIR "1.3.6.1.4.1.311.13.2.1"
  2061. #define szOID_ENROLLMENT_CSP_PROVIDER "1.3.6.1.4.1.311.13.2.2"
  2062. #define szOID_OS_VERSION "1.3.6.1.4.1.311.13.2.3"
  2063. //
  2064. // Extension contain certificate type
  2065. #define szOID_ENROLLMENT_AGENT "1.3.6.1.4.1.311.20.2.1"
  2066. // Internet Public Key Infrastructure (PKIX)
  2067. #define szOID_PKIX "1.3.6.1.5.5.7"
  2068. #define szOID_PKIX_PE "1.3.6.1.5.5.7.1"
  2069. #define szOID_AUTHORITY_INFO_ACCESS "1.3.6.1.5.5.7.1.1"
  2070. // Microsoft extensions or attributes
  2071. #define szOID_CERT_EXTENSIONS "1.3.6.1.4.1.311.2.1.14"
  2072. #define szOID_NEXT_UPDATE_LOCATION "1.3.6.1.4.1.311.10.2"
  2073. #define szOID_REMOVE_CERTIFICATE "1.3.6.1.4.1.311.10.8.1"
  2074. #define szOID_CROSS_CERT_DIST_POINTS "1.3.6.1.4.1.311.10.9.1"
  2075. // Microsoft PKCS #7 ContentType Object Identifiers
  2076. #define szOID_CTL "1.3.6.1.4.1.311.10.1"
  2077. // Microsoft Sorted CTL Extension Object Identifier
  2078. #define szOID_SORTED_CTL "1.3.6.1.4.1.311.10.1.1"
  2079. // serialized serial numbers for PRS
  2080. #ifndef szOID_SERIALIZED
  2081. #define szOID_SERIALIZED "1.3.6.1.4.1.311.10.3.3.1"
  2082. #endif
  2083. // UPN principal name in SubjectAltName
  2084. #ifndef szOID_NT_PRINCIPAL_NAME
  2085. #define szOID_NT_PRINCIPAL_NAME "1.3.6.1.4.1.311.20.2.3"
  2086. #endif
  2087. // Windows product update unauthenticated attribute
  2088. #ifndef szOID_PRODUCT_UPDATE
  2089. #define szOID_PRODUCT_UPDATE "1.3.6.1.4.1.311.31.1"
  2090. #endif
  2091. // CryptUI
  2092. #define szOID_ANY_APPLICATION_POLICY "1.3.6.1.4.1.311.10.12.1"
  2093. //+-------------------------------------------------------------------------
  2094. // Object Identifiers for use with Auto Enrollment
  2095. //--------------------------------------------------------------------------
  2096. #define szOID_AUTO_ENROLL_CTL_USAGE "1.3.6.1.4.1.311.20.1"
  2097. // Extension contain certificate type
  2098. #define szOID_ENROLL_CERTTYPE_EXTENSION "1.3.6.1.4.1.311.20.2"
  2099. #define szOID_CERT_MANIFOLD "1.3.6.1.4.1.311.20.3"
  2100. //+-------------------------------------------------------------------------
  2101. // Object Identifiers for use with the MS Certificate Server
  2102. //--------------------------------------------------------------------------
  2103. #ifndef szOID_CERTSRV_CA_VERSION
  2104. #define szOID_CERTSRV_CA_VERSION "1.3.6.1.4.1.311.21.1"
  2105. #endif
  2106. // szOID_CERTSRV_PREVIOUS_CERT_HASH -- Contains the sha1 hash of the previous
  2107. // version of the CA certificate.
  2108. #define szOID_CERTSRV_PREVIOUS_CERT_HASH "1.3.6.1.4.1.311.21.2"
  2109. // szOID_CRL_VIRTUAL_BASE -- Delta CRLs only. Contains the base CRL Number
  2110. // of the corresponding base CRL.
  2111. #define szOID_CRL_VIRTUAL_BASE "1.3.6.1.4.1.311.21.3"
  2112. // szOID_CRL_NEXT_PUBLISH -- Contains the time when the next CRL is expected
  2113. // to be published. This may be sooner than the CRL's NextUpdate field.
  2114. #define szOID_CRL_NEXT_PUBLISH "1.3.6.1.4.1.311.21.4"
  2115. // Enhanced Key Usage for CA encryption certificate
  2116. #define szOID_KP_CA_EXCHANGE "1.3.6.1.4.1.311.21.5"
  2117. // Enhanced Key Usage for key recovery agent certificate
  2118. #define szOID_KP_KEY_RECOVERY_AGENT "1.3.6.1.4.1.311.21.6"
  2119. // Certificate template extension (v2)
  2120. #define szOID_CERTIFICATE_TEMPLATE "1.3.6.1.4.1.311.21.7"
  2121. // The root oid for all enterprise specific oids
  2122. #define szOID_ENTERPRISE_OID_ROOT "1.3.6.1.4.1.311.21.8"
  2123. // Dummy signing Subject RDN
  2124. #define szOID_RDN_DUMMY_SIGNER "1.3.6.1.4.1.311.21.9"
  2125. // Application Policies extension -- same encoding as szOID_CERT_POLICIES
  2126. #define szOID_APPLICATION_CERT_POLICIES "1.3.6.1.4.1.311.21.10"
  2127. // Application Policy Mappings -- same encoding as szOID_POLICY_MAPPINGS
  2128. #define szOID_APPLICATION_POLICY_MAPPINGS "1.3.6.1.4.1.311.21.11"
  2129. // Application Policy Constraints -- same encoding as szOID_POLICY_CONSTRAINTS
  2130. #define szOID_APPLICATION_POLICY_CONSTRAINTS "1.3.6.1.4.1.311.21.12"
  2131. #define szOID_ARCHIVED_KEY_ATTR "1.3.6.1.4.1.311.21.13"
  2132. #define szOID_CRL_SELF_CDP "1.3.6.1.4.1.311.21.14"
  2133. // Requires all certificates below the root to have a non-empty intersecting
  2134. // issuance certificate policy usage.
  2135. #define szOID_REQUIRE_CERT_CHAIN_POLICY "1.3.6.1.4.1.311.21.15"
  2136. #define szOID_ARCHIVED_KEY_CERT_HASH "1.3.6.1.4.1.311.21.16"
  2137. #define szOID_ISSUED_CERT_HASH "1.3.6.1.4.1.311.21.17"
  2138. // Enhanced key usage for DS email replication
  2139. #define szOID_DS_EMAIL_REPLICATION "1.3.6.1.4.1.311.21.19"
  2140. #define szOID_REQUEST_CLIENT_INFO "1.3.6.1.4.1.311.21.20"
  2141. #define szOID_ENCRYPTED_KEY_HASH "1.3.6.1.4.1.311.21.21"
  2142. #define szOID_CERTSRV_CROSSCA_VERSION "1.3.6.1.4.1.311.21.22"
  2143. //+-------------------------------------------------------------------------
  2144. // Object Identifiers for use with the MS Directory Service
  2145. //--------------------------------------------------------------------------
  2146. #define szOID_NTDS_REPLICATION "1.3.6.1.4.1.311.25.1"
  2147. //+-------------------------------------------------------------------------
  2148. // Extension Object Identifiers (currently not implemented)
  2149. //--------------------------------------------------------------------------
  2150. #define szOID_SUBJECT_DIR_ATTRS "2.5.29.9"
  2151. //+-------------------------------------------------------------------------
  2152. // Enhanced Key Usage (Purpose) Object Identifiers
  2153. //--------------------------------------------------------------------------
  2154. #define szOID_PKIX_KP "1.3.6.1.5.5.7.3"
  2155. // Consistent key usage bits: DIGITAL_SIGNATURE, KEY_ENCIPHERMENT
  2156. // or KEY_AGREEMENT
  2157. #define szOID_PKIX_KP_SERVER_AUTH "1.3.6.1.5.5.7.3.1"
  2158. // Consistent key usage bits: DIGITAL_SIGNATURE
  2159. #define szOID_PKIX_KP_CLIENT_AUTH "1.3.6.1.5.5.7.3.2"
  2160. // Consistent key usage bits: DIGITAL_SIGNATURE
  2161. #define szOID_PKIX_KP_CODE_SIGNING "1.3.6.1.5.5.7.3.3"
  2162. // Consistent key usage bits: DIGITAL_SIGNATURE, NON_REPUDIATION and/or
  2163. // (KEY_ENCIPHERMENT or KEY_AGREEMENT)
  2164. #define szOID_PKIX_KP_EMAIL_PROTECTION "1.3.6.1.5.5.7.3.4"
  2165. // Consistent key usage bits: DIGITAL_SIGNATURE and/or
  2166. // (KEY_ENCIPHERMENT or KEY_AGREEMENT)
  2167. #define szOID_PKIX_KP_IPSEC_END_SYSTEM "1.3.6.1.5.5.7.3.5"
  2168. // Consistent key usage bits: DIGITAL_SIGNATURE and/or
  2169. // (KEY_ENCIPHERMENT or KEY_AGREEMENT)
  2170. #define szOID_PKIX_KP_IPSEC_TUNNEL "1.3.6.1.5.5.7.3.6"
  2171. // Consistent key usage bits: DIGITAL_SIGNATURE and/or
  2172. // (KEY_ENCIPHERMENT or KEY_AGREEMENT)
  2173. #define szOID_PKIX_KP_IPSEC_USER "1.3.6.1.5.5.7.3.7"
  2174. // Consistent key usage bits: DIGITAL_SIGNATURE or NON_REPUDIATION
  2175. #define szOID_PKIX_KP_TIMESTAMP_SIGNING "1.3.6.1.5.5.7.3.8"
  2176. // IKE (Internet Key Exchange) Intermediate KP for an IPsec end entity.
  2177. // Defined in draft-ietf-ipsec-pki-req-04.txt, December 14, 1999.
  2178. #define szOID_IPSEC_KP_IKE_INTERMEDIATE "1.3.6.1.5.5.8.2.2"
  2179. //+-------------------------------------------------------------------------
  2180. // Microsoft Enhanced Key Usage (Purpose) Object Identifiers
  2181. //+-------------------------------------------------------------------------
  2182. // Signer of CTLs
  2183. #define szOID_KP_CTL_USAGE_SIGNING "1.3.6.1.4.1.311.10.3.1"
  2184. // Signer of TimeStamps
  2185. #define szOID_KP_TIME_STAMP_SIGNING "1.3.6.1.4.1.311.10.3.2"
  2186. #ifndef szOID_SERVER_GATED_CRYPTO
  2187. #define szOID_SERVER_GATED_CRYPTO "1.3.6.1.4.1.311.10.3.3"
  2188. #endif
  2189. #ifndef szOID_SGC_NETSCAPE
  2190. #define szOID_SGC_NETSCAPE "2.16.840.1.113730.4.1"
  2191. #endif
  2192. #define szOID_KP_EFS "1.3.6.1.4.1.311.10.3.4"
  2193. #define szOID_EFS_RECOVERY "1.3.6.1.4.1.311.10.3.4.1"
  2194. // Can use Windows Hardware Compatible (WHQL)
  2195. #define szOID_WHQL_CRYPTO "1.3.6.1.4.1.311.10.3.5"
  2196. // Signed by the NT5 build lab
  2197. #define szOID_NT5_CRYPTO "1.3.6.1.4.1.311.10.3.6"
  2198. // Signed by and OEM of WHQL
  2199. #define szOID_OEM_WHQL_CRYPTO "1.3.6.1.4.1.311.10.3.7"
  2200. // Signed by the Embedded NT
  2201. #define szOID_EMBEDDED_NT_CRYPTO "1.3.6.1.4.1.311.10.3.8"
  2202. // Signer of a CTL containing trusted roots
  2203. #define szOID_ROOT_LIST_SIGNER "1.3.6.1.4.1.311.10.3.9"
  2204. // Can sign cross-cert and subordinate CA requests with qualified
  2205. // subordination (name constraints, policy mapping, etc.)
  2206. #define szOID_KP_QUALIFIED_SUBORDINATION "1.3.6.1.4.1.311.10.3.10"
  2207. // Can be used to encrypt/recover escrowed keys
  2208. #define szOID_KP_KEY_RECOVERY "1.3.6.1.4.1.311.10.3.11"
  2209. // Signer of documents
  2210. #define szOID_KP_DOCUMENT_SIGNING "1.3.6.1.4.1.311.10.3.12"
  2211. // The default WinVerifyTrust Authenticode policy is to treat all time stamped
  2212. // signatures as being valid forever. This OID limits the valid lifetime of the
  2213. // signature to the lifetime of the certificate. This allows timestamped
  2214. // signatures to expire. Normally this OID will be used in conjunction with
  2215. // szOID_PKIX_KP_CODE_SIGNING to indicate new time stamp semantics should be
  2216. // used. Support for this OID was added in WXP.
  2217. #define szOID_KP_LIFETIME_SIGNING "1.3.6.1.4.1.311.10.3.13"
  2218. #define szOID_KP_MOBILE_DEVICE_SOFTWARE "1.3.6.1.4.1.311.10.3.14"
  2219. #ifndef szOID_DRM
  2220. #define szOID_DRM "1.3.6.1.4.1.311.10.5.1"
  2221. #endif
  2222. // Microsoft DRM EKU
  2223. #ifndef szOID_DRM_INDIVIDUALIZATION
  2224. #define szOID_DRM_INDIVIDUALIZATION "1.3.6.1.4.1.311.10.5.2"
  2225. #endif
  2226. #ifndef szOID_LICENSES
  2227. #define szOID_LICENSES "1.3.6.1.4.1.311.10.6.1"
  2228. #endif
  2229. #ifndef szOID_LICENSE_SERVER
  2230. #define szOID_LICENSE_SERVER "1.3.6.1.4.1.311.10.6.2"
  2231. #endif
  2232. #ifndef szOID_KP_SMARTCARD_LOGON
  2233. #define szOID_KP_SMARTCARD_LOGON "1.3.6.1.4.1.311.20.2.2"
  2234. #endif
  2235. //+-------------------------------------------------------------------------
  2236. // Microsoft Attribute Object Identifiers
  2237. //+-------------------------------------------------------------------------
  2238. #define szOID_YESNO_TRUST_ATTR "1.3.6.1.4.1.311.10.4.1"
  2239. //+-------------------------------------------------------------------------
  2240. // Qualifiers that may be part of the szOID_CERT_POLICIES and
  2241. // szOID_CERT_POLICIES95 extensions
  2242. //+-------------------------------------------------------------------------
  2243. #define szOID_PKIX_POLICY_QUALIFIER_CPS "1.3.6.1.5.5.7.2.1"
  2244. #define szOID_PKIX_POLICY_QUALIFIER_USERNOTICE "1.3.6.1.5.5.7.2.2"
  2245. // OID for old qualifer
  2246. #define szOID_CERT_POLICIES_95_QUALIFIER1 "2.16.840.1.113733.1.7.1.1"
  2247. //+-------------------------------------------------------------------------
  2248. // X509_CERT
  2249. //
  2250. // The "to be signed" encoded content plus its signature. The ToBeSigned
  2251. // content is the CryptEncodeObject() output for one of the following:
  2252. // X509_CERT_TO_BE_SIGNED, X509_CERT_CRL_TO_BE_SIGNED or
  2253. // X509_CERT_REQUEST_TO_BE_SIGNED.
  2254. //
  2255. // pvStructInfo points to CERT_SIGNED_CONTENT_INFO.
  2256. //--------------------------------------------------------------------------
  2257. //+-------------------------------------------------------------------------
  2258. // X509_CERT_TO_BE_SIGNED
  2259. //
  2260. // pvStructInfo points to CERT_INFO.
  2261. //
  2262. // For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  2263. // signature (output of a X509_CERT CryptEncodeObject()).
  2264. //
  2265. // For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  2266. //--------------------------------------------------------------------------
  2267. //+-------------------------------------------------------------------------
  2268. // X509_CERT_CRL_TO_BE_SIGNED
  2269. //
  2270. // pvStructInfo points to CRL_INFO.
  2271. //
  2272. // For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  2273. // signature (output of a X509_CERT CryptEncodeObject()).
  2274. //
  2275. // For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  2276. //--------------------------------------------------------------------------
  2277. //+-------------------------------------------------------------------------
  2278. // X509_CERT_REQUEST_TO_BE_SIGNED
  2279. //
  2280. // pvStructInfo points to CERT_REQUEST_INFO.
  2281. //
  2282. // For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  2283. // signature (output of a X509_CERT CryptEncodeObject()).
  2284. //
  2285. // For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  2286. //--------------------------------------------------------------------------
  2287. //+-------------------------------------------------------------------------
  2288. // X509_EXTENSIONS
  2289. // szOID_CERT_EXTENSIONS
  2290. //
  2291. // pvStructInfo points to following CERT_EXTENSIONS.
  2292. //--------------------------------------------------------------------------
  2293. typedef struct _CERT_EXTENSIONS {
  2294. DWORD cExtension;
  2295. PCERT_EXTENSION rgExtension;
  2296. } CERT_EXTENSIONS, *PCERT_EXTENSIONS;
  2297. //+-------------------------------------------------------------------------
  2298. // X509_NAME_VALUE
  2299. // X509_ANY_STRING
  2300. //
  2301. // pvStructInfo points to CERT_NAME_VALUE.
  2302. //--------------------------------------------------------------------------
  2303. //+-------------------------------------------------------------------------
  2304. // X509_UNICODE_NAME_VALUE
  2305. // X509_UNICODE_ANY_STRING
  2306. //
  2307. // pvStructInfo points to CERT_NAME_VALUE.
  2308. //
  2309. // The name values are unicode strings.
  2310. //
  2311. // For CryptEncodeObject:
  2312. // Value.pbData points to the unicode string.
  2313. // If Value.cbData = 0, then, the unicode string is NULL terminated.
  2314. // Otherwise, Value.cbData is the unicode string byte count. The byte count
  2315. // is twice the character count.
  2316. //
  2317. // If the unicode string contains an invalid character for the specified
  2318. // dwValueType, then, *pcbEncoded is updated with the unicode character
  2319. // index of the first invalid character. LastError is set to:
  2320. // CRYPT_E_INVALID_NUMERIC_STRING, CRYPT_E_INVALID_PRINTABLE_STRING or
  2321. // CRYPT_E_INVALID_IA5_STRING.
  2322. //
  2323. // To disable the above check, either set CERT_RDN_DISABLE_CHECK_TYPE_FLAG
  2324. // in dwValueType or set CRYPT_UNICODE_NAME_ENCODE_DISABLE_CHECK_TYPE_FLAG
  2325. // in dwFlags passed to CryptEncodeObjectEx.
  2326. //
  2327. // The unicode string is converted before being encoded according to
  2328. // the specified dwValueType. If dwValueType is set to 0, LastError
  2329. // is set to E_INVALIDARG.
  2330. //
  2331. // If the dwValueType isn't one of the character strings (its a
  2332. // CERT_RDN_ENCODED_BLOB or CERT_RDN_OCTET_STRING), then, CryptEncodeObject
  2333. // will return FALSE with LastError set to CRYPT_E_NOT_CHAR_STRING.
  2334. //
  2335. // For CryptDecodeObject:
  2336. // Value.pbData points to a NULL terminated unicode string. Value.cbData
  2337. // contains the byte count of the unicode string excluding the NULL
  2338. // terminator. dwValueType contains the type used in the encoded object.
  2339. // Its not forced to CERT_RDN_UNICODE_STRING. The encoded value is
  2340. // converted to the unicode string according to the dwValueType.
  2341. //
  2342. // If the encoded object isn't one of the character string types, then,
  2343. // CryptDecodeObject will return FALSE with LastError set to
  2344. // CRYPT_E_NOT_CHAR_STRING. For a non character string, decode using
  2345. // X509_NAME_VALUE or X509_ANY_STRING.
  2346. //
  2347. // By default, CERT_RDN_T61_STRING values are initially decoded
  2348. // as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  2349. // Set CRYPT_UNICODE_NAME_DECODE_DISABLE_IE4_UTF8_FLAG in dwFlags
  2350. // passed to either CryptDecodeObject or CryptDecodeObjectEx to
  2351. // skip the initial attempt to decode as UTF8.
  2352. //--------------------------------------------------------------------------
  2353. //+-------------------------------------------------------------------------
  2354. // X509_NAME
  2355. //
  2356. // pvStructInfo points to CERT_NAME_INFO.
  2357. //--------------------------------------------------------------------------
  2358. //+-------------------------------------------------------------------------
  2359. // X509_UNICODE_NAME
  2360. //
  2361. // pvStructInfo points to CERT_NAME_INFO.
  2362. //
  2363. // The RDN attribute values are unicode strings except for the dwValueTypes of
  2364. // CERT_RDN_ENCODED_BLOB or CERT_RDN_OCTET_STRING. These dwValueTypes are
  2365. // the same as for a X509_NAME. Their values aren't converted to/from unicode.
  2366. //
  2367. // For CryptEncodeObject:
  2368. // Value.pbData points to the unicode string.
  2369. // If Value.cbData = 0, then, the unicode string is NULL terminated.
  2370. // Otherwise, Value.cbData is the unicode string byte count. The byte count
  2371. // is twice the character count.
  2372. //
  2373. // If dwValueType = 0 (CERT_RDN_ANY_TYPE), the pszObjId is used to find
  2374. // an acceptable dwValueType. If the unicode string contains an
  2375. // invalid character for the found or specified dwValueType, then,
  2376. // *pcbEncoded is updated with the error location of the invalid character.
  2377. // See below for details. LastError is set to:
  2378. // CRYPT_E_INVALID_NUMERIC_STRING, CRYPT_E_INVALID_PRINTABLE_STRING or
  2379. // CRYPT_E_INVALID_IA5_STRING.
  2380. //
  2381. // To disable the above check, either set CERT_RDN_DISABLE_CHECK_TYPE_FLAG
  2382. // in dwValueType or set CRYPT_UNICODE_NAME_ENCODE_DISABLE_CHECK_TYPE_FLAG
  2383. // in dwFlags passed to CryptEncodeObjectEx.
  2384. //
  2385. // Set CERT_RDN_UNICODE_STRING in dwValueType or set
  2386. // CRYPT_UNICODE_NAME_ENCODE_ENABLE_T61_UNICODE_FLAG in dwFlags passed
  2387. // to CryptEncodeObjectEx to select CERT_RDN_T61_STRING instead of
  2388. // CERT_RDN_UNICODE_STRING if all the unicode characters are <= 0xFF.
  2389. //
  2390. // Set CERT_RDN_ENABLE_UTF8_UNICODE_STRING in dwValueType or set
  2391. // CRYPT_UNICODE_NAME_ENCODE_ENABLE_UTF8_UNICODE_FLAG in dwFlags passed
  2392. // to CryptEncodeObjectEx to select CERT_RDN_UTF8_STRING instead of
  2393. // CERT_RDN_UNICODE_STRING.
  2394. //
  2395. // The unicode string is converted before being encoded according to
  2396. // the specified or ObjId matching dwValueType.
  2397. //
  2398. // For CryptDecodeObject:
  2399. // Value.pbData points to a NULL terminated unicode string. Value.cbData
  2400. // contains the byte count of the unicode string excluding the NULL
  2401. // terminator. dwValueType contains the type used in the encoded object.
  2402. // Its not forced to CERT_RDN_UNICODE_STRING. The encoded value is
  2403. // converted to the unicode string according to the dwValueType.
  2404. //
  2405. // If the dwValueType of the encoded value isn't a character string
  2406. // type, then, it isn't converted to UNICODE. Use the
  2407. // IS_CERT_RDN_CHAR_STRING() macro on the dwValueType to check
  2408. // that Value.pbData points to a converted unicode string.
  2409. //
  2410. // By default, CERT_RDN_T61_STRING values are initially decoded
  2411. // as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  2412. // Set CRYPT_UNICODE_NAME_DECODE_DISABLE_IE4_UTF8_FLAG in dwFlags
  2413. // passed to either CryptDecodeObject or CryptDecodeObjectEx to
  2414. // skip the initial attempt to decode as UTF8.
  2415. //--------------------------------------------------------------------------
  2416. //+-------------------------------------------------------------------------
  2417. // Unicode Name Value Error Location Definitions
  2418. //
  2419. // Error location is returned in *pcbEncoded by
  2420. // CryptEncodeObject(X509_UNICODE_NAME)
  2421. //
  2422. // Error location consists of:
  2423. // RDN_INDEX - 10 bits << 22
  2424. // ATTR_INDEX - 6 bits << 16
  2425. // VALUE_INDEX - 16 bits (unicode character index)
  2426. //--------------------------------------------------------------------------
  2427. #define CERT_UNICODE_RDN_ERR_INDEX_MASK 0x3FF
  2428. #define CERT_UNICODE_RDN_ERR_INDEX_SHIFT 22
  2429. #define CERT_UNICODE_ATTR_ERR_INDEX_MASK 0x003F
  2430. #define CERT_UNICODE_ATTR_ERR_INDEX_SHIFT 16
  2431. #define CERT_UNICODE_VALUE_ERR_INDEX_MASK 0x0000FFFF
  2432. #define CERT_UNICODE_VALUE_ERR_INDEX_SHIFT 0
  2433. #define GET_CERT_UNICODE_RDN_ERR_INDEX(X) \
  2434. ((X >> CERT_UNICODE_RDN_ERR_INDEX_SHIFT) & CERT_UNICODE_RDN_ERR_INDEX_MASK)
  2435. #define GET_CERT_UNICODE_ATTR_ERR_INDEX(X) \
  2436. ((X >> CERT_UNICODE_ATTR_ERR_INDEX_SHIFT) & CERT_UNICODE_ATTR_ERR_INDEX_MASK)
  2437. #define GET_CERT_UNICODE_VALUE_ERR_INDEX(X) \
  2438. (X & CERT_UNICODE_VALUE_ERR_INDEX_MASK)
  2439. //+-------------------------------------------------------------------------
  2440. // X509_PUBLIC_KEY_INFO
  2441. //
  2442. // pvStructInfo points to CERT_PUBLIC_KEY_INFO.
  2443. //--------------------------------------------------------------------------
  2444. //+-------------------------------------------------------------------------
  2445. // X509_AUTHORITY_KEY_ID
  2446. // szOID_AUTHORITY_KEY_IDENTIFIER
  2447. //
  2448. // pvStructInfo points to following CERT_AUTHORITY_KEY_ID_INFO.
  2449. //--------------------------------------------------------------------------
  2450. typedef struct _CERT_AUTHORITY_KEY_ID_INFO {
  2451. CRYPT_DATA_BLOB KeyId;
  2452. CERT_NAME_BLOB CertIssuer;
  2453. CRYPT_INTEGER_BLOB CertSerialNumber;
  2454. } CERT_AUTHORITY_KEY_ID_INFO, *PCERT_AUTHORITY_KEY_ID_INFO;
  2455. //+-------------------------------------------------------------------------
  2456. // X509_KEY_ATTRIBUTES
  2457. // szOID_KEY_ATTRIBUTES
  2458. //
  2459. // pvStructInfo points to following CERT_KEY_ATTRIBUTES_INFO.
  2460. //--------------------------------------------------------------------------
  2461. typedef struct _CERT_PRIVATE_KEY_VALIDITY {
  2462. FILETIME NotBefore;
  2463. FILETIME NotAfter;
  2464. } CERT_PRIVATE_KEY_VALIDITY, *PCERT_PRIVATE_KEY_VALIDITY;
  2465. typedef struct _CERT_KEY_ATTRIBUTES_INFO {
  2466. CRYPT_DATA_BLOB KeyId;
  2467. CRYPT_BIT_BLOB IntendedKeyUsage;
  2468. PCERT_PRIVATE_KEY_VALIDITY pPrivateKeyUsagePeriod; // OPTIONAL
  2469. } CERT_KEY_ATTRIBUTES_INFO, *PCERT_KEY_ATTRIBUTES_INFO;
  2470. // Byte[0]
  2471. #define CERT_DIGITAL_SIGNATURE_KEY_USAGE 0x80
  2472. #define CERT_NON_REPUDIATION_KEY_USAGE 0x40
  2473. #define CERT_KEY_ENCIPHERMENT_KEY_USAGE 0x20
  2474. #define CERT_DATA_ENCIPHERMENT_KEY_USAGE 0x10
  2475. #define CERT_KEY_AGREEMENT_KEY_USAGE 0x08
  2476. #define CERT_KEY_CERT_SIGN_KEY_USAGE 0x04
  2477. #define CERT_OFFLINE_CRL_SIGN_KEY_USAGE 0x02
  2478. #define CERT_CRL_SIGN_KEY_USAGE 0x02
  2479. #define CERT_ENCIPHER_ONLY_KEY_USAGE 0x01
  2480. // Byte[1]
  2481. #define CERT_DECIPHER_ONLY_KEY_USAGE 0x80
  2482. //+-------------------------------------------------------------------------
  2483. // X509_KEY_USAGE_RESTRICTION
  2484. // szOID_KEY_USAGE_RESTRICTION
  2485. //
  2486. // pvStructInfo points to following CERT_KEY_USAGE_RESTRICTION_INFO.
  2487. //--------------------------------------------------------------------------
  2488. typedef struct _CERT_POLICY_ID {
  2489. DWORD cCertPolicyElementId;
  2490. LPSTR *rgpszCertPolicyElementId; // pszObjId
  2491. } CERT_POLICY_ID, *PCERT_POLICY_ID;
  2492. typedef struct _CERT_KEY_USAGE_RESTRICTION_INFO {
  2493. DWORD cCertPolicyId;
  2494. PCERT_POLICY_ID rgCertPolicyId;
  2495. CRYPT_BIT_BLOB RestrictedKeyUsage;
  2496. } CERT_KEY_USAGE_RESTRICTION_INFO, *PCERT_KEY_USAGE_RESTRICTION_INFO;
  2497. // See CERT_KEY_ATTRIBUTES_INFO for definition of the RestrictedKeyUsage bits
  2498. //+-------------------------------------------------------------------------
  2499. // X509_ALTERNATE_NAME
  2500. // szOID_SUBJECT_ALT_NAME
  2501. // szOID_ISSUER_ALT_NAME
  2502. // szOID_SUBJECT_ALT_NAME2
  2503. // szOID_ISSUER_ALT_NAME2
  2504. //
  2505. // pvStructInfo points to following CERT_ALT_NAME_INFO.
  2506. //--------------------------------------------------------------------------
  2507. typedef struct _CERT_OTHER_NAME {
  2508. LPSTR pszObjId;
  2509. CRYPT_OBJID_BLOB Value;
  2510. } CERT_OTHER_NAME, *PCERT_OTHER_NAME;
  2511. typedef struct _CERT_ALT_NAME_ENTRY {
  2512. DWORD dwAltNameChoice;
  2513. union {
  2514. PCERT_OTHER_NAME pOtherName; // 1
  2515. LPWSTR pwszRfc822Name; // 2 (encoded IA5)
  2516. LPWSTR pwszDNSName; // 3 (encoded IA5)
  2517. // Not implemented x400Address; // 4
  2518. CERT_NAME_BLOB DirectoryName; // 5
  2519. // Not implemented pEdiPartyName; // 6
  2520. LPWSTR pwszURL; // 7 (encoded IA5)
  2521. CRYPT_DATA_BLOB IPAddress; // 8 (Octet String)
  2522. LPSTR pszRegisteredID; // 9 (Object Identifer)
  2523. };
  2524. } CERT_ALT_NAME_ENTRY, *PCERT_ALT_NAME_ENTRY;
  2525. #define CERT_ALT_NAME_OTHER_NAME 1
  2526. #define CERT_ALT_NAME_RFC822_NAME 2
  2527. #define CERT_ALT_NAME_DNS_NAME 3
  2528. #define CERT_ALT_NAME_X400_ADDRESS 4
  2529. #define CERT_ALT_NAME_DIRECTORY_NAME 5
  2530. #define CERT_ALT_NAME_EDI_PARTY_NAME 6
  2531. #define CERT_ALT_NAME_URL 7
  2532. #define CERT_ALT_NAME_IP_ADDRESS 8
  2533. #define CERT_ALT_NAME_REGISTERED_ID 9
  2534. typedef struct _CERT_ALT_NAME_INFO {
  2535. DWORD cAltEntry;
  2536. PCERT_ALT_NAME_ENTRY rgAltEntry;
  2537. } CERT_ALT_NAME_INFO, *PCERT_ALT_NAME_INFO;
  2538. //+-------------------------------------------------------------------------
  2539. // Alternate name IA5 Error Location Definitions for
  2540. // CRYPT_E_INVALID_IA5_STRING.
  2541. //
  2542. // Error location is returned in *pcbEncoded by
  2543. // CryptEncodeObject(X509_ALTERNATE_NAME)
  2544. //
  2545. // Error location consists of:
  2546. // ENTRY_INDEX - 8 bits << 16
  2547. // VALUE_INDEX - 16 bits (unicode character index)
  2548. //--------------------------------------------------------------------------
  2549. #define CERT_ALT_NAME_ENTRY_ERR_INDEX_MASK 0xFF
  2550. #define CERT_ALT_NAME_ENTRY_ERR_INDEX_SHIFT 16
  2551. #define CERT_ALT_NAME_VALUE_ERR_INDEX_MASK 0x0000FFFF
  2552. #define CERT_ALT_NAME_VALUE_ERR_INDEX_SHIFT 0
  2553. #define GET_CERT_ALT_NAME_ENTRY_ERR_INDEX(X) \
  2554. ((X >> CERT_ALT_NAME_ENTRY_ERR_INDEX_SHIFT) & \
  2555. CERT_ALT_NAME_ENTRY_ERR_INDEX_MASK)
  2556. #define GET_CERT_ALT_NAME_VALUE_ERR_INDEX(X) \
  2557. (X & CERT_ALT_NAME_VALUE_ERR_INDEX_MASK)
  2558. //+-------------------------------------------------------------------------
  2559. // X509_BASIC_CONSTRAINTS
  2560. // szOID_BASIC_CONSTRAINTS
  2561. //
  2562. // pvStructInfo points to following CERT_BASIC_CONSTRAINTS_INFO.
  2563. //--------------------------------------------------------------------------
  2564. typedef struct _CERT_BASIC_CONSTRAINTS_INFO {
  2565. CRYPT_BIT_BLOB SubjectType;
  2566. BOOL fPathLenConstraint;
  2567. DWORD dwPathLenConstraint;
  2568. DWORD cSubtreesConstraint;
  2569. CERT_NAME_BLOB *rgSubtreesConstraint;
  2570. } CERT_BASIC_CONSTRAINTS_INFO, *PCERT_BASIC_CONSTRAINTS_INFO;
  2571. #define CERT_CA_SUBJECT_FLAG 0x80
  2572. #define CERT_END_ENTITY_SUBJECT_FLAG 0x40
  2573. //+-------------------------------------------------------------------------
  2574. // X509_BASIC_CONSTRAINTS2
  2575. // szOID_BASIC_CONSTRAINTS2
  2576. //
  2577. // pvStructInfo points to following CERT_BASIC_CONSTRAINTS2_INFO.
  2578. //--------------------------------------------------------------------------
  2579. typedef struct _CERT_BASIC_CONSTRAINTS2_INFO {
  2580. BOOL fCA;
  2581. BOOL fPathLenConstraint;
  2582. DWORD dwPathLenConstraint;
  2583. } CERT_BASIC_CONSTRAINTS2_INFO, *PCERT_BASIC_CONSTRAINTS2_INFO;
  2584. //+-------------------------------------------------------------------------
  2585. // X509_KEY_USAGE
  2586. // szOID_KEY_USAGE
  2587. //
  2588. // pvStructInfo points to a CRYPT_BIT_BLOB. Has same bit definitions as
  2589. // CERT_KEY_ATTRIBUTES_INFO's IntendedKeyUsage.
  2590. //--------------------------------------------------------------------------
  2591. //+-------------------------------------------------------------------------
  2592. // X509_CERT_POLICIES
  2593. // szOID_CERT_POLICIES
  2594. // szOID_CERT_POLICIES_95 NOTE--Only allowed for decoding!!!
  2595. //
  2596. // pvStructInfo points to following CERT_POLICIES_INFO.
  2597. //
  2598. // NOTE: when decoding using szOID_CERT_POLICIES_95 the pszPolicyIdentifier
  2599. // may contain an empty string
  2600. //--------------------------------------------------------------------------
  2601. typedef struct _CERT_POLICY_QUALIFIER_INFO {
  2602. LPSTR pszPolicyQualifierId; // pszObjId
  2603. CRYPT_OBJID_BLOB Qualifier; // optional
  2604. } CERT_POLICY_QUALIFIER_INFO, *PCERT_POLICY_QUALIFIER_INFO;
  2605. typedef struct _CERT_POLICY_INFO {
  2606. LPSTR pszPolicyIdentifier; // pszObjId
  2607. DWORD cPolicyQualifier; // optional
  2608. CERT_POLICY_QUALIFIER_INFO *rgPolicyQualifier;
  2609. } CERT_POLICY_INFO, *PCERT_POLICY_INFO;
  2610. typedef struct _CERT_POLICIES_INFO {
  2611. DWORD cPolicyInfo;
  2612. CERT_POLICY_INFO *rgPolicyInfo;
  2613. } CERT_POLICIES_INFO, *PCERT_POLICIES_INFO;
  2614. //+-------------------------------------------------------------------------
  2615. // X509_PKIX_POLICY_QUALIFIER_USERNOTICE
  2616. // szOID_PKIX_POLICY_QUALIFIER_USERNOTICE
  2617. //
  2618. // pvStructInfo points to following CERT_POLICY_QUALIFIER_USER_NOTICE.
  2619. //
  2620. //--------------------------------------------------------------------------
  2621. typedef struct _CERT_POLICY_QUALIFIER_NOTICE_REFERENCE {
  2622. LPSTR pszOrganization;
  2623. DWORD cNoticeNumbers;
  2624. int *rgNoticeNumbers;
  2625. } CERT_POLICY_QUALIFIER_NOTICE_REFERENCE, *PCERT_POLICY_QUALIFIER_NOTICE_REFERENCE;
  2626. typedef struct _CERT_POLICY_QUALIFIER_USER_NOTICE {
  2627. CERT_POLICY_QUALIFIER_NOTICE_REFERENCE *pNoticeReference; // optional
  2628. LPWSTR pszDisplayText; // optional
  2629. } CERT_POLICY_QUALIFIER_USER_NOTICE, *PCERT_POLICY_QUALIFIER_USER_NOTICE;
  2630. //+-------------------------------------------------------------------------
  2631. // szOID_CERT_POLICIES_95_QUALIFIER1 - Decode Only!!!!
  2632. //
  2633. // pvStructInfo points to following CERT_POLICY95_QUALIFIER1.
  2634. //
  2635. //--------------------------------------------------------------------------
  2636. typedef struct _CPS_URLS {
  2637. LPWSTR pszURL;
  2638. CRYPT_ALGORITHM_IDENTIFIER *pAlgorithm; // optional
  2639. CRYPT_DATA_BLOB *pDigest; // optional
  2640. } CPS_URLS, *PCPS_URLS;
  2641. typedef struct _CERT_POLICY95_QUALIFIER1 {
  2642. LPWSTR pszPracticesReference; // optional
  2643. LPSTR pszNoticeIdentifier; // optional
  2644. LPSTR pszNSINoticeIdentifier; // optional
  2645. DWORD cCPSURLs;
  2646. CPS_URLS *rgCPSURLs; // optional
  2647. } CERT_POLICY95_QUALIFIER1, *PCERT_POLICY95_QUALIFIER1;
  2648. //+-------------------------------------------------------------------------
  2649. // X509_POLICY_MAPPINGS
  2650. // szOID_POLICY_MAPPINGS
  2651. // szOID_LEGACY_POLICY_MAPPINGS
  2652. //
  2653. // pvStructInfo points to following CERT_POLICY_MAPPINGS_INFO.
  2654. //--------------------------------------------------------------------------
  2655. typedef struct _CERT_POLICY_MAPPING {
  2656. LPSTR pszIssuerDomainPolicy; // pszObjId
  2657. LPSTR pszSubjectDomainPolicy; // pszObjId
  2658. } CERT_POLICY_MAPPING, *PCERT_POLICY_MAPPING;
  2659. typedef struct _CERT_POLICY_MAPPINGS_INFO {
  2660. DWORD cPolicyMapping;
  2661. PCERT_POLICY_MAPPING rgPolicyMapping;
  2662. } CERT_POLICY_MAPPINGS_INFO, *PCERT_POLICY_MAPPINGS_INFO;
  2663. //+-------------------------------------------------------------------------
  2664. // X509_POLICY_CONSTRAINTS
  2665. // szOID_POLICY_CONSTRAINTS
  2666. //
  2667. // pvStructInfo points to following CERT_POLICY_CONSTRAINTS_INFO.
  2668. //--------------------------------------------------------------------------
  2669. typedef struct _CERT_POLICY_CONSTRAINTS_INFO {
  2670. BOOL fRequireExplicitPolicy;
  2671. DWORD dwRequireExplicitPolicySkipCerts;
  2672. BOOL fInhibitPolicyMapping;
  2673. DWORD dwInhibitPolicyMappingSkipCerts;
  2674. } CERT_POLICY_CONSTRAINTS_INFO, *PCERT_POLICY_CONSTRAINTS_INFO;
  2675. //+-------------------------------------------------------------------------
  2676. // RSA_CSP_PUBLICKEYBLOB
  2677. //
  2678. // pvStructInfo points to a PUBLICKEYSTRUC immediately followed by a
  2679. // RSAPUBKEY and the modulus bytes.
  2680. //
  2681. // CryptExportKey outputs the above StructInfo for a dwBlobType of
  2682. // PUBLICKEYBLOB. CryptImportKey expects the above StructInfo when
  2683. // importing a public key.
  2684. //
  2685. // For dwCertEncodingType = X509_ASN_ENCODING, the RSA_CSP_PUBLICKEYBLOB is
  2686. // encoded as a PKCS #1 RSAPublicKey consisting of a SEQUENCE of a
  2687. // modulus INTEGER and a publicExponent INTEGER. The modulus is encoded
  2688. // as being a unsigned integer. When decoded, if the modulus was encoded
  2689. // as unsigned integer with a leading 0 byte, the 0 byte is removed before
  2690. // converting to the CSP modulus bytes.
  2691. //
  2692. // For decode, the aiKeyAlg field of PUBLICKEYSTRUC is always set to
  2693. // CALG_RSA_KEYX.
  2694. //--------------------------------------------------------------------------
  2695. //+-------------------------------------------------------------------------
  2696. // X509_KEYGEN_REQUEST_TO_BE_SIGNED
  2697. //
  2698. // pvStructInfo points to CERT_KEYGEN_REQUEST_INFO.
  2699. //
  2700. // For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  2701. // signature (output of a X509_CERT CryptEncodeObject()).
  2702. //
  2703. // For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  2704. //--------------------------------------------------------------------------
  2705. //+-------------------------------------------------------------------------
  2706. // PKCS_ATTRIBUTE data structure
  2707. //
  2708. // pvStructInfo points to a CRYPT_ATTRIBUTE.
  2709. //--------------------------------------------------------------------------
  2710. //+-------------------------------------------------------------------------
  2711. // PKCS_ATTRIBUTES data structure
  2712. //
  2713. // pvStructInfo points to a CRYPT_ATTRIBUTES.
  2714. //--------------------------------------------------------------------------
  2715. //+-------------------------------------------------------------------------
  2716. // PKCS_CONTENT_INFO_SEQUENCE_OF_ANY data structure
  2717. //
  2718. // pvStructInfo points to following CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY.
  2719. //
  2720. // For X509_ASN_ENCODING: encoded as a PKCS#7 ContentInfo structure wrapping
  2721. // a sequence of ANY. The value of the contentType field is pszObjId,
  2722. // while the content field is the following structure:
  2723. // SequenceOfAny ::= SEQUENCE OF ANY
  2724. //
  2725. // The CRYPT_DER_BLOBs point to the already encoded ANY content.
  2726. //--------------------------------------------------------------------------
  2727. typedef struct _CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY {
  2728. LPSTR pszObjId;
  2729. DWORD cValue;
  2730. PCRYPT_DER_BLOB rgValue;
  2731. } CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY, *PCRYPT_CONTENT_INFO_SEQUENCE_OF_ANY;
  2732. //+-------------------------------------------------------------------------
  2733. // PKCS_CONTENT_INFO data structure
  2734. //
  2735. // pvStructInfo points to following CRYPT_CONTENT_INFO.
  2736. //
  2737. // For X509_ASN_ENCODING: encoded as a PKCS#7 ContentInfo structure.
  2738. // The CRYPT_DER_BLOB points to the already encoded ANY content.
  2739. //--------------------------------------------------------------------------
  2740. typedef struct _CRYPT_CONTENT_INFO {
  2741. LPSTR pszObjId;
  2742. CRYPT_DER_BLOB Content;
  2743. } CRYPT_CONTENT_INFO, *PCRYPT_CONTENT_INFO;
  2744. //+-------------------------------------------------------------------------
  2745. // X509_OCTET_STRING data structure
  2746. //
  2747. // pvStructInfo points to a CRYPT_DATA_BLOB.
  2748. //--------------------------------------------------------------------------
  2749. //+-------------------------------------------------------------------------
  2750. // X509_BITS data structure
  2751. //
  2752. // pvStructInfo points to a CRYPT_BIT_BLOB.
  2753. //--------------------------------------------------------------------------
  2754. //+-------------------------------------------------------------------------
  2755. // X509_BITS_WITHOUT_TRAILING_ZEROES data structure
  2756. //
  2757. // pvStructInfo points to a CRYPT_BIT_BLOB.
  2758. //
  2759. // The same as X509_BITS, except before encoding, the bit length is
  2760. // decremented to exclude trailing zero bits.
  2761. //--------------------------------------------------------------------------
  2762. //+-------------------------------------------------------------------------
  2763. // X509_INTEGER data structure
  2764. //
  2765. // pvStructInfo points to an int.
  2766. //--------------------------------------------------------------------------
  2767. //+-------------------------------------------------------------------------
  2768. // X509_MULTI_BYTE_INTEGER data structure
  2769. //
  2770. // pvStructInfo points to a CRYPT_INTEGER_BLOB.
  2771. //--------------------------------------------------------------------------
  2772. //+-------------------------------------------------------------------------
  2773. // X509_ENUMERATED data structure
  2774. //
  2775. // pvStructInfo points to an int containing the enumerated value
  2776. //--------------------------------------------------------------------------
  2777. //+-------------------------------------------------------------------------
  2778. // X509_CHOICE_OF_TIME data structure
  2779. //
  2780. // pvStructInfo points to a FILETIME.
  2781. //--------------------------------------------------------------------------
  2782. //+-------------------------------------------------------------------------
  2783. // X509_SEQUENCE_OF_ANY data structure
  2784. //
  2785. // pvStructInfo points to following CRYPT_SEQUENCE_OF_ANY.
  2786. //
  2787. // The CRYPT_DER_BLOBs point to the already encoded ANY content.
  2788. //--------------------------------------------------------------------------
  2789. typedef struct _CRYPT_SEQUENCE_OF_ANY {
  2790. DWORD cValue;
  2791. PCRYPT_DER_BLOB rgValue;
  2792. } CRYPT_SEQUENCE_OF_ANY, *PCRYPT_SEQUENCE_OF_ANY;
  2793. //+-------------------------------------------------------------------------
  2794. // X509_AUTHORITY_KEY_ID2
  2795. // szOID_AUTHORITY_KEY_IDENTIFIER2
  2796. //
  2797. // pvStructInfo points to following CERT_AUTHORITY_KEY_ID2_INFO.
  2798. //
  2799. // For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  2800. // *pcbEncoded by CryptEncodeObject(X509_AUTHORITY_KEY_ID2)
  2801. //
  2802. // See X509_ALTERNATE_NAME for error location defines.
  2803. //--------------------------------------------------------------------------
  2804. typedef struct _CERT_AUTHORITY_KEY_ID2_INFO {
  2805. CRYPT_DATA_BLOB KeyId;
  2806. CERT_ALT_NAME_INFO AuthorityCertIssuer; // Optional, set cAltEntry
  2807. // to 0 to omit.
  2808. CRYPT_INTEGER_BLOB AuthorityCertSerialNumber;
  2809. } CERT_AUTHORITY_KEY_ID2_INFO, *PCERT_AUTHORITY_KEY_ID2_INFO;
  2810. //+-------------------------------------------------------------------------
  2811. // szOID_SUBJECT_KEY_IDENTIFIER
  2812. //
  2813. // pvStructInfo points to a CRYPT_DATA_BLOB.
  2814. //--------------------------------------------------------------------------
  2815. //+-------------------------------------------------------------------------
  2816. // X509_AUTHORITY_INFO_ACCESS
  2817. // szOID_AUTHORITY_INFO_ACCESS
  2818. //
  2819. // pvStructInfo points to following CERT_AUTHORITY_INFO_ACCESS.
  2820. //
  2821. // For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  2822. // *pcbEncoded by CryptEncodeObject(X509_AUTHORITY_INFO_ACCESS)
  2823. //
  2824. // Error location consists of:
  2825. // ENTRY_INDEX - 8 bits << 16
  2826. // VALUE_INDEX - 16 bits (unicode character index)
  2827. //
  2828. // See X509_ALTERNATE_NAME for ENTRY_INDEX and VALUE_INDEX error location
  2829. // defines.
  2830. //--------------------------------------------------------------------------
  2831. typedef struct _CERT_ACCESS_DESCRIPTION {
  2832. LPSTR pszAccessMethod; // pszObjId
  2833. CERT_ALT_NAME_ENTRY AccessLocation;
  2834. } CERT_ACCESS_DESCRIPTION, *PCERT_ACCESS_DESCRIPTION;
  2835. typedef struct _CERT_AUTHORITY_INFO_ACCESS {
  2836. DWORD cAccDescr;
  2837. PCERT_ACCESS_DESCRIPTION rgAccDescr;
  2838. } CERT_AUTHORITY_INFO_ACCESS, *PCERT_AUTHORITY_INFO_ACCESS;
  2839. //+-------------------------------------------------------------------------
  2840. // PKIX Access Description: Access Method Object Identifiers
  2841. //--------------------------------------------------------------------------
  2842. #define szOID_PKIX_ACC_DESCR "1.3.6.1.5.5.7.48"
  2843. #define szOID_PKIX_OCSP "1.3.6.1.5.5.7.48.1"
  2844. #define szOID_PKIX_CA_ISSUERS "1.3.6.1.5.5.7.48.2"
  2845. //+-------------------------------------------------------------------------
  2846. // X509_CRL_REASON_CODE
  2847. // szOID_CRL_REASON_CODE
  2848. //
  2849. // pvStructInfo points to an int which can be set to one of the following
  2850. // enumerated values:
  2851. //--------------------------------------------------------------------------
  2852. #define CRL_REASON_UNSPECIFIED 0
  2853. #define CRL_REASON_KEY_COMPROMISE 1
  2854. #define CRL_REASON_CA_COMPROMISE 2
  2855. #define CRL_REASON_AFFILIATION_CHANGED 3
  2856. #define CRL_REASON_SUPERSEDED 4
  2857. #define CRL_REASON_CESSATION_OF_OPERATION 5
  2858. #define CRL_REASON_CERTIFICATE_HOLD 6
  2859. #define CRL_REASON_REMOVE_FROM_CRL 8
  2860. //+-------------------------------------------------------------------------
  2861. // X509_CRL_DIST_POINTS
  2862. // szOID_CRL_DIST_POINTS
  2863. //
  2864. // pvStructInfo points to following CRL_DIST_POINTS_INFO.
  2865. //
  2866. // For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  2867. // *pcbEncoded by CryptEncodeObject(X509_CRL_DIST_POINTS)
  2868. //
  2869. // Error location consists of:
  2870. // CRL_ISSUER_BIT - 1 bit << 31 (0 for FullName, 1 for CRLIssuer)
  2871. // POINT_INDEX - 7 bits << 24
  2872. // ENTRY_INDEX - 8 bits << 16
  2873. // VALUE_INDEX - 16 bits (unicode character index)
  2874. //
  2875. // See X509_ALTERNATE_NAME for ENTRY_INDEX and VALUE_INDEX error location
  2876. // defines.
  2877. //--------------------------------------------------------------------------
  2878. typedef struct _CRL_DIST_POINT_NAME {
  2879. DWORD dwDistPointNameChoice;
  2880. union {
  2881. CERT_ALT_NAME_INFO FullName; // 1
  2882. // Not implemented IssuerRDN; // 2
  2883. };
  2884. } CRL_DIST_POINT_NAME, *PCRL_DIST_POINT_NAME;
  2885. #define CRL_DIST_POINT_NO_NAME 0
  2886. #define CRL_DIST_POINT_FULL_NAME 1
  2887. #define CRL_DIST_POINT_ISSUER_RDN_NAME 2
  2888. typedef struct _CRL_DIST_POINT {
  2889. CRL_DIST_POINT_NAME DistPointName; // OPTIONAL
  2890. CRYPT_BIT_BLOB ReasonFlags; // OPTIONAL
  2891. CERT_ALT_NAME_INFO CRLIssuer; // OPTIONAL
  2892. } CRL_DIST_POINT, *PCRL_DIST_POINT;
  2893. #define CRL_REASON_UNUSED_FLAG 0x80
  2894. #define CRL_REASON_KEY_COMPROMISE_FLAG 0x40
  2895. #define CRL_REASON_CA_COMPROMISE_FLAG 0x20
  2896. #define CRL_REASON_AFFILIATION_CHANGED_FLAG 0x10
  2897. #define CRL_REASON_SUPERSEDED_FLAG 0x08
  2898. #define CRL_REASON_CESSATION_OF_OPERATION_FLAG 0x04
  2899. #define CRL_REASON_CERTIFICATE_HOLD_FLAG 0x02
  2900. typedef struct _CRL_DIST_POINTS_INFO {
  2901. DWORD cDistPoint;
  2902. PCRL_DIST_POINT rgDistPoint;
  2903. } CRL_DIST_POINTS_INFO, *PCRL_DIST_POINTS_INFO;
  2904. #define CRL_DIST_POINT_ERR_INDEX_MASK 0x7F
  2905. #define CRL_DIST_POINT_ERR_INDEX_SHIFT 24
  2906. #define GET_CRL_DIST_POINT_ERR_INDEX(X) \
  2907. ((X >> CRL_DIST_POINT_ERR_INDEX_SHIFT) & CRL_DIST_POINT_ERR_INDEX_MASK)
  2908. #define CRL_DIST_POINT_ERR_CRL_ISSUER_BIT 0x80000000L
  2909. #define IS_CRL_DIST_POINT_ERR_CRL_ISSUER(X) \
  2910. (0 != (X & CRL_DIST_POINT_ERR_CRL_ISSUER_BIT))
  2911. //+-------------------------------------------------------------------------
  2912. // X509_CROSS_CERT_DIST_POINTS
  2913. // szOID_CROSS_CERT_DIST_POINTS
  2914. //
  2915. // pvStructInfo points to following CROSS_CERT_DIST_POINTS_INFO.
  2916. //
  2917. // For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  2918. // *pcbEncoded by CryptEncodeObject(X509_CRL_DIST_POINTS)
  2919. //
  2920. // Error location consists of:
  2921. // POINT_INDEX - 8 bits << 24
  2922. // ENTRY_INDEX - 8 bits << 16
  2923. // VALUE_INDEX - 16 bits (unicode character index)
  2924. //
  2925. // See X509_ALTERNATE_NAME for ENTRY_INDEX and VALUE_INDEX error location
  2926. // defines.
  2927. //--------------------------------------------------------------------------
  2928. typedef struct _CROSS_CERT_DIST_POINTS_INFO {
  2929. // Seconds between syncs. 0 implies use client default.
  2930. DWORD dwSyncDeltaTime;
  2931. DWORD cDistPoint;
  2932. PCERT_ALT_NAME_INFO rgDistPoint;
  2933. } CROSS_CERT_DIST_POINTS_INFO, *PCROSS_CERT_DIST_POINTS_INFO;
  2934. #define CROSS_CERT_DIST_POINT_ERR_INDEX_MASK 0xFF
  2935. #define CROSS_CERT_DIST_POINT_ERR_INDEX_SHIFT 24
  2936. #define GET_CROSS_CERT_DIST_POINT_ERR_INDEX(X) \
  2937. ((X >> CROSS_CERT_DIST_POINT_ERR_INDEX_SHIFT) & \
  2938. CROSS_CERT_DIST_POINT_ERR_INDEX_MASK)
  2939. //+-------------------------------------------------------------------------
  2940. // X509_ENHANCED_KEY_USAGE
  2941. // szOID_ENHANCED_KEY_USAGE
  2942. //
  2943. // pvStructInfo points to a CERT_ENHKEY_USAGE, CTL_USAGE.
  2944. //--------------------------------------------------------------------------
  2945. //+-------------------------------------------------------------------------
  2946. // X509_CERT_PAIR
  2947. //
  2948. // pvStructInfo points to the following CERT_PAIR.
  2949. //--------------------------------------------------------------------------
  2950. typedef struct _CERT_PAIR {
  2951. CERT_BLOB Forward; // OPTIONAL, if Forward.cbData == 0, omitted
  2952. CERT_BLOB Reverse; // OPTIONAL, if Reverse.cbData == 0, omitted
  2953. } CERT_PAIR, *PCERT_PAIR;
  2954. //+-------------------------------------------------------------------------
  2955. // szOID_CRL_NUMBER
  2956. //
  2957. // pvStructInfo points to an int.
  2958. //--------------------------------------------------------------------------
  2959. //+-------------------------------------------------------------------------
  2960. // szOID_DELTA_CRL_INDICATOR
  2961. //
  2962. // pvStructInfo points to an int.
  2963. //--------------------------------------------------------------------------
  2964. //+-------------------------------------------------------------------------
  2965. // szOID_ISSUING_DIST_POINT
  2966. // X509_ISSUING_DIST_POINT
  2967. //
  2968. // pvStructInfo points to the following CRL_ISSUING_DIST_POINT.
  2969. //
  2970. // For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  2971. // *pcbEncoded by CryptEncodeObject(X509_ISSUING_DIST_POINT)
  2972. //
  2973. // Error location consists of:
  2974. // ENTRY_INDEX - 8 bits << 16
  2975. // VALUE_INDEX - 16 bits (unicode character index)
  2976. //
  2977. // See X509_ALTERNATE_NAME for ENTRY_INDEX and VALUE_INDEX error location
  2978. // defines.
  2979. //--------------------------------------------------------------------------
  2980. typedef struct _CRL_ISSUING_DIST_POINT {
  2981. CRL_DIST_POINT_NAME DistPointName; // OPTIONAL
  2982. BOOL fOnlyContainsUserCerts;
  2983. BOOL fOnlyContainsCACerts;
  2984. CRYPT_BIT_BLOB OnlySomeReasonFlags; // OPTIONAL
  2985. BOOL fIndirectCRL;
  2986. } CRL_ISSUING_DIST_POINT, *PCRL_ISSUING_DIST_POINT;
  2987. //+-------------------------------------------------------------------------
  2988. // szOID_FRESHEST_CRL
  2989. //
  2990. // pvStructInfo points to CRL_DIST_POINTS_INFO.
  2991. //--------------------------------------------------------------------------
  2992. //+-------------------------------------------------------------------------
  2993. // szOID_NAME_CONSTRAINTS
  2994. // X509_NAME_CONSTRAINTS
  2995. //
  2996. // pvStructInfo points to the following CERT_NAME_CONSTRAINTS_INFO
  2997. //
  2998. // For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  2999. // *pcbEncoded by CryptEncodeObject(X509_NAME_CONSTRAINTS)
  3000. //
  3001. // Error location consists of:
  3002. // EXCLUDED_SUBTREE_BIT - 1 bit << 31 (0 for permitted, 1 for excluded)
  3003. // ENTRY_INDEX - 8 bits << 16
  3004. // VALUE_INDEX - 16 bits (unicode character index)
  3005. //
  3006. // See X509_ALTERNATE_NAME for ENTRY_INDEX and VALUE_INDEX error location
  3007. // defines.
  3008. //--------------------------------------------------------------------------
  3009. typedef struct _CERT_GENERAL_SUBTREE {
  3010. CERT_ALT_NAME_ENTRY Base;
  3011. DWORD dwMinimum;
  3012. BOOL fMaximum;
  3013. DWORD dwMaximum;
  3014. } CERT_GENERAL_SUBTREE, *PCERT_GENERAL_SUBTREE;
  3015. typedef struct _CERT_NAME_CONSTRAINTS_INFO {
  3016. DWORD cPermittedSubtree;
  3017. PCERT_GENERAL_SUBTREE rgPermittedSubtree;
  3018. DWORD cExcludedSubtree;
  3019. PCERT_GENERAL_SUBTREE rgExcludedSubtree;
  3020. } CERT_NAME_CONSTRAINTS_INFO, *PCERT_NAME_CONSTRAINTS_INFO;
  3021. #define CERT_EXCLUDED_SUBTREE_BIT 0x80000000L
  3022. #define IS_CERT_EXCLUDED_SUBTREE(X) \
  3023. (0 != (X & CERT_EXCLUDED_SUBTREE_BIT))
  3024. //+-------------------------------------------------------------------------
  3025. // szOID_NEXT_UPDATE_LOCATION
  3026. //
  3027. // pvStructInfo points to a CERT_ALT_NAME_INFO.
  3028. //--------------------------------------------------------------------------
  3029. //+-------------------------------------------------------------------------
  3030. // szOID_REMOVE_CERTIFICATE
  3031. //
  3032. // pvStructInfo points to an int which can be set to one of the following
  3033. // 0 - Add certificate
  3034. // 1 - Remove certificate
  3035. //--------------------------------------------------------------------------
  3036. //+-------------------------------------------------------------------------
  3037. // PKCS_CTL
  3038. // szOID_CTL
  3039. //
  3040. // pvStructInfo points to a CTL_INFO.
  3041. //--------------------------------------------------------------------------
  3042. //+-------------------------------------------------------------------------
  3043. // PKCS_SORTED_CTL
  3044. //
  3045. // pvStructInfo points to a CTL_INFO.
  3046. //
  3047. // Same as for PKCS_CTL, except, the CTL entries are sorted. The following
  3048. // extension containing the sort information is inserted as the first
  3049. // extension in the encoded CTL.
  3050. //
  3051. // Only supported for Encoding. CRYPT_ENCODE_ALLOC_FLAG flag must be
  3052. // set.
  3053. //--------------------------------------------------------------------------
  3054. //+-------------------------------------------------------------------------
  3055. // Sorted CTL TrustedSubjects extension
  3056. //
  3057. // Array of little endian DWORDs:
  3058. // [0] - Flags
  3059. // [1] - Count of HashBucket entry offsets
  3060. // [2] - Maximum HashBucket entry collision count
  3061. // [3 ..] (Count + 1) HashBucket entry offsets
  3062. //
  3063. // When this extension is present in the CTL,
  3064. // the ASN.1 encoded sequence of TrustedSubjects are HashBucket ordered.
  3065. //
  3066. // The entry offsets point to the start of the first encoded TrustedSubject
  3067. // sequence for the HashBucket. The encoded TrustedSubjects for a HashBucket
  3068. // continue until the encoded offset of the next HashBucket. A HashBucket has
  3069. // no entries if HashBucket[N] == HashBucket[N + 1].
  3070. //
  3071. // The HashBucket offsets are from the start of the ASN.1 encoded CTL_INFO.
  3072. //--------------------------------------------------------------------------
  3073. #define SORTED_CTL_EXT_FLAGS_OFFSET (0*4)
  3074. #define SORTED_CTL_EXT_COUNT_OFFSET (1*4)
  3075. #define SORTED_CTL_EXT_MAX_COLLISION_OFFSET (2*4)
  3076. #define SORTED_CTL_EXT_HASH_BUCKET_OFFSET (3*4)
  3077. // If the SubjectIdentifiers are a MD5 or SHA1 hash, the following flag is
  3078. // set. When set, the first 4 bytes of the SubjectIdentifier are used as
  3079. // the dwhash. Otherwise, the SubjectIdentifier bytes are hashed into dwHash.
  3080. // In either case the HashBucket index = dwHash % cHashBucket.
  3081. #define SORTED_CTL_EXT_HASHED_SUBJECT_IDENTIFIER_FLAG 0x1
  3082. //+-------------------------------------------------------------------------
  3083. // X509_MULTI_BYTE_UINT
  3084. //
  3085. // pvStructInfo points to a CRYPT_UINT_BLOB. Before encoding, inserts a
  3086. // leading 0x00. After decoding, removes a leading 0x00.
  3087. //--------------------------------------------------------------------------
  3088. //+-------------------------------------------------------------------------
  3089. // X509_DSS_PUBLICKEY
  3090. //
  3091. // pvStructInfo points to a CRYPT_UINT_BLOB.
  3092. //--------------------------------------------------------------------------
  3093. //+-------------------------------------------------------------------------
  3094. // X509_DSS_PARAMETERS
  3095. //
  3096. // pvStructInfo points to following CERT_DSS_PARAMETERS data structure.
  3097. //--------------------------------------------------------------------------
  3098. typedef struct _CERT_DSS_PARAMETERS {
  3099. CRYPT_UINT_BLOB p;
  3100. CRYPT_UINT_BLOB q;
  3101. CRYPT_UINT_BLOB g;
  3102. } CERT_DSS_PARAMETERS, *PCERT_DSS_PARAMETERS;
  3103. //+-------------------------------------------------------------------------
  3104. // X509_DSS_SIGNATURE
  3105. //
  3106. // pvStructInfo is a BYTE rgbSignature[CERT_DSS_SIGNATURE_LEN]. The
  3107. // bytes are ordered as output by the DSS CSP's CryptSignHash().
  3108. //--------------------------------------------------------------------------
  3109. #define CERT_DSS_R_LEN 20
  3110. #define CERT_DSS_S_LEN 20
  3111. #define CERT_DSS_SIGNATURE_LEN (CERT_DSS_R_LEN + CERT_DSS_S_LEN)
  3112. // Sequence of 2 unsigned integers (the extra +1 is for a potential leading
  3113. // 0x00 to make the integer unsigned)
  3114. #define CERT_MAX_ASN_ENCODED_DSS_SIGNATURE_LEN (2 + 2*(2 + 20 +1))
  3115. //+-------------------------------------------------------------------------
  3116. // X509_DH_PUBLICKEY
  3117. //
  3118. // pvStructInfo points to a CRYPT_UINT_BLOB.
  3119. //--------------------------------------------------------------------------
  3120. //+-------------------------------------------------------------------------
  3121. // X509_DH_PARAMETERS
  3122. //
  3123. // pvStructInfo points to following CERT_DH_PARAMETERS data structure.
  3124. //--------------------------------------------------------------------------
  3125. typedef struct _CERT_DH_PARAMETERS {
  3126. CRYPT_UINT_BLOB p;
  3127. CRYPT_UINT_BLOB g;
  3128. } CERT_DH_PARAMETERS, *PCERT_DH_PARAMETERS;
  3129. //+-------------------------------------------------------------------------
  3130. // X942_DH_PARAMETERS
  3131. //
  3132. // pvStructInfo points to following CERT_X942_DH_PARAMETERS data structure.
  3133. //
  3134. // If q.cbData == 0, then, the following fields are zero'ed.
  3135. //--------------------------------------------------------------------------
  3136. typedef struct _CERT_X942_DH_VALIDATION_PARAMS {
  3137. CRYPT_BIT_BLOB seed;
  3138. DWORD pgenCounter;
  3139. } CERT_X942_DH_VALIDATION_PARAMS, *PCERT_X942_DH_VALIDATION_PARAMS;
  3140. typedef struct _CERT_X942_DH_PARAMETERS {
  3141. CRYPT_UINT_BLOB p; // odd prime, p = jq + 1
  3142. CRYPT_UINT_BLOB g; // generator, g
  3143. CRYPT_UINT_BLOB q; // factor of p - 1, OPTIONAL
  3144. CRYPT_UINT_BLOB j; // subgroup factor, OPTIONAL
  3145. PCERT_X942_DH_VALIDATION_PARAMS pValidationParams; // OPTIONAL
  3146. } CERT_X942_DH_PARAMETERS, *PCERT_X942_DH_PARAMETERS;
  3147. //+-------------------------------------------------------------------------
  3148. // X942_OTHER_INFO
  3149. //
  3150. // pvStructInfo points to following CRYPT_X942_OTHER_INFO data structure.
  3151. //
  3152. // rgbCounter and rgbKeyLength are in Little Endian order.
  3153. //--------------------------------------------------------------------------
  3154. #define CRYPT_X942_COUNTER_BYTE_LENGTH 4
  3155. #define CRYPT_X942_KEY_LENGTH_BYTE_LENGTH 4
  3156. #define CRYPT_X942_PUB_INFO_BYTE_LENGTH (512/8)
  3157. typedef struct _CRYPT_X942_OTHER_INFO {
  3158. LPSTR pszContentEncryptionObjId;
  3159. BYTE rgbCounter[CRYPT_X942_COUNTER_BYTE_LENGTH];
  3160. BYTE rgbKeyLength[CRYPT_X942_KEY_LENGTH_BYTE_LENGTH];
  3161. CRYPT_DATA_BLOB PubInfo; // OPTIONAL
  3162. } CRYPT_X942_OTHER_INFO, *PCRYPT_X942_OTHER_INFO;
  3163. //+-------------------------------------------------------------------------
  3164. // PKCS_RC2_CBC_PARAMETERS
  3165. // szOID_RSA_RC2CBC
  3166. //
  3167. // pvStructInfo points to following CRYPT_RC2_CBC_PARAMETERS data structure.
  3168. //--------------------------------------------------------------------------
  3169. typedef struct _CRYPT_RC2_CBC_PARAMETERS {
  3170. DWORD dwVersion;
  3171. BOOL fIV; // set if has following IV
  3172. BYTE rgbIV[8];
  3173. } CRYPT_RC2_CBC_PARAMETERS, *PCRYPT_RC2_CBC_PARAMETERS;
  3174. #define CRYPT_RC2_40BIT_VERSION 160
  3175. #define CRYPT_RC2_56BIT_VERSION 52
  3176. #define CRYPT_RC2_64BIT_VERSION 120
  3177. #define CRYPT_RC2_128BIT_VERSION 58
  3178. //+-------------------------------------------------------------------------
  3179. // PKCS_SMIME_CAPABILITIES
  3180. // szOID_RSA_SMIMECapabilities
  3181. //
  3182. // pvStructInfo points to following CRYPT_SMIME_CAPABILITIES data structure.
  3183. //
  3184. // Note, for CryptEncodeObject(X509_ASN_ENCODING), Parameters.cbData == 0
  3185. // causes the encoded parameters to be omitted and not encoded as a NULL
  3186. // (05 00) as is done when encoding a CRYPT_ALGORITHM_IDENTIFIER. This
  3187. // is per the SMIME specification for encoding capabilities.
  3188. //--------------------------------------------------------------------------
  3189. typedef struct _CRYPT_SMIME_CAPABILITY {
  3190. LPSTR pszObjId;
  3191. CRYPT_OBJID_BLOB Parameters;
  3192. } CRYPT_SMIME_CAPABILITY, *PCRYPT_SMIME_CAPABILITY;
  3193. typedef struct _CRYPT_SMIME_CAPABILITIES {
  3194. DWORD cCapability;
  3195. PCRYPT_SMIME_CAPABILITY rgCapability;
  3196. } CRYPT_SMIME_CAPABILITIES, *PCRYPT_SMIME_CAPABILITIES;
  3197. //+-------------------------------------------------------------------------
  3198. // PKCS7_SIGNER_INFO
  3199. //
  3200. // pvStructInfo points to CMSG_SIGNER_INFO.
  3201. //--------------------------------------------------------------------------
  3202. //+-------------------------------------------------------------------------
  3203. // CMS_SIGNER_INFO
  3204. //
  3205. // pvStructInfo points to CMSG_CMS_SIGNER_INFO.
  3206. //--------------------------------------------------------------------------
  3207. //+-------------------------------------------------------------------------
  3208. // Verisign Certificate Extension Object Identifiers
  3209. //--------------------------------------------------------------------------
  3210. // Octet String containing Boolean
  3211. #define szOID_VERISIGN_PRIVATE_6_9 "2.16.840.1.113733.1.6.9"
  3212. // Octet String containing IA5 string: lower case 32 char hex string
  3213. #define szOID_VERISIGN_ONSITE_JURISDICTION_HASH "2.16.840.1.113733.1.6.11"
  3214. // Octet String containing Bit string
  3215. #define szOID_VERISIGN_BITSTRING_6_13 "2.16.840.1.113733.1.6.13"
  3216. // EKU
  3217. #define szOID_VERISIGN_ISS_STRONG_CRYPTO "2.16.840.1.113733.1.8.1"
  3218. //+-------------------------------------------------------------------------
  3219. // Netscape Certificate Extension Object Identifiers
  3220. //--------------------------------------------------------------------------
  3221. #define szOID_NETSCAPE "2.16.840.1.113730"
  3222. #define szOID_NETSCAPE_CERT_EXTENSION "2.16.840.1.113730.1"
  3223. #define szOID_NETSCAPE_CERT_TYPE "2.16.840.1.113730.1.1"
  3224. #define szOID_NETSCAPE_BASE_URL "2.16.840.1.113730.1.2"
  3225. #define szOID_NETSCAPE_REVOCATION_URL "2.16.840.1.113730.1.3"
  3226. #define szOID_NETSCAPE_CA_REVOCATION_URL "2.16.840.1.113730.1.4"
  3227. #define szOID_NETSCAPE_CERT_RENEWAL_URL "2.16.840.1.113730.1.7"
  3228. #define szOID_NETSCAPE_CA_POLICY_URL "2.16.840.1.113730.1.8"
  3229. #define szOID_NETSCAPE_SSL_SERVER_NAME "2.16.840.1.113730.1.12"
  3230. #define szOID_NETSCAPE_COMMENT "2.16.840.1.113730.1.13"
  3231. //+-------------------------------------------------------------------------
  3232. // Netscape Certificate Data Type Object Identifiers
  3233. //--------------------------------------------------------------------------
  3234. #define szOID_NETSCAPE_DATA_TYPE "2.16.840.1.113730.2"
  3235. #define szOID_NETSCAPE_CERT_SEQUENCE "2.16.840.1.113730.2.5"
  3236. //+-------------------------------------------------------------------------
  3237. // szOID_NETSCAPE_CERT_TYPE extension
  3238. //
  3239. // Its value is a bit string. CryptDecodeObject/CryptEncodeObject using
  3240. // X509_BITS or X509_BITS_WITHOUT_TRAILING_ZEROES.
  3241. //
  3242. // The following bits are defined:
  3243. //--------------------------------------------------------------------------
  3244. #define NETSCAPE_SSL_CLIENT_AUTH_CERT_TYPE 0x80
  3245. #define NETSCAPE_SSL_SERVER_AUTH_CERT_TYPE 0x40
  3246. #define NETSCAPE_SMIME_CERT_TYPE 0x20
  3247. #define NETSCAPE_SIGN_CERT_TYPE 0x10
  3248. #define NETSCAPE_SSL_CA_CERT_TYPE 0x04
  3249. #define NETSCAPE_SMIME_CA_CERT_TYPE 0x02
  3250. #define NETSCAPE_SIGN_CA_CERT_TYPE 0x01
  3251. //+-------------------------------------------------------------------------
  3252. // szOID_NETSCAPE_BASE_URL extension
  3253. //
  3254. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3255. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3256. // dwValueType = CERT_RDN_IA5_STRING.
  3257. //
  3258. // When present this string is added to the beginning of all relative URLs
  3259. // in the certificate. This extension can be considered an optimization
  3260. // to reduce the size of the URL extensions.
  3261. //--------------------------------------------------------------------------
  3262. //+-------------------------------------------------------------------------
  3263. // szOID_NETSCAPE_REVOCATION_URL extension
  3264. //
  3265. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3266. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3267. // dwValueType = CERT_RDN_IA5_STRING.
  3268. //
  3269. // It is a relative or absolute URL that can be used to check the
  3270. // revocation status of a certificate. The revocation check will be
  3271. // performed as an HTTP GET method using a url that is the concatenation of
  3272. // revocation-url and certificate-serial-number.
  3273. // Where the certificate-serial-number is encoded as a string of
  3274. // ascii hexadecimal digits. For example, if the netscape-base-url is
  3275. // https://www.certs-r-us.com/, the netscape-revocation-url is
  3276. // cgi-bin/check-rev.cgi?, and the certificate serial number is 173420,
  3277. // the resulting URL would be:
  3278. // https://www.certs-r-us.com/cgi-bin/check-rev.cgi?02a56c
  3279. //
  3280. // The server should return a document with a Content-Type of
  3281. // application/x-netscape-revocation. The document should contain
  3282. // a single ascii digit, '1' if the certificate is not curently valid,
  3283. // and '0' if it is curently valid.
  3284. //
  3285. // Note: for all of the URLs that include the certificate serial number,
  3286. // the serial number will be encoded as a string which consists of an even
  3287. // number of hexadecimal digits. If the number of significant digits is odd,
  3288. // the string will have a single leading zero to ensure an even number of
  3289. // digits is generated.
  3290. //--------------------------------------------------------------------------
  3291. //+-------------------------------------------------------------------------
  3292. // szOID_NETSCAPE_CA_REVOCATION_URL extension
  3293. //
  3294. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3295. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3296. // dwValueType = CERT_RDN_IA5_STRING.
  3297. //
  3298. // It is a relative or absolute URL that can be used to check the
  3299. // revocation status of any certificates that are signed by the CA that
  3300. // this certificate belongs to. This extension is only valid in CA
  3301. // certificates. The use of this extension is the same as the above
  3302. // szOID_NETSCAPE_REVOCATION_URL extension.
  3303. //--------------------------------------------------------------------------
  3304. //+-------------------------------------------------------------------------
  3305. // szOID_NETSCAPE_CERT_RENEWAL_URL extension
  3306. //
  3307. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3308. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3309. // dwValueType = CERT_RDN_IA5_STRING.
  3310. //
  3311. // It is a relative or absolute URL that points to a certificate renewal
  3312. // form. The renewal form will be accessed with an HTTP GET method using a
  3313. // url that is the concatenation of renewal-url and
  3314. // certificate-serial-number. Where the certificate-serial-number is
  3315. // encoded as a string of ascii hexadecimal digits. For example, if the
  3316. // netscape-base-url is https://www.certs-r-us.com/, the
  3317. // netscape-cert-renewal-url is cgi-bin/check-renew.cgi?, and the
  3318. // certificate serial number is 173420, the resulting URL would be:
  3319. // https://www.certs-r-us.com/cgi-bin/check-renew.cgi?02a56c
  3320. // The document returned should be an HTML form that will allow the user
  3321. // to request a renewal of their certificate.
  3322. //--------------------------------------------------------------------------
  3323. //+-------------------------------------------------------------------------
  3324. // szOID_NETSCAPE_CA_POLICY_URL extension
  3325. //
  3326. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3327. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3328. // dwValueType = CERT_RDN_IA5_STRING.
  3329. //
  3330. // It is a relative or absolute URL that points to a web page that
  3331. // describes the policies under which the certificate was issued.
  3332. //--------------------------------------------------------------------------
  3333. //+-------------------------------------------------------------------------
  3334. // szOID_NETSCAPE_SSL_SERVER_NAME extension
  3335. //
  3336. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3337. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3338. // dwValueType = CERT_RDN_IA5_STRING.
  3339. //
  3340. // It is a "shell expression" that can be used to match the hostname of the
  3341. // SSL server that is using this certificate. It is recommended that if
  3342. // the server's hostname does not match this pattern the user be notified
  3343. // and given the option to terminate the SSL connection. If this extension
  3344. // is not present then the CommonName in the certificate subject's
  3345. // distinguished name is used for the same purpose.
  3346. //--------------------------------------------------------------------------
  3347. //+-------------------------------------------------------------------------
  3348. // szOID_NETSCAPE_COMMENT extension
  3349. //
  3350. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3351. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3352. // dwValueType = CERT_RDN_IA5_STRING.
  3353. //
  3354. // It is a comment that may be displayed to the user when the certificate
  3355. // is viewed.
  3356. //--------------------------------------------------------------------------
  3357. //+-------------------------------------------------------------------------
  3358. // szOID_NETSCAPE_CERT_SEQUENCE
  3359. //
  3360. // Its value is a PKCS#7 ContentInfo structure wrapping a sequence of
  3361. // certificates. The value of the contentType field is
  3362. // szOID_NETSCAPE_CERT_SEQUENCE, while the content field is the following
  3363. // structure:
  3364. // CertificateSequence ::= SEQUENCE OF Certificate.
  3365. //
  3366. // CryptDecodeObject/CryptEncodeObject using
  3367. // PKCS_CONTENT_INFO_SEQUENCE_OF_ANY, where,
  3368. // pszObjId = szOID_NETSCAPE_CERT_SEQUENCE and the CRYPT_DER_BLOBs point
  3369. // to encoded X509 certificates.
  3370. //--------------------------------------------------------------------------
  3371. //+=========================================================================
  3372. // Certificate Management Messages over CMS (CMC) Data Structures
  3373. //==========================================================================
  3374. // Content Type (request)
  3375. #define szOID_CT_PKI_DATA "1.3.6.1.5.5.7.12.2"
  3376. // Content Type (response)
  3377. #define szOID_CT_PKI_RESPONSE "1.3.6.1.5.5.7.12.3"
  3378. // Signature value that only contains the hash octets. The parameters for
  3379. // this algorithm must be present and must be encoded as NULL.
  3380. #define szOID_PKIX_NO_SIGNATURE "1.3.6.1.5.5.7.6.2"
  3381. #define szOID_CMC "1.3.6.1.5.5.7.7"
  3382. #define szOID_CMC_STATUS_INFO "1.3.6.1.5.5.7.7.1"
  3383. #define szOID_CMC_IDENTIFICATION "1.3.6.1.5.5.7.7.2"
  3384. #define szOID_CMC_IDENTITY_PROOF "1.3.6.1.5.5.7.7.3"
  3385. #define szOID_CMC_DATA_RETURN "1.3.6.1.5.5.7.7.4"
  3386. // Transaction Id (integer)
  3387. #define szOID_CMC_TRANSACTION_ID "1.3.6.1.5.5.7.7.5"
  3388. // Sender Nonce (octet string)
  3389. #define szOID_CMC_SENDER_NONCE "1.3.6.1.5.5.7.7.6"
  3390. // Recipient Nonce (octet string)
  3391. #define szOID_CMC_RECIPIENT_NONCE "1.3.6.1.5.5.7.7.7"
  3392. #define szOID_CMC_ADD_EXTENSIONS "1.3.6.1.5.5.7.7.8"
  3393. #define szOID_CMC_ENCRYPTED_POP "1.3.6.1.5.5.7.7.9"
  3394. #define szOID_CMC_DECRYPTED_POP "1.3.6.1.5.5.7.7.10"
  3395. #define szOID_CMC_LRA_POP_WITNESS "1.3.6.1.5.5.7.7.11"
  3396. // Issuer Name + Serial
  3397. #define szOID_CMC_GET_CERT "1.3.6.1.5.5.7.7.15"
  3398. // Issuer Name [+ CRL Name] + Time [+ Reasons]
  3399. #define szOID_CMC_GET_CRL "1.3.6.1.5.5.7.7.16"
  3400. // Issuer Name + Serial [+ Reason] [+ Effective Time] [+ Secret] [+ Comment]
  3401. #define szOID_CMC_REVOKE_REQUEST "1.3.6.1.5.5.7.7.17"
  3402. // (octet string) URL-style parameter list (IA5?)
  3403. #define szOID_CMC_REG_INFO "1.3.6.1.5.5.7.7.18"
  3404. #define szOID_CMC_RESPONSE_INFO "1.3.6.1.5.5.7.7.19"
  3405. // (octet string)
  3406. #define szOID_CMC_QUERY_PENDING "1.3.6.1.5.5.7.7.21"
  3407. #define szOID_CMC_ID_POP_LINK_RANDOM "1.3.6.1.5.5.7.7.22"
  3408. #define szOID_CMC_ID_POP_LINK_WITNESS "1.3.6.1.5.5.7.7.23"
  3409. // optional Name + Integer
  3410. #define szOID_CMC_ID_CONFIRM_CERT_ACCEPTANCE "1.3.6.1.5.5.7.7.24"
  3411. #define szOID_CMC_ADD_ATTRIBUTES "1.3.6.1.4.1.311.10.10.1"
  3412. //+-------------------------------------------------------------------------
  3413. // CMC_DATA
  3414. // CMC_RESPONSE
  3415. //
  3416. // Certificate Management Messages over CMS (CMC) PKIData and Response
  3417. // messages.
  3418. //
  3419. // For CMC_DATA, pvStructInfo points to a CMC_DATA_INFO.
  3420. // CMC_DATA_INFO contains optional arrays of tagged attributes, requests,
  3421. // content info and/or arbitrary other messages.
  3422. //
  3423. // For CMC_RESPONSE, pvStructInfo points to a CMC_RESPONSE_INFO.
  3424. // CMC_RESPONSE_INFO is the same as CMC_DATA_INFO without the tagged
  3425. // requests.
  3426. //--------------------------------------------------------------------------
  3427. typedef struct _CMC_TAGGED_ATTRIBUTE {
  3428. DWORD dwBodyPartID;
  3429. CRYPT_ATTRIBUTE Attribute;
  3430. } CMC_TAGGED_ATTRIBUTE, *PCMC_TAGGED_ATTRIBUTE;
  3431. typedef struct _CMC_TAGGED_CERT_REQUEST {
  3432. DWORD dwBodyPartID;
  3433. CRYPT_DER_BLOB SignedCertRequest;
  3434. } CMC_TAGGED_CERT_REQUEST, *PCMC_TAGGED_CERT_REQUEST;
  3435. typedef struct _CMC_TAGGED_REQUEST {
  3436. DWORD dwTaggedRequestChoice;
  3437. union {
  3438. // CMC_TAGGED_CERT_REQUEST_CHOICE
  3439. PCMC_TAGGED_CERT_REQUEST pTaggedCertRequest;
  3440. };
  3441. } CMC_TAGGED_REQUEST, *PCMC_TAGGED_REQUEST;
  3442. #define CMC_TAGGED_CERT_REQUEST_CHOICE 1
  3443. typedef struct _CMC_TAGGED_CONTENT_INFO {
  3444. DWORD dwBodyPartID;
  3445. CRYPT_DER_BLOB EncodedContentInfo;
  3446. } CMC_TAGGED_CONTENT_INFO, *PCMC_TAGGED_CONTENT_INFO;
  3447. typedef struct _CMC_TAGGED_OTHER_MSG {
  3448. DWORD dwBodyPartID;
  3449. LPSTR pszObjId;
  3450. CRYPT_OBJID_BLOB Value;
  3451. } CMC_TAGGED_OTHER_MSG, *PCMC_TAGGED_OTHER_MSG;
  3452. // All the tagged arrays are optional
  3453. typedef struct _CMC_DATA_INFO {
  3454. DWORD cTaggedAttribute;
  3455. PCMC_TAGGED_ATTRIBUTE rgTaggedAttribute;
  3456. DWORD cTaggedRequest;
  3457. PCMC_TAGGED_REQUEST rgTaggedRequest;
  3458. DWORD cTaggedContentInfo;
  3459. PCMC_TAGGED_CONTENT_INFO rgTaggedContentInfo;
  3460. DWORD cTaggedOtherMsg;
  3461. PCMC_TAGGED_OTHER_MSG rgTaggedOtherMsg;
  3462. } CMC_DATA_INFO, *PCMC_DATA_INFO;
  3463. // All the tagged arrays are optional
  3464. typedef struct _CMC_RESPONSE_INFO {
  3465. DWORD cTaggedAttribute;
  3466. PCMC_TAGGED_ATTRIBUTE rgTaggedAttribute;
  3467. DWORD cTaggedContentInfo;
  3468. PCMC_TAGGED_CONTENT_INFO rgTaggedContentInfo;
  3469. DWORD cTaggedOtherMsg;
  3470. PCMC_TAGGED_OTHER_MSG rgTaggedOtherMsg;
  3471. } CMC_RESPONSE_INFO, *PCMC_RESPONSE_INFO;
  3472. //+-------------------------------------------------------------------------
  3473. // CMC_STATUS
  3474. //
  3475. // Certificate Management Messages over CMS (CMC) Status.
  3476. //
  3477. // pvStructInfo points to a CMC_STATUS_INFO.
  3478. //--------------------------------------------------------------------------
  3479. typedef struct _CMC_PEND_INFO {
  3480. CRYPT_DATA_BLOB PendToken;
  3481. FILETIME PendTime;
  3482. } CMC_PEND_INFO, *PCMC_PEND_INFO;
  3483. typedef struct _CMC_STATUS_INFO {
  3484. DWORD dwStatus;
  3485. DWORD cBodyList;
  3486. DWORD *rgdwBodyList;
  3487. LPWSTR pwszStatusString; // OPTIONAL
  3488. DWORD dwOtherInfoChoice;
  3489. union {
  3490. // CMC_OTHER_INFO_NO_CHOICE
  3491. // none
  3492. // CMC_OTHER_INFO_FAIL_CHOICE
  3493. DWORD dwFailInfo;
  3494. // CMC_OTHER_INFO_PEND_CHOICE
  3495. PCMC_PEND_INFO pPendInfo;
  3496. };
  3497. } CMC_STATUS_INFO, *PCMC_STATUS_INFO;
  3498. #define CMC_OTHER_INFO_NO_CHOICE 0
  3499. #define CMC_OTHER_INFO_FAIL_CHOICE 1
  3500. #define CMC_OTHER_INFO_PEND_CHOICE 2
  3501. //
  3502. // dwStatus values
  3503. //
  3504. // Request was granted
  3505. #define CMC_STATUS_SUCCESS 0
  3506. // Request failed, more information elsewhere in the message
  3507. #define CMC_STATUS_FAILED 2
  3508. // The request body part has not yet been processed. Requester is responsible
  3509. // to poll back. May only be returned for certificate request operations.
  3510. #define CMC_STATUS_PENDING 3
  3511. // The requested operation is not supported
  3512. #define CMC_STATUS_NO_SUPPORT 4
  3513. // Confirmation using the idConfirmCertAcceptance control is required
  3514. // before use of certificate
  3515. #define CMC_STATUS_CONFIRM_REQUIRED 5
  3516. //
  3517. // dwFailInfo values
  3518. //
  3519. // Unrecognized or unsupported algorithm
  3520. #define CMC_FAIL_BAD_ALG 0
  3521. // Integrity check failed
  3522. #define CMC_FAIL_BAD_MESSAGE_CHECK 1
  3523. // Transaction not permitted or supported
  3524. #define CMC_FAIL_BAD_REQUEST 2
  3525. // Message time field was not sufficiently close to the system time
  3526. #define CMC_FAIL_BAD_TIME 3
  3527. // No certificate could be identified matching the provided criteria
  3528. #define CMC_FAIL_BAD_CERT_ID 4
  3529. // A requested X.509 extension is not supported by the recipient CA.
  3530. #define CMC_FAIL_UNSUPORTED_EXT 5
  3531. // Private key material must be supplied
  3532. #define CMC_FAIL_MUST_ARCHIVE_KEYS 6
  3533. // Identification Attribute failed to verify
  3534. #define CMC_FAIL_BAD_IDENTITY 7
  3535. // Server requires a POP proof before issuing certificate
  3536. #define CMC_FAIL_POP_REQUIRED 8
  3537. // POP processing failed
  3538. #define CMC_FAIL_POP_FAILED 9
  3539. // Server policy does not allow key re-use
  3540. #define CMC_FAIL_NO_KEY_REUSE 10
  3541. #define CMC_FAIL_INTERNAL_CA_ERROR 11
  3542. #define CMC_FAIL_TRY_LATER 12
  3543. //+-------------------------------------------------------------------------
  3544. // CMC_ADD_EXTENSIONS
  3545. //
  3546. // Certificate Management Messages over CMS (CMC) Add Extensions control
  3547. // attribute.
  3548. //
  3549. // pvStructInfo points to a CMC_ADD_EXTENSIONS_INFO.
  3550. //--------------------------------------------------------------------------
  3551. typedef struct _CMC_ADD_EXTENSIONS_INFO {
  3552. DWORD dwCmcDataReference;
  3553. DWORD cCertReference;
  3554. DWORD *rgdwCertReference;
  3555. DWORD cExtension;
  3556. PCERT_EXTENSION rgExtension;
  3557. } CMC_ADD_EXTENSIONS_INFO, *PCMC_ADD_EXTENSIONS_INFO;
  3558. //+-------------------------------------------------------------------------
  3559. // CMC_ADD_ATTRIBUTES
  3560. //
  3561. // Certificate Management Messages over CMS (CMC) Add Attributes control
  3562. // attribute.
  3563. //
  3564. // pvStructInfo points to a CMC_ADD_ATTRIBUTES_INFO.
  3565. //--------------------------------------------------------------------------
  3566. typedef struct _CMC_ADD_ATTRIBUTES_INFO {
  3567. DWORD dwCmcDataReference;
  3568. DWORD cCertReference;
  3569. DWORD *rgdwCertReference;
  3570. DWORD cAttribute;
  3571. PCRYPT_ATTRIBUTE rgAttribute;
  3572. } CMC_ADD_ATTRIBUTES_INFO, *PCMC_ADD_ATTRIBUTES_INFO;
  3573. //+-------------------------------------------------------------------------
  3574. // X509_CERTIFICATE_TEMPLATE
  3575. // szOID_CERTIFICATE_TEMPLATE
  3576. //
  3577. // pvStructInfo points to following CERT_TEMPLATE_EXT data structure.
  3578. //
  3579. //--------------------------------------------------------------------------
  3580. typedef struct _CERT_TEMPLATE_EXT {
  3581. LPSTR pszObjId;
  3582. DWORD dwMajorVersion;
  3583. BOOL fMinorVersion; // TRUE for a minor version
  3584. DWORD dwMinorVersion;
  3585. } CERT_TEMPLATE_EXT, *PCERT_TEMPLATE_EXT;
  3586. //+=========================================================================
  3587. // Object IDentifier (OID) Installable Functions: Data Structures and APIs
  3588. //==========================================================================
  3589. typedef void *HCRYPTOIDFUNCSET;
  3590. typedef void *HCRYPTOIDFUNCADDR;
  3591. // Predefined OID Function Names
  3592. #define CRYPT_OID_ENCODE_OBJECT_FUNC "CryptDllEncodeObject"
  3593. #define CRYPT_OID_DECODE_OBJECT_FUNC "CryptDllDecodeObject"
  3594. #define CRYPT_OID_ENCODE_OBJECT_EX_FUNC "CryptDllEncodeObjectEx"
  3595. #define CRYPT_OID_DECODE_OBJECT_EX_FUNC "CryptDllDecodeObjectEx"
  3596. #define CRYPT_OID_CREATE_COM_OBJECT_FUNC "CryptDllCreateCOMObject"
  3597. #define CRYPT_OID_VERIFY_REVOCATION_FUNC "CertDllVerifyRevocation"
  3598. #define CRYPT_OID_VERIFY_CTL_USAGE_FUNC "CertDllVerifyCTLUsage"
  3599. #define CRYPT_OID_FORMAT_OBJECT_FUNC "CryptDllFormatObject"
  3600. #define CRYPT_OID_FIND_OID_INFO_FUNC "CryptDllFindOIDInfo"
  3601. #define CRYPT_OID_FIND_LOCALIZED_NAME_FUNC "CryptDllFindLocalizedName"
  3602. // CryptDllEncodeObject has same function signature as CryptEncodeObject.
  3603. // CryptDllDecodeObject has same function signature as CryptDecodeObject.
  3604. // CryptDllEncodeObjectEx has same function signature as CryptEncodeObjectEx.
  3605. // The Ex version MUST support the CRYPT_ENCODE_ALLOC_FLAG option.
  3606. //
  3607. // If an Ex function isn't installed or registered, then, attempts to find
  3608. // a non-EX version. If the ALLOC flag is set, then, CryptEncodeObjectEx,
  3609. // does the allocation and calls the non-EX version twice.
  3610. // CryptDllDecodeObjectEx has same function signature as CryptDecodeObjectEx.
  3611. // The Ex version MUST support the CRYPT_DECODE_ALLOC_FLAG option.
  3612. //
  3613. // If an Ex function isn't installed or registered, then, attempts to find
  3614. // a non-EX version. If the ALLOC flag is set, then, CryptDecodeObjectEx,
  3615. // does the allocation and calls the non-EX version twice.
  3616. // CryptDllCreateCOMObject has the following signature:
  3617. // BOOL WINAPI CryptDllCreateCOMObject(
  3618. // IN DWORD dwEncodingType,
  3619. // IN LPCSTR pszOID,
  3620. // IN PCRYPT_DATA_BLOB pEncodedContent,
  3621. // IN DWORD dwFlags,
  3622. // IN REFIID riid,
  3623. // OUT void **ppvObj);
  3624. // CertDllVerifyRevocation has the same signature as CertVerifyRevocation
  3625. // (See CertVerifyRevocation for details on when called)
  3626. // CertDllVerifyCTLUsage has the same signature as CertVerifyCTLUsage
  3627. // CryptDllFindOIDInfo currently is only used to store values used by
  3628. // CryptFindOIDInfo. See CryptFindOIDInfo() for more details.
  3629. // CryptDllFindLocalizedName is only used to store localized string
  3630. // values used by CryptFindLocalizedName. See CryptFindLocalizedName() for
  3631. // more details.
  3632. // Example of a complete OID Function Registry Name:
  3633. // HKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography\OID
  3634. // Encoding Type 1\CryptDllEncodeObject\1.2.3
  3635. //
  3636. // The key's L"Dll" value contains the name of the Dll.
  3637. // The key's L"FuncName" value overrides the default function name
  3638. #define CRYPT_OID_REGPATH "Software\\Microsoft\\Cryptography\\OID"
  3639. #define CRYPT_OID_REG_ENCODING_TYPE_PREFIX "EncodingType "
  3640. #define CRYPT_OID_REG_DLL_VALUE_NAME L"Dll"
  3641. #define CRYPT_OID_REG_FUNC_NAME_VALUE_NAME L"FuncName"
  3642. #define CRYPT_OID_REG_FUNC_NAME_VALUE_NAME_A "FuncName"
  3643. // CRYPT_INSTALL_OID_FUNC_BEFORE_FLAG can be set in the key's L"CryptFlags"
  3644. // value to register the functions before the installed functions.
  3645. //
  3646. // CryptSetOIDFunctionValue must be called to set this value. L"CryptFlags"
  3647. // must be set using a dwValueType of REG_DWORD.
  3648. #define CRYPT_OID_REG_FLAGS_VALUE_NAME L"CryptFlags"
  3649. // OID used for Default OID functions
  3650. #define CRYPT_DEFAULT_OID "DEFAULT"
  3651. typedef struct _CRYPT_OID_FUNC_ENTRY {
  3652. LPCSTR pszOID;
  3653. void *pvFuncAddr;
  3654. } CRYPT_OID_FUNC_ENTRY, *PCRYPT_OID_FUNC_ENTRY;
  3655. #define CRYPT_INSTALL_OID_FUNC_BEFORE_FLAG 1
  3656. //+-------------------------------------------------------------------------
  3657. // Install a set of callable OID function addresses.
  3658. //
  3659. // By default the functions are installed at end of the list.
  3660. // Set CRYPT_INSTALL_OID_FUNC_BEFORE_FLAG to install at beginning of list.
  3661. //
  3662. // hModule should be updated with the hModule passed to DllMain to prevent
  3663. // the Dll containing the function addresses from being unloaded by
  3664. // CryptGetOIDFuncAddress/CryptFreeOIDFunctionAddress. This would be the
  3665. // case when the Dll has also regsvr32'ed OID functions via
  3666. // CryptRegisterOIDFunction.
  3667. //
  3668. // DEFAULT functions are installed by setting rgFuncEntry[].pszOID =
  3669. // CRYPT_DEFAULT_OID.
  3670. //--------------------------------------------------------------------------
  3671. WINCRYPT32API
  3672. BOOL
  3673. WINAPI
  3674. CryptInstallOIDFunctionAddress(
  3675. IN HMODULE hModule, // hModule passed to DllMain
  3676. IN DWORD dwEncodingType,
  3677. IN LPCSTR pszFuncName,
  3678. IN DWORD cFuncEntry,
  3679. IN const CRYPT_OID_FUNC_ENTRY rgFuncEntry[],
  3680. IN DWORD dwFlags
  3681. );
  3682. //+-------------------------------------------------------------------------
  3683. // Initialize and return handle to the OID function set identified by its
  3684. // function name.
  3685. //
  3686. // If the set already exists, a handle to the existing set is returned.
  3687. //--------------------------------------------------------------------------
  3688. WINCRYPT32API
  3689. HCRYPTOIDFUNCSET
  3690. WINAPI
  3691. CryptInitOIDFunctionSet(
  3692. IN LPCSTR pszFuncName,
  3693. IN DWORD dwFlags
  3694. );
  3695. //+-------------------------------------------------------------------------
  3696. // Search the list of installed functions for an encoding type and OID match.
  3697. // If not found, search the registry.
  3698. //
  3699. // For success, returns TRUE with *ppvFuncAddr updated with the function's
  3700. // address and *phFuncAddr updated with the function address's handle.
  3701. // The function's handle is AddRef'ed. CryptFreeOIDFunctionAddress needs to
  3702. // be called to release it.
  3703. //
  3704. // For a registry match, the Dll containing the function is loaded.
  3705. //
  3706. // By default, both the registered and installed function lists are searched.
  3707. // Set CRYPT_GET_INSTALLED_OID_FUNC_FLAG to only search the installed list
  3708. // of functions. This flag would be set by a registered function to get
  3709. // the address of a pre-installed function it was replacing. For example,
  3710. // the registered function might handle a new special case and call the
  3711. // pre-installed function to handle the remaining cases.
  3712. //--------------------------------------------------------------------------
  3713. WINCRYPT32API
  3714. BOOL
  3715. WINAPI
  3716. CryptGetOIDFunctionAddress(
  3717. IN HCRYPTOIDFUNCSET hFuncSet,
  3718. IN DWORD dwEncodingType,
  3719. IN LPCSTR pszOID,
  3720. IN DWORD dwFlags,
  3721. OUT void **ppvFuncAddr,
  3722. OUT HCRYPTOIDFUNCADDR *phFuncAddr
  3723. );
  3724. #define CRYPT_GET_INSTALLED_OID_FUNC_FLAG 0x1
  3725. //+-------------------------------------------------------------------------
  3726. // Get the list of registered default Dll entries for the specified
  3727. // function set and encoding type.
  3728. //
  3729. // The returned list consists of none, one or more null terminated Dll file
  3730. // names. The list is terminated with an empty (L"\0") Dll file name.
  3731. // For example: L"first.dll" L"\0" L"second.dll" L"\0" L"\0"
  3732. //--------------------------------------------------------------------------
  3733. WINCRYPT32API
  3734. BOOL
  3735. WINAPI
  3736. CryptGetDefaultOIDDllList(
  3737. IN HCRYPTOIDFUNCSET hFuncSet,
  3738. IN DWORD dwEncodingType,
  3739. OUT LPWSTR pwszDllList,
  3740. IN OUT DWORD *pcchDllList
  3741. );
  3742. //+-------------------------------------------------------------------------
  3743. // Either: get the first or next installed DEFAULT function OR
  3744. // load the Dll containing the DEFAULT function.
  3745. //
  3746. // If pwszDll is NULL, search the list of installed DEFAULT functions.
  3747. // *phFuncAddr must be set to NULL to get the first installed function.
  3748. // Successive installed functions are returned by setting *phFuncAddr
  3749. // to the hFuncAddr returned by the previous call.
  3750. //
  3751. // If pwszDll is NULL, the input *phFuncAddr
  3752. // is always CryptFreeOIDFunctionAddress'ed by this function, even for
  3753. // an error.
  3754. //
  3755. // If pwszDll isn't NULL, then, attempts to load the Dll and the DEFAULT
  3756. // function. *phFuncAddr is ignored upon entry and isn't
  3757. // CryptFreeOIDFunctionAddress'ed.
  3758. //
  3759. // For success, returns TRUE with *ppvFuncAddr updated with the function's
  3760. // address and *phFuncAddr updated with the function address's handle.
  3761. // The function's handle is AddRef'ed. CryptFreeOIDFunctionAddress needs to
  3762. // be called to release it or CryptGetDefaultOIDFunctionAddress can also
  3763. // be called for a NULL pwszDll.
  3764. //--------------------------------------------------------------------------
  3765. WINCRYPT32API
  3766. BOOL
  3767. WINAPI
  3768. CryptGetDefaultOIDFunctionAddress(
  3769. IN HCRYPTOIDFUNCSET hFuncSet,
  3770. IN DWORD dwEncodingType,
  3771. IN OPTIONAL LPCWSTR pwszDll,
  3772. IN DWORD dwFlags,
  3773. OUT void **ppvFuncAddr,
  3774. IN OUT HCRYPTOIDFUNCADDR *phFuncAddr
  3775. );
  3776. //+-------------------------------------------------------------------------
  3777. // Releases the handle AddRef'ed and returned by CryptGetOIDFunctionAddress
  3778. // or CryptGetDefaultOIDFunctionAddress.
  3779. //
  3780. // If a Dll was loaded for the function its unloaded. However, before doing
  3781. // the unload, the DllCanUnloadNow function exported by the loaded Dll is
  3782. // called. It should return S_FALSE to inhibit the unload or S_TRUE to enable
  3783. // the unload. If the Dll doesn't export DllCanUnloadNow, the Dll is unloaded.
  3784. //
  3785. // DllCanUnloadNow has the following signature:
  3786. // STDAPI DllCanUnloadNow(void);
  3787. //--------------------------------------------------------------------------
  3788. WINCRYPT32API
  3789. BOOL
  3790. WINAPI
  3791. CryptFreeOIDFunctionAddress(
  3792. IN HCRYPTOIDFUNCADDR hFuncAddr,
  3793. IN DWORD dwFlags
  3794. );
  3795. //+-------------------------------------------------------------------------
  3796. // Register the Dll containing the function to be called for the specified
  3797. // encoding type, function name and OID.
  3798. //
  3799. // pwszDll may contain environment-variable strings
  3800. // which are ExpandEnvironmentStrings()'ed before loading the Dll.
  3801. //
  3802. // In addition to registering the DLL, you may override the
  3803. // name of the function to be called. For example,
  3804. // pszFuncName = "CryptDllEncodeObject",
  3805. // pszOverrideFuncName = "MyEncodeXyz".
  3806. // This allows a Dll to export multiple OID functions for the same
  3807. // function name without needing to interpose its own OID dispatcher function.
  3808. //--------------------------------------------------------------------------
  3809. WINCRYPT32API
  3810. BOOL
  3811. WINAPI
  3812. CryptRegisterOIDFunction(
  3813. IN DWORD dwEncodingType,
  3814. IN LPCSTR pszFuncName,
  3815. IN LPCSTR pszOID,
  3816. IN OPTIONAL LPCWSTR pwszDll,
  3817. IN OPTIONAL LPCSTR pszOverrideFuncName
  3818. );
  3819. //+-------------------------------------------------------------------------
  3820. // Unregister the Dll containing the function to be called for the specified
  3821. // encoding type, function name and OID.
  3822. //--------------------------------------------------------------------------
  3823. WINCRYPT32API
  3824. BOOL
  3825. WINAPI
  3826. CryptUnregisterOIDFunction(
  3827. IN DWORD dwEncodingType,
  3828. IN LPCSTR pszFuncName,
  3829. IN LPCSTR pszOID
  3830. );
  3831. //+-------------------------------------------------------------------------
  3832. // Register the Dll containing the default function to be called for the
  3833. // specified encoding type and function name.
  3834. //
  3835. // Unlike CryptRegisterOIDFunction, you can't override the function name
  3836. // needing to be exported by the Dll.
  3837. //
  3838. // The Dll is inserted before the entry specified by dwIndex.
  3839. // dwIndex == 0, inserts at the beginning.
  3840. // dwIndex == CRYPT_REGISTER_LAST_INDEX, appends at the end.
  3841. //
  3842. // pwszDll may contain environment-variable strings
  3843. // which are ExpandEnvironmentStrings()'ed before loading the Dll.
  3844. //--------------------------------------------------------------------------
  3845. WINCRYPT32API
  3846. BOOL
  3847. WINAPI
  3848. CryptRegisterDefaultOIDFunction(
  3849. IN DWORD dwEncodingType,
  3850. IN LPCSTR pszFuncName,
  3851. IN DWORD dwIndex,
  3852. IN LPCWSTR pwszDll
  3853. );
  3854. #define CRYPT_REGISTER_FIRST_INDEX 0
  3855. #define CRYPT_REGISTER_LAST_INDEX 0xFFFFFFFF
  3856. //+-------------------------------------------------------------------------
  3857. // Unregister the Dll containing the default function to be called for
  3858. // the specified encoding type and function name.
  3859. //--------------------------------------------------------------------------
  3860. WINCRYPT32API
  3861. BOOL
  3862. WINAPI
  3863. CryptUnregisterDefaultOIDFunction(
  3864. IN DWORD dwEncodingType,
  3865. IN LPCSTR pszFuncName,
  3866. IN LPCWSTR pwszDll
  3867. );
  3868. //+-------------------------------------------------------------------------
  3869. // Set the value for the specified encoding type, function name, OID and
  3870. // value name.
  3871. //
  3872. // See RegSetValueEx for the possible value types.
  3873. //
  3874. // String types are UNICODE.
  3875. //--------------------------------------------------------------------------
  3876. WINCRYPT32API
  3877. BOOL
  3878. WINAPI
  3879. CryptSetOIDFunctionValue(
  3880. IN DWORD dwEncodingType,
  3881. IN LPCSTR pszFuncName,
  3882. IN LPCSTR pszOID,
  3883. IN LPCWSTR pwszValueName,
  3884. IN DWORD dwValueType,
  3885. IN const BYTE *pbValueData,
  3886. IN DWORD cbValueData
  3887. );
  3888. //+-------------------------------------------------------------------------
  3889. // Get the value for the specified encoding type, function name, OID and
  3890. // value name.
  3891. //
  3892. // See RegEnumValue for the possible value types.
  3893. //
  3894. // String types are UNICODE.
  3895. //--------------------------------------------------------------------------
  3896. WINCRYPT32API
  3897. BOOL
  3898. WINAPI
  3899. CryptGetOIDFunctionValue(
  3900. IN DWORD dwEncodingType,
  3901. IN LPCSTR pszFuncName,
  3902. IN LPCSTR pszOID,
  3903. IN LPCWSTR pwszValueName,
  3904. OUT DWORD *pdwValueType,
  3905. OUT BYTE *pbValueData,
  3906. IN OUT DWORD *pcbValueData
  3907. );
  3908. typedef BOOL (WINAPI *PFN_CRYPT_ENUM_OID_FUNC)(
  3909. IN DWORD dwEncodingType,
  3910. IN LPCSTR pszFuncName,
  3911. IN LPCSTR pszOID,
  3912. IN DWORD cValue,
  3913. IN const DWORD rgdwValueType[],
  3914. IN LPCWSTR const rgpwszValueName[],
  3915. IN const BYTE * const rgpbValueData[],
  3916. IN const DWORD rgcbValueData[],
  3917. IN void *pvArg
  3918. );
  3919. //+-------------------------------------------------------------------------
  3920. // Enumerate the OID functions identified by their encoding type,
  3921. // function name and OID.
  3922. //
  3923. // pfnEnumOIDFunc is called for each registry key matching the input
  3924. // parameters. Setting dwEncodingType to CRYPT_MATCH_ANY_ENCODING_TYPE matches
  3925. // any. Setting pszFuncName or pszOID to NULL matches any.
  3926. //
  3927. // Set pszOID == CRYPT_DEFAULT_OID to restrict the enumeration to only the
  3928. // DEFAULT functions
  3929. //
  3930. // String types are UNICODE.
  3931. //--------------------------------------------------------------------------
  3932. WINCRYPT32API
  3933. BOOL
  3934. WINAPI
  3935. CryptEnumOIDFunction(
  3936. IN DWORD dwEncodingType,
  3937. IN OPTIONAL LPCSTR pszFuncName,
  3938. IN OPTIONAL LPCSTR pszOID,
  3939. IN DWORD dwFlags,
  3940. IN void *pvArg,
  3941. IN PFN_CRYPT_ENUM_OID_FUNC pfnEnumOIDFunc
  3942. );
  3943. #define CRYPT_MATCH_ANY_ENCODING_TYPE 0xFFFFFFFF
  3944. //+=========================================================================
  3945. // Object IDentifier (OID) Information: Data Structures and APIs
  3946. //==========================================================================
  3947. //+-------------------------------------------------------------------------
  3948. // OID Information
  3949. //--------------------------------------------------------------------------
  3950. typedef struct _CRYPT_OID_INFO {
  3951. DWORD cbSize;
  3952. LPCSTR pszOID;
  3953. LPCWSTR pwszName;
  3954. DWORD dwGroupId;
  3955. union {
  3956. DWORD dwValue;
  3957. ALG_ID Algid;
  3958. DWORD dwLength;
  3959. };
  3960. CRYPT_DATA_BLOB ExtraInfo;
  3961. } CRYPT_OID_INFO, *PCRYPT_OID_INFO;
  3962. typedef const CRYPT_OID_INFO CCRYPT_OID_INFO, *PCCRYPT_OID_INFO;
  3963. //+-------------------------------------------------------------------------
  3964. // OID Group IDs
  3965. //--------------------------------------------------------------------------
  3966. #define CRYPT_HASH_ALG_OID_GROUP_ID 1
  3967. #define CRYPT_ENCRYPT_ALG_OID_GROUP_ID 2
  3968. #define CRYPT_PUBKEY_ALG_OID_GROUP_ID 3
  3969. #define CRYPT_SIGN_ALG_OID_GROUP_ID 4
  3970. #define CRYPT_RDN_ATTR_OID_GROUP_ID 5
  3971. #define CRYPT_EXT_OR_ATTR_OID_GROUP_ID 6
  3972. #define CRYPT_ENHKEY_USAGE_OID_GROUP_ID 7
  3973. #define CRYPT_POLICY_OID_GROUP_ID 8
  3974. #define CRYPT_TEMPLATE_OID_GROUP_ID 9
  3975. #define CRYPT_LAST_OID_GROUP_ID 9
  3976. #define CRYPT_FIRST_ALG_OID_GROUP_ID CRYPT_HASH_ALG_OID_GROUP_ID
  3977. #define CRYPT_LAST_ALG_OID_GROUP_ID CRYPT_SIGN_ALG_OID_GROUP_ID
  3978. // The CRYPT_*_ALG_OID_GROUP_ID's have an Algid. The CRYPT_RDN_ATTR_OID_GROUP_ID
  3979. // has a dwLength. The CRYPT_EXT_OR_ATTR_OID_GROUP_ID,
  3980. // CRYPT_ENHKEY_USAGE_OID_GROUP_ID, CRYPT_POLICY_OID_GROUP_ID or
  3981. // CRYPT_TEMPLATE_OID_GROUP_ID don't have a dwValue.
  3982. //
  3983. // CRYPT_PUBKEY_ALG_OID_GROUP_ID has the following optional ExtraInfo:
  3984. // DWORD[0] - Flags. CRYPT_OID_INHIBIT_SIGNATURE_FORMAT_FLAG can be set to
  3985. // inhibit the reformatting of the signature before
  3986. // CryptVerifySignature is called or after CryptSignHash
  3987. // is called. CRYPT_OID_USE_PUBKEY_PARA_FOR_PKCS7_FLAG can
  3988. // be set to include the public key algorithm's parameters
  3989. // in the PKCS7's digestEncryptionAlgorithm's parameters.
  3990. // CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG can be set to omit
  3991. // NULL parameters when encoding.
  3992. #define CRYPT_OID_INHIBIT_SIGNATURE_FORMAT_FLAG 0x1
  3993. #define CRYPT_OID_USE_PUBKEY_PARA_FOR_PKCS7_FLAG 0x2
  3994. #define CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG 0x4
  3995. // CRYPT_SIGN_ALG_OID_GROUP_ID has the following optional ExtraInfo:
  3996. // DWORD[0] - Public Key Algid.
  3997. // DWORD[1] - Flags. Same as above for CRYPT_PUBKEY_ALG_OID_GROUP_ID.
  3998. // DWORD[2] - Optional CryptAcquireContext(CRYPT_VERIFYCONTEXT)'s dwProvType.
  3999. // If omitted or 0, uses Public Key Algid to select
  4000. // appropriate dwProvType for signature verification.
  4001. // CRYPT_RDN_ATTR_OID_GROUP_ID has the following optional ExtraInfo:
  4002. // Array of DWORDs:
  4003. // [0 ..] - Null terminated list of acceptable RDN attribute
  4004. // value types. An empty list implies CERT_RDN_PRINTABLE_STRING,
  4005. // CERT_RDN_UNICODE_STRING, 0.
  4006. //+-------------------------------------------------------------------------
  4007. // Find OID information. Returns NULL if unable to find any information
  4008. // for the specified key and group. Note, returns a pointer to a constant
  4009. // data structure. The returned pointer MUST NOT be freed.
  4010. //
  4011. // dwKeyType's:
  4012. // CRYPT_OID_INFO_OID_KEY, pvKey points to a szOID
  4013. // CRYPT_OID_INFO_NAME_KEY, pvKey points to a wszName
  4014. // CRYPT_OID_INFO_ALGID_KEY, pvKey points to an ALG_ID
  4015. // CRYPT_OID_INFO_SIGN_KEY, pvKey points to an array of two ALG_ID's:
  4016. // ALG_ID[0] - Hash Algid
  4017. // ALG_ID[1] - PubKey Algid
  4018. //
  4019. // Setting dwGroupId to 0, searches all groups according to the dwKeyType.
  4020. // Otherwise, only the dwGroupId is searched.
  4021. //--------------------------------------------------------------------------
  4022. WINCRYPT32API
  4023. PCCRYPT_OID_INFO
  4024. WINAPI
  4025. CryptFindOIDInfo(
  4026. IN DWORD dwKeyType,
  4027. IN void *pvKey,
  4028. IN DWORD dwGroupId
  4029. );
  4030. #define CRYPT_OID_INFO_OID_KEY 1
  4031. #define CRYPT_OID_INFO_NAME_KEY 2
  4032. #define CRYPT_OID_INFO_ALGID_KEY 3
  4033. #define CRYPT_OID_INFO_SIGN_KEY 4
  4034. //+-------------------------------------------------------------------------
  4035. // Register OID information. The OID information specified in the
  4036. // CCRYPT_OID_INFO structure is persisted to the registry.
  4037. //
  4038. // crypt32.dll contains information for the commonly known OIDs. This function
  4039. // allows applications to augment crypt32.dll's OID information. During
  4040. // CryptFindOIDInfo's first call, the registered OID information is installed.
  4041. //
  4042. // By default the registered OID information is installed after crypt32.dll's
  4043. // OID entries. Set CRYPT_INSTALL_OID_INFO_BEFORE_FLAG to install before.
  4044. //--------------------------------------------------------------------------
  4045. WINCRYPT32API
  4046. BOOL
  4047. WINAPI
  4048. CryptRegisterOIDInfo(
  4049. IN PCCRYPT_OID_INFO pInfo,
  4050. IN DWORD dwFlags
  4051. );
  4052. #define CRYPT_INSTALL_OID_INFO_BEFORE_FLAG 1
  4053. //+-------------------------------------------------------------------------
  4054. // Unregister OID information. Only the pszOID and dwGroupId fields are
  4055. // used to identify the OID information to be unregistered.
  4056. //--------------------------------------------------------------------------
  4057. WINCRYPT32API
  4058. BOOL
  4059. WINAPI
  4060. CryptUnregisterOIDInfo(
  4061. IN PCCRYPT_OID_INFO pInfo
  4062. );
  4063. // If the callback returns FALSE, stops the enumeration.
  4064. typedef BOOL (WINAPI *PFN_CRYPT_ENUM_OID_INFO)(
  4065. IN PCCRYPT_OID_INFO pInfo,
  4066. IN void *pvArg
  4067. );
  4068. //+-------------------------------------------------------------------------
  4069. // Enumerate the OID information.
  4070. //
  4071. // pfnEnumOIDInfo is called for each OID information entry.
  4072. //
  4073. // Setting dwGroupId to 0 matches all groups. Otherwise, only enumerates
  4074. // entries in the specified group.
  4075. //
  4076. // dwFlags currently isn't used and must be set to 0.
  4077. //--------------------------------------------------------------------------
  4078. WINCRYPT32API
  4079. BOOL
  4080. WINAPI
  4081. CryptEnumOIDInfo(
  4082. IN DWORD dwGroupId,
  4083. IN DWORD dwFlags,
  4084. IN void *pvArg,
  4085. IN PFN_CRYPT_ENUM_OID_INFO pfnEnumOIDInfo
  4086. );
  4087. //+-------------------------------------------------------------------------
  4088. // Find the localized name for the specified name. For example, find the
  4089. // localized name for the "Root" system store name. A case insensitive
  4090. // string comparison is done.
  4091. //
  4092. // Returns NULL if unable to find the the specified name.
  4093. //
  4094. // Localized names for the predefined system stores ("Root", "My") and
  4095. // predefined physical stores (".Default", ".LocalMachine") are pre-installed
  4096. // as resource strings in crypt32.dll. CryptSetOIDFunctionValue can be called
  4097. // as follows to register additional localized strings:
  4098. // dwEncodingType = CRYPT_LOCALIZED_NAME_ENCODING_TYPE
  4099. // pszFuncName = CRYPT_OID_FIND_LOCALIZED_NAME_FUNC
  4100. // pszOID = CRYPT_LOCALIZED_NAME_OID
  4101. // pwszValueName = Name to be localized, for example, L"ApplicationStore"
  4102. // dwValueType = REG_SZ
  4103. // pbValueData = pointer to the UNICODE localized string
  4104. // cbValueData = (wcslen(UNICODE localized string) + 1) * sizeof(WCHAR)
  4105. //
  4106. // To unregister, set pbValueData to NULL and cbValueData to 0.
  4107. //
  4108. // The registered names are searched before the pre-installed names.
  4109. //--------------------------------------------------------------------------
  4110. WINCRYPT32API
  4111. LPCWSTR
  4112. WINAPI
  4113. CryptFindLocalizedName(
  4114. IN LPCWSTR pwszCryptName
  4115. );
  4116. #define CRYPT_LOCALIZED_NAME_ENCODING_TYPE 0
  4117. #define CRYPT_LOCALIZED_NAME_OID "LocalizedNames"
  4118. //+=========================================================================
  4119. // Low Level Cryptographic Message Data Structures and APIs
  4120. //==========================================================================
  4121. typedef void *HCRYPTMSG;
  4122. #define szOID_PKCS_7_DATA "1.2.840.113549.1.7.1"
  4123. #define szOID_PKCS_7_SIGNED "1.2.840.113549.1.7.2"
  4124. #define szOID_PKCS_7_ENVELOPED "1.2.840.113549.1.7.3"
  4125. #define szOID_PKCS_7_SIGNEDANDENVELOPED "1.2.840.113549.1.7.4"
  4126. #define szOID_PKCS_7_DIGESTED "1.2.840.113549.1.7.5"
  4127. #define szOID_PKCS_7_ENCRYPTED "1.2.840.113549.1.7.6"
  4128. #define szOID_PKCS_9_CONTENT_TYPE "1.2.840.113549.1.9.3"
  4129. #define szOID_PKCS_9_MESSAGE_DIGEST "1.2.840.113549.1.9.4"
  4130. //+-------------------------------------------------------------------------
  4131. // Message types
  4132. //--------------------------------------------------------------------------
  4133. #define CMSG_DATA 1
  4134. #define CMSG_SIGNED 2
  4135. #define CMSG_ENVELOPED 3
  4136. #define CMSG_SIGNED_AND_ENVELOPED 4
  4137. #define CMSG_HASHED 5
  4138. #define CMSG_ENCRYPTED 6
  4139. //+-------------------------------------------------------------------------
  4140. // Message Type Bit Flags
  4141. //--------------------------------------------------------------------------
  4142. #define CMSG_ALL_FLAGS (~0UL)
  4143. #define CMSG_DATA_FLAG (1 << CMSG_DATA)
  4144. #define CMSG_SIGNED_FLAG (1 << CMSG_SIGNED)
  4145. #define CMSG_ENVELOPED_FLAG (1 << CMSG_ENVELOPED)
  4146. #define CMSG_SIGNED_AND_ENVELOPED_FLAG (1 << CMSG_SIGNED_AND_ENVELOPED)
  4147. #define CMSG_HASHED_FLAG (1 << CMSG_HASHED)
  4148. #define CMSG_ENCRYPTED_FLAG (1 << CMSG_ENCRYPTED)
  4149. //+-------------------------------------------------------------------------
  4150. // Certificate Issuer and SerialNumber
  4151. //--------------------------------------------------------------------------
  4152. typedef struct _CERT_ISSUER_SERIAL_NUMBER {
  4153. CERT_NAME_BLOB Issuer;
  4154. CRYPT_INTEGER_BLOB SerialNumber;
  4155. } CERT_ISSUER_SERIAL_NUMBER, *PCERT_ISSUER_SERIAL_NUMBER;
  4156. //+-------------------------------------------------------------------------
  4157. // Certificate Identifier
  4158. //--------------------------------------------------------------------------
  4159. typedef struct _CERT_ID {
  4160. DWORD dwIdChoice;
  4161. union {
  4162. // CERT_ID_ISSUER_SERIAL_NUMBER
  4163. CERT_ISSUER_SERIAL_NUMBER IssuerSerialNumber;
  4164. // CERT_ID_KEY_IDENTIFIER
  4165. CRYPT_HASH_BLOB KeyId;
  4166. // CERT_ID_SHA1_HASH
  4167. CRYPT_HASH_BLOB HashId;
  4168. };
  4169. } CERT_ID, *PCERT_ID;
  4170. #define CERT_ID_ISSUER_SERIAL_NUMBER 1
  4171. #define CERT_ID_KEY_IDENTIFIER 2
  4172. #define CERT_ID_SHA1_HASH 3
  4173. //+-------------------------------------------------------------------------
  4174. // The message encode information (pvMsgEncodeInfo) is message type dependent
  4175. //--------------------------------------------------------------------------
  4176. //+-------------------------------------------------------------------------
  4177. // CMSG_DATA: pvMsgEncodeInfo = NULL
  4178. //--------------------------------------------------------------------------
  4179. //+-------------------------------------------------------------------------
  4180. // CMSG_SIGNED
  4181. //
  4182. // The pCertInfo in the CMSG_SIGNER_ENCODE_INFO provides the Issuer, SerialNumber
  4183. // and PublicKeyInfo.Algorithm. The PublicKeyInfo.Algorithm implicitly
  4184. // specifies the HashEncryptionAlgorithm to be used.
  4185. //
  4186. // If the SignerId is present with a nonzero dwIdChoice its used instead
  4187. // of the Issuer and SerialNumber in pCertInfo.
  4188. //
  4189. // CMS supports the KEY_IDENTIFIER and ISSUER_SERIAL_NUMBER CERT_IDs. PKCS #7
  4190. // version 1.5 only supports the ISSUER_SERIAL_NUMBER CERT_ID choice.
  4191. //
  4192. // If HashEncryptionAlgorithm is present and not NULL its used instead of
  4193. // the PublicKeyInfo.Algorithm.
  4194. //
  4195. // Note, for RSA, the hash encryption algorithm is normally the same as
  4196. // the public key algorithm. For DSA, the hash encryption algorithm is
  4197. // normally a DSS signature algorithm.
  4198. //
  4199. // pvHashEncryptionAuxInfo currently isn't used and must be set to NULL if
  4200. // present in the data structure.
  4201. //
  4202. // The hCryptProv and dwKeySpec specify the private key to use. If dwKeySpec
  4203. // == 0, then, defaults to AT_SIGNATURE.
  4204. //
  4205. // If the HashEncryptionAlgorithm is set to szOID_PKIX_NO_SIGNATURE, then,
  4206. // the signature value only contains the hash octets. hCryptProv must still
  4207. // be specified. However, since a private key isn't used the hCryptProv can be
  4208. // acquired using CRYPT_VERIFYCONTEXT.
  4209. //
  4210. // If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  4211. // passed to CryptMsgOpenToEncode(), the signer hCryptProv's are released.
  4212. //
  4213. // pvHashAuxInfo currently isn't used and must be set to NULL.
  4214. //
  4215. // CMS signed messages allow the inclusion of Attribute Certs.
  4216. //--------------------------------------------------------------------------
  4217. typedef struct _CMSG_SIGNER_ENCODE_INFO {
  4218. DWORD cbSize;
  4219. PCERT_INFO pCertInfo;
  4220. HCRYPTPROV hCryptProv;
  4221. DWORD dwKeySpec;
  4222. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  4223. void *pvHashAuxInfo;
  4224. DWORD cAuthAttr;
  4225. PCRYPT_ATTRIBUTE rgAuthAttr;
  4226. DWORD cUnauthAttr;
  4227. PCRYPT_ATTRIBUTE rgUnauthAttr;
  4228. #ifdef CMSG_SIGNER_ENCODE_INFO_HAS_CMS_FIELDS
  4229. CERT_ID SignerId;
  4230. CRYPT_ALGORITHM_IDENTIFIER HashEncryptionAlgorithm;
  4231. void *pvHashEncryptionAuxInfo;
  4232. #endif
  4233. } CMSG_SIGNER_ENCODE_INFO, *PCMSG_SIGNER_ENCODE_INFO;
  4234. typedef struct _CMSG_SIGNED_ENCODE_INFO {
  4235. DWORD cbSize;
  4236. DWORD cSigners;
  4237. PCMSG_SIGNER_ENCODE_INFO rgSigners;
  4238. DWORD cCertEncoded;
  4239. PCERT_BLOB rgCertEncoded;
  4240. DWORD cCrlEncoded;
  4241. PCRL_BLOB rgCrlEncoded;
  4242. #ifdef CMSG_SIGNED_ENCODE_INFO_HAS_CMS_FIELDS
  4243. DWORD cAttrCertEncoded;
  4244. PCERT_BLOB rgAttrCertEncoded;
  4245. #endif
  4246. } CMSG_SIGNED_ENCODE_INFO, *PCMSG_SIGNED_ENCODE_INFO;
  4247. //+-------------------------------------------------------------------------
  4248. // CMSG_ENVELOPED
  4249. //
  4250. // The PCERT_INFO for the rgRecipients provides the Issuer, SerialNumber
  4251. // and PublicKeyInfo. The PublicKeyInfo.Algorithm implicitly
  4252. // specifies the KeyEncryptionAlgorithm to be used.
  4253. //
  4254. // The PublicKeyInfo.PublicKey in PCERT_INFO is used to encrypt the content
  4255. // encryption key for the recipient.
  4256. //
  4257. // hCryptProv is used to do the content encryption, recipient key encryption
  4258. // and export. The hCryptProv's private keys aren't used. If hCryptProv
  4259. // is NULL, a default hCryptProv is chosen according to the
  4260. // ContentEncryptionAlgorithm and the first recipient KeyEncryptionAlgorithm.
  4261. //
  4262. // If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  4263. // passed to CryptMsgOpenToEncode(), the envelope's hCryptProv is released.
  4264. //
  4265. // Note: CAPI currently doesn't support more than one KeyEncryptionAlgorithm
  4266. // per provider. This will need to be fixed.
  4267. //
  4268. // Currently, pvEncryptionAuxInfo is only defined for RC2 or RC4 encryption
  4269. // algorithms. Otherwise, its not used and must be set to NULL.
  4270. // See CMSG_RC2_AUX_INFO for the RC2 encryption algorithms.
  4271. // See CMSG_RC4_AUX_INFO for the RC4 encryption algorithms.
  4272. //
  4273. // To enable SP3 compatible encryption, pvEncryptionAuxInfo should point to
  4274. // a CMSG_SP3_COMPATIBLE_AUX_INFO data structure.
  4275. //
  4276. // To enable the CMS envelope enhancements, rgpRecipients must be set to
  4277. // NULL, and rgCmsRecipients updated to point to an array of
  4278. // CMSG_RECIPIENT_ENCODE_INFO's.
  4279. //
  4280. // Also, CMS envelope enhancements support the inclusion of a bag of
  4281. // Certs, CRLs, Attribute Certs and/or Unprotected Attributes.
  4282. //--------------------------------------------------------------------------
  4283. typedef struct _CMSG_RECIPIENT_ENCODE_INFO CMSG_RECIPIENT_ENCODE_INFO,
  4284. *PCMSG_RECIPIENT_ENCODE_INFO;
  4285. typedef struct _CMSG_ENVELOPED_ENCODE_INFO {
  4286. DWORD cbSize;
  4287. HCRYPTPROV hCryptProv;
  4288. CRYPT_ALGORITHM_IDENTIFIER ContentEncryptionAlgorithm;
  4289. void *pvEncryptionAuxInfo;
  4290. DWORD cRecipients;
  4291. // The following array may only be used for transport recipients identified
  4292. // by their IssuereAndSerialNumber. If rgpRecipients != NULL, then,
  4293. // the rgCmsRecipients must be NULL.
  4294. PCERT_INFO *rgpRecipients;
  4295. #ifdef CMSG_ENVELOPED_ENCODE_INFO_HAS_CMS_FIELDS
  4296. // If rgCmsRecipients != NULL, then, the above rgpRecipients must be
  4297. // NULL.
  4298. PCMSG_RECIPIENT_ENCODE_INFO rgCmsRecipients;
  4299. DWORD cCertEncoded;
  4300. PCERT_BLOB rgCertEncoded;
  4301. DWORD cCrlEncoded;
  4302. PCRL_BLOB rgCrlEncoded;
  4303. DWORD cAttrCertEncoded;
  4304. PCERT_BLOB rgAttrCertEncoded;
  4305. DWORD cUnprotectedAttr;
  4306. PCRYPT_ATTRIBUTE rgUnprotectedAttr;
  4307. #endif
  4308. } CMSG_ENVELOPED_ENCODE_INFO, *PCMSG_ENVELOPED_ENCODE_INFO;
  4309. //+-------------------------------------------------------------------------
  4310. // Key Transport Recipient Encode Info
  4311. //
  4312. // hCryptProv is used to do the recipient key encryption
  4313. // and export. The hCryptProv's private keys aren't used.
  4314. //
  4315. // If hCryptProv is NULL, then, the hCryptProv specified in
  4316. // CMSG_ENVELOPED_ENCODE_INFO is used.
  4317. //
  4318. // Note, even if CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  4319. // passed to CryptMsgOpenToEncode(), this hCryptProv isn't released.
  4320. //
  4321. // CMS supports the KEY_IDENTIFIER and ISSUER_SERIAL_NUMBER CERT_IDs. PKCS #7
  4322. // version 1.5 only supports the ISSUER_SERIAL_NUMBER CERT_ID choice.
  4323. //--------------------------------------------------------------------------
  4324. typedef struct _CMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO {
  4325. DWORD cbSize;
  4326. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  4327. void *pvKeyEncryptionAuxInfo;
  4328. HCRYPTPROV hCryptProv;
  4329. CRYPT_BIT_BLOB RecipientPublicKey;
  4330. CERT_ID RecipientId;
  4331. } CMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO, *PCMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO;
  4332. //+-------------------------------------------------------------------------
  4333. // Key Agreement Recipient Encode Info
  4334. //
  4335. // If hCryptProv is NULL, then, the hCryptProv specified in
  4336. // CMSG_ENVELOPED_ENCODE_INFO is used.
  4337. //
  4338. // For the CMSG_KEY_AGREE_STATIC_KEY_CHOICE, both the hCryptProv and
  4339. // dwKeySpec must be specified to select the sender's private key.
  4340. //
  4341. // Note, even if CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  4342. // passed to CryptMsgOpenToEncode(), this hCryptProv isn't released.
  4343. //
  4344. // CMS supports the KEY_IDENTIFIER and ISSUER_SERIAL_NUMBER CERT_IDs.
  4345. //
  4346. // There is 1 key choice, ephemeral originator. The originator's ephemeral
  4347. // key is generated using the public key algorithm parameters shared
  4348. // amongst all the recipients.
  4349. //
  4350. // There are 2 key choices: ephemeral originator or static sender. The
  4351. // originator's ephemeral key is generated using the public key algorithm
  4352. // parameters shared amongst all the recipients. For the static sender its
  4353. // private key is used. The hCryptProv and dwKeySpec specify the private key.
  4354. // The pSenderId identifies the certificate containing the sender's public key.
  4355. //
  4356. // Currently, pvKeyEncryptionAuxInfo isn't used and must be set to NULL.
  4357. //
  4358. // If KeyEncryptionAlgorithm.Parameters.cbData == 0, then, its Parameters
  4359. // are updated with the encoded KeyWrapAlgorithm.
  4360. //
  4361. // Currently, pvKeyWrapAuxInfo is only defined for algorithms with
  4362. // RC2. Otherwise, its not used and must be set to NULL.
  4363. // When set for RC2 algorithms, points to a CMSG_RC2_AUX_INFO containing
  4364. // the RC2 effective key length.
  4365. //
  4366. // Note, key agreement recipients are not supported in PKCS #7 version 1.5.
  4367. //--------------------------------------------------------------------------
  4368. typedef struct _CMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO {
  4369. DWORD cbSize;
  4370. CRYPT_BIT_BLOB RecipientPublicKey;
  4371. CERT_ID RecipientId;
  4372. // Following fields are optional and only applicable to KEY_IDENTIFIER
  4373. // CERT_IDs.
  4374. FILETIME Date;
  4375. PCRYPT_ATTRIBUTE_TYPE_VALUE pOtherAttr;
  4376. } CMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO,
  4377. *PCMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO;
  4378. typedef struct _CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO {
  4379. DWORD cbSize;
  4380. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  4381. void *pvKeyEncryptionAuxInfo;
  4382. CRYPT_ALGORITHM_IDENTIFIER KeyWrapAlgorithm;
  4383. void *pvKeyWrapAuxInfo;
  4384. // The following hCryptProv and dwKeySpec must be specified for the
  4385. // CMSG_KEY_AGREE_STATIC_KEY_CHOICE.
  4386. //
  4387. // For CMSG_KEY_AGREE_EPHEMERAL_KEY_CHOICE, dwKeySpec isn't applicable
  4388. // and hCryptProv is optional.
  4389. HCRYPTPROV hCryptProv;
  4390. DWORD dwKeySpec;
  4391. DWORD dwKeyChoice;
  4392. union {
  4393. // CMSG_KEY_AGREE_EPHEMERAL_KEY_CHOICE
  4394. //
  4395. // The ephemeral public key algorithm and parameters.
  4396. PCRYPT_ALGORITHM_IDENTIFIER pEphemeralAlgorithm;
  4397. // CMSG_KEY_AGREE_STATIC_KEY_CHOICE
  4398. //
  4399. // The CertId of the sender's certificate
  4400. PCERT_ID pSenderId;
  4401. };
  4402. CRYPT_DATA_BLOB UserKeyingMaterial; // OPTIONAL
  4403. DWORD cRecipientEncryptedKeys;
  4404. PCMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO *rgpRecipientEncryptedKeys;
  4405. } CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO, *PCMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO;
  4406. #define CMSG_KEY_AGREE_EPHEMERAL_KEY_CHOICE 1
  4407. #define CMSG_KEY_AGREE_STATIC_KEY_CHOICE 2
  4408. //+-------------------------------------------------------------------------
  4409. // Mail List Recipient Encode Info
  4410. //
  4411. // There is 1 choice for the KeyEncryptionKey: an already created CSP key
  4412. // handle. For the key handle choice, hCryptProv must be nonzero. This key
  4413. // handle isn't destroyed.
  4414. //
  4415. // Note, even if CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  4416. // passed to CryptMsgOpenToEncode(), this hCryptProv isn't released.
  4417. //
  4418. // Currently, pvKeyEncryptionAuxInfo is only defined for RC2 key wrap
  4419. // algorithms. Otherwise, its not used and must be set to NULL.
  4420. // When set for RC2 algorithms, points to a CMSG_RC2_AUX_INFO containing
  4421. // the RC2 effective key length.
  4422. //
  4423. // Note, mail list recipients are not supported in PKCS #7 version 1.5.
  4424. //--------------------------------------------------------------------------
  4425. typedef struct _CMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO {
  4426. DWORD cbSize;
  4427. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  4428. void *pvKeyEncryptionAuxInfo;
  4429. HCRYPTPROV hCryptProv;
  4430. DWORD dwKeyChoice;
  4431. union {
  4432. // CMSG_MAIL_LIST_HANDLE_KEY_CHOICE
  4433. HCRYPTKEY hKeyEncryptionKey;
  4434. // Reserve space for a potential pointer choice
  4435. void *pvKeyEncryptionKey;
  4436. };
  4437. CRYPT_DATA_BLOB KeyId;
  4438. // Following fields are optional.
  4439. FILETIME Date;
  4440. PCRYPT_ATTRIBUTE_TYPE_VALUE pOtherAttr;
  4441. } CMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO, *PCMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO;
  4442. #define CMSG_MAIL_LIST_HANDLE_KEY_CHOICE 1
  4443. //+-------------------------------------------------------------------------
  4444. // Recipient Encode Info
  4445. //
  4446. // Note, only key transport recipients are supported in PKCS #7 version 1.5.
  4447. //--------------------------------------------------------------------------
  4448. struct _CMSG_RECIPIENT_ENCODE_INFO {
  4449. DWORD dwRecipientChoice;
  4450. union {
  4451. // CMSG_KEY_TRANS_RECIPIENT
  4452. PCMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO pKeyTrans;
  4453. // CMSG_KEY_AGREE_RECIPIENT
  4454. PCMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO pKeyAgree;
  4455. // CMSG_MAIL_LIST_RECIPIENT
  4456. PCMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO pMailList;
  4457. };
  4458. };
  4459. #define CMSG_KEY_TRANS_RECIPIENT 1
  4460. #define CMSG_KEY_AGREE_RECIPIENT 2
  4461. #define CMSG_MAIL_LIST_RECIPIENT 3
  4462. //+-------------------------------------------------------------------------
  4463. // CMSG_RC2_AUX_INFO
  4464. //
  4465. // AuxInfo for RC2 encryption algorithms. The pvEncryptionAuxInfo field
  4466. // in CMSG_ENCRYPTED_ENCODE_INFO should be updated to point to this
  4467. // structure. If not specified, defaults to 40 bit.
  4468. //
  4469. // Note, this AuxInfo is only used when, the ContentEncryptionAlgorithm's
  4470. // Parameter.cbData is zero. Otherwise, the Parameters is decoded to
  4471. // get the bit length.
  4472. //
  4473. // If CMSG_SP3_COMPATIBLE_ENCRYPT_FLAG is set in dwBitLen, then, SP3
  4474. // compatible encryption is done and the bit length is ignored.
  4475. //--------------------------------------------------------------------------
  4476. typedef struct _CMSG_RC2_AUX_INFO {
  4477. DWORD cbSize;
  4478. DWORD dwBitLen;
  4479. } CMSG_RC2_AUX_INFO, *PCMSG_RC2_AUX_INFO;
  4480. //+-------------------------------------------------------------------------
  4481. // CMSG_SP3_COMPATIBLE_AUX_INFO
  4482. //
  4483. // AuxInfo for enabling SP3 compatible encryption.
  4484. //
  4485. // The CMSG_SP3_COMPATIBLE_ENCRYPT_FLAG is set in dwFlags to enable SP3
  4486. // compatible encryption. When set, uses zero salt instead of no salt,
  4487. // the encryption algorithm parameters are NULL instead of containing the
  4488. // encoded RC2 parameters or encoded IV octet string and the encrypted
  4489. // symmetric key is encoded little endian instead of big endian.
  4490. //--------------------------------------------------------------------------
  4491. typedef struct _CMSG_SP3_COMPATIBLE_AUX_INFO {
  4492. DWORD cbSize;
  4493. DWORD dwFlags;
  4494. } CMSG_SP3_COMPATIBLE_AUX_INFO, *PCMSG_SP3_COMPATIBLE_AUX_INFO;
  4495. #define CMSG_SP3_COMPATIBLE_ENCRYPT_FLAG 0x80000000
  4496. //+-------------------------------------------------------------------------
  4497. // CMSG_RC4_AUX_INFO
  4498. //
  4499. // AuxInfo for RC4 encryption algorithms. The pvEncryptionAuxInfo field
  4500. // in CMSG_ENCRYPTED_ENCODE_INFO should be updated to point to this
  4501. // structure. If not specified, uses the CSP's default bit length with no
  4502. // salt. Note, the base CSP has a 40 bit default and the enhanced CSP has
  4503. // a 128 bit default.
  4504. //
  4505. // If CMSG_RC4_NO_SALT_FLAG is set in dwBitLen, then, no salt is generated.
  4506. // Otherwise, (128 - dwBitLen)/8 bytes of salt are generated and encoded
  4507. // as an OCTET STRING in the algorithm parameters field.
  4508. //--------------------------------------------------------------------------
  4509. typedef struct _CMSG_RC4_AUX_INFO {
  4510. DWORD cbSize;
  4511. DWORD dwBitLen;
  4512. } CMSG_RC4_AUX_INFO, *PCMSG_RC4_AUX_INFO;
  4513. #define CMSG_RC4_NO_SALT_FLAG 0x40000000
  4514. //+-------------------------------------------------------------------------
  4515. // CMSG_SIGNED_AND_ENVELOPED
  4516. //
  4517. // For PKCS #7, a signed and enveloped message doesn't have the
  4518. // signer's authenticated or unauthenticated attributes. Otherwise, a
  4519. // combination of the CMSG_SIGNED_ENCODE_INFO and CMSG_ENVELOPED_ENCODE_INFO.
  4520. //--------------------------------------------------------------------------
  4521. typedef struct _CMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO {
  4522. DWORD cbSize;
  4523. CMSG_SIGNED_ENCODE_INFO SignedInfo;
  4524. CMSG_ENVELOPED_ENCODE_INFO EnvelopedInfo;
  4525. } CMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO, *PCMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO;
  4526. //+-------------------------------------------------------------------------
  4527. // CMSG_HASHED
  4528. //
  4529. // hCryptProv is used to do the hash. Doesn't need to use a private key.
  4530. //
  4531. // If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  4532. // passed to CryptMsgOpenToEncode(), the hCryptProv is released.
  4533. //
  4534. // If fDetachedHash is set, then, the encoded message doesn't contain
  4535. // any content (its treated as NULL Data)
  4536. //
  4537. // pvHashAuxInfo currently isn't used and must be set to NULL.
  4538. //--------------------------------------------------------------------------
  4539. typedef struct _CMSG_HASHED_ENCODE_INFO {
  4540. DWORD cbSize;
  4541. HCRYPTPROV hCryptProv;
  4542. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  4543. void *pvHashAuxInfo;
  4544. } CMSG_HASHED_ENCODE_INFO, *PCMSG_HASHED_ENCODE_INFO;
  4545. //+-------------------------------------------------------------------------
  4546. // CMSG_ENCRYPTED
  4547. //
  4548. // The key used to encrypt the message is identified outside of the message
  4549. // content (for example, password).
  4550. //
  4551. // The content input to CryptMsgUpdate has already been encrypted.
  4552. //
  4553. // pvEncryptionAuxInfo currently isn't used and must be set to NULL.
  4554. //--------------------------------------------------------------------------
  4555. typedef struct _CMSG_ENCRYPTED_ENCODE_INFO {
  4556. DWORD cbSize;
  4557. CRYPT_ALGORITHM_IDENTIFIER ContentEncryptionAlgorithm;
  4558. void *pvEncryptionAuxInfo;
  4559. } CMSG_ENCRYPTED_ENCODE_INFO, *PCMSG_ENCRYPTED_ENCODE_INFO;
  4560. //+-------------------------------------------------------------------------
  4561. // This parameter allows messages to be of variable length with streamed
  4562. // output.
  4563. //
  4564. // By default, messages are of a definite length and
  4565. // CryptMsgGetParam(CMSG_CONTENT_PARAM) is
  4566. // called to get the cryptographically processed content. Until closed,
  4567. // the handle keeps a copy of the processed content.
  4568. //
  4569. // With streamed output, the processed content can be freed as its streamed.
  4570. //
  4571. // If the length of the content to be updated is known at the time of the
  4572. // open, then, ContentLength should be set to that length. Otherwise, it
  4573. // should be set to CMSG_INDEFINITE_LENGTH.
  4574. //--------------------------------------------------------------------------
  4575. typedef BOOL (WINAPI *PFN_CMSG_STREAM_OUTPUT)(
  4576. IN const void *pvArg,
  4577. IN BYTE *pbData,
  4578. IN DWORD cbData,
  4579. IN BOOL fFinal
  4580. );
  4581. #define CMSG_INDEFINITE_LENGTH (0xFFFFFFFF)
  4582. typedef struct _CMSG_STREAM_INFO {
  4583. DWORD cbContent;
  4584. PFN_CMSG_STREAM_OUTPUT pfnStreamOutput;
  4585. void *pvArg;
  4586. } CMSG_STREAM_INFO, *PCMSG_STREAM_INFO;
  4587. //+-------------------------------------------------------------------------
  4588. // Open dwFlags
  4589. //--------------------------------------------------------------------------
  4590. #define CMSG_BARE_CONTENT_FLAG 0x00000001
  4591. #define CMSG_LENGTH_ONLY_FLAG 0x00000002
  4592. #define CMSG_DETACHED_FLAG 0x00000004
  4593. #define CMSG_AUTHENTICATED_ATTRIBUTES_FLAG 0x00000008
  4594. #define CMSG_CONTENTS_OCTETS_FLAG 0x00000010
  4595. #define CMSG_MAX_LENGTH_FLAG 0x00000020
  4596. // When set, nonData type inner content is encapsulated within an
  4597. // OCTET STRING. Applicable to both Signed and Enveloped messages.
  4598. #define CMSG_CMS_ENCAPSULATED_CONTENT_FLAG 0x00000040
  4599. // If set, then, the hCryptProv passed to CryptMsgOpenToEncode or
  4600. // CryptMsgOpenToDecode is released on the final CryptMsgClose.
  4601. // Not released if CryptMsgOpenToEncode or CryptMsgOpenToDecode fails.
  4602. //
  4603. // Note, the envelope recipient hCryptProv's aren't released.
  4604. #define CMSG_CRYPT_RELEASE_CONTEXT_FLAG 0x00008000
  4605. //+-------------------------------------------------------------------------
  4606. // Open a cryptographic message for encoding
  4607. //
  4608. // If CMSG_BARE_CONTENT_FLAG is specified for a streamed message,
  4609. // the streamed output will not have an outer ContentInfo wrapper. This
  4610. // makes it suitable to be streamed into an enclosing message.
  4611. //
  4612. // The pStreamInfo parameter needs to be set to stream the encoded message
  4613. // output.
  4614. //--------------------------------------------------------------------------
  4615. WINCRYPT32API
  4616. HCRYPTMSG
  4617. WINAPI
  4618. CryptMsgOpenToEncode(
  4619. IN DWORD dwMsgEncodingType,
  4620. IN DWORD dwFlags,
  4621. IN DWORD dwMsgType,
  4622. IN void const *pvMsgEncodeInfo,
  4623. IN OPTIONAL LPSTR pszInnerContentObjID,
  4624. IN OPTIONAL PCMSG_STREAM_INFO pStreamInfo
  4625. );
  4626. //+-------------------------------------------------------------------------
  4627. // Calculate the length of an encoded cryptographic message.
  4628. //
  4629. // Calculates the length of the encoded message given the
  4630. // message type, encoding parameters and total length of
  4631. // the data to be updated. Note, this might not be the exact length. However,
  4632. // it will always be greater than or equal to the actual length.
  4633. //--------------------------------------------------------------------------
  4634. WINCRYPT32API
  4635. DWORD
  4636. WINAPI
  4637. CryptMsgCalculateEncodedLength(
  4638. IN DWORD dwMsgEncodingType,
  4639. IN DWORD dwFlags,
  4640. IN DWORD dwMsgType,
  4641. IN void const *pvMsgEncodeInfo,
  4642. IN OPTIONAL LPSTR pszInnerContentObjID,
  4643. IN DWORD cbData
  4644. );
  4645. //+-------------------------------------------------------------------------
  4646. // Open a cryptographic message for decoding
  4647. //
  4648. // hCryptProv specifies the crypto provider to use for hashing and/or
  4649. // decrypting the message. If hCryptProv is NULL, a default crypt provider
  4650. // is used.
  4651. //
  4652. // Currently pRecipientInfo isn't used and should be set to NULL.
  4653. //
  4654. // The pStreamInfo parameter needs to be set to stream the decoded content
  4655. // output.
  4656. //--------------------------------------------------------------------------
  4657. WINCRYPT32API
  4658. HCRYPTMSG
  4659. WINAPI
  4660. CryptMsgOpenToDecode(
  4661. IN DWORD dwMsgEncodingType,
  4662. IN DWORD dwFlags,
  4663. IN DWORD dwMsgType,
  4664. IN HCRYPTPROV hCryptProv,
  4665. IN OPTIONAL PCERT_INFO pRecipientInfo,
  4666. IN OPTIONAL PCMSG_STREAM_INFO pStreamInfo
  4667. );
  4668. //+-------------------------------------------------------------------------
  4669. // Duplicate a cryptographic message handle
  4670. //--------------------------------------------------------------------------
  4671. WINCRYPT32API
  4672. HCRYPTMSG
  4673. WINAPI
  4674. CryptMsgDuplicate(
  4675. IN HCRYPTMSG hCryptMsg
  4676. );
  4677. //+-------------------------------------------------------------------------
  4678. // Close a cryptographic message handle
  4679. //
  4680. // LastError is preserved unless FALSE is returned.
  4681. //--------------------------------------------------------------------------
  4682. WINCRYPT32API
  4683. BOOL
  4684. WINAPI
  4685. CryptMsgClose(
  4686. IN HCRYPTMSG hCryptMsg
  4687. );
  4688. //+-------------------------------------------------------------------------
  4689. // Update the content of a cryptographic message. Depending on how the
  4690. // message was opened, the content is either encoded or decoded.
  4691. //
  4692. // This function is repetitively called to append to the message content.
  4693. // fFinal is set to identify the last update. On fFinal, the encode/decode
  4694. // is completed. The encoded/decoded content and the decoded parameters
  4695. // are valid until the open and all duplicated handles are closed.
  4696. //--------------------------------------------------------------------------
  4697. WINCRYPT32API
  4698. BOOL
  4699. WINAPI
  4700. CryptMsgUpdate(
  4701. IN HCRYPTMSG hCryptMsg,
  4702. IN const BYTE *pbData,
  4703. IN DWORD cbData,
  4704. IN BOOL fFinal
  4705. );
  4706. //+-------------------------------------------------------------------------
  4707. // Get a parameter after encoding/decoding a cryptographic message. Called
  4708. // after the final CryptMsgUpdate. Only the CMSG_CONTENT_PARAM and
  4709. // CMSG_COMPUTED_HASH_PARAM are valid for an encoded message.
  4710. //
  4711. // For an encoded HASHED message, the CMSG_COMPUTED_HASH_PARAM can be got
  4712. // before any CryptMsgUpdates to get its length.
  4713. //
  4714. // The pvData type definition depends on the dwParamType value.
  4715. //
  4716. // Elements pointed to by fields in the pvData structure follow the
  4717. // structure. Therefore, *pcbData may exceed the size of the structure.
  4718. //
  4719. // Upon input, if *pcbData == 0, then, *pcbData is updated with the length
  4720. // of the data and the pvData parameter is ignored.
  4721. //
  4722. // Upon return, *pcbData is updated with the length of the data.
  4723. //
  4724. // The OBJID BLOBs returned in the pvData structures point to
  4725. // their still encoded representation. The appropriate functions
  4726. // must be called to decode the information.
  4727. //
  4728. // See below for a list of the parameters to get.
  4729. //--------------------------------------------------------------------------
  4730. WINCRYPT32API
  4731. BOOL
  4732. WINAPI
  4733. CryptMsgGetParam(
  4734. IN HCRYPTMSG hCryptMsg,
  4735. IN DWORD dwParamType,
  4736. IN DWORD dwIndex,
  4737. OUT void *pvData,
  4738. IN OUT DWORD *pcbData
  4739. );
  4740. //+-------------------------------------------------------------------------
  4741. // Get parameter types and their corresponding data structure definitions.
  4742. //--------------------------------------------------------------------------
  4743. #define CMSG_TYPE_PARAM 1
  4744. #define CMSG_CONTENT_PARAM 2
  4745. #define CMSG_BARE_CONTENT_PARAM 3
  4746. #define CMSG_INNER_CONTENT_TYPE_PARAM 4
  4747. #define CMSG_SIGNER_COUNT_PARAM 5
  4748. #define CMSG_SIGNER_INFO_PARAM 6
  4749. #define CMSG_SIGNER_CERT_INFO_PARAM 7
  4750. #define CMSG_SIGNER_HASH_ALGORITHM_PARAM 8
  4751. #define CMSG_SIGNER_AUTH_ATTR_PARAM 9
  4752. #define CMSG_SIGNER_UNAUTH_ATTR_PARAM 10
  4753. #define CMSG_CERT_COUNT_PARAM 11
  4754. #define CMSG_CERT_PARAM 12
  4755. #define CMSG_CRL_COUNT_PARAM 13
  4756. #define CMSG_CRL_PARAM 14
  4757. #define CMSG_ENVELOPE_ALGORITHM_PARAM 15
  4758. #define CMSG_RECIPIENT_COUNT_PARAM 17
  4759. #define CMSG_RECIPIENT_INDEX_PARAM 18
  4760. #define CMSG_RECIPIENT_INFO_PARAM 19
  4761. #define CMSG_HASH_ALGORITHM_PARAM 20
  4762. #define CMSG_HASH_DATA_PARAM 21
  4763. #define CMSG_COMPUTED_HASH_PARAM 22
  4764. #define CMSG_ENCRYPT_PARAM 26
  4765. #define CMSG_ENCRYPTED_DIGEST 27
  4766. #define CMSG_ENCODED_SIGNER 28
  4767. #define CMSG_ENCODED_MESSAGE 29
  4768. #define CMSG_VERSION_PARAM 30
  4769. #define CMSG_ATTR_CERT_COUNT_PARAM 31
  4770. #define CMSG_ATTR_CERT_PARAM 32
  4771. #define CMSG_CMS_RECIPIENT_COUNT_PARAM 33
  4772. #define CMSG_CMS_RECIPIENT_INDEX_PARAM 34
  4773. #define CMSG_CMS_RECIPIENT_ENCRYPTED_KEY_INDEX_PARAM 35
  4774. #define CMSG_CMS_RECIPIENT_INFO_PARAM 36
  4775. #define CMSG_UNPROTECTED_ATTR_PARAM 37
  4776. #define CMSG_SIGNER_CERT_ID_PARAM 38
  4777. #define CMSG_CMS_SIGNER_INFO_PARAM 39
  4778. //+-------------------------------------------------------------------------
  4779. // CMSG_TYPE_PARAM
  4780. //
  4781. // The type of the decoded message.
  4782. //
  4783. // pvData points to a DWORD
  4784. //--------------------------------------------------------------------------
  4785. //+-------------------------------------------------------------------------
  4786. // CMSG_CONTENT_PARAM
  4787. //
  4788. // The encoded content of a cryptographic message. Depending on how the
  4789. // message was opened, the content is either the whole PKCS#7
  4790. // message (opened to encode) or the inner content (opened to decode).
  4791. // In the decode case, the decrypted content is returned, if enveloped.
  4792. // If not enveloped, and if the inner content is of type DATA, the returned
  4793. // data is the contents octets of the inner content.
  4794. //
  4795. // pvData points to the buffer receiving the content bytes
  4796. //--------------------------------------------------------------------------
  4797. //+-------------------------------------------------------------------------
  4798. // CMSG_BARE_CONTENT_PARAM
  4799. //
  4800. // The encoded content of an encoded cryptographic message, without the
  4801. // outer layer of ContentInfo. That is, only the encoding of the
  4802. // ContentInfo.content field is returned.
  4803. //
  4804. // pvData points to the buffer receiving the content bytes
  4805. //--------------------------------------------------------------------------
  4806. //+-------------------------------------------------------------------------
  4807. // CMSG_INNER_CONTENT_TYPE_PARAM
  4808. //
  4809. // The type of the inner content of a decoded cryptographic message,
  4810. // in the form of a NULL-terminated object identifier string
  4811. // (eg. "1.2.840.113549.1.7.1").
  4812. //
  4813. // pvData points to the buffer receiving the object identifier string
  4814. //--------------------------------------------------------------------------
  4815. //+-------------------------------------------------------------------------
  4816. // CMSG_SIGNER_COUNT_PARAM
  4817. //
  4818. // Count of signers in a SIGNED or SIGNED_AND_ENVELOPED message
  4819. //
  4820. // pvData points to a DWORD
  4821. //--------------------------------------------------------------------------
  4822. //+-------------------------------------------------------------------------
  4823. // CMSG_SIGNER_CERT_INFO_PARAM
  4824. //
  4825. // To get all the signers, repetitively call CryptMsgGetParam, with
  4826. // dwIndex set to 0 .. SignerCount - 1.
  4827. //
  4828. // pvData points to a CERT_INFO struct.
  4829. //
  4830. // Only the following fields have been updated in the CERT_INFO struct:
  4831. // Issuer and SerialNumber.
  4832. //
  4833. // Note, if the KEYID choice was selected for a CMS SignerId, then, the
  4834. // SerialNumber is 0 and the Issuer is encoded containing a single RDN with a
  4835. // single Attribute whose OID is szOID_KEYID_RDN, value type is
  4836. // CERT_RDN_OCTET_STRING and value is the KEYID. When the
  4837. // CertGetSubjectCertificateFromStore and
  4838. // CertFindCertificateInStore(CERT_FIND_SUBJECT_CERT) APIs see this
  4839. // special KEYID Issuer and SerialNumber, they do a KEYID match.
  4840. //--------------------------------------------------------------------------
  4841. //+-------------------------------------------------------------------------
  4842. // CMSG_SIGNER_INFO_PARAM
  4843. //
  4844. // To get all the signers, repetitively call CryptMsgGetParam, with
  4845. // dwIndex set to 0 .. SignerCount - 1.
  4846. //
  4847. // pvData points to a CMSG_SIGNER_INFO struct.
  4848. //
  4849. // Note, if the KEYID choice was selected for a CMS SignerId, then, the
  4850. // SerialNumber is 0 and the Issuer is encoded containing a single RDN with a
  4851. // single Attribute whose OID is szOID_KEYID_RDN, value type is
  4852. // CERT_RDN_OCTET_STRING and value is the KEYID. When the
  4853. // CertGetSubjectCertificateFromStore and
  4854. // CertFindCertificateInStore(CERT_FIND_SUBJECT_CERT) APIs see this
  4855. // special KEYID Issuer and SerialNumber, they do a KEYID match.
  4856. //--------------------------------------------------------------------------
  4857. typedef struct _CMSG_SIGNER_INFO {
  4858. DWORD dwVersion;
  4859. CERT_NAME_BLOB Issuer;
  4860. CRYPT_INTEGER_BLOB SerialNumber;
  4861. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  4862. CRYPT_ALGORITHM_IDENTIFIER HashEncryptionAlgorithm;
  4863. CRYPT_DATA_BLOB EncryptedHash;
  4864. CRYPT_ATTRIBUTES AuthAttrs;
  4865. CRYPT_ATTRIBUTES UnauthAttrs;
  4866. } CMSG_SIGNER_INFO, *PCMSG_SIGNER_INFO;
  4867. //+-------------------------------------------------------------------------
  4868. // CMSG_SIGNER_CERT_ID_PARAM
  4869. //
  4870. // To get all the signers, repetitively call CryptMsgGetParam, with
  4871. // dwIndex set to 0 .. SignerCount - 1.
  4872. //
  4873. // pvData points to a CERT_ID struct.
  4874. //--------------------------------------------------------------------------
  4875. //+-------------------------------------------------------------------------
  4876. // CMSG_CMS_SIGNER_INFO_PARAM
  4877. //
  4878. // Same as CMSG_SIGNER_INFO_PARAM, except, contains SignerId instead of
  4879. // Issuer and SerialNumber.
  4880. //
  4881. // To get all the signers, repetitively call CryptMsgGetParam, with
  4882. // dwIndex set to 0 .. SignerCount - 1.
  4883. //
  4884. // pvData points to a CMSG_CMS_SIGNER_INFO struct.
  4885. //--------------------------------------------------------------------------
  4886. typedef struct _CMSG_CMS_SIGNER_INFO {
  4887. DWORD dwVersion;
  4888. CERT_ID SignerId;
  4889. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  4890. CRYPT_ALGORITHM_IDENTIFIER HashEncryptionAlgorithm;
  4891. CRYPT_DATA_BLOB EncryptedHash;
  4892. CRYPT_ATTRIBUTES AuthAttrs;
  4893. CRYPT_ATTRIBUTES UnauthAttrs;
  4894. } CMSG_CMS_SIGNER_INFO, *PCMSG_CMS_SIGNER_INFO;
  4895. //+-------------------------------------------------------------------------
  4896. // CMSG_SIGNER_HASH_ALGORITHM_PARAM
  4897. //
  4898. // This parameter specifies the HashAlgorithm that was used for the signer.
  4899. //
  4900. // Set dwIndex to iterate through all the signers.
  4901. //
  4902. // pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  4903. //--------------------------------------------------------------------------
  4904. //+-------------------------------------------------------------------------
  4905. // CMSG_SIGNER_AUTH_ATTR_PARAM
  4906. //
  4907. // The authenticated attributes for the signer.
  4908. //
  4909. // Set dwIndex to iterate through all the signers.
  4910. //
  4911. // pvData points to a CMSG_ATTR struct.
  4912. //--------------------------------------------------------------------------
  4913. typedef CRYPT_ATTRIBUTES CMSG_ATTR;
  4914. typedef CRYPT_ATTRIBUTES *PCMSG_ATTR;
  4915. //+-------------------------------------------------------------------------
  4916. // CMSG_SIGNER_UNAUTH_ATTR_PARAM
  4917. //
  4918. // The unauthenticated attributes for the signer.
  4919. //
  4920. // Set dwIndex to iterate through all the signers.
  4921. //
  4922. // pvData points to a CMSG_ATTR struct.
  4923. //--------------------------------------------------------------------------
  4924. //+-------------------------------------------------------------------------
  4925. // CMSG_CERT_COUNT_PARAM
  4926. //
  4927. // Count of certificates in a SIGNED or SIGNED_AND_ENVELOPED message.
  4928. //
  4929. // CMS, also supports certificates in an ENVELOPED message.
  4930. //
  4931. // pvData points to a DWORD
  4932. //--------------------------------------------------------------------------
  4933. //+-------------------------------------------------------------------------
  4934. // CMSG_CERT_PARAM
  4935. //
  4936. // To get all the certificates, repetitively call CryptMsgGetParam, with
  4937. // dwIndex set to 0 .. CertCount - 1.
  4938. //
  4939. // pvData points to an array of the certificate's encoded bytes.
  4940. //--------------------------------------------------------------------------
  4941. //+-------------------------------------------------------------------------
  4942. // CMSG_CRL_COUNT_PARAM
  4943. //
  4944. // Count of CRLs in a SIGNED or SIGNED_AND_ENVELOPED message.
  4945. //
  4946. // CMS, also supports CRLs in an ENVELOPED message.
  4947. //
  4948. // pvData points to a DWORD
  4949. //--------------------------------------------------------------------------
  4950. //+-------------------------------------------------------------------------
  4951. // CMSG_CRL_PARAM
  4952. //
  4953. // To get all the CRLs, repetitively call CryptMsgGetParam, with
  4954. // dwIndex set to 0 .. CrlCount - 1.
  4955. //
  4956. // pvData points to an array of the CRL's encoded bytes.
  4957. //--------------------------------------------------------------------------
  4958. //+-------------------------------------------------------------------------
  4959. // CMSG_ENVELOPE_ALGORITHM_PARAM
  4960. //
  4961. // The ContentEncryptionAlgorithm that was used in
  4962. // an ENVELOPED or SIGNED_AND_ENVELOPED message.
  4963. //
  4964. // For streaming you must be able to successfully get this parameter before
  4965. // doing a CryptMsgControl decrypt.
  4966. //
  4967. // pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  4968. //--------------------------------------------------------------------------
  4969. //+-------------------------------------------------------------------------
  4970. // CMSG_RECIPIENT_COUNT_PARAM
  4971. //
  4972. // Count of recipients in an ENVELOPED or SIGNED_AND_ENVELOPED message.
  4973. //
  4974. // Count of key transport recepients.
  4975. //
  4976. // The CMSG_CMS_RECIPIENT_COUNT_PARAM has the total count of
  4977. // recipients (it also includes key agree and mail list recipients).
  4978. //
  4979. // pvData points to a DWORD
  4980. //--------------------------------------------------------------------------
  4981. //+-------------------------------------------------------------------------
  4982. // CMSG_RECIPIENT_INDEX_PARAM
  4983. //
  4984. // Index of the recipient used to decrypt an ENVELOPED or SIGNED_AND_ENVELOPED
  4985. // message.
  4986. //
  4987. // Index of a key transport recipient. If a non key transport
  4988. // recipient was used to decrypt, fails with LastError set to
  4989. // CRYPT_E_INVALID_INDEX.
  4990. //
  4991. // pvData points to a DWORD
  4992. //--------------------------------------------------------------------------
  4993. //+-------------------------------------------------------------------------
  4994. // CMSG_RECIPIENT_INFO_PARAM
  4995. //
  4996. // To get all the recipients, repetitively call CryptMsgGetParam, with
  4997. // dwIndex set to 0 .. RecipientCount - 1.
  4998. //
  4999. // Only returns the key transport recepients.
  5000. //
  5001. // The CMSG_CMS_RECIPIENT_INFO_PARAM returns all recipients.
  5002. //
  5003. // pvData points to a CERT_INFO struct.
  5004. //
  5005. // Only the following fields have been updated in the CERT_INFO struct:
  5006. // Issuer, SerialNumber and PublicKeyAlgorithm. The PublicKeyAlgorithm
  5007. // specifies the KeyEncryptionAlgorithm that was used.
  5008. //
  5009. // Note, if the KEYID choice was selected for a key transport recipient, then,
  5010. // the SerialNumber is 0 and the Issuer is encoded containing a single RDN
  5011. // with a single Attribute whose OID is szOID_KEYID_RDN, value type is
  5012. // CERT_RDN_OCTET_STRING and value is the KEYID. When the
  5013. // CertGetSubjectCertificateFromStore and
  5014. // CertFindCertificateInStore(CERT_FIND_SUBJECT_CERT) APIs see this
  5015. // special KEYID Issuer and SerialNumber, they do a KEYID match.
  5016. //--------------------------------------------------------------------------
  5017. //+-------------------------------------------------------------------------
  5018. // CMSG_HASH_ALGORITHM_PARAM
  5019. //
  5020. // The HashAlgorithm in a HASHED message.
  5021. //
  5022. // pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  5023. //--------------------------------------------------------------------------
  5024. //+-------------------------------------------------------------------------
  5025. // CMSG_HASH_DATA_PARAM
  5026. //
  5027. // The hash in a HASHED message.
  5028. //
  5029. // pvData points to an array of bytes.
  5030. //--------------------------------------------------------------------------
  5031. //+-------------------------------------------------------------------------
  5032. // CMSG_COMPUTED_HASH_PARAM
  5033. //
  5034. // The computed hash for a HASHED message.
  5035. // This may be called for either an encoded or decoded message.
  5036. //
  5037. // Also, the computed hash for one of the signer's in a SIGNED message.
  5038. // It may be called for either an encoded or decoded message after the
  5039. // final update. Set dwIndex to iterate through all the signers.
  5040. //
  5041. // pvData points to an array of bytes.
  5042. //--------------------------------------------------------------------------
  5043. //+-------------------------------------------------------------------------
  5044. // CMSG_ENCRYPT_PARAM
  5045. //
  5046. // The ContentEncryptionAlgorithm that was used in an ENCRYPTED message.
  5047. //
  5048. // pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  5049. //--------------------------------------------------------------------------
  5050. //+-------------------------------------------------------------------------
  5051. // CMSG_ENCODED_MESSAGE
  5052. //
  5053. // The full encoded message. This is useful in the case of a decoded
  5054. // message which has been modified (eg. a signed-data or
  5055. // signed-and-enveloped-data message which has been countersigned).
  5056. //
  5057. // pvData points to an array of the message's encoded bytes.
  5058. //--------------------------------------------------------------------------
  5059. //+-------------------------------------------------------------------------
  5060. // CMSG_VERSION_PARAM
  5061. //
  5062. // The version of the decoded message.
  5063. //
  5064. // pvData points to a DWORD
  5065. //--------------------------------------------------------------------------
  5066. #define CMSG_SIGNED_DATA_V1 1
  5067. #define CMSG_SIGNED_DATA_V3 3
  5068. #define CMSG_SIGNED_DATA_PKCS_1_5_VERSION CMSG_SIGNED_DATA_V1
  5069. #define CMSG_SIGNED_DATA_CMS_VERSION CMSG_SIGNED_DATA_V3
  5070. #define CMSG_SIGNER_INFO_V1 1
  5071. #define CMSG_SIGNER_INFO_V3 3
  5072. #define CMSG_SIGNER_INFO_PKCS_1_5_VERSION CMSG_SIGNER_INFO_V1
  5073. #define CMSG_SIGNER_INFO_CMS_VERSION CMSG_SIGNER_INFO_V3
  5074. #define CMSG_HASHED_DATA_V0 0
  5075. #define CMSG_HASHED_DATA_V2 2
  5076. #define CMSG_HASHED_DATA_PKCS_1_5_VERSION CMSG_HASHED_DATA_V0
  5077. #define CMSG_HASHED_DATA_CMS_VERSION CMSG_HASHED_DATA_V2
  5078. #define CMSG_ENVELOPED_DATA_V0 0
  5079. #define CMSG_ENVELOPED_DATA_V2 2
  5080. #define CMSG_ENVELOPED_DATA_PKCS_1_5_VERSION CMSG_ENVELOPED_DATA_V0
  5081. #define CMSG_ENVELOPED_DATA_CMS_VERSION CMSG_ENVELOPED_DATA_V2
  5082. //+-------------------------------------------------------------------------
  5083. // CMSG_ATTR_CERT_COUNT_PARAM
  5084. //
  5085. // Count of attribute certificates in a SIGNED or ENVELOPED message.
  5086. //
  5087. // pvData points to a DWORD
  5088. //--------------------------------------------------------------------------
  5089. //+-------------------------------------------------------------------------
  5090. // CMSG_ATTR_CERT_PARAM
  5091. //
  5092. // To get all the attribute certificates, repetitively call CryptMsgGetParam,
  5093. // with dwIndex set to 0 .. AttrCertCount - 1.
  5094. //
  5095. // pvData points to an array of the attribute certificate's encoded bytes.
  5096. //--------------------------------------------------------------------------
  5097. //+-------------------------------------------------------------------------
  5098. // CMSG_CMS_RECIPIENT_COUNT_PARAM
  5099. //
  5100. // Count of all CMS recipients in an ENVELOPED message.
  5101. //
  5102. // pvData points to a DWORD
  5103. //--------------------------------------------------------------------------
  5104. //+-------------------------------------------------------------------------
  5105. // CMSG_CMS_RECIPIENT_INDEX_PARAM
  5106. //
  5107. // Index of the CMS recipient used to decrypt an ENVELOPED message.
  5108. //
  5109. // pvData points to a DWORD
  5110. //--------------------------------------------------------------------------
  5111. //+-------------------------------------------------------------------------
  5112. // CMSG_CMS_RECIPIENT_ENCRYPTED_KEY_INDEX_PARAM
  5113. //
  5114. // For a CMS key agreement recipient, the index of the encrypted key
  5115. // used to decrypt an ENVELOPED message.
  5116. //
  5117. // pvData points to a DWORD
  5118. //--------------------------------------------------------------------------
  5119. //+-------------------------------------------------------------------------
  5120. // CMSG_CMS_RECIPIENT_INFO_PARAM
  5121. //
  5122. // To get all the CMS recipients, repetitively call CryptMsgGetParam, with
  5123. // dwIndex set to 0 .. CmsRecipientCount - 1.
  5124. //
  5125. // pvData points to a CMSG_CMS_RECIPIENT_INFO struct.
  5126. //--------------------------------------------------------------------------
  5127. typedef struct _CMSG_KEY_TRANS_RECIPIENT_INFO {
  5128. DWORD dwVersion;
  5129. // Currently, only ISSUER_SERIAL_NUMBER or KEYID choices
  5130. CERT_ID RecipientId;
  5131. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  5132. CRYPT_DATA_BLOB EncryptedKey;
  5133. } CMSG_KEY_TRANS_RECIPIENT_INFO, *PCMSG_KEY_TRANS_RECIPIENT_INFO;
  5134. typedef struct _CMSG_RECIPIENT_ENCRYPTED_KEY_INFO {
  5135. // Currently, only ISSUER_SERIAL_NUMBER or KEYID choices
  5136. CERT_ID RecipientId;
  5137. CRYPT_DATA_BLOB EncryptedKey;
  5138. // The following optional fields are only applicable to KEYID choice
  5139. FILETIME Date;
  5140. PCRYPT_ATTRIBUTE_TYPE_VALUE pOtherAttr;
  5141. } CMSG_RECIPIENT_ENCRYPTED_KEY_INFO, *PCMSG_RECIPIENT_ENCRYPTED_KEY_INFO;
  5142. typedef struct _CMSG_KEY_AGREE_RECIPIENT_INFO {
  5143. DWORD dwVersion;
  5144. DWORD dwOriginatorChoice;
  5145. union {
  5146. // CMSG_KEY_AGREE_ORIGINATOR_CERT
  5147. CERT_ID OriginatorCertId;
  5148. // CMSG_KEY_AGREE_ORIGINATOR_PUBLIC_KEY
  5149. CERT_PUBLIC_KEY_INFO OriginatorPublicKeyInfo;
  5150. };
  5151. CRYPT_DATA_BLOB UserKeyingMaterial;
  5152. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  5153. DWORD cRecipientEncryptedKeys;
  5154. PCMSG_RECIPIENT_ENCRYPTED_KEY_INFO *rgpRecipientEncryptedKeys;
  5155. } CMSG_KEY_AGREE_RECIPIENT_INFO, *PCMSG_KEY_AGREE_RECIPIENT_INFO;
  5156. #define CMSG_KEY_AGREE_ORIGINATOR_CERT 1
  5157. #define CMSG_KEY_AGREE_ORIGINATOR_PUBLIC_KEY 2
  5158. typedef struct _CMSG_MAIL_LIST_RECIPIENT_INFO {
  5159. DWORD dwVersion;
  5160. CRYPT_DATA_BLOB KeyId;
  5161. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  5162. CRYPT_DATA_BLOB EncryptedKey;
  5163. // The following fields are optional
  5164. FILETIME Date;
  5165. PCRYPT_ATTRIBUTE_TYPE_VALUE pOtherAttr;
  5166. } CMSG_MAIL_LIST_RECIPIENT_INFO, *PCMSG_MAIL_LIST_RECIPIENT_INFO;
  5167. typedef struct _CMSG_CMS_RECIPIENT_INFO {
  5168. DWORD dwRecipientChoice;
  5169. union {
  5170. // CMSG_KEY_TRANS_RECIPIENT
  5171. PCMSG_KEY_TRANS_RECIPIENT_INFO pKeyTrans;
  5172. // CMSG_KEY_AGREE_RECIPIENT
  5173. PCMSG_KEY_AGREE_RECIPIENT_INFO pKeyAgree;
  5174. // CMSG_MAIL_LIST_RECIPIENT
  5175. PCMSG_MAIL_LIST_RECIPIENT_INFO pMailList;
  5176. };
  5177. } CMSG_CMS_RECIPIENT_INFO, *PCMSG_CMS_RECIPIENT_INFO;
  5178. // dwVersion numbers for the KeyTrans, KeyAgree and MailList recipients
  5179. #define CMSG_ENVELOPED_RECIPIENT_V0 0
  5180. #define CMSG_ENVELOPED_RECIPIENT_V2 2
  5181. #define CMSG_ENVELOPED_RECIPIENT_V3 3
  5182. #define CMSG_ENVELOPED_RECIPIENT_V4 4
  5183. #define CMSG_KEY_TRANS_PKCS_1_5_VERSION CMSG_ENVELOPED_RECIPIENT_V0
  5184. #define CMSG_KEY_TRANS_CMS_VERSION CMSG_ENVELOPED_RECIPIENT_V2
  5185. #define CMSG_KEY_AGREE_VERSION CMSG_ENVELOPED_RECIPIENT_V3
  5186. #define CMSG_MAIL_LIST_VERSION CMSG_ENVELOPED_RECIPIENT_V4
  5187. //+-------------------------------------------------------------------------
  5188. // CMSG_UNPROTECTED_ATTR_PARAM
  5189. //
  5190. // The unprotected attributes in the envelped message.
  5191. //
  5192. // pvData points to a CMSG_ATTR struct.
  5193. //--------------------------------------------------------------------------
  5194. //+-------------------------------------------------------------------------
  5195. // Perform a special "control" function after the final CryptMsgUpdate of a
  5196. // encoded/decoded cryptographic message.
  5197. //
  5198. // The dwCtrlType parameter specifies the type of operation to be performed.
  5199. //
  5200. // The pvCtrlPara definition depends on the dwCtrlType value.
  5201. //
  5202. // See below for a list of the control operations and their pvCtrlPara
  5203. // type definition.
  5204. //--------------------------------------------------------------------------
  5205. WINCRYPT32API
  5206. BOOL
  5207. WINAPI
  5208. CryptMsgControl(
  5209. IN HCRYPTMSG hCryptMsg,
  5210. IN DWORD dwFlags,
  5211. IN DWORD dwCtrlType,
  5212. IN void const *pvCtrlPara
  5213. );
  5214. //+-------------------------------------------------------------------------
  5215. // Message control types
  5216. //--------------------------------------------------------------------------
  5217. #define CMSG_CTRL_VERIFY_SIGNATURE 1
  5218. #define CMSG_CTRL_DECRYPT 2
  5219. #define CMSG_CTRL_VERIFY_HASH 5
  5220. #define CMSG_CTRL_ADD_SIGNER 6
  5221. #define CMSG_CTRL_DEL_SIGNER 7
  5222. #define CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR 8
  5223. #define CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR 9
  5224. #define CMSG_CTRL_ADD_CERT 10
  5225. #define CMSG_CTRL_DEL_CERT 11
  5226. #define CMSG_CTRL_ADD_CRL 12
  5227. #define CMSG_CTRL_DEL_CRL 13
  5228. #define CMSG_CTRL_ADD_ATTR_CERT 14
  5229. #define CMSG_CTRL_DEL_ATTR_CERT 15
  5230. #define CMSG_CTRL_KEY_TRANS_DECRYPT 16
  5231. #define CMSG_CTRL_KEY_AGREE_DECRYPT 17
  5232. #define CMSG_CTRL_MAIL_LIST_DECRYPT 18
  5233. #define CMSG_CTRL_VERIFY_SIGNATURE_EX 19
  5234. #define CMSG_CTRL_ADD_CMS_SIGNER_INFO 20
  5235. //+-------------------------------------------------------------------------
  5236. // CMSG_CTRL_VERIFY_SIGNATURE
  5237. //
  5238. // Verify the signature of a SIGNED or SIGNED_AND_ENVELOPED
  5239. // message after it has been decoded.
  5240. //
  5241. // For a SIGNED_AND_ENVELOPED message, called after
  5242. // CryptMsgControl(CMSG_CTRL_DECRYPT), if CryptMsgOpenToDecode was called
  5243. // with a NULL pRecipientInfo.
  5244. //
  5245. // pvCtrlPara points to a CERT_INFO struct.
  5246. //
  5247. // The CERT_INFO contains the Issuer and SerialNumber identifying
  5248. // the Signer of the message. The CERT_INFO also contains the
  5249. // PublicKeyInfo
  5250. // used to verify the signature. The cryptographic provider specified
  5251. // in CryptMsgOpenToDecode is used.
  5252. //
  5253. // Note, if the message contains CMS signers identified by KEYID, then,
  5254. // the CERT_INFO's Issuer and SerialNumber is ignored and only the public
  5255. // key is used to find a signer whose signature verifies.
  5256. //
  5257. // The following CMSG_CTRL_VERIFY_SIGNATURE_EX should be used instead.
  5258. //--------------------------------------------------------------------------
  5259. //+-------------------------------------------------------------------------
  5260. // CMSG_CTRL_VERIFY_SIGNATURE_EX
  5261. //
  5262. // Verify the signature of a SIGNED message after it has been decoded.
  5263. //
  5264. // pvCtrlPara points to the following CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA.
  5265. //
  5266. // If hCryptProv is NULL, uses the cryptographic provider specified in
  5267. // CryptMsgOpenToDecode. If CryptMsgOpenToDecode's hCryptProv is also NULL,
  5268. // gets default provider according to the signer's public key OID.
  5269. //
  5270. // dwSignerIndex is the index of the signer to use to verify the signature.
  5271. //
  5272. // The signer can be a pointer to a CERT_PUBLIC_KEY_INFO, certificate
  5273. // context or a chain context.
  5274. //
  5275. // If the signer's HashEncryptionAlgorithm is szOID_PKIX_NO_SIGNATURE, then,
  5276. // the signature is expected to contain the hash octets. Only dwSignerType
  5277. // of CMSG_VERIFY_SIGNER_NULL may be specified to verify this no signature
  5278. // case.
  5279. //--------------------------------------------------------------------------
  5280. typedef struct _CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA {
  5281. DWORD cbSize;
  5282. HCRYPTPROV hCryptProv;
  5283. DWORD dwSignerIndex;
  5284. DWORD dwSignerType;
  5285. void *pvSigner;
  5286. } CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA, *PCMSG_CTRL_VERIFY_SIGNATURE_EX_PARA;
  5287. // Signer Types
  5288. #define CMSG_VERIFY_SIGNER_PUBKEY 1
  5289. // pvSigner :: PCERT_PUBLIC_KEY_INFO
  5290. #define CMSG_VERIFY_SIGNER_CERT 2
  5291. // pvSigner :: PCCERT_CONTEXT
  5292. #define CMSG_VERIFY_SIGNER_CHAIN 3
  5293. // pvSigner :: PCCERT_CHAIN_CONTEXT
  5294. #define CMSG_VERIFY_SIGNER_NULL 4
  5295. // pvSigner :: NULL
  5296. //+-------------------------------------------------------------------------
  5297. // CMSG_CTRL_DECRYPT
  5298. //
  5299. // Decrypt an ENVELOPED or SIGNED_AND_ENVELOPED message after it has been
  5300. // decoded.
  5301. //
  5302. // This decrypt is only applicable to key transport recipients.
  5303. //
  5304. // hCryptProv and dwKeySpec specify the private key to use. For dwKeySpec ==
  5305. // 0, defaults to AT_KEYEXCHANGE.
  5306. //
  5307. // If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags passed
  5308. // to CryptMsgControl, then, the hCryptProv is released on the final
  5309. // CryptMsgClose. Not released if CryptMsgControl fails.
  5310. //
  5311. // dwRecipientIndex is the index of the recipient in the message associated
  5312. // with the hCryptProv's private key.
  5313. //
  5314. // The dwRecipientIndex is the index of a key transport recipient.
  5315. //
  5316. // Note, the message can only be decrypted once.
  5317. //--------------------------------------------------------------------------
  5318. typedef struct _CMSG_CTRL_DECRYPT_PARA {
  5319. DWORD cbSize;
  5320. HCRYPTPROV hCryptProv;
  5321. DWORD dwKeySpec;
  5322. DWORD dwRecipientIndex;
  5323. } CMSG_CTRL_DECRYPT_PARA, *PCMSG_CTRL_DECRYPT_PARA;
  5324. //+-------------------------------------------------------------------------
  5325. // CMSG_CTRL_KEY_TRANS_DECRYPT
  5326. //
  5327. // Decrypt an ENVELOPED message after it has been decoded for a key
  5328. // transport recipient.
  5329. //
  5330. // hCryptProv and dwKeySpec specify the private key to use. For dwKeySpec ==
  5331. // 0, defaults to AT_KEYEXCHANGE.
  5332. //
  5333. // If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags passed
  5334. // to CryptMsgControl, then, the hCryptProv is released on the final
  5335. // CryptMsgClose. Not released if CryptMsgControl fails.
  5336. //
  5337. // pKeyTrans points to the CMSG_KEY_TRANS_RECIPIENT_INFO obtained via
  5338. // CryptMsgGetParam(CMSG_CMS_RECIPIENT_INFO_PARAM)
  5339. //
  5340. // dwRecipientIndex is the index of the recipient in the message associated
  5341. // with the hCryptProv's private key.
  5342. //
  5343. // Note, the message can only be decrypted once.
  5344. //--------------------------------------------------------------------------
  5345. typedef struct _CMSG_CTRL_KEY_TRANS_DECRYPT_PARA {
  5346. DWORD cbSize;
  5347. HCRYPTPROV hCryptProv;
  5348. DWORD dwKeySpec;
  5349. PCMSG_KEY_TRANS_RECIPIENT_INFO pKeyTrans;
  5350. DWORD dwRecipientIndex;
  5351. } CMSG_CTRL_KEY_TRANS_DECRYPT_PARA, *PCMSG_CTRL_KEY_TRANS_DECRYPT_PARA;
  5352. //+-------------------------------------------------------------------------
  5353. // CMSG_CTRL_KEY_AGREE_DECRYPT
  5354. //
  5355. // Decrypt an ENVELOPED message after it has been decoded for a key
  5356. // agreement recipient.
  5357. //
  5358. // hCryptProv and dwKeySpec specify the private key to use. For dwKeySpec ==
  5359. // 0, defaults to AT_KEYEXCHANGE.
  5360. //
  5361. // If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags passed
  5362. // to CryptMsgControl, then, the hCryptProv is released on the final
  5363. // CryptMsgClose. Not released if CryptMsgControl fails.
  5364. //
  5365. // pKeyAgree points to the CMSG_KEY_AGREE_RECIPIENT_INFO obtained via
  5366. // CryptMsgGetParam(CMSG_CMS_RECIPIENT_INFO_PARAM) for dwRecipientIndex.
  5367. //
  5368. // dwRecipientIndex, dwRecipientEncryptedKeyIndex are the indices of the
  5369. // recipient's encrypted key in the message associated with the hCryptProv's
  5370. // private key.
  5371. //
  5372. // OriginatorPublicKey is the originator's public key obtained from either
  5373. // the originator's certificate or the CMSG_KEY_AGREE_RECIPIENT_INFO obtained
  5374. // via the CMSG_CMS_RECIPIENT_INFO_PARAM.
  5375. //
  5376. // Note, the message can only be decrypted once.
  5377. //--------------------------------------------------------------------------
  5378. typedef struct _CMSG_CTRL_KEY_AGREE_DECRYPT_PARA {
  5379. DWORD cbSize;
  5380. HCRYPTPROV hCryptProv;
  5381. DWORD dwKeySpec;
  5382. PCMSG_KEY_AGREE_RECIPIENT_INFO pKeyAgree;
  5383. DWORD dwRecipientIndex;
  5384. DWORD dwRecipientEncryptedKeyIndex;
  5385. CRYPT_BIT_BLOB OriginatorPublicKey;
  5386. } CMSG_CTRL_KEY_AGREE_DECRYPT_PARA, *PCMSG_CTRL_KEY_AGREE_DECRYPT_PARA;
  5387. //+-------------------------------------------------------------------------
  5388. // CMSG_CTRL_MAIL_LIST_DECRYPT
  5389. //
  5390. // Decrypt an ENVELOPED message after it has been decoded for a mail
  5391. // list recipient.
  5392. //
  5393. // pMailList points to the CMSG_MAIL_LIST_RECIPIENT_INFO obtained via
  5394. // CryptMsgGetParam(CMSG_CMS_RECIPIENT_INFO_PARAM) for dwRecipientIndex.
  5395. //
  5396. // There is 1 choice for the KeyEncryptionKey: an already created CSP key
  5397. // handle. For the key handle choice, hCryptProv must be nonzero. This key
  5398. // handle isn't destroyed.
  5399. //
  5400. // If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags passed
  5401. // to CryptMsgControl, then, the hCryptProv is released on the final
  5402. // CryptMsgClose. Not released if CryptMsgControl fails.
  5403. //
  5404. // For RC2 wrap, the effective key length is obtained from the
  5405. // KeyEncryptionAlgorithm parameters and set on the hKeyEncryptionKey before
  5406. // decrypting.
  5407. //
  5408. // Note, the message can only be decrypted once.
  5409. //--------------------------------------------------------------------------
  5410. typedef struct _CMSG_CTRL_MAIL_LIST_DECRYPT_PARA {
  5411. DWORD cbSize;
  5412. HCRYPTPROV hCryptProv;
  5413. PCMSG_MAIL_LIST_RECIPIENT_INFO pMailList;
  5414. DWORD dwRecipientIndex;
  5415. DWORD dwKeyChoice;
  5416. union {
  5417. // CMSG_MAIL_LIST_HANDLE_KEY_CHOICE
  5418. HCRYPTKEY hKeyEncryptionKey;
  5419. // Reserve space for a potential pointer choice
  5420. void *pvKeyEncryptionKey;
  5421. };
  5422. } CMSG_CTRL_MAIL_LIST_DECRYPT_PARA, *PCMSG_CTRL_MAIL_LIST_DECRYPT_PARA;
  5423. //+-------------------------------------------------------------------------
  5424. // CMSG_CTRL_VERIFY_HASH
  5425. //
  5426. // Verify the hash of a HASHED message after it has been decoded.
  5427. //
  5428. // Only the hCryptMsg parameter is used, to specify the message whose
  5429. // hash is being verified.
  5430. //--------------------------------------------------------------------------
  5431. //+-------------------------------------------------------------------------
  5432. // CMSG_CTRL_ADD_SIGNER
  5433. //
  5434. // Add a signer to a signed-data message.
  5435. //
  5436. // pvCtrlPara points to a CMSG_SIGNER_ENCODE_INFO.
  5437. //--------------------------------------------------------------------------
  5438. //+-------------------------------------------------------------------------
  5439. // CMSG_CTRL_ADD_CMS_SIGNER_INFO
  5440. //
  5441. // Add a signer to a signed-data message.
  5442. //
  5443. // Differs from the above, CMSG_CTRL_ADD_SIGNER, wherein, the signer info
  5444. // already contains the signature.
  5445. //
  5446. // pvCtrlPara points to a CMSG_CMS_SIGNER_INFO.
  5447. //--------------------------------------------------------------------------
  5448. //+-------------------------------------------------------------------------
  5449. // CMSG_CTRL_DEL_SIGNER
  5450. //
  5451. // Remove a signer from a signed-data or signed-and-enveloped-data message.
  5452. //
  5453. // pvCtrlPara points to a DWORD containing the 0-based index of the
  5454. // signer to be removed.
  5455. //--------------------------------------------------------------------------
  5456. //+-------------------------------------------------------------------------
  5457. // CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR
  5458. //
  5459. // Add an unauthenticated attribute to the SignerInfo of a signed-data or
  5460. // signed-and-enveloped-data message.
  5461. //
  5462. // The unauthenticated attribute is input in the form of an encoded blob.
  5463. //--------------------------------------------------------------------------
  5464. typedef struct _CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA {
  5465. DWORD cbSize;
  5466. DWORD dwSignerIndex;
  5467. CRYPT_DATA_BLOB blob;
  5468. } CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA, *PCMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA;
  5469. //+-------------------------------------------------------------------------
  5470. // CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR
  5471. //
  5472. // Delete an unauthenticated attribute from the SignerInfo of a signed-data
  5473. // or signed-and-enveloped-data message.
  5474. //
  5475. // The unauthenticated attribute to be removed is specified by
  5476. // a 0-based index.
  5477. //--------------------------------------------------------------------------
  5478. typedef struct _CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA {
  5479. DWORD cbSize;
  5480. DWORD dwSignerIndex;
  5481. DWORD dwUnauthAttrIndex;
  5482. } CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA, *PCMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA;
  5483. //+-------------------------------------------------------------------------
  5484. // CMSG_CTRL_ADD_CERT
  5485. //
  5486. // Add a certificate to a signed-data or signed-and-enveloped-data message.
  5487. //
  5488. // pvCtrlPara points to a CRYPT_DATA_BLOB containing the certificate's
  5489. // encoded bytes.
  5490. //--------------------------------------------------------------------------
  5491. //+-------------------------------------------------------------------------
  5492. // CMSG_CTRL_DEL_CERT
  5493. //
  5494. // Delete a certificate from a signed-data or signed-and-enveloped-data
  5495. // message.
  5496. //
  5497. // pvCtrlPara points to a DWORD containing the 0-based index of the
  5498. // certificate to be removed.
  5499. //--------------------------------------------------------------------------
  5500. //+-------------------------------------------------------------------------
  5501. // CMSG_CTRL_ADD_CRL
  5502. //
  5503. // Add a CRL to a signed-data or signed-and-enveloped-data message.
  5504. //
  5505. // pvCtrlPara points to a CRYPT_DATA_BLOB containing the CRL's
  5506. // encoded bytes.
  5507. //--------------------------------------------------------------------------
  5508. //+-------------------------------------------------------------------------
  5509. // CMSG_CTRL_DEL_CRL
  5510. //
  5511. // Delete a CRL from a signed-data or signed-and-enveloped-data message.
  5512. //
  5513. // pvCtrlPara points to a DWORD containing the 0-based index of the CRL
  5514. // to be removed.
  5515. //--------------------------------------------------------------------------
  5516. //+-------------------------------------------------------------------------
  5517. // CMSG_CTRL_ADD_ATTR_CERT
  5518. //
  5519. // Add an attribute certificate to a signed-data message.
  5520. //
  5521. // pvCtrlPara points to a CRYPT_DATA_BLOB containing the attribute
  5522. // certificate's encoded bytes.
  5523. //--------------------------------------------------------------------------
  5524. //+-------------------------------------------------------------------------
  5525. // CMSG_CTRL_DEL_ATTR_CERT
  5526. //
  5527. // Delete an attribute certificate from a signed-data message.
  5528. //
  5529. // pvCtrlPara points to a DWORD containing the 0-based index of the
  5530. // attribute certificate to be removed.
  5531. //--------------------------------------------------------------------------
  5532. //+-------------------------------------------------------------------------
  5533. // Verify a countersignature, at the SignerInfo level.
  5534. // ie. verify that pbSignerInfoCountersignature contains the encrypted
  5535. // hash of the encryptedDigest field of pbSignerInfo.
  5536. //
  5537. // hCryptProv is used to hash the encryptedDigest field of pbSignerInfo.
  5538. // The only fields referenced from pciCountersigner are SerialNumber, Issuer,
  5539. // and SubjectPublicKeyInfo.
  5540. //--------------------------------------------------------------------------
  5541. BOOL
  5542. WINAPI
  5543. CryptMsgVerifyCountersignatureEncoded(
  5544. IN HCRYPTPROV hCryptProv,
  5545. IN DWORD dwEncodingType,
  5546. IN PBYTE pbSignerInfo,
  5547. IN DWORD cbSignerInfo,
  5548. IN PBYTE pbSignerInfoCountersignature,
  5549. IN DWORD cbSignerInfoCountersignature,
  5550. IN PCERT_INFO pciCountersigner
  5551. );
  5552. //+-------------------------------------------------------------------------
  5553. // Verify a countersignature, at the SignerInfo level.
  5554. // ie. verify that pbSignerInfoCountersignature contains the encrypted
  5555. // hash of the encryptedDigest field of pbSignerInfo.
  5556. //
  5557. // hCryptProv is used to hash the encryptedDigest field of pbSignerInfo.
  5558. //
  5559. // The signer can be a CERT_PUBLIC_KEY_INFO, certificate context or a
  5560. // chain context.
  5561. //--------------------------------------------------------------------------
  5562. BOOL
  5563. WINAPI
  5564. CryptMsgVerifyCountersignatureEncodedEx(
  5565. IN HCRYPTPROV hCryptProv,
  5566. IN DWORD dwEncodingType,
  5567. IN PBYTE pbSignerInfo,
  5568. IN DWORD cbSignerInfo,
  5569. IN PBYTE pbSignerInfoCountersignature,
  5570. IN DWORD cbSignerInfoCountersignature,
  5571. IN DWORD dwSignerType,
  5572. IN void *pvSigner,
  5573. IN DWORD dwFlags,
  5574. IN OPTIONAL void *pvReserved
  5575. );
  5576. // See CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA for dwSignerType definitions
  5577. //+-------------------------------------------------------------------------
  5578. // Countersign an already-existing signature in a message
  5579. //
  5580. // dwIndex is a zero-based index of the SignerInfo to be countersigned.
  5581. //--------------------------------------------------------------------------
  5582. BOOL
  5583. WINAPI
  5584. CryptMsgCountersign(
  5585. IN OUT HCRYPTMSG hCryptMsg,
  5586. IN DWORD dwIndex,
  5587. IN DWORD cCountersigners,
  5588. IN PCMSG_SIGNER_ENCODE_INFO rgCountersigners
  5589. );
  5590. //+-------------------------------------------------------------------------
  5591. // Countersign an already-existing signature (encoded SignerInfo).
  5592. // Output an encoded SignerInfo blob, suitable for use as a countersignature
  5593. // attribute in the unauthenticated attributes of a signed-data or
  5594. // signed-and-enveloped-data message.
  5595. //--------------------------------------------------------------------------
  5596. BOOL
  5597. WINAPI
  5598. CryptMsgCountersignEncoded(
  5599. IN DWORD dwEncodingType,
  5600. IN PBYTE pbSignerInfo,
  5601. IN DWORD cbSignerInfo,
  5602. IN DWORD cCountersigners,
  5603. IN PCMSG_SIGNER_ENCODE_INFO rgCountersigners,
  5604. OUT PBYTE pbCountersignature,
  5605. IN OUT PDWORD pcbCountersignature
  5606. );
  5607. //+-------------------------------------------------------------------------
  5608. // CryptMsg OID installable functions
  5609. //--------------------------------------------------------------------------
  5610. typedef void * (WINAPI *PFN_CMSG_ALLOC) (
  5611. IN size_t cb
  5612. );
  5613. typedef void (WINAPI *PFN_CMSG_FREE)(
  5614. IN void *pv
  5615. );
  5616. // Note, the following 3 installable functions are obsolete and have been
  5617. // replaced with GenContentEncryptKey, ExportKeyTrans, ExportKeyAgree,
  5618. // ExportMailList, ImportKeyTrans, ImportKeyAgree and ImportMailList
  5619. // installable functions.
  5620. // If *phCryptProv is NULL upon entry, then, if supported, the installable
  5621. // function should acquire a default provider and return. Note, its up
  5622. // to the installable function to release at process detach.
  5623. //
  5624. // If paiEncrypt->Parameters.cbData is 0, then, the callback may optionally
  5625. // return default encoded parameters in *ppbEncryptParameters and
  5626. // *pcbEncryptParameters. pfnAlloc must be called for the allocation.
  5627. #define CMSG_OID_GEN_ENCRYPT_KEY_FUNC "CryptMsgDllGenEncryptKey"
  5628. typedef BOOL (WINAPI *PFN_CMSG_GEN_ENCRYPT_KEY) (
  5629. IN OUT HCRYPTPROV *phCryptProv,
  5630. IN PCRYPT_ALGORITHM_IDENTIFIER paiEncrypt,
  5631. IN PVOID pvEncryptAuxInfo,
  5632. IN PCERT_PUBLIC_KEY_INFO pPublicKeyInfo,
  5633. IN PFN_CMSG_ALLOC pfnAlloc,
  5634. OUT HCRYPTKEY *phEncryptKey,
  5635. OUT PBYTE *ppbEncryptParameters,
  5636. OUT PDWORD pcbEncryptParameters
  5637. );
  5638. #define CMSG_OID_EXPORT_ENCRYPT_KEY_FUNC "CryptMsgDllExportEncryptKey"
  5639. typedef BOOL (WINAPI *PFN_CMSG_EXPORT_ENCRYPT_KEY) (
  5640. IN HCRYPTPROV hCryptProv,
  5641. IN HCRYPTKEY hEncryptKey,
  5642. IN PCERT_PUBLIC_KEY_INFO pPublicKeyInfo,
  5643. OUT PBYTE pbData,
  5644. IN OUT PDWORD pcbData
  5645. );
  5646. #define CMSG_OID_IMPORT_ENCRYPT_KEY_FUNC "CryptMsgDllImportEncryptKey"
  5647. typedef BOOL (WINAPI *PFN_CMSG_IMPORT_ENCRYPT_KEY) (
  5648. IN HCRYPTPROV hCryptProv,
  5649. IN DWORD dwKeySpec,
  5650. IN PCRYPT_ALGORITHM_IDENTIFIER paiEncrypt,
  5651. IN PCRYPT_ALGORITHM_IDENTIFIER paiPubKey,
  5652. IN PBYTE pbEncodedKey,
  5653. IN DWORD cbEncodedKey,
  5654. OUT HCRYPTKEY *phEncryptKey
  5655. );
  5656. // To get the default installable function for GenContentEncryptKey,
  5657. // ExportKeyTrans, ExportKeyAgree, ExportMailList, ImportKeyTrans,
  5658. // ImportKeyAgree or ImportMailList call CryptGetOIDFunctionAddress()
  5659. // with the pszOID argument set to the following constant. dwEncodingType
  5660. // should be set to CRYPT_ASN_ENCODING or X509_ASN_ENCODING.
  5661. #define CMSG_DEFAULT_INSTALLABLE_FUNC_OID ((LPCSTR) 1)
  5662. //+-------------------------------------------------------------------------
  5663. // Content Encrypt Info
  5664. //
  5665. // The following data structure contains the information shared between
  5666. // the GenContentEncryptKey and the ExportKeyTrans, ExportKeyAgree and
  5667. // ExportMailList installable functions.
  5668. //--------------------------------------------------------------------------
  5669. typedef struct _CMSG_CONTENT_ENCRYPT_INFO {
  5670. DWORD cbSize;
  5671. HCRYPTPROV hCryptProv;
  5672. CRYPT_ALGORITHM_IDENTIFIER ContentEncryptionAlgorithm;
  5673. void *pvEncryptionAuxInfo;
  5674. DWORD cRecipients;
  5675. PCMSG_RECIPIENT_ENCODE_INFO rgCmsRecipients;
  5676. PFN_CMSG_ALLOC pfnAlloc;
  5677. PFN_CMSG_FREE pfnFree;
  5678. DWORD dwEncryptFlags;
  5679. HCRYPTKEY hContentEncryptKey;
  5680. DWORD dwFlags;
  5681. } CMSG_CONTENT_ENCRYPT_INFO, *PCMSG_CONTENT_ENCRYPT_INFO;
  5682. #define CMSG_CONTENT_ENCRYPT_PAD_ENCODED_LEN_FLAG 0x00000001
  5683. #define CMSG_CONTENT_ENCRYPT_FREE_PARA_FLAG 0x00000001
  5684. #define CMSG_CONTENT_ENCRYPT_RELEASE_CONTEXT_FLAG 0x00008000
  5685. //+-------------------------------------------------------------------------
  5686. // Upon input, ContentEncryptInfo has been initialized from the
  5687. // EnvelopedEncodeInfo.
  5688. //
  5689. // Note, if rgpRecipients instead of rgCmsRecipients are set in the
  5690. // EnvelopedEncodeInfo, then, the rgpRecipients have been converted
  5691. // to rgCmsRecipients in the ContentEncryptInfo.
  5692. //
  5693. // The following fields may be changed in ContentEncryptInfo:
  5694. // hContentEncryptKey
  5695. // hCryptProv
  5696. // ContentEncryptionAlgorithm.Parameters
  5697. // dwFlags
  5698. //
  5699. // All other fields in the ContentEncryptInfo are READONLY.
  5700. //
  5701. // If CMSG_CONTENT_ENCRYPT_PAD_ENCODED_LEN_FLAG is set upon entry
  5702. // in dwEncryptFlags, then, any potentially variable length encoded
  5703. // output should be padded with zeroes to always obtain the
  5704. // same maximum encoded length. This is necessary for
  5705. // CryptMsgCalculateEncodedLength() or CryptMsgOpenToEncode() with
  5706. // definite length streaming.
  5707. //
  5708. // The hContentEncryptKey must be updated.
  5709. //
  5710. // If hCryptProv is NULL upon input, then, it must be updated.
  5711. // If a HCRYPTPROV is acquired that must be released, then, the
  5712. // CMSG_CONTENT_ENCRYPT_RELEASE_CONTEXT_FLAG must be set in dwFlags.
  5713. //
  5714. // If ContentEncryptionAlgorithm.Parameters is updated, then, the
  5715. // CMSG_CONTENT_ENCRYPT_FREE_PARA_FLAG must be set in dwFlags. pfnAlloc and
  5716. // pfnFree must be used for doing the allocation.
  5717. //
  5718. // ContentEncryptionAlgorithm.pszObjId is used to get the OIDFunctionAddress.
  5719. //--------------------------------------------------------------------------
  5720. #define CMSG_OID_GEN_CONTENT_ENCRYPT_KEY_FUNC "CryptMsgDllGenContentEncryptKey"
  5721. typedef BOOL (WINAPI *PFN_CMSG_GEN_CONTENT_ENCRYPT_KEY) (
  5722. IN OUT PCMSG_CONTENT_ENCRYPT_INFO pContentEncryptInfo,
  5723. IN DWORD dwFlags,
  5724. IN OPTIONAL void *pvReserved
  5725. );
  5726. //+-------------------------------------------------------------------------
  5727. // Key Transport Encrypt Info
  5728. //
  5729. // The following data structure contains the information updated by the
  5730. // ExportKeyTrans installable function.
  5731. //--------------------------------------------------------------------------
  5732. typedef struct _CMSG_KEY_TRANS_ENCRYPT_INFO {
  5733. DWORD cbSize;
  5734. DWORD dwRecipientIndex;
  5735. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  5736. CRYPT_DATA_BLOB EncryptedKey;
  5737. DWORD dwFlags;
  5738. } CMSG_KEY_TRANS_ENCRYPT_INFO, *PCMSG_KEY_TRANS_ENCRYPT_INFO;
  5739. #define CMSG_KEY_TRANS_ENCRYPT_FREE_PARA_FLAG 0x00000001
  5740. //+-------------------------------------------------------------------------
  5741. // Upon input, KeyTransEncryptInfo has been initialized from the
  5742. // KeyTransEncodeInfo.
  5743. //
  5744. // The following fields may be changed in KeyTransEncryptInfo:
  5745. // EncryptedKey
  5746. // KeyEncryptionAlgorithm.Parameters
  5747. // dwFlags
  5748. //
  5749. // All other fields in the KeyTransEncryptInfo are READONLY.
  5750. //
  5751. // The EncryptedKey must be updated. The pfnAlloc and pfnFree specified in
  5752. // ContentEncryptInfo must be used for doing the allocation.
  5753. //
  5754. // If the KeyEncryptionAlgorithm.Parameters is updated, then, the
  5755. // CMSG_KEY_TRANS_ENCRYPT_FREE_PARA_FLAG must be set in dwFlags.
  5756. // The pfnAlloc and pfnFree specified in ContentEncryptInfo must be used
  5757. // for doing the allocation.
  5758. //
  5759. // KeyEncryptionAlgorithm.pszObjId is used to get the OIDFunctionAddress.
  5760. //--------------------------------------------------------------------------
  5761. #define CMSG_OID_EXPORT_KEY_TRANS_FUNC "CryptMsgDllExportKeyTrans"
  5762. typedef BOOL (WINAPI *PFN_CMSG_EXPORT_KEY_TRANS) (
  5763. IN PCMSG_CONTENT_ENCRYPT_INFO pContentEncryptInfo,
  5764. IN PCMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO pKeyTransEncodeInfo,
  5765. IN OUT PCMSG_KEY_TRANS_ENCRYPT_INFO pKeyTransEncryptInfo,
  5766. IN DWORD dwFlags,
  5767. IN OPTIONAL void *pvReserved
  5768. );
  5769. //+-------------------------------------------------------------------------
  5770. // Key Agree Key Encrypt Info
  5771. //
  5772. // The following data structure contains the information updated by the
  5773. // ExportKeyAgree installable function for each encrypted key agree
  5774. // recipient.
  5775. //--------------------------------------------------------------------------
  5776. typedef struct _CMSG_KEY_AGREE_KEY_ENCRYPT_INFO {
  5777. DWORD cbSize;
  5778. CRYPT_DATA_BLOB EncryptedKey;
  5779. } CMSG_KEY_AGREE_KEY_ENCRYPT_INFO, *PCMSG_KEY_AGREE_KEY_ENCRYPT_INFO;
  5780. //+-------------------------------------------------------------------------
  5781. // Key Agree Encrypt Info
  5782. //
  5783. // The following data structure contains the information applicable to
  5784. // all recipients. Its updated by the ExportKeyAgree installable function.
  5785. //--------------------------------------------------------------------------
  5786. typedef struct _CMSG_KEY_AGREE_ENCRYPT_INFO {
  5787. DWORD cbSize;
  5788. DWORD dwRecipientIndex;
  5789. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  5790. CRYPT_DATA_BLOB UserKeyingMaterial;
  5791. DWORD dwOriginatorChoice;
  5792. union {
  5793. // CMSG_KEY_AGREE_ORIGINATOR_CERT
  5794. CERT_ID OriginatorCertId;
  5795. // CMSG_KEY_AGREE_ORIGINATOR_PUBLIC_KEY
  5796. CERT_PUBLIC_KEY_INFO OriginatorPublicKeyInfo;
  5797. };
  5798. DWORD cKeyAgreeKeyEncryptInfo;
  5799. PCMSG_KEY_AGREE_KEY_ENCRYPT_INFO *rgpKeyAgreeKeyEncryptInfo;
  5800. DWORD dwFlags;
  5801. } CMSG_KEY_AGREE_ENCRYPT_INFO, *PCMSG_KEY_AGREE_ENCRYPT_INFO;
  5802. #define CMSG_KEY_AGREE_ENCRYPT_FREE_PARA_FLAG 0x00000001
  5803. #define CMSG_KEY_AGREE_ENCRYPT_FREE_MATERIAL_FLAG 0x00000002
  5804. #define CMSG_KEY_AGREE_ENCRYPT_FREE_PUBKEY_ALG_FLAG 0x00000004
  5805. #define CMSG_KEY_AGREE_ENCRYPT_FREE_PUBKEY_PARA_FLAG 0x00000008
  5806. #define CMSG_KEY_AGREE_ENCRYPT_FREE_PUBKEY_BITS_FLAG 0x00000010
  5807. //+-------------------------------------------------------------------------
  5808. // Upon input, KeyAgreeEncryptInfo has been initialized from the
  5809. // KeyAgreeEncodeInfo.
  5810. //
  5811. // The following fields may be changed in KeyAgreeEncryptInfo:
  5812. // KeyEncryptionAlgorithm.Parameters
  5813. // UserKeyingMaterial
  5814. // dwOriginatorChoice
  5815. // OriginatorCertId
  5816. // OriginatorPublicKeyInfo
  5817. // dwFlags
  5818. //
  5819. // All other fields in the KeyAgreeEncryptInfo are READONLY.
  5820. //
  5821. // If the KeyEncryptionAlgorithm.Parameters is updated, then, the
  5822. // CMSG_KEY_AGREE_ENCRYPT_FREE_PARA_FLAG must be set in dwFlags.
  5823. // The pfnAlloc and pfnFree specified in ContentEncryptInfo must be used
  5824. // for doing the allocation.
  5825. //
  5826. // If the UserKeyingMaterial is updated, then, the
  5827. // CMSG_KEY_AGREE_ENCRYPT_FREE_MATERIAL_FLAG must be set in dwFlags.
  5828. // pfnAlloc and pfnFree must be used for doing the allocation.
  5829. //
  5830. // The dwOriginatorChoice must be updated to either
  5831. // CMSG_KEY_AGREE_ORIGINATOR_CERT or CMSG_KEY_AGREE_ORIGINATOR_PUBLIC_KEY.
  5832. //
  5833. // If the OriginatorPublicKeyInfo is updated, then, the appropriate
  5834. // CMSG_KEY_AGREE_ENCRYPT_FREE_PUBKEY_*_FLAG must be set in dwFlags and
  5835. // pfnAlloc and pfnFree must be used for doing the allocation.
  5836. //
  5837. // If CMSG_CONTENT_ENCRYPT_PAD_ENCODED_LEN_FLAG is set upon entry
  5838. // in pContentEncryptInfo->dwEncryptFlags, then, the OriginatorPublicKeyInfo's
  5839. // Ephemeral PublicKey should be padded with zeroes to always obtain the
  5840. // same maximum encoded length. Note, the length of the generated ephemeral Y
  5841. // public key can vary depending on the number of leading zero bits.
  5842. //
  5843. // Upon input, the array of *rgpKeyAgreeKeyEncryptInfo has been initialized.
  5844. // The EncryptedKey must be updated for each recipient key.
  5845. // The pfnAlloc and pfnFree specified in
  5846. // ContentEncryptInfo must be used for doing the allocation.
  5847. //
  5848. // KeyEncryptionAlgorithm.pszObjId is used to get the OIDFunctionAddress.
  5849. //--------------------------------------------------------------------------
  5850. #define CMSG_OID_EXPORT_KEY_AGREE_FUNC "CryptMsgDllExportKeyAgree"
  5851. typedef BOOL (WINAPI *PFN_CMSG_EXPORT_KEY_AGREE) (
  5852. IN PCMSG_CONTENT_ENCRYPT_INFO pContentEncryptInfo,
  5853. IN PCMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO pKeyAgreeEncodeInfo,
  5854. IN OUT PCMSG_KEY_AGREE_ENCRYPT_INFO pKeyAgreeEncryptInfo,
  5855. IN DWORD dwFlags,
  5856. IN OPTIONAL void *pvReserved
  5857. );
  5858. //+-------------------------------------------------------------------------
  5859. // Mail List Encrypt Info
  5860. //
  5861. // The following data structure contains the information updated by the
  5862. // ExportMailList installable function.
  5863. //--------------------------------------------------------------------------
  5864. typedef struct _CMSG_MAIL_LIST_ENCRYPT_INFO {
  5865. DWORD cbSize;
  5866. DWORD dwRecipientIndex;
  5867. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  5868. CRYPT_DATA_BLOB EncryptedKey;
  5869. DWORD dwFlags;
  5870. } CMSG_MAIL_LIST_ENCRYPT_INFO, *PCMSG_MAIL_LIST_ENCRYPT_INFO;
  5871. #define CMSG_MAIL_LIST_ENCRYPT_FREE_PARA_FLAG 0x00000001
  5872. //+-------------------------------------------------------------------------
  5873. // Upon input, MailListEncryptInfo has been initialized from the
  5874. // MailListEncodeInfo.
  5875. //
  5876. // The following fields may be changed in MailListEncryptInfo:
  5877. // EncryptedKey
  5878. // KeyEncryptionAlgorithm.Parameters
  5879. // dwFlags
  5880. //
  5881. // All other fields in the MailListEncryptInfo are READONLY.
  5882. //
  5883. // The EncryptedKey must be updated. The pfnAlloc and pfnFree specified in
  5884. // ContentEncryptInfo must be used for doing the allocation.
  5885. //
  5886. // If the KeyEncryptionAlgorithm.Parameters is updated, then, the
  5887. // CMSG_MAIL_LIST_ENCRYPT_FREE_PARA_FLAG must be set in dwFlags.
  5888. // The pfnAlloc and pfnFree specified in ContentEncryptInfo must be used
  5889. // for doing the allocation.
  5890. //
  5891. // KeyEncryptionAlgorithm.pszObjId is used to get the OIDFunctionAddress.
  5892. //--------------------------------------------------------------------------
  5893. #define CMSG_OID_EXPORT_MAIL_LIST_FUNC "CryptMsgDllExportMailList"
  5894. typedef BOOL (WINAPI *PFN_CMSG_EXPORT_MAIL_LIST) (
  5895. IN PCMSG_CONTENT_ENCRYPT_INFO pContentEncryptInfo,
  5896. IN PCMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO pMailListEncodeInfo,
  5897. IN OUT PCMSG_MAIL_LIST_ENCRYPT_INFO pMailListEncryptInfo,
  5898. IN DWORD dwFlags,
  5899. IN OPTIONAL void *pvReserved
  5900. );
  5901. //+-------------------------------------------------------------------------
  5902. // OID Installable functions for importing an encoded and encrypted content
  5903. // encryption key.
  5904. //
  5905. // There's a different installable function for each CMS Recipient choice:
  5906. // ImportKeyTrans
  5907. // ImportKeyAgree
  5908. // ImportMailList
  5909. //
  5910. // Iterates through the following OIDs to get the OID installable function:
  5911. // KeyEncryptionOID!ContentEncryptionOID
  5912. // KeyEncryptionOID
  5913. // ContentEncryptionOID
  5914. //
  5915. // If the OID installable function doesn't support the specified
  5916. // KeyEncryption and ContentEncryption OIDs, then, return FALSE with
  5917. // LastError set to E_NOTIMPL.
  5918. //--------------------------------------------------------------------------
  5919. #define CMSG_OID_IMPORT_KEY_TRANS_FUNC "CryptMsgDllImportKeyTrans"
  5920. typedef BOOL (WINAPI *PFN_CMSG_IMPORT_KEY_TRANS) (
  5921. IN PCRYPT_ALGORITHM_IDENTIFIER pContentEncryptionAlgorithm,
  5922. IN PCMSG_CTRL_KEY_TRANS_DECRYPT_PARA pKeyTransDecryptPara,
  5923. IN DWORD dwFlags,
  5924. IN OPTIONAL void *pvReserved,
  5925. OUT HCRYPTKEY *phContentEncryptKey
  5926. );
  5927. #define CMSG_OID_IMPORT_KEY_AGREE_FUNC "CryptMsgDllImportKeyAgree"
  5928. typedef BOOL (WINAPI *PFN_CMSG_IMPORT_KEY_AGREE) (
  5929. IN PCRYPT_ALGORITHM_IDENTIFIER pContentEncryptionAlgorithm,
  5930. IN PCMSG_CTRL_KEY_AGREE_DECRYPT_PARA pKeyAgreeDecryptPara,
  5931. IN DWORD dwFlags,
  5932. IN OPTIONAL void *pvReserved,
  5933. OUT HCRYPTKEY *phContentEncryptKey
  5934. );
  5935. #define CMSG_OID_IMPORT_MAIL_LIST_FUNC "CryptMsgDllImportMailList"
  5936. typedef BOOL (WINAPI *PFN_CMSG_IMPORT_MAIL_LIST) (
  5937. IN PCRYPT_ALGORITHM_IDENTIFIER pContentEncryptionAlgorithm,
  5938. IN PCMSG_CTRL_MAIL_LIST_DECRYPT_PARA pMailListDecryptPara,
  5939. IN DWORD dwFlags,
  5940. IN OPTIONAL void *pvReserved,
  5941. OUT HCRYPTKEY *phContentEncryptKey
  5942. );
  5943. //+=========================================================================
  5944. // Certificate Store Data Structures and APIs
  5945. //==========================================================================
  5946. //+-------------------------------------------------------------------------
  5947. // In its most basic implementation, a cert store is simply a
  5948. // collection of certificates and/or CRLs. This is the case when
  5949. // a cert store is opened with all of its certificates and CRLs
  5950. // coming from a PKCS #7 encoded cryptographic message.
  5951. //
  5952. // Nonetheless, all cert stores have the following properties:
  5953. // - A public key may have more than one certificate in the store.
  5954. // For example, a private/public key used for signing may have a
  5955. // certificate issued for VISA and another issued for
  5956. // Mastercard. Also, when a certificate is renewed there might
  5957. // be more than one certificate with the same subject and
  5958. // issuer.
  5959. // - However, each certificate in the store is uniquely
  5960. // identified by its Issuer and SerialNumber.
  5961. // - There's an issuer of subject certificate relationship. A
  5962. // certificate's issuer is found by doing a match of
  5963. // pSubjectCert->Issuer with pIssuerCert->Subject.
  5964. // The relationship is verified by using
  5965. // the issuer's public key to verify the subject certificate's
  5966. // signature. Note, there might be X.509 v3 extensions
  5967. // to assist in finding the issuer certificate.
  5968. // - Since issuer certificates might be renewed, a subject
  5969. // certificate might have more than one issuer certificate.
  5970. // - There's an issuer of CRL relationship. An
  5971. // issuer's CRL is found by doing a match of
  5972. // pIssuerCert->Subject with pCrl->Issuer.
  5973. // The relationship is verified by using
  5974. // the issuer's public key to verify the CRL's
  5975. // signature. Note, there might be X.509 v3 extensions
  5976. // to assist in finding the CRL.
  5977. // - Since some issuers might support the X.509 v3 delta CRL
  5978. // extensions, an issuer might have more than one CRL.
  5979. // - The store shouldn't have any redundant certificates or
  5980. // CRLs. There shouldn't be two certificates with the same
  5981. // Issuer and SerialNumber. There shouldn't be two CRLs with
  5982. // the same Issuer, ThisUpdate and NextUpdate.
  5983. // - The store has NO policy or trust information. No
  5984. // certificates are tagged as being "root". Its up to
  5985. // the application to maintain a list of CertIds (Issuer +
  5986. // SerialNumber) for certificates it trusts.
  5987. // - The store might contain bad certificates and/or CRLs.
  5988. // The issuer's signature of a subject certificate or CRL may
  5989. // not verify. Certificates or CRLs may not satisfy their
  5990. // time validity requirements. Certificates may be
  5991. // revoked.
  5992. //
  5993. // In addition to the certificates and CRLs, properties can be
  5994. // stored. There are two predefined property IDs for a user
  5995. // certificate: CERT_KEY_PROV_HANDLE_PROP_ID and
  5996. // CERT_KEY_PROV_INFO_PROP_ID. The CERT_KEY_PROV_HANDLE_PROP_ID
  5997. // is a HCRYPTPROV handle to the private key assoicated
  5998. // with the certificate. The CERT_KEY_PROV_INFO_PROP_ID contains
  5999. // information to be used to call
  6000. // CryptAcquireContext and CryptSetProvParam to get a handle
  6001. // to the private key associated with the certificate.
  6002. //
  6003. // There exists two more predefined property IDs for certificates
  6004. // and CRLs, CERT_SHA1_HASH_PROP_ID and CERT_MD5_HASH_PROP_ID.
  6005. // If these properties don't already exist, then, a hash of the
  6006. // content is computed. (CERT_HASH_PROP_ID maps to the default
  6007. // hash algorithm, currently, CERT_SHA1_HASH_PROP_ID).
  6008. //
  6009. // There are additional APIs for creating certificate and CRL
  6010. // contexts not in a store (CertCreateCertificateContext and
  6011. // CertCreateCRLContext).
  6012. //
  6013. //--------------------------------------------------------------------------
  6014. typedef void *HCERTSTORE;
  6015. //+-------------------------------------------------------------------------
  6016. // Certificate context.
  6017. //
  6018. // A certificate context contains both the encoded and decoded representation
  6019. // of a certificate. A certificate context returned by a cert store function
  6020. // must be freed by calling the CertFreeCertificateContext function. The
  6021. // CertDuplicateCertificateContext function can be called to make a duplicate
  6022. // copy (which also must be freed by calling CertFreeCertificateContext).
  6023. //--------------------------------------------------------------------------
  6024. typedef struct _CERT_CONTEXT {
  6025. DWORD dwCertEncodingType;
  6026. BYTE *pbCertEncoded;
  6027. DWORD cbCertEncoded;
  6028. PCERT_INFO pCertInfo;
  6029. HCERTSTORE hCertStore;
  6030. } CERT_CONTEXT, *PCERT_CONTEXT;
  6031. typedef const CERT_CONTEXT *PCCERT_CONTEXT;
  6032. //+-------------------------------------------------------------------------
  6033. // CRL context.
  6034. //
  6035. // A CRL context contains both the encoded and decoded representation
  6036. // of a CRL. A CRL context returned by a cert store function
  6037. // must be freed by calling the CertFreeCRLContext function. The
  6038. // CertDuplicateCRLContext function can be called to make a duplicate
  6039. // copy (which also must be freed by calling CertFreeCRLContext).
  6040. //--------------------------------------------------------------------------
  6041. typedef struct _CRL_CONTEXT {
  6042. DWORD dwCertEncodingType;
  6043. BYTE *pbCrlEncoded;
  6044. DWORD cbCrlEncoded;
  6045. PCRL_INFO pCrlInfo;
  6046. HCERTSTORE hCertStore;
  6047. } CRL_CONTEXT, *PCRL_CONTEXT;
  6048. typedef const CRL_CONTEXT *PCCRL_CONTEXT;
  6049. //+-------------------------------------------------------------------------
  6050. // Certificate Trust List (CTL) context.
  6051. //
  6052. // A CTL context contains both the encoded and decoded representation
  6053. // of a CTL. Also contains an opened HCRYPTMSG handle to the decoded
  6054. // cryptographic signed message containing the CTL_INFO as its inner content.
  6055. // pbCtlContent is the encoded inner content of the signed message.
  6056. //
  6057. // The CryptMsg APIs can be used to extract additional signer information.
  6058. //--------------------------------------------------------------------------
  6059. typedef struct _CTL_CONTEXT {
  6060. DWORD dwMsgAndCertEncodingType;
  6061. BYTE *pbCtlEncoded;
  6062. DWORD cbCtlEncoded;
  6063. PCTL_INFO pCtlInfo;
  6064. HCERTSTORE hCertStore;
  6065. HCRYPTMSG hCryptMsg;
  6066. BYTE *pbCtlContent;
  6067. DWORD cbCtlContent;
  6068. } CTL_CONTEXT, *PCTL_CONTEXT;
  6069. typedef const CTL_CONTEXT *PCCTL_CONTEXT;
  6070. //+-------------------------------------------------------------------------
  6071. // Certificate, CRL and CTL property IDs
  6072. //
  6073. // See CertSetCertificateContextProperty or CertGetCertificateContextProperty
  6074. // for usage information.
  6075. //--------------------------------------------------------------------------
  6076. #define CERT_KEY_PROV_HANDLE_PROP_ID 1
  6077. #define CERT_KEY_PROV_INFO_PROP_ID 2
  6078. #define CERT_SHA1_HASH_PROP_ID 3
  6079. #define CERT_MD5_HASH_PROP_ID 4
  6080. #define CERT_HASH_PROP_ID CERT_SHA1_HASH_PROP_ID
  6081. #define CERT_KEY_CONTEXT_PROP_ID 5
  6082. #define CERT_KEY_SPEC_PROP_ID 6
  6083. #define CERT_IE30_RESERVED_PROP_ID 7
  6084. #define CERT_PUBKEY_HASH_RESERVED_PROP_ID 8
  6085. #define CERT_ENHKEY_USAGE_PROP_ID 9
  6086. #define CERT_CTL_USAGE_PROP_ID CERT_ENHKEY_USAGE_PROP_ID
  6087. #define CERT_NEXT_UPDATE_LOCATION_PROP_ID 10
  6088. #define CERT_FRIENDLY_NAME_PROP_ID 11
  6089. #define CERT_PVK_FILE_PROP_ID 12
  6090. #define CERT_DESCRIPTION_PROP_ID 13
  6091. #define CERT_ACCESS_STATE_PROP_ID 14
  6092. #define CERT_SIGNATURE_HASH_PROP_ID 15
  6093. #define CERT_SMART_CARD_DATA_PROP_ID 16
  6094. #define CERT_EFS_PROP_ID 17
  6095. #define CERT_FORTEZZA_DATA_PROP_ID 18
  6096. #define CERT_ARCHIVED_PROP_ID 19
  6097. #define CERT_KEY_IDENTIFIER_PROP_ID 20
  6098. #define CERT_AUTO_ENROLL_PROP_ID 21
  6099. #define CERT_PUBKEY_ALG_PARA_PROP_ID 22
  6100. #define CERT_CROSS_CERT_DIST_POINTS_PROP_ID 23
  6101. #define CERT_ISSUER_PUBLIC_KEY_MD5_HASH_PROP_ID 24
  6102. #define CERT_SUBJECT_PUBLIC_KEY_MD5_HASH_PROP_ID 25
  6103. #define CERT_ENROLLMENT_PROP_ID 26
  6104. #define CERT_DATE_STAMP_PROP_ID 27
  6105. #define CERT_ISSUER_SERIAL_NUMBER_MD5_HASH_PROP_ID 28
  6106. #define CERT_SUBJECT_NAME_MD5_HASH_PROP_ID 29
  6107. #define CERT_EXTENDED_ERROR_INFO_PROP_ID 30
  6108. // Note, 32 - 35 are reserved for the CERT, CRL, CTL and KeyId file element IDs.
  6109. // 36 - 63 are reserved for future element IDs.
  6110. #define CERT_RENEWAL_PROP_ID 64
  6111. #define CERT_ARCHIVED_KEY_HASH_PROP_ID 65
  6112. #define CERT_AUTO_ENROLL_RETRY_PROP_ID 66
  6113. #define CERT_AIA_URL_RETRIEVED_PROP_ID 67
  6114. #define CERT_FIRST_RESERVED_PROP_ID 68
  6115. #define CERT_LAST_RESERVED_PROP_ID 0x00007FFF
  6116. #define CERT_FIRST_USER_PROP_ID 0x00008000
  6117. #define CERT_LAST_USER_PROP_ID 0x0000FFFF
  6118. #define IS_CERT_HASH_PROP_ID(X) (CERT_SHA1_HASH_PROP_ID == (X) || \
  6119. CERT_MD5_HASH_PROP_ID == (X) || \
  6120. CERT_SIGNATURE_HASH_PROP_ID == (X))
  6121. #define IS_PUBKEY_HASH_PROP_ID(X) (CERT_ISSUER_PUBLIC_KEY_MD5_HASH_PROP_ID == (X) || \
  6122. CERT_SUBJECT_PUBLIC_KEY_MD5_HASH_PROP_ID == (X))
  6123. #define IS_CHAIN_HASH_PROP_ID(X) (CERT_ISSUER_PUBLIC_KEY_MD5_HASH_PROP_ID == (X) || \
  6124. CERT_SUBJECT_PUBLIC_KEY_MD5_HASH_PROP_ID == (X) || \
  6125. CERT_ISSUER_SERIAL_NUMBER_MD5_HASH_PROP_ID == (X) || \
  6126. CERT_SUBJECT_NAME_MD5_HASH_PROP_ID == (X))
  6127. //+-------------------------------------------------------------------------
  6128. // Property OIDs
  6129. //--------------------------------------------------------------------------
  6130. // The OID component following the prefix contains the PROP_ID (decimal)
  6131. #define szOID_CERT_PROP_ID_PREFIX "1.3.6.1.4.1.311.10.11."
  6132. #define szOID_CERT_KEY_IDENTIFIER_PROP_ID "1.3.6.1.4.1.311.10.11.20"
  6133. #define szOID_CERT_ISSUER_SERIAL_NUMBER_MD5_HASH_PROP_ID \
  6134. "1.3.6.1.4.1.311.10.11.28"
  6135. #define szOID_CERT_SUBJECT_NAME_MD5_HASH_PROP_ID \
  6136. "1.3.6.1.4.1.311.10.11.29"
  6137. //+-------------------------------------------------------------------------
  6138. // Access State flags returned by CERT_ACCESS_STATE_PROP_ID. Note,
  6139. // CERT_ACCESS_PROP_ID is read only.
  6140. //--------------------------------------------------------------------------
  6141. // Set if context property writes are persisted. For instance, not set for
  6142. // memory store contexts. Set for registry based stores opened as read or write.
  6143. // Not set for registry based stores opened as read only.
  6144. #define CERT_ACCESS_STATE_WRITE_PERSIST_FLAG 0x1
  6145. // Set if context resides in a SYSTEM or SYSTEM_REGISTRY store.
  6146. #define CERT_ACCESS_STATE_SYSTEM_STORE_FLAG 0x2
  6147. // Set if context resides in a LocalMachine SYSTEM or SYSTEM_REGISTRY store.
  6148. #define CERT_ACCESS_STATE_LM_SYSTEM_STORE_FLAG 0x4
  6149. //+-------------------------------------------------------------------------
  6150. // Cryptographic Key Provider Information
  6151. //
  6152. // CRYPT_KEY_PROV_INFO defines the CERT_KEY_PROV_INFO_PROP_ID's pvData.
  6153. //
  6154. // The CRYPT_KEY_PROV_INFO fields are passed to CryptAcquireContext
  6155. // to get a HCRYPTPROV handle. The optional CRYPT_KEY_PROV_PARAM fields are
  6156. // passed to CryptSetProvParam to further initialize the provider.
  6157. //
  6158. // The dwKeySpec field identifies the private key to use from the container
  6159. // For example, AT_KEYEXCHANGE or AT_SIGNATURE.
  6160. //--------------------------------------------------------------------------
  6161. typedef struct _CRYPT_KEY_PROV_PARAM {
  6162. DWORD dwParam;
  6163. BYTE *pbData;
  6164. DWORD cbData;
  6165. DWORD dwFlags;
  6166. } CRYPT_KEY_PROV_PARAM, *PCRYPT_KEY_PROV_PARAM;
  6167. typedef struct _CRYPT_KEY_PROV_INFO {
  6168. LPWSTR pwszContainerName;
  6169. LPWSTR pwszProvName;
  6170. DWORD dwProvType;
  6171. DWORD dwFlags;
  6172. DWORD cProvParam;
  6173. PCRYPT_KEY_PROV_PARAM rgProvParam;
  6174. DWORD dwKeySpec;
  6175. } CRYPT_KEY_PROV_INFO, *PCRYPT_KEY_PROV_INFO;
  6176. //+-------------------------------------------------------------------------
  6177. // The following flag should be set in the above dwFlags to enable
  6178. // a CertSetCertificateContextProperty(CERT_KEY_CONTEXT_PROP_ID) after a
  6179. // CryptAcquireContext is done in the Sign or Decrypt Message functions.
  6180. //
  6181. // The following define must not collide with any of the
  6182. // CryptAcquireContext dwFlag defines.
  6183. //--------------------------------------------------------------------------
  6184. #define CERT_SET_KEY_PROV_HANDLE_PROP_ID 0x00000001
  6185. #define CERT_SET_KEY_CONTEXT_PROP_ID 0x00000001
  6186. //+-------------------------------------------------------------------------
  6187. // Certificate Key Context
  6188. //
  6189. // CERT_KEY_CONTEXT defines the CERT_KEY_CONTEXT_PROP_ID's pvData.
  6190. //--------------------------------------------------------------------------
  6191. typedef struct _CERT_KEY_CONTEXT {
  6192. DWORD cbSize; // sizeof(CERT_KEY_CONTEXT)
  6193. HCRYPTPROV hCryptProv;
  6194. DWORD dwKeySpec;
  6195. } CERT_KEY_CONTEXT, *PCERT_KEY_CONTEXT;
  6196. //+-------------------------------------------------------------------------
  6197. // Certificate Store Provider Types
  6198. //--------------------------------------------------------------------------
  6199. #define CERT_STORE_PROV_MSG ((LPCSTR) 1)
  6200. #define CERT_STORE_PROV_MEMORY ((LPCSTR) 2)
  6201. #define CERT_STORE_PROV_FILE ((LPCSTR) 3)
  6202. #define CERT_STORE_PROV_REG ((LPCSTR) 4)
  6203. #define CERT_STORE_PROV_PKCS7 ((LPCSTR) 5)
  6204. #define CERT_STORE_PROV_SERIALIZED ((LPCSTR) 6)
  6205. #define CERT_STORE_PROV_FILENAME_A ((LPCSTR) 7)
  6206. #define CERT_STORE_PROV_FILENAME_W ((LPCSTR) 8)
  6207. #define CERT_STORE_PROV_FILENAME CERT_STORE_PROV_FILENAME_W
  6208. #define CERT_STORE_PROV_SYSTEM_A ((LPCSTR) 9)
  6209. #define CERT_STORE_PROV_SYSTEM_W ((LPCSTR) 10)
  6210. #define CERT_STORE_PROV_SYSTEM CERT_STORE_PROV_SYSTEM_W
  6211. #define CERT_STORE_PROV_COLLECTION ((LPCSTR) 11)
  6212. #define CERT_STORE_PROV_SYSTEM_REGISTRY_A ((LPCSTR) 12)
  6213. #define CERT_STORE_PROV_SYSTEM_REGISTRY_W ((LPCSTR) 13)
  6214. #define CERT_STORE_PROV_SYSTEM_REGISTRY CERT_STORE_PROV_SYSTEM_REGISTRY_W
  6215. #define CERT_STORE_PROV_PHYSICAL_W ((LPCSTR) 14)
  6216. #define CERT_STORE_PROV_PHYSICAL CERT_STORE_PROV_PHYSICAL_W
  6217. #define CERT_STORE_PROV_SMART_CARD_W ((LPCSTR) 15)
  6218. #define CERT_STORE_PROV_SMART_CARD CERT_STORE_PROV_SMART_CARD_W
  6219. #define CERT_STORE_PROV_LDAP_W ((LPCSTR) 16)
  6220. #define CERT_STORE_PROV_LDAP CERT_STORE_PROV_LDAP_W
  6221. #define sz_CERT_STORE_PROV_MEMORY "Memory"
  6222. #define sz_CERT_STORE_PROV_FILENAME_W "File"
  6223. #define sz_CERT_STORE_PROV_FILENAME sz_CERT_STORE_PROV_FILENAME_W
  6224. #define sz_CERT_STORE_PROV_SYSTEM_W "System"
  6225. #define sz_CERT_STORE_PROV_SYSTEM sz_CERT_STORE_PROV_SYSTEM_W
  6226. #define sz_CERT_STORE_PROV_PKCS7 "PKCS7"
  6227. #define sz_CERT_STORE_PROV_SERIALIZED "Serialized"
  6228. #define sz_CERT_STORE_PROV_COLLECTION "Collection"
  6229. #define sz_CERT_STORE_PROV_SYSTEM_REGISTRY_W "SystemRegistry"
  6230. #define sz_CERT_STORE_PROV_SYSTEM_REGISTRY sz_CERT_STORE_PROV_SYSTEM_REGISTRY_W
  6231. #define sz_CERT_STORE_PROV_PHYSICAL_W "Physical"
  6232. #define sz_CERT_STORE_PROV_PHYSICAL sz_CERT_STORE_PROV_PHYSICAL_W
  6233. #define sz_CERT_STORE_PROV_SMART_CARD_W "SmartCard"
  6234. #define sz_CERT_STORE_PROV_SMART_CARD sz_CERT_STORE_PROV_SMART_CARD_W
  6235. #define sz_CERT_STORE_PROV_LDAP_W "Ldap"
  6236. #define sz_CERT_STORE_PROV_LDAP sz_CERT_STORE_PROV_LDAP_W
  6237. //+-------------------------------------------------------------------------
  6238. // Certificate Store verify/results flags
  6239. //--------------------------------------------------------------------------
  6240. #define CERT_STORE_SIGNATURE_FLAG 0x00000001
  6241. #define CERT_STORE_TIME_VALIDITY_FLAG 0x00000002
  6242. #define CERT_STORE_REVOCATION_FLAG 0x00000004
  6243. #define CERT_STORE_NO_CRL_FLAG 0x00010000
  6244. #define CERT_STORE_NO_ISSUER_FLAG 0x00020000
  6245. #define CERT_STORE_BASE_CRL_FLAG 0x00000100
  6246. #define CERT_STORE_DELTA_CRL_FLAG 0x00000200
  6247. //+-------------------------------------------------------------------------
  6248. // Certificate Store open/property flags
  6249. //--------------------------------------------------------------------------
  6250. #define CERT_STORE_NO_CRYPT_RELEASE_FLAG 0x00000001
  6251. #define CERT_STORE_SET_LOCALIZED_NAME_FLAG 0x00000002
  6252. #define CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG 0x00000004
  6253. #define CERT_STORE_DELETE_FLAG 0x00000010
  6254. #define CERT_STORE_UNSAFE_PHYSICAL_FLAG 0x00000020
  6255. #define CERT_STORE_SHARE_STORE_FLAG 0x00000040
  6256. #define CERT_STORE_SHARE_CONTEXT_FLAG 0x00000080
  6257. #define CERT_STORE_MANIFOLD_FLAG 0x00000100
  6258. #define CERT_STORE_ENUM_ARCHIVED_FLAG 0x00000200
  6259. #define CERT_STORE_UPDATE_KEYID_FLAG 0x00000400
  6260. #define CERT_STORE_BACKUP_RESTORE_FLAG 0x00000800
  6261. #define CERT_STORE_READONLY_FLAG 0x00008000
  6262. #define CERT_STORE_OPEN_EXISTING_FLAG 0x00004000
  6263. #define CERT_STORE_CREATE_NEW_FLAG 0x00002000
  6264. #define CERT_STORE_MAXIMUM_ALLOWED_FLAG 0x00001000
  6265. //+-------------------------------------------------------------------------
  6266. // Certificate Store Provider flags are in the HiWord (0xFFFF0000)
  6267. //--------------------------------------------------------------------------
  6268. //+-------------------------------------------------------------------------
  6269. // Certificate System Store Flag Values
  6270. //--------------------------------------------------------------------------
  6271. // Includes flags and location
  6272. #define CERT_SYSTEM_STORE_MASK 0xFFFF0000
  6273. // Set if pvPara points to a CERT_SYSTEM_STORE_RELOCATE_PARA structure
  6274. #define CERT_SYSTEM_STORE_RELOCATE_FLAG 0x80000000
  6275. typedef struct _CERT_SYSTEM_STORE_RELOCATE_PARA {
  6276. union {
  6277. HKEY hKeyBase;
  6278. void *pvBase;
  6279. };
  6280. union {
  6281. void *pvSystemStore;
  6282. LPCSTR pszSystemStore;
  6283. LPCWSTR pwszSystemStore;
  6284. };
  6285. } CERT_SYSTEM_STORE_RELOCATE_PARA, *PCERT_SYSTEM_STORE_RELOCATE_PARA;
  6286. // By default, when the CurrentUser "Root" store is opened, any SystemRegistry
  6287. // roots not also on the protected root list are deleted from the cache before
  6288. // CertOpenStore() returns. Set the following flag to return all the roots
  6289. // in the SystemRegistry without checking the protected root list.
  6290. #define CERT_SYSTEM_STORE_UNPROTECTED_FLAG 0x40000000
  6291. // Location of the system store:
  6292. #define CERT_SYSTEM_STORE_LOCATION_MASK 0x00FF0000
  6293. #define CERT_SYSTEM_STORE_LOCATION_SHIFT 16
  6294. // Registry: HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE
  6295. #define CERT_SYSTEM_STORE_CURRENT_USER_ID 1
  6296. #define CERT_SYSTEM_STORE_LOCAL_MACHINE_ID 2
  6297. // Registry: HKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography\Services
  6298. #define CERT_SYSTEM_STORE_CURRENT_SERVICE_ID 4
  6299. #define CERT_SYSTEM_STORE_SERVICES_ID 5
  6300. // Registry: HKEY_USERS
  6301. #define CERT_SYSTEM_STORE_USERS_ID 6
  6302. // Registry: HKEY_CURRENT_USER\Software\Policies\Microsoft\SystemCertificates
  6303. #define CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY_ID 7
  6304. // Registry: HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\SystemCertificates
  6305. #define CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY_ID 8
  6306. // Registry: HKEY_LOCAL_MACHINE\Software\Microsoft\EnterpriseCertificates
  6307. #define CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE_ID 9
  6308. #define CERT_SYSTEM_STORE_CURRENT_USER \
  6309. (CERT_SYSTEM_STORE_CURRENT_USER_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6310. #define CERT_SYSTEM_STORE_LOCAL_MACHINE \
  6311. (CERT_SYSTEM_STORE_LOCAL_MACHINE_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6312. #define CERT_SYSTEM_STORE_CURRENT_SERVICE \
  6313. (CERT_SYSTEM_STORE_CURRENT_SERVICE_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6314. #define CERT_SYSTEM_STORE_SERVICES \
  6315. (CERT_SYSTEM_STORE_SERVICES_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6316. #define CERT_SYSTEM_STORE_USERS \
  6317. (CERT_SYSTEM_STORE_USERS_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6318. #define CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY \
  6319. (CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY_ID << \
  6320. CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6321. #define CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY \
  6322. (CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY_ID << \
  6323. CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6324. #define CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE \
  6325. (CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE_ID << \
  6326. CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6327. //+-------------------------------------------------------------------------
  6328. // Group Policy Store Defines
  6329. //--------------------------------------------------------------------------
  6330. // Registry path to the Group Policy system stores
  6331. #define CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH \
  6332. L"Software\\Policies\\Microsoft\\SystemCertificates"
  6333. //+-------------------------------------------------------------------------
  6334. // EFS Defines
  6335. //--------------------------------------------------------------------------
  6336. // Registry path to the EFS EFSBlob SubKey - Value type is REG_BINARY
  6337. #define CERT_EFSBLOB_REGPATH \
  6338. CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH L"\\EFS"
  6339. #define CERT_EFSBLOB_VALUE_NAME L"EFSBlob"
  6340. //+-------------------------------------------------------------------------
  6341. // Protected Root Defines
  6342. //--------------------------------------------------------------------------
  6343. // Registry path to the Protected Roots Flags SubKey
  6344. #define CERT_PROT_ROOT_FLAGS_REGPATH \
  6345. CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH L"\\Root\\ProtectedRoots"
  6346. #define CERT_PROT_ROOT_FLAGS_VALUE_NAME L"Flags"
  6347. // Set the following flag to inhibit the opening of the CurrentUser's
  6348. // .Default physical store when opening the CurrentUser's "Root" system store.
  6349. // The .Default physical store open's the CurrentUser SystemRegistry "Root"
  6350. // store.
  6351. #define CERT_PROT_ROOT_DISABLE_CURRENT_USER_FLAG 0x1
  6352. // Set the following flag to inhibit the adding of roots from the
  6353. // CurrentUser SystemRegistry "Root" store to the protected root list
  6354. // when the "Root" store is initially protected.
  6355. #define CERT_PROT_ROOT_INHIBIT_ADD_AT_INIT_FLAG 0x2
  6356. // Set the following flag to inhibit the purging of protected roots from the
  6357. // CurrentUser SystemRegistry "Root" store that are
  6358. // also in the LocalMachine SystemRegistry "Root" store. Note, when not
  6359. // disabled, the purging is done silently without UI.
  6360. #define CERT_PROT_ROOT_INHIBIT_PURGE_LM_FLAG 0x4
  6361. // Set the following flag to inhibit the opening of the LocalMachine's
  6362. // .AuthRoot physical store when opening the LocalMachine's "Root" system store.
  6363. // The .AuthRoot physical store open's the LocalMachine SystemRegistry
  6364. // "AuthRoot" store. The "AuthRoot" store contains the pre-installed
  6365. // SSL ServerAuth and the ActiveX Authenticode "root" certificates.
  6366. #define CERT_PROT_ROOT_DISABLE_LM_AUTH_FLAG 0x8
  6367. // The semantics for the following legacy definition has been changed to be
  6368. // the same as for the CERT_PROT_ROOT_DISABLE_LM_AUTH_FLAG.
  6369. #define CERT_PROT_ROOT_ONLY_LM_GPT_FLAG 0x8
  6370. // Set the following flag to disable the requiring of the issuing CA
  6371. // certificate being in the "NTAuth" system registry store found in the
  6372. // CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE store location.
  6373. //
  6374. // When set, CertVerifyCertificateChainPolicy(CERT_CHAIN_POLICY_NT_AUTH)
  6375. // will check that the chain has a valid name constraint for all name
  6376. // spaces, including UPN if the issuing CA isn't in the "NTAuth" store.
  6377. #define CERT_PROT_ROOT_DISABLE_NT_AUTH_REQUIRED_FLAG 0x10
  6378. // Set the following flag to disable checking for not defined name
  6379. // constraints.
  6380. //
  6381. // When set, CertGetCertificateChain won't check for or set the following
  6382. // dwErrorStatus: CERT_TRUST_HAS_NOT_DEFINED_NAME_CONSTRAINT.
  6383. #define CERT_PROT_ROOT_DISABLE_NOT_DEFINED_NAME_CONSTRAINT_FLAG 0x20
  6384. //+-------------------------------------------------------------------------
  6385. // Trusted Publisher Definitions
  6386. //--------------------------------------------------------------------------
  6387. // Registry path to the trusted publisher "Safer" group policy subkey
  6388. #define CERT_TRUST_PUB_SAFER_GROUP_POLICY_REGPATH \
  6389. CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH L"\\TrustedPublisher\\Safer"
  6390. // Registry path to the Local Machine system stores
  6391. #define CERT_LOCAL_MACHINE_SYSTEM_STORE_REGPATH \
  6392. L"Software\\Microsoft\\SystemCertificates"
  6393. // Registry path to the trusted publisher "Safer" local machine subkey
  6394. #define CERT_TRUST_PUB_SAFER_LOCAL_MACHINE_REGPATH \
  6395. CERT_LOCAL_MACHINE_SYSTEM_STORE_REGPATH L"\\TrustedPublisher\\Safer"
  6396. // "Safer" subkey value names. All values are DWORDs.
  6397. #define CERT_TRUST_PUB_AUTHENTICODE_FLAGS_VALUE_NAME L"AuthenticodeFlags"
  6398. // AuthenticodeFlags definitions
  6399. // Definition of who is allowed to trust publishers
  6400. //
  6401. // Setting allowed trust to MACHINE_ADMIN or ENTERPRISE_ADMIN disables UI,
  6402. // only trusts publishers in the "TrustedPublisher" system store and
  6403. // inhibits the opening of the CurrentUser's .Default physical store when
  6404. // opening the CurrentUsers's "TrustedPublisher" system store.
  6405. //
  6406. // The .Default physical store open's the CurrentUser SystemRegistry
  6407. // "TrustedPublisher" store.
  6408. //
  6409. // Setting allowed trust to ENTERPRISE_ADMIN only opens the
  6410. // LocalMachine's .GroupPolicy and .Enterprise physical stores when opening
  6411. // the CurrentUser's "TrustedPublisher" system store or when opening the
  6412. // LocalMachine's "TrustedPublisher" system store.
  6413. #define CERT_TRUST_PUB_ALLOW_TRUST_MASK 0x00000003
  6414. #define CERT_TRUST_PUB_ALLOW_END_USER_TRUST 0x00000000
  6415. #define CERT_TRUST_PUB_ALLOW_MACHINE_ADMIN_TRUST 0x00000001
  6416. #define CERT_TRUST_PUB_ALLOW_ENTERPRISE_ADMIN_TRUST 0x00000002
  6417. // Set the following flag to enable revocation checking of the publisher
  6418. // chain.
  6419. #define CERT_TRUST_PUB_CHECK_PUBLISHER_REV_FLAG 0x00000100
  6420. // Set the following flag to enable revocation checking of the time stamp
  6421. // chain.
  6422. #define CERT_TRUST_PUB_CHECK_TIMESTAMP_REV_FLAG 0x00000200
  6423. //+-------------------------------------------------------------------------
  6424. // OCM Subcomponents Definitions
  6425. //--------------------------------------------------------------------------
  6426. // Registry path to the OCM Subcomponents local machine subkey
  6427. #define CERT_OCM_SUBCOMPONENTS_LOCAL_MACHINE_REGPATH \
  6428. L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\OC Manager\\Subcomponents"
  6429. // REG_DWORD, 1 is installed, 0 is NOT installed
  6430. #define CERT_OCM_SUBCOMPONENTS_ROOT_AUTO_UPDATE_VALUE_NAME L"RootAutoUpdate"
  6431. //+-------------------------------------------------------------------------
  6432. // AuthRoot Auto Update Definitions
  6433. //--------------------------------------------------------------------------
  6434. // Registry path to the AuthRoot "Auto Update" local machine subkey
  6435. #define CERT_AUTH_ROOT_AUTO_UPDATE_LOCAL_MACHINE_REGPATH \
  6436. CERT_LOCAL_MACHINE_SYSTEM_STORE_REGPATH L"\\AuthRoot\\AutoUpdate"
  6437. // AuthRoot Auto Update subkey value names.
  6438. // REG_SZ, URL to the directory containing the AuthRoots, CTL and Seq files
  6439. #define CERT_AUTH_ROOT_AUTO_UPDATE_ROOT_DIR_URL_VALUE_NAME L"RootDirUrl"
  6440. // REG_DWORD, seconds between syncs. 0 implies use default.
  6441. #define CERT_AUTH_ROOT_AUTO_UPDATE_SYNC_DELTA_TIME_VALUE_NAME L"SyncDeltaTime"
  6442. // REG_DWORD, misc flags
  6443. #define CERT_AUTH_ROOT_AUTO_UPDATE_FLAGS_VALUE_NAME L"Flags"
  6444. #define CERT_AUTH_ROOT_AUTO_UPDATE_DISABLE_UNTRUSTED_ROOT_LOGGING_FLAG 0x1
  6445. #define CERT_AUTH_ROOT_AUTO_UPDATE_DISABLE_PARTIAL_CHAIN_LOGGING_FLAG 0x2
  6446. // AuthRoot Auto Update filenames
  6447. // CTL containing the list of certs in the AuthRoot store
  6448. #define CERT_AUTH_ROOT_CTL_FILENAME L"authroot.stl"
  6449. #define CERT_AUTH_ROOT_CTL_FILENAME_A "authroot.stl"
  6450. // Cab containing the above CTL
  6451. #define CERT_AUTH_ROOT_CAB_FILENAME L"authrootstl.cab"
  6452. // SequenceNumber (Formatted as big endian ascii hex)
  6453. #define CERT_AUTH_ROOT_SEQ_FILENAME L"authrootseq.txt"
  6454. // Root certs extension
  6455. #define CERT_AUTH_ROOT_CERT_EXT L".crt"
  6456. //+-------------------------------------------------------------------------
  6457. // Certificate Registry Store Flag Values (CERT_STORE_REG)
  6458. //--------------------------------------------------------------------------
  6459. // Set this flag if the HKEY passed in pvPara points to a remote computer
  6460. // registry key.
  6461. #define CERT_REGISTRY_STORE_REMOTE_FLAG 0x10000
  6462. // Set this flag if the contexts are to be persisted as a single serialized
  6463. // store in the registry. Mainly used for stores downloaded from the GPT.
  6464. // Such as the CurrentUserGroupPolicy or LocalMachineGroupPolicy stores.
  6465. #define CERT_REGISTRY_STORE_SERIALIZED_FLAG 0x20000
  6466. // The following flags are for internal use. When set, the
  6467. // pvPara parameter passed to CertOpenStore is a pointer to the following
  6468. // data structure and not the HKEY. The above CERT_REGISTRY_STORE_REMOTE_FLAG
  6469. // is also set if hKeyBase was obtained via RegConnectRegistry().
  6470. #define CERT_REGISTRY_STORE_CLIENT_GPT_FLAG 0x80000000
  6471. #define CERT_REGISTRY_STORE_LM_GPT_FLAG 0x01000000
  6472. typedef struct _CERT_REGISTRY_STORE_CLIENT_GPT_PARA {
  6473. HKEY hKeyBase;
  6474. LPWSTR pwszRegPath;
  6475. } CERT_REGISTRY_STORE_CLIENT_GPT_PARA, *PCERT_REGISTRY_STORE_CLIENT_GPT_PARA;
  6476. // The following flag is for internal use. When set, the contexts are
  6477. // persisted into roaming files instead of the registry. Such as, the
  6478. // CurrentUser "My" store. When this flag is set, the following data structure
  6479. // is passed to CertOpenStore instead of HKEY.
  6480. #define CERT_REGISTRY_STORE_ROAMING_FLAG 0x40000
  6481. // hKey may be NULL or non-NULL. When non-NULL, existing contexts are
  6482. // moved from the registry to roaming files.
  6483. typedef struct _CERT_REGISTRY_STORE_ROAMING_PARA {
  6484. HKEY hKey;
  6485. LPWSTR pwszStoreDirectory;
  6486. } CERT_REGISTRY_STORE_ROAMING_PARA, *PCERT_REGISTRY_STORE_ROAMING_PARA;
  6487. // The following flag is for internal use. When set, the "My" DWORD value
  6488. // at HKLM\Software\Microsoft\Cryptography\IEDirtyFlags is set to 0x1
  6489. // whenever a certificate is added to the registry store.
  6490. //
  6491. // Legacy definition, no longer supported after 01-May-02 (Server 2003)
  6492. #define CERT_REGISTRY_STORE_MY_IE_DIRTY_FLAG 0x80000
  6493. // Registry path to the subkey containing the "My" DWORD value to be set
  6494. //
  6495. // Legacy definition, no longer supported after 01-May-02 (Server 2003)
  6496. #define CERT_IE_DIRTY_FLAGS_REGPATH \
  6497. L"Software\\Microsoft\\Cryptography\\IEDirtyFlags"
  6498. //+-------------------------------------------------------------------------
  6499. // Certificate File Store Flag Values for the providers:
  6500. // CERT_STORE_PROV_FILE
  6501. // CERT_STORE_PROV_FILENAME
  6502. // CERT_STORE_PROV_FILENAME_A
  6503. // CERT_STORE_PROV_FILENAME_W
  6504. // sz_CERT_STORE_PROV_FILENAME_W
  6505. //--------------------------------------------------------------------------
  6506. // Set this flag if any store changes are to be committed to the file.
  6507. // The changes are committed at CertCloseStore or by calling
  6508. // CertControlStore(CERT_STORE_CTRL_COMMIT).
  6509. //
  6510. // The open fails with E_INVALIDARG if both CERT_FILE_STORE_COMMIT_ENABLE_FLAG
  6511. // and CERT_STORE_READONLY_FLAG are set in dwFlags.
  6512. //
  6513. // For the FILENAME providers: if the file contains an X509 encoded
  6514. // certificate, the open fails with ERROR_ACCESS_DENIED.
  6515. //
  6516. // For the FILENAME providers: if CERT_STORE_CREATE_NEW_FLAG is set, the
  6517. // CreateFile uses CREATE_NEW. If CERT_STORE_OPEN_EXISTING is set, uses
  6518. // OPEN_EXISTING. Otherwise, defaults to OPEN_ALWAYS.
  6519. //
  6520. // For the FILENAME providers: the file is committed as either a PKCS7 or
  6521. // serialized store depending on the type read at open. However, if the
  6522. // file is empty then, if the filename has either a ".p7c" or ".spc"
  6523. // extension its committed as a PKCS7. Otherwise, its committed as a
  6524. // serialized store.
  6525. //
  6526. // For CERT_STORE_PROV_FILE, the file handle is duplicated. Its always
  6527. // committed as a serialized store.
  6528. //
  6529. #define CERT_FILE_STORE_COMMIT_ENABLE_FLAG 0x10000
  6530. //+-------------------------------------------------------------------------
  6531. // Certificate LDAP Store Flag Values for the providers:
  6532. // CERT_STORE_PROV_LDAP
  6533. // CERT_STORE_PROV_LDAP_W
  6534. // sz_CERT_STORE_PROV_LDAP_W
  6535. // sz_CERT_STORE_PROV_LDAP
  6536. //--------------------------------------------------------------------------
  6537. // Set this flag to digitally sign all of the ldap traffic to and from a
  6538. // Windows 2000 LDAP server using the Kerberos authentication protocol.
  6539. // This feature provides integrity required by some applications.
  6540. //
  6541. #define CERT_LDAP_STORE_SIGN_FLAG 0x10000
  6542. // Performs an A-Record only DNS lookup on the supplied host string.
  6543. // This prevents bogus DNS queries from being generated when resolving host
  6544. // names. Use this flag whenever passing a hostname as opposed to a
  6545. // domain name for the hostname parameter.
  6546. //
  6547. // See LDAP_OPT_AREC_EXCLUSIVE defined in winldap.h for more details.
  6548. #define CERT_LDAP_STORE_AREC_EXCLUSIVE_FLAG 0x20000
  6549. // Set this flag if the LDAP session handle has already been opened. When
  6550. // set, pvPara points to the following CERT_LDAP_STORE_OPENED_PARA structure.
  6551. #define CERT_LDAP_STORE_OPENED_FLAG 0x40000
  6552. typedef struct _CERT_LDAP_STORE_OPENED_PARA {
  6553. void *pvLdapSessionHandle; // The (LDAP *) handle returned by
  6554. // ldap_init
  6555. LPCWSTR pwszLdapUrl;
  6556. } CERT_LDAP_STORE_OPENED_PARA, *PCERT_LDAP_STORE_OPENED_PARA;
  6557. // Set this flag if the above CERT_LDAP_STORE_OPENED_FLAG is set and
  6558. // you want an ldap_unbind() of the above pvLdapSessionHandle when the
  6559. // store is closed. Note, if CertOpenStore() fails, then, ldap_unbind()
  6560. // isn't called.
  6561. #define CERT_LDAP_STORE_UNBIND_FLAG 0x80000
  6562. //+-------------------------------------------------------------------------
  6563. // Open the cert store using the specified store provider.
  6564. //
  6565. // If CERT_STORE_DELETE_FLAG is set, then, the store is deleted. NULL is
  6566. // returned for both success and failure. However, GetLastError() returns 0
  6567. // for success and nonzero for failure.
  6568. //
  6569. // If CERT_STORE_SET_LOCALIZED_NAME_FLAG is set, then, if supported, the
  6570. // provider sets the store's CERT_STORE_LOCALIZED_NAME_PROP_ID property.
  6571. // The store's localized name can be retrieved by calling
  6572. // CertSetStoreProperty(dwPropID = CERT_STORE_LOCALIZED_NAME_PROP_ID).
  6573. // This flag is supported by the following providers (and their sz_
  6574. // equivalent):
  6575. // CERT_STORE_PROV_FILENAME_A
  6576. // CERT_STORE_PROV_FILENAME_W
  6577. // CERT_STORE_PROV_SYSTEM_A
  6578. // CERT_STORE_PROV_SYSTEM_W
  6579. // CERT_STORE_PROV_SYSTEM_REGISTRY_A
  6580. // CERT_STORE_PROV_SYSTEM_REGISTRY_W
  6581. // CERT_STORE_PROV_PHYSICAL_W
  6582. //
  6583. // If CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG is set, then, the
  6584. // closing of the store's provider is deferred until all certificate,
  6585. // CRL and CTL contexts obtained from the store are freed. Also,
  6586. // if a non NULL HCRYPTPROV was passed, then, it will continue to be used.
  6587. // By default, the store's provider is closed on the final CertCloseStore.
  6588. // If this flag isn't set, then, any property changes made to previously
  6589. // duplicated contexts after the final CertCloseStore will not be persisted.
  6590. // By setting this flag, property changes made
  6591. // after the CertCloseStore will be persisted. Note, setting this flag
  6592. // causes extra overhead in doing context duplicates and frees.
  6593. // If CertCloseStore is called with CERT_CLOSE_STORE_FORCE_FLAG, then,
  6594. // the CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG flag is ignored.
  6595. //
  6596. // CERT_STORE_MANIFOLD_FLAG can be set to check for certificates having the
  6597. // manifold extension and archive the "older" certificates with the same
  6598. // manifold extension value. A certificate is archived by setting the
  6599. // CERT_ARCHIVED_PROP_ID.
  6600. //
  6601. // By default, contexts having the CERT_ARCHIVED_PROP_ID, are skipped
  6602. // during enumeration. CERT_STORE_ENUM_ARCHIVED_FLAG can be set to include
  6603. // archived contexts when enumerating. Note, contexts having the
  6604. // CERT_ARCHIVED_PROP_ID are still found for explicit finds, such as,
  6605. // finding a context with a specific hash or finding a certificate having
  6606. // a specific issuer and serial number.
  6607. //
  6608. // CERT_STORE_UPDATE_KEYID_FLAG can be set to also update the Key Identifier's
  6609. // CERT_KEY_PROV_INFO_PROP_ID property whenever a certificate's
  6610. // CERT_KEY_IDENTIFIER_PROP_ID or CERT_KEY_PROV_INFO_PROP_ID property is set
  6611. // and the other property already exists. If the Key Identifier's
  6612. // CERT_KEY_PROV_INFO_PROP_ID already exists, it isn't updated. Any
  6613. // errors encountered are silently ignored.
  6614. //
  6615. // By default, this flag is implicitly set for the "My\.Default" CurrentUser
  6616. // and LocalMachine physical stores.
  6617. //
  6618. // CERT_STORE_READONLY_FLAG can be set to open the store as read only.
  6619. // Otherwise, the store is opened as read/write.
  6620. //
  6621. // CERT_STORE_OPEN_EXISTING_FLAG can be set to only open an existing
  6622. // store. CERT_STORE_CREATE_NEW_FLAG can be set to create a new store and
  6623. // fail if the store already exists. Otherwise, the default is to open
  6624. // an existing store or create a new store if it doesn't already exist.
  6625. //
  6626. // hCryptProv specifies the crypto provider to use to create the hash
  6627. // properties or verify the signature of a subject certificate or CRL.
  6628. // The store doesn't need to use a private
  6629. // key. If the CERT_STORE_NO_CRYPT_RELEASE_FLAG isn't set, hCryptProv is
  6630. // CryptReleaseContext'ed on the final CertCloseStore.
  6631. //
  6632. // Note, if the open fails, hCryptProv is released if it would have been
  6633. // released when the store was closed.
  6634. //
  6635. // If hCryptProv is zero, then, the default provider and container for the
  6636. // PROV_RSA_FULL provider type is CryptAcquireContext'ed with
  6637. // CRYPT_VERIFYCONTEXT access. The CryptAcquireContext is deferred until
  6638. // the first create hash or verify signature. In addition, once acquired,
  6639. // the default provider isn't released until process exit when crypt32.dll
  6640. // is unloaded. The acquired default provider is shared across all stores
  6641. // and threads.
  6642. //
  6643. // After initializing the store's data structures and optionally acquiring a
  6644. // default crypt provider, CertOpenStore calls CryptGetOIDFunctionAddress to
  6645. // get the address of the CRYPT_OID_OPEN_STORE_PROV_FUNC specified by
  6646. // lpszStoreProvider. Since a store can contain certificates with different
  6647. // encoding types, CryptGetOIDFunctionAddress is called with dwEncodingType
  6648. // set to 0 and not the dwEncodingType passed to CertOpenStore.
  6649. // PFN_CERT_DLL_OPEN_STORE_FUNC specifies the signature of the provider's
  6650. // open function. This provider open function is called to load the
  6651. // store's certificates and CRLs. Optionally, the provider may return an
  6652. // array of functions called before a certificate or CRL is added or deleted
  6653. // or has a property that is set.
  6654. //
  6655. // Use of the dwEncodingType parameter is provider dependent. The type
  6656. // definition for pvPara also depends on the provider.
  6657. //
  6658. // Store providers are installed or registered via
  6659. // CryptInstallOIDFunctionAddress or CryptRegisterOIDFunction, where,
  6660. // dwEncodingType is 0 and pszFuncName is CRYPT_OID_OPEN_STORE_PROV_FUNC.
  6661. //
  6662. // Here's a list of the predefined provider types (implemented in crypt32.dll):
  6663. //
  6664. // CERT_STORE_PROV_MSG:
  6665. // Gets the certificates and CRLs from the specified cryptographic message.
  6666. // dwEncodingType contains the message and certificate encoding types.
  6667. // The message's handle is passed in pvPara. Given,
  6668. // HCRYPTMSG hCryptMsg; pvPara = (const void *) hCryptMsg;
  6669. //
  6670. // CERT_STORE_PROV_MEMORY
  6671. // sz_CERT_STORE_PROV_MEMORY:
  6672. // Opens a store without any initial certificates or CRLs. pvPara
  6673. // isn't used.
  6674. //
  6675. // CERT_STORE_PROV_FILE:
  6676. // Reads the certificates and CRLs from the specified file. The file's
  6677. // handle is passed in pvPara. Given,
  6678. // HANDLE hFile; pvPara = (const void *) hFile;
  6679. //
  6680. // For a successful open, the file pointer is advanced past
  6681. // the certificates and CRLs and their properties read from the file.
  6682. // Note, only expects a serialized store and not a file containing
  6683. // either a PKCS #7 signed message or a single encoded certificate.
  6684. //
  6685. // The hFile isn't closed.
  6686. //
  6687. // CERT_STORE_PROV_REG:
  6688. // Reads the certificates and CRLs from the registry. The registry's
  6689. // key handle is passed in pvPara. Given,
  6690. // HKEY hKey; pvPara = (const void *) hKey;
  6691. //
  6692. // The input hKey isn't closed by the provider. Before returning, the
  6693. // provider opens it own copy of the hKey.
  6694. //
  6695. // If CERT_STORE_READONLY_FLAG is set, then, the registry subkeys are
  6696. // RegOpenKey'ed with KEY_READ_ACCESS. Otherwise, the registry subkeys
  6697. // are RegCreateKey'ed with KEY_ALL_ACCESS.
  6698. //
  6699. // This provider returns the array of functions for reading, writing,
  6700. // deleting and property setting certificates and CRLs.
  6701. // Any changes to the opened store are immediately pushed through to
  6702. // the registry. However, if CERT_STORE_READONLY_FLAG is set, then,
  6703. // writing, deleting or property setting results in a
  6704. // SetLastError(E_ACCESSDENIED).
  6705. //
  6706. // Note, all the certificates and CRLs are read from the registry
  6707. // when the store is opened. The opened store serves as a write through
  6708. // cache.
  6709. //
  6710. // If CERT_REGISTRY_STORE_SERIALIZED_FLAG is set, then, the
  6711. // contexts are persisted as a single serialized store subkey in the
  6712. // registry.
  6713. //
  6714. // CERT_STORE_PROV_PKCS7:
  6715. // sz_CERT_STORE_PROV_PKCS7:
  6716. // Gets the certificates and CRLs from the encoded PKCS #7 signed message.
  6717. // dwEncodingType specifies the message and certificate encoding types.
  6718. // The pointer to the encoded message's blob is passed in pvPara. Given,
  6719. // CRYPT_DATA_BLOB EncodedMsg; pvPara = (const void *) &EncodedMsg;
  6720. //
  6721. // Note, also supports the IE3.0 special version of a
  6722. // PKCS #7 signed message referred to as a "SPC" formatted message.
  6723. //
  6724. // CERT_STORE_PROV_SERIALIZED:
  6725. // sz_CERT_STORE_PROV_SERIALIZED:
  6726. // Gets the certificates and CRLs from memory containing a serialized
  6727. // store. The pointer to the serialized memory blob is passed in pvPara.
  6728. // Given,
  6729. // CRYPT_DATA_BLOB Serialized; pvPara = (const void *) &Serialized;
  6730. //
  6731. // CERT_STORE_PROV_FILENAME_A:
  6732. // CERT_STORE_PROV_FILENAME_W:
  6733. // CERT_STORE_PROV_FILENAME:
  6734. // sz_CERT_STORE_PROV_FILENAME_W:
  6735. // sz_CERT_STORE_PROV_FILENAME:
  6736. // Opens the file and first attempts to read as a serialized store. Then,
  6737. // as a PKCS #7 signed message. Finally, as a single encoded certificate.
  6738. // The filename is passed in pvPara. The filename is UNICODE for the
  6739. // "_W" provider and ASCII for the "_A" provider. For "_W": given,
  6740. // LPCWSTR pwszFilename; pvPara = (const void *) pwszFilename;
  6741. // For "_A": given,
  6742. // LPCSTR pszFilename; pvPara = (const void *) pszFilename;
  6743. //
  6744. // Note, the default (without "_A" or "_W") is unicode.
  6745. //
  6746. // Note, also supports the reading of the IE3.0 special version of a
  6747. // PKCS #7 signed message file referred to as a "SPC" formatted file.
  6748. //
  6749. // CERT_STORE_PROV_SYSTEM_A:
  6750. // CERT_STORE_PROV_SYSTEM_W:
  6751. // CERT_STORE_PROV_SYSTEM:
  6752. // sz_CERT_STORE_PROV_SYSTEM_W:
  6753. // sz_CERT_STORE_PROV_SYSTEM:
  6754. // Opens the specified logical "System" store. The upper word of the
  6755. // dwFlags parameter is used to specify the location of the system store.
  6756. //
  6757. // A "System" store is a collection consisting of one or more "Physical"
  6758. // stores. A "Physical" store is registered via the
  6759. // CertRegisterPhysicalStore API. Each of the registered physical stores
  6760. // is CertStoreOpen'ed and added to the collection via
  6761. // CertAddStoreToCollection.
  6762. //
  6763. // The CERT_SYSTEM_STORE_CURRENT_USER, CERT_SYSTEM_STORE_LOCAL_MACHINE,
  6764. // CERT_SYSTEM_STORE_CURRENT_SERVICE, CERT_SYSTEM_STORE_SERVICES,
  6765. // CERT_SYSTEM_STORE_USERS, CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY,
  6766. // CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY and
  6767. // CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRSE
  6768. // system stores by default have a "SystemRegistry" store that is
  6769. // opened and added to the collection.
  6770. //
  6771. // The system store name is passed in pvPara. The name is UNICODE for the
  6772. // "_W" provider and ASCII for the "_A" provider. For "_W": given,
  6773. // LPCWSTR pwszSystemName; pvPara = (const void *) pwszSystemName;
  6774. // For "_A": given,
  6775. // LPCSTR pszSystemName; pvPara = (const void *) pszSystemName;
  6776. //
  6777. // Note, the default (without "_A" or "_W") is UNICODE.
  6778. //
  6779. // The system store name can't contain any backslashes.
  6780. //
  6781. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvPara
  6782. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure instead
  6783. // of pointing to a null terminated UNICODE or ASCII string.
  6784. // Sibling physical stores are also opened as relocated using
  6785. // pvPara's hKeyBase.
  6786. //
  6787. // The CERT_SYSTEM_STORE_SERVICES or CERT_SYSTEM_STORE_USERS system
  6788. // store name must be prefixed with the ServiceName or UserName.
  6789. // For example, "ServiceName\Trust".
  6790. //
  6791. // Stores on remote computers can be accessed for the
  6792. // CERT_SYSTEM_STORE_LOCAL_MACHINE, CERT_SYSTEM_STORE_SERVICES,
  6793. // CERT_SYSTEM_STORE_USERS, CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY
  6794. // or CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE
  6795. // locations by prepending the computer name. For example, a remote
  6796. // local machine store is accessed via "\\ComputerName\Trust" or
  6797. // "ComputerName\Trust". A remote service store is accessed via
  6798. // "\\ComputerName\ServiceName\Trust". The leading "\\" backslashes are
  6799. // optional in the ComputerName.
  6800. //
  6801. // If CERT_STORE_READONLY_FLAG is set, then, the registry is
  6802. // RegOpenKey'ed with KEY_READ_ACCESS. Otherwise, the registry is
  6803. // RegCreateKey'ed with KEY_ALL_ACCESS.
  6804. //
  6805. // The "root" store is treated differently from the other system
  6806. // stores. Before a certificate is added to or deleted from the "root"
  6807. // store, a pop up message box is displayed. The certificate's subject,
  6808. // issuer, serial number, time validity, sha1 and md5 thumbprints are
  6809. // displayed. The user is given the option to do the add or delete.
  6810. // If they don't allow the operation, LastError is set to E_ACCESSDENIED.
  6811. //
  6812. // CERT_STORE_PROV_SYSTEM_REGISTRY_A
  6813. // CERT_STORE_PROV_SYSTEM_REGISTRY_W
  6814. // CERT_STORE_PROV_SYSTEM_REGISTRY
  6815. // sz_CERT_STORE_PROV_SYSTEM_REGISTRY_W
  6816. // sz_CERT_STORE_PROV_SYSTEM_REGISTRY
  6817. // Opens the "System" store's default "Physical" store residing in the
  6818. // registry. The upper word of the dwFlags
  6819. // parameter is used to specify the location of the system store.
  6820. //
  6821. // After opening the registry key associated with the system name,
  6822. // the CERT_STORE_PROV_REG provider is called to complete the open.
  6823. //
  6824. // The system store name is passed in pvPara. The name is UNICODE for the
  6825. // "_W" provider and ASCII for the "_A" provider. For "_W": given,
  6826. // LPCWSTR pwszSystemName; pvPara = (const void *) pwszSystemName;
  6827. // For "_A": given,
  6828. // LPCSTR pszSystemName; pvPara = (const void *) pszSystemName;
  6829. //
  6830. // Note, the default (without "_A" or "_W") is UNICODE.
  6831. //
  6832. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvPara
  6833. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure instead
  6834. // of pointing to a null terminated UNICODE or ASCII string.
  6835. //
  6836. // See above for details on prepending a ServiceName and/or ComputerName
  6837. // to the store name.
  6838. //
  6839. // If CERT_STORE_READONLY_FLAG is set, then, the registry is
  6840. // RegOpenKey'ed with KEY_READ_ACCESS. Otherwise, the registry is
  6841. // RegCreateKey'ed with KEY_ALL_ACCESS.
  6842. //
  6843. // The "root" store is treated differently from the other system
  6844. // stores. Before a certificate is added to or deleted from the "root"
  6845. // store, a pop up message box is displayed. The certificate's subject,
  6846. // issuer, serial number, time validity, sha1 and md5 thumbprints are
  6847. // displayed. The user is given the option to do the add or delete.
  6848. // If they don't allow the operation, LastError is set to E_ACCESSDENIED.
  6849. //
  6850. // CERT_STORE_PROV_PHYSICAL_W
  6851. // CERT_STORE_PROV_PHYSICAL
  6852. // sz_CERT_STORE_PROV_PHYSICAL_W
  6853. // sz_CERT_STORE_PROV_PHYSICAL
  6854. // Opens the specified "Physical" store in the "System" store.
  6855. //
  6856. // Both the system store and physical names are passed in pvPara. The
  6857. // names are separated with an intervening "\". For example,
  6858. // "Root\.Default". The string is UNICODE.
  6859. //
  6860. // The system and physical store names can't contain any backslashes.
  6861. //
  6862. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvPara
  6863. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure instead
  6864. // of pointing to a null terminated UNICODE string.
  6865. // The specified physical store is opened as relocated using pvPara's
  6866. // hKeyBase.
  6867. //
  6868. // For CERT_SYSTEM_STORE_SERVICES or CERT_SYSTEM_STORE_USERS,
  6869. // the system and physical store names
  6870. // must be prefixed with the ServiceName or UserName. For example,
  6871. // "ServiceName\Root\.Default".
  6872. //
  6873. // Physical stores on remote computers can be accessed for the
  6874. // CERT_SYSTEM_STORE_LOCAL_MACHINE, CERT_SYSTEM_STORE_SERVICES,
  6875. // CERT_SYSTEM_STORE_USERS, CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY
  6876. // or CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE
  6877. // locations by prepending the computer name. For example, a remote
  6878. // local machine store is accessed via "\\ComputerName\Root\.Default"
  6879. // or "ComputerName\Root\.Default". A remote service store is
  6880. // accessed via "\\ComputerName\ServiceName\Root\.Default". The
  6881. // leading "\\" backslashes are optional in the ComputerName.
  6882. //
  6883. // CERT_STORE_PROV_COLLECTION
  6884. // sz_CERT_STORE_PROV_COLLECTION
  6885. // Opens a store that is a collection of other stores. Stores are
  6886. // added or removed to/from the collection via the CertAddStoreToCollection
  6887. // and CertRemoveStoreFromCollection APIs.
  6888. //
  6889. // CERT_STORE_PROV_SMART_CARD_W
  6890. // CERT_STORE_PROV_SMART_CARD
  6891. // sz_CERT_STORE_PROV_SMART_CARD_W
  6892. // sz_CERT_STORE_PROV_SMART_CARD
  6893. // Opens a store instantiated over a particular smart card storage. pvPara
  6894. // identifies where on the card the store is located and is of the
  6895. // following format:
  6896. //
  6897. // Card Name\Provider Name\Provider Type[\Container Name]
  6898. //
  6899. // Container Name is optional and if NOT specified the Card Name is used
  6900. // as the Container Name. Future versions of the provider will support
  6901. // instantiating the store over the entire card in which case just
  6902. // Card Name ( or id ) will be sufficient.
  6903. //
  6904. // Here's a list of the predefined provider types (implemented in
  6905. // cryptnet.dll):
  6906. //
  6907. // CERT_STORE_PROV_LDAP_W
  6908. // CERT_STORE_PROV_LDAP
  6909. // sz_CERT_STORE_PROV_LDAP_W
  6910. // sz_CERT_STORE_PROV_LDAP
  6911. // Opens a store over the results of the query specified by and LDAP
  6912. // URL which is passed in via pvPara. In order to do writes to the
  6913. // store the URL must specify a BASE query, no filter and a single
  6914. // attribute.
  6915. //
  6916. //--------------------------------------------------------------------------
  6917. WINCRYPT32API
  6918. HCERTSTORE
  6919. WINAPI
  6920. CertOpenStore(
  6921. IN LPCSTR lpszStoreProvider,
  6922. IN DWORD dwEncodingType,
  6923. IN HCRYPTPROV hCryptProv,
  6924. IN DWORD dwFlags,
  6925. IN const void *pvPara
  6926. );
  6927. //+-------------------------------------------------------------------------
  6928. // OID Installable Certificate Store Provider Data Structures
  6929. //--------------------------------------------------------------------------
  6930. // Handle returned by the store provider when opened.
  6931. typedef void *HCERTSTOREPROV;
  6932. // Store Provider OID function's pszFuncName.
  6933. #define CRYPT_OID_OPEN_STORE_PROV_FUNC "CertDllOpenStoreProv"
  6934. // Note, the Store Provider OID function's dwEncodingType is always 0.
  6935. // The following information is returned by the provider when opened. Its
  6936. // zeroed with cbSize set before the provider is called. If the provider
  6937. // doesn't need to be called again after the open it doesn't need to
  6938. // make any updates to the CERT_STORE_PROV_INFO.
  6939. typedef struct _CERT_STORE_PROV_INFO {
  6940. DWORD cbSize;
  6941. DWORD cStoreProvFunc;
  6942. void **rgpvStoreProvFunc;
  6943. HCERTSTOREPROV hStoreProv;
  6944. DWORD dwStoreProvFlags;
  6945. HCRYPTOIDFUNCADDR hStoreProvFuncAddr2;
  6946. } CERT_STORE_PROV_INFO, *PCERT_STORE_PROV_INFO;
  6947. // Definition of the store provider's open function.
  6948. //
  6949. // *pStoreProvInfo has been zeroed before the call.
  6950. //
  6951. // Note, pStoreProvInfo->cStoreProvFunc should be set last. Once set,
  6952. // all subsequent store calls, such as CertAddSerializedElementToStore will
  6953. // call the appropriate provider callback function.
  6954. typedef BOOL (WINAPI *PFN_CERT_DLL_OPEN_STORE_PROV_FUNC)(
  6955. IN LPCSTR lpszStoreProvider,
  6956. IN DWORD dwEncodingType,
  6957. IN HCRYPTPROV hCryptProv,
  6958. IN DWORD dwFlags,
  6959. IN const void *pvPara,
  6960. IN HCERTSTORE hCertStore,
  6961. IN OUT PCERT_STORE_PROV_INFO pStoreProvInfo
  6962. );
  6963. // The open callback sets the following flag, if it maintains its
  6964. // contexts externally and not in the cached store.
  6965. #define CERT_STORE_PROV_EXTERNAL_FLAG 0x1
  6966. // The open callback sets the following flag for a successful delete.
  6967. // When set, the close callback isn't called.
  6968. #define CERT_STORE_PROV_DELETED_FLAG 0x2
  6969. // The open callback sets the following flag if it doesn't persist store
  6970. // changes.
  6971. #define CERT_STORE_PROV_NO_PERSIST_FLAG 0x4
  6972. // The open callback sets the following flag if the contexts are persisted
  6973. // to a system store.
  6974. #define CERT_STORE_PROV_SYSTEM_STORE_FLAG 0x8
  6975. // The open callback sets the following flag if the contexts are persisted
  6976. // to a LocalMachine system store.
  6977. #define CERT_STORE_PROV_LM_SYSTEM_STORE_FLAG 0x10
  6978. // Indices into the store provider's array of callback functions.
  6979. //
  6980. // The provider can implement any subset of the following functions. It
  6981. // sets pStoreProvInfo->cStoreProvFunc to the last index + 1 and any
  6982. // preceding not implemented functions to NULL.
  6983. #define CERT_STORE_PROV_CLOSE_FUNC 0
  6984. #define CERT_STORE_PROV_READ_CERT_FUNC 1
  6985. #define CERT_STORE_PROV_WRITE_CERT_FUNC 2
  6986. #define CERT_STORE_PROV_DELETE_CERT_FUNC 3
  6987. #define CERT_STORE_PROV_SET_CERT_PROPERTY_FUNC 4
  6988. #define CERT_STORE_PROV_READ_CRL_FUNC 5
  6989. #define CERT_STORE_PROV_WRITE_CRL_FUNC 6
  6990. #define CERT_STORE_PROV_DELETE_CRL_FUNC 7
  6991. #define CERT_STORE_PROV_SET_CRL_PROPERTY_FUNC 8
  6992. #define CERT_STORE_PROV_READ_CTL_FUNC 9
  6993. #define CERT_STORE_PROV_WRITE_CTL_FUNC 10
  6994. #define CERT_STORE_PROV_DELETE_CTL_FUNC 11
  6995. #define CERT_STORE_PROV_SET_CTL_PROPERTY_FUNC 12
  6996. #define CERT_STORE_PROV_CONTROL_FUNC 13
  6997. #define CERT_STORE_PROV_FIND_CERT_FUNC 14
  6998. #define CERT_STORE_PROV_FREE_FIND_CERT_FUNC 15
  6999. #define CERT_STORE_PROV_GET_CERT_PROPERTY_FUNC 16
  7000. #define CERT_STORE_PROV_FIND_CRL_FUNC 17
  7001. #define CERT_STORE_PROV_FREE_FIND_CRL_FUNC 18
  7002. #define CERT_STORE_PROV_GET_CRL_PROPERTY_FUNC 19
  7003. #define CERT_STORE_PROV_FIND_CTL_FUNC 20
  7004. #define CERT_STORE_PROV_FREE_FIND_CTL_FUNC 21
  7005. #define CERT_STORE_PROV_GET_CTL_PROPERTY_FUNC 22
  7006. // Called by CertCloseStore when the store's reference count is
  7007. // decremented to 0.
  7008. typedef void (WINAPI *PFN_CERT_STORE_PROV_CLOSE)(
  7009. IN HCERTSTOREPROV hStoreProv,
  7010. IN DWORD dwFlags
  7011. );
  7012. // Currently not called directly by the store APIs. However, may be exported
  7013. // to support other providers based on it.
  7014. //
  7015. // Reads the provider's copy of the certificate context. If it exists,
  7016. // creates a new certificate context.
  7017. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_READ_CERT)(
  7018. IN HCERTSTOREPROV hStoreProv,
  7019. IN PCCERT_CONTEXT pStoreCertContext,
  7020. IN DWORD dwFlags,
  7021. OUT PCCERT_CONTEXT *ppProvCertContext
  7022. );
  7023. #define CERT_STORE_PROV_WRITE_ADD_FLAG 0x1
  7024. // Called by CertAddEncodedCertificateToStore,
  7025. // CertAddCertificateContextToStore or CertAddSerializedElementToStore before
  7026. // adding to the store. The CERT_STORE_PROV_WRITE_ADD_FLAG is set. In
  7027. // addition to the encoded certificate, the added pCertContext might also
  7028. // have properties.
  7029. //
  7030. // Returns TRUE if its OK to update the the store.
  7031. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_WRITE_CERT)(
  7032. IN HCERTSTOREPROV hStoreProv,
  7033. IN PCCERT_CONTEXT pCertContext,
  7034. IN DWORD dwFlags
  7035. );
  7036. // Called by CertDeleteCertificateFromStore before deleting from the
  7037. // store.
  7038. //
  7039. // Returns TRUE if its OK to delete from the store.
  7040. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_DELETE_CERT)(
  7041. IN HCERTSTOREPROV hStoreProv,
  7042. IN PCCERT_CONTEXT pCertContext,
  7043. IN DWORD dwFlags
  7044. );
  7045. // Called by CertSetCertificateContextProperty before setting the
  7046. // certificate's property. Also called by CertGetCertificateContextProperty,
  7047. // when getting a hash property that needs to be created and then persisted
  7048. // via the set.
  7049. //
  7050. // Upon input, the property hasn't been set for the pCertContext parameter.
  7051. //
  7052. // Returns TRUE if its OK to set the property.
  7053. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_SET_CERT_PROPERTY)(
  7054. IN HCERTSTOREPROV hStoreProv,
  7055. IN PCCERT_CONTEXT pCertContext,
  7056. IN DWORD dwPropId,
  7057. IN DWORD dwFlags,
  7058. IN const void *pvData
  7059. );
  7060. // Currently not called directly by the store APIs. However, may be exported
  7061. // to support other providers based on it.
  7062. //
  7063. // Reads the provider's copy of the CRL context. If it exists,
  7064. // creates a new CRL context.
  7065. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_READ_CRL)(
  7066. IN HCERTSTOREPROV hStoreProv,
  7067. IN PCCRL_CONTEXT pStoreCrlContext,
  7068. IN DWORD dwFlags,
  7069. OUT PCCRL_CONTEXT *ppProvCrlContext
  7070. );
  7071. // Called by CertAddEncodedCRLToStore,
  7072. // CertAddCRLContextToStore or CertAddSerializedElementToStore before
  7073. // adding to the store. The CERT_STORE_PROV_WRITE_ADD_FLAG is set. In
  7074. // addition to the encoded CRL, the added pCertContext might also
  7075. // have properties.
  7076. //
  7077. // Returns TRUE if its OK to update the the store.
  7078. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_WRITE_CRL)(
  7079. IN HCERTSTOREPROV hStoreProv,
  7080. IN PCCRL_CONTEXT pCrlContext,
  7081. IN DWORD dwFlags
  7082. );
  7083. // Called by CertDeleteCRLFromStore before deleting from the store.
  7084. //
  7085. // Returns TRUE if its OK to delete from the store.
  7086. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_DELETE_CRL)(
  7087. IN HCERTSTOREPROV hStoreProv,
  7088. IN PCCRL_CONTEXT pCrlContext,
  7089. IN DWORD dwFlags
  7090. );
  7091. // Called by CertSetCRLContextProperty before setting the
  7092. // CRL's property. Also called by CertGetCRLContextProperty,
  7093. // when getting a hash property that needs to be created and then persisted
  7094. // via the set.
  7095. //
  7096. // Upon input, the property hasn't been set for the pCrlContext parameter.
  7097. //
  7098. // Returns TRUE if its OK to set the property.
  7099. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_SET_CRL_PROPERTY)(
  7100. IN HCERTSTOREPROV hStoreProv,
  7101. IN PCCRL_CONTEXT pCrlContext,
  7102. IN DWORD dwPropId,
  7103. IN DWORD dwFlags,
  7104. IN const void *pvData
  7105. );
  7106. // Currently not called directly by the store APIs. However, may be exported
  7107. // to support other providers based on it.
  7108. //
  7109. // Reads the provider's copy of the CTL context. If it exists,
  7110. // creates a new CTL context.
  7111. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_READ_CTL)(
  7112. IN HCERTSTOREPROV hStoreProv,
  7113. IN PCCTL_CONTEXT pStoreCtlContext,
  7114. IN DWORD dwFlags,
  7115. OUT PCCTL_CONTEXT *ppProvCtlContext
  7116. );
  7117. // Called by CertAddEncodedCTLToStore,
  7118. // CertAddCTLContextToStore or CertAddSerializedElementToStore before
  7119. // adding to the store. The CERT_STORE_PROV_WRITE_ADD_FLAG is set. In
  7120. // addition to the encoded CTL, the added pCertContext might also
  7121. // have properties.
  7122. //
  7123. // Returns TRUE if its OK to update the the store.
  7124. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_WRITE_CTL)(
  7125. IN HCERTSTOREPROV hStoreProv,
  7126. IN PCCTL_CONTEXT pCtlContext,
  7127. IN DWORD dwFlags
  7128. );
  7129. // Called by CertDeleteCTLFromStore before deleting from the store.
  7130. //
  7131. // Returns TRUE if its OK to delete from the store.
  7132. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_DELETE_CTL)(
  7133. IN HCERTSTOREPROV hStoreProv,
  7134. IN PCCTL_CONTEXT pCtlContext,
  7135. IN DWORD dwFlags
  7136. );
  7137. // Called by CertSetCTLContextProperty before setting the
  7138. // CTL's property. Also called by CertGetCTLContextProperty,
  7139. // when getting a hash property that needs to be created and then persisted
  7140. // via the set.
  7141. //
  7142. // Upon input, the property hasn't been set for the pCtlContext parameter.
  7143. //
  7144. // Returns TRUE if its OK to set the property.
  7145. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_SET_CTL_PROPERTY)(
  7146. IN HCERTSTOREPROV hStoreProv,
  7147. IN PCCTL_CONTEXT pCtlContext,
  7148. IN DWORD dwPropId,
  7149. IN DWORD dwFlags,
  7150. IN const void *pvData
  7151. );
  7152. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_CONTROL)(
  7153. IN HCERTSTOREPROV hStoreProv,
  7154. IN DWORD dwFlags,
  7155. IN DWORD dwCtrlType,
  7156. IN void const *pvCtrlPara
  7157. );
  7158. typedef struct _CERT_STORE_PROV_FIND_INFO {
  7159. DWORD cbSize;
  7160. DWORD dwMsgAndCertEncodingType;
  7161. DWORD dwFindFlags;
  7162. DWORD dwFindType;
  7163. const void *pvFindPara;
  7164. } CERT_STORE_PROV_FIND_INFO, *PCERT_STORE_PROV_FIND_INFO;
  7165. typedef const CERT_STORE_PROV_FIND_INFO CCERT_STORE_PROV_FIND_INFO,
  7166. *PCCERT_STORE_PROV_FIND_INFO;
  7167. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_FIND_CERT)(
  7168. IN HCERTSTOREPROV hStoreProv,
  7169. IN PCCERT_STORE_PROV_FIND_INFO pFindInfo,
  7170. IN PCCERT_CONTEXT pPrevCertContext,
  7171. IN DWORD dwFlags,
  7172. IN OUT void **ppvStoreProvFindInfo,
  7173. OUT PCCERT_CONTEXT *ppProvCertContext
  7174. );
  7175. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_FREE_FIND_CERT)(
  7176. IN HCERTSTOREPROV hStoreProv,
  7177. IN PCCERT_CONTEXT pCertContext,
  7178. IN void *pvStoreProvFindInfo,
  7179. IN DWORD dwFlags
  7180. );
  7181. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_GET_CERT_PROPERTY)(
  7182. IN HCERTSTOREPROV hStoreProv,
  7183. IN PCCERT_CONTEXT pCertContext,
  7184. IN DWORD dwPropId,
  7185. IN DWORD dwFlags,
  7186. OUT void *pvData,
  7187. IN OUT DWORD *pcbData
  7188. );
  7189. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_FIND_CRL)(
  7190. IN HCERTSTOREPROV hStoreProv,
  7191. IN PCCERT_STORE_PROV_FIND_INFO pFindInfo,
  7192. IN PCCRL_CONTEXT pPrevCrlContext,
  7193. IN DWORD dwFlags,
  7194. IN OUT void **ppvStoreProvFindInfo,
  7195. OUT PCCRL_CONTEXT *ppProvCrlContext
  7196. );
  7197. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_FREE_FIND_CRL)(
  7198. IN HCERTSTOREPROV hStoreProv,
  7199. IN PCCRL_CONTEXT pCrlContext,
  7200. IN void *pvStoreProvFindInfo,
  7201. IN DWORD dwFlags
  7202. );
  7203. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_GET_CRL_PROPERTY)(
  7204. IN HCERTSTOREPROV hStoreProv,
  7205. IN PCCRL_CONTEXT pCrlContext,
  7206. IN DWORD dwPropId,
  7207. IN DWORD dwFlags,
  7208. OUT void *pvData,
  7209. IN OUT DWORD *pcbData
  7210. );
  7211. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_FIND_CTL)(
  7212. IN HCERTSTOREPROV hStoreProv,
  7213. IN PCCERT_STORE_PROV_FIND_INFO pFindInfo,
  7214. IN PCCTL_CONTEXT pPrevCtlContext,
  7215. IN DWORD dwFlags,
  7216. IN OUT void **ppvStoreProvFindInfo,
  7217. OUT PCCTL_CONTEXT *ppProvCtlContext
  7218. );
  7219. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_FREE_FIND_CTL)(
  7220. IN HCERTSTOREPROV hStoreProv,
  7221. IN PCCTL_CONTEXT pCtlContext,
  7222. IN void *pvStoreProvFindInfo,
  7223. IN DWORD dwFlags
  7224. );
  7225. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_GET_CTL_PROPERTY)(
  7226. IN HCERTSTOREPROV hStoreProv,
  7227. IN PCCTL_CONTEXT pCtlContext,
  7228. IN DWORD dwPropId,
  7229. IN DWORD dwFlags,
  7230. OUT void *pvData,
  7231. IN OUT DWORD *pcbData
  7232. );
  7233. //+-------------------------------------------------------------------------
  7234. // Duplicate a cert store handle
  7235. //--------------------------------------------------------------------------
  7236. WINCRYPT32API
  7237. HCERTSTORE
  7238. WINAPI
  7239. CertDuplicateStore(
  7240. IN HCERTSTORE hCertStore
  7241. );
  7242. #define CERT_STORE_SAVE_AS_STORE 1
  7243. #define CERT_STORE_SAVE_AS_PKCS7 2
  7244. #define CERT_STORE_SAVE_TO_FILE 1
  7245. #define CERT_STORE_SAVE_TO_MEMORY 2
  7246. #define CERT_STORE_SAVE_TO_FILENAME_A 3
  7247. #define CERT_STORE_SAVE_TO_FILENAME_W 4
  7248. #define CERT_STORE_SAVE_TO_FILENAME CERT_STORE_SAVE_TO_FILENAME_W
  7249. //+-------------------------------------------------------------------------
  7250. // Save the cert store. Extended version with lots of options.
  7251. //
  7252. // According to the dwSaveAs parameter, the store can be saved as a
  7253. // serialized store (CERT_STORE_SAVE_AS_STORE) containing properties in
  7254. // addition to encoded certificates, CRLs and CTLs or the store can be saved
  7255. // as a PKCS #7 signed message (CERT_STORE_SAVE_AS_PKCS7) which doesn't
  7256. // include the properties or CTLs.
  7257. //
  7258. // Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  7259. // CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't saved into
  7260. // a serialized store.
  7261. //
  7262. // For CERT_STORE_SAVE_AS_PKCS7, the dwEncodingType specifies the message
  7263. // encoding type. The dwEncodingType parameter isn't used for
  7264. // CERT_STORE_SAVE_AS_STORE.
  7265. //
  7266. // The dwFlags parameter currently isn't used and should be set to 0.
  7267. //
  7268. // The dwSaveTo and pvSaveToPara parameters specify where to save the
  7269. // store as follows:
  7270. // CERT_STORE_SAVE_TO_FILE:
  7271. // Saves to the specified file. The file's handle is passed in
  7272. // pvSaveToPara. Given,
  7273. // HANDLE hFile; pvSaveToPara = (void *) hFile;
  7274. //
  7275. // For a successful save, the file pointer is positioned after the
  7276. // last write.
  7277. //
  7278. // CERT_STORE_SAVE_TO_MEMORY:
  7279. // Saves to the specified memory blob. The pointer to
  7280. // the memory blob is passed in pvSaveToPara. Given,
  7281. // CRYPT_DATA_BLOB SaveBlob; pvSaveToPara = (void *) &SaveBlob;
  7282. // Upon entry, the SaveBlob's pbData and cbData need to be initialized.
  7283. // Upon return, cbData is updated with the actual length.
  7284. // For a length only calculation, pbData should be set to NULL. If
  7285. // pbData is non-NULL and cbData isn't large enough, FALSE is returned
  7286. // with a last error of ERRROR_MORE_DATA.
  7287. //
  7288. // CERT_STORE_SAVE_TO_FILENAME_A:
  7289. // CERT_STORE_SAVE_TO_FILENAME_W:
  7290. // CERT_STORE_SAVE_TO_FILENAME:
  7291. // Opens the file and saves to it. The filename is passed in pvSaveToPara.
  7292. // The filename is UNICODE for the "_W" option and ASCII for the "_A"
  7293. // option. For "_W": given,
  7294. // LPCWSTR pwszFilename; pvSaveToPara = (void *) pwszFilename;
  7295. // For "_A": given,
  7296. // LPCSTR pszFilename; pvSaveToPara = (void *) pszFilename;
  7297. //
  7298. // Note, the default (without "_A" or "_W") is UNICODE.
  7299. //
  7300. //--------------------------------------------------------------------------
  7301. WINCRYPT32API
  7302. BOOL
  7303. WINAPI
  7304. CertSaveStore(
  7305. IN HCERTSTORE hCertStore,
  7306. IN DWORD dwEncodingType,
  7307. IN DWORD dwSaveAs,
  7308. IN DWORD dwSaveTo,
  7309. IN OUT void *pvSaveToPara,
  7310. IN DWORD dwFlags
  7311. );
  7312. //+-------------------------------------------------------------------------
  7313. // Certificate Store close flags
  7314. //--------------------------------------------------------------------------
  7315. #define CERT_CLOSE_STORE_FORCE_FLAG 0x00000001
  7316. #define CERT_CLOSE_STORE_CHECK_FLAG 0x00000002
  7317. //+-------------------------------------------------------------------------
  7318. // Close a cert store handle.
  7319. //
  7320. // There needs to be a corresponding close for each open and duplicate.
  7321. //
  7322. // Even on the final close, the cert store isn't freed until all of its
  7323. // certificate and CRL contexts have also been freed.
  7324. //
  7325. // On the final close, the hCryptProv passed to CertStoreOpen is
  7326. // CryptReleaseContext'ed.
  7327. //
  7328. // To force the closure of the store with all of its memory freed, set the
  7329. // CERT_STORE_CLOSE_FORCE_FLAG. This flag should be set when the caller does
  7330. // its own reference counting and wants everything to vanish.
  7331. //
  7332. // To check if all the store's certificates and CRLs have been freed and that
  7333. // this is the last CertCloseStore, set the CERT_CLOSE_STORE_CHECK_FLAG. If
  7334. // set and certs, CRLs or stores still need to be freed/closed, FALSE is
  7335. // returned with LastError set to CRYPT_E_PENDING_CLOSE. Note, for FALSE,
  7336. // the store is still closed. This is a diagnostic flag.
  7337. //
  7338. // LastError is preserved unless CERT_CLOSE_STORE_CHECK_FLAG is set and FALSE
  7339. // is returned.
  7340. //--------------------------------------------------------------------------
  7341. WINCRYPT32API
  7342. BOOL
  7343. WINAPI
  7344. CertCloseStore(
  7345. IN HCERTSTORE hCertStore,
  7346. DWORD dwFlags
  7347. );
  7348. //+-------------------------------------------------------------------------
  7349. // Get the subject certificate context uniquely identified by its Issuer and
  7350. // SerialNumber from the store.
  7351. //
  7352. // If the certificate isn't found, NULL is returned. Otherwise, a pointer to
  7353. // a read only CERT_CONTEXT is returned. CERT_CONTEXT must be freed by calling
  7354. // CertFreeCertificateContext. CertDuplicateCertificateContext can be called to make a
  7355. // duplicate.
  7356. //
  7357. // The returned certificate might not be valid. Normally, it would be
  7358. // verified when getting its issuer certificate (CertGetIssuerCertificateFromStore).
  7359. //--------------------------------------------------------------------------
  7360. WINCRYPT32API
  7361. PCCERT_CONTEXT
  7362. WINAPI
  7363. CertGetSubjectCertificateFromStore(
  7364. IN HCERTSTORE hCertStore,
  7365. IN DWORD dwCertEncodingType,
  7366. IN PCERT_INFO pCertId // Only the Issuer and SerialNumber
  7367. // fields are used
  7368. );
  7369. //+-------------------------------------------------------------------------
  7370. // Enumerate the certificate contexts in the store.
  7371. //
  7372. // If a certificate isn't found, NULL is returned.
  7373. // Otherwise, a pointer to a read only CERT_CONTEXT is returned. CERT_CONTEXT
  7374. // must be freed by calling CertFreeCertificateContext or is freed when passed as the
  7375. // pPrevCertContext on a subsequent call. CertDuplicateCertificateContext
  7376. // can be called to make a duplicate.
  7377. //
  7378. // pPrevCertContext MUST BE NULL to enumerate the first
  7379. // certificate in the store. Successive certificates are enumerated by setting
  7380. // pPrevCertContext to the CERT_CONTEXT returned by a previous call.
  7381. //
  7382. // NOTE: a NON-NULL pPrevCertContext is always CertFreeCertificateContext'ed by
  7383. // this function, even for an error.
  7384. //--------------------------------------------------------------------------
  7385. WINCRYPT32API
  7386. PCCERT_CONTEXT
  7387. WINAPI
  7388. CertEnumCertificatesInStore(
  7389. IN HCERTSTORE hCertStore,
  7390. IN PCCERT_CONTEXT pPrevCertContext
  7391. );
  7392. //+-------------------------------------------------------------------------
  7393. // Find the first or next certificate context in the store.
  7394. //
  7395. // The certificate is found according to the dwFindType and its pvFindPara.
  7396. // See below for a list of the find types and its parameters.
  7397. //
  7398. // Currently dwFindFlags is only used for CERT_FIND_SUBJECT_ATTR,
  7399. // CERT_FIND_ISSUER_ATTR or CERT_FIND_CTL_USAGE. Otherwise, must be set to 0.
  7400. //
  7401. // Usage of dwCertEncodingType depends on the dwFindType.
  7402. //
  7403. // If the first or next certificate isn't found, NULL is returned.
  7404. // Otherwise, a pointer to a read only CERT_CONTEXT is returned. CERT_CONTEXT
  7405. // must be freed by calling CertFreeCertificateContext or is freed when passed as the
  7406. // pPrevCertContext on a subsequent call. CertDuplicateCertificateContext
  7407. // can be called to make a duplicate.
  7408. //
  7409. // pPrevCertContext MUST BE NULL on the first
  7410. // call to find the certificate. To find the next certificate, the
  7411. // pPrevCertContext is set to the CERT_CONTEXT returned by a previous call.
  7412. //
  7413. // NOTE: a NON-NULL pPrevCertContext is always CertFreeCertificateContext'ed by
  7414. // this function, even for an error.
  7415. //--------------------------------------------------------------------------
  7416. WINCRYPT32API
  7417. PCCERT_CONTEXT
  7418. WINAPI
  7419. CertFindCertificateInStore(
  7420. IN HCERTSTORE hCertStore,
  7421. IN DWORD dwCertEncodingType,
  7422. IN DWORD dwFindFlags,
  7423. IN DWORD dwFindType,
  7424. IN const void *pvFindPara,
  7425. IN PCCERT_CONTEXT pPrevCertContext
  7426. );
  7427. //+-------------------------------------------------------------------------
  7428. // Certificate comparison functions
  7429. //--------------------------------------------------------------------------
  7430. #define CERT_COMPARE_MASK 0xFFFF
  7431. #define CERT_COMPARE_SHIFT 16
  7432. #define CERT_COMPARE_ANY 0
  7433. #define CERT_COMPARE_SHA1_HASH 1
  7434. #define CERT_COMPARE_NAME 2
  7435. #define CERT_COMPARE_ATTR 3
  7436. #define CERT_COMPARE_MD5_HASH 4
  7437. #define CERT_COMPARE_PROPERTY 5
  7438. #define CERT_COMPARE_PUBLIC_KEY 6
  7439. #define CERT_COMPARE_HASH CERT_COMPARE_SHA1_HASH
  7440. #define CERT_COMPARE_NAME_STR_A 7
  7441. #define CERT_COMPARE_NAME_STR_W 8
  7442. #define CERT_COMPARE_KEY_SPEC 9
  7443. #define CERT_COMPARE_ENHKEY_USAGE 10
  7444. #define CERT_COMPARE_CTL_USAGE CERT_COMPARE_ENHKEY_USAGE
  7445. #define CERT_COMPARE_SUBJECT_CERT 11
  7446. #define CERT_COMPARE_ISSUER_OF 12
  7447. #define CERT_COMPARE_EXISTING 13
  7448. #define CERT_COMPARE_SIGNATURE_HASH 14
  7449. #define CERT_COMPARE_KEY_IDENTIFIER 15
  7450. #define CERT_COMPARE_CERT_ID 16
  7451. #define CERT_COMPARE_CROSS_CERT_DIST_POINTS 17
  7452. #define CERT_COMPARE_PUBKEY_MD5_HASH 18
  7453. //+-------------------------------------------------------------------------
  7454. // dwFindType
  7455. //
  7456. // The dwFindType definition consists of two components:
  7457. // - comparison function
  7458. // - certificate information flag
  7459. //--------------------------------------------------------------------------
  7460. #define CERT_FIND_ANY (CERT_COMPARE_ANY << CERT_COMPARE_SHIFT)
  7461. #define CERT_FIND_SHA1_HASH (CERT_COMPARE_SHA1_HASH << CERT_COMPARE_SHIFT)
  7462. #define CERT_FIND_MD5_HASH (CERT_COMPARE_MD5_HASH << CERT_COMPARE_SHIFT)
  7463. #define CERT_FIND_SIGNATURE_HASH (CERT_COMPARE_SIGNATURE_HASH << CERT_COMPARE_SHIFT)
  7464. #define CERT_FIND_KEY_IDENTIFIER (CERT_COMPARE_KEY_IDENTIFIER << CERT_COMPARE_SHIFT)
  7465. #define CERT_FIND_HASH CERT_FIND_SHA1_HASH
  7466. #define CERT_FIND_PROPERTY (CERT_COMPARE_PROPERTY << CERT_COMPARE_SHIFT)
  7467. #define CERT_FIND_PUBLIC_KEY (CERT_COMPARE_PUBLIC_KEY << CERT_COMPARE_SHIFT)
  7468. #define CERT_FIND_SUBJECT_NAME (CERT_COMPARE_NAME << CERT_COMPARE_SHIFT | \
  7469. CERT_INFO_SUBJECT_FLAG)
  7470. #define CERT_FIND_SUBJECT_ATTR (CERT_COMPARE_ATTR << CERT_COMPARE_SHIFT | \
  7471. CERT_INFO_SUBJECT_FLAG)
  7472. #define CERT_FIND_ISSUER_NAME (CERT_COMPARE_NAME << CERT_COMPARE_SHIFT | \
  7473. CERT_INFO_ISSUER_FLAG)
  7474. #define CERT_FIND_ISSUER_ATTR (CERT_COMPARE_ATTR << CERT_COMPARE_SHIFT | \
  7475. CERT_INFO_ISSUER_FLAG)
  7476. #define CERT_FIND_SUBJECT_STR_A (CERT_COMPARE_NAME_STR_A << CERT_COMPARE_SHIFT | \
  7477. CERT_INFO_SUBJECT_FLAG)
  7478. #define CERT_FIND_SUBJECT_STR_W (CERT_COMPARE_NAME_STR_W << CERT_COMPARE_SHIFT | \
  7479. CERT_INFO_SUBJECT_FLAG)
  7480. #define CERT_FIND_SUBJECT_STR CERT_FIND_SUBJECT_STR_W
  7481. #define CERT_FIND_ISSUER_STR_A (CERT_COMPARE_NAME_STR_A << CERT_COMPARE_SHIFT | \
  7482. CERT_INFO_ISSUER_FLAG)
  7483. #define CERT_FIND_ISSUER_STR_W (CERT_COMPARE_NAME_STR_W << CERT_COMPARE_SHIFT | \
  7484. CERT_INFO_ISSUER_FLAG)
  7485. #define CERT_FIND_ISSUER_STR CERT_FIND_ISSUER_STR_W
  7486. #define CERT_FIND_KEY_SPEC (CERT_COMPARE_KEY_SPEC << CERT_COMPARE_SHIFT)
  7487. #define CERT_FIND_ENHKEY_USAGE (CERT_COMPARE_ENHKEY_USAGE << CERT_COMPARE_SHIFT)
  7488. #define CERT_FIND_CTL_USAGE CERT_FIND_ENHKEY_USAGE
  7489. #define CERT_FIND_SUBJECT_CERT (CERT_COMPARE_SUBJECT_CERT << CERT_COMPARE_SHIFT)
  7490. #define CERT_FIND_ISSUER_OF (CERT_COMPARE_ISSUER_OF << CERT_COMPARE_SHIFT)
  7491. #define CERT_FIND_EXISTING (CERT_COMPARE_EXISTING << CERT_COMPARE_SHIFT)
  7492. #define CERT_FIND_CERT_ID (CERT_COMPARE_CERT_ID << CERT_COMPARE_SHIFT)
  7493. #define CERT_FIND_CROSS_CERT_DIST_POINTS \
  7494. (CERT_COMPARE_CROSS_CERT_DIST_POINTS << CERT_COMPARE_SHIFT)
  7495. #define CERT_FIND_PUBKEY_MD5_HASH \
  7496. (CERT_COMPARE_PUBKEY_MD5_HASH << CERT_COMPARE_SHIFT)
  7497. //+-------------------------------------------------------------------------
  7498. // CERT_FIND_ANY
  7499. //
  7500. // Find any certificate.
  7501. //
  7502. // pvFindPara isn't used.
  7503. //--------------------------------------------------------------------------
  7504. //+-------------------------------------------------------------------------
  7505. // CERT_FIND_HASH
  7506. //
  7507. // Find a certificate with the specified hash.
  7508. //
  7509. // pvFindPara points to a CRYPT_HASH_BLOB.
  7510. //--------------------------------------------------------------------------
  7511. //+-------------------------------------------------------------------------
  7512. // CERT_FIND_KEY_IDENTIFIER
  7513. //
  7514. // Find a certificate with the specified KeyIdentifier. Gets the
  7515. // CERT_KEY_IDENTIFIER_PROP_ID property and compares with the input
  7516. // CRYPT_HASH_BLOB.
  7517. //
  7518. // pvFindPara points to a CRYPT_HASH_BLOB.
  7519. //--------------------------------------------------------------------------
  7520. //+-------------------------------------------------------------------------
  7521. // CERT_FIND_PROPERTY
  7522. //
  7523. // Find a certificate having the specified property.
  7524. //
  7525. // pvFindPara points to a DWORD containing the PROP_ID
  7526. //--------------------------------------------------------------------------
  7527. //+-------------------------------------------------------------------------
  7528. // CERT_FIND_PUBLIC_KEY
  7529. //
  7530. // Find a certificate matching the specified public key.
  7531. //
  7532. // pvFindPara points to a CERT_PUBLIC_KEY_INFO containing the public key
  7533. //--------------------------------------------------------------------------
  7534. //+-------------------------------------------------------------------------
  7535. // CERT_FIND_SUBJECT_NAME
  7536. // CERT_FIND_ISSUER_NAME
  7537. //
  7538. // Find a certificate with the specified subject/issuer name. Does an exact
  7539. // match of the entire name.
  7540. //
  7541. // Restricts search to certificates matching the dwCertEncodingType.
  7542. //
  7543. // pvFindPara points to a CERT_NAME_BLOB.
  7544. //--------------------------------------------------------------------------
  7545. //+-------------------------------------------------------------------------
  7546. // CERT_FIND_SUBJECT_ATTR
  7547. // CERT_FIND_ISSUER_ATTR
  7548. //
  7549. // Find a certificate with the specified subject/issuer attributes.
  7550. //
  7551. // Compares the attributes in the subject/issuer name with the
  7552. // Relative Distinguished Name's (CERT_RDN) array of attributes specified in
  7553. // pvFindPara. The comparison iterates through the CERT_RDN attributes and looks
  7554. // for an attribute match in any of the subject/issuer's RDNs.
  7555. //
  7556. // The CERT_RDN_ATTR fields can have the following special values:
  7557. // pszObjId == NULL - ignore the attribute object identifier
  7558. // dwValueType == RDN_ANY_TYPE - ignore the value type
  7559. // Value.pbData == NULL - match any value
  7560. //
  7561. // CERT_CASE_INSENSITIVE_IS_RDN_ATTRS_FLAG should be set in dwFindFlags to do
  7562. // a case insensitive match. Otherwise, defaults to an exact, case sensitive
  7563. // match.
  7564. //
  7565. // CERT_UNICODE_IS_RDN_ATTRS_FLAG should be set in dwFindFlags if the RDN was
  7566. // initialized with unicode strings as for
  7567. // CryptEncodeObject(X509_UNICODE_NAME).
  7568. //
  7569. // Restricts search to certificates matching the dwCertEncodingType.
  7570. //
  7571. // pvFindPara points to a CERT_RDN (defined in wincert.h).
  7572. //--------------------------------------------------------------------------
  7573. //+-------------------------------------------------------------------------
  7574. // CERT_FIND_SUBJECT_STR_A
  7575. // CERT_FIND_SUBJECT_STR_W | CERT_FIND_SUBJECT_STR
  7576. // CERT_FIND_ISSUER_STR_A
  7577. // CERT_FIND_ISSUER_STR_W | CERT_FIND_ISSUER_STR
  7578. //
  7579. // Find a certificate containing the specified subject/issuer name string.
  7580. //
  7581. // First, the certificate's subject/issuer is converted to a name string
  7582. // via CertNameToStrA/CertNameToStrW(CERT_SIMPLE_NAME_STR). Then, a
  7583. // case insensitive substring within string match is performed.
  7584. //
  7585. // Restricts search to certificates matching the dwCertEncodingType.
  7586. //
  7587. // For *_STR_A, pvFindPara points to a null terminated character string.
  7588. // For *_STR_W, pvFindPara points to a null terminated wide character string.
  7589. //--------------------------------------------------------------------------
  7590. //+-------------------------------------------------------------------------
  7591. // CERT_FIND_KEY_SPEC
  7592. //
  7593. // Find a certificate having a CERT_KEY_SPEC_PROP_ID property matching
  7594. // the specified KeySpec.
  7595. //
  7596. // pvFindPara points to a DWORD containing the KeySpec.
  7597. //--------------------------------------------------------------------------
  7598. //+-------------------------------------------------------------------------
  7599. // CERT_FIND_ENHKEY_USAGE
  7600. //
  7601. // Find a certificate having the szOID_ENHANCED_KEY_USAGE extension or
  7602. // the CERT_ENHKEY_USAGE_PROP_ID and matching the specified pszUsageIdentifers.
  7603. //
  7604. // pvFindPara points to a CERT_ENHKEY_USAGE data structure. If pvFindPara
  7605. // is NULL or CERT_ENHKEY_USAGE's cUsageIdentifier is 0, then, matches any
  7606. // certificate having enhanced key usage.
  7607. //
  7608. // If the CERT_FIND_VALID_ENHKEY_USAGE_FLAG is set, then, only does a match
  7609. // for certificates that are valid for the specified usages. By default,
  7610. // the ceriticate must be valid for all usages. CERT_FIND_OR_ENHKEY_USAGE_FLAG
  7611. // can be set, if the certificate only needs to be valid for one of the
  7612. // specified usages. Note, CertGetValidUsages() is called to get the
  7613. // certificate's list of valid usages. Only the CERT_FIND_OR_ENHKEY_USAGE_FLAG
  7614. // is applicable when this flag is set.
  7615. //
  7616. // The CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG can be set in dwFindFlags to
  7617. // also match a certificate without either the extension or property.
  7618. //
  7619. // If CERT_FIND_NO_ENHKEY_USAGE_FLAG is set in dwFindFlags, finds
  7620. // certificates without the key usage extension or property. Setting this
  7621. // flag takes precedence over pvFindPara being NULL.
  7622. //
  7623. // If the CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG is set, then, only does a match
  7624. // using the extension. If pvFindPara is NULL or cUsageIdentifier is set to
  7625. // 0, finds certificates having the extension. If
  7626. // CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG is set, also matches a certificate
  7627. // without the extension. If CERT_FIND_NO_ENHKEY_USAGE_FLAG is set, finds
  7628. // certificates without the extension.
  7629. //
  7630. // If the CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG is set, then, only does a match
  7631. // using the property. If pvFindPara is NULL or cUsageIdentifier is set to
  7632. // 0, finds certificates having the property. If
  7633. // CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG is set, also matches a certificate
  7634. // without the property. If CERT_FIND_NO_ENHKEY_USAGE_FLAG is set, finds
  7635. // certificates without the property.
  7636. //
  7637. // If CERT_FIND_OR_ENHKEY_USAGE_FLAG is set, does an "OR" match of any of
  7638. // the specified pszUsageIdentifiers. If not set, then, does an "AND" match
  7639. // of all of the specified pszUsageIdentifiers.
  7640. //--------------------------------------------------------------------------
  7641. #define CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG 0x1
  7642. #define CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG 0x2
  7643. #define CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG 0x4
  7644. #define CERT_FIND_NO_ENHKEY_USAGE_FLAG 0x8
  7645. #define CERT_FIND_OR_ENHKEY_USAGE_FLAG 0x10
  7646. #define CERT_FIND_VALID_ENHKEY_USAGE_FLAG 0x20
  7647. #define CERT_FIND_OPTIONAL_CTL_USAGE_FLAG CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG
  7648. #define CERT_FIND_EXT_ONLY_CTL_USAGE_FLAG \
  7649. CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG
  7650. #define CERT_FIND_PROP_ONLY_CTL_USAGE_FLAG \
  7651. CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG
  7652. #define CERT_FIND_NO_CTL_USAGE_FLAG CERT_FIND_NO_ENHKEY_USAGE_FLAG
  7653. #define CERT_FIND_OR_CTL_USAGE_FLAG CERT_FIND_OR_ENHKEY_USAGE_FLAG
  7654. #define CERT_FIND_VALID_CTL_USAGE_FLAG CERT_FIND_VALID_ENHKEY_USAGE_FLAG
  7655. //+-------------------------------------------------------------------------
  7656. // CERT_FIND_CERT_ID
  7657. //
  7658. // Find a certificate with the specified CERT_ID.
  7659. //
  7660. // pvFindPara points to a CERT_ID.
  7661. //--------------------------------------------------------------------------
  7662. //+-------------------------------------------------------------------------
  7663. // CERT_FIND_CROSS_CERT_DIST_POINTS
  7664. //
  7665. // Find a certificate having either a cross certificate distribution
  7666. // point extension or property.
  7667. //
  7668. // pvFindPara isn't used.
  7669. //--------------------------------------------------------------------------
  7670. //+-------------------------------------------------------------------------
  7671. // Get the certificate context from the store for the first or next issuer
  7672. // of the specified subject certificate. Perform the enabled
  7673. // verification checks on the subject. (Note, the checks are on the subject
  7674. // using the returned issuer certificate.)
  7675. //
  7676. // If the first or next issuer certificate isn't found, NULL is returned.
  7677. // Otherwise, a pointer to a read only CERT_CONTEXT is returned. CERT_CONTEXT
  7678. // must be freed by calling CertFreeCertificateContext or is freed when passed as the
  7679. // pPrevIssuerContext on a subsequent call. CertDuplicateCertificateContext
  7680. // can be called to make a duplicate.
  7681. //
  7682. // For a self signed subject certificate, NULL is returned with LastError set
  7683. // to CERT_STORE_SELF_SIGNED. The enabled verification checks are still done.
  7684. //
  7685. // The pSubjectContext may have been obtained from this store, another store
  7686. // or created by the caller application. When created by the caller, the
  7687. // CertCreateCertificateContext function must have been called.
  7688. //
  7689. // An issuer may have multiple certificates. This may occur when the validity
  7690. // period is about to change. pPrevIssuerContext MUST BE NULL on the first
  7691. // call to get the issuer. To get the next certificate for the issuer, the
  7692. // pPrevIssuerContext is set to the CERT_CONTEXT returned by a previous call.
  7693. //
  7694. // NOTE: a NON-NULL pPrevIssuerContext is always CertFreeCertificateContext'ed by
  7695. // this function, even for an error.
  7696. //
  7697. // The following flags can be set in *pdwFlags to enable verification checks
  7698. // on the subject certificate context:
  7699. // CERT_STORE_SIGNATURE_FLAG - use the public key in the returned
  7700. // issuer certificate to verify the
  7701. // signature on the subject certificate.
  7702. // Note, if pSubjectContext->hCertStore ==
  7703. // hCertStore, the store provider might
  7704. // be able to eliminate a redo of
  7705. // the signature verify.
  7706. // CERT_STORE_TIME_VALIDITY_FLAG - get the current time and verify that
  7707. // its within the subject certificate's
  7708. // validity period
  7709. // CERT_STORE_REVOCATION_FLAG - check if the subject certificate is on
  7710. // the issuer's revocation list
  7711. //
  7712. // If an enabled verification check fails, then, its flag is set upon return.
  7713. // If CERT_STORE_REVOCATION_FLAG was enabled and the issuer doesn't have a
  7714. // CRL in the store, then, CERT_STORE_NO_CRL_FLAG is set in addition to
  7715. // the CERT_STORE_REVOCATION_FLAG.
  7716. //
  7717. // If CERT_STORE_SIGNATURE_FLAG or CERT_STORE_REVOCATION_FLAG is set, then,
  7718. // CERT_STORE_NO_ISSUER_FLAG is set if it doesn't have an issuer certificate
  7719. // in the store.
  7720. //
  7721. // For a verification check failure, a pointer to the issuer's CERT_CONTEXT
  7722. // is still returned and SetLastError isn't updated.
  7723. //--------------------------------------------------------------------------
  7724. WINCRYPT32API
  7725. PCCERT_CONTEXT
  7726. WINAPI
  7727. CertGetIssuerCertificateFromStore(
  7728. IN HCERTSTORE hCertStore,
  7729. IN PCCERT_CONTEXT pSubjectContext,
  7730. IN OPTIONAL PCCERT_CONTEXT pPrevIssuerContext,
  7731. IN OUT DWORD *pdwFlags
  7732. );
  7733. //+-------------------------------------------------------------------------
  7734. // Perform the enabled verification checks on the subject certificate
  7735. // using the issuer. Same checks and flags definitions as for the above
  7736. // CertGetIssuerCertificateFromStore.
  7737. //
  7738. // If you are only checking CERT_STORE_TIME_VALIDITY_FLAG, then, the
  7739. // issuer can be NULL.
  7740. //
  7741. // For a verification check failure, SUCCESS is still returned.
  7742. //--------------------------------------------------------------------------
  7743. WINCRYPT32API
  7744. BOOL
  7745. WINAPI
  7746. CertVerifySubjectCertificateContext(
  7747. IN PCCERT_CONTEXT pSubject,
  7748. IN OPTIONAL PCCERT_CONTEXT pIssuer,
  7749. IN OUT DWORD *pdwFlags
  7750. );
  7751. //+-------------------------------------------------------------------------
  7752. // Duplicate a certificate context
  7753. //--------------------------------------------------------------------------
  7754. WINCRYPT32API
  7755. PCCERT_CONTEXT
  7756. WINAPI
  7757. CertDuplicateCertificateContext(
  7758. IN PCCERT_CONTEXT pCertContext
  7759. );
  7760. //+-------------------------------------------------------------------------
  7761. // Create a certificate context from the encoded certificate. The created
  7762. // context isn't put in a store.
  7763. //
  7764. // Makes a copy of the encoded certificate in the created context.
  7765. //
  7766. // If unable to decode and create the certificate context, NULL is returned.
  7767. // Otherwise, a pointer to a read only CERT_CONTEXT is returned.
  7768. // CERT_CONTEXT must be freed by calling CertFreeCertificateContext.
  7769. // CertDuplicateCertificateContext can be called to make a duplicate.
  7770. //
  7771. // CertSetCertificateContextProperty and CertGetCertificateContextProperty can be called
  7772. // to store properties for the certificate.
  7773. //--------------------------------------------------------------------------
  7774. WINCRYPT32API
  7775. PCCERT_CONTEXT
  7776. WINAPI
  7777. CertCreateCertificateContext(
  7778. IN DWORD dwCertEncodingType,
  7779. IN const BYTE *pbCertEncoded,
  7780. IN DWORD cbCertEncoded
  7781. );
  7782. //+-------------------------------------------------------------------------
  7783. // Free a certificate context
  7784. //
  7785. // There needs to be a corresponding free for each context obtained by a
  7786. // get, find, duplicate or create.
  7787. //--------------------------------------------------------------------------
  7788. WINCRYPT32API
  7789. BOOL
  7790. WINAPI
  7791. CertFreeCertificateContext(
  7792. IN PCCERT_CONTEXT pCertContext
  7793. );
  7794. //+-------------------------------------------------------------------------
  7795. // Set the property for the specified certificate context.
  7796. //
  7797. // The type definition for pvData depends on the dwPropId value. There are
  7798. // five predefined types:
  7799. // CERT_KEY_PROV_HANDLE_PROP_ID - a HCRYPTPROV for the certificate's
  7800. // private key is passed in pvData. Updates the hCryptProv field
  7801. // of the CERT_KEY_CONTEXT_PROP_ID. If the CERT_KEY_CONTEXT_PROP_ID
  7802. // doesn't exist, its created with all the other fields zeroed out. If
  7803. // CERT_STORE_NO_CRYPT_RELEASE_FLAG isn't set, HCRYPTPROV is implicitly
  7804. // released when either the property is set to NULL or on the final
  7805. // free of the CertContext.
  7806. //
  7807. // CERT_KEY_PROV_INFO_PROP_ID - a PCRYPT_KEY_PROV_INFO for the certificate's
  7808. // private key is passed in pvData.
  7809. //
  7810. // CERT_SHA1_HASH_PROP_ID -
  7811. // CERT_MD5_HASH_PROP_ID -
  7812. // CERT_SIGNATURE_HASH_PROP_ID - normally, a hash property is implicitly
  7813. // set by doing a CertGetCertificateContextProperty. pvData points to a
  7814. // CRYPT_HASH_BLOB.
  7815. //
  7816. // CERT_KEY_CONTEXT_PROP_ID - a PCERT_KEY_CONTEXT for the certificate's
  7817. // private key is passed in pvData. The CERT_KEY_CONTEXT contains both the
  7818. // hCryptProv and dwKeySpec for the private key.
  7819. // See the CERT_KEY_PROV_HANDLE_PROP_ID for more information about
  7820. // the hCryptProv field and dwFlags settings. Note, more fields may
  7821. // be added for this property. The cbSize field value will be adjusted
  7822. // accordingly.
  7823. //
  7824. // CERT_KEY_SPEC_PROP_ID - the dwKeySpec for the private key. pvData
  7825. // points to a DWORD containing the KeySpec
  7826. //
  7827. // CERT_ENHKEY_USAGE_PROP_ID - enhanced key usage definition for the
  7828. // certificate. pvData points to a CRYPT_DATA_BLOB containing an
  7829. // ASN.1 encoded CERT_ENHKEY_USAGE (encoded via
  7830. // CryptEncodeObject(X509_ENHANCED_KEY_USAGE).
  7831. //
  7832. // CERT_NEXT_UPDATE_LOCATION_PROP_ID - location of the next update.
  7833. // Currently only applicable to CTLs. pvData points to a CRYPT_DATA_BLOB
  7834. // containing an ASN.1 encoded CERT_ALT_NAME_INFO (encoded via
  7835. // CryptEncodeObject(X509_ALTERNATE_NAME)).
  7836. //
  7837. // CERT_FRIENDLY_NAME_PROP_ID - friendly name for the cert, CRL or CTL.
  7838. // pvData points to a CRYPT_DATA_BLOB. pbData is a pointer to a NULL
  7839. // terminated unicode, wide character string.
  7840. // cbData = (wcslen((LPWSTR) pbData) + 1) * sizeof(WCHAR).
  7841. //
  7842. // CERT_DESCRIPTION_PROP_ID - description for the cert, CRL or CTL.
  7843. // pvData points to a CRYPT_DATA_BLOB. pbData is a pointer to a NULL
  7844. // terminated unicode, wide character string.
  7845. // cbData = (wcslen((LPWSTR) pbData) + 1) * sizeof(WCHAR).
  7846. //
  7847. // CERT_ARCHIVED_PROP_ID - when this property is set, the certificate
  7848. // is skipped during enumeration. Note, certificates having this property
  7849. // are still found for explicit finds, such as, finding a certificate
  7850. // with a specific hash or finding a certificate having a specific issuer
  7851. // and serial number. pvData points to a CRYPT_DATA_BLOB. This blob
  7852. // can be NULL (pbData = NULL, cbData = 0).
  7853. //
  7854. // CERT_PUBKEY_ALG_PARA_PROP_ID - for public keys supporting
  7855. // algorithm parameter inheritance. pvData points to a CRYPT_OBJID_BLOB
  7856. // containing the ASN.1 encoded PublicKey Algorithm Parameters. For
  7857. // DSS this would be the parameters encoded via
  7858. // CryptEncodeObject(X509_DSS_PARAMETERS). This property may be set
  7859. // by CryptVerifyCertificateSignatureEx().
  7860. //
  7861. // CERT_CROSS_CERT_DIST_POINTS_PROP_ID - location of the cross certs.
  7862. // Currently only applicable to certs. pvData points to a CRYPT_DATA_BLOB
  7863. // containing an ASN.1 encoded CROSS_CERT_DIST_POINTS_INFO (encoded via
  7864. // CryptEncodeObject(X509_CROSS_CERT_DIST_POINTS)).
  7865. //
  7866. // CERT_ENROLLMENT_PROP_ID - enrollment information of the pending request.
  7867. // It contains RequestID, CADNSName, CAName, and FriendlyName.
  7868. // The data format is defined as, the first 4 bytes - pending request ID,
  7869. // next 4 bytes - CADNSName size in characters including null-terminator
  7870. // followed by CADNSName string with null-terminator,
  7871. // next 4 bytes - CAName size in characters including null-terminator
  7872. // followed by CAName string with null-terminator,
  7873. // next 4 bytes - FriendlyName size in characters including null-terminator
  7874. // followed by FriendlyName string with null-terminator.
  7875. //
  7876. // CERT_DATE_STAMP_PROP_ID - contains the time when added to the store
  7877. // by an admin tool. pvData points to a CRYPT_DATA_BLOB containing
  7878. // the FILETIME.
  7879. //
  7880. // CERT_RENEWAL_PROP_ID - contains the hash of renewed certificate
  7881. //
  7882. // For all the other PROP_IDs: an encoded PCRYPT_DATA_BLOB is passed in pvData.
  7883. //
  7884. // If the property already exists, then, the old value is deleted and silently
  7885. // replaced. Setting, pvData to NULL, deletes the property.
  7886. //
  7887. // CERT_SET_PROPERTY_IGNORE_PERSIST_ERROR_FLAG can be set to ignore any
  7888. // provider write errors and always update the cached context's property.
  7889. //--------------------------------------------------------------------------
  7890. WINCRYPT32API
  7891. BOOL
  7892. WINAPI
  7893. CertSetCertificateContextProperty(
  7894. IN PCCERT_CONTEXT pCertContext,
  7895. IN DWORD dwPropId,
  7896. IN DWORD dwFlags,
  7897. IN const void *pvData
  7898. );
  7899. // Set this flag to ignore any store provider write errors and always update
  7900. // the cached context's property
  7901. #define CERT_SET_PROPERTY_IGNORE_PERSIST_ERROR_FLAG 0x80000000
  7902. // Set this flag to inhibit the persisting of this property
  7903. #define CERT_SET_PROPERTY_INHIBIT_PERSIST_FLAG 0x40000000
  7904. //+-------------------------------------------------------------------------
  7905. // Get the property for the specified certificate context.
  7906. //
  7907. // For CERT_KEY_PROV_HANDLE_PROP_ID, pvData points to a HCRYPTPROV.
  7908. //
  7909. // For CERT_KEY_PROV_INFO_PROP_ID, pvData points to a CRYPT_KEY_PROV_INFO structure.
  7910. // Elements pointed to by fields in the pvData structure follow the
  7911. // structure. Therefore, *pcbData may exceed the size of the structure.
  7912. //
  7913. // For CERT_KEY_CONTEXT_PROP_ID, pvData points to a CERT_KEY_CONTEXT structure.
  7914. //
  7915. // For CERT_KEY_SPEC_PROP_ID, pvData points to a DWORD containing the KeySpec.
  7916. // If the CERT_KEY_CONTEXT_PROP_ID exists, the KeySpec is obtained from there.
  7917. // Otherwise, if the CERT_KEY_PROV_INFO_PROP_ID exists, its the source
  7918. // of the KeySpec.
  7919. //
  7920. // For CERT_SHA1_HASH_PROP_ID or CERT_MD5_HASH_PROP_ID, if the hash
  7921. // doesn't already exist, then, its computed via CryptHashCertificate()
  7922. // and then set. pvData points to the computed hash. Normally, the length
  7923. // is 20 bytes for SHA and 16 for MD5.
  7924. //
  7925. // For CERT_SIGNATURE_HASH_PROP_ID, if the hash
  7926. // doesn't already exist, then, its computed via CryptHashToBeSigned()
  7927. // and then set. pvData points to the computed hash. Normally, the length
  7928. // is 20 bytes for SHA and 16 for MD5.
  7929. //
  7930. // For CERT_ACCESS_STATE_PROP_ID, pvData points to a DWORD containing the
  7931. // access state flags. The appropriate CERT_ACCESS_STATE_*_FLAG's are set
  7932. // in the returned DWORD. See the CERT_ACCESS_STATE_*_FLAG definitions
  7933. // above. Note, this property is read only. It can't be set.
  7934. //
  7935. // For CERT_KEY_IDENTIFIER_PROP_ID, if property doesn't already exist,
  7936. // first searches for the szOID_SUBJECT_KEY_IDENTIFIER extension. Next,
  7937. // does SHA1 hash of the certficate's SubjectPublicKeyInfo. pvData
  7938. // points to the key identifier bytes. Normally, the length is 20 bytes.
  7939. //
  7940. // For CERT_PUBKEY_ALG_PARA_PROP_ID, pvPara points to the ASN.1 encoded
  7941. // PublicKey Algorithm Parameters. This property will only be set
  7942. // for public keys supporting algorithm parameter inheritance and when the
  7943. // parameters have been omitted from the encoded and signed certificate.
  7944. //
  7945. // For CERT_DATE_STAMP_PROP_ID, pvPara points to a FILETIME updated by
  7946. // an admin tool to indicate when the certificate was added to the store.
  7947. //
  7948. // For all other PROP_IDs, pvData points to an encoded array of bytes.
  7949. //--------------------------------------------------------------------------
  7950. WINCRYPT32API
  7951. BOOL
  7952. WINAPI
  7953. CertGetCertificateContextProperty(
  7954. IN PCCERT_CONTEXT pCertContext,
  7955. IN DWORD dwPropId,
  7956. OUT void *pvData,
  7957. IN OUT DWORD *pcbData
  7958. );
  7959. //+-------------------------------------------------------------------------
  7960. // Enumerate the properties for the specified certificate context.
  7961. //
  7962. // To get the first property, set dwPropId to 0. The ID of the first
  7963. // property is returned. To get the next property, set dwPropId to the
  7964. // ID returned by the last call. To enumerate all the properties continue
  7965. // until 0 is returned.
  7966. //
  7967. // CertGetCertificateContextProperty is called to get the property's data.
  7968. //
  7969. // Note, since, the CERT_KEY_PROV_HANDLE_PROP_ID and CERT_KEY_SPEC_PROP_ID
  7970. // properties are stored as fields in the CERT_KEY_CONTEXT_PROP_ID
  7971. // property, they aren't enumerated individually.
  7972. //--------------------------------------------------------------------------
  7973. WINCRYPT32API
  7974. DWORD
  7975. WINAPI
  7976. CertEnumCertificateContextProperties(
  7977. IN PCCERT_CONTEXT pCertContext,
  7978. IN DWORD dwPropId
  7979. );
  7980. //+-------------------------------------------------------------------------
  7981. // Creates a CTL entry whose attributes are the certificate context's
  7982. // properties.
  7983. //
  7984. // The SubjectIdentifier in the CTL entry is the SHA1 hash of the certificate.
  7985. //
  7986. // The certificate properties are added as attributes. The property attribute
  7987. // OID is the decimal PROP_ID preceded by szOID_CERT_PROP_ID_PREFIX. Each
  7988. // property value is copied as a single attribute value.
  7989. //
  7990. // Any additional attributes to be included in the CTL entry can be passed
  7991. // in via the cOptAttr and rgOptAttr parameters.
  7992. //
  7993. // CTL_ENTRY_FROM_PROP_CHAIN_FLAG can be set in dwFlags, to force the
  7994. // inclusion of the chain building hash properties as attributes.
  7995. //--------------------------------------------------------------------------
  7996. WINCRYPT32API
  7997. BOOL
  7998. WINAPI
  7999. CertCreateCTLEntryFromCertificateContextProperties(
  8000. IN PCCERT_CONTEXT pCertContext,
  8001. IN DWORD cOptAttr,
  8002. IN OPTIONAL PCRYPT_ATTRIBUTE rgOptAttr,
  8003. IN DWORD dwFlags,
  8004. IN OPTIONAL void *pvReserved,
  8005. OUT OPTIONAL PCTL_ENTRY pCtlEntry,
  8006. IN OUT DWORD *pcbCtlEntry
  8007. );
  8008. // Set this flag to get and include the chain building hash properties
  8009. // as attributes in the CTL entry
  8010. #define CTL_ENTRY_FROM_PROP_CHAIN_FLAG 0x1
  8011. //+-------------------------------------------------------------------------
  8012. // Sets properties on the certificate context using the attributes in
  8013. // the CTL entry.
  8014. //
  8015. // The property attribute OID is the decimal PROP_ID preceded by
  8016. // szOID_CERT_PROP_ID_PREFIX. Only attributes containing such an OID are
  8017. // copied.
  8018. //
  8019. // CERT_SET_PROPERTY_IGNORE_PERSIST_ERROR_FLAG may be set in dwFlags.
  8020. //--------------------------------------------------------------------------
  8021. WINCRYPT32API
  8022. BOOL
  8023. WINAPI
  8024. CertSetCertificateContextPropertiesFromCTLEntry(
  8025. IN PCCERT_CONTEXT pCertContext,
  8026. IN PCTL_ENTRY pCtlEntry,
  8027. IN DWORD dwFlags
  8028. );
  8029. //+-------------------------------------------------------------------------
  8030. // Get the first or next CRL context from the store for the specified
  8031. // issuer certificate. Perform the enabled verification checks on the CRL.
  8032. //
  8033. // If the first or next CRL isn't found, NULL is returned.
  8034. // Otherwise, a pointer to a read only CRL_CONTEXT is returned. CRL_CONTEXT
  8035. // must be freed by calling CertFreeCRLContext. However, the free must be
  8036. // pPrevCrlContext on a subsequent call. CertDuplicateCRLContext
  8037. // can be called to make a duplicate.
  8038. //
  8039. // The pIssuerContext may have been obtained from this store, another store
  8040. // or created by the caller application. When created by the caller, the
  8041. // CertCreateCertificateContext function must have been called.
  8042. //
  8043. // If pIssuerContext == NULL, finds all the CRLs in the store.
  8044. //
  8045. // An issuer may have multiple CRLs. For example, it generates delta CRLs
  8046. // using a X.509 v3 extension. pPrevCrlContext MUST BE NULL on the first
  8047. // call to get the CRL. To get the next CRL for the issuer, the
  8048. // pPrevCrlContext is set to the CRL_CONTEXT returned by a previous call.
  8049. //
  8050. // NOTE: a NON-NULL pPrevCrlContext is always CertFreeCRLContext'ed by
  8051. // this function, even for an error.
  8052. //
  8053. // The following flags can be set in *pdwFlags to enable verification checks
  8054. // on the returned CRL:
  8055. // CERT_STORE_SIGNATURE_FLAG - use the public key in the
  8056. // issuer's certificate to verify the
  8057. // signature on the returned CRL.
  8058. // Note, if pIssuerContext->hCertStore ==
  8059. // hCertStore, the store provider might
  8060. // be able to eliminate a redo of
  8061. // the signature verify.
  8062. // CERT_STORE_TIME_VALIDITY_FLAG - get the current time and verify that
  8063. // its within the CRL's ThisUpdate and
  8064. // NextUpdate validity period.
  8065. // CERT_STORE_BASE_CRL_FLAG - get base CRL.
  8066. // CERT_STORE_DELTA_CRL_FLAG - get delta CRL.
  8067. //
  8068. // If only one of CERT_STORE_BASE_CRL_FLAG or CERT_STORE_DELTA_CRL_FLAG is
  8069. // set, then, only returns either a base or delta CRL. In any case, the
  8070. // appropriate base or delta flag will be cleared upon returned. If both
  8071. // flags are set, then, only one of flags will be cleared.
  8072. //
  8073. // If an enabled verification check fails, then, its flag is set upon return.
  8074. //
  8075. // If pIssuerContext == NULL, then, an enabled CERT_STORE_SIGNATURE_FLAG
  8076. // always fails and the CERT_STORE_NO_ISSUER_FLAG is also set.
  8077. //
  8078. // For a verification check failure, a pointer to the first or next
  8079. // CRL_CONTEXT is still returned and SetLastError isn't updated.
  8080. //--------------------------------------------------------------------------
  8081. WINCRYPT32API
  8082. PCCRL_CONTEXT
  8083. WINAPI
  8084. CertGetCRLFromStore(
  8085. IN HCERTSTORE hCertStore,
  8086. IN OPTIONAL PCCERT_CONTEXT pIssuerContext,
  8087. IN PCCRL_CONTEXT pPrevCrlContext,
  8088. IN OUT DWORD *pdwFlags
  8089. );
  8090. //+-------------------------------------------------------------------------
  8091. // Enumerate the CRL contexts in the store.
  8092. //
  8093. // If a CRL isn't found, NULL is returned.
  8094. // Otherwise, a pointer to a read only CRL_CONTEXT is returned. CRL_CONTEXT
  8095. // must be freed by calling CertFreeCRLContext or is freed when passed as the
  8096. // pPrevCrlContext on a subsequent call. CertDuplicateCRLContext
  8097. // can be called to make a duplicate.
  8098. //
  8099. // pPrevCrlContext MUST BE NULL to enumerate the first
  8100. // CRL in the store. Successive CRLs are enumerated by setting
  8101. // pPrevCrlContext to the CRL_CONTEXT returned by a previous call.
  8102. //
  8103. // NOTE: a NON-NULL pPrevCrlContext is always CertFreeCRLContext'ed by
  8104. // this function, even for an error.
  8105. //--------------------------------------------------------------------------
  8106. WINCRYPT32API
  8107. PCCRL_CONTEXT
  8108. WINAPI
  8109. CertEnumCRLsInStore(
  8110. IN HCERTSTORE hCertStore,
  8111. IN PCCRL_CONTEXT pPrevCrlContext
  8112. );
  8113. //+-------------------------------------------------------------------------
  8114. // Find the first or next CRL context in the store.
  8115. //
  8116. // The CRL is found according to the dwFindType and its pvFindPara.
  8117. // See below for a list of the find types and its parameters.
  8118. //
  8119. // Currently dwFindFlags isn't used and must be set to 0.
  8120. //
  8121. // Usage of dwCertEncodingType depends on the dwFindType.
  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 or is freed when passed as the
  8126. // pPrevCrlContext on a subsequent call. CertDuplicateCRLContext
  8127. // can be called to make a duplicate.
  8128. //
  8129. // pPrevCrlContext MUST BE NULL on the first
  8130. // call to find the CRL. To find the next CRL, the
  8131. // pPrevCrlContext is set to the CRL_CONTEXT returned by a previous call.
  8132. //
  8133. // NOTE: a NON-NULL pPrevCrlContext is always CertFreeCRLContext'ed by
  8134. // this function, even for an error.
  8135. //--------------------------------------------------------------------------
  8136. WINCRYPT32API
  8137. PCCRL_CONTEXT
  8138. WINAPI
  8139. CertFindCRLInStore(
  8140. IN HCERTSTORE hCertStore,
  8141. IN DWORD dwCertEncodingType,
  8142. IN DWORD dwFindFlags,
  8143. IN DWORD dwFindType,
  8144. IN const void *pvFindPara,
  8145. IN PCCRL_CONTEXT pPrevCrlContext
  8146. );
  8147. #define CRL_FIND_ANY 0
  8148. #define CRL_FIND_ISSUED_BY 1
  8149. #define CRL_FIND_EXISTING 2
  8150. #define CRL_FIND_ISSUED_FOR 3
  8151. //+-------------------------------------------------------------------------
  8152. // CRL_FIND_ANY
  8153. //
  8154. // Find any CRL.
  8155. //
  8156. // pvFindPara isn't used.
  8157. //--------------------------------------------------------------------------
  8158. //+-------------------------------------------------------------------------
  8159. // CRL_FIND_ISSUED_BY
  8160. //
  8161. // Find CRL matching the specified issuer.
  8162. //
  8163. // pvFindPara is the PCCERT_CONTEXT of the CRL issuer. May be NULL to
  8164. // match any issuer.
  8165. //
  8166. // By default, only does issuer name matching. The following flags can be
  8167. // set in dwFindFlags to do additional filtering.
  8168. //
  8169. // If CRL_FIND_ISSUED_BY_AKI_FLAG is set in dwFindFlags, then, checks if the
  8170. // CRL has an Authority Key Identifier (AKI) extension. If the CRL has an
  8171. // AKI, then, only returns a CRL whose AKI matches the issuer.
  8172. //
  8173. // Note, the AKI extension has the following OID:
  8174. // szOID_AUTHORITY_KEY_IDENTIFIER2 and its corresponding data structure.
  8175. //
  8176. // If CRL_FIND_ISSUED_BY_SIGNATURE_FLAG is set in dwFindFlags, then,
  8177. // uses the public key in the issuer's certificate to verify the
  8178. // signature on the CRL. Only returns a CRL having a valid signature.
  8179. //
  8180. // If CRL_FIND_ISSUED_BY_DELTA_FLAG is set in dwFindFlags, then, only
  8181. // returns a delta CRL.
  8182. //
  8183. // If CRL_FIND_ISSUED_BY_BASE_FLAG is set in dwFindFlags, then, only
  8184. // returns a base CRL.
  8185. //--------------------------------------------------------------------------
  8186. #define CRL_FIND_ISSUED_BY_AKI_FLAG 0x1
  8187. #define CRL_FIND_ISSUED_BY_SIGNATURE_FLAG 0x2
  8188. #define CRL_FIND_ISSUED_BY_DELTA_FLAG 0x4
  8189. #define CRL_FIND_ISSUED_BY_BASE_FLAG 0x8
  8190. //+-------------------------------------------------------------------------
  8191. // CRL_FIND_EXISTING
  8192. //
  8193. // Find existing CRL in the store.
  8194. //
  8195. // pvFindPara is the PCCRL_CONTEXT of the CRL to check if it already
  8196. // exists in the store.
  8197. //--------------------------------------------------------------------------
  8198. //+-------------------------------------------------------------------------
  8199. // CRL_FIND_ISSUED_FOR
  8200. //
  8201. // Find CRL for the specified subject and its issuer.
  8202. //
  8203. // pvFindPara points to the following CRL_FIND_ISSUED_FOR_PARA which contains
  8204. // both the subject and issuer certificates. Not optional.
  8205. //
  8206. // The subject's issuer name is used to match the CRL's issuer name. Otherwise,
  8207. // the issuer's certificate is used the same as in the above
  8208. // CRL_FIND_ISSUED_BY.
  8209. //
  8210. // Note, when cross certificates are used, the subject name in the issuer's
  8211. // certificate may not match the issuer name in the subject certificate and
  8212. // its corresponding CRL.
  8213. //
  8214. // All of the above CRL_FIND_ISSUED_BY_*_FLAGS apply to this find type.
  8215. //--------------------------------------------------------------------------
  8216. typedef struct _CRL_FIND_ISSUED_FOR_PARA {
  8217. PCCERT_CONTEXT pSubjectCert;
  8218. PCCERT_CONTEXT pIssuerCert;
  8219. } CRL_FIND_ISSUED_FOR_PARA, *PCRL_FIND_ISSUED_FOR_PARA;
  8220. //+-------------------------------------------------------------------------
  8221. // Duplicate a CRL context
  8222. //--------------------------------------------------------------------------
  8223. WINCRYPT32API
  8224. PCCRL_CONTEXT
  8225. WINAPI
  8226. CertDuplicateCRLContext(
  8227. IN PCCRL_CONTEXT pCrlContext
  8228. );
  8229. //+-------------------------------------------------------------------------
  8230. // Create a CRL context from the encoded CRL. The created
  8231. // context isn't put in a store.
  8232. //
  8233. // Makes a copy of the encoded CRL in the created context.
  8234. //
  8235. // If unable to decode and create the CRL context, NULL is returned.
  8236. // Otherwise, a pointer to a read only CRL_CONTEXT is returned.
  8237. // CRL_CONTEXT must be freed by calling CertFreeCRLContext.
  8238. // CertDuplicateCRLContext can be called to make a duplicate.
  8239. //
  8240. // CertSetCRLContextProperty and CertGetCRLContextProperty can be called
  8241. // to store properties for the CRL.
  8242. //--------------------------------------------------------------------------
  8243. WINCRYPT32API
  8244. PCCRL_CONTEXT
  8245. WINAPI
  8246. CertCreateCRLContext(
  8247. IN DWORD dwCertEncodingType,
  8248. IN const BYTE *pbCrlEncoded,
  8249. IN DWORD cbCrlEncoded
  8250. );
  8251. //+-------------------------------------------------------------------------
  8252. // Free a CRL context
  8253. //
  8254. // There needs to be a corresponding free for each context obtained by a
  8255. // get, duplicate or create.
  8256. //--------------------------------------------------------------------------
  8257. WINCRYPT32API
  8258. BOOL
  8259. WINAPI
  8260. CertFreeCRLContext(
  8261. IN PCCRL_CONTEXT pCrlContext
  8262. );
  8263. //+-------------------------------------------------------------------------
  8264. // Set the property for the specified CRL context.
  8265. //
  8266. // Same Property Ids and semantics as CertSetCertificateContextProperty.
  8267. //--------------------------------------------------------------------------
  8268. WINCRYPT32API
  8269. BOOL
  8270. WINAPI
  8271. CertSetCRLContextProperty(
  8272. IN PCCRL_CONTEXT pCrlContext,
  8273. IN DWORD dwPropId,
  8274. IN DWORD dwFlags,
  8275. IN const void *pvData
  8276. );
  8277. //+-------------------------------------------------------------------------
  8278. // Get the property for the specified CRL context.
  8279. //
  8280. // Same Property Ids and semantics as CertGetCertificateContextProperty.
  8281. //
  8282. // CERT_SHA1_HASH_PROP_ID, CERT_MD5_HASH_PROP_ID or
  8283. // CERT_SIGNATURE_HASH_PROP_ID is the predefined property of most interest.
  8284. //--------------------------------------------------------------------------
  8285. WINCRYPT32API
  8286. BOOL
  8287. WINAPI
  8288. CertGetCRLContextProperty(
  8289. IN PCCRL_CONTEXT pCrlContext,
  8290. IN DWORD dwPropId,
  8291. OUT void *pvData,
  8292. IN OUT DWORD *pcbData
  8293. );
  8294. //+-------------------------------------------------------------------------
  8295. // Enumerate the properties for the specified CRL context.
  8296. //
  8297. // To get the first property, set dwPropId to 0. The ID of the first
  8298. // property is returned. To get the next property, set dwPropId to the
  8299. // ID returned by the last call. To enumerate all the properties continue
  8300. // until 0 is returned.
  8301. //
  8302. // CertGetCRLContextProperty is called to get the property's data.
  8303. //--------------------------------------------------------------------------
  8304. WINCRYPT32API
  8305. DWORD
  8306. WINAPI
  8307. CertEnumCRLContextProperties(
  8308. IN PCCRL_CONTEXT pCrlContext,
  8309. IN DWORD dwPropId
  8310. );
  8311. //+-------------------------------------------------------------------------
  8312. // Search the CRL's list of entries for the specified certificate.
  8313. //
  8314. // TRUE is returned if we were able to search the list. Otherwise, FALSE is
  8315. // returned,
  8316. //
  8317. // For success, if the certificate was found in the list, *ppCrlEntry is
  8318. // updated with a pointer to the entry. Otherwise, *ppCrlEntry is set to NULL.
  8319. // The returned entry isn't allocated and must not be freed.
  8320. //
  8321. // dwFlags and pvReserved currently aren't used and must be set to 0 or NULL.
  8322. //--------------------------------------------------------------------------
  8323. WINCRYPT32API
  8324. BOOL
  8325. WINAPI
  8326. CertFindCertificateInCRL(
  8327. IN PCCERT_CONTEXT pCert,
  8328. IN PCCRL_CONTEXT pCrlContext,
  8329. IN DWORD dwFlags,
  8330. IN OPTIONAL void *pvReserved,
  8331. OUT PCRL_ENTRY *ppCrlEntry
  8332. );
  8333. //+-------------------------------------------------------------------------
  8334. // Is the specified CRL valid for the certificate.
  8335. //
  8336. // Returns TRUE if the CRL's list of entries would contain the certificate
  8337. // if it was revoked. Note, doesn't check that the certificate is in the
  8338. // list of entries.
  8339. //
  8340. // If the CRL has an Issuing Distribution Point (IDP) extension, checks
  8341. // that it's valid for the subject certificate.
  8342. //
  8343. // dwFlags and pvReserved currently aren't used and must be set to 0 and NULL.
  8344. //--------------------------------------------------------------------------
  8345. WINCRYPT32API
  8346. BOOL
  8347. WINAPI
  8348. CertIsValidCRLForCertificate(
  8349. IN PCCERT_CONTEXT pCert,
  8350. IN PCCRL_CONTEXT pCrl,
  8351. IN DWORD dwFlags,
  8352. IN void *pvReserved
  8353. );
  8354. //+-------------------------------------------------------------------------
  8355. // Add certificate/CRL, encoded, context or element disposition values.
  8356. //--------------------------------------------------------------------------
  8357. #define CERT_STORE_ADD_NEW 1
  8358. #define CERT_STORE_ADD_USE_EXISTING 2
  8359. #define CERT_STORE_ADD_REPLACE_EXISTING 3
  8360. #define CERT_STORE_ADD_ALWAYS 4
  8361. #define CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES 5
  8362. #define CERT_STORE_ADD_NEWER 6
  8363. #define CERT_STORE_ADD_NEWER_INHERIT_PROPERTIES 7
  8364. //+-------------------------------------------------------------------------
  8365. // Add the encoded certificate to the store according to the specified
  8366. // disposition action.
  8367. //
  8368. // Makes a copy of the encoded certificate before adding to the store.
  8369. //
  8370. // dwAddDispostion specifies the action to take if the certificate
  8371. // already exists in the store. This parameter must be one of the following
  8372. // values:
  8373. // CERT_STORE_ADD_NEW
  8374. // Fails if the certificate already exists in the store. LastError
  8375. // is set to CRYPT_E_EXISTS.
  8376. // CERT_STORE_ADD_USE_EXISTING
  8377. // If the certifcate already exists, then, its used and if ppCertContext
  8378. // is non-NULL, the existing context is duplicated.
  8379. // CERT_STORE_ADD_REPLACE_EXISTING
  8380. // If the certificate already exists, then, the existing certificate
  8381. // context is deleted before creating and adding the new context.
  8382. // CERT_STORE_ADD_ALWAYS
  8383. // No check is made to see if the certificate already exists. A
  8384. // new certificate context is always created. This may lead to
  8385. // duplicates in the store.
  8386. // CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES
  8387. // If the certificate already exists, then, its used.
  8388. // CERT_STORE_ADD_NEWER
  8389. // Fails if the certificate already exists in the store AND the NotBefore
  8390. // time of the existing certificate is equal to or greater than the
  8391. // NotBefore time of the new certificate being added. LastError
  8392. // is set to CRYPT_E_EXISTS.
  8393. //
  8394. // If an older certificate is replaced, same as
  8395. // CERT_STORE_ADD_REPLACE_EXISTING.
  8396. //
  8397. // For CRLs or CTLs compares the ThisUpdate times.
  8398. //
  8399. // CERT_STORE_ADD_NEWER_INHERIT_PROPERTIES
  8400. // Same as CERT_STORE_ADD_NEWER. However, if an older certificate is
  8401. // replaced, same as CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES.
  8402. //
  8403. // CertGetSubjectCertificateFromStore is called to determine if the
  8404. // certificate already exists in the store.
  8405. //
  8406. // ppCertContext can be NULL, indicating the caller isn't interested
  8407. // in getting the CERT_CONTEXT of the added or existing certificate.
  8408. //--------------------------------------------------------------------------
  8409. WINCRYPT32API
  8410. BOOL
  8411. WINAPI
  8412. CertAddEncodedCertificateToStore(
  8413. IN HCERTSTORE hCertStore,
  8414. IN DWORD dwCertEncodingType,
  8415. IN const BYTE *pbCertEncoded,
  8416. IN DWORD cbCertEncoded,
  8417. IN DWORD dwAddDisposition,
  8418. OUT OPTIONAL PCCERT_CONTEXT *ppCertContext
  8419. );
  8420. //+-------------------------------------------------------------------------
  8421. // Add the certificate context to the store according to the specified
  8422. // disposition action.
  8423. //
  8424. // In addition to the encoded certificate, the context's properties are
  8425. // also copied. Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  8426. // CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't copied.
  8427. //
  8428. // Makes a copy of the certificate context before adding to the store.
  8429. //
  8430. // dwAddDispostion specifies the action to take if the certificate
  8431. // already exists in the store. This parameter must be one of the following
  8432. // values:
  8433. // CERT_STORE_ADD_NEW
  8434. // Fails if the certificate already exists in the store. LastError
  8435. // is set to CRYPT_E_EXISTS.
  8436. // CERT_STORE_ADD_USE_EXISTING
  8437. // If the certifcate already exists, then, its used and if ppStoreContext
  8438. // is non-NULL, the existing context is duplicated. Iterates
  8439. // through pCertContext's properties and only copies the properties
  8440. // that don't already exist. The SHA1 and MD5 hash properties aren't
  8441. // copied.
  8442. // CERT_STORE_ADD_REPLACE_EXISTING
  8443. // If the certificate already exists, then, the existing certificate
  8444. // context is deleted before creating and adding a new context.
  8445. // Properties are copied before doing the add.
  8446. // CERT_STORE_ADD_ALWAYS
  8447. // No check is made to see if the certificate already exists. A
  8448. // new certificate context is always created and added. This may lead to
  8449. // duplicates in the store. Properties are
  8450. // copied before doing the add.
  8451. // CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES
  8452. // If the certificate already exists, then, the existing certificate
  8453. // context is used. Properties from the added context are copied and
  8454. // replace existing properties. However, any existing properties not
  8455. // in the added context remain and aren't deleted.
  8456. // CERT_STORE_ADD_NEWER
  8457. // Fails if the certificate already exists in the store AND the NotBefore
  8458. // time of the existing context is equal to or greater than the
  8459. // NotBefore time of the new context being added. LastError
  8460. // is set to CRYPT_E_EXISTS.
  8461. //
  8462. // If an older context is replaced, same as
  8463. // CERT_STORE_ADD_REPLACE_EXISTING.
  8464. //
  8465. // For CRLs or CTLs compares the ThisUpdate times.
  8466. //
  8467. // CERT_STORE_ADD_NEWER_INHERIT_PROPERTIES
  8468. // Same as CERT_STORE_ADD_NEWER. However, if an older context is
  8469. // replaced, same as CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES.
  8470. //
  8471. // CertGetSubjectCertificateFromStore is called to determine if the
  8472. // certificate already exists in the store.
  8473. //
  8474. // ppStoreContext can be NULL, indicating the caller isn't interested
  8475. // in getting the CERT_CONTEXT of the added or existing certificate.
  8476. //--------------------------------------------------------------------------
  8477. WINCRYPT32API
  8478. BOOL
  8479. WINAPI
  8480. CertAddCertificateContextToStore(
  8481. IN HCERTSTORE hCertStore,
  8482. IN PCCERT_CONTEXT pCertContext,
  8483. IN DWORD dwAddDisposition,
  8484. OUT OPTIONAL PCCERT_CONTEXT *ppStoreContext
  8485. );
  8486. //+-------------------------------------------------------------------------
  8487. // Certificate Store Context Types
  8488. //--------------------------------------------------------------------------
  8489. #define CERT_STORE_CERTIFICATE_CONTEXT 1
  8490. #define CERT_STORE_CRL_CONTEXT 2
  8491. #define CERT_STORE_CTL_CONTEXT 3
  8492. //+-------------------------------------------------------------------------
  8493. // Certificate Store Context Bit Flags
  8494. //--------------------------------------------------------------------------
  8495. #define CERT_STORE_ALL_CONTEXT_FLAG (~0UL)
  8496. #define CERT_STORE_CERTIFICATE_CONTEXT_FLAG \
  8497. (1 << CERT_STORE_CERTIFICATE_CONTEXT)
  8498. #define CERT_STORE_CRL_CONTEXT_FLAG \
  8499. (1 << CERT_STORE_CRL_CONTEXT)
  8500. #define CERT_STORE_CTL_CONTEXT_FLAG \
  8501. (1 << CERT_STORE_CTL_CONTEXT)
  8502. //+-------------------------------------------------------------------------
  8503. // Add the serialized certificate or CRL element to the store.
  8504. //
  8505. // The serialized element contains the encoded certificate, CRL or CTL and
  8506. // its properties, such as, CERT_KEY_PROV_INFO_PROP_ID.
  8507. //
  8508. // If hCertStore is NULL, creates a certificate, CRL or CTL context not
  8509. // residing in any store.
  8510. //
  8511. // dwAddDispostion specifies the action to take if the certificate or CRL
  8512. // already exists in the store. See CertAddCertificateContextToStore for a
  8513. // list of and actions taken.
  8514. //
  8515. // dwFlags currently isn't used and should be set to 0.
  8516. //
  8517. // dwContextTypeFlags specifies the set of allowable contexts. For example, to
  8518. // add either a certificate or CRL, set dwContextTypeFlags to:
  8519. // CERT_STORE_CERTIFICATE_CONTEXT_FLAG | CERT_STORE_CRL_CONTEXT_FLAG
  8520. //
  8521. // *pdwContextType is updated with the type of the context returned in
  8522. // *ppvContxt. pdwContextType or ppvContext can be NULL, indicating the
  8523. // caller isn't interested in getting the output. If *ppvContext is
  8524. // returned it must be freed by calling CertFreeCertificateContext or
  8525. // CertFreeCRLContext.
  8526. //--------------------------------------------------------------------------
  8527. WINCRYPT32API
  8528. BOOL
  8529. WINAPI
  8530. CertAddSerializedElementToStore(
  8531. IN HCERTSTORE hCertStore,
  8532. IN const BYTE *pbElement,
  8533. IN DWORD cbElement,
  8534. IN DWORD dwAddDisposition,
  8535. IN DWORD dwFlags,
  8536. IN DWORD dwContextTypeFlags,
  8537. OUT OPTIONAL DWORD *pdwContextType,
  8538. OUT OPTIONAL const void **ppvContext
  8539. );
  8540. //+-------------------------------------------------------------------------
  8541. // Delete the specified certificate from the store.
  8542. //
  8543. // All subsequent gets or finds for the certificate will fail. However,
  8544. // memory allocated for the certificate isn't freed until all of its contexts
  8545. // have also been freed.
  8546. //
  8547. // The pCertContext is obtained from a get, enum, find or duplicate.
  8548. //
  8549. // Some store provider implementations might also delete the issuer's CRLs
  8550. // if this is the last certificate for the issuer in the store.
  8551. //
  8552. // NOTE: the pCertContext is always CertFreeCertificateContext'ed by
  8553. // this function, even for an error.
  8554. //--------------------------------------------------------------------------
  8555. WINCRYPT32API
  8556. BOOL
  8557. WINAPI
  8558. CertDeleteCertificateFromStore(
  8559. IN PCCERT_CONTEXT pCertContext
  8560. );
  8561. //+-------------------------------------------------------------------------
  8562. // Add the encoded CRL to the store according to the specified
  8563. // disposition option.
  8564. //
  8565. // Makes a copy of the encoded CRL before adding to the store.
  8566. //
  8567. // dwAddDispostion specifies the action to take if the CRL
  8568. // already exists in the store. See CertAddEncodedCertificateToStore for a
  8569. // list of and actions taken.
  8570. //
  8571. // Compares the CRL's Issuer to determine if the CRL already exists in the
  8572. // store.
  8573. //
  8574. // ppCrlContext can be NULL, indicating the caller isn't interested
  8575. // in getting the CRL_CONTEXT of the added or existing CRL.
  8576. //--------------------------------------------------------------------------
  8577. WINCRYPT32API
  8578. BOOL
  8579. WINAPI
  8580. CertAddEncodedCRLToStore(
  8581. IN HCERTSTORE hCertStore,
  8582. IN DWORD dwCertEncodingType,
  8583. IN const BYTE *pbCrlEncoded,
  8584. IN DWORD cbCrlEncoded,
  8585. IN DWORD dwAddDisposition,
  8586. OUT OPTIONAL PCCRL_CONTEXT *ppCrlContext
  8587. );
  8588. //+-------------------------------------------------------------------------
  8589. // Add the CRL context to the store according to the specified
  8590. // disposition option.
  8591. //
  8592. // In addition to the encoded CRL, the context's properties are
  8593. // also copied. Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  8594. // CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't copied.
  8595. //
  8596. // Makes a copy of the encoded CRL before adding to the store.
  8597. //
  8598. // dwAddDispostion specifies the action to take if the CRL
  8599. // already exists in the store. See CertAddCertificateContextToStore for a
  8600. // list of and actions taken.
  8601. //
  8602. // Compares the CRL's Issuer, ThisUpdate and NextUpdate to determine
  8603. // if the CRL already exists in the store.
  8604. //
  8605. // ppStoreContext can be NULL, indicating the caller isn't interested
  8606. // in getting the CRL_CONTEXT of the added or existing CRL.
  8607. //--------------------------------------------------------------------------
  8608. WINCRYPT32API
  8609. BOOL
  8610. WINAPI
  8611. CertAddCRLContextToStore(
  8612. IN HCERTSTORE hCertStore,
  8613. IN PCCRL_CONTEXT pCrlContext,
  8614. IN DWORD dwAddDisposition,
  8615. OUT OPTIONAL PCCRL_CONTEXT *ppStoreContext
  8616. );
  8617. //+-------------------------------------------------------------------------
  8618. // Delete the specified CRL from the store.
  8619. //
  8620. // All subsequent gets for the CRL will fail. However,
  8621. // memory allocated for the CRL isn't freed until all of its contexts
  8622. // have also been freed.
  8623. //
  8624. // The pCrlContext is obtained from a get or duplicate.
  8625. //
  8626. // NOTE: the pCrlContext is always CertFreeCRLContext'ed by
  8627. // this function, even for an error.
  8628. //--------------------------------------------------------------------------
  8629. WINCRYPT32API
  8630. BOOL
  8631. WINAPI
  8632. CertDeleteCRLFromStore(
  8633. IN PCCRL_CONTEXT pCrlContext
  8634. );
  8635. //+-------------------------------------------------------------------------
  8636. // Serialize the certificate context's encoded certificate and its
  8637. // properties.
  8638. //--------------------------------------------------------------------------
  8639. WINCRYPT32API
  8640. BOOL
  8641. WINAPI
  8642. CertSerializeCertificateStoreElement(
  8643. IN PCCERT_CONTEXT pCertContext,
  8644. IN DWORD dwFlags,
  8645. OUT BYTE *pbElement,
  8646. IN OUT DWORD *pcbElement
  8647. );
  8648. //+-------------------------------------------------------------------------
  8649. // Serialize the CRL context's encoded CRL and its properties.
  8650. //--------------------------------------------------------------------------
  8651. WINCRYPT32API
  8652. BOOL
  8653. WINAPI
  8654. CertSerializeCRLStoreElement(
  8655. IN PCCRL_CONTEXT pCrlContext,
  8656. IN DWORD dwFlags,
  8657. OUT BYTE *pbElement,
  8658. IN OUT DWORD *pcbElement
  8659. );
  8660. //+=========================================================================
  8661. // Certificate Trust List (CTL) Store Data Structures and APIs
  8662. //==========================================================================
  8663. //+-------------------------------------------------------------------------
  8664. // Duplicate a CTL context
  8665. //--------------------------------------------------------------------------
  8666. WINCRYPT32API
  8667. PCCTL_CONTEXT
  8668. WINAPI
  8669. CertDuplicateCTLContext(
  8670. IN PCCTL_CONTEXT pCtlContext
  8671. );
  8672. //+-------------------------------------------------------------------------
  8673. // Create a CTL context from the encoded CTL. The created
  8674. // context isn't put in a store.
  8675. //
  8676. // Makes a copy of the encoded CTL in the created context.
  8677. //
  8678. // If unable to decode and create the CTL context, NULL is returned.
  8679. // Otherwise, a pointer to a read only CTL_CONTEXT is returned.
  8680. // CTL_CONTEXT must be freed by calling CertFreeCTLContext.
  8681. // CertDuplicateCTLContext can be called to make a duplicate.
  8682. //
  8683. // CertSetCTLContextProperty and CertGetCTLContextProperty can be called
  8684. // to store properties for the CTL.
  8685. //--------------------------------------------------------------------------
  8686. WINCRYPT32API
  8687. PCCTL_CONTEXT
  8688. WINAPI
  8689. CertCreateCTLContext(
  8690. IN DWORD dwMsgAndCertEncodingType,
  8691. IN const BYTE *pbCtlEncoded,
  8692. IN DWORD cbCtlEncoded
  8693. );
  8694. //+-------------------------------------------------------------------------
  8695. // Free a CTL context
  8696. //
  8697. // There needs to be a corresponding free for each context obtained by a
  8698. // get, duplicate or create.
  8699. //--------------------------------------------------------------------------
  8700. WINCRYPT32API
  8701. BOOL
  8702. WINAPI
  8703. CertFreeCTLContext(
  8704. IN PCCTL_CONTEXT pCtlContext
  8705. );
  8706. //+-------------------------------------------------------------------------
  8707. // Set the property for the specified CTL context.
  8708. //
  8709. // Same Property Ids and semantics as CertSetCertificateContextProperty.
  8710. //--------------------------------------------------------------------------
  8711. WINCRYPT32API
  8712. BOOL
  8713. WINAPI
  8714. CertSetCTLContextProperty(
  8715. IN PCCTL_CONTEXT pCtlContext,
  8716. IN DWORD dwPropId,
  8717. IN DWORD dwFlags,
  8718. IN const void *pvData
  8719. );
  8720. //+-------------------------------------------------------------------------
  8721. // Get the property for the specified CTL context.
  8722. //
  8723. // Same Property Ids and semantics as CertGetCertificateContextProperty.
  8724. //
  8725. // CERT_SHA1_HASH_PROP_ID or CERT_NEXT_UPDATE_LOCATION_PROP_ID are the
  8726. // predefined properties of most interest.
  8727. //--------------------------------------------------------------------------
  8728. WINCRYPT32API
  8729. BOOL
  8730. WINAPI
  8731. CertGetCTLContextProperty(
  8732. IN PCCTL_CONTEXT pCtlContext,
  8733. IN DWORD dwPropId,
  8734. OUT void *pvData,
  8735. IN OUT DWORD *pcbData
  8736. );
  8737. //+-------------------------------------------------------------------------
  8738. // Enumerate the properties for the specified CTL context.
  8739. //--------------------------------------------------------------------------
  8740. WINCRYPT32API
  8741. DWORD
  8742. WINAPI
  8743. CertEnumCTLContextProperties(
  8744. IN PCCTL_CONTEXT pCtlContext,
  8745. IN DWORD dwPropId
  8746. );
  8747. //+-------------------------------------------------------------------------
  8748. // Enumerate the CTL contexts in the store.
  8749. //
  8750. // If a CTL isn't found, NULL is returned.
  8751. // Otherwise, a pointer to a read only CTL_CONTEXT is returned. CTL_CONTEXT
  8752. // must be freed by calling CertFreeCTLContext or is freed when passed as the
  8753. // pPrevCtlContext on a subsequent call. CertDuplicateCTLContext
  8754. // can be called to make a duplicate.
  8755. //
  8756. // pPrevCtlContext MUST BE NULL to enumerate the first
  8757. // CTL in the store. Successive CTLs are enumerated by setting
  8758. // pPrevCtlContext to the CTL_CONTEXT returned by a previous call.
  8759. //
  8760. // NOTE: a NON-NULL pPrevCtlContext is always CertFreeCTLContext'ed by
  8761. // this function, even for an error.
  8762. //--------------------------------------------------------------------------
  8763. WINCRYPT32API
  8764. PCCTL_CONTEXT
  8765. WINAPI
  8766. CertEnumCTLsInStore(
  8767. IN HCERTSTORE hCertStore,
  8768. IN PCCTL_CONTEXT pPrevCtlContext
  8769. );
  8770. //+-------------------------------------------------------------------------
  8771. // Attempt to find the specified subject in the CTL.
  8772. //
  8773. // For CTL_CERT_SUBJECT_TYPE, pvSubject points to a CERT_CONTEXT. The CTL's
  8774. // SubjectAlgorithm is examined to determine the representation of the
  8775. // subject's identity. Initially, only SHA1 or MD5 hash will be supported.
  8776. // The appropriate hash property is obtained from the CERT_CONTEXT.
  8777. //
  8778. // For CTL_ANY_SUBJECT_TYPE, pvSubject points to the CTL_ANY_SUBJECT_INFO
  8779. // structure which contains the SubjectAlgorithm to be matched in the CTL
  8780. // and the SubjectIdentifer to be matched in one of the CTL entries.
  8781. //
  8782. // The certificate's hash or the CTL_ANY_SUBJECT_INFO's SubjectIdentifier
  8783. // is used as the key in searching the subject entries. A binary
  8784. // memory comparison is done between the key and the entry's SubjectIdentifer.
  8785. //
  8786. // dwEncodingType isn't used for either of the above SubjectTypes.
  8787. //--------------------------------------------------------------------------
  8788. WINCRYPT32API
  8789. PCTL_ENTRY
  8790. WINAPI
  8791. CertFindSubjectInCTL(
  8792. IN DWORD dwEncodingType,
  8793. IN DWORD dwSubjectType,
  8794. IN void *pvSubject,
  8795. IN PCCTL_CONTEXT pCtlContext,
  8796. IN DWORD dwFlags
  8797. );
  8798. // Subject Types:
  8799. // CTL_ANY_SUBJECT_TYPE, pvSubject points to following CTL_ANY_SUBJECT_INFO.
  8800. // CTL_CERT_SUBJECT_TYPE, pvSubject points to CERT_CONTEXT.
  8801. #define CTL_ANY_SUBJECT_TYPE 1
  8802. #define CTL_CERT_SUBJECT_TYPE 2
  8803. typedef struct _CTL_ANY_SUBJECT_INFO {
  8804. CRYPT_ALGORITHM_IDENTIFIER SubjectAlgorithm;
  8805. CRYPT_DATA_BLOB SubjectIdentifier;
  8806. } CTL_ANY_SUBJECT_INFO, *PCTL_ANY_SUBJECT_INFO;
  8807. //+-------------------------------------------------------------------------
  8808. // Find the first or next CTL context in the store.
  8809. //
  8810. // The CTL is found according to the dwFindType and its pvFindPara.
  8811. // See below for a list of the find types and its parameters.
  8812. //
  8813. // Currently dwFindFlags isn't used and must be set to 0.
  8814. //
  8815. // Usage of dwMsgAndCertEncodingType depends on the dwFindType.
  8816. //
  8817. // If the first or next CTL isn't found, NULL is returned.
  8818. // Otherwise, a pointer to a read only CTL_CONTEXT is returned. CTL_CONTEXT
  8819. // must be freed by calling CertFreeCTLContext or is freed when passed as the
  8820. // pPrevCtlContext on a subsequent call. CertDuplicateCTLContext
  8821. // can be called to make a duplicate.
  8822. //
  8823. // pPrevCtlContext MUST BE NULL on the first
  8824. // call to find the CTL. To find the next CTL, the
  8825. // pPrevCtlContext is set to the CTL_CONTEXT returned by a previous call.
  8826. //
  8827. // NOTE: a NON-NULL pPrevCtlContext is always CertFreeCTLContext'ed by
  8828. // this function, even for an error.
  8829. //--------------------------------------------------------------------------
  8830. WINCRYPT32API
  8831. PCCTL_CONTEXT
  8832. WINAPI
  8833. CertFindCTLInStore(
  8834. IN HCERTSTORE hCertStore,
  8835. IN DWORD dwMsgAndCertEncodingType,
  8836. IN DWORD dwFindFlags,
  8837. IN DWORD dwFindType,
  8838. IN const void *pvFindPara,
  8839. IN PCCTL_CONTEXT pPrevCtlContext
  8840. );
  8841. #define CTL_FIND_ANY 0
  8842. #define CTL_FIND_SHA1_HASH 1
  8843. #define CTL_FIND_MD5_HASH 2
  8844. #define CTL_FIND_USAGE 3
  8845. #define CTL_FIND_SUBJECT 4
  8846. #define CTL_FIND_EXISTING 5
  8847. typedef struct _CTL_FIND_USAGE_PARA {
  8848. DWORD cbSize;
  8849. CTL_USAGE SubjectUsage; // optional
  8850. CRYPT_DATA_BLOB ListIdentifier; // optional
  8851. PCERT_INFO pSigner; // optional
  8852. } CTL_FIND_USAGE_PARA, *PCTL_FIND_USAGE_PARA;
  8853. #define CTL_FIND_NO_LIST_ID_CBDATA 0xFFFFFFFF
  8854. #define CTL_FIND_NO_SIGNER_PTR ((PCERT_INFO) -1)
  8855. #define CTL_FIND_SAME_USAGE_FLAG 0x1
  8856. typedef struct _CTL_FIND_SUBJECT_PARA {
  8857. DWORD cbSize;
  8858. PCTL_FIND_USAGE_PARA pUsagePara; // optional
  8859. DWORD dwSubjectType;
  8860. void *pvSubject;
  8861. } CTL_FIND_SUBJECT_PARA, *PCTL_FIND_SUBJECT_PARA;
  8862. //+-------------------------------------------------------------------------
  8863. // CTL_FIND_ANY
  8864. //
  8865. // Find any CTL.
  8866. //
  8867. // pvFindPara isn't used.
  8868. //--------------------------------------------------------------------------
  8869. //+-------------------------------------------------------------------------
  8870. // CTL_FIND_SHA1_HASH
  8871. // CTL_FIND_MD5_HASH
  8872. //
  8873. // Find a CTL with the specified hash.
  8874. //
  8875. // pvFindPara points to a CRYPT_HASH_BLOB.
  8876. //--------------------------------------------------------------------------
  8877. //+-------------------------------------------------------------------------
  8878. // CTL_FIND_USAGE
  8879. //
  8880. // Find a CTL having the specified usage identifiers, list identifier or
  8881. // signer. The CertEncodingType of the signer is obtained from the
  8882. // dwMsgAndCertEncodingType parameter.
  8883. //
  8884. // pvFindPara points to a CTL_FIND_USAGE_PARA data structure. The
  8885. // SubjectUsage.cUsageIdentifer can be 0 to match any usage. The
  8886. // ListIdentifier.cbData can be 0 to match any list identifier. To only match
  8887. // CTLs without a ListIdentifier, cbData must be set to
  8888. // CTL_FIND_NO_LIST_ID_CBDATA. pSigner can be NULL to match any signer. Only
  8889. // the Issuer and SerialNumber fields of the pSigner's PCERT_INFO are used.
  8890. // To only match CTLs without a signer, pSigner must be set to
  8891. // CTL_FIND_NO_SIGNER_PTR.
  8892. //
  8893. // The CTL_FIND_SAME_USAGE_FLAG can be set in dwFindFlags to
  8894. // only match CTLs with the same usage identifiers. CTLs having additional
  8895. // usage identifiers aren't matched. For example, if only "1.2.3" is specified
  8896. // in CTL_FIND_USAGE_PARA, then, for a match, the CTL must only contain
  8897. // "1.2.3" and not any additional usage identifers.
  8898. //--------------------------------------------------------------------------
  8899. //+-------------------------------------------------------------------------
  8900. // CTL_FIND_SUBJECT
  8901. //
  8902. // Find a CTL having the specified subject. CertFindSubjectInCTL can be
  8903. // called to get a pointer to the subject's entry in the CTL. pUsagePara can
  8904. // optionally be set to enable the above CTL_FIND_USAGE matching.
  8905. //
  8906. // pvFindPara points to a CTL_FIND_SUBJECT_PARA data structure.
  8907. //--------------------------------------------------------------------------
  8908. //+-------------------------------------------------------------------------
  8909. // Add the encoded CTL to the store according to the specified
  8910. // disposition option.
  8911. //
  8912. // Makes a copy of the encoded CTL before adding to the store.
  8913. //
  8914. // dwAddDispostion specifies the action to take if the CTL
  8915. // already exists in the store. See CertAddEncodedCertificateToStore for a
  8916. // list of and actions taken.
  8917. //
  8918. // Compares the CTL's SubjectUsage, ListIdentifier and any of its signers
  8919. // to determine if the CTL already exists in the store.
  8920. //
  8921. // ppCtlContext can be NULL, indicating the caller isn't interested
  8922. // in getting the CTL_CONTEXT of the added or existing CTL.
  8923. //--------------------------------------------------------------------------
  8924. WINCRYPT32API
  8925. BOOL
  8926. WINAPI
  8927. CertAddEncodedCTLToStore(
  8928. IN HCERTSTORE hCertStore,
  8929. IN DWORD dwMsgAndCertEncodingType,
  8930. IN const BYTE *pbCtlEncoded,
  8931. IN DWORD cbCtlEncoded,
  8932. IN DWORD dwAddDisposition,
  8933. OUT OPTIONAL PCCTL_CONTEXT *ppCtlContext
  8934. );
  8935. //+-------------------------------------------------------------------------
  8936. // Add the CTL context to the store according to the specified
  8937. // disposition option.
  8938. //
  8939. // In addition to the encoded CTL, the context's properties are
  8940. // also copied. Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  8941. // CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't copied.
  8942. //
  8943. // Makes a copy of the encoded CTL before adding to the store.
  8944. //
  8945. // dwAddDispostion specifies the action to take if the CTL
  8946. // already exists in the store. See CertAddCertificateContextToStore for a
  8947. // list of and actions taken.
  8948. //
  8949. // Compares the CTL's SubjectUsage, ListIdentifier and any of its signers
  8950. // to determine if the CTL already exists in the store.
  8951. //
  8952. // ppStoreContext can be NULL, indicating the caller isn't interested
  8953. // in getting the CTL_CONTEXT of the added or existing CTL.
  8954. //--------------------------------------------------------------------------
  8955. WINCRYPT32API
  8956. BOOL
  8957. WINAPI
  8958. CertAddCTLContextToStore(
  8959. IN HCERTSTORE hCertStore,
  8960. IN PCCTL_CONTEXT pCtlContext,
  8961. IN DWORD dwAddDisposition,
  8962. OUT OPTIONAL PCCTL_CONTEXT *ppStoreContext
  8963. );
  8964. //+-------------------------------------------------------------------------
  8965. // Serialize the CTL context's encoded CTL and its properties.
  8966. //--------------------------------------------------------------------------
  8967. WINCRYPT32API
  8968. BOOL
  8969. WINAPI
  8970. CertSerializeCTLStoreElement(
  8971. IN PCCTL_CONTEXT pCtlContext,
  8972. IN DWORD dwFlags,
  8973. OUT BYTE *pbElement,
  8974. IN OUT DWORD *pcbElement
  8975. );
  8976. //+-------------------------------------------------------------------------
  8977. // Delete the specified CTL from the store.
  8978. //
  8979. // All subsequent gets for the CTL will fail. However,
  8980. // memory allocated for the CTL isn't freed until all of its contexts
  8981. // have also been freed.
  8982. //
  8983. // The pCtlContext is obtained from a get or duplicate.
  8984. //
  8985. // NOTE: the pCtlContext is always CertFreeCTLContext'ed by
  8986. // this function, even for an error.
  8987. //--------------------------------------------------------------------------
  8988. WINCRYPT32API
  8989. BOOL
  8990. WINAPI
  8991. CertDeleteCTLFromStore(
  8992. IN PCCTL_CONTEXT pCtlContext
  8993. );
  8994. WINCRYPT32API
  8995. BOOL
  8996. WINAPI
  8997. CertAddCertificateLinkToStore(
  8998. IN HCERTSTORE hCertStore,
  8999. IN PCCERT_CONTEXT pCertContext,
  9000. IN DWORD dwAddDisposition,
  9001. OUT OPTIONAL PCCERT_CONTEXT *ppStoreContext
  9002. );
  9003. WINCRYPT32API
  9004. BOOL
  9005. WINAPI
  9006. CertAddCRLLinkToStore(
  9007. IN HCERTSTORE hCertStore,
  9008. IN PCCRL_CONTEXT pCrlContext,
  9009. IN DWORD dwAddDisposition,
  9010. OUT OPTIONAL PCCRL_CONTEXT *ppStoreContext
  9011. );
  9012. WINCRYPT32API
  9013. BOOL
  9014. WINAPI
  9015. CertAddCTLLinkToStore(
  9016. IN HCERTSTORE hCertStore,
  9017. IN PCCTL_CONTEXT pCtlContext,
  9018. IN DWORD dwAddDisposition,
  9019. OUT OPTIONAL PCCTL_CONTEXT *ppStoreContext
  9020. );
  9021. WINCRYPT32API
  9022. BOOL
  9023. WINAPI
  9024. CertAddStoreToCollection(
  9025. IN HCERTSTORE hCollectionStore,
  9026. IN OPTIONAL HCERTSTORE hSiblingStore,
  9027. IN DWORD dwUpdateFlags,
  9028. IN DWORD dwPriority
  9029. );
  9030. WINCRYPT32API
  9031. void
  9032. WINAPI
  9033. CertRemoveStoreFromCollection(
  9034. IN HCERTSTORE hCollectionStore,
  9035. IN HCERTSTORE hSiblingStore
  9036. );
  9037. WINCRYPT32API
  9038. BOOL
  9039. WINAPI
  9040. CertControlStore(
  9041. IN HCERTSTORE hCertStore,
  9042. IN DWORD dwFlags,
  9043. IN DWORD dwCtrlType,
  9044. IN void const *pvCtrlPara
  9045. );
  9046. //+-------------------------------------------------------------------------
  9047. // Certificate Store control types
  9048. //--------------------------------------------------------------------------
  9049. #define CERT_STORE_CTRL_RESYNC 1
  9050. #define CERT_STORE_CTRL_NOTIFY_CHANGE 2
  9051. #define CERT_STORE_CTRL_COMMIT 3
  9052. #define CERT_STORE_CTRL_AUTO_RESYNC 4
  9053. #define CERT_STORE_CTRL_CANCEL_NOTIFY 5
  9054. #define CERT_STORE_CTRL_INHIBIT_DUPLICATE_HANDLE_FLAG 0x1
  9055. //+-------------------------------------------------------------------------
  9056. // CERT_STORE_CTRL_RESYNC
  9057. //
  9058. // Re-synchronize the store.
  9059. //
  9060. // The pvCtrlPara points to the event HANDLE to be signaled on
  9061. // the next store change. Normally, this would be the same
  9062. // event HANDLE passed to CERT_STORE_CTRL_NOTIFY_CHANGE during initialization.
  9063. //
  9064. // If pvCtrlPara is NULL, no events are re-armed.
  9065. //
  9066. // By default the event HANDLE is DuplicateHandle'd.
  9067. // CERT_STORE_CTRL_INHIBIT_DUPLICATE_HANDLE_FLAG can be set in dwFlags
  9068. // to inhibit a DupicateHandle of the event HANDLE. If this flag
  9069. // is set, then, CertControlStore(CERT_STORE_CTRL_CANCEL_NOTIFY) must be
  9070. // called for this event HANDLE before closing the hCertStore.
  9071. //--------------------------------------------------------------------------
  9072. //+-------------------------------------------------------------------------
  9073. // CERT_STORE_CTRL_NOTIFY_CHANGE
  9074. //
  9075. // Signal the event when the underlying store is changed.
  9076. //
  9077. // pvCtrlPara points to the event HANDLE to be signaled.
  9078. //
  9079. // pvCtrlPara can be NULL to inform the store of a subsequent
  9080. // CERT_STORE_CTRL_RESYNC and allow it to optimize by only doing a resync
  9081. // if the store has changed. For the registry based stores, an internal
  9082. // notify change event is created and registered to be signaled.
  9083. //
  9084. // Recommend calling CERT_STORE_CTRL_NOTIFY_CHANGE once for each event to
  9085. // be passed to CERT_STORE_CTRL_RESYNC. This should only happen after
  9086. // the event has been created. Not after each time the event is signaled.
  9087. //
  9088. // By default the event HANDLE is DuplicateHandle'd.
  9089. // CERT_STORE_CTRL_INHIBIT_DUPLICATE_HANDLE_FLAG can be set in dwFlags
  9090. // to inhibit a DupicateHandle of the event HANDLE. If this flag
  9091. // is set, then, CertControlStore(CERT_STORE_CTRL_CANCEL_NOTIFY) must be
  9092. // called for this event HANDLE before closing the hCertStore.
  9093. //--------------------------------------------------------------------------
  9094. //+-------------------------------------------------------------------------
  9095. // CERT_STORE_CTRL_CANCEL_NOTIFY
  9096. //
  9097. // Cancel notification signaling of the event HANDLE passed in a previous
  9098. // CERT_STORE_CTRL_NOTIFY_CHANGE or CERT_STORE_CTRL_RESYNC.
  9099. //
  9100. // pvCtrlPara points to the event HANDLE to be canceled.
  9101. //--------------------------------------------------------------------------
  9102. //+-------------------------------------------------------------------------
  9103. // CERT_STORE_CTRL_AUTO_RESYNC
  9104. //
  9105. // At the start of every enumeration or find store API call, check if the
  9106. // underlying store has changed. If it has changed, re-synchronize.
  9107. //
  9108. // This check is only done in the enumeration or find APIs when the
  9109. // pPrevContext is NULL.
  9110. //
  9111. // The pvCtrlPara isn't used and must be set to NULL.
  9112. //--------------------------------------------------------------------------
  9113. //+-------------------------------------------------------------------------
  9114. // CERT_STORE_CTRL_COMMIT
  9115. //
  9116. // If any changes have been to the cached store, they are committed to
  9117. // persisted storage. If no changes have been made since the store was
  9118. // opened or the last commit, this call is ignored. May also be ignored by
  9119. // store providers that persist changes immediately.
  9120. //
  9121. // CERT_STORE_CTRL_COMMIT_FORCE_FLAG can be set to force the store
  9122. // to be committed even if it hasn't been touched.
  9123. //
  9124. // CERT_STORE_CTRL_COMMIT_CLEAR_FLAG can be set to inhibit a commit on
  9125. // store close.
  9126. //--------------------------------------------------------------------------
  9127. #define CERT_STORE_CTRL_COMMIT_FORCE_FLAG 0x1
  9128. #define CERT_STORE_CTRL_COMMIT_CLEAR_FLAG 0x2
  9129. //+=========================================================================
  9130. // Cert Store Property Defines and APIs
  9131. //==========================================================================
  9132. //+-------------------------------------------------------------------------
  9133. // Store property IDs. This is a property applicable to the entire store.
  9134. // Its not a property on an individual certificate, CRL or CTL context.
  9135. //
  9136. // Currently, no store properties are persisted. (This differs from
  9137. // most context properties which are persisted.)
  9138. //
  9139. // See CertSetStoreProperty or CertGetStoreProperty for usage information.
  9140. //
  9141. // Note, the range for predefined store properties should be outside
  9142. // the range of predefined context properties. We will start at 4096.
  9143. //--------------------------------------------------------------------------
  9144. #define CERT_STORE_LOCALIZED_NAME_PROP_ID 0x1000
  9145. //+-------------------------------------------------------------------------
  9146. // Set a store property.
  9147. //
  9148. // The type definition for pvData depends on the dwPropId value.
  9149. // CERT_STORE_LOCALIZED_NAME_PROP_ID - localized name of the store.
  9150. // pvData points to a CRYPT_DATA_BLOB. pbData is a pointer to a NULL
  9151. // terminated unicode, wide character string.
  9152. // cbData = (wcslen((LPWSTR) pbData) + 1) * sizeof(WCHAR).
  9153. //
  9154. // For all the other PROP_IDs: an encoded PCRYPT_DATA_BLOB is passed in pvData.
  9155. //
  9156. // If the property already exists, then, the old value is deleted and silently
  9157. // replaced. Setting, pvData to NULL, deletes the property.
  9158. //--------------------------------------------------------------------------
  9159. WINCRYPT32API
  9160. BOOL
  9161. WINAPI
  9162. CertSetStoreProperty(
  9163. IN HCERTSTORE hCertStore,
  9164. IN DWORD dwPropId,
  9165. IN DWORD dwFlags,
  9166. IN const void *pvData
  9167. );
  9168. //+-------------------------------------------------------------------------
  9169. // Get a store property.
  9170. //
  9171. // The type definition for pvData depends on the dwPropId value.
  9172. // CERT_STORE_LOCALIZED_NAME_PROP_ID - localized name of the store.
  9173. // pvData points to a NULL terminated unicode, wide character string.
  9174. // cbData = (wcslen((LPWSTR) pvData) + 1) * sizeof(WCHAR).
  9175. //
  9176. // For all other PROP_IDs, pvData points to an array of bytes.
  9177. //
  9178. // If the property doesn't exist, returns FALSE and sets LastError to
  9179. // CRYPT_E_NOT_FOUND.
  9180. //--------------------------------------------------------------------------
  9181. WINCRYPT32API
  9182. BOOL
  9183. WINAPI
  9184. CertGetStoreProperty(
  9185. IN HCERTSTORE hCertStore,
  9186. IN DWORD dwPropId,
  9187. OUT void *pvData,
  9188. IN OUT DWORD *pcbData
  9189. );
  9190. typedef struct _CERT_CREATE_CONTEXT_PARA {
  9191. DWORD cbSize;
  9192. PFN_CRYPT_FREE pfnFree; // OPTIONAL
  9193. void *pvFree; // OPTIONAL
  9194. } CERT_CREATE_CONTEXT_PARA, *PCERT_CREATE_CONTEXT_PARA;
  9195. //+-------------------------------------------------------------------------
  9196. // Creates the specified context from the encoded bytes. The created
  9197. // context isn't put in a store.
  9198. //
  9199. // dwContextType values:
  9200. // CERT_STORE_CERTIFICATE_CONTEXT
  9201. // CERT_STORE_CRL_CONTEXT
  9202. // CERT_STORE_CTL_CONTEXT
  9203. //
  9204. // If CERT_CREATE_CONTEXT_NOCOPY_FLAG is set, the created context points
  9205. // directly to the pbEncoded instead of an allocated copy. See flag
  9206. // definition for more details.
  9207. //
  9208. // If CERT_CREATE_CONTEXT_SORTED_FLAG is set, the context is created
  9209. // with sorted entries. This flag may only be set for CERT_STORE_CTL_CONTEXT.
  9210. // Setting this flag implicitly sets CERT_CREATE_CONTEXT_NO_HCRYPTMSG_FLAG and
  9211. // CERT_CREATE_CONTEXT_NO_ENTRY_FLAG. See flag definition for
  9212. // more details.
  9213. //
  9214. // If CERT_CREATE_CONTEXT_NO_HCRYPTMSG_FLAG is set, the context is created
  9215. // without creating a HCRYPTMSG handle for the context. This flag may only be
  9216. // set for CERT_STORE_CTL_CONTEXT. See flag definition for more details.
  9217. //
  9218. // If CERT_CREATE_CONTEXT_NO_ENTRY_FLAG is set, the context is created
  9219. // without decoding the entries. This flag may only be set for
  9220. // CERT_STORE_CTL_CONTEXT. See flag definition for more details.
  9221. //
  9222. // If unable to decode and create the context, NULL is returned.
  9223. // Otherwise, a pointer to a read only CERT_CONTEXT, CRL_CONTEXT or
  9224. // CTL_CONTEXT is returned. The context must be freed by the appropriate
  9225. // free context API. The context can be duplicated by calling the
  9226. // appropriate duplicate context API.
  9227. //--------------------------------------------------------------------------
  9228. WINCRYPT32API
  9229. const void *
  9230. WINAPI
  9231. CertCreateContext(
  9232. IN DWORD dwContextType,
  9233. IN DWORD dwEncodingType,
  9234. IN const BYTE *pbEncoded,
  9235. IN DWORD cbEncoded,
  9236. IN DWORD dwFlags,
  9237. IN OPTIONAL PCERT_CREATE_CONTEXT_PARA pCreatePara
  9238. );
  9239. // When the following flag is set, the created context points directly to the
  9240. // pbEncoded instead of an allocated copy. If pCreatePara and
  9241. // pCreatePara->pfnFree are non-NULL, then, pfnFree is called to free
  9242. // the pbEncoded when the context is last freed. Otherwise, no attempt is
  9243. // made to free the pbEncoded. If pCreatePara->pvFree is non-NULL, then its
  9244. // passed to pfnFree instead of pbEncoded.
  9245. //
  9246. // Note, if CertCreateContext fails, pfnFree is still called.
  9247. #define CERT_CREATE_CONTEXT_NOCOPY_FLAG 0x1
  9248. // When the following flag is set, a context with sorted entries is created.
  9249. // Currently only applicable to a CTL context.
  9250. //
  9251. // For CTLs: the cCTLEntry in the returned CTL_INFO is always
  9252. // 0. CertFindSubjectInSortedCTL and CertEnumSubjectInSortedCTL must be called
  9253. // to find or enumerate the CTL entries.
  9254. //
  9255. // The Sorted CTL TrustedSubjects extension isn't returned in the created
  9256. // context's CTL_INFO.
  9257. #define CERT_CREATE_CONTEXT_SORTED_FLAG 0x2
  9258. // By default when a CTL context is created, a HCRYPTMSG handle to its
  9259. // SignedData message is created. This flag can be set to improve performance
  9260. // by not creating the HCRYPTMSG handle.
  9261. //
  9262. // This flag is only applicable to a CTL context.
  9263. #define CERT_CREATE_CONTEXT_NO_HCRYPTMSG_FLAG 0x4
  9264. // By default when a CTL context is created, its entries are decoded.
  9265. // This flag can be set to improve performance by not decoding the
  9266. // entries.
  9267. //
  9268. // This flag is only applicable to a CTL context.
  9269. #define CERT_CREATE_CONTEXT_NO_ENTRY_FLAG 0x8
  9270. //+=========================================================================
  9271. // Certificate System Store Data Structures and APIs
  9272. //==========================================================================
  9273. //+-------------------------------------------------------------------------
  9274. // System Store Information
  9275. //
  9276. // Currently, no system store information is persisted.
  9277. //--------------------------------------------------------------------------
  9278. typedef struct _CERT_SYSTEM_STORE_INFO {
  9279. DWORD cbSize;
  9280. } CERT_SYSTEM_STORE_INFO, *PCERT_SYSTEM_STORE_INFO;
  9281. //+-------------------------------------------------------------------------
  9282. // Physical Store Information
  9283. //
  9284. // The Open fields are passed directly to CertOpenStore() to open
  9285. // the physical store.
  9286. //
  9287. // By default all system stores located in the registry have an
  9288. // implicit SystemRegistry physical store that is opened. To disable the
  9289. // opening of this store, the SystemRegistry
  9290. // physical store corresponding to the System store must be registered with
  9291. // CERT_PHYSICAL_STORE_OPEN_DISABLE_FLAG set in dwFlags. Alternatively,
  9292. // a physical store with the name of ".Default" may be registered.
  9293. //
  9294. // Depending on the store location and store name, additional predefined
  9295. // physical stores may be opened. For example, system stores in
  9296. // CURRENT_USER have the predefined physical store, .LocalMachine.
  9297. // To disable the opening of these predefined physical stores, the
  9298. // corresponding physical store must be registered with
  9299. // CERT_PHYSICAL_STORE_OPEN_DISABLE_FLAG set in dwFlags.
  9300. //
  9301. // The CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG must be set in dwFlags
  9302. // to enable the adding of a context to the store.
  9303. //
  9304. // When a system store is opened via the SERVICES or USERS store location,
  9305. // the ServiceName\ is prepended to the OpenParameters
  9306. // for CERT_SYSTEM_STORE_CURRENT_USER or CERT_SYSTEM_STORE_CURRENT_SERVICE
  9307. // physical stores and the dwOpenFlags store location is changed to
  9308. // CERT_SYSTEM_STORE_USERS or CERT_SYSTEM_STORE_SERVICES.
  9309. //
  9310. // By default the SYSTEM, SYSTEM_REGISTRY and PHYSICAL provider
  9311. // stores are also opened remotely when the outer system store is opened.
  9312. // The CERT_PHYSICAL_STORE_REMOTE_OPEN_DISABLE_FLAG may be set in dwFlags
  9313. // to disable remote opens.
  9314. //
  9315. // When opened remotely, the \\ComputerName is implicitly prepended to the
  9316. // OpenParameters for the SYSTEM, SYSTEM_REGISTRY and PHYSICAL provider types.
  9317. // To also prepend the \\ComputerName to other provider types, set the
  9318. // CERT_PHYSICAL_STORE_INSERT_COMPUTER_NAME_ENABLE_FLAG in dwFlags.
  9319. //
  9320. // When the system store is opened, its physical stores are ordered
  9321. // according to the dwPriority. A larger dwPriority indicates higher priority.
  9322. //--------------------------------------------------------------------------
  9323. typedef struct _CERT_PHYSICAL_STORE_INFO {
  9324. DWORD cbSize;
  9325. LPSTR pszOpenStoreProvider; // REG_SZ
  9326. DWORD dwOpenEncodingType; // REG_DWORD
  9327. DWORD dwOpenFlags; // REG_DWORD
  9328. CRYPT_DATA_BLOB OpenParameters; // REG_BINARY
  9329. DWORD dwFlags; // REG_DWORD
  9330. DWORD dwPriority; // REG_DWORD
  9331. } CERT_PHYSICAL_STORE_INFO, *PCERT_PHYSICAL_STORE_INFO;
  9332. //+-------------------------------------------------------------------------
  9333. // Physical Store Information dwFlags
  9334. //--------------------------------------------------------------------------
  9335. #define CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG 0x1
  9336. #define CERT_PHYSICAL_STORE_OPEN_DISABLE_FLAG 0x2
  9337. #define CERT_PHYSICAL_STORE_REMOTE_OPEN_DISABLE_FLAG 0x4
  9338. #define CERT_PHYSICAL_STORE_INSERT_COMPUTER_NAME_ENABLE_FLAG 0x8
  9339. //+-------------------------------------------------------------------------
  9340. // Register a system store.
  9341. //
  9342. // The upper word of the dwFlags parameter is used to specify the location of
  9343. // the system store.
  9344. //
  9345. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvSystemStore
  9346. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure. Otherwise,
  9347. // pvSystemStore points to a null terminated UNICODE string.
  9348. //
  9349. // The CERT_SYSTEM_STORE_SERVICES or CERT_SYSTEM_STORE_USERS system store
  9350. // name must be prefixed with the ServiceName or UserName. For example,
  9351. // "ServiceName\Trust".
  9352. //
  9353. // Stores on remote computers can be registered for the
  9354. // CERT_SYSTEM_STORE_LOCAL_MACHINE, CERT_SYSTEM_STORE_SERVICES,
  9355. // CERT_SYSTEM_STORE_USERS, CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY
  9356. // or CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE
  9357. // locations by prepending the computer name. For example, a remote
  9358. // local machine store is registered via "\\ComputerName\Trust" or
  9359. // "ComputerName\Trust". A remote service store is registered via
  9360. // "\\ComputerName\ServiceName\Trust". The leading "\\" backslashes are
  9361. // optional in the ComputerName.
  9362. //
  9363. // Set CERT_STORE_CREATE_NEW_FLAG to cause a failure if the system store
  9364. // already exists in the store location.
  9365. //--------------------------------------------------------------------------
  9366. WINCRYPT32API
  9367. BOOL
  9368. WINAPI
  9369. CertRegisterSystemStore(
  9370. IN const void *pvSystemStore,
  9371. IN DWORD dwFlags,
  9372. IN PCERT_SYSTEM_STORE_INFO pStoreInfo,
  9373. IN OPTIONAL void *pvReserved
  9374. );
  9375. //+-------------------------------------------------------------------------
  9376. // Register a physical store for the specified system store.
  9377. //
  9378. // The upper word of the dwFlags parameter is used to specify the location of
  9379. // the system store.
  9380. //
  9381. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvSystemStore
  9382. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure. Otherwise,
  9383. // pvSystemStore points to a null terminated UNICODE string.
  9384. //
  9385. // See CertRegisterSystemStore for details on prepending a ServiceName
  9386. // and/or ComputerName to the system store name.
  9387. //
  9388. // Set CERT_STORE_CREATE_NEW_FLAG to cause a failure if the physical store
  9389. // already exists in the system store.
  9390. //--------------------------------------------------------------------------
  9391. WINCRYPT32API
  9392. BOOL
  9393. WINAPI
  9394. CertRegisterPhysicalStore(
  9395. IN const void *pvSystemStore,
  9396. IN DWORD dwFlags,
  9397. IN LPCWSTR pwszStoreName,
  9398. IN PCERT_PHYSICAL_STORE_INFO pStoreInfo,
  9399. IN OPTIONAL void *pvReserved
  9400. );
  9401. //+-------------------------------------------------------------------------
  9402. // Unregister the specified system store.
  9403. //
  9404. // The upper word of the dwFlags parameter is used to specify the location of
  9405. // the system store.
  9406. //
  9407. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvSystemStore
  9408. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure. Otherwise,
  9409. // pvSystemStore points to a null terminated UNICODE string.
  9410. //
  9411. // See CertRegisterSystemStore for details on prepending a ServiceName
  9412. // and/or ComputerName to the system store name.
  9413. //
  9414. // CERT_STORE_DELETE_FLAG can optionally be set in dwFlags.
  9415. //--------------------------------------------------------------------------
  9416. WINCRYPT32API
  9417. BOOL
  9418. WINAPI
  9419. CertUnregisterSystemStore(
  9420. IN const void *pvSystemStore,
  9421. IN DWORD dwFlags
  9422. );
  9423. //+-------------------------------------------------------------------------
  9424. // Unregister the physical store from the specified system store.
  9425. //
  9426. // The upper word of the dwFlags parameter is used to specify the location of
  9427. // the system store.
  9428. //
  9429. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvSystemStore
  9430. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure. Otherwise,
  9431. // pvSystemStore points to a null terminated UNICODE string.
  9432. //
  9433. // See CertRegisterSystemStore for details on prepending a ServiceName
  9434. // and/or ComputerName to the system store name.
  9435. //
  9436. // CERT_STORE_DELETE_FLAG can optionally be set in dwFlags.
  9437. //--------------------------------------------------------------------------
  9438. WINCRYPT32API
  9439. BOOL
  9440. WINAPI
  9441. CertUnregisterPhysicalStore(
  9442. IN const void *pvSystemStore,
  9443. IN DWORD dwFlags,
  9444. IN LPCWSTR pwszStoreName
  9445. );
  9446. //+-------------------------------------------------------------------------
  9447. // Enum callbacks
  9448. //
  9449. // The CERT_SYSTEM_STORE_LOCATION_MASK bits in the dwFlags parameter
  9450. // specifies the location of the system store
  9451. //
  9452. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvSystemStore
  9453. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure. Otherwise,
  9454. // pvSystemStore points to a null terminated UNICODE string.
  9455. //
  9456. // The callback returns FALSE and sets LAST_ERROR to stop the enumeration.
  9457. // The LAST_ERROR is returned to the caller of the enumeration.
  9458. //
  9459. // The pvSystemStore passed to the callback has leading ComputerName and/or
  9460. // ServiceName prefixes where appropriate.
  9461. //--------------------------------------------------------------------------
  9462. typedef BOOL (WINAPI *PFN_CERT_ENUM_SYSTEM_STORE_LOCATION)(
  9463. IN LPCWSTR pwszStoreLocation,
  9464. IN DWORD dwFlags,
  9465. IN OPTIONAL void *pvReserved,
  9466. IN OPTIONAL void *pvArg
  9467. );
  9468. typedef BOOL (WINAPI *PFN_CERT_ENUM_SYSTEM_STORE)(
  9469. IN const void *pvSystemStore,
  9470. IN DWORD dwFlags,
  9471. IN PCERT_SYSTEM_STORE_INFO pStoreInfo,
  9472. IN OPTIONAL void *pvReserved,
  9473. IN OPTIONAL void *pvArg
  9474. );
  9475. typedef BOOL (WINAPI *PFN_CERT_ENUM_PHYSICAL_STORE)(
  9476. IN const void *pvSystemStore,
  9477. IN DWORD dwFlags,
  9478. IN LPCWSTR pwszStoreName,
  9479. IN PCERT_PHYSICAL_STORE_INFO pStoreInfo,
  9480. IN OPTIONAL void *pvReserved,
  9481. IN OPTIONAL void *pvArg
  9482. );
  9483. // In the PFN_CERT_ENUM_PHYSICAL_STORE callback the following flag is
  9484. // set if the physical store wasn't registered and is an implicitly created
  9485. // predefined physical store.
  9486. #define CERT_PHYSICAL_STORE_PREDEFINED_ENUM_FLAG 0x1
  9487. // Names of implicitly created predefined physical stores
  9488. #define CERT_PHYSICAL_STORE_DEFAULT_NAME L".Default"
  9489. #define CERT_PHYSICAL_STORE_GROUP_POLICY_NAME L".GroupPolicy"
  9490. #define CERT_PHYSICAL_STORE_LOCAL_MACHINE_NAME L".LocalMachine"
  9491. #define CERT_PHYSICAL_STORE_DS_USER_CERTIFICATE_NAME L".UserCertificate"
  9492. #define CERT_PHYSICAL_STORE_LOCAL_MACHINE_GROUP_POLICY_NAME \
  9493. L".LocalMachineGroupPolicy"
  9494. #define CERT_PHYSICAL_STORE_ENTERPRISE_NAME L".Enterprise"
  9495. #define CERT_PHYSICAL_STORE_AUTH_ROOT_NAME L".AuthRoot"
  9496. //+-------------------------------------------------------------------------
  9497. // Enumerate the system store locations.
  9498. //--------------------------------------------------------------------------
  9499. WINCRYPT32API
  9500. BOOL
  9501. WINAPI
  9502. CertEnumSystemStoreLocation(
  9503. IN DWORD dwFlags,
  9504. IN void *pvArg,
  9505. IN PFN_CERT_ENUM_SYSTEM_STORE_LOCATION pfnEnum
  9506. );
  9507. //+-------------------------------------------------------------------------
  9508. // Enumerate the system stores.
  9509. //
  9510. // The upper word of the dwFlags parameter is used to specify the location of
  9511. // the system store.
  9512. //
  9513. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags,
  9514. // pvSystemStoreLocationPara points to a CERT_SYSTEM_STORE_RELOCATE_PARA
  9515. // data structure. Otherwise, pvSystemStoreLocationPara points to a null
  9516. // terminated UNICODE string.
  9517. //
  9518. // For CERT_SYSTEM_STORE_LOCAL_MACHINE,
  9519. // CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY or
  9520. // CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE, pvSystemStoreLocationPara can
  9521. // optionally be set to a unicode computer name for enumerating local machine
  9522. // stores on a remote computer. For example, "\\ComputerName" or
  9523. // "ComputerName". The leading "\\" backslashes are optional in the
  9524. // ComputerName.
  9525. //
  9526. // For CERT_SYSTEM_STORE_SERVICES or CERT_SYSTEM_STORE_USERS,
  9527. // if pvSystemStoreLocationPara is NULL, then,
  9528. // enumerates both the service/user names and the stores for each service/user
  9529. // name. Otherwise, pvSystemStoreLocationPara is a unicode string specifying a
  9530. // remote computer name and/or service/user name. For example:
  9531. // "ServiceName"
  9532. // "\\ComputerName" or "ComputerName\"
  9533. // "ComputerName\ServiceName"
  9534. // Note, if only the ComputerName is specified, then, it must have either
  9535. // the leading "\\" backslashes or a trailing backslash. Otherwise, its
  9536. // interpretted as the ServiceName or UserName.
  9537. //--------------------------------------------------------------------------
  9538. WINCRYPT32API
  9539. BOOL
  9540. WINAPI
  9541. CertEnumSystemStore(
  9542. IN DWORD dwFlags,
  9543. IN OPTIONAL void *pvSystemStoreLocationPara,
  9544. IN void *pvArg,
  9545. IN PFN_CERT_ENUM_SYSTEM_STORE pfnEnum
  9546. );
  9547. //+-------------------------------------------------------------------------
  9548. // Enumerate the physical stores for the specified system store.
  9549. //
  9550. // The upper word of the dwFlags parameter is used to specify the location of
  9551. // the system store.
  9552. //
  9553. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvSystemStore
  9554. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure. Otherwise,
  9555. // pvSystemStore points to a null terminated UNICODE string.
  9556. //
  9557. // See CertRegisterSystemStore for details on prepending a ServiceName
  9558. // and/or ComputerName to the system store name.
  9559. //
  9560. // If the system store location only supports system stores and doesn't
  9561. // support physical stores, LastError is set to ERROR_CALL_NOT_IMPLEMENTED.
  9562. //--------------------------------------------------------------------------
  9563. WINCRYPT32API
  9564. BOOL
  9565. WINAPI
  9566. CertEnumPhysicalStore(
  9567. IN const void *pvSystemStore,
  9568. IN DWORD dwFlags,
  9569. IN void *pvArg,
  9570. IN PFN_CERT_ENUM_PHYSICAL_STORE pfnEnum
  9571. );
  9572. //+-------------------------------------------------------------------------
  9573. // Certificate System Store Installable Functions
  9574. //
  9575. // The CERT_SYSTEM_STORE_LOCATION_MASK bits in the dwFlags parameter passed
  9576. // to the CertOpenStore(for "System", "SystemRegistry" or "Physical"
  9577. // Provider), CertRegisterSystemStore,
  9578. // CertUnregisterSystemStore, CertEnumSystemStore, CertRegisterPhysicalStore,
  9579. // CertUnregisterPhysicalStore and CertEnumPhysicalStore APIs is used as the
  9580. // constant pszOID value passed to the OID installable functions.
  9581. // Therefore, the pszOID is restricted to a constant <= (LPCSTR) 0x0FFF.
  9582. //
  9583. // The EncodingType is 0.
  9584. //--------------------------------------------------------------------------
  9585. // Installable System Store Provider OID pszFuncNames.
  9586. #define CRYPT_OID_OPEN_SYSTEM_STORE_PROV_FUNC "CertDllOpenSystemStoreProv"
  9587. #define CRYPT_OID_REGISTER_SYSTEM_STORE_FUNC "CertDllRegisterSystemStore"
  9588. #define CRYPT_OID_UNREGISTER_SYSTEM_STORE_FUNC "CertDllUnregisterSystemStore"
  9589. #define CRYPT_OID_ENUM_SYSTEM_STORE_FUNC "CertDllEnumSystemStore"
  9590. #define CRYPT_OID_REGISTER_PHYSICAL_STORE_FUNC "CertDllRegisterPhysicalStore"
  9591. #define CRYPT_OID_UNREGISTER_PHYSICAL_STORE_FUNC "CertDllUnregisterPhysicalStore"
  9592. #define CRYPT_OID_ENUM_PHYSICAL_STORE_FUNC "CertDllEnumPhysicalStore"
  9593. // CertDllOpenSystemStoreProv has the same function signature as the
  9594. // installable "CertDllOpenStoreProv" function. See CertOpenStore for
  9595. // more details.
  9596. // CertDllRegisterSystemStore has the same function signature as
  9597. // CertRegisterSystemStore.
  9598. //
  9599. // The "SystemStoreLocation" REG_SZ value must also be set for registered
  9600. // CertDllEnumSystemStore OID functions.
  9601. #define CRYPT_OID_SYSTEM_STORE_LOCATION_VALUE_NAME L"SystemStoreLocation"
  9602. // The remaining Register, Enum and Unregister OID installable functions
  9603. // have the same signature as their Cert Store API counterpart.
  9604. //+=========================================================================
  9605. // Enhanced Key Usage Helper Functions
  9606. //==========================================================================
  9607. //+-------------------------------------------------------------------------
  9608. // Get the enhanced key usage extension or property from the certificate
  9609. // and decode.
  9610. //
  9611. // If the CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG is set, then, only get the
  9612. // extension.
  9613. //
  9614. // If the CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG is set, then, only get the
  9615. // property.
  9616. //--------------------------------------------------------------------------
  9617. WINCRYPT32API
  9618. BOOL
  9619. WINAPI
  9620. CertGetEnhancedKeyUsage(
  9621. IN PCCERT_CONTEXT pCertContext,
  9622. IN DWORD dwFlags,
  9623. OUT PCERT_ENHKEY_USAGE pUsage,
  9624. IN OUT DWORD *pcbUsage
  9625. );
  9626. //+-------------------------------------------------------------------------
  9627. // Set the enhanced key usage property for the certificate.
  9628. //--------------------------------------------------------------------------
  9629. WINCRYPT32API
  9630. BOOL
  9631. WINAPI
  9632. CertSetEnhancedKeyUsage(
  9633. IN PCCERT_CONTEXT pCertContext,
  9634. IN PCERT_ENHKEY_USAGE pUsage
  9635. );
  9636. //+-------------------------------------------------------------------------
  9637. // Add the usage identifier to the certificate's enhanced key usage property.
  9638. //--------------------------------------------------------------------------
  9639. WINCRYPT32API
  9640. BOOL
  9641. WINAPI
  9642. CertAddEnhancedKeyUsageIdentifier(
  9643. IN PCCERT_CONTEXT pCertContext,
  9644. IN LPCSTR pszUsageIdentifier
  9645. );
  9646. //+-------------------------------------------------------------------------
  9647. // Remove the usage identifier from the certificate's enhanced key usage
  9648. // property.
  9649. //--------------------------------------------------------------------------
  9650. WINCRYPT32API
  9651. BOOL
  9652. WINAPI
  9653. CertRemoveEnhancedKeyUsageIdentifier(
  9654. IN PCCERT_CONTEXT pCertContext,
  9655. IN LPCSTR pszUsageIdentifier
  9656. );
  9657. //+---------------------------------------------------------------------------
  9658. //
  9659. //
  9660. // Takes an array of certs and returns an array of usages
  9661. // which consists of the intersection of the valid usages for each cert.
  9662. // If each cert is good for all possible usages then the cNumOIDs is set to -1.
  9663. //
  9664. //----------------------------------------------------------------------------
  9665. WINCRYPT32API
  9666. BOOL
  9667. WINAPI
  9668. CertGetValidUsages(
  9669. IN DWORD cCerts,
  9670. IN PCCERT_CONTEXT *rghCerts,
  9671. OUT int *cNumOIDs,
  9672. OUT LPSTR *rghOIDs,
  9673. IN OUT DWORD *pcbOIDs);
  9674. //+=========================================================================
  9675. // Cryptographic Message helper functions for verifying and signing a
  9676. // CTL.
  9677. //==========================================================================
  9678. //+-------------------------------------------------------------------------
  9679. // Get and verify the signer of a cryptographic message.
  9680. //
  9681. // To verify a CTL, the hCryptMsg is obtained from the CTL_CONTEXT's
  9682. // hCryptMsg field.
  9683. //
  9684. // If CMSG_TRUSTED_SIGNER_FLAG is set, then, treat the Signer stores as being
  9685. // trusted and only search them to find the certificate corresponding to the
  9686. // signer's issuer and serial number. Otherwise, the SignerStores are
  9687. // optionally provided to supplement the message's store of certificates.
  9688. // If a signer certificate is found, its public key is used to verify
  9689. // the message signature. The CMSG_SIGNER_ONLY_FLAG can be set to
  9690. // return the signer without doing the signature verify.
  9691. //
  9692. // If CMSG_USE_SIGNER_INDEX_FLAG is set, then, only get the signer specified
  9693. // by *pdwSignerIndex. Otherwise, iterate through all the signers
  9694. // until a signer verifies or no more signers.
  9695. //
  9696. // For a verified signature, *ppSigner is updated with certificate context
  9697. // of the signer and *pdwSignerIndex is updated with the index of the signer.
  9698. // ppSigner and/or pdwSignerIndex can be NULL, indicating the caller isn't
  9699. // interested in getting the CertContext and/or index of the signer.
  9700. //--------------------------------------------------------------------------
  9701. WINCRYPT32API
  9702. BOOL
  9703. WINAPI
  9704. CryptMsgGetAndVerifySigner(
  9705. IN HCRYPTMSG hCryptMsg,
  9706. IN DWORD cSignerStore,
  9707. IN OPTIONAL HCERTSTORE *rghSignerStore,
  9708. IN DWORD dwFlags,
  9709. OUT OPTIONAL PCCERT_CONTEXT *ppSigner,
  9710. IN OUT OPTIONAL DWORD *pdwSignerIndex
  9711. );
  9712. #define CMSG_TRUSTED_SIGNER_FLAG 0x1
  9713. #define CMSG_SIGNER_ONLY_FLAG 0x2
  9714. #define CMSG_USE_SIGNER_INDEX_FLAG 0x4
  9715. //+-------------------------------------------------------------------------
  9716. // Sign an encoded CTL.
  9717. //
  9718. // The pbCtlContent can be obtained via a CTL_CONTEXT's pbCtlContent
  9719. // field or via a CryptEncodeObject(PKCS_CTL or PKCS_SORTED_CTL).
  9720. //
  9721. // CMSG_CMS_ENCAPSULATED_CTL_FLAG can be set to encode a CMS compatible
  9722. // V3 SignedData message.
  9723. //--------------------------------------------------------------------------
  9724. WINCRYPT32API
  9725. BOOL
  9726. WINAPI
  9727. CryptMsgSignCTL(
  9728. IN DWORD dwMsgEncodingType,
  9729. IN BYTE *pbCtlContent,
  9730. IN DWORD cbCtlContent,
  9731. IN PCMSG_SIGNED_ENCODE_INFO pSignInfo,
  9732. IN DWORD dwFlags,
  9733. OUT BYTE *pbEncoded,
  9734. IN OUT DWORD *pcbEncoded
  9735. );
  9736. // When set, CTL inner content is encapsulated within an OCTET STRING
  9737. #define CMSG_CMS_ENCAPSULATED_CTL_FLAG 0x00008000
  9738. //+-------------------------------------------------------------------------
  9739. // Encode the CTL and create a signed message containing the encoded CTL.
  9740. //
  9741. // Set CMSG_ENCODE_SORTED_CTL_FLAG if the CTL entries are to be sorted
  9742. // before encoding. This flag should be set, if the
  9743. // CertFindSubjectInSortedCTL or CertEnumSubjectInSortedCTL APIs will
  9744. // be called. If the identifier for the CTL entries is a hash, such as,
  9745. // MD5 or SHA1, then, CMSG_ENCODE_HASHED_SUBJECT_IDENTIFIER_FLAG should
  9746. // also be set.
  9747. //
  9748. // CMSG_CMS_ENCAPSULATED_CTL_FLAG can be set to encode a CMS compatible
  9749. // V3 SignedData message.
  9750. //--------------------------------------------------------------------------
  9751. WINCRYPT32API
  9752. BOOL
  9753. WINAPI
  9754. CryptMsgEncodeAndSignCTL(
  9755. IN DWORD dwMsgEncodingType,
  9756. IN PCTL_INFO pCtlInfo,
  9757. IN PCMSG_SIGNED_ENCODE_INFO pSignInfo,
  9758. IN DWORD dwFlags,
  9759. OUT BYTE *pbEncoded,
  9760. IN OUT DWORD *pcbEncoded
  9761. );
  9762. // The following flag is set if the CTL is to be encoded with sorted
  9763. // trusted subjects and the szOID_SORTED_CTL extension is inserted containing
  9764. // sorted offsets to the encoded subjects.
  9765. #define CMSG_ENCODE_SORTED_CTL_FLAG 0x1
  9766. // If the above sorted flag is set, then, the following flag should also
  9767. // be set if the identifier for the TrustedSubjects is a hash,
  9768. // such as, MD5 or SHA1.
  9769. #define CMSG_ENCODE_HASHED_SUBJECT_IDENTIFIER_FLAG 0x2
  9770. //+-------------------------------------------------------------------------
  9771. // Returns TRUE if the SubjectIdentifier exists in the CTL. Optionally
  9772. // returns a pointer to and byte count of the Subject's encoded attributes.
  9773. //--------------------------------------------------------------------------
  9774. WINCRYPT32API
  9775. BOOL
  9776. WINAPI
  9777. CertFindSubjectInSortedCTL(
  9778. IN PCRYPT_DATA_BLOB pSubjectIdentifier,
  9779. IN PCCTL_CONTEXT pCtlContext,
  9780. IN DWORD dwFlags,
  9781. IN void *pvReserved,
  9782. OUT OPTIONAL PCRYPT_DER_BLOB pEncodedAttributes
  9783. );
  9784. //+-------------------------------------------------------------------------
  9785. // Enumerates through the sequence of TrustedSubjects in a CTL context
  9786. // created with CERT_CREATE_CONTEXT_SORTED_FLAG set.
  9787. //
  9788. // To start the enumeration, *ppvNextSubject must be NULL. Upon return,
  9789. // *ppvNextSubject is updated to point to the next TrustedSubject in
  9790. // the encoded sequence.
  9791. //
  9792. // Returns FALSE for no more subjects or invalid arguments.
  9793. //
  9794. // Note, the returned DER_BLOBs point directly into the encoded
  9795. // bytes (not allocated, and must not be freed).
  9796. //--------------------------------------------------------------------------
  9797. WINCRYPT32API
  9798. BOOL
  9799. WINAPI
  9800. CertEnumSubjectInSortedCTL(
  9801. IN PCCTL_CONTEXT pCtlContext,
  9802. IN OUT void **ppvNextSubject,
  9803. OUT OPTIONAL PCRYPT_DER_BLOB pSubjectIdentifier,
  9804. OUT OPTIONAL PCRYPT_DER_BLOB pEncodedAttributes
  9805. );
  9806. //+=========================================================================
  9807. // Certificate Verify CTL Usage Data Structures and APIs
  9808. //==========================================================================
  9809. typedef struct _CTL_VERIFY_USAGE_PARA {
  9810. DWORD cbSize;
  9811. CRYPT_DATA_BLOB ListIdentifier; // OPTIONAL
  9812. DWORD cCtlStore;
  9813. HCERTSTORE *rghCtlStore; // OPTIONAL
  9814. DWORD cSignerStore;
  9815. HCERTSTORE *rghSignerStore; // OPTIONAL
  9816. } CTL_VERIFY_USAGE_PARA, *PCTL_VERIFY_USAGE_PARA;
  9817. typedef struct _CTL_VERIFY_USAGE_STATUS {
  9818. DWORD cbSize;
  9819. DWORD dwError;
  9820. DWORD dwFlags;
  9821. PCCTL_CONTEXT *ppCtl; // IN OUT OPTIONAL
  9822. DWORD dwCtlEntryIndex;
  9823. PCCERT_CONTEXT *ppSigner; // IN OUT OPTIONAL
  9824. DWORD dwSignerIndex;
  9825. } CTL_VERIFY_USAGE_STATUS, *PCTL_VERIFY_USAGE_STATUS;
  9826. #define CERT_VERIFY_INHIBIT_CTL_UPDATE_FLAG 0x1
  9827. #define CERT_VERIFY_TRUSTED_SIGNERS_FLAG 0x2
  9828. #define CERT_VERIFY_NO_TIME_CHECK_FLAG 0x4
  9829. #define CERT_VERIFY_ALLOW_MORE_USAGE_FLAG 0x8
  9830. #define CERT_VERIFY_UPDATED_CTL_FLAG 0x1
  9831. //+-------------------------------------------------------------------------
  9832. // Verify that a subject is trusted for the specified usage by finding a
  9833. // signed and time valid CTL with the usage identifiers and containing the
  9834. // the subject. A subject can be identified by either its certificate context
  9835. // or any identifier such as its SHA1 hash.
  9836. //
  9837. // See CertFindSubjectInCTL for definition of dwSubjectType and pvSubject
  9838. // parameters.
  9839. //
  9840. // Via pVerifyUsagePara, the caller can specify the stores to be searched
  9841. // to find the CTL. The caller can also specify the stores containing
  9842. // acceptable CTL signers. By setting the ListIdentifier, the caller
  9843. // can also restrict to a particular signer CTL list.
  9844. //
  9845. // Via pVerifyUsageStatus, the CTL containing the subject, the subject's
  9846. // index into the CTL's array of entries, and the signer of the CTL
  9847. // are returned. If the caller is not interested, ppCtl and ppSigner can be set
  9848. // to NULL. Returned contexts must be freed via the store's free context APIs.
  9849. //
  9850. // If the CERT_VERIFY_INHIBIT_CTL_UPDATE_FLAG isn't set, then, a time
  9851. // invalid CTL in one of the CtlStores may be replaced. When replaced, the
  9852. // CERT_VERIFY_UPDATED_CTL_FLAG is set in pVerifyUsageStatus->dwFlags.
  9853. //
  9854. // If the CERT_VERIFY_TRUSTED_SIGNERS_FLAG is set, then, only the
  9855. // SignerStores specified in pVerifyUsageStatus are searched to find
  9856. // the signer. Otherwise, the SignerStores provide additional sources
  9857. // to find the signer's certificate.
  9858. //
  9859. // If CERT_VERIFY_NO_TIME_CHECK_FLAG is set, then, the CTLs aren't checked
  9860. // for time validity.
  9861. //
  9862. // If CERT_VERIFY_ALLOW_MORE_USAGE_FLAG is set, then, the CTL may contain
  9863. // additional usage identifiers than specified by pSubjectUsage. Otherwise,
  9864. // the found CTL will contain the same usage identifers and no more.
  9865. //
  9866. // CertVerifyCTLUsage will be implemented as a dispatcher to OID installable
  9867. // functions. First, it will try to find an OID function matching the first
  9868. // usage object identifier in the pUsage sequence. Next, it will dispatch
  9869. // to the default CertDllVerifyCTLUsage functions.
  9870. //
  9871. // If the subject is trusted for the specified usage, then, TRUE is
  9872. // returned. Otherwise, FALSE is returned with dwError set to one of the
  9873. // following:
  9874. // CRYPT_E_NO_VERIFY_USAGE_DLL
  9875. // CRYPT_E_NO_VERIFY_USAGE_CHECK
  9876. // CRYPT_E_VERIFY_USAGE_OFFLINE
  9877. // CRYPT_E_NOT_IN_CTL
  9878. // CRYPT_E_NO_TRUSTED_SIGNER
  9879. //--------------------------------------------------------------------------
  9880. WINCRYPT32API
  9881. BOOL
  9882. WINAPI
  9883. CertVerifyCTLUsage(
  9884. IN DWORD dwEncodingType,
  9885. IN DWORD dwSubjectType,
  9886. IN void *pvSubject,
  9887. IN PCTL_USAGE pSubjectUsage,
  9888. IN DWORD dwFlags,
  9889. IN OPTIONAL PCTL_VERIFY_USAGE_PARA pVerifyUsagePara,
  9890. IN OUT PCTL_VERIFY_USAGE_STATUS pVerifyUsageStatus
  9891. );
  9892. //+=========================================================================
  9893. // Certificate Revocation Data Structures and APIs
  9894. //==========================================================================
  9895. //+-------------------------------------------------------------------------
  9896. // This data structure is updated by a CRL revocation type handler
  9897. // with the base and possibly the delta CRL used.
  9898. //--------------------------------------------------------------------------
  9899. typedef struct _CERT_REVOCATION_CRL_INFO {
  9900. DWORD cbSize;
  9901. PCCRL_CONTEXT pBaseCrlContext;
  9902. PCCRL_CONTEXT pDeltaCrlContext;
  9903. // When revoked, points to entry in either of the above CRL contexts.
  9904. // Don't free.
  9905. PCRL_ENTRY pCrlEntry;
  9906. BOOL fDeltaCrlEntry; // TRUE if in pDeltaCrlContext
  9907. } CERT_REVOCATION_CRL_INFO, *PCERT_REVOCATION_CRL_INFO;
  9908. //+-------------------------------------------------------------------------
  9909. // The following data structure may be passed to CertVerifyRevocation to
  9910. // assist in finding the issuer of the context to be verified.
  9911. //
  9912. // When pIssuerCert is specified, pIssuerCert is the issuer of
  9913. // rgpvContext[cContext - 1].
  9914. //
  9915. // When cCertStore and rgCertStore are specified, these stores may contain
  9916. // an issuer certificate.
  9917. //
  9918. // When hCrlStore is specified then a handler which uses CRLs can search this
  9919. // store for them
  9920. //
  9921. // When pftTimeToUse is specified then the handler (if possible) must determine
  9922. // revocation status relative to the time given otherwise the answer may be
  9923. // independent of time or relative to current time
  9924. //--------------------------------------------------------------------------
  9925. typedef struct _CERT_REVOCATION_PARA {
  9926. DWORD cbSize;
  9927. PCCERT_CONTEXT pIssuerCert;
  9928. DWORD cCertStore;
  9929. HCERTSTORE *rgCertStore;
  9930. HCERTSTORE hCrlStore;
  9931. LPFILETIME pftTimeToUse;
  9932. #ifdef CERT_REVOCATION_PARA_HAS_EXTRA_FIELDS
  9933. // Note, if you #define CERT_REVOCATION_PARA_HAS_EXTRA_FIELDS, then, you
  9934. // must zero all unused fields in this data structure.
  9935. // More fields could be added in a future release.
  9936. // 0 uses revocation handler's default timeout.
  9937. DWORD dwUrlRetrievalTimeout; // milliseconds
  9938. // When set, checks and attempts to retrieve a CRL where
  9939. // ThisUpdate >= (CurrentTime - dwFreshnessTime). Otherwise, defaults
  9940. // to using the CRL's NextUpdate.
  9941. BOOL fCheckFreshnessTime;
  9942. DWORD dwFreshnessTime; // seconds
  9943. // If NULL, revocation handler gets the current time
  9944. LPFILETIME pftCurrentTime;
  9945. // If nonNULL, a CRL revocation type handler updates with the base and
  9946. // possibly the delta CRL used. Note, *pCrlInfo must be initialized
  9947. // by the caller. Any nonNULL CRL contexts are freed. Any updated
  9948. // CRL contexts must be freed by the caller.
  9949. //
  9950. // The CRL info is only applicable to the last context checked. If
  9951. // interested in this information, then, CertVerifyRevocation should be
  9952. // called with cContext = 1.
  9953. PCERT_REVOCATION_CRL_INFO pCrlInfo;
  9954. #endif
  9955. } CERT_REVOCATION_PARA, *PCERT_REVOCATION_PARA;
  9956. //+-------------------------------------------------------------------------
  9957. // The following data structure is returned by CertVerifyRevocation to
  9958. // specify the status of the revoked or unchecked context. Review the
  9959. // following CertVerifyRevocation comments for details.
  9960. //
  9961. // Upon input to CertVerifyRevocation, cbSize must be set to a size
  9962. // >= (offsetof(CERT_REVOCATION_STATUS, dwReason) + sizeof(DWORD) ).
  9963. // Otherwise, CertVerifyRevocation returns FALSE and sets LastError to
  9964. // E_INVALIDARG.
  9965. //
  9966. // Upon input to the installed or registered CRYPT_OID_VERIFY_REVOCATION_FUNC
  9967. // functions, the dwIndex, dwError and dwReason have been zero'ed.
  9968. // If present, fHasFreshnessTime and dwFreshnessTime have been zero'ed.
  9969. //--------------------------------------------------------------------------
  9970. typedef struct _CERT_REVOCATION_STATUS {
  9971. DWORD cbSize;
  9972. DWORD dwIndex;
  9973. DWORD dwError;
  9974. DWORD dwReason;
  9975. // Depending on cbSize, the following fields may optionally be returned.
  9976. // The Freshness time is only applicable to the last context checked. If
  9977. // interested in this information, then, CertVerifyRevocation should be
  9978. // called with cContext = 1.
  9979. //
  9980. // fHasFreshnessTime is only set if we are able to retrieve revocation
  9981. // information. For a CRL its CurrentTime - ThisUpdate.
  9982. BOOL fHasFreshnessTime;
  9983. DWORD dwFreshnessTime; // seconds
  9984. } CERT_REVOCATION_STATUS, *PCERT_REVOCATION_STATUS;
  9985. //+-------------------------------------------------------------------------
  9986. // Verifies the array of contexts for revocation. The dwRevType parameter
  9987. // indicates the type of the context data structure passed in rgpvContext.
  9988. // Currently only the revocation of certificates is defined.
  9989. //
  9990. // If the CERT_VERIFY_REV_CHAIN_FLAG flag is set, then, CertVerifyRevocation
  9991. // is verifying a chain of certs where, rgpvContext[i + 1] is the issuer
  9992. // of rgpvContext[i]. Otherwise, CertVerifyRevocation makes no assumptions
  9993. // about the order of the contexts.
  9994. //
  9995. // To assist in finding the issuer, the pRevPara may optionally be set. See
  9996. // the CERT_REVOCATION_PARA data structure for details.
  9997. //
  9998. // The contexts must contain enough information to allow the
  9999. // installable or registered revocation DLLs to find the revocation server. For
  10000. // certificates, this information would normally be conveyed in an
  10001. // extension such as the IETF's AuthorityInfoAccess extension.
  10002. //
  10003. // CertVerifyRevocation returns TRUE if all of the contexts were successfully
  10004. // checked and none were revoked. Otherwise, returns FALSE and updates the
  10005. // returned pRevStatus data structure as follows:
  10006. // dwIndex
  10007. // Index of the first context that was revoked or unable to
  10008. // be checked for revocation
  10009. // dwError
  10010. // Error status. LastError is also set to this error status.
  10011. // dwError can be set to one of the following error codes defined
  10012. // in winerror.h:
  10013. // ERROR_SUCCESS - good context
  10014. // CRYPT_E_REVOKED - context was revoked. dwReason contains the
  10015. // reason for revocation
  10016. // CRYPT_E_REVOCATION_OFFLINE - unable to connect to the
  10017. // revocation server
  10018. // CRYPT_E_NOT_IN_REVOCATION_DATABASE - the context to be checked
  10019. // was not found in the revocation server's database.
  10020. // CRYPT_E_NO_REVOCATION_CHECK - the called revocation function
  10021. // wasn't able to do a revocation check on the context
  10022. // CRYPT_E_NO_REVOCATION_DLL - no installed or registered Dll was
  10023. // found to verify revocation
  10024. // dwReason
  10025. // The dwReason is currently only set for CRYPT_E_REVOKED and contains
  10026. // the reason why the context was revoked. May be one of the following
  10027. // CRL reasons defined by the CRL Reason Code extension ("2.5.29.21")
  10028. // CRL_REASON_UNSPECIFIED 0
  10029. // CRL_REASON_KEY_COMPROMISE 1
  10030. // CRL_REASON_CA_COMPROMISE 2
  10031. // CRL_REASON_AFFILIATION_CHANGED 3
  10032. // CRL_REASON_SUPERSEDED 4
  10033. // CRL_REASON_CESSATION_OF_OPERATION 5
  10034. // CRL_REASON_CERTIFICATE_HOLD 6
  10035. //
  10036. // For each entry in rgpvContext, CertVerifyRevocation iterates
  10037. // through the CRYPT_OID_VERIFY_REVOCATION_FUNC
  10038. // function set's list of installed DEFAULT functions.
  10039. // CryptGetDefaultOIDFunctionAddress is called with pwszDll = NULL. If no
  10040. // installed functions are found capable of doing the revocation verification,
  10041. // CryptVerifyRevocation iterates through CRYPT_OID_VERIFY_REVOCATION_FUNC's
  10042. // list of registered DEFAULT Dlls. CryptGetDefaultOIDDllList is called to
  10043. // get the list. CryptGetDefaultOIDFunctionAddress is called to load the Dll.
  10044. //
  10045. // The called functions have the same signature as CertVerifyRevocation. A
  10046. // called function returns TRUE if it was able to successfully check all of
  10047. // the contexts and none were revoked. Otherwise, the called function returns
  10048. // FALSE and updates pRevStatus. dwIndex is set to the index of
  10049. // the first context that was found to be revoked or unable to be checked.
  10050. // dwError and LastError are updated. For CRYPT_E_REVOKED, dwReason
  10051. // is updated. Upon input to the called function, dwIndex, dwError and
  10052. // dwReason have been zero'ed. cbSize has been checked to be >=
  10053. // sizeof(CERT_REVOCATION_STATUS).
  10054. //
  10055. // If the called function returns FALSE, and dwError isn't set to
  10056. // CRYPT_E_REVOKED, then, CertVerifyRevocation either continues on to the
  10057. // next DLL in the list for a returned dwIndex of 0 or for a returned
  10058. // dwIndex > 0, restarts the process of finding a verify function by
  10059. // advancing the start of the context array to the returned dwIndex and
  10060. // decrementing the count of remaining contexts.
  10061. //--------------------------------------------------------------------------
  10062. WINCRYPT32API
  10063. BOOL
  10064. WINAPI
  10065. CertVerifyRevocation(
  10066. IN DWORD dwEncodingType,
  10067. IN DWORD dwRevType,
  10068. IN DWORD cContext,
  10069. IN PVOID rgpvContext[],
  10070. IN DWORD dwFlags,
  10071. IN OPTIONAL PCERT_REVOCATION_PARA pRevPara,
  10072. IN OUT PCERT_REVOCATION_STATUS pRevStatus
  10073. );
  10074. //+-------------------------------------------------------------------------
  10075. // Revocation types
  10076. //--------------------------------------------------------------------------
  10077. #define CERT_CONTEXT_REVOCATION_TYPE 1
  10078. //+-------------------------------------------------------------------------
  10079. // When the following flag is set, rgpvContext[] consists of a chain
  10080. // of certificates, where rgpvContext[i + 1] is the issuer of rgpvContext[i].
  10081. //--------------------------------------------------------------------------
  10082. #define CERT_VERIFY_REV_CHAIN_FLAG 0x00000001
  10083. //+-------------------------------------------------------------------------
  10084. // CERT_VERIFY_CACHE_ONLY_BASED_REVOCATION prevents the revocation handler from
  10085. // accessing any network based resources for revocation checking
  10086. //--------------------------------------------------------------------------
  10087. #define CERT_VERIFY_CACHE_ONLY_BASED_REVOCATION 0x00000002
  10088. //+-------------------------------------------------------------------------
  10089. // By default, the dwUrlRetrievalTimeout in pRevPara is the timeout used
  10090. // for each URL wire retrieval. When the following flag is set,
  10091. // dwUrlRetrievalTimeout is the accumulative timeout across all URL wire
  10092. // retrievals.
  10093. //--------------------------------------------------------------------------
  10094. #define CERT_VERIFY_REV_ACCUMULATIVE_TIMEOUT_FLAG 0x00000004
  10095. //+-------------------------------------------------------------------------
  10096. // CERT_CONTEXT_REVOCATION_TYPE
  10097. //
  10098. // pvContext points to a const CERT_CONTEXT.
  10099. //--------------------------------------------------------------------------
  10100. //+=========================================================================
  10101. // Certificate Helper APIs
  10102. //==========================================================================
  10103. //+-------------------------------------------------------------------------
  10104. // Compare two multiple byte integer blobs to see if they are identical.
  10105. //
  10106. // Before doing the comparison, leading zero bytes are removed from a
  10107. // positive number and leading 0xFF bytes are removed from a negative
  10108. // number.
  10109. //
  10110. // The multiple byte integers are treated as Little Endian. pbData[0] is the
  10111. // least significant byte and pbData[cbData - 1] is the most significant
  10112. // byte.
  10113. //
  10114. // Returns TRUE if the integer blobs are identical after removing leading
  10115. // 0 or 0xFF bytes.
  10116. //--------------------------------------------------------------------------
  10117. BOOL
  10118. WINAPI
  10119. CertCompareIntegerBlob(
  10120. IN PCRYPT_INTEGER_BLOB pInt1,
  10121. IN PCRYPT_INTEGER_BLOB pInt2
  10122. );
  10123. //+-------------------------------------------------------------------------
  10124. // Compare two certificates to see if they are identical.
  10125. //
  10126. // Since a certificate is uniquely identified by its Issuer and SerialNumber,
  10127. // these are the only fields needing to be compared.
  10128. //
  10129. // Returns TRUE if the certificates are identical.
  10130. //--------------------------------------------------------------------------
  10131. WINCRYPT32API
  10132. BOOL
  10133. WINAPI
  10134. CertCompareCertificate(
  10135. IN DWORD dwCertEncodingType,
  10136. IN PCERT_INFO pCertId1,
  10137. IN PCERT_INFO pCertId2
  10138. );
  10139. //+-------------------------------------------------------------------------
  10140. // Compare two certificate names to see if they are identical.
  10141. //
  10142. // Returns TRUE if the names are identical.
  10143. //--------------------------------------------------------------------------
  10144. WINCRYPT32API
  10145. BOOL
  10146. WINAPI
  10147. CertCompareCertificateName(
  10148. IN DWORD dwCertEncodingType,
  10149. IN PCERT_NAME_BLOB pCertName1,
  10150. IN PCERT_NAME_BLOB pCertName2
  10151. );
  10152. //+-------------------------------------------------------------------------
  10153. // Compare the attributes in the certificate name with the specified
  10154. // Relative Distinguished Name's (CERT_RDN) array of attributes.
  10155. // The comparison iterates through the CERT_RDN attributes and looks for an
  10156. // attribute match in any of the certificate name's RDNs.
  10157. // Returns TRUE if all the attributes are found and match.
  10158. //
  10159. // The CERT_RDN_ATTR fields can have the following special values:
  10160. // pszObjId == NULL - ignore the attribute object identifier
  10161. // dwValueType == RDN_ANY_TYPE - ignore the value type
  10162. //
  10163. // CERT_CASE_INSENSITIVE_IS_RDN_ATTRS_FLAG should be set to do
  10164. // a case insensitive match. Otherwise, defaults to an exact, case sensitive
  10165. // match.
  10166. //
  10167. // CERT_UNICODE_IS_RDN_ATTRS_FLAG should be set if the pRDN was initialized
  10168. // with unicode strings as for CryptEncodeObject(X509_UNICODE_NAME).
  10169. //--------------------------------------------------------------------------
  10170. WINCRYPT32API
  10171. BOOL
  10172. WINAPI
  10173. CertIsRDNAttrsInCertificateName(
  10174. IN DWORD dwCertEncodingType,
  10175. IN DWORD dwFlags,
  10176. IN PCERT_NAME_BLOB pCertName,
  10177. IN PCERT_RDN pRDN
  10178. );
  10179. #define CERT_UNICODE_IS_RDN_ATTRS_FLAG 0x1
  10180. #define CERT_CASE_INSENSITIVE_IS_RDN_ATTRS_FLAG 0x2
  10181. //+-------------------------------------------------------------------------
  10182. // Compare two public keys to see if they are identical.
  10183. //
  10184. // Returns TRUE if the keys are identical.
  10185. //--------------------------------------------------------------------------
  10186. WINCRYPT32API
  10187. BOOL
  10188. WINAPI
  10189. CertComparePublicKeyInfo(
  10190. IN DWORD dwCertEncodingType,
  10191. IN PCERT_PUBLIC_KEY_INFO pPublicKey1,
  10192. IN PCERT_PUBLIC_KEY_INFO pPublicKey2
  10193. );
  10194. //+-------------------------------------------------------------------------
  10195. // Get the public/private key's bit length.
  10196. //
  10197. // Returns 0 if unable to determine the key's length.
  10198. //--------------------------------------------------------------------------
  10199. WINCRYPT32API
  10200. DWORD
  10201. WINAPI
  10202. CertGetPublicKeyLength(
  10203. IN DWORD dwCertEncodingType,
  10204. IN PCERT_PUBLIC_KEY_INFO pPublicKey
  10205. );
  10206. //+-------------------------------------------------------------------------
  10207. // Verify the signature of a subject certificate or a CRL using the
  10208. // public key info
  10209. //
  10210. // Returns TRUE for a valid signature.
  10211. //
  10212. // hCryptProv specifies the crypto provider to use to verify the signature.
  10213. // It doesn't need to use a private key.
  10214. //--------------------------------------------------------------------------
  10215. WINCRYPT32API
  10216. BOOL
  10217. WINAPI
  10218. CryptVerifyCertificateSignature(
  10219. IN HCRYPTPROV hCryptProv,
  10220. IN DWORD dwCertEncodingType,
  10221. IN const BYTE * pbEncoded,
  10222. IN DWORD cbEncoded,
  10223. IN PCERT_PUBLIC_KEY_INFO pPublicKey
  10224. );
  10225. //+-------------------------------------------------------------------------
  10226. // Verify the signature of a subject certificate, CRL, certificate request
  10227. // or keygen request using the issuer's public key.
  10228. //
  10229. // Returns TRUE for a valid signature.
  10230. //
  10231. // The subject can be an encoded blob or a context for a certificate or CRL.
  10232. // For a subject certificate context, if the certificate is missing
  10233. // inheritable PublicKey Algorithm Parameters, the context's
  10234. // CERT_PUBKEY_ALG_PARA_PROP_ID is updated with the issuer's public key
  10235. // algorithm parameters for a valid signature.
  10236. //
  10237. // The issuer can be a pointer to a CERT_PUBLIC_KEY_INFO, certificate
  10238. // context or a chain context.
  10239. //
  10240. // hCryptProv specifies the crypto provider to use to verify the signature.
  10241. // Its private key isn't used. If hCryptProv is NULL, a default
  10242. // provider is picked according to the PublicKey Algorithm OID.
  10243. //
  10244. // If the signature algorithm is a hashing algorithm, then, the
  10245. // signature is expected to contain the hash octets. Only dwIssuerType
  10246. // of CRYPT_VERIFY_CERT_SIGN_ISSUER_NULL may be specified
  10247. // to verify this no signature case. If any other dwIssuerType is
  10248. // specified, the verify will fail with LastError set to E_INVALIDARG.
  10249. //--------------------------------------------------------------------------
  10250. WINCRYPT32API
  10251. BOOL
  10252. WINAPI
  10253. CryptVerifyCertificateSignatureEx(
  10254. IN OPTIONAL HCRYPTPROV hCryptProv,
  10255. IN DWORD dwCertEncodingType,
  10256. IN DWORD dwSubjectType,
  10257. IN void *pvSubject,
  10258. IN DWORD dwIssuerType,
  10259. IN void *pvIssuer,
  10260. IN DWORD dwFlags,
  10261. IN OPTIONAL void *pvReserved
  10262. );
  10263. // Subject Types
  10264. #define CRYPT_VERIFY_CERT_SIGN_SUBJECT_BLOB 1
  10265. // pvSubject :: PCRYPT_DATA_BLOB
  10266. #define CRYPT_VERIFY_CERT_SIGN_SUBJECT_CERT 2
  10267. // pvSubject :: PCCERT_CONTEXT
  10268. #define CRYPT_VERIFY_CERT_SIGN_SUBJECT_CRL 3
  10269. // pvSubject :: PCCRL_CONTEXT
  10270. // Issuer Types
  10271. #define CRYPT_VERIFY_CERT_SIGN_ISSUER_PUBKEY 1
  10272. // pvIssuer :: PCERT_PUBLIC_KEY_INFO
  10273. #define CRYPT_VERIFY_CERT_SIGN_ISSUER_CERT 2
  10274. // pvIssuer :: PCCERT_CONTEXT
  10275. #define CRYPT_VERIFY_CERT_SIGN_ISSUER_CHAIN 3
  10276. // pvIssuer :: PCCERT_CHAIN_CONTEXT
  10277. #define CRYPT_VERIFY_CERT_SIGN_ISSUER_NULL 4
  10278. // pvIssuer :: NULL
  10279. //+-------------------------------------------------------------------------
  10280. // Compute the hash of the "to be signed" information in the encoded
  10281. // signed content (CERT_SIGNED_CONTENT_INFO).
  10282. //
  10283. // hCryptProv specifies the crypto provider to use to compute the hash.
  10284. // It doesn't need to use a private key.
  10285. //--------------------------------------------------------------------------
  10286. WINCRYPT32API
  10287. BOOL
  10288. WINAPI
  10289. CryptHashToBeSigned(
  10290. IN HCRYPTPROV hCryptProv,
  10291. IN DWORD dwCertEncodingType,
  10292. IN const BYTE *pbEncoded,
  10293. IN DWORD cbEncoded,
  10294. OUT BYTE *pbComputedHash,
  10295. IN OUT DWORD *pcbComputedHash
  10296. );
  10297. //+-------------------------------------------------------------------------
  10298. // Hash the encoded content.
  10299. //
  10300. // hCryptProv specifies the crypto provider to use to compute the hash.
  10301. // It doesn't need to use a private key.
  10302. //
  10303. // Algid specifies the CAPI hash algorithm to use. If Algid is 0, then, the
  10304. // default hash algorithm (currently SHA1) is used.
  10305. //--------------------------------------------------------------------------
  10306. WINCRYPT32API
  10307. BOOL
  10308. WINAPI
  10309. CryptHashCertificate(
  10310. IN HCRYPTPROV hCryptProv,
  10311. IN ALG_ID Algid,
  10312. IN DWORD dwFlags,
  10313. IN const BYTE *pbEncoded,
  10314. IN DWORD cbEncoded,
  10315. OUT BYTE *pbComputedHash,
  10316. IN OUT DWORD *pcbComputedHash
  10317. );
  10318. //+-------------------------------------------------------------------------
  10319. // Sign the "to be signed" information in the encoded signed content.
  10320. //
  10321. // hCryptProv specifies the crypto provider to use to do the signature.
  10322. // It uses the specified private key.
  10323. //
  10324. // If the SignatureAlgorithm is a hash algorithm, then, the signature
  10325. // contains the hash octets. A private key isn't used to encrypt the hash.
  10326. // dwKeySpec isn't used and hCryptProv can be NULL where an appropriate
  10327. // default provider will be used for hashing.
  10328. //--------------------------------------------------------------------------
  10329. WINCRYPT32API
  10330. BOOL
  10331. WINAPI
  10332. CryptSignCertificate(
  10333. IN HCRYPTPROV hCryptProv,
  10334. IN DWORD dwKeySpec,
  10335. IN DWORD dwCertEncodingType,
  10336. IN const BYTE *pbEncodedToBeSigned,
  10337. IN DWORD cbEncodedToBeSigned,
  10338. IN PCRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm,
  10339. IN OPTIONAL const void *pvHashAuxInfo,
  10340. OUT BYTE *pbSignature,
  10341. IN OUT DWORD *pcbSignature
  10342. );
  10343. //+-------------------------------------------------------------------------
  10344. // Encode the "to be signed" information. Sign the encoded "to be signed".
  10345. // Encode the "to be signed" and the signature.
  10346. //
  10347. // hCryptProv specifies the crypto provider to use to do the signature.
  10348. // It uses the specified private key.
  10349. //
  10350. // If the SignatureAlgorithm is a hash algorithm, then, the signature
  10351. // contains the hash octets. A private key isn't used to encrypt the hash.
  10352. // dwKeySpec isn't used and hCryptProv can be NULL where an appropriate
  10353. // default provider will be used for hashing.
  10354. //--------------------------------------------------------------------------
  10355. WINCRYPT32API
  10356. BOOL
  10357. WINAPI
  10358. CryptSignAndEncodeCertificate(
  10359. IN HCRYPTPROV hCryptProv,
  10360. IN DWORD dwKeySpec,
  10361. IN DWORD dwCertEncodingType,
  10362. IN LPCSTR lpszStructType, // "to be signed"
  10363. IN const void *pvStructInfo,
  10364. IN PCRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm,
  10365. IN OPTIONAL const void *pvHashAuxInfo,
  10366. OUT PBYTE pbEncoded,
  10367. IN OUT DWORD *pcbEncoded
  10368. );
  10369. //+-------------------------------------------------------------------------
  10370. // Verify the time validity of a certificate.
  10371. //
  10372. // Returns -1 if before NotBefore, +1 if after NotAfter and otherwise 0 for
  10373. // a valid certificate
  10374. //
  10375. // If pTimeToVerify is NULL, uses the current time.
  10376. //--------------------------------------------------------------------------
  10377. WINCRYPT32API
  10378. LONG
  10379. WINAPI
  10380. CertVerifyTimeValidity(
  10381. IN LPFILETIME pTimeToVerify,
  10382. IN PCERT_INFO pCertInfo
  10383. );
  10384. //+-------------------------------------------------------------------------
  10385. // Verify the time validity of a CRL.
  10386. //
  10387. // Returns -1 if before ThisUpdate, +1 if after NextUpdate and otherwise 0 for
  10388. // a valid CRL
  10389. //
  10390. // If pTimeToVerify is NULL, uses the current time.
  10391. //--------------------------------------------------------------------------
  10392. WINCRYPT32API
  10393. LONG
  10394. WINAPI
  10395. CertVerifyCRLTimeValidity(
  10396. IN LPFILETIME pTimeToVerify,
  10397. IN PCRL_INFO pCrlInfo
  10398. );
  10399. //+-------------------------------------------------------------------------
  10400. // Verify that the subject's time validity nests within the issuer's time
  10401. // validity.
  10402. //
  10403. // Returns TRUE if it nests. Otherwise, returns FALSE.
  10404. //--------------------------------------------------------------------------
  10405. WINCRYPT32API
  10406. BOOL
  10407. WINAPI
  10408. CertVerifyValidityNesting(
  10409. IN PCERT_INFO pSubjectInfo,
  10410. IN PCERT_INFO pIssuerInfo
  10411. );
  10412. //+-------------------------------------------------------------------------
  10413. // Verify that the subject certificate isn't on its issuer CRL.
  10414. //
  10415. // Returns true if the certificate isn't on the CRL.
  10416. //--------------------------------------------------------------------------
  10417. WINCRYPT32API
  10418. BOOL
  10419. WINAPI
  10420. CertVerifyCRLRevocation(
  10421. IN DWORD dwCertEncodingType,
  10422. IN PCERT_INFO pCertId, // Only the Issuer and SerialNumber
  10423. // fields are used
  10424. IN DWORD cCrlInfo,
  10425. IN PCRL_INFO rgpCrlInfo[]
  10426. );
  10427. //+-------------------------------------------------------------------------
  10428. // Convert the CAPI AlgId to the ASN.1 Object Identifier string
  10429. //
  10430. // Returns NULL if there isn't an ObjId corresponding to the AlgId.
  10431. //--------------------------------------------------------------------------
  10432. WINCRYPT32API
  10433. LPCSTR
  10434. WINAPI
  10435. CertAlgIdToOID(
  10436. IN DWORD dwAlgId
  10437. );
  10438. //+-------------------------------------------------------------------------
  10439. // Convert the ASN.1 Object Identifier string to the CAPI AlgId.
  10440. //
  10441. // Returns 0 if there isn't an AlgId corresponding to the ObjId.
  10442. //--------------------------------------------------------------------------
  10443. WINCRYPT32API
  10444. DWORD
  10445. WINAPI
  10446. CertOIDToAlgId(
  10447. IN LPCSTR pszObjId
  10448. );
  10449. //+-------------------------------------------------------------------------
  10450. // Find an extension identified by its Object Identifier.
  10451. //
  10452. // If found, returns pointer to the extension. Otherwise, returns NULL.
  10453. //--------------------------------------------------------------------------
  10454. WINCRYPT32API
  10455. PCERT_EXTENSION
  10456. WINAPI
  10457. CertFindExtension(
  10458. IN LPCSTR pszObjId,
  10459. IN DWORD cExtensions,
  10460. IN CERT_EXTENSION rgExtensions[]
  10461. );
  10462. //+-------------------------------------------------------------------------
  10463. // Find the first attribute identified by its Object Identifier.
  10464. //
  10465. // If found, returns pointer to the attribute. Otherwise, returns NULL.
  10466. //--------------------------------------------------------------------------
  10467. WINCRYPT32API
  10468. PCRYPT_ATTRIBUTE
  10469. WINAPI
  10470. CertFindAttribute(
  10471. IN LPCSTR pszObjId,
  10472. IN DWORD cAttr,
  10473. IN CRYPT_ATTRIBUTE rgAttr[]
  10474. );
  10475. //+-------------------------------------------------------------------------
  10476. // Find the first CERT_RDN attribute identified by its Object Identifier in
  10477. // the name's list of Relative Distinguished Names.
  10478. //
  10479. // If found, returns pointer to the attribute. Otherwise, returns NULL.
  10480. //--------------------------------------------------------------------------
  10481. WINCRYPT32API
  10482. PCERT_RDN_ATTR
  10483. WINAPI
  10484. CertFindRDNAttr(
  10485. IN LPCSTR pszObjId,
  10486. IN PCERT_NAME_INFO pName
  10487. );
  10488. //+-------------------------------------------------------------------------
  10489. // Get the intended key usage bytes from the certificate.
  10490. //
  10491. // If the certificate doesn't have any intended key usage bytes, returns FALSE
  10492. // and *pbKeyUsage is zeroed. Otherwise, returns TRUE and up through
  10493. // cbKeyUsage bytes are copied into *pbKeyUsage. Any remaining uncopied
  10494. // bytes are zeroed.
  10495. //--------------------------------------------------------------------------
  10496. WINCRYPT32API
  10497. BOOL
  10498. WINAPI
  10499. CertGetIntendedKeyUsage(
  10500. IN DWORD dwCertEncodingType,
  10501. IN PCERT_INFO pCertInfo,
  10502. OUT BYTE *pbKeyUsage,
  10503. IN DWORD cbKeyUsage
  10504. );
  10505. typedef void *HCRYPTDEFAULTCONTEXT;
  10506. //+-------------------------------------------------------------------------
  10507. // Install a previously CryptAcquiredContext'ed HCRYPTPROV to be used as
  10508. // a default context.
  10509. //
  10510. // dwDefaultType and pvDefaultPara specify where the default context is used.
  10511. // For example, install the HCRYPTPROV to be used to verify certificate's
  10512. // having szOID_OIWSEC_md5RSA signatures.
  10513. //
  10514. // By default, the installed HCRYPTPROV is only applicable to the current
  10515. // thread. Set CRYPT_DEFAULT_CONTEXT_PROCESS_FLAG to allow the HCRYPTPROV
  10516. // to be used by all threads in the current process.
  10517. //
  10518. // For a successful install, TRUE is returned and *phDefaultContext is
  10519. // updated with the HANDLE to be passed to CryptUninstallDefaultContext.
  10520. //
  10521. // The installed HCRYPTPROVs are stack ordered (the last installed
  10522. // HCRYPTPROV is checked first). All thread installed HCRYPTPROVs are
  10523. // checked before any process HCRYPTPROVs.
  10524. //
  10525. // The installed HCRYPTPROV remains available for default usage until
  10526. // CryptUninstallDefaultContext is called or the thread or process exits.
  10527. //
  10528. // If CRYPT_DEFAULT_CONTEXT_AUTO_RELEASE_FLAG is set, then, the HCRYPTPROV
  10529. // is CryptReleaseContext'ed at thread or process exit. However,
  10530. // not CryptReleaseContext'ed if CryptUninstallDefaultContext is
  10531. // called.
  10532. //--------------------------------------------------------------------------
  10533. WINCRYPT32API
  10534. BOOL
  10535. WINAPI
  10536. CryptInstallDefaultContext(
  10537. IN HCRYPTPROV hCryptProv,
  10538. IN DWORD dwDefaultType,
  10539. IN const void *pvDefaultPara,
  10540. IN DWORD dwFlags,
  10541. IN void *pvReserved,
  10542. OUT HCRYPTDEFAULTCONTEXT *phDefaultContext
  10543. );
  10544. // dwFlags
  10545. #define CRYPT_DEFAULT_CONTEXT_AUTO_RELEASE_FLAG 0x00000001
  10546. #define CRYPT_DEFAULT_CONTEXT_PROCESS_FLAG 0x00000002
  10547. // List of dwDefaultType's
  10548. #define CRYPT_DEFAULT_CONTEXT_CERT_SIGN_OID 1
  10549. #define CRYPT_DEFAULT_CONTEXT_MULTI_CERT_SIGN_OID 2
  10550. //+-------------------------------------------------------------------------
  10551. // CRYPT_DEFAULT_CONTEXT_CERT_SIGN_OID
  10552. //
  10553. // Install a default HCRYPTPROV used to verify a certificate
  10554. // signature. pvDefaultPara points to the szOID of the certificate
  10555. // signature algorithm, for example, szOID_OIWSEC_md5RSA. If
  10556. // pvDefaultPara is NULL, then, the HCRYPTPROV is used to verify all
  10557. // certificate signatures. Note, pvDefaultPara can't be NULL when
  10558. // CRYPT_DEFAULT_CONTEXT_PROCESS_FLAG is set.
  10559. //--------------------------------------------------------------------------
  10560. //+-------------------------------------------------------------------------
  10561. // CRYPT_DEFAULT_CONTEXT_MULTI_CERT_SIGN_OID
  10562. //
  10563. // Same as CRYPT_DEFAULT_CONTEXT_CERT_SIGN_OID. However, the default
  10564. // HCRYPTPROV is to be used for multiple signature szOIDs. pvDefaultPara
  10565. // points to a CRYPT_DEFAULT_CONTEXT_MULTI_OID_PARA structure containing
  10566. // an array of szOID pointers.
  10567. //--------------------------------------------------------------------------
  10568. typedef struct _CRYPT_DEFAULT_CONTEXT_MULTI_OID_PARA {
  10569. DWORD cOID;
  10570. LPSTR *rgpszOID;
  10571. } CRYPT_DEFAULT_CONTEXT_MULTI_OID_PARA, *PCRYPT_DEFAULT_CONTEXT_MULTI_OID_PARA;
  10572. //+-------------------------------------------------------------------------
  10573. // Uninstall a default context previously installed by
  10574. // CryptInstallDefaultContext.
  10575. //
  10576. // For a default context installed with CRYPT_DEFAULT_CONTEXT_PROCESS_FLAG
  10577. // set, if any other threads are currently using this context,
  10578. // this function will block until they finish.
  10579. //--------------------------------------------------------------------------
  10580. WINCRYPT32API
  10581. BOOL
  10582. WINAPI
  10583. CryptUninstallDefaultContext(
  10584. HCRYPTDEFAULTCONTEXT hDefaultContext,
  10585. IN DWORD dwFlags,
  10586. IN void *pvReserved
  10587. );
  10588. //+-------------------------------------------------------------------------
  10589. // Export the public key info associated with the provider's corresponding
  10590. // private key.
  10591. //
  10592. // Calls CryptExportPublicKeyInfoEx with pszPublicKeyObjId = NULL,
  10593. // dwFlags = 0 and pvAuxInfo = NULL.
  10594. //--------------------------------------------------------------------------
  10595. WINCRYPT32API
  10596. BOOL
  10597. WINAPI
  10598. CryptExportPublicKeyInfo(
  10599. IN HCRYPTPROV hCryptProv,
  10600. IN DWORD dwKeySpec,
  10601. IN DWORD dwCertEncodingType,
  10602. OUT PCERT_PUBLIC_KEY_INFO pInfo,
  10603. IN OUT DWORD *pcbInfo
  10604. );
  10605. //+-------------------------------------------------------------------------
  10606. // Export the public key info associated with the provider's corresponding
  10607. // private key.
  10608. //
  10609. // Uses the dwCertEncodingType and pszPublicKeyObjId to call the
  10610. // installable CRYPT_OID_EXPORT_PUBLIC_KEY_INFO_FUNC. The called function
  10611. // has the same signature as CryptExportPublicKeyInfoEx.
  10612. //
  10613. // If unable to find an installable OID function for the pszPublicKeyObjId,
  10614. // attempts to export as a RSA Public Key (szOID_RSA_RSA).
  10615. //
  10616. // The dwFlags and pvAuxInfo aren't used for szOID_RSA_RSA.
  10617. //--------------------------------------------------------------------------
  10618. #define CRYPT_OID_EXPORT_PUBLIC_KEY_INFO_FUNC "CryptDllExportPublicKeyInfoEx"
  10619. WINCRYPT32API
  10620. BOOL
  10621. WINAPI
  10622. CryptExportPublicKeyInfoEx(
  10623. IN HCRYPTPROV hCryptProv,
  10624. IN DWORD dwKeySpec,
  10625. IN DWORD dwCertEncodingType,
  10626. IN LPSTR pszPublicKeyObjId,
  10627. IN DWORD dwFlags,
  10628. IN OPTIONAL void *pvAuxInfo,
  10629. OUT PCERT_PUBLIC_KEY_INFO pInfo,
  10630. IN OUT DWORD *pcbInfo
  10631. );
  10632. //+-------------------------------------------------------------------------
  10633. // Convert and import the public key info into the provider and return a
  10634. // handle to the public key.
  10635. //
  10636. // Calls CryptImportPublicKeyInfoEx with aiKeyAlg = 0, dwFlags = 0 and
  10637. // pvAuxInfo = NULL.
  10638. //--------------------------------------------------------------------------
  10639. WINCRYPT32API
  10640. BOOL
  10641. WINAPI
  10642. CryptImportPublicKeyInfo(
  10643. IN HCRYPTPROV hCryptProv,
  10644. IN DWORD dwCertEncodingType,
  10645. IN PCERT_PUBLIC_KEY_INFO pInfo,
  10646. OUT HCRYPTKEY *phKey
  10647. );
  10648. //+-------------------------------------------------------------------------
  10649. // Convert and import the public key info into the provider and return a
  10650. // handle to the public key.
  10651. //
  10652. // Uses the dwCertEncodingType and pInfo->Algorithm.pszObjId to call the
  10653. // installable CRYPT_OID_IMPORT_PUBLIC_KEY_INFO_FUNC. The called function
  10654. // has the same signature as CryptImportPublicKeyInfoEx.
  10655. //
  10656. // If unable to find an installable OID function for the pszObjId,
  10657. // attempts to import as a RSA Public Key (szOID_RSA_RSA).
  10658. //
  10659. // For szOID_RSA_RSA: aiKeyAlg may be set to CALG_RSA_SIGN or CALG_RSA_KEYX.
  10660. // Defaults to CALG_RSA_KEYX. The dwFlags and pvAuxInfo aren't used.
  10661. //--------------------------------------------------------------------------
  10662. #define CRYPT_OID_IMPORT_PUBLIC_KEY_INFO_FUNC "CryptDllImportPublicKeyInfoEx"
  10663. WINCRYPT32API
  10664. BOOL
  10665. WINAPI
  10666. CryptImportPublicKeyInfoEx(
  10667. IN HCRYPTPROV hCryptProv,
  10668. IN DWORD dwCertEncodingType,
  10669. IN PCERT_PUBLIC_KEY_INFO pInfo,
  10670. IN ALG_ID aiKeyAlg,
  10671. IN DWORD dwFlags,
  10672. IN OPTIONAL void *pvAuxInfo,
  10673. OUT HCRYPTKEY *phKey
  10674. );
  10675. //+-------------------------------------------------------------------------
  10676. // Acquire a HCRYPTPROV handle and dwKeySpec for the specified certificate
  10677. // context. Uses the certificate's CERT_KEY_PROV_INFO_PROP_ID property.
  10678. // The returned HCRYPTPROV handle may optionally be cached using the
  10679. // certificate's CERT_KEY_CONTEXT_PROP_ID property.
  10680. //
  10681. // If CRYPT_ACQUIRE_CACHE_FLAG is set, then, if an already acquired and
  10682. // cached HCRYPTPROV exists for the certificate, its returned. Otherwise,
  10683. // a HCRYPTPROV is acquired and then cached via the certificate's
  10684. // CERT_KEY_CONTEXT_PROP_ID.
  10685. //
  10686. // The CRYPT_ACQUIRE_USE_PROV_INFO_FLAG can be set to use the dwFlags field of
  10687. // the certificate's CERT_KEY_PROV_INFO_PROP_ID property's CRYPT_KEY_PROV_INFO
  10688. // data structure to determine if the returned HCRYPTPROV should be cached.
  10689. // HCRYPTPROV caching is enabled if the CERT_SET_KEY_CONTEXT_PROP_ID flag was
  10690. // set.
  10691. //
  10692. // If CRYPT_ACQUIRE_COMPARE_KEY_FLAG is set, then,
  10693. // the public key in the certificate is compared with the public
  10694. // key returned by the cryptographic provider. If the keys don't match, the
  10695. // acquire fails and LastError is set to NTE_BAD_PUBLIC_KEY. Note, if
  10696. // a cached HCRYPTPROV is returned, the comparison isn't done. We assume the
  10697. // comparison was done on the initial acquire.
  10698. //
  10699. // The CRYPT_ACQUIRE_SILENT_FLAG can be set to suppress any UI by the CSP.
  10700. // See CryptAcquireContext's CRYPT_SILENT flag for more details.
  10701. //
  10702. // *pfCallerFreeProv is returned set to FALSE for:
  10703. // - Acquire or public key comparison fails.
  10704. // - CRYPT_ACQUIRE_CACHE_FLAG is set.
  10705. // - CRYPT_ACQUIRE_USE_PROV_INFO_FLAG is set AND
  10706. // CERT_SET_KEY_CONTEXT_PROP_ID flag is set in the dwFlags field of the
  10707. // certificate's CERT_KEY_PROV_INFO_PROP_ID property's
  10708. // CRYPT_KEY_PROV_INFO data structure.
  10709. // When *pfCallerFreeProv is FALSE, the caller must not release. The
  10710. // returned HCRYPTPROV will be released on the last free of the certificate
  10711. // context.
  10712. //
  10713. // Otherwise, *pfCallerFreeProv is TRUE and the returned HCRYPTPROV must
  10714. // be released by the caller by calling CryptReleaseContext.
  10715. //--------------------------------------------------------------------------
  10716. WINCRYPT32API
  10717. BOOL
  10718. WINAPI
  10719. CryptAcquireCertificatePrivateKey(
  10720. IN PCCERT_CONTEXT pCert,
  10721. IN DWORD dwFlags,
  10722. IN void *pvReserved,
  10723. OUT HCRYPTPROV *phCryptProv,
  10724. OUT OPTIONAL DWORD *pdwKeySpec,
  10725. OUT OPTIONAL BOOL *pfCallerFreeProv
  10726. );
  10727. #define CRYPT_ACQUIRE_CACHE_FLAG 0x00000001
  10728. #define CRYPT_ACQUIRE_USE_PROV_INFO_FLAG 0x00000002
  10729. #define CRYPT_ACQUIRE_COMPARE_KEY_FLAG 0x00000004
  10730. #define CRYPT_ACQUIRE_SILENT_FLAG 0x00000040
  10731. //+-------------------------------------------------------------------------
  10732. // Enumerates the cryptographic providers and their containers to find the
  10733. // private key corresponding to the certificate's public key. For a match,
  10734. // the certificate's CERT_KEY_PROV_INFO_PROP_ID property is updated.
  10735. //
  10736. // If the CERT_KEY_PROV_INFO_PROP_ID is already set, then, its checked to
  10737. // see if it matches the provider's public key. For a match, the above
  10738. // enumeration is skipped.
  10739. //
  10740. // By default both the user and machine key containers are searched.
  10741. // The CRYPT_FIND_USER_KEYSET_FLAG or CRYPT_FIND_MACHINE_KEYSET_FLAG
  10742. // can be set in dwFlags to restrict the search to either of the containers.
  10743. //
  10744. // The CRYPT_FIND_SILENT_KEYSET_FLAG can be set to suppress any UI by the CSP.
  10745. // See CryptAcquireContext's CRYPT_SILENT flag for more details.
  10746. //
  10747. // If a container isn't found, returns FALSE with LastError set to
  10748. // NTE_NO_KEY.
  10749. //--------------------------------------------------------------------------
  10750. WINCRYPT32API
  10751. BOOL
  10752. WINAPI
  10753. CryptFindCertificateKeyProvInfo(
  10754. IN PCCERT_CONTEXT pCert,
  10755. IN DWORD dwFlags,
  10756. IN void *pvReserved
  10757. );
  10758. #define CRYPT_FIND_USER_KEYSET_FLAG 0x00000001
  10759. #define CRYPT_FIND_MACHINE_KEYSET_FLAG 0x00000002
  10760. #define CRYPT_FIND_SILENT_KEYSET_FLAG 0x00000040
  10761. //+-------------------------------------------------------------------------
  10762. // This is the prototype for the installable function which is called to
  10763. // actually import a key into a CSP. an installable of this type is called
  10764. // from CryptImportPKCS8. the algorithm OID of the private key is used
  10765. // to look up the proper installable function to call.
  10766. //
  10767. // hCryptProv - the provider to import the key to
  10768. // pPrivateKeyInfo - describes the key to be imported
  10769. // dwFlags - The available flags are:
  10770. // CRYPT_EXPORTABLE
  10771. // this flag is used when importing private keys, for a full
  10772. // explanation please see the documentation for CryptImportKey.
  10773. // pvAuxInfo - reserved for future, must be NULL
  10774. //--------------------------------------------------------------------------
  10775. typedef BOOL (WINAPI *PFN_IMPORT_PRIV_KEY_FUNC) (
  10776. HCRYPTPROV hCryptProv, // in
  10777. CRYPT_PRIVATE_KEY_INFO *pPrivateKeyInfo, // in
  10778. DWORD dwFlags, // in, optional
  10779. void *pvAuxInfo // in, optional
  10780. );
  10781. #define CRYPT_OID_IMPORT_PRIVATE_KEY_INFO_FUNC "CryptDllImportPrivateKeyInfoEx"
  10782. //+-------------------------------------------------------------------------
  10783. // Convert (from PKCS8 format) and import the private key into a provider
  10784. // and return a handle to the provider as well as the KeySpec used to import to.
  10785. //
  10786. // This function will call the PRESOLVE_HCRYPTPROV_FUNC in the
  10787. // privateKeyAndParams to obtain a handle of provider to import the key to.
  10788. // if the PRESOLVE_HCRYPTPROV_FUNC is NULL then the default provider will be used.
  10789. //
  10790. // privateKeyAndParams - private key blob and corresponding parameters
  10791. // dwFlags - The available flags are:
  10792. // CRYPT_EXPORTABLE
  10793. // this flag is used when importing private keys, for a full
  10794. // explanation please see the documentation for CryptImportKey.
  10795. // phCryptProv - filled in with the handle of the provider the key was
  10796. // imported to, the caller is responsible for freeing it
  10797. // pvAuxInfo - This parameter is reserved for future use and should be set
  10798. // to NULL in the interim.
  10799. //--------------------------------------------------------------------------
  10800. WINCRYPT32API
  10801. BOOL
  10802. WINAPI
  10803. CryptImportPKCS8(
  10804. CRYPT_PKCS8_IMPORT_PARAMS sImportParams, // in
  10805. DWORD dwFlags, // in, optional
  10806. HCRYPTPROV *phCryptProv, // out, optional
  10807. void *pvAuxInfo // in, optional
  10808. );
  10809. //+-------------------------------------------------------------------------
  10810. // this is the prototype for installable functions for exporting the private key
  10811. //--------------------------------------------------------------------------
  10812. typedef BOOL (WINAPI *PFN_EXPORT_PRIV_KEY_FUNC) (
  10813. HCRYPTPROV hCryptProv, // in
  10814. DWORD dwKeySpec, // in
  10815. LPSTR pszPrivateKeyObjId, // in
  10816. DWORD dwFlags, // in
  10817. void *pvAuxInfo, // in
  10818. CRYPT_PRIVATE_KEY_INFO *pPrivateKeyInfo, // out
  10819. DWORD *pcbPrivateKeyBlob // in, out
  10820. );
  10821. #define CRYPT_OID_EXPORT_PRIVATE_KEY_INFO_FUNC "CryptDllExportPrivateKeyInfoEx"
  10822. #define CRYPT_DELETE_KEYSET 0x0001
  10823. //+-------------------------------------------------------------------------
  10824. // CryptExportPKCS8 -- superseded by CryptExportPKCS8Ex
  10825. //
  10826. // Export the private key in PKCS8 format
  10827. //--------------------------------------------------------------------------
  10828. WINCRYPT32API
  10829. BOOL
  10830. WINAPI
  10831. CryptExportPKCS8(
  10832. HCRYPTPROV hCryptProv, // in
  10833. DWORD dwKeySpec, // in
  10834. LPSTR pszPrivateKeyObjId, // in
  10835. DWORD dwFlags, // in
  10836. void *pvAuxInfo, // in
  10837. BYTE *pbPrivateKeyBlob, // out
  10838. DWORD *pcbPrivateKeyBlob // in, out
  10839. );
  10840. //+-------------------------------------------------------------------------
  10841. // CryptExportPKCS8Ex
  10842. //
  10843. // Export the private key in PKCS8 format
  10844. //
  10845. //
  10846. // Uses the pszPrivateKeyObjId to call the
  10847. // installable CRYPT_OID_EXPORT_PRIVATE_KEY_INFO_FUNC. The called function
  10848. // has the signature defined by PFN_EXPORT_PRIV_KEY_FUNC.
  10849. //
  10850. // If unable to find an installable OID function for the pszPrivateKeyObjId,
  10851. // attempts to export as a RSA Private Key (szOID_RSA_RSA).
  10852. //
  10853. // psExportParams - specifies information about the key to export
  10854. // dwFlags - The flag values. None currently supported
  10855. // pvAuxInfo - This parameter is reserved for future use and should be set to
  10856. // NULL in the interim.
  10857. // pbPrivateKeyBlob - A pointer to the private key blob. It will be encoded
  10858. // as a PKCS8 PrivateKeyInfo.
  10859. // pcbPrivateKeyBlob - A pointer to a DWORD that contains the size, in bytes,
  10860. // of the private key blob being exported.
  10861. //+-------------------------------------------------------------------------
  10862. WINCRYPT32API
  10863. BOOL
  10864. WINAPI
  10865. CryptExportPKCS8Ex(
  10866. CRYPT_PKCS8_EXPORT_PARAMS* psExportParams, // in
  10867. DWORD dwFlags, // in
  10868. void *pvAuxInfo, // in
  10869. BYTE *pbPrivateKeyBlob, // out
  10870. DWORD *pcbPrivateKeyBlob // in, out
  10871. );
  10872. //+-------------------------------------------------------------------------
  10873. // Compute the hash of the encoded public key info.
  10874. //
  10875. // The public key info is encoded and then hashed.
  10876. //--------------------------------------------------------------------------
  10877. WINCRYPT32API
  10878. BOOL
  10879. WINAPI
  10880. CryptHashPublicKeyInfo(
  10881. IN HCRYPTPROV hCryptProv,
  10882. IN ALG_ID Algid,
  10883. IN DWORD dwFlags,
  10884. IN DWORD dwCertEncodingType,
  10885. IN PCERT_PUBLIC_KEY_INFO pInfo,
  10886. OUT BYTE *pbComputedHash,
  10887. IN OUT DWORD *pcbComputedHash
  10888. );
  10889. //+-------------------------------------------------------------------------
  10890. // Convert a Name Value to a null terminated char string
  10891. //
  10892. // Returns the number of characters converted including the terminating null
  10893. // character. If psz is NULL or csz is 0, returns the required size of the
  10894. // destination string (including the terminating null char).
  10895. //
  10896. // If psz != NULL && csz != 0, returned psz is always NULL terminated.
  10897. //
  10898. // Note: csz includes the NULL char.
  10899. //--------------------------------------------------------------------------
  10900. WINCRYPT32API
  10901. DWORD
  10902. WINAPI
  10903. CertRDNValueToStr%(
  10904. IN DWORD dwValueType,
  10905. IN PCERT_RDN_VALUE_BLOB pValue,
  10906. OUT OPTIONAL LPTSTR% psz,
  10907. IN DWORD csz
  10908. );
  10909. //+-------------------------------------------------------------------------
  10910. // Convert the certificate name blob to a null terminated char string.
  10911. //
  10912. // Follows the string representation of distinguished names specified in
  10913. // RFC 1779. (Note, added double quoting "" for embedded quotes, quote
  10914. // empty strings and don't quote strings containing consecutive spaces).
  10915. // RDN values of type CERT_RDN_ENCODED_BLOB or CERT_RDN_OCTET_STRING are
  10916. // formatted in hexadecimal (e.g. #0A56CF).
  10917. //
  10918. // The name string is formatted according to the dwStrType:
  10919. // CERT_SIMPLE_NAME_STR
  10920. // The object identifiers are discarded. CERT_RDN entries are separated
  10921. // by ", ". Multiple attributes per CERT_RDN are separated by " + ".
  10922. // For example:
  10923. // Microsoft, Joe Cool + Programmer
  10924. // CERT_OID_NAME_STR
  10925. // The object identifiers are included with a "=" separator from their
  10926. // attribute value. CERT_RDN entries are separated by ", ".
  10927. // Multiple attributes per CERT_RDN are separated by " + ". For example:
  10928. // 2.5.4.11=Microsoft, 2.5.4.3=Joe Cool + 2.5.4.12=Programmer
  10929. // CERT_X500_NAME_STR
  10930. // The object identifiers are converted to their X500 key name. Otherwise,
  10931. // same as CERT_OID_NAME_STR. If the object identifier doesn't have
  10932. // a corresponding X500 key name, then, the object identifier is used with
  10933. // a "OID." prefix. For example:
  10934. // OU=Microsoft, CN=Joe Cool + T=Programmer, OID.1.2.3.4.5.6=Unknown
  10935. //
  10936. // We quote the RDN value if it contains leading or trailing whitespace
  10937. // or one of the following characters: ",", "+", "=", """, "\n", "<", ">",
  10938. // "#" or ";". The quoting character is ". If the the RDN Value contains
  10939. // a " it is double quoted (""). For example:
  10940. // OU=" Microsoft", CN="Joe ""Cool""" + T="Programmer, Manager"
  10941. //
  10942. // CERT_NAME_STR_SEMICOLON_FLAG can be or'ed into dwStrType to replace
  10943. // the ", " separator with a "; " separator.
  10944. //
  10945. // CERT_NAME_STR_CRLF_FLAG can be or'ed into dwStrType to replace
  10946. // the ", " separator with a "\r\n" separator.
  10947. //
  10948. // CERT_NAME_STR_NO_PLUS_FLAG can be or'ed into dwStrType to replace the
  10949. // " + " separator with a single space, " ".
  10950. //
  10951. // CERT_NAME_STR_NO_QUOTING_FLAG can be or'ed into dwStrType to inhibit
  10952. // the above quoting.
  10953. //
  10954. // CERT_NAME_STR_REVERSE_FLAG can be or'ed into dwStrType to reverse the
  10955. // order of the RDNs before converting to the string.
  10956. //
  10957. // By default, CERT_RDN_T61_STRING encoded values are initially decoded
  10958. // as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  10959. // CERT_NAME_STR_DISABLE_IE4_UTF8_FLAG can be or'ed into dwStrType to
  10960. // skip the initial attempt to decode as UTF8.
  10961. //
  10962. // Returns the number of characters converted including the terminating null
  10963. // character. If psz is NULL or csz is 0, returns the required size of the
  10964. // destination string (including the terminating null char).
  10965. //
  10966. // If psz != NULL && csz != 0, returned psz is always NULL terminated.
  10967. //
  10968. // Note: csz includes the NULL char.
  10969. //--------------------------------------------------------------------------
  10970. //+-------------------------------------------------------------------------
  10971. //--------------------------------------------------------------------------
  10972. WINCRYPT32API
  10973. DWORD
  10974. WINAPI
  10975. CertNameToStr%(
  10976. IN DWORD dwCertEncodingType,
  10977. IN PCERT_NAME_BLOB pName,
  10978. IN DWORD dwStrType,
  10979. OUT OPTIONAL LPTSTR% psz,
  10980. IN DWORD csz
  10981. );
  10982. //+-------------------------------------------------------------------------
  10983. // Certificate name string types
  10984. //--------------------------------------------------------------------------
  10985. #define CERT_SIMPLE_NAME_STR 1
  10986. #define CERT_OID_NAME_STR 2
  10987. #define CERT_X500_NAME_STR 3
  10988. //+-------------------------------------------------------------------------
  10989. // Certificate name string type flags OR'ed with the above types
  10990. //--------------------------------------------------------------------------
  10991. #define CERT_NAME_STR_SEMICOLON_FLAG 0x40000000
  10992. #define CERT_NAME_STR_NO_PLUS_FLAG 0x20000000
  10993. #define CERT_NAME_STR_NO_QUOTING_FLAG 0x10000000
  10994. #define CERT_NAME_STR_CRLF_FLAG 0x08000000
  10995. #define CERT_NAME_STR_COMMA_FLAG 0x04000000
  10996. #define CERT_NAME_STR_REVERSE_FLAG 0x02000000
  10997. #define CERT_NAME_STR_DISABLE_IE4_UTF8_FLAG 0x00010000
  10998. #define CERT_NAME_STR_ENABLE_T61_UNICODE_FLAG 0x00020000
  10999. #define CERT_NAME_STR_ENABLE_UTF8_UNICODE_FLAG 0x00040000
  11000. //+-------------------------------------------------------------------------
  11001. // Convert the null terminated X500 string to an encoded certificate name.
  11002. //
  11003. // The input string is expected to be formatted the same as the output
  11004. // from the above CertNameToStr API.
  11005. //
  11006. // The CERT_SIMPLE_NAME_STR type isn't supported. Otherwise, when dwStrType
  11007. // is set to 0, CERT_OID_NAME_STR or CERT_X500_NAME_STR, allow either a
  11008. // case insensitive X500 key (CN=), case insensitive "OID." prefixed
  11009. // object identifier (OID.1.2.3.4.5.6=) or an object identifier (1.2.3.4=).
  11010. //
  11011. // If no flags are OR'ed into dwStrType, then, allow "," or ";" as RDN
  11012. // separators and "+" as the multiple RDN value separator. Quoting is
  11013. // supported. A quote may be included in a quoted value by double quoting,
  11014. // for example (CN="Joe ""Cool"""). A value starting with a "#" is treated
  11015. // as ascii hex and converted to a CERT_RDN_OCTET_STRING. Embedded whitespace
  11016. // is skipped (1.2.3 = # AB CD 01 is the same as 1.2.3=#ABCD01).
  11017. //
  11018. // Whitespace surrounding the keys, object identifers and values is removed.
  11019. //
  11020. // CERT_NAME_STR_COMMA_FLAG can be or'ed into dwStrType to only allow the
  11021. // "," as the RDN separator.
  11022. //
  11023. // CERT_NAME_STR_SEMICOLON_FLAG can be or'ed into dwStrType to only allow the
  11024. // ";" as the RDN separator.
  11025. //
  11026. // CERT_NAME_STR_CRLF_FLAG can be or'ed into dwStrType to only allow
  11027. // "\r" or "\n" as the RDN separator.
  11028. //
  11029. // CERT_NAME_STR_NO_PLUS_FLAG can be or'ed into dwStrType to ignore "+"
  11030. // as a separator and not allow multiple values per RDN.
  11031. //
  11032. // CERT_NAME_STR_NO_QUOTING_FLAG can be or'ed into dwStrType to inhibit
  11033. // quoting.
  11034. //
  11035. // CERT_NAME_STR_REVERSE_FLAG can be or'ed into dwStrType to reverse the
  11036. // order of the RDNs after converting from the string and before encoding.
  11037. //
  11038. // CERT_NAME_STR_ENABLE_T61_UNICODE_FLAG can be or'ed into dwStrType to
  11039. // to select the CERT_RDN_T61_STRING encoded value type instead of
  11040. // CERT_RDN_UNICODE_STRING if all the UNICODE characters are <= 0xFF.
  11041. //
  11042. // CERT_NAME_STR_ENABLE_UTF8_UNICODE_FLAG can be or'ed into dwStrType to
  11043. // to select the CERT_RDN_UTF8_STRING encoded value type instead of
  11044. // CERT_RDN_UNICODE_STRING.
  11045. //
  11046. // Support the following X500 Keys:
  11047. //
  11048. // Key Object Identifier RDN Value Type(s)
  11049. // --- ----------------- -----------------
  11050. // CN szOID_COMMON_NAME Printable, Unicode
  11051. // L szOID_LOCALITY_NAME Printable, Unicode
  11052. // O szOID_ORGANIZATION_NAME Printable, Unicode
  11053. // OU szOID_ORGANIZATIONAL_UNIT_NAME Printable, Unicode
  11054. // E szOID_RSA_emailAddr Only IA5
  11055. // Email szOID_RSA_emailAddr Only IA5
  11056. // C szOID_COUNTRY_NAME Only Printable
  11057. // S szOID_STATE_OR_PROVINCE_NAME Printable, Unicode
  11058. // ST szOID_STATE_OR_PROVINCE_NAME Printable, Unicode
  11059. // STREET szOID_STREET_ADDRESS Printable, Unicode
  11060. // T szOID_TITLE Printable, Unicode
  11061. // Title szOID_TITLE Printable, Unicode
  11062. // G szOID_GIVEN_NAME Printable, Unicode
  11063. // GivenName szOID_GIVEN_NAME Printable, Unicode
  11064. // I szOID_INITIALS Printable, Unicode
  11065. // Initials szOID_INITIALS Printable, Unicode
  11066. // SN szOID_SUR_NAME Printable, Unicode
  11067. // DC szOID_DOMAIN_COMPONENT IA5, UTF8
  11068. //
  11069. // Note, T61 is selected instead of Unicode if
  11070. // CERT_NAME_STR_ENABLE_T61_UNICODE_FLAG is set and all the unicode
  11071. // characters are <= 0xFF.
  11072. //
  11073. // Note, UTF8 is selected instead of Unicode if
  11074. // CERT_NAME_STR_ENABLE_UTF8_UNICODE_FLAG is set.
  11075. //
  11076. // Returns TRUE if successfully parsed the input string and encoded
  11077. // the name.
  11078. //
  11079. // If the input string is detected to be invalid, *ppszError is updated
  11080. // to point to the beginning of the invalid character sequence. Otherwise,
  11081. // *ppszError is set to NULL. *ppszError is updated with a non-NULL pointer
  11082. // for the following errors:
  11083. // CRYPT_E_INVALID_X500_STRING
  11084. // CRYPT_E_INVALID_NUMERIC_STRING
  11085. // CRYPT_E_INVALID_PRINTABLE_STRING
  11086. // CRYPT_E_INVALID_IA5_STRING
  11087. //
  11088. // ppszError can be set to NULL if not interested in getting a pointer
  11089. // to the invalid character sequence.
  11090. //--------------------------------------------------------------------------
  11091. //+-------------------------------------------------------------------------
  11092. //--------------------------------------------------------------------------
  11093. WINCRYPT32API
  11094. BOOL
  11095. WINAPI
  11096. CertStrToName%(
  11097. IN DWORD dwCertEncodingType,
  11098. IN LPCTSTR% pszX500,
  11099. IN DWORD dwStrType,
  11100. IN OPTIONAL void *pvReserved,
  11101. OUT BYTE *pbEncoded,
  11102. IN OUT DWORD *pcbEncoded,
  11103. OUT OPTIONAL LPCTSTR% *ppszError
  11104. );
  11105. //+-------------------------------------------------------------------------
  11106. // Get the subject or issuer name from the certificate and
  11107. // according to the specified format type, convert to a null terminated
  11108. // character string.
  11109. //
  11110. // CERT_NAME_ISSUER_FLAG can be set to get the issuer's name. Otherwise,
  11111. // gets the subject's name.
  11112. //
  11113. // By default, CERT_RDN_T61_STRING encoded values are initially decoded
  11114. // as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  11115. // CERT_NAME_DISABLE_IE4_UTF8_FLAG can be set in dwFlags to
  11116. // skip the initial attempt to decode as UTF8.
  11117. //
  11118. // The name string is formatted according to the dwType:
  11119. // CERT_NAME_EMAIL_TYPE
  11120. // If the certificate has a Subject Alternative Name extension (for
  11121. // issuer, Issuer Alternative Name), searches for first rfc822Name choice.
  11122. // If the rfc822Name choice isn't found in the extension, searches the
  11123. // Subject Name field for the Email OID, "1.2.840.113549.1.9.1".
  11124. // If the rfc822Name or Email OID is found, returns the string. Otherwise,
  11125. // returns an empty string (returned character count is 1).
  11126. // CERT_NAME_DNS_TYPE
  11127. // If the certificate has a Subject Alternative Name extension (for
  11128. // issuer, Issuer Alternative Name), searches for first DNSName choice.
  11129. // If the DNSName choice isn't found in the extension, searches the
  11130. // Subject Name field for the CN OID, "2.5.4.3".
  11131. // If the DNSName or CN OID is found, returns the string. Otherwise,
  11132. // returns an empty string.
  11133. // CERT_NAME_URL_TYPE
  11134. // If the certificate has a Subject Alternative Name extension (for
  11135. // issuer, Issuer Alternative Name), searches for first URL choice.
  11136. // If the URL choice is found, returns the string. Otherwise,
  11137. // returns an empty string.
  11138. // CERT_NAME_UPN_TYPE
  11139. // If the certificate has a Subject Alternative Name extension,
  11140. // searches the OtherName choices looking for a
  11141. // pszObjId == szOID_NT_PRINCIPAL_NAME, "1.3.6.1.4.1.311.20.2.3".
  11142. // If the UPN OID is found, the blob is decoded as a
  11143. // X509_UNICODE_ANY_STRING and the decoded string is returned.
  11144. // Otherwise, returns an empty string.
  11145. // CERT_NAME_RDN_TYPE
  11146. // Converts the Subject Name blob by calling CertNameToStr. pvTypePara
  11147. // points to a DWORD containing the dwStrType passed to CertNameToStr.
  11148. // If the Subject Name field is empty and the certificate has a
  11149. // Subject Alternative Name extension, searches for and converts
  11150. // the first directoryName choice.
  11151. // CERT_NAME_ATTR_TYPE
  11152. // pvTypePara points to the Object Identifier specifying the name attribute
  11153. // to be returned. For example, to get the CN,
  11154. // pvTypePara = szOID_COMMON_NAME ("2.5.4.3"). Searches, the Subject Name
  11155. // field for the attribute.
  11156. // If the Subject Name field is empty and the certificate has a
  11157. // Subject Alternative Name extension, checks for
  11158. // the first directoryName choice and searches it.
  11159. //
  11160. // Note, searches the RDNs in reverse order.
  11161. //
  11162. // CERT_NAME_SIMPLE_DISPLAY_TYPE
  11163. // Iterates through the following list of name attributes and searches
  11164. // the Subject Name and then the Subject Alternative Name extension
  11165. // for the first occurrence of:
  11166. // szOID_COMMON_NAME ("2.5.4.3")
  11167. // szOID_ORGANIZATIONAL_UNIT_NAME ("2.5.4.11")
  11168. // szOID_ORGANIZATION_NAME ("2.5.4.10")
  11169. // szOID_RSA_emailAddr ("1.2.840.113549.1.9.1")
  11170. //
  11171. // If none of the above attributes is found, then, searches the
  11172. // Subject Alternative Name extension for a rfc822Name choice.
  11173. //
  11174. // If still no match, then, returns the first attribute.
  11175. //
  11176. // Note, like CERT_NAME_ATTR_TYPE, searches the RDNs in reverse order.
  11177. //
  11178. // CERT_NAME_FRIENDLY_DISPLAY_TYPE
  11179. // First checks if the certificate has a CERT_FRIENDLY_NAME_PROP_ID
  11180. // property. If it does, then, this property is returned. Otherwise,
  11181. // returns the above CERT_NAME_SIMPLE_DISPLAY_TYPE.
  11182. //
  11183. // Returns the number of characters converted including the terminating null
  11184. // character. If pwszNameString is NULL or cchNameString is 0, returns the
  11185. // required size of the destination string (including the terminating null
  11186. // char). If the specified name type isn't found. returns an empty string
  11187. // with a returned character count of 1.
  11188. //
  11189. // If pwszNameString != NULL && cwszNameString != 0, returned pwszNameString
  11190. // is always NULL terminated.
  11191. //
  11192. // Note: cchNameString includes the NULL char.
  11193. //--------------------------------------------------------------------------
  11194. //+-------------------------------------------------------------------------
  11195. //--------------------------------------------------------------------------
  11196. WINCRYPT32API
  11197. DWORD
  11198. WINAPI
  11199. CertGetNameString%(
  11200. IN PCCERT_CONTEXT pCertContext,
  11201. IN DWORD dwType,
  11202. IN DWORD dwFlags,
  11203. IN void *pvTypePara,
  11204. OUT OPTIONAL LPTSTR% pszNameString,
  11205. IN DWORD cchNameString
  11206. );
  11207. //+-------------------------------------------------------------------------
  11208. // Certificate name types
  11209. //--------------------------------------------------------------------------
  11210. #define CERT_NAME_EMAIL_TYPE 1
  11211. #define CERT_NAME_RDN_TYPE 2
  11212. #define CERT_NAME_ATTR_TYPE 3
  11213. #define CERT_NAME_SIMPLE_DISPLAY_TYPE 4
  11214. #define CERT_NAME_FRIENDLY_DISPLAY_TYPE 5
  11215. #define CERT_NAME_DNS_TYPE 6
  11216. #define CERT_NAME_URL_TYPE 7
  11217. #define CERT_NAME_UPN_TYPE 8
  11218. //+-------------------------------------------------------------------------
  11219. // Certificate name flags
  11220. //--------------------------------------------------------------------------
  11221. #define CERT_NAME_ISSUER_FLAG 0x1
  11222. #define CERT_NAME_DISABLE_IE4_UTF8_FLAG 0x00010000
  11223. //+=========================================================================
  11224. // Simplified Cryptographic Message Data Structures and APIs
  11225. //==========================================================================
  11226. //+-------------------------------------------------------------------------
  11227. // Conventions for the *pb and *pcb output parameters:
  11228. //
  11229. // Upon entry to the function:
  11230. // if pcb is OPTIONAL && pcb == NULL, then,
  11231. // No output is returned
  11232. // else if pb == NULL && pcb != NULL, then,
  11233. // Length only determination. No length error is
  11234. // returned.
  11235. // otherwise where (pb != NULL && pcb != NULL && *pcb != 0)
  11236. // Output is returned. If *pcb isn't big enough a
  11237. // length error is returned. In all cases *pcb is updated
  11238. // with the actual length needed/returned.
  11239. //--------------------------------------------------------------------------
  11240. //+-------------------------------------------------------------------------
  11241. // Type definitions of the parameters used for doing the cryptographic
  11242. // operations.
  11243. //--------------------------------------------------------------------------
  11244. //+-------------------------------------------------------------------------
  11245. // Callback to get and verify the signer's certificate.
  11246. //
  11247. // Passed the CertId of the signer (its Issuer and SerialNumber) and a
  11248. // handle to its cryptographic signed message's cert store.
  11249. //
  11250. // For CRYPT_E_NO_SIGNER, called with pSignerId == NULL.
  11251. //
  11252. // For a valid signer certificate, returns a pointer to a read only
  11253. // CERT_CONTEXT. The returned CERT_CONTEXT is either obtained from a
  11254. // cert store or was created via CertCreateCertificateContext. For either case,
  11255. // its freed via CertFreeCertificateContext.
  11256. //
  11257. // If a valid certificate isn't found, this callback returns NULL with
  11258. // LastError set via SetLastError().
  11259. //
  11260. // The NULL implementation tries to get the Signer certificate from the
  11261. // message cert store. It doesn't verify the certificate.
  11262. //
  11263. // Note, if the KEYID choice was selected for a CMS SignerId, then, the
  11264. // SerialNumber is 0 and the Issuer is encoded containing a single RDN with a
  11265. // single Attribute whose OID is szOID_KEYID_RDN, value type is
  11266. // CERT_RDN_OCTET_STRING and value is the KEYID. When the
  11267. // CertGetSubjectCertificateFromStore and
  11268. // CertFindCertificateInStore(CERT_FIND_SUBJECT_CERT) APIs see this
  11269. // special KEYID Issuer and SerialNumber, they do a KEYID match.
  11270. //--------------------------------------------------------------------------
  11271. typedef PCCERT_CONTEXT (WINAPI *PFN_CRYPT_GET_SIGNER_CERTIFICATE)(
  11272. IN void *pvGetArg,
  11273. IN DWORD dwCertEncodingType,
  11274. IN PCERT_INFO pSignerId, // Only the Issuer and SerialNumber
  11275. // fields have been updated
  11276. IN HCERTSTORE hMsgCertStore
  11277. );
  11278. //+-------------------------------------------------------------------------
  11279. // The CRYPT_SIGN_MESSAGE_PARA are used for signing messages using the
  11280. // specified signing certificate context.
  11281. //
  11282. // Either the CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_PROV_INFO_PROP_ID must
  11283. // be set for each rgpSigningCert[]. Either one specifies the private
  11284. // signature key to use.
  11285. //
  11286. // If any certificates and/or CRLs are to be included in the signed message,
  11287. // then, the MsgCert and MsgCrl parameters need to be updated. If the
  11288. // rgpSigningCerts are to be included, then, they must also be in the
  11289. // rgpMsgCert array.
  11290. //
  11291. // cbSize must be set to the sizeof(CRYPT_SIGN_MESSAGE_PARA) or else
  11292. // LastError will be updated with E_INVALIDARG.
  11293. //
  11294. // pvHashAuxInfo currently isn't used and must be set to NULL.
  11295. //
  11296. // dwFlags normally is set to 0. However, if the encoded output
  11297. // is to be a CMSG_SIGNED inner content of an outer cryptographic message,
  11298. // such as a CMSG_ENVELOPED, then, the CRYPT_MESSAGE_BARE_CONTENT_OUT_FLAG
  11299. // should be set. If not set, then it would be encoded as an inner content
  11300. // type of CMSG_DATA.
  11301. //
  11302. // dwInnerContentType is normally set to 0. It needs to be set if the
  11303. // ToBeSigned input is the encoded output of another cryptographic
  11304. // message, such as, an CMSG_ENVELOPED. When set, it's one of the cryptographic
  11305. // message types, for example, CMSG_ENVELOPED.
  11306. //
  11307. // If the inner content of a nested cryptographic message is data (CMSG_DATA
  11308. // the default), then, neither dwFlags or dwInnerContentType need to be set.
  11309. //
  11310. // For CMS messages, CRYPT_MESSAGE_ENCAPSULATED_CONTENT_OUT_FLAG may be
  11311. // set to encapsulate nonData inner content within an OCTET STRING.
  11312. //
  11313. // For CMS messages, CRYPT_MESSAGE_KEYID_SIGNER_FLAG may be set to identify
  11314. // signers by their Key Identifier and not their Issuer and Serial Number.
  11315. //
  11316. // The CRYPT_MESSAGE_SILENT_KEYSET_FLAG can be set to suppress any UI by the
  11317. // CSP. See CryptAcquireContext's CRYPT_SILENT flag for more details.
  11318. //
  11319. // If HashEncryptionAlgorithm is present and not NULL its used instead of
  11320. // the SigningCert's PublicKeyInfo.Algorithm.
  11321. //
  11322. // Note, for RSA, the hash encryption algorithm is normally the same as
  11323. // the public key algorithm. For DSA, the hash encryption algorithm is
  11324. // normally a DSS signature algorithm.
  11325. //
  11326. // pvHashEncryptionAuxInfo currently isn't used and must be set to NULL if
  11327. // present in the data structure.
  11328. //--------------------------------------------------------------------------
  11329. typedef struct _CRYPT_SIGN_MESSAGE_PARA {
  11330. DWORD cbSize;
  11331. DWORD dwMsgEncodingType;
  11332. PCCERT_CONTEXT pSigningCert;
  11333. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  11334. void *pvHashAuxInfo;
  11335. DWORD cMsgCert;
  11336. PCCERT_CONTEXT *rgpMsgCert;
  11337. DWORD cMsgCrl;
  11338. PCCRL_CONTEXT *rgpMsgCrl;
  11339. DWORD cAuthAttr;
  11340. PCRYPT_ATTRIBUTE rgAuthAttr;
  11341. DWORD cUnauthAttr;
  11342. PCRYPT_ATTRIBUTE rgUnauthAttr;
  11343. DWORD dwFlags;
  11344. DWORD dwInnerContentType;
  11345. #ifdef CRYPT_SIGN_MESSAGE_PARA_HAS_CMS_FIELDS
  11346. CRYPT_ALGORITHM_IDENTIFIER HashEncryptionAlgorithm;
  11347. void *pvHashEncryptionAuxInfo;
  11348. #endif
  11349. } CRYPT_SIGN_MESSAGE_PARA, *PCRYPT_SIGN_MESSAGE_PARA;
  11350. #define CRYPT_MESSAGE_BARE_CONTENT_OUT_FLAG 0x00000001
  11351. // When set, nonData type inner content is encapsulated within an
  11352. // OCTET STRING
  11353. #define CRYPT_MESSAGE_ENCAPSULATED_CONTENT_OUT_FLAG 0x00000002
  11354. // When set, signers are identified by their Key Identifier and not
  11355. // their Issuer and Serial Number.
  11356. #define CRYPT_MESSAGE_KEYID_SIGNER_FLAG 0x00000004
  11357. // When set, suppresses any UI by the CSP.
  11358. // See CryptAcquireContext's CRYPT_SILENT flag for more details.
  11359. #define CRYPT_MESSAGE_SILENT_KEYSET_FLAG 0x00000040
  11360. //+-------------------------------------------------------------------------
  11361. // The CRYPT_VERIFY_MESSAGE_PARA are used to verify signed messages.
  11362. //
  11363. // hCryptProv is used to do hashing and signature verification.
  11364. //
  11365. // The dwCertEncodingType specifies the encoding type of the certificates
  11366. // and/or CRLs in the message.
  11367. //
  11368. // pfnGetSignerCertificate is called to get and verify the message signer's
  11369. // certificate.
  11370. //
  11371. // cbSize must be set to the sizeof(CRYPT_VERIFY_MESSAGE_PARA) or else
  11372. // LastError will be updated with E_INVALIDARG.
  11373. //--------------------------------------------------------------------------
  11374. typedef struct _CRYPT_VERIFY_MESSAGE_PARA {
  11375. DWORD cbSize;
  11376. DWORD dwMsgAndCertEncodingType;
  11377. HCRYPTPROV hCryptProv;
  11378. PFN_CRYPT_GET_SIGNER_CERTIFICATE pfnGetSignerCertificate;
  11379. void *pvGetArg;
  11380. } CRYPT_VERIFY_MESSAGE_PARA, *PCRYPT_VERIFY_MESSAGE_PARA;
  11381. //+-------------------------------------------------------------------------
  11382. // The CRYPT_ENCRYPT_MESSAGE_PARA are used for encrypting messages.
  11383. //
  11384. // hCryptProv is used to do content encryption, recipient key
  11385. // encryption, and recipient key export. Its private key
  11386. // isn't used.
  11387. //
  11388. // Currently, pvEncryptionAuxInfo is only defined for RC2 or RC4 encryption
  11389. // algorithms. Otherwise, its not used and must be set to NULL.
  11390. // See CMSG_RC2_AUX_INFO for the RC2 encryption algorithms.
  11391. // See CMSG_RC4_AUX_INFO for the RC4 encryption algorithms.
  11392. //
  11393. // To enable SP3 compatible encryption, pvEncryptionAuxInfo should point to
  11394. // a CMSG_SP3_COMPATIBLE_AUX_INFO data structure.
  11395. //
  11396. // cbSize must be set to the sizeof(CRYPT_ENCRYPT_MESSAGE_PARA) or else
  11397. // LastError will be updated with E_INVALIDARG.
  11398. //
  11399. // dwFlags normally is set to 0. However, if the encoded output
  11400. // is to be a CMSG_ENVELOPED inner content of an outer cryptographic message,
  11401. // such as a CMSG_SIGNED, then, the CRYPT_MESSAGE_BARE_CONTENT_OUT_FLAG
  11402. // should be set. If not set, then it would be encoded as an inner content
  11403. // type of CMSG_DATA.
  11404. //
  11405. // dwInnerContentType is normally set to 0. It needs to be set if the
  11406. // ToBeEncrypted input is the encoded output of another cryptographic
  11407. // message, such as, an CMSG_SIGNED. When set, it's one of the cryptographic
  11408. // message types, for example, CMSG_SIGNED.
  11409. //
  11410. // If the inner content of a nested cryptographic message is data (CMSG_DATA
  11411. // the default), then, neither dwFlags or dwInnerContentType need to be set.
  11412. //
  11413. // For CMS messages, CRYPT_MESSAGE_ENCAPSULATED_CONTENT_OUT_FLAG may be
  11414. // set to encapsulate nonData inner content within an OCTET STRING before
  11415. // encrypting.
  11416. //
  11417. // For CMS messages, CRYPT_MESSAGE_KEYID_RECIPIENT_FLAG may be set to identify
  11418. // recipients by their Key Identifier and not their Issuer and Serial Number.
  11419. //--------------------------------------------------------------------------
  11420. typedef struct _CRYPT_ENCRYPT_MESSAGE_PARA {
  11421. DWORD cbSize;
  11422. DWORD dwMsgEncodingType;
  11423. HCRYPTPROV hCryptProv;
  11424. CRYPT_ALGORITHM_IDENTIFIER ContentEncryptionAlgorithm;
  11425. void *pvEncryptionAuxInfo;
  11426. DWORD dwFlags;
  11427. DWORD dwInnerContentType;
  11428. } CRYPT_ENCRYPT_MESSAGE_PARA, *PCRYPT_ENCRYPT_MESSAGE_PARA;
  11429. // When set, recipients are identified by their Key Identifier and not
  11430. // their Issuer and Serial Number.
  11431. #define CRYPT_MESSAGE_KEYID_RECIPIENT_FLAG 0x4
  11432. //+-------------------------------------------------------------------------
  11433. // The CRYPT_DECRYPT_MESSAGE_PARA are used for decrypting messages.
  11434. //
  11435. // The CertContext to use for decrypting a message is obtained from one
  11436. // of the specified cert stores. An encrypted message can have one or
  11437. // more recipients. The recipients are identified by their CertId (Issuer
  11438. // and SerialNumber). The cert stores are searched to find the CertContext
  11439. // corresponding to the CertId.
  11440. //
  11441. // For CMS, the recipients may also be identified by their KeyId.
  11442. // CMS also allows Key Agreement (Diffie Hellman) in addition to
  11443. // Key Transport (RSA) recipients.
  11444. //
  11445. // Only CertContexts in the store with either
  11446. // the CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_PROV_INFO_PROP_ID set
  11447. // can be used. Either property specifies the private exchange key to use.
  11448. //
  11449. // cbSize must be set to the sizeof(CRYPT_DECRYPT_MESSAGE_PARA) or else
  11450. // LastError will be updated with E_INVALIDARG.
  11451. //--------------------------------------------------------------------------
  11452. typedef struct _CRYPT_DECRYPT_MESSAGE_PARA {
  11453. DWORD cbSize;
  11454. DWORD dwMsgAndCertEncodingType;
  11455. DWORD cCertStore;
  11456. HCERTSTORE *rghCertStore;
  11457. #ifdef CRYPT_DECRYPT_MESSAGE_PARA_HAS_EXTRA_FIELDS
  11458. // The above defined, CRYPT_MESSAGE_SILENT_KEYSET_FLAG, can be set to
  11459. // suppress UI by the CSP. See CryptAcquireContext's CRYPT_SILENT
  11460. // flag for more details.
  11461. DWORD dwFlags;
  11462. #endif
  11463. } CRYPT_DECRYPT_MESSAGE_PARA, *PCRYPT_DECRYPT_MESSAGE_PARA;
  11464. //+-------------------------------------------------------------------------
  11465. // The CRYPT_HASH_MESSAGE_PARA are used for hashing or unhashing
  11466. // messages.
  11467. //
  11468. // hCryptProv is used to compute the hash.
  11469. //
  11470. // pvHashAuxInfo currently isn't used and must be set to NULL.
  11471. //
  11472. // cbSize must be set to the sizeof(CRYPT_HASH_MESSAGE_PARA) or else
  11473. // LastError will be updated with E_INVALIDARG.
  11474. //--------------------------------------------------------------------------
  11475. typedef struct _CRYPT_HASH_MESSAGE_PARA {
  11476. DWORD cbSize;
  11477. DWORD dwMsgEncodingType;
  11478. HCRYPTPROV hCryptProv;
  11479. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  11480. void *pvHashAuxInfo;
  11481. } CRYPT_HASH_MESSAGE_PARA, *PCRYPT_HASH_MESSAGE_PARA;
  11482. //+-------------------------------------------------------------------------
  11483. // The CRYPT_KEY_SIGN_MESSAGE_PARA are used for signing messages until a
  11484. // certificate has been created for the signature key.
  11485. //
  11486. // pvHashAuxInfo currently isn't used and must be set to NULL.
  11487. //
  11488. // If PubKeyAlgorithm isn't set, defaults to szOID_RSA_RSA.
  11489. //
  11490. // cbSize must be set to the sizeof(CRYPT_KEY_SIGN_MESSAGE_PARA) or else
  11491. // LastError will be updated with E_INVALIDARG.
  11492. //--------------------------------------------------------------------------
  11493. typedef struct _CRYPT_KEY_SIGN_MESSAGE_PARA {
  11494. DWORD cbSize;
  11495. DWORD dwMsgAndCertEncodingType;
  11496. HCRYPTPROV hCryptProv;
  11497. DWORD dwKeySpec;
  11498. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  11499. void *pvHashAuxInfo;
  11500. CRYPT_ALGORITHM_IDENTIFIER PubKeyAlgorithm;
  11501. } CRYPT_KEY_SIGN_MESSAGE_PARA, *PCRYPT_KEY_SIGN_MESSAGE_PARA;
  11502. //+-------------------------------------------------------------------------
  11503. // The CRYPT_KEY_VERIFY_MESSAGE_PARA are used to verify signed messages without
  11504. // a certificate for the signer.
  11505. //
  11506. // Normally used until a certificate has been created for the key.
  11507. //
  11508. // hCryptProv is used to do hashing and signature verification.
  11509. //
  11510. // cbSize must be set to the sizeof(CRYPT_KEY_VERIFY_MESSAGE_PARA) or else
  11511. // LastError will be updated with E_INVALIDARG.
  11512. //--------------------------------------------------------------------------
  11513. typedef struct _CRYPT_KEY_VERIFY_MESSAGE_PARA {
  11514. DWORD cbSize;
  11515. DWORD dwMsgEncodingType;
  11516. HCRYPTPROV hCryptProv;
  11517. } CRYPT_KEY_VERIFY_MESSAGE_PARA, *PCRYPT_KEY_VERIFY_MESSAGE_PARA;
  11518. //+-------------------------------------------------------------------------
  11519. // Sign the message.
  11520. //
  11521. // If fDetachedSignature is TRUE, the "to be signed" content isn't included
  11522. // in the encoded signed blob.
  11523. //--------------------------------------------------------------------------
  11524. WINCRYPT32API
  11525. BOOL
  11526. WINAPI
  11527. CryptSignMessage(
  11528. IN PCRYPT_SIGN_MESSAGE_PARA pSignPara,
  11529. IN BOOL fDetachedSignature,
  11530. IN DWORD cToBeSigned,
  11531. IN const BYTE *rgpbToBeSigned[],
  11532. IN DWORD rgcbToBeSigned[],
  11533. OUT BYTE *pbSignedBlob,
  11534. IN OUT DWORD *pcbSignedBlob
  11535. );
  11536. //+-------------------------------------------------------------------------
  11537. // Verify a signed message.
  11538. //
  11539. // If pbDecoded == NULL, then, *pcbDecoded is implicitly set to 0 on input.
  11540. // For *pcbDecoded == 0 && ppSignerCert == NULL on input, the signer isn't
  11541. // verified.
  11542. //
  11543. // A message might have more than one signer. Set dwSignerIndex to iterate
  11544. // through all the signers. dwSignerIndex == 0 selects the first signer.
  11545. //
  11546. // pVerifyPara's pfnGetSignerCertificate is called to get the signer's
  11547. // certificate.
  11548. //
  11549. // For a verified signer and message, *ppSignerCert is updated
  11550. // with the CertContext of the signer. It must be freed by calling
  11551. // CertFreeCertificateContext. Otherwise, *ppSignerCert is set to NULL.
  11552. //
  11553. // ppSignerCert can be NULL, indicating the caller isn't interested
  11554. // in getting the CertContext of the signer.
  11555. //
  11556. // pcbDecoded can be NULL, indicating the caller isn't interested in getting
  11557. // the decoded content. Furthermore, if the message doesn't contain any
  11558. // content or signers, then, pcbDecoded must be set to NULL, to allow the
  11559. // pVerifyPara->pfnGetCertificate to be called. Normally, this would be
  11560. // the case when the signed message contains only certficates and CRLs.
  11561. // If pcbDecoded is NULL and the message doesn't have the indicated signer,
  11562. // pfnGetCertificate is called with pSignerId set to NULL.
  11563. //
  11564. // If the message doesn't contain any signers || dwSignerIndex > message's
  11565. // SignerCount, then, an error is returned with LastError set to
  11566. // CRYPT_E_NO_SIGNER. Also, for CRYPT_E_NO_SIGNER, pfnGetSignerCertificate
  11567. // is still called with pSignerId set to NULL.
  11568. //
  11569. // Note, an alternative way to get the certificates and CRLs from a
  11570. // signed message is to call CryptGetMessageCertificates.
  11571. //--------------------------------------------------------------------------
  11572. WINCRYPT32API
  11573. BOOL
  11574. WINAPI
  11575. CryptVerifyMessageSignature(
  11576. IN PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara,
  11577. IN DWORD dwSignerIndex,
  11578. IN const BYTE *pbSignedBlob,
  11579. IN DWORD cbSignedBlob,
  11580. OUT BYTE OPTIONAL *pbDecoded,
  11581. IN OUT OPTIONAL DWORD *pcbDecoded,
  11582. OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert
  11583. );
  11584. //+-------------------------------------------------------------------------
  11585. // Returns the count of signers in the signed message. For no signers, returns
  11586. // 0. For an error returns -1 with LastError updated accordingly.
  11587. //--------------------------------------------------------------------------
  11588. WINCRYPT32API
  11589. LONG
  11590. WINAPI
  11591. CryptGetMessageSignerCount(
  11592. IN DWORD dwMsgEncodingType,
  11593. IN const BYTE *pbSignedBlob,
  11594. IN DWORD cbSignedBlob
  11595. );
  11596. //+-------------------------------------------------------------------------
  11597. // Returns the cert store containing the message's certs and CRLs.
  11598. // For an error, returns NULL with LastError updated.
  11599. //--------------------------------------------------------------------------
  11600. WINCRYPT32API
  11601. HCERTSTORE
  11602. WINAPI
  11603. CryptGetMessageCertificates(
  11604. IN DWORD dwMsgAndCertEncodingType,
  11605. IN HCRYPTPROV hCryptProv, // passed to CertOpenStore
  11606. IN DWORD dwFlags, // passed to CertOpenStore
  11607. IN const BYTE *pbSignedBlob,
  11608. IN DWORD cbSignedBlob
  11609. );
  11610. //+-------------------------------------------------------------------------
  11611. // Verify a signed message containing detached signature(s).
  11612. // The "to be signed" content is passed in separately. No
  11613. // decoded output. Otherwise, identical to CryptVerifyMessageSignature.
  11614. //--------------------------------------------------------------------------
  11615. WINCRYPT32API
  11616. BOOL
  11617. WINAPI
  11618. CryptVerifyDetachedMessageSignature(
  11619. IN PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara,
  11620. IN DWORD dwSignerIndex,
  11621. IN const BYTE *pbDetachedSignBlob,
  11622. IN DWORD cbDetachedSignBlob,
  11623. IN DWORD cToBeSigned,
  11624. IN const BYTE *rgpbToBeSigned[],
  11625. IN DWORD rgcbToBeSigned[],
  11626. OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert
  11627. );
  11628. //+-------------------------------------------------------------------------
  11629. // Encrypts the message for the recipient(s).
  11630. //--------------------------------------------------------------------------
  11631. WINCRYPT32API
  11632. BOOL
  11633. WINAPI
  11634. CryptEncryptMessage(
  11635. IN PCRYPT_ENCRYPT_MESSAGE_PARA pEncryptPara,
  11636. IN DWORD cRecipientCert,
  11637. IN PCCERT_CONTEXT rgpRecipientCert[],
  11638. IN const BYTE *pbToBeEncrypted,
  11639. IN DWORD cbToBeEncrypted,
  11640. OUT BYTE *pbEncryptedBlob,
  11641. IN OUT DWORD *pcbEncryptedBlob
  11642. );
  11643. //+-------------------------------------------------------------------------
  11644. // Decrypts the message.
  11645. //
  11646. // If pbDecrypted == NULL, then, *pcbDecrypted is implicitly set to 0 on input.
  11647. // For *pcbDecrypted == 0 && ppXchgCert == NULL on input, the message isn't
  11648. // decrypted.
  11649. //
  11650. // For a successfully decrypted message, *ppXchgCert is updated
  11651. // with the CertContext used to decrypt. It must be freed by calling
  11652. // CertStoreFreeCert. Otherwise, *ppXchgCert is set to NULL.
  11653. //
  11654. // ppXchgCert can be NULL, indicating the caller isn't interested
  11655. // in getting the CertContext used to decrypt.
  11656. //--------------------------------------------------------------------------
  11657. WINCRYPT32API
  11658. BOOL
  11659. WINAPI
  11660. CryptDecryptMessage(
  11661. IN PCRYPT_DECRYPT_MESSAGE_PARA pDecryptPara,
  11662. IN const BYTE *pbEncryptedBlob,
  11663. IN DWORD cbEncryptedBlob,
  11664. OUT OPTIONAL BYTE *pbDecrypted,
  11665. IN OUT OPTIONAL DWORD *pcbDecrypted,
  11666. OUT OPTIONAL PCCERT_CONTEXT *ppXchgCert
  11667. );
  11668. //+-------------------------------------------------------------------------
  11669. // Sign the message and encrypt for the recipient(s). Does a CryptSignMessage
  11670. // followed with a CryptEncryptMessage.
  11671. //
  11672. // Note: this isn't the CMSG_SIGNED_AND_ENVELOPED. Its a CMSG_SIGNED
  11673. // inside of an CMSG_ENVELOPED.
  11674. //--------------------------------------------------------------------------
  11675. WINCRYPT32API
  11676. BOOL
  11677. WINAPI
  11678. CryptSignAndEncryptMessage(
  11679. IN PCRYPT_SIGN_MESSAGE_PARA pSignPara,
  11680. IN PCRYPT_ENCRYPT_MESSAGE_PARA pEncryptPara,
  11681. IN DWORD cRecipientCert,
  11682. IN PCCERT_CONTEXT rgpRecipientCert[],
  11683. IN const BYTE *pbToBeSignedAndEncrypted,
  11684. IN DWORD cbToBeSignedAndEncrypted,
  11685. OUT BYTE *pbSignedAndEncryptedBlob,
  11686. IN OUT DWORD *pcbSignedAndEncryptedBlob
  11687. );
  11688. //+-------------------------------------------------------------------------
  11689. // Decrypts the message and verifies the signer. Does a CryptDecryptMessage
  11690. // followed with a CryptVerifyMessageSignature.
  11691. //
  11692. // If pbDecrypted == NULL, then, *pcbDecrypted is implicitly set to 0 on input.
  11693. // For *pcbDecrypted == 0 && ppSignerCert == NULL on input, the signer isn't
  11694. // verified.
  11695. //
  11696. // A message might have more than one signer. Set dwSignerIndex to iterate
  11697. // through all the signers. dwSignerIndex == 0 selects the first signer.
  11698. //
  11699. // The pVerifyPara's VerifySignerPolicy is called to verify the signer's
  11700. // certificate.
  11701. //
  11702. // For a successfully decrypted and verified message, *ppXchgCert and
  11703. // *ppSignerCert are updated. They must be freed by calling
  11704. // CertStoreFreeCert. Otherwise, they are set to NULL.
  11705. //
  11706. // ppXchgCert and/or ppSignerCert can be NULL, indicating the
  11707. // caller isn't interested in getting the CertContext.
  11708. //
  11709. // Note: this isn't the CMSG_SIGNED_AND_ENVELOPED. Its a CMSG_SIGNED
  11710. // inside of an CMSG_ENVELOPED.
  11711. //
  11712. // The message always needs to be decrypted to allow access to the
  11713. // signed message. Therefore, if ppXchgCert != NULL, its always updated.
  11714. //--------------------------------------------------------------------------
  11715. WINCRYPT32API
  11716. BOOL
  11717. WINAPI
  11718. CryptDecryptAndVerifyMessageSignature(
  11719. IN PCRYPT_DECRYPT_MESSAGE_PARA pDecryptPara,
  11720. IN PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara,
  11721. IN DWORD dwSignerIndex,
  11722. IN const BYTE *pbEncryptedBlob,
  11723. IN DWORD cbEncryptedBlob,
  11724. OUT OPTIONAL BYTE *pbDecrypted,
  11725. IN OUT OPTIONAL DWORD *pcbDecrypted,
  11726. OUT OPTIONAL PCCERT_CONTEXT *ppXchgCert,
  11727. OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert
  11728. );
  11729. //+-------------------------------------------------------------------------
  11730. // Decodes a cryptographic message which may be one of the following types:
  11731. // CMSG_DATA
  11732. // CMSG_SIGNED
  11733. // CMSG_ENVELOPED
  11734. // CMSG_SIGNED_AND_ENVELOPED
  11735. // CMSG_HASHED
  11736. //
  11737. // dwMsgTypeFlags specifies the set of allowable messages. For example, to
  11738. // decode either SIGNED or ENVELOPED messages, set dwMsgTypeFlags to:
  11739. // CMSG_SIGNED_FLAG | CMSG_ENVELOPED_FLAG.
  11740. //
  11741. // dwProvInnerContentType is only applicable when processing nested
  11742. // crytographic messages. When processing an outer crytographic message
  11743. // it must be set to 0. When decoding a nested cryptographic message
  11744. // its the dwInnerContentType returned by a previous CryptDecodeMessage
  11745. // of the outer message. The InnerContentType can be any of the CMSG types,
  11746. // for example, CMSG_DATA, CMSG_SIGNED, ...
  11747. //
  11748. // The optional *pdwMsgType is updated with the type of message.
  11749. //
  11750. // The optional *pdwInnerContentType is updated with the type of the inner
  11751. // message. Unless there is cryptographic message nesting, CMSG_DATA
  11752. // is returned.
  11753. //
  11754. // For CMSG_DATA: returns decoded content.
  11755. // For CMSG_SIGNED: same as CryptVerifyMessageSignature.
  11756. // For CMSG_ENVELOPED: same as CryptDecryptMessage.
  11757. // For CMSG_SIGNED_AND_ENVELOPED: same as CryptDecryptMessage plus
  11758. // CryptVerifyMessageSignature.
  11759. // For CMSG_HASHED: verifies the hash and returns decoded content.
  11760. //--------------------------------------------------------------------------
  11761. WINCRYPT32API
  11762. BOOL
  11763. WINAPI
  11764. CryptDecodeMessage(
  11765. IN DWORD dwMsgTypeFlags,
  11766. IN PCRYPT_DECRYPT_MESSAGE_PARA pDecryptPara,
  11767. IN PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara,
  11768. IN DWORD dwSignerIndex,
  11769. IN const BYTE *pbEncodedBlob,
  11770. IN DWORD cbEncodedBlob,
  11771. IN DWORD dwPrevInnerContentType,
  11772. OUT OPTIONAL DWORD *pdwMsgType,
  11773. OUT OPTIONAL DWORD *pdwInnerContentType,
  11774. OUT OPTIONAL BYTE *pbDecoded,
  11775. IN OUT OPTIONAL DWORD *pcbDecoded,
  11776. OUT OPTIONAL PCCERT_CONTEXT *ppXchgCert,
  11777. OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert
  11778. );
  11779. //+-------------------------------------------------------------------------
  11780. // Hash the message.
  11781. //
  11782. // If fDetachedHash is TRUE, only the ComputedHash is encoded in the
  11783. // pbHashedBlob. Otherwise, both the ToBeHashed and ComputedHash
  11784. // are encoded.
  11785. //
  11786. // pcbHashedBlob or pcbComputedHash can be NULL, indicating the caller
  11787. // isn't interested in getting the output.
  11788. //--------------------------------------------------------------------------
  11789. WINCRYPT32API
  11790. BOOL
  11791. WINAPI
  11792. CryptHashMessage(
  11793. IN PCRYPT_HASH_MESSAGE_PARA pHashPara,
  11794. IN BOOL fDetachedHash,
  11795. IN DWORD cToBeHashed,
  11796. IN const BYTE *rgpbToBeHashed[],
  11797. IN DWORD rgcbToBeHashed[],
  11798. OUT OPTIONAL BYTE *pbHashedBlob,
  11799. IN OUT OPTIONAL DWORD *pcbHashedBlob,
  11800. OUT OPTIONAL BYTE *pbComputedHash,
  11801. IN OUT OPTIONAL DWORD *pcbComputedHash
  11802. );
  11803. //+-------------------------------------------------------------------------
  11804. // Verify a hashed message.
  11805. //
  11806. // pcbToBeHashed or pcbComputedHash can be NULL,
  11807. // indicating the caller isn't interested in getting the output.
  11808. //--------------------------------------------------------------------------
  11809. WINCRYPT32API
  11810. BOOL
  11811. WINAPI
  11812. CryptVerifyMessageHash(
  11813. IN PCRYPT_HASH_MESSAGE_PARA pHashPara,
  11814. IN BYTE *pbHashedBlob,
  11815. IN DWORD cbHashedBlob,
  11816. OUT OPTIONAL BYTE *pbToBeHashed,
  11817. IN OUT OPTIONAL DWORD *pcbToBeHashed,
  11818. OUT OPTIONAL BYTE *pbComputedHash,
  11819. IN OUT OPTIONAL DWORD *pcbComputedHash
  11820. );
  11821. //+-------------------------------------------------------------------------
  11822. // Verify a hashed message containing a detached hash.
  11823. // The "to be hashed" content is passed in separately. No
  11824. // decoded output. Otherwise, identical to CryptVerifyMessageHash.
  11825. //
  11826. // pcbComputedHash can be NULL, indicating the caller isn't interested
  11827. // in getting the output.
  11828. //--------------------------------------------------------------------------
  11829. WINCRYPT32API
  11830. BOOL
  11831. WINAPI
  11832. CryptVerifyDetachedMessageHash(
  11833. IN PCRYPT_HASH_MESSAGE_PARA pHashPara,
  11834. IN BYTE *pbDetachedHashBlob,
  11835. IN DWORD cbDetachedHashBlob,
  11836. IN DWORD cToBeHashed,
  11837. IN const BYTE *rgpbToBeHashed[],
  11838. IN DWORD rgcbToBeHashed[],
  11839. OUT OPTIONAL BYTE *pbComputedHash,
  11840. IN OUT OPTIONAL DWORD *pcbComputedHash
  11841. );
  11842. //+-------------------------------------------------------------------------
  11843. // Sign the message using the provider's private key specified in the
  11844. // parameters. A dummy SignerId is created and stored in the message.
  11845. //
  11846. // Normally used until a certificate has been created for the key.
  11847. //--------------------------------------------------------------------------
  11848. WINCRYPT32API
  11849. BOOL
  11850. WINAPI
  11851. CryptSignMessageWithKey(
  11852. IN PCRYPT_KEY_SIGN_MESSAGE_PARA pSignPara,
  11853. IN const BYTE *pbToBeSigned,
  11854. IN DWORD cbToBeSigned,
  11855. OUT BYTE *pbSignedBlob,
  11856. IN OUT DWORD *pcbSignedBlob
  11857. );
  11858. //+-------------------------------------------------------------------------
  11859. // Verify a signed message using the specified public key info.
  11860. //
  11861. // Normally called by a CA until it has created a certificate for the
  11862. // key.
  11863. //
  11864. // pPublicKeyInfo contains the public key to use to verify the signed
  11865. // message. If NULL, the signature isn't verified (for instance, the decoded
  11866. // content may contain the PublicKeyInfo).
  11867. //
  11868. // pcbDecoded can be NULL, indicating the caller isn't interested
  11869. // in getting the decoded content.
  11870. //--------------------------------------------------------------------------
  11871. WINCRYPT32API
  11872. BOOL
  11873. WINAPI
  11874. CryptVerifyMessageSignatureWithKey(
  11875. IN PCRYPT_KEY_VERIFY_MESSAGE_PARA pVerifyPara,
  11876. IN OPTIONAL PCERT_PUBLIC_KEY_INFO pPublicKeyInfo,
  11877. IN const BYTE *pbSignedBlob,
  11878. IN DWORD cbSignedBlob,
  11879. OUT OPTIONAL BYTE *pbDecoded,
  11880. IN OUT OPTIONAL DWORD *pcbDecoded
  11881. );
  11882. //+=========================================================================
  11883. // System Certificate Store Data Structures and APIs
  11884. //==========================================================================
  11885. //+-------------------------------------------------------------------------
  11886. // Get a system certificate store based on a subsystem protocol.
  11887. //
  11888. // Current examples of subsystems protocols are:
  11889. // "MY" Cert Store hold certs with associated Private Keys
  11890. // "CA" Certifying Authority certs
  11891. // "ROOT" Root Certs
  11892. // "SPC" Software publisher certs
  11893. //
  11894. //
  11895. // If hProv is NULL the default provider "1" is opened for you.
  11896. // When the store is closed the provider is release. Otherwise
  11897. // if hProv is not NULL, no provider is created or released.
  11898. //
  11899. // The returned Cert Store can be searched for an appropriate Cert
  11900. // using the Cert Store API's (see certstor.h)
  11901. //
  11902. // When done, the cert store should be closed using CertStoreClose
  11903. //--------------------------------------------------------------------------
  11904. WINCRYPT32API
  11905. HCERTSTORE
  11906. WINAPI
  11907. CertOpenSystemStore%(
  11908. HCRYPTPROV hProv,
  11909. LPCTSTR% szSubsystemProtocol
  11910. );
  11911. WINCRYPT32API
  11912. BOOL
  11913. WINAPI
  11914. CertAddEncodedCertificateToSystemStore%(
  11915. LPCTSTR% szCertStoreName,
  11916. const BYTE * pbCertEncoded,
  11917. DWORD cbCertEncoded
  11918. );
  11919. //+-------------------------------------------------------------------------
  11920. // Find all certificate chains tying the given issuer name to any certificate
  11921. // that the current user has a private key for.
  11922. //
  11923. // If no certificate chain is found, FALSE is returned with LastError set
  11924. // to CRYPT_E_NOT_FOUND and the counts zeroed.
  11925. //
  11926. // IE 3.0 ASSUMPTION:
  11927. // The client certificates are in the "My" system store. The issuer
  11928. // cerificates may be in the "Root", "CA" or "My" system stores.
  11929. //--------------------------------------------------------------------------
  11930. typedef struct _CERT_CHAIN {
  11931. DWORD cCerts; // number of certs in chain
  11932. PCERT_BLOB certs; // pointer to array of cert chain blobs
  11933. // representing the certs
  11934. CRYPT_KEY_PROV_INFO keyLocatorInfo; // key locator for cert
  11935. } CERT_CHAIN, *PCERT_CHAIN;
  11936. // WINCRYPT32API This is not exported by crypt32, it is exported by softpub
  11937. HRESULT
  11938. WINAPI
  11939. FindCertsByIssuer(
  11940. OUT PCERT_CHAIN pCertChains,
  11941. IN OUT DWORD *pcbCertChains,
  11942. OUT DWORD *pcCertChains, // count of certificates chains returned
  11943. IN BYTE* pbEncodedIssuerName, // DER encoded issuer name
  11944. IN DWORD cbEncodedIssuerName, // count in bytes of encoded issuer name
  11945. IN LPCWSTR pwszPurpose, // "ClientAuth" or "CodeSigning"
  11946. IN DWORD dwKeySpec // only return signers supporting this
  11947. // keyspec
  11948. );
  11949. //-------------------------------------------------------------------------
  11950. //
  11951. // CryptQueryObject takes a CERT_BLOB or a file name and returns the
  11952. // information about the content in the blob or in the file.
  11953. //
  11954. // Parameters:
  11955. // INPUT dwObjectType:
  11956. // Indicate the type of the object. Should be one of the
  11957. // following:
  11958. // CERT_QUERY_OBJECT_FILE
  11959. // CERT_QUERY_OBJECT_BLOB
  11960. //
  11961. // INPUT pvObject:
  11962. // If dwObjectType == CERT_QUERY_OBJECT_FILE, it is a
  11963. // LPWSTR, that is, the pointer to a wchar file name
  11964. // if dwObjectType == CERT_QUERY_OBJECT_BLOB, it is a
  11965. // PCERT_BLOB, that is, a pointer to a CERT_BLOB
  11966. //
  11967. // INPUT dwExpectedContentTypeFlags:
  11968. // Indicate the expected contenet type.
  11969. // Can be one of the following:
  11970. // CERT_QUERY_CONTENT_FLAG_ALL (the content can be any type)
  11971. // CERT_QUERY_CONTENT_FLAG_CERT
  11972. // CERT_QUERY_CONTENT_FLAG_CTL
  11973. // CERT_QUERY_CONTENT_FLAG_CRL
  11974. // CERT_QUERY_CONTENT_FLAG_SERIALIZED_STORE
  11975. // CERT_QUERY_CONTENT_FLAG_SERIALIZED_CERT
  11976. // CERT_QUERY_CONTENT_FLAG_SERIALIZED_CTL
  11977. // CERT_QUERY_CONTENT_FLAG_SERIALIZED_CRL
  11978. // CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED
  11979. // CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED
  11980. // CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED
  11981. // CERT_QUERY_CONTENT_FLAG_PKCS10
  11982. // CERT_QUERY_CONTENT_FLAG_PFX
  11983. // CERT_QUERY_CONTENT_FLAG_CERT_PAIR
  11984. //
  11985. // INPUT dwExpectedFormatTypeFlags:
  11986. // Indicate the expected format type.
  11987. // Can be one of the following:
  11988. // CERT_QUERY_FORMAT_FLAG_ALL (the content can be any format)
  11989. // CERT_QUERY_FORMAT_FLAG_BINARY
  11990. // CERT_QUERY_FORMAT_FLAG_BASE64_ENCODED
  11991. // CERT_QUERY_FORMAT_FLAG_ASN_ASCII_HEX_ENCODED
  11992. //
  11993. //
  11994. // INPUT dwFlags
  11995. // Reserved flag. Should always set to 0
  11996. //
  11997. // OUTPUT pdwMsgAndCertEncodingType
  11998. // Optional output. If NULL != pdwMsgAndCertEncodingType,
  11999. // it contains the encoding type of the content as any
  12000. // combination of the following:
  12001. // X509_ASN_ENCODING
  12002. // PKCS_7_ASN_ENCODING
  12003. //
  12004. // OUTPUT pdwContentType
  12005. // Optional output. If NULL!=pdwContentType, it contains
  12006. // the content type as one of the the following:
  12007. // CERT_QUERY_CONTENT_CERT
  12008. // CERT_QUERY_CONTENT_CTL
  12009. // CERT_QUERY_CONTENT_CRL
  12010. // CERT_QUERY_CONTENT_SERIALIZED_STORE
  12011. // CERT_QUERY_CONTENT_SERIALIZED_CERT
  12012. // CERT_QUERY_CONTENT_SERIALIZED_CTL
  12013. // CERT_QUERY_CONTENT_SERIALIZED_CRL
  12014. // CERT_QUERY_CONTENT_PKCS7_SIGNED
  12015. // CERT_QUERY_CONTENT_PKCS7_UNSIGNED
  12016. // CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED
  12017. // CERT_QUERY_CONTENT_PKCS10
  12018. // CERT_QUERY_CONTENT_PFX
  12019. // CERT_QUERY_CONTENT_CERT_PAIR
  12020. //
  12021. // OUTPUT pdwFormatType
  12022. // Optional output. If NULL !=pdwFormatType, it
  12023. // contains the format type of the content as one of the
  12024. // following:
  12025. // CERT_QUERY_FORMAT_BINARY
  12026. // CERT_QUERY_FORMAT_BASE64_ENCODED
  12027. // CERT_QUERY_FORMAT_ASN_ASCII_HEX_ENCODED
  12028. //
  12029. //
  12030. // OUTPUT phCertStore
  12031. // Optional output. If NULL !=phStore,
  12032. // it contains a cert store that includes all of certificates,
  12033. // CRL, and CTL in the object if the object content type is
  12034. // one of the following:
  12035. // CERT_QUERY_CONTENT_CERT
  12036. // CERT_QUERY_CONTENT_CTL
  12037. // CERT_QUERY_CONTENT_CRL
  12038. // CERT_QUERY_CONTENT_SERIALIZED_STORE
  12039. // CERT_QUERY_CONTENT_SERIALIZED_CERT
  12040. // CERT_QUERY_CONTENT_SERIALIZED_CTL
  12041. // CERT_QUERY_CONTENT_SERIALIZED_CRL
  12042. // CERT_QUERY_CONTENT_PKCS7_SIGNED
  12043. // CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED
  12044. // CERT_QUERY_CONTENT_CERT_PAIR
  12045. //
  12046. // Caller should free *phCertStore via CertCloseStore.
  12047. //
  12048. //
  12049. // OUTPUT phMsg Optional output. If NULL != phMsg,
  12050. // it contains a handle to a opened message if
  12051. // the content type is one of the following:
  12052. // CERT_QUERY_CONTENT_PKCS7_SIGNED
  12053. // CERT_QUERY_CONTENT_PKCS7_UNSIGNED
  12054. // CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED
  12055. //
  12056. // Caller should free *phMsg via CryptMsgClose.
  12057. //
  12058. // OUTPUT pContext Optional output. If NULL != pContext,
  12059. // it contains either a PCCERT_CONTEXT or PCCRL_CONTEXT,
  12060. // or PCCTL_CONTEXT based on the content type.
  12061. //
  12062. // If the content type is CERT_QUERY_CONTENT_CERT or
  12063. // CERT_QUERY_CONTENT_SERIALIZED_CERT, it is a PCCERT_CONTEXT;
  12064. // Caller should free the pContext via CertFreeCertificateContext.
  12065. //
  12066. // If the content type is CERT_QUERY_CONTENT_CRL or
  12067. // CERT_QUERY_CONTENT_SERIALIZED_CRL, it is a PCCRL_CONTEXT;
  12068. // Caller should free the pContext via CertFreeCRLContext.
  12069. //
  12070. // If the content type is CERT_QUERY_CONTENT_CTL or
  12071. // CERT_QUERY_CONTENT_SERIALIZED_CTL, it is a PCCTL_CONTEXT;
  12072. // Caller should free the pContext via CertFreeCTLContext.
  12073. //
  12074. // If the *pbObject is of type CERT_QUERY_CONTENT_PKCS10 or CERT_QUERY_CONTENT_PFX, CryptQueryObject
  12075. // will not return anything in *phCertstore, *phMsg, or *ppvContext.
  12076. //--------------------------------------------------------------------------
  12077. WINCRYPT32API
  12078. BOOL
  12079. WINAPI
  12080. CryptQueryObject(
  12081. DWORD dwObjectType,
  12082. const void *pvObject,
  12083. DWORD dwExpectedContentTypeFlags,
  12084. DWORD dwExpectedFormatTypeFlags,
  12085. DWORD dwFlags,
  12086. DWORD *pdwMsgAndCertEncodingType,
  12087. DWORD *pdwContentType,
  12088. DWORD *pdwFormatType,
  12089. HCERTSTORE *phCertStore,
  12090. HCRYPTMSG *phMsg,
  12091. const void **ppvContext
  12092. );
  12093. //-------------------------------------------------------------------------
  12094. //dwObjectType for CryptQueryObject
  12095. //-------------------------------------------------------------------------
  12096. #define CERT_QUERY_OBJECT_FILE 0x00000001
  12097. #define CERT_QUERY_OBJECT_BLOB 0x00000002
  12098. //-------------------------------------------------------------------------
  12099. //dwContentType for CryptQueryObject
  12100. //-------------------------------------------------------------------------
  12101. //encoded single certificate
  12102. #define CERT_QUERY_CONTENT_CERT 1
  12103. //encoded single CTL
  12104. #define CERT_QUERY_CONTENT_CTL 2
  12105. //encoded single CRL
  12106. #define CERT_QUERY_CONTENT_CRL 3
  12107. //serialized store
  12108. #define CERT_QUERY_CONTENT_SERIALIZED_STORE 4
  12109. //serialized single certificate
  12110. #define CERT_QUERY_CONTENT_SERIALIZED_CERT 5
  12111. //serialized single CTL
  12112. #define CERT_QUERY_CONTENT_SERIALIZED_CTL 6
  12113. //serialized single CRL
  12114. #define CERT_QUERY_CONTENT_SERIALIZED_CRL 7
  12115. //a PKCS#7 signed message
  12116. #define CERT_QUERY_CONTENT_PKCS7_SIGNED 8
  12117. //a PKCS#7 message, such as enveloped message. But it is not a signed message,
  12118. #define CERT_QUERY_CONTENT_PKCS7_UNSIGNED 9
  12119. //a PKCS7 signed message embedded in a file
  12120. #define CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED 10
  12121. //an encoded PKCS#10
  12122. #define CERT_QUERY_CONTENT_PKCS10 11
  12123. //an encoded PKX BLOB
  12124. #define CERT_QUERY_CONTENT_PFX 12
  12125. //an encoded CertificatePair (contains forward and/or reverse cross certs)
  12126. #define CERT_QUERY_CONTENT_CERT_PAIR 13
  12127. //-------------------------------------------------------------------------
  12128. //dwExpectedConentTypeFlags for CryptQueryObject
  12129. //-------------------------------------------------------------------------
  12130. //encoded single certificate
  12131. #define CERT_QUERY_CONTENT_FLAG_CERT \
  12132. ( 1 << CERT_QUERY_CONTENT_CERT)
  12133. //encoded single CTL
  12134. #define CERT_QUERY_CONTENT_FLAG_CTL \
  12135. ( 1 << CERT_QUERY_CONTENT_CTL)
  12136. //encoded single CRL
  12137. #define CERT_QUERY_CONTENT_FLAG_CRL \
  12138. ( 1 << CERT_QUERY_CONTENT_CRL)
  12139. //serialized store
  12140. #define CERT_QUERY_CONTENT_FLAG_SERIALIZED_STORE \
  12141. ( 1 << CERT_QUERY_CONTENT_SERIALIZED_STORE)
  12142. //serialized single certificate
  12143. #define CERT_QUERY_CONTENT_FLAG_SERIALIZED_CERT \
  12144. ( 1 << CERT_QUERY_CONTENT_SERIALIZED_CERT)
  12145. //serialized single CTL
  12146. #define CERT_QUERY_CONTENT_FLAG_SERIALIZED_CTL \
  12147. ( 1 << CERT_QUERY_CONTENT_SERIALIZED_CTL)
  12148. //serialized single CRL
  12149. #define CERT_QUERY_CONTENT_FLAG_SERIALIZED_CRL \
  12150. ( 1 << CERT_QUERY_CONTENT_SERIALIZED_CRL)
  12151. //an encoded PKCS#7 signed message
  12152. #define CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED \
  12153. ( 1 << CERT_QUERY_CONTENT_PKCS7_SIGNED)
  12154. //an encoded PKCS#7 message. But it is not a signed message
  12155. #define CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED \
  12156. ( 1 << CERT_QUERY_CONTENT_PKCS7_UNSIGNED)
  12157. //the content includes an embedded PKCS7 signed message
  12158. #define CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED \
  12159. ( 1 << CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED)
  12160. //an encoded PKCS#10
  12161. #define CERT_QUERY_CONTENT_FLAG_PKCS10 \
  12162. ( 1 << CERT_QUERY_CONTENT_PKCS10)
  12163. //an encoded PFX BLOB
  12164. #define CERT_QUERY_CONTENT_FLAG_PFX \
  12165. ( 1 << CERT_QUERY_CONTENT_PFX)
  12166. //an encoded CertificatePair (contains forward and/or reverse cross certs)
  12167. #define CERT_QUERY_CONTENT_FLAG_CERT_PAIR \
  12168. ( 1 << CERT_QUERY_CONTENT_CERT_PAIR)
  12169. //content can be any type
  12170. #define CERT_QUERY_CONTENT_FLAG_ALL \
  12171. CERT_QUERY_CONTENT_FLAG_CERT | \
  12172. CERT_QUERY_CONTENT_FLAG_CTL | \
  12173. CERT_QUERY_CONTENT_FLAG_CRL | \
  12174. CERT_QUERY_CONTENT_FLAG_SERIALIZED_STORE | \
  12175. CERT_QUERY_CONTENT_FLAG_SERIALIZED_CERT | \
  12176. CERT_QUERY_CONTENT_FLAG_SERIALIZED_CTL | \
  12177. CERT_QUERY_CONTENT_FLAG_SERIALIZED_CRL | \
  12178. CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED | \
  12179. CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED | \
  12180. CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED | \
  12181. CERT_QUERY_CONTENT_FLAG_PKCS10 | \
  12182. CERT_QUERY_CONTENT_FLAG_PFX | \
  12183. CERT_QUERY_CONTENT_FLAG_CERT_PAIR
  12184. //-------------------------------------------------------------------------
  12185. //dwFormatType for CryptQueryObject
  12186. //-------------------------------------------------------------------------
  12187. //the content is in binary format
  12188. #define CERT_QUERY_FORMAT_BINARY 1
  12189. //the content is base64 encoded
  12190. #define CERT_QUERY_FORMAT_BASE64_ENCODED 2
  12191. //the content is ascii hex encoded with "{ASN}" prefix
  12192. #define CERT_QUERY_FORMAT_ASN_ASCII_HEX_ENCODED 3
  12193. //-------------------------------------------------------------------------
  12194. //dwExpectedFormatTypeFlags for CryptQueryObject
  12195. //-------------------------------------------------------------------------
  12196. //the content is in binary format
  12197. #define CERT_QUERY_FORMAT_FLAG_BINARY \
  12198. ( 1 << CERT_QUERY_FORMAT_BINARY)
  12199. //the content is base64 encoded
  12200. #define CERT_QUERY_FORMAT_FLAG_BASE64_ENCODED \
  12201. ( 1 << CERT_QUERY_FORMAT_BASE64_ENCODED)
  12202. //the content is ascii hex encoded with "{ASN}" prefix
  12203. #define CERT_QUERY_FORMAT_FLAG_ASN_ASCII_HEX_ENCODED \
  12204. ( 1 << CERT_QUERY_FORMAT_ASN_ASCII_HEX_ENCODED)
  12205. //the content can be of any format
  12206. #define CERT_QUERY_FORMAT_FLAG_ALL \
  12207. CERT_QUERY_FORMAT_FLAG_BINARY | \
  12208. CERT_QUERY_FORMAT_FLAG_BASE64_ENCODED | \
  12209. CERT_QUERY_FORMAT_FLAG_ASN_ASCII_HEX_ENCODED
  12210. //
  12211. // Crypt32 Memory Management Routines. All Crypt32 API which return allocated
  12212. // buffers will do so via CryptMemAlloc, CryptMemRealloc. Clients can free
  12213. // those buffers using CryptMemFree. Also included is CryptMemSize
  12214. //
  12215. WINCRYPT32API
  12216. LPVOID
  12217. WINAPI
  12218. CryptMemAlloc (
  12219. IN ULONG cbSize
  12220. );
  12221. WINCRYPT32API
  12222. LPVOID
  12223. WINAPI
  12224. CryptMemRealloc (
  12225. IN LPVOID pv,
  12226. IN ULONG cbSize
  12227. );
  12228. WINCRYPT32API
  12229. VOID
  12230. WINAPI
  12231. CryptMemFree (
  12232. IN LPVOID pv
  12233. );
  12234. //
  12235. // Crypt32 Asynchronous Parameter Management Routines. All Crypt32 API which
  12236. // expose asynchronous mode operation use a Crypt32 Async Handle to pass
  12237. // around information about the operation e.g. callback routines. The
  12238. // following API are used for manipulation of the async handle
  12239. //
  12240. typedef HANDLE HCRYPTASYNC, *PHCRYPTASYNC;
  12241. typedef VOID (WINAPI *PFN_CRYPT_ASYNC_PARAM_FREE_FUNC) (
  12242. LPSTR pszParamOid,
  12243. LPVOID pvParam
  12244. );
  12245. WINCRYPT32API
  12246. BOOL
  12247. WINAPI
  12248. CryptCreateAsyncHandle (
  12249. IN DWORD dwFlags,
  12250. OUT PHCRYPTASYNC phAsync
  12251. );
  12252. WINCRYPT32API
  12253. BOOL
  12254. WINAPI
  12255. CryptSetAsyncParam (
  12256. IN HCRYPTASYNC hAsync,
  12257. IN LPSTR pszParamOid,
  12258. IN LPVOID pvParam,
  12259. IN OPTIONAL PFN_CRYPT_ASYNC_PARAM_FREE_FUNC pfnFree
  12260. );
  12261. WINCRYPT32API
  12262. BOOL
  12263. WINAPI
  12264. CryptGetAsyncParam (
  12265. IN HCRYPTASYNC hAsync,
  12266. IN LPSTR pszParamOid,
  12267. OUT LPVOID* ppvParam,
  12268. OUT OPTIONAL PFN_CRYPT_ASYNC_PARAM_FREE_FUNC* ppfnFree
  12269. );
  12270. WINCRYPT32API
  12271. BOOL
  12272. WINAPI
  12273. CryptCloseAsyncHandle (
  12274. IN HCRYPTASYNC hAsync
  12275. );
  12276. //
  12277. // Crypt32 Remote Object Retrieval Routines. This API allows retrieval of
  12278. // remote PKI objects where the location is given by an URL. The remote
  12279. // object retrieval manager exposes two provider models. One is the "Scheme
  12280. // Provider" model which allows for installable protocol providers as defined
  12281. // by the URL scheme e.g. ldap, http, ftp. The scheme provider entry point is
  12282. // the same as the CryptRetrieveObjectByUrl however the *ppvObject returned
  12283. // is ALWAYS a counted array of encoded bits (one per object retrieved). The
  12284. // second provider model is the "Context Provider" model which allows for
  12285. // installable creators of CAPI2 context handles (objects) based on the
  12286. // retrieved encoded bits. These are dispatched based on the object OID given
  12287. // in the call to CryptRetrieveObjectByUrl.
  12288. //
  12289. typedef struct _CRYPT_BLOB_ARRAY {
  12290. DWORD cBlob;
  12291. PCRYPT_DATA_BLOB rgBlob;
  12292. } CRYPT_BLOB_ARRAY, *PCRYPT_BLOB_ARRAY;
  12293. typedef struct _CRYPT_CREDENTIALS {
  12294. DWORD cbSize;
  12295. LPCSTR pszCredentialsOid;
  12296. LPVOID pvCredentials;
  12297. } CRYPT_CREDENTIALS, *PCRYPT_CREDENTIALS;
  12298. #define CREDENTIAL_OID_PASSWORD_CREDENTIALS_A ((LPCSTR)1)
  12299. #define CREDENTIAL_OID_PASSWORD_CREDENTIALS_W ((LPCSTR)2)
  12300. #ifdef UNICODE
  12301. #define CREDENTIAL_OID_PASSWORD_CREDENTIALS CREDENTIAL_OID_PASSWORD_CREDENTIALS_W
  12302. #else
  12303. #define CREDENTIAL_OID_PASSWORD_CREDENTIALS CREDENTIAL_OID_PASSWORD_CREDENTIALS_A
  12304. #endif //UNICODE
  12305. typedef struct _CRYPT_PASSWORD_CREDENTIALS% {
  12306. DWORD cbSize;
  12307. LPTSTR% pszUsername;
  12308. LPTSTR% pszPassword;
  12309. } CRYPT_PASSWORD_CREDENTIALS%, *PCRYPT_PASSWORD_CREDENTIALS%;
  12310. //
  12311. // Scheme Provider Signatures
  12312. //
  12313. // The following is obsolete and has been replaced with the following
  12314. // definition
  12315. #define SCHEME_OID_RETRIEVE_ENCODED_OBJECT_FUNC "SchemeDllRetrieveEncodedObject"
  12316. // 2-8-02 Server 2003 changed to use UNICODE Url strings instead of multibyte
  12317. #define SCHEME_OID_RETRIEVE_ENCODED_OBJECTW_FUNC "SchemeDllRetrieveEncodedObjectW"
  12318. typedef VOID (WINAPI *PFN_FREE_ENCODED_OBJECT_FUNC) (
  12319. LPCSTR pszObjectOid,
  12320. PCRYPT_BLOB_ARRAY pObject,
  12321. LPVOID pvFreeContext
  12322. );
  12323. //
  12324. // SchemeDllRetrieveEncodedObject was replaced in Server 2003 with
  12325. // the following. (Changed to use UNICODE Url Strings.)
  12326. //
  12327. //
  12328. // SchemeDllRetrieveEncodedObjectW has the following signature:
  12329. //
  12330. // BOOL WINAPI SchemeDllRetrieveEncodedObjectW (
  12331. // IN LPCWSTR pwszUrl,
  12332. // IN LPCSTR pszObjectOid,
  12333. // IN DWORD dwRetrievalFlags,
  12334. // IN DWORD dwTimeout, // milliseconds
  12335. // OUT PCRYPT_BLOB_ARRAY pObject,
  12336. // OUT PFN_FREE_ENCODED_OBJECT_FUNC* ppfnFreeObject,
  12337. // OUT LPVOID* ppvFreeContext,
  12338. // IN HCRYPTASYNC hAsyncRetrieve,
  12339. // IN PCRYPT_CREDENTIALS pCredentials,
  12340. // IN PCRYPT_RETRIEVE_AUX_INFO pAuxInfo
  12341. // )
  12342. //
  12343. //
  12344. // Context Provider Signatures
  12345. //
  12346. #define CONTEXT_OID_CREATE_OBJECT_CONTEXT_FUNC "ContextDllCreateObjectContext"
  12347. #define CONTEXT_OID_CERTIFICATE ((LPCSTR)1)
  12348. #define CONTEXT_OID_CRL ((LPCSTR)2)
  12349. #define CONTEXT_OID_CTL ((LPCSTR)3)
  12350. #define CONTEXT_OID_PKCS7 ((LPCSTR)4)
  12351. #define CONTEXT_OID_CAPI2_ANY ((LPCSTR)5)
  12352. //
  12353. // ContextDllCreateObjectContext has the following signature:
  12354. //
  12355. // BOOL WINAPI ContextDllCreateObjectContext (
  12356. // IN LPCSTR pszObjectOid,
  12357. // IN DWORD dwRetrievalFlags,
  12358. // IN PCRYPT_BLOB_ARRAY pObject,
  12359. // OUT LPVOID* ppvContext
  12360. // )
  12361. //
  12362. //
  12363. // Remote Object Retrieval API
  12364. //
  12365. //
  12366. // Retrieval flags
  12367. //
  12368. #define CRYPT_RETRIEVE_MULTIPLE_OBJECTS 0x00000001
  12369. #define CRYPT_CACHE_ONLY_RETRIEVAL 0x00000002
  12370. #define CRYPT_WIRE_ONLY_RETRIEVAL 0x00000004
  12371. #define CRYPT_DONT_CACHE_RESULT 0x00000008
  12372. #define CRYPT_ASYNC_RETRIEVAL 0x00000010
  12373. #define CRYPT_STICKY_CACHE_RETRIEVAL 0x00001000
  12374. #define CRYPT_LDAP_SCOPE_BASE_ONLY_RETRIEVAL 0x00002000
  12375. #define CRYPT_OFFLINE_CHECK_RETRIEVAL 0x00004000
  12376. // When the following flag is set, the following 2 NULL terminated ascii
  12377. // strings are inserted at the beginning of each returned blob:
  12378. // "%d\0%s\0", dwEntryIndex, pszAttribute
  12379. //
  12380. // The first dwEntryIndex is 0, "0\0".
  12381. //
  12382. // When set, pszObjectOid must be NULL, so that a PCRYPT_BLOB_ARRAY is returned.
  12383. #define CRYPT_LDAP_INSERT_ENTRY_ATTRIBUTE 0x00008000
  12384. // Set this flag to digitally sign all of the ldap traffic to and from a
  12385. // Windows 2000 LDAP server using the Kerberos authentication protocol.
  12386. // This feature provides integrity required by some applications.
  12387. #define CRYPT_LDAP_SIGN_RETRIEVAL 0x00010000
  12388. // Set this flag to inhibit automatic authentication handling. See the
  12389. // wininet flag, INTERNET_FLAG_NO_AUTH, for more details.
  12390. #define CRYPT_NO_AUTH_RETRIEVAL 0x00020000
  12391. // Performs an A-Record only DNS lookup on the supplied host string.
  12392. // This prevents bogus DNS queries from being generated when resolving host
  12393. // names. Use this flag whenever passing a hostname as opposed to a
  12394. // domain name for the hostname parameter.
  12395. //
  12396. // See LDAP_OPT_AREC_EXCLUSIVE defined in winldap.h for more details.
  12397. #define CRYPT_LDAP_AREC_EXCLUSIVE_RETRIEVAL 0x00040000
  12398. // Apply AIA URL restrictions, such as, validate retrieved content before
  12399. // writing to cache.
  12400. #define CRYPT_AIA_RETRIEVAL 0x00080000
  12401. //
  12402. // Data verification retrieval flags
  12403. //
  12404. // CRYPT_VERIFY_CONTEXT_SIGNATURE is used to get signature verification
  12405. // on the context created. In this case pszObjectOid must be non-NULL and
  12406. // pvVerify points to the signer certificate context
  12407. //
  12408. // CRYPT_VERIFY_DATA_HASH is used to get verification of the blob data
  12409. // retrieved by the protocol. The pvVerify points to an URL_DATA_HASH
  12410. // structure (TBD)
  12411. //
  12412. #define CRYPT_VERIFY_CONTEXT_SIGNATURE 0x00000020
  12413. #define CRYPT_VERIFY_DATA_HASH 0x00000040
  12414. //
  12415. // Time Valid Object flags
  12416. //
  12417. #define CRYPT_KEEP_TIME_VALID 0x00000080
  12418. #define CRYPT_DONT_VERIFY_SIGNATURE 0x00000100
  12419. #define CRYPT_DONT_CHECK_TIME_VALIDITY 0x00000200
  12420. // The default checks if ftNextUpdate >= ftValidFor. Set this flag to
  12421. // check if ftThisUpdate >= ftValidFor.
  12422. #define CRYPT_CHECK_FRESHNESS_TIME_VALIDITY 0x00000400
  12423. #define CRYPT_ACCUMULATIVE_TIMEOUT 0x00000800
  12424. typedef struct _CRYPT_RETRIEVE_AUX_INFO {
  12425. DWORD cbSize;
  12426. FILETIME *pLastSyncTime;
  12427. DWORD dwMaxUrlRetrievalByteCount; // 0 => implies no limit
  12428. } CRYPT_RETRIEVE_AUX_INFO, *PCRYPT_RETRIEVE_AUX_INFO;
  12429. WINCRYPT32API
  12430. BOOL
  12431. WINAPI
  12432. CryptRetrieveObjectByUrl% (
  12433. IN LPCTSTR% pszUrl,
  12434. IN LPCSTR pszObjectOid,
  12435. IN DWORD dwRetrievalFlags,
  12436. IN DWORD dwTimeout, // milliseconds
  12437. OUT LPVOID* ppvObject,
  12438. IN HCRYPTASYNC hAsyncRetrieve,
  12439. IN OPTIONAL PCRYPT_CREDENTIALS pCredentials,
  12440. IN OPTIONAL LPVOID pvVerify,
  12441. IN OPTIONAL PCRYPT_RETRIEVE_AUX_INFO pAuxInfo
  12442. );
  12443. //
  12444. // Call back function to cancel object retrieval
  12445. //
  12446. // The function can be installed on a per thread basis.
  12447. // If CryptInstallCancelRetrieval is called for multiple times, only the most recent
  12448. // installation will be kept.
  12449. //
  12450. // This is only effective for http, https, gopher, and ftp protocol.
  12451. // It is ignored by the rest of the protocols.
  12452. typedef BOOL (WINAPI *PFN_CRYPT_CANCEL_RETRIEVAL)(
  12453. IN DWORD dwFlags,
  12454. IN void *pvArg
  12455. );
  12456. //
  12457. // PFN_CRYPT_CANCEL_RETRIEVAL
  12458. //
  12459. // This function should return FALSE when the object retrieval should be continued
  12460. // and return TRUE when the object retrieval should be cancelled.
  12461. //
  12462. WINCRYPT32API
  12463. BOOL
  12464. WINAPI
  12465. CryptInstallCancelRetrieval(
  12466. IN PFN_CRYPT_CANCEL_RETRIEVAL pfnCancel,
  12467. IN const void *pvArg,
  12468. IN DWORD dwFlags,
  12469. IN void *pvReserved
  12470. );
  12471. WINCRYPT32API
  12472. BOOL
  12473. WINAPI
  12474. CryptUninstallCancelRetrieval(
  12475. IN DWORD dwFlags,
  12476. IN void *pvReserved
  12477. );
  12478. WINCRYPT32API
  12479. BOOL
  12480. WINAPI
  12481. CryptCancelAsyncRetrieval (
  12482. HCRYPTASYNC hAsyncRetrieval
  12483. );
  12484. //
  12485. // Remote Object Async Retrieval parameters
  12486. //
  12487. //
  12488. // A client that wants to be notified of asynchronous object retrieval
  12489. // completion sets this parameter on the async handle
  12490. //
  12491. #define CRYPT_PARAM_ASYNC_RETRIEVAL_COMPLETION ((LPCSTR)1)
  12492. typedef VOID (WINAPI *PFN_CRYPT_ASYNC_RETRIEVAL_COMPLETION_FUNC) (
  12493. IN LPVOID pvCompletion,
  12494. IN DWORD dwCompletionCode,
  12495. IN LPCSTR pszUrl,
  12496. IN LPSTR pszObjectOid,
  12497. IN LPVOID pvObject
  12498. );
  12499. typedef struct _CRYPT_ASYNC_RETRIEVAL_COMPLETION {
  12500. PFN_CRYPT_ASYNC_RETRIEVAL_COMPLETION_FUNC pfnCompletion;
  12501. LPVOID pvCompletion;
  12502. } CRYPT_ASYNC_RETRIEVAL_COMPLETION, *PCRYPT_ASYNC_RETRIEVAL_COMPLETION;
  12503. //
  12504. // This function is set on the async handle by a scheme provider that
  12505. // supports asynchronous retrieval
  12506. //
  12507. #define CRYPT_PARAM_CANCEL_ASYNC_RETRIEVAL ((LPCSTR)2)
  12508. typedef BOOL (WINAPI *PFN_CANCEL_ASYNC_RETRIEVAL_FUNC) (
  12509. HCRYPTASYNC hAsyncRetrieve
  12510. );
  12511. //
  12512. // Get the locator for a CAPI object
  12513. //
  12514. #define CRYPT_GET_URL_FROM_PROPERTY 0x00000001
  12515. #define CRYPT_GET_URL_FROM_EXTENSION 0x00000002
  12516. #define CRYPT_GET_URL_FROM_UNAUTH_ATTRIBUTE 0x00000004
  12517. #define CRYPT_GET_URL_FROM_AUTH_ATTRIBUTE 0x00000008
  12518. typedef struct _CRYPT_URL_ARRAY {
  12519. DWORD cUrl;
  12520. LPWSTR* rgwszUrl;
  12521. } CRYPT_URL_ARRAY, *PCRYPT_URL_ARRAY;
  12522. typedef struct _CRYPT_URL_INFO {
  12523. DWORD cbSize;
  12524. // Seconds between syncs
  12525. DWORD dwSyncDeltaTime;
  12526. // Returned URLs may be grouped. For instance, groups of cross cert
  12527. // distribution points. Each distribution point may have multiple
  12528. // URLs, (LDAP and HTTP scheme).
  12529. DWORD cGroup;
  12530. DWORD *rgcGroupEntry;
  12531. } CRYPT_URL_INFO, *PCRYPT_URL_INFO;
  12532. WINCRYPT32API
  12533. BOOL
  12534. WINAPI
  12535. CryptGetObjectUrl (
  12536. IN LPCSTR pszUrlOid,
  12537. IN LPVOID pvPara,
  12538. IN DWORD dwFlags,
  12539. OUT OPTIONAL PCRYPT_URL_ARRAY pUrlArray,
  12540. IN OUT DWORD* pcbUrlArray,
  12541. OUT OPTIONAL PCRYPT_URL_INFO pUrlInfo,
  12542. IN OUT OPTIONAL DWORD* pcbUrlInfo,
  12543. IN OPTIONAL LPVOID pvReserved
  12544. );
  12545. #define URL_OID_GET_OBJECT_URL_FUNC "UrlDllGetObjectUrl"
  12546. //
  12547. // UrlDllGetObjectUrl has the same signature as CryptGetObjectUrl
  12548. //
  12549. //
  12550. // URL_OID_CERTIFICATE_ISSUER
  12551. //
  12552. // pvPara == PCCERT_CONTEXT, certificate whose issuer's URL is being requested
  12553. //
  12554. // This will be retrieved from the authority info access extension or property
  12555. // on the certificate
  12556. //
  12557. // URL_OID_CERTIFICATE_CRL_DIST_POINT
  12558. //
  12559. // pvPara == PCCERT_CONTEXT, certificate whose CRL distribution point is being
  12560. // requested
  12561. //
  12562. // This will be retrieved from the CRL distribution point extension or property
  12563. // on the certificate
  12564. //
  12565. // URL_OID_CTL_ISSUER
  12566. //
  12567. // pvPara == PCCTL_CONTEXT, Signer Index, CTL whose issuer's URL (identified
  12568. // by the signer index) is being requested
  12569. //
  12570. // This will be retrieved from an authority info access attribute method encoded
  12571. // in each signer info in the PKCS7 (CTL)
  12572. //
  12573. // URL_OID_CTL_NEXT_UPDATE
  12574. //
  12575. // pvPara == PCCTL_CONTEXT, Signer Index, CTL whose next update URL is being
  12576. // requested and an optional signer index in case we need to check signer
  12577. // info attributes
  12578. //
  12579. // This will be retrieved from an authority info access CTL extension, property,
  12580. // or signer info attribute method
  12581. //
  12582. // URL_OID_CRL_ISSUER
  12583. //
  12584. // pvPara == PCCRL_CONTEXT, CRL whose issuer's URL is being requested
  12585. //
  12586. // This will be retrieved from a property on the CRL which has been inherited
  12587. // from the subject cert (either from the subject cert issuer or the subject
  12588. // cert distribution point extension). It will be encoded as an authority
  12589. // info access extension method.
  12590. //
  12591. // URL_OID_CERTIFICATE_FRESHEST_CRL
  12592. //
  12593. // pvPara == PCCERT_CONTEXT, certificate whose freshest CRL distribution point
  12594. // is being requested
  12595. //
  12596. // This will be retrieved from the freshest CRL extension or property
  12597. // on the certificate
  12598. //
  12599. // URL_OID_CRL_FRESHEST_CRL
  12600. //
  12601. // pvPara == PCCERT_CRL_CONTEXT_PAIR, certificate's base CRL whose
  12602. // freshest CRL distribution point is being requested
  12603. //
  12604. // This will be retrieved from the freshest CRL extension or property
  12605. // on the CRL
  12606. //
  12607. // URL_OID_CROSS_CERT_DIST_POINT
  12608. //
  12609. // pvPara == PCCERT_CONTEXT, certificate whose cross certificate distribution
  12610. // point is being requested
  12611. //
  12612. // This will be retrieved from the cross certificate distribution point
  12613. // extension or property on the certificate
  12614. //
  12615. #define URL_OID_CERTIFICATE_ISSUER ((LPCSTR)1)
  12616. #define URL_OID_CERTIFICATE_CRL_DIST_POINT ((LPCSTR)2)
  12617. #define URL_OID_CTL_ISSUER ((LPCSTR)3)
  12618. #define URL_OID_CTL_NEXT_UPDATE ((LPCSTR)4)
  12619. #define URL_OID_CRL_ISSUER ((LPCSTR)5)
  12620. #define URL_OID_CERTIFICATE_FRESHEST_CRL ((LPCSTR)6)
  12621. #define URL_OID_CRL_FRESHEST_CRL ((LPCSTR)7)
  12622. #define URL_OID_CROSS_CERT_DIST_POINT ((LPCSTR)8)
  12623. typedef struct _CERT_CRL_CONTEXT_PAIR {
  12624. PCCERT_CONTEXT pCertContext;
  12625. PCCRL_CONTEXT pCrlContext;
  12626. } CERT_CRL_CONTEXT_PAIR, *PCERT_CRL_CONTEXT_PAIR;
  12627. typedef const CERT_CRL_CONTEXT_PAIR *PCCERT_CRL_CONTEXT_PAIR;
  12628. //
  12629. // Get a time valid CAPI2 object
  12630. //
  12631. WINCRYPT32API
  12632. BOOL
  12633. WINAPI
  12634. CryptGetTimeValidObject (
  12635. IN LPCSTR pszTimeValidOid,
  12636. IN LPVOID pvPara,
  12637. IN PCCERT_CONTEXT pIssuer,
  12638. IN OPTIONAL LPFILETIME pftValidFor,
  12639. IN DWORD dwFlags,
  12640. IN DWORD dwTimeout, // milliseconds
  12641. OUT OPTIONAL LPVOID* ppvObject,
  12642. IN OPTIONAL PCRYPT_CREDENTIALS pCredentials,
  12643. IN OPTIONAL LPVOID pvReserved
  12644. );
  12645. #define TIME_VALID_OID_GET_OBJECT_FUNC "TimeValidDllGetObject"
  12646. //
  12647. // TimeValidDllGetObject has the same signature as CryptGetTimeValidObject
  12648. //
  12649. //
  12650. // TIME_VALID_OID_GET_CTL
  12651. //
  12652. // pvPara == PCCTL_CONTEXT, the current CTL
  12653. //
  12654. // TIME_VALID_OID_GET_CRL
  12655. //
  12656. // pvPara == PCCRL_CONTEXT, the current CRL
  12657. //
  12658. // TIME_VALID_OID_GET_CRL_FROM_CERT
  12659. //
  12660. // pvPara == PCCERT_CONTEXT, the subject cert
  12661. //
  12662. // TIME_VALID_OID_GET_FRESHEST_CRL_FROM_CERT
  12663. //
  12664. // pvPara == PCCERT_CONTEXT, the subject cert
  12665. //
  12666. // TIME_VALID_OID_GET_FRESHEST_CRL_FROM_CRL
  12667. //
  12668. // pvPara == PCCERT_CRL_CONTEXT_PAIR, the subject cert and its base CRL
  12669. //
  12670. #define TIME_VALID_OID_GET_CTL ((LPCSTR)1)
  12671. #define TIME_VALID_OID_GET_CRL ((LPCSTR)2)
  12672. #define TIME_VALID_OID_GET_CRL_FROM_CERT ((LPCSTR)3)
  12673. #define TIME_VALID_OID_GET_FRESHEST_CRL_FROM_CERT ((LPCSTR)4)
  12674. #define TIME_VALID_OID_GET_FRESHEST_CRL_FROM_CRL ((LPCSTR)5)
  12675. WINCRYPT32API
  12676. BOOL
  12677. WINAPI
  12678. CryptFlushTimeValidObject (
  12679. IN LPCSTR pszFlushTimeValidOid,
  12680. IN LPVOID pvPara,
  12681. IN PCCERT_CONTEXT pIssuer,
  12682. IN DWORD dwFlags,
  12683. IN LPVOID pvReserved
  12684. );
  12685. #define TIME_VALID_OID_FLUSH_OBJECT_FUNC "TimeValidDllFlushObject"
  12686. //
  12687. // TimeValidDllFlushObject has the same signature as CryptFlushTimeValidObject
  12688. //
  12689. //
  12690. // TIME_VALID_OID_FLUSH_CTL
  12691. //
  12692. // pvPara == PCCTL_CONTEXT, the CTL to flush
  12693. //
  12694. // TIME_VALID_OID_FLUSH_CRL
  12695. //
  12696. // pvPara == PCCRL_CONTEXT, the CRL to flush
  12697. //
  12698. // TIME_VALID_OID_FLUSH_CRL_FROM_CERT
  12699. //
  12700. // pvPara == PCCERT_CONTEXT, the subject cert's CRL to flush
  12701. //
  12702. // TIME_VALID_OID_FLUSH_FRESHEST_CRL_FROM_CERT
  12703. //
  12704. // pvPara == PCCERT_CONTEXT, the subject cert's freshest CRL to flush
  12705. //
  12706. // TIME_VALID_OID_FLUSH_FRESHEST_CRL_FROM_CRL
  12707. //
  12708. // pvPara == PCCERT_CRL_CONTEXT_PAIR, the subject cert and its base CRL's
  12709. // freshest CRL to flush
  12710. //
  12711. #define TIME_VALID_OID_FLUSH_CTL ((LPCSTR)1)
  12712. #define TIME_VALID_OID_FLUSH_CRL ((LPCSTR)2)
  12713. #define TIME_VALID_OID_FLUSH_CRL_FROM_CERT ((LPCSTR)3)
  12714. #define TIME_VALID_OID_FLUSH_FRESHEST_CRL_FROM_CERT ((LPCSTR)4)
  12715. #define TIME_VALID_OID_FLUSH_FRESHEST_CRL_FROM_CRL ((LPCSTR)5)
  12716. //-------------------------------------------------------------------------
  12717. // Data Protection APIs
  12718. //-------------------------------------------------------------------------
  12719. //
  12720. // Data protection APIs enable applications to easily secure data.
  12721. //
  12722. // The base provider provides protection based on the users' logon
  12723. // credentials. The data secured with these APIs follow the same
  12724. // roaming characteristics as HKCU -- if HKCU roams, the data
  12725. // protected by the base provider may roam as well. This makes
  12726. // the API ideal for the munging of data stored in the registry.
  12727. //
  12728. //
  12729. // Prompt struct -- what to tell users about the access
  12730. //
  12731. typedef struct _CRYPTPROTECT_PROMPTSTRUCT
  12732. {
  12733. DWORD cbSize;
  12734. DWORD dwPromptFlags;
  12735. HWND hwndApp;
  12736. LPCWSTR szPrompt;
  12737. } CRYPTPROTECT_PROMPTSTRUCT, *PCRYPTPROTECT_PROMPTSTRUCT;
  12738. //
  12739. // base provider action
  12740. //
  12741. #define CRYPTPROTECT_DEFAULT_PROVIDER { 0xdf9d8cd0, 0x1501, 0x11d1, {0x8c, 0x7a, 0x00, 0xc0, 0x4f, 0xc2, 0x97, 0xeb} }
  12742. //
  12743. // CryptProtect PromptStruct dwPromtFlags
  12744. //
  12745. //
  12746. // prompt on unprotect
  12747. #define CRYPTPROTECT_PROMPT_ON_UNPROTECT 0x1 // 1<<0
  12748. //
  12749. // prompt on protect
  12750. #define CRYPTPROTECT_PROMPT_ON_PROTECT 0x2 // 1<<1
  12751. #define CRYPTPROTECT_PROMPT_RESERVED 0x04 // reserved, do not use.
  12752. //
  12753. // default to strong variant UI protection (user supplied password currently).
  12754. #define CRYPTPROTECT_PROMPT_STRONG 0x08 // 1<<3
  12755. //
  12756. // require strong variant UI protection (user supplied password currently).
  12757. #define CRYPTPROTECT_PROMPT_REQUIRE_STRONG 0x10 // 1<<4
  12758. //
  12759. // CryptProtectData and CryptUnprotectData dwFlags
  12760. //
  12761. // for remote-access situations where ui is not an option
  12762. // if UI was specified on protect or unprotect operation, the call
  12763. // will fail and GetLastError() will indicate ERROR_PASSWORD_RESTRICTION
  12764. #define CRYPTPROTECT_UI_FORBIDDEN 0x1
  12765. //
  12766. // per machine protected data -- any user on machine where CryptProtectData
  12767. // took place may CryptUnprotectData
  12768. #define CRYPTPROTECT_LOCAL_MACHINE 0x4
  12769. //
  12770. // force credential synchronize during CryptProtectData()
  12771. // Synchronize is only operation that occurs during this operation
  12772. #define CRYPTPROTECT_CRED_SYNC 0x8
  12773. //
  12774. // Generate an Audit on protect and unprotect operations
  12775. //
  12776. #define CRYPTPROTECT_AUDIT 0x10
  12777. //
  12778. // Protect data with a non-recoverable key
  12779. //
  12780. #define CRYPTPROTECT_NO_RECOVERY 0x20
  12781. //
  12782. // Verify the protection of a protected blob
  12783. //
  12784. #define CRYPTPROTECT_VERIFY_PROTECTION 0x40
  12785. //
  12786. // Regenerate the local machine protection
  12787. //
  12788. #define CRYPTPROTECT_CRED_REGENERATE 0x80
  12789. // flags reserved for system use
  12790. #define CRYPTPROTECT_FIRST_RESERVED_FLAGVAL 0x0FFFFFFF
  12791. #define CRYPTPROTECT_LAST_RESERVED_FLAGVAL 0xFFFFFFFF
  12792. //
  12793. // flags specific to base provider
  12794. //
  12795. WINCRYPT32API
  12796. BOOL
  12797. WINAPI
  12798. CryptProtectData(
  12799. IN DATA_BLOB* pDataIn,
  12800. IN LPCWSTR szDataDescr,
  12801. IN OPTIONAL DATA_BLOB* pOptionalEntropy,
  12802. IN PVOID pvReserved,
  12803. IN OPTIONAL CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct,
  12804. IN DWORD dwFlags,
  12805. OUT DATA_BLOB* pDataOut // out encr blob
  12806. );
  12807. WINCRYPT32API
  12808. BOOL
  12809. WINAPI
  12810. CryptUnprotectData(
  12811. IN DATA_BLOB* pDataIn, // in encr blob
  12812. OUT OPTIONAL LPWSTR* ppszDataDescr, // out
  12813. IN OPTIONAL DATA_BLOB* pOptionalEntropy,
  12814. IN PVOID pvReserved,
  12815. IN OPTIONAL CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct,
  12816. IN DWORD dwFlags,
  12817. OUT DATA_BLOB* pDataOut
  12818. );
  12819. //
  12820. // The buffer length passed into CryptProtectMemory and CryptUnprotectMemory
  12821. // must be a multiple of this length (or zero).
  12822. //
  12823. #define CRYPTPROTECTMEMORY_BLOCK_SIZE 16
  12824. //
  12825. // CryptProtectMemory/CryptUnprotectMemory dwFlags
  12826. //
  12827. //
  12828. // Encrypt/Decrypt within current process context.
  12829. //
  12830. #define CRYPTPROTECTMEMORY_SAME_PROCESS 0x00
  12831. //
  12832. // Encrypt/Decrypt across process boundaries.
  12833. // eg: encrypted buffer passed across LPC to another process which calls CryptUnprotectMemory.
  12834. //
  12835. #define CRYPTPROTECTMEMORY_CROSS_PROCESS 0x01
  12836. //
  12837. // Encrypt/Decrypt across callers with same LogonId.
  12838. // eg: encrypted buffer passed across LPC to another process which calls CryptUnprotectMemory whilst impersonating.
  12839. //
  12840. #define CRYPTPROTECTMEMORY_SAME_LOGON 0x02
  12841. WINCRYPT32API
  12842. BOOL
  12843. WINAPI
  12844. CryptProtectMemory(
  12845. IN OUT LPVOID pDataIn, // in out data to encrypt
  12846. IN DWORD cbDataIn, // multiple of CRYPTPROTECTMEMORY_BLOCK_SIZE
  12847. IN DWORD dwFlags
  12848. );
  12849. WINCRYPT32API
  12850. BOOL
  12851. WINAPI
  12852. CryptUnprotectMemory(
  12853. IN OUT LPVOID pDataIn, // in out data to decrypt
  12854. IN DWORD cbDataIn, // multiple of CRYPTPROTECTMEMORY_BLOCK_SIZE
  12855. IN DWORD dwFlags
  12856. );
  12857. //+=========================================================================
  12858. // Helper functions to build certificates
  12859. //==========================================================================
  12860. //+-------------------------------------------------------------------------
  12861. //
  12862. // Builds a self-signed certificate and returns a PCCERT_CONTEXT representing
  12863. // the certificate. A hProv must be specified to build the cert context.
  12864. //
  12865. // pSubjectIssuerBlob is the DN for the certifcate. If an alternate subject
  12866. // name is desired it must be specified as an extension in the pExtensions
  12867. // parameter. pSubjectIssuerBlob can NOT be NULL, so minimually an empty DN
  12868. // must be specified.
  12869. //
  12870. // By default:
  12871. // pKeyProvInfo - The CSP is queried for the KeyProvInfo parameters. Only the Provider,
  12872. // Provider Type and Container is queried. Many CSPs don't support these
  12873. // queries and will cause a failure. In such cases the pKeyProvInfo
  12874. // must be specified (RSA BASE works fine).
  12875. //
  12876. // pSignatureAlgorithm - will default to SHA1RSA
  12877. // pStartTime will default to the current time
  12878. // pEndTime will default to 1 year
  12879. // pEntensions will be empty.
  12880. //
  12881. // The returned PCCERT_CONTEXT will reference the private keys by setting the
  12882. // CERT_KEY_PROV_INFO_PROP_ID. However, if this property is not desired specify the
  12883. // CERT_CREATE_SELFSIGN_NO_KEY_INFO in dwFlags.
  12884. //
  12885. // If the cert being built is only a dummy placeholder cert for speed it may not
  12886. // need to be signed. Signing of the cert is skipped if CERT_CREATE_SELFSIGN_NO_SIGN
  12887. // is specified in dwFlags.
  12888. //
  12889. //--------------------------------------------------------------------------
  12890. WINCRYPT32API
  12891. PCCERT_CONTEXT
  12892. WINAPI
  12893. CertCreateSelfSignCertificate(
  12894. IN HCRYPTPROV hProv,
  12895. IN PCERT_NAME_BLOB pSubjectIssuerBlob,
  12896. IN DWORD dwFlags,
  12897. OPTIONAL PCRYPT_KEY_PROV_INFO pKeyProvInfo,
  12898. OPTIONAL PCRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm,
  12899. OPTIONAL PSYSTEMTIME pStartTime,
  12900. OPTIONAL PSYSTEMTIME pEndTime,
  12901. OPTIONAL PCERT_EXTENSIONS pExtensions
  12902. );
  12903. #define CERT_CREATE_SELFSIGN_NO_SIGN 1
  12904. #define CERT_CREATE_SELFSIGN_NO_KEY_INFO 2
  12905. //+=========================================================================
  12906. // Key Identifier Property Data Structures and APIs
  12907. //==========================================================================
  12908. //+-------------------------------------------------------------------------
  12909. // Get the property for the specified Key Identifier.
  12910. //
  12911. // The Key Identifier is the SHA1 hash of the encoded CERT_PUBLIC_KEY_INFO.
  12912. // The Key Identifier for a certificate can be obtained by getting the
  12913. // certificate's CERT_KEY_IDENTIFIER_PROP_ID. The
  12914. // CryptCreateKeyIdentifierFromCSP API can be called to create the Key
  12915. // Identifier from a CSP Public Key Blob.
  12916. //
  12917. // A Key Identifier can have the same properties as a certificate context.
  12918. // CERT_KEY_PROV_INFO_PROP_ID is the property of most interest.
  12919. // For CERT_KEY_PROV_INFO_PROP_ID, pvData points to a CRYPT_KEY_PROV_INFO
  12920. // structure. Elements pointed to by fields in the pvData structure follow the
  12921. // structure. Therefore, *pcbData will exceed the size of the structure.
  12922. //
  12923. // If CRYPT_KEYID_ALLOC_FLAG is set, then, *pvData is updated with a
  12924. // pointer to allocated memory. LocalFree() must be called to free the
  12925. // allocated memory.
  12926. //
  12927. // By default, searches the CurrentUser's list of Key Identifiers.
  12928. // CRYPT_KEYID_MACHINE_FLAG can be set to search the LocalMachine's list
  12929. // of Key Identifiers. When CRYPT_KEYID_MACHINE_FLAG is set, pwszComputerName
  12930. // can also be set to specify the name of a remote computer to be searched
  12931. // instead of the local machine.
  12932. //--------------------------------------------------------------------------
  12933. WINCRYPT32API
  12934. BOOL
  12935. WINAPI
  12936. CryptGetKeyIdentifierProperty(
  12937. IN const CRYPT_HASH_BLOB *pKeyIdentifier,
  12938. IN DWORD dwPropId,
  12939. IN DWORD dwFlags,
  12940. IN OPTIONAL LPCWSTR pwszComputerName,
  12941. IN OPTIONAL void *pvReserved,
  12942. OUT void *pvData,
  12943. IN OUT DWORD *pcbData
  12944. );
  12945. // When the following flag is set, searches the LocalMachine instead of the
  12946. // CurrentUser. This flag is applicable to all the KeyIdentifierProperty APIs.
  12947. #define CRYPT_KEYID_MACHINE_FLAG 0x00000020
  12948. // When the following flag is set, *pvData is updated with a pointer to
  12949. // allocated memory. LocalFree() must be called to free the allocated memory.
  12950. #define CRYPT_KEYID_ALLOC_FLAG 0x00008000
  12951. //+-------------------------------------------------------------------------
  12952. // Set the property for the specified Key Identifier.
  12953. //
  12954. // For CERT_KEY_PROV_INFO_PROP_ID pvData points to the
  12955. // CRYPT_KEY_PROV_INFO data structure. For all other properties, pvData
  12956. // points to a CRYPT_DATA_BLOB.
  12957. //
  12958. // Setting pvData == NULL, deletes the property.
  12959. //
  12960. // Set CRYPT_KEYID_MACHINE_FLAG to set the property for a LocalMachine
  12961. // Key Identifier. Set pwszComputerName, to select a remote computer.
  12962. //
  12963. // If CRYPT_KEYID_DELETE_FLAG is set, the Key Identifier and all its
  12964. // properties is deleted.
  12965. //
  12966. // If CRYPT_KEYID_SET_NEW_FLAG is set, the set fails if the property already
  12967. // exists. For an existing property, FALSE is returned with LastError set to
  12968. // CRYPT_E_EXISTS.
  12969. //--------------------------------------------------------------------------
  12970. WINCRYPT32API
  12971. BOOL
  12972. WINAPI
  12973. CryptSetKeyIdentifierProperty(
  12974. IN const CRYPT_HASH_BLOB *pKeyIdentifier,
  12975. IN DWORD dwPropId,
  12976. IN DWORD dwFlags,
  12977. IN OPTIONAL LPCWSTR pwszComputerName,
  12978. IN OPTIONAL void *pvReserved,
  12979. IN const void *pvData
  12980. );
  12981. // When the following flag is set, the Key Identifier and all its properties
  12982. // are deleted.
  12983. #define CRYPT_KEYID_DELETE_FLAG 0x00000010
  12984. // When the following flag is set, the set fails if the property already
  12985. // exists.
  12986. #define CRYPT_KEYID_SET_NEW_FLAG 0x00002000
  12987. //+-------------------------------------------------------------------------
  12988. // For CERT_KEY_PROV_INFO_PROP_ID, rgppvData[] points to a
  12989. // CRYPT_KEY_PROV_INFO.
  12990. //
  12991. // Return FALSE to stop the enumeration.
  12992. //--------------------------------------------------------------------------
  12993. typedef BOOL (WINAPI *PFN_CRYPT_ENUM_KEYID_PROP)(
  12994. IN const CRYPT_HASH_BLOB *pKeyIdentifier,
  12995. IN DWORD dwFlags,
  12996. IN void *pvReserved,
  12997. IN void *pvArg,
  12998. IN DWORD cProp,
  12999. IN DWORD *rgdwPropId,
  13000. IN void **rgpvData,
  13001. IN DWORD *rgcbData
  13002. );
  13003. //+-------------------------------------------------------------------------
  13004. // Enumerate the Key Identifiers.
  13005. //
  13006. // If pKeyIdentifier is NULL, enumerates all Key Identifers. Otherwise,
  13007. // calls the callback for the specified KeyIdentifier. If dwPropId is
  13008. // 0, calls the callback with all the properties. Otherwise, only calls
  13009. // the callback with the specified property (cProp = 1).
  13010. // Furthermore, when dwPropId is specified, skips KeyIdentifiers not
  13011. // having the property.
  13012. //
  13013. // Set CRYPT_KEYID_MACHINE_FLAG to enumerate the LocalMachine
  13014. // Key Identifiers. Set pwszComputerName, to enumerate Key Identifiers on
  13015. // a remote computer.
  13016. //--------------------------------------------------------------------------
  13017. WINCRYPT32API
  13018. BOOL
  13019. WINAPI
  13020. CryptEnumKeyIdentifierProperties(
  13021. IN OPTIONAL const CRYPT_HASH_BLOB *pKeyIdentifier,
  13022. IN DWORD dwPropId,
  13023. IN DWORD dwFlags,
  13024. IN OPTIONAL LPCWSTR pwszComputerName,
  13025. IN OPTIONAL void *pvReserved,
  13026. IN OPTIONAL void *pvArg,
  13027. IN PFN_CRYPT_ENUM_KEYID_PROP pfnEnum
  13028. );
  13029. //+-------------------------------------------------------------------------
  13030. // Create a KeyIdentifier from the CSP Public Key Blob.
  13031. //
  13032. // Converts the CSP PUBLICKEYSTRUC into a X.509 CERT_PUBLIC_KEY_INFO and
  13033. // encodes. The encoded CERT_PUBLIC_KEY_INFO is SHA1 hashed to obtain
  13034. // the Key Identifier.
  13035. //
  13036. // By default, the pPubKeyStruc->aiKeyAlg is used to find the appropriate
  13037. // public key Object Identifier. pszPubKeyOID can be set to override
  13038. // the default OID obtained from the aiKeyAlg.
  13039. //--------------------------------------------------------------------------
  13040. WINCRYPT32API
  13041. BOOL
  13042. WINAPI
  13043. CryptCreateKeyIdentifierFromCSP(
  13044. IN DWORD dwCertEncodingType,
  13045. IN OPTIONAL LPCSTR pszPubKeyOID,
  13046. IN const PUBLICKEYSTRUC *pPubKeyStruc,
  13047. IN DWORD cbPubKeyStruc,
  13048. IN DWORD dwFlags,
  13049. IN OPTIONAL void *pvReserved,
  13050. OUT BYTE *pbHash,
  13051. IN OUT DWORD *pcbHash
  13052. );
  13053. //+=========================================================================
  13054. // Certificate Chaining Infrastructure
  13055. //==========================================================================
  13056. #define CERT_CHAIN_CONFIG_REGPATH \
  13057. L"Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CertDllCreateCertificateChainEngine\\Config"
  13058. // The following are REG_DWORD's. These configuration parameters are used
  13059. // to restrict Authority Info Access (AIA) URL retrieval.
  13060. #define CERT_CHAIN_DISABLE_AIA_URL_RETRIEVAL_VALUE_NAME \
  13061. L"DisableAIAUrlRetrieval"
  13062. // By default AIA Url Retrieval is enabled. Set this registry value to nonzero
  13063. // to disable
  13064. #define CERT_CHAIN_MAX_AIA_URL_COUNT_IN_CERT_VALUE_NAME \
  13065. L"MaxAIAUrlCountInCert"
  13066. #define CERT_CHAIN_MAX_AIA_URL_COUNT_IN_CERT_DEFAULT 5
  13067. #define CERT_CHAIN_MAX_AIA_URL_RETRIEVAL_COUNT_PER_CHAIN_VALUE_NAME \
  13068. L"MaxAIAUrlRetrievalCountPerChain"
  13069. #define CERT_CHAIN_MAX_AIA_URL_RETRIEVAL_COUNT_PER_CHAIN_DEFAULT 10
  13070. #define CERT_CHAIN_MAX_AIA_URL_RETRIEVAL_BYTE_COUNT_VALUE_NAME \
  13071. L"MaxAIAUrlRetrievalByteCount"
  13072. #define CERT_CHAIN_MAX_AIA_URL_RETRIEVAL_BYTE_COUNT_DEFAULT 100000
  13073. #define CERT_CHAIN_MAX_AIA_URL_RETRIEVAL_CERT_COUNT_VALUE_NAME \
  13074. L"MaxAIAUrlRetrievalCertCount"
  13075. #define CERT_CHAIN_MAX_AIA_URL_RETRIEVAL_CERT_COUNT_DEFAULT 10
  13076. //
  13077. // The chain engine defines the store namespace and cache partitioning for
  13078. // the Certificate Chaining infrastructure. A default chain engine
  13079. // is defined for the process which uses all default system stores e.g.
  13080. // Root, CA, Trust, for chain building and caching. If an application
  13081. // wishes to define its own store namespace or have its own partitioned
  13082. // cache then it can create its own chain engine. It is advisable to create
  13083. // a chain engine at application startup and use it throughout the lifetime
  13084. // of the application in order to get optimal caching behavior
  13085. //
  13086. typedef HANDLE HCERTCHAINENGINE;
  13087. #define HCCE_CURRENT_USER ((HCERTCHAINENGINE)NULL)
  13088. #define HCCE_LOCAL_MACHINE ((HCERTCHAINENGINE)0x1)
  13089. //
  13090. // Create a certificate chain engine.
  13091. //
  13092. //
  13093. // Configuration parameters for the certificate chain engine
  13094. //
  13095. // hRestrictedRoot - restrict the root store (must be a subset of "Root")
  13096. //
  13097. // hRestrictedTrust - restrict the store for CTLs
  13098. //
  13099. // hRestrictedOther - restrict the store for certs and CRLs
  13100. //
  13101. // cAdditionalStore, rghAdditionalStore - additional stores
  13102. //
  13103. // NOTE: The algorithm used to define the stores for the engine is as
  13104. // follows:
  13105. //
  13106. // hRoot = hRestrictedRoot or System Store "Root"
  13107. //
  13108. // hTrust = hRestrictedTrust or hWorld (defined later)
  13109. //
  13110. // hOther = hRestrictedOther or (hRestrictedTrust == NULL) ? hWorld :
  13111. // hRestrictedTrust + hWorld
  13112. //
  13113. // hWorld = hRoot + "CA" + "My" + "Trust" + rghAdditionalStore
  13114. //
  13115. // dwFlags - flags
  13116. //
  13117. // CERT_CHAIN_CACHE_END_CERT - information will be cached on
  13118. // the end cert as well as the other
  13119. // certs in the chain
  13120. //
  13121. // CERT_CHAIN_THREAD_STORE_SYNC - use separate thread for store syncs
  13122. // and related cache updates
  13123. //
  13124. // CERT_CHAIN_CACHE_ONLY_URL_RETRIEVAL - don't hit the wire to get
  13125. // URL based objects
  13126. //
  13127. // dwUrlRetrievalTimeout - timeout for wire based URL object retrievals
  13128. // (milliseconds)
  13129. //
  13130. #define CERT_CHAIN_CACHE_END_CERT 0x00000001
  13131. #define CERT_CHAIN_THREAD_STORE_SYNC 0x00000002
  13132. #define CERT_CHAIN_CACHE_ONLY_URL_RETRIEVAL 0x00000004
  13133. #define CERT_CHAIN_USE_LOCAL_MACHINE_STORE 0x00000008
  13134. #define CERT_CHAIN_ENABLE_CACHE_AUTO_UPDATE 0x00000010
  13135. #define CERT_CHAIN_ENABLE_SHARE_STORE 0x00000020
  13136. typedef struct _CERT_CHAIN_ENGINE_CONFIG {
  13137. DWORD cbSize;
  13138. HCERTSTORE hRestrictedRoot;
  13139. HCERTSTORE hRestrictedTrust;
  13140. HCERTSTORE hRestrictedOther;
  13141. DWORD cAdditionalStore;
  13142. HCERTSTORE* rghAdditionalStore;
  13143. DWORD dwFlags;
  13144. DWORD dwUrlRetrievalTimeout; // milliseconds
  13145. DWORD MaximumCachedCertificates;
  13146. DWORD CycleDetectionModulus;
  13147. } CERT_CHAIN_ENGINE_CONFIG, *PCERT_CHAIN_ENGINE_CONFIG;
  13148. WINCRYPT32API
  13149. BOOL
  13150. WINAPI
  13151. CertCreateCertificateChainEngine (
  13152. IN PCERT_CHAIN_ENGINE_CONFIG pConfig,
  13153. OUT HCERTCHAINENGINE* phChainEngine
  13154. );
  13155. //
  13156. // Free a certificate trust engine
  13157. //
  13158. WINCRYPT32API
  13159. VOID
  13160. WINAPI
  13161. CertFreeCertificateChainEngine (
  13162. IN HCERTCHAINENGINE hChainEngine
  13163. );
  13164. //
  13165. // Resync the certificate chain engine. This resync's the stores backing
  13166. // the engine and updates the engine caches.
  13167. //
  13168. WINCRYPT32API
  13169. BOOL
  13170. WINAPI
  13171. CertResyncCertificateChainEngine (
  13172. IN HCERTCHAINENGINE hChainEngine
  13173. );
  13174. //
  13175. // When an application requests a certificate chain, the data structure
  13176. // returned is in the form of a CERT_CHAIN_CONTEXT. This contains
  13177. // an array of CERT_SIMPLE_CHAIN where each simple chain goes from
  13178. // an end cert to a self signed cert and the chain context connects simple
  13179. // chains via trust lists. Each simple chain contains the chain of
  13180. // certificates, summary trust information about the chain and trust information
  13181. // about each certificate element in the chain.
  13182. //
  13183. //
  13184. // Trust status bits
  13185. //
  13186. typedef struct _CERT_TRUST_STATUS {
  13187. DWORD dwErrorStatus;
  13188. DWORD dwInfoStatus;
  13189. } CERT_TRUST_STATUS, *PCERT_TRUST_STATUS;
  13190. //
  13191. // The following are error status bits
  13192. //
  13193. // These can be applied to certificates and chains
  13194. #define CERT_TRUST_NO_ERROR 0x00000000
  13195. #define CERT_TRUST_IS_NOT_TIME_VALID 0x00000001
  13196. #define CERT_TRUST_IS_NOT_TIME_NESTED 0x00000002
  13197. #define CERT_TRUST_IS_REVOKED 0x00000004
  13198. #define CERT_TRUST_IS_NOT_SIGNATURE_VALID 0x00000008
  13199. #define CERT_TRUST_IS_NOT_VALID_FOR_USAGE 0x00000010
  13200. #define CERT_TRUST_IS_UNTRUSTED_ROOT 0x00000020
  13201. #define CERT_TRUST_REVOCATION_STATUS_UNKNOWN 0x00000040
  13202. #define CERT_TRUST_IS_CYCLIC 0x00000080
  13203. #define CERT_TRUST_INVALID_EXTENSION 0x00000100
  13204. #define CERT_TRUST_INVALID_POLICY_CONSTRAINTS 0x00000200
  13205. #define CERT_TRUST_INVALID_BASIC_CONSTRAINTS 0x00000400
  13206. #define CERT_TRUST_INVALID_NAME_CONSTRAINTS 0x00000800
  13207. #define CERT_TRUST_HAS_NOT_SUPPORTED_NAME_CONSTRAINT 0x00001000
  13208. #define CERT_TRUST_HAS_NOT_DEFINED_NAME_CONSTRAINT 0x00002000
  13209. #define CERT_TRUST_HAS_NOT_PERMITTED_NAME_CONSTRAINT 0x00004000
  13210. #define CERT_TRUST_HAS_EXCLUDED_NAME_CONSTRAINT 0x00008000
  13211. #define CERT_TRUST_IS_OFFLINE_REVOCATION 0x01000000
  13212. #define CERT_TRUST_NO_ISSUANCE_CHAIN_POLICY 0x02000000
  13213. // These can be applied to chains only
  13214. #define CERT_TRUST_IS_PARTIAL_CHAIN 0x00010000
  13215. #define CERT_TRUST_CTL_IS_NOT_TIME_VALID 0x00020000
  13216. #define CERT_TRUST_CTL_IS_NOT_SIGNATURE_VALID 0x00040000
  13217. #define CERT_TRUST_CTL_IS_NOT_VALID_FOR_USAGE 0x00080000
  13218. //
  13219. // The following are info status bits
  13220. //
  13221. // These can be applied to certificates only
  13222. #define CERT_TRUST_HAS_EXACT_MATCH_ISSUER 0x00000001
  13223. #define CERT_TRUST_HAS_KEY_MATCH_ISSUER 0x00000002
  13224. #define CERT_TRUST_HAS_NAME_MATCH_ISSUER 0x00000004
  13225. #define CERT_TRUST_IS_SELF_SIGNED 0x00000008
  13226. // These can be applied to certificates and chains
  13227. #define CERT_TRUST_HAS_PREFERRED_ISSUER 0x00000100
  13228. #define CERT_TRUST_HAS_ISSUANCE_CHAIN_POLICY 0x00000200
  13229. #define CERT_TRUST_HAS_VALID_NAME_CONSTRAINTS 0x00000400
  13230. // These can be applied to chains only
  13231. #define CERT_TRUST_IS_COMPLEX_CHAIN 0x00010000
  13232. //
  13233. // Each certificate context in a simple chain has a corresponding chain element
  13234. // in the simple chain context
  13235. //
  13236. // dwErrorStatus has CERT_TRUST_IS_REVOKED, pRevocationInfo set
  13237. // dwErrorStatus has CERT_TRUST_REVOCATION_STATUS_UNKNOWN, pRevocationInfo set
  13238. //
  13239. // Note that the post processing revocation supported in the first
  13240. // version only sets cbSize and dwRevocationResult. Everything else
  13241. // is NULL
  13242. //
  13243. //
  13244. // Revocation Information
  13245. //
  13246. typedef struct _CERT_REVOCATION_INFO {
  13247. DWORD cbSize;
  13248. DWORD dwRevocationResult;
  13249. LPCSTR pszRevocationOid;
  13250. LPVOID pvOidSpecificInfo;
  13251. // fHasFreshnessTime is only set if we are able to retrieve revocation
  13252. // information. For a CRL its CurrentTime - ThisUpdate.
  13253. BOOL fHasFreshnessTime;
  13254. DWORD dwFreshnessTime; // seconds
  13255. // NonNULL for CRL base revocation checking
  13256. PCERT_REVOCATION_CRL_INFO pCrlInfo;
  13257. } CERT_REVOCATION_INFO, *PCERT_REVOCATION_INFO;
  13258. //
  13259. // Trust List Information
  13260. //
  13261. typedef struct _CERT_TRUST_LIST_INFO {
  13262. DWORD cbSize;
  13263. PCTL_ENTRY pCtlEntry;
  13264. PCCTL_CONTEXT pCtlContext;
  13265. } CERT_TRUST_LIST_INFO, *PCERT_TRUST_LIST_INFO;
  13266. //
  13267. // Chain Element
  13268. //
  13269. typedef struct _CERT_CHAIN_ELEMENT {
  13270. DWORD cbSize;
  13271. PCCERT_CONTEXT pCertContext;
  13272. CERT_TRUST_STATUS TrustStatus;
  13273. PCERT_REVOCATION_INFO pRevocationInfo;
  13274. PCERT_ENHKEY_USAGE pIssuanceUsage; // If NULL, any
  13275. PCERT_ENHKEY_USAGE pApplicationUsage; // If NULL, any
  13276. LPCWSTR pwszExtendedErrorInfo; // If NULL, none
  13277. } CERT_CHAIN_ELEMENT, *PCERT_CHAIN_ELEMENT;
  13278. //
  13279. // The simple chain is an array of chain elements and a summary trust status
  13280. // for the chain
  13281. //
  13282. // rgpElements[0] is the end certificate chain element
  13283. //
  13284. // rgpElements[cElement-1] is the self-signed "root" certificate chain element
  13285. //
  13286. typedef struct _CERT_SIMPLE_CHAIN {
  13287. DWORD cbSize;
  13288. CERT_TRUST_STATUS TrustStatus;
  13289. DWORD cElement;
  13290. PCERT_CHAIN_ELEMENT* rgpElement;
  13291. PCERT_TRUST_LIST_INFO pTrustListInfo;
  13292. // fHasRevocationFreshnessTime is only set if we are able to retrieve
  13293. // revocation information for all elements checked for revocation.
  13294. // For a CRL its CurrentTime - ThisUpdate.
  13295. //
  13296. // dwRevocationFreshnessTime is the largest time across all elements
  13297. // checked.
  13298. BOOL fHasRevocationFreshnessTime;
  13299. DWORD dwRevocationFreshnessTime; // seconds
  13300. } CERT_SIMPLE_CHAIN, *PCERT_SIMPLE_CHAIN;
  13301. //
  13302. // And the chain context contains an array of simple chains and summary trust
  13303. // status for all the connected simple chains
  13304. //
  13305. // rgpChains[0] is the end certificate simple chain
  13306. //
  13307. // rgpChains[cChain-1] is the final (possibly trust list signer) chain which
  13308. // ends in a certificate which is contained in the root store
  13309. //
  13310. typedef struct _CERT_CHAIN_CONTEXT CERT_CHAIN_CONTEXT, *PCERT_CHAIN_CONTEXT;
  13311. typedef const CERT_CHAIN_CONTEXT *PCCERT_CHAIN_CONTEXT;
  13312. struct _CERT_CHAIN_CONTEXT {
  13313. DWORD cbSize;
  13314. CERT_TRUST_STATUS TrustStatus;
  13315. DWORD cChain;
  13316. PCERT_SIMPLE_CHAIN* rgpChain;
  13317. // Following is returned when CERT_CHAIN_RETURN_LOWER_QUALITY_CONTEXTS
  13318. // is set in dwFlags
  13319. DWORD cLowerQualityChainContext;
  13320. PCCERT_CHAIN_CONTEXT* rgpLowerQualityChainContext;
  13321. // fHasRevocationFreshnessTime is only set if we are able to retrieve
  13322. // revocation information for all elements checked for revocation.
  13323. // For a CRL its CurrentTime - ThisUpdate.
  13324. //
  13325. // dwRevocationFreshnessTime is the largest time across all elements
  13326. // checked.
  13327. BOOL fHasRevocationFreshnessTime;
  13328. DWORD dwRevocationFreshnessTime; // seconds
  13329. };
  13330. //
  13331. // When building a chain, the there are various parameters used for finding
  13332. // issuing certificates and trust lists. They are identified in the
  13333. // following structure
  13334. //
  13335. // Default usage match type is AND with value zero
  13336. #define USAGE_MATCH_TYPE_AND 0x00000000
  13337. #define USAGE_MATCH_TYPE_OR 0x00000001
  13338. typedef struct _CERT_USAGE_MATCH {
  13339. DWORD dwType;
  13340. CERT_ENHKEY_USAGE Usage;
  13341. } CERT_USAGE_MATCH, *PCERT_USAGE_MATCH;
  13342. typedef struct _CTL_USAGE_MATCH {
  13343. DWORD dwType;
  13344. CTL_USAGE Usage;
  13345. } CTL_USAGE_MATCH, *PCTL_USAGE_MATCH;
  13346. typedef struct _CERT_CHAIN_PARA {
  13347. DWORD cbSize;
  13348. CERT_USAGE_MATCH RequestedUsage;
  13349. #ifdef CERT_CHAIN_PARA_HAS_EXTRA_FIELDS
  13350. // Note, if you #define CERT_CHAIN_PARA_HAS_EXTRA_FIELDS, then, you
  13351. // must zero all unused fields in this data structure.
  13352. // More fields could be added in a future release.
  13353. CERT_USAGE_MATCH RequestedIssuancePolicy;
  13354. DWORD dwUrlRetrievalTimeout; // milliseconds
  13355. BOOL fCheckRevocationFreshnessTime;
  13356. DWORD dwRevocationFreshnessTime; // seconds
  13357. #endif
  13358. } CERT_CHAIN_PARA, *PCERT_CHAIN_PARA;
  13359. //
  13360. // The following API is used for retrieving certificate chains
  13361. //
  13362. // Parameters:
  13363. //
  13364. // hChainEngine - the chain engine (namespace and cache) to use, NULL
  13365. // mean use the default chain engine
  13366. //
  13367. // pCertContext - the context we are retrieving the chain for, it
  13368. // will be the zero index element in the chain
  13369. //
  13370. // pTime - the point in time that we want the chain validated
  13371. // for. Note that the time does not affect trust list,
  13372. // revocation, or root store checking. NULL means use
  13373. // the current system time
  13374. //
  13375. // hAdditionalStore - additional store to use when looking up objects
  13376. //
  13377. // pChainPara - parameters for chain building
  13378. //
  13379. // dwFlags - flags such as should revocation checking be done
  13380. // on the chain?
  13381. //
  13382. // pvReserved - reserved parameter, must be NULL
  13383. //
  13384. // ppChainContext - chain context returned
  13385. //
  13386. // CERT_CHAIN_CACHE_END_CERT can be used here as well
  13387. // Revocation flags are in the high nibble
  13388. #define CERT_CHAIN_REVOCATION_CHECK_END_CERT 0x10000000
  13389. #define CERT_CHAIN_REVOCATION_CHECK_CHAIN 0x20000000
  13390. #define CERT_CHAIN_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT 0x40000000
  13391. #define CERT_CHAIN_REVOCATION_CHECK_CACHE_ONLY 0x80000000
  13392. // By default, the dwUrlRetrievalTimeout in pChainPara is the timeout used
  13393. // for each revocation URL wire retrieval. When the following flag is set,
  13394. // dwUrlRetrievalTimeout is the accumulative timeout across all
  13395. // revocation URL wire retrievals.
  13396. #define CERT_CHAIN_REVOCATION_ACCUMULATIVE_TIMEOUT 0x08000000
  13397. // First pass determines highest quality based upon:
  13398. // - Chain signature valid (higest quality bit of this set)
  13399. // - Complete chain
  13400. // - Trusted root (lowestest quality bit of this set)
  13401. // By default, second pass only considers paths >= highest first pass quality
  13402. #define CERT_CHAIN_DISABLE_PASS1_QUALITY_FILTERING 0x00000040
  13403. #define CERT_CHAIN_RETURN_LOWER_QUALITY_CONTEXTS 0x00000080
  13404. #define CERT_CHAIN_DISABLE_AUTH_ROOT_AUTO_UPDATE 0x00000100
  13405. // When this flag is set, pTime will be used as the timestamp time.
  13406. // pTime will be used to determine if the end certificate was valid at this
  13407. // time. Revocation checking will be relative to pTime.
  13408. // In addition, current time will also be used
  13409. // to determine if the certificate is still time valid. All remaining
  13410. // CA and root certificates will be checked using current time and not pTime.
  13411. //
  13412. // This flag was added 4/5/01 in WXP.
  13413. #define CERT_CHAIN_TIMESTAMP_TIME 0x00000200
  13414. WINCRYPT32API
  13415. BOOL
  13416. WINAPI
  13417. CertGetCertificateChain (
  13418. IN OPTIONAL HCERTCHAINENGINE hChainEngine,
  13419. IN PCCERT_CONTEXT pCertContext,
  13420. IN OPTIONAL LPFILETIME pTime,
  13421. IN OPTIONAL HCERTSTORE hAdditionalStore,
  13422. IN PCERT_CHAIN_PARA pChainPara,
  13423. IN DWORD dwFlags,
  13424. IN LPVOID pvReserved,
  13425. OUT PCCERT_CHAIN_CONTEXT* ppChainContext
  13426. );
  13427. //
  13428. // Free a certificate chain
  13429. //
  13430. WINCRYPT32API
  13431. VOID
  13432. WINAPI
  13433. CertFreeCertificateChain (
  13434. IN PCCERT_CHAIN_CONTEXT pChainContext
  13435. );
  13436. //
  13437. // Duplicate (add a reference to) a certificate chain
  13438. //
  13439. WINCRYPT32API
  13440. PCCERT_CHAIN_CONTEXT
  13441. WINAPI
  13442. CertDuplicateCertificateChain (
  13443. IN PCCERT_CHAIN_CONTEXT pChainContext
  13444. );
  13445. //
  13446. // Specific Revocation Type OID and structure definitions
  13447. //
  13448. //
  13449. // CRL Revocation OID
  13450. //
  13451. #define REVOCATION_OID_CRL_REVOCATION ((LPCSTR)1)
  13452. //
  13453. // For the CRL revocation OID the pvRevocationPara is NULL
  13454. //
  13455. //
  13456. // CRL Revocation Info
  13457. //
  13458. typedef struct _CRL_REVOCATION_INFO {
  13459. PCRL_ENTRY pCrlEntry;
  13460. PCCRL_CONTEXT pCrlContext;
  13461. PCCERT_CHAIN_CONTEXT pCrlIssuerChain;
  13462. } CRL_REVOCATION_INFO, *PCRL_REVOCATION_INFO;
  13463. //+-------------------------------------------------------------------------
  13464. // Find the first or next certificate chain context in the store.
  13465. //
  13466. // The chain context is found according to the dwFindFlags, dwFindType and
  13467. // its pvFindPara. See below for a list of the find types and its parameters.
  13468. //
  13469. // If the first or next chain context isn't found, NULL is returned.
  13470. // Otherwise, a pointer to a read only CERT_CHAIN_CONTEXT is returned.
  13471. // CERT_CHAIN_CONTEXT must be freed by calling CertFreeCertificateChain
  13472. // or is freed when passed as the
  13473. // pPrevChainContext on a subsequent call. CertDuplicateCertificateChain
  13474. // can be called to make a duplicate.
  13475. //
  13476. // pPrevChainContext MUST BE NULL on the first
  13477. // call to find the chain context. To find the next chain context, the
  13478. // pPrevChainContext is set to the CERT_CHAIN_CONTEXT returned by a previous
  13479. // call.
  13480. //
  13481. // NOTE: a NON-NULL pPrevChainContext is always CertFreeCertificateChain'ed by
  13482. // this function, even for an error.
  13483. //--------------------------------------------------------------------------
  13484. WINCRYPT32API
  13485. PCCERT_CHAIN_CONTEXT
  13486. WINAPI
  13487. CertFindChainInStore(
  13488. IN HCERTSTORE hCertStore,
  13489. IN DWORD dwCertEncodingType,
  13490. IN DWORD dwFindFlags,
  13491. IN DWORD dwFindType,
  13492. IN const void *pvFindPara,
  13493. IN PCCERT_CHAIN_CONTEXT pPrevChainContext
  13494. );
  13495. #define CERT_CHAIN_FIND_BY_ISSUER 1
  13496. //+-------------------------------------------------------------------------
  13497. // CERT_CHAIN_FIND_BY_ISSUER
  13498. //
  13499. // Find a certificate chain having a private key for the end certificate and
  13500. // matching one of the given issuer names. A matching dwKeySpec and
  13501. // enhanced key usage can also be specified. Additionally a callback can
  13502. // be provided for even more caller provided filtering before building the
  13503. // chain.
  13504. //
  13505. // By default, only the issuers in the first simple chain are compared
  13506. // for a name match. CERT_CHAIN_FIND_BY_ISSUER_COMPLEX_CHAIN_FLAG can
  13507. // be set in dwFindFlags to match issuers in all the simple chains.
  13508. //
  13509. // CERT_CHAIN_FIND_BY_ISSUER_NO_KEY_FLAG can be set in dwFindFlags to
  13510. // not check if the end certificate has a private key.
  13511. //
  13512. // CERT_CHAIN_FIND_BY_ISSUER_COMPARE_KEY_FLAG can be set in dwFindFlags
  13513. // to compare the public key in the end certificate with the crypto
  13514. // provider's public key. The dwAcquirePrivateKeyFlags can be set
  13515. // in CERT_CHAIN_FIND_BY_ISSUER_PARA to enable caching of the private key's
  13516. // HKEY returned by the CSP.
  13517. //
  13518. // If dwCertEncodingType == 0, defaults to X509_ASN_ENCODING for the
  13519. // array of encoded issuer names.
  13520. //
  13521. // By default, the hCertStore passed to CertFindChainInStore, is passed
  13522. // as an additional store to CertGetCertificateChain.
  13523. // CERT_CHAIN_FIND_BY_ISSUER_CACHE_ONLY_FLAG can be set in dwFindFlags
  13524. // to improve performance by only searching the cached system stores
  13525. // (root, my, ca, trust) to find the issuer certificates. If you are doing
  13526. // a find in the "my" system store, than, this flag should be set to
  13527. // improve performance.
  13528. //
  13529. // Setting CERT_CHAIN_FIND_BY_ISSUER_LOCAL_MACHINE_FLAG in dwFindFlags
  13530. // restricts CertGetCertificateChain to search the Local Machine
  13531. // cached system stores instead of the Current User's.
  13532. //
  13533. // Setting CERT_CHAIN_FIND_BY_ISSUER_CACHE_ONLY_URL_FLAG in dwFindFlags
  13534. // restricts CertGetCertificateChain to only search the URL cache
  13535. // and not hit the wire.
  13536. //--------------------------------------------------------------------------
  13537. // Returns FALSE to skip this certificate. Otherwise, returns TRUE to
  13538. // build a chain for this certificate.
  13539. typedef BOOL (WINAPI *PFN_CERT_CHAIN_FIND_BY_ISSUER_CALLBACK)(
  13540. IN PCCERT_CONTEXT pCert,
  13541. IN void *pvFindArg
  13542. );
  13543. typedef struct _CERT_CHAIN_FIND_BY_ISSUER_PARA {
  13544. DWORD cbSize;
  13545. // If pszUsageIdentifier == NULL, matches any usage.
  13546. LPCSTR pszUsageIdentifier;
  13547. // If dwKeySpec == 0, matches any KeySpec
  13548. DWORD dwKeySpec;
  13549. // When CERT_CHAIN_FIND_BY_ISSUER_COMPARE_KEY_FLAG is set in dwFindFlags,
  13550. // CryptAcquireCertificatePrivateKey is called to do the public key
  13551. // comparison. The following flags can be set to enable caching
  13552. // of the acquired private key or suppress CSP UI. See the API for more
  13553. // details on these flags.
  13554. DWORD dwAcquirePrivateKeyFlags;
  13555. // Pointer to an array of X509, ASN.1 encoded issuer name blobs. If
  13556. // cIssuer == 0, matches any issuer
  13557. DWORD cIssuer;
  13558. CERT_NAME_BLOB *rgIssuer;
  13559. // If NULL or Callback returns TRUE, builds the chain for the end
  13560. // certificate having a private key with the specified KeySpec and
  13561. // enhanced key usage.
  13562. PFN_CERT_CHAIN_FIND_BY_ISSUER_CALLBACK pfnFindCallback;
  13563. void *pvFindArg;
  13564. #ifdef CERT_CHAIN_FIND_BY_ISSUER_PARA_HAS_EXTRA_FIELDS
  13565. // Note, if you #define CERT_CHAIN_FIND_BY_ISSUER_PARA_HAS_EXTRA_FIELDS,
  13566. // then, you must zero all unused fields in this data structure.
  13567. // More fields could be added in a future release.
  13568. // If the following pointers are nonNull, returns the index of the
  13569. // matching issuer certificate, which is at:
  13570. // pChainContext->
  13571. // rgpChain[*pdwIssuerChainIndex]->rgpElement[*pdwIssuerElementIndex].
  13572. //
  13573. // The issuer name blob is compared against the Issuer field in the
  13574. // certificate. The *pdwIssuerElementIndex is set to the index of this
  13575. // subject certificate + 1. Therefore, its possible for a partial chain or
  13576. // a self signed certificate matching the name blob, where
  13577. // *pdwIssuerElementIndex points past the last certificate in the chain.
  13578. //
  13579. // Note, not updated if the above cIssuer == 0.
  13580. DWORD *pdwIssuerChainIndex;
  13581. DWORD *pdwIssuerElementIndex;
  13582. #endif
  13583. } CERT_CHAIN_FIND_ISSUER_PARA, *PCERT_CHAIN_FIND_ISSUER_PARA,
  13584. CERT_CHAIN_FIND_BY_ISSUER_PARA, *PCERT_CHAIN_FIND_BY_ISSUER_PARA;
  13585. // The following dwFindFlags can be set for CERT_CHAIN_FIND_BY_ISSUER
  13586. // If set, compares the public key in the end certificate with the crypto
  13587. // provider's public key. This comparison is the last check made on the
  13588. // build chain.
  13589. #define CERT_CHAIN_FIND_BY_ISSUER_COMPARE_KEY_FLAG 0x0001
  13590. // If not set, only checks the first simple chain for an issuer name match.
  13591. // When set, also checks second and subsequent simple chains.
  13592. #define CERT_CHAIN_FIND_BY_ISSUER_COMPLEX_CHAIN_FLAG 0x0002
  13593. // If set, CertGetCertificateChain only searches the URL cache and
  13594. // doesn't hit the wire.
  13595. #define CERT_CHAIN_FIND_BY_ISSUER_CACHE_ONLY_URL_FLAG 0x0004
  13596. // If set, CertGetCertificateChain only opens the Local Machine
  13597. // certificate stores instead of the Current User's.
  13598. #define CERT_CHAIN_FIND_BY_ISSUER_LOCAL_MACHINE_FLAG 0x0008
  13599. // If set, no check is made to see if the end certificate has a private
  13600. // key associated with it.
  13601. #define CERT_CHAIN_FIND_BY_ISSUER_NO_KEY_FLAG 0x4000
  13602. // By default, the hCertStore passed to CertFindChainInStore, is passed
  13603. // as the additional store to CertGetCertificateChain. This flag can be
  13604. // set to improve performance by only searching the cached system stores
  13605. // (root, my, ca, trust) to find the issuer certificates. If not set, then,
  13606. // the hCertStore is always searched in addition to the cached system
  13607. // stores.
  13608. #define CERT_CHAIN_FIND_BY_ISSUER_CACHE_ONLY_FLAG 0x8000
  13609. //+=========================================================================
  13610. // Certificate Chain Policy Data Structures and APIs
  13611. //==========================================================================
  13612. typedef struct _CERT_CHAIN_POLICY_PARA {
  13613. DWORD cbSize;
  13614. DWORD dwFlags;
  13615. void *pvExtraPolicyPara; // pszPolicyOID specific
  13616. } CERT_CHAIN_POLICY_PARA, *PCERT_CHAIN_POLICY_PARA;
  13617. // If both lChainIndex and lElementIndex are set to -1, the dwError applies
  13618. // to the whole chain context. If only lElementIndex is set to -1, the
  13619. // dwError applies to the lChainIndex'ed chain. Otherwise, the dwError applies
  13620. // to the certificate element at
  13621. // pChainContext->rgpChain[lChainIndex]->rgpElement[lElementIndex].
  13622. typedef struct _CERT_CHAIN_POLICY_STATUS {
  13623. DWORD cbSize;
  13624. DWORD dwError;
  13625. LONG lChainIndex;
  13626. LONG lElementIndex;
  13627. void *pvExtraPolicyStatus; // pszPolicyOID specific
  13628. } CERT_CHAIN_POLICY_STATUS, *PCERT_CHAIN_POLICY_STATUS;
  13629. // Common chain policy flags
  13630. #define CERT_CHAIN_POLICY_IGNORE_NOT_TIME_VALID_FLAG 0x00000001
  13631. #define CERT_CHAIN_POLICY_IGNORE_CTL_NOT_TIME_VALID_FLAG 0x00000002
  13632. #define CERT_CHAIN_POLICY_IGNORE_NOT_TIME_NESTED_FLAG 0x00000004
  13633. #define CERT_CHAIN_POLICY_IGNORE_INVALID_BASIC_CONSTRAINTS_FLAG 0x00000008
  13634. #define CERT_CHAIN_POLICY_IGNORE_ALL_NOT_TIME_VALID_FLAGS ( \
  13635. CERT_CHAIN_POLICY_IGNORE_NOT_TIME_VALID_FLAG | \
  13636. CERT_CHAIN_POLICY_IGNORE_CTL_NOT_TIME_VALID_FLAG | \
  13637. CERT_CHAIN_POLICY_IGNORE_NOT_TIME_NESTED_FLAG \
  13638. )
  13639. #define CERT_CHAIN_POLICY_ALLOW_UNKNOWN_CA_FLAG 0x00000010
  13640. #define CERT_CHAIN_POLICY_IGNORE_WRONG_USAGE_FLAG 0x00000020
  13641. #define CERT_CHAIN_POLICY_IGNORE_INVALID_NAME_FLAG 0x00000040
  13642. #define CERT_CHAIN_POLICY_IGNORE_INVALID_POLICY_FLAG 0x00000080
  13643. #define CERT_CHAIN_POLICY_IGNORE_END_REV_UNKNOWN_FLAG 0x00000100
  13644. #define CERT_CHAIN_POLICY_IGNORE_CTL_SIGNER_REV_UNKNOWN_FLAG 0x00000200
  13645. #define CERT_CHAIN_POLICY_IGNORE_CA_REV_UNKNOWN_FLAG 0x00000400
  13646. #define CERT_CHAIN_POLICY_IGNORE_ROOT_REV_UNKNOWN_FLAG 0x00000800
  13647. #define CERT_CHAIN_POLICY_IGNORE_ALL_REV_UNKNOWN_FLAGS ( \
  13648. CERT_CHAIN_POLICY_IGNORE_END_REV_UNKNOWN_FLAG | \
  13649. CERT_CHAIN_POLICY_IGNORE_CTL_SIGNER_REV_UNKNOWN_FLAG | \
  13650. CERT_CHAIN_POLICY_IGNORE_CA_REV_UNKNOWN_FLAG | \
  13651. CERT_CHAIN_POLICY_IGNORE_ROOT_REV_UNKNOWN_FLAG \
  13652. )
  13653. #define CERT_CHAIN_POLICY_ALLOW_TESTROOT_FLAG 0x00008000
  13654. #define CERT_CHAIN_POLICY_TRUST_TESTROOT_FLAG 0x00004000
  13655. //+-------------------------------------------------------------------------
  13656. // Verify that the certificate chain satisfies the specified policy
  13657. // requirements. If we were able to verify the chain policy, TRUE is returned
  13658. // and the dwError field of the pPolicyStatus is updated. A dwError of 0
  13659. // (ERROR_SUCCESS, S_OK) indicates the chain satisfies the specified policy.
  13660. //
  13661. // If dwError applies to the entire chain context, both lChainIndex and
  13662. // lElementIndex are set to -1. If dwError applies to a simple chain,
  13663. // lElementIndex is set to -1 and lChainIndex is set to the index of the
  13664. // first offending chain having the error. If dwError applies to a
  13665. // certificate element, lChainIndex and lElementIndex are updated to
  13666. // index the first offending certificate having the error, where, the
  13667. // the certificate element is at:
  13668. // pChainContext->rgpChain[lChainIndex]->rgpElement[lElementIndex].
  13669. //
  13670. // The dwFlags in pPolicyPara can be set to change the default policy checking
  13671. // behaviour. In addition, policy specific parameters can be passed in
  13672. // the pvExtraPolicyPara field of pPolicyPara.
  13673. //
  13674. // In addition to returning dwError, in pPolicyStatus, policy OID specific
  13675. // extra status may be returned via pvExtraPolicyStatus.
  13676. //--------------------------------------------------------------------------
  13677. WINCRYPT32API
  13678. BOOL
  13679. WINAPI
  13680. CertVerifyCertificateChainPolicy(
  13681. IN LPCSTR pszPolicyOID,
  13682. IN PCCERT_CHAIN_CONTEXT pChainContext,
  13683. IN PCERT_CHAIN_POLICY_PARA pPolicyPara,
  13684. IN OUT PCERT_CHAIN_POLICY_STATUS pPolicyStatus
  13685. );
  13686. // Predefined OID Function Names
  13687. #define CRYPT_OID_VERIFY_CERTIFICATE_CHAIN_POLICY_FUNC \
  13688. "CertDllVerifyCertificateChainPolicy"
  13689. // CertDllVerifyCertificateChainPolicy has same function signature as
  13690. // CertVerifyCertificateChainPolicy.
  13691. //+-------------------------------------------------------------------------
  13692. // Predefined verify chain policies
  13693. //--------------------------------------------------------------------------
  13694. #define CERT_CHAIN_POLICY_BASE ((LPCSTR) 1)
  13695. #define CERT_CHAIN_POLICY_AUTHENTICODE ((LPCSTR) 2)
  13696. #define CERT_CHAIN_POLICY_AUTHENTICODE_TS ((LPCSTR) 3)
  13697. #define CERT_CHAIN_POLICY_SSL ((LPCSTR) 4)
  13698. #define CERT_CHAIN_POLICY_BASIC_CONSTRAINTS ((LPCSTR) 5)
  13699. #define CERT_CHAIN_POLICY_NT_AUTH ((LPCSTR) 6)
  13700. #define CERT_CHAIN_POLICY_MICROSOFT_ROOT ((LPCSTR) 7)
  13701. //+-------------------------------------------------------------------------
  13702. // CERT_CHAIN_POLICY_BASE
  13703. //
  13704. // Implements the base chain policy verification checks. dwFlags can
  13705. // be set in pPolicyPara to alter the default policy checking behaviour.
  13706. //--------------------------------------------------------------------------
  13707. //+-------------------------------------------------------------------------
  13708. // CERT_CHAIN_POLICY_AUTHENTICODE
  13709. //
  13710. // Implements the Authenticode chain policy verification checks.
  13711. //
  13712. // pvExtraPolicyPara may optionally be set to point to the following
  13713. // AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_PARA.
  13714. //
  13715. // pvExtraPolicyStatus may optionally be set to point to the following
  13716. // AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_STATUS.
  13717. //--------------------------------------------------------------------------
  13718. // dwRegPolicySettings are defined in wintrust.h
  13719. typedef struct _AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_PARA {
  13720. DWORD cbSize;
  13721. DWORD dwRegPolicySettings;
  13722. PCMSG_SIGNER_INFO pSignerInfo; // optional
  13723. } AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_PARA,
  13724. *PAUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_PARA;
  13725. typedef struct _AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_STATUS {
  13726. DWORD cbSize;
  13727. BOOL fCommercial; // obtained from signer statement
  13728. } AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_STATUS,
  13729. *PAUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_STATUS;
  13730. //+-------------------------------------------------------------------------
  13731. // CERT_CHAIN_POLICY_AUTHENTICODE_TS
  13732. //
  13733. // Implements the Authenticode Time Stamp chain policy verification checks.
  13734. //
  13735. // pvExtraPolicyPara may optionally be set to point to the following
  13736. // AUTHENTICODE_TS_EXTRA_CERT_CHAIN_POLICY_PARA.
  13737. //
  13738. // pvExtraPolicyStatus isn't used and must be set to NULL.
  13739. //--------------------------------------------------------------------------
  13740. // dwRegPolicySettings are defined in wintrust.h
  13741. typedef struct _AUTHENTICODE_TS_EXTRA_CERT_CHAIN_POLICY_PARA {
  13742. DWORD cbSize;
  13743. DWORD dwRegPolicySettings;
  13744. BOOL fCommercial;
  13745. } AUTHENTICODE_TS_EXTRA_CERT_CHAIN_POLICY_PARA,
  13746. *PAUTHENTICODE_TS_EXTRA_CERT_CHAIN_POLICY_PARA;
  13747. //+-------------------------------------------------------------------------
  13748. // CERT_CHAIN_POLICY_SSL
  13749. //
  13750. // Implements the SSL client/server chain policy verification checks.
  13751. //
  13752. // pvExtraPolicyPara may optionally be set to point to the following
  13753. // SSL_EXTRA_CERT_CHAIN_POLICY_PARA data structure
  13754. //--------------------------------------------------------------------------
  13755. // fdwChecks flags are defined in wininet.h
  13756. typedef struct _HTTPSPolicyCallbackData
  13757. {
  13758. union {
  13759. DWORD cbStruct; // sizeof(HTTPSPolicyCallbackData);
  13760. DWORD cbSize; // sizeof(HTTPSPolicyCallbackData);
  13761. };
  13762. DWORD dwAuthType;
  13763. # define AUTHTYPE_CLIENT 1
  13764. # define AUTHTYPE_SERVER 2
  13765. DWORD fdwChecks;
  13766. WCHAR *pwszServerName; // used to check against CN=xxxx
  13767. } HTTPSPolicyCallbackData, *PHTTPSPolicyCallbackData,
  13768. SSL_EXTRA_CERT_CHAIN_POLICY_PARA, *PSSL_EXTRA_CERT_CHAIN_POLICY_PARA;
  13769. //+-------------------------------------------------------------------------
  13770. // CERT_CHAIN_POLICY_BASIC_CONSTRAINTS
  13771. //
  13772. // Implements the basic constraints chain policy.
  13773. //
  13774. // Iterates through all the certificates in the chain checking for either
  13775. // a szOID_BASIC_CONSTRAINTS or a szOID_BASIC_CONSTRAINTS2 extension. If
  13776. // neither extension is present, the certificate is assumed to have
  13777. // valid policy. Otherwise, for the first certificate element, checks if
  13778. // it matches the expected CA_FLAG or END_ENTITY_FLAG specified in
  13779. // pPolicyPara->dwFlags. If neither or both flags are set, then, the first
  13780. // element can be either a CA or END_ENTITY. All other elements must be
  13781. // a CA. If the PathLenConstraint is present in the extension, its
  13782. // checked.
  13783. //
  13784. // The first elements in the remaining simple chains (ie, the certificate
  13785. // used to sign the CTL) are checked to be an END_ENTITY.
  13786. //
  13787. // If this verification fails, dwError will be set to
  13788. // TRUST_E_BASIC_CONSTRAINTS.
  13789. //--------------------------------------------------------------------------
  13790. #define BASIC_CONSTRAINTS_CERT_CHAIN_POLICY_CA_FLAG 0x80000000
  13791. #define BASIC_CONSTRAINTS_CERT_CHAIN_POLICY_END_ENTITY_FLAG 0x40000000
  13792. //+-------------------------------------------------------------------------
  13793. // CERT_CHAIN_POLICY_NT_AUTH
  13794. //
  13795. // Implements the NT Authentication chain policy.
  13796. //
  13797. // The NT Authentication chain policy consists of 3 distinct chain
  13798. // verifications in the following order:
  13799. // [1] CERT_CHAIN_POLICY_BASE - Implements the base chain policy
  13800. // verification checks. The LOWORD of dwFlags can be set in
  13801. // pPolicyPara to alter the default policy checking behaviour. See
  13802. // CERT_CHAIN_POLICY_BASE for more details.
  13803. //
  13804. // [2] CERT_CHAIN_POLICY_BASIC_CONSTRAINTS - Implements the basic
  13805. // constraints chain policy. The HIWORD of dwFlags can be set
  13806. // to specify if the first element must be either a CA or END_ENTITY.
  13807. // See CERT_CHAIN_POLICY_BASIC_CONSTRAINTS for more details.
  13808. //
  13809. // [3] Checks if the second element in the chain, the CA that issued
  13810. // the end certificate, is a trusted CA for NT
  13811. // Authentication. A CA is considered to be trusted if it exists in
  13812. // the "NTAuth" system registry store found in the
  13813. // CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE store location.
  13814. // If this verification fails, whereby the CA isn't trusted,
  13815. // dwError is set to CERT_E_UNTRUSTEDCA.
  13816. //
  13817. // If CERT_PROT_ROOT_DISABLE_NT_AUTH_REQUIRED_FLAG is set
  13818. // in the "Flags" value of the HKLM policy "ProtectedRoots" subkey
  13819. // defined by CERT_PROT_ROOT_FLAGS_REGPATH, then,
  13820. // if the above check fails, checks if the chain
  13821. // has CERT_TRUST_HAS_VALID_NAME_CONSTRAINTS set in dwInfoStatus. This
  13822. // will only be set if there was a valid name constraint for all
  13823. // name spaces including UPN. If the chain doesn't have this info
  13824. // status set, dwError is set to CERT_E_UNTRUSTEDCA.
  13825. //--------------------------------------------------------------------------
  13826. //+-------------------------------------------------------------------------
  13827. // CERT_CHAIN_POLICY_MICROSOFT_ROOT
  13828. //
  13829. // Checks if the last element of the first simple chain contains a
  13830. // Microsoft root public key. If it doesn't contain a Microsoft root
  13831. // public key, dwError is set to CERT_E_UNTRUSTEDROOT.
  13832. //
  13833. // pPolicyPara is optional. However,
  13834. // MICROSOFT_ROOT_CERT_CHAIN_POLICY_ENABLE_TEST_ROOT_FLAG can be set in
  13835. // the dwFlags in pPolicyPara to also check for the Microsoft Test Roots.
  13836. //
  13837. // pvExtraPolicyPara and pvExtraPolicyStatus aren't used and must be set
  13838. // to NULL.
  13839. //--------------------------------------------------------------------------
  13840. #define MICROSOFT_ROOT_CERT_CHAIN_POLICY_ENABLE_TEST_ROOT_FLAG 0x00010000
  13841. //+-------------------------------------------------------------------------
  13842. // convert formatted string to binary
  13843. // If cchString is 0, then pszString is NULL terminated and
  13844. // cchString is obtained via strlen() + 1.
  13845. // dwFlags defines string format
  13846. // if pbBinary is NULL, *pcbBinary returns the size of required memory
  13847. // *pdwSkip returns the character count of skipped strings, optional
  13848. // *pdwFlags returns the actual format used in the conversion, optional
  13849. //--------------------------------------------------------------------------
  13850. WINCRYPT32STRINGAPI
  13851. BOOL
  13852. WINAPI
  13853. CryptStringToBinary%(
  13854. IN LPCTSTR% pszString,
  13855. IN DWORD cchString,
  13856. IN DWORD dwFlags,
  13857. IN BYTE *pbBinary,
  13858. IN OUT DWORD *pcbBinary,
  13859. OUT DWORD *pdwSkip, //OPTIONAL
  13860. OUT DWORD *pdwFlags //OPTIONAL
  13861. );
  13862. //+-------------------------------------------------------------------------
  13863. // convert binary to formatted string
  13864. // dwFlags defines string format
  13865. // if pszString is NULL, *pcchString returns size in characters
  13866. // including null-terminator
  13867. //--------------------------------------------------------------------------
  13868. WINCRYPT32STRINGAPI
  13869. BOOL
  13870. WINAPI
  13871. CryptBinaryToString%(
  13872. IN CONST BYTE *pbBinary,
  13873. IN DWORD cbBinary,
  13874. IN DWORD dwFlags,
  13875. IN LPTSTR% pszString,
  13876. IN OUT DWORD *pcchString
  13877. );
  13878. // dwFlags has the following defines
  13879. #define CRYPT_STRING_BASE64HEADER 0x00000000
  13880. #define CRYPT_STRING_BASE64 0x00000001
  13881. #define CRYPT_STRING_BINARY 0x00000002
  13882. #define CRYPT_STRING_BASE64REQUESTHEADER 0x00000003
  13883. #define CRYPT_STRING_HEX 0x00000004
  13884. #define CRYPT_STRING_HEXASCII 0x00000005
  13885. #define CRYPT_STRING_BASE64_ANY 0x00000006
  13886. #define CRYPT_STRING_ANY 0x00000007
  13887. #define CRYPT_STRING_HEX_ANY 0x00000008
  13888. #define CRYPT_STRING_BASE64X509CRLHEADER 0x00000009
  13889. #define CRYPT_STRING_HEXADDR 0x0000000a
  13890. #define CRYPT_STRING_HEXASCIIADDR 0x0000000b
  13891. #define CRYPT_STRING_NOCR 0x80000000
  13892. // CryptBinaryToString uses the following flags
  13893. // CRYPT_STRING_BASE64HEADER - base64 format with certificate begin
  13894. // and end headers
  13895. // CRYPT_STRING_BASE64 - only base64 without headers
  13896. // CRYPT_STRING_BINARY - pure binary copy
  13897. // CRYPT_STRING_BASE64REQUESTHEADER - base64 format with request begin
  13898. // and end headers
  13899. // CRYPT_STRING_BASE64X509CRLHEADER - base64 format with x509 crl begin
  13900. // and end headers
  13901. // CRYPT_STRING_HEX - only hex format
  13902. // CRYPT_STRING_HEXASCII - hex format with ascii char display
  13903. // CRYPT_STRING_HEXADDR - hex format with address display
  13904. // CRYPT_STRING_HEXASCIIADDR - hex format with ascii char and address display
  13905. //
  13906. // CryptBinaryToString accepts CRYPT_STRING_NOCR or'd into one of the above.
  13907. // When set, line breaks contain only LF, instead of CR-LF pairs.
  13908. // CryptStringToBinary uses the following flags
  13909. // CRYPT_STRING_BASE64_ANY tries the following, in order:
  13910. // CRYPT_STRING_BASE64HEADER
  13911. // CRYPT_STRING_BASE64
  13912. // CRYPT_STRING_ANY tries the following, in order:
  13913. // CRYPT_STRING_BASE64_ANY
  13914. // CRYPT_STRING_BINARY -- should always succeed
  13915. // CRYPT_STRING_HEX_ANY tries the following, in order:
  13916. // CRYPT_STRING_HEXADDR
  13917. // CRYPT_STRING_HEXASCIIADDR
  13918. // CRYPT_STRING_HEXASCII
  13919. // CRYPT_STRING_HEX
  13920. //+=========================================================================
  13921. // PFX (PKCS #12) function defintions and types
  13922. //==========================================================================
  13923. //+-------------------------------------------------------------------------
  13924. // PFXImportCertStore
  13925. //
  13926. // Import the PFX blob and return a store containing certificates
  13927. //
  13928. // If the password parameter is incorrect or any other problems decoding
  13929. // the PFX blob are encountered, the function will return NULL and the
  13930. // error code can be found from GetLastError().
  13931. //
  13932. // The dwFlags parameter may be set to the following:
  13933. // CRYPT_EXPORTABLE - specify that any imported keys should be marked as
  13934. // exportable (see documentation on CryptImportKey)
  13935. // CRYPT_USER_PROTECTED - (see documentation on CryptImportKey)
  13936. // CRYPT_MACHINE_KEYSET - used to force the private key to be stored in the
  13937. // the local machine and not the current user.
  13938. // CRYPT_USER_KEYSET - used to force the private key to be stored in the
  13939. // the current user and not the local machine, even if
  13940. // the pfx blob specifies that it should go into local
  13941. // machine.
  13942. //--------------------------------------------------------------------------
  13943. WINCRYPT32API
  13944. HCERTSTORE
  13945. WINAPI
  13946. PFXImportCertStore(
  13947. IN CRYPT_DATA_BLOB* pPFX,
  13948. IN LPCWSTR szPassword,
  13949. IN DWORD dwFlags);
  13950. // dwFlags definitions for PFXImportCertStore
  13951. //#define CRYPT_EXPORTABLE 0x00000001 // CryptImportKey dwFlags
  13952. //#define CRYPT_USER_PROTECTED 0x00000002 // CryptImportKey dwFlags
  13953. //#define CRYPT_MACHINE_KEYSET 0x00000020 // CryptAcquireContext dwFlags
  13954. #define CRYPT_USER_KEYSET 0x00001000
  13955. #define PKCS12_IMPORT_RESERVED_MASK 0xffff0000
  13956. //+-------------------------------------------------------------------------
  13957. // PFXIsPFXBlob
  13958. //
  13959. // This function will try to decode the outer layer of the blob as a pfx
  13960. // blob, and if that works it will return TRUE, it will return FALSE otherwise
  13961. //
  13962. //--------------------------------------------------------------------------
  13963. WINCRYPT32API
  13964. BOOL
  13965. WINAPI
  13966. PFXIsPFXBlob(
  13967. IN CRYPT_DATA_BLOB* pPFX);
  13968. //+-------------------------------------------------------------------------
  13969. // PFXVerifyPassword
  13970. //
  13971. // This function will attempt to decode the outer layer of the blob as a pfx
  13972. // blob and decrypt with the given password. No data from the blob will be
  13973. // imported.
  13974. //
  13975. // Return value is TRUE if password appears correct, FALSE otherwise.
  13976. //
  13977. //--------------------------------------------------------------------------
  13978. WINCRYPT32API
  13979. BOOL
  13980. WINAPI
  13981. PFXVerifyPassword(
  13982. IN CRYPT_DATA_BLOB* pPFX,
  13983. IN LPCWSTR szPassword,
  13984. IN DWORD dwFlags);
  13985. //+-------------------------------------------------------------------------
  13986. // PFXExportCertStoreEx
  13987. //
  13988. // Export the certificates and private keys referenced in the passed-in store
  13989. //
  13990. // This API encodes the blob under a stronger algorithm. The resulting
  13991. // PKCS12 blobs are incompatible with the earlier PFXExportCertStore API.
  13992. //
  13993. // The value passed in the password parameter will be used to encrypt and
  13994. // verify the integrity of the PFX packet. If any problems encoding the store
  13995. // are encountered, the function will return FALSE and the error code can
  13996. // be found from GetLastError().
  13997. //
  13998. // The dwFlags parameter may be set to any combination of
  13999. // EXPORT_PRIVATE_KEYS
  14000. // REPORT_NO_PRIVATE_KEY
  14001. // REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY
  14002. //
  14003. // The encoded PFX blob is returned in *pPFX. If pPFX->pbData is NULL upon
  14004. // input, this is a length only calculation, whereby, pPFX->cbData is updated
  14005. // with the number of bytes required for the encoded blob. Otherwise,
  14006. // the memory pointed to by pPFX->pbData is updated with the encoded bytes
  14007. // and pPFX->cbData is updated with the encoded byte length.
  14008. //--------------------------------------------------------------------------
  14009. WINCRYPT32API
  14010. BOOL
  14011. WINAPI
  14012. PFXExportCertStoreEx(
  14013. IN HCERTSTORE hStore,
  14014. IN OUT CRYPT_DATA_BLOB* pPFX,
  14015. IN LPCWSTR szPassword,
  14016. IN void* pvReserved,
  14017. IN DWORD dwFlags);
  14018. // dwFlags definitions for PFXExportCertStoreEx
  14019. #define REPORT_NO_PRIVATE_KEY 0x0001
  14020. #define REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY 0x0002
  14021. #define EXPORT_PRIVATE_KEYS 0x0004
  14022. #define PKCS12_EXPORT_RESERVED_MASK 0xffff0000
  14023. //+-------------------------------------------------------------------------
  14024. // PFXExportCertStore
  14025. //
  14026. // Export the certificates and private keys referenced in the passed-in store
  14027. //
  14028. // This is an old API kept for compatibility with IE4 clients. New applications
  14029. // should call the above PfxExportCertStoreEx for enhanced security.
  14030. //--------------------------------------------------------------------------
  14031. WINCRYPT32API
  14032. BOOL
  14033. WINAPI
  14034. PFXExportCertStore(
  14035. IN HCERTSTORE hStore,
  14036. IN OUT CRYPT_DATA_BLOB* pPFX,
  14037. IN LPCWSTR szPassword,
  14038. IN DWORD dwFlags);
  14039. #ifdef __cplusplus
  14040. } // Balance extern "C" above
  14041. #endif
  14042. #if defined (_MSC_VER)
  14043. #if ( _MSC_VER >= 800 )
  14044. #if _MSC_VER >= 1200
  14045. #pragma warning(pop)
  14046. #else
  14047. #pragma warning(default:4201)
  14048. #endif
  14049. #endif
  14050. #endif
  14051. #endif // __WINCRYPT_H__