home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / C++ / FreeCommandLineTools.exe / Include / wincrypt.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-31  |  563.1 KB  |  14,161 lines

  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.  
  12. #ifndef __WINCRYPT_H__
  13. #pragma option push -b -a8 -pc -A- /*P_O_Push*/
  14. #define __WINCRYPT_H__
  15.  
  16. #if defined (_MSC_VER)
  17.  
  18. #if ( _MSC_VER >= 800 )
  19. #if _MSC_VER >= 1200
  20. #pragma warning(push)
  21. #endif
  22. #pragma warning(disable:4201)    /* Nameless struct/union */
  23. #endif
  24.  
  25. #if (_MSC_VER > 1020)
  26. #pragma once
  27. #endif
  28.  
  29. #endif
  30.  
  31.  
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35.  
  36. #ifndef _HRESULT_DEFINED
  37. #define _HRESULT_DEFINED
  38. typedef LONG HRESULT;
  39.  
  40. #endif // !_HRESULT_DEFINED
  41.  
  42. #ifndef WINADVAPI
  43. #define WINADVAPI
  44. #endif
  45.  
  46. #ifndef WINAPI
  47. #define WINAPI __stdcall
  48. #endif
  49.  
  50. #ifndef CALLBACK
  51. #define CALLBACK __stdcall
  52. #endif
  53.  
  54. #ifndef DECLSPEC_IMPORT
  55. #define DECLSPEC_IMPORT
  56. #endif
  57.  
  58. #ifndef CONST
  59. #define CONST const
  60. #endif
  61.  
  62. #ifndef IN
  63. #define IN
  64. #endif
  65.  
  66. #ifndef OUT
  67. #define OUT
  68. #endif
  69.  
  70. #ifndef OPTIONAL
  71. #define OPTIONAL
  72. #endif
  73.  
  74. #if !defined(_CRYPT32_)
  75. #define WINCRYPT32API DECLSPEC_IMPORT
  76. #else
  77. #define WINCRYPT32API
  78. #endif
  79.  
  80. //
  81. // Algorithm IDs and Flags
  82. //
  83.  
  84. // ALG_ID crackers
  85. #define GET_ALG_CLASS(x)                (x & (7 << 13))
  86. #define GET_ALG_TYPE(x)                 (x & (15 << 9))
  87. #define GET_ALG_SID(x)                  (x & (511))
  88.  
  89. // Algorithm classes
  90. #define ALG_CLASS_ANY                   (0)
  91. #define ALG_CLASS_SIGNATURE             (1 << 13)
  92. #define ALG_CLASS_MSG_ENCRYPT           (2 << 13)
  93. #define ALG_CLASS_DATA_ENCRYPT          (3 << 13)
  94. #define ALG_CLASS_HASH                  (4 << 13)
  95. #define ALG_CLASS_KEY_EXCHANGE          (5 << 13)
  96. #define ALG_CLASS_ALL                   (7 << 13)
  97.  
  98. // Algorithm types
  99. #define ALG_TYPE_ANY                    (0)
  100. #define ALG_TYPE_DSS                    (1 << 9)
  101. #define ALG_TYPE_RSA                    (2 << 9)
  102. #define ALG_TYPE_BLOCK                  (3 << 9)
  103. #define ALG_TYPE_STREAM                 (4 << 9)
  104. #define ALG_TYPE_DH                     (5 << 9)
  105. #define ALG_TYPE_SECURECHANNEL          (6 << 9)
  106.  
  107. // Generic sub-ids
  108. #define ALG_SID_ANY                     (0)
  109.  
  110. // Some RSA sub-ids
  111. #define ALG_SID_RSA_ANY                 0
  112. #define ALG_SID_RSA_PKCS                1
  113. #define ALG_SID_RSA_MSATWORK            2
  114. #define ALG_SID_RSA_ENTRUST             3
  115. #define ALG_SID_RSA_PGP                 4
  116.  
  117. // Some DSS sub-ids
  118. //
  119. #define ALG_SID_DSS_ANY                 0
  120. #define ALG_SID_DSS_PKCS                1
  121. #define ALG_SID_DSS_DMS                 2
  122.  
  123. // Block cipher sub ids
  124. // DES sub_ids
  125. #define ALG_SID_DES                     1
  126. #define ALG_SID_3DES                    3
  127. #define ALG_SID_DESX                    4
  128. #define ALG_SID_IDEA                    5
  129. #define ALG_SID_CAST                    6
  130. #define ALG_SID_SAFERSK64               7
  131. #define ALG_SID_SAFERSK128              8
  132. #define ALG_SID_3DES_112                9
  133. #define ALG_SID_CYLINK_MEK              12
  134. #define ALG_SID_RC5                     13
  135.  
  136. // Fortezza sub-ids
  137. #define ALG_SID_SKIPJACK                10
  138. #define ALG_SID_TEK                     11
  139.  
  140. // KP_MODE
  141. #define CRYPT_MODE_CBCI                 6       // ANSI CBC Interleaved
  142. #define CRYPT_MODE_CFBP                 7       // ANSI CFB Pipelined
  143. #define CRYPT_MODE_OFBP                 8       // ANSI OFB Pipelined
  144. #define CRYPT_MODE_CBCOFM               9       // ANSI CBC + OF Masking
  145. #define CRYPT_MODE_CBCOFMI              10      // ANSI CBC + OFM Interleaved
  146.  
  147. // RC2 sub-ids
  148. #define ALG_SID_RC2                     2
  149.  
  150. // Stream cipher sub-ids
  151. #define ALG_SID_RC4                     1
  152. #define ALG_SID_SEAL                    2
  153.  
  154. // Diffie-Hellman sub-ids
  155. #define ALG_SID_DH_SANDF                1
  156. #define ALG_SID_DH_EPHEM                2
  157. #define ALG_SID_AGREED_KEY_ANY          3
  158. #define ALG_SID_KEA                     4
  159.  
  160. // Hash sub ids
  161. #define ALG_SID_MD2                     1
  162. #define ALG_SID_MD4                     2
  163. #define ALG_SID_MD5                     3
  164. #define ALG_SID_SHA                     4
  165. #define ALG_SID_SHA1                    4
  166. #define ALG_SID_MAC                     5
  167. #define ALG_SID_RIPEMD                  6
  168. #define ALG_SID_RIPEMD160               7
  169. #define ALG_SID_SSL3SHAMD5              8
  170. #define ALG_SID_HMAC                    9
  171. #define    ALG_SID_TLS1PRF                    10
  172.  
  173. // secure channel sub ids
  174. #define ALG_SID_SSL3_MASTER             1
  175. #define ALG_SID_SCHANNEL_MASTER_HASH    2
  176. #define ALG_SID_SCHANNEL_MAC_KEY        3
  177. #define ALG_SID_PCT1_MASTER             4
  178. #define ALG_SID_SSL2_MASTER             5
  179. #define ALG_SID_TLS1_MASTER             6
  180. #define ALG_SID_SCHANNEL_ENC_KEY        7
  181.  
  182. // Our silly example sub-id
  183. #define ALG_SID_EXAMPLE                 80
  184.  
  185. #ifndef ALGIDDEF
  186. #define ALGIDDEF
  187. typedef unsigned int ALG_ID;
  188. #endif
  189.  
  190. // algorithm identifier definitions
  191. #define CALG_MD2                (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD2)
  192. #define CALG_MD4                (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD4)
  193. #define CALG_MD5                (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD5)
  194. #define CALG_SHA                (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA)
  195. #define CALG_SHA1               (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA1)
  196. #define CALG_MAC                (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MAC)
  197. #define CALG_RSA_SIGN           (ALG_CLASS_SIGNATURE | ALG_TYPE_RSA | ALG_SID_RSA_ANY)
  198. #define CALG_DSS_SIGN           (ALG_CLASS_SIGNATURE | ALG_TYPE_DSS | ALG_SID_DSS_ANY)
  199. #define CALG_RSA_KEYX           (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_RSA|ALG_SID_RSA_ANY)
  200. #define CALG_DES                (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_DES)
  201. #define CALG_3DES_112           (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_3DES_112)
  202. #define CALG_3DES               (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_3DES)
  203. #define CALG_DESX               (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_DESX)
  204. #define CALG_RC2                (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_RC2)
  205. #define CALG_RC4                (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_STREAM|ALG_SID_RC4)
  206. #define CALG_SEAL                (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_STREAM|ALG_SID_SEAL)
  207. #define CALG_DH_SF              (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_DH_SANDF)
  208. #define CALG_DH_EPHEM            (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_DH_EPHEM)
  209. #define CALG_AGREEDKEY_ANY        (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_AGREED_KEY_ANY)
  210. #define CALG_KEA_KEYX            (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_KEA)
  211. #define CALG_HUGHES_MD5         (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_ANY|ALG_SID_MD5)
  212. #define CALG_SKIPJACK            (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_SKIPJACK)
  213. #define CALG_TEK                (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_TEK)
  214. #define CALG_CYLINK_MEK         (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_CYLINK_MEK)
  215. #define CALG_SSL3_SHAMD5        (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SSL3SHAMD5)
  216. #define CALG_SSL3_MASTER        (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SSL3_MASTER)
  217. #define CALG_SCHANNEL_MASTER_HASH   (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SCHANNEL_MASTER_HASH)
  218. #define CALG_SCHANNEL_MAC_KEY   (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SCHANNEL_MAC_KEY)
  219. #define CALG_SCHANNEL_ENC_KEY   (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SCHANNEL_ENC_KEY)
  220. #define CALG_PCT1_MASTER        (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_PCT1_MASTER)
  221. #define CALG_SSL2_MASTER        (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SSL2_MASTER)
  222. #define CALG_TLS1_MASTER        (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_TLS1_MASTER)
  223. #define CALG_RC5                (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_RC5)
  224. #define CALG_HMAC                (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_HMAC)
  225. #define CALG_TLS1PRF            (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_TLS1PRF)
  226.  
  227. // resource number for signatures in the CSP
  228. #define    SIGNATURE_RESOURCE_NUMBER    0x29A
  229.  
  230. typedef struct _VTableProvStruc {
  231.     DWORD   Version;
  232.     FARPROC FuncVerifyImage;
  233.     FARPROC FuncReturnhWnd;
  234.     DWORD   dwProvType;
  235.     BYTE    *pbContextInfo;
  236.     DWORD    cbContextInfo;
  237.     LPSTR   pszProvName;
  238. } VTableProvStruc, *PVTableProvStruc;
  239.  
  240. typedef ULONG_PTR HCRYPTPROV;
  241. typedef ULONG_PTR HCRYPTKEY;
  242. typedef ULONG_PTR HCRYPTHASH;
  243.  
  244. // dwFlags definitions for CryptAcquireContext
  245. #define CRYPT_VERIFYCONTEXT     0xF0000000
  246. #define CRYPT_NEWKEYSET         0x00000008
  247. #define CRYPT_DELETEKEYSET      0x00000010
  248. #define CRYPT_MACHINE_KEYSET    0x00000020
  249. #define CRYPT_SILENT            0x00000040
  250.  
  251. // dwFlag definitions for CryptGenKey
  252. #define CRYPT_EXPORTABLE        0x00000001
  253. #define CRYPT_USER_PROTECTED    0x00000002
  254. #define CRYPT_CREATE_SALT       0x00000004
  255. #define CRYPT_UPDATE_KEY        0x00000008
  256. #define CRYPT_NO_SALT           0x00000010
  257. #define CRYPT_PREGEN            0x00000040
  258. #define CRYPT_RECIPIENT         0x00000010
  259. #define CRYPT_INITIATOR         0x00000040
  260. #define CRYPT_ONLINE            0x00000080
  261. #define CRYPT_SF                0x00000100
  262. #define CRYPT_CREATE_IV         0x00000200
  263. #define CRYPT_KEK               0x00000400
  264. #define CRYPT_DATA_KEY          0x00000800
  265. #define    CRYPT_VOLATILE          0x00001000
  266. #define    CRYPT_SGCKEY            0x00002000
  267.  
  268. #define RSA1024BIT_KEY          0x04000000
  269.  
  270. // dwFlags definitions for CryptDeriveKey
  271. #define    CRYPT_SERVER            0x00000400
  272.  
  273. #define KEY_LENGTH_MASK         0xFFFF0000
  274.  
  275. // dwFlag definitions for CryptExportKey
  276. #define CRYPT_Y_ONLY            0x00000001
  277. #define CRYPT_SSL2_FALLBACK     0x00000002
  278. #define CRYPT_DESTROYKEY        0x00000004
  279. #define CRYPT_OAEP              0x00000040  // used with RSA encryptions/decryptions
  280.                                             // CryptExportKey, CryptImportKey,
  281.                                             // CryptEncrypt and CryptDecrypt
  282.  
  283. #define CRYPT_BLOB_VER3         0x00000080  // export version 3 of a blob type
  284.  
  285. // dwFlags definitions for CryptCreateHash
  286. #define CRYPT_SECRETDIGEST      0x00000001
  287.  
  288. // dwFlags definitions for CryptHashSessionKey
  289. #define CRYPT_LITTLE_ENDIAN     0x00000001
  290.  
  291. // dwFlags definitions for CryptSignHash and CryptVerifySignature
  292. #define    CRYPT_NOHASHOID         0x00000001
  293. #define    CRYPT_TYPE2_FORMAT      0x00000002
  294. #define    CRYPT_X931_FORMAT       0x00000004
  295.  
  296. // dwFlag definitions for CryptSetProviderEx and CryptGetDefaultProvider
  297. #define CRYPT_MACHINE_DEFAULT   0x00000001
  298. #define CRYPT_USER_DEFAULT      0x00000002
  299. #define CRYPT_DELETE_DEFAULT    0x00000004
  300.  
  301. // exported key blob definitions
  302. #define SIMPLEBLOB              0x1
  303. #define PUBLICKEYBLOB           0x6
  304. #define PRIVATEKEYBLOB          0x7
  305. #define PLAINTEXTKEYBLOB        0x8
  306. #define OPAQUEKEYBLOB           0x9
  307. #define PUBLICKEYBLOBEX         0xA
  308. #define SYMMETRICWRAPKEYBLOB    0xB
  309.  
  310. #define AT_KEYEXCHANGE          1
  311. #define AT_SIGNATURE            2
  312.  
  313. #define CRYPT_USERDATA          1
  314.  
  315. // dwParam
  316. #define KP_IV                   1       // Initialization vector
  317. #define KP_SALT                 2       // Salt value
  318. #define KP_PADDING              3       // Padding values
  319. #define KP_MODE                 4       // Mode of the cipher
  320. #define KP_MODE_BITS            5       // Number of bits to feedback
  321. #define KP_PERMISSIONS          6       // Key permissions DWORD
  322. #define KP_ALGID                7       // Key algorithm
  323. #define KP_BLOCKLEN             8       // Block size of the cipher
  324. #define KP_KEYLEN               9       // Length of key in bits
  325. #define KP_SALT_EX              10      // Length of salt in bytes
  326. #define KP_P                    11      // DSS/Diffie-Hellman P value
  327. #define KP_G                    12      // DSS/Diffie-Hellman G value
  328. #define KP_Q                    13      // DSS Q value
  329. #define KP_X                    14      // Diffie-Hellman X value
  330. #define KP_Y                    15      // Y value
  331. #define KP_RA                   16      // Fortezza RA value
  332. #define KP_RB                   17      // Fortezza RB value
  333. #define KP_INFO                 18      // for putting information into an RSA envelope
  334. #define KP_EFFECTIVE_KEYLEN     19      // setting and getting RC2 effective key length
  335. #define KP_SCHANNEL_ALG            20      // for setting the Secure Channel algorithms
  336. #define KP_CLIENT_RANDOM        21      // for setting the Secure Channel client random data
  337. #define KP_SERVER_RANDOM        22      // for setting the Secure Channel server random data
  338. #define    KP_RP                    23
  339. #define    KP_PRECOMP_MD5            24
  340. #define    KP_PRECOMP_SHA            25
  341. #define KP_CERTIFICATE          26      // for setting Secure Channel certificate data (PCT1)
  342. #define KP_CLEAR_KEY            27      // for setting Secure Channel clear key data (PCT1)
  343. #define KP_PUB_EX_LEN           28
  344. #define KP_PUB_EX_VAL           29
  345. #define KP_KEYVAL                30
  346. #define KP_ADMIN_PIN            31
  347. #define KP_KEYEXCHANGE_PIN      32
  348. #define KP_SIGNATURE_PIN        33
  349. #define    KP_PREHASH              34
  350.  
  351. #define    KP_OAEP_PARAMS          36      // for setting OAEP params on RSA keys
  352. #define    KP_CMS_KEY_INFO            37
  353. #define    KP_CMS_DH_KEY_INFO      38
  354. #define KP_PUB_PARAMS           39      // for setting public parameters
  355. #define KP_VERIFY_PARAMS        40      // for verifying DSA and DH parameters
  356. #define KP_HIGHEST_VERSION      41      // for TLS protocol version setting
  357.  
  358. // KP_PADDING
  359. #define PKCS5_PADDING           1       // PKCS 5 (sec 6.2) padding method
  360. #define RANDOM_PADDING            2
  361. #define    ZERO_PADDING            3
  362.  
  363. // KP_MODE
  364. #define CRYPT_MODE_CBC          1       // Cipher block chaining
  365. #define CRYPT_MODE_ECB          2       // Electronic code book
  366. #define CRYPT_MODE_OFB          3       // Output feedback mode
  367. #define CRYPT_MODE_CFB          4       // Cipher feedback mode
  368. #define CRYPT_MODE_CTS          5       // Ciphertext stealing mode
  369.  
  370. // KP_PERMISSIONS
  371. #define CRYPT_ENCRYPT           0x0001  // Allow encryption
  372. #define CRYPT_DECRYPT           0x0002  // Allow decryption
  373. #define CRYPT_EXPORT            0x0004  // Allow key to be exported
  374. #define CRYPT_READ              0x0008  // Allow parameters to be read
  375. #define CRYPT_WRITE             0x0010  // Allow parameters to be set
  376. #define CRYPT_MAC               0x0020  // Allow MACs to be used with key
  377. #define CRYPT_EXPORT_KEY        0x0040  // Allow key to be used for exporting keys
  378. #define CRYPT_IMPORT_KEY        0x0080  // Allow key to be used for importing keys
  379.  
  380. #define HP_ALGID                0x0001  // Hash algorithm
  381. #define HP_HASHVAL              0x0002  // Hash value
  382. #define HP_HASHSIZE             0x0004  // Hash value size
  383. #define HP_HMAC_INFO            0x0005  // information for creating an HMAC
  384. #define HP_TLS1PRF_LABEL        0x0006  // label for TLS1 PRF
  385. #define HP_TLS1PRF_SEED         0x0007  // seed for TLS1 PRF
  386.  
  387. #define CRYPT_FAILED            FALSE
  388. #define CRYPT_SUCCEED           TRUE
  389.  
  390. #define RCRYPT_SUCCEEDED(rt)     ((rt) == CRYPT_SUCCEED)
  391. #define RCRYPT_FAILED(rt)        ((rt) == CRYPT_FAILED)
  392.  
  393. //
  394. // CryptGetProvParam
  395. //
  396. #define PP_ENUMALGS             1
  397. #define PP_ENUMCONTAINERS       2
  398. #define PP_IMPTYPE              3
  399. #define PP_NAME                 4
  400. #define PP_VERSION              5
  401. #define PP_CONTAINER            6
  402. #define PP_CHANGE_PASSWORD      7
  403. #define PP_KEYSET_SEC_DESCR     8       // get/set security descriptor of keyset
  404. #define PP_CERTCHAIN            9       // for retrieving certificates from tokens
  405. #define PP_KEY_TYPE_SUBTYPE     10
  406. #define PP_PROVTYPE             16
  407. #define PP_KEYSTORAGE           17
  408. #define PP_APPLI_CERT           18
  409. #define PP_SYM_KEYSIZE          19
  410. #define PP_SESSION_KEYSIZE      20
  411. #define PP_UI_PROMPT            21
  412. #define PP_ENUMALGS_EX          22
  413. #define PP_ENUMMANDROOTS        25
  414. #define PP_ENUMELECTROOTS        26
  415. #define    PP_KEYSET_TYPE            27
  416. #define PP_ADMIN_PIN            31
  417. #define PP_KEYEXCHANGE_PIN      32
  418. #define PP_SIGNATURE_PIN        33
  419. #define PP_SIG_KEYSIZE_INC      34
  420. #define PP_KEYX_KEYSIZE_INC     35
  421. #define PP_UNIQUE_CONTAINER     36
  422. #define PP_SGC_INFO             37
  423. #define PP_USE_HARDWARE_RNG     38
  424. #define    PP_KEYSPEC              39
  425. #define    PP_ENUMEX_SIGNING_PROT  40
  426.  
  427. #define CRYPT_FIRST             1
  428. #define CRYPT_NEXT              2
  429. #define CRYPT_SGC_ENUM            4
  430.  
  431. #define CRYPT_IMPL_HARDWARE     1
  432. #define CRYPT_IMPL_SOFTWARE     2
  433. #define CRYPT_IMPL_MIXED        3
  434. #define CRYPT_IMPL_UNKNOWN      4
  435. #define CRYPT_IMPL_REMOVABLE    8
  436.  
  437. // key storage flags
  438. #define CRYPT_SEC_DESCR         0x00000001
  439. #define CRYPT_PSTORE            0x00000002
  440. #define CRYPT_UI_PROMPT         0x00000004
  441.  
  442. // protocol flags
  443. #define CRYPT_FLAG_PCT1         0x0001
  444. #define CRYPT_FLAG_SSL2         0x0002
  445. #define CRYPT_FLAG_SSL3         0x0004
  446. #define CRYPT_FLAG_TLS1         0x0008
  447. #define CRYPT_FLAG_IPSEC        0x0010
  448. #define CRYPT_FLAG_SIGNING      0x0020
  449.  
  450. // SGC flags
  451. #define CRYPT_SGC               0x0001
  452. #define CRYPT_FASTSGC           0x0002
  453.  
  454. //
  455. // CryptSetProvParam
  456. //
  457. #define PP_CLIENT_HWND          1
  458. #define PP_CONTEXT_INFO            11
  459. #define    PP_KEYEXCHANGE_KEYSIZE    12
  460. #define    PP_SIGNATURE_KEYSIZE    13
  461. #define PP_KEYEXCHANGE_ALG      14
  462. #define PP_SIGNATURE_ALG        15
  463. #define PP_DELETEKEY            24
  464.  
  465. #define PROV_RSA_FULL           1
  466. #define PROV_RSA_SIG            2
  467. #define PROV_DSS                3
  468. #define PROV_FORTEZZA           4
  469. #define PROV_MS_EXCHANGE        5
  470. #define PROV_SSL                6
  471. #define PROV_RSA_SCHANNEL       12
  472. #define PROV_DSS_DH             13
  473. #define PROV_EC_ECDSA_SIG       14
  474. #define PROV_EC_ECNRA_SIG       15
  475. #define PROV_EC_ECDSA_FULL      16
  476. #define PROV_EC_ECNRA_FULL      17
  477. #define PROV_DH_SCHANNEL        18
  478. #define PROV_SPYRUS_LYNKS       20
  479. #define PROV_RNG                21
  480. #define PROV_INTEL_SEC          22
  481.  
  482.  
  483. //
  484. // STT defined Providers
  485. //
  486. #define PROV_STT_MER                    7
  487. #define PROV_STT_ACQ                    8
  488. #define PROV_STT_BRND                   9
  489. #define PROV_STT_ROOT                   10
  490. #define PROV_STT_ISS                    11
  491.  
  492. //
  493. // Provider friendly names
  494. //
  495. #define MS_DEF_PROV_A       "Microsoft Base Cryptographic Provider v1.0"
  496. #define MS_DEF_PROV_W       L"Microsoft Base Cryptographic Provider v1.0"
  497. #ifdef UNICODE
  498. #define MS_DEF_PROV         MS_DEF_PROV_W
  499. #else
  500. #define MS_DEF_PROV         MS_DEF_PROV_A
  501. #endif
  502.  
  503. #define MS_ENHANCED_PROV_A       "Microsoft Enhanced Cryptographic Provider v1.0"
  504. #define MS_ENHANCED_PROV_W       L"Microsoft Enhanced Cryptographic Provider v1.0"
  505. #ifdef UNICODE
  506. #define MS_ENHANCED_PROV         MS_ENHANCED_PROV_W
  507. #else
  508. #define MS_ENHANCED_PROV         MS_ENHANCED_PROV_A
  509. #endif
  510.  
  511. #define MS_STRONG_PROV_A       "Microsoft Strong Cryptographic Provider"
  512. #define MS_STRONG_PROV_W       L"Microsoft Strong Cryptographic Provider"
  513. #ifdef UNICODE
  514. #define MS_STRONG_PROV         MS_STRONG_PROV_W
  515. #else
  516. #define MS_STRONG_PROV           MS_STRONG_PROV_A
  517. #endif
  518.  
  519. #define MS_DEF_RSA_SIG_PROV_A    "Microsoft RSA Signature Cryptographic Provider"
  520. #define MS_DEF_RSA_SIG_PROV_W    L"Microsoft RSA Signature Cryptographic Provider"
  521. #ifdef UNICODE
  522. #define MS_DEF_RSA_SIG_PROV      MS_DEF_RSA_SIG_PROV_W
  523. #else
  524. #define MS_DEF_RSA_SIG_PROV      MS_DEF_RSA_SIG_PROV_A
  525. #endif
  526.  
  527. #define MS_DEF_RSA_SCHANNEL_PROV_A  "Microsoft RSA SChannel Cryptographic Provider"
  528. #define MS_DEF_RSA_SCHANNEL_PROV_W  L"Microsoft RSA SChannel Cryptographic Provider"
  529. #ifdef UNICODE
  530. #define MS_DEF_RSA_SCHANNEL_PROV         MS_DEF_RSA_SCHANNEL_PROV_W
  531. #else
  532. #define MS_DEF_RSA_SCHANNEL_PROV         MS_DEF_RSA_SCHANNEL_PROV_A
  533. #endif
  534.  
  535. #define MS_DEF_DSS_PROV_A        "Microsoft Base DSS Cryptographic Provider"
  536. #define MS_DEF_DSS_PROV_W        L"Microsoft Base DSS Cryptographic Provider"
  537. #ifdef UNICODE
  538. #define MS_DEF_DSS_PROV          MS_DEF_DSS_PROV_W
  539. #else
  540. #define MS_DEF_DSS_PROV          MS_DEF_DSS_PROV_A
  541. #endif
  542.  
  543. #define MS_DEF_DSS_DH_PROV_A    "Microsoft Base DSS and Diffie-Hellman Cryptographic Provider"
  544. #define MS_DEF_DSS_DH_PROV_W    L"Microsoft Base DSS and Diffie-Hellman Cryptographic Provider"
  545. #ifdef UNICODE
  546. #define MS_DEF_DSS_DH_PROV      MS_DEF_DSS_DH_PROV_W
  547. #else
  548. #define MS_DEF_DSS_DH_PROV      MS_DEF_DSS_DH_PROV_A
  549. #endif
  550.  
  551. #define MS_ENH_DSS_DH_PROV_A    "Microsoft Enhanced DSS and Diffie-Hellman Cryptographic Provider"
  552. #define MS_ENH_DSS_DH_PROV_W    L"Microsoft Enhanced DSS and Diffie-Hellman Cryptographic Provider"
  553. #ifdef UNICODE
  554. #define MS_ENH_DSS_DH_PROV      MS_ENH_DSS_DH_PROV_W
  555. #else
  556. #define MS_ENH_DSS_DH_PROV      MS_ENH_DSS_DH_PROV_A
  557. #endif
  558.  
  559. #define MS_DEF_DH_SCHANNEL_PROV_A  "Microsoft DH SChannel Cryptographic Provider"
  560. #define MS_DEF_DH_SCHANNEL_PROV_W  L"Microsoft DH SChannel Cryptographic Provider"
  561. #ifdef UNICODE
  562. #define MS_DEF_DH_SCHANNEL_PROV         MS_DEF_DH_SCHANNEL_PROV_W
  563. #else
  564. #define MS_DEF_DH_SCHANNEL_PROV         MS_DEF_DH_SCHANNEL_PROV_A
  565. #endif
  566.  
  567. #define MS_SCARD_PROV_A  "Microsoft Base Smart Card Crypto Provider"
  568. #define MS_SCARD_PROV_W  L"Microsoft Base Smart Card Crypto Provider"
  569. #ifdef UNICODE
  570. #define MS_SCARD_PROV MS_SCARD_PROV_W
  571. #else
  572. #define MS_SCARD_PROV MS_SCARD_PROV_A
  573. #endif
  574.  
  575. #define MAXUIDLEN               64
  576.  
  577. // Exponentiation Offload Reg Location
  578. #define EXPO_OFFLOAD_REG_VALUE "ExpoOffload"
  579. #define EXPO_OFFLOAD_FUNC_NAME "OffloadModExpo"
  580.  
  581. #define CUR_BLOB_VERSION        2
  582.  
  583. // structure for use with CryptSetKeyParam for CMS keys
  584. // DO NOT USE THIS STRUCTURE!!!!!
  585. typedef struct _CMS_KEY_INFO {
  586.     DWORD    dwVersion;            // sizeof(CMS_KEY_INFO)
  587.     ALG_ID  Algid;                // algorithmm id for the key to be converted
  588.     BYTE    *pbOID;                // pointer to OID to hash in with Z
  589.     DWORD   cbOID;                // length of OID to hash in with Z
  590. } CMS_KEY_INFO, *PCMS_KEY_INFO;
  591.  
  592. // structure for use with CryptSetHashParam with CALG_HMAC
  593. typedef struct _HMAC_Info {
  594.     ALG_ID  HashAlgid;
  595.     BYTE    *pbInnerString;
  596.     DWORD   cbInnerString;
  597.     BYTE    *pbOuterString;
  598.     DWORD   cbOuterString;
  599. } HMAC_INFO, *PHMAC_INFO;
  600.  
  601. // structure for use with CryptSetKeyParam with KP_SCHANNEL_ALG
  602. typedef struct _SCHANNEL_ALG {
  603.     DWORD   dwUse;
  604.     ALG_ID  Algid;
  605.     DWORD   cBits;
  606.     DWORD   dwFlags;
  607.     DWORD   dwReserved;
  608. } SCHANNEL_ALG, *PSCHANNEL_ALG;
  609.  
  610. // uses of algortihms for SCHANNEL_ALG structure
  611. #define     SCHANNEL_MAC_KEY    0x00000000
  612. #define     SCHANNEL_ENC_KEY    0x00000001
  613.  
  614. // uses of dwFlags SCHANNEL_ALG structure
  615. #define     INTERNATIONAL_USAGE 0x00000001
  616.  
  617. typedef struct _PROV_ENUMALGS {
  618.     ALG_ID    aiAlgid;
  619.     DWORD     dwBitLen;
  620.     DWORD     dwNameLen;
  621.     CHAR      szName[20];
  622. } PROV_ENUMALGS;
  623.  
  624. typedef struct _PROV_ENUMALGS_EX {
  625.     ALG_ID    aiAlgid;
  626.     DWORD     dwDefaultLen;
  627.     DWORD     dwMinLen;
  628.     DWORD     dwMaxLen;
  629.     DWORD     dwProtocols;
  630.     DWORD     dwNameLen;
  631.     CHAR      szName[20];
  632.     DWORD     dwLongNameLen;
  633.     CHAR      szLongName[40];
  634. } PROV_ENUMALGS_EX;
  635.  
  636. typedef struct _PUBLICKEYSTRUC {
  637.         BYTE    bType;
  638.         BYTE    bVersion;
  639.         WORD    reserved;
  640.         ALG_ID  aiKeyAlg;
  641. } BLOBHEADER, PUBLICKEYSTRUC;
  642.  
  643. typedef struct _RSAPUBKEY {
  644.         DWORD   magic;                  // Has to be RSA1
  645.         DWORD   bitlen;                 // # of bits in modulus
  646.         DWORD   pubexp;                 // public exponent
  647.                                         // Modulus data follows
  648. } RSAPUBKEY;
  649.  
  650. typedef struct _PUBKEY {
  651.         DWORD   magic;
  652.         DWORD   bitlen;                 // # of bits in modulus
  653. } DHPUBKEY, DSSPUBKEY, KEAPUBKEY, TEKPUBKEY;
  654.  
  655. typedef struct _DSSSEED {
  656.         DWORD   counter;
  657.         BYTE    seed[20];
  658. } DSSSEED;
  659.  
  660. typedef struct _PUBKEYVER3 {
  661.         DWORD   magic;
  662.         DWORD   bitlenP;                // # of bits in prime modulus
  663.         DWORD   bitlenQ;                // # of bits in prime q, 0 if not available
  664.         DWORD   bitlenJ;                // # of bits in (p-1)/q, 0 if not available
  665.         DSSSEED DSSSeed;
  666. } DHPUBKEY_VER3, DSSPUBKEY_VER3;
  667.  
  668. typedef struct _PRIVKEYVER3 {
  669.         DWORD   magic;
  670.         DWORD   bitlenP;                // # of bits in prime modulus
  671.         DWORD   bitlenQ;                // # of bits in prime q, 0 if not available
  672.         DWORD   bitlenJ;                // # of bits in (p-1)/q, 0 if not available
  673.         DWORD   bitlenX;                // # of bits in X
  674.         DSSSEED DSSSeed;
  675. } DHPRIVKEY_VER3, DSSPRIVKEY_VER3;
  676.  
  677. typedef struct _KEY_TYPE_SUBTYPE {
  678.         DWORD   dwKeySpec;
  679.         GUID    Type;
  680.         GUID    Subtype;
  681. } KEY_TYPE_SUBTYPE, *PKEY_TYPE_SUBTYPE;
  682.  
  683. typedef struct _CERT_FORTEZZA_DATA_PROP {
  684.     unsigned char   SerialNumber[8];
  685.     int             CertIndex;
  686.     unsigned char   CertLabel[36];
  687. } CERT_FORTEZZA_DATA_PROP;
  688.  
  689.  
  690. //+-------------------------------------------------------------------------
  691. //  CRYPTOAPI BLOB definitions
  692. //--------------------------------------------------------------------------
  693. typedef struct _CRYPTOAPI_BLOB {
  694.     DWORD   cbData;
  695.     BYTE    *pbData;
  696. } CRYPT_INTEGER_BLOB, *PCRYPT_INTEGER_BLOB,
  697. CRYPT_UINT_BLOB, *PCRYPT_UINT_BLOB,
  698. CRYPT_OBJID_BLOB, *PCRYPT_OBJID_BLOB,
  699. CERT_NAME_BLOB, *PCERT_NAME_BLOB,
  700. CERT_RDN_VALUE_BLOB, *PCERT_RDN_VALUE_BLOB,
  701. CERT_BLOB, *PCERT_BLOB,
  702. CRL_BLOB, *PCRL_BLOB,
  703. DATA_BLOB, *PDATA_BLOB,
  704. CRYPT_DATA_BLOB, *PCRYPT_DATA_BLOB,
  705. CRYPT_HASH_BLOB, *PCRYPT_HASH_BLOB,
  706. CRYPT_DIGEST_BLOB, *PCRYPT_DIGEST_BLOB,
  707. CRYPT_DER_BLOB, *PCRYPT_DER_BLOB,
  708. CRYPT_ATTR_BLOB, *PCRYPT_ATTR_BLOB;
  709.  
  710. // structure for use with CryptSetKeyParam for CMS keys
  711. typedef struct _CMS_DH_KEY_INFO {
  712.     DWORD            dwVersion;            // sizeof(CMS_DH_KEY_INFO)
  713.     ALG_ID          Algid;                // algorithmm id for the key to be converted
  714.     LPSTR           pszContentEncObjId; // pointer to OID to hash in with Z
  715.     CRYPT_DATA_BLOB PubInfo;            // OPTIONAL - public information
  716.     void            *pReserved;         // reserved - should be NULL
  717. } CMS_DH_KEY_INFO, *PCMS_DH_KEY_INFO;
  718.  
  719.  
  720. WINADVAPI
  721. BOOL
  722. WINAPI
  723. CryptAcquireContextA(
  724.     HCRYPTPROV *phProv,
  725.     LPCSTR pszContainer,
  726.     LPCSTR pszProvider,
  727.     DWORD dwProvType,
  728.     DWORD dwFlags
  729.     );
  730. WINADVAPI
  731. BOOL
  732. WINAPI
  733. CryptAcquireContextW(
  734.     HCRYPTPROV *phProv,
  735.     LPCWSTR pszContainer,
  736.     LPCWSTR pszProvider,
  737.     DWORD dwProvType,
  738.     DWORD dwFlags
  739.     );
  740. #ifdef UNICODE
  741. #define CryptAcquireContext  CryptAcquireContextW
  742. #else
  743. #define CryptAcquireContext  CryptAcquireContextA
  744. #endif // !UNICODE
  745.  
  746. WINADVAPI
  747. BOOL
  748. WINAPI
  749. CryptReleaseContext(
  750.     HCRYPTPROV hProv,
  751.     ULONG_PTR dwFlags
  752.     );
  753.  
  754. WINADVAPI
  755. BOOL
  756. WINAPI
  757. CryptGenKey(
  758.     HCRYPTPROV hProv,
  759.     ALG_ID Algid,
  760.     DWORD dwFlags,
  761.     HCRYPTKEY *phKey
  762.     );
  763.  
  764. WINADVAPI
  765. BOOL
  766. WINAPI
  767. CryptDeriveKey(
  768.     HCRYPTPROV hProv,
  769.     ALG_ID Algid,
  770.     HCRYPTHASH hBaseData,
  771.     DWORD dwFlags,
  772.     HCRYPTKEY *phKey
  773.     );
  774.  
  775. WINADVAPI
  776. BOOL
  777. WINAPI
  778. CryptDestroyKey(
  779.     HCRYPTKEY hKey
  780.     );
  781.  
  782. WINADVAPI
  783. BOOL
  784. WINAPI
  785. CryptSetKeyParam(
  786.     HCRYPTKEY hKey,
  787.     DWORD dwParam,
  788.     BYTE *pbData,
  789.     DWORD dwFlags
  790.     );
  791.  
  792. WINADVAPI
  793. BOOL
  794. WINAPI
  795. CryptGetKeyParam(
  796.     HCRYPTKEY hKey,
  797.     DWORD dwParam,
  798.     BYTE *pbData,
  799.     DWORD *pdwDataLen,
  800.     DWORD dwFlags
  801.     );
  802.  
  803. WINADVAPI
  804. BOOL
  805. WINAPI
  806. CryptSetHashParam(
  807.     HCRYPTHASH hHash,
  808.     DWORD dwParam,
  809.     BYTE*pbData,
  810.     DWORD dwFlags
  811.     );
  812.  
  813. WINADVAPI
  814. BOOL
  815. WINAPI
  816. CryptGetHashParam(
  817.     HCRYPTHASH hHash,
  818.     DWORD dwParam,
  819.     BYTE*pbData,
  820.     DWORD *pdwDataLen,
  821.     DWORD dwFlags
  822.     );
  823.  
  824. WINADVAPI
  825. BOOL
  826. WINAPI
  827. CryptSetProvParam(
  828.     HCRYPTPROV hProv,
  829.     DWORD dwParam,
  830.     BYTE*pbData,
  831.     DWORD dwFlags
  832.     );
  833.  
  834. WINADVAPI
  835. BOOL
  836. WINAPI
  837. CryptGetProvParam(
  838.     HCRYPTPROV hProv,
  839.     DWORD dwParam,
  840.     BYTE*pbData,
  841.     DWORD *pdwDataLen,
  842.     DWORD dwFlags
  843.     );
  844.  
  845. WINADVAPI
  846. BOOL
  847. WINAPI
  848. CryptGenRandom(
  849.     HCRYPTPROV hProv,
  850.     DWORD dwLen,
  851.     BYTE *pbBuffer
  852.     );
  853.  
  854. WINADVAPI
  855. BOOL
  856. WINAPI
  857. CryptGetUserKey(
  858.     HCRYPTPROV hProv,
  859.     DWORD dwKeySpec,
  860.     HCRYPTKEY *phUserKey
  861.     );
  862.  
  863. WINADVAPI
  864. BOOL
  865. WINAPI
  866. CryptExportKey(
  867.     HCRYPTKEY hKey,
  868.     HCRYPTKEY hExpKey,
  869.     DWORD dwBlobType,
  870.     DWORD dwFlags,
  871.     BYTE *pbData,
  872.     DWORD *pdwDataLen
  873.     );
  874.  
  875. WINADVAPI
  876. BOOL
  877. WINAPI
  878. CryptImportKey(
  879.     HCRYPTPROV hProv,
  880.     CONST BYTE *pbData,
  881.     DWORD dwDataLen,
  882.     HCRYPTKEY hPubKey,
  883.     DWORD dwFlags,
  884.     HCRYPTKEY *phKey
  885.     );
  886.  
  887. WINADVAPI
  888. BOOL
  889. WINAPI
  890. CryptEncrypt(
  891.     HCRYPTKEY hKey,
  892.     HCRYPTHASH hHash,
  893.     BOOL Final,
  894.     DWORD dwFlags,
  895.     BYTE *pbData,
  896.     DWORD *pdwDataLen,
  897.     DWORD dwBufLen
  898.     );
  899.  
  900. WINADVAPI
  901. BOOL
  902. WINAPI
  903. CryptDecrypt(
  904.     HCRYPTKEY hKey,
  905.     HCRYPTHASH hHash,
  906.     BOOL Final,
  907.     DWORD dwFlags,
  908.     BYTE *pbData,
  909.     DWORD *pdwDataLen
  910.     );
  911.  
  912. WINADVAPI
  913. BOOL
  914. WINAPI
  915. CryptCreateHash(
  916.     HCRYPTPROV hProv,
  917.     ALG_ID Algid,
  918.     HCRYPTKEY hKey,
  919.     DWORD dwFlags,
  920.     HCRYPTHASH *phHash
  921.     );
  922.  
  923. WINADVAPI
  924. BOOL
  925. WINAPI
  926. CryptHashData(
  927.     HCRYPTHASH hHash,
  928.     CONST BYTE *pbData,
  929.     DWORD dwDataLen,
  930.     DWORD dwFlags
  931.     );
  932.  
  933. WINADVAPI
  934. BOOL
  935. WINAPI
  936. CryptHashSessionKey(
  937.     HCRYPTHASH hHash,
  938.     HCRYPTKEY hKey,
  939.     DWORD dwFlags
  940.     );
  941.  
  942. WINADVAPI
  943. BOOL
  944. WINAPI
  945. CryptDestroyHash(
  946.     HCRYPTHASH hHash
  947.     );
  948.  
  949. WINADVAPI
  950. BOOL
  951. WINAPI
  952. CryptSignHashA(
  953.     HCRYPTHASH hHash,
  954.     DWORD dwKeySpec,
  955.     LPCSTR sDescription,
  956.     DWORD dwFlags,
  957.     BYTE *pbSignature,
  958.     DWORD *pdwSigLen
  959.     );
  960. WINADVAPI
  961. BOOL
  962. WINAPI
  963. CryptSignHashW(
  964.     HCRYPTHASH hHash,
  965.     DWORD dwKeySpec,
  966.     LPCWSTR sDescription,
  967.     DWORD dwFlags,
  968.     BYTE *pbSignature,
  969.     DWORD *pdwSigLen
  970.     );
  971. #ifdef UNICODE
  972. #define CryptSignHash  CryptSignHashW
  973. #else
  974. #define CryptSignHash  CryptSignHashA
  975. #endif // !UNICODE
  976.  
  977. WINADVAPI
  978. BOOL
  979. WINAPI
  980. CryptVerifySignatureA(
  981.     HCRYPTHASH hHash,
  982.     CONST BYTE *pbSignature,
  983.     DWORD dwSigLen,
  984.     HCRYPTKEY hPubKey,
  985.     LPCSTR sDescription,
  986.     DWORD dwFlags
  987.     );
  988. WINADVAPI
  989. BOOL
  990. WINAPI
  991. CryptVerifySignatureW(
  992.     HCRYPTHASH hHash,
  993.     CONST BYTE *pbSignature,
  994.     DWORD dwSigLen,
  995.     HCRYPTKEY hPubKey,
  996.     LPCWSTR sDescription,
  997.     DWORD dwFlags
  998.     );
  999. #ifdef UNICODE
  1000. #define CryptVerifySignature  CryptVerifySignatureW
  1001. #else
  1002. #define CryptVerifySignature  CryptVerifySignatureA
  1003. #endif // !UNICODE
  1004.  
  1005. WINADVAPI
  1006. BOOL
  1007. WINAPI
  1008. CryptSetProviderA(
  1009.     LPCSTR pszProvName,
  1010.     DWORD    dwProvType
  1011.     );
  1012. WINADVAPI
  1013. BOOL
  1014. WINAPI
  1015. CryptSetProviderW(
  1016.     LPCWSTR pszProvName,
  1017.     DWORD    dwProvType
  1018.     );
  1019. #ifdef UNICODE
  1020. #define CryptSetProvider  CryptSetProviderW
  1021. #else
  1022. #define CryptSetProvider  CryptSetProviderA
  1023. #endif // !UNICODE
  1024.  
  1025. WINADVAPI
  1026. BOOL
  1027. WINAPI
  1028. CryptSetProviderExA(
  1029.     LPCSTR pszProvName,
  1030.     DWORD    dwProvType,
  1031.     DWORD * pdwReserved,
  1032.     DWORD   dwFlags
  1033.     );
  1034. WINADVAPI
  1035. BOOL
  1036. WINAPI
  1037. CryptSetProviderExW(
  1038.     LPCWSTR pszProvName,
  1039.     DWORD    dwProvType,
  1040.     DWORD * pdwReserved,
  1041.     DWORD   dwFlags
  1042.     );
  1043. #ifdef UNICODE
  1044. #define CryptSetProviderEx  CryptSetProviderExW
  1045. #else
  1046. #define CryptSetProviderEx  CryptSetProviderExA
  1047. #endif // !UNICODE
  1048.  
  1049. WINADVAPI
  1050. BOOL
  1051. WINAPI
  1052. CryptGetDefaultProviderA(
  1053.     DWORD dwProvType,
  1054.     DWORD *pdwReserved,
  1055.     DWORD dwFlags,
  1056.     LPSTR pszProvName,
  1057.     DWORD *pcbProvName
  1058.     );
  1059. WINADVAPI
  1060. BOOL
  1061. WINAPI
  1062. CryptGetDefaultProviderW(
  1063.     DWORD dwProvType,
  1064.     DWORD *pdwReserved,
  1065.     DWORD dwFlags,
  1066.     LPWSTR pszProvName,
  1067.     DWORD *pcbProvName
  1068.     );
  1069. #ifdef UNICODE
  1070. #define CryptGetDefaultProvider  CryptGetDefaultProviderW
  1071. #else
  1072. #define CryptGetDefaultProvider  CryptGetDefaultProviderA
  1073. #endif // !UNICODE
  1074.  
  1075. WINADVAPI
  1076. BOOL
  1077. WINAPI
  1078. CryptEnumProviderTypesA(
  1079.     DWORD   dwIndex,
  1080.     DWORD * pdwReserved,
  1081.     DWORD   dwFlags,
  1082.     DWORD * pdwProvType,
  1083.     LPSTR pszTypeName,
  1084.     DWORD * pcbTypeName
  1085.     );
  1086. WINADVAPI
  1087. BOOL
  1088. WINAPI
  1089. CryptEnumProviderTypesW(
  1090.     DWORD   dwIndex,
  1091.     DWORD * pdwReserved,
  1092.     DWORD   dwFlags,
  1093.     DWORD * pdwProvType,
  1094.     LPWSTR pszTypeName,
  1095.     DWORD * pcbTypeName
  1096.     );
  1097. #ifdef UNICODE
  1098. #define CryptEnumProviderTypes  CryptEnumProviderTypesW
  1099. #else
  1100. #define CryptEnumProviderTypes  CryptEnumProviderTypesA
  1101. #endif // !UNICODE
  1102.  
  1103. WINADVAPI
  1104. BOOL
  1105. WINAPI
  1106. CryptEnumProvidersA(
  1107.     DWORD   dwIndex,
  1108.     DWORD * pdwReserved,
  1109.     DWORD   dwFlags,
  1110.     DWORD * pdwProvType,
  1111.     LPSTR pszProvName,
  1112.     DWORD * pcbProvName
  1113.     );
  1114. WINADVAPI
  1115. BOOL
  1116. WINAPI
  1117. CryptEnumProvidersW(
  1118.     DWORD   dwIndex,
  1119.     DWORD * pdwReserved,
  1120.     DWORD   dwFlags,
  1121.     DWORD * pdwProvType,
  1122.     LPWSTR pszProvName,
  1123.     DWORD * pcbProvName
  1124.     );
  1125. #ifdef UNICODE
  1126. #define CryptEnumProviders  CryptEnumProvidersW
  1127. #else
  1128. #define CryptEnumProviders  CryptEnumProvidersA
  1129. #endif // !UNICODE
  1130.  
  1131. WINADVAPI
  1132. BOOL
  1133. WINAPI
  1134. CryptContextAddRef(
  1135.     HCRYPTPROV hProv,
  1136.     DWORD * pdwReserved,
  1137.     DWORD   dwFlags
  1138.     );
  1139.  
  1140. WINADVAPI
  1141. BOOL
  1142. WINAPI
  1143. CryptDuplicateKey(
  1144.     HCRYPTKEY   hKey,
  1145.     DWORD     * pdwReserved,
  1146.     DWORD       dwFlags,
  1147.     HCRYPTKEY * phKey
  1148.     );
  1149.  
  1150. WINADVAPI
  1151. BOOL
  1152. WINAPI
  1153. CryptDuplicateHash(
  1154.     HCRYPTHASH   hHash,
  1155.     DWORD      * pdwReserved,
  1156.     DWORD        dwFlags,
  1157.     HCRYPTHASH * phHash
  1158.     );
  1159.  
  1160. //+-------------------------------------------------------------------------
  1161. //  In a CRYPT_BIT_BLOB the last byte may contain 0-7 unused bits. Therefore, the
  1162. //  overall bit length is cbData * 8 - cUnusedBits.
  1163. //--------------------------------------------------------------------------
  1164. typedef struct _CRYPT_BIT_BLOB {
  1165.     DWORD   cbData;
  1166.     BYTE    *pbData;
  1167.     DWORD   cUnusedBits;
  1168. } CRYPT_BIT_BLOB, *PCRYPT_BIT_BLOB;
  1169.  
  1170. //+-------------------------------------------------------------------------
  1171. //  Type used for any algorithm
  1172. //
  1173. //  Where the Parameters CRYPT_OBJID_BLOB is in its encoded representation. For most
  1174. //  algorithm types, the Parameters CRYPT_OBJID_BLOB is NULL (Parameters.cbData = 0).
  1175. //--------------------------------------------------------------------------
  1176. typedef struct _CRYPT_ALGORITHM_IDENTIFIER {
  1177.     LPSTR               pszObjId;
  1178.     CRYPT_OBJID_BLOB    Parameters;
  1179. } CRYPT_ALGORITHM_IDENTIFIER, *PCRYPT_ALGORITHM_IDENTIFIER;
  1180.  
  1181. // Following are the definitions of various algorithm object identifiers
  1182. // RSA
  1183. #define szOID_RSA               "1.2.840.113549"
  1184. #define szOID_PKCS              "1.2.840.113549.1"
  1185. #define szOID_RSA_HASH          "1.2.840.113549.2"
  1186. #define szOID_RSA_ENCRYPT       "1.2.840.113549.3"
  1187.  
  1188. #define szOID_PKCS_1            "1.2.840.113549.1.1"
  1189. #define szOID_PKCS_2            "1.2.840.113549.1.2"
  1190. #define szOID_PKCS_3            "1.2.840.113549.1.3"
  1191. #define szOID_PKCS_4            "1.2.840.113549.1.4"
  1192. #define szOID_PKCS_5            "1.2.840.113549.1.5"
  1193. #define szOID_PKCS_6            "1.2.840.113549.1.6"
  1194. #define szOID_PKCS_7            "1.2.840.113549.1.7"
  1195. #define szOID_PKCS_8            "1.2.840.113549.1.8"
  1196. #define szOID_PKCS_9            "1.2.840.113549.1.9"
  1197. #define szOID_PKCS_10           "1.2.840.113549.1.10"
  1198. #define szOID_PKCS_12           "1.2.840.113549.1.12"
  1199.  
  1200. #define szOID_RSA_RSA           "1.2.840.113549.1.1.1"
  1201. #define szOID_RSA_MD2RSA        "1.2.840.113549.1.1.2"
  1202. #define szOID_RSA_MD4RSA        "1.2.840.113549.1.1.3"
  1203. #define szOID_RSA_MD5RSA        "1.2.840.113549.1.1.4"
  1204. #define szOID_RSA_SHA1RSA       "1.2.840.113549.1.1.5"
  1205. #define szOID_RSA_SETOAEP_RSA   "1.2.840.113549.1.1.6"
  1206.  
  1207. #define szOID_RSA_DH            "1.2.840.113549.1.3.1"
  1208.  
  1209. #define szOID_RSA_data          "1.2.840.113549.1.7.1"
  1210. #define szOID_RSA_signedData    "1.2.840.113549.1.7.2"
  1211. #define szOID_RSA_envelopedData "1.2.840.113549.1.7.3"
  1212. #define szOID_RSA_signEnvData   "1.2.840.113549.1.7.4"
  1213. #define szOID_RSA_digestedData  "1.2.840.113549.1.7.5"
  1214. #define szOID_RSA_hashedData    "1.2.840.113549.1.7.5"
  1215. #define szOID_RSA_encryptedData "1.2.840.113549.1.7.6"
  1216.  
  1217. #define szOID_RSA_emailAddr     "1.2.840.113549.1.9.1"
  1218. #define szOID_RSA_unstructName  "1.2.840.113549.1.9.2"
  1219. #define szOID_RSA_contentType   "1.2.840.113549.1.9.3"
  1220. #define szOID_RSA_messageDigest "1.2.840.113549.1.9.4"
  1221. #define szOID_RSA_signingTime   "1.2.840.113549.1.9.5"
  1222. #define szOID_RSA_counterSign   "1.2.840.113549.1.9.6"
  1223. #define szOID_RSA_challengePwd  "1.2.840.113549.1.9.7"
  1224. #define szOID_RSA_unstructAddr  "1.2.840.113549.1.9.8"
  1225. #define szOID_RSA_extCertAttrs  "1.2.840.113549.1.9.9"
  1226. #define szOID_RSA_certExtensions "1.2.840.113549.1.9.14"
  1227. #define szOID_RSA_SMIMECapabilities "1.2.840.113549.1.9.15"
  1228. #define szOID_RSA_preferSignedData "1.2.840.113549.1.9.15.1"
  1229.  
  1230. #define szOID_RSA_SMIMEalg              "1.2.840.113549.1.9.16.3"
  1231. #define szOID_RSA_SMIMEalgESDH          "1.2.840.113549.1.9.16.3.5"
  1232. #define szOID_RSA_SMIMEalgCMS3DESwrap   "1.2.840.113549.1.9.16.3.6"
  1233. #define szOID_RSA_SMIMEalgCMSRC2wrap    "1.2.840.113549.1.9.16.3.7"
  1234.  
  1235. #define szOID_RSA_MD2           "1.2.840.113549.2.2"
  1236. #define szOID_RSA_MD4           "1.2.840.113549.2.4"
  1237. #define szOID_RSA_MD5           "1.2.840.113549.2.5"
  1238.  
  1239. #define szOID_RSA_RC2CBC        "1.2.840.113549.3.2"
  1240. #define szOID_RSA_RC4           "1.2.840.113549.3.4"
  1241. #define szOID_RSA_DES_EDE3_CBC  "1.2.840.113549.3.7"
  1242. #define szOID_RSA_RC5_CBCPad    "1.2.840.113549.3.9"
  1243.  
  1244.  
  1245. #define szOID_ANSI_X942         "1.2.840.10046"
  1246. #define szOID_ANSI_X942_DH      "1.2.840.10046.2.1"
  1247.  
  1248. #define szOID_X957              "1.2.840.10040"
  1249. #define szOID_X957_DSA          "1.2.840.10040.4.1"
  1250. #define szOID_X957_SHA1DSA      "1.2.840.10040.4.3"
  1251.  
  1252. // ITU-T UsefulDefinitions
  1253. #define szOID_DS                "2.5"
  1254. #define szOID_DSALG             "2.5.8"
  1255. #define szOID_DSALG_CRPT        "2.5.8.1"
  1256. #define szOID_DSALG_HASH        "2.5.8.2"
  1257. #define szOID_DSALG_SIGN        "2.5.8.3"
  1258. #define szOID_DSALG_RSA         "2.5.8.1.1"
  1259. // NIST OSE Implementors' Workshop (OIW)
  1260. // http://nemo.ncsl.nist.gov/oiw/agreements/stable/OSI/12s_9506.w51
  1261. // http://nemo.ncsl.nist.gov/oiw/agreements/working/OSI/12w_9503.w51
  1262. #define szOID_OIW               "1.3.14"
  1263. // NIST OSE Implementors' Workshop (OIW) Security SIG algorithm identifiers
  1264. #define szOID_OIWSEC            "1.3.14.3.2"
  1265. #define szOID_OIWSEC_md4RSA     "1.3.14.3.2.2"
  1266. #define szOID_OIWSEC_md5RSA     "1.3.14.3.2.3"
  1267. #define szOID_OIWSEC_md4RSA2    "1.3.14.3.2.4"
  1268. #define szOID_OIWSEC_desECB     "1.3.14.3.2.6"
  1269. #define szOID_OIWSEC_desCBC     "1.3.14.3.2.7"
  1270. #define szOID_OIWSEC_desOFB     "1.3.14.3.2.8"
  1271. #define szOID_OIWSEC_desCFB     "1.3.14.3.2.9"
  1272. #define szOID_OIWSEC_desMAC     "1.3.14.3.2.10"
  1273. #define szOID_OIWSEC_rsaSign    "1.3.14.3.2.11"
  1274. #define szOID_OIWSEC_dsa        "1.3.14.3.2.12"
  1275. #define szOID_OIWSEC_shaDSA     "1.3.14.3.2.13"
  1276. #define szOID_OIWSEC_mdc2RSA    "1.3.14.3.2.14"
  1277. #define szOID_OIWSEC_shaRSA     "1.3.14.3.2.15"
  1278. #define szOID_OIWSEC_dhCommMod  "1.3.14.3.2.16"
  1279. #define szOID_OIWSEC_desEDE     "1.3.14.3.2.17"
  1280. #define szOID_OIWSEC_sha        "1.3.14.3.2.18"
  1281. #define szOID_OIWSEC_mdc2       "1.3.14.3.2.19"
  1282. #define szOID_OIWSEC_dsaComm    "1.3.14.3.2.20"
  1283. #define szOID_OIWSEC_dsaCommSHA "1.3.14.3.2.21"
  1284. #define szOID_OIWSEC_rsaXchg    "1.3.14.3.2.22"
  1285. #define szOID_OIWSEC_keyHashSeal "1.3.14.3.2.23"
  1286. #define szOID_OIWSEC_md2RSASign "1.3.14.3.2.24"
  1287. #define szOID_OIWSEC_md5RSASign "1.3.14.3.2.25"
  1288. #define szOID_OIWSEC_sha1       "1.3.14.3.2.26"
  1289. #define szOID_OIWSEC_dsaSHA1    "1.3.14.3.2.27"
  1290. #define szOID_OIWSEC_dsaCommSHA1 "1.3.14.3.2.28"
  1291. #define szOID_OIWSEC_sha1RSASign "1.3.14.3.2.29"
  1292. // NIST OSE Implementors' Workshop (OIW) Directory SIG algorithm identifiers
  1293. #define szOID_OIWDIR            "1.3.14.7.2"
  1294. #define szOID_OIWDIR_CRPT       "1.3.14.7.2.1"
  1295. #define szOID_OIWDIR_HASH       "1.3.14.7.2.2"
  1296. #define szOID_OIWDIR_SIGN       "1.3.14.7.2.3"
  1297. #define szOID_OIWDIR_md2        "1.3.14.7.2.2.1"
  1298. #define szOID_OIWDIR_md2RSA     "1.3.14.7.2.3.1"
  1299.  
  1300.  
  1301. // INFOSEC Algorithms
  1302. // joint-iso-ccitt(2) country(16) us(840) organization(1) us-government(101) dod(2) id-infosec(1)
  1303. #define szOID_INFOSEC                       "2.16.840.1.101.2.1"
  1304. #define szOID_INFOSEC_sdnsSignature         "2.16.840.1.101.2.1.1.1"
  1305. #define szOID_INFOSEC_mosaicSignature       "2.16.840.1.101.2.1.1.2"
  1306. #define szOID_INFOSEC_sdnsConfidentiality   "2.16.840.1.101.2.1.1.3"
  1307. #define szOID_INFOSEC_mosaicConfidentiality "2.16.840.1.101.2.1.1.4"
  1308. #define szOID_INFOSEC_sdnsIntegrity         "2.16.840.1.101.2.1.1.5"
  1309. #define szOID_INFOSEC_mosaicIntegrity       "2.16.840.1.101.2.1.1.6"
  1310. #define szOID_INFOSEC_sdnsTokenProtection   "2.16.840.1.101.2.1.1.7"
  1311. #define szOID_INFOSEC_mosaicTokenProtection "2.16.840.1.101.2.1.1.8"
  1312. #define szOID_INFOSEC_sdnsKeyManagement     "2.16.840.1.101.2.1.1.9"
  1313. #define szOID_INFOSEC_mosaicKeyManagement   "2.16.840.1.101.2.1.1.10"
  1314. #define szOID_INFOSEC_sdnsKMandSig          "2.16.840.1.101.2.1.1.11"
  1315. #define szOID_INFOSEC_mosaicKMandSig        "2.16.840.1.101.2.1.1.12"
  1316. #define szOID_INFOSEC_SuiteASignature       "2.16.840.1.101.2.1.1.13"
  1317. #define szOID_INFOSEC_SuiteAConfidentiality "2.16.840.1.101.2.1.1.14"
  1318. #define szOID_INFOSEC_SuiteAIntegrity       "2.16.840.1.101.2.1.1.15"
  1319. #define szOID_INFOSEC_SuiteATokenProtection "2.16.840.1.101.2.1.1.16"
  1320. #define szOID_INFOSEC_SuiteAKeyManagement   "2.16.840.1.101.2.1.1.17"
  1321. #define szOID_INFOSEC_SuiteAKMandSig        "2.16.840.1.101.2.1.1.18"
  1322. #define szOID_INFOSEC_mosaicUpdatedSig      "2.16.840.1.101.2.1.1.19"
  1323. #define szOID_INFOSEC_mosaicKMandUpdSig     "2.16.840.1.101.2.1.1.20"
  1324. #define szOID_INFOSEC_mosaicUpdatedInteg    "2.16.840.1.101.2.1.1.21"
  1325.  
  1326. typedef struct _CRYPT_OBJID_TABLE {
  1327.     DWORD   dwAlgId;
  1328.     LPCSTR  pszObjId;
  1329. } CRYPT_OBJID_TABLE, *PCRYPT_OBJID_TABLE;
  1330.  
  1331.  
  1332. //+-------------------------------------------------------------------------
  1333. //  PKCS #1 HashInfo (DigestInfo)
  1334. //--------------------------------------------------------------------------
  1335. typedef struct _CRYPT_HASH_INFO {
  1336.     CRYPT_ALGORITHM_IDENTIFIER  HashAlgorithm;
  1337.     CRYPT_HASH_BLOB             Hash;
  1338. } CRYPT_HASH_INFO, *PCRYPT_HASH_INFO;
  1339.  
  1340. //+-------------------------------------------------------------------------
  1341. //  Type used for an extension to an encoded content
  1342. //
  1343. //  Where the Value's CRYPT_OBJID_BLOB is in its encoded representation.
  1344. //--------------------------------------------------------------------------
  1345. typedef struct _CERT_EXTENSION {
  1346.     LPSTR               pszObjId;
  1347.     BOOL                fCritical;
  1348.     CRYPT_OBJID_BLOB    Value;
  1349. } CERT_EXTENSION, *PCERT_EXTENSION;
  1350.  
  1351. //+-------------------------------------------------------------------------
  1352. //  AttributeTypeValue
  1353. //
  1354. //  Where the Value's CRYPT_OBJID_BLOB is in its encoded representation.
  1355. //--------------------------------------------------------------------------
  1356. typedef struct _CRYPT_ATTRIBUTE_TYPE_VALUE {
  1357.     LPSTR               pszObjId;
  1358.     CRYPT_OBJID_BLOB    Value;
  1359. } CRYPT_ATTRIBUTE_TYPE_VALUE, *PCRYPT_ATTRIBUTE_TYPE_VALUE;
  1360.  
  1361. //+-------------------------------------------------------------------------
  1362. //  Attributes
  1363. //
  1364. //  Where the Value's PATTR_BLOBs are in their encoded representation.
  1365. //--------------------------------------------------------------------------
  1366. typedef struct _CRYPT_ATTRIBUTE {
  1367.     LPSTR               pszObjId;
  1368.     DWORD               cValue;
  1369.     PCRYPT_ATTR_BLOB    rgValue;
  1370. } CRYPT_ATTRIBUTE, *PCRYPT_ATTRIBUTE;
  1371.  
  1372. typedef struct _CRYPT_ATTRIBUTES {
  1373.     IN DWORD                cAttr;
  1374.     IN PCRYPT_ATTRIBUTE     rgAttr;
  1375. } CRYPT_ATTRIBUTES, *PCRYPT_ATTRIBUTES;
  1376.  
  1377. //+-------------------------------------------------------------------------
  1378. //  Attributes making up a Relative Distinguished Name (CERT_RDN)
  1379. //
  1380. //  The interpretation of the Value depends on the dwValueType.
  1381. //  See below for a list of the types.
  1382. //--------------------------------------------------------------------------
  1383. typedef struct _CERT_RDN_ATTR {
  1384.     LPSTR                   pszObjId;
  1385.     DWORD                   dwValueType;
  1386.     CERT_RDN_VALUE_BLOB     Value;
  1387. } CERT_RDN_ATTR, *PCERT_RDN_ATTR;
  1388.  
  1389. //+-------------------------------------------------------------------------
  1390. //  CERT_RDN attribute Object Identifiers
  1391. //--------------------------------------------------------------------------
  1392. // Labeling attribute types:
  1393. #define szOID_COMMON_NAME                   "2.5.4.3"  // case-ignore string
  1394. #define szOID_SUR_NAME                      "2.5.4.4"  // case-ignore string
  1395. #define szOID_DEVICE_SERIAL_NUMBER          "2.5.4.5"  // printable string
  1396.  
  1397. // Geographic attribute types:
  1398. #define szOID_COUNTRY_NAME                  "2.5.4.6"  // printable 2char string
  1399. #define szOID_LOCALITY_NAME                 "2.5.4.7"  // case-ignore string
  1400. #define szOID_STATE_OR_PROVINCE_NAME        "2.5.4.8"  // case-ignore string
  1401. #define szOID_STREET_ADDRESS                "2.5.4.9"  // case-ignore string
  1402.  
  1403. // Organizational attribute types:
  1404. #define szOID_ORGANIZATION_NAME             "2.5.4.10" // case-ignore string
  1405. #define szOID_ORGANIZATIONAL_UNIT_NAME      "2.5.4.11" // case-ignore string
  1406. #define szOID_TITLE                         "2.5.4.12" // case-ignore string
  1407.  
  1408. // Explanatory attribute types:
  1409. #define szOID_DESCRIPTION                   "2.5.4.13" // case-ignore string
  1410. #define szOID_SEARCH_GUIDE                  "2.5.4.14"
  1411. #define szOID_BUSINESS_CATEGORY             "2.5.4.15" // case-ignore string
  1412.  
  1413. // Postal addressing attribute types:
  1414. #define szOID_POSTAL_ADDRESS                "2.5.4.16"
  1415. #define szOID_POSTAL_CODE                   "2.5.4.17" // case-ignore string
  1416. #define szOID_POST_OFFICE_BOX               "2.5.4.18" // case-ignore string
  1417. #define szOID_PHYSICAL_DELIVERY_OFFICE_NAME "2.5.4.19" // case-ignore string
  1418.  
  1419. // Telecommunications addressing attribute types:
  1420. #define szOID_TELEPHONE_NUMBER              "2.5.4.20" // telephone number
  1421. #define szOID_TELEX_NUMBER                  "2.5.4.21"
  1422. #define szOID_TELETEXT_TERMINAL_IDENTIFIER  "2.5.4.22"
  1423. #define szOID_FACSIMILE_TELEPHONE_NUMBER    "2.5.4.23"
  1424. #define szOID_X21_ADDRESS                   "2.5.4.24" // numeric string
  1425. #define szOID_INTERNATIONAL_ISDN_NUMBER     "2.5.4.25" // numeric string
  1426. #define szOID_REGISTERED_ADDRESS            "2.5.4.26"
  1427. #define szOID_DESTINATION_INDICATOR         "2.5.4.27" // printable string
  1428.  
  1429. // Preference attribute types:
  1430. #define szOID_PREFERRED_DELIVERY_METHOD     "2.5.4.28"
  1431.  
  1432. // OSI application attribute types:
  1433. #define szOID_PRESENTATION_ADDRESS          "2.5.4.29"
  1434. #define szOID_SUPPORTED_APPLICATION_CONTEXT "2.5.4.30"
  1435.  
  1436. // Relational application attribute types:
  1437. #define szOID_MEMBER                        "2.5.4.31"
  1438. #define szOID_OWNER                         "2.5.4.32"
  1439. #define szOID_ROLE_OCCUPANT                 "2.5.4.33"
  1440. #define szOID_SEE_ALSO                      "2.5.4.34"
  1441.  
  1442. // Security attribute types:
  1443. #define szOID_USER_PASSWORD                 "2.5.4.35"
  1444. #define szOID_USER_CERTIFICATE              "2.5.4.36"
  1445. #define szOID_CA_CERTIFICATE                "2.5.4.37"
  1446. #define szOID_AUTHORITY_REVOCATION_LIST     "2.5.4.38"
  1447. #define szOID_CERTIFICATE_REVOCATION_LIST   "2.5.4.39"
  1448. #define szOID_CROSS_CERTIFICATE_PAIR        "2.5.4.40"
  1449.  
  1450. // Undocumented attribute types???
  1451. //#define szOID_???                         "2.5.4.41"
  1452. #define szOID_GIVEN_NAME                    "2.5.4.42" // case-ignore string
  1453. #define szOID_INITIALS                      "2.5.4.43" // case-ignore string
  1454.  
  1455. // The DN Qualifier attribute type specifies disambiguating information to add
  1456. // to the relative distinguished name of an entry. It is intended to be used
  1457. // for entries held in multiple DSAs which would otherwise have the same name,
  1458. // and that its value be the same in a given DSA for all entries to which
  1459. // the information has been added.
  1460. #define szOID_DN_QUALIFIER                  "2.5.4.46"
  1461.  
  1462. // Pilot user attribute types:
  1463. #define szOID_DOMAIN_COMPONENT  "0.9.2342.19200300.100.1.25" // IA5, UTF8 string
  1464.  
  1465. // used for PKCS 12 attributes
  1466. #define szOID_PKCS_12_FRIENDLY_NAME_ATTR     "1.2.840.113549.1.9.20"
  1467. #define szOID_PKCS_12_LOCAL_KEY_ID           "1.2.840.113549.1.9.21"
  1468. #define szOID_PKCS_12_KEY_PROVIDER_NAME_ATTR "1.3.6.1.4.1.311.17.1"
  1469. #define szOID_LOCAL_MACHINE_KEYSET             "1.3.6.1.4.1.311.17.2"
  1470.  
  1471. //+-------------------------------------------------------------------------
  1472. //  Microsoft CERT_RDN attribute Object Identifiers
  1473. //--------------------------------------------------------------------------
  1474. // Special RDN containing the KEY_ID. Its value type is CERT_RDN_OCTET_STRING.
  1475. #define szOID_KEYID_RDN                     "1.3.6.1.4.1.311.10.7.1"
  1476.  
  1477. //+-------------------------------------------------------------------------
  1478. //  CERT_RDN Attribute Value Types
  1479. //
  1480. //  For RDN_ENCODED_BLOB, the Value's CERT_RDN_VALUE_BLOB is in its encoded
  1481. //  representation. Otherwise, its an array of bytes.
  1482. //
  1483. //  For all CERT_RDN types, Value.cbData is always the number of bytes, not
  1484. //  necessarily the number of elements in the string. For instance,
  1485. //  RDN_UNIVERSAL_STRING is an array of ints (cbData == intCnt * 4) and
  1486. //  RDN_BMP_STRING is an array of unsigned shorts (cbData == ushortCnt * 2).
  1487. //
  1488. //  A RDN_UTF8_STRING is an array of UNICODE characters (cbData == charCnt *2).
  1489. //  These UNICODE characters are encoded as UTF8 8 bit characters.
  1490. //
  1491. //  For CertDecodeName, two 0 bytes are always appended to the end of the
  1492. //  string (ensures a CHAR or WCHAR string is null terminated).
  1493. //  These added 0 bytes are't included in the BLOB.cbData.
  1494. //--------------------------------------------------------------------------
  1495. #define CERT_RDN_ANY_TYPE                0
  1496. #define CERT_RDN_ENCODED_BLOB            1
  1497. #define CERT_RDN_OCTET_STRING            2
  1498. #define CERT_RDN_NUMERIC_STRING          3
  1499. #define CERT_RDN_PRINTABLE_STRING        4
  1500. #define CERT_RDN_TELETEX_STRING          5
  1501. #define CERT_RDN_T61_STRING              5
  1502. #define CERT_RDN_VIDEOTEX_STRING         6
  1503. #define CERT_RDN_IA5_STRING              7
  1504. #define CERT_RDN_GRAPHIC_STRING          8
  1505. #define CERT_RDN_VISIBLE_STRING          9
  1506. #define CERT_RDN_ISO646_STRING           9
  1507. #define CERT_RDN_GENERAL_STRING          10
  1508. #define CERT_RDN_UNIVERSAL_STRING        11
  1509. #define CERT_RDN_INT4_STRING             11
  1510. #define CERT_RDN_BMP_STRING              12
  1511. #define CERT_RDN_UNICODE_STRING          12
  1512. #define CERT_RDN_UTF8_STRING             13
  1513.  
  1514. #define CERT_RDN_TYPE_MASK                  0x000000FF
  1515. #define CERT_RDN_FLAGS_MASK                 0xFF000000
  1516.  
  1517. //+-------------------------------------------------------------------------
  1518. //  Flags that can be or'ed with the above Value Type when encoding/decoding
  1519. //--------------------------------------------------------------------------
  1520. // For encoding: when set, CERT_RDN_T61_STRING is selected instead of
  1521. // CERT_RDN_UNICODE_STRING if all the unicode characters are <= 0xFF
  1522. #define CERT_RDN_ENABLE_T61_UNICODE_FLAG    0x80000000
  1523.  
  1524. // For encoding: when set, CERT_RDN_UTF8_STRING is selected instead of
  1525. // CERT_RDN_UNICODE_STRING.
  1526. #define CERT_RDN_ENABLE_UTF8_UNICODE_FLAG   0x20000000
  1527.  
  1528. // For encoding: when set, the characters aren't checked to see if they
  1529. // are valid for the Value Type.
  1530. #define CERT_RDN_DISABLE_CHECK_TYPE_FLAG    0x40000000
  1531.  
  1532. // For decoding: by default, CERT_RDN_T61_STRING values are initially decoded
  1533. // as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  1534. // Setting this flag skips the initial attempt to decode as UTF8.
  1535. #define CERT_RDN_DISABLE_IE4_UTF8_FLAG      0x01000000
  1536.  
  1537.  
  1538. // Macro to check that the dwValueType is a character string and not an
  1539. // encoded blob or octet string
  1540. #define IS_CERT_RDN_CHAR_STRING(X)      \
  1541.                 (((X) & CERT_RDN_TYPE_MASK) >= CERT_RDN_NUMERIC_STRING)
  1542.  
  1543.  
  1544. //+-------------------------------------------------------------------------
  1545. //  A CERT_RDN consists of an array of the above attributes
  1546. //--------------------------------------------------------------------------
  1547. typedef struct _CERT_RDN {
  1548.     DWORD           cRDNAttr;
  1549.     PCERT_RDN_ATTR  rgRDNAttr;
  1550. } CERT_RDN, *PCERT_RDN;
  1551.  
  1552. //+-------------------------------------------------------------------------
  1553. //  Information stored in a subject's or issuer's name. The information
  1554. //  is represented as an array of the above RDNs.
  1555. //--------------------------------------------------------------------------
  1556. typedef struct _CERT_NAME_INFO {
  1557.     DWORD       cRDN;
  1558.     PCERT_RDN   rgRDN;
  1559. } CERT_NAME_INFO, *PCERT_NAME_INFO;
  1560.  
  1561. //+-------------------------------------------------------------------------
  1562. //  Name attribute value without the Object Identifier
  1563. //
  1564. //  The interpretation of the Value depends on the dwValueType.
  1565. //  See above for a list of the types.
  1566. //--------------------------------------------------------------------------
  1567. typedef struct _CERT_NAME_VALUE {
  1568.     DWORD               dwValueType;
  1569.     CERT_RDN_VALUE_BLOB Value;
  1570. } CERT_NAME_VALUE, *PCERT_NAME_VALUE;
  1571.  
  1572. //+-------------------------------------------------------------------------
  1573. //  Public Key Info
  1574. //
  1575. //  The PublicKey is the encoded representation of the information as it is
  1576. //  stored in the bit string
  1577. //--------------------------------------------------------------------------
  1578. typedef struct _CERT_PUBLIC_KEY_INFO {
  1579.     CRYPT_ALGORITHM_IDENTIFIER    Algorithm;
  1580.     CRYPT_BIT_BLOB                PublicKey;
  1581. } CERT_PUBLIC_KEY_INFO, *PCERT_PUBLIC_KEY_INFO;
  1582.  
  1583. #define CERT_RSA_PUBLIC_KEY_OBJID            szOID_RSA_RSA
  1584. #define CERT_DEFAULT_OID_PUBLIC_KEY_SIGN     szOID_RSA_RSA
  1585. #define CERT_DEFAULT_OID_PUBLIC_KEY_XCHG     szOID_RSA_RSA
  1586.  
  1587.  
  1588. //+-------------------------------------------------------------------------
  1589. //  structure that contains all the information in a PKCS#8 PrivateKeyInfo
  1590. //--------------------------------------------------------------------------
  1591. typedef struct _CRYPT_PRIVATE_KEY_INFO{
  1592.     DWORD                       Version;
  1593.     CRYPT_ALGORITHM_IDENTIFIER  Algorithm;
  1594.     CRYPT_DER_BLOB              PrivateKey;
  1595.     PCRYPT_ATTRIBUTES           pAttributes;
  1596. }  CRYPT_PRIVATE_KEY_INFO, *PCRYPT_PRIVATE_KEY_INFO;
  1597.  
  1598. //+-------------------------------------------------------------------------
  1599. //  structure that contains all the information in a PKCS#8
  1600. //  EncryptedPrivateKeyInfo
  1601. //--------------------------------------------------------------------------
  1602. typedef struct _CRYPT_ENCRYPTED_PRIVATE_KEY_INFO{
  1603.     CRYPT_ALGORITHM_IDENTIFIER  EncryptionAlgorithm;
  1604.     CRYPT_DATA_BLOB             EncryptedPrivateKey;
  1605. } CRYPT_ENCRYPTED_PRIVATE_KEY_INFO, *PCRYPT_ENCRYPTED_PRIVATE_KEY_INFO;
  1606.  
  1607. //+-------------------------------------------------------------------------
  1608. // this callback is given when an EncryptedProvateKeyInfo structure is
  1609. // encountered during ImportPKCS8.  the caller is then expected to decrypt
  1610. // the private key and hand back the decrypted contents.
  1611. //
  1612. // the parameters are:
  1613. // Algorithm - the algorithm used to encrypt the PrivateKeyInfo
  1614. // EncryptedPrivateKey - the encrypted private key blob
  1615. // pClearTextKey - a buffer to receive the clear text
  1616. // cbClearTextKey - the number of bytes of the pClearTextKey buffer
  1617. //                  note the if this is zero then this should be
  1618. //                  filled in with the size required to decrypt the
  1619. //                  key into, and pClearTextKey should be ignored
  1620. // pVoidDecryptFunc - this is the pVoid that was passed into the call
  1621. //                    and is preserved and passed back as context
  1622. //+-------------------------------------------------------------------------
  1623. typedef BOOL (CALLBACK *PCRYPT_DECRYPT_PRIVATE_KEY_FUNC)(
  1624.                                                         CRYPT_ALGORITHM_IDENTIFIER  Algorithm,
  1625.                                                         CRYPT_DATA_BLOB             EncryptedPrivateKey,
  1626.                                                         BYTE                        *pbClearTextKey,
  1627.                                                         DWORD                       *pcbClearTextKey,
  1628.                                                         LPVOID                      pVoidDecryptFunc);
  1629.  
  1630. //+-------------------------------------------------------------------------
  1631. // this callback is given when creating a PKCS8 EncryptedPrivateKeyInfo.
  1632. // The caller is then expected to encrypt the private key and hand back
  1633. // the encrypted contents.
  1634. //
  1635. // the parameters are:
  1636. // Algorithm - the algorithm used to encrypt the PrivateKeyInfo
  1637. // pClearTextPrivateKey - the cleartext private key to be encrypted
  1638. // pbEncryptedKey - the output encrypted private key blob
  1639. // cbEncryptedKey - the number of bytes of the pbEncryptedKey buffer
  1640. //                  note the if this is zero then this should be
  1641. //                  filled in with the size required to encrypt the
  1642. //                  key into, and pbEncryptedKey should be ignored
  1643. // pVoidEncryptFunc - this is the pVoid that was passed into the call
  1644. //                    and is preserved and passed back as context
  1645. //+-------------------------------------------------------------------------
  1646. typedef BOOL (CALLBACK *PCRYPT_ENCRYPT_PRIVATE_KEY_FUNC)(
  1647.                                                         CRYPT_ALGORITHM_IDENTIFIER* pAlgorithm,
  1648.                                                         CRYPT_DATA_BLOB*            pClearTextPrivateKey,
  1649.                                                         BYTE                        *pbEncryptedKey,
  1650.                                                         DWORD                       *pcbEncryptedKey,
  1651.                                                         LPVOID                      pVoidEncryptFunc);
  1652.  
  1653. //+-------------------------------------------------------------------------
  1654. // this callback is given from the context of a ImportPKCS8 calls.  the caller
  1655. // is then expected to hand back an HCRYPTPROV to receive the key being imported
  1656. //
  1657. // the parameters are:
  1658. // pPrivateKeyInfo - pointer to a CRYPT_PRIVATE_KEY_INFO structure which
  1659. //                   describes the key being imported
  1660. // EncryptedPrivateKey - the encrypted private key blob
  1661. // phCryptProv - a pointer to a HCRRYPTPROV to be filled in
  1662. // pVoidResolveFunc - this is the pVoidResolveFunc passed in by the caller in the
  1663. //                    CRYPT_PRIVATE_KEY_BLOB_AND_PARAMS struct
  1664. //+-------------------------------------------------------------------------
  1665. typedef BOOL (CALLBACK *PCRYPT_RESOLVE_HCRYPTPROV_FUNC)(
  1666.                                                        CRYPT_PRIVATE_KEY_INFO      *pPrivateKeyInfo,
  1667.                                                        HCRYPTPROV                  *phCryptProv,
  1668.                                                        LPVOID                      pVoidResolveFunc);
  1669.  
  1670. //+-------------------------------------------------------------------------
  1671. // this struct contains a PKCS8 private key and two pointers to callback
  1672. // functions, with a corresponding pVoids.  the first callback is used to give
  1673. // the caller the opportunity to specify where the key is imported to.  the callback
  1674. // passes the caller the algoroithm OID and key size to use in making the decision.
  1675. // the other callback is used to decrypt the private key if the PKCS8 contains an
  1676. // EncryptedPrivateKeyInfo.  both pVoids are preserved and passed back to the caller
  1677. // in the respective callback
  1678. //+-------------------------------------------------------------------------
  1679. typedef struct _CRYPT_PKCS8_IMPORT_PARAMS{
  1680.     CRYPT_DIGEST_BLOB               PrivateKey;             // PKCS8 blob
  1681.     PCRYPT_RESOLVE_HCRYPTPROV_FUNC  pResolvehCryptProvFunc; // optional
  1682.     LPVOID                          pVoidResolveFunc;       // optional
  1683.     PCRYPT_DECRYPT_PRIVATE_KEY_FUNC pDecryptPrivateKeyFunc;
  1684.     LPVOID                          pVoidDecryptFunc;
  1685. } CRYPT_PKCS8_IMPORT_PARAMS, *PCRYPT_PKCS8_IMPORT_PARAMS, CRYPT_PRIVATE_KEY_BLOB_AND_PARAMS, *PCRYPT_PRIVATE_KEY_BLOB_AND_PARAMS;
  1686.  
  1687.  
  1688. //+-------------------------------------------------------------------------
  1689. // this struct contains information identifying a private key and a pointer
  1690. // to a callback function, with a corresponding pVoid. The callback is used
  1691. // to encrypt the private key. If the pEncryptPrivateKeyFunc is NULL, the
  1692. // key will not be encrypted and an EncryptedPrivateKeyInfo will not be generated.
  1693. // The pVoid is preserved and passed back to the caller in the respective callback
  1694. //+-------------------------------------------------------------------------
  1695. typedef struct _CRYPT_PKCS8_EXPORT_PARAMS{
  1696.     HCRYPTPROV                      hCryptProv;
  1697.     DWORD                           dwKeySpec;
  1698.     LPSTR                           pszPrivateKeyObjId;
  1699.  
  1700.     PCRYPT_ENCRYPT_PRIVATE_KEY_FUNC pEncryptPrivateKeyFunc;
  1701.     LPVOID                          pVoidEncryptFunc;
  1702. } CRYPT_PKCS8_EXPORT_PARAMS, *PCRYPT_PKCS8_EXPORT_PARAMS;
  1703.  
  1704. //+-------------------------------------------------------------------------
  1705. //  Information stored in a certificate
  1706. //
  1707. //  The Issuer, Subject, Algorithm, PublicKey and Extension BLOBs are the
  1708. //  encoded representation of the information.
  1709. //--------------------------------------------------------------------------
  1710. typedef struct _CERT_INFO {
  1711.     DWORD                       dwVersion;
  1712.     CRYPT_INTEGER_BLOB          SerialNumber;
  1713.     CRYPT_ALGORITHM_IDENTIFIER  SignatureAlgorithm;
  1714.     CERT_NAME_BLOB              Issuer;
  1715.     FILETIME                    NotBefore;
  1716.     FILETIME                    NotAfter;
  1717.     CERT_NAME_BLOB              Subject;
  1718.     CERT_PUBLIC_KEY_INFO        SubjectPublicKeyInfo;
  1719.     CRYPT_BIT_BLOB              IssuerUniqueId;
  1720.     CRYPT_BIT_BLOB              SubjectUniqueId;
  1721.     DWORD                       cExtension;
  1722.     PCERT_EXTENSION             rgExtension;
  1723. } CERT_INFO, *PCERT_INFO;
  1724.  
  1725. //+-------------------------------------------------------------------------
  1726. //  Certificate versions
  1727. //--------------------------------------------------------------------------
  1728. #define CERT_V1     0
  1729. #define CERT_V2     1
  1730. #define CERT_V3     2
  1731.  
  1732. //+-------------------------------------------------------------------------
  1733. //  Certificate Information Flags
  1734. //--------------------------------------------------------------------------
  1735. #define CERT_INFO_VERSION_FLAG                      1
  1736. #define CERT_INFO_SERIAL_NUMBER_FLAG                2
  1737. #define CERT_INFO_SIGNATURE_ALGORITHM_FLAG          3
  1738. #define CERT_INFO_ISSUER_FLAG                       4
  1739. #define CERT_INFO_NOT_BEFORE_FLAG                   5
  1740. #define CERT_INFO_NOT_AFTER_FLAG                    6
  1741. #define CERT_INFO_SUBJECT_FLAG                      7
  1742. #define CERT_INFO_SUBJECT_PUBLIC_KEY_INFO_FLAG      8
  1743. #define CERT_INFO_ISSUER_UNIQUE_ID_FLAG             9
  1744. #define CERT_INFO_SUBJECT_UNIQUE_ID_FLAG            10
  1745. #define CERT_INFO_EXTENSION_FLAG                    11
  1746.  
  1747. //+-------------------------------------------------------------------------
  1748. //  An entry in a CRL
  1749. //
  1750. //  The Extension BLOBs are the encoded representation of the information.
  1751. //--------------------------------------------------------------------------
  1752. typedef struct _CRL_ENTRY {
  1753.     CRYPT_INTEGER_BLOB  SerialNumber;
  1754.     FILETIME            RevocationDate;
  1755.     DWORD               cExtension;
  1756.     PCERT_EXTENSION     rgExtension;
  1757. } CRL_ENTRY, *PCRL_ENTRY;
  1758.  
  1759. //+-------------------------------------------------------------------------
  1760. //  Information stored in a CRL
  1761. //
  1762. //  The Issuer, Algorithm and Extension BLOBs are the encoded
  1763. //  representation of the information.
  1764. //--------------------------------------------------------------------------
  1765. typedef struct _CRL_INFO {
  1766.     DWORD                       dwVersion;
  1767.     CRYPT_ALGORITHM_IDENTIFIER  SignatureAlgorithm;
  1768.     CERT_NAME_BLOB              Issuer;
  1769.     FILETIME                    ThisUpdate;
  1770.     FILETIME                    NextUpdate;
  1771.     DWORD                       cCRLEntry;
  1772.     PCRL_ENTRY                  rgCRLEntry;
  1773.     DWORD                       cExtension;
  1774.     PCERT_EXTENSION             rgExtension;
  1775. } CRL_INFO, *PCRL_INFO;
  1776.  
  1777. //+-------------------------------------------------------------------------
  1778. //  CRL versions
  1779. //--------------------------------------------------------------------------
  1780. #define CRL_V1     0
  1781. #define CRL_V2     1
  1782.  
  1783.  
  1784. //+-------------------------------------------------------------------------
  1785. //  Information stored in a certificate request
  1786. //
  1787. //  The Subject, Algorithm, PublicKey and Attribute BLOBs are the encoded
  1788. //  representation of the information.
  1789. //--------------------------------------------------------------------------
  1790. typedef struct _CERT_REQUEST_INFO {
  1791.     DWORD                   dwVersion;
  1792.     CERT_NAME_BLOB          Subject;
  1793.     CERT_PUBLIC_KEY_INFO    SubjectPublicKeyInfo;
  1794.     DWORD                   cAttribute;
  1795.     PCRYPT_ATTRIBUTE        rgAttribute;
  1796. } CERT_REQUEST_INFO, *PCERT_REQUEST_INFO;
  1797.  
  1798. //+-------------------------------------------------------------------------
  1799. //  Certificate Request versions
  1800. //--------------------------------------------------------------------------
  1801. #define CERT_REQUEST_V1     0
  1802.  
  1803. //+-------------------------------------------------------------------------
  1804. //  Information stored in Netscape's Keygen request
  1805. //--------------------------------------------------------------------------
  1806. typedef struct _CERT_KEYGEN_REQUEST_INFO {
  1807.     DWORD                   dwVersion;
  1808.     CERT_PUBLIC_KEY_INFO    SubjectPublicKeyInfo;
  1809.     LPWSTR                  pwszChallengeString;        // encoded as IA5
  1810. } CERT_KEYGEN_REQUEST_INFO, *PCERT_KEYGEN_REQUEST_INFO;
  1811.  
  1812. #define CERT_KEYGEN_REQUEST_V1     0
  1813.  
  1814.  
  1815. //+-------------------------------------------------------------------------
  1816. //  Certificate, CRL, Certificate Request or Keygen Request Signed Content
  1817. //
  1818. //  The "to be signed" encoded content plus its signature. The ToBeSigned
  1819. //  is the encoded CERT_INFO, CRL_INFO, CERT_REQUEST_INFO or
  1820. //  CERT_KEYGEN_REQUEST_INFO.
  1821. //--------------------------------------------------------------------------
  1822. typedef struct _CERT_SIGNED_CONTENT_INFO {
  1823.     CRYPT_DER_BLOB              ToBeSigned;
  1824.     CRYPT_ALGORITHM_IDENTIFIER  SignatureAlgorithm;
  1825.     CRYPT_BIT_BLOB              Signature;
  1826. } CERT_SIGNED_CONTENT_INFO, *PCERT_SIGNED_CONTENT_INFO;
  1827.  
  1828.  
  1829. //+-------------------------------------------------------------------------
  1830. //  Certificate Trust List (CTL)
  1831. //--------------------------------------------------------------------------
  1832.  
  1833. //+-------------------------------------------------------------------------
  1834. //  CTL Usage. Also used for EnhancedKeyUsage extension.
  1835. //--------------------------------------------------------------------------
  1836. typedef struct _CTL_USAGE {
  1837.     DWORD               cUsageIdentifier;
  1838.     LPSTR               *rgpszUsageIdentifier;      // array of pszObjId
  1839. } CTL_USAGE, *PCTL_USAGE,
  1840. CERT_ENHKEY_USAGE, *PCERT_ENHKEY_USAGE;
  1841.  
  1842.  
  1843. //+-------------------------------------------------------------------------
  1844. //  An entry in a CTL
  1845. //--------------------------------------------------------------------------
  1846. typedef struct _CTL_ENTRY {
  1847.     CRYPT_DATA_BLOB     SubjectIdentifier;          // For example, its hash
  1848.     DWORD               cAttribute;
  1849.     PCRYPT_ATTRIBUTE    rgAttribute;                // OPTIONAL
  1850. } CTL_ENTRY, *PCTL_ENTRY;
  1851.  
  1852. //+-------------------------------------------------------------------------
  1853. //  Information stored in a CTL
  1854. //--------------------------------------------------------------------------
  1855. typedef struct _CTL_INFO {
  1856.     DWORD                       dwVersion;
  1857.     CTL_USAGE                   SubjectUsage;
  1858.     CRYPT_DATA_BLOB             ListIdentifier;     // OPTIONAL
  1859.     CRYPT_INTEGER_BLOB          SequenceNumber;     // OPTIONAL
  1860.     FILETIME                    ThisUpdate;
  1861.     FILETIME                    NextUpdate;         // OPTIONAL
  1862.     CRYPT_ALGORITHM_IDENTIFIER  SubjectAlgorithm;
  1863.     DWORD                       cCTLEntry;
  1864.     PCTL_ENTRY                  rgCTLEntry;         // OPTIONAL
  1865.     DWORD                       cExtension;
  1866.     PCERT_EXTENSION             rgExtension;        // OPTIONAL
  1867. } CTL_INFO, *PCTL_INFO;
  1868.  
  1869. //+-------------------------------------------------------------------------
  1870. //  CTL versions
  1871. //--------------------------------------------------------------------------
  1872. #define CTL_V1     0
  1873.  
  1874.  
  1875. //+-------------------------------------------------------------------------
  1876. //  TimeStamp Request
  1877. //
  1878. //  The pszTimeStamp is the OID for the Time type requested
  1879. //  The pszContentType is the Content Type OID for the content, usually DATA
  1880. //  The Content is a un-decoded blob
  1881. //--------------------------------------------------------------------------
  1882. typedef struct _CRYPT_TIME_STAMP_REQUEST_INFO {
  1883.     LPSTR                   pszTimeStampAlgorithm;   // pszObjId
  1884.     LPSTR                   pszContentType;          // pszObjId
  1885.     CRYPT_OBJID_BLOB        Content;
  1886.     DWORD                   cAttribute;
  1887.     PCRYPT_ATTRIBUTE        rgAttribute;
  1888. } CRYPT_TIME_STAMP_REQUEST_INFO, *PCRYPT_TIME_STAMP_REQUEST_INFO;
  1889.  
  1890. //+-------------------------------------------------------------------------
  1891. //  Name Value Attribute
  1892. //--------------------------------------------------------------------------
  1893. typedef struct _CRYPT_ENROLLMENT_NAME_VALUE_PAIR {
  1894.     LPWSTR      pwszName;
  1895.     LPWSTR      pwszValue;
  1896. } CRYPT_ENROLLMENT_NAME_VALUE_PAIR, * PCRYPT_ENROLLMENT_NAME_VALUE_PAIR;
  1897.  
  1898. //+-------------------------------------------------------------------------
  1899. //  CSP Provider
  1900. //--------------------------------------------------------------------------
  1901. typedef struct _CRYPT_CSP_PROVIDER {
  1902.     DWORD           dwKeySpec;
  1903.     LPWSTR          pwszProviderName;
  1904.     CRYPT_BIT_BLOB  Signature;
  1905. } CRYPT_CSP_PROVIDER, * PCRYPT_CSP_PROVIDER;
  1906.  
  1907. //+-------------------------------------------------------------------------
  1908. //  Certificate and Message encoding types
  1909. //
  1910. //  The encoding type is a DWORD containing both the certificate and message
  1911. //  encoding types. The certificate encoding type is stored in the LOWORD.
  1912. //  The message encoding type is stored in the HIWORD. Some functions or
  1913. //  structure fields require only one of the encoding types. The following
  1914. //  naming convention is used to indicate which encoding type(s) are
  1915. //  required:
  1916. //      dwEncodingType              (both encoding types are required)
  1917. //      dwMsgAndCertEncodingType    (both encoding types are required)
  1918. //      dwMsgEncodingType           (only msg encoding type is required)
  1919. //      dwCertEncodingType          (only cert encoding type is required)
  1920. //
  1921. //  Its always acceptable to specify both.
  1922. //--------------------------------------------------------------------------
  1923. #define CERT_ENCODING_TYPE_MASK     0x0000FFFF
  1924. #define CMSG_ENCODING_TYPE_MASK     0xFFFF0000
  1925. #define GET_CERT_ENCODING_TYPE(X)   (X & CERT_ENCODING_TYPE_MASK)
  1926. #define GET_CMSG_ENCODING_TYPE(X)   (X & CMSG_ENCODING_TYPE_MASK)
  1927.  
  1928. #define CRYPT_ASN_ENCODING          0x00000001
  1929. #define CRYPT_NDR_ENCODING          0x00000002
  1930. #define X509_ASN_ENCODING           0x00000001
  1931. #define X509_NDR_ENCODING           0x00000002
  1932. #define PKCS_7_ASN_ENCODING         0x00010000
  1933. #define PKCS_7_NDR_ENCODING         0x00020000
  1934.  
  1935.  
  1936. //+-------------------------------------------------------------------------
  1937. //  format the specified data structure according to the certificate
  1938. //  encoding type.
  1939. //
  1940. //  The default behavior of CryptFormatObject is to return single line
  1941. //  display of the encoded data, that is, each subfield will be concatenated with
  1942. //  a ", " on one line.  If user prefers to display the data in multiple line,
  1943. //  set the flag CRYPT_FORMAT_STR_MULTI_LINE, that is, each subfield will be displayed
  1944. //  on a seperate line.
  1945. //
  1946. //  If there is no formatting routine installed or registered
  1947. //  for the lpszStructType, the hex dump of the encoded BLOB will be returned.
  1948. //  User can set the flag CRYPT_FORMAT_STR_NO_HEX to disable the hex dump.
  1949. //--------------------------------------------------------------------------
  1950. WINCRYPT32API
  1951. BOOL
  1952. WINAPI
  1953. CryptFormatObject(
  1954.     IN DWORD dwCertEncodingType,
  1955.     IN DWORD dwFormatType,
  1956.     IN DWORD dwFormatStrType,
  1957.     IN void  *pFormatStruct,
  1958.     IN LPCSTR lpszStructType,
  1959.     IN const BYTE *pbEncoded,
  1960.     IN DWORD cbEncoded,
  1961.     OUT void *pbFormat,
  1962.     IN OUT DWORD *pcbFormat
  1963.     );
  1964. //-------------------------------------------------------------------------
  1965. // constants for dwFormatStrType of function CryptFormatObject
  1966. //-------------------------------------------------------------------------
  1967. #define         CRYPT_FORMAT_STR_MULTI_LINE         0x0001
  1968. #define         CRYPT_FORMAT_STR_NO_HEX             0x0010
  1969.  
  1970. //-------------------------------------------------------------------------
  1971. // constants for dwFormatType of function CryptFormatObject
  1972. // when format X509_NAME or X509_UNICODE_NAME
  1973. //-------------------------------------------------------------------------
  1974. // Just get the simple string
  1975. #define         CRYPT_FORMAT_SIMPLE                 0x0001
  1976.  
  1977. //Put an attribute name infront of the attribute
  1978. //such as "O=Microsoft,DN=xiaohs"
  1979. #define         CRYPT_FORMAT_X509                   0x0002
  1980.  
  1981. //Put an OID infront of the simple string, such as
  1982. //"2.5.4.22=Microsoft,2.5.4.3=xiaohs"
  1983. #define         CRYPT_FORMAT_OID                    0x0004
  1984.  
  1985. //Put a ";" between each RDN.  The default is ","
  1986. #define         CRYPT_FORMAT_RDN_SEMICOLON          0x0100
  1987.  
  1988. //Put a "\n" between each RDN.
  1989. #define         CRYPT_FORMAT_RDN_CRLF               0x0200
  1990.  
  1991.  
  1992. //Unquote the DN value, which is quoated by default va the following
  1993. //rules: if the DN contains leading or trailing
  1994. //white space or one of the following characters: ",", "+", "=",
  1995. //""", "\n",  "<", ">", "#" or ";". The quoting character is ".
  1996. //If the DN Value contains a " it is double quoted ("").
  1997. #define         CRYPT_FORMAT_RDN_UNQUOTE            0x0400
  1998.  
  1999. //reverse the order of the RDNs before converting to the string
  2000. #define         CRYPT_FORMAT_RDN_REVERSE            0x0800
  2001.  
  2002.  
  2003. //-------------------------------------------------------------------------
  2004. //  contants dwFormatType of function CryptFormatObject when format a DN.:
  2005. //
  2006. //  The following three values are defined in the section above:
  2007. //  CRYPT_FORMAT_SIMPLE:    Just a simple string
  2008. //                          such as  "Microsoft+xiaohs+NT"
  2009. //  CRYPT_FORMAT_X509       Put an attribute name infront of the attribute
  2010. //                          such as "O=Microsoft+xiaohs+NT"
  2011. //
  2012. //  CRYPT_FORMAT_OID        Put an OID infront of the simple string,
  2013. //                          such as "2.5.4.22=Microsoft+xiaohs+NT"
  2014. //
  2015. //  Additional values are defined as following:
  2016. //----------------------------------------------------------------------------
  2017. //Put a "," between each value.  Default is "+"
  2018. #define         CRYPT_FORMAT_COMMA                  0x1000
  2019.  
  2020. //Put a ";" between each value
  2021. #define         CRYPT_FORMAT_SEMICOLON              CRYPT_FORMAT_RDN_SEMICOLON
  2022.  
  2023. //Put a "\n" between each value
  2024. #define         CRYPT_FORMAT_CRLF                   CRYPT_FORMAT_RDN_CRLF
  2025.  
  2026. //+-------------------------------------------------------------------------
  2027. //  Encode / decode the specified data structure according to the certificate
  2028. //  encoding type.
  2029. //
  2030. //  See below for a list of the predefined data structures.
  2031. //--------------------------------------------------------------------------
  2032.  
  2033. typedef LPVOID (WINAPI *PFN_CRYPT_ALLOC)(
  2034.     IN size_t cbSize
  2035.     );
  2036.  
  2037. typedef VOID (WINAPI *PFN_CRYPT_FREE)(
  2038.     IN LPVOID pv
  2039.     );
  2040.  
  2041.  
  2042. typedef struct _CRYPT_ENCODE_PARA {
  2043.     DWORD                   cbSize;
  2044.     PFN_CRYPT_ALLOC         pfnAlloc;           // OPTIONAL
  2045.     PFN_CRYPT_FREE          pfnFree;            // OPTIONAL
  2046. } CRYPT_ENCODE_PARA, *PCRYPT_ENCODE_PARA;
  2047.  
  2048.  
  2049. WINCRYPT32API
  2050. BOOL
  2051. WINAPI
  2052. CryptEncodeObjectEx(
  2053.     IN DWORD dwCertEncodingType,
  2054.     IN LPCSTR lpszStructType,
  2055.     IN const void *pvStructInfo,
  2056.     IN DWORD dwFlags,
  2057.     IN OPTIONAL PCRYPT_ENCODE_PARA pEncodePara,
  2058.     OUT void *pvEncoded,
  2059.     IN OUT DWORD *pcbEncoded
  2060.     );
  2061.  
  2062. WINCRYPT32API
  2063. BOOL
  2064. WINAPI
  2065. CryptEncodeObject(
  2066.     IN DWORD        dwCertEncodingType,
  2067.     IN LPCSTR       lpszStructType,
  2068.     IN const void   *pvStructInfo,
  2069.     OUT BYTE        *pbEncoded,
  2070.     IN OUT DWORD    *pcbEncoded
  2071.     );
  2072.  
  2073. // By default the signature bytes are reversed. The following flag can
  2074. // be set to inhibit the byte reversal.
  2075. //
  2076. // This flag is applicable to
  2077. //      X509_CERT_TO_BE_SIGNED
  2078. #define CRYPT_ENCODE_NO_SIGNATURE_BYTE_REVERSAL_FLAG    0x8
  2079.  
  2080.  
  2081. //  When the following flag is set the called encode function allocates
  2082. //  memory for the encoded bytes. A pointer to the allocated bytes
  2083. //  is returned in pvEncoded. If pEncodePara or pEncodePara->pfnAlloc is
  2084. //  NULL, then, LocalAlloc is called for the allocation and LocalFree must
  2085. //  be called to do the free. Otherwise, pEncodePara->pfnAlloc is called
  2086. //  for the allocation.
  2087. //
  2088. //  *pcbEncoded is ignored on input and updated with the length of the
  2089. //  allocated, encoded bytes.
  2090. //
  2091. //  If pfnAlloc is set, then, pfnFree should also be set.
  2092. #define CRYPT_ENCODE_ALLOC_FLAG             0x8000
  2093.  
  2094.  
  2095. //  The following flag is applicable when encoding X509_UNICODE_NAME.
  2096. //  When set, CERT_RDN_T61_STRING is selected instead of
  2097. //  CERT_RDN_UNICODE_STRING if all the unicode characters are <= 0xFF
  2098. #define CRYPT_UNICODE_NAME_ENCODE_ENABLE_T61_UNICODE_FLAG   \
  2099.             CERT_RDN_ENABLE_T61_UNICODE_FLAG
  2100.  
  2101. //  The following flag is applicable when encoding X509_UNICODE_NAME.
  2102. //  When set, CERT_RDN_UTF8_STRING is selected instead of
  2103. //  CERT_RDN_UNICODE_STRING.
  2104. #define CRYPT_UNICODE_NAME_ENCODE_ENABLE_UTF8_UNICODE_FLAG   \
  2105.             CERT_RDN_ENABLE_UTF8_UNICODE_FLAG
  2106.  
  2107. //  The following flag is applicable when encoding X509_UNICODE_NAME,
  2108. //  X509_UNICODE_NAME_VALUE or X509_UNICODE_ANY_STRING.
  2109. //  When set, the characters aren't checked to see if they
  2110. //  are valid for the specified Value Type.
  2111. #define CRYPT_UNICODE_NAME_ENCODE_DISABLE_CHECK_TYPE_FLAG   \
  2112.             CERT_RDN_DISABLE_CHECK_TYPE_FLAG
  2113.  
  2114. //  The following flag is applicable when encoding the PKCS_SORTED_CTL. This
  2115. //  flag should be set if the identifier for the TrustedSubjects is a hash,
  2116. //  such as, MD5 or SHA1.
  2117. #define CRYPT_SORTED_CTL_ENCODE_HASHED_SUBJECT_IDENTIFIER_FLAG     0x10000
  2118.  
  2119.  
  2120. typedef struct _CRYPT_DECODE_PARA {
  2121.     DWORD                   cbSize;
  2122.     PFN_CRYPT_ALLOC         pfnAlloc;           // OPTIONAL
  2123.     PFN_CRYPT_FREE          pfnFree;            // OPTIONAL
  2124. } CRYPT_DECODE_PARA, *PCRYPT_DECODE_PARA;
  2125.  
  2126. WINCRYPT32API
  2127. BOOL
  2128. WINAPI
  2129. CryptDecodeObjectEx(
  2130.     IN DWORD dwCertEncodingType,
  2131.     IN LPCSTR lpszStructType,
  2132.     IN const BYTE *pbEncoded,
  2133.     IN DWORD cbEncoded,
  2134.     IN DWORD dwFlags,
  2135.     IN OPTIONAL PCRYPT_DECODE_PARA pDecodePara,
  2136.     OUT OPTIONAL void *pvStructInfo,
  2137.     IN OUT DWORD *pcbStructInfo
  2138.     );
  2139.  
  2140.  
  2141. WINCRYPT32API
  2142. BOOL
  2143. WINAPI
  2144. CryptDecodeObject(
  2145.     IN DWORD        dwCertEncodingType,
  2146.     IN LPCSTR       lpszStructType,
  2147.     IN const BYTE   *pbEncoded,
  2148.     IN DWORD        cbEncoded,
  2149.     IN DWORD        dwFlags,
  2150.     OUT void        *pvStructInfo,
  2151.     IN OUT DWORD    *pcbStructInfo
  2152.     );
  2153.  
  2154. // When the following flag is set the nocopy optimization is enabled.
  2155. // This optimization where appropriate, updates the pvStructInfo fields
  2156. // to point to content residing within pbEncoded instead of making a copy
  2157. // of and appending to pvStructInfo.
  2158. //
  2159. // Note, when set, pbEncoded can't be freed until pvStructInfo is freed.
  2160. #define CRYPT_DECODE_NOCOPY_FLAG            0x1
  2161.  
  2162. // For CryptDecodeObject(), by default the pbEncoded is the "to be signed"
  2163. // plus its signature. Set the following flag, if pbEncoded points to only
  2164. // the "to be signed".
  2165. //
  2166. // This flag is applicable to
  2167. //      X509_CERT_TO_BE_SIGNED
  2168. //      X509_CERT_CRL_TO_BE_SIGNED
  2169. //      X509_CERT_REQUEST_TO_BE_SIGNED
  2170. //      X509_KEYGEN_REQUEST_TO_BE_SIGNED
  2171. #define CRYPT_DECODE_TO_BE_SIGNED_FLAG      0x2
  2172.  
  2173. // When the following flag is set, the OID strings are allocated in
  2174. // crypt32.dll and shared instead of being copied into the returned
  2175. // data structure. This flag may be set if crypt32.dll isn't unloaded
  2176. // before the caller is unloaded.
  2177. #define CRYPT_DECODE_SHARE_OID_STRING_FLAG  0x4
  2178.  
  2179. // By default the signature bytes are reversed. The following flag can
  2180. // be set to inhibit the byte reversal.
  2181. //
  2182. // This flag is applicable to
  2183. //      X509_CERT_TO_BE_SIGNED
  2184. #define CRYPT_DECODE_NO_SIGNATURE_BYTE_REVERSAL_FLAG    0x8
  2185.  
  2186.  
  2187. // When the following flag is set the called decode function allocates
  2188. // memory for the decoded structure. A pointer to the allocated structure
  2189. // is returned in pvStructInfo. If pDecodePara or pDecodePara->pfnAlloc is
  2190. // NULL, then, LocalAlloc is called for the allocation and LocalFree must
  2191. // be called to do the free. Otherwise, pDecodePara->pfnAlloc is called
  2192. // for the allocation.
  2193. //
  2194. // *pcbStructInfo is ignored on input and updated with the length of the
  2195. // allocated, decoded structure.
  2196. //
  2197. // This flag may also be set in the CryptDecodeObject API. Since
  2198. // CryptDecodeObject doesn't take a pDecodePara, LocalAlloc is always
  2199. // called for the allocation which must be freed by calling LocalFree.
  2200. #define CRYPT_DECODE_ALLOC_FLAG             0x8000
  2201.  
  2202. // The following flag is applicable when decoding X509_UNICODE_NAME,
  2203. // X509_UNICODE_NAME_VALUE or X509_UNICODE_ANY_STRING.
  2204. // By default, CERT_RDN_T61_STRING values are initially decoded
  2205. // as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  2206. // Setting this flag skips the initial attempt to decode as UTF8.
  2207. #define CRYPT_UNICODE_NAME_DECODE_DISABLE_IE4_UTF8_FLAG     \
  2208.             CERT_RDN_DISABLE_IE4_UTF8_FLAG
  2209.  
  2210.  
  2211. //+-------------------------------------------------------------------------
  2212. //  Predefined X509 certificate data structures that can be encoded / decoded.
  2213. //--------------------------------------------------------------------------
  2214. #define CRYPT_ENCODE_DECODE_NONE            0
  2215. #define X509_CERT                           ((LPCSTR) 1)
  2216. #define X509_CERT_TO_BE_SIGNED              ((LPCSTR) 2)
  2217. #define X509_CERT_CRL_TO_BE_SIGNED          ((LPCSTR) 3)
  2218. #define X509_CERT_REQUEST_TO_BE_SIGNED      ((LPCSTR) 4)
  2219. #define X509_EXTENSIONS                     ((LPCSTR) 5)
  2220. #define X509_NAME_VALUE                     ((LPCSTR) 6)
  2221. #define X509_NAME                           ((LPCSTR) 7)
  2222. #define X509_PUBLIC_KEY_INFO                ((LPCSTR) 8)
  2223.  
  2224. //+-------------------------------------------------------------------------
  2225. //  Predefined X509 certificate extension data structures that can be
  2226. //  encoded / decoded.
  2227. //--------------------------------------------------------------------------
  2228. #define X509_AUTHORITY_KEY_ID               ((LPCSTR) 9)
  2229. #define X509_KEY_ATTRIBUTES                 ((LPCSTR) 10)
  2230. #define X509_KEY_USAGE_RESTRICTION          ((LPCSTR) 11)
  2231. #define X509_ALTERNATE_NAME                 ((LPCSTR) 12)
  2232. #define X509_BASIC_CONSTRAINTS              ((LPCSTR) 13)
  2233. #define X509_KEY_USAGE                      ((LPCSTR) 14)
  2234. #define X509_BASIC_CONSTRAINTS2             ((LPCSTR) 15)
  2235. #define X509_CERT_POLICIES                  ((LPCSTR) 16)
  2236.  
  2237. //+-------------------------------------------------------------------------
  2238. //  Additional predefined data structures that can be encoded / decoded.
  2239. //--------------------------------------------------------------------------
  2240. #define PKCS_UTC_TIME                       ((LPCSTR) 17)
  2241. #define PKCS_TIME_REQUEST                   ((LPCSTR) 18)
  2242. #define RSA_CSP_PUBLICKEYBLOB               ((LPCSTR) 19)
  2243. #define X509_UNICODE_NAME                   ((LPCSTR) 20)
  2244.  
  2245. #define X509_KEYGEN_REQUEST_TO_BE_SIGNED    ((LPCSTR) 21)
  2246. #define PKCS_ATTRIBUTE                      ((LPCSTR) 22)
  2247. #define PKCS_CONTENT_INFO_SEQUENCE_OF_ANY   ((LPCSTR) 23)
  2248.  
  2249. //+-------------------------------------------------------------------------
  2250. //  Predefined primitive data structures that can be encoded / decoded.
  2251. //--------------------------------------------------------------------------
  2252. #define X509_UNICODE_NAME_VALUE             ((LPCSTR) 24)
  2253. #define X509_ANY_STRING                     X509_NAME_VALUE
  2254. #define X509_UNICODE_ANY_STRING             X509_UNICODE_NAME_VALUE
  2255. #define X509_OCTET_STRING                   ((LPCSTR) 25)
  2256. #define X509_BITS                           ((LPCSTR) 26)
  2257. #define X509_INTEGER                        ((LPCSTR) 27)
  2258. #define X509_MULTI_BYTE_INTEGER             ((LPCSTR) 28)
  2259. #define X509_ENUMERATED                     ((LPCSTR) 29)
  2260. #define X509_CHOICE_OF_TIME                 ((LPCSTR) 30)
  2261.  
  2262. //+-------------------------------------------------------------------------
  2263. //  More predefined X509 certificate extension data structures that can be
  2264. //  encoded / decoded.
  2265. //--------------------------------------------------------------------------
  2266. #define X509_AUTHORITY_KEY_ID2              ((LPCSTR) 31)
  2267. #define X509_AUTHORITY_INFO_ACCESS          ((LPCSTR) 32)
  2268. #define X509_CRL_REASON_CODE                X509_ENUMERATED
  2269. #define PKCS_CONTENT_INFO                   ((LPCSTR) 33)
  2270. #define X509_SEQUENCE_OF_ANY                ((LPCSTR) 34)
  2271. #define X509_CRL_DIST_POINTS                ((LPCSTR) 35)
  2272. #define X509_ENHANCED_KEY_USAGE             ((LPCSTR) 36)
  2273. #define PKCS_CTL                            ((LPCSTR) 37)
  2274.  
  2275. #define X509_MULTI_BYTE_UINT                ((LPCSTR) 38)
  2276. #define X509_DSS_PUBLICKEY                  X509_MULTI_BYTE_UINT
  2277. #define X509_DSS_PARAMETERS                 ((LPCSTR) 39)
  2278. #define X509_DSS_SIGNATURE                  ((LPCSTR) 40)
  2279. #define PKCS_RC2_CBC_PARAMETERS             ((LPCSTR) 41)
  2280. #define PKCS_SMIME_CAPABILITIES             ((LPCSTR) 42)
  2281.  
  2282. //+-------------------------------------------------------------------------
  2283. //  data structures for private keys
  2284. //--------------------------------------------------------------------------
  2285. #define PKCS_RSA_PRIVATE_KEY                ((LPCSTR) 43)
  2286. #define PKCS_PRIVATE_KEY_INFO               ((LPCSTR) 44)
  2287. #define PKCS_ENCRYPTED_PRIVATE_KEY_INFO     ((LPCSTR) 45)
  2288.  
  2289. //+-------------------------------------------------------------------------
  2290. //  certificate policy qualifier
  2291. //--------------------------------------------------------------------------
  2292. #define X509_PKIX_POLICY_QUALIFIER_USERNOTICE ((LPCSTR) 46)
  2293.  
  2294. //+-------------------------------------------------------------------------
  2295. //  Diffie-Hellman Key Exchange
  2296. //--------------------------------------------------------------------------
  2297. #define X509_DH_PUBLICKEY                   X509_MULTI_BYTE_UINT
  2298. #define X509_DH_PARAMETERS                  ((LPCSTR) 47)
  2299. #define PKCS_ATTRIBUTES                     ((LPCSTR) 48)
  2300. #define PKCS_SORTED_CTL                     ((LPCSTR) 49)
  2301.  
  2302. //+-------------------------------------------------------------------------
  2303. //  X942 Diffie-Hellman
  2304. //--------------------------------------------------------------------------
  2305. #define X942_DH_PARAMETERS                  ((LPCSTR) 50)
  2306.  
  2307. //+-------------------------------------------------------------------------
  2308. //  The following is the same as X509_BITS, except before encoding,
  2309. //  the bit length is decremented to exclude trailing zero bits.
  2310. //--------------------------------------------------------------------------
  2311. #define X509_BITS_WITHOUT_TRAILING_ZEROES   ((LPCSTR) 51)
  2312.  
  2313. //+-------------------------------------------------------------------------
  2314. //  X942 Diffie-Hellman Other Info
  2315. //--------------------------------------------------------------------------
  2316. #define X942_OTHER_INFO                     ((LPCSTR) 52)
  2317.  
  2318. //+-------------------------------------------------------------------------
  2319. //  Predefined PKCS #7 data structures that can be encoded / decoded.
  2320. //--------------------------------------------------------------------------
  2321. #define PKCS7_SIGNER_INFO                   ((LPCSTR) 500)
  2322.  
  2323. //+-------------------------------------------------------------------------
  2324. //  Predefined PKCS #7 data structures that can be encoded / decoded.
  2325. //--------------------------------------------------------------------------
  2326. #define CMS_SIGNER_INFO                     ((LPCSTR) 501)
  2327.  
  2328. //+-------------------------------------------------------------------------
  2329. //  Predefined Software Publishing Credential (SPC)  data structures that
  2330. //  can be encoded / decoded.
  2331. //
  2332. //  Predefined values: 2000 .. 2999
  2333. //
  2334. //  See spc.h for value and data structure definitions.
  2335. //--------------------------------------------------------------------------
  2336.  
  2337. //+-------------------------------------------------------------------------
  2338. //  Extension Object Identifiers
  2339. //--------------------------------------------------------------------------
  2340. #define szOID_AUTHORITY_KEY_IDENTIFIER  "2.5.29.1"
  2341. #define szOID_KEY_ATTRIBUTES            "2.5.29.2"
  2342. #define szOID_CERT_POLICIES_95          "2.5.29.3"
  2343. #define szOID_KEY_USAGE_RESTRICTION     "2.5.29.4"
  2344. #define szOID_SUBJECT_ALT_NAME          "2.5.29.7"
  2345. #define szOID_ISSUER_ALT_NAME           "2.5.29.8"
  2346. #define szOID_BASIC_CONSTRAINTS         "2.5.29.10"
  2347. #define szOID_KEY_USAGE                 "2.5.29.15"
  2348. #define szOID_PRIVATEKEY_USAGE_PERIOD   "2.5.29.16"
  2349. #define szOID_BASIC_CONSTRAINTS2        "2.5.29.19"
  2350. #define szOID_CERT_POLICIES             "2.5.29.32"
  2351.  
  2352. #define szOID_AUTHORITY_KEY_IDENTIFIER2 "2.5.29.35"
  2353. #define szOID_SUBJECT_KEY_IDENTIFIER    "2.5.29.14"
  2354. #define szOID_SUBJECT_ALT_NAME2         "2.5.29.17"
  2355. #define szOID_ISSUER_ALT_NAME2          "2.5.29.18"
  2356. #define szOID_CRL_REASON_CODE           "2.5.29.21"
  2357. #define szOID_CRL_DIST_POINTS           "2.5.29.31"
  2358. #define szOID_ENHANCED_KEY_USAGE        "2.5.29.37"
  2359.  
  2360. // Microsoft PKCS10 Attributes
  2361. #define szOID_RENEWAL_CERTIFICATE        "1.3.6.1.4.1.311.13.1"
  2362. #define szOID_ENROLLMENT_NAME_VALUE_PAIR    "1.3.6.1.4.1.311.13.2.1"
  2363. #define szOID_ENROLLMENT_CSP_PROVIDER        "1.3.6.1.4.1.311.13.2.2"
  2364. #define szOID_OS_VERSION                "1.3.6.1.4.1.311.13.2.3"
  2365.  
  2366. //
  2367. // Extension contain certificate type
  2368. #define szOID_ENROLLMENT_AGENT            "1.3.6.1.4.1.311.20.2.1"
  2369.  
  2370. // Internet Public Key Infrastructure (PKIX)
  2371. #define szOID_PKIX                      "1.3.6.1.5.5.7"
  2372. #define szOID_PKIX_PE                   "1.3.6.1.5.5.7.1"
  2373. #define szOID_AUTHORITY_INFO_ACCESS     "1.3.6.1.5.5.7.1.1"
  2374.  
  2375. // Microsoft extensions or attributes
  2376. #define szOID_CERT_EXTENSIONS           "1.3.6.1.4.1.311.2.1.14"
  2377. #define szOID_NEXT_UPDATE_LOCATION      "1.3.6.1.4.1.311.10.2"
  2378.  
  2379. //  Microsoft PKCS #7 ContentType Object Identifiers
  2380. #define szOID_CTL                       "1.3.6.1.4.1.311.10.1"
  2381.  
  2382. //  Microsoft Sorted CTL Extension Object Identifier
  2383. #define szOID_SORTED_CTL                "1.3.6.1.4.1.311.10.1.1"
  2384.  
  2385. // serialized serial numbers for PRS
  2386. #ifndef szOID_SERIALIZED
  2387. #define szOID_SERIALIZED        "1.3.6.1.4.1.311.10.3.3.1"
  2388. #endif
  2389.  
  2390. // UPN principal name in SubjectAltName
  2391. #ifndef szOID_NT_PRINCIPAL_NAME
  2392. #define szOID_NT_PRINCIPAL_NAME     "1.3.6.1.4.1.311.20.2.3"
  2393. #endif
  2394.  
  2395. // Windows product update unauthenticated attribute
  2396. #ifndef szOID_PRODUCT_UPDATE
  2397. #define szOID_PRODUCT_UPDATE        "1.3.6.1.4.1.311.31.1"
  2398. #endif
  2399.  
  2400.  
  2401. //+-------------------------------------------------------------------------
  2402. //  Object Identifiers for use with Auto Enrollment
  2403. //--------------------------------------------------------------------------
  2404. #define szOID_AUTO_ENROLL_CTL_USAGE    "1.3.6.1.4.1.311.20.1"
  2405.  
  2406. // Extension contain certificate type
  2407. #define szOID_ENROLL_CERTTYPE_EXTENSION "1.3.6.1.4.1.311.20.2"
  2408.  
  2409.  
  2410. #define szOID_CERT_MANIFOLD             "1.3.6.1.4.1.311.20.3"
  2411.  
  2412. //+-------------------------------------------------------------------------
  2413. //  Object Identifiers for use with the MS Certificate Server
  2414. //--------------------------------------------------------------------------
  2415. #ifndef szOID_CERTSRV_CA_VERSION
  2416. #define szOID_CERTSRV_CA_VERSION    "1.3.6.1.4.1.311.21.1"
  2417. #endif
  2418.  
  2419. //+-------------------------------------------------------------------------
  2420. //  Object Identifiers for use with the MS Directory Service
  2421. //--------------------------------------------------------------------------
  2422. #define szOID_NTDS_REPLICATION        "1.3.6.1.4.1.311.25.1"
  2423.  
  2424.  
  2425. //+-------------------------------------------------------------------------
  2426. //  Extension Object Identifiers (currently not implemented)
  2427. //--------------------------------------------------------------------------
  2428. #define szOID_POLICY_MAPPINGS           "2.5.29.5"
  2429. #define szOID_SUBJECT_DIR_ATTRS         "2.5.29.9"
  2430.  
  2431. //+-------------------------------------------------------------------------
  2432. //  Enhanced Key Usage (Purpose) Object Identifiers
  2433. //--------------------------------------------------------------------------
  2434. #define szOID_PKIX_KP                   "1.3.6.1.5.5.7.3"
  2435.  
  2436. // Consistent key usage bits: DIGITAL_SIGNATURE, KEY_ENCIPHERMENT
  2437. // or KEY_AGREEMENT
  2438. #define szOID_PKIX_KP_SERVER_AUTH       "1.3.6.1.5.5.7.3.1"
  2439.  
  2440. // Consistent key usage bits: DIGITAL_SIGNATURE
  2441. #define szOID_PKIX_KP_CLIENT_AUTH       "1.3.6.1.5.5.7.3.2"
  2442.  
  2443. // Consistent key usage bits: DIGITAL_SIGNATURE
  2444. #define szOID_PKIX_KP_CODE_SIGNING      "1.3.6.1.5.5.7.3.3"
  2445.  
  2446. // Consistent key usage bits: DIGITAL_SIGNATURE, NON_REPUDIATION and/or
  2447. // (KEY_ENCIPHERMENT or KEY_AGREEMENT)
  2448. #define szOID_PKIX_KP_EMAIL_PROTECTION  "1.3.6.1.5.5.7.3.4"
  2449.  
  2450. // Consistent key usage bits: DIGITAL_SIGNATURE and/or
  2451. // (KEY_ENCIPHERMENT or KEY_AGREEMENT)
  2452. #define szOID_PKIX_KP_IPSEC_END_SYSTEM  "1.3.6.1.5.5.7.3.5"
  2453.  
  2454. // Consistent key usage bits: DIGITAL_SIGNATURE and/or
  2455. // (KEY_ENCIPHERMENT or KEY_AGREEMENT)
  2456. #define szOID_PKIX_KP_IPSEC_TUNNEL      "1.3.6.1.5.5.7.3.6"
  2457.  
  2458. // Consistent key usage bits: DIGITAL_SIGNATURE and/or
  2459. // (KEY_ENCIPHERMENT or KEY_AGREEMENT)
  2460. #define szOID_PKIX_KP_IPSEC_USER        "1.3.6.1.5.5.7.3.7"
  2461.  
  2462. // Consistent key usage bits: DIGITAL_SIGNATURE or NON_REPUDIATION
  2463. #define szOID_PKIX_KP_TIMESTAMP_SIGNING "1.3.6.1.5.5.7.3.8"
  2464.  
  2465. //+-------------------------------------------------------------------------
  2466. //  Microsoft Enhanced Key Usage (Purpose) Object Identifiers
  2467. //+-------------------------------------------------------------------------
  2468.  
  2469. //  Signer of CTLs
  2470. #define szOID_KP_CTL_USAGE_SIGNING      "1.3.6.1.4.1.311.10.3.1"
  2471.  
  2472. //  Signer of TimeStamps
  2473. #define szOID_KP_TIME_STAMP_SIGNING     "1.3.6.1.4.1.311.10.3.2"
  2474.  
  2475. #ifndef szOID_SERVER_GATED_CRYPTO
  2476. #define szOID_SERVER_GATED_CRYPTO       "1.3.6.1.4.1.311.10.3.3"
  2477. #endif
  2478.  
  2479. #ifndef szOID_SGC_NETSCAPE
  2480. #define szOID_SGC_NETSCAPE              "2.16.840.1.113730.4.1"
  2481. #endif
  2482.  
  2483. #define szOID_KP_EFS            "1.3.6.1.4.1.311.10.3.4"
  2484.  
  2485. // Can use Windows Hardware Compatible (WHQL)
  2486. #define szOID_WHQL_CRYPTO        "1.3.6.1.4.1.311.10.3.5"
  2487.  
  2488. // Signed by the NT5 build lab
  2489. #define szOID_NT5_CRYPTO        "1.3.6.1.4.1.311.10.3.6"
  2490.  
  2491. // Signed by and OEM of WHQL
  2492. #define szOID_OEM_WHQL_CRYPTO        "1.3.6.1.4.1.311.10.3.7"
  2493.  
  2494. // Signed by the Embedded NT
  2495. #define szOID_EMBEDDED_NT_CRYPTO    "1.3.6.1.4.1.311.10.3.8"
  2496.  
  2497. #ifndef szOID_DRM
  2498. #define szOID_DRM            "1.3.6.1.4.1.311.10.5.1"
  2499. #endif
  2500.  
  2501. #ifndef szOID_LICENSES
  2502. #define szOID_LICENSES            "1.3.6.1.4.1.311.10.6.1"
  2503. #endif
  2504.  
  2505. #ifndef szOID_LICENSE_SERVER
  2506. #define szOID_LICENSE_SERVER        "1.3.6.1.4.1.311.10.6.2"
  2507. #endif
  2508.  
  2509. #ifndef szOID_KP_SMARTCARD_LOGON
  2510. #define szOID_KP_SMARTCARD_LOGON    "1.3.6.1.4.1.311.20.2.2"
  2511. #endif
  2512.  
  2513. //+-------------------------------------------------------------------------
  2514. //  Microsoft Attribute Object Identifiers
  2515. //+-------------------------------------------------------------------------
  2516. #define szOID_YESNO_TRUST_ATTR          "1.3.6.1.4.1.311.10.4.1"
  2517.  
  2518. //+-------------------------------------------------------------------------
  2519. //  Qualifiers that may be part of the szOID_CERT_POLICIES and
  2520. //  szOID_CERT_POLICIES95 extensions
  2521. //+-------------------------------------------------------------------------
  2522. #define szOID_PKIX_POLICY_QUALIFIER_CPS               "1.3.6.1.5.5.7.2.1"
  2523. #define szOID_PKIX_POLICY_QUALIFIER_USERNOTICE        "1.3.6.1.5.5.7.2.2"
  2524.  
  2525. // OID for old qualifer
  2526. #define szOID_CERT_POLICIES_95_QUALIFIER1             "2.16.840.1.113733.1.7.1.1"
  2527.  
  2528. //+-------------------------------------------------------------------------
  2529. //  X509_CERT
  2530. //
  2531. //  The "to be signed" encoded content plus its signature. The ToBeSigned
  2532. //  content is the CryptEncodeObject() output for one of the following:
  2533. //  X509_CERT_TO_BE_SIGNED, X509_CERT_CRL_TO_BE_SIGNED or
  2534. //  X509_CERT_REQUEST_TO_BE_SIGNED.
  2535. //
  2536. //  pvStructInfo points to CERT_SIGNED_CONTENT_INFO.
  2537. //--------------------------------------------------------------------------
  2538.  
  2539. //+-------------------------------------------------------------------------
  2540. //  X509_CERT_TO_BE_SIGNED
  2541. //
  2542. //  pvStructInfo points to CERT_INFO.
  2543. //
  2544. //  For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  2545. //  signature (output of a X509_CERT CryptEncodeObject()).
  2546. //
  2547. //  For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  2548. //--------------------------------------------------------------------------
  2549.  
  2550. //+-------------------------------------------------------------------------
  2551. //  X509_CERT_CRL_TO_BE_SIGNED
  2552. //
  2553. //  pvStructInfo points to CRL_INFO.
  2554. //
  2555. //  For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  2556. //  signature (output of a X509_CERT CryptEncodeObject()).
  2557. //
  2558. //  For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  2559. //--------------------------------------------------------------------------
  2560.  
  2561. //+-------------------------------------------------------------------------
  2562. //  X509_CERT_REQUEST_TO_BE_SIGNED
  2563. //
  2564. //  pvStructInfo points to CERT_REQUEST_INFO.
  2565. //
  2566. //  For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  2567. //  signature (output of a X509_CERT CryptEncodeObject()).
  2568. //
  2569. //  For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  2570. //--------------------------------------------------------------------------
  2571.  
  2572. //+-------------------------------------------------------------------------
  2573. //  X509_EXTENSIONS
  2574. //  szOID_CERT_EXTENSIONS
  2575. //
  2576. //  pvStructInfo points to following CERT_EXTENSIONS.
  2577. //--------------------------------------------------------------------------
  2578. typedef struct _CERT_EXTENSIONS {
  2579.     DWORD           cExtension;
  2580.     PCERT_EXTENSION rgExtension;
  2581. } CERT_EXTENSIONS, *PCERT_EXTENSIONS;
  2582.  
  2583. //+-------------------------------------------------------------------------
  2584. //  X509_NAME_VALUE
  2585. //  X509_ANY_STRING
  2586. //
  2587. //  pvStructInfo points to CERT_NAME_VALUE.
  2588. //--------------------------------------------------------------------------
  2589.  
  2590. //+-------------------------------------------------------------------------
  2591. //  X509_UNICODE_NAME_VALUE
  2592. //  X509_UNICODE_ANY_STRING
  2593. //
  2594. //  pvStructInfo points to CERT_NAME_VALUE.
  2595. //
  2596. //  The name values are unicode strings.
  2597. //
  2598. //  For CryptEncodeObject:
  2599. //    Value.pbData points to the unicode string.
  2600. //    If Value.cbData = 0, then, the unicode string is NULL terminated.
  2601. //    Otherwise, Value.cbData is the unicode string byte count. The byte count
  2602. //    is twice the character count.
  2603. //
  2604. //    If the unicode string contains an invalid character for the specified
  2605. //    dwValueType, then, *pcbEncoded is updated with the unicode character
  2606. //    index of the first invalid character. LastError is set to:
  2607. //    CRYPT_E_INVALID_NUMERIC_STRING, CRYPT_E_INVALID_PRINTABLE_STRING or
  2608. //    CRYPT_E_INVALID_IA5_STRING.
  2609. //
  2610. //    To disable the above check, either set CERT_RDN_DISABLE_CHECK_TYPE_FLAG
  2611. //    in dwValueType or set CRYPT_UNICODE_NAME_ENCODE_DISABLE_CHECK_TYPE_FLAG
  2612. //    in dwFlags passed to CryptEncodeObjectEx.
  2613. //
  2614. //    The unicode string is converted before being encoded according to
  2615. //    the specified dwValueType. If dwValueType is set to 0, LastError
  2616. //    is set to E_INVALIDARG.
  2617. //
  2618. //    If the dwValueType isn't one of the character strings (its a
  2619. //    CERT_RDN_ENCODED_BLOB or CERT_RDN_OCTET_STRING), then, CryptEncodeObject
  2620. //    will return FALSE with LastError set to CRYPT_E_NOT_CHAR_STRING.
  2621. //
  2622. //  For CryptDecodeObject:
  2623. //    Value.pbData points to a NULL terminated unicode string. Value.cbData
  2624. //    contains the byte count of the unicode string excluding the NULL
  2625. //    terminator. dwValueType contains the type used in the encoded object.
  2626. //    Its not forced to CERT_RDN_UNICODE_STRING. The encoded value is
  2627. //    converted to the unicode string according to the dwValueType.
  2628. //
  2629. //    If the encoded object isn't one of the character string types, then,
  2630. //    CryptDecodeObject will return FALSE with LastError set to
  2631. //    CRYPT_E_NOT_CHAR_STRING. For a non character string, decode using
  2632. //    X509_NAME_VALUE or X509_ANY_STRING.
  2633. //
  2634. //    By default, CERT_RDN_T61_STRING values are initially decoded
  2635. //    as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  2636. //    Set CRYPT_UNICODE_NAME_DECODE_DISABLE_IE4_UTF8_FLAG in dwFlags
  2637. //    passed to either CryptDecodeObject or CryptDecodeObjectEx to
  2638. //    skip the initial attempt to decode as UTF8.
  2639. //--------------------------------------------------------------------------
  2640.  
  2641. //+-------------------------------------------------------------------------
  2642. //  X509_NAME
  2643. //
  2644. //  pvStructInfo points to CERT_NAME_INFO.
  2645. //--------------------------------------------------------------------------
  2646.  
  2647. //+-------------------------------------------------------------------------
  2648. //  X509_UNICODE_NAME
  2649. //
  2650. //  pvStructInfo points to CERT_NAME_INFO.
  2651. //
  2652. //  The RDN attribute values are unicode strings except for the dwValueTypes of
  2653. //  CERT_RDN_ENCODED_BLOB or CERT_RDN_OCTET_STRING. These dwValueTypes are
  2654. //  the same as for a X509_NAME. Their values aren't converted to/from unicode.
  2655. //
  2656. //  For CryptEncodeObject:
  2657. //    Value.pbData points to the unicode string.
  2658. //    If Value.cbData = 0, then, the unicode string is NULL terminated.
  2659. //    Otherwise, Value.cbData is the unicode string byte count. The byte count
  2660. //    is twice the character count.
  2661. //
  2662. //    If dwValueType = 0 (CERT_RDN_ANY_TYPE), the pszObjId is used to find
  2663. //    an acceptable dwValueType. If the unicode string contains an
  2664. //    invalid character for the found or specified dwValueType, then,
  2665. //    *pcbEncoded is updated with the error location of the invalid character.
  2666. //    See below for details. LastError is set to:
  2667. //    CRYPT_E_INVALID_NUMERIC_STRING, CRYPT_E_INVALID_PRINTABLE_STRING or
  2668. //    CRYPT_E_INVALID_IA5_STRING.
  2669. //
  2670. //    To disable the above check, either set CERT_RDN_DISABLE_CHECK_TYPE_FLAG
  2671. //    in dwValueType or set CRYPT_UNICODE_NAME_ENCODE_DISABLE_CHECK_TYPE_FLAG
  2672. //    in dwFlags passed to CryptEncodeObjectEx.
  2673. //
  2674. //    Set CERT_RDN_UNICODE_STRING in dwValueType or set
  2675. //    CRYPT_UNICODE_NAME_ENCODE_ENABLE_T61_UNICODE_FLAG in dwFlags passed
  2676. //    to CryptEncodeObjectEx to select CERT_RDN_T61_STRING instead of
  2677. //    CERT_RDN_UNICODE_STRING if all the unicode characters are <= 0xFF.
  2678. //
  2679. //    Set CERT_RDN_ENABLE_UTF8_UNICODE_STRING in dwValueType or set
  2680. //    CRYPT_UNICODE_NAME_ENCODE_ENABLE_UTF8_UNICODE_FLAG in dwFlags passed
  2681. //    to CryptEncodeObjectEx to select CERT_RDN_UTF8_STRING instead of
  2682. //    CERT_RDN_UNICODE_STRING.
  2683. //
  2684. //    The unicode string is converted before being encoded according to
  2685. //    the specified or ObjId matching dwValueType.
  2686. //
  2687. //  For CryptDecodeObject:
  2688. //    Value.pbData points to a NULL terminated unicode string. Value.cbData
  2689. //    contains the byte count of the unicode string excluding the NULL
  2690. //    terminator. dwValueType contains the type used in the encoded object.
  2691. //    Its not forced to CERT_RDN_UNICODE_STRING. The encoded value is
  2692. //    converted to the unicode string according to the dwValueType.
  2693. //
  2694. //    If the dwValueType of the encoded value isn't a character string
  2695. //    type, then, it isn't converted to UNICODE. Use the
  2696. //    IS_CERT_RDN_CHAR_STRING() macro on the dwValueType to check
  2697. //    that Value.pbData points to a converted unicode string.
  2698. //
  2699. //    By default, CERT_RDN_T61_STRING values are initially decoded
  2700. //    as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  2701. //    Set CRYPT_UNICODE_NAME_DECODE_DISABLE_IE4_UTF8_FLAG in dwFlags
  2702. //    passed to either CryptDecodeObject or CryptDecodeObjectEx to
  2703. //    skip the initial attempt to decode as UTF8.
  2704. //--------------------------------------------------------------------------
  2705.  
  2706. //+-------------------------------------------------------------------------
  2707. //  Unicode Name Value Error Location Definitions
  2708. //
  2709. //  Error location is returned in *pcbEncoded by
  2710. //  CryptEncodeObject(X509_UNICODE_NAME)
  2711. //
  2712. //  Error location consists of:
  2713. //    RDN_INDEX     - 10 bits << 22
  2714. //    ATTR_INDEX    - 6 bits << 16
  2715. //    VALUE_INDEX   - 16 bits (unicode character index)
  2716. //--------------------------------------------------------------------------
  2717. #define CERT_UNICODE_RDN_ERR_INDEX_MASK     0x3FF
  2718. #define CERT_UNICODE_RDN_ERR_INDEX_SHIFT    22
  2719. #define CERT_UNICODE_ATTR_ERR_INDEX_MASK    0x003F
  2720. #define CERT_UNICODE_ATTR_ERR_INDEX_SHIFT   16
  2721. #define CERT_UNICODE_VALUE_ERR_INDEX_MASK   0x0000FFFF
  2722. #define CERT_UNICODE_VALUE_ERR_INDEX_SHIFT  0
  2723.  
  2724. #define GET_CERT_UNICODE_RDN_ERR_INDEX(X)   \
  2725.     ((X >> CERT_UNICODE_RDN_ERR_INDEX_SHIFT) & CERT_UNICODE_RDN_ERR_INDEX_MASK)
  2726. #define GET_CERT_UNICODE_ATTR_ERR_INDEX(X)  \
  2727.     ((X >> CERT_UNICODE_ATTR_ERR_INDEX_SHIFT) & CERT_UNICODE_ATTR_ERR_INDEX_MASK)
  2728. #define GET_CERT_UNICODE_VALUE_ERR_INDEX(X) \
  2729.     (X & CERT_UNICODE_VALUE_ERR_INDEX_MASK)
  2730.  
  2731. //+-------------------------------------------------------------------------
  2732. //  X509_PUBLIC_KEY_INFO
  2733. //
  2734. //  pvStructInfo points to CERT_PUBLIC_KEY_INFO.
  2735. //--------------------------------------------------------------------------
  2736.  
  2737.  
  2738. //+-------------------------------------------------------------------------
  2739. //  X509_AUTHORITY_KEY_ID
  2740. //  szOID_AUTHORITY_KEY_IDENTIFIER
  2741. //
  2742. //  pvStructInfo points to following CERT_AUTHORITY_KEY_ID_INFO.
  2743. //--------------------------------------------------------------------------
  2744. typedef struct _CERT_AUTHORITY_KEY_ID_INFO {
  2745.     CRYPT_DATA_BLOB     KeyId;
  2746.     CERT_NAME_BLOB      CertIssuer;
  2747.     CRYPT_INTEGER_BLOB  CertSerialNumber;
  2748. } CERT_AUTHORITY_KEY_ID_INFO, *PCERT_AUTHORITY_KEY_ID_INFO;
  2749.  
  2750. //+-------------------------------------------------------------------------
  2751. //  X509_KEY_ATTRIBUTES
  2752. //  szOID_KEY_ATTRIBUTES
  2753. //
  2754. //  pvStructInfo points to following CERT_KEY_ATTRIBUTES_INFO.
  2755. //--------------------------------------------------------------------------
  2756. typedef struct _CERT_PRIVATE_KEY_VALIDITY {
  2757.     FILETIME            NotBefore;
  2758.     FILETIME            NotAfter;
  2759. } CERT_PRIVATE_KEY_VALIDITY, *PCERT_PRIVATE_KEY_VALIDITY;
  2760.  
  2761. typedef struct _CERT_KEY_ATTRIBUTES_INFO {
  2762.     CRYPT_DATA_BLOB             KeyId;
  2763.     CRYPT_BIT_BLOB              IntendedKeyUsage;
  2764.     PCERT_PRIVATE_KEY_VALIDITY  pPrivateKeyUsagePeriod;     // OPTIONAL
  2765. } CERT_KEY_ATTRIBUTES_INFO, *PCERT_KEY_ATTRIBUTES_INFO;
  2766.  
  2767. // Byte[0]
  2768. #define CERT_DIGITAL_SIGNATURE_KEY_USAGE     0x80
  2769. #define CERT_NON_REPUDIATION_KEY_USAGE       0x40
  2770. #define CERT_KEY_ENCIPHERMENT_KEY_USAGE      0x20
  2771. #define CERT_DATA_ENCIPHERMENT_KEY_USAGE     0x10
  2772. #define CERT_KEY_AGREEMENT_KEY_USAGE         0x08
  2773. #define CERT_KEY_CERT_SIGN_KEY_USAGE         0x04
  2774. #define CERT_OFFLINE_CRL_SIGN_KEY_USAGE      0x02
  2775. #define CERT_CRL_SIGN_KEY_USAGE              0x02
  2776. #define CERT_ENCIPHER_ONLY_KEY_USAGE         0x01
  2777. // Byte[1]
  2778. #define CERT_DECIPHER_ONLY_KEY_USAGE         0x80
  2779.  
  2780. //+-------------------------------------------------------------------------
  2781. //  X509_KEY_USAGE_RESTRICTION
  2782. //  szOID_KEY_USAGE_RESTRICTION
  2783. //
  2784. //  pvStructInfo points to following CERT_KEY_USAGE_RESTRICTION_INFO.
  2785. //--------------------------------------------------------------------------
  2786. typedef struct _CERT_POLICY_ID {
  2787.     DWORD                   cCertPolicyElementId;
  2788.     LPSTR                   *rgpszCertPolicyElementId;  // pszObjId
  2789. } CERT_POLICY_ID, *PCERT_POLICY_ID;
  2790.  
  2791. typedef struct _CERT_KEY_USAGE_RESTRICTION_INFO {
  2792.     DWORD                   cCertPolicyId;
  2793.     PCERT_POLICY_ID         rgCertPolicyId;
  2794.     CRYPT_BIT_BLOB          RestrictedKeyUsage;
  2795. } CERT_KEY_USAGE_RESTRICTION_INFO, *PCERT_KEY_USAGE_RESTRICTION_INFO;
  2796.  
  2797. // See CERT_KEY_ATTRIBUTES_INFO for definition of the RestrictedKeyUsage bits
  2798.  
  2799. //+-------------------------------------------------------------------------
  2800. //  X509_ALTERNATE_NAME
  2801. //  szOID_SUBJECT_ALT_NAME
  2802. //  szOID_ISSUER_ALT_NAME
  2803. //  szOID_SUBJECT_ALT_NAME2
  2804. //  szOID_ISSUER_ALT_NAME2
  2805. //
  2806. //  pvStructInfo points to following CERT_ALT_NAME_INFO.
  2807. //--------------------------------------------------------------------------
  2808.  
  2809. typedef struct _CERT_OTHER_NAME {
  2810.     LPSTR               pszObjId;
  2811.     CRYPT_OBJID_BLOB    Value;
  2812. } CERT_OTHER_NAME, *PCERT_OTHER_NAME;
  2813.  
  2814. typedef struct _CERT_ALT_NAME_ENTRY {
  2815.     DWORD   dwAltNameChoice;
  2816.     union {
  2817.         PCERT_OTHER_NAME            pOtherName;         // 1
  2818.         LPWSTR                      pwszRfc822Name;     // 2  (encoded IA5)
  2819.         LPWSTR                      pwszDNSName;        // 3  (encoded IA5)
  2820.         // Not implemented          x400Address;        // 4
  2821.         CERT_NAME_BLOB              DirectoryName;      // 5
  2822.         // Not implemented          pEdiPartyName;      // 6
  2823.         LPWSTR                      pwszURL;            // 7  (encoded IA5)
  2824.         CRYPT_DATA_BLOB             IPAddress;          // 8  (Octet String)
  2825.         LPSTR                       pszRegisteredID;    // 9  (Object Identifer)
  2826.     };
  2827. } CERT_ALT_NAME_ENTRY, *PCERT_ALT_NAME_ENTRY;
  2828.  
  2829. #define CERT_ALT_NAME_OTHER_NAME         1
  2830. #define CERT_ALT_NAME_RFC822_NAME        2
  2831. #define CERT_ALT_NAME_DNS_NAME           3
  2832. #define CERT_ALT_NAME_X400_ADDRESS       4
  2833. #define CERT_ALT_NAME_DIRECTORY_NAME     5
  2834. #define CERT_ALT_NAME_EDI_PARTY_NAME     6
  2835. #define CERT_ALT_NAME_URL                7
  2836. #define CERT_ALT_NAME_IP_ADDRESS         8
  2837. #define CERT_ALT_NAME_REGISTERED_ID      9
  2838.  
  2839.  
  2840. typedef struct _CERT_ALT_NAME_INFO {
  2841.     DWORD                   cAltEntry;
  2842.     PCERT_ALT_NAME_ENTRY    rgAltEntry;
  2843. } CERT_ALT_NAME_INFO, *PCERT_ALT_NAME_INFO;
  2844.  
  2845. //+-------------------------------------------------------------------------
  2846. //  Alternate name IA5 Error Location Definitions for
  2847. //  CRYPT_E_INVALID_IA5_STRING.
  2848. //
  2849. //  Error location is returned in *pcbEncoded by
  2850. //  CryptEncodeObject(X509_ALTERNATE_NAME)
  2851. //
  2852. //  Error location consists of:
  2853. //    ENTRY_INDEX   - 8 bits << 16
  2854. //    VALUE_INDEX   - 16 bits (unicode character index)
  2855. //--------------------------------------------------------------------------
  2856. #define CERT_ALT_NAME_ENTRY_ERR_INDEX_MASK  0xFF
  2857. #define CERT_ALT_NAME_ENTRY_ERR_INDEX_SHIFT 16
  2858. #define CERT_ALT_NAME_VALUE_ERR_INDEX_MASK  0x0000FFFF
  2859. #define CERT_ALT_NAME_VALUE_ERR_INDEX_SHIFT 0
  2860.  
  2861. #define GET_CERT_ALT_NAME_ENTRY_ERR_INDEX(X)   \
  2862.     ((X >> CERT_ALT_NAME_ENTRY_ERR_INDEX_SHIFT) & \
  2863.     CERT_ALT_NAME_ENTRY_ERR_INDEX_MASK)
  2864. #define GET_CERT_ALT_NAME_VALUE_ERR_INDEX(X) \
  2865.     (X & CERT_ALT_NAME_VALUE_ERR_INDEX_MASK)
  2866.  
  2867.  
  2868. //+-------------------------------------------------------------------------
  2869. //  X509_BASIC_CONSTRAINTS
  2870. //  szOID_BASIC_CONSTRAINTS
  2871. //
  2872. //  pvStructInfo points to following CERT_BASIC_CONSTRAINTS_INFO.
  2873. //--------------------------------------------------------------------------
  2874. typedef struct _CERT_BASIC_CONSTRAINTS_INFO {
  2875.     CRYPT_BIT_BLOB          SubjectType;
  2876.     BOOL                    fPathLenConstraint;
  2877.     DWORD                   dwPathLenConstraint;
  2878.     DWORD                   cSubtreesConstraint;
  2879.     CERT_NAME_BLOB          *rgSubtreesConstraint;
  2880. } CERT_BASIC_CONSTRAINTS_INFO, *PCERT_BASIC_CONSTRAINTS_INFO;
  2881.  
  2882. #define CERT_CA_SUBJECT_FLAG         0x80
  2883. #define CERT_END_ENTITY_SUBJECT_FLAG 0x40
  2884.  
  2885. //+-------------------------------------------------------------------------
  2886. //  X509_BASIC_CONSTRAINTS2
  2887. //  szOID_BASIC_CONSTRAINTS2
  2888. //
  2889. //  pvStructInfo points to following CERT_BASIC_CONSTRAINTS2_INFO.
  2890. //--------------------------------------------------------------------------
  2891. typedef struct _CERT_BASIC_CONSTRAINTS2_INFO {
  2892.     BOOL                    fCA;
  2893.     BOOL                    fPathLenConstraint;
  2894.     DWORD                   dwPathLenConstraint;
  2895. } CERT_BASIC_CONSTRAINTS2_INFO, *PCERT_BASIC_CONSTRAINTS2_INFO;
  2896.  
  2897. //+-------------------------------------------------------------------------
  2898. //  X509_KEY_USAGE
  2899. //  szOID_KEY_USAGE
  2900. //
  2901. //  pvStructInfo points to a CRYPT_BIT_BLOB. Has same bit definitions as
  2902. //  CERT_KEY_ATTRIBUTES_INFO's IntendedKeyUsage.
  2903. //--------------------------------------------------------------------------
  2904.  
  2905. //+-------------------------------------------------------------------------
  2906. //  X509_CERT_POLICIES
  2907. //  szOID_CERT_POLICIES
  2908. //  szOID_CERT_POLICIES_95   NOTE--Only allowed for decoding!!!
  2909. //
  2910. //  pvStructInfo points to following CERT_POLICIES_INFO.
  2911. //
  2912. //  NOTE: when decoding using szOID_CERT_POLICIES_95 the pszPolicyIdentifier
  2913. //        may contain an empty string
  2914. //--------------------------------------------------------------------------
  2915. typedef struct _CERT_POLICY_QUALIFIER_INFO {
  2916.     LPSTR                       pszPolicyQualifierId;   // pszObjId
  2917.     CRYPT_OBJID_BLOB            Qualifier;              // optional
  2918. } CERT_POLICY_QUALIFIER_INFO, *PCERT_POLICY_QUALIFIER_INFO;
  2919.  
  2920. typedef struct _CERT_POLICY_INFO {
  2921.     LPSTR                       pszPolicyIdentifier;    // pszObjId
  2922.     DWORD                       cPolicyQualifier;       // optional
  2923.     CERT_POLICY_QUALIFIER_INFO  *rgPolicyQualifier;
  2924. } CERT_POLICY_INFO, *PCERT_POLICY_INFO;
  2925.  
  2926. typedef struct _CERT_POLICIES_INFO {
  2927.     DWORD                       cPolicyInfo;
  2928.     CERT_POLICY_INFO            *rgPolicyInfo;
  2929. } CERT_POLICIES_INFO, *PCERT_POLICIES_INFO;
  2930.  
  2931. //+-------------------------------------------------------------------------
  2932. //  X509_PKIX_POLICY_QUALIFIER_USERNOTICE
  2933. //  szOID_PKIX_POLICY_QUALIFIER_USERNOTICE
  2934. //
  2935. //  pvStructInfo points to following CERT_POLICY_QUALIFIER_USER_NOTICE.
  2936. //
  2937. //--------------------------------------------------------------------------
  2938. typedef struct _CERT_POLICY_QUALIFIER_NOTICE_REFERENCE {
  2939.     LPSTR   pszOrganization;
  2940.     DWORD   cNoticeNumbers;
  2941.     int     *rgNoticeNumbers;
  2942. } CERT_POLICY_QUALIFIER_NOTICE_REFERENCE, *PCERT_POLICY_QUALIFIER_NOTICE_REFERENCE;
  2943.  
  2944. typedef struct _CERT_POLICY_QUALIFIER_USER_NOTICE {
  2945.     CERT_POLICY_QUALIFIER_NOTICE_REFERENCE  *pNoticeReference;  // optional
  2946.     LPWSTR                                  pszDisplayText;     // optional
  2947. } CERT_POLICY_QUALIFIER_USER_NOTICE, *PCERT_POLICY_QUALIFIER_USER_NOTICE;
  2948.  
  2949. //+-------------------------------------------------------------------------
  2950. //  szOID_CERT_POLICIES_95_QUALIFIER1 - Decode Only!!!!
  2951. //
  2952. //  pvStructInfo points to following CERT_POLICY95_QUALIFIER1.
  2953. //
  2954. //--------------------------------------------------------------------------
  2955. typedef struct _CPS_URLS {
  2956.     LPWSTR                      pszURL;
  2957.     CRYPT_ALGORITHM_IDENTIFIER  *pAlgorithm; // optional
  2958.     CRYPT_DATA_BLOB             *pDigest;    // optional
  2959. } CPS_URLS, *PCPS_URLS;
  2960.  
  2961. typedef struct _CERT_POLICY95_QUALIFIER1 {
  2962.     LPWSTR      pszPracticesReference;      // optional
  2963.     LPSTR       pszNoticeIdentifier;        // optional
  2964.     LPSTR       pszNSINoticeIdentifier;     // optional
  2965.     DWORD       cCPSURLs;
  2966.     CPS_URLS    *rgCPSURLs;                 // optional
  2967. } CERT_POLICY95_QUALIFIER1, *PCERT_POLICY95_QUALIFIER1;
  2968.  
  2969. //+-------------------------------------------------------------------------
  2970. //  RSA_CSP_PUBLICKEYBLOB
  2971. //
  2972. //  pvStructInfo points to a PUBLICKEYSTRUC immediately followed by a
  2973. //  RSAPUBKEY and the modulus bytes.
  2974. //
  2975. //  CryptExportKey outputs the above StructInfo for a dwBlobType of
  2976. //  PUBLICKEYBLOB. CryptImportKey expects the above StructInfo when
  2977. //  importing a public key.
  2978. //
  2979. //  For dwCertEncodingType = X509_ASN_ENCODING, the RSA_CSP_PUBLICKEYBLOB is
  2980. //  encoded as a PKCS #1 RSAPublicKey consisting of a SEQUENCE of a
  2981. //  modulus INTEGER and a publicExponent INTEGER. The modulus is encoded
  2982. //  as being a unsigned integer. When decoded, if the modulus was encoded
  2983. //  as unsigned integer with a leading 0 byte, the 0 byte is removed before
  2984. //  converting to the CSP modulus bytes.
  2985. //
  2986. //  For decode, the aiKeyAlg field of PUBLICKEYSTRUC is always set to
  2987. //  CALG_RSA_KEYX.
  2988. //--------------------------------------------------------------------------
  2989.  
  2990. //+-------------------------------------------------------------------------
  2991. //  X509_KEYGEN_REQUEST_TO_BE_SIGNED
  2992. //
  2993. //  pvStructInfo points to CERT_KEYGEN_REQUEST_INFO.
  2994. //
  2995. //  For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  2996. //  signature (output of a X509_CERT CryptEncodeObject()).
  2997. //
  2998. //  For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  2999. //--------------------------------------------------------------------------
  3000.  
  3001. //+-------------------------------------------------------------------------
  3002. //  PKCS_ATTRIBUTE data structure
  3003. //
  3004. //  pvStructInfo points to a CRYPT_ATTRIBUTE.
  3005. //--------------------------------------------------------------------------
  3006.  
  3007. //+-------------------------------------------------------------------------
  3008. //  PKCS_ATTRIBUTES data structure
  3009. //
  3010. //  pvStructInfo points to a CRYPT_ATTRIBUTES.
  3011. //--------------------------------------------------------------------------
  3012.  
  3013. //+-------------------------------------------------------------------------
  3014. //  PKCS_CONTENT_INFO_SEQUENCE_OF_ANY data structure
  3015. //
  3016. //  pvStructInfo points to following CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY.
  3017. //
  3018. //  For X509_ASN_ENCODING: encoded as a PKCS#7 ContentInfo structure wrapping
  3019. //  a sequence of ANY. The value of the contentType field is pszObjId,
  3020. //  while the content field is the following structure:
  3021. //      SequenceOfAny ::= SEQUENCE OF ANY
  3022. //
  3023. //  The CRYPT_DER_BLOBs point to the already encoded ANY content.
  3024. //--------------------------------------------------------------------------
  3025. typedef struct _CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY {
  3026.     LPSTR               pszObjId;
  3027.     DWORD               cValue;
  3028.     PCRYPT_DER_BLOB     rgValue;
  3029. } CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY, *PCRYPT_CONTENT_INFO_SEQUENCE_OF_ANY;
  3030.  
  3031. //+-------------------------------------------------------------------------
  3032. //  PKCS_CONTENT_INFO data structure
  3033. //
  3034. //  pvStructInfo points to following CRYPT_CONTENT_INFO.
  3035. //
  3036. //  For X509_ASN_ENCODING: encoded as a PKCS#7 ContentInfo structure.
  3037. //  The CRYPT_DER_BLOB points to the already encoded ANY content.
  3038. //--------------------------------------------------------------------------
  3039. typedef struct _CRYPT_CONTENT_INFO {
  3040.     LPSTR               pszObjId;
  3041.     CRYPT_DER_BLOB      Content;
  3042. } CRYPT_CONTENT_INFO, *PCRYPT_CONTENT_INFO;
  3043.  
  3044.  
  3045. //+-------------------------------------------------------------------------
  3046. //  X509_OCTET_STRING data structure
  3047. //
  3048. //  pvStructInfo points to a CRYPT_DATA_BLOB.
  3049. //--------------------------------------------------------------------------
  3050.  
  3051. //+-------------------------------------------------------------------------
  3052. //  X509_BITS data structure
  3053. //
  3054. //  pvStructInfo points to a CRYPT_BIT_BLOB.
  3055. //--------------------------------------------------------------------------
  3056.  
  3057. //+-------------------------------------------------------------------------
  3058. //  X509_BITS_WITHOUT_TRAILING_ZEROES data structure
  3059. //
  3060. //  pvStructInfo points to a CRYPT_BIT_BLOB.
  3061. //
  3062. //  The same as X509_BITS, except before encoding, the bit length is
  3063. //  decremented to exclude trailing zero bits.
  3064. //--------------------------------------------------------------------------
  3065.  
  3066. //+-------------------------------------------------------------------------
  3067. //  X509_INTEGER data structure
  3068. //
  3069. //  pvStructInfo points to an int.
  3070. //--------------------------------------------------------------------------
  3071.  
  3072. //+-------------------------------------------------------------------------
  3073. //  X509_MULTI_BYTE_INTEGER data structure
  3074. //
  3075. //  pvStructInfo points to a CRYPT_INTEGER_BLOB.
  3076. //--------------------------------------------------------------------------
  3077.  
  3078. //+-------------------------------------------------------------------------
  3079. //  X509_ENUMERATED data structure
  3080. //
  3081. //  pvStructInfo points to an int containing the enumerated value
  3082. //--------------------------------------------------------------------------
  3083.  
  3084. //+-------------------------------------------------------------------------
  3085. //  X509_CHOICE_OF_TIME data structure
  3086. //
  3087. //  pvStructInfo points to a FILETIME.
  3088. //--------------------------------------------------------------------------
  3089.  
  3090. //+-------------------------------------------------------------------------
  3091. //  X509_SEQUENCE_OF_ANY data structure
  3092. //
  3093. //  pvStructInfo points to following CRYPT_SEQUENCE_OF_ANY.
  3094. //
  3095. //  The CRYPT_DER_BLOBs point to the already encoded ANY content.
  3096. //--------------------------------------------------------------------------
  3097. typedef struct _CRYPT_SEQUENCE_OF_ANY {
  3098.     DWORD               cValue;
  3099.     PCRYPT_DER_BLOB     rgValue;
  3100. } CRYPT_SEQUENCE_OF_ANY, *PCRYPT_SEQUENCE_OF_ANY;
  3101.  
  3102.  
  3103. //+-------------------------------------------------------------------------
  3104. //  X509_AUTHORITY_KEY_ID2
  3105. //  szOID_AUTHORITY_KEY_IDENTIFIER2
  3106. //
  3107. //  pvStructInfo points to following CERT_AUTHORITY_KEY_ID2_INFO.
  3108. //
  3109. //  For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  3110. //  *pcbEncoded by CryptEncodeObject(X509_AUTHORITY_KEY_ID2)
  3111. //
  3112. //  See X509_ALTERNATE_NAME for error location defines.
  3113. //--------------------------------------------------------------------------
  3114. typedef struct _CERT_AUTHORITY_KEY_ID2_INFO {
  3115.     CRYPT_DATA_BLOB     KeyId;
  3116.     CERT_ALT_NAME_INFO  AuthorityCertIssuer;    // Optional, set cAltEntry
  3117.                                                 // to 0 to omit.
  3118.     CRYPT_INTEGER_BLOB  AuthorityCertSerialNumber;
  3119. } CERT_AUTHORITY_KEY_ID2_INFO, *PCERT_AUTHORITY_KEY_ID2_INFO;
  3120.  
  3121. //+-------------------------------------------------------------------------
  3122. //  szOID_SUBJECT_KEY_IDENTIFIER
  3123. //
  3124. //  pvStructInfo points to a CRYPT_DATA_BLOB.
  3125. //--------------------------------------------------------------------------
  3126.  
  3127. //+-------------------------------------------------------------------------
  3128. //  X509_AUTHORITY_INFO_ACCESS
  3129. //  szOID_AUTHORITY_INFO_ACCESS
  3130. //
  3131. //  pvStructInfo points to following CERT_AUTHORITY_INFO_ACCESS.
  3132. //
  3133. //  For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  3134. //  *pcbEncoded by CryptEncodeObject(X509_AUTHORITY_INFO_ACCESS)
  3135. //
  3136. //  Error location consists of:
  3137. //    ENTRY_INDEX   - 8 bits << 16
  3138. //    VALUE_INDEX   - 16 bits (unicode character index)
  3139. //
  3140. //  See X509_ALTERNATE_NAME for ENTRY_INDEX and VALUE_INDEX error location
  3141. //  defines.
  3142. //--------------------------------------------------------------------------
  3143.  
  3144. typedef struct _CERT_ACCESS_DESCRIPTION {
  3145.     LPSTR               pszAccessMethod;        // pszObjId
  3146.     CERT_ALT_NAME_ENTRY AccessLocation;
  3147. } CERT_ACCESS_DESCRIPTION, *PCERT_ACCESS_DESCRIPTION;
  3148.  
  3149.  
  3150. typedef struct _CERT_AUTHORITY_INFO_ACCESS {
  3151.     DWORD                       cAccDescr;
  3152.     PCERT_ACCESS_DESCRIPTION    rgAccDescr;
  3153. } CERT_AUTHORITY_INFO_ACCESS, *PCERT_AUTHORITY_INFO_ACCESS;
  3154.  
  3155.  
  3156. //+-------------------------------------------------------------------------
  3157. //  PKIX Access Description: Access Method Object Identifiers
  3158. //--------------------------------------------------------------------------
  3159. #define szOID_PKIX_ACC_DESCR            "1.3.6.1.5.5.7.48"
  3160. #define szOID_PKIX_OCSP                 "1.3.6.1.5.5.7.48.1"
  3161. #define szOID_PKIX_CA_ISSUERS           "1.3.6.1.5.5.7.48.2"
  3162.  
  3163.  
  3164. //+-------------------------------------------------------------------------
  3165. //  X509_CRL_REASON_CODE
  3166. //  szOID_CRL_REASON_CODE
  3167. //
  3168. //  pvStructInfo points to an int which can be set to one of the following
  3169. //  enumerated values:
  3170. //--------------------------------------------------------------------------
  3171. #define CRL_REASON_UNSPECIFIED              0
  3172. #define CRL_REASON_KEY_COMPROMISE           1
  3173. #define CRL_REASON_CA_COMPROMISE            2
  3174. #define CRL_REASON_AFFILIATION_CHANGED      3
  3175. #define CRL_REASON_SUPERSEDED               4
  3176. #define CRL_REASON_CESSATION_OF_OPERATION   5
  3177. #define CRL_REASON_CERTIFICATE_HOLD         6
  3178. #define CRL_REASON_REMOVE_FROM_CRL          8
  3179.  
  3180.  
  3181. //+-------------------------------------------------------------------------
  3182. //  X509_CRL_DIST_POINTS
  3183. //  szOID_CRL_DIST_POINTS
  3184. //
  3185. //  pvStructInfo points to following CRL_DIST_POINTS_INFO.
  3186. //
  3187. //  For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  3188. //  *pcbEncoded by CryptEncodeObject(X509_CRL_DIST_POINTS)
  3189. //
  3190. //  Error location consists of:
  3191. //    CRL_ISSUER_BIT    - 1 bit  << 31 (0 for FullName, 1 for CRLIssuer)
  3192. //    POINT_INDEX       - 7 bits << 24
  3193. //    ENTRY_INDEX       - 8 bits << 16
  3194. //    VALUE_INDEX       - 16 bits (unicode character index)
  3195. //
  3196. //  See X509_ALTERNATE_NAME for ENTRY_INDEX and VALUE_INDEX error location
  3197. //  defines.
  3198. //--------------------------------------------------------------------------
  3199. typedef struct _CRL_DIST_POINT_NAME {
  3200.     DWORD   dwDistPointNameChoice;
  3201.     union {
  3202.         CERT_ALT_NAME_INFO      FullName;       // 1
  3203.         // Not implemented      IssuerRDN;      // 2
  3204.     };
  3205. } CRL_DIST_POINT_NAME, *PCRL_DIST_POINT_NAME;
  3206.  
  3207. #define CRL_DIST_POINT_NO_NAME          0
  3208. #define CRL_DIST_POINT_FULL_NAME        1
  3209. #define CRL_DIST_POINT_ISSUER_RDN_NAME  2
  3210.  
  3211. typedef struct _CRL_DIST_POINT {
  3212.     CRL_DIST_POINT_NAME     DistPointName;      // OPTIONAL
  3213.     CRYPT_BIT_BLOB          ReasonFlags;        // OPTIONAL
  3214.     CERT_ALT_NAME_INFO      CRLIssuer;          // OPTIONAL
  3215. } CRL_DIST_POINT, *PCRL_DIST_POINT;
  3216.  
  3217. #define CRL_REASON_UNUSED_FLAG                  0x80
  3218. #define CRL_REASON_KEY_COMPROMISE_FLAG          0x40
  3219. #define CRL_REASON_CA_COMPROMISE_FLAG           0x20
  3220. #define CRL_REASON_AFFILIATION_CHANGED_FLAG     0x10
  3221. #define CRL_REASON_SUPERSEDED_FLAG              0x08
  3222. #define CRL_REASON_CESSATION_OF_OPERATION_FLAG  0x04
  3223. #define CRL_REASON_CERTIFICATE_HOLD_FLAG        0x02
  3224.  
  3225. typedef struct _CRL_DIST_POINTS_INFO {
  3226.     DWORD                   cDistPoint;
  3227.     PCRL_DIST_POINT         rgDistPoint;
  3228. } CRL_DIST_POINTS_INFO, *PCRL_DIST_POINTS_INFO;
  3229.  
  3230. #define CRL_DIST_POINT_ERR_INDEX_MASK          0x7F
  3231. #define CRL_DIST_POINT_ERR_INDEX_SHIFT         24
  3232. #define GET_CRL_DIST_POINT_ERR_INDEX(X)   \
  3233.     ((X >> CRL_DIST_POINT_ERR_INDEX_SHIFT) & CRL_DIST_POINT_ERR_INDEX_MASK)
  3234.  
  3235. #define CRL_DIST_POINT_ERR_CRL_ISSUER_BIT      0x80000000L
  3236. #define IS_CRL_DIST_POINT_ERR_CRL_ISSUER(X)   \
  3237.     (0 != (X & CRL_DIST_POINT_ERR_CRL_ISSUER_BIT))
  3238.  
  3239.  
  3240. //+-------------------------------------------------------------------------
  3241. //  X509_ENHANCED_KEY_USAGE
  3242. //  szOID_ENHANCED_KEY_USAGE
  3243. //
  3244. //  pvStructInfo points to a CERT_ENHKEY_USAGE, CTL_USAGE.
  3245. //--------------------------------------------------------------------------
  3246.  
  3247. //+-------------------------------------------------------------------------
  3248. //  szOID_NEXT_UPDATE_LOCATION
  3249. //
  3250. //  pvStructInfo points to a CERT_ALT_NAME_INFO.
  3251. //--------------------------------------------------------------------------
  3252.  
  3253. //+-------------------------------------------------------------------------
  3254. //  PKCS_CTL
  3255. //  szOID_CTL
  3256. //
  3257. //  pvStructInfo points to a CTL_INFO.
  3258. //--------------------------------------------------------------------------
  3259.  
  3260. //+-------------------------------------------------------------------------
  3261. //  PKCS_SORTED_CTL
  3262. //
  3263. //  pvStructInfo points to a CTL_INFO.
  3264. //
  3265. //  Same as for PKCS_CTL, except, the CTL entries are sorted. The following
  3266. //  extension containing the sort information is inserted as the first
  3267. //  extension in the encoded CTL.
  3268. //
  3269. //  Only supported for Encoding. CRYPT_ENCODE_ALLOC_FLAG flag must be
  3270. //  set.
  3271. //--------------------------------------------------------------------------
  3272.  
  3273.  
  3274. //+-------------------------------------------------------------------------
  3275. // Sorted CTL TrustedSubjects extension
  3276. //
  3277. //  Array of little endian DWORDs:
  3278. //   [0] - Flags
  3279. //   [1] - Count of HashBucket entry offsets
  3280. //   [2] - Maximum HashBucket entry collision count
  3281. //   [3 ..] (Count + 1) HashBucket entry offsets
  3282. //
  3283. //  When this extension is present in the CTL,
  3284. //  the ASN.1 encoded sequence of TrustedSubjects are HashBucket ordered.
  3285. //
  3286. //  The entry offsets point to the start of the first encoded TrustedSubject
  3287. //  sequence for the HashBucket. The encoded TrustedSubjects for a HashBucket
  3288. //  continue until the encoded offset of the next HashBucket. A HashBucket has
  3289. //  no entries if HashBucket[N] == HashBucket[N + 1].
  3290. //
  3291. //  The HashBucket offsets are from the start of the ASN.1 encoded CTL_INFO.
  3292. //--------------------------------------------------------------------------
  3293. #define SORTED_CTL_EXT_FLAGS_OFFSET         (0*4)
  3294. #define SORTED_CTL_EXT_COUNT_OFFSET         (1*4)
  3295. #define SORTED_CTL_EXT_MAX_COLLISION_OFFSET (2*4)
  3296. #define SORTED_CTL_EXT_HASH_BUCKET_OFFSET   (3*4)
  3297.  
  3298. // If the SubjectIdentifiers are a MD5 or SHA1 hash, the following flag is
  3299. // set. When set, the first 4 bytes of the SubjectIdentifier are used as
  3300. // the dwhash. Otherwise, the SubjectIdentifier bytes are hashed into dwHash.
  3301. // In either case the HashBucket index = dwHash % cHashBucket.
  3302. #define SORTED_CTL_EXT_HASHED_SUBJECT_IDENTIFIER_FLAG       0x1
  3303.  
  3304. //+-------------------------------------------------------------------------
  3305. //  X509_MULTI_BYTE_UINT
  3306. //
  3307. //  pvStructInfo points to a CRYPT_UINT_BLOB. Before encoding, inserts a
  3308. //  leading 0x00. After decoding, removes a leading 0x00.
  3309. //--------------------------------------------------------------------------
  3310.  
  3311. //+-------------------------------------------------------------------------
  3312. //  X509_DSS_PUBLICKEY
  3313. //
  3314. //  pvStructInfo points to a CRYPT_UINT_BLOB.
  3315. //--------------------------------------------------------------------------
  3316.  
  3317. //+-------------------------------------------------------------------------
  3318. //  X509_DSS_PARAMETERS
  3319. //
  3320. //  pvStructInfo points to following CERT_DSS_PARAMETERS data structure.
  3321. //--------------------------------------------------------------------------
  3322. typedef struct _CERT_DSS_PARAMETERS {
  3323.     CRYPT_UINT_BLOB     p;
  3324.     CRYPT_UINT_BLOB     q;
  3325.     CRYPT_UINT_BLOB     g;
  3326. } CERT_DSS_PARAMETERS, *PCERT_DSS_PARAMETERS;
  3327.  
  3328. //+-------------------------------------------------------------------------
  3329. //  X509_DSS_SIGNATURE
  3330. //
  3331. //  pvStructInfo is a BYTE rgbSignature[CERT_DSS_SIGNATURE_LEN]. The
  3332. //  bytes are ordered as output by the DSS CSP's CryptSignHash().
  3333. //--------------------------------------------------------------------------
  3334. #define CERT_DSS_R_LEN          20
  3335. #define CERT_DSS_S_LEN          20
  3336. #define CERT_DSS_SIGNATURE_LEN  (CERT_DSS_R_LEN + CERT_DSS_S_LEN)
  3337.  
  3338. // Sequence of 2 unsigned integers (the extra +1 is for a potential leading
  3339. // 0x00 to make the integer unsigned)
  3340. #define CERT_MAX_ASN_ENCODED_DSS_SIGNATURE_LEN  (2 + 2*(2 + 20 +1))
  3341.  
  3342. //+-------------------------------------------------------------------------
  3343. //  X509_DH_PUBLICKEY
  3344. //
  3345. //  pvStructInfo points to a CRYPT_UINT_BLOB.
  3346. //--------------------------------------------------------------------------
  3347.  
  3348. //+-------------------------------------------------------------------------
  3349. //  X509_DH_PARAMETERS
  3350. //
  3351. //  pvStructInfo points to following CERT_DH_PARAMETERS data structure.
  3352. //--------------------------------------------------------------------------
  3353. typedef struct _CERT_DH_PARAMETERS {
  3354.     CRYPT_UINT_BLOB     p;
  3355.     CRYPT_UINT_BLOB     g;
  3356. } CERT_DH_PARAMETERS, *PCERT_DH_PARAMETERS;
  3357.  
  3358. //+-------------------------------------------------------------------------
  3359. //  X942_DH_PARAMETERS
  3360. //
  3361. //  pvStructInfo points to following CERT_X942_DH_PARAMETERS data structure.
  3362. //
  3363. //  If q.cbData == 0, then, the following fields are zero'ed.
  3364. //--------------------------------------------------------------------------
  3365. typedef struct _CERT_X942_DH_VALIDATION_PARAMS {
  3366.     CRYPT_BIT_BLOB      seed;
  3367.     DWORD               pgenCounter;
  3368. } CERT_X942_DH_VALIDATION_PARAMS, *PCERT_X942_DH_VALIDATION_PARAMS;
  3369.  
  3370. typedef struct _CERT_X942_DH_PARAMETERS {
  3371.     CRYPT_UINT_BLOB     p;          // odd prime, p = jq + 1
  3372.     CRYPT_UINT_BLOB     g;          // generator, g
  3373.     CRYPT_UINT_BLOB     q;          // factor of p - 1, OPTIONAL
  3374.     CRYPT_UINT_BLOB     j;          // subgroup factor, OPTIONAL
  3375.     PCERT_X942_DH_VALIDATION_PARAMS pValidationParams;  // OPTIONAL
  3376. } CERT_X942_DH_PARAMETERS, *PCERT_X942_DH_PARAMETERS;
  3377.  
  3378. //+-------------------------------------------------------------------------
  3379. //  X942_OTHER_INFO
  3380. //
  3381. //  pvStructInfo points to following CRYPT_X942_OTHER_INFO data structure.
  3382. //
  3383. //  rgbCounter and rgbKeyLength are in Little Endian order.
  3384. //--------------------------------------------------------------------------
  3385. #define CRYPT_X942_COUNTER_BYTE_LENGTH      4
  3386. #define CRYPT_X942_KEY_LENGTH_BYTE_LENGTH   4
  3387. #define CRYPT_X942_PUB_INFO_BYTE_LENGTH     (512/8)
  3388. typedef struct _CRYPT_X942_OTHER_INFO {
  3389.     LPSTR               pszContentEncryptionObjId;
  3390.     BYTE                rgbCounter[CRYPT_X942_COUNTER_BYTE_LENGTH];
  3391.     BYTE                rgbKeyLength[CRYPT_X942_KEY_LENGTH_BYTE_LENGTH];
  3392.     CRYPT_DATA_BLOB     PubInfo;    // OPTIONAL
  3393. } CRYPT_X942_OTHER_INFO, *PCRYPT_X942_OTHER_INFO;
  3394.  
  3395.  
  3396. //+-------------------------------------------------------------------------
  3397. //  PKCS_RC2_CBC_PARAMETERS
  3398. //  szOID_RSA_RC2CBC
  3399. //
  3400. //  pvStructInfo points to following CRYPT_RC2_CBC_PARAMETERS data structure.
  3401. //--------------------------------------------------------------------------
  3402. typedef struct _CRYPT_RC2_CBC_PARAMETERS {
  3403.     DWORD               dwVersion;
  3404.     BOOL                fIV;            // set if has following IV
  3405.     BYTE                rgbIV[8];
  3406. } CRYPT_RC2_CBC_PARAMETERS, *PCRYPT_RC2_CBC_PARAMETERS;
  3407.  
  3408. #define CRYPT_RC2_40BIT_VERSION     160
  3409. #define CRYPT_RC2_56BIT_VERSION     52
  3410. #define CRYPT_RC2_64BIT_VERSION     120
  3411. #define CRYPT_RC2_128BIT_VERSION    58
  3412.  
  3413.  
  3414. //+-------------------------------------------------------------------------
  3415. //  PKCS_SMIME_CAPABILITIES
  3416. //  szOID_RSA_SMIMECapabilities
  3417. //
  3418. //  pvStructInfo points to following CRYPT_SMIME_CAPABILITIES data structure.
  3419. //
  3420. //  Note, for CryptEncodeObject(X509_ASN_ENCODING), Parameters.cbData == 0
  3421. //  causes the encoded parameters to be omitted and not encoded as a NULL
  3422. //  (05 00) as is done when encoding a CRYPT_ALGORITHM_IDENTIFIER. This
  3423. //  is per the SMIME specification for encoding capabilities.
  3424. //--------------------------------------------------------------------------
  3425. typedef struct _CRYPT_SMIME_CAPABILITY {
  3426.     LPSTR               pszObjId;
  3427.     CRYPT_OBJID_BLOB    Parameters;
  3428. } CRYPT_SMIME_CAPABILITY, *PCRYPT_SMIME_CAPABILITY;
  3429.  
  3430. typedef struct _CRYPT_SMIME_CAPABILITIES {
  3431.     DWORD                   cCapability;
  3432.     PCRYPT_SMIME_CAPABILITY rgCapability;
  3433. } CRYPT_SMIME_CAPABILITIES, *PCRYPT_SMIME_CAPABILITIES;
  3434.  
  3435.  
  3436. //+-------------------------------------------------------------------------
  3437. //  PKCS7_SIGNER_INFO
  3438. //
  3439. //  pvStructInfo points to CMSG_SIGNER_INFO.
  3440. //--------------------------------------------------------------------------
  3441.  
  3442. //+-------------------------------------------------------------------------
  3443. //  CMS_SIGNER_INFO
  3444. //
  3445. //  pvStructInfo points to CMSG_CMS_SIGNER_INFO.
  3446. //--------------------------------------------------------------------------
  3447.  
  3448.  
  3449. //+-------------------------------------------------------------------------
  3450. //  Netscape Certificate Extension Object Identifiers
  3451. //--------------------------------------------------------------------------
  3452. #define szOID_NETSCAPE                  "2.16.840.1.113730"
  3453. #define szOID_NETSCAPE_CERT_EXTENSION   "2.16.840.1.113730.1"
  3454. #define szOID_NETSCAPE_CERT_TYPE        "2.16.840.1.113730.1.1"
  3455. #define szOID_NETSCAPE_BASE_URL         "2.16.840.1.113730.1.2"
  3456. #define szOID_NETSCAPE_REVOCATION_URL   "2.16.840.1.113730.1.3"
  3457. #define szOID_NETSCAPE_CA_REVOCATION_URL "2.16.840.1.113730.1.4"
  3458. #define szOID_NETSCAPE_CERT_RENEWAL_URL "2.16.840.1.113730.1.7"
  3459. #define szOID_NETSCAPE_CA_POLICY_URL    "2.16.840.1.113730.1.8"
  3460. #define szOID_NETSCAPE_SSL_SERVER_NAME  "2.16.840.1.113730.1.12"
  3461. #define szOID_NETSCAPE_COMMENT          "2.16.840.1.113730.1.13"
  3462.  
  3463. //+-------------------------------------------------------------------------
  3464. //  Netscape Certificate Data Type Object Identifiers
  3465. //--------------------------------------------------------------------------
  3466. #define szOID_NETSCAPE_DATA_TYPE        "2.16.840.1.113730.2"
  3467. #define szOID_NETSCAPE_CERT_SEQUENCE    "2.16.840.1.113730.2.5"
  3468.  
  3469.  
  3470. //+-------------------------------------------------------------------------
  3471. //  szOID_NETSCAPE_CERT_TYPE extension
  3472. //
  3473. //  Its value is a bit string. CryptDecodeObject/CryptEncodeObject using
  3474. //  X509_BITS or X509_BITS_WITHOUT_TRAILING_ZEROES.
  3475. //
  3476. //  The following bits are defined:
  3477. //--------------------------------------------------------------------------
  3478. #define NETSCAPE_SSL_CLIENT_AUTH_CERT_TYPE  0x80
  3479. #define NETSCAPE_SSL_SERVER_AUTH_CERT_TYPE  0x40
  3480. #define NETSCAPE_SMIME_CERT_TYPE            0x20
  3481. #define NETSCAPE_SIGN_CERT_TYPE             0x10
  3482. #define NETSCAPE_SSL_CA_CERT_TYPE           0x04
  3483. #define NETSCAPE_SMIME_CA_CERT_TYPE         0x02
  3484. #define NETSCAPE_SIGN_CA_CERT_TYPE          0x01
  3485.  
  3486. //+-------------------------------------------------------------------------
  3487. //  szOID_NETSCAPE_BASE_URL extension
  3488. //
  3489. //  Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3490. //  X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3491. //  dwValueType = CERT_RDN_IA5_STRING.
  3492. //
  3493. //  When present this string is added to the beginning of all relative URLs
  3494. //  in the certificate.  This extension can be considered an optimization
  3495. //  to reduce the size of the URL extensions.
  3496. //--------------------------------------------------------------------------
  3497.  
  3498. //+-------------------------------------------------------------------------
  3499. //  szOID_NETSCAPE_REVOCATION_URL extension
  3500. //
  3501. //  Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3502. //  X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3503. //  dwValueType = CERT_RDN_IA5_STRING.
  3504. //
  3505. //  It is a relative or absolute URL that can be used to check the
  3506. //  revocation status of a certificate. The revocation check will be
  3507. //  performed as an HTTP GET method using a url that is the concatenation of
  3508. //  revocation-url and certificate-serial-number.
  3509. //  Where the certificate-serial-number is encoded as a string of
  3510. //  ascii hexadecimal digits. For example, if the netscape-base-url is
  3511. //  https://www.certs-r-us.com/, the netscape-revocation-url is
  3512. //  cgi-bin/check-rev.cgi?, and the certificate serial number is 173420,
  3513. //  the resulting URL would be:
  3514. //  https://www.certs-r-us.com/cgi-bin/check-rev.cgi?02a56c
  3515. //
  3516. //  The server should return a document with a Content-Type of
  3517. //  application/x-netscape-revocation.  The document should contain
  3518. //  a single ascii digit, '1' if the certificate is not curently valid,
  3519. //  and '0' if it is curently valid.
  3520. //
  3521. //  Note: for all of the URLs that include the certificate serial number,
  3522. //  the serial number will be encoded as a string which consists of an even
  3523. //  number of hexadecimal digits.  If the number of significant digits is odd,
  3524. //  the string will have a single leading zero to ensure an even number of
  3525. //  digits is generated.
  3526. //--------------------------------------------------------------------------
  3527.  
  3528. //+-------------------------------------------------------------------------
  3529. //  szOID_NETSCAPE_CA_REVOCATION_URL extension
  3530. //
  3531. //  Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3532. //  X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3533. //  dwValueType = CERT_RDN_IA5_STRING.
  3534. //
  3535. //  It is a relative or absolute URL that can be used to check the
  3536. //  revocation status of any certificates that are signed by the CA that
  3537. //  this certificate belongs to. This extension is only valid in CA
  3538. //  certificates.  The use of this extension is the same as the above
  3539. //  szOID_NETSCAPE_REVOCATION_URL extension.
  3540. //--------------------------------------------------------------------------
  3541.  
  3542. //+-------------------------------------------------------------------------
  3543. //  szOID_NETSCAPE_CERT_RENEWAL_URL extension
  3544. //
  3545. //  Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3546. //  X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3547. //  dwValueType = CERT_RDN_IA5_STRING.
  3548. //
  3549. //  It is a relative or absolute URL that points to a certificate renewal
  3550. //  form. The renewal form will be accessed with an HTTP GET method using a
  3551. //  url that is the concatenation of renewal-url and
  3552. //  certificate-serial-number. Where the certificate-serial-number is
  3553. //  encoded as a string of ascii hexadecimal digits. For example, if the
  3554. //  netscape-base-url is https://www.certs-r-us.com/, the
  3555. //  netscape-cert-renewal-url is cgi-bin/check-renew.cgi?, and the
  3556. //  certificate serial number is 173420, the resulting URL would be:
  3557. //  https://www.certs-r-us.com/cgi-bin/check-renew.cgi?02a56c
  3558. //  The document returned should be an HTML form that will allow the user
  3559. //  to request a renewal of their certificate.
  3560. //--------------------------------------------------------------------------
  3561.  
  3562. //+-------------------------------------------------------------------------
  3563. //  szOID_NETSCAPE_CA_POLICY_URL extension
  3564. //
  3565. //  Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3566. //  X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3567. //  dwValueType = CERT_RDN_IA5_STRING.
  3568. //
  3569. //  It is a relative or absolute URL that points to a web page that
  3570. //  describes the policies under which the certificate was issued.
  3571. //--------------------------------------------------------------------------
  3572.  
  3573. //+-------------------------------------------------------------------------
  3574. //  szOID_NETSCAPE_SSL_SERVER_NAME extension
  3575. //
  3576. //  Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3577. //  X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3578. //  dwValueType = CERT_RDN_IA5_STRING.
  3579. //
  3580. //  It is a "shell expression" that can be used to match the hostname of the
  3581. //  SSL server that is using this certificate.  It is recommended that if
  3582. //  the server's hostname does not match this pattern the user be notified
  3583. //  and given the option to terminate the SSL connection.  If this extension
  3584. //  is not present then the CommonName in the certificate subject's
  3585. //  distinguished name is used for the same purpose.
  3586. //--------------------------------------------------------------------------
  3587.  
  3588. //+-------------------------------------------------------------------------
  3589. //  szOID_NETSCAPE_COMMENT extension
  3590. //
  3591. //  Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3592. //  X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3593. //  dwValueType = CERT_RDN_IA5_STRING.
  3594. //
  3595. //  It is a comment that may be displayed to the user when the certificate
  3596. //  is viewed.
  3597. //--------------------------------------------------------------------------
  3598.  
  3599. //+-------------------------------------------------------------------------
  3600. //  szOID_NETSCAPE_CERT_SEQUENCE
  3601. //
  3602. //  Its value is a PKCS#7 ContentInfo structure wrapping a sequence of
  3603. //  certificates. The value of the contentType field is
  3604. //  szOID_NETSCAPE_CERT_SEQUENCE, while the content field is the following
  3605. //  structure:
  3606. //      CertificateSequence ::= SEQUENCE OF Certificate.
  3607. //
  3608. //  CryptDecodeObject/CryptEncodeObject using
  3609. //  PKCS_CONTENT_INFO_SEQUENCE_OF_ANY, where,
  3610. //  pszObjId = szOID_NETSCAPE_CERT_SEQUENCE and the CRYPT_DER_BLOBs point
  3611. //  to encoded X509 certificates.
  3612. //--------------------------------------------------------------------------
  3613.  
  3614.  
  3615. //+=========================================================================
  3616. //  Object IDentifier (OID) Installable Functions:  Data Structures and APIs
  3617. //==========================================================================
  3618.  
  3619. typedef void *HCRYPTOIDFUNCSET;
  3620. typedef void *HCRYPTOIDFUNCADDR;
  3621.  
  3622. // Predefined OID Function Names
  3623. #define CRYPT_OID_ENCODE_OBJECT_FUNC        "CryptDllEncodeObject"
  3624. #define CRYPT_OID_DECODE_OBJECT_FUNC        "CryptDllDecodeObject"
  3625. #define CRYPT_OID_ENCODE_OBJECT_EX_FUNC     "CryptDllEncodeObjectEx"
  3626. #define CRYPT_OID_DECODE_OBJECT_EX_FUNC     "CryptDllDecodeObjectEx"
  3627. #define CRYPT_OID_CREATE_COM_OBJECT_FUNC    "CryptDllCreateCOMObject"
  3628. #define CRYPT_OID_VERIFY_REVOCATION_FUNC    "CertDllVerifyRevocation"
  3629. #define CRYPT_OID_VERIFY_CTL_USAGE_FUNC     "CertDllVerifyCTLUsage"
  3630. #define CRYPT_OID_FORMAT_OBJECT_FUNC        "CryptDllFormatObject"
  3631. #define CRYPT_OID_FIND_OID_INFO_FUNC        "CryptDllFindOIDInfo"
  3632. #define CRYPT_OID_FIND_LOCALIZED_NAME_FUNC  "CryptDllFindLocalizedName"
  3633.  
  3634.  
  3635. // CryptDllEncodeObject has same function signature as CryptEncodeObject.
  3636.  
  3637. // CryptDllDecodeObject has same function signature as CryptDecodeObject.
  3638.  
  3639. // CryptDllEncodeObjectEx has same function signature as CryptEncodeObjectEx.
  3640. // The Ex version MUST support the CRYPT_ENCODE_ALLOC_FLAG option.
  3641. //
  3642. // If an Ex function isn't installed or registered, then, attempts to find
  3643. // a non-EX version. If the ALLOC flag is set, then, CryptEncodeObjectEx,
  3644. // does the allocation and calls the non-EX version twice.
  3645.  
  3646. // CryptDllDecodeObjectEx has same function signature as CryptDecodeObjectEx.
  3647. // The Ex version MUST support the CRYPT_DECODE_ALLOC_FLAG option.
  3648. //
  3649. // If an Ex function isn't installed or registered, then, attempts to find
  3650. // a non-EX version. If the ALLOC flag is set, then, CryptDecodeObjectEx,
  3651. // does the allocation and calls the non-EX version twice.
  3652.  
  3653. // CryptDllCreateCOMObject has the following signature:
  3654. //      BOOL WINAPI CryptDllCreateCOMObject(
  3655. //          IN DWORD dwEncodingType,
  3656. //          IN LPCSTR pszOID,
  3657. //          IN PCRYPT_DATA_BLOB pEncodedContent,
  3658. //          IN DWORD dwFlags,
  3659. //          IN REFIID riid,
  3660. //          OUT void **ppvObj);
  3661.  
  3662. // CertDllVerifyRevocation has the same signature as CertVerifyRevocation
  3663. //  (See CertVerifyRevocation for details on when called)
  3664.  
  3665. // CertDllVerifyCTLUsage has the same signature as CertVerifyCTLUsage
  3666.  
  3667. // CryptDllFindOIDInfo currently is only used to store values used by
  3668. // CryptFindOIDInfo. See CryptFindOIDInfo() for more details.
  3669.  
  3670. // CryptDllFindLocalizedName is only used to store localized string
  3671. // values used by CryptFindLocalizedName. See CryptFindLocalizedName() for
  3672. // more details.
  3673.  
  3674. //  Example of a complete OID Function Registry Name:
  3675. //    HKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography\OID
  3676. //      Encoding Type 1\CryptDllEncodeObject\1.2.3
  3677. //
  3678. //  The key's L"Dll" value contains the name of the Dll.
  3679. //  The key's L"FuncName" value overrides the default function name
  3680. #define CRYPT_OID_REGPATH "Software\\Microsoft\\Cryptography\\OID"
  3681. #define CRYPT_OID_REG_ENCODING_TYPE_PREFIX  "EncodingType "
  3682. #define CRYPT_OID_REG_DLL_VALUE_NAME        L"Dll"
  3683. #define CRYPT_OID_REG_FUNC_NAME_VALUE_NAME  L"FuncName"
  3684. #define CRYPT_OID_REG_FUNC_NAME_VALUE_NAME_A "FuncName"
  3685.  
  3686. // CRYPT_INSTALL_OID_FUNC_BEFORE_FLAG can be set in the key's L"CryptFlags"
  3687. // value to register the functions before the installed functions.
  3688. //
  3689. // CryptSetOIDFunctionValue must be called to set this value. L"CryptFlags"
  3690. // must be set using a dwValueType of REG_DWORD.
  3691. #define CRYPT_OID_REG_FLAGS_VALUE_NAME      L"CryptFlags"
  3692.  
  3693. // OID used for Default OID functions
  3694. #define CRYPT_DEFAULT_OID                   "DEFAULT"
  3695.  
  3696. typedef struct _CRYPT_OID_FUNC_ENTRY {
  3697.     LPCSTR  pszOID;
  3698.     void    *pvFuncAddr;
  3699. } CRYPT_OID_FUNC_ENTRY, *PCRYPT_OID_FUNC_ENTRY;
  3700.  
  3701.  
  3702. #define CRYPT_INSTALL_OID_FUNC_BEFORE_FLAG  1
  3703.  
  3704.  
  3705. //+-------------------------------------------------------------------------
  3706. //  Install a set of callable OID function addresses.
  3707. //
  3708. //  By default the functions are installed at end of the list.
  3709. //  Set CRYPT_INSTALL_OID_FUNC_BEFORE_FLAG to install at beginning of list.
  3710. //
  3711. //  hModule should be updated with the hModule passed to DllMain to prevent
  3712. //  the Dll containing the function addresses from being unloaded by
  3713. //  CryptGetOIDFuncAddress/CryptFreeOIDFunctionAddress. This would be the
  3714. //  case when the Dll has also regsvr32'ed OID functions via
  3715. //  CryptRegisterOIDFunction.
  3716. //
  3717. //  DEFAULT functions are installed by setting rgFuncEntry[].pszOID =
  3718. //  CRYPT_DEFAULT_OID.
  3719. //--------------------------------------------------------------------------
  3720. WINCRYPT32API
  3721. BOOL
  3722. WINAPI
  3723. CryptInstallOIDFunctionAddress(
  3724.     IN HMODULE hModule,         // hModule passed to DllMain
  3725.     IN DWORD dwEncodingType,
  3726.     IN LPCSTR pszFuncName,
  3727.     IN DWORD cFuncEntry,
  3728.     IN const CRYPT_OID_FUNC_ENTRY rgFuncEntry[],
  3729.     IN DWORD dwFlags
  3730.     );
  3731.  
  3732. //+-------------------------------------------------------------------------
  3733. //  Initialize and return handle to the OID function set identified by its
  3734. //  function name.
  3735. //
  3736. //  If the set already exists, a handle to the existing set is returned.
  3737. //--------------------------------------------------------------------------
  3738. WINCRYPT32API
  3739. HCRYPTOIDFUNCSET
  3740. WINAPI
  3741. CryptInitOIDFunctionSet(
  3742.     IN LPCSTR pszFuncName,
  3743.     IN DWORD dwFlags
  3744.     );
  3745.  
  3746. //+-------------------------------------------------------------------------
  3747. //  Search the list of installed functions for an encoding type and OID match.
  3748. //  If not found, search the registry.
  3749. //
  3750. //  For success, returns TRUE with *ppvFuncAddr updated with the function's
  3751. //  address and *phFuncAddr updated with the function address's handle.
  3752. //  The function's handle is AddRef'ed. CryptFreeOIDFunctionAddress needs to
  3753. //  be called to release it.
  3754. //
  3755. //  For a registry match, the Dll containing the function is loaded.
  3756. //
  3757. //  By default, both the registered and installed function lists are searched.
  3758. //  Set CRYPT_GET_INSTALLED_OID_FUNC_FLAG to only search the installed list
  3759. //  of functions. This flag would be set by a registered function to get
  3760. //  the address of a pre-installed function it was replacing. For example,
  3761. //  the registered function might handle a new special case and call the
  3762. //  pre-installed function to handle the remaining cases.
  3763. //--------------------------------------------------------------------------
  3764. WINCRYPT32API
  3765. BOOL
  3766. WINAPI
  3767. CryptGetOIDFunctionAddress(
  3768.     IN HCRYPTOIDFUNCSET hFuncSet,
  3769.     IN DWORD dwEncodingType,
  3770.     IN LPCSTR pszOID,
  3771.     IN DWORD dwFlags,
  3772.     OUT void **ppvFuncAddr,
  3773.     OUT HCRYPTOIDFUNCADDR *phFuncAddr
  3774.     );
  3775.  
  3776. #define CRYPT_GET_INSTALLED_OID_FUNC_FLAG       0x1
  3777.  
  3778.  
  3779. //+-------------------------------------------------------------------------
  3780. //  Get the list of registered default Dll entries for the specified
  3781. //  function set and encoding type.
  3782. //
  3783. //  The returned list consists of none, one or more null terminated Dll file
  3784. //  names. The list is terminated with an empty (L"\0") Dll file name.
  3785. //  For example: L"first.dll" L"\0" L"second.dll" L"\0" L"\0"
  3786. //--------------------------------------------------------------------------
  3787. WINCRYPT32API
  3788. BOOL
  3789. WINAPI
  3790. CryptGetDefaultOIDDllList(
  3791.     IN HCRYPTOIDFUNCSET hFuncSet,
  3792.     IN DWORD dwEncodingType,
  3793.     OUT LPWSTR pwszDllList,
  3794.     IN OUT DWORD *pcchDllList
  3795.     );
  3796.  
  3797. //+-------------------------------------------------------------------------
  3798. //  Either: get the first or next installed DEFAULT function OR
  3799. //  load the Dll containing the DEFAULT function.
  3800. //
  3801. //  If pwszDll is NULL, search the list of installed DEFAULT functions.
  3802. //  *phFuncAddr must be set to NULL to get the first installed function.
  3803. //  Successive installed functions are returned by setting *phFuncAddr
  3804. //  to the hFuncAddr returned by the previous call.
  3805. //
  3806. //  If pwszDll is NULL, the input *phFuncAddr
  3807. //  is always CryptFreeOIDFunctionAddress'ed by this function, even for
  3808. //  an error.
  3809. //
  3810. //  If pwszDll isn't NULL, then, attempts to load the Dll and the DEFAULT
  3811. //  function. *phFuncAddr is ignored upon entry and isn't
  3812. //  CryptFreeOIDFunctionAddress'ed.
  3813. //
  3814. //  For success, returns TRUE with *ppvFuncAddr updated with the function's
  3815. //  address and *phFuncAddr updated with the function address's handle.
  3816. //  The function's handle is AddRef'ed. CryptFreeOIDFunctionAddress needs to
  3817. //  be called to release it or CryptGetDefaultOIDFunctionAddress can also
  3818. //  be called for a NULL pwszDll.
  3819. //--------------------------------------------------------------------------
  3820. WINCRYPT32API
  3821. BOOL
  3822. WINAPI
  3823. CryptGetDefaultOIDFunctionAddress(
  3824.     IN HCRYPTOIDFUNCSET hFuncSet,
  3825.     IN DWORD dwEncodingType,
  3826.     IN OPTIONAL LPCWSTR pwszDll,
  3827.     IN DWORD dwFlags,
  3828.     OUT void **ppvFuncAddr,
  3829.     IN OUT HCRYPTOIDFUNCADDR *phFuncAddr
  3830.     );
  3831.  
  3832. //+-------------------------------------------------------------------------
  3833. //  Releases the handle AddRef'ed and returned by CryptGetOIDFunctionAddress
  3834. //  or CryptGetDefaultOIDFunctionAddress.
  3835. //
  3836. //  If a Dll was loaded for the function its unloaded. However, before doing
  3837. //  the unload, the DllCanUnloadNow function exported by the loaded Dll is
  3838. //  called. It should return S_FALSE to inhibit the unload or S_TRUE to enable
  3839. //  the unload. If the Dll doesn't export DllCanUnloadNow, the Dll is unloaded.
  3840. //
  3841. //  DllCanUnloadNow has the following signature:
  3842. //      STDAPI  DllCanUnloadNow(void);
  3843. //--------------------------------------------------------------------------
  3844. WINCRYPT32API
  3845. BOOL
  3846. WINAPI
  3847. CryptFreeOIDFunctionAddress(
  3848.     IN HCRYPTOIDFUNCADDR hFuncAddr,
  3849.     IN DWORD dwFlags
  3850.     );
  3851.  
  3852. //+-------------------------------------------------------------------------
  3853. //  Register the Dll containing the function to be called for the specified
  3854. //  encoding type, function name and OID.
  3855. //
  3856. //  pwszDll may contain environment-variable strings
  3857. //  which are ExpandEnvironmentStrings()'ed before loading the Dll.
  3858. //
  3859. //  In addition to registering the DLL, you may override the
  3860. //  name of the function to be called. For example,
  3861. //      pszFuncName = "CryptDllEncodeObject",
  3862. //      pszOverrideFuncName = "MyEncodeXyz".
  3863. //  This allows a Dll to export multiple OID functions for the same
  3864. //  function name without needing to interpose its own OID dispatcher function.
  3865. //--------------------------------------------------------------------------
  3866. WINCRYPT32API
  3867. BOOL
  3868. WINAPI
  3869. CryptRegisterOIDFunction(
  3870.     IN DWORD dwEncodingType,
  3871.     IN LPCSTR pszFuncName,
  3872.     IN LPCSTR pszOID,
  3873.     IN OPTIONAL LPCWSTR pwszDll,
  3874.     IN OPTIONAL LPCSTR pszOverrideFuncName
  3875.     );
  3876.  
  3877. //+-------------------------------------------------------------------------
  3878. //  Unregister the Dll containing the function to be called for the specified
  3879. //  encoding type, function name and OID.
  3880. //--------------------------------------------------------------------------
  3881. WINCRYPT32API
  3882. BOOL
  3883. WINAPI
  3884. CryptUnregisterOIDFunction(
  3885.     IN DWORD dwEncodingType,
  3886.     IN LPCSTR pszFuncName,
  3887.     IN LPCSTR pszOID
  3888.     );
  3889.  
  3890.  
  3891. //+-------------------------------------------------------------------------
  3892. //  Register the Dll containing the default function to be called for the
  3893. //  specified encoding type and function name.
  3894. //
  3895. //  Unlike CryptRegisterOIDFunction, you can't override the function name
  3896. //  needing to be exported by the Dll.
  3897. //
  3898. //  The Dll is inserted before the entry specified by dwIndex.
  3899. //    dwIndex == 0, inserts at the beginning.
  3900. //    dwIndex == CRYPT_REGISTER_LAST_INDEX, appends at the end.
  3901. //
  3902. //  pwszDll may contain environment-variable strings
  3903. //  which are ExpandEnvironmentStrings()'ed before loading the Dll.
  3904. //--------------------------------------------------------------------------
  3905. WINCRYPT32API
  3906. BOOL
  3907. WINAPI
  3908. CryptRegisterDefaultOIDFunction(
  3909.     IN DWORD dwEncodingType,
  3910.     IN LPCSTR pszFuncName,
  3911.     IN DWORD dwIndex,
  3912.     IN LPCWSTR pwszDll
  3913.     );
  3914.  
  3915. #define CRYPT_REGISTER_FIRST_INDEX   0
  3916. #define CRYPT_REGISTER_LAST_INDEX    0xFFFFFFFF
  3917.  
  3918. //+-------------------------------------------------------------------------
  3919. //  Unregister the Dll containing the default function to be called for
  3920. //  the specified encoding type and function name.
  3921. //--------------------------------------------------------------------------
  3922. WINCRYPT32API
  3923. BOOL
  3924. WINAPI
  3925. CryptUnregisterDefaultOIDFunction(
  3926.     IN DWORD dwEncodingType,
  3927.     IN LPCSTR pszFuncName,
  3928.     IN LPCWSTR pwszDll
  3929.     );
  3930.  
  3931. //+-------------------------------------------------------------------------
  3932. //  Set the value for the specified encoding type, function name, OID and
  3933. //  value name.
  3934. //
  3935. //  See RegSetValueEx for the possible value types.
  3936. //
  3937. //  String types are UNICODE.
  3938. //--------------------------------------------------------------------------
  3939. WINCRYPT32API
  3940. BOOL
  3941. WINAPI
  3942. CryptSetOIDFunctionValue(
  3943.     IN DWORD dwEncodingType,
  3944.     IN LPCSTR pszFuncName,
  3945.     IN LPCSTR pszOID,
  3946.     IN LPCWSTR pwszValueName,
  3947.     IN DWORD dwValueType,
  3948.     IN const BYTE *pbValueData,
  3949.     IN DWORD cbValueData
  3950.     );
  3951.  
  3952. //+-------------------------------------------------------------------------
  3953. //  Get the value for the specified encoding type, function name, OID and
  3954. //  value name.
  3955. //
  3956. //  See RegEnumValue for the possible value types.
  3957. //
  3958. //  String types are UNICODE.
  3959. //--------------------------------------------------------------------------
  3960. WINCRYPT32API
  3961. BOOL
  3962. WINAPI
  3963. CryptGetOIDFunctionValue(
  3964.     IN DWORD dwEncodingType,
  3965.     IN LPCSTR pszFuncName,
  3966.     IN LPCSTR pszOID,
  3967.     IN LPCWSTR pwszValueName,
  3968.     OUT DWORD *pdwValueType,
  3969.     OUT BYTE *pbValueData,
  3970.     IN OUT DWORD *pcbValueData
  3971.     );
  3972.  
  3973. typedef BOOL (WINAPI *PFN_CRYPT_ENUM_OID_FUNC)(
  3974.     IN DWORD dwEncodingType,
  3975.     IN LPCSTR pszFuncName,
  3976.     IN LPCSTR pszOID,
  3977.     IN DWORD cValue,
  3978.     IN const DWORD rgdwValueType[],
  3979.     IN LPCWSTR const rgpwszValueName[],
  3980.     IN const BYTE * const rgpbValueData[],
  3981.     IN const DWORD rgcbValueData[],
  3982.     IN void *pvArg
  3983.     );
  3984.  
  3985. //+-------------------------------------------------------------------------
  3986. //  Enumerate the OID functions identified by their encoding type,
  3987. //  function name and OID.
  3988. //
  3989. //  pfnEnumOIDFunc is called for each registry key matching the input
  3990. //  parameters. Setting dwEncodingType to CRYPT_MATCH_ANY_ENCODING_TYPE matches
  3991. //  any. Setting pszFuncName or pszOID to NULL matches any.
  3992. //
  3993. //  Set pszOID == CRYPT_DEFAULT_OID to restrict the enumeration to only the
  3994. //  DEFAULT functions
  3995. //
  3996. //  String types are UNICODE.
  3997. //--------------------------------------------------------------------------
  3998. WINCRYPT32API
  3999. BOOL
  4000. WINAPI
  4001. CryptEnumOIDFunction(
  4002.     IN DWORD dwEncodingType,
  4003.     IN OPTIONAL LPCSTR pszFuncName,
  4004.     IN OPTIONAL LPCSTR pszOID,
  4005.     IN DWORD dwFlags,
  4006.     IN void *pvArg,
  4007.     IN PFN_CRYPT_ENUM_OID_FUNC pfnEnumOIDFunc
  4008.     );
  4009.  
  4010. #define CRYPT_MATCH_ANY_ENCODING_TYPE   0xFFFFFFFF
  4011.  
  4012.  
  4013. //+=========================================================================
  4014. //  Object IDentifier (OID) Information:  Data Structures and APIs
  4015. //==========================================================================
  4016.  
  4017. //+-------------------------------------------------------------------------
  4018. //  OID Information
  4019. //--------------------------------------------------------------------------
  4020. typedef struct _CRYPT_OID_INFO {
  4021.     DWORD           cbSize;
  4022.     LPCSTR          pszOID;
  4023.     LPCWSTR         pwszName;
  4024.     DWORD           dwGroupId;
  4025.     union {
  4026.         DWORD       dwValue;
  4027.         ALG_ID      Algid;
  4028.         DWORD       dwLength;
  4029.     };
  4030.     CRYPT_DATA_BLOB ExtraInfo;
  4031. } CRYPT_OID_INFO, *PCRYPT_OID_INFO;
  4032. typedef const CRYPT_OID_INFO CCRYPT_OID_INFO, *PCCRYPT_OID_INFO;
  4033.  
  4034. //+-------------------------------------------------------------------------
  4035. //  OID Group IDs
  4036. //--------------------------------------------------------------------------
  4037. #define CRYPT_HASH_ALG_OID_GROUP_ID             1
  4038. #define CRYPT_ENCRYPT_ALG_OID_GROUP_ID          2
  4039. #define CRYPT_PUBKEY_ALG_OID_GROUP_ID           3
  4040. #define CRYPT_SIGN_ALG_OID_GROUP_ID             4
  4041. #define CRYPT_RDN_ATTR_OID_GROUP_ID             5
  4042. #define CRYPT_EXT_OR_ATTR_OID_GROUP_ID          6
  4043. #define CRYPT_ENHKEY_USAGE_OID_GROUP_ID         7
  4044. #define CRYPT_POLICY_OID_GROUP_ID               8
  4045. #define CRYPT_LAST_OID_GROUP_ID                 8
  4046.  
  4047. #define CRYPT_FIRST_ALG_OID_GROUP_ID            CRYPT_HASH_ALG_OID_GROUP_ID
  4048. #define CRYPT_LAST_ALG_OID_GROUP_ID             CRYPT_SIGN_ALG_OID_GROUP_ID
  4049.  
  4050.  
  4051. // The CRYPT_*_ALG_OID_GROUP_ID's have an Algid. The CRYPT_RDN_ATTR_OID_GROUP_ID
  4052. // has a dwLength. The CRYPT_EXT_OR_ATTR_OID_GROUP_ID,
  4053. // CRYPT_ENHKEY_USAGE_OID_GROUP_ID or CRYPT_POLICY_OID_GROUP_ID don't have a
  4054. // dwValue.
  4055. //
  4056.  
  4057. // CRYPT_PUBKEY_ALG_OID_GROUP_ID has the following optional ExtraInfo:
  4058. //  DWORD[0] - Flags. CRYPT_OID_INHIBIT_SIGNATURE_FORMAT_FLAG can be set to
  4059. //             inhibit the reformatting of the signature before
  4060. //             CryptVerifySignature is called or after CryptSignHash
  4061. //             is called. CRYPT_OID_USE_PUBKEY_PARA_FOR_PKCS7_FLAG can
  4062. //             be set to include the public key algorithm's parameters
  4063. //             in the PKCS7's digestEncryptionAlgorithm's parameters.
  4064. //             CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG can be set to omit
  4065. //             NULL parameters when encoding.
  4066.  
  4067. #define CRYPT_OID_INHIBIT_SIGNATURE_FORMAT_FLAG     0x1
  4068. #define CRYPT_OID_USE_PUBKEY_PARA_FOR_PKCS7_FLAG    0x2
  4069. #define CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG       0x4
  4070.  
  4071. // CRYPT_SIGN_ALG_OID_GROUP_ID has the following optional ExtraInfo:
  4072. //  DWORD[0] - Public Key Algid.
  4073. //  DWORD[1] - Flags. Same as above for CRYPT_PUBKEY_ALG_OID_GROUP_ID.
  4074. //  DWORD[2] - Optional CryptAcquireContext(CRYPT_VERIFYCONTEXT)'s dwProvType.
  4075. //             If omitted or 0, uses Public Key Algid to select
  4076. //             appropriate dwProvType for signature verification.
  4077.  
  4078. // CRYPT_RDN_ATTR_OID_GROUP_ID has the following optional ExtraInfo:
  4079. //  Array of DWORDs:
  4080. //   [0 ..] - Null terminated list of acceptable RDN attribute
  4081. //            value types. An empty list implies CERT_RDN_PRINTABLE_STRING,
  4082. //            CERT_RDN_UNICODE_STRING, 0.
  4083.  
  4084. //+-------------------------------------------------------------------------
  4085. //  Find OID information. Returns NULL if unable to find any information
  4086. //  for the specified key and group. Note, returns a pointer to a constant
  4087. //  data structure. The returned pointer MUST NOT be freed.
  4088. //
  4089. //  dwKeyType's:
  4090. //    CRYPT_OID_INFO_OID_KEY, pvKey points to a szOID
  4091. //    CRYPT_OID_INFO_NAME_KEY, pvKey points to a wszName
  4092. //    CRYPT_OID_INFO_ALGID_KEY, pvKey points to an ALG_ID
  4093. //    CRYPT_OID_INFO_SIGN_KEY, pvKey points to an array of two ALG_ID's:
  4094. //      ALG_ID[0] - Hash Algid
  4095. //      ALG_ID[1] - PubKey Algid
  4096. //
  4097. //  Setting dwGroupId to 0, searches all groups according to the dwKeyType.
  4098. //  Otherwise, only the dwGroupId is searched.
  4099. //--------------------------------------------------------------------------
  4100. WINCRYPT32API
  4101. PCCRYPT_OID_INFO
  4102. WINAPI
  4103. CryptFindOIDInfo(
  4104.     IN DWORD dwKeyType,
  4105.     IN void *pvKey,
  4106.     IN DWORD dwGroupId
  4107.     );
  4108.  
  4109. #define CRYPT_OID_INFO_OID_KEY           1
  4110. #define CRYPT_OID_INFO_NAME_KEY          2
  4111. #define CRYPT_OID_INFO_ALGID_KEY         3
  4112. #define CRYPT_OID_INFO_SIGN_KEY          4
  4113.  
  4114. //+-------------------------------------------------------------------------
  4115. //  Register OID information. The OID information specified in the
  4116. //  CCRYPT_OID_INFO structure is persisted to the registry.
  4117. //
  4118. //  crypt32.dll contains information for the commonly known OIDs. This function
  4119. //  allows applications to augment crypt32.dll's OID information. During
  4120. //  CryptFindOIDInfo's first call, the registered OID information is installed.
  4121. //
  4122. //  By default the registered OID information is installed after crypt32.dll's
  4123. //  OID entries. Set CRYPT_INSTALL_OID_INFO_BEFORE_FLAG to install before.
  4124. //--------------------------------------------------------------------------
  4125. WINCRYPT32API
  4126. BOOL
  4127. WINAPI
  4128. CryptRegisterOIDInfo(
  4129.     IN PCCRYPT_OID_INFO pInfo,
  4130.     IN DWORD dwFlags
  4131.     );
  4132.  
  4133. #define CRYPT_INSTALL_OID_INFO_BEFORE_FLAG  1
  4134.  
  4135. //+-------------------------------------------------------------------------
  4136. //  Unregister OID information. Only the pszOID and dwGroupId fields are
  4137. //  used to identify the OID information to be unregistered.
  4138. //--------------------------------------------------------------------------
  4139. WINCRYPT32API
  4140. BOOL
  4141. WINAPI
  4142. CryptUnregisterOIDInfo(
  4143.     IN PCCRYPT_OID_INFO pInfo
  4144.     );
  4145.  
  4146. // If the callback returns FALSE, stops the enumeration.
  4147. typedef BOOL (WINAPI *PFN_CRYPT_ENUM_OID_INFO)(
  4148.     IN PCCRYPT_OID_INFO pInfo,
  4149.     IN void *pvArg
  4150.     );
  4151.  
  4152. //+-------------------------------------------------------------------------
  4153. //  Enumerate the OID information.
  4154. //
  4155. //  pfnEnumOIDInfo is called for each OID information entry.
  4156. //
  4157. //  Setting dwGroupId to 0 matches all groups. Otherwise, only enumerates
  4158. //  entries in the specified group.
  4159. //
  4160. //  dwFlags currently isn't used and must be set to 0.
  4161. //--------------------------------------------------------------------------
  4162. WINCRYPT32API
  4163. BOOL
  4164. WINAPI
  4165. CryptEnumOIDInfo(
  4166.     IN DWORD dwGroupId,
  4167.     IN DWORD dwFlags,
  4168.     IN void *pvArg,
  4169.     IN PFN_CRYPT_ENUM_OID_INFO pfnEnumOIDInfo
  4170.     );
  4171.  
  4172. //+-------------------------------------------------------------------------
  4173. //  Find the localized name for the specified name. For example, find the
  4174. //  localized name for the "Root" system store name. A case insensitive
  4175. //  string comparison is done.
  4176. //
  4177. //  Returns NULL if unable to find the the specified name.
  4178. //
  4179. //  Localized names for the predefined system stores ("Root", "My") and
  4180. //  predefined physical stores (".Default", ".LocalMachine") are pre-installed
  4181. //  as resource strings in crypt32.dll. CryptSetOIDFunctionValue can be called
  4182. //  as follows to register additional localized strings:
  4183. //      dwEncodingType = CRYPT_LOCALIZED_NAME_ENCODING_TYPE
  4184. //      pszFuncName = CRYPT_OID_FIND_LOCALIZED_NAME_FUNC
  4185. //      pszOID = CRYPT_LOCALIZED_NAME_OID
  4186. //      pwszValueName = Name to be localized, for example, L"ApplicationStore"
  4187. //      dwValueType = REG_SZ
  4188. //      pbValueData = pointer to the UNICODE localized string
  4189. //      cbValueData = (wcslen(UNICODE localized string) + 1) * sizeof(WCHAR)
  4190. //
  4191. //  To unregister, set pbValueData to NULL and cbValueData to 0.
  4192. //
  4193. //  The registered names are searched before the pre-installed names.
  4194. //--------------------------------------------------------------------------
  4195. WINCRYPT32API
  4196. LPCWSTR
  4197. WINAPI
  4198. CryptFindLocalizedName(
  4199.     IN LPCWSTR pwszCryptName
  4200.     );
  4201.  
  4202. #define CRYPT_LOCALIZED_NAME_ENCODING_TYPE  0
  4203. #define CRYPT_LOCALIZED_NAME_OID            "LocalizedNames"
  4204.  
  4205. //+=========================================================================
  4206. //  Low Level Cryptographic Message Data Structures and APIs
  4207. //==========================================================================
  4208.  
  4209. typedef void *HCRYPTMSG;
  4210.  
  4211. #define szOID_PKCS_7_DATA               "1.2.840.113549.1.7.1"
  4212. #define szOID_PKCS_7_SIGNED             "1.2.840.113549.1.7.2"
  4213. #define szOID_PKCS_7_ENVELOPED          "1.2.840.113549.1.7.3"
  4214. #define szOID_PKCS_7_SIGNEDANDENVELOPED "1.2.840.113549.1.7.4"
  4215. #define szOID_PKCS_7_DIGESTED           "1.2.840.113549.1.7.5"
  4216. #define szOID_PKCS_7_ENCRYPTED          "1.2.840.113549.1.7.6"
  4217.  
  4218. #define szOID_PKCS_9_CONTENT_TYPE       "1.2.840.113549.1.9.3"
  4219. #define szOID_PKCS_9_MESSAGE_DIGEST     "1.2.840.113549.1.9.4"
  4220.  
  4221. //+-------------------------------------------------------------------------
  4222. //  Message types
  4223. //--------------------------------------------------------------------------
  4224. #define CMSG_DATA                    1
  4225. #define CMSG_SIGNED                  2
  4226. #define CMSG_ENVELOPED               3
  4227. #define CMSG_SIGNED_AND_ENVELOPED    4
  4228. #define CMSG_HASHED                  5
  4229. #define CMSG_ENCRYPTED               6
  4230.  
  4231. //+-------------------------------------------------------------------------
  4232. //  Message Type Bit Flags
  4233. //--------------------------------------------------------------------------
  4234. #define CMSG_ALL_FLAGS                   (~0UL)
  4235. #define CMSG_DATA_FLAG                   (1 << CMSG_DATA)
  4236. #define CMSG_SIGNED_FLAG                 (1 << CMSG_SIGNED)
  4237. #define CMSG_ENVELOPED_FLAG              (1 << CMSG_ENVELOPED)
  4238. #define CMSG_SIGNED_AND_ENVELOPED_FLAG   (1 << CMSG_SIGNED_AND_ENVELOPED)
  4239. #define CMSG_HASHED_FLAG                 (1 << CMSG_HASHED)
  4240. #define CMSG_ENCRYPTED_FLAG              (1 << CMSG_ENCRYPTED)
  4241.  
  4242.  
  4243. //+-------------------------------------------------------------------------
  4244. //  Certificate Issuer and SerialNumber
  4245. //--------------------------------------------------------------------------
  4246. typedef struct _CERT_ISSUER_SERIAL_NUMBER {
  4247.     CERT_NAME_BLOB      Issuer;
  4248.     CRYPT_INTEGER_BLOB  SerialNumber;
  4249. } CERT_ISSUER_SERIAL_NUMBER, *PCERT_ISSUER_SERIAL_NUMBER;
  4250.  
  4251. //+-------------------------------------------------------------------------
  4252. //  Certificate Identifier
  4253. //--------------------------------------------------------------------------
  4254. typedef struct _CERT_ID {
  4255.     DWORD   dwIdChoice;
  4256.     union {
  4257.         // CERT_ID_ISSUER_SERIAL_NUMBER
  4258.         CERT_ISSUER_SERIAL_NUMBER   IssuerSerialNumber;
  4259.         // CERT_ID_KEY_IDENTIFIER
  4260.         CRYPT_HASH_BLOB             KeyId;
  4261.         // CERT_ID_SHA1_HASH
  4262.         CRYPT_HASH_BLOB             HashId;
  4263.     };
  4264. } CERT_ID, *PCERT_ID;
  4265.  
  4266. #define CERT_ID_ISSUER_SERIAL_NUMBER    1
  4267. #define CERT_ID_KEY_IDENTIFIER          2
  4268. #define CERT_ID_SHA1_HASH               3
  4269.  
  4270.  
  4271. //+-------------------------------------------------------------------------
  4272. //  The message encode information (pvMsgEncodeInfo) is message type dependent
  4273. //--------------------------------------------------------------------------
  4274.  
  4275. //+-------------------------------------------------------------------------
  4276. //  CMSG_DATA: pvMsgEncodeInfo = NULL
  4277. //--------------------------------------------------------------------------
  4278.  
  4279. //+-------------------------------------------------------------------------
  4280. //  CMSG_SIGNED
  4281. //
  4282. //  The pCertInfo in the CMSG_SIGNER_ENCODE_INFO provides the Issuer, SerialNumber
  4283. //  and PublicKeyInfo.Algorithm. The PublicKeyInfo.Algorithm implicitly
  4284. //  specifies the HashEncryptionAlgorithm to be used.
  4285. //
  4286. //  If the SignerId is present with a nonzero dwIdChoice its used instead
  4287. //  of the Issuer and SerialNumber in pCertInfo.
  4288. //
  4289. //  CMS supports the KEY_IDENTIFIER and ISSUER_SERIAL_NUMBER CERT_IDs. PKCS #7
  4290. //  version 1.5 only supports the ISSUER_SERIAL_NUMBER CERT_ID choice.
  4291. //
  4292. //  If HashEncryptionAlgorithm is present and not NULL its used instead of
  4293. //  the PublicKeyInfo.Algorithm.
  4294. //
  4295. //  Note, for RSA, the hash encryption algorithm is normally the same as
  4296. //  the public key algorithm. For DSA, the hash encryption algorithm is
  4297. //  normally a DSS signature algorithm.
  4298. //
  4299. //  pvHashEncryptionAuxInfo currently isn't used and must be set to NULL if
  4300. //  present in the data structure.
  4301. //
  4302. //  The hCryptProv and dwKeySpec specify the private key to use. If dwKeySpec
  4303. //  == 0, then, defaults to AT_SIGNATURE.
  4304. //
  4305. //  If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  4306. //  passed to CryptMsgOpenToEncode(), the signer hCryptProv's are released.
  4307. //
  4308. //  pvHashAuxInfo currently isn't used and must be set to NULL.
  4309. //
  4310. //  CMS signed messages allow the inclusion of Attribute Certs.
  4311. //--------------------------------------------------------------------------
  4312. typedef struct _CMSG_SIGNER_ENCODE_INFO {
  4313.     DWORD                       cbSize;
  4314.     PCERT_INFO                  pCertInfo;
  4315.     HCRYPTPROV                  hCryptProv;
  4316.     DWORD                       dwKeySpec;
  4317.     CRYPT_ALGORITHM_IDENTIFIER  HashAlgorithm;
  4318.     void                        *pvHashAuxInfo;
  4319.     DWORD                       cAuthAttr;
  4320.     PCRYPT_ATTRIBUTE            rgAuthAttr;
  4321.     DWORD                       cUnauthAttr;
  4322.     PCRYPT_ATTRIBUTE            rgUnauthAttr;
  4323.  
  4324. #ifdef CMSG_SIGNER_ENCODE_INFO_HAS_CMS_FIELDS
  4325.     CERT_ID                     SignerId;
  4326.     CRYPT_ALGORITHM_IDENTIFIER  HashEncryptionAlgorithm;
  4327.     void                        *pvHashEncryptionAuxInfo;
  4328. #endif
  4329. } CMSG_SIGNER_ENCODE_INFO, *PCMSG_SIGNER_ENCODE_INFO;
  4330.  
  4331. typedef struct _CMSG_SIGNED_ENCODE_INFO {
  4332.     DWORD                       cbSize;
  4333.     DWORD                       cSigners;
  4334.     PCMSG_SIGNER_ENCODE_INFO    rgSigners;
  4335.     DWORD                       cCertEncoded;
  4336.     PCERT_BLOB                  rgCertEncoded;
  4337.     DWORD                       cCrlEncoded;
  4338.     PCRL_BLOB                   rgCrlEncoded;
  4339.  
  4340. #ifdef CMSG_SIGNED_ENCODE_INFO_HAS_CMS_FIELDS
  4341.     DWORD                       cAttrCertEncoded;
  4342.     PCERT_BLOB                  rgAttrCertEncoded;
  4343. #endif
  4344. } CMSG_SIGNED_ENCODE_INFO, *PCMSG_SIGNED_ENCODE_INFO;
  4345.  
  4346. //+-------------------------------------------------------------------------
  4347. //  CMSG_ENVELOPED
  4348. //
  4349. //  The PCERT_INFO for the rgRecipients provides the Issuer, SerialNumber
  4350. //  and PublicKeyInfo. The PublicKeyInfo.Algorithm implicitly
  4351. //  specifies the KeyEncryptionAlgorithm to be used.
  4352. //
  4353. //  The PublicKeyInfo.PublicKey in PCERT_INFO is used to encrypt the content
  4354. //  encryption key for the recipient.
  4355. //
  4356. //  hCryptProv is used to do the content encryption, recipient key encryption
  4357. //  and export. The hCryptProv's private keys aren't used. If hCryptProv
  4358. //  is NULL, a default hCryptProv is chosen according to the
  4359. //  ContentEncryptionAlgorithm and the first recipient KeyEncryptionAlgorithm.
  4360. //
  4361. //  If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  4362. //  passed to CryptMsgOpenToEncode(), the envelope's hCryptProv is released.
  4363. //
  4364. //  Note: CAPI currently doesn't support more than one KeyEncryptionAlgorithm
  4365. //  per provider. This will need to be fixed.
  4366. //
  4367. //  Currently, pvEncryptionAuxInfo is only defined for RC2 or RC4 encryption
  4368. //  algorithms. Otherwise, its not used and must be set to NULL.
  4369. //  See CMSG_RC2_AUX_INFO for the RC2 encryption algorithms.
  4370. //  See CMSG_RC4_AUX_INFO for the RC4 encryption algorithms.
  4371. //
  4372. //  To enable SP3 compatible encryption, pvEncryptionAuxInfo should point to
  4373. //  a CMSG_SP3_COMPATIBLE_AUX_INFO data structure.
  4374. //
  4375. //  To enable the CMS envelope enhancements, rgpRecipients must be set to
  4376. //  NULL, and rgCmsRecipients updated to point to an array of
  4377. //  CMSG_RECIPIENT_ENCODE_INFO's.
  4378. //
  4379. //  Also, CMS envelope enhancements support the inclusion of a bag of
  4380. //  Certs, CRLs, Attribute Certs and/or Unprotected Attributes.
  4381. //--------------------------------------------------------------------------
  4382. typedef struct _CMSG_RECIPIENT_ENCODE_INFO CMSG_RECIPIENT_ENCODE_INFO,
  4383.     *PCMSG_RECIPIENT_ENCODE_INFO;
  4384.  
  4385. typedef struct _CMSG_ENVELOPED_ENCODE_INFO {
  4386.     DWORD                       cbSize;
  4387.     HCRYPTPROV                  hCryptProv;
  4388.     CRYPT_ALGORITHM_IDENTIFIER  ContentEncryptionAlgorithm;
  4389.     void                        *pvEncryptionAuxInfo;
  4390.     DWORD                       cRecipients;
  4391.  
  4392.     // The following array may only be used for transport recipients identified
  4393.     // by their IssuereAndSerialNumber. If rgpRecipients != NULL, then,
  4394.     // the rgCmsRecipients must be NULL.
  4395.     PCERT_INFO                  *rgpRecipients;
  4396.  
  4397. #ifdef CMSG_ENVELOPED_ENCODE_INFO_HAS_CMS_FIELDS
  4398.     // If rgCmsRecipients != NULL, then, the above rgpRecipients must be
  4399.     // NULL.
  4400.     PCMSG_RECIPIENT_ENCODE_INFO rgCmsRecipients;
  4401.     DWORD                       cCertEncoded;
  4402.     PCERT_BLOB                  rgCertEncoded;
  4403.     DWORD                       cCrlEncoded;
  4404.     PCRL_BLOB                   rgCrlEncoded;
  4405.     DWORD                       cAttrCertEncoded;
  4406.     PCERT_BLOB                  rgAttrCertEncoded;
  4407.     DWORD                       cUnprotectedAttr;
  4408.     PCRYPT_ATTRIBUTE            rgUnprotectedAttr;
  4409. #endif
  4410. } CMSG_ENVELOPED_ENCODE_INFO, *PCMSG_ENVELOPED_ENCODE_INFO;
  4411.  
  4412.  
  4413.  
  4414. //+-------------------------------------------------------------------------
  4415. //  Key Transport Recipient Encode Info
  4416. //
  4417. //  hCryptProv is used to do the recipient key encryption
  4418. //  and export. The hCryptProv's private keys aren't used.
  4419. //
  4420. //  If hCryptProv is NULL, then, the hCryptProv specified in
  4421. //  CMSG_ENVELOPED_ENCODE_INFO is used.
  4422. //
  4423. //  Note, even if CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  4424. //  passed to CryptMsgOpenToEncode(), this hCryptProv isn't released.
  4425. //
  4426. //  CMS supports the KEY_IDENTIFIER and ISSUER_SERIAL_NUMBER CERT_IDs. PKCS #7
  4427. //  version 1.5 only supports the ISSUER_SERIAL_NUMBER CERT_ID choice.
  4428. //--------------------------------------------------------------------------
  4429. typedef struct _CMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO {
  4430.     DWORD                       cbSize;
  4431.     CRYPT_ALGORITHM_IDENTIFIER  KeyEncryptionAlgorithm;
  4432.     void                        *pvKeyEncryptionAuxInfo;
  4433.     HCRYPTPROV                  hCryptProv;
  4434.     CRYPT_BIT_BLOB              RecipientPublicKey;
  4435.     CERT_ID                     RecipientId;
  4436. } CMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO, *PCMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO;
  4437.  
  4438.  
  4439. //+-------------------------------------------------------------------------
  4440. //  Key Agreement Recipient Encode Info
  4441. //
  4442. //  If hCryptProv is NULL, then, the hCryptProv specified in
  4443. //  CMSG_ENVELOPED_ENCODE_INFO is used.
  4444. //
  4445. //  For the CMSG_KEY_AGREE_STATIC_KEY_CHOICE, both the hCryptProv and
  4446. //  dwKeySpec must be specified to select the sender's private key.
  4447. //
  4448. //  Note, even if CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  4449. //  passed to CryptMsgOpenToEncode(), this hCryptProv isn't released.
  4450. //
  4451. //  CMS supports the KEY_IDENTIFIER and ISSUER_SERIAL_NUMBER CERT_IDs.
  4452. //
  4453. //  There is 1 key choice, ephemeral originator. The originator's ephemeral
  4454. //  key is generated using the public key algorithm parameters shared
  4455. //  amongst all the recipients.
  4456. //
  4457. //  There are 2 key choices: ephemeral originator or static sender. The
  4458. //  originator's ephemeral key is generated using the public key algorithm
  4459. //  parameters shared amongst all the recipients. For the static sender its
  4460. //  private key is used. The hCryptProv and dwKeySpec specify the private key.
  4461. //  The pSenderId identifies the certificate containing the sender's public key.
  4462. //
  4463. //  Currently, pvKeyEncryptionAuxInfo isn't used and must be set to NULL. 
  4464. //
  4465. //  If KeyEncryptionAlgorithm.Parameters.cbData == 0, then, its Parameters
  4466. //  are updated with the encoded KeyWrapAlgorithm.
  4467. //
  4468. //  Currently, pvKeyWrapAuxInfo is only defined for algorithms with
  4469. //  RC2. Otherwise, its not used and must be set to NULL.
  4470. //  When set for RC2 algorithms, points to a CMSG_RC2_AUX_INFO containing
  4471. //  the RC2 effective key length.
  4472. //
  4473. //  Note, key agreement recipients are not supported in PKCS #7 version 1.5.
  4474. //--------------------------------------------------------------------------
  4475. typedef struct _CMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO {
  4476.     DWORD                       cbSize;
  4477.     CRYPT_BIT_BLOB              RecipientPublicKey;
  4478.     CERT_ID                     RecipientId;
  4479.  
  4480.     // Following fields are optional and only applicable to KEY_IDENTIFIER
  4481.     // CERT_IDs.
  4482.     FILETIME                    Date;
  4483.     PCRYPT_ATTRIBUTE_TYPE_VALUE pOtherAttr;
  4484. } CMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO,
  4485.     *PCMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO;
  4486.  
  4487. typedef struct _CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO {
  4488.     DWORD                       cbSize;
  4489.     CRYPT_ALGORITHM_IDENTIFIER  KeyEncryptionAlgorithm;
  4490.     void                        *pvKeyEncryptionAuxInfo;
  4491.     CRYPT_ALGORITHM_IDENTIFIER  KeyWrapAlgorithm;
  4492.     void                        *pvKeyWrapAuxInfo;
  4493.  
  4494.     // The following hCryptProv and dwKeySpec must be specified for the
  4495.     // CMSG_KEY_AGREE_STATIC_KEY_CHOICE.
  4496.     //
  4497.     // For CMSG_KEY_AGREE_EPHEMERAL_KEY_CHOICE, dwKeySpec isn't applicable
  4498.     // and hCryptProv is optional.
  4499.     HCRYPTPROV                  hCryptProv;
  4500.     DWORD                       dwKeySpec;
  4501.  
  4502.     DWORD                       dwKeyChoice;
  4503.     union {
  4504.         // CMSG_KEY_AGREE_EPHEMERAL_KEY_CHOICE
  4505.         //
  4506.         // The ephemeral public key algorithm and parameters.
  4507.         PCRYPT_ALGORITHM_IDENTIFIER pEphemeralAlgorithm;
  4508.  
  4509.         // CMSG_KEY_AGREE_STATIC_KEY_CHOICE
  4510.         //
  4511.         // The CertId of the sender's certificate
  4512.         PCERT_ID                    pSenderId;
  4513.     };
  4514.     CRYPT_DATA_BLOB             UserKeyingMaterial;     // OPTIONAL
  4515.  
  4516.     DWORD                                       cRecipientEncryptedKeys;
  4517.     PCMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO   *rgpRecipientEncryptedKeys;
  4518. } CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO, *PCMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO;
  4519.  
  4520. #define CMSG_KEY_AGREE_EPHEMERAL_KEY_CHOICE         1
  4521. #define CMSG_KEY_AGREE_STATIC_KEY_CHOICE            2
  4522.  
  4523. //+-------------------------------------------------------------------------
  4524. //  Mail List Recipient Encode Info
  4525. //
  4526. //  There is 1 choice for the KeyEncryptionKey: an already created CSP key
  4527. //  handle. For the key handle choice, hCryptProv must be nonzero. This key
  4528. //  handle isn't destroyed.
  4529. //
  4530. //  Note, even if CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  4531. //  passed to CryptMsgOpenToEncode(), this hCryptProv isn't released.
  4532. //
  4533. //  Currently, pvKeyEncryptionAuxInfo is only defined for RC2 key wrap
  4534. //  algorithms. Otherwise, its not used and must be set to NULL.
  4535. //  When set for RC2 algorithms, points to a CMSG_RC2_AUX_INFO containing
  4536. //  the RC2 effective key length.
  4537. //
  4538. //  Note, mail list recipients are not supported in PKCS #7 version 1.5.
  4539. //--------------------------------------------------------------------------
  4540. typedef struct _CMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO {
  4541.     DWORD                       cbSize;
  4542.     CRYPT_ALGORITHM_IDENTIFIER  KeyEncryptionAlgorithm;
  4543.     void                        *pvKeyEncryptionAuxInfo;
  4544.     HCRYPTPROV                  hCryptProv;
  4545.     DWORD                       dwKeyChoice;
  4546.     union {
  4547.         // CMSG_MAIL_LIST_HANDLE_KEY_CHOICE
  4548.         HCRYPTKEY                   hKeyEncryptionKey;
  4549.         // Reserve space for a potential pointer choice
  4550.         void                        *pvKeyEncryptionKey;
  4551.     };
  4552.     CRYPT_DATA_BLOB             KeyId;
  4553.  
  4554.     // Following fields are optional.
  4555.     FILETIME                    Date;
  4556.     PCRYPT_ATTRIBUTE_TYPE_VALUE pOtherAttr;
  4557. } CMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO, *PCMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO;
  4558.  
  4559. #define CMSG_MAIL_LIST_HANDLE_KEY_CHOICE    1
  4560.  
  4561. //+-------------------------------------------------------------------------
  4562. //  Recipient Encode Info
  4563. //
  4564. //  Note, only key transport recipients are supported in PKCS #7 version 1.5.
  4565. //--------------------------------------------------------------------------
  4566. struct _CMSG_RECIPIENT_ENCODE_INFO {
  4567.     DWORD   dwRecipientChoice;
  4568.     union {
  4569.         // CMSG_KEY_TRANS_RECIPIENT
  4570.         PCMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO   pKeyTrans;
  4571.         // CMSG_KEY_AGREE_RECIPIENT
  4572.         PCMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO   pKeyAgree;
  4573.         // CMSG_MAIL_LIST_RECIPIENT
  4574.         PCMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO   pMailList;
  4575.     };
  4576. };
  4577.  
  4578.  
  4579. #define CMSG_KEY_TRANS_RECIPIENT         1
  4580. #define CMSG_KEY_AGREE_RECIPIENT         2
  4581. #define CMSG_MAIL_LIST_RECIPIENT         3
  4582.  
  4583.  
  4584. //+-------------------------------------------------------------------------
  4585. //  CMSG_RC2_AUX_INFO
  4586. //
  4587. //  AuxInfo for RC2 encryption algorithms. The pvEncryptionAuxInfo field
  4588. //  in CMSG_ENCRYPTED_ENCODE_INFO should be updated to point to this
  4589. //  structure. If not specified, defaults to 40 bit.
  4590. //
  4591. //  Note, this AuxInfo is only used when, the ContentEncryptionAlgorithm's
  4592. //  Parameter.cbData is zero. Otherwise, the Parameters is decoded to
  4593. //  get the bit length.
  4594. //
  4595. //  If CMSG_SP3_COMPATIBLE_ENCRYPT_FLAG is set in dwBitLen, then, SP3
  4596. //  compatible encryption is done and the bit length is ignored.
  4597. //--------------------------------------------------------------------------
  4598. typedef struct _CMSG_RC2_AUX_INFO {
  4599.     DWORD                       cbSize;
  4600.     DWORD                       dwBitLen;
  4601. } CMSG_RC2_AUX_INFO, *PCMSG_RC2_AUX_INFO;
  4602.  
  4603. //+-------------------------------------------------------------------------
  4604. //  CMSG_SP3_COMPATIBLE_AUX_INFO
  4605. //
  4606. //  AuxInfo for enabling SP3 compatible encryption.
  4607. //
  4608. //  The CMSG_SP3_COMPATIBLE_ENCRYPT_FLAG is set in dwFlags to enable SP3
  4609. //  compatible encryption. When set, uses zero salt instead of no salt,
  4610. //  the encryption algorithm parameters are NULL instead of containing the
  4611. //  encoded RC2 parameters or encoded IV octet string and the encrypted
  4612. //  symmetric key is encoded little endian instead of big endian.
  4613. //--------------------------------------------------------------------------
  4614. typedef struct _CMSG_SP3_COMPATIBLE_AUX_INFO {
  4615.     DWORD                       cbSize;
  4616.     DWORD                       dwFlags;
  4617. } CMSG_SP3_COMPATIBLE_AUX_INFO, *PCMSG_SP3_COMPATIBLE_AUX_INFO;
  4618.  
  4619. #define CMSG_SP3_COMPATIBLE_ENCRYPT_FLAG    0x80000000
  4620.  
  4621. //+-------------------------------------------------------------------------
  4622. //  CMSG_RC4_AUX_INFO
  4623. //
  4624. //  AuxInfo for RC4 encryption algorithms. The pvEncryptionAuxInfo field
  4625. //  in CMSG_ENCRYPTED_ENCODE_INFO should be updated to point to this
  4626. //  structure. If not specified, uses the CSP's default bit length with no
  4627. //  salt. Note, the base CSP has a 40 bit default and the enhanced CSP has
  4628. //  a 128 bit default.
  4629. //
  4630. //  If CMSG_RC4_NO_SALT_FLAG is set in dwBitLen, then, no salt is generated.
  4631. //  Otherwise, (128 - dwBitLen)/8 bytes of salt are generated and encoded
  4632. //  as an OCTET STRING in the algorithm parameters field.
  4633. //--------------------------------------------------------------------------
  4634. typedef struct _CMSG_RC4_AUX_INFO {
  4635.     DWORD                       cbSize;
  4636.     DWORD                       dwBitLen;
  4637. } CMSG_RC4_AUX_INFO, *PCMSG_RC4_AUX_INFO;
  4638.  
  4639. #define CMSG_RC4_NO_SALT_FLAG               0x40000000
  4640.  
  4641. //+-------------------------------------------------------------------------
  4642. //  CMSG_SIGNED_AND_ENVELOPED
  4643. //
  4644. //  For PKCS #7, a signed and enveloped message doesn't have the
  4645. //  signer's authenticated or unauthenticated attributes. Otherwise, a
  4646. //  combination of the CMSG_SIGNED_ENCODE_INFO and CMSG_ENVELOPED_ENCODE_INFO.
  4647. //--------------------------------------------------------------------------
  4648. typedef struct _CMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO {
  4649.     DWORD                       cbSize;
  4650.     CMSG_SIGNED_ENCODE_INFO     SignedInfo;
  4651.     CMSG_ENVELOPED_ENCODE_INFO  EnvelopedInfo;
  4652. } CMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO, *PCMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO;
  4653.  
  4654. //+-------------------------------------------------------------------------
  4655. //  CMSG_HASHED
  4656. //
  4657. //  hCryptProv is used to do the hash. Doesn't need to use a private key.
  4658. //
  4659. //  If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  4660. //  passed to CryptMsgOpenToEncode(), the hCryptProv is released.
  4661. //
  4662. //  If fDetachedHash is set, then, the encoded message doesn't contain
  4663. //  any content (its treated as NULL Data)
  4664. //
  4665. //  pvHashAuxInfo currently isn't used and must be set to NULL.
  4666. //--------------------------------------------------------------------------
  4667. typedef struct _CMSG_HASHED_ENCODE_INFO {
  4668.     DWORD                       cbSize;
  4669.     HCRYPTPROV                  hCryptProv;
  4670.     CRYPT_ALGORITHM_IDENTIFIER  HashAlgorithm;
  4671.     void                        *pvHashAuxInfo;
  4672. } CMSG_HASHED_ENCODE_INFO, *PCMSG_HASHED_ENCODE_INFO;
  4673.  
  4674. //+-------------------------------------------------------------------------
  4675. //  CMSG_ENCRYPTED
  4676. //
  4677. //  The key used to encrypt the message is identified outside of the message
  4678. //  content (for example, password).
  4679. //
  4680. //  The content input to CryptMsgUpdate has already been encrypted.
  4681. //
  4682. //  pvEncryptionAuxInfo currently isn't used and must be set to NULL.
  4683. //--------------------------------------------------------------------------
  4684. typedef struct _CMSG_ENCRYPTED_ENCODE_INFO {
  4685.     DWORD                       cbSize;
  4686.     CRYPT_ALGORITHM_IDENTIFIER  ContentEncryptionAlgorithm;
  4687.     void                        *pvEncryptionAuxInfo;
  4688. } CMSG_ENCRYPTED_ENCODE_INFO, *PCMSG_ENCRYPTED_ENCODE_INFO;
  4689.  
  4690. //+-------------------------------------------------------------------------
  4691. //  This parameter allows messages to be of variable length with streamed
  4692. //  output.
  4693. //
  4694. //  By default, messages are of a definite length and
  4695. //  CryptMsgGetParam(CMSG_CONTENT_PARAM) is
  4696. //  called to get the cryptographically processed content. Until closed,
  4697. //  the handle keeps a copy of the processed content.
  4698. //
  4699. //  With streamed output, the processed content can be freed as its streamed.
  4700. //
  4701. //  If the length of the content to be updated is known at the time of the
  4702. //  open, then, ContentLength should be set to that length. Otherwise, it
  4703. //  should be set to CMSG_INDEFINITE_LENGTH.
  4704. //--------------------------------------------------------------------------
  4705. typedef BOOL (WINAPI *PFN_CMSG_STREAM_OUTPUT)(
  4706.     IN const void *pvArg,
  4707.     IN BYTE *pbData,
  4708.     IN DWORD cbData,
  4709.     IN BOOL fFinal
  4710.     );
  4711.  
  4712. #define CMSG_INDEFINITE_LENGTH       (0xFFFFFFFF)
  4713.  
  4714. typedef struct _CMSG_STREAM_INFO {
  4715.     DWORD                   cbContent;
  4716.     PFN_CMSG_STREAM_OUTPUT  pfnStreamOutput;
  4717.     void                    *pvArg;
  4718. } CMSG_STREAM_INFO, *PCMSG_STREAM_INFO;
  4719.  
  4720. //+-------------------------------------------------------------------------
  4721. //  Open dwFlags
  4722. //--------------------------------------------------------------------------
  4723. #define CMSG_BARE_CONTENT_FLAG              0x00000001
  4724. #define CMSG_LENGTH_ONLY_FLAG               0x00000002
  4725. #define CMSG_DETACHED_FLAG                  0x00000004
  4726. #define CMSG_AUTHENTICATED_ATTRIBUTES_FLAG  0x00000008
  4727. #define CMSG_CONTENTS_OCTETS_FLAG           0x00000010
  4728. #define CMSG_MAX_LENGTH_FLAG                0x00000020
  4729.  
  4730. // When set, nonData type inner content is encapsulated within an
  4731. // OCTET STRING. Applicable to both Signed and Enveloped messages.
  4732. #define CMSG_CMS_ENCAPSULATED_CONTENT_FLAG  0x00000040
  4733.  
  4734. // If set, then, the hCryptProv passed to CryptMsgOpenToEncode or
  4735. // CryptMsgOpenToDecode is released on the final CryptMsgClose.
  4736. // Not released if CryptMsgOpenToEncode or CryptMsgOpenToDecode fails.
  4737. //
  4738. // Note, the envelope recipient hCryptProv's aren't released.
  4739. #define CMSG_CRYPT_RELEASE_CONTEXT_FLAG     0x00008000
  4740.  
  4741. //+-------------------------------------------------------------------------
  4742. //  Open a cryptographic message for encoding
  4743. //
  4744. //  For PKCS #7:
  4745. //  If the content to be passed to CryptMsgUpdate has already
  4746. //  been message encoded (the input to CryptMsgUpdate is the streamed output
  4747. //  from another message encode), then, the CMSG_ENCODED_CONTENT_INFO_FLAG should
  4748. //  be set in dwFlags. If not set, then, the inner ContentType is Data and
  4749. //  the input to CryptMsgUpdate is treated as the inner Data type's Content,
  4750. //  a string of bytes.
  4751. //  If CMSG_BARE_CONTENT_FLAG is specified for a streamed message,
  4752. //  the streamed output will not have an outer ContentInfo wrapper. This
  4753. //  makes it suitable to be streamed into an enclosing message.
  4754. //
  4755. //  The pStreamInfo parameter needs to be set to stream the encoded message
  4756. //  output.
  4757. //--------------------------------------------------------------------------
  4758. WINCRYPT32API
  4759. HCRYPTMSG
  4760. WINAPI
  4761. CryptMsgOpenToEncode(
  4762.     IN DWORD dwMsgEncodingType,
  4763.     IN DWORD dwFlags,
  4764.     IN DWORD dwMsgType,
  4765.     IN void const *pvMsgEncodeInfo,
  4766.     IN OPTIONAL LPSTR pszInnerContentObjID,
  4767.     IN OPTIONAL PCMSG_STREAM_INFO pStreamInfo
  4768.     );
  4769.  
  4770. //+-------------------------------------------------------------------------
  4771. //  Calculate the length of an encoded cryptographic message.
  4772. //
  4773. //  Calculates the length of the encoded message given the
  4774. //  message type, encoding parameters and total length of
  4775. //  the data to be updated. Note, this might not be the exact length. However,
  4776. //  it will always be greater than or equal to the actual length.
  4777. //--------------------------------------------------------------------------
  4778. WINCRYPT32API
  4779. DWORD
  4780. WINAPI
  4781. CryptMsgCalculateEncodedLength(
  4782.     IN DWORD dwMsgEncodingType,
  4783.     IN DWORD dwFlags,
  4784.     IN DWORD dwMsgType,
  4785.     IN void const *pvMsgEncodeInfo,
  4786.     IN OPTIONAL LPSTR pszInnerContentObjID,
  4787.     IN DWORD cbData
  4788.     );
  4789.  
  4790. //+-------------------------------------------------------------------------
  4791. //  Open a cryptographic message for decoding
  4792. //
  4793. //  hCryptProv specifies the crypto provider to use for hashing and/or
  4794. //  decrypting the message. If hCryptProv is NULL, a default crypt provider
  4795. //  is used.
  4796. //
  4797. //  Currently pRecipientInfo isn't used and should be set to NULL.
  4798. //
  4799. //  The pStreamInfo parameter needs to be set to stream the decoded content
  4800. //  output.
  4801. //--------------------------------------------------------------------------
  4802. WINCRYPT32API
  4803. HCRYPTMSG
  4804. WINAPI
  4805. CryptMsgOpenToDecode(
  4806.     IN DWORD dwMsgEncodingType,
  4807.     IN DWORD dwFlags,
  4808.     IN DWORD dwMsgType,
  4809.     IN HCRYPTPROV hCryptProv,
  4810.     IN OPTIONAL PCERT_INFO pRecipientInfo,
  4811.     IN OPTIONAL PCMSG_STREAM_INFO pStreamInfo
  4812.     );
  4813.  
  4814. //+-------------------------------------------------------------------------
  4815. //  Duplicate a cryptographic message handle
  4816. //--------------------------------------------------------------------------
  4817. WINCRYPT32API
  4818. HCRYPTMSG
  4819. WINAPI
  4820. CryptMsgDuplicate(
  4821.     IN HCRYPTMSG hCryptMsg
  4822.     );
  4823.  
  4824. //+-------------------------------------------------------------------------
  4825. //  Close a cryptographic message handle
  4826. //
  4827. //  LastError is preserved unless FALSE is returned.
  4828. //--------------------------------------------------------------------------
  4829. WINCRYPT32API
  4830. BOOL
  4831. WINAPI
  4832. CryptMsgClose(
  4833.     IN HCRYPTMSG hCryptMsg
  4834.     );
  4835.  
  4836. //+-------------------------------------------------------------------------
  4837. //  Update the content of a cryptographic message. Depending on how the
  4838. //  message was opened, the content is either encoded or decoded.
  4839. //
  4840. //  This function is repetitively called to append to the message content.
  4841. //  fFinal is set to identify the last update. On fFinal, the encode/decode
  4842. //  is completed. The encoded/decoded content and the decoded parameters
  4843. //  are valid until the open and all duplicated handles are closed.
  4844. //--------------------------------------------------------------------------
  4845. WINCRYPT32API
  4846. BOOL
  4847. WINAPI
  4848. CryptMsgUpdate(
  4849.     IN HCRYPTMSG hCryptMsg,
  4850.     IN const BYTE *pbData,
  4851.     IN DWORD cbData,
  4852.     IN BOOL fFinal
  4853.     );
  4854.  
  4855. //+-------------------------------------------------------------------------
  4856. //  Get a parameter after encoding/decoding a cryptographic message. Called
  4857. //  after the final CryptMsgUpdate. Only the CMSG_CONTENT_PARAM and
  4858. //  CMSG_COMPUTED_HASH_PARAM are valid for an encoded message.
  4859. //
  4860. //  For an encoded HASHED message, the CMSG_COMPUTED_HASH_PARAM can be got
  4861. //  before any CryptMsgUpdates to get its length.
  4862. //
  4863. //  The pvData type definition depends on the dwParamType value.
  4864. //
  4865. //  Elements pointed to by fields in the pvData structure follow the
  4866. //  structure. Therefore, *pcbData may exceed the size of the structure.
  4867. //
  4868. //  Upon input, if *pcbData == 0, then, *pcbData is updated with the length
  4869. //  of the data and the pvData parameter is ignored.
  4870. //
  4871. //  Upon return, *pcbData is updated with the length of the data.
  4872. //
  4873. //  The OBJID BLOBs returned in the pvData structures point to
  4874. //  their still encoded representation. The appropriate functions
  4875. //  must be called to decode the information.
  4876. //
  4877. //  See below for a list of the parameters to get.
  4878. //--------------------------------------------------------------------------
  4879. WINCRYPT32API
  4880. BOOL
  4881. WINAPI
  4882. CryptMsgGetParam(
  4883.     IN HCRYPTMSG hCryptMsg,
  4884.     IN DWORD dwParamType,
  4885.     IN DWORD dwIndex,
  4886.     OUT void *pvData,
  4887.     IN OUT DWORD *pcbData
  4888.     );
  4889.  
  4890. //+-------------------------------------------------------------------------
  4891. //  Get parameter types and their corresponding data structure definitions.
  4892. //--------------------------------------------------------------------------
  4893. #define CMSG_TYPE_PARAM                              1
  4894. #define CMSG_CONTENT_PARAM                           2
  4895. #define CMSG_BARE_CONTENT_PARAM                      3
  4896. #define CMSG_INNER_CONTENT_TYPE_PARAM                4
  4897. #define CMSG_SIGNER_COUNT_PARAM                      5
  4898. #define CMSG_SIGNER_INFO_PARAM                       6
  4899. #define CMSG_SIGNER_CERT_INFO_PARAM                  7
  4900. #define CMSG_SIGNER_HASH_ALGORITHM_PARAM             8
  4901. #define CMSG_SIGNER_AUTH_ATTR_PARAM                  9
  4902. #define CMSG_SIGNER_UNAUTH_ATTR_PARAM                10
  4903. #define CMSG_CERT_COUNT_PARAM                        11
  4904. #define CMSG_CERT_PARAM                              12
  4905. #define CMSG_CRL_COUNT_PARAM                         13
  4906. #define CMSG_CRL_PARAM                               14
  4907. #define CMSG_ENVELOPE_ALGORITHM_PARAM                15
  4908. #define CMSG_RECIPIENT_COUNT_PARAM                   17
  4909. #define CMSG_RECIPIENT_INDEX_PARAM                   18
  4910. #define CMSG_RECIPIENT_INFO_PARAM                    19
  4911. #define CMSG_HASH_ALGORITHM_PARAM                    20
  4912. #define CMSG_HASH_DATA_PARAM                         21
  4913. #define CMSG_COMPUTED_HASH_PARAM                     22
  4914. #define CMSG_ENCRYPT_PARAM                           26
  4915. #define CMSG_ENCRYPTED_DIGEST                        27
  4916. #define CMSG_ENCODED_SIGNER                          28
  4917. #define CMSG_ENCODED_MESSAGE                         29
  4918. #define CMSG_VERSION_PARAM                           30
  4919. #define CMSG_ATTR_CERT_COUNT_PARAM                   31
  4920. #define CMSG_ATTR_CERT_PARAM                         32
  4921. #define CMSG_CMS_RECIPIENT_COUNT_PARAM               33
  4922. #define CMSG_CMS_RECIPIENT_INDEX_PARAM               34
  4923. #define CMSG_CMS_RECIPIENT_ENCRYPTED_KEY_INDEX_PARAM 35
  4924. #define CMSG_CMS_RECIPIENT_INFO_PARAM                36
  4925. #define CMSG_UNPROTECTED_ATTR_PARAM                  37
  4926. #define CMSG_SIGNER_CERT_ID_PARAM                    38
  4927. #define CMSG_CMS_SIGNER_INFO_PARAM                   39
  4928.  
  4929. //+-------------------------------------------------------------------------
  4930. //  CMSG_TYPE_PARAM
  4931. //
  4932. //  The type of the decoded message.
  4933. //
  4934. //  pvData points to a DWORD
  4935. //--------------------------------------------------------------------------
  4936.  
  4937. //+-------------------------------------------------------------------------
  4938. //  CMSG_CONTENT_PARAM
  4939. //
  4940. //  The encoded content of a cryptographic message. Depending on how the
  4941. //  message was opened, the content is either the whole PKCS#7
  4942. //  message (opened to encode) or the inner content (opened to decode).
  4943. //  In the decode case, the decrypted content is returned, if enveloped.
  4944. //  If not enveloped, and if the inner content is of type DATA, the returned
  4945. //  data is the contents octets of the inner content.
  4946. //
  4947. //  pvData points to the buffer receiving the content bytes
  4948. //--------------------------------------------------------------------------
  4949.  
  4950. //+-------------------------------------------------------------------------
  4951. //  CMSG_BARE_CONTENT_PARAM
  4952. //
  4953. //  The encoded content of an encoded cryptographic message, without the
  4954. //  outer layer of ContentInfo. That is, only the encoding of the
  4955. //  ContentInfo.content field is returned.
  4956. //
  4957. //  pvData points to the buffer receiving the content bytes
  4958. //--------------------------------------------------------------------------
  4959.  
  4960. //+-------------------------------------------------------------------------
  4961. //  CMSG_INNER_CONTENT_TYPE_PARAM
  4962. //
  4963. //  The type of the inner content of a decoded cryptographic message,
  4964. //  in the form of a NULL-terminated object identifier string
  4965. //  (eg. "1.2.840.113549.1.7.1").
  4966. //
  4967. //  pvData points to the buffer receiving the object identifier string
  4968. //--------------------------------------------------------------------------
  4969.  
  4970. //+-------------------------------------------------------------------------
  4971. //  CMSG_SIGNER_COUNT_PARAM
  4972. //
  4973. //  Count of signers in a SIGNED or SIGNED_AND_ENVELOPED message
  4974. //
  4975. //  pvData points to a DWORD
  4976. //--------------------------------------------------------------------------
  4977.  
  4978. //+-------------------------------------------------------------------------
  4979. //  CMSG_SIGNER_CERT_INFO_PARAM
  4980. //
  4981. //  To get all the signers, repetitively call CryptMsgGetParam, with
  4982. //  dwIndex set to 0 .. SignerCount - 1.
  4983. //
  4984. //  pvData points to a CERT_INFO struct.
  4985. //
  4986. //  Only the following fields have been updated in the CERT_INFO struct:
  4987. //  Issuer and SerialNumber.
  4988. //
  4989. //  Note, if the KEYID choice was selected for a CMS SignerId, then, the
  4990. //  SerialNumber is 0 and the Issuer is encoded containing a single RDN with a
  4991. //  single Attribute whose OID is szOID_KEYID_RDN, value type is
  4992. //  CERT_RDN_OCTET_STRING and value is the KEYID. When the
  4993. //  CertGetSubjectCertificateFromStore and
  4994. //  CertFindCertificateInStore(CERT_FIND_SUBJECT_CERT) APIs see this
  4995. //  special KEYID Issuer and SerialNumber, they do a KEYID match.
  4996. //--------------------------------------------------------------------------
  4997.  
  4998. //+-------------------------------------------------------------------------
  4999. //  CMSG_SIGNER_INFO_PARAM
  5000. //
  5001. //  To get all the signers, repetitively call CryptMsgGetParam, with
  5002. //  dwIndex set to 0 .. SignerCount - 1.
  5003. //
  5004. //  pvData points to a CMSG_SIGNER_INFO struct.
  5005. //
  5006. //  Note, if the KEYID choice was selected for a CMS SignerId, then, the
  5007. //  SerialNumber is 0 and the Issuer is encoded containing a single RDN with a
  5008. //  single Attribute whose OID is szOID_KEYID_RDN, value type is
  5009. //  CERT_RDN_OCTET_STRING and value is the KEYID. When the
  5010. //  CertGetSubjectCertificateFromStore and
  5011. //  CertFindCertificateInStore(CERT_FIND_SUBJECT_CERT) APIs see this
  5012. //  special KEYID Issuer and SerialNumber, they do a KEYID match.
  5013. //--------------------------------------------------------------------------
  5014. typedef struct _CMSG_SIGNER_INFO {
  5015.     DWORD                       dwVersion;
  5016.     CERT_NAME_BLOB              Issuer;
  5017.     CRYPT_INTEGER_BLOB          SerialNumber;
  5018.     CRYPT_ALGORITHM_IDENTIFIER  HashAlgorithm;
  5019.     CRYPT_ALGORITHM_IDENTIFIER  HashEncryptionAlgorithm;
  5020.     CRYPT_DATA_BLOB             EncryptedHash;
  5021.     CRYPT_ATTRIBUTES            AuthAttrs;
  5022.     CRYPT_ATTRIBUTES            UnauthAttrs;
  5023. } CMSG_SIGNER_INFO, *PCMSG_SIGNER_INFO;
  5024.  
  5025.  
  5026. //+-------------------------------------------------------------------------
  5027. //  CMSG_SIGNER_CERT_ID_PARAM
  5028. //
  5029. //  To get all the signers, repetitively call CryptMsgGetParam, with
  5030. //  dwIndex set to 0 .. SignerCount - 1.
  5031. //
  5032. //  pvData points to a CERT_ID struct.
  5033. //--------------------------------------------------------------------------
  5034.  
  5035. //+-------------------------------------------------------------------------
  5036. //  CMSG_CMS_SIGNER_INFO_PARAM
  5037. //
  5038. //  Same as CMSG_SIGNER_INFO_PARAM, except, contains SignerId instead of
  5039. //  Issuer and SerialNumber.
  5040. //
  5041. //  To get all the signers, repetitively call CryptMsgGetParam, with
  5042. //  dwIndex set to 0 .. SignerCount - 1.
  5043. //
  5044. //  pvData points to a CMSG_CMS_SIGNER_INFO struct.
  5045. //--------------------------------------------------------------------------
  5046. typedef struct _CMSG_CMS_SIGNER_INFO {
  5047.     DWORD                       dwVersion;
  5048.     CERT_ID                     SignerId;
  5049.     CRYPT_ALGORITHM_IDENTIFIER  HashAlgorithm;
  5050.     CRYPT_ALGORITHM_IDENTIFIER  HashEncryptionAlgorithm;
  5051.     CRYPT_DATA_BLOB             EncryptedHash;
  5052.     CRYPT_ATTRIBUTES            AuthAttrs;
  5053.     CRYPT_ATTRIBUTES            UnauthAttrs;
  5054. } CMSG_CMS_SIGNER_INFO, *PCMSG_CMS_SIGNER_INFO;
  5055.  
  5056.  
  5057. //+-------------------------------------------------------------------------
  5058. //  CMSG_SIGNER_HASH_ALGORITHM_PARAM
  5059. //
  5060. //  This parameter specifies the HashAlgorithm that was used for the signer.
  5061. //
  5062. //  Set dwIndex to iterate through all the signers.
  5063. //
  5064. //  pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  5065. //--------------------------------------------------------------------------
  5066.  
  5067. //+-------------------------------------------------------------------------
  5068. //  CMSG_SIGNER_AUTH_ATTR_PARAM
  5069. //
  5070. //  The authenticated attributes for the signer.
  5071. //
  5072. //  Set dwIndex to iterate through all the signers.
  5073. //
  5074. //  pvData points to a CMSG_ATTR struct.
  5075. //--------------------------------------------------------------------------
  5076. typedef CRYPT_ATTRIBUTES CMSG_ATTR;
  5077. typedef CRYPT_ATTRIBUTES *PCMSG_ATTR;
  5078.  
  5079. //+-------------------------------------------------------------------------
  5080. //  CMSG_SIGNER_UNAUTH_ATTR_PARAM
  5081. //
  5082. //  The unauthenticated attributes for the signer.
  5083. //
  5084. //  Set dwIndex to iterate through all the signers.
  5085. //
  5086. //  pvData points to a CMSG_ATTR struct.
  5087. //--------------------------------------------------------------------------
  5088.  
  5089. //+-------------------------------------------------------------------------
  5090. //  CMSG_CERT_COUNT_PARAM
  5091. //
  5092. //  Count of certificates in a SIGNED or SIGNED_AND_ENVELOPED message.
  5093. //
  5094. //  CMS, also supports certificates in an ENVELOPED message.
  5095. //
  5096. //  pvData points to a DWORD
  5097. //--------------------------------------------------------------------------
  5098.  
  5099. //+-------------------------------------------------------------------------
  5100. //  CMSG_CERT_PARAM
  5101. //
  5102. //  To get all the certificates, repetitively call CryptMsgGetParam, with
  5103. //  dwIndex set to 0 .. CertCount - 1.
  5104. //
  5105. //  pvData points to an array of the certificate's encoded bytes.
  5106. //--------------------------------------------------------------------------
  5107.  
  5108. //+-------------------------------------------------------------------------
  5109. //  CMSG_CRL_COUNT_PARAM
  5110. //
  5111. //  Count of CRLs in a SIGNED or SIGNED_AND_ENVELOPED message.
  5112. //
  5113. //  CMS, also supports CRLs in an ENVELOPED message.
  5114. //
  5115. //  pvData points to a DWORD
  5116. //--------------------------------------------------------------------------
  5117.  
  5118. //+-------------------------------------------------------------------------
  5119. //  CMSG_CRL_PARAM
  5120. //
  5121. //  To get all the CRLs, repetitively call CryptMsgGetParam, with
  5122. //  dwIndex set to 0 .. CrlCount - 1.
  5123. //
  5124. //  pvData points to an array of the CRL's encoded bytes.
  5125. //--------------------------------------------------------------------------
  5126.  
  5127.  
  5128. //+-------------------------------------------------------------------------
  5129. //  CMSG_ENVELOPE_ALGORITHM_PARAM
  5130. //
  5131. //  The ContentEncryptionAlgorithm that was used in
  5132. //  an ENVELOPED or SIGNED_AND_ENVELOPED message.
  5133. //
  5134. //  For streaming you must be able to successfully get this parameter before
  5135. //  doing a CryptMsgControl decrypt.
  5136. //
  5137. //  pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  5138. //--------------------------------------------------------------------------
  5139.  
  5140. //+-------------------------------------------------------------------------
  5141. //  CMSG_RECIPIENT_COUNT_PARAM
  5142. //
  5143. //  Count of recipients in an ENVELOPED or SIGNED_AND_ENVELOPED message.
  5144. //
  5145. //  Count of key transport recepients.
  5146. //
  5147. //  The CMSG_CMS_RECIPIENT_COUNT_PARAM has the total count of
  5148. //  recipients (it also includes key agree and mail list recipients).
  5149. //
  5150. //  pvData points to a DWORD
  5151. //--------------------------------------------------------------------------
  5152.  
  5153. //+-------------------------------------------------------------------------
  5154. //  CMSG_RECIPIENT_INDEX_PARAM
  5155. //
  5156. //  Index of the recipient used to decrypt an ENVELOPED or SIGNED_AND_ENVELOPED
  5157. //  message.
  5158. //
  5159. //  Index of a key transport recipient. If a non key transport
  5160. //  recipient was used to decrypt, fails with LastError set to
  5161. //  CRYPT_E_INVALID_INDEX.
  5162. //
  5163. //  pvData points to a DWORD
  5164. //--------------------------------------------------------------------------
  5165.  
  5166. //+-------------------------------------------------------------------------
  5167. //  CMSG_RECIPIENT_INFO_PARAM
  5168. //
  5169. //  To get all the recipients, repetitively call CryptMsgGetParam, with
  5170. //  dwIndex set to 0 .. RecipientCount - 1.
  5171. //
  5172. //  Only returns the key transport recepients.
  5173. //
  5174. //  The CMSG_CMS_RECIPIENT_INFO_PARAM returns all recipients.
  5175. //
  5176. //  pvData points to a CERT_INFO struct.
  5177. //
  5178. //  Only the following fields have been updated in the CERT_INFO struct:
  5179. //  Issuer, SerialNumber and PublicKeyAlgorithm. The PublicKeyAlgorithm
  5180. //  specifies the KeyEncryptionAlgorithm that was used.
  5181. //
  5182. //  Note, if the KEYID choice was selected for a key transport recipient, then,
  5183. //  the SerialNumber is 0 and the Issuer is encoded containing a single RDN
  5184. //  with a single Attribute whose OID is szOID_KEYID_RDN, value type is
  5185. //  CERT_RDN_OCTET_STRING and value is the KEYID. When the
  5186. //  CertGetSubjectCertificateFromStore and
  5187. //  CertFindCertificateInStore(CERT_FIND_SUBJECT_CERT) APIs see this
  5188. //  special KEYID Issuer and SerialNumber, they do a KEYID match.
  5189. //--------------------------------------------------------------------------
  5190.  
  5191. //+-------------------------------------------------------------------------
  5192. //  CMSG_HASH_ALGORITHM_PARAM
  5193. //
  5194. //  The HashAlgorithm in a HASHED message.
  5195. //
  5196. //  pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  5197. //--------------------------------------------------------------------------
  5198.  
  5199. //+-------------------------------------------------------------------------
  5200. //  CMSG_HASH_DATA_PARAM
  5201. //
  5202. //  The hash in a HASHED message.
  5203. //
  5204. //  pvData points to an array of bytes.
  5205. //--------------------------------------------------------------------------
  5206.  
  5207. //+-------------------------------------------------------------------------
  5208. //  CMSG_COMPUTED_HASH_PARAM
  5209. //
  5210. //  The computed hash for a HASHED message.
  5211. //  This may be called for either an encoded or decoded message.
  5212. //
  5213. //  Also, the computed hash for one of the signer's in a SIGNED message.
  5214. //  It may be called for either an encoded or decoded message after the
  5215. //  final update.  Set dwIndex to iterate through all the signers.
  5216. //
  5217. //  pvData points to an array of bytes.
  5218. //--------------------------------------------------------------------------
  5219.  
  5220. //+-------------------------------------------------------------------------
  5221. //  CMSG_ENCRYPT_PARAM
  5222. //
  5223. //  The ContentEncryptionAlgorithm that was used in an ENCRYPTED message.
  5224. //
  5225. //  pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  5226. //--------------------------------------------------------------------------
  5227.  
  5228. //+-------------------------------------------------------------------------
  5229. //  CMSG_ENCODED_MESSAGE
  5230. //
  5231. //  The full encoded message. This is useful in the case of a decoded
  5232. //  message which has been modified (eg. a signed-data or
  5233. //  signed-and-enveloped-data message which has been countersigned).
  5234. //
  5235. //  pvData points to an array of the message's encoded bytes.
  5236. //--------------------------------------------------------------------------
  5237.  
  5238. //+-------------------------------------------------------------------------
  5239. //  CMSG_VERSION_PARAM
  5240. //
  5241. //  The version of the decoded message.
  5242. //
  5243. //  pvData points to a DWORD
  5244. //--------------------------------------------------------------------------
  5245.  
  5246. #define CMSG_SIGNED_DATA_V1                     1
  5247. #define CMSG_SIGNED_DATA_V3                     3
  5248. #define CMSG_SIGNED_DATA_PKCS_1_5_VERSION       CMSG_SIGNED_DATA_V1
  5249. #define CMSG_SIGNED_DATA_CMS_VERSION            CMSG_SIGNED_DATA_V3
  5250.  
  5251. #define CMSG_SIGNER_INFO_V1                     1
  5252. #define CMSG_SIGNER_INFO_V3                     3
  5253. #define CMSG_SIGNER_INFO_PKCS_1_5_VERSION       CMSG_SIGNER_INFO_V1
  5254. #define CMSG_SIGNER_INFO_CMS_VERSION            CMSG_SIGNER_INFO_V3
  5255.  
  5256. #define CMSG_HASHED_DATA_V0                     0
  5257. #define CMSG_HASHED_DATA_V2                     2
  5258. #define CMSG_HASHED_DATA_PKCS_1_5_VERSION       CMSG_HASHED_DATA_V0
  5259. #define CMSG_HASHED_DATA_CMS_VERSION            CMSG_HASHED_DATA_V2
  5260.  
  5261. #define CMSG_ENVELOPED_DATA_V0                  0
  5262. #define CMSG_ENVELOPED_DATA_V2                  2
  5263. #define CMSG_ENVELOPED_DATA_PKCS_1_5_VERSION    CMSG_ENVELOPED_DATA_V0
  5264. #define CMSG_ENVELOPED_DATA_CMS_VERSION         CMSG_ENVELOPED_DATA_V2
  5265.  
  5266. //+-------------------------------------------------------------------------
  5267. //  CMSG_ATTR_CERT_COUNT_PARAM
  5268. //
  5269. //  Count of attribute certificates in a SIGNED or ENVELOPED message.
  5270. //
  5271. //  pvData points to a DWORD
  5272. //--------------------------------------------------------------------------
  5273.  
  5274. //+-------------------------------------------------------------------------
  5275. //  CMSG_ATTR_CERT_PARAM
  5276. //
  5277. //  To get all the attribute certificates, repetitively call CryptMsgGetParam,
  5278. //  with dwIndex set to 0 .. AttrCertCount - 1.
  5279. //
  5280. //  pvData points to an array of the attribute certificate's encoded bytes.
  5281. //--------------------------------------------------------------------------
  5282.  
  5283. //+-------------------------------------------------------------------------
  5284. //  CMSG_CMS_RECIPIENT_COUNT_PARAM
  5285. //
  5286. //  Count of all CMS recipients in an ENVELOPED message.
  5287. //
  5288. //  pvData points to a DWORD
  5289. //--------------------------------------------------------------------------
  5290.  
  5291. //+-------------------------------------------------------------------------
  5292. //  CMSG_CMS_RECIPIENT_INDEX_PARAM
  5293. //
  5294. //  Index of the CMS recipient used to decrypt an ENVELOPED message.
  5295. //
  5296. //  pvData points to a DWORD
  5297. //--------------------------------------------------------------------------
  5298.  
  5299. //+-------------------------------------------------------------------------
  5300. //  CMSG_CMS_RECIPIENT_ENCRYPTED_KEY_INDEX_PARAM
  5301. //
  5302. //  For a CMS key agreement recipient, the index of the encrypted key
  5303. //  used to decrypt an ENVELOPED message.
  5304. //
  5305. //  pvData points to a DWORD
  5306. //--------------------------------------------------------------------------
  5307.  
  5308. //+-------------------------------------------------------------------------
  5309. //  CMSG_CMS_RECIPIENT_INFO_PARAM
  5310. //
  5311. //  To get all the CMS recipients, repetitively call CryptMsgGetParam, with
  5312. //  dwIndex set to 0 .. CmsRecipientCount - 1.
  5313. //
  5314. //  pvData points to a CMSG_CMS_RECIPIENT_INFO struct.
  5315. //--------------------------------------------------------------------------
  5316.  
  5317. typedef struct _CMSG_KEY_TRANS_RECIPIENT_INFO {
  5318.     DWORD                       dwVersion;
  5319.  
  5320.     // Currently, only ISSUER_SERIAL_NUMBER or KEYID choices
  5321.     CERT_ID                     RecipientId;
  5322.  
  5323.     CRYPT_ALGORITHM_IDENTIFIER  KeyEncryptionAlgorithm;
  5324.     CRYPT_DATA_BLOB             EncryptedKey;
  5325. } CMSG_KEY_TRANS_RECIPIENT_INFO, *PCMSG_KEY_TRANS_RECIPIENT_INFO;
  5326.  
  5327. typedef struct _CMSG_RECIPIENT_ENCRYPTED_KEY_INFO {
  5328.     // Currently, only ISSUER_SERIAL_NUMBER or KEYID choices
  5329.     CERT_ID                     RecipientId;
  5330.  
  5331.     CRYPT_DATA_BLOB             EncryptedKey;
  5332.  
  5333.     // The following optional fields are only applicable to KEYID choice
  5334.     FILETIME                    Date;
  5335.     PCRYPT_ATTRIBUTE_TYPE_VALUE pOtherAttr;
  5336. } CMSG_RECIPIENT_ENCRYPTED_KEY_INFO, *PCMSG_RECIPIENT_ENCRYPTED_KEY_INFO;
  5337.  
  5338. typedef struct _CMSG_KEY_AGREE_RECIPIENT_INFO {
  5339.     DWORD                       dwVersion;
  5340.     DWORD                       dwOriginatorChoice;
  5341.     union {
  5342.         // CMSG_KEY_AGREE_ORIGINATOR_CERT
  5343.         CERT_ID                     OriginatorCertId;
  5344.         // CMSG_KEY_AGREE_ORIGINATOR_PUBLIC_KEY
  5345.         CERT_PUBLIC_KEY_INFO        OriginatorPublicKeyInfo;
  5346.     };
  5347.     CRYPT_DATA_BLOB             UserKeyingMaterial;
  5348.     CRYPT_ALGORITHM_IDENTIFIER  KeyEncryptionAlgorithm;
  5349.  
  5350.     DWORD                                cRecipientEncryptedKeys;
  5351.     PCMSG_RECIPIENT_ENCRYPTED_KEY_INFO   *rgpRecipientEncryptedKeys;
  5352. } CMSG_KEY_AGREE_RECIPIENT_INFO, *PCMSG_KEY_AGREE_RECIPIENT_INFO;
  5353.  
  5354. #define CMSG_KEY_AGREE_ORIGINATOR_CERT         1
  5355. #define CMSG_KEY_AGREE_ORIGINATOR_PUBLIC_KEY   2
  5356.  
  5357.  
  5358. typedef struct _CMSG_MAIL_LIST_RECIPIENT_INFO {
  5359.     DWORD                       dwVersion;
  5360.     CRYPT_DATA_BLOB             KeyId;
  5361.     CRYPT_ALGORITHM_IDENTIFIER  KeyEncryptionAlgorithm;
  5362.     CRYPT_DATA_BLOB             EncryptedKey;
  5363.  
  5364.     // The following fields are optional
  5365.     FILETIME                    Date;
  5366.     PCRYPT_ATTRIBUTE_TYPE_VALUE pOtherAttr;
  5367. } CMSG_MAIL_LIST_RECIPIENT_INFO, *PCMSG_MAIL_LIST_RECIPIENT_INFO;
  5368.  
  5369. typedef struct _CMSG_CMS_RECIPIENT_INFO {
  5370.     DWORD   dwRecipientChoice;
  5371.     union {
  5372.         // CMSG_KEY_TRANS_RECIPIENT
  5373.         PCMSG_KEY_TRANS_RECIPIENT_INFO   pKeyTrans;
  5374.         // CMSG_KEY_AGREE_RECIPIENT
  5375.         PCMSG_KEY_AGREE_RECIPIENT_INFO   pKeyAgree;
  5376.         // CMSG_MAIL_LIST_RECIPIENT
  5377.         PCMSG_MAIL_LIST_RECIPIENT_INFO   pMailList;
  5378.     };
  5379. } CMSG_CMS_RECIPIENT_INFO, *PCMSG_CMS_RECIPIENT_INFO;
  5380.  
  5381.  
  5382. // dwVersion numbers for the KeyTrans, KeyAgree and MailList recipients
  5383. #define CMSG_ENVELOPED_RECIPIENT_V0             0
  5384. #define CMSG_ENVELOPED_RECIPIENT_V2             2
  5385. #define CMSG_ENVELOPED_RECIPIENT_V3             3
  5386. #define CMSG_ENVELOPED_RECIPIENT_V4             4
  5387. #define CMSG_KEY_TRANS_PKCS_1_5_VERSION         CMSG_ENVELOPED_RECIPIENT_V0
  5388. #define CMSG_KEY_TRANS_CMS_VERSION              CMSG_ENVELOPED_RECIPIENT_V2
  5389. #define CMSG_KEY_AGREE_VERSION                  CMSG_ENVELOPED_RECIPIENT_V3
  5390. #define CMSG_MAIL_LIST_VERSION                  CMSG_ENVELOPED_RECIPIENT_V4
  5391.  
  5392. //+-------------------------------------------------------------------------
  5393. //  CMSG_UNPROTECTED_ATTR_PARAM
  5394. //
  5395. //  The unprotected attributes in the envelped message.
  5396. //
  5397. //  pvData points to a CMSG_ATTR struct.
  5398. //--------------------------------------------------------------------------
  5399.  
  5400.  
  5401. //+-------------------------------------------------------------------------
  5402. //  Perform a special "control" function after the final CryptMsgUpdate of a
  5403. //  encoded/decoded cryptographic message.
  5404. //
  5405. //  The dwCtrlType parameter specifies the type of operation to be performed.
  5406. //
  5407. //  The pvCtrlPara definition depends on the dwCtrlType value.
  5408. //
  5409. //  See below for a list of the control operations and their pvCtrlPara
  5410. //  type definition.
  5411. //--------------------------------------------------------------------------
  5412. WINCRYPT32API
  5413. BOOL
  5414. WINAPI
  5415. CryptMsgControl(
  5416.     IN HCRYPTMSG hCryptMsg,
  5417.     IN DWORD dwFlags,
  5418.     IN DWORD dwCtrlType,
  5419.     IN void const *pvCtrlPara
  5420.     );
  5421.  
  5422. //+-------------------------------------------------------------------------
  5423. //  Message control types
  5424. //--------------------------------------------------------------------------
  5425. #define CMSG_CTRL_VERIFY_SIGNATURE       1
  5426. #define CMSG_CTRL_DECRYPT                2
  5427. #define CMSG_CTRL_VERIFY_HASH            5
  5428. #define CMSG_CTRL_ADD_SIGNER             6
  5429. #define CMSG_CTRL_DEL_SIGNER             7
  5430. #define CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR 8
  5431. #define CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR 9
  5432. #define CMSG_CTRL_ADD_CERT               10
  5433. #define CMSG_CTRL_DEL_CERT               11
  5434. #define CMSG_CTRL_ADD_CRL                12
  5435. #define CMSG_CTRL_DEL_CRL                13
  5436. #define CMSG_CTRL_ADD_ATTR_CERT          14
  5437. #define CMSG_CTRL_DEL_ATTR_CERT          15
  5438. #define CMSG_CTRL_KEY_TRANS_DECRYPT      16
  5439. #define CMSG_CTRL_KEY_AGREE_DECRYPT      17
  5440. #define CMSG_CTRL_MAIL_LIST_DECRYPT      18
  5441. #define CMSG_CTRL_VERIFY_SIGNATURE_EX    19
  5442. #define CMSG_CTRL_ADD_CMS_SIGNER_INFO    20
  5443.  
  5444. //+-------------------------------------------------------------------------
  5445. //  CMSG_CTRL_VERIFY_SIGNATURE
  5446. //
  5447. //  Verify the signature of a SIGNED or SIGNED_AND_ENVELOPED
  5448. //  message after it has been decoded.
  5449. //
  5450. //  For a SIGNED_AND_ENVELOPED message, called after
  5451. //  CryptMsgControl(CMSG_CTRL_DECRYPT), if CryptMsgOpenToDecode was called
  5452. //  with a NULL pRecipientInfo.
  5453. //
  5454. //  pvCtrlPara points to a CERT_INFO struct.
  5455. //
  5456. //  The CERT_INFO contains the Issuer and SerialNumber identifying
  5457. //  the Signer of the message. The CERT_INFO also contains the
  5458. //  PublicKeyInfo
  5459. //  used to verify the signature. The cryptographic provider specified
  5460. //  in CryptMsgOpenToDecode is used.
  5461. //
  5462. //  Note, if the message contains CMS signers identified by KEYID, then,
  5463. //  the CERT_INFO's Issuer and SerialNumber is ignored and only the public
  5464. //  key is used to find a signer whose signature verifies.
  5465. //
  5466. //  The following CMSG_CTRL_VERIFY_SIGNATURE_EX should be used instead.
  5467. //--------------------------------------------------------------------------
  5468.  
  5469. //+-------------------------------------------------------------------------
  5470. //  CMSG_CTRL_VERIFY_SIGNATURE_EX
  5471. //
  5472. //  Verify the signature of a SIGNED message after it has been decoded.
  5473. //
  5474. //  pvCtrlPara points to the following CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA.
  5475. //
  5476. //  If hCryptProv is NULL, uses the cryptographic provider specified in
  5477. //  CryptMsgOpenToDecode. If CryptMsgOpenToDecode's hCryptProv is also NULL,
  5478. //  gets default provider according to the signer's public key OID.
  5479. //
  5480. //  dwSignerIndex is the index of the signer to use to verify the signature.
  5481. //
  5482. //  The signer can be a pointer to a CERT_PUBLIC_KEY_INFO, certificate
  5483. //  context or a chain context.
  5484. //--------------------------------------------------------------------------
  5485. typedef struct _CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA {
  5486.     DWORD               cbSize;
  5487.     HCRYPTPROV          hCryptProv;
  5488.     DWORD               dwSignerIndex;
  5489.     DWORD               dwSignerType;
  5490.     void                *pvSigner;
  5491. } CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA, *PCMSG_CTRL_VERIFY_SIGNATURE_EX_PARA;
  5492.  
  5493. // Signer Types
  5494. #define CMSG_VERIFY_SIGNER_PUBKEY                   1
  5495.     // pvSigner :: PCERT_PUBLIC_KEY_INFO
  5496. #define CMSG_VERIFY_SIGNER_CERT                     2
  5497.     // pvSigner :: PCCERT_CONTEXT
  5498. #define CMSG_VERIFY_SIGNER_CHAIN                    3
  5499.     // pvSigner :: PCCERT_CHAIN_CONTEXT
  5500.  
  5501.  
  5502. //+-------------------------------------------------------------------------
  5503. //  CMSG_CTRL_DECRYPT
  5504. //
  5505. //  Decrypt an ENVELOPED or SIGNED_AND_ENVELOPED message after it has been
  5506. //  decoded.
  5507. //
  5508. //  This decrypt is only applicable to key transport recipients.
  5509. //
  5510. //  hCryptProv and dwKeySpec specify the private key to use. For dwKeySpec ==
  5511. //  0, defaults to AT_KEYEXCHANGE.
  5512. //
  5513. //  If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags passed
  5514. //  to CryptMsgControl, then, the hCryptProv is released on the final
  5515. //  CryptMsgClose. Not released if CryptMsgControl fails.
  5516. //
  5517. //  dwRecipientIndex is the index of the recipient in the message associated
  5518. //  with the hCryptProv's private key.
  5519. //
  5520. //  The dwRecipientIndex is the index of a key transport recipient.
  5521. //
  5522. //  Note, the message can only be decrypted once.
  5523. //--------------------------------------------------------------------------
  5524. typedef struct _CMSG_CTRL_DECRYPT_PARA {
  5525.     DWORD       cbSize;
  5526.     HCRYPTPROV  hCryptProv;
  5527.     DWORD       dwKeySpec;
  5528.     DWORD       dwRecipientIndex;
  5529. } CMSG_CTRL_DECRYPT_PARA, *PCMSG_CTRL_DECRYPT_PARA;
  5530.  
  5531.  
  5532. //+-------------------------------------------------------------------------
  5533. //  CMSG_CTRL_KEY_TRANS_DECRYPT
  5534. //
  5535. //  Decrypt an ENVELOPED message after it has been decoded for a key
  5536. //  transport recipient.
  5537. //
  5538. //  hCryptProv and dwKeySpec specify the private key to use. For dwKeySpec ==
  5539. //  0, defaults to AT_KEYEXCHANGE.
  5540. //
  5541. //  If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags passed
  5542. //  to CryptMsgControl, then, the hCryptProv is released on the final
  5543. //  CryptMsgClose. Not released if CryptMsgControl fails.
  5544. //
  5545. //  pKeyTrans points to the CMSG_KEY_TRANS_RECIPIENT_INFO obtained via
  5546. //  CryptMsgGetParam(CMSG_CMS_RECIPIENT_INFO_PARAM)
  5547. //
  5548. //  dwRecipientIndex is the index of the recipient in the message associated
  5549. //  with the hCryptProv's private key.
  5550. //
  5551. //  Note, the message can only be decrypted once.
  5552. //--------------------------------------------------------------------------
  5553. typedef struct _CMSG_CTRL_KEY_TRANS_DECRYPT_PARA {
  5554.     DWORD                           cbSize;
  5555.     HCRYPTPROV                      hCryptProv;
  5556.     DWORD                           dwKeySpec;
  5557.     PCMSG_KEY_TRANS_RECIPIENT_INFO  pKeyTrans;
  5558.     DWORD                           dwRecipientIndex;
  5559. } CMSG_CTRL_KEY_TRANS_DECRYPT_PARA, *PCMSG_CTRL_KEY_TRANS_DECRYPT_PARA;
  5560.  
  5561. //+-------------------------------------------------------------------------
  5562. //  CMSG_CTRL_KEY_AGREE_DECRYPT
  5563. //
  5564. //  Decrypt an ENVELOPED message after it has been decoded for a key
  5565. //  agreement recipient.
  5566. //
  5567. //  hCryptProv and dwKeySpec specify the private key to use. For dwKeySpec ==
  5568. //  0, defaults to AT_KEYEXCHANGE.
  5569. //
  5570. //  If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags passed
  5571. //  to CryptMsgControl, then, the hCryptProv is released on the final
  5572. //  CryptMsgClose. Not released if CryptMsgControl fails.
  5573. //
  5574. //  pKeyAgree points to the CMSG_KEY_AGREE_RECIPIENT_INFO obtained via
  5575. //  CryptMsgGetParam(CMSG_CMS_RECIPIENT_INFO_PARAM) for dwRecipientIndex.
  5576. //
  5577. //  dwRecipientIndex, dwRecipientEncryptedKeyIndex are the indices of the
  5578. //  recipient's encrypted key in the message associated with the hCryptProv's
  5579. //  private key.
  5580. //
  5581. //  OriginatorPublicKey is the originator's public key obtained from either
  5582. //  the originator's certificate or the CMSG_KEY_AGREE_RECIPIENT_INFO obtained
  5583. //  via the CMSG_CMS_RECIPIENT_INFO_PARAM.
  5584. //
  5585. //  Note, the message can only be decrypted once.
  5586. //--------------------------------------------------------------------------
  5587. typedef struct _CMSG_CTRL_KEY_AGREE_DECRYPT_PARA {
  5588.     DWORD                           cbSize;
  5589.     HCRYPTPROV                      hCryptProv;
  5590.     DWORD                           dwKeySpec;
  5591.     PCMSG_KEY_AGREE_RECIPIENT_INFO  pKeyAgree;
  5592.     DWORD                           dwRecipientIndex;
  5593.     DWORD                           dwRecipientEncryptedKeyIndex;
  5594.     CRYPT_BIT_BLOB                  OriginatorPublicKey;
  5595. } CMSG_CTRL_KEY_AGREE_DECRYPT_PARA, *PCMSG_CTRL_KEY_AGREE_DECRYPT_PARA;
  5596.  
  5597.  
  5598. //+-------------------------------------------------------------------------
  5599. //  CMSG_CTRL_MAIL_LIST_DECRYPT
  5600. //
  5601. //  Decrypt an ENVELOPED message after it has been decoded for a mail
  5602. //  list recipient.
  5603. //
  5604. //  pMailList points to the CMSG_MAIL_LIST_RECIPIENT_INFO obtained via
  5605. //  CryptMsgGetParam(CMSG_CMS_RECIPIENT_INFO_PARAM) for dwRecipientIndex.
  5606. //
  5607. //  There is 1 choice for the KeyEncryptionKey: an already created CSP key
  5608. //  handle. For the key handle choice, hCryptProv must be nonzero. This key
  5609. //  handle isn't destroyed.
  5610. //
  5611. //  If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags passed
  5612. //  to CryptMsgControl, then, the hCryptProv is released on the final
  5613. //  CryptMsgClose. Not released if CryptMsgControl fails.
  5614. //
  5615. //  For RC2 wrap, the effective key length is obtained from the
  5616. //  KeyEncryptionAlgorithm parameters and set on the hKeyEncryptionKey before
  5617. //  decrypting.
  5618. //
  5619. //  Note, the message can only be decrypted once.
  5620. //--------------------------------------------------------------------------
  5621. typedef struct _CMSG_CTRL_MAIL_LIST_DECRYPT_PARA {
  5622.     DWORD                           cbSize;
  5623.     HCRYPTPROV                      hCryptProv;
  5624.     PCMSG_MAIL_LIST_RECIPIENT_INFO  pMailList;
  5625.     DWORD                           dwRecipientIndex;
  5626.     DWORD                           dwKeyChoice;
  5627.     union {
  5628.         // CMSG_MAIL_LIST_HANDLE_KEY_CHOICE
  5629.         HCRYPTKEY                       hKeyEncryptionKey;
  5630.         // Reserve space for a potential pointer choice
  5631.         void                            *pvKeyEncryptionKey;
  5632.     };
  5633. } CMSG_CTRL_MAIL_LIST_DECRYPT_PARA, *PCMSG_CTRL_MAIL_LIST_DECRYPT_PARA;
  5634.  
  5635.  
  5636.  
  5637. //+-------------------------------------------------------------------------
  5638. //  CMSG_CTRL_VERIFY_HASH
  5639. //
  5640. //  Verify the hash of a HASHED message after it has been decoded.
  5641. //
  5642. //  Only the hCryptMsg parameter is used, to specify the message whose
  5643. //  hash is being verified.
  5644. //--------------------------------------------------------------------------
  5645.  
  5646. //+-------------------------------------------------------------------------
  5647. //  CMSG_CTRL_ADD_SIGNER
  5648. //
  5649. //  Add a signer to a signed-data message.
  5650. //
  5651. //  pvCtrlPara points to a CMSG_SIGNER_ENCODE_INFO.
  5652. //--------------------------------------------------------------------------
  5653.  
  5654. //+-------------------------------------------------------------------------
  5655. //  CMSG_CTRL_ADD_CMS_SIGNER_INFO
  5656. //
  5657. //  Add a signer to a signed-data message.
  5658. //
  5659. //  Differs from the above, CMSG_CTRL_ADD_SIGNER, wherein, the signer info
  5660. //  already contains the signature.
  5661. //
  5662. //  pvCtrlPara points to a CMSG_CMS_SIGNER_INFO.
  5663. //--------------------------------------------------------------------------
  5664.  
  5665. //+-------------------------------------------------------------------------
  5666. //  CMSG_CTRL_DEL_SIGNER
  5667. //
  5668. //  Remove a signer from a signed-data or signed-and-enveloped-data message.
  5669. //
  5670. //  pvCtrlPara points to a DWORD containing the 0-based index of the
  5671. //  signer to be removed.
  5672. //--------------------------------------------------------------------------
  5673.  
  5674. //+-------------------------------------------------------------------------
  5675. //  CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR
  5676. //
  5677. //  Add an unauthenticated attribute to the SignerInfo of a signed-data or
  5678. //  signed-and-enveloped-data message.
  5679. //
  5680. //  The unauthenticated attribute is input in the form of an encoded blob.
  5681. //--------------------------------------------------------------------------
  5682.  
  5683. typedef struct _CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA {
  5684.     DWORD               cbSize;
  5685.     DWORD               dwSignerIndex;
  5686.     CRYPT_DATA_BLOB     blob;
  5687. } CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA, *PCMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA;
  5688.  
  5689. //+-------------------------------------------------------------------------
  5690. //  CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR
  5691. //
  5692. //  Delete an unauthenticated attribute from the SignerInfo of a signed-data
  5693. //  or signed-and-enveloped-data message.
  5694. //
  5695. //  The unauthenticated attribute to be removed is specified by
  5696. //  a 0-based index.
  5697. //--------------------------------------------------------------------------
  5698.  
  5699. typedef struct _CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA {
  5700.     DWORD               cbSize;
  5701.     DWORD               dwSignerIndex;
  5702.     DWORD               dwUnauthAttrIndex;
  5703. } CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA, *PCMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA;
  5704.  
  5705. //+-------------------------------------------------------------------------
  5706. //  CMSG_CTRL_ADD_CERT
  5707. //
  5708. //  Add a certificate to a signed-data or signed-and-enveloped-data message.
  5709. //
  5710. //  pvCtrlPara points to a CRYPT_DATA_BLOB containing the certificate's
  5711. //  encoded bytes.
  5712. //--------------------------------------------------------------------------
  5713.  
  5714. //+-------------------------------------------------------------------------
  5715. //  CMSG_CTRL_DEL_CERT
  5716. //
  5717. //  Delete a certificate from a signed-data or signed-and-enveloped-data
  5718. //  message.
  5719. //
  5720. //  pvCtrlPara points to a DWORD containing the 0-based index of the
  5721. //  certificate to be removed.
  5722. //--------------------------------------------------------------------------
  5723.  
  5724. //+-------------------------------------------------------------------------
  5725. //  CMSG_CTRL_ADD_CRL
  5726. //
  5727. //  Add a CRL to a signed-data or signed-and-enveloped-data message.
  5728. //
  5729. //  pvCtrlPara points to a CRYPT_DATA_BLOB containing the CRL's
  5730. //  encoded bytes.
  5731. //--------------------------------------------------------------------------
  5732.  
  5733. //+-------------------------------------------------------------------------
  5734. //  CMSG_CTRL_DEL_CRL
  5735. //
  5736. //  Delete a CRL from a signed-data or signed-and-enveloped-data message.
  5737. //
  5738. //  pvCtrlPara points to a DWORD containing the 0-based index of the CRL
  5739. //  to be removed.
  5740. //--------------------------------------------------------------------------
  5741.  
  5742. //+-------------------------------------------------------------------------
  5743. //  CMSG_CTRL_ADD_ATTR_CERT
  5744. //
  5745. //  Add an attribute certificate to a signed-data message.
  5746. //
  5747. //  pvCtrlPara points to a CRYPT_DATA_BLOB containing the attribute
  5748. //  certificate's encoded bytes.
  5749. //--------------------------------------------------------------------------
  5750.  
  5751. //+-------------------------------------------------------------------------
  5752. //  CMSG_CTRL_DEL_ATTR_CERT
  5753. //
  5754. //  Delete an attribute certificate from a signed-data message.
  5755. //
  5756. //  pvCtrlPara points to a DWORD containing the 0-based index of the
  5757. //  attribute certificate to be removed.
  5758. //--------------------------------------------------------------------------
  5759.  
  5760.  
  5761. //+-------------------------------------------------------------------------
  5762. //  Verify a countersignature, at the SignerInfo level.
  5763. //  ie. verify that pbSignerInfoCountersignature contains the encrypted
  5764. //  hash of the encryptedDigest field of pbSignerInfo.
  5765. //
  5766. //  hCryptProv is used to hash the encryptedDigest field of pbSignerInfo.
  5767. //  The only fields referenced from pciCountersigner are SerialNumber, Issuer,
  5768. //  and SubjectPublicKeyInfo.
  5769. //--------------------------------------------------------------------------
  5770. BOOL
  5771. WINAPI
  5772. CryptMsgVerifyCountersignatureEncoded(
  5773.     IN HCRYPTPROV   hCryptProv,
  5774.     IN DWORD        dwEncodingType,
  5775.     IN PBYTE        pbSignerInfo,
  5776.     IN DWORD        cbSignerInfo,
  5777.     IN PBYTE        pbSignerInfoCountersignature,
  5778.     IN DWORD        cbSignerInfoCountersignature,
  5779.     IN PCERT_INFO   pciCountersigner
  5780.     );
  5781.  
  5782.  
  5783. //+-------------------------------------------------------------------------
  5784. //  Verify a countersignature, at the SignerInfo level.
  5785. //  ie. verify that pbSignerInfoCountersignature contains the encrypted
  5786. //  hash of the encryptedDigest field of pbSignerInfo.
  5787. //
  5788. //  hCryptProv is used to hash the encryptedDigest field of pbSignerInfo.
  5789. //
  5790. //  The signer can be a CERT_PUBLIC_KEY_INFO, certificate context or a
  5791. //  chain context.
  5792. //--------------------------------------------------------------------------
  5793. BOOL
  5794. WINAPI
  5795. CryptMsgVerifyCountersignatureEncodedEx(
  5796.     IN HCRYPTPROV   hCryptProv,
  5797.     IN DWORD        dwEncodingType,
  5798.     IN PBYTE        pbSignerInfo,
  5799.     IN DWORD        cbSignerInfo,
  5800.     IN PBYTE        pbSignerInfoCountersignature,
  5801.     IN DWORD        cbSignerInfoCountersignature,
  5802.     IN DWORD        dwSignerType,
  5803.     IN void         *pvSigner,
  5804.     IN DWORD        dwFlags,
  5805.     IN OPTIONAL void *pvReserved
  5806.     );
  5807.  
  5808.  
  5809. // See CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA for dwSignerType definitions
  5810.  
  5811.  
  5812. //+-------------------------------------------------------------------------
  5813. //  Countersign an already-existing signature in a message
  5814. //
  5815. //  dwIndex is a zero-based index of the SignerInfo to be countersigned.
  5816. //--------------------------------------------------------------------------
  5817. BOOL
  5818. WINAPI
  5819. CryptMsgCountersign(
  5820.     IN OUT HCRYPTMSG            hCryptMsg,
  5821.     IN DWORD                    dwIndex,
  5822.     IN DWORD                    cCountersigners,
  5823.     IN PCMSG_SIGNER_ENCODE_INFO rgCountersigners
  5824.     );
  5825.  
  5826. //+-------------------------------------------------------------------------
  5827. //  Countersign an already-existing signature (encoded SignerInfo).
  5828. //  Output an encoded SignerInfo blob, suitable for use as a countersignature
  5829. //  attribute in the unauthenticated attributes of a signed-data or
  5830. //  signed-and-enveloped-data message.
  5831. //--------------------------------------------------------------------------
  5832. BOOL
  5833. WINAPI
  5834. CryptMsgCountersignEncoded(
  5835.     IN DWORD                    dwEncodingType,
  5836.     IN PBYTE                    pbSignerInfo,
  5837.     IN DWORD                    cbSignerInfo,
  5838.     IN DWORD                    cCountersigners,
  5839.     IN PCMSG_SIGNER_ENCODE_INFO rgCountersigners,
  5840.     OUT PBYTE                   pbCountersignature,
  5841.     IN OUT PDWORD               pcbCountersignature
  5842.     );
  5843.  
  5844.  
  5845.  
  5846.  
  5847. //+-------------------------------------------------------------------------
  5848. //  CryptMsg OID installable functions
  5849. //--------------------------------------------------------------------------
  5850.  
  5851. typedef void * (WINAPI *PFN_CMSG_ALLOC) (
  5852.     IN size_t cb
  5853.     );
  5854.  
  5855. typedef void (WINAPI *PFN_CMSG_FREE)(
  5856.     IN void *pv
  5857.     );
  5858.  
  5859. // Note, the following 3 installable functions are obsolete and have been
  5860. // replaced with GenContentEncryptKey, ExportKeyTrans, ExportKeyAgree,
  5861. // ExportMailList, ImportKeyTrans, ImportKeyAgree and ImportMailList
  5862. // installable functions.
  5863.  
  5864. // If *phCryptProv is NULL upon entry, then, if supported, the installable
  5865. // function should acquire a default provider and return. Note, its up
  5866. // to the installable function to release at process detach.
  5867. //
  5868. // If paiEncrypt->Parameters.cbData is 0, then, the callback may optionally
  5869. // return default encoded parameters in *ppbEncryptParameters and
  5870. // *pcbEncryptParameters. pfnAlloc must be called for the allocation.
  5871. #define CMSG_OID_GEN_ENCRYPT_KEY_FUNC   "CryptMsgDllGenEncryptKey"
  5872. typedef BOOL (WINAPI *PFN_CMSG_GEN_ENCRYPT_KEY) (
  5873.     IN OUT HCRYPTPROV               *phCryptProv,
  5874.     IN PCRYPT_ALGORITHM_IDENTIFIER  paiEncrypt,
  5875.     IN PVOID                        pvEncryptAuxInfo,
  5876.     IN PCERT_PUBLIC_KEY_INFO        pPublicKeyInfo,
  5877.     IN PFN_CMSG_ALLOC               pfnAlloc,
  5878.     OUT HCRYPTKEY                   *phEncryptKey,
  5879.     OUT PBYTE                       *ppbEncryptParameters,
  5880.     OUT PDWORD                      pcbEncryptParameters
  5881.     );
  5882.  
  5883. #define CMSG_OID_EXPORT_ENCRYPT_KEY_FUNC   "CryptMsgDllExportEncryptKey"
  5884. typedef BOOL (WINAPI *PFN_CMSG_EXPORT_ENCRYPT_KEY) (
  5885.     IN HCRYPTPROV                   hCryptProv,
  5886.     IN HCRYPTKEY                    hEncryptKey,
  5887.     IN PCERT_PUBLIC_KEY_INFO        pPublicKeyInfo,
  5888.     OUT PBYTE                       pbData,
  5889.     IN OUT PDWORD                   pcbData
  5890.     );
  5891.  
  5892. #define CMSG_OID_IMPORT_ENCRYPT_KEY_FUNC   "CryptMsgDllImportEncryptKey"
  5893. typedef BOOL (WINAPI *PFN_CMSG_IMPORT_ENCRYPT_KEY) (
  5894.     IN HCRYPTPROV                   hCryptProv,
  5895.     IN DWORD                        dwKeySpec,
  5896.     IN PCRYPT_ALGORITHM_IDENTIFIER  paiEncrypt,
  5897.     IN PCRYPT_ALGORITHM_IDENTIFIER  paiPubKey,
  5898.     IN PBYTE                        pbEncodedKey,
  5899.     IN DWORD                        cbEncodedKey,
  5900.     OUT HCRYPTKEY                   *phEncryptKey
  5901.     );
  5902.  
  5903.  
  5904. // To get the default installable function for GenContentEncryptKey,
  5905. // ExportKeyTrans, ExportKeyAgree, ExportMailList, ImportKeyTrans,
  5906. // ImportKeyAgree or ImportMailList call CryptGetOIDFunctionAddress()
  5907. // with the pszOID argument set to the following constant. dwEncodingType
  5908. // should be set to CRYPT_ASN_ENCODING or X509_ASN_ENCODING.
  5909. #define CMSG_DEFAULT_INSTALLABLE_FUNC_OID   ((LPCSTR) 1)
  5910.  
  5911. //+-------------------------------------------------------------------------
  5912. //  Content Encrypt Info
  5913. //
  5914. //  The following data structure contains the information shared between
  5915. //  the GenContentEncryptKey and the ExportKeyTrans, ExportKeyAgree and
  5916. //  ExportMailList installable functions.
  5917. //--------------------------------------------------------------------------
  5918. typedef struct _CMSG_CONTENT_ENCRYPT_INFO {
  5919.     DWORD                       cbSize;
  5920.     HCRYPTPROV                  hCryptProv;
  5921.     CRYPT_ALGORITHM_IDENTIFIER  ContentEncryptionAlgorithm;
  5922.     void                        *pvEncryptionAuxInfo;
  5923.     DWORD                       cRecipients;
  5924.     PCMSG_RECIPIENT_ENCODE_INFO rgCmsRecipients;
  5925.     PFN_CMSG_ALLOC              pfnAlloc;
  5926.     PFN_CMSG_FREE               pfnFree;
  5927.     DWORD                       dwEncryptFlags;
  5928.     HCRYPTKEY                   hContentEncryptKey;
  5929.     DWORD                       dwFlags;
  5930. } CMSG_CONTENT_ENCRYPT_INFO, *PCMSG_CONTENT_ENCRYPT_INFO;
  5931.  
  5932. #define CMSG_CONTENT_ENCRYPT_PAD_ENCODED_LEN_FLAG   0x00000001
  5933.  
  5934. #define CMSG_CONTENT_ENCRYPT_FREE_PARA_FLAG         0x00000001
  5935. #define CMSG_CONTENT_ENCRYPT_RELEASE_CONTEXT_FLAG   0x00008000
  5936.  
  5937. //+-------------------------------------------------------------------------
  5938. // Upon input, ContentEncryptInfo has been initialized from the
  5939. // EnvelopedEncodeInfo.
  5940. //
  5941. // Note, if rgpRecipients instead of rgCmsRecipients are set in the
  5942. // EnvelopedEncodeInfo, then, the rgpRecipients have been converted
  5943. // to rgCmsRecipients in the ContentEncryptInfo.
  5944. //
  5945. // The following fields may be changed in ContentEncryptInfo:
  5946. //      hContentEncryptKey
  5947. //      hCryptProv
  5948. //      ContentEncryptionAlgorithm.Parameters
  5949. //      dwFlags
  5950. //
  5951. // All other fields in the ContentEncryptInfo are READONLY.
  5952. //
  5953. // If CMSG_CONTENT_ENCRYPT_PAD_ENCODED_LEN_FLAG is set upon entry
  5954. // in dwEncryptFlags, then, any potentially variable length encoded
  5955. // output should be padded with zeroes to always obtain the
  5956. // same maximum encoded length. This is necessary for
  5957. // CryptMsgCalculateEncodedLength() or CryptMsgOpenToEncode() with
  5958. // definite length streaming.
  5959. //
  5960. // The hContentEncryptKey must be updated.
  5961. //
  5962. // If hCryptProv is NULL upon input, then, it must be updated.
  5963. // If a HCRYPTPROV is acquired that must be released, then, the
  5964. // CMSG_CONTENT_ENCRYPT_RELEASE_CONTEXT_FLAG must be set in dwFlags.
  5965. //
  5966. // If ContentEncryptionAlgorithm.Parameters is updated, then, the
  5967. // CMSG_CONTENT_ENCRYPT_FREE_PARA_FLAG must be set in dwFlags. pfnAlloc and
  5968. // pfnFree must be used for doing the allocation.
  5969. //
  5970. // ContentEncryptionAlgorithm.pszObjId is used to get the OIDFunctionAddress.
  5971. //--------------------------------------------------------------------------
  5972. #define CMSG_OID_GEN_CONTENT_ENCRYPT_KEY_FUNC  "CryptMsgDllGenContentEncryptKey"
  5973. typedef BOOL (WINAPI *PFN_CMSG_GEN_CONTENT_ENCRYPT_KEY) (
  5974.     IN OUT PCMSG_CONTENT_ENCRYPT_INFO pContentEncryptInfo,
  5975.     IN DWORD dwFlags,
  5976.     IN OPTIONAL void *pvReserved
  5977.     );
  5978.  
  5979. //+-------------------------------------------------------------------------
  5980. //  Key Transport Encrypt Info
  5981. //
  5982. //  The following data structure contains the information updated by the
  5983. //  ExportKeyTrans installable function.
  5984. //--------------------------------------------------------------------------
  5985. typedef struct _CMSG_KEY_TRANS_ENCRYPT_INFO {
  5986.     DWORD                       cbSize;
  5987.     DWORD                       dwRecipientIndex;
  5988.     CRYPT_ALGORITHM_IDENTIFIER  KeyEncryptionAlgorithm;
  5989.     CRYPT_DATA_BLOB             EncryptedKey;
  5990.     DWORD                       dwFlags;
  5991. } CMSG_KEY_TRANS_ENCRYPT_INFO, *PCMSG_KEY_TRANS_ENCRYPT_INFO;
  5992.  
  5993. #define CMSG_KEY_TRANS_ENCRYPT_FREE_PARA_FLAG       0x00000001
  5994.  
  5995.  
  5996. //+-------------------------------------------------------------------------
  5997. // Upon input, KeyTransEncryptInfo has been initialized from the
  5998. // KeyTransEncodeInfo.
  5999. //
  6000. // The following fields may be changed in KeyTransEncryptInfo:
  6001. //      EncryptedKey
  6002. //      KeyEncryptionAlgorithm.Parameters
  6003. //      dwFlags
  6004. //
  6005. // All other fields in the KeyTransEncryptInfo are READONLY.
  6006. //
  6007. // The EncryptedKey must be updated. The pfnAlloc and pfnFree specified in
  6008. // ContentEncryptInfo must be used for doing the allocation.
  6009. //
  6010. // If the KeyEncryptionAlgorithm.Parameters is updated, then, the
  6011. // CMSG_KEY_TRANS_ENCRYPT_FREE_PARA_FLAG must be set in dwFlags.
  6012. // The pfnAlloc and pfnFree specified in ContentEncryptInfo must be used
  6013. // for doing the allocation.
  6014. //
  6015. // KeyEncryptionAlgorithm.pszObjId is used to get the OIDFunctionAddress.
  6016. //--------------------------------------------------------------------------
  6017. #define CMSG_OID_EXPORT_KEY_TRANS_FUNC  "CryptMsgDllExportKeyTrans"
  6018. typedef BOOL (WINAPI *PFN_CMSG_EXPORT_KEY_TRANS) (
  6019.     IN PCMSG_CONTENT_ENCRYPT_INFO pContentEncryptInfo,
  6020.     IN PCMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO pKeyTransEncodeInfo,
  6021.     IN OUT PCMSG_KEY_TRANS_ENCRYPT_INFO pKeyTransEncryptInfo,
  6022.     IN DWORD dwFlags,
  6023.     IN OPTIONAL void *pvReserved
  6024.     );
  6025.  
  6026. //+-------------------------------------------------------------------------
  6027. //  Key Agree Key Encrypt Info
  6028. //
  6029. //  The following data structure contains the information updated by the
  6030. //  ExportKeyAgree installable function for each encrypted key agree
  6031. //  recipient.
  6032. //--------------------------------------------------------------------------
  6033. typedef struct _CMSG_KEY_AGREE_KEY_ENCRYPT_INFO {
  6034.     DWORD                       cbSize;
  6035.     CRYPT_DATA_BLOB             EncryptedKey;
  6036. } CMSG_KEY_AGREE_KEY_ENCRYPT_INFO, *PCMSG_KEY_AGREE_KEY_ENCRYPT_INFO;
  6037.  
  6038. //+-------------------------------------------------------------------------
  6039. //  Key Agree Encrypt Info
  6040. //
  6041. //  The following data structure contains the information applicable to
  6042. //  all recipients. Its updated by the ExportKeyAgree installable function.
  6043. //--------------------------------------------------------------------------
  6044. typedef struct _CMSG_KEY_AGREE_ENCRYPT_INFO {
  6045.     DWORD                       cbSize;
  6046.     DWORD                       dwRecipientIndex;
  6047.     CRYPT_ALGORITHM_IDENTIFIER  KeyEncryptionAlgorithm;
  6048.     CRYPT_DATA_BLOB             UserKeyingMaterial;
  6049.     DWORD                       dwOriginatorChoice;
  6050.     union {
  6051.         // CMSG_KEY_AGREE_ORIGINATOR_CERT
  6052.         CERT_ID                     OriginatorCertId;
  6053.         // CMSG_KEY_AGREE_ORIGINATOR_PUBLIC_KEY
  6054.         CERT_PUBLIC_KEY_INFO        OriginatorPublicKeyInfo;
  6055.     };
  6056.     DWORD                       cKeyAgreeKeyEncryptInfo;
  6057.     PCMSG_KEY_AGREE_KEY_ENCRYPT_INFO *rgpKeyAgreeKeyEncryptInfo;
  6058.     DWORD                       dwFlags;
  6059. } CMSG_KEY_AGREE_ENCRYPT_INFO, *PCMSG_KEY_AGREE_ENCRYPT_INFO;
  6060.  
  6061. #define CMSG_KEY_AGREE_ENCRYPT_FREE_PARA_FLAG           0x00000001
  6062. #define CMSG_KEY_AGREE_ENCRYPT_FREE_MATERIAL_FLAG       0x00000002
  6063. #define CMSG_KEY_AGREE_ENCRYPT_FREE_PUBKEY_ALG_FLAG     0x00000004
  6064. #define CMSG_KEY_AGREE_ENCRYPT_FREE_PUBKEY_PARA_FLAG    0x00000008
  6065. #define CMSG_KEY_AGREE_ENCRYPT_FREE_PUBKEY_BITS_FLAG    0x00000010
  6066.  
  6067.  
  6068. //+-------------------------------------------------------------------------
  6069. // Upon input, KeyAgreeEncryptInfo has been initialized from the
  6070. // KeyAgreeEncodeInfo.
  6071. //
  6072. // The following fields may be changed in KeyAgreeEncryptInfo:
  6073. //      KeyEncryptionAlgorithm.Parameters
  6074. //      UserKeyingMaterial
  6075. //      dwOriginatorChoice
  6076. //      OriginatorCertId
  6077. //      OriginatorPublicKeyInfo
  6078. //      dwFlags
  6079. //
  6080. // All other fields in the KeyAgreeEncryptInfo are READONLY.
  6081. //
  6082. // If the KeyEncryptionAlgorithm.Parameters is updated, then, the
  6083. // CMSG_KEY_AGREE_ENCRYPT_FREE_PARA_FLAG must be set in dwFlags.
  6084. // The pfnAlloc and pfnFree specified in ContentEncryptInfo must be used
  6085. // for doing the allocation.
  6086. //
  6087. // If the UserKeyingMaterial is updated, then, the
  6088. // CMSG_KEY_AGREE_ENCRYPT_FREE_MATERIAL_FLAG must be set in dwFlags.
  6089. // pfnAlloc and pfnFree must be used for doing the allocation.
  6090. //
  6091. // The dwOriginatorChoice must be updated to either
  6092. // CMSG_KEY_AGREE_ORIGINATOR_CERT or CMSG_KEY_AGREE_ORIGINATOR_PUBLIC_KEY.
  6093. //
  6094. // If the OriginatorPublicKeyInfo is updated, then, the appropriate
  6095. // CMSG_KEY_AGREE_ENCRYPT_FREE_PUBKEY_*_FLAG must be set in dwFlags and
  6096. // pfnAlloc and pfnFree must be used for doing the allocation.
  6097. //
  6098. // If CMSG_CONTENT_ENCRYPT_PAD_ENCODED_LEN_FLAG is set upon entry
  6099. // in pContentEncryptInfo->dwEncryptFlags, then, the OriginatorPublicKeyInfo's
  6100. // Ephemeral PublicKey should be padded with zeroes to always obtain the
  6101. // same maximum encoded length. Note, the length of the generated ephemeral Y
  6102. // public key can vary depending on the number of leading zero bits.
  6103. //
  6104. // Upon input, the array of *rgpKeyAgreeKeyEncryptInfo has been initialized.
  6105. // The EncryptedKey must be updated for each recipient key.
  6106. // The pfnAlloc and pfnFree specified in
  6107. // ContentEncryptInfo must be used for doing the allocation.
  6108. //
  6109. // KeyEncryptionAlgorithm.pszObjId is used to get the OIDFunctionAddress.
  6110. //--------------------------------------------------------------------------
  6111. #define CMSG_OID_EXPORT_KEY_AGREE_FUNC  "CryptMsgDllExportKeyAgree"
  6112. typedef BOOL (WINAPI *PFN_CMSG_EXPORT_KEY_AGREE) (
  6113.     IN PCMSG_CONTENT_ENCRYPT_INFO pContentEncryptInfo,
  6114.     IN PCMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO pKeyAgreeEncodeInfo,
  6115.     IN OUT PCMSG_KEY_AGREE_ENCRYPT_INFO pKeyAgreeEncryptInfo,
  6116.     IN DWORD dwFlags,
  6117.     IN OPTIONAL void *pvReserved
  6118.     );
  6119.  
  6120. //+-------------------------------------------------------------------------
  6121. //  Mail List Encrypt Info
  6122. //
  6123. //  The following data structure contains the information updated by the
  6124. //  ExportMailList installable function.
  6125. //--------------------------------------------------------------------------
  6126. typedef struct _CMSG_MAIL_LIST_ENCRYPT_INFO {
  6127.     DWORD                       cbSize;
  6128.     DWORD                       dwRecipientIndex;
  6129.     CRYPT_ALGORITHM_IDENTIFIER  KeyEncryptionAlgorithm;
  6130.     CRYPT_DATA_BLOB             EncryptedKey;
  6131.     DWORD                       dwFlags;
  6132. } CMSG_MAIL_LIST_ENCRYPT_INFO, *PCMSG_MAIL_LIST_ENCRYPT_INFO;
  6133.  
  6134. #define CMSG_MAIL_LIST_ENCRYPT_FREE_PARA_FLAG       0x00000001
  6135.  
  6136.  
  6137. //+-------------------------------------------------------------------------
  6138. // Upon input, MailListEncryptInfo has been initialized from the
  6139. // MailListEncodeInfo.
  6140. //
  6141. // The following fields may be changed in MailListEncryptInfo:
  6142. //      EncryptedKey
  6143. //      KeyEncryptionAlgorithm.Parameters
  6144. //      dwFlags
  6145. //
  6146. // All other fields in the MailListEncryptInfo are READONLY.
  6147. //
  6148. // The EncryptedKey must be updated. The pfnAlloc and pfnFree specified in
  6149. // ContentEncryptInfo must be used for doing the allocation.
  6150. //
  6151. // If the KeyEncryptionAlgorithm.Parameters is updated, then, the
  6152. // CMSG_MAIL_LIST_ENCRYPT_FREE_PARA_FLAG must be set in dwFlags.
  6153. // The pfnAlloc and pfnFree specified in ContentEncryptInfo must be used
  6154. // for doing the allocation.
  6155. //
  6156. // KeyEncryptionAlgorithm.pszObjId is used to get the OIDFunctionAddress.
  6157. //--------------------------------------------------------------------------
  6158. #define CMSG_OID_EXPORT_MAIL_LIST_FUNC  "CryptMsgDllExportMailList"
  6159. typedef BOOL (WINAPI *PFN_CMSG_EXPORT_MAIL_LIST) (
  6160.     IN PCMSG_CONTENT_ENCRYPT_INFO pContentEncryptInfo,
  6161.     IN PCMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO pMailListEncodeInfo,
  6162.     IN OUT PCMSG_MAIL_LIST_ENCRYPT_INFO pMailListEncryptInfo,
  6163.     IN DWORD dwFlags,
  6164.     IN OPTIONAL void *pvReserved
  6165.     );
  6166.  
  6167.  
  6168. //+-------------------------------------------------------------------------
  6169. // OID Installable functions for importing an encoded and encrypted content
  6170. // encryption key.
  6171. //
  6172. // There's a different installable function for each CMS Recipient choice:
  6173. //  ImportKeyTrans
  6174. //  ImportKeyAgree
  6175. //  ImportMailList
  6176. //
  6177. // Iterates through the following OIDs to get the OID installable function:
  6178. //   KeyEncryptionOID!ContentEncryptionOID
  6179. //   KeyEncryptionOID
  6180. //   ContentEncryptionOID
  6181. //
  6182. // If the OID installable function doesn't support the specified
  6183. // KeyEncryption and ContentEncryption OIDs, then, return FALSE with
  6184. // LastError set to E_NOTIMPL.
  6185. //--------------------------------------------------------------------------
  6186. #define CMSG_OID_IMPORT_KEY_TRANS_FUNC   "CryptMsgDllImportKeyTrans"
  6187. typedef BOOL (WINAPI *PFN_CMSG_IMPORT_KEY_TRANS) (
  6188.     IN PCRYPT_ALGORITHM_IDENTIFIER pContentEncryptionAlgorithm,
  6189.     IN PCMSG_CTRL_KEY_TRANS_DECRYPT_PARA pKeyTransDecryptPara,
  6190.     IN DWORD dwFlags,
  6191.     IN OPTIONAL void *pvReserved,
  6192.     OUT HCRYPTKEY *phContentEncryptKey
  6193.     );
  6194.  
  6195. #define CMSG_OID_IMPORT_KEY_AGREE_FUNC   "CryptMsgDllImportKeyAgree"
  6196. typedef BOOL (WINAPI *PFN_CMSG_IMPORT_KEY_AGREE) (
  6197.     IN PCRYPT_ALGORITHM_IDENTIFIER pContentEncryptionAlgorithm,
  6198.     IN PCMSG_CTRL_KEY_AGREE_DECRYPT_PARA pKeyAgreeDecryptPara,
  6199.     IN DWORD dwFlags,
  6200.     IN OPTIONAL void *pvReserved,
  6201.     OUT HCRYPTKEY *phContentEncryptKey
  6202.     );
  6203.  
  6204. #define CMSG_OID_IMPORT_MAIL_LIST_FUNC   "CryptMsgDllImportMailList"
  6205. typedef BOOL (WINAPI *PFN_CMSG_IMPORT_MAIL_LIST) (
  6206.     IN PCRYPT_ALGORITHM_IDENTIFIER pContentEncryptionAlgorithm,
  6207.     IN PCMSG_CTRL_MAIL_LIST_DECRYPT_PARA pMailListDecryptPara,
  6208.     IN DWORD dwFlags,
  6209.     IN OPTIONAL void *pvReserved,
  6210.     OUT HCRYPTKEY *phContentEncryptKey
  6211.     );
  6212.  
  6213.  
  6214.  
  6215. //+=========================================================================
  6216. //  Certificate Store Data Structures and APIs
  6217. //==========================================================================
  6218.  
  6219. //+-------------------------------------------------------------------------
  6220. //              In its most basic implementation, a cert store is simply a
  6221. //              collection of certificates and/or CRLs. This is the case when
  6222. //              a cert store is opened with all of its certificates and CRLs
  6223. //              coming from a PKCS #7 encoded cryptographic message.
  6224. //
  6225. //              Nonetheless, all cert stores have the following properties:
  6226. //               - A public key may have more than one certificate in the store.
  6227. //                 For example, a private/public key used for signing may have a
  6228. //                 certificate issued for VISA and another issued for
  6229. //                 Mastercard. Also, when a certificate is renewed there might
  6230. //                 be more than one certificate with the same subject and
  6231. //                 issuer.
  6232. //               - However, each certificate in the store is uniquely
  6233. //                 identified by its Issuer and SerialNumber.
  6234. //               - There's an issuer of subject certificate relationship. A
  6235. //                 certificate's issuer is found by doing a match of
  6236. //                 pSubjectCert->Issuer with pIssuerCert->Subject.
  6237. //                 The relationship is verified by using
  6238. //                 the issuer's public key to verify the subject certificate's
  6239. //                 signature. Note, there might be X.509 v3 extensions
  6240. //                 to assist in finding the issuer certificate.
  6241. //               - Since issuer certificates might be renewed, a subject
  6242. //                 certificate might have more than one issuer certificate.
  6243. //               - There's an issuer of CRL relationship. An
  6244. //                 issuer's CRL is found by doing a match of
  6245. //                 pIssuerCert->Subject with pCrl->Issuer.
  6246. //                 The relationship is verified by using
  6247. //                 the issuer's public key to verify the CRL's
  6248. //                 signature. Note, there might be X.509 v3 extensions
  6249. //                 to assist in finding the CRL.
  6250. //               - Since some issuers might support the X.509 v3 delta CRL
  6251. //                 extensions, an issuer might have more than one CRL.
  6252. //               - The store shouldn't have any redundant certificates or
  6253. //                 CRLs. There shouldn't be two certificates with the same
  6254. //                 Issuer and SerialNumber. There shouldn't be two CRLs with
  6255. //                 the same Issuer, ThisUpdate and NextUpdate.
  6256. //               - The store has NO policy or trust information. No
  6257. //                 certificates are tagged as being "root". Its up to
  6258. //                 the application to maintain a list of CertIds (Issuer +
  6259. //                 SerialNumber) for certificates it trusts.
  6260. //               - The store might contain bad certificates and/or CRLs.
  6261. //                 The issuer's signature of a subject certificate or CRL may
  6262. //                 not verify. Certificates or CRLs may not satisfy their
  6263. //                 time validity requirements. Certificates may be
  6264. //                 revoked.
  6265. //
  6266. //              In addition to the certificates and CRLs, properties can be
  6267. //              stored. There are two predefined property IDs for a user
  6268. //              certificate: CERT_KEY_PROV_HANDLE_PROP_ID and
  6269. //              CERT_KEY_PROV_INFO_PROP_ID. The CERT_KEY_PROV_HANDLE_PROP_ID
  6270. //              is a HCRYPTPROV handle to the private key assoicated
  6271. //              with the certificate. The CERT_KEY_PROV_INFO_PROP_ID contains
  6272. //              information to be used to call
  6273. //              CryptAcquireContext and CryptSetProvParam to get a handle
  6274. //              to the private key associated with the certificate.
  6275. //
  6276. //              There exists two more predefined property IDs for certificates
  6277. //              and CRLs, CERT_SHA1_HASH_PROP_ID and CERT_MD5_HASH_PROP_ID.
  6278. //              If these properties don't already exist, then, a hash of the
  6279. //              content is computed. (CERT_HASH_PROP_ID maps to the default
  6280. //              hash algorithm, currently, CERT_SHA1_HASH_PROP_ID).
  6281. //
  6282. //              There are additional APIs for creating certificate and CRL
  6283. //      contexts not in a store (CertCreateCertificateContext and
  6284. //      CertCreateCRLContext).
  6285. //
  6286. //--------------------------------------------------------------------------
  6287.  
  6288.  
  6289. typedef void *HCERTSTORE;
  6290.  
  6291. //+-------------------------------------------------------------------------
  6292. //  Certificate context.
  6293. //
  6294. //  A certificate context contains both the encoded and decoded representation
  6295. //  of a certificate. A certificate context returned by a cert store function
  6296. //  must be freed by calling the CertFreeCertificateContext function. The
  6297. //  CertDuplicateCertificateContext function can be called to make a duplicate
  6298. //  copy (which also must be freed by calling CertFreeCertificateContext).
  6299. //--------------------------------------------------------------------------
  6300. typedef struct _CERT_CONTEXT {
  6301.     DWORD                   dwCertEncodingType;
  6302.     BYTE                    *pbCertEncoded;
  6303.     DWORD                   cbCertEncoded;
  6304.     PCERT_INFO              pCertInfo;
  6305.     HCERTSTORE              hCertStore;
  6306. } CERT_CONTEXT, *PCERT_CONTEXT;
  6307. typedef const CERT_CONTEXT *PCCERT_CONTEXT;
  6308.  
  6309. //+-------------------------------------------------------------------------
  6310. //  CRL context.
  6311. //
  6312. //  A CRL context contains both the encoded and decoded representation
  6313. //  of a CRL. A CRL context returned by a cert store function
  6314. //  must be freed by calling the CertFreeCRLContext function. The
  6315. //  CertDuplicateCRLContext function can be called to make a duplicate
  6316. //  copy (which also must be freed by calling CertFreeCRLContext).
  6317. //--------------------------------------------------------------------------
  6318. typedef struct _CRL_CONTEXT {
  6319.     DWORD                   dwCertEncodingType;
  6320.     BYTE                    *pbCrlEncoded;
  6321.     DWORD                   cbCrlEncoded;
  6322.     PCRL_INFO               pCrlInfo;
  6323.     HCERTSTORE              hCertStore;
  6324. } CRL_CONTEXT, *PCRL_CONTEXT;
  6325. typedef const CRL_CONTEXT *PCCRL_CONTEXT;
  6326.  
  6327. //+-------------------------------------------------------------------------
  6328. //  Certificate Trust List (CTL) context.
  6329. //
  6330. //  A CTL context contains both the encoded and decoded representation
  6331. //  of a CTL. Also contains an opened HCRYPTMSG handle to the decoded
  6332. //  cryptographic signed message containing the CTL_INFO as its inner content.
  6333. //  pbCtlContent is the encoded inner content of the signed message.
  6334. //
  6335. //  The CryptMsg APIs can be used to extract additional signer information.
  6336. //--------------------------------------------------------------------------
  6337. typedef struct _CTL_CONTEXT {
  6338.     DWORD                   dwMsgAndCertEncodingType;
  6339.     BYTE                    *pbCtlEncoded;
  6340.     DWORD                   cbCtlEncoded;
  6341.     PCTL_INFO               pCtlInfo;
  6342.     HCERTSTORE              hCertStore;
  6343.     HCRYPTMSG               hCryptMsg;
  6344.     BYTE                    *pbCtlContent;
  6345.     DWORD                   cbCtlContent;
  6346. } CTL_CONTEXT, *PCTL_CONTEXT;
  6347. typedef const CTL_CONTEXT *PCCTL_CONTEXT;
  6348.  
  6349. //+-------------------------------------------------------------------------
  6350. //  Certificate, CRL and CTL property IDs
  6351. //
  6352. //  See CertSetCertificateContextProperty or CertGetCertificateContextProperty
  6353. //  for usage information.
  6354. //--------------------------------------------------------------------------
  6355. #define CERT_KEY_PROV_HANDLE_PROP_ID        1
  6356. #define CERT_KEY_PROV_INFO_PROP_ID          2
  6357. #define CERT_SHA1_HASH_PROP_ID              3
  6358. #define CERT_MD5_HASH_PROP_ID               4
  6359. #define CERT_HASH_PROP_ID                   CERT_SHA1_HASH_PROP_ID
  6360. #define CERT_KEY_CONTEXT_PROP_ID            5
  6361. #define CERT_KEY_SPEC_PROP_ID               6
  6362. #define CERT_IE30_RESERVED_PROP_ID          7
  6363. #define CERT_PUBKEY_HASH_RESERVED_PROP_ID   8
  6364. #define CERT_ENHKEY_USAGE_PROP_ID           9
  6365. #define CERT_CTL_USAGE_PROP_ID              CERT_ENHKEY_USAGE_PROP_ID
  6366. #define CERT_NEXT_UPDATE_LOCATION_PROP_ID   10
  6367. #define CERT_FRIENDLY_NAME_PROP_ID          11
  6368. #define CERT_PVK_FILE_PROP_ID               12
  6369. #define CERT_DESCRIPTION_PROP_ID            13
  6370. #define CERT_ACCESS_STATE_PROP_ID           14
  6371. #define CERT_SIGNATURE_HASH_PROP_ID         15
  6372. #define CERT_SMART_CARD_DATA_PROP_ID        16
  6373. #define CERT_EFS_PROP_ID                    17
  6374. #define CERT_FORTEZZA_DATA_PROP_ID          18
  6375. #define CERT_ARCHIVED_PROP_ID               19
  6376. #define CERT_KEY_IDENTIFIER_PROP_ID         20
  6377. #define CERT_AUTO_ENROLL_PROP_ID            21
  6378. #define CERT_PUBKEY_ALG_PARA_PROP_ID        22
  6379.  
  6380. #define CERT_FIRST_RESERVED_PROP_ID         23
  6381. // Note, 32 - 35 are reserved for the CERT, CRL, CTL and KeyId file element IDs.
  6382. #define CERT_LAST_RESERVED_PROP_ID          0x00007FFF
  6383. #define CERT_FIRST_USER_PROP_ID             0x00008000
  6384. #define CERT_LAST_USER_PROP_ID              0x0000FFFF
  6385.  
  6386.  
  6387. #define IS_CERT_HASH_PROP_ID(X)     (CERT_SHA1_HASH_PROP_ID == (X) || \
  6388.                                         CERT_MD5_HASH_PROP_ID == (X) || \
  6389.                                         CERT_SIGNATURE_HASH_PROP_ID == (X))
  6390.  
  6391. //+-------------------------------------------------------------------------
  6392. //  Access State flags returned by CERT_ACCESS_STATE_PROP_ID. Note,
  6393. //  CERT_ACCESS_PROP_ID is read only.
  6394. //--------------------------------------------------------------------------
  6395.  
  6396. // Set if context property writes are persisted. For instance, not set for
  6397. // memory store contexts. Set for registry based stores opened as read or write.
  6398. // Not set for registry based stores opened as read only.
  6399. #define CERT_ACCESS_STATE_WRITE_PERSIST_FLAG    0x1
  6400.  
  6401. // Set if context resides in a SYSTEM or SYSTEM_REGISTRY store.
  6402. #define CERT_ACCESS_STATE_SYSTEM_STORE_FLAG     0x2
  6403.  
  6404. //+-------------------------------------------------------------------------
  6405. //  Cryptographic Key Provider Information
  6406. //
  6407. //  CRYPT_KEY_PROV_INFO defines the CERT_KEY_PROV_INFO_PROP_ID's pvData.
  6408. //
  6409. //  The CRYPT_KEY_PROV_INFO fields are passed to CryptAcquireContext
  6410. //  to get a HCRYPTPROV handle. The optional CRYPT_KEY_PROV_PARAM fields are
  6411. //  passed to CryptSetProvParam to further initialize the provider.
  6412. //
  6413. //  The dwKeySpec field identifies the private key to use from the container
  6414. //  For example, AT_KEYEXCHANGE or AT_SIGNATURE.
  6415. //--------------------------------------------------------------------------
  6416. typedef struct _CRYPT_KEY_PROV_PARAM {
  6417.     DWORD           dwParam;
  6418.     BYTE            *pbData;
  6419.     DWORD           cbData;
  6420.     DWORD           dwFlags;
  6421. } CRYPT_KEY_PROV_PARAM, *PCRYPT_KEY_PROV_PARAM;
  6422.  
  6423. typedef struct _CRYPT_KEY_PROV_INFO {
  6424.     LPWSTR                  pwszContainerName;
  6425.     LPWSTR                  pwszProvName;
  6426.     DWORD                   dwProvType;
  6427.     DWORD                   dwFlags;
  6428.     DWORD                   cProvParam;
  6429.     PCRYPT_KEY_PROV_PARAM   rgProvParam;
  6430.     DWORD                   dwKeySpec;
  6431. } CRYPT_KEY_PROV_INFO, *PCRYPT_KEY_PROV_INFO;
  6432.  
  6433. //+-------------------------------------------------------------------------
  6434. //  The following flag should be set in the above dwFlags to enable
  6435. //  a CertSetCertificateContextProperty(CERT_KEY_CONTEXT_PROP_ID) after a
  6436. //  CryptAcquireContext is done in the Sign or Decrypt Message functions.
  6437. //
  6438. //  The following define must not collide with any of the
  6439. //  CryptAcquireContext dwFlag defines.
  6440. //--------------------------------------------------------------------------
  6441. #define CERT_SET_KEY_PROV_HANDLE_PROP_ID    0x00000001
  6442. #define CERT_SET_KEY_CONTEXT_PROP_ID        0x00000001
  6443.  
  6444. //+-------------------------------------------------------------------------
  6445. //  Certificate Key Context
  6446. //
  6447. //  CERT_KEY_CONTEXT defines the CERT_KEY_CONTEXT_PROP_ID's pvData.
  6448. //--------------------------------------------------------------------------
  6449. typedef struct _CERT_KEY_CONTEXT {
  6450.     DWORD           cbSize;           // sizeof(CERT_KEY_CONTEXT)
  6451.     HCRYPTPROV      hCryptProv;
  6452.     DWORD           dwKeySpec;
  6453. } CERT_KEY_CONTEXT, *PCERT_KEY_CONTEXT;
  6454.  
  6455. //+-------------------------------------------------------------------------
  6456. //  Certificate Store Provider Types
  6457. //--------------------------------------------------------------------------
  6458. #define CERT_STORE_PROV_MSG                 ((LPCSTR) 1)
  6459. #define CERT_STORE_PROV_MEMORY              ((LPCSTR) 2)
  6460. #define CERT_STORE_PROV_FILE                ((LPCSTR) 3)
  6461. #define CERT_STORE_PROV_REG                 ((LPCSTR) 4)
  6462.  
  6463. #define CERT_STORE_PROV_PKCS7               ((LPCSTR) 5)
  6464. #define CERT_STORE_PROV_SERIALIZED          ((LPCSTR) 6)
  6465. #define CERT_STORE_PROV_FILENAME_A          ((LPCSTR) 7)
  6466. #define CERT_STORE_PROV_FILENAME_W          ((LPCSTR) 8)
  6467. #define CERT_STORE_PROV_FILENAME            CERT_STORE_PROV_FILENAME_W
  6468. #define CERT_STORE_PROV_SYSTEM_A            ((LPCSTR) 9)
  6469. #define CERT_STORE_PROV_SYSTEM_W            ((LPCSTR) 10)
  6470. #define CERT_STORE_PROV_SYSTEM              CERT_STORE_PROV_SYSTEM_W
  6471.  
  6472. #define CERT_STORE_PROV_COLLECTION          ((LPCSTR) 11)
  6473. #define CERT_STORE_PROV_SYSTEM_REGISTRY_A   ((LPCSTR) 12)
  6474. #define CERT_STORE_PROV_SYSTEM_REGISTRY_W   ((LPCSTR) 13)
  6475. #define CERT_STORE_PROV_SYSTEM_REGISTRY     CERT_STORE_PROV_SYSTEM_REGISTRY_W
  6476. #define CERT_STORE_PROV_PHYSICAL_W          ((LPCSTR) 14)
  6477. #define CERT_STORE_PROV_PHYSICAL            CERT_STORE_PROV_PHYSICAL_W
  6478. #define CERT_STORE_PROV_SMART_CARD_W        ((LPCSTR) 15)
  6479. #define CERT_STORE_PROV_SMART_CARD          CERT_STORE_PROV_SMART_CARD_W
  6480. #define CERT_STORE_PROV_LDAP_W              ((LPCSTR) 16)
  6481. #define CERT_STORE_PROV_LDAP                CERT_STORE_PROV_LDAP_W
  6482.  
  6483. #define sz_CERT_STORE_PROV_MEMORY           "Memory"
  6484. #define sz_CERT_STORE_PROV_FILENAME_W       "File"
  6485. #define sz_CERT_STORE_PROV_FILENAME         sz_CERT_STORE_PROV_FILENAME_W
  6486. #define sz_CERT_STORE_PROV_SYSTEM_W         "System"
  6487. #define sz_CERT_STORE_PROV_SYSTEM           sz_CERT_STORE_PROV_SYSTEM_W
  6488. #define sz_CERT_STORE_PROV_PKCS7            "PKCS7"
  6489. #define sz_CERT_STORE_PROV_SERIALIZED       "Serialized"
  6490.  
  6491. #define sz_CERT_STORE_PROV_COLLECTION       "Collection"
  6492. #define sz_CERT_STORE_PROV_SYSTEM_REGISTRY_W "SystemRegistry"
  6493. #define sz_CERT_STORE_PROV_SYSTEM_REGISTRY  sz_CERT_STORE_PROV_SYSTEM_REGISTRY_W
  6494. #define sz_CERT_STORE_PROV_PHYSICAL_W       "Physical"
  6495. #define sz_CERT_STORE_PROV_PHYSICAL         sz_CERT_STORE_PROV_PHYSICAL_W
  6496. #define sz_CERT_STORE_PROV_SMART_CARD_W     "SmartCard"
  6497. #define sz_CERT_STORE_PROV_SMART_CARD       sz_CERT_STORE_PROV_SMART_CARD_W
  6498. #define sz_CERT_STORE_PROV_LDAP_W           "Ldap"
  6499. #define sz_CERT_STORE_PROV_LDAP             sz_CERT_STORE_PROV_LDAP_W
  6500.  
  6501. //+-------------------------------------------------------------------------
  6502. //  Certificate Store verify/results flags
  6503. //--------------------------------------------------------------------------
  6504. #define CERT_STORE_SIGNATURE_FLAG           0x00000001
  6505. #define CERT_STORE_TIME_VALIDITY_FLAG       0x00000002
  6506. #define CERT_STORE_REVOCATION_FLAG          0x00000004
  6507. #define CERT_STORE_NO_CRL_FLAG              0x00010000
  6508. #define CERT_STORE_NO_ISSUER_FLAG           0x00020000
  6509.  
  6510.  
  6511. //+-------------------------------------------------------------------------
  6512. //  Certificate Store open/property flags
  6513. //--------------------------------------------------------------------------
  6514. #define CERT_STORE_NO_CRYPT_RELEASE_FLAG                0x00000001
  6515. #define CERT_STORE_SET_LOCALIZED_NAME_FLAG              0x00000002
  6516. #define CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG     0x00000004
  6517. #define CERT_STORE_DELETE_FLAG                          0x00000010
  6518. #define CERT_STORE_MANIFOLD_FLAG                        0x00000100
  6519. #define CERT_STORE_ENUM_ARCHIVED_FLAG                   0x00000200
  6520. #define CERT_STORE_UPDATE_KEYID_FLAG                    0x00000400
  6521. #define CERT_STORE_READONLY_FLAG                        0x00008000
  6522. #define CERT_STORE_OPEN_EXISTING_FLAG                   0x00004000
  6523. #define CERT_STORE_CREATE_NEW_FLAG                      0x00002000
  6524. #define CERT_STORE_MAXIMUM_ALLOWED_FLAG                 0x00001000
  6525.  
  6526. //+-------------------------------------------------------------------------
  6527. //  Certificate Store Provider flags are in the HiWord (0xFFFF0000)
  6528. //--------------------------------------------------------------------------
  6529.  
  6530. //+-------------------------------------------------------------------------
  6531. //  Certificate System Store Flag Values
  6532. //--------------------------------------------------------------------------
  6533. // Includes flags and location
  6534. #define CERT_SYSTEM_STORE_MASK                  0xFFFF0000
  6535.  
  6536. // Set if pvPara points to a CERT_SYSTEM_STORE_RELOCATE_PARA structure
  6537. #define CERT_SYSTEM_STORE_RELOCATE_FLAG         0x80000000
  6538.  
  6539. typedef struct _CERT_SYSTEM_STORE_RELOCATE_PARA {
  6540.     union {
  6541.         HKEY                hKeyBase;
  6542.         void                *pvBase;
  6543.     };
  6544.     union {
  6545.         void                *pvSystemStore;
  6546.         LPCSTR              pszSystemStore;
  6547.         LPCWSTR             pwszSystemStore;
  6548.     };
  6549. } CERT_SYSTEM_STORE_RELOCATE_PARA, *PCERT_SYSTEM_STORE_RELOCATE_PARA;
  6550.  
  6551. // By default, when the CurrentUser "Root" store is opened, any SystemRegistry
  6552. // roots not also on the protected root list are deleted from the cache before
  6553. // CertOpenStore() returns. Set the following flag to return all the roots
  6554. // in the SystemRegistry without checking the protected root list.
  6555. #define CERT_SYSTEM_STORE_UNPROTECTED_FLAG      0x40000000
  6556.  
  6557. // Location of the system store:
  6558. #define CERT_SYSTEM_STORE_LOCATION_MASK         0x00FF0000
  6559. #define CERT_SYSTEM_STORE_LOCATION_SHIFT        16
  6560.  
  6561.  
  6562. //  Registry: HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE
  6563. #define CERT_SYSTEM_STORE_CURRENT_USER_ID       1
  6564. #define CERT_SYSTEM_STORE_LOCAL_MACHINE_ID      2
  6565. //  Registry: HKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography\Services
  6566. #define CERT_SYSTEM_STORE_CURRENT_SERVICE_ID    4
  6567. #define CERT_SYSTEM_STORE_SERVICES_ID           5
  6568. //  Registry: HKEY_USERS
  6569. #define CERT_SYSTEM_STORE_USERS_ID              6
  6570.  
  6571. //  Registry: HKEY_CURRENT_USER\Software\Policies\Microsoft\SystemCertificates
  6572. #define CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY_ID    7
  6573. //  Registry: HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\SystemCertificates
  6574. #define CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY_ID   8
  6575.  
  6576. //  Registry: HKEY_LOCAL_MACHINE\Software\Microsoft\EnterpriseCertificates
  6577. #define CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE_ID     9
  6578.  
  6579. #define CERT_SYSTEM_STORE_CURRENT_USER          \
  6580.     (CERT_SYSTEM_STORE_CURRENT_USER_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6581. #define CERT_SYSTEM_STORE_LOCAL_MACHINE         \
  6582.     (CERT_SYSTEM_STORE_LOCAL_MACHINE_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6583. #define CERT_SYSTEM_STORE_CURRENT_SERVICE       \
  6584.     (CERT_SYSTEM_STORE_CURRENT_SERVICE_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6585. #define CERT_SYSTEM_STORE_SERVICES              \
  6586.     (CERT_SYSTEM_STORE_SERVICES_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6587. #define CERT_SYSTEM_STORE_USERS                 \
  6588.     (CERT_SYSTEM_STORE_USERS_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6589.  
  6590. #define CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY   \
  6591.     (CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY_ID << \
  6592.         CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6593. #define CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY  \
  6594.     (CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY_ID << \
  6595.         CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6596.  
  6597. #define CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE  \
  6598.     (CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE_ID << \
  6599.         CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6600.  
  6601.  
  6602. //+-------------------------------------------------------------------------
  6603. //  Group Policy Store Defines
  6604. //--------------------------------------------------------------------------
  6605. // Registry path to the Group Policy system stores
  6606. #define CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH \
  6607.     L"Software\\Policies\\Microsoft\\SystemCertificates"
  6608.  
  6609.  
  6610. //+-------------------------------------------------------------------------
  6611. //  EFS Defines
  6612. //--------------------------------------------------------------------------
  6613. // Registry path to the EFS EFSBlob SubKey - Value type is REG_BINARY
  6614. #define CERT_EFSBLOB_REGPATH    \
  6615.     CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH L"\\EFS"
  6616. #define CERT_EFSBLOB_VALUE_NAME L"EFSBlob"
  6617.  
  6618. //+-------------------------------------------------------------------------
  6619. //  Protected Root Defines
  6620. //--------------------------------------------------------------------------
  6621. // Registry path to the Protected Roots Flags SubKey
  6622. #define CERT_PROT_ROOT_FLAGS_REGPATH    \
  6623.     CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH L"\\Root\\ProtectedRoots"
  6624. #define CERT_PROT_ROOT_FLAGS_VALUE_NAME L"Flags"
  6625.  
  6626. // Set the following flag to inhibit the opening of the CurrentUser's
  6627. // .Default physical store when opening the CurrentUser's "Root" system store.
  6628. // The .Default physical store open's the CurrentUser SystemRegistry "Root"
  6629. // store.
  6630. #define CERT_PROT_ROOT_DISABLE_CURRENT_USER_FLAG    0x1
  6631.  
  6632. // Set the following flag to inhibit the adding of roots from the
  6633. // CurrentUser SystemRegistry "Root" store to the protected root list
  6634. // when the "Root" store is initially protected.
  6635. #define CERT_PROT_ROOT_INHIBIT_ADD_AT_INIT_FLAG     0x2
  6636.  
  6637. // Set the following flag to inhibit the purging of protected roots from the
  6638. // CurrentUser SystemRegistry "Root" store that are
  6639. // also in the LocalMachine SystemRegistry "Root" store. Note, when not
  6640. // disabled, the purging is done silently without UI.
  6641. #define CERT_PROT_ROOT_INHIBIT_PURGE_LM_FLAG        0x4
  6642.  
  6643. // Set the following flag to only open the .LocalMachineGroupPolicy
  6644. // physical store when opening the CurrentUser's "Root" system store.
  6645. #define CERT_PROT_ROOT_ONLY_LM_GPT_FLAG             0x8
  6646.  
  6647.  
  6648. //+-------------------------------------------------------------------------
  6649. //  Certificate Registry Store Flag Values (CERT_STORE_REG)
  6650. //--------------------------------------------------------------------------
  6651.  
  6652. // Set this flag if the HKEY passed in pvPara points to a remote computer
  6653. // registry key.
  6654. #define CERT_REGISTRY_STORE_REMOTE_FLAG         0x10000
  6655.  
  6656. // Set this flag if the contexts are to be persisted as a single serialized
  6657. // store in the registry. Mainly used for stores downloaded from the GPT.
  6658. // Such as the CurrentUserGroupPolicy or LocalMachineGroupPolicy stores.
  6659. #define CERT_REGISTRY_STORE_SERIALIZED_FLAG     0x20000
  6660.  
  6661. // The following flags are for internal use. When set, the
  6662. // pvPara parameter passed to CertOpenStore is a pointer to the following
  6663. // data structure and not the HKEY. The above CERT_REGISTRY_STORE_REMOTE_FLAG
  6664. // is also set if hKeyBase was obtained via RegConnectRegistry().
  6665. #define CERT_REGISTRY_STORE_CLIENT_GPT_FLAG     0x80000000
  6666. #define CERT_REGISTRY_STORE_LM_GPT_FLAG         0x01000000
  6667.  
  6668. typedef struct _CERT_REGISTRY_STORE_CLIENT_GPT_PARA {
  6669.     HKEY                hKeyBase;
  6670.     LPWSTR              pwszRegPath;
  6671. } CERT_REGISTRY_STORE_CLIENT_GPT_PARA, *PCERT_REGISTRY_STORE_CLIENT_GPT_PARA;
  6672.  
  6673. // The following flag is for internal use. When set, the contexts are
  6674. // persisted into roaming files instead of the registry. Such as, the
  6675. // CurrentUser "My" store. When this flag is set, the following data structure
  6676. // is passed to CertOpenStore instead of HKEY.
  6677. #define CERT_REGISTRY_STORE_ROAMING_FLAG        0x40000
  6678.  
  6679. // hKey may be NULL or non-NULL. When non-NULL, existing contexts are
  6680. // moved from the registry to roaming files.
  6681. typedef struct _CERT_REGISTRY_STORE_ROAMING_PARA {
  6682.     HKEY                hKey;
  6683.     LPWSTR              pwszStoreDirectory;
  6684. } CERT_REGISTRY_STORE_ROAMING_PARA, *PCERT_REGISTRY_STORE_ROAMING_PARA;
  6685.  
  6686. // The following flag is for internal use. When set, the "My" DWORD value
  6687. // at HKLM\Software\Microsoft\Cryptography\IEDirtyFlags is set to 0x1
  6688. // whenever a certificate is added to the registry store.
  6689. #define CERT_REGISTRY_STORE_MY_IE_DIRTY_FLAG    0x80000
  6690.  
  6691. // Registry path to the subkey containing the "My" DWORD value to be set
  6692. #define CERT_IE_DIRTY_FLAGS_REGPATH \
  6693.     L"Software\\Microsoft\\Cryptography\\IEDirtyFlags"
  6694.  
  6695. //+-------------------------------------------------------------------------
  6696. //  Certificate File Store Flag Values for the providers:
  6697. //      CERT_STORE_PROV_FILE
  6698. //      CERT_STORE_PROV_FILENAME
  6699. //      CERT_STORE_PROV_FILENAME_A
  6700. //      CERT_STORE_PROV_FILENAME_W
  6701. //      sz_CERT_STORE_PROV_FILENAME_W
  6702. //--------------------------------------------------------------------------
  6703.  
  6704. // Set this flag if any store changes are to be committed to the file.
  6705. // The changes are committed at CertCloseStore or by calling
  6706. // CertControlStore(CERT_STORE_CTRL_COMMIT).
  6707. //
  6708. // The open fails with E_INVALIDARG if both CERT_FILE_STORE_COMMIT_ENABLE_FLAG
  6709. // and CERT_STORE_READONLY_FLAG are set in dwFlags.
  6710. //
  6711. // For the FILENAME providers:  if the file contains an X509 encoded
  6712. // certificate, the open fails with ERROR_ACCESS_DENIED.
  6713. //
  6714. // For the FILENAME providers: if CERT_STORE_CREATE_NEW_FLAG is set, the
  6715. // CreateFile uses CREATE_NEW. If CERT_STORE_OPEN_EXISTING is set, uses
  6716. // OPEN_EXISTING. Otherwise, defaults to OPEN_ALWAYS.
  6717. //
  6718. // For the FILENAME providers:  the file is committed as either a PKCS7 or
  6719. // serialized store depending on the type read at open. However, if the
  6720. // file is empty then, if the filename has either a ".p7c" or ".spc"
  6721. // extension its committed as a PKCS7. Otherwise, its committed as a
  6722. // serialized store.
  6723. //
  6724. // For CERT_STORE_PROV_FILE, the file handle is duplicated. Its always
  6725. // committed as a serialized store.
  6726. //
  6727. #define CERT_FILE_STORE_COMMIT_ENABLE_FLAG      0x10000
  6728.  
  6729.  
  6730. //+-------------------------------------------------------------------------
  6731. //  Open the cert store using the specified store provider.
  6732. //
  6733. //  If CERT_STORE_DELETE_FLAG is set, then, the store is deleted. NULL is
  6734. //  returned for both success and failure. However, GetLastError() returns 0
  6735. //  for success and nonzero for failure.
  6736. //
  6737. //  If CERT_STORE_SET_LOCALIZED_NAME_FLAG is set, then, if supported, the
  6738. //  provider sets the store's CERT_STORE_LOCALIZED_NAME_PROP_ID property.
  6739. //  The store's localized name can be retrieved by calling
  6740. //  CertSetStoreProperty(dwPropID = CERT_STORE_LOCALIZED_NAME_PROP_ID).
  6741. //  This flag is supported by the following providers (and their sz_
  6742. //  equivalent):
  6743. //      CERT_STORE_PROV_FILENAME_A
  6744. //      CERT_STORE_PROV_FILENAME_W
  6745. //      CERT_STORE_PROV_SYSTEM_A
  6746. //      CERT_STORE_PROV_SYSTEM_W
  6747. //      CERT_STORE_PROV_SYSTEM_REGISTRY_A
  6748. //      CERT_STORE_PROV_SYSTEM_REGISTRY_W
  6749. //      CERT_STORE_PROV_PHYSICAL_W
  6750. //
  6751. //  If CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG is set, then, the
  6752. //  closing of the store's provider is deferred until all certificate,
  6753. //  CRL and CTL contexts obtained from the store are freed. Also,
  6754. //  if a non NULL HCRYPTPROV was passed, then, it will continue to be used.
  6755. //  By default, the store's provider is closed on the final CertCloseStore.
  6756. //  If this flag isn't set, then, any property changes made to previously
  6757. //  duplicated contexts after the final CertCloseStore will not be persisted.
  6758. //  By setting this flag, property changes made
  6759. //  after the CertCloseStore will be persisted. Note, setting this flag
  6760. //  causes extra overhead in doing context duplicates and frees.
  6761. //  If CertCloseStore is called with CERT_CLOSE_STORE_FORCE_FLAG, then,
  6762. //  the CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG flag is ignored.
  6763. //
  6764. //  CERT_STORE_MANIFOLD_FLAG can be set to check for certificates having the
  6765. //  manifold extension and archive the "older" certificates with the same
  6766. //  manifold extension value. A certificate is archived by setting the
  6767. //  CERT_ARCHIVED_PROP_ID.
  6768. //
  6769. //  By default, contexts having the CERT_ARCHIVED_PROP_ID, are skipped
  6770. //  during enumeration. CERT_STORE_ENUM_ARCHIVED_FLAG can be set to include
  6771. //  archived contexts when enumerating. Note, contexts having the
  6772. //  CERT_ARCHIVED_PROP_ID are still found for explicit finds, such as,
  6773. //  finding a context with a specific hash or finding a certificate having
  6774. //  a specific issuer and serial number.
  6775. //
  6776. //  CERT_STORE_UPDATE_KEYID_FLAG can be set to also update the Key Identifier's
  6777. //  CERT_KEY_PROV_INFO_PROP_ID property whenever a certificate's
  6778. //  CERT_KEY_IDENTIFIER_PROP_ID or CERT_KEY_PROV_INFO_PROP_ID property is set
  6779. //  and the other property already exists. If the Key Identifier's
  6780. //  CERT_KEY_PROV_INFO_PROP_ID already exists, it isn't updated. Any
  6781. //  errors encountered are silently ignored.
  6782. //
  6783. //  By default, this flag is implicitly set for the "My\.Default" CurrentUser
  6784. //  and LocalMachine physical stores.
  6785. //
  6786. //  CERT_STORE_READONLY_FLAG can be set to open the store as read only.
  6787. //  Otherwise, the store is opened as read/write.
  6788. //
  6789. //  CERT_STORE_OPEN_EXISTING_FLAG can be set to only open an existing
  6790. //  store. CERT_STORE_CREATE_NEW_FLAG can be set to create a new store and
  6791. //  fail if the store already exists. Otherwise, the default is to open
  6792. //  an existing store or create a new store if it doesn't already exist.
  6793. //
  6794. //  hCryptProv specifies the crypto provider to use to create the hash
  6795. //  properties or verify the signature of a subject certificate or CRL.
  6796. //  The store doesn't need to use a private
  6797. //  key. If the CERT_STORE_NO_CRYPT_RELEASE_FLAG isn't set, hCryptProv is
  6798. //  CryptReleaseContext'ed on the final CertCloseStore.
  6799. //
  6800. //  Note, if the open fails, hCryptProv is released if it would have been
  6801. //  released when the store was closed.
  6802. //
  6803. //  If hCryptProv is zero, then, the default provider and container for the
  6804. //  PROV_RSA_FULL provider type is CryptAcquireContext'ed with
  6805. //  CRYPT_VERIFYCONTEXT access. The CryptAcquireContext is deferred until
  6806. //  the first create hash or verify signature. In addition, once acquired,
  6807. //  the default provider isn't released until process exit when crypt32.dll
  6808. //  is unloaded. The acquired default provider is shared across all stores
  6809. //  and threads.
  6810. //
  6811. //  After initializing the store's data structures and optionally acquiring a
  6812. //  default crypt provider, CertOpenStore calls CryptGetOIDFunctionAddress to
  6813. //  get the address of the CRYPT_OID_OPEN_STORE_PROV_FUNC specified by
  6814. //  lpszStoreProvider. Since a store can contain certificates with different
  6815. //  encoding types, CryptGetOIDFunctionAddress is called with dwEncodingType
  6816. //  set to 0 and not the dwEncodingType passed to CertOpenStore.
  6817. //  PFN_CERT_DLL_OPEN_STORE_FUNC specifies the signature of the provider's
  6818. //  open function. This provider open function is called to load the
  6819. //  store's certificates and CRLs. Optionally, the provider may return an
  6820. //  array of functions called before a certificate or CRL is added or deleted
  6821. //  or has a property that is set.
  6822. //
  6823. //  Use of the dwEncodingType parameter is provider dependent. The type
  6824. //  definition for pvPara also depends on the provider.
  6825. //
  6826. //  Store providers are installed or registered via
  6827. //  CryptInstallOIDFunctionAddress or CryptRegisterOIDFunction, where,
  6828. //  dwEncodingType is 0 and pszFuncName is CRYPT_OID_OPEN_STORE_PROV_FUNC.
  6829. //
  6830. //  Here's a list of the predefined provider types (implemented in crypt32.dll):
  6831. //
  6832. //  CERT_STORE_PROV_MSG:
  6833. //      Gets the certificates and CRLs from the specified cryptographic message.
  6834. //      dwEncodingType contains the message and certificate encoding types.
  6835. //      The message's handle is passed in pvPara. Given,
  6836. //          HCRYPTMSG hCryptMsg; pvPara = (const void *) hCryptMsg;
  6837. //
  6838. //  CERT_STORE_PROV_MEMORY
  6839. //  sz_CERT_STORE_PROV_MEMORY:
  6840. //      Opens a store without any initial certificates or CRLs. pvPara
  6841. //      isn't used.
  6842. //
  6843. //  CERT_STORE_PROV_FILE:
  6844. //      Reads the certificates and CRLs from the specified file. The file's
  6845. //      handle is passed in pvPara. Given,
  6846. //          HANDLE hFile; pvPara = (const void *) hFile;
  6847. //
  6848. //      For a successful open, the file pointer is advanced past
  6849. //      the certificates and CRLs and their properties read from the file.
  6850. //      Note, only expects a serialized store and not a file containing
  6851. //      either a PKCS #7 signed message or a single encoded certificate.
  6852. //
  6853. //      The hFile isn't closed.
  6854. //
  6855. //  CERT_STORE_PROV_REG:
  6856. //      Reads the certificates and CRLs from the registry. The registry's
  6857. //      key handle is passed in pvPara. Given,
  6858. //          HKEY hKey; pvPara = (const void *) hKey;
  6859. //
  6860. //      The input hKey isn't closed by the provider. Before returning, the
  6861. //      provider opens it own copy of the hKey.
  6862. //
  6863. //      If CERT_STORE_READONLY_FLAG is set, then, the registry subkeys are
  6864. //      RegOpenKey'ed with KEY_READ_ACCESS. Otherwise, the registry subkeys
  6865. //      are RegCreateKey'ed with KEY_ALL_ACCESS.
  6866. //
  6867. //      This provider returns the array of functions for reading, writing,
  6868. //      deleting and property setting certificates and CRLs.
  6869. //      Any changes to the opened store are immediately pushed through to
  6870. //      the registry. However, if CERT_STORE_READONLY_FLAG is set, then,
  6871. //      writing, deleting or property setting results in a
  6872. //      SetLastError(E_ACCESSDENIED).
  6873. //
  6874. //      Note, all the certificates and CRLs are read from the registry
  6875. //      when the store is opened. The opened store serves as a write through
  6876. //      cache.
  6877. //
  6878. //      If CERT_REGISTRY_STORE_SERIALIZED_FLAG is set, then, the
  6879. //      contexts are persisted as a single serialized store subkey in the
  6880. //      registry.
  6881. //
  6882. //  CERT_STORE_PROV_PKCS7:
  6883. //  sz_CERT_STORE_PROV_PKCS7:
  6884. //      Gets the certificates and CRLs from the encoded PKCS #7 signed message.
  6885. //      dwEncodingType specifies the message and certificate encoding types.
  6886. //      The pointer to the encoded message's blob is passed in pvPara. Given,
  6887. //          CRYPT_DATA_BLOB EncodedMsg; pvPara = (const void *) &EncodedMsg;
  6888. //
  6889. //      Note, also supports the IE3.0 special version of a
  6890. //      PKCS #7 signed message referred to as a "SPC" formatted message.
  6891. //
  6892. //  CERT_STORE_PROV_SERIALIZED:
  6893. //  sz_CERT_STORE_PROV_SERIALIZED:
  6894. //      Gets the certificates and CRLs from memory containing a serialized
  6895. //      store.  The pointer to the serialized memory blob is passed in pvPara.
  6896. //      Given,
  6897. //          CRYPT_DATA_BLOB Serialized; pvPara = (const void *) &Serialized;
  6898. //
  6899. //  CERT_STORE_PROV_FILENAME_A:
  6900. //  CERT_STORE_PROV_FILENAME_W:
  6901. //  CERT_STORE_PROV_FILENAME:
  6902. //  sz_CERT_STORE_PROV_FILENAME_W:
  6903. //  sz_CERT_STORE_PROV_FILENAME:
  6904. //      Opens the file and first attempts to read as a serialized store. Then,
  6905. //      as a PKCS #7 signed message. Finally, as a single encoded certificate.
  6906. //      The filename is passed in pvPara. The filename is UNICODE for the
  6907. //      "_W" provider and ASCII for the "_A" provider. For "_W": given,
  6908. //          LPCWSTR pwszFilename; pvPara = (const void *) pwszFilename;
  6909. //      For "_A": given,
  6910. //          LPCSTR pszFilename; pvPara = (const void *) pszFilename;
  6911. //
  6912. //      Note, the default (without "_A" or "_W") is unicode.
  6913. //
  6914. //      Note, also supports the reading of the IE3.0 special version of a
  6915. //      PKCS #7 signed message file referred to as a "SPC" formatted file.
  6916. //
  6917. //  CERT_STORE_PROV_SYSTEM_A:
  6918. //  CERT_STORE_PROV_SYSTEM_W:
  6919. //  CERT_STORE_PROV_SYSTEM:
  6920. //  sz_CERT_STORE_PROV_SYSTEM_W:
  6921. //  sz_CERT_STORE_PROV_SYSTEM:
  6922. //      Opens the specified logical "System" store. The upper word of the
  6923. //      dwFlags parameter is used to specify the location of the system store.
  6924. //
  6925. //      A "System" store is a collection consisting of one or more "Physical"
  6926. //      stores. A "Physical" store is registered via the
  6927. //      CertRegisterPhysicalStore API. Each of the registered physical stores
  6928. //      is CertStoreOpen'ed and added to the collection via
  6929. //      CertAddStoreToCollection.
  6930. //
  6931. //      The CERT_SYSTEM_STORE_CURRENT_USER, CERT_SYSTEM_STORE_LOCAL_MACHINE,
  6932. //      CERT_SYSTEM_STORE_CURRENT_SERVICE, CERT_SYSTEM_STORE_SERVICES,
  6933. //      CERT_SYSTEM_STORE_USERS, CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY,
  6934. //      CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY and
  6935. //      CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRSE
  6936. //      system stores by default have a "SystemRegistry" store that is
  6937. //      opened and added to the collection.
  6938. //
  6939. //      The system store name is passed in pvPara. The name is UNICODE for the
  6940. //      "_W" provider and ASCII for the "_A" provider. For "_W": given,
  6941. //          LPCWSTR pwszSystemName; pvPara = (const void *) pwszSystemName;
  6942. //      For "_A": given,
  6943. //          LPCSTR pszSystemName; pvPara = (const void *) pszSystemName;
  6944. //
  6945. //      Note, the default (without "_A" or "_W") is UNICODE.
  6946. //
  6947. //      The system store name can't contain any backslashes.
  6948. //
  6949. //      If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvPara
  6950. //      points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure instead
  6951. //      of pointing to a null terminated UNICODE or ASCII string.
  6952. //      Sibling physical stores are also opened as relocated using
  6953. //      pvPara's hKeyBase.
  6954. //
  6955. //      The CERT_SYSTEM_STORE_SERVICES or CERT_SYSTEM_STORE_USERS system
  6956. //      store name must be prefixed with the ServiceName or UserName.
  6957. //      For example, "ServiceName\Trust".
  6958. //
  6959. //      Stores on remote computers can be accessed for the
  6960. //      CERT_SYSTEM_STORE_LOCAL_MACHINE, CERT_SYSTEM_STORE_SERVICES,
  6961. //      CERT_SYSTEM_STORE_USERS, CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY
  6962. //      or CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE
  6963. //      locations by prepending the computer name. For example, a remote
  6964. //      local machine store is accessed via "\\ComputerName\Trust" or
  6965. //      "ComputerName\Trust". A remote service store is accessed via
  6966. //      "\\ComputerName\ServiceName\Trust". The leading "\\" backslashes are
  6967. //      optional in the ComputerName.
  6968. //
  6969. //      If CERT_STORE_READONLY_FLAG is set, then, the registry is
  6970. //      RegOpenKey'ed with KEY_READ_ACCESS. Otherwise, the registry is
  6971. //      RegCreateKey'ed with KEY_ALL_ACCESS.
  6972. //
  6973. //      The "root" store is treated differently from the other system
  6974. //      stores. Before a certificate is added to or deleted from the "root"
  6975. //      store, a pop up message box is displayed. The certificate's subject,
  6976. //      issuer, serial number, time validity, sha1 and md5 thumbprints are
  6977. //      displayed. The user is given the option to do the add or delete.
  6978. //      If they don't allow the operation, LastError is set to E_ACCESSDENIED.
  6979. //
  6980. //  CERT_STORE_PROV_SYSTEM_REGISTRY_A
  6981. //  CERT_STORE_PROV_SYSTEM_REGISTRY_W
  6982. //  CERT_STORE_PROV_SYSTEM_REGISTRY
  6983. //  sz_CERT_STORE_PROV_SYSTEM_REGISTRY_W
  6984. //  sz_CERT_STORE_PROV_SYSTEM_REGISTRY
  6985. //      Opens the "System" store's default "Physical" store residing in the
  6986. //      registry. The upper word of the dwFlags
  6987. //      parameter is used to specify the location of the system store.
  6988. //
  6989. //      After opening the registry key associated with the system name,
  6990. //      the CERT_STORE_PROV_REG provider is called to complete the open.
  6991. //
  6992. //      The system store name is passed in pvPara. The name is UNICODE for the
  6993. //      "_W" provider and ASCII for the "_A" provider. For "_W": given,
  6994. //          LPCWSTR pwszSystemName; pvPara = (const void *) pwszSystemName;
  6995. //      For "_A": given,
  6996. //          LPCSTR pszSystemName; pvPara = (const void *) pszSystemName;
  6997. //
  6998. //      Note, the default (without "_A" or "_W") is UNICODE.
  6999. //
  7000. //      If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvPara
  7001. //      points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure instead
  7002. //      of pointing to a null terminated UNICODE or ASCII string.
  7003. //
  7004. //      See above for details on prepending a ServiceName and/or ComputerName
  7005. //      to the store name.
  7006. //
  7007. //      If CERT_STORE_READONLY_FLAG is set, then, the registry is
  7008. //      RegOpenKey'ed with KEY_READ_ACCESS. Otherwise, the registry is
  7009. //      RegCreateKey'ed with KEY_ALL_ACCESS.
  7010. //
  7011. //      The "root" store is treated differently from the other system
  7012. //      stores. Before a certificate is added to or deleted from the "root"
  7013. //      store, a pop up message box is displayed. The certificate's subject,
  7014. //      issuer, serial number, time validity, sha1 and md5 thumbprints are
  7015. //      displayed. The user is given the option to do the add or delete.
  7016. //      If they don't allow the operation, LastError is set to E_ACCESSDENIED.
  7017. //
  7018. //  CERT_STORE_PROV_PHYSICAL_W
  7019. //  CERT_STORE_PROV_PHYSICAL
  7020. //  sz_CERT_STORE_PROV_PHYSICAL_W
  7021. //  sz_CERT_STORE_PROV_PHYSICAL
  7022. //      Opens the specified "Physical" store in the "System" store.
  7023. //
  7024. //      Both the system store and physical names are passed in pvPara. The
  7025. //      names are separated with an intervening "\". For example,
  7026. //      "Root\.Default". The string is UNICODE.
  7027. //
  7028. //      The system and physical store names can't contain any backslashes.
  7029. //
  7030. //      If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvPara
  7031. //      points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure instead
  7032. //      of pointing to a null terminated UNICODE string.
  7033. //      The specified physical store is opened as relocated using pvPara's
  7034. //      hKeyBase.
  7035. //
  7036. //      For CERT_SYSTEM_STORE_SERVICES or CERT_SYSTEM_STORE_USERS,
  7037. //      the system and physical store names
  7038. //      must be prefixed with the ServiceName or UserName. For example,
  7039. //      "ServiceName\Root\.Default".
  7040. //
  7041. //      Physical stores on remote computers can be accessed for the
  7042. //      CERT_SYSTEM_STORE_LOCAL_MACHINE, CERT_SYSTEM_STORE_SERVICES,
  7043. //      CERT_SYSTEM_STORE_USERS, CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY
  7044. //      or CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE
  7045. //      locations by prepending the computer name. For example, a remote
  7046. //      local machine store is accessed via "\\ComputerName\Root\.Default"
  7047. //      or "ComputerName\Root\.Default". A remote service store is
  7048. //      accessed via "\\ComputerName\ServiceName\Root\.Default". The
  7049. //      leading "\\" backslashes are optional in the ComputerName.
  7050. //
  7051. //  CERT_STORE_PROV_COLLECTION
  7052. //  sz_CERT_STORE_PROV_COLLECTION
  7053. //      Opens a store that is a collection of other stores. Stores are
  7054. //      added or removed to/from the collection via the CertAddStoreToCollection
  7055. //      and CertRemoveStoreFromCollection APIs.
  7056. //
  7057. //  CERT_STORE_PROV_SMART_CARD_W
  7058. //  CERT_STORE_PROV_SMART_CARD
  7059. //  sz_CERT_STORE_PROV_SMART_CARD_W
  7060. //  sz_CERT_STORE_PROV_SMART_CARD
  7061. //      Opens a store instantiated over a particular smart card storage.  pvPara
  7062. //      identifies where on the card the store is located and is of the
  7063. //      following format:
  7064. //
  7065. //                Card Name\Provider Name\Provider Type[\Container Name]
  7066. //
  7067. //      Container Name is optional and if NOT specified the Card Name is used
  7068. //      as the Container Name.  Future versions of the provider will support
  7069. //      instantiating the store over the entire card in which case just
  7070. //      Card Name ( or id ) will be sufficient.
  7071. //
  7072. //  Here's a list of the predefined provider types (implemented in
  7073. //  cryptnet.dll):
  7074. //
  7075. //  CERT_STORE_PROV_LDAP_W
  7076. //  CERT_STORE_PROV_LDAP
  7077. //  sz_CERT_STORE_PROV_LDAP_W
  7078. //  sz_CERT_STORE_PROV_LDAP
  7079. //      Opens a store over the results of the query specified by and LDAP
  7080. //      URL which is passed in via pvPara.  In order to do writes to the
  7081. //      store the URL must specify a BASE query, no filter and a single
  7082. //      attribute.
  7083. //
  7084. //--------------------------------------------------------------------------
  7085. WINCRYPT32API
  7086. HCERTSTORE
  7087. WINAPI
  7088. CertOpenStore(
  7089.     IN LPCSTR lpszStoreProvider,
  7090.     IN DWORD dwEncodingType,
  7091.     IN HCRYPTPROV hCryptProv,
  7092.     IN DWORD dwFlags,
  7093.     IN const void *pvPara
  7094.     );
  7095.  
  7096.  
  7097. //+-------------------------------------------------------------------------
  7098. //  OID Installable Certificate Store Provider Data Structures
  7099. //--------------------------------------------------------------------------
  7100.  
  7101. // Handle returned by the store provider when opened.
  7102. typedef void *HCERTSTOREPROV;
  7103.  
  7104. // Store Provider OID function's pszFuncName.
  7105. #define CRYPT_OID_OPEN_STORE_PROV_FUNC   "CertDllOpenStoreProv"
  7106.  
  7107. // Note, the Store Provider OID function's dwEncodingType is always 0.
  7108.  
  7109. // The following information is returned by the provider when opened. Its
  7110. // zeroed with cbSize set before the provider is called. If the provider
  7111. // doesn't need to be called again after the open it doesn't need to
  7112. // make any updates to the CERT_STORE_PROV_INFO.
  7113. typedef struct _CERT_STORE_PROV_INFO {
  7114.     DWORD               cbSize;
  7115.     DWORD               cStoreProvFunc;
  7116.     void                **rgpvStoreProvFunc;
  7117.     HCERTSTOREPROV      hStoreProv;
  7118.     DWORD               dwStoreProvFlags;
  7119.     HCRYPTOIDFUNCADDR   hStoreProvFuncAddr2;
  7120. } CERT_STORE_PROV_INFO, *PCERT_STORE_PROV_INFO;
  7121.  
  7122. // Definition of the store provider's open function.
  7123. //
  7124. // *pStoreProvInfo has been zeroed before the call.
  7125. //
  7126. // Note, pStoreProvInfo->cStoreProvFunc should be set last.  Once set,
  7127. // all subsequent store calls, such as CertAddSerializedElementToStore will
  7128. // call the appropriate provider callback function.
  7129. typedef BOOL (WINAPI *PFN_CERT_DLL_OPEN_STORE_PROV_FUNC)(
  7130.     IN LPCSTR lpszStoreProvider,
  7131.     IN DWORD dwEncodingType,
  7132.     IN HCRYPTPROV hCryptProv,
  7133.     IN DWORD dwFlags,
  7134.     IN const void *pvPara,
  7135.     IN HCERTSTORE hCertStore,
  7136.     IN OUT PCERT_STORE_PROV_INFO pStoreProvInfo
  7137.     );
  7138.  
  7139. // The open callback sets the following flag, if it maintains its
  7140. // contexts externally and not in the cached store.
  7141. #define CERT_STORE_PROV_EXTERNAL_FLAG           0x1
  7142.  
  7143. // The open callback sets the following flag for a successful delete.
  7144. // When set, the close callback isn't called.
  7145. #define CERT_STORE_PROV_DELETED_FLAG            0x2
  7146.  
  7147. // The open callback sets the following flag if it doesn't persist store
  7148. // changes.
  7149. #define CERT_STORE_PROV_NO_PERSIST_FLAG         0x4
  7150.  
  7151. // The open callback sets the following flag if the contexts are persisted
  7152. // to a system store.
  7153. #define CERT_STORE_PROV_SYSTEM_STORE_FLAG       0x8
  7154.  
  7155. // Indices into the store provider's array of callback functions.
  7156. //
  7157. // The provider can implement any subset of the following functions. It
  7158. // sets pStoreProvInfo->cStoreProvFunc to the last index + 1 and any
  7159. // preceding not implemented functions to NULL.
  7160. #define CERT_STORE_PROV_CLOSE_FUNC              0
  7161. #define CERT_STORE_PROV_READ_CERT_FUNC          1
  7162. #define CERT_STORE_PROV_WRITE_CERT_FUNC         2
  7163. #define CERT_STORE_PROV_DELETE_CERT_FUNC        3
  7164. #define CERT_STORE_PROV_SET_CERT_PROPERTY_FUNC  4
  7165. #define CERT_STORE_PROV_READ_CRL_FUNC           5
  7166. #define CERT_STORE_PROV_WRITE_CRL_FUNC          6
  7167. #define CERT_STORE_PROV_DELETE_CRL_FUNC         7
  7168. #define CERT_STORE_PROV_SET_CRL_PROPERTY_FUNC   8
  7169. #define CERT_STORE_PROV_READ_CTL_FUNC           9
  7170. #define CERT_STORE_PROV_WRITE_CTL_FUNC          10
  7171. #define CERT_STORE_PROV_DELETE_CTL_FUNC         11
  7172. #define CERT_STORE_PROV_SET_CTL_PROPERTY_FUNC   12
  7173. #define CERT_STORE_PROV_CONTROL_FUNC            13
  7174. #define CERT_STORE_PROV_FIND_CERT_FUNC          14
  7175. #define CERT_STORE_PROV_FREE_FIND_CERT_FUNC     15
  7176. #define CERT_STORE_PROV_GET_CERT_PROPERTY_FUNC  16
  7177. #define CERT_STORE_PROV_FIND_CRL_FUNC           17
  7178. #define CERT_STORE_PROV_FREE_FIND_CRL_FUNC      18
  7179. #define CERT_STORE_PROV_GET_CRL_PROPERTY_FUNC   19
  7180. #define CERT_STORE_PROV_FIND_CTL_FUNC           20
  7181. #define CERT_STORE_PROV_FREE_FIND_CTL_FUNC      21
  7182. #define CERT_STORE_PROV_GET_CTL_PROPERTY_FUNC   22
  7183.  
  7184.  
  7185. // Called by CertCloseStore when the store's reference count is
  7186. // decremented to 0.
  7187. typedef void (WINAPI *PFN_CERT_STORE_PROV_CLOSE)(
  7188.     IN HCERTSTOREPROV hStoreProv,
  7189.     IN DWORD dwFlags
  7190.     );
  7191.  
  7192. // Currently not called directly by the store APIs. However, may be exported
  7193. // to support other providers based on it.
  7194. //
  7195. // Reads the provider's copy of the certificate context. If it exists,
  7196. // creates a new certificate context.
  7197. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_READ_CERT)(
  7198.     IN HCERTSTOREPROV hStoreProv,
  7199.     IN PCCERT_CONTEXT pStoreCertContext,
  7200.     IN DWORD dwFlags,
  7201.     OUT PCCERT_CONTEXT *ppProvCertContext
  7202.     );
  7203.  
  7204. #define CERT_STORE_PROV_WRITE_ADD_FLAG      0x1
  7205.  
  7206. // Called by CertAddEncodedCertificateToStore,
  7207. // CertAddCertificateContextToStore or CertAddSerializedElementToStore before
  7208. // adding to the store. The CERT_STORE_PROV_WRITE_ADD_FLAG is set. In
  7209. // addition to the encoded certificate, the added pCertContext might also
  7210. // have properties.
  7211. //
  7212. // Returns TRUE if its OK to update the the store.
  7213. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_WRITE_CERT)(
  7214.     IN HCERTSTOREPROV hStoreProv,
  7215.     IN PCCERT_CONTEXT pCertContext,
  7216.     IN DWORD dwFlags
  7217.     );
  7218.  
  7219. // Called by CertDeleteCertificateFromStore before deleting from the
  7220. // store.
  7221. //
  7222. // Returns TRUE if its OK to delete from the store.
  7223. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_DELETE_CERT)(
  7224.     IN HCERTSTOREPROV hStoreProv,
  7225.     IN PCCERT_CONTEXT pCertContext,
  7226.     IN DWORD dwFlags
  7227.     );
  7228.  
  7229. // Called by CertSetCertificateContextProperty before setting the
  7230. // certificate's property. Also called by CertGetCertificateContextProperty,
  7231. // when getting a hash property that needs to be created and then persisted
  7232. // via the set.
  7233. //
  7234. // Upon input, the property hasn't been set for the pCertContext parameter.
  7235. //
  7236. // Returns TRUE if its OK to set the property.
  7237. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_SET_CERT_PROPERTY)(
  7238.     IN HCERTSTOREPROV hStoreProv,
  7239.     IN PCCERT_CONTEXT pCertContext,
  7240.     IN DWORD dwPropId,
  7241.     IN DWORD dwFlags,
  7242.     IN const void *pvData
  7243.     );
  7244.  
  7245. // Currently not called directly by the store APIs. However, may be exported
  7246. // to support other providers based on it.
  7247. //
  7248. // Reads the provider's copy of the CRL context. If it exists,
  7249. // creates a new CRL context.
  7250. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_READ_CRL)(
  7251.     IN HCERTSTOREPROV hStoreProv,
  7252.     IN PCCRL_CONTEXT pStoreCrlContext,
  7253.     IN DWORD dwFlags,
  7254.     OUT PCCRL_CONTEXT *ppProvCrlContext
  7255.     );
  7256.  
  7257. // Called by CertAddEncodedCRLToStore,
  7258. // CertAddCRLContextToStore or CertAddSerializedElementToStore before
  7259. // adding to the store. The CERT_STORE_PROV_WRITE_ADD_FLAG is set. In
  7260. // addition to the encoded CRL, the added pCertContext might also
  7261. // have properties.
  7262. //
  7263. // Returns TRUE if its OK to update the the store.
  7264. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_WRITE_CRL)(
  7265.     IN HCERTSTOREPROV hStoreProv,
  7266.     IN PCCRL_CONTEXT pCrlContext,
  7267.     IN DWORD dwFlags
  7268.     );
  7269.  
  7270. // Called by CertDeleteCRLFromStore before deleting from the store.
  7271. //
  7272. // Returns TRUE if its OK to delete from the store.
  7273. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_DELETE_CRL)(
  7274.     IN HCERTSTOREPROV hStoreProv,
  7275.     IN PCCRL_CONTEXT pCrlContext,
  7276.     IN DWORD dwFlags
  7277.     );
  7278.  
  7279. // Called by CertSetCRLContextProperty before setting the
  7280. // CRL's property. Also called by CertGetCRLContextProperty,
  7281. // when getting a hash property that needs to be created and then persisted
  7282. // via the set.
  7283. //
  7284. // Upon input, the property hasn't been set for the pCrlContext parameter.
  7285. //
  7286. // Returns TRUE if its OK to set the property.
  7287. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_SET_CRL_PROPERTY)(
  7288.     IN HCERTSTOREPROV hStoreProv,
  7289.     IN PCCRL_CONTEXT pCrlContext,
  7290.     IN DWORD dwPropId,
  7291.     IN DWORD dwFlags,
  7292.     IN const void *pvData
  7293.     );
  7294.  
  7295. // Currently not called directly by the store APIs. However, may be exported
  7296. // to support other providers based on it.
  7297. //
  7298. // Reads the provider's copy of the CTL context. If it exists,
  7299. // creates a new CTL context.
  7300. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_READ_CTL)(
  7301.     IN HCERTSTOREPROV hStoreProv,
  7302.     IN PCCTL_CONTEXT pStoreCtlContext,
  7303.     IN DWORD dwFlags,
  7304.     OUT PCCTL_CONTEXT *ppProvCtlContext
  7305.     );
  7306.  
  7307. // Called by CertAddEncodedCTLToStore,
  7308. // CertAddCTLContextToStore or CertAddSerializedElementToStore before
  7309. // adding to the store. The CERT_STORE_PROV_WRITE_ADD_FLAG is set. In
  7310. // addition to the encoded CTL, the added pCertContext might also
  7311. // have properties.
  7312. //
  7313. // Returns TRUE if its OK to update the the store.
  7314. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_WRITE_CTL)(
  7315.     IN HCERTSTOREPROV hStoreProv,
  7316.     IN PCCTL_CONTEXT pCtlContext,
  7317.     IN DWORD dwFlags
  7318.     );
  7319.  
  7320. // Called by CertDeleteCTLFromStore before deleting from the store.
  7321. //
  7322. // Returns TRUE if its OK to delete from the store.
  7323. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_DELETE_CTL)(
  7324.     IN HCERTSTOREPROV hStoreProv,
  7325.     IN PCCTL_CONTEXT pCtlContext,
  7326.     IN DWORD dwFlags
  7327.                                                      );
  7328.  
  7329. // Called by CertSetCTLContextProperty before setting the
  7330. // CTL's property. Also called by CertGetCTLContextProperty,
  7331. // when getting a hash property that needs to be created and then persisted
  7332. // via the set.
  7333. //
  7334. // Upon input, the property hasn't been set for the pCtlContext parameter.
  7335. //
  7336. // Returns TRUE if its OK to set the property.
  7337. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_SET_CTL_PROPERTY)(
  7338.     IN HCERTSTOREPROV hStoreProv,
  7339.     IN PCCTL_CONTEXT pCtlContext,
  7340.     IN DWORD dwPropId,
  7341.     IN DWORD dwFlags,
  7342.     IN const void *pvData
  7343.     );
  7344.  
  7345. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_CONTROL)(
  7346.     IN HCERTSTOREPROV hStoreProv,
  7347.     IN DWORD dwFlags,
  7348.     IN DWORD dwCtrlType,
  7349.     IN void const *pvCtrlPara
  7350.     );
  7351.  
  7352. typedef struct _CERT_STORE_PROV_FIND_INFO {
  7353.     DWORD               cbSize;
  7354.     DWORD               dwMsgAndCertEncodingType;
  7355.     DWORD               dwFindFlags;
  7356.     DWORD               dwFindType;
  7357.     const void          *pvFindPara;
  7358. } CERT_STORE_PROV_FIND_INFO, *PCERT_STORE_PROV_FIND_INFO;
  7359. typedef const CERT_STORE_PROV_FIND_INFO CCERT_STORE_PROV_FIND_INFO,
  7360. *PCCERT_STORE_PROV_FIND_INFO;
  7361.  
  7362. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_FIND_CERT)(
  7363.     IN HCERTSTOREPROV hStoreProv,
  7364.     IN PCCERT_STORE_PROV_FIND_INFO pFindInfo,
  7365.     IN PCCERT_CONTEXT pPrevCertContext,
  7366.     IN DWORD dwFlags,
  7367.     IN OUT void **ppvStoreProvFindInfo,
  7368.     OUT PCCERT_CONTEXT *ppProvCertContext
  7369.     );
  7370.  
  7371. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_FREE_FIND_CERT)(
  7372.     IN HCERTSTOREPROV hStoreProv,
  7373.     IN PCCERT_CONTEXT pCertContext,
  7374.     IN void *pvStoreProvFindInfo,
  7375.     IN DWORD dwFlags
  7376.     );
  7377.  
  7378. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_GET_CERT_PROPERTY)(
  7379.     IN HCERTSTOREPROV hStoreProv,
  7380.     IN PCCERT_CONTEXT pCertContext,
  7381.     IN DWORD dwPropId,
  7382.     IN DWORD dwFlags,
  7383.     OUT void *pvData,
  7384.     IN OUT DWORD *pcbData
  7385.     );
  7386.  
  7387.  
  7388. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_FIND_CRL)(
  7389.     IN HCERTSTOREPROV hStoreProv,
  7390.     IN PCCERT_STORE_PROV_FIND_INFO pFindInfo,
  7391.     IN PCCRL_CONTEXT pPrevCrlContext,
  7392.     IN DWORD dwFlags,
  7393.     IN OUT void **ppvStoreProvFindInfo,
  7394.     OUT PCCRL_CONTEXT *ppProvCrlContext
  7395.     );
  7396.  
  7397. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_FREE_FIND_CRL)(
  7398.     IN HCERTSTOREPROV hStoreProv,
  7399.     IN PCCRL_CONTEXT pCrlContext,
  7400.     IN void *pvStoreProvFindInfo,
  7401.     IN DWORD dwFlags
  7402.     );
  7403.  
  7404. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_GET_CRL_PROPERTY)(
  7405.     IN HCERTSTOREPROV hStoreProv,
  7406.     IN PCCRL_CONTEXT pCrlContext,
  7407.     IN DWORD dwPropId,
  7408.     IN DWORD dwFlags,
  7409.     OUT void *pvData,
  7410.     IN OUT DWORD *pcbData
  7411.     );
  7412.  
  7413. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_FIND_CTL)(
  7414.     IN HCERTSTOREPROV hStoreProv,
  7415.     IN PCCERT_STORE_PROV_FIND_INFO pFindInfo,
  7416.     IN PCCTL_CONTEXT pPrevCtlContext,
  7417.     IN DWORD dwFlags,
  7418.     IN OUT void **ppvStoreProvFindInfo,
  7419.     OUT PCCTL_CONTEXT *ppProvCtlContext
  7420.     );
  7421.  
  7422. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_FREE_FIND_CTL)(
  7423.     IN HCERTSTOREPROV hStoreProv,
  7424.     IN PCCTL_CONTEXT pCtlContext,
  7425.     IN void *pvStoreProvFindInfo,
  7426.     IN DWORD dwFlags
  7427.     );
  7428.  
  7429. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_GET_CTL_PROPERTY)(
  7430.     IN HCERTSTOREPROV hStoreProv,
  7431.     IN PCCTL_CONTEXT pCtlContext,
  7432.     IN DWORD dwPropId,
  7433.     IN DWORD dwFlags,
  7434.     OUT void *pvData,
  7435.     IN OUT DWORD *pcbData
  7436.     );
  7437.  
  7438.  
  7439. //+-------------------------------------------------------------------------
  7440. //  Duplicate a cert store handle
  7441. //--------------------------------------------------------------------------
  7442. WINCRYPT32API
  7443. HCERTSTORE
  7444. WINAPI
  7445. CertDuplicateStore(
  7446.     IN HCERTSTORE hCertStore
  7447.     );
  7448.  
  7449. #define CERT_STORE_SAVE_AS_STORE        1
  7450. #define CERT_STORE_SAVE_AS_PKCS7        2
  7451.  
  7452. #define CERT_STORE_SAVE_TO_FILE         1
  7453. #define CERT_STORE_SAVE_TO_MEMORY       2
  7454. #define CERT_STORE_SAVE_TO_FILENAME_A   3
  7455. #define CERT_STORE_SAVE_TO_FILENAME_W   4
  7456. #define CERT_STORE_SAVE_TO_FILENAME     CERT_STORE_SAVE_TO_FILENAME_W
  7457.  
  7458. //+-------------------------------------------------------------------------
  7459. //  Save the cert store. Extended version with lots of options.
  7460. //
  7461. //  According to the dwSaveAs parameter, the store can be saved as a
  7462. //  serialized store (CERT_STORE_SAVE_AS_STORE) containing properties in
  7463. //  addition to encoded certificates, CRLs and CTLs or the store can be saved
  7464. //  as a PKCS #7 signed message (CERT_STORE_SAVE_AS_PKCS7) which doesn't
  7465. //  include the properties or CTLs.
  7466. //
  7467. //  Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  7468. //  CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't saved into
  7469. //  a serialized store.
  7470. //
  7471. //  For CERT_STORE_SAVE_AS_PKCS7, the dwEncodingType specifies the message
  7472. //  encoding type. The dwEncodingType parameter isn't used for
  7473. //  CERT_STORE_SAVE_AS_STORE.
  7474. //
  7475. //  The dwFlags parameter currently isn't used and should be set to 0.
  7476. //
  7477. //  The dwSaveTo and pvSaveToPara parameters specify where to save the
  7478. //  store as follows:
  7479. //    CERT_STORE_SAVE_TO_FILE:
  7480. //      Saves to the specified file. The file's handle is passed in
  7481. //      pvSaveToPara. Given,
  7482. //          HANDLE hFile; pvSaveToPara = (void *) hFile;
  7483. //
  7484. //      For a successful save, the file pointer is positioned after the
  7485. //      last write.
  7486. //
  7487. //    CERT_STORE_SAVE_TO_MEMORY:
  7488. //      Saves to the specified memory blob. The pointer to
  7489. //      the memory blob is passed in pvSaveToPara. Given,
  7490. //          CRYPT_DATA_BLOB SaveBlob; pvSaveToPara = (void *) &SaveBlob;
  7491. //      Upon entry, the SaveBlob's pbData and cbData need to be initialized.
  7492. //      Upon return, cbData is updated with the actual length.
  7493. //      For a length only calculation, pbData should be set to NULL. If
  7494. //      pbData is non-NULL and cbData isn't large enough, FALSE is returned
  7495. //      with a last error of ERRROR_MORE_DATA.
  7496. //
  7497. //    CERT_STORE_SAVE_TO_FILENAME_A:
  7498. //    CERT_STORE_SAVE_TO_FILENAME_W:
  7499. //    CERT_STORE_SAVE_TO_FILENAME:
  7500. //      Opens the file and saves to it. The filename is passed in pvSaveToPara.
  7501. //      The filename is UNICODE for the "_W" option and ASCII for the "_A"
  7502. //      option. For "_W": given,
  7503. //          LPCWSTR pwszFilename; pvSaveToPara = (void *) pwszFilename;
  7504. //      For "_A": given,
  7505. //          LPCSTR pszFilename; pvSaveToPara = (void *) pszFilename;
  7506. //
  7507. //      Note, the default (without "_A" or "_W") is UNICODE.
  7508. //
  7509. //--------------------------------------------------------------------------
  7510. WINCRYPT32API
  7511. BOOL
  7512. WINAPI
  7513. CertSaveStore(
  7514.     IN HCERTSTORE hCertStore,
  7515.     IN DWORD dwEncodingType,
  7516.     IN DWORD dwSaveAs,
  7517.     IN DWORD dwSaveTo,
  7518.     IN OUT void *pvSaveToPara,
  7519.     IN DWORD dwFlags
  7520.     );
  7521.  
  7522. //+-------------------------------------------------------------------------
  7523. //  Certificate Store close flags
  7524. //--------------------------------------------------------------------------
  7525. #define CERT_CLOSE_STORE_FORCE_FLAG         0x00000001
  7526. #define CERT_CLOSE_STORE_CHECK_FLAG         0x00000002
  7527.  
  7528. //+-------------------------------------------------------------------------
  7529. //  Close a cert store handle.
  7530. //
  7531. //  There needs to be a corresponding close for each open and duplicate.
  7532. //
  7533. //  Even on the final close, the cert store isn't freed until all of its
  7534. //  certificate and CRL contexts have also been freed.
  7535. //
  7536. //  On the final close, the hCryptProv passed to CertStoreOpen is
  7537. //  CryptReleaseContext'ed.
  7538. //
  7539. //  To force the closure of the store with all of its memory freed, set the
  7540. //  CERT_STORE_CLOSE_FORCE_FLAG. This flag should be set when the caller does
  7541. //  its own reference counting and wants everything to vanish.
  7542. //
  7543. //  To check if all the store's certificates and CRLs have been freed and that
  7544. //  this is the last CertCloseStore, set the CERT_CLOSE_STORE_CHECK_FLAG. If
  7545. //  set and certs, CRLs or stores still need to be freed/closed, FALSE is
  7546. //  returned with LastError set to CRYPT_E_PENDING_CLOSE. Note, for FALSE,
  7547. //  the store is still closed. This is a diagnostic flag.
  7548. //
  7549. //  LastError is preserved unless CERT_CLOSE_STORE_CHECK_FLAG is set and FALSE
  7550. //  is returned.
  7551. //--------------------------------------------------------------------------
  7552. WINCRYPT32API
  7553. BOOL
  7554. WINAPI
  7555. CertCloseStore(
  7556.     IN HCERTSTORE hCertStore,
  7557.     DWORD dwFlags
  7558.     );
  7559.  
  7560. //+-------------------------------------------------------------------------
  7561. //  Get the subject certificate context uniquely identified by its Issuer and
  7562. //  SerialNumber from the store.
  7563. //
  7564. //  If the certificate isn't found, NULL is returned. Otherwise, a pointer to
  7565. //  a read only CERT_CONTEXT is returned. CERT_CONTEXT must be freed by calling
  7566. //  CertFreeCertificateContext. CertDuplicateCertificateContext can be called to make a
  7567. //  duplicate.
  7568. //
  7569. //  The returned certificate might not be valid. Normally, it would be
  7570. //  verified when getting its issuer certificate (CertGetIssuerCertificateFromStore).
  7571. //--------------------------------------------------------------------------
  7572. WINCRYPT32API
  7573. PCCERT_CONTEXT
  7574. WINAPI
  7575. CertGetSubjectCertificateFromStore(
  7576.     IN HCERTSTORE hCertStore,
  7577.     IN DWORD dwCertEncodingType,
  7578.     IN PCERT_INFO pCertId           // Only the Issuer and SerialNumber
  7579.     // fields are used
  7580.     );
  7581.  
  7582. //+-------------------------------------------------------------------------
  7583. //  Enumerate the certificate contexts in the store.
  7584. //
  7585. //  If a certificate isn't found, NULL is returned.
  7586. //  Otherwise, a pointer to a read only CERT_CONTEXT is returned. CERT_CONTEXT
  7587. //  must be freed by calling CertFreeCertificateContext or is freed when passed as the
  7588. //  pPrevCertContext on a subsequent call. CertDuplicateCertificateContext
  7589. //  can be called to make a duplicate.
  7590. //
  7591. //  pPrevCertContext MUST BE NULL to enumerate the first
  7592. //  certificate in the store. Successive certificates are enumerated by setting
  7593. //  pPrevCertContext to the CERT_CONTEXT returned by a previous call.
  7594. //
  7595. //  NOTE: a NON-NULL pPrevCertContext is always CertFreeCertificateContext'ed by
  7596. //  this function, even for an error.
  7597. //--------------------------------------------------------------------------
  7598. WINCRYPT32API
  7599. PCCERT_CONTEXT
  7600. WINAPI
  7601. CertEnumCertificatesInStore(
  7602.     IN HCERTSTORE hCertStore,
  7603.     IN PCCERT_CONTEXT pPrevCertContext
  7604.     );
  7605.  
  7606. //+-------------------------------------------------------------------------
  7607. //  Find the first or next certificate context in the store.
  7608. //
  7609. //  The certificate is found according to the dwFindType and its pvFindPara.
  7610. //  See below for a list of the find types and its parameters.
  7611. //
  7612. //  Currently dwFindFlags is only used for CERT_FIND_SUBJECT_ATTR,
  7613. //  CERT_FIND_ISSUER_ATTR or CERT_FIND_CTL_USAGE. Otherwise, must be set to 0.
  7614. //
  7615. //  Usage of dwCertEncodingType depends on the dwFindType.
  7616. //
  7617. //  If the first or next certificate isn't found, NULL is returned.
  7618. //  Otherwise, a pointer to a read only CERT_CONTEXT is returned. CERT_CONTEXT
  7619. //  must be freed by calling CertFreeCertificateContext or is freed when passed as the
  7620. //  pPrevCertContext on a subsequent call. CertDuplicateCertificateContext
  7621. //  can be called to make a duplicate.
  7622. //
  7623. //  pPrevCertContext MUST BE NULL on the first
  7624. //  call to find the certificate. To find the next certificate, the
  7625. //  pPrevCertContext is set to the CERT_CONTEXT returned by a previous call.
  7626. //
  7627. //  NOTE: a NON-NULL pPrevCertContext is always CertFreeCertificateContext'ed by
  7628. //  this function, even for an error.
  7629. //--------------------------------------------------------------------------
  7630. WINCRYPT32API
  7631. PCCERT_CONTEXT
  7632. WINAPI
  7633. CertFindCertificateInStore(
  7634.     IN HCERTSTORE hCertStore,
  7635.     IN DWORD dwCertEncodingType,
  7636.     IN DWORD dwFindFlags,
  7637.     IN DWORD dwFindType,
  7638.     IN const void *pvFindPara,
  7639.     IN PCCERT_CONTEXT pPrevCertContext
  7640.     );
  7641.  
  7642.  
  7643. //+-------------------------------------------------------------------------
  7644. // Certificate comparison functions
  7645. //--------------------------------------------------------------------------
  7646. #define CERT_COMPARE_MASK           0xFFFF
  7647. #define CERT_COMPARE_SHIFT          16
  7648. #define CERT_COMPARE_ANY            0
  7649. #define CERT_COMPARE_SHA1_HASH      1
  7650. #define CERT_COMPARE_NAME           2
  7651. #define CERT_COMPARE_ATTR           3
  7652. #define CERT_COMPARE_MD5_HASH       4
  7653. #define CERT_COMPARE_PROPERTY       5
  7654. #define CERT_COMPARE_PUBLIC_KEY     6
  7655. #define CERT_COMPARE_HASH           CERT_COMPARE_SHA1_HASH
  7656. #define CERT_COMPARE_NAME_STR_A     7
  7657. #define CERT_COMPARE_NAME_STR_W     8
  7658. #define CERT_COMPARE_KEY_SPEC       9
  7659. #define CERT_COMPARE_ENHKEY_USAGE   10
  7660. #define CERT_COMPARE_CTL_USAGE      CERT_COMPARE_ENHKEY_USAGE
  7661. #define CERT_COMPARE_SUBJECT_CERT   11
  7662. #define CERT_COMPARE_ISSUER_OF      12
  7663. #define CERT_COMPARE_EXISTING       13
  7664. #define CERT_COMPARE_SIGNATURE_HASH 14
  7665. #define CERT_COMPARE_KEY_IDENTIFIER 15
  7666. #define CERT_COMPARE_CERT_ID        16
  7667.  
  7668.  
  7669. //+-------------------------------------------------------------------------
  7670. //  dwFindType
  7671. //
  7672. //  The dwFindType definition consists of two components:
  7673. //   - comparison function
  7674. //   - certificate information flag
  7675. //--------------------------------------------------------------------------
  7676. #define CERT_FIND_ANY           (CERT_COMPARE_ANY << CERT_COMPARE_SHIFT)
  7677. #define CERT_FIND_SHA1_HASH     (CERT_COMPARE_SHA1_HASH << CERT_COMPARE_SHIFT)
  7678. #define CERT_FIND_MD5_HASH      (CERT_COMPARE_MD5_HASH << CERT_COMPARE_SHIFT)
  7679. #define CERT_FIND_SIGNATURE_HASH (CERT_COMPARE_SIGNATURE_HASH << CERT_COMPARE_SHIFT)
  7680. #define CERT_FIND_KEY_IDENTIFIER (CERT_COMPARE_KEY_IDENTIFIER << CERT_COMPARE_SHIFT)
  7681. #define CERT_FIND_HASH          CERT_FIND_SHA1_HASH
  7682. #define CERT_FIND_PROPERTY      (CERT_COMPARE_PROPERTY << CERT_COMPARE_SHIFT)
  7683. #define CERT_FIND_PUBLIC_KEY    (CERT_COMPARE_PUBLIC_KEY << CERT_COMPARE_SHIFT)
  7684. #define CERT_FIND_SUBJECT_NAME  (CERT_COMPARE_NAME << CERT_COMPARE_SHIFT | \
  7685.                                  CERT_INFO_SUBJECT_FLAG)
  7686. #define CERT_FIND_SUBJECT_ATTR  (CERT_COMPARE_ATTR << CERT_COMPARE_SHIFT | \
  7687.                                  CERT_INFO_SUBJECT_FLAG)
  7688. #define CERT_FIND_ISSUER_NAME   (CERT_COMPARE_NAME << CERT_COMPARE_SHIFT | \
  7689.                                  CERT_INFO_ISSUER_FLAG)
  7690. #define CERT_FIND_ISSUER_ATTR   (CERT_COMPARE_ATTR << CERT_COMPARE_SHIFT | \
  7691.                                  CERT_INFO_ISSUER_FLAG)
  7692. #define CERT_FIND_SUBJECT_STR_A (CERT_COMPARE_NAME_STR_A << CERT_COMPARE_SHIFT | \
  7693.                                  CERT_INFO_SUBJECT_FLAG)
  7694. #define CERT_FIND_SUBJECT_STR_W (CERT_COMPARE_NAME_STR_W << CERT_COMPARE_SHIFT | \
  7695.                                  CERT_INFO_SUBJECT_FLAG)
  7696. #define CERT_FIND_SUBJECT_STR   CERT_FIND_SUBJECT_STR_W
  7697. #define CERT_FIND_ISSUER_STR_A  (CERT_COMPARE_NAME_STR_A << CERT_COMPARE_SHIFT | \
  7698.                                  CERT_INFO_ISSUER_FLAG)
  7699. #define CERT_FIND_ISSUER_STR_W  (CERT_COMPARE_NAME_STR_W << CERT_COMPARE_SHIFT | \
  7700.                                  CERT_INFO_ISSUER_FLAG)
  7701. #define CERT_FIND_ISSUER_STR    CERT_FIND_ISSUER_STR_W
  7702. #define CERT_FIND_KEY_SPEC      (CERT_COMPARE_KEY_SPEC << CERT_COMPARE_SHIFT)
  7703. #define CERT_FIND_ENHKEY_USAGE  (CERT_COMPARE_ENHKEY_USAGE << CERT_COMPARE_SHIFT)
  7704. #define CERT_FIND_CTL_USAGE     CERT_FIND_ENHKEY_USAGE
  7705.  
  7706. #define CERT_FIND_SUBJECT_CERT  (CERT_COMPARE_SUBJECT_CERT << CERT_COMPARE_SHIFT)
  7707. #define CERT_FIND_ISSUER_OF     (CERT_COMPARE_ISSUER_OF << CERT_COMPARE_SHIFT)
  7708. #define CERT_FIND_EXISTING      (CERT_COMPARE_EXISTING << CERT_COMPARE_SHIFT)
  7709. #define CERT_FIND_CERT_ID       (CERT_COMPARE_CERT_ID << CERT_COMPARE_SHIFT)
  7710.  
  7711.  
  7712.  
  7713. //+-------------------------------------------------------------------------
  7714. //  CERT_FIND_ANY
  7715. //
  7716. //  Find any certificate.
  7717. //
  7718. //  pvFindPara isn't used.
  7719. //--------------------------------------------------------------------------
  7720.  
  7721. //+-------------------------------------------------------------------------
  7722. //  CERT_FIND_HASH
  7723. //
  7724. //  Find a certificate with the specified hash.
  7725. //
  7726. //  pvFindPara points to a CRYPT_HASH_BLOB.
  7727. //--------------------------------------------------------------------------
  7728.  
  7729. //+-------------------------------------------------------------------------
  7730. //  CERT_FIND_KEY_IDENTIFIER
  7731. //
  7732. //  Find a certificate with the specified KeyIdentifier. Gets the
  7733. //  CERT_KEY_IDENTIFIER_PROP_ID property and compares with the input
  7734. //  CRYPT_HASH_BLOB.
  7735. //
  7736. //  pvFindPara points to a CRYPT_HASH_BLOB.
  7737. //--------------------------------------------------------------------------
  7738.  
  7739. //+-------------------------------------------------------------------------
  7740. //  CERT_FIND_PROPERTY
  7741. //
  7742. //  Find a certificate having the specified property.
  7743. //
  7744. //  pvFindPara points to a DWORD containing the PROP_ID
  7745. //--------------------------------------------------------------------------
  7746.  
  7747. //+-------------------------------------------------------------------------
  7748. //  CERT_FIND_PUBLIC_KEY
  7749. //
  7750. //  Find a certificate matching the specified public key.
  7751. //
  7752. //  pvFindPara points to a CERT_PUBLIC_KEY_INFO containing the public key
  7753. //--------------------------------------------------------------------------
  7754.  
  7755. //+-------------------------------------------------------------------------
  7756. //  CERT_FIND_SUBJECT_NAME
  7757. //  CERT_FIND_ISSUER_NAME
  7758. //
  7759. //  Find a certificate with the specified subject/issuer name. Does an exact
  7760. //  match of the entire name.
  7761. //
  7762. //  Restricts search to certificates matching the dwCertEncodingType.
  7763. //
  7764. //  pvFindPara points to a CERT_NAME_BLOB.
  7765. //--------------------------------------------------------------------------
  7766.  
  7767. //+-------------------------------------------------------------------------
  7768. //  CERT_FIND_SUBJECT_ATTR
  7769. //  CERT_FIND_ISSUER_ATTR
  7770. //
  7771. //  Find a certificate with the specified subject/issuer attributes.
  7772. //
  7773. //  Compares the attributes in the subject/issuer name with the
  7774. //  Relative Distinguished Name's (CERT_RDN) array of attributes specified in
  7775. //  pvFindPara. The comparison iterates through the CERT_RDN attributes and looks
  7776. //  for an attribute match in any of the subject/issuer's RDNs.
  7777. //
  7778. //  The CERT_RDN_ATTR fields can have the following special values:
  7779. //    pszObjId == NULL              - ignore the attribute object identifier
  7780. //    dwValueType == RDN_ANY_TYPE   - ignore the value type
  7781. //    Value.pbData == NULL          - match any value
  7782. //
  7783. //  CERT_CASE_INSENSITIVE_IS_RDN_ATTRS_FLAG should be set in dwFindFlags to do
  7784. //  a case insensitive match. Otherwise, defaults to an exact, case sensitive
  7785. //  match.
  7786. //
  7787. //  CERT_UNICODE_IS_RDN_ATTRS_FLAG should be set in dwFindFlags if the RDN was
  7788. //  initialized with unicode strings as for
  7789. //  CryptEncodeObject(X509_UNICODE_NAME).
  7790. //
  7791. //  Restricts search to certificates matching the dwCertEncodingType.
  7792. //
  7793. //  pvFindPara points to a CERT_RDN (defined in wincert.h).
  7794. //--------------------------------------------------------------------------
  7795.  
  7796. //+-------------------------------------------------------------------------
  7797. //  CERT_FIND_SUBJECT_STR_A
  7798. //  CERT_FIND_SUBJECT_STR_W | CERT_FIND_SUBJECT_STR
  7799. //  CERT_FIND_ISSUER_STR_A
  7800. //  CERT_FIND_ISSUER_STR_W  | CERT_FIND_ISSUER_STR
  7801. //
  7802. //  Find a certificate containing the specified subject/issuer name string.
  7803. //
  7804. //  First, the certificate's subject/issuer is converted to a name string
  7805. //  via CertNameToStrA/CertNameToStrW(CERT_SIMPLE_NAME_STR). Then, a
  7806. //  case insensitive substring within string match is performed.
  7807. //
  7808. //  Restricts search to certificates matching the dwCertEncodingType.
  7809. //
  7810. //  For *_STR_A, pvFindPara points to a null terminated character string.
  7811. //  For *_STR_W, pvFindPara points to a null terminated wide character string.
  7812. //--------------------------------------------------------------------------
  7813.  
  7814. //+-------------------------------------------------------------------------
  7815. //  CERT_FIND_KEY_SPEC
  7816. //
  7817. //  Find a certificate having a CERT_KEY_SPEC_PROP_ID property matching
  7818. //  the specified KeySpec.
  7819. //
  7820. //  pvFindPara points to a DWORD containing the KeySpec.
  7821. //--------------------------------------------------------------------------
  7822.  
  7823. //+-------------------------------------------------------------------------
  7824. //  CERT_FIND_ENHKEY_USAGE
  7825. //
  7826. //  Find a certificate having the szOID_ENHANCED_KEY_USAGE extension or
  7827. //  the CERT_ENHKEY_USAGE_PROP_ID and matching the specified pszUsageIdentifers.
  7828. //
  7829. //  pvFindPara points to a CERT_ENHKEY_USAGE data structure. If pvFindPara
  7830. //  is NULL or CERT_ENHKEY_USAGE's cUsageIdentifier is 0, then, matches any
  7831. //  certificate having enhanced key usage.
  7832. //
  7833. //  If the CERT_FIND_VALID_ENHKEY_USAGE_FLAG is set, then, only does a match
  7834. //  for certificates that are valid for the specified usages. By default,
  7835. //  the ceriticate must be valid for all usages. CERT_FIND_OR_ENHKEY_USAGE_FLAG
  7836. //  can be set, if the certificate only needs to be valid for one of the
  7837. //  specified usages. Note, CertGetValidUsages() is called to get the
  7838. //  certificate's list of valid usages. Only the CERT_FIND_OR_ENHKEY_USAGE_FLAG
  7839. //  is applicable when this flag is set.
  7840. //
  7841. //  The CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG can be set in dwFindFlags to
  7842. //  also match a certificate without either the extension or property.
  7843. //
  7844. //  If CERT_FIND_NO_ENHKEY_USAGE_FLAG is set in dwFindFlags, finds
  7845. //  certificates without the key usage extension or property. Setting this
  7846. //  flag takes precedence over pvFindPara being NULL.
  7847. //
  7848. //  If the CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG is set, then, only does a match
  7849. //  using the extension. If pvFindPara is NULL or cUsageIdentifier is set to
  7850. //  0, finds certificates having the extension. If
  7851. //  CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG is set, also matches a certificate
  7852. //  without the extension. If CERT_FIND_NO_ENHKEY_USAGE_FLAG is set, finds
  7853. //  certificates without the extension.
  7854. //
  7855. //  If the CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG is set, then, only does a match
  7856. //  using the property. If pvFindPara is NULL or cUsageIdentifier is set to
  7857. //  0, finds certificates having the property. If
  7858. //  CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG is set, also matches a certificate
  7859. //  without the property. If CERT_FIND_NO_ENHKEY_USAGE_FLAG is set, finds
  7860. //  certificates without the property.
  7861. //
  7862. //  If CERT_FIND_OR_ENHKEY_USAGE_FLAG is set, does an "OR" match of any of
  7863. //  the specified pszUsageIdentifiers. If not set, then, does an "AND" match
  7864. //  of all of the specified pszUsageIdentifiers.
  7865. //--------------------------------------------------------------------------
  7866.  
  7867. #define CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG  0x1
  7868. #define CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG  0x2
  7869. #define CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG 0x4
  7870. #define CERT_FIND_NO_ENHKEY_USAGE_FLAG        0x8
  7871. #define CERT_FIND_OR_ENHKEY_USAGE_FLAG        0x10
  7872. #define CERT_FIND_VALID_ENHKEY_USAGE_FLAG     0x20
  7873.  
  7874. #define CERT_FIND_OPTIONAL_CTL_USAGE_FLAG   CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG
  7875.  
  7876. #define CERT_FIND_EXT_ONLY_CTL_USAGE_FLAG \
  7877.         CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG
  7878.  
  7879. #define CERT_FIND_PROP_ONLY_CTL_USAGE_FLAG \
  7880.         CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG
  7881.  
  7882. #define CERT_FIND_NO_CTL_USAGE_FLAG         CERT_FIND_NO_ENHKEY_USAGE_FLAG
  7883. #define CERT_FIND_OR_CTL_USAGE_FLAG         CERT_FIND_OR_ENHKEY_USAGE_FLAG
  7884. #define CERT_FIND_VALID_CTL_USAGE_FLAG      CERT_FIND_VALID_ENHKEY_USAGE_FLAG
  7885.  
  7886. //+-------------------------------------------------------------------------
  7887. //  CERT_FIND_CERT_ID
  7888. //
  7889. //  Find a certificate with the specified CERT_ID.
  7890. //
  7891. //  pvFindPara points to a CERT_ID.
  7892. //--------------------------------------------------------------------------
  7893.  
  7894. //+-------------------------------------------------------------------------
  7895. //  Get the certificate context from the store for the first or next issuer
  7896. //  of the specified subject certificate. Perform the enabled
  7897. //  verification checks on the subject. (Note, the checks are on the subject
  7898. //  using the returned issuer certificate.)
  7899. //
  7900. //  If the first or next issuer certificate isn't found, NULL is returned.
  7901. //  Otherwise, a pointer to a read only CERT_CONTEXT is returned. CERT_CONTEXT
  7902. //  must be freed by calling CertFreeCertificateContext or is freed when passed as the
  7903. //  pPrevIssuerContext on a subsequent call. CertDuplicateCertificateContext
  7904. //  can be called to make a duplicate.
  7905. //
  7906. //  For a self signed subject certificate, NULL is returned with LastError set
  7907. //  to CERT_STORE_SELF_SIGNED. The enabled verification checks are still done.
  7908. //
  7909. //  The pSubjectContext may have been obtained from this store, another store
  7910. //  or created by the caller application. When created by the caller, the
  7911. //  CertCreateCertificateContext function must have been called.
  7912. //
  7913. //  An issuer may have multiple certificates. This may occur when the validity
  7914. //  period is about to change. pPrevIssuerContext MUST BE NULL on the first
  7915. //  call to get the issuer. To get the next certificate for the issuer, the
  7916. //  pPrevIssuerContext is set to the CERT_CONTEXT returned by a previous call.
  7917. //
  7918. //  NOTE: a NON-NULL pPrevIssuerContext is always CertFreeCertificateContext'ed by
  7919. //  this function, even for an error.
  7920. //
  7921. //  The following flags can be set in *pdwFlags to enable verification checks
  7922. //  on the subject certificate context:
  7923. //      CERT_STORE_SIGNATURE_FLAG     - use the public key in the returned
  7924. //                                      issuer certificate to verify the
  7925. //                                      signature on the subject certificate.
  7926. //                                      Note, if pSubjectContext->hCertStore ==
  7927. //                                      hCertStore, the store provider might
  7928. //                                      be able to eliminate a redo of
  7929. //                                      the signature verify.
  7930. //      CERT_STORE_TIME_VALIDITY_FLAG - get the current time and verify that
  7931. //                                      its within the subject certificate's
  7932. //                                      validity period
  7933. //      CERT_STORE_REVOCATION_FLAG    - check if the subject certificate is on
  7934. //                                      the issuer's revocation list
  7935. //
  7936. //  If an enabled verification check fails, then, its flag is set upon return.
  7937. //  If CERT_STORE_REVOCATION_FLAG was enabled and the issuer doesn't have a
  7938. //  CRL in the store, then, CERT_STORE_NO_CRL_FLAG is set in addition to
  7939. //  the CERT_STORE_REVOCATION_FLAG.
  7940. //
  7941. //  If CERT_STORE_SIGNATURE_FLAG or CERT_STORE_REVOCATION_FLAG is set, then,
  7942. //  CERT_STORE_NO_ISSUER_FLAG is set if it doesn't have an issuer certificate
  7943. //  in the store.
  7944. //
  7945. //  For a verification check failure, a pointer to the issuer's CERT_CONTEXT
  7946. //  is still returned and SetLastError isn't updated.
  7947. //--------------------------------------------------------------------------
  7948. WINCRYPT32API
  7949. PCCERT_CONTEXT
  7950. WINAPI
  7951. CertGetIssuerCertificateFromStore(
  7952.     IN HCERTSTORE hCertStore,
  7953.     IN PCCERT_CONTEXT pSubjectContext,
  7954.     IN OPTIONAL PCCERT_CONTEXT pPrevIssuerContext,
  7955.     IN OUT DWORD *pdwFlags
  7956.     );
  7957.  
  7958. //+-------------------------------------------------------------------------
  7959. //  Perform the enabled verification checks on the subject certificate
  7960. //  using the issuer. Same checks and flags definitions as for the above
  7961. //  CertGetIssuerCertificateFromStore.
  7962. //
  7963. //  If you are only checking CERT_STORE_TIME_VALIDITY_FLAG, then, the
  7964. //  issuer can be NULL.
  7965. //
  7966. //  For a verification check failure, SUCCESS is still returned.
  7967. //--------------------------------------------------------------------------
  7968. WINCRYPT32API
  7969. BOOL
  7970. WINAPI
  7971. CertVerifySubjectCertificateContext(
  7972.     IN PCCERT_CONTEXT pSubject,
  7973.     IN OPTIONAL PCCERT_CONTEXT pIssuer,
  7974.     IN OUT DWORD *pdwFlags
  7975.     );
  7976.  
  7977. //+-------------------------------------------------------------------------
  7978. //  Duplicate a certificate context
  7979. //--------------------------------------------------------------------------
  7980. WINCRYPT32API
  7981. PCCERT_CONTEXT
  7982. WINAPI
  7983. CertDuplicateCertificateContext(
  7984.     IN PCCERT_CONTEXT pCertContext
  7985.     );
  7986.  
  7987. //+-------------------------------------------------------------------------
  7988. //  Create a certificate context from the encoded certificate. The created
  7989. //  context isn't put in a store.
  7990. //
  7991. //  Makes a copy of the encoded certificate in the created context.
  7992. //
  7993. //  If unable to decode and create the certificate context, NULL is returned.
  7994. //  Otherwise, a pointer to a read only CERT_CONTEXT is returned.
  7995. //  CERT_CONTEXT must be freed by calling CertFreeCertificateContext.
  7996. //  CertDuplicateCertificateContext can be called to make a duplicate.
  7997. //
  7998. //  CertSetCertificateContextProperty and CertGetCertificateContextProperty can be called
  7999. //  to store properties for the certificate.
  8000. //--------------------------------------------------------------------------
  8001. WINCRYPT32API
  8002. PCCERT_CONTEXT
  8003. WINAPI
  8004. CertCreateCertificateContext(
  8005.     IN DWORD dwCertEncodingType,
  8006.     IN const BYTE *pbCertEncoded,
  8007.     IN DWORD cbCertEncoded
  8008.     );
  8009.  
  8010. //+-------------------------------------------------------------------------
  8011. //  Free a certificate context
  8012. //
  8013. //  There needs to be a corresponding free for each context obtained by a
  8014. //  get, find, duplicate or create.
  8015. //--------------------------------------------------------------------------
  8016. WINCRYPT32API
  8017. BOOL
  8018. WINAPI
  8019. CertFreeCertificateContext(
  8020.     IN PCCERT_CONTEXT pCertContext
  8021.     );
  8022.  
  8023. //+-------------------------------------------------------------------------
  8024. //  Set the property for the specified certificate context.
  8025. //
  8026. //  The type definition for pvData depends on the dwPropId value. There are
  8027. //  five predefined types:
  8028. //      CERT_KEY_PROV_HANDLE_PROP_ID - a HCRYPTPROV for the certificate's
  8029. //      private key is passed in pvData. Updates the hCryptProv field
  8030. //      of the CERT_KEY_CONTEXT_PROP_ID. If the CERT_KEY_CONTEXT_PROP_ID
  8031. //      doesn't exist, its created with all the other fields zeroed out. If
  8032. //      CERT_STORE_NO_CRYPT_RELEASE_FLAG isn't set, HCRYPTPROV is implicitly
  8033. //      released when either the property is set to NULL or on the final
  8034. //      free of the CertContext.
  8035. //
  8036. //      CERT_KEY_PROV_INFO_PROP_ID - a PCRYPT_KEY_PROV_INFO for the certificate's
  8037. //      private key is passed in pvData.
  8038. //
  8039. //      CERT_SHA1_HASH_PROP_ID       -
  8040. //      CERT_MD5_HASH_PROP_ID        -
  8041. //      CERT_SIGNATURE_HASH_PROP_ID  - normally, a hash property is implicitly
  8042. //      set by doing a CertGetCertificateContextProperty. pvData points to a
  8043. //      CRYPT_HASH_BLOB.
  8044. //
  8045. //      CERT_KEY_CONTEXT_PROP_ID - a PCERT_KEY_CONTEXT for the certificate's
  8046. //      private key is passed in pvData. The CERT_KEY_CONTEXT contains both the
  8047. //      hCryptProv and dwKeySpec for the private key.
  8048. //      See the CERT_KEY_PROV_HANDLE_PROP_ID for more information about
  8049. //      the hCryptProv field and dwFlags settings. Note, more fields may
  8050. //      be added for this property. The cbSize field value will be adjusted
  8051. //      accordingly.
  8052. //
  8053. //      CERT_KEY_SPEC_PROP_ID - the dwKeySpec for the private key. pvData
  8054. //      points to a DWORD containing the KeySpec
  8055. //
  8056. //      CERT_ENHKEY_USAGE_PROP_ID - enhanced key usage definition for the
  8057. //      certificate. pvData points to a CRYPT_DATA_BLOB containing an
  8058. //      ASN.1 encoded CERT_ENHKEY_USAGE (encoded via
  8059. //      CryptEncodeObject(X509_ENHANCED_KEY_USAGE).
  8060. //
  8061. //      CERT_NEXT_UPDATE_LOCATION_PROP_ID - location of the next update.
  8062. //      Currently only applicable to CTLs. pvData points to a CRYPT_DATA_BLOB
  8063. //      containing an ASN.1 encoded CERT_ALT_NAME_INFO (encoded via
  8064. //      CryptEncodeObject(X509_ALTERNATE_NAME)).
  8065. //
  8066. //      CERT_FRIENDLY_NAME_PROP_ID - friendly name for the cert, CRL or CTL.
  8067. //      pvData points to a CRYPT_DATA_BLOB. pbData is a pointer to a NULL
  8068. //      terminated unicode, wide character string.
  8069. //      cbData = (wcslen((LPWSTR) pbData) + 1) * sizeof(WCHAR).
  8070. //
  8071. //      CERT_DESCRIPTION_PROP_ID - description for the cert, CRL or CTL.
  8072. //      pvData points to a CRYPT_DATA_BLOB. pbData is a pointer to a NULL
  8073. //      terminated unicode, wide character string.
  8074. //      cbData = (wcslen((LPWSTR) pbData) + 1) * sizeof(WCHAR).
  8075. //
  8076. //      CERT_ARCHIVED_PROP_ID - when this property is set, the certificate
  8077. //      is skipped during enumeration. Note, certificates having this property
  8078. //      are still found for explicit finds, such as, finding a certificate
  8079. //      with a specific hash or finding a certificate having a specific issuer
  8080. //      and serial number. pvData points to a CRYPT_DATA_BLOB. This blob
  8081. //      can be NULL (pbData = NULL, cbData = 0).
  8082. //
  8083. //      CERT_PUBKEY_ALG_PARA_PROP_ID - for public keys supporting
  8084. //      algorithm parameter inheritance. pvData points to a CRYPT_OBJID_BLOB
  8085. //      containing the ASN.1 encoded PublicKey Algorithm Parameters. For
  8086. //      DSS this would be the parameters encoded via
  8087. //      CryptEncodeObject(X509_DSS_PARAMETERS). This property may be set
  8088. //      by CryptVerifyCertificateSignatureEx().
  8089. //
  8090. //  For all the other PROP_IDs: an encoded PCRYPT_DATA_BLOB is passed in pvData.
  8091. //
  8092. //  If the property already exists, then, the old value is deleted and silently
  8093. //  replaced. Setting, pvData to NULL, deletes the property.
  8094. //
  8095. //  CERT_SET_PROPERTY_IGNORE_PERSIST_ERROR_FLAG can be set to ignore any
  8096. //  provider write errors and always update the cached context's property.
  8097. //--------------------------------------------------------------------------
  8098. WINCRYPT32API
  8099. BOOL
  8100. WINAPI
  8101. CertSetCertificateContextProperty(
  8102.     IN PCCERT_CONTEXT pCertContext,
  8103.     IN DWORD dwPropId,
  8104.     IN DWORD dwFlags,
  8105.     IN const void *pvData
  8106.     );
  8107.  
  8108. // Set this flag to ignore any store provider write errors and always update
  8109. // the cached context's property
  8110. #define CERT_SET_PROPERTY_IGNORE_PERSIST_ERROR_FLAG     0x80000000
  8111.  
  8112. //+-------------------------------------------------------------------------
  8113. //  Get the property for the specified certificate context.
  8114. //
  8115. //  For CERT_KEY_PROV_HANDLE_PROP_ID, pvData points to a HCRYPTPROV.
  8116. //
  8117. //  For CERT_KEY_PROV_INFO_PROP_ID, pvData points to a CRYPT_KEY_PROV_INFO structure.
  8118. //  Elements pointed to by fields in the pvData structure follow the
  8119. //  structure. Therefore, *pcbData may exceed the size of the structure.
  8120. //
  8121. //  For CERT_KEY_CONTEXT_PROP_ID, pvData points to a CERT_KEY_CONTEXT structure.
  8122. //
  8123. //  For CERT_KEY_SPEC_PROP_ID, pvData points to a DWORD containing the KeySpec.
  8124. //  If the CERT_KEY_CONTEXT_PROP_ID exists, the KeySpec is obtained from there.
  8125. //  Otherwise, if the CERT_KEY_PROV_INFO_PROP_ID exists, its the source
  8126. //  of the KeySpec.
  8127. //
  8128. //  For CERT_SHA1_HASH_PROP_ID or CERT_MD5_HASH_PROP_ID, if the hash
  8129. //  doesn't already exist, then, its computed via CryptHashCertificate()
  8130. //  and then set. pvData points to the computed hash. Normally, the length
  8131. //  is 20 bytes for SHA and 16 for MD5.
  8132. //
  8133. //  For CERT_SIGNATURE_HASH_PROP_ID, if the hash
  8134. //  doesn't already exist, then, its computed via CryptHashToBeSigned()
  8135. //  and then set. pvData points to the computed hash. Normally, the length
  8136. //  is 20 bytes for SHA and 16 for MD5.
  8137. //
  8138. //  For CERT_ACCESS_STATE_PROP_ID, pvData points to a DWORD containing the
  8139. //  access state flags. The appropriate CERT_ACCESS_STATE_*_FLAG's are set
  8140. //  in the returned DWORD. See the CERT_ACCESS_STATE_*_FLAG definitions
  8141. //  above. Note, this property is read only. It can't be set.
  8142. //
  8143. //  For CERT_KEY_IDENTIFIER_PROP_ID, if property doesn't already exist,
  8144. //  first searches for the szOID_SUBJECT_KEY_IDENTIFIER extension. Next,
  8145. //  does SHA1 hash of the certficate's SubjectPublicKeyInfo. pvData
  8146. //  points to the key identifier bytes. Normally, the length is 20 bytes.
  8147. //
  8148. //  For CERT_PUBKEY_ALG_PARA_PROP_ID, pvPara points to the ASN.1 encoded
  8149. //  PublicKey Algorithm Parameters. This property will only be set
  8150. //  for public keys supporting algorithm parameter inheritance and when the
  8151. //  parameters have been omitted from the encoded and signed certificate.
  8152. //
  8153. //  For all other PROP_IDs, pvData points to an encoded array of bytes.
  8154. //--------------------------------------------------------------------------
  8155. WINCRYPT32API
  8156. BOOL
  8157. WINAPI
  8158. CertGetCertificateContextProperty(
  8159.     IN PCCERT_CONTEXT pCertContext,
  8160.     IN DWORD dwPropId,
  8161.     OUT void *pvData,
  8162.     IN OUT DWORD *pcbData
  8163.     );
  8164.  
  8165. //+-------------------------------------------------------------------------
  8166. //  Enumerate the properties for the specified certificate context.
  8167. //
  8168. //  To get the first property, set dwPropId to 0. The ID of the first
  8169. //  property is returned. To get the next property, set dwPropId to the
  8170. //  ID returned by the last call. To enumerate all the properties continue
  8171. //  until 0 is returned.
  8172. //
  8173. //  CertGetCertificateContextProperty is called to get the property's data.
  8174. //
  8175. //  Note, since, the CERT_KEY_PROV_HANDLE_PROP_ID and CERT_KEY_SPEC_PROP_ID
  8176. //  properties are stored as fields in the CERT_KEY_CONTEXT_PROP_ID
  8177. //  property, they aren't enumerated individually.
  8178. //--------------------------------------------------------------------------
  8179. WINCRYPT32API
  8180. DWORD
  8181. WINAPI
  8182. CertEnumCertificateContextProperties(
  8183.     IN PCCERT_CONTEXT pCertContext,
  8184.     IN DWORD dwPropId
  8185.     );
  8186.  
  8187. //+-------------------------------------------------------------------------
  8188. //  Get the first or next CRL context from the store for the specified
  8189. //  issuer certificate. Perform the enabled verification checks on the CRL.
  8190. //
  8191. //  If the first or next CRL isn't found, NULL is returned.
  8192. //  Otherwise, a pointer to a read only CRL_CONTEXT is returned. CRL_CONTEXT
  8193. //  must be freed by calling CertFreeCRLContext. However, the free must be
  8194. //  pPrevCrlContext on a subsequent call. CertDuplicateCRLContext
  8195. //  can be called to make a duplicate.
  8196. //
  8197. //  The pIssuerContext may have been obtained from this store, another store
  8198. //  or created by the caller application. When created by the caller, the
  8199. //  CertCreateCertificateContext function must have been called.
  8200. //
  8201. //  If pIssuerContext == NULL, finds all the CRLs in the store.
  8202. //
  8203. //  An issuer may have multiple CRLs. For example, it generates delta CRLs
  8204. //  using a X.509 v3 extension. pPrevCrlContext MUST BE NULL on the first
  8205. //  call to get the CRL. To get the next CRL for the issuer, the
  8206. //  pPrevCrlContext is set to the CRL_CONTEXT returned by a previous call.
  8207. //
  8208. //  NOTE: a NON-NULL pPrevCrlContext is always CertFreeCRLContext'ed by
  8209. //  this function, even for an error.
  8210. //
  8211. //  The following flags can be set in *pdwFlags to enable verification checks
  8212. //  on the returned CRL:
  8213. //      CERT_STORE_SIGNATURE_FLAG     - use the public key in the
  8214. //                                      issuer's certificate to verify the
  8215. //                                      signature on the returned CRL.
  8216. //                                      Note, if pIssuerContext->hCertStore ==
  8217. //                                      hCertStore, the store provider might
  8218. //                                      be able to eliminate a redo of
  8219. //                                      the signature verify.
  8220. //      CERT_STORE_TIME_VALIDITY_FLAG - get the current time and verify that
  8221. //                                      its within the CRL's ThisUpdate and
  8222. //                                      NextUpdate validity period.
  8223. //
  8224. //  If an enabled verification check fails, then, its flag is set upon return.
  8225. //
  8226. //  If pIssuerContext == NULL, then, an enabled CERT_STORE_SIGNATURE_FLAG
  8227. //  always fails and the CERT_STORE_NO_ISSUER_FLAG is also set.
  8228. //
  8229. //  For a verification check failure, a pointer to the first or next
  8230. //  CRL_CONTEXT is still returned and SetLastError isn't updated.
  8231. //--------------------------------------------------------------------------
  8232. WINCRYPT32API
  8233. PCCRL_CONTEXT
  8234. WINAPI
  8235. CertGetCRLFromStore(
  8236.     IN HCERTSTORE hCertStore,
  8237.     IN OPTIONAL PCCERT_CONTEXT pIssuerContext,
  8238.     IN PCCRL_CONTEXT pPrevCrlContext,
  8239.     IN OUT DWORD *pdwFlags
  8240.     );
  8241.  
  8242. //+-------------------------------------------------------------------------
  8243. //  Enumerate the CRL contexts in the store.
  8244. //
  8245. //  If a CRL isn't found, NULL is returned.
  8246. //  Otherwise, a pointer to a read only CRL_CONTEXT is returned. CRL_CONTEXT
  8247. //  must be freed by calling CertFreeCRLContext or is freed when passed as the
  8248. //  pPrevCrlContext on a subsequent call. CertDuplicateCRLContext
  8249. //  can be called to make a duplicate.
  8250. //
  8251. //  pPrevCrlContext MUST BE NULL to enumerate the first
  8252. //  CRL in the store. Successive CRLs are enumerated by setting
  8253. //  pPrevCrlContext to the CRL_CONTEXT returned by a previous call.
  8254. //
  8255. //  NOTE: a NON-NULL pPrevCrlContext is always CertFreeCRLContext'ed by
  8256. //  this function, even for an error.
  8257. //--------------------------------------------------------------------------
  8258. WINCRYPT32API
  8259. PCCRL_CONTEXT
  8260. WINAPI
  8261. CertEnumCRLsInStore(
  8262.     IN HCERTSTORE hCertStore,
  8263.     IN PCCRL_CONTEXT pPrevCrlContext
  8264.     );
  8265.  
  8266. //+-------------------------------------------------------------------------
  8267. //  Find the first or next CRL context in the store.
  8268. //
  8269. //  The CRL is found according to the dwFindType and its pvFindPara.
  8270. //  See below for a list of the find types and its parameters.
  8271. //
  8272. //  Currently dwFindFlags isn't used and must be set to 0.
  8273. //
  8274. //  Usage of dwCertEncodingType depends on the dwFindType.
  8275. //
  8276. //  If the first or next CRL isn't found, NULL is returned.
  8277. //  Otherwise, a pointer to a read only CRL_CONTEXT is returned. CRL_CONTEXT
  8278. //  must be freed by calling CertFreeCRLContext or is freed when passed as the
  8279. //  pPrevCrlContext on a subsequent call. CertDuplicateCRLContext
  8280. //  can be called to make a duplicate.
  8281. //
  8282. //  pPrevCrlContext MUST BE NULL on the first
  8283. //  call to find the CRL. To find the next CRL, the
  8284. //  pPrevCrlContext is set to the CRL_CONTEXT returned by a previous call.
  8285. //
  8286. //  NOTE: a NON-NULL pPrevCrlContext is always CertFreeCRLContext'ed by
  8287. //  this function, even for an error.
  8288. //--------------------------------------------------------------------------
  8289. WINCRYPT32API
  8290. PCCRL_CONTEXT
  8291. WINAPI
  8292. CertFindCRLInStore(
  8293.     IN HCERTSTORE hCertStore,
  8294.     IN DWORD dwCertEncodingType,
  8295.     IN DWORD dwFindFlags,
  8296.     IN DWORD dwFindType,
  8297.     IN const void *pvFindPara,
  8298.     IN PCCRL_CONTEXT pPrevCrlContext
  8299.     );
  8300.  
  8301. #define CRL_FIND_ANY                0
  8302. #define CRL_FIND_ISSUED_BY          1
  8303. #define CRL_FIND_EXISTING           2
  8304.  
  8305. //+-------------------------------------------------------------------------
  8306. //  CRL_FIND_ANY
  8307. //
  8308. //  Find any CRL.
  8309. //
  8310. //  pvFindPara isn't used.
  8311. //--------------------------------------------------------------------------
  8312.  
  8313. //+-------------------------------------------------------------------------
  8314. //  CRL_FIND_ISSUED_BY
  8315. //
  8316. //  Find CRL matching the specified issuer. 
  8317. //
  8318. //  pvFindPara is the PCCERT_CONTEXT of the CRL issuer.
  8319. //
  8320. //  By default, only does issuer name matching. The following flags can be
  8321. //  set in dwFindFlags to do additional filtering.
  8322. //
  8323. //  If CRL_FIND_ISSUED_BY_AKI_FLAG is set in dwFindFlags, then, checks if the
  8324. //  CRL has an Authority Key Identifier (AKI) extension. If the CRL has an
  8325. //  AKI, then, only returns a CRL whose AKI matches the issuer.
  8326. //
  8327. //  Note, the AKI extension has the following OID:
  8328. //  szOID_AUTHORITY_KEY_IDENTIFIER2 and its corresponding data structure.
  8329. //
  8330. //  If CRL_FIND_ISSUED_BY_SIGNATURE_FLAG is set in dwFindFlags, then,
  8331. //  uses the public key in the issuer's certificate to verify the
  8332. //  signature on the CRL. Only returns a CRL having a valid signature.
  8333. //--------------------------------------------------------------------------
  8334. #define CRL_FIND_ISSUED_BY_AKI_FLAG         0x1
  8335. #define CRL_FIND_ISSUED_BY_SIGNATURE_FLAG   0x2
  8336.  
  8337. //+-------------------------------------------------------------------------
  8338. //  CRL_FIND_EXISTING
  8339. //
  8340. //  Find existing CRL in the store.
  8341. //
  8342. //  pvFindPara is the PCCRL_CONTEXT of the CRL to check if it already
  8343. //  exists in the store.
  8344. //--------------------------------------------------------------------------
  8345.  
  8346.  
  8347. //+-------------------------------------------------------------------------
  8348. //  Duplicate a CRL context
  8349. //--------------------------------------------------------------------------
  8350. WINCRYPT32API
  8351. PCCRL_CONTEXT
  8352. WINAPI
  8353. CertDuplicateCRLContext(
  8354.     IN PCCRL_CONTEXT pCrlContext
  8355.     );
  8356.  
  8357. //+-------------------------------------------------------------------------
  8358. //  Create a CRL context from the encoded CRL. The created
  8359. //  context isn't put in a store.
  8360. //
  8361. //  Makes a copy of the encoded CRL in the created context.
  8362. //
  8363. //  If unable to decode and create the CRL context, NULL is returned.
  8364. //  Otherwise, a pointer to a read only CRL_CONTEXT is returned.
  8365. //  CRL_CONTEXT must be freed by calling CertFreeCRLContext.
  8366. //  CertDuplicateCRLContext can be called to make a duplicate.
  8367. //
  8368. //  CertSetCRLContextProperty and CertGetCRLContextProperty can be called
  8369. //  to store properties for the CRL.
  8370. //--------------------------------------------------------------------------
  8371. WINCRYPT32API
  8372. PCCRL_CONTEXT
  8373. WINAPI
  8374. CertCreateCRLContext(
  8375.     IN DWORD dwCertEncodingType,
  8376.     IN const BYTE *pbCrlEncoded,
  8377.     IN DWORD cbCrlEncoded
  8378.     );
  8379.  
  8380. //+-------------------------------------------------------------------------
  8381. //  Free a CRL context
  8382. //
  8383. //  There needs to be a corresponding free for each context obtained by a
  8384. //  get, duplicate or create.
  8385. //--------------------------------------------------------------------------
  8386. WINCRYPT32API
  8387. BOOL
  8388. WINAPI
  8389. CertFreeCRLContext(
  8390.     IN PCCRL_CONTEXT pCrlContext
  8391.     );
  8392.  
  8393. //+-------------------------------------------------------------------------
  8394. //  Set the property for the specified CRL context.
  8395. //
  8396. //  Same Property Ids and semantics as CertSetCertificateContextProperty.
  8397. //--------------------------------------------------------------------------
  8398. WINCRYPT32API
  8399. BOOL
  8400. WINAPI
  8401. CertSetCRLContextProperty(
  8402.     IN PCCRL_CONTEXT pCrlContext,
  8403.     IN DWORD dwPropId,
  8404.     IN DWORD dwFlags,
  8405.     IN const void *pvData
  8406.     );
  8407.  
  8408. //+-------------------------------------------------------------------------
  8409. //  Get the property for the specified CRL context.
  8410. //
  8411. //  Same Property Ids and semantics as CertGetCertificateContextProperty.
  8412. //
  8413. //  CERT_SHA1_HASH_PROP_ID, CERT_MD5_HASH_PROP_ID or
  8414. //  CERT_SIGNATURE_HASH_PROP_ID is the predefined property of most interest.
  8415. //--------------------------------------------------------------------------
  8416. WINCRYPT32API
  8417. BOOL
  8418. WINAPI
  8419. CertGetCRLContextProperty(
  8420.     IN PCCRL_CONTEXT pCrlContext,
  8421.     IN DWORD dwPropId,
  8422.     OUT void *pvData,
  8423.     IN OUT DWORD *pcbData
  8424.     );
  8425.  
  8426. //+-------------------------------------------------------------------------
  8427. //  Enumerate the properties for the specified CRL context.
  8428. //
  8429. //  To get the first property, set dwPropId to 0. The ID of the first
  8430. //  property is returned. To get the next property, set dwPropId to the
  8431. //  ID returned by the last call. To enumerate all the properties continue
  8432. //  until 0 is returned.
  8433. //
  8434. //  CertGetCRLContextProperty is called to get the property's data.
  8435. //--------------------------------------------------------------------------
  8436. WINCRYPT32API
  8437. DWORD
  8438. WINAPI
  8439. CertEnumCRLContextProperties(
  8440.     IN PCCRL_CONTEXT pCrlContext,
  8441.     IN DWORD dwPropId
  8442.     );
  8443.  
  8444.  
  8445. //+-------------------------------------------------------------------------
  8446. //  Search the CRL's list of entries for the specified certificate.
  8447. //
  8448. //  TRUE is returned if we were able to search the list. Otherwise, FALSE is
  8449. //  returned,
  8450. //
  8451. //  For success, if the certificate was found in the list, *ppCrlEntry is
  8452. //  updated with a pointer to the entry. Otherwise, *ppCrlEntry is set to NULL.
  8453. //  The returned entry isn't allocated and must not be freed.
  8454. //
  8455. //  dwFlags and pvReserved currently aren't used and must be set to 0 or NULL.
  8456. //--------------------------------------------------------------------------
  8457. WINCRYPT32API
  8458. BOOL
  8459. WINAPI
  8460. CertFindCertificateInCRL(
  8461.     IN PCCERT_CONTEXT pCert,
  8462.     IN PCCRL_CONTEXT pCrlContext,
  8463.     IN DWORD dwFlags,
  8464.     IN OPTIONAL void *pvReserved,
  8465.     OUT PCRL_ENTRY *ppCrlEntry
  8466.     );
  8467.  
  8468. //+-------------------------------------------------------------------------
  8469. // Add certificate/CRL, encoded, context or element disposition values.
  8470. //--------------------------------------------------------------------------
  8471. #define CERT_STORE_ADD_NEW                                  1
  8472. #define CERT_STORE_ADD_USE_EXISTING                         2
  8473. #define CERT_STORE_ADD_REPLACE_EXISTING                     3
  8474. #define CERT_STORE_ADD_ALWAYS                               4
  8475. #define CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES  5
  8476. #define CERT_STORE_ADD_NEWER                                6
  8477. #define CERT_STORE_ADD_NEWER_INHERIT_PROPERTIES             7
  8478.  
  8479.  
  8480. //+-------------------------------------------------------------------------
  8481. //  Add the encoded certificate to the store according to the specified
  8482. //  disposition action.
  8483. //
  8484. //  Makes a copy of the encoded certificate before adding to the store.
  8485. //
  8486. //  dwAddDispostion specifies the action to take if the certificate
  8487. //  already exists in the store. This parameter must be one of the following
  8488. //  values:
  8489. //    CERT_STORE_ADD_NEW
  8490. //      Fails if the certificate already exists in the store. LastError
  8491. //      is set to CRYPT_E_EXISTS.
  8492. //    CERT_STORE_ADD_USE_EXISTING
  8493. //      If the certifcate already exists, then, its used and if ppCertContext
  8494. //      is non-NULL, the existing context is duplicated.
  8495. //    CERT_STORE_ADD_REPLACE_EXISTING
  8496. //      If the certificate already exists, then, the existing certificate
  8497. //      context is deleted before creating and adding the new context.
  8498. //    CERT_STORE_ADD_ALWAYS
  8499. //      No check is made to see if the certificate already exists. A
  8500. //      new certificate context is always created. This may lead to
  8501. //      duplicates in the store.
  8502. //    CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES
  8503. //      If the certificate already exists, then, its used.
  8504. //    CERT_STORE_ADD_NEWER
  8505. //      Fails if the certificate already exists in the store AND the NotBefore
  8506. //      time of the existing certificate is equal to or greater than the
  8507. //      NotBefore time of the new certificate being added. LastError
  8508. //      is set to CRYPT_E_EXISTS.
  8509. //
  8510. //      If an older certificate is replaced, same as
  8511. //      CERT_STORE_ADD_REPLACE_EXISTING.
  8512. //
  8513. //      For CRLs or CTLs compares the ThisUpdate times.
  8514. //
  8515. //    CERT_STORE_ADD_NEWER_INHERIT_PROPERTIES
  8516. //      Same as CERT_STORE_ADD_NEWER. However, if an older certificate is
  8517. //      replaced, same as CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES.
  8518. //
  8519. //  CertGetSubjectCertificateFromStore is called to determine if the
  8520. //  certificate already exists in the store.
  8521. //
  8522. //  ppCertContext can be NULL, indicating the caller isn't interested
  8523. //  in getting the CERT_CONTEXT of the added or existing certificate.
  8524. //--------------------------------------------------------------------------
  8525. WINCRYPT32API
  8526. BOOL
  8527. WINAPI
  8528. CertAddEncodedCertificateToStore(
  8529.     IN HCERTSTORE hCertStore,
  8530.     IN DWORD dwCertEncodingType,
  8531.     IN const BYTE *pbCertEncoded,
  8532.     IN DWORD cbCertEncoded,
  8533.     IN DWORD dwAddDisposition,
  8534.     OUT OPTIONAL PCCERT_CONTEXT *ppCertContext
  8535.     );
  8536.  
  8537. //+-------------------------------------------------------------------------
  8538. //  Add the certificate context to the store according to the specified
  8539. //  disposition action.
  8540. //
  8541. //  In addition to the encoded certificate, the context's properties are
  8542. //  also copied.  Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  8543. //  CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't copied.
  8544. //
  8545. //  Makes a copy of the certificate context before adding to the store.
  8546. //
  8547. //  dwAddDispostion specifies the action to take if the certificate
  8548. //  already exists in the store. This parameter must be one of the following
  8549. //  values:
  8550. //    CERT_STORE_ADD_NEW
  8551. //      Fails if the certificate already exists in the store. LastError
  8552. //      is set to CRYPT_E_EXISTS.
  8553. //    CERT_STORE_ADD_USE_EXISTING
  8554. //      If the certifcate already exists, then, its used and if ppStoreContext
  8555. //      is non-NULL, the existing context is duplicated. Iterates
  8556. //      through pCertContext's properties and only copies the properties
  8557. //      that don't already exist. The SHA1 and MD5 hash properties aren't
  8558. //      copied.
  8559. //    CERT_STORE_ADD_REPLACE_EXISTING
  8560. //      If the certificate already exists, then, the existing certificate
  8561. //      context is deleted before creating and adding a new context.
  8562. //      Properties are copied before doing the add.
  8563. //    CERT_STORE_ADD_ALWAYS
  8564. //      No check is made to see if the certificate already exists. A
  8565. //      new certificate context is always created and added. This may lead to
  8566. //      duplicates in the store. Properties are
  8567. //      copied before doing the add.
  8568. //    CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES
  8569. //      If the certificate already exists, then, the existing certificate
  8570. //      context is used. Properties from the added context are copied and
  8571. //      replace existing properties. However, any existing properties not
  8572. //      in the added context remain and aren't deleted.
  8573. //    CERT_STORE_ADD_NEWER
  8574. //      Fails if the certificate already exists in the store AND the NotBefore
  8575. //      time of the existing context is equal to or greater than the
  8576. //      NotBefore time of the new context being added. LastError
  8577. //      is set to CRYPT_E_EXISTS.
  8578. //
  8579. //      If an older context is replaced, same as
  8580. //      CERT_STORE_ADD_REPLACE_EXISTING.
  8581. //
  8582. //      For CRLs or CTLs compares the ThisUpdate times.
  8583. //
  8584. //    CERT_STORE_ADD_NEWER_INHERIT_PROPERTIES
  8585. //      Same as CERT_STORE_ADD_NEWER. However, if an older context is
  8586. //      replaced, same as CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES.
  8587. //
  8588. //  CertGetSubjectCertificateFromStore is called to determine if the
  8589. //  certificate already exists in the store.
  8590. //
  8591. //  ppStoreContext can be NULL, indicating the caller isn't interested
  8592. //  in getting the CERT_CONTEXT of the added or existing certificate.
  8593. //--------------------------------------------------------------------------
  8594. WINCRYPT32API
  8595. BOOL
  8596. WINAPI
  8597. CertAddCertificateContextToStore(
  8598.     IN HCERTSTORE hCertStore,
  8599.     IN PCCERT_CONTEXT pCertContext,
  8600.     IN DWORD dwAddDisposition,
  8601.     OUT OPTIONAL PCCERT_CONTEXT *ppStoreContext
  8602.     );
  8603.  
  8604.  
  8605. //+-------------------------------------------------------------------------
  8606. //  Certificate Store Context Types
  8607. //--------------------------------------------------------------------------
  8608. #define CERT_STORE_CERTIFICATE_CONTEXT  1
  8609. #define CERT_STORE_CRL_CONTEXT          2
  8610. #define CERT_STORE_CTL_CONTEXT          3
  8611.  
  8612. //+-------------------------------------------------------------------------
  8613. //  Certificate Store Context Bit Flags
  8614. //--------------------------------------------------------------------------
  8615. #define CERT_STORE_ALL_CONTEXT_FLAG             (~0UL)
  8616. #define CERT_STORE_CERTIFICATE_CONTEXT_FLAG     \
  8617.                 (1 << CERT_STORE_CERTIFICATE_CONTEXT)
  8618. #define CERT_STORE_CRL_CONTEXT_FLAG             \
  8619.                 (1 << CERT_STORE_CRL_CONTEXT)
  8620. #define CERT_STORE_CTL_CONTEXT_FLAG             \
  8621.                 (1 << CERT_STORE_CTL_CONTEXT)
  8622.  
  8623. //+-------------------------------------------------------------------------
  8624. //  Add the serialized certificate or CRL element to the store.
  8625. //
  8626. //  The serialized element contains the encoded certificate, CRL or CTL and
  8627. //  its properties, such as, CERT_KEY_PROV_INFO_PROP_ID.
  8628. //
  8629. //  If hCertStore is NULL, creates a certificate, CRL or CTL context not
  8630. //  residing in any store.
  8631. //
  8632. //  dwAddDispostion specifies the action to take if the certificate or CRL
  8633. //  already exists in the store. See CertAddCertificateContextToStore for a
  8634. //  list of and actions taken.
  8635. //
  8636. //  dwFlags currently isn't used and should be set to 0.
  8637. //
  8638. //  dwContextTypeFlags specifies the set of allowable contexts. For example, to
  8639. //  add either a certificate or CRL, set dwContextTypeFlags to:
  8640. //      CERT_STORE_CERTIFICATE_CONTEXT_FLAG | CERT_STORE_CRL_CONTEXT_FLAG
  8641. //
  8642. //  *pdwContextType is updated with the type of the context returned in
  8643. //  *ppvContxt. pdwContextType or ppvContext can be NULL, indicating the
  8644. //  caller isn't interested in getting the output. If *ppvContext is
  8645. //  returned it must be freed by calling CertFreeCertificateContext or
  8646. //  CertFreeCRLContext.
  8647. //--------------------------------------------------------------------------
  8648. WINCRYPT32API
  8649. BOOL
  8650. WINAPI
  8651. CertAddSerializedElementToStore(
  8652.     IN HCERTSTORE hCertStore,
  8653.     IN const BYTE *pbElement,
  8654.     IN DWORD cbElement,
  8655.     IN DWORD dwAddDisposition,
  8656.     IN DWORD dwFlags,
  8657.     IN DWORD dwContextTypeFlags,
  8658.     OUT OPTIONAL DWORD *pdwContextType,
  8659.     OUT OPTIONAL const void **ppvContext
  8660.     );
  8661.  
  8662. //+-------------------------------------------------------------------------
  8663. //  Delete the specified certificate from the store.
  8664. //
  8665. //  All subsequent gets or finds for the certificate will fail. However,
  8666. //  memory allocated for the certificate isn't freed until all of its contexts
  8667. //  have also been freed.
  8668. //
  8669. //  The pCertContext is obtained from a get, enum, find or duplicate.
  8670. //
  8671. //  Some store provider implementations might also delete the issuer's CRLs
  8672. //  if this is the last certificate for the issuer in the store.
  8673. //
  8674. //  NOTE: the pCertContext is always CertFreeCertificateContext'ed by
  8675. //  this function, even for an error.
  8676. //--------------------------------------------------------------------------
  8677. WINCRYPT32API
  8678. BOOL
  8679. WINAPI
  8680. CertDeleteCertificateFromStore(
  8681.     IN PCCERT_CONTEXT pCertContext
  8682.     );
  8683.  
  8684. //+-------------------------------------------------------------------------
  8685. //  Add the encoded CRL to the store according to the specified
  8686. //  disposition option.
  8687. //
  8688. //  Makes a copy of the encoded CRL before adding to the store.
  8689. //
  8690. //  dwAddDispostion specifies the action to take if the CRL
  8691. //  already exists in the store. See CertAddEncodedCertificateToStore for a
  8692. //  list of and actions taken.
  8693. //
  8694. //  Compares the CRL's Issuer to determine if the CRL already exists in the
  8695. //  store.
  8696. //
  8697. //  ppCrlContext can be NULL, indicating the caller isn't interested
  8698. //  in getting the CRL_CONTEXT of the added or existing CRL.
  8699. //--------------------------------------------------------------------------
  8700. WINCRYPT32API
  8701. BOOL
  8702. WINAPI
  8703. CertAddEncodedCRLToStore(
  8704.     IN HCERTSTORE hCertStore,
  8705.     IN DWORD dwCertEncodingType,
  8706.     IN const BYTE *pbCrlEncoded,
  8707.     IN DWORD cbCrlEncoded,
  8708.     IN DWORD dwAddDisposition,
  8709.     OUT OPTIONAL PCCRL_CONTEXT *ppCrlContext
  8710.     );
  8711.  
  8712. //+-------------------------------------------------------------------------
  8713. //  Add the CRL context to the store according to the specified
  8714. //  disposition option.
  8715. //
  8716. //  In addition to the encoded CRL, the context's properties are
  8717. //  also copied.  Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  8718. //  CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't copied.
  8719. //
  8720. //  Makes a copy of the encoded CRL before adding to the store.
  8721. //
  8722. //  dwAddDispostion specifies the action to take if the CRL
  8723. //  already exists in the store. See CertAddCertificateContextToStore for a
  8724. //  list of and actions taken.
  8725. //
  8726. //  Compares the CRL's Issuer, ThisUpdate and NextUpdate to determine
  8727. //  if the CRL already exists in the store.
  8728. //
  8729. //  ppStoreContext can be NULL, indicating the caller isn't interested
  8730. //  in getting the CRL_CONTEXT of the added or existing CRL.
  8731. //--------------------------------------------------------------------------
  8732. WINCRYPT32API
  8733. BOOL
  8734. WINAPI
  8735. CertAddCRLContextToStore(
  8736.     IN HCERTSTORE hCertStore,
  8737.     IN PCCRL_CONTEXT pCrlContext,
  8738.     IN DWORD dwAddDisposition,
  8739.     OUT OPTIONAL PCCRL_CONTEXT *ppStoreContext
  8740.     );
  8741.  
  8742. //+-------------------------------------------------------------------------
  8743. //  Delete the specified CRL from the store.
  8744. //
  8745. //  All subsequent gets for the CRL will fail. However,
  8746. //  memory allocated for the CRL isn't freed until all of its contexts
  8747. //  have also been freed.
  8748. //
  8749. //  The pCrlContext is obtained from a get or duplicate.
  8750. //
  8751. //  NOTE: the pCrlContext is always CertFreeCRLContext'ed by
  8752. //  this function, even for an error.
  8753. //--------------------------------------------------------------------------
  8754. WINCRYPT32API
  8755. BOOL
  8756. WINAPI
  8757. CertDeleteCRLFromStore(
  8758.     IN PCCRL_CONTEXT pCrlContext
  8759.     );
  8760.  
  8761. //+-------------------------------------------------------------------------
  8762. //  Serialize the certificate context's encoded certificate and its
  8763. //  properties.
  8764. //--------------------------------------------------------------------------
  8765. WINCRYPT32API
  8766. BOOL
  8767. WINAPI
  8768. CertSerializeCertificateStoreElement(
  8769.     IN PCCERT_CONTEXT pCertContext,
  8770.     IN DWORD dwFlags,
  8771.     OUT BYTE *pbElement,
  8772.     IN OUT DWORD *pcbElement
  8773.     );
  8774.  
  8775.  
  8776. //+-------------------------------------------------------------------------
  8777. //  Serialize the CRL context's encoded CRL and its properties.
  8778. //--------------------------------------------------------------------------
  8779. WINCRYPT32API
  8780. BOOL
  8781. WINAPI
  8782. CertSerializeCRLStoreElement(
  8783.     IN PCCRL_CONTEXT pCrlContext,
  8784.     IN DWORD dwFlags,
  8785.     OUT BYTE *pbElement,
  8786.     IN OUT DWORD *pcbElement
  8787.     );
  8788.  
  8789.  
  8790.  
  8791. //+=========================================================================
  8792. //  Certificate Trust List (CTL) Store Data Structures and APIs
  8793. //==========================================================================
  8794.  
  8795. //+-------------------------------------------------------------------------
  8796. //  Duplicate a CTL context
  8797. //--------------------------------------------------------------------------
  8798. WINCRYPT32API
  8799. PCCTL_CONTEXT
  8800. WINAPI
  8801. CertDuplicateCTLContext(
  8802.     IN PCCTL_CONTEXT pCtlContext
  8803.     );
  8804.  
  8805. //+-------------------------------------------------------------------------
  8806. //  Create a CTL context from the encoded CTL. The created
  8807. //  context isn't put in a store.
  8808. //
  8809. //  Makes a copy of the encoded CTL in the created context.
  8810. //
  8811. //  If unable to decode and create the CTL context, NULL is returned.
  8812. //  Otherwise, a pointer to a read only CTL_CONTEXT is returned.
  8813. //  CTL_CONTEXT must be freed by calling CertFreeCTLContext.
  8814. //  CertDuplicateCTLContext can be called to make a duplicate.
  8815. //
  8816. //  CertSetCTLContextProperty and CertGetCTLContextProperty can be called
  8817. //  to store properties for the CTL.
  8818. //--------------------------------------------------------------------------
  8819. WINCRYPT32API
  8820. PCCTL_CONTEXT
  8821. WINAPI
  8822. CertCreateCTLContext(
  8823.     IN DWORD dwMsgAndCertEncodingType,
  8824.     IN const BYTE *pbCtlEncoded,
  8825.     IN DWORD cbCtlEncoded
  8826.     );
  8827.  
  8828. //+-------------------------------------------------------------------------
  8829. //  Free a CTL context
  8830. //
  8831. //  There needs to be a corresponding free for each context obtained by a
  8832. //  get, duplicate or create.
  8833. //--------------------------------------------------------------------------
  8834. WINCRYPT32API
  8835. BOOL
  8836. WINAPI
  8837. CertFreeCTLContext(
  8838.     IN PCCTL_CONTEXT pCtlContext
  8839.     );
  8840.  
  8841. //+-------------------------------------------------------------------------
  8842. //  Set the property for the specified CTL context.
  8843. //
  8844. //  Same Property Ids and semantics as CertSetCertificateContextProperty.
  8845. //--------------------------------------------------------------------------
  8846. WINCRYPT32API
  8847. BOOL
  8848. WINAPI
  8849. CertSetCTLContextProperty(
  8850.     IN PCCTL_CONTEXT pCtlContext,
  8851.     IN DWORD dwPropId,
  8852.     IN DWORD dwFlags,
  8853.     IN const void *pvData
  8854.     );
  8855.  
  8856. //+-------------------------------------------------------------------------
  8857. //  Get the property for the specified CTL context.
  8858. //
  8859. //  Same Property Ids and semantics as CertGetCertificateContextProperty.
  8860. //
  8861. //  CERT_SHA1_HASH_PROP_ID or CERT_NEXT_UPDATE_LOCATION_PROP_ID are the
  8862. //  predefined properties of most interest.
  8863. //--------------------------------------------------------------------------
  8864. WINCRYPT32API
  8865. BOOL
  8866. WINAPI
  8867. CertGetCTLContextProperty(
  8868.     IN PCCTL_CONTEXT pCtlContext,
  8869.     IN DWORD dwPropId,
  8870.     OUT void *pvData,
  8871.     IN OUT DWORD *pcbData
  8872.     );
  8873.  
  8874. //+-------------------------------------------------------------------------
  8875. //  Enumerate the properties for the specified CTL context.
  8876. //--------------------------------------------------------------------------
  8877. WINCRYPT32API
  8878. DWORD
  8879. WINAPI
  8880. CertEnumCTLContextProperties(
  8881.     IN PCCTL_CONTEXT pCtlContext,
  8882.     IN DWORD dwPropId
  8883.     );
  8884.  
  8885. //+-------------------------------------------------------------------------
  8886. //  Enumerate the CTL contexts in the store.
  8887. //
  8888. //  If a CTL isn't found, NULL is returned.
  8889. //  Otherwise, a pointer to a read only CTL_CONTEXT is returned. CTL_CONTEXT
  8890. //  must be freed by calling CertFreeCTLContext or is freed when passed as the
  8891. //  pPrevCtlContext on a subsequent call. CertDuplicateCTLContext
  8892. //  can be called to make a duplicate.
  8893. //
  8894. //  pPrevCtlContext MUST BE NULL to enumerate the first
  8895. //  CTL in the store. Successive CTLs are enumerated by setting
  8896. //  pPrevCtlContext to the CTL_CONTEXT returned by a previous call.
  8897. //
  8898. //  NOTE: a NON-NULL pPrevCtlContext is always CertFreeCTLContext'ed by
  8899. //  this function, even for an error.
  8900. //--------------------------------------------------------------------------
  8901. WINCRYPT32API
  8902. PCCTL_CONTEXT
  8903. WINAPI
  8904. CertEnumCTLsInStore(
  8905.     IN HCERTSTORE hCertStore,
  8906.     IN PCCTL_CONTEXT pPrevCtlContext
  8907.     );
  8908.  
  8909. //+-------------------------------------------------------------------------
  8910. //  Attempt to find the specified subject in the CTL.
  8911. //
  8912. //  For CTL_CERT_SUBJECT_TYPE, pvSubject points to a CERT_CONTEXT. The CTL's
  8913. //  SubjectAlgorithm is examined to determine the representation of the
  8914. //  subject's identity. Initially, only SHA1 or MD5 hash will be supported.
  8915. //  The appropriate hash property is obtained from the CERT_CONTEXT.
  8916. //
  8917. //  For CTL_ANY_SUBJECT_TYPE, pvSubject points to the CTL_ANY_SUBJECT_INFO
  8918. //  structure which contains the SubjectAlgorithm to be matched in the CTL
  8919. //  and the SubjectIdentifer to be matched in one of the CTL entries.
  8920. //
  8921. //  The certificate's hash or the CTL_ANY_SUBJECT_INFO's SubjectIdentifier
  8922. //  is used as the key in searching the subject entries. A binary
  8923. //  memory comparison is done between the key and the entry's SubjectIdentifer.
  8924. //
  8925. //  dwEncodingType isn't used for either of the above SubjectTypes.
  8926. //--------------------------------------------------------------------------
  8927. WINCRYPT32API
  8928. PCTL_ENTRY
  8929. WINAPI
  8930. CertFindSubjectInCTL(
  8931.     IN DWORD dwEncodingType,
  8932.     IN DWORD dwSubjectType,
  8933.     IN void *pvSubject,
  8934.     IN PCCTL_CONTEXT pCtlContext,
  8935.     IN DWORD dwFlags
  8936.     );
  8937.  
  8938. // Subject Types:
  8939. //  CTL_ANY_SUBJECT_TYPE, pvSubject points to following CTL_ANY_SUBJECT_INFO.
  8940. //  CTL_CERT_SUBJECT_TYPE, pvSubject points to CERT_CONTEXT.
  8941. #define CTL_ANY_SUBJECT_TYPE            1
  8942. #define CTL_CERT_SUBJECT_TYPE           2
  8943.  
  8944. typedef struct _CTL_ANY_SUBJECT_INFO {
  8945.     CRYPT_ALGORITHM_IDENTIFIER  SubjectAlgorithm;
  8946.     CRYPT_DATA_BLOB             SubjectIdentifier;
  8947. } CTL_ANY_SUBJECT_INFO, *PCTL_ANY_SUBJECT_INFO;
  8948.  
  8949. //+-------------------------------------------------------------------------
  8950. //  Find the first or next CTL context in the store.
  8951. //
  8952. //  The CTL is found according to the dwFindType and its pvFindPara.
  8953. //  See below for a list of the find types and its parameters.
  8954. //
  8955. //  Currently dwFindFlags isn't used and must be set to 0.
  8956. //
  8957. //  Usage of dwMsgAndCertEncodingType depends on the dwFindType.
  8958. //
  8959. //  If the first or next CTL isn't found, NULL is returned.
  8960. //  Otherwise, a pointer to a read only CTL_CONTEXT is returned. CTL_CONTEXT
  8961. //  must be freed by calling CertFreeCTLContext or is freed when passed as the
  8962. //  pPrevCtlContext on a subsequent call. CertDuplicateCTLContext
  8963. //  can be called to make a duplicate.
  8964. //
  8965. //  pPrevCtlContext MUST BE NULL on the first
  8966. //  call to find the CTL. To find the next CTL, the
  8967. //  pPrevCtlContext is set to the CTL_CONTEXT returned by a previous call.
  8968. //
  8969. //  NOTE: a NON-NULL pPrevCtlContext is always CertFreeCTLContext'ed by
  8970. //  this function, even for an error.
  8971. //--------------------------------------------------------------------------
  8972. WINCRYPT32API
  8973. PCCTL_CONTEXT
  8974. WINAPI
  8975. CertFindCTLInStore(
  8976.     IN HCERTSTORE hCertStore,
  8977.     IN DWORD dwMsgAndCertEncodingType,
  8978.     IN DWORD dwFindFlags,
  8979.     IN DWORD dwFindType,
  8980.     IN const void *pvFindPara,
  8981.     IN PCCTL_CONTEXT pPrevCtlContext
  8982.     );
  8983.  
  8984. #define CTL_FIND_ANY                0
  8985. #define CTL_FIND_SHA1_HASH          1
  8986. #define CTL_FIND_MD5_HASH           2
  8987. #define CTL_FIND_USAGE              3
  8988. #define CTL_FIND_SUBJECT            4
  8989. #define CTL_FIND_EXISTING           5
  8990.  
  8991. typedef struct _CTL_FIND_USAGE_PARA {
  8992.     DWORD               cbSize;
  8993.     CTL_USAGE           SubjectUsage;   // optional
  8994.     CRYPT_DATA_BLOB     ListIdentifier; // optional
  8995.     PCERT_INFO          pSigner;        // optional
  8996. } CTL_FIND_USAGE_PARA, *PCTL_FIND_USAGE_PARA;
  8997.  
  8998. #define CTL_FIND_NO_LIST_ID_CBDATA  0xFFFFFFFF
  8999. #define CTL_FIND_NO_SIGNER_PTR      ((PCERT_INFO) -1)
  9000.  
  9001. #define CTL_FIND_SAME_USAGE_FLAG    0x1
  9002.  
  9003.  
  9004. typedef struct _CTL_FIND_SUBJECT_PARA {
  9005.     DWORD                   cbSize;
  9006.     PCTL_FIND_USAGE_PARA    pUsagePara; // optional
  9007.     DWORD                   dwSubjectType;
  9008.     void                    *pvSubject;
  9009. } CTL_FIND_SUBJECT_PARA, *PCTL_FIND_SUBJECT_PARA;
  9010.  
  9011.  
  9012. //+-------------------------------------------------------------------------
  9013. //  CTL_FIND_ANY
  9014. //
  9015. //  Find any CTL.
  9016. //
  9017. //  pvFindPara isn't used.
  9018. //--------------------------------------------------------------------------
  9019.  
  9020. //+-------------------------------------------------------------------------
  9021. //  CTL_FIND_SHA1_HASH
  9022. //  CTL_FIND_MD5_HASH
  9023. //
  9024. //  Find a CTL with the specified hash.
  9025. //
  9026. //  pvFindPara points to a CRYPT_HASH_BLOB.
  9027. //--------------------------------------------------------------------------
  9028.  
  9029. //+-------------------------------------------------------------------------
  9030. //  CTL_FIND_USAGE
  9031. //
  9032. //  Find a CTL having the specified usage identifiers, list identifier or
  9033. //  signer. The CertEncodingType of the signer is obtained from the
  9034. //  dwMsgAndCertEncodingType parameter.
  9035. //
  9036. //  pvFindPara points to a CTL_FIND_USAGE_PARA data structure. The
  9037. //  SubjectUsage.cUsageIdentifer can be 0 to match any usage. The
  9038. //  ListIdentifier.cbData can be 0 to match any list identifier. To only match
  9039. //  CTLs without a ListIdentifier, cbData must be set to
  9040. //  CTL_FIND_NO_LIST_ID_CBDATA. pSigner can be NULL to match any signer. Only
  9041. //  the Issuer and SerialNumber fields of the pSigner's PCERT_INFO are used.
  9042. //  To only match CTLs without a signer, pSigner must be set to
  9043. //  CTL_FIND_NO_SIGNER_PTR.
  9044. //
  9045. //  The CTL_FIND_SAME_USAGE_FLAG can be set in dwFindFlags to
  9046. //  only match CTLs with the same usage identifiers. CTLs having additional
  9047. //  usage identifiers aren't matched. For example, if only "1.2.3" is specified
  9048. //  in CTL_FIND_USAGE_PARA, then, for a match, the CTL must only contain
  9049. //  "1.2.3" and not any additional usage identifers.
  9050. //--------------------------------------------------------------------------
  9051.  
  9052. //+-------------------------------------------------------------------------
  9053. //  CTL_FIND_SUBJECT
  9054. //
  9055. //  Find a CTL having the specified subject. CertFindSubjectInCTL can be
  9056. //  called to get a pointer to the subject's entry in the CTL.  pUsagePara can
  9057. //  optionally be set to enable the above CTL_FIND_USAGE matching.
  9058. //
  9059. //  pvFindPara points to a CTL_FIND_SUBJECT_PARA data structure.
  9060. //--------------------------------------------------------------------------
  9061.  
  9062. //+-------------------------------------------------------------------------
  9063. //  Add the encoded CTL to the store according to the specified
  9064. //  disposition option.
  9065. //
  9066. //  Makes a copy of the encoded CTL before adding to the store.
  9067. //
  9068. //  dwAddDispostion specifies the action to take if the CTL
  9069. //  already exists in the store. See CertAddEncodedCertificateToStore for a
  9070. //  list of and actions taken.
  9071. //
  9072. //  Compares the CTL's SubjectUsage, ListIdentifier and any of its signers
  9073. //  to determine if the CTL already exists in the store.
  9074. //
  9075. //  ppCtlContext can be NULL, indicating the caller isn't interested
  9076. //  in getting the CTL_CONTEXT of the added or existing CTL.
  9077. //--------------------------------------------------------------------------
  9078. WINCRYPT32API
  9079. BOOL
  9080. WINAPI
  9081. CertAddEncodedCTLToStore(
  9082.     IN HCERTSTORE hCertStore,
  9083.     IN DWORD dwMsgAndCertEncodingType,
  9084.     IN const BYTE *pbCtlEncoded,
  9085.     IN DWORD cbCtlEncoded,
  9086.     IN DWORD dwAddDisposition,
  9087.     OUT OPTIONAL PCCTL_CONTEXT *ppCtlContext
  9088.     );
  9089.  
  9090. //+-------------------------------------------------------------------------
  9091. //  Add the CTL context to the store according to the specified
  9092. //  disposition option.
  9093. //
  9094. //  In addition to the encoded CTL, the context's properties are
  9095. //  also copied.  Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  9096. //  CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't copied.
  9097. //
  9098. //  Makes a copy of the encoded CTL before adding to the store.
  9099. //
  9100. //  dwAddDispostion specifies the action to take if the CTL
  9101. //  already exists in the store. See CertAddCertificateContextToStore for a
  9102. //  list of and actions taken.
  9103. //
  9104. //  Compares the CTL's SubjectUsage, ListIdentifier and any of its signers
  9105. //  to determine if the CTL already exists in the store.
  9106. //
  9107. //  ppStoreContext can be NULL, indicating the caller isn't interested
  9108. //  in getting the CTL_CONTEXT of the added or existing CTL.
  9109. //--------------------------------------------------------------------------
  9110. WINCRYPT32API
  9111. BOOL
  9112. WINAPI
  9113. CertAddCTLContextToStore(
  9114.     IN HCERTSTORE hCertStore,
  9115.     IN PCCTL_CONTEXT pCtlContext,
  9116.     IN DWORD dwAddDisposition,
  9117.     OUT OPTIONAL PCCTL_CONTEXT *ppStoreContext
  9118.     );
  9119.  
  9120. //+-------------------------------------------------------------------------
  9121. //  Serialize the CTL context's encoded CTL and its properties.
  9122. //--------------------------------------------------------------------------
  9123. WINCRYPT32API
  9124. BOOL
  9125. WINAPI
  9126. CertSerializeCTLStoreElement(
  9127.     IN PCCTL_CONTEXT pCtlContext,
  9128.     IN DWORD dwFlags,
  9129.     OUT BYTE *pbElement,
  9130.     IN OUT DWORD *pcbElement
  9131.     );
  9132.  
  9133. //+-------------------------------------------------------------------------
  9134. //  Delete the specified CTL from the store.
  9135. //
  9136. //  All subsequent gets for the CTL will fail. However,
  9137. //  memory allocated for the CTL isn't freed until all of its contexts
  9138. //  have also been freed.
  9139. //
  9140. //  The pCtlContext is obtained from a get or duplicate.
  9141. //
  9142. //  NOTE: the pCtlContext is always CertFreeCTLContext'ed by
  9143. //  this function, even for an error.
  9144. //--------------------------------------------------------------------------
  9145. WINCRYPT32API
  9146. BOOL
  9147. WINAPI
  9148. CertDeleteCTLFromStore(
  9149.     IN PCCTL_CONTEXT pCtlContext
  9150.     );
  9151.  
  9152.  
  9153. WINCRYPT32API
  9154. BOOL
  9155. WINAPI
  9156. CertAddCertificateLinkToStore(
  9157.     IN HCERTSTORE hCertStore,
  9158.     IN PCCERT_CONTEXT pCertContext,
  9159.     IN DWORD dwAddDisposition,
  9160.     OUT OPTIONAL PCCERT_CONTEXT *ppStoreContext
  9161.     );
  9162.  
  9163. WINCRYPT32API
  9164. BOOL
  9165. WINAPI
  9166. CertAddCRLLinkToStore(
  9167.     IN HCERTSTORE hCertStore,
  9168.     IN PCCRL_CONTEXT pCrlContext,
  9169.     IN DWORD dwAddDisposition,
  9170.     OUT OPTIONAL PCCRL_CONTEXT *ppStoreContext
  9171.     );
  9172.  
  9173. WINCRYPT32API
  9174. BOOL
  9175. WINAPI
  9176. CertAddCTLLinkToStore(
  9177.     IN HCERTSTORE hCertStore,
  9178.     IN PCCTL_CONTEXT pCtlContext,
  9179.     IN DWORD dwAddDisposition,
  9180.     OUT OPTIONAL PCCTL_CONTEXT *ppStoreContext
  9181.     );
  9182.  
  9183. WINCRYPT32API
  9184. BOOL
  9185. WINAPI
  9186. CertAddStoreToCollection(
  9187.     IN HCERTSTORE hCollectionStore,
  9188.     IN OPTIONAL HCERTSTORE hSiblingStore,
  9189.     IN DWORD dwUpdateFlags,
  9190.     IN DWORD dwPriority
  9191.     );
  9192.  
  9193. WINCRYPT32API
  9194. void
  9195. WINAPI
  9196. CertRemoveStoreFromCollection(
  9197.     IN HCERTSTORE hCollectionStore,
  9198.     IN HCERTSTORE hSiblingStore
  9199.     );
  9200.  
  9201.  
  9202. WINCRYPT32API
  9203. BOOL
  9204. WINAPI
  9205. CertControlStore(
  9206.     IN HCERTSTORE hCertStore,
  9207.     IN DWORD dwFlags,
  9208.     IN DWORD dwCtrlType,
  9209.     IN void const *pvCtrlPara
  9210.     );
  9211.  
  9212. //+-------------------------------------------------------------------------
  9213. //  Certificate Store control types
  9214. //--------------------------------------------------------------------------
  9215. #define CERT_STORE_CTRL_RESYNC              1
  9216. #define CERT_STORE_CTRL_NOTIFY_CHANGE       2
  9217. #define CERT_STORE_CTRL_COMMIT              3
  9218. #define CERT_STORE_CTRL_AUTO_RESYNC         4
  9219.  
  9220.  
  9221. //+-------------------------------------------------------------------------
  9222. //  CERT_STORE_CTRL_RESYNC
  9223. //
  9224. //  Re-synchronize the store.
  9225. //
  9226. //  The pvCtrlPara points to the event HANDLE to be signaled on
  9227. //  the next store change. Normally, this would be the same
  9228. //  event HANDLE passed to CERT_STORE_CTRL_NOTIFY_CHANGE during initialization.
  9229. //
  9230. //  If pvCtrlPara is NULL, no events are re-armed.
  9231. //--------------------------------------------------------------------------
  9232.  
  9233. //+-------------------------------------------------------------------------
  9234. //  CERT_STORE_CTRL_NOTIFY_CHANGE
  9235. //
  9236. //  Signal the event when the underlying store is changed.
  9237. //
  9238. //  pvCtrlPara points to the event HANDLE to be signaled.
  9239. //
  9240. //  pvCtrlPara can be NULL to inform the store of a subsequent
  9241. //  CERT_STORE_CTRL_RESYNC and allow it to optimize by only doing a resync
  9242. //  if the store has changed. For the registry based stores, an internal
  9243. //  notify change event is created and registered to be signaled.
  9244. //
  9245. //  Recommend calling CERT_STORE_CTRL_NOTIFY_CHANGE once for each event to
  9246. //  be passed to CERT_STORE_CTRL_RESYNC. This should only happen after
  9247. //  the event has been created. Not after each time the event is signaled.
  9248. //--------------------------------------------------------------------------
  9249.  
  9250. //+-------------------------------------------------------------------------
  9251. //  CERT_STORE_CTRL_AUTO_RESYNC
  9252. //
  9253. //  At the start of every enumeration or find store API call, check if the
  9254. //  underlying store has changed. If it has changed, re-synchronize.
  9255. //
  9256. //  This check is only done in the enumeration or find APIs when the
  9257. //  pPrevContext is NULL.
  9258. //
  9259. //  The pvCtrlPara isn't used and must be set to NULL.
  9260. //--------------------------------------------------------------------------
  9261.  
  9262. //+-------------------------------------------------------------------------
  9263. //  CERT_STORE_CTRL_COMMIT
  9264. //
  9265. //  If any changes have been to the cached store, they are committed to
  9266. //  persisted storage. If no changes have been made since the store was
  9267. //  opened or the last commit, this call is ignored. May also be ignored by
  9268. //  store providers that persist changes immediately.
  9269. //
  9270. //  CERT_STORE_CTRL_COMMIT_FORCE_FLAG can be set to force the store
  9271. //  to be committed even if it hasn't been touched.
  9272. //
  9273. //  CERT_STORE_CTRL_COMMIT_CLEAR_FLAG can be set to inhibit a commit on
  9274. //  store close.
  9275. //--------------------------------------------------------------------------
  9276.  
  9277. #define CERT_STORE_CTRL_COMMIT_FORCE_FLAG   0x1
  9278. #define CERT_STORE_CTRL_COMMIT_CLEAR_FLAG   0x2
  9279.  
  9280.  
  9281. //+=========================================================================
  9282. //  Cert Store Property Defines and APIs
  9283. //==========================================================================
  9284.  
  9285. //+-------------------------------------------------------------------------
  9286. //  Store property IDs. This is a property applicable to the entire store.
  9287. //  Its not a property on an individual certificate, CRL or CTL context.
  9288. //
  9289. //  Currently, no store properties are persisted. (This differs from
  9290. //  most context properties which are persisted.)
  9291. //
  9292. //  See CertSetStoreProperty or CertGetStoreProperty for usage information.
  9293. //
  9294. //  Note, the range for predefined store properties should be outside
  9295. //  the range of predefined context properties. We will start at 4096.
  9296. //--------------------------------------------------------------------------
  9297. #define CERT_STORE_LOCALIZED_NAME_PROP_ID   0x1000
  9298.  
  9299. //+-------------------------------------------------------------------------
  9300. //  Set a store property.
  9301. //
  9302. //  The type definition for pvData depends on the dwPropId value.
  9303. //      CERT_STORE_LOCALIZED_NAME_PROP_ID - localized name of the store.
  9304. //      pvData points to a CRYPT_DATA_BLOB. pbData is a pointer to a NULL
  9305. //      terminated unicode, wide character string.
  9306. //      cbData = (wcslen((LPWSTR) pbData) + 1) * sizeof(WCHAR).
  9307. //
  9308. //  For all the other PROP_IDs: an encoded PCRYPT_DATA_BLOB is passed in pvData.
  9309. //
  9310. //  If the property already exists, then, the old value is deleted and silently
  9311. //  replaced. Setting, pvData to NULL, deletes the property.
  9312. //--------------------------------------------------------------------------
  9313. WINCRYPT32API
  9314. BOOL
  9315. WINAPI
  9316. CertSetStoreProperty(
  9317.     IN HCERTSTORE hCertStore,
  9318.     IN DWORD dwPropId,
  9319.     IN DWORD dwFlags,
  9320.     IN const void *pvData
  9321.     );
  9322.  
  9323. //+-------------------------------------------------------------------------
  9324. //  Get a store property.
  9325. //
  9326. //  The type definition for pvData depends on the dwPropId value.
  9327. //      CERT_STORE_LOCALIZED_NAME_PROP_ID - localized name of the store.
  9328. //      pvData points to a NULL terminated unicode, wide character string.
  9329. //      cbData = (wcslen((LPWSTR) pvData) + 1) * sizeof(WCHAR).
  9330. //
  9331. //  For all other PROP_IDs, pvData points to an array of bytes.
  9332. //
  9333. //  If the property doesn't exist, returns FALSE and sets LastError to
  9334. //  CRYPT_E_NOT_FOUND.
  9335. //--------------------------------------------------------------------------
  9336. WINCRYPT32API
  9337. BOOL
  9338. WINAPI
  9339. CertGetStoreProperty(
  9340.     IN HCERTSTORE hCertStore,
  9341.     IN DWORD dwPropId,
  9342.     OUT void *pvData,
  9343.     IN OUT DWORD *pcbData
  9344.     );
  9345.  
  9346.  
  9347. typedef struct _CERT_CREATE_CONTEXT_PARA {
  9348.     DWORD                   cbSize;
  9349.     PFN_CRYPT_FREE          pfnFree;            // OPTIONAL
  9350.     void                    *pvFree;            // OPTIONAL
  9351. } CERT_CREATE_CONTEXT_PARA, *PCERT_CREATE_CONTEXT_PARA;
  9352.  
  9353. //+-------------------------------------------------------------------------
  9354. //  Creates the specified context from the encoded bytes. The created
  9355. //  context isn't put in a store.
  9356. //
  9357. //  dwContextType values:
  9358. //      CERT_STORE_CERTIFICATE_CONTEXT
  9359. //      CERT_STORE_CRL_CONTEXT
  9360. //      CERT_STORE_CTL_CONTEXT
  9361. //
  9362. //  If CERT_CREATE_CONTEXT_NOCOPY_FLAG is set, the created context points
  9363. //  directly to the pbEncoded instead of an allocated copy. See flag
  9364. //  definition for more details.
  9365. //
  9366. //  If CERT_CREATE_CONTEXT_SORTED_FLAG is set, the context is created
  9367. //  with sorted entries. This flag may only be set for CERT_STORE_CTL_CONTEXT.
  9368. //  Setting this flag implicitly sets CERT_CREATE_CONTEXT_NO_HCRYPTMSG_FLAG and
  9369. //  CERT_CREATE_CONTEXT_NO_ENTRY_FLAG. See flag definition for
  9370. //  more details.
  9371. //
  9372. //  If CERT_CREATE_CONTEXT_NO_HCRYPTMSG_FLAG is set, the context is created
  9373. //  without creating a HCRYPTMSG handle for the context. This flag may only be
  9374. //  set for CERT_STORE_CTL_CONTEXT.  See flag definition for more details.
  9375. //
  9376. //  If CERT_CREATE_CONTEXT_NO_ENTRY_FLAG is set, the context is created
  9377. //  without decoding the entries. This flag may only be set for
  9378. //  CERT_STORE_CTL_CONTEXT.  See flag definition for more details.
  9379. //
  9380. //  If unable to decode and create the context, NULL is returned.
  9381. //  Otherwise, a pointer to a read only CERT_CONTEXT, CRL_CONTEXT or
  9382. //  CTL_CONTEXT is returned. The context must be freed by the appropriate
  9383. //  free context API. The context can be duplicated by calling the
  9384. //  appropriate duplicate context API.
  9385. //--------------------------------------------------------------------------
  9386. WINCRYPT32API
  9387. const void *
  9388. WINAPI
  9389. CertCreateContext(
  9390.     IN DWORD dwContextType,
  9391.     IN DWORD dwEncodingType,
  9392.     IN const BYTE *pbEncoded,
  9393.     IN DWORD cbEncoded,
  9394.     IN DWORD dwFlags,
  9395.     IN OPTIONAL PCERT_CREATE_CONTEXT_PARA pCreatePara
  9396.     );
  9397.  
  9398. // When the following flag is set, the created context points directly to the
  9399. // pbEncoded instead of an allocated copy. If pCreatePara and
  9400. // pCreatePara->pfnFree are non-NULL, then, pfnFree is called to free
  9401. // the pbEncoded when the context is last freed. Otherwise, no attempt is
  9402. // made to free the pbEncoded. If pCreatePara->pvFree is non-NULL, then its
  9403. // passed to pfnFree instead of pbEncoded.
  9404. //
  9405. // Note, if CertCreateContext fails, pfnFree is still called.
  9406. #define CERT_CREATE_CONTEXT_NOCOPY_FLAG     0x1
  9407.  
  9408. // When the following flag is set, a context with sorted entries is created.
  9409. // Currently only applicable to a CTL context.
  9410. //
  9411. // For CTLs: the cCTLEntry in the returned CTL_INFO is always
  9412. // 0. CertFindSubjectInSortedCTL and CertEnumSubjectInSortedCTL must be called
  9413. // to find or enumerate the CTL entries.
  9414. //
  9415. // The Sorted CTL TrustedSubjects extension isn't returned in the created
  9416. // context's CTL_INFO.
  9417. #define CERT_CREATE_CONTEXT_SORTED_FLAG     0x2
  9418.  
  9419. // By default when a CTL context is created, a HCRYPTMSG handle to its
  9420. // SignedData message is created. This flag can be set to improve performance
  9421. // by not creating the HCRYPTMSG handle.
  9422. //
  9423. // This flag is only applicable to a CTL context.
  9424. #define CERT_CREATE_CONTEXT_NO_HCRYPTMSG_FLAG   0x4
  9425.  
  9426. // By default when a CTL context is created, its entries are decoded.
  9427. // This flag can be set to improve performance by not decoding the
  9428. // entries.
  9429. //
  9430. // This flag is only applicable to a CTL context.
  9431. #define CERT_CREATE_CONTEXT_NO_ENTRY_FLAG       0x8
  9432.  
  9433.  
  9434. //+=========================================================================
  9435. //  Certificate System Store Data Structures and APIs
  9436. //==========================================================================
  9437.  
  9438. //+-------------------------------------------------------------------------
  9439. //  System Store Information
  9440. //
  9441. //  Currently, no system store information is persisted.
  9442. //--------------------------------------------------------------------------
  9443. typedef struct _CERT_SYSTEM_STORE_INFO {
  9444.     DWORD   cbSize;
  9445. } CERT_SYSTEM_STORE_INFO, *PCERT_SYSTEM_STORE_INFO;
  9446.  
  9447. //+-------------------------------------------------------------------------
  9448. //  Physical Store Information
  9449. //
  9450. //  The Open fields are passed directly to CertOpenStore() to open
  9451. //  the physical store.
  9452. //
  9453. //  By default all system stores located in the registry have an
  9454. //  implicit SystemRegistry physical store that is opened. To disable the
  9455. //  opening of this store, the SystemRegistry
  9456. //  physical store corresponding to the System store must be registered with
  9457. //  CERT_PHYSICAL_STORE_OPEN_DISABLE_FLAG set in dwFlags. Alternatively,
  9458. //  a physical store with the name of ".Default" may be registered.
  9459. //
  9460. //  Depending on the store location and store name, additional predefined
  9461. //  physical stores may be opened. For example, system stores in
  9462. //  CURRENT_USER have the predefined physical store, .LocalMachine.
  9463. //  To disable the opening of these predefined physical stores, the
  9464. //  corresponding physical store must be registered with
  9465. //  CERT_PHYSICAL_STORE_OPEN_DISABLE_FLAG set in dwFlags.
  9466. //
  9467. //  The CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG must be set in dwFlags
  9468. //  to enable the adding of a context to the store.
  9469. //
  9470. //  When a system store is opened via the SERVICES or USERS store location,
  9471. //  the ServiceName\ is prepended to the OpenParameters
  9472. //  for CERT_SYSTEM_STORE_CURRENT_USER or CERT_SYSTEM_STORE_CURRENT_SERVICE
  9473. //  physical stores and the dwOpenFlags store location is changed to
  9474. //  CERT_SYSTEM_STORE_USERS or CERT_SYSTEM_STORE_SERVICES.
  9475. //
  9476. //  By default the SYSTEM, SYSTEM_REGISTRY and PHYSICAL provider
  9477. //  stores are also opened remotely when the outer system store is opened.
  9478. //  The CERT_PHYSICAL_STORE_REMOTE_OPEN_DISABLE_FLAG may be set in dwFlags
  9479. //  to disable remote opens.
  9480. //
  9481. //  When opened remotely, the \\ComputerName is implicitly prepended to the
  9482. //  OpenParameters for the SYSTEM, SYSTEM_REGISTRY and PHYSICAL provider types.
  9483. //  To also prepend the \\ComputerName to other provider types, set the
  9484. //  CERT_PHYSICAL_STORE_INSERT_COMPUTER_NAME_ENABLE_FLAG in dwFlags.
  9485. //
  9486. //  When the system store is opened, its physical stores are ordered
  9487. //  according to the dwPriority. A larger dwPriority indicates higher priority.
  9488. //--------------------------------------------------------------------------
  9489. typedef struct _CERT_PHYSICAL_STORE_INFO {
  9490.     DWORD               cbSize;
  9491.     LPSTR               pszOpenStoreProvider;   // REG_SZ
  9492.     DWORD               dwOpenEncodingType;     // REG_DWORD
  9493.     DWORD               dwOpenFlags;            // REG_DWORD
  9494.     CRYPT_DATA_BLOB     OpenParameters;         // REG_BINARY
  9495.     DWORD               dwFlags;                // REG_DWORD
  9496.     DWORD               dwPriority;             // REG_DWORD
  9497. } CERT_PHYSICAL_STORE_INFO, *PCERT_PHYSICAL_STORE_INFO;
  9498.  
  9499. //+-------------------------------------------------------------------------
  9500. //  Physical Store Information dwFlags
  9501. //--------------------------------------------------------------------------
  9502. #define CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG                     0x1
  9503. #define CERT_PHYSICAL_STORE_OPEN_DISABLE_FLAG                   0x2
  9504. #define CERT_PHYSICAL_STORE_REMOTE_OPEN_DISABLE_FLAG            0x4
  9505. #define CERT_PHYSICAL_STORE_INSERT_COMPUTER_NAME_ENABLE_FLAG    0x8
  9506.  
  9507.  
  9508. //+-------------------------------------------------------------------------
  9509. //  Register a system store.
  9510. //
  9511. //  The upper word of the dwFlags parameter is used to specify the location of
  9512. //  the system store.
  9513. //
  9514. //  If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvSystemStore
  9515. //  points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure. Otherwise,
  9516. //  pvSystemStore points to a null terminated UNICODE string.
  9517. //
  9518. //  The CERT_SYSTEM_STORE_SERVICES or CERT_SYSTEM_STORE_USERS system store
  9519. //  name must be prefixed with the ServiceName or UserName. For example,
  9520. //  "ServiceName\Trust".
  9521. //
  9522. //  Stores on remote computers can be registered for the
  9523. //  CERT_SYSTEM_STORE_LOCAL_MACHINE, CERT_SYSTEM_STORE_SERVICES,
  9524. //  CERT_SYSTEM_STORE_USERS, CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY
  9525. //  or CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE
  9526. //  locations by prepending the computer name. For example, a remote
  9527. //  local machine store is registered via "\\ComputerName\Trust" or
  9528. //  "ComputerName\Trust". A remote service store is registered via
  9529. //  "\\ComputerName\ServiceName\Trust". The leading "\\" backslashes are
  9530. //  optional in the ComputerName.
  9531. //
  9532. //  Set CERT_STORE_CREATE_NEW_FLAG to cause a failure if the system store
  9533. //  already exists in the store location.
  9534. //--------------------------------------------------------------------------
  9535. WINCRYPT32API
  9536. BOOL
  9537. WINAPI
  9538. CertRegisterSystemStore(
  9539.     IN const void *pvSystemStore,
  9540.     IN DWORD dwFlags,
  9541.     IN PCERT_SYSTEM_STORE_INFO pStoreInfo,
  9542.     IN OPTIONAL void *pvReserved
  9543.     );
  9544.  
  9545. //+-------------------------------------------------------------------------
  9546. //  Register a physical store for the specified system store.
  9547. //
  9548. //  The upper word of the dwFlags parameter is used to specify the location of
  9549. //  the system store.
  9550. //
  9551. //  If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvSystemStore
  9552. //  points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure. Otherwise,
  9553. //  pvSystemStore points to a null terminated UNICODE string.
  9554. //
  9555. //  See CertRegisterSystemStore for details on prepending a ServiceName
  9556. //  and/or ComputerName to the system store name.
  9557. //
  9558. //  Set CERT_STORE_CREATE_NEW_FLAG to cause a failure if the physical store
  9559. //  already exists in the system store.
  9560. //--------------------------------------------------------------------------
  9561. WINCRYPT32API
  9562. BOOL
  9563. WINAPI
  9564. CertRegisterPhysicalStore(
  9565.     IN const void *pvSystemStore,
  9566.     IN DWORD dwFlags,
  9567.     IN LPCWSTR pwszStoreName,
  9568.     IN PCERT_PHYSICAL_STORE_INFO pStoreInfo,
  9569.     IN OPTIONAL void *pvReserved
  9570.     );
  9571.  
  9572. //+-------------------------------------------------------------------------
  9573. //  Unregister the specified system store.
  9574. //
  9575. //  The upper word of the dwFlags parameter is used to specify the location of
  9576. //  the system store.
  9577. //
  9578. //  If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvSystemStore
  9579. //  points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure. Otherwise,
  9580. //  pvSystemStore points to a null terminated UNICODE string.
  9581. //
  9582. //  See CertRegisterSystemStore for details on prepending a ServiceName
  9583. //  and/or ComputerName to the system store name.
  9584. //
  9585. //  CERT_STORE_DELETE_FLAG can optionally be set in dwFlags.
  9586. //--------------------------------------------------------------------------
  9587. WINCRYPT32API
  9588. BOOL
  9589. WINAPI
  9590. CertUnregisterSystemStore(
  9591.     IN const void *pvSystemStore,
  9592.     IN DWORD dwFlags
  9593.     );
  9594.  
  9595. //+-------------------------------------------------------------------------
  9596. //  Unregister the physical store from the specified system store.
  9597. //
  9598. //  The upper word of the dwFlags parameter is used to specify the location of
  9599. //  the system store.
  9600. //
  9601. //  If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvSystemStore
  9602. //  points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure. Otherwise,
  9603. //  pvSystemStore points to a null terminated UNICODE string.
  9604. //
  9605. //  See CertRegisterSystemStore for details on prepending a ServiceName
  9606. //  and/or ComputerName to the system store name.
  9607. //
  9608. //  CERT_STORE_DELETE_FLAG can optionally be set in dwFlags.
  9609. //--------------------------------------------------------------------------
  9610. WINCRYPT32API
  9611. BOOL
  9612. WINAPI
  9613. CertUnregisterPhysicalStore(
  9614.     IN const void *pvSystemStore,
  9615.     IN DWORD dwFlags,
  9616.     IN LPCWSTR pwszStoreName
  9617.     );
  9618.  
  9619. //+-------------------------------------------------------------------------
  9620. //  Enum callbacks
  9621. //
  9622. //  The CERT_SYSTEM_STORE_LOCATION_MASK bits in the dwFlags parameter
  9623. //  specifies the location of the system store
  9624. //
  9625. //  If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvSystemStore
  9626. //  points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure. Otherwise,
  9627. //  pvSystemStore points to a null terminated UNICODE string.
  9628. //
  9629. //  The callback returns FALSE and sets LAST_ERROR to stop the enumeration.
  9630. //  The LAST_ERROR is returned to the caller of the enumeration.
  9631. //
  9632. //  The pvSystemStore passed to the callback has leading ComputerName and/or
  9633. //  ServiceName prefixes where appropriate.
  9634. //--------------------------------------------------------------------------
  9635.  
  9636. typedef BOOL (WINAPI *PFN_CERT_ENUM_SYSTEM_STORE_LOCATION)(
  9637.     IN LPCWSTR pwszStoreLocation,
  9638.     IN DWORD dwFlags,
  9639.     IN OPTIONAL void *pvReserved,
  9640.     IN OPTIONAL void *pvArg
  9641.     );
  9642.  
  9643. typedef BOOL (WINAPI *PFN_CERT_ENUM_SYSTEM_STORE)(
  9644.     IN const void *pvSystemStore,
  9645.     IN DWORD dwFlags,
  9646.     IN PCERT_SYSTEM_STORE_INFO pStoreInfo,
  9647.     IN OPTIONAL void *pvReserved,
  9648.     IN OPTIONAL void *pvArg
  9649.     );
  9650.  
  9651. typedef BOOL (WINAPI *PFN_CERT_ENUM_PHYSICAL_STORE)(
  9652.     IN const void *pvSystemStore,
  9653.     IN DWORD dwFlags,
  9654.     IN LPCWSTR pwszStoreName,
  9655.     IN PCERT_PHYSICAL_STORE_INFO pStoreInfo,
  9656.     IN OPTIONAL void *pvReserved,
  9657.     IN OPTIONAL void *pvArg
  9658.     );
  9659.  
  9660. // In the PFN_CERT_ENUM_PHYSICAL_STORE callback the following flag is
  9661. // set if the physical store wasn't registered and is an implicitly created
  9662. // predefined physical store.
  9663. #define CERT_PHYSICAL_STORE_PREDEFINED_ENUM_FLAG    0x1
  9664.  
  9665. // Names of implicitly created predefined physical stores
  9666. #define CERT_PHYSICAL_STORE_DEFAULT_NAME            L".Default"
  9667. #define CERT_PHYSICAL_STORE_GROUP_POLICY_NAME       L".GroupPolicy"
  9668. #define CERT_PHYSICAL_STORE_LOCAL_MACHINE_NAME      L".LocalMachine"
  9669. #define CERT_PHYSICAL_STORE_DS_USER_CERTIFICATE_NAME L".UserCertificate"
  9670. #define CERT_PHYSICAL_STORE_LOCAL_MACHINE_GROUP_POLICY_NAME \
  9671.             L".LocalMachineGroupPolicy"
  9672. #define CERT_PHYSICAL_STORE_ENTERPRISE_NAME         L".Enterprise"
  9673.  
  9674. //+-------------------------------------------------------------------------
  9675. //  Enumerate the system store locations.
  9676. //--------------------------------------------------------------------------
  9677. WINCRYPT32API
  9678. BOOL
  9679. WINAPI
  9680. CertEnumSystemStoreLocation(
  9681.     IN DWORD dwFlags,
  9682.     IN void *pvArg,
  9683.     IN PFN_CERT_ENUM_SYSTEM_STORE_LOCATION pfnEnum
  9684.     );
  9685.  
  9686. //+-------------------------------------------------------------------------
  9687. //  Enumerate the system stores.
  9688. //
  9689. //  The upper word of the dwFlags parameter is used to specify the location of
  9690. //  the system store.
  9691. //
  9692. //  If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags,
  9693. //  pvSystemStoreLocationPara points to a CERT_SYSTEM_STORE_RELOCATE_PARA
  9694. //  data structure. Otherwise, pvSystemStoreLocationPara points to a null
  9695. //  terminated UNICODE string.
  9696. //
  9697. //  For CERT_SYSTEM_STORE_LOCAL_MACHINE,
  9698. //  CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY or
  9699. //  CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE, pvSystemStoreLocationPara can
  9700. //  optionally be set to a unicode computer name for enumerating local machine
  9701. //  stores on a remote computer. For example, "\\ComputerName" or
  9702. //  "ComputerName".  The leading "\\" backslashes are optional in the
  9703. //  ComputerName.
  9704. //
  9705. //  For CERT_SYSTEM_STORE_SERVICES or CERT_SYSTEM_STORE_USERS,
  9706. //  if pvSystemStoreLocationPara is NULL, then,
  9707. //  enumerates both the service/user names and the stores for each service/user
  9708. //  name. Otherwise, pvSystemStoreLocationPara is a unicode string specifying a
  9709. //  remote computer name and/or service/user name. For example:
  9710. //      "ServiceName"
  9711. //      "\\ComputerName" or "ComputerName\"
  9712. //      "ComputerName\ServiceName"
  9713. //  Note, if only the ComputerName is specified, then, it must have either
  9714. //  the leading "\\" backslashes or a trailing backslash. Otherwise, its
  9715. //  interpretted as the ServiceName or UserName.
  9716. //--------------------------------------------------------------------------
  9717. WINCRYPT32API
  9718. BOOL
  9719. WINAPI
  9720. CertEnumSystemStore(
  9721.     IN DWORD dwFlags,
  9722.     IN OPTIONAL void *pvSystemStoreLocationPara,
  9723.     IN void *pvArg,
  9724.     IN PFN_CERT_ENUM_SYSTEM_STORE pfnEnum
  9725.     );
  9726.  
  9727. //+-------------------------------------------------------------------------
  9728. //  Enumerate the physical stores for the specified system store.
  9729. //
  9730. //  The upper word of the dwFlags parameter is used to specify the location of
  9731. //  the system store.
  9732. //
  9733. //  If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvSystemStore
  9734. //  points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure. Otherwise,
  9735. //  pvSystemStore points to a null terminated UNICODE string.
  9736. //
  9737. //  See CertRegisterSystemStore for details on prepending a ServiceName
  9738. //  and/or ComputerName to the system store name.
  9739. //
  9740. //  If the system store location only supports system stores and doesn't
  9741. //  support physical stores, LastError is set to ERROR_CALL_NOT_IMPLEMENTED.
  9742. //--------------------------------------------------------------------------
  9743. WINCRYPT32API
  9744. BOOL
  9745. WINAPI
  9746. CertEnumPhysicalStore(
  9747.     IN const void *pvSystemStore,
  9748.     IN DWORD dwFlags,
  9749.     IN void *pvArg,
  9750.     IN PFN_CERT_ENUM_PHYSICAL_STORE pfnEnum
  9751.     );
  9752.  
  9753.  
  9754. //+-------------------------------------------------------------------------
  9755. //  Certificate System Store Installable Functions
  9756. //
  9757. //  The CERT_SYSTEM_STORE_LOCATION_MASK bits in the dwFlags parameter passed
  9758. //  to the CertOpenStore(for "System", "SystemRegistry" or "Physical"
  9759. //  Provider), CertRegisterSystemStore,
  9760. //  CertUnregisterSystemStore, CertEnumSystemStore, CertRegisterPhysicalStore,
  9761. //  CertUnregisterPhysicalStore and CertEnumPhysicalStore APIs is used as the
  9762. //  constant pszOID value passed to the OID installable functions.
  9763. //  Therefore, the pszOID is restricted to a constant <= (LPCSTR) 0x0FFF.
  9764. //
  9765. //  The EncodingType is 0.
  9766. //--------------------------------------------------------------------------
  9767.  
  9768. // Installable System Store Provider OID pszFuncNames.
  9769. #define CRYPT_OID_OPEN_SYSTEM_STORE_PROV_FUNC   "CertDllOpenSystemStoreProv"
  9770. #define CRYPT_OID_REGISTER_SYSTEM_STORE_FUNC    "CertDllRegisterSystemStore"
  9771. #define CRYPT_OID_UNREGISTER_SYSTEM_STORE_FUNC  "CertDllUnregisterSystemStore"
  9772. #define CRYPT_OID_ENUM_SYSTEM_STORE_FUNC        "CertDllEnumSystemStore"
  9773. #define CRYPT_OID_REGISTER_PHYSICAL_STORE_FUNC  "CertDllRegisterPhysicalStore"
  9774. #define CRYPT_OID_UNREGISTER_PHYSICAL_STORE_FUNC "CertDllUnregisterPhysicalStore"
  9775. #define CRYPT_OID_ENUM_PHYSICAL_STORE_FUNC      "CertDllEnumPhysicalStore"
  9776.  
  9777. // CertDllOpenSystemStoreProv has the same function signature as the
  9778. // installable "CertDllOpenStoreProv" function. See CertOpenStore for
  9779. // more details.
  9780.  
  9781. // CertDllRegisterSystemStore has the same function signature as
  9782. // CertRegisterSystemStore.
  9783. //
  9784. // The "SystemStoreLocation" REG_SZ value must also be set for registered
  9785. // CertDllEnumSystemStore OID functions.
  9786. #define CRYPT_OID_SYSTEM_STORE_LOCATION_VALUE_NAME  L"SystemStoreLocation"
  9787.  
  9788. // The remaining Register, Enum and Unregister OID installable functions
  9789. // have the same signature as their Cert Store API counterpart.
  9790.  
  9791.  
  9792. //+=========================================================================
  9793. //  Enhanced Key Usage Helper Functions
  9794. //==========================================================================
  9795.  
  9796. //+-------------------------------------------------------------------------
  9797. //  Get the enhanced key usage extension or property from the certificate
  9798. //  and decode.
  9799. //
  9800. //  If the CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG is set, then, only get the
  9801. //  extension.
  9802. //
  9803. //  If the CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG is set, then, only get the
  9804. //  property.
  9805. //--------------------------------------------------------------------------
  9806. WINCRYPT32API
  9807. BOOL
  9808. WINAPI
  9809. CertGetEnhancedKeyUsage(
  9810.     IN PCCERT_CONTEXT pCertContext,
  9811.     IN DWORD dwFlags,
  9812.     OUT PCERT_ENHKEY_USAGE pUsage,
  9813.     IN OUT DWORD *pcbUsage
  9814.     );
  9815.  
  9816. //+-------------------------------------------------------------------------
  9817. //  Set the enhanced key usage property for the certificate.
  9818. //--------------------------------------------------------------------------
  9819. WINCRYPT32API
  9820. BOOL
  9821. WINAPI
  9822. CertSetEnhancedKeyUsage(
  9823.     IN PCCERT_CONTEXT pCertContext,
  9824.     IN PCERT_ENHKEY_USAGE pUsage
  9825.     );
  9826.  
  9827. //+-------------------------------------------------------------------------
  9828. //  Add the usage identifier to the certificate's enhanced key usage property.
  9829. //--------------------------------------------------------------------------
  9830. WINCRYPT32API
  9831. BOOL
  9832. WINAPI
  9833. CertAddEnhancedKeyUsageIdentifier(
  9834.     IN PCCERT_CONTEXT pCertContext,
  9835.     IN LPCSTR pszUsageIdentifier
  9836.     );
  9837.  
  9838.  
  9839. //+-------------------------------------------------------------------------
  9840. //  Remove the usage identifier from the certificate's enhanced key usage
  9841. //  property.
  9842. //--------------------------------------------------------------------------
  9843. WINCRYPT32API
  9844. BOOL
  9845. WINAPI
  9846. CertRemoveEnhancedKeyUsageIdentifier(
  9847.     IN PCCERT_CONTEXT pCertContext,
  9848.     IN LPCSTR pszUsageIdentifier
  9849.     );
  9850.  
  9851. //+---------------------------------------------------------------------------
  9852. //
  9853. //
  9854. //  Takes an array of certs and returns an array of usages
  9855. //  which consists of the intersection of the valid usages for each cert.
  9856. //  If each cert is good for all possible usages then the cNumOIDs is set to -1.
  9857. //
  9858. //----------------------------------------------------------------------------
  9859. WINCRYPT32API
  9860. BOOL
  9861. WINAPI
  9862. CertGetValidUsages(
  9863.     IN      DWORD           cCerts,
  9864.     IN      PCCERT_CONTEXT  *rghCerts,
  9865.     OUT     int             *cNumOIDs,
  9866.     OUT     LPSTR           *rghOIDs,
  9867.     IN OUT  DWORD           *pcbOIDs);
  9868.  
  9869. //+=========================================================================
  9870. //  Cryptographic Message helper functions for verifying and signing a
  9871. //  CTL.
  9872. //==========================================================================
  9873.  
  9874. //+-------------------------------------------------------------------------
  9875. //  Get and verify the signer of a cryptographic message.
  9876. //
  9877. //  To verify a CTL, the hCryptMsg is obtained from the CTL_CONTEXT's
  9878. //  hCryptMsg field.
  9879. //
  9880. //  If CMSG_TRUSTED_SIGNER_FLAG is set, then, treat the Signer stores as being
  9881. //  trusted and only search them to find the certificate corresponding to the
  9882. //  signer's issuer and serial number.  Otherwise, the SignerStores are
  9883. //  optionally provided to supplement the message's store of certificates.
  9884. //  If a signer certificate is found, its public key is used to verify
  9885. //  the message signature. The CMSG_SIGNER_ONLY_FLAG can be set to
  9886. //  return the signer without doing the signature verify.
  9887. //
  9888. //  If CMSG_USE_SIGNER_INDEX_FLAG is set, then, only get the signer specified
  9889. //  by *pdwSignerIndex. Otherwise, iterate through all the signers
  9890. //  until a signer verifies or no more signers.
  9891. //
  9892. //  For a verified signature, *ppSigner is updated with certificate context
  9893. //  of the signer and *pdwSignerIndex is updated with the index of the signer.
  9894. //  ppSigner and/or pdwSignerIndex can be NULL, indicating the caller isn't
  9895. //  interested in getting the CertContext and/or index of the signer.
  9896. //--------------------------------------------------------------------------
  9897. WINCRYPT32API
  9898. BOOL
  9899. WINAPI
  9900. CryptMsgGetAndVerifySigner(
  9901.     IN HCRYPTMSG hCryptMsg,
  9902.     IN DWORD cSignerStore,
  9903.     IN OPTIONAL HCERTSTORE *rghSignerStore,
  9904.     IN DWORD dwFlags,
  9905.     OUT OPTIONAL PCCERT_CONTEXT *ppSigner,
  9906.     IN OUT OPTIONAL DWORD *pdwSignerIndex
  9907.     );
  9908.  
  9909. #define CMSG_TRUSTED_SIGNER_FLAG            0x1
  9910. #define CMSG_SIGNER_ONLY_FLAG               0x2
  9911. #define CMSG_USE_SIGNER_INDEX_FLAG          0x4
  9912.  
  9913. //+-------------------------------------------------------------------------
  9914. //  Sign an encoded CTL.
  9915. //
  9916. //  The pbCtlContent can be obtained via a CTL_CONTEXT's pbCtlContent
  9917. //  field or via a CryptEncodeObject(PKCS_CTL or PKCS_SORTED_CTL).
  9918. //
  9919. //  CMSG_CMS_ENCAPSULATED_CTL_FLAG can be set to encode a CMS compatible
  9920. //  V3 SignedData message.
  9921. //--------------------------------------------------------------------------
  9922. WINCRYPT32API
  9923. BOOL
  9924. WINAPI
  9925. CryptMsgSignCTL(
  9926.     IN DWORD dwMsgEncodingType,
  9927.     IN BYTE *pbCtlContent,
  9928.     IN DWORD cbCtlContent,
  9929.     IN PCMSG_SIGNED_ENCODE_INFO pSignInfo,
  9930.     IN DWORD dwFlags,
  9931.     OUT BYTE *pbEncoded,
  9932.     IN OUT DWORD *pcbEncoded
  9933.     );
  9934.  
  9935. // When set, CTL inner content is encapsulated within an OCTET STRING
  9936. #define CMSG_CMS_ENCAPSULATED_CTL_FLAG  0x00008000
  9937.  
  9938. //+-------------------------------------------------------------------------
  9939. //  Encode the CTL and create a signed message containing the encoded CTL.
  9940. //
  9941. //  Set CMSG_ENCODE_SORTED_CTL_FLAG if the CTL entries are to be sorted
  9942. //  before encoding. This flag should be set, if the
  9943. //  CertFindSubjectInSortedCTL or CertEnumSubjectInSortedCTL APIs will
  9944. //  be called. If the identifier for the CTL entries is a hash, such as,
  9945. //  MD5 or SHA1, then, CMSG_ENCODE_HASHED_SUBJECT_IDENTIFIER_FLAG should
  9946. //  also be set.
  9947. //
  9948. //  CMSG_CMS_ENCAPSULATED_CTL_FLAG can be set to encode a CMS compatible
  9949. //  V3 SignedData message.
  9950. //--------------------------------------------------------------------------
  9951. WINCRYPT32API
  9952. BOOL
  9953. WINAPI
  9954. CryptMsgEncodeAndSignCTL(
  9955.     IN DWORD dwMsgEncodingType,
  9956.     IN PCTL_INFO pCtlInfo,
  9957.     IN PCMSG_SIGNED_ENCODE_INFO pSignInfo,
  9958.     IN DWORD dwFlags,
  9959.     OUT BYTE *pbEncoded,
  9960.     IN OUT DWORD *pcbEncoded
  9961.     );
  9962.  
  9963. //  The following flag is set if the CTL is to be encoded with sorted
  9964. //  trusted subjects and the szOID_SORTED_CTL extension is inserted containing
  9965. //  sorted offsets to the encoded subjects.
  9966. #define CMSG_ENCODE_SORTED_CTL_FLAG                     0x1
  9967.  
  9968. //  If the above sorted flag is set, then, the following flag should also
  9969. //  be set if the identifier for the TrustedSubjects is a hash,
  9970. //  such as, MD5 or SHA1.
  9971. #define CMSG_ENCODE_HASHED_SUBJECT_IDENTIFIER_FLAG      0x2
  9972.  
  9973.  
  9974. //+-------------------------------------------------------------------------
  9975. //  Returns TRUE if the SubjectIdentifier exists in the CTL. Optionally
  9976. //  returns a pointer to and byte count of the Subject's encoded attributes.
  9977. //--------------------------------------------------------------------------
  9978. WINCRYPT32API
  9979. BOOL
  9980. WINAPI
  9981. CertFindSubjectInSortedCTL(
  9982.     IN PCRYPT_DATA_BLOB pSubjectIdentifier,
  9983.     IN PCCTL_CONTEXT pCtlContext,
  9984.     IN DWORD dwFlags,
  9985.     IN void *pvReserved,
  9986.     OUT OPTIONAL PCRYPT_DER_BLOB pEncodedAttributes
  9987.     );
  9988.  
  9989. //+-------------------------------------------------------------------------
  9990. //  Enumerates through the sequence of TrustedSubjects in a CTL context
  9991. //  created with CERT_CREATE_CONTEXT_SORTED_FLAG set.
  9992. //
  9993. //  To start the enumeration, *ppvNextSubject must be NULL. Upon return,
  9994. //  *ppvNextSubject is updated to point to the next TrustedSubject in
  9995. //  the encoded sequence.
  9996. //
  9997. //  Returns FALSE for no more subjects or invalid arguments.
  9998. //
  9999. //  Note, the returned DER_BLOBs point directly into the encoded
  10000. //  bytes (not allocated, and must not be freed).
  10001. //--------------------------------------------------------------------------
  10002. WINCRYPT32API
  10003. BOOL
  10004. WINAPI
  10005. CertEnumSubjectInSortedCTL(
  10006.     IN PCCTL_CONTEXT pCtlContext,
  10007.     IN OUT void **ppvNextSubject,
  10008.     OUT OPTIONAL PCRYPT_DER_BLOB pSubjectIdentifier,
  10009.     OUT OPTIONAL PCRYPT_DER_BLOB pEncodedAttributes
  10010.     );
  10011.  
  10012.  
  10013. //+=========================================================================
  10014. //  Certificate Verify CTL Usage Data Structures and APIs
  10015. //==========================================================================
  10016.  
  10017. typedef struct _CTL_VERIFY_USAGE_PARA {
  10018.     DWORD                   cbSize;
  10019.     CRYPT_DATA_BLOB         ListIdentifier;     // OPTIONAL
  10020.     DWORD                   cCtlStore;
  10021.     HCERTSTORE              *rghCtlStore;       // OPTIONAL
  10022.     DWORD                   cSignerStore;
  10023.     HCERTSTORE              *rghSignerStore;    // OPTIONAL
  10024. } CTL_VERIFY_USAGE_PARA, *PCTL_VERIFY_USAGE_PARA;
  10025.  
  10026. typedef struct _CTL_VERIFY_USAGE_STATUS {
  10027.     DWORD                   cbSize;
  10028.     DWORD                   dwError;
  10029.     DWORD                   dwFlags;
  10030.     PCCTL_CONTEXT           *ppCtl;             // IN OUT OPTIONAL
  10031.     DWORD                   dwCtlEntryIndex;
  10032.     PCCERT_CONTEXT          *ppSigner;          // IN OUT OPTIONAL
  10033.     DWORD                   dwSignerIndex;
  10034. } CTL_VERIFY_USAGE_STATUS, *PCTL_VERIFY_USAGE_STATUS;
  10035.  
  10036. #define CERT_VERIFY_INHIBIT_CTL_UPDATE_FLAG     0x1
  10037. #define CERT_VERIFY_TRUSTED_SIGNERS_FLAG        0x2
  10038. #define CERT_VERIFY_NO_TIME_CHECK_FLAG          0x4
  10039. #define CERT_VERIFY_ALLOW_MORE_USAGE_FLAG       0x8
  10040.  
  10041. #define CERT_VERIFY_UPDATED_CTL_FLAG            0x1
  10042.  
  10043. //+-------------------------------------------------------------------------
  10044. //  Verify that a subject is trusted for the specified usage by finding a
  10045. //  signed and time valid CTL with the usage identifiers and containing the
  10046. //  the subject. A subject can be identified by either its certificate context
  10047. //  or any identifier such as its SHA1 hash.
  10048. //
  10049. //  See CertFindSubjectInCTL for definition of dwSubjectType and pvSubject
  10050. //  parameters.
  10051. //
  10052. //  Via pVerifyUsagePara, the caller can specify the stores to be searched
  10053. //  to find the CTL. The caller can also specify the stores containing
  10054. //  acceptable CTL signers. By setting the ListIdentifier, the caller
  10055. //  can also restrict to a particular signer CTL list.
  10056. //
  10057. //  Via pVerifyUsageStatus, the CTL containing the subject, the subject's
  10058. //  index into the CTL's array of entries, and the signer of the CTL
  10059. //  are returned. If the caller is not interested, ppCtl and ppSigner can be set
  10060. //  to NULL. Returned contexts must be freed via the store's free context APIs.
  10061. //
  10062. //  If the CERT_VERIFY_INHIBIT_CTL_UPDATE_FLAG isn't set, then, a time
  10063. //  invalid CTL in one of the CtlStores may be replaced. When replaced, the
  10064. //  CERT_VERIFY_UPDATED_CTL_FLAG is set in pVerifyUsageStatus->dwFlags.
  10065. //
  10066. //  If the CERT_VERIFY_TRUSTED_SIGNERS_FLAG is set, then, only the
  10067. //  SignerStores specified in pVerifyUsageStatus are searched to find
  10068. //  the signer. Otherwise, the SignerStores provide additional sources
  10069. //  to find the signer's certificate.
  10070. //
  10071. //  If CERT_VERIFY_NO_TIME_CHECK_FLAG is set, then, the CTLs aren't checked
  10072. //  for time validity.
  10073. //
  10074. //  If CERT_VERIFY_ALLOW_MORE_USAGE_FLAG is set, then, the CTL may contain
  10075. //  additional usage identifiers than specified by pSubjectUsage. Otherwise,
  10076. //  the found CTL will contain the same usage identifers and no more.
  10077. //
  10078. //  CertVerifyCTLUsage will be implemented as a dispatcher to OID installable
  10079. //  functions. First, it will try to find an OID function matching the first
  10080. //  usage object identifier in the pUsage sequence. Next, it will dispatch
  10081. //  to the default CertDllVerifyCTLUsage functions.
  10082. //
  10083. //  If the subject is trusted for the specified usage, then, TRUE is
  10084. //  returned. Otherwise, FALSE is returned with dwError set to one of the
  10085. //  following:
  10086. //      CRYPT_E_NO_VERIFY_USAGE_DLL
  10087. //      CRYPT_E_NO_VERIFY_USAGE_CHECK
  10088. //      CRYPT_E_VERIFY_USAGE_OFFLINE
  10089. //      CRYPT_E_NOT_IN_CTL
  10090. //      CRYPT_E_NO_TRUSTED_SIGNER
  10091. //--------------------------------------------------------------------------
  10092. WINCRYPT32API
  10093. BOOL
  10094. WINAPI
  10095. CertVerifyCTLUsage(
  10096.     IN DWORD dwEncodingType,
  10097.     IN DWORD dwSubjectType,
  10098.     IN void *pvSubject,
  10099.     IN PCTL_USAGE pSubjectUsage,
  10100.     IN DWORD dwFlags,
  10101.     IN OPTIONAL PCTL_VERIFY_USAGE_PARA pVerifyUsagePara,
  10102.     IN OUT PCTL_VERIFY_USAGE_STATUS pVerifyUsageStatus
  10103.     );
  10104.  
  10105.  
  10106. //+=========================================================================
  10107. //  Certificate Revocation Data Structures and APIs
  10108. //==========================================================================
  10109.  
  10110. //+-------------------------------------------------------------------------
  10111. //  The following data structure may be passed to CertVerifyRevocation to
  10112. //  assist in finding the issuer of the context to be verified.
  10113. //
  10114. //  When pIssuerCert is specified, pIssuerCert is the issuer of
  10115. //  rgpvContext[cContext - 1].
  10116. //
  10117. //  When cCertStore and rgCertStore are specified, these stores may contain
  10118. //  an issuer certificate.
  10119. //
  10120. //  When hCrlStore is specified then a handler which uses CRLs can search this
  10121. //  store for them
  10122. //
  10123. //  When pftTimeToUse is specified then the handler (if possible) must determine
  10124. //  revocation status relative to the time given otherwise the answer may be
  10125. //  independent of time or relative to current time
  10126. //--------------------------------------------------------------------------
  10127. typedef struct _CERT_REVOCATION_PARA {
  10128.     DWORD                   cbSize;
  10129.     PCCERT_CONTEXT          pIssuerCert;
  10130.     DWORD                   cCertStore;
  10131.     HCERTSTORE              *rgCertStore;
  10132.     HCERTSTORE              hCrlStore;
  10133.     LPFILETIME              pftTimeToUse;
  10134. } CERT_REVOCATION_PARA, *PCERT_REVOCATION_PARA;
  10135.  
  10136.  
  10137. //+-------------------------------------------------------------------------
  10138. //  The following data structure is returned by CertVerifyRevocation to
  10139. //  specify the status of the revoked or unchecked context. Review the
  10140. //  following CertVerifyRevocation comments for details.
  10141. //
  10142. //  Upon input to CertVerifyRevocation, cbSize must be set to a size
  10143. //  >= sizeof(CERT_REVOCATION_STATUS). Otherwise, CertVerifyRevocation
  10144. //  returns FALSE and sets LastError to E_INVALIDARG.
  10145. //
  10146. //  Upon input to the installed or registered CRYPT_OID_VERIFY_REVOCATION_FUNC
  10147. //  functions, the dwIndex, dwError and dwReason have been zero'ed.
  10148. //--------------------------------------------------------------------------
  10149. typedef struct _CERT_REVOCATION_STATUS {
  10150.     DWORD                   cbSize;
  10151.     DWORD                   dwIndex;
  10152.     DWORD                   dwError;
  10153.     DWORD                   dwReason;
  10154. } CERT_REVOCATION_STATUS, *PCERT_REVOCATION_STATUS;
  10155.  
  10156. //+-------------------------------------------------------------------------
  10157. //  Verifies the array of contexts for revocation. The dwRevType parameter
  10158. //  indicates the type of the context data structure passed in rgpvContext.
  10159. //  Currently only the revocation of certificates is defined.
  10160. //
  10161. //  If the CERT_VERIFY_REV_CHAIN_FLAG flag is set, then, CertVerifyRevocation
  10162. //  is verifying a chain of certs where, rgpvContext[i + 1] is the issuer
  10163. //  of rgpvContext[i]. Otherwise, CertVerifyRevocation makes no assumptions
  10164. //  about the order of the contexts.
  10165. //
  10166. //  To assist in finding the issuer, the pRevPara may optionally be set. See
  10167. //  the CERT_REVOCATION_PARA data structure for details.
  10168. //
  10169. //  The contexts must contain enough information to allow the
  10170. //  installable or registered revocation DLLs to find the revocation server. For
  10171. //  certificates, this information would normally be conveyed in an
  10172. //  extension such as the IETF's AuthorityInfoAccess extension.
  10173. //
  10174. //  CertVerifyRevocation returns TRUE if all of the contexts were successfully
  10175. //  checked and none were revoked. Otherwise, returns FALSE and updates the
  10176. //  returned pRevStatus data structure as follows:
  10177. //    dwIndex
  10178. //      Index of the first context that was revoked or unable to
  10179. //      be checked for revocation
  10180. //    dwError
  10181. //      Error status. LastError is also set to this error status.
  10182. //      dwError can be set to one of the following error codes defined
  10183. //      in winerror.h:
  10184. //        ERROR_SUCCESS - good context
  10185. //        CRYPT_E_REVOKED - context was revoked. dwReason contains the
  10186. //           reason for revocation
  10187. //        CRYPT_E_REVOCATION_OFFLINE - unable to connect to the
  10188. //           revocation server
  10189. //        CRYPT_E_NOT_IN_REVOCATION_DATABASE - the context to be checked
  10190. //           was not found in the revocation server's database.
  10191. //        CRYPT_E_NO_REVOCATION_CHECK - the called revocation function
  10192. //           wasn't able to do a revocation check on the context
  10193. //        CRYPT_E_NO_REVOCATION_DLL - no installed or registered Dll was
  10194. //           found to verify revocation
  10195. //    dwReason
  10196. //      The dwReason is currently only set for CRYPT_E_REVOKED and contains
  10197. //      the reason why the context was revoked. May be one of the following
  10198. //      CRL reasons defined by the CRL Reason Code extension ("2.5.29.21")
  10199. //          CRL_REASON_UNSPECIFIED              0
  10200. //          CRL_REASON_KEY_COMPROMISE           1
  10201. //          CRL_REASON_CA_COMPROMISE            2
  10202. //          CRL_REASON_AFFILIATION_CHANGED      3
  10203. //          CRL_REASON_SUPERSEDED               4
  10204. //          CRL_REASON_CESSATION_OF_OPERATION   5
  10205. //          CRL_REASON_CERTIFICATE_HOLD         6
  10206. //
  10207. //  For each entry in rgpvContext, CertVerifyRevocation iterates
  10208. //  through the CRYPT_OID_VERIFY_REVOCATION_FUNC
  10209. //  function set's list of installed DEFAULT functions.
  10210. //  CryptGetDefaultOIDFunctionAddress is called with pwszDll = NULL. If no
  10211. //  installed functions are found capable of doing the revocation verification,
  10212. //  CryptVerifyRevocation iterates through CRYPT_OID_VERIFY_REVOCATION_FUNC's
  10213. //  list of registered DEFAULT Dlls. CryptGetDefaultOIDDllList is called to
  10214. //  get the list. CryptGetDefaultOIDFunctionAddress is called to load the Dll.
  10215. //
  10216. //  The called functions have the same signature as CertVerifyRevocation. A
  10217. //  called function returns TRUE if it was able to successfully check all of
  10218. //  the contexts and none were revoked. Otherwise, the called function returns
  10219. //  FALSE and updates pRevStatus. dwIndex is set to the index of
  10220. //  the first context that was found to be revoked or unable to be checked.
  10221. //  dwError and LastError are updated. For CRYPT_E_REVOKED, dwReason
  10222. //  is updated. Upon input to the called function, dwIndex, dwError and
  10223. //  dwReason have been zero'ed. cbSize has been checked to be >=
  10224. //  sizeof(CERT_REVOCATION_STATUS).
  10225. //
  10226. //  If the called function returns FALSE, and dwError isn't set to
  10227. //  CRYPT_E_REVOKED, then, CertVerifyRevocation either continues on to the
  10228. //  next DLL in the list for a returned dwIndex of 0 or for a returned
  10229. //  dwIndex > 0, restarts the process of finding a verify function by
  10230. //  advancing the start of the context array to the returned dwIndex and
  10231. //  decrementing the count of remaining contexts.
  10232. //--------------------------------------------------------------------------
  10233. WINCRYPT32API
  10234. BOOL
  10235. WINAPI
  10236. CertVerifyRevocation(
  10237.     IN DWORD dwEncodingType,
  10238.     IN DWORD dwRevType,
  10239.     IN DWORD cContext,
  10240.     IN PVOID rgpvContext[],
  10241.     IN DWORD dwFlags,
  10242.     IN OPTIONAL PCERT_REVOCATION_PARA pRevPara,
  10243.     IN OUT PCERT_REVOCATION_STATUS pRevStatus
  10244.     );
  10245.  
  10246. //+-------------------------------------------------------------------------
  10247. //  Revocation types
  10248. //--------------------------------------------------------------------------
  10249. #define CERT_CONTEXT_REVOCATION_TYPE        1
  10250.  
  10251. //+-------------------------------------------------------------------------
  10252. //  When the following flag is set, rgpvContext[] consists of a chain
  10253. //  of certificates, where rgpvContext[i + 1] is the issuer of rgpvContext[i].
  10254. //--------------------------------------------------------------------------
  10255. #define CERT_VERIFY_REV_CHAIN_FLAG              0x00000001
  10256.  
  10257. //+-------------------------------------------------------------------------
  10258. // CERT_VERIFY_CACHE_ONLY_BASED_REVOCATION prevents the revocation handler from
  10259. // accessing any network based resources for revocation checking
  10260. //--------------------------------------------------------------------------
  10261. #define CERT_VERIFY_CACHE_ONLY_BASED_REVOCATION 0x00000002
  10262.  
  10263. //+-------------------------------------------------------------------------
  10264. //  CERT_CONTEXT_REVOCATION_TYPE
  10265. //
  10266. //  pvContext points to a const CERT_CONTEXT.
  10267. //--------------------------------------------------------------------------
  10268.  
  10269. //+=========================================================================
  10270. //  Certificate Helper APIs
  10271. //==========================================================================
  10272.  
  10273.  
  10274. //+-------------------------------------------------------------------------
  10275. //  Compare two multiple byte integer blobs to see if they are identical.
  10276. //
  10277. //  Before doing the comparison, leading zero bytes are removed from a
  10278. //  positive number and leading 0xFF bytes are removed from a negative
  10279. //  number.
  10280. //
  10281. //  The multiple byte integers are treated as Little Endian. pbData[0] is the
  10282. //  least significant byte and pbData[cbData - 1] is the most significant
  10283. //  byte.
  10284. //
  10285. //  Returns TRUE if the integer blobs are identical after removing leading
  10286. //  0 or 0xFF bytes.
  10287. //--------------------------------------------------------------------------
  10288. BOOL
  10289. WINAPI
  10290. CertCompareIntegerBlob(
  10291.     IN PCRYPT_INTEGER_BLOB pInt1,
  10292.     IN PCRYPT_INTEGER_BLOB pInt2
  10293.     );
  10294.  
  10295. //+-------------------------------------------------------------------------
  10296. //  Compare two certificates to see if they are identical.
  10297. //
  10298. //  Since a certificate is uniquely identified by its Issuer and SerialNumber,
  10299. //  these are the only fields needing to be compared.
  10300. //
  10301. //  Returns TRUE if the certificates are identical.
  10302. //--------------------------------------------------------------------------
  10303. WINCRYPT32API
  10304. BOOL
  10305. WINAPI
  10306. CertCompareCertificate(
  10307.     IN DWORD dwCertEncodingType,
  10308.     IN PCERT_INFO pCertId1,
  10309.     IN PCERT_INFO pCertId2
  10310.     );
  10311.  
  10312. //+-------------------------------------------------------------------------
  10313. //  Compare two certificate names to see if they are identical.
  10314. //
  10315. //  Returns TRUE if the names are identical.
  10316. //--------------------------------------------------------------------------
  10317. WINCRYPT32API
  10318. BOOL
  10319. WINAPI
  10320. CertCompareCertificateName(
  10321.     IN DWORD dwCertEncodingType,
  10322.     IN PCERT_NAME_BLOB pCertName1,
  10323.     IN PCERT_NAME_BLOB pCertName2
  10324.     );
  10325.  
  10326. //+-------------------------------------------------------------------------
  10327. //  Compare the attributes in the certificate name with the specified
  10328. //  Relative Distinguished Name's (CERT_RDN) array of attributes.
  10329. //  The comparison iterates through the CERT_RDN attributes and looks for an
  10330. //  attribute match in any of the certificate name's RDNs.
  10331. //  Returns TRUE if all the attributes are found and match.
  10332. //
  10333. //  The CERT_RDN_ATTR fields can have the following special values:
  10334. //    pszObjId == NULL              - ignore the attribute object identifier
  10335. //    dwValueType == RDN_ANY_TYPE   - ignore the value type
  10336. //
  10337. //  CERT_CASE_INSENSITIVE_IS_RDN_ATTRS_FLAG should be set to do
  10338. //  a case insensitive match. Otherwise, defaults to an exact, case sensitive
  10339. //  match.
  10340. //
  10341. //  CERT_UNICODE_IS_RDN_ATTRS_FLAG should be set if the pRDN was initialized
  10342. //  with unicode strings as for CryptEncodeObject(X509_UNICODE_NAME).
  10343. //--------------------------------------------------------------------------
  10344. WINCRYPT32API
  10345. BOOL
  10346. WINAPI
  10347. CertIsRDNAttrsInCertificateName(
  10348.     IN DWORD dwCertEncodingType,
  10349.     IN DWORD dwFlags,
  10350.     IN PCERT_NAME_BLOB pCertName,
  10351.     IN PCERT_RDN pRDN
  10352.     );
  10353.  
  10354. #define CERT_UNICODE_IS_RDN_ATTRS_FLAG              0x1
  10355. #define CERT_CASE_INSENSITIVE_IS_RDN_ATTRS_FLAG     0x2
  10356.  
  10357. //+-------------------------------------------------------------------------
  10358. //  Compare two public keys to see if they are identical.
  10359. //
  10360. //  Returns TRUE if the keys are identical.
  10361. //--------------------------------------------------------------------------
  10362. WINCRYPT32API
  10363. BOOL
  10364. WINAPI
  10365. CertComparePublicKeyInfo(
  10366.     IN DWORD dwCertEncodingType,
  10367.     IN PCERT_PUBLIC_KEY_INFO pPublicKey1,
  10368.     IN PCERT_PUBLIC_KEY_INFO pPublicKey2
  10369.     );
  10370.  
  10371. //+-------------------------------------------------------------------------
  10372. //  Get the public/private key's bit length.
  10373. //
  10374. //  Returns 0 if unable to determine the key's length.
  10375. //--------------------------------------------------------------------------
  10376. WINCRYPT32API
  10377. DWORD
  10378. WINAPI
  10379. CertGetPublicKeyLength(
  10380.     IN DWORD dwCertEncodingType,
  10381.     IN PCERT_PUBLIC_KEY_INFO pPublicKey
  10382.     );
  10383.  
  10384. //+-------------------------------------------------------------------------
  10385. //  Verify the signature of a subject certificate or a CRL using the
  10386. //  public key info
  10387. //
  10388. //  Returns TRUE for a valid signature.
  10389. //
  10390. //  hCryptProv specifies the crypto provider to use to verify the signature.
  10391. //  It doesn't need to use a private key.
  10392. //--------------------------------------------------------------------------
  10393. WINCRYPT32API
  10394. BOOL
  10395. WINAPI
  10396. CryptVerifyCertificateSignature(
  10397.     IN HCRYPTPROV               hCryptProv,
  10398.     IN DWORD                    dwCertEncodingType,
  10399.     IN const BYTE *             pbEncoded,
  10400.     IN DWORD                    cbEncoded,
  10401.     IN PCERT_PUBLIC_KEY_INFO    pPublicKey
  10402.     );
  10403.  
  10404. //+-------------------------------------------------------------------------
  10405. //  Verify the signature of a subject certificate, CRL, certificate request
  10406. //  or keygen request using the issuer's public key.
  10407. //
  10408. //  Returns TRUE for a valid signature.
  10409. //
  10410. //  The subject can be an encoded blob or a context for a certificate or CRL.
  10411. //  For a subject certificate context, if the certificate is missing
  10412. //  inheritable PublicKey Algorithm Parameters, the context's
  10413. //  CERT_PUBKEY_ALG_PARA_PROP_ID is updated with the issuer's public key
  10414. //  algorithm parameters for a valid signature.
  10415. //
  10416. //  The issuer can be a pointer to a CERT_PUBLIC_KEY_INFO, certificate
  10417. //  context or a chain context.
  10418. //
  10419. //  hCryptProv specifies the crypto provider to use to verify the signature.
  10420. //  Its private key isn't used. If hCryptProv is NULL, a default
  10421. //  provider is picked according to the PublicKey Algorithm OID.
  10422. //--------------------------------------------------------------------------
  10423. WINCRYPT32API
  10424. BOOL
  10425. WINAPI
  10426. CryptVerifyCertificateSignatureEx(
  10427.     IN OPTIONAL HCRYPTPROV hCryptProv,
  10428.     IN DWORD dwCertEncodingType,
  10429.     IN DWORD dwSubjectType,
  10430.     IN void *pvSubject,
  10431.     IN DWORD dwIssuerType,
  10432.     IN void *pvIssuer,
  10433.     IN DWORD dwFlags,
  10434.     IN OPTIONAL void *pvReserved
  10435.     );
  10436.  
  10437.  
  10438. // Subject Types
  10439. #define CRYPT_VERIFY_CERT_SIGN_SUBJECT_BLOB         1
  10440.     // pvSubject :: PCRYPT_DATA_BLOB
  10441. #define CRYPT_VERIFY_CERT_SIGN_SUBJECT_CERT         2
  10442.     // pvSubject :: PCCERT_CONTEXT
  10443. #define CRYPT_VERIFY_CERT_SIGN_SUBJECT_CRL          3
  10444.     // pvSubject :: PCCRL_CONTEXT
  10445.  
  10446. // Issuer Types
  10447. #define CRYPT_VERIFY_CERT_SIGN_ISSUER_PUBKEY        1
  10448.     // pvIssuer :: PCERT_PUBLIC_KEY_INFO
  10449. #define CRYPT_VERIFY_CERT_SIGN_ISSUER_CERT          2
  10450.     // pvIssuer :: PCCERT_CONTEXT
  10451. #define CRYPT_VERIFY_CERT_SIGN_ISSUER_CHAIN         3
  10452.     // pvIssuer :: PCCERT_CHAIN_CONTEXT
  10453.  
  10454. //+-------------------------------------------------------------------------
  10455. //  Compute the hash of the "to be signed" information in the encoded
  10456. //  signed content (CERT_SIGNED_CONTENT_INFO).
  10457. //
  10458. //  hCryptProv specifies the crypto provider to use to compute the hash.
  10459. //  It doesn't need to use a private key.
  10460. //--------------------------------------------------------------------------
  10461. WINCRYPT32API
  10462. BOOL
  10463. WINAPI
  10464. CryptHashToBeSigned(
  10465.     IN HCRYPTPROV hCryptProv,
  10466.     IN DWORD dwCertEncodingType,
  10467.     IN const BYTE *pbEncoded,
  10468.     IN DWORD cbEncoded,
  10469.     OUT BYTE *pbComputedHash,
  10470.     IN OUT DWORD *pcbComputedHash
  10471.     );
  10472.  
  10473. //+-------------------------------------------------------------------------
  10474. //  Hash the encoded content.
  10475. //
  10476. //  hCryptProv specifies the crypto provider to use to compute the hash.
  10477. //  It doesn't need to use a private key.
  10478. //
  10479. //  Algid specifies the CAPI hash algorithm to use. If Algid is 0, then, the
  10480. //  default hash algorithm (currently SHA1) is used.
  10481. //--------------------------------------------------------------------------
  10482. WINCRYPT32API
  10483. BOOL
  10484. WINAPI
  10485. CryptHashCertificate(
  10486.     IN HCRYPTPROV hCryptProv,
  10487.     IN ALG_ID Algid,
  10488.     IN DWORD dwFlags,
  10489.     IN const BYTE *pbEncoded,
  10490.     IN DWORD cbEncoded,
  10491.     OUT BYTE *pbComputedHash,
  10492.     IN OUT DWORD *pcbComputedHash
  10493.     );
  10494.  
  10495. //+-------------------------------------------------------------------------
  10496. //  Sign the "to be signed" information in the encoded signed content.
  10497. //
  10498. //  hCryptProv specifies the crypto provider to use to do the signature.
  10499. //  It uses the specified private key.
  10500. //--------------------------------------------------------------------------
  10501. WINCRYPT32API
  10502. BOOL
  10503. WINAPI
  10504. CryptSignCertificate(
  10505.     IN HCRYPTPROV hCryptProv,
  10506.     IN DWORD dwKeySpec,
  10507.     IN DWORD dwCertEncodingType,
  10508.     IN const BYTE *pbEncodedToBeSigned,
  10509.     IN DWORD cbEncodedToBeSigned,
  10510.     IN PCRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm,
  10511.     IN OPTIONAL const void *pvHashAuxInfo,
  10512.     OUT BYTE *pbSignature,
  10513.     IN OUT DWORD *pcbSignature
  10514.     );
  10515.  
  10516. //+-------------------------------------------------------------------------
  10517. //  Encode the "to be signed" information. Sign the encoded "to be signed".
  10518. //  Encode the "to be signed" and the signature.
  10519. //
  10520. //  hCryptProv specifies the crypto provider to use to do the signature.
  10521. //  It uses the specified private key.
  10522. //--------------------------------------------------------------------------
  10523. WINCRYPT32API
  10524. BOOL
  10525. WINAPI
  10526. CryptSignAndEncodeCertificate(
  10527.     IN HCRYPTPROV hCryptProv,
  10528.     IN DWORD dwKeySpec,
  10529.     IN DWORD dwCertEncodingType,
  10530.     IN LPCSTR lpszStructType,       // "to be signed"
  10531.     IN const void *pvStructInfo,
  10532.     IN PCRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm,
  10533.     IN OPTIONAL const void *pvHashAuxInfo,
  10534.     OUT PBYTE pbEncoded,
  10535.     IN OUT DWORD *pcbEncoded
  10536.     );
  10537.  
  10538.  
  10539. //+-------------------------------------------------------------------------
  10540. //  Verify the time validity of a certificate.
  10541. //
  10542. //  Returns -1 if before NotBefore, +1 if after NotAfter and otherwise 0 for
  10543. //  a valid certificate
  10544. //
  10545. //  If pTimeToVerify is NULL, uses the current time.
  10546. //--------------------------------------------------------------------------
  10547. WINCRYPT32API
  10548. LONG
  10549. WINAPI
  10550. CertVerifyTimeValidity(
  10551.     IN LPFILETIME pTimeToVerify,
  10552.     IN PCERT_INFO pCertInfo
  10553.     );
  10554.  
  10555.  
  10556. //+-------------------------------------------------------------------------
  10557. //  Verify the time validity of a CRL.
  10558. //
  10559. //  Returns -1 if before ThisUpdate, +1 if after NextUpdate and otherwise 0 for
  10560. //  a valid CRL
  10561. //
  10562. //  If pTimeToVerify is NULL, uses the current time.
  10563. //--------------------------------------------------------------------------
  10564. WINCRYPT32API
  10565. LONG
  10566. WINAPI
  10567. CertVerifyCRLTimeValidity(
  10568.     IN LPFILETIME pTimeToVerify,
  10569.     IN PCRL_INFO pCrlInfo
  10570.     );
  10571.  
  10572. //+-------------------------------------------------------------------------
  10573. //  Verify that the subject's time validity nests within the issuer's time
  10574. //  validity.
  10575. //
  10576. //  Returns TRUE if it nests. Otherwise, returns FALSE.
  10577. //--------------------------------------------------------------------------
  10578. WINCRYPT32API
  10579. BOOL
  10580. WINAPI
  10581. CertVerifyValidityNesting(
  10582.     IN PCERT_INFO pSubjectInfo,
  10583.     IN PCERT_INFO pIssuerInfo
  10584.     );
  10585.  
  10586. //+-------------------------------------------------------------------------
  10587. //  Verify that the subject certificate isn't on its issuer CRL.
  10588. //
  10589. //  Returns true if the certificate isn't on the CRL.
  10590. //--------------------------------------------------------------------------
  10591. WINCRYPT32API
  10592. BOOL
  10593. WINAPI
  10594. CertVerifyCRLRevocation(
  10595.     IN DWORD dwCertEncodingType,
  10596.     IN PCERT_INFO pCertId,          // Only the Issuer and SerialNumber
  10597.     // fields are used
  10598.     IN DWORD cCrlInfo,
  10599.     IN PCRL_INFO rgpCrlInfo[]
  10600.     );
  10601.  
  10602. //+-------------------------------------------------------------------------
  10603. //  Convert the CAPI AlgId to the ASN.1 Object Identifier string
  10604. //
  10605. //  Returns NULL if there isn't an ObjId corresponding to the AlgId.
  10606. //--------------------------------------------------------------------------
  10607. WINCRYPT32API
  10608. LPCSTR
  10609. WINAPI
  10610. CertAlgIdToOID(
  10611.     IN DWORD dwAlgId
  10612.     );
  10613.  
  10614. //+-------------------------------------------------------------------------
  10615. //  Convert the ASN.1 Object Identifier string to the CAPI AlgId.
  10616. //
  10617. //  Returns 0 if there isn't an AlgId corresponding to the ObjId.
  10618. //--------------------------------------------------------------------------
  10619. WINCRYPT32API
  10620. DWORD
  10621. WINAPI
  10622. CertOIDToAlgId(
  10623.     IN LPCSTR pszObjId
  10624.     );
  10625.  
  10626. //+-------------------------------------------------------------------------
  10627. //  Find an extension identified by its Object Identifier.
  10628. //
  10629. //  If found, returns pointer to the extension. Otherwise, returns NULL.
  10630. //--------------------------------------------------------------------------
  10631. WINCRYPT32API
  10632. PCERT_EXTENSION
  10633. WINAPI
  10634. CertFindExtension(
  10635.     IN LPCSTR pszObjId,
  10636.     IN DWORD cExtensions,
  10637.     IN CERT_EXTENSION rgExtensions[]
  10638.     );
  10639.  
  10640. //+-------------------------------------------------------------------------
  10641. //  Find the first attribute identified by its Object Identifier.
  10642. //
  10643. //  If found, returns pointer to the attribute. Otherwise, returns NULL.
  10644. //--------------------------------------------------------------------------
  10645. WINCRYPT32API
  10646. PCRYPT_ATTRIBUTE
  10647. WINAPI
  10648. CertFindAttribute(
  10649.     IN LPCSTR pszObjId,
  10650.     IN DWORD cAttr,
  10651.     IN CRYPT_ATTRIBUTE rgAttr[]
  10652.     );
  10653.  
  10654. //+-------------------------------------------------------------------------
  10655. //  Find the first CERT_RDN attribute identified by its Object Identifier in
  10656. //  the name's list of Relative Distinguished Names.
  10657. //
  10658. //  If found, returns pointer to the attribute. Otherwise, returns NULL.
  10659. //--------------------------------------------------------------------------
  10660. WINCRYPT32API
  10661. PCERT_RDN_ATTR
  10662. WINAPI
  10663. CertFindRDNAttr(
  10664.     IN LPCSTR pszObjId,
  10665.     IN PCERT_NAME_INFO pName
  10666.     );
  10667.  
  10668. //+-------------------------------------------------------------------------
  10669. //  Get the intended key usage bytes from the certificate.
  10670. //
  10671. //  If the certificate doesn't have any intended key usage bytes, returns FALSE
  10672. //  and *pbKeyUsage is zeroed. Otherwise, returns TRUE and up through
  10673. //  cbKeyUsage bytes are copied into *pbKeyUsage. Any remaining uncopied
  10674. //  bytes are zeroed.
  10675. //--------------------------------------------------------------------------
  10676. WINCRYPT32API
  10677. BOOL
  10678. WINAPI
  10679. CertGetIntendedKeyUsage(
  10680.     IN DWORD dwCertEncodingType,
  10681.     IN PCERT_INFO pCertInfo,
  10682.     OUT BYTE *pbKeyUsage,
  10683.     IN DWORD cbKeyUsage
  10684.     );
  10685.  
  10686. typedef void *HCRYPTDEFAULTCONTEXT;
  10687.  
  10688. //+-------------------------------------------------------------------------
  10689. //  Install a previously CryptAcquiredContext'ed HCRYPTPROV to be used as
  10690. //  a default context.
  10691. //
  10692. //  dwDefaultType and pvDefaultPara specify where the default context is used.
  10693. //  For example, install the HCRYPTPROV to be used to verify certificate's
  10694. //  having szOID_OIWSEC_md5RSA signatures.
  10695. //
  10696. //  By default, the installed HCRYPTPROV is only applicable to the current
  10697. //  thread. Set CRYPT_DEFAULT_CONTEXT_PROCESS_FLAG to allow the HCRYPTPROV
  10698. //  to be used by all threads in the current process.
  10699. //
  10700. //  For a successful install, TRUE is returned and *phDefaultContext is
  10701. //  updated with the HANDLE to be passed to CryptUninstallDefaultContext.
  10702. //
  10703. //  The installed HCRYPTPROVs are stack ordered (the last installed
  10704. //  HCRYPTPROV is checked first). All thread installed HCRYPTPROVs are
  10705. //  checked before any process HCRYPTPROVs.
  10706. //
  10707. //  The installed HCRYPTPROV remains available for default usage until
  10708. //  CryptUninstallDefaultContext is called or the thread or process exits.
  10709. //
  10710. //  If CRYPT_DEFAULT_CONTEXT_AUTO_RELEASE_FLAG is set, then, the HCRYPTPROV
  10711. //  is CryptReleaseContext'ed at thread or process exit. However,
  10712. //  not CryptReleaseContext'ed if CryptUninstallDefaultContext is
  10713. //  called.
  10714. //--------------------------------------------------------------------------
  10715. WINCRYPT32API
  10716. BOOL
  10717. WINAPI
  10718. CryptInstallDefaultContext(
  10719.     IN HCRYPTPROV hCryptProv,
  10720.     IN DWORD dwDefaultType,
  10721.     IN const void *pvDefaultPara,
  10722.     IN DWORD dwFlags,
  10723.     IN void *pvReserved,
  10724.     OUT HCRYPTDEFAULTCONTEXT *phDefaultContext
  10725.     );
  10726.  
  10727. // dwFlags
  10728. #define CRYPT_DEFAULT_CONTEXT_AUTO_RELEASE_FLAG             0x00000001
  10729. #define CRYPT_DEFAULT_CONTEXT_PROCESS_FLAG                  0x00000002
  10730.  
  10731. // List of dwDefaultType's
  10732. #define CRYPT_DEFAULT_CONTEXT_CERT_SIGN_OID         1
  10733. #define CRYPT_DEFAULT_CONTEXT_MULTI_CERT_SIGN_OID   2
  10734.  
  10735.  
  10736. //+-------------------------------------------------------------------------
  10737. //  CRYPT_DEFAULT_CONTEXT_CERT_SIGN_OID
  10738. //
  10739. //  Install a default HCRYPTPROV used to verify a certificate
  10740. //  signature. pvDefaultPara points to the szOID of the certificate
  10741. //  signature algorithm, for example, szOID_OIWSEC_md5RSA. If
  10742. //  pvDefaultPara is NULL, then, the HCRYPTPROV is used to verify all
  10743. //  certificate signatures. Note, pvDefaultPara can't be NULL when
  10744. //  CRYPT_DEFAULT_CONTEXT_PROCESS_FLAG is set.
  10745. //--------------------------------------------------------------------------
  10746.  
  10747. //+-------------------------------------------------------------------------
  10748. //  CRYPT_DEFAULT_CONTEXT_MULTI_CERT_SIGN_OID
  10749. //
  10750. //  Same as CRYPT_DEFAULT_CONTEXT_CERT_SIGN_OID. However, the default
  10751. //  HCRYPTPROV is to be used for multiple signature szOIDs. pvDefaultPara
  10752. //  points to a CRYPT_DEFAULT_CONTEXT_MULTI_OID_PARA structure containing
  10753. //  an array of szOID pointers.
  10754. //--------------------------------------------------------------------------
  10755.  
  10756. typedef struct _CRYPT_DEFAULT_CONTEXT_MULTI_OID_PARA {
  10757.     DWORD               cOID;
  10758.     LPSTR               *rgpszOID;
  10759. } CRYPT_DEFAULT_CONTEXT_MULTI_OID_PARA, *PCRYPT_DEFAULT_CONTEXT_MULTI_OID_PARA;
  10760.  
  10761.  
  10762. //+-------------------------------------------------------------------------
  10763. //  Uninstall a default context previously installed by
  10764. //  CryptInstallDefaultContext.
  10765. //
  10766. //  For a default context installed with CRYPT_DEFAULT_CONTEXT_PROCESS_FLAG
  10767. //  set, if any other threads are currently using this context,
  10768. //  this function will block until they finish.
  10769. //--------------------------------------------------------------------------
  10770. WINCRYPT32API
  10771. BOOL
  10772. WINAPI
  10773. CryptUninstallDefaultContext(
  10774.     HCRYPTDEFAULTCONTEXT hDefaultContext,
  10775.     IN DWORD dwFlags,
  10776.     IN void *pvReserved
  10777.     );
  10778.  
  10779. //+-------------------------------------------------------------------------
  10780. //  Export the public key info associated with the provider's corresponding
  10781. //  private key.
  10782. //
  10783. //  Calls CryptExportPublicKeyInfo with pszPublicKeyObjId = szOID_RSA_RSA,
  10784. //  dwFlags = 0 and pvAuxInfo = NULL.
  10785. //--------------------------------------------------------------------------
  10786. WINCRYPT32API
  10787. BOOL
  10788. WINAPI
  10789. CryptExportPublicKeyInfo(
  10790.     IN HCRYPTPROV hCryptProv,
  10791.     IN DWORD dwKeySpec,
  10792.     IN DWORD dwCertEncodingType,
  10793.     OUT PCERT_PUBLIC_KEY_INFO pInfo,
  10794.     IN OUT DWORD *pcbInfo
  10795.     );
  10796.  
  10797.  
  10798. //+-------------------------------------------------------------------------
  10799. //  Export the public key info associated with the provider's corresponding
  10800. //  private key.
  10801. //
  10802. //  Uses the dwCertEncodingType and pszPublicKeyObjId to call the
  10803. //  installable CRYPT_OID_EXPORT_PUBLIC_KEY_INFO_FUNC. The called function
  10804. //  has the same signature as CryptExportPublicKeyInfoEx.
  10805. //
  10806. //  If unable to find an installable OID function for the pszPublicKeyObjId,
  10807. //  attempts to export as a RSA Public Key (szOID_RSA_RSA).
  10808. //
  10809. //  The dwFlags and pvAuxInfo aren't used for szOID_RSA_RSA.
  10810. //--------------------------------------------------------------------------
  10811. #define CRYPT_OID_EXPORT_PUBLIC_KEY_INFO_FUNC   "CryptDllExportPublicKeyInfoEx"
  10812.  
  10813. WINCRYPT32API
  10814. BOOL
  10815. WINAPI
  10816. CryptExportPublicKeyInfoEx(
  10817.     IN HCRYPTPROV hCryptProv,
  10818.     IN DWORD dwKeySpec,
  10819.     IN DWORD dwCertEncodingType,
  10820.     IN LPSTR pszPublicKeyObjId,
  10821.     IN DWORD dwFlags,
  10822.     IN OPTIONAL void *pvAuxInfo,
  10823.     OUT PCERT_PUBLIC_KEY_INFO pInfo,
  10824.     IN OUT DWORD *pcbInfo
  10825.     );
  10826.  
  10827.  
  10828. //+-------------------------------------------------------------------------
  10829. //  Convert and import the public key info into the provider and return a
  10830. //  handle to the public key.
  10831. //
  10832. //  Calls CryptImportPublicKeyInfoEx with aiKeyAlg = 0, dwFlags = 0 and
  10833. //  pvAuxInfo = NULL.
  10834. //--------------------------------------------------------------------------
  10835. WINCRYPT32API
  10836. BOOL
  10837. WINAPI
  10838. CryptImportPublicKeyInfo(
  10839.     IN HCRYPTPROV hCryptProv,
  10840.     IN DWORD dwCertEncodingType,
  10841.     IN PCERT_PUBLIC_KEY_INFO pInfo,
  10842.     OUT HCRYPTKEY *phKey
  10843.     );
  10844.  
  10845. //+-------------------------------------------------------------------------
  10846. //  Convert and import the public key info into the provider and return a
  10847. //  handle to the public key.
  10848. //
  10849. //  Uses the dwCertEncodingType and pInfo->Algorithm.pszObjId to call the
  10850. //  installable CRYPT_OID_IMPORT_PUBLIC_KEY_INFO_FUNC. The called function
  10851. //  has the same signature as CryptImportPublicKeyInfoEx.
  10852. //
  10853. //  If unable to find an installable OID function for the pszObjId,
  10854. //  attempts to import as a RSA Public Key (szOID_RSA_RSA).
  10855. //
  10856. //  For szOID_RSA_RSA: aiKeyAlg may be set to CALG_RSA_SIGN or CALG_RSA_KEYX.
  10857. //  Defaults to CALG_RSA_KEYX. The dwFlags and pvAuxInfo aren't used.
  10858. //--------------------------------------------------------------------------
  10859. #define CRYPT_OID_IMPORT_PUBLIC_KEY_INFO_FUNC   "CryptDllImportPublicKeyInfoEx"
  10860.  
  10861. WINCRYPT32API
  10862. BOOL
  10863. WINAPI
  10864. CryptImportPublicKeyInfoEx(
  10865.     IN HCRYPTPROV hCryptProv,
  10866.     IN DWORD dwCertEncodingType,
  10867.     IN PCERT_PUBLIC_KEY_INFO pInfo,
  10868.     IN ALG_ID aiKeyAlg,
  10869.     IN DWORD dwFlags,
  10870.     IN OPTIONAL void *pvAuxInfo,
  10871.     OUT HCRYPTKEY *phKey
  10872.     );
  10873.  
  10874.  
  10875. //+-------------------------------------------------------------------------
  10876. //  Acquire a HCRYPTPROV handle and dwKeySpec for the specified certificate
  10877. //  context. Uses the certificate's CERT_KEY_PROV_INFO_PROP_ID property.
  10878. //  The returned HCRYPTPROV handle may optionally be cached using the
  10879. //  certificate's CERT_KEY_CONTEXT_PROP_ID property.
  10880. //
  10881. //  If CRYPT_ACQUIRE_CACHE_FLAG is set, then, if an already acquired and
  10882. //  cached HCRYPTPROV exists for the certificate, its returned. Otherwise,
  10883. //  a HCRYPTPROV is acquired and then cached via the certificate's
  10884. //  CERT_KEY_CONTEXT_PROP_ID.
  10885. //
  10886. //  The CRYPT_ACQUIRE_USE_PROV_INFO_FLAG can be set to use the dwFlags field of
  10887. //  the certificate's CERT_KEY_PROV_INFO_PROP_ID property's CRYPT_KEY_PROV_INFO
  10888. //  data structure to determine if the returned HCRYPTPROV should be cached.
  10889. //  HCRYPTPROV caching is enabled if the CERT_SET_KEY_CONTEXT_PROP_ID flag was
  10890. //  set.
  10891. //
  10892. //  If CRYPT_ACQUIRE_COMPARE_KEY_FLAG is set, then,
  10893. //  the public key in the certificate is compared with the public
  10894. //  key returned by the cryptographic provider. If the keys don't match, the
  10895. //  acquire fails and LastError is set to NTE_BAD_PUBLIC_KEY. Note, if
  10896. //  a cached HCRYPTPROV is returned, the comparison isn't done. We assume the
  10897. //  comparison was done on the initial acquire.
  10898. //
  10899. //  *pfCallerFreeProv is returned set to FALSE for:
  10900. //    - Acquire or public key comparison fails.
  10901. //    - CRYPT_ACQUIRE_CACHE_FLAG is set.
  10902. //    - CRYPT_ACQUIRE_USE_PROV_INFO_FLAG is set AND
  10903. //      CERT_SET_KEY_CONTEXT_PROP_ID flag is set in the dwFlags field of the
  10904. //      certificate's CERT_KEY_PROV_INFO_PROP_ID property's
  10905. //      CRYPT_KEY_PROV_INFO data structure.
  10906. //  When *pfCallerFreeProv is FALSE, the caller must not release. The
  10907. //  returned HCRYPTPROV will be released on the last free of the certificate
  10908. //  context.
  10909. //
  10910. //  Otherwise, *pfCallerFreeProv is TRUE and the returned HCRYPTPROV must
  10911. //  be released by the caller by calling CryptReleaseContext.
  10912. //--------------------------------------------------------------------------
  10913. WINCRYPT32API
  10914. BOOL
  10915. WINAPI
  10916. CryptAcquireCertificatePrivateKey(
  10917.     IN PCCERT_CONTEXT pCert,
  10918.     IN DWORD dwFlags,
  10919.     IN void *pvReserved,
  10920.     OUT HCRYPTPROV *phCryptProv,
  10921.     OUT OPTIONAL DWORD *pdwKeySpec,
  10922.     OUT OPTIONAL BOOL *pfCallerFreeProv
  10923.     );
  10924.  
  10925. #define CRYPT_ACQUIRE_CACHE_FLAG                0x1
  10926. #define CRYPT_ACQUIRE_USE_PROV_INFO_FLAG        0x2
  10927. #define CRYPT_ACQUIRE_COMPARE_KEY_FLAG          0x4
  10928.  
  10929.  
  10930. //+-------------------------------------------------------------------------
  10931. //  Enumerates the cryptographic providers and their containers to find the
  10932. //  private key corresponding to the certificate's public key. For a match,
  10933. //  the certificate's CERT_KEY_PROV_INFO_PROP_ID property is updated.
  10934. //
  10935. //  If the CERT_KEY_PROV_INFO_PROP_ID is already set, then, its checked to
  10936. //  see if it matches the provider's public key. For a match, the above
  10937. //  enumeration is skipped.
  10938. //
  10939. //  By default both the user and machine key containers are searched.
  10940. //  The CRYPT_FIND_USER_KEYSET_FLAG or CRYPT_FIND_MACHINE_KEYSET_FLAG
  10941. //  can be set in dwFlags to restrict the search to either of the containers.
  10942. //
  10943. //  If a container isn't found, returns FALSE with LastError set to
  10944. //  NTE_NO_KEY.
  10945. //--------------------------------------------------------------------------
  10946. WINCRYPT32API
  10947. BOOL
  10948. WINAPI
  10949. CryptFindCertificateKeyProvInfo(
  10950.     IN PCCERT_CONTEXT pCert,
  10951.     IN DWORD dwFlags,
  10952.     IN void *pvReserved
  10953.     );
  10954.  
  10955. #define CRYPT_FIND_USER_KEYSET_FLAG        0x1
  10956. #define CRYPT_FIND_MACHINE_KEYSET_FLAG     0x2
  10957.  
  10958.  
  10959. //+-------------------------------------------------------------------------
  10960. //  This is the prototype for the installable function which is called to
  10961. //  actually import a key into a CSP.  an installable of this type is called
  10962. //  from CryptImportPKCS8.  the algorithm OID of the private key is used
  10963. //  to look up the proper installable function to call.
  10964. //
  10965. //  hCryptProv - the provider to import the key to
  10966. //  pPrivateKeyInfo - describes the key to be imported
  10967. //  dwFlags - The available flags are:
  10968. //              CRYPT_EXPORTABLE
  10969. //              this flag is used when importing private keys, for a full
  10970. //              explanation please see the documentation for CryptImportKey.
  10971. //  pvAuxInfo - reserved for future, must be NULL
  10972. //--------------------------------------------------------------------------
  10973. typedef BOOL (WINAPI *PFN_IMPORT_PRIV_KEY_FUNC) (
  10974.     HCRYPTPROV              hCryptProv,         // in
  10975.     CRYPT_PRIVATE_KEY_INFO  *pPrivateKeyInfo,   // in
  10976.     DWORD                   dwFlags,            // in, optional
  10977.     void                    *pvAuxInfo          // in, optional
  10978.     );
  10979.  
  10980. #define CRYPT_OID_IMPORT_PRIVATE_KEY_INFO_FUNC   "CryptDllImportPrivateKeyInfoEx"
  10981.  
  10982. //+-------------------------------------------------------------------------
  10983. // Convert (from PKCS8 format) and import the private key into a provider
  10984. // and return a handle to the provider as well as the KeySpec used to import to.
  10985. //
  10986. // This function will call the PRESOLVE_HCRYPTPROV_FUNC in the
  10987. // privateKeyAndParams to obtain a handle of provider to import the key to.
  10988. // if the PRESOLVE_HCRYPTPROV_FUNC is NULL then the default provider will be used.
  10989. //
  10990. // privateKeyAndParams - private key blob and corresponding parameters
  10991. // dwFlags - The available flags are:
  10992. //              CRYPT_EXPORTABLE
  10993. //              this flag is used when importing private keys, for a full
  10994. //              explanation please see the documentation for CryptImportKey.
  10995. // phCryptProv - filled in with the handle of the provider the key was
  10996. //               imported to, the caller is responsible for freeing it
  10997. // pvAuxInfo - This parameter is reserved for future use and should be set
  10998. //             to NULL in the interim.
  10999. //--------------------------------------------------------------------------
  11000. WINCRYPT32API
  11001. BOOL
  11002. WINAPI
  11003. CryptImportPKCS8(
  11004.     CRYPT_PKCS8_IMPORT_PARAMS           sImportParams,          // in
  11005.     DWORD                               dwFlags,                // in, optional
  11006.     HCRYPTPROV                          *phCryptProv,           // out, optional
  11007.     void                                *pvAuxInfo              // in, optional
  11008.     );
  11009.  
  11010. //+-------------------------------------------------------------------------
  11011. // this is the prototype for installable functions for exporting the private key
  11012. //--------------------------------------------------------------------------
  11013. typedef BOOL (WINAPI *PFN_EXPORT_PRIV_KEY_FUNC) (
  11014.     HCRYPTPROV              hCryptProv,         // in
  11015.     DWORD                   dwKeySpec,          // in
  11016.     LPSTR                   pszPrivateKeyObjId, // in
  11017.     DWORD                   dwFlags,            // in
  11018.     void                    *pvAuxInfo,         // in
  11019.     CRYPT_PRIVATE_KEY_INFO  *pPrivateKeyInfo,   // out
  11020.     DWORD                   *pcbPrivateKeyBlob  // in, out
  11021.     );
  11022.  
  11023. #define CRYPT_OID_EXPORT_PRIVATE_KEY_INFO_FUNC   "CryptDllExportPrivateKeyInfoEx"
  11024.  
  11025. #define CRYPT_DELETE_KEYSET 0x0001
  11026. //+-------------------------------------------------------------------------
  11027. //  CryptExportPKCS8 -- superseded by CryptExportPKCS8Ex
  11028. //
  11029. //  Export the private key in PKCS8 format
  11030. //--------------------------------------------------------------------------
  11031. WINCRYPT32API
  11032. BOOL
  11033. WINAPI
  11034. CryptExportPKCS8(
  11035.     HCRYPTPROV  hCryptProv,         // in
  11036.     DWORD       dwKeySpec,          // in
  11037.     LPSTR       pszPrivateKeyObjId, // in
  11038.     DWORD       dwFlags,            // in
  11039.     void        *pvAuxInfo,         // in
  11040.     BYTE        *pbPrivateKeyBlob,  // out
  11041.     DWORD       *pcbPrivateKeyBlob  // in, out
  11042.     );
  11043.  
  11044. //+-------------------------------------------------------------------------
  11045. // CryptExportPKCS8Ex
  11046. //
  11047. //  Export the private key in PKCS8 format
  11048. //
  11049. //
  11050. //  Uses the pszPrivateKeyObjId to call the
  11051. //  installable CRYPT_OID_EXPORT_PRIVATE_KEY_INFO_FUNC. The called function
  11052. //  has the signature defined by PFN_EXPORT_PRIV_KEY_FUNC.
  11053. //
  11054. //  If unable to find an installable OID function for the pszPrivateKeyObjId,
  11055. //  attempts to export as a RSA Private Key (szOID_RSA_RSA).
  11056. //
  11057. // psExportParams - specifies information about the key to export
  11058. // dwFlags - The flag values. None currently supported
  11059. // pvAuxInfo - This parameter is reserved for future use and should be set to
  11060. //               NULL in the interim.
  11061. // pbPrivateKeyBlob - A pointer to the private key blob.  It will be encoded
  11062. //                      as a PKCS8 PrivateKeyInfo.
  11063. // pcbPrivateKeyBlob - A pointer to a DWORD that contains the size, in bytes,
  11064. //                       of the private key blob being exported.
  11065. //+-------------------------------------------------------------------------
  11066. WINCRYPT32API
  11067. BOOL
  11068. WINAPI
  11069. CryptExportPKCS8Ex(
  11070.     CRYPT_PKCS8_EXPORT_PARAMS* psExportParams, // in
  11071.     DWORD       dwFlags,            // in
  11072.     void        *pvAuxInfo,         // in
  11073.     BYTE        *pbPrivateKeyBlob,  // out
  11074.     DWORD       *pcbPrivateKeyBlob  // in, out
  11075.     );
  11076.  
  11077. //+-------------------------------------------------------------------------
  11078. //  Compute the hash of the encoded public key info.
  11079. //
  11080. //  The public key info is encoded and then hashed.
  11081. //--------------------------------------------------------------------------
  11082. WINCRYPT32API
  11083. BOOL
  11084. WINAPI
  11085. CryptHashPublicKeyInfo(
  11086.     IN HCRYPTPROV hCryptProv,
  11087.     IN ALG_ID Algid,
  11088.     IN DWORD dwFlags,
  11089.     IN DWORD dwCertEncodingType,
  11090.     IN PCERT_PUBLIC_KEY_INFO pInfo,
  11091.     OUT BYTE *pbComputedHash,
  11092.     IN OUT DWORD *pcbComputedHash
  11093.     );
  11094.  
  11095. //+-------------------------------------------------------------------------
  11096. //  Convert a Name Value to a null terminated char string
  11097. //
  11098. //  Returns the number of characters converted including the terminating null
  11099. //  character. If psz is NULL or csz is 0, returns the required size of the
  11100. //  destination string (including the terminating null char).
  11101. //
  11102. //  If psz != NULL && csz != 0, returned psz is always NULL terminated.
  11103. //
  11104. //  Note: csz includes the NULL char.
  11105. //--------------------------------------------------------------------------
  11106. WINCRYPT32API
  11107. DWORD
  11108. WINAPI
  11109. CertRDNValueToStrA(
  11110.     IN DWORD dwValueType,
  11111.     IN PCERT_RDN_VALUE_BLOB pValue,
  11112.     OUT OPTIONAL LPSTR psz,
  11113.     IN DWORD csz
  11114.     );
  11115. //+-------------------------------------------------------------------------
  11116. //  Convert a Name Value to a null terminated char string
  11117. //
  11118. //  Returns the number of characters converted including the terminating null
  11119. //  character. If psz is NULL or csz is 0, returns the required size of the
  11120. //  destination string (including the terminating null char).
  11121. //
  11122. //  If psz != NULL && csz != 0, returned psz is always NULL terminated.
  11123. //
  11124. //  Note: csz includes the NULL char.
  11125. //--------------------------------------------------------------------------
  11126. WINCRYPT32API
  11127. DWORD
  11128. WINAPI
  11129. CertRDNValueToStrW(
  11130.     IN DWORD dwValueType,
  11131.     IN PCERT_RDN_VALUE_BLOB pValue,
  11132.     OUT OPTIONAL LPWSTR psz,
  11133.     IN DWORD csz
  11134.     );
  11135. #ifdef UNICODE
  11136. #define CertRDNValueToStr  CertRDNValueToStrW
  11137. #else
  11138. #define CertRDNValueToStr  CertRDNValueToStrA
  11139. #endif // !UNICODE
  11140.  
  11141. //+-------------------------------------------------------------------------
  11142. //  Convert the certificate name blob to a null terminated char string.
  11143. //
  11144. //  Follows the string representation of distinguished names specified in
  11145. //  RFC 1779. (Note, added double quoting "" for embedded quotes, quote
  11146. //  empty strings and don't quote strings containing consecutive spaces).
  11147. //  RDN values of type CERT_RDN_ENCODED_BLOB or CERT_RDN_OCTET_STRING are
  11148. //  formatted in hexadecimal (e.g. #0A56CF).
  11149. //
  11150. //  The name string is formatted according to the dwStrType:
  11151. //    CERT_SIMPLE_NAME_STR
  11152. //      The object identifiers are discarded. CERT_RDN entries are separated
  11153. //      by ", ". Multiple attributes per CERT_RDN are separated by " + ".
  11154. //      For example:
  11155. //          Microsoft, Joe Cool + Programmer
  11156. //    CERT_OID_NAME_STR
  11157. //      The object identifiers are included with a "=" separator from their
  11158. //      attribute value. CERT_RDN entries are separated by ", ".
  11159. //      Multiple attributes per CERT_RDN are separated by " + ". For example:
  11160. //          2.5.4.11=Microsoft, 2.5.4.3=Joe Cool + 2.5.4.12=Programmer
  11161. //    CERT_X500_NAME_STR
  11162. //      The object identifiers are converted to their X500 key name. Otherwise,
  11163. //      same as CERT_OID_NAME_STR. If the object identifier doesn't have
  11164. //      a corresponding X500 key name, then, the object identifier is used with
  11165. //      a "OID." prefix. For example:
  11166. //          OU=Microsoft, CN=Joe Cool + T=Programmer, OID.1.2.3.4.5.6=Unknown
  11167. //
  11168. //  We quote the RDN value if it contains leading or trailing whitespace
  11169. //  or one of the following characters: ",", "+", "=", """, "\n",  "<", ">",
  11170. //  "#" or ";". The quoting character is ". If the the RDN Value contains
  11171. //  a " it is double quoted (""). For example:
  11172. //      OU="  Microsoft", CN="Joe ""Cool""" + T="Programmer, Manager"
  11173. //
  11174. //  CERT_NAME_STR_SEMICOLON_FLAG can be or'ed into dwStrType to replace
  11175. //  the ", " separator with a "; " separator.
  11176. //
  11177. //  CERT_NAME_STR_CRLF_FLAG can be or'ed into dwStrType to replace
  11178. //  the ", " separator with a "\r\n" separator.
  11179. //
  11180. //  CERT_NAME_STR_NO_PLUS_FLAG can be or'ed into dwStrType to replace the
  11181. //  " + " separator with a single space, " ".
  11182. //
  11183. //  CERT_NAME_STR_NO_QUOTING_FLAG can be or'ed into dwStrType to inhibit
  11184. //  the above quoting.
  11185. //
  11186. //  CERT_NAME_STR_REVERSE_FLAG can be or'ed into dwStrType to reverse the
  11187. //  order of the RDNs before converting to the string.
  11188. //
  11189. //  By default, CERT_RDN_T61_STRING encoded values are initially decoded
  11190. //  as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  11191. //  CERT_NAME_STR_DISABLE_IE4_UTF8_FLAG can be or'ed into dwStrType to
  11192. //  skip the initial attempt to decode as UTF8.
  11193. //
  11194. //  Returns the number of characters converted including the terminating null
  11195. //  character. If psz is NULL or csz is 0, returns the required size of the
  11196. //  destination string (including the terminating null char).
  11197. //
  11198. //  If psz != NULL && csz != 0, returned psz is always NULL terminated.
  11199. //
  11200. //  Note: csz includes the NULL char.
  11201. //--------------------------------------------------------------------------
  11202.  
  11203. //+-------------------------------------------------------------------------
  11204. //--------------------------------------------------------------------------
  11205. WINCRYPT32API
  11206. DWORD
  11207. WINAPI
  11208. CertNameToStrA(
  11209.     IN DWORD dwCertEncodingType,
  11210.     IN PCERT_NAME_BLOB pName,
  11211.     IN DWORD dwStrType,
  11212.     OUT OPTIONAL LPSTR psz,
  11213.     IN DWORD csz
  11214.     );
  11215. //+-------------------------------------------------------------------------
  11216. //--------------------------------------------------------------------------
  11217. WINCRYPT32API
  11218. DWORD
  11219. WINAPI
  11220. CertNameToStrW(
  11221.     IN DWORD dwCertEncodingType,
  11222.     IN PCERT_NAME_BLOB pName,
  11223.     IN DWORD dwStrType,
  11224.     OUT OPTIONAL LPWSTR psz,
  11225.     IN DWORD csz
  11226.     );
  11227. #ifdef UNICODE
  11228. #define CertNameToStr  CertNameToStrW
  11229. #else
  11230. #define CertNameToStr  CertNameToStrA
  11231. #endif // !UNICODE
  11232.  
  11233. //+-------------------------------------------------------------------------
  11234. //  Certificate name string types
  11235. //--------------------------------------------------------------------------
  11236. #define CERT_SIMPLE_NAME_STR        1
  11237. #define CERT_OID_NAME_STR           2
  11238. #define CERT_X500_NAME_STR          3
  11239.  
  11240. //+-------------------------------------------------------------------------
  11241. //  Certificate name string type flags OR'ed with the above types
  11242. //--------------------------------------------------------------------------
  11243. #define CERT_NAME_STR_SEMICOLON_FLAG    0x40000000
  11244. #define CERT_NAME_STR_NO_PLUS_FLAG      0x20000000
  11245. #define CERT_NAME_STR_NO_QUOTING_FLAG   0x10000000
  11246. #define CERT_NAME_STR_CRLF_FLAG         0x08000000
  11247. #define CERT_NAME_STR_COMMA_FLAG        0x04000000
  11248. #define CERT_NAME_STR_REVERSE_FLAG      0x02000000
  11249.  
  11250. #define CERT_NAME_STR_DISABLE_IE4_UTF8_FLAG     0x00010000
  11251. #define CERT_NAME_STR_ENABLE_T61_UNICODE_FLAG   0x00020000
  11252. #define CERT_NAME_STR_ENABLE_UTF8_UNICODE_FLAG  0x00040000
  11253.  
  11254.  
  11255. //+-------------------------------------------------------------------------
  11256. //  Convert the null terminated X500 string to an encoded certificate name.
  11257. //
  11258. //  The input string is expected to be formatted the same as the output
  11259. //  from the above CertNameToStr API.
  11260. //
  11261. //  The CERT_SIMPLE_NAME_STR type isn't supported. Otherwise, when dwStrType
  11262. //  is set to 0, CERT_OID_NAME_STR or CERT_X500_NAME_STR, allow either a
  11263. //  case insensitive X500 key (CN=), case insensitive "OID." prefixed
  11264. //  object identifier (OID.1.2.3.4.5.6=) or an object identifier (1.2.3.4=).
  11265. //
  11266. //  If no flags are OR'ed into dwStrType, then, allow "," or ";" as RDN
  11267. //  separators and "+" as the multiple RDN value separator. Quoting is
  11268. //  supported. A quote may be included in a quoted value by double quoting,
  11269. //  for example (CN="Joe ""Cool"""). A value starting with a "#" is treated
  11270. //  as ascii hex and converted to a CERT_RDN_OCTET_STRING. Embedded whitespace
  11271. //  is skipped (1.2.3 = # AB CD 01  is the same as 1.2.3=#ABCD01).
  11272. //
  11273. //  Whitespace surrounding the keys, object identifers and values is removed.
  11274. //
  11275. //  CERT_NAME_STR_COMMA_FLAG can be or'ed into dwStrType to only allow the
  11276. //  "," as the RDN separator.
  11277. //
  11278. //  CERT_NAME_STR_SEMICOLON_FLAG can be or'ed into dwStrType to only allow the
  11279. //  ";" as the RDN separator.
  11280. //
  11281. //  CERT_NAME_STR_CRLF_FLAG can be or'ed into dwStrType to only allow
  11282. //  "\r" or "\n" as the RDN separator.
  11283. //
  11284. //  CERT_NAME_STR_NO_PLUS_FLAG can be or'ed into dwStrType to ignore "+"
  11285. //  as a separator and not allow multiple values per RDN.
  11286. //
  11287. //  CERT_NAME_STR_NO_QUOTING_FLAG can be or'ed into dwStrType to inhibit
  11288. //  quoting.
  11289. //
  11290. //  CERT_NAME_STR_REVERSE_FLAG can be or'ed into dwStrType to reverse the
  11291. //  order of the RDNs after converting from the string and before encoding.
  11292. //
  11293. //  CERT_NAME_STR_ENABLE_T61_UNICODE_FLAG can be or'ed into dwStrType to
  11294. //  to select the CERT_RDN_T61_STRING encoded value type instead of
  11295. //  CERT_RDN_UNICODE_STRING if all the UNICODE characters are <= 0xFF.
  11296. //
  11297. //  CERT_NAME_STR_ENABLE_UTF8_UNICODE_FLAG can be or'ed into dwStrType to
  11298. //  to select the CERT_RDN_UTF8_STRING encoded value type instead of
  11299. //  CERT_RDN_UNICODE_STRING.
  11300. //
  11301. //  Support the following X500 Keys:
  11302. //
  11303. //  Key         Object Identifier               RDN Value Type(s)
  11304. //  ---         -----------------               -----------------
  11305. //  CN          szOID_COMMON_NAME               Printable, Unicode
  11306. //  L           szOID_LOCALITY_NAME             Printable, Unicode
  11307. //  O           szOID_ORGANIZATION_NAME         Printable, Unicode
  11308. //  OU          szOID_ORGANIZATIONAL_UNIT_NAME  Printable, Unicode
  11309. //  E           szOID_RSA_emailAddr             Only IA5
  11310. //  Email       szOID_RSA_emailAddr             Only IA5
  11311. //  C           szOID_COUNTRY_NAME              Only Printable
  11312. //  S           szOID_STATE_OR_PROVINCE_NAME    Printable, Unicode
  11313. //  ST          szOID_STATE_OR_PROVINCE_NAME    Printable, Unicode
  11314. //  STREET      szOID_STREET_ADDRESS            Printable, Unicode
  11315. //  T           szOID_TITLE                     Printable, Unicode
  11316. //  Title       szOID_TITLE                     Printable, Unicode
  11317. //  G           szOID_GIVEN_NAME                Printable, Unicode
  11318. //  GivenName   szOID_GIVEN_NAME                Printable, Unicode
  11319. //  I           szOID_INITIALS                  Printable, Unicode
  11320. //  Initials    szOID_INITIALS                  Printable, Unicode
  11321. //  SN          szOID_SUR_NAME                  Printable, Unicode
  11322. //  DC          szOID_DOMAIN_COMPONENT          IA5, UTF8
  11323. //
  11324. //  Note, T61 is selected instead of Unicode if
  11325. //  CERT_NAME_STR_ENABLE_T61_UNICODE_FLAG is set and all the unicode
  11326. //  characters are <= 0xFF.
  11327. //
  11328. //  Note, UTF8 is selected instead of Unicode if
  11329. //  CERT_NAME_STR_ENABLE_UTF8_UNICODE_FLAG is set.
  11330. //
  11331. //  Returns TRUE if successfully parsed the input string and encoded
  11332. //  the name.
  11333. //
  11334. //  If the input string is detected to be invalid, *ppszError is updated
  11335. //  to point to the beginning of the invalid character sequence. Otherwise,
  11336. //  *ppszError is set to NULL. *ppszError is updated with a non-NULL pointer
  11337. //  for the following errors:
  11338. //      CRYPT_E_INVALID_X500_STRING
  11339. //      CRYPT_E_INVALID_NUMERIC_STRING
  11340. //      CRYPT_E_INVALID_PRINTABLE_STRING
  11341. //      CRYPT_E_INVALID_IA5_STRING
  11342. //
  11343. //  ppszError can be set to NULL if not interested in getting a pointer
  11344. //  to the invalid character sequence.
  11345. //--------------------------------------------------------------------------
  11346.  
  11347. //+-------------------------------------------------------------------------
  11348. //--------------------------------------------------------------------------
  11349. WINCRYPT32API
  11350. BOOL
  11351. WINAPI
  11352. CertStrToNameA(
  11353.     IN DWORD dwCertEncodingType,
  11354.     IN LPCSTR pszX500,
  11355.     IN DWORD dwStrType,
  11356.     IN OPTIONAL void *pvReserved,
  11357.     OUT BYTE *pbEncoded,
  11358.     IN OUT DWORD *pcbEncoded,
  11359.     OUT OPTIONAL LPCSTR *ppszError
  11360.     );
  11361. //+-------------------------------------------------------------------------
  11362. //--------------------------------------------------------------------------
  11363. WINCRYPT32API
  11364. BOOL
  11365. WINAPI
  11366. CertStrToNameW(
  11367.     IN DWORD dwCertEncodingType,
  11368.     IN LPCWSTR pszX500,
  11369.     IN DWORD dwStrType,
  11370.     IN OPTIONAL void *pvReserved,
  11371.     OUT BYTE *pbEncoded,
  11372.     IN OUT DWORD *pcbEncoded,
  11373.     OUT OPTIONAL LPCWSTR *ppszError
  11374.     );
  11375. #ifdef UNICODE
  11376. #define CertStrToName  CertStrToNameW
  11377. #else
  11378. #define CertStrToName  CertStrToNameA
  11379. #endif // !UNICODE
  11380.  
  11381.  
  11382. //+-------------------------------------------------------------------------
  11383. //  Get the subject or issuer name from the certificate and
  11384. //  according to the specified format type, convert to a null terminated
  11385. //  character string.
  11386. //
  11387. //  CERT_NAME_ISSUER_FLAG can be set to get the issuer's name. Otherwise,
  11388. //  gets the subject's name.
  11389. //
  11390. //  By default, CERT_RDN_T61_STRING encoded values are initially decoded
  11391. //  as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  11392. //  CERT_NAME_DISABLE_IE4_UTF8_FLAG can be set in dwFlags to
  11393. //  skip the initial attempt to decode as UTF8.
  11394. //
  11395. //  The name string is formatted according to the dwType:
  11396. //    CERT_NAME_EMAIL_TYPE
  11397. //      If the certificate has a Subject Alternative Name extension (for
  11398. //      issuer, Issuer Alternative Name), searches for first rfc822Name choice.
  11399. //      If the rfc822Name choice isn't found in the extension, searches the
  11400. //      Subject Name field for the Email OID, "1.2.840.113549.1.9.1".
  11401. //      If the rfc822Name or Email OID is found, returns the string. Otherwise,
  11402. //      returns an empty string (returned character count is 1).
  11403. //    CERT_NAME_RDN_TYPE
  11404. //      Converts the Subject Name blob by calling CertNameToStr. pvTypePara
  11405. //      points to a DWORD containing the dwStrType passed to CertNameToStr.
  11406. //      If the Subject Name field is empty and the certificate has a
  11407. //      Subject Alternative Name extension, searches for and converts
  11408. //      the first directoryName choice.
  11409. //    CERT_NAME_ATTR_TYPE
  11410. //      pvTypePara points to the Object Identifier specifying the name attribute
  11411. //      to be returned. For example, to get the CN,
  11412. //      pvTypePara = szOID_COMMON_NAME ("2.5.4.3"). Searches, the Subject Name
  11413. //      field for the attribute.
  11414. //      If the Subject Name field is empty and the certificate has a
  11415. //      Subject Alternative Name extension, checks for
  11416. //      the first directoryName choice and searches it.
  11417. //
  11418. //      Note, searches the RDNs in reverse order.
  11419. //
  11420. //    CERT_NAME_SIMPLE_DISPLAY_TYPE
  11421. //      Iterates through the following list of name attributes and searches
  11422. //      the Subject Name and then the Subject Alternative Name extension
  11423. //      for the first occurrence of:
  11424. //          szOID_COMMON_NAME ("2.5.4.3")
  11425. //          szOID_ORGANIZATIONAL_UNIT_NAME ("2.5.4.11")
  11426. //          szOID_ORGANIZATION_NAME ("2.5.4.10")
  11427. //          szOID_RSA_emailAddr ("1.2.840.113549.1.9.1")
  11428. //
  11429. //      If none of the above attributes is found, then, searches the
  11430. //      Subject Alternative Name extension for a rfc822Name choice.
  11431. //
  11432. //      If still no match, then, returns the first attribute.
  11433. //
  11434. //      Note, like CERT_NAME_ATTR_TYPE, searches the RDNs in reverse order.
  11435. //
  11436. //    CERT_NAME_FRIENDLY_DISPLAY_TYPE
  11437. //      First checks if the certificate has a CERT_FRIENDLY_NAME_PROP_ID
  11438. //      property. If it does, then, this property is returned. Otherwise,
  11439. //      returns the above CERT_NAME_SIMPLE_DISPLAY_TYPE.
  11440. //
  11441. //  Returns the number of characters converted including the terminating null
  11442. //  character. If pwszNameString is NULL or cchNameString is 0, returns the
  11443. //  required size of the destination string (including the terminating null
  11444. //  char). If the specified name type isn't found. returns an empty string
  11445. //  with a returned character count of 1.
  11446. //
  11447. //  If pwszNameString != NULL && cwszNameString != 0, returned pwszNameString
  11448. //  is always NULL terminated.
  11449. //
  11450. //  Note: cchNameString includes the NULL char.
  11451. //--------------------------------------------------------------------------
  11452.  
  11453. //+-------------------------------------------------------------------------
  11454. //--------------------------------------------------------------------------
  11455. WINCRYPT32API
  11456. DWORD
  11457. WINAPI
  11458. CertGetNameStringA(
  11459.     IN PCCERT_CONTEXT pCertContext,
  11460.     IN DWORD dwType,
  11461.     IN DWORD dwFlags,
  11462.     IN void *pvTypePara,
  11463.     OUT OPTIONAL LPSTR pszNameString,
  11464.     IN DWORD cchNameString
  11465.     );
  11466. //+-------------------------------------------------------------------------
  11467. //--------------------------------------------------------------------------
  11468. WINCRYPT32API
  11469. DWORD
  11470. WINAPI
  11471. CertGetNameStringW(
  11472.     IN PCCERT_CONTEXT pCertContext,
  11473.     IN DWORD dwType,
  11474.     IN DWORD dwFlags,
  11475.     IN void *pvTypePara,
  11476.     OUT OPTIONAL LPWSTR pszNameString,
  11477.     IN DWORD cchNameString
  11478.     );
  11479. #ifdef UNICODE
  11480. #define CertGetNameString  CertGetNameStringW
  11481. #else
  11482. #define CertGetNameString  CertGetNameStringA
  11483. #endif // !UNICODE
  11484.  
  11485. //+-------------------------------------------------------------------------
  11486. //  Certificate name types
  11487. //--------------------------------------------------------------------------
  11488. #define CERT_NAME_EMAIL_TYPE            1
  11489. #define CERT_NAME_RDN_TYPE              2
  11490. #define CERT_NAME_ATTR_TYPE             3
  11491. #define CERT_NAME_SIMPLE_DISPLAY_TYPE   4
  11492. #define CERT_NAME_FRIENDLY_DISPLAY_TYPE 5
  11493.  
  11494. //+-------------------------------------------------------------------------
  11495. //  Certificate name flags
  11496. //--------------------------------------------------------------------------
  11497. #define CERT_NAME_ISSUER_FLAG           0x1
  11498. #define CERT_NAME_DISABLE_IE4_UTF8_FLAG 0x00010000
  11499.  
  11500.  
  11501. //+=========================================================================
  11502. //  Simplified Cryptographic Message Data Structures and APIs
  11503. //==========================================================================
  11504.  
  11505.  
  11506. //+-------------------------------------------------------------------------
  11507. //              Conventions for the *pb and *pcb output parameters:
  11508. //
  11509. //              Upon entry to the function:
  11510. //                  if pcb is OPTIONAL && pcb == NULL, then,
  11511. //                      No output is returned
  11512. //                  else if pb == NULL && pcb != NULL, then,
  11513. //                      Length only determination. No length error is
  11514. //                      returned.
  11515. //                  otherwise where (pb != NULL && pcb != NULL && *pcb != 0)
  11516. //                      Output is returned. If *pcb isn't big enough a
  11517. //                      length error is returned. In all cases *pcb is updated
  11518. //                      with the actual length needed/returned.
  11519. //--------------------------------------------------------------------------
  11520.  
  11521.  
  11522. //+-------------------------------------------------------------------------
  11523. //  Type definitions of the parameters used for doing the cryptographic
  11524. //  operations.
  11525. //--------------------------------------------------------------------------
  11526.  
  11527. //+-------------------------------------------------------------------------
  11528. //  Callback to get and verify the signer's certificate.
  11529. //
  11530. //  Passed the CertId of the signer (its Issuer and SerialNumber) and a
  11531. //  handle to its cryptographic signed message's cert store.
  11532. //
  11533. //  For CRYPT_E_NO_SIGNER, called with pSignerId == NULL.
  11534. //
  11535. //  For a valid signer certificate, returns a pointer to a read only
  11536. //  CERT_CONTEXT. The returned CERT_CONTEXT is either obtained from a
  11537. //  cert store or was created via CertCreateCertificateContext. For either case,
  11538. //  its freed via CertFreeCertificateContext.
  11539. //
  11540. //  If a valid certificate isn't found, this callback returns NULL with
  11541. //  LastError set via SetLastError().
  11542. //
  11543. //  The NULL implementation tries to get the Signer certificate from the
  11544. //  message cert store. It doesn't verify the certificate.
  11545. //
  11546. //  Note, if the KEYID choice was selected for a CMS SignerId, then, the
  11547. //  SerialNumber is 0 and the Issuer is encoded containing a single RDN with a
  11548. //  single Attribute whose OID is szOID_KEYID_RDN, value type is
  11549. //  CERT_RDN_OCTET_STRING and value is the KEYID. When the
  11550. //  CertGetSubjectCertificateFromStore and
  11551. //  CertFindCertificateInStore(CERT_FIND_SUBJECT_CERT) APIs see this
  11552. //  special KEYID Issuer and SerialNumber, they do a KEYID match.
  11553. //--------------------------------------------------------------------------
  11554. typedef PCCERT_CONTEXT (WINAPI *PFN_CRYPT_GET_SIGNER_CERTIFICATE)(
  11555.     IN void *pvGetArg,
  11556.     IN DWORD dwCertEncodingType,
  11557.     IN PCERT_INFO pSignerId,    // Only the Issuer and SerialNumber
  11558.                                 // fields have been updated
  11559.     IN HCERTSTORE hMsgCertStore
  11560.     );
  11561.  
  11562. //+-------------------------------------------------------------------------
  11563. //  The CRYPT_SIGN_MESSAGE_PARA are used for signing messages using the
  11564. //  specified signing certificate context.
  11565. //
  11566. //  Either the CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_PROV_INFO_PROP_ID must
  11567. //  be set for each rgpSigningCert[]. Either one specifies the private
  11568. //  signature key to use.
  11569. //
  11570. //  If any certificates and/or CRLs are to be included in the signed message,
  11571. //  then, the MsgCert and MsgCrl parameters need to be updated. If the
  11572. //  rgpSigningCerts are to be included, then, they must also be in the
  11573. //  rgpMsgCert array.
  11574. //
  11575. //  cbSize must be set to the sizeof(CRYPT_SIGN_MESSAGE_PARA) or else
  11576. //  LastError will be updated with E_INVALIDARG.
  11577. //
  11578. //  pvHashAuxInfo currently isn't used and must be set to NULL.
  11579. //
  11580. //  dwFlags normally is set to 0. However, if the encoded output
  11581. //  is to be a CMSG_SIGNED inner content of an outer cryptographic message,
  11582. //  such as a CMSG_ENVELOPED, then, the CRYPT_MESSAGE_BARE_CONTENT_OUT_FLAG
  11583. //  should be set. If not set, then it would be encoded as an inner content
  11584. //  type of CMSG_DATA.
  11585. //
  11586. //  dwInnerContentType is normally set to 0. It needs to be set if the
  11587. //  ToBeSigned input is the encoded output of another cryptographic
  11588. //  message, such as, an CMSG_ENVELOPED. When set, it's one of the cryptographic
  11589. //  message types, for example, CMSG_ENVELOPED.
  11590. //
  11591. //  If the inner content of a nested cryptographic message is data (CMSG_DATA
  11592. //  the default), then, neither dwFlags or dwInnerContentType need to be set.
  11593. //
  11594. //  For CMS messages, CRYPT_MESSAGE_ENCAPSULATED_CONTENT_OUT_FLAG may be
  11595. //  set to encapsulate nonData inner content within an OCTET STRING.
  11596. //
  11597. //  For CMS messages, CRYPT_MESSAGE_KEYID_SIGNER_FLAG may be set to identify
  11598. //  signers by their Key Identifier and not their Issuer and Serial Number.
  11599. //
  11600. //  If HashEncryptionAlgorithm is present and not NULL its used instead of
  11601. //  the SigningCert's PublicKeyInfo.Algorithm.
  11602. //
  11603. //  Note, for RSA, the hash encryption algorithm is normally the same as
  11604. //  the public key algorithm. For DSA, the hash encryption algorithm is
  11605. //  normally a DSS signature algorithm.
  11606. //
  11607. //  pvHashEncryptionAuxInfo currently isn't used and must be set to NULL if
  11608. //  present in the data structure.
  11609. //--------------------------------------------------------------------------
  11610. typedef struct _CRYPT_SIGN_MESSAGE_PARA {
  11611.     DWORD                       cbSize;
  11612.     DWORD                       dwMsgEncodingType;
  11613.     PCCERT_CONTEXT              pSigningCert;
  11614.     CRYPT_ALGORITHM_IDENTIFIER  HashAlgorithm;
  11615.     void                        *pvHashAuxInfo;
  11616.     DWORD                       cMsgCert;
  11617.     PCCERT_CONTEXT              *rgpMsgCert;
  11618.     DWORD                       cMsgCrl;
  11619.     PCCRL_CONTEXT               *rgpMsgCrl;
  11620.     DWORD                       cAuthAttr;
  11621.     PCRYPT_ATTRIBUTE            rgAuthAttr;
  11622.     DWORD                       cUnauthAttr;
  11623.     PCRYPT_ATTRIBUTE            rgUnauthAttr;
  11624.     DWORD                       dwFlags;
  11625.     DWORD                       dwInnerContentType;
  11626.  
  11627. #ifdef CRYPT_SIGN_MESSAGE_PARA_HAS_CMS_FIELDS
  11628.     CRYPT_ALGORITHM_IDENTIFIER  HashEncryptionAlgorithm;
  11629.     void                        *pvHashEncryptionAuxInfo;
  11630. #endif
  11631. } CRYPT_SIGN_MESSAGE_PARA, *PCRYPT_SIGN_MESSAGE_PARA;
  11632.  
  11633. #define CRYPT_MESSAGE_BARE_CONTENT_OUT_FLAG     0x1
  11634.  
  11635. // When set, nonData type inner content is encapsulated within an
  11636. // OCTET STRING
  11637. #define CRYPT_MESSAGE_ENCAPSULATED_CONTENT_OUT_FLAG 0x2
  11638.  
  11639. // When set, signers are identified by their Key Identifier and not
  11640. // their Issuer and Serial Number.
  11641. #define CRYPT_MESSAGE_KEYID_SIGNER_FLAG         0x4
  11642.  
  11643. //+-------------------------------------------------------------------------
  11644. //  The CRYPT_VERIFY_MESSAGE_PARA are used to verify signed messages.
  11645. //
  11646. //  hCryptProv is used to do hashing and signature verification.
  11647. //
  11648. //  The dwCertEncodingType specifies the encoding type of the certificates
  11649. //  and/or CRLs in the message.
  11650. //
  11651. //  pfnGetSignerCertificate is called to get and verify the message signer's
  11652. //  certificate.
  11653. //
  11654. //  cbSize must be set to the sizeof(CRYPT_VERIFY_MESSAGE_PARA) or else
  11655. //  LastError will be updated with E_INVALIDARG.
  11656. //--------------------------------------------------------------------------
  11657. typedef struct _CRYPT_VERIFY_MESSAGE_PARA {
  11658.     DWORD                               cbSize;
  11659.     DWORD                               dwMsgAndCertEncodingType;
  11660.     HCRYPTPROV                          hCryptProv;
  11661.     PFN_CRYPT_GET_SIGNER_CERTIFICATE    pfnGetSignerCertificate;
  11662.     void                                *pvGetArg;
  11663. } CRYPT_VERIFY_MESSAGE_PARA, *PCRYPT_VERIFY_MESSAGE_PARA;
  11664.  
  11665. //+-------------------------------------------------------------------------
  11666. //  The CRYPT_ENCRYPT_MESSAGE_PARA are used for encrypting messages.
  11667. //
  11668. //  hCryptProv is used to do content encryption, recipient key
  11669. //  encryption, and recipient key export. Its private key
  11670. //  isn't used.
  11671. //
  11672. //  Currently, pvEncryptionAuxInfo is only defined for RC2 or RC4 encryption
  11673. //  algorithms. Otherwise, its not used and must be set to NULL.
  11674. //  See CMSG_RC2_AUX_INFO for the RC2 encryption algorithms.
  11675. //  See CMSG_RC4_AUX_INFO for the RC4 encryption algorithms.
  11676. //
  11677. //  To enable SP3 compatible encryption, pvEncryptionAuxInfo should point to
  11678. //  a CMSG_SP3_COMPATIBLE_AUX_INFO data structure.
  11679. //
  11680. //  cbSize must be set to the sizeof(CRYPT_ENCRYPT_MESSAGE_PARA) or else
  11681. //  LastError will be updated with E_INVALIDARG.
  11682. //
  11683. //  dwFlags normally is set to 0. However, if the encoded output
  11684. //  is to be a CMSG_ENVELOPED inner content of an outer cryptographic message,
  11685. //  such as a CMSG_SIGNED, then, the CRYPT_MESSAGE_BARE_CONTENT_OUT_FLAG
  11686. //  should be set. If not set, then it would be encoded as an inner content
  11687. //  type of CMSG_DATA.
  11688. //
  11689. //  dwInnerContentType is normally set to 0. It needs to be set if the
  11690. //  ToBeEncrypted input is the encoded output of another cryptographic
  11691. //  message, such as, an CMSG_SIGNED. When set, it's one of the cryptographic
  11692. //  message types, for example, CMSG_SIGNED.
  11693. //
  11694. //  If the inner content of a nested cryptographic message is data (CMSG_DATA
  11695. //  the default), then, neither dwFlags or dwInnerContentType need to be set.
  11696. //
  11697. //  For CMS messages, CRYPT_MESSAGE_ENCAPSULATED_CONTENT_OUT_FLAG may be
  11698. //  set to encapsulate nonData inner content within an OCTET STRING before
  11699. //  encrypting.
  11700. //
  11701. //  For CMS messages, CRYPT_MESSAGE_KEYID_RECIPIENT_FLAG may be set to identify
  11702. //  recipients by their Key Identifier and not their Issuer and Serial Number.
  11703. //--------------------------------------------------------------------------
  11704. typedef struct _CRYPT_ENCRYPT_MESSAGE_PARA {
  11705.     DWORD                       cbSize;
  11706.     DWORD                       dwMsgEncodingType;
  11707.     HCRYPTPROV                  hCryptProv;
  11708.     CRYPT_ALGORITHM_IDENTIFIER  ContentEncryptionAlgorithm;
  11709.     void                        *pvEncryptionAuxInfo;
  11710.     DWORD                       dwFlags;
  11711.     DWORD                       dwInnerContentType;
  11712. } CRYPT_ENCRYPT_MESSAGE_PARA, *PCRYPT_ENCRYPT_MESSAGE_PARA;
  11713.  
  11714. // When set, recipients are identified by their Key Identifier and not
  11715. // their Issuer and Serial Number.
  11716. #define CRYPT_MESSAGE_KEYID_RECIPIENT_FLAG          0x4
  11717.  
  11718. //+-------------------------------------------------------------------------
  11719. //  The CRYPT_DECRYPT_MESSAGE_PARA are used for decrypting messages.
  11720. //
  11721. //  The CertContext to use for decrypting a message is obtained from one
  11722. //  of the specified cert stores. An encrypted message can have one or
  11723. //  more recipients. The recipients are identified by their CertId (Issuer
  11724. //  and SerialNumber). The cert stores are searched to find the CertContext
  11725. //  corresponding to the CertId.
  11726. //
  11727. //  For CMS, the recipients may also be identified by their KeyId.
  11728. //  CMS also allows Key Agreement (Diffie Hellman) in addition to
  11729. //  Key Transport (RSA) recipients.
  11730. //
  11731. //  Only CertContexts in the store with either
  11732. //  the CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_PROV_INFO_PROP_ID set
  11733. //  can be used. Either property specifies the private exchange key to use.
  11734. //
  11735. //  cbSize must be set to the sizeof(CRYPT_DECRYPT_MESSAGE_PARA) or else
  11736. //  LastError will be updated with E_INVALIDARG.
  11737. //--------------------------------------------------------------------------
  11738. typedef struct _CRYPT_DECRYPT_MESSAGE_PARA {
  11739.     DWORD                   cbSize;
  11740.     DWORD                   dwMsgAndCertEncodingType;
  11741.     DWORD                   cCertStore;
  11742.     HCERTSTORE              *rghCertStore;
  11743. } CRYPT_DECRYPT_MESSAGE_PARA, *PCRYPT_DECRYPT_MESSAGE_PARA;
  11744.  
  11745. //+-------------------------------------------------------------------------
  11746. //  The CRYPT_HASH_MESSAGE_PARA are used for hashing or unhashing
  11747. //  messages.
  11748. //
  11749. //  hCryptProv is used to compute the hash.
  11750. //
  11751. //  pvHashAuxInfo currently isn't used and must be set to NULL.
  11752. //
  11753. //  cbSize must be set to the sizeof(CRYPT_HASH_MESSAGE_PARA) or else
  11754. //  LastError will be updated with E_INVALIDARG.
  11755. //--------------------------------------------------------------------------
  11756. typedef struct _CRYPT_HASH_MESSAGE_PARA {
  11757.     DWORD                       cbSize;
  11758.     DWORD                       dwMsgEncodingType;
  11759.     HCRYPTPROV                  hCryptProv;
  11760.     CRYPT_ALGORITHM_IDENTIFIER  HashAlgorithm;
  11761.     void                        *pvHashAuxInfo;
  11762. } CRYPT_HASH_MESSAGE_PARA, *PCRYPT_HASH_MESSAGE_PARA;
  11763.  
  11764.  
  11765. //+-------------------------------------------------------------------------
  11766. //  The CRYPT_KEY_SIGN_MESSAGE_PARA are used for signing messages until a
  11767. //  certificate has been created for the signature key.
  11768. //
  11769. //  pvHashAuxInfo currently isn't used and must be set to NULL.
  11770. //
  11771. //  If PubKeyAlgorithm isn't set, defaults to szOID_RSA_RSA.
  11772. //
  11773. //  cbSize must be set to the sizeof(CRYPT_KEY_SIGN_MESSAGE_PARA) or else
  11774. //  LastError will be updated with E_INVALIDARG.
  11775. //--------------------------------------------------------------------------
  11776. typedef struct _CRYPT_KEY_SIGN_MESSAGE_PARA {
  11777.     DWORD                       cbSize;
  11778.     DWORD                       dwMsgAndCertEncodingType;
  11779.     HCRYPTPROV                  hCryptProv;
  11780.     DWORD                       dwKeySpec;
  11781.     CRYPT_ALGORITHM_IDENTIFIER  HashAlgorithm;
  11782.     void                        *pvHashAuxInfo;
  11783.     CRYPT_ALGORITHM_IDENTIFIER  PubKeyAlgorithm;
  11784. } CRYPT_KEY_SIGN_MESSAGE_PARA, *PCRYPT_KEY_SIGN_MESSAGE_PARA;
  11785.  
  11786. //+-------------------------------------------------------------------------
  11787. //  The CRYPT_KEY_VERIFY_MESSAGE_PARA are used to verify signed messages without
  11788. //  a certificate for the signer.
  11789. //
  11790. //  Normally used until a certificate has been created for the key.
  11791. //
  11792. //  hCryptProv is used to do hashing and signature verification.
  11793. //
  11794. //  cbSize must be set to the sizeof(CRYPT_KEY_VERIFY_MESSAGE_PARA) or else
  11795. //  LastError will be updated with E_INVALIDARG.
  11796. //--------------------------------------------------------------------------
  11797. typedef struct _CRYPT_KEY_VERIFY_MESSAGE_PARA {
  11798.     DWORD                   cbSize;
  11799.     DWORD                   dwMsgEncodingType;
  11800.     HCRYPTPROV              hCryptProv;
  11801. } CRYPT_KEY_VERIFY_MESSAGE_PARA, *PCRYPT_KEY_VERIFY_MESSAGE_PARA;
  11802.  
  11803.  
  11804. //+-------------------------------------------------------------------------
  11805. //  Sign the message.
  11806. //
  11807. //  If fDetachedSignature is TRUE, the "to be signed" content isn't included
  11808. //  in the encoded signed blob.
  11809. //--------------------------------------------------------------------------
  11810. WINCRYPT32API
  11811. BOOL
  11812. WINAPI
  11813. CryptSignMessage(
  11814.     IN PCRYPT_SIGN_MESSAGE_PARA pSignPara,
  11815.     IN BOOL fDetachedSignature,
  11816.     IN DWORD cToBeSigned,
  11817.     IN const BYTE *rgpbToBeSigned[],
  11818.     IN DWORD rgcbToBeSigned[],
  11819.     OUT BYTE *pbSignedBlob,
  11820.     IN OUT DWORD *pcbSignedBlob
  11821.     );
  11822.  
  11823. //+-------------------------------------------------------------------------
  11824. //  Verify a signed message.
  11825. //
  11826. //  If pbDecoded == NULL, then, *pcbDecoded is implicitly set to 0 on input.
  11827. //  For *pcbDecoded == 0 && ppSignerCert == NULL on input, the signer isn't
  11828. //  verified.
  11829. //
  11830. //  A message might have more than one signer. Set dwSignerIndex to iterate
  11831. //  through all the signers. dwSignerIndex == 0 selects the first signer.
  11832. //
  11833. //  pVerifyPara's pfnGetSignerCertificate is called to get the signer's
  11834. //  certificate.
  11835. //
  11836. //  For a verified signer and message, *ppSignerCert is updated
  11837. //  with the CertContext of the signer. It must be freed by calling
  11838. //  CertFreeCertificateContext. Otherwise, *ppSignerCert is set to NULL.
  11839. //
  11840. //  ppSignerCert can be NULL, indicating the caller isn't interested
  11841. //  in getting the CertContext of the signer.
  11842. //
  11843. //  pcbDecoded can be NULL, indicating the caller isn't interested in getting
  11844. //  the decoded content. Furthermore, if the message doesn't contain any
  11845. //  content or signers, then, pcbDecoded must be set to NULL, to allow the
  11846. //  pVerifyPara->pfnGetCertificate to be called. Normally, this would be
  11847. //  the case when the signed message contains only certficates and CRLs.
  11848. //  If pcbDecoded is NULL and the message doesn't have the indicated signer,
  11849. //  pfnGetCertificate is called with pSignerId set to NULL.
  11850. //
  11851. //  If the message doesn't contain any signers || dwSignerIndex > message's
  11852. //  SignerCount, then, an error is returned with LastError set to
  11853. //  CRYPT_E_NO_SIGNER. Also, for CRYPT_E_NO_SIGNER, pfnGetSignerCertificate
  11854. //  is still called with pSignerId set to NULL.
  11855. //
  11856. //  Note, an alternative way to get the certificates and CRLs from a
  11857. //  signed message is to call CryptGetMessageCertificates.
  11858. //--------------------------------------------------------------------------
  11859. WINCRYPT32API
  11860. BOOL
  11861. WINAPI
  11862. CryptVerifyMessageSignature(
  11863.     IN PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara,
  11864.     IN DWORD dwSignerIndex,
  11865.     IN const BYTE *pbSignedBlob,
  11866.     IN DWORD cbSignedBlob,
  11867.     OUT BYTE OPTIONAL *pbDecoded,
  11868.     IN OUT OPTIONAL DWORD *pcbDecoded,
  11869.     OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert
  11870.     );
  11871.  
  11872. //+-------------------------------------------------------------------------
  11873. //  Returns the count of signers in the signed message. For no signers, returns
  11874. //  0. For an error returns -1 with LastError updated accordingly.
  11875. //--------------------------------------------------------------------------
  11876. WINCRYPT32API
  11877. LONG
  11878. WINAPI
  11879. CryptGetMessageSignerCount(
  11880.     IN DWORD dwMsgEncodingType,
  11881.     IN const BYTE *pbSignedBlob,
  11882.     IN DWORD cbSignedBlob
  11883.     );
  11884.  
  11885. //+-------------------------------------------------------------------------
  11886. //  Returns the cert store containing the message's certs and CRLs.
  11887. //  For an error, returns NULL with LastError updated.
  11888. //--------------------------------------------------------------------------
  11889. WINCRYPT32API
  11890. HCERTSTORE
  11891. WINAPI
  11892. CryptGetMessageCertificates(
  11893.     IN DWORD dwMsgAndCertEncodingType,
  11894.     IN HCRYPTPROV hCryptProv,           // passed to CertOpenStore
  11895.     IN DWORD dwFlags,                   // passed to CertOpenStore
  11896.     IN const BYTE *pbSignedBlob,
  11897.     IN DWORD cbSignedBlob
  11898.     );
  11899.  
  11900. //+-------------------------------------------------------------------------
  11901. //  Verify a signed message containing detached signature(s).
  11902. //  The "to be signed" content is passed in separately. No
  11903. //  decoded output. Otherwise, identical to CryptVerifyMessageSignature.
  11904. //--------------------------------------------------------------------------
  11905. WINCRYPT32API
  11906. BOOL
  11907. WINAPI
  11908. CryptVerifyDetachedMessageSignature(
  11909.     IN PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara,
  11910.     IN DWORD dwSignerIndex,
  11911.     IN const BYTE *pbDetachedSignBlob,
  11912.     IN DWORD cbDetachedSignBlob,
  11913.     IN DWORD cToBeSigned,
  11914.     IN const BYTE *rgpbToBeSigned[],
  11915.     IN DWORD rgcbToBeSigned[],
  11916.     OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert
  11917.     );
  11918.  
  11919. //+-------------------------------------------------------------------------
  11920. //  Encrypts the message for the recipient(s).
  11921. //--------------------------------------------------------------------------
  11922. WINCRYPT32API
  11923. BOOL
  11924. WINAPI
  11925. CryptEncryptMessage(
  11926.     IN PCRYPT_ENCRYPT_MESSAGE_PARA pEncryptPara,
  11927.     IN DWORD cRecipientCert,
  11928.     IN PCCERT_CONTEXT rgpRecipientCert[],
  11929.     IN const BYTE *pbToBeEncrypted,
  11930.     IN DWORD cbToBeEncrypted,
  11931.     OUT BYTE *pbEncryptedBlob,
  11932.     IN OUT DWORD *pcbEncryptedBlob
  11933.     );
  11934.  
  11935. //+-------------------------------------------------------------------------
  11936. //  Decrypts the message.
  11937. //
  11938. //  If pbDecrypted == NULL, then, *pcbDecrypted is implicitly set to 0 on input.
  11939. //  For *pcbDecrypted == 0 && ppXchgCert == NULL on input, the message isn't
  11940. //  decrypted.
  11941. //
  11942. //  For a successfully decrypted message, *ppXchgCert is updated
  11943. //  with the CertContext used to decrypt. It must be freed by calling
  11944. //  CertStoreFreeCert. Otherwise, *ppXchgCert is set to NULL.
  11945. //
  11946. //  ppXchgCert can be NULL, indicating the caller isn't interested
  11947. //  in getting the CertContext used to decrypt.
  11948. //--------------------------------------------------------------------------
  11949. WINCRYPT32API
  11950. BOOL
  11951. WINAPI
  11952. CryptDecryptMessage(
  11953.     IN PCRYPT_DECRYPT_MESSAGE_PARA pDecryptPara,
  11954.     IN const BYTE *pbEncryptedBlob,
  11955.     IN DWORD cbEncryptedBlob,
  11956.     OUT OPTIONAL BYTE *pbDecrypted,
  11957.     IN OUT OPTIONAL DWORD *pcbDecrypted,
  11958.     OUT OPTIONAL PCCERT_CONTEXT *ppXchgCert
  11959.     );
  11960.  
  11961. //+-------------------------------------------------------------------------
  11962. //  Sign the message and encrypt for the recipient(s). Does a CryptSignMessage
  11963. //  followed with a CryptEncryptMessage.
  11964. //
  11965. //  Note: this isn't the CMSG_SIGNED_AND_ENVELOPED. Its a CMSG_SIGNED
  11966. //  inside of an CMSG_ENVELOPED.
  11967. //--------------------------------------------------------------------------
  11968. WINCRYPT32API
  11969. BOOL
  11970. WINAPI
  11971. CryptSignAndEncryptMessage(
  11972.     IN PCRYPT_SIGN_MESSAGE_PARA pSignPara,
  11973.     IN PCRYPT_ENCRYPT_MESSAGE_PARA pEncryptPara,
  11974.     IN DWORD cRecipientCert,
  11975.     IN PCCERT_CONTEXT rgpRecipientCert[],
  11976.     IN const BYTE *pbToBeSignedAndEncrypted,
  11977.     IN DWORD cbToBeSignedAndEncrypted,
  11978.     OUT BYTE *pbSignedAndEncryptedBlob,
  11979.     IN OUT DWORD *pcbSignedAndEncryptedBlob
  11980.     );
  11981.  
  11982. //+-------------------------------------------------------------------------
  11983. //  Decrypts the message and verifies the signer. Does a CryptDecryptMessage
  11984. //  followed with a CryptVerifyMessageSignature.
  11985. //
  11986. //  If pbDecrypted == NULL, then, *pcbDecrypted is implicitly set to 0 on input.
  11987. //  For *pcbDecrypted == 0 && ppSignerCert == NULL on input, the signer isn't
  11988. //  verified.
  11989. //
  11990. //  A message might have more than one signer. Set dwSignerIndex to iterate
  11991. //  through all the signers. dwSignerIndex == 0 selects the first signer.
  11992. //
  11993. //  The pVerifyPara's VerifySignerPolicy is called to verify the signer's
  11994. //  certificate.
  11995. //
  11996. //  For a successfully decrypted and verified message, *ppXchgCert and
  11997. //  *ppSignerCert are updated. They must be freed by calling
  11998. //  CertStoreFreeCert. Otherwise, they are set to NULL.
  11999. //
  12000. //  ppXchgCert and/or ppSignerCert can be NULL, indicating the
  12001. //  caller isn't interested in getting the CertContext.
  12002. //
  12003. //  Note: this isn't the CMSG_SIGNED_AND_ENVELOPED. Its a CMSG_SIGNED
  12004. //  inside of an CMSG_ENVELOPED.
  12005. //
  12006. //  The message always needs to be decrypted to allow access to the
  12007. //  signed message. Therefore, if ppXchgCert != NULL, its always updated.
  12008. //--------------------------------------------------------------------------
  12009. WINCRYPT32API
  12010. BOOL
  12011. WINAPI
  12012. CryptDecryptAndVerifyMessageSignature(
  12013.     IN PCRYPT_DECRYPT_MESSAGE_PARA pDecryptPara,
  12014.     IN PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara,
  12015.     IN DWORD dwSignerIndex,
  12016.     IN const BYTE *pbEncryptedBlob,
  12017.     IN DWORD cbEncryptedBlob,
  12018.     OUT OPTIONAL BYTE *pbDecrypted,
  12019.     IN OUT OPTIONAL DWORD *pcbDecrypted,
  12020.     OUT OPTIONAL PCCERT_CONTEXT *ppXchgCert,
  12021.     OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert
  12022.     );
  12023.  
  12024. //+-------------------------------------------------------------------------
  12025. //  Decodes a cryptographic message which may be one of the following types:
  12026. //    CMSG_DATA
  12027. //    CMSG_SIGNED
  12028. //    CMSG_ENVELOPED
  12029. //    CMSG_SIGNED_AND_ENVELOPED
  12030. //    CMSG_HASHED
  12031. //
  12032. //  dwMsgTypeFlags specifies the set of allowable messages. For example, to
  12033. //  decode either SIGNED or ENVELOPED messages, set dwMsgTypeFlags to:
  12034. //      CMSG_SIGNED_FLAG | CMSG_ENVELOPED_FLAG.
  12035. //
  12036. //  dwProvInnerContentType is only applicable when processing nested
  12037. //  crytographic messages. When processing an outer crytographic message
  12038. //  it must be set to 0. When decoding a nested cryptographic message
  12039. //  its the dwInnerContentType returned by a previous CryptDecodeMessage
  12040. //  of the outer message. The InnerContentType can be any of the CMSG types,
  12041. //  for example, CMSG_DATA, CMSG_SIGNED, ...
  12042. //
  12043. //  The optional *pdwMsgType is updated with the type of message.
  12044. //
  12045. //  The optional *pdwInnerContentType is updated with the type of the inner
  12046. //  message. Unless there is cryptographic message nesting, CMSG_DATA
  12047. //  is returned.
  12048. //
  12049. //  For CMSG_DATA: returns decoded content.
  12050. //  For CMSG_SIGNED: same as CryptVerifyMessageSignature.
  12051. //  For CMSG_ENVELOPED: same as CryptDecryptMessage.
  12052. //  For CMSG_SIGNED_AND_ENVELOPED: same as CryptDecryptMessage plus
  12053. //      CryptVerifyMessageSignature.
  12054. //  For CMSG_HASHED: verifies the hash and returns decoded content.
  12055. //--------------------------------------------------------------------------
  12056. WINCRYPT32API
  12057. BOOL
  12058. WINAPI
  12059. CryptDecodeMessage(
  12060.     IN DWORD dwMsgTypeFlags,
  12061.     IN PCRYPT_DECRYPT_MESSAGE_PARA pDecryptPara,
  12062.     IN PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara,
  12063.     IN DWORD dwSignerIndex,
  12064.     IN const BYTE *pbEncodedBlob,
  12065.     IN DWORD cbEncodedBlob,
  12066.     IN DWORD dwPrevInnerContentType,
  12067.     OUT OPTIONAL DWORD *pdwMsgType,
  12068.     OUT OPTIONAL DWORD *pdwInnerContentType,
  12069.     OUT OPTIONAL BYTE *pbDecoded,
  12070.     IN OUT OPTIONAL DWORD *pcbDecoded,
  12071.     OUT OPTIONAL PCCERT_CONTEXT *ppXchgCert,
  12072.     OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert
  12073.     );
  12074.  
  12075. //+-------------------------------------------------------------------------
  12076. //  Hash the message.
  12077. //
  12078. //  If fDetachedHash is TRUE, only the ComputedHash is encoded in the
  12079. //  pbHashedBlob. Otherwise, both the ToBeHashed and ComputedHash
  12080. //  are encoded.
  12081. //
  12082. //  pcbHashedBlob or pcbComputedHash can be NULL, indicating the caller
  12083. //  isn't interested in getting the output.
  12084. //--------------------------------------------------------------------------
  12085. WINCRYPT32API
  12086. BOOL
  12087. WINAPI
  12088. CryptHashMessage(
  12089.     IN PCRYPT_HASH_MESSAGE_PARA pHashPara,
  12090.     IN BOOL fDetachedHash,
  12091.     IN DWORD cToBeHashed,
  12092.     IN const BYTE *rgpbToBeHashed[],
  12093.     IN DWORD rgcbToBeHashed[],
  12094.     OUT OPTIONAL BYTE *pbHashedBlob,
  12095.     IN OUT OPTIONAL DWORD *pcbHashedBlob,
  12096.     OUT OPTIONAL BYTE *pbComputedHash,
  12097.     IN OUT OPTIONAL DWORD *pcbComputedHash
  12098.     );
  12099.  
  12100. //+-------------------------------------------------------------------------
  12101. //  Verify a hashed message.
  12102. //
  12103. //  pcbToBeHashed or pcbComputedHash can be NULL,
  12104. //  indicating the caller isn't interested in getting the output.
  12105. //--------------------------------------------------------------------------
  12106. WINCRYPT32API
  12107. BOOL
  12108. WINAPI
  12109. CryptVerifyMessageHash(
  12110.     IN PCRYPT_HASH_MESSAGE_PARA pHashPara,
  12111.     IN BYTE *pbHashedBlob,
  12112.     IN DWORD cbHashedBlob,
  12113.     OUT OPTIONAL BYTE *pbToBeHashed,
  12114.     IN OUT OPTIONAL DWORD *pcbToBeHashed,
  12115.     OUT OPTIONAL BYTE *pbComputedHash,
  12116.     IN OUT OPTIONAL DWORD *pcbComputedHash
  12117.     );
  12118.  
  12119. //+-------------------------------------------------------------------------
  12120. //  Verify a hashed message containing a detached hash.
  12121. //  The "to be hashed" content is passed in separately. No
  12122. //  decoded output. Otherwise, identical to CryptVerifyMessageHash.
  12123. //
  12124. //  pcbComputedHash can be NULL, indicating the caller isn't interested
  12125. //  in getting the output.
  12126. //--------------------------------------------------------------------------
  12127. WINCRYPT32API
  12128. BOOL
  12129. WINAPI
  12130. CryptVerifyDetachedMessageHash(
  12131.     IN PCRYPT_HASH_MESSAGE_PARA pHashPara,
  12132.     IN BYTE *pbDetachedHashBlob,
  12133.     IN DWORD cbDetachedHashBlob,
  12134.     IN DWORD cToBeHashed,
  12135.     IN const BYTE *rgpbToBeHashed[],
  12136.     IN DWORD rgcbToBeHashed[],
  12137.     OUT OPTIONAL BYTE *pbComputedHash,
  12138.     IN OUT OPTIONAL DWORD *pcbComputedHash
  12139.     );
  12140.  
  12141. //+-------------------------------------------------------------------------
  12142. //  Sign the message using the provider's private key specified in the
  12143. //  parameters. A dummy SignerId is created and stored in the message.
  12144. //
  12145. //  Normally used until a certificate has been created for the key.
  12146. //--------------------------------------------------------------------------
  12147. WINCRYPT32API
  12148. BOOL
  12149. WINAPI
  12150. CryptSignMessageWithKey(
  12151.     IN PCRYPT_KEY_SIGN_MESSAGE_PARA pSignPara,
  12152.     IN const BYTE *pbToBeSigned,
  12153.     IN DWORD cbToBeSigned,
  12154.     OUT BYTE *pbSignedBlob,
  12155.     IN OUT DWORD *pcbSignedBlob
  12156.     );
  12157.  
  12158. //+-------------------------------------------------------------------------
  12159. //  Verify a signed message using the specified public key info.
  12160. //
  12161. //  Normally called by a CA until it has created a certificate for the
  12162. //  key.
  12163. //
  12164. //  pPublicKeyInfo contains the public key to use to verify the signed
  12165. //  message. If NULL, the signature isn't verified (for instance, the decoded
  12166. //  content may contain the PublicKeyInfo).
  12167. //
  12168. //  pcbDecoded can be NULL, indicating the caller isn't interested
  12169. //  in getting the decoded content.
  12170. //--------------------------------------------------------------------------
  12171. WINCRYPT32API
  12172. BOOL
  12173. WINAPI
  12174. CryptVerifyMessageSignatureWithKey(
  12175.     IN PCRYPT_KEY_VERIFY_MESSAGE_PARA pVerifyPara,
  12176.     IN OPTIONAL PCERT_PUBLIC_KEY_INFO pPublicKeyInfo,
  12177.     IN const BYTE *pbSignedBlob,
  12178.     IN DWORD cbSignedBlob,
  12179.     OUT OPTIONAL BYTE *pbDecoded,
  12180.     IN OUT OPTIONAL DWORD *pcbDecoded
  12181.     );
  12182.  
  12183.  
  12184. //+=========================================================================
  12185. //  System Certificate Store Data Structures and APIs
  12186. //==========================================================================
  12187.  
  12188.  
  12189. //+-------------------------------------------------------------------------
  12190. //  Get a system certificate store based on a subsystem protocol.
  12191. //
  12192. //  Current examples of subsystems protocols are:
  12193. //      "MY"    Cert Store hold certs with associated Private Keys
  12194. //      "CA"    Certifying Authority certs
  12195. //      "ROOT"  Root Certs
  12196. //      "SPC"   Software publisher certs
  12197. //
  12198. //
  12199. //  If hProv is NULL the default provider "1" is opened for you.
  12200. //  When the store is closed the provider is release. Otherwise
  12201. //  if hProv is not NULL, no provider is created or released.
  12202. //
  12203. //  The returned Cert Store can be searched for an appropriate Cert
  12204. //  using the Cert Store API's (see certstor.h)
  12205. //
  12206. //  When done, the cert store should be closed using CertStoreClose
  12207. //--------------------------------------------------------------------------
  12208.  
  12209.  
  12210. WINCRYPT32API
  12211. HCERTSTORE
  12212. WINAPI
  12213. CertOpenSystemStoreA(
  12214.     HCRYPTPROV      hProv,
  12215.     LPCSTR            szSubsystemProtocol
  12216.     );
  12217. WINCRYPT32API
  12218. HCERTSTORE
  12219. WINAPI
  12220. CertOpenSystemStoreW(
  12221.     HCRYPTPROV      hProv,
  12222.     LPCWSTR            szSubsystemProtocol
  12223.     );
  12224. #ifdef UNICODE
  12225. #define CertOpenSystemStore  CertOpenSystemStoreW
  12226. #else
  12227. #define CertOpenSystemStore  CertOpenSystemStoreA
  12228. #endif // !UNICODE
  12229.  
  12230. WINCRYPT32API
  12231. BOOL
  12232. WINAPI
  12233. CertAddEncodedCertificateToSystemStoreA(
  12234.     LPCSTR            szCertStoreName,
  12235.     const BYTE *    pbCertEncoded,
  12236.     DWORD           cbCertEncoded
  12237.     );
  12238. WINCRYPT32API
  12239. BOOL
  12240. WINAPI
  12241. CertAddEncodedCertificateToSystemStoreW(
  12242.     LPCWSTR            szCertStoreName,
  12243.     const BYTE *    pbCertEncoded,
  12244.     DWORD           cbCertEncoded
  12245.     );
  12246. #ifdef UNICODE
  12247. #define CertAddEncodedCertificateToSystemStore  CertAddEncodedCertificateToSystemStoreW
  12248. #else
  12249. #define CertAddEncodedCertificateToSystemStore  CertAddEncodedCertificateToSystemStoreA
  12250. #endif // !UNICODE
  12251.  
  12252.  
  12253. //+-------------------------------------------------------------------------
  12254. //  Find all certificate chains tying the given issuer name to any certificate
  12255. //  that the current user has a private key for.
  12256. //
  12257. //  If no certificate chain is found, FALSE is returned with LastError set
  12258. //  to CRYPT_E_NOT_FOUND and the counts zeroed.
  12259. //
  12260. //  IE 3.0 ASSUMPTION:
  12261. //   The client certificates are in the "My" system store. The issuer
  12262. //   cerificates may be in the "Root", "CA" or "My" system stores.
  12263. //--------------------------------------------------------------------------
  12264. typedef struct _CERT_CHAIN {
  12265.     DWORD                   cCerts;     // number of certs in chain
  12266.     PCERT_BLOB              certs;      // pointer to array of cert chain blobs
  12267.                                         // representing the certs
  12268.     CRYPT_KEY_PROV_INFO     keyLocatorInfo; // key locator for cert
  12269. } CERT_CHAIN, *PCERT_CHAIN;
  12270.  
  12271.  
  12272. // WINCRYPT32API    This is not exported by crypt32, it is exported by softpub
  12273. HRESULT
  12274. WINAPI
  12275. FindCertsByIssuer(
  12276.     OUT PCERT_CHAIN pCertChains,
  12277.     IN OUT DWORD *pcbCertChains,
  12278.     OUT DWORD *pcCertChains,        // count of certificates chains returned
  12279.     IN BYTE* pbEncodedIssuerName,   // DER encoded issuer name
  12280.     IN DWORD cbEncodedIssuerName,   // count in bytes of encoded issuer name
  12281.     IN LPCWSTR pwszPurpose,         // "ClientAuth" or "CodeSigning"
  12282.     IN DWORD dwKeySpec              // only return signers supporting this
  12283.     // keyspec
  12284.     );
  12285.  
  12286. //-------------------------------------------------------------------------
  12287. //
  12288. //  CryptQueryObject takes a CERT_BLOB or a file name and returns the
  12289. //  information about the content in the blob or in the file.
  12290. //
  12291. //  Parameters:
  12292. //  INPUT   dwObjectType:
  12293. //                       Indicate the type of the object.  Should be one of the
  12294. //                       following:
  12295. //                          CERT_QUERY_OBJECT_FILE
  12296. //                          CERT_QUERY_OBJECT_BLOB
  12297. //
  12298. //  INPUT   pvObject:
  12299. //                        If dwObjectType == CERT_QUERY_OBJECT_FILE, it is a
  12300. //                        LPWSTR, that is, the pointer to a wchar file name
  12301. //                        if dwObjectType == CERT_QUERY_OBJECT_BLOB, it is a
  12302. //                        PCERT_BLOB, that is, a pointer to a CERT_BLOB
  12303. //
  12304. //  INPUT   dwExpectedContentTypeFlags:
  12305. //                        Indicate the expected contenet type.
  12306. //                        Can be one of the following:
  12307. //                              CERT_QUERY_CONTENT_FLAG_ALL  (the content can be any type)
  12308. //                              CERT_QUERY_CONTENT_FLAG_CERT
  12309. //                              CERT_QUERY_CONTENT_FLAG_CTL
  12310. //                              CERT_QUERY_CONTENT_FLAG_CRL
  12311. //                              CERT_QUERY_CONTENT_FLAG_SERIALIZED_STORE
  12312. //                              CERT_QUERY_CONTENT_FLAG_SERIALIZED_CERT
  12313. //                              CERT_QUERY_CONTENT_FLAG_SERIALIZED_CTL
  12314. //                              CERT_QUERY_CONTENT_FLAG_SERIALIZED_CRL
  12315. //                              CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED
  12316. //                              CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED
  12317. //                              CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED
  12318. //                              CERT_QUERY_CONTNET_FLAG_PKCS10
  12319. //                              CERT_QUERY_CONTNET_FLAG_PFX
  12320. //
  12321. //  INPUT   dwExpectedFormatTypeFlags:
  12322. //                        Indicate the expected format type.
  12323. //                        Can be one of the following:
  12324. //                              CERT_QUERY_FORMAT_FLAG_ALL (the content can be any format)
  12325. //                              CERT_QUERY_FORMAT_FLAG_BINARY
  12326. //                              CERT_QUERY_FORMAT_FLAG_BASE64_ENCODED
  12327. //
  12328. //
  12329. //  INPUT   dwFlags
  12330. //                        Reserved flag.  Should always set to 0
  12331. //
  12332. //  OUTPUT  pdwMsgAndCertEncodingType
  12333. //                        Optional output.  If NULL != pdwMsgAndCertEncodingType,
  12334. //                        it contains the encoding type of the content as any
  12335. //                        combination of the following:
  12336. //                              X509_ASN_ENCODING
  12337. //                              PKCS_7_ASN_ENCODING
  12338. //
  12339. //  OUTPUT  pdwContentType
  12340. //                        Optional output.  If NULL!=pdwContentType, it contains
  12341. //                        the content type as one of the the following:
  12342. //                              CERT_QUERY_CONTENT_CERT
  12343. //                              CERT_QUERY_CONTENT_CTL
  12344. //                              CERT_QUERY_CONTENT_CRL
  12345. //                              CERT_QUERY_CONTENT_SERIALIZED_STORE
  12346. //                              CERT_QUERY_CONTENT_SERIALIZED_CERT
  12347. //                              CERT_QUERY_CONTENT_SERIALIZED_CTL
  12348. //                              CERT_QUERY_CONTENT_SERIALIZED_CRL
  12349. //                              CERT_QUERY_CONTENT_PKCS7_SIGNED
  12350. //                              CERT_QUERY_CONTENT_PKCS7_UNSIGNED
  12351. //                              CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED
  12352. //                              CERT_QUERY_CONTENT_PKCS10
  12353. //                              CERT_QUERY_CONTENT_PFX
  12354. //
  12355. //  OUTPUT  pdwFormatType
  12356. //                        Optional output.  If NULL !=pdwFormatType, it
  12357. //                        contains the format type of the content as one of the
  12358. //                        following:
  12359. //                              CERT_QUERY_FORMAT_BINARY
  12360. //                              CERT_QUERY_FORMAT_BASE64_ENCODED
  12361. //
  12362. //
  12363. //  OUTPUT  phCertStore
  12364. //                        Optional output.  If NULL !=phStore,
  12365. //                        it contains a cert store that includes all of certificates,
  12366. //                        CRL, and CTL in the object if the object content type is
  12367. //                        one of the following:
  12368. //                              CERT_QUERY_CONTENT_CERT
  12369. //                              CERT_QUERY_CONTENT_CTL
  12370. //                              CERT_QUERY_CONTENT_CRL
  12371. //                              CERT_QUERY_CONTENT_SERIALIZED_STORE
  12372. //                              CERT_QUERY_CONTENT_SERIALIZED_CERT
  12373. //                              CERT_QUERY_CONTENT_SERIALIZED_CTL
  12374. //                              CERT_QUERY_CONTENT_SERIALIZED_CRL
  12375. //                              CERT_QUERY_CONTENT_PKCS7_SIGNED
  12376. //                              CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED
  12377. //
  12378. //                       Caller should free *phCertStore via CertCloseStore.
  12379. //
  12380. //
  12381. //  OUTPUT  phMsg        Optional output.  If NULL != phMsg,
  12382. //                        it contains a handle to a opened message if
  12383. //                        the content type is one of the following:
  12384. //                              CERT_QUERY_CONTENT_PKCS7_SIGNED
  12385. //                              CERT_QUERY_CONTENT_PKCS7_UNSIGNED
  12386. //                              CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED
  12387. //
  12388. //                       Caller should free *phMsg via CryptMsgClose.
  12389. //
  12390. //  OUTPUT pContext     Optional output.  If NULL != pContext,
  12391. //                      it contains either a PCCERT_CONTEXT or PCCRL_CONTEXT,
  12392. //                      or PCCTL_CONTEXT based on the content type.
  12393. //
  12394. //                      If the content type is CERT_QUERY_CONTENT_CERT or
  12395. //                      CERT_QUERY_CONTENT_SERIALIZED_CERT, it is a PCCERT_CONTEXT;
  12396. //                      Caller should free the pContext via CertFreeCertificateContext.
  12397. //
  12398. //                      If the content type is CERT_QUERY_CONTENT_CRL or
  12399. //                      CERT_QUERY_CONTENT_SERIALIZED_CRL, it is a PCCRL_CONTEXT;
  12400. //                      Caller should free the pContext via CertFreeCRLContext.
  12401. //
  12402. //                      If the content type is CERT_QUERY_CONTENT_CTL or
  12403. //                      CERT_QUERY_CONTENT_SERIALIZED_CTL, it is a PCCTL_CONTEXT;
  12404. //                      Caller should free the pContext via CertFreeCTLContext.
  12405. //
  12406. //  If the *pbObject is of type CERT_QUERY_CONTENT_PKCS10 or CERT_QUERY_CONTENT_PFX, CryptQueryObject
  12407. //  will not return anything in *phCertstore, *phMsg, or *ppvContext.
  12408. //--------------------------------------------------------------------------
  12409. WINCRYPT32API
  12410. BOOL
  12411. WINAPI
  12412. CryptQueryObject(
  12413.     DWORD            dwObjectType,
  12414.     const void       *pvObject,
  12415.     DWORD            dwExpectedContentTypeFlags,
  12416.     DWORD            dwExpectedFormatTypeFlags,
  12417.     DWORD            dwFlags,
  12418.     DWORD            *pdwMsgAndCertEncodingType,
  12419.     DWORD            *pdwContentType,
  12420.     DWORD            *pdwFormatType,
  12421.     HCERTSTORE       *phCertStore,
  12422.     HCRYPTMSG        *phMsg,
  12423.     const void       **ppvContext
  12424.     );
  12425.  
  12426.  
  12427. //-------------------------------------------------------------------------
  12428. //dwObjectType for CryptQueryObject
  12429. //-------------------------------------------------------------------------
  12430. #define     CERT_QUERY_OBJECT_FILE         0x00000001
  12431. #define     CERT_QUERY_OBJECT_BLOB         0x00000002
  12432.  
  12433. //-------------------------------------------------------------------------
  12434. //dwConentType for CryptQueryObject
  12435. //-------------------------------------------------------------------------
  12436. //encoded single certificate
  12437. #define     CERT_QUERY_CONTENT_CERT                 1
  12438. //encoded single CTL
  12439. #define     CERT_QUERY_CONTENT_CTL                  2
  12440. //encoded single CRL
  12441. #define     CERT_QUERY_CONTENT_CRL                  3
  12442. //serialized store
  12443. #define     CERT_QUERY_CONTENT_SERIALIZED_STORE     4
  12444. //serialized single certificate
  12445. #define     CERT_QUERY_CONTENT_SERIALIZED_CERT      5
  12446. //serialized single CTL
  12447. #define     CERT_QUERY_CONTENT_SERIALIZED_CTL       6
  12448. //serialized single CRL
  12449. #define     CERT_QUERY_CONTENT_SERIALIZED_CRL       7
  12450. //a PKCS#7 signed message
  12451. #define     CERT_QUERY_CONTENT_PKCS7_SIGNED         8
  12452. //a PKCS#7 message, such as enveloped message.  But it is not a signed message,
  12453. #define     CERT_QUERY_CONTENT_PKCS7_UNSIGNED       9
  12454. //a PKCS7 signed message embedded in a file
  12455. #define     CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED   10
  12456. //an encoded PKCS#10
  12457. #define     CERT_QUERY_CONTENT_PKCS10               11
  12458. //an encoded PKX BLOB
  12459. #define     CERT_QUERY_CONTENT_PFX                    12
  12460.  
  12461.  
  12462. //-------------------------------------------------------------------------
  12463. //dwExpectedConentTypeFlags for CryptQueryObject
  12464. //-------------------------------------------------------------------------
  12465.  
  12466. //encoded single certificate
  12467. #define     CERT_QUERY_CONTENT_FLAG_CERT   \
  12468.                 ( 1 << CERT_QUERY_CONTENT_CERT)
  12469.  
  12470. //encoded single CTL
  12471. #define     CERT_QUERY_CONTENT_FLAG_CTL   \
  12472.                 ( 1 << CERT_QUERY_CONTENT_CTL)
  12473.  
  12474. //encoded single CRL
  12475. #define     CERT_QUERY_CONTENT_FLAG_CRL   \
  12476.                 ( 1 << CERT_QUERY_CONTENT_CRL)
  12477.  
  12478. //serialized store
  12479. #define     CERT_QUERY_CONTENT_FLAG_SERIALIZED_STORE   \
  12480.                 ( 1 << CERT_QUERY_CONTENT_SERIALIZED_STORE)
  12481.  
  12482. //serialized single certificate
  12483. #define     CERT_QUERY_CONTENT_FLAG_SERIALIZED_CERT   \
  12484.                 ( 1 << CERT_QUERY_CONTENT_SERIALIZED_CERT)
  12485.  
  12486. //serialized single CTL
  12487. #define     CERT_QUERY_CONTENT_FLAG_SERIALIZED_CTL   \
  12488.                 ( 1 << CERT_QUERY_CONTENT_SERIALIZED_CTL)
  12489.  
  12490. //serialized single CRL
  12491. #define     CERT_QUERY_CONTENT_FLAG_SERIALIZED_CRL   \
  12492.                 ( 1 << CERT_QUERY_CONTENT_SERIALIZED_CRL)
  12493.  
  12494. //an encoded PKCS#7 signed message
  12495. #define     CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED   \
  12496.                 ( 1 << CERT_QUERY_CONTENT_PKCS7_SIGNED)
  12497.  
  12498. //an encoded PKCS#7 message.  But it is not a signed message
  12499. #define     CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED   \
  12500.                 ( 1 << CERT_QUERY_CONTENT_PKCS7_UNSIGNED)
  12501.  
  12502. //the content includes an embedded PKCS7 signed message
  12503. #define     CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED  \
  12504.                 ( 1 << CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED)
  12505.  
  12506. //an encoded PKCS#10
  12507. #define     CERT_QUERY_CONTENT_FLAG_PKCS10   \
  12508.                 ( 1 << CERT_QUERY_CONTENT_PKCS10)
  12509.  
  12510. //an encoded PFX BLOB
  12511. #define     CERT_QUERY_CONTENT_FLAG_PFX      \
  12512.                 ( 1 << CERT_QUERY_CONTENT_PFX)
  12513.  
  12514. //content can be any type
  12515. #define     CERT_QUERY_CONTENT_FLAG_ALL                         \
  12516.                 CERT_QUERY_CONTENT_FLAG_CERT |                  \
  12517.                 CERT_QUERY_CONTENT_FLAG_CTL  |                  \
  12518.                 CERT_QUERY_CONTENT_FLAG_CRL  |                  \
  12519.                 CERT_QUERY_CONTENT_FLAG_SERIALIZED_STORE |      \
  12520.                 CERT_QUERY_CONTENT_FLAG_SERIALIZED_CERT  |      \
  12521.                 CERT_QUERY_CONTENT_FLAG_SERIALIZED_CTL   |      \
  12522.                 CERT_QUERY_CONTENT_FLAG_SERIALIZED_CRL   |      \
  12523.                 CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED     |      \
  12524.                 CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED   |      \
  12525.                 CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED |    \
  12526.                 CERT_QUERY_CONTENT_FLAG_PKCS10               |    \
  12527.                 CERT_QUERY_CONTENT_FLAG_PFX
  12528.  
  12529.  
  12530. //-------------------------------------------------------------------------
  12531. //dwFormatType for CryptQueryObject
  12532. //-------------------------------------------------------------------------
  12533. //the content is in binary format
  12534. #define     CERT_QUERY_FORMAT_BINARY                1
  12535.  
  12536. //the content is base64 encoded
  12537. #define     CERT_QUERY_FORMAT_BASE64_ENCODED        2
  12538. //-------------------------------------------------------------------------
  12539. //dwExpectedFormatTypeFlags for CryptQueryObject
  12540. //-------------------------------------------------------------------------
  12541. //the content is in binary format
  12542. #define     CERT_QUERY_FORMAT_FLAG_BINARY         \
  12543.                 ( 1 << CERT_QUERY_FORMAT_BINARY)
  12544.  
  12545. //the content is base64 encoded
  12546. #define     CERT_QUERY_FORMAT_FLAG_BASE64_ENCODED \
  12547.                 ( 1 << CERT_QUERY_FORMAT_BASE64_ENCODED)
  12548.  
  12549. //the content can be of any format
  12550. #define     CERT_QUERY_FORMAT_FLAG_ALL              \
  12551.             CERT_QUERY_FORMAT_FLAG_BINARY   |       \
  12552.             CERT_QUERY_FORMAT_FLAG_BASE64_ENCODED
  12553.  
  12554.  
  12555.  
  12556. //
  12557. // Crypt32 Memory Management Routines.  All Crypt32 API which return allocated
  12558. // buffers will do so via CryptMemAlloc, CryptMemRealloc.  Clients can free
  12559. // those buffers using CryptMemFree.  Also included is CryptMemSize
  12560. //
  12561.  
  12562. WINCRYPT32API
  12563. LPVOID
  12564. WINAPI
  12565. CryptMemAlloc (
  12566.     IN ULONG cbSize
  12567.     );
  12568.  
  12569. WINCRYPT32API
  12570. LPVOID
  12571. WINAPI
  12572. CryptMemRealloc (
  12573.     IN LPVOID pv,
  12574.     IN ULONG cbSize
  12575.     );
  12576.  
  12577. WINCRYPT32API
  12578. VOID
  12579. WINAPI
  12580. CryptMemFree (
  12581.     IN LPVOID pv
  12582.     );
  12583.  
  12584. //
  12585. // Crypt32 Asynchronous Parameter Management Routines.  All Crypt32 API which
  12586. // expose asynchronous mode operation use a Crypt32 Async Handle to pass
  12587. // around information about the operation e.g. callback routines.  The
  12588. // following API are used for manipulation of the async handle
  12589. //
  12590.  
  12591. typedef HANDLE HCRYPTASYNC, *PHCRYPTASYNC;
  12592.  
  12593. typedef VOID (WINAPI *PFN_CRYPT_ASYNC_PARAM_FREE_FUNC) (
  12594.     LPSTR pszParamOid,
  12595.     LPVOID pvParam
  12596.     );
  12597.  
  12598. WINCRYPT32API
  12599. BOOL
  12600. WINAPI
  12601. CryptCreateAsyncHandle (
  12602.     IN DWORD dwFlags,
  12603.     OUT PHCRYPTASYNC phAsync
  12604.     );
  12605.  
  12606. WINCRYPT32API
  12607. BOOL
  12608. WINAPI
  12609. CryptSetAsyncParam (
  12610.     IN HCRYPTASYNC hAsync,
  12611.     IN LPSTR pszParamOid,
  12612.     IN LPVOID pvParam,
  12613.     IN OPTIONAL PFN_CRYPT_ASYNC_PARAM_FREE_FUNC pfnFree
  12614.     );
  12615.  
  12616. WINCRYPT32API
  12617. BOOL
  12618. WINAPI
  12619. CryptGetAsyncParam (
  12620.     IN HCRYPTASYNC hAsync,
  12621.     IN LPSTR pszParamOid,
  12622.     OUT LPVOID* ppvParam,
  12623.     OUT OPTIONAL PFN_CRYPT_ASYNC_PARAM_FREE_FUNC* ppfnFree
  12624.     );
  12625.  
  12626. WINCRYPT32API
  12627. BOOL
  12628. WINAPI
  12629. CryptCloseAsyncHandle (
  12630.     IN HCRYPTASYNC hAsync
  12631.     );
  12632.  
  12633. //
  12634. // Crypt32 Remote Object Retrieval Routines.  This API allows retrieval of
  12635. // remote PKI objects where the location is given by an URL.  The remote
  12636. // object retrieval manager exposes two provider models.  One is the "Scheme
  12637. // Provider" model which allows for installable protocol providers as defined
  12638. // by the URL scheme e.g. ldap, http, ftp.  The scheme provider entry point is
  12639. // the same as the CryptRetrieveObjectByUrl however the *ppvObject returned
  12640. // is ALWAYS a counted array of encoded bits (one per object retrieved).  The
  12641. // second provider model is the "Context Provider" model which allows for
  12642. // installable creators of CAPI2 context handles (objects) based on the
  12643. // retrieved encoded bits.  These are dispatched based on the object OID given
  12644. // in the call to CryptRetrieveObjectByUrl.
  12645. //
  12646.  
  12647. typedef struct _CRYPT_BLOB_ARRAY {
  12648.     DWORD            cBlob;
  12649.     PCRYPT_DATA_BLOB rgBlob;
  12650. } CRYPT_BLOB_ARRAY, *PCRYPT_BLOB_ARRAY;
  12651.  
  12652. typedef struct _CRYPT_CREDENTIALS {
  12653.     DWORD  cbSize;
  12654.     LPCSTR pszCredentialsOid;
  12655.     LPVOID pvCredentials;
  12656. } CRYPT_CREDENTIALS, *PCRYPT_CREDENTIALS;
  12657.  
  12658. #define CREDENTIAL_OID_PASSWORD_CREDENTIALS_A ((LPCSTR)1)
  12659. #define CREDENTIAL_OID_PASSWORD_CREDENTIALS_W ((LPCSTR)2)
  12660.  
  12661. #ifdef UNICODE
  12662. #define CREDENTIAL_OID_PASSWORD_CREDENTIALS CREDENTIAL_OID_PASSWORD_CREDENTIALS_W
  12663. #else
  12664. #define CREDENTIAL_OID_PASSWORD_CREDENTIALS CREDENTIAL_OID_PASSWORD_CREDENTIALS_A
  12665. #endif //UNICODE
  12666.  
  12667. typedef struct _CRYPT_PASSWORD_CREDENTIALSA {
  12668.     DWORD   cbSize;
  12669.     LPSTR   pszUsername;
  12670.     LPSTR   pszPassword;
  12671. } CRYPT_PASSWORD_CREDENTIALSA, *PCRYPT_PASSWORD_CREDENTIALSA;
  12672. typedef struct _CRYPT_PASSWORD_CREDENTIALSW {
  12673.     DWORD   cbSize;
  12674.     LPWSTR  pszUsername;
  12675.     LPWSTR  pszPassword;
  12676. } CRYPT_PASSWORD_CREDENTIALSW, *PCRYPT_PASSWORD_CREDENTIALSW;
  12677. #ifdef UNICODE
  12678. typedef CRYPT_PASSWORD_CREDENTIALSW CRYPT_PASSWORD_CREDENTIALS;
  12679. typedef PCRYPT_PASSWORD_CREDENTIALSW PCRYPT_PASSWORD_CREDENTIALS;
  12680. #else
  12681. typedef CRYPT_PASSWORD_CREDENTIALSA CRYPT_PASSWORD_CREDENTIALS;
  12682. typedef PCRYPT_PASSWORD_CREDENTIALSA PCRYPT_PASSWORD_CREDENTIALS;
  12683. #endif // UNICODE
  12684.  
  12685. //
  12686. // Scheme Provider Signatures
  12687. //
  12688.  
  12689. #define SCHEME_OID_RETRIEVE_ENCODED_OBJECT_FUNC "SchemeDllRetrieveEncodedObject"
  12690.  
  12691. typedef VOID (WINAPI *PFN_FREE_ENCODED_OBJECT_FUNC) (
  12692.     LPCSTR pszObjectOid,
  12693.     PCRYPT_BLOB_ARRAY pObject,
  12694.     LPVOID pvFreeContext
  12695.     );
  12696.  
  12697. //
  12698. // SchemeDllRetrieveEncodedObject has the following signature:
  12699. //
  12700. // BOOL WINAPI SchemeDllRetrieveEncodedObject (
  12701. //                   IN LPCSTR pszUrl,
  12702. //                   IN LPCSTR pszObjectOid,
  12703. //                   IN DWORD dwRetrievalFlags,
  12704. //                   IN DWORD dwTimeout,
  12705. //                   OUT PCRYPT_BLOB_ARRAY pObject,
  12706. //                   OUT PFN_FREE_ENCODED_OBJECT_FUNC* ppfnFreeObject,
  12707. //                   OUT LPVOID* ppvFreeContext,
  12708. //                   IN HCRYPTASYNC hAsyncRetrieve,
  12709. //                   IN PCRYPT_CREDENTIALS pCredentials,
  12710. //                   IN LPVOID pvReserved
  12711. //                   )
  12712. //
  12713.  
  12714. //
  12715. // Context Provider Signatures
  12716. //
  12717.  
  12718. #define CONTEXT_OID_CREATE_OBJECT_CONTEXT_FUNC "ContextDllCreateObjectContext"
  12719.  
  12720. #define CONTEXT_OID_CERTIFICATE ((LPCSTR)1)
  12721. #define CONTEXT_OID_CRL         ((LPCSTR)2)
  12722. #define CONTEXT_OID_CTL         ((LPCSTR)3)
  12723. #define CONTEXT_OID_PKCS7       ((LPCSTR)4)
  12724. #define CONTEXT_OID_CAPI2_ANY   ((LPCSTR)5)
  12725.  
  12726. //
  12727. // ContextDllCreateObjectContext has the following signature:
  12728. //
  12729. // BOOL WINAPI ContextDllCreateObjectContext (
  12730. //                    IN LPCSTR pszObjectOid,
  12731. //                    IN DWORD dwRetrievalFlags,
  12732. //                    IN PCRYPT_BLOB_ARRAY pObject,
  12733. //                    OUT LPVOID* ppvContext
  12734. //                    )
  12735. //
  12736.  
  12737. //
  12738. // Remote Object Retrieval API
  12739. //
  12740.  
  12741. //
  12742. // Retrieval flags
  12743. //
  12744.  
  12745. #define CRYPT_RETRIEVE_MULTIPLE_OBJECTS 0x00000001
  12746. #define CRYPT_CACHE_ONLY_RETRIEVAL      0x00000002
  12747. #define CRYPT_WIRE_ONLY_RETRIEVAL       0x00000004
  12748. #define CRYPT_DONT_CACHE_RESULT         0x00000008
  12749. #define CRYPT_ASYNC_RETRIEVAL           0x00000010
  12750.  
  12751. //
  12752. // Data verification retrieval flags
  12753. //
  12754. // CRYPT_VERIFY_CONTEXT_SIGNATURE is used to get signature verification
  12755. // on the context created.  In this case pszObjectOid must be non-NULL and
  12756. // pvVerify points to the signer certificate context
  12757. //
  12758. // CRYPT_VERIFY_DATA_HASH is used to get verification of the blob data
  12759. // retrieved by the protocol.  The pvVerify points to an URL_DATA_HASH
  12760. // structure (TBD)
  12761. //
  12762.  
  12763. #define CRYPT_VERIFY_CONTEXT_SIGNATURE  0x00000020
  12764. #define CRYPT_VERIFY_DATA_HASH          0x00000040
  12765.  
  12766. //
  12767. // Time Valid Object flags
  12768. //
  12769.  
  12770. #define CRYPT_KEEP_TIME_VALID           0x00000080
  12771. #define CRYPT_DONT_VERIFY_SIGNATURE     0x00000100
  12772. #define CRYPT_DONT_CHECK_TIME_VALIDITY  0x00000200
  12773.  
  12774. WINCRYPT32API
  12775. BOOL
  12776. WINAPI
  12777. CryptRetrieveObjectByUrlA (
  12778.     IN LPCSTR pszUrl,
  12779.     IN LPCSTR pszObjectOid,
  12780.     IN DWORD dwRetrievalFlags,
  12781.     IN DWORD dwTimeout,
  12782.     OUT LPVOID* ppvObject,
  12783.     IN HCRYPTASYNC hAsyncRetrieve,
  12784.     IN OPTIONAL PCRYPT_CREDENTIALS pCredentials,
  12785.     IN OPTIONAL LPVOID pvVerify,
  12786.     IN OPTIONAL LPVOID pvReserved
  12787.     );
  12788. WINCRYPT32API
  12789. BOOL
  12790. WINAPI
  12791. CryptRetrieveObjectByUrlW (
  12792.     IN LPCWSTR pszUrl,
  12793.     IN LPCSTR pszObjectOid,
  12794.     IN DWORD dwRetrievalFlags,
  12795.     IN DWORD dwTimeout,
  12796.     OUT LPVOID* ppvObject,
  12797.     IN HCRYPTASYNC hAsyncRetrieve,
  12798.     IN OPTIONAL PCRYPT_CREDENTIALS pCredentials,
  12799.     IN OPTIONAL LPVOID pvVerify,
  12800.     IN OPTIONAL LPVOID pvReserved
  12801.     );
  12802. #ifdef UNICODE
  12803. #define CryptRetrieveObjectByUrl  CryptRetrieveObjectByUrlW
  12804. #else
  12805. #define CryptRetrieveObjectByUrl  CryptRetrieveObjectByUrlA
  12806. #endif // !UNICODE
  12807.  
  12808.  
  12809. //
  12810. // Call back function to cancel object retrieval
  12811. //
  12812. // The function can be installed on a per thread basis.  
  12813. // If CryptInstallCancelRetrieval is called for multiple times, only the most recent
  12814. // installation will be kept.
  12815. //
  12816. // This is only effective for http, https, gopher, and ftp protocol.  
  12817. // It is ignored by the rest of the protocols.
  12818.  
  12819.  
  12820. typedef BOOL (WINAPI *PFN_CRYPT_CANCEL_RETRIEVAL)(
  12821.     IN DWORD dwFlags,
  12822.     IN void  *pvArg
  12823.     );
  12824.  
  12825.  
  12826. //
  12827. // PFN_CRYPT_CANCEL_RETRIEVAL
  12828. //
  12829. // This function should return FALSE when the object retrieval should be continued
  12830. // and return TRUE when the object retrieval should be cancelled.
  12831. //
  12832.  
  12833. WINCRYPT32API
  12834. BOOL
  12835. WINAPI
  12836. CryptInstallCancelRetrieval(
  12837.     IN PFN_CRYPT_CANCEL_RETRIEVAL pfnCancel, 
  12838.     IN const void *pvArg,
  12839.     IN DWORD dwFlags,
  12840.     IN void *pvReserved
  12841. );
  12842.  
  12843.  
  12844. WINCRYPT32API
  12845. BOOL
  12846. WINAPI
  12847. CryptUninstallCancelRetrieval(
  12848.     IN DWORD dwFlags,
  12849.     IN void  *pvReserved
  12850.     );
  12851.  
  12852.  
  12853. WINCRYPT32API
  12854. BOOL
  12855. WINAPI
  12856. CryptCancelAsyncRetrieval (
  12857.     HCRYPTASYNC hAsyncRetrieval
  12858.     );
  12859.  
  12860. //
  12861. // Remote Object Async Retrieval parameters
  12862. //
  12863.  
  12864. //
  12865. // A client that wants to be notified of asynchronous object retrieval
  12866. // completion sets this parameter on the async handle
  12867. //
  12868.  
  12869. #define CRYPT_PARAM_ASYNC_RETRIEVAL_COMPLETION ((LPCSTR)1)
  12870.  
  12871. typedef VOID (WINAPI *PFN_CRYPT_ASYNC_RETRIEVAL_COMPLETION_FUNC) (
  12872.     IN LPVOID pvCompletion,
  12873.     IN DWORD dwCompletionCode,
  12874.     IN LPCSTR pszUrl,
  12875.     IN LPSTR pszObjectOid,
  12876.     IN LPVOID pvObject
  12877.     );
  12878.  
  12879. typedef struct _CRYPT_ASYNC_RETRIEVAL_COMPLETION {
  12880.     PFN_CRYPT_ASYNC_RETRIEVAL_COMPLETION_FUNC pfnCompletion;
  12881.     LPVOID pvCompletion;
  12882. } CRYPT_ASYNC_RETRIEVAL_COMPLETION, *PCRYPT_ASYNC_RETRIEVAL_COMPLETION;
  12883.  
  12884. //
  12885. // This function is set on the async handle by a scheme provider that
  12886. // supports asynchronous retrieval
  12887. //
  12888.  
  12889. #define CRYPT_PARAM_CANCEL_ASYNC_RETRIEVAL ((LPCSTR)2)
  12890.  
  12891. typedef BOOL (WINAPI *PFN_CANCEL_ASYNC_RETRIEVAL_FUNC) (
  12892.     HCRYPTASYNC hAsyncRetrieve
  12893.     );
  12894.  
  12895. //
  12896. // Get the locator for a CAPI object
  12897. //
  12898.  
  12899. #define CRYPT_GET_URL_FROM_PROPERTY         0x00000001
  12900. #define CRYPT_GET_URL_FROM_EXTENSION        0x00000002
  12901. #define CRYPT_GET_URL_FROM_UNAUTH_ATTRIBUTE 0x00000004
  12902. #define CRYPT_GET_URL_FROM_AUTH_ATTRIBUTE   0x00000008
  12903.  
  12904. typedef struct _CRYPT_URL_ARRAY {
  12905.     DWORD   cUrl;
  12906.     LPWSTR* rgwszUrl;
  12907. } CRYPT_URL_ARRAY, *PCRYPT_URL_ARRAY;
  12908.  
  12909. typedef struct _CRYPT_URL_INFO {
  12910.     DWORD cbSize;
  12911. } CRYPT_URL_INFO, *PCRYPT_URL_INFO;
  12912.  
  12913. WINCRYPT32API
  12914. BOOL
  12915. WINAPI
  12916. CryptGetObjectUrl (
  12917.     IN LPCSTR pszUrlOid,
  12918.     IN LPVOID pvPara,
  12919.     IN DWORD dwFlags,
  12920.     OUT OPTIONAL PCRYPT_URL_ARRAY pUrlArray,
  12921.     IN OUT DWORD* pcbUrlArray,
  12922.     OUT OPTIONAL PCRYPT_URL_INFO pUrlInfo,
  12923.     IN OUT OPTIONAL DWORD* pcbUrlInfo,
  12924.     IN OPTIONAL LPVOID pvReserved
  12925.     );
  12926.  
  12927. #define URL_OID_GET_OBJECT_URL_FUNC "UrlDllGetObjectUrl"
  12928.  
  12929. //
  12930. // UrlDllGetObjectUrl has the same signature as CryptGetObjectUrl
  12931. //
  12932.  
  12933. //
  12934. // URL_OID_CERTIFICATE_ISSUER
  12935. //
  12936. // pvPara == PCCERT_CONTEXT, certificate whose issuer's URL is being requested
  12937. //
  12938. // This will be retrieved from the authority info access extension or property
  12939. // on the certificate
  12940. //
  12941. // URL_OID_CERTIFICATE_CRL_DIST_POINT
  12942. //
  12943. // pvPara == PCCERT_CONTEXT, certificate whose CRL distribution point is being
  12944. // requested
  12945. //
  12946. // This will be retrieved from the CRL distribution point extension or property
  12947. // on the certificate
  12948. //
  12949. // URL_OID_CTL_ISSUER
  12950. //
  12951. // pvPara == PCCTL_CONTEXT, Signer Index, CTL whose issuer's URL (identified
  12952. // by the signer index) is being requested
  12953. //
  12954. // This will be retrieved from an authority info access attribute method encoded
  12955. // in each signer info in the PKCS7 (CTL)
  12956. //
  12957. // URL_OID_CTL_NEXT_UPDATE
  12958. //
  12959. // pvPara == PCCTL_CONTEXT, Signer Index, CTL whose next update URL is being
  12960. // requested and an optional signer index in case we need to check signer
  12961. // info attributes
  12962. //
  12963. // This will be retrieved from an authority info access CTL extension, property,
  12964. // or signer info attribute method
  12965. //
  12966. // URL_OID_CRL_ISSUER
  12967. //
  12968. // pvPara == PCCRL_CONTEXT, CRL whose issuer's URL is being requested
  12969. //
  12970. // This will be retrieved from a property on the CRL which has been inherited
  12971. // from the subject cert (either from the subject cert issuer or the subject
  12972. // cert distribution point extension).  It will be encoded as an authority
  12973. // info access extension method.
  12974. //
  12975.  
  12976. #define URL_OID_CERTIFICATE_ISSUER         ((LPCSTR)1)
  12977. #define URL_OID_CERTIFICATE_CRL_DIST_POINT ((LPCSTR)2)
  12978. #define URL_OID_CTL_ISSUER                 ((LPCSTR)3)
  12979. #define URL_OID_CTL_NEXT_UPDATE            ((LPCSTR)4)
  12980. #define URL_OID_CRL_ISSUER                 ((LPCSTR)5)
  12981.  
  12982. //
  12983. // Get a time valid CAPI2 object
  12984. //
  12985.  
  12986. WINCRYPT32API
  12987. BOOL
  12988. WINAPI
  12989. CryptGetTimeValidObject (
  12990.     IN LPCSTR pszTimeValidOid,
  12991.     IN LPVOID pvPara,
  12992.     IN PCCERT_CONTEXT pIssuer,
  12993.     IN OPTIONAL LPFILETIME pftValidFor,
  12994.     IN DWORD dwFlags,
  12995.     IN DWORD dwTimeout,
  12996.     OUT OPTIONAL LPVOID* ppvObject,
  12997.     IN OPTIONAL PCRYPT_CREDENTIALS pCredentials,
  12998.     IN OPTIONAL LPVOID pvReserved
  12999.     );
  13000.  
  13001. #define TIME_VALID_OID_GET_OBJECT_FUNC "TimeValidDllGetObject"
  13002.  
  13003. //
  13004. // TimeValidDllGetObject has the same signature as CryptGetTimeValidObject
  13005. //
  13006.  
  13007. //
  13008. // TIME_VALID_OID_GET_CTL
  13009. //
  13010. // pvPara == PCCTL_CONTEXT, the current CTL
  13011. //
  13012. // TIME_VALID_OID_GET_CRL
  13013. //
  13014. // pvPara == PCCRL_CONTEXT, the current CRL
  13015. //
  13016. // TIME_VALID_OID_GET_CRL_FROM_CERT
  13017. //
  13018. // pvPara == PCCERT_CONTEXT, the subject cert
  13019. //
  13020.  
  13021. #define TIME_VALID_OID_GET_CTL           ((LPCSTR)1)
  13022. #define TIME_VALID_OID_GET_CRL           ((LPCSTR)2)
  13023. #define TIME_VALID_OID_GET_CRL_FROM_CERT ((LPCSTR)3)
  13024.  
  13025. WINCRYPT32API
  13026. BOOL
  13027. WINAPI
  13028. CryptFlushTimeValidObject (
  13029.      IN LPCSTR pszFlushTimeValidOid,
  13030.      IN LPVOID pvPara,
  13031.      IN PCCERT_CONTEXT pIssuer,
  13032.      IN DWORD dwFlags,
  13033.      IN LPVOID pvReserved
  13034.      );
  13035.  
  13036. #define TIME_VALID_OID_FLUSH_OBJECT_FUNC "TimeValidDllFlushObject"
  13037.  
  13038. //
  13039. // TimeValidDllFlushObject has the same signature as CryptFlushTimeValidObject
  13040. //
  13041.  
  13042. //
  13043. // TIME_VALID_OID_FLUSH_CTL
  13044. //
  13045. // pvPara == PCCTL_CONTEXT, the CTL to flush
  13046. //
  13047. // TIME_VALID_OID_FLUSH_CRL
  13048. //
  13049. // pvPara == PCCRL_CONTEXT, the CRL to flush
  13050. //
  13051. // TIME_VALID_OID_FLUSH_CRL_FROM_CERT
  13052. //
  13053.  
  13054. #define TIME_VALID_OID_FLUSH_CTL           ((LPCSTR)1)
  13055. #define TIME_VALID_OID_FLUSH_CRL           ((LPCSTR)2)
  13056. #define TIME_VALID_OID_FLUSH_CRL_FROM_CERT ((LPCSTR)3)
  13057.  
  13058. //-------------------------------------------------------------------------
  13059. // Data Protection APIs
  13060. //-------------------------------------------------------------------------
  13061.  
  13062. //
  13063. // Data protection APIs enable applications to easily secure data.
  13064. //
  13065. // The base provider provides protection based on the users' logon
  13066. // credentials. The data secured with these APIs follow the same
  13067. // roaming characteristics as HKCU -- if HKCU roams, the data
  13068. // protected by the base provider may roam as well. This makes
  13069. // the API ideal for the munging of data stored in the registry.
  13070. //
  13071.  
  13072. //
  13073. // Prompt struct -- what to tell users about the access
  13074. //
  13075. typedef struct  _CRYPTPROTECT_PROMPTSTRUCT
  13076. {
  13077.     DWORD cbSize;
  13078.     DWORD dwPromptFlags;
  13079.     HWND  hwndApp;
  13080.     LPCWSTR szPrompt;
  13081. } CRYPTPROTECT_PROMPTSTRUCT, *PCRYPTPROTECT_PROMPTSTRUCT;
  13082.  
  13083.  
  13084. //
  13085. // base provider action
  13086. //
  13087. #define CRYPTPROTECT_DEFAULT_PROVIDER   { 0xdf9d8cd0, 0x1501, 0x11d1, {0x8c, 0x7a, 0x00, 0xc0, 0x4f, 0xc2, 0x97, 0xeb} }
  13088.  
  13089. //
  13090. // CryptProtect PromptStruct dwPromtFlags
  13091. //
  13092. //
  13093. // prompt on unprotect
  13094. #define CRYPTPROTECT_PROMPT_ON_UNPROTECT     0x1  // 1<<0
  13095. //
  13096. // prompt on protect
  13097. #define CRYPTPROTECT_PROMPT_ON_PROTECT       0x2  // 1<<1
  13098. #define CRYPTPROTECT_PROMPT_RESERVED         0x04 // reserved, do not use.
  13099.  
  13100. //
  13101. // only allow strong variant UI protection (user supplied password currently).
  13102. #define CRYPTPROTECT_PROMPT_STRONG         0x08 // 1<<3
  13103.  
  13104. //
  13105. // CryptProtectData and CryptUnprotectData dwFlags
  13106. //
  13107. // for remote-access situations where ui is not an option
  13108. // if UI was specified on protect or unprotect operation, the call
  13109. // will fail and GetLastError() will indicate ERROR_PASSWORD_RESTRICTION
  13110. #define CRYPTPROTECT_UI_FORBIDDEN        0x1
  13111.  
  13112. //
  13113. // per machine protected data -- any user on machine where CryptProtectData
  13114. // took place may CryptUnprotectData
  13115. #define CRYPTPROTECT_LOCAL_MACHINE       0x4
  13116.  
  13117. //
  13118. // force credential synchronize during CryptProtectData()
  13119. // Synchronize is only operation that occurs during this operation
  13120. #define CRYPTPROTECT_CRED_SYNC           0x8
  13121.  
  13122. // flags reserved for system use
  13123. #define CRYPTPROTECT_FIRST_RESERVED_FLAGVAL    0x0FFFFFFF
  13124. #define CRYPTPROTECT_LAST_RESERVED_FLAGVAL     0xFFFFFFFF
  13125.  
  13126. //
  13127. // flags specific to base provider
  13128. //
  13129.  
  13130.  
  13131. WINCRYPT32API
  13132. BOOL
  13133. WINAPI
  13134. CryptProtectData(
  13135.     IN              DATA_BLOB*      pDataIn,
  13136.     IN              LPCWSTR         szDataDescr,
  13137.     IN OPTIONAL     DATA_BLOB*      pOptionalEntropy,
  13138.     IN              PVOID           pvReserved,
  13139.     IN OPTIONAL     CRYPTPROTECT_PROMPTSTRUCT*  pPromptStruct,
  13140.     IN              DWORD           dwFlags,
  13141.     OUT             DATA_BLOB*      pDataOut            // out encr blob
  13142.     );
  13143.  
  13144. WINCRYPT32API
  13145. BOOL
  13146. WINAPI
  13147. CryptUnprotectData(
  13148.     IN              DATA_BLOB*      pDataIn,             // in encr blob
  13149.     OUT OPTIONAL    LPWSTR*         ppszDataDescr,       // out
  13150.     IN OPTIONAL     DATA_BLOB*      pOptionalEntropy,
  13151.     IN              PVOID           pvReserved,
  13152.     IN OPTIONAL     CRYPTPROTECT_PROMPTSTRUCT*  pPromptStruct,
  13153.     IN              DWORD           dwFlags,
  13154.     OUT             DATA_BLOB*      pDataOut
  13155.     );
  13156.  
  13157. //+=========================================================================
  13158. //  Helper functions to build certificates
  13159. //==========================================================================
  13160.  
  13161. //+-------------------------------------------------------------------------
  13162. //
  13163. // Builds a self-signed certificate and returns a PCCERT_CONTEXT representing
  13164. // the certificate. A hProv must be specified to build the cert context.
  13165. //
  13166. // pSubjectIssuerBlob is the DN for the certifcate. If an alternate subject
  13167. // name is desired it must be specified as an extension in the pExtensions
  13168. // parameter. pSubjectIssuerBlob can NOT be NULL, so minimually an empty DN
  13169. // must be specified.
  13170. //
  13171. // By default:
  13172. // pKeyProvInfo - The CSP is queried for the KeyProvInfo parameters. Only the Provider,
  13173. // Provider Type and Container is queried. Many CSPs don't support these
  13174. // queries and will cause a failure. In such cases the pKeyProvInfo
  13175. // must be specified (RSA BASE works fine).
  13176. //
  13177. // pSignatureAlgorithm - will default to SHA1RSA
  13178. // pStartTime will default to the current time
  13179. // pEndTime will default to 1 year
  13180. // pEntensions will be empty.
  13181. //
  13182. // The returned PCCERT_CONTEXT will reference the private keys by setting the
  13183. // CERT_KEY_PROV_INFO_PROP_ID. However, if this property is not desired specify the
  13184. // CERT_CREATE_SELFSIGN_NO_KEY_INFO in dwFlags.
  13185. //
  13186. // If the cert being built is only a dummy placeholder cert for speed it may not
  13187. // need to be signed. Signing of the cert is skipped if CERT_CREATE_SELFSIGN_NO_SIGN
  13188. // is specified in dwFlags.
  13189. //
  13190. //--------------------------------------------------------------------------
  13191. WINCRYPT32API
  13192. PCCERT_CONTEXT
  13193. WINAPI
  13194. CertCreateSelfSignCertificate(
  13195.     IN          HCRYPTPROV                  hProv,
  13196.     IN          PCERT_NAME_BLOB             pSubjectIssuerBlob,
  13197.     IN          DWORD                       dwFlags,
  13198.     OPTIONAL    PCRYPT_KEY_PROV_INFO        pKeyProvInfo,
  13199.     OPTIONAL    PCRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm,
  13200.     OPTIONAL    PSYSTEMTIME                 pStartTime,
  13201.     OPTIONAL    PSYSTEMTIME                 pEndTime,
  13202.     OPTIONAL    PCERT_EXTENSIONS            pExtensions
  13203.     );
  13204.  
  13205. #define CERT_CREATE_SELFSIGN_NO_SIGN    1
  13206. #define CERT_CREATE_SELFSIGN_NO_KEY_INFO 2
  13207.  
  13208. //+=========================================================================
  13209. //  Key Identifier Property Data Structures and APIs
  13210. //==========================================================================
  13211.  
  13212. //+-------------------------------------------------------------------------
  13213. //  Get the property for the specified Key Identifier.
  13214. //
  13215. //  The Key Identifier is the SHA1 hash of the encoded CERT_PUBLIC_KEY_INFO.
  13216. //  The Key Identifier for a certificate can be obtained by getting the
  13217. //  certificate's CERT_KEY_IDENTIFIER_PROP_ID. The
  13218. //  CryptCreateKeyIdentifierFromCSP API can be called to create the Key
  13219. //  Identifier from a CSP Public Key Blob.
  13220. //
  13221. //  A Key Identifier can have the same properties as a certificate context.
  13222. //  CERT_KEY_PROV_INFO_PROP_ID is the property of most interest.
  13223. //  For CERT_KEY_PROV_INFO_PROP_ID, pvData points to a CRYPT_KEY_PROV_INFO
  13224. //  structure. Elements pointed to by fields in the pvData structure follow the
  13225. //  structure. Therefore, *pcbData will exceed the size of the structure.
  13226. //
  13227. //  If CRYPT_KEYID_ALLOC_FLAG is set, then, *pvData is updated with a
  13228. //  pointer to allocated memory. LocalFree() must be called to free the
  13229. //  allocated memory.
  13230. //
  13231. //  By default, searches the CurrentUser's list of Key Identifiers.
  13232. //  CRYPT_KEYID_MACHINE_FLAG can be set to search the LocalMachine's list
  13233. //  of Key Identifiers. When CRYPT_KEYID_MACHINE_FLAG is set, pwszComputerName
  13234. //  can also be set to specify the name of a remote computer to be searched
  13235. //  instead of the local machine.
  13236. //--------------------------------------------------------------------------
  13237. WINCRYPT32API
  13238. BOOL
  13239. WINAPI
  13240. CryptGetKeyIdentifierProperty(
  13241.     IN const CRYPT_HASH_BLOB *pKeyIdentifier,
  13242.     IN DWORD dwPropId,
  13243.     IN DWORD dwFlags,
  13244.     IN OPTIONAL LPCWSTR pwszComputerName,
  13245.     IN OPTIONAL void *pvReserved,
  13246.     OUT void *pvData,
  13247.     IN OUT DWORD *pcbData
  13248.     );
  13249.  
  13250. // When the following flag is set, searches the LocalMachine instead of the
  13251. // CurrentUser. This flag is applicable to all the KeyIdentifierProperty APIs.
  13252. #define CRYPT_KEYID_MACHINE_FLAG        0x00000020
  13253.  
  13254. // When the following flag is set, *pvData is updated with a pointer to
  13255. // allocated memory. LocalFree() must be called to free the allocated memory.
  13256. #define CRYPT_KEYID_ALLOC_FLAG          0x00008000
  13257.  
  13258.  
  13259. //+-------------------------------------------------------------------------
  13260. //  Set the property for the specified Key Identifier.
  13261. //
  13262. //  For CERT_KEY_PROV_INFO_PROP_ID pvData points to the
  13263. //  CRYPT_KEY_PROV_INFO data structure. For all other properties, pvData
  13264. //  points to a CRYPT_DATA_BLOB.
  13265. //
  13266. //  Setting pvData == NULL, deletes the property.
  13267. //
  13268. //  Set CRYPT_KEYID_MACHINE_FLAG to set the property for a LocalMachine
  13269. //  Key Identifier. Set pwszComputerName, to select a remote computer.
  13270. //
  13271. //  If CRYPT_KEYID_DELETE_FLAG is set, the Key Identifier and all its
  13272. //  properties is deleted.
  13273. //
  13274. //  If CRYPT_KEYID_SET_NEW_FLAG is set, the set fails if the property already
  13275. //  exists. For an existing property, FALSE is returned with LastError set to
  13276. //  CRYPT_E_EXISTS.
  13277. //--------------------------------------------------------------------------
  13278. WINCRYPT32API
  13279. BOOL
  13280. WINAPI
  13281. CryptSetKeyIdentifierProperty(
  13282.     IN const CRYPT_HASH_BLOB *pKeyIdentifier,
  13283.     IN DWORD dwPropId,
  13284.     IN DWORD dwFlags,
  13285.     IN OPTIONAL LPCWSTR pwszComputerName,
  13286.     IN OPTIONAL void *pvReserved,
  13287.     IN const void *pvData
  13288.     );
  13289.  
  13290. // When the following flag is set, the Key Identifier and all its properties
  13291. // are deleted.
  13292. #define CRYPT_KEYID_DELETE_FLAG         0x00000010
  13293.  
  13294. // When the following flag is set, the set fails if the property already
  13295. // exists.
  13296. #define CRYPT_KEYID_SET_NEW_FLAG        0x00002000
  13297.  
  13298.  
  13299. //+-------------------------------------------------------------------------
  13300. //  For CERT_KEY_PROV_INFO_PROP_ID, rgppvData[] points to a
  13301. //  CRYPT_KEY_PROV_INFO.
  13302. //
  13303. //  Return FALSE to stop the enumeration.
  13304. //--------------------------------------------------------------------------
  13305. typedef BOOL (WINAPI *PFN_CRYPT_ENUM_KEYID_PROP)(
  13306.     IN const CRYPT_HASH_BLOB *pKeyIdentifier,
  13307.     IN DWORD dwFlags,
  13308.     IN void *pvReserved,
  13309.     IN void *pvArg,
  13310.     IN DWORD cProp,
  13311.     IN DWORD *rgdwPropId,
  13312.     IN void **rgpvData,
  13313.     IN DWORD *rgcbData
  13314.     );
  13315.  
  13316. //+-------------------------------------------------------------------------
  13317. //  Enumerate the Key Identifiers.
  13318. //
  13319. //  If pKeyIdentifier is NULL, enumerates all Key Identifers. Otherwise,
  13320. //  calls the callback for the specified KeyIdentifier. If dwPropId is
  13321. //  0, calls the callback with all the properties. Otherwise, only calls
  13322. //  the callback with the specified property (cProp = 1).
  13323. //  Furthermore, when dwPropId is specified, skips KeyIdentifiers not
  13324. //  having the property.
  13325. //
  13326. //  Set CRYPT_KEYID_MACHINE_FLAG to enumerate the LocalMachine
  13327. //  Key Identifiers. Set pwszComputerName, to enumerate Key Identifiers on
  13328. //  a remote computer.
  13329. //--------------------------------------------------------------------------
  13330. WINCRYPT32API
  13331. BOOL
  13332. WINAPI
  13333. CryptEnumKeyIdentifierProperties(
  13334.     IN OPTIONAL const CRYPT_HASH_BLOB *pKeyIdentifier,
  13335.     IN DWORD dwPropId,
  13336.     IN DWORD dwFlags,
  13337.     IN OPTIONAL LPCWSTR pwszComputerName,
  13338.     IN OPTIONAL void *pvReserved,
  13339.     IN OPTIONAL void *pvArg,
  13340.     IN PFN_CRYPT_ENUM_KEYID_PROP pfnEnum
  13341.     );
  13342.  
  13343. //+-------------------------------------------------------------------------
  13344. //  Create a KeyIdentifier from the CSP Public Key Blob.
  13345. //
  13346. //  Converts the CSP PUBLICKEYSTRUC into a X.509 CERT_PUBLIC_KEY_INFO and
  13347. //  encodes. The encoded CERT_PUBLIC_KEY_INFO is SHA1 hashed to obtain
  13348. //  the Key Identifier.
  13349. //
  13350. //  By default, the pPubKeyStruc->aiKeyAlg is used to find the appropriate
  13351. //  public key Object Identifier. pszPubKeyOID can be set to override
  13352. //  the default OID obtained from the aiKeyAlg.
  13353. //--------------------------------------------------------------------------
  13354. WINCRYPT32API
  13355. BOOL
  13356. WINAPI
  13357. CryptCreateKeyIdentifierFromCSP(
  13358.     IN DWORD dwCertEncodingType,
  13359.     IN OPTIONAL LPCSTR pszPubKeyOID,
  13360.     IN const PUBLICKEYSTRUC *pPubKeyStruc,
  13361.     IN DWORD cbPubKeyStruc,
  13362.     IN DWORD dwFlags,
  13363.     IN OPTIONAL void *pvReserved,
  13364.     OUT BYTE *pbHash,
  13365.     IN OUT DWORD *pcbHash
  13366.     );
  13367.  
  13368.  
  13369. //+=========================================================================
  13370. //  Certificate Chaining Infrastructure
  13371. //==========================================================================
  13372.  
  13373. //
  13374. // The chain engine defines the store namespace and cache partitioning for
  13375. // the Certificate Chaining infrastructure.  A default chain engine
  13376. // is defined for the process which uses all default system stores e.g.
  13377. // Root, CA, Trust, for chain building and caching.  If an application
  13378. // wishes to define its own store namespace or have its own partitioned
  13379. // cache then it can create its own chain engine.  It is advisable to create
  13380. // a chain engine at application startup and use it throughout the lifetime
  13381. // of the application in order to get optimal caching behavior
  13382. //
  13383.  
  13384. typedef HANDLE HCERTCHAINENGINE;
  13385.  
  13386. #define HCCE_CURRENT_USER  ((HCERTCHAINENGINE)NULL)
  13387. #define HCCE_LOCAL_MACHINE ((HCERTCHAINENGINE)0x1)
  13388.  
  13389. //
  13390. // Create a certificate chain engine.
  13391. //
  13392.  
  13393. //
  13394. // Configuration parameters for the certificate chain engine
  13395. //
  13396. //      hRestrictedRoot - restrict the root store (must be a subset of "Root")
  13397. //
  13398. //      hRestrictedTrust - restrict the store for CTLs
  13399. //
  13400. //      hRestrictedOther - restrict the store for certs and CRLs
  13401. //
  13402. //      cAdditionalStore, rghAdditionalStore - additional stores
  13403. //
  13404. //      NOTE: The algorithm used to define the stores for the engine is as
  13405. //            follows:
  13406. //
  13407. //            hRoot = hRestrictedRoot or System Store "Root"
  13408. //
  13409. //            hTrust = hRestrictedTrust or hWorld (defined later)
  13410. //
  13411. //            hOther = hRestrictedOther or (hRestrictedTrust == NULL) ? hWorld :
  13412. //                     hRestrictedTrust + hWorld
  13413. //
  13414. //            hWorld = hRoot + "CA" + "My" + "Trust" + rghAdditionalStore
  13415. //
  13416. //      dwFlags  - flags
  13417. //
  13418. //          CERT_CHAIN_CACHE_END_CERT - information will be cached on
  13419. //                                      the end cert as well as the other
  13420. //                                      certs in the chain
  13421. //
  13422. //          CERT_CHAIN_THREAD_STORE_SYNC - use separate thread for store syncs
  13423. //                                         and related cache updates
  13424. //
  13425. //          CERT_CHAIN_CACHE_ONLY_URL_RETRIEVAL - don't hit the wire to get
  13426. //                                                URL based objects
  13427. //
  13428. //      dwUrlRetrievalTimeout - timeout for wire based URL object retrievals
  13429. //
  13430.  
  13431. #define CERT_CHAIN_CACHE_END_CERT           0x00000001
  13432. #define CERT_CHAIN_THREAD_STORE_SYNC        0x00000002
  13433. #define CERT_CHAIN_CACHE_ONLY_URL_RETRIEVAL 0x00000004
  13434. #define CERT_CHAIN_USE_LOCAL_MACHINE_STORE  0x00000008
  13435. #define CERT_CHAIN_ENABLE_CACHE_AUTO_UPDATE 0x00000010
  13436.  
  13437. typedef struct _CERT_CHAIN_ENGINE_CONFIG {
  13438.  
  13439.     DWORD       cbSize;
  13440.     HCERTSTORE  hRestrictedRoot;
  13441.     HCERTSTORE  hRestrictedTrust;
  13442.     HCERTSTORE  hRestrictedOther;
  13443.     DWORD       cAdditionalStore;
  13444.     HCERTSTORE* rghAdditionalStore;
  13445.     DWORD       dwFlags;
  13446.     DWORD       dwUrlRetrievalTimeout;
  13447.     DWORD       MaximumCachedCertificates;
  13448.     DWORD       CycleDetectionModulus;
  13449.  
  13450. } CERT_CHAIN_ENGINE_CONFIG, *PCERT_CHAIN_ENGINE_CONFIG;
  13451.  
  13452. WINCRYPT32API
  13453. BOOL
  13454. WINAPI
  13455. CertCreateCertificateChainEngine (
  13456.     IN PCERT_CHAIN_ENGINE_CONFIG pConfig,
  13457.     OUT HCERTCHAINENGINE* phChainEngine
  13458.     );
  13459.  
  13460. //
  13461. // Free a certificate trust engine
  13462. //
  13463.  
  13464. WINCRYPT32API
  13465. VOID
  13466. WINAPI
  13467. CertFreeCertificateChainEngine (
  13468.     IN HCERTCHAINENGINE hChainEngine
  13469.     );
  13470.  
  13471. //
  13472. // Resync the certificate chain engine.  This resync's the stores backing
  13473. // the engine and updates the engine caches.
  13474. //
  13475.  
  13476. WINCRYPT32API
  13477. BOOL
  13478. WINAPI
  13479. CertResyncCertificateChainEngine (
  13480.     IN HCERTCHAINENGINE hChainEngine
  13481.     );
  13482.  
  13483. //
  13484. // When an application requests a certificate chain, the data structure
  13485. // returned is in the form of a CERT_CHAIN_CONTEXT.  This contains
  13486. // an array of CERT_SIMPLE_CHAIN where each simple chain goes from
  13487. // an end cert to a self signed cert and the chain context connects simple
  13488. // chains via trust lists.  Each simple chain contains the chain of
  13489. // certificates, summary trust information about the chain and trust information
  13490. // about each certificate element in the chain.
  13491. //
  13492.  
  13493. //
  13494. // Trust status bits
  13495. //
  13496.  
  13497. typedef struct _CERT_TRUST_STATUS {
  13498.  
  13499.     DWORD dwErrorStatus;
  13500.     DWORD dwInfoStatus;
  13501.  
  13502. } CERT_TRUST_STATUS, *PCERT_TRUST_STATUS;
  13503.  
  13504. //
  13505. // The following are error status bits
  13506. //
  13507.  
  13508. // These can be applied to certificates and chains
  13509.  
  13510. #define CERT_TRUST_NO_ERROR                   0x00000000
  13511. #define CERT_TRUST_IS_NOT_TIME_VALID          0x00000001
  13512. #define CERT_TRUST_IS_NOT_TIME_NESTED         0x00000002
  13513. #define CERT_TRUST_IS_REVOKED                 0x00000004
  13514. #define CERT_TRUST_IS_NOT_SIGNATURE_VALID     0x00000008
  13515. #define CERT_TRUST_IS_NOT_VALID_FOR_USAGE     0x00000010
  13516. #define CERT_TRUST_IS_UNTRUSTED_ROOT          0x00000020
  13517. #define CERT_TRUST_REVOCATION_STATUS_UNKNOWN  0x00000040
  13518. #define CERT_TRUST_IS_CYCLIC                  0x00000080
  13519.  
  13520. // These can be applied to chains only
  13521.  
  13522. #define CERT_TRUST_IS_PARTIAL_CHAIN           0x00010000
  13523. #define CERT_TRUST_CTL_IS_NOT_TIME_VALID      0x00020000
  13524. #define CERT_TRUST_CTL_IS_NOT_SIGNATURE_VALID 0x00040000
  13525. #define CERT_TRUST_CTL_IS_NOT_VALID_FOR_USAGE 0x00080000
  13526.  
  13527. //
  13528. // The following are info status bits
  13529. //
  13530.  
  13531. // These can be applied to certificates only
  13532.  
  13533. #define CERT_TRUST_HAS_EXACT_MATCH_ISSUER     0x00000001
  13534. #define CERT_TRUST_HAS_KEY_MATCH_ISSUER       0x00000002
  13535. #define CERT_TRUST_HAS_NAME_MATCH_ISSUER      0x00000004
  13536. #define CERT_TRUST_IS_SELF_SIGNED             0x00000008
  13537.  
  13538. // These can be applied to chains only
  13539.  
  13540. #define CERT_TRUST_IS_COMPLEX_CHAIN           0x00010000
  13541.  
  13542. //
  13543. // Each certificate context in a simple chain has a corresponding chain element
  13544. // in the simple chain context
  13545. //
  13546. // dwErrorStatus has CERT_TRUST_IS_REVOKED, pRevocationInfo set
  13547. // dwErrorStatus has CERT_TRUST_REVOCATION_STATUS_UNKNOWN, pRevocationInfo set
  13548.  
  13549. //
  13550. // BUGBUG: Note that the post processing revocation supported in the first
  13551. //         version only sets cbSize and dwRevocationResult.  Everything else
  13552. //         is NULL
  13553. //
  13554.  
  13555. //
  13556. // Revocation Information
  13557. //
  13558.  
  13559. typedef struct _CERT_REVOCATION_INFO {
  13560.  
  13561.     DWORD  cbSize;
  13562.     DWORD  dwRevocationResult;
  13563.     LPCSTR pszRevocationOid;
  13564.     LPVOID pvOidSpecificInfo;
  13565.  
  13566. } CERT_REVOCATION_INFO, *PCERT_REVOCATION_INFO;
  13567.  
  13568. //
  13569. // Trust List Information
  13570. //
  13571.  
  13572. typedef struct _CERT_TRUST_LIST_INFO {
  13573.  
  13574.     DWORD         cbSize;
  13575.     PCTL_ENTRY    pCtlEntry;
  13576.     PCCTL_CONTEXT pCtlContext;
  13577.  
  13578. } CERT_TRUST_LIST_INFO, *PCERT_TRUST_LIST_INFO;
  13579.  
  13580. //
  13581. // Chain Element
  13582. //
  13583.  
  13584. typedef struct _CERT_CHAIN_ELEMENT {
  13585.  
  13586.     DWORD                 cbSize;
  13587.     PCCERT_CONTEXT        pCertContext;
  13588.     CERT_TRUST_STATUS     TrustStatus;
  13589.     PCERT_REVOCATION_INFO pRevocationInfo;
  13590.  
  13591. } CERT_CHAIN_ELEMENT, *PCERT_CHAIN_ELEMENT;
  13592.  
  13593. //
  13594. // The simple chain is an array of chain elements and a summary trust status
  13595. // for the chain
  13596. //
  13597. // rgpElements[0] is the end certificate chain element
  13598. //
  13599. // rgpElements[cElement-1] is the self-signed "root" certificate chain element
  13600. //
  13601.  
  13602. typedef struct _CERT_SIMPLE_CHAIN {
  13603.  
  13604.     DWORD                 cbSize;
  13605.     CERT_TRUST_STATUS     TrustStatus;
  13606.     DWORD                 cElement;
  13607.     PCERT_CHAIN_ELEMENT*  rgpElement;
  13608.     PCERT_TRUST_LIST_INFO pTrustListInfo;
  13609.  
  13610. } CERT_SIMPLE_CHAIN, *PCERT_SIMPLE_CHAIN;
  13611.  
  13612. //
  13613. // And the chain context contains an array of simple chains and summary trust
  13614. // status for all the connected simple chains
  13615. //
  13616. // rgpChains[0] is the end certificate simple chain
  13617. //
  13618. // rgpChains[cChain-1] is the final (possibly trust list signer) chain which
  13619. // ends in a certificate which is contained in the root store
  13620. //
  13621.  
  13622. typedef struct _CERT_CHAIN_CONTEXT {
  13623.  
  13624.     DWORD               cbSize;
  13625.     CERT_TRUST_STATUS   TrustStatus;
  13626.     DWORD               cChain;
  13627.     PCERT_SIMPLE_CHAIN* rgpChain;
  13628.  
  13629. } CERT_CHAIN_CONTEXT, *PCERT_CHAIN_CONTEXT;
  13630.  
  13631. typedef const CERT_CHAIN_CONTEXT *PCCERT_CHAIN_CONTEXT;
  13632.  
  13633. //
  13634. // When building a chain, the there are various parameters used for finding
  13635. // issuing certificates and trust lists.  They are identified in the
  13636. // following structure
  13637. //
  13638.  
  13639. // Default usage match type is AND with value zero
  13640. #define USAGE_MATCH_TYPE_AND 0x00000000
  13641. #define USAGE_MATCH_TYPE_OR  0x00000001
  13642.  
  13643. typedef struct _CERT_USAGE_MATCH {
  13644.  
  13645.     DWORD             dwType;
  13646.     CERT_ENHKEY_USAGE Usage;
  13647.  
  13648. } CERT_USAGE_MATCH, *PCERT_USAGE_MATCH;
  13649.  
  13650. typedef struct _CTL_USAGE_MATCH {
  13651.  
  13652.     DWORD     dwType;
  13653.     CTL_USAGE Usage;
  13654.  
  13655. } CTL_USAGE_MATCH, *PCTL_USAGE_MATCH;
  13656.  
  13657. typedef struct _CERT_CHAIN_PARA {
  13658.  
  13659.     DWORD            cbSize;
  13660.     CERT_USAGE_MATCH RequestedUsage;
  13661.  
  13662. } CERT_CHAIN_PARA, *PCERT_CHAIN_PARA;
  13663.  
  13664. //
  13665. // The following API is used for retrieving certificate chains
  13666. //
  13667. // Parameters:
  13668. //
  13669. //      hChainEngine     - the chain engine (namespace and cache) to use, NULL
  13670. //                         mean use the default chain engine
  13671. //
  13672. //      pCertContext     - the context we are retrieving the chain for, it
  13673. //                         will be the zero index element in the chain
  13674. //
  13675. //      pTime            - the point in time that we want the chain validated
  13676. //                         for.  Note that the time does not affect trust list,
  13677. //                         revocation, or root store checking.  NULL means use
  13678. //                         the current system time
  13679. //
  13680. //      hAdditionalStore - additional store to use when looking up objects
  13681. //
  13682. //      pChainPara       - parameters for chain building
  13683. //
  13684. //      dwFlags          - flags such as should revocation checking be done
  13685. //                         on the chain?
  13686. //
  13687. //      pvReserved       - reserved parameter, must be NULL
  13688. //
  13689. //      ppChainContext   - chain context returned
  13690. //
  13691.  
  13692. // CERT_CHAIN_CACHE_END_CERT can be used here as well
  13693. // Revocation flags are in the high nibble
  13694. #define CERT_CHAIN_REVOCATION_CHECK_END_CERT           0x10000000
  13695. #define CERT_CHAIN_REVOCATION_CHECK_CHAIN              0x20000000
  13696. #define CERT_CHAIN_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT 0x40000000
  13697. #define CERT_CHAIN_REVOCATION_CHECK_CACHE_ONLY         0x80000000
  13698.  
  13699. WINCRYPT32API
  13700. BOOL
  13701. WINAPI
  13702. CertGetCertificateChain (
  13703.     IN OPTIONAL HCERTCHAINENGINE hChainEngine,
  13704.     IN PCCERT_CONTEXT pCertContext,
  13705.     IN OPTIONAL LPFILETIME pTime,
  13706.     IN OPTIONAL HCERTSTORE hAdditionalStore,
  13707.     IN PCERT_CHAIN_PARA pChainPara,
  13708.     IN DWORD dwFlags,
  13709.     IN LPVOID pvReserved,
  13710.     OUT PCCERT_CHAIN_CONTEXT* ppChainContext
  13711.     );
  13712.  
  13713. //
  13714. // Free a certificate chain
  13715. //
  13716.  
  13717. WINCRYPT32API
  13718. VOID
  13719. WINAPI
  13720. CertFreeCertificateChain (
  13721.     IN PCCERT_CHAIN_CONTEXT pChainContext
  13722.     );
  13723.  
  13724. //
  13725. // Duplicate (add a reference to) a certificate chain
  13726. //
  13727.  
  13728. WINCRYPT32API
  13729. PCCERT_CHAIN_CONTEXT
  13730. WINAPI
  13731. CertDuplicateCertificateChain (
  13732.     IN PCCERT_CHAIN_CONTEXT pChainContext
  13733.     );
  13734.  
  13735. //
  13736. // Specific Revocation Type OID and structure definitions
  13737. //
  13738.  
  13739. //
  13740. // CRL Revocation OID
  13741. //
  13742.  
  13743. #define REVOCATION_OID_CRL_REVOCATION ((LPCSTR)1)
  13744.  
  13745. //
  13746. // For the CRL revocation OID the pvRevocationPara is NULL
  13747. //
  13748.  
  13749. //
  13750. // CRL Revocation Info
  13751. //
  13752.  
  13753. typedef struct _CRL_REVOCATION_INFO {
  13754.  
  13755.     PCRL_ENTRY           pCrlEntry;
  13756.     PCCRL_CONTEXT        pCrlContext;
  13757.     PCCERT_CHAIN_CONTEXT pCrlIssuerChain;
  13758.  
  13759. } CRL_REVOCATION_INFO, *PCRL_REVOCATION_INFO;
  13760.  
  13761. //+-------------------------------------------------------------------------
  13762. //  Find the first or next certificate chain context in the store.
  13763. //
  13764. //  The chain context is found according to the dwFindFlags, dwFindType and
  13765. //  its pvFindPara. See below for a list of the find types and its parameters.
  13766. //
  13767. //  If the first or next chain context isn't found, NULL is returned.
  13768. //  Otherwise, a pointer to a read only CERT_CHAIN_CONTEXT is returned.
  13769. //  CERT_CHAIN_CONTEXT must be freed by calling CertFreeCertificateChain
  13770. //  or is freed when passed as the
  13771. //  pPrevChainContext on a subsequent call. CertDuplicateCertificateChain
  13772. //  can be called to make a duplicate.
  13773. //
  13774. //  pPrevChainContext MUST BE NULL on the first
  13775. //  call to find the chain context. To find the next chain context, the
  13776. //  pPrevChainContext is set to the CERT_CHAIN_CONTEXT returned by a previous
  13777. //  call.
  13778. //
  13779. //  NOTE: a NON-NULL pPrevChainContext is always CertFreeCertificateChain'ed by
  13780. //  this function, even for an error.
  13781. //--------------------------------------------------------------------------
  13782. WINCRYPT32API
  13783. PCCERT_CHAIN_CONTEXT
  13784. WINAPI
  13785. CertFindChainInStore(
  13786.     IN HCERTSTORE hCertStore,
  13787.     IN DWORD dwCertEncodingType,
  13788.     IN DWORD dwFindFlags,
  13789.     IN DWORD dwFindType,
  13790.     IN const void *pvFindPara,
  13791.     IN PCCERT_CHAIN_CONTEXT pPrevChainContext
  13792.     );
  13793.  
  13794. #define CERT_CHAIN_FIND_BY_ISSUER       1
  13795.  
  13796.  
  13797. //+-------------------------------------------------------------------------
  13798. //  CERT_CHAIN_FIND_BY_ISSUER
  13799. //
  13800. //  Find a certificate chain having a private key for the end certificate and
  13801. //  matching one of the given issuer names. A matching dwKeySpec and
  13802. //  enhanced key usage can also be specified. Additionally a callback can
  13803. //  be provided for even more caller provided filtering before building the
  13804. //  chain.
  13805. //
  13806. //  By default, only the issuers in the first simple chain are compared
  13807. //  for a name match. CERT_CHAIN_FIND_BY_ISSUER_COMPLEX_CHAIN_FLAG can
  13808. //  be set in dwFindFlags to match issuers in all the simple chains.
  13809. //
  13810. //  CERT_CHAIN_FIND_BY_ISSUER_NO_KEY_FLAG can be set in dwFindFlags to
  13811. //  not check if the end certificate has a private key.
  13812. //
  13813. //  CERT_CHAIN_FIND_BY_ISSUER_COMPARE_KEY_FLAG can be set in dwFindFlags
  13814. //  to compare the public key in the end certificate with the crypto
  13815. //  provider's public key. The dwAcquirePrivateKeyFlags can be set
  13816. //  in CERT_CHAIN_FIND_BY_ISSUER_PARA to enable caching of the private key's
  13817. //  HKEY returned by the CSP.
  13818. //
  13819. //  If dwCertEncodingType == 0, defaults to X509_ASN_ENCODING for the
  13820. //  array of encoded issuer names.
  13821. //
  13822. //  By default, the hCertStore passed to CertFindChainInStore, is passed
  13823. //  as an additional store to CertGetCertificateChain.
  13824. //  CERT_CHAIN_FIND_BY_ISSUER_CACHE_ONLY_FLAG can be set in dwFindFlags
  13825. //  to improve performance by only searching the cached system stores
  13826. //  (root, my, ca, trust) to find the issuer certificates. If you are doing
  13827. //  a find in the "my" system store, than, this flag should be set to
  13828. //  improve performance.
  13829. //
  13830. //  Setting CERT_CHAIN_FIND_BY_ISSUER_LOCAL_MACHINE_FLAG in dwFindFlags
  13831. //  restricts CertGetCertificateChain to search the Local Machine
  13832. //  cached system stores instead of the Current User's.
  13833. //
  13834. //  Setting CERT_CHAIN_FIND_BY_ISSUER_CACHE_ONLY_URL_FLAG in dwFindFlags
  13835. //  restricts CertGetCertificateChain to only search the URL cache
  13836. //  and not hit the wire.
  13837. //--------------------------------------------------------------------------
  13838.  
  13839. // Returns FALSE to skip this certificate. Otherwise, returns TRUE to
  13840. // build a chain for this certificate.
  13841. typedef BOOL (WINAPI *PFN_CERT_CHAIN_FIND_BY_ISSUER_CALLBACK)(
  13842.     IN PCCERT_CONTEXT pCert,
  13843.     IN void *pvFindArg
  13844.     );
  13845.  
  13846. typedef struct _CERT_CHAIN_FIND_BY_ISSUER_PARA {
  13847.     DWORD                                   cbSize;
  13848.  
  13849.     // If pszUsageIdentifier == NULL, matches any usage.
  13850.     LPCSTR                                  pszUsageIdentifier;
  13851.  
  13852.     // If dwKeySpec == 0, matches any KeySpec
  13853.     DWORD                                   dwKeySpec;
  13854.  
  13855.     // When CERT_CHAIN_FIND_BY_ISSUER_COMPARE_KEY_FLAG is set in dwFindFlags,
  13856.     // CryptAcquireCertificatePrivateKey is called to do the public key
  13857.     // comparison. The following flags can be set to enable caching
  13858.     // of the acquired private key. See the API for more details on these
  13859.     // flags.
  13860.     DWORD                                   dwAcquirePrivateKeyFlags;
  13861.  
  13862.     // Pointer to an array of X509, ASN.1 encoded issuer name blobs. If
  13863.     // cIssuer == 0, matches any issuer
  13864.     DWORD                                   cIssuer;
  13865.     CERT_NAME_BLOB                          *rgIssuer;
  13866.  
  13867.     // If NULL or Callback returns TRUE, builds the chain for the end
  13868.     // certificate having a private key with the specified KeySpec and
  13869.     // enhanced key usage.
  13870.     PFN_CERT_CHAIN_FIND_BY_ISSUER_CALLBACK pfnFindCallback;
  13871.     void                                    *pvFindArg;
  13872. } CERT_CHAIN_FIND_BY_ISSUER_PARA, *PCERT_CHAIN_FIND_ISSUER_PARA;
  13873.  
  13874. // The following dwFindFlags can be set for CERT_CHAIN_FIND_BY_ISSUER
  13875.  
  13876. // If set, compares the public key in the end certificate with the crypto
  13877. // provider's public key. This comparison is the last check made on the
  13878. // build chain.
  13879. #define CERT_CHAIN_FIND_BY_ISSUER_COMPARE_KEY_FLAG          0x0001
  13880.  
  13881. // If not set, only checks the first simple chain for an issuer name match.
  13882. // When set, also checks second and subsequent simple chains.
  13883. #define CERT_CHAIN_FIND_BY_ISSUER_COMPLEX_CHAIN_FLAG        0x0002
  13884.  
  13885. // If set, CertGetCertificateChain only searches the URL cache and
  13886. // doesn't hit the wire.
  13887. #define CERT_CHAIN_FIND_BY_ISSUER_CACHE_ONLY_URL_FLAG       0x0004
  13888.  
  13889. // If set, CertGetCertificateChain only opens the Local Machine
  13890. // certificate stores instead of the Current User's.
  13891. #define CERT_CHAIN_FIND_BY_ISSUER_LOCAL_MACHINE_FLAG        0x0008
  13892.  
  13893. // If set, no check is made to see if the end certificate has a private
  13894. // key associated with it.
  13895. #define CERT_CHAIN_FIND_BY_ISSUER_NO_KEY_FLAG               0x4000
  13896.  
  13897.  
  13898. // By default, the hCertStore passed to CertFindChainInStore, is passed
  13899. // as the additional store to CertGetCertificateChain. This flag can be
  13900. // set to improve performance by only searching the cached system stores
  13901. // (root, my, ca, trust) to find the issuer certificates. If not set, then,
  13902. // the hCertStore is always searched in addition to the cached system
  13903. // stores.
  13904. #define CERT_CHAIN_FIND_BY_ISSUER_CACHE_ONLY_FLAG           0x8000
  13905.  
  13906.  
  13907.  
  13908. //+=========================================================================
  13909. //  Certificate Chain Policy Data Structures and APIs
  13910. //==========================================================================
  13911. typedef struct _CERT_CHAIN_POLICY_PARA {
  13912.     DWORD                   cbSize;
  13913.     DWORD                   dwFlags;
  13914.     void                    *pvExtraPolicyPara;     // pszPolicyOID specific
  13915. } CERT_CHAIN_POLICY_PARA, *PCERT_CHAIN_POLICY_PARA;
  13916.  
  13917. // If both lChainIndex and lElementIndex are set to -1, the dwError applies
  13918. // to the whole chain context. If only lElementIndex is set to -1, the
  13919. // dwError applies to the lChainIndex'ed chain. Otherwise, the dwError applies
  13920. // to the certificate element at
  13921. // pChainContext->rgpChain[lChainIndex]->rgpElement[lElementIndex].
  13922. typedef struct _CERT_CHAIN_POLICY_STATUS {
  13923.     DWORD                   cbSize;
  13924.     DWORD                   dwError;
  13925.     LONG                    lChainIndex;
  13926.     LONG                    lElementIndex;
  13927.     void                    *pvExtraPolicyStatus;   // pszPolicyOID specific
  13928. } CERT_CHAIN_POLICY_STATUS, *PCERT_CHAIN_POLICY_STATUS;
  13929.  
  13930. // Common chain policy flags
  13931. #define CERT_CHAIN_POLICY_IGNORE_NOT_TIME_VALID_FLAG                0x00000001
  13932. #define CERT_CHAIN_POLICY_IGNORE_CTL_NOT_TIME_VALID_FLAG            0x00000002
  13933. #define CERT_CHAIN_POLICY_IGNORE_NOT_TIME_NESTED_FLAG               0x00000004
  13934.  
  13935. #define CERT_CHAIN_POLICY_IGNORE_ALL_NOT_TIME_VALID_FLAGS ( \
  13936.     CERT_CHAIN_POLICY_IGNORE_NOT_TIME_VALID_FLAG                | \
  13937.     CERT_CHAIN_POLICY_IGNORE_CTL_NOT_TIME_VALID_FLAG            | \
  13938.     CERT_CHAIN_POLICY_IGNORE_NOT_TIME_NESTED_FLAG                 \
  13939.     )
  13940.  
  13941.  
  13942. #define CERT_CHAIN_POLICY_ALLOW_UNKNOWN_CA_FLAG                     0x00000010
  13943. #define CERT_CHAIN_POLICY_IGNORE_WRONG_USAGE_FLAG                   0x00000020
  13944.  
  13945. #define CERT_CHAIN_POLICY_IGNORE_END_REV_UNKNOWN_FLAG               0x00000100
  13946. #define CERT_CHAIN_POLICY_IGNORE_CTL_SIGNER_REV_UNKNOWN_FLAG        0x00000200
  13947. #define CERT_CHAIN_POLICY_IGNORE_CA_REV_UNKNOWN_FLAG                0x00000400
  13948. #define CERT_CHAIN_POLICY_IGNORE_ROOT_REV_UNKNOWN_FLAG              0x00000800
  13949.  
  13950. #define CERT_CHAIN_POLICY_IGNORE_ALL_REV_UNKNOWN_FLAGS ( \
  13951.     CERT_CHAIN_POLICY_IGNORE_END_REV_UNKNOWN_FLAG         | \
  13952.     CERT_CHAIN_POLICY_IGNORE_CTL_SIGNER_REV_UNKNOWN_FLAG  | \
  13953.     CERT_CHAIN_POLICY_IGNORE_CA_REV_UNKNOWN_FLAG          | \
  13954.     CERT_CHAIN_POLICY_IGNORE_ROOT_REV_UNKNOWN_FLAG          \
  13955.     )
  13956.  
  13957. #define CERT_CHAIN_POLICY_ALLOW_TESTROOT_FLAG                       0x00008000
  13958. #define CERT_CHAIN_POLICY_TRUST_TESTROOT_FLAG                       0x00004000
  13959.  
  13960.  
  13961. //+-------------------------------------------------------------------------
  13962. //  Verify that the certificate chain satisfies the specified policy
  13963. //  requirements. If we were able to verify the chain policy, TRUE is returned
  13964. //  and the dwError field of the pPolicyStatus is updated. A dwError of 0
  13965. //  (ERROR_SUCCESS, S_OK) indicates the chain satisfies the specified policy.
  13966. //
  13967. //  If dwError applies to the entire chain context, both lChainIndex and
  13968. //  lElementIndex are set to -1. If dwError applies to a simple chain,
  13969. //  lElementIndex is set to -1 and lChainIndex is set to the index of the
  13970. //  first offending chain having the error. If dwError applies to a
  13971. //  certificate element, lChainIndex and lElementIndex are updated to
  13972. //  index the first offending certificate having the error, where, the
  13973. //  the certificate element is at:
  13974. //      pChainContext->rgpChain[lChainIndex]->rgpElement[lElementIndex].
  13975. //
  13976. //  The dwFlags in pPolicyPara can be set to change the default policy checking
  13977. //  behaviour. In addition, policy specific parameters can be passed in
  13978. //  the pvExtraPolicyPara field of pPolicyPara.
  13979. //
  13980. //  In addition to returning dwError, in pPolicyStatus, policy OID specific
  13981. //  extra status may be returned via pvExtraPolicyStatus.
  13982. //--------------------------------------------------------------------------
  13983. WINCRYPT32API
  13984. BOOL
  13985. WINAPI
  13986. CertVerifyCertificateChainPolicy(
  13987.     IN LPCSTR pszPolicyOID,
  13988.     IN PCCERT_CHAIN_CONTEXT pChainContext,
  13989.     IN PCERT_CHAIN_POLICY_PARA pPolicyPara,
  13990.     IN OUT PCERT_CHAIN_POLICY_STATUS pPolicyStatus
  13991.     );
  13992.  
  13993. // Predefined OID Function Names
  13994. #define CRYPT_OID_VERIFY_CERTIFICATE_CHAIN_POLICY_FUNC  \
  13995.     "CertDllVerifyCertificateChainPolicy"
  13996.  
  13997. // CertDllVerifyCertificateChainPolicy has same function signature as
  13998. // CertVerifyCertificateChainPolicy.
  13999.  
  14000. //+-------------------------------------------------------------------------
  14001. //  Predefined verify chain policies
  14002. //--------------------------------------------------------------------------
  14003. #define CERT_CHAIN_POLICY_BASE              ((LPCSTR) 1)
  14004. #define CERT_CHAIN_POLICY_AUTHENTICODE      ((LPCSTR) 2)
  14005. #define CERT_CHAIN_POLICY_AUTHENTICODE_TS   ((LPCSTR) 3)
  14006. #define CERT_CHAIN_POLICY_SSL               ((LPCSTR) 4)
  14007. #define CERT_CHAIN_POLICY_BASIC_CONSTRAINTS ((LPCSTR) 5)
  14008. #define CERT_CHAIN_POLICY_NT_AUTH           ((LPCSTR) 6)
  14009.  
  14010. //+-------------------------------------------------------------------------
  14011. //  CERT_CHAIN_POLICY_BASE
  14012. //
  14013. //  Implements the base chain policy verification checks. dwFlags can
  14014. //  be set in pPolicyPara to alter the default policy checking behaviour.
  14015. //--------------------------------------------------------------------------
  14016.  
  14017. //+-------------------------------------------------------------------------
  14018. //  CERT_CHAIN_POLICY_AUTHENTICODE
  14019. //
  14020. //  Implements the Authenticode chain policy verification checks.
  14021. //
  14022. //  pvExtraPolicyPara may optionally be set to point to the following
  14023. //  AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_PARA.
  14024. //
  14025. //  pvExtraPolicyStatus may optionally be set to point to the following
  14026. //  AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_STATUS.
  14027. //--------------------------------------------------------------------------
  14028.  
  14029. // dwRegPolicySettings are defined in wintrust.h
  14030. typedef struct _AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_PARA {
  14031.     DWORD               cbSize;
  14032.     DWORD               dwRegPolicySettings;
  14033.     PCMSG_SIGNER_INFO   pSignerInfo;                // optional
  14034. } AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_PARA,
  14035.     *PAUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_PARA;
  14036.  
  14037. typedef struct _AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_STATUS {
  14038.     DWORD               cbSize;
  14039.     BOOL                fCommercial;        // obtained from signer statement
  14040. } AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_STATUS,
  14041.     *PAUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_STATUS;
  14042.  
  14043. //+-------------------------------------------------------------------------
  14044. //  CERT_CHAIN_POLICY_AUTHENTICODE_TS
  14045. //
  14046. //  Implements the Authenticode Time Stamp chain policy verification checks.
  14047. //
  14048. //  pvExtraPolicyPara may optionally be set to point to the following
  14049. //  AUTHENTICODE_TS_EXTRA_CERT_CHAIN_POLICY_PARA.
  14050. //
  14051. //  pvExtraPolicyStatus isn't used and must be set to NULL.
  14052. //--------------------------------------------------------------------------
  14053.  
  14054. // dwRegPolicySettings are defined in wintrust.h
  14055. typedef struct _AUTHENTICODE_TS_EXTRA_CERT_CHAIN_POLICY_PARA {
  14056.     DWORD               cbSize;
  14057.     DWORD               dwRegPolicySettings;
  14058.     BOOL                fCommercial;
  14059. } AUTHENTICODE_TS_EXTRA_CERT_CHAIN_POLICY_PARA,
  14060.     *PAUTHENTICODE_TS_EXTRA_CERT_CHAIN_POLICY_PARA;
  14061.  
  14062.  
  14063. //+-------------------------------------------------------------------------
  14064. //  CERT_CHAIN_POLICY_SSL
  14065. //
  14066. //  Implements the SSL client/server chain policy verification checks.
  14067. //
  14068. //  pvExtraPolicyPara may optionally be set to point to the following
  14069. //  SSL_EXTRA_CERT_CHAIN_POLICY_PARA data structure
  14070. //--------------------------------------------------------------------------
  14071.  
  14072. // fdwChecks flags are defined in wininet.h
  14073. typedef struct _HTTPSPolicyCallbackData
  14074. {
  14075.     union {
  14076.         DWORD           cbStruct;       // sizeof(HTTPSPolicyCallbackData);
  14077.         DWORD           cbSize;         // sizeof(HTTPSPolicyCallbackData);
  14078.     };
  14079.  
  14080.     DWORD           dwAuthType;
  14081. #                       define      AUTHTYPE_CLIENT         1
  14082. #                       define      AUTHTYPE_SERVER         2
  14083.  
  14084.     DWORD           fdwChecks;
  14085.  
  14086.     WCHAR           *pwszServerName; // used to check against CN=xxxx
  14087.  
  14088. } HTTPSPolicyCallbackData, *PHTTPSPolicyCallbackData,
  14089.     SSL_EXTRA_CERT_CHAIN_POLICY_PARA, *PSSL_EXTRA_CERT_CHAIN_POLICY_PARA;
  14090.  
  14091. //+-------------------------------------------------------------------------
  14092. //  CERT_CHAIN_POLICY_BASIC_CONSTRAINTS
  14093. //
  14094. //  Implements the basic constraints chain policy.
  14095. //
  14096. //  Iterates through all the certificates in the chain checking for either
  14097. //  a szOID_BASIC_CONSTRAINTS or a szOID_BASIC_CONSTRAINTS2 extension. If
  14098. //  neither extension is present, the certificate is assumed to have
  14099. //  valid policy. Otherwise, for the first certificate element, checks if
  14100. //  it matches the expected CA_FLAG or END_ENTITY_FLAG specified in
  14101. //  pPolicyPara->dwFlags. If neither or both flags are set, then, the first
  14102. //  element can be either a CA or END_ENTITY. All other elements must be
  14103. //  a CA. If the PathLenConstraint is present in the extension, its
  14104. //  checked.
  14105. //
  14106. //  The first elements in the remaining simple chains (ie, the certificate
  14107. //  used to sign the CTL) are checked to be an END_ENTITY.
  14108. //
  14109. //  If this verification fails, dwError will be set to
  14110. //  TRUST_E_BASIC_CONSTRAINTS.
  14111. //--------------------------------------------------------------------------
  14112.  
  14113. #define BASIC_CONSTRAINTS_CERT_CHAIN_POLICY_CA_FLAG         0x80000000
  14114. #define BASIC_CONSTRAINTS_CERT_CHAIN_POLICY_END_ENTITY_FLAG 0x40000000
  14115.  
  14116. //+-------------------------------------------------------------------------
  14117. //  CERT_CHAIN_POLICY_NT_AUTH
  14118. //
  14119. //  Implements the NT Authentication chain policy.
  14120. //
  14121. //  The NT Authentication chain policy consists of 3 distinct chain
  14122. //  verifications in the following order:
  14123. //      [1] CERT_CHAIN_POLICY_BASE - Implements the base chain policy
  14124. //          verification checks. The LOWORD of dwFlags can be set in
  14125. //          pPolicyPara to alter the default policy checking behaviour. See
  14126. //          CERT_CHAIN_POLICY_BASE for more details.
  14127. //
  14128. //      [2] CERT_CHAIN_POLICY_BASIC_CONSTRAINTS - Implements the basic
  14129. //          constraints chain policy. The HIWORD of dwFlags can be set
  14130. //          to specify if the first element must be either a CA or END_ENTITY.
  14131. //          See CERT_CHAIN_POLICY_BASIC_CONSTRAINTS for more details.
  14132. //
  14133. //      [3] Checks if the second element in the chain, the CA that issued
  14134. //          the end certificate, is a trusted CA for NT
  14135. //          Authentication. A CA is considered to be trusted if it exists in
  14136. //          the "NTAuth" system registry store found in the
  14137. //          CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE store location.
  14138. //          If this verification fails, whereby the CA isn't trusted,
  14139. //          dwError is set to CERT_E_UNTRUSTEDCA.
  14140. //--------------------------------------------------------------------------
  14141.  
  14142. #ifdef __cplusplus
  14143. }       // Balance extern "C" above
  14144. #endif
  14145.  
  14146. #if defined (_MSC_VER)
  14147. #if ( _MSC_VER >= 800 )
  14148.  
  14149. #if _MSC_VER >= 1200
  14150. #pragma warning(pop)
  14151. #else
  14152. #pragma warning(default:4201)
  14153. #endif
  14154.  
  14155. #endif
  14156. #endif
  14157.  
  14158. #pragma option pop /*P_O_Pop*/
  14159. #endif // __WINCRYPT_H__
  14160.  
  14161.