/Source/Wcrypt2.pas

http://github.com/ghquant/Delphi-EmbeddedWB · Pascal · 7870 lines · 3058 code · 764 blank · 4048 comment · 1 complexity · 653dd10fe116261dfaf6237a676f060c MD5 · raw file

  1. {******************************************************************}
  2. { }
  3. { Borland Delphi Runtime Library }
  4. { Cryptographic API interface unit }
  5. { }
  6. { Portions created by Microsoft are }
  7. { Copyright (C) 1993-1998 Microsoft Corporation. }
  8. { All Rights Reserved. }
  9. { }
  10. { The original file is: wincrypt.h, 1992 - 1997 }
  11. { The original Pascal code is: wcrypt2.pas, released 01 Jan 1998 }
  12. { The initial developer of the Pascal code is }
  13. { Massimo Maria Ghisalberti (nissl@dada.it) }
  14. { }
  15. { Portions created by Massimo Maria Ghisalberti are }
  16. { Copyright (C) 1997-1998 Massimo Maria Ghisalberti }
  17. { }
  18. { Contributor(s): }
  19. { Peter Tang (peter.tang@citicorp.com) }
  20. { Phil Shrimpton (phil@shrimpton.co.uk) }
  21. { }
  22. { Obtained through: }
  23. { }
  24. { Joint Endeavour of Delphi Innovators (Project JEDI) }
  25. { }
  26. { You may retrieve the latest version of this file at the Project }
  27. { JEDI home page, located at http://delphi-jedi.org }
  28. { }
  29. { The contents of this file are used with permission, subject to }
  30. { the Mozilla Public License Version 1.1 (the "License"); you may }
  31. { not use this file except in compliance with the License. You may }
  32. { obtain a copy of the License at }
  33. { http://www.mozilla.org/MPL/MPL-1.1.html }
  34. { }
  35. { Software distributed under the License is distributed on an }
  36. { "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or }
  37. { implied. See the License for the specific language governing }
  38. { rights and limitations under the License. }
  39. { }
  40. {******************************************************************}
  41. //$Id: Wcrypt2.pas,v 1.2 2006/11/15 21:01:44 sergev Exp $
  42. unit wcrypt2;
  43. {.DEFINE NT5}
  44. {$ALIGN ON}
  45. {$IFNDEF VER90}
  46. {$WEAKPACKAGEUNIT}
  47. {$ENDIF}
  48. interface
  49. uses
  50. Windows
  51. {$IFDEF VER90}
  52. , Ole2
  53. {$ENDIF};
  54. const
  55. ADVAPI32 = 'advapi32.dll';
  56. CRYPT32 = 'crypt32.dll';
  57. SOFTPUB = 'softpub.dll';
  58. {$IFDEF NT5}
  59. ADVAPI32NT5 = 'advapi32.dll';
  60. {$ENDIF}
  61. {Support Type}
  62. type
  63. PVOID = Pointer;
  64. LONG = DWORD;
  65. {$IFDEF UNICODE}
  66. LPAWSTR = PWideChar;
  67. {$ELSE}
  68. LPAWSTR = PAnsiChar;
  69. {$ENDIF}
  70. //-----------------------------------------------------------------------------
  71. // Type support for a pointer to an array of pointer (type **name)
  72. PLPSTR = Pointer; // type for a pointer to Array of pointer a type
  73. PPCERT_INFO = Pointer; // type for a pointer to Array of pointer a type
  74. PPVOID = Pointer; // type for a pointer to Array of pointer a type
  75. PPCCERT_CONTEXT = Pointer; // type for a pointer to Array of pointer a type
  76. PPCCTL_CONTEXT = Pointer; // type for a pointer to Array of pointer a type
  77. PPCCRL_CONTEXT = Pointer; // type for a pointer to Array of pointer a type
  78. //-----------------------------------------------------------------------------
  79. //+---------------------------------------------------------------------------
  80. //
  81. // Microsoft Windows
  82. // Copyright (C) Microsoft Corporation, 1992 - 1997.
  83. //
  84. // File: wincrypt.h
  85. //
  86. // Contents: Cryptographic API Prototypes and Definitions
  87. //
  88. //----------------------------------------------------------------------------
  89. //
  90. // Algorithm IDs and Flags
  91. //
  92. // ALG_ID crackers
  93. function GET_ALG_CLASS(x: integer): integer;
  94. function GET_ALG_TYPE(x: integer): integer;
  95. function GET_ALG_SID(x: integer): integer;
  96. const
  97. // Algorithm classes
  98. ALG_CLASS_ANY = 0;
  99. ALG_CLASS_SIGNATURE = (1 shl 13);
  100. ALG_CLASS_MSG_ENCRYPT = (2 shl 13);
  101. ALG_CLASS_DATA_ENCRYPT = (3 shl 13);
  102. ALG_CLASS_HASH = (4 shl 13);
  103. ALG_CLASS_KEY_EXCHANGE = (5 shl 13);
  104. // Algorithm types
  105. ALG_TYPE_ANY = 0;
  106. ALG_TYPE_DSS = (1 shl 9);
  107. ALG_TYPE_RSA = (2 shl 9);
  108. ALG_TYPE_BLOCK = (3 shl 9);
  109. ALG_TYPE_STREAM = (4 shl 9);
  110. ALG_TYPE_DH = (5 shl 9);
  111. ALG_TYPE_SECURECHANNEL = (6 shl 9);
  112. // Generic sub-ids
  113. ALG_SID_ANY = 0;
  114. // Some RSA sub-ids
  115. ALG_SID_RSA_ANY = 0;
  116. ALG_SID_RSA_PKCS = 1;
  117. ALG_SID_RSA_MSATWORK = 2;
  118. ALG_SID_RSA_ENTRUST = 3;
  119. ALG_SID_RSA_PGP = 4;
  120. // Some DSS sub-ids
  121. ALG_SID_DSS_ANY = 0;
  122. ALG_SID_DSS_PKCS = 1;
  123. ALG_SID_DSS_DMS = 2;
  124. // Block cipher sub ids
  125. // DES sub_ids
  126. ALG_SID_DES = 1;
  127. ALG_SID_3DES = 3;
  128. ALG_SID_DESX = 4;
  129. ALG_SID_IDEA = 5;
  130. ALG_SID_CAST = 6;
  131. ALG_SID_SAFERSK64 = 7;
  132. ALD_SID_SAFERSK128 = 8;
  133. ALG_SID_SAFERSK128 = 8;
  134. ALG_SID_3DES_112 = 9;
  135. ALG_SID_CYLINK_MEK = 12;
  136. ALG_SID_RC5 = 13;
  137. // Fortezza sub-ids
  138. ALG_SID_SKIPJACK = 10;
  139. ALG_SID_TEK = 11;
  140. // KP_MODE
  141. CRYPT_MODE_CBCI = 6; {ANSI CBC Interleaved}
  142. CRYPT_MODE_CFBP = 7; {ANSI CFB Pipelined}
  143. CRYPT_MODE_OFBP = 8; {ANSI OFB Pipelined}
  144. CRYPT_MODE_CBCOFM = 9; {ANSI CBC + OF Masking}
  145. CRYPT_MODE_CBCOFMI = 10; {ANSI CBC + OFM Interleaved}
  146. // RC2 sub-ids
  147. ALG_SID_RC2 = 2;
  148. // Stream cipher sub-ids
  149. ALG_SID_RC4 = 1;
  150. ALG_SID_SEAL = 2;
  151. // Diffie-Hellman sub-ids
  152. ALG_SID_DH_SANDF = 1;
  153. ALG_SID_DH_EPHEM = 2;
  154. ALG_SID_AGREED_KEY_ANY = 3;
  155. ALG_SID_KEA = 4;
  156. // Hash sub ids
  157. ALG_SID_MD2 = 1;
  158. ALG_SID_MD4 = 2;
  159. ALG_SID_MD5 = 3;
  160. ALG_SID_SHA = 4;
  161. ALG_SID_SHA1 = 4;
  162. ALG_SID_MAC = 5;
  163. ALG_SID_RIPEMD = 6;
  164. ALG_SID_RIPEMD160 = 7;
  165. ALG_SID_SSL3SHAMD5 = 8;
  166. ALG_SID_HMAC = 9;
  167. // secure channel sub ids
  168. ALG_SID_SSL3_MASTER = 1;
  169. ALG_SID_SCHANNEL_MASTER_HASH = 2;
  170. ALG_SID_SCHANNEL_MAC_KEY = 3;
  171. ALG_SID_PCT1_MASTER = 4;
  172. ALG_SID_SSL2_MASTER = 5;
  173. ALG_SID_TLS1_MASTER = 6;
  174. ALG_SID_SCHANNEL_ENC_KEY = 7;
  175. // Our silly example sub-id
  176. ALG_SID_EXAMPLE = 80;
  177. {$IFNDEF ALGIDDEF}
  178. {$DEFINE ALGIDDEF}
  179. type ALG_ID = ULONG;
  180. {$ENDIF}
  181. // algorithm identifier definitions
  182. const
  183. CALG_MD2 = (ALG_CLASS_HASH or ALG_TYPE_ANY or ALG_SID_MD2);
  184. CALG_MD4 = (ALG_CLASS_HASH or ALG_TYPE_ANY or ALG_SID_MD4);
  185. CALG_MD5 = (ALG_CLASS_HASH or ALG_TYPE_ANY or ALG_SID_MD5);
  186. CALG_SHA = (ALG_CLASS_HASH or ALG_TYPE_ANY or ALG_SID_SHA);
  187. CALG_SHA1 = (ALG_CLASS_HASH or ALG_TYPE_ANY or ALG_SID_SHA1);
  188. CALG_MAC = (ALG_CLASS_HASH or ALG_TYPE_ANY or ALG_SID_MAC);
  189. CALG_RSA_SIGN = (ALG_CLASS_SIGNATURE or ALG_TYPE_RSA or ALG_SID_RSA_ANY);
  190. CALG_DSS_SIGN = (ALG_CLASS_SIGNATURE or ALG_TYPE_DSS or ALG_SID_DSS_ANY);
  191. CALG_RSA_KEYX = (ALG_CLASS_KEY_EXCHANGE or ALG_TYPE_RSA or ALG_SID_RSA_ANY);
  192. CALG_DES = (ALG_CLASS_DATA_ENCRYPT or ALG_TYPE_BLOCK or ALG_SID_DES);
  193. CALG_3DES_112 = (ALG_CLASS_DATA_ENCRYPT or ALG_TYPE_BLOCK or ALG_SID_3DES_112);
  194. CALG_3DES = (ALG_CLASS_DATA_ENCRYPT or ALG_TYPE_BLOCK or ALG_SID_3DES);
  195. CALG_RC2 = (ALG_CLASS_DATA_ENCRYPT or ALG_TYPE_BLOCK or ALG_SID_RC2);
  196. CALG_RC4 = (ALG_CLASS_DATA_ENCRYPT or ALG_TYPE_STREAM or ALG_SID_RC4);
  197. CALG_SEAL = (ALG_CLASS_DATA_ENCRYPT or ALG_TYPE_STREAM or ALG_SID_SEAL);
  198. CALG_DH_SF = (ALG_CLASS_KEY_EXCHANGE or ALG_TYPE_DH or ALG_SID_DH_SANDF);
  199. CALG_DH_EPHEM = (ALG_CLASS_KEY_EXCHANGE or ALG_TYPE_DH or ALG_SID_DH_EPHEM);
  200. CALG_AGREEDKEY_ANY = (ALG_CLASS_KEY_EXCHANGE or ALG_TYPE_DH or ALG_SID_AGREED_KEY_ANY);
  201. CALG_KEA_KEYX = (ALG_CLASS_KEY_EXCHANGE or ALG_TYPE_DH or ALG_SID_KEA);
  202. CALG_HUGHES_MD5 = (ALG_CLASS_KEY_EXCHANGE or ALG_TYPE_ANY or ALG_SID_MD5);
  203. CALG_SKIPJACK = (ALG_CLASS_DATA_ENCRYPT or ALG_TYPE_BLOCK or ALG_SID_SKIPJACK);
  204. CALG_TEK = (ALG_CLASS_DATA_ENCRYPT or ALG_TYPE_BLOCK or ALG_SID_TEK);
  205. CALG_CYLINK_MEK = (ALG_CLASS_DATA_ENCRYPT or ALG_TYPE_BLOCK or ALG_SID_CYLINK_MEK);
  206. CALG_SSL3_SHAMD5 = (ALG_CLASS_HASH or ALG_TYPE_ANY or ALG_SID_SSL3SHAMD5);
  207. CALG_SSL3_MASTER = (ALG_CLASS_MSG_ENCRYPT or ALG_TYPE_SECURECHANNEL or ALG_SID_SSL3_MASTER);
  208. CALG_SCHANNEL_MASTER_HASH = (ALG_CLASS_MSG_ENCRYPT or ALG_TYPE_SECURECHANNEL or ALG_SID_SCHANNEL_MASTER_HASH);
  209. CALG_SCHANNEL_MAC_KEY = (ALG_CLASS_MSG_ENCRYPT or ALG_TYPE_SECURECHANNEL or ALG_SID_SCHANNEL_MAC_KEY);
  210. CALG_SCHANNEL_ENC_KEY = (ALG_CLASS_MSG_ENCRYPT or ALG_TYPE_SECURECHANNEL or ALG_SID_SCHANNEL_ENC_KEY);
  211. CALG_PCT1_MASTER = (ALG_CLASS_MSG_ENCRYPT or ALG_TYPE_SECURECHANNEL or ALG_SID_PCT1_MASTER);
  212. CALG_SSL2_MASTER = (ALG_CLASS_MSG_ENCRYPT or ALG_TYPE_SECURECHANNEL or ALG_SID_SSL2_MASTER);
  213. CALG_TLS1_MASTER = (ALG_CLASS_MSG_ENCRYPT or ALG_TYPE_SECURECHANNEL or ALG_SID_TLS1_MASTER);
  214. CALG_RC5 = (ALG_CLASS_DATA_ENCRYPT or ALG_TYPE_BLOCK or ALG_SID_RC5);
  215. CALG_HMAC = (ALG_CLASS_HASH or ALG_TYPE_ANY or ALG_SID_HMAC);
  216. type
  217. PVTableProvStruc = ^VTableProvStruc;
  218. VTableProvStruc = record
  219. Version: DWORD;
  220. FuncVerifyImage: TFarProc;
  221. FuncReturnhWnd: TFarProc;
  222. dwProvType: DWORD;
  223. pbContextInfo: PBYTE;
  224. cbContextInfo: DWORD;
  225. end;
  226. //type HCRYPTPROV = ULONG;
  227. //type HCRYPTKEY = ULONG;
  228. //type HCRYPTHASH = ULONG;
  229. const
  230. // dwFlags definitions for CryptAcquireContext
  231. CRYPT_VERIFYCONTEXT = $F0000000;
  232. CRYPT_NEWKEYSET = $00000008;
  233. CRYPT_DELETEKEYSET = $00000010;
  234. CRYPT_MACHINE_KEYSET = $00000020;
  235. // dwFlag definitions for CryptGenKey
  236. CRYPT_EXPORTABLE = $00000001;
  237. CRYPT_USER_PROTECTED = $00000002;
  238. CRYPT_CREATE_SALT = $00000004;
  239. CRYPT_UPDATE_KEY = $00000008;
  240. CRYPT_NO_SALT = $00000010;
  241. CRYPT_PREGEN = $00000040;
  242. CRYPT_RECIPIENT = $00000010;
  243. CRYPT_INITIATOR = $00000040;
  244. CRYPT_ONLINE = $00000080;
  245. CRYPT_SF = $00000100;
  246. CRYPT_CREATE_IV = $00000200;
  247. CRYPT_KEK = $00000400;
  248. CRYPT_DATA_KEY = $00000800;
  249. // dwFlags definitions for CryptDeriveKey
  250. CRYPT_SERVER = $00000400;
  251. KEY_LENGTH_MASK = $FFFF0000;
  252. // dwFlag definitions for CryptExportKey
  253. CRYPT_Y_ONLY = $00000001;
  254. CRYPT_SSL2_SLUMMING = $00000002;
  255. // dwFlags definitions for CryptHashSessionKey
  256. CRYPT_LITTLE_ENDIAN = $00000001;
  257. // dwFlag definitions for CryptSetProviderEx and CryptGetDefaultProvider
  258. CRYPT_MACHINE_DEFAULT = $00000001;
  259. CRYPT_USER_DEFAULT = $00000002;
  260. CRYPT_DELETE_DEFAULT = $00000004;
  261. // exported key blob definitions
  262. SIMPLEBLOB = $1;
  263. PUBLICKEYBLOB = $6;
  264. PRIVATEKEYBLOB = $7;
  265. PLAINTEXTKEYBLOB = $8;
  266. AT_KEYEXCHANGE = 1;
  267. AT_SIGNATURE = 2;
  268. CRYPT_USERDATA = 1;
  269. // dwParam
  270. KP_IV = 1; // Initialization vector
  271. KP_SALT = 2; // Salt value
  272. KP_PADDING = 3; // Padding values
  273. KP_MODE = 4; // Mode of the cipher
  274. KP_MODE_BITS = 5; // Number of bits to feedback
  275. KP_PERMISSIONS = 6; // Key permissions DWORD
  276. KP_ALGID = 7; // Key algorithm
  277. KP_BLOCKLEN = 8; // Block size of the cipher
  278. KP_KEYLEN = 9; // Length of key in bits
  279. KP_SALT_EX = 10; // Length of salt in bytes
  280. KP_P = 11; // DSS/Diffie-Hellman P value
  281. KP_G = 12; // DSS/Diffie-Hellman G value
  282. KP_Q = 13; // DSS Q value
  283. KP_X = 14; // Diffie-Hellman X value
  284. KP_Y = 15; // Y value
  285. KP_RA = 16; // Fortezza RA value
  286. KP_RB = 17; // Fortezza RB value
  287. KP_INFO = 18; // for putting information into an RSA envelope
  288. KP_EFFECTIVE_KEYLEN = 19; // setting and getting RC2 effective key length
  289. KP_SCHANNEL_ALG = 20; // for setting the Secure Channel algorithms
  290. KP_CLIENT_RANDOM = 21; // for setting the Secure Channel client random data
  291. KP_SERVER_RANDOM = 22; // for setting the Secure Channel server random data
  292. KP_RP = 23;
  293. KP_PRECOMP_MD5 = 24;
  294. KP_PRECOMP_SHA = 25;
  295. KP_CERTIFICATE = 26; // for setting Secure Channel certificate data (PCT1)
  296. KP_CLEAR_KEY = 27; // for setting Secure Channel clear key data (PCT1)
  297. KP_PUB_EX_LEN = 28;
  298. KP_PUB_EX_VAL = 29;
  299. // KP_PADDING
  300. PKCS5_PADDING = 1; {PKCS 5 (sec 6.2) padding method}
  301. RANDOM_PADDING = 2;
  302. ZERO_PADDING = 3;
  303. // KP_MODE
  304. CRYPT_MODE_CBC = 1; // Cipher block chaining
  305. CRYPT_MODE_ECB = 2; // Electronic code book
  306. CRYPT_MODE_OFB = 3; // Output feedback mode
  307. CRYPT_MODE_CFB = 4; // Cipher feedback mode
  308. CRYPT_MODE_CTS = 5; // Ciphertext stealing mode
  309. // KP_PERMISSIONS
  310. CRYPT_ENCRYPT = $0001; // Allow encryption
  311. CRYPT_DECRYPT = $0002; // Allow decryption
  312. CRYPT_EXPORT = $0004; // Allow key to be exported
  313. CRYPT_READ = $0008; // Allow parameters to be read
  314. CRYPT_WRITE = $0010; // Allow parameters to be set
  315. CRYPT_MAC = $0020; // Allow MACs to be used with key
  316. CRYPT_EXPORT_KEY = $0040; // Allow key to be used for exporting keys
  317. CRYPT_IMPORT_KEY = $0080; // Allow key to be used for importing keys
  318. HP_ALGID = $0001; // Hash algorithm
  319. HP_HASHVAL = $0002; // Hash value
  320. HP_HASHSIZE = $0004; // Hash value size
  321. HP_HMAC_INFO = $0005; // information for creating an HMAC
  322. CRYPT_FAILED = FALSE;
  323. CRYPT_SUCCEED = TRUE;
  324. function RCRYPT_SUCCEEDED(rt: BOOL): BOOL;
  325. function RCRYPT_FAILED(rt: BOOL): BOOL;
  326. const
  327. // CryptGetProvParam
  328. PP_ENUMALGS = 1;
  329. PP_ENUMCONTAINERS = 2;
  330. PP_IMPTYPE = 3;
  331. PP_NAME = 4;
  332. PP_VERSION = 5;
  333. PP_CONTAINER = 6;
  334. PP_CHANGE_PASSWORD = 7;
  335. PP_KEYSET_SEC_DESCR = 8; // get/set security descriptor of keyset
  336. PP_CERTCHAIN = 9; // for retrieving certificates from tokens
  337. PP_KEY_TYPE_SUBTYPE = 10;
  338. PP_PROVTYPE = 16;
  339. PP_KEYSTORAGE = 17;
  340. PP_APPLI_CERT = 18;
  341. PP_SYM_KEYSIZE = 19;
  342. PP_SESSION_KEYSIZE = 20;
  343. PP_UI_PROMPT = 21;
  344. PP_ENUMALGS_EX = 22;
  345. CRYPT_FIRST = 1;
  346. CRYPT_NEXT = 2;
  347. CRYPT_IMPL_HARDWARE = 1;
  348. CRYPT_IMPL_SOFTWARE = 2;
  349. CRYPT_IMPL_MIXED = 3;
  350. CRYPT_IMPL_UNKNOWN = 4;
  351. // key storage flags
  352. CRYPT_SEC_DESCR = $00000001;
  353. CRYPT_PSTORE = $00000002;
  354. CRYPT_UI_PROMPT = $00000004;
  355. // protocol flags
  356. CRYPT_FLAG_PCT1 = $0001;
  357. CRYPT_FLAG_SSL2 = $0002;
  358. CRYPT_FLAG_SSL3 = $0004;
  359. CRYPT_FLAG_TLS1 = $0008;
  360. // CryptSetProvParam
  361. PP_CLIENT_HWND = 1;
  362. PP_CONTEXT_INFO = 11;
  363. PP_KEYEXCHANGE_KEYSIZE = 12;
  364. PP_SIGNATURE_KEYSIZE = 13;
  365. PP_KEYEXCHANGE_ALG = 14;
  366. PP_SIGNATURE_ALG = 15;
  367. PP_DELETEKEY = 24;
  368. PROV_RSA_FULL = 1;
  369. PROV_RSA_SIG = 2;
  370. PROV_DSS = 3;
  371. PROV_FORTEZZA = 4;
  372. PROV_MS_EXCHANGE = 5;
  373. PROV_SSL = 6;
  374. PROV_RSA_SCHANNEL = 12;
  375. PROV_DSS_DH = 13;
  376. PROV_EC_ECDSA_SIG = 14;
  377. PROV_EC_ECNRA_SIG = 15;
  378. PROV_EC_ECDSA_FULL = 16;
  379. PROV_EC_ECNRA_FULL = 17;
  380. PROV_SPYRUS_LYNKS = 20;
  381. // STT defined Providers
  382. PROV_STT_MER = 7;
  383. PROV_STT_ACQ = 8;
  384. PROV_STT_BRND = 9;
  385. PROV_STT_ROOT = 10;
  386. PROV_STT_ISS = 11;
  387. // Provider friendly names
  388. MS_DEF_PROV_A = 'Microsoft Base Cryptographic Provider v1.0';
  389. {$IFNDEF VER90}
  390. MS_DEF_PROV_W = WideString('Microsoft Base Cryptographic Provider v1.0');
  391. {$ELSE}
  392. MS_DEF_PROV_W = ('Microsoft Base Cryptographic Provider v1.0');
  393. {$ENDIF}
  394. {$IFDEF UNICODE}
  395. MS_DEF_PROV = MS_DEF_PROV_W;
  396. {$ELSE}
  397. MS_DEF_PROV = MS_DEF_PROV_A;
  398. {$ENDIF}
  399. MS_ENHANCED_PROV_A = 'Microsoft Enhanced Cryptographic Provider v1.0';
  400. {$IFNDEF VER90}
  401. MS_ENHANCED_PROV_W = WideString('Microsoft Enhanced Cryptographic Provider v1.0');
  402. {$ELSE}
  403. MS_ENHANCED_PROV_W = ('Microsoft Enhanced Cryptographic Provider v1.0');
  404. {$ENDIF}
  405. {$IFDEF UNICODE}
  406. MS_ENHANCED_PROV = MS_ENHANCED_PROV_W;
  407. {$ELSE}
  408. MS_ENHANCED_PROV = MS_ENHANCED_PROV_A;
  409. {$ENDIF}
  410. MS_DEF_RSA_SIG_PROV_A = 'Microsoft RSA Signature Cryptographic Provider';
  411. {$IFNDEF VER90}
  412. MS_DEF_RSA_SIG_PROV_W = WideString('Microsoft RSA Signature Cryptographic Provider');
  413. {$ELSE}
  414. MS_DEF_RSA_SIG_PROV_W = ('Microsoft RSA Signature Cryptographic Provider');
  415. {$ENDIF}
  416. {$IFDEF UNICODE}
  417. MS_DEF_RSA_SIG_PROV = MS_DEF_RSA_SIG_PROV_W;
  418. {$ELSE}
  419. MS_DEF_RSA_SIG_PROV = MS_DEF_RSA_SIG_PROV_A;
  420. {$ENDIF}
  421. MS_DEF_RSA_SCHANNEL_PROV_A = 'Microsoft Base RSA SChannel Cryptographic Provider';
  422. {$IFNDEF VER90}
  423. MS_DEF_RSA_SCHANNEL_PROV_W = WideString('Microsoft Base RSA SChannel Cryptographic Provider');
  424. {$ELSE}
  425. MS_DEF_RSA_SCHANNEL_PROV_W = ('Microsoft Base RSA SChannel Cryptographic Provider');
  426. {$ENDIF}
  427. {$IFDEF UNICODE}
  428. MS_DEF_RSA_SCHANNEL_PROV = MS_DEF_RSA_SCHANNEL_PROV_W;
  429. {$ELSE}
  430. MS_DEF_RSA_SCHANNEL_PROV = MS_DEF_RSA_SCHANNEL_PROV_A;
  431. {$ENDIF}
  432. MS_ENHANCED_RSA_SCHANNEL_PROV_A = 'Microsoft Enhanced RSA SChannel Cryptographic Provider';
  433. {$IFNDEF VER90}
  434. MS_ENHANCED_RSA_SCHANNEL_PROV_W = WideString('Microsoft Enhanced RSA SChannel Cryptographic Provider');
  435. {$ELSE}
  436. MS_ENHANCED_RSA_SCHANNEL_PROV_W = ('Microsoft Enhanced RSA SChannel Cryptographic Provider');
  437. {$ENDIF}
  438. {$IFDEF UNICODE}
  439. MS_ENHANCED_RSA_SCHANNEL_PROV = MS_ENHANCED_RSA_SCHANNEL_PROV_W;
  440. {$ELSE}
  441. MS_ENHANCED_RSA_SCHANNEL_PROV = MS_ENHANCED_RSA_SCHANNEL_PROV_A;
  442. {$ENDIF}
  443. MS_DEF_DSS_PROV_A = 'Microsoft Base DSS Cryptographic Provider';
  444. {$IFNDEF VER90}
  445. MS_DEF_DSS_PROV_W = WideString('Microsoft Base DSS Cryptographic Provider');
  446. {$ELSE}
  447. MS_DEF_DSS_PROV_W = ('Microsoft Base DSS Cryptographic Provider');
  448. {$ENDIF}
  449. {$IFDEF UNICODE}
  450. MS_DEF_DSS_PROV = MS_DEF_DSS_PROV_W;
  451. {$ELSE}
  452. MS_DEF_DSS_PROV = MS_DEF_DSS_PROV_A;
  453. {$ENDIF}
  454. MS_DEF_DSS_DH_PROV_A = 'Microsoft Base DSS and Diffie-Hellman Cryptographic Provider';
  455. {$IFNDEF VER90}
  456. MS_DEF_DSS_DH_PROV_W = WideString('Microsoft Base DSS and Diffie-Hellman Cryptographic Provider');
  457. {$ELSE}
  458. MS_DEF_DSS_DH_PROV_W = ('Microsoft Base DSS and Diffie-Hellman Cryptographic Provider');
  459. {$ENDIF}
  460. {$IFDEF UNICODE}
  461. MS_DEF_DSS_DH_PROV = MS_DEF_DSS_DH_PROV_W;
  462. {$ELSE}
  463. MS_DEF_DSS_DH_PROV = MS_DEF_DSS_DH_PROV_A;
  464. {$ENDIF}
  465. MAXUIDLEN = 64;
  466. CUR_BLOB_VERSION = 2;
  467. {structure for use with CryptSetHashParam with CALG_HMAC}
  468. type
  469. PHMAC_INFO = ^HMAC_INFO;
  470. HMAC_INFO = record
  471. HashAlgid: ALG_ID;
  472. pbInnerString: PBYTE;
  473. cbInnerString: DWORD;
  474. pbOuterString: PBYTE;
  475. cbOuterString: DWORD;
  476. end;
  477. // structure for use with CryptSetHashParam with CALG_HMAC
  478. type
  479. PSCHANNEL_ALG = ^SCHANNEL_ALG;
  480. SCHANNEL_ALG = record
  481. dwUse: DWORD;
  482. Algid: ALG_ID;
  483. cBits: DWORD;
  484. end;
  485. // uses of algortihms for SCHANNEL_ALG structure
  486. const
  487. SCHANNEL_MAC_KEY = $00000000;
  488. SCHANNEL_ENC_KEY = $00000001;
  489. type
  490. PPROV_ENUMALGS = ^PROV_ENUMALGS;
  491. PROV_ENUMALGS = record
  492. aiAlgid: ALG_ID;
  493. dwBitLen: DWORD;
  494. dwNameLen: DWORD;
  495. szName: array[0..20 - 1] of Char;
  496. end;
  497. type
  498. PPROV_ENUMALGS_EX = ^PROV_ENUMALGS_EX;
  499. PROV_ENUMALGS_EX = record
  500. aiAlgid: ALG_ID;
  501. dwDefaultLen: DWORD;
  502. dwMinLen: DWORD;
  503. dwMaxLen: DWORD;
  504. dwProtocols: DWORD;
  505. dwNameLen: DWORD;
  506. szName: array[0..20 - 1] of Char;
  507. dwLongNameLen: DWORD;
  508. szLongName: array[0..40 - 1] of Char;
  509. end;
  510. type
  511. PPUBLICKEYSTRUC = ^PUBLICKEYSTRUC;
  512. PUBLICKEYSTRUC = record
  513. bType: BYTE;
  514. bVersion: BYTE;
  515. reserved: Word;
  516. aiKeyAlg: ALG_ID;
  517. end;
  518. type
  519. BLOBHEADER = PUBLICKEYSTRUC;
  520. PBLOBHEADER = ^BLOBHEADER;
  521. type
  522. PRSAPUBKEY = ^RSAPUBKEY;
  523. RSAPUBKEY = record
  524. magic: DWORD; // Has to be RSA1
  525. bitlen: DWORD; // # of bits in modulus
  526. pubexp: DWORD; // public exponent
  527. // Modulus data follows
  528. end;
  529. type
  530. PPUBKEY = ^PUBKEY;
  531. PUBKEY = record
  532. magic: DWORD;
  533. bitlen: DWORD; // # of bits in modulus
  534. end;
  535. type
  536. DHPUBKEY = PUBKEY;
  537. DSSPUBKEY = PUBKEY;
  538. KEAPUBKEY = PUBKEY;
  539. TEKPUBKEY = PUBKEY;
  540. type
  541. PDSSSEED = ^DSSSEED;
  542. DSSSEED = record
  543. counter: DWORD;
  544. seed: array[0..20 - 1] of BYTE;
  545. end;
  546. type
  547. PKEY_TYPE_SUBTYPE = ^KEY_TYPE_SUBTYPE;
  548. KEY_TYPE_SUBTYPE = record
  549. dwKeySpec: DWORD;
  550. Type_: TGUID; {conflict with base Delphi type: original name 'Type'}
  551. Subtype: TGUID;
  552. end;
  553. type
  554. HCRYPTPROV = ULONG;
  555. PHCRYPTPROV = ^HCRYPTPROV;
  556. HCRYPTKEY = ULONG;
  557. PHCRYPTKEY = ^HCRYPTKEY;
  558. HCRYPTHASH = ULONG;
  559. PHCRYPTHASH = ^HCRYPTHASH;
  560. function CryptAcquireContextA(phProv: PHCRYPTPROV;
  561. pszContainer: PAnsiChar;
  562. pszProvider: PAnsiChar;
  563. dwProvType: DWORD;
  564. dwFlags: DWORD): BOOL; stdcall;
  565. function CryptAcquireContext(phProv: PHCRYPTPROV;
  566. pszContainer: LPAWSTR;
  567. pszProvider: LPAWSTR;
  568. dwProvType: DWORD;
  569. dwFlags: DWORD): BOOL; stdcall;
  570. function CryptAcquireContextW(phProv: PHCRYPTPROV;
  571. pszContainer: PWideChar;
  572. pszProvider: PWideChar;
  573. dwProvType: DWORD;
  574. dwFlags: DWORD): BOOL; stdcall;
  575. function CryptReleaseContext(hProv: HCRYPTPROV;
  576. dwFlags: DWORD): BOOL; stdcall;
  577. function CryptGenKey(hProv: HCRYPTPROV;
  578. Algid: ALG_ID;
  579. dwFlags: DWORD;
  580. phKey: PHCRYPTKEY): BOOL; stdcall;
  581. function CryptDeriveKey(hProv: HCRYPTPROV;
  582. Algid: ALG_ID;
  583. hBaseData: HCRYPTHASH;
  584. dwFlags: DWORD;
  585. phKey: PHCRYPTKEY): BOOL; stdcall;
  586. function CryptDestroyKey(hKey: HCRYPTKEY): BOOL; stdcall;
  587. function CryptSetKeyParam(hKey: HCRYPTKEY;
  588. dwParam: DWORD;
  589. pbData: PBYTE;
  590. dwFlags: DWORD): BOOL; stdcall;
  591. function CryptGetKeyParam(hKey: HCRYPTKEY;
  592. dwParam: DWORD;
  593. pbData: PBYTE;
  594. pdwDataLen: PDWORD;
  595. dwFlags: DWORD): BOOL; stdcall;
  596. function CryptSetHashParam(hHash: HCRYPTHASH;
  597. dwParam: DWORD;
  598. pbData: PBYTE;
  599. dwFlags: DWORD): BOOL; stdcall;
  600. function CryptGetHashParam(hHash: HCRYPTHASH;
  601. dwParam: DWORD;
  602. pbData: PBYTE;
  603. pdwDataLen: PDWORD;
  604. dwFlags: DWORD): BOOL; stdcall;
  605. function CryptSetProvParam(hProv: HCRYPTPROV;
  606. dwParam: DWORD;
  607. pbData: PBYTE;
  608. dwFlags: DWORD): BOOL; stdcall;
  609. function CryptGetProvParam(hProv: HCRYPTPROV;
  610. dwParam: DWORD;
  611. pbData: PBYTE;
  612. pdwDataLen: PDWORD;
  613. dwFlags: DWORD): BOOL; stdcall;
  614. function CryptGenRandom(hProv: HCRYPTPROV;
  615. dwLen: DWORD;
  616. pbBuffer: PBYTE): BOOL; stdcall;
  617. function CryptGetUserKey(hProv: HCRYPTPROV;
  618. dwKeySpec: DWORD;
  619. phUserKey: PHCRYPTKEY): BOOL; stdcall;
  620. function CryptExportKey(hKey: HCRYPTKEY;
  621. hExpKey: HCRYPTKEY;
  622. dwBlobType: DWORD;
  623. dwFlags: DWORD;
  624. pbData: PBYTE;
  625. pdwDataLen: PDWORD): BOOL; stdcall;
  626. function CryptImportKey(hProv: HCRYPTPROV;
  627. pbData: PBYTE;
  628. dwDataLen: DWORD;
  629. hPubKey: HCRYPTKEY;
  630. dwFlags: DWORD;
  631. phKey: PHCRYPTKEY): BOOL; stdcall;
  632. function CryptEncrypt(hKey: HCRYPTKEY;
  633. hHash: HCRYPTHASH;
  634. Final: BOOL;
  635. dwFlags: DWORD;
  636. pbData: PBYTE;
  637. pdwDataLen: PDWORD;
  638. dwBufLen: DWORD): BOOL; stdcall;
  639. function CryptDecrypt(hKey: HCRYPTKEY;
  640. hHash: HCRYPTHASH;
  641. Final: BOOL;
  642. dwFlags: DWORD;
  643. pbData: PBYTE;
  644. pdwDataLen: PDWORD): BOOL; stdcall;
  645. function CryptCreateHash(hProv: HCRYPTPROV;
  646. Algid: ALG_ID;
  647. hKey: HCRYPTKEY;
  648. dwFlags: DWORD;
  649. phHash: PHCRYPTHASH): BOOL; stdcall;
  650. function CryptHashData(hHash: HCRYPTHASH;
  651. const pbData: PBYTE;
  652. dwDataLen: DWORD;
  653. dwFlags: DWORD): BOOL; stdcall;
  654. function CryptHashSessionKey(hHash: HCRYPTHASH;
  655. hKey: HCRYPTKEY;
  656. dwFlags: DWORD): BOOL; stdcall;
  657. function CryptDestroyHash(hHash: HCRYPTHASH): BOOL; stdcall;
  658. function CryptSignHashA(hHash: HCRYPTHASH;
  659. dwKeySpec: DWORD;
  660. sDescription: PAnsiChar;
  661. dwFlags: DWORD;
  662. pbSignature: PBYTE;
  663. pdwSigLen: PDWORD): BOOL; stdcall;
  664. function CryptSignHash(hHash: HCRYPTHASH;
  665. dwKeySpec: DWORD;
  666. sDescription: LPAWSTR;
  667. dwFlags: DWORD;
  668. pbSignature: PBYTE;
  669. pdwSigLen: PDWORD): BOOL; stdcall;
  670. function CryptSignHashW(hHash: HCRYPTHASH;
  671. dwKeySpec: DWORD;
  672. sDescription: PWideChar;
  673. dwFlags: DWORD;
  674. pbSignature: PBYTE;
  675. pdwSigLen: PDWORD): BOOL; stdcall;
  676. function CryptSignHashU(hHash: HCRYPTHASH;
  677. dwKeySpec: DWORD;
  678. sDescription: PWideChar;
  679. dwFlags: DWORD;
  680. pbSignature: PBYTE;
  681. pdwSigLen: PDWORD): BOOL; stdcall;
  682. function CryptVerifySignatureA(hHash: HCRYPTHASH;
  683. const pbSignature: PBYTE;
  684. dwSigLen: DWORD;
  685. hPubKey: HCRYPTKEY;
  686. sDescription: PAnsiChar;
  687. dwFlags: DWORD): BOOL; stdcall;
  688. function CryptVerifySignature(hHash: HCRYPTHASH;
  689. const pbSignature: PBYTE;
  690. dwSigLen: DWORD;
  691. hPubKey: HCRYPTKEY;
  692. sDescription: LPAWSTR;
  693. dwFlags: DWORD): BOOL; stdcall;
  694. function CryptVerifySignatureW(hHash: HCRYPTHASH;
  695. const pbSignature: PBYTE;
  696. dwSigLen: DWORD;
  697. hPubKey: HCRYPTKEY;
  698. sDescription: PWideChar;
  699. dwFlags: DWORD): BOOL; stdcall;
  700. function CryptSetProviderA(pszProvName: PAnsiChar;
  701. dwProvType: DWORD): BOOL; stdcall;
  702. function CryptSetProvider(pszProvName: LPAWSTR;
  703. dwProvType: DWORD): BOOL; stdcall;
  704. function CryptSetProviderW(pszProvName: PWideChar;
  705. dwProvType: DWORD): BOOL; stdcall;
  706. function CryptSetProviderU(pszProvName: PWideChar;
  707. dwProvType: DWORD): BOOL; stdcall;
  708. {$IFDEF NT5}
  709. function CryptSetProviderExA(pszProvName: LPCSTR;
  710. dwProvType: DWORD;
  711. pdwReserved: PDWORD;
  712. dwFlags: DWORD): BOOL; stdcall;
  713. function CryptSetProviderExW(pszProvName: LPCWSTR;
  714. dwProvType: DWORD;
  715. pdwReserved: PDWORD;
  716. dwFlags: DWORD): BOOL; stdcall;
  717. function CryptSetProviderEx(pszProvName: LPAWSTR;
  718. dwProvType: DWORD;
  719. pdwReserved: PDWORD;
  720. dwFlags: DWORD): BOOL; stdcall;
  721. function CryptGetDefaultProviderA(dwProvType: DWORD;
  722. pdwReserved: DWORD;
  723. dwFlags: DWORD;
  724. pszProvName: LPSTR;
  725. pcbProvName: PDWORD): BOOL; stdcall;
  726. function CryptGetDefaultProviderW(dwProvType: DWORD;
  727. pdwReserved: DWORD;
  728. dwFlags: DWORD;
  729. pszProvName: LPWSTR;
  730. pcbProvName: PDWORD): BOOL; stdcall;
  731. function CryptGetDefaultProvider(dwProvType: DWORD;
  732. pdwReserved: DWORD;
  733. dwFlags: DWORD;
  734. pszProvName: LPAWSTR;
  735. pcbProvName: PDWORD): BOOL; stdcall;
  736. function CryptEnumProviderTypesA(dwIndex: DWORD;
  737. pdwReserved: PDWORD;
  738. dwFlags: DWORD;
  739. pdwProvType: PDWORD;
  740. pszTypeName: LPSTR;
  741. pcbTypeName: PDWORD): BOOL; stdcall;
  742. function CryptEnumProviderTypesW(dwIndex: DWORD;
  743. pdwReserved: PDWORD;
  744. dwFlags: DWORD;
  745. pdwProvType: PDWORD;
  746. pszTypeName: LPWSTR;
  747. pcbTypeName: PDWORD): BOOL; stdcall;
  748. function CryptEnumProviderTypes(dwIndex: DWORD;
  749. pdwReserved: PDWORD;
  750. dwFlags: DWORD;
  751. pdwProvType: PDWORD;
  752. pszTypeName: LPAWSTR;
  753. pcbTypeName: PDWORD): BOOL; stdcall;
  754. function CryptEnumProvidersA(dwIndex: DWORD;
  755. pdwReserved: PDWORD;
  756. dwFlags: DWORD;
  757. pdwProvType: PDWORD;
  758. pszProvName: LPSTR;
  759. pcbProvName: PDWORD): BOOL; stdcall;
  760. function CryptEnumProvidersW(dwIndex: DWORD;
  761. pdwReserved: PDWORD;
  762. dwFlags: DWORD;
  763. pdwProvType: PDWORD;
  764. pszProvName: LPWSTR;
  765. pcbProvName: PDWORD): BOOL; stdcall;
  766. function CryptEnumProviders(dwIndex: DWORD;
  767. pdwReserved: PDWORD;
  768. dwFlags: DWORD;
  769. pdwProvType: PDWORD;
  770. pszProvName: LPAWSTR;
  771. pcbProvName: PDWORD): BOOL; stdcall;
  772. function CryptContextAddRef(hProv: HCRYPTPROV;
  773. pdwReserved: PDWORD;
  774. dwFlags: DWORD): BOOL; stdcall;
  775. function CryptDuplicateKey(hKey: HCRYPTKEY;
  776. pdwReserved: PDWORD;
  777. dwFlags: DWORD;
  778. phKey: PHCRYPTKEY): BOOL; stdcall;
  779. function CryptDuplicateHash(hHash: HCRYPTHASH;
  780. pdwReserved: PDWORD;
  781. dwFlags: DWORD;
  782. phHash: PHCRYPTHASH): BOOL; stdcall;
  783. {$ENDIF NT5}
  784. function CryptEnumProvidersU(dwIndex: DWORD;
  785. pdwReserved: PDWORD;
  786. dwFlags: DWORD;
  787. pdwProvType: PDWORD;
  788. pszProvName: LPWSTR;
  789. pcbProvName: PDWORD): BOOL; stdcall;
  790. //+-------------------------------------------------------------------------
  791. // CRYPTOAPI BLOB definitions
  792. //--------------------------------------------------------------------------
  793. type
  794. PCRYPTOAPI_BLOB = ^CRYPTOAPI_BLOB;
  795. CRYPTOAPI_BLOB = record
  796. cbData: DWORD;
  797. pbData: PBYTE;
  798. end;
  799. type
  800. CRYPT_INTEGER_BLOB = CRYPTOAPI_BLOB;
  801. PCRYPT_INTEGER_BLOB = ^CRYPT_INTEGER_BLOB;
  802. CRYPT_UINT_BLOB = CRYPTOAPI_BLOB;
  803. PCRYPT_UINT_BLOB = ^CRYPT_UINT_BLOB;
  804. CRYPT_OBJID_BLOB = CRYPTOAPI_BLOB;
  805. PCRYPT_OBJID_BLOB = ^CRYPT_OBJID_BLOB;
  806. CERT_NAME_BLOB = CRYPTOAPI_BLOB;
  807. PCERT_NAME_BLOB = ^CERT_NAME_BLOB;
  808. CERT_RDN_VALUE_BLOB = CRYPTOAPI_BLOB;
  809. PCERT_RDN_VALUE_BLOB = ^CERT_RDN_VALUE_BLOB;
  810. CERT_BLOB = CRYPTOAPI_BLOB;
  811. PCERT_BLOB = ^CERT_BLOB;
  812. CRL_BLOB = CRYPTOAPI_BLOB;
  813. PCRL_BLOB = ^CRL_BLOB;
  814. DATA_BLOB = CRYPTOAPI_BLOB;
  815. PDATA_BLOB = ^DATA_BLOB; // JEFFJEFF temporary (too generic)
  816. CRYPT_DATA_BLOB = CRYPTOAPI_BLOB;
  817. PCRYPT_DATA_BLOB = ^CRYPT_DATA_BLOB;
  818. CRYPT_HASH_BLOB = CRYPTOAPI_BLOB;
  819. PCRYPT_HASH_BLOB = ^CRYPT_HASH_BLOB;
  820. CRYPT_DIGEST_BLOB = CRYPTOAPI_BLOB;
  821. PCRYPT_DIGEST_BLOB = ^CRYPT_DIGEST_BLOB;
  822. CRYPT_DER_BLOB = CRYPTOAPI_BLOB;
  823. PCRYPT_DER_BLOB = ^CRYPT_DER_BLOB;
  824. CRYPT_ATTR_BLOB = CRYPTOAPI_BLOB;
  825. PCRYPT_ATTR_BLOB = ^CRYPT_ATTR_BLOB;
  826. //+-------------------------------------------------------------------------
  827. // In a CRYPT_BIT_BLOB the last byte may contain 0-7 unused bits. Therefore, the
  828. // overall bit length is cbData * 8 - cUnusedBits.
  829. //--------------------------------------------------------------------------
  830. type
  831. PCRYPT_BIT_BLOB = ^CRYPT_BIT_BLOB;
  832. CRYPT_BIT_BLOB = record
  833. cbData: DWORD;
  834. pbData: PBYTE;
  835. cUnusedBits: DWORD;
  836. end;
  837. //+-------------------------------------------------------------------------
  838. // Type used for any algorithm
  839. //
  840. // Where the Parameters CRYPT_OBJID_BLOB is in its encoded representation. For most
  841. // algorithm types, the Parameters CRYPT_OBJID_BLOB is NULL (Parameters.cbData = 0).
  842. //--------------------------------------------------------------------------
  843. type
  844. PCRYPT_ALGORITHM_IDENTIFIER = ^CRYPT_ALGORITHM_IDENTIFIER;
  845. CRYPT_ALGORITHM_IDENTIFIER = record
  846. pszObjId: LPSTR;
  847. Parameters: CRYPT_OBJID_BLOB;
  848. end;
  849. // Following are the definitions of various algorithm object identifiers
  850. // RSA
  851. const
  852. szOID_RSA = '1.2.840.113549';
  853. szOID_PKCS = '1.2.840.113549.1';
  854. szOID_RSA_HASH = '1.2.840.113549.2';
  855. szOID_RSA_ENCRYPT = '1.2.840.113549.3';
  856. szOID_PKCS_1 = '1.2.840.113549.1.1';
  857. szOID_PKCS_2 = '1.2.840.113549.1.2';
  858. szOID_PKCS_3 = '1.2.840.113549.1.3';
  859. szOID_PKCS_4 = '1.2.840.113549.1.4';
  860. szOID_PKCS_5 = '1.2.840.113549.1.5';
  861. szOID_PKCS_6 = '1.2.840.113549.1.6';
  862. szOID_PKCS_7 = '1.2.840.113549.1.7';
  863. szOID_PKCS_8 = '1.2.840.113549.1.8';
  864. szOID_PKCS_9 = '1.2.840.113549.1.9';
  865. szOID_PKCS_10 = '1.2.840.113549.1.10';
  866. szOID_RSA_RSA = '1.2.840.113549.1.1.1';
  867. szOID_RSA_MD2RSA = '1.2.840.113549.1.1.2';
  868. szOID_RSA_MD4RSA = '1.2.840.113549.1.1.3';
  869. szOID_RSA_MD5RSA = '1.2.840.113549.1.1.4';
  870. szOID_RSA_SHA1RSA = '1.2.840.113549.1.1.5';
  871. szOID_RSA_SETOAEP_RSA = '1.2.840.113549.1.1.6';
  872. szOID_RSA_data = '1.2.840.113549.1.7.1';
  873. szOID_RSA_signedData = '1.2.840.113549.1.7.2';
  874. szOID_RSA_envelopedData = '1.2.840.113549.1.7.3';
  875. szOID_RSA_signEnvData = '1.2.840.113549.1.7.4';
  876. szOID_RSA_digestedData = '1.2.840.113549.1.7.5';
  877. szOID_RSA_hashedData = '1.2.840.113549.1.7.5';
  878. szOID_RSA_encryptedData = '1.2.840.113549.1.7.6';
  879. szOID_RSA_emailAddr = '1.2.840.113549.1.9.1';
  880. szOID_RSA_unstructName = '1.2.840.113549.1.9.2';
  881. szOID_RSA_contentType = '1.2.840.113549.1.9.3';
  882. szOID_RSA_messageDigest = '1.2.840.113549.1.9.4';
  883. szOID_RSA_signingTime = '1.2.840.113549.1.9.5';
  884. szOID_RSA_counterSign = '1.2.840.113549.1.9.6';
  885. szOID_RSA_challengePwd = '1.2.840.113549.1.9.7';
  886. szOID_RSA_unstructAddr = '1.2.840.113549.1.9.8';
  887. szOID_RSA_extCertAttrs = '1.2.840.113549.1.9.9';
  888. szOID_RSA_SMIMECapabilities = '1.2.840.113549.1.9.15';
  889. szOID_RSA_preferSignedData = '1.2.840.113549.1.9.15.1';
  890. szOID_RSA_MD2 = '1.2.840.113549.2.2';
  891. szOID_RSA_MD4 = '1.2.840.113549.2.4';
  892. szOID_RSA_MD5 = '1.2.840.113549.2.5';
  893. szOID_RSA_RC2CBC = '1.2.840.113549.3.2';
  894. szOID_RSA_RC4 = '1.2.840.113549.3.4';
  895. szOID_RSA_DES_EDE3_CBC = '1.2.840.113549.3.7';
  896. szOID_RSA_RC5_CBCPad = '1.2.840.113549.3.9';
  897. // ITU-T UsefulDefinitions
  898. szOID_DS = '2.5';
  899. szOID_DSALG = '2.5.8';
  900. szOID_DSALG_CRPT = '2.5.8.1';
  901. szOID_DSALG_HASH = '2.5.8.2';
  902. szOID_DSALG_SIGN = '2.5.8.3';
  903. szOID_DSALG_RSA = '2.5.8.1.1';
  904. // NIST OSE Implementors' Workshop (OIW)
  905. // http://nemo.ncsl.nist.gov/oiw/agreements/stable/OSI/12s_9506.w51
  906. // http://nemo.ncsl.nist.gov/oiw/agreements/working/OSI/12w_9503.w51
  907. szOID_OIW = '1.3.14';
  908. // NIST OSE Implementors' Workshop (OIW) Security SIG algorithm identifiers
  909. szOID_OIWSEC = '1.3.14.3.2';
  910. szOID_OIWSEC_md4RSA = '1.3.14.3.2.2';
  911. szOID_OIWSEC_md5RSA = '1.3.14.3.2.3';
  912. szOID_OIWSEC_md4RSA2 = '1.3.14.3.2.4';
  913. szOID_OIWSEC_desECB = '1.3.14.3.2.6';
  914. szOID_OIWSEC_desCBC = '1.3.14.3.2.7';
  915. szOID_OIWSEC_desOFB = '1.3.14.3.2.8';
  916. szOID_OIWSEC_desCFB = '1.3.14.3.2.9';
  917. szOID_OIWSEC_desMAC = '1.3.14.3.2.10';
  918. szOID_OIWSEC_rsaSign = '1.3.14.3.2.11';
  919. szOID_OIWSEC_dsa = '1.3.14.3.2.12';
  920. szOID_OIWSEC_shaDSA = '1.3.14.3.2.13';
  921. szOID_OIWSEC_mdc2RSA = '1.3.14.3.2.14';
  922. szOID_OIWSEC_shaRSA = '1.3.14.3.2.15';
  923. szOID_OIWSEC_dhCommMod = '1.3.14.3.2.16';
  924. szOID_OIWSEC_desEDE = '1.3.14.3.2.17';
  925. szOID_OIWSEC_sha = '1.3.14.3.2.18';
  926. szOID_OIWSEC_mdc2 = '1.3.14.3.2.19';
  927. szOID_OIWSEC_dsaComm = '1.3.14.3.2.20';
  928. szOID_OIWSEC_dsaCommSHA = '1.3.14.3.2.21';
  929. szOID_OIWSEC_rsaXchg = '1.3.14.3.2.22';
  930. szOID_OIWSEC_keyHashSeal = '1.3.14.3.2.23';
  931. szOID_OIWSEC_md2RSASign = '1.3.14.3.2.24';
  932. szOID_OIWSEC_md5RSASign = '1.3.14.3.2.25';
  933. szOID_OIWSEC_sha1 = '1.3.14.3.2.26';
  934. szOID_OIWSEC_dsaSHA1 = '1.3.14.3.2.27';
  935. szOID_OIWSEC_dsaCommSHA1 = '1.3.14.3.2.28';
  936. szOID_OIWSEC_sha1RSASign = '1.3.14.3.2.29';
  937. // NIST OSE Implementors' Workshop (OIW) Directory SIG algorithm identifiers
  938. szOID_OIWDIR = '1.3.14.7.2';
  939. szOID_OIWDIR_CRPT = '1.3.14.7.2.1';
  940. szOID_OIWDIR_HASH = '1.3.14.7.2.2';
  941. szOID_OIWDIR_SIGN = '1.3.14.7.2.3';
  942. szOID_OIWDIR_md2 = '1.3.14.7.2.2.1';
  943. szOID_OIWDIR_md2RSA = '1.3.14.7.2.3.1';
  944. // INFOSEC Algorithms
  945. // joint-iso-ccitt(2) country(16) us(840) organization(1) us-government(101) dod(2) id-infosec(1)
  946. szOID_INFOSEC = '2.16.840.1.101.2.1';
  947. szOID_INFOSEC_sdnsSignature = '2.16.840.1.101.2.1.1.1';
  948. szOID_INFOSEC_mosaicSignature = '2.16.840.1.101.2.1.1.2';
  949. szOID_INFOSEC_sdnsConfidentiality = '2.16.840.1.101.2.1.1.3';
  950. szOID_INFOSEC_mosaicConfidentiality = '2.16.840.1.101.2.1.1.4';
  951. szOID_INFOSEC_sdnsIntegrity = '2.16.840.1.101.2.1.1.5';
  952. szOID_INFOSEC_mosaicIntegrity = '2.16.840.1.101.2.1.1.6';
  953. szOID_INFOSEC_sdnsTokenProtection = '2.16.840.1.101.2.1.1.7';
  954. szOID_INFOSEC_mosaicTokenProtection = '2.16.840.1.101.2.1.1.8';
  955. szOID_INFOSEC_sdnsKeyManagement = '2.16.840.1.101.2.1.1.9';
  956. szOID_INFOSEC_mosaicKeyManagement = '2.16.840.1.101.2.1.1.10';
  957. szOID_INFOSEC_sdnsKMandSig = '2.16.840.1.101.2.1.1.11';
  958. szOID_INFOSEC_mosaicKMandSig = '2.16.840.1.101.2.1.1.12';
  959. szOID_INFOSEC_SuiteASignature = '2.16.840.1.101.2.1.1.13';
  960. szOID_INFOSEC_SuiteAConfidentiality = '2.16.840.1.101.2.1.1.14';
  961. szOID_INFOSEC_SuiteAIntegrity = '2.16.840.1.101.2.1.1.15';
  962. szOID_INFOSEC_SuiteATokenProtection = '2.16.840.1.101.2.1.1.16';
  963. szOID_INFOSEC_SuiteAKeyManagement = '2.16.840.1.101.2.1.1.17';
  964. szOID_INFOSEC_SuiteAKMandSig = '2.16.840.1.101.2.1.1.18';
  965. szOID_INFOSEC_mosaicUpdatedSig = '2.16.840.1.101.2.1.1.19';
  966. szOID_INFOSEC_mosaicKMandUpdSig = '2.16.840.1.101.2.1.1.20';
  967. szOID_INFOSEC_mosaicUpdatedInteg = '2.16.840.1.101.2.1.1.21';
  968. type
  969. PCRYPT_OBJID_TABLE = ^CRYPT_OBJID_TABLE;
  970. CRYPT_OBJID_TABLE = record
  971. dwAlgId: DWORD;
  972. pszObjId: LPCSTR;
  973. end;
  974. //+-------------------------------------------------------------------------
  975. // PKCS #1 HashInfo (DigestInfo)
  976. //--------------------------------------------------------------------------
  977. type
  978. PCRYPT_HASH_INFO = ^CRYPT_HASH_INFO;
  979. CRYPT_HASH_INFO = record
  980. HashAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  981. Hash: CRYPT_HASH_BLOB;
  982. end;
  983. //+-------------------------------------------------------------------------
  984. // Type used for an extension to an encoded content
  985. //
  986. // Where the Value's CRYPT_OBJID_BLOB is in its encoded representation.
  987. //--------------------------------------------------------------------------
  988. type
  989. PCERT_EXTENSION = ^CERT_EXTENSION;
  990. CERT_EXTENSION = record
  991. pszObjId: LPSTR;
  992. fCritical: BOOL;
  993. Value: CRYPT_OBJID_BLOB;
  994. end;
  995. //+-------------------------------------------------------------------------
  996. // AttributeTypeValue
  997. //
  998. // Where the Value's CRYPT_OBJID_BLOB is in its encoded representation.
  999. //--------------------------------------------------------------------------
  1000. type
  1001. PCRYPT_ATTRIBUTE_TYPE_VALUE = ^CRYPT_ATTRIBUTE_TYPE_VALUE;
  1002. CRYPT_ATTRIBUTE_TYPE_VALUE = record
  1003. pszObjId: LPSTR;
  1004. Value: CRYPT_OBJID_BLOB;
  1005. end;
  1006. //+-------------------------------------------------------------------------
  1007. // Attributes
  1008. //
  1009. // Where the Value's PATTR_BLOBs are in their encoded representation.
  1010. //--------------------------------------------------------------------------
  1011. type
  1012. PCRYPT_ATTRIBUTE = ^CRYPT_ATTRIBUTE;
  1013. CRYPT_ATTRIBUTE = record
  1014. pszObjId: LPSTR;
  1015. cValue: DWORD;
  1016. rgValue: PCRYPT_ATTR_BLOB;
  1017. end;
  1018. type
  1019. PCRYPT_ATTRIBUTES = ^CRYPT_ATTRIBUTES;
  1020. CRYPT_ATTRIBUTES = record
  1021. cAttr: DWORD; {IN}
  1022. rgAttr: PCRYPT_ATTRIBUTE; {IN}
  1023. end;
  1024. //+-------------------------------------------------------------------------
  1025. // Attributes making up a Relative Distinguished Name (CERT_RDN)
  1026. //
  1027. // The interpretation of the Value depends on the dwValueType.
  1028. // See below for a list of the types.
  1029. //--------------------------------------------------------------------------
  1030. type
  1031. PCERT_RDN_ATTR = ^CERT_RDN_ATTR;
  1032. CERT_RDN_ATTR = record
  1033. pszObjId: LPSTR;
  1034. dwValueType: DWORD;
  1035. Value: CERT_RDN_VALUE_BLOB;
  1036. end;
  1037. //+-------------------------------------------------------------------------
  1038. // CERT_RDN attribute Object Identifiers
  1039. //--------------------------------------------------------------------------
  1040. // Labeling attribute types:
  1041. const
  1042. szOID_COMMON_NAME = '2.5.4.3'; // case-ignore string
  1043. szOID_SUR_NAME = '2.5.4.4'; // case-ignore string
  1044. szOID_DEVICE_SERIAL_NUMBER = '2.5.4.5'; // printable string
  1045. // Geographic attribute types:
  1046. szOID_COUNTRY_NAME = '2.5.4.6'; // printable 2char string
  1047. szOID_LOCALITY_NAME = '2.5.4.7'; // case-ignore string
  1048. szOID_STATE_OR_PROVINCE_NAME = '2.5.4.8'; // case-ignore string
  1049. szOID_STREET_ADDRESS = '2.5.4.9'; // case-ignore string
  1050. // Organizational attribute types:
  1051. szOID_ORGANIZATION_NAME = '2.5.4.10'; // case-ignore string
  1052. szOID_ORGANIZATIONAL_UNIT_NAME = '2.5.4.11'; // case-ignore string
  1053. szOID_TITLE = '2.5.4.12'; // case-ignore string
  1054. // Explanatory attribute types:
  1055. szOID_DESCRIPTION = '2.5.4.13'; // case-ignore string
  1056. szOID_SEARCH_GUIDE = '2.5.4.14';
  1057. szOID_BUSINESS_CATEGORY = '2.5.4.15'; // case-ignore string
  1058. // Postal addressing attribute types:
  1059. szOID_POSTAL_ADDRESS = '2.5.4.16';
  1060. szOID_POSTAL_CODE = '2.5.4.17'; // case-ignore string
  1061. szOID_POST_OFFICE_BOX = '2.5.4.18'; // case-ignore string
  1062. szOID_PHYSICAL_DELIVERY_OFFICE_NAME = '2.5.4.19'; // case-ignore string
  1063. // Telecommunications addressing attribute types:
  1064. szOID_TELEPHONE_NUMBER = '2.5.4.20'; // telephone number
  1065. szOID_TELEX_NUMBER = '2.5.4.21';
  1066. szOID_TELETEXT_TERMINAL_IDENTIFIER = '2.5.4.22';
  1067. szOID_FACSIMILE_TELEPHONE_NUMBER = '2.5.4.23';
  1068. szOID_X21_ADDRESS = '2.5.4.24'; // numeric string
  1069. szOID_INTERNATIONAL_ISDN_NUMBER = '2.5.4.25'; // numeric string
  1070. szOID_REGISTERED_ADDRESS = '2.5.4.26';
  1071. szOID_DESTINATION_INDICATOR = '2.5.4.27'; // printable string
  1072. // Preference attribute types:
  1073. szOID_PREFERRED_DELIVERY_METHOD = '2.5.4.28';
  1074. // OSI application attribute types:
  1075. szOID_PRESENTATION_ADDRESS = '2.5.4.29';
  1076. szOID_SUPPORTED_APPLICATION_CONTEXT = '2.5.4.30';
  1077. // Relational application attribute types:
  1078. szOID_MEMBER = '2.5.4.31';
  1079. szOID_OWNER = '2.5.4.32';
  1080. szOID_ROLE_OCCUPANT = '2.5.4.33';
  1081. szOID_SEE_ALSO = '2.5.4.34';
  1082. // Security attribute types:
  1083. szOID_USER_PASSWORD = '2.5.4.35';
  1084. szOID_USER_CERTIFICATE = '2.5.4.36';
  1085. szOID_CA_CERTIFICATE = '2.5.4.37';
  1086. szOID_AUTHORITY_REVOCATION_LIST = '2.5.4.38';
  1087. szOID_CERTIFICATE_REVOCATION_LIST = '2.5.4.39';
  1088. szOID_CROSS_CERTIFICATE_PAIR = '2.5.4.40';
  1089. // Undocumented attribute types???
  1090. //#define szOID_??? '2.5.4.41'
  1091. szOID_GIVEN_NAME = '2.5.4.42'; // case-ignore string
  1092. szOID_INITIALS = '2.5.4.43'; // case-ignore string
  1093. // Pilot user attribute types:
  1094. szOID_DOMAIN_COMPONENT = '0.9.2342.19200300.100.1.25'; // IA5 string
  1095. //+-------------------------------------------------------------------------
  1096. // CERT_RDN Attribute Value Types
  1097. //
  1098. // For RDN_ENCODED_BLOB, the Value's CERT_RDN_VALUE_BLOB is in its encoded
  1099. // representation. Otherwise, its an array of bytes.
  1100. //
  1101. // For all CERT_RDN types, Value.cbData is always the number of bytes, not
  1102. // necessarily the number of elements in the string. For instance,
  1103. // RDN_UNIVERSAL_STRING is an array of ints (cbData == intCnt * 4) and
  1104. // RDN_BMP_STRING is an array of unsigned shorts (cbData == ushortCnt * 2).
  1105. //
  1106. // For CertDecodeName, two 0 bytes are always appended to the end of the
  1107. // string (ensures a CHAR or WCHAR string is null terminated).
  1108. // These added 0 bytes are't included in the BLOB.cbData.
  1109. //--------------------------------------------------------------------------
  1110. const
  1111. CERT_RDN_ANY_TYPE = 0;
  1112. CERT_RDN_ENCODED_BLOB = 1;
  1113. CERT_RDN_OCTET_STRING = 2;
  1114. CERT_RDN_NUMERIC_STRING = 3;
  1115. CERT_RDN_PRINTABLE_STRING = 4;
  1116. CERT_RDN_TELETEX_STRING = 5;
  1117. CERT_RDN_T61_STRING = 5;
  1118. CERT_RDN_VIDEOTEX_STRING = 6;
  1119. CERT_RDN_IA5_STRING = 7;
  1120. CERT_RDN_GRAPHIC_STRING = 8;
  1121. CERT_RDN_VISIBLE_STRING = 9;
  1122. CERT_RDN_ISO646_STRING = 9;
  1123. CERT_RDN_GENERAL_STRING = 10;
  1124. CERT_RDN_UNIVERSAL_STRING = 11;
  1125. CERT_RDN_INT4_STRING = 11;
  1126. CERT_RDN_BMP_STRING = 12;
  1127. CERT_RDN_UNICODE_STRING = 12;
  1128. // Macro to check that the dwValueType is a character string and not an
  1129. // encoded blob or octet string
  1130. function IS_CERT_RDN_CHAR_STRING(X: DWORD): BOOL;
  1131. //+-------------------------------------------------------------------------
  1132. // A CERT_RDN consists of an array of the above attributes
  1133. //--------------------------------------------------------------------------
  1134. type
  1135. PCERT_RDN = ^CERT_RDN;
  1136. CERT_RDN = record
  1137. cRDNAttr: DWORD;
  1138. rgRDNAttr: PCERT_RDN_ATTR;
  1139. end;
  1140. //+-------------------------------------------------------------------------
  1141. // Information stored in a subject's or issuer's name. The information
  1142. // is represented as an array of the above RDNs.
  1143. //--------------------------------------------------------------------------
  1144. type
  1145. PCERT_NAME_INFO = ^CERT_NAME_INFO;
  1146. CERT_NAME_INFO = record
  1147. cRDN: DWORD;
  1148. rgRDN: PCERT_RDN;
  1149. end;
  1150. //+-------------------------------------------------------------------------
  1151. // Name attribute value without the Object Identifier
  1152. //
  1153. // The interpretation of the Value depends on the dwValueType.
  1154. // See above for a list of the types.
  1155. //--------------------------------------------------------------------------
  1156. type
  1157. PCERT_NAME_VALUE = ^CERT_NAME_VALUE;
  1158. CERT_NAME_VALUE = record
  1159. dwValueType: DWORD;
  1160. Value: CERT_RDN_VALUE_BLOB;
  1161. end;
  1162. //+-------------------------------------------------------------------------
  1163. // Public Key Info
  1164. //
  1165. // The PublicKey is the encoded representation of the information as it is
  1166. // stored in the bit string
  1167. //--------------------------------------------------------------------------
  1168. type
  1169. PCERT_PUBLIC_KEY_INFO = ^CERT_PUBLIC_KEY_INFO;
  1170. CERT_PUBLIC_KEY_INFO = record
  1171. Algorithm: CRYPT_ALGORITHM_IDENTIFIER;
  1172. PublicKey: CRYPT_BIT_BLOB;
  1173. end;
  1174. const
  1175. CERT_RSA_PUBLIC_KEY_OBJID = szOID_RSA_RSA;
  1176. CERT_DEFAULT_OID_PUBLIC_KEY_SIGN = szOID_RSA_RSA;
  1177. CERT_DEFAULT_OID_PUBLIC_KEY_XCHG = szOID_RSA_RSA;
  1178. //+-------------------------------------------------------------------------
  1179. // Information stored in a certificate
  1180. //
  1181. // The Issuer, Subject, Algorithm, PublicKey and Extension BLOBs are the
  1182. // encoded representation of the information.
  1183. //--------------------------------------------------------------------------
  1184. type
  1185. PCERT_INFO = ^CERT_INFO;
  1186. CERT_INFO = record
  1187. dwVersion: DWORD;
  1188. SerialNumber: CRYPT_INTEGER_BLOB;
  1189. SignatureAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  1190. Issuer: CERT_NAME_BLOB;
  1191. NotBefore: TFILETIME;
  1192. NotAfter: TFILETIME;
  1193. Subject: CERT_NAME_BLOB;
  1194. SubjectPublicKeyInfo: CERT_PUBLIC_KEY_INFO;
  1195. IssuerUniqueId: CRYPT_BIT_BLOB;
  1196. SubjectUniqueId: CRYPT_BIT_BLOB;
  1197. cExtension: DWORD;
  1198. rgExtension: PCERT_EXTENSION;
  1199. end;
  1200. //+-------------------------------------------------------------------------
  1201. // Certificate versions
  1202. //--------------------------------------------------------------------------
  1203. const
  1204. CERT_V1 = 0;
  1205. CERT_V2 = 1;
  1206. CERT_V3 = 2;
  1207. //+-------------------------------------------------------------------------
  1208. // Certificate Information Flags
  1209. //--------------------------------------------------------------------------
  1210. CERT_INFO_VERSION_FLAG = 1;
  1211. CERT_INFO_SERIAL_NUMBER_FLAG = 2;
  1212. CERT_INFO_SIGNATURE_ALGORITHM_FLAG = 3;
  1213. CERT_INFO_ISSUER_FLAG = 4;
  1214. CERT_INFO_NOT_BEFORE_FLAG = 5;
  1215. CERT_INFO_NOT_AFTER_FLAG = 6;
  1216. CERT_INFO_SUBJECT_FLAG = 7;
  1217. CERT_INFO_SUBJECT_PUBLIC_KEY_INFO_FLAG = 8;
  1218. CERT_INFO_ISSUER_UNIQUE_ID_FLAG = 9;
  1219. CERT_INFO_SUBJECT_UNIQUE_ID_FLAG = 10;
  1220. CERT_INFO_EXTENSION_FLAG = 11;
  1221. //+-------------------------------------------------------------------------
  1222. // An entry in a CRL
  1223. //
  1224. // The Extension BLOBs are the encoded representation of the information.
  1225. //--------------------------------------------------------------------------
  1226. type
  1227. PCRL_ENTRY = ^CRL_ENTRY;
  1228. CRL_ENTRY = record
  1229. SerialNumber: CRYPT_INTEGER_BLOB;
  1230. RevocationDate: TFILETIME;
  1231. cExtension: DWORD;
  1232. rgExtension: PCERT_EXTENSION;
  1233. end;
  1234. //+-------------------------------------------------------------------------
  1235. // Information stored in a CRL
  1236. //
  1237. // The Issuer, Algorithm and Extension BLOBs are the encoded
  1238. // representation of the information.
  1239. //--------------------------------------------------------------------------
  1240. type
  1241. PCRL_INFO = ^CRL_INFO;
  1242. CRL_INFO = record
  1243. dwVersion: DWORD;
  1244. SignatureAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  1245. Issuer: CERT_NAME_BLOB;
  1246. ThisUpdate: TFILETIME;
  1247. NextUpdate: TFILETIME;
  1248. cCRLEntry: DWORD;
  1249. rgCRLEntry: PCRL_ENTRY;
  1250. cExtension: DWORD;
  1251. rgExtension: PCERT_EXTENSION;
  1252. end;
  1253. //+-------------------------------------------------------------------------
  1254. // CRL versions
  1255. //--------------------------------------------------------------------------
  1256. const
  1257. CRL_V1 = 0;
  1258. CRL_V2 = 1;
  1259. //+-------------------------------------------------------------------------
  1260. // Information stored in a certificate request
  1261. //
  1262. // The Subject, Algorithm, PublicKey and Attribute BLOBs are the encoded
  1263. // representation of the information.
  1264. //--------------------------------------------------------------------------
  1265. type
  1266. PCERT_REQUEST_INFO = ^CERT_REQUEST_INFO;
  1267. CERT_REQUEST_INFO = record
  1268. dwVersion: DWORD;
  1269. Subject: CERT_NAME_BLOB;
  1270. SubjectPublicKeyInfo: CERT_PUBLIC_KEY_INFO;
  1271. cAttribute: DWORD;
  1272. rgAttribute: PCRYPT_ATTRIBUTE;
  1273. end;
  1274. //+-------------------------------------------------------------------------
  1275. // Certificate Request versions
  1276. //--------------------------------------------------------------------------
  1277. const CERT_REQUEST_V1 = 0;
  1278. //+-------------------------------------------------------------------------
  1279. // Information stored in Netscape's Keygen request
  1280. //--------------------------------------------------------------------------
  1281. type
  1282. PCERT_KEYGEN_REQUEST_INFO = ^CERT_KEYGEN_REQUEST_INFO;
  1283. CERT_KEYGEN_REQUEST_INFO = record
  1284. dwVersion: DWORD;
  1285. SubjectPublicKeyInfo: CERT_PUBLIC_KEY_INFO;
  1286. pwszChallengeString: LPWSTR; // encoded as IA5
  1287. end;
  1288. const
  1289. CERT_KEYGEN_REQUEST_V1 = 0;
  1290. //+-------------------------------------------------------------------------
  1291. // Certificate, CRL, Certificate Request or Keygen Request Signed Content
  1292. //
  1293. // The "to be signed" encoded content plus its signature. The ToBeSigned
  1294. // is the encoded CERT_INFO, CRL_INFO, CERT_REQUEST_INFO or
  1295. // CERT_KEYGEN_REQUEST_INFO.
  1296. //--------------------------------------------------------------------------
  1297. type
  1298. PCERT_SIGNED_CONTENT_INFO = ^CERT_SIGNED_CONTENT_INFO;
  1299. CERT_SIGNED_CONTENT_INFO = record
  1300. ToBeSigned: CRYPT_DER_BLOB;
  1301. SignatureAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  1302. Signature: CRYPT_BIT_BLOB;
  1303. end;
  1304. //+-------------------------------------------------------------------------
  1305. // Certificate Trust List (CTL)
  1306. //--------------------------------------------------------------------------
  1307. //+-------------------------------------------------------------------------
  1308. // CTL Usage. Also used for EnhancedKeyUsage extension.
  1309. //--------------------------------------------------------------------------
  1310. type
  1311. PCTL_USAGE = ^CTL_USAGE;
  1312. CTL_USAGE = record
  1313. cUsageIdentifier: DWORD;
  1314. rgpszUsageIdentifier: PLPSTR; // array of pszObjId
  1315. end;
  1316. type
  1317. CERT_ENHKEY_USAGE = CTL_USAGE;
  1318. PCERT_ENHKEY_USAGE = ^CERT_ENHKEY_USAGE;
  1319. //+-------------------------------------------------------------------------
  1320. // An entry in a CTL
  1321. //--------------------------------------------------------------------------
  1322. type
  1323. PCTL_ENTRY = ^CTL_ENTRY;
  1324. CTL_ENTRY = record
  1325. SubjectIdentifier: CRYPT_DATA_BLOB; // For example, its hash
  1326. cAttribute: DWORD;
  1327. rgAttribute: PCRYPT_ATTRIBUTE; // OPTIONAL
  1328. end;
  1329. //+-------------------------------------------------------------------------
  1330. // Information stored in a CTL
  1331. //--------------------------------------------------------------------------
  1332. type
  1333. PCTL_INFO = ^CTL_INFO;
  1334. CTL_INFO = record
  1335. dwVersion: DWORD;
  1336. SubjectUsage: CTL_USAGE;
  1337. ListIdentifier: CRYPT_DATA_BLOB; // OPTIONAL
  1338. SequenceNumber: CRYPT_INTEGER_BLOB; // OPTIONAL
  1339. ThisUpdate: TFILETIME;
  1340. NextUpdate: TFILETIME; // OPTIONAL
  1341. SubjectAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  1342. cCTLEntry: DWORD;
  1343. rgCTLEntry: PCTL_ENTRY; // OPTIONAL
  1344. cExtension: DWORD;
  1345. rgExtension: PCERT_EXTENSION; // OPTIONAL
  1346. end;
  1347. //+-------------------------------------------------------------------------
  1348. // CTL versions
  1349. //--------------------------------------------------------------------------
  1350. const
  1351. CTL_V1 = 0;
  1352. //+-------------------------------------------------------------------------
  1353. // TimeStamp Request
  1354. //
  1355. // The pszTimeStamp is the OID for the Time type requested
  1356. // The pszContentType is the Content Type OID for the content, usually DATA
  1357. // The Content is a un-decoded blob
  1358. //--------------------------------------------------------------------------
  1359. type
  1360. PCRYPT_TIME_STAMP_REQUEST_INFO = ^CRYPT_TIME_STAMP_REQUEST_INFO;
  1361. CRYPT_TIME_STAMP_REQUEST_INFO = record
  1362. pszTimeStampAlgorithm: LPSTR; // pszObjId
  1363. pszContentType: LPSTR; // pszObjId
  1364. Content: CRYPT_OBJID_BLOB;
  1365. cAttribute: DWORD;
  1366. rgAttribute: PCRYPT_ATTRIBUTE;
  1367. end;
  1368. //+-------------------------------------------------------------------------
  1369. // Certificate and Message encoding types
  1370. //
  1371. // The encoding type is a DWORD containing both the certificate and message
  1372. // encoding types. The certificate encoding type is stored in the LOWORD.
  1373. // The message encoding type is stored in the HIWORD. Some functions or
  1374. // structure fields require only one of the encoding types. The following
  1375. // naming convention is used to indicate which encoding type(s) are
  1376. // required:
  1377. // dwEncodingType (both encoding types are required)
  1378. // dwMsgAndCertEncodingType (both encoding types are required)
  1379. // dwMsgEncodingType (only msg encoding type is required)
  1380. // dwCertEncodingType (only cert encoding type is required)
  1381. //
  1382. // Its always acceptable to specify both.
  1383. //--------------------------------------------------------------------------
  1384. const
  1385. CERT_ENCODING_TYPE_MASK = $0000FFFF;
  1386. CMSG_ENCODING_TYPE_MASK = $FFFF0000;
  1387. //#define GET_CERT_ENCODING_TYPE(X) (X & CERT_ENCODING_TYPE_MASK)
  1388. //#define GET_CMSG_ENCODING_TYPE(X) (X & CMSG_ENCODING_TYPE_MASK)
  1389. function GET_CERT_ENCODING_TYPE(X: DWORD): DWORD;
  1390. function GET_CMSG_ENCODING_TYPE(X: DWORD): DWORD;
  1391. const
  1392. CRYPT_ASN_ENCODING = $00000001;
  1393. CRYPT_NDR_ENCODING = $00000002;
  1394. X509_ASN_ENCODING = $00000001;
  1395. X509_NDR_ENCODING = $00000002;
  1396. PKCS_7_ASN_ENCODING = $00010000;
  1397. PKCS_7_NDR_ENCODING = $00020000;
  1398. //+-------------------------------------------------------------------------
  1399. // format the specified data structure according to the certificate
  1400. // encoding type.
  1401. //
  1402. //--------------------------------------------------------------------------
  1403. function CryptFormatObject(dwCertEncodingType: DWORD;
  1404. dwFormatType: DWORD;
  1405. dwFormatStrType: DWORD;
  1406. pFormatStruct: PVOID;
  1407. lpszStructType: LPCSTR;
  1408. const pbEncoded: PBYTE;
  1409. cbEncoded: DWORD;
  1410. pbFormat: PVOID;
  1411. pcbFormat: PDWORD): BOOL; stdcall;
  1412. //+-------------------------------------------------------------------------
  1413. // Encode / decode the specified data structure according to the certificate
  1414. // encoding type.
  1415. //
  1416. // See below for a list of the predefined data structures.
  1417. //--------------------------------------------------------------------------
  1418. function CryptEncodeObject(dwCertEncodingType: DWORD;
  1419. lpszStructType: LPCSTR;
  1420. const pvStructInfo: PVOID;
  1421. pbEncoded: PBYTE;
  1422. pcbEncoded: PDWORD): BOOL; stdcall;
  1423. function CryptDecodeObject(dwCertEncodingType: DWORD;
  1424. lpszStructType: LPCSTR;
  1425. const pbEncoded: PBYTE;
  1426. cbEncoded: DWORD;
  1427. dwFlags: DWORD;
  1428. pvStructInfo: PVOID;
  1429. pcbStructInfo: PDWORD): BOOL; stdcall;
  1430. // When the following flag is set the nocopy optimization is enabled.
  1431. // This optimization where appropriate, updates the pvStructInfo fields
  1432. // to point to content residing within pbEncoded instead of making a copy
  1433. // of and appending to pvStructInfo.
  1434. //
  1435. // Note, when set, pbEncoded can't be freed until pvStructInfo is freed.
  1436. const
  1437. CRYPT_DECODE_NOCOPY_FLAG = $1;
  1438. //+-------------------------------------------------------------------------
  1439. // Predefined X509 certificate data structures that can be encoded / decoded.
  1440. //--------------------------------------------------------------------------
  1441. CRYPT_ENCODE_DECODE_NONE = 0;
  1442. X509_CERT = (LPCSTR(1));
  1443. X509_CERT_TO_BE_SIGNED = (LPCSTR(2));
  1444. X509_CERT_CRL_TO_BE_SIGNED = (LPCSTR(3));
  1445. X509_CERT_REQUEST_TO_BE_SIGNED = (LPCSTR(4));
  1446. X509_EXTENSIONS = (LPCSTR(5));
  1447. X509_NAME_VALUE = (LPCSTR(6));
  1448. X509_NAME = (LPCSTR(7));
  1449. X509_PUBLIC_KEY_INFO = (LPCSTR(8));
  1450. //+-------------------------------------------------------------------------
  1451. // Predefined X509 certificate extension data structures that can be
  1452. // encoded / decoded.
  1453. //--------------------------------------------------------------------------
  1454. X509_AUTHORITY_KEY_ID = (LPCSTR(9));
  1455. X509_KEY_ATTRIBUTES = (LPCSTR(10));
  1456. X509_KEY_USAGE_RESTRICTION = (LPCSTR(11));
  1457. X509_ALTERNATE_NAME = (LPCSTR(12));
  1458. X509_BASIC_CONSTRAINTS = (LPCSTR(13));
  1459. X509_KEY_USAGE = (LPCSTR(14));
  1460. X509_BASIC_CONSTRAINTS2 = (LPCSTR(15));
  1461. X509_CERT_POLICIES = (LPCSTR(16));
  1462. //+-------------------------------------------------------------------------
  1463. // Additional predefined data structures that can be encoded / decoded.
  1464. //--------------------------------------------------------------------------
  1465. PKCS_UTC_TIME = (LPCSTR(17));
  1466. PKCS_TIME_REQUEST = (LPCSTR(18));
  1467. RSA_CSP_PUBLICKEYBLOB = (LPCSTR(19));
  1468. X509_UNICODE_NAME = (LPCSTR(20));
  1469. X509_KEYGEN_REQUEST_TO_BE_SIGNED = (LPCSTR(21));
  1470. PKCS_ATTRIBUTE = (LPCSTR(22));
  1471. PKCS_CONTENT_INFO_SEQUENCE_OF_ANY = (LPCSTR(23));
  1472. //+-------------------------------------------------------------------------
  1473. // Predefined primitive data structures that can be encoded / decoded.
  1474. //--------------------------------------------------------------------------
  1475. X509_UNICODE_NAME_VALUE = (LPCSTR(24));
  1476. X509_ANY_STRING = X509_NAME_VALUE;
  1477. X509_UNICODE_ANY_STRING = X509_UNICODE_NAME_VALUE;
  1478. X509_OCTET_STRING = (LPCSTR(25));
  1479. X509_BITS = (LPCSTR(26));
  1480. X509_INTEGER = (LPCSTR(27));
  1481. X509_MULTI_BYTE_INTEGER = (LPCSTR(28));
  1482. X509_ENUMERATED = (LPCSTR(29));
  1483. X509_CHOICE_OF_TIME = (LPCSTR(30));
  1484. //+-------------------------------------------------------------------------
  1485. // More predefined X509 certificate extension data structures that can be
  1486. // encoded / decoded.
  1487. //--------------------------------------------------------------------------
  1488. X509_AUTHORITY_KEY_ID2 = (LPCSTR(31));
  1489. // X509_AUTHORITY_INFO_ACCESS (LPCSTR(32));
  1490. X509_CRL_REASON_CODE = X509_ENUMERATED;
  1491. PKCS_CONTENT_INFO = (LPCSTR(33));
  1492. X509_SEQUENCE_OF_ANY = (LPCSTR(34));
  1493. X509_CRL_DIST_POINTS = (LPCSTR(35));
  1494. X509_ENHANCED_KEY_USAGE = (LPCSTR(36));
  1495. PKCS_CTL = (LPCSTR(37));
  1496. X509_MULTI_BYTE_UINT = (LPCSTR(38));
  1497. X509_DSS_PUBLICKEY = X509_MULTI_BYTE_UINT;
  1498. X509_DSS_PARAMETERS = (LPCSTR(39));
  1499. X509_DSS_SIGNATURE = (LPCSTR(40));
  1500. PKCS_RC2_CBC_PARAMETERS = (LPCSTR(41));
  1501. PKCS_SMIME_CAPABILITIES = (LPCSTR(42));
  1502. //+-------------------------------------------------------------------------
  1503. // Predefined PKCS #7 data structures that can be encoded / decoded.
  1504. //--------------------------------------------------------------------------
  1505. PKCS7_SIGNER_INFO = (LPCSTR(500));
  1506. //+-------------------------------------------------------------------------
  1507. // Predefined Software Publishing Credential (SPC) data structures that
  1508. // can be encoded / decoded.
  1509. //
  1510. // Predefined values: 2000 .. 2999
  1511. //
  1512. // See spc.h for value and data structure definitions.
  1513. //--------------------------------------------------------------------------
  1514. //+-------------------------------------------------------------------------
  1515. // Extension Object Identifiers
  1516. //--------------------------------------------------------------------------
  1517. const
  1518. szOID_AUTHORITY_KEY_IDENTIFIER = '2.5.29.1';
  1519. szOID_KEY_ATTRIBUTES = '2.5.29.2';
  1520. szOID_KEY_USAGE_RESTRICTION = '2.5.29.4';
  1521. szOID_SUBJECT_ALT_NAME = '2.5.29.7';
  1522. szOID_ISSUER_ALT_NAME = '2.5.29.8';
  1523. szOID_BASIC_CONSTRAINTS = '2.5.29.10';
  1524. szOID_KEY_USAGE = '2.5.29.15';
  1525. szOID_BASIC_CONSTRAINTS2 = '2.5.29.19';
  1526. szOID_CERT_POLICIES = '2.5.29.32';
  1527. szOID_AUTHORITY_KEY_IDENTIFIER2 = '2.5.29.35';
  1528. szOID_SUBJECT_KEY_IDENTIFIER = '2.5.29.14';
  1529. szOID_SUBJECT_ALT_NAME2 = '2.5.29.17';
  1530. szOID_ISSUER_ALT_NAME2 = '2.5.29.18';
  1531. szOID_CRL_REASON_CODE = '2.5.29.21';
  1532. szOID_CRL_DIST_POINTS = '2.5.29.31';
  1533. szOID_ENHANCED_KEY_USAGE = '2.5.29.37';
  1534. // Internet Public Key Infrastructure
  1535. szOID_PKIX = '1.3.6.1.5.5.7';
  1536. szOID_AUTHORITY_INFO_ACCESS = '1.3.6.1.5.5.7.2';
  1537. // Microsoft extensions or attributes
  1538. szOID_CERT_EXTENSIONS = '1.3.6.1.4.1.311.2.1.14';
  1539. szOID_NEXT_UPDATE_LOCATION = '1.3.6.1.4.1.311.10.2';
  1540. // Microsoft PKCS #7 ContentType Object Identifiers
  1541. szOID_CTL = '1.3.6.1.4.1.311.10.1';
  1542. //+-------------------------------------------------------------------------
  1543. // Extension Object Identifiers (currently not implemented)
  1544. //--------------------------------------------------------------------------
  1545. szOID_POLICY_MAPPINGS = '2.5.29.5';
  1546. szOID_SUBJECT_DIR_ATTRS = '2.5.29.9';
  1547. //+-------------------------------------------------------------------------
  1548. // Enhanced Key Usage (Purpose) Object Identifiers
  1549. //--------------------------------------------------------------------------
  1550. const szOID_PKIX_KP = '1.3.6.1.5.5.7.3';
  1551. // Consistent key usage bits: DIGITAL_SIGNATURE, KEY_ENCIPHERMENT
  1552. // or KEY_AGREEMENT
  1553. szOID_PKIX_KP_SERVER_AUTH = '1.3.6.1.5.5.7.3.1';
  1554. // Consistent key usage bits: DIGITAL_SIGNATURE
  1555. szOID_PKIX_KP_CLIENT_AUTH = '1.3.6.1.5.5.7.3.2';
  1556. // Consistent key usage bits: DIGITAL_SIGNATURE
  1557. szOID_PKIX_KP_CODE_SIGNING = '1.3.6.1.5.5.7.3.3';
  1558. // Consistent key usage bits: DIGITAL_SIGNATURE, NON_REPUDIATION and/or
  1559. // (KEY_ENCIPHERMENT or KEY_AGREEMENT)
  1560. szOID_PKIX_KP_EMAIL_PROTECTION = '1.3.6.1.5.5.7.3.4';
  1561. //+-------------------------------------------------------------------------
  1562. // Microsoft Enhanced Key Usage (Purpose) Object Identifiers
  1563. //+-------------------------------------------------------------------------
  1564. // Signer of CTLs
  1565. szOID_KP_CTL_USAGE_SIGNING = '1.3.6.1.4.1.311.10.3.1';
  1566. // Signer of TimeStamps
  1567. szOID_KP_TIME_STAMP_SIGNING = '1.3.6.1.4.1.311.10.3.2';
  1568. //+-------------------------------------------------------------------------
  1569. // Microsoft Attribute Object Identifiers
  1570. //+-------------------------------------------------------------------------
  1571. szOID_YESNO_TRUST_ATTR = '1.3.6.1.4.1.311.10.4.1';
  1572. //+-------------------------------------------------------------------------
  1573. // X509_CERT
  1574. //
  1575. // The "to be signed" encoded content plus its signature. The ToBeSigned
  1576. // content is the CryptEncodeObject() output for one of the following:
  1577. // X509_CERT_TO_BE_SIGNED, X509_CERT_CRL_TO_BE_SIGNED or
  1578. // X509_CERT_REQUEST_TO_BE_SIGNED.
  1579. //
  1580. // pvStructInfo points to CERT_SIGNED_CONTENT_INFO.
  1581. //--------------------------------------------------------------------------
  1582. //+-------------------------------------------------------------------------
  1583. // X509_CERT_TO_BE_SIGNED
  1584. //
  1585. // pvStructInfo points to CERT_INFO.
  1586. //
  1587. // For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  1588. // signature (output of a X509_CERT CryptEncodeObject()).
  1589. //
  1590. // For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  1591. //--------------------------------------------------------------------------
  1592. //+-------------------------------------------------------------------------
  1593. // X509_CERT_CRL_TO_BE_SIGNED
  1594. //
  1595. // pvStructInfo points to CRL_INFO.
  1596. //
  1597. // For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  1598. // signature (output of a X509_CERT CryptEncodeObject()).
  1599. //
  1600. // For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  1601. //--------------------------------------------------------------------------
  1602. //+-------------------------------------------------------------------------
  1603. // X509_CERT_REQUEST_TO_BE_SIGNED
  1604. //
  1605. // pvStructInfo points to CERT_REQUEST_INFO.
  1606. //
  1607. // For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  1608. // signature (output of a X509_CERT CryptEncodeObject()).
  1609. //
  1610. // For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  1611. //--------------------------------------------------------------------------
  1612. //+-------------------------------------------------------------------------
  1613. // X509_EXTENSIONS
  1614. // szOID_CERT_EXTENSIONS
  1615. //
  1616. // pvStructInfo points to following CERT_EXTENSIONS.
  1617. //--------------------------------------------------------------------------
  1618. type
  1619. PCERT_EXTENSIONS = ^CERT_EXTENSIONS;
  1620. CERT_EXTENSIONS = record
  1621. cExtension: DWORD;
  1622. rgExtension: PCERT_EXTENSION;
  1623. end;
  1624. //+-------------------------------------------------------------------------
  1625. // X509_NAME_VALUE
  1626. // X509_ANY_STRING
  1627. //
  1628. // pvStructInfo points to CERT_NAME_VALUE.
  1629. //--------------------------------------------------------------------------
  1630. //+-------------------------------------------------------------------------
  1631. // X509_UNICODE_NAME_VALUE
  1632. // X509_UNICODE_ANY_STRING
  1633. //
  1634. // pvStructInfo points to CERT_NAME_VALUE.
  1635. //
  1636. // The name values are unicode strings.
  1637. //
  1638. // For CryptEncodeObject:
  1639. // Value.pbData points to the unicode string.
  1640. // If Value.cbData = 0, then, the unicode string is NULL terminated.
  1641. // Otherwise, Value.cbData is the unicode string byte count. The byte count
  1642. // is twice the character count.
  1643. //
  1644. // If the unicode string contains an invalid character for the specified
  1645. // dwValueType, then, *pcbEncoded is updated with the unicode character
  1646. // index of the first invalid character. LastError is set to:
  1647. // CRYPT_E_INVALID_NUMERIC_STRING, CRYPT_E_INVALID_PRINTABLE_STRING or
  1648. // CRYPT_E_INVALID_IA5_STRING.
  1649. //
  1650. // The unicode string is converted before being encoded according to
  1651. // the specified dwValueType. If dwValueType is set to 0, LastError
  1652. // is set to E_INVALIDARG.
  1653. //
  1654. // If the dwValueType isn't one of the character strings (its a
  1655. // CERT_RDN_ENCODED_BLOB or CERT_RDN_OCTET_STRING), then, CryptEncodeObject
  1656. // will return FALSE with LastError set to CRYPT_E_NOT_CHAR_STRING.
  1657. //
  1658. // For CryptDecodeObject:
  1659. // Value.pbData points to a NULL terminated unicode string. Value.cbData
  1660. // contains the byte count of the unicode string excluding the NULL
  1661. // terminator. dwValueType contains the type used in the encoded object.
  1662. // Its not forced to CERT_RDN_UNICODE_STRING. The encoded value is
  1663. // converted to the unicode string according to the dwValueType.
  1664. //
  1665. // If the encoded object isn't one of the character string types, then,
  1666. // CryptDecodeObject will return FALSE with LastError set to
  1667. // CRYPT_E_NOT_CHAR_STRING. For a non character string, decode using
  1668. // X509_NAME_VALUE or X509_ANY_STRING.
  1669. //--------------------------------------------------------------------------
  1670. //+-------------------------------------------------------------------------
  1671. // X509_NAME
  1672. //
  1673. // pvStructInfo points to CERT_NAME_INFO.
  1674. //--------------------------------------------------------------------------
  1675. //+-------------------------------------------------------------------------
  1676. // X509_UNICODE_NAME
  1677. //
  1678. // pvStructInfo points to CERT_NAME_INFO.
  1679. //
  1680. // The RDN attribute values are unicode strings except for the dwValueTypes of
  1681. // CERT_RDN_ENCODED_BLOB or CERT_RDN_OCTET_STRING. These dwValueTypes are
  1682. // the same as for a X509_NAME. Their values aren't converted to/from unicode.
  1683. //
  1684. // For CryptEncodeObject:
  1685. // Value.pbData points to the unicode string.
  1686. // If Value.cbData = 0, then, the unicode string is NULL terminated.
  1687. // Otherwise, Value.cbData is the unicode string byte count. The byte count
  1688. // is twice the character count.
  1689. //
  1690. // If dwValueType = 0 (CERT_RDN_ANY_TYPE), the pszObjId is used to find
  1691. // an acceptable dwValueType. If the unicode string contains an
  1692. // invalid character for the found or specified dwValueType, then,
  1693. // *pcbEncoded is updated with the error location of the invalid character.
  1694. // See below for details. LastError is set to:
  1695. // CRYPT_E_INVALID_NUMERIC_STRING, CRYPT_E_INVALID_PRINTABLE_STRING or
  1696. // CRYPT_E_INVALID_IA5_STRING.
  1697. //
  1698. // The unicode string is converted before being encoded according to
  1699. // the specified or ObjId matching dwValueType.
  1700. //
  1701. // For CryptDecodeObject:
  1702. // Value.pbData points to a NULL terminated unicode string. Value.cbData
  1703. // contains the byte count of the unicode string excluding the NULL
  1704. // terminator. dwValueType contains the type used in the encoded object.
  1705. // Its not forced to CERT_RDN_UNICODE_STRING. The encoded value is
  1706. // converted to the unicode string according to the dwValueType.
  1707. //
  1708. // If the dwValueType of the encoded value isn't a character string
  1709. // type, then, it isn't converted to UNICODE. Use the
  1710. // IS_CERT_RDN_CHAR_STRING() macro on the dwValueType to check
  1711. // that Value.pbData points to a converted unicode string.
  1712. //--------------------------------------------------------------------------
  1713. //+-------------------------------------------------------------------------
  1714. // Unicode Name Value Error Location Definitions
  1715. //
  1716. // Error location is returned in *pcbEncoded by
  1717. // CryptEncodeObject(X509_UNICODE_NAME)
  1718. //
  1719. // Error location consists of:
  1720. // RDN_INDEX - 10 bits << 22
  1721. // ATTR_INDEX - 6 bits << 16
  1722. // VALUE_INDEX - 16 bits (unicode character index)
  1723. //--------------------------------------------------------------------------
  1724. const
  1725. CERT_UNICODE_RDN_ERR_INDEX_MASK = $3FF;
  1726. CERT_UNICODE_RDN_ERR_INDEX_SHIFT = 22;
  1727. CERT_UNICODE_ATTR_ERR_INDEX_MASK = $003F;
  1728. CERT_UNICODE_ATTR_ERR_INDEX_SHIFT = 16;
  1729. CERT_UNICODE_VALUE_ERR_INDEX_MASK = $0000FFFF;
  1730. CERT_UNICODE_VALUE_ERR_INDEX_SHIFT = 0;
  1731. {#define GET_CERT_UNICODE_RDN_ERR_INDEX(X) \
  1732. ((X >> CERT_UNICODE_RDN_ERR_INDEX_SHIFT) & CERT_UNICODE_RDN_ERR_INDEX_MASK)}
  1733. function GET_CERT_UNICODE_RDN_ERR_INDEX(X: integer): integer;
  1734. {#define GET_CERT_UNICODE_ATTR_ERR_INDEX(X) \
  1735. ((X >> CERT_UNICODE_ATTR_ERR_INDEX_SHIFT) & CERT_UNICODE_ATTR_ERR_INDEX_MASK)}
  1736. function GET_CERT_UNICODE_ATTR_ERR_INDEX(X: integer): integer;
  1737. {#define GET_CERT_UNICODE_VALUE_ERR_INDEX(X) \
  1738. (X & CERT_UNICODE_VALUE_ERR_INDEX_MASK)}
  1739. function GET_CERT_UNICODE_VALUE_ERR_INDEX(X: integer): integer;
  1740. //+-------------------------------------------------------------------------
  1741. // X509_PUBLIC_KEY_INFO
  1742. //
  1743. // pvStructInfo points to CERT_PUBLIC_KEY_INFO.
  1744. //--------------------------------------------------------------------------
  1745. //+-------------------------------------------------------------------------
  1746. // X509_AUTHORITY_KEY_ID
  1747. // szOID_AUTHORITY_KEY_IDENTIFIER
  1748. //
  1749. // pvStructInfo points to following CERT_AUTHORITY_KEY_ID_INFO.
  1750. //--------------------------------------------------------------------------
  1751. type
  1752. PCERT_AUTHORITY_KEY_ID_INFO = ^CERT_AUTHORITY_KEY_ID_INFO;
  1753. CERT_AUTHORITY_KEY_ID_INFO = record
  1754. KeyId: CRYPT_DATA_BLOB;
  1755. CertIssuer: CERT_NAME_BLOB;
  1756. CertSerialNumber: CRYPT_INTEGER_BLOB;
  1757. end;
  1758. //+-------------------------------------------------------------------------
  1759. // X509_KEY_ATTRIBUTES
  1760. // szOID_KEY_ATTRIBUTES
  1761. //
  1762. // pvStructInfo points to following CERT_KEY_ATTRIBUTES_INFO.
  1763. //--------------------------------------------------------------------------
  1764. type
  1765. PCERT_PRIVATE_KEY_VALIDITY = ^CERT_PRIVATE_KEY_VALIDITY;
  1766. CERT_PRIVATE_KEY_VALIDITY = record
  1767. NotBefore: TFILETIME;
  1768. NotAfter: TFILETIME;
  1769. end;
  1770. type
  1771. PCERT_KEY_ATTRIBUTES_INFO = ^CERT_KEY_ATTRIBUTES_INFO;
  1772. CERT_KEY_ATTRIBUTES_INFO = record
  1773. KeyId: CRYPT_DATA_BLOB;
  1774. IntendedKeyUsage: CRYPT_BIT_BLOB;
  1775. pPrivateKeyUsagePeriod: PCERT_PRIVATE_KEY_VALIDITY; // OPTIONAL
  1776. end;
  1777. const
  1778. CERT_DIGITAL_SIGNATURE_KEY_USAGE = $80;
  1779. CERT_NON_REPUDIATION_KEY_USAGE = $40;
  1780. CERT_KEY_ENCIPHERMENT_KEY_USAGE = $20;
  1781. CERT_DATA_ENCIPHERMENT_KEY_USAGE = $10;
  1782. CERT_KEY_AGREEMENT_KEY_USAGE = $08;
  1783. CERT_KEY_CERT_SIGN_KEY_USAGE = $04;
  1784. CERT_OFFLINE_CRL_SIGN_KEY_USAGE = $02;
  1785. CERT_CRL_SIGN_KEY_USAGE = $02;
  1786. //+-------------------------------------------------------------------------
  1787. // X509_KEY_USAGE_RESTRICTION
  1788. // szOID_KEY_USAGE_RESTRICTION
  1789. //
  1790. // pvStructInfo points to following CERT_KEY_USAGE_RESTRICTION_INFO.
  1791. //--------------------------------------------------------------------------
  1792. type
  1793. PCERT_POLICY_ID = ^CERT_POLICY_ID;
  1794. CERT_POLICY_ID = record
  1795. cCertPolicyElementId: DWORD;
  1796. rgpszCertPolicyElementId: PLPSTR; // pszObjId
  1797. end;
  1798. type
  1799. PCERT_KEY_USAGE_RESTRICTION_INFO = ^CERT_KEY_USAGE_RESTRICTION_INFO;
  1800. CERT_KEY_USAGE_RESTRICTION_INFO = record
  1801. cCertPolicyId: DWORD;
  1802. rgCertPolicyId: PCERT_POLICY_ID;
  1803. RestrictedKeyUsage: CRYPT_BIT_BLOB;
  1804. end;
  1805. // See CERT_KEY_ATTRIBUTES_INFO for definition of the RestrictedKeyUsage bits
  1806. //+-------------------------------------------------------------------------
  1807. // X509_ALTERNATE_NAME
  1808. // szOID_SUBJECT_ALT_NAME
  1809. // szOID_ISSUER_ALT_NAME
  1810. // szOID_SUBJECT_ALT_NAME2
  1811. // szOID_ISSUER_ALT_NAME2
  1812. //
  1813. // pvStructInfo points to following CERT_ALT_NAME_INFO.
  1814. //--------------------------------------------------------------------------
  1815. type
  1816. PCERT_ALT_NAME_ENTRY = ^CERT_ALT_NAME_ENTRY;
  1817. CERT_ALT_NAME_ENTRY = record
  1818. dwAltNameChoice: DWORD;
  1819. case integer of
  1820. {1}0: ({OtherName :Not implemented});
  1821. {2}1: (pwszRfc822Name: LPWSTR); //(encoded IA5)
  1822. {3}2: (pwszDNSName: LPWSTR); //(encoded IA5)
  1823. {4}3: ({x400Address :Not implemented});
  1824. {5}4: (DirectoryName: CERT_NAME_BLOB);
  1825. {6}5: ({pEdiPartyName :Not implemented});
  1826. {7}6: (pwszURL: LPWSTR); //(encoded IA5)
  1827. {8}7: (IPAddress: CRYPT_DATA_BLOB); //(Octet String)
  1828. {9}8: (pszRegisteredID: LPSTR); //(Octet String)
  1829. end;
  1830. const
  1831. CERT_ALT_NAME_OTHER_NAME = 1;
  1832. CERT_ALT_NAME_RFC822_NAME = 2;
  1833. CERT_ALT_NAME_DNS_NAME = 3;
  1834. CERT_ALT_NAME_X400_ADDRESS = 4;
  1835. CERT_ALT_NAME_DIRECTORY_NAME = 5;
  1836. CERT_ALT_NAME_EDI_PARTY_NAME = 6;
  1837. CERT_ALT_NAME_URL = 7;
  1838. CERT_ALT_NAME_IP_ADDRESS = 8;
  1839. CERT_ALT_NAME_REGISTERED_ID = 9;
  1840. type
  1841. PCERT_ALT_NAME_INFO = ^CERT_ALT_NAME_INFO;
  1842. CERT_ALT_NAME_INFO = record
  1843. cAltEntry: DWORD;
  1844. rgAltEntry: PCERT_ALT_NAME_ENTRY;
  1845. end;
  1846. //+-------------------------------------------------------------------------
  1847. // Alternate name IA5 Error Location Definitions for
  1848. // CRYPT_E_INVALID_IA5_STRING.
  1849. //
  1850. // Error location is returned in *pcbEncoded by
  1851. // CryptEncodeObject(X509_ALTERNATE_NAME)
  1852. //
  1853. // Error location consists of:
  1854. // ENTRY_INDEX - 8 bits << 16
  1855. // VALUE_INDEX - 16 bits (unicode character index)
  1856. //--------------------------------------------------------------------------
  1857. const
  1858. CERT_ALT_NAME_ENTRY_ERR_INDEX_MASK = $FF;
  1859. CERT_ALT_NAME_ENTRY_ERR_INDEX_SHIFT = 16;
  1860. CERT_ALT_NAME_VALUE_ERR_INDEX_MASK = $0000FFFF;
  1861. CERT_ALT_NAME_VALUE_ERR_INDEX_SHIFT = 0;
  1862. {#define GET_CERT_ALT_NAME_ENTRY_ERR_INDEX(X) \
  1863. ((X >> CERT_ALT_NAME_ENTRY_ERR_INDEX_SHIFT) & \
  1864. CERT_ALT_NAME_ENTRY_ERR_INDEX_MASK)}
  1865. function GET_CERT_ALT_NAME_ENTRY_ERR_INDEX(X: DWORD): DWORD;
  1866. {#define GET_CERT_ALT_NAME_VALUE_ERR_INDEX(X) \
  1867. (X & CERT_ALT_NAME_VALUE_ERR_INDEX_MASK)}
  1868. function GET_CERT_ALT_NAME_VALUE_ERR_INDEX(X: DWORD): DWORD;
  1869. //+-------------------------------------------------------------------------
  1870. // X509_BASIC_CONSTRAINTS
  1871. // szOID_BASIC_CONSTRAINTS
  1872. //
  1873. // pvStructInfo points to following CERT_BASIC_CONSTRAINTS_INFO.
  1874. //--------------------------------------------------------------------------
  1875. type
  1876. PCERT_BASIC_CONSTRAINTS_INFO = ^CERT_BASIC_CONSTRAINTS_INFO;
  1877. CERT_BASIC_CONSTRAINTS_INFO = record
  1878. SubjectType: CRYPT_BIT_BLOB;
  1879. fPathLenConstraint: BOOL;
  1880. dwPathLenConstraint: DWORD;
  1881. cSubtreesConstraint: DWORD;
  1882. rgSubtreesConstraint: PCERT_NAME_BLOB;
  1883. end;
  1884. const
  1885. CERT_CA_SUBJECT_FLAG = $80;
  1886. CERT_END_ENTITY_SUBJECT_FLAG = $40;
  1887. //+-------------------------------------------------------------------------
  1888. // X509_BASIC_CONSTRAINTS2
  1889. // szOID_BASIC_CONSTRAINTS2
  1890. //
  1891. // pvStructInfo points to following CERT_BASIC_CONSTRAINTS2_INFO.
  1892. //--------------------------------------------------------------------------
  1893. type
  1894. PCERT_BASIC_CONSTRAINTS2_INFO = ^CERT_BASIC_CONSTRAINTS2_INFO;
  1895. CERT_BASIC_CONSTRAINTS2_INFO = record
  1896. fCA: BOOL;
  1897. fPathLenConstraint: BOOL;
  1898. dwPathLenConstraint: DWORD;
  1899. end;
  1900. //+-------------------------------------------------------------------------
  1901. // X509_KEY_USAGE
  1902. // szOID_KEY_USAGE
  1903. //
  1904. // pvStructInfo points to a CRYPT_BIT_BLOB. Has same bit definitions as
  1905. // CERT_KEY_ATTRIBUTES_INFO's IntendedKeyUsage.
  1906. //--------------------------------------------------------------------------
  1907. //+-------------------------------------------------------------------------
  1908. // X509_CERT_POLICIES
  1909. // szOID_CERT_POLICIES
  1910. //
  1911. // pvStructInfo points to following CERT_POLICIES_INFO.
  1912. //--------------------------------------------------------------------------
  1913. type
  1914. PCERT_POLICY_QUALIFIER_INFO = ^CERT_POLICY_QUALIFIER_INFO;
  1915. CERT_POLICY_QUALIFIER_INFO = record
  1916. pszPolicyQualifierId: LPSTR; // pszObjId
  1917. Qualifier: CRYPT_OBJID_BLOB; // optional
  1918. end;
  1919. type
  1920. PCERT_POLICY_INFO = ^CERT_POLICY_INFO;
  1921. CERT_POLICY_INFO = record
  1922. pszPolicyIdentifier: LPSTR; // pszObjId
  1923. cPolicyQualifier: DWORD; // optional
  1924. rgPolicyQualifier: PCERT_POLICY_QUALIFIER_INFO;
  1925. end;
  1926. type
  1927. PCERT_POLICIES_INFO = ^CERT_POLICIES_INFO;
  1928. CERT_POLICIES_INFO = record
  1929. cPolicyInfo: DWORD;
  1930. rgPolicyInfo: PCERT_POLICY_INFO;
  1931. end;
  1932. //+-------------------------------------------------------------------------
  1933. // RSA_CSP_PUBLICKEYBLOB
  1934. //
  1935. // pvStructInfo points to a PUBLICKEYSTRUC immediately followed by a
  1936. // RSAPUBKEY and the modulus bytes.
  1937. //
  1938. // CryptExportKey outputs the above StructInfo for a dwBlobType of
  1939. // PUBLICKEYBLOB. CryptImportKey expects the above StructInfo when
  1940. // importing a public key.
  1941. //
  1942. // For dwCertEncodingType = X509_ASN_ENCODING, the RSA_CSP_PUBLICKEYBLOB is
  1943. // encoded as a PKCS #1 RSAPublicKey consisting of a SEQUENCE of a
  1944. // modulus INTEGER and a publicExponent INTEGER. The modulus is encoded
  1945. // as being a unsigned integer. When decoded, if the modulus was encoded
  1946. // as unsigned integer with a leading 0 byte, the 0 byte is removed before
  1947. // converting to the CSP modulus bytes.
  1948. //
  1949. // For decode, the aiKeyAlg field of PUBLICKEYSTRUC is always set to
  1950. // CALG_RSA_KEYX.
  1951. //--------------------------------------------------------------------------
  1952. //+-------------------------------------------------------------------------
  1953. // X509_KEYGEN_REQUEST_TO_BE_SIGNED
  1954. //
  1955. // pvStructInfo points to CERT_KEYGEN_REQUEST_INFO.
  1956. //
  1957. // For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  1958. // signature (output of a X509_CERT CryptEncodeObject()).
  1959. //
  1960. // For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  1961. //--------------------------------------------------------------------------
  1962. //+-------------------------------------------------------------------------
  1963. // PKCS_ATTRIBUTE data structure
  1964. //
  1965. // pvStructInfo points to a CRYPT_ATTRIBUTE.
  1966. //--------------------------------------------------------------------------
  1967. //+-------------------------------------------------------------------------
  1968. // PKCS_CONTENT_INFO_SEQUENCE_OF_ANY data structure
  1969. //
  1970. // pvStructInfo points to following CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY.
  1971. //
  1972. // For X509_ASN_ENCODING: encoded as a PKCS#7 ContentInfo structure wrapping
  1973. // a sequence of ANY. The value of the contentType field is pszObjId,
  1974. // while the content field is the following structure:
  1975. // SequenceOfAny ::= SEQUENCE OF ANY
  1976. //
  1977. // The CRYPT_DER_BLOBs point to the already encoded ANY content.
  1978. //--------------------------------------------------------------------------
  1979. type
  1980. PCRYPT_CONTENT_INFO_SEQUENCE_OF_ANY = ^CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY;
  1981. CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY = record
  1982. pszObjId: LPSTR;
  1983. cValue: DWORD;
  1984. rgValue: PCRYPT_DER_BLOB;
  1985. end;
  1986. //+-------------------------------------------------------------------------
  1987. // PKCS_CONTENT_INFO data structure
  1988. //
  1989. // pvStructInfo points to following CRYPT_CONTENT_INFO.
  1990. //
  1991. // For X509_ASN_ENCODING: encoded as a PKCS#7 ContentInfo structure.
  1992. // The CRYPT_DER_BLOB points to the already encoded ANY content.
  1993. //--------------------------------------------------------------------------
  1994. type
  1995. PCRYPT_CONTENT_INFO = ^CRYPT_CONTENT_INFO;
  1996. CRYPT_CONTENT_INFO = record
  1997. pszObjId: LPSTR;
  1998. Content: CRYPT_DER_BLOB;
  1999. end;
  2000. //+-------------------------------------------------------------------------
  2001. // X509_OCTET_STRING data structure
  2002. //
  2003. // pvStructInfo points to a CRYPT_DATA_BLOB.
  2004. //--------------------------------------------------------------------------
  2005. //+-------------------------------------------------------------------------
  2006. // X509_BITS data structure
  2007. //
  2008. // pvStructInfo points to a CRYPT_BIT_BLOB.
  2009. //--------------------------------------------------------------------------
  2010. //+-------------------------------------------------------------------------
  2011. // X509_INTEGER data structure
  2012. //
  2013. // pvStructInfo points to an int.
  2014. //--------------------------------------------------------------------------
  2015. //+-------------------------------------------------------------------------
  2016. // X509_MULTI_BYTE_INTEGER data structure
  2017. //
  2018. // pvStructInfo points to a CRYPT_INTEGER_BLOB.
  2019. //--------------------------------------------------------------------------
  2020. //+-------------------------------------------------------------------------
  2021. // X509_ENUMERATED data structure
  2022. //
  2023. // pvStructInfo points to an int containing the enumerated value
  2024. //--------------------------------------------------------------------------
  2025. //+-------------------------------------------------------------------------
  2026. // X509_CHOICE_OF_TIME data structure
  2027. //
  2028. // pvStructInfo points to a FILETIME.
  2029. //--------------------------------------------------------------------------
  2030. //+-------------------------------------------------------------------------
  2031. // X509_SEQUENCE_OF_ANY data structure
  2032. //
  2033. // pvStructInfo points to following CRYPT_SEQUENCE_OF_ANY.
  2034. //
  2035. // The CRYPT_DER_BLOBs point to the already encoded ANY content.
  2036. //--------------------------------------------------------------------------
  2037. type
  2038. PCRYPT_SEQUENCE_OF_ANY = ^CRYPT_SEQUENCE_OF_ANY;
  2039. CRYPT_SEQUENCE_OF_ANY = record
  2040. cValue: DWORD;
  2041. rgValue: PCRYPT_DER_BLOB;
  2042. end;
  2043. //+-------------------------------------------------------------------------
  2044. // X509_AUTHORITY_KEY_ID2
  2045. // szOID_AUTHORITY_KEY_IDENTIFIER2
  2046. //
  2047. // pvStructInfo points to following CERT_AUTHORITY_KEY_ID2_INFO.
  2048. //
  2049. // For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  2050. // *pcbEncoded by CryptEncodeObject(X509_AUTHORITY_KEY_ID2)
  2051. //
  2052. // See X509_ALTERNATE_NAME for error location defines.
  2053. //--------------------------------------------------------------------------
  2054. type
  2055. PCERT_AUTHORITY_KEY_ID2_INFO = ^CERT_AUTHORITY_KEY_ID2_INFO;
  2056. CERT_AUTHORITY_KEY_ID2_INFO = record
  2057. KeyId: CRYPT_DATA_BLOB;
  2058. AuthorityCertIssuer: CERT_ALT_NAME_INFO; // Optional, set cAltEntry to 0 to omit.
  2059. AuthorityCertSerialNumber: CRYPT_INTEGER_BLOB;
  2060. end;
  2061. //+-------------------------------------------------------------------------
  2062. // szOID_SUBJECT_KEY_IDENTIFIER
  2063. //
  2064. // pvStructInfo points to a CRYPT_DATA_BLOB.
  2065. //--------------------------------------------------------------------------
  2066. //+-------------------------------------------------------------------------
  2067. // X509_CRL_REASON_CODE
  2068. // szOID_CRL_REASON_CODE
  2069. //
  2070. // pvStructInfo points to an int which can be set to one of the following
  2071. // enumerated values:
  2072. //--------------------------------------------------------------------------
  2073. const
  2074. CRL_REASON_UNSPECIFIED = 0;
  2075. CRL_REASON_KEY_COMPROMISE = 1;
  2076. CRL_REASON_CA_COMPROMISE = 2;
  2077. CRL_REASON_AFFILIATION_CHANGED = 3;
  2078. CRL_REASON_SUPERSEDED = 4;
  2079. CRL_REASON_CESSATION_OF_OPERATION = 5;
  2080. CRL_REASON_CERTIFICATE_HOLD = 6;
  2081. CRL_REASON_REMOVE_FROM_CRL = 8;
  2082. //+-------------------------------------------------------------------------
  2083. // X509_CRL_DIST_POINTS
  2084. // szOID_CRL_DIST_POINTS
  2085. //
  2086. // pvStructInfo points to following CRL_DIST_POINTS_INFO.
  2087. //
  2088. // For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  2089. // *pcbEncoded by CryptEncodeObject(X509_CRL_DIST_POINTS)
  2090. //
  2091. // Error location consists of:
  2092. // CRL_ISSUER_BIT - 1 bit << 31 (0 for FullName, 1 for CRLIssuer)
  2093. // POINT_INDEX - 7 bits << 24
  2094. // ENTRY_INDEX - 8 bits << 16
  2095. // VALUE_INDEX - 16 bits (unicode character index)
  2096. //
  2097. // See X509_ALTERNATE_NAME for ENTRY_INDEX and VALUE_INDEX error location
  2098. // defines.
  2099. //--------------------------------------------------------------------------
  2100. type
  2101. PCRL_DIST_POINT_NAME = ^CRL_DIST_POINT_NAME;
  2102. CRL_DIST_POINT_NAME = record
  2103. dwDistPointNameChoice: DWORD;
  2104. case integer of
  2105. 0: (FullName: CERT_ALT_NAME_INFO); {1}
  2106. 1: ({IssuerRDN :Not implemented}); {2}
  2107. end;
  2108. const
  2109. CRL_DIST_POINT_NO_NAME = 0;
  2110. CRL_DIST_POINT_FULL_NAME = 1;
  2111. CRL_DIST_POINT_ISSUER_RDN_NAME = 2;
  2112. type
  2113. PCRL_DIST_POINT = ^CRL_DIST_POINT;
  2114. CRL_DIST_POINT = record
  2115. DistPointName: CRL_DIST_POINT_NAME; // OPTIONAL
  2116. ReasonFlags: CRYPT_BIT_BLOB; // OPTIONAL
  2117. CRLIssuer: CERT_ALT_NAME_INFO; // OPTIONAL
  2118. end;
  2119. const
  2120. CRL_REASON_UNUSED_FLAG = $80;
  2121. CRL_REASON_KEY_COMPROMISE_FLAG = $40;
  2122. CRL_REASON_CA_COMPROMISE_FLAG = $20;
  2123. CRL_REASON_AFFILIATION_CHANGED_FLAG = $10;
  2124. CRL_REASON_SUPERSEDED_FLAG = $08;
  2125. CRL_REASON_CESSATION_OF_OPERATION_FLAG = $04;
  2126. CRL_REASON_CERTIFICATE_HOLD_FLAG = $02;
  2127. type
  2128. PCRL_DIST_POINTS_INFO = ^CRL_DIST_POINTS_INFO;
  2129. CRL_DIST_POINTS_INFO = record
  2130. cDistPoint: DWORD;
  2131. rgDistPoint: PCRL_DIST_POINT;
  2132. end;
  2133. const
  2134. CRL_DIST_POINT_ERR_INDEX_MASK = $7F;
  2135. CRL_DIST_POINT_ERR_INDEX_SHIFT = 24;
  2136. {#define GET_CRL_DIST_POINT_ERR_INDEX(X) \
  2137. ((X >> CRL_DIST_POINT_ERR_INDEX_SHIFT) & CRL_DIST_POINT_ERR_INDEX_MASK)}
  2138. function GET_CRL_DIST_POINT_ERR_INDEX(X: DWORD): DWORD;
  2139. const CRL_DIST_POINT_ERR_CRL_ISSUER_BIT = (DWORD($80000000));
  2140. {#define IS_CRL_DIST_POINT_ERR_CRL_ISSUER(X) \
  2141. (0 != (X & CRL_DIST_POINT_ERR_CRL_ISSUER_BIT))}
  2142. function IS_CRL_DIST_POINT_ERR_CRL_ISSUER(X: DWORD): BOOL;
  2143. //+-------------------------------------------------------------------------
  2144. // X509_ENHANCED_KEY_USAGE
  2145. // szOID_ENHANCED_KEY_USAGE
  2146. //
  2147. // pvStructInfo points to a CERT_ENHKEY_USAGE, CTL_USAGE.
  2148. //--------------------------------------------------------------------------
  2149. //+-------------------------------------------------------------------------
  2150. // szOID_NEXT_UPDATE_LOCATION
  2151. //
  2152. // pvStructInfo points to a CERT_ALT_NAME_INFO.
  2153. //--------------------------------------------------------------------------
  2154. //+-------------------------------------------------------------------------
  2155. // PKCS_CTL
  2156. // szOID_CTL
  2157. //
  2158. // pvStructInfo points to a CTL_INFO.
  2159. //--------------------------------------------------------------------------
  2160. //+-------------------------------------------------------------------------
  2161. // X509_MULTI_BYTE_UINT
  2162. //
  2163. // pvStructInfo points to a CRYPT_UINT_BLOB. Before encoding, inserts a
  2164. // leading 0x00. After decoding, removes a leading 0x00.
  2165. //--------------------------------------------------------------------------
  2166. //+-------------------------------------------------------------------------
  2167. // X509_DSS_PUBLICKEY
  2168. //
  2169. // pvStructInfo points to a CRYPT_UINT_BLOB.
  2170. //--------------------------------------------------------------------------
  2171. //+-------------------------------------------------------------------------
  2172. // X509_DSS_PARAMETERS
  2173. //
  2174. // pvStructInfo points to following CERT_DSS_PARAMETERS data structure.
  2175. //--------------------------------------------------------------------------
  2176. type
  2177. PCERT_DSS_PARAMETERS = ^CERT_DSS_PARAMETERS;
  2178. CERT_DSS_PARAMETERS = record
  2179. p: CRYPT_UINT_BLOB;
  2180. q: CRYPT_UINT_BLOB;
  2181. g: CRYPT_UINT_BLOB;
  2182. end;
  2183. //+-------------------------------------------------------------------------
  2184. // X509_DSS_SIGNATURE
  2185. //
  2186. // pvStructInfo is a BYTE rgbSignature[CERT_DSS_SIGNATURE_LEN]. The
  2187. // bytes are ordered as output by the DSS CSP's CryptSignHash().
  2188. //--------------------------------------------------------------------------
  2189. const
  2190. CERT_DSS_R_LEN = 20;
  2191. CERT_DSS_S_LEN = 20;
  2192. CERT_DSS_SIGNATURE_LEN = (CERT_DSS_R_LEN + CERT_DSS_S_LEN);
  2193. // Sequence of 2 unsigned integers (the extra +1 is for a potential leading
  2194. // 0x00 to make the integer unsigned)
  2195. CERT_MAX_ASN_ENCODED_DSS_SIGNATURE_LEN = (2 + 2 * (2 + 20 + 1));
  2196. //+-------------------------------------------------------------------------
  2197. // PKCS_RC2_CBC_PARAMETERS
  2198. // szOID_RSA_RC2CBC
  2199. //
  2200. // pvStructInfo points to following CRYPT_RC2_CBC_PARAMETERS data structure.
  2201. //--------------------------------------------------------------------------
  2202. type
  2203. PCRYPT_RC2_CBC_PARAMETERS = ^CRYPT_RC2_CBC_PARAMETERS;
  2204. CRYPT_RC2_CBC_PARAMETERS = record
  2205. dwVersion: DWORD;
  2206. fIV: BOOL; // set if has following IV
  2207. rgbIV: array[0..8 - 1] of BYTE;
  2208. end;
  2209. const
  2210. CRYPT_RC2_40BIT_VERSION = 160;
  2211. CRYPT_RC2_64BIT_VERSION = 120;
  2212. CRYPT_RC2_128BIT_VERSION = 58;
  2213. //+-------------------------------------------------------------------------
  2214. // PKCS_SMIME_CAPABILITIES
  2215. // szOID_RSA_SMIMECapabilities
  2216. //
  2217. // pvStructInfo points to following CRYPT_SMIME_CAPABILITIES data structure.
  2218. //
  2219. // Note, for CryptEncodeObject(X509_ASN_ENCODING), Parameters.cbData == 0
  2220. // causes the encoded parameters to be omitted and not encoded as a NULL
  2221. // (05 00) as is done when encoding a CRYPT_ALGORITHM_IDENTIFIER. This
  2222. // is per the SMIME specification for encoding capabilities.
  2223. //--------------------------------------------------------------------------
  2224. type
  2225. PCRYPT_SMIME_CAPABILITY = ^CRYPT_SMIME_CAPABILITY;
  2226. CRYPT_SMIME_CAPABILITY = record
  2227. pszObjId: LPSTR;
  2228. Parameters: CRYPT_OBJID_BLOB;
  2229. end;
  2230. type
  2231. PCRYPT_SMIME_CAPABILITIES = ^CRYPT_SMIME_CAPABILITIES;
  2232. CRYPT_SMIME_CAPABILITIES = record
  2233. cCapability: DWORD;
  2234. rgCapability: PCRYPT_SMIME_CAPABILITY;
  2235. end;
  2236. //+-------------------------------------------------------------------------
  2237. // PKCS7_SIGNER_INFO
  2238. //
  2239. // pvStructInfo points to CMSG_SIGNER_INFO.
  2240. //--------------------------------------------------------------------------
  2241. //+-------------------------------------------------------------------------
  2242. // Netscape Certificate Extension Object Identifiers
  2243. //--------------------------------------------------------------------------
  2244. const
  2245. szOID_NETSCAPE = '2.16.840.1.113730';
  2246. szOID_NETSCAPE_CERT_EXTENSION = '2.16.840.1.113730.1';
  2247. szOID_NETSCAPE_CERT_TYPE = '2.16.840.1.113730.1.1';
  2248. szOID_NETSCAPE_BASE_URL = '2.16.840.1.113730.1.2';
  2249. szOID_NETSCAPE_REVOCATION_URL = '2.16.840.1.113730.1.3';
  2250. szOID_NETSCAPE_CA_REVOCATION_URL = '2.16.840.1.113730.1.4';
  2251. szOID_NETSCAPE_CERT_RENEWAL_URL = '2.16.840.1.113730.1.7';
  2252. szOID_NETSCAPE_CA_POLICY_URL = '2.16.840.1.113730.1.8';
  2253. szOID_NETSCAPE_SSL_SERVER_NAME = '2.16.840.1.113730.1.12';
  2254. szOID_NETSCAPE_COMMENT = '2.16.840.1.113730.1.13';
  2255. //+-------------------------------------------------------------------------
  2256. // Netscape Certificate Data Type Object Identifiers
  2257. //--------------------------------------------------------------------------
  2258. const
  2259. szOID_NETSCAPE_DATA_TYPE = '2.16.840.1.113730.2';
  2260. szOID_NETSCAPE_CERT_SEQUENCE = '2.16.840.1.113730.2.5';
  2261. //+-------------------------------------------------------------------------
  2262. // szOID_NETSCAPE_CERT_TYPE extension
  2263. //
  2264. // Its value is a bit string. CryptDecodeObject/CryptEncodeObject using
  2265. // X509_BITS.
  2266. //
  2267. // The following bits are defined:
  2268. //--------------------------------------------------------------------------
  2269. const
  2270. NETSCAPE_SSL_CLIENT_AUTH_CERT_TYPE = $80;
  2271. NETSCAPE_SSL_SERVER_AUTH_CERT_TYPE = $40;
  2272. NETSCAPE_SSL_CA_CERT_TYPE = $04;
  2273. //+-------------------------------------------------------------------------
  2274. // szOID_NETSCAPE_BASE_URL extension
  2275. //
  2276. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  2277. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  2278. // dwValueType = CERT_RDN_IA5_STRING.
  2279. //
  2280. // When present this string is added to the beginning of all relative URLs
  2281. // in the certificate. This extension can be considered an optimization
  2282. // to reduce the size of the URL extensions.
  2283. //--------------------------------------------------------------------------
  2284. //+-------------------------------------------------------------------------
  2285. // szOID_NETSCAPE_REVOCATION_URL extension
  2286. //
  2287. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  2288. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  2289. // dwValueType = CERT_RDN_IA5_STRING.
  2290. //
  2291. // It is a relative or absolute URL that can be used to check the
  2292. // revocation status of a certificate. The revocation check will be
  2293. // performed as an HTTP GET method using a url that is the concatenation of
  2294. // revocation-url and certificate-serial-number.
  2295. // Where the certificate-serial-number is encoded as a string of
  2296. // ascii hexadecimal digits. For example, if the netscape-base-url is
  2297. // https://www.certs-r-us.com/, the netscape-revocation-url is
  2298. // cgi-bin/check-rev.cgi?, and the certificate serial number is 173420,
  2299. // the resulting URL would be:
  2300. // https://www.certs-r-us.com/cgi-bin/check-rev.cgi?02a56c
  2301. //
  2302. // The server should return a document with a Content-Type of
  2303. // application/x-netscape-revocation. The document should contain
  2304. // a single ascii digit, '1' if the certificate is not curently valid,
  2305. // and '0' if it is curently valid.
  2306. //
  2307. // Note: for all of the URLs that include the certificate serial number,
  2308. // the serial number will be encoded as a string which consists of an even
  2309. // number of hexadecimal digits. If the number of significant digits is odd,
  2310. // the string will have a single leading zero to ensure an even number of
  2311. // digits is generated.
  2312. //--------------------------------------------------------------------------
  2313. //+-------------------------------------------------------------------------
  2314. // szOID_NETSCAPE_CA_REVOCATION_URL extension
  2315. //
  2316. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  2317. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  2318. // dwValueType = CERT_RDN_IA5_STRING.
  2319. //
  2320. // It is a relative or absolute URL that can be used to check the
  2321. // revocation status of any certificates that are signed by the CA that
  2322. // this certificate belongs to. This extension is only valid in CA
  2323. // certificates. The use of this extension is the same as the above
  2324. // szOID_NETSCAPE_REVOCATION_URL extension.
  2325. //--------------------------------------------------------------------------
  2326. //+-------------------------------------------------------------------------
  2327. // szOID_NETSCAPE_CERT_RENEWAL_URL extension
  2328. //
  2329. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  2330. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  2331. // dwValueType = CERT_RDN_IA5_STRING.
  2332. //
  2333. // It is a relative or absolute URL that points to a certificate renewal
  2334. // form. The renewal form will be accessed with an HTTP GET method using a
  2335. // url that is the concatenation of renewal-url and
  2336. // certificate-serial-number. Where the certificate-serial-number is
  2337. // encoded as a string of ascii hexadecimal digits. For example, if the
  2338. // netscape-base-url is https://www.certs-r-us.com/, the
  2339. // netscape-cert-renewal-url is cgi-bin/check-renew.cgi?, and the
  2340. // certificate serial number is 173420, the resulting URL would be:
  2341. // https://www.certs-r-us.com/cgi-bin/check-renew.cgi?02a56c
  2342. // The document returned should be an HTML form that will allow the user
  2343. // to request a renewal of their certificate.
  2344. //--------------------------------------------------------------------------
  2345. //+-------------------------------------------------------------------------
  2346. // szOID_NETSCAPE_CA_POLICY_URL extension
  2347. //
  2348. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  2349. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  2350. // dwValueType = CERT_RDN_IA5_STRING.
  2351. //
  2352. // It is a relative or absolute URL that points to a web page that
  2353. // describes the policies under which the certificate was issued.
  2354. //--------------------------------------------------------------------------
  2355. //+-------------------------------------------------------------------------
  2356. // szOID_NETSCAPE_SSL_SERVER_NAME extension
  2357. //
  2358. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  2359. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  2360. // dwValueType = CERT_RDN_IA5_STRING.
  2361. //
  2362. // It is a "shell expression" that can be used to match the hostname of the
  2363. // SSL server that is using this certificate. It is recommended that if
  2364. // the server's hostname does not match this pattern the user be notified
  2365. // and given the option to terminate the SSL connection. If this extension
  2366. // is not present then the CommonName in the certificate subject's
  2367. // distinguished name is used for the same purpose.
  2368. //--------------------------------------------------------------------------
  2369. //+-------------------------------------------------------------------------
  2370. // szOID_NETSCAPE_COMMENT extension
  2371. //
  2372. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  2373. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  2374. // dwValueType = CERT_RDN_IA5_STRING.
  2375. //
  2376. // It is a comment that may be displayed to the user when the certificate
  2377. // is viewed.
  2378. //--------------------------------------------------------------------------
  2379. //+-------------------------------------------------------------------------
  2380. // szOID_NETSCAPE_CERT_SEQUENCE
  2381. //
  2382. // Its value is a PKCS#7 ContentInfo structure wrapping a sequence of
  2383. // certificates. The value of the contentType field is
  2384. // szOID_NETSCAPE_CERT_SEQUENCE, while the content field is the following
  2385. // structure:
  2386. // CertificateSequence ::= SEQUENCE OF Certificate.
  2387. //
  2388. // CryptDecodeObject/CryptEncodeObject using
  2389. // PKCS_CONTENT_INFO_SEQUENCE_OF_ANY, where,
  2390. // pszObjId = szOID_NETSCAPE_CERT_SEQUENCE and the CRYPT_DER_BLOBs point
  2391. // to encoded X509 certificates.
  2392. //--------------------------------------------------------------------------
  2393. //+=========================================================================
  2394. // Object IDentifier (OID) Installable Functions: Data Structures and APIs
  2395. //==========================================================================
  2396. type
  2397. HCRYPTOIDFUNCSET = procedure;
  2398. HCRYPTOIDFUNCADDR = procedure;
  2399. // Predefined OID Function Names
  2400. const
  2401. CRYPT_OID_ENCODE_OBJECT_FUNC = 'CryptDllEncodeObject';
  2402. CRYPT_OID_DECODE_OBJECT_FUNC = 'CryptDllDecodeObject';
  2403. CRYPT_OID_CREATE_COM_OBJECT_FUNC = 'CryptDllCreateCOMObject';
  2404. CRYPT_OID_VERIFY_REVOCATION_FUNC = 'CertDllVerifyRevocation';
  2405. CRYPT_OID_VERIFY_CTL_USAGE_FUNC = 'CertDllVerifyCTLUsage';
  2406. CRYPT_OID_FORMAT_OBJECT_FUNC = 'CryptDllFormatObject';
  2407. CRYPT_OID_FIND_OID_INFO_FUNC = 'CryptDllFindOIDInfo';
  2408. // CryptDllEncodeObject has same function signature as CryptEncodeObject.
  2409. // CryptDllDecodeObject has same function signature as CryptDecodeObject.
  2410. // CryptDllCreateCOMObject has the following signature:
  2411. // BOOL WINAPI CryptDllCreateCOMObject(
  2412. // IN DWORD dwEncodingType,
  2413. // IN LPCSTR pszOID,
  2414. // IN PCRYPT_DATA_BLOB pEncodedContent,
  2415. // IN DWORD dwFlags,
  2416. // IN REFIID riid,
  2417. // OUT void **ppvObj);
  2418. // CertDllVerifyRevocation has the same signature as CertVerifyRevocation
  2419. // (See CertVerifyRevocation for details on when called)
  2420. // CertDllVerifyCTLUsage has the same signature as CertVerifyCTLUsage
  2421. // CryptDllFindOIDInfo currently is only used to store values used by
  2422. // CryptFindOIDInfo. See CryptFindOIDInfo() for more details.
  2423. // Example of a complete OID Function Registry Name:
  2424. // HKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography\OID
  2425. // Encoding Type 1\CryptDllEncodeObject\1.2.3
  2426. //
  2427. // The key's L"Dll" value contains the name of the Dll.
  2428. // The key's L"FuncName" value overrides the default function name
  2429. const
  2430. CRYPT_OID_REGPATH = 'Software\\Microsoft\\Cryptography\\OID';
  2431. CRYPT_OID_REG_ENCODING_TYPE_PREFIX = 'EncodingType ';
  2432. {$IFNDEF VER90}
  2433. CRYPT_OID_REG_DLL_VALUE_NAME = WideString('Dll');
  2434. CRYPT_OID_REG_FUNC_NAME_VALUE_NAME = WideString('FuncName');
  2435. {$ELSE}
  2436. CRYPT_OID_REG_DLL_VALUE_NAME = ('Dll');
  2437. CRYPT_OID_REG_FUNC_NAME_VALUE_NAME = ('FuncName');
  2438. {$ENDIF}
  2439. CRYPT_OID_REG_FUNC_NAME_VALUE_NAME_A = 'FuncName';
  2440. // OID used for Default OID functions
  2441. CRYPT_DEFAULT_OID = 'DEFAULT';
  2442. type
  2443. PCRYPT_OID_FUNC_ENTRY = ^CRYPT_OID_FUNC_ENTRY;
  2444. CRYPT_OID_FUNC_ENTRY = record
  2445. pszOID: LPCSTR;
  2446. pvFuncAddr: PVOID;
  2447. end;
  2448. const
  2449. CRYPT_INSTALL_OID_FUNC_BEFORE_FLAG = 1;
  2450. //+-------------------------------------------------------------------------
  2451. // Install a set of callable OID function addresses.
  2452. //
  2453. // By default the functions are installed at end of the list.
  2454. // Set CRYPT_INSTALL_OID_FUNC_BEFORE_FLAG to install at beginning of list.
  2455. //
  2456. // hModule should be updated with the hModule passed to DllMain to prevent
  2457. // the Dll containing the function addresses from being unloaded by
  2458. // CryptGetOIDFuncAddress/CryptFreeOIDFunctionAddress. This would be the
  2459. // case when the Dll has also regsvr32'ed OID functions via
  2460. // CryptRegisterOIDFunction.
  2461. //
  2462. // DEFAULT functions are installed by setting rgFuncEntry[].pszOID =
  2463. // CRYPT_DEFAULT_OID.
  2464. //--------------------------------------------------------------------------
  2465. function CryptInstallOIDFunctionAddress(hModule: HMODULE; // hModule passed to DllMain
  2466. dwEncodingType: DWORD;
  2467. pszFuncName: LPCSTR;
  2468. cFuncEntry: DWORD;
  2469. const rgFuncEntry: array of CRYPT_OID_FUNC_ENTRY;
  2470. dwFlags: DWORD): BOOL; stdcall;
  2471. //+-------------------------------------------------------------------------
  2472. // Initialize and return handle to the OID function set identified by its
  2473. // function name.
  2474. //
  2475. // If the set already exists, a handle to the existing set is returned.
  2476. //--------------------------------------------------------------------------
  2477. function CryptInitOIDFunctionSet(pszFuncName: LPCSTR;
  2478. dwFlags: DWORD): HCRYPTOIDFUNCSET; stdcall;
  2479. //+-------------------------------------------------------------------------
  2480. // Search the list of installed functions for an encoding type and OID match.
  2481. // If not found, search the registry.
  2482. //
  2483. // For success, returns TRUE with *ppvFuncAddr updated with the function's
  2484. // address and *phFuncAddr updated with the function address's handle.
  2485. // The function's handle is AddRef'ed. CryptFreeOIDFunctionAddress needs to
  2486. // be called to release it.
  2487. //
  2488. // For a registry match, the Dll containing the function is loaded.
  2489. //--------------------------------------------------------------------------
  2490. function CryptGetOIDFunctionAddress(hFuncSet: HCRYPTOIDFUNCSET;
  2491. dwEncodingType: DWORD;
  2492. pszOID: LPCSTR;
  2493. dwFlags: DWORD;
  2494. var ppvFuncAddr: array of PVOID;
  2495. var phFuncAddr: HCRYPTOIDFUNCADDR): BOOL; stdcall;
  2496. //+-------------------------------------------------------------------------
  2497. // Get the list of registered default Dll entries for the specified
  2498. // function set and encoding type.
  2499. //
  2500. // The returned list consists of none, one or more null terminated Dll file
  2501. // names. The list is terminated with an empty (L"\0") Dll file name.
  2502. // For example: L"first.dll" L"\0" L"second.dll" L"\0" L"\0"
  2503. //--------------------------------------------------------------------------
  2504. function CryptGetDefaultOIDDllList(hFuncSet: HCRYPTOIDFUNCSET;
  2505. dwEncodingType: DWORD;
  2506. pwszDllList: LPWSTR;
  2507. pcchDllList: PDWORD): BOOL; stdcall;
  2508. //+-------------------------------------------------------------------------
  2509. // Either: get the first or next installed DEFAULT function OR
  2510. // load the Dll containing the DEFAULT function.
  2511. //
  2512. // If pwszDll is NULL, search the list of installed DEFAULT functions.
  2513. // *phFuncAddr must be set to NULL to get the first installed function.
  2514. // Successive installed functions are returned by setting *phFuncAddr
  2515. // to the hFuncAddr returned by the previous call.
  2516. //
  2517. // If pwszDll is NULL, the input *phFuncAddr
  2518. // is always CryptFreeOIDFunctionAddress'ed by this function, even for
  2519. // an error.
  2520. //
  2521. // If pwszDll isn't NULL, then, attempts to load the Dll and the DEFAULT
  2522. // function. *phFuncAddr is ignored upon entry and isn't
  2523. // CryptFreeOIDFunctionAddress'ed.
  2524. //
  2525. // For success, returns TRUE with *ppvFuncAddr updated with the function's
  2526. // address and *phFuncAddr updated with the function address's handle.
  2527. // The function's handle is AddRef'ed. CryptFreeOIDFunctionAddress needs to
  2528. // be called to release it or CryptGetDefaultOIDFunctionAddress can also
  2529. // be called for a NULL pwszDll.
  2530. //--------------------------------------------------------------------------
  2531. function CryptGetDefaultOIDFunctionAddress(hFuncSet: HCRYPTOIDFUNCSET;
  2532. dwEncodingType: DWORD;
  2533. pwszDll: DWORD;
  2534. dwFlags: LPCWSTR;
  2535. var ppvFuncAddr: array of PVOID;
  2536. var phFuncAddr: HCRYPTOIDFUNCADDR): BOOL; stdcall;
  2537. //+-------------------------------------------------------------------------
  2538. // Releases the handle AddRef'ed and returned by CryptGetOIDFunctionAddress
  2539. // or CryptGetDefaultOIDFunctionAddress.
  2540. //
  2541. // If a Dll was loaded for the function its unloaded. However, before doing
  2542. // the unload, the DllCanUnloadNow function exported by the loaded Dll is
  2543. // called. It should return S_FALSE to inhibit the unload or S_TRUE to enable
  2544. // the unload. If the Dll doesn't export DllCanUnloadNow, the Dll is unloaded.
  2545. //
  2546. // DllCanUnloadNow has the following signature:
  2547. // STDAPI DllCanUnloadNow(void);
  2548. //--------------------------------------------------------------------------
  2549. function CryptFreeOIDFunctionAddress(hFuncAddr: HCRYPTOIDFUNCADDR;
  2550. dwFlags: DWORD): BOOL; stdcall;
  2551. //+-------------------------------------------------------------------------
  2552. // Register the Dll containing the function to be called for the specified
  2553. // encoding type, function name and OID.
  2554. //
  2555. // pwszDll may contain environment-variable strings
  2556. // which are ExpandEnvironmentStrings()'ed before loading the Dll.
  2557. //
  2558. // In addition to registering the DLL, you may override the
  2559. // name of the function to be called. For example,
  2560. // pszFuncName = "CryptDllEncodeObject",
  2561. // pszOverrideFuncName = "MyEncodeXyz".
  2562. // This allows a Dll to export multiple OID functions for the same
  2563. // function name without needing to interpose its own OID dispatcher function.
  2564. //--------------------------------------------------------------------------
  2565. function CryptRegisterOIDFunction(dwEncodingType: DWORD;
  2566. pszFuncName: LPCSTR;
  2567. pszOID: LPCSTR; //OPTIONAL
  2568. pwszDll: LPCWSTR; //OPTIONAL
  2569. pszOverrideFuncName: LPCSTR): BOOL; stdcall;
  2570. //+-------------------------------------------------------------------------
  2571. // Unregister the Dll containing the function to be called for the specified
  2572. // encoding type, function name and OID.
  2573. //--------------------------------------------------------------------------
  2574. function CryptUnregisterOIDFunction(dwEncodingType: DWORD;
  2575. pszFuncName: LPCSTR;
  2576. pszOID: LPCSTR): BOOL; stdcall;
  2577. //+-------------------------------------------------------------------------
  2578. // Register the Dll containing the default function to be called for the
  2579. // specified encoding type and function name.
  2580. //
  2581. // Unlike CryptRegisterOIDFunction, you can't override the function name
  2582. // needing to be exported by the Dll.
  2583. //
  2584. // The Dll is inserted before the entry specified by dwIndex.
  2585. // dwIndex == 0, inserts at the beginning.
  2586. // dwIndex == CRYPT_REGISTER_LAST_INDEX, appends at the end.
  2587. //
  2588. // pwszDll may contain environment-variable strings
  2589. // which are ExpandEnvironmentStrings()'ed before loading the Dll.
  2590. //--------------------------------------------------------------------------
  2591. function CryptRegisterDefaultOIDFunction(dwEncodingType: DWORD;
  2592. pszFuncName: LPCSTR;
  2593. dwIndex: DWORD;
  2594. pwszDll: LPCWSTR): BOOL; stdcall;
  2595. const
  2596. CRYPT_REGISTER_FIRST_INDEX = 0;
  2597. CRYPT_REGISTER_LAST_INDEX = $FFFFFFFF;
  2598. //+-------------------------------------------------------------------------
  2599. // Unregister the Dll containing the default function to be called for
  2600. // the specified encoding type and function name.
  2601. //--------------------------------------------------------------------------
  2602. function CryptUnregisterDefaultOIDFunction(dwEncodingType: DWORD;
  2603. pszFuncName: LPCSTR;
  2604. pwszDll: LPCWSTR): BOOL; stdcall;
  2605. //+-------------------------------------------------------------------------
  2606. // Set the value for the specified encoding type, function name, OID and
  2607. // value name.
  2608. //
  2609. // See RegSetValueEx for the possible value types.
  2610. //
  2611. // String types are UNICODE.
  2612. //--------------------------------------------------------------------------
  2613. function CryptSetOIDFunctionValue(dwEncodingType: DWORD;
  2614. pszFuncName: LPCSTR;
  2615. pszOID: LPCSTR;
  2616. pwszValueName: LPCWSTR;
  2617. dwValueType: DWORD;
  2618. const pbValueData: PBYTE;
  2619. cbValueData: DWORD): BOOL; stdcall;
  2620. //+-------------------------------------------------------------------------
  2621. // Get the value for the specified encoding type, function name, OID and
  2622. // value name.
  2623. //
  2624. // See RegEnumValue for the possible value types.
  2625. //
  2626. // String types are UNICODE.
  2627. //--------------------------------------------------------------------------
  2628. function CryptGetOIDFunctionValue(dwEncodingType: DWORD;
  2629. pszFuncName: LPCSTR;
  2630. pwszValueName: LPCSTR;
  2631. pszOID: LPCWSTR;
  2632. pdwValueType: PDWORD;
  2633. pbValueData: PBYTE;
  2634. pcbValueData: PDWORD): BOOL; stdcall;
  2635. type
  2636. PFN_CRYPT_ENUM_OID_FUNC = function(dwEncodingType: DWORD;
  2637. pszFuncName: LPCSTR;
  2638. pszOID: LPCSTR;
  2639. cValue: DWORD;
  2640. const rgdwValueType: array of DWORD;
  2641. const rgpwszValueName: array of LPCWSTR;
  2642. const rgpbValueData: array of PBYTE;
  2643. const rgcbValueData: array of DWORD;
  2644. pvArg: PVOID): BOOL; stdcall;
  2645. //+-------------------------------------------------------------------------
  2646. // Enumerate the OID functions identified by their encoding type,
  2647. // function name and OID.
  2648. //
  2649. // pfnEnumOIDFunc is called for each registry key matching the input
  2650. // parameters. Setting dwEncodingType to CRYPT_MATCH_ANY_ENCODING_TYPE matches
  2651. // any. Setting pszFuncName or pszOID to NULL matches any.
  2652. //
  2653. // Set pszOID == CRYPT_DEFAULT_OID to restrict the enumeration to only the
  2654. // DEFAULT functions
  2655. //
  2656. // String types are UNICODE.
  2657. //--------------------------------------------------------------------------
  2658. function CryptEnumOIDFunction(dwEncodingType: DWORD;
  2659. pszFuncName: LPCSTR; //OPTIONAL
  2660. pszOID: LPCSTR; //OPTIONAL
  2661. dwFlags: DWORD;
  2662. pvArg: PVOID;
  2663. pfnEnumOIDFunc: PFN_CRYPT_ENUM_OID_FUNC): BOOL; stdcall;
  2664. const
  2665. CRYPT_MATCH_ANY_ENCODING_TYPE = $FFFFFFFF;
  2666. //+=========================================================================
  2667. // Object IDentifier (OID) Information: Data Structures and APIs
  2668. //==========================================================================
  2669. //+-------------------------------------------------------------------------
  2670. // OID Information
  2671. //--------------------------------------------------------------------------
  2672. type
  2673. PCRYPT_OID_INFO = ^CRYPT_OID_INFO;
  2674. CRYPT_OID_INFO = record
  2675. cbSize: DWORD;
  2676. pszOID: LPCSTR;
  2677. pwszName: LPCWSTR;
  2678. dwGroupId: DWORD;
  2679. EnumValue: record {type EnumValue for the union part of the original struct --max--}
  2680. case integer of
  2681. 0: (dwValue: DWORD);
  2682. 1: (Algid: ALG_ID);
  2683. 2: (dwLength: DWORD);
  2684. end;
  2685. ExtraInfo: CRYPT_DATA_BLOB;
  2686. end;
  2687. type
  2688. CCRYPT_OID_INFO = CRYPT_OID_INFO;
  2689. PCCRYPT_OID_INFO = ^CCRYPT_OID_INFO;
  2690. //+-------------------------------------------------------------------------
  2691. // OID Group IDs
  2692. //--------------------------------------------------------------------------
  2693. const
  2694. CRYPT_HASH_ALG_OID_GROUP_ID = 1;
  2695. CRYPT_ENCRYPT_ALG_OID_GROUP_ID = 2;
  2696. CRYPT_PUBKEY_ALG_OID_GROUP_ID = 3;
  2697. CRYPT_SIGN_ALG_OID_GROUP_ID = 4;
  2698. CRYPT_RDN_ATTR_OID_GROUP_ID = 5;
  2699. CRYPT_EXT_OR_ATTR_OID_GROUP_ID = 6;
  2700. CRYPT_ENHKEY_USAGE_OID_GROUP_ID = 7;
  2701. CRYPT_POLICY_OID_GROUP_ID = 8;
  2702. CRYPT_LAST_OID_GROUP_ID = 8;
  2703. CRYPT_FIRST_ALG_OID_GROUP_ID = CRYPT_HASH_ALG_OID_GROUP_ID;
  2704. CRYPT_LAST_ALG_OID_GROUP_ID = CRYPT_SIGN_ALG_OID_GROUP_ID;
  2705. // The CRYPT_*_ALG_OID_GROUP_ID's have an Algid. The CRYPT_RDN_ATTR_OID_GROUP_ID
  2706. // has a dwLength. The CRYPT_EXT_OR_ATTR_OID_GROUP_ID,
  2707. // CRYPT_ENHKEY_USAGE_OID_GROUP_ID or CRYPT_POLICY_OID_GROUP_ID don't have a
  2708. // dwValue.
  2709. // CRYPT_PUBKEY_ALG_OID_GROUP_ID has the following optional ExtraInfo:
  2710. // DWORD[0] - Flags. CRYPT_OID_INHIBIT_SIGNATURE_FORMAT_FLAG can be set to
  2711. // inhibit the reformatting of the signature before
  2712. // CryptVerifySignature is called or after CryptSignHash
  2713. // is called. CRYPT_OID_USE_PUBKEY_PARA_FOR_PKCS7_FLAG can
  2714. // be set to include the public key algorithm's parameters
  2715. // in the PKCS7's digestEncryptionAlgorithm's parameters.
  2716. CRYPT_OID_INHIBIT_SIGNATURE_FORMAT_FLAG = $1;
  2717. CRYPT_OID_USE_PUBKEY_PARA_FOR_PKCS7_FLAG = $2;
  2718. // CRYPT_SIGN_ALG_OID_GROUP_ID has the following optional ExtraInfo:
  2719. // DWORD[0] - Public Key Algid.
  2720. // DWORD[1] - Flags. Same as above for CRYPT_PUBKEY_ALG_OID_GROUP_ID.
  2721. // CRYPT_RDN_ATTR_OID_GROUP_ID has the following optional ExtraInfo:
  2722. // Array of DWORDs:
  2723. // [0 ..] - Null terminated list of acceptable RDN attribute
  2724. // value types. An empty list implies CERT_RDN_PRINTABLE_STRING,
  2725. // CERT_RDN_T61_STRING, 0.
  2726. //+-------------------------------------------------------------------------
  2727. // Find OID information. Returns NULL if unable to find any information
  2728. // for the specified key and group. Note, returns a pointer to a constant
  2729. // data structure. The returned pointer MUST NOT be freed.
  2730. //
  2731. // dwKeyType's:
  2732. // CRYPT_OID_INFO_OID_KEY, pvKey points to a szOID
  2733. // CRYPT_OID_INFO_NAME_KEY, pvKey points to a wszName
  2734. // CRYPT_OID_INFO_ALGID_KEY, pvKey points to an ALG_ID
  2735. // CRYPT_OID_INFO_SIGN_KEY, pvKey points to an array of two ALG_ID's:
  2736. // ALG_ID[0] - Hash Algid
  2737. // ALG_ID[1] - PubKey Algid
  2738. //
  2739. // Setting dwGroupId to 0, searches all groups according to the dwKeyType.
  2740. // Otherwise, only the dwGroupId is searched.
  2741. //--------------------------------------------------------------------------
  2742. function CryptFindOIDInfo(dwKeyType: DWORD;
  2743. pvKey: PVOID;
  2744. dwGroupId: DWORD): PCCRYPT_OID_INFO; stdcall;
  2745. const
  2746. CRYPT_OID_INFO_OID_KEY = 1;
  2747. CRYPT_OID_INFO_NAME_KEY = 2;
  2748. CRYPT_OID_INFO_ALGID_KEY = 3;
  2749. CRYPT_OID_INFO_SIGN_KEY = 4;
  2750. //+-------------------------------------------------------------------------
  2751. // Register OID information. The OID information specified in the
  2752. // CCRYPT_OID_INFO structure is persisted to the registry.
  2753. //
  2754. // crypt32.dll contains information for the commonly known OIDs. This function
  2755. // allows applications to augment crypt32.dll's OID information. During
  2756. // CryptFindOIDInfo's first call, the registered OID information is installed.
  2757. //
  2758. // By default the registered OID information is installed after crypt32.dll's
  2759. // OID entries. Set CRYPT_INSTALL_OID_INFO_BEFORE_FLAG to install before.
  2760. //--------------------------------------------------------------------------
  2761. function CryptRegisterOIDInfo(pInfo: PCCRYPT_OID_INFO;
  2762. dwFlags: DWORD): BOOL; stdcall;
  2763. const
  2764. CRYPT_INSTALL_OID_INFO_BEFORE_FLAG = 1;
  2765. //+-------------------------------------------------------------------------
  2766. // Unregister OID information. Only the pszOID and dwGroupId fields are
  2767. // used to identify the OID information to be unregistered.
  2768. //--------------------------------------------------------------------------
  2769. function CryptUnregisterOIDInfo(pInfo: PCCRYPT_OID_INFO): BOOL; stdcall;
  2770. //+=========================================================================
  2771. // Low Level Cryptographic Message Data Structures and APIs
  2772. //==========================================================================
  2773. type
  2774. HCRYPTMSG = Pointer;
  2775. const
  2776. szOID_PKCS_7_DATA = '1.2.840.113549.1.7.1';
  2777. szOID_PKCS_7_SIGNED = '1.2.840.113549.1.7.2';
  2778. szOID_PKCS_7_ENVELOPED = '1.2.840.113549.1.7.3';
  2779. szOID_PKCS_7_SIGNEDANDENVELOPED = '1.2.840.113549.1.7.4';
  2780. szOID_PKCS_7_DIGESTED = '1.2.840.113549.1.7.5';
  2781. szOID_PKCS_7_ENCRYPTED = '1.2.840.113549.1.7.6';
  2782. szOID_PKCS_9_CONTENT_TYPE = '1.2.840.113549.1.9.3';
  2783. szOID_PKCS_9_MESSAGE_DIGEST = '1.2.840.113549.1.9.4';
  2784. //+-------------------------------------------------------------------------
  2785. // Message types
  2786. //--------------------------------------------------------------------------
  2787. const
  2788. CMSG_DATA = 1;
  2789. CMSG_SIGNED = 2;
  2790. CMSG_ENVELOPED = 3;
  2791. CMSG_SIGNED_AND_ENVELOPED = 4;
  2792. CMSG_HASHED = 5;
  2793. CMSG_ENCRYPTED = 6;
  2794. //+-------------------------------------------------------------------------
  2795. // Message Type Bit Flags
  2796. //--------------------------------------------------------------------------
  2797. CMSG_ALL_FLAGS = (not ULONG(0));
  2798. CMSG_DATA_FLAG = (1 shl CMSG_DATA);
  2799. CMSG_SIGNED_FLAG = (1 shl CMSG_SIGNED);
  2800. CMSG_ENVELOPED_FLAG = (1 shl CMSG_ENVELOPED);
  2801. CMSG_SIGNED_AND_ENVELOPED_FLAG = (1 shl CMSG_SIGNED_AND_ENVELOPED);
  2802. CMSG_HASHED_FLAG = (1 shl CMSG_HASHED);
  2803. CMSG_ENCRYPTED_FLAG = (1 shl CMSG_ENCRYPTED);
  2804. //+-------------------------------------------------------------------------
  2805. // The message encode information (pvMsgEncodeInfo) is message type dependent
  2806. //--------------------------------------------------------------------------
  2807. //+-------------------------------------------------------------------------
  2808. // CMSG_DATA: pvMsgEncodeInfo = NULL
  2809. //--------------------------------------------------------------------------
  2810. //+-------------------------------------------------------------------------
  2811. // CMSG_SIGNED
  2812. //
  2813. // The pCertInfo in the CMSG_SIGNER_ENCODE_INFO provides the Issuer, SerialNumber
  2814. // and PublicKeyInfo.Algorithm. The PublicKeyInfo.Algorithm implicitly
  2815. // specifies the HashEncryptionAlgorithm to be used.
  2816. //
  2817. // The hCryptProv and dwKeySpec specify the private key to use. If dwKeySpec
  2818. // == 0, then, defaults to AT_SIGNATURE.
  2819. //
  2820. // pvHashAuxInfo currently isn't used and must be set to NULL.
  2821. //--------------------------------------------------------------------------
  2822. type
  2823. PCMSG_SIGNER_ENCODE_INFO = ^CMSG_SIGNER_ENCODE_INFO;
  2824. CMSG_SIGNER_ENCODE_INFO = record
  2825. cbSize: DWORD;
  2826. pCertInfo: PCERT_INFO;
  2827. hCryptProv: HCRYPTPROV;
  2828. dwKeySpec: DWORD;
  2829. HashAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  2830. pvHashAuxInfo: PVOID;
  2831. cAuthAttr: DWORD;
  2832. rgAuthAttr: PCRYPT_ATTRIBUTE;
  2833. cUnauthAttr: DWORD;
  2834. rgUnauthAttr: PCRYPT_ATTRIBUTE;
  2835. end;
  2836. type
  2837. PCMSG_SIGNED_ENCODE_INFO = ^CMSG_SIGNED_ENCODE_INFO;
  2838. CMSG_SIGNED_ENCODE_INFO = record
  2839. cbSize: DWORD;
  2840. cSigners: DWORD;
  2841. rgSigners: PCMSG_SIGNER_ENCODE_INFO;
  2842. cCertEncoded: DWORD;
  2843. rgCertEncoded: PCERT_BLOB;
  2844. cCrlEncoded: DWORD;
  2845. rgCrlEncoded: PCRL_BLOB;
  2846. end;
  2847. //+-------------------------------------------------------------------------
  2848. // CMSG_ENVELOPED
  2849. //
  2850. // The PCERT_INFO for the rgRecipients provides the Issuer, SerialNumber
  2851. // and PublicKeyInfo. The PublicKeyInfo.Algorithm implicitly
  2852. // specifies the KeyEncryptionAlgorithm to be used.
  2853. //
  2854. // The PublicKeyInfo.PublicKey in PCERT_INFO is used to encrypt the content
  2855. // encryption key for the recipient.
  2856. //
  2857. // hCryptProv is used to do the content encryption, recipient key encryption
  2858. // and export. The hCryptProv's private keys aren't used.
  2859. //
  2860. // Note: CAPI currently doesn't support more than one KeyEncryptionAlgorithm
  2861. // per provider. This will need to be fixed.
  2862. //
  2863. // pvEncryptionAuxInfo currently isn't used and must be set to NULL.
  2864. //--------------------------------------------------------------------------
  2865. type
  2866. PCMSG_ENVELOPED_ENCODE_INFO = ^CMSG_ENVELOPED_ENCODE_INFO;
  2867. CMSG_ENVELOPED_ENCODE_INFO = record
  2868. cbSize: DWORD;
  2869. hCryptProv: HCRYPTPROV;
  2870. ContentEncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  2871. pvEncryptionAuxInfo: PVOID;
  2872. cRecipients: DWORD;
  2873. rgpRecipients: PPCERT_INFO; // pointer to array of PCERT_INFO
  2874. end;
  2875. //+-------------------------------------------------------------------------
  2876. // CMSG_SIGNED_AND_ENVELOPED
  2877. //
  2878. // For PKCS #7, a signed and enveloped message doesn't have the
  2879. // signer's authenticated or unauthenticated attributes. Otherwise, a
  2880. // combination of the CMSG_SIGNED_ENCODE_INFO and CMSG_ENVELOPED_ENCODE_INFO.
  2881. //--------------------------------------------------------------------------
  2882. type
  2883. PCMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO = ^CMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO;
  2884. CMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO = record
  2885. cbSize: DWORD;
  2886. SignedInfo: CMSG_SIGNED_ENCODE_INFO;
  2887. EnvelopedInfo: CMSG_ENVELOPED_ENCODE_INFO;
  2888. end;
  2889. //+-------------------------------------------------------------------------
  2890. // CMSG_HASHED
  2891. //
  2892. // hCryptProv is used to do the hash. Doesn't need to use a private key.
  2893. //
  2894. // If fDetachedHash is set, then, the encoded message doesn't contain
  2895. // any content (its treated as NULL Data)
  2896. //
  2897. // pvHashAuxInfo currently isn't used and must be set to NULL.
  2898. //--------------------------------------------------------------------------
  2899. type
  2900. PCMSG_HASHED_ENCODE_INFO = ^CMSG_HASHED_ENCODE_INFO;
  2901. CMSG_HASHED_ENCODE_INFO = record
  2902. cbSize: DWORD;
  2903. hCryptProv: HCRYPTPROV;
  2904. HashAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  2905. pvHashAuxInfo: PVOID;
  2906. end;
  2907. //+-------------------------------------------------------------------------
  2908. // CMSG_ENCRYPTED
  2909. //
  2910. // The key used to encrypt the message is identified outside of the message
  2911. // content (for example, password).
  2912. //
  2913. // The content input to CryptMsgUpdate has already been encrypted.
  2914. //
  2915. // pvEncryptionAuxInfo currently isn't used and must be set to NULL.
  2916. //--------------------------------------------------------------------------
  2917. type
  2918. PCMSG_ENCRYPTED_ENCODE_INFO = ^CMSG_ENCRYPTED_ENCODE_INFO;
  2919. CMSG_ENCRYPTED_ENCODE_INFO = record
  2920. cbSize: DWORD;
  2921. ContentEncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  2922. pvEncryptionAuxInfo: PVOID;
  2923. end;
  2924. //+-------------------------------------------------------------------------
  2925. // This parameter allows messages to be of variable length with streamed
  2926. // output.
  2927. //
  2928. // By default, messages are of a definite length and
  2929. // CryptMsgGetParam(CMSG_CONTENT_PARAM) is
  2930. // called to get the cryptographically processed content. Until closed,
  2931. // the handle keeps a copy of the processed content.
  2932. //
  2933. // With streamed output, the processed content can be freed as its streamed.
  2934. //
  2935. // If the length of the content to be updated is known at the time of the
  2936. // open, then, ContentLength should be set to that length. Otherwise, it
  2937. // should be set to CMSG_INDEFINITE_LENGTH.
  2938. //--------------------------------------------------------------------------
  2939. type
  2940. PFN_CMSG_STREAM_OUTPUT = function(
  2941. const pvArg: PVOID;
  2942. pbData: PBYTE;
  2943. cbData: DWORD;
  2944. fFinal: BOOL): BOOL; stdcall;
  2945. const
  2946. CMSG_INDEFINITE_LENGTH = ($FFFFFFFF);
  2947. type
  2948. PCMSG_STREAM_INFO = ^CMSG_STREAM_INFO;
  2949. CMSG_STREAM_INFO = record
  2950. cbContent: DWORD;
  2951. pfnStreamOutput: PFN_CMSG_STREAM_OUTPUT;
  2952. pvArg: PVOID;
  2953. end;
  2954. //+-------------------------------------------------------------------------
  2955. // Open dwFlags
  2956. //--------------------------------------------------------------------------
  2957. const
  2958. CMSG_BARE_CONTENT_FLAG = $00000001;
  2959. CMSG_LENGTH_ONLY_FLAG = $00000002;
  2960. CMSG_DETACHED_FLAG = $00000004;
  2961. CMSG_AUTHENTICATED_ATTRIBUTES_FLAG = $00000008;
  2962. CMSG_CONTENTS_OCTETS_FLAG = $00000010;
  2963. CMSG_MAX_LENGTH_FLAG = $00000020;
  2964. //+-------------------------------------------------------------------------
  2965. // Open a cryptographic message for encoding
  2966. //
  2967. // For PKCS #7:
  2968. // If the content to be passed to CryptMsgUpdate has already
  2969. // been message encoded (the input to CryptMsgUpdate is the streamed output
  2970. // from another message encode), then, the CMSG_ENCODED_CONTENT_INFO_FLAG should
  2971. // be set in dwFlags. If not set, then, the inner ContentType is Data and
  2972. // the input to CryptMsgUpdate is treated as the inner Data type's Content,
  2973. // a string of bytes.
  2974. // If CMSG_BARE_CONTENT_FLAG is specified for a streamed message,
  2975. // the streamed output will not have an outer ContentInfo wrapper. This
  2976. // makes it suitable to be streamed into an enclosing message.
  2977. //
  2978. // The pStreamInfo parameter needs to be set to stream the encoded message
  2979. // output.
  2980. //--------------------------------------------------------------------------
  2981. function CryptMsgOpenToEncode(dwMsgEncodingType: DWORD;
  2982. dwFlags: DWORD;
  2983. dwMsgType: DWORD;
  2984. pvMsgEncodeInfo: PVOID;
  2985. pszInnerContentObjID: LPSTR; //OPTIONAL
  2986. pStreamInfo: PCMSG_STREAM_INFO //OPTIONAL
  2987. ): HCRYPTMSG; stdcall;
  2988. //+-------------------------------------------------------------------------
  2989. // Calculate the length of an encoded cryptographic message.
  2990. //
  2991. // Calculates the length of the encoded message given the
  2992. // message type, encoding parameters and total length of
  2993. // the data to be updated. Note, this might not be the exact length. However,
  2994. // it will always be greater than or equal to the actual length.
  2995. //--------------------------------------------------------------------------
  2996. function CryptMsgCalculateEncodedLength(dwMsgEncodingType: DWORD;
  2997. dwFlags: DWORD;
  2998. dwMsgType: DWORD;
  2999. pvMsgEncodeInfo: PVOID;
  3000. pszInnerContentObjID: LPSTR; //OPTIONAL
  3001. cbData: DWORD): DWORD; stdcall;
  3002. //+-------------------------------------------------------------------------
  3003. // Open a cryptographic message for decoding
  3004. //
  3005. // For PKCS #7: if the inner ContentType isn't Data, then, the inner
  3006. // ContentInfo consisting of both ContentType and Content is output.
  3007. // To also enable ContentInfo output for the Data ContentType, then,
  3008. // the CMSG_ENCODED_CONTENT_INFO_FLAG should be set
  3009. // in dwFlags. If not set, then, only the content portion of the inner
  3010. // ContentInfo is output for the Data ContentType.
  3011. //
  3012. // To only calculate the length of the decoded message, set the
  3013. // CMSG_LENGTH_ONLY_FLAG in dwFlags. After the final CryptMsgUpdate get the
  3014. // MSG_CONTENT_PARAM. Note, this might not be the exact length. However,
  3015. // it will always be greater than or equal to the actual length.
  3016. //
  3017. // hCryptProv specifies the crypto provider to use for hashing and/or
  3018. // decrypting the message. For enveloped messages, hCryptProv also specifies
  3019. // the private exchange key to use. For signed messages, hCryptProv is used
  3020. // when CryptMsgVerifySigner is called.
  3021. //
  3022. // For enveloped messages, the pRecipientInfo contains the Issuer and
  3023. // SerialNumber identifying the RecipientInfo in the message.
  3024. //
  3025. // Note, the pRecipientInfo should correspond to the provider's private
  3026. // exchange key.
  3027. //
  3028. // If pRecipientInfo is NULL, then, the message isn't decrypted. To decrypt
  3029. // the message, CryptMsgControl(CMSG_CTRL_DECRYPT) is called after the final
  3030. // CryptMsgUpdate.
  3031. //
  3032. // The pStreamInfo parameter needs to be set to stream the decoded content
  3033. // output. Note, if pRecipientInfo is NULL, then, the streamed output isn't
  3034. // decrypted.
  3035. //--------------------------------------------------------------------------
  3036. function CryptMsgOpenToDecode(dwMsgEncodingType: DWORD;
  3037. dwFlags: DWORD;
  3038. dwMsgType: DWORD;
  3039. hCryptProv: HCRYPTPROV;
  3040. pRecipientInfo: PCERT_INFO; //OPTIONAL
  3041. pStreamInfo: PCMSG_STREAM_INFO //OPTIONAL
  3042. ): HCRYPTMSG; stdcall;
  3043. //+-------------------------------------------------------------------------
  3044. // Close a cryptographic message handle
  3045. //
  3046. // LastError is preserved unless FALSE is returned.
  3047. //--------------------------------------------------------------------------
  3048. function CryptMsgClose(hCryptMsg: HCRYPTMSG): BOOL; stdcall;
  3049. //+-------------------------------------------------------------------------
  3050. // Update the content of a cryptographic message. Depending on how the
  3051. // message was opened, the content is either encoded or decoded.
  3052. //
  3053. // This function is repetitively called to append to the message content.
  3054. // fFinal is set to identify the last update. On fFinal, the encode/decode
  3055. // is completed. The encoded/decoded content and the decoded parameters
  3056. // are valid until the open and all duplicated handles are closed.
  3057. //--------------------------------------------------------------------------
  3058. function CryptMsgUpdate(hCryptMsg: HCRYPTMSG;
  3059. const pbData: PBYTE;
  3060. cbData: DWORD;
  3061. fFinal: BOOL): BOOL; stdcall;
  3062. //+-------------------------------------------------------------------------
  3063. // Perform a special "control" function after the final CryptMsgUpdate of a
  3064. // encoded/decoded cryptographic message.
  3065. //
  3066. // The dwCtrlType parameter specifies the type of operation to be performed.
  3067. //
  3068. // The pvCtrlPara definition depends on the dwCtrlType value.
  3069. //
  3070. // See below for a list of the control operations and their pvCtrlPara
  3071. // type definition.
  3072. //--------------------------------------------------------------------------
  3073. function CryptMsgControl(hCryptMsg: HCRYPTMSG;
  3074. dwFlags: DWORD;
  3075. dwCtrlType: DWORD;
  3076. pvCtrlPara: PVOID): BOOL; stdcall;
  3077. //+-------------------------------------------------------------------------
  3078. // Message control types
  3079. //--------------------------------------------------------------------------
  3080. const
  3081. CMSG_CTRL_VERIFY_SIGNATURE = 1;
  3082. CMSG_CTRL_DECRYPT = 2;
  3083. CMSG_CTRL_VERIFY_HASH = 5;
  3084. CMSG_CTRL_ADD_SIGNER = 6;
  3085. CMSG_CTRL_DEL_SIGNER = 7;
  3086. CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR = 8;
  3087. CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR = 9;
  3088. CMSG_CTRL_ADD_CERT = 10;
  3089. CMSG_CTRL_DEL_CERT = 11;
  3090. CMSG_CTRL_ADD_CRL = 12;
  3091. CMSG_CTRL_DEL_CRL = 13;
  3092. //+-------------------------------------------------------------------------
  3093. // CMSG_CTRL_VERIFY_SIGNATURE
  3094. //
  3095. // Verify the signature of a SIGNED or SIGNED_AND_ENVELOPED
  3096. // message after it has been decoded.
  3097. //
  3098. // For a SIGNED_AND_ENVELOPED message, called after
  3099. // CryptMsgControl(CMSG_CTRL_DECRYPT), if CryptMsgOpenToDecode was called
  3100. // with a NULL pRecipientInfo.
  3101. //
  3102. // pvCtrlPara points to a CERT_INFO struct.
  3103. //
  3104. // The CERT_INFO contains the Issuer and SerialNumber identifying
  3105. // the Signer of the message. The CERT_INFO also contains the
  3106. // PublicKeyInfo
  3107. // used to verify the signature. The cryptographic provider specified
  3108. // in CryptMsgOpenToDecode is used.
  3109. //--------------------------------------------------------------------------
  3110. //+-------------------------------------------------------------------------
  3111. // CMSG_CTRL_DECRYPT
  3112. //
  3113. // Decrypt an ENVELOPED or SIGNED_AND_ENVELOPED message after it has been
  3114. // decoded.
  3115. //
  3116. // hCryptProv and dwKeySpec specify the private key to use. For dwKeySpec ==
  3117. // 0, defaults to AT_KEYEXCHANGE.
  3118. //
  3119. // dwRecipientIndex is the index of the recipient in the message associated
  3120. // with the hCryptProv's private key.
  3121. //
  3122. // This control function needs to be called, if you don't know the appropriate
  3123. // recipient before calling CryptMsgOpenToDecode. After the final
  3124. // CryptMsgUpdate, the list of recipients is obtained by iterating through
  3125. // CMSG_RECIPIENT_INFO_PARAM. The recipient corresponding to a private
  3126. // key owned by the caller is selected and passed to this function to decrypt
  3127. // the message.
  3128. //
  3129. // Note, the message can only be decrypted once.
  3130. //--------------------------------------------------------------------------
  3131. type
  3132. PCMSG_CTRL_DECRYPT_PARA = ^CMSG_CTRL_DECRYPT_PARA;
  3133. CMSG_CTRL_DECRYPT_PARA = record
  3134. cbSize: DWORD;
  3135. hCryptProv: HCRYPTPROV;
  3136. dwKeySpec: DWORD;
  3137. dwRecipientIndex: DWORD;
  3138. end;
  3139. //+-------------------------------------------------------------------------
  3140. // CMSG_CTRL_VERIFY_HASH
  3141. //
  3142. // Verify the hash of a HASHED message after it has been decoded.
  3143. //
  3144. // Only the hCryptMsg parameter is used, to specify the message whose
  3145. // hash is being verified.
  3146. //--------------------------------------------------------------------------
  3147. //+-------------------------------------------------------------------------
  3148. // CMSG_CTRL_ADD_SIGNER
  3149. //
  3150. // Add a signer to a signed-data or signed-and-enveloped-data message.
  3151. //
  3152. // pvCtrlPara points to a CMSG_SIGNER_ENCODE_INFO.
  3153. //--------------------------------------------------------------------------
  3154. //+-------------------------------------------------------------------------
  3155. // CMSG_CTRL_DEL_SIGNER
  3156. //
  3157. // Remove a signer from a signed-data or signed-and-enveloped-data message.
  3158. //
  3159. // pvCtrlPara points to a DWORD containing the 0-based index of the
  3160. // signer to be removed.
  3161. //--------------------------------------------------------------------------
  3162. //+-------------------------------------------------------------------------
  3163. // CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR
  3164. //
  3165. // Add an unauthenticated attribute to the SignerInfo of a signed-data or
  3166. // signed-and-enveloped-data message.
  3167. //
  3168. // The unauthenticated attribute is input in the form of an encoded blob.
  3169. //--------------------------------------------------------------------------
  3170. type
  3171. PCMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA = ^CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA;
  3172. CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA = record
  3173. cbSize: DWORD;
  3174. dwSignerIndex: DWORD;
  3175. blob: CRYPT_DATA_BLOB;
  3176. end;
  3177. //+-------------------------------------------------------------------------
  3178. // CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR
  3179. //
  3180. // Delete an unauthenticated attribute from the SignerInfo of a signed-data
  3181. // or signed-and-enveloped-data message.
  3182. //
  3183. // The unauthenticated attribute to be removed is specified by
  3184. // a 0-based index.
  3185. //--------------------------------------------------------------------------
  3186. type
  3187. PCMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA = ^CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA;
  3188. CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA = record
  3189. cbSize: DWORD;
  3190. dwSignerIndex: DWORD;
  3191. dwUnauthAttrIndex: DWORD;
  3192. end;
  3193. //+-------------------------------------------------------------------------
  3194. // CMSG_CTRL_ADD_CERT
  3195. //
  3196. // Add a certificate to a signed-data or signed-and-enveloped-data message.
  3197. //
  3198. // pvCtrlPara points to a CRYPT_DATA_BLOB containing the certificate's
  3199. // encoded bytes.
  3200. //--------------------------------------------------------------------------
  3201. //+-------------------------------------------------------------------------
  3202. // CMSG_CTRL_DEL_CERT
  3203. //
  3204. // Delete a certificate from a signed-data or signed-and-enveloped-data
  3205. // message.
  3206. //
  3207. // pvCtrlPara points to a DWORD containing the 0-based index of the
  3208. // certificate to be removed.
  3209. //--------------------------------------------------------------------------
  3210. //+-------------------------------------------------------------------------
  3211. // CMSG_CTRL_ADD_CRL
  3212. //
  3213. // Add a CRL to a signed-data or signed-and-enveloped-data message.
  3214. //
  3215. // pvCtrlPara points to a CRYPT_DATA_BLOB containing the CRL's
  3216. // encoded bytes.
  3217. //--------------------------------------------------------------------------
  3218. //+-------------------------------------------------------------------------
  3219. // CMSG_CTRL_DEL_CRL
  3220. //
  3221. // Delete a CRL from a signed-data or signed-and-enveloped-data message.
  3222. //
  3223. // pvCtrlPara points to a DWORD containing the 0-based index of the CRL
  3224. // to be removed.
  3225. //--------------------------------------------------------------------------
  3226. //+-------------------------------------------------------------------------
  3227. // Verify a countersignature, at the SignerInfo level.
  3228. // ie. verify that pbSignerInfoCountersignature contains the encrypted
  3229. // hash of the encryptedDigest field of pbSignerInfo.
  3230. //
  3231. // hCryptProv is used to hash the encryptedDigest field of pbSignerInfo.
  3232. // The only fields referenced from pciCountersigner are SerialNumber, Issuer,
  3233. // and SubjectPublicKeyInfo.
  3234. //--------------------------------------------------------------------------
  3235. function CryptMsgVerifyCountersignatureEncoded(hCryptProv: HCRYPTPROV;
  3236. dwEncodingType: DWORD;
  3237. pbSignerInfo: PBYTE;
  3238. cbSignerInfo: DWORD;
  3239. pbSignerInfoCountersignature: PBYTE;
  3240. cbSignerInfoCountersignature: DWORD;
  3241. pciCountersigner: PCERT_INFO): BOOL; stdcall;
  3242. //+-------------------------------------------------------------------------
  3243. // Countersign an already-existing signature in a message
  3244. //
  3245. // dwIndex is a zero-based index of the SignerInfo to be countersigned.
  3246. //--------------------------------------------------------------------------
  3247. function CryptMsgCountersign(hCryptMsg: HCRYPTMSG;
  3248. dwIndex: DWORD;
  3249. cCountersigners: DWORD;
  3250. rgCountersigners: PCMSG_SIGNER_ENCODE_INFO): BOOL; stdcall;
  3251. //+-------------------------------------------------------------------------
  3252. // Countersign an already-existing signature (encoded SignerInfo).
  3253. // Output an encoded SignerInfo blob, suitable for use as a countersignature
  3254. // attribute in the unauthenticated attributes of a signed-data or
  3255. // signed-and-enveloped-data message.
  3256. //--------------------------------------------------------------------------
  3257. function CryptMsgCountersignEncoded(dwEncodingType: DWORD;
  3258. pbSignerInfo: PBYTE;
  3259. cbSignerInfo: DWORD;
  3260. cCountersigners: DWORD;
  3261. rgCountersigners: PCMSG_SIGNER_ENCODE_INFO;
  3262. pbCountersignature: PBYTE;
  3263. pcbCountersignature: PDWORD): BOOL; stdcall;
  3264. //+-------------------------------------------------------------------------
  3265. // Get a parameter after encoding/decoding a cryptographic message. Called
  3266. // after the final CryptMsgUpdate. Only the CMSG_CONTENT_PARAM and
  3267. // CMSG_COMPUTED_HASH_PARAM are valid for an encoded message.
  3268. //
  3269. // For an encoded HASHED message, the CMSG_COMPUTED_HASH_PARAM can be got
  3270. // before any CryptMsgUpdates to get its length.
  3271. //
  3272. // The pvData type definition depends on the dwParamType value.
  3273. //
  3274. // Elements pointed to by fields in the pvData structure follow the
  3275. // structure. Therefore, *pcbData may exceed the size of the structure.
  3276. //
  3277. // Upon input, if *pcbData == 0, then, *pcbData is updated with the length
  3278. // of the data and the pvData parameter is ignored.
  3279. //
  3280. // Upon return, *pcbData is updated with the length of the data.
  3281. //
  3282. // The OBJID BLOBs returned in the pvData structures point to
  3283. // their still encoded representation. The appropriate functions
  3284. // must be called to decode the information.
  3285. //
  3286. // See below for a list of the parameters to get.
  3287. //--------------------------------------------------------------------------
  3288. function CryptMsgGetParam(hCryptMsg: HCRYPTMSG;
  3289. dwParamType: DWORD;
  3290. dwIndex: DWORD;
  3291. pvData: PVOID;
  3292. pcbData: PDWORD): BOOL; stdcall;
  3293. //+-------------------------------------------------------------------------
  3294. // Get parameter types and their corresponding data structure definitions.
  3295. //--------------------------------------------------------------------------
  3296. const
  3297. CMSG_TYPE_PARAM = 1;
  3298. CMSG_CONTENT_PARAM = 2;
  3299. CMSG_BARE_CONTENT_PARAM = 3;
  3300. CMSG_INNER_CONTENT_TYPE_PARAM = 4;
  3301. CMSG_SIGNER_COUNT_PARAM = 5;
  3302. CMSG_SIGNER_INFO_PARAM = 6;
  3303. CMSG_SIGNER_CERT_INFO_PARAM = 7;
  3304. CMSG_SIGNER_HASH_ALGORITHM_PARAM = 8;
  3305. CMSG_SIGNER_AUTH_ATTR_PARAM = 9;
  3306. CMSG_SIGNER_UNAUTH_ATTR_PARAM = 10;
  3307. CMSG_CERT_COUNT_PARAM = 11;
  3308. CMSG_CERT_PARAM = 12;
  3309. CMSG_CRL_COUNT_PARAM = 13;
  3310. CMSG_CRL_PARAM = 14;
  3311. CMSG_ENVELOPE_ALGORITHM_PARAM = 15;
  3312. CMSG_RECIPIENT_COUNT_PARAM = 17;
  3313. CMSG_RECIPIENT_INDEX_PARAM = 18;
  3314. CMSG_RECIPIENT_INFO_PARAM = 19;
  3315. CMSG_HASH_ALGORITHM_PARAM = 20;
  3316. CMSG_HASH_DATA_PARAM = 21;
  3317. CMSG_COMPUTED_HASH_PARAM = 22;
  3318. CMSG_ENCRYPT_PARAM = 26;
  3319. CMSG_ENCRYPTED_DIGEST = 27;
  3320. CMSG_ENCODED_SIGNER = 28;
  3321. CMSG_ENCODED_MESSAGE = 29;
  3322. //+-------------------------------------------------------------------------
  3323. // CMSG_TYPE_PARAM
  3324. //
  3325. // The type of the decoded message.
  3326. //
  3327. // pvData points to a DWORD
  3328. //--------------------------------------------------------------------------
  3329. //+-------------------------------------------------------------------------
  3330. // CMSG_CONTENT_PARAM
  3331. //
  3332. // The encoded content of a cryptographic message. Depending on how the
  3333. // message was opened, the content is either the whole PKCS#7
  3334. // message (opened to encode) or the inner content (opened to decode).
  3335. // In the decode case, the decrypted content is returned, if enveloped.
  3336. // If not enveloped, and if the inner content is of type DATA, the returned
  3337. // data is the contents octets of the inner content.
  3338. //
  3339. // pvData points to the buffer receiving the content bytes
  3340. //--------------------------------------------------------------------------
  3341. //+-------------------------------------------------------------------------
  3342. // CMSG_BARE_CONTENT_PARAM
  3343. //
  3344. // The encoded content of an encoded cryptographic message, without the
  3345. // outer layer of ContentInfo. That is, only the encoding of the
  3346. // ContentInfo.content field is returned.
  3347. //
  3348. // pvData points to the buffer receiving the content bytes
  3349. //--------------------------------------------------------------------------
  3350. //+-------------------------------------------------------------------------
  3351. // CMSG_INNER_CONTENT_TYPE_PARAM
  3352. //
  3353. // The type of the inner content of a decoded cryptographic message,
  3354. // in the form of a NULL-terminated object identifier string
  3355. // (eg. "1.2.840.113549.1.7.1").
  3356. //
  3357. // pvData points to the buffer receiving the object identifier string
  3358. //--------------------------------------------------------------------------
  3359. //+-------------------------------------------------------------------------
  3360. // CMSG_SIGNER_COUNT_PARAM
  3361. //
  3362. // Count of signers in a SIGNED or SIGNED_AND_ENVELOPED message
  3363. //
  3364. // pvData points to a DWORD
  3365. //--------------------------------------------------------------------------
  3366. //+-------------------------------------------------------------------------
  3367. // CMSG_SIGNER_CERT_INFO_PARAM
  3368. //
  3369. // To get all the signers, repetitively call CryptMsgGetParam, with
  3370. // dwIndex set to 0 .. SignerCount - 1.
  3371. //
  3372. // pvData points to a CERT_INFO struct.
  3373. //
  3374. // Only the following fields have been updated in the CERT_INFO struct:
  3375. // Issuer and SerialNumber.
  3376. //--------------------------------------------------------------------------
  3377. //+-------------------------------------------------------------------------
  3378. // CMSG_SIGNER_INFO_PARAM
  3379. //
  3380. // To get all the signers, repetitively call CryptMsgGetParam, with
  3381. // dwIndex set to 0 .. SignerCount - 1.
  3382. //
  3383. // pvData points to a CMSG_SIGNER_INFO struct.
  3384. //--------------------------------------------------------------------------
  3385. type
  3386. PCMSG_SIGNER_INFO = ^CMSG_SIGNER_INFO;
  3387. CMSG_SIGNER_INFO = record
  3388. dwVersion: DWORD;
  3389. Issuer: CERT_NAME_BLOB;
  3390. SerialNumber: CRYPT_INTEGER_BLOB;
  3391. HashAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  3392. HashEncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  3393. EncryptedHash: CRYPT_DATA_BLOB;
  3394. AuthAttrs: CRYPT_ATTRIBUTES;
  3395. UnauthAttrs: CRYPT_ATTRIBUTES;
  3396. end;
  3397. //+-------------------------------------------------------------------------
  3398. // CMSG_SIGNER_HASH_ALGORITHM_PARAM
  3399. //
  3400. // This parameter specifies the HashAlgorithm that was used for the signer.
  3401. //
  3402. // Set dwIndex to iterate through all the signers.
  3403. //
  3404. // pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  3405. //--------------------------------------------------------------------------
  3406. //+-------------------------------------------------------------------------
  3407. // CMSG_SIGNER_AUTH_ATTR_PARAM
  3408. //
  3409. // The authenticated attributes for the signer.
  3410. //
  3411. // Set dwIndex to iterate through all the signers.
  3412. //
  3413. // pvData points to a CMSG_ATTR struct.
  3414. //--------------------------------------------------------------------------
  3415. type
  3416. CMSG_ATTR = CRYPT_ATTRIBUTES;
  3417. PCMSG_ATTR = ^CRYPT_ATTRIBUTES;
  3418. //+-------------------------------------------------------------------------
  3419. // CMSG_SIGNER_UNAUTH_ATTR_PARAM
  3420. //
  3421. // The unauthenticated attributes for the signer.
  3422. //
  3423. // Set dwIndex to iterate through all the signers.
  3424. //
  3425. // pvData points to a CMSG_ATTR struct.
  3426. //--------------------------------------------------------------------------
  3427. //+-------------------------------------------------------------------------
  3428. // CMSG_CERT_COUNT_PARAM
  3429. //
  3430. // Count of certificates in a SIGNED or SIGNED_AND_ENVELOPED message.
  3431. //
  3432. // pvData points to a DWORD
  3433. //--------------------------------------------------------------------------
  3434. //+-------------------------------------------------------------------------
  3435. // CMSG_CERT_PARAM
  3436. //
  3437. // To get all the certificates, repetitively call CryptMsgGetParam, with
  3438. // dwIndex set to 0 .. CertCount - 1.
  3439. //
  3440. // pvData points to an array of the certificate's encoded bytes.
  3441. //--------------------------------------------------------------------------
  3442. //+-------------------------------------------------------------------------
  3443. // CMSG_CRL_COUNT_PARAM
  3444. //
  3445. // Count of CRLs in a SIGNED or SIGNED_AND_ENVELOPED message.
  3446. //
  3447. // pvData points to a DWORD
  3448. //--------------------------------------------------------------------------
  3449. //+-------------------------------------------------------------------------
  3450. // CMSG_CRL_PARAM
  3451. //
  3452. // To get all the CRLs, repetitively call CryptMsgGetParam, with
  3453. // dwIndex set to 0 .. CrlCount - 1.
  3454. //
  3455. // pvData points to an array of the CRL's encoded bytes.
  3456. //--------------------------------------------------------------------------
  3457. //+-------------------------------------------------------------------------
  3458. // CMSG_ENVELOPE_ALGORITHM_PARAM
  3459. //
  3460. // The ContentEncryptionAlgorithm that was used in
  3461. // an ENVELOPED or SIGNED_AND_ENVELOPED message.
  3462. //
  3463. // pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  3464. //--------------------------------------------------------------------------
  3465. //+-------------------------------------------------------------------------
  3466. // CMSG_RECIPIENT_COUNT_PARAM
  3467. //
  3468. // Count of recipients in an ENVELOPED or SIGNED_AND_ENVELOPED message.
  3469. //
  3470. // pvData points to a DWORD
  3471. //--------------------------------------------------------------------------
  3472. //+-------------------------------------------------------------------------
  3473. // CMSG_RECIPIENT_INDEX_PARAM
  3474. //
  3475. // Index of the recipient used to decrypt an ENVELOPED or SIGNED_AND_ENVELOPED
  3476. // message.
  3477. //
  3478. // pvData points to a DWORD
  3479. //--------------------------------------------------------------------------
  3480. //+-------------------------------------------------------------------------
  3481. // CMSG_RECIPIENT_INFO_PARAM
  3482. //
  3483. // To get all the recipients, repetitively call CryptMsgGetParam, with
  3484. // dwIndex set to 0 .. RecipientCount - 1.
  3485. //
  3486. // pvData points to a CERT_INFO struct.
  3487. //
  3488. // Only the following fields have been updated in the CERT_INFO struct:
  3489. // Issuer, SerialNumber and PublicKeyAlgorithm. The PublicKeyAlgorithm
  3490. // specifies the KeyEncryptionAlgorithm that was used.
  3491. //--------------------------------------------------------------------------
  3492. //+-------------------------------------------------------------------------
  3493. // CMSG_HASH_ALGORITHM_PARAM
  3494. //
  3495. // The HashAlgorithm in a HASHED message.
  3496. //
  3497. // pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  3498. //--------------------------------------------------------------------------
  3499. //+-------------------------------------------------------------------------
  3500. // CMSG_HASH_DATA_PARAM
  3501. //
  3502. // The hash in a HASHED message.
  3503. //
  3504. // pvData points to an array of bytes.
  3505. //--------------------------------------------------------------------------
  3506. //+-------------------------------------------------------------------------
  3507. // CMSG_COMPUTED_HASH_PARAM
  3508. //
  3509. // The computed hash for a HASHED message.
  3510. //
  3511. // This may be called for either an encoded or decoded message.
  3512. // It also may be called before any encoded CryptMsgUpdates to get its length.
  3513. //
  3514. // pvData points to an array of bytes.
  3515. //--------------------------------------------------------------------------
  3516. //+-------------------------------------------------------------------------
  3517. // CMSG_ENCRYPT_PARAM
  3518. //
  3519. // The ContentEncryptionAlgorithm that was used in an ENCRYPTED message.
  3520. //
  3521. // pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  3522. //--------------------------------------------------------------------------
  3523. //+-------------------------------------------------------------------------
  3524. // CMSG_ENCODED_MESSAGE
  3525. //
  3526. // The full encoded message. This is useful in the case of a decoded
  3527. // message which has been modified (eg. a signed-data or
  3528. // signed-and-enveloped-data message which has been countersigned).
  3529. //
  3530. // pvData points to an array of the message's encoded bytes.
  3531. //--------------------------------------------------------------------------
  3532. //+-------------------------------------------------------------------------
  3533. // CryptMsg OID installable functions
  3534. //--------------------------------------------------------------------------
  3535. // If *phCryptProv is NULL upon entry, then, if supported, the installable
  3536. // function should acquire a default provider and return. Note, its up
  3537. // to the installable function to release at process detach.
  3538. const
  3539. CMSG_OID_GEN_ENCRYPT_KEY_FUNC = 'CryptMsgDllGenEncryptKey';
  3540. type
  3541. PFN_CMSG_GEN_ENCRYPT_KEY = function(phCryptProv: PHCRYPTPROV;
  3542. paiEncrypt: PCRYPT_ALGORITHM_IDENTIFIER;
  3543. pvEncryptAuxInfo: PVOID;
  3544. pPublicKeyInfo: PCERT_PUBLIC_KEY_INFO;
  3545. phEncryptKey: PHCRYPTKEY
  3546. ): BOOL; stdcall;
  3547. const
  3548. CMSG_OID_EXPORT_ENCRYPT_KEY_FUNC = 'CryptMsgDllExportEncryptKey';
  3549. type
  3550. PFN_CMSG_EXPORT_ENCRYPT_KEY = function(hCryptProv: HCRYPTPROV;
  3551. hEncryptKey: HCRYPTKEY;
  3552. pPublicKeyInfo: PCERT_PUBLIC_KEY_INFO;
  3553. pbData: PBYTE;
  3554. pcbData: PDWORD): BOOL; stdcall;
  3555. const
  3556. CMSG_OID_IMPORT_ENCRYPT_KEY_FUNC = 'CryptMsgDllImportEncryptKey';
  3557. type
  3558. PFN_CMSG_IMPORT_ENCRYPT_KEY = function(hCryptProv: HCRYPTPROV;
  3559. dwKeySpec: DWORD;
  3560. paiEncrypt: PCRYPT_ALGORITHM_IDENTIFIER;
  3561. paiPubKey: PCRYPT_ALGORITHM_IDENTIFIER;
  3562. pbEncodedKey: PBYTE;
  3563. cbEncodedKey: DWORD;
  3564. phEncryptKey: PHCRYPTKEY
  3565. ): BOOL; stdcall;
  3566. //+=========================================================================
  3567. // Certificate Store Data Structures and APIs
  3568. //==========================================================================
  3569. //+-------------------------------------------------------------------------
  3570. // In its most basic implementation, a cert store is simply a
  3571. // collection of certificates and/or CRLs. This is the case when
  3572. // a cert store is opened with all of its certificates and CRLs
  3573. // coming from a PKCS #7 encoded cryptographic message.
  3574. //
  3575. // Nonetheless, all cert stores have the following properties:
  3576. // - A public key may have more than one certificate in the store.
  3577. // For example, a private/public key used for signing may have a
  3578. // certificate issued for VISA and another issued for
  3579. // Mastercard. Also, when a certificate is renewed there might
  3580. // be more than one certificate with the same subject and
  3581. // issuer.
  3582. // - However, each certificate in the store is uniquely
  3583. // identified by its Issuer and SerialNumber.
  3584. // - There's an issuer of subject certificate relationship. A
  3585. // certificate's issuer is found by doing a match of
  3586. // pSubjectCert->Issuer with pIssuerCert->Subject.
  3587. // The relationship is verified by using
  3588. // the issuer's public key to verify the subject certificate's
  3589. // signature. Note, there might be X.509 v3 extensions
  3590. // to assist in finding the issuer certificate.
  3591. // - Since issuer certificates might be renewed, a subject
  3592. // certificate might have more than one issuer certificate.
  3593. // - There's an issuer of CRL relationship. An
  3594. // issuer's CRL is found by doing a match of
  3595. // pIssuerCert->Subject with pCrl->Issuer.
  3596. // The relationship is verified by using
  3597. // the issuer's public key to verify the CRL's
  3598. // signature. Note, there might be X.509 v3 extensions
  3599. // to assist in finding the CRL.
  3600. // - Since some issuers might support the X.509 v3 delta CRL
  3601. // extensions, an issuer might have more than one CRL.
  3602. // - The store shouldn't have any redundant certificates or
  3603. // CRLs. There shouldn't be two certificates with the same
  3604. // Issuer and SerialNumber. There shouldn't be two CRLs with
  3605. // the same Issuer, ThisUpdate and NextUpdate.
  3606. // - The store has NO policy or trust information. No
  3607. // certificates are tagged as being "root". Its up to
  3608. // the application to maintain a list of CertIds (Issuer +
  3609. // SerialNumber) for certificates it trusts.
  3610. // - The store might contain bad certificates and/or CRLs.
  3611. // The issuer's signature of a subject certificate or CRL may
  3612. // not verify. Certificates or CRLs may not satisfy their
  3613. // time validity requirements. Certificates may be
  3614. // revoked.
  3615. //
  3616. // In addition to the certificates and CRLs, properties can be
  3617. // stored. There are two predefined property IDs for a user
  3618. // certificate: CERT_KEY_PROV_HANDLE_PROP_ID and
  3619. // CERT_KEY_PROV_INFO_PROP_ID. The CERT_KEY_PROV_HANDLE_PROP_ID
  3620. // is a HCRYPTPROV handle to the private key assoicated
  3621. // with the certificate. The CERT_KEY_PROV_INFO_PROP_ID contains
  3622. // information to be used to call
  3623. // CryptAcquireContext and CryptProvSetParam to get a handle
  3624. // to the private key associated with the certificate.
  3625. //
  3626. // There exists two more predefined property IDs for certificates
  3627. // and CRLs, CERT_SHA1_HASH_PROP_ID and CERT_MD5_HASH_PROP_ID.
  3628. // If these properties don't already exist, then, a hash of the
  3629. // content is computed. (CERT_HASH_PROP_ID maps to the default
  3630. // hash algorithm, currently, CERT_SHA1_HASH_PROP_ID).
  3631. //
  3632. // There are additional APIs for creating certificate and CRL
  3633. // contexts not in a store (CertCreateCertificateContext and
  3634. // CertCreateCRLContext).
  3635. //
  3636. //--------------------------------------------------------------------------
  3637. type
  3638. HCERTSTORE = PVOID;
  3639. //+-------------------------------------------------------------------------
  3640. // Certificate context.
  3641. //
  3642. // A certificate context contains both the encoded and decoded representation
  3643. // of a certificate. A certificate context returned by a cert store function
  3644. // must be freed by calling the CertFreeCertificateContext function. The
  3645. // CertDuplicateCertificateContext function can be called to make a duplicate
  3646. // copy (which also must be freed by calling CertFreeCertificateContext).
  3647. //--------------------------------------------------------------------------
  3648. type
  3649. PCERT_CONTEXT = ^CERT_CONTEXT;
  3650. CERT_CONTEXT = record
  3651. dwCertEncodingType: DWORD;
  3652. pbCertEncoded: PBYTE;
  3653. cbCertEncoded: DWORD;
  3654. pCertInfo: PCERT_INFO;
  3655. hCertStore: HCERTSTORE;
  3656. end;
  3657. type
  3658. PCCERT_CONTEXT = ^CERT_CONTEXT;
  3659. //+-------------------------------------------------------------------------
  3660. // CRL context.
  3661. //
  3662. // A CRL context contains both the encoded and decoded representation
  3663. // of a CRL. A CRL context returned by a cert store function
  3664. // must be freed by calling the CertFreeCRLContext function. The
  3665. // CertDuplicateCRLContext function can be called to make a duplicate
  3666. // copy (which also must be freed by calling CertFreeCRLContext).
  3667. //--------------------------------------------------------------------------
  3668. type
  3669. PCRL_CONTEXT = ^CRL_CONTEXT;
  3670. CRL_CONTEXT = record
  3671. dwCertEncodingType: DWORD;
  3672. pbCrlEncoded: PBYTE;
  3673. cbCrlEncoded: DWORD;
  3674. pCrlInfo: PCRL_INFO;
  3675. hCertStore: HCERTSTORE;
  3676. end;
  3677. type
  3678. PCCRL_CONTEXT = ^CRL_CONTEXT;
  3679. //+-------------------------------------------------------------------------
  3680. // Certificate Trust List (CTL) context.
  3681. //
  3682. // A CTL context contains both the encoded and decoded representation
  3683. // of a CTL. Also contains an opened HCRYPTMSG handle to the decoded
  3684. // cryptographic signed message containing the CTL_INFO as its inner content.
  3685. // pbCtlContent is the encoded inner content of the signed message.
  3686. //
  3687. // The CryptMsg APIs can be used to extract additional signer information.
  3688. //--------------------------------------------------------------------------
  3689. type
  3690. PCTL_CONTEXT = ^CTL_CONTEXT;
  3691. CTL_CONTEXT = record
  3692. dwMsgAndCertEncodingType: DWORD;
  3693. pbCtlEncoded: PBYTE;
  3694. cbCtlEncoded: DWORD;
  3695. pCtlInfo: PCTL_INFO;
  3696. hCertStore: HCERTSTORE;
  3697. hCryptMsg: HCRYPTMSG;
  3698. pbCtlContent: PBYTE;
  3699. cbCtlContent: DWORD;
  3700. end;
  3701. type
  3702. PCCTL_CONTEXT = ^CTL_CONTEXT;
  3703. //+-------------------------------------------------------------------------
  3704. // Certificate, CRL and CTL property IDs
  3705. //
  3706. // See CertSetCertificateContextProperty or CertGetCertificateContextProperty
  3707. // for usage information.
  3708. //--------------------------------------------------------------------------
  3709. const
  3710. CERT_KEY_PROV_HANDLE_PROP_ID = 1;
  3711. CERT_KEY_PROV_INFO_PROP_ID = 2;
  3712. CERT_SHA1_HASH_PROP_ID = 3;
  3713. CERT_MD5_HASH_PROP_ID = 4;
  3714. CERT_HASH_PROP_ID = CERT_SHA1_HASH_PROP_ID;
  3715. CERT_KEY_CONTEXT_PROP_ID = 5;
  3716. CERT_KEY_SPEC_PROP_ID = 6;
  3717. CERT_IE30_RESERVED_PROP_ID = 7;
  3718. CERT_PUBKEY_HASH_RESERVED_PROP_ID = 8;
  3719. CERT_ENHKEY_USAGE_PROP_ID = 9;
  3720. CERT_CTL_USAGE_PROP_ID = CERT_ENHKEY_USAGE_PROP_ID;
  3721. CERT_NEXT_UPDATE_LOCATION_PROP_ID = 10;
  3722. CERT_FRIENDLY_NAME_PROP_ID = 11;
  3723. CERT_PVK_FILE_PROP_ID = 12;
  3724. // Note, 32 - 34 are reserved for the CERT, CRL and CTL file element IDs.
  3725. CERT_FIRST_RESERVED_PROP_ID = 13;
  3726. CERT_LAST_RESERVED_PROP_ID = $00007FFF;
  3727. CERT_FIRST_USER_PROP_ID = $00008000;
  3728. CERT_LAST_USER_PROP_ID = $0000FFFF;
  3729. function IS_CERT_HASH_PROP_ID(X: DWORD): BOOL;
  3730. //+-------------------------------------------------------------------------
  3731. // Cryptographic Key Provider Information
  3732. //
  3733. // CRYPT_KEY_PROV_INFO defines the CERT_KEY_PROV_INFO_PROP_ID's pvData.
  3734. //
  3735. // The CRYPT_KEY_PROV_INFO fields are passed to CryptAcquireContext
  3736. // to get a HCRYPTPROV handle. The optional CRYPT_KEY_PROV_PARAM fields are
  3737. // passed to CryptProvSetParam to further initialize the provider.
  3738. //
  3739. // The dwKeySpec field identifies the private key to use from the container
  3740. // For example, AT_KEYEXCHANGE or AT_SIGNATURE.
  3741. //--------------------------------------------------------------------------
  3742. type
  3743. PCRYPT_KEY_PROV_PARAM = ^CRYPT_KEY_PROV_PARAM;
  3744. CRYPT_KEY_PROV_PARAM = record
  3745. dwParam: DWORD;
  3746. pbData: PBYTE;
  3747. cbData: DWORD;
  3748. dwFlags: DWORD;
  3749. end;
  3750. type
  3751. PCRYPT_KEY_PROV_INFO = ^CRYPT_KEY_PROV_INFO;
  3752. CRYPT_KEY_PROV_INFO = record
  3753. pwszContainerName: LPWSTR;
  3754. pwszProvName: LPWSTR;
  3755. dwProvType: DWORD;
  3756. dwFlags: DWORD;
  3757. cProvParam: DWORD;
  3758. rgProvParam: PCRYPT_KEY_PROV_PARAM;
  3759. dwKeySpec: DWORD;
  3760. end;
  3761. //+-------------------------------------------------------------------------
  3762. // The following flag should be set in the above dwFlags to enable
  3763. // a CertSetCertificateContextProperty(CERT_KEY_CONTEXT_PROP_ID) after a
  3764. // CryptAcquireContext is done in the Sign or Decrypt Message functions.
  3765. //
  3766. // The following define must not collide with any of the
  3767. // CryptAcquireContext dwFlag defines.
  3768. //--------------------------------------------------------------------------
  3769. const
  3770. CERT_SET_KEY_PROV_HANDLE_PROP_ID = $00000001;
  3771. CERT_SET_KEY_CONTEXT_PROP_ID = $00000001;
  3772. //+-------------------------------------------------------------------------
  3773. // Certificate Key Context
  3774. //
  3775. // CERT_KEY_CONTEXT defines the CERT_KEY_CONTEXT_PROP_ID's pvData.
  3776. //--------------------------------------------------------------------------
  3777. type
  3778. PCERT_KEY_CONTEXT = ^CERT_KEY_CONTEXT;
  3779. CERT_KEY_CONTEXT = record
  3780. cbSize: DWORD; // sizeof(CERT_KEY_CONTEXT)
  3781. hCryptProv: HCRYPTPROV;
  3782. dwKeySpec: DWORD;
  3783. end;
  3784. //+-------------------------------------------------------------------------
  3785. // Certificate Store Provider Types
  3786. //--------------------------------------------------------------------------
  3787. const
  3788. CERT_STORE_PROV_MSG = (LPCSTR(1));
  3789. CERT_STORE_PROV_MEMORY = (LPCSTR(2));
  3790. CERT_STORE_PROV_FILE = (LPCSTR(3));
  3791. CERT_STORE_PROV_REG = (LPCSTR(4));
  3792. CERT_STORE_PROV_PKCS7 = (LPCSTR(5));
  3793. CERT_STORE_PROV_SERIALIZED = (LPCSTR(6));
  3794. CERT_STORE_PROV_FILENAME_A = (LPCSTR(7));
  3795. CERT_STORE_PROV_FILENAME_W = (LPCSTR(8));
  3796. CERT_STORE_PROV_FILENAME = CERT_STORE_PROV_FILENAME_W;
  3797. CERT_STORE_PROV_SYSTEM_A = (LPCSTR(9));
  3798. CERT_STORE_PROV_SYSTEM_W = (LPCSTR(10));
  3799. CERT_STORE_PROV_SYSTEM = CERT_STORE_PROV_SYSTEM_W;
  3800. sz_CERT_STORE_PROV_MEMORY = 'Memory';
  3801. sz_CERT_STORE_PROV_FILENAME_W = 'File';
  3802. sz_CERT_STORE_PROV_FILENAME = sz_CERT_STORE_PROV_FILENAME_W;
  3803. sz_CERT_STORE_PROV_SYSTEM_W = 'System';
  3804. sz_CERT_STORE_PROV_SYSTEM = sz_CERT_STORE_PROV_SYSTEM_W;
  3805. sz_CERT_STORE_PROV_PKCS7 = 'PKCS7';
  3806. sz_CERT_STORE_PROV_SERIALIZED = 'Serialized';
  3807. //+-------------------------------------------------------------------------
  3808. // Certificate Store verify/results flags
  3809. //--------------------------------------------------------------------------
  3810. CERT_STORE_SIGNATURE_FLAG = $00000001;
  3811. CERT_STORE_TIME_VALIDITY_FLAG = $00000002;
  3812. CERT_STORE_REVOCATION_FLAG = $00000004;
  3813. CERT_STORE_NO_CRL_FLAG = $00010000;
  3814. CERT_STORE_NO_ISSUER_FLAG = $00020000;
  3815. //+-------------------------------------------------------------------------
  3816. // Certificate Store open/property flags
  3817. //--------------------------------------------------------------------------
  3818. CERT_STORE_NO_CRYPT_RELEASE_FLAG = $00000001;
  3819. CERT_STORE_READONLY_FLAG = $00008000;
  3820. //+-------------------------------------------------------------------------
  3821. // Certificate Store Provider flags are in the HiWord (0xFFFF0000)
  3822. //--------------------------------------------------------------------------
  3823. //+-------------------------------------------------------------------------
  3824. // Certificate System Store Flag Values
  3825. //--------------------------------------------------------------------------
  3826. // Location of the system store in the registry:
  3827. // HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE
  3828. CERT_SYSTEM_STORE_LOCATION_MASK = $00030000;
  3829. CERT_SYSTEM_STORE_CURRENT_USER = $00010000;
  3830. CERT_SYSTEM_STORE_LOCAL_MACHINE = $00020000;
  3831. //+-------------------------------------------------------------------------
  3832. // Open the cert store using the specified store provider.
  3833. //
  3834. // hCryptProv specifies the crypto provider to use to create the hash
  3835. // properties or verify the signature of a subject certificate or CRL.
  3836. // The store doesn't need to use a private
  3837. // key. If the CERT_STORE_NO_CRYPT_RELEASE_FLAG isn't set, hCryptProv is
  3838. // CryptReleaseContext'ed on the final CertCloseStore.
  3839. //
  3840. // Note, if the open fails, hCryptProv is released if it would have been
  3841. // released when the store was closed.
  3842. //
  3843. // If hCryptProv is zero, then, the default provider and container for the
  3844. // PROV_RSA_FULL provider type is CryptAcquireContext'ed with
  3845. // CRYPT_VERIFYCONTEXT access. The CryptAcquireContext is deferred until
  3846. // the first create hash or verify signature. In addition, once acquired,
  3847. // the default provider isn't released until process exit when crypt32.dll
  3848. // is unloaded. The acquired default provider is shared across all stores
  3849. // and threads.
  3850. //
  3851. // After initializing the store's data structures and optionally acquiring a
  3852. // default crypt provider, CertOpenStore calls CryptGetOIDFunctionAddress to
  3853. // get the address of the CRYPT_OID_OPEN_STORE_PROV_FUNC specified by
  3854. // lpszStoreProvider. Since a store can contain certificates with different
  3855. // encoding types, CryptGetOIDFunctionAddress is called with dwEncodingType
  3856. // set to 0 and not the dwEncodingType passed to CertOpenStore.
  3857. // PFN_CERT_DLL_OPEN_STORE_FUNC specifies the signature of the provider's
  3858. // open function. This provider open function is called to load the
  3859. // store's certificates and CRLs. Optionally, the provider may return an
  3860. // array of functions called before a certificate or CRL is added or deleted
  3861. // or has a property that is set.
  3862. //
  3863. // Use of the dwEncodingType parameter is provider dependent. The type
  3864. // definition for pvPara also depends on the provider.
  3865. //
  3866. // Store providers are installed or registered via
  3867. // CryptInstallOIDFunctionAddress or CryptRegisterOIDFunction, where,
  3868. // dwEncodingType is 0 and pszFuncName is CRYPT_OID_OPEN_STORE_PROV_FUNC.
  3869. //
  3870. // Here's a list of the predefined provider types (implemented in crypt32.dll):
  3871. //
  3872. // CERT_STORE_PROV_MSG:
  3873. // Gets the certificates and CRLs from the specified cryptographic message.
  3874. // dwEncodingType contains the message and certificate encoding types.
  3875. // The message's handle is passed in pvPara. Given,
  3876. // HCRYPTMSG hCryptMsg; pvPara = (const void *) hCryptMsg;
  3877. //
  3878. // CERT_STORE_PROV_MEMORY
  3879. // sz_CERT_STORE_PROV_MEMORY:
  3880. // Opens a store without any initial certificates or CRLs. pvPara
  3881. // isn't used.
  3882. //
  3883. // CERT_STORE_PROV_FILE:
  3884. // Reads the certificates and CRLs from the specified file. The file's
  3885. // handle is passed in pvPara. Given,
  3886. // HANDLE hFile; pvPara = (const void *) hFile;
  3887. //
  3888. // For a successful open, the file pointer is advanced past
  3889. // the certificates and CRLs and their properties read from the file.
  3890. // Note, only expects a serialized store and not a file containing
  3891. // either a PKCS #7 signed message or a single encoded certificate.
  3892. //
  3893. // The hFile isn't closed.
  3894. //
  3895. // CERT_STORE_PROV_REG:
  3896. // Reads the certificates and CRLs from the registry. The registry's
  3897. // key handle is passed in pvPara. Given,
  3898. // HKEY hKey; pvPara = (const void *) hKey;
  3899. //
  3900. // The input hKey isn't closed by the provider. Before returning, the
  3901. // provider opens/creates "Certificates" and "CRLs" subkeys. These
  3902. // subkeys remain open until the store is closed.
  3903. //
  3904. // If CERT_STORE_READONLY_FLAG is set, then, the registry subkeys are
  3905. // RegOpenKey'ed with KEY_READ_ACCESS. Otherwise, the registry subkeys
  3906. // are RegCreateKey'ed with KEY_ALL_ACCESS.
  3907. //
  3908. // This provider returns the array of functions for reading, writing,
  3909. // deleting and property setting certificates and CRLs.
  3910. // Any changes to the opened store are immediately pushed through to
  3911. // the registry. However, if CERT_STORE_READONLY_FLAG is set, then,
  3912. // writing, deleting or property setting results in a
  3913. // SetLastError(E_ACCESSDENIED).
  3914. //
  3915. // Note, all the certificates and CRLs are read from the registry
  3916. // when the store is opened. The opened store serves as a write through
  3917. // cache. However, the opened store isn't notified of other changes
  3918. // made to the registry. Note, RegNotifyChangeKeyValue is supported
  3919. // on NT but not supported on Windows95.
  3920. //
  3921. // CERT_STORE_PROV_PKCS7:
  3922. // sz_CERT_STORE_PROV_PKCS7:
  3923. // Gets the certificates and CRLs from the encoded PKCS #7 signed message.
  3924. // dwEncodingType specifies the message and certificate encoding types.
  3925. // The pointer to the encoded message's blob is passed in pvPara. Given,
  3926. // CRYPT_DATA_BLOB EncodedMsg; pvPara = (const void *) &EncodedMsg;
  3927. //
  3928. // Note, also supports the IE3.0 special version of a
  3929. // PKCS #7 signed message referred to as a "SPC" formatted message.
  3930. //
  3931. // CERT_STORE_PROV_SERIALIZED:
  3932. // sz_CERT_STORE_PROV_SERIALIZED:
  3933. // Gets the certificates and CRLs from memory containing a serialized
  3934. // store. The pointer to the serialized memory blob is passed in pvPara.
  3935. // Given,
  3936. // CRYPT_DATA_BLOB Serialized; pvPara = (const void *) &Serialized;
  3937. //
  3938. // CERT_STORE_PROV_FILENAME_A:
  3939. // CERT_STORE_PROV_FILENAME_W:
  3940. // CERT_STORE_PROV_FILENAME:
  3941. // sz_CERT_STORE_PROV_FILENAME_W:
  3942. // sz_CERT_STORE_PROV_FILENAME:
  3943. // Opens the file and first attempts to read as a serialized store. Then,
  3944. // as a PKCS #7 signed message. Finally, as a single encoded certificate.
  3945. // The filename is passed in pvPara. The filename is UNICODE for the
  3946. // "_W" provider and ASCII for the "_A" provider. For "_W": given,
  3947. // LPCWSTR pwszFilename; pvPara = (const void *) pwszFilename;
  3948. // For "_A": given,
  3949. // LPCSTR pszFilename; pvPara = (const void *) pszFilename;
  3950. //
  3951. // Note, the default (without "_A" or "_W") is unicode.
  3952. //
  3953. // Note, also supports the reading of the IE3.0 special version of a
  3954. // PKCS #7 signed message file referred to as a "SPC" formatted file.
  3955. //
  3956. // CERT_STORE_PROV_SYSTEM_A:
  3957. // CERT_STORE_PROV_SYSTEM_W:
  3958. // CERT_STORE_PROV_SYSTEM:
  3959. // sz_CERT_STORE_PROV_SYSTEM_W:
  3960. // sz_CERT_STORE_PROV_SYSTEM:
  3961. // Opens the specified "system" store. Currently, all the system
  3962. // stores are stored in the registry. The upper word of the dwFlags
  3963. // parameter is used to specify the location of the system store. It
  3964. // should be set to either CERT_SYSTEM_STORE_CURRENT_USER for
  3965. // HKEY_CURRENT_USER or CERT_SYSTEM_STORE_LOCAL_MACHINE for
  3966. // HKEY_LOCAL_MACHINE.
  3967. //
  3968. // After opening the registry key associated with the system name,
  3969. // the CERT_STORE_PROV_REG provider is called to complete the open.
  3970. //
  3971. // The system store name is passed in pvPara. The name is UNICODE for the
  3972. // "_W" provider and ASCII for the "_A" provider. For "_W": given,
  3973. // LPCWSTR pwszSystemName; pvPara = (const void *) pwszSystemName;
  3974. // For "_A": given,
  3975. // LPCSTR pszSystemName; pvPara = (const void *) pszSystemName;
  3976. //
  3977. // Note, the default (without "_A" or "_W") is UNICODE.
  3978. //
  3979. // If CERT_STORE_READONLY_FLAG is set, then, the registry is
  3980. // RegOpenKey'ed with KEY_READ_ACCESS. Otherwise, the registry is
  3981. // RegCreateKey'ed with KEY_ALL_ACCESS.
  3982. //
  3983. // The "root" store is treated differently from the other system
  3984. // stores. Before a certificate is added to or deleted from the "root"
  3985. // store, a pop up message box is displayed. The certificate's subject,
  3986. // issuer, serial number, time validity, sha1 and md5 thumbprints are
  3987. // displayed. The user is given the option to do the add or delete.
  3988. // If they don't allow the operation, LastError is set to E_ACCESSDENIED.
  3989. //--------------------------------------------------------------------------
  3990. function CertOpenStore(lpszStoreProvider: LPCSTR;
  3991. dwEncodingType: DWORD;
  3992. hCryptProv: HCRYPTPROV;
  3993. dwFlags: DWORD;
  3994. const pvPara: PVOID): HCERTSTORE; stdcall;
  3995. //+-------------------------------------------------------------------------
  3996. // OID Installable Certificate Store Provider Data Structures
  3997. //--------------------------------------------------------------------------
  3998. // Handle returned by the store provider when opened.
  3999. type
  4000. HCERTSTOREPROV = PVOID;
  4001. // Store Provider OID function's pszFuncName.
  4002. const
  4003. CRYPT_OID_OPEN_STORE_PROV_FUNC = 'CertDllOpenStoreProv';
  4004. // Note, the Store Provider OID function's dwEncodingType is always 0.
  4005. // The following information is returned by the provider when opened. Its
  4006. // zeroed with cbSize set before the provider is called. If the provider
  4007. // doesn't need to be called again after the open it doesn't need to
  4008. // make any updates to the CERT_STORE_PROV_INFO.
  4009. type
  4010. PCERT_STORE_PROV_INFO = ^CERT_STORE_PROV_INFO;
  4011. CERT_STORE_PROV_INFO = record
  4012. cbSize: DWORD;
  4013. cStoreProvFunc: DWORD;
  4014. rgpvStoreProvFunc: PPVOID;
  4015. hStoreProv: HCERTSTOREPROV;
  4016. dwStoreProvFlags: DWORD;
  4017. end;
  4018. // Definition of the store provider's open function.
  4019. //
  4020. // *pStoreProvInfo has been zeroed before the call.
  4021. //
  4022. // Note, pStoreProvInfo->cStoreProvFunc should be set last. Once set,
  4023. // all subsequent store calls, such as CertAddSerializedElementToStore will
  4024. // call the appropriate provider callback function.
  4025. type
  4026. PFN_CERT_DLL_OPEN_STORE_PROV_FUNC = function(lpszStoreProvider: LPCSTR;
  4027. dwEncodingType: DWORD;
  4028. hCryptProv: HCRYPTPROV;
  4029. dwFlags: DWORD;
  4030. const pvPara: PVOID;
  4031. hCertStore: HCERTSTORE;
  4032. pStoreProvInfo: PCERT_STORE_PROV_INFO
  4033. ): BOOL; stdcall;
  4034. // Indices into the store provider's array of callback functions.
  4035. //
  4036. // The provider can implement any subset of the following functions. It
  4037. // sets pStoreProvInfo->cStoreProvFunc to the last index + 1 and any
  4038. // preceding not implemented functions to NULL.
  4039. const
  4040. CERT_STORE_PROV_CLOSE_FUNC = 0;
  4041. CERT_STORE_PROV_READ_CERT_FUNC = 1;
  4042. CERT_STORE_PROV_WRITE_CERT_FUNC = 2;
  4043. CERT_STORE_PROV_DELETE_CERT_FUNC = 3;
  4044. CERT_STORE_PROV_SET_CERT_PROPERTY_FUNC = 4;
  4045. CERT_STORE_PROV_READ_CRL_FUNC = 5;
  4046. CERT_STORE_PROV_WRITE_CRL_FUNC = 6;
  4047. CERT_STORE_PROV_DELETE_CRL_FUNC = 7;
  4048. CERT_STORE_PROV_SET_CRL_PROPERTY_FUNC = 8;
  4049. CERT_STORE_PROV_READ_CTL_FUNC = 9;
  4050. CERT_STORE_PROV_WRITE_CTL_FUNC = 10;
  4051. CERT_STORE_PROV_DELETE_CTL_FUNC = 11;
  4052. CERT_STORE_PROV_SET_CTL_PROPERTY_FUNC = 12;
  4053. // Called by CertCloseStore when the store's reference count is
  4054. // decremented to 0.
  4055. type
  4056. PFN_CERT_STORE_PROV_CLOSE = procedure(hStoreProv: HCERTSTOREPROV;
  4057. dwFlags: DWORD); stdcall;
  4058. // Currently not called directly by the store APIs. However, may be exported
  4059. // to support other providers based on it.
  4060. //
  4061. // Reads the provider's copy of the certificate context. If it exists,
  4062. // creates a new certificate context.
  4063. type
  4064. PFN_CERT_STORE_PROV_READ_CERT = function(hStoreProv: HCERTSTOREPROV;
  4065. pStoreCertContext: PCCERT_CONTEXT;
  4066. dwFlags: DWORD;
  4067. var ppProvCertContext: PCCERT_CONTEXT
  4068. ): BOOL; stdcall;
  4069. const
  4070. CERT_STORE_PROV_WRITE_ADD_FLAG = $1;
  4071. // Called by CertAddEncodedCertificateToStore,
  4072. // CertAddCertificateContextToStore or CertAddSerializedElementToStore before
  4073. // adding to the store. The CERT_STORE_PROV_WRITE_ADD_FLAG is set. In
  4074. // addition to the encoded certificate, the added pCertContext might also
  4075. // have properties.
  4076. //
  4077. // Returns TRUE if its OK to update the the store.
  4078. type
  4079. PFN_CERT_STORE_PROV_WRITE_CERT = function(hStoreProv: HCERTSTOREPROV;
  4080. pCertContext: PCCERT_CONTEXT;
  4081. dwFlags: DWORD): BOOL; stdcall;
  4082. // Called by CertDeleteCertificateFromStore before deleting from the
  4083. // store.
  4084. //
  4085. // Returns TRUE if its OK to delete from the store.
  4086. type
  4087. PFN_CERT_STORE_PROV_DELETE_CERT = function(hStoreProv: HCERTSTOREPROV;
  4088. pCertContext: PCCERT_CONTEXT;
  4089. dwFlags: DWORD): BOOL; stdcall;
  4090. // Called by CertSetCertificateContextProperty before setting the
  4091. // certificate's property. Also called by CertGetCertificateContextProperty,
  4092. // when getting a hash property that needs to be created and then persisted
  4093. // via the set.
  4094. //
  4095. // Upon input, the property hasn't been set for the pCertContext parameter.
  4096. //
  4097. // Returns TRUE if its OK to set the property.
  4098. type
  4099. PFN_CERT_STORE_PROV_SET_CERT_PROPERTY = function(hStoreProv: HCERTSTOREPROV;
  4100. pCertContext: PCCERT_CONTEXT;
  4101. dwPropId: DWORD;
  4102. dwFlags: DWORD;
  4103. const pvData: PVOID
  4104. ): BOOL; stdcall;
  4105. // Currently not called directly by the store APIs. However, may be exported
  4106. // to support other providers based on it.
  4107. //
  4108. // Reads the provider's copy of the CRL context. If it exists,
  4109. // creates a new CRL context.
  4110. type
  4111. PFN_CERT_STORE_PROV_READ_CRL = function(hStoreProv: HCERTSTOREPROV;
  4112. pStoreCrlContext: PCCRL_CONTEXT;
  4113. dwFlags: DWORD;
  4114. var ppProvCrlContext: PCCRL_CONTEXT
  4115. ): BOOL; stdcall;
  4116. // Called by CertAddEncodedCRLToStore,
  4117. // CertAddCRLContextToStore or CertAddSerializedElementToStore before
  4118. // adding to the store. The CERT_STORE_PROV_WRITE_ADD_FLAG is set. In
  4119. // addition to the encoded CRL, the added pCertContext might also
  4120. // have properties.
  4121. //
  4122. // Returns TRUE if its OK to update the the store.
  4123. type
  4124. PFN_CERT_STORE_PROV_WRITE_CRL = function(hStoreProv: HCERTSTOREPROV;
  4125. pCrlContext: PCCRL_CONTEXT;
  4126. dwFlags: DWORD): BOOL; stdcall;
  4127. // Called by CertDeleteCRLFromStore before deleting from the store.
  4128. //
  4129. // Returns TRUE if its OK to delete from the store.
  4130. type
  4131. PFN_CERT_STORE_PROV_DELETE_CRL = function(hStoreProv: HCERTSTOREPROV;
  4132. pCrlContext: PCCRL_CONTEXT;
  4133. dwFlags: DWORD): BOOL; stdcall;
  4134. // Called by CertDeleteCRLFromStore before deleting from the store.
  4135. //
  4136. // Returns TRUE if its OK to delete from the store.
  4137. type
  4138. PFN_CERT_STORE_PROV_SET_CRL_PROPERTY = function(hStoreProv: HCERTSTOREPROV;
  4139. pCrlContext: PCCRL_CONTEXT;
  4140. dwPropId: DWORD;
  4141. dwFlags: DWORD;
  4142. pvData: PVOID): BOOL; stdcall;
  4143. // Currently not called directly by the store APIs. However, may be exported
  4144. // to support other providers based on it.
  4145. //
  4146. // Reads the provider's copy of the CTL context. If it exists,
  4147. // creates a new CTL context.
  4148. type
  4149. PFN_CERT_STORE_PROV_READ_CTL = function(hStoreProv: HCERTSTOREPROV;
  4150. pStoreCtlContext: PCCTL_CONTEXT;
  4151. dwFlags: DWORD;
  4152. var ppProvCtlContext: PCCTL_CONTEXT
  4153. ): BOOL; stdcall;
  4154. // Called by CertAddEncodedCTLToStore,
  4155. // CertAddCTLContextToStore or CertAddSerializedElementToStore before
  4156. // adding to the store. The CERT_STORE_PROV_WRITE_ADD_FLAG is set. In
  4157. // addition to the encoded CTL, the added pCertContext might also
  4158. // have properties.
  4159. //
  4160. // Returns TRUE if its OK to update the the store.
  4161. type
  4162. PFN_CERT_STORE_PROV_WRITE_CTL = function(hStoreProv: HCERTSTOREPROV;
  4163. pCtlContext: PCCTL_CONTEXT;
  4164. dwFlags: DWORD): BOOL; stdcall;
  4165. // Called by CertDeleteCTLFromStore before deleting from the store.
  4166. //
  4167. // Returns TRUE if its OK to delete from the store.
  4168. type
  4169. PFN_CERT_STORE_PROV_DELETE_CTL = function(hStoreProv: HCERTSTOREPROV;
  4170. pCtlContext: PCCTL_CONTEXT;
  4171. dwFlags: DWORD): BOOL; stdcall;
  4172. // Called by CertSetCTLContextProperty before setting the
  4173. // CTL's property. Also called by CertGetCTLContextProperty,
  4174. // when getting a hash property that needs to be created and then persisted
  4175. // via the set.
  4176. //
  4177. // Upon input, the property hasn't been set for the pCtlContext parameter.
  4178. //
  4179. // Returns TRUE if its OK to set the property.
  4180. type
  4181. PFN_CERT_STORE_PROV_SET_CTL_PROPERTY = function(hStoreProv: HCERTSTOREPROV;
  4182. pCtlContext: PCCTL_CONTEXT;
  4183. dwPropId: DWORD;
  4184. dwFlags: DWORD;
  4185. const pvData: PVOID
  4186. ): BOOL; stdcall;
  4187. //+-------------------------------------------------------------------------
  4188. // Duplicate a cert store handle
  4189. //--------------------------------------------------------------------------
  4190. function CertDuplicateStore(hCertStore: HCERTSTORE): HCERTSTORE; stdcall;
  4191. const CERT_STORE_SAVE_AS_STORE = 1;
  4192. const CERT_STORE_SAVE_AS_PKCS7 = 2;
  4193. const CERT_STORE_SAVE_TO_FILE = 1;
  4194. const CERT_STORE_SAVE_TO_MEMORY = 2;
  4195. const CERT_STORE_SAVE_TO_FILENAME_A = 3;
  4196. const CERT_STORE_SAVE_TO_FILENAME_W = 4;
  4197. const CERT_STORE_SAVE_TO_FILENAME = CERT_STORE_SAVE_TO_FILENAME_W;
  4198. //+-------------------------------------------------------------------------
  4199. // Save the cert store. Extended version with lots of options.
  4200. //
  4201. // According to the dwSaveAs parameter, the store can be saved as a
  4202. // serialized store (CERT_STORE_SAVE_AS_STORE) containing properties in
  4203. // addition to encoded certificates, CRLs and CTLs or the store can be saved
  4204. // as a PKCS #7 signed message (CERT_STORE_SAVE_AS_PKCS7) which doesn't
  4205. // include the properties or CTLs.
  4206. //
  4207. // Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  4208. // CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't saved into
  4209. // a serialized store.
  4210. //
  4211. // For CERT_STORE_SAVE_AS_PKCS7, the dwEncodingType specifies the message
  4212. // encoding type. The dwEncodingType parameter isn't used for
  4213. // CERT_STORE_SAVE_AS_STORE.
  4214. //
  4215. // The dwFlags parameter currently isn't used and should be set to 0.
  4216. //
  4217. // The dwSaveTo and pvSaveToPara parameters specify where to save the
  4218. // store as follows:
  4219. // CERT_STORE_SAVE_TO_FILE:
  4220. // Saves to the specified file. The file's handle is passed in
  4221. // pvSaveToPara. Given,
  4222. // HANDLE hFile; pvSaveToPara = (void *) hFile;
  4223. //
  4224. // For a successful save, the file pointer is positioned after the
  4225. // last write.
  4226. //
  4227. // CERT_STORE_SAVE_TO_MEMORY:
  4228. // Saves to the specified memory blob. The pointer to
  4229. // the memory blob is passed in pvSaveToPara. Given,
  4230. // CRYPT_DATA_BLOB SaveBlob; pvSaveToPara = (void *) &SaveBlob;
  4231. // Upon entry, the SaveBlob's pbData and cbData need to be initialized.
  4232. // Upon return, cbData is updated with the actual length.
  4233. // For a length only calculation, pbData should be set to NULL. If
  4234. // pbData is non-NULL and cbData isn't large enough, FALSE is returned
  4235. // with a last error of ERRROR_MORE_DATA.
  4236. //
  4237. // CERT_STORE_SAVE_TO_FILENAME_A:
  4238. // CERT_STORE_SAVE_TO_FILENAME_W:
  4239. // CERT_STORE_SAVE_TO_FILENAME:
  4240. // Opens the file and saves to it. The filename is passed in pvSaveToPara.
  4241. // The filename is UNICODE for the "_W" option and ASCII for the "_A"
  4242. // option. For "_W": given,
  4243. // LPCWSTR pwszFilename; pvSaveToPara = (void *) pwszFilename;
  4244. // For "_A": given,
  4245. // LPCSTR pszFilename; pvSaveToPara = (void *) pszFilename;
  4246. //
  4247. // Note, the default (without "_A" or "_W") is UNICODE.
  4248. //
  4249. //--------------------------------------------------------------------------
  4250. function CertSaveStore(hCertStore: HCERTSTORE;
  4251. dwEncodingType: DWORD;
  4252. dwSaveAs: DWORD;
  4253. dwSaveTo: DWORD;
  4254. pvSaveToPara: PVOID;
  4255. dwFlags: DWORD): BOOL; stdcall;
  4256. //+-------------------------------------------------------------------------
  4257. // Certificate Store close flags
  4258. //--------------------------------------------------------------------------
  4259. const CERT_CLOSE_STORE_FORCE_FLAG = $00000001;
  4260. const CERT_CLOSE_STORE_CHECK_FLAG = $00000002;
  4261. //+-------------------------------------------------------------------------
  4262. // Close a cert store handle.
  4263. //
  4264. // There needs to be a corresponding close for each open and duplicate.
  4265. //
  4266. // Even on the final close, the cert store isn't freed until all of its
  4267. // certificate and CRL contexts have also been freed.
  4268. //
  4269. // On the final close, the hCryptProv passed to CertStoreOpen is
  4270. // CryptReleaseContext'ed.
  4271. //
  4272. // To force the closure of the store with all of its memory freed, set the
  4273. // CERT_STORE_CLOSE_FORCE_FLAG. This flag should be set when the caller does
  4274. // its own reference counting and wants everything to vanish.
  4275. //
  4276. // To check if all the store's certificates and CRLs have been freed and that
  4277. // this is the last CertCloseStore, set the CERT_CLOSE_STORE_CHECK_FLAG. If
  4278. // set and certs, CRLs or stores still need to be freed/closed, FALSE is
  4279. // returned with LastError set to CRYPT_E_PENDING_CLOSE. Note, for FALSE,
  4280. // the store is still closed. This is a diagnostic flag.
  4281. //
  4282. // LastError is preserved unless CERT_CLOSE_STORE_CHECK_FLAG is set and FALSE
  4283. // is returned.
  4284. //--------------------------------------------------------------------------
  4285. function CertCloseStore(hCertStore: HCERTSTORE; dwFlags: DWORD): BOOL; stdcall;
  4286. //+-------------------------------------------------------------------------
  4287. // Get the subject certificate context uniquely identified by its Issuer and
  4288. // SerialNumber from the store.
  4289. //
  4290. // If the certificate isn't found, NULL is returned. Otherwise, a pointer to
  4291. // a read only CERT_CONTEXT is returned. CERT_CONTEXT must be freed by calling
  4292. // CertFreeCertificateContext. CertDuplicateCertificateContext can be called to make a
  4293. // duplicate.
  4294. //
  4295. // The returned certificate might not be valid. Normally, it would be
  4296. // verified when getting its issuer certificate (CertGetIssuerCertificateFromStore).
  4297. //--------------------------------------------------------------------------
  4298. function CertGetSubjectCertificateFromStore(hCertStore: HCERTSTORE;
  4299. dwCertEncodingType: DWORD;
  4300. pCertId: PCERT_INFO // Only the Issuer and SerialNumber
  4301. ): PCCERT_CONTEXT; stdcall; // fields are used
  4302. //+-------------------------------------------------------------------------
  4303. // Enumerate the certificate contexts in the store.
  4304. //
  4305. // If a certificate isn't found, NULL is returned.
  4306. // Otherwise, a pointer to a read only CERT_CONTEXT is returned. CERT_CONTEXT
  4307. // must be freed by calling CertFreeCertificateContext or is freed when passed as the
  4308. // pPrevCertContext on a subsequent call. CertDuplicateCertificateContext
  4309. // can be called to make a duplicate.
  4310. //
  4311. // pPrevCertContext MUST BE NULL to enumerate the first
  4312. // certificate in the store. Successive certificates are enumerated by setting
  4313. // pPrevCertContext to the CERT_CONTEXT returned by a previous call.
  4314. //
  4315. // NOTE: a NON-NULL pPrevCertContext is always CertFreeCertificateContext'ed by
  4316. // this function, even for an error.
  4317. //--------------------------------------------------------------------------
  4318. function CertEnumCertificatesInStore(hCertStore: HCERTSTORE;
  4319. pPrevCertContext: PCCERT_CONTEXT
  4320. ): PCCERT_CONTEXT; stdcall;
  4321. //+-------------------------------------------------------------------------
  4322. // Find the first or next certificate context in the store.
  4323. //
  4324. // The certificate is found according to the dwFindType and its pvFindPara.
  4325. // See below for a list of the find types and its parameters.
  4326. //
  4327. // Currently dwFindFlags is only used for CERT_FIND_SUBJECT_ATTR,
  4328. // CERT_FIND_ISSUER_ATTR or CERT_FIND_CTL_USAGE. Otherwise, must be set to 0.
  4329. //
  4330. // Usage of dwCertEncodingType depends on the dwFindType.
  4331. //
  4332. // If the first or next certificate isn't found, NULL is returned.
  4333. // Otherwise, a pointer to a read only CERT_CONTEXT is returned. CERT_CONTEXT
  4334. // must be freed by calling CertFreeCertificateContext or is freed when passed as the
  4335. // pPrevCertContext on a subsequent call. CertDuplicateCertificateContext
  4336. // can be called to make a duplicate.
  4337. //
  4338. // pPrevCertContext MUST BE NULL on the first
  4339. // call to find the certificate. To find the next certificate, the
  4340. // pPrevCertContext is set to the CERT_CONTEXT returned by a previous call.
  4341. //
  4342. // NOTE: a NON-NULL pPrevCertContext is always CertFreeCertificateContext'ed by
  4343. // this function, even for an error.
  4344. //--------------------------------------------------------------------------
  4345. function CertFindCertificateInStore(hCertStore: HCERTSTORE;
  4346. dwCertEncodingType: DWORD;
  4347. dwFindFlags: DWORD;
  4348. dwFindType: DWORD;
  4349. const pvFindPara: PVOID;
  4350. pPrevCertContext: PCCERT_CONTEXT
  4351. ): PCCERT_CONTEXT; stdcall;
  4352. //+-------------------------------------------------------------------------
  4353. // Certificate comparison functions
  4354. //--------------------------------------------------------------------------
  4355. const CERT_COMPARE_SHIFT = 16;
  4356. const CERT_COMPARE_ANY = 0;
  4357. const CERT_COMPARE_SHA1_HASH = 1;
  4358. const CERT_COMPARE_NAME = 2;
  4359. const CERT_COMPARE_ATTR = 3;
  4360. const CERT_COMPARE_MD5_HASH = 4;
  4361. const CERT_COMPARE_PROPERTY = 5;
  4362. const CERT_COMPARE_PUBLIC_KEY = 6;
  4363. const CERT_COMPARE_HASH = CERT_COMPARE_SHA1_HASH;
  4364. const CERT_COMPARE_NAME_STR_A = 7;
  4365. const CERT_COMPARE_NAME_STR_W = 8;
  4366. const CERT_COMPARE_KEY_SPEC = 9;
  4367. const CERT_COMPARE_ENHKEY_USAGE = 10;
  4368. const CERT_COMPARE_CTL_USAGE = CERT_COMPARE_ENHKEY_USAGE;
  4369. //+-------------------------------------------------------------------------
  4370. // dwFindType
  4371. //
  4372. // The dwFindType definition consists of two components:
  4373. // - comparison function
  4374. // - certificate information flag
  4375. //--------------------------------------------------------------------------
  4376. const CERT_FIND_ANY = (CERT_COMPARE_ANY shl CERT_COMPARE_SHIFT);
  4377. const CERT_FIND_SHA1_HASH = (CERT_COMPARE_SHA1_HASH shl CERT_COMPARE_SHIFT);
  4378. const CERT_FIND_MD5_HASH = (CERT_COMPARE_MD5_HASH shl CERT_COMPARE_SHIFT);
  4379. const CERT_FIND_HASH = CERT_FIND_SHA1_HASH;
  4380. const CERT_FIND_PROPERTY = (CERT_COMPARE_PROPERTY shl CERT_COMPARE_SHIFT);
  4381. const CERT_FIND_PUBLIC_KEY = (CERT_COMPARE_PUBLIC_KEY shl CERT_COMPARE_SHIFT);
  4382. const CERT_FIND_SUBJECT_NAME = (CERT_COMPARE_NAME shl CERT_COMPARE_SHIFT or CERT_INFO_SUBJECT_FLAG);
  4383. const CERT_FIND_SUBJECT_ATTR = (CERT_COMPARE_ATTR shl CERT_COMPARE_SHIFT or CERT_INFO_SUBJECT_FLAG);
  4384. const CERT_FIND_ISSUER_NAME = (CERT_COMPARE_NAME shl CERT_COMPARE_SHIFT or CERT_INFO_ISSUER_FLAG);
  4385. const CERT_FIND_ISSUER_ATTR = (CERT_COMPARE_ATTR shl CERT_COMPARE_SHIFT or CERT_INFO_ISSUER_FLAG);
  4386. const CERT_FIND_SUBJECT_STR_A = (CERT_COMPARE_NAME_STR_A shl CERT_COMPARE_SHIFT or CERT_INFO_SUBJECT_FLAG);
  4387. const CERT_FIND_SUBJECT_STR_W = (CERT_COMPARE_NAME_STR_W shl CERT_COMPARE_SHIFT or CERT_INFO_SUBJECT_FLAG);
  4388. const CERT_FIND_SUBJECT_STR = CERT_FIND_SUBJECT_STR_W;
  4389. const CERT_FIND_ISSUER_STR_A = (CERT_COMPARE_NAME_STR_A shl CERT_COMPARE_SHIFT or CERT_INFO_ISSUER_FLAG);
  4390. const CERT_FIND_ISSUER_STR_W = (CERT_COMPARE_NAME_STR_W shl CERT_COMPARE_SHIFT or CERT_INFO_ISSUER_FLAG);
  4391. const CERT_FIND_ISSUER_STR = CERT_FIND_ISSUER_STR_W;
  4392. const CERT_FIND_KEY_SPEC = (CERT_COMPARE_KEY_SPEC shl CERT_COMPARE_SHIFT);
  4393. const CERT_FIND_ENHKEY_USAGE = (CERT_COMPARE_ENHKEY_USAGE shl CERT_COMPARE_SHIFT);
  4394. const CERT_FIND_CTL_USAGE = CERT_FIND_ENHKEY_USAGE;
  4395. //+-------------------------------------------------------------------------
  4396. // CERT_FIND_ANY
  4397. //
  4398. // Find any certificate.
  4399. //
  4400. // pvFindPara isn't used.
  4401. //--------------------------------------------------------------------------
  4402. //+-------------------------------------------------------------------------
  4403. // CERT_FIND_HASH
  4404. //
  4405. // Find a certificate with the specified hash.
  4406. //
  4407. // pvFindPara points to a CRYPT_HASH_BLOB.
  4408. //--------------------------------------------------------------------------
  4409. //+-------------------------------------------------------------------------
  4410. // CERT_FIND_PROPERTY
  4411. //
  4412. // Find a certificate having the specified property.
  4413. //
  4414. // pvFindPara points to a DWORD containing the PROP_ID
  4415. //--------------------------------------------------------------------------
  4416. //+-------------------------------------------------------------------------
  4417. // CERT_FIND_PUBLIC_KEY
  4418. //
  4419. // Find a certificate matching the specified public key.
  4420. //
  4421. // pvFindPara points to a CERT_PUBLIC_KEY_INFO containing the public key
  4422. //--------------------------------------------------------------------------
  4423. //+-------------------------------------------------------------------------
  4424. // CERT_FIND_SUBJECT_NAME
  4425. // CERT_FIND_ISSUER_NAME
  4426. //
  4427. // Find a certificate with the specified subject/issuer name. Does an exact
  4428. // match of the entire name.
  4429. //
  4430. // Restricts search to certificates matching the dwCertEncodingType.
  4431. //
  4432. // pvFindPara points to a CERT_NAME_BLOB.
  4433. //--------------------------------------------------------------------------
  4434. //+-------------------------------------------------------------------------
  4435. // CERT_FIND_SUBJECT_ATTR
  4436. // CERT_FIND_ISSUER_ATTR
  4437. //
  4438. // Find a certificate with the specified subject/issuer attributes.
  4439. //
  4440. // Compares the attributes in the subject/issuer name with the
  4441. // Relative Distinguished Name's (CERT_RDN) array of attributes specified in
  4442. // pvFindPara. The comparison iterates through the CERT_RDN attributes and looks
  4443. // for an attribute match in any of the subject/issuer's RDNs.
  4444. //
  4445. // The CERT_RDN_ATTR fields can have the following special values:
  4446. // pszObjId == NULL - ignore the attribute object identifier
  4447. // dwValueType == RDN_ANY_TYPE - ignore the value type
  4448. // Value.pbData == NULL - match any value
  4449. //
  4450. // Currently only an exact, case sensitive match is supported.
  4451. //
  4452. // CERT_UNICODE_IS_RDN_ATTRS_FLAG should be set in dwFindFlags if the RDN was
  4453. // initialized with unicode strings as for
  4454. // CryptEncodeObject(X509_UNICODE_NAME).
  4455. //
  4456. // Restricts search to certificates matching the dwCertEncodingType.
  4457. //
  4458. // pvFindPara points to a CERT_RDN (defined in wincert.h).
  4459. //--------------------------------------------------------------------------
  4460. //+-------------------------------------------------------------------------
  4461. // CERT_FIND_SUBJECT_STR_A
  4462. // CERT_FIND_SUBJECT_STR_W | CERT_FIND_SUBJECT_STR
  4463. // CERT_FIND_ISSUER_STR_A
  4464. // CERT_FIND_ISSUER_STR_W | CERT_FIND_ISSUER_STR
  4465. //
  4466. // Find a certificate containing the specified subject/issuer name string.
  4467. //
  4468. // First, the certificate's subject/issuer is converted to a name string
  4469. // via CertNameToStrA/CertNameToStrW(CERT_SIMPLE_NAME_STR). Then, a
  4470. // case insensitive substring within string match is performed.
  4471. //
  4472. // Restricts search to certificates matching the dwCertEncodingType.
  4473. //
  4474. // For *_STR_A, pvFindPara points to a null terminated character string.
  4475. // For *_STR_W, pvFindPara points to a null terminated wide character string.
  4476. //--------------------------------------------------------------------------
  4477. //+-------------------------------------------------------------------------
  4478. // CERT_FIND_KEY_SPEC
  4479. //
  4480. // Find a certificate having a CERT_KEY_SPEC_PROP_ID property matching
  4481. // the specified KeySpec.
  4482. //
  4483. // pvFindPara points to a DWORD containing the KeySpec.
  4484. //--------------------------------------------------------------------------
  4485. //+-------------------------------------------------------------------------
  4486. // CERT_FIND_ENHKEY_USAGE
  4487. //
  4488. // Find a certificate having the szOID_ENHANCED_KEY_USAGE extension or
  4489. // the CERT_ENHKEY_USAGE_PROP_ID and matching the specified pszUsageIdentifers.
  4490. //
  4491. // pvFindPara points to a CERT_ENHKEY_USAGE data structure. If pvFindPara
  4492. // is NULL or CERT_ENHKEY_USAGE's cUsageIdentifier is 0, then, matches any
  4493. // certificate having enhanced key usage.
  4494. //
  4495. // The CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG can be set in dwFindFlags to
  4496. // also match a certificate without either the extension or property.
  4497. //
  4498. // If CERT_FIND_NO_ENHKEY_USAGE_FLAG is set in dwFindFlags, finds
  4499. // certificates without the key usage extension or property. Setting this
  4500. // flag takes precedence over pvFindPara being NULL.
  4501. //
  4502. // If the CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG is set, then, only does a match
  4503. // using the extension. If pvFindPara is NULL or cUsageIdentifier is set to
  4504. // 0, finds certificates having the extension. If
  4505. // CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG is set, also matches a certificate
  4506. // without the extension. If CERT_FIND_NO_ENHKEY_USAGE_FLAG is set, finds
  4507. // certificates without the extension.
  4508. //
  4509. // If the CERT_FIND_EXT_PROP_ENHKEY_USAGE_FLAG is set, then, only does a match
  4510. // using the property. If pvFindPara is NULL or cUsageIdentifier is set to
  4511. // 0, finds certificates having the property. If
  4512. // CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG is set, also matches a certificate
  4513. // without the property. If CERT_FIND_NO_ENHKEY_USAGE_FLAG is set, finds
  4514. // certificates without the property.
  4515. //--------------------------------------------------------------------------
  4516. const CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG = $1;
  4517. const CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG = $2;
  4518. const CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG = $4;
  4519. const CERT_FIND_NO_ENHKEY_USAGE_FLAG = $8;
  4520. const CERT_FIND_OPTIONAL_CTL_USAGE_FLAG = CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG;
  4521. const CERT_FIND_EXT_ONLY_CTL_USAGE_FLAG = CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG;
  4522. const CERT_FIND_PROP_ONLY_CTL_USAGE_FLAG = CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG;
  4523. const CERT_FIND_NO_CTL_USAGE_FLAG = CERT_FIND_NO_ENHKEY_USAGE_FLAG;
  4524. //+-------------------------------------------------------------------------
  4525. // Get the certificate context from the store for the first or next issuer
  4526. // of the specified subject certificate. Perform the enabled
  4527. // verification checks on the subject. (Note, the checks are on the subject
  4528. // using the returned issuer certificate.)
  4529. //
  4530. // If the first or next issuer certificate isn't found, NULL is returned.
  4531. // Otherwise, a pointer to a read only CERT_CONTEXT is returned. CERT_CONTEXT
  4532. // must be freed by calling CertFreeCertificateContext or is freed when passed as the
  4533. // pPrevIssuerContext on a subsequent call. CertDuplicateCertificateContext
  4534. // can be called to make a duplicate.
  4535. //
  4536. // For a self signed subject certificate, NULL is returned with LastError set
  4537. // to CERT_STORE_SELF_SIGNED. The enabled verification checks are still done.
  4538. //
  4539. // The pSubjectContext may have been obtained from this store, another store
  4540. // or created by the caller application. When created by the caller, the
  4541. // CertCreateCertificateContext function must have been called.
  4542. //
  4543. // An issuer may have multiple certificates. This may occur when the validity
  4544. // period is about to change. pPrevIssuerContext MUST BE NULL on the first
  4545. // call to get the issuer. To get the next certificate for the issuer, the
  4546. // pPrevIssuerContext is set to the CERT_CONTEXT returned by a previous call.
  4547. //
  4548. // NOTE: a NON-NULL pPrevIssuerContext is always CertFreeCertificateContext'ed by
  4549. // this function, even for an error.
  4550. //
  4551. // The following flags can be set in *pdwFlags to enable verification checks
  4552. // on the subject certificate context:
  4553. // CERT_STORE_SIGNATURE_FLAG - use the public key in the returned
  4554. // issuer certificate to verify the
  4555. // signature on the subject certificate.
  4556. // Note, if pSubjectContext->hCertStore ==
  4557. // hCertStore, the store provider might
  4558. // be able to eliminate a redo of
  4559. // the signature verify.
  4560. // CERT_STORE_TIME_VALIDITY_FLAG - get the current time and verify that
  4561. // its within the subject certificate's
  4562. // validity period
  4563. // CERT_STORE_REVOCATION_FLAG - check if the subject certificate is on
  4564. // the issuer's revocation list
  4565. //
  4566. // If an enabled verification check fails, then, its flag is set upon return.
  4567. // If CERT_STORE_REVOCATION_FLAG was enabled and the issuer doesn't have a
  4568. // CRL in the store, then, CERT_STORE_NO_CRL_FLAG is set in addition to
  4569. // the CERT_STORE_REVOCATION_FLAG.
  4570. //
  4571. // If CERT_STORE_SIGNATURE_FLAG or CERT_STORE_REVOCATION_FLAG is set, then,
  4572. // CERT_STORE_NO_ISSUER_FLAG is set if it doesn't have an issuer certificate
  4573. // in the store.
  4574. //
  4575. // For a verification check failure, a pointer to the issuer's CERT_CONTEXT
  4576. // is still returned and SetLastError isn't updated.
  4577. //--------------------------------------------------------------------------
  4578. function CertGetIssuerCertificateFromStore(hCertStore: HCERTSTORE;
  4579. pSubjectContext: PCCERT_CONTEXT;
  4580. pPrevIssuerContext: PCCERT_CONTEXT; //OPTIONAL
  4581. pdwFlags: PDWORD): PCCERT_CONTEXT; stdcall;
  4582. //+-------------------------------------------------------------------------
  4583. // Perform the enabled verification checks on the subject certificate
  4584. // using the issuer. Same checks and flags definitions as for the above
  4585. // CertGetIssuerCertificateFromStore.
  4586. //
  4587. // If you are only checking CERT_STORE_TIME_VALIDITY_FLAG, then, the
  4588. // issuer can be NULL.
  4589. //
  4590. // For a verification check failure, SUCCESS is still returned.
  4591. //--------------------------------------------------------------------------
  4592. function CertVerifySubjectCertificateContext(pSubject: PCCERT_CONTEXT;
  4593. pIssuer: PCCERT_CONTEXT; //OPTIONAL
  4594. pdwFlags: PDWORD): BOOL; stdcall;
  4595. //+-------------------------------------------------------------------------
  4596. // Duplicate a certificate context
  4597. //--------------------------------------------------------------------------
  4598. function CertDuplicateCertificateContext(pCertContext: PCCERT_CONTEXT): PCCERT_CONTEXT; stdcall;
  4599. //+-------------------------------------------------------------------------
  4600. // Create a certificate context from the encoded certificate. The created
  4601. // context isn't put in a store.
  4602. //
  4603. // Makes a copy of the encoded certificate in the created context.
  4604. //
  4605. // If unable to decode and create the certificate context, NULL is returned.
  4606. // Otherwise, a pointer to a read only CERT_CONTEXT is returned.
  4607. // CERT_CONTEXT must be freed by calling CertFreeCertificateContext.
  4608. // CertDuplicateCertificateContext can be called to make a duplicate.
  4609. //
  4610. // CertSetCertificateContextProperty and CertGetCertificateContextProperty can be called
  4611. // to store properties for the certificate.
  4612. //--------------------------------------------------------------------------
  4613. function CertCreateCertificateContext(dwCertEncodingType: DWORD;
  4614. pbCertEncoded: PBYTE;
  4615. cbCertEncoded: DWORD): PCCERT_CONTEXT; stdcall;
  4616. //+-------------------------------------------------------------------------
  4617. // Free a certificate context
  4618. //
  4619. // There needs to be a corresponding free for each context obtained by a
  4620. // get, find, duplicate or create.
  4621. //--------------------------------------------------------------------------
  4622. function CertFreeCertificateContext(pCertContext: PCCERT_CONTEXT): BOOL; stdcall;
  4623. //+-------------------------------------------------------------------------
  4624. // Set the property for the specified certificate context.
  4625. //
  4626. // The type definition for pvData depends on the dwPropId value. There are
  4627. // five predefined types:
  4628. // CERT_KEY_PROV_HANDLE_PROP_ID - a HCRYPTPROV for the certificate's
  4629. // private key is passed in pvData. Updates the hCryptProv field
  4630. // of the CERT_KEY_CONTEXT_PROP_ID. If the CERT_KEY_CONTEXT_PROP_ID
  4631. // doesn't exist, its created with all the other fields zeroed out. If
  4632. // CERT_STORE_NO_CRYPT_RELEASE_FLAG isn't set, HCRYPTPROV is implicitly
  4633. // released when either the property is set to NULL or on the final
  4634. // free of the CertContext.
  4635. //
  4636. // CERT_KEY_PROV_INFO_PROP_ID - a PCRYPT_KEY_PROV_INFO for the certificate's
  4637. // private key is passed in pvData.
  4638. //
  4639. // CERT_SHA1_HASH_PROP_ID -
  4640. // CERT_MD5_HASH_PROP_ID - normally, either property is implicitly
  4641. // set by doing a CertGetCertificateContextProperty. pvData points to a
  4642. // CRYPT_HASH_BLOB.
  4643. //
  4644. // CERT_KEY_CONTEXT_PROP_ID - a PCERT_KEY_CONTEXT for the certificate's
  4645. // private key is passed in pvData. The CERT_KEY_CONTEXT contains both the
  4646. // hCryptProv and dwKeySpec for the private key.
  4647. // See the CERT_KEY_PROV_HANDLE_PROP_ID for more information about
  4648. // the hCryptProv field and dwFlags settings. Note, more fields may
  4649. // be added for this property. The cbSize field value will be adjusted
  4650. // accordingly.
  4651. //
  4652. // CERT_KEY_SPEC_PROP_ID - the dwKeySpec for the private key. pvData
  4653. // points to a DWORD containing the KeySpec
  4654. //
  4655. // CERT_ENHKEY_USAGE_PROP_ID - enhanced key usage definition for the
  4656. // certificate. pvData points to a CRYPT_DATA_BLOB containing an
  4657. // ASN.1 encoded CERT_ENHKEY_USAGE (encoded via
  4658. // CryptEncodeObject(X509_ENHANCED_KEY_USAGE).
  4659. //
  4660. // CERT_NEXT_UPDATE_LOCATION_PROP_ID - location of the next update.
  4661. // Currently only applicable to CTLs. pvData points to a CRYPT_DATA_BLOB
  4662. // containing an ASN.1 encoded CERT_ALT_NAME_INFO (encoded via
  4663. // CryptEncodeObject(X509_ALTERNATE_NAME)).
  4664. //
  4665. // CERT_FRIENDLY_NAME_PROP_ID - friendly name for the cert, CRL or CTL.
  4666. // pvData points to a CRYPT_DATA_BLOB. pbData is a pointer to a NULL
  4667. // terminated unicode, wide character string.
  4668. // cbData = (wcslen((LPWSTR) pbData) + 1) * sizeof(WCHAR).
  4669. //
  4670. // For all the other PROP_IDs: an encoded PCRYPT_DATA_BLOB is passed in pvData.
  4671. //
  4672. // If the property already exists, then, the old value is deleted and silently
  4673. // replaced. Setting, pvData to NULL, deletes the property.
  4674. //--------------------------------------------------------------------------
  4675. function CertSetCertificateContextProperty(pCertContext: PCCERT_CONTEXT;
  4676. dwPropId: DWORD;
  4677. dwFlags: DWORD;
  4678. pvData: PVOID): BOOL; stdcall;
  4679. //+-------------------------------------------------------------------------
  4680. // Get the property for the specified certificate context.
  4681. //
  4682. // For CERT_KEY_PROV_HANDLE_PROP_ID, pvData points to a HCRYPTPROV.
  4683. //
  4684. // For CERT_KEY_PROV_INFO_PROP_ID, pvData points to a CRYPT_KEY_PROV_INFO structure.
  4685. // Elements pointed to by fields in the pvData structure follow the
  4686. // structure. Therefore, *pcbData may exceed the size of the structure.
  4687. //
  4688. // For CERT_KEY_CONTEXT_PROP_ID, pvData points to a CERT_KEY_CONTEXT structure.
  4689. //
  4690. // For CERT_KEY_SPEC_PROP_ID, pvData points to a DWORD containing the KeySpec.
  4691. // If the CERT_KEY_CONTEXT_PROP_ID exists, the KeySpec is obtained from there.
  4692. // Otherwise, if the CERT_KEY_PROV_INFO_PROP_ID exists, its the source
  4693. // of the KeySpec.
  4694. //
  4695. // For CERT_SHA1_HASH_PROP_ID or CERT_MD5_HASH_PROP_ID, if the hash
  4696. // doesn't already exist, then, its computed via CryptHashCertificate()
  4697. // and then set. pvData points to the computed hash. Normally, the length
  4698. // is 20 bytes for SHA and 16 for MD5.
  4699. //
  4700. // For all other PROP_IDs, pvData points to an encoded array of bytes.
  4701. //--------------------------------------------------------------------------
  4702. function CertGetCertificateContextProperty(pCertContext: PCCERT_CONTEXT;
  4703. dwPropId: DWORD;
  4704. pvData: PVOID;
  4705. pcbData: PDWORD): BOOL; stdcall;
  4706. //+-------------------------------------------------------------------------
  4707. // Enumerate the properties for the specified certificate context.
  4708. //
  4709. // To get the first property, set dwPropId to 0. The ID of the first
  4710. // property is returned. To get the next property, set dwPropId to the
  4711. // ID returned by the last call. To enumerate all the properties continue
  4712. // until 0 is returned.
  4713. //
  4714. // CertGetCertificateContextProperty is called to get the property's data.
  4715. //
  4716. // Note, since, the CERT_KEY_PROV_HANDLE_PROP_ID and CERT_KEY_SPEC_PROP_ID
  4717. // properties are stored as fields in the CERT_KEY_CONTEXT_PROP_ID
  4718. // property, they aren't enumerated individually.
  4719. //--------------------------------------------------------------------------
  4720. function CertEnumCertificateContextProperties(pCertContext: PCCERT_CONTEXT;
  4721. dwPropId: DWORD): DWORD; stdcall;
  4722. //+-------------------------------------------------------------------------
  4723. // Get the first or next CRL context from the store for the specified
  4724. // issuer certificate. Perform the enabled verification checks on the CRL.
  4725. //
  4726. // If the first or next CRL isn't found, NULL is returned.
  4727. // Otherwise, a pointer to a read only CRL_CONTEXT is returned. CRL_CONTEXT
  4728. // must be freed by calling CertFreeCRLContext. However, the free must be
  4729. // pPrevCrlContext on a subsequent call. CertDuplicateCRLContext
  4730. // can be called to make a duplicate.
  4731. //
  4732. // The pIssuerContext may have been obtained from this store, another store
  4733. // or created by the caller application. When created by the caller, the
  4734. // CertCreateCertificateContext function must have been called.
  4735. //
  4736. // If pIssuerContext == NULL, finds all the CRLs in the store.
  4737. //
  4738. // An issuer may have multiple CRLs. For example, it generates delta CRLs
  4739. // using a X.509 v3 extension. pPrevCrlContext MUST BE NULL on the first
  4740. // call to get the CRL. To get the next CRL for the issuer, the
  4741. // pPrevCrlContext is set to the CRL_CONTEXT returned by a previous call.
  4742. //
  4743. // NOTE: a NON-NULL pPrevCrlContext is always CertFreeCRLContext'ed by
  4744. // this function, even for an error.
  4745. //
  4746. // The following flags can be set in *pdwFlags to enable verification checks
  4747. // on the returned CRL:
  4748. // CERT_STORE_SIGNATURE_FLAG - use the public key in the
  4749. // issuer's certificate to verify the
  4750. // signature on the returned CRL.
  4751. // Note, if pIssuerContext->hCertStore ==
  4752. // hCertStore, the store provider might
  4753. // be able to eliminate a redo of
  4754. // the signature verify.
  4755. // CERT_STORE_TIME_VALIDITY_FLAG - get the current time and verify that
  4756. // its within the CRL's ThisUpdate and
  4757. // NextUpdate validity period.
  4758. //
  4759. // If an enabled verification check fails, then, its flag is set upon return.
  4760. //
  4761. // If pIssuerContext == NULL, then, an enabled CERT_STORE_SIGNATURE_FLAG
  4762. // always fails and the CERT_STORE_NO_ISSUER_FLAG is also set.
  4763. //
  4764. // For a verification check failure, a pointer to the first or next
  4765. // CRL_CONTEXT is still returned and SetLastError isn't updated.
  4766. //--------------------------------------------------------------------------
  4767. function CertGetCRLFromStore(hCertStore: HCERTSTORE;
  4768. pIssuerContext: PCCERT_CONTEXT; //OPTIONAL
  4769. pPrevCrlContext: PCCRL_CONTEXT;
  4770. pdwFlags: PDWORD): PCCRL_CONTEXT; stdcall;
  4771. //+-------------------------------------------------------------------------
  4772. // Duplicate a CRL context
  4773. //--------------------------------------------------------------------------
  4774. function CertDuplicateCRLContext(pCrlContext: PCCRL_CONTEXT): PCCRL_CONTEXT; stdcall;
  4775. //+-------------------------------------------------------------------------
  4776. // Create a CRL context from the encoded CRL. The created
  4777. // context isn't put in a store.
  4778. //
  4779. // Makes a copy of the encoded CRL in the created context.
  4780. //
  4781. // If unable to decode and create the CRL context, NULL is returned.
  4782. // Otherwise, a pointer to a read only CRL_CONTEXT is returned.
  4783. // CRL_CONTEXT must be freed by calling CertFreeCRLContext.
  4784. // CertDuplicateCRLContext can be called to make a duplicate.
  4785. //
  4786. // CertSetCRLContextProperty and CertGetCRLContextProperty can be called
  4787. // to store properties for the CRL.
  4788. //--------------------------------------------------------------------------
  4789. function CertCreateCRLContext(dwCertEncodingType: DWORD;
  4790. pbCrlEncoded: PBYTE;
  4791. cbCrlEncoded: DWORD): PCCRL_CONTEXT; stdcall;
  4792. //+-------------------------------------------------------------------------
  4793. // Free a CRL context
  4794. //
  4795. // There needs to be a corresponding free for each context obtained by a
  4796. // get, duplicate or create.
  4797. //--------------------------------------------------------------------------
  4798. function CertFreeCRLContext(pCrlContext: PCCRL_CONTEXT): BOOL; stdcall;
  4799. //+-------------------------------------------------------------------------
  4800. // Set the property for the specified CRL context.
  4801. //
  4802. // Same Property Ids and semantics as CertSetCertificateContextProperty.
  4803. //--------------------------------------------------------------------------
  4804. function CertSetCRLContextProperty(pCrlContext: PCCRL_CONTEXT;
  4805. dwPropId: DWORD;
  4806. dwFlags: DWORD;
  4807. const pvData: PVOID): BOOL; stdcall;
  4808. //+-------------------------------------------------------------------------
  4809. // Get the property for the specified CRL context.
  4810. //
  4811. // Same Property Ids and semantics as CertGetCertificateContextProperty.
  4812. //
  4813. // CERT_SHA1_HASH_PROP_ID or CERT_MD5_HASH_PROP_ID is the predefined
  4814. // property of most interest.
  4815. //--------------------------------------------------------------------------
  4816. function CertGetCRLContextProperty(pCrlContext: PCCRL_CONTEXT;
  4817. dwPropId: DWORD;
  4818. pvData: PVOID;
  4819. pcbData: PDWORD): BOOL; stdcall;
  4820. //+-------------------------------------------------------------------------
  4821. // Enumerate the properties for the specified CRL context.
  4822. //
  4823. // To get the first property, set dwPropId to 0. The ID of the first
  4824. // property is returned. To get the next property, set dwPropId to the
  4825. // ID returned by the last call. To enumerate all the properties continue
  4826. // until 0 is returned.
  4827. //
  4828. // CertGetCRLContextProperty is called to get the property's data.
  4829. //--------------------------------------------------------------------------
  4830. function CertEnumCRLContextProperties(pCrlContext: PCCRL_CONTEXT;
  4831. dwPropId: DWORD): DWORD; stdcall;
  4832. //+-------------------------------------------------------------------------
  4833. // Add certificate/CRL, encoded, context or element disposition values.
  4834. //--------------------------------------------------------------------------
  4835. const CERT_STORE_ADD_NEW = 1;
  4836. const CERT_STORE_ADD_USE_EXISTING = 2;
  4837. const CERT_STORE_ADD_REPLACE_EXISTING = 3;
  4838. const CERT_STORE_ADD_ALWAYS = 4;
  4839. //+-------------------------------------------------------------------------
  4840. // Add the encoded certificate to the store according to the specified
  4841. // disposition action.
  4842. //
  4843. // Makes a copy of the encoded certificate before adding to the store.
  4844. //
  4845. // dwAddDispostion specifies the action to take if the certificate
  4846. // already exists in the store. This parameter must be one of the following
  4847. // values:
  4848. // CERT_STORE_ADD_NEW
  4849. // Fails if the certificate already exists in the store. LastError
  4850. // is set to CRYPT_E_EXISTS.
  4851. // CERT_STORE_ADD_USE_EXISTING
  4852. // If the certifcate already exists, then, its used and if ppCertContext
  4853. // is non-NULL, the existing context is duplicated.
  4854. // CERT_STORE_ADD_REPLACE_EXISTING
  4855. // If the certificate already exists, then, the existing certificate
  4856. // context is deleted before creating and adding the new context.
  4857. // CERT_STORE_ADD_ALWAYS
  4858. // No check is made to see if the certificate already exists. A
  4859. // new certificate context is always created. This may lead to
  4860. // duplicates in the store.
  4861. //
  4862. // CertGetSubjectCertificateFromStore is called to determine if the
  4863. // certificate already exists in the store.
  4864. //
  4865. // ppCertContext can be NULL, indicating the caller isn't interested
  4866. // in getting the CERT_CONTEXT of the added or existing certificate.
  4867. //--------------------------------------------------------------------------
  4868. function CertAddEncodedCertificateToStore(hCertStore: HCERTSTORE;
  4869. dwCertEncodingType: DWORD;
  4870. const pbCertEncoded: PBYTE;
  4871. cbCertEncoded: DWORD;
  4872. dwAddDisposition: DWORD;
  4873. var ppCertContext: PCCERT_CONTEXT): BOOL; stdcall;
  4874. //+-------------------------------------------------------------------------
  4875. // Add the certificate context to the store according to the specified
  4876. // disposition action.
  4877. //
  4878. // In addition to the encoded certificate, the context's properties are
  4879. // also copied. Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  4880. // CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't copied.
  4881. //
  4882. // Makes a copy of the certificate context before adding to the store.
  4883. //
  4884. // dwAddDispostion specifies the action to take if the certificate
  4885. // already exists in the store. This parameter must be one of the following
  4886. // values:
  4887. // CERT_STORE_ADD_NEW
  4888. // Fails if the certificate already exists in the store. LastError
  4889. // is set to CRYPT_E_EXISTS.
  4890. // CERT_STORE_ADD_USE_EXISTING
  4891. // If the certifcate already exists, then, its used and if ppStoreContext
  4892. // is non-NULL, the existing context is duplicated. Iterates
  4893. // through pCertContext's properties and only copies the properties
  4894. // that don't already exist. The SHA1 and MD5 hash properties aren't
  4895. // copied.
  4896. // CERT_STORE_ADD_REPLACE_EXISTING
  4897. // If the certificate already exists, then, the existing certificate
  4898. // context is deleted before creating and adding a new context.
  4899. // Properties are copied before doing the add.
  4900. // CERT_STORE_ADD_ALWAYS
  4901. // No check is made to see if the certificate already exists. A
  4902. // new certificate context is always created and added. This may lead to
  4903. // duplicates in the store. Properties are
  4904. // copied before doing the add.
  4905. //
  4906. // CertGetSubjectCertificateFromStore is called to determine if the
  4907. // certificate already exists in the store.
  4908. //
  4909. // ppStoreContext can be NULL, indicating the caller isn't interested
  4910. // in getting the CERT_CONTEXT of the added or existing certificate.
  4911. //--------------------------------------------------------------------------
  4912. function CertAddCertificateContextToStore(hCertStore: HCERTSTORE;
  4913. pCertContext: PCCERT_CONTEXT;
  4914. dwAddDisposition: DWORD;
  4915. var ppStoreContext: PCCERT_CONTEXT //OPTIONAL
  4916. ): BOOL; stdcall;
  4917. //+-------------------------------------------------------------------------
  4918. // Certificate Store Context Types
  4919. //--------------------------------------------------------------------------
  4920. const CERT_STORE_CERTIFICATE_CONTEXT = 1;
  4921. const CERT_STORE_CRL_CONTEXT = 2;
  4922. const CERT_STORE_CTL_CONTEXT = 3;
  4923. //+-------------------------------------------------------------------------
  4924. // Certificate Store Context Bit Flags
  4925. //--------------------------------------------------------------------------
  4926. const CERT_STORE_ALL_CONTEXT_FLAG = (not ULONG(0));
  4927. const CERT_STORE_CERTIFICATE_CONTEXT_FLAG = (1 shl CERT_STORE_CERTIFICATE_CONTEXT);
  4928. const CERT_STORE_CRL_CONTEXT_FLAG = (1 shl CERT_STORE_CRL_CONTEXT);
  4929. const CERT_STORE_CTL_CONTEXT_FLAG = (1 shl CERT_STORE_CTL_CONTEXT);
  4930. //+-------------------------------------------------------------------------
  4931. // Add the serialized certificate or CRL element to the store.
  4932. //
  4933. // The serialized element contains the encoded certificate, CRL or CTL and
  4934. // its properties, such as, CERT_KEY_PROV_INFO_PROP_ID.
  4935. //
  4936. // If hCertStore is NULL, creates a certificate, CRL or CTL context not
  4937. // residing in any store.
  4938. //
  4939. // dwAddDispostion specifies the action to take if the certificate or CRL
  4940. // already exists in the store. See CertAddCertificateContextToStore for a
  4941. // list of and actions taken.
  4942. //
  4943. // dwFlags currently isn't used and should be set to 0.
  4944. //
  4945. // dwContextTypeFlags specifies the set of allowable contexts. For example, to
  4946. // add either a certificate or CRL, set dwContextTypeFlags to:
  4947. // CERT_STORE_CERTIFICATE_CONTEXT_FLAG | CERT_STORE_CRL_CONTEXT_FLAG
  4948. //
  4949. // *pdwContextType is updated with the type of the context returned in
  4950. // *ppvContxt. pdwContextType or ppvContext can be NULL, indicating the
  4951. // caller isn't interested in getting the output. If *ppvContext is
  4952. // returned it must be freed by calling CertFreeCertificateContext or
  4953. // CertFreeCRLContext.
  4954. //--------------------------------------------------------------------------
  4955. function CertAddSerializedElementToStore(hCertStore: HCERTSTORE;
  4956. pbElement: PBYTE;
  4957. cbElement: DWORD;
  4958. dwAddDisposition: DWORD;
  4959. dwFlags: DWORD;
  4960. dwContextTypeFlags: DWORD;
  4961. pdwContextType: PDWORD;
  4962. var ppvContext: array of PVOID): BOOL; stdcall;
  4963. //+-------------------------------------------------------------------------
  4964. // Delete the specified certificate from the store.
  4965. //
  4966. // All subsequent gets or finds for the certificate will fail. However,
  4967. // memory allocated for the certificate isn't freed until all of its contexts
  4968. // have also been freed.
  4969. //
  4970. // The pCertContext is obtained from a get, enum, find or duplicate.
  4971. //
  4972. // Some store provider implementations might also delete the issuer's CRLs
  4973. // if this is the last certificate for the issuer in the store.
  4974. //
  4975. // NOTE: the pCertContext is always CertFreeCertificateContext'ed by
  4976. // this function, even for an error.
  4977. //--------------------------------------------------------------------------
  4978. function CertDeleteCertificateFromStore(pCertContext: PCCERT_CONTEXT): BOOL; stdcall;
  4979. //+-------------------------------------------------------------------------
  4980. // Add the encoded CRL to the store according to the specified
  4981. // disposition option.
  4982. //
  4983. // Makes a copy of the encoded CRL before adding to the store.
  4984. //
  4985. // dwAddDispostion specifies the action to take if the CRL
  4986. // already exists in the store. See CertAddEncodedCertificateToStore for a
  4987. // list of and actions taken.
  4988. //
  4989. // Compares the CRL's Issuer to determine if the CRL already exists in the
  4990. // store.
  4991. //
  4992. // ppCrlContext can be NULL, indicating the caller isn't interested
  4993. // in getting the CRL_CONTEXT of the added or existing CRL.
  4994. //--------------------------------------------------------------------------
  4995. function CertAddEncodedCRLToStore(hCertStore: HCERTSTORE;
  4996. dwCertEncodingType: DWORD;
  4997. pbCrlEncoded: PBYTE;
  4998. cbCrlEncoded: DWORD;
  4999. dwAddDisposition: DWORD;
  5000. var ppCrlContext: PCCRL_CONTEXT
  5001. ): BOOL; stdcall;
  5002. //+-------------------------------------------------------------------------
  5003. // Add the CRL context to the store according to the specified
  5004. // disposition option.
  5005. //
  5006. // In addition to the encoded CRL, the context's properties are
  5007. // also copied. Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  5008. // CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't copied.
  5009. //
  5010. // Makes a copy of the encoded CRL before adding to the store.
  5011. //
  5012. // dwAddDispostion specifies the action to take if the CRL
  5013. // already exists in the store. See CertAddCertificateContextToStore for a
  5014. // list of and actions taken.
  5015. //
  5016. // Compares the CRL's Issuer, ThisUpdate and NextUpdate to determine
  5017. // if the CRL already exists in the store.
  5018. //
  5019. // ppStoreContext can be NULL, indicating the caller isn't interested
  5020. // in getting the CRL_CONTEXT of the added or existing CRL.
  5021. //--------------------------------------------------------------------------
  5022. function CertAddCRLContextToStore(hCertStore: HCERTSTORE;
  5023. pCrlContext: PCCRL_CONTEXT;
  5024. dwAddDisposition: DWORD;
  5025. var ppStoreContext: PCCRL_CONTEXT
  5026. ): BOOL; stdcall;
  5027. //+-------------------------------------------------------------------------
  5028. // Delete the specified CRL from the store.
  5029. //
  5030. // All subsequent gets for the CRL will fail. However,
  5031. // memory allocated for the CRL isn't freed until all of its contexts
  5032. // have also been freed.
  5033. //
  5034. // The pCrlContext is obtained from a get or duplicate.
  5035. //
  5036. // NOTE: the pCrlContext is always CertFreeCRLContext'ed by
  5037. // this function, even for an error.
  5038. //--------------------------------------------------------------------------
  5039. function CertDeleteCRLFromStore(pCrlContext: PCCRL_CONTEXT): BOOL; stdcall;
  5040. //+-------------------------------------------------------------------------
  5041. // Serialize the certificate context's encoded certificate and its
  5042. // properties.
  5043. //--------------------------------------------------------------------------
  5044. function CertSerializeCertificateStoreElement(pCertContext: PCCERT_CONTEXT;
  5045. dwFlags: DWORD;
  5046. pbElement: PBYTE;
  5047. pcbElement: PDWORD): BOOL; stdcall;
  5048. //+-------------------------------------------------------------------------
  5049. // Serialize the CRL context's encoded CRL and its properties.
  5050. //--------------------------------------------------------------------------
  5051. function CertSerializeCRLStoreElement(pCrlContext: PCCRL_CONTEXT;
  5052. dwFlags: DWORD;
  5053. pbElement: PBYTE;
  5054. pcbElement: PDWORD): BOOL; stdcall;
  5055. //+=========================================================================
  5056. // Certificate Trust List (CTL) Store Data Structures and APIs
  5057. //==========================================================================
  5058. //+-------------------------------------------------------------------------
  5059. // Duplicate a CTL context
  5060. //--------------------------------------------------------------------------
  5061. function CertDuplicateCTLContext(pCtlContext: PCCTL_CONTEXT): PCCTL_CONTEXT; stdcall;
  5062. //+-------------------------------------------------------------------------
  5063. // Create a CTL context from the encoded CTL. The created
  5064. // context isn't put in a store.
  5065. //
  5066. // Makes a copy of the encoded CTL in the created context.
  5067. //
  5068. // If unable to decode and create the CTL context, NULL is returned.
  5069. // Otherwise, a pointer to a read only CTL_CONTEXT is returned.
  5070. // CTL_CONTEXT must be freed by calling CertFreeCTLContext.
  5071. // CertDuplicateCTLContext can be called to make a duplicate.
  5072. //
  5073. // CertSetCTLContextProperty and CertGetCTLContextProperty can be called
  5074. // to store properties for the CTL.
  5075. //--------------------------------------------------------------------------
  5076. function CertCreateCTLContext(dwMsgAndCertEncodingType: DWORD;
  5077. const pbCtlEncoded: PBYTE;
  5078. cbCtlEncoded: DWORD): PCCTL_CONTEXT; stdcall;
  5079. //+-------------------------------------------------------------------------
  5080. // Free a CTL context
  5081. //
  5082. // There needs to be a corresponding free for each context obtained by a
  5083. // get, duplicate or create.
  5084. //--------------------------------------------------------------------------
  5085. function CertFreeCTLContext(pCtlContext: PCCTL_CONTEXT): BOOL; stdcall;
  5086. //+-------------------------------------------------------------------------
  5087. // Set the property for the specified CTL context.
  5088. //
  5089. // Same Property Ids and semantics as CertSetCertificateContextProperty.
  5090. //--------------------------------------------------------------------------
  5091. function CertSetCTLContextProperty(pCtlContext: PCCTL_CONTEXT;
  5092. dwPropId: DWORD;
  5093. dwFlags: DWORD;
  5094. const pvData: PVOID): BOOL; stdcall;
  5095. //+-------------------------------------------------------------------------
  5096. // Get the property for the specified CTL context.
  5097. //
  5098. // Same Property Ids and semantics as CertGetCertificateContextProperty.
  5099. //
  5100. // CERT_SHA1_HASH_PROP_ID or CERT_NEXT_UPDATE_LOCATION_PROP_ID are the
  5101. // predefined properties of most interest.
  5102. //--------------------------------------------------------------------------
  5103. function CertGetCTLContextProperty(pCtlContext: PCCTL_CONTEXT;
  5104. dwPropId: DWORD;
  5105. pvData: PVOID;
  5106. pcbData: PDWORD): BOOL; stdcall;
  5107. //+-------------------------------------------------------------------------
  5108. // Enumerate the properties for the specified CTL context.
  5109. //--------------------------------------------------------------------------
  5110. function CertEnumCTLContextProperties(pCtlContext: PCCTL_CONTEXT;
  5111. dwPropId: DWORD): DWORD; stdcall;
  5112. //+-------------------------------------------------------------------------
  5113. // Enumerate the CTL contexts in the store.
  5114. //
  5115. // If a CTL isn't found, NULL is returned.
  5116. // Otherwise, a pointer to a read only CTL_CONTEXT is returned. CTL_CONTEXT
  5117. // must be freed by calling CertFreeCTLContext or is freed when passed as the
  5118. // pPrevCtlContext on a subsequent call. CertDuplicateCTLContext
  5119. // can be called to make a duplicate.
  5120. //
  5121. // pPrevCtlContext MUST BE NULL to enumerate the first
  5122. // CTL in the store. Successive CTLs are enumerated by setting
  5123. // pPrevCtlContext to the CTL_CONTEXT returned by a previous call.
  5124. //
  5125. // NOTE: a NON-NULL pPrevCtlContext is always CertFreeCTLContext'ed by
  5126. // this function, even for an error.
  5127. //--------------------------------------------------------------------------
  5128. function CertEnumCTLsInStore(hCertStore: HCERTSTORE;
  5129. pPrevCtlContext: PCCTL_CONTEXT
  5130. ): PCCTL_CONTEXT; stdcall;
  5131. //+-------------------------------------------------------------------------
  5132. // Attempt to find the specified subject in the CTL.
  5133. //
  5134. // For CTL_CERT_SUBJECT_TYPE, pvSubject points to a CERT_CONTEXT. The CTL's
  5135. // SubjectAlgorithm is examined to determine the representation of the
  5136. // subject's identity. Initially, only SHA1 or MD5 hash will be supported.
  5137. // The appropriate hash property is obtained from the CERT_CONTEXT.
  5138. //
  5139. // For CTL_ANY_SUBJECT_TYPE, pvSubject points to the CTL_ANY_SUBJECT_INFO
  5140. // structure which contains the SubjectAlgorithm to be matched in the CTL
  5141. // and the SubjectIdentifer to be matched in one of the CTL entries.
  5142. //
  5143. // The certificate's hash or the CTL_ANY_SUBJECT_INFO's SubjectIdentifier
  5144. // is used as the key in searching the subject entries. A binary
  5145. // memory comparison is done between the key and the entry's SubjectIdentifer.
  5146. //
  5147. // dwEncodingType isn't used for either of the above SubjectTypes.
  5148. //--------------------------------------------------------------------------
  5149. function CertFindSubjectInCTL(dwEncodingType: DWORD;
  5150. dwSubjectType: DWORD;
  5151. pvSubject: PVOID;
  5152. pCtlContext: PCCTL_CONTEXT;
  5153. dwFlags: DWORD): PCTL_ENTRY; stdcall;
  5154. // Subject Types:
  5155. // CTL_ANY_SUBJECT_TYPE, pvSubject points to following CTL_ANY_SUBJECT_INFO.
  5156. // CTL_CERT_SUBJECT_TYPE, pvSubject points to CERT_CONTEXT.
  5157. const CTL_ANY_SUBJECT_TYPE = 1;
  5158. const CTL_CERT_SUBJECT_TYPE = 2;
  5159. type
  5160. PCTL_ANY_SUBJECT_INFO = ^CTL_ANY_SUBJECT_INFO;
  5161. CTL_ANY_SUBJECT_INFO = record
  5162. SubjectAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  5163. SubjectIdentifier: CRYPT_DATA_BLOB;
  5164. end;
  5165. //+-------------------------------------------------------------------------
  5166. // Find the first or next CTL context in the store.
  5167. //
  5168. // The CTL is found according to the dwFindType and its pvFindPara.
  5169. // See below for a list of the find types and its parameters.
  5170. //
  5171. // Currently dwFindFlags isn't used and must be set to 0.
  5172. //
  5173. // Usage of dwMsgAndCertEncodingType depends on the dwFindType.
  5174. //
  5175. // If the first or next CTL isn't found, NULL is returned.
  5176. // Otherwise, a pointer to a read only CTL_CONTEXT is returned. CTL_CONTEXT
  5177. // must be freed by calling CertFreeCTLContext or is freed when passed as the
  5178. // pPrevCtlContext on a subsequent call. CertDuplicateCTLContext
  5179. // can be called to make a duplicate.
  5180. //
  5181. // pPrevCtlContext MUST BE NULL on the first
  5182. // call to find the CTL. To find the next CTL, the
  5183. // pPrevCtlContext is set to the CTL_CONTEXT returned by a previous call.
  5184. //
  5185. // NOTE: a NON-NULL pPrevCtlContext is always CertFreeCTLContext'ed by
  5186. // this function, even for an error.
  5187. //--------------------------------------------------------------------------
  5188. function CertFindCTLInStore(hCertStore: HCERTSTORE;
  5189. dwMsgAndCertEncodingType: DWORD;
  5190. dwFindFlags: DWORD;
  5191. dwFindType: DWORD;
  5192. const pvFindPara: PVOID;
  5193. pPrevCtlContext: PCCTL_CONTEXT): PCCTL_CONTEXT; stdcall;
  5194. const CTL_FIND_ANY = 0;
  5195. const CTL_FIND_SHA1_HASH = 1;
  5196. const CTL_FIND_MD5_HASH = 2;
  5197. const CTL_FIND_USAGE = 3;
  5198. const CTL_FIND_SUBJECT = 4;
  5199. type
  5200. PCTL_FIND_USAGE_PARA = ^CTL_FIND_USAGE_PARA;
  5201. CTL_FIND_USAGE_PARA = record
  5202. cbSize: DWORD;
  5203. SubjectUsage: CTL_USAGE; // optional
  5204. ListIdentifier: CRYPT_DATA_BLOB; // optional
  5205. pSigner: PCERT_INFO; // optional
  5206. end;
  5207. const CTL_FIND_NO_LIST_ID_CBDATA = $FFFFFFFF;
  5208. const CTL_FIND_NO_SIGNER_PTR = (PCERT_INFO($FFFFFFFF));
  5209. const CTL_FIND_SAME_USAGE_FLAG = $1;
  5210. type
  5211. PCTL_FIND_SUBJECT_PARA = ^CTL_FIND_SUBJECT_PARA;
  5212. CTL_FIND_SUBJECT_PARA = record
  5213. cbSize: DWORD;
  5214. pUsagePara: PCTL_FIND_USAGE_PARA; // optional
  5215. dwSubjectType: DWORD;
  5216. pvSubject: PVOID;
  5217. end;
  5218. //+-------------------------------------------------------------------------
  5219. // CTL_FIND_ANY
  5220. //
  5221. // Find any CTL.
  5222. //
  5223. // pvFindPara isn't used.
  5224. //--------------------------------------------------------------------------
  5225. //+-------------------------------------------------------------------------
  5226. // CTL_FIND_SHA1_HASH
  5227. // CTL_FIND_MD5_HASH
  5228. //
  5229. // Find a CTL with the specified hash.
  5230. //
  5231. // pvFindPara points to a CRYPT_HASH_BLOB.
  5232. //--------------------------------------------------------------------------
  5233. //+-------------------------------------------------------------------------
  5234. // CTL_FIND_USAGE
  5235. //
  5236. // Find a CTL having the specified usage identifiers, list identifier or
  5237. // signer. The CertEncodingType of the signer is obtained from the
  5238. // dwMsgAndCertEncodingType parameter.
  5239. //
  5240. // pvFindPara points to a CTL_FIND_USAGE_PARA data structure. The
  5241. // SubjectUsage.cUsageIdentifer can be 0 to match any usage. The
  5242. // ListIdentifier.cbData can be 0 to match any list identifier. To only match
  5243. // CTLs without a ListIdentifier, cbData must be set to
  5244. // CTL_FIND_NO_LIST_ID_CBDATA. pSigner can be NULL to match any signer. Only
  5245. // the Issuer and SerialNumber fields of the pSigner's PCERT_INFO are used.
  5246. // To only match CTLs without a signer, pSigner must be set to
  5247. // CTL_FIND_NO_SIGNER_PTR.
  5248. //
  5249. // The CTL_FIND_SAME_USAGE_FLAG can be set in dwFindFlags to
  5250. // only match CTLs with the same usage identifiers. CTLs having additional
  5251. // usage identifiers aren't matched. For example, if only "1.2.3" is specified
  5252. // in CTL_FIND_USAGE_PARA, then, for a match, the CTL must only contain
  5253. // "1.2.3" and not any additional usage identifers.
  5254. //--------------------------------------------------------------------------
  5255. //+-------------------------------------------------------------------------
  5256. // CTL_FIND_SUBJECT
  5257. //
  5258. // Find a CTL having the specified subject. CertFindSubjectInCTL can be
  5259. // called to get a pointer to the subject's entry in the CTL. pUsagePara can
  5260. // optionally be set to enable the above CTL_FIND_USAGE matching.
  5261. //
  5262. // pvFindPara points to a CTL_FIND_SUBJECT_PARA data structure.
  5263. //--------------------------------------------------------------------------
  5264. //+-------------------------------------------------------------------------
  5265. // Add the encoded CTL to the store according to the specified
  5266. // disposition option.
  5267. //
  5268. // Makes a copy of the encoded CTL before adding to the store.
  5269. //
  5270. // dwAddDispostion specifies the action to take if the CTL
  5271. // already exists in the store. See CertAddEncodedCertificateToStore for a
  5272. // list of and actions taken.
  5273. //
  5274. // Compares the CTL's SubjectUsage, ListIdentifier and any of its signers
  5275. // to determine if the CTL already exists in the store.
  5276. //
  5277. // ppCtlContext can be NULL, indicating the caller isn't interested
  5278. // in getting the CTL_CONTEXT of the added or existing CTL.
  5279. //--------------------------------------------------------------------------
  5280. function CertAddEncodedCTLToStore(hCertStore: HCERTSTORE;
  5281. dwMsgAndCertEncodingType: DWORD;
  5282. const pbCtlEncoded: PBYTE;
  5283. cbCtlEncoded: DWORD;
  5284. dwAddDisposition: DWORD;
  5285. var ppCtlContext: PCCTL_CONTEXT //OPTIONAL
  5286. ): BOOL; stdcall;
  5287. //+-------------------------------------------------------------------------
  5288. // Add the CTL context to the store according to the specified
  5289. // disposition option.
  5290. //
  5291. // In addition to the encoded CTL, the context's properties are
  5292. // also copied. Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  5293. // CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't copied.
  5294. //
  5295. // Makes a copy of the encoded CTL before adding to the store.
  5296. //
  5297. // dwAddDispostion specifies the action to take if the CTL
  5298. // already exists in the store. See CertAddCertificateContextToStore for a
  5299. // list of and actions taken.
  5300. //
  5301. // Compares the CTL's SubjectUsage, ListIdentifier and any of its signers
  5302. // to determine if the CTL already exists in the store.
  5303. //
  5304. // ppStoreContext can be NULL, indicating the caller isn't interested
  5305. // in getting the CTL_CONTEXT of the added or existing CTL.
  5306. //--------------------------------------------------------------------------
  5307. function CertAddCTLContextToStore(hCertStore: HCERTSTORE;
  5308. pCtlContext: PCCTL_CONTEXT;
  5309. dwAddDisposition: DWORD;
  5310. var ppStoreContext: PCCTL_CONTEXT
  5311. ): BOOL; stdcall;
  5312. //+-------------------------------------------------------------------------
  5313. // Serialize the CTL context's encoded CTL and its properties.
  5314. //--------------------------------------------------------------------------
  5315. function CertSerializeCTLStoreElement(pCtlContext: PCCTL_CONTEXT;
  5316. dwFlags: DWORD;
  5317. pbElement: PBYTE;
  5318. pcbElement: PDWORD): BOOL; stdcall;
  5319. //+-------------------------------------------------------------------------
  5320. // Delete the specified CTL from the store.
  5321. //
  5322. // All subsequent gets for the CTL will fail. However,
  5323. // memory allocated for the CTL isn't freed until all of its contexts
  5324. // have also been freed.
  5325. //
  5326. // The pCtlContext is obtained from a get or duplicate.
  5327. //
  5328. // NOTE: the pCtlContext is always CertFreeCTLContext'ed by
  5329. // this function, even for an error.
  5330. //--------------------------------------------------------------------------
  5331. function CertDeleteCTLFromStore(pCtlContext: PCCTL_CONTEXT): BOOL; stdcall;
  5332. //+=========================================================================
  5333. // Enhanced Key Usage Helper Functions
  5334. //==========================================================================
  5335. //+-------------------------------------------------------------------------
  5336. // Get the enhanced key usage extension or property from the certificate
  5337. // and decode.
  5338. //
  5339. // If the CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG is set, then, only get the
  5340. // extension.
  5341. //
  5342. // If the CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG is set, then, only get the
  5343. // property.
  5344. //--------------------------------------------------------------------------
  5345. function CertGetEnhancedKeyUsage(pCertContext: PCCERT_CONTEXT;
  5346. dwFlags: DWORD;
  5347. pUsage: PCERT_ENHKEY_USAGE;
  5348. pcbUsage: PDWORD): BOOL; stdcall;
  5349. //+-------------------------------------------------------------------------
  5350. // Set the enhanced key usage property for the certificate.
  5351. //--------------------------------------------------------------------------
  5352. function CertSetEnhancedKeyUsage(pCertContext: PCCERT_CONTEXT;
  5353. pUsage: PCERT_ENHKEY_USAGE
  5354. ): BOOL; stdcall;
  5355. //+-------------------------------------------------------------------------
  5356. // Add the usage identifier to the certificate's enhanced key usage property.
  5357. //--------------------------------------------------------------------------
  5358. function CertAddEnhancedKeyUsageIdentifier(pCertContext: PCCERT_CONTEXT;
  5359. pszUsageIdentifier: LPCSTR
  5360. ): BOOL; stdcall;
  5361. //+-------------------------------------------------------------------------
  5362. // Remove the usage identifier from the certificate's enhanced key usage
  5363. // property.
  5364. //--------------------------------------------------------------------------
  5365. function CertRemoveEnhancedKeyUsageIdentifier(pCertContext: PCCERT_CONTEXT;
  5366. pszUsageIdentifier: LPCSTR
  5367. ): BOOL; stdcall;
  5368. //+=========================================================================
  5369. // Cryptographic Message helper functions for verifying and signing a
  5370. // CTL.
  5371. //==========================================================================
  5372. //+-------------------------------------------------------------------------
  5373. // Get and verify the signer of a cryptographic message.
  5374. //
  5375. // To verify a CTL, the hCryptMsg is obtained from the CTL_CONTEXT's
  5376. // hCryptMsg field.
  5377. //
  5378. // If CMSG_TRUSTED_SIGNER_FLAG is set, then, treat the Signer stores as being
  5379. // trusted and only search them to find the certificate corresponding to the
  5380. // signer's issuer and serial number. Otherwise, the SignerStores are
  5381. // optionally provided to supplement the message's store of certificates.
  5382. // If a signer certificate is found, its public key is used to verify
  5383. // the message signature. The CMSG_SIGNER_ONLY_FLAG can be set to
  5384. // return the signer without doing the signature verify.
  5385. //
  5386. // If CMSG_USE_SIGNER_INDEX_FLAG is set, then, only get the signer specified
  5387. // by *pdwSignerIndex. Otherwise, iterate through all the signers
  5388. // until a signer verifies or no more signers.
  5389. //
  5390. // For a verified signature, *ppSigner is updated with certificate context
  5391. // of the signer and *pdwSignerIndex is updated with the index of the signer.
  5392. // ppSigner and/or pdwSignerIndex can be NULL, indicating the caller isn't
  5393. // interested in getting the CertContext and/or index of the signer.
  5394. //--------------------------------------------------------------------------
  5395. function CryptMsgGetAndVerifySigner(hCryptMsg: HCRYPTMSG;
  5396. cSignerStore: DWORD;
  5397. var rghSignerStore: HCERTSTORE;
  5398. dwFlags: DWORD;
  5399. var ppSigner: PCCERT_CONTEXT;
  5400. pdwSignerIndex: PDWORD): BOOL; stdcall;
  5401. const CMSG_TRUSTED_SIGNER_FLAG = $1;
  5402. const CMSG_SIGNER_ONLY_FLAG = $2;
  5403. const CMSG_USE_SIGNER_INDEX_FLAG = $4;
  5404. //+-------------------------------------------------------------------------
  5405. // Sign an encoded CTL.
  5406. //
  5407. // The pbCtlContent can be obtained via a CTL_CONTEXT's pbCtlContent
  5408. // field or via a CryptEncodeObject(PKCS_CTL).
  5409. //--------------------------------------------------------------------------
  5410. function CryptMsgSignCTL(dwMsgEncodingType: DWORD;
  5411. pbCtlContent: PBYTE;
  5412. cbCtlContent: DWORD;
  5413. pSignInfo: PCMSG_SIGNED_ENCODE_INFO;
  5414. dwFlags: DWORD;
  5415. pbEncoded: PBYTE;
  5416. pcbEncoded: PDWORD): BOOL; stdcall;
  5417. //+-------------------------------------------------------------------------
  5418. // Encode the CTL and create a signed message containing the encoded CTL.
  5419. //--------------------------------------------------------------------------
  5420. function CryptMsgEncodeAndSignCTL(dwMsgEncodingType: DWORD;
  5421. pCtlInfo: PCTL_INFO;
  5422. pSignInfo: PCMSG_SIGNED_ENCODE_INFO;
  5423. dwFlags: DWORD;
  5424. pbEncoded: PBYTE;
  5425. pcbEncoded: PDWORD): BOOL; stdcall;
  5426. //+=========================================================================
  5427. // Certificate Verify CTL Usage Data Structures and APIs
  5428. //==========================================================================
  5429. type
  5430. PHCERTSTORE = ^HCERTSTORE;
  5431. type
  5432. PCTL_VERIFY_USAGE_PARA = ^CTL_VERIFY_USAGE_PARA;
  5433. CTL_VERIFY_USAGE_PARA = record
  5434. cbSize: DWORD;
  5435. ListIdentifier: CRYPT_DATA_BLOB; // OPTIONAL
  5436. cCtlStore: DWORD;
  5437. rghCtlStore: PHCERTSTORE; // OPTIONAL
  5438. cSignerStore: DWORD;
  5439. rghSignerStore: PHCERTSTORE; // OPTIONAL
  5440. end;
  5441. type
  5442. PCTL_VERIFY_USAGE_STATUS = ^CTL_VERIFY_USAGE_STATUS;
  5443. CTL_VERIFY_USAGE_STATUS = record
  5444. cbSize: DWORD;
  5445. dwError: DWORD;
  5446. dwFlags: DWORD;
  5447. ppCtl: PPCCTL_CONTEXT; // IN OUT OPTIONAL
  5448. dwCtlEntryIndex: DWORD;
  5449. ppSigner: PPCCERT_CONTEXT; // IN OUT OPTIONAL
  5450. dwSignerIndex: DWORD;
  5451. end;
  5452. const CERT_VERIFY_INHIBIT_CTL_UPDATE_FLAG = $1;
  5453. const CERT_VERIFY_TRUSTED_SIGNERS_FLAG = $2;
  5454. const CERT_VERIFY_NO_TIME_CHECK_FLAG = $4;
  5455. const CERT_VERIFY_ALLOW_MORE_USAGE_FLAG = $8;
  5456. const CERT_VERIFY_UPDATED_CTL_FLAG = $1;
  5457. //+-------------------------------------------------------------------------
  5458. // Verify that a subject is trusted for the specified usage by finding a
  5459. // signed and time valid CTL with the usage identifiers and containing the
  5460. // the subject. A subject can be identified by either its certificate context
  5461. // or any identifier such as its SHA1 hash.
  5462. //
  5463. // See CertFindSubjectInCTL for definition of dwSubjectType and pvSubject
  5464. // parameters.
  5465. //
  5466. // Via pVerifyUsagePara, the caller can specify the stores to be searched
  5467. // to find the CTL. The caller can also specify the stores containing
  5468. // acceptable CTL signers. By setting the ListIdentifier, the caller
  5469. // can also restrict to a particular signer CTL list.
  5470. //
  5471. // Via pVerifyUsageStatus, the CTL containing the subject, the subject's
  5472. // index into the CTL's array of entries, and the signer of the CTL
  5473. // are returned. If the caller is not interested, ppCtl and ppSigner can be set
  5474. // to NULL. Returned contexts must be freed via the store's free context APIs.
  5475. //
  5476. // If the CERT_VERIFY_INHIBIT_CTL_UPDATE_FLAG isn't set, then, a time
  5477. // invalid CTL in one of the CtlStores may be replaced. When replaced, the
  5478. // CERT_VERIFY_UPDATED_CTL_FLAG is set in pVerifyUsageStatus->dwFlags.
  5479. //
  5480. // If the CERT_VERIFY_TRUSTED_SIGNERS_FLAG is set, then, only the
  5481. // SignerStores specified in pVerifyUsageStatus are searched to find
  5482. // the signer. Otherwise, the SignerStores provide additional sources
  5483. // to find the signer's certificate.
  5484. //
  5485. // If CERT_VERIFY_NO_TIME_CHECK_FLAG is set, then, the CTLs aren't checked
  5486. // for time validity.
  5487. //
  5488. // If CERT_VERIFY_ALLOW_MORE_USAGE_FLAG is set, then, the CTL may contain
  5489. // additional usage identifiers than specified by pSubjectUsage. Otherwise,
  5490. // the found CTL will contain the same usage identifers and no more.
  5491. //
  5492. // CertVerifyCTLUsage will be implemented as a dispatcher to OID installable
  5493. // functions. First, it will try to find an OID function matching the first
  5494. // usage object identifier in the pUsage sequence. Next, it will dispatch
  5495. // to the default CertDllVerifyCTLUsage functions.
  5496. //
  5497. // If the subject is trusted for the specified usage, then, TRUE is
  5498. // returned. Otherwise, FALSE is returned with dwError set to one of the
  5499. // following:
  5500. // CRYPT_E_NO_VERIFY_USAGE_DLL
  5501. // CRYPT_E_NO_VERIFY_USAGE_CHECK
  5502. // CRYPT_E_VERIFY_USAGE_OFFLINE
  5503. // CRYPT_E_NOT_IN_CTL
  5504. // CRYPT_E_NO_TRUSTED_SIGNER
  5505. //--------------------------------------------------------------------------
  5506. function CertVerifyCTLUsage(dwEncodingType: DWORD;
  5507. dwSubjectType: DWORD;
  5508. pvSubject: PVOID;
  5509. pSubjectUsage: PCTL_USAGE;
  5510. dwFlags: DWORD;
  5511. pVerifyUsagePara: PCTL_VERIFY_USAGE_PARA;
  5512. pVerifyUsageStatus: PCTL_VERIFY_USAGE_STATUS
  5513. ): BOOL; stdcall;
  5514. //+=========================================================================
  5515. // Certificate Revocation Data Structures and APIs
  5516. //==========================================================================
  5517. //+-------------------------------------------------------------------------
  5518. // The following data structure may be passed to CertVerifyRevocation to
  5519. // assist in finding the issuer of the context to be verified.
  5520. //
  5521. // When pIssuerCert is specified, pIssuerCert is the issuer of
  5522. // rgpvContext[cContext - 1].
  5523. //
  5524. // When cCertStore and rgCertStore are specified, these stores may contain
  5525. // an issuer certificate.
  5526. //--------------------------------------------------------------------------
  5527. type
  5528. PCERT_REVOCATION_PARA = ^CERT_REVOCATION_PARA;
  5529. CERT_REVOCATION_PARA = record
  5530. cbSize: DWORD;
  5531. pIssuerCert: PCCERT_CONTEXT;
  5532. cCertStore: DWORD;
  5533. rgCertStore: PHCERTSTORE;
  5534. end;
  5535. //+-------------------------------------------------------------------------
  5536. // The following data structure is returned by CertVerifyRevocation to
  5537. // specify the status of the revoked or unchecked context. Review the
  5538. // following CertVerifyRevocation comments for details.
  5539. //
  5540. // Upon input to CertVerifyRevocation, cbSize must be set to a size
  5541. // >= sizeof(CERT_REVOCATION_STATUS). Otherwise, CertVerifyRevocation
  5542. // returns FALSE and sets LastError to E_INVALIDARG.
  5543. //
  5544. // Upon input to the installed or registered CRYPT_OID_VERIFY_REVOCATION_FUNC
  5545. // functions, the dwIndex, dwError and dwReason have been zero'ed.
  5546. //--------------------------------------------------------------------------
  5547. type
  5548. PCERT_REVOCATION_STATUS = ^CERT_REVOCATION_STATUS;
  5549. CERT_REVOCATION_STATUS = record
  5550. cbSize: DWORD;
  5551. dwIndex: DWORD;
  5552. dwError: DWORD;
  5553. dwReason: DWORD;
  5554. end;
  5555. //+-------------------------------------------------------------------------
  5556. // Verifies the array of contexts for revocation. The dwRevType parameter
  5557. // indicates the type of the context data structure passed in rgpvContext.
  5558. // Currently only the revocation of certificates is defined.
  5559. //
  5560. // If the CERT_VERIFY_REV_CHAIN_FLAG flag is set, then, CertVerifyRevocation
  5561. // is verifying a chain of certs where, rgpvContext[i + 1] is the issuer
  5562. // of rgpvContext[i]. Otherwise, CertVerifyRevocation makes no assumptions
  5563. // about the order of the contexts.
  5564. //
  5565. // To assist in finding the issuer, the pRevPara may optionally be set. See
  5566. // the CERT_REVOCATION_PARA data structure for details.
  5567. //
  5568. // The contexts must contain enough information to allow the
  5569. // installable or registered revocation DLLs to find the revocation server. For
  5570. // certificates, this information would normally be conveyed in an
  5571. // extension such as the IETF's AuthorityInfoAccess extension.
  5572. //
  5573. // CertVerifyRevocation returns TRUE if all of the contexts were successfully
  5574. // checked and none were revoked. Otherwise, returns FALSE and updates the
  5575. // returned pRevStatus data structure as follows:
  5576. // dwIndex
  5577. // Index of the first context that was revoked or unable to
  5578. // be checked for revocation
  5579. // dwError
  5580. // Error status. LastError is also set to this error status.
  5581. // dwError can be set to one of the following error codes defined
  5582. // in winerror.h:
  5583. // ERROR_SUCCESS - good context
  5584. // CRYPT_E_REVOKED - context was revoked. dwReason contains the
  5585. // reason for revocation
  5586. // CRYPT_E_REVOCATION_OFFLINE - unable to connect to the
  5587. // revocation server
  5588. // CRYPT_E_NOT_IN_REVOCATION_DATABASE - the context to be checked
  5589. // was not found in the revocation server's database.
  5590. // CRYPT_E_NO_REVOCATION_CHECK - the called revocation function
  5591. // wasn't able to do a revocation check on the context
  5592. // CRYPT_E_NO_REVOCATION_DLL - no installed or registered Dll was
  5593. // found to verify revocation
  5594. // dwReason
  5595. // The dwReason is currently only set for CRYPT_E_REVOKED and contains
  5596. // the reason why the context was revoked. May be one of the following
  5597. // CRL reasons defined by the CRL Reason Code extension ("2.5.29.21")
  5598. // CRL_REASON_UNSPECIFIED 0
  5599. // CRL_REASON_KEY_COMPROMISE 1
  5600. // CRL_REASON_CA_COMPROMISE 2
  5601. // CRL_REASON_AFFILIATION_CHANGED 3
  5602. // CRL_REASON_SUPERSEDED 4
  5603. // CRL_REASON_CESSATION_OF_OPERATION 5
  5604. // CRL_REASON_CERTIFICATE_HOLD 6
  5605. //
  5606. // For each entry in rgpvContext, CertVerifyRevocation iterates
  5607. // through the CRYPT_OID_VERIFY_REVOCATION_FUNC
  5608. // function set's list of installed DEFAULT functions.
  5609. // CryptGetDefaultOIDFunctionAddress is called with pwszDll = NULL. If no
  5610. // installed functions are found capable of doing the revocation verification,
  5611. // CryptVerifyRevocation iterates through CRYPT_OID_VERIFY_REVOCATION_FUNC's
  5612. // list of registered DEFAULT Dlls. CryptGetDefaultOIDDllList is called to
  5613. // get the list. CryptGetDefaultOIDFunctionAddress is called to load the Dll.
  5614. //
  5615. // The called functions have the same signature as CertVerifyRevocation. A
  5616. // called function returns TRUE if it was able to successfully check all of
  5617. // the contexts and none were revoked. Otherwise, the called function returns
  5618. // FALSE and updates pRevStatus. dwIndex is set to the index of
  5619. // the first context that was found to be revoked or unable to be checked.
  5620. // dwError and LastError are updated. For CRYPT_E_REVOKED, dwReason
  5621. // is updated. Upon input to the called function, dwIndex, dwError and
  5622. // dwReason have been zero'ed. cbSize has been checked to be >=
  5623. // sizeof(CERT_REVOCATION_STATUS).
  5624. //
  5625. // If the called function returns FALSE, and dwError isn't set to
  5626. // CRYPT_E_REVOKED, then, CertVerifyRevocation either continues on to the
  5627. // next DLL in the list for a returned dwIndex of 0 or for a returned
  5628. // dwIndex > 0, restarts the process of finding a verify function by
  5629. // advancing the start of the context array to the returned dwIndex and
  5630. // decrementing the count of remaining contexts.
  5631. //--------------------------------------------------------------------------
  5632. function CertVerifyRevocation(dwEncodingType: DWORD;
  5633. dwRevType: DWORD;
  5634. cContext: DWORD;
  5635. rgpvContext: array of PVOID;
  5636. dwFlags: DWORD;
  5637. pRevPara: PCERT_REVOCATION_PARA;
  5638. pRevStatus: PCERT_REVOCATION_STATUS
  5639. ): BOOL; stdcall;
  5640. //+-------------------------------------------------------------------------
  5641. // Revocation types
  5642. //--------------------------------------------------------------------------
  5643. const CERT_CONTEXT_REVOCATION_TYPE = 1;
  5644. //+-------------------------------------------------------------------------
  5645. // When the following flag is set, rgpvContext[] consists of a chain
  5646. // of certificates, where rgpvContext[i + 1] is the issuer of rgpvContext[i].
  5647. //--------------------------------------------------------------------------
  5648. const CERT_VERIFY_REV_CHAIN_FLAG = $1;
  5649. //+-------------------------------------------------------------------------
  5650. // CERT_CONTEXT_REVOCATION_TYPE
  5651. //
  5652. // pvContext points to a const CERT_CONTEXT.
  5653. //--------------------------------------------------------------------------
  5654. //+=========================================================================
  5655. // Certificate Helper APIs
  5656. //==========================================================================
  5657. //+-------------------------------------------------------------------------
  5658. // Compare two multiple byte integer blobs to see if they are identical.
  5659. //
  5660. // Before doing the comparison, leading zero bytes are removed from a
  5661. // positive number and leading 0xFF bytes are removed from a negative
  5662. // number.
  5663. //
  5664. // The multiple byte integers are treated as Little Endian. pbData[0] is the
  5665. // least significant byte and pbData[cbData - 1] is the most significant
  5666. // byte.
  5667. //
  5668. // Returns TRUE if the integer blobs are identical after removing leading
  5669. // 0 or 0xFF bytes.
  5670. //--------------------------------------------------------------------------
  5671. function CertCompareIntegerBlob(pInt1: PCRYPT_INTEGER_BLOB;
  5672. pInt2: PCRYPT_INTEGER_BLOB
  5673. ): BOOL; stdcall;
  5674. //+-------------------------------------------------------------------------
  5675. // Compare two certificates to see if they are identical.
  5676. //
  5677. // Since a certificate is uniquely identified by its Issuer and SerialNumber,
  5678. // these are the only fields needing to be compared.
  5679. //
  5680. // Returns TRUE if the certificates are identical.
  5681. //--------------------------------------------------------------------------
  5682. function CertCompareCertificate(dwCertEncodingType: DWORD;
  5683. pCertId1: PCERT_INFO;
  5684. pCertId2: PCERT_INFO): BOOL; stdcall;
  5685. //+-------------------------------------------------------------------------
  5686. // Compare two certificate names to see if they are identical.
  5687. //
  5688. // Returns TRUE if the names are identical.
  5689. //--------------------------------------------------------------------------
  5690. function CertCompareCertificateName(dwCertEncodingType: DWORD;
  5691. pCertName1: PCERT_NAME_BLOB;
  5692. pCertName2: PCERT_NAME_BLOB): BOOL; stdcall;
  5693. //+-------------------------------------------------------------------------
  5694. // Compare the attributes in the certificate name with the specified
  5695. // Relative Distinguished Name's (CERT_RDN) array of attributes.
  5696. // The comparison iterates through the CERT_RDN attributes and looks for an
  5697. // attribute match in any of the certificate name's RDNs.
  5698. // Returns TRUE if all the attributes are found and match.
  5699. //
  5700. // The CERT_RDN_ATTR fields can have the following special values:
  5701. // pszObjId == NULL - ignore the attribute object identifier
  5702. // dwValueType == RDN_ANY_TYPE - ignore the value type
  5703. //
  5704. // Currently only an exact, case sensitive match is supported.
  5705. //
  5706. // CERT_UNICODE_IS_RDN_ATTRS_FLAG should be set if the pRDN was initialized
  5707. // with unicode strings as for CryptEncodeObject(X509_UNICODE_NAME).
  5708. //--------------------------------------------------------------------------
  5709. function CertIsRDNAttrsInCertificateName(dwCertEncodingType: DWORD;
  5710. dwFlags: DWORD;
  5711. pCertName: PCERT_NAME_BLOB;
  5712. pRDN: PCERT_RDN): BOOL; stdcall;
  5713. const CERT_UNICODE_IS_RDN_ATTRS_FLAG = $1;
  5714. //+-------------------------------------------------------------------------
  5715. // Compare two public keys to see if they are identical.
  5716. //
  5717. // Returns TRUE if the keys are identical.
  5718. //--------------------------------------------------------------------------
  5719. function CertComparePublicKeyInfo(dwCertEncodingType: DWORD;
  5720. pPublicKey1: PCERT_PUBLIC_KEY_INFO;
  5721. pPublicKey2: PCERT_PUBLIC_KEY_INFO
  5722. ): BOOL; stdcall;
  5723. //+-------------------------------------------------------------------------
  5724. // Get the public/private key's bit length.
  5725. //
  5726. // Returns 0 if unable to determine the key's length.
  5727. //--------------------------------------------------------------------------
  5728. function CertGetPublicKeyLength(dwCertEncodingType: DWORD;
  5729. pPublicKey: PCERT_PUBLIC_KEY_INFO
  5730. ): DWORD; stdcall;
  5731. //+-------------------------------------------------------------------------
  5732. // Verify the signature of a subject certificate or a CRL using the
  5733. // public key info
  5734. //
  5735. // Returns TRUE for a valid signature.
  5736. //
  5737. // hCryptProv specifies the crypto provider to use to verify the signature.
  5738. // It doesn't need to use a private key.
  5739. //--------------------------------------------------------------------------
  5740. function CryptVerifyCertificateSignature(hCryptProv: HCRYPTPROV;
  5741. dwCertEncodingType: DWORD;
  5742. const pbEncoded: PBYTE;
  5743. cbEncoded: DWORD;
  5744. pPublicKey: PCERT_PUBLIC_KEY_INFO
  5745. ): BOOL; stdcall;
  5746. //+-------------------------------------------------------------------------
  5747. // Compute the hash of the "to be signed" information in the encoded
  5748. // signed content (CERT_SIGNED_CONTENT_INFO).
  5749. //
  5750. // hCryptProv specifies the crypto provider to use to compute the hash.
  5751. // It doesn't need to use a private key.
  5752. //--------------------------------------------------------------------------
  5753. function CryptHashToBeSigned(hCryptProv: HCRYPTPROV;
  5754. dwCertEncodingType: DWORD;
  5755. const pbEncoded: PBYTE;
  5756. cbEncoded: DWORD;
  5757. pbComputedHash: PBYTE;
  5758. pcbComputedHash: PDWORD): BOOL; stdcall;
  5759. //+-------------------------------------------------------------------------
  5760. // Hash the encoded content.
  5761. //
  5762. // hCryptProv specifies the crypto provider to use to compute the hash.
  5763. // It doesn't need to use a private key.
  5764. //
  5765. // Algid specifies the CAPI hash algorithm to use. If Algid is 0, then, the
  5766. // default hash algorithm (currently SHA1) is used.
  5767. //--------------------------------------------------------------------------
  5768. function CryptHashCertificate(hCryptProv: HCRYPTPROV;
  5769. Algid: ALG_ID;
  5770. dwFlags: DWORD;
  5771. const pbEncoded: PBYTE;
  5772. cbEncoded: DWORD;
  5773. pbComputedHash: PBYTE;
  5774. pcbComputedHash: PDWORD): BOOL; stdcall;
  5775. //+-------------------------------------------------------------------------
  5776. // Sign the "to be signed" information in the encoded signed content.
  5777. //
  5778. // hCryptProv specifies the crypto provider to use to do the signature.
  5779. // It uses the specified private key.
  5780. //--------------------------------------------------------------------------
  5781. function CryptSignCertificate(hCryptProv: HCRYPTPROV;
  5782. dwKeySpec: DWORD;
  5783. dwCertEncodingType: DWORD;
  5784. const pbEncodedToBeSigned: PBYTE;
  5785. cbEncodedToBeSigned: DWORD;
  5786. pSignatureAlgorithm: PCRYPT_ALGORITHM_IDENTIFIER;
  5787. const pvHashAuxInfo: PVOID;
  5788. pbSignature: PBYTE;
  5789. pcbSignature: PDWORD): BOOL; stdcall;
  5790. //+-------------------------------------------------------------------------
  5791. // Encode the "to be signed" information. Sign the encoded "to be signed".
  5792. // Encode the "to be signed" and the signature.
  5793. //
  5794. // hCryptProv specifies the crypto provider to use to do the signature.
  5795. // It uses the specified private key.
  5796. //--------------------------------------------------------------------------
  5797. function CryptSignAndEncodeCertificate(hCryptProv: HCRYPTPROV;
  5798. dwKeySpec: DWORD;
  5799. dwCertEncodingType: DWORD;
  5800. const lpszStructType: LPCSTR; // "to be signed"
  5801. pvStructInfo: PVOID;
  5802. pSignatureAlgorithm: PCRYPT_ALGORITHM_IDENTIFIER;
  5803. const pvHashAuxInfo: PVOID;
  5804. pbEncoded: PBYTE;
  5805. pcbEncoded: PDWORD): BOOL; stdcall;
  5806. //+-------------------------------------------------------------------------
  5807. // Verify the time validity of a certificate.
  5808. //
  5809. // Returns -1 if before NotBefore, +1 if after NotAfter and otherwise 0 for
  5810. // a valid certificate
  5811. //
  5812. // If pTimeToVerify is NULL, uses the current time.
  5813. //--------------------------------------------------------------------------
  5814. function CertVerifyTimeValidity(pTimeToVerify: PFILETIME;
  5815. pCertInfo: PCERT_INFO): LONG; stdcall;
  5816. //+-------------------------------------------------------------------------
  5817. // Verify the time validity of a CRL.
  5818. //
  5819. // Returns -1 if before ThisUpdate, +1 if after NextUpdate and otherwise 0 for
  5820. // a valid CRL
  5821. //
  5822. // If pTimeToVerify is NULL, uses the current time.
  5823. //--------------------------------------------------------------------------
  5824. function CertVerifyCRLTimeValidity(pTimeToVerify: PFILETIME;
  5825. pCrlInfo: PCRL_INFO): LONG; stdcall;
  5826. //+-------------------------------------------------------------------------
  5827. // Verify that the subject's time validity nests within the issuer's time
  5828. // validity.
  5829. //
  5830. // Returns TRUE if it nests. Otherwise, returns FALSE.
  5831. //--------------------------------------------------------------------------
  5832. function CertVerifyValidityNesting(pSubjectInfo: PCERT_INFO;
  5833. pIssuerInfo: PCERT_INFO): BOOL; stdcall;
  5834. //+-------------------------------------------------------------------------
  5835. // Verify that the subject certificate isn't on its issuer CRL.
  5836. //
  5837. // Returns true if the certificate isn't on the CRL.
  5838. //--------------------------------------------------------------------------
  5839. function CertVerifyCRLRevocation(dwCertEncodingType: DWORD;
  5840. pCertId: PCERT_INFO; // Only the Issuer and SerialNumber
  5841. cCrlInfo: DWORD; // fields are used
  5842. rgpCrlInfo: array of PCRL_INFO): BOOL; stdcall;
  5843. //+-------------------------------------------------------------------------
  5844. // Convert the CAPI AlgId to the ASN.1 Object Identifier string
  5845. //
  5846. // Returns NULL if there isn't an ObjId corresponding to the AlgId.
  5847. //--------------------------------------------------------------------------
  5848. function CertAlgIdToOID(dwAlgId: DWORD): LPCSTR; stdcall;
  5849. //+-------------------------------------------------------------------------
  5850. // Convert the ASN.1 Object Identifier string to the CAPI AlgId.
  5851. //
  5852. // Returns 0 if there isn't an AlgId corresponding to the ObjId.
  5853. //--------------------------------------------------------------------------
  5854. function CertOIDToAlgId(pszObjId: LPCSTR): DWORD; stdcall;
  5855. //+-------------------------------------------------------------------------
  5856. // Find an extension identified by its Object Identifier.
  5857. //
  5858. // If found, returns pointer to the extension. Otherwise, returns NULL.
  5859. //--------------------------------------------------------------------------
  5860. function CertFindExtension(pszObjId: LPCSTR;
  5861. cExtensions: DWORD;
  5862. rgExtensions: array of CERT_EXTENSION): PCERT_EXTENSION; stdcall;
  5863. //+-------------------------------------------------------------------------
  5864. // Find the first attribute identified by its Object Identifier.
  5865. //
  5866. // If found, returns pointer to the attribute. Otherwise, returns NULL.
  5867. //--------------------------------------------------------------------------
  5868. function CertFindAttribute(pszObjId: LPCSTR;
  5869. cAttr: DWORD;
  5870. rgAttr: array of CRYPT_ATTRIBUTE): PCRYPT_ATTRIBUTE; stdcall;
  5871. //+-------------------------------------------------------------------------
  5872. // Find the first CERT_RDN attribute identified by its Object Identifier in
  5873. // the name's list of Relative Distinguished Names.
  5874. //
  5875. // If found, returns pointer to the attribute. Otherwise, returns NULL.
  5876. //--------------------------------------------------------------------------
  5877. function CertFindRDNAttr(pszObjId: LPCSTR;
  5878. pName: PCERT_NAME_INFO): PCERT_RDN_ATTR; stdcall;
  5879. //+-------------------------------------------------------------------------
  5880. // Get the intended key usage bytes from the certificate.
  5881. //
  5882. // If the certificate doesn't have any intended key usage bytes, returns FALSE
  5883. // and *pbKeyUsage is zeroed. Otherwise, returns TRUE and up through
  5884. // cbKeyUsage bytes are copied into *pbKeyUsage. Any remaining uncopied
  5885. // bytes are zeroed.
  5886. //--------------------------------------------------------------------------
  5887. function CertGetIntendedKeyUsage(dwCertEncodingType: DWORD;
  5888. pCertInfo: PCERT_INFO;
  5889. pbKeyUsage: PBYTE;
  5890. cbKeyUsage: DWORD): BOOL; stdcall;
  5891. //+-------------------------------------------------------------------------
  5892. // Export the public key info associated with the provider's corresponding
  5893. // private key.
  5894. //
  5895. // Calls CryptExportPublicKeyInfo with pszPublicKeyObjId = szOID_RSA_RSA,
  5896. // dwFlags = 0 and pvAuxInfo = NULL.
  5897. //--------------------------------------------------------------------------
  5898. function CryptExportPublicKeyInfo(hCryptProv: HCRYPTPROV;
  5899. dwKeySpec: DWORD;
  5900. dwCertEncodingType: DWORD;
  5901. pInfo: PCERT_PUBLIC_KEY_INFO;
  5902. pcbInfo: PDWORD): BOOL; stdcall;
  5903. //+-------------------------------------------------------------------------
  5904. // Export the public key info associated with the provider's corresponding
  5905. // private key.
  5906. //
  5907. // Uses the dwCertEncodingType and pszPublicKeyObjId to call the
  5908. // installable CRYPT_OID_EXPORT_PUBLIC_KEY_INFO_FUNC. The called function
  5909. // has the same signature as CryptExportPublicKeyInfoEx.
  5910. //
  5911. // If unable to find an installable OID function for the pszPublicKeyObjId,
  5912. // attempts to export as a RSA Public Key (szOID_RSA_RSA).
  5913. //
  5914. // The dwFlags and pvAuxInfo aren't used for szOID_RSA_RSA.
  5915. //--------------------------------------------------------------------------
  5916. const CRYPT_OID_EXPORT_PUBLIC_KEY_INFO_FUNC = 'CryptDllExportPublicKeyInfoEx';
  5917. function CryptExportPublicKeyInfoEx(hCryptProv: HCRYPTPROV;
  5918. dwKeySpec: DWORD;
  5919. dwCertEncodingType: DWORD;
  5920. pszPublicKeyObjId: LPSTR;
  5921. dwFlags: DWORD;
  5922. pvAuxInfo: PVOID;
  5923. pInfo: PCERT_PUBLIC_KEY_INFO;
  5924. pcbInfo: PDWORD): BOOL; stdcall;
  5925. //+-------------------------------------------------------------------------
  5926. // Convert and import the public key info into the provider and return a
  5927. // handle to the public key.
  5928. //
  5929. // Calls CryptImportPublicKeyInfoEx with aiKeyAlg = 0, dwFlags = 0 and
  5930. // pvAuxInfo = NULL.
  5931. //--------------------------------------------------------------------------
  5932. function CryptImportPublicKeyInfo(hCryptProv: HCRYPTPROV;
  5933. dwCertEncodingType: DWORD;
  5934. pInfo: PCERT_PUBLIC_KEY_INFO;
  5935. phKey: PHCRYPTKEY): BOOL; stdcall;
  5936. //+-------------------------------------------------------------------------
  5937. // Convert and import the public key info into the provider and return a
  5938. // handle to the public key.
  5939. //
  5940. // Uses the dwCertEncodingType and pInfo->Algorithm.pszObjId to call the
  5941. // installable CRYPT_OID_IMPORT_PUBLIC_KEY_INFO_FUNC. The called function
  5942. // has the same signature as CryptImportPublicKeyInfoEx.
  5943. //
  5944. // If unable to find an installable OID function for the pszObjId,
  5945. // attempts to import as a RSA Public Key (szOID_RSA_RSA).
  5946. //
  5947. // For szOID_RSA_RSA: aiKeyAlg may be set to CALG_RSA_SIGN or CALG_RSA_KEYX.
  5948. // Defaults to CALG_RSA_KEYX. The dwFlags and pvAuxInfo aren't used.
  5949. //--------------------------------------------------------------------------
  5950. const CRYPT_OID_IMPORT_PUBLIC_KEY_INFO_FUNC = 'CryptDllImportPublicKeyInfoEx';
  5951. function CryptImportPublicKeyInfoEx(hCryptProv: HCRYPTPROV;
  5952. dwCertEncodingType: DWORD;
  5953. pInfo: PCERT_PUBLIC_KEY_INFO;
  5954. aiKeyAlg: ALG_ID;
  5955. dwFlags: DWORD;
  5956. pvAuxInfo: PVOID;
  5957. phKey: PHCRYPTKEY
  5958. ): BOOL; stdcall;
  5959. //+-------------------------------------------------------------------------
  5960. // Compute the hash of the encoded public key info.
  5961. //
  5962. // The public key info is encoded and then hashed.
  5963. //--------------------------------------------------------------------------
  5964. function CryptHashPublicKeyInfo(hCryptProv: HCRYPTPROV;
  5965. Algid: ALG_ID;
  5966. dwFlags: DWORD;
  5967. dwCertEncodingType: DWORD;
  5968. pInfo: PCERT_PUBLIC_KEY_INFO;
  5969. pbComputedHash: PBYTE;
  5970. pcbComputedHash: PDWORD): BOOL; stdcall;
  5971. //+-------------------------------------------------------------------------
  5972. // Convert a Name Value to a null terminated char string
  5973. //
  5974. // Returns the number of characters converted including the terminating null
  5975. // character. If psz is NULL or csz is 0, returns the required size of the
  5976. // destination string (including the terminating null char).
  5977. //
  5978. // If psz != NULL && csz != 0, returned psz is always NULL terminated.
  5979. //
  5980. // Note: csz includes the NULL char.
  5981. //--------------------------------------------------------------------------
  5982. function CertRDNValueToStrA(dwValueType: DWORD;
  5983. pValue: PCERT_RDN_VALUE_BLOB;
  5984. psz: LPSTR; //OPTIONAL
  5985. csz: DWORD): DWORD; stdcall;
  5986. //+-------------------------------------------------------------------------
  5987. // Convert a Name Value to a null terminated char string
  5988. //
  5989. // Returns the number of characters converted including the terminating null
  5990. // character. If psz is NULL or csz is 0, returns the required size of the
  5991. // destination string (including the terminating null char).
  5992. //
  5993. // If psz != NULL && csz != 0, returned psz is always NULL terminated.
  5994. //
  5995. // Note: csz includes the NULL char.
  5996. //--------------------------------------------------------------------------
  5997. function CertRDNValueToStrW(dwValueType: DWORD;
  5998. pValue: PCERT_RDN_VALUE_BLOB;
  5999. psz: LPWSTR; //OPTIONAL
  6000. csz: DWORD): DWORD; stdcall;
  6001. function CertRDNValueToStr(dwValueType: DWORD;
  6002. pValue: PCERT_RDN_VALUE_BLOB;
  6003. psz: LPAWSTR; //OPTIONAL
  6004. csz: DWORD): DWORD; stdcall;
  6005. //+-------------------------------------------------------------------------
  6006. // Convert the certificate name blob to a null terminated char string.
  6007. //
  6008. // Follows the string representation of distinguished names specified in
  6009. // RFC 1779. (Note, added double quoting "" for embedded quotes, quote
  6010. // empty strings and don't quote strings containing consecutive spaces).
  6011. // RDN values of type CERT_RDN_ENCODED_BLOB or CERT_RDN_OCTET_STRING are
  6012. // formatted in hexadecimal (e.g. #0A56CF).
  6013. //
  6014. // The name string is formatted according to the dwStrType:
  6015. // CERT_SIMPLE_NAME_STR
  6016. // The object identifiers are discarded. CERT_RDN entries are separated
  6017. // by ", ". Multiple attributes per CERT_RDN are separated by " + ".
  6018. // For example:
  6019. // Microsoft, Joe Cool + Programmer
  6020. // CERT_OID_NAME_STR
  6021. // The object identifiers are included with a "=" separator from their
  6022. // attribute value. CERT_RDN entries are separated by ", ".
  6023. // Multiple attributes per CERT_RDN are separated by " + ". For example:
  6024. // 2.5.4.11=Microsoft, 2.5.4.3=Joe Cool + 2.5.4.12=Programmer
  6025. // CERT_X500_NAME_STR
  6026. // The object identifiers are converted to their X500 key name. Otherwise,
  6027. // same as CERT_OID_NAME_STR. If the object identifier doesn't have
  6028. // a corresponding X500 key name, then, the object identifier is used with
  6029. // a "OID." prefix. For example:
  6030. // OU=Microsoft, CN=Joe Cool + T=Programmer, OID.1.2.3.4.5.6=Unknown
  6031. //
  6032. // We quote the RDN value if it contains leading or trailing whitespace
  6033. // or one of the following characters: ",", "+", "=", """, "\n", "<", ">",
  6034. // "#" or ";". The quoting character is ". If the the RDN Value contains
  6035. // a " it is double quoted (""). For example:
  6036. // OU=" Microsoft", CN="Joe ""Cool""" + T="Programmer, Manager"
  6037. //
  6038. // CERT_NAME_STR_SEMICOLON_FLAG can be or'ed into dwStrType to replace
  6039. // the ", " separator with a "; " separator.
  6040. //
  6041. // CERT_NAME_STR_CRLF_FLAG can be or'ed into dwStrType to replace
  6042. // the ", " separator with a "\r\n" separator.
  6043. //
  6044. // CERT_NAME_STR_NO_PLUS_FLAG can be or'ed into dwStrType to replace the
  6045. // " + " separator with a single space, " ".
  6046. //
  6047. // CERT_NAME_STR_NO_QUOTING_FLAG can be or'ed into dwStrType to inhibit
  6048. // the above quoting.
  6049. //
  6050. // Returns the number of characters converted including the terminating null
  6051. // character. If psz is NULL or csz is 0, returns the required size of the
  6052. // destination string (including the terminating null char).
  6053. //
  6054. // If psz != NULL && csz != 0, returned psz is always NULL terminated.
  6055. //
  6056. // Note: csz includes the NULL char.
  6057. //--------------------------------------------------------------------------
  6058. //+-------------------------------------------------------------------------
  6059. //--------------------------------------------------------------------------
  6060. function CertNameToStrA(dwCertEncodingType: DWORD;
  6061. pName: PCERT_NAME_BLOB;
  6062. dwStrType: DWORD;
  6063. psz: LPSTR; //OPTIONAL
  6064. csz: DWORD): DWORD; stdcall;
  6065. //+-------------------------------------------------------------------------
  6066. //--------------------------------------------------------------------------
  6067. function CertNameToStrW(dwCertEncodingType: DWORD;
  6068. pName: PCERT_NAME_BLOB;
  6069. dwStrType: DWORD;
  6070. psz: LPWSTR; //OPTIONAL
  6071. csz: DWORD): DWORD; stdcall;
  6072. function CertNameToStr(dwCertEncodingType: DWORD;
  6073. pName: PCERT_NAME_BLOB;
  6074. dwStrType: DWORD;
  6075. psz: LPAWSTR; //OPTIONAL
  6076. csz: DWORD): DWORD; stdcall;
  6077. //+-------------------------------------------------------------------------
  6078. // Certificate name string types
  6079. //--------------------------------------------------------------------------
  6080. const CERT_SIMPLE_NAME_STR = 1;
  6081. const CERT_OID_NAME_STR = 2;
  6082. const CERT_X500_NAME_STR = 3;
  6083. //+-------------------------------------------------------------------------
  6084. // Certificate name string type flags OR'ed with the above types
  6085. //--------------------------------------------------------------------------
  6086. const CERT_NAME_STR_SEMICOLON_FLAG = $40000000;
  6087. const CERT_NAME_STR_NO_PLUS_FLAG = $20000000;
  6088. const CERT_NAME_STR_NO_QUOTING_FLAG = $10000000;
  6089. const CERT_NAME_STR_CRLF_FLAG = $08000000;
  6090. const CERT_NAME_STR_COMMA_FLAG = $04000000;
  6091. //+-------------------------------------------------------------------------
  6092. // Convert the null terminated X500 string to an encoded certificate name.
  6093. //
  6094. // The input string is expected to be formatted the same as the output
  6095. // from the above CertNameToStr API.
  6096. //
  6097. // The CERT_SIMPLE_NAME_STR type isn't supported. Otherwise, when dwStrType
  6098. // is set to 0, CERT_OID_NAME_STR or CERT_X500_NAME_STR, allow either a
  6099. // case insensitive X500 key (CN=), case insensitive "OID." prefixed
  6100. // object identifier (OID.1.2.3.4.5.6=) or an object identifier (1.2.3.4=).
  6101. //
  6102. // If no flags are OR'ed into dwStrType, then, allow "," or ";" as RDN
  6103. // separators and "+" as the multiple RDN value separator. Quoting is
  6104. // supported. A quote may be included in a quoted value by double quoting,
  6105. // for example (CN="Joe ""Cool"""). A value starting with a "#" is treated
  6106. // as ascii hex and converted to a CERT_RDN_OCTET_STRING. Embedded whitespace
  6107. // is skipped (1.2.3 = # AB CD 01 is the same as 1.2.3=#ABCD01).
  6108. //
  6109. // Whitespace surrounding the keys, object identifers and values is removed.
  6110. //
  6111. // CERT_NAME_STR_COMMA_FLAG can be or'ed into dwStrType to only allow the
  6112. // "," as the RDN separator.
  6113. //
  6114. // CERT_NAME_STR_SEMICOLON_FLAG can be or'ed into dwStrType to only allow the
  6115. // ";" as the RDN separator.
  6116. //
  6117. // CERT_NAME_STR_CRLF_FLAG can be or'ed into dwStrType to only allow
  6118. // "\r" or "\n" as the RDN separator.
  6119. //
  6120. // CERT_NAME_STR_NO_PLUS_FLAG can be or'ed into dwStrType to ignore "+"
  6121. // as a separator and not allow multiple values per RDN.
  6122. //
  6123. // CERT_NAME_STR_NO_QUOTING_FLAG can be or'ed into dwStrType to inhibit
  6124. // quoting.
  6125. //
  6126. // Support the following X500 Keys:
  6127. //
  6128. // Key Object Identifier RDN Value Type(s)
  6129. // --- ----------------- -----------------
  6130. // CN szOID_COMMON_NAME Printable, T61
  6131. // L szOID_LOCALITY_NAME Printable, T61
  6132. // O szOID_ORGANIZATION_NAME Printable, T61
  6133. // OU szOID_ORGANIZATIONAL_UNIT_NAME Printable, T61
  6134. // Email szOID_RSA_emailAddr Only IA5
  6135. // C szOID_COUNTRY_NAME Only Printable
  6136. // S szOID_STATE_OR_PROVINCE_NAME Printable, T61
  6137. // ST szOID_STATE_OR_PROVINCE_NAME Printable, T61
  6138. // STREET szOID_STREET_ADDRESS Printable, T61
  6139. // T szOID_TITLE Printable, T61
  6140. // Title szOID_TITLE Printable, T61
  6141. // G szOID_GIVEN_NAME Printable, T61
  6142. // GivenName szOID_GIVEN_NAME Printable, T61
  6143. // I szOID_INITIALS Printable, T61
  6144. // Initials szOID_INITIALS Printable, T61
  6145. // SN szOID_SUR_NAME Printable, T61
  6146. // DC szOID_DOMAIN_COMPONENT Only IA5
  6147. //
  6148. // The T61 types are UTF-8 encoded.
  6149. //
  6150. // Returns TRUE if successfully parsed the input string and encoded
  6151. // the name.
  6152. //
  6153. // If the input string is detected to be invalid, *ppszError is updated
  6154. // to point to the beginning of the invalid character sequence. Otherwise,
  6155. // *ppszError is set to NULL. *ppszError is updated with a non-NULL pointer
  6156. // for the following errors:
  6157. // CRYPT_E_INVALID_X500_STRING
  6158. // CRYPT_E_INVALID_NUMERIC_STRING
  6159. // CRYPT_E_INVALID_PRINTABLE_STRING
  6160. // CRYPT_E_INVALID_IA5_STRING
  6161. //
  6162. // ppszError can be set to NULL if not interested in getting a pointer
  6163. // to the invalid character sequence.
  6164. //--------------------------------------------------------------------------
  6165. //+-------------------------------------------------------------------------
  6166. //--------------------------------------------------------------------------
  6167. function CertStrToNameA(dwCertEncodingType: DWORD;
  6168. pszX500: LPCSTR;
  6169. dwStrType: DWORD;
  6170. pvReserved: PVOID;
  6171. pbEncoded: PBYTE;
  6172. pcbEncoded: PDWORD;
  6173. var ppszError: array of LPCSTR): BOOL; stdcall; {--max-- iniziato qui}
  6174. //+-------------------------------------------------------------------------
  6175. //--------------------------------------------------------------------------
  6176. function CertStrToNameW(dwCertEncodingType: DWORD;
  6177. pszX500: LPCWSTR;
  6178. dwStrType: DWORD;
  6179. pvReserved: PVOID;
  6180. pbEncoded: PBYTE;
  6181. pcbEncoded: PDWORD;
  6182. var ppszError: array of LPWSTR): BOOL; stdcall;
  6183. function CertStrToName(dwCertEncodingType: DWORD;
  6184. pszX500: LPAWSTR;
  6185. dwStrType: DWORD;
  6186. pvReserved: PVOID;
  6187. pbEncoded: PBYTE;
  6188. pcbEncoded: PDWORD;
  6189. var ppszError: array of LPAWSTR): BOOL; stdcall;
  6190. //+=========================================================================
  6191. // Simplified Cryptographic Message Data Structures and APIs
  6192. //==========================================================================
  6193. //+-------------------------------------------------------------------------
  6194. // Conventions for the *pb and *pcb output parameters:
  6195. //
  6196. // Upon entry to the function:
  6197. // if pcb is OPTIONAL && pcb == NULL, then,
  6198. // No output is returned
  6199. // else if pb == NULL && pcb != NULL, then,
  6200. // Length only determination. No length error is
  6201. // returned.
  6202. // otherwise where (pb != NULL && pcb != NULL && *pcb != 0)
  6203. // Output is returned. If *pcb isn't big enough a
  6204. // length error is returned. In all cases *pcb is updated
  6205. // with the actual length needed/returned.
  6206. //--------------------------------------------------------------------------
  6207. //+-------------------------------------------------------------------------
  6208. // Type definitions of the parameters used for doing the cryptographic
  6209. // operations.
  6210. //--------------------------------------------------------------------------
  6211. //+-------------------------------------------------------------------------
  6212. // Callback to get and verify the signer's certificate.
  6213. //
  6214. // Passed the CertId of the signer (its Issuer and SerialNumber) and a
  6215. // handle to its cryptographic signed message's cert store.
  6216. //
  6217. // For CRYPT_E_NO_SIGNER, called with pSignerId == NULL.
  6218. //
  6219. // For a valid signer certificate, returns a pointer to a read only
  6220. // CERT_CONTEXT. The returned CERT_CONTEXT is either obtained from a
  6221. // cert store or was created via CertCreateCertificateContext. For either case,
  6222. // its freed via CertFreeCertificateContext.
  6223. //
  6224. // If a valid certificate isn't found, this callback returns NULL with
  6225. // LastError set via SetLastError().
  6226. //
  6227. // The NULL implementation tries to get the Signer certificate from the
  6228. // message cert store. It doesn't verify the certificate.
  6229. //--------------------------------------------------------------------------
  6230. type
  6231. PFN_CRYPT_GET_SIGNER_CERTIFICATE = function(pvGetArg: PVOID;
  6232. dwCertEncodingType: DWORD;
  6233. pSignerId: PCERT_INFO; // Only the Issuer and SerialNumber
  6234. hMsgCertStore: HCERTSTORE // fields have been updated
  6235. ): PCCERT_CONTEXT; stdcall;
  6236. //+-------------------------------------------------------------------------
  6237. // The CRYPT_SIGN_MESSAGE_PARA are used for signing messages using the
  6238. // specified signing certificate contexts. (Note, allows multiple signers.)
  6239. //
  6240. // Either the CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_PROV_INFO_PROP_ID must
  6241. // be set for each rgpSigningCert[]. Either one specifies the private
  6242. // signature key to use.
  6243. //
  6244. // If any certificates and/or CRLs are to be included in the signed message,
  6245. // then, the MsgCert and MsgCrl parameters need to be updated. If the
  6246. // rgpSigningCerts are to be included, then, they must also be in the
  6247. // rgpMsgCert array.
  6248. //
  6249. // cbSize must be set to the sizeof(CRYPT_SIGN_MESSAGE_PARA) or else
  6250. // LastError will be updated with E_INVALIDARG.
  6251. //
  6252. // pvHashAuxInfo currently isn't used and must be set to NULL.
  6253. //
  6254. // dwFlags normally is set to 0. However, if the encoded output
  6255. // is to be a CMSG_SIGNED inner content of an outer cryptographic message,
  6256. // such as a CMSG_ENVELOPED, then, the CRYPT_MESSAGE_BARE_CONTENT_OUT_FLAG
  6257. // should be set. If not set, then it would be encoded as an inner content
  6258. // type of CMSG_DATA.
  6259. //
  6260. // dwInnerContentType is normally set to 0. It needs to be set if the
  6261. // ToBeSigned input is the encoded output of another cryptographic
  6262. // message, such as, an CMSG_ENVELOPED. When set, it's one of the cryptographic
  6263. // message types, for example, CMSG_ENVELOPED.
  6264. //
  6265. // If the inner content of a nested cryptographic message is data (CMSG_DATA
  6266. // the default), then, neither dwFlags or dwInnerContentType need to be set.
  6267. //--------------------------------------------------------------------------
  6268. type
  6269. PCRYPT_SIGN_MESSAGE_PARA = ^CRYPT_SIGN_MESSAGE_PARA;
  6270. CRYPT_SIGN_MESSAGE_PARA = record
  6271. cbSize: DWORD;
  6272. dwMsgEncodingType: DWORD;
  6273. pSigningCert: PCCERT_CONTEXT;
  6274. HashAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  6275. pvHashAuxInfo: PVOID;
  6276. cMsgCert: DWORD;
  6277. rgpMsgCert: PPCCERT_CONTEXT; // pointer to array of PCCERT_CONTEXT
  6278. cMsgCrl: DWORD;
  6279. rgpMsgCrl: PPCCRL_CONTEXT; // pointer to array of PCCERT_CO
  6280. cAuthAttr: DWORD;
  6281. rgAuthAttr: PCRYPT_ATTRIBUTE;
  6282. cUnauthAttr: DWORD;
  6283. rgUnauthAttr: PCRYPT_ATTRIBUTE;
  6284. dwFlags: DWORD;
  6285. dwInnerContentType: DWORD;
  6286. end;
  6287. const CRYPT_MESSAGE_BARE_CONTENT_OUT_FLAG = $1;
  6288. //+-------------------------------------------------------------------------
  6289. // The CRYPT_VERIFY_MESSAGE_PARA are used to verify signed messages.
  6290. //
  6291. // hCryptProv is used to do hashing and signature verification.
  6292. //
  6293. // The dwCertEncodingType specifies the encoding type of the certificates
  6294. // and/or CRLs in the message.
  6295. //
  6296. // pfnGetSignerCertificate is called to get and verify the message signer's
  6297. // certificate.
  6298. //
  6299. // cbSize must be set to the sizeof(CRYPT_VERIFY_MESSAGE_PARA) or else
  6300. // LastError will be updated with E_INVALIDARG.
  6301. //--------------------------------------------------------------------------
  6302. type
  6303. PCRYPT_VERIFY_MESSAGE_PARA = ^CRYPT_VERIFY_MESSAGE_PARA;
  6304. CRYPT_VERIFY_MESSAGE_PARA = record
  6305. cbSize: DWORD;
  6306. dwMsgAndCertEncodingType: DWORD;
  6307. hCryptProv: HCRYPTPROV;
  6308. pfnGetSignerCertificate: PFN_CRYPT_GET_SIGNER_CERTIFICATE;
  6309. pvGetArg: PVOID;
  6310. end;
  6311. //+-------------------------------------------------------------------------
  6312. // The CRYPT_ENCRYPT_MESSAGE_PARA are used for encrypting messages.
  6313. //
  6314. // hCryptProv is used to do content encryption, recipient key
  6315. // encryption, and recipient key export. Its private key
  6316. // isn't used.
  6317. //
  6318. // pvEncryptionAuxInfo currently isn't used and must be set to NULL.
  6319. //
  6320. // cbSize must be set to the sizeof(CRYPT_ENCRYPT_MESSAGE_PARA) or else
  6321. // LastError will be updated with E_INVALIDARG.
  6322. //
  6323. // dwFlags normally is set to 0. However, if the encoded output
  6324. // is to be a CMSG_ENVELOPED inner content of an outer cryptographic message,
  6325. // such as a CMSG_SIGNED, then, the CRYPT_MESSAGE_BARE_CONTENT_OUT_FLAG
  6326. // should be set. If not set, then it would be encoded as an inner content
  6327. // type of CMSG_DATA.
  6328. //
  6329. // dwInnerContentType is normally set to 0. It needs to be set if the
  6330. // ToBeEncrypted input is the encoded output of another cryptographic
  6331. // message, such as, an CMSG_SIGNED. When set, it's one of the cryptographic
  6332. // message types, for example, CMSG_SIGNED.
  6333. //
  6334. // If the inner content of a nested cryptographic message is data (CMSG_DATA
  6335. // the default), then, neither dwFlags or dwInnerContentType need to be set.
  6336. //--------------------------------------------------------------------------
  6337. type
  6338. PCRYPT_ENCRYPT_MESSAGE_PARA = ^CRYPT_ENCRYPT_MESSAGE_PARA;
  6339. CRYPT_ENCRYPT_MESSAGE_PARA = record
  6340. cbSize: DWORD;
  6341. dwMsgEncodingType: DWORD;
  6342. hCryptProv: HCRYPTPROV;
  6343. ContentEncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  6344. pvEncryptionAuxInfo: PVOID;
  6345. dwFlags: DWORD;
  6346. dwInnerContentType: DWORD;
  6347. end;
  6348. //+-------------------------------------------------------------------------
  6349. // The CRYPT_DECRYPT_MESSAGE_PARA are used for decrypting messages.
  6350. //
  6351. // The CertContext to use for decrypting a message is obtained from one
  6352. // of the specified cert stores. An encrypted message can have one or
  6353. // more recipients. The recipients are identified by their CertId (Issuer
  6354. // and SerialNumber). The cert stores are searched to find the CertContext
  6355. // corresponding to the CertId.
  6356. //
  6357. // Only CertContexts in the store with either
  6358. // the CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_PROV_INFO_PROP_ID set
  6359. // can be used. Either property specifies the private exchange key to use.
  6360. //
  6361. // cbSize must be set to the sizeof(CRYPT_DECRYPT_MESSAGE_PARA) or else
  6362. // LastError will be updated with E_INVALIDARG.
  6363. //--------------------------------------------------------------------------
  6364. type
  6365. PCRYPT_DECRYPT_MESSAGE_PARA = ^CRYPT_DECRYPT_MESSAGE_PARA;
  6366. CRYPT_DECRYPT_MESSAGE_PARA = record
  6367. cbSize: DWORD;
  6368. dwMsgAndCertEncodingType: DWORD;
  6369. cCertStore: DWORD;
  6370. rghCertStore: PHCERTSTORE;
  6371. end;
  6372. //+-------------------------------------------------------------------------
  6373. // The CRYPT_HASH_MESSAGE_PARA are used for hashing or unhashing
  6374. // messages.
  6375. //
  6376. // hCryptProv is used to compute the hash.
  6377. //
  6378. // pvHashAuxInfo currently isn't used and must be set to NULL.
  6379. //
  6380. // cbSize must be set to the sizeof(CRYPT_HASH_MESSAGE_PARA) or else
  6381. // LastError will be updated with E_INVALIDARG.
  6382. //--------------------------------------------------------------------------
  6383. type
  6384. PCRYPT_HASH_MESSAGE_PARA = ^CRYPT_HASH_MESSAGE_PARA;
  6385. CRYPT_HASH_MESSAGE_PARA = record
  6386. cbSize: DWORD;
  6387. dwMsgEncodingType: DWORD;
  6388. hCryptProv: HCRYPTPROV;
  6389. HashAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  6390. pvHashAuxInfo: PVOID;
  6391. end;
  6392. //+-------------------------------------------------------------------------
  6393. // The CRYPT_KEY_SIGN_MESSAGE_PARA are used for signing messages until a
  6394. // certificate has been created for the signature key.
  6395. //
  6396. // pvHashAuxInfo currently isn't used and must be set to NULL.
  6397. //
  6398. // If PubKeyAlgorithm isn't set, defaults to szOID_RSA_RSA.
  6399. //
  6400. // cbSize must be set to the sizeof(CRYPT_KEY_SIGN_MESSAGE_PARA) or else
  6401. // LastError will be updated with E_INVALIDARG.
  6402. //--------------------------------------------------------------------------
  6403. type
  6404. PCRYPT_KEY_SIGN_MESSAGE_PARA = ^CRYPT_KEY_SIGN_MESSAGE_PARA;
  6405. CRYPT_KEY_SIGN_MESSAGE_PARA = record
  6406. cbSize: DWORD;
  6407. dwMsgAndCertEncodingType: DWORD;
  6408. hCryptProv: HCRYPTPROV;
  6409. dwKeySpec: DWORD;
  6410. HashAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  6411. pvHashAuxInfo: PVOID;
  6412. PubKeyAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  6413. end;
  6414. //+-------------------------------------------------------------------------
  6415. // The CRYPT_KEY_VERIFY_MESSAGE_PARA are used to verify signed messages without
  6416. // a certificate for the signer.
  6417. //
  6418. // Normally used until a certificate has been created for the key.
  6419. //
  6420. // hCryptProv is used to do hashing and signature verification.
  6421. //
  6422. // cbSize must be set to the sizeof(CRYPT_KEY_VERIFY_MESSAGE_PARA) or else
  6423. // LastError will be updated with E_INVALIDARG.
  6424. //--------------------------------------------------------------------------
  6425. type
  6426. PCRYPT_KEY_VERIFY_MESSAGE_PARA = ^CRYPT_KEY_VERIFY_MESSAGE_PARA;
  6427. CRYPT_KEY_VERIFY_MESSAGE_PARA = record
  6428. cbSize: DWORD;
  6429. dwMsgEncodingType: DWORD;
  6430. hCryptProv: HCRYPTPROV;
  6431. end;
  6432. //+-------------------------------------------------------------------------
  6433. // Sign the message.
  6434. //
  6435. // If fDetachedSignature is TRUE, the "to be signed" content isn't included
  6436. // in the encoded signed blob.
  6437. //--------------------------------------------------------------------------
  6438. function CryptSignMessage(pSignPara: PCRYPT_SIGN_MESSAGE_PARA;
  6439. fDetachedSignature: BOOL;
  6440. cToBeSigned: DWORD;
  6441. const rgpbToBeSigned: array of PBYTE;
  6442. rgcbToBeSigned: array of DWORD;
  6443. pbSignedBlob: PBYTE;
  6444. pcbSignedBlob: PDWORD): BOOL; stdcall;
  6445. //+-------------------------------------------------------------------------
  6446. // Verify a signed message.
  6447. //
  6448. // If pbDecoded == NULL, then, *pcbDecoded is implicitly set to 0 on input.
  6449. // For *pcbDecoded == 0 && ppSignerCert == NULL on input, the signer isn't
  6450. // verified.
  6451. //
  6452. // A message might have more than one signer. Set dwSignerIndex to iterate
  6453. // through all the signers. dwSignerIndex == 0 selects the first signer.
  6454. //
  6455. // pVerifyPara's pfnGetSignerCertificate is called to get the signer's
  6456. // certificate.
  6457. //
  6458. // For a verified signer and message, *ppSignerCert is updated
  6459. // with the CertContext of the signer. It must be freed by calling
  6460. // CertFreeCertificateContext. Otherwise, *ppSignerCert is set to NULL.
  6461. //
  6462. // ppSignerCert can be NULL, indicating the caller isn't interested
  6463. // in getting the CertContext of the signer.
  6464. //
  6465. // pcbDecoded can be NULL, indicating the caller isn't interested in getting
  6466. // the decoded content. Furthermore, if the message doesn't contain any
  6467. // content or signers, then, pcbDecoded must be set to NULL, to allow the
  6468. // pVerifyPara->pfnGetCertificate to be called. Normally, this would be
  6469. // the case when the signed message contains only certficates and CRLs.
  6470. // If pcbDecoded is NULL and the message doesn't have the indicated signer,
  6471. // pfnGetCertificate is called with pSignerId set to NULL.
  6472. //
  6473. // If the message doesn't contain any signers || dwSignerIndex > message's
  6474. // SignerCount, then, an error is returned with LastError set to
  6475. // CRYPT_E_NO_SIGNER. Also, for CRYPT_E_NO_SIGNER, pfnGetSignerCertificate
  6476. // is still called with pSignerId set to NULL.
  6477. //
  6478. // Note, an alternative way to get the certificates and CRLs from a
  6479. // signed message is to call CryptGetMessageCertificates.
  6480. //--------------------------------------------------------------------------
  6481. function CryptVerifyMessageSignature(pVerifyPara: PCRYPT_VERIFY_MESSAGE_PARA;
  6482. dwSignerIndex: DWORD;
  6483. const pbSignedBlob: PBYTE;
  6484. cbSignedBlob: DWORD;
  6485. pbDecoded: PBYTE;
  6486. pcbDecoded: DWORD;
  6487. ppSignerCert: PCCERT_CONTEXT
  6488. ): BOOL; stdcall;
  6489. //+-------------------------------------------------------------------------
  6490. // Returns the count of signers in the signed message. For no signers, returns
  6491. // 0. For an error returns -1 with LastError updated accordingly.
  6492. //--------------------------------------------------------------------------
  6493. function CryptGetMessageSignerCount(dwMsgEncodingType: DWORD;
  6494. const pbSignedBlob: PBYTE;
  6495. cbSignedBlob: DWORD): LONG; stdcall;
  6496. //+-------------------------------------------------------------------------
  6497. // Returns the cert store containing the message's certs and CRLs.
  6498. // For an error, returns NULL with LastError updated.
  6499. //--------------------------------------------------------------------------
  6500. function CryptGetMessageCertificates(dwMsgAndCertEncodingType: DWORD;
  6501. hCryptProv: HCRYPTPROV; // passed to CertOpenStore
  6502. dwFlags: DWORD; // passed to CertOpenStore
  6503. const pbSignedBlob: PBYTE;
  6504. cbSignedBlob: DWORD): HCERTSTORE; stdcall;
  6505. //+-------------------------------------------------------------------------
  6506. // Verify a signed message containing detached signature(s).
  6507. // The "to be signed" content is passed in separately. No
  6508. // decoded output. Otherwise, identical to CryptVerifyMessageSignature.
  6509. //--------------------------------------------------------------------------
  6510. function CryptVerifyDetachedMessageSignature(pVerifyPara: PCRYPT_VERIFY_MESSAGE_PARA;
  6511. dwSignerIndex: DWORD;
  6512. const pbDetachedSignBlob: PBYTE;
  6513. cbDetachedSignBlob: DWORD;
  6514. cToBeSigned: DWORD;
  6515. const rgpbToBeSigned: array of PBYTE;
  6516. rgcbToBeSigned: array of DWORD;
  6517. ppSignerCert: PPCCERT_CONTEXT): BOOL; stdcall;
  6518. //+-------------------------------------------------------------------------
  6519. // Encrypts the message for the recipient(s).
  6520. //--------------------------------------------------------------------------
  6521. function CryptEncryptMessage(pEncryptPara: PCRYPT_ENCRYPT_MESSAGE_PARA;
  6522. cRecipientCert: DWORD;
  6523. rgpRecipientCert: array of PCCERT_CONTEXT;
  6524. const pbToBeEncrypted: PBYTE;
  6525. cbToBeEncrypted: DWORD;
  6526. pbEncryptedBlob: PBYTE;
  6527. pcbEncryptedBlob: PDWORD): BOOL; stdcall;
  6528. //+-------------------------------------------------------------------------
  6529. // Decrypts the message.
  6530. //
  6531. // If pbDecrypted == NULL, then, *pcbDecrypted is implicitly set to 0 on input.
  6532. // For *pcbDecrypted == 0 && ppXchgCert == NULL on input, the message isn't
  6533. // decrypted.
  6534. //
  6535. // For a successfully decrypted message, *ppXchgCert is updated
  6536. // with the CertContext used to decrypt. It must be freed by calling
  6537. // CertStoreFreeCert. Otherwise, *ppXchgCert is set to NULL.
  6538. //
  6539. // ppXchgCert can be NULL, indicating the caller isn't interested
  6540. // in getting the CertContext used to decrypt.
  6541. //--------------------------------------------------------------------------
  6542. function CryptDecryptMessage(pDecryptPara: PCRYPT_DECRYPT_MESSAGE_PARA;
  6543. const pbEncryptedBlob: PBYTE;
  6544. cbEncryptedBlob: DWORD;
  6545. pbDecrypted: PBYTE;
  6546. pcbDecrypted: PDWORD;
  6547. ppXchgCert: PPCCERT_CONTEXT): BOOL; stdcall;
  6548. //+-------------------------------------------------------------------------
  6549. // Sign the message and encrypt for the recipient(s). Does a CryptSignMessage
  6550. // followed with a CryptEncryptMessage.
  6551. //
  6552. // Note: this isn't the CMSG_SIGNED_AND_ENVELOPED. Its a CMSG_SIGNED
  6553. // inside of an CMSG_ENVELOPED.
  6554. //--------------------------------------------------------------------------
  6555. function CryptSignAndEncryptMessage(pSignPara: PCRYPT_SIGN_MESSAGE_PARA;
  6556. pEncryptPara: PCRYPT_ENCRYPT_MESSAGE_PARA;
  6557. cRecipientCert: DWORD;
  6558. rgpRecipientCert: array of PCCERT_CONTEXT;
  6559. const pbToBeSignedAndEncrypted: PBYTE;
  6560. cbToBeSignedAndEncrypted: DWORD;
  6561. pbSignedAndEncryptedBlob: PBYTE;
  6562. pcbSignedAndEncryptedBlob: PDWORD
  6563. ): BOOL; stdcall;
  6564. //+-------------------------------------------------------------------------
  6565. // Decrypts the message and verifies the signer. Does a CryptDecryptMessage
  6566. // followed with a CryptVerifyMessageSignature.
  6567. //
  6568. // If pbDecrypted == NULL, then, *pcbDecrypted is implicitly set to 0 on input.
  6569. // For *pcbDecrypted == 0 && ppSignerCert == NULL on input, the signer isn't
  6570. // verified.
  6571. //
  6572. // A message might have more than one signer. Set dwSignerIndex to iterate
  6573. // through all the signers. dwSignerIndex == 0 selects the first signer.
  6574. //
  6575. // The pVerifyPara's VerifySignerPolicy is called to verify the signer's
  6576. // certificate.
  6577. //
  6578. // For a successfully decrypted and verified message, *ppXchgCert and
  6579. // *ppSignerCert are updated. They must be freed by calling
  6580. // CertStoreFreeCert. Otherwise, they are set to NULL.
  6581. //
  6582. // ppXchgCert and/or ppSignerCert can be NULL, indicating the
  6583. // caller isn't interested in getting the CertContext.
  6584. //
  6585. // Note: this isn't the CMSG_SIGNED_AND_ENVELOPED. Its a CMSG_SIGNED
  6586. // inside of an CMSG_ENVELOPED.
  6587. //
  6588. // The message always needs to be decrypted to allow access to the
  6589. // signed message. Therefore, if ppXchgCert != NULL, its always updated.
  6590. //--------------------------------------------------------------------------
  6591. function CryptDecryptAndVerifyMessageSignature(pDecryptPara: PCRYPT_DECRYPT_MESSAGE_PARA;
  6592. pVerifyPara: PCRYPT_VERIFY_MESSAGE_PARA;
  6593. dwSignerIndex: DWORD;
  6594. const pbEncryptedBlob: PBYTE;
  6595. cbEncryptedBlob: DWORD;
  6596. pbDecrypted: PBYTE;
  6597. pcbDecrypted: PDWORD;
  6598. var ppXchgCert: array of PCCERT_CONTEXT;
  6599. var ppSignerCert: array of PCCERT_CONTEXT
  6600. ): BOOL; stdcall;
  6601. //+-------------------------------------------------------------------------
  6602. // Decodes a cryptographic message which may be one of the following types:
  6603. // CMSG_DATA
  6604. // CMSG_SIGNED
  6605. // CMSG_ENVELOPED
  6606. // CMSG_SIGNED_AND_ENVELOPED
  6607. // CMSG_HASHED
  6608. //
  6609. // dwMsgTypeFlags specifies the set of allowable messages. For example, to
  6610. // decode either SIGNED or ENVELOPED messages, set dwMsgTypeFlags to:
  6611. // CMSG_SIGNED_FLAG | CMSG_ENVELOPED_FLAG.
  6612. //
  6613. // dwProvInnerContentType is only applicable when processing nested
  6614. // crytographic messages. When processing an outer crytographic message
  6615. // it must be set to 0. When decoding a nested cryptographic message
  6616. // its the dwInnerContentType returned by a previous CryptDecodeMessage
  6617. // of the outer message. The InnerContentType can be any of the CMSG types,
  6618. // for example, CMSG_DATA, CMSG_SIGNED, ...
  6619. //
  6620. // The optional *pdwMsgType is updated with the type of message.
  6621. //
  6622. // The optional *pdwInnerContentType is updated with the type of the inner
  6623. // message. Unless there is cryptographic message nesting, CMSG_DATA
  6624. // is returned.
  6625. //
  6626. // For CMSG_DATA: returns decoded content.
  6627. // For CMSG_SIGNED: same as CryptVerifyMessageSignature.
  6628. // For CMSG_ENVELOPED: same as CryptDecryptMessage.
  6629. // For CMSG_SIGNED_AND_ENVELOPED: same as CryptDecryptMessage plus
  6630. // CryptVerifyMessageSignature.
  6631. // For CMSG_HASHED: verifies the hash and returns decoded content.
  6632. //--------------------------------------------------------------------------
  6633. function CryptDecodeMessage(dwMsgTypeFlags: DWORD;
  6634. pDecryptPara: PCRYPT_DECRYPT_MESSAGE_PARA;
  6635. pVerifyPara: PCRYPT_VERIFY_MESSAGE_PARA;
  6636. dwSignerIndex: DWORD;
  6637. const pbEncodedBlob: PBYTE;
  6638. cbEncodedBlob: DWORD;
  6639. dwPrevInnerContentType: DWORD;
  6640. pdwMsgType: PDWORD;
  6641. pdwInnerContentType: PDWORD;
  6642. pbDecoded: PBYTE;
  6643. pcbDecoded: PDWORD;
  6644. var ppXchgCert: array of PCCERT_CONTEXT;
  6645. var ppSignerCert: array of PCCERT_CONTEXT
  6646. ): BOOL; stdcall;
  6647. //+-------------------------------------------------------------------------
  6648. // Hash the message.
  6649. //
  6650. // If fDetachedHash is TRUE, only the ComputedHash is encoded in the
  6651. // pbHashedBlob. Otherwise, both the ToBeHashed and ComputedHash
  6652. // are encoded.
  6653. //
  6654. // pcbHashedBlob or pcbComputedHash can be NULL, indicating the caller
  6655. // isn't interested in getting the output.
  6656. //--------------------------------------------------------------------------
  6657. function CryptHashMessage(pHashPara: PCRYPT_HASH_MESSAGE_PARA;
  6658. fDetachedHash: BOOL;
  6659. cToBeHashed: DWORD;
  6660. const rgpbToBeHashed: array of PBYTE;
  6661. rgcbToBeHashed: array of DWORD;
  6662. pbHashedBlob: PBYTE;
  6663. pcbHashedBlob: PDWORD;
  6664. pbComputedHash: PBYTE;
  6665. pcbComputedHash: PDWORD): BOOL; stdcall;
  6666. //+-------------------------------------------------------------------------
  6667. // Verify a hashed message.
  6668. //
  6669. // pcbToBeHashed or pcbComputedHash can be NULL,
  6670. // indicating the caller isn't interested in getting the output.
  6671. //--------------------------------------------------------------------------
  6672. function CryptVerifyMessageHash(pHashPara: PCRYPT_HASH_MESSAGE_PARA;
  6673. pbHashedBlob: PBYTE;
  6674. cbHashedBlob: DWORD;
  6675. pbToBeHashed: PBYTE;
  6676. pcbToBeHashed: PDWORD;
  6677. pbComputedHash: PBYTE;
  6678. pcbComputedHash: PDWORD): BOOL; stdcall;
  6679. //+-------------------------------------------------------------------------
  6680. // Verify a hashed message containing a detached hash.
  6681. // The "to be hashed" content is passed in separately. No
  6682. // decoded output. Otherwise, identical to CryptVerifyMessageHash.
  6683. //
  6684. // pcbComputedHash can be NULL, indicating the caller isn't interested
  6685. // in getting the output.
  6686. //--------------------------------------------------------------------------
  6687. function CryptVerifyDetachedMessageHash(pHashPara: PCRYPT_HASH_MESSAGE_PARA;
  6688. pbDetachedHashBlob: PBYTE;
  6689. cbDetachedHashBlob: DWORD;
  6690. cToBeHashed: DWORD;
  6691. rgpbToBeHashed: array of PBYTE;
  6692. rgcbToBeHashed: array of DWORD;
  6693. pbComputedHash: PBYTE;
  6694. pcbComputedHash: PDWORD): BOOL; stdcall;
  6695. //+-------------------------------------------------------------------------
  6696. // Sign the message using the provider's private key specified in the
  6697. // parameters. A dummy SignerId is created and stored in the message.
  6698. //
  6699. // Normally used until a certificate has been created for the key.
  6700. //--------------------------------------------------------------------------
  6701. function CryptSignMessageWithKey(pSignPara: PCRYPT_KEY_SIGN_MESSAGE_PARA;
  6702. const pbToBeSigned: PBYTE;
  6703. cbToBeSigned: DWORD;
  6704. pbSignedBlob: PBYTE;
  6705. pcbSignedBlob: PDWORD): BOOL; stdcall;
  6706. //+-------------------------------------------------------------------------
  6707. // Verify a signed message using the specified public key info.
  6708. //
  6709. // Normally called by a CA until it has created a certificate for the
  6710. // key.
  6711. //
  6712. // pPublicKeyInfo contains the public key to use to verify the signed
  6713. // message. If NULL, the signature isn't verified (for instance, the decoded
  6714. // content may contain the PublicKeyInfo).
  6715. //
  6716. // pcbDecoded can be NULL, indicating the caller isn't interested
  6717. // in getting the decoded content.
  6718. //--------------------------------------------------------------------------
  6719. function CryptVerifyMessageSignatureWithKey(pVerifyPara: PCRYPT_KEY_VERIFY_MESSAGE_PARA;
  6720. pPublicKeyInfo: PCERT_PUBLIC_KEY_INFO;
  6721. const pbSignedBlob: PBYTE;
  6722. cbSignedBlob: DWORD;
  6723. pbDecoded: PBYTE;
  6724. pcbDecoded: PDWORD): BOOL; stdcall;
  6725. //+=========================================================================
  6726. // System Certificate Store Data Structures and APIs
  6727. //==========================================================================
  6728. //+-------------------------------------------------------------------------
  6729. // Get a system certificate store based on a subsystem protocol.
  6730. //
  6731. // Current examples of subsystems protocols are:
  6732. // "MY" Cert Store hold certs with associated Private Keys
  6733. // "CA" Certifying Authority certs
  6734. // "ROOT" Root Certs
  6735. // "SPC" Software publisher certs
  6736. //
  6737. //
  6738. // If hProv is NULL the default provider "1" is opened for you.
  6739. // When the store is closed the provider is release. Otherwise
  6740. // if hProv is not NULL, no provider is created or released.
  6741. //
  6742. // The returned Cert Store can be searched for an appropriate Cert
  6743. // using the Cert Store API's (see certstor.h)
  6744. //
  6745. // When done, the cert store should be closed using CertStoreClose
  6746. //--------------------------------------------------------------------------
  6747. function CertOpenSystemStoreA(hProv: HCRYPTPROV;
  6748. szSubsystemProtocol: LPCSTR): HCERTSTORE; stdcall;
  6749. function CertOpenSystemStoreW(hProv: HCRYPTPROV;
  6750. szSubsystemProtocol: LPCWSTR): HCERTSTORE; stdcall;
  6751. function CertOpenSystemStore(hProv: HCRYPTPROV;
  6752. szSubsystemProtocol: LPAWSTR): HCERTSTORE; stdcall;
  6753. function CertAddEncodedCertificateToSystemStoreA(szCertStoreName: LPCSTR;
  6754. const pbCertEncoded: PBYTE;
  6755. cbCertEncoded: DWORD): BOOL; stdcall;
  6756. function CertAddEncodedCertificateToSystemStoreW(szCertStoreName: LPCWSTR;
  6757. const pbCertEncoded: PBYTE;
  6758. cbCertEncoded: DWORD): BOOL; stdcall;
  6759. function CertAddEncodedCertificateToSystemStore(szCertStoreName: LPAWSTR;
  6760. const pbCertEncoded: PBYTE;
  6761. cbCertEncoded: DWORD): BOOL; stdcall;
  6762. //+-------------------------------------------------------------------------
  6763. // Find all certificate chains tying the given issuer name to any certificate
  6764. // that the current user has a private key for.
  6765. //
  6766. // If no certificate chain is found, FALSE is returned with LastError set
  6767. // to CRYPT_E_NOT_FOUND and the counts zeroed.
  6768. //
  6769. // IE 3.0 ASSUMPTION:
  6770. // The client certificates are in the "My" system store. The issuer
  6771. // cerificates may be in the "Root", "CA" or "My" system stores.
  6772. //--------------------------------------------------------------------------
  6773. type
  6774. PCERT_CHAIN = ^CERT_CHAIN;
  6775. CERT_CHAIN = record
  6776. cCerts: DWORD; // number of certs in chain
  6777. certs: PCERT_BLOB; // pointer to array of cert chain blobs representing the certs
  6778. keyLocatorInfo: CRYPT_KEY_PROV_INFO; // key locator for cert
  6779. end;
  6780. // WINCRYPT32API This is not exported by crypt32, it is exported by softpub
  6781. function FindCertsByIssuer(pCertChains: PCERT_CHAIN;
  6782. pcbCertChains: PDWORD;
  6783. pcCertChains: PDWORD; // count of certificates chains returned
  6784. pbEncodedIssuerName: PBYTE; // DER encoded issuer name
  6785. cbEncodedIssuerName: DWORD; // count in bytes of encoded issuer name
  6786. pwszPurpose: LPCWSTR; // "ClientAuth" or "CodeSigning"
  6787. dwKeySpec: DWORD // only return signers supporting this keyspec
  6788. ): HRESULT; stdcall;
  6789. //////////////////////////// VERSION 2 ////////////////////////////////////////////////////////////////////
  6790. implementation
  6791. {Macro inplementation}
  6792. function GET_ALG_CLASS(x: integer): integer;
  6793. begin
  6794. Result := (x and (7 shl 13));
  6795. end;
  6796. function GET_ALG_TYPE(x: integer): integer;
  6797. begin
  6798. Result := (x and (15 shl 9));
  6799. end;
  6800. function GET_ALG_SID(x: integer): integer;
  6801. begin
  6802. Result := (x and (511));
  6803. end;
  6804. function RCRYPT_SUCCEEDED(rt: BOOL): BOOL;
  6805. begin
  6806. Result := rt = CRYPT_SUCCEED;
  6807. end;
  6808. function RCRYPT_FAILED(rt: BOOL): BOOL;
  6809. begin
  6810. Result := rt = CRYPT_FAILED;
  6811. end;
  6812. function GET_CERT_UNICODE_RDN_ERR_INDEX(X: integer): integer;
  6813. begin
  6814. Result := ((X shr CERT_UNICODE_RDN_ERR_INDEX_SHIFT) and CERT_UNICODE_RDN_ERR_INDEX_MASK);
  6815. end;
  6816. function GET_CERT_UNICODE_ATTR_ERR_INDEX(X: integer): integer;
  6817. begin
  6818. Result := ((X shr CERT_UNICODE_ATTR_ERR_INDEX_SHIFT) and CERT_UNICODE_ATTR_ERR_INDEX_MASK);
  6819. end;
  6820. function GET_CERT_UNICODE_VALUE_ERR_INDEX(X: integer): integer;
  6821. begin
  6822. Result := (X and CERT_UNICODE_VALUE_ERR_INDEX_MASK);
  6823. end;
  6824. function GET_CERT_ALT_NAME_ENTRY_ERR_INDEX(X: DWORD): DWORD;
  6825. begin
  6826. Result := ((X shr CERT_ALT_NAME_ENTRY_ERR_INDEX_SHIFT) and CERT_ALT_NAME_ENTRY_ERR_INDEX_MASK);
  6827. end;
  6828. function GET_CERT_ALT_NAME_VALUE_ERR_INDEX(X: DWORD): DWORD;
  6829. begin
  6830. Result := (X and CERT_ALT_NAME_VALUE_ERR_INDEX_MASK);
  6831. end;
  6832. function GET_CRL_DIST_POINT_ERR_INDEX(X: DWORD): DWORD;
  6833. begin
  6834. Result := ((X shr CRL_DIST_POINT_ERR_INDEX_SHIFT) and CRL_DIST_POINT_ERR_INDEX_MASK);
  6835. end;
  6836. function IS_CRL_DIST_POINT_ERR_CRL_ISSUER(X: DWORD): BOOL;
  6837. begin
  6838. Result := (0 <> (X and CRL_DIST_POINT_ERR_CRL_ISSUER_BIT));
  6839. end;
  6840. ///////////////////////////////////////version 2 /////////////////////////
  6841. function IS_CERT_RDN_CHAR_STRING(X: DWORD): BOOL;
  6842. begin
  6843. Result := BOOL(X >= CERT_RDN_NUMERIC_STRING);
  6844. end;
  6845. function GET_CERT_ENCODING_TYPE(X: DWORD): DWORD;
  6846. begin
  6847. Result := (X and CERT_ENCODING_TYPE_MASK);
  6848. end;
  6849. function GET_CMSG_ENCODING_TYPE(X: DWORD): DWORD;
  6850. begin
  6851. Result := (X and CMSG_ENCODING_TYPE_MASK);
  6852. end;
  6853. function IS_CERT_HASH_PROP_ID(X: DWORD): BOOL;
  6854. begin
  6855. if (X = CERT_SHA1_HASH_PROP_ID) or (X = CERT_MD5_HASH_PROP_ID) then
  6856. Result := True
  6857. else
  6858. Result := False;
  6859. end;
  6860. {end Macro}
  6861. function CryptAcquireContextA; external ADVAPI32 name 'CryptAcquireContextA';
  6862. {$IFDEF UNICODE}
  6863. function CryptAcquireContext; external ADVAPI32 name 'CryptAcquireContextW';
  6864. {$ELSE}
  6865. function CryptAcquireContext; external ADVAPI32 name 'CryptAcquireContextA';
  6866. {$ENDIF}
  6867. function CryptAcquireContextW; external ADVAPI32 name 'CryptAcquireContextW';
  6868. function CryptReleaseContext; external ADVAPI32 name 'CryptReleaseContext';
  6869. function CryptGenKey; external ADVAPI32 name 'CryptGenKey';
  6870. function CryptDeriveKey; external ADVAPI32 name 'CryptDeriveKey';
  6871. function CryptDestroyKey; external ADVAPI32 name 'CryptDestroyKey';
  6872. function CryptSetKeyParam; external ADVAPI32 name 'CryptSetKeyParam';
  6873. function CryptGetKeyParam; external ADVAPI32 name 'CryptGetKeyParam';
  6874. function CryptSetHashParam; external ADVAPI32 name 'CryptSetHashParam';
  6875. function CryptGetHashParam; external ADVAPI32 name 'CryptGetHashParam';
  6876. function CryptSetProvParam; external ADVAPI32 name 'CryptSetProvParam';
  6877. function CryptGetProvParam; external ADVAPI32 name 'CryptGetProvParam';
  6878. function CryptGenRandom; external ADVAPI32 name 'CryptGenRandom';
  6879. function CryptGetUserKey; external ADVAPI32 name 'CryptGetUserKey';
  6880. function CryptExportKey; external ADVAPI32 name 'CryptExportKey';
  6881. function CryptImportKey; external ADVAPI32 name 'CryptImportKey';
  6882. function CryptEncrypt; external ADVAPI32 name 'CryptEncrypt';
  6883. function CryptDecrypt; external ADVAPI32 name 'CryptDecrypt';
  6884. function CryptCreateHash; external ADVAPI32 name 'CryptCreateHash';
  6885. function CryptHashData; external ADVAPI32 name 'CryptHashData';
  6886. function CryptHashSessionKey; external ADVAPI32 name 'CryptHashSessionKey';
  6887. function CryptDestroyHash; external ADVAPI32 name 'CryptDestroyHash';
  6888. function CryptSignHashA; external ADVAPI32 name 'CryptSignHashA';
  6889. function CryptSignHashW; external ADVAPI32 name 'CryptSignHashW';
  6890. function CryptSignHashU; external CRYPT32 name 'CryptSignHashU';
  6891. {$IFDEF UNICODE}
  6892. function CryptSignHash; external ADVAPI32 name 'CryptSignHashW';
  6893. {$ELSE}
  6894. function CryptSignHash; external ADVAPI32 name 'CryptSignHashA';
  6895. {$ENDIF}
  6896. function CryptVerifySignatureA; external ADVAPI32 name 'CryptVerifySignatureA';
  6897. function CryptVerifySignatureW; external ADVAPI32 name 'CryptVerifySignatureW';
  6898. {$IFDEF UNICODE}
  6899. function CryptVerifySignature; external ADVAPI32 name 'CryptVerifySignatureW';
  6900. {$ELSE}
  6901. function CryptVerifySignature; external ADVAPI32 name 'CryptVerifySignatureA';
  6902. {$ENDIF}
  6903. function CryptSetProviderW; external ADVAPI32 name 'CryptSetProviderW';
  6904. function CryptSetProviderA; external ADVAPI32 name 'CryptSetProviderA';
  6905. function CryptSetProviderU; external CRYPT32 name 'CryptSetProviderU';
  6906. {$IFDEF UNICODE}
  6907. function CryptSetProvider; external ADVAPI32 name 'CryptSetProviderW';
  6908. {$ELSE}
  6909. function CryptSetProvider; external ADVAPI32 name 'CryptSetProviderA';
  6910. {$ENDIF}
  6911. {$IFDEF NT5}
  6912. function CryptSetProviderExA; external ADVAPI32NT5 name 'CryptSetProviderExA'; //nt5 advapi32
  6913. function CryptSetProviderExW; external ADVAPI32NT5 name 'CryptSetProviderExW';
  6914. {$IFDEF UNICODE}
  6915. function CryptSetProviderEx; external ADVAPI32NT5 name 'CryptSetProviderExW';
  6916. {$ELSE}
  6917. function CryptSetProviderEx; external ADVAPI32NT5 name 'CryptSetProviderExA';
  6918. {$ENDIF} // !UNICODE
  6919. function CryptGetDefaultProviderA; external ADVAPI32NT5 name 'CryptGetDefaultProviderA'; //nt5 advapi32
  6920. function CryptGetDefaultProviderW; external ADVAPI32NT5 name 'CryptGetDefaultProviderW';
  6921. {$IFDEF UNICODE}
  6922. function CryptGetDefaultProvider; external ADVAPI32NT5 name 'CryptGetDefaultProviderW';
  6923. {$ELSE}
  6924. function CryptGetDefaultProvider; external ADVAPI32NT5 name 'CryptGetDefaultProviderA';
  6925. {$ENDIF} // !UNICODE
  6926. function CryptEnumProviderTypesA; external ADVAPI32NT5 name 'CryptEnumProviderTypesA'; //nt5 advapi32
  6927. function CryptEnumProviderTypesW; external ADVAPI32NT5 name 'CryptEnumProviderTypesW';
  6928. {$IFDEF UNICODE}
  6929. function CryptEnumProviderTypes; external ADVAPI32NT5 name 'CryptEnumProviderTypesW';
  6930. {$ELSE}
  6931. function CryptEnumProviderTypes; external ADVAPI32NT5 name 'CryptEnumProviderTypesA';
  6932. {$ENDIF} // !UNICODE
  6933. function CryptEnumProvidersA; external ADVAPI32NT5 name 'CryptEnumProvidersA'; //nt5 advapi32
  6934. function CryptEnumProvidersW; external ADVAPI32NT5 name 'CryptEnumProvidersW';
  6935. {$IFDEF UNICODE}
  6936. function CryptEnumProviders; external ADVAPI32NT5 name 'CryptEnumProvidersW';
  6937. {$ELSE}
  6938. function CryptEnumProviders; external ADVAPI32NT5 name 'CryptEnumProvidersA';
  6939. {$ENDIF} // !UNICODE
  6940. function CryptContextAddRef; external ADVAPI32NT5 name 'CryptContextAddRef'; //nt5 advapi32
  6941. function CryptDuplicateKey; external ADVAPI32NT5 name 'CryptDuplicateKey'; //nt5 advapi32
  6942. function CryptDuplicateHash; external ADVAPI32NT5 name 'CryptDuplicateHash'; //nt5 advapi32
  6943. {$ENDIF NT5}
  6944. function CryptEnumProvidersU; external CRYPT32 name 'CryptEnumProvidersU';
  6945. function CryptFormatObject; external CRYPT32 name 'CryptFormatObject';
  6946. function CryptEncodeObject; external CRYPT32 name 'CryptEncodeObject';
  6947. function CryptDecodeObject; external CRYPT32 name 'CryptDecodeObject';
  6948. function CryptInstallOIDFunctionAddress; external CRYPT32 name 'CryptInstallOIDFunctionAddress';
  6949. function CryptInitOIDFunctionSet; external CRYPT32 name 'CryptInitOIDFunctionSet';
  6950. function CryptGetOIDFunctionAddress; external CRYPT32 name 'CryptGetOIDFunctionAddress';
  6951. function CryptGetDefaultOIDDllList; external CRYPT32 name 'CryptGetDefaultOIDDllList';
  6952. function CryptGetDefaultOIDFunctionAddress; external CRYPT32 name 'CryptGetDefaultOIDFunctionAddress';
  6953. function CryptFreeOIDFunctionAddress; external CRYPT32 name 'CryptFreeOIDFunctionAddress';
  6954. function CryptRegisterOIDFunction; external CRYPT32 name 'CryptRegisterOIDFunction';
  6955. function CryptUnregisterOIDFunction; external CRYPT32 name 'CryptUnregisterOIDFunction';
  6956. function CryptRegisterDefaultOIDFunction; external CRYPT32 name 'CryptRegisterDefaultOIDFunction';
  6957. function CryptUnregisterDefaultOIDFunction; external CRYPT32 name 'CryptUnregisterDefaultOIDFunction';
  6958. function CryptSetOIDFunctionValue; external CRYPT32 name 'CryptSetOIDFunctionValue';
  6959. function CryptGetOIDFunctionValue; external CRYPT32 name 'CryptGetOIDFunctionValue';
  6960. function CryptEnumOIDFunction; external CRYPT32 name 'CryptEnumOIDFunction';
  6961. function CryptFindOIDInfo; external CRYPT32 name 'CryptFindOIDInfo';
  6962. function CryptRegisterOIDInfo; external CRYPT32 name 'CryptRegisterOIDInfo';
  6963. function CryptUnregisterOIDInfo; external CRYPT32 name 'CryptUnregisterOIDInfo';
  6964. function CryptMsgOpenToEncode; external CRYPT32 name 'CryptMsgOpenToEncode';
  6965. function CryptMsgCalculateEncodedLength; external CRYPT32 name 'CryptMsgCalculateEncodedLength';
  6966. function CryptMsgOpenToDecode; external CRYPT32 name 'CryptMsgOpenToDecode';
  6967. function CryptMsgClose; external CRYPT32 name 'CryptMsgClose';
  6968. function CryptMsgUpdate; external CRYPT32 name 'CryptMsgUpdate';
  6969. function CryptMsgControl; external CRYPT32 name 'CryptMsgControl';
  6970. function CryptMsgVerifyCountersignatureEncoded; external CRYPT32 name 'CryptMsgVerifyCountersignatureEncoded';
  6971. function CryptMsgCountersign; external CRYPT32 name 'CryptMsgCountersign';
  6972. function CryptMsgCountersignEncoded; external CRYPT32 name 'CryptMsgCountersignEncoded';
  6973. function CryptMsgGetParam; external CRYPT32 name 'CryptMsgGetParam';
  6974. function CertOpenStore; external CRYPT32 name 'CertOpenStore';
  6975. function CertDuplicateStore; external CRYPT32 name 'CertDuplicateStore';
  6976. function CertSaveStore; external CRYPT32 name 'CertSaveStore';
  6977. function CertCloseStore; external CRYPT32 name 'CertCloseStore';
  6978. function CertGetSubjectCertificateFromStore; external CRYPT32 name 'CertGetSubjectCertificateFromStore';
  6979. function CertEnumCertificatesInStore; external CRYPT32 name 'CertEnumCertificatesInStore';
  6980. function CertFindCertificateInStore; external CRYPT32 name 'CertFindCertificateInStore';
  6981. function CertGetIssuerCertificateFromStore; external CRYPT32 name 'CertGetIssuerCertificateFromStore';
  6982. function CertVerifySubjectCertificateContext; external CRYPT32 name 'CertVerifySubjectCertificateContext';
  6983. function CertDuplicateCertificateContext; external CRYPT32 name 'CertDuplicateCertificateContext';
  6984. function CertCreateCertificateContext; external CRYPT32 name 'CertCreateCertificateContext';
  6985. function CertFreeCertificateContext; external CRYPT32 name 'CertFreeCertificateContext';
  6986. function CertSetCertificateContextProperty; external CRYPT32 name 'CertSetCertificateContextProperty';
  6987. function CertGetCertificateContextProperty; external CRYPT32 name 'CertGetCertificateContextProperty';
  6988. function CertEnumCertificateContextProperties; external CRYPT32 name 'CertEnumCertificateContextProperties';
  6989. function CertGetCRLFromStore; external CRYPT32 name 'CertGetCRLFromStore';
  6990. function CertDuplicateCRLContext; external CRYPT32 name 'CertDuplicateCRLContext';
  6991. function CertCreateCRLContext; external CRYPT32 name 'CertCreateCRLContext';
  6992. function CertFreeCRLContext; external CRYPT32 name 'CertFreeCRLContext';
  6993. function CertSetCRLContextProperty; external CRYPT32 name 'CertSetCRLContextProperty';
  6994. function CertGetCRLContextProperty; external CRYPT32 name 'CertGetCRLContextProperty';
  6995. function CertEnumCRLContextProperties; external CRYPT32 name 'CertEnumCRLContextProperties';
  6996. function CertAddEncodedCertificateToStore; external CRYPT32 name 'CertAddEncodedCertificateToStore';
  6997. function CertAddCertificateContextToStore; external CRYPT32 name 'CertAddCertificateContextToStore';
  6998. function CertAddSerializedElementToStore; external CRYPT32 name 'CertAddSerializedElementToStore';
  6999. function CertDeleteCertificateFromStore; external CRYPT32 name 'CertDeleteCertificateFromStore';
  7000. function CertAddEncodedCRLToStore; external CRYPT32 name 'CertAddEncodedCRLToStore';
  7001. function CertAddCRLContextToStore; external CRYPT32 name 'CertAddCRLContextToStore';
  7002. function CertDeleteCRLFromStore; external CRYPT32 name 'CertDeleteCRLFromStore';
  7003. function CertSerializeCertificateStoreElement; external CRYPT32 name 'CertSerializeCertificateStoreElement';
  7004. function CertSerializeCRLStoreElement; external CRYPT32 name 'CertSerializeCRLStoreElement';
  7005. function CertDuplicateCTLContext; external CRYPT32 name 'CertDuplicateCTLContext';
  7006. function CertCreateCTLContext; external CRYPT32 name 'CertCreateCTLContext';
  7007. function CertFreeCTLContext; external CRYPT32 name 'CertFreeCTLContext';
  7008. function CertSetCTLContextProperty; external CRYPT32 name 'CertSetCTLContextProperty';
  7009. function CertGetCTLContextProperty; external CRYPT32 name 'CertGetCTLContextProperty';
  7010. function CertEnumCTLContextProperties; external CRYPT32 name 'CertEnumCTLContextProperties';
  7011. function CertEnumCTLsInStore; external CRYPT32 name 'CertEnumCTLsInStore';
  7012. function CertFindSubjectInCTL; external CRYPT32 name 'CertFindSubjectInCTL';
  7013. function CertFindCTLInStore; external CRYPT32 name 'CertFindCTLInStore';
  7014. function CertAddEncodedCTLToStore; external CRYPT32 name 'CertAddEncodedCTLToStore';
  7015. function CertAddCTLContextToStore; external CRYPT32 name 'CertAddCTLContextToStore';
  7016. function CertSerializeCTLStoreElement; external CRYPT32 name 'CertSerializeCTLStoreElement';
  7017. function CertDeleteCTLFromStore; external CRYPT32 name 'CertDeleteCTLFromStore';
  7018. function CertGetEnhancedKeyUsage; external CRYPT32 name 'CertGetEnhancedKeyUsage';
  7019. function CertSetEnhancedKeyUsage; external CRYPT32 name 'CertSetEnhancedKeyUsage';
  7020. function CertAddEnhancedKeyUsageIdentifier; external CRYPT32 name 'CertAddEnhancedKeyUsageIdentifier';
  7021. function CertRemoveEnhancedKeyUsageIdentifier; external CRYPT32 name 'CertRemoveEnhancedKeyUsageIdentifier';
  7022. function CryptMsgGetAndVerifySigner; external CRYPT32 name 'CryptMsgGetAndVerifySigner';
  7023. function CryptMsgSignCTL; external CRYPT32 name 'CryptMsgSignCTL';
  7024. function CryptMsgEncodeAndSignCTL; external CRYPT32 name 'CryptMsgEncodeAndSignCTL';
  7025. function CertVerifyCTLUsage; external CRYPT32 name 'CertVerifyCTLUsage';
  7026. function CertVerifyRevocation; external CRYPT32 name 'CertVerifyRevocation';
  7027. function CertCompareIntegerBlob; external CRYPT32 name 'CertCompareIntegerBlob';
  7028. function CertCompareCertificate; external CRYPT32 name 'CertCompareCertificate';
  7029. function CertCompareCertificateName; external CRYPT32 name 'CertCompareCertificateName';
  7030. function CertIsRDNAttrsInCertificateName; external CRYPT32 name 'CertIsRDNAttrsInCertificateName';
  7031. function CertComparePublicKeyInfo; external CRYPT32 name 'CertComparePublicKeyInfo';
  7032. function CertGetPublicKeyLength; external CRYPT32 name 'CertGetPublicKeyLength';
  7033. function CryptVerifyCertificateSignature; external CRYPT32 name 'CryptVerifyCertificateSignature';
  7034. function CryptHashToBeSigned; external CRYPT32 name 'CryptHashToBeSigned';
  7035. function CryptHashCertificate; external CRYPT32 name 'CryptHashCertificate';
  7036. function CryptSignCertificate; external CRYPT32 name 'CryptSignCertificate';
  7037. function CryptSignAndEncodeCertificate; external CRYPT32 name 'CryptSignAndEncodeCertificate';
  7038. function CertVerifyTimeValidity; external CRYPT32 name 'CertVerifyTimeValidity';
  7039. function CertVerifyCRLTimeValidity; external CRYPT32 name 'CertVerifyCRLTimeValidity';
  7040. function CertVerifyValidityNesting; external CRYPT32 name 'CertVerifyValidityNesting';
  7041. function CertVerifyCRLRevocation; external CRYPT32 name 'CertVerifyCRLRevocation';
  7042. function CertAlgIdToOID; external CRYPT32 name 'CertAlgIdToOID';
  7043. function CertOIDToAlgId; external CRYPT32 name 'CertOIDToAlgId';
  7044. function CertFindExtension; external CRYPT32 name 'CertFindExtension';
  7045. function CertFindAttribute; external CRYPT32 name 'CertFindAttribute';
  7046. function CertFindRDNAttr; external CRYPT32 name 'CertFindRDNAttr';
  7047. function CertGetIntendedKeyUsage; external CRYPT32 name 'CertGetIntendedKeyUsage';
  7048. function CryptExportPublicKeyInfo; external CRYPT32 name 'CryptExportPublicKeyInfo';
  7049. function CryptExportPublicKeyInfoEx; external CRYPT32 name 'CryptExportPublicKeyInfoEx';
  7050. function CryptImportPublicKeyInfo; external CRYPT32 name 'CryptImportPublicKeyInfo';
  7051. function CryptImportPublicKeyInfoEx; external CRYPT32 name 'CryptImportPublicKeyInfoEx';
  7052. function CryptHashPublicKeyInfo; external CRYPT32 name 'CryptHashPublicKeyInfo';
  7053. function CertRDNValueToStrA; external CRYPT32 name 'CertRDNValueToStrA';
  7054. function CertRDNValueToStrW; external CRYPT32 name 'CertRDNValueToStrW';
  7055. {$IFDEF UNICODE}
  7056. function CertRDNValueToStr; external CRYPT32 name 'CertRDNValueToStrW';
  7057. {$ELSE}
  7058. function CertRDNValueToStr; external CRYPT32 name 'CertRDNValueToStrA';
  7059. {$ENDIF} // !UNICODE
  7060. function CertNameToStrA; external CRYPT32 name 'CertNameToStrA';
  7061. function CertNameToStrW; external CRYPT32 name 'CertNameToStrW';
  7062. {$IFDEF UNICODE}
  7063. function CertNameToStr; external CRYPT32 name 'CertNameToStrW';
  7064. {$ELSE}
  7065. function CertNameToStr; external CRYPT32 name 'CertNameToStrA';
  7066. {$ENDIF} // !UNICODE
  7067. function CertStrToNameW; external CRYPT32 name 'CertStrToNameW';
  7068. function CertStrToNameA; external CRYPT32 name 'CertStrToNameA';
  7069. {$IFDEF UNICODE}
  7070. function CertStrToName; external CRYPT32 name 'CertStrToNameW';
  7071. {$ELSE}
  7072. function CertStrToName; external CRYPT32 name 'CertStrToNameA';
  7073. {$ENDIF} // !UNICODE
  7074. function CryptSignMessage; external CRYPT32 name 'CryptSignMessage';
  7075. //function CryptSignMessageWithKey; external CRYPT32 name 'CryptSignMessageWithKey';
  7076. function CryptVerifyMessageSignature; external CRYPT32 name 'CryptVerifyMessageSignature';
  7077. //function CryptVerifyMessageSignatureWithKey; external CRYPT32 name 'CryptVerifyMessageSignatureWithKey';
  7078. function CryptGetMessageSignerCount; external CRYPT32 name 'CryptGetMessageSignerCount';
  7079. function CryptGetMessageCertificates; external CRYPT32 name 'CryptGetMessageCertificates';
  7080. function CryptVerifyDetachedMessageSignature; external CRYPT32 name 'CryptVerifyDetachedMessageSignature';
  7081. function CryptEncryptMessage; external CRYPT32 name 'CryptEncryptMessage';
  7082. function CryptDecryptMessage; external CRYPT32 name 'CryptDecryptMessage';
  7083. function CryptSignAndEncryptMessage; external CRYPT32 name 'CryptSignAndEncryptMessage';
  7084. function CryptDecryptAndVerifyMessageSignature; external CRYPT32 name 'CryptDecryptAndVerifyMessageSignature';
  7085. function CryptDecodeMessage; external CRYPT32 name 'CryptDecodeMessage';
  7086. function CryptHashMessage; external CRYPT32 name 'CryptHashMessage';
  7087. function CryptVerifyMessageHash; external CRYPT32 name 'CryptVerifyMessageHash';
  7088. function CryptVerifyDetachedMessageHash; external CRYPT32 name 'CryptVerifyDetachedMessageHash';
  7089. function CryptSignMessageWithKey; external CRYPT32 name 'CryptSignMessageWithKey';
  7090. function CryptVerifyMessageSignatureWithKey; external CRYPT32 name 'CryptVerifyMessageSignatureWithKey';
  7091. function CertOpenSystemStoreA; external CRYPT32 name 'CertOpenSystemStoreA';
  7092. function CertOpenSystemStoreW; external CRYPT32 name 'CertOpenSystemStoreW';
  7093. {$IFDEF UNICODE}
  7094. function CertOpenSystemStore; external CRYPT32 name 'CertOpenSystemStoreW';
  7095. {$ELSE}
  7096. function CertOpenSystemStore; external CRYPT32 name 'CertOpenSystemStoreA';
  7097. {$ENDIF} // !UNICODE
  7098. function CertAddEncodedCertificateToSystemStoreA; external CRYPT32 name 'CertAddEncodedCertificateToSystemStoreA';
  7099. function CertAddEncodedCertificateToSystemStoreW; external CRYPT32 name 'CertAddEncodedCertificateToSystemStoreW';
  7100. {$IFDEF UNICODE}
  7101. function CertAddEncodedCertificateToSystemStore; external CRYPT32 name 'CertAddEncodedCertificateToSystemStoreW';
  7102. {$ELSE}
  7103. function CertAddEncodedCertificateToSystemStore; external CRYPT32 name 'CertAddEncodedCertificateToSystemStoreA';
  7104. {$ENDIF} // !UNICODE
  7105. function FindCertsByIssuer; external SOFTPUB name 'FindCertsByIssuer';
  7106. end.