home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / include / wincrypt.h < prev    next >
C/C++ Source or Header  |  1998-04-25  |  321KB  |  7,894 lines

  1. //+---------------------------------------------------------------------------
  2. //
  3. //  Microsoft Windows
  4. //  Copyright 1992 - 1998 Microsoft Corporation.
  5. //
  6. //  File:       wincrypt.h
  7. //
  8. //  Contents:   Cryptographic API Prototypes and Definitions
  9. //
  10. //----------------------------------------------------------------------------
  11.  
  12. #ifndef __WINCRYPT_H__
  13. #define __WINCRYPT_H__
  14.  
  15.  
  16. #if(_WIN32_WINNT >= 0x0400)
  17.  
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21.  
  22. #ifndef _HRESULT_DEFINED
  23. #define _HRESULT_DEFINED
  24. typedef LONG HRESULT;
  25.  
  26. #endif // !_HRESULT_DEFINED
  27.  
  28. #if !defined(_CRYPT32_)
  29. #define WINCRYPT32API DECLSPEC_IMPORT
  30. #else
  31. #define WINCRYPT32API
  32. #endif
  33.  
  34. //
  35. // Algorithm IDs and Flags
  36. //
  37.  
  38. // ALG_ID crackers
  39. #define GET_ALG_CLASS(x)                (x & (7 << 13))
  40. #define GET_ALG_TYPE(x)                 (x & (15 << 9))
  41. #define GET_ALG_SID(x)                  (x & (511))
  42.  
  43. // Algorithm classes
  44. #define ALG_CLASS_ANY                   (0)
  45. #define ALG_CLASS_SIGNATURE             (1 << 13)
  46. #define ALG_CLASS_MSG_ENCRYPT           (2 << 13)
  47. #define ALG_CLASS_DATA_ENCRYPT          (3 << 13)
  48. #define ALG_CLASS_HASH                  (4 << 13)
  49. #define ALG_CLASS_KEY_EXCHANGE          (5 << 13)
  50.  
  51. // Algorithm types
  52. #define ALG_TYPE_ANY                    (0)
  53. #define ALG_TYPE_DSS                    (1 << 9)
  54. #define ALG_TYPE_RSA                    (2 << 9)
  55. #define ALG_TYPE_BLOCK                  (3 << 9)
  56. #define ALG_TYPE_STREAM                 (4 << 9)
  57. #define ALG_TYPE_DH                     (5 << 9)
  58. #define ALG_TYPE_SECURECHANNEL          (6 << 9)
  59.  
  60. // Generic sub-ids
  61. #define ALG_SID_ANY                     (0)
  62.  
  63. // Some RSA sub-ids
  64. #define ALG_SID_RSA_ANY                 0
  65. #define ALG_SID_RSA_PKCS                1
  66. #define ALG_SID_RSA_MSATWORK            2
  67. #define ALG_SID_RSA_ENTRUST             3
  68. #define ALG_SID_RSA_PGP                 4
  69.  
  70. // Some DSS sub-ids
  71. //
  72. #define ALG_SID_DSS_ANY                 0
  73. #define ALG_SID_DSS_PKCS                1
  74. #define ALG_SID_DSS_DMS                 2
  75.  
  76. // Block cipher sub ids
  77. // DES sub_ids
  78. #define ALG_SID_DES                     1
  79. #define ALG_SID_3DES                    3
  80. #define ALG_SID_DESX                    4
  81. #define ALG_SID_IDEA                    5
  82. #define ALG_SID_CAST                    6
  83. #define ALG_SID_SAFERSK64               7
  84. #define ALG_SID_SAFERSK128              8
  85. #define ALG_SID_3DES_112                9
  86. #define ALG_SID_CYLINK_MEK              12
  87. #define ALG_SID_RC5                     13
  88.  
  89. // Fortezza sub-ids
  90. #define ALG_SID_SKIPJACK                10
  91. #define ALG_SID_TEK                     11
  92.  
  93. // KP_MODE
  94. #define CRYPT_MODE_CBCI                 6       // ANSI CBC Interleaved
  95. #define CRYPT_MODE_CFBP                 7       // ANSI CFB Pipelined
  96. #define CRYPT_MODE_OFBP                 8       // ANSI OFB Pipelined
  97. #define CRYPT_MODE_CBCOFM               9       // ANSI CBC + OF Masking
  98. #define CRYPT_MODE_CBCOFMI              10      // ANSI CBC + OFM Interleaved
  99.  
  100. // RC2 sub-ids
  101. #define ALG_SID_RC2                     2
  102.  
  103. // Stream cipher sub-ids
  104. #define ALG_SID_RC4                     1
  105. #define ALG_SID_SEAL                    2
  106.  
  107. // Diffie-Hellman sub-ids
  108. #define ALG_SID_DH_SANDF                1
  109. #define ALG_SID_DH_EPHEM                2
  110. #define ALG_SID_AGREED_KEY_ANY          3
  111. #define ALG_SID_KEA                     4
  112.  
  113. // Hash sub ids
  114. #define ALG_SID_MD2                     1
  115. #define ALG_SID_MD4                     2
  116. #define ALG_SID_MD5                     3
  117. #define ALG_SID_SHA                     4
  118. #define ALG_SID_SHA1                    4
  119. #define ALG_SID_MAC                     5
  120. #define ALG_SID_RIPEMD                  6
  121. #define ALG_SID_RIPEMD160               7
  122. #define ALG_SID_SSL3SHAMD5              8
  123. #define ALG_SID_HMAC                    9
  124.  
  125. // secure channel sub ids
  126. #define ALG_SID_SSL3_MASTER             1
  127. #define ALG_SID_SCHANNEL_MASTER_HASH    2
  128. #define ALG_SID_SCHANNEL_MAC_KEY        3
  129. #define ALG_SID_PCT1_MASTER             4
  130. #define ALG_SID_SSL2_MASTER             5
  131. #define ALG_SID_TLS1_MASTER             6
  132. #define ALG_SID_SCHANNEL_ENC_KEY        7
  133.  
  134. // Our silly example sub-id
  135. #define ALG_SID_EXAMPLE                 80
  136.  
  137. #ifndef ALGIDDEF
  138. #define ALGIDDEF
  139. typedef unsigned int ALG_ID;
  140. #endif
  141.  
  142. // algorithm identifier definitions
  143. #define CALG_MD2                (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD2)
  144. #define CALG_MD4                (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD4)
  145. #define CALG_MD5                (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD5)
  146. #define CALG_SHA                (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA)
  147. #define CALG_SHA1                (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA1)
  148. #define CALG_MAC                (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MAC)
  149. #define CALG_RSA_SIGN            (ALG_CLASS_SIGNATURE | ALG_TYPE_RSA | ALG_SID_RSA_ANY)
  150. #define CALG_DSS_SIGN            (ALG_CLASS_SIGNATURE | ALG_TYPE_DSS | ALG_SID_DSS_ANY)
  151. #define CALG_RSA_KEYX            (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_RSA|ALG_SID_RSA_ANY)
  152. #define CALG_DES                (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_DES)
  153. #define CALG_3DES_112            (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_3DES_112)
  154. #define CALG_3DES                (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_3DES)
  155. #define CALG_RC2                (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_RC2)
  156. #define CALG_RC4                (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_STREAM|ALG_SID_RC4)
  157. #define CALG_SEAL                (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_STREAM|ALG_SID_SEAL)
  158. #define CALG_DH_SF              (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_DH_SANDF)
  159. #define CALG_DH_EPHEM            (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_DH_EPHEM)
  160. #define CALG_AGREEDKEY_ANY        (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_AGREED_KEY_ANY)
  161. #define CALG_KEA_KEYX            (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_KEA)
  162. #define CALG_HUGHES_MD5         (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_ANY|ALG_SID_MD5)
  163. #define CALG_SKIPJACK            (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_SKIPJACK)
  164. #define CALG_TEK                (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_TEK)
  165. #define CALG_CYLINK_MEK         (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_CYLINK_MEK)
  166. #define CALG_SSL3_SHAMD5        (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SSL3SHAMD5)
  167. #define CALG_SSL3_MASTER        (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SSL3_MASTER)
  168. #define CALG_SCHANNEL_MASTER_HASH   (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SCHANNEL_MASTER_HASH)
  169. #define CALG_SCHANNEL_MAC_KEY   (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SCHANNEL_MAC_KEY)
  170. #define CALG_SCHANNEL_ENC_KEY   (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SCHANNEL_ENC_KEY)
  171. #define CALG_PCT1_MASTER        (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_PCT1_MASTER)
  172. #define CALG_SSL2_MASTER        (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SSL2_MASTER)
  173. #define CALG_TLS1_MASTER        (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_TLS1_MASTER)
  174. #define CALG_RC5                (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_RC5)
  175. #define CALG_HMAC                (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_HMAC)
  176.  
  177. typedef struct _VTableProvStruc {
  178.     DWORD   Version;
  179.     FARPROC FuncVerifyImage;
  180.     FARPROC FuncReturnhWnd;
  181.     DWORD   dwProvType;
  182.     BYTE    *pbContextInfo;
  183.     DWORD    cbContextInfo;
  184. } VTableProvStruc, *PVTableProvStruc;
  185.  
  186. typedef unsigned long HCRYPTPROV;
  187. typedef unsigned long HCRYPTKEY;
  188. typedef unsigned long HCRYPTHASH;
  189.  
  190. // dwFlags definitions for CryptAcquireContext
  191. #define CRYPT_VERIFYCONTEXT     0xF0000000
  192. #define CRYPT_NEWKEYSET         0x00000008
  193. #define CRYPT_DELETEKEYSET      0x00000010
  194. #define CRYPT_MACHINE_KEYSET    0x00000020
  195.  
  196. // dwFlag definitions for CryptGenKey
  197. #define CRYPT_EXPORTABLE        0x00000001
  198. #define CRYPT_USER_PROTECTED    0x00000002
  199. #define CRYPT_CREATE_SALT       0x00000004
  200. #define CRYPT_UPDATE_KEY        0x00000008
  201. #define CRYPT_NO_SALT           0x00000010
  202. #define CRYPT_PREGEN            0x00000040
  203. #define CRYPT_RECIPIENT         0x00000010
  204. #define CRYPT_INITIATOR         0x00000040
  205. #define CRYPT_ONLINE            0x00000080
  206. #define CRYPT_SF                0x00000100
  207. #define CRYPT_CREATE_IV         0x00000200
  208. #define CRYPT_KEK               0x00000400
  209. #define CRYPT_DATA_KEY          0x00000800
  210.  
  211. // dwFlags definitions for CryptDeriveKey
  212. #define    CRYPT_SERVER            0x00000400
  213.  
  214. #define KEY_LENGTH_MASK         0xFFFF0000
  215.  
  216. // dwFlag definitions for CryptExportKey
  217. #define CRYPT_Y_ONLY            0x00000001
  218. #define CRYPT_SSL2_SLUMMING     0x00000002
  219.  
  220. // dwFlags definitions for CryptHashSessionKey
  221. #define    CRYPT_LITTLE_ENDIAN        0x00000001
  222.  
  223. // dwFlag definitions for CryptSetProviderEx and CryptGetDefaultProvider
  224. #define CRYPT_MACHINE_DEFAULT   0x00000001
  225. #define CRYPT_USER_DEFAULT      0x00000002
  226. #define CRYPT_DELETE_DEFAULT    0x00000004
  227.  
  228. // exported key blob definitions
  229. #define SIMPLEBLOB              0x1
  230. #define PUBLICKEYBLOB           0x6
  231. #define PRIVATEKEYBLOB          0x7
  232. #define PLAINTEXTKEYBLOB        0x8
  233.  
  234. #define AT_KEYEXCHANGE          1
  235. #define AT_SIGNATURE            2
  236.  
  237. #define CRYPT_USERDATA          1
  238.  
  239. // dwParam
  240. #define KP_IV                   1       // Initialization vector
  241. #define KP_SALT                 2       // Salt value
  242. #define KP_PADDING              3       // Padding values
  243. #define KP_MODE                 4       // Mode of the cipher
  244. #define KP_MODE_BITS            5       // Number of bits to feedback
  245. #define KP_PERMISSIONS          6       // Key permissions DWORD
  246. #define KP_ALGID                7       // Key algorithm
  247. #define KP_BLOCKLEN             8       // Block size of the cipher
  248. #define KP_KEYLEN               9       // Length of key in bits
  249. #define KP_SALT_EX              10      // Length of salt in bytes
  250. #define KP_P                    11      // DSS/Diffie-Hellman P value
  251. #define KP_G                    12      // DSS/Diffie-Hellman G value
  252. #define KP_Q                    13      // DSS Q value
  253. #define KP_X                    14      // Diffie-Hellman X value
  254. #define KP_Y                    15      // Y value
  255. #define KP_RA                   16      // Fortezza RA value
  256. #define KP_RB                   17      // Fortezza RB value
  257. #define KP_INFO                 18      // for putting information into an RSA envelope
  258. #define KP_EFFECTIVE_KEYLEN     19      // setting and getting RC2 effective key length
  259. #define KP_SCHANNEL_ALG            20      // for setting the Secure Channel algorithms
  260. #define KP_CLIENT_RANDOM        21      // for setting the Secure Channel client random data
  261. #define KP_SERVER_RANDOM        22      // for setting the Secure Channel server random data
  262. #define    KP_RP                    23
  263. #define    KP_PRECOMP_MD5            24
  264. #define    KP_PRECOMP_SHA            25
  265. #define KP_CERTIFICATE          26      // for setting Secure Channel certificate data (PCT1)
  266. #define KP_CLEAR_KEY            27      // for setting Secure Channel clear key data (PCT1)
  267. #define KP_PUB_EX_LEN           28
  268. #define KP_PUB_EX_VAL           29
  269.  
  270. // KP_PADDING
  271. #define PKCS5_PADDING           1       // PKCS 5 (sec 6.2) padding method
  272. #define RANDOM_PADDING            2
  273. #define    ZERO_PADDING            3
  274.  
  275. // KP_MODE
  276. #define CRYPT_MODE_CBC          1       // Cipher block chaining
  277. #define CRYPT_MODE_ECB          2       // Electronic code book
  278. #define CRYPT_MODE_OFB          3       // Output feedback mode
  279. #define CRYPT_MODE_CFB          4       // Cipher feedback mode
  280. #define CRYPT_MODE_CTS          5       // Ciphertext stealing mode
  281.  
  282. // KP_PERMISSIONS
  283. #define CRYPT_ENCRYPT           0x0001  // Allow encryption
  284. #define CRYPT_DECRYPT           0x0002  // Allow decryption
  285. #define CRYPT_EXPORT            0x0004  // Allow key to be exported
  286. #define CRYPT_READ              0x0008  // Allow parameters to be read
  287. #define CRYPT_WRITE             0x0010  // Allow parameters to be set
  288. #define CRYPT_MAC               0x0020  // Allow MACs to be used with key
  289. #define CRYPT_EXPORT_KEY        0x0040  // Allow key to be used for exporting keys
  290. #define CRYPT_IMPORT_KEY        0x0080  // Allow key to be used for importing keys
  291.  
  292. #define HP_ALGID                0x0001  // Hash algorithm
  293. #define HP_HASHVAL              0x0002  // Hash value
  294. #define HP_HASHSIZE             0x0004  // Hash value size
  295. #define HP_HMAC_INFO            0x0005  // information for creating an HMAC
  296.  
  297. #define CRYPT_FAILED            FALSE
  298. #define CRYPT_SUCCEED           TRUE
  299.  
  300. #define RCRYPT_SUCCEEDED(rt)     ((rt) == CRYPT_SUCCEED)
  301. #define RCRYPT_FAILED(rt)        ((rt) == CRYPT_FAILED)
  302.  
  303. //
  304. // CryptGetProvParam
  305. //
  306. #define PP_ENUMALGS             1
  307. #define PP_ENUMCONTAINERS       2
  308. #define PP_IMPTYPE              3
  309. #define PP_NAME                 4
  310. #define PP_VERSION              5
  311. #define PP_CONTAINER            6
  312. #define PP_CHANGE_PASSWORD      7
  313. #define PP_KEYSET_SEC_DESCR     8       // get/set security descriptor of keyset
  314. #define PP_CERTCHAIN            9       // for retrieving certificates from tokens
  315. #define PP_KEY_TYPE_SUBTYPE     10
  316. #define PP_PROVTYPE             16
  317. #define PP_KEYSTORAGE           17
  318. #define PP_APPLI_CERT           18
  319. #define PP_SYM_KEYSIZE          19
  320. #define PP_SESSION_KEYSIZE      20
  321. #define PP_UI_PROMPT            21
  322. #define PP_ENUMALGS_EX          22
  323.  
  324. #define CRYPT_FIRST             1
  325. #define CRYPT_NEXT              2
  326.  
  327. #define CRYPT_IMPL_HARDWARE     1
  328. #define CRYPT_IMPL_SOFTWARE     2
  329. #define CRYPT_IMPL_MIXED        3
  330. #define CRYPT_IMPL_UNKNOWN      4
  331.  
  332. // key storage flags
  333. #define CRYPT_SEC_DESCR         0x00000001
  334. #define CRYPT_PSTORE            0x00000002
  335. #define CRYPT_UI_PROMPT         0x00000004
  336.  
  337. // protocol flags
  338. #define CRYPT_FLAG_PCT1         0x0001
  339. #define CRYPT_FLAG_SSL2         0x0002
  340. #define CRYPT_FLAG_SSL3         0x0004
  341. #define CRYPT_FLAG_TLS1         0x0008
  342.  
  343. //
  344. // CryptSetProvParam
  345. //
  346. #define PP_CLIENT_HWND          1
  347. #define PP_CONTEXT_INFO            11
  348. #define    PP_KEYEXCHANGE_KEYSIZE    12
  349. #define    PP_SIGNATURE_KEYSIZE    13
  350. #define PP_KEYEXCHANGE_ALG      14
  351. #define PP_SIGNATURE_ALG        15
  352. #define PP_DELETEKEY            24
  353.  
  354. #define PROV_RSA_FULL           1
  355. #define PROV_RSA_SIG            2
  356. #define PROV_DSS                3
  357. #define PROV_FORTEZZA           4
  358. #define PROV_MS_EXCHANGE        5
  359. #define PROV_SSL                6
  360. #define PROV_RSA_SCHANNEL       12
  361. #define PROV_DSS_DH             13
  362. #define PROV_EC_ECDSA_SIG       14
  363. #define PROV_EC_ECNRA_SIG       15
  364. #define PROV_EC_ECDSA_FULL      16
  365. #define PROV_EC_ECNRA_FULL      17
  366. #define PROV_SPYRUS_LYNKS       20
  367.  
  368. //
  369. // STT defined Providers
  370. //
  371. #define PROV_STT_MER                    7
  372. #define PROV_STT_ACQ                    8
  373. #define PROV_STT_BRND                   9
  374. #define PROV_STT_ROOT                   10
  375. #define PROV_STT_ISS                    11
  376.  
  377. //
  378. // Provider friendly names
  379. //
  380. #define MS_DEF_PROV_A       "Microsoft Base Cryptographic Provider v1.0"
  381. #define MS_DEF_PROV_W       L"Microsoft Base Cryptographic Provider v1.0"
  382. #ifdef UNICODE
  383. #define MS_DEF_PROV         MS_DEF_PROV_W
  384. #else
  385. #define MS_DEF_PROV         MS_DEF_PROV_A
  386. #endif
  387.  
  388. #define MS_ENHANCED_PROV_A       "Microsoft Enhanced Cryptographic Provider v1.0"
  389. #define MS_ENHANCED_PROV_W       L"Microsoft Enhanced Cryptographic Provider v1.0"
  390. #ifdef UNICODE
  391. #define MS_ENHANCED_PROV         MS_ENHANCED_PROV_W
  392. #else
  393. #define MS_ENHANCED_PROV         MS_ENHANCED_PROV_A
  394. #endif
  395.  
  396. #define MS_DEF_RSA_SIG_PROV_A    "Microsoft RSA Signature Cryptographic Provider"
  397. #define MS_DEF_RSA_SIG_PROV_W    L"Microsoft RSA Signature Cryptographic Provider"
  398. #ifdef UNICODE
  399. #define MS_DEF_RSA_SIG_PROV      MS_DEF_RSA_SIG_PROV_W
  400. #else
  401. #define MS_DEF_RSA_SIG_PROV      MS_DEF_RSA_SIG_PROV_A
  402. #endif
  403.  
  404. #define MS_DEF_RSA_SCHANNEL_PROV_A  "Microsoft Base RSA SChannel Cryptographic Provider"
  405. #define MS_DEF_RSA_SCHANNEL_PROV_W  L"Microsoft Base RSA SChannel Cryptographic Provider"
  406. #ifdef UNICODE
  407. #define MS_DEF_RSA_SCHANNEL_PROV         MS_DEF_RSA_SCHANNEL_PROV_W
  408. #else
  409. #define MS_DEF_RSA_SCHANNEL_PROV         MS_DEF_RSA_SCHANNEL_PROV_A
  410. #endif
  411.  
  412. #define MS_ENHANCED_RSA_SCHANNEL_PROV_A  "Microsoft Enhanced RSA SChannel Cryptographic Provider"
  413. #define MS_ENHANCED_RSA_SCHANNEL_PROV_W  L"Microsoft Enhanced RSA SChannel Cryptographic Provider"
  414. #ifdef UNICODE
  415. #define MS_ENHANCED_RSA_SCHANNEL_PROV    MS_ENHANCED_RSA_SCHANNEL_PROV_W
  416. #else
  417. #define MS_ENHANCED_RSA_SCHANNEL_PROV    MS_ENHANCED_RSA_SCHANNEL_PROV_A
  418. #endif
  419.  
  420. #define MS_DEF_DSS_PROV_A        "Microsoft Base DSS Cryptographic Provider"
  421. #define MS_DEF_DSS_PROV_W        L"Microsoft Base DSS Cryptographic Provider"
  422. #ifdef UNICODE
  423. #define MS_DEF_DSS_PROV          MS_DEF_DSS_PROV_W
  424. #else
  425. #define MS_DEF_DSS_PROV          MS_DEF_DSS_PROV_A
  426. #endif
  427.  
  428. #define MS_DEF_DSS_DH_PROV_A    "Microsoft Base DSS and Diffie-Hellman Cryptographic Provider"
  429. #define MS_DEF_DSS_DH_PROV_W    L"Microsoft Base DSS and Diffie-Hellman Cryptographic Provider"
  430. #ifdef UNICODE
  431. #define MS_DEF_DSS_DH_PROV      MS_DEF_DSS_DH_PROV_W
  432. #else
  433. #define MS_DEF_DSS_DH_PROV      MS_DEF_DSS_DH_PROV_A
  434. #endif
  435.  
  436.  
  437. #define MAXUIDLEN               64
  438.  
  439. #define CUR_BLOB_VERSION        2
  440.  
  441. // structure for use with CryptSetHashParam with CALG_HMAC
  442. typedef struct _HMAC_Info {
  443.         ALG_ID  HashAlgid;
  444.         BYTE    *pbInnerString;
  445.         DWORD   cbInnerString;
  446.         BYTE    *pbOuterString;
  447.         DWORD   cbOuterString;
  448. } HMAC_INFO, *PHMAC_INFO;
  449.  
  450. // structure for use with CryptSetKeyParam with KP_SCHANNEL_ALG
  451. typedef struct _SCHANNEL_ALG {
  452.         DWORD   dwUse;
  453.         ALG_ID  Algid;
  454.         DWORD   cBits;
  455. } SCHANNEL_ALG, *PSCHANNEL_ALG;
  456.  
  457. // uses of algortihms for SCHANNEL_ALG structure
  458. #define     SCHANNEL_MAC_KEY    0x00000000
  459. #define     SCHANNEL_ENC_KEY    0x00000001
  460.  
  461. typedef struct _PROV_ENUMALGS {
  462.     ALG_ID    aiAlgid;
  463.     DWORD     dwBitLen;
  464.     DWORD     dwNameLen;
  465.     CHAR      szName[20];
  466. } PROV_ENUMALGS;
  467.  
  468. typedef struct _PROV_ENUMALGS_EX {
  469.     ALG_ID    aiAlgid;
  470.     DWORD     dwDefaultLen;
  471.     DWORD     dwMinLen;
  472.     DWORD     dwMaxLen;
  473.     DWORD     dwProtocols;
  474.     DWORD     dwNameLen;
  475.     CHAR      szName[20];
  476.     DWORD     dwLongNameLen;
  477.     CHAR      szLongName[40];
  478. } PROV_ENUMALGS_EX;
  479.  
  480. typedef struct _PUBLICKEYSTRUC {
  481.         BYTE    bType;
  482.         BYTE    bVersion;
  483.         WORD    reserved;
  484.         ALG_ID  aiKeyAlg;
  485. } BLOBHEADER, PUBLICKEYSTRUC;
  486.  
  487. typedef struct _RSAPUBKEY {
  488.         DWORD   magic;                  // Has to be RSA1
  489.         DWORD   bitlen;                 // # of bits in modulus
  490.         DWORD   pubexp;                 // public exponent
  491.                                         // Modulus data follows
  492. } RSAPUBKEY;
  493.  
  494. typedef struct _PUBKEY {
  495.         DWORD   magic;
  496.         DWORD   bitlen;                 // # of bits in modulus
  497. } DHPUBKEY, DSSPUBKEY, KEAPUBKEY, TEKPUBKEY;
  498.  
  499. typedef struct _DSSSEED {
  500.         DWORD   counter;
  501.         BYTE    seed[20];
  502. } DSSSEED;
  503.  
  504. typedef struct _KEY_TYPE_SUBTYPE {
  505.         DWORD   dwKeySpec;
  506.         GUID    Type;
  507.         GUID    Subtype;
  508. } KEY_TYPE_SUBTYPE, *PKEY_TYPE_SUBTYPE;
  509.  
  510.  
  511. WINADVAPI
  512. BOOL
  513. WINAPI
  514. CryptAcquireContextA(
  515.     HCRYPTPROV *phProv,
  516.     LPCSTR pszContainer,
  517.     LPCSTR pszProvider,
  518.     DWORD dwProvType,
  519.     DWORD dwFlags);
  520. WINADVAPI
  521. BOOL
  522. WINAPI
  523. CryptAcquireContextW(
  524.     HCRYPTPROV *phProv,
  525.     LPCWSTR pszContainer,
  526.     LPCWSTR pszProvider,
  527.     DWORD dwProvType,
  528.     DWORD dwFlags);
  529. #ifdef UNICODE
  530. #define CryptAcquireContext  CryptAcquireContextW
  531. #else
  532. #define CryptAcquireContext  CryptAcquireContextA
  533. #endif // !UNICODE
  534.  
  535.  
  536. WINADVAPI
  537. BOOL
  538. WINAPI
  539. CryptReleaseContext(
  540.     HCRYPTPROV hProv,
  541.     DWORD dwFlags);
  542.  
  543.  
  544. WINADVAPI
  545. BOOL
  546. WINAPI
  547. CryptGenKey(
  548.     HCRYPTPROV hProv,
  549.     ALG_ID Algid,
  550.     DWORD dwFlags,
  551.     HCRYPTKEY *phKey);
  552.  
  553. WINADVAPI
  554. BOOL
  555. WINAPI
  556. CryptDeriveKey(
  557.     HCRYPTPROV hProv,
  558.     ALG_ID Algid,
  559.     HCRYPTHASH hBaseData,
  560.     DWORD dwFlags,
  561.     HCRYPTKEY *phKey);
  562.  
  563.  
  564. WINADVAPI
  565. BOOL
  566. WINAPI
  567. CryptDestroyKey(
  568.     HCRYPTKEY hKey);
  569.  
  570. WINADVAPI
  571. BOOL
  572. WINAPI
  573. CryptSetKeyParam(
  574.     HCRYPTKEY hKey,
  575.     DWORD dwParam,
  576.     BYTE *pbData,
  577.     DWORD dwFlags);
  578.  
  579. WINADVAPI
  580. BOOL
  581. WINAPI
  582. CryptGetKeyParam(
  583.     HCRYPTKEY hKey,
  584.     DWORD dwParam,
  585.     BYTE *pbData,
  586.     DWORD *pdwDataLen,
  587.     DWORD dwFlags);
  588.  
  589. WINADVAPI
  590. BOOL
  591. WINAPI
  592. CryptSetHashParam(
  593.     HCRYPTHASH hHash,
  594.     DWORD dwParam,
  595.     BYTE *pbData,
  596.     DWORD dwFlags);
  597.  
  598. WINADVAPI
  599. BOOL
  600. WINAPI
  601. CryptGetHashParam(
  602.     HCRYPTHASH hHash,
  603.     DWORD dwParam,
  604.     BYTE *pbData,
  605.     DWORD *pdwDataLen,
  606.     DWORD dwFlags);
  607.  
  608. WINADVAPI
  609. BOOL
  610. WINAPI
  611. CryptSetProvParam(
  612.     HCRYPTPROV hProv,
  613.     DWORD dwParam,
  614.     BYTE *pbData,
  615.     DWORD dwFlags);
  616.  
  617. WINADVAPI
  618. BOOL
  619. WINAPI
  620. CryptGetProvParam(
  621.     HCRYPTPROV hProv,
  622.     DWORD dwParam,
  623.     BYTE *pbData,
  624.     DWORD *pdwDataLen,
  625.     DWORD dwFlags);
  626.  
  627. WINADVAPI
  628. BOOL
  629. WINAPI
  630. CryptGenRandom(
  631.     HCRYPTPROV hProv,
  632.     DWORD dwLen,
  633.     BYTE *pbBuffer);
  634.  
  635. WINADVAPI
  636. BOOL
  637. WINAPI
  638. CryptGetUserKey(
  639.     HCRYPTPROV hProv,
  640.     DWORD dwKeySpec,
  641.     HCRYPTKEY *phUserKey);
  642.  
  643. WINADVAPI
  644. BOOL
  645. WINAPI
  646. CryptExportKey(
  647.     HCRYPTKEY hKey,
  648.     HCRYPTKEY hExpKey,
  649.     DWORD dwBlobType,
  650.     DWORD dwFlags,
  651.     BYTE *pbData,
  652.     DWORD *pdwDataLen);
  653.  
  654. WINADVAPI
  655. BOOL
  656. WINAPI
  657. CryptImportKey(
  658.     HCRYPTPROV hProv,
  659.     CONST BYTE *pbData,
  660.     DWORD dwDataLen,
  661.     HCRYPTKEY hPubKey,
  662.     DWORD dwFlags,
  663.     HCRYPTKEY *phKey);
  664.  
  665. WINADVAPI
  666. BOOL
  667. WINAPI
  668. CryptEncrypt(
  669.     HCRYPTKEY hKey,
  670.     HCRYPTHASH hHash,
  671.     BOOL Final,
  672.     DWORD dwFlags,
  673.     BYTE *pbData,
  674.     DWORD *pdwDataLen,
  675.     DWORD dwBufLen);
  676.  
  677. WINADVAPI
  678. BOOL
  679. WINAPI
  680. CryptDecrypt(
  681.     HCRYPTKEY hKey,
  682.     HCRYPTHASH hHash,
  683.     BOOL Final,
  684.     DWORD dwFlags,
  685.     BYTE *pbData,
  686.     DWORD *pdwDataLen);
  687.  
  688. WINADVAPI
  689. BOOL
  690. WINAPI
  691. CryptCreateHash(
  692.     HCRYPTPROV hProv,
  693.     ALG_ID Algid,
  694.     HCRYPTKEY hKey,
  695.     DWORD dwFlags,
  696.     HCRYPTHASH *phHash);
  697.  
  698. WINADVAPI
  699. BOOL
  700. WINAPI
  701. CryptHashData(
  702.     HCRYPTHASH hHash,
  703.     CONST BYTE *pbData,
  704.     DWORD dwDataLen,
  705.     DWORD dwFlags);
  706.  
  707. WINADVAPI
  708. BOOL
  709. WINAPI
  710. CryptHashSessionKey(
  711.     HCRYPTHASH hHash,
  712.     HCRYPTKEY hKey,
  713.     DWORD dwFlags);
  714.  
  715. WINADVAPI
  716. BOOL
  717. WINAPI
  718. CryptDestroyHash(
  719.     HCRYPTHASH hHash);
  720.  
  721. WINADVAPI
  722. BOOL
  723. WINAPI
  724. CryptSignHashA(
  725.     HCRYPTHASH hHash,
  726.     DWORD dwKeySpec,
  727.     LPCSTR sDescription,
  728.     DWORD dwFlags,
  729.     BYTE *pbSignature,
  730.     DWORD *pdwSigLen);
  731. WINADVAPI
  732. BOOL
  733. WINAPI
  734. CryptSignHashW(
  735.     HCRYPTHASH hHash,
  736.     DWORD dwKeySpec,
  737.     LPCWSTR sDescription,
  738.     DWORD dwFlags,
  739.     BYTE *pbSignature,
  740.     DWORD *pdwSigLen);
  741. #ifdef UNICODE
  742. #define CryptSignHash  CryptSignHashW
  743. #else
  744. #define CryptSignHash  CryptSignHashA
  745. #endif // !UNICODE
  746.  
  747. WINADVAPI
  748. BOOL
  749. WINAPI
  750. CryptVerifySignatureA(
  751.     HCRYPTHASH hHash,
  752.     CONST BYTE *pbSignature,
  753.     DWORD dwSigLen,
  754.     HCRYPTKEY hPubKey,
  755.     LPCSTR sDescription,
  756.     DWORD dwFlags);
  757. WINADVAPI
  758. BOOL
  759. WINAPI
  760. CryptVerifySignatureW(
  761.     HCRYPTHASH hHash,
  762.     CONST BYTE *pbSignature,
  763.     DWORD dwSigLen,
  764.     HCRYPTKEY hPubKey,
  765.     LPCWSTR sDescription,
  766.     DWORD dwFlags);
  767. #ifdef UNICODE
  768. #define CryptVerifySignature  CryptVerifySignatureW
  769. #else
  770. #define CryptVerifySignature  CryptVerifySignatureA
  771. #endif // !UNICODE
  772.  
  773. WINADVAPI
  774. BOOL
  775. WINAPI
  776. CryptSetProviderA(
  777.     LPCSTR pszProvName,
  778.     DWORD dwProvType);
  779. WINADVAPI
  780. BOOL
  781. WINAPI
  782. CryptSetProviderW(
  783.     LPCWSTR pszProvName,
  784.     DWORD dwProvType);
  785. #ifdef UNICODE
  786. #define CryptSetProvider  CryptSetProviderW
  787. #else
  788. #define CryptSetProvider  CryptSetProviderA
  789. #endif // !UNICODE
  790.  
  791. WINADVAPI
  792. BOOL
  793. WINAPI
  794. CryptSetProviderExA(
  795.     LPCSTR pszProvName,
  796.     DWORD dwProvType,
  797.     DWORD *pdwReserved,
  798.     DWORD dwFlags);
  799. WINADVAPI
  800. BOOL
  801. WINAPI
  802. CryptSetProviderExW(
  803.     LPCWSTR pszProvName,
  804.     DWORD dwProvType,
  805.     DWORD *pdwReserved,
  806.     DWORD dwFlags);
  807. #ifdef UNICODE
  808. #define CryptSetProviderEx  CryptSetProviderExW
  809. #else
  810. #define CryptSetProviderEx  CryptSetProviderExA
  811. #endif // !UNICODE
  812.  
  813. WINADVAPI
  814. BOOL
  815. WINAPI
  816. CryptGetDefaultProviderA(
  817.     DWORD dwProvType,
  818.     DWORD *pdwReserved,
  819.     DWORD dwFlags,
  820.     LPSTR pszProvName,
  821.     DWORD *pcbProvName);
  822. WINADVAPI
  823. BOOL
  824. WINAPI
  825. CryptGetDefaultProviderW(
  826.     DWORD dwProvType,
  827.     DWORD *pdwReserved,
  828.     DWORD dwFlags,
  829.     LPWSTR pszProvName,
  830.     DWORD *pcbProvName);
  831. #ifdef UNICODE
  832. #define CryptGetDefaultProvider  CryptGetDefaultProviderW
  833. #else
  834. #define CryptGetDefaultProvider  CryptGetDefaultProviderA
  835. #endif // !UNICODE
  836.  
  837. WINADVAPI
  838. BOOL
  839. WINAPI CryptEnumProviderTypesA(
  840.     DWORD dwIndex,
  841.     DWORD *pdwReserved,
  842.     DWORD dwFlags,
  843.     DWORD *pdwProvType,
  844.     LPSTR pszTypeName,
  845.     DWORD *pcbTypeName);
  846. WINADVAPI
  847. BOOL
  848. WINAPI CryptEnumProviderTypesW(
  849.     DWORD dwIndex,
  850.     DWORD *pdwReserved,
  851.     DWORD dwFlags,
  852.     DWORD *pdwProvType,
  853.     LPWSTR pszTypeName,
  854.     DWORD *pcbTypeName);
  855. #ifdef UNICODE
  856. #define CryptEnumProviderTypes  CryptEnumProviderTypesW
  857. #else
  858. #define CryptEnumProviderTypes  CryptEnumProviderTypesA
  859. #endif // !UNICODE
  860.  
  861. WINADVAPI
  862. BOOL
  863. WINAPI CryptEnumProvidersA(
  864.     DWORD dwIndex,
  865.     DWORD *pdwReserved,
  866.     DWORD dwFlags,
  867.     DWORD *pdwProvType,
  868.     LPSTR pszProvName,
  869.     DWORD *pcbProvName);
  870. WINADVAPI
  871. BOOL
  872. WINAPI CryptEnumProvidersW(
  873.     DWORD dwIndex,
  874.     DWORD *pdwReserved,
  875.     DWORD dwFlags,
  876.     DWORD *pdwProvType,
  877.     LPWSTR pszProvName,
  878.     DWORD *pcbProvName);
  879. #ifdef UNICODE
  880. #define CryptEnumProviders  CryptEnumProvidersW
  881. #else
  882. #define CryptEnumProviders  CryptEnumProvidersA
  883. #endif // !UNICODE
  884.  
  885. WINADVAPI
  886. BOOL
  887. WINAPI CryptContextAddRef(
  888.     HCRYPTPROV hProv,
  889.     DWORD *pdwReserved,
  890.     DWORD dwFlags);
  891.  
  892. WINADVAPI
  893. BOOL
  894. WINAPI CryptDuplicateKey(
  895.     HCRYPTKEY hKey,
  896.     DWORD *pdwReserved,
  897.     DWORD dwFlags,
  898.     HCRYPTKEY * phKey);
  899.  
  900. WINADVAPI
  901. BOOL
  902. WINAPI CryptDuplicateHash(
  903.     HCRYPTHASH hHash,
  904.     DWORD *pdwReserved,
  905.     DWORD dwFlags,
  906.     HCRYPTHASH * phHash);
  907.  
  908. //+-------------------------------------------------------------------------
  909. //  CRYPTOAPI BLOB definitions
  910. //--------------------------------------------------------------------------
  911. typedef struct _CRYPTOAPI_BLOB {
  912.     DWORD   cbData;
  913.     BYTE    *pbData;
  914. } CRYPT_INTEGER_BLOB, *PCRYPT_INTEGER_BLOB,
  915.   CRYPT_UINT_BLOB, *PCRYPT_UINT_BLOB,
  916.   CRYPT_OBJID_BLOB, *PCRYPT_OBJID_BLOB,
  917.   CERT_NAME_BLOB, *PCERT_NAME_BLOB,
  918.   CERT_RDN_VALUE_BLOB, *PCERT_RDN_VALUE_BLOB,
  919.   CERT_BLOB, *PCERT_BLOB,
  920.   CRL_BLOB, *PCRL_BLOB,
  921.   DATA_BLOB, *PDATA_BLOB,                   // JEFFJEFF temporary (too generic)
  922.   CRYPT_DATA_BLOB, *PCRYPT_DATA_BLOB,
  923.   CRYPT_HASH_BLOB, *PCRYPT_HASH_BLOB,
  924.   CRYPT_DIGEST_BLOB, *PCRYPT_DIGEST_BLOB,
  925.   CRYPT_DER_BLOB, *PCRYPT_DER_BLOB,
  926.   CRYPT_ATTR_BLOB, *PCRYPT_ATTR_BLOB;
  927.  
  928. //+-------------------------------------------------------------------------
  929. //  In a CRYPT_BIT_BLOB the last byte may contain 0-7 unused bits. Therefore, the
  930. //  overall bit length is cbData * 8 - cUnusedBits.
  931. //--------------------------------------------------------------------------
  932. typedef struct _CRYPT_BIT_BLOB {
  933.     DWORD   cbData;
  934.     BYTE    *pbData;
  935.     DWORD   cUnusedBits;
  936. } CRYPT_BIT_BLOB, *PCRYPT_BIT_BLOB;
  937.  
  938. //+-------------------------------------------------------------------------
  939. //  Type used for any algorithm
  940. //
  941. //  Where the Parameters CRYPT_OBJID_BLOB is in its encoded representation. For most
  942. //  algorithm types, the Parameters CRYPT_OBJID_BLOB is NULL (Parameters.cbData = 0).
  943. //--------------------------------------------------------------------------
  944. typedef struct _CRYPT_ALGORITHM_IDENTIFIER {
  945.     LPSTR               pszObjId;
  946.     CRYPT_OBJID_BLOB    Parameters;
  947. } CRYPT_ALGORITHM_IDENTIFIER, *PCRYPT_ALGORITHM_IDENTIFIER;
  948.  
  949. // Following are the definitions of various algorithm object identifiers
  950. // RSA
  951. #define szOID_RSA               "1.2.840.113549"
  952. #define szOID_PKCS              "1.2.840.113549.1"
  953. #define szOID_RSA_HASH          "1.2.840.113549.2"
  954. #define szOID_RSA_ENCRYPT       "1.2.840.113549.3"
  955.  
  956. #define szOID_PKCS_1            "1.2.840.113549.1.1"
  957. #define szOID_PKCS_2            "1.2.840.113549.1.2"
  958. #define szOID_PKCS_3            "1.2.840.113549.1.3"
  959. #define szOID_PKCS_4            "1.2.840.113549.1.4"
  960. #define szOID_PKCS_5            "1.2.840.113549.1.5"
  961. #define szOID_PKCS_6            "1.2.840.113549.1.6"
  962. #define szOID_PKCS_7            "1.2.840.113549.1.7"
  963. #define szOID_PKCS_8            "1.2.840.113549.1.8"
  964. #define szOID_PKCS_9            "1.2.840.113549.1.9"
  965. #define szOID_PKCS_10           "1.2.840.113549.1.10"
  966.  
  967. #define szOID_RSA_RSA           "1.2.840.113549.1.1.1"
  968. #define szOID_RSA_MD2RSA        "1.2.840.113549.1.1.2"
  969. #define szOID_RSA_MD4RSA        "1.2.840.113549.1.1.3"
  970. #define szOID_RSA_MD5RSA        "1.2.840.113549.1.1.4"
  971. #define szOID_RSA_SHA1RSA       "1.2.840.113549.1.1.5"
  972. #define szOID_RSA_SETOAEP_RSA   "1.2.840.113549.1.1.6"
  973.  
  974. #define szOID_RSA_data          "1.2.840.113549.1.7.1"
  975. #define szOID_RSA_signedData    "1.2.840.113549.1.7.2"
  976. #define szOID_RSA_envelopedData "1.2.840.113549.1.7.3"
  977. #define szOID_RSA_signEnvData   "1.2.840.113549.1.7.4"
  978. #define szOID_RSA_digestedData  "1.2.840.113549.1.7.5"
  979. #define szOID_RSA_hashedData    "1.2.840.113549.1.7.5"
  980. #define szOID_RSA_encryptedData "1.2.840.113549.1.7.6"
  981.  
  982. #define szOID_RSA_emailAddr     "1.2.840.113549.1.9.1"
  983. #define szOID_RSA_unstructName  "1.2.840.113549.1.9.2"
  984. #define szOID_RSA_contentType   "1.2.840.113549.1.9.3"
  985. #define szOID_RSA_messageDigest "1.2.840.113549.1.9.4"
  986. #define szOID_RSA_signingTime   "1.2.840.113549.1.9.5"
  987. #define szOID_RSA_counterSign   "1.2.840.113549.1.9.6"
  988. #define szOID_RSA_challengePwd  "1.2.840.113549.1.9.7"
  989. #define szOID_RSA_unstructAddr  "1.2.840.113549.1.9.8"
  990. #define szOID_RSA_extCertAttrs  "1.2.840.113549.1.9.9"
  991. #define szOID_RSA_SMIMECapabilities "1.2.840.113549.1.9.15"
  992. #define szOID_RSA_preferSignedData "1.2.840.113549.1.9.15.1"
  993.  
  994. #define szOID_RSA_MD2           "1.2.840.113549.2.2"
  995. #define szOID_RSA_MD4           "1.2.840.113549.2.4"
  996. #define szOID_RSA_MD5           "1.2.840.113549.2.5"
  997.  
  998. #define szOID_RSA_RC2CBC        "1.2.840.113549.3.2"
  999. #define szOID_RSA_RC4           "1.2.840.113549.3.4"
  1000. #define szOID_RSA_DES_EDE3_CBC  "1.2.840.113549.3.7"
  1001. #define szOID_RSA_RC5_CBCPad    "1.2.840.113549.3.9"
  1002.  
  1003. // ITU-T UsefulDefinitions
  1004. #define szOID_DS                "2.5"
  1005. #define szOID_DSALG             "2.5.8"
  1006. #define szOID_DSALG_CRPT        "2.5.8.1"
  1007. #define szOID_DSALG_HASH        "2.5.8.2"
  1008. #define szOID_DSALG_SIGN        "2.5.8.3"
  1009. #define szOID_DSALG_RSA         "2.5.8.1.1"
  1010. // NIST OSE Implementors' Workshop (OIW)
  1011. // http://nemo.ncsl.nist.gov/oiw/agreements/stable/OSI/12s_9506.w51
  1012. // http://nemo.ncsl.nist.gov/oiw/agreements/working/OSI/12w_9503.w51
  1013. #define szOID_OIW               "1.3.14"
  1014. // NIST OSE Implementors' Workshop (OIW) Security SIG algorithm identifiers
  1015. #define szOID_OIWSEC            "1.3.14.3.2"
  1016. #define szOID_OIWSEC_md4RSA     "1.3.14.3.2.2"
  1017. #define szOID_OIWSEC_md5RSA     "1.3.14.3.2.3"
  1018. #define szOID_OIWSEC_md4RSA2    "1.3.14.3.2.4"
  1019. #define szOID_OIWSEC_desECB     "1.3.14.3.2.6"
  1020. #define szOID_OIWSEC_desCBC     "1.3.14.3.2.7"
  1021. #define szOID_OIWSEC_desOFB     "1.3.14.3.2.8"
  1022. #define szOID_OIWSEC_desCFB     "1.3.14.3.2.9"
  1023. #define szOID_OIWSEC_desMAC     "1.3.14.3.2.10"
  1024. #define szOID_OIWSEC_rsaSign    "1.3.14.3.2.11"
  1025. #define szOID_OIWSEC_dsa        "1.3.14.3.2.12"
  1026. #define szOID_OIWSEC_shaDSA     "1.3.14.3.2.13"
  1027. #define szOID_OIWSEC_mdc2RSA    "1.3.14.3.2.14"
  1028. #define szOID_OIWSEC_shaRSA     "1.3.14.3.2.15"
  1029. #define szOID_OIWSEC_dhCommMod  "1.3.14.3.2.16"
  1030. #define szOID_OIWSEC_desEDE     "1.3.14.3.2.17"
  1031. #define szOID_OIWSEC_sha        "1.3.14.3.2.18"
  1032. #define szOID_OIWSEC_mdc2       "1.3.14.3.2.19"
  1033. #define szOID_OIWSEC_dsaComm    "1.3.14.3.2.20"
  1034. #define szOID_OIWSEC_dsaCommSHA "1.3.14.3.2.21"
  1035. #define szOID_OIWSEC_rsaXchg    "1.3.14.3.2.22"
  1036. #define szOID_OIWSEC_keyHashSeal "1.3.14.3.2.23"
  1037. #define szOID_OIWSEC_md2RSASign "1.3.14.3.2.24"
  1038. #define szOID_OIWSEC_md5RSASign "1.3.14.3.2.25"
  1039. #define szOID_OIWSEC_sha1       "1.3.14.3.2.26"
  1040. #define szOID_OIWSEC_dsaSHA1    "1.3.14.3.2.27"
  1041. #define szOID_OIWSEC_dsaCommSHA1 "1.3.14.3.2.28"
  1042. #define szOID_OIWSEC_sha1RSASign "1.3.14.3.2.29"
  1043. // NIST OSE Implementors' Workshop (OIW) Directory SIG algorithm identifiers
  1044. #define szOID_OIWDIR            "1.3.14.7.2"
  1045. #define szOID_OIWDIR_CRPT       "1.3.14.7.2.1"
  1046. #define szOID_OIWDIR_HASH       "1.3.14.7.2.2"
  1047. #define szOID_OIWDIR_SIGN       "1.3.14.7.2.3"
  1048. #define szOID_OIWDIR_md2        "1.3.14.7.2.2.1"
  1049. #define szOID_OIWDIR_md2RSA     "1.3.14.7.2.3.1"
  1050.  
  1051.  
  1052. // INFOSEC Algorithms
  1053. // joint-iso-ccitt(2) country(16) us(840) organization(1) us-government(101) dod(2) id-infosec(1)
  1054. #define szOID_INFOSEC                       "2.16.840.1.101.2.1"
  1055. #define szOID_INFOSEC_sdnsSignature         "2.16.840.1.101.2.1.1.1"
  1056. #define szOID_INFOSEC_mosaicSignature       "2.16.840.1.101.2.1.1.2"
  1057. #define szOID_INFOSEC_sdnsConfidentiality   "2.16.840.1.101.2.1.1.3"
  1058. #define szOID_INFOSEC_mosaicConfidentiality "2.16.840.1.101.2.1.1.4"
  1059. #define szOID_INFOSEC_sdnsIntegrity         "2.16.840.1.101.2.1.1.5"
  1060. #define szOID_INFOSEC_mosaicIntegrity       "2.16.840.1.101.2.1.1.6"
  1061. #define szOID_INFOSEC_sdnsTokenProtection   "2.16.840.1.101.2.1.1.7"
  1062. #define szOID_INFOSEC_mosaicTokenProtection "2.16.840.1.101.2.1.1.8"
  1063. #define szOID_INFOSEC_sdnsKeyManagement     "2.16.840.1.101.2.1.1.9"
  1064. #define szOID_INFOSEC_mosaicKeyManagement   "2.16.840.1.101.2.1.1.10"
  1065. #define szOID_INFOSEC_sdnsKMandSig          "2.16.840.1.101.2.1.1.11"
  1066. #define szOID_INFOSEC_mosaicKMandSig        "2.16.840.1.101.2.1.1.12"
  1067. #define szOID_INFOSEC_SuiteASignature       "2.16.840.1.101.2.1.1.13"
  1068. #define szOID_INFOSEC_SuiteAConfidentiality "2.16.840.1.101.2.1.1.14"
  1069. #define szOID_INFOSEC_SuiteAIntegrity       "2.16.840.1.101.2.1.1.15"
  1070. #define szOID_INFOSEC_SuiteATokenProtection "2.16.840.1.101.2.1.1.16"
  1071. #define szOID_INFOSEC_SuiteAKeyManagement   "2.16.840.1.101.2.1.1.17"
  1072. #define szOID_INFOSEC_SuiteAKMandSig        "2.16.840.1.101.2.1.1.18"
  1073. #define szOID_INFOSEC_mosaicUpdatedSig      "2.16.840.1.101.2.1.1.19"
  1074. #define szOID_INFOSEC_mosaicKMandUpdSig     "2.16.840.1.101.2.1.1.20"
  1075. #define szOID_INFOSEC_mosaicUpdatedInteg    "2.16.840.1.101.2.1.1.21"
  1076.  
  1077. typedef struct _CRYPT_OBJID_TABLE {
  1078.     DWORD   dwAlgId;
  1079.     LPCSTR  pszObjId;
  1080. } CRYPT_OBJID_TABLE, *PCRYPT_OBJID_TABLE;
  1081.  
  1082.  
  1083. //+-------------------------------------------------------------------------
  1084. //  PKCS #1 HashInfo (DigestInfo)
  1085. //--------------------------------------------------------------------------
  1086. typedef struct _CRYPT_HASH_INFO {
  1087.     CRYPT_ALGORITHM_IDENTIFIER  HashAlgorithm;
  1088.     CRYPT_HASH_BLOB             Hash;
  1089. } CRYPT_HASH_INFO, *PCRYPT_HASH_INFO;
  1090.  
  1091. //+-------------------------------------------------------------------------
  1092. //  Type used for an extension to an encoded content
  1093. //
  1094. //  Where the Value's CRYPT_OBJID_BLOB is in its encoded representation.
  1095. //--------------------------------------------------------------------------
  1096. typedef struct _CERT_EXTENSION {
  1097.     LPSTR               pszObjId;
  1098.     BOOL                fCritical;
  1099.     CRYPT_OBJID_BLOB    Value;
  1100. } CERT_EXTENSION, *PCERT_EXTENSION;
  1101.  
  1102. //+-------------------------------------------------------------------------
  1103. //  AttributeTypeValue
  1104. //
  1105. //  Where the Value's CRYPT_OBJID_BLOB is in its encoded representation.
  1106. //--------------------------------------------------------------------------
  1107. typedef struct _CRYPT_ATTRIBUTE_TYPE_VALUE {
  1108.     LPSTR               pszObjId;
  1109.     CRYPT_OBJID_BLOB    Value;
  1110. } CRYPT_ATTRIBUTE_TYPE_VALUE, *PCRYPT_ATTRIBUTE_TYPE_VALUE;
  1111.  
  1112. //+-------------------------------------------------------------------------
  1113. //  Attributes
  1114. //
  1115. //  Where the Value's PATTR_BLOBs are in their encoded representation.
  1116. //--------------------------------------------------------------------------
  1117. typedef struct _CRYPT_ATTRIBUTE {
  1118.     LPSTR               pszObjId;
  1119.     DWORD               cValue;
  1120.     PCRYPT_ATTR_BLOB    rgValue;
  1121. } CRYPT_ATTRIBUTE, *PCRYPT_ATTRIBUTE;
  1122.  
  1123. typedef struct _CRYPT_ATTRIBUTES {
  1124.     IN DWORD                cAttr;
  1125.     IN PCRYPT_ATTRIBUTE     rgAttr;
  1126. } CRYPT_ATTRIBUTES, *PCRYPT_ATTRIBUTES;
  1127.  
  1128. //+-------------------------------------------------------------------------
  1129. //  Attributes making up a Relative Distinguished Name (CERT_RDN)
  1130. //
  1131. //  The interpretation of the Value depends on the dwValueType.
  1132. //  See below for a list of the types.
  1133. //--------------------------------------------------------------------------
  1134. typedef struct _CERT_RDN_ATTR {
  1135.     LPSTR                   pszObjId;
  1136.     DWORD                   dwValueType;
  1137.     CERT_RDN_VALUE_BLOB     Value;
  1138. } CERT_RDN_ATTR, *PCERT_RDN_ATTR;
  1139.  
  1140. //+-------------------------------------------------------------------------
  1141. //  CERT_RDN attribute Object Identifiers
  1142. //--------------------------------------------------------------------------
  1143. // Labeling attribute types:
  1144. #define szOID_COMMON_NAME                   "2.5.4.3"  // case-ignore string
  1145. #define szOID_SUR_NAME                      "2.5.4.4"  // case-ignore string
  1146. #define szOID_DEVICE_SERIAL_NUMBER          "2.5.4.5"  // printable string
  1147.  
  1148. // Geographic attribute types:
  1149. #define szOID_COUNTRY_NAME                  "2.5.4.6"  // printable 2char string
  1150. #define szOID_LOCALITY_NAME                 "2.5.4.7"  // case-ignore string
  1151. #define szOID_STATE_OR_PROVINCE_NAME        "2.5.4.8"  // case-ignore string
  1152. #define szOID_STREET_ADDRESS                "2.5.4.9"  // case-ignore string
  1153.  
  1154. // Organizational attribute types:
  1155. #define szOID_ORGANIZATION_NAME             "2.5.4.10" // case-ignore string
  1156. #define szOID_ORGANIZATIONAL_UNIT_NAME      "2.5.4.11" // case-ignore string
  1157. #define szOID_TITLE                         "2.5.4.12" // case-ignore string
  1158.  
  1159. // Explanatory attribute types:
  1160. #define szOID_DESCRIPTION                   "2.5.4.13" // case-ignore string
  1161. #define szOID_SEARCH_GUIDE                  "2.5.4.14"
  1162. #define szOID_BUSINESS_CATEGORY             "2.5.4.15" // case-ignore string
  1163.  
  1164. // Postal addressing attribute types:
  1165. #define szOID_POSTAL_ADDRESS                "2.5.4.16"
  1166. #define szOID_POSTAL_CODE                   "2.5.4.17" // case-ignore string
  1167. #define szOID_POST_OFFICE_BOX               "2.5.4.18" // case-ignore string
  1168. #define szOID_PHYSICAL_DELIVERY_OFFICE_NAME "2.5.4.19" // case-ignore string
  1169.  
  1170. // Telecommunications addressing attribute types:
  1171. #define szOID_TELEPHONE_NUMBER              "2.5.4.20" // telephone number
  1172. #define szOID_TELEX_NUMBER                  "2.5.4.21"
  1173. #define szOID_TELETEXT_TERMINAL_IDENTIFIER  "2.5.4.22"
  1174. #define szOID_FACSIMILE_TELEPHONE_NUMBER    "2.5.4.23"
  1175. #define szOID_X21_ADDRESS                   "2.5.4.24" // numeric string
  1176. #define szOID_INTERNATIONAL_ISDN_NUMBER     "2.5.4.25" // numeric string
  1177. #define szOID_REGISTERED_ADDRESS            "2.5.4.26"
  1178. #define szOID_DESTINATION_INDICATOR         "2.5.4.27" // printable string
  1179.  
  1180. // Preference attribute types:
  1181. #define szOID_PREFERRED_DELIVERY_METHOD     "2.5.4.28"
  1182.  
  1183. // OSI application attribute types:
  1184. #define szOID_PRESENTATION_ADDRESS          "2.5.4.29"
  1185. #define szOID_SUPPORTED_APPLICATION_CONTEXT "2.5.4.30"
  1186.  
  1187. // Relational application attribute types:
  1188. #define szOID_MEMBER                        "2.5.4.31"
  1189. #define szOID_OWNER                         "2.5.4.32"
  1190. #define szOID_ROLE_OCCUPANT                 "2.5.4.33"
  1191. #define szOID_SEE_ALSO                      "2.5.4.34"
  1192.  
  1193. // Security attribute types:
  1194. #define szOID_USER_PASSWORD                 "2.5.4.35"
  1195. #define szOID_USER_CERTIFICATE              "2.5.4.36"
  1196. #define szOID_CA_CERTIFICATE                "2.5.4.37"
  1197. #define szOID_AUTHORITY_REVOCATION_LIST     "2.5.4.38"
  1198. #define szOID_CERTIFICATE_REVOCATION_LIST   "2.5.4.39"
  1199. #define szOID_CROSS_CERTIFICATE_PAIR        "2.5.4.40"
  1200.  
  1201. // Undocumented attribute types???
  1202. //#define szOID_???                         "2.5.4.41"
  1203. #define szOID_GIVEN_NAME                    "2.5.4.42" // case-ignore string
  1204. #define szOID_INITIALS                      "2.5.4.43" // case-ignore string
  1205.  
  1206. // Pilot user attribute types:
  1207. #define szOID_DOMAIN_COMPONENT  "0.9.2342.19200300.100.1.25" // IA5 string
  1208.  
  1209. //+-------------------------------------------------------------------------
  1210. //  CERT_RDN Attribute Value Types
  1211. //
  1212. //  For RDN_ENCODED_BLOB, the Value's CERT_RDN_VALUE_BLOB is in its encoded
  1213. //  representation. Otherwise, its an array of bytes.
  1214. //
  1215. //  For all CERT_RDN types, Value.cbData is always the number of bytes, not
  1216. //  necessarily the number of elements in the string. For instance,
  1217. //  RDN_UNIVERSAL_STRING is an array of ints (cbData == intCnt * 4) and
  1218. //  RDN_BMP_STRING is an array of unsigned shorts (cbData == ushortCnt * 2).
  1219. //
  1220. //  For CertDecodeName, two 0 bytes are always appended to the end of the
  1221. //  string (ensures a CHAR or WCHAR string is null terminated).
  1222. //  These added 0 bytes are't included in the BLOB.cbData.
  1223. //--------------------------------------------------------------------------
  1224. #define CERT_RDN_ANY_TYPE                0
  1225. #define CERT_RDN_ENCODED_BLOB            1
  1226. #define CERT_RDN_OCTET_STRING            2
  1227. #define CERT_RDN_NUMERIC_STRING          3
  1228. #define CERT_RDN_PRINTABLE_STRING        4
  1229. #define CERT_RDN_TELETEX_STRING          5
  1230. #define CERT_RDN_T61_STRING              5
  1231. #define CERT_RDN_VIDEOTEX_STRING         6
  1232. #define CERT_RDN_IA5_STRING              7
  1233. #define CERT_RDN_GRAPHIC_STRING          8
  1234. #define CERT_RDN_VISIBLE_STRING          9
  1235. #define CERT_RDN_ISO646_STRING           9
  1236. #define CERT_RDN_GENERAL_STRING          10
  1237. #define CERT_RDN_UNIVERSAL_STRING        11
  1238. #define CERT_RDN_INT4_STRING             11
  1239. #define CERT_RDN_BMP_STRING              12
  1240. #define CERT_RDN_UNICODE_STRING          12
  1241.  
  1242.  
  1243. // Macro to check that the dwValueType is a character string and not an
  1244. // encoded blob or octet string
  1245. #define IS_CERT_RDN_CHAR_STRING(X) (X >= CERT_RDN_NUMERIC_STRING)
  1246.  
  1247. //+-------------------------------------------------------------------------
  1248. //  A CERT_RDN consists of an array of the above attributes
  1249. //--------------------------------------------------------------------------
  1250. typedef struct _CERT_RDN {
  1251.     DWORD           cRDNAttr;
  1252.     PCERT_RDN_ATTR  rgRDNAttr;
  1253. } CERT_RDN, *PCERT_RDN;
  1254.  
  1255. //+-------------------------------------------------------------------------
  1256. //  Information stored in a subject's or issuer's name. The information
  1257. //  is represented as an array of the above RDNs.
  1258. //--------------------------------------------------------------------------
  1259. typedef struct _CERT_NAME_INFO {
  1260.     DWORD       cRDN;
  1261.     PCERT_RDN   rgRDN;
  1262. } CERT_NAME_INFO, *PCERT_NAME_INFO;
  1263.  
  1264. //+-------------------------------------------------------------------------
  1265. //  Name attribute value without the Object Identifier
  1266. //
  1267. //  The interpretation of the Value depends on the dwValueType.
  1268. //  See above for a list of the types.
  1269. //--------------------------------------------------------------------------
  1270. typedef struct _CERT_NAME_VALUE {
  1271.     DWORD               dwValueType;
  1272.     CERT_RDN_VALUE_BLOB Value;
  1273. } CERT_NAME_VALUE, *PCERT_NAME_VALUE;
  1274.  
  1275. //+-------------------------------------------------------------------------
  1276. //  Public Key Info
  1277. //
  1278. //  The PublicKey is the encoded representation of the information as it is
  1279. //  stored in the bit string
  1280. //--------------------------------------------------------------------------
  1281. typedef struct _CERT_PUBLIC_KEY_INFO {
  1282.     CRYPT_ALGORITHM_IDENTIFIER    Algorithm;
  1283.     CRYPT_BIT_BLOB                PublicKey;
  1284. } CERT_PUBLIC_KEY_INFO, *PCERT_PUBLIC_KEY_INFO;
  1285.  
  1286. #define CERT_RSA_PUBLIC_KEY_OBJID            szOID_RSA_RSA
  1287. #define CERT_DEFAULT_OID_PUBLIC_KEY_SIGN     szOID_RSA_RSA
  1288. #define CERT_DEFAULT_OID_PUBLIC_KEY_XCHG     szOID_RSA_RSA
  1289.  
  1290. //+-------------------------------------------------------------------------
  1291. //  Information stored in a certificate
  1292. //
  1293. //  The Issuer, Subject, Algorithm, PublicKey and Extension BLOBs are the
  1294. //  encoded representation of the information.
  1295. //--------------------------------------------------------------------------
  1296. typedef struct _CERT_INFO {
  1297.     DWORD                       dwVersion;
  1298.     CRYPT_INTEGER_BLOB          SerialNumber;
  1299.     CRYPT_ALGORITHM_IDENTIFIER  SignatureAlgorithm;
  1300.     CERT_NAME_BLOB              Issuer;
  1301.     FILETIME                    NotBefore;
  1302.     FILETIME                    NotAfter;
  1303.     CERT_NAME_BLOB              Subject;
  1304.     CERT_PUBLIC_KEY_INFO        SubjectPublicKeyInfo;
  1305.     CRYPT_BIT_BLOB              IssuerUniqueId;
  1306.     CRYPT_BIT_BLOB              SubjectUniqueId;
  1307.     DWORD                       cExtension;
  1308.     PCERT_EXTENSION             rgExtension;
  1309. } CERT_INFO, *PCERT_INFO;
  1310.  
  1311. //+-------------------------------------------------------------------------
  1312. //  Certificate versions
  1313. //--------------------------------------------------------------------------
  1314. #define CERT_V1     0
  1315. #define CERT_V2     1
  1316. #define CERT_V3     2
  1317.  
  1318. //+-------------------------------------------------------------------------
  1319. //  Certificate Information Flags
  1320. //--------------------------------------------------------------------------
  1321. #define CERT_INFO_VERSION_FLAG                      1
  1322. #define CERT_INFO_SERIAL_NUMBER_FLAG                2
  1323. #define CERT_INFO_SIGNATURE_ALGORITHM_FLAG          3
  1324. #define CERT_INFO_ISSUER_FLAG                       4
  1325. #define CERT_INFO_NOT_BEFORE_FLAG                   5
  1326. #define CERT_INFO_NOT_AFTER_FLAG                    6
  1327. #define CERT_INFO_SUBJECT_FLAG                      7
  1328. #define CERT_INFO_SUBJECT_PUBLIC_KEY_INFO_FLAG      8
  1329. #define CERT_INFO_ISSUER_UNIQUE_ID_FLAG             9
  1330. #define CERT_INFO_SUBJECT_UNIQUE_ID_FLAG            10
  1331. #define CERT_INFO_EXTENSION_FLAG                    11
  1332.  
  1333. //+-------------------------------------------------------------------------
  1334. //  An entry in a CRL
  1335. //
  1336. //  The Extension BLOBs are the encoded representation of the information.
  1337. //--------------------------------------------------------------------------
  1338. typedef struct _CRL_ENTRY {
  1339.     CRYPT_INTEGER_BLOB  SerialNumber;
  1340.     FILETIME            RevocationDate;
  1341.     DWORD               cExtension;
  1342.     PCERT_EXTENSION     rgExtension;
  1343. } CRL_ENTRY, *PCRL_ENTRY;
  1344.  
  1345. //+-------------------------------------------------------------------------
  1346. //  Information stored in a CRL
  1347. //
  1348. //  The Issuer, Algorithm and Extension BLOBs are the encoded
  1349. //  representation of the information.
  1350. //--------------------------------------------------------------------------
  1351. typedef struct _CRL_INFO {
  1352.     DWORD                       dwVersion;
  1353.     CRYPT_ALGORITHM_IDENTIFIER  SignatureAlgorithm;
  1354.     CERT_NAME_BLOB              Issuer;
  1355.     FILETIME                    ThisUpdate;
  1356.     FILETIME                    NextUpdate;
  1357.     DWORD                       cCRLEntry;
  1358.     PCRL_ENTRY                  rgCRLEntry;
  1359.     DWORD                       cExtension;
  1360.     PCERT_EXTENSION             rgExtension;
  1361. } CRL_INFO, *PCRL_INFO;
  1362.  
  1363. //+-------------------------------------------------------------------------
  1364. //  CRL versions
  1365. //--------------------------------------------------------------------------
  1366. #define CRL_V1     0
  1367. #define CRL_V2     1
  1368.  
  1369.  
  1370. //+-------------------------------------------------------------------------
  1371. //  Information stored in a certificate request
  1372. //
  1373. //  The Subject, Algorithm, PublicKey and Attribute BLOBs are the encoded
  1374. //  representation of the information.
  1375. //--------------------------------------------------------------------------
  1376. typedef struct _CERT_REQUEST_INFO {
  1377.     DWORD                   dwVersion;
  1378.     CERT_NAME_BLOB          Subject;
  1379.     CERT_PUBLIC_KEY_INFO    SubjectPublicKeyInfo;
  1380.     DWORD                   cAttribute;
  1381.     PCRYPT_ATTRIBUTE        rgAttribute;
  1382. } CERT_REQUEST_INFO, *PCERT_REQUEST_INFO;
  1383.  
  1384. //+-------------------------------------------------------------------------
  1385. //  Certificate Request versions
  1386. //--------------------------------------------------------------------------
  1387. #define CERT_REQUEST_V1     0
  1388.  
  1389. //+-------------------------------------------------------------------------
  1390. //  Information stored in Netscape's Keygen request
  1391. //--------------------------------------------------------------------------
  1392. typedef struct _CERT_KEYGEN_REQUEST_INFO {
  1393.     DWORD                   dwVersion;
  1394.     CERT_PUBLIC_KEY_INFO    SubjectPublicKeyInfo;
  1395.     LPWSTR                  pwszChallengeString;        // encoded as IA5
  1396. } CERT_KEYGEN_REQUEST_INFO, *PCERT_KEYGEN_REQUEST_INFO;
  1397.  
  1398. #define CERT_KEYGEN_REQUEST_V1     0
  1399.  
  1400.  
  1401. //+-------------------------------------------------------------------------
  1402. //  Certificate, CRL, Certificate Request or Keygen Request Signed Content
  1403. //
  1404. //  The "to be signed" encoded content plus its signature. The ToBeSigned
  1405. //  is the encoded CERT_INFO, CRL_INFO, CERT_REQUEST_INFO or
  1406. //  CERT_KEYGEN_REQUEST_INFO.
  1407. //--------------------------------------------------------------------------
  1408. typedef struct _CERT_SIGNED_CONTENT_INFO {
  1409.     CRYPT_DER_BLOB              ToBeSigned;
  1410.     CRYPT_ALGORITHM_IDENTIFIER  SignatureAlgorithm;
  1411.     CRYPT_BIT_BLOB              Signature;
  1412. } CERT_SIGNED_CONTENT_INFO, *PCERT_SIGNED_CONTENT_INFO;
  1413.  
  1414.  
  1415. //+-------------------------------------------------------------------------
  1416. //  Certificate Trust List (CTL)
  1417. //--------------------------------------------------------------------------
  1418.  
  1419. //+-------------------------------------------------------------------------
  1420. //  CTL Usage. Also used for EnhancedKeyUsage extension.
  1421. //--------------------------------------------------------------------------
  1422. typedef struct _CTL_USAGE {
  1423.     DWORD               cUsageIdentifier;
  1424.     LPSTR               *rgpszUsageIdentifier;      // array of pszObjId
  1425. } CTL_USAGE, *PCTL_USAGE,
  1426.   CERT_ENHKEY_USAGE, *PCERT_ENHKEY_USAGE;
  1427.  
  1428.  
  1429. //+-------------------------------------------------------------------------
  1430. //  An entry in a CTL
  1431. //--------------------------------------------------------------------------
  1432. typedef struct _CTL_ENTRY {
  1433.     CRYPT_DATA_BLOB     SubjectIdentifier;          // For example, its hash
  1434.     DWORD               cAttribute;
  1435.     PCRYPT_ATTRIBUTE    rgAttribute;                // OPTIONAL
  1436. } CTL_ENTRY, *PCTL_ENTRY;
  1437.  
  1438. //+-------------------------------------------------------------------------
  1439. //  Information stored in a CTL
  1440. //--------------------------------------------------------------------------
  1441. typedef struct _CTL_INFO {
  1442.     DWORD                       dwVersion;
  1443.     CTL_USAGE                   SubjectUsage;
  1444.     CRYPT_DATA_BLOB             ListIdentifier;     // OPTIONAL
  1445.     CRYPT_INTEGER_BLOB          SequenceNumber;     // OPTIONAL
  1446.     FILETIME                    ThisUpdate;
  1447.     FILETIME                    NextUpdate;         // OPTIONAL
  1448.     CRYPT_ALGORITHM_IDENTIFIER  SubjectAlgorithm;
  1449.     DWORD                       cCTLEntry;
  1450.     PCTL_ENTRY                  rgCTLEntry;         // OPTIONAL
  1451.     DWORD                       cExtension;
  1452.     PCERT_EXTENSION             rgExtension;        // OPTIONAL
  1453. } CTL_INFO, *PCTL_INFO;
  1454.  
  1455. //+-------------------------------------------------------------------------
  1456. //  CTL versions
  1457. //--------------------------------------------------------------------------
  1458. #define CTL_V1     0
  1459.  
  1460.  
  1461. //+-------------------------------------------------------------------------
  1462. //  TimeStamp Request
  1463. //
  1464. //  The pszTimeStamp is the OID for the Time type requested
  1465. //  The pszContentType is the Content Type OID for the content, usually DATA
  1466. //  The Content is a un-decoded blob
  1467. //--------------------------------------------------------------------------
  1468. typedef struct _CRYPT_TIME_STAMP_REQUEST_INFO {
  1469.     LPSTR                   pszTimeStampAlgorithm;   // pszObjId
  1470.     LPSTR                   pszContentType;          // pszObjId
  1471.     CRYPT_OBJID_BLOB        Content;
  1472.     DWORD                   cAttribute;
  1473.     PCRYPT_ATTRIBUTE        rgAttribute;
  1474. } CRYPT_TIME_STAMP_REQUEST_INFO, *PCRYPT_TIME_STAMP_REQUEST_INFO;
  1475.  
  1476. //+-------------------------------------------------------------------------
  1477. //  Certificate and Message encoding types
  1478. //
  1479. //  The encoding type is a DWORD containing both the certificate and message
  1480. //  encoding types. The certificate encoding type is stored in the LOWORD.
  1481. //  The message encoding type is stored in the HIWORD. Some functions or
  1482. //  structure fields require only one of the encoding types. The following
  1483. //  naming convention is used to indicate which encoding type(s) are
  1484. //  required:
  1485. //      dwEncodingType              (both encoding types are required)
  1486. //      dwMsgAndCertEncodingType    (both encoding types are required)
  1487. //      dwMsgEncodingType           (only msg encoding type is required)
  1488. //      dwCertEncodingType          (only cert encoding type is required)
  1489. //
  1490. //  Its always acceptable to specify both.
  1491. //--------------------------------------------------------------------------
  1492. #define CERT_ENCODING_TYPE_MASK     0x0000FFFF
  1493. #define CMSG_ENCODING_TYPE_MASK     0xFFFF0000
  1494. #define GET_CERT_ENCODING_TYPE(X)   (X & CERT_ENCODING_TYPE_MASK)
  1495. #define GET_CMSG_ENCODING_TYPE(X)   (X & CMSG_ENCODING_TYPE_MASK)
  1496.  
  1497. #define CRYPT_ASN_ENCODING          0x00000001
  1498. #define CRYPT_NDR_ENCODING          0x00000002
  1499. #define X509_ASN_ENCODING           0x00000001
  1500. #define X509_NDR_ENCODING           0x00000002
  1501. #define PKCS_7_ASN_ENCODING         0x00010000
  1502. #define PKCS_7_NDR_ENCODING         0x00020000
  1503.  
  1504.  
  1505. //+-------------------------------------------------------------------------
  1506. //  format the specified data structure according to the certificate
  1507. //  encoding type.
  1508. //
  1509. //--------------------------------------------------------------------------
  1510. WINCRYPT32API
  1511. BOOL
  1512. WINAPI
  1513. CryptFormatObject(
  1514.     IN DWORD dwCertEncodingType,
  1515.     IN DWORD dwFormatType,
  1516.     IN DWORD dwFormatStrType,
  1517.     IN void     *pFormatStruct,
  1518.     IN LPCSTR lpszStructType,
  1519.     IN const BYTE *pbEncoded,
  1520.     IN DWORD cbEncoded,
  1521.     OUT void *pbFormat,
  1522.     IN OUT DWORD *pcbFormat
  1523.     );
  1524.  
  1525. //+-------------------------------------------------------------------------
  1526. //  Encode / decode the specified data structure according to the certificate
  1527. //  encoding type.
  1528. //
  1529. //  See below for a list of the predefined data structures.
  1530. //--------------------------------------------------------------------------
  1531.  
  1532.  
  1533. WINCRYPT32API
  1534. BOOL
  1535. WINAPI
  1536. CryptEncodeObject(
  1537.     IN DWORD        dwCertEncodingType,
  1538.     IN LPCSTR       lpszStructType,
  1539.     IN const void   *pvStructInfo,
  1540.     OUT BYTE        *pbEncoded,
  1541.     IN OUT DWORD    *pcbEncoded
  1542.     );
  1543.  
  1544. WINCRYPT32API
  1545. BOOL
  1546. WINAPI
  1547. CryptDecodeObject(
  1548.     IN DWORD        dwCertEncodingType,
  1549.     IN LPCSTR       lpszStructType,
  1550.     IN const BYTE   *pbEncoded,
  1551.     IN DWORD        cbEncoded,
  1552.     IN DWORD        dwFlags,
  1553.     OUT void        *pvStructInfo,
  1554.     IN OUT DWORD    *pcbStructInfo
  1555.     );
  1556.  
  1557. // When the following flag is set the nocopy optimization is enabled.
  1558. // This optimization where appropriate, updates the pvStructInfo fields
  1559. // to point to content residing within pbEncoded instead of making a copy
  1560. // of and appending to pvStructInfo.
  1561. //
  1562. // Note, when set, pbEncoded can't be freed until pvStructInfo is freed.
  1563. #define CRYPT_DECODE_NOCOPY_FLAG            0x1
  1564.  
  1565. //+-------------------------------------------------------------------------
  1566. //  Predefined X509 certificate data structures that can be encoded / decoded.
  1567. //--------------------------------------------------------------------------
  1568. #define CRYPT_ENCODE_DECODE_NONE            0
  1569. #define X509_CERT                           ((LPCSTR) 1)
  1570. #define X509_CERT_TO_BE_SIGNED              ((LPCSTR) 2)
  1571. #define X509_CERT_CRL_TO_BE_SIGNED          ((LPCSTR) 3)
  1572. #define X509_CERT_REQUEST_TO_BE_SIGNED      ((LPCSTR) 4)
  1573. #define X509_EXTENSIONS                     ((LPCSTR) 5)
  1574. #define X509_NAME_VALUE                     ((LPCSTR) 6)
  1575. #define X509_NAME                           ((LPCSTR) 7)
  1576. #define X509_PUBLIC_KEY_INFO                ((LPCSTR) 8)
  1577.  
  1578. //+-------------------------------------------------------------------------
  1579. //  Predefined X509 certificate extension data structures that can be
  1580. //  encoded / decoded.
  1581. //--------------------------------------------------------------------------
  1582. #define X509_AUTHORITY_KEY_ID               ((LPCSTR) 9)
  1583. #define X509_KEY_ATTRIBUTES                 ((LPCSTR) 10)
  1584. #define X509_KEY_USAGE_RESTRICTION          ((LPCSTR) 11)
  1585. #define X509_ALTERNATE_NAME                 ((LPCSTR) 12)
  1586. #define X509_BASIC_CONSTRAINTS              ((LPCSTR) 13)
  1587. #define X509_KEY_USAGE                      ((LPCSTR) 14)
  1588. #define X509_BASIC_CONSTRAINTS2             ((LPCSTR) 15)
  1589. #define X509_CERT_POLICIES                  ((LPCSTR) 16)
  1590.  
  1591. //+-------------------------------------------------------------------------
  1592. //  Additional predefined data structures that can be encoded / decoded.
  1593. //--------------------------------------------------------------------------
  1594. #define PKCS_UTC_TIME                       ((LPCSTR) 17)
  1595. #define PKCS_TIME_REQUEST                   ((LPCSTR) 18)
  1596. #define RSA_CSP_PUBLICKEYBLOB               ((LPCSTR) 19)
  1597. #define X509_UNICODE_NAME                   ((LPCSTR) 20)
  1598.  
  1599. #define X509_KEYGEN_REQUEST_TO_BE_SIGNED    ((LPCSTR) 21)
  1600. #define PKCS_ATTRIBUTE                      ((LPCSTR) 22)
  1601. #define PKCS_CONTENT_INFO_SEQUENCE_OF_ANY   ((LPCSTR) 23)
  1602.  
  1603. //+-------------------------------------------------------------------------
  1604. //  Predefined primitive data structures that can be encoded / decoded.
  1605. //--------------------------------------------------------------------------
  1606. #define X509_UNICODE_NAME_VALUE             ((LPCSTR) 24)
  1607. #define X509_ANY_STRING                     X509_NAME_VALUE
  1608. #define X509_UNICODE_ANY_STRING             X509_UNICODE_NAME_VALUE
  1609. #define X509_OCTET_STRING                   ((LPCSTR) 25)
  1610. #define X509_BITS                           ((LPCSTR) 26)
  1611. #define X509_INTEGER                        ((LPCSTR) 27)
  1612. #define X509_MULTI_BYTE_INTEGER             ((LPCSTR) 28)
  1613. #define X509_ENUMERATED                     ((LPCSTR) 29)
  1614. #define X509_CHOICE_OF_TIME                 ((LPCSTR) 30)
  1615.  
  1616. //+-------------------------------------------------------------------------
  1617. //  More predefined X509 certificate extension data structures that can be
  1618. //  encoded / decoded.
  1619. //--------------------------------------------------------------------------
  1620. #define X509_AUTHORITY_KEY_ID2              ((LPCSTR) 31)
  1621. //#define X509_AUTHORITY_INFO_ACCESS          ((LPCSTR) 32)
  1622. #define X509_CRL_REASON_CODE                X509_ENUMERATED
  1623. #define PKCS_CONTENT_INFO                   ((LPCSTR) 33)
  1624. #define X509_SEQUENCE_OF_ANY                ((LPCSTR) 34)
  1625. #define X509_CRL_DIST_POINTS                ((LPCSTR) 35)
  1626. #define X509_ENHANCED_KEY_USAGE             ((LPCSTR) 36)
  1627. #define PKCS_CTL                            ((LPCSTR) 37)
  1628.  
  1629. #define X509_MULTI_BYTE_UINT                ((LPCSTR) 38)
  1630. #define X509_DSS_PUBLICKEY                  X509_MULTI_BYTE_UINT
  1631. #define X509_DSS_PARAMETERS                 ((LPCSTR) 39)
  1632. #define X509_DSS_SIGNATURE                  ((LPCSTR) 40)
  1633. #define PKCS_RC2_CBC_PARAMETERS             ((LPCSTR) 41)
  1634. #define PKCS_SMIME_CAPABILITIES             ((LPCSTR) 42)
  1635.  
  1636.  
  1637. //+-------------------------------------------------------------------------
  1638. //  Predefined PKCS #7 data structures that can be encoded / decoded.
  1639. //--------------------------------------------------------------------------
  1640. #define PKCS7_SIGNER_INFO                   ((LPCSTR) 500)
  1641.  
  1642. //+-------------------------------------------------------------------------
  1643. //  Predefined Software Publishing Credential (SPC)  data structures that
  1644. //  can be encoded / decoded.
  1645. //
  1646. //  Predefined values: 2000 .. 2999
  1647. //
  1648. //  See spc.h for value and data structure definitions.
  1649. //--------------------------------------------------------------------------
  1650.  
  1651. //+-------------------------------------------------------------------------
  1652. //  Extension Object Identifiers
  1653. //--------------------------------------------------------------------------
  1654. #define szOID_AUTHORITY_KEY_IDENTIFIER  "2.5.29.1"
  1655. #define szOID_KEY_ATTRIBUTES            "2.5.29.2"
  1656. #define szOID_KEY_USAGE_RESTRICTION     "2.5.29.4"
  1657. #define szOID_SUBJECT_ALT_NAME          "2.5.29.7"
  1658. #define szOID_ISSUER_ALT_NAME           "2.5.29.8"
  1659. #define szOID_BASIC_CONSTRAINTS         "2.5.29.10"
  1660. #define szOID_KEY_USAGE                 "2.5.29.15"
  1661. #define szOID_BASIC_CONSTRAINTS2        "2.5.29.19"
  1662. #define szOID_CERT_POLICIES             "2.5.29.32"
  1663.  
  1664. #define szOID_AUTHORITY_KEY_IDENTIFIER2 "2.5.29.35"
  1665. #define szOID_SUBJECT_KEY_IDENTIFIER    "2.5.29.14"
  1666. #define szOID_SUBJECT_ALT_NAME2         "2.5.29.17"
  1667. #define szOID_ISSUER_ALT_NAME2          "2.5.29.18"
  1668. #define szOID_CRL_REASON_CODE           "2.5.29.21"
  1669. #define szOID_CRL_DIST_POINTS           "2.5.29.31"
  1670. #define szOID_ENHANCED_KEY_USAGE        "2.5.29.37"
  1671.  
  1672.  
  1673. // Internet Public Key Infrastructure
  1674. #define szOID_PKIX                      "1.3.6.1.5.5.7"
  1675. #define szOID_AUTHORITY_INFO_ACCESS     "1.3.6.1.5.5.7.2"
  1676.  
  1677. // Microsoft extensions or attributes
  1678. #define szOID_CERT_EXTENSIONS           "1.3.6.1.4.1.311.2.1.14"
  1679. #define szOID_NEXT_UPDATE_LOCATION      "1.3.6.1.4.1.311.10.2"
  1680.  
  1681. //  Microsoft PKCS #7 ContentType Object Identifiers
  1682. #define szOID_CTL                       "1.3.6.1.4.1.311.10.1"
  1683.  
  1684. //+-------------------------------------------------------------------------
  1685. //  Extension Object Identifiers (currently not implemented)
  1686. //--------------------------------------------------------------------------
  1687. #define szOID_POLICY_MAPPINGS           "2.5.29.5"
  1688. #define szOID_SUBJECT_DIR_ATTRS         "2.5.29.9"
  1689.  
  1690. //+-------------------------------------------------------------------------
  1691. //  Enhanced Key Usage (Purpose) Object Identifiers
  1692. //--------------------------------------------------------------------------
  1693. #define szOID_PKIX_KP                   "1.3.6.1.5.5.7.3"
  1694.  
  1695. // Consistent key usage bits: DIGITAL_SIGNATURE, KEY_ENCIPHERMENT
  1696. // or KEY_AGREEMENT
  1697. #define szOID_PKIX_KP_SERVER_AUTH       "1.3.6.1.5.5.7.3.1"
  1698.  
  1699. // Consistent key usage bits: DIGITAL_SIGNATURE
  1700. #define szOID_PKIX_KP_CLIENT_AUTH       "1.3.6.1.5.5.7.3.2"
  1701.  
  1702. // Consistent key usage bits: DIGITAL_SIGNATURE
  1703. #define szOID_PKIX_KP_CODE_SIGNING      "1.3.6.1.5.5.7.3.3"
  1704.  
  1705. // Consistent key usage bits: DIGITAL_SIGNATURE, NON_REPUDIATION and/or
  1706. // (KEY_ENCIPHERMENT or KEY_AGREEMENT)
  1707. #define szOID_PKIX_KP_EMAIL_PROTECTION  "1.3.6.1.5.5.7.3.4"
  1708.  
  1709. //+-------------------------------------------------------------------------
  1710. //  Microsoft Enhanced Key Usage (Purpose) Object Identifiers
  1711. //+-------------------------------------------------------------------------
  1712.  
  1713. //  Signer of CTLs
  1714. #define szOID_KP_CTL_USAGE_SIGNING      "1.3.6.1.4.1.311.10.3.1"
  1715.  
  1716. //  Signer of TimeStamps
  1717. #define szOID_KP_TIME_STAMP_SIGNING         "1.3.6.1.4.1.311.10.3.2"
  1718.  
  1719. //+-------------------------------------------------------------------------
  1720. //  Microsoft Attribute Object Identifiers
  1721. //+-------------------------------------------------------------------------
  1722. #define szOID_YESNO_TRUST_ATTR          "1.3.6.1.4.1.311.10.4.1"
  1723.  
  1724. //+-------------------------------------------------------------------------
  1725. //  X509_CERT
  1726. //
  1727. //  The "to be signed" encoded content plus its signature. The ToBeSigned
  1728. //  content is the CryptEncodeObject() output for one of the following:
  1729. //  X509_CERT_TO_BE_SIGNED, X509_CERT_CRL_TO_BE_SIGNED or
  1730. //  X509_CERT_REQUEST_TO_BE_SIGNED.
  1731. //
  1732. //  pvStructInfo points to CERT_SIGNED_CONTENT_INFO.
  1733. //--------------------------------------------------------------------------
  1734.  
  1735. //+-------------------------------------------------------------------------
  1736. //  X509_CERT_TO_BE_SIGNED
  1737. //
  1738. //  pvStructInfo points to CERT_INFO.
  1739. //
  1740. //  For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  1741. //  signature (output of a X509_CERT CryptEncodeObject()).
  1742. //
  1743. //  For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  1744. //--------------------------------------------------------------------------
  1745.  
  1746. //+-------------------------------------------------------------------------
  1747. //  X509_CERT_CRL_TO_BE_SIGNED
  1748. //
  1749. //  pvStructInfo points to CRL_INFO.
  1750. //
  1751. //  For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  1752. //  signature (output of a X509_CERT CryptEncodeObject()).
  1753. //
  1754. //  For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  1755. //--------------------------------------------------------------------------
  1756.  
  1757. //+-------------------------------------------------------------------------
  1758. //  X509_CERT_REQUEST_TO_BE_SIGNED
  1759. //
  1760. //  pvStructInfo points to CERT_REQUEST_INFO.
  1761. //
  1762. //  For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  1763. //  signature (output of a X509_CERT CryptEncodeObject()).
  1764. //
  1765. //  For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  1766. //--------------------------------------------------------------------------
  1767.  
  1768. //+-------------------------------------------------------------------------
  1769. //  X509_EXTENSIONS
  1770. //  szOID_CERT_EXTENSIONS
  1771. //
  1772. //  pvStructInfo points to following CERT_EXTENSIONS.
  1773. //--------------------------------------------------------------------------
  1774. typedef struct _CERT_EXTENSIONS {
  1775.     DWORD           cExtension;
  1776.     PCERT_EXTENSION rgExtension;
  1777. } CERT_EXTENSIONS, *PCERT_EXTENSIONS;
  1778.  
  1779. //+-------------------------------------------------------------------------
  1780. //  X509_NAME_VALUE
  1781. //  X509_ANY_STRING
  1782. //
  1783. //  pvStructInfo points to CERT_NAME_VALUE.
  1784. //--------------------------------------------------------------------------
  1785.  
  1786. //+-------------------------------------------------------------------------
  1787. //  X509_UNICODE_NAME_VALUE
  1788. //  X509_UNICODE_ANY_STRING
  1789. //
  1790. //  pvStructInfo points to CERT_NAME_VALUE.
  1791. //
  1792. //  The name values are unicode strings.
  1793. //
  1794. //  For CryptEncodeObject:
  1795. //    Value.pbData points to the unicode string.
  1796. //    If Value.cbData = 0, then, the unicode string is NULL terminated.
  1797. //    Otherwise, Value.cbData is the unicode string byte count. The byte count
  1798. //    is twice the character count.
  1799. //
  1800. //    If the unicode string contains an invalid character for the specified
  1801. //    dwValueType, then, *pcbEncoded is updated with the unicode character
  1802. //    index of the first invalid character. LastError is set to:
  1803. //    CRYPT_E_INVALID_NUMERIC_STRING, CRYPT_E_INVALID_PRINTABLE_STRING or
  1804. //    CRYPT_E_INVALID_IA5_STRING.
  1805. //
  1806. //    The unicode string is converted before being encoded according to
  1807. //    the specified dwValueType. If dwValueType is set to 0, LastError
  1808. //    is set to E_INVALIDARG.
  1809. //
  1810. //    If the dwValueType isn't one of the character strings (its a
  1811. //    CERT_RDN_ENCODED_BLOB or CERT_RDN_OCTET_STRING), then, CryptEncodeObject
  1812. //    will return FALSE with LastError set to CRYPT_E_NOT_CHAR_STRING.
  1813. //
  1814. //  For CryptDecodeObject:
  1815. //    Value.pbData points to a NULL terminated unicode string. Value.cbData
  1816. //    contains the byte count of the unicode string excluding the NULL
  1817. //    terminator. dwValueType contains the type used in the encoded object.
  1818. //    Its not forced to CERT_RDN_UNICODE_STRING. The encoded value is
  1819. //    converted to the unicode string according to the dwValueType.
  1820. //
  1821. //    If the encoded object isn't one of the character string types, then,
  1822. //    CryptDecodeObject will return FALSE with LastError set to
  1823. //    CRYPT_E_NOT_CHAR_STRING. For a non character string, decode using
  1824. //    X509_NAME_VALUE or X509_ANY_STRING.
  1825. //--------------------------------------------------------------------------
  1826.  
  1827. //+-------------------------------------------------------------------------
  1828. //  X509_NAME
  1829. //
  1830. //  pvStructInfo points to CERT_NAME_INFO.
  1831. //--------------------------------------------------------------------------
  1832.  
  1833. //+-------------------------------------------------------------------------
  1834. //  X509_UNICODE_NAME
  1835. //
  1836. //  pvStructInfo points to CERT_NAME_INFO.
  1837. //
  1838. //  The RDN attribute values are unicode strings except for the dwValueTypes of
  1839. //  CERT_RDN_ENCODED_BLOB or CERT_RDN_OCTET_STRING. These dwValueTypes are
  1840. //  the same as for a X509_NAME. Their values aren't converted to/from unicode.
  1841. //
  1842. //  For CryptEncodeObject:
  1843. //    Value.pbData points to the unicode string.
  1844. //    If Value.cbData = 0, then, the unicode string is NULL terminated.
  1845. //    Otherwise, Value.cbData is the unicode string byte count. The byte count
  1846. //    is twice the character count.
  1847. //
  1848. //    If dwValueType = 0 (CERT_RDN_ANY_TYPE), the pszObjId is used to find
  1849. //    an acceptable dwValueType. If the unicode string contains an
  1850. //    invalid character for the found or specified dwValueType, then,
  1851. //    *pcbEncoded is updated with the error location of the invalid character.
  1852. //    See below for details. LastError is set to:
  1853. //    CRYPT_E_INVALID_NUMERIC_STRING, CRYPT_E_INVALID_PRINTABLE_STRING or
  1854. //    CRYPT_E_INVALID_IA5_STRING.
  1855. //
  1856. //    The unicode string is converted before being encoded according to
  1857. //    the specified or ObjId matching dwValueType.
  1858. //
  1859. //  For CryptDecodeObject:
  1860. //    Value.pbData points to a NULL terminated unicode string. Value.cbData
  1861. //    contains the byte count of the unicode string excluding the NULL
  1862. //    terminator. dwValueType contains the type used in the encoded object.
  1863. //    Its not forced to CERT_RDN_UNICODE_STRING. The encoded value is
  1864. //    converted to the unicode string according to the dwValueType.
  1865. //
  1866. //    If the dwValueType of the encoded value isn't a character string
  1867. //    type, then, it isn't converted to UNICODE. Use the
  1868. //    IS_CERT_RDN_CHAR_STRING() macro on the dwValueType to check
  1869. //    that Value.pbData points to a converted unicode string.
  1870. //--------------------------------------------------------------------------
  1871.  
  1872. //+-------------------------------------------------------------------------
  1873. //  Unicode Name Value Error Location Definitions
  1874. //
  1875. //  Error location is returned in *pcbEncoded by
  1876. //  CryptEncodeObject(X509_UNICODE_NAME)
  1877. //
  1878. //  Error location consists of:
  1879. //    RDN_INDEX     - 10 bits << 22
  1880. //    ATTR_INDEX    - 6 bits << 16
  1881. //    VALUE_INDEX   - 16 bits (unicode character index)
  1882. //--------------------------------------------------------------------------
  1883. #define CERT_UNICODE_RDN_ERR_INDEX_MASK     0x3FF
  1884. #define CERT_UNICODE_RDN_ERR_INDEX_SHIFT    22
  1885. #define CERT_UNICODE_ATTR_ERR_INDEX_MASK    0x003F
  1886. #define CERT_UNICODE_ATTR_ERR_INDEX_SHIFT   16
  1887. #define CERT_UNICODE_VALUE_ERR_INDEX_MASK   0x0000FFFF
  1888. #define CERT_UNICODE_VALUE_ERR_INDEX_SHIFT  0
  1889.  
  1890. #define GET_CERT_UNICODE_RDN_ERR_INDEX(X)   \
  1891.     ((X >> CERT_UNICODE_RDN_ERR_INDEX_SHIFT) & CERT_UNICODE_RDN_ERR_INDEX_MASK)
  1892. #define GET_CERT_UNICODE_ATTR_ERR_INDEX(X)  \
  1893.     ((X >> CERT_UNICODE_ATTR_ERR_INDEX_SHIFT) & CERT_UNICODE_ATTR_ERR_INDEX_MASK)
  1894. #define GET_CERT_UNICODE_VALUE_ERR_INDEX(X) \
  1895.     (X & CERT_UNICODE_VALUE_ERR_INDEX_MASK)
  1896.  
  1897. //+-------------------------------------------------------------------------
  1898. //  X509_PUBLIC_KEY_INFO
  1899. //
  1900. //  pvStructInfo points to CERT_PUBLIC_KEY_INFO.
  1901. //--------------------------------------------------------------------------
  1902.  
  1903.  
  1904. //+-------------------------------------------------------------------------
  1905. //  X509_AUTHORITY_KEY_ID
  1906. //  szOID_AUTHORITY_KEY_IDENTIFIER
  1907. //
  1908. //  pvStructInfo points to following CERT_AUTHORITY_KEY_ID_INFO.
  1909. //--------------------------------------------------------------------------
  1910. typedef struct _CERT_AUTHORITY_KEY_ID_INFO {
  1911.     CRYPT_DATA_BLOB     KeyId;
  1912.     CERT_NAME_BLOB      CertIssuer;
  1913.     CRYPT_INTEGER_BLOB  CertSerialNumber;
  1914. } CERT_AUTHORITY_KEY_ID_INFO, *PCERT_AUTHORITY_KEY_ID_INFO;
  1915.  
  1916. //+-------------------------------------------------------------------------
  1917. //  X509_KEY_ATTRIBUTES
  1918. //  szOID_KEY_ATTRIBUTES
  1919. //
  1920. //  pvStructInfo points to following CERT_KEY_ATTRIBUTES_INFO.
  1921. //--------------------------------------------------------------------------
  1922. typedef struct _CERT_PRIVATE_KEY_VALIDITY {
  1923.     FILETIME                NotBefore;
  1924.     FILETIME                NotAfter;
  1925. } CERT_PRIVATE_KEY_VALIDITY, *PCERT_PRIVATE_KEY_VALIDITY;
  1926.  
  1927. typedef struct _CERT_KEY_ATTRIBUTES_INFO {
  1928.     CRYPT_DATA_BLOB             KeyId;
  1929.     CRYPT_BIT_BLOB              IntendedKeyUsage;
  1930.     PCERT_PRIVATE_KEY_VALIDITY  pPrivateKeyUsagePeriod;     // OPTIONAL
  1931. } CERT_KEY_ATTRIBUTES_INFO, *PCERT_KEY_ATTRIBUTES_INFO;
  1932.  
  1933. #define CERT_DIGITAL_SIGNATURE_KEY_USAGE     0x80
  1934. #define CERT_NON_REPUDIATION_KEY_USAGE       0x40
  1935. #define CERT_KEY_ENCIPHERMENT_KEY_USAGE      0x20
  1936. #define CERT_DATA_ENCIPHERMENT_KEY_USAGE     0x10
  1937. #define CERT_KEY_AGREEMENT_KEY_USAGE         0x08
  1938. #define CERT_KEY_CERT_SIGN_KEY_USAGE         0x04
  1939. #define CERT_OFFLINE_CRL_SIGN_KEY_USAGE      0x02
  1940.  
  1941. #define CERT_CRL_SIGN_KEY_USAGE              0x02
  1942.  
  1943. //+-------------------------------------------------------------------------
  1944. //  X509_KEY_USAGE_RESTRICTION
  1945. //  szOID_KEY_USAGE_RESTRICTION
  1946. //
  1947. //  pvStructInfo points to following CERT_KEY_USAGE_RESTRICTION_INFO.
  1948. //--------------------------------------------------------------------------
  1949. typedef struct _CERT_POLICY_ID {
  1950.     DWORD                   cCertPolicyElementId;
  1951.     LPSTR                   *rgpszCertPolicyElementId;  // pszObjId
  1952. } CERT_POLICY_ID, *PCERT_POLICY_ID;
  1953.  
  1954. typedef struct _CERT_KEY_USAGE_RESTRICTION_INFO {
  1955.     DWORD                   cCertPolicyId;
  1956.     PCERT_POLICY_ID         rgCertPolicyId;
  1957.     CRYPT_BIT_BLOB          RestrictedKeyUsage;
  1958. } CERT_KEY_USAGE_RESTRICTION_INFO, *PCERT_KEY_USAGE_RESTRICTION_INFO;
  1959.  
  1960. // See CERT_KEY_ATTRIBUTES_INFO for definition of the RestrictedKeyUsage bits
  1961.  
  1962. //+-------------------------------------------------------------------------
  1963. //  X509_ALTERNATE_NAME
  1964. //  szOID_SUBJECT_ALT_NAME
  1965. //  szOID_ISSUER_ALT_NAME
  1966. //  szOID_SUBJECT_ALT_NAME2
  1967. //  szOID_ISSUER_ALT_NAME2
  1968. //
  1969. //  pvStructInfo points to following CERT_ALT_NAME_INFO.
  1970. //--------------------------------------------------------------------------
  1971.  
  1972. typedef struct _CERT_ALT_NAME_ENTRY {
  1973.     DWORD   dwAltNameChoice;
  1974.     union {
  1975.         // Not implemented          OtherName;          // 1
  1976.         LPWSTR                      pwszRfc822Name;     // 2  (encoded IA5)
  1977.         LPWSTR                      pwszDNSName;        // 3  (encoded IA5)
  1978.         // Not implemented          x400Address;        // 4
  1979.         CERT_NAME_BLOB              DirectoryName;      // 5
  1980.         // Not implemented          pEdiPartyName;      // 6
  1981.         LPWSTR                      pwszURL;            // 7  (encoded IA5)
  1982.         CRYPT_DATA_BLOB             IPAddress;          // 8  (Octet String)
  1983.         LPSTR                       pszRegisteredID;    // 9  (Object Identifer)
  1984.     };
  1985. } CERT_ALT_NAME_ENTRY, *PCERT_ALT_NAME_ENTRY;
  1986.  
  1987. #define CERT_ALT_NAME_OTHER_NAME         1
  1988. #define CERT_ALT_NAME_RFC822_NAME        2
  1989. #define CERT_ALT_NAME_DNS_NAME           3
  1990. #define CERT_ALT_NAME_X400_ADDRESS       4
  1991. #define CERT_ALT_NAME_DIRECTORY_NAME     5
  1992. #define CERT_ALT_NAME_EDI_PARTY_NAME     6
  1993. #define CERT_ALT_NAME_URL                7
  1994. #define CERT_ALT_NAME_IP_ADDRESS         8
  1995. #define CERT_ALT_NAME_REGISTERED_ID      9
  1996.  
  1997.  
  1998. typedef struct _CERT_ALT_NAME_INFO {
  1999.     DWORD                   cAltEntry;
  2000.     PCERT_ALT_NAME_ENTRY    rgAltEntry;
  2001. } CERT_ALT_NAME_INFO, *PCERT_ALT_NAME_INFO;
  2002.  
  2003. //+-------------------------------------------------------------------------
  2004. //  Alternate name IA5 Error Location Definitions for
  2005. //  CRYPT_E_INVALID_IA5_STRING.
  2006. //
  2007. //  Error location is returned in *pcbEncoded by
  2008. //  CryptEncodeObject(X509_ALTERNATE_NAME)
  2009. //
  2010. //  Error location consists of:
  2011. //    ENTRY_INDEX   - 8 bits << 16
  2012. //    VALUE_INDEX   - 16 bits (unicode character index)
  2013. //--------------------------------------------------------------------------
  2014. #define CERT_ALT_NAME_ENTRY_ERR_INDEX_MASK  0xFF
  2015. #define CERT_ALT_NAME_ENTRY_ERR_INDEX_SHIFT 16
  2016. #define CERT_ALT_NAME_VALUE_ERR_INDEX_MASK  0x0000FFFF
  2017. #define CERT_ALT_NAME_VALUE_ERR_INDEX_SHIFT 0
  2018.  
  2019. #define GET_CERT_ALT_NAME_ENTRY_ERR_INDEX(X)   \
  2020.     ((X >> CERT_ALT_NAME_ENTRY_ERR_INDEX_SHIFT) & \
  2021.     CERT_ALT_NAME_ENTRY_ERR_INDEX_MASK)
  2022. #define GET_CERT_ALT_NAME_VALUE_ERR_INDEX(X) \
  2023.     (X & CERT_ALT_NAME_VALUE_ERR_INDEX_MASK)
  2024.  
  2025.  
  2026. //+-------------------------------------------------------------------------
  2027. //  X509_BASIC_CONSTRAINTS
  2028. //  szOID_BASIC_CONSTRAINTS
  2029. //
  2030. //  pvStructInfo points to following CERT_BASIC_CONSTRAINTS_INFO.
  2031. //--------------------------------------------------------------------------
  2032. typedef struct _CERT_BASIC_CONSTRAINTS_INFO {
  2033.     CRYPT_BIT_BLOB          SubjectType;
  2034.     BOOL                    fPathLenConstraint;
  2035.     DWORD                   dwPathLenConstraint;
  2036.     DWORD                   cSubtreesConstraint;
  2037.     CERT_NAME_BLOB          *rgSubtreesConstraint;
  2038. } CERT_BASIC_CONSTRAINTS_INFO, *PCERT_BASIC_CONSTRAINTS_INFO;
  2039.  
  2040. #define CERT_CA_SUBJECT_FLAG         0x80
  2041. #define CERT_END_ENTITY_SUBJECT_FLAG 0x40
  2042.  
  2043. //+-------------------------------------------------------------------------
  2044. //  X509_BASIC_CONSTRAINTS2
  2045. //  szOID_BASIC_CONSTRAINTS2
  2046. //
  2047. //  pvStructInfo points to following CERT_BASIC_CONSTRAINTS2_INFO.
  2048. //--------------------------------------------------------------------------
  2049. typedef struct _CERT_BASIC_CONSTRAINTS2_INFO {
  2050.     BOOL                    fCA;
  2051.     BOOL                    fPathLenConstraint;
  2052.     DWORD                   dwPathLenConstraint;
  2053. } CERT_BASIC_CONSTRAINTS2_INFO, *PCERT_BASIC_CONSTRAINTS2_INFO;
  2054.  
  2055. //+-------------------------------------------------------------------------
  2056. //  X509_KEY_USAGE
  2057. //  szOID_KEY_USAGE
  2058. //
  2059. //  pvStructInfo points to a CRYPT_BIT_BLOB. Has same bit definitions as
  2060. //  CERT_KEY_ATTRIBUTES_INFO's IntendedKeyUsage.
  2061. //--------------------------------------------------------------------------
  2062.  
  2063. //+-------------------------------------------------------------------------
  2064. //  X509_CERT_POLICIES
  2065. //  szOID_CERT_POLICIES
  2066. //
  2067. //  pvStructInfo points to following CERT_POLICIES_INFO.
  2068. //--------------------------------------------------------------------------
  2069. typedef struct _CERT_POLICY_QUALIFIER_INFO {
  2070.     LPSTR                       pszPolicyQualifierId;   // pszObjId
  2071.     CRYPT_OBJID_BLOB            Qualifier;              // optional
  2072. } CERT_POLICY_QUALIFIER_INFO, *PCERT_POLICY_QUALIFIER_INFO;
  2073.  
  2074. typedef struct _CERT_POLICY_INFO {
  2075.     LPSTR                       pszPolicyIdentifier;    // pszObjId
  2076.     DWORD                       cPolicyQualifier;       // optional
  2077.     CERT_POLICY_QUALIFIER_INFO  *rgPolicyQualifier;
  2078. } CERT_POLICY_INFO, *PCERT_POLICY_INFO;
  2079.  
  2080. typedef struct _CERT_POLICIES_INFO {
  2081.     DWORD                       cPolicyInfo;
  2082.     CERT_POLICY_INFO            *rgPolicyInfo;
  2083. } CERT_POLICIES_INFO, *PCERT_POLICIES_INFO;
  2084.  
  2085. //+-------------------------------------------------------------------------
  2086. //  RSA_CSP_PUBLICKEYBLOB
  2087. //
  2088. //  pvStructInfo points to a PUBLICKEYSTRUC immediately followed by a
  2089. //  RSAPUBKEY and the modulus bytes.
  2090. //
  2091. //  CryptExportKey outputs the above StructInfo for a dwBlobType of
  2092. //  PUBLICKEYBLOB. CryptImportKey expects the above StructInfo when
  2093. //  importing a public key.
  2094. //
  2095. //  For dwCertEncodingType = X509_ASN_ENCODING, the RSA_CSP_PUBLICKEYBLOB is
  2096. //  encoded as a PKCS #1 RSAPublicKey consisting of a SEQUENCE of a
  2097. //  modulus INTEGER and a publicExponent INTEGER. The modulus is encoded
  2098. //  as being a unsigned integer. When decoded, if the modulus was encoded
  2099. //  as unsigned integer with a leading 0 byte, the 0 byte is removed before
  2100. //  converting to the CSP modulus bytes.
  2101. //
  2102. //  For decode, the aiKeyAlg field of PUBLICKEYSTRUC is always set to
  2103. //  CALG_RSA_KEYX.
  2104. //--------------------------------------------------------------------------
  2105.  
  2106. //+-------------------------------------------------------------------------
  2107. //  X509_KEYGEN_REQUEST_TO_BE_SIGNED
  2108. //
  2109. //  pvStructInfo points to CERT_KEYGEN_REQUEST_INFO.
  2110. //
  2111. //  For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  2112. //  signature (output of a X509_CERT CryptEncodeObject()).
  2113. //
  2114. //  For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  2115. //--------------------------------------------------------------------------
  2116.  
  2117. //+-------------------------------------------------------------------------
  2118. //  PKCS_ATTRIBUTE data structure
  2119. //
  2120. //  pvStructInfo points to a CRYPT_ATTRIBUTE.
  2121. //--------------------------------------------------------------------------
  2122.  
  2123. //+-------------------------------------------------------------------------
  2124. //  PKCS_CONTENT_INFO_SEQUENCE_OF_ANY data structure
  2125. //
  2126. //  pvStructInfo points to following CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY.
  2127. //
  2128. //  For X509_ASN_ENCODING: encoded as a PKCS#7 ContentInfo structure wrapping
  2129. //  a sequence of ANY. The value of the contentType field is pszObjId,
  2130. //  while the content field is the following structure:
  2131. //      SequenceOfAny ::= SEQUENCE OF ANY
  2132. //
  2133. //  The CRYPT_DER_BLOBs point to the already encoded ANY content.
  2134. //--------------------------------------------------------------------------
  2135. typedef struct _CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY {
  2136.     LPSTR               pszObjId;
  2137.     DWORD               cValue;
  2138.     PCRYPT_DER_BLOB     rgValue;
  2139. } CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY, *PCRYPT_CONTENT_INFO_SEQUENCE_OF_ANY;
  2140.  
  2141. //+-------------------------------------------------------------------------
  2142. //  PKCS_CONTENT_INFO data structure
  2143. //
  2144. //  pvStructInfo points to following CRYPT_CONTENT_INFO.
  2145. //
  2146. //  For X509_ASN_ENCODING: encoded as a PKCS#7 ContentInfo structure.
  2147. //  The CRYPT_DER_BLOB points to the already encoded ANY content.
  2148. //--------------------------------------------------------------------------
  2149. typedef struct _CRYPT_CONTENT_INFO {
  2150.     LPSTR               pszObjId;
  2151.     CRYPT_DER_BLOB      Content;
  2152. } CRYPT_CONTENT_INFO, *PCRYPT_CONTENT_INFO;
  2153.  
  2154.  
  2155. //+-------------------------------------------------------------------------
  2156. //  X509_OCTET_STRING data structure
  2157. //
  2158. //  pvStructInfo points to a CRYPT_DATA_BLOB.
  2159. //--------------------------------------------------------------------------
  2160.  
  2161. //+-------------------------------------------------------------------------
  2162. //  X509_BITS data structure
  2163. //
  2164. //  pvStructInfo points to a CRYPT_BIT_BLOB.
  2165. //--------------------------------------------------------------------------
  2166.  
  2167. //+-------------------------------------------------------------------------
  2168. //  X509_INTEGER data structure
  2169. //
  2170. //  pvStructInfo points to an int.
  2171. //--------------------------------------------------------------------------
  2172.  
  2173. //+-------------------------------------------------------------------------
  2174. //  X509_MULTI_BYTE_INTEGER data structure
  2175. //
  2176. //  pvStructInfo points to a CRYPT_INTEGER_BLOB.
  2177. //--------------------------------------------------------------------------
  2178.  
  2179. //+-------------------------------------------------------------------------
  2180. //  X509_ENUMERATED data structure
  2181. //
  2182. //  pvStructInfo points to an int containing the enumerated value
  2183. //--------------------------------------------------------------------------
  2184.  
  2185. //+-------------------------------------------------------------------------
  2186. //  X509_CHOICE_OF_TIME data structure
  2187. //
  2188. //  pvStructInfo points to a FILETIME.
  2189. //--------------------------------------------------------------------------
  2190.  
  2191. //+-------------------------------------------------------------------------
  2192. //  X509_SEQUENCE_OF_ANY data structure
  2193. //
  2194. //  pvStructInfo points to following CRYPT_SEQUENCE_OF_ANY.
  2195. //
  2196. //  The CRYPT_DER_BLOBs point to the already encoded ANY content.
  2197. //--------------------------------------------------------------------------
  2198. typedef struct _CRYPT_SEQUENCE_OF_ANY {
  2199.     DWORD               cValue;
  2200.     PCRYPT_DER_BLOB     rgValue;
  2201. } CRYPT_SEQUENCE_OF_ANY, *PCRYPT_SEQUENCE_OF_ANY;
  2202.  
  2203.  
  2204. //+-------------------------------------------------------------------------
  2205. //  X509_AUTHORITY_KEY_ID2
  2206. //  szOID_AUTHORITY_KEY_IDENTIFIER2
  2207. //
  2208. //  pvStructInfo points to following CERT_AUTHORITY_KEY_ID2_INFO.
  2209. //
  2210. //  For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  2211. //  *pcbEncoded by CryptEncodeObject(X509_AUTHORITY_KEY_ID2)
  2212. //
  2213. //  See X509_ALTERNATE_NAME for error location defines.
  2214. //--------------------------------------------------------------------------
  2215. typedef struct _CERT_AUTHORITY_KEY_ID2_INFO {
  2216.     CRYPT_DATA_BLOB     KeyId;
  2217.     CERT_ALT_NAME_INFO  AuthorityCertIssuer;    // Optional, set cAltEntry
  2218.                                                 // to 0 to omit.
  2219.     CRYPT_INTEGER_BLOB  AuthorityCertSerialNumber;
  2220. } CERT_AUTHORITY_KEY_ID2_INFO, *PCERT_AUTHORITY_KEY_ID2_INFO;
  2221.  
  2222. //+-------------------------------------------------------------------------
  2223. //  szOID_SUBJECT_KEY_IDENTIFIER
  2224. //
  2225. //  pvStructInfo points to a CRYPT_DATA_BLOB.
  2226. //--------------------------------------------------------------------------
  2227.  
  2228.  
  2229. //+-------------------------------------------------------------------------
  2230. //  X509_CRL_REASON_CODE
  2231. //  szOID_CRL_REASON_CODE
  2232. //
  2233. //  pvStructInfo points to an int which can be set to one of the following
  2234. //  enumerated values:
  2235. //--------------------------------------------------------------------------
  2236. #define CRL_REASON_UNSPECIFIED              0
  2237. #define CRL_REASON_KEY_COMPROMISE           1
  2238. #define CRL_REASON_CA_COMPROMISE            2
  2239. #define CRL_REASON_AFFILIATION_CHANGED      3
  2240. #define CRL_REASON_SUPERSEDED               4
  2241. #define CRL_REASON_CESSATION_OF_OPERATION   5
  2242. #define CRL_REASON_CERTIFICATE_HOLD         6
  2243. #define CRL_REASON_REMOVE_FROM_CRL          8
  2244.  
  2245.  
  2246. //+-------------------------------------------------------------------------
  2247. //  X509_CRL_DIST_POINTS
  2248. //  szOID_CRL_DIST_POINTS
  2249. //
  2250. //  pvStructInfo points to following CRL_DIST_POINTS_INFO.
  2251. //
  2252. //  For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  2253. //  *pcbEncoded by CryptEncodeObject(X509_CRL_DIST_POINTS)
  2254. //
  2255. //  Error location consists of:
  2256. //    CRL_ISSUER_BIT    - 1 bit  << 31 (0 for FullName, 1 for CRLIssuer)
  2257. //    POINT_INDEX       - 7 bits << 24
  2258. //    ENTRY_INDEX       - 8 bits << 16
  2259. //    VALUE_INDEX       - 16 bits (unicode character index)
  2260. //
  2261. //  See X509_ALTERNATE_NAME for ENTRY_INDEX and VALUE_INDEX error location
  2262. //  defines.
  2263. //--------------------------------------------------------------------------
  2264. typedef struct _CRL_DIST_POINT_NAME {
  2265.     DWORD   dwDistPointNameChoice;
  2266.     union {
  2267.         CERT_ALT_NAME_INFO      FullName;       // 1
  2268.         // Not implemented      IssuerRDN;      // 2
  2269.     };
  2270. } CRL_DIST_POINT_NAME, *PCRL_DIST_POINT_NAME;
  2271.  
  2272. #define CRL_DIST_POINT_NO_NAME          0
  2273. #define CRL_DIST_POINT_FULL_NAME        1
  2274. #define CRL_DIST_POINT_ISSUER_RDN_NAME  2
  2275.  
  2276. typedef struct _CRL_DIST_POINT {
  2277.     CRL_DIST_POINT_NAME     DistPointName;      // OPTIONAL
  2278.     CRYPT_BIT_BLOB          ReasonFlags;        // OPTIONAL
  2279.     CERT_ALT_NAME_INFO      CRLIssuer;          // OPTIONAL
  2280. } CRL_DIST_POINT, *PCRL_DIST_POINT;
  2281.  
  2282. #define CRL_REASON_UNUSED_FLAG                  0x80
  2283. #define CRL_REASON_KEY_COMPROMISE_FLAG          0x40
  2284. #define CRL_REASON_CA_COMPROMISE_FLAG           0x20
  2285. #define CRL_REASON_AFFILIATION_CHANGED_FLAG     0x10
  2286. #define CRL_REASON_SUPERSEDED_FLAG              0x08
  2287. #define CRL_REASON_CESSATION_OF_OPERATION_FLAG  0x04
  2288. #define CRL_REASON_CERTIFICATE_HOLD_FLAG        0x02
  2289.  
  2290. typedef struct _CRL_DIST_POINTS_INFO {
  2291.     DWORD                   cDistPoint;
  2292.     PCRL_DIST_POINT         rgDistPoint;
  2293. } CRL_DIST_POINTS_INFO, *PCRL_DIST_POINTS_INFO;
  2294.  
  2295. #define CRL_DIST_POINT_ERR_INDEX_MASK          0x7F
  2296. #define CRL_DIST_POINT_ERR_INDEX_SHIFT         24
  2297. #define GET_CRL_DIST_POINT_ERR_INDEX(X)   \
  2298.     ((X >> CRL_DIST_POINT_ERR_INDEX_SHIFT) & CRL_DIST_POINT_ERR_INDEX_MASK)
  2299.  
  2300. #define CRL_DIST_POINT_ERR_CRL_ISSUER_BIT      0x80000000L
  2301. #define IS_CRL_DIST_POINT_ERR_CRL_ISSUER(X)   \
  2302.     (0 != (X & CRL_DIST_POINT_ERR_CRL_ISSUER_BIT))
  2303.  
  2304.  
  2305. //+-------------------------------------------------------------------------
  2306. //  X509_ENHANCED_KEY_USAGE
  2307. //  szOID_ENHANCED_KEY_USAGE
  2308. //
  2309. //  pvStructInfo points to a CERT_ENHKEY_USAGE, CTL_USAGE.
  2310. //--------------------------------------------------------------------------
  2311.  
  2312. //+-------------------------------------------------------------------------
  2313. //  szOID_NEXT_UPDATE_LOCATION
  2314. //
  2315. //  pvStructInfo points to a CERT_ALT_NAME_INFO.
  2316. //--------------------------------------------------------------------------
  2317.  
  2318. //+-------------------------------------------------------------------------
  2319. //  PKCS_CTL
  2320. //  szOID_CTL
  2321. //
  2322. //  pvStructInfo points to a CTL_INFO.
  2323. //--------------------------------------------------------------------------
  2324.  
  2325. //+-------------------------------------------------------------------------
  2326. //  X509_MULTI_BYTE_UINT
  2327. //
  2328. //  pvStructInfo points to a CRYPT_UINT_BLOB. Before encoding, inserts a
  2329. //  leading 0x00. After decoding, removes a leading 0x00.
  2330. //--------------------------------------------------------------------------
  2331.  
  2332. //+-------------------------------------------------------------------------
  2333. //  X509_DSS_PUBLICKEY
  2334. //
  2335. //  pvStructInfo points to a CRYPT_UINT_BLOB.
  2336. //--------------------------------------------------------------------------
  2337.  
  2338. //+-------------------------------------------------------------------------
  2339. //  X509_DSS_PARAMETERS
  2340. //
  2341. //  pvStructInfo points to following CERT_DSS_PARAMETERS data structure.
  2342. //--------------------------------------------------------------------------
  2343. typedef struct _CERT_DSS_PARAMETERS {
  2344.     CRYPT_UINT_BLOB     p;
  2345.     CRYPT_UINT_BLOB     q;
  2346.     CRYPT_UINT_BLOB     g;
  2347. } CERT_DSS_PARAMETERS, *PCERT_DSS_PARAMETERS;
  2348.  
  2349. //+-------------------------------------------------------------------------
  2350. //  X509_DSS_SIGNATURE
  2351. //
  2352. //  pvStructInfo is a BYTE rgbSignature[CERT_DSS_SIGNATURE_LEN]. The
  2353. //  bytes are ordered as output by the DSS CSP's CryptSignHash().
  2354. //--------------------------------------------------------------------------
  2355. #define CERT_DSS_R_LEN          20      
  2356. #define CERT_DSS_S_LEN          20      
  2357. #define CERT_DSS_SIGNATURE_LEN  (CERT_DSS_R_LEN + CERT_DSS_S_LEN)
  2358.  
  2359. // Sequence of 2 unsigned integers (the extra +1 is for a potential leading
  2360. // 0x00 to make the integer unsigned)
  2361. #define CERT_MAX_ASN_ENCODED_DSS_SIGNATURE_LEN  (2 + 2*(2 + 20 +1))
  2362.  
  2363.  
  2364. //+-------------------------------------------------------------------------
  2365. //  PKCS_RC2_CBC_PARAMETERS
  2366. //  szOID_RSA_RC2CBC
  2367. //
  2368. //  pvStructInfo points to following CRYPT_RC2_CBC_PARAMETERS data structure.
  2369. //--------------------------------------------------------------------------
  2370. typedef struct _CRYPT_RC2_CBC_PARAMETERS {
  2371.     DWORD               dwVersion;
  2372.     BOOL                fIV;            // set if has following IV
  2373.     BYTE                rgbIV[8];
  2374. } CRYPT_RC2_CBC_PARAMETERS, *PCRYPT_RC2_CBC_PARAMETERS;
  2375.  
  2376. #define CRYPT_RC2_40BIT_VERSION     160
  2377. #define CRYPT_RC2_64BIT_VERSION     120
  2378. #define CRYPT_RC2_128BIT_VERSION    58
  2379.  
  2380.  
  2381. //+-------------------------------------------------------------------------
  2382. //  PKCS_SMIME_CAPABILITIES
  2383. //  szOID_RSA_SMIMECapabilities
  2384. //
  2385. //  pvStructInfo points to following CRYPT_SMIME_CAPABILITIES data structure.
  2386. //
  2387. //  Note, for CryptEncodeObject(X509_ASN_ENCODING), Parameters.cbData == 0
  2388. //  causes the encoded parameters to be omitted and not encoded as a NULL
  2389. //  (05 00) as is done when encoding a CRYPT_ALGORITHM_IDENTIFIER. This
  2390. //  is per the SMIME specification for encoding capabilities.
  2391. //--------------------------------------------------------------------------
  2392. typedef struct _CRYPT_SMIME_CAPABILITY {
  2393.     LPSTR               pszObjId;
  2394.     CRYPT_OBJID_BLOB    Parameters;
  2395. } CRYPT_SMIME_CAPABILITY, *PCRYPT_SMIME_CAPABILITY;
  2396.  
  2397. typedef struct _CRYPT_SMIME_CAPABILITIES {
  2398.     DWORD                   cCapability;
  2399.     PCRYPT_SMIME_CAPABILITY rgCapability;
  2400. } CRYPT_SMIME_CAPABILITIES, *PCRYPT_SMIME_CAPABILITIES;
  2401.  
  2402.  
  2403. //+-------------------------------------------------------------------------
  2404. //  PKCS7_SIGNER_INFO
  2405. //
  2406. //  pvStructInfo points to CMSG_SIGNER_INFO.
  2407. //--------------------------------------------------------------------------
  2408.  
  2409.  
  2410. //+-------------------------------------------------------------------------
  2411. //  Netscape Certificate Extension Object Identifiers
  2412. //--------------------------------------------------------------------------
  2413. #define szOID_NETSCAPE                  "2.16.840.1.113730"
  2414. #define szOID_NETSCAPE_CERT_EXTENSION   "2.16.840.1.113730.1"
  2415. #define szOID_NETSCAPE_CERT_TYPE        "2.16.840.1.113730.1.1"
  2416. #define szOID_NETSCAPE_BASE_URL         "2.16.840.1.113730.1.2"
  2417. #define szOID_NETSCAPE_REVOCATION_URL   "2.16.840.1.113730.1.3"
  2418. #define szOID_NETSCAPE_CA_REVOCATION_URL "2.16.840.1.113730.1.4"
  2419. #define szOID_NETSCAPE_CERT_RENEWAL_URL "2.16.840.1.113730.1.7"
  2420. #define szOID_NETSCAPE_CA_POLICY_URL    "2.16.840.1.113730.1.8"
  2421. #define szOID_NETSCAPE_SSL_SERVER_NAME  "2.16.840.1.113730.1.12"
  2422. #define szOID_NETSCAPE_COMMENT          "2.16.840.1.113730.1.13"
  2423.  
  2424. //+-------------------------------------------------------------------------
  2425. //  Netscape Certificate Data Type Object Identifiers
  2426. //--------------------------------------------------------------------------
  2427. #define szOID_NETSCAPE_DATA_TYPE        "2.16.840.1.113730.2"
  2428. #define szOID_NETSCAPE_CERT_SEQUENCE    "2.16.840.1.113730.2.5"
  2429.  
  2430.  
  2431. //+-------------------------------------------------------------------------
  2432. //  szOID_NETSCAPE_CERT_TYPE extension
  2433. //
  2434. //  Its value is a bit string. CryptDecodeObject/CryptEncodeObject using
  2435. //  X509_BITS.
  2436. //
  2437. //  The following bits are defined:
  2438. //--------------------------------------------------------------------------
  2439. #define NETSCAPE_SSL_CLIENT_AUTH_CERT_TYPE  0x80
  2440. #define NETSCAPE_SSL_SERVER_AUTH_CERT_TYPE  0x40
  2441. #define NETSCAPE_SSL_CA_CERT_TYPE           0x04
  2442.  
  2443. //+-------------------------------------------------------------------------
  2444. //  szOID_NETSCAPE_BASE_URL extension
  2445. //
  2446. //  Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  2447. //  X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  2448. //  dwValueType = CERT_RDN_IA5_STRING.
  2449. //
  2450. //  When present this string is added to the beginning of all relative URLs
  2451. //  in the certificate.  This extension can be considered an optimization
  2452. //  to reduce the size of the URL extensions.
  2453. //--------------------------------------------------------------------------
  2454.  
  2455. //+-------------------------------------------------------------------------
  2456. //  szOID_NETSCAPE_REVOCATION_URL extension
  2457. //
  2458. //  Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  2459. //  X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  2460. //  dwValueType = CERT_RDN_IA5_STRING.
  2461. //
  2462. //  It is a relative or absolute URL that can be used to check the
  2463. //  revocation status of a certificate. The revocation check will be
  2464. //  performed as an HTTP GET method using a url that is the concatenation of
  2465. //  revocation-url and certificate-serial-number.
  2466. //  Where the certificate-serial-number is encoded as a string of
  2467. //  ascii hexadecimal digits. For example, if the netscape-base-url is
  2468. //  https://www.certs-r-us.com/, the netscape-revocation-url is
  2469. //  cgi-bin/check-rev.cgi?, and the certificate serial number is 173420,
  2470. //  the resulting URL would be:
  2471. //  https://www.certs-r-us.com/cgi-bin/check-rev.cgi?02a56c
  2472. //
  2473. //  The server should return a document with a Content-Type of
  2474. //  application/x-netscape-revocation.  The document should contain
  2475. //  a single ascii digit, '1' if the certificate is not curently valid,
  2476. //  and '0' if it is curently valid.
  2477. //
  2478. //  Note: for all of the URLs that include the certificate serial number,
  2479. //  the serial number will be encoded as a string which consists of an even
  2480. //  number of hexadecimal digits.  If the number of significant digits is odd,
  2481. //  the string will have a single leading zero to ensure an even number of
  2482. //  digits is generated.
  2483. //--------------------------------------------------------------------------
  2484.  
  2485. //+-------------------------------------------------------------------------
  2486. //  szOID_NETSCAPE_CA_REVOCATION_URL extension
  2487. //
  2488. //  Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  2489. //  X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  2490. //  dwValueType = CERT_RDN_IA5_STRING.
  2491. //
  2492. //  It is a relative or absolute URL that can be used to check the
  2493. //  revocation status of any certificates that are signed by the CA that
  2494. //  this certificate belongs to. This extension is only valid in CA
  2495. //  certificates.  The use of this extension is the same as the above
  2496. //  szOID_NETSCAPE_REVOCATION_URL extension.
  2497. //--------------------------------------------------------------------------
  2498.  
  2499. //+-------------------------------------------------------------------------
  2500. //  szOID_NETSCAPE_CERT_RENEWAL_URL extension
  2501. //
  2502. //  Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  2503. //  X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  2504. //  dwValueType = CERT_RDN_IA5_STRING.
  2505. //
  2506. //  It is a relative or absolute URL that points to a certificate renewal
  2507. //  form. The renewal form will be accessed with an HTTP GET method using a
  2508. //  url that is the concatenation of renewal-url and
  2509. //  certificate-serial-number. Where the certificate-serial-number is
  2510. //  encoded as a string of ascii hexadecimal digits. For example, if the
  2511. //  netscape-base-url is https://www.certs-r-us.com/, the
  2512. //  netscape-cert-renewal-url is cgi-bin/check-renew.cgi?, and the
  2513. //  certificate serial number is 173420, the resulting URL would be:
  2514. //  https://www.certs-r-us.com/cgi-bin/check-renew.cgi?02a56c
  2515. //  The document returned should be an HTML form that will allow the user
  2516. //  to request a renewal of their certificate.
  2517. //--------------------------------------------------------------------------
  2518.  
  2519. //+-------------------------------------------------------------------------
  2520. //  szOID_NETSCAPE_CA_POLICY_URL extension
  2521. //
  2522. //  Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  2523. //  X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  2524. //  dwValueType = CERT_RDN_IA5_STRING.
  2525. //
  2526. //  It is a relative or absolute URL that points to a web page that
  2527. //  describes the policies under which the certificate was issued.
  2528. //--------------------------------------------------------------------------
  2529.  
  2530. //+-------------------------------------------------------------------------
  2531. //  szOID_NETSCAPE_SSL_SERVER_NAME extension
  2532. //
  2533. //  Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  2534. //  X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  2535. //  dwValueType = CERT_RDN_IA5_STRING.
  2536. //
  2537. //  It is a "shell expression" that can be used to match the hostname of the
  2538. //  SSL server that is using this certificate.  It is recommended that if
  2539. //  the server's hostname does not match this pattern the user be notified
  2540. //  and given the option to terminate the SSL connection.  If this extension
  2541. //  is not present then the CommonName in the certificate subject's
  2542. //  distinguished name is used for the same purpose.
  2543. //--------------------------------------------------------------------------
  2544.  
  2545. //+-------------------------------------------------------------------------
  2546. //  szOID_NETSCAPE_COMMENT extension
  2547. //
  2548. //  Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  2549. //  X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  2550. //  dwValueType = CERT_RDN_IA5_STRING.
  2551. //
  2552. //  It is a comment that may be displayed to the user when the certificate
  2553. //  is viewed.
  2554. //--------------------------------------------------------------------------
  2555.  
  2556. //+-------------------------------------------------------------------------
  2557. //  szOID_NETSCAPE_CERT_SEQUENCE
  2558. //
  2559. //  Its value is a PKCS#7 ContentInfo structure wrapping a sequence of
  2560. //  certificates. The value of the contentType field is
  2561. //  szOID_NETSCAPE_CERT_SEQUENCE, while the content field is the following
  2562. //  structure:
  2563. //      CertificateSequence ::= SEQUENCE OF Certificate.
  2564. //
  2565. //  CryptDecodeObject/CryptEncodeObject using
  2566. //  PKCS_CONTENT_INFO_SEQUENCE_OF_ANY, where,
  2567. //  pszObjId = szOID_NETSCAPE_CERT_SEQUENCE and the CRYPT_DER_BLOBs point
  2568. //  to encoded X509 certificates.
  2569. //--------------------------------------------------------------------------
  2570.  
  2571.  
  2572. //+=========================================================================
  2573. //  Object IDentifier (OID) Installable Functions:  Data Structures and APIs
  2574. //==========================================================================
  2575.  
  2576. typedef void *HCRYPTOIDFUNCSET;
  2577. typedef void *HCRYPTOIDFUNCADDR;
  2578.  
  2579. // Predefined OID Function Names
  2580. #define CRYPT_OID_ENCODE_OBJECT_FUNC        "CryptDllEncodeObject"
  2581. #define CRYPT_OID_DECODE_OBJECT_FUNC        "CryptDllDecodeObject"
  2582. #define CRYPT_OID_CREATE_COM_OBJECT_FUNC    "CryptDllCreateCOMObject"
  2583. #define CRYPT_OID_VERIFY_REVOCATION_FUNC    "CertDllVerifyRevocation"
  2584. #define CRYPT_OID_VERIFY_CTL_USAGE_FUNC     "CertDllVerifyCTLUsage"
  2585. #define CRYPT_OID_FORMAT_OBJECT_FUNC        "CryptDllFormatObject"
  2586. #define CRYPT_OID_FIND_OID_INFO_FUNC        "CryptDllFindOIDInfo"
  2587.  
  2588. // CryptDllEncodeObject has same function signature as CryptEncodeObject.
  2589.  
  2590. // CryptDllDecodeObject has same function signature as CryptDecodeObject.
  2591.  
  2592. // CryptDllCreateCOMObject has the following signature:
  2593. //      BOOL WINAPI CryptDllCreateCOMObject(
  2594. //          IN DWORD dwEncodingType,
  2595. //          IN LPCSTR pszOID,
  2596. //          IN PCRYPT_DATA_BLOB pEncodedContent,
  2597. //          IN DWORD dwFlags,
  2598. //          IN REFIID riid,
  2599. //          OUT void **ppvObj);
  2600.  
  2601. // CertDllVerifyRevocation has the same signature as CertVerifyRevocation
  2602. //  (See CertVerifyRevocation for details on when called)
  2603.  
  2604. // CertDllVerifyCTLUsage has the same signature as CertVerifyCTLUsage
  2605.  
  2606. // CryptDllFindOIDInfo currently is only used to store values used by
  2607. // CryptFindOIDInfo. See CryptFindOIDInfo() for more details.
  2608.  
  2609. //  Example of a complete OID Function Registry Name:
  2610. //    HKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography\OID
  2611. //      Encoding Type 1\CryptDllEncodeObject\1.2.3
  2612. //
  2613. //  The key's L"Dll" value contains the name of the Dll.
  2614. //  The key's L"FuncName" value overrides the default function name
  2615. #define CRYPT_OID_REGPATH "Software\\Microsoft\\Cryptography\\OID"
  2616. #define CRYPT_OID_REG_ENCODING_TYPE_PREFIX  "EncodingType "
  2617. #define CRYPT_OID_REG_DLL_VALUE_NAME        L"Dll"
  2618. #define CRYPT_OID_REG_FUNC_NAME_VALUE_NAME  L"FuncName"
  2619. #define CRYPT_OID_REG_FUNC_NAME_VALUE_NAME_A "FuncName"
  2620.  
  2621. // OID used for Default OID functions
  2622. #define CRYPT_DEFAULT_OID                   "DEFAULT"
  2623.  
  2624. typedef struct _CRYPT_OID_FUNC_ENTRY {
  2625.     LPCSTR  pszOID;
  2626.     void    *pvFuncAddr;
  2627. } CRYPT_OID_FUNC_ENTRY, *PCRYPT_OID_FUNC_ENTRY;
  2628.  
  2629.  
  2630. #define CRYPT_INSTALL_OID_FUNC_BEFORE_FLAG  1
  2631.  
  2632. //+-------------------------------------------------------------------------
  2633. //  Install a set of callable OID function addresses.
  2634. //
  2635. //  By default the functions are installed at end of the list.
  2636. //  Set CRYPT_INSTALL_OID_FUNC_BEFORE_FLAG to install at beginning of list.
  2637. //
  2638. //  hModule should be updated with the hModule passed to DllMain to prevent
  2639. //  the Dll containing the function addresses from being unloaded by
  2640. //  CryptGetOIDFuncAddress/CryptFreeOIDFunctionAddress. This would be the
  2641. //  case when the Dll has also regsvr32'ed OID functions via
  2642. //  CryptRegisterOIDFunction.
  2643. //
  2644. //  DEFAULT functions are installed by setting rgFuncEntry[].pszOID =
  2645. //  CRYPT_DEFAULT_OID.
  2646. //--------------------------------------------------------------------------
  2647. WINCRYPT32API
  2648. BOOL
  2649. WINAPI
  2650. CryptInstallOIDFunctionAddress(
  2651.     IN HMODULE hModule,         // hModule passed to DllMain
  2652.     IN DWORD dwEncodingType,
  2653.     IN LPCSTR pszFuncName,
  2654.     IN DWORD cFuncEntry,
  2655.     IN const CRYPT_OID_FUNC_ENTRY rgFuncEntry[],
  2656.     IN DWORD dwFlags
  2657.     );
  2658.  
  2659. //+-------------------------------------------------------------------------
  2660. //  Initialize and return handle to the OID function set identified by its
  2661. //  function name.
  2662. //
  2663. //  If the set already exists, a handle to the existing set is returned.
  2664. //--------------------------------------------------------------------------
  2665. WINCRYPT32API
  2666. HCRYPTOIDFUNCSET
  2667. WINAPI
  2668. CryptInitOIDFunctionSet(
  2669.     IN LPCSTR pszFuncName,
  2670.     IN DWORD dwFlags
  2671.     );
  2672.  
  2673. //+-------------------------------------------------------------------------
  2674. //  Search the list of installed functions for an encoding type and OID match.
  2675. //  If not found, search the registry.
  2676. //
  2677. //  For success, returns TRUE with *ppvFuncAddr updated with the function's
  2678. //  address and *phFuncAddr updated with the function address's handle.
  2679. //  The function's handle is AddRef'ed. CryptFreeOIDFunctionAddress needs to
  2680. //  be called to release it.
  2681. //
  2682. //  For a registry match, the Dll containing the function is loaded.
  2683. //--------------------------------------------------------------------------
  2684. WINCRYPT32API
  2685. BOOL
  2686. WINAPI
  2687. CryptGetOIDFunctionAddress(
  2688.     IN HCRYPTOIDFUNCSET hFuncSet,
  2689.     IN DWORD dwEncodingType,
  2690.     IN LPCSTR pszOID,
  2691.     IN DWORD dwFlags,
  2692.     OUT void **ppvFuncAddr,
  2693.     OUT HCRYPTOIDFUNCADDR *phFuncAddr
  2694.     );
  2695.  
  2696.  
  2697. //+-------------------------------------------------------------------------
  2698. //  Get the list of registered default Dll entries for the specified
  2699. //  function set and encoding type.
  2700. //
  2701. //  The returned list consists of none, one or more null terminated Dll file
  2702. //  names. The list is terminated with an empty (L"\0") Dll file name.
  2703. //  For example: L"first.dll" L"\0" L"second.dll" L"\0" L"\0"
  2704. //--------------------------------------------------------------------------
  2705. WINCRYPT32API
  2706. BOOL
  2707. WINAPI
  2708. CryptGetDefaultOIDDllList(
  2709.     IN HCRYPTOIDFUNCSET hFuncSet,
  2710.     IN DWORD dwEncodingType,
  2711.     OUT LPWSTR pwszDllList,
  2712.     IN OUT DWORD *pcchDllList
  2713.     );
  2714.  
  2715. //+-------------------------------------------------------------------------
  2716. //  Either: get the first or next installed DEFAULT function OR
  2717. //  load the Dll containing the DEFAULT function.
  2718. //
  2719. //  If pwszDll is NULL, search the list of installed DEFAULT functions.
  2720. //  *phFuncAddr must be set to NULL to get the first installed function.
  2721. //  Successive installed functions are returned by setting *phFuncAddr
  2722. //  to the hFuncAddr returned by the previous call.
  2723. //
  2724. //  If pwszDll is NULL, the input *phFuncAddr
  2725. //  is always CryptFreeOIDFunctionAddress'ed by this function, even for
  2726. //  an error.
  2727. //
  2728. //  If pwszDll isn't NULL, then, attempts to load the Dll and the DEFAULT
  2729. //  function. *phFuncAddr is ignored upon entry and isn't
  2730. //  CryptFreeOIDFunctionAddress'ed.
  2731. //
  2732. //  For success, returns TRUE with *ppvFuncAddr updated with the function's
  2733. //  address and *phFuncAddr updated with the function address's handle.
  2734. //  The function's handle is AddRef'ed. CryptFreeOIDFunctionAddress needs to
  2735. //  be called to release it or CryptGetDefaultOIDFunctionAddress can also
  2736. //  be called for a NULL pwszDll.
  2737. //--------------------------------------------------------------------------
  2738. WINCRYPT32API
  2739. BOOL
  2740. WINAPI
  2741. CryptGetDefaultOIDFunctionAddress(
  2742.     IN HCRYPTOIDFUNCSET hFuncSet,
  2743.     IN DWORD dwEncodingType,
  2744.     IN OPTIONAL LPCWSTR pwszDll,
  2745.     IN DWORD dwFlags,
  2746.     OUT void **ppvFuncAddr,
  2747.     IN OUT HCRYPTOIDFUNCADDR *phFuncAddr
  2748.     );
  2749.  
  2750. //+-------------------------------------------------------------------------
  2751. //  Releases the handle AddRef'ed and returned by CryptGetOIDFunctionAddress
  2752. //  or CryptGetDefaultOIDFunctionAddress.
  2753. //
  2754. //  If a Dll was loaded for the function its unloaded. However, before doing
  2755. //  the unload, the DllCanUnloadNow function exported by the loaded Dll is
  2756. //  called. It should return S_FALSE to inhibit the unload or S_TRUE to enable
  2757. //  the unload. If the Dll doesn't export DllCanUnloadNow, the Dll is unloaded.
  2758. //
  2759. //  DllCanUnloadNow has the following signature:
  2760. //      STDAPI  DllCanUnloadNow(void);
  2761. //--------------------------------------------------------------------------
  2762. WINCRYPT32API
  2763. BOOL
  2764. WINAPI
  2765. CryptFreeOIDFunctionAddress(
  2766.     IN HCRYPTOIDFUNCADDR hFuncAddr,
  2767.     IN DWORD dwFlags
  2768.     );
  2769.  
  2770. //+-------------------------------------------------------------------------
  2771. //  Register the Dll containing the function to be called for the specified
  2772. //  encoding type, function name and OID.
  2773. //
  2774. //  pwszDll may contain environment-variable strings
  2775. //  which are ExpandEnvironmentStrings()'ed before loading the Dll.
  2776. //
  2777. //  In addition to registering the DLL, you may override the
  2778. //  name of the function to be called. For example,
  2779. //      pszFuncName = "CryptDllEncodeObject",
  2780. //      pszOverrideFuncName = "MyEncodeXyz".
  2781. //  This allows a Dll to export multiple OID functions for the same
  2782. //  function name without needing to interpose its own OID dispatcher function.
  2783. //--------------------------------------------------------------------------
  2784. WINCRYPT32API
  2785. BOOL
  2786. WINAPI
  2787. CryptRegisterOIDFunction(
  2788.     IN DWORD dwEncodingType,
  2789.     IN LPCSTR pszFuncName,
  2790.     IN LPCSTR pszOID,
  2791.     IN OPTIONAL LPCWSTR pwszDll,
  2792.     IN OPTIONAL LPCSTR pszOverrideFuncName
  2793.     );
  2794.  
  2795. //+-------------------------------------------------------------------------
  2796. //  Unregister the Dll containing the function to be called for the specified
  2797. //  encoding type, function name and OID.
  2798. //--------------------------------------------------------------------------
  2799. WINCRYPT32API
  2800. BOOL
  2801. WINAPI
  2802. CryptUnregisterOIDFunction(
  2803.     IN DWORD dwEncodingType,
  2804.     IN LPCSTR pszFuncName,
  2805.     IN LPCSTR pszOID
  2806.     );
  2807.  
  2808.  
  2809. //+-------------------------------------------------------------------------
  2810. //  Register the Dll containing the default function to be called for the
  2811. //  specified encoding type and function name.
  2812. //
  2813. //  Unlike CryptRegisterOIDFunction, you can't override the function name
  2814. //  needing to be exported by the Dll.
  2815. //
  2816. //  The Dll is inserted before the entry specified by dwIndex.
  2817. //    dwIndex == 0, inserts at the beginning.
  2818. //    dwIndex == CRYPT_REGISTER_LAST_INDEX, appends at the end.
  2819. //
  2820. //  pwszDll may contain environment-variable strings
  2821. //  which are ExpandEnvironmentStrings()'ed before loading the Dll.
  2822. //--------------------------------------------------------------------------
  2823. WINCRYPT32API
  2824. BOOL
  2825. WINAPI
  2826. CryptRegisterDefaultOIDFunction(
  2827.     IN DWORD dwEncodingType,
  2828.     IN LPCSTR pszFuncName,
  2829.     IN DWORD dwIndex,
  2830.     IN LPCWSTR pwszDll
  2831.     );
  2832.  
  2833. #define CRYPT_REGISTER_FIRST_INDEX   0
  2834. #define CRYPT_REGISTER_LAST_INDEX    0xFFFFFFFF
  2835.  
  2836. //+-------------------------------------------------------------------------
  2837. //  Unregister the Dll containing the default function to be called for
  2838. //  the specified encoding type and function name.
  2839. //--------------------------------------------------------------------------
  2840. WINCRYPT32API
  2841. BOOL
  2842. WINAPI
  2843. CryptUnregisterDefaultOIDFunction(
  2844.     IN DWORD dwEncodingType,
  2845.     IN LPCSTR pszFuncName,
  2846.     IN LPCWSTR pwszDll
  2847.     );
  2848.  
  2849. //+-------------------------------------------------------------------------
  2850. //  Set the value for the specified encoding type, function name, OID and
  2851. //  value name.
  2852. //
  2853. //  See RegSetValueEx for the possible value types.
  2854. //
  2855. //  String types are UNICODE.
  2856. //--------------------------------------------------------------------------
  2857. WINCRYPT32API
  2858. BOOL
  2859. WINAPI
  2860. CryptSetOIDFunctionValue(
  2861.     IN DWORD dwEncodingType,
  2862.     IN LPCSTR pszFuncName,
  2863.     IN LPCSTR pszOID,
  2864.     IN LPCWSTR pwszValueName,
  2865.     IN DWORD dwValueType,
  2866.     IN const BYTE *pbValueData,
  2867.     IN DWORD cbValueData
  2868.     );
  2869.  
  2870. //+-------------------------------------------------------------------------
  2871. //  Get the value for the specified encoding type, function name, OID and
  2872. //  value name.
  2873. //
  2874. //  See RegEnumValue for the possible value types.
  2875. //
  2876. //  String types are UNICODE.
  2877. //--------------------------------------------------------------------------
  2878. WINCRYPT32API
  2879. BOOL
  2880. WINAPI
  2881. CryptGetOIDFunctionValue(
  2882.     IN DWORD dwEncodingType,
  2883.     IN LPCSTR pszFuncName,
  2884.     IN LPCSTR pszOID,
  2885.     IN LPCWSTR pwszValueName,
  2886.     OUT DWORD *pdwValueType,
  2887.     OUT BYTE *pbValueData,
  2888.     IN OUT DWORD *pcbValueData
  2889.     );
  2890.  
  2891. typedef BOOL (WINAPI *PFN_CRYPT_ENUM_OID_FUNC)(
  2892.         IN DWORD dwEncodingType,
  2893.         IN LPCSTR pszFuncName,
  2894.         IN LPCSTR pszOID,
  2895.         IN DWORD cValue,
  2896.         IN const DWORD rgdwValueType[],
  2897.         IN LPCWSTR const rgpwszValueName[],
  2898.         IN const BYTE * const rgpbValueData[],
  2899.         IN const DWORD rgcbValueData[],
  2900.         IN void *pvArg
  2901.         );
  2902.  
  2903. //+-------------------------------------------------------------------------
  2904. //  Enumerate the OID functions identified by their encoding type,
  2905. //  function name and OID.
  2906. //
  2907. //  pfnEnumOIDFunc is called for each registry key matching the input
  2908. //  parameters. Setting dwEncodingType to CRYPT_MATCH_ANY_ENCODING_TYPE matches
  2909. //  any. Setting pszFuncName or pszOID to NULL matches any.
  2910. //
  2911. //  Set pszOID == CRYPT_DEFAULT_OID to restrict the enumeration to only the
  2912. //  DEFAULT functions
  2913. //
  2914. //  String types are UNICODE.
  2915. //--------------------------------------------------------------------------
  2916. WINCRYPT32API
  2917. BOOL
  2918. WINAPI
  2919. CryptEnumOIDFunction(
  2920.     IN DWORD dwEncodingType,
  2921.     IN OPTIONAL LPCSTR pszFuncName,
  2922.     IN OPTIONAL LPCSTR pszOID,
  2923.     IN DWORD dwFlags,
  2924.     IN void *pvArg,
  2925.     IN PFN_CRYPT_ENUM_OID_FUNC pfnEnumOIDFunc
  2926.     );
  2927.  
  2928. #define CRYPT_MATCH_ANY_ENCODING_TYPE   0xFFFFFFFF
  2929.  
  2930.  
  2931. //+=========================================================================
  2932. //  Object IDentifier (OID) Information:  Data Structures and APIs
  2933. //==========================================================================
  2934.  
  2935. //+-------------------------------------------------------------------------
  2936. //  OID Information
  2937. //--------------------------------------------------------------------------
  2938. typedef struct _CRYPT_OID_INFO {
  2939.     DWORD               cbSize;
  2940.     LPCSTR              pszOID;
  2941.     LPCWSTR             pwszName;
  2942.     DWORD               dwGroupId;
  2943.     union {
  2944.         DWORD               dwValue;
  2945.         ALG_ID              Algid;
  2946.         DWORD               dwLength;
  2947.     };
  2948.     CRYPT_DATA_BLOB     ExtraInfo;
  2949. } CRYPT_OID_INFO, *PCRYPT_OID_INFO;
  2950. typedef const CRYPT_OID_INFO CCRYPT_OID_INFO, *PCCRYPT_OID_INFO;
  2951.  
  2952. //+-------------------------------------------------------------------------
  2953. //  OID Group IDs
  2954. //--------------------------------------------------------------------------
  2955. #define CRYPT_HASH_ALG_OID_GROUP_ID             1
  2956. #define CRYPT_ENCRYPT_ALG_OID_GROUP_ID          2
  2957. #define CRYPT_PUBKEY_ALG_OID_GROUP_ID           3
  2958. #define CRYPT_SIGN_ALG_OID_GROUP_ID             4
  2959. #define CRYPT_RDN_ATTR_OID_GROUP_ID             5
  2960. #define CRYPT_EXT_OR_ATTR_OID_GROUP_ID          6
  2961. #define CRYPT_ENHKEY_USAGE_OID_GROUP_ID         7
  2962. #define CRYPT_POLICY_OID_GROUP_ID               8
  2963. #define CRYPT_LAST_OID_GROUP_ID                 8
  2964.  
  2965. #define CRYPT_FIRST_ALG_OID_GROUP_ID            CRYPT_HASH_ALG_OID_GROUP_ID
  2966. #define CRYPT_LAST_ALG_OID_GROUP_ID             CRYPT_SIGN_ALG_OID_GROUP_ID
  2967.  
  2968.  
  2969. // The CRYPT_*_ALG_OID_GROUP_ID's have an Algid. The CRYPT_RDN_ATTR_OID_GROUP_ID
  2970. // has a dwLength. The CRYPT_EXT_OR_ATTR_OID_GROUP_ID,
  2971. // CRYPT_ENHKEY_USAGE_OID_GROUP_ID or CRYPT_POLICY_OID_GROUP_ID don't have a
  2972. // dwValue.
  2973. //
  2974.  
  2975. // CRYPT_PUBKEY_ALG_OID_GROUP_ID has the following optional ExtraInfo:
  2976. //  DWORD[0] - Flags. CRYPT_OID_INHIBIT_SIGNATURE_FORMAT_FLAG can be set to
  2977. //             inhibit the reformatting of the signature before
  2978. //             CryptVerifySignature is called or after CryptSignHash
  2979. //             is called. CRYPT_OID_USE_PUBKEY_PARA_FOR_PKCS7_FLAG can
  2980. //             be set to include the public key algorithm's parameters
  2981. //             in the PKCS7's digestEncryptionAlgorithm's parameters.
  2982.  
  2983. #define CRYPT_OID_INHIBIT_SIGNATURE_FORMAT_FLAG     0x1
  2984. #define CRYPT_OID_USE_PUBKEY_PARA_FOR_PKCS7_FLAG    0x2
  2985.  
  2986. // CRYPT_SIGN_ALG_OID_GROUP_ID has the following optional ExtraInfo:
  2987. //  DWORD[0] - Public Key Algid.
  2988. //  DWORD[1] - Flags. Same as above for CRYPT_PUBKEY_ALG_OID_GROUP_ID.
  2989.  
  2990. // CRYPT_RDN_ATTR_OID_GROUP_ID has the following optional ExtraInfo:
  2991. //  Array of DWORDs:
  2992. //   [0 ..] - Null terminated list of acceptable RDN attribute
  2993. //            value types. An empty list implies CERT_RDN_PRINTABLE_STRING,
  2994. //            CERT_RDN_T61_STRING, 0.
  2995.  
  2996. //+-------------------------------------------------------------------------
  2997. //  Find OID information. Returns NULL if unable to find any information
  2998. //  for the specified key and group. Note, returns a pointer to a constant
  2999. //  data structure. The returned pointer MUST NOT be freed.
  3000. //
  3001. //  dwKeyType's:
  3002. //    CRYPT_OID_INFO_OID_KEY, pvKey points to a szOID
  3003. //    CRYPT_OID_INFO_NAME_KEY, pvKey points to a wszName
  3004. //    CRYPT_OID_INFO_ALGID_KEY, pvKey points to an ALG_ID
  3005. //    CRYPT_OID_INFO_SIGN_KEY, pvKey points to an array of two ALG_ID's:
  3006. //      ALG_ID[0] - Hash Algid
  3007. //      ALG_ID[1] - PubKey Algid
  3008. //
  3009. //  Setting dwGroupId to 0, searches all groups according to the dwKeyType.
  3010. //  Otherwise, only the dwGroupId is searched.
  3011. //--------------------------------------------------------------------------
  3012. WINCRYPT32API
  3013. PCCRYPT_OID_INFO
  3014. WINAPI
  3015. CryptFindOIDInfo(
  3016.     IN DWORD dwKeyType,
  3017.     IN void *pvKey,
  3018.     IN DWORD dwGroupId
  3019.     );
  3020.  
  3021. #define CRYPT_OID_INFO_OID_KEY           1
  3022. #define CRYPT_OID_INFO_NAME_KEY          2
  3023. #define CRYPT_OID_INFO_ALGID_KEY         3
  3024. #define CRYPT_OID_INFO_SIGN_KEY          4
  3025.  
  3026. //+-------------------------------------------------------------------------
  3027. //  Register OID information. The OID information specified in the
  3028. //  CCRYPT_OID_INFO structure is persisted to the registry.
  3029. //
  3030. //  crypt32.dll contains information for the commonly known OIDs. This function
  3031. //  allows applications to augment crypt32.dll's OID information. During
  3032. //  CryptFindOIDInfo's first call, the registered OID information is installed.
  3033. //
  3034. //  By default the registered OID information is installed after crypt32.dll's
  3035. //  OID entries. Set CRYPT_INSTALL_OID_INFO_BEFORE_FLAG to install before.
  3036. //--------------------------------------------------------------------------
  3037. WINCRYPT32API
  3038. BOOL
  3039. WINAPI
  3040. CryptRegisterOIDInfo(
  3041.     IN PCCRYPT_OID_INFO pInfo,
  3042.     IN DWORD dwFlags
  3043.     );
  3044.  
  3045. #define CRYPT_INSTALL_OID_INFO_BEFORE_FLAG  1
  3046.  
  3047. //+-------------------------------------------------------------------------
  3048. //  Unregister OID information. Only the pszOID and dwGroupId fields are
  3049. //  used to identify the OID information to be unregistered.
  3050. //--------------------------------------------------------------------------
  3051. WINCRYPT32API
  3052. BOOL
  3053. WINAPI
  3054. CryptUnregisterOIDInfo(
  3055.     IN PCCRYPT_OID_INFO pInfo
  3056.     );
  3057.  
  3058.  
  3059. //+=========================================================================
  3060. //  Low Level Cryptographic Message Data Structures and APIs
  3061. //==========================================================================
  3062.  
  3063. typedef void *HCRYPTMSG;
  3064.  
  3065. #define szOID_PKCS_7_DATA               "1.2.840.113549.1.7.1"
  3066. #define szOID_PKCS_7_SIGNED             "1.2.840.113549.1.7.2"
  3067. #define szOID_PKCS_7_ENVELOPED          "1.2.840.113549.1.7.3"
  3068. #define szOID_PKCS_7_SIGNEDANDENVELOPED "1.2.840.113549.1.7.4"
  3069. #define szOID_PKCS_7_DIGESTED           "1.2.840.113549.1.7.5"
  3070. #define szOID_PKCS_7_ENCRYPTED          "1.2.840.113549.1.7.6"
  3071.  
  3072. #define szOID_PKCS_9_CONTENT_TYPE       "1.2.840.113549.1.9.3"
  3073. #define szOID_PKCS_9_MESSAGE_DIGEST     "1.2.840.113549.1.9.4"
  3074.  
  3075. //+-------------------------------------------------------------------------
  3076. //  Message types
  3077. //--------------------------------------------------------------------------
  3078. #define CMSG_DATA                    1
  3079. #define CMSG_SIGNED                  2
  3080. #define CMSG_ENVELOPED               3
  3081. #define CMSG_SIGNED_AND_ENVELOPED    4
  3082. #define CMSG_HASHED                  5
  3083. #define CMSG_ENCRYPTED               6
  3084.  
  3085. //+-------------------------------------------------------------------------
  3086. //  Message Type Bit Flags
  3087. //--------------------------------------------------------------------------
  3088. #define CMSG_ALL_FLAGS                   (~0UL)
  3089. #define CMSG_DATA_FLAG                   (1 << CMSG_DATA)
  3090. #define CMSG_SIGNED_FLAG                 (1 << CMSG_SIGNED)
  3091. #define CMSG_ENVELOPED_FLAG              (1 << CMSG_ENVELOPED)
  3092. #define CMSG_SIGNED_AND_ENVELOPED_FLAG   (1 << CMSG_SIGNED_AND_ENVELOPED)
  3093. #define CMSG_HASHED_FLAG                 (1 << CMSG_HASHED)
  3094. #define CMSG_ENCRYPTED_FLAG              (1 << CMSG_ENCRYPTED)
  3095.  
  3096. //+-------------------------------------------------------------------------
  3097. //  The message encode information (pvMsgEncodeInfo) is message type dependent
  3098. //--------------------------------------------------------------------------
  3099.  
  3100. //+-------------------------------------------------------------------------
  3101. //  CMSG_DATA: pvMsgEncodeInfo = NULL
  3102. //--------------------------------------------------------------------------
  3103.  
  3104. //+-------------------------------------------------------------------------
  3105. //  CMSG_SIGNED
  3106. //
  3107. //  The pCertInfo in the CMSG_SIGNER_ENCODE_INFO provides the Issuer, SerialNumber
  3108. //  and PublicKeyInfo.Algorithm. The PublicKeyInfo.Algorithm implicitly
  3109. //  specifies the HashEncryptionAlgorithm to be used.
  3110. //
  3111. //  The hCryptProv and dwKeySpec specify the private key to use. If dwKeySpec
  3112. //  == 0, then, defaults to AT_SIGNATURE.
  3113. //
  3114. //  pvHashAuxInfo currently isn't used and must be set to NULL.
  3115. //--------------------------------------------------------------------------
  3116. typedef struct _CMSG_SIGNER_ENCODE_INFO {
  3117.     DWORD                       cbSize;
  3118.     PCERT_INFO                  pCertInfo;
  3119.     HCRYPTPROV                  hCryptProv;
  3120.     DWORD                       dwKeySpec;
  3121.     CRYPT_ALGORITHM_IDENTIFIER  HashAlgorithm;
  3122.     void                        *pvHashAuxInfo;
  3123.     DWORD                       cAuthAttr;
  3124.     PCRYPT_ATTRIBUTE            rgAuthAttr;
  3125.     DWORD                       cUnauthAttr;
  3126.     PCRYPT_ATTRIBUTE            rgUnauthAttr;
  3127. } CMSG_SIGNER_ENCODE_INFO, *PCMSG_SIGNER_ENCODE_INFO;
  3128.  
  3129. typedef struct _CMSG_SIGNED_ENCODE_INFO {
  3130.     DWORD                       cbSize;
  3131.     DWORD                       cSigners;
  3132.     PCMSG_SIGNER_ENCODE_INFO    rgSigners;
  3133.     DWORD                       cCertEncoded;
  3134.     PCERT_BLOB                  rgCertEncoded;
  3135.     DWORD                       cCrlEncoded;
  3136.     PCRL_BLOB                   rgCrlEncoded;
  3137. } CMSG_SIGNED_ENCODE_INFO, *PCMSG_SIGNED_ENCODE_INFO;
  3138.  
  3139. //+-------------------------------------------------------------------------
  3140. //  CMSG_ENVELOPED
  3141. //
  3142. //  The PCERT_INFO for the rgRecipients provides the Issuer, SerialNumber
  3143. //  and PublicKeyInfo. The PublicKeyInfo.Algorithm implicitly
  3144. //  specifies the KeyEncryptionAlgorithm to be used.
  3145. //
  3146. //  The PublicKeyInfo.PublicKey in PCERT_INFO is used to encrypt the content
  3147. //  encryption key for the recipient.
  3148. //
  3149. //  hCryptProv is used to do the content encryption, recipient key encryption
  3150. //  and export. The hCryptProv's private keys aren't used.
  3151. //
  3152. //  Note: CAPI currently doesn't support more than one KeyEncryptionAlgorithm
  3153. //  per provider. This will need to be fixed.
  3154. //
  3155. //  pvEncryptionAuxInfo currently isn't used and must be set to NULL.
  3156. //--------------------------------------------------------------------------
  3157. typedef struct _CMSG_ENVELOPED_ENCODE_INFO {
  3158.     DWORD                       cbSize;
  3159.     HCRYPTPROV                  hCryptProv;
  3160.     CRYPT_ALGORITHM_IDENTIFIER  ContentEncryptionAlgorithm;
  3161.     void                        *pvEncryptionAuxInfo;
  3162.     DWORD                       cRecipients;
  3163.     PCERT_INFO                  *rgpRecipients;
  3164. } CMSG_ENVELOPED_ENCODE_INFO, *PCMSG_ENVELOPED_ENCODE_INFO;
  3165.  
  3166. //+-------------------------------------------------------------------------
  3167. //  CMSG_SIGNED_AND_ENVELOPED
  3168. //
  3169. //  For PKCS #7, a signed and enveloped message doesn't have the
  3170. //  signer's authenticated or unauthenticated attributes. Otherwise, a
  3171. //  combination of the CMSG_SIGNED_ENCODE_INFO and CMSG_ENVELOPED_ENCODE_INFO.
  3172. //--------------------------------------------------------------------------
  3173. typedef struct _CMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO {
  3174.     DWORD                       cbSize;
  3175.     CMSG_SIGNED_ENCODE_INFO     SignedInfo;
  3176.     CMSG_ENVELOPED_ENCODE_INFO  EnvelopedInfo;
  3177. } CMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO, *PCMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO;
  3178.  
  3179. //+-------------------------------------------------------------------------
  3180. //  CMSG_HASHED
  3181. //
  3182. //  hCryptProv is used to do the hash. Doesn't need to use a private key.
  3183. //
  3184. //  If fDetachedHash is set, then, the encoded message doesn't contain
  3185. //  any content (its treated as NULL Data)
  3186. //
  3187. //  pvHashAuxInfo currently isn't used and must be set to NULL.
  3188. //--------------------------------------------------------------------------
  3189. typedef struct _CMSG_HASHED_ENCODE_INFO {
  3190.     DWORD                       cbSize;
  3191.     HCRYPTPROV                  hCryptProv;
  3192.     CRYPT_ALGORITHM_IDENTIFIER  HashAlgorithm;
  3193.     void                        *pvHashAuxInfo;
  3194. } CMSG_HASHED_ENCODE_INFO, *PCMSG_HASHED_ENCODE_INFO;
  3195.  
  3196. //+-------------------------------------------------------------------------
  3197. //  CMSG_ENCRYPTED
  3198. //
  3199. //  The key used to encrypt the message is identified outside of the message
  3200. //  content (for example, password).
  3201. //
  3202. //  The content input to CryptMsgUpdate has already been encrypted.
  3203. //
  3204. //  pvEncryptionAuxInfo currently isn't used and must be set to NULL.
  3205. //--------------------------------------------------------------------------
  3206. typedef struct _CMSG_ENCRYPTED_ENCODE_INFO {
  3207.     DWORD                       cbSize;
  3208.     CRYPT_ALGORITHM_IDENTIFIER  ContentEncryptionAlgorithm;
  3209.     void                        *pvEncryptionAuxInfo;
  3210. } CMSG_ENCRYPTED_ENCODE_INFO, *PCMSG_ENCRYPTED_ENCODE_INFO;
  3211.  
  3212. //+-------------------------------------------------------------------------
  3213. //  This parameter allows messages to be of variable length with streamed
  3214. //  output.
  3215. //
  3216. //  By default, messages are of a definite length and
  3217. //  CryptMsgGetParam(CMSG_CONTENT_PARAM) is
  3218. //  called to get the cryptographically processed content. Until closed,
  3219. //  the handle keeps a copy of the processed content.
  3220. //
  3221. //  With streamed output, the processed content can be freed as its streamed.
  3222. //
  3223. //  If the length of the content to be updated is known at the time of the
  3224. //  open, then, ContentLength should be set to that length. Otherwise, it
  3225. //  should be set to CMSG_INDEFINITE_LENGTH.
  3226. //--------------------------------------------------------------------------
  3227. typedef BOOL (WINAPI *PFN_CMSG_STREAM_OUTPUT)(
  3228.         IN const void *pvArg,
  3229.         IN BYTE *pbData,
  3230.         IN DWORD cbData,
  3231.         IN BOOL fFinal
  3232.         );
  3233.  
  3234. #define CMSG_INDEFINITE_LENGTH       (0xFFFFFFFF)
  3235.  
  3236. typedef struct _CMSG_STREAM_INFO {
  3237.     DWORD                   cbContent;
  3238.     PFN_CMSG_STREAM_OUTPUT  pfnStreamOutput;
  3239.     void                    *pvArg;
  3240. } CMSG_STREAM_INFO, *PCMSG_STREAM_INFO;
  3241.  
  3242. //+-------------------------------------------------------------------------
  3243. //  Open dwFlags
  3244. //--------------------------------------------------------------------------
  3245. #define CMSG_BARE_CONTENT_FLAG              0x00000001
  3246. #define CMSG_LENGTH_ONLY_FLAG               0x00000002
  3247. #define CMSG_DETACHED_FLAG                  0x00000004
  3248. #define CMSG_AUTHENTICATED_ATTRIBUTES_FLAG  0x00000008
  3249. #define CMSG_CONTENTS_OCTETS_FLAG           0x00000010
  3250. #define CMSG_MAX_LENGTH_FLAG                0x00000020
  3251.  
  3252. //+-------------------------------------------------------------------------
  3253. //  Open a cryptographic message for encoding
  3254. //
  3255. //  For PKCS #7:
  3256. //  If the content to be passed to CryptMsgUpdate has already
  3257. //  been message encoded (the input to CryptMsgUpdate is the streamed output
  3258. //  from another message encode), then, the CMSG_ENCODED_CONTENT_INFO_FLAG should
  3259. //  be set in dwFlags. If not set, then, the inner ContentType is Data and
  3260. //  the input to CryptMsgUpdate is treated as the inner Data type's Content,
  3261. //  a string of bytes.
  3262. //  If CMSG_BARE_CONTENT_FLAG is specified for a streamed message,
  3263. //  the streamed output will not have an outer ContentInfo wrapper. This
  3264. //  makes it suitable to be streamed into an enclosing message.
  3265. //
  3266. //  The pStreamInfo parameter needs to be set to stream the encoded message
  3267. //  output.
  3268. //--------------------------------------------------------------------------
  3269. WINCRYPT32API
  3270. HCRYPTMSG
  3271. WINAPI
  3272. CryptMsgOpenToEncode(
  3273.     IN DWORD dwMsgEncodingType,
  3274.     IN DWORD dwFlags,
  3275.     IN DWORD dwMsgType,
  3276.     IN void const *pvMsgEncodeInfo,
  3277.     IN OPTIONAL LPSTR pszInnerContentObjID,
  3278.     IN OPTIONAL PCMSG_STREAM_INFO pStreamInfo
  3279.     );
  3280.  
  3281. //+-------------------------------------------------------------------------
  3282. //  Calculate the length of an encoded cryptographic message.
  3283. //
  3284. //  Calculates the length of the encoded message given the
  3285. //  message type, encoding parameters and total length of
  3286. //  the data to be updated. Note, this might not be the exact length. However,
  3287. //  it will always be greater than or equal to the actual length.
  3288. //--------------------------------------------------------------------------
  3289. WINCRYPT32API
  3290. DWORD
  3291. WINAPI
  3292. CryptMsgCalculateEncodedLength(
  3293.     IN DWORD dwMsgEncodingType,
  3294.     IN DWORD dwFlags,
  3295.     IN DWORD dwMsgType,
  3296.     IN void const *pvMsgEncodeInfo,
  3297.     IN OPTIONAL LPSTR pszInnerContentObjID,
  3298.     IN DWORD cbData
  3299.     );
  3300.  
  3301. //+-------------------------------------------------------------------------
  3302. //  Open a cryptographic message for decoding
  3303. //
  3304. // These comments need to be changed
  3305. //  For PKCS #7: if the inner ContentType isn't Data, then, the inner
  3306. //  ContentInfo consisting of both ContentType and Content is output.
  3307. //  To also enable ContentInfo output for the Data ContentType, then,
  3308. //  the CMSG_ENCODED_CONTENT_INFO_FLAG should be set
  3309. //  in dwFlags. If not set, then, only the content portion of the inner
  3310. //  ContentInfo is output for the Data ContentType.
  3311. //
  3312. //  To only calculate the length of the decoded message, set the
  3313. //  CMSG_LENGTH_ONLY_FLAG in dwFlags. After the final CryptMsgUpdate get the
  3314. //  MSG_CONTENT_PARAM. Note, this might not be the exact length. However,
  3315. //  it will always be greater than or equal to the actual length.
  3316. //
  3317. //  hCryptProv specifies the crypto provider to use for hashing and/or
  3318. //  decrypting the message. For enveloped messages, hCryptProv also specifies
  3319. //  the private exchange key to use. For signed messages, hCryptProv is used
  3320. //  when CryptMsgVerifySigner is called.
  3321. //
  3322. //  For enveloped messages, the pRecipientInfo contains the Issuer and
  3323. //  SerialNumber identifying the RecipientInfo in the message.
  3324. //
  3325. //  Note, the pRecipientInfo should correspond to the provider's private
  3326. //  exchange key.
  3327. //
  3328. //  If pRecipientInfo is NULL, then, the message isn't decrypted. To decrypt
  3329. //  the message, CryptMsgControl(CMSG_CTRL_DECRYPT) is called after the final
  3330. //  CryptMsgUpdate.
  3331. //
  3332. //  The pStreamInfo parameter needs to be set to stream the decoded content
  3333. //  output. Note, if pRecipientInfo is NULL, then, the streamed output isn't
  3334. //  decrypted.
  3335. //--------------------------------------------------------------------------
  3336. WINCRYPT32API
  3337. HCRYPTMSG
  3338. WINAPI
  3339. CryptMsgOpenToDecode(
  3340.     IN DWORD dwMsgEncodingType,
  3341.     IN DWORD dwFlags,
  3342.     IN DWORD dwMsgType,
  3343.     IN HCRYPTPROV hCryptProv,
  3344.     IN OPTIONAL PCERT_INFO pRecipientInfo,
  3345.     IN OPTIONAL PCMSG_STREAM_INFO pStreamInfo
  3346.     );
  3347.  
  3348. //+-------------------------------------------------------------------------
  3349. //  Close a cryptographic message handle
  3350. //
  3351. //  LastError is preserved unless FALSE is returned.
  3352. //--------------------------------------------------------------------------
  3353. WINCRYPT32API
  3354. BOOL
  3355. WINAPI
  3356. CryptMsgClose(
  3357.     IN HCRYPTMSG hCryptMsg
  3358.     );
  3359.  
  3360. //+-------------------------------------------------------------------------
  3361. //  Update the content of a cryptographic message. Depending on how the
  3362. //  message was opened, the content is either encoded or decoded.
  3363. //
  3364. //  This function is repetitively called to append to the message content.
  3365. //  fFinal is set to identify the last update. On fFinal, the encode/decode
  3366. //  is completed. The encoded/decoded content and the decoded parameters
  3367. //  are valid until the open and all duplicated handles are closed.
  3368. //--------------------------------------------------------------------------
  3369. WINCRYPT32API
  3370. BOOL
  3371. WINAPI
  3372. CryptMsgUpdate(
  3373.     IN HCRYPTMSG hCryptMsg,
  3374.     IN const BYTE *pbData,
  3375.     IN DWORD cbData,
  3376.     IN BOOL fFinal
  3377.     );
  3378.  
  3379. //+-------------------------------------------------------------------------
  3380. //  Perform a special "control" function after the final CryptMsgUpdate of a
  3381. //  encoded/decoded cryptographic message.
  3382. //
  3383. //  The dwCtrlType parameter specifies the type of operation to be performed.
  3384. //
  3385. //  The pvCtrlPara definition depends on the dwCtrlType value.
  3386. //
  3387. //  See below for a list of the control operations and their pvCtrlPara
  3388. //  type definition.
  3389. //--------------------------------------------------------------------------
  3390. WINCRYPT32API
  3391. BOOL
  3392. WINAPI
  3393. CryptMsgControl(
  3394.     IN HCRYPTMSG hCryptMsg,
  3395.     IN DWORD dwFlags,
  3396.     IN DWORD dwCtrlType,
  3397.     IN void const *pvCtrlPara
  3398.     );
  3399.  
  3400. //+-------------------------------------------------------------------------
  3401. //  Message control types
  3402. //--------------------------------------------------------------------------
  3403. #define CMSG_CTRL_VERIFY_SIGNATURE       1
  3404. #define CMSG_CTRL_DECRYPT                2
  3405. #define CMSG_CTRL_VERIFY_HASH            5
  3406. #define CMSG_CTRL_ADD_SIGNER             6
  3407. #define CMSG_CTRL_DEL_SIGNER             7
  3408. #define CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR 8
  3409. #define CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR 9
  3410. #define CMSG_CTRL_ADD_CERT               10
  3411. #define CMSG_CTRL_DEL_CERT               11
  3412. #define CMSG_CTRL_ADD_CRL                12
  3413. #define CMSG_CTRL_DEL_CRL                13
  3414.  
  3415. //+-------------------------------------------------------------------------
  3416. //  CMSG_CTRL_VERIFY_SIGNATURE
  3417. //
  3418. //  Verify the signature of a SIGNED or SIGNED_AND_ENVELOPED
  3419. //  message after it has been decoded.
  3420. //
  3421. //  For a SIGNED_AND_ENVELOPED message, called after
  3422. //  CryptMsgControl(CMSG_CTRL_DECRYPT), if CryptMsgOpenToDecode was called
  3423. //  with a NULL pRecipientInfo.
  3424. //
  3425. //  pvCtrlPara points to a CERT_INFO struct.
  3426. //
  3427. //  The CERT_INFO contains the Issuer and SerialNumber identifying
  3428. //  the Signer of the message. The CERT_INFO also contains the
  3429. //  PublicKeyInfo
  3430. //  used to verify the signature. The cryptographic provider specified
  3431. //  in CryptMsgOpenToDecode is used.
  3432. //--------------------------------------------------------------------------
  3433.  
  3434. //+-------------------------------------------------------------------------
  3435. //  CMSG_CTRL_DECRYPT
  3436. //
  3437. //  Decrypt an ENVELOPED or SIGNED_AND_ENVELOPED message after it has been
  3438. //  decoded.
  3439. //
  3440. //  hCryptProv and dwKeySpec specify the private key to use. For dwKeySpec ==
  3441. //  0, defaults to AT_KEYEXCHANGE.
  3442. //
  3443. //  dwRecipientIndex is the index of the recipient in the message associated
  3444. //  with the hCryptProv's private key.
  3445. //
  3446. //  This control function needs to be called, if you don't know the appropriate
  3447. //  recipient before calling CryptMsgOpenToDecode. After the final
  3448. //  CryptMsgUpdate, the list of recipients is obtained by iterating through
  3449. //  CMSG_RECIPIENT_INFO_PARAM. The recipient corresponding to a private
  3450. //  key owned by the caller is selected and passed to this function to decrypt
  3451. //  the message.
  3452. //
  3453. //  Note, the message can only be decrypted once.
  3454. //--------------------------------------------------------------------------
  3455. typedef struct _CMSG_CTRL_DECRYPT_PARA {
  3456.     DWORD       cbSize;
  3457.     HCRYPTPROV  hCryptProv;
  3458.     DWORD       dwKeySpec;
  3459.     DWORD       dwRecipientIndex;
  3460. } CMSG_CTRL_DECRYPT_PARA, *PCMSG_CTRL_DECRYPT_PARA;
  3461.  
  3462.  
  3463. //+-------------------------------------------------------------------------
  3464. //  CMSG_CTRL_VERIFY_HASH
  3465. //
  3466. //  Verify the hash of a HASHED message after it has been decoded.
  3467. //
  3468. //  Only the hCryptMsg parameter is used, to specify the message whose
  3469. //  hash is being verified.
  3470. //--------------------------------------------------------------------------
  3471.  
  3472. //+-------------------------------------------------------------------------
  3473. //  CMSG_CTRL_ADD_SIGNER
  3474. //
  3475. //  Add a signer to a signed-data or signed-and-enveloped-data message.
  3476. //
  3477. //  pvCtrlPara points to a CMSG_SIGNER_ENCODE_INFO.
  3478. //--------------------------------------------------------------------------
  3479.  
  3480. //+-------------------------------------------------------------------------
  3481. //  CMSG_CTRL_DEL_SIGNER
  3482. //
  3483. //  Remove a signer from a signed-data or signed-and-enveloped-data message.
  3484. //
  3485. //  pvCtrlPara points to a DWORD containing the 0-based index of the
  3486. //  signer to be removed.
  3487. //--------------------------------------------------------------------------
  3488.  
  3489. //+-------------------------------------------------------------------------
  3490. //  CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR
  3491. //
  3492. //  Add an unauthenticated attribute to the SignerInfo of a signed-data or
  3493. //  signed-and-enveloped-data message.
  3494. //
  3495. //  The unauthenticated attribute is input in the form of an encoded blob.
  3496. //--------------------------------------------------------------------------
  3497.  
  3498. typedef struct _CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA {
  3499.     DWORD               cbSize;
  3500.     DWORD               dwSignerIndex;
  3501.     CRYPT_DATA_BLOB     blob;
  3502. } CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA, *PCMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA;
  3503.  
  3504. //+-------------------------------------------------------------------------
  3505. //  CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR
  3506. //
  3507. //  Delete an unauthenticated attribute from the SignerInfo of a signed-data
  3508. //  or signed-and-enveloped-data message.
  3509. //
  3510. //  The unauthenticated attribute to be removed is specified by
  3511. //  a 0-based index.
  3512. //--------------------------------------------------------------------------
  3513.  
  3514. typedef struct _CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA {
  3515.     DWORD               cbSize;
  3516.     DWORD               dwSignerIndex;
  3517.     DWORD               dwUnauthAttrIndex;
  3518. } CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA, *PCMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA;
  3519.  
  3520. //+-------------------------------------------------------------------------
  3521. //  CMSG_CTRL_ADD_CERT
  3522. //
  3523. //  Add a certificate to a signed-data or signed-and-enveloped-data message.
  3524. //
  3525. //  pvCtrlPara points to a CRYPT_DATA_BLOB containing the certificate's
  3526. //  encoded bytes.
  3527. //--------------------------------------------------------------------------
  3528.  
  3529. //+-------------------------------------------------------------------------
  3530. //  CMSG_CTRL_DEL_CERT
  3531. //
  3532. //  Delete a certificate from a signed-data or signed-and-enveloped-data
  3533. //  message.
  3534. //
  3535. //  pvCtrlPara points to a DWORD containing the 0-based index of the
  3536. //  certificate to be removed.
  3537. //--------------------------------------------------------------------------
  3538.  
  3539. //+-------------------------------------------------------------------------
  3540. //  CMSG_CTRL_ADD_CRL
  3541. //
  3542. //  Add a CRL to a signed-data or signed-and-enveloped-data message.
  3543. //
  3544. //  pvCtrlPara points to a CRYPT_DATA_BLOB containing the CRL's
  3545. //  encoded bytes.
  3546. //--------------------------------------------------------------------------
  3547.  
  3548. //+-------------------------------------------------------------------------
  3549. //  CMSG_CTRL_DEL_CRL
  3550. //
  3551. //  Delete a CRL from a signed-data or signed-and-enveloped-data message.
  3552. //
  3553. //  pvCtrlPara points to a DWORD containing the 0-based index of the CRL
  3554. //  to be removed.
  3555. //--------------------------------------------------------------------------
  3556.  
  3557.  
  3558. //+-------------------------------------------------------------------------
  3559. //  Verify a countersignature, at the SignerInfo level.
  3560. //  ie. verify that pbSignerInfoCountersignature contains the encrypted
  3561. //  hash of the encryptedDigest field of pbSignerInfo.
  3562. //
  3563. //  hCryptProv is used to hash the encryptedDigest field of pbSignerInfo.
  3564. //  The only fields referenced from pciCountersigner are SerialNumber, Issuer,
  3565. //  and SubjectPublicKeyInfo.
  3566. //--------------------------------------------------------------------------
  3567. BOOL
  3568. WINAPI
  3569. CryptMsgVerifyCountersignatureEncoded(
  3570.     IN HCRYPTPROV   hCryptProv,
  3571.     IN DWORD        dwEncodingType,
  3572.     IN PBYTE        pbSignerInfo,
  3573.     IN DWORD        cbSignerInfo,
  3574.     IN PBYTE        pbSignerInfoCountersignature,
  3575.     IN DWORD        cbSignerInfoCountersignature,
  3576.     IN PCERT_INFO   pciCountersigner
  3577.     );
  3578.  
  3579. //+-------------------------------------------------------------------------
  3580. //  Countersign an already-existing signature in a message
  3581. //
  3582. //  dwIndex is a zero-based index of the SignerInfo to be countersigned.
  3583. //--------------------------------------------------------------------------
  3584. BOOL
  3585. WINAPI
  3586. CryptMsgCountersign(
  3587.     IN OUT HCRYPTMSG            hCryptMsg,
  3588.     IN DWORD                    dwIndex,
  3589.     IN DWORD                    cCountersigners,
  3590.     IN PCMSG_SIGNER_ENCODE_INFO rgCountersigners
  3591.     );
  3592.  
  3593. //+-------------------------------------------------------------------------
  3594. //  Countersign an already-existing signature (encoded SignerInfo).
  3595. //  Output an encoded SignerInfo blob, suitable for use as a countersignature
  3596. //  attribute in the unauthenticated attributes of a signed-data or
  3597. //  signed-and-enveloped-data message.
  3598. //--------------------------------------------------------------------------
  3599. BOOL
  3600. WINAPI
  3601. CryptMsgCountersignEncoded(
  3602.     IN DWORD                    dwEncodingType,
  3603.     IN PBYTE                    pbSignerInfo,
  3604.     IN DWORD                    cbSignerInfo,
  3605.     IN DWORD                    cCountersigners,
  3606.     IN PCMSG_SIGNER_ENCODE_INFO rgCountersigners,
  3607.     OUT PBYTE                   pbCountersignature,
  3608.     IN OUT PDWORD               pcbCountersignature
  3609.     );
  3610.  
  3611.  
  3612. //+-------------------------------------------------------------------------
  3613. //  Get a parameter after encoding/decoding a cryptographic message. Called
  3614. //  after the final CryptMsgUpdate. Only the CMSG_CONTENT_PARAM and
  3615. //  CMSG_COMPUTED_HASH_PARAM are valid for an encoded message.
  3616. //
  3617. //  For an encoded HASHED message, the CMSG_COMPUTED_HASH_PARAM can be got
  3618. //  before any CryptMsgUpdates to get its length.
  3619. //
  3620. //  The pvData type definition depends on the dwParamType value.
  3621. //
  3622. //  Elements pointed to by fields in the pvData structure follow the
  3623. //  structure. Therefore, *pcbData may exceed the size of the structure.
  3624. //
  3625. //  Upon input, if *pcbData == 0, then, *pcbData is updated with the length
  3626. //  of the data and the pvData parameter is ignored.
  3627. //
  3628. //  Upon return, *pcbData is updated with the length of the data.
  3629. //
  3630. //  The OBJID BLOBs returned in the pvData structures point to
  3631. //  their still encoded representation. The appropriate functions
  3632. //  must be called to decode the information.
  3633. //
  3634. //  See below for a list of the parameters to get.
  3635. //--------------------------------------------------------------------------
  3636. WINCRYPT32API
  3637. BOOL
  3638. WINAPI
  3639. CryptMsgGetParam(
  3640.     IN HCRYPTMSG hCryptMsg,
  3641.     IN DWORD dwParamType,
  3642.     IN DWORD dwIndex,
  3643.     OUT void *pvData,
  3644.     IN OUT DWORD *pcbData
  3645.     );
  3646.  
  3647. //+-------------------------------------------------------------------------
  3648. //  Get parameter types and their corresponding data structure definitions.
  3649. //--------------------------------------------------------------------------
  3650. #define CMSG_TYPE_PARAM                              1
  3651. #define CMSG_CONTENT_PARAM                           2
  3652. #define CMSG_BARE_CONTENT_PARAM                      3
  3653. #define CMSG_INNER_CONTENT_TYPE_PARAM                4
  3654. #define CMSG_SIGNER_COUNT_PARAM                      5
  3655. #define CMSG_SIGNER_INFO_PARAM                       6
  3656. #define CMSG_SIGNER_CERT_INFO_PARAM                  7
  3657. #define CMSG_SIGNER_HASH_ALGORITHM_PARAM             8
  3658. #define CMSG_SIGNER_AUTH_ATTR_PARAM                  9
  3659. #define CMSG_SIGNER_UNAUTH_ATTR_PARAM                10
  3660. #define CMSG_CERT_COUNT_PARAM                        11
  3661. #define CMSG_CERT_PARAM                              12
  3662. #define CMSG_CRL_COUNT_PARAM                         13
  3663. #define CMSG_CRL_PARAM                               14
  3664. #define CMSG_ENVELOPE_ALGORITHM_PARAM                15
  3665. #define CMSG_RECIPIENT_COUNT_PARAM                   17
  3666. #define CMSG_RECIPIENT_INDEX_PARAM                   18
  3667. #define CMSG_RECIPIENT_INFO_PARAM                    19
  3668. #define CMSG_HASH_ALGORITHM_PARAM                    20
  3669. #define CMSG_HASH_DATA_PARAM                         21
  3670. #define CMSG_COMPUTED_HASH_PARAM                     22
  3671. #define CMSG_ENCRYPT_PARAM                           26
  3672. #define CMSG_ENCRYPTED_DIGEST                        27
  3673. #define CMSG_ENCODED_SIGNER                          28
  3674. #define CMSG_ENCODED_MESSAGE                         29
  3675.  
  3676. //+-------------------------------------------------------------------------
  3677. //  CMSG_TYPE_PARAM
  3678. //
  3679. //  The type of the decoded message.
  3680. //
  3681. //  pvData points to a DWORD
  3682. //--------------------------------------------------------------------------
  3683.  
  3684. //+-------------------------------------------------------------------------
  3685. //  CMSG_CONTENT_PARAM
  3686. //
  3687. //  The encoded content of a cryptographic message. Depending on how the
  3688. //  message was opened, the content is either the whole PKCS#7
  3689. //  message (opened to encode) or the inner content (opened to decode).
  3690. //  In the decode case, the decrypted content is returned, if enveloped.
  3691. //  If not enveloped, and if the inner content is of type DATA, the returned
  3692. //  data is the contents octets of the inner content.
  3693. //
  3694. //  pvData points to the buffer receiving the content bytes
  3695. //--------------------------------------------------------------------------
  3696.  
  3697. //+-------------------------------------------------------------------------
  3698. //  CMSG_BARE_CONTENT_PARAM
  3699. //
  3700. //  The encoded content of an encoded cryptographic message, without the
  3701. //  outer layer of ContentInfo. That is, only the encoding of the
  3702. //  ContentInfo.content field is returned.
  3703. //
  3704. //  pvData points to the buffer receiving the content bytes
  3705. //--------------------------------------------------------------------------
  3706.  
  3707. //+-------------------------------------------------------------------------
  3708. //  CMSG_INNER_CONTENT_TYPE_PARAM
  3709. //
  3710. //  The type of the inner content of a decoded cryptographic message,
  3711. //  in the form of a NULL-terminated object identifier string
  3712. //  (eg. "1.2.840.113549.1.7.1").
  3713. //
  3714. //  pvData points to the buffer receiving the object identifier string
  3715. //--------------------------------------------------------------------------
  3716.  
  3717. //+-------------------------------------------------------------------------
  3718. //  CMSG_SIGNER_COUNT_PARAM
  3719. //
  3720. //  Count of signers in a SIGNED or SIGNED_AND_ENVELOPED message
  3721. //
  3722. //  pvData points to a DWORD
  3723. //--------------------------------------------------------------------------
  3724.  
  3725. //+-------------------------------------------------------------------------
  3726. //  CMSG_SIGNER_CERT_INFO_PARAM
  3727. //
  3728. //  To get all the signers, repetitively call CryptMsgGetParam, with
  3729. //  dwIndex set to 0 .. SignerCount - 1.
  3730. //
  3731. //  pvData points to a CERT_INFO struct.
  3732. //
  3733. //  Only the following fields have been updated in the CERT_INFO struct:
  3734. //  Issuer and SerialNumber.
  3735. //--------------------------------------------------------------------------
  3736.  
  3737. //+-------------------------------------------------------------------------
  3738. //  CMSG_SIGNER_INFO_PARAM
  3739. //
  3740. //  To get all the signers, repetitively call CryptMsgGetParam, with
  3741. //  dwIndex set to 0 .. SignerCount - 1.
  3742. //
  3743. //  pvData points to a CMSG_SIGNER_INFO struct.
  3744. //--------------------------------------------------------------------------
  3745. typedef struct _CMSG_SIGNER_INFO {
  3746.     DWORD                       dwVersion;
  3747.     CERT_NAME_BLOB              Issuer;
  3748.     CRYPT_INTEGER_BLOB          SerialNumber;
  3749.     CRYPT_ALGORITHM_IDENTIFIER  HashAlgorithm;
  3750.     CRYPT_ALGORITHM_IDENTIFIER  HashEncryptionAlgorithm;
  3751.     CRYPT_DATA_BLOB             EncryptedHash;
  3752.     CRYPT_ATTRIBUTES            AuthAttrs;
  3753.     CRYPT_ATTRIBUTES            UnauthAttrs;
  3754. } CMSG_SIGNER_INFO, *PCMSG_SIGNER_INFO;
  3755.  
  3756. //+-------------------------------------------------------------------------
  3757. //  CMSG_SIGNER_HASH_ALGORITHM_PARAM
  3758. //
  3759. //  This parameter specifies the HashAlgorithm that was used for the signer.
  3760. //
  3761. //  Set dwIndex to iterate through all the signers.
  3762. //
  3763. //  pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  3764. //--------------------------------------------------------------------------
  3765.  
  3766. //+-------------------------------------------------------------------------
  3767. //  CMSG_SIGNER_AUTH_ATTR_PARAM
  3768. //
  3769. //  The authenticated attributes for the signer.
  3770. //
  3771. //  Set dwIndex to iterate through all the signers.
  3772. //
  3773. //  pvData points to a CMSG_ATTR struct.
  3774. //--------------------------------------------------------------------------
  3775. typedef CRYPT_ATTRIBUTES CMSG_ATTR;
  3776. typedef CRYPT_ATTRIBUTES *PCMSG_ATTR;
  3777.  
  3778. //+-------------------------------------------------------------------------
  3779. //  CMSG_SIGNER_UNAUTH_ATTR_PARAM
  3780. //
  3781. //  The unauthenticated attributes for the signer.
  3782. //
  3783. //  Set dwIndex to iterate through all the signers.
  3784. //
  3785. //  pvData points to a CMSG_ATTR struct.
  3786. //--------------------------------------------------------------------------
  3787.  
  3788. //+-------------------------------------------------------------------------
  3789. //  CMSG_CERT_COUNT_PARAM
  3790. //
  3791. //  Count of certificates in a SIGNED or SIGNED_AND_ENVELOPED message.
  3792. //
  3793. //  pvData points to a DWORD
  3794. //--------------------------------------------------------------------------
  3795.  
  3796. //+-------------------------------------------------------------------------
  3797. //  CMSG_CERT_PARAM
  3798. //
  3799. //  To get all the certificates, repetitively call CryptMsgGetParam, with
  3800. //  dwIndex set to 0 .. CertCount - 1.
  3801. //
  3802. //  pvData points to an array of the certificate's encoded bytes.
  3803. //--------------------------------------------------------------------------
  3804.  
  3805. //+-------------------------------------------------------------------------
  3806. //  CMSG_CRL_COUNT_PARAM
  3807. //
  3808. //  Count of CRLs in a SIGNED or SIGNED_AND_ENVELOPED message.
  3809. //
  3810. //  pvData points to a DWORD
  3811. //--------------------------------------------------------------------------
  3812.  
  3813. //+-------------------------------------------------------------------------
  3814. //  CMSG_CRL_PARAM
  3815. //
  3816. //  To get all the CRLs, repetitively call CryptMsgGetParam, with
  3817. //  dwIndex set to 0 .. CrlCount - 1.
  3818. //
  3819. //  pvData points to an array of the CRL's encoded bytes.
  3820. //--------------------------------------------------------------------------
  3821.  
  3822.  
  3823. //+-------------------------------------------------------------------------
  3824. //  CMSG_ENVELOPE_ALGORITHM_PARAM
  3825. //
  3826. //  The ContentEncryptionAlgorithm that was used in
  3827. //  an ENVELOPED or SIGNED_AND_ENVELOPED message.
  3828. //
  3829. //  pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  3830. //--------------------------------------------------------------------------
  3831.  
  3832. //+-------------------------------------------------------------------------
  3833. //  CMSG_RECIPIENT_COUNT_PARAM
  3834. //
  3835. //  Count of recipients in an ENVELOPED or SIGNED_AND_ENVELOPED message.
  3836. //
  3837. //  pvData points to a DWORD
  3838. //--------------------------------------------------------------------------
  3839.  
  3840. //+-------------------------------------------------------------------------
  3841. //  CMSG_RECIPIENT_INDEX_PARAM
  3842. //
  3843. //  Index of the recipient used to decrypt an ENVELOPED or SIGNED_AND_ENVELOPED
  3844. //  message.
  3845. //
  3846. //  pvData points to a DWORD
  3847. //--------------------------------------------------------------------------
  3848.  
  3849. //+-------------------------------------------------------------------------
  3850. //  CMSG_RECIPIENT_INFO_PARAM
  3851. //
  3852. //  To get all the recipients, repetitively call CryptMsgGetParam, with
  3853. //  dwIndex set to 0 .. RecipientCount - 1.
  3854. //
  3855. //  pvData points to a CERT_INFO struct.
  3856. //
  3857. //  Only the following fields have been updated in the CERT_INFO struct:
  3858. //  Issuer, SerialNumber and PublicKeyAlgorithm. The PublicKeyAlgorithm
  3859. //  specifies the KeyEncryptionAlgorithm that was used.
  3860. //--------------------------------------------------------------------------
  3861.  
  3862. //+-------------------------------------------------------------------------
  3863. //  CMSG_HASH_ALGORITHM_PARAM
  3864. //
  3865. //  The HashAlgorithm in a HASHED message.
  3866. //
  3867. //  pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  3868. //--------------------------------------------------------------------------
  3869.  
  3870. //+-------------------------------------------------------------------------
  3871. //  CMSG_HASH_DATA_PARAM
  3872. //
  3873. //  The hash in a HASHED message.
  3874. //
  3875. //  pvData points to an array of bytes.
  3876. //--------------------------------------------------------------------------
  3877.  
  3878. //+-------------------------------------------------------------------------
  3879. //  CMSG_COMPUTED_HASH_PARAM
  3880. //
  3881. //  The computed hash for a HASHED message.
  3882. //
  3883. //  This may be called for either an encoded or decoded message.
  3884. //  It also may be called before any encoded CryptMsgUpdates to get its length.
  3885. //
  3886. //  pvData points to an array of bytes.
  3887. //--------------------------------------------------------------------------
  3888.  
  3889. //+-------------------------------------------------------------------------
  3890. //  CMSG_ENCRYPT_PARAM
  3891. //
  3892. //  The ContentEncryptionAlgorithm that was used in an ENCRYPTED message.
  3893. //
  3894. //  pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  3895. //--------------------------------------------------------------------------
  3896.  
  3897. //+-------------------------------------------------------------------------
  3898. //  CMSG_ENCODED_MESSAGE
  3899. //
  3900. //  The full encoded message. This is useful in the case of a decoded
  3901. //  message which has been modified (eg. a signed-data or
  3902. //  signed-and-enveloped-data message which has been countersigned).
  3903. //
  3904. //  pvData points to an array of the message's encoded bytes.
  3905. //--------------------------------------------------------------------------
  3906.  
  3907. //+-------------------------------------------------------------------------
  3908. //  CryptMsg OID installable functions
  3909. //--------------------------------------------------------------------------
  3910.  
  3911. // If *phCryptProv is NULL upon entry, then, if supported, the installable
  3912. // function should acquire a default provider and return. Note, its up
  3913. // to the installable function to release at process detach.
  3914. #define CMSG_OID_GEN_ENCRYPT_KEY_FUNC   "CryptMsgDllGenEncryptKey"
  3915. typedef BOOL (WINAPI *PFN_CMSG_GEN_ENCRYPT_KEY) (
  3916.     IN OUT HCRYPTPROV               *phCryptProv,
  3917.     IN PCRYPT_ALGORITHM_IDENTIFIER  paiEncrypt,
  3918.     IN PVOID                        pvEncryptAuxInfo,
  3919.     IN PCERT_PUBLIC_KEY_INFO        pPublicKeyInfo,
  3920.     OUT HCRYPTKEY                   *phEncryptKey
  3921.     );
  3922.  
  3923. #define CMSG_OID_EXPORT_ENCRYPT_KEY_FUNC   "CryptMsgDllExportEncryptKey"
  3924. typedef BOOL (WINAPI *PFN_CMSG_EXPORT_ENCRYPT_KEY) (
  3925.     IN HCRYPTPROV                   hCryptProv,
  3926.     IN HCRYPTKEY                    hEncryptKey,
  3927.     IN PCERT_PUBLIC_KEY_INFO        pPublicKeyInfo,
  3928.     OUT PBYTE                       pbData,
  3929.     IN OUT PDWORD                   pcbData
  3930.     );
  3931.  
  3932. #define CMSG_OID_IMPORT_ENCRYPT_KEY_FUNC   "CryptMsgDllImportEncryptKey"
  3933. typedef BOOL (WINAPI *PFN_CMSG_IMPORT_ENCRYPT_KEY) (
  3934.     IN HCRYPTPROV                   hCryptProv,
  3935.     IN DWORD                        dwKeySpec,
  3936.     IN PCRYPT_ALGORITHM_IDENTIFIER  paiEncrypt,
  3937.     IN PCRYPT_ALGORITHM_IDENTIFIER  paiPubKey,
  3938.     IN PBYTE                        pbEncodedKey,
  3939.     IN DWORD                        cbEncodedKey,
  3940.     OUT HCRYPTKEY                   *phEncryptKey
  3941.     );
  3942.  
  3943.  
  3944. //+=========================================================================
  3945. //  Certificate Store Data Structures and APIs
  3946. //==========================================================================
  3947.  
  3948. //+-------------------------------------------------------------------------
  3949. //              In its most basic implementation, a cert store is simply a
  3950. //              collection of certificates and/or CRLs. This is the case when
  3951. //              a cert store is opened with all of its certificates and CRLs
  3952. //              coming from a PKCS #7 encoded cryptographic message.
  3953. //
  3954. //              Nonetheless, all cert stores have the following properties:
  3955. //               - A public key may have more than one certificate in the store.
  3956. //                 For example, a private/public key used for signing may have a
  3957. //                 certificate issued for VISA and another issued for
  3958. //                 Mastercard. Also, when a certificate is renewed there might
  3959. //                 be more than one certificate with the same subject and
  3960. //                 issuer.
  3961. //               - However, each certificate in the store is uniquely
  3962. //                 identified by its Issuer and SerialNumber.
  3963. //               - There's an issuer of subject certificate relationship. A
  3964. //                 certificate's issuer is found by doing a match of
  3965. //                 pSubjectCert->Issuer with pIssuerCert->Subject.
  3966. //                 The relationship is verified by using
  3967. //                 the issuer's public key to verify the subject certificate's
  3968. //                 signature. Note, there might be X.509 v3 extensions
  3969. //                 to assist in finding the issuer certificate.
  3970. //               - Since issuer certificates might be renewed, a subject
  3971. //                 certificate might have more than one issuer certificate.
  3972. //               - There's an issuer of CRL relationship. An
  3973. //                 issuer's CRL is found by doing a match of
  3974. //                 pIssuerCert->Subject with pCrl->Issuer.
  3975. //                 The relationship is verified by using
  3976. //                 the issuer's public key to verify the CRL's
  3977. //                 signature. Note, there might be X.509 v3 extensions
  3978. //                 to assist in finding the CRL.
  3979. //               - Since some issuers might support the X.509 v3 delta CRL
  3980. //                 extensions, an issuer might have more than one CRL.
  3981. //               - The store shouldn't have any redundant certificates or
  3982. //                 CRLs. There shouldn't be two certificates with the same
  3983. //                 Issuer and SerialNumber. There shouldn't be two CRLs with
  3984. //                 the same Issuer, ThisUpdate and NextUpdate.
  3985. //               - The store has NO policy or trust information. No
  3986. //                 certificates are tagged as being "root". Its up to
  3987. //                 the application to maintain a list of CertIds (Issuer +
  3988. //                 SerialNumber) for certificates it trusts.
  3989. //               - The store might contain bad certificates and/or CRLs.
  3990. //                 The issuer's signature of a subject certificate or CRL may
  3991. //                 not verify. Certificates or CRLs may not satisfy their
  3992. //                 time validity requirements. Certificates may be
  3993. //                 revoked.
  3994. //
  3995. //              In addition to the certificates and CRLs, properties can be
  3996. //              stored. There are two predefined property IDs for a user
  3997. //              certificate: CERT_KEY_PROV_HANDLE_PROP_ID and
  3998. //              CERT_KEY_PROV_INFO_PROP_ID. The CERT_KEY_PROV_HANDLE_PROP_ID
  3999. //              is a HCRYPTPROV handle to the private key assoicated
  4000. //              with the certificate. The CERT_KEY_PROV_INFO_PROP_ID contains
  4001. //              information to be used to call
  4002. //              CryptAcquireContext and CryptProvSetParam to get a handle
  4003. //              to the private key associated with the certificate.
  4004. //
  4005. //              There exists two more predefined property IDs for certificates
  4006. //              and CRLs, CERT_SHA1_HASH_PROP_ID and CERT_MD5_HASH_PROP_ID.
  4007. //              If these properties don't already exist, then, a hash of the
  4008. //              content is computed. (CERT_HASH_PROP_ID maps to the default
  4009. //              hash algorithm, currently, CERT_SHA1_HASH_PROP_ID).
  4010. //
  4011. //              There are additional APIs for creating certificate and CRL
  4012. //      contexts not in a store (CertCreateCertificateContext and
  4013. //      CertCreateCRLContext).
  4014. //
  4015. //--------------------------------------------------------------------------
  4016.  
  4017.  
  4018. typedef void *HCERTSTORE;
  4019.  
  4020. //+-------------------------------------------------------------------------
  4021. //  Certificate context.
  4022. //
  4023. //  A certificate context contains both the encoded and decoded representation
  4024. //  of a certificate. A certificate context returned by a cert store function
  4025. //  must be freed by calling the CertFreeCertificateContext function. The
  4026. //  CertDuplicateCertificateContext function can be called to make a duplicate
  4027. //  copy (which also must be freed by calling CertFreeCertificateContext).
  4028. //--------------------------------------------------------------------------
  4029. typedef struct _CERT_CONTEXT {
  4030.     DWORD                   dwCertEncodingType;
  4031.     BYTE                    *pbCertEncoded;
  4032.     DWORD                   cbCertEncoded;
  4033.     PCERT_INFO              pCertInfo;
  4034.     HCERTSTORE              hCertStore;
  4035. } CERT_CONTEXT, *PCERT_CONTEXT;
  4036. typedef const CERT_CONTEXT *PCCERT_CONTEXT;
  4037.  
  4038. //+-------------------------------------------------------------------------
  4039. //  CRL context.
  4040. //
  4041. //  A CRL context contains both the encoded and decoded representation
  4042. //  of a CRL. A CRL context returned by a cert store function
  4043. //  must be freed by calling the CertFreeCRLContext function. The
  4044. //  CertDuplicateCRLContext function can be called to make a duplicate
  4045. //  copy (which also must be freed by calling CertFreeCRLContext).
  4046. //--------------------------------------------------------------------------
  4047. typedef struct _CRL_CONTEXT {
  4048.     DWORD                   dwCertEncodingType;
  4049.     BYTE                    *pbCrlEncoded;
  4050.     DWORD                   cbCrlEncoded;
  4051.     PCRL_INFO               pCrlInfo;
  4052.     HCERTSTORE              hCertStore;
  4053. } CRL_CONTEXT, *PCRL_CONTEXT;
  4054. typedef const CRL_CONTEXT *PCCRL_CONTEXT;
  4055.  
  4056. //+-------------------------------------------------------------------------
  4057. //  Certificate Trust List (CTL) context.
  4058. //
  4059. //  A CTL context contains both the encoded and decoded representation
  4060. //  of a CTL. Also contains an opened HCRYPTMSG handle to the decoded
  4061. //  cryptographic signed message containing the CTL_INFO as its inner content.
  4062. //  pbCtlContent is the encoded inner content of the signed message.
  4063. //
  4064. //  The CryptMsg APIs can be used to extract additional signer information.
  4065. //--------------------------------------------------------------------------
  4066. typedef struct _CTL_CONTEXT {
  4067.     DWORD                   dwMsgAndCertEncodingType;
  4068.     BYTE                    *pbCtlEncoded;
  4069.     DWORD                   cbCtlEncoded;
  4070.     PCTL_INFO               pCtlInfo;
  4071.     HCERTSTORE              hCertStore;
  4072.     HCRYPTMSG               hCryptMsg;
  4073.     BYTE                    *pbCtlContent;
  4074.     DWORD                   cbCtlContent;
  4075. } CTL_CONTEXT, *PCTL_CONTEXT;
  4076. typedef const CTL_CONTEXT *PCCTL_CONTEXT;
  4077.  
  4078. //+-------------------------------------------------------------------------
  4079. //  Certificate, CRL and CTL property IDs
  4080. //
  4081. //  See CertSetCertificateContextProperty or CertGetCertificateContextProperty
  4082. //  for usage information.
  4083. //--------------------------------------------------------------------------
  4084. #define CERT_KEY_PROV_HANDLE_PROP_ID        1
  4085. #define CERT_KEY_PROV_INFO_PROP_ID          2
  4086. #define CERT_SHA1_HASH_PROP_ID              3
  4087. #define CERT_MD5_HASH_PROP_ID               4
  4088. #define CERT_HASH_PROP_ID                   CERT_SHA1_HASH_PROP_ID
  4089. #define CERT_KEY_CONTEXT_PROP_ID            5
  4090. #define CERT_KEY_SPEC_PROP_ID               6
  4091. #define CERT_IE30_RESERVED_PROP_ID          7
  4092. #define CERT_PUBKEY_HASH_RESERVED_PROP_ID   8
  4093. #define CERT_ENHKEY_USAGE_PROP_ID           9
  4094. #define CERT_CTL_USAGE_PROP_ID              CERT_ENHKEY_USAGE_PROP_ID
  4095. #define CERT_NEXT_UPDATE_LOCATION_PROP_ID   10
  4096. #define CERT_FRIENDLY_NAME_PROP_ID          11
  4097. #define CERT_PVK_FILE_PROP_ID                12
  4098. // Note, 32 - 34 are reserved for the CERT, CRL and CTL file element IDs.
  4099. #define CERT_FIRST_RESERVED_PROP_ID         13
  4100.  
  4101. #define CERT_LAST_RESERVED_PROP_ID          0x00007FFF
  4102. #define CERT_FIRST_USER_PROP_ID             0x00008000
  4103. #define CERT_LAST_USER_PROP_ID              0x0000FFFF
  4104.  
  4105.  
  4106. #define IS_CERT_HASH_PROP_ID(X)     (CERT_SHA1_HASH_PROP_ID == (X) || \
  4107.                                             CERT_MD5_HASH_PROP_ID == (X))
  4108.  
  4109.  
  4110. //+-------------------------------------------------------------------------
  4111. //  Cryptographic Key Provider Information
  4112. //
  4113. //  CRYPT_KEY_PROV_INFO defines the CERT_KEY_PROV_INFO_PROP_ID's pvData.
  4114. //
  4115. //  The CRYPT_KEY_PROV_INFO fields are passed to CryptAcquireContext
  4116. //  to get a HCRYPTPROV handle. The optional CRYPT_KEY_PROV_PARAM fields are
  4117. //  passed to CryptProvSetParam to further initialize the provider.
  4118. //
  4119. //  The dwKeySpec field identifies the private key to use from the container
  4120. //  For example, AT_KEYEXCHANGE or AT_SIGNATURE.
  4121. //--------------------------------------------------------------------------
  4122. typedef struct _CRYPT_KEY_PROV_PARAM {
  4123.     DWORD           dwParam;
  4124.     BYTE            *pbData;
  4125.     DWORD           cbData;
  4126.     DWORD           dwFlags;
  4127. } CRYPT_KEY_PROV_PARAM, *PCRYPT_KEY_PROV_PARAM;
  4128.  
  4129. typedef struct _CRYPT_KEY_PROV_INFO {
  4130.     LPWSTR                  pwszContainerName;
  4131.     LPWSTR                  pwszProvName;
  4132.     DWORD                   dwProvType;
  4133.     DWORD                   dwFlags;
  4134.     DWORD                   cProvParam;
  4135.     PCRYPT_KEY_PROV_PARAM   rgProvParam;
  4136.     DWORD                   dwKeySpec;
  4137. } CRYPT_KEY_PROV_INFO, *PCRYPT_KEY_PROV_INFO;
  4138.  
  4139. //+-------------------------------------------------------------------------
  4140. //  The following flag should be set in the above dwFlags to enable
  4141. //  a CertSetCertificateContextProperty(CERT_KEY_CONTEXT_PROP_ID) after a
  4142. //  CryptAcquireContext is done in the Sign or Decrypt Message functions.
  4143. //
  4144. //  The following define must not collide with any of the
  4145. //  CryptAcquireContext dwFlag defines.
  4146. //--------------------------------------------------------------------------
  4147. #define CERT_SET_KEY_PROV_HANDLE_PROP_ID    0x00000001
  4148. #define CERT_SET_KEY_CONTEXT_PROP_ID        0x00000001
  4149.  
  4150. //+-------------------------------------------------------------------------
  4151. //  Certificate Key Context
  4152. //
  4153. //  CERT_KEY_CONTEXT defines the CERT_KEY_CONTEXT_PROP_ID's pvData.
  4154. //--------------------------------------------------------------------------
  4155. typedef struct _CERT_KEY_CONTEXT {
  4156.     DWORD           cbSize;           // sizeof(CERT_KEY_CONTEXT)
  4157.     HCRYPTPROV      hCryptProv;
  4158.     DWORD           dwKeySpec;
  4159. } CERT_KEY_CONTEXT, *PCERT_KEY_CONTEXT;
  4160.  
  4161. //+-------------------------------------------------------------------------
  4162. //  Certificate Store Provider Types
  4163. //--------------------------------------------------------------------------
  4164. #define CERT_STORE_PROV_MSG                 ((LPCSTR) 1)
  4165. #define CERT_STORE_PROV_MEMORY              ((LPCSTR) 2)
  4166. #define CERT_STORE_PROV_FILE                ((LPCSTR) 3)
  4167. #define CERT_STORE_PROV_REG                 ((LPCSTR) 4)
  4168.  
  4169. #define CERT_STORE_PROV_PKCS7               ((LPCSTR) 5)
  4170. #define CERT_STORE_PROV_SERIALIZED          ((LPCSTR) 6)
  4171. #define CERT_STORE_PROV_FILENAME_A          ((LPCSTR) 7)
  4172. #define CERT_STORE_PROV_FILENAME_W          ((LPCSTR) 8)
  4173. #define CERT_STORE_PROV_FILENAME            CERT_STORE_PROV_FILENAME_W
  4174. #define CERT_STORE_PROV_SYSTEM_A            ((LPCSTR) 9)
  4175. #define CERT_STORE_PROV_SYSTEM_W            ((LPCSTR) 10)
  4176. #define CERT_STORE_PROV_SYSTEM              CERT_STORE_PROV_SYSTEM_W
  4177.  
  4178. #define sz_CERT_STORE_PROV_MEMORY           "Memory"
  4179. #define sz_CERT_STORE_PROV_FILENAME_W       "File"
  4180. #define sz_CERT_STORE_PROV_FILENAME         sz_CERT_STORE_PROV_FILENAME_W
  4181. #define sz_CERT_STORE_PROV_SYSTEM_W         "System"
  4182. #define sz_CERT_STORE_PROV_SYSTEM           sz_CERT_STORE_PROV_SYSTEM_W
  4183. #define sz_CERT_STORE_PROV_PKCS7            "PKCS7"
  4184. #define sz_CERT_STORE_PROV_SERIALIZED       "Serialized"
  4185.  
  4186. //+-------------------------------------------------------------------------
  4187. //  Certificate Store verify/results flags
  4188. //--------------------------------------------------------------------------
  4189. #define CERT_STORE_SIGNATURE_FLAG           0x00000001
  4190. #define CERT_STORE_TIME_VALIDITY_FLAG       0x00000002
  4191. #define CERT_STORE_REVOCATION_FLAG          0x00000004
  4192. #define CERT_STORE_NO_CRL_FLAG              0x00010000
  4193. #define CERT_STORE_NO_ISSUER_FLAG           0x00020000
  4194.  
  4195.  
  4196. //+-------------------------------------------------------------------------
  4197. //  Certificate Store open/property flags
  4198. //--------------------------------------------------------------------------
  4199. #define CERT_STORE_NO_CRYPT_RELEASE_FLAG        0x00000001
  4200. #define CERT_STORE_READONLY_FLAG                0x00008000
  4201.  
  4202. //+-------------------------------------------------------------------------
  4203. //  Certificate Store Provider flags are in the HiWord (0xFFFF0000)
  4204. //--------------------------------------------------------------------------
  4205.  
  4206. //+-------------------------------------------------------------------------
  4207. //  Certificate System Store Flag Values
  4208. //--------------------------------------------------------------------------
  4209. // Location of the system store in the registry:
  4210. //  HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE
  4211. #define CERT_SYSTEM_STORE_LOCATION_MASK         0x00030000
  4212. #define CERT_SYSTEM_STORE_CURRENT_USER          0x00010000
  4213. #define CERT_SYSTEM_STORE_LOCAL_MACHINE         0x00020000
  4214.  
  4215.  
  4216. //+-------------------------------------------------------------------------
  4217. //  Open the cert store using the specified store provider.
  4218. //
  4219. //  hCryptProv specifies the crypto provider to use to create the hash
  4220. //  properties or verify the signature of a subject certificate or CRL.
  4221. //  The store doesn't need to use a private
  4222. //  key. If the CERT_STORE_NO_CRYPT_RELEASE_FLAG isn't set, hCryptProv is
  4223. //  CryptReleaseContext'ed on the final CertCloseStore.
  4224. //
  4225. //  Note, if the open fails, hCryptProv is released if it would have been
  4226. //  released when the store was closed.
  4227. //
  4228. //  If hCryptProv is zero, then, the default provider and container for the
  4229. //  PROV_RSA_FULL provider type is CryptAcquireContext'ed with
  4230. //  CRYPT_VERIFYCONTEXT access. The CryptAcquireContext is deferred until
  4231. //  the first create hash or verify signature. In addition, once acquired,
  4232. //  the default provider isn't released until process exit when crypt32.dll
  4233. //  is unloaded. The acquired default provider is shared across all stores
  4234. //  and threads.
  4235. //
  4236. //  After initializing the store's data structures and optionally acquiring a
  4237. //  default crypt provider, CertOpenStore calls CryptGetOIDFunctionAddress to
  4238. //  get the address of the CRYPT_OID_OPEN_STORE_PROV_FUNC specified by
  4239. //  lpszStoreProvider. Since a store can contain certificates with different
  4240. //  encoding types, CryptGetOIDFunctionAddress is called with dwEncodingType
  4241. //  set to 0 and not the dwEncodingType passed to CertOpenStore.
  4242. //  PFN_CERT_DLL_OPEN_STORE_FUNC specifies the signature of the provider's
  4243. //  open function. This provider open function is called to load the
  4244. //  store's certificates and CRLs. Optionally, the provider may return an
  4245. //  array of functions called before a certificate or CRL is added or deleted
  4246. //  or has a property that is set.
  4247. //
  4248. //  Use of the dwEncodingType parameter is provider dependent. The type
  4249. //  definition for pvPara also depends on the provider.
  4250. //
  4251. //  Store providers are installed or registered via
  4252. //  CryptInstallOIDFunctionAddress or CryptRegisterOIDFunction, where,
  4253. //  dwEncodingType is 0 and pszFuncName is CRYPT_OID_OPEN_STORE_PROV_FUNC.
  4254. //
  4255. //  Here's a list of the predefined provider types (implemented in crypt32.dll):
  4256. //
  4257. //  CERT_STORE_PROV_MSG:
  4258. //      Gets the certificates and CRLs from the specified cryptographic message.
  4259. //      dwEncodingType contains the message and certificate encoding types.
  4260. //      The message's handle is passed in pvPara. Given,
  4261. //          HCRYPTMSG hCryptMsg; pvPara = (const void *) hCryptMsg;
  4262. //
  4263. //  CERT_STORE_PROV_MEMORY
  4264. //  sz_CERT_STORE_PROV_MEMORY:
  4265. //      Opens a store without any initial certificates or CRLs. pvPara
  4266. //      isn't used.
  4267. //
  4268. //  CERT_STORE_PROV_FILE:
  4269. //      Reads the certificates and CRLs from the specified file. The file's
  4270. //      handle is passed in pvPara. Given,
  4271. //          HANDLE hFile; pvPara = (const void *) hFile;
  4272. //
  4273. //      For a successful open, the file pointer is advanced past
  4274. //      the certificates and CRLs and their properties read from the file.
  4275. //      Note, only expects a serialized store and not a file containing
  4276. //      either a PKCS #7 signed message or a single encoded certificate.
  4277. //
  4278. //      The hFile isn't closed.
  4279. //
  4280. //  CERT_STORE_PROV_REG:
  4281. //      Reads the certificates and CRLs from the registry. The registry's
  4282. //      key handle is passed in pvPara. Given,
  4283. //          HKEY hKey; pvPara = (const void *) hKey;
  4284. //
  4285. //      The input hKey isn't closed by the provider. Before returning, the
  4286. //      provider opens/creates "Certificates" and "CRLs" subkeys. These
  4287. //      subkeys remain open until the store is closed.
  4288. //
  4289. //      If CERT_STORE_READONLY_FLAG is set, then, the registry subkeys are
  4290. //      RegOpenKey'ed with KEY_READ_ACCESS. Otherwise, the registry subkeys
  4291. //      are RegCreateKey'ed with KEY_ALL_ACCESS.
  4292. //
  4293. //      This provider returns the array of functions for reading, writing,
  4294. //      deleting and property setting certificates and CRLs.
  4295. //      Any changes to the opened store are immediately pushed through to
  4296. //      the registry. However, if CERT_STORE_READONLY_FLAG is set, then,
  4297. //      writing, deleting or property setting results in a
  4298. //      SetLastError(E_ACCESSDENIED).
  4299. //
  4300. //      Note, all the certificates and CRLs are read from the registry
  4301. //      when the store is opened. The opened store serves as a write through
  4302. //      cache. However, the opened store isn't notified of other changes
  4303. //      made to the registry. Note, RegNotifyChangeKeyValue is supported
  4304. //      on NT but not supported on Windows95.
  4305. //
  4306. //  CERT_STORE_PROV_PKCS7:
  4307. //  sz_CERT_STORE_PROV_PKCS7:
  4308. //      Gets the certificates and CRLs from the encoded PKCS #7 signed message.
  4309. //      dwEncodingType specifies the message and certificate encoding types.
  4310. //      The pointer to the encoded message's blob is passed in pvPara. Given,
  4311. //          CRYPT_DATA_BLOB EncodedMsg; pvPara = (const void *) &EncodedMsg;
  4312. //
  4313. //      Note, also supports the IE3.0 special version of a
  4314. //      PKCS #7 signed message referred to as a "SPC" formatted message.
  4315. //
  4316. //  CERT_STORE_PROV_SERIALIZED:
  4317. //  sz_CERT_STORE_PROV_SERIALIZED:
  4318. //      Gets the certificates and CRLs from memory containing a serialized
  4319. //      store.  The pointer to the serialized memory blob is passed in pvPara.
  4320. //      Given,
  4321. //          CRYPT_DATA_BLOB Serialized; pvPara = (const void *) &Serialized;
  4322. //
  4323. //  CERT_STORE_PROV_FILENAME_A:
  4324. //  CERT_STORE_PROV_FILENAME_W:
  4325. //  CERT_STORE_PROV_FILENAME:
  4326. //  sz_CERT_STORE_PROV_FILENAME_W:
  4327. //  sz_CERT_STORE_PROV_FILENAME:
  4328. //      Opens the file and first attempts to read as a serialized store. Then,
  4329. //      as a PKCS #7 signed message. Finally, as a single encoded certificate.
  4330. //      The filename is passed in pvPara. The filename is UNICODE for the
  4331. //      "_W" provider and ASCII for the "_A" provider. For "_W": given,
  4332. //          LPCWSTR pwszFilename; pvPara = (const void *) pwszFilename;
  4333. //      For "_A": given,
  4334. //          LPCSTR pszFilename; pvPara = (const void *) pszFilename;
  4335. //
  4336. //      Note, the default (without "_A" or "_W") is unicode.
  4337. //
  4338. //      Note, also supports the reading of the IE3.0 special version of a
  4339. //      PKCS #7 signed message file referred to as a "SPC" formatted file.
  4340. //
  4341. //  CERT_STORE_PROV_SYSTEM_A:
  4342. //  CERT_STORE_PROV_SYSTEM_W:
  4343. //  CERT_STORE_PROV_SYSTEM:
  4344. //  sz_CERT_STORE_PROV_SYSTEM_W:
  4345. //  sz_CERT_STORE_PROV_SYSTEM:
  4346. //      Opens the specified "system" store. Currently, all the system
  4347. //      stores are stored in the registry. The upper word of the dwFlags
  4348. //      parameter is used to specify the location of the system store. It
  4349. //      should be set to either CERT_SYSTEM_STORE_CURRENT_USER for
  4350. //      HKEY_CURRENT_USER or CERT_SYSTEM_STORE_LOCAL_MACHINE for
  4351. //      HKEY_LOCAL_MACHINE.
  4352. //
  4353. //      After opening the registry key associated with the system name,
  4354. //      the CERT_STORE_PROV_REG provider is called to complete the open.
  4355. //
  4356. //      The system store name is passed in pvPara. The name is UNICODE for the
  4357. //      "_W" provider and ASCII for the "_A" provider. For "_W": given,
  4358. //          LPCWSTR pwszSystemName; pvPara = (const void *) pwszSystemName;
  4359. //      For "_A": given,
  4360. //          LPCSTR pszSystemName; pvPara = (const void *) pszSystemName;
  4361. //
  4362. //      Note, the default (without "_A" or "_W") is UNICODE.
  4363. //
  4364. //      If CERT_STORE_READONLY_FLAG is set, then, the registry is
  4365. //      RegOpenKey'ed with KEY_READ_ACCESS. Otherwise, the registry is
  4366. //      RegCreateKey'ed with KEY_ALL_ACCESS.
  4367. //
  4368. //      The "root" store is treated differently from the other system
  4369. //      stores. Before a certificate is added to or deleted from the "root"
  4370. //      store, a pop up message box is displayed. The certificate's subject,
  4371. //      issuer, serial number, time validity, sha1 and md5 thumbprints are
  4372. //      displayed. The user is given the option to do the add or delete.
  4373. //      If they don't allow the operation, LastError is set to E_ACCESSDENIED.
  4374. //--------------------------------------------------------------------------
  4375. WINCRYPT32API
  4376. HCERTSTORE
  4377. WINAPI
  4378. CertOpenStore(
  4379.     IN LPCSTR lpszStoreProvider,
  4380.     IN DWORD dwEncodingType,
  4381.     IN HCRYPTPROV hCryptProv,
  4382.     IN DWORD dwFlags,
  4383.     IN const void *pvPara
  4384.     );
  4385.  
  4386.  
  4387. //+-------------------------------------------------------------------------
  4388. //  OID Installable Certificate Store Provider Data Structures
  4389. //--------------------------------------------------------------------------
  4390.  
  4391. // Handle returned by the store provider when opened.
  4392. typedef void *HCERTSTOREPROV;
  4393.  
  4394. // Store Provider OID function's pszFuncName.
  4395. #define CRYPT_OID_OPEN_STORE_PROV_FUNC   "CertDllOpenStoreProv"
  4396.  
  4397. // Note, the Store Provider OID function's dwEncodingType is always 0.
  4398.  
  4399. // The following information is returned by the provider when opened. Its
  4400. // zeroed with cbSize set before the provider is called. If the provider
  4401. // doesn't need to be called again after the open it doesn't need to
  4402. // make any updates to the CERT_STORE_PROV_INFO.
  4403. typedef struct _CERT_STORE_PROV_INFO {
  4404.     DWORD               cbSize;
  4405.     DWORD               cStoreProvFunc;
  4406.     void                **rgpvStoreProvFunc;
  4407.     HCERTSTOREPROV      hStoreProv;
  4408.     DWORD               dwStoreProvFlags;
  4409. } CERT_STORE_PROV_INFO, *PCERT_STORE_PROV_INFO;
  4410.  
  4411. // Definition of the store provider's open function.
  4412. //
  4413. // *pStoreProvInfo has been zeroed before the call.
  4414. //
  4415. // Note, pStoreProvInfo->cStoreProvFunc should be set last.  Once set,
  4416. // all subsequent store calls, such as CertAddSerializedElementToStore will
  4417. // call the appropriate provider callback function.
  4418. typedef BOOL (WINAPI *PFN_CERT_DLL_OPEN_STORE_PROV_FUNC)(
  4419.         IN LPCSTR lpszStoreProvider,
  4420.         IN DWORD dwEncodingType,
  4421.         IN HCRYPTPROV hCryptProv,
  4422.         IN DWORD dwFlags,
  4423.         IN const void *pvPara,
  4424.         IN HCERTSTORE hCertStore,
  4425.         IN OUT PCERT_STORE_PROV_INFO pStoreProvInfo
  4426.         );
  4427.  
  4428. // Indices into the store provider's array of callback functions.
  4429. //
  4430. // The provider can implement any subset of the following functions. It
  4431. // sets pStoreProvInfo->cStoreProvFunc to the last index + 1 and any
  4432. // preceding not implemented functions to NULL.
  4433. #define CERT_STORE_PROV_CLOSE_FUNC              0
  4434. #define CERT_STORE_PROV_READ_CERT_FUNC          1
  4435. #define CERT_STORE_PROV_WRITE_CERT_FUNC         2
  4436. #define CERT_STORE_PROV_DELETE_CERT_FUNC        3
  4437. #define CERT_STORE_PROV_SET_CERT_PROPERTY_FUNC  4
  4438. #define CERT_STORE_PROV_READ_CRL_FUNC           5
  4439. #define CERT_STORE_PROV_WRITE_CRL_FUNC          6
  4440. #define CERT_STORE_PROV_DELETE_CRL_FUNC         7
  4441. #define CERT_STORE_PROV_SET_CRL_PROPERTY_FUNC   8
  4442. #define CERT_STORE_PROV_READ_CTL_FUNC           9
  4443. #define CERT_STORE_PROV_WRITE_CTL_FUNC          10
  4444. #define CERT_STORE_PROV_DELETE_CTL_FUNC         11
  4445. #define CERT_STORE_PROV_SET_CTL_PROPERTY_FUNC   12
  4446.  
  4447. // Called by CertCloseStore when the store's reference count is
  4448. // decremented to 0.
  4449. typedef void (WINAPI *PFN_CERT_STORE_PROV_CLOSE)(
  4450.         IN HCERTSTOREPROV hStoreProv,
  4451.         IN DWORD dwFlags
  4452.         );
  4453.  
  4454. // Currently not called directly by the store APIs. However, may be exported
  4455. // to support other providers based on it.
  4456. //
  4457. // Reads the provider's copy of the certificate context. If it exists,
  4458. // creates a new certificate context.
  4459. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_READ_CERT)(
  4460.         IN HCERTSTOREPROV hStoreProv,
  4461.         IN PCCERT_CONTEXT pStoreCertContext,
  4462.         IN DWORD dwFlags,
  4463.         OUT PCCERT_CONTEXT *ppProvCertContext
  4464.         );
  4465.  
  4466. #define CERT_STORE_PROV_WRITE_ADD_FLAG      0x1
  4467.  
  4468. // Called by CertAddEncodedCertificateToStore,
  4469. // CertAddCertificateContextToStore or CertAddSerializedElementToStore before
  4470. // adding to the store. The CERT_STORE_PROV_WRITE_ADD_FLAG is set. In
  4471. // addition to the encoded certificate, the added pCertContext might also
  4472. // have properties.
  4473. //
  4474. // Returns TRUE if its OK to update the the store.
  4475. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_WRITE_CERT)(
  4476.         IN HCERTSTOREPROV hStoreProv,
  4477.         IN PCCERT_CONTEXT pCertContext,
  4478.         IN DWORD dwFlags
  4479.         );
  4480.  
  4481. // Called by CertDeleteCertificateFromStore before deleting from the
  4482. // store.
  4483. //
  4484. // Returns TRUE if its OK to delete from the store.
  4485. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_DELETE_CERT)(
  4486.         IN HCERTSTOREPROV hStoreProv,
  4487.         IN PCCERT_CONTEXT pCertContext,
  4488.         IN DWORD dwFlags
  4489.         );
  4490.  
  4491. // Called by CertSetCertificateContextProperty before setting the
  4492. // certificate's property. Also called by CertGetCertificateContextProperty,
  4493. // when getting a hash property that needs to be created and then persisted
  4494. // via the set.
  4495. //
  4496. // Upon input, the property hasn't been set for the pCertContext parameter.
  4497. //
  4498. // Returns TRUE if its OK to set the property.
  4499. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_SET_CERT_PROPERTY)(
  4500.         IN HCERTSTOREPROV hStoreProv,
  4501.         IN PCCERT_CONTEXT pCertContext,
  4502.         IN DWORD dwPropId,
  4503.         IN DWORD dwFlags,
  4504.         IN const void *pvData
  4505.         );
  4506.  
  4507. // Currently not called directly by the store APIs. However, may be exported
  4508. // to support other providers based on it.
  4509. //
  4510. // Reads the provider's copy of the CRL context. If it exists,
  4511. // creates a new CRL context.
  4512. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_READ_CRL)(
  4513.         IN HCERTSTOREPROV hStoreProv,
  4514.         IN PCCRL_CONTEXT pStoreCrlContext,
  4515.         IN DWORD dwFlags,
  4516.         OUT PCCRL_CONTEXT *ppProvCrlContext
  4517.         );
  4518.  
  4519. // Called by CertAddEncodedCRLToStore,
  4520. // CertAddCRLContextToStore or CertAddSerializedElementToStore before
  4521. // adding to the store. The CERT_STORE_PROV_WRITE_ADD_FLAG is set. In
  4522. // addition to the encoded CRL, the added pCertContext might also
  4523. // have properties.
  4524. //
  4525. // Returns TRUE if its OK to update the the store.
  4526. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_WRITE_CRL)(
  4527.         IN HCERTSTOREPROV hStoreProv,
  4528.         IN PCCRL_CONTEXT pCrlContext,
  4529.         IN DWORD dwFlags
  4530.         );
  4531.  
  4532. // Called by CertDeleteCRLFromStore before deleting from the store.
  4533. //
  4534. // Returns TRUE if its OK to delete from the store.
  4535. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_DELETE_CRL)(
  4536.         IN HCERTSTOREPROV hStoreProv,
  4537.         IN PCCRL_CONTEXT pCrlContext,
  4538.         IN DWORD dwFlags
  4539.         );
  4540.  
  4541. // Called by CertSetCRLContextProperty before setting the
  4542. // CRL's property. Also called by CertGetCRLContextProperty,
  4543. // when getting a hash property that needs to be created and then persisted
  4544. // via the set.
  4545. //
  4546. // Upon input, the property hasn't been set for the pCrlContext parameter.
  4547. //
  4548. // Returns TRUE if its OK to set the property.
  4549. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_SET_CRL_PROPERTY)(
  4550.         IN HCERTSTOREPROV hStoreProv,
  4551.         IN PCCRL_CONTEXT pCrlContext,
  4552.         IN DWORD dwPropId,
  4553.         IN DWORD dwFlags,
  4554.         IN const void *pvData
  4555.         );
  4556.  
  4557. // Currently not called directly by the store APIs. However, may be exported
  4558. // to support other providers based on it.
  4559. //
  4560. // Reads the provider's copy of the CTL context. If it exists,
  4561. // creates a new CTL context.
  4562. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_READ_CTL)(
  4563.         IN HCERTSTOREPROV hStoreProv,
  4564.         IN PCCTL_CONTEXT pStoreCtlContext,
  4565.         IN DWORD dwFlags,
  4566.         OUT PCCTL_CONTEXT *ppProvCtlContext
  4567.         );
  4568.  
  4569. // Called by CertAddEncodedCTLToStore,
  4570. // CertAddCTLContextToStore or CertAddSerializedElementToStore before
  4571. // adding to the store. The CERT_STORE_PROV_WRITE_ADD_FLAG is set. In
  4572. // addition to the encoded CTL, the added pCertContext might also
  4573. // have properties.
  4574. //
  4575. // Returns TRUE if its OK to update the the store.
  4576. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_WRITE_CTL)(
  4577.         IN HCERTSTOREPROV hStoreProv,
  4578.         IN PCCTL_CONTEXT pCtlContext,
  4579.         IN DWORD dwFlags
  4580.         );
  4581.  
  4582. // Called by CertDeleteCTLFromStore before deleting from the store.
  4583. //
  4584. // Returns TRUE if its OK to delete from the store.
  4585. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_DELETE_CTL)(
  4586.         IN HCERTSTOREPROV hStoreProv,
  4587.         IN PCCTL_CONTEXT pCtlContext,
  4588.         IN DWORD dwFlags
  4589.         );
  4590.  
  4591. // Called by CertSetCTLContextProperty before setting the
  4592. // CTL's property. Also called by CertGetCTLContextProperty,
  4593. // when getting a hash property that needs to be created and then persisted
  4594. // via the set.
  4595. //
  4596. // Upon input, the property hasn't been set for the pCtlContext parameter.
  4597. //
  4598. // Returns TRUE if its OK to set the property.
  4599. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_SET_CTL_PROPERTY)(
  4600.         IN HCERTSTOREPROV hStoreProv,
  4601.         IN PCCTL_CONTEXT pCtlContext,
  4602.         IN DWORD dwPropId,
  4603.         IN DWORD dwFlags,
  4604.         IN const void *pvData
  4605.         );
  4606.  
  4607. //+-------------------------------------------------------------------------
  4608. //  Duplicate a cert store handle
  4609. //--------------------------------------------------------------------------
  4610. WINCRYPT32API
  4611. HCERTSTORE
  4612. WINAPI
  4613. CertDuplicateStore(
  4614.     IN HCERTSTORE hCertStore
  4615.     );
  4616.  
  4617. #define CERT_STORE_SAVE_AS_STORE        1
  4618. #define CERT_STORE_SAVE_AS_PKCS7        2
  4619.  
  4620. #define CERT_STORE_SAVE_TO_FILE         1
  4621. #define CERT_STORE_SAVE_TO_MEMORY       2
  4622. #define CERT_STORE_SAVE_TO_FILENAME_A   3
  4623. #define CERT_STORE_SAVE_TO_FILENAME_W   4
  4624. #define CERT_STORE_SAVE_TO_FILENAME     CERT_STORE_SAVE_TO_FILENAME_W
  4625.  
  4626. //+-------------------------------------------------------------------------
  4627. //  Save the cert store. Extended version with lots of options.
  4628. //
  4629. //  According to the dwSaveAs parameter, the store can be saved as a
  4630. //  serialized store (CERT_STORE_SAVE_AS_STORE) containing properties in
  4631. //  addition to encoded certificates, CRLs and CTLs or the store can be saved
  4632. //  as a PKCS #7 signed message (CERT_STORE_SAVE_AS_PKCS7) which doesn't
  4633. //  include the properties or CTLs.
  4634. //
  4635. //  Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  4636. //  CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't saved into
  4637. //  a serialized store.
  4638. //
  4639. //  For CERT_STORE_SAVE_AS_PKCS7, the dwEncodingType specifies the message
  4640. //  encoding type. The dwEncodingType parameter isn't used for
  4641. //  CERT_STORE_SAVE_AS_STORE.
  4642. //
  4643. //  The dwFlags parameter currently isn't used and should be set to 0.
  4644. //
  4645. //  The dwSaveTo and pvSaveToPara parameters specify where to save the
  4646. //  store as follows:
  4647. //    CERT_STORE_SAVE_TO_FILE:
  4648. //      Saves to the specified file. The file's handle is passed in
  4649. //      pvSaveToPara. Given,
  4650. //          HANDLE hFile; pvSaveToPara = (void *) hFile;
  4651. //
  4652. //      For a successful save, the file pointer is positioned after the
  4653. //      last write.
  4654. //
  4655. //    CERT_STORE_SAVE_TO_MEMORY:
  4656. //      Saves to the specified memory blob. The pointer to
  4657. //      the memory blob is passed in pvSaveToPara. Given,
  4658. //          CRYPT_DATA_BLOB SaveBlob; pvSaveToPara = (void *) &SaveBlob;
  4659. //      Upon entry, the SaveBlob's pbData and cbData need to be initialized.
  4660. //      Upon return, cbData is updated with the actual length.
  4661. //      For a length only calculation, pbData should be set to NULL. If
  4662. //      pbData is non-NULL and cbData isn't large enough, FALSE is returned
  4663. //      with a last error of ERRROR_MORE_DATA.
  4664. //
  4665. //    CERT_STORE_SAVE_TO_FILENAME_A:
  4666. //    CERT_STORE_SAVE_TO_FILENAME_W:
  4667. //    CERT_STORE_SAVE_TO_FILENAME:
  4668. //      Opens the file and saves to it. The filename is passed in pvSaveToPara.
  4669. //      The filename is UNICODE for the "_W" option and ASCII for the "_A"
  4670. //      option. For "_W": given,
  4671. //          LPCWSTR pwszFilename; pvSaveToPara = (void *) pwszFilename;
  4672. //      For "_A": given,
  4673. //          LPCSTR pszFilename; pvSaveToPara = (void *) pszFilename;
  4674. //
  4675. //      Note, the default (without "_A" or "_W") is UNICODE.
  4676. //
  4677. //--------------------------------------------------------------------------
  4678. BOOL
  4679. WINAPI
  4680. CertSaveStore(
  4681.     IN HCERTSTORE hCertStore,
  4682.     IN DWORD dwEncodingType,
  4683.     IN DWORD dwSaveAs,
  4684.     IN DWORD dwSaveTo,
  4685.     IN OUT void *pvSaveToPara,
  4686.     IN DWORD dwFlags
  4687.     );
  4688.  
  4689. //+-------------------------------------------------------------------------
  4690. //  Certificate Store close flags
  4691. //--------------------------------------------------------------------------
  4692. #define CERT_CLOSE_STORE_FORCE_FLAG         0x00000001
  4693. #define CERT_CLOSE_STORE_CHECK_FLAG         0x00000002
  4694.  
  4695. //+-------------------------------------------------------------------------
  4696. //  Close a cert store handle.
  4697. //
  4698. //  There needs to be a corresponding close for each open and duplicate.
  4699. //
  4700. //  Even on the final close, the cert store isn't freed until all of its
  4701. //  certificate and CRL contexts have also been freed.
  4702. //
  4703. //  On the final close, the hCryptProv passed to CertStoreOpen is
  4704. //  CryptReleaseContext'ed.
  4705. //
  4706. //  To force the closure of the store with all of its memory freed, set the
  4707. //  CERT_STORE_CLOSE_FORCE_FLAG. This flag should be set when the caller does
  4708. //  its own reference counting and wants everything to vanish.
  4709. //
  4710. //  To check if all the store's certificates and CRLs have been freed and that
  4711. //  this is the last CertCloseStore, set the CERT_CLOSE_STORE_CHECK_FLAG. If
  4712. //  set and certs, CRLs or stores still need to be freed/closed, FALSE is
  4713. //  returned with LastError set to CRYPT_E_PENDING_CLOSE. Note, for FALSE,
  4714. //  the store is still closed. This is a diagnostic flag.
  4715. //
  4716. //  LastError is preserved unless CERT_CLOSE_STORE_CHECK_FLAG is set and FALSE
  4717. //  is returned.
  4718. //--------------------------------------------------------------------------
  4719. WINCRYPT32API
  4720. BOOL
  4721. WINAPI
  4722. CertCloseStore(
  4723.     IN HCERTSTORE hCertStore,
  4724.     DWORD dwFlags
  4725.     );
  4726.  
  4727. //+-------------------------------------------------------------------------
  4728. //  Get the subject certificate context uniquely identified by its Issuer and
  4729. //  SerialNumber from the store.
  4730. //
  4731. //  If the certificate isn't found, NULL is returned. Otherwise, a pointer to
  4732. //  a read only CERT_CONTEXT is returned. CERT_CONTEXT must be freed by calling
  4733. //  CertFreeCertificateContext. CertDuplicateCertificateContext can be called to make a
  4734. //  duplicate.
  4735. //
  4736. //  The returned certificate might not be valid. Normally, it would be
  4737. //  verified when getting its issuer certificate (CertGetIssuerCertificateFromStore).
  4738. //--------------------------------------------------------------------------
  4739. WINCRYPT32API
  4740. PCCERT_CONTEXT
  4741. WINAPI
  4742. CertGetSubjectCertificateFromStore(
  4743.     IN HCERTSTORE hCertStore,
  4744.     IN DWORD dwCertEncodingType,
  4745.     IN PCERT_INFO pCertId           // Only the Issuer and SerialNumber
  4746.                                     // fields are used
  4747.     );
  4748.  
  4749. //+-------------------------------------------------------------------------
  4750. //  Enumerate the certificate contexts in the store.
  4751. //
  4752. //  If a certificate isn't found, NULL is returned.
  4753. //  Otherwise, a pointer to a read only CERT_CONTEXT is returned. CERT_CONTEXT
  4754. //  must be freed by calling CertFreeCertificateContext or is freed when passed as the
  4755. //  pPrevCertContext on a subsequent call. CertDuplicateCertificateContext
  4756. //  can be called to make a duplicate.
  4757. //
  4758. //  pPrevCertContext MUST BE NULL to enumerate the first
  4759. //  certificate in the store. Successive certificates are enumerated by setting
  4760. //  pPrevCertContext to the CERT_CONTEXT returned by a previous call.
  4761. //
  4762. //  NOTE: a NON-NULL pPrevCertContext is always CertFreeCertificateContext'ed by
  4763. //  this function, even for an error.
  4764. //--------------------------------------------------------------------------
  4765. WINCRYPT32API
  4766. PCCERT_CONTEXT
  4767. WINAPI
  4768. CertEnumCertificatesInStore(
  4769.     IN HCERTSTORE hCertStore,
  4770.     IN PCCERT_CONTEXT pPrevCertContext
  4771.     );
  4772.  
  4773. //+-------------------------------------------------------------------------
  4774. //  Find the first or next certificate context in the store.
  4775. //
  4776. //  The certificate is found according to the dwFindType and its pvFindPara.
  4777. //  See below for a list of the find types and its parameters.
  4778. //
  4779. //  Currently dwFindFlags is only used for CERT_FIND_SUBJECT_ATTR,
  4780. //  CERT_FIND_ISSUER_ATTR or CERT_FIND_CTL_USAGE. Otherwise, must be set to 0.
  4781. //
  4782. //  Usage of dwCertEncodingType depends on the dwFindType.
  4783. //
  4784. //  If the first or next certificate isn't found, NULL is returned.
  4785. //  Otherwise, a pointer to a read only CERT_CONTEXT is returned. CERT_CONTEXT
  4786. //  must be freed by calling CertFreeCertificateContext or is freed when passed as the
  4787. //  pPrevCertContext on a subsequent call. CertDuplicateCertificateContext
  4788. //  can be called to make a duplicate.
  4789. //
  4790. //  pPrevCertContext MUST BE NULL on the first
  4791. //  call to find the certificate. To find the next certificate, the
  4792. //  pPrevCertContext is set to the CERT_CONTEXT returned by a previous call.
  4793. //
  4794. //  NOTE: a NON-NULL pPrevCertContext is always CertFreeCertificateContext'ed by
  4795. //  this function, even for an error.
  4796. //--------------------------------------------------------------------------
  4797. WINCRYPT32API
  4798. PCCERT_CONTEXT
  4799. WINAPI
  4800. CertFindCertificateInStore(
  4801.     IN HCERTSTORE hCertStore,
  4802.     IN DWORD dwCertEncodingType,
  4803.     IN DWORD dwFindFlags,
  4804.     IN DWORD dwFindType,
  4805.     IN const void *pvFindPara,
  4806.     IN PCCERT_CONTEXT pPrevCertContext
  4807.     );
  4808.  
  4809.  
  4810. //+-------------------------------------------------------------------------
  4811. // Certificate comparison functions
  4812. //--------------------------------------------------------------------------
  4813. #define CERT_COMPARE_MASK           0xFFFF
  4814. #define CERT_COMPARE_SHIFT          16
  4815. #define CERT_COMPARE_ANY            0
  4816. #define CERT_COMPARE_SHA1_HASH      1
  4817. #define CERT_COMPARE_NAME           2
  4818. #define CERT_COMPARE_ATTR           3
  4819. #define CERT_COMPARE_MD5_HASH       4
  4820. #define CERT_COMPARE_PROPERTY       5
  4821. #define CERT_COMPARE_PUBLIC_KEY     6
  4822. #define CERT_COMPARE_HASH           CERT_COMPARE_SHA1_HASH
  4823. #define CERT_COMPARE_NAME_STR_A     7
  4824. #define CERT_COMPARE_NAME_STR_W     8
  4825. #define CERT_COMPARE_KEY_SPEC       9
  4826. #define CERT_COMPARE_ENHKEY_USAGE   10
  4827. #define CERT_COMPARE_CTL_USAGE      CERT_COMPARE_ENHKEY_USAGE
  4828.  
  4829. //+-------------------------------------------------------------------------
  4830. //  dwFindType
  4831. //
  4832. //  The dwFindType definition consists of two components:
  4833. //   - comparison function
  4834. //   - certificate information flag
  4835. //--------------------------------------------------------------------------
  4836. #define CERT_FIND_ANY           (CERT_COMPARE_ANY << CERT_COMPARE_SHIFT)
  4837. #define CERT_FIND_SHA1_HASH     (CERT_COMPARE_SHA1_HASH << CERT_COMPARE_SHIFT)
  4838. #define CERT_FIND_MD5_HASH      (CERT_COMPARE_MD5_HASH << CERT_COMPARE_SHIFT)
  4839. #define CERT_FIND_HASH          CERT_FIND_SHA1_HASH
  4840. #define CERT_FIND_PROPERTY      (CERT_COMPARE_PROPERTY << CERT_COMPARE_SHIFT)
  4841. #define CERT_FIND_PUBLIC_KEY    (CERT_COMPARE_PUBLIC_KEY << CERT_COMPARE_SHIFT)
  4842. #define CERT_FIND_SUBJECT_NAME  (CERT_COMPARE_NAME << CERT_COMPARE_SHIFT | \
  4843.                                  CERT_INFO_SUBJECT_FLAG)
  4844. #define CERT_FIND_SUBJECT_ATTR  (CERT_COMPARE_ATTR << CERT_COMPARE_SHIFT | \
  4845.                                  CERT_INFO_SUBJECT_FLAG)
  4846. #define CERT_FIND_ISSUER_NAME   (CERT_COMPARE_NAME << CERT_COMPARE_SHIFT | \
  4847.                                  CERT_INFO_ISSUER_FLAG)
  4848. #define CERT_FIND_ISSUER_ATTR   (CERT_COMPARE_ATTR << CERT_COMPARE_SHIFT | \
  4849.                                  CERT_INFO_ISSUER_FLAG)
  4850. #define CERT_FIND_SUBJECT_STR_A (CERT_COMPARE_NAME_STR_A << CERT_COMPARE_SHIFT | \
  4851.                                  CERT_INFO_SUBJECT_FLAG)
  4852. #define CERT_FIND_SUBJECT_STR_W (CERT_COMPARE_NAME_STR_W << CERT_COMPARE_SHIFT | \
  4853.                                  CERT_INFO_SUBJECT_FLAG)
  4854. #define CERT_FIND_SUBJECT_STR   CERT_FIND_SUBJECT_STR_W
  4855. #define CERT_FIND_ISSUER_STR_A  (CERT_COMPARE_NAME_STR_A << CERT_COMPARE_SHIFT | \
  4856.                                  CERT_INFO_ISSUER_FLAG)
  4857. #define CERT_FIND_ISSUER_STR_W  (CERT_COMPARE_NAME_STR_W << CERT_COMPARE_SHIFT | \
  4858.                                  CERT_INFO_ISSUER_FLAG)
  4859. #define CERT_FIND_ISSUER_STR    CERT_FIND_ISSUER_STR_W
  4860. #define CERT_FIND_KEY_SPEC      (CERT_COMPARE_KEY_SPEC << CERT_COMPARE_SHIFT)
  4861. #define CERT_FIND_ENHKEY_USAGE  (CERT_COMPARE_ENHKEY_USAGE << CERT_COMPARE_SHIFT)
  4862. #define CERT_FIND_CTL_USAGE     CERT_FIND_ENHKEY_USAGE
  4863.  
  4864.  
  4865.  
  4866. //+-------------------------------------------------------------------------
  4867. //  CERT_FIND_ANY
  4868. //
  4869. //  Find any certificate.
  4870. //
  4871. //  pvFindPara isn't used.
  4872. //--------------------------------------------------------------------------
  4873.  
  4874. //+-------------------------------------------------------------------------
  4875. //  CERT_FIND_HASH
  4876. //
  4877. //  Find a certificate with the specified hash.
  4878. //
  4879. //  pvFindPara points to a CRYPT_HASH_BLOB.
  4880. //--------------------------------------------------------------------------
  4881.  
  4882. //+-------------------------------------------------------------------------
  4883. //  CERT_FIND_PROPERTY
  4884. //
  4885. //  Find a certificate having the specified property.
  4886. //
  4887. //  pvFindPara points to a DWORD containing the PROP_ID
  4888. //--------------------------------------------------------------------------
  4889.  
  4890. //+-------------------------------------------------------------------------
  4891. //  CERT_FIND_PUBLIC_KEY
  4892. //
  4893. //  Find a certificate matching the specified public key.
  4894. //
  4895. //  pvFindPara points to a CERT_PUBLIC_KEY_INFO containing the public key
  4896. //--------------------------------------------------------------------------
  4897.  
  4898. //+-------------------------------------------------------------------------
  4899. //  CERT_FIND_SUBJECT_NAME
  4900. //  CERT_FIND_ISSUER_NAME
  4901. //
  4902. //  Find a certificate with the specified subject/issuer name. Does an exact
  4903. //  match of the entire name.
  4904. //
  4905. //  Restricts search to certificates matching the dwCertEncodingType.
  4906. //
  4907. //  pvFindPara points to a CERT_NAME_BLOB.
  4908. //--------------------------------------------------------------------------
  4909.  
  4910. //+-------------------------------------------------------------------------
  4911. //  CERT_FIND_SUBJECT_ATTR
  4912. //  CERT_FIND_ISSUER_ATTR
  4913. //
  4914. //  Find a certificate with the specified subject/issuer attributes.
  4915. //
  4916. //  Compares the attributes in the subject/issuer name with the
  4917. //  Relative Distinguished Name's (CERT_RDN) array of attributes specified in
  4918. //  pvFindPara. The comparison iterates through the CERT_RDN attributes and looks
  4919. //  for an attribute match in any of the subject/issuer's RDNs.
  4920. //
  4921. //  The CERT_RDN_ATTR fields can have the following special values:
  4922. //    pszObjId == NULL              - ignore the attribute object identifier
  4923. //    dwValueType == RDN_ANY_TYPE   - ignore the value type
  4924. //    Value.pbData == NULL          - match any value
  4925. //
  4926. //  Currently only an exact, case sensitive match is supported.
  4927. //
  4928. //  CERT_UNICODE_IS_RDN_ATTRS_FLAG should be set in dwFindFlags if the RDN was
  4929. //  initialized with unicode strings as for
  4930. //  CryptEncodeObject(X509_UNICODE_NAME).
  4931. //
  4932. //  Restricts search to certificates matching the dwCertEncodingType.
  4933. //
  4934. //  pvFindPara points to a CERT_RDN (defined in wincert.h).
  4935. //--------------------------------------------------------------------------
  4936.  
  4937. //+-------------------------------------------------------------------------
  4938. //  CERT_FIND_SUBJECT_STR_A
  4939. //  CERT_FIND_SUBJECT_STR_W | CERT_FIND_SUBJECT_STR
  4940. //  CERT_FIND_ISSUER_STR_A
  4941. //  CERT_FIND_ISSUER_STR_W  | CERT_FIND_ISSUER_STR
  4942. //
  4943. //  Find a certificate containing the specified subject/issuer name string.
  4944. //
  4945. //  First, the certificate's subject/issuer is converted to a name string
  4946. //  via CertNameToStrA/CertNameToStrW(CERT_SIMPLE_NAME_STR). Then, a
  4947. //  case insensitive substring within string match is performed.
  4948. //
  4949. //  Restricts search to certificates matching the dwCertEncodingType.
  4950. //
  4951. //  For *_STR_A, pvFindPara points to a null terminated character string.
  4952. //  For *_STR_W, pvFindPara points to a null terminated wide character string.
  4953. //--------------------------------------------------------------------------
  4954.  
  4955. //+-------------------------------------------------------------------------
  4956. //  CERT_FIND_KEY_SPEC
  4957. //
  4958. //  Find a certificate having a CERT_KEY_SPEC_PROP_ID property matching
  4959. //  the specified KeySpec.
  4960. //
  4961. //  pvFindPara points to a DWORD containing the KeySpec.
  4962. //--------------------------------------------------------------------------
  4963.  
  4964. //+-------------------------------------------------------------------------
  4965. //  CERT_FIND_ENHKEY_USAGE
  4966. //
  4967. //  Find a certificate having the szOID_ENHANCED_KEY_USAGE extension or
  4968. //  the CERT_ENHKEY_USAGE_PROP_ID and matching the specified pszUsageIdentifers.
  4969. //
  4970. //  pvFindPara points to a CERT_ENHKEY_USAGE data structure. If pvFindPara
  4971. //  is NULL or CERT_ENHKEY_USAGE's cUsageIdentifier is 0, then, matches any
  4972. //  certificate having enhanced key usage.
  4973. //
  4974. //  The CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG can be set in dwFindFlags to
  4975. //  also match a certificate without either the extension or property.
  4976. //
  4977. //  If CERT_FIND_NO_ENHKEY_USAGE_FLAG is set in dwFindFlags, finds
  4978. //  certificates without the key usage extension or property. Setting this
  4979. //  flag takes precedence over pvFindPara being NULL.
  4980. //
  4981. //  If the CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG is set, then, only does a match
  4982. //  using the extension. If pvFindPara is NULL or cUsageIdentifier is set to
  4983. //  0, finds certificates having the extension. If
  4984. //  CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG is set, also matches a certificate
  4985. //  without the extension. If CERT_FIND_NO_ENHKEY_USAGE_FLAG is set, finds
  4986. //  certificates without the extension.
  4987. //
  4988. //  If the CERT_FIND_EXT_PROP_ENHKEY_USAGE_FLAG is set, then, only does a match
  4989. //  using the property. If pvFindPara is NULL or cUsageIdentifier is set to
  4990. //  0, finds certificates having the property. If
  4991. //  CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG is set, also matches a certificate
  4992. //  without the property. If CERT_FIND_NO_ENHKEY_USAGE_FLAG is set, finds
  4993. //  certificates without the property.
  4994. //--------------------------------------------------------------------------
  4995.  
  4996. #define CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG  0x1
  4997. #define CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG  0x2
  4998. #define CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG 0x4
  4999. #define CERT_FIND_NO_ENHKEY_USAGE_FLAG        0x8
  5000.  
  5001. #define CERT_FIND_OPTIONAL_CTL_USAGE_FLAG   CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG
  5002.  
  5003. #define CERT_FIND_EXT_ONLY_CTL_USAGE_FLAG \
  5004.         CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG
  5005.  
  5006. #define CERT_FIND_PROP_ONLY_CTL_USAGE_FLAG \
  5007.         CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG
  5008.  
  5009. #define CERT_FIND_NO_CTL_USAGE_FLAG         CERT_FIND_NO_ENHKEY_USAGE_FLAG
  5010.  
  5011. //+-------------------------------------------------------------------------
  5012. //  Get the certificate context from the store for the first or next issuer
  5013. //  of the specified subject certificate. Perform the enabled
  5014. //  verification checks on the subject. (Note, the checks are on the subject
  5015. //  using the returned issuer certificate.)
  5016. //
  5017. //  If the first or next issuer certificate isn't found, NULL is returned.
  5018. //  Otherwise, a pointer to a read only CERT_CONTEXT is returned. CERT_CONTEXT
  5019. //  must be freed by calling CertFreeCertificateContext or is freed when passed as the
  5020. //  pPrevIssuerContext on a subsequent call. CertDuplicateCertificateContext
  5021. //  can be called to make a duplicate.
  5022. //
  5023. //  For a self signed subject certificate, NULL is returned with LastError set
  5024. //  to CERT_STORE_SELF_SIGNED. The enabled verification checks are still done.
  5025. //
  5026. //  The pSubjectContext may have been obtained from this store, another store
  5027. //  or created by the caller application. When created by the caller, the
  5028. //  CertCreateCertificateContext function must have been called.
  5029. //
  5030. //  An issuer may have multiple certificates. This may occur when the validity
  5031. //  period is about to change. pPrevIssuerContext MUST BE NULL on the first
  5032. //  call to get the issuer. To get the next certificate for the issuer, the
  5033. //  pPrevIssuerContext is set to the CERT_CONTEXT returned by a previous call.
  5034. //
  5035. //  NOTE: a NON-NULL pPrevIssuerContext is always CertFreeCertificateContext'ed by
  5036. //  this function, even for an error.
  5037. //
  5038. //  The following flags can be set in *pdwFlags to enable verification checks
  5039. //  on the subject certificate context:
  5040. //      CERT_STORE_SIGNATURE_FLAG     - use the public key in the returned
  5041. //                                      issuer certificate to verify the
  5042. //                                      signature on the subject certificate.
  5043. //                                      Note, if pSubjectContext->hCertStore ==
  5044. //                                      hCertStore, the store provider might
  5045. //                                      be able to eliminate a redo of
  5046. //                                      the signature verify.
  5047. //      CERT_STORE_TIME_VALIDITY_FLAG - get the current time and verify that
  5048. //                                      its within the subject certificate's
  5049. //                                      validity period
  5050. //      CERT_STORE_REVOCATION_FLAG    - check if the subject certificate is on
  5051. //                                      the issuer's revocation list
  5052. //
  5053. //  If an enabled verification check fails, then, its flag is set upon return.
  5054. //  If CERT_STORE_REVOCATION_FLAG was enabled and the issuer doesn't have a
  5055. //  CRL in the store, then, CERT_STORE_NO_CRL_FLAG is set in addition to
  5056. //  the CERT_STORE_REVOCATION_FLAG.
  5057. //
  5058. //  If CERT_STORE_SIGNATURE_FLAG or CERT_STORE_REVOCATION_FLAG is set, then,
  5059. //  CERT_STORE_NO_ISSUER_FLAG is set if it doesn't have an issuer certificate
  5060. //  in the store.
  5061. //
  5062. //  For a verification check failure, a pointer to the issuer's CERT_CONTEXT
  5063. //  is still returned and SetLastError isn't updated.
  5064. //--------------------------------------------------------------------------
  5065. WINCRYPT32API
  5066. PCCERT_CONTEXT
  5067. WINAPI
  5068. CertGetIssuerCertificateFromStore(
  5069.     IN HCERTSTORE hCertStore,
  5070.     IN PCCERT_CONTEXT pSubjectContext,
  5071.     IN OPTIONAL PCCERT_CONTEXT pPrevIssuerContext,
  5072.     IN OUT DWORD *pdwFlags
  5073.     );
  5074.  
  5075. //+-------------------------------------------------------------------------
  5076. //  Perform the enabled verification checks on the subject certificate
  5077. //  using the issuer. Same checks and flags definitions as for the above
  5078. //  CertGetIssuerCertificateFromStore.
  5079. //
  5080. //  If you are only checking CERT_STORE_TIME_VALIDITY_FLAG, then, the
  5081. //  issuer can be NULL.
  5082. //
  5083. //  For a verification check failure, SUCCESS is still returned.
  5084. //--------------------------------------------------------------------------
  5085. WINCRYPT32API
  5086. BOOL
  5087. WINAPI
  5088. CertVerifySubjectCertificateContext(
  5089.     IN PCCERT_CONTEXT pSubject,
  5090.     IN OPTIONAL PCCERT_CONTEXT pIssuer,
  5091.     IN OUT DWORD *pdwFlags
  5092.     );
  5093.  
  5094. //+-------------------------------------------------------------------------
  5095. //  Duplicate a certificate context
  5096. //--------------------------------------------------------------------------
  5097. WINCRYPT32API
  5098. PCCERT_CONTEXT
  5099. WINAPI
  5100. CertDuplicateCertificateContext(
  5101.     IN PCCERT_CONTEXT pCertContext
  5102.     );
  5103.  
  5104. //+-------------------------------------------------------------------------
  5105. //  Create a certificate context from the encoded certificate. The created
  5106. //  context isn't put in a store.
  5107. //
  5108. //  Makes a copy of the encoded certificate in the created context.
  5109. //
  5110. //  If unable to decode and create the certificate context, NULL is returned.
  5111. //  Otherwise, a pointer to a read only CERT_CONTEXT is returned.
  5112. //  CERT_CONTEXT must be freed by calling CertFreeCertificateContext.
  5113. //  CertDuplicateCertificateContext can be called to make a duplicate.
  5114. //
  5115. //  CertSetCertificateContextProperty and CertGetCertificateContextProperty can be called
  5116. //  to store properties for the certificate.
  5117. //--------------------------------------------------------------------------
  5118. WINCRYPT32API
  5119. PCCERT_CONTEXT
  5120. WINAPI
  5121. CertCreateCertificateContext(
  5122.     IN DWORD dwCertEncodingType,
  5123.     IN const BYTE *pbCertEncoded,
  5124.     IN DWORD cbCertEncoded
  5125.     );
  5126.  
  5127. //+-------------------------------------------------------------------------
  5128. //  Free a certificate context
  5129. //
  5130. //  There needs to be a corresponding free for each context obtained by a
  5131. //  get, find, duplicate or create.
  5132. //--------------------------------------------------------------------------
  5133. WINCRYPT32API
  5134. BOOL
  5135. WINAPI
  5136. CertFreeCertificateContext(
  5137.     IN PCCERT_CONTEXT pCertContext
  5138.     );
  5139.  
  5140. //+-------------------------------------------------------------------------
  5141. //  Set the property for the specified certificate context.
  5142. //
  5143. //  The type definition for pvData depends on the dwPropId value. There are
  5144. //  five predefined types:
  5145. //      CERT_KEY_PROV_HANDLE_PROP_ID - a HCRYPTPROV for the certificate's
  5146. //      private key is passed in pvData. Updates the hCryptProv field
  5147. //      of the CERT_KEY_CONTEXT_PROP_ID. If the CERT_KEY_CONTEXT_PROP_ID
  5148. //      doesn't exist, its created with all the other fields zeroed out. If
  5149. //      CERT_STORE_NO_CRYPT_RELEASE_FLAG isn't set, HCRYPTPROV is implicitly
  5150. //      released when either the property is set to NULL or on the final
  5151. //      free of the CertContext.
  5152. //
  5153. //      CERT_KEY_PROV_INFO_PROP_ID - a PCRYPT_KEY_PROV_INFO for the certificate's
  5154. //      private key is passed in pvData.
  5155. //
  5156. //      CERT_SHA1_HASH_PROP_ID -
  5157. //      CERT_MD5_HASH_PROP_ID  - normally, either property is implicitly
  5158. //      set by doing a CertGetCertificateContextProperty. pvData points to a
  5159. //      CRYPT_HASH_BLOB.
  5160. //
  5161. //      CERT_KEY_CONTEXT_PROP_ID - a PCERT_KEY_CONTEXT for the certificate's
  5162. //      private key is passed in pvData. The CERT_KEY_CONTEXT contains both the
  5163. //      hCryptProv and dwKeySpec for the private key.
  5164. //      See the CERT_KEY_PROV_HANDLE_PROP_ID for more information about
  5165. //      the hCryptProv field and dwFlags settings. Note, more fields may
  5166. //      be added for this property. The cbSize field value will be adjusted
  5167. //      accordingly.
  5168. //
  5169. //      CERT_KEY_SPEC_PROP_ID - the dwKeySpec for the private key. pvData
  5170. //      points to a DWORD containing the KeySpec
  5171. //
  5172. //      CERT_ENHKEY_USAGE_PROP_ID - enhanced key usage definition for the
  5173. //      certificate. pvData points to a CRYPT_DATA_BLOB containing an
  5174. //      ASN.1 encoded CERT_ENHKEY_USAGE (encoded via
  5175. //      CryptEncodeObject(X509_ENHANCED_KEY_USAGE).
  5176. //
  5177. //      CERT_NEXT_UPDATE_LOCATION_PROP_ID - location of the next update.
  5178. //      Currently only applicable to CTLs. pvData points to a CRYPT_DATA_BLOB
  5179. //      containing an ASN.1 encoded CERT_ALT_NAME_INFO (encoded via
  5180. //      CryptEncodeObject(X509_ALTERNATE_NAME)).
  5181. //
  5182. //      CERT_FRIENDLY_NAME_PROP_ID - friendly name for the cert, CRL or CTL.
  5183. //      pvData points to a CRYPT_DATA_BLOB. pbData is a pointer to a NULL
  5184. //      terminated unicode, wide character string.
  5185. //      cbData = (wcslen((LPWSTR) pbData) + 1) * sizeof(WCHAR).
  5186. //
  5187. //  For all the other PROP_IDs: an encoded PCRYPT_DATA_BLOB is passed in pvData.
  5188. //
  5189. //  If the property already exists, then, the old value is deleted and silently
  5190. //  replaced. Setting, pvData to NULL, deletes the property.
  5191. //--------------------------------------------------------------------------
  5192. WINCRYPT32API
  5193. BOOL
  5194. WINAPI
  5195. CertSetCertificateContextProperty(
  5196.     IN PCCERT_CONTEXT pCertContext,
  5197.     IN DWORD dwPropId,
  5198.     IN DWORD dwFlags,
  5199.     IN const void *pvData
  5200.     );
  5201.  
  5202. //+-------------------------------------------------------------------------
  5203. //  Get the property for the specified certificate context.
  5204. //
  5205. //  For CERT_KEY_PROV_HANDLE_PROP_ID, pvData points to a HCRYPTPROV.
  5206. //
  5207. //  For CERT_KEY_PROV_INFO_PROP_ID, pvData points to a CRYPT_KEY_PROV_INFO structure.
  5208. //  Elements pointed to by fields in the pvData structure follow the
  5209. //  structure. Therefore, *pcbData may exceed the size of the structure.
  5210. //
  5211. //  For CERT_KEY_CONTEXT_PROP_ID, pvData points to a CERT_KEY_CONTEXT structure.
  5212. //
  5213. //  For CERT_KEY_SPEC_PROP_ID, pvData points to a DWORD containing the KeySpec.
  5214. //  If the CERT_KEY_CONTEXT_PROP_ID exists, the KeySpec is obtained from there.
  5215. //  Otherwise, if the CERT_KEY_PROV_INFO_PROP_ID exists, its the source
  5216. //  of the KeySpec.
  5217. //
  5218. //  For CERT_SHA1_HASH_PROP_ID or CERT_MD5_HASH_PROP_ID, if the hash
  5219. //  doesn't already exist, then, its computed via CryptHashCertificate()
  5220. //  and then set. pvData points to the computed hash. Normally, the length
  5221. //  is 20 bytes for SHA and 16 for MD5.
  5222. //
  5223. //  For all other PROP_IDs, pvData points to an encoded array of bytes.
  5224. //--------------------------------------------------------------------------
  5225. WINCRYPT32API
  5226. BOOL
  5227. WINAPI
  5228. CertGetCertificateContextProperty(
  5229.     IN PCCERT_CONTEXT pCertContext,
  5230.     IN DWORD dwPropId,
  5231.     OUT void *pvData,
  5232.     IN OUT DWORD *pcbData
  5233.     );
  5234.  
  5235. //+-------------------------------------------------------------------------
  5236. //  Enumerate the properties for the specified certificate context.
  5237. //
  5238. //  To get the first property, set dwPropId to 0. The ID of the first
  5239. //  property is returned. To get the next property, set dwPropId to the
  5240. //  ID returned by the last call. To enumerate all the properties continue
  5241. //  until 0 is returned.
  5242. //
  5243. //  CertGetCertificateContextProperty is called to get the property's data.
  5244. //
  5245. //  Note, since, the CERT_KEY_PROV_HANDLE_PROP_ID and CERT_KEY_SPEC_PROP_ID
  5246. //  properties are stored as fields in the CERT_KEY_CONTEXT_PROP_ID
  5247. //  property, they aren't enumerated individually.
  5248. //--------------------------------------------------------------------------
  5249. WINCRYPT32API
  5250. DWORD
  5251. WINAPI
  5252. CertEnumCertificateContextProperties(
  5253.     IN PCCERT_CONTEXT pCertContext,
  5254.     IN DWORD dwPropId
  5255.     );
  5256.  
  5257. //+-------------------------------------------------------------------------
  5258. //  Get the first or next CRL context from the store for the specified
  5259. //  issuer certificate. Perform the enabled verification checks on the CRL.
  5260. //
  5261. //  If the first or next CRL isn't found, NULL is returned.
  5262. //  Otherwise, a pointer to a read only CRL_CONTEXT is returned. CRL_CONTEXT
  5263. //  must be freed by calling CertFreeCRLContext. However, the free must be
  5264. //  pPrevCrlContext on a subsequent call. CertDuplicateCRLContext
  5265. //  can be called to make a duplicate.
  5266. //
  5267. //  The pIssuerContext may have been obtained from this store, another store
  5268. //  or created by the caller application. When created by the caller, the
  5269. //  CertCreateCertificateContext function must have been called.
  5270. //
  5271. //  If pIssuerContext == NULL, finds all the CRLs in the store.
  5272. //
  5273. //  An issuer may have multiple CRLs. For example, it generates delta CRLs
  5274. //  using a X.509 v3 extension. pPrevCrlContext MUST BE NULL on the first
  5275. //  call to get the CRL. To get the next CRL for the issuer, the
  5276. //  pPrevCrlContext is set to the CRL_CONTEXT returned by a previous call.
  5277. //
  5278. //  NOTE: a NON-NULL pPrevCrlContext is always CertFreeCRLContext'ed by
  5279. //  this function, even for an error.
  5280. //
  5281. //  The following flags can be set in *pdwFlags to enable verification checks
  5282. //  on the returned CRL:
  5283. //      CERT_STORE_SIGNATURE_FLAG     - use the public key in the
  5284. //                                      issuer's certificate to verify the
  5285. //                                      signature on the returned CRL.
  5286. //                                      Note, if pIssuerContext->hCertStore ==
  5287. //                                      hCertStore, the store provider might
  5288. //                                      be able to eliminate a redo of
  5289. //                                      the signature verify.
  5290. //      CERT_STORE_TIME_VALIDITY_FLAG - get the current time and verify that
  5291. //                                      its within the CRL's ThisUpdate and
  5292. //                                      NextUpdate validity period.
  5293. //
  5294. //  If an enabled verification check fails, then, its flag is set upon return.
  5295. //
  5296. //  If pIssuerContext == NULL, then, an enabled CERT_STORE_SIGNATURE_FLAG
  5297. //  always fails and the CERT_STORE_NO_ISSUER_FLAG is also set.
  5298. //
  5299. //  For a verification check failure, a pointer to the first or next
  5300. //  CRL_CONTEXT is still returned and SetLastError isn't updated.
  5301. //--------------------------------------------------------------------------
  5302. WINCRYPT32API
  5303. PCCRL_CONTEXT
  5304. WINAPI
  5305. CertGetCRLFromStore(
  5306.     IN HCERTSTORE hCertStore,
  5307.     IN OPTIONAL PCCERT_CONTEXT pIssuerContext,
  5308.     IN PCCRL_CONTEXT pPrevCrlContext,
  5309.     IN OUT DWORD *pdwFlags
  5310.     );
  5311.  
  5312.  
  5313. //+-------------------------------------------------------------------------
  5314. //  Duplicate a CRL context
  5315. //--------------------------------------------------------------------------
  5316. WINCRYPT32API
  5317. PCCRL_CONTEXT
  5318. WINAPI
  5319. CertDuplicateCRLContext(
  5320.     IN PCCRL_CONTEXT pCrlContext
  5321.     );
  5322.  
  5323. //+-------------------------------------------------------------------------
  5324. //  Create a CRL context from the encoded CRL. The created
  5325. //  context isn't put in a store.
  5326. //
  5327. //  Makes a copy of the encoded CRL in the created context.
  5328. //
  5329. //  If unable to decode and create the CRL context, NULL is returned.
  5330. //  Otherwise, a pointer to a read only CRL_CONTEXT is returned.
  5331. //  CRL_CONTEXT must be freed by calling CertFreeCRLContext.
  5332. //  CertDuplicateCRLContext can be called to make a duplicate.
  5333. //
  5334. //  CertSetCRLContextProperty and CertGetCRLContextProperty can be called
  5335. //  to store properties for the CRL.
  5336. //--------------------------------------------------------------------------
  5337. WINCRYPT32API
  5338. PCCRL_CONTEXT
  5339. WINAPI
  5340. CertCreateCRLContext(
  5341.     IN DWORD dwCertEncodingType,
  5342.     IN const BYTE *pbCrlEncoded,
  5343.     IN DWORD cbCrlEncoded
  5344.     );
  5345.  
  5346. //+-------------------------------------------------------------------------
  5347. //  Free a CRL context
  5348. //
  5349. //  There needs to be a corresponding free for each context obtained by a
  5350. //  get, duplicate or create.
  5351. //--------------------------------------------------------------------------
  5352. WINCRYPT32API
  5353. BOOL
  5354. WINAPI
  5355. CertFreeCRLContext(
  5356.     IN PCCRL_CONTEXT pCrlContext
  5357.     );
  5358.  
  5359. //+-------------------------------------------------------------------------
  5360. //  Set the property for the specified CRL context.
  5361. //
  5362. //  Same Property Ids and semantics as CertSetCertificateContextProperty.
  5363. //--------------------------------------------------------------------------
  5364. WINCRYPT32API
  5365. BOOL
  5366. WINAPI
  5367. CertSetCRLContextProperty(
  5368.     IN PCCRL_CONTEXT pCrlContext,
  5369.     IN DWORD dwPropId,
  5370.     IN DWORD dwFlags,
  5371.     IN const void *pvData
  5372.     );
  5373.  
  5374. //+-------------------------------------------------------------------------
  5375. //  Get the property for the specified CRL context.
  5376. //
  5377. //  Same Property Ids and semantics as CertGetCertificateContextProperty.
  5378. //
  5379. //  CERT_SHA1_HASH_PROP_ID or CERT_MD5_HASH_PROP_ID is the predefined
  5380. //  property of most interest.
  5381. //--------------------------------------------------------------------------
  5382. WINCRYPT32API
  5383. BOOL
  5384. WINAPI
  5385. CertGetCRLContextProperty(
  5386.     IN PCCRL_CONTEXT pCrlContext,
  5387.     IN DWORD dwPropId,
  5388.     OUT void *pvData,
  5389.     IN OUT DWORD *pcbData
  5390.     );
  5391.  
  5392. //+-------------------------------------------------------------------------
  5393. //  Enumerate the properties for the specified CRL context.
  5394. //
  5395. //  To get the first property, set dwPropId to 0. The ID of the first
  5396. //  property is returned. To get the next property, set dwPropId to the
  5397. //  ID returned by the last call. To enumerate all the properties continue
  5398. //  until 0 is returned.
  5399. //
  5400. //  CertGetCRLContextProperty is called to get the property's data.
  5401. //--------------------------------------------------------------------------
  5402. WINCRYPT32API
  5403. DWORD
  5404. WINAPI
  5405. CertEnumCRLContextProperties(
  5406.     IN PCCRL_CONTEXT pCrlContext,
  5407.     IN DWORD dwPropId
  5408.     );
  5409.  
  5410. //+-------------------------------------------------------------------------
  5411. // Add certificate/CRL, encoded, context or element disposition values.
  5412. //--------------------------------------------------------------------------
  5413. #define CERT_STORE_ADD_NEW                  1
  5414. #define CERT_STORE_ADD_USE_EXISTING         2
  5415. #define CERT_STORE_ADD_REPLACE_EXISTING     3
  5416. #define CERT_STORE_ADD_ALWAYS               4
  5417.  
  5418. //+-------------------------------------------------------------------------
  5419. //  Add the encoded certificate to the store according to the specified
  5420. //  disposition action.
  5421. //
  5422. //  Makes a copy of the encoded certificate before adding to the store.
  5423. //
  5424. //  dwAddDispostion specifies the action to take if the certificate
  5425. //  already exists in the store. This parameter must be one of the following
  5426. //  values:
  5427. //    CERT_STORE_ADD_NEW
  5428. //      Fails if the certificate already exists in the store. LastError
  5429. //      is set to CRYPT_E_EXISTS.
  5430. //    CERT_STORE_ADD_USE_EXISTING
  5431. //      If the certifcate already exists, then, its used and if ppCertContext
  5432. //      is non-NULL, the existing context is duplicated.
  5433. //    CERT_STORE_ADD_REPLACE_EXISTING
  5434. //      If the certificate already exists, then, the existing certificate
  5435. //      context is deleted before creating and adding the new context.
  5436. //    CERT_STORE_ADD_ALWAYS
  5437. //      No check is made to see if the certificate already exists. A
  5438. //      new certificate context is always created. This may lead to
  5439. //      duplicates in the store.
  5440. //
  5441. //  CertGetSubjectCertificateFromStore is called to determine if the
  5442. //  certificate already exists in the store.
  5443. //
  5444. //  ppCertContext can be NULL, indicating the caller isn't interested
  5445. //  in getting the CERT_CONTEXT of the added or existing certificate.
  5446. //--------------------------------------------------------------------------
  5447. WINCRYPT32API
  5448. BOOL
  5449. WINAPI
  5450. CertAddEncodedCertificateToStore(
  5451.     IN HCERTSTORE hCertStore,
  5452.     IN DWORD dwCertEncodingType,
  5453.     IN const BYTE *pbCertEncoded,
  5454.     IN DWORD cbCertEncoded,
  5455.     IN DWORD dwAddDisposition,
  5456.     OUT OPTIONAL PCCERT_CONTEXT *ppCertContext
  5457.     );
  5458.  
  5459. //+-------------------------------------------------------------------------
  5460. //  Add the certificate context to the store according to the specified
  5461. //  disposition action.
  5462. //
  5463. //  In addition to the encoded certificate, the context's properties are
  5464. //  also copied.  Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  5465. //  CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't copied.
  5466. //
  5467. //  Makes a copy of the certificate context before adding to the store.
  5468. //
  5469. //  dwAddDispostion specifies the action to take if the certificate
  5470. //  already exists in the store. This parameter must be one of the following
  5471. //  values:
  5472. //    CERT_STORE_ADD_NEW
  5473. //      Fails if the certificate already exists in the store. LastError
  5474. //      is set to CRYPT_E_EXISTS.
  5475. //    CERT_STORE_ADD_USE_EXISTING
  5476. //      If the certifcate already exists, then, its used and if ppStoreContext
  5477. //      is non-NULL, the existing context is duplicated. Iterates
  5478. //      through pCertContext's properties and only copies the properties
  5479. //      that don't already exist. The SHA1 and MD5 hash properties aren't
  5480. //      copied.
  5481. //    CERT_STORE_ADD_REPLACE_EXISTING
  5482. //      If the certificate already exists, then, the existing certificate
  5483. //      context is deleted before creating and adding a new context.
  5484. //      Properties are copied before doing the add.
  5485. //    CERT_STORE_ADD_ALWAYS
  5486. //      No check is made to see if the certificate already exists. A
  5487. //      new certificate context is always created and added. This may lead to
  5488. //      duplicates in the store. Properties are
  5489. //      copied before doing the add.
  5490. //
  5491. //  CertGetSubjectCertificateFromStore is called to determine if the
  5492. //  certificate already exists in the store.
  5493. //
  5494. //  ppStoreContext can be NULL, indicating the caller isn't interested
  5495. //  in getting the CERT_CONTEXT of the added or existing certificate.
  5496. //--------------------------------------------------------------------------
  5497. WINCRYPT32API
  5498. BOOL
  5499. WINAPI
  5500. CertAddCertificateContextToStore(
  5501.     IN HCERTSTORE hCertStore,
  5502.     IN PCCERT_CONTEXT pCertContext,
  5503.     IN DWORD dwAddDisposition,
  5504.     OUT OPTIONAL PCCERT_CONTEXT *ppStoreContext
  5505.     );
  5506.  
  5507.  
  5508. //+-------------------------------------------------------------------------
  5509. //  Certificate Store Context Types
  5510. //--------------------------------------------------------------------------
  5511. #define CERT_STORE_CERTIFICATE_CONTEXT  1
  5512. #define CERT_STORE_CRL_CONTEXT          2
  5513. #define CERT_STORE_CTL_CONTEXT          3
  5514.  
  5515. //+-------------------------------------------------------------------------
  5516. //  Certificate Store Context Bit Flags
  5517. //--------------------------------------------------------------------------
  5518. #define CERT_STORE_ALL_CONTEXT_FLAG             (~0UL)
  5519. #define CERT_STORE_CERTIFICATE_CONTEXT_FLAG     \
  5520.                 (1 << CERT_STORE_CERTIFICATE_CONTEXT)
  5521. #define CERT_STORE_CRL_CONTEXT_FLAG             \
  5522.                 (1 << CERT_STORE_CRL_CONTEXT)
  5523. #define CERT_STORE_CTL_CONTEXT_FLAG             \
  5524.                 (1 << CERT_STORE_CTL_CONTEXT)
  5525.  
  5526. //+-------------------------------------------------------------------------
  5527. //  Add the serialized certificate or CRL element to the store.
  5528. //
  5529. //  The serialized element contains the encoded certificate, CRL or CTL and
  5530. //  its properties, such as, CERT_KEY_PROV_INFO_PROP_ID.
  5531. //
  5532. //  If hCertStore is NULL, creates a certificate, CRL or CTL context not
  5533. //  residing in any store.
  5534. //
  5535. //  dwAddDispostion specifies the action to take if the certificate or CRL
  5536. //  already exists in the store. See CertAddCertificateContextToStore for a
  5537. //  list of and actions taken.
  5538. //
  5539. //  dwFlags currently isn't used and should be set to 0.
  5540. //
  5541. //  dwContextTypeFlags specifies the set of allowable contexts. For example, to
  5542. //  add either a certificate or CRL, set dwContextTypeFlags to:
  5543. //      CERT_STORE_CERTIFICATE_CONTEXT_FLAG | CERT_STORE_CRL_CONTEXT_FLAG
  5544. //
  5545. //  *pdwContextType is updated with the type of the context returned in
  5546. //  *ppvContxt. pdwContextType or ppvContext can be NULL, indicating the
  5547. //  caller isn't interested in getting the output. If *ppvContext is
  5548. //  returned it must be freed by calling CertFreeCertificateContext or
  5549. //  CertFreeCRLContext.
  5550. //--------------------------------------------------------------------------
  5551. WINCRYPT32API
  5552. BOOL
  5553. WINAPI
  5554. CertAddSerializedElementToStore(
  5555.     IN HCERTSTORE hCertStore,
  5556.     IN const BYTE *pbElement,
  5557.     IN DWORD cbElement,
  5558.     IN DWORD dwAddDisposition,
  5559.     IN DWORD dwFlags,
  5560.     IN DWORD dwContextTypeFlags,
  5561.     OUT OPTIONAL DWORD *pdwContextType,
  5562.     OUT OPTIONAL const void **ppvContext
  5563.     );
  5564.  
  5565. //+-------------------------------------------------------------------------
  5566. //  Delete the specified certificate from the store.
  5567. //
  5568. //  All subsequent gets or finds for the certificate will fail. However,
  5569. //  memory allocated for the certificate isn't freed until all of its contexts
  5570. //  have also been freed.
  5571. //
  5572. //  The pCertContext is obtained from a get, enum, find or duplicate.
  5573. //
  5574. //  Some store provider implementations might also delete the issuer's CRLs
  5575. //  if this is the last certificate for the issuer in the store.
  5576. //
  5577. //  NOTE: the pCertContext is always CertFreeCertificateContext'ed by
  5578. //  this function, even for an error.
  5579. //--------------------------------------------------------------------------
  5580. WINCRYPT32API
  5581. BOOL
  5582. WINAPI
  5583. CertDeleteCertificateFromStore(
  5584.     IN PCCERT_CONTEXT pCertContext
  5585.     );
  5586.  
  5587. //+-------------------------------------------------------------------------
  5588. //  Add the encoded CRL to the store according to the specified
  5589. //  disposition option.
  5590. //
  5591. //  Makes a copy of the encoded CRL before adding to the store.
  5592. //
  5593. //  dwAddDispostion specifies the action to take if the CRL
  5594. //  already exists in the store. See CertAddEncodedCertificateToStore for a
  5595. //  list of and actions taken.
  5596. //
  5597. //  Compares the CRL's Issuer to determine if the CRL already exists in the
  5598. //  store.
  5599. //
  5600. //  ppCrlContext can be NULL, indicating the caller isn't interested
  5601. //  in getting the CRL_CONTEXT of the added or existing CRL.
  5602. //--------------------------------------------------------------------------
  5603. WINCRYPT32API
  5604. BOOL
  5605. WINAPI
  5606. CertAddEncodedCRLToStore(
  5607.     IN HCERTSTORE hCertStore,
  5608.     IN DWORD dwCertEncodingType,
  5609.     IN const BYTE *pbCrlEncoded,
  5610.     IN DWORD cbCrlEncoded,
  5611.     IN DWORD dwAddDisposition,
  5612.     OUT OPTIONAL PCCRL_CONTEXT *ppCrlContext
  5613.     );
  5614.  
  5615. //+-------------------------------------------------------------------------
  5616. //  Add the CRL context to the store according to the specified
  5617. //  disposition option.
  5618. //
  5619. //  In addition to the encoded CRL, the context's properties are
  5620. //  also copied.  Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  5621. //  CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't copied.
  5622. //
  5623. //  Makes a copy of the encoded CRL before adding to the store.
  5624. //
  5625. //  dwAddDispostion specifies the action to take if the CRL
  5626. //  already exists in the store. See CertAddCertificateContextToStore for a
  5627. //  list of and actions taken.
  5628. //
  5629. //  Compares the CRL's Issuer, ThisUpdate and NextUpdate to determine
  5630. //  if the CRL already exists in the store.
  5631. //
  5632. //  ppStoreContext can be NULL, indicating the caller isn't interested
  5633. //  in getting the CRL_CONTEXT of the added or existing CRL.
  5634. //--------------------------------------------------------------------------
  5635. WINCRYPT32API
  5636. BOOL
  5637. WINAPI
  5638. CertAddCRLContextToStore(
  5639.     IN HCERTSTORE hCertStore,
  5640.     IN PCCRL_CONTEXT pCrlContext,
  5641.     IN DWORD dwAddDisposition,
  5642.     OUT OPTIONAL PCCRL_CONTEXT *ppStoreContext
  5643.     );
  5644.  
  5645. //+-------------------------------------------------------------------------
  5646. //  Delete the specified CRL from the store.
  5647. //
  5648. //  All subsequent gets for the CRL will fail. However,
  5649. //  memory allocated for the CRL isn't freed until all of its contexts
  5650. //  have also been freed.
  5651. //
  5652. //  The pCrlContext is obtained from a get or duplicate.
  5653. //
  5654. //  NOTE: the pCrlContext is always CertFreeCRLContext'ed by
  5655. //  this function, even for an error.
  5656. //--------------------------------------------------------------------------
  5657. WINCRYPT32API
  5658. BOOL
  5659. WINAPI
  5660. CertDeleteCRLFromStore(
  5661.     IN PCCRL_CONTEXT pCrlContext
  5662.     );
  5663.  
  5664. //+-------------------------------------------------------------------------
  5665. //  Serialize the certificate context's encoded certificate and its
  5666. //  properties.
  5667. //--------------------------------------------------------------------------
  5668. WINCRYPT32API
  5669. BOOL
  5670. WINAPI
  5671. CertSerializeCertificateStoreElement(
  5672.     IN PCCERT_CONTEXT pCertContext,
  5673.     IN DWORD dwFlags,
  5674.     OUT BYTE *pbElement,
  5675.     IN OUT DWORD *pcbElement
  5676.     );
  5677.  
  5678.  
  5679. //+-------------------------------------------------------------------------
  5680. //  Serialize the CRL context's encoded CRL and its properties.
  5681. //--------------------------------------------------------------------------
  5682. WINCRYPT32API
  5683. BOOL
  5684. WINAPI
  5685. CertSerializeCRLStoreElement(
  5686.     IN PCCRL_CONTEXT pCrlContext,
  5687.     IN DWORD dwFlags,
  5688.     OUT BYTE *pbElement,
  5689.     IN OUT DWORD *pcbElement
  5690.     );
  5691.  
  5692.  
  5693. //+=========================================================================
  5694. //  Certificate Trust List (CTL) Store Data Structures and APIs
  5695. //==========================================================================
  5696.  
  5697. //+-------------------------------------------------------------------------
  5698. //  Duplicate a CTL context
  5699. //--------------------------------------------------------------------------
  5700. WINCRYPT32API
  5701. PCCTL_CONTEXT
  5702. WINAPI
  5703. CertDuplicateCTLContext(
  5704.     IN PCCTL_CONTEXT pCtlContext
  5705.     );
  5706.  
  5707. //+-------------------------------------------------------------------------
  5708. //  Create a CTL context from the encoded CTL. The created
  5709. //  context isn't put in a store.
  5710. //
  5711. //  Makes a copy of the encoded CTL in the created context.
  5712. //
  5713. //  If unable to decode and create the CTL context, NULL is returned.
  5714. //  Otherwise, a pointer to a read only CTL_CONTEXT is returned.
  5715. //  CTL_CONTEXT must be freed by calling CertFreeCTLContext.
  5716. //  CertDuplicateCTLContext can be called to make a duplicate.
  5717. //
  5718. //  CertSetCTLContextProperty and CertGetCTLContextProperty can be called
  5719. //  to store properties for the CTL.
  5720. //--------------------------------------------------------------------------
  5721. WINCRYPT32API
  5722. PCCTL_CONTEXT
  5723. WINAPI
  5724. CertCreateCTLContext(
  5725.     IN DWORD dwMsgAndCertEncodingType,
  5726.     IN const BYTE *pbCtlEncoded,
  5727.     IN DWORD cbCtlEncoded
  5728.     );
  5729.  
  5730. //+-------------------------------------------------------------------------
  5731. //  Free a CTL context
  5732. //
  5733. //  There needs to be a corresponding free for each context obtained by a
  5734. //  get, duplicate or create.
  5735. //--------------------------------------------------------------------------
  5736. WINCRYPT32API
  5737. BOOL
  5738. WINAPI
  5739. CertFreeCTLContext(
  5740.     IN PCCTL_CONTEXT pCtlContext
  5741.     );
  5742.  
  5743. //+-------------------------------------------------------------------------
  5744. //  Set the property for the specified CTL context.
  5745. //
  5746. //  Same Property Ids and semantics as CertSetCertificateContextProperty.
  5747. //--------------------------------------------------------------------------
  5748. WINCRYPT32API
  5749. BOOL
  5750. WINAPI
  5751. CertSetCTLContextProperty(
  5752.     IN PCCTL_CONTEXT pCtlContext,
  5753.     IN DWORD dwPropId,
  5754.     IN DWORD dwFlags,
  5755.     IN const void *pvData
  5756.     );
  5757.  
  5758. //+-------------------------------------------------------------------------
  5759. //  Get the property for the specified CTL context.
  5760. //
  5761. //  Same Property Ids and semantics as CertGetCertificateContextProperty.
  5762. //
  5763. //  CERT_SHA1_HASH_PROP_ID or CERT_NEXT_UPDATE_LOCATION_PROP_ID are the
  5764. //  predefined properties of most interest.
  5765. //--------------------------------------------------------------------------
  5766. WINCRYPT32API
  5767. BOOL
  5768. WINAPI
  5769. CertGetCTLContextProperty(
  5770.     IN PCCTL_CONTEXT pCtlContext,
  5771.     IN DWORD dwPropId,
  5772.     OUT void *pvData,
  5773.     IN OUT DWORD *pcbData
  5774.     );
  5775.  
  5776. //+-------------------------------------------------------------------------
  5777. //  Enumerate the properties for the specified CTL context.
  5778. //--------------------------------------------------------------------------
  5779. WINCRYPT32API
  5780. DWORD
  5781. WINAPI
  5782. CertEnumCTLContextProperties(
  5783.     IN PCCTL_CONTEXT pCtlContext,
  5784.     IN DWORD dwPropId
  5785.     );
  5786.  
  5787. //+-------------------------------------------------------------------------
  5788. //  Enumerate the CTL contexts in the store.
  5789. //
  5790. //  If a CTL isn't found, NULL is returned.
  5791. //  Otherwise, a pointer to a read only CTL_CONTEXT is returned. CTL_CONTEXT
  5792. //  must be freed by calling CertFreeCTLContext or is freed when passed as the
  5793. //  pPrevCtlContext on a subsequent call. CertDuplicateCTLContext
  5794. //  can be called to make a duplicate.
  5795. //
  5796. //  pPrevCtlContext MUST BE NULL to enumerate the first
  5797. //  CTL in the store. Successive CTLs are enumerated by setting
  5798. //  pPrevCtlContext to the CTL_CONTEXT returned by a previous call.
  5799. //
  5800. //  NOTE: a NON-NULL pPrevCtlContext is always CertFreeCTLContext'ed by
  5801. //  this function, even for an error.
  5802. //--------------------------------------------------------------------------
  5803. WINCRYPT32API
  5804. PCCTL_CONTEXT
  5805. WINAPI
  5806. CertEnumCTLsInStore(
  5807.     IN HCERTSTORE hCertStore,
  5808.     IN PCCTL_CONTEXT pPrevCtlContext
  5809.     );
  5810.  
  5811. //+-------------------------------------------------------------------------
  5812. //  Attempt to find the specified subject in the CTL.
  5813. //
  5814. //  For CTL_CERT_SUBJECT_TYPE, pvSubject points to a CERT_CONTEXT. The CTL's
  5815. //  SubjectAlgorithm is examined to determine the representation of the
  5816. //  subject's identity. Initially, only SHA1 or MD5 hash will be supported.
  5817. //  The appropriate hash property is obtained from the CERT_CONTEXT.
  5818. //
  5819. //  For CTL_ANY_SUBJECT_TYPE, pvSubject points to the CTL_ANY_SUBJECT_INFO
  5820. //  structure which contains the SubjectAlgorithm to be matched in the CTL
  5821. //  and the SubjectIdentifer to be matched in one of the CTL entries.
  5822. //
  5823. //  The certificate's hash or the CTL_ANY_SUBJECT_INFO's SubjectIdentifier
  5824. //  is used as the key in searching the subject entries. A binary
  5825. //  memory comparison is done between the key and the entry's SubjectIdentifer.
  5826. //
  5827. //  dwEncodingType isn't used for either of the above SubjectTypes.
  5828. //--------------------------------------------------------------------------
  5829. WINCRYPT32API
  5830. PCTL_ENTRY
  5831. WINAPI
  5832. CertFindSubjectInCTL(
  5833.     IN DWORD dwEncodingType,
  5834.     IN DWORD dwSubjectType,
  5835.     IN void *pvSubject,
  5836.     IN PCCTL_CONTEXT pCtlContext,
  5837.     IN DWORD dwFlags
  5838.     );
  5839.  
  5840. // Subject Types:
  5841. //  CTL_ANY_SUBJECT_TYPE, pvSubject points to following CTL_ANY_SUBJECT_INFO.
  5842. //  CTL_CERT_SUBJECT_TYPE, pvSubject points to CERT_CONTEXT.
  5843. #define CTL_ANY_SUBJECT_TYPE            1
  5844. #define CTL_CERT_SUBJECT_TYPE           2
  5845.  
  5846. typedef struct _CTL_ANY_SUBJECT_INFO {
  5847.     CRYPT_ALGORITHM_IDENTIFIER  SubjectAlgorithm;
  5848.     CRYPT_DATA_BLOB             SubjectIdentifier;
  5849. } CTL_ANY_SUBJECT_INFO, *PCTL_ANY_SUBJECT_INFO;
  5850.  
  5851. //+-------------------------------------------------------------------------
  5852. //  Find the first or next CTL context in the store.
  5853. //
  5854. //  The CTL is found according to the dwFindType and its pvFindPara.
  5855. //  See below for a list of the find types and its parameters.
  5856. //
  5857. //  Currently dwFindFlags isn't used and must be set to 0.
  5858. //
  5859. //  Usage of dwMsgAndCertEncodingType depends on the dwFindType.
  5860. //
  5861. //  If the first or next CTL isn't found, NULL is returned.
  5862. //  Otherwise, a pointer to a read only CTL_CONTEXT is returned. CTL_CONTEXT
  5863. //  must be freed by calling CertFreeCTLContext or is freed when passed as the
  5864. //  pPrevCtlContext on a subsequent call. CertDuplicateCTLContext
  5865. //  can be called to make a duplicate.
  5866. //
  5867. //  pPrevCtlContext MUST BE NULL on the first
  5868. //  call to find the CTL. To find the next CTL, the
  5869. //  pPrevCtlContext is set to the CTL_CONTEXT returned by a previous call.
  5870. //
  5871. //  NOTE: a NON-NULL pPrevCtlContext is always CertFreeCTLContext'ed by
  5872. //  this function, even for an error.
  5873. //--------------------------------------------------------------------------
  5874. WINCRYPT32API
  5875. PCCTL_CONTEXT
  5876. WINAPI
  5877. CertFindCTLInStore(
  5878.     IN HCERTSTORE hCertStore,
  5879.     IN DWORD dwMsgAndCertEncodingType,
  5880.     IN DWORD dwFindFlags,
  5881.     IN DWORD dwFindType,
  5882.     IN const void *pvFindPara,
  5883.     IN PCCTL_CONTEXT pPrevCtlContext
  5884.     );
  5885.  
  5886. #define CTL_FIND_ANY                0
  5887. #define CTL_FIND_SHA1_HASH          1
  5888. #define CTL_FIND_MD5_HASH           2
  5889. #define CTL_FIND_USAGE              3
  5890. #define CTL_FIND_SUBJECT            4
  5891.  
  5892. typedef struct _CTL_FIND_USAGE_PARA {
  5893.     DWORD               cbSize;
  5894.     CTL_USAGE           SubjectUsage;   // optional
  5895.     CRYPT_DATA_BLOB     ListIdentifier; // optional
  5896.     PCERT_INFO          pSigner;        // optional
  5897. } CTL_FIND_USAGE_PARA, *PCTL_FIND_USAGE_PARA;
  5898.  
  5899. #define CTL_FIND_NO_LIST_ID_CBDATA  0xFFFFFFFF
  5900. #define CTL_FIND_NO_SIGNER_PTR      ((PCERT_INFO) 0xFFFFFFFF)
  5901.  
  5902. #define CTL_FIND_SAME_USAGE_FLAG    0x1
  5903.  
  5904.  
  5905. typedef struct _CTL_FIND_SUBJECT_PARA {
  5906.     DWORD                   cbSize;
  5907.     PCTL_FIND_USAGE_PARA    pUsagePara; // optional
  5908.     DWORD                   dwSubjectType;
  5909.     void                    *pvSubject;
  5910. } CTL_FIND_SUBJECT_PARA, *PCTL_FIND_SUBJECT_PARA;
  5911.  
  5912.  
  5913. //+-------------------------------------------------------------------------
  5914. //  CTL_FIND_ANY
  5915. //
  5916. //  Find any CTL.
  5917. //
  5918. //  pvFindPara isn't used.
  5919. //--------------------------------------------------------------------------
  5920.  
  5921. //+-------------------------------------------------------------------------
  5922. //  CTL_FIND_SHA1_HASH
  5923. //  CTL_FIND_MD5_HASH
  5924. //
  5925. //  Find a CTL with the specified hash.
  5926. //
  5927. //  pvFindPara points to a CRYPT_HASH_BLOB.
  5928. //--------------------------------------------------------------------------
  5929.  
  5930. //+-------------------------------------------------------------------------
  5931. //  CTL_FIND_USAGE
  5932. //
  5933. //  Find a CTL having the specified usage identifiers, list identifier or
  5934. //  signer. The CertEncodingType of the signer is obtained from the
  5935. //  dwMsgAndCertEncodingType parameter.
  5936. //
  5937. //  pvFindPara points to a CTL_FIND_USAGE_PARA data structure. The
  5938. //  SubjectUsage.cUsageIdentifer can be 0 to match any usage. The
  5939. //  ListIdentifier.cbData can be 0 to match any list identifier. To only match
  5940. //  CTLs without a ListIdentifier, cbData must be set to
  5941. //  CTL_FIND_NO_LIST_ID_CBDATA. pSigner can be NULL to match any signer. Only
  5942. //  the Issuer and SerialNumber fields of the pSigner's PCERT_INFO are used.
  5943. //  To only match CTLs without a signer, pSigner must be set to
  5944. //  CTL_FIND_NO_SIGNER_PTR.
  5945. //
  5946. //  The CTL_FIND_SAME_USAGE_FLAG can be set in dwFindFlags to
  5947. //  only match CTLs with the same usage identifiers. CTLs having additional
  5948. //  usage identifiers aren't matched. For example, if only "1.2.3" is specified
  5949. //  in CTL_FIND_USAGE_PARA, then, for a match, the CTL must only contain
  5950. //  "1.2.3" and not any additional usage identifers.
  5951. //--------------------------------------------------------------------------
  5952.  
  5953. //+-------------------------------------------------------------------------
  5954. //  CTL_FIND_SUBJECT
  5955. //
  5956. //  Find a CTL having the specified subject. CertFindSubjectInCTL can be
  5957. //  called to get a pointer to the subject's entry in the CTL.  pUsagePara can
  5958. //  optionally be set to enable the above CTL_FIND_USAGE matching.
  5959. //
  5960. //  pvFindPara points to a CTL_FIND_SUBJECT_PARA data structure.
  5961. //--------------------------------------------------------------------------
  5962.  
  5963. //+-------------------------------------------------------------------------
  5964. //  Add the encoded CTL to the store according to the specified
  5965. //  disposition option.
  5966. //
  5967. //  Makes a copy of the encoded CTL before adding to the store.
  5968. //
  5969. //  dwAddDispostion specifies the action to take if the CTL
  5970. //  already exists in the store. See CertAddEncodedCertificateToStore for a
  5971. //  list of and actions taken.
  5972. //
  5973. //  Compares the CTL's SubjectUsage, ListIdentifier and any of its signers
  5974. //  to determine if the CTL already exists in the store.
  5975. //
  5976. //  ppCtlContext can be NULL, indicating the caller isn't interested
  5977. //  in getting the CTL_CONTEXT of the added or existing CTL.
  5978. //--------------------------------------------------------------------------
  5979. WINCRYPT32API
  5980. BOOL
  5981. WINAPI
  5982. CertAddEncodedCTLToStore(
  5983.     IN HCERTSTORE hCertStore,
  5984.     IN DWORD dwMsgAndCertEncodingType,
  5985.     IN const BYTE *pbCtlEncoded,
  5986.     IN DWORD cbCtlEncoded,
  5987.     IN DWORD dwAddDisposition,
  5988.     OUT OPTIONAL PCCTL_CONTEXT *ppCtlContext
  5989.     );
  5990.  
  5991. //+-------------------------------------------------------------------------
  5992. //  Add the CTL context to the store according to the specified
  5993. //  disposition option.
  5994. //
  5995. //  In addition to the encoded CTL, the context's properties are
  5996. //  also copied.  Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  5997. //  CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't copied.
  5998. //
  5999. //  Makes a copy of the encoded CTL before adding to the store.
  6000. //
  6001. //  dwAddDispostion specifies the action to take if the CTL
  6002. //  already exists in the store. See CertAddCertificateContextToStore for a
  6003. //  list of and actions taken.
  6004. //
  6005. //  Compares the CTL's SubjectUsage, ListIdentifier and any of its signers
  6006. //  to determine if the CTL already exists in the store.
  6007. //
  6008. //  ppStoreContext can be NULL, indicating the caller isn't interested
  6009. //  in getting the CTL_CONTEXT of the added or existing CTL.
  6010. //--------------------------------------------------------------------------
  6011. WINCRYPT32API
  6012. BOOL
  6013. WINAPI
  6014. CertAddCTLContextToStore(
  6015.     IN HCERTSTORE hCertStore,
  6016.     IN PCCTL_CONTEXT pCtlContext,
  6017.     IN DWORD dwAddDisposition,
  6018.     OUT OPTIONAL PCCTL_CONTEXT *ppStoreContext
  6019.     );
  6020.  
  6021. //+-------------------------------------------------------------------------
  6022. //  Serialize the CTL context's encoded CTL and its properties.
  6023. //--------------------------------------------------------------------------
  6024. WINCRYPT32API
  6025. BOOL
  6026. WINAPI
  6027. CertSerializeCTLStoreElement(
  6028.     IN PCCTL_CONTEXT pCtlContext,
  6029.     IN DWORD dwFlags,
  6030.     OUT BYTE *pbElement,
  6031.     IN OUT DWORD *pcbElement
  6032.     );
  6033.  
  6034. //+-------------------------------------------------------------------------
  6035. //  Delete the specified CTL from the store.
  6036. //
  6037. //  All subsequent gets for the CTL will fail. However,
  6038. //  memory allocated for the CTL isn't freed until all of its contexts
  6039. //  have also been freed.
  6040. //
  6041. //  The pCtlContext is obtained from a get or duplicate.
  6042. //
  6043. //  NOTE: the pCtlContext is always CertFreeCTLContext'ed by
  6044. //  this function, even for an error.
  6045. //--------------------------------------------------------------------------
  6046. WINCRYPT32API
  6047. BOOL
  6048. WINAPI
  6049. CertDeleteCTLFromStore(
  6050.     IN PCCTL_CONTEXT pCtlContext
  6051.     );
  6052.  
  6053.  
  6054. //+=========================================================================
  6055. //  Enhanced Key Usage Helper Functions
  6056. //==========================================================================
  6057.  
  6058. //+-------------------------------------------------------------------------
  6059. //  Get the enhanced key usage extension or property from the certificate
  6060. //  and decode.
  6061. //
  6062. //  If the CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG is set, then, only get the
  6063. //  extension.
  6064. //
  6065. //  If the CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG is set, then, only get the
  6066. //  property.
  6067. //--------------------------------------------------------------------------
  6068. WINCRYPT32API
  6069. BOOL
  6070. WINAPI
  6071. CertGetEnhancedKeyUsage(
  6072.     IN PCCERT_CONTEXT pCertContext,
  6073.     IN DWORD dwFlags,
  6074.     OUT PCERT_ENHKEY_USAGE pUsage,
  6075.     IN OUT DWORD *pcbUsage
  6076.     );
  6077.  
  6078. //+-------------------------------------------------------------------------
  6079. //  Set the enhanced key usage property for the certificate.
  6080. //--------------------------------------------------------------------------
  6081. WINCRYPT32API
  6082. BOOL
  6083. WINAPI
  6084. CertSetEnhancedKeyUsage(
  6085.     IN PCCERT_CONTEXT pCertContext,
  6086.     IN PCERT_ENHKEY_USAGE pUsage
  6087.     );
  6088.  
  6089. //+-------------------------------------------------------------------------
  6090. //  Add the usage identifier to the certificate's enhanced key usage property.
  6091. //--------------------------------------------------------------------------
  6092. WINCRYPT32API
  6093. BOOL
  6094. WINAPI
  6095. CertAddEnhancedKeyUsageIdentifier(
  6096.     IN PCCERT_CONTEXT pCertContext,
  6097.     IN LPCSTR pszUsageIdentifier
  6098.     );
  6099.  
  6100.  
  6101. //+-------------------------------------------------------------------------
  6102. //  Remove the usage identifier from the certificate's enhanced key usage
  6103. //  property.
  6104. //--------------------------------------------------------------------------
  6105. WINCRYPT32API
  6106. BOOL
  6107. WINAPI
  6108. CertRemoveEnhancedKeyUsageIdentifier(
  6109.     IN PCCERT_CONTEXT pCertContext,
  6110.     IN LPCSTR pszUsageIdentifier
  6111.     );
  6112.  
  6113.  
  6114. //+=========================================================================
  6115. //  Cryptographic Message helper functions for verifying and signing a
  6116. //  CTL.
  6117. //==========================================================================
  6118.  
  6119. //+-------------------------------------------------------------------------
  6120. //  Get and verify the signer of a cryptographic message.
  6121. //
  6122. //  To verify a CTL, the hCryptMsg is obtained from the CTL_CONTEXT's
  6123. //  hCryptMsg field.
  6124. //
  6125. //  If CMSG_TRUSTED_SIGNER_FLAG is set, then, treat the Signer stores as being
  6126. //  trusted and only search them to find the certificate corresponding to the
  6127. //  signer's issuer and serial number.  Otherwise, the SignerStores are
  6128. //  optionally provided to supplement the message's store of certificates.
  6129. //  If a signer certificate is found, its public key is used to verify
  6130. //  the message signature. The CMSG_SIGNER_ONLY_FLAG can be set to
  6131. //  return the signer without doing the signature verify.
  6132. //
  6133. //  If CMSG_USE_SIGNER_INDEX_FLAG is set, then, only get the signer specified
  6134. //  by *pdwSignerIndex. Otherwise, iterate through all the signers
  6135. //  until a signer verifies or no more signers.
  6136. //
  6137. //  For a verified signature, *ppSigner is updated with certificate context
  6138. //  of the signer and *pdwSignerIndex is updated with the index of the signer.
  6139. //  ppSigner and/or pdwSignerIndex can be NULL, indicating the caller isn't
  6140. //  interested in getting the CertContext and/or index of the signer.
  6141. //--------------------------------------------------------------------------
  6142. WINCRYPT32API
  6143. BOOL
  6144. WINAPI
  6145. CryptMsgGetAndVerifySigner(
  6146.     IN HCRYPTMSG hCryptMsg,
  6147.     IN DWORD cSignerStore,
  6148.     IN OPTIONAL HCERTSTORE *rghSignerStore,
  6149.     IN DWORD dwFlags,
  6150.     OUT OPTIONAL PCCERT_CONTEXT *ppSigner,
  6151.     IN OUT OPTIONAL DWORD *pdwSignerIndex
  6152.     );
  6153.  
  6154. #define CMSG_TRUSTED_SIGNER_FLAG            0x1
  6155. #define CMSG_SIGNER_ONLY_FLAG               0x2
  6156. #define CMSG_USE_SIGNER_INDEX_FLAG          0x4
  6157.  
  6158. //+-------------------------------------------------------------------------
  6159. //  Sign an encoded CTL.
  6160. //
  6161. //  The pbCtlContent can be obtained via a CTL_CONTEXT's pbCtlContent
  6162. //  field or via a CryptEncodeObject(PKCS_CTL).
  6163. //--------------------------------------------------------------------------
  6164. WINCRYPT32API
  6165. BOOL
  6166. WINAPI
  6167. CryptMsgSignCTL(
  6168.     IN DWORD dwMsgEncodingType,
  6169.     IN BYTE *pbCtlContent,
  6170.     IN DWORD cbCtlContent,
  6171.     IN PCMSG_SIGNED_ENCODE_INFO pSignInfo,
  6172.     IN DWORD dwFlags,
  6173.     OUT BYTE *pbEncoded,
  6174.     IN OUT DWORD *pcbEncoded
  6175.     );
  6176.  
  6177. //+-------------------------------------------------------------------------
  6178. //  Encode the CTL and create a signed message containing the encoded CTL.
  6179. //--------------------------------------------------------------------------
  6180. WINCRYPT32API
  6181. BOOL
  6182. WINAPI
  6183. CryptMsgEncodeAndSignCTL(
  6184.     IN DWORD dwMsgEncodingType,
  6185.     IN PCTL_INFO pCtlInfo,
  6186.     IN PCMSG_SIGNED_ENCODE_INFO pSignInfo,
  6187.     IN DWORD dwFlags,
  6188.     OUT BYTE *pbEncoded,
  6189.     IN OUT DWORD *pcbEncoded
  6190.     );
  6191.  
  6192.  
  6193. //+=========================================================================
  6194. //  Certificate Verify CTL Usage Data Structures and APIs
  6195. //==========================================================================
  6196.  
  6197. typedef struct _CTL_VERIFY_USAGE_PARA {
  6198.     DWORD                   cbSize;
  6199.     CRYPT_DATA_BLOB         ListIdentifier;     // OPTIONAL
  6200.     DWORD                   cCtlStore;
  6201.     HCERTSTORE              *rghCtlStore;       // OPTIONAL
  6202.     DWORD                   cSignerStore;
  6203.     HCERTSTORE              *rghSignerStore;    // OPTIONAL
  6204. } CTL_VERIFY_USAGE_PARA, *PCTL_VERIFY_USAGE_PARA;
  6205.  
  6206. typedef struct _CTL_VERIFY_USAGE_STATUS {
  6207.     DWORD                   cbSize;
  6208.     DWORD                   dwError;
  6209.     DWORD                   dwFlags;
  6210.     PCCTL_CONTEXT           *ppCtl;             // IN OUT OPTIONAL
  6211.     DWORD                   dwCtlEntryIndex;
  6212.     PCCERT_CONTEXT          *ppSigner;          // IN OUT OPTIONAL
  6213.     DWORD                   dwSignerIndex;
  6214. } CTL_VERIFY_USAGE_STATUS, *PCTL_VERIFY_USAGE_STATUS;
  6215.  
  6216. #define CERT_VERIFY_INHIBIT_CTL_UPDATE_FLAG     0x1
  6217. #define CERT_VERIFY_TRUSTED_SIGNERS_FLAG        0x2
  6218. #define CERT_VERIFY_NO_TIME_CHECK_FLAG          0x4
  6219. #define CERT_VERIFY_ALLOW_MORE_USAGE_FLAG       0x8
  6220.  
  6221. #define CERT_VERIFY_UPDATED_CTL_FLAG            0x1
  6222.  
  6223. //+-------------------------------------------------------------------------
  6224. //  Verify that a subject is trusted for the specified usage by finding a
  6225. //  signed and time valid CTL with the usage identifiers and containing the
  6226. //  the subject. A subject can be identified by either its certificate context
  6227. //  or any identifier such as its SHA1 hash.
  6228. //
  6229. //  See CertFindSubjectInCTL for definition of dwSubjectType and pvSubject
  6230. //  parameters.
  6231. //
  6232. //  Via pVerifyUsagePara, the caller can specify the stores to be searched
  6233. //  to find the CTL. The caller can also specify the stores containing
  6234. //  acceptable CTL signers. By setting the ListIdentifier, the caller
  6235. //  can also restrict to a particular signer CTL list.
  6236. //
  6237. //  Via pVerifyUsageStatus, the CTL containing the subject, the subject's
  6238. //  index into the CTL's array of entries, and the signer of the CTL
  6239. //  are returned. If the caller is not interested, ppCtl and ppSigner can be set
  6240. //  to NULL. Returned contexts must be freed via the store's free context APIs.
  6241. //
  6242. //  If the CERT_VERIFY_INHIBIT_CTL_UPDATE_FLAG isn't set, then, a time
  6243. //  invalid CTL in one of the CtlStores may be replaced. When replaced, the
  6244. //  CERT_VERIFY_UPDATED_CTL_FLAG is set in pVerifyUsageStatus->dwFlags.
  6245. //
  6246. //  If the CERT_VERIFY_TRUSTED_SIGNERS_FLAG is set, then, only the
  6247. //  SignerStores specified in pVerifyUsageStatus are searched to find
  6248. //  the signer. Otherwise, the SignerStores provide additional sources
  6249. //  to find the signer's certificate.
  6250. //
  6251. //  If CERT_VERIFY_NO_TIME_CHECK_FLAG is set, then, the CTLs aren't checked
  6252. //  for time validity.
  6253. //
  6254. //  If CERT_VERIFY_ALLOW_MORE_USAGE_FLAG is set, then, the CTL may contain
  6255. //  additional usage identifiers than specified by pSubjectUsage. Otherwise,
  6256. //  the found CTL will contain the same usage identifers and no more.
  6257. //
  6258. //  CertVerifyCTLUsage will be implemented as a dispatcher to OID installable
  6259. //  functions. First, it will try to find an OID function matching the first
  6260. //  usage object identifier in the pUsage sequence. Next, it will dispatch
  6261. //  to the default CertDllVerifyCTLUsage functions.
  6262. //
  6263. //  If the subject is trusted for the specified usage, then, TRUE is
  6264. //  returned. Otherwise, FALSE is returned with dwError set to one of the
  6265. //  following:
  6266. //      CRYPT_E_NO_VERIFY_USAGE_DLL
  6267. //      CRYPT_E_NO_VERIFY_USAGE_CHECK
  6268. //      CRYPT_E_VERIFY_USAGE_OFFLINE
  6269. //      CRYPT_E_NOT_IN_CTL
  6270. //      CRYPT_E_NO_TRUSTED_SIGNER
  6271. //--------------------------------------------------------------------------
  6272. WINCRYPT32API
  6273. BOOL
  6274. WINAPI
  6275. CertVerifyCTLUsage(
  6276.     IN DWORD dwEncodingType,
  6277.     IN DWORD dwSubjectType,
  6278.     IN void *pvSubject,
  6279.     IN PCTL_USAGE pSubjectUsage,
  6280.     IN DWORD dwFlags,
  6281.     IN OPTIONAL PCTL_VERIFY_USAGE_PARA pVerifyUsagePara,
  6282.     IN OUT PCTL_VERIFY_USAGE_STATUS pVerifyUsageStatus
  6283.     );
  6284.  
  6285.  
  6286. //+=========================================================================
  6287. //  Certificate Revocation Data Structures and APIs
  6288. //==========================================================================
  6289.  
  6290. //+-------------------------------------------------------------------------
  6291. //  The following data structure may be passed to CertVerifyRevocation to
  6292. //  assist in finding the issuer of the context to be verified.
  6293. //
  6294. //  When pIssuerCert is specified, pIssuerCert is the issuer of
  6295. //  rgpvContext[cContext - 1].
  6296. //
  6297. //  When cCertStore and rgCertStore are specified, these stores may contain
  6298. //  an issuer certificate.
  6299. //--------------------------------------------------------------------------
  6300. typedef struct _CERT_REVOCATION_PARA {
  6301.     DWORD                   cbSize;
  6302.     PCCERT_CONTEXT          pIssuerCert;
  6303.     DWORD                   cCertStore;
  6304.     HCERTSTORE              *rgCertStore;
  6305. } CERT_REVOCATION_PARA, *PCERT_REVOCATION_PARA;
  6306.  
  6307.  
  6308. //+-------------------------------------------------------------------------
  6309. //  The following data structure is returned by CertVerifyRevocation to
  6310. //  specify the status of the revoked or unchecked context. Review the
  6311. //  following CertVerifyRevocation comments for details.
  6312. //
  6313. //  Upon input to CertVerifyRevocation, cbSize must be set to a size
  6314. //  >= sizeof(CERT_REVOCATION_STATUS). Otherwise, CertVerifyRevocation
  6315. //  returns FALSE and sets LastError to E_INVALIDARG.
  6316. //
  6317. //  Upon input to the installed or registered CRYPT_OID_VERIFY_REVOCATION_FUNC
  6318. //  functions, the dwIndex, dwError and dwReason have been zero'ed.
  6319. //--------------------------------------------------------------------------
  6320. typedef struct _CERT_REVOCATION_STATUS {
  6321.     DWORD                   cbSize;
  6322.     DWORD                   dwIndex;
  6323.     DWORD                   dwError;
  6324.     DWORD                   dwReason;
  6325. } CERT_REVOCATION_STATUS, *PCERT_REVOCATION_STATUS;
  6326.  
  6327.  
  6328. //+-------------------------------------------------------------------------
  6329. //  Verifies the array of contexts for revocation. The dwRevType parameter
  6330. //  indicates the type of the context data structure passed in rgpvContext.
  6331. //  Currently only the revocation of certificates is defined.
  6332. //
  6333. //  If the CERT_VERIFY_REV_CHAIN_FLAG flag is set, then, CertVerifyRevocation
  6334. //  is verifying a chain of certs where, rgpvContext[i + 1] is the issuer
  6335. //  of rgpvContext[i]. Otherwise, CertVerifyRevocation makes no assumptions
  6336. //  about the order of the contexts.
  6337. //
  6338. //  To assist in finding the issuer, the pRevPara may optionally be set. See
  6339. //  the CERT_REVOCATION_PARA data structure for details.
  6340. //
  6341. //  The contexts must contain enough information to allow the
  6342. //  installable or registered revocation DLLs to find the revocation server. For
  6343. //  certificates, this information would normally be conveyed in an
  6344. //  extension such as the IETF's AuthorityInfoAccess extension.
  6345. //
  6346. //  CertVerifyRevocation returns TRUE if all of the contexts were successfully
  6347. //  checked and none were revoked. Otherwise, returns FALSE and updates the
  6348. //  returned pRevStatus data structure as follows:
  6349. //    dwIndex
  6350. //      Index of the first context that was revoked or unable to
  6351. //      be checked for revocation
  6352. //    dwError
  6353. //      Error status. LastError is also set to this error status.
  6354. //      dwError can be set to one of the following error codes defined
  6355. //      in winerror.h:
  6356. //        ERROR_SUCCESS - good context
  6357. //        CRYPT_E_REVOKED - context was revoked. dwReason contains the
  6358. //           reason for revocation
  6359. //        CRYPT_E_REVOCATION_OFFLINE - unable to connect to the
  6360. //           revocation server
  6361. //        CRYPT_E_NOT_IN_REVOCATION_DATABASE - the context to be checked
  6362. //           was not found in the revocation server's database.
  6363. //        CRYPT_E_NO_REVOCATION_CHECK - the called revocation function
  6364. //           wasn't able to do a revocation check on the context
  6365. //        CRYPT_E_NO_REVOCATION_DLL - no installed or registered Dll was
  6366. //           found to verify revocation
  6367. //    dwReason
  6368. //      The dwReason is currently only set for CRYPT_E_REVOKED and contains
  6369. //      the reason why the context was revoked. May be one of the following
  6370. //      CRL reasons defined by the CRL Reason Code extension ("2.5.29.21")
  6371. //          CRL_REASON_UNSPECIFIED              0
  6372. //          CRL_REASON_KEY_COMPROMISE           1
  6373. //          CRL_REASON_CA_COMPROMISE            2
  6374. //          CRL_REASON_AFFILIATION_CHANGED      3
  6375. //          CRL_REASON_SUPERSEDED               4
  6376. //          CRL_REASON_CESSATION_OF_OPERATION   5
  6377. //          CRL_REASON_CERTIFICATE_HOLD         6
  6378. //
  6379. //  For each entry in rgpvContext, CertVerifyRevocation iterates
  6380. //  through the CRYPT_OID_VERIFY_REVOCATION_FUNC
  6381. //  function set's list of installed DEFAULT functions.
  6382. //  CryptGetDefaultOIDFunctionAddress is called with pwszDll = NULL. If no
  6383. //  installed functions are found capable of doing the revocation verification,
  6384. //  CryptVerifyRevocation iterates through CRYPT_OID_VERIFY_REVOCATION_FUNC's
  6385. //  list of registered DEFAULT Dlls. CryptGetDefaultOIDDllList is called to
  6386. //  get the list. CryptGetDefaultOIDFunctionAddress is called to load the Dll.
  6387. //
  6388. //  The called functions have the same signature as CertVerifyRevocation. A
  6389. //  called function returns TRUE if it was able to successfully check all of
  6390. //  the contexts and none were revoked. Otherwise, the called function returns
  6391. //  FALSE and updates pRevStatus. dwIndex is set to the index of
  6392. //  the first context that was found to be revoked or unable to be checked.
  6393. //  dwError and LastError are updated. For CRYPT_E_REVOKED, dwReason
  6394. //  is updated. Upon input to the called function, dwIndex, dwError and
  6395. //  dwReason have been zero'ed. cbSize has been checked to be >=
  6396. //  sizeof(CERT_REVOCATION_STATUS).
  6397. //
  6398. //  If the called function returns FALSE, and dwError isn't set to
  6399. //  CRYPT_E_REVOKED, then, CertVerifyRevocation either continues on to the
  6400. //  next DLL in the list for a returned dwIndex of 0 or for a returned
  6401. //  dwIndex > 0, restarts the process of finding a verify function by
  6402. //  advancing the start of the context array to the returned dwIndex and
  6403. //  decrementing the count of remaining contexts.
  6404. //--------------------------------------------------------------------------
  6405. WINCRYPT32API
  6406. BOOL
  6407. WINAPI
  6408. CertVerifyRevocation(
  6409.     IN DWORD dwEncodingType,
  6410.     IN DWORD dwRevType,
  6411.     IN DWORD cContext,
  6412.     IN PVOID rgpvContext[],
  6413.     IN DWORD dwFlags,
  6414.     IN OPTIONAL PCERT_REVOCATION_PARA pRevPara,
  6415.     IN OUT PCERT_REVOCATION_STATUS pRevStatus
  6416.     );
  6417.  
  6418. //+-------------------------------------------------------------------------
  6419. //  Revocation types
  6420. //--------------------------------------------------------------------------
  6421. #define CERT_CONTEXT_REVOCATION_TYPE        1
  6422.  
  6423. //+-------------------------------------------------------------------------
  6424. //  When the following flag is set, rgpvContext[] consists of a chain
  6425. //  of certificates, where rgpvContext[i + 1] is the issuer of rgpvContext[i].
  6426. //--------------------------------------------------------------------------
  6427. #define CERT_VERIFY_REV_CHAIN_FLAG          0x1
  6428.  
  6429. //+-------------------------------------------------------------------------
  6430. //  CERT_CONTEXT_REVOCATION_TYPE
  6431. //
  6432. //  pvContext points to a const CERT_CONTEXT.
  6433. //--------------------------------------------------------------------------
  6434.  
  6435. //+=========================================================================
  6436. //  Certificate Helper APIs
  6437. //==========================================================================
  6438.  
  6439.  
  6440. //+-------------------------------------------------------------------------
  6441. //  Compare two multiple byte integer blobs to see if they are identical.
  6442. //
  6443. //  Before doing the comparison, leading zero bytes are removed from a
  6444. //  positive number and leading 0xFF bytes are removed from a negative
  6445. //  number.
  6446. //
  6447. //  The multiple byte integers are treated as Little Endian. pbData[0] is the
  6448. //  least significant byte and pbData[cbData - 1] is the most significant
  6449. //  byte.
  6450. //
  6451. //  Returns TRUE if the integer blobs are identical after removing leading
  6452. //  0 or 0xFF bytes.
  6453. //--------------------------------------------------------------------------
  6454. BOOL
  6455. WINAPI
  6456. CertCompareIntegerBlob(
  6457.     IN PCRYPT_INTEGER_BLOB pInt1,
  6458.     IN PCRYPT_INTEGER_BLOB pInt2
  6459.     );
  6460.  
  6461. //+-------------------------------------------------------------------------
  6462. //  Compare two certificates to see if they are identical.
  6463. //
  6464. //  Since a certificate is uniquely identified by its Issuer and SerialNumber,
  6465. //  these are the only fields needing to be compared.
  6466. //
  6467. //  Returns TRUE if the certificates are identical.
  6468. //--------------------------------------------------------------------------
  6469. WINCRYPT32API
  6470. BOOL
  6471. WINAPI
  6472. CertCompareCertificate(
  6473.     IN DWORD dwCertEncodingType,
  6474.     IN PCERT_INFO pCertId1,
  6475.     IN PCERT_INFO pCertId2
  6476.     );
  6477.  
  6478. //+-------------------------------------------------------------------------
  6479. //  Compare two certificate names to see if they are identical.
  6480. //
  6481. //  Returns TRUE if the names are identical.
  6482. //--------------------------------------------------------------------------
  6483. WINCRYPT32API
  6484. BOOL
  6485. WINAPI
  6486. CertCompareCertificateName(
  6487.     IN DWORD dwCertEncodingType,
  6488.     IN PCERT_NAME_BLOB pCertName1,
  6489.     IN PCERT_NAME_BLOB pCertName2
  6490.     );
  6491.  
  6492. //+-------------------------------------------------------------------------
  6493. //  Compare the attributes in the certificate name with the specified
  6494. //  Relative Distinguished Name's (CERT_RDN) array of attributes.
  6495. //  The comparison iterates through the CERT_RDN attributes and looks for an
  6496. //  attribute match in any of the certificate name's RDNs.
  6497. //  Returns TRUE if all the attributes are found and match.
  6498. //
  6499. //  The CERT_RDN_ATTR fields can have the following special values:
  6500. //    pszObjId == NULL              - ignore the attribute object identifier
  6501. //    dwValueType == RDN_ANY_TYPE   - ignore the value type
  6502. //
  6503. //  Currently only an exact, case sensitive match is supported.
  6504. //
  6505. //  CERT_UNICODE_IS_RDN_ATTRS_FLAG should be set if the pRDN was initialized
  6506. //  with unicode strings as for CryptEncodeObject(X509_UNICODE_NAME).
  6507. //--------------------------------------------------------------------------
  6508. WINCRYPT32API
  6509. BOOL
  6510. WINAPI
  6511. CertIsRDNAttrsInCertificateName(
  6512.     IN DWORD dwCertEncodingType,
  6513.     IN DWORD dwFlags,
  6514.     IN PCERT_NAME_BLOB pCertName,
  6515.     IN PCERT_RDN pRDN
  6516.     );
  6517.  
  6518. #define CERT_UNICODE_IS_RDN_ATTRS_FLAG  0x1
  6519.  
  6520. //+-------------------------------------------------------------------------
  6521. //  Compare two public keys to see if they are identical.
  6522. //
  6523. //  Returns TRUE if the keys are identical.
  6524. //--------------------------------------------------------------------------
  6525. WINCRYPT32API
  6526. BOOL
  6527. WINAPI
  6528. CertComparePublicKeyInfo(
  6529.     IN DWORD dwCertEncodingType,
  6530.     IN PCERT_PUBLIC_KEY_INFO pPublicKey1,
  6531.     IN PCERT_PUBLIC_KEY_INFO pPublicKey2
  6532.     );
  6533.  
  6534. //+-------------------------------------------------------------------------
  6535. //  Get the public/private key's bit length.
  6536. //
  6537. //  Returns 0 if unable to determine the key's length.
  6538. //--------------------------------------------------------------------------
  6539. WINCRYPT32API
  6540. DWORD
  6541. WINAPI
  6542. CertGetPublicKeyLength(
  6543.     IN DWORD dwCertEncodingType,
  6544.     IN PCERT_PUBLIC_KEY_INFO pPublicKey
  6545.     );
  6546.  
  6547. //+-------------------------------------------------------------------------
  6548. //  Verify the signature of a subject certificate or a CRL using the
  6549. //  public key info
  6550. //
  6551. //  Returns TRUE for a valid signature.
  6552. //
  6553. //  hCryptProv specifies the crypto provider to use to verify the signature.
  6554. //  It doesn't need to use a private key.
  6555. //--------------------------------------------------------------------------
  6556. WINCRYPT32API
  6557. BOOL
  6558. WINAPI
  6559. CryptVerifyCertificateSignature(
  6560.     IN HCRYPTPROV               hCryptProv,
  6561.     IN DWORD                    dwCertEncodingType,
  6562.     IN const BYTE *             pbEncoded,
  6563.     IN DWORD                    cbEncoded,
  6564.     IN PCERT_PUBLIC_KEY_INFO    pPublicKey
  6565.     );
  6566.  
  6567. //+-------------------------------------------------------------------------
  6568. //  Compute the hash of the "to be signed" information in the encoded
  6569. //  signed content (CERT_SIGNED_CONTENT_INFO).
  6570. //
  6571. //  hCryptProv specifies the crypto provider to use to compute the hash.
  6572. //  It doesn't need to use a private key.
  6573. //--------------------------------------------------------------------------
  6574. WINCRYPT32API
  6575. BOOL
  6576. WINAPI
  6577. CryptHashToBeSigned(
  6578.     IN HCRYPTPROV hCryptProv,
  6579.     IN DWORD dwCertEncodingType,
  6580.     IN const BYTE *pbEncoded,
  6581.     IN DWORD cbEncoded,
  6582.     OUT BYTE *pbComputedHash,
  6583.     IN OUT DWORD *pcbComputedHash
  6584.     );
  6585.  
  6586. //+-------------------------------------------------------------------------
  6587. //  Hash the encoded content.
  6588. //
  6589. //  hCryptProv specifies the crypto provider to use to compute the hash.
  6590. //  It doesn't need to use a private key.
  6591. //
  6592. //  Algid specifies the CAPI hash algorithm to use. If Algid is 0, then, the
  6593. //  default hash algorithm (currently SHA1) is used.
  6594. //--------------------------------------------------------------------------
  6595. WINCRYPT32API
  6596. BOOL
  6597. WINAPI
  6598. CryptHashCertificate(
  6599.     IN HCRYPTPROV hCryptProv,
  6600.     IN ALG_ID Algid,
  6601.     IN DWORD dwFlags,
  6602.     IN const BYTE *pbEncoded,
  6603.     IN DWORD cbEncoded,
  6604.     OUT BYTE *pbComputedHash,
  6605.     IN OUT DWORD *pcbComputedHash
  6606.     );
  6607.  
  6608. //+-------------------------------------------------------------------------
  6609. //  Sign the "to be signed" information in the encoded signed content.
  6610. //
  6611. //  hCryptProv specifies the crypto provider to use to do the signature.
  6612. //  It uses the specified private key.
  6613. //--------------------------------------------------------------------------
  6614. WINCRYPT32API
  6615. BOOL
  6616. WINAPI
  6617. CryptSignCertificate(
  6618.     IN HCRYPTPROV hCryptProv,
  6619.     IN DWORD dwKeySpec,
  6620.     IN DWORD dwCertEncodingType,
  6621.     IN const BYTE *pbEncodedToBeSigned,
  6622.     IN DWORD cbEncodedToBeSigned,
  6623.     IN PCRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm,
  6624.     IN OPTIONAL const void *pvHashAuxInfo,
  6625.     OUT BYTE *pbSignature,
  6626.     IN OUT DWORD *pcbSignature
  6627.     );
  6628.  
  6629. //+-------------------------------------------------------------------------
  6630. //  Encode the "to be signed" information. Sign the encoded "to be signed".
  6631. //  Encode the "to be signed" and the signature.
  6632. //
  6633. //  hCryptProv specifies the crypto provider to use to do the signature.
  6634. //  It uses the specified private key.
  6635. //--------------------------------------------------------------------------
  6636. WINCRYPT32API
  6637. BOOL
  6638. WINAPI
  6639. CryptSignAndEncodeCertificate(
  6640.     IN HCRYPTPROV hCryptProv,
  6641.     IN DWORD dwKeySpec,
  6642.     IN DWORD dwCertEncodingType,
  6643.     IN LPCSTR lpszStructType,       // "to be signed"
  6644.     IN const void *pvStructInfo,
  6645.     IN PCRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm,
  6646.     IN OPTIONAL const void *pvHashAuxInfo,
  6647.     OUT PBYTE pbEncoded,
  6648.     IN OUT DWORD *pcbEncoded
  6649.     );
  6650.  
  6651.  
  6652. //+-------------------------------------------------------------------------
  6653. //  Verify the time validity of a certificate.
  6654. //
  6655. //  Returns -1 if before NotBefore, +1 if after NotAfter and otherwise 0 for
  6656. //  a valid certificate
  6657. //
  6658. //  If pTimeToVerify is NULL, uses the current time.
  6659. //--------------------------------------------------------------------------
  6660. WINCRYPT32API
  6661. LONG
  6662. WINAPI
  6663. CertVerifyTimeValidity(
  6664.     IN LPFILETIME pTimeToVerify,
  6665.     IN PCERT_INFO pCertInfo
  6666.     );
  6667.  
  6668.  
  6669. //+-------------------------------------------------------------------------
  6670. //  Verify the time validity of a CRL.
  6671. //
  6672. //  Returns -1 if before ThisUpdate, +1 if after NextUpdate and otherwise 0 for
  6673. //  a valid CRL
  6674. //
  6675. //  If pTimeToVerify is NULL, uses the current time.
  6676. //--------------------------------------------------------------------------
  6677. WINCRYPT32API
  6678. LONG
  6679. WINAPI
  6680. CertVerifyCRLTimeValidity(
  6681.     IN LPFILETIME pTimeToVerify,
  6682.     IN PCRL_INFO pCrlInfo
  6683.     );
  6684.  
  6685. //+-------------------------------------------------------------------------
  6686. //  Verify that the subject's time validity nests within the issuer's time
  6687. //  validity.
  6688. //
  6689. //  Returns TRUE if it nests. Otherwise, returns FALSE.
  6690. //--------------------------------------------------------------------------
  6691. WINCRYPT32API
  6692. BOOL
  6693. WINAPI
  6694. CertVerifyValidityNesting(
  6695.     IN PCERT_INFO pSubjectInfo,
  6696.     IN PCERT_INFO pIssuerInfo
  6697.     );
  6698.  
  6699. //+-------------------------------------------------------------------------
  6700. //  Verify that the subject certificate isn't on its issuer CRL.
  6701. //
  6702. //  Returns true if the certificate isn't on the CRL.
  6703. //--------------------------------------------------------------------------
  6704. WINCRYPT32API
  6705. BOOL
  6706. WINAPI
  6707. CertVerifyCRLRevocation(
  6708.     IN DWORD dwCertEncodingType,
  6709.     IN PCERT_INFO pCertId,          // Only the Issuer and SerialNumber
  6710.                                     // fields are used
  6711.     IN DWORD cCrlInfo,
  6712.     IN PCRL_INFO rgpCrlInfo[]
  6713.     );
  6714.  
  6715. //+-------------------------------------------------------------------------
  6716. //  Convert the CAPI AlgId to the ASN.1 Object Identifier string
  6717. //
  6718. //  Returns NULL if there isn't an ObjId corresponding to the AlgId.
  6719. //--------------------------------------------------------------------------
  6720. WINCRYPT32API
  6721. LPCSTR
  6722. WINAPI
  6723. CertAlgIdToOID(
  6724.     IN DWORD dwAlgId
  6725.     );
  6726.  
  6727. //+-------------------------------------------------------------------------
  6728. //  Convert the ASN.1 Object Identifier string to the CAPI AlgId.
  6729. //
  6730. //  Returns 0 if there isn't an AlgId corresponding to the ObjId.
  6731. //--------------------------------------------------------------------------
  6732. WINCRYPT32API
  6733. DWORD
  6734. WINAPI
  6735. CertOIDToAlgId(
  6736.     IN LPCSTR pszObjId
  6737.     );
  6738.  
  6739. //+-------------------------------------------------------------------------
  6740. //  Find an extension identified by its Object Identifier.
  6741. //
  6742. //  If found, returns pointer to the extension. Otherwise, returns NULL.
  6743. //--------------------------------------------------------------------------
  6744. WINCRYPT32API
  6745. PCERT_EXTENSION
  6746. WINAPI
  6747. CertFindExtension(
  6748.     IN LPCSTR pszObjId,
  6749.     IN DWORD cExtensions,
  6750.     IN CERT_EXTENSION rgExtensions[]
  6751.     );
  6752.  
  6753. //+-------------------------------------------------------------------------
  6754. //  Find the first attribute identified by its Object Identifier.
  6755. //
  6756. //  If found, returns pointer to the attribute. Otherwise, returns NULL.
  6757. //--------------------------------------------------------------------------
  6758. WINCRYPT32API
  6759. PCRYPT_ATTRIBUTE
  6760. WINAPI
  6761. CertFindAttribute(
  6762.     IN LPCSTR pszObjId,
  6763.     IN DWORD cAttr,
  6764.     IN CRYPT_ATTRIBUTE rgAttr[]
  6765.     );
  6766.  
  6767. //+-------------------------------------------------------------------------
  6768. //  Find the first CERT_RDN attribute identified by its Object Identifier in
  6769. //  the name's list of Relative Distinguished Names.
  6770. //
  6771. //  If found, returns pointer to the attribute. Otherwise, returns NULL.
  6772. //--------------------------------------------------------------------------
  6773. WINCRYPT32API
  6774. PCERT_RDN_ATTR
  6775. WINAPI
  6776. CertFindRDNAttr(
  6777.     IN LPCSTR pszObjId,
  6778.     IN PCERT_NAME_INFO pName
  6779.     );
  6780.  
  6781. //+-------------------------------------------------------------------------
  6782. //  Get the intended key usage bytes from the certificate.
  6783. //
  6784. //  If the certificate doesn't have any intended key usage bytes, returns FALSE
  6785. //  and *pbKeyUsage is zeroed. Otherwise, returns TRUE and up through
  6786. //  cbKeyUsage bytes are copied into *pbKeyUsage. Any remaining uncopied
  6787. //  bytes are zeroed.
  6788. //--------------------------------------------------------------------------
  6789. WINCRYPT32API
  6790. BOOL
  6791. WINAPI
  6792. CertGetIntendedKeyUsage(
  6793.     IN DWORD dwCertEncodingType,
  6794.     IN PCERT_INFO pCertInfo,
  6795.     OUT BYTE *pbKeyUsage,
  6796.     IN DWORD cbKeyUsage
  6797.     );
  6798.  
  6799.  
  6800. //+-------------------------------------------------------------------------
  6801. //  Export the public key info associated with the provider's corresponding
  6802. //  private key.
  6803. //
  6804. //  Calls CryptExportPublicKeyInfo with pszPublicKeyObjId = szOID_RSA_RSA,
  6805. //  dwFlags = 0 and pvAuxInfo = NULL.
  6806. //--------------------------------------------------------------------------
  6807. WINCRYPT32API
  6808. BOOL
  6809. WINAPI
  6810. CryptExportPublicKeyInfo(
  6811.     IN HCRYPTPROV hCryptProv,
  6812.     IN DWORD dwKeySpec,
  6813.     IN DWORD dwCertEncodingType,
  6814.     OUT PCERT_PUBLIC_KEY_INFO pInfo,
  6815.     IN OUT DWORD *pcbInfo
  6816.     );
  6817.  
  6818.  
  6819. //+-------------------------------------------------------------------------
  6820. //  Export the public key info associated with the provider's corresponding
  6821. //  private key.
  6822. //
  6823. //  Uses the dwCertEncodingType and pszPublicKeyObjId to call the
  6824. //  installable CRYPT_OID_EXPORT_PUBLIC_KEY_INFO_FUNC. The called function
  6825. //  has the same signature as CryptExportPublicKeyInfoEx.
  6826. //
  6827. //  If unable to find an installable OID function for the pszPublicKeyObjId,
  6828. //  attempts to export as a RSA Public Key (szOID_RSA_RSA).
  6829. //
  6830. //  The dwFlags and pvAuxInfo aren't used for szOID_RSA_RSA.
  6831. //--------------------------------------------------------------------------
  6832. #define CRYPT_OID_EXPORT_PUBLIC_KEY_INFO_FUNC   "CryptDllExportPublicKeyInfoEx"
  6833.  
  6834. WINCRYPT32API
  6835. BOOL
  6836. WINAPI
  6837. CryptExportPublicKeyInfoEx(
  6838.     IN HCRYPTPROV hCryptProv,
  6839.     IN DWORD dwKeySpec,
  6840.     IN DWORD dwCertEncodingType,
  6841.     IN LPSTR pszPublicKeyObjId,
  6842.     IN DWORD dwFlags,
  6843.     IN OPTIONAL void *pvAuxInfo,
  6844.     OUT PCERT_PUBLIC_KEY_INFO pInfo,
  6845.     IN OUT DWORD *pcbInfo
  6846.     );
  6847.  
  6848.  
  6849. //+-------------------------------------------------------------------------
  6850. //  Convert and import the public key info into the provider and return a
  6851. //  handle to the public key.
  6852. //
  6853. //  Calls CryptImportPublicKeyInfoEx with aiKeyAlg = 0, dwFlags = 0 and
  6854. //  pvAuxInfo = NULL.
  6855. //--------------------------------------------------------------------------
  6856. WINCRYPT32API
  6857. BOOL
  6858. WINAPI
  6859. CryptImportPublicKeyInfo(
  6860.     IN HCRYPTPROV hCryptProv,
  6861.     IN DWORD dwCertEncodingType,
  6862.     IN PCERT_PUBLIC_KEY_INFO pInfo,
  6863.     OUT HCRYPTKEY *phKey
  6864.     );
  6865.  
  6866. //+-------------------------------------------------------------------------
  6867. //  Convert and import the public key info into the provider and return a
  6868. //  handle to the public key.
  6869. //
  6870. //  Uses the dwCertEncodingType and pInfo->Algorithm.pszObjId to call the
  6871. //  installable CRYPT_OID_IMPORT_PUBLIC_KEY_INFO_FUNC. The called function
  6872. //  has the same signature as CryptImportPublicKeyInfoEx.
  6873. //
  6874. //  If unable to find an installable OID function for the pszObjId,
  6875. //  attempts to import as a RSA Public Key (szOID_RSA_RSA).
  6876. //
  6877. //  For szOID_RSA_RSA: aiKeyAlg may be set to CALG_RSA_SIGN or CALG_RSA_KEYX.
  6878. //  Defaults to CALG_RSA_KEYX. The dwFlags and pvAuxInfo aren't used.
  6879. //--------------------------------------------------------------------------
  6880. #define CRYPT_OID_IMPORT_PUBLIC_KEY_INFO_FUNC   "CryptDllImportPublicKeyInfoEx"
  6881.  
  6882. WINCRYPT32API
  6883. BOOL
  6884. WINAPI
  6885. CryptImportPublicKeyInfoEx(
  6886.     IN HCRYPTPROV hCryptProv,
  6887.     IN DWORD dwCertEncodingType,
  6888.     IN PCERT_PUBLIC_KEY_INFO pInfo,
  6889.     IN ALG_ID aiKeyAlg,
  6890.     IN DWORD dwFlags,
  6891.     IN OPTIONAL void *pvAuxInfo,
  6892.     OUT HCRYPTKEY *phKey
  6893.     );
  6894.  
  6895. //+-------------------------------------------------------------------------
  6896. //  Compute the hash of the encoded public key info.
  6897. //
  6898. //  The public key info is encoded and then hashed.
  6899. //--------------------------------------------------------------------------
  6900. WINCRYPT32API
  6901. BOOL
  6902. WINAPI
  6903. CryptHashPublicKeyInfo(
  6904.     IN HCRYPTPROV hCryptProv,
  6905.     IN ALG_ID Algid,
  6906.     IN DWORD dwFlags,
  6907.     IN DWORD dwCertEncodingType,
  6908.     IN PCERT_PUBLIC_KEY_INFO pInfo,
  6909.     OUT BYTE *pbComputedHash,
  6910.     IN OUT DWORD *pcbComputedHash
  6911.     );
  6912.  
  6913. //+-------------------------------------------------------------------------
  6914. //  Convert a Name Value to a null terminated char string
  6915. //
  6916. //  Returns the number of characters converted including the terminating null
  6917. //  character. If psz is NULL or csz is 0, returns the required size of the
  6918. //  destination string (including the terminating null char).
  6919. //
  6920. //  If psz != NULL && csz != 0, returned psz is always NULL terminated.
  6921. //
  6922. //  Note: csz includes the NULL char.
  6923. //--------------------------------------------------------------------------
  6924. WINCRYPT32API
  6925. DWORD
  6926. WINAPI
  6927. CertRDNValueToStrA(
  6928.     IN DWORD dwValueType,
  6929.     IN PCERT_RDN_VALUE_BLOB pValue,
  6930.     OUT OPTIONAL LPSTR psz,
  6931.     IN DWORD csz
  6932.     );
  6933. //+-------------------------------------------------------------------------
  6934. //  Convert a Name Value to a null terminated char string
  6935. //
  6936. //  Returns the number of characters converted including the terminating null
  6937. //  character. If psz is NULL or csz is 0, returns the required size of the
  6938. //  destination string (including the terminating null char).
  6939. //
  6940. //  If psz != NULL && csz != 0, returned psz is always NULL terminated.
  6941. //
  6942. //  Note: csz includes the NULL char.
  6943. //--------------------------------------------------------------------------
  6944. WINCRYPT32API
  6945. DWORD
  6946. WINAPI
  6947. CertRDNValueToStrW(
  6948.     IN DWORD dwValueType,
  6949.     IN PCERT_RDN_VALUE_BLOB pValue,
  6950.     OUT OPTIONAL LPWSTR psz,
  6951.     IN DWORD csz
  6952.     );
  6953. #ifdef UNICODE
  6954. #define CertRDNValueToStr  CertRDNValueToStrW
  6955. #else
  6956. #define CertRDNValueToStr  CertRDNValueToStrA
  6957. #endif // !UNICODE
  6958.  
  6959. //+-------------------------------------------------------------------------
  6960. //  Convert the certificate name blob to a null terminated char string.
  6961. //
  6962. //  Follows the string representation of distinguished names specified in
  6963. //  RFC 1779. (Note, added double quoting "" for embedded quotes, quote
  6964. //  empty strings and don't quote strings containing consecutive spaces).
  6965. //  RDN values of type CERT_RDN_ENCODED_BLOB or CERT_RDN_OCTET_STRING are
  6966. //  formatted in hexadecimal (e.g. #0A56CF).
  6967. //
  6968. //  The name string is formatted according to the dwStrType:
  6969. //    CERT_SIMPLE_NAME_STR
  6970. //      The object identifiers are discarded. CERT_RDN entries are separated
  6971. //      by ", ". Multiple attributes per CERT_RDN are separated by " + ".
  6972. //      For example:
  6973. //          Microsoft, Joe Cool + Programmer
  6974. //    CERT_OID_NAME_STR
  6975. //      The object identifiers are included with a "=" separator from their
  6976. //      attribute value. CERT_RDN entries are separated by ", ".
  6977. //      Multiple attributes per CERT_RDN are separated by " + ". For example:
  6978. //          2.5.4.11=Microsoft, 2.5.4.3=Joe Cool + 2.5.4.12=Programmer
  6979. //    CERT_X500_NAME_STR
  6980. //      The object identifiers are converted to their X500 key name. Otherwise,
  6981. //      same as CERT_OID_NAME_STR. If the object identifier doesn't have
  6982. //      a corresponding X500 key name, then, the object identifier is used with
  6983. //      a "OID." prefix. For example:
  6984. //          OU=Microsoft, CN=Joe Cool + T=Programmer, OID.1.2.3.4.5.6=Unknown
  6985. //
  6986. //  We quote the RDN value if it contains leading or trailing whitespace
  6987. //  or one of the following characters: ",", "+", "=", """, "\n",  "<", ">",
  6988. //  "#" or ";". The quoting character is ". If the the RDN Value contains
  6989. //  a " it is double quoted (""). For example:
  6990. //      OU="  Microsoft", CN="Joe ""Cool""" + T="Programmer, Manager"
  6991. //
  6992. //  CERT_NAME_STR_SEMICOLON_FLAG can be or'ed into dwStrType to replace
  6993. //  the ", " separator with a "; " separator.
  6994. //
  6995. //  CERT_NAME_STR_CRLF_FLAG can be or'ed into dwStrType to replace
  6996. //  the ", " separator with a "\r\n" separator.
  6997. //
  6998. //  CERT_NAME_STR_NO_PLUS_FLAG can be or'ed into dwStrType to replace the
  6999. //  " + " separator with a single space, " ".
  7000. //
  7001. //  CERT_NAME_STR_NO_QUOTING_FLAG can be or'ed into dwStrType to inhibit
  7002. //  the above quoting.
  7003. //
  7004. //  Returns the number of characters converted including the terminating null
  7005. //  character. If psz is NULL or csz is 0, returns the required size of the
  7006. //  destination string (including the terminating null char).
  7007. //
  7008. //  If psz != NULL && csz != 0, returned psz is always NULL terminated.
  7009. //
  7010. //  Note: csz includes the NULL char.
  7011. //--------------------------------------------------------------------------
  7012.  
  7013. //+-------------------------------------------------------------------------
  7014. //--------------------------------------------------------------------------
  7015. WINCRYPT32API
  7016. DWORD
  7017. WINAPI
  7018. CertNameToStrA(
  7019.     IN DWORD dwCertEncodingType,
  7020.     IN PCERT_NAME_BLOB pName,
  7021.     IN DWORD dwStrType,
  7022.     OUT OPTIONAL LPSTR psz,
  7023.     IN DWORD csz
  7024.     );
  7025. //+-------------------------------------------------------------------------
  7026. //--------------------------------------------------------------------------
  7027. WINCRYPT32API
  7028. DWORD
  7029. WINAPI
  7030. CertNameToStrW(
  7031.     IN DWORD dwCertEncodingType,
  7032.     IN PCERT_NAME_BLOB pName,
  7033.     IN DWORD dwStrType,
  7034.     OUT OPTIONAL LPWSTR psz,
  7035.     IN DWORD csz
  7036.     );
  7037. #ifdef UNICODE
  7038. #define CertNameToStr  CertNameToStrW
  7039. #else
  7040. #define CertNameToStr  CertNameToStrA
  7041. #endif // !UNICODE
  7042.  
  7043. //+-------------------------------------------------------------------------
  7044. //  Certificate name string types
  7045. //--------------------------------------------------------------------------
  7046. #define CERT_SIMPLE_NAME_STR        1
  7047. #define CERT_OID_NAME_STR           2
  7048. #define CERT_X500_NAME_STR          3
  7049.  
  7050. //+-------------------------------------------------------------------------
  7051. //  Certificate name string type flags OR'ed with the above types
  7052. //--------------------------------------------------------------------------
  7053. #define CERT_NAME_STR_SEMICOLON_FLAG    0x40000000
  7054. #define CERT_NAME_STR_NO_PLUS_FLAG      0x20000000
  7055. #define CERT_NAME_STR_NO_QUOTING_FLAG   0x10000000
  7056. #define CERT_NAME_STR_CRLF_FLAG         0x08000000
  7057. #define CERT_NAME_STR_COMMA_FLAG        0x04000000
  7058.  
  7059.  
  7060. //+-------------------------------------------------------------------------
  7061. //  Convert the null terminated X500 string to an encoded certificate name.
  7062. //
  7063. //  The input string is expected to be formatted the same as the output
  7064. //  from the above CertNameToStr API.
  7065. //
  7066. //  The CERT_SIMPLE_NAME_STR type isn't supported. Otherwise, when dwStrType
  7067. //  is set to 0, CERT_OID_NAME_STR or CERT_X500_NAME_STR, allow either a
  7068. //  case insensitive X500 key (CN=), case insensitive "OID." prefixed
  7069. //  object identifier (OID.1.2.3.4.5.6=) or an object identifier (1.2.3.4=).
  7070. //
  7071. //  If no flags are OR'ed into dwStrType, then, allow "," or ";" as RDN
  7072. //  separators and "+" as the multiple RDN value separator. Quoting is
  7073. //  supported. A quote may be included in a quoted value by double quoting,
  7074. //  for example (CN="Joe ""Cool"""). A value starting with a "#" is treated
  7075. //  as ascii hex and converted to a CERT_RDN_OCTET_STRING. Embedded whitespace
  7076. //  is skipped (1.2.3 = # AB CD 01  is the same as 1.2.3=#ABCD01).
  7077. //
  7078. //  Whitespace surrounding the keys, object identifers and values is removed.
  7079. //
  7080. //  CERT_NAME_STR_COMMA_FLAG can be or'ed into dwStrType to only allow the
  7081. //  "," as the RDN separator.
  7082. //
  7083. //  CERT_NAME_STR_SEMICOLON_FLAG can be or'ed into dwStrType to only allow the
  7084. //  ";" as the RDN separator.
  7085. //
  7086. //  CERT_NAME_STR_CRLF_FLAG can be or'ed into dwStrType to only allow
  7087. //  "\r" or "\n" as the RDN separator.
  7088. //
  7089. //  CERT_NAME_STR_NO_PLUS_FLAG can be or'ed into dwStrType to ignore "+"
  7090. //  as a separator and not allow multiple values per RDN.
  7091. //
  7092. //  CERT_NAME_STR_NO_QUOTING_FLAG can be or'ed into dwStrType to inhibit
  7093. //  quoting.
  7094. //
  7095. //  Support the following X500 Keys:
  7096. //
  7097. //  Key         Object Identifier               RDN Value Type(s)
  7098. //  ---         -----------------               -----------------
  7099. //  CN          szOID_COMMON_NAME               Printable, T61
  7100. //  L           szOID_LOCALITY_NAME             Printable, T61
  7101. //  O           szOID_ORGANIZATION_NAME         Printable, T61
  7102. //  OU          szOID_ORGANIZATIONAL_UNIT_NAME  Printable, T61
  7103. //  Email       szOID_RSA_emailAddr             Only IA5
  7104. //  C           szOID_COUNTRY_NAME              Only Printable
  7105. //  S           szOID_STATE_OR_PROVINCE_NAME    Printable, T61
  7106. //  ST          szOID_STATE_OR_PROVINCE_NAME    Printable, T61
  7107. //  STREET      szOID_STREET_ADDRESS            Printable, T61
  7108. //  T           szOID_TITLE                     Printable, T61
  7109. //  Title       szOID_TITLE                     Printable, T61
  7110. //  G           szOID_GIVEN_NAME                Printable, T61
  7111. //  GivenName   szOID_GIVEN_NAME                Printable, T61
  7112. //  I           szOID_INITIALS                  Printable, T61
  7113. //  Initials    szOID_INITIALS                  Printable, T61
  7114. //  SN          szOID_SUR_NAME                  Printable, T61
  7115. //  DC          szOID_DOMAIN_COMPONENT          Only IA5
  7116. //
  7117. //  The T61 types are UTF-8 encoded.
  7118. //
  7119. //  Returns TRUE if successfully parsed the input string and encoded
  7120. //  the name.
  7121. //
  7122. //  If the input string is detected to be invalid, *ppszError is updated
  7123. //  to point to the beginning of the invalid character sequence. Otherwise,
  7124. //  *ppszError is set to NULL. *ppszError is updated with a non-NULL pointer
  7125. //  for the following errors:
  7126. //      CRYPT_E_INVALID_X500_STRING
  7127. //      CRYPT_E_INVALID_NUMERIC_STRING
  7128. //      CRYPT_E_INVALID_PRINTABLE_STRING
  7129. //      CRYPT_E_INVALID_IA5_STRING
  7130. //
  7131. //  ppszError can be set to NULL if not interested in getting a pointer
  7132. //  to the invalid character sequence.
  7133. //--------------------------------------------------------------------------
  7134.  
  7135. //+-------------------------------------------------------------------------
  7136. //--------------------------------------------------------------------------
  7137. WINCRYPT32API
  7138. BOOL
  7139. WINAPI
  7140. CertStrToNameA(
  7141.     IN DWORD dwCertEncodingType,
  7142.     IN LPCSTR pszX500,
  7143.     IN DWORD dwStrType,
  7144.     IN OPTIONAL void *pvReserved,
  7145.     OUT BYTE *pbEncoded,
  7146.     IN OUT DWORD *pcbEncoded,
  7147.     OUT OPTIONAL LPCSTR *ppszError
  7148.     );
  7149. //+-------------------------------------------------------------------------
  7150. //--------------------------------------------------------------------------
  7151. WINCRYPT32API
  7152. BOOL
  7153. WINAPI
  7154. CertStrToNameW(
  7155.     IN DWORD dwCertEncodingType,
  7156.     IN LPCWSTR pszX500,
  7157.     IN DWORD dwStrType,
  7158.     IN OPTIONAL void *pvReserved,
  7159.     OUT BYTE *pbEncoded,
  7160.     IN OUT DWORD *pcbEncoded,
  7161.     OUT OPTIONAL LPCWSTR *ppszError
  7162.     );
  7163. #ifdef UNICODE
  7164. #define CertStrToName  CertStrToNameW
  7165. #else
  7166. #define CertStrToName  CertStrToNameA
  7167. #endif // !UNICODE
  7168.  
  7169.  
  7170. //+=========================================================================
  7171. //  Simplified Cryptographic Message Data Structures and APIs
  7172. //==========================================================================
  7173.  
  7174.  
  7175. //+-------------------------------------------------------------------------
  7176. //              Conventions for the *pb and *pcb output parameters:
  7177. //
  7178. //              Upon entry to the function:
  7179. //                  if pcb is OPTIONAL && pcb == NULL, then,
  7180. //                      No output is returned
  7181. //                  else if pb == NULL && pcb != NULL, then,
  7182. //                      Length only determination. No length error is
  7183. //                      returned.
  7184. //                  otherwise where (pb != NULL && pcb != NULL && *pcb != 0)
  7185. //                      Output is returned. If *pcb isn't big enough a
  7186. //                      length error is returned. In all cases *pcb is updated
  7187. //                      with the actual length needed/returned.
  7188. //--------------------------------------------------------------------------
  7189.  
  7190.  
  7191. //+-------------------------------------------------------------------------
  7192. //  Type definitions of the parameters used for doing the cryptographic
  7193. //  operations.
  7194. //--------------------------------------------------------------------------
  7195.  
  7196. //+-------------------------------------------------------------------------
  7197. //  Callback to get and verify the signer's certificate.
  7198. //
  7199. //  Passed the CertId of the signer (its Issuer and SerialNumber) and a
  7200. //  handle to its cryptographic signed message's cert store.
  7201. //
  7202. //  For CRYPT_E_NO_SIGNER, called with pSignerId == NULL.
  7203. //
  7204. //  For a valid signer certificate, returns a pointer to a read only
  7205. //  CERT_CONTEXT. The returned CERT_CONTEXT is either obtained from a
  7206. //  cert store or was created via CertCreateCertificateContext. For either case,
  7207. //  its freed via CertFreeCertificateContext.
  7208. //
  7209. //  If a valid certificate isn't found, this callback returns NULL with
  7210. //  LastError set via SetLastError().
  7211. //
  7212. //  The NULL implementation tries to get the Signer certificate from the
  7213. //  message cert store. It doesn't verify the certificate.
  7214. //--------------------------------------------------------------------------
  7215. typedef PCCERT_CONTEXT (WINAPI *PFN_CRYPT_GET_SIGNER_CERTIFICATE)(
  7216.             IN void *pvGetArg,
  7217.             IN DWORD dwCertEncodingType,
  7218.             IN PCERT_INFO pSignerId,    // Only the Issuer and SerialNumber
  7219.                                         // fields have been updated
  7220.             IN HCERTSTORE hMsgCertStore
  7221.             );
  7222.  
  7223. //+-------------------------------------------------------------------------
  7224. //  The CRYPT_SIGN_MESSAGE_PARA are used for signing messages using the
  7225. //  specified signing certificate contexts. (Note, allows multiple signers.)
  7226. //
  7227. //  Either the CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_PROV_INFO_PROP_ID must
  7228. //  be set for each rgpSigningCert[]. Either one specifies the private
  7229. //  signature key to use.
  7230. //
  7231. //  If any certificates and/or CRLs are to be included in the signed message,
  7232. //  then, the MsgCert and MsgCrl parameters need to be updated. If the
  7233. //  rgpSigningCerts are to be included, then, they must also be in the
  7234. //  rgpMsgCert array.
  7235. //
  7236. //  cbSize must be set to the sizeof(CRYPT_SIGN_MESSAGE_PARA) or else
  7237. //  LastError will be updated with E_INVALIDARG.
  7238. //
  7239. //  pvHashAuxInfo currently isn't used and must be set to NULL.
  7240. //
  7241. //  dwFlags normally is set to 0. However, if the encoded output
  7242. //  is to be a CMSG_SIGNED inner content of an outer cryptographic message,
  7243. //  such as a CMSG_ENVELOPED, then, the CRYPT_MESSAGE_BARE_CONTENT_OUT_FLAG
  7244. //  should be set. If not set, then it would be encoded as an inner content
  7245. //  type of CMSG_DATA.
  7246. //
  7247. //  dwInnerContentType is normally set to 0. It needs to be set if the
  7248. //  ToBeSigned input is the encoded output of another cryptographic
  7249. //  message, such as, an CMSG_ENVELOPED. When set, it's one of the cryptographic
  7250. //  message types, for example, CMSG_ENVELOPED.
  7251. //
  7252. //  If the inner content of a nested cryptographic message is data (CMSG_DATA
  7253. //  the default), then, neither dwFlags or dwInnerContentType need to be set.
  7254. //--------------------------------------------------------------------------
  7255. typedef struct _CRYPT_SIGN_MESSAGE_PARA {
  7256.     DWORD                       cbSize;
  7257.     DWORD                       dwMsgEncodingType;
  7258.     PCCERT_CONTEXT              pSigningCert;
  7259.     CRYPT_ALGORITHM_IDENTIFIER  HashAlgorithm;
  7260.     void                        *pvHashAuxInfo;
  7261.     DWORD                       cMsgCert;
  7262.     PCCERT_CONTEXT              *rgpMsgCert;
  7263.     DWORD                       cMsgCrl;
  7264.     PCCRL_CONTEXT               *rgpMsgCrl;
  7265.     DWORD                       cAuthAttr;
  7266.     PCRYPT_ATTRIBUTE            rgAuthAttr;
  7267.     DWORD                       cUnauthAttr;
  7268.     PCRYPT_ATTRIBUTE            rgUnauthAttr;
  7269.     DWORD                       dwFlags;
  7270.     DWORD                       dwInnerContentType;
  7271. } CRYPT_SIGN_MESSAGE_PARA, *PCRYPT_SIGN_MESSAGE_PARA;
  7272.  
  7273. #define CRYPT_MESSAGE_BARE_CONTENT_OUT_FLAG     0x1
  7274.  
  7275. //+-------------------------------------------------------------------------
  7276. //  The CRYPT_VERIFY_MESSAGE_PARA are used to verify signed messages.
  7277. //
  7278. //  hCryptProv is used to do hashing and signature verification.
  7279. //
  7280. //  The dwCertEncodingType specifies the encoding type of the certificates
  7281. //  and/or CRLs in the message.
  7282. //
  7283. //  pfnGetSignerCertificate is called to get and verify the message signer's
  7284. //  certificate.
  7285. //
  7286. //  cbSize must be set to the sizeof(CRYPT_VERIFY_MESSAGE_PARA) or else
  7287. //  LastError will be updated with E_INVALIDARG.
  7288. //--------------------------------------------------------------------------
  7289. typedef struct _CRYPT_VERIFY_MESSAGE_PARA {
  7290.     DWORD                               cbSize;
  7291.     DWORD                               dwMsgAndCertEncodingType;
  7292.     HCRYPTPROV                          hCryptProv;
  7293.     PFN_CRYPT_GET_SIGNER_CERTIFICATE    pfnGetSignerCertificate;
  7294.     void                                *pvGetArg;
  7295. } CRYPT_VERIFY_MESSAGE_PARA, *PCRYPT_VERIFY_MESSAGE_PARA;
  7296.  
  7297. //+-------------------------------------------------------------------------
  7298. //  The CRYPT_ENCRYPT_MESSAGE_PARA are used for encrypting messages.
  7299. //
  7300. //  hCryptProv is used to do content encryption, recipient key
  7301. //  encryption, and recipient key export. Its private key
  7302. //  isn't used.
  7303. //
  7304. //  pvEncryptionAuxInfo currently isn't used and must be set to NULL.
  7305. //
  7306. //  cbSize must be set to the sizeof(CRYPT_ENCRYPT_MESSAGE_PARA) or else
  7307. //  LastError will be updated with E_INVALIDARG.
  7308. //
  7309. //  dwFlags normally is set to 0. However, if the encoded output
  7310. //  is to be a CMSG_ENVELOPED inner content of an outer cryptographic message,
  7311. //  such as a CMSG_SIGNED, then, the CRYPT_MESSAGE_BARE_CONTENT_OUT_FLAG
  7312. //  should be set. If not set, then it would be encoded as an inner content
  7313. //  type of CMSG_DATA.
  7314. //
  7315. //  dwInnerContentType is normally set to 0. It needs to be set if the
  7316. //  ToBeEncrypted input is the encoded output of another cryptographic
  7317. //  message, such as, an CMSG_SIGNED. When set, it's one of the cryptographic
  7318. //  message types, for example, CMSG_SIGNED.
  7319. //
  7320. //  If the inner content of a nested cryptographic message is data (CMSG_DATA
  7321. //  the default), then, neither dwFlags or dwInnerContentType need to be set.
  7322. //--------------------------------------------------------------------------
  7323. typedef struct _CRYPT_ENCRYPT_MESSAGE_PARA {
  7324.     DWORD                       cbSize;
  7325.     DWORD                       dwMsgEncodingType;
  7326.     HCRYPTPROV                  hCryptProv;
  7327.     CRYPT_ALGORITHM_IDENTIFIER  ContentEncryptionAlgorithm;
  7328.     void                        *pvEncryptionAuxInfo;
  7329.     DWORD                       dwFlags;
  7330.     DWORD                       dwInnerContentType;
  7331. } CRYPT_ENCRYPT_MESSAGE_PARA, *PCRYPT_ENCRYPT_MESSAGE_PARA;
  7332.  
  7333. //+-------------------------------------------------------------------------
  7334. //  The CRYPT_DECRYPT_MESSAGE_PARA are used for decrypting messages.
  7335. //
  7336. //  The CertContext to use for decrypting a message is obtained from one
  7337. //  of the specified cert stores. An encrypted message can have one or
  7338. //  more recipients. The recipients are identified by their CertId (Issuer
  7339. //  and SerialNumber). The cert stores are searched to find the CertContext
  7340. //  corresponding to the CertId.
  7341. //
  7342. //  Only CertContexts in the store with either
  7343. //  the CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_PROV_INFO_PROP_ID set
  7344. //  can be used. Either property specifies the private exchange key to use.
  7345. //
  7346. //  cbSize must be set to the sizeof(CRYPT_DECRYPT_MESSAGE_PARA) or else
  7347. //  LastError will be updated with E_INVALIDARG.
  7348. //--------------------------------------------------------------------------
  7349. typedef struct _CRYPT_DECRYPT_MESSAGE_PARA {
  7350.     DWORD                   cbSize;
  7351.     DWORD                   dwMsgAndCertEncodingType;
  7352.     DWORD                   cCertStore;
  7353.     HCERTSTORE              *rghCertStore;
  7354. } CRYPT_DECRYPT_MESSAGE_PARA, *PCRYPT_DECRYPT_MESSAGE_PARA;
  7355.  
  7356. //+-------------------------------------------------------------------------
  7357. //  The CRYPT_HASH_MESSAGE_PARA are used for hashing or unhashing
  7358. //  messages.
  7359. //
  7360. //  hCryptProv is used to compute the hash.
  7361. //
  7362. //  pvHashAuxInfo currently isn't used and must be set to NULL.
  7363. //
  7364. //  cbSize must be set to the sizeof(CRYPT_HASH_MESSAGE_PARA) or else
  7365. //  LastError will be updated with E_INVALIDARG.
  7366. //--------------------------------------------------------------------------
  7367. typedef struct _CRYPT_HASH_MESSAGE_PARA {
  7368.     DWORD                       cbSize;
  7369.     DWORD                       dwMsgEncodingType;
  7370.     HCRYPTPROV                  hCryptProv;
  7371.     CRYPT_ALGORITHM_IDENTIFIER  HashAlgorithm;
  7372.     void                        *pvHashAuxInfo;
  7373. } CRYPT_HASH_MESSAGE_PARA, *PCRYPT_HASH_MESSAGE_PARA;
  7374.  
  7375.  
  7376.  
  7377. //+-------------------------------------------------------------------------
  7378. //  The CRYPT_KEY_SIGN_MESSAGE_PARA are used for signing messages until a
  7379. //  certificate has been created for the signature key.
  7380. //
  7381. //  pvHashAuxInfo currently isn't used and must be set to NULL.
  7382. //
  7383. //  If PubKeyAlgorithm isn't set, defaults to szOID_RSA_RSA.
  7384. //
  7385. //  cbSize must be set to the sizeof(CRYPT_KEY_SIGN_MESSAGE_PARA) or else
  7386. //  LastError will be updated with E_INVALIDARG.
  7387. //--------------------------------------------------------------------------
  7388. typedef struct _CRYPT_KEY_SIGN_MESSAGE_PARA {
  7389.     DWORD                       cbSize;
  7390.     DWORD                       dwMsgAndCertEncodingType;
  7391.     HCRYPTPROV                  hCryptProv;
  7392.     DWORD                       dwKeySpec;
  7393.     CRYPT_ALGORITHM_IDENTIFIER  HashAlgorithm;
  7394.     void                        *pvHashAuxInfo;
  7395.     CRYPT_ALGORITHM_IDENTIFIER  PubKeyAlgorithm;
  7396. } CRYPT_KEY_SIGN_MESSAGE_PARA, *PCRYPT_KEY_SIGN_MESSAGE_PARA;
  7397.  
  7398. //+-------------------------------------------------------------------------
  7399. //  The CRYPT_KEY_VERIFY_MESSAGE_PARA are used to verify signed messages without
  7400. //  a certificate for the signer.
  7401. //
  7402. //  Normally used until a certificate has been created for the key.
  7403. //
  7404. //  hCryptProv is used to do hashing and signature verification.
  7405. //
  7406. //  cbSize must be set to the sizeof(CRYPT_KEY_VERIFY_MESSAGE_PARA) or else
  7407. //  LastError will be updated with E_INVALIDARG.
  7408. //--------------------------------------------------------------------------
  7409. typedef struct _CRYPT_KEY_VERIFY_MESSAGE_PARA {
  7410.     DWORD                   cbSize;
  7411.     DWORD                   dwMsgEncodingType;
  7412.     HCRYPTPROV              hCryptProv;
  7413. } CRYPT_KEY_VERIFY_MESSAGE_PARA, *PCRYPT_KEY_VERIFY_MESSAGE_PARA;
  7414.  
  7415.  
  7416. //+-------------------------------------------------------------------------
  7417. //  Sign the message.
  7418. //
  7419. //  If fDetachedSignature is TRUE, the "to be signed" content isn't included
  7420. //  in the encoded signed blob.
  7421. //--------------------------------------------------------------------------
  7422. WINCRYPT32API
  7423. BOOL
  7424. WINAPI
  7425. CryptSignMessage(
  7426.     IN PCRYPT_SIGN_MESSAGE_PARA pSignPara,
  7427.     IN BOOL fDetachedSignature,
  7428.     IN DWORD cToBeSigned,
  7429.     IN const BYTE *rgpbToBeSigned[],
  7430.     IN DWORD rgcbToBeSigned[],
  7431.     OUT BYTE *pbSignedBlob,
  7432.     IN OUT DWORD *pcbSignedBlob
  7433.     );
  7434.  
  7435. //+-------------------------------------------------------------------------
  7436. //  Verify a signed message.
  7437. //
  7438. //  If pbDecoded == NULL, then, *pcbDecoded is implicitly set to 0 on input.
  7439. //  For *pcbDecoded == 0 && ppSignerCert == NULL on input, the signer isn't
  7440. //  verified.
  7441. //
  7442. //  A message might have more than one signer. Set dwSignerIndex to iterate
  7443. //  through all the signers. dwSignerIndex == 0 selects the first signer.
  7444. //
  7445. //  pVerifyPara's pfnGetSignerCertificate is called to get the signer's
  7446. //  certificate.
  7447. //
  7448. //  For a verified signer and message, *ppSignerCert is updated
  7449. //  with the CertContext of the signer. It must be freed by calling
  7450. //  CertFreeCertificateContext. Otherwise, *ppSignerCert is set to NULL.
  7451. //
  7452. //  ppSignerCert can be NULL, indicating the caller isn't interested
  7453. //  in getting the CertContext of the signer.
  7454. //
  7455. //  pcbDecoded can be NULL, indicating the caller isn't interested in getting
  7456. //  the decoded content. Furthermore, if the message doesn't contain any
  7457. //  content or signers, then, pcbDecoded must be set to NULL, to allow the
  7458. //  pVerifyPara->pfnGetCertificate to be called. Normally, this would be
  7459. //  the case when the signed message contains only certficates and CRLs.
  7460. //  If pcbDecoded is NULL and the message doesn't have the indicated signer,
  7461. //  pfnGetCertificate is called with pSignerId set to NULL.
  7462. //
  7463. //  If the message doesn't contain any signers || dwSignerIndex > message's
  7464. //  SignerCount, then, an error is returned with LastError set to
  7465. //  CRYPT_E_NO_SIGNER. Also, for CRYPT_E_NO_SIGNER, pfnGetSignerCertificate
  7466. //  is still called with pSignerId set to NULL.
  7467. //
  7468. //  Note, an alternative way to get the certificates and CRLs from a
  7469. //  signed message is to call CryptGetMessageCertificates.
  7470. //--------------------------------------------------------------------------
  7471. WINCRYPT32API
  7472. BOOL
  7473. WINAPI
  7474. CryptVerifyMessageSignature(
  7475.     IN PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara,
  7476.     IN DWORD dwSignerIndex,
  7477.     IN const BYTE *pbSignedBlob,
  7478.     IN DWORD cbSignedBlob,
  7479.     OUT BYTE OPTIONAL *pbDecoded,
  7480.     IN OUT OPTIONAL DWORD *pcbDecoded,
  7481.     OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert
  7482.     );
  7483.  
  7484. //+-------------------------------------------------------------------------
  7485. //  Returns the count of signers in the signed message. For no signers, returns
  7486. //  0. For an error returns -1 with LastError updated accordingly.
  7487. //--------------------------------------------------------------------------
  7488. WINCRYPT32API
  7489. LONG
  7490. WINAPI
  7491. CryptGetMessageSignerCount(
  7492.     IN DWORD dwMsgEncodingType,
  7493.     IN const BYTE *pbSignedBlob,
  7494.     IN DWORD cbSignedBlob
  7495.     );
  7496.  
  7497. //+-------------------------------------------------------------------------
  7498. //  Returns the cert store containing the message's certs and CRLs.
  7499. //  For an error, returns NULL with LastError updated.
  7500. //--------------------------------------------------------------------------
  7501. WINCRYPT32API
  7502. HCERTSTORE
  7503. WINAPI
  7504. CryptGetMessageCertificates(
  7505.     IN DWORD dwMsgAndCertEncodingType,
  7506.     IN HCRYPTPROV hCryptProv,           // passed to CertOpenStore
  7507.     IN DWORD dwFlags,                   // passed to CertOpenStore
  7508.     IN const BYTE *pbSignedBlob,
  7509.     IN DWORD cbSignedBlob
  7510.     );
  7511.  
  7512. //+-------------------------------------------------------------------------
  7513. //  Verify a signed message containing detached signature(s).
  7514. //  The "to be signed" content is passed in separately. No
  7515. //  decoded output. Otherwise, identical to CryptVerifyMessageSignature.
  7516. //--------------------------------------------------------------------------
  7517. WINCRYPT32API
  7518. BOOL
  7519. WINAPI
  7520. CryptVerifyDetachedMessageSignature(
  7521.     IN PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara,
  7522.     IN DWORD dwSignerIndex,
  7523.     IN const BYTE *pbDetachedSignBlob,
  7524.     IN DWORD cbDetachedSignBlob,
  7525.     IN DWORD cToBeSigned,
  7526.     IN const BYTE *rgpbToBeSigned[],
  7527.     IN DWORD rgcbToBeSigned[],
  7528.     OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert
  7529.     );
  7530.  
  7531. //+-------------------------------------------------------------------------
  7532. //  Encrypts the message for the recipient(s).
  7533. //--------------------------------------------------------------------------
  7534. WINCRYPT32API
  7535. BOOL
  7536. WINAPI
  7537. CryptEncryptMessage(
  7538.     IN PCRYPT_ENCRYPT_MESSAGE_PARA pEncryptPara,
  7539.     IN DWORD cRecipientCert,
  7540.     IN PCCERT_CONTEXT rgpRecipientCert[],
  7541.     IN const BYTE *pbToBeEncrypted,
  7542.     IN DWORD cbToBeEncrypted,
  7543.     OUT BYTE *pbEncryptedBlob,
  7544.     IN OUT DWORD *pcbEncryptedBlob
  7545.     );
  7546.  
  7547. //+-------------------------------------------------------------------------
  7548. //  Decrypts the message.
  7549. //
  7550. //  If pbDecrypted == NULL, then, *pcbDecrypted is implicitly set to 0 on input.
  7551. //  For *pcbDecrypted == 0 && ppXchgCert == NULL on input, the message isn't
  7552. //  decrypted.
  7553. //
  7554. //  For a successfully decrypted message, *ppXchgCert is updated
  7555. //  with the CertContext used to decrypt. It must be freed by calling
  7556. //  CertStoreFreeCert. Otherwise, *ppXchgCert is set to NULL.
  7557. //
  7558. //  ppXchgCert can be NULL, indicating the caller isn't interested
  7559. //  in getting the CertContext used to decrypt.
  7560. //--------------------------------------------------------------------------
  7561. WINCRYPT32API
  7562. BOOL
  7563. WINAPI
  7564. CryptDecryptMessage(
  7565.     IN PCRYPT_DECRYPT_MESSAGE_PARA pDecryptPara,
  7566.     IN const BYTE *pbEncryptedBlob,
  7567.     IN DWORD cbEncryptedBlob,
  7568.     OUT OPTIONAL BYTE *pbDecrypted,
  7569.     IN OUT OPTIONAL DWORD *pcbDecrypted,
  7570.     OUT OPTIONAL PCCERT_CONTEXT *ppXchgCert
  7571.     );
  7572.  
  7573. //+-------------------------------------------------------------------------
  7574. //  Sign the message and encrypt for the recipient(s). Does a CryptSignMessage
  7575. //  followed with a CryptEncryptMessage.
  7576. //
  7577. //  Note: this isn't the CMSG_SIGNED_AND_ENVELOPED. Its a CMSG_SIGNED
  7578. //  inside of an CMSG_ENVELOPED.
  7579. //--------------------------------------------------------------------------
  7580. WINCRYPT32API
  7581. BOOL
  7582. WINAPI
  7583. CryptSignAndEncryptMessage(
  7584.     IN PCRYPT_SIGN_MESSAGE_PARA pSignPara,
  7585.     IN PCRYPT_ENCRYPT_MESSAGE_PARA pEncryptPara,
  7586.     IN DWORD cRecipientCert,
  7587.     IN PCCERT_CONTEXT rgpRecipientCert[],
  7588.     IN const BYTE *pbToBeSignedAndEncrypted,
  7589.     IN DWORD cbToBeSignedAndEncrypted,
  7590.     OUT BYTE *pbSignedAndEncryptedBlob,
  7591.     IN OUT DWORD *pcbSignedAndEncryptedBlob
  7592.     );
  7593.  
  7594. //+-------------------------------------------------------------------------
  7595. //  Decrypts the message and verifies the signer. Does a CryptDecryptMessage
  7596. //  followed with a CryptVerifyMessageSignature.
  7597. //
  7598. //  If pbDecrypted == NULL, then, *pcbDecrypted is implicitly set to 0 on input.
  7599. //  For *pcbDecrypted == 0 && ppSignerCert == NULL on input, the signer isn't
  7600. //  verified.
  7601. //
  7602. //  A message might have more than one signer. Set dwSignerIndex to iterate
  7603. //  through all the signers. dwSignerIndex == 0 selects the first signer.
  7604. //
  7605. //  The pVerifyPara's VerifySignerPolicy is called to verify the signer's
  7606. //  certificate.
  7607. //
  7608. //  For a successfully decrypted and verified message, *ppXchgCert and
  7609. //  *ppSignerCert are updated. They must be freed by calling
  7610. //  CertStoreFreeCert. Otherwise, they are set to NULL.
  7611. //
  7612. //  ppXchgCert and/or ppSignerCert can be NULL, indicating the
  7613. //  caller isn't interested in getting the CertContext.
  7614. //
  7615. //  Note: this isn't the CMSG_SIGNED_AND_ENVELOPED. Its a CMSG_SIGNED
  7616. //  inside of an CMSG_ENVELOPED.
  7617. //
  7618. //  The message always needs to be decrypted to allow access to the
  7619. //  signed message. Therefore, if ppXchgCert != NULL, its always updated.
  7620. //--------------------------------------------------------------------------
  7621. WINCRYPT32API
  7622. BOOL
  7623. WINAPI
  7624. CryptDecryptAndVerifyMessageSignature(
  7625.     IN PCRYPT_DECRYPT_MESSAGE_PARA pDecryptPara,
  7626.     IN PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara,
  7627.     IN DWORD dwSignerIndex,
  7628.     IN const BYTE *pbEncryptedBlob,
  7629.     IN DWORD cbEncryptedBlob,
  7630.     OUT OPTIONAL BYTE *pbDecrypted,
  7631.     IN OUT OPTIONAL DWORD *pcbDecrypted,
  7632.     OUT OPTIONAL PCCERT_CONTEXT *ppXchgCert,
  7633.     OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert
  7634.     );
  7635.  
  7636. //+-------------------------------------------------------------------------
  7637. //  Decodes a cryptographic message which may be one of the following types:
  7638. //    CMSG_DATA
  7639. //    CMSG_SIGNED
  7640. //    CMSG_ENVELOPED
  7641. //    CMSG_SIGNED_AND_ENVELOPED
  7642. //    CMSG_HASHED
  7643. //
  7644. //  dwMsgTypeFlags specifies the set of allowable messages. For example, to
  7645. //  decode either SIGNED or ENVELOPED messages, set dwMsgTypeFlags to:
  7646. //      CMSG_SIGNED_FLAG | CMSG_ENVELOPED_FLAG.
  7647. //
  7648. //  dwProvInnerContentType is only applicable when processing nested
  7649. //  crytographic messages. When processing an outer crytographic message
  7650. //  it must be set to 0. When decoding a nested cryptographic message
  7651. //  its the dwInnerContentType returned by a previous CryptDecodeMessage
  7652. //  of the outer message. The InnerContentType can be any of the CMSG types,
  7653. //  for example, CMSG_DATA, CMSG_SIGNED, ...
  7654. //
  7655. //  The optional *pdwMsgType is updated with the type of message.
  7656. //
  7657. //  The optional *pdwInnerContentType is updated with the type of the inner
  7658. //  message. Unless there is cryptographic message nesting, CMSG_DATA
  7659. //  is returned.
  7660. //
  7661. //  For CMSG_DATA: returns decoded content.
  7662. //  For CMSG_SIGNED: same as CryptVerifyMessageSignature.
  7663. //  For CMSG_ENVELOPED: same as CryptDecryptMessage.
  7664. //  For CMSG_SIGNED_AND_ENVELOPED: same as CryptDecryptMessage plus
  7665. //      CryptVerifyMessageSignature.
  7666. //  For CMSG_HASHED: verifies the hash and returns decoded content.
  7667. //--------------------------------------------------------------------------
  7668. WINCRYPT32API
  7669. BOOL
  7670. WINAPI
  7671. CryptDecodeMessage(
  7672.     IN DWORD dwMsgTypeFlags,
  7673.     IN PCRYPT_DECRYPT_MESSAGE_PARA pDecryptPara,
  7674.     IN PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara,
  7675.     IN DWORD dwSignerIndex,
  7676.     IN const BYTE *pbEncodedBlob,
  7677.     IN DWORD cbEncodedBlob,
  7678.     IN DWORD dwPrevInnerContentType,
  7679.     OUT OPTIONAL DWORD *pdwMsgType,
  7680.     OUT OPTIONAL DWORD *pdwInnerContentType,
  7681.     OUT OPTIONAL BYTE *pbDecoded,
  7682.     IN OUT OPTIONAL DWORD *pcbDecoded,
  7683.     OUT OPTIONAL PCCERT_CONTEXT *ppXchgCert,
  7684.     OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert
  7685.     );
  7686.  
  7687. //+-------------------------------------------------------------------------
  7688. //  Hash the message.
  7689. //
  7690. //  If fDetachedHash is TRUE, only the ComputedHash is encoded in the
  7691. //  pbHashedBlob. Otherwise, both the ToBeHashed and ComputedHash
  7692. //  are encoded.
  7693. //
  7694. //  pcbHashedBlob or pcbComputedHash can be NULL, indicating the caller
  7695. //  isn't interested in getting the output.
  7696. //--------------------------------------------------------------------------
  7697. WINCRYPT32API
  7698. BOOL
  7699. WINAPI
  7700. CryptHashMessage(
  7701.     IN PCRYPT_HASH_MESSAGE_PARA pHashPara,
  7702.     IN BOOL fDetachedHash,
  7703.     IN DWORD cToBeHashed,
  7704.     IN const BYTE *rgpbToBeHashed[],
  7705.     IN DWORD rgcbToBeHashed[],
  7706.     OUT OPTIONAL BYTE *pbHashedBlob,
  7707.     IN OUT OPTIONAL DWORD *pcbHashedBlob,
  7708.     OUT OPTIONAL BYTE *pbComputedHash,
  7709.     IN OUT OPTIONAL DWORD *pcbComputedHash
  7710.     );
  7711.  
  7712. //+-------------------------------------------------------------------------
  7713. //  Verify a hashed message.
  7714. //
  7715. //  pcbToBeHashed or pcbComputedHash can be NULL,
  7716. //  indicating the caller isn't interested in getting the output.
  7717. //--------------------------------------------------------------------------
  7718. WINCRYPT32API
  7719. BOOL
  7720. WINAPI
  7721. CryptVerifyMessageHash(
  7722.     IN PCRYPT_HASH_MESSAGE_PARA pHashPara,
  7723.     IN BYTE *pbHashedBlob,
  7724.     IN DWORD cbHashedBlob,
  7725.     OUT OPTIONAL BYTE *pbToBeHashed,
  7726.     IN OUT OPTIONAL DWORD *pcbToBeHashed,
  7727.     OUT OPTIONAL BYTE *pbComputedHash,
  7728.     IN OUT OPTIONAL DWORD *pcbComputedHash
  7729.     );
  7730.  
  7731. //+-------------------------------------------------------------------------
  7732. //  Verify a hashed message containing a detached hash.
  7733. //  The "to be hashed" content is passed in separately. No
  7734. //  decoded output. Otherwise, identical to CryptVerifyMessageHash.
  7735. //
  7736. //  pcbComputedHash can be NULL, indicating the caller isn't interested
  7737. //  in getting the output.
  7738. //--------------------------------------------------------------------------
  7739. WINCRYPT32API
  7740. BOOL
  7741. WINAPI
  7742. CryptVerifyDetachedMessageHash(
  7743.     IN PCRYPT_HASH_MESSAGE_PARA pHashPara,
  7744.     IN BYTE *pbDetachedHashBlob,
  7745.     IN DWORD cbDetachedHashBlob,
  7746.     IN DWORD cToBeHashed,
  7747.     IN const BYTE *rgpbToBeHashed[],
  7748.     IN DWORD rgcbToBeHashed[],
  7749.     OUT OPTIONAL BYTE *pbComputedHash,
  7750.     IN OUT OPTIONAL DWORD *pcbComputedHash
  7751.     );
  7752.  
  7753. //+-------------------------------------------------------------------------
  7754. //  Sign the message using the provider's private key specified in the
  7755. //  parameters. A dummy SignerId is created and stored in the message.
  7756. //
  7757. //  Normally used until a certificate has been created for the key.
  7758. //--------------------------------------------------------------------------
  7759. WINCRYPT32API
  7760. BOOL
  7761. WINAPI
  7762. CryptSignMessageWithKey(
  7763.     IN PCRYPT_KEY_SIGN_MESSAGE_PARA pSignPara,
  7764.     IN const BYTE *pbToBeSigned,
  7765.     IN DWORD cbToBeSigned,
  7766.     OUT BYTE *pbSignedBlob,
  7767.     IN OUT DWORD *pcbSignedBlob
  7768.     );
  7769.  
  7770. //+-------------------------------------------------------------------------
  7771. //  Verify a signed message using the specified public key info.
  7772. //
  7773. //  Normally called by a CA until it has created a certificate for the
  7774. //  key.
  7775. //
  7776. //  pPublicKeyInfo contains the public key to use to verify the signed
  7777. //  message. If NULL, the signature isn't verified (for instance, the decoded
  7778. //  content may contain the PublicKeyInfo).
  7779. //
  7780. //  pcbDecoded can be NULL, indicating the caller isn't interested
  7781. //  in getting the decoded content.
  7782. //--------------------------------------------------------------------------
  7783. WINCRYPT32API
  7784. BOOL
  7785. WINAPI
  7786. CryptVerifyMessageSignatureWithKey(
  7787.     IN PCRYPT_KEY_VERIFY_MESSAGE_PARA pVerifyPara,
  7788.     IN OPTIONAL PCERT_PUBLIC_KEY_INFO pPublicKeyInfo,
  7789.     IN const BYTE *pbSignedBlob,
  7790.     IN DWORD cbSignedBlob,
  7791.     OUT OPTIONAL BYTE *pbDecoded,
  7792.     IN OUT OPTIONAL DWORD *pcbDecoded
  7793.     );
  7794.  
  7795.  
  7796. //+=========================================================================
  7797. //  System Certificate Store Data Structures and APIs
  7798. //==========================================================================
  7799.  
  7800.  
  7801. //+-------------------------------------------------------------------------
  7802. //  Get a system certificate store based on a subsystem protocol.
  7803. //
  7804. //  Current examples of subsystems protocols are:
  7805. //      "MY"    Cert Store hold certs with associated Private Keys
  7806. //      "CA"    Certifying Authority certs
  7807. //      "ROOT"  Root Certs
  7808. //      "SPC"   Software publisher certs
  7809. //
  7810. //
  7811. //  If hProv is NULL the default provider "1" is opened for you.
  7812. //  When the store is closed the provider is release. Otherwise
  7813. //  if hProv is not NULL, no provider is created or released.
  7814. //
  7815. //  The returned Cert Store can be searched for an appropriate Cert
  7816. //  using the Cert Store API's (see certstor.h)
  7817. //
  7818. //  When done, the cert store should be closed using CertStoreClose
  7819. //--------------------------------------------------------------------------
  7820.  
  7821.  
  7822. WINCRYPT32API HCERTSTORE WINAPI CertOpenSystemStoreA(
  7823.     HCRYPTPROV      hProv,
  7824.     LPCSTR            szSubsystemProtocol
  7825.     );
  7826. WINCRYPT32API HCERTSTORE WINAPI CertOpenSystemStoreW(
  7827.     HCRYPTPROV      hProv,
  7828.     LPCWSTR            szSubsystemProtocol
  7829.     );
  7830. #ifdef UNICODE
  7831. #define CertOpenSystemStore  CertOpenSystemStoreW
  7832. #else
  7833. #define CertOpenSystemStore  CertOpenSystemStoreA
  7834. #endif // !UNICODE
  7835.  
  7836. WINCRYPT32API BOOL WINAPI CertAddEncodedCertificateToSystemStoreA(
  7837.     LPCSTR            szCertStoreName,
  7838.     const BYTE *    pbCertEncoded,
  7839.     DWORD           cbCertEncoded
  7840.     );
  7841. WINCRYPT32API BOOL WINAPI CertAddEncodedCertificateToSystemStoreW(
  7842.     LPCWSTR            szCertStoreName,
  7843.     const BYTE *    pbCertEncoded,
  7844.     DWORD           cbCertEncoded
  7845.     );
  7846. #ifdef UNICODE
  7847. #define CertAddEncodedCertificateToSystemStore  CertAddEncodedCertificateToSystemStoreW
  7848. #else
  7849. #define CertAddEncodedCertificateToSystemStore  CertAddEncodedCertificateToSystemStoreA
  7850. #endif // !UNICODE
  7851.  
  7852.  
  7853. //+-------------------------------------------------------------------------
  7854. //  Find all certificate chains tying the given issuer name to any certificate
  7855. //  that the current user has a private key for.
  7856. //
  7857. //  If no certificate chain is found, FALSE is returned with LastError set
  7858. //  to CRYPT_E_NOT_FOUND and the counts zeroed.
  7859. //
  7860. //  IE 3.0 ASSUMPTION:
  7861. //   The client certificates are in the "My" system store. The issuer
  7862. //   cerificates may be in the "Root", "CA" or "My" system stores.
  7863. //--------------------------------------------------------------------------
  7864. typedef struct _CERT_CHAIN {
  7865.     DWORD                   cCerts;     // number of certs in chain
  7866.     PCERT_BLOB              certs;      // pointer to array of cert chain blobs
  7867.                                         // representing the certs
  7868.     CRYPT_KEY_PROV_INFO     keyLocatorInfo; // key locator for cert
  7869. } CERT_CHAIN, *PCERT_CHAIN;
  7870.  
  7871.  
  7872. // WINCRYPT32API    This is not exported by crypt32, it is exported by softpub
  7873. HRESULT
  7874. WINAPI
  7875. FindCertsByIssuer(
  7876.     OUT PCERT_CHAIN pCertChains,
  7877.     IN OUT DWORD *pcbCertChains,
  7878.     OUT DWORD *pcCertChains,        // count of certificates chains returned
  7879.     IN BYTE* pbEncodedIssuerName,   // DER encoded issuer name
  7880.     IN DWORD cbEncodedIssuerName,   // count in bytes of encoded issuer name
  7881.     IN LPCWSTR pwszPurpose,         // "ClientAuth" or "CodeSigning"
  7882.     IN DWORD dwKeySpec              // only return signers supporting this
  7883.                                     // keyspec
  7884.     );
  7885.  
  7886. #ifdef __cplusplus
  7887. }       // Balance extern "C" above
  7888. #endif
  7889.  
  7890. #endif /* _WIN32_WINNT >= 0x0400 */
  7891.  
  7892.  
  7893. #endif // __WINCRYPT_H__
  7894.