JwaWinCrypt.pas
上传用户:davidchvip
上传日期:2009-07-28
资源大小:1749k
文件大小:773k
源码类别:

Windows编程

开发平台:

Delphi

  1.   CMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO = _CMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO;
  2.   {$EXTERNALSYM CMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO}
  3.   TCmsgRecipientEncryptedKeyEncodeInfo = CMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO;
  4.   PCmsgRecipientEncryptedKeyEncodeInfo = PCMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO;
  5.   PCMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO = ^CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO;
  6.   {$EXTERNALSYM PCMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO}
  7.   _CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO = record
  8.     cbSize: DWORD;
  9.     KeyEncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  10.     pvKeyEncryptionAuxInfo: Pointer;
  11.     KeyWrapAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  12.     pvKeyWrapAuxInfo: Pointer;
  13.     // The following hCryptProv and dwKeySpec must be specified for the
  14.     // CMSG_KEY_AGREE_STATIC_KEY_CHOICE.
  15.     //
  16.     // For CMSG_KEY_AGREE_EPHEMERAL_KEY_CHOICE, dwKeySpec isn't applicable
  17.     // and hCryptProv is optional.
  18.     hCryptProv: HCRYPTPROV;
  19.     dwKeySpec: DWORD;
  20.     dwKeyChoice: DWORD;
  21.     Union: record
  22.     case Integer of
  23.       // CMSG_KEY_AGREE_EPHEMERAL_KEY_CHOICE
  24.       //
  25.       // The ephemeral public key algorithm and parameters.
  26.       0: (pEphemeralAlgorithm: PCRYPT_ALGORITHM_IDENTIFIER);
  27.       // CMSG_KEY_AGREE_STATIC_KEY_CHOICE
  28.       //
  29.       // The CertId of the sender's certificate
  30.       1: (pSenderId: PCERT_ID);
  31.     end;
  32.     UserKeyingMaterial: CRYPT_DATA_BLOB; // OPTIONAL
  33.     cRecipientEncryptedKeys: DWORD;
  34.     rgpRecipientEncryptedKeys: PCMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO;
  35.   end;
  36.   {$EXTERNALSYM _CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO}
  37.   CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO = _CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO;
  38.   {$EXTERNALSYM CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO}
  39.   TCmsgKeyAgreeRecipientEncodeInfo = CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO;
  40.   PCmsgKeyAgreeRecipientEncodeInfo = PCMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO;
  41. const
  42.   CMSG_KEY_AGREE_EPHEMERAL_KEY_CHOICE = 1;
  43.   {$EXTERNALSYM CMSG_KEY_AGREE_EPHEMERAL_KEY_CHOICE}
  44.   CMSG_KEY_AGREE_STATIC_KEY_CHOICE    = 2;
  45.   {$EXTERNALSYM CMSG_KEY_AGREE_STATIC_KEY_CHOICE}
  46. //+-------------------------------------------------------------------------
  47. //  Mail List Recipient Encode Info
  48. //
  49. //  There is 1 choice for the KeyEncryptionKey: an already created CSP key
  50. //  handle. For the key handle choice, hCryptProv must be nonzero. This key
  51. //  handle isn't destroyed.
  52. //
  53. //  Note, even if CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  54. //  passed to CryptMsgOpenToEncode(), this hCryptProv isn't released.
  55. //
  56. //  Currently, pvKeyEncryptionAuxInfo is only defined for RC2 key wrap
  57. //  algorithms. Otherwise, its not used and must be set to NULL.
  58. //  When set for RC2 algorithms, points to a CMSG_RC2_AUX_INFO containing
  59. //  the RC2 effective key length.
  60. //
  61. //  Note, mail list recipients are not supported in PKCS #7 version 1.5.
  62. //--------------------------------------------------------------------------
  63. type
  64.   PCMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO = ^CMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO;
  65.   {$EXTERNALSYM PCMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO}
  66.   _CMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO = record
  67.     cbSize: DWORD;
  68.     KeyEncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  69.     pvKeyEncryptionAuxInfo: Pointer;
  70.     hCryptProv: HCRYPTPROV;
  71.     dwKeyChoice: DWORD;
  72.     Union: record
  73.     case Integer of
  74.       // CMSG_MAIL_LIST_HANDLE_KEY_CHOICE
  75.       0: (hKeyEncryptionKey: HCRYPTKEY);
  76.       // Reserve space for a potential pointer choice
  77.       1: (pvKeyEncryptionKey: Pointer);
  78.     end;
  79.     KeyId: CRYPT_DATA_BLOB;
  80.     // Following fields are optional.
  81.     Date: FILETIME;
  82.     pOtherAttr: PCRYPT_ATTRIBUTE_TYPE_VALUE;
  83.   end;
  84.   {$EXTERNALSYM _CMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO}
  85.   CMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO = _CMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO;
  86.   {$EXTERNALSYM CMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO}
  87.   TCmsgMailListRecipientEncodeInfo = CMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO;
  88.   PCmsgMailListRecipientEncodeInfo = PCMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO;
  89. const
  90.   CMSG_MAIL_LIST_HANDLE_KEY_CHOICE = 1;
  91.   {$EXTERNALSYM CMSG_MAIL_LIST_HANDLE_KEY_CHOICE}
  92. //+-------------------------------------------------------------------------
  93. //  Recipient Encode Info
  94. //
  95. //  Note, only key transport recipients are supported in PKCS #7 version 1.5.
  96. //--------------------------------------------------------------------------
  97. type
  98.   PCMSG_RECIPIENT_ENCODE_INFO = ^CMSG_RECIPIENT_ENCODE_INFO;
  99.   {$NODEFINE PCMSG_RECIPIENT_ENCODE_INFO}
  100.   _CMSG_RECIPIENT_ENCODE_INFO = record
  101.     dwRecipientChoice: DWORD;
  102.     case Integer of
  103.       // CMSG_KEY_TRANS_RECIPIENT
  104.       0: (pKeyTrans: PCMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO);
  105.       // CMSG_KEY_AGREE_RECIPIENT
  106.       1: (pKeyAgree: PCMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO);
  107.       // CMSG_MAIL_LIST_RECIPIENT
  108.       2: (pMailList: PCMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO);
  109.   end;
  110.   {$EXTERNALSYM _CMSG_RECIPIENT_ENCODE_INFO}
  111.   CMSG_RECIPIENT_ENCODE_INFO = _CMSG_RECIPIENT_ENCODE_INFO;
  112.   {$NODEFINE CMSG_RECIPIENT_ENCODE_INFO}
  113.   TCmsgRecipientEncodeInfo = CMSG_RECIPIENT_ENCODE_INFO;
  114.   PCmsgRecipientEncodeInfo = PCMSG_RECIPIENT_ENCODE_INFO;
  115. const
  116.   CMSG_KEY_TRANS_RECIPIENT = 1;
  117.   {$EXTERNALSYM CMSG_KEY_TRANS_RECIPIENT}
  118.   CMSG_KEY_AGREE_RECIPIENT = 2;
  119.   {$EXTERNALSYM CMSG_KEY_AGREE_RECIPIENT}
  120.   CMSG_MAIL_LIST_RECIPIENT = 3;
  121.   {$EXTERNALSYM CMSG_MAIL_LIST_RECIPIENT}
  122. //+-------------------------------------------------------------------------
  123. //  CMSG_RC2_AUX_INFO
  124. //
  125. //  AuxInfo for RC2 encryption algorithms. The pvEncryptionAuxInfo field
  126. //  in CMSG_ENCRYPTED_ENCODE_INFO should be updated to point to this
  127. //  structure. If not specified, defaults to 40 bit.
  128. //
  129. //  Note, this AuxInfo is only used when, the ContentEncryptionAlgorithm's
  130. //  Parameter.cbData is zero. Otherwise, the Parameters is decoded to
  131. //  get the bit length.
  132. //
  133. //  If CMSG_SP3_COMPATIBLE_ENCRYPT_FLAG is set in dwBitLen, then, SP3
  134. //  compatible encryption is done and the bit length is ignored.
  135. //--------------------------------------------------------------------------
  136. type
  137.   PCMSG_RC2_AUX_INFO = ^CMSG_RC2_AUX_INFO;
  138.   {$EXTERNALSYM PCMSG_RC2_AUX_INFO}
  139.   _CMSG_RC2_AUX_INFO = record
  140.     cbSize: DWORD;
  141.     dwBitLen: DWORD;
  142.   end;
  143.   {$EXTERNALSYM _CMSG_RC2_AUX_INFO}
  144.   CMSG_RC2_AUX_INFO = _CMSG_RC2_AUX_INFO;
  145.   {$EXTERNALSYM CMSG_RC2_AUX_INFO}
  146.   TCmsgRc2AuxInfo = CMSG_RC2_AUX_INFO;
  147.   PCmsgRc2AuxInfo = PCMSG_RC2_AUX_INFO;
  148. //+-------------------------------------------------------------------------
  149. //  CMSG_SP3_COMPATIBLE_AUX_INFO
  150. //
  151. //  AuxInfo for enabling SP3 compatible encryption.
  152. //
  153. //  The CMSG_SP3_COMPATIBLE_ENCRYPT_FLAG is set in dwFlags to enable SP3
  154. //  compatible encryption. When set, uses zero salt instead of no salt,
  155. //  the encryption algorithm parameters are NULL instead of containing the
  156. //  encoded RC2 parameters or encoded IV octet string and the encrypted
  157. //  symmetric key is encoded little endian instead of big endian.
  158. //--------------------------------------------------------------------------
  159.   PCMSG_SP3_COMPATIBLE_AUX_INFO = ^CMSG_SP3_COMPATIBLE_AUX_INFO;
  160.   {$EXTERNALSYM PCMSG_SP3_COMPATIBLE_AUX_INFO}
  161.   _CMSG_SP3_COMPATIBLE_AUX_INFO = record
  162.     cbSize: DWORD;
  163.     dwFlags: DWORD;
  164.   end;
  165.   {$EXTERNALSYM _CMSG_SP3_COMPATIBLE_AUX_INFO}
  166.   CMSG_SP3_COMPATIBLE_AUX_INFO = _CMSG_SP3_COMPATIBLE_AUX_INFO;
  167.   {$EXTERNALSYM CMSG_SP3_COMPATIBLE_AUX_INFO}
  168.   TCmsgSp3CompatibleAuxInfo = CMSG_SP3_COMPATIBLE_AUX_INFO;
  169.   PCmsgSp3CompatibleAuxInfo = PCMSG_SP3_COMPATIBLE_AUX_INFO;
  170. const
  171.   CMSG_SP3_COMPATIBLE_ENCRYPT_FLAG = DWORD($80000000);
  172.   {$EXTERNALSYM CMSG_SP3_COMPATIBLE_ENCRYPT_FLAG}
  173. //+-------------------------------------------------------------------------
  174. //  CMSG_RC4_AUX_INFO
  175. //
  176. //  AuxInfo for RC4 encryption algorithms. The pvEncryptionAuxInfo field
  177. //  in CMSG_ENCRYPTED_ENCODE_INFO should be updated to point to this
  178. //  structure. If not specified, uses the CSP's default bit length with no
  179. //  salt. Note, the base CSP has a 40 bit default and the enhanced CSP has
  180. //  a 128 bit default.
  181. //
  182. //  If CMSG_RC4_NO_SALT_FLAG is set in dwBitLen, then, no salt is generated.
  183. //  Otherwise, (128 - dwBitLen)/8 bytes of salt are generated and encoded
  184. //  as an OCTET STRING in the algorithm parameters field.
  185. //--------------------------------------------------------------------------
  186. type
  187.   PCMSG_RC4_AUX_INFO = ^CMSG_RC4_AUX_INFO;
  188.   {$EXTERNALSYM PCMSG_RC4_AUX_INFO}
  189.   _CMSG_RC4_AUX_INFO = record
  190.     cbSize: DWORD;
  191.     dwBitLen: DWORD;
  192.   end;
  193.   {$EXTERNALSYM _CMSG_RC4_AUX_INFO}
  194.   CMSG_RC4_AUX_INFO = _CMSG_RC4_AUX_INFO;
  195.   {$EXTERNALSYM CMSG_RC4_AUX_INFO}
  196.   TCmsgRc4AuxInfo = CMSG_RC4_AUX_INFO;
  197.   PCmsgRc4AuxInfo = PCMSG_RC4_AUX_INFO;
  198. const
  199.   CMSG_RC4_NO_SALT_FLAG = $40000000;
  200.   {$EXTERNALSYM CMSG_RC4_NO_SALT_FLAG}
  201. //+-------------------------------------------------------------------------
  202. //  CMSG_SIGNED_AND_ENVELOPED
  203. //
  204. //  For PKCS #7, a signed and enveloped message doesn't have the
  205. //  signer's authenticated or unauthenticated attributes. Otherwise, a
  206. //  combination of the CMSG_SIGNED_ENCODE_INFO and CMSG_ENVELOPED_ENCODE_INFO.
  207. //--------------------------------------------------------------------------
  208. type
  209.   PCMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO = ^CMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO;
  210.   {$EXTERNALSYM PCMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO}
  211.   _CMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO = record
  212.     cbSize: DWORD;
  213.     SignedInfo: CMSG_SIGNED_ENCODE_INFO;
  214.     EnvelopedInfo: CMSG_ENVELOPED_ENCODE_INFO;
  215.   end;
  216.   {$EXTERNALSYM _CMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO}
  217.   CMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO = _CMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO;
  218.   {$EXTERNALSYM CMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO}
  219.   TCmsgSignedAndEnvelopedEncodeInfo = CMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO;
  220.   PCmsgSignedAndEnvelopedEncodeInfo = PCMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO;
  221. //+-------------------------------------------------------------------------
  222. //  CMSG_HASHED
  223. //
  224. //  hCryptProv is used to do the hash. Doesn't need to use a private key.
  225. //
  226. //  If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  227. //  passed to CryptMsgOpenToEncode(), the hCryptProv is released.
  228. //
  229. //  If fDetachedHash is set, then, the encoded message doesn't contain
  230. //  any content (its treated as NULL Data)
  231. //
  232. //  pvHashAuxInfo currently isn't used and must be set to NULL.
  233. //--------------------------------------------------------------------------
  234.   PCMSG_HASHED_ENCODE_INFO = ^CMSG_HASHED_ENCODE_INFO;
  235.   {$EXTERNALSYM PCMSG_HASHED_ENCODE_INFO}
  236.   _CMSG_HASHED_ENCODE_INFO = record
  237.     cbSize: DWORD;
  238.     hCryptProv: HCRYPTPROV;
  239.     HashAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  240.     pvHashAuxInfo: Pointer;
  241.   end;
  242.   {$EXTERNALSYM _CMSG_HASHED_ENCODE_INFO}
  243.   CMSG_HASHED_ENCODE_INFO = _CMSG_HASHED_ENCODE_INFO;
  244.   {$EXTERNALSYM CMSG_HASHED_ENCODE_INFO}
  245.   TCmsgHashedEncodeInfo = CMSG_HASHED_ENCODE_INFO;
  246.   PCmsgHashedEncodeInfo = PCMSG_HASHED_ENCODE_INFO;
  247. //+-------------------------------------------------------------------------
  248. //  CMSG_ENCRYPTED
  249. //
  250. //  The key used to encrypt the message is identified outside of the message
  251. //  content (for example, password).
  252. //
  253. //  The content input to CryptMsgUpdate has already been encrypted.
  254. //
  255. //  pvEncryptionAuxInfo currently isn't used and must be set to NULL.
  256. //--------------------------------------------------------------------------
  257.   PCMSG_ENCRYPTED_ENCODE_INFO = ^CMSG_ENCRYPTED_ENCODE_INFO;
  258.   {$EXTERNALSYM PCMSG_ENCRYPTED_ENCODE_INFO}
  259.   _CMSG_ENCRYPTED_ENCODE_INFO = record
  260.     cbSize: DWORD;
  261.     ContentEncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  262.     pvEncryptionAuxInfo: Pointer;
  263.   end;
  264.   {$EXTERNALSYM _CMSG_ENCRYPTED_ENCODE_INFO}
  265.   CMSG_ENCRYPTED_ENCODE_INFO = _CMSG_ENCRYPTED_ENCODE_INFO;
  266.   {$EXTERNALSYM CMSG_ENCRYPTED_ENCODE_INFO}
  267.   TCmsgEncryptedEncodeInfo = CMSG_ENCRYPTED_ENCODE_INFO;
  268.   PCmsgEncryptedEncodeInfo = PCMSG_ENCRYPTED_ENCODE_INFO;
  269. //+-------------------------------------------------------------------------
  270. //  This parameter allows messages to be of variable length with streamed
  271. //  output.
  272. //
  273. //  By default, messages are of a definite length and
  274. //  CryptMsgGetParam(CMSG_CONTENT_PARAM) is
  275. //  called to get the cryptographically processed content. Until closed,
  276. //  the handle keeps a copy of the processed content.
  277. //
  278. //  With streamed output, the processed content can be freed as its streamed.
  279. //
  280. //  If the length of the content to be updated is known at the time of the
  281. //  open, then, ContentLength should be set to that length. Otherwise, it
  282. //  should be set to CMSG_INDEFINITE_LENGTH.
  283. //--------------------------------------------------------------------------
  284. type
  285.   PFN_CMSG_STREAM_OUTPUT = function (pvArg: Pointer; pbData: LPBYTE;
  286.     cbData: DWORD; fFinal: BOOL): BOOL; stdcall;
  287.   {$EXTERNALSYM PFN_CMSG_STREAM_OUTPUT}
  288.   PFnCMsgStreamOutput = PFN_CMSG_STREAM_OUTPUT;
  289. const
  290.   CMSG_INDEFINITE_LENGTH = DWORD($FFFFFFFF);
  291.   {$EXTERNALSYM CMSG_INDEFINITE_LENGTH}
  292. type
  293.   PCMSG_STREAM_INFO = ^CMSG_STREAM_INFO;
  294.   {$EXTERNALSYM PCMSG_STREAM_INFO}
  295.   _CMSG_STREAM_INFO = record
  296.     cbContent: DWORD;
  297.     pfnStreamOutput: PFN_CMSG_STREAM_OUTPUT;
  298.     pvArg: Pointer;
  299.   end;
  300.   {$EXTERNALSYM _CMSG_STREAM_INFO}
  301.   CMSG_STREAM_INFO = _CMSG_STREAM_INFO;
  302.   {$EXTERNALSYM CMSG_STREAM_INFO}
  303.   TCmsgStreamInfo = CMSG_STREAM_INFO;
  304.   PCmsgStreamInfo = PCMSG_STREAM_INFO;
  305. //+-------------------------------------------------------------------------
  306. //  Open dwFlags
  307. //--------------------------------------------------------------------------
  308. const
  309.   CMSG_BARE_CONTENT_FLAG             = $00000001;
  310.   {$EXTERNALSYM CMSG_BARE_CONTENT_FLAG}
  311.   CMSG_LENGTH_ONLY_FLAG              = $00000002;
  312.   {$EXTERNALSYM CMSG_LENGTH_ONLY_FLAG}
  313.   CMSG_DETACHED_FLAG                 = $00000004;
  314.   {$EXTERNALSYM CMSG_DETACHED_FLAG}
  315.   CMSG_AUTHENTICATED_ATTRIBUTES_FLAG = $00000008;
  316.   {$EXTERNALSYM CMSG_AUTHENTICATED_ATTRIBUTES_FLAG}
  317.   CMSG_CONTENTS_OCTETS_FLAG          = $00000010;
  318.   {$EXTERNALSYM CMSG_CONTENTS_OCTETS_FLAG}
  319.   CMSG_MAX_LENGTH_FLAG               = $00000020;
  320.   {$EXTERNALSYM CMSG_MAX_LENGTH_FLAG}
  321. // When set, nonData type inner content is encapsulated within an
  322. // OCTET STRING. Applicable to both Signed and Enveloped messages.
  323.   CMSG_CMS_ENCAPSULATED_CONTENT_FLAG = $00000040;
  324.   {$EXTERNALSYM CMSG_CMS_ENCAPSULATED_CONTENT_FLAG}
  325. // If set, then, the hCryptProv passed to CryptMsgOpenToEncode or
  326. // CryptMsgOpenToDecode is released on the final CryptMsgClose.
  327. // Not released if CryptMsgOpenToEncode or CryptMsgOpenToDecode fails.
  328. //
  329. // Note, the envelope recipient hCryptProv's aren't released.
  330.   CMSG_CRYPT_RELEASE_CONTEXT_FLAG = $00008000;
  331.   {$EXTERNALSYM CMSG_CRYPT_RELEASE_CONTEXT_FLAG}
  332. //+-------------------------------------------------------------------------
  333. //  Open a cryptographic message for encoding
  334. //
  335. //  For PKCS #7:
  336. //  If the content to be passed to CryptMsgUpdate has already
  337. //  been message encoded (the input to CryptMsgUpdate is the streamed output
  338. //  from another message encode), then, the CMSG_ENCODED_CONTENT_INFO_FLAG should
  339. //  be set in dwFlags. If not set, then, the inner ContentType is Data and
  340. //  the input to CryptMsgUpdate is treated as the inner Data type's Content,
  341. //  a string of bytes.
  342. //  If CMSG_BARE_CONTENT_FLAG is specified for a streamed message,
  343. //  the streamed output will not have an outer ContentInfo wrapper. This
  344. //  makes it suitable to be streamed into an enclosing message.
  345. //
  346. //  The pStreamInfo parameter needs to be set to stream the encoded message
  347. //  output.
  348. //--------------------------------------------------------------------------
  349. function CryptMsgOpenToEncode(dwMsgEncodingType, dwFlags, dwMsgType: DWORD;
  350.   pvMsgEncodeInfo: Pointer; pszInnerContentObjID: LPSTR;
  351.   pStreamInfo: PCMSG_STREAM_INFO): HCRYPTMSG; stdcall;
  352. {$EXTERNALSYM CryptMsgOpenToEncode}
  353. //+-------------------------------------------------------------------------
  354. //  Calculate the length of an encoded cryptographic message.
  355. //
  356. //  Calculates the length of the encoded message given the
  357. //  message type, encoding parameters and total length of
  358. //  the data to be updated. Note, this might not be the exact length. However,
  359. //  it will always be greater than or equal to the actual length.
  360. //--------------------------------------------------------------------------
  361. function CryptMsgCalculateEncodedLength(dwMsgEncodingType, dwFlags, dwMsgType: DWORD;
  362.   pvMsgEncodeInfo: Pointer; pszInnerContentObjID: LPSTR; cbData: DWORD): DWORD; stdcall;
  363. {$EXTERNALSYM CryptMsgCalculateEncodedLength}
  364. //+-------------------------------------------------------------------------
  365. //  Open a cryptographic message for decoding
  366. //
  367. //  hCryptProv specifies the crypto provider to use for hashing and/or
  368. //  decrypting the message. If hCryptProv is NULL, a default crypt provider
  369. //  is used.
  370. //
  371. //  Currently pRecipientInfo isn't used and should be set to NULL.
  372. //
  373. //  The pStreamInfo parameter needs to be set to stream the decoded content
  374. //  output.
  375. //--------------------------------------------------------------------------
  376. function CryptMsgOpenToDecode(dwMsgEncodingType, dwFlags, dwMsgType: DWORD;
  377.   hCryptProv: HCRYPTPROV; pRecipientInfo: PCERT_INFO;
  378.   pStreamInfo: PCMSG_STREAM_INFO): HCRYPTMSG; stdcall;
  379. {$EXTERNALSYM CryptMsgOpenToDecode}
  380. //+-------------------------------------------------------------------------
  381. //  Duplicate a cryptographic message handle
  382. //--------------------------------------------------------------------------
  383. function CryptMsgDuplicate(hCryptMsg: HCRYPTMSG): HCRYPTMSG; stdcall;
  384. {$EXTERNALSYM CryptMsgDuplicate}
  385. //+-------------------------------------------------------------------------
  386. //  Close a cryptographic message handle
  387. //
  388. //  LastError is preserved unless FALSE is returned.
  389. //--------------------------------------------------------------------------
  390. function CryptMsgClose(hCryptMsg: HCRYPTMSG): BOOL; stdcall;
  391. {$EXTERNALSYM CryptMsgClose}
  392. //+-------------------------------------------------------------------------
  393. //  Update the content of a cryptographic message. Depending on how the
  394. //  message was opened, the content is either encoded or decoded.
  395. //
  396. //  This function is repetitively called to append to the message content.
  397. //  fFinal is set to identify the last update. On fFinal, the encode/decode
  398. //  is completed. The encoded/decoded content and the decoded parameters
  399. //  are valid until the open and all duplicated handles are closed.
  400. //--------------------------------------------------------------------------
  401. function CryptMsgUpdate(hCryptMsg: HCRYPTMSG; pbData: LPBYTE; cbData: DWORD;
  402.   fFinal: BOOL): BOOL; stdcall;
  403. {$EXTERNALSYM CryptMsgUpdate}
  404. //+-------------------------------------------------------------------------
  405. //  Get a parameter after encoding/decoding a cryptographic message. Called
  406. //  after the final CryptMsgUpdate. Only the CMSG_CONTENT_PARAM and
  407. //  CMSG_COMPUTED_HASH_PARAM are valid for an encoded message.
  408. //
  409. //  For an encoded HASHED message, the CMSG_COMPUTED_HASH_PARAM can be got
  410. //  before any CryptMsgUpdates to get its length.
  411. //
  412. //  The pvData type definition depends on the dwParamType value.
  413. //
  414. //  Elements pointed to by fields in the pvData structure follow the
  415. //  structure. Therefore, *pcbData may exceed the size of the structure.
  416. //
  417. //  Upon input, if *pcbData == 0, then, *pcbData is updated with the length
  418. //  of the data and the pvData parameter is ignored.
  419. //
  420. //  Upon return, *pcbData is updated with the length of the data.
  421. //
  422. //  The OBJID BLOBs returned in the pvData structures point to
  423. //  their still encoded representation. The appropriate functions
  424. //  must be called to decode the information.
  425. //
  426. //  See below for a list of the parameters to get.
  427. //--------------------------------------------------------------------------
  428. function CryptMsgGetParam(hCryptMsg: HCRYPTMSG; dwParamType, dwIndex: DWORD;
  429.   pvData: Pointer; var pcbData: DWORD): BOOL; stdcall;
  430. {$EXTERNALSYM CryptMsgGetParam}
  431. //+-------------------------------------------------------------------------
  432. //  Get parameter types and their corresponding data structure definitions.
  433. //--------------------------------------------------------------------------
  434. const
  435.   CMSG_TYPE_PARAM                              = 1;
  436.   {$EXTERNALSYM CMSG_TYPE_PARAM}
  437.   CMSG_CONTENT_PARAM                           = 2;
  438.   {$EXTERNALSYM CMSG_CONTENT_PARAM}
  439.   CMSG_BARE_CONTENT_PARAM                      = 3;
  440.   {$EXTERNALSYM CMSG_BARE_CONTENT_PARAM}
  441.   CMSG_INNER_CONTENT_TYPE_PARAM                = 4;
  442.   {$EXTERNALSYM CMSG_INNER_CONTENT_TYPE_PARAM}
  443.   CMSG_SIGNER_COUNT_PARAM                      = 5;
  444.   {$EXTERNALSYM CMSG_SIGNER_COUNT_PARAM}
  445.   CMSG_SIGNER_INFO_PARAM                       = 6;
  446.   {$EXTERNALSYM CMSG_SIGNER_INFO_PARAM}
  447.   CMSG_SIGNER_CERT_INFO_PARAM                  = 7;
  448.   {$EXTERNALSYM CMSG_SIGNER_CERT_INFO_PARAM}
  449.   CMSG_SIGNER_HASH_ALGORITHM_PARAM             = 8;
  450.   {$EXTERNALSYM CMSG_SIGNER_HASH_ALGORITHM_PARAM}
  451.   CMSG_SIGNER_AUTH_ATTR_PARAM                  = 9;
  452.   {$EXTERNALSYM CMSG_SIGNER_AUTH_ATTR_PARAM}
  453.   CMSG_SIGNER_UNAUTH_ATTR_PARAM                = 10;
  454.   {$EXTERNALSYM CMSG_SIGNER_UNAUTH_ATTR_PARAM}
  455.   CMSG_CERT_COUNT_PARAM                        = 11;
  456.   {$EXTERNALSYM CMSG_CERT_COUNT_PARAM}
  457.   CMSG_CERT_PARAM                              = 12;
  458.   {$EXTERNALSYM CMSG_CERT_PARAM}
  459.   CMSG_CRL_COUNT_PARAM                         = 13;
  460.   {$EXTERNALSYM CMSG_CRL_COUNT_PARAM}
  461.   CMSG_CRL_PARAM                               = 14;
  462.   {$EXTERNALSYM CMSG_CRL_PARAM}
  463.   CMSG_ENVELOPE_ALGORITHM_PARAM                = 15;
  464.   {$EXTERNALSYM CMSG_ENVELOPE_ALGORITHM_PARAM}
  465.   CMSG_RECIPIENT_COUNT_PARAM                   = 17;
  466.   {$EXTERNALSYM CMSG_RECIPIENT_COUNT_PARAM}
  467.   CMSG_RECIPIENT_INDEX_PARAM                   = 18;
  468.   {$EXTERNALSYM CMSG_RECIPIENT_INDEX_PARAM}
  469.   CMSG_RECIPIENT_INFO_PARAM                    = 19;
  470.   {$EXTERNALSYM CMSG_RECIPIENT_INFO_PARAM}
  471.   CMSG_HASH_ALGORITHM_PARAM                    = 20;
  472.   {$EXTERNALSYM CMSG_HASH_ALGORITHM_PARAM}
  473.   CMSG_HASH_DATA_PARAM                         = 21;
  474.   {$EXTERNALSYM CMSG_HASH_DATA_PARAM}
  475.   CMSG_COMPUTED_HASH_PARAM                     = 22;
  476.   {$EXTERNALSYM CMSG_COMPUTED_HASH_PARAM}
  477.   CMSG_ENCRYPT_PARAM                           = 26;
  478.   {$EXTERNALSYM CMSG_ENCRYPT_PARAM}
  479.   CMSG_ENCRYPTED_DIGEST                        = 27;
  480.   {$EXTERNALSYM CMSG_ENCRYPTED_DIGEST}
  481.   CMSG_ENCODED_SIGNER                          = 28;
  482.   {$EXTERNALSYM CMSG_ENCODED_SIGNER}
  483.   CMSG_ENCODED_MESSAGE                         = 29;
  484.   {$EXTERNALSYM CMSG_ENCODED_MESSAGE}
  485.   CMSG_VERSION_PARAM                           = 30;
  486.   {$EXTERNALSYM CMSG_VERSION_PARAM}
  487.   CMSG_ATTR_CERT_COUNT_PARAM                   = 31;
  488.   {$EXTERNALSYM CMSG_ATTR_CERT_COUNT_PARAM}
  489.   CMSG_ATTR_CERT_PARAM                         = 32;
  490.   {$EXTERNALSYM CMSG_ATTR_CERT_PARAM}
  491.   CMSG_CMS_RECIPIENT_COUNT_PARAM               = 33;
  492.   {$EXTERNALSYM CMSG_CMS_RECIPIENT_COUNT_PARAM}
  493.   CMSG_CMS_RECIPIENT_INDEX_PARAM               = 34;
  494.   {$EXTERNALSYM CMSG_CMS_RECIPIENT_INDEX_PARAM}
  495.   CMSG_CMS_RECIPIENT_ENCRYPTED_KEY_INDEX_PARAM = 35;
  496.   {$EXTERNALSYM CMSG_CMS_RECIPIENT_ENCRYPTED_KEY_INDEX_PARAM}
  497.   CMSG_CMS_RECIPIENT_INFO_PARAM                = 36;
  498.   {$EXTERNALSYM CMSG_CMS_RECIPIENT_INFO_PARAM}
  499.   CMSG_UNPROTECTED_ATTR_PARAM                  = 37;
  500.   {$EXTERNALSYM CMSG_UNPROTECTED_ATTR_PARAM}
  501.   CMSG_SIGNER_CERT_ID_PARAM                    = 38;
  502.   {$EXTERNALSYM CMSG_SIGNER_CERT_ID_PARAM}
  503.   CMSG_CMS_SIGNER_INFO_PARAM                   = 39;
  504.   {$EXTERNALSYM CMSG_CMS_SIGNER_INFO_PARAM}
  505. //+-------------------------------------------------------------------------
  506. //  CMSG_TYPE_PARAM
  507. //
  508. //  The type of the decoded message.
  509. //
  510. //  pvData points to a DWORD
  511. //--------------------------------------------------------------------------
  512. //+-------------------------------------------------------------------------
  513. //  CMSG_CONTENT_PARAM
  514. //
  515. //  The encoded content of a cryptographic message. Depending on how the
  516. //  message was opened, the content is either the whole PKCS#7
  517. //  message (opened to encode) or the inner content (opened to decode).
  518. //  In the decode case, the decrypted content is returned, if enveloped.
  519. //  If not enveloped, and if the inner content is of type DATA, the returned
  520. //  data is the contents octets of the inner content.
  521. //
  522. //  pvData points to the buffer receiving the content bytes
  523. //--------------------------------------------------------------------------
  524. //+-------------------------------------------------------------------------
  525. //  CMSG_BARE_CONTENT_PARAM
  526. //
  527. //  The encoded content of an encoded cryptographic message, without the
  528. //  outer layer of ContentInfo. That is, only the encoding of the
  529. //  ContentInfo.content field is returned.
  530. //
  531. //  pvData points to the buffer receiving the content bytes
  532. //--------------------------------------------------------------------------
  533. //+-------------------------------------------------------------------------
  534. //  CMSG_INNER_CONTENT_TYPE_PARAM
  535. //
  536. //  The type of the inner content of a decoded cryptographic message,
  537. //  in the form of a NULL-terminated object identifier string
  538. //  (eg. "1.2.840.113549.1.7.1").
  539. //
  540. //  pvData points to the buffer receiving the object identifier string
  541. //--------------------------------------------------------------------------
  542. //+-------------------------------------------------------------------------
  543. //  CMSG_SIGNER_COUNT_PARAM
  544. //
  545. //  Count of signers in a SIGNED or SIGNED_AND_ENVELOPED message
  546. //
  547. //  pvData points to a DWORD
  548. //--------------------------------------------------------------------------
  549. //+-------------------------------------------------------------------------
  550. //  CMSG_SIGNER_CERT_INFO_PARAM
  551. //
  552. //  To get all the signers, repetitively call CryptMsgGetParam, with
  553. //  dwIndex set to 0 .. SignerCount - 1.
  554. //
  555. //  pvData points to a CERT_INFO struct.
  556. //
  557. //  Only the following fields have been updated in the CERT_INFO struct:
  558. //  Issuer and SerialNumber.
  559. //
  560. //  Note, if the KEYID choice was selected for a CMS SignerId, then, the
  561. //  SerialNumber is 0 and the Issuer is encoded containing a single RDN with a
  562. //  single Attribute whose OID is szOID_KEYID_RDN, value type is
  563. //  CERT_RDN_OCTET_STRING and value is the KEYID. When the
  564. //  CertGetSubjectCertificateFromStore and
  565. //  CertFindCertificateInStore(CERT_FIND_SUBJECT_CERT) APIs see this
  566. //  special KEYID Issuer and SerialNumber, they do a KEYID match.
  567. //--------------------------------------------------------------------------
  568. //+-------------------------------------------------------------------------
  569. //  CMSG_SIGNER_INFO_PARAM
  570. //
  571. //  To get all the signers, repetitively call CryptMsgGetParam, with
  572. //  dwIndex set to 0 .. SignerCount - 1.
  573. //
  574. //  pvData points to a CMSG_SIGNER_INFO struct.
  575. //
  576. //  Note, if the KEYID choice was selected for a CMS SignerId, then, the
  577. //  SerialNumber is 0 and the Issuer is encoded containing a single RDN with a
  578. //  single Attribute whose OID is szOID_KEYID_RDN, value type is
  579. //  CERT_RDN_OCTET_STRING and value is the KEYID. When the
  580. //  CertGetSubjectCertificateFromStore and
  581. //  CertFindCertificateInStore(CERT_FIND_SUBJECT_CERT) APIs see this
  582. //  special KEYID Issuer and SerialNumber, they do a KEYID match.
  583. //--------------------------------------------------------------------------
  584. type
  585.   PCMSG_SIGNER_INFO = ^CMSG_SIGNER_INFO;
  586.   {$EXTERNALSYM PCMSG_SIGNER_INFO}
  587.   _CMSG_SIGNER_INFO = record
  588.     dwVersion: DWORD;
  589.     Issuer: CERT_NAME_BLOB;
  590.     SerialNumber: CRYPT_INTEGER_BLOB;
  591.     HashAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  592.     HashEncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  593.     EncryptedHash: CRYPT_DATA_BLOB;
  594.     AuthAttrs: CRYPT_ATTRIBUTES;
  595.     UnauthAttrs: CRYPT_ATTRIBUTES;
  596.   end;
  597.   {$EXTERNALSYM _CMSG_SIGNER_INFO}
  598.   CMSG_SIGNER_INFO = _CMSG_SIGNER_INFO;
  599.   {$EXTERNALSYM CMSG_SIGNER_INFO}
  600.   TCmsgSignerInfo = CMSG_SIGNER_INFO;
  601.   PCmsgSignerInfo = PCMSG_SIGNER_INFO;
  602. //+-------------------------------------------------------------------------
  603. //  CMSG_SIGNER_CERT_ID_PARAM
  604. //
  605. //  To get all the signers, repetitively call CryptMsgGetParam, with
  606. //  dwIndex set to 0 .. SignerCount - 1.
  607. //
  608. //  pvData points to a CERT_ID struct.
  609. //--------------------------------------------------------------------------
  610. //+-------------------------------------------------------------------------
  611. //  CMSG_CMS_SIGNER_INFO_PARAM
  612. //
  613. //  Same as CMSG_SIGNER_INFO_PARAM, except, contains SignerId instead of
  614. //  Issuer and SerialNumber.
  615. //
  616. //  To get all the signers, repetitively call CryptMsgGetParam, with
  617. //  dwIndex set to 0 .. SignerCount - 1.
  618. //
  619. //  pvData points to a CMSG_CMS_SIGNER_INFO struct.
  620. //--------------------------------------------------------------------------
  621.   PCMSG_CMS_SIGNER_INFO = ^CMSG_CMS_SIGNER_INFO;
  622.   {$EXTERNALSYM PCMSG_CMS_SIGNER_INFO}
  623.   _CMSG_CMS_SIGNER_INFO = record
  624.     dwVersion: DWORD;
  625.     SignerId: CERT_ID;
  626.     HashAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  627.     HashEncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  628.     EncryptedHash: CRYPT_DATA_BLOB;
  629.     AuthAttrs: CRYPT_ATTRIBUTES;
  630.     UnauthAttrs: CRYPT_ATTRIBUTES;
  631.   end;
  632.   {$EXTERNALSYM _CMSG_CMS_SIGNER_INFO}
  633.   CMSG_CMS_SIGNER_INFO = _CMSG_CMS_SIGNER_INFO;
  634.   {$EXTERNALSYM CMSG_CMS_SIGNER_INFO}
  635.   TCmsgCmsSignerInfo = CMSG_CMS_SIGNER_INFO;
  636.   PCmsgCmsSignerInfo = PCMSG_CMS_SIGNER_INFO;
  637. //+-------------------------------------------------------------------------
  638. //  CMSG_SIGNER_HASH_ALGORITHM_PARAM
  639. //
  640. //  This parameter specifies the HashAlgorithm that was used for the signer.
  641. //
  642. //  Set dwIndex to iterate through all the signers.
  643. //
  644. //  pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  645. //--------------------------------------------------------------------------
  646. //+-------------------------------------------------------------------------
  647. //  CMSG_SIGNER_AUTH_ATTR_PARAM
  648. //
  649. //  The authenticated attributes for the signer.
  650. //
  651. //  Set dwIndex to iterate through all the signers.
  652. //
  653. //  pvData points to a CMSG_ATTR struct.
  654. //--------------------------------------------------------------------------
  655.   CMSG_ATTR = CRYPT_ATTRIBUTES;
  656.   {$EXTERNALSYM CMSG_ATTR}
  657.   PCMSG_ATTR = ^CRYPT_ATTRIBUTES;
  658.   {$EXTERNALSYM PCMSG_ATTR}
  659. //+-------------------------------------------------------------------------
  660. //  CMSG_SIGNER_UNAUTH_ATTR_PARAM
  661. //
  662. //  The unauthenticated attributes for the signer.
  663. //
  664. //  Set dwIndex to iterate through all the signers.
  665. //
  666. //  pvData points to a CMSG_ATTR struct.
  667. //--------------------------------------------------------------------------
  668. //+-------------------------------------------------------------------------
  669. //  CMSG_CERT_COUNT_PARAM
  670. //
  671. //  Count of certificates in a SIGNED or SIGNED_AND_ENVELOPED message.
  672. //
  673. //  CMS, also supports certificates in an ENVELOPED message.
  674. //
  675. //  pvData points to a DWORD
  676. //--------------------------------------------------------------------------
  677. //+-------------------------------------------------------------------------
  678. //  CMSG_CERT_PARAM
  679. //
  680. //  To get all the certificates, repetitively call CryptMsgGetParam, with
  681. //  dwIndex set to 0 .. CertCount - 1.
  682. //
  683. //  pvData points to an array of the certificate's encoded bytes.
  684. //--------------------------------------------------------------------------
  685. //+-------------------------------------------------------------------------
  686. //  CMSG_CRL_COUNT_PARAM
  687. //
  688. //  Count of CRLs in a SIGNED or SIGNED_AND_ENVELOPED message.
  689. //
  690. //  CMS, also supports CRLs in an ENVELOPED message.
  691. //
  692. //  pvData points to a DWORD
  693. //--------------------------------------------------------------------------
  694. //+-------------------------------------------------------------------------
  695. //  CMSG_CRL_PARAM
  696. //
  697. //  To get all the CRLs, repetitively call CryptMsgGetParam, with
  698. //  dwIndex set to 0 .. CrlCount - 1.
  699. //
  700. //  pvData points to an array of the CRL's encoded bytes.
  701. //--------------------------------------------------------------------------
  702. //+-------------------------------------------------------------------------
  703. //  CMSG_ENVELOPE_ALGORITHM_PARAM
  704. //
  705. //  The ContentEncryptionAlgorithm that was used in
  706. //  an ENVELOPED or SIGNED_AND_ENVELOPED message.
  707. //
  708. //  For streaming you must be able to successfully get this parameter before
  709. //  doing a CryptMsgControl decrypt.
  710. //
  711. //  pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  712. //--------------------------------------------------------------------------
  713. //+-------------------------------------------------------------------------
  714. //  CMSG_RECIPIENT_COUNT_PARAM
  715. //
  716. //  Count of recipients in an ENVELOPED or SIGNED_AND_ENVELOPED message.
  717. //
  718. //  Count of key transport recepients.
  719. //
  720. //  The CMSG_CMS_RECIPIENT_COUNT_PARAM has the total count of
  721. //  recipients (it also includes key agree and mail list recipients).
  722. //
  723. //  pvData points to a DWORD
  724. //--------------------------------------------------------------------------
  725. //+-------------------------------------------------------------------------
  726. //  CMSG_RECIPIENT_INDEX_PARAM
  727. //
  728. //  Index of the recipient used to decrypt an ENVELOPED or SIGNED_AND_ENVELOPED
  729. //  message.
  730. //
  731. //  Index of a key transport recipient. If a non key transport
  732. //  recipient was used to decrypt, fails with LastError set to
  733. //  CRYPT_E_INVALID_INDEX.
  734. //
  735. //  pvData points to a DWORD
  736. //--------------------------------------------------------------------------
  737. //+-------------------------------------------------------------------------
  738. //  CMSG_RECIPIENT_INFO_PARAM
  739. //
  740. //  To get all the recipients, repetitively call CryptMsgGetParam, with
  741. //  dwIndex set to 0 .. RecipientCount - 1.
  742. //
  743. //  Only returns the key transport recepients.
  744. //
  745. //  The CMSG_CMS_RECIPIENT_INFO_PARAM returns all recipients.
  746. //
  747. //  pvData points to a CERT_INFO struct.
  748. //
  749. //  Only the following fields have been updated in the CERT_INFO struct:
  750. //  Issuer, SerialNumber and PublicKeyAlgorithm. The PublicKeyAlgorithm
  751. //  specifies the KeyEncryptionAlgorithm that was used.
  752. //
  753. //  Note, if the KEYID choice was selected for a key transport recipient, then,
  754. //  the SerialNumber is 0 and the Issuer is encoded containing a single RDN
  755. //  with a single Attribute whose OID is szOID_KEYID_RDN, value type is
  756. //  CERT_RDN_OCTET_STRING and value is the KEYID. When the
  757. //  CertGetSubjectCertificateFromStore and
  758. //  CertFindCertificateInStore(CERT_FIND_SUBJECT_CERT) APIs see this
  759. //  special KEYID Issuer and SerialNumber, they do a KEYID match.
  760. //--------------------------------------------------------------------------
  761. //+-------------------------------------------------------------------------
  762. //  CMSG_HASH_ALGORITHM_PARAM
  763. //
  764. //  The HashAlgorithm in a HASHED message.
  765. //
  766. //  pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  767. //--------------------------------------------------------------------------
  768. //+-------------------------------------------------------------------------
  769. //  CMSG_HASH_DATA_PARAM
  770. //
  771. //  The hash in a HASHED message.
  772. //
  773. //  pvData points to an array of bytes.
  774. //--------------------------------------------------------------------------
  775. //+-------------------------------------------------------------------------
  776. //  CMSG_COMPUTED_HASH_PARAM
  777. //
  778. //  The computed hash for a HASHED message.
  779. //  This may be called for either an encoded or decoded message.
  780. //
  781. //  Also, the computed hash for one of the signer's in a SIGNED message.
  782. //  It may be called for either an encoded or decoded message after the
  783. //  final update.  Set dwIndex to iterate through all the signers.
  784. //
  785. //  pvData points to an array of bytes.
  786. //--------------------------------------------------------------------------
  787. //+-------------------------------------------------------------------------
  788. //  CMSG_ENCRYPT_PARAM
  789. //
  790. //  The ContentEncryptionAlgorithm that was used in an ENCRYPTED message.
  791. //
  792. //  pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  793. //--------------------------------------------------------------------------
  794. //+-------------------------------------------------------------------------
  795. //  CMSG_ENCODED_MESSAGE
  796. //
  797. //  The full encoded message. This is useful in the case of a decoded
  798. //  message which has been modified (eg. a signed-data or
  799. //  signed-and-enveloped-data message which has been countersigned).
  800. //
  801. //  pvData points to an array of the message's encoded bytes.
  802. //--------------------------------------------------------------------------
  803. //+-------------------------------------------------------------------------
  804. //  CMSG_VERSION_PARAM
  805. //
  806. //  The version of the decoded message.
  807. //
  808. //  pvData points to a DWORD
  809. //--------------------------------------------------------------------------
  810. const
  811.   CMSG_SIGNED_DATA_V1               = 1;
  812.   {$EXTERNALSYM CMSG_SIGNED_DATA_V1}
  813.   CMSG_SIGNED_DATA_V3               = 3;
  814.   {$EXTERNALSYM CMSG_SIGNED_DATA_V3}
  815.   CMSG_SIGNED_DATA_PKCS_1_5_VERSION = CMSG_SIGNED_DATA_V1;
  816.   {$EXTERNALSYM CMSG_SIGNED_DATA_PKCS_1_5_VERSION}
  817.   CMSG_SIGNED_DATA_CMS_VERSION      = CMSG_SIGNED_DATA_V3;
  818.   {$EXTERNALSYM CMSG_SIGNED_DATA_CMS_VERSION}
  819.   CMSG_SIGNER_INFO_V1               = 1;
  820.   {$EXTERNALSYM CMSG_SIGNER_INFO_V1}
  821.   CMSG_SIGNER_INFO_V3               = 3;
  822.   {$EXTERNALSYM CMSG_SIGNER_INFO_V3}
  823.   CMSG_SIGNER_INFO_PKCS_1_5_VERSION = CMSG_SIGNER_INFO_V1;
  824.   {$EXTERNALSYM CMSG_SIGNER_INFO_PKCS_1_5_VERSION}
  825.   CMSG_SIGNER_INFO_CMS_VERSION      = CMSG_SIGNER_INFO_V3;
  826.   {$EXTERNALSYM CMSG_SIGNER_INFO_CMS_VERSION}
  827.   CMSG_HASHED_DATA_V0               = 0;
  828.   {$EXTERNALSYM CMSG_HASHED_DATA_V0}
  829.   CMSG_HASHED_DATA_V2               = 2;
  830.   {$EXTERNALSYM CMSG_HASHED_DATA_V2}
  831.   CMSG_HASHED_DATA_PKCS_1_5_VERSION = CMSG_HASHED_DATA_V0;
  832.   {$EXTERNALSYM CMSG_HASHED_DATA_PKCS_1_5_VERSION}
  833.   CMSG_HASHED_DATA_CMS_VERSION      = CMSG_HASHED_DATA_V2;
  834.   {$EXTERNALSYM CMSG_HASHED_DATA_CMS_VERSION}
  835.   CMSG_ENVELOPED_DATA_V0               = 0;
  836.   {$EXTERNALSYM CMSG_ENVELOPED_DATA_V0}
  837.   CMSG_ENVELOPED_DATA_V2               = 2;
  838.   {$EXTERNALSYM CMSG_ENVELOPED_DATA_V2}
  839.   CMSG_ENVELOPED_DATA_PKCS_1_5_VERSION = CMSG_ENVELOPED_DATA_V0;
  840.   {$EXTERNALSYM CMSG_ENVELOPED_DATA_PKCS_1_5_VERSION}
  841.   CMSG_ENVELOPED_DATA_CMS_VERSION      = CMSG_ENVELOPED_DATA_V2;
  842.   {$EXTERNALSYM CMSG_ENVELOPED_DATA_CMS_VERSION}
  843. //+-------------------------------------------------------------------------
  844. //  CMSG_ATTR_CERT_COUNT_PARAM
  845. //
  846. //  Count of attribute certificates in a SIGNED or ENVELOPED message.
  847. //
  848. //  pvData points to a DWORD
  849. //--------------------------------------------------------------------------
  850. //+-------------------------------------------------------------------------
  851. //  CMSG_ATTR_CERT_PARAM
  852. //
  853. //  To get all the attribute certificates, repetitively call CryptMsgGetParam,
  854. //  with dwIndex set to 0 .. AttrCertCount - 1.
  855. //
  856. //  pvData points to an array of the attribute certificate's encoded bytes.
  857. //--------------------------------------------------------------------------
  858. //+-------------------------------------------------------------------------
  859. //  CMSG_CMS_RECIPIENT_COUNT_PARAM
  860. //
  861. //  Count of all CMS recipients in an ENVELOPED message.
  862. //
  863. //  pvData points to a DWORD
  864. //--------------------------------------------------------------------------
  865. //+-------------------------------------------------------------------------
  866. //  CMSG_CMS_RECIPIENT_INDEX_PARAM
  867. //
  868. //  Index of the CMS recipient used to decrypt an ENVELOPED message.
  869. //
  870. //  pvData points to a DWORD
  871. //--------------------------------------------------------------------------
  872. //+-------------------------------------------------------------------------
  873. //  CMSG_CMS_RECIPIENT_ENCRYPTED_KEY_INDEX_PARAM
  874. //
  875. //  For a CMS key agreement recipient, the index of the encrypted key
  876. //  used to decrypt an ENVELOPED message.
  877. //
  878. //  pvData points to a DWORD
  879. //--------------------------------------------------------------------------
  880. //+-------------------------------------------------------------------------
  881. //  CMSG_CMS_RECIPIENT_INFO_PARAM
  882. //
  883. //  To get all the CMS recipients, repetitively call CryptMsgGetParam, with
  884. //  dwIndex set to 0 .. CmsRecipientCount - 1.
  885. //
  886. //  pvData points to a CMSG_CMS_RECIPIENT_INFO struct.
  887. //--------------------------------------------------------------------------
  888. type
  889.   PCMSG_KEY_TRANS_RECIPIENT_INFO = ^CMSG_KEY_TRANS_RECIPIENT_INFO;
  890.   {$EXTERNALSYM PCMSG_KEY_TRANS_RECIPIENT_INFO}
  891.   _CMSG_KEY_TRANS_RECIPIENT_INFO = record
  892.     dwVersion: DWORD;
  893.     // Currently, only ISSUER_SERIAL_NUMBER or KEYID choices
  894.     RecipientId: CERT_ID;
  895.     KeyEncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  896.     EncryptedKey: CRYPT_DATA_BLOB;
  897.   end;
  898.   {$EXTERNALSYM _CMSG_KEY_TRANS_RECIPIENT_INFO}
  899.   CMSG_KEY_TRANS_RECIPIENT_INFO = _CMSG_KEY_TRANS_RECIPIENT_INFO;
  900.   {$EXTERNALSYM CMSG_KEY_TRANS_RECIPIENT_INFO}
  901.   TCmsgKeyTransRecipientInfo = CMSG_KEY_TRANS_RECIPIENT_INFO;
  902.   PCmsgKeyTransRecipientInfo = PCMSG_KEY_TRANS_RECIPIENT_INFO;
  903.   PCMSG_RECIPIENT_ENCRYPTED_KEY_INFO = ^CMSG_RECIPIENT_ENCRYPTED_KEY_INFO;
  904.   {$EXTERNALSYM PCMSG_RECIPIENT_ENCRYPTED_KEY_INFO}
  905.   _CMSG_RECIPIENT_ENCRYPTED_KEY_INFO = record
  906.     // Currently, only ISSUER_SERIAL_NUMBER or KEYID choices
  907.     RecipientId: CERT_ID;
  908.     EncryptedKey: CRYPT_DATA_BLOB;
  909.     // The following optional fields are only applicable to KEYID choice
  910.     Date: FILETIME;
  911.     pOtherAttr: PCRYPT_ATTRIBUTE_TYPE_VALUE;
  912.   end;
  913.   {$EXTERNALSYM _CMSG_RECIPIENT_ENCRYPTED_KEY_INFO}
  914.   CMSG_RECIPIENT_ENCRYPTED_KEY_INFO = _CMSG_RECIPIENT_ENCRYPTED_KEY_INFO;
  915.   {$EXTERNALSYM CMSG_RECIPIENT_ENCRYPTED_KEY_INFO}
  916.   TCmsgRecipientEncryptedKeyInfo = CMSG_RECIPIENT_ENCRYPTED_KEY_INFO;
  917.   PCmsgRecipientEncryptedKeyInfo = PCMSG_RECIPIENT_ENCRYPTED_KEY_INFO;
  918.   PCMSG_KEY_AGREE_RECIPIENT_INFO = ^CMSG_KEY_AGREE_RECIPIENT_INFO;
  919.   {$EXTERNALSYM PCMSG_KEY_AGREE_RECIPIENT_INFO}
  920.   _CMSG_KEY_AGREE_RECIPIENT_INFO = record
  921.     dwVersion: DWORD;
  922.     dwOriginatorChoice: DWORD;
  923.     Union: record
  924.     case Integer of
  925.       // CMSG_KEY_AGREE_ORIGINATOR_CERT
  926.       0: (OriginatorCertId: CERT_ID);
  927.       // CMSG_KEY_AGREE_ORIGINATOR_PUBLIC_KEY
  928.       1: (OriginatorPublicKeyInfo: CERT_PUBLIC_KEY_INFO);
  929.     end;
  930.     UserKeyingMaterial: CRYPT_DATA_BLOB;
  931.     KeyEncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  932.     cRecipientEncryptedKeys: DWORD;
  933.     rgpRecipientEncryptedKeys: PCMSG_RECIPIENT_ENCRYPTED_KEY_INFO;
  934.   end;
  935.   {$EXTERNALSYM _CMSG_KEY_AGREE_RECIPIENT_INFO}
  936.   CMSG_KEY_AGREE_RECIPIENT_INFO = _CMSG_KEY_AGREE_RECIPIENT_INFO;
  937.   {$EXTERNALSYM CMSG_KEY_AGREE_RECIPIENT_INFO}
  938.   TCmsgKeyAgreeRecipientInfo = CMSG_KEY_AGREE_RECIPIENT_INFO;
  939.   PCmsgKeyAgreeRecipientInfo = PCMSG_KEY_AGREE_RECIPIENT_INFO;
  940. const
  941.   CMSG_KEY_AGREE_ORIGINATOR_CERT       = 1;
  942.   {$EXTERNALSYM CMSG_KEY_AGREE_ORIGINATOR_CERT}
  943.   CMSG_KEY_AGREE_ORIGINATOR_PUBLIC_KEY = 2;
  944.   {$EXTERNALSYM CMSG_KEY_AGREE_ORIGINATOR_PUBLIC_KEY}
  945. type
  946.   PCMSG_MAIL_LIST_RECIPIENT_INFO = ^CMSG_MAIL_LIST_RECIPIENT_INFO;
  947.   {$EXTERNALSYM PCMSG_MAIL_LIST_RECIPIENT_INFO}
  948.   _CMSG_MAIL_LIST_RECIPIENT_INFO = record
  949.     dwVersion: DWORD;
  950.     KeyId: CRYPT_DATA_BLOB;
  951.     KeyEncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  952.     EncryptedKey: CRYPT_DATA_BLOB;
  953.     // The following fields are optional
  954.     Date: FILETIME;
  955.     pOtherAttr: PCRYPT_ATTRIBUTE_TYPE_VALUE;
  956.   end;
  957.   {$EXTERNALSYM _CMSG_MAIL_LIST_RECIPIENT_INFO}
  958.   CMSG_MAIL_LIST_RECIPIENT_INFO = _CMSG_MAIL_LIST_RECIPIENT_INFO;
  959.   {$EXTERNALSYM CMSG_MAIL_LIST_RECIPIENT_INFO}
  960.   TCmsgMailListRecipientInfo = CMSG_MAIL_LIST_RECIPIENT_INFO;
  961.   PCmsgMailListRecipientInfo = PCMSG_MAIL_LIST_RECIPIENT_INFO;
  962.   PCMSG_CMS_RECIPIENT_INFO = ^CMSG_CMS_RECIPIENT_INFO;
  963.   {$EXTERNALSYM PCMSG_CMS_RECIPIENT_INFO}
  964.   _CMSG_CMS_RECIPIENT_INFO = record
  965.     dwRecipientChoice: DWORD;
  966.     case Integer of
  967.       // CMSG_KEY_TRANS_RECIPIENT
  968.       0: (pKeyTrans: PCMSG_KEY_TRANS_RECIPIENT_INFO);
  969.       // CMSG_KEY_AGREE_RECIPIENT
  970.       1: (pKeyAgree: PCMSG_KEY_AGREE_RECIPIENT_INFO);
  971.       // CMSG_MAIL_LIST_RECIPIENT
  972.       2: (pMailList: PCMSG_MAIL_LIST_RECIPIENT_INFO);
  973.   end;
  974.   {$EXTERNALSYM _CMSG_CMS_RECIPIENT_INFO}
  975.   CMSG_CMS_RECIPIENT_INFO = _CMSG_CMS_RECIPIENT_INFO;
  976.   {$EXTERNALSYM CMSG_CMS_RECIPIENT_INFO}
  977.   TCmsgCmsRecipientInfo = CMSG_CMS_RECIPIENT_INFO;
  978.   PCmsgCmsRecipientInfo = PCMSG_CMS_RECIPIENT_INFO;
  979. // dwVersion numbers for the KeyTrans, KeyAgree and MailList recipients
  980. const
  981.   CMSG_ENVELOPED_RECIPIENT_V0     = 0;
  982.   {$EXTERNALSYM CMSG_ENVELOPED_RECIPIENT_V0}
  983.   CMSG_ENVELOPED_RECIPIENT_V2     = 2;
  984.   {$EXTERNALSYM CMSG_ENVELOPED_RECIPIENT_V2}
  985.   CMSG_ENVELOPED_RECIPIENT_V3     = 3;
  986.   {$EXTERNALSYM CMSG_ENVELOPED_RECIPIENT_V3}
  987.   CMSG_ENVELOPED_RECIPIENT_V4     = 4;
  988.   {$EXTERNALSYM CMSG_ENVELOPED_RECIPIENT_V4}
  989.   CMSG_KEY_TRANS_PKCS_1_5_VERSION = CMSG_ENVELOPED_RECIPIENT_V0;
  990.   {$EXTERNALSYM CMSG_KEY_TRANS_PKCS_1_5_VERSION}
  991.   CMSG_KEY_TRANS_CMS_VERSION      = CMSG_ENVELOPED_RECIPIENT_V2;
  992.   {$EXTERNALSYM CMSG_KEY_TRANS_CMS_VERSION}
  993.   CMSG_KEY_AGREE_VERSION          = CMSG_ENVELOPED_RECIPIENT_V3;
  994.   {$EXTERNALSYM CMSG_KEY_AGREE_VERSION}
  995.   CMSG_MAIL_LIST_VERSION          = CMSG_ENVELOPED_RECIPIENT_V4;
  996.   {$EXTERNALSYM CMSG_MAIL_LIST_VERSION}
  997. //+-------------------------------------------------------------------------
  998. //  CMSG_UNPROTECTED_ATTR_PARAM
  999. //
  1000. //  The unprotected attributes in the envelped message.
  1001. //
  1002. //  pvData points to a CMSG_ATTR struct.
  1003. //--------------------------------------------------------------------------
  1004. //+-------------------------------------------------------------------------
  1005. //  Perform a special "control" function after the final CryptMsgUpdate of a
  1006. //  encoded/decoded cryptographic message.
  1007. //
  1008. //  The dwCtrlType parameter specifies the type of operation to be performed.
  1009. //
  1010. //  The pvCtrlPara definition depends on the dwCtrlType value.
  1011. //
  1012. //  See below for a list of the control operations and their pvCtrlPara
  1013. //  type definition.
  1014. //--------------------------------------------------------------------------
  1015. function CryptMsgControl(hCryptMsg: HCRYPTMSG; dwFlags, dwCtrlType: DWORD;
  1016.   pvCtrlPara: Pointer): BOOL; stdcall;
  1017. {$EXTERNALSYM CryptMsgControl}
  1018. //+-------------------------------------------------------------------------
  1019. //  Message control types
  1020. //--------------------------------------------------------------------------
  1021. const
  1022.   CMSG_CTRL_VERIFY_SIGNATURE       = 1;
  1023.   {$EXTERNALSYM CMSG_CTRL_VERIFY_SIGNATURE}
  1024.   CMSG_CTRL_DECRYPT                = 2;
  1025.   {$EXTERNALSYM CMSG_CTRL_DECRYPT}
  1026.   CMSG_CTRL_VERIFY_HASH            = 5;
  1027.   {$EXTERNALSYM CMSG_CTRL_VERIFY_HASH}
  1028.   CMSG_CTRL_ADD_SIGNER             = 6;
  1029.   {$EXTERNALSYM CMSG_CTRL_ADD_SIGNER}
  1030.   CMSG_CTRL_DEL_SIGNER             = 7;
  1031.   {$EXTERNALSYM CMSG_CTRL_DEL_SIGNER}
  1032.   CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR = 8;
  1033.   {$EXTERNALSYM CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR}
  1034.   CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR = 9;
  1035.   {$EXTERNALSYM CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR}
  1036.   CMSG_CTRL_ADD_CERT               = 10;
  1037.   {$EXTERNALSYM CMSG_CTRL_ADD_CERT}
  1038.   CMSG_CTRL_DEL_CERT               = 11;
  1039.   {$EXTERNALSYM CMSG_CTRL_DEL_CERT}
  1040.   CMSG_CTRL_ADD_CRL                = 12;
  1041.   {$EXTERNALSYM CMSG_CTRL_ADD_CRL}
  1042.   CMSG_CTRL_DEL_CRL                = 13;
  1043.   {$EXTERNALSYM CMSG_CTRL_DEL_CRL}
  1044.   CMSG_CTRL_ADD_ATTR_CERT          = 14;
  1045.   {$EXTERNALSYM CMSG_CTRL_ADD_ATTR_CERT}
  1046.   CMSG_CTRL_DEL_ATTR_CERT          = 15;
  1047.   {$EXTERNALSYM CMSG_CTRL_DEL_ATTR_CERT}
  1048.   CMSG_CTRL_KEY_TRANS_DECRYPT      = 16;
  1049.   {$EXTERNALSYM CMSG_CTRL_KEY_TRANS_DECRYPT}
  1050.   CMSG_CTRL_KEY_AGREE_DECRYPT      = 17;
  1051.   {$EXTERNALSYM CMSG_CTRL_KEY_AGREE_DECRYPT}
  1052.   CMSG_CTRL_MAIL_LIST_DECRYPT      = 18;
  1053.   {$EXTERNALSYM CMSG_CTRL_MAIL_LIST_DECRYPT}
  1054.   CMSG_CTRL_VERIFY_SIGNATURE_EX    = 19;
  1055.   {$EXTERNALSYM CMSG_CTRL_VERIFY_SIGNATURE_EX}
  1056.   CMSG_CTRL_ADD_CMS_SIGNER_INFO    = 20;
  1057.   {$EXTERNALSYM CMSG_CTRL_ADD_CMS_SIGNER_INFO}
  1058. //+-------------------------------------------------------------------------
  1059. //  CMSG_CTRL_VERIFY_SIGNATURE
  1060. //
  1061. //  Verify the signature of a SIGNED or SIGNED_AND_ENVELOPED
  1062. //  message after it has been decoded.
  1063. //
  1064. //  For a SIGNED_AND_ENVELOPED message, called after
  1065. //  CryptMsgControl(CMSG_CTRL_DECRYPT), if CryptMsgOpenToDecode was called
  1066. //  with a NULL pRecipientInfo.
  1067. //
  1068. //  pvCtrlPara points to a CERT_INFO struct.
  1069. //
  1070. //  The CERT_INFO contains the Issuer and SerialNumber identifying
  1071. //  the Signer of the message. The CERT_INFO also contains the
  1072. //  PublicKeyInfo
  1073. //  used to verify the signature. The cryptographic provider specified
  1074. //  in CryptMsgOpenToDecode is used.
  1075. //
  1076. //  Note, if the message contains CMS signers identified by KEYID, then,
  1077. //  the CERT_INFO's Issuer and SerialNumber is ignored and only the public
  1078. //  key is used to find a signer whose signature verifies.
  1079. //
  1080. //  The following CMSG_CTRL_VERIFY_SIGNATURE_EX should be used instead.
  1081. //--------------------------------------------------------------------------
  1082. //+-------------------------------------------------------------------------
  1083. //  CMSG_CTRL_VERIFY_SIGNATURE_EX
  1084. //
  1085. //  Verify the signature of a SIGNED message after it has been decoded.
  1086. //
  1087. //  pvCtrlPara points to the following CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA.
  1088. //
  1089. //  If hCryptProv is NULL, uses the cryptographic provider specified in
  1090. //  CryptMsgOpenToDecode. If CryptMsgOpenToDecode's hCryptProv is also NULL,
  1091. //  gets default provider according to the signer's public key OID.
  1092. //
  1093. //  dwSignerIndex is the index of the signer to use to verify the signature.
  1094. //
  1095. //  The signer can be a pointer to a CERT_PUBLIC_KEY_INFO, certificate
  1096. //  context or a chain context.
  1097. //--------------------------------------------------------------------------
  1098. type
  1099.   PCMSG_CTRL_VERIFY_SIGNATURE_EX_PARA = ^CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA;
  1100.   {$EXTERNALSYM PCMSG_CTRL_VERIFY_SIGNATURE_EX_PARA}
  1101.   _CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA = record
  1102.     cbSize: DWORD;
  1103.     hCryptProv: HCRYPTPROV;
  1104.     dwSignerIndex: DWORD;
  1105.     dwSignerType: DWORD;
  1106.     pvSigner: Pointer;
  1107.   end;
  1108.   {$EXTERNALSYM _CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA}
  1109.   CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA = _CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA;
  1110.   {$EXTERNALSYM CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA}
  1111.   TCmsgCtrlVerifySignatureExPara = CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA;
  1112.   PCmsgCtrlVerifySignatureExPara = PCMSG_CTRL_VERIFY_SIGNATURE_EX_PARA;
  1113. // Signer Types
  1114. const
  1115.   CMSG_VERIFY_SIGNER_PUBKEY = 1;
  1116.   {$EXTERNALSYM CMSG_VERIFY_SIGNER_PUBKEY}
  1117.   // pvSigner :: PCERT_PUBLIC_KEY_INFO
  1118.   CMSG_VERIFY_SIGNER_CERT = 2;
  1119.   {$EXTERNALSYM CMSG_VERIFY_SIGNER_CERT}
  1120.   // pvSigner :: PCCERT_CONTEXT
  1121.   CMSG_VERIFY_SIGNER_CHAIN = 3;
  1122.   {$EXTERNALSYM CMSG_VERIFY_SIGNER_CHAIN}
  1123.   // pvSigner :: PCCERT_CHAIN_CONTEXT
  1124. //+-------------------------------------------------------------------------
  1125. //  CMSG_CTRL_DECRYPT
  1126. //
  1127. //  Decrypt an ENVELOPED or SIGNED_AND_ENVELOPED message after it has been
  1128. //  decoded.
  1129. //
  1130. //  This decrypt is only applicable to key transport recipients.
  1131. //
  1132. //  hCryptProv and dwKeySpec specify the private key to use. For dwKeySpec ==
  1133. //  0, defaults to AT_KEYEXCHANGE.
  1134. //
  1135. //  If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags passed
  1136. //  to CryptMsgControl, then, the hCryptProv is released on the final
  1137. //  CryptMsgClose. Not released if CryptMsgControl fails.
  1138. //
  1139. //  dwRecipientIndex is the index of the recipient in the message associated
  1140. //  with the hCryptProv's private key.
  1141. //
  1142. //  The dwRecipientIndex is the index of a key transport recipient.
  1143. //
  1144. //  Note, the message can only be decrypted once.
  1145. //--------------------------------------------------------------------------
  1146. type
  1147.   PCMSG_CTRL_DECRYPT_PARA = ^CMSG_CTRL_DECRYPT_PARA;
  1148.   {$EXTERNALSYM PCMSG_CTRL_DECRYPT_PARA}
  1149.   _CMSG_CTRL_DECRYPT_PARA = record
  1150.     cbSize: DWORD;
  1151.     hCryptProv: HCRYPTPROV;
  1152.     dwKeySpec: DWORD;
  1153.     dwRecipientIndex: DWORD;
  1154.   end;
  1155.   {$EXTERNALSYM _CMSG_CTRL_DECRYPT_PARA}
  1156.   CMSG_CTRL_DECRYPT_PARA = _CMSG_CTRL_DECRYPT_PARA;
  1157.   {$EXTERNALSYM CMSG_CTRL_DECRYPT_PARA}
  1158.   TCmsgCtrlDecryptPara = CMSG_CTRL_DECRYPT_PARA;
  1159.   PCmsgCtrlDecryptPara = PCMSG_CTRL_DECRYPT_PARA;
  1160. //+-------------------------------------------------------------------------
  1161. //  CMSG_CTRL_KEY_TRANS_DECRYPT
  1162. //
  1163. //  Decrypt an ENVELOPED message after it has been decoded for a key
  1164. //  transport recipient.
  1165. //
  1166. //  hCryptProv and dwKeySpec specify the private key to use. For dwKeySpec ==
  1167. //  0, defaults to AT_KEYEXCHANGE.
  1168. //
  1169. //  If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags passed
  1170. //  to CryptMsgControl, then, the hCryptProv is released on the final
  1171. //  CryptMsgClose. Not released if CryptMsgControl fails.
  1172. //
  1173. //  pKeyTrans points to the CMSG_KEY_TRANS_RECIPIENT_INFO obtained via
  1174. //  CryptMsgGetParam(CMSG_CMS_RECIPIENT_INFO_PARAM)
  1175. //
  1176. //  dwRecipientIndex is the index of the recipient in the message associated
  1177. //  with the hCryptProv's private key.
  1178. //
  1179. //  Note, the message can only be decrypted once.
  1180. //--------------------------------------------------------------------------
  1181.   PCMSG_CTRL_KEY_TRANS_DECRYPT_PARA = ^CMSG_CTRL_KEY_TRANS_DECRYPT_PARA;
  1182.   {$EXTERNALSYM PCMSG_CTRL_KEY_TRANS_DECRYPT_PARA}
  1183.   _CMSG_CTRL_KEY_TRANS_DECRYPT_PARA = record
  1184.     cbSize: DWORD;
  1185.     hCryptProv: HCRYPTPROV;
  1186.     dwKeySpec: DWORD;
  1187.     pKeyTrans: PCMSG_KEY_TRANS_RECIPIENT_INFO;
  1188.     dwRecipientIndex: DWORD;
  1189.   end;
  1190.   {$EXTERNALSYM _CMSG_CTRL_KEY_TRANS_DECRYPT_PARA}
  1191.   CMSG_CTRL_KEY_TRANS_DECRYPT_PARA = _CMSG_CTRL_KEY_TRANS_DECRYPT_PARA;
  1192.   {$EXTERNALSYM CMSG_CTRL_KEY_TRANS_DECRYPT_PARA}
  1193.   TCmsgCtrlKeyTransDecryptPara = CMSG_CTRL_KEY_TRANS_DECRYPT_PARA;
  1194.   PCmsgCtrlKeyTransDecryptPara = PCMSG_CTRL_KEY_TRANS_DECRYPT_PARA;
  1195. //+-------------------------------------------------------------------------
  1196. //  CMSG_CTRL_KEY_AGREE_DECRYPT
  1197. //
  1198. //  Decrypt an ENVELOPED message after it has been decoded for a key
  1199. //  agreement recipient.
  1200. //
  1201. //  hCryptProv and dwKeySpec specify the private key to use. For dwKeySpec ==
  1202. //  0, defaults to AT_KEYEXCHANGE.
  1203. //
  1204. //  If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags passed
  1205. //  to CryptMsgControl, then, the hCryptProv is released on the final
  1206. //  CryptMsgClose. Not released if CryptMsgControl fails.
  1207. //
  1208. //  pKeyAgree points to the CMSG_KEY_AGREE_RECIPIENT_INFO obtained via
  1209. //  CryptMsgGetParam(CMSG_CMS_RECIPIENT_INFO_PARAM) for dwRecipientIndex.
  1210. //
  1211. //  dwRecipientIndex, dwRecipientEncryptedKeyIndex are the indices of the
  1212. //  recipient's encrypted key in the message associated with the hCryptProv's
  1213. //  private key.
  1214. //
  1215. //  OriginatorPublicKey is the originator's public key obtained from either
  1216. //  the originator's certificate or the CMSG_KEY_AGREE_RECIPIENT_INFO obtained
  1217. //  via the CMSG_CMS_RECIPIENT_INFO_PARAM.
  1218. //
  1219. //  Note, the message can only be decrypted once.
  1220. //--------------------------------------------------------------------------
  1221.   PCMSG_CTRL_KEY_AGREE_DECRYPT_PARA = ^CMSG_CTRL_KEY_AGREE_DECRYPT_PARA;
  1222.   {$EXTERNALSYM PCMSG_CTRL_KEY_AGREE_DECRYPT_PARA}
  1223.   _CMSG_CTRL_KEY_AGREE_DECRYPT_PARA = record
  1224.     cbSize: DWORD;
  1225.     hCryptProv: HCRYPTPROV;
  1226.     dwKeySpec: DWORD;
  1227.     pKeyAgree: PCMSG_KEY_AGREE_RECIPIENT_INFO;
  1228.     dwRecipientIndex: DWORD;
  1229.     dwRecipientEncryptedKeyIndex: DWORD;
  1230.     OriginatorPublicKey: CRYPT_BIT_BLOB;
  1231.   end;
  1232.   {$EXTERNALSYM _CMSG_CTRL_KEY_AGREE_DECRYPT_PARA}
  1233.   CMSG_CTRL_KEY_AGREE_DECRYPT_PARA = _CMSG_CTRL_KEY_AGREE_DECRYPT_PARA;
  1234.   {$EXTERNALSYM CMSG_CTRL_KEY_AGREE_DECRYPT_PARA}
  1235.   TCmsgCtrlKeyAgreeDecryptPara = CMSG_CTRL_KEY_AGREE_DECRYPT_PARA;
  1236.   PCmsgCtrlKeyAgreeDecryptPara = PCMSG_CTRL_KEY_AGREE_DECRYPT_PARA;
  1237. //+-------------------------------------------------------------------------
  1238. //  CMSG_CTRL_MAIL_LIST_DECRYPT
  1239. //
  1240. //  Decrypt an ENVELOPED message after it has been decoded for a mail
  1241. //  list recipient.
  1242. //
  1243. //  pMailList points to the CMSG_MAIL_LIST_RECIPIENT_INFO obtained via
  1244. //  CryptMsgGetParam(CMSG_CMS_RECIPIENT_INFO_PARAM) for dwRecipientIndex.
  1245. //
  1246. //  There is 1 choice for the KeyEncryptionKey: an already created CSP key
  1247. //  handle. For the key handle choice, hCryptProv must be nonzero. This key
  1248. //  handle isn't destroyed.
  1249. //
  1250. //  If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags passed
  1251. //  to CryptMsgControl, then, the hCryptProv is released on the final
  1252. //  CryptMsgClose. Not released if CryptMsgControl fails.
  1253. //
  1254. //  For RC2 wrap, the effective key length is obtained from the
  1255. //  KeyEncryptionAlgorithm parameters and set on the hKeyEncryptionKey before
  1256. //  decrypting.
  1257. //
  1258. //  Note, the message can only be decrypted once.
  1259. //--------------------------------------------------------------------------
  1260.   PCMSG_CTRL_MAIL_LIST_DECRYPT_PARA = ^CMSG_CTRL_MAIL_LIST_DECRYPT_PARA;
  1261.   {$EXTERNALSYM PCMSG_CTRL_MAIL_LIST_DECRYPT_PARA}
  1262.   _CMSG_CTRL_MAIL_LIST_DECRYPT_PARA = record
  1263.     cbSize: DWORD;
  1264.     hCryptProv: HCRYPTPROV;
  1265.     pMailList: PCMSG_MAIL_LIST_RECIPIENT_INFO;
  1266.     dwRecipientIndex: DWORD;
  1267.     dwKeyChoice: DWORD;
  1268.     case Integer of
  1269.       // CMSG_MAIL_LIST_HANDLE_KEY_CHOICE
  1270.       0: (hKeyEncryptionKey: HCRYPTKEY);
  1271.       // Reserve space for a potential pointer choice
  1272.       1: (pvKeyEncryptionKey: Pointer);
  1273.   end;
  1274.   {$EXTERNALSYM _CMSG_CTRL_MAIL_LIST_DECRYPT_PARA}
  1275.   CMSG_CTRL_MAIL_LIST_DECRYPT_PARA = _CMSG_CTRL_MAIL_LIST_DECRYPT_PARA;
  1276.   {$EXTERNALSYM CMSG_CTRL_MAIL_LIST_DECRYPT_PARA}
  1277.   TCmsgCtrlMailListDecryptPara = CMSG_CTRL_MAIL_LIST_DECRYPT_PARA;
  1278.   PCmsgCtrlMailListDecryptPara = PCMSG_CTRL_MAIL_LIST_DECRYPT_PARA;
  1279. //+-------------------------------------------------------------------------
  1280. //  CMSG_CTRL_VERIFY_HASH
  1281. //
  1282. //  Verify the hash of a HASHED message after it has been decoded.
  1283. //
  1284. //  Only the hCryptMsg parameter is used, to specify the message whose
  1285. //  hash is being verified.
  1286. //--------------------------------------------------------------------------
  1287. //+-------------------------------------------------------------------------
  1288. //  CMSG_CTRL_ADD_SIGNER
  1289. //
  1290. //  Add a signer to a signed-data message.
  1291. //
  1292. //  pvCtrlPara points to a CMSG_SIGNER_ENCODE_INFO.
  1293. //--------------------------------------------------------------------------
  1294. //+-------------------------------------------------------------------------
  1295. //  CMSG_CTRL_ADD_CMS_SIGNER_INFO
  1296. //
  1297. //  Add a signer to a signed-data message.
  1298. //
  1299. //  Differs from the above, CMSG_CTRL_ADD_SIGNER, wherein, the signer info
  1300. //  already contains the signature.
  1301. //
  1302. //  pvCtrlPara points to a CMSG_CMS_SIGNER_INFO.
  1303. //--------------------------------------------------------------------------
  1304. //+-------------------------------------------------------------------------
  1305. //  CMSG_CTRL_DEL_SIGNER
  1306. //
  1307. //  Remove a signer from a signed-data or signed-and-enveloped-data message.
  1308. //
  1309. //  pvCtrlPara points to a DWORD containing the 0-based index of the
  1310. //  signer to be removed.
  1311. //--------------------------------------------------------------------------
  1312. //+-------------------------------------------------------------------------
  1313. //  CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR
  1314. //
  1315. //  Add an unauthenticated attribute to the SignerInfo of a signed-data or
  1316. //  signed-and-enveloped-data message.
  1317. //
  1318. //  The unauthenticated attribute is input in the form of an encoded blob.
  1319. //--------------------------------------------------------------------------
  1320.   PCMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA = ^CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA;
  1321.   {$EXTERNALSYM PCMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA}
  1322.   _CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA = record
  1323.     cbSize: DWORD;
  1324.     dwSignerIndex: DWORD;
  1325.     blob: CRYPT_DATA_BLOB;
  1326.   end;
  1327.   {$EXTERNALSYM _CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA}
  1328.   CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA = _CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA;
  1329.   {$EXTERNALSYM CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA}
  1330.   TCmsgCtrlAddSignerUnauthAttrPara = CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA;
  1331.   PCmsgCtrlAddSignerUnauthAttrPara = PCMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA;
  1332. //+-------------------------------------------------------------------------
  1333. //  CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR
  1334. //
  1335. //  Delete an unauthenticated attribute from the SignerInfo of a signed-data
  1336. //  or signed-and-enveloped-data message.
  1337. //
  1338. //  The unauthenticated attribute to be removed is specified by
  1339. //  a 0-based index.
  1340. //--------------------------------------------------------------------------
  1341.   PCMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA = ^CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA;
  1342.   {$EXTERNALSYM PCMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA}
  1343.   _CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA = record
  1344.     cbSize: DWORD;
  1345.     dwSignerIndex: DWORD;
  1346.     dwUnauthAttrIndex: DWORD;
  1347.   end;
  1348.   {$EXTERNALSYM _CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA}
  1349.   CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA = _CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA;
  1350.   {$EXTERNALSYM CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA}
  1351.   TCmsgCtrlDelSignerUnauthAttrPara = CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA;
  1352.   PCmsgCtrlDelSignerUnauthAttrPara = PCMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA;
  1353. //+-------------------------------------------------------------------------
  1354. //  CMSG_CTRL_ADD_CERT
  1355. //
  1356. //  Add a certificate to a signed-data or signed-and-enveloped-data message.
  1357. //
  1358. //  pvCtrlPara points to a CRYPT_DATA_BLOB containing the certificate's
  1359. //  encoded bytes.
  1360. //--------------------------------------------------------------------------
  1361. //+-------------------------------------------------------------------------
  1362. //  CMSG_CTRL_DEL_CERT
  1363. //
  1364. //  Delete a certificate from a signed-data or signed-and-enveloped-data
  1365. //  message.
  1366. //
  1367. //  pvCtrlPara points to a DWORD containing the 0-based index of the
  1368. //  certificate to be removed.
  1369. //--------------------------------------------------------------------------
  1370. //+-------------------------------------------------------------------------
  1371. //  CMSG_CTRL_ADD_CRL
  1372. //
  1373. //  Add a CRL to a signed-data or signed-and-enveloped-data message.
  1374. //
  1375. //  pvCtrlPara points to a CRYPT_DATA_BLOB containing the CRL's
  1376. //  encoded bytes.
  1377. //--------------------------------------------------------------------------
  1378. //+-------------------------------------------------------------------------
  1379. //  CMSG_CTRL_DEL_CRL
  1380. //
  1381. //  Delete a CRL from a signed-data or signed-and-enveloped-data message.
  1382. //
  1383. //  pvCtrlPara points to a DWORD containing the 0-based index of the CRL
  1384. //  to be removed.
  1385. //--------------------------------------------------------------------------
  1386. //+-------------------------------------------------------------------------
  1387. //  CMSG_CTRL_ADD_ATTR_CERT
  1388. //
  1389. //  Add an attribute certificate to a signed-data message.
  1390. //
  1391. //  pvCtrlPara points to a CRYPT_DATA_BLOB containing the attribute
  1392. //  certificate's encoded bytes.
  1393. //--------------------------------------------------------------------------
  1394. //+-------------------------------------------------------------------------
  1395. //  CMSG_CTRL_DEL_ATTR_CERT
  1396. //
  1397. //  Delete an attribute certificate from a signed-data message.
  1398. //
  1399. //  pvCtrlPara points to a DWORD containing the 0-based index of the
  1400. //  attribute certificate to be removed.
  1401. //--------------------------------------------------------------------------
  1402. //+-------------------------------------------------------------------------
  1403. //  Verify a countersignature, at the SignerInfo level.
  1404. //  ie. verify that pbSignerInfoCountersignature contains the encrypted
  1405. //  hash of the encryptedDigest field of pbSignerInfo.
  1406. //
  1407. //  hCryptProv is used to hash the encryptedDigest field of pbSignerInfo.
  1408. //  The only fields referenced from pciCountersigner are SerialNumber, Issuer,
  1409. //  and SubjectPublicKeyInfo.
  1410. //--------------------------------------------------------------------------
  1411. function CryptMsgVerifyCountersignatureEncoded(hCryptProv: HCRYPTPROV;
  1412.   dwEncodingType: DWORD; pbSignerInfo: PBYTE; cbSignerInfo: DWORD;
  1413.   pbSignerInfoCountersignature: PBYTE; cbSignerInfoCountersignature: DWORD;
  1414.   pciCountersigner: PCERT_INFO): BOOL; stdcall;
  1415. {$EXTERNALSYM CryptMsgVerifyCountersignatureEncoded}
  1416. //+-------------------------------------------------------------------------
  1417. //  Verify a countersignature, at the SignerInfo level.
  1418. //  ie. verify that pbSignerInfoCountersignature contains the encrypted
  1419. //  hash of the encryptedDigest field of pbSignerInfo.
  1420. //
  1421. //  hCryptProv is used to hash the encryptedDigest field of pbSignerInfo.
  1422. //
  1423. //  The signer can be a CERT_PUBLIC_KEY_INFO, certificate context or a
  1424. //  chain context.
  1425. //--------------------------------------------------------------------------
  1426. function CryptMsgVerifyCountersignatureEncodedEx(hCryptProv: HCRYPTPROV;
  1427.   dwEncodingType: DWORD; pbSignerInfo: PBYTE; cbSignerInfo: DWORD;
  1428.   pbSignerInfoCountersignature: PBYTE; cbSignerInfoCountersignature: DWORD;
  1429.   dwSignerType: DWORD; pvSigner: Pointer; dwFlags: DWORD; pvReserved: Pointer): BOOL; stdcall;
  1430. {$EXTERNALSYM CryptMsgVerifyCountersignatureEncodedEx}
  1431. // See CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA for dwSignerType definitions
  1432. //+-------------------------------------------------------------------------
  1433. //  Countersign an already-existing signature in a message
  1434. //
  1435. //  dwIndex is a zero-based index of the SignerInfo to be countersigned.
  1436. //--------------------------------------------------------------------------
  1437. function CryptMsgCountersign(hCryptMsg: HCRYPTMSG; dwIndex, cCountersigners: DWORD;
  1438.   rgCountersigners: PCMSG_SIGNER_ENCODE_INFO): BOOL; stdcall;
  1439. {$EXTERNALSYM CryptMsgCountersign}
  1440. //+-------------------------------------------------------------------------
  1441. //  Countersign an already-existing signature (encoded SignerInfo).
  1442. //  Output an encoded SignerInfo blob, suitable for use as a countersignature
  1443. //  attribute in the unauthenticated attributes of a signed-data or
  1444. //  signed-and-enveloped-data message.
  1445. //--------------------------------------------------------------------------
  1446. function CryptMsgCountersignEncoded(dwEncodingType: DWORD; pbSignerInfo: PBYTE;
  1447.   cbSignerInfo: DWORD; cCountersigners: DWORD; rgCountersigners: PCMSG_SIGNER_ENCODE_INFO;
  1448.   pbCountersignature: PBYTE; var pcbCountersignature: DWORD): BOOL; stdcall;
  1449. {$EXTERNALSYM CryptMsgCountersignEncoded}
  1450. //+-------------------------------------------------------------------------
  1451. //  CryptMsg OID installable functions
  1452. //--------------------------------------------------------------------------
  1453. type
  1454.   PFN_CMSG_ALLOC = function (cb: size_t): Pointer; stdcall;
  1455.   {$EXTERNALSYM PFN_CMSG_ALLOC}
  1456.   PFnCMsgAlloc = PFN_CMSG_ALLOC;
  1457.   PFN_CMSG_FREE = procedure (pv: Pointer); stdcall;
  1458.   {$EXTERNALSYM PFN_CMSG_FREE}
  1459.   PFnCMsgFree = PFN_CMSG_FREE;
  1460. // Note, the following 3 installable functions are obsolete and have been
  1461. // replaced with GenContentEncryptKey, ExportKeyTrans, ExportKeyAgree,
  1462. // ExportMailList, ImportKeyTrans, ImportKeyAgree and ImportMailList
  1463. // installable functions.
  1464. // If *phCryptProv is NULL upon entry, then, if supported, the installable
  1465. // function should acquire a default provider and return. Note, its up
  1466. // to the installable function to release at process detach.
  1467. //
  1468. // If paiEncrypt->Parameters.cbData is 0, then, the callback may optionally
  1469. // return default encoded parameters in *ppbEncryptParameters and
  1470. // *pcbEncryptParameters. pfnAlloc must be called for the allocation.
  1471. const
  1472.   CMSG_OID_GEN_ENCRYPT_KEY_FUNC = 'CryptMsgDllGenEncryptKey';
  1473.   {$EXTERNALSYM CMSG_OID_GEN_ENCRYPT_KEY_FUNC}
  1474. type
  1475.   PFN_CMSG_GEN_ENCRYPT_KEY = function (phCryptProv: PHCRYPTPROV;
  1476.     paiEncrypt: PCRYPT_ALGORITHM_IDENTIFIER; pvEncryptAuxInfo: PVOID;
  1477.     pPublicKeyInfo: PCERT_PUBLIC_KEY_INFO; pfnAlloc: PFN_CMSG_ALLOC;
  1478.     var phEncryptKey: HCRYPTKEY; var ppbEncryptParameters: PBYTE;
  1479.     pcbEncryptParameters: PDWORD): BOOL; stdcall;
  1480.   {$EXTERNALSYM PFN_CMSG_GEN_ENCRYPT_KEY}
  1481.   PfnCmsgGenEncryptKey = PFN_CMSG_GEN_ENCRYPT_KEY;
  1482. const
  1483.   CMSG_OID_EXPORT_ENCRYPT_KEY_FUNC = 'CryptMsgDllExportEncryptKey';
  1484.   {$EXTERNALSYM CMSG_OID_EXPORT_ENCRYPT_KEY_FUNC}
  1485. type
  1486.   PFN_CMSG_EXPORT_ENCRYPT_KEY = function (hCryptProv: HCRYPTPROV;
  1487.     hEncryptKey: HCRYPTKEY; pPublicKeyInfo: PCERT_PUBLIC_KEY_INFO;
  1488.     pbData: PBYTE; var pcbData: DWORD): BOOL; stdcall;
  1489.   {$EXTERNALSYM PFN_CMSG_EXPORT_ENCRYPT_KEY}
  1490.   PfnCmsgExportEncryptKey = PFN_CMSG_EXPORT_ENCRYPT_KEY;
  1491. const
  1492.   CMSG_OID_IMPORT_ENCRYPT_KEY_FUNC = 'CryptMsgDllImportEncryptKey';
  1493.   {$EXTERNALSYM CMSG_OID_IMPORT_ENCRYPT_KEY_FUNC}
  1494. type
  1495.   PFN_CMSG_IMPORT_ENCRYPT_KEY = function (hCryptProv: HCRYPTPROV;
  1496.     dwKeySpec: DWORD; paiEncrypt: PCRYPT_ALGORITHM_IDENTIFIER;
  1497.     paiPubKey: PCRYPT_ALGORITHM_IDENTIFIER; pbEncodedKey: PBYTE;
  1498.     cbEncodedKey: DWORD; var phEncryptKey: HCRYPTKEY): BOOL; stdcall;
  1499.   {$EXTERNALSYM PFN_CMSG_IMPORT_ENCRYPT_KEY}
  1500.   PfnCmsgImportEncryptKey = PFN_CMSG_IMPORT_ENCRYPT_KEY;
  1501. // To get the default installable function for GenContentEncryptKey,
  1502. // ExportKeyTrans, ExportKeyAgree, ExportMailList, ImportKeyTrans,
  1503. // ImportKeyAgree or ImportMailList call CryptGetOIDFunctionAddress()
  1504. // with the pszOID argument set to the following constant. dwEncodingType
  1505. // should be set to CRYPT_ASN_ENCODING or X509_ASN_ENCODING.
  1506. const
  1507.   CMSG_DEFAULT_INSTALLABLE_FUNC_OID = LPCSTR(1);
  1508.   {$EXTERNALSYM CMSG_DEFAULT_INSTALLABLE_FUNC_OID}
  1509. //+-------------------------------------------------------------------------
  1510. //  Content Encrypt Info
  1511. //
  1512. //  The following data structure contains the information shared between
  1513. //  the GenContentEncryptKey and the ExportKeyTrans, ExportKeyAgree and
  1514. //  ExportMailList installable functions.
  1515. //--------------------------------------------------------------------------
  1516. type
  1517.   PCMSG_CONTENT_ENCRYPT_INFO = ^CMSG_CONTENT_ENCRYPT_INFO;
  1518.   {$EXTERNALSYM PCMSG_CONTENT_ENCRYPT_INFO}
  1519.   _CMSG_CONTENT_ENCRYPT_INFO = record
  1520.     cbSize: DWORD;
  1521.     hCryptProv: HCRYPTPROV;
  1522.     ContentEncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  1523.     pvEncryptionAuxInfo: Pointer;
  1524.     cRecipients: DWORD;
  1525.     rgCmsRecipients: PCMSG_RECIPIENT_ENCODE_INFO;
  1526.     pfnAlloc: PFN_CMSG_ALLOC;
  1527.     pfnFree: PFN_CMSG_FREE;
  1528.     dwEncryptFlags: DWORD;
  1529.     hContentEncryptKey: HCRYPTKEY;
  1530.     dwFlags: DWORD;
  1531.   end;
  1532.   {$EXTERNALSYM _CMSG_CONTENT_ENCRYPT_INFO}
  1533.   CMSG_CONTENT_ENCRYPT_INFO = _CMSG_CONTENT_ENCRYPT_INFO;
  1534.   {$EXTERNALSYM CMSG_CONTENT_ENCRYPT_INFO}
  1535.   TCmsgContentEncryptInfo = CMSG_CONTENT_ENCRYPT_INFO;
  1536.   PCmsgContentEncryptInfo = PCMSG_CONTENT_ENCRYPT_INFO;
  1537. const
  1538.   CMSG_CONTENT_ENCRYPT_PAD_ENCODED_LEN_FLAG = $00000001;
  1539.   {$EXTERNALSYM CMSG_CONTENT_ENCRYPT_PAD_ENCODED_LEN_FLAG}
  1540.   CMSG_CONTENT_ENCRYPT_FREE_PARA_FLAG       = $00000001;
  1541.   {$EXTERNALSYM CMSG_CONTENT_ENCRYPT_FREE_PARA_FLAG}
  1542.   CMSG_CONTENT_ENCRYPT_RELEASE_CONTEXT_FLAG = $00008000;
  1543.   {$EXTERNALSYM CMSG_CONTENT_ENCRYPT_RELEASE_CONTEXT_FLAG}
  1544. //+-------------------------------------------------------------------------
  1545. // Upon input, ContentEncryptInfo has been initialized from the
  1546. // EnvelopedEncodeInfo.
  1547. //
  1548. // Note, if rgpRecipients instead of rgCmsRecipients are set in the
  1549. // EnvelopedEncodeInfo, then, the rgpRecipients have been converted
  1550. // to rgCmsRecipients in the ContentEncryptInfo.
  1551. //
  1552. // The following fields may be changed in ContentEncryptInfo:
  1553. //      hContentEncryptKey
  1554. //      hCryptProv
  1555. //      ContentEncryptionAlgorithm.Parameters
  1556. //      dwFlags
  1557. //
  1558. // All other fields in the ContentEncryptInfo are READONLY.
  1559. //
  1560. // If CMSG_CONTENT_ENCRYPT_PAD_ENCODED_LEN_FLAG is set upon entry
  1561. // in dwEncryptFlags, then, any potentially variable length encoded
  1562. // output should be padded with zeroes to always obtain the
  1563. // same maximum encoded length. This is necessary for
  1564. // CryptMsgCalculateEncodedLength() or CryptMsgOpenToEncode() with
  1565. // definite length streaming.
  1566. //
  1567. // The hContentEncryptKey must be updated.
  1568. //
  1569. // If hCryptProv is NULL upon input, then, it must be updated.
  1570. // If a HCRYPTPROV is acquired that must be released, then, the
  1571. // CMSG_CONTENT_ENCRYPT_RELEASE_CONTEXT_FLAG must be set in dwFlags.
  1572. //
  1573. // If ContentEncryptionAlgorithm.Parameters is updated, then, the
  1574. // CMSG_CONTENT_ENCRYPT_FREE_PARA_FLAG must be set in dwFlags. pfnAlloc and
  1575. // pfnFree must be used for doing the allocation.
  1576. //
  1577. // ContentEncryptionAlgorithm.pszObjId is used to get the OIDFunctionAddress.
  1578. //--------------------------------------------------------------------------
  1579. const
  1580.   CMSG_OID_GEN_CONTENT_ENCRYPT_KEY_FUNC = 'CryptMsgDllGenContentEncryptKey';
  1581.   {$EXTERNALSYM CMSG_OID_GEN_CONTENT_ENCRYPT_KEY_FUNC}
  1582. type
  1583.   PFN_CMSG_GEN_CONTENT_ENCRYPT_KEY = function (pContentEncryptInfo: PCMSG_CONTENT_ENCRYPT_INFO;
  1584.     dwFlags: DWORD; pvReserved: PPointer): BOOL; stdcall;
  1585.   {$EXTERNALSYM PFN_CMSG_GEN_CONTENT_ENCRYPT_KEY}
  1586.   PfnCmsgGenContentEncryptKey = PFN_CMSG_GEN_CONTENT_ENCRYPT_KEY;
  1587. //+-------------------------------------------------------------------------
  1588. //  Key Transport Encrypt Info
  1589. //
  1590. //  The following data structure contains the information updated by the
  1591. //  ExportKeyTrans installable function.
  1592. //--------------------------------------------------------------------------
  1593. type
  1594.   PCMSG_KEY_TRANS_ENCRYPT_INFO = ^CMSG_KEY_TRANS_ENCRYPT_INFO;
  1595.   {$EXTERNALSYM PCMSG_KEY_TRANS_ENCRYPT_INFO}
  1596.   _CMSG_KEY_TRANS_ENCRYPT_INFO = record
  1597.     cbSize: DWORD;
  1598.     dwRecipientIndex: DWORD;
  1599.     KeyEncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  1600.     EncryptedKey: CRYPT_DATA_BLOB;
  1601.     dwFlags: DWORD;
  1602.   end;
  1603.   {$EXTERNALSYM _CMSG_KEY_TRANS_ENCRYPT_INFO}
  1604.   CMSG_KEY_TRANS_ENCRYPT_INFO = _CMSG_KEY_TRANS_ENCRYPT_INFO;
  1605.   {$EXTERNALSYM CMSG_KEY_TRANS_ENCRYPT_INFO}
  1606.   TCmsgKeyTransEncryptInfo = CMSG_KEY_TRANS_ENCRYPT_INFO;
  1607.   PCmsgKeyTransEncryptInfo = PCMSG_KEY_TRANS_ENCRYPT_INFO;
  1608. const
  1609.   CMSG_KEY_TRANS_ENCRYPT_FREE_PARA_FLAG = $00000001;
  1610.   {$EXTERNALSYM CMSG_KEY_TRANS_ENCRYPT_FREE_PARA_FLAG}
  1611. //+-------------------------------------------------------------------------
  1612. // Upon input, KeyTransEncryptInfo has been initialized from the
  1613. // KeyTransEncodeInfo.
  1614. //
  1615. // The following fields may be changed in KeyTransEncryptInfo:
  1616. //      EncryptedKey
  1617. //      KeyEncryptionAlgorithm.Parameters
  1618. //      dwFlags
  1619. //
  1620. // All other fields in the KeyTransEncryptInfo are READONLY.
  1621. //
  1622. // The EncryptedKey must be updated. The pfnAlloc and pfnFree specified in
  1623. // ContentEncryptInfo must be used for doing the allocation.
  1624. //
  1625. // If the KeyEncryptionAlgorithm.Parameters is updated, then, the
  1626. // CMSG_KEY_TRANS_ENCRYPT_FREE_PARA_FLAG must be set in dwFlags.
  1627. // The pfnAlloc and pfnFree specified in ContentEncryptInfo must be used
  1628. // for doing the allocation.
  1629. //
  1630. // KeyEncryptionAlgorithm.pszObjId is used to get the OIDFunctionAddress.
  1631. //--------------------------------------------------------------------------
  1632. const
  1633.   CMSG_OID_EXPORT_KEY_TRANS_FUNC = 'CryptMsgDllExportKeyTrans';
  1634.   {$EXTERNALSYM CMSG_OID_EXPORT_KEY_TRANS_FUNC}
  1635. type
  1636.   PFN_CMSG_EXPORT_KEY_TRANS = function (pContentEncryptInfo: PCMSG_CONTENT_ENCRYPT_INFO;
  1637.     pKeyTransEncodeInfo: PCMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO;
  1638.     pKeyTransEncryptInfo: PCMSG_KEY_TRANS_ENCRYPT_INFO; dwFlags: DWORD;
  1639.     pvReserved: Pointer): BOOL; stdcall;
  1640.   {$EXTERNALSYM PFN_CMSG_EXPORT_KEY_TRANS}
  1641.   PfnCmsgExportKeyTrans = PFN_CMSG_EXPORT_KEY_TRANS;
  1642. //+-------------------------------------------------------------------------
  1643. //  Key Agree Key Encrypt Info
  1644. //
  1645. //  The following data structure contains the information updated by the
  1646. //  ExportKeyAgree installable function for each encrypted key agree
  1647. //  recipient.
  1648. //--------------------------------------------------------------------------
  1649. type
  1650.   PCMSG_KEY_AGREE_KEY_ENCRYPT_INFO = ^CMSG_KEY_AGREE_KEY_ENCRYPT_INFO;
  1651.   {$EXTERNALSYM PCMSG_KEY_AGREE_KEY_ENCRYPT_INFO}
  1652.   _CMSG_KEY_AGREE_KEY_ENCRYPT_INFO = record
  1653.     cbSize: DWORD;
  1654.     EncryptedKey: CRYPT_DATA_BLOB;
  1655.   end;
  1656.   {$EXTERNALSYM _CMSG_KEY_AGREE_KEY_ENCRYPT_INFO}
  1657.   CMSG_KEY_AGREE_KEY_ENCRYPT_INFO = _CMSG_KEY_AGREE_KEY_ENCRYPT_INFO;
  1658.   {$EXTERNALSYM CMSG_KEY_AGREE_KEY_ENCRYPT_INFO}
  1659.   TCmsgKeyAgreeKeyEncryptInfo = CMSG_KEY_AGREE_KEY_ENCRYPT_INFO;
  1660.   PCmsgKeyAgreeKeyEncryptInfo = PCMSG_KEY_AGREE_KEY_ENCRYPT_INFO;
  1661.   PPCMSG_KEY_AGREE_KEY_ENCRYPT_INFO = ^PCMSG_KEY_AGREE_KEY_ENCRYPT_INFO;
  1662.   {$NODEFINE PPCMSG_KEY_AGREE_KEY_ENCRYPT_INFO}
  1663. //+-------------------------------------------------------------------------
  1664. //  Key Agree Encrypt Info
  1665. //
  1666. //  The following data structure contains the information applicable to
  1667. //  all recipients. Its updated by the ExportKeyAgree installable function.
  1668. //--------------------------------------------------------------------------
  1669.   PCMSG_KEY_AGREE_ENCRYPT_INFO = ^CMSG_KEY_AGREE_ENCRYPT_INFO;
  1670.   {$EXTERNALSYM PCMSG_KEY_AGREE_ENCRYPT_INFO}
  1671.   _CMSG_KEY_AGREE_ENCRYPT_INFO = record
  1672.     cbSize: DWORD;
  1673.     dwRecipientIndex: DWORD;
  1674.     KeyEncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  1675.     UserKeyingMaterial: CRYPT_DATA_BLOB;
  1676.     dwOriginatorChoice: DWORD;
  1677.     Union: record
  1678.     case Integer of
  1679.       // CMSG_KEY_AGREE_ORIGINATOR_CERT
  1680.       0: (OriginatorCertId: CERT_ID);
  1681.       // CMSG_KEY_AGREE_ORIGINATOR_PUBLIC_KEY
  1682.       1: (OriginatorPublicKeyInfo: CERT_PUBLIC_KEY_INFO);
  1683.     end;
  1684.     cKeyAgreeKeyEncryptInfo: DWORD;
  1685.     rgpKeyAgreeKeyEncryptInfo: PPCMSG_KEY_AGREE_KEY_ENCRYPT_INFO;
  1686.     dwFlags: DWORD;
  1687.   end;
  1688.   {$EXTERNALSYM _CMSG_KEY_AGREE_ENCRYPT_INFO}
  1689.   CMSG_KEY_AGREE_ENCRYPT_INFO = _CMSG_KEY_AGREE_ENCRYPT_INFO;
  1690.   {$EXTERNALSYM CMSG_KEY_AGREE_ENCRYPT_INFO}
  1691.   TCmsgKeyAgreeEncryptInfo = CMSG_KEY_AGREE_ENCRYPT_INFO;
  1692.   PCmsgKeyAgreeEncryptInfo = PCMSG_KEY_AGREE_ENCRYPT_INFO;
  1693. const
  1694.   CMSG_KEY_AGREE_ENCRYPT_FREE_PARA_FLAG        = $00000001;
  1695.   {$EXTERNALSYM CMSG_KEY_AGREE_ENCRYPT_FREE_PARA_FLAG}
  1696.   CMSG_KEY_AGREE_ENCRYPT_FREE_MATERIAL_FLAG    = $00000002;
  1697.   {$EXTERNALSYM CMSG_KEY_AGREE_ENCRYPT_FREE_MATERIAL_FLAG}
  1698.   CMSG_KEY_AGREE_ENCRYPT_FREE_PUBKEY_ALG_FLAG  = $00000004;
  1699.   {$EXTERNALSYM CMSG_KEY_AGREE_ENCRYPT_FREE_PUBKEY_ALG_FLAG}
  1700.   CMSG_KEY_AGREE_ENCRYPT_FREE_PUBKEY_PARA_FLAG = $00000008;
  1701.   {$EXTERNALSYM CMSG_KEY_AGREE_ENCRYPT_FREE_PUBKEY_PARA_FLAG}
  1702.   CMSG_KEY_AGREE_ENCRYPT_FREE_PUBKEY_BITS_FLAG = $00000010;
  1703.   {$EXTERNALSYM CMSG_KEY_AGREE_ENCRYPT_FREE_PUBKEY_BITS_FLAG}
  1704. //+-------------------------------------------------------------------------
  1705. // Upon input, KeyAgreeEncryptInfo has been initialized from the
  1706. // KeyAgreeEncodeInfo.
  1707. //
  1708. // The following fields may be changed in KeyAgreeEncryptInfo:
  1709. //      KeyEncryptionAlgorithm.Parameters
  1710. //      UserKeyingMaterial
  1711. //      dwOriginatorChoice
  1712. //      OriginatorCertId
  1713. //      OriginatorPublicKeyInfo
  1714. //      dwFlags
  1715. //
  1716. // All other fields in the KeyAgreeEncryptInfo are READONLY.
  1717. //
  1718. // If the KeyEncryptionAlgorithm.Parameters is updated, then, the
  1719. // CMSG_KEY_AGREE_ENCRYPT_FREE_PARA_FLAG must be set in dwFlags.
  1720. // The pfnAlloc and pfnFree specified in ContentEncryptInfo must be used
  1721. // for doing the allocation.
  1722. //
  1723. // If the UserKeyingMaterial is updated, then, the
  1724. // CMSG_KEY_AGREE_ENCRYPT_FREE_MATERIAL_FLAG must be set in dwFlags.
  1725. // pfnAlloc and pfnFree must be used for doing the allocation.
  1726. //
  1727. // The dwOriginatorChoice must be updated to either
  1728. // CMSG_KEY_AGREE_ORIGINATOR_CERT or CMSG_KEY_AGREE_ORIGINATOR_PUBLIC_KEY.
  1729. //
  1730. // If the OriginatorPublicKeyInfo is updated, then, the appropriate
  1731. // CMSG_KEY_AGREE_ENCRYPT_FREE_PUBKEY_*_FLAG must be set in dwFlags and
  1732. // pfnAlloc and pfnFree must be used for doing the allocation.
  1733. //
  1734. // If CMSG_CONTENT_ENCRYPT_PAD_ENCODED_LEN_FLAG is set upon entry
  1735. // in pContentEncryptInfo->dwEncryptFlags, then, the OriginatorPublicKeyInfo's
  1736. // Ephemeral PublicKey should be padded with zeroes to always obtain the
  1737. // same maximum encoded length. Note, the length of the generated ephemeral Y
  1738. // public key can vary depending on the number of leading zero bits.
  1739. //
  1740. // Upon input, the array of *rgpKeyAgreeKeyEncryptInfo has been initialized.
  1741. // The EncryptedKey must be updated for each recipient key.
  1742. // The pfnAlloc and pfnFree specified in
  1743. // ContentEncryptInfo must be used for doing the allocation.
  1744. //
  1745. // KeyEncryptionAlgorithm.pszObjId is used to get the OIDFunctionAddress.
  1746. //--------------------------------------------------------------------------
  1747. const
  1748.   CMSG_OID_EXPORT_KEY_AGREE_FUNC = 'CryptMsgDllExportKeyAgree';
  1749.   {$EXTERNALSYM CMSG_OID_EXPORT_KEY_AGREE_FUNC}
  1750. type
  1751.   PFN_CMSG_EXPORT_KEY_AGREE = function (pContentEncryptInfo: PCMSG_CONTENT_ENCRYPT_INFO;
  1752.     pKeyAgreeEncodeInfo: PCMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO;
  1753.     pKeyAgreeEncryptInfo: PCMSG_KEY_AGREE_ENCRYPT_INFO; dwFlags: DWORD;
  1754.     pvReserved: Pointer): BOOL; stdcall;
  1755.   {$EXTERNALSYM PFN_CMSG_EXPORT_KEY_AGREE}
  1756.   PfnCmsgExportKeyAgree = PFN_CMSG_EXPORT_KEY_AGREE;
  1757. //+-------------------------------------------------------------------------
  1758. //  Mail List Encrypt Info
  1759. //
  1760. //  The following data structure contains the information updated by the
  1761. //  ExportMailList installable function.
  1762. //--------------------------------------------------------------------------
  1763. type
  1764.   PCMSG_MAIL_LIST_ENCRYPT_INFO = ^CMSG_MAIL_LIST_ENCRYPT_INFO;
  1765.   {$EXTERNALSYM PCMSG_MAIL_LIST_ENCRYPT_INFO}
  1766.   _CMSG_MAIL_LIST_ENCRYPT_INFO = record
  1767.     cbSize: DWORD;
  1768.     dwRecipientIndex: DWORD;
  1769.     KeyEncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  1770.     EncryptedKey: CRYPT_DATA_BLOB;
  1771.     dwFlags: DWORD;
  1772.   end;
  1773.   {$EXTERNALSYM _CMSG_MAIL_LIST_ENCRYPT_INFO}
  1774.   CMSG_MAIL_LIST_ENCRYPT_INFO = _CMSG_MAIL_LIST_ENCRYPT_INFO;
  1775.   {$EXTERNALSYM CMSG_MAIL_LIST_ENCRYPT_INFO}
  1776.   TCmsgMailListEncryptInfo = CMSG_MAIL_LIST_ENCRYPT_INFO;
  1777.   PCmsgMailListEncryptInfo = PCMSG_MAIL_LIST_ENCRYPT_INFO;
  1778. const
  1779.   CMSG_MAIL_LIST_ENCRYPT_FREE_PARA_FLAG = $00000001;
  1780.   {$EXTERNALSYM CMSG_MAIL_LIST_ENCRYPT_FREE_PARA_FLAG}
  1781. //+-------------------------------------------------------------------------
  1782. // Upon input, MailListEncryptInfo has been initialized from the
  1783. // MailListEncodeInfo.
  1784. //
  1785. // The following fields may be changed in MailListEncryptInfo:
  1786. //      EncryptedKey
  1787. //      KeyEncryptionAlgorithm.Parameters
  1788. //      dwFlags
  1789. //
  1790. // All other fields in the MailListEncryptInfo are READONLY.
  1791. //
  1792. // The EncryptedKey must be updated. The pfnAlloc and pfnFree specified in
  1793. // ContentEncryptInfo must be used for doing the allocation.
  1794. //
  1795. // If the KeyEncryptionAlgorithm.Parameters is updated, then, the
  1796. // CMSG_MAIL_LIST_ENCRYPT_FREE_PARA_FLAG must be set in dwFlags.
  1797. // The pfnAlloc and pfnFree specified in ContentEncryptInfo must be used
  1798. // for doing the allocation.
  1799. //
  1800. // KeyEncryptionAlgorithm.pszObjId is used to get the OIDFunctionAddress.
  1801. //--------------------------------------------------------------------------
  1802. const
  1803.   CMSG_OID_EXPORT_MAIL_LIST_FUNC = 'CryptMsgDllExportMailList';
  1804.   {$EXTERNALSYM CMSG_OID_EXPORT_MAIL_LIST_FUNC}
  1805. type
  1806.   PFN_CMSG_EXPORT_MAIL_LIST = function (pContentEncryptInfo: PCMSG_CONTENT_ENCRYPT_INFO;
  1807.     pMailListEncodeInfo: PCMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO;
  1808.     pMailListEncryptInfo: PCMSG_MAIL_LIST_ENCRYPT_INFO; dwFlags: DWORD;
  1809.     pvReserved: Pointer): BOOL; stdcall;
  1810.   {$EXTERNALSYM PFN_CMSG_EXPORT_MAIL_LIST}
  1811.   PfnCmsgExportMailList = PFN_CMSG_EXPORT_MAIL_LIST;
  1812. //+-------------------------------------------------------------------------
  1813. // OID Installable functions for importing an encoded and encrypted content
  1814. // encryption key.
  1815. //
  1816. // There's a different installable function for each CMS Recipient choice:
  1817. //  ImportKeyTrans
  1818. //  ImportKeyAgree
  1819. //  ImportMailList
  1820. //
  1821. // Iterates through the following OIDs to get the OID installable function:
  1822. //   KeyEncryptionOID!ContentEncryptionOID
  1823. //   KeyEncryptionOID
  1824. //   ContentEncryptionOID
  1825. //
  1826. // If the OID installable function doesn't support the specified
  1827. // KeyEncryption and ContentEncryption OIDs, then, return FALSE with
  1828. // LastError set to E_NOTIMPL.
  1829. //--------------------------------------------------------------------------
  1830. const
  1831.   CMSG_OID_IMPORT_KEY_TRANS_FUNC = 'CryptMsgDllImportKeyTrans';
  1832.   {$EXTERNALSYM CMSG_OID_IMPORT_KEY_TRANS_FUNC}
  1833. type
  1834.   PFN_CMSG_IMPORT_KEY_TRANS = function (pContentEncryptionAlgorithm: PCRYPT_ALGORITHM_IDENTIFIER;
  1835.     pKeyTransDecryptPara: PCMSG_CTRL_KEY_TRANS_DECRYPT_PARA; dwFlags: DWORD;
  1836.     pvReserved: Pointer; var phContentEncryptKey: HCRYPTKEY): BOOL; stdcall;
  1837.   {$EXTERNALSYM PFN_CMSG_IMPORT_KEY_TRANS}
  1838.   PfnCmsgImportKeyTrans = PFN_CMSG_IMPORT_KEY_TRANS;
  1839. const
  1840.   CMSG_OID_IMPORT_KEY_AGREE_FUNC = 'CryptMsgDllImportKeyAgree';
  1841.   {$EXTERNALSYM CMSG_OID_IMPORT_KEY_AGREE_FUNC}
  1842. type
  1843.   PFN_CMSG_IMPORT_KEY_AGREE = function (pContentEncryptionAlgorithm: PCRYPT_ALGORITHM_IDENTIFIER;
  1844.     pKeyAgreeDecryptPara: PCMSG_CTRL_KEY_AGREE_DECRYPT_PARA; dwFlags: DWORD;
  1845.     pvReserved: Pointer; var phContentEncryptKey: HCRYPTKEY): BOOL; stdcall;
  1846.   {$EXTERNALSYM PFN_CMSG_IMPORT_KEY_AGREE}
  1847.   PfnCmsgImportKeyAgree = PFN_CMSG_IMPORT_KEY_AGREE;
  1848. const
  1849.   CMSG_OID_IMPORT_MAIL_LIST_FUNC = 'CryptMsgDllImportMailList';
  1850.   {$EXTERNALSYM CMSG_OID_IMPORT_MAIL_LIST_FUNC}
  1851. type
  1852.   PFN_CMSG_IMPORT_MAIL_LIST = function (pContentEncryptionAlgorithm: PCRYPT_ALGORITHM_IDENTIFIER;
  1853.     pMailListDecryptPara: PCMSG_CTRL_MAIL_LIST_DECRYPT_PARA; dwFlags: DWORD;
  1854.     pvReserved: Pointer; var phContentEncryptKey: HCRYPTKEY): BOOL; stdcall;
  1855.   {$EXTERNALSYM PFN_CMSG_IMPORT_MAIL_LIST}
  1856.   PfnCmsgImportMailList = PFN_CMSG_IMPORT_MAIL_LIST;
  1857. //+=========================================================================
  1858. //  Certificate Store Data Structures and APIs
  1859. //==========================================================================
  1860. //+-------------------------------------------------------------------------
  1861. //              In its most basic implementation, a cert store is simply a
  1862. //              collection of certificates and/or CRLs. This is the case when
  1863. //              a cert store is opened with all of its certificates and CRLs
  1864. //              coming from a PKCS #7 encoded cryptographic message.
  1865. //
  1866. //              Nonetheless, all cert stores have the following properties:
  1867. //               - A public key may have more than one certificate in the store.
  1868. //                 For example, a private/public key used for signing may have a
  1869. //                 certificate issued for VISA and another issued for
  1870. //                 Mastercard. Also, when a certificate is renewed there might
  1871. //                 be more than one certificate with the same subject and
  1872. //                 issuer.
  1873. //               - However, each certificate in the store is uniquely
  1874. //                 identified by its Issuer and SerialNumber.
  1875. //               - There's an issuer of subject certificate relationship. A
  1876. //                 certificate's issuer is found by doing a match of
  1877. //                 pSubjectCert->Issuer with pIssuerCert->Subject.
  1878. //                 The relationship is verified by using
  1879. //                 the issuer's public key to verify the subject certificate's
  1880. //                 signature. Note, there might be X.509 v3 extensions
  1881. //                 to assist in finding the issuer certificate.
  1882. //               - Since issuer certificates might be renewed, a subject
  1883. //                 certificate might have more than one issuer certificate.
  1884. //               - There's an issuer of CRL relationship. An
  1885. //                 issuer's CRL is found by doing a match of
  1886. //                 pIssuerCert->Subject with pCrl->Issuer.
  1887. //                 The relationship is verified by using
  1888. //                 the issuer's public key to verify the CRL's
  1889. //                 signature. Note, there might be X.509 v3 extensions
  1890. //                 to assist in finding the CRL.
  1891. //               - Since some issuers might support the X.509 v3 delta CRL
  1892. //                 extensions, an issuer might have more than one CRL.
  1893. //               - The store shouldn't have any redundant certificates or
  1894. //                 CRLs. There shouldn't be two certificates with the same
  1895. //                 Issuer and SerialNumber. There shouldn't be two CRLs with
  1896. //                 the same Issuer, ThisUpdate and NextUpdate.
  1897. //               - The store has NO policy or trust information. No
  1898. //                 certificates are tagged as being "root". Its up to
  1899. //                 the application to maintain a list of CertIds (Issuer +
  1900. //                 SerialNumber) for certificates it trusts.
  1901. //               - The store might contain bad certificates and/or CRLs.
  1902. //                 The issuer's signature of a subject certificate or CRL may
  1903. //                 not verify. Certificates or CRLs may not satisfy their
  1904. //                 time validity requirements. Certificates may be
  1905. //                 revoked.
  1906. //
  1907. //              In addition to the certificates and CRLs, properties can be
  1908. //              stored. There are two predefined property IDs for a user
  1909. //              certificate: CERT_KEY_PROV_HANDLE_PROP_ID and
  1910. //              CERT_KEY_PROV_INFO_PROP_ID. The CERT_KEY_PROV_HANDLE_PROP_ID
  1911. //              is a HCRYPTPROV handle to the private key assoicated
  1912. //              with the certificate. The CERT_KEY_PROV_INFO_PROP_ID contains
  1913. //              information to be used to call
  1914. //              CryptAcquireContext and CryptSetProvParam to get a handle
  1915. //              to the private key associated with the certificate.
  1916. //
  1917. //              There exists two more predefined property IDs for certificates
  1918. //              and CRLs, CERT_SHA1_HASH_PROP_ID and CERT_MD5_HASH_PROP_ID.
  1919. //              If these properties don't already exist, then, a hash of the
  1920. //              content is computed. (CERT_HASH_PROP_ID maps to the default
  1921. //              hash algorithm, currently, CERT_SHA1_HASH_PROP_ID).
  1922. //
  1923. //              There are additional APIs for creating certificate and CRL
  1924. //      contexts not in a store (CertCreateCertificateContext and
  1925. //      CertCreateCRLContext).
  1926. //
  1927. //--------------------------------------------------------------------------
  1928. type
  1929.   HCERTSTORE = Pointer;
  1930.   {$EXTERNALSYM HCERTSTORE}
  1931.   PHCERTSTORE = ^HCERTSTORE;
  1932.   {$NODEFINE PHCERTSTORE}
  1933. //+-------------------------------------------------------------------------
  1934. //  Certificate context.
  1935. //
  1936. //  A certificate context contains both the encoded and decoded representation
  1937. //  of a certificate. A certificate context returned by a cert store function
  1938. //  must be freed by calling the CertFreeCertificateContext function. The
  1939. //  CertDuplicateCertificateContext function can be called to make a duplicate
  1940. //  copy (which also must be freed by calling CertFreeCertificateContext).
  1941. //--------------------------------------------------------------------------
  1942.   PCERT_CONTEXT = ^CERT_CONTEXT;
  1943.   {$EXTERNALSYM CERT_CONTEXT}
  1944.   _CERT_CONTEXT = record
  1945.     dwCertEncodingType: DWORD;
  1946.     pbCertEncoded: LPBYTE;
  1947.     cbCertEncoded: DWORD;
  1948.     pCertInfo: PCERT_INFO;
  1949.     hCertStore: HCERTSTORE;
  1950.   end;
  1951.   {$EXTERNALSYM _CERT_CONTEXT}
  1952.   CERT_CONTEXT = _CERT_CONTEXT;
  1953.   {$EXTERNALSYM CERT_CONTEXT}
  1954.   TCertContext = CERT_CONTEXT;
  1955.   PCertContext = PCERT_CONTEXT;
  1956.   PCCERT_CONTEXT = PCERT_CONTEXT;
  1957.   {$EXTERNALSYM PCCERT_CONTEXT}
  1958.   PPCCERT_CONTEXT = ^PCCERT_CONTEXT;
  1959.   {$NODEFINE PCCERT_CONTEXT}
  1960. //+-------------------------------------------------------------------------
  1961. //  CRL context.
  1962. //
  1963. //  A CRL context contains both the encoded and decoded representation
  1964. //  of a CRL. A CRL context returned by a cert store function
  1965. //  must be freed by calling the CertFreeCRLContext function. The
  1966. //  CertDuplicateCRLContext function can be called to make a duplicate
  1967. //  copy (which also must be freed by calling CertFreeCRLContext).
  1968. //--------------------------------------------------------------------------
  1969.   PCRL_CONTEXT = ^CRL_CONTEXT;
  1970.   {$EXTERNALSYM PCRL_CONTEXT}
  1971.   _CRL_CONTEXT = record
  1972.     dwCertEncodingType: DWORD;
  1973.     pbCrlEncoded: LPBYTE;
  1974.     cbCrlEncoded: DWORD;
  1975.     pCrlInfo: PCRL_INFO;
  1976.     hCertStore: HCERTSTORE;
  1977.   end;
  1978.   {$EXTERNALSYM _CRL_CONTEXT}
  1979.   CRL_CONTEXT = _CRL_CONTEXT;
  1980.   {$EXTERNALSYM CRL_CONTEXT}
  1981.   TCrlContext = CRL_CONTEXT;
  1982.   PCrlContext = PCRL_CONTEXT;
  1983.   PCCRL_CONTEXT = PCRL_CONTEXT;
  1984.   {$EXTERNALSYM PCCRL_CONTEXT}
  1985.   PPCCRL_CONTEXT = ^PCCRL_CONTEXT;
  1986.   {$NODEFINE PPCCRL_CONTEXT}
  1987. //+-------------------------------------------------------------------------
  1988. //  Certificate Trust List (CTL) context.
  1989. //
  1990. //  A CTL context contains both the encoded and decoded representation
  1991. //  of a CTL. Also contains an opened HCRYPTMSG handle to the decoded
  1992. //  cryptographic signed message containing the CTL_INFO as its inner content.
  1993. //  pbCtlContent is the encoded inner content of the signed message.
  1994. //
  1995. //  The CryptMsg APIs can be used to extract additional signer information.
  1996. //--------------------------------------------------------------------------
  1997.   PCTL_CONTEXT = ^CTL_CONTEXT;
  1998.   {$EXTERNALSYM PCTL_CONTEXT}
  1999.   _CTL_CONTEXT = record
  2000.     dwMsgAndCertEncodingType: DWORD;
  2001.     pbCtlEncoded: LPBYTE;
  2002.     cbCtlEncoded: DWORD;
  2003.     pCtlInfo: PCTL_INFO;
  2004.     hCertStore: HCERTSTORE;
  2005.     hCryptMsg: HCRYPTMSG;
  2006.     pbCtlContent: LPBYTE;
  2007.     cbCtlContent: DWORD;
  2008.   end;
  2009.   {$EXTERNALSYM _CTL_CONTEXT}
  2010.   CTL_CONTEXT = _CTL_CONTEXT;
  2011.   {$EXTERNALSYM CTL_CONTEXT}
  2012.   TCtlContext = CTL_CONTEXT;
  2013.   PCtlContext = PCTL_CONTEXT;
  2014.   PCCTL_CONTEXT = PCTL_CONTEXT;
  2015.   {$EXTERNALSYM PCCTL_CONTEXT}
  2016.   PPCCTL_CONTEXT = ^PCCTL_CONTEXT;
  2017.   {$EXTERNALSYM PPCCTL_CONTEXT}
  2018.   
  2019. //+-------------------------------------------------------------------------
  2020. //  Certificate, CRL and CTL property IDs
  2021. //
  2022. //  See CertSetCertificateContextProperty or CertGetCertificateContextProperty
  2023. //  for usage information.
  2024. //--------------------------------------------------------------------------
  2025. const
  2026.   CERT_KEY_PROV_HANDLE_PROP_ID      = 1;
  2027.   {$EXTERNALSYM CERT_KEY_PROV_HANDLE_PROP_ID}
  2028.   CERT_KEY_PROV_INFO_PROP_ID        = 2;
  2029.   {$EXTERNALSYM CERT_KEY_PROV_INFO_PROP_ID}
  2030.   CERT_SHA1_HASH_PROP_ID            = 3;
  2031.   {$EXTERNALSYM CERT_SHA1_HASH_PROP_ID}
  2032.   CERT_MD5_HASH_PROP_ID             = 4;
  2033.   {$EXTERNALSYM CERT_MD5_HASH_PROP_ID}
  2034.   CERT_HASH_PROP_ID                 = CERT_SHA1_HASH_PROP_ID;
  2035.   {$EXTERNALSYM CERT_HASH_PROP_ID}
  2036.   CERT_KEY_CONTEXT_PROP_ID          = 5;
  2037.   {$EXTERNALSYM CERT_KEY_CONTEXT_PROP_ID}
  2038.   CERT_KEY_SPEC_PROP_ID             = 6;
  2039.   {$EXTERNALSYM CERT_KEY_SPEC_PROP_ID}
  2040.   CERT_IE30_RESERVED_PROP_ID        = 7;
  2041.   {$EXTERNALSYM CERT_IE30_RESERVED_PROP_ID}
  2042.   CERT_PUBKEY_HASH_RESERVED_PROP_ID = 8;
  2043.   {$EXTERNALSYM CERT_PUBKEY_HASH_RESERVED_PROP_ID}
  2044.   CERT_ENHKEY_USAGE_PROP_ID         = 9;
  2045.   {$EXTERNALSYM CERT_ENHKEY_USAGE_PROP_ID}
  2046.   CERT_CTL_USAGE_PROP_ID            = CERT_ENHKEY_USAGE_PROP_ID;
  2047.   {$EXTERNALSYM CERT_CTL_USAGE_PROP_ID}
  2048.   CERT_NEXT_UPDATE_LOCATION_PROP_ID = 10;
  2049.   {$EXTERNALSYM CERT_NEXT_UPDATE_LOCATION_PROP_ID}
  2050.   CERT_FRIENDLY_NAME_PROP_ID        = 11;
  2051.   {$EXTERNALSYM CERT_FRIENDLY_NAME_PROP_ID}
  2052.   CERT_PVK_FILE_PROP_ID             = 12;
  2053.   {$EXTERNALSYM CERT_PVK_FILE_PROP_ID}
  2054.   CERT_DESCRIPTION_PROP_ID          = 13;
  2055.   {$EXTERNALSYM CERT_DESCRIPTION_PROP_ID}
  2056.   CERT_ACCESS_STATE_PROP_ID         = 14;
  2057.   {$EXTERNALSYM CERT_ACCESS_STATE_PROP_ID}
  2058.   CERT_SIGNATURE_HASH_PROP_ID       = 15;
  2059.   {$EXTERNALSYM CERT_SIGNATURE_HASH_PROP_ID}
  2060.   CERT_SMART_CARD_DATA_PROP_ID      = 16;
  2061.   {$EXTERNALSYM CERT_SMART_CARD_DATA_PROP_ID}
  2062.   CERT_EFS_PROP_ID                  = 17;
  2063.   {$EXTERNALSYM CERT_EFS_PROP_ID}
  2064.   CERT_FORTEZZA_DATA_PROP_ID        = 18;
  2065.   {$EXTERNALSYM CERT_FORTEZZA_DATA_PROP_ID}
  2066.   CERT_ARCHIVED_PROP_ID             = 19;
  2067.   {$EXTERNALSYM CERT_ARCHIVED_PROP_ID}
  2068.   CERT_KEY_IDENTIFIER_PROP_ID       = 20;
  2069.   {$EXTERNALSYM CERT_KEY_IDENTIFIER_PROP_ID}
  2070.   CERT_AUTO_ENROLL_PROP_ID          = 21;
  2071.   {$EXTERNALSYM CERT_AUTO_ENROLL_PROP_ID}
  2072.   CERT_PUBKEY_ALG_PARA_PROP_ID      = 22;
  2073.   {$EXTERNALSYM CERT_PUBKEY_ALG_PARA_PROP_ID}
  2074.   CERT_FIRST_RESERVED_PROP_ID = 23;
  2075.   {$EXTERNALSYM CERT_FIRST_RESERVED_PROP_ID}
  2076. // Note, 32 - 35 are reserved for the CERT, CRL, CTL and KeyId file element IDs.
  2077.   CERT_LAST_RESERVED_PROP_ID = $00007FFF;
  2078.   {$EXTERNALSYM CERT_LAST_RESERVED_PROP_ID}
  2079.   CERT_FIRST_USER_PROP_ID    = $00008000;
  2080.   {$EXTERNALSYM CERT_FIRST_USER_PROP_ID}
  2081.   CERT_LAST_USER_PROP_ID     = $0000FFFF;
  2082.   {$EXTERNALSYM CERT_LAST_USER_PROP_ID}
  2083. function IS_CERT_HASH_PROP_ID(X: DWORD): Boolean;
  2084. {$EXTERNALSYM IS_CERT_HASH_PROP_ID}
  2085. //+-------------------------------------------------------------------------
  2086. //  Access State flags returned by CERT_ACCESS_STATE_PROP_ID. Note,
  2087. //  CERT_ACCESS_PROP_ID is read only.
  2088. //--------------------------------------------------------------------------
  2089. // Set if context property writes are persisted. For instance, not set for
  2090. // memory store contexts. Set for registry based stores opened as read or write.
  2091. // Not set for registry based stores opened as read only.
  2092. const
  2093.   CERT_ACCESS_STATE_WRITE_PERSIST_FLAG = $1;
  2094.   {$EXTERNALSYM CERT_ACCESS_STATE_WRITE_PERSIST_FLAG}
  2095. // Set if context resides in a SYSTEM or SYSTEM_REGISTRY store.
  2096.   CERT_ACCESS_STATE_SYSTEM_STORE_FLAG = $2;
  2097.   {$EXTERNALSYM CERT_ACCESS_STATE_SYSTEM_STORE_FLAG}
  2098. //+-------------------------------------------------------------------------
  2099. //  Cryptographic Key Provider Information
  2100. //
  2101. //  CRYPT_KEY_PROV_INFO defines the CERT_KEY_PROV_INFO_PROP_ID's pvData.
  2102. //
  2103. //  The CRYPT_KEY_PROV_INFO fields are passed to CryptAcquireContext
  2104. //  to get a HCRYPTPROV handle. The optional CRYPT_KEY_PROV_PARAM fields are
  2105. //  passed to CryptSetProvParam to further initialize the provider.
  2106. //
  2107. //  The dwKeySpec field identifies the private key to use from the container
  2108. //  For example, AT_KEYEXCHANGE or AT_SIGNATURE.
  2109. //--------------------------------------------------------------------------
  2110. type
  2111.   PCRYPT_KEY_PROV_PARAM = ^CRYPT_KEY_PROV_PARAM;
  2112.   {$EXTERNALSYM PCRYPT_KEY_PROV_PARAM}
  2113.   _CRYPT_KEY_PROV_PARAM = record
  2114.     dwParam: DWORD;
  2115.     pbData: LPBYTE;
  2116.     cbData: DWORD;
  2117.     dwFlags: DWORD;
  2118.   end;
  2119.   {$EXTERNALSYM _CRYPT_KEY_PROV_PARAM}
  2120.   CRYPT_KEY_PROV_PARAM = _CRYPT_KEY_PROV_PARAM;
  2121.   {$EXTERNALSYM CRYPT_KEY_PROV_PARAM}
  2122.   TCryptKeyProvParam = CRYPT_KEY_PROV_PARAM;
  2123.   PCryptKeyProvParam = PCRYPT_KEY_PROV_PARAM;
  2124.   PCRYPT_KEY_PROV_INFO = ^CRYPT_KEY_PROV_INFO;
  2125.   {$EXTERNALSYM PCRYPT_KEY_PROV_INFO}
  2126.   _CRYPT_KEY_PROV_INFO = record
  2127.     pwszContainerName: LPWSTR;
  2128.     pwszProvName: LPWSTR;
  2129.     dwProvType: DWORD;
  2130.     dwFlags: DWORD;
  2131.     cProvParam: DWORD;
  2132.     rgProvParam: PCRYPT_KEY_PROV_PARAM;
  2133.     dwKeySpec: DWORD;
  2134.   end;
  2135.   {$EXTERNALSYM _CRYPT_KEY_PROV_INFO}
  2136.   CRYPT_KEY_PROV_INFO = _CRYPT_KEY_PROV_INFO;
  2137.   {$EXTERNALSYM CRYPT_KEY_PROV_INFO}
  2138.   TCryptKeyProvInfo = CRYPT_KEY_PROV_INFO;
  2139.   PCryptKeyProvInfo = PCRYPT_KEY_PROV_INFO;
  2140. //+-------------------------------------------------------------------------
  2141. //  The following flag should be set in the above dwFlags to enable
  2142. //  a CertSetCertificateContextProperty(CERT_KEY_CONTEXT_PROP_ID) after a
  2143. //  CryptAcquireContext is done in the Sign or Decrypt Message functions.
  2144. //
  2145. //  The following define must not collide with any of the
  2146. //  CryptAcquireContext dwFlag defines.
  2147. //--------------------------------------------------------------------------
  2148. const
  2149.   CERT_SET_KEY_PROV_HANDLE_PROP_ID = $00000001;
  2150.   {$EXTERNALSYM CERT_SET_KEY_PROV_HANDLE_PROP_ID}
  2151.   CERT_SET_KEY_CONTEXT_PROP_ID     = $00000001;
  2152.   {$EXTERNALSYM CERT_SET_KEY_CONTEXT_PROP_ID}
  2153. //+-------------------------------------------------------------------------
  2154. //  Certificate Key Context
  2155. //
  2156. //  CERT_KEY_CONTEXT defines the CERT_KEY_CONTEXT_PROP_ID's pvData.
  2157. //--------------------------------------------------------------------------
  2158. type
  2159.   PCERT_KEY_CONTEXT = ^CERT_KEY_CONTEXT;
  2160.   {$EXTERNALSYM PCERT_KEY_CONTEXT}
  2161.   _CERT_KEY_CONTEXT = record
  2162.     cbSize: DWORD; // sizeof(CERT_KEY_CONTEXT)
  2163.     hCryptProv: HCRYPTPROV;
  2164.     dwKeySpec: DWORD;
  2165.   end;
  2166.   {$EXTERNALSYM _CERT_KEY_CONTEXT}
  2167.   CERT_KEY_CONTEXT = _CERT_KEY_CONTEXT;
  2168.   {$EXTERNALSYM CERT_KEY_CONTEXT}
  2169.   TCertKeyContext = CERT_KEY_CONTEXT;
  2170.   PCertKeyContext = PCERT_KEY_CONTEXT;
  2171. //+-------------------------------------------------------------------------
  2172. //  Certificate Store Provider Types
  2173. //--------------------------------------------------------------------------
  2174. const
  2175.   CERT_STORE_PROV_MSG    = LPCSTR(1);
  2176.   {$EXTERNALSYM CERT_STORE_PROV_MSG}
  2177.   CERT_STORE_PROV_MEMORY = LPCSTR(2);
  2178.   {$EXTERNALSYM CERT_STORE_PROV_MEMORY}
  2179.   CERT_STORE_PROV_FILE   = LPCSTR(3);
  2180.   {$EXTERNALSYM CERT_STORE_PROV_FILE}
  2181.   CERT_STORE_PROV_REG    = LPCSTR(4);
  2182.   {$EXTERNALSYM CERT_STORE_PROV_REG}
  2183.   CERT_STORE_PROV_PKCS7      = LPCSTR(5);
  2184.   {$EXTERNALSYM CERT_STORE_PROV_PKCS7}
  2185.   CERT_STORE_PROV_SERIALIZED = LPCSTR(6);
  2186.   {$EXTERNALSYM CERT_STORE_PROV_SERIALIZED}
  2187.   CERT_STORE_PROV_FILENAME_A = LPCSTR(7);
  2188.   {$EXTERNALSYM CERT_STORE_PROV_FILENAME_A}
  2189.   CERT_STORE_PROV_FILENAME_W = LPCSTR(8);
  2190.   {$EXTERNALSYM CERT_STORE_PROV_FILENAME_W}
  2191.   CERT_STORE_PROV_FILENAME   = CERT_STORE_PROV_FILENAME_W;
  2192.   {$EXTERNALSYM CERT_STORE_PROV_FILENAME}
  2193.   CERT_STORE_PROV_SYSTEM_A   = LPCSTR(9);
  2194.   {$EXTERNALSYM CERT_STORE_PROV_SYSTEM_A}
  2195.   CERT_STORE_PROV_SYSTEM_W   = LPCSTR(10);
  2196.   {$EXTERNALSYM CERT_STORE_PROV_SYSTEM_W}
  2197.   CERT_STORE_PROV_SYSTEM     = CERT_STORE_PROV_SYSTEM_W;
  2198.   {$EXTERNALSYM CERT_STORE_PROV_SYSTEM}
  2199.   CERT_STORE_PROV_COLLECTION        = LPCSTR(11);
  2200.   {$EXTERNALSYM CERT_STORE_PROV_COLLECTION}
  2201.   CERT_STORE_PROV_SYSTEM_REGISTRY_A = LPCSTR(12);
  2202.   {$EXTERNALSYM CERT_STORE_PROV_SYSTEM_REGISTRY_A}
  2203.   CERT_STORE_PROV_SYSTEM_REGISTRY_W = LPCSTR(13);
  2204.   {$EXTERNALSYM CERT_STORE_PROV_SYSTEM_REGISTRY_W}
  2205.   CERT_STORE_PROV_SYSTEM_REGISTRY   = CERT_STORE_PROV_SYSTEM_REGISTRY_W;
  2206.   {$EXTERNALSYM CERT_STORE_PROV_SYSTEM_REGISTRY}
  2207.   CERT_STORE_PROV_PHYSICAL_W        = LPCSTR(14);
  2208.   {$EXTERNALSYM CERT_STORE_PROV_PHYSICAL_W}
  2209.   CERT_STORE_PROV_PHYSICAL          = CERT_STORE_PROV_PHYSICAL_W;
  2210.   {$EXTERNALSYM CERT_STORE_PROV_PHYSICAL}
  2211.   CERT_STORE_PROV_SMART_CARD_W      = LPCSTR(15);
  2212.   {$EXTERNALSYM CERT_STORE_PROV_SMART_CARD_W}
  2213.   CERT_STORE_PROV_SMART_CARD        = CERT_STORE_PROV_SMART_CARD_W;
  2214.   {$EXTERNALSYM CERT_STORE_PROV_SMART_CARD}
  2215.   CERT_STORE_PROV_LDAP_W            = LPCSTR(16);
  2216.   {$EXTERNALSYM CERT_STORE_PROV_LDAP_W}
  2217.   CERT_STORE_PROV_LDAP              = CERT_STORE_PROV_LDAP_W;
  2218.   {$EXTERNALSYM CERT_STORE_PROV_LDAP}
  2219.   sz_CERT_STORE_PROV_MEMORY     = 'Memory';
  2220.   {$EXTERNALSYM sz_CERT_STORE_PROV_MEMORY}
  2221.   sz_CERT_STORE_PROV_FILENAME_W = 'File';
  2222.   {$EXTERNALSYM sz_CERT_STORE_PROV_FILENAME_W}
  2223.   sz_CERT_STORE_PROV_FILENAME   = sz_CERT_STORE_PROV_FILENAME_W;
  2224.   {$EXTERNALSYM sz_CERT_STORE_PROV_FILENAME}
  2225.   sz_CERT_STORE_PROV_SYSTEM_W   = 'System';
  2226.   {$EXTERNALSYM sz_CERT_STORE_PROV_SYSTEM_W}
  2227.   sz_CERT_STORE_PROV_SYSTEM     = sz_CERT_STORE_PROV_SYSTEM_W;
  2228.   {$EXTERNALSYM sz_CERT_STORE_PROV_SYSTEM}
  2229.   sz_CERT_STORE_PROV_PKCS7      = 'PKCS7';
  2230.   {$EXTERNALSYM sz_CERT_STORE_PROV_PKCS7}
  2231.   sz_CERT_STORE_PROV_SERIALIZED = 'Serialized';
  2232.   {$EXTERNALSYM sz_CERT_STORE_PROV_SERIALIZED}
  2233.   sz_CERT_STORE_PROV_COLLECTION        = 'Collection';
  2234.   {$EXTERNALSYM sz_CERT_STORE_PROV_COLLECTION}
  2235.   sz_CERT_STORE_PROV_SYSTEM_REGISTRY_W = 'SystemRegistry';
  2236.   {$EXTERNALSYM sz_CERT_STORE_PROV_SYSTEM_REGISTRY_W}
  2237.   sz_CERT_STORE_PROV_SYSTEM_REGISTRY   = sz_CERT_STORE_PROV_SYSTEM_REGISTRY_W;
  2238.   {$EXTERNALSYM sz_CERT_STORE_PROV_SYSTEM_REGISTRY}
  2239.   sz_CERT_STORE_PROV_PHYSICAL_W        = 'Physical';
  2240.   {$EXTERNALSYM sz_CERT_STORE_PROV_PHYSICAL_W}
  2241.   sz_CERT_STORE_PROV_PHYSICAL          = sz_CERT_STORE_PROV_PHYSICAL_W;
  2242.   {$EXTERNALSYM sz_CERT_STORE_PROV_PHYSICAL}
  2243.   sz_CERT_STORE_PROV_SMART_CARD_W      = 'SmartCard';
  2244.   {$EXTERNALSYM sz_CERT_STORE_PROV_SMART_CARD_W}
  2245.   sz_CERT_STORE_PROV_SMART_CARD        = sz_CERT_STORE_PROV_SMART_CARD_W;
  2246.   {$EXTERNALSYM sz_CERT_STORE_PROV_SMART_CARD}
  2247.   sz_CERT_STORE_PROV_LDAP_W            = 'Ldap';
  2248.   {$EXTERNALSYM sz_CERT_STORE_PROV_LDAP_W}
  2249.   sz_CERT_STORE_PROV_LDAP              = sz_CERT_STORE_PROV_LDAP_W;
  2250.   {$EXTERNALSYM sz_CERT_STORE_PROV_LDAP}
  2251. //+-------------------------------------------------------------------------
  2252. //  Certificate Store verify/results flags
  2253. //--------------------------------------------------------------------------
  2254.   CERT_STORE_SIGNATURE_FLAG     = $00000001;
  2255.   {$EXTERNALSYM CERT_STORE_SIGNATURE_FLAG}
  2256.   CERT_STORE_TIME_VALIDITY_FLAG = $00000002;
  2257.   {$EXTERNALSYM CERT_STORE_TIME_VALIDITY_FLAG}
  2258.   CERT_STORE_REVOCATION_FLAG    = $00000004;
  2259.   {$EXTERNALSYM CERT_STORE_REVOCATION_FLAG}
  2260.   CERT_STORE_NO_CRL_FLAG        = $00010000;
  2261.   {$EXTERNALSYM CERT_STORE_NO_CRL_FLAG}
  2262.   CERT_STORE_NO_ISSUER_FLAG     = $00020000;
  2263.   {$EXTERNALSYM CERT_STORE_NO_ISSUER_FLAG}
  2264. //+-------------------------------------------------------------------------
  2265. //  Certificate Store open/property flags
  2266. //--------------------------------------------------------------------------
  2267.   CERT_STORE_NO_CRYPT_RELEASE_FLAG            = $00000001;
  2268.   {$EXTERNALSYM CERT_STORE_NO_CRYPT_RELEASE_FLAG}
  2269.   CERT_STORE_SET_LOCALIZED_NAME_FLAG          = $00000002;
  2270.   {$EXTERNALSYM CERT_STORE_SET_LOCALIZED_NAME_FLAG}
  2271.   CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG = $00000004;
  2272.   {$EXTERNALSYM CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG}
  2273.   CERT_STORE_DELETE_FLAG                      = $00000010;
  2274.   {$EXTERNALSYM CERT_STORE_DELETE_FLAG}
  2275.   CERT_STORE_MANIFOLD_FLAG                    = $00000100;
  2276.   {$EXTERNALSYM CERT_STORE_MANIFOLD_FLAG}
  2277.   CERT_STORE_ENUM_ARCHIVED_FLAG               = $00000200;
  2278.   {$EXTERNALSYM CERT_STORE_ENUM_ARCHIVED_FLAG}
  2279.   CERT_STORE_UPDATE_KEYID_FLAG                = $00000400;
  2280.   {$EXTERNALSYM CERT_STORE_UPDATE_KEYID_FLAG}
  2281.   CERT_STORE_READONLY_FLAG                    = $00008000;
  2282.   {$EXTERNALSYM CERT_STORE_READONLY_FLAG}
  2283.   CERT_STORE_OPEN_EXISTING_FLAG               = $00004000;
  2284.   {$EXTERNALSYM CERT_STORE_OPEN_EXISTING_FLAG}
  2285.   CERT_STORE_CREATE_NEW_FLAG                  = $00002000;
  2286.   {$EXTERNALSYM CERT_STORE_CREATE_NEW_FLAG}
  2287.   CERT_STORE_MAXIMUM_ALLOWED_FLAG             = $00001000;
  2288.   {$EXTERNALSYM CERT_STORE_MAXIMUM_ALLOWED_FLAG}
  2289. //+-------------------------------------------------------------------------
  2290. //  Certificate Store Provider flags are in the HiWord (0xFFFF0000)
  2291. //--------------------------------------------------------------------------
  2292. //+-------------------------------------------------------------------------
  2293. //  Certificate System Store Flag Values
  2294. //--------------------------------------------------------------------------
  2295. // Includes flags and location
  2296.   CERT_SYSTEM_STORE_MASK = DWORD($FFFF0000);
  2297.   {$EXTERNALSYM CERT_SYSTEM_STORE_MASK}
  2298. // Set if pvPara points to a CERT_SYSTEM_STORE_RELOCATE_PARA structure
  2299.   CERT_SYSTEM_STORE_RELOCATE_FLAG = DWORD($80000000);
  2300.   {$EXTERNALSYM CERT_SYSTEM_STORE_RELOCATE_FLAG}
  2301. type
  2302.   PCERT_SYSTEM_STORE_RELOCATE_PARA = ^CERT_SYSTEM_STORE_RELOCATE_PARA;
  2303.   {$EXTERNALSYM PCERT_SYSTEM_STORE_RELOCATE_PARA}
  2304.   _CERT_SYSTEM_STORE_RELOCATE_PARA = record
  2305.     Union1: record
  2306.     case Integer of
  2307.       0: (hKeyBase: HKEY);
  2308.       1: (pvBase: Pointer);
  2309.     end;
  2310.     case Integer of
  2311.       0: (pvSystemStore: Pointer);
  2312.       1: (pszSystemStore: LPCSTR);
  2313.       2: (pwszSystemStore: LPCWSTR);
  2314.   end;
  2315.   {$EXTERNALSYM _CERT_SYSTEM_STORE_RELOCATE_PARA}
  2316.   CERT_SYSTEM_STORE_RELOCATE_PARA = _CERT_SYSTEM_STORE_RELOCATE_PARA;
  2317.   {$EXTERNALSYM CERT_SYSTEM_STORE_RELOCATE_PARA}
  2318.   TCertSystemStoreRelocatePara = CERT_SYSTEM_STORE_RELOCATE_PARA;
  2319.   PCertSystemStoreRelocatePara = PCERT_SYSTEM_STORE_RELOCATE_PARA;
  2320. // By default, when the CurrentUser "Root" store is opened, any SystemRegistry
  2321. // roots not also on the protected root list are deleted from the cache before
  2322. // CertOpenStore() returns. Set the following flag to return all the roots
  2323. // in the SystemRegistry without checking the protected root list.
  2324. const
  2325.   CERT_SYSTEM_STORE_UNPROTECTED_FLAG = $40000000;
  2326.   {$EXTERNALSYM CERT_SYSTEM_STORE_UNPROTECTED_FLAG}
  2327. // Location of the system store:
  2328.   CERT_SYSTEM_STORE_LOCATION_MASK  = $00FF0000;
  2329.   {$EXTERNALSYM CERT_SYSTEM_STORE_LOCATION_MASK}
  2330.   CERT_SYSTEM_STORE_LOCATION_SHIFT = 16;
  2331.   {$EXTERNALSYM CERT_SYSTEM_STORE_LOCATION_SHIFT}
  2332. //  Registry: HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE
  2333.   CERT_SYSTEM_STORE_CURRENT_USER_ID  = 1;
  2334.   {$EXTERNALSYM CERT_SYSTEM_STORE_CURRENT_USER_ID}
  2335.   CERT_SYSTEM_STORE_LOCAL_MACHINE_ID = 2;
  2336.   {$EXTERNALSYM CERT_SYSTEM_STORE_LOCAL_MACHINE_ID}
  2337. //  Registry: HKEY_LOCAL_MACHINESoftwareMicrosoftCryptographyServices
  2338.   CERT_SYSTEM_STORE_CURRENT_SERVICE_ID = 4;
  2339.   {$EXTERNALSYM CERT_SYSTEM_STORE_CURRENT_SERVICE_ID}
  2340.   CERT_SYSTEM_STORE_SERVICES_ID        = 5;
  2341.   {$EXTERNALSYM CERT_SYSTEM_STORE_SERVICES_ID}
  2342. //  Registry: HKEY_USERS
  2343.   CERT_SYSTEM_STORE_USERS_ID = 6;
  2344.   {$EXTERNALSYM CERT_SYSTEM_STORE_USERS_ID}
  2345. //  Registry: HKEY_CURRENT_USERSoftwarePoliciesMicrosoftSystemCertificates
  2346.   CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY_ID = 7;
  2347.   {$EXTERNALSYM CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY_ID}
  2348. //  Registry: HKEY_LOCAL_MACHINESoftwarePoliciesMicrosoftSystemCertificates
  2349.   CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY_ID = 8;
  2350.   {$EXTERNALSYM CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY_ID}
  2351. //  Registry: HKEY_LOCAL_MACHINESoftwareMicrosoftEnterpriseCertificates
  2352.   CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE_ID = 9;
  2353.   {$EXTERNALSYM CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE_ID}
  2354.   CERT_SYSTEM_STORE_CURRENT_USER    = (CERT_SYSTEM_STORE_CURRENT_USER_ID shl CERT_SYSTEM_STORE_LOCATION_SHIFT);
  2355.   {$EXTERNALSYM CERT_SYSTEM_STORE_CURRENT_USER}
  2356.   CERT_SYSTEM_STORE_LOCAL_MACHINE   = (CERT_SYSTEM_STORE_LOCAL_MACHINE_ID shl CERT_SYSTEM_STORE_LOCATION_SHIFT);
  2357.   {$EXTERNALSYM CERT_SYSTEM_STORE_LOCAL_MACHINE}
  2358.   CERT_SYSTEM_STORE_CURRENT_SERVICE = (CERT_SYSTEM_STORE_CURRENT_SERVICE_ID shl CERT_SYSTEM_STORE_LOCATION_SHIFT);
  2359.   {$EXTERNALSYM CERT_SYSTEM_STORE_CURRENT_SERVICE}
  2360.   CERT_SYSTEM_STORE_SERVICES        = (CERT_SYSTEM_STORE_SERVICES_ID shl CERT_SYSTEM_STORE_LOCATION_SHIFT);
  2361.   {$EXTERNALSYM CERT_SYSTEM_STORE_SERVICES}
  2362.   CERT_SYSTEM_STORE_USERS           = (CERT_SYSTEM_STORE_USERS_ID shl CERT_SYSTEM_STORE_LOCATION_SHIFT);
  2363.   {$EXTERNALSYM CERT_SYSTEM_STORE_USERS}
  2364.   CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY  = (CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY_ID shl CERT_SYSTEM_STORE_LOCATION_SHIFT);
  2365.   {$EXTERNALSYM CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY}
  2366.   CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY = (CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY_ID shl CERT_SYSTEM_STORE_LOCATION_SHIFT);
  2367.   {$EXTERNALSYM CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY}
  2368.   CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE = (CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE_ID shl CERT_SYSTEM_STORE_LOCATION_SHIFT);
  2369.   {$EXTERNALSYM CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE}
  2370. //+-------------------------------------------------------------------------
  2371. //  Group Policy Store Defines
  2372. //--------------------------------------------------------------------------
  2373. // Registry path to the Group Policy system stores
  2374.   CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH = 'SoftwarePoliciesMicrosoftSystemCertificates';
  2375.   {$EXTERNALSYM CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH}
  2376. //+-------------------------------------------------------------------------
  2377. //  EFS Defines
  2378. //--------------------------------------------------------------------------
  2379. // Registry path to the EFS EFSBlob SubKey - Value type is REG_BINARY
  2380.   CERT_EFSBLOB_REGPATH    = CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH + 'EFS';
  2381.   {$EXTERNALSYM CERT_EFSBLOB_REGPATH}
  2382.   CERT_EFSBLOB_VALUE_NAME = 'EFSBlob';
  2383.   {$EXTERNALSYM CERT_EFSBLOB_VALUE_NAME}
  2384. //+-------------------------------------------------------------------------
  2385. //  Protected Root Defines
  2386. //--------------------------------------------------------------------------
  2387. // Registry path to the Protected Roots Flags SubKey
  2388.   CERT_PROT_ROOT_FLAGS_REGPATH    = CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH + 'RootProtectedRoots';
  2389.   {$EXTERNALSYM CERT_PROT_ROOT_FLAGS_REGPATH}
  2390.   CERT_PROT_ROOT_FLAGS_VALUE_NAME = 'Flags';
  2391.   {$EXTERNALSYM CERT_PROT_ROOT_FLAGS_VALUE_NAME}
  2392. // Set the following flag to inhibit the opening of the CurrentUser's
  2393. // .Default physical store when opening the CurrentUser's "Root" system store.
  2394. // The .Default physical store open's the CurrentUser SystemRegistry "Root"
  2395. // store.
  2396.   CERT_PROT_ROOT_DISABLE_CURRENT_USER_FLAG = $1;
  2397.   {$EXTERNALSYM CERT_PROT_ROOT_DISABLE_CURRENT_USER_FLAG}
  2398. // Set the following flag to inhibit the adding of roots from the
  2399. // CurrentUser SystemRegistry "Root" store to the protected root list
  2400. // when the "Root" store is initially protected.
  2401.   CERT_PROT_ROOT_INHIBIT_ADD_AT_INIT_FLAG = $2;
  2402.   {$EXTERNALSYM CERT_PROT_ROOT_INHIBIT_ADD_AT_INIT_FLAG}
  2403. // Set the following flag to inhibit the purging of protected roots from the
  2404. // CurrentUser SystemRegistry "Root" store that are
  2405. // also in the LocalMachine SystemRegistry "Root" store. Note, when not
  2406. // disabled, the purging is done silently without UI.
  2407.   CERT_PROT_ROOT_INHIBIT_PURGE_LM_FLAG = $4;
  2408.   {$EXTERNALSYM CERT_PROT_ROOT_INHIBIT_PURGE_LM_FLAG}
  2409. // Set the following flag to only open the .LocalMachineGroupPolicy
  2410. // physical store when opening the CurrentUser's "Root" system store.
  2411.   CERT_PROT_ROOT_ONLY_LM_GPT_FLAG = $8;
  2412.   {$EXTERNALSYM CERT_PROT_ROOT_ONLY_LM_GPT_FLAG}
  2413. //+-------------------------------------------------------------------------
  2414. //  Certificate Registry Store Flag Values (CERT_STORE_REG)
  2415. //--------------------------------------------------------------------------
  2416. // Set this flag if the HKEY passed in pvPara points to a remote computer
  2417. // registry key.
  2418.   CERT_REGISTRY_STORE_REMOTE_FLAG = $10000;
  2419.   {$EXTERNALSYM CERT_REGISTRY_STORE_REMOTE_FLAG}
  2420. // Set this flag if the contexts are to be persisted as a single serialized
  2421. // store in the registry. Mainly used for stores downloaded from the GPT.
  2422. // Such as the CurrentUserGroupPolicy or LocalMachineGroupPolicy stores.
  2423.   CERT_REGISTRY_STORE_SERIALIZED_FLAG = $20000;
  2424.   {$EXTERNALSYM CERT_REGISTRY_STORE_SERIALIZED_FLAG}
  2425. // The following flags are for internal use. When set, the
  2426. // pvPara parameter passed to CertOpenStore is a pointer to the following
  2427. // data structure and not the HKEY. The above CERT_REGISTRY_STORE_REMOTE_FLAG
  2428. // is also set if hKeyBase was obtained via RegConnectRegistry().
  2429.   CERT_REGISTRY_STORE_CLIENT_GPT_FLAG = DWORD($80000000);
  2430.   {$EXTERNALSYM CERT_REGISTRY_STORE_CLIENT_GPT_FLAG}
  2431.   CERT_REGISTRY_STORE_LM_GPT_FLAG     = $01000000;
  2432.   {$EXTERNALSYM CERT_REGISTRY_STORE_LM_GPT_FLAG}
  2433. type
  2434.   PCERT_REGISTRY_STORE_CLIENT_GPT_PARA = ^CERT_REGISTRY_STORE_CLIENT_GPT_PARA;
  2435.   {$EXTERNALSYM PCERT_REGISTRY_STORE_CLIENT_GPT_PARA}
  2436.   _CERT_REGISTRY_STORE_CLIENT_GPT_PARA = record
  2437.     hKeyBase: HKEY;
  2438.     pwszRegPath: LPWSTR;
  2439.   end;
  2440.   {$EXTERNALSYM _CERT_REGISTRY_STORE_CLIENT_GPT_PARA}
  2441.   CERT_REGISTRY_STORE_CLIENT_GPT_PARA = _CERT_REGISTRY_STORE_CLIENT_GPT_PARA;
  2442.   {$EXTERNALSYM CERT_REGISTRY_STORE_CLIENT_GPT_PARA}
  2443.   TCertRegistryStoreClientGptPara = CERT_REGISTRY_STORE_CLIENT_GPT_PARA;
  2444.   PCertRegistryStoreClientGptPara = PCERT_REGISTRY_STORE_CLIENT_GPT_PARA;
  2445. // The following flag is for internal use. When set, the contexts are
  2446. // persisted into roaming files instead of the registry. Such as, the
  2447. // CurrentUser "My" store. When this flag is set, the following data structure
  2448. // is passed to CertOpenStore instead of HKEY.
  2449. const
  2450.   CERT_REGISTRY_STORE_ROAMING_FLAG = $40000;
  2451.   {$EXTERNALSYM CERT_REGISTRY_STORE_ROAMING_FLAG}
  2452. // hKey may be NULL or non-NULL. When non-NULL, existing contexts are
  2453. // moved from the registry to roaming files.
  2454. type
  2455.   PCERT_REGISTRY_STORE_ROAMING_PARA = ^CERT_REGISTRY_STORE_ROAMING_PARA;
  2456.   {$EXTERNALSYM PCERT_REGISTRY_STORE_ROAMING_PARA}
  2457.   _CERT_REGISTRY_STORE_ROAMING_PARA = record
  2458.     hKey: HKEY;
  2459.     pwszStoreDirectory: LPWSTR;
  2460.   end;
  2461.   {$EXTERNALSYM _CERT_REGISTRY_STORE_ROAMING_PARA}
  2462.   CERT_REGISTRY_STORE_ROAMING_PARA = _CERT_REGISTRY_STORE_ROAMING_PARA;
  2463.   {$EXTERNALSYM CERT_REGISTRY_STORE_ROAMING_PARA}
  2464.   TCertRegistryStoreRoamingPara = CERT_REGISTRY_STORE_ROAMING_PARA;
  2465.   PCertRegistryStoreRoamingPara = PCERT_REGISTRY_STORE_ROAMING_PARA;
  2466. // The following flag is for internal use. When set, the "My" DWORD value
  2467. // at HKLMSoftwareMicrosoftCryptographyIEDirtyFlags is set to 0x1
  2468. // whenever a certificate is added to the registry store.
  2469. const
  2470.   CERT_REGISTRY_STORE_MY_IE_DIRTY_FLAG = $80000;
  2471.   {$EXTERNALSYM CERT_REGISTRY_STORE_MY_IE_DIRTY_FLAG}
  2472. // Registry path to the subkey containing the "My" DWORD value to be set
  2473.   CERT_IE_DIRTY_FLAGS_REGPATH = 'SoftwareMicrosoftCryptographyIEDirtyFlags';
  2474.   {$EXTERNALSYM CERT_IE_DIRTY_FLAGS_REGPATH}
  2475. //+-------------------------------------------------------------------------
  2476. //  Certificate File Store Flag Values for the providers:
  2477. //      CERT_STORE_PROV_FILE
  2478. //      CERT_STORE_PROV_FILENAME
  2479. //      CERT_STORE_PROV_FILENAME_A
  2480. //      CERT_STORE_PROV_FILENAME_W
  2481. //      sz_CERT_STORE_PROV_FILENAME_W
  2482. //--------------------------------------------------------------------------
  2483. // Set this flag if any store changes are to be committed to the file.
  2484. // The changes are committed at CertCloseStore or by calling
  2485. // CertControlStore(CERT_STORE_CTRL_COMMIT).
  2486. //
  2487. // The open fails with E_INVALIDARG if both CERT_FILE_STORE_COMMIT_ENABLE_FLAG
  2488. // and CERT_STORE_READONLY_FLAG are set in dwFlags.
  2489. //
  2490. // For the FILENAME providers:  if the file contains an X509 encoded
  2491. // certificate, the open fails with ERROR_ACCESS_DENIED.
  2492. //
  2493. // For the FILENAME providers: if CERT_STORE_CREATE_NEW_FLAG is set, the
  2494. // CreateFile uses CREATE_NEW. If CERT_STORE_OPEN_EXISTING is set, uses
  2495. // OPEN_EXISTING. Otherwise, defaults to OPEN_ALWAYS.
  2496. //
  2497. // For the FILENAME providers:  the file is committed as either a PKCS7 or
  2498. // serialized store depending on the type read at open. However, if the
  2499. // file is empty then, if the filename has either a ".p7c" or ".spc"
  2500. // extension its committed as a PKCS7. Otherwise, its committed as a
  2501. // serialized store.
  2502. //
  2503. // For CERT_STORE_PROV_FILE, the file handle is duplicated. Its always
  2504. // committed as a serialized store.
  2505. //
  2506.   CERT_FILE_STORE_COMMIT_ENABLE_FLAG = $10000;
  2507.   {$EXTERNALSYM CERT_FILE_STORE_COMMIT_ENABLE_FLAG}
  2508. //+-------------------------------------------------------------------------
  2509. //  Open the cert store using the specified store provider.
  2510. //
  2511. //  If CERT_STORE_DELETE_FLAG is set, then, the store is deleted. NULL is
  2512. //  returned for both success and failure. However, GetLastError() returns 0
  2513. //  for success and nonzero for failure.
  2514. //
  2515. //  If CERT_STORE_SET_LOCALIZED_NAME_FLAG is set, then, if supported, the
  2516. //  provider sets the store's CERT_STORE_LOCALIZED_NAME_PROP_ID property.
  2517. //  The store's localized name can be retrieved by calling
  2518. //  CertSetStoreProperty(dwPropID = CERT_STORE_LOCALIZED_NAME_PROP_ID).
  2519. //  This flag is supported by the following providers (and their sz_
  2520. //  equivalent):
  2521. //      CERT_STORE_PROV_FILENAME_A
  2522. //      CERT_STORE_PROV_FILENAME_W
  2523. //      CERT_STORE_PROV_SYSTEM_A
  2524. //      CERT_STORE_PROV_SYSTEM_W
  2525. //      CERT_STORE_PROV_SYSTEM_REGISTRY_A
  2526. //      CERT_STORE_PROV_SYSTEM_REGISTRY_W
  2527. //      CERT_STORE_PROV_PHYSICAL_W
  2528. //
  2529. //  If CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG is set, then, the
  2530. //  closing of the store's provider is deferred until all certificate,
  2531. //  CRL and CTL contexts obtained from the store are freed. Also,
  2532. //  if a non NULL HCRYPTPROV was passed, then, it will continue to be used.
  2533. //  By default, the store's provider is closed on the final CertCloseStore.
  2534. //  If this flag isn't set, then, any property changes made to previously
  2535. //  duplicated contexts after the final CertCloseStore will not be persisted.
  2536. //  By setting this flag, property changes made
  2537. //  after the CertCloseStore will be persisted. Note, setting this flag
  2538. //  causes extra overhead in doing context duplicates and frees.
  2539. //  If CertCloseStore is called with CERT_CLOSE_STORE_FORCE_FLAG, then,
  2540. //  the CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG flag is ignored.
  2541. //
  2542. //  CERT_STORE_MANIFOLD_FLAG can be set to check for certificates having the
  2543. //  manifold extension and archive the "older" certificates with the same
  2544. //  manifold extension value. A certificate is archived by setting the
  2545. //  CERT_ARCHIVED_PROP_ID.
  2546. //
  2547. //  By default, contexts having the CERT_ARCHIVED_PROP_ID, are skipped
  2548. //  during enumeration. CERT_STORE_ENUM_ARCHIVED_FLAG can be set to include
  2549. //  archived contexts when enumerating. Note, contexts having the
  2550. //  CERT_ARCHIVED_PROP_ID are still found for explicit finds, such as,
  2551. //  finding a context with a specific hash or finding a certificate having
  2552. //  a specific issuer and serial number.
  2553. //
  2554. //  CERT_STORE_UPDATE_KEYID_FLAG can be set to also update the Key Identifier's
  2555. //  CERT_KEY_PROV_INFO_PROP_ID property whenever a certificate's
  2556. //  CERT_KEY_IDENTIFIER_PROP_ID or CERT_KEY_PROV_INFO_PROP_ID property is set
  2557. //  and the other property already exists. If the Key Identifier's
  2558. //  CERT_KEY_PROV_INFO_PROP_ID already exists, it isn't updated. Any
  2559. //  errors encountered are silently ignored.
  2560. //
  2561. //  By default, this flag is implicitly set for the "My.Default" CurrentUser
  2562. //  and LocalMachine physical stores.
  2563. //
  2564. //  CERT_STORE_READONLY_FLAG can be set to open the store as read only.
  2565. //  Otherwise, the store is opened as read/write.
  2566. //
  2567. //  CERT_STORE_OPEN_EXISTING_FLAG can be set to only open an existing
  2568. //  store. CERT_STORE_CREATE_NEW_FLAG can be set to create a new store and
  2569. //  fail if the store already exists. Otherwise, the default is to open
  2570. //  an existing store or create a new store if it doesn't already exist.
  2571. //
  2572. //  hCryptProv specifies the crypto provider to use to create the hash
  2573. //  properties or verify the signature of a subject certificate or CRL.
  2574. //  The store doesn't need to use a private
  2575. //  key. If the CERT_STORE_NO_CRYPT_RELEASE_FLAG isn't set, hCryptProv is
  2576. //  CryptReleaseContext'ed on the final CertCloseStore.
  2577. //
  2578. //  Note, if the open fails, hCryptProv is released if it would have been
  2579. //  released when the store was closed.
  2580. //
  2581. //  If hCryptProv is zero, then, the default provider and container for the
  2582. //  PROV_RSA_FULL provider type is CryptAcquireContext'ed with
  2583. //  CRYPT_VERIFYCONTEXT access. The CryptAcquireContext is deferred until
  2584. //  the first create hash or verify signature. In addition, once acquired,
  2585. //  the default provider isn't released until process exit when crypt32.dll
  2586. //  is unloaded. The acquired default provider is shared across all stores
  2587. //  and threads.
  2588. //
  2589. //  After initializing the store's data structures and optionally acquiring a
  2590. //  default crypt provider, CertOpenStore calls CryptGetOIDFunctionAddress to
  2591. //  get the address of the CRYPT_OID_OPEN_STORE_PROV_FUNC specified by
  2592. //  lpszStoreProvider. Since a store can contain certificates with different
  2593. //  encoding types, CryptGetOIDFunctionAddress is called with dwEncodingType
  2594. //  set to 0 and not the dwEncodingType passed to CertOpenStore.
  2595. //  PFN_CERT_DLL_OPEN_STORE_FUNC specifies the signature of the provider's
  2596. //  open function. This provider open function is called to load the
  2597. //  store's certificates and CRLs. Optionally, the provider may return an
  2598. //  array of functions called before a certificate or CRL is added or deleted
  2599. //  or has a property that is set.
  2600. //
  2601. //  Use of the dwEncodingType parameter is provider dependent. The type
  2602. //  definition for pvPara also depends on the provider.
  2603. //
  2604. //  Store providers are installed or registered via
  2605. //  CryptInstallOIDFunctionAddress or CryptRegisterOIDFunction, where,
  2606. //  dwEncodingType is 0 and pszFuncName is CRYPT_OID_OPEN_STORE_PROV_FUNC.
  2607. //
  2608. //  Here's a list of the predefined provider types (implemented in crypt32.dll):
  2609. //
  2610. //  CERT_STORE_PROV_MSG:
  2611. //      Gets the certificates and CRLs from the specified cryptographic message.
  2612. //      dwEncodingType contains the message and certificate encoding types.
  2613. //      The message's handle is passed in pvPara. Given,
  2614. //          HCRYPTMSG hCryptMsg; pvPara = (const void *) hCryptMsg;
  2615. //
  2616. //  CERT_STORE_PROV_MEMORY
  2617. //  sz_CERT_STORE_PROV_MEMORY:
  2618. //      Opens a store without any initial certificates or CRLs. pvPara
  2619. //      isn't used.
  2620. //
  2621. //  CERT_STORE_PROV_FILE:
  2622. //      Reads the certificates and CRLs from the specified file. The file's
  2623. //      handle is passed in pvPara. Given,
  2624. //          HANDLE hFile; pvPara = (const void *) hFile;
  2625. //
  2626. //      For a successful open, the file pointer is advanced past
  2627. //      the certificates and CRLs and their properties read from the file.
  2628. //      Note, only expects a serialized store and not a file containing
  2629. //      either a PKCS #7 signed message or a single encoded certificate.
  2630. //
  2631. //      The hFile isn't closed.
  2632. //
  2633. //  CERT_STORE_PROV_REG:
  2634. //      Reads the certificates and CRLs from the registry. The registry's
  2635. //      key handle is passed in pvPara. Given,
  2636. //          HKEY hKey; pvPara = (const void *) hKey;
  2637. //
  2638. //      The input hKey isn't closed by the provider. Before returning, the
  2639. //      provider opens it own copy of the hKey.
  2640. //
  2641. //      If CERT_STORE_READONLY_FLAG is set, then, the registry subkeys are
  2642. //      RegOpenKey'ed with KEY_READ_ACCESS. Otherwise, the registry subkeys
  2643. //      are RegCreateKey'ed with KEY_ALL_ACCESS.
  2644. //
  2645. //      This provider returns the array of functions for reading, writing,
  2646. //      deleting and property setting certificates and CRLs.
  2647. //      Any changes to the opened store are immediately pushed through to
  2648. //      the registry. However, if CERT_STORE_READONLY_FLAG is set, then,
  2649. //      writing, deleting or property setting results in a
  2650. //      SetLastError(E_ACCESSDENIED).
  2651. //
  2652. //      Note, all the certificates and CRLs are read from the registry
  2653. //      when the store is opened. The opened store serves as a write through
  2654. //      cache.
  2655. //
  2656. //      If CERT_REGISTRY_STORE_SERIALIZED_FLAG is set, then, the
  2657. //      contexts are persisted as a single serialized store subkey in the
  2658. //      registry.
  2659. //
  2660. //  CERT_STORE_PROV_PKCS7:
  2661. //  sz_CERT_STORE_PROV_PKCS7:
  2662. //      Gets the certificates and CRLs from the encoded PKCS #7 signed message.
  2663. //      dwEncodingType specifies the message and certificate encoding types.
  2664. //      The pointer to the encoded message's blob is passed in pvPara. Given,
  2665. //          CRYPT_DATA_BLOB EncodedMsg; pvPara = (const void *) &EncodedMsg;
  2666. //
  2667. //      Note, also supports the IE3.0 special version of a
  2668. //      PKCS #7 signed message referred to as a "SPC" formatted message.
  2669. //
  2670. //  CERT_STORE_PROV_SERIALIZED:
  2671. //  sz_CERT_STORE_PROV_SERIALIZED:
  2672. //      Gets the certificates and CRLs from memory containing a serialized
  2673. //      store.  The pointer to the serialized memory blob is passed in pvPara.
  2674. //      Given,
  2675. //          CRYPT_DATA_BLOB Serialized; pvPara = (const void *) &Serialized;
  2676. //
  2677. //  CERT_STORE_PROV_FILENAME_A:
  2678. //  CERT_STORE_PROV_FILENAME_W:
  2679. //  CERT_STORE_PROV_FILENAME:
  2680. //  sz_CERT_STORE_PROV_FILENAME_W:
  2681. //  sz_CERT_STORE_PROV_FILENAME:
  2682. //      Opens the file and first attempts to read as a serialized store. Then,
  2683. //      as a PKCS #7 signed message. Finally, as a single encoded certificate.
  2684. //      The filename is passed in pvPara. The filename is UNICODE for the
  2685. //      "_W" provider and ASCII for the "_A" provider. For "_W": given,
  2686. //          LPCWSTR pwszFilename; pvPara = (const void *) pwszFilename;
  2687. //      For "_A": given,
  2688. //          LPCSTR pszFilename; pvPara = (const void *) pszFilename;
  2689. //
  2690. //      Note, the default (without "_A" or "_W") is unicode.
  2691. //