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

Windows编程

开发平台:

Delphi

  1. //  The following flag is applicable when encoding X509_UNICODE_NAME.
  2. //  When set, CERT_RDN_UTF8_STRING is selected instead of
  3. //  CERT_RDN_UNICODE_STRING.
  4.   CRYPT_UNICODE_NAME_ENCODE_ENABLE_UTF8_UNICODE_FLAG = CERT_RDN_ENABLE_UTF8_UNICODE_FLAG;
  5.   {$EXTERNALSYM CRYPT_UNICODE_NAME_ENCODE_ENABLE_UTF8_UNICODE_FLAG}
  6. //  The following flag is applicable when encoding X509_UNICODE_NAME,
  7. //  X509_UNICODE_NAME_VALUE or X509_UNICODE_ANY_STRING.
  8. //  When set, the characters aren't checked to see if they
  9. //  are valid for the specified Value Type.
  10.   CRYPT_UNICODE_NAME_ENCODE_DISABLE_CHECK_TYPE_FLAG = CERT_RDN_DISABLE_CHECK_TYPE_FLAG;
  11.   {$EXTERNALSYM CRYPT_UNICODE_NAME_ENCODE_DISABLE_CHECK_TYPE_FLAG}
  12. //  The following flag is applicable when encoding the PKCS_SORTED_CTL. This
  13. //  flag should be set if the identifier for the TrustedSubjects is a hash,
  14. //  such as, MD5 or SHA1.
  15.   CRYPT_SORTED_CTL_ENCODE_HASHED_SUBJECT_IDENTIFIER_FLAG = $10000;
  16.   {$EXTERNALSYM CRYPT_SORTED_CTL_ENCODE_HASHED_SUBJECT_IDENTIFIER_FLAG}
  17. type
  18.   PCRYPT_DECODE_PARA = ^CRYPT_DECODE_PARA;
  19.   {$EXTERNALSYM PCRYPT_DECODE_PARA}
  20.   _CRYPT_DECODE_PARA = record
  21.     cbSize: DWORD;
  22.     pfnAlloc: PFN_CRYPT_ALLOC; // OPTIONAL
  23.     pfnFree: PFN_CRYPT_FREE;   // OPTIONAL
  24.   end;
  25.   {$EXTERNALSYM _CRYPT_DECODE_PARA}
  26.   CRYPT_DECODE_PARA = _CRYPT_DECODE_PARA;
  27.   {$EXTERNALSYM CRYPT_DECODE_PARA}
  28.   TCryptDecodePara = CRYPT_DECODE_PARA;
  29.   PCryptDecodePara = PCRYPT_DECODE_PARA;
  30. function CryptDecodeObjectEx(dwCertEncodingType: DWORD; lpszStructType: LPCSTR;
  31.   pbEncoded: Pointer; cbEncoded, dwFlags: DWORD; pDecodePara: PCRYPT_DECODE_PARA;
  32.   pvStructInfo: Pointer; var pcbStructInfo: DWORD): BOOL; stdcall;
  33. {$EXTERNALSYM CryptDecodeObjectEx}
  34. function CryptDecodeObject(dwCertEncodingType: DWORD; lpszStructType: LPCSTR;
  35.   pbEncoded: LPBYTE; cbEncoded, dwFlags: DWORD; pvStructInfo: Pointer;
  36.   var pcbStructInfo: DWORD): BOOL; stdcall;
  37. {$EXTERNALSYM CryptDecodeObject}
  38. // When the following flag is set the nocopy optimization is enabled.
  39. // This optimization where appropriate, updates the pvStructInfo fields
  40. // to point to content residing within pbEncoded instead of making a copy
  41. // of and appending to pvStructInfo.
  42. //
  43. // Note, when set, pbEncoded can't be freed until pvStructInfo is freed.
  44. const
  45.   CRYPT_DECODE_NOCOPY_FLAG = $1;
  46.   {$EXTERNALSYM CRYPT_DECODE_NOCOPY_FLAG}
  47. // For CryptDecodeObject(), by default the pbEncoded is the "to be signed"
  48. // plus its signature. Set the following flag, if pbEncoded points to only
  49. // the "to be signed".
  50. //
  51. // This flag is applicable to
  52. //      X509_CERT_TO_BE_SIGNED
  53. //      X509_CERT_CRL_TO_BE_SIGNED
  54. //      X509_CERT_REQUEST_TO_BE_SIGNED
  55. //      X509_KEYGEN_REQUEST_TO_BE_SIGNED
  56.   CRYPT_DECODE_TO_BE_SIGNED_FLAG = $2;
  57.   {$EXTERNALSYM CRYPT_DECODE_TO_BE_SIGNED_FLAG}
  58. // When the following flag is set, the OID strings are allocated in
  59. // crypt32.dll and shared instead of being copied into the returned
  60. // data structure. This flag may be set if crypt32.dll isn't unloaded
  61. // before the caller is unloaded.
  62.   CRYPT_DECODE_SHARE_OID_STRING_FLAG = $4;
  63.   {$EXTERNALSYM CRYPT_DECODE_SHARE_OID_STRING_FLAG}
  64. // By default the signature bytes are reversed. The following flag can
  65. // be set to inhibit the byte reversal.
  66. //
  67. // This flag is applicable to
  68. //      X509_CERT_TO_BE_SIGNED
  69.   CRYPT_DECODE_NO_SIGNATURE_BYTE_REVERSAL_FLAG = $8;
  70.   {$EXTERNALSYM CRYPT_DECODE_NO_SIGNATURE_BYTE_REVERSAL_FLAG}
  71. // When the following flag is set the called decode function allocates
  72. // memory for the decoded structure. A pointer to the allocated structure
  73. // is returned in pvStructInfo. If pDecodePara or pDecodePara->pfnAlloc is
  74. // NULL, then, LocalAlloc is called for the allocation and LocalFree must
  75. // be called to do the free. Otherwise, pDecodePara->pfnAlloc is called
  76. // for the allocation.
  77. //
  78. // *pcbStructInfo is ignored on input and updated with the length of the
  79. // allocated, decoded structure.
  80. //
  81. // This flag may also be set in the CryptDecodeObject API. Since
  82. // CryptDecodeObject doesn't take a pDecodePara, LocalAlloc is always
  83. // called for the allocation which must be freed by calling LocalFree.
  84.   CRYPT_DECODE_ALLOC_FLAG = $8000;
  85.   {$EXTERNALSYM CRYPT_DECODE_ALLOC_FLAG}
  86. // The following flag is applicable when decoding X509_UNICODE_NAME,
  87. // X509_UNICODE_NAME_VALUE or X509_UNICODE_ANY_STRING.
  88. // By default, CERT_RDN_T61_STRING values are initially decoded
  89. // as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  90. // Setting this flag skips the initial attempt to decode as UTF8.
  91.   CRYPT_UNICODE_NAME_DECODE_DISABLE_IE4_UTF8_FLAG = CERT_RDN_DISABLE_IE4_UTF8_FLAG;
  92.   {$EXTERNALSYM CRYPT_UNICODE_NAME_DECODE_DISABLE_IE4_UTF8_FLAG}
  93. //+-------------------------------------------------------------------------
  94. //  Predefined X509 certificate data structures that can be encoded / decoded.
  95. //--------------------------------------------------------------------------
  96.   CRYPT_ENCODE_DECODE_NONE       = 0;
  97.   {$EXTERNALSYM CRYPT_ENCODE_DECODE_NONE}
  98.   X509_CERT                      = LPCSTR(1);
  99.   {$EXTERNALSYM X509_CERT}
  100.   X509_CERT_TO_BE_SIGNED         = LPCSTR(2);
  101.   {$EXTERNALSYM X509_CERT_TO_BE_SIGNED}
  102.   X509_CERT_CRL_TO_BE_SIGNED     = LPCSTR(3);
  103.   {$EXTERNALSYM X509_CERT_CRL_TO_BE_SIGNED}
  104.   X509_CERT_REQUEST_TO_BE_SIGNED = LPCSTR(4);
  105.   {$EXTERNALSYM X509_CERT_REQUEST_TO_BE_SIGNED}
  106.   X509_EXTENSIONS                = LPCSTR(5);
  107.   {$EXTERNALSYM X509_EXTENSIONS}
  108.   X509_NAME_VALUE                = LPCSTR(6);
  109.   {$EXTERNALSYM X509_NAME_VALUE}
  110.   X509_NAME                      = LPCSTR(7);
  111.   {$EXTERNALSYM X509_NAME}
  112.   X509_PUBLIC_KEY_INFO           = LPCSTR(8);
  113.   {$EXTERNALSYM X509_PUBLIC_KEY_INFO}
  114. //+-------------------------------------------------------------------------
  115. //  Predefined X509 certificate extension data structures that can be
  116. //  encoded / decoded.
  117. //--------------------------------------------------------------------------
  118.   X509_AUTHORITY_KEY_ID      = LPCSTR(9);
  119.   {$EXTERNALSYM X509_AUTHORITY_KEY_ID}
  120.   X509_KEY_ATTRIBUTES        = LPCSTR(10);
  121.   {$EXTERNALSYM X509_KEY_ATTRIBUTES}
  122.   X509_KEY_USAGE_RESTRICTION = LPCSTR(11);
  123.   {$EXTERNALSYM X509_KEY_USAGE_RESTRICTION}
  124.   X509_ALTERNATE_NAME        = LPCSTR(12);
  125.   {$EXTERNALSYM X509_ALTERNATE_NAME}
  126.   X509_BASIC_CONSTRAINTS     = LPCSTR(13);
  127.   {$EXTERNALSYM X509_BASIC_CONSTRAINTS}
  128.   X509_KEY_USAGE             = LPCSTR(14);
  129.   {$EXTERNALSYM X509_KEY_USAGE}
  130.   X509_BASIC_CONSTRAINTS2    = LPCSTR(15);
  131.   {$EXTERNALSYM X509_BASIC_CONSTRAINTS2}
  132.   X509_CERT_POLICIES         = LPCSTR(16);
  133.   {$EXTERNALSYM X509_CERT_POLICIES}
  134. //+-------------------------------------------------------------------------
  135. //  Additional predefined data structures that can be encoded / decoded.
  136. //--------------------------------------------------------------------------
  137.   PKCS_UTC_TIME         = LPCSTR(17);
  138.   {$EXTERNALSYM PKCS_UTC_TIME}
  139.   PKCS_TIME_REQUEST     = LPCSTR(18);
  140.   {$EXTERNALSYM PKCS_TIME_REQUEST}
  141.   RSA_CSP_PUBLICKEYBLOB = LPCSTR(19);
  142.   {$EXTERNALSYM RSA_CSP_PUBLICKEYBLOB}
  143.   X509_UNICODE_NAME     = LPCSTR(20);
  144.   {$EXTERNALSYM X509_UNICODE_NAME}
  145.   X509_KEYGEN_REQUEST_TO_BE_SIGNED  = LPCSTR(21);
  146.   {$EXTERNALSYM X509_KEYGEN_REQUEST_TO_BE_SIGNED}
  147.   PKCS_ATTRIBUTE                    = LPCSTR(22);
  148.   {$EXTERNALSYM PKCS_ATTRIBUTE}
  149.   PKCS_CONTENT_INFO_SEQUENCE_OF_ANY = LPCSTR(23);
  150.   {$EXTERNALSYM PKCS_CONTENT_INFO_SEQUENCE_OF_ANY}
  151. //+-------------------------------------------------------------------------
  152. //  Predefined primitive data structures that can be encoded / decoded.
  153. //--------------------------------------------------------------------------
  154.   X509_UNICODE_NAME_VALUE = LPCSTR(24);
  155.   {$EXTERNALSYM X509_UNICODE_NAME_VALUE}
  156.   X509_ANY_STRING         = X509_NAME_VALUE;
  157.   {$EXTERNALSYM X509_ANY_STRING}
  158.   X509_UNICODE_ANY_STRING = X509_UNICODE_NAME_VALUE;
  159.   {$EXTERNALSYM X509_UNICODE_ANY_STRING}
  160.   X509_OCTET_STRING       = LPCSTR(25);
  161.   {$EXTERNALSYM X509_OCTET_STRING}
  162.   X509_BITS               = LPCSTR(26);
  163.   {$EXTERNALSYM X509_BITS}
  164.   X509_INTEGER            = LPCSTR(27);
  165.   {$EXTERNALSYM X509_INTEGER}
  166.   X509_MULTI_BYTE_INTEGER = LPCSTR(28);
  167.   {$EXTERNALSYM X509_MULTI_BYTE_INTEGER}
  168.   X509_ENUMERATED         = LPCSTR(29);
  169.   {$EXTERNALSYM X509_ENUMERATED}
  170.   X509_CHOICE_OF_TIME     = LPCSTR(30);
  171.   {$EXTERNALSYM X509_CHOICE_OF_TIME}
  172. //+-------------------------------------------------------------------------
  173. //  More predefined X509 certificate extension data structures that can be
  174. //  encoded / decoded.
  175. //--------------------------------------------------------------------------
  176.   X509_AUTHORITY_KEY_ID2     = LPCSTR(31);
  177.   {$EXTERNALSYM X509_AUTHORITY_KEY_ID2}
  178.   X509_AUTHORITY_INFO_ACCESS = LPCSTR(32);
  179.   {$EXTERNALSYM X509_AUTHORITY_INFO_ACCESS}
  180.   X509_CRL_REASON_CODE       = X509_ENUMERATED;
  181.   {$EXTERNALSYM X509_CRL_REASON_CODE}
  182.   PKCS_CONTENT_INFO          = LPCSTR(33);
  183.   {$EXTERNALSYM PKCS_CONTENT_INFO}
  184.   X509_SEQUENCE_OF_ANY       = LPCSTR(34);
  185.   {$EXTERNALSYM X509_SEQUENCE_OF_ANY}
  186.   X509_CRL_DIST_POINTS       = LPCSTR(35);
  187.   {$EXTERNALSYM X509_CRL_DIST_POINTS}
  188.   X509_ENHANCED_KEY_USAGE    = LPCSTR(36);
  189.   {$EXTERNALSYM X509_ENHANCED_KEY_USAGE}
  190.   PKCS_CTL                   = LPCSTR(37);
  191.   {$EXTERNALSYM PKCS_CTL}
  192.   X509_MULTI_BYTE_UINT    = LPCSTR(38);
  193.   {$EXTERNALSYM X509_MULTI_BYTE_UINT}
  194.   X509_DSS_PUBLICKEY      = X509_MULTI_BYTE_UINT;
  195.   {$EXTERNALSYM X509_DSS_PUBLICKEY}
  196.   X509_DSS_PARAMETERS     = LPCSTR(39);
  197.   {$EXTERNALSYM X509_DSS_PARAMETERS}
  198.   X509_DSS_SIGNATURE      = LPCSTR(40);
  199.   {$EXTERNALSYM X509_DSS_SIGNATURE}
  200.   PKCS_RC2_CBC_PARAMETERS = LPCSTR(41);
  201.   {$EXTERNALSYM PKCS_RC2_CBC_PARAMETERS}
  202.   PKCS_SMIME_CAPABILITIES = LPCSTR(42);
  203.   {$EXTERNALSYM PKCS_SMIME_CAPABILITIES}
  204. //+-------------------------------------------------------------------------
  205. //  data structures for private keys
  206. //--------------------------------------------------------------------------
  207.   PKCS_RSA_PRIVATE_KEY            = LPCSTR(43);
  208.   {$EXTERNALSYM PKCS_RSA_PRIVATE_KEY}
  209.   PKCS_PRIVATE_KEY_INFO           = LPCSTR(44);
  210.   {$EXTERNALSYM PKCS_PRIVATE_KEY_INFO}
  211.   PKCS_ENCRYPTED_PRIVATE_KEY_INFO = LPCSTR(45);
  212.   {$EXTERNALSYM PKCS_ENCRYPTED_PRIVATE_KEY_INFO}
  213. //+-------------------------------------------------------------------------
  214. //  certificate policy qualifier
  215. //--------------------------------------------------------------------------
  216.   X509_PKIX_POLICY_QUALIFIER_USERNOTICE = LPCSTR(46);
  217.   {$EXTERNALSYM X509_PKIX_POLICY_QUALIFIER_USERNOTICE}
  218. //+-------------------------------------------------------------------------
  219. //  Diffie-Hellman Key Exchange
  220. //--------------------------------------------------------------------------
  221.   X509_DH_PUBLICKEY  = X509_MULTI_BYTE_UINT;
  222.   {$EXTERNALSYM X509_DH_PUBLICKEY}
  223.   X509_DH_PARAMETERS = LPCSTR(47);
  224.   {$EXTERNALSYM X509_DH_PARAMETERS}
  225.   PKCS_ATTRIBUTES    = LPCSTR(48);
  226.   {$EXTERNALSYM PKCS_ATTRIBUTES}
  227.   PKCS_SORTED_CTL    = LPCSTR(49);
  228.   {$EXTERNALSYM PKCS_SORTED_CTL}
  229. //+-------------------------------------------------------------------------
  230. //  X942 Diffie-Hellman
  231. //--------------------------------------------------------------------------
  232.   X942_DH_PARAMETERS = LPCSTR(50);
  233.   {$EXTERNALSYM X942_DH_PARAMETERS}
  234. //+-------------------------------------------------------------------------
  235. //  The following is the same as X509_BITS, except before encoding,
  236. //  the bit length is decremented to exclude trailing zero bits.
  237. //--------------------------------------------------------------------------
  238.   X509_BITS_WITHOUT_TRAILING_ZEROES = LPCSTR(51);
  239.   {$EXTERNALSYM X509_BITS_WITHOUT_TRAILING_ZEROES}
  240. //+-------------------------------------------------------------------------
  241. //  X942 Diffie-Hellman Other Info
  242. //--------------------------------------------------------------------------
  243.   X942_OTHER_INFO = LPCSTR(52);
  244.   {$EXTERNALSYM X942_OTHER_INFO}
  245. //+-------------------------------------------------------------------------
  246. //  Predefined PKCS #7 data structures that can be encoded / decoded.
  247. //--------------------------------------------------------------------------
  248.   PKCS7_SIGNER_INFO = LPCSTR(500);
  249.   {$EXTERNALSYM PKCS7_SIGNER_INFO}
  250. //+-------------------------------------------------------------------------
  251. //  Predefined PKCS #7 data structures that can be encoded / decoded.
  252. //--------------------------------------------------------------------------
  253.   CMS_SIGNER_INFO = LPCSTR(501);
  254.   {$EXTERNALSYM CMS_SIGNER_INFO}
  255. //+-------------------------------------------------------------------------
  256. //  Predefined Software Publishing Credential (SPC)  data structures that
  257. //  can be encoded / decoded.
  258. //
  259. //  Predefined values: 2000 .. 2999
  260. //
  261. //  See spc.h for value and data structure definitions.
  262. //--------------------------------------------------------------------------
  263. //+-------------------------------------------------------------------------
  264. //  Extension Object Identifiers
  265. //--------------------------------------------------------------------------
  266.   szOID_AUTHORITY_KEY_IDENTIFIER = '2.5.29.1';
  267.   {$EXTERNALSYM szOID_AUTHORITY_KEY_IDENTIFIER}
  268.   szOID_KEY_ATTRIBUTES           = '2.5.29.2';
  269.   {$EXTERNALSYM szOID_KEY_ATTRIBUTES}
  270.   szOID_CERT_POLICIES_95         = '2.5.29.3';
  271.   {$EXTERNALSYM szOID_CERT_POLICIES_95}
  272.   szOID_KEY_USAGE_RESTRICTION    = '2.5.29.4';
  273.   {$EXTERNALSYM szOID_KEY_USAGE_RESTRICTION}
  274.   szOID_SUBJECT_ALT_NAME         = '2.5.29.7';
  275.   {$EXTERNALSYM szOID_SUBJECT_ALT_NAME}
  276.   szOID_ISSUER_ALT_NAME          = '2.5.29.8';
  277.   {$EXTERNALSYM szOID_ISSUER_ALT_NAME}
  278.   szOID_BASIC_CONSTRAINTS        = '2.5.29.10';
  279.   {$EXTERNALSYM szOID_BASIC_CONSTRAINTS}
  280.   szOID_KEY_USAGE                = '2.5.29.15';
  281.   {$EXTERNALSYM szOID_KEY_USAGE}
  282.   szOID_PRIVATEKEY_USAGE_PERIOD  = '2.5.29.16';
  283.   {$EXTERNALSYM szOID_PRIVATEKEY_USAGE_PERIOD}
  284.   szOID_BASIC_CONSTRAINTS2       = '2.5.29.19';
  285.   {$EXTERNALSYM szOID_BASIC_CONSTRAINTS2}
  286.   szOID_CERT_POLICIES            = '2.5.29.32';
  287.   {$EXTERNALSYM szOID_CERT_POLICIES}
  288.   szOID_AUTHORITY_KEY_IDENTIFIER2 = '2.5.29.35';
  289.   {$EXTERNALSYM szOID_AUTHORITY_KEY_IDENTIFIER2}
  290.   szOID_SUBJECT_KEY_IDENTIFIER    = '2.5.29.14';
  291.   {$EXTERNALSYM szOID_SUBJECT_KEY_IDENTIFIER}
  292.   szOID_SUBJECT_ALT_NAME2         = '2.5.29.17';
  293.   {$EXTERNALSYM szOID_SUBJECT_ALT_NAME2}
  294.   szOID_ISSUER_ALT_NAME2          = '2.5.29.18';
  295.   {$EXTERNALSYM szOID_ISSUER_ALT_NAME2}
  296.   szOID_CRL_REASON_CODE           = '2.5.29.21';
  297.   {$EXTERNALSYM szOID_CRL_REASON_CODE}
  298.   szOID_CRL_DIST_POINTS           = '2.5.29.31';
  299.   {$EXTERNALSYM szOID_CRL_DIST_POINTS}
  300.   szOID_ENHANCED_KEY_USAGE        = '2.5.29.37';
  301.   {$EXTERNALSYM szOID_ENHANCED_KEY_USAGE}
  302. // Microsoft PKCS10 Attributes
  303.   szOID_RENEWAL_CERTIFICATE        = '1.3.6.1.4.1.311.13.1';
  304.   {$EXTERNALSYM szOID_RENEWAL_CERTIFICATE}
  305.   szOID_ENROLLMENT_NAME_VALUE_PAIR = '1.3.6.1.4.1.311.13.2.1';
  306.   {$EXTERNALSYM szOID_ENROLLMENT_NAME_VALUE_PAIR}
  307.   szOID_ENROLLMENT_CSP_PROVIDER    = '1.3.6.1.4.1.311.13.2.2';
  308.   {$EXTERNALSYM szOID_ENROLLMENT_CSP_PROVIDER}
  309.   szOID_OS_VERSION                 = '1.3.6.1.4.1.311.13.2.3';
  310.   {$EXTERNALSYM szOID_OS_VERSION}
  311. //
  312. // Extension contain certificate type
  313.   szOID_ENROLLMENT_AGENT = '1.3.6.1.4.1.311.20.2.1';
  314.   {$EXTERNALSYM szOID_ENROLLMENT_AGENT}
  315. // Internet Public Key Infrastructure (PKIX)
  316.   szOID_PKIX                  = '1.3.6.1.5.5.7';
  317.   {$EXTERNALSYM szOID_PKIX}
  318.   szOID_PKIX_PE               = '1.3.6.1.5.5.7.1';
  319.   {$EXTERNALSYM szOID_PKIX_PE}
  320.   szOID_AUTHORITY_INFO_ACCESS = '1.3.6.1.5.5.7.1.1';
  321.   {$EXTERNALSYM szOID_AUTHORITY_INFO_ACCESS}
  322. // Microsoft extensions or attributes
  323.   szOID_CERT_EXTENSIONS      = '1.3.6.1.4.1.311.2.1.14';
  324.   {$EXTERNALSYM szOID_CERT_EXTENSIONS}
  325.   szOID_NEXT_UPDATE_LOCATION = '1.3.6.1.4.1.311.10.2';
  326.   {$EXTERNALSYM szOID_NEXT_UPDATE_LOCATION}
  327. //  Microsoft PKCS #7 ContentType Object Identifiers
  328.   szOID_CTL = '1.3.6.1.4.1.311.10.1';
  329.   {$EXTERNALSYM szOID_CTL}
  330. //  Microsoft Sorted CTL Extension Object Identifier
  331.   szOID_SORTED_CTL = '1.3.6.1.4.1.311.10.1.1';
  332.   {$EXTERNALSYM szOID_SORTED_CTL}
  333. // serialized serial numbers for PRS
  334.   szOID_SERIALIZED = '1.3.6.1.4.1.311.10.3.3.1';
  335.   {$EXTERNALSYM szOID_SERIALIZED}
  336. // UPN principal name in SubjectAltName
  337.   szOID_NT_PRINCIPAL_NAME = '1.3.6.1.4.1.311.20.2.3';
  338.   {$EXTERNALSYM szOID_NT_PRINCIPAL_NAME}
  339. // Windows product update unauthenticated attribute
  340.   szOID_PRODUCT_UPDATE = '1.3.6.1.4.1.311.31.1';
  341.   {$EXTERNALSYM szOID_PRODUCT_UPDATE}
  342. //+-------------------------------------------------------------------------
  343. //  Object Identifiers for use with Auto Enrollment
  344. //--------------------------------------------------------------------------
  345.   szOID_AUTO_ENROLL_CTL_USAGE = '1.3.6.1.4.1.311.20.1';
  346.   {$EXTERNALSYM szOID_AUTO_ENROLL_CTL_USAGE}
  347. // Extension contain certificate type
  348.   szOID_ENROLL_CERTTYPE_EXTENSION = '1.3.6.1.4.1.311.20.2';
  349.   {$EXTERNALSYM szOID_ENROLL_CERTTYPE_EXTENSION}
  350.   szOID_CERT_MANIFOLD = '1.3.6.1.4.1.311.20.3';
  351.   {$EXTERNALSYM szOID_CERT_MANIFOLD}
  352. //+-------------------------------------------------------------------------
  353. //  Object Identifiers for use with the MS Certificate Server
  354. //--------------------------------------------------------------------------
  355.   szOID_CERTSRV_CA_VERSION = '1.3.6.1.4.1.311.21.1';
  356.   {$EXTERNALSYM szOID_CERTSRV_CA_VERSION}
  357. //+-------------------------------------------------------------------------
  358. //  Object Identifiers for use with the MS Directory Service
  359. //--------------------------------------------------------------------------
  360.   szOID_NTDS_REPLICATION = '1.3.6.1.4.1.311.25.1';
  361.   {$EXTERNALSYM szOID_NTDS_REPLICATION}
  362. //+-------------------------------------------------------------------------
  363. //  Extension Object Identifiers (currently not implemented)
  364. //--------------------------------------------------------------------------
  365.   szOID_POLICY_MAPPINGS   = '2.5.29.5';
  366.   {$EXTERNALSYM szOID_POLICY_MAPPINGS}
  367.   szOID_SUBJECT_DIR_ATTRS = '2.5.29.9';
  368.   {$EXTERNALSYM szOID_SUBJECT_DIR_ATTRS}
  369. //+-------------------------------------------------------------------------
  370. //  Enhanced Key Usage (Purpose) Object Identifiers
  371. //--------------------------------------------------------------------------
  372.   szOID_PKIX_KP = '1.3.6.1.5.5.7.3';
  373.   {$EXTERNALSYM szOID_PKIX_KP}
  374. // Consistent key usage bits: DIGITAL_SIGNATURE, KEY_ENCIPHERMENT
  375. // or KEY_AGREEMENT
  376.   szOID_PKIX_KP_SERVER_AUTH = '1.3.6.1.5.5.7.3.1';
  377.   {$EXTERNALSYM szOID_PKIX_KP_SERVER_AUTH}
  378. // Consistent key usage bits: DIGITAL_SIGNATURE
  379.   szOID_PKIX_KP_CLIENT_AUTH = '1.3.6.1.5.5.7.3.2';
  380.   {$EXTERNALSYM szOID_PKIX_KP_CLIENT_AUTH}
  381. // Consistent key usage bits: DIGITAL_SIGNATURE
  382.   szOID_PKIX_KP_CODE_SIGNING = '1.3.6.1.5.5.7.3.3';
  383.   {$EXTERNALSYM szOID_PKIX_KP_CODE_SIGNING}
  384. // Consistent key usage bits: DIGITAL_SIGNATURE, NON_REPUDIATION and/or
  385. // (KEY_ENCIPHERMENT or KEY_AGREEMENT)
  386.   szOID_PKIX_KP_EMAIL_PROTECTION = '1.3.6.1.5.5.7.3.4';
  387.   {$EXTERNALSYM szOID_PKIX_KP_EMAIL_PROTECTION}
  388. // Consistent key usage bits: DIGITAL_SIGNATURE and/or
  389. // (KEY_ENCIPHERMENT or KEY_AGREEMENT)
  390.   szOID_PKIX_KP_IPSEC_END_SYSTEM = '1.3.6.1.5.5.7.3.5';
  391.   {$EXTERNALSYM szOID_PKIX_KP_IPSEC_END_SYSTEM}
  392. // Consistent key usage bits: DIGITAL_SIGNATURE and/or
  393. // (KEY_ENCIPHERMENT or KEY_AGREEMENT)
  394.   szOID_PKIX_KP_IPSEC_TUNNEL = '1.3.6.1.5.5.7.3.6';
  395.   {$EXTERNALSYM szOID_PKIX_KP_IPSEC_TUNNEL}
  396. // Consistent key usage bits: DIGITAL_SIGNATURE and/or
  397. // (KEY_ENCIPHERMENT or KEY_AGREEMENT)
  398.   szOID_PKIX_KP_IPSEC_USER = '1.3.6.1.5.5.7.3.7';
  399.   {$EXTERNALSYM szOID_PKIX_KP_IPSEC_USER}
  400. // Consistent key usage bits: DIGITAL_SIGNATURE or NON_REPUDIATION
  401.   szOID_PKIX_KP_TIMESTAMP_SIGNING = '1.3.6.1.5.5.7.3.8';
  402.   {$EXTERNALSYM szOID_PKIX_KP_TIMESTAMP_SIGNING}
  403. //+-------------------------------------------------------------------------
  404. //  Microsoft Enhanced Key Usage (Purpose) Object Identifiers
  405. //+-------------------------------------------------------------------------
  406. //  Signer of CTLs
  407.   szOID_KP_CTL_USAGE_SIGNING = '1.3.6.1.4.1.311.10.3.1';
  408.   {$EXTERNALSYM szOID_KP_CTL_USAGE_SIGNING}
  409. //  Signer of TimeStamps
  410.   szOID_KP_TIME_STAMP_SIGNING = '1.3.6.1.4.1.311.10.3.2';
  411.   {$EXTERNALSYM szOID_KP_TIME_STAMP_SIGNING}
  412.   szOID_SERVER_GATED_CRYPTO = '1.3.6.1.4.1.311.10.3.3';
  413.   {$EXTERNALSYM szOID_SERVER_GATED_CRYPTO}
  414.   szOID_SGC_NETSCAPE = '2.16.840.1.113730.4.1';
  415.   {$EXTERNALSYM szOID_SGC_NETSCAPE}
  416.   szOID_KP_EFS = '1.3.6.1.4.1.311.10.3.4';
  417.   {$EXTERNALSYM szOID_KP_EFS}
  418. // Can use Windows Hardware Compatible (WHQL)
  419.   szOID_WHQL_CRYPTO = '1.3.6.1.4.1.311.10.3.5';
  420.   {$EXTERNALSYM szOID_WHQL_CRYPTO}
  421. // Signed by the NT5 build lab
  422.   szOID_NT5_CRYPTO = '1.3.6.1.4.1.311.10.3.6';
  423.   {$EXTERNALSYM szOID_NT5_CRYPTO}
  424. // Signed by and OEM of WHQL
  425.   szOID_OEM_WHQL_CRYPTO = '1.3.6.1.4.1.311.10.3.7';
  426.   {$EXTERNALSYM szOID_OEM_WHQL_CRYPTO}
  427. // Signed by the Embedded NT
  428.   szOID_EMBEDDED_NT_CRYPTO = '1.3.6.1.4.1.311.10.3.8';
  429.   {$EXTERNALSYM szOID_EMBEDDED_NT_CRYPTO}
  430.   szOID_DRM = '1.3.6.1.4.1.311.10.5.1';
  431.   {$EXTERNALSYM szOID_DRM}
  432.   szOID_LICENSES = '1.3.6.1.4.1.311.10.6.1';
  433.   {$EXTERNALSYM szOID_LICENSES}
  434.   szOID_LICENSE_SERVER = '1.3.6.1.4.1.311.10.6.2';
  435.   {$EXTERNALSYM szOID_LICENSE_SERVER}
  436.   szOID_KP_SMARTCARD_LOGON = '1.3.6.1.4.1.311.20.2.2';
  437.   {$EXTERNALSYM szOID_KP_SMARTCARD_LOGON}
  438. //+-------------------------------------------------------------------------
  439. //  Microsoft Attribute Object Identifiers
  440. //+-------------------------------------------------------------------------
  441.   szOID_YESNO_TRUST_ATTR = '1.3.6.1.4.1.311.10.4.1';
  442.   {$EXTERNALSYM szOID_YESNO_TRUST_ATTR}
  443. //+-------------------------------------------------------------------------
  444. //  Qualifiers that may be part of the szOID_CERT_POLICIES and
  445. //  szOID_CERT_POLICIES95 extensions
  446. //+-------------------------------------------------------------------------
  447.   szOID_PKIX_POLICY_QUALIFIER_CPS        = '1.3.6.1.5.5.7.2.1';
  448.   {$EXTERNALSYM szOID_PKIX_POLICY_QUALIFIER_CPS}
  449.   szOID_PKIX_POLICY_QUALIFIER_USERNOTICE = '1.3.6.1.5.5.7.2.2';
  450.   {$EXTERNALSYM szOID_PKIX_POLICY_QUALIFIER_USERNOTICE}
  451. // OID for old qualifer
  452.   szOID_CERT_POLICIES_95_QUALIFIER1 = '2.16.840.1.113733.1.7.1.1';
  453.   {$EXTERNALSYM szOID_CERT_POLICIES_95_QUALIFIER1}
  454. //+-------------------------------------------------------------------------
  455. //  X509_CERT
  456. //
  457. //  The "to be signed" encoded content plus its signature. The ToBeSigned
  458. //  content is the CryptEncodeObject() output for one of the following:
  459. //  X509_CERT_TO_BE_SIGNED, X509_CERT_CRL_TO_BE_SIGNED or
  460. //  X509_CERT_REQUEST_TO_BE_SIGNED.
  461. //
  462. //  pvStructInfo points to CERT_SIGNED_CONTENT_INFO.
  463. //--------------------------------------------------------------------------
  464. //+-------------------------------------------------------------------------
  465. //  X509_CERT_TO_BE_SIGNED
  466. //
  467. //  pvStructInfo points to CERT_INFO.
  468. //
  469. //  For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  470. //  signature (output of a X509_CERT CryptEncodeObject()).
  471. //
  472. //  For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  473. //--------------------------------------------------------------------------
  474. //+-------------------------------------------------------------------------
  475. //  X509_CERT_CRL_TO_BE_SIGNED
  476. //
  477. //  pvStructInfo points to CRL_INFO.
  478. //
  479. //  For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  480. //  signature (output of a X509_CERT CryptEncodeObject()).
  481. //
  482. //  For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  483. //--------------------------------------------------------------------------
  484. //+-------------------------------------------------------------------------
  485. //  X509_CERT_REQUEST_TO_BE_SIGNED
  486. //
  487. //  pvStructInfo points to CERT_REQUEST_INFO.
  488. //
  489. //  For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  490. //  signature (output of a X509_CERT CryptEncodeObject()).
  491. //
  492. //  For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  493. //--------------------------------------------------------------------------
  494. //+-------------------------------------------------------------------------
  495. //  X509_EXTENSIONS
  496. //  szOID_CERT_EXTENSIONS
  497. //
  498. //  pvStructInfo points to following CERT_EXTENSIONS.
  499. //--------------------------------------------------------------------------
  500. type
  501.   PCERT_EXTENSIONS = ^CERT_EXTENSIONS;
  502.   {$EXTERNALSYM PCERT_EXTENSIONS}
  503.   _CERT_EXTENSIONS = record
  504.     cExtension: DWORD;
  505.     rgExtension: PCERT_EXTENSION;
  506.   end;
  507.   {$EXTERNALSYM _CERT_EXTENSIONS}
  508.   CERT_EXTENSIONS = _CERT_EXTENSIONS;
  509.   {$EXTERNALSYM CERT_EXTENSIONS}
  510.   TCertExtensions = CERT_EXTENSIONS;
  511.   PCertExtensions = PCERT_EXTENSIONS;
  512. //+-------------------------------------------------------------------------
  513. //  X509_NAME_VALUE
  514. //  X509_ANY_STRING
  515. //
  516. //  pvStructInfo points to CERT_NAME_VALUE.
  517. //--------------------------------------------------------------------------
  518. //+-------------------------------------------------------------------------
  519. //  X509_UNICODE_NAME_VALUE
  520. //  X509_UNICODE_ANY_STRING
  521. //
  522. //  pvStructInfo points to CERT_NAME_VALUE.
  523. //
  524. //  The name values are unicode strings.
  525. //
  526. //  For CryptEncodeObject:
  527. //    Value.pbData points to the unicode string.
  528. //    If Value.cbData = 0, then, the unicode string is NULL terminated.
  529. //    Otherwise, Value.cbData is the unicode string byte count. The byte count
  530. //    is twice the character count.
  531. //
  532. //    If the unicode string contains an invalid character for the specified
  533. //    dwValueType, then, *pcbEncoded is updated with the unicode character
  534. //    index of the first invalid character. LastError is set to:
  535. //    CRYPT_E_INVALID_NUMERIC_STRING, CRYPT_E_INVALID_PRINTABLE_STRING or
  536. //    CRYPT_E_INVALID_IA5_STRING.
  537. //
  538. //    To disable the above check, either set CERT_RDN_DISABLE_CHECK_TYPE_FLAG
  539. //    in dwValueType or set CRYPT_UNICODE_NAME_ENCODE_DISABLE_CHECK_TYPE_FLAG
  540. //    in dwFlags passed to CryptEncodeObjectEx.
  541. //
  542. //    The unicode string is converted before being encoded according to
  543. //    the specified dwValueType. If dwValueType is set to 0, LastError
  544. //    is set to E_INVALIDARG.
  545. //
  546. //    If the dwValueType isn't one of the character strings (its a
  547. //    CERT_RDN_ENCODED_BLOB or CERT_RDN_OCTET_STRING), then, CryptEncodeObject
  548. //    will return FALSE with LastError set to CRYPT_E_NOT_CHAR_STRING.
  549. //
  550. //  For CryptDecodeObject:
  551. //    Value.pbData points to a NULL terminated unicode string. Value.cbData
  552. //    contains the byte count of the unicode string excluding the NULL
  553. //    terminator. dwValueType contains the type used in the encoded object.
  554. //    Its not forced to CERT_RDN_UNICODE_STRING. The encoded value is
  555. //    converted to the unicode string according to the dwValueType.
  556. //
  557. //    If the encoded object isn't one of the character string types, then,
  558. //    CryptDecodeObject will return FALSE with LastError set to
  559. //    CRYPT_E_NOT_CHAR_STRING. For a non character string, decode using
  560. //    X509_NAME_VALUE or X509_ANY_STRING.
  561. //
  562. //    By default, CERT_RDN_T61_STRING values are initially decoded
  563. //    as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  564. //    Set CRYPT_UNICODE_NAME_DECODE_DISABLE_IE4_UTF8_FLAG in dwFlags
  565. //    passed to either CryptDecodeObject or CryptDecodeObjectEx to
  566. //    skip the initial attempt to decode as UTF8.
  567. //--------------------------------------------------------------------------
  568. //+-------------------------------------------------------------------------
  569. //  X509_NAME
  570. //
  571. //  pvStructInfo points to CERT_NAME_INFO.
  572. //--------------------------------------------------------------------------
  573. //+-------------------------------------------------------------------------
  574. //  X509_UNICODE_NAME
  575. //
  576. //  pvStructInfo points to CERT_NAME_INFO.
  577. //
  578. //  The RDN attribute values are unicode strings except for the dwValueTypes of
  579. //  CERT_RDN_ENCODED_BLOB or CERT_RDN_OCTET_STRING. These dwValueTypes are
  580. //  the same as for a X509_NAME. Their values aren't converted to/from unicode.
  581. //
  582. //  For CryptEncodeObject:
  583. //    Value.pbData points to the unicode string.
  584. //    If Value.cbData = 0, then, the unicode string is NULL terminated.
  585. //    Otherwise, Value.cbData is the unicode string byte count. The byte count
  586. //    is twice the character count.
  587. //
  588. //    If dwValueType = 0 (CERT_RDN_ANY_TYPE), the pszObjId is used to find
  589. //    an acceptable dwValueType. If the unicode string contains an
  590. //    invalid character for the found or specified dwValueType, then,
  591. //    *pcbEncoded is updated with the error location of the invalid character.
  592. //    See below for details. LastError is set to:
  593. //    CRYPT_E_INVALID_NUMERIC_STRING, CRYPT_E_INVALID_PRINTABLE_STRING or
  594. //    CRYPT_E_INVALID_IA5_STRING.
  595. //
  596. //    To disable the above check, either set CERT_RDN_DISABLE_CHECK_TYPE_FLAG
  597. //    in dwValueType or set CRYPT_UNICODE_NAME_ENCODE_DISABLE_CHECK_TYPE_FLAG
  598. //    in dwFlags passed to CryptEncodeObjectEx.
  599. //
  600. //    Set CERT_RDN_UNICODE_STRING in dwValueType or set
  601. //    CRYPT_UNICODE_NAME_ENCODE_ENABLE_T61_UNICODE_FLAG in dwFlags passed
  602. //    to CryptEncodeObjectEx to select CERT_RDN_T61_STRING instead of
  603. //    CERT_RDN_UNICODE_STRING if all the unicode characters are <= 0xFF.
  604. //
  605. //    Set CERT_RDN_ENABLE_UTF8_UNICODE_STRING in dwValueType or set
  606. //    CRYPT_UNICODE_NAME_ENCODE_ENABLE_UTF8_UNICODE_FLAG in dwFlags passed
  607. //    to CryptEncodeObjectEx to select CERT_RDN_UTF8_STRING instead of
  608. //    CERT_RDN_UNICODE_STRING.
  609. //
  610. //    The unicode string is converted before being encoded according to
  611. //    the specified or ObjId matching dwValueType.
  612. //
  613. //  For CryptDecodeObject:
  614. //    Value.pbData points to a NULL terminated unicode string. Value.cbData
  615. //    contains the byte count of the unicode string excluding the NULL
  616. //    terminator. dwValueType contains the type used in the encoded object.
  617. //    Its not forced to CERT_RDN_UNICODE_STRING. The encoded value is
  618. //    converted to the unicode string according to the dwValueType.
  619. //
  620. //    If the dwValueType of the encoded value isn't a character string
  621. //    type, then, it isn't converted to UNICODE. Use the
  622. //    IS_CERT_RDN_CHAR_STRING() macro on the dwValueType to check
  623. //    that Value.pbData points to a converted unicode string.
  624. //
  625. //    By default, CERT_RDN_T61_STRING values are initially decoded
  626. //    as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  627. //    Set CRYPT_UNICODE_NAME_DECODE_DISABLE_IE4_UTF8_FLAG in dwFlags
  628. //    passed to either CryptDecodeObject or CryptDecodeObjectEx to
  629. //    skip the initial attempt to decode as UTF8.
  630. //--------------------------------------------------------------------------
  631. //+-------------------------------------------------------------------------
  632. //  Unicode Name Value Error Location Definitions
  633. //
  634. //  Error location is returned in *pcbEncoded by
  635. //  CryptEncodeObject(X509_UNICODE_NAME)
  636. //
  637. //  Error location consists of:
  638. //    RDN_INDEX     - 10 bits << 22
  639. //    ATTR_INDEX    - 6 bits << 16
  640. //    VALUE_INDEX   - 16 bits (unicode character index)
  641. //--------------------------------------------------------------------------
  642. const
  643.   CERT_UNICODE_RDN_ERR_INDEX_MASK    = $3FF;
  644.   {$EXTERNALSYM CERT_UNICODE_RDN_ERR_INDEX_MASK}
  645.   CERT_UNICODE_RDN_ERR_INDEX_SHIFT   = 22;
  646.   {$EXTERNALSYM CERT_UNICODE_RDN_ERR_INDEX_SHIFT}
  647.   CERT_UNICODE_ATTR_ERR_INDEX_MASK   = $003F;
  648.   {$EXTERNALSYM CERT_UNICODE_ATTR_ERR_INDEX_MASK}
  649.   CERT_UNICODE_ATTR_ERR_INDEX_SHIFT  = 16;
  650.   {$EXTERNALSYM CERT_UNICODE_ATTR_ERR_INDEX_SHIFT}
  651.   CERT_UNICODE_VALUE_ERR_INDEX_MASK  = $0000FFFF;
  652.   {$EXTERNALSYM CERT_UNICODE_VALUE_ERR_INDEX_MASK}
  653.   CERT_UNICODE_VALUE_ERR_INDEX_SHIFT = 0;
  654.   {$EXTERNALSYM CERT_UNICODE_VALUE_ERR_INDEX_SHIFT}
  655. function GET_CERT_UNICODE_RDN_ERR_INDEX(X: DWORD): DWORD;
  656. {$EXTERNALSYM GET_CERT_UNICODE_RDN_ERR_INDEX}
  657. function GET_CERT_UNICODE_ATTR_ERR_INDEX(X: DWORD): DWORD;
  658. {$EXTERNALSYM GET_CERT_UNICODE_ATTR_ERR_INDEX}
  659. function GET_CERT_UNICODE_VALUE_ERR_INDEX(X: DWORD): DWORD;
  660. {$EXTERNALSYM GET_CERT_UNICODE_VALUE_ERR_INDEX}
  661. //+-------------------------------------------------------------------------
  662. //  X509_PUBLIC_KEY_INFO
  663. //
  664. //  pvStructInfo points to CERT_PUBLIC_KEY_INFO.
  665. //--------------------------------------------------------------------------
  666. //+-------------------------------------------------------------------------
  667. //  X509_AUTHORITY_KEY_ID
  668. //  szOID_AUTHORITY_KEY_IDENTIFIER
  669. //
  670. //  pvStructInfo points to following CERT_AUTHORITY_KEY_ID_INFO.
  671. //--------------------------------------------------------------------------
  672. type
  673.   PCERT_AUTHORITY_KEY_ID_INFO = ^CERT_AUTHORITY_KEY_ID_INFO;
  674.   {$EXTERNALSYM PCERT_AUTHORITY_KEY_ID_INFO}
  675.   _CERT_AUTHORITY_KEY_ID_INFO = record
  676.     KeyId: CRYPT_DATA_BLOB;
  677.     CertIssuer: CERT_NAME_BLOB;
  678.     CertSerialNumber: CRYPT_INTEGER_BLOB;
  679.   end;
  680.   {$EXTERNALSYM _CERT_AUTHORITY_KEY_ID_INFO}
  681.   CERT_AUTHORITY_KEY_ID_INFO = _CERT_AUTHORITY_KEY_ID_INFO;
  682.   {$EXTERNALSYM CERT_AUTHORITY_KEY_ID_INFO}
  683.   TCertAuthorityKeyIdInfo = CERT_AUTHORITY_KEY_ID_INFO;
  684.   PCertAuthorityKeyIdInfo = PCERT_AUTHORITY_KEY_ID_INFO;
  685. //+-------------------------------------------------------------------------
  686. //  X509_KEY_ATTRIBUTES
  687. //  szOID_KEY_ATTRIBUTES
  688. //
  689. //  pvStructInfo points to following CERT_KEY_ATTRIBUTES_INFO.
  690. //--------------------------------------------------------------------------
  691.   PCERT_PRIVATE_KEY_VALIDITY = ^CERT_PRIVATE_KEY_VALIDITY;
  692.   {$EXTERNALSYM PCERT_PRIVATE_KEY_VALIDITY}
  693.   _CERT_PRIVATE_KEY_VALIDITY = record
  694.     NotBefore: FILETIME;
  695.     NotAfter: FILETIME;
  696.   end;
  697.   {$EXTERNALSYM _CERT_PRIVATE_KEY_VALIDITY}
  698.   CERT_PRIVATE_KEY_VALIDITY = _CERT_PRIVATE_KEY_VALIDITY;
  699.   {$EXTERNALSYM CERT_PRIVATE_KEY_VALIDITY}
  700.   TCertPrivateKeyValidity = CERT_PRIVATE_KEY_VALIDITY;
  701.   PCertPrivateKeyValidity = PCERT_PRIVATE_KEY_VALIDITY;
  702.   PCERT_KEY_ATTRIBUTES_INFO = ^CERT_KEY_ATTRIBUTES_INFO;
  703.   {$EXTERNALSYM PCERT_KEY_ATTRIBUTES_INFO}
  704.   _CERT_KEY_ATTRIBUTES_INFO = record
  705.     KeyId: CRYPT_DATA_BLOB;
  706.     IntendedKeyUsage: CRYPT_BIT_BLOB;
  707.     pPrivateKeyUsagePeriod: PCERT_PRIVATE_KEY_VALIDITY; // OPTIONAL
  708.   end;
  709.   {$EXTERNALSYM _CERT_KEY_ATTRIBUTES_INFO}
  710.   CERT_KEY_ATTRIBUTES_INFO = _CERT_KEY_ATTRIBUTES_INFO;
  711.   {$EXTERNALSYM CERT_KEY_ATTRIBUTES_INFO}
  712.   TCertKeyAttributesInfo = CERT_KEY_ATTRIBUTES_INFO;
  713.   PCertKeyAttributesInfo = PCERT_KEY_ATTRIBUTES_INFO;
  714. // Byte[0]
  715. const
  716.   CERT_DIGITAL_SIGNATURE_KEY_USAGE = $80;
  717.   {$EXTERNALSYM CERT_DIGITAL_SIGNATURE_KEY_USAGE}
  718.   CERT_NON_REPUDIATION_KEY_USAGE   = $40;
  719.   {$EXTERNALSYM CERT_NON_REPUDIATION_KEY_USAGE}
  720.   CERT_KEY_ENCIPHERMENT_KEY_USAGE  = $20;
  721.   {$EXTERNALSYM CERT_KEY_ENCIPHERMENT_KEY_USAGE}
  722.   CERT_DATA_ENCIPHERMENT_KEY_USAGE = $10;
  723.   {$EXTERNALSYM CERT_DATA_ENCIPHERMENT_KEY_USAGE}
  724.   CERT_KEY_AGREEMENT_KEY_USAGE     = $08;
  725.   {$EXTERNALSYM CERT_KEY_AGREEMENT_KEY_USAGE}
  726.   CERT_KEY_CERT_SIGN_KEY_USAGE     = $04;
  727.   {$EXTERNALSYM CERT_KEY_CERT_SIGN_KEY_USAGE}
  728.   CERT_OFFLINE_CRL_SIGN_KEY_USAGE  = $02;
  729.   {$EXTERNALSYM CERT_OFFLINE_CRL_SIGN_KEY_USAGE}
  730.   CERT_CRL_SIGN_KEY_USAGE          = $02;
  731.   {$EXTERNALSYM CERT_CRL_SIGN_KEY_USAGE}
  732.   CERT_ENCIPHER_ONLY_KEY_USAGE     = $01;
  733.   {$EXTERNALSYM CERT_ENCIPHER_ONLY_KEY_USAGE}
  734. // Byte[1]
  735.   CERT_DECIPHER_ONLY_KEY_USAGE     = $80;
  736.   {$EXTERNALSYM CERT_DECIPHER_ONLY_KEY_USAGE}
  737. //+-------------------------------------------------------------------------
  738. //  X509_KEY_USAGE_RESTRICTION
  739. //  szOID_KEY_USAGE_RESTRICTION
  740. //
  741. //  pvStructInfo points to following CERT_KEY_USAGE_RESTRICTION_INFO.
  742. //--------------------------------------------------------------------------
  743. type
  744.   PCERT_POLICY_ID = ^CERT_POLICY_ID;
  745.   {$EXTERNALSYM PCERT_POLICY_ID}
  746.   _CERT_POLICY_ID = record
  747.     cCertPolicyElementId: DWORD;
  748.     rgpszCertPolicyElementId: LPSTR; // pszObjId
  749.   end;
  750.   {$EXTERNALSYM _CERT_POLICY_ID}
  751.   CERT_POLICY_ID = _CERT_POLICY_ID;
  752.   {$EXTERNALSYM CERT_POLICY_ID}
  753.   TCertPolicyId = CERT_POLICY_ID;
  754.   PCertPolicyId = PCERT_POLICY_ID;
  755.   PCERT_KEY_USAGE_RESTRICTION_INFO = ^CERT_KEY_USAGE_RESTRICTION_INFO;
  756.   {$EXTERNALSYM PCERT_KEY_USAGE_RESTRICTION_INFO}
  757.   _CERT_KEY_USAGE_RESTRICTION_INFO = record
  758.     cCertPolicyId: DWORD;
  759.     rgCertPolicyId: PCERT_POLICY_ID;
  760.     RestrictedKeyUsage: CRYPT_BIT_BLOB;
  761.   end;
  762.   {$EXTERNALSYM _CERT_KEY_USAGE_RESTRICTION_INFO}
  763.   CERT_KEY_USAGE_RESTRICTION_INFO = _CERT_KEY_USAGE_RESTRICTION_INFO;
  764.   {$EXTERNALSYM CERT_KEY_USAGE_RESTRICTION_INFO}
  765.   TCertKeyUsageRestrictionInfo = CERT_KEY_USAGE_RESTRICTION_INFO;
  766.   PCertKeyUsageRestrictionInfo = PCERT_KEY_USAGE_RESTRICTION_INFO;
  767. // See CERT_KEY_ATTRIBUTES_INFO for definition of the RestrictedKeyUsage bits
  768. //+-------------------------------------------------------------------------
  769. //  X509_ALTERNATE_NAME
  770. //  szOID_SUBJECT_ALT_NAME
  771. //  szOID_ISSUER_ALT_NAME
  772. //  szOID_SUBJECT_ALT_NAME2
  773. //  szOID_ISSUER_ALT_NAME2
  774. //
  775. //  pvStructInfo points to following CERT_ALT_NAME_INFO.
  776. //--------------------------------------------------------------------------
  777.   PCERT_OTHER_NAME = ^CERT_OTHER_NAME;
  778.   {$EXTERNALSYM PCERT_OTHER_NAME}
  779.   _CERT_OTHER_NAME = record
  780.     pszObjId: LPSTR;
  781.     Value: CRYPT_OBJID_BLOB;
  782.   end;
  783.   {$EXTERNALSYM _CERT_OTHER_NAME}
  784.   CERT_OTHER_NAME = _CERT_OTHER_NAME;
  785.   {$EXTERNALSYM CERT_OTHER_NAME}
  786.   TCertOtherName = CERT_OTHER_NAME;
  787.   PCertOtherName = PCERT_OTHER_NAME;
  788.   PCERT_ALT_NAME_ENTRY = ^CERT_ALT_NAME_ENTRY;
  789.   {$EXTERNALSYM PCERT_ALT_NAME_ENTRY}
  790.   _CERT_ALT_NAME_ENTRY = record
  791.     dwAltNameChoice: DWORD;
  792.     //union {
  793.     case Integer of
  794.       0: (pOtherName: PCERT_OTHER_NAME);  // 1
  795.       1: (pwszRfc822Name: LPWSTR);        // 2  (encoded IA5)
  796.       2: (pwszDNSName: LPWSTR);           // 3  (encoded IA5)
  797.       3: ();// Not implemented          x400Address;        // 4
  798.       4: (DirectoryName: CERT_NAME_BLOB); // 5
  799.       5: ();// Not implemented          pEdiPartyName;      // 6
  800.       6: (pwszURL: LPWSTR);               // 7  (encoded IA5)
  801.       7: (IPAddress: CRYPT_DATA_BLOB);    // 8  (Octet String)
  802.       8: (pszRegisteredID: LPSTR);        // 9  (Object Identifer)
  803.   end;
  804.   {$EXTERNALSYM _CERT_ALT_NAME_ENTRY}
  805.   CERT_ALT_NAME_ENTRY = _CERT_ALT_NAME_ENTRY;
  806.   {$EXTERNALSYM CERT_ALT_NAME_ENTRY}
  807.   TCertAltNameEntry = CERT_ALT_NAME_ENTRY;
  808.   PCertAltNameEntry = PCERT_ALT_NAME_ENTRY;
  809. const
  810.   CERT_ALT_NAME_OTHER_NAME     = 1;
  811.   {$EXTERNALSYM CERT_ALT_NAME_OTHER_NAME}
  812.   CERT_ALT_NAME_RFC822_NAME    = 2;
  813.   {$EXTERNALSYM CERT_ALT_NAME_RFC822_NAME}
  814.   CERT_ALT_NAME_DNS_NAME       = 3;
  815.   {$EXTERNALSYM CERT_ALT_NAME_DNS_NAME}
  816.   CERT_ALT_NAME_X400_ADDRESS   = 4;
  817.   {$EXTERNALSYM CERT_ALT_NAME_X400_ADDRESS}
  818.   CERT_ALT_NAME_DIRECTORY_NAME = 5;
  819.   {$EXTERNALSYM CERT_ALT_NAME_DIRECTORY_NAME}
  820.   CERT_ALT_NAME_EDI_PARTY_NAME = 6;
  821.   {$EXTERNALSYM CERT_ALT_NAME_EDI_PARTY_NAME}
  822.   CERT_ALT_NAME_URL            = 7;
  823.   {$EXTERNALSYM CERT_ALT_NAME_URL}
  824.   CERT_ALT_NAME_IP_ADDRESS     = 8;
  825.   {$EXTERNALSYM CERT_ALT_NAME_IP_ADDRESS}
  826.   CERT_ALT_NAME_REGISTERED_ID  = 9;
  827.   {$EXTERNALSYM CERT_ALT_NAME_REGISTERED_ID}
  828. type
  829.   PCERT_ALT_NAME_INFO = ^CERT_ALT_NAME_INFO;
  830.   {$EXTERNALSYM PCERT_ALT_NAME_INFO}
  831.   _CERT_ALT_NAME_INFO = record
  832.     cAltEntry: DWORD;
  833.     rgAltEntry: PCERT_ALT_NAME_ENTRY;
  834.   end;
  835.   {$EXTERNALSYM _CERT_ALT_NAME_INFO}
  836.   CERT_ALT_NAME_INFO = _CERT_ALT_NAME_INFO;
  837.   {$EXTERNALSYM CERT_ALT_NAME_INFO}
  838.   TCertAltNameInfo = CERT_ALT_NAME_INFO;
  839.   PCertAltNameInfo = PCERT_ALT_NAME_INFO;
  840. //+-------------------------------------------------------------------------
  841. //  Alternate name IA5 Error Location Definitions for
  842. //  CRYPT_E_INVALID_IA5_STRING.
  843. //
  844. //  Error location is returned in *pcbEncoded by
  845. //  CryptEncodeObject(X509_ALTERNATE_NAME)
  846. //
  847. //  Error location consists of:
  848. //    ENTRY_INDEX   - 8 bits << 16
  849. //    VALUE_INDEX   - 16 bits (unicode character index)
  850. //--------------------------------------------------------------------------
  851. const
  852.   CERT_ALT_NAME_ENTRY_ERR_INDEX_MASK  = $FF;
  853.   {$EXTERNALSYM CERT_ALT_NAME_ENTRY_ERR_INDEX_MASK}
  854.   CERT_ALT_NAME_ENTRY_ERR_INDEX_SHIFT = 16;
  855.   {$EXTERNALSYM CERT_ALT_NAME_ENTRY_ERR_INDEX_SHIFT}
  856.   CERT_ALT_NAME_VALUE_ERR_INDEX_MASK  = $0000FFFF;
  857.   {$EXTERNALSYM CERT_ALT_NAME_VALUE_ERR_INDEX_MASK}
  858.   CERT_ALT_NAME_VALUE_ERR_INDEX_SHIFT = 0;
  859.   {$EXTERNALSYM CERT_ALT_NAME_VALUE_ERR_INDEX_SHIFT}
  860. function GET_CERT_ALT_NAME_ENTRY_ERR_INDEX(X: DWORD): DWORD;
  861. {$EXTERNALSYM GET_CERT_ALT_NAME_ENTRY_ERR_INDEX}
  862. function GET_CERT_ALT_NAME_VALUE_ERR_INDEX(X: DWORD): DWORD;
  863. {$EXTERNALSYM GET_CERT_ALT_NAME_VALUE_ERR_INDEX}
  864. //+-------------------------------------------------------------------------
  865. //  X509_BASIC_CONSTRAINTS
  866. //  szOID_BASIC_CONSTRAINTS
  867. //
  868. //  pvStructInfo points to following CERT_BASIC_CONSTRAINTS_INFO.
  869. //--------------------------------------------------------------------------
  870. type
  871.   PCERT_BASIC_CONSTRAINTS_INFO = ^CERT_BASIC_CONSTRAINTS_INFO;
  872.   {$EXTERNALSYM PCERT_BASIC_CONSTRAINTS_INFO}
  873.   _CERT_BASIC_CONSTRAINTS_INFO = record
  874.     SubjectType: CRYPT_BIT_BLOB;
  875.     fPathLenConstraint: BOOL;
  876.     dwPathLenConstraint: DWORD;
  877.     cSubtreesConstraint: DWORD;
  878.     rgSubtreesConstraint: PCERT_NAME_BLOB;
  879.   end;
  880.   {$EXTERNALSYM _CERT_BASIC_CONSTRAINTS_INFO}
  881.   CERT_BASIC_CONSTRAINTS_INFO = _CERT_BASIC_CONSTRAINTS_INFO;
  882.   {$EXTERNALSYM CERT_BASIC_CONSTRAINTS_INFO}
  883.   TCertBasicConstraintsInfo = CERT_BASIC_CONSTRAINTS_INFO;
  884.   PCertBasicConstraintsInfo = PCERT_BASIC_CONSTRAINTS_INFO;
  885. const
  886.   CERT_CA_SUBJECT_FLAG         = $80;
  887.   {$EXTERNALSYM CERT_CA_SUBJECT_FLAG}
  888.   CERT_END_ENTITY_SUBJECT_FLAG = $40;
  889.   {$EXTERNALSYM CERT_END_ENTITY_SUBJECT_FLAG}
  890. //+-------------------------------------------------------------------------
  891. //  X509_BASIC_CONSTRAINTS2
  892. //  szOID_BASIC_CONSTRAINTS2
  893. //
  894. //  pvStructInfo points to following CERT_BASIC_CONSTRAINTS2_INFO.
  895. //--------------------------------------------------------------------------
  896. type
  897.   PCERT_BASIC_CONSTRAINTS2_INFO = ^CERT_BASIC_CONSTRAINTS2_INFO;
  898.   {$EXTERNALSYM PCERT_BASIC_CONSTRAINTS2_INFO}
  899.   _CERT_BASIC_CONSTRAINTS2_INFO = record
  900.     fCA: BOOL;
  901.     fPathLenConstraint: BOOL;
  902.     dwPathLenConstraint: DWORD;
  903.   end;
  904.   {$EXTERNALSYM _CERT_BASIC_CONSTRAINTS2_INFO}
  905.   CERT_BASIC_CONSTRAINTS2_INFO = _CERT_BASIC_CONSTRAINTS2_INFO;
  906.   {$EXTERNALSYM CERT_BASIC_CONSTRAINTS2_INFO}
  907.   TCertBasicConstraints2Info = CERT_BASIC_CONSTRAINTS2_INFO;
  908.   PCertBasicConstraints2Info = PCERT_BASIC_CONSTRAINTS2_INFO;
  909. //+-------------------------------------------------------------------------
  910. //  X509_KEY_USAGE
  911. //  szOID_KEY_USAGE
  912. //
  913. //  pvStructInfo points to a CRYPT_BIT_BLOB. Has same bit definitions as
  914. //  CERT_KEY_ATTRIBUTES_INFO's IntendedKeyUsage.
  915. //--------------------------------------------------------------------------
  916. //+-------------------------------------------------------------------------
  917. //  X509_CERT_POLICIES
  918. //  szOID_CERT_POLICIES
  919. //  szOID_CERT_POLICIES_95   NOTE--Only allowed for decoding!!!
  920. //
  921. //  pvStructInfo points to following CERT_POLICIES_INFO.
  922. //
  923. //  NOTE: when decoding using szOID_CERT_POLICIES_95 the pszPolicyIdentifier
  924. //        may contain an empty string
  925. //--------------------------------------------------------------------------
  926.   PCERT_POLICY_QUALIFIER_INFO = ^CERT_POLICY_QUALIFIER_INFO;
  927.   {$EXTERNALSYM PCERT_POLICY_QUALIFIER_INFO}
  928.   _CERT_POLICY_QUALIFIER_INFO = record
  929.     pszPolicyQualifierId: LPSTR; // pszObjId
  930.     Qualifier: CRYPT_OBJID_BLOB; // optional
  931.   end;
  932.   {$EXTERNALSYM _CERT_POLICY_QUALIFIER_INFO}
  933.   CERT_POLICY_QUALIFIER_INFO = _CERT_POLICY_QUALIFIER_INFO;
  934.   {$EXTERNALSYM CERT_POLICY_QUALIFIER_INFO}
  935.   TCertPolicyQualifierInfo = CERT_POLICY_QUALIFIER_INFO;
  936.   PCertPolicyQualifierInfo = PCERT_POLICY_QUALIFIER_INFO;
  937.   PCERT_POLICY_INFO = ^CERT_POLICY_INFO;
  938.   {$EXTERNALSYM PCERT_POLICY_INFO}
  939.   _CERT_POLICY_INFO = record
  940.     pszPolicyIdentifier: LPSTR; // pszObjId
  941.     cPolicyQualifier: DWORD; // optional
  942.     rgPolicyQualifier: PCERT_POLICY_QUALIFIER_INFO;
  943.   end;
  944.   {$EXTERNALSYM _CERT_POLICY_INFO}
  945.   CERT_POLICY_INFO = _CERT_POLICY_INFO;
  946.   {$EXTERNALSYM CERT_POLICY_INFO}
  947.   TCertPolicyInfo = CERT_POLICY_INFO;
  948.   PCertPolicyInfo = PCERT_POLICY_INFO;
  949.   PCERT_POLICIES_INFO = ^CERT_POLICIES_INFO;
  950.   {$EXTERNALSYM PCERT_POLICIES_INFO}
  951.   _CERT_POLICIES_INFO = record
  952.     cPolicyInfo: DWORD;
  953.     rgPolicyInfo: PCERT_POLICY_INFO;
  954.   end;
  955.   {$EXTERNALSYM _CERT_POLICIES_INFO}
  956.   CERT_POLICIES_INFO = _CERT_POLICIES_INFO;
  957.   {$EXTERNALSYM CERT_POLICIES_INFO}
  958.   TCertPoliciesInfo = CERT_POLICIES_INFO;
  959.   PCertPoliciesInfo = PCERT_POLICIES_INFO;
  960. //+-------------------------------------------------------------------------
  961. //  X509_PKIX_POLICY_QUALIFIER_USERNOTICE
  962. //  szOID_PKIX_POLICY_QUALIFIER_USERNOTICE
  963. //
  964. //  pvStructInfo points to following CERT_POLICY_QUALIFIER_USER_NOTICE.
  965. //
  966. //--------------------------------------------------------------------------
  967.   PCERT_POLICY_QUALIFIER_NOTICE_REFERENCE = ^CERT_POLICY_QUALIFIER_NOTICE_REFERENCE;
  968.   {$EXTERNALSYM PCERT_POLICY_QUALIFIER_NOTICE_REFERENCE}
  969.   _CERT_POLICY_QUALIFIER_NOTICE_REFERENCE = record
  970.     pszOrganization: LPSTR;
  971.     cNoticeNumbers: DWORD;
  972.     rgNoticeNumbers: LPINT;
  973.   end;
  974.   {$EXTERNALSYM _CERT_POLICY_QUALIFIER_NOTICE_REFERENCE}
  975.   CERT_POLICY_QUALIFIER_NOTICE_REFERENCE = _CERT_POLICY_QUALIFIER_NOTICE_REFERENCE;
  976.   {$EXTERNALSYM CERT_POLICY_QUALIFIER_NOTICE_REFERENCE}
  977.   TCertPolicyQualifierNoticeReference = CERT_POLICY_QUALIFIER_NOTICE_REFERENCE;
  978.   PCertPolicyQualifierNoticeReference = PCERT_POLICY_QUALIFIER_NOTICE_REFERENCE;
  979.   PCERT_POLICY_QUALIFIER_USER_NOTICE = ^CERT_POLICY_QUALIFIER_USER_NOTICE;
  980.   {$EXTERNALSYM PCERT_POLICY_QUALIFIER_USER_NOTICE}
  981.   _CERT_POLICY_QUALIFIER_USER_NOTICE = record
  982.     pNoticeReference: PCERT_POLICY_QUALIFIER_NOTICE_REFERENCE; // optional
  983.     pszDisplayText: LPWSTR; // optional
  984.   end;
  985.   {$EXTERNALSYM _CERT_POLICY_QUALIFIER_USER_NOTICE}
  986.   CERT_POLICY_QUALIFIER_USER_NOTICE = _CERT_POLICY_QUALIFIER_USER_NOTICE;
  987.   {$EXTERNALSYM CERT_POLICY_QUALIFIER_USER_NOTICE}
  988.   TCertPolicyQualifierUserNotice = CERT_POLICY_QUALIFIER_USER_NOTICE;
  989.   PCertPolicyQualifierUserNotice = PCERT_POLICY_QUALIFIER_USER_NOTICE;
  990. //+-------------------------------------------------------------------------
  991. //  szOID_CERT_POLICIES_95_QUALIFIER1 - Decode Only!!!!
  992. //
  993. //  pvStructInfo points to following CERT_POLICY95_QUALIFIER1.
  994. //
  995. //--------------------------------------------------------------------------
  996.   PCPS_URLS = ^CPS_URLS;
  997.   {$EXTERNALSYM PCPS_URLS}
  998.   _CPS_URLS = record
  999.     pszURL: LPWSTR;
  1000.     pAlgorithm: PCRYPT_ALGORITHM_IDENTIFIER; // optional
  1001.     pDigest: PCRYPT_DATA_BLOB; // optional
  1002.   end;
  1003.   {$EXTERNALSYM _CPS_URLS}
  1004.   CPS_URLS = _CPS_URLS;
  1005.   {$EXTERNALSYM CPS_URLS}
  1006.   TCpsUrls = CPS_URLS;
  1007.   PCpsUrls = PCPS_URLS;
  1008.   PCERT_POLICY95_QUALIFIER1 = ^CERT_POLICY95_QUALIFIER1;
  1009.   {$EXTERNALSYM PCERT_POLICY95_QUALIFIER1}
  1010.   _CERT_POLICY95_QUALIFIER1 = record
  1011.     pszPracticesReference: LPWSTR; // optional
  1012.     pszNoticeIdentifier: LPSTR; // optional
  1013.     pszNSINoticeIdentifier: LPSTR; // optional
  1014.     cCPSURLs: DWORD;
  1015.     rgCPSURLs: PCPS_URLS; // optional
  1016.   end;
  1017.   {$EXTERNALSYM _CERT_POLICY95_QUALIFIER1}
  1018.   CERT_POLICY95_QUALIFIER1 = _CERT_POLICY95_QUALIFIER1;
  1019.   {$EXTERNALSYM CERT_POLICY95_QUALIFIER1}
  1020.   TCertPolicy95Qualifier1 = CERT_POLICY95_QUALIFIER1;
  1021.   PCertPolicy95Qualifier1 = PCERT_POLICY95_QUALIFIER1;
  1022. //+-------------------------------------------------------------------------
  1023. //  RSA_CSP_PUBLICKEYBLOB
  1024. //
  1025. //  pvStructInfo points to a PUBLICKEYSTRUC immediately followed by a
  1026. //  RSAPUBKEY and the modulus bytes.
  1027. //
  1028. //  CryptExportKey outputs the above StructInfo for a dwBlobType of
  1029. //  PUBLICKEYBLOB. CryptImportKey expects the above StructInfo when
  1030. //  importing a public key.
  1031. //
  1032. //  For dwCertEncodingType = X509_ASN_ENCODING, the RSA_CSP_PUBLICKEYBLOB is
  1033. //  encoded as a PKCS #1 RSAPublicKey consisting of a SEQUENCE of a
  1034. //  modulus INTEGER and a publicExponent INTEGER. The modulus is encoded
  1035. //  as being a unsigned integer. When decoded, if the modulus was encoded
  1036. //  as unsigned integer with a leading 0 byte, the 0 byte is removed before
  1037. //  converting to the CSP modulus bytes.
  1038. //
  1039. //  For decode, the aiKeyAlg field of PUBLICKEYSTRUC is always set to
  1040. //  CALG_RSA_KEYX.
  1041. //--------------------------------------------------------------------------
  1042. //+-------------------------------------------------------------------------
  1043. //  X509_KEYGEN_REQUEST_TO_BE_SIGNED
  1044. //
  1045. //  pvStructInfo points to CERT_KEYGEN_REQUEST_INFO.
  1046. //
  1047. //  For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  1048. //  signature (output of a X509_CERT CryptEncodeObject()).
  1049. //
  1050. //  For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  1051. //--------------------------------------------------------------------------
  1052. //+-------------------------------------------------------------------------
  1053. //  PKCS_ATTRIBUTE data structure
  1054. //
  1055. //  pvStructInfo points to a CRYPT_ATTRIBUTE.
  1056. //--------------------------------------------------------------------------
  1057. //+-------------------------------------------------------------------------
  1058. //  PKCS_ATTRIBUTES data structure
  1059. //
  1060. //  pvStructInfo points to a CRYPT_ATTRIBUTES.
  1061. //--------------------------------------------------------------------------
  1062. //+-------------------------------------------------------------------------
  1063. //  PKCS_CONTENT_INFO_SEQUENCE_OF_ANY data structure
  1064. //
  1065. //  pvStructInfo points to following CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY.
  1066. //
  1067. //  For X509_ASN_ENCODING: encoded as a PKCS#7 ContentInfo structure wrapping
  1068. //  a sequence of ANY. The value of the contentType field is pszObjId,
  1069. //  while the content field is the following structure:
  1070. //      SequenceOfAny ::= SEQUENCE OF ANY
  1071. //
  1072. //  The CRYPT_DER_BLOBs point to the already encoded ANY content.
  1073. //--------------------------------------------------------------------------
  1074.   PCRYPT_CONTENT_INFO_SEQUENCE_OF_ANY = ^CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY;
  1075.   {$EXTERNALSYM PCRYPT_CONTENT_INFO_SEQUENCE_OF_ANY}
  1076.   _CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY = record
  1077.     pszObjId: LPSTR;
  1078.     cValue: DWORD;
  1079.     rgValue: PCRYPT_DER_BLOB;
  1080.   end;
  1081.   {$EXTERNALSYM _CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY}
  1082.   CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY = _CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY;
  1083.   {$EXTERNALSYM CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY}
  1084.   TCryptContentInfoSequenceOfAny = CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY;
  1085.   PCryptContentInfoSequenceOfAny = PCRYPT_CONTENT_INFO_SEQUENCE_OF_ANY;
  1086. //+-------------------------------------------------------------------------
  1087. //  PKCS_CONTENT_INFO data structure
  1088. //
  1089. //  pvStructInfo points to following CRYPT_CONTENT_INFO.
  1090. //
  1091. //  For X509_ASN_ENCODING: encoded as a PKCS#7 ContentInfo structure.
  1092. //  The CRYPT_DER_BLOB points to the already encoded ANY content.
  1093. //--------------------------------------------------------------------------
  1094.   PCRYPT_CONTENT_INFO = ^CRYPT_CONTENT_INFO;
  1095.   {$EXTERNALSYM PCRYPT_CONTENT_INFO}
  1096.   _CRYPT_CONTENT_INFO = record
  1097.     pszObjId: LPSTR;
  1098.     Content: CRYPT_DER_BLOB;
  1099.   end;
  1100.   {$EXTERNALSYM _CRYPT_CONTENT_INFO}
  1101.   CRYPT_CONTENT_INFO = _CRYPT_CONTENT_INFO;
  1102.   {$EXTERNALSYM CRYPT_CONTENT_INFO}
  1103.   TCryptContentInfo = CRYPT_CONTENT_INFO;
  1104.   PCryptContentInfo = PCRYPT_CONTENT_INFO;
  1105. //+-------------------------------------------------------------------------
  1106. //  X509_OCTET_STRING data structure
  1107. //
  1108. //  pvStructInfo points to a CRYPT_DATA_BLOB.
  1109. //--------------------------------------------------------------------------
  1110. //+-------------------------------------------------------------------------
  1111. //  X509_BITS data structure
  1112. //
  1113. //  pvStructInfo points to a CRYPT_BIT_BLOB.
  1114. //--------------------------------------------------------------------------
  1115. //+-------------------------------------------------------------------------
  1116. //  X509_BITS_WITHOUT_TRAILING_ZEROES data structure
  1117. //
  1118. //  pvStructInfo points to a CRYPT_BIT_BLOB.
  1119. //
  1120. //  The same as X509_BITS, except before encoding, the bit length is
  1121. //  decremented to exclude trailing zero bits.
  1122. //--------------------------------------------------------------------------
  1123. //+-------------------------------------------------------------------------
  1124. //  X509_INTEGER data structure
  1125. //
  1126. //  pvStructInfo points to an int.
  1127. //--------------------------------------------------------------------------
  1128. //+-------------------------------------------------------------------------
  1129. //  X509_MULTI_BYTE_INTEGER data structure
  1130. //
  1131. //  pvStructInfo points to a CRYPT_INTEGER_BLOB.
  1132. //--------------------------------------------------------------------------
  1133. //+-------------------------------------------------------------------------
  1134. //  X509_ENUMERATED data structure
  1135. //
  1136. //  pvStructInfo points to an int containing the enumerated value
  1137. //--------------------------------------------------------------------------
  1138. //+-------------------------------------------------------------------------
  1139. //  X509_CHOICE_OF_TIME data structure
  1140. //
  1141. //  pvStructInfo points to a FILETIME.
  1142. //--------------------------------------------------------------------------
  1143. //+-------------------------------------------------------------------------
  1144. //  X509_SEQUENCE_OF_ANY data structure
  1145. //
  1146. //  pvStructInfo points to following CRYPT_SEQUENCE_OF_ANY.
  1147. //
  1148. //  The CRYPT_DER_BLOBs point to the already encoded ANY content.
  1149. //--------------------------------------------------------------------------
  1150.   PCRYPT_SEQUENCE_OF_ANY = ^CRYPT_SEQUENCE_OF_ANY;
  1151.   {$EXTERNALSYM PCRYPT_SEQUENCE_OF_ANY}
  1152.   _CRYPT_SEQUENCE_OF_ANY = record
  1153.     cValue: DWORD;
  1154.     rgValue: PCRYPT_DER_BLOB;
  1155.   end;
  1156.   {$EXTERNALSYM _CRYPT_SEQUENCE_OF_ANY}
  1157.   CRYPT_SEQUENCE_OF_ANY = _CRYPT_SEQUENCE_OF_ANY;
  1158.   {$EXTERNALSYM CRYPT_SEQUENCE_OF_ANY}
  1159.   TCryptSequenceOfAny = CRYPT_SEQUENCE_OF_ANY;
  1160.   PCryptSequenceOfAny = PCRYPT_SEQUENCE_OF_ANY;
  1161. //+-------------------------------------------------------------------------
  1162. //  X509_AUTHORITY_KEY_ID2
  1163. //  szOID_AUTHORITY_KEY_IDENTIFIER2
  1164. //
  1165. //  pvStructInfo points to following CERT_AUTHORITY_KEY_ID2_INFO.
  1166. //
  1167. //  For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  1168. //  *pcbEncoded by CryptEncodeObject(X509_AUTHORITY_KEY_ID2)
  1169. //
  1170. //  See X509_ALTERNATE_NAME for error location defines.
  1171. //--------------------------------------------------------------------------
  1172.   PCERT_AUTHORITY_KEY_ID2_INFO = ^CERT_AUTHORITY_KEY_ID2_INFO;
  1173.   {$EXTERNALSYM PCERT_AUTHORITY_KEY_ID2_INFO}
  1174.   _CERT_AUTHORITY_KEY_ID2_INFO = record
  1175.     KeyId: CRYPT_DATA_BLOB;
  1176.     AuthorityCertIssuer: CERT_ALT_NAME_INFO; // Optional, set cAltEntry
  1177.     // to 0 to omit.
  1178.     AuthorityCertSerialNumber: CRYPT_INTEGER_BLOB;
  1179.   end;
  1180.   {$EXTERNALSYM _CERT_AUTHORITY_KEY_ID2_INFO}
  1181.   CERT_AUTHORITY_KEY_ID2_INFO = _CERT_AUTHORITY_KEY_ID2_INFO;
  1182.   {$EXTERNALSYM CERT_AUTHORITY_KEY_ID2_INFO}
  1183.   TCertAuthorityKeyId2Info = CERT_AUTHORITY_KEY_ID2_INFO;
  1184.   PCertAuthorityKeyId2Info = PCERT_AUTHORITY_KEY_ID2_INFO;
  1185. //+-------------------------------------------------------------------------
  1186. //  szOID_SUBJECT_KEY_IDENTIFIER
  1187. //
  1188. //  pvStructInfo points to a CRYPT_DATA_BLOB.
  1189. //--------------------------------------------------------------------------
  1190. //+-------------------------------------------------------------------------
  1191. //  X509_AUTHORITY_INFO_ACCESS
  1192. //  szOID_AUTHORITY_INFO_ACCESS
  1193. //
  1194. //  pvStructInfo points to following CERT_AUTHORITY_INFO_ACCESS.
  1195. //
  1196. //  For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  1197. //  *pcbEncoded by CryptEncodeObject(X509_AUTHORITY_INFO_ACCESS)
  1198. //
  1199. //  Error location consists of:
  1200. //    ENTRY_INDEX   - 8 bits << 16
  1201. //    VALUE_INDEX   - 16 bits (unicode character index)
  1202. //
  1203. //  See X509_ALTERNATE_NAME for ENTRY_INDEX and VALUE_INDEX error location
  1204. //  defines.
  1205. //--------------------------------------------------------------------------
  1206.   PCERT_ACCESS_DESCRIPTION = ^CERT_ACCESS_DESCRIPTION;
  1207.   {$EXTERNALSYM PCERT_ACCESS_DESCRIPTION}
  1208.   _CERT_ACCESS_DESCRIPTION = record
  1209.     pszAccessMethod: LPSTR; // pszObjId
  1210.     AccessLocation: CERT_ALT_NAME_ENTRY;
  1211.   end;
  1212.   {$EXTERNALSYM _CERT_ACCESS_DESCRIPTION}
  1213.   CERT_ACCESS_DESCRIPTION = _CERT_ACCESS_DESCRIPTION;
  1214.   {$EXTERNALSYM CERT_ACCESS_DESCRIPTION}
  1215.   TCertAccessDescription = CERT_ACCESS_DESCRIPTION;
  1216.   PCertAccessDescription = PCERT_ACCESS_DESCRIPTION;
  1217.   PCERT_AUTHORITY_INFO_ACCESS = ^CERT_AUTHORITY_INFO_ACCESS;
  1218.   {$EXTERNALSYM PCERT_AUTHORITY_INFO_ACCESS}
  1219.   _CERT_AUTHORITY_INFO_ACCESS = record
  1220.     cAccDescr: DWORD;
  1221.     rgAccDescr: PCERT_ACCESS_DESCRIPTION;
  1222.   end;
  1223.   {$EXTERNALSYM _CERT_AUTHORITY_INFO_ACCESS}
  1224.   CERT_AUTHORITY_INFO_ACCESS = _CERT_AUTHORITY_INFO_ACCESS;
  1225.   {$EXTERNALSYM CERT_AUTHORITY_INFO_ACCESS}
  1226.   TCertAuthorityInfoAccess = CERT_AUTHORITY_INFO_ACCESS;
  1227.   PCertAuthorityInfoAccess = PCERT_AUTHORITY_INFO_ACCESS;
  1228. //+-------------------------------------------------------------------------
  1229. //  PKIX Access Description: Access Method Object Identifiers
  1230. //--------------------------------------------------------------------------
  1231. const
  1232.   szOID_PKIX_ACC_DESCR  = '1.3.6.1.5.5.7.48';
  1233.   {$EXTERNALSYM szOID_PKIX_ACC_DESCR}
  1234.   szOID_PKIX_OCSP       = '1.3.6.1.5.5.7.48.1';
  1235.   {$EXTERNALSYM szOID_PKIX_OCSP}
  1236.   szOID_PKIX_CA_ISSUERS = '1.3.6.1.5.5.7.48.2';
  1237.   {$EXTERNALSYM szOID_PKIX_CA_ISSUERS}
  1238. //+-------------------------------------------------------------------------
  1239. //  X509_CRL_REASON_CODE
  1240. //  szOID_CRL_REASON_CODE
  1241. //
  1242. //  pvStructInfo points to an int which can be set to one of the following
  1243. //  enumerated values:
  1244. //--------------------------------------------------------------------------
  1245.   CRL_REASON_UNSPECIFIED            = 0;
  1246.   {$EXTERNALSYM CRL_REASON_UNSPECIFIED}
  1247.   CRL_REASON_KEY_COMPROMISE         = 1;
  1248.   {$EXTERNALSYM CRL_REASON_KEY_COMPROMISE}
  1249.   CRL_REASON_CA_COMPROMISE          = 2;
  1250.   {$EXTERNALSYM CRL_REASON_CA_COMPROMISE}
  1251.   CRL_REASON_AFFILIATION_CHANGED    = 3;
  1252.   {$EXTERNALSYM CRL_REASON_AFFILIATION_CHANGED}
  1253.   CRL_REASON_SUPERSEDED             = 4;
  1254.   {$EXTERNALSYM CRL_REASON_SUPERSEDED}
  1255.   CRL_REASON_CESSATION_OF_OPERATION = 5;
  1256.   {$EXTERNALSYM CRL_REASON_CESSATION_OF_OPERATION}
  1257.   CRL_REASON_CERTIFICATE_HOLD       = 6;
  1258.   {$EXTERNALSYM CRL_REASON_CERTIFICATE_HOLD}
  1259.   CRL_REASON_REMOVE_FROM_CRL        = 8;
  1260.   {$EXTERNALSYM CRL_REASON_REMOVE_FROM_CRL}
  1261. //+-------------------------------------------------------------------------
  1262. //  X509_CRL_DIST_POINTS
  1263. //  szOID_CRL_DIST_POINTS
  1264. //
  1265. //  pvStructInfo points to following CRL_DIST_POINTS_INFO.
  1266. //
  1267. //  For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  1268. //  *pcbEncoded by CryptEncodeObject(X509_CRL_DIST_POINTS)
  1269. //
  1270. //  Error location consists of:
  1271. //    CRL_ISSUER_BIT    - 1 bit  << 31 (0 for FullName, 1 for CRLIssuer)
  1272. //    POINT_INDEX       - 7 bits << 24
  1273. //    ENTRY_INDEX       - 8 bits << 16
  1274. //    VALUE_INDEX       - 16 bits (unicode character index)
  1275. //
  1276. //  See X509_ALTERNATE_NAME for ENTRY_INDEX and VALUE_INDEX error location
  1277. //  defines.
  1278. //--------------------------------------------------------------------------
  1279. type
  1280.   PCRL_DIST_POINT_NAME = ^CRL_DIST_POINT_NAME;
  1281.   {$EXTERNALSYM PCRL_DIST_POINT_NAME}
  1282.   _CRL_DIST_POINT_NAME = record
  1283.     dwDistPointNameChoice: DWORD;
  1284.     case Integer of
  1285.       0: (FullName: CERT_ALT_NAME_INFO); // 1
  1286.       1: ();// Not implemented      IssuerRDN;      // 2
  1287.   end;
  1288.   {$EXTERNALSYM _CRL_DIST_POINT_NAME}
  1289.   CRL_DIST_POINT_NAME = _CRL_DIST_POINT_NAME;
  1290.   {$EXTERNALSYM CRL_DIST_POINT_NAME}
  1291.   TCrlDistPointName = CRL_DIST_POINT_NAME;
  1292.   PCrlDistPointName = PCRL_DIST_POINT_NAME;
  1293. const
  1294.   CRL_DIST_POINT_NO_NAME         = 0;
  1295.   {$EXTERNALSYM CRL_DIST_POINT_NO_NAME}
  1296.   CRL_DIST_POINT_FULL_NAME       = 1;
  1297.   {$EXTERNALSYM CRL_DIST_POINT_FULL_NAME}
  1298.   CRL_DIST_POINT_ISSUER_RDN_NAME = 2;
  1299.   {$EXTERNALSYM CRL_DIST_POINT_ISSUER_RDN_NAME}
  1300. type
  1301.   PCRL_DIST_POINT = ^CRL_DIST_POINT;
  1302.   {$EXTERNALSYM PCRL_DIST_POINT}
  1303.   _CRL_DIST_POINT = record
  1304.     DistPointName: CRL_DIST_POINT_NAME; // OPTIONAL
  1305.     ReasonFlags: CRYPT_BIT_BLOB; // OPTIONAL
  1306.     CRLIssuer: CERT_ALT_NAME_INFO; // OPTIONAL
  1307.   end;
  1308.   {$EXTERNALSYM _CRL_DIST_POINT}
  1309.   CRL_DIST_POINT = _CRL_DIST_POINT;
  1310.   {$EXTERNALSYM CRL_DIST_POINT}
  1311.   TCrlDistPoint = CRL_DIST_POINT;
  1312.   PCrlDistPoint = PCRL_DIST_POINT;
  1313. const
  1314.   CRL_REASON_UNUSED_FLAG                 = $80;
  1315.   {$EXTERNALSYM CRL_REASON_UNUSED_FLAG}
  1316.   CRL_REASON_KEY_COMPROMISE_FLAG         = $40;
  1317.   {$EXTERNALSYM CRL_REASON_KEY_COMPROMISE_FLAG}
  1318.   CRL_REASON_CA_COMPROMISE_FLAG          = $20;
  1319.   {$EXTERNALSYM CRL_REASON_CA_COMPROMISE_FLAG}
  1320.   CRL_REASON_AFFILIATION_CHANGED_FLAG    = $10;
  1321.   {$EXTERNALSYM CRL_REASON_AFFILIATION_CHANGED_FLAG}
  1322.   CRL_REASON_SUPERSEDED_FLAG             = $08;
  1323.   {$EXTERNALSYM CRL_REASON_SUPERSEDED_FLAG}
  1324.   CRL_REASON_CESSATION_OF_OPERATION_FLAG = $04;
  1325.   {$EXTERNALSYM CRL_REASON_CESSATION_OF_OPERATION_FLAG}
  1326.   CRL_REASON_CERTIFICATE_HOLD_FLAG       = $02;
  1327.   {$EXTERNALSYM CRL_REASON_CERTIFICATE_HOLD_FLAG}
  1328. type
  1329.   PCRL_DIST_POINTS_INFO = ^CRL_DIST_POINTS_INFO;
  1330.   {$EXTERNALSYM PCRL_DIST_POINTS_INFO}
  1331.   _CRL_DIST_POINTS_INFO = record
  1332.     cDistPoint: DWORD;
  1333.     rgDistPoint: PCRL_DIST_POINT;
  1334.   end;
  1335.   {$EXTERNALSYM _CRL_DIST_POINTS_INFO}
  1336.   CRL_DIST_POINTS_INFO = _CRL_DIST_POINTS_INFO;
  1337.   {$EXTERNALSYM CRL_DIST_POINTS_INFO}
  1338.   TCrlDistPointsInfo = CRL_DIST_POINTS_INFO;
  1339.   PCrlDistPointsInfo = PCRL_DIST_POINTS_INFO;
  1340. const
  1341.   CRL_DIST_POINT_ERR_INDEX_MASK   = $7F;
  1342.   {$EXTERNALSYM CRL_DIST_POINT_ERR_INDEX_MASK}
  1343.   CRL_DIST_POINT_ERR_INDEX_SHIFT  = 24;
  1344.   {$EXTERNALSYM CRL_DIST_POINT_ERR_INDEX_SHIFT}
  1345. function GET_CRL_DIST_POINT_ERR_INDEX(X: DWORD): DWORD;
  1346. {$EXTERNALSYM GET_CRL_DIST_POINT_ERR_INDEX}
  1347. const
  1348.   CRL_DIST_POINT_ERR_CRL_ISSUER_BIT = DWORD($80000000);
  1349.   {$EXTERNALSYM CRL_DIST_POINT_ERR_CRL_ISSUER_BIT}
  1350. function IS_CRL_DIST_POINT_ERR_CRL_ISSUER(X: DWORD): Boolean;
  1351. {$EXTERNALSYM IS_CRL_DIST_POINT_ERR_CRL_ISSUER}
  1352. //+-------------------------------------------------------------------------
  1353. //  X509_ENHANCED_KEY_USAGE
  1354. //  szOID_ENHANCED_KEY_USAGE
  1355. //
  1356. //  pvStructInfo points to a CERT_ENHKEY_USAGE, CTL_USAGE.
  1357. //--------------------------------------------------------------------------
  1358. //+-------------------------------------------------------------------------
  1359. //  szOID_NEXT_UPDATE_LOCATION
  1360. //
  1361. //  pvStructInfo points to a CERT_ALT_NAME_INFO.
  1362. //--------------------------------------------------------------------------
  1363. //+-------------------------------------------------------------------------
  1364. //  PKCS_CTL
  1365. //  szOID_CTL
  1366. //
  1367. //  pvStructInfo points to a CTL_INFO.
  1368. //--------------------------------------------------------------------------
  1369. //+-------------------------------------------------------------------------
  1370. //  PKCS_SORTED_CTL
  1371. //
  1372. //  pvStructInfo points to a CTL_INFO.
  1373. //
  1374. //  Same as for PKCS_CTL, except, the CTL entries are sorted. The following
  1375. //  extension containing the sort information is inserted as the first
  1376. //  extension in the encoded CTL.
  1377. //
  1378. //  Only supported for Encoding. CRYPT_ENCODE_ALLOC_FLAG flag must be
  1379. //  set.
  1380. //--------------------------------------------------------------------------
  1381. //+-------------------------------------------------------------------------
  1382. // Sorted CTL TrustedSubjects extension
  1383. //
  1384. //  Array of little endian DWORDs:
  1385. //   [0] - Flags
  1386. //   [1] - Count of HashBucket entry offsets
  1387. //   [2] - Maximum HashBucket entry collision count
  1388. //   [3 ..] (Count + 1) HashBucket entry offsets
  1389. //
  1390. //  When this extension is present in the CTL,
  1391. //  the ASN.1 encoded sequence of TrustedSubjects are HashBucket ordered.
  1392. //
  1393. //  The entry offsets point to the start of the first encoded TrustedSubject
  1394. //  sequence for the HashBucket. The encoded TrustedSubjects for a HashBucket
  1395. //  continue until the encoded offset of the next HashBucket. A HashBucket has
  1396. //  no entries if HashBucket[N] == HashBucket[N + 1].
  1397. //
  1398. //  The HashBucket offsets are from the start of the ASN.1 encoded CTL_INFO.
  1399. //--------------------------------------------------------------------------
  1400. const
  1401.   SORTED_CTL_EXT_FLAGS_OFFSET         = (0*4);
  1402.   {$EXTERNALSYM SORTED_CTL_EXT_FLAGS_OFFSET}
  1403.   SORTED_CTL_EXT_COUNT_OFFSET         = (1*4);
  1404.   {$EXTERNALSYM SORTED_CTL_EXT_COUNT_OFFSET}
  1405.   SORTED_CTL_EXT_MAX_COLLISION_OFFSET = (2*4);
  1406.   {$EXTERNALSYM SORTED_CTL_EXT_MAX_COLLISION_OFFSET}
  1407.   SORTED_CTL_EXT_HASH_BUCKET_OFFSET   = (3*4);
  1408.   {$EXTERNALSYM SORTED_CTL_EXT_HASH_BUCKET_OFFSET}
  1409. // If the SubjectIdentifiers are a MD5 or SHA1 hash, the following flag is
  1410. // set. When set, the first 4 bytes of the SubjectIdentifier are used as
  1411. // the dwhash. Otherwise, the SubjectIdentifier bytes are hashed into dwHash.
  1412. // In either case the HashBucket index = dwHash % cHashBucket.
  1413.   SORTED_CTL_EXT_HASHED_SUBJECT_IDENTIFIER_FLAG = $1;
  1414.   {$EXTERNALSYM SORTED_CTL_EXT_HASHED_SUBJECT_IDENTIFIER_FLAG}
  1415. //+-------------------------------------------------------------------------
  1416. //  X509_MULTI_BYTE_UINT
  1417. //
  1418. //  pvStructInfo points to a CRYPT_UINT_BLOB. Before encoding, inserts a
  1419. //  leading 0x00. After decoding, removes a leading 0x00.
  1420. //--------------------------------------------------------------------------
  1421. //+-------------------------------------------------------------------------
  1422. //  X509_DSS_PUBLICKEY
  1423. //
  1424. //  pvStructInfo points to a CRYPT_UINT_BLOB.
  1425. //--------------------------------------------------------------------------
  1426. //+-------------------------------------------------------------------------
  1427. //  X509_DSS_PARAMETERS
  1428. //
  1429. //  pvStructInfo points to following CERT_DSS_PARAMETERS data structure.
  1430. //--------------------------------------------------------------------------
  1431. type
  1432.   PCERT_DSS_PARAMETERS = ^CERT_DSS_PARAMETERS;
  1433.   {$EXTERNALSYM PCERT_DSS_PARAMETERS}
  1434.   _CERT_DSS_PARAMETERS = record
  1435.     p: CRYPT_UINT_BLOB;
  1436.     q: CRYPT_UINT_BLOB;
  1437.     g: CRYPT_UINT_BLOB;
  1438.   end;
  1439.   {$EXTERNALSYM _CERT_DSS_PARAMETERS}
  1440.   CERT_DSS_PARAMETERS = _CERT_DSS_PARAMETERS;
  1441.   {$EXTERNALSYM CERT_DSS_PARAMETERS}
  1442.   TCertDssParameters = CERT_DSS_PARAMETERS;
  1443.   PCertDssParameters = PCERT_DSS_PARAMETERS;
  1444. //+-------------------------------------------------------------------------
  1445. //  X509_DSS_SIGNATURE
  1446. //
  1447. //  pvStructInfo is a BYTE rgbSignature[CERT_DSS_SIGNATURE_LEN]. The
  1448. //  bytes are ordered as output by the DSS CSP's CryptSignHash().
  1449. //--------------------------------------------------------------------------
  1450. const
  1451.   CERT_DSS_R_LEN         = 20;
  1452.   {$EXTERNALSYM CERT_DSS_R_LEN}
  1453.   CERT_DSS_S_LEN         = 20;
  1454.   {$EXTERNALSYM CERT_DSS_S_LEN}
  1455.   CERT_DSS_SIGNATURE_LEN = (CERT_DSS_R_LEN + CERT_DSS_S_LEN);
  1456.   {$EXTERNALSYM CERT_DSS_SIGNATURE_LEN}
  1457. // Sequence of 2 unsigned integers (the extra +1 is for a potential leading
  1458. // 0x00 to make the integer unsigned)
  1459.   CERT_MAX_ASN_ENCODED_DSS_SIGNATURE_LEN = (2 + 2 * (2 + 20 + 1));
  1460.   {$EXTERNALSYM CERT_MAX_ASN_ENCODED_DSS_SIGNATURE_LEN}
  1461. //+-------------------------------------------------------------------------
  1462. //  X509_DH_PUBLICKEY
  1463. //
  1464. //  pvStructInfo points to a CRYPT_UINT_BLOB.
  1465. //--------------------------------------------------------------------------
  1466. //+-------------------------------------------------------------------------
  1467. //  X509_DH_PARAMETERS
  1468. //
  1469. //  pvStructInfo points to following CERT_DH_PARAMETERS data structure.
  1470. //--------------------------------------------------------------------------
  1471. type
  1472.   PCERT_DH_PARAMETERS = ^CERT_DH_PARAMETERS;
  1473.   {$EXTERNALSYM PCERT_DH_PARAMETERS}
  1474.   _CERT_DH_PARAMETERS = record
  1475.     p: CRYPT_UINT_BLOB;
  1476.     g: CRYPT_UINT_BLOB;
  1477.   end;
  1478.   {$EXTERNALSYM _CERT_DH_PARAMETERS}
  1479.   CERT_DH_PARAMETERS = _CERT_DH_PARAMETERS;
  1480.   {$EXTERNALSYM CERT_DH_PARAMETERS}
  1481.   TCertDhParameters = CERT_DH_PARAMETERS;
  1482.   PCertDhParameters = PCERT_DH_PARAMETERS;
  1483. //+-------------------------------------------------------------------------
  1484. //  X942_DH_PARAMETERS
  1485. //
  1486. //  pvStructInfo points to following CERT_X942_DH_PARAMETERS data structure.
  1487. //
  1488. //  If q.cbData == 0, then, the following fields are zero'ed.
  1489. //--------------------------------------------------------------------------
  1490.   PCERT_X942_DH_VALIDATION_PARAMS = ^CERT_X942_DH_VALIDATION_PARAMS;
  1491.   {$EXTERNALSYM PCERT_X942_DH_VALIDATION_PARAMS}
  1492.   _CERT_X942_DH_VALIDATION_PARAMS = record
  1493.     seed: CRYPT_BIT_BLOB;
  1494.     pgenCounter: DWORD;
  1495.   end;
  1496.   {$EXTERNALSYM _CERT_X942_DH_VALIDATION_PARAMS}
  1497.   CERT_X942_DH_VALIDATION_PARAMS = _CERT_X942_DH_VALIDATION_PARAMS;
  1498.   {$EXTERNALSYM CERT_X942_DH_VALIDATION_PARAMS}
  1499.   TCertX942DhValidationParams = CERT_X942_DH_VALIDATION_PARAMS;
  1500.   PCertX942DhValidationParams = PCERT_X942_DH_VALIDATION_PARAMS;
  1501.   PCERT_X942_DH_PARAMETERS = ^CERT_X942_DH_PARAMETERS;
  1502.   {$EXTERNALSYM PCERT_X942_DH_PARAMETERS}
  1503.   _CERT_X942_DH_PARAMETERS = record
  1504.     p: CRYPT_UINT_BLOB; // odd prime, p = jq + 1
  1505.     g: CRYPT_UINT_BLOB; // generator, g
  1506.     q: CRYPT_UINT_BLOB; // factor of p - 1, OPTIONAL
  1507.     j: CRYPT_UINT_BLOB; // subgroup factor, OPTIONAL
  1508.     pValidationParams: PCERT_X942_DH_VALIDATION_PARAMS; // OPTIONAL
  1509.   end;
  1510.   {$EXTERNALSYM _CERT_X942_DH_PARAMETERS}
  1511.   CERT_X942_DH_PARAMETERS = _CERT_X942_DH_PARAMETERS;
  1512.   {$EXTERNALSYM CERT_X942_DH_PARAMETERS}
  1513.   TCertX942DhParameters = CERT_X942_DH_PARAMETERS;
  1514.   PCertX942DhParameters = PCERT_X942_DH_PARAMETERS;
  1515. //+-------------------------------------------------------------------------
  1516. //  X942_OTHER_INFO
  1517. //
  1518. //  pvStructInfo points to following CRYPT_X942_OTHER_INFO data structure.
  1519. //
  1520. //  rgbCounter and rgbKeyLength are in Little Endian order.
  1521. //--------------------------------------------------------------------------
  1522. const
  1523.   CRYPT_X942_COUNTER_BYTE_LENGTH    = 4;
  1524.   {$EXTERNALSYM CRYPT_X942_COUNTER_BYTE_LENGTH}
  1525.   CRYPT_X942_KEY_LENGTH_BYTE_LENGTH = 4;
  1526.   {$EXTERNALSYM CRYPT_X942_KEY_LENGTH_BYTE_LENGTH}
  1527.   CRYPT_X942_PUB_INFO_BYTE_LENGTH   = (512 div 8);
  1528.   {$EXTERNALSYM CRYPT_X942_PUB_INFO_BYTE_LENGTH}
  1529. type
  1530.   PCRYPT_X942_OTHER_INFO = ^CRYPT_X942_OTHER_INFO;
  1531.   {$EXTERNALSYM PCRYPT_X942_OTHER_INFO}
  1532.   _CRYPT_X942_OTHER_INFO = record
  1533.     pszContentEncryptionObjId: LPSTR;
  1534.     rgbCounter: array [0..CRYPT_X942_COUNTER_BYTE_LENGTH - 1] of BYTE;
  1535.     rgbKeyLength: array [0..CRYPT_X942_KEY_LENGTH_BYTE_LENGTH - 1] of BYTE;
  1536.     PubInfo: CRYPT_DATA_BLOB; // OPTIONAL
  1537.   end;
  1538.   {$EXTERNALSYM _CRYPT_X942_OTHER_INFO}
  1539.   CRYPT_X942_OTHER_INFO = _CRYPT_X942_OTHER_INFO;
  1540.   {$EXTERNALSYM CRYPT_X942_OTHER_INFO}
  1541.   TCryptX942OtherInfo = CRYPT_X942_OTHER_INFO;
  1542.   PCryptX942OtherInfo = PCRYPT_X942_OTHER_INFO;
  1543. //+-------------------------------------------------------------------------
  1544. //  PKCS_RC2_CBC_PARAMETERS
  1545. //  szOID_RSA_RC2CBC
  1546. //
  1547. //  pvStructInfo points to following CRYPT_RC2_CBC_PARAMETERS data structure.
  1548. //--------------------------------------------------------------------------
  1549.   PCRYPT_RC2_CBC_PARAMETERS = ^CRYPT_RC2_CBC_PARAMETERS;
  1550.   {$EXTERNALSYM PCRYPT_RC2_CBC_PARAMETERS}
  1551.   _CRYPT_RC2_CBC_PARAMETERS = record
  1552.     dwVersion: DWORD;
  1553.     fIV: BOOL; // set if has following IV
  1554.     rgbIV: array [0..7] of BYTE;
  1555.   end;
  1556.   {$EXTERNALSYM _CRYPT_RC2_CBC_PARAMETERS}
  1557.   CRYPT_RC2_CBC_PARAMETERS = _CRYPT_RC2_CBC_PARAMETERS;
  1558.   {$EXTERNALSYM CRYPT_RC2_CBC_PARAMETERS}
  1559.   TCryptRc2CbcParameters = CRYPT_RC2_CBC_PARAMETERS;
  1560.   PCryptRc2CbcParameters = PCRYPT_RC2_CBC_PARAMETERS;
  1561. const
  1562.   CRYPT_RC2_40BIT_VERSION  = 160;
  1563.   {$EXTERNALSYM CRYPT_RC2_40BIT_VERSION}
  1564.   CRYPT_RC2_56BIT_VERSION  = 52;
  1565.   {$EXTERNALSYM CRYPT_RC2_56BIT_VERSION}
  1566.   CRYPT_RC2_64BIT_VERSION  = 120;
  1567.   {$EXTERNALSYM CRYPT_RC2_64BIT_VERSION}
  1568.   CRYPT_RC2_128BIT_VERSION = 58;
  1569.   {$EXTERNALSYM CRYPT_RC2_128BIT_VERSION}
  1570. //+-------------------------------------------------------------------------
  1571. //  PKCS_SMIME_CAPABILITIES
  1572. //  szOID_RSA_SMIMECapabilities
  1573. //
  1574. //  pvStructInfo points to following CRYPT_SMIME_CAPABILITIES data structure.
  1575. //
  1576. //  Note, for CryptEncodeObject(X509_ASN_ENCODING), Parameters.cbData == 0
  1577. //  causes the encoded parameters to be omitted and not encoded as a NULL
  1578. //  (05 00) as is done when encoding a CRYPT_ALGORITHM_IDENTIFIER. This
  1579. //  is per the SMIME specification for encoding capabilities.
  1580. //--------------------------------------------------------------------------
  1581. type
  1582.   PCRYPT_SMIME_CAPABILITY = ^CRYPT_SMIME_CAPABILITY;
  1583.   {$EXTERNALSYM PCRYPT_SMIME_CAPABILITY}
  1584.   _CRYPT_SMIME_CAPABILITY = record
  1585.     pszObjId: LPSTR;
  1586.     Parameters: CRYPT_OBJID_BLOB;
  1587.   end;
  1588.   {$EXTERNALSYM _CRYPT_SMIME_CAPABILITY}
  1589.   CRYPT_SMIME_CAPABILITY = _CRYPT_SMIME_CAPABILITY;
  1590.   {$EXTERNALSYM CRYPT_SMIME_CAPABILITY}
  1591.   TCryptSmimeCapability = CRYPT_SMIME_CAPABILITY;
  1592.   PCryptSmimeCapability = PCRYPT_SMIME_CAPABILITY;
  1593.   PCRYPT_SMIME_CAPABILITIES = ^CRYPT_SMIME_CAPABILITIES;
  1594.   {$EXTERNALSYM PCRYPT_SMIME_CAPABILITIES}
  1595.   _CRYPT_SMIME_CAPABILITIES = record
  1596.     cCapability: DWORD;
  1597.     rgCapability: PCRYPT_SMIME_CAPABILITY;
  1598.   end;
  1599.   {$EXTERNALSYM _CRYPT_SMIME_CAPABILITIES}
  1600.   CRYPT_SMIME_CAPABILITIES = _CRYPT_SMIME_CAPABILITIES;
  1601.   {$EXTERNALSYM CRYPT_SMIME_CAPABILITIES}
  1602.   TCryptSmimeCapabilities = CRYPT_SMIME_CAPABILITIES;
  1603.   PCryptSmimeCapabilities = PCRYPT_SMIME_CAPABILITIES;
  1604. //+-------------------------------------------------------------------------
  1605. //  PKCS7_SIGNER_INFO
  1606. //
  1607. //  pvStructInfo points to CMSG_SIGNER_INFO.
  1608. //--------------------------------------------------------------------------
  1609. //+-------------------------------------------------------------------------
  1610. //  CMS_SIGNER_INFO
  1611. //
  1612. //  pvStructInfo points to CMSG_CMS_SIGNER_INFO.
  1613. //--------------------------------------------------------------------------
  1614. //+-------------------------------------------------------------------------
  1615. //  Netscape Certificate Extension Object Identifiers
  1616. //--------------------------------------------------------------------------
  1617. const
  1618.   szOID_NETSCAPE                   = '2.16.840.1.113730';
  1619.   {$EXTERNALSYM szOID_NETSCAPE}
  1620.   szOID_NETSCAPE_CERT_EXTENSION    = '2.16.840.1.113730.1';
  1621.   {$EXTERNALSYM szOID_NETSCAPE_CERT_EXTENSION}
  1622.   szOID_NETSCAPE_CERT_TYPE         = '2.16.840.1.113730.1.1';
  1623.   {$EXTERNALSYM szOID_NETSCAPE_CERT_TYPE}
  1624.   szOID_NETSCAPE_BASE_URL          = '2.16.840.1.113730.1.2';
  1625.   {$EXTERNALSYM szOID_NETSCAPE_BASE_URL}
  1626.   szOID_NETSCAPE_REVOCATION_URL    = '2.16.840.1.113730.1.3';
  1627.   {$EXTERNALSYM szOID_NETSCAPE_REVOCATION_URL}
  1628.   szOID_NETSCAPE_CA_REVOCATION_URL = '2.16.840.1.113730.1.4';
  1629.   {$EXTERNALSYM szOID_NETSCAPE_CA_REVOCATION_URL}
  1630.   szOID_NETSCAPE_CERT_RENEWAL_URL  = '2.16.840.1.113730.1.7';
  1631.   {$EXTERNALSYM szOID_NETSCAPE_CERT_RENEWAL_URL}
  1632.   szOID_NETSCAPE_CA_POLICY_URL     = '2.16.840.1.113730.1.8';
  1633.   {$EXTERNALSYM szOID_NETSCAPE_CA_POLICY_URL}
  1634.   szOID_NETSCAPE_SSL_SERVER_NAME   = '2.16.840.1.113730.1.12';
  1635.   {$EXTERNALSYM szOID_NETSCAPE_SSL_SERVER_NAME}
  1636.   szOID_NETSCAPE_COMMENT           = '2.16.840.1.113730.1.13';
  1637.   {$EXTERNALSYM szOID_NETSCAPE_COMMENT}
  1638. //+-------------------------------------------------------------------------
  1639. //  Netscape Certificate Data Type Object Identifiers
  1640. //--------------------------------------------------------------------------
  1641.   szOID_NETSCAPE_DATA_TYPE     = '2.16.840.1.113730.2';
  1642.   {$EXTERNALSYM szOID_NETSCAPE_DATA_TYPE}
  1643.   szOID_NETSCAPE_CERT_SEQUENCE = '2.16.840.1.113730.2.5';
  1644.   {$EXTERNALSYM szOID_NETSCAPE_CERT_SEQUENCE}
  1645. //+-------------------------------------------------------------------------
  1646. //  szOID_NETSCAPE_CERT_TYPE extension
  1647. //
  1648. //  Its value is a bit string. CryptDecodeObject/CryptEncodeObject using
  1649. //  X509_BITS or X509_BITS_WITHOUT_TRAILING_ZEROES.
  1650. //
  1651. //  The following bits are defined:
  1652. //--------------------------------------------------------------------------
  1653.   NETSCAPE_SSL_CLIENT_AUTH_CERT_TYPE = $80;
  1654.   {$EXTERNALSYM NETSCAPE_SSL_CLIENT_AUTH_CERT_TYPE}
  1655.   NETSCAPE_SSL_SERVER_AUTH_CERT_TYPE = $40;
  1656.   {$EXTERNALSYM NETSCAPE_SSL_SERVER_AUTH_CERT_TYPE}
  1657.   NETSCAPE_SMIME_CERT_TYPE           = $20;
  1658.   {$EXTERNALSYM NETSCAPE_SMIME_CERT_TYPE}
  1659.   NETSCAPE_SIGN_CERT_TYPE            = $10;
  1660.   {$EXTERNALSYM NETSCAPE_SIGN_CERT_TYPE}
  1661.   NETSCAPE_SSL_CA_CERT_TYPE          = $04;
  1662.   {$EXTERNALSYM NETSCAPE_SSL_CA_CERT_TYPE}
  1663.   NETSCAPE_SMIME_CA_CERT_TYPE        = $02;
  1664.   {$EXTERNALSYM NETSCAPE_SMIME_CA_CERT_TYPE}
  1665.   NETSCAPE_SIGN_CA_CERT_TYPE         = $01;
  1666.   {$EXTERNALSYM NETSCAPE_SIGN_CA_CERT_TYPE}
  1667. //+-------------------------------------------------------------------------
  1668. //  szOID_NETSCAPE_BASE_URL extension
  1669. //
  1670. //  Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  1671. //  X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  1672. //  dwValueType = CERT_RDN_IA5_STRING.
  1673. //
  1674. //  When present this string is added to the beginning of all relative URLs
  1675. //  in the certificate.  This extension can be considered an optimization
  1676. //  to reduce the size of the URL extensions.
  1677. //--------------------------------------------------------------------------
  1678. //+-------------------------------------------------------------------------
  1679. //  szOID_NETSCAPE_REVOCATION_URL extension
  1680. //
  1681. //  Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  1682. //  X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  1683. //  dwValueType = CERT_RDN_IA5_STRING.
  1684. //
  1685. //  It is a relative or absolute URL that can be used to check the
  1686. //  revocation status of a certificate. The revocation check will be
  1687. //  performed as an HTTP GET method using a url that is the concatenation of
  1688. //  revocation-url and certificate-serial-number.
  1689. //  Where the certificate-serial-number is encoded as a string of
  1690. //  ascii hexadecimal digits. For example, if the netscape-base-url is
  1691. //  https://www.certs-r-us.com/, the netscape-revocation-url is
  1692. //  cgi-bin/check-rev.cgi?, and the certificate serial number is 173420,
  1693. //  the resulting URL would be:
  1694. //  https://www.certs-r-us.com/cgi-bin/check-rev.cgi?02a56c
  1695. //
  1696. //  The server should return a document with a Content-Type of
  1697. //  application/x-netscape-revocation.  The document should contain
  1698. //  a single ascii digit, '1' if the certificate is not curently valid,
  1699. //  and '0' if it is curently valid.
  1700. //
  1701. //  Note: for all of the URLs that include the certificate serial number,
  1702. //  the serial number will be encoded as a string which consists of an even
  1703. //  number of hexadecimal digits.  If the number of significant digits is odd,
  1704. //  the string will have a single leading zero to ensure an even number of
  1705. //  digits is generated.
  1706. //--------------------------------------------------------------------------
  1707. //+-------------------------------------------------------------------------
  1708. //  szOID_NETSCAPE_CA_REVOCATION_URL extension
  1709. //
  1710. //  Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  1711. //  X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  1712. //  dwValueType = CERT_RDN_IA5_STRING.
  1713. //
  1714. //  It is a relative or absolute URL that can be used to check the
  1715. //  revocation status of any certificates that are signed by the CA that
  1716. //  this certificate belongs to. This extension is only valid in CA
  1717. //  certificates.  The use of this extension is the same as the above
  1718. //  szOID_NETSCAPE_REVOCATION_URL extension.
  1719. //--------------------------------------------------------------------------
  1720. //+-------------------------------------------------------------------------
  1721. //  szOID_NETSCAPE_CERT_RENEWAL_URL extension
  1722. //
  1723. //  Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  1724. //  X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  1725. //  dwValueType = CERT_RDN_IA5_STRING.
  1726. //
  1727. //  It is a relative or absolute URL that points to a certificate renewal
  1728. //  form. The renewal form will be accessed with an HTTP GET method using a
  1729. //  url that is the concatenation of renewal-url and
  1730. //  certificate-serial-number. Where the certificate-serial-number is
  1731. //  encoded as a string of ascii hexadecimal digits. For example, if the
  1732. //  netscape-base-url is https://www.certs-r-us.com/, the
  1733. //  netscape-cert-renewal-url is cgi-bin/check-renew.cgi?, and the
  1734. //  certificate serial number is 173420, the resulting URL would be:
  1735. //  https://www.certs-r-us.com/cgi-bin/check-renew.cgi?02a56c
  1736. //  The document returned should be an HTML form that will allow the user
  1737. //  to request a renewal of their certificate.
  1738. //--------------------------------------------------------------------------
  1739. //+-------------------------------------------------------------------------
  1740. //  szOID_NETSCAPE_CA_POLICY_URL extension
  1741. //
  1742. //  Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  1743. //  X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  1744. //  dwValueType = CERT_RDN_IA5_STRING.
  1745. //
  1746. //  It is a relative or absolute URL that points to a web page that
  1747. //  describes the policies under which the certificate was issued.
  1748. //--------------------------------------------------------------------------
  1749. //+-------------------------------------------------------------------------
  1750. //  szOID_NETSCAPE_SSL_SERVER_NAME extension
  1751. //
  1752. //  Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  1753. //  X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  1754. //  dwValueType = CERT_RDN_IA5_STRING.
  1755. //
  1756. //  It is a "shell expression" that can be used to match the hostname of the
  1757. //  SSL server that is using this certificate.  It is recommended that if
  1758. //  the server's hostname does not match this pattern the user be notified
  1759. //  and given the option to terminate the SSL connection.  If this extension
  1760. //  is not present then the CommonName in the certificate subject's
  1761. //  distinguished name is used for the same purpose.
  1762. //--------------------------------------------------------------------------
  1763. //+-------------------------------------------------------------------------
  1764. //  szOID_NETSCAPE_COMMENT extension
  1765. //
  1766. //  Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  1767. //  X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  1768. //  dwValueType = CERT_RDN_IA5_STRING.
  1769. //
  1770. //  It is a comment that may be displayed to the user when the certificate
  1771. //  is viewed.
  1772. //--------------------------------------------------------------------------
  1773. //+-------------------------------------------------------------------------
  1774. //  szOID_NETSCAPE_CERT_SEQUENCE
  1775. //
  1776. //  Its value is a PKCS#7 ContentInfo structure wrapping a sequence of
  1777. //  certificates. The value of the contentType field is
  1778. //  szOID_NETSCAPE_CERT_SEQUENCE, while the content field is the following
  1779. //  structure:
  1780. //      CertificateSequence ::= SEQUENCE OF Certificate.
  1781. //
  1782. //  CryptDecodeObject/CryptEncodeObject using
  1783. //  PKCS_CONTENT_INFO_SEQUENCE_OF_ANY, where,
  1784. //  pszObjId = szOID_NETSCAPE_CERT_SEQUENCE and the CRYPT_DER_BLOBs point
  1785. //  to encoded X509 certificates.
  1786. //--------------------------------------------------------------------------
  1787. //+=========================================================================
  1788. //  Object IDentifier (OID) Installable Functions:  Data Structures and APIs
  1789. //==========================================================================
  1790. type
  1791.   HCRYPTOIDFUNCSET = Pointer;
  1792.   {$EXTERNALSYM HCRYPTOIDFUNCSET}
  1793.   HCRYPTOIDFUNCADDR = Pointer;
  1794.   {$EXTERNALSYM HCRYPTOIDFUNCADDR}
  1795. // Predefined OID Function Names
  1796. const
  1797.   CRYPT_OID_ENCODE_OBJECT_FUNC       = 'CryptDllEncodeObject';
  1798.   {$EXTERNALSYM CRYPT_OID_ENCODE_OBJECT_FUNC}
  1799.   CRYPT_OID_DECODE_OBJECT_FUNC       = 'CryptDllDecodeObject';
  1800.   {$EXTERNALSYM CRYPT_OID_DECODE_OBJECT_FUNC}
  1801.   CRYPT_OID_ENCODE_OBJECT_EX_FUNC    = 'CryptDllEncodeObjectEx';
  1802.   {$EXTERNALSYM CRYPT_OID_ENCODE_OBJECT_EX_FUNC}
  1803.   CRYPT_OID_DECODE_OBJECT_EX_FUNC    = 'CryptDllDecodeObjectEx';
  1804.   {$EXTERNALSYM CRYPT_OID_DECODE_OBJECT_EX_FUNC}
  1805.   CRYPT_OID_CREATE_COM_OBJECT_FUNC   = 'CryptDllCreateCOMObject';
  1806.   {$EXTERNALSYM CRYPT_OID_CREATE_COM_OBJECT_FUNC}
  1807.   CRYPT_OID_VERIFY_REVOCATION_FUNC   = 'CertDllVerifyRevocation';
  1808.   {$EXTERNALSYM CRYPT_OID_VERIFY_REVOCATION_FUNC}
  1809.   CRYPT_OID_VERIFY_CTL_USAGE_FUNC    = 'CertDllVerifyCTLUsage';
  1810.   {$EXTERNALSYM CRYPT_OID_VERIFY_CTL_USAGE_FUNC}
  1811.   CRYPT_OID_FORMAT_OBJECT_FUNC       = 'CryptDllFormatObject';
  1812.   {$EXTERNALSYM CRYPT_OID_FORMAT_OBJECT_FUNC}
  1813.   CRYPT_OID_FIND_OID_INFO_FUNC       = 'CryptDllFindOIDInfo';
  1814.   {$EXTERNALSYM CRYPT_OID_FIND_OID_INFO_FUNC}
  1815.   CRYPT_OID_FIND_LOCALIZED_NAME_FUNC = 'CryptDllFindLocalizedName';
  1816.   {$EXTERNALSYM CRYPT_OID_FIND_LOCALIZED_NAME_FUNC}
  1817. // CryptDllEncodeObject has same function signature as CryptEncodeObject.
  1818. // CryptDllDecodeObject has same function signature as CryptDecodeObject.
  1819. // CryptDllEncodeObjectEx has same function signature as CryptEncodeObjectEx.
  1820. // The Ex version MUST support the CRYPT_ENCODE_ALLOC_FLAG option.
  1821. //
  1822. // If an Ex function isn't installed or registered, then, attempts to find
  1823. // a non-EX version. If the ALLOC flag is set, then, CryptEncodeObjectEx,
  1824. // does the allocation and calls the non-EX version twice.
  1825. // CryptDllDecodeObjectEx has same function signature as CryptDecodeObjectEx.
  1826. // The Ex version MUST support the CRYPT_DECODE_ALLOC_FLAG option.
  1827. //
  1828. // If an Ex function isn't installed or registered, then, attempts to find
  1829. // a non-EX version. If the ALLOC flag is set, then, CryptDecodeObjectEx,
  1830. // does the allocation and calls the non-EX version twice.
  1831. // CryptDllCreateCOMObject has the following signature:
  1832. //      BOOL WINAPI CryptDllCreateCOMObject(
  1833. //          IN DWORD dwEncodingType,
  1834. //          IN LPCSTR pszOID,
  1835. //          IN PCRYPT_DATA_BLOB pEncodedContent,
  1836. //          IN DWORD dwFlags,
  1837. //          IN REFIID riid,
  1838. //          OUT void **ppvObj);
  1839. // CertDllVerifyRevocation has the same signature as CertVerifyRevocation
  1840. //  (See CertVerifyRevocation for details on when called)
  1841. // CertDllVerifyCTLUsage has the same signature as CertVerifyCTLUsage
  1842. // CryptDllFindOIDInfo currently is only used to store values used by
  1843. // CryptFindOIDInfo. See CryptFindOIDInfo() for more details.
  1844. // CryptDllFindLocalizedName is only used to store localized string
  1845. // values used by CryptFindLocalizedName. See CryptFindLocalizedName() for
  1846. // more details.
  1847. //  Example of a complete OID Function Registry Name:
  1848. //    HKEY_LOCAL_MACHINESoftwareMicrosoftCryptographyOID
  1849. //      Encoding Type 1CryptDllEncodeObject1.2.3
  1850. //
  1851. //  The key's L"Dll" value contains the name of the Dll.
  1852. //  The key's L"FuncName" value overrides the default function name
  1853.   CRYPT_OID_REGPATH                    = 'SoftwareMicrosoftCryptographyOID';
  1854.   {$EXTERNALSYM CRYPT_OID_REGPATH}
  1855.   CRYPT_OID_REG_ENCODING_TYPE_PREFIX   = 'EncodingType ';
  1856.   {$EXTERNALSYM CRYPT_OID_REG_ENCODING_TYPE_PREFIX}
  1857.   CRYPT_OID_REG_DLL_VALUE_NAME         = 'Dll';
  1858.   {$EXTERNALSYM CRYPT_OID_REG_DLL_VALUE_NAME}
  1859.   CRYPT_OID_REG_FUNC_NAME_VALUE_NAME   = 'FuncName';
  1860.   {$EXTERNALSYM CRYPT_OID_REG_FUNC_NAME_VALUE_NAME}
  1861.   CRYPT_OID_REG_FUNC_NAME_VALUE_NAME_A = 'FuncName';
  1862.   {$EXTERNALSYM CRYPT_OID_REG_FUNC_NAME_VALUE_NAME_A}
  1863. // CRYPT_INSTALL_OID_FUNC_BEFORE_FLAG can be set in the key's L"CryptFlags"
  1864. // value to register the functions before the installed functions.
  1865. //
  1866. // CryptSetOIDFunctionValue must be called to set this value. L"CryptFlags"
  1867. // must be set using a dwValueType of REG_DWORD.
  1868.   CRYPT_OID_REG_FLAGS_VALUE_NAME = 'CryptFlags';
  1869.   {$EXTERNALSYM CRYPT_OID_REG_FLAGS_VALUE_NAME}
  1870. // OID used for Default OID functions
  1871.   CRYPT_DEFAULT_OID = 'DEFAULT';
  1872.   {$EXTERNALSYM CRYPT_DEFAULT_OID}
  1873. type
  1874.   PCRYPT_OID_FUNC_ENTRY = ^CRYPT_OID_FUNC_ENTRY;
  1875.   {$EXTERNALSYM PCRYPT_OID_FUNC_ENTRY}
  1876.   _CRYPT_OID_FUNC_ENTRY = record
  1877.     pszOID: LPCSTR;
  1878.     pvFuncAddr: Pointer;
  1879.   end;
  1880.   {$EXTERNALSYM _CRYPT_OID_FUNC_ENTRY}
  1881.   CRYPT_OID_FUNC_ENTRY = _CRYPT_OID_FUNC_ENTRY;
  1882.   {$EXTERNALSYM CRYPT_OID_FUNC_ENTRY}
  1883.   TCryptOidFuncEntry = CRYPT_OID_FUNC_ENTRY;
  1884.   PCryptOidFuncEntry = PCRYPT_OID_FUNC_ENTRY;
  1885. const
  1886.   CRYPT_INSTALL_OID_FUNC_BEFORE_FLAG = 1;
  1887.   {$EXTERNALSYM CRYPT_INSTALL_OID_FUNC_BEFORE_FLAG}
  1888. //+-------------------------------------------------------------------------
  1889. //  Install a set of callable OID function addresses.
  1890. //
  1891. //  By default the functions are installed at end of the list.
  1892. //  Set CRYPT_INSTALL_OID_FUNC_BEFORE_FLAG to install at beginning of list.
  1893. //
  1894. //  hModule should be updated with the hModule passed to DllMain to prevent
  1895. //  the Dll containing the function addresses from being unloaded by
  1896. //  CryptGetOIDFuncAddress/CryptFreeOIDFunctionAddress. This would be the
  1897. //  case when the Dll has also regsvr32'ed OID functions via
  1898. //  CryptRegisterOIDFunction.
  1899. //
  1900. //  DEFAULT functions are installed by setting rgFuncEntry[].pszOID =
  1901. //  CRYPT_DEFAULT_OID.
  1902. //--------------------------------------------------------------------------
  1903. function CryptInstallOIDFunctionAddress(hModule: HMODULE; dwEncodingType: DWORD;
  1904.   pszFuncName: LPCSTR; cFuncEntry: DWORD; rgFuncEntry: PCRYPT_OID_FUNC_ENTRY;
  1905.   dwFlags: DWORD): BOOL; stdcall;
  1906. {$EXTERNALSYM CryptInstallOIDFunctionAddress}
  1907. //+-------------------------------------------------------------------------
  1908. //  Initialize and return handle to the OID function set identified by its
  1909. //  function name.
  1910. //
  1911. //  If the set already exists, a handle to the existing set is returned.
  1912. //--------------------------------------------------------------------------
  1913. function CryptInitOIDFunctionSet(pszFuncName: LPCSTR; dwFlags: DWORD): HCRYPTOIDFUNCSET; stdcall;
  1914. {$EXTERNALSYM CryptInitOIDFunctionSet}
  1915. //+-------------------------------------------------------------------------
  1916. //  Search the list of installed functions for an encoding type and OID match.
  1917. //  If not found, search the registry.
  1918. //
  1919. //  For success, returns TRUE with *ppvFuncAddr updated with the function's
  1920. //  address and *phFuncAddr updated with the function address's handle.
  1921. //  The function's handle is AddRef'ed. CryptFreeOIDFunctionAddress needs to
  1922. //  be called to release it.
  1923. //
  1924. //  For a registry match, the Dll containing the function is loaded.
  1925. //
  1926. //  By default, both the registered and installed function lists are searched.
  1927. //  Set CRYPT_GET_INSTALLED_OID_FUNC_FLAG to only search the installed list
  1928. //  of functions. This flag would be set by a registered function to get
  1929. //  the address of a pre-installed function it was replacing. For example,
  1930. //  the registered function might handle a new special case and call the
  1931. //  pre-installed function to handle the remaining cases.
  1932. //--------------------------------------------------------------------------
  1933. function CryptGetOIDFunctionAddress(hFuncSet: HCRYPTOIDFUNCSET;
  1934.   dwEncodingType: DWORD; pszOID: LPCSTR; dwFlags: DWORD;
  1935.   var ppvFuncAddr: Pointer; var phFuncAddr: HCRYPTOIDFUNCADDR): BOOL; stdcall;
  1936. {$EXTERNALSYM CryptGetOIDFunctionAddress}
  1937. const
  1938.   CRYPT_GET_INSTALLED_OID_FUNC_FLAG = $1;
  1939.   {$EXTERNALSYM CRYPT_GET_INSTALLED_OID_FUNC_FLAG}
  1940. //+-------------------------------------------------------------------------
  1941. //  Get the list of registered default Dll entries for the specified
  1942. //  function set and encoding type.
  1943. //
  1944. //  The returned list consists of none, one or more null terminated Dll file
  1945. //  names. The list is terminated with an empty (L"") Dll file name.
  1946. //  For example: L"first.dll" L"" L"second.dll" L"" L""
  1947. //--------------------------------------------------------------------------
  1948. function CryptGetDefaultOIDDllList(hFuncSet: HCRYPTOIDFUNCSET; dwEncodingType: DWORD;
  1949.   pwszDllList: LPWSTR; pcchDllList: DWORD): BOOL; stdcall;
  1950. {$EXTERNALSYM CryptGetDefaultOIDDllList}
  1951. //+-------------------------------------------------------------------------
  1952. //  Either: get the first or next installed DEFAULT function OR
  1953. //  load the Dll containing the DEFAULT function.
  1954. //
  1955. //  If pwszDll is NULL, search the list of installed DEFAULT functions.
  1956. //  *phFuncAddr must be set to NULL to get the first installed function.
  1957. //  Successive installed functions are returned by setting *phFuncAddr
  1958. //  to the hFuncAddr returned by the previous call.
  1959. //
  1960. //  If pwszDll is NULL, the input *phFuncAddr
  1961. //  is always CryptFreeOIDFunctionAddress'ed by this function, even for
  1962. //  an error.
  1963. //
  1964. //  If pwszDll isn't NULL, then, attempts to load the Dll and the DEFAULT
  1965. //  function. *phFuncAddr is ignored upon entry and isn't
  1966. //  CryptFreeOIDFunctionAddress'ed.
  1967. //
  1968. //  For success, returns TRUE with *ppvFuncAddr updated with the function's
  1969. //  address and *phFuncAddr updated with the function address's handle.
  1970. //  The function's handle is AddRef'ed. CryptFreeOIDFunctionAddress needs to
  1971. //  be called to release it or CryptGetDefaultOIDFunctionAddress can also
  1972. //  be called for a NULL pwszDll.
  1973. //--------------------------------------------------------------------------
  1974. function CryptGetDefaultOIDFunctionAddress(hFuncSet: HCRYPTOIDFUNCSET;
  1975.   dwEncodingType: DWORD; pwszDll: LPCWSTR; dwFlags: DWORD;
  1976.   var ppvFuncAddr: Pointer; phFuncAddr: HCRYPTOIDFUNCADDR): BOOL; stdcall;
  1977. {$EXTERNALSYM CryptGetDefaultOIDFunctionAddress}
  1978. //+-------------------------------------------------------------------------
  1979. //  Releases the handle AddRef'ed and returned by CryptGetOIDFunctionAddress
  1980. //  or CryptGetDefaultOIDFunctionAddress.
  1981. //
  1982. //  If a Dll was loaded for the function its unloaded. However, before doing
  1983. //  the unload, the DllCanUnloadNow function exported by the loaded Dll is
  1984. //  called. It should return S_FALSE to inhibit the unload or S_TRUE to enable
  1985. //  the unload. If the Dll doesn't export DllCanUnloadNow, the Dll is unloaded.
  1986. //
  1987. //  DllCanUnloadNow has the following signature:
  1988. //      STDAPI  DllCanUnloadNow(void);
  1989. //--------------------------------------------------------------------------
  1990. function CryptFreeOIDFunctionAddress(hFuncAddr: HCRYPTOIDFUNCADDR; dwFlags: DWORD): BOOL; stdcall;
  1991. {$EXTERNALSYM CryptFreeOIDFunctionAddress}
  1992. //+-------------------------------------------------------------------------
  1993. //  Register the Dll containing the function to be called for the specified
  1994. //  encoding type, function name and OID.
  1995. //
  1996. //  pwszDll may contain environment-variable strings
  1997. //  which are ExpandEnvironmentStrings()'ed before loading the Dll.
  1998. //
  1999. //  In addition to registering the DLL, you may override the
  2000. //  name of the function to be called. For example,
  2001. //      pszFuncName = "CryptDllEncodeObject",
  2002. //      pszOverrideFuncName = "MyEncodeXyz".
  2003. //  This allows a Dll to export multiple OID functions for the same
  2004. //  function name without needing to interpose its own OID dispatcher function.
  2005. //--------------------------------------------------------------------------
  2006. function CryptRegisterOIDFunction(dwEncodingType: DWORD; pszFuncName: LPCSTR;
  2007.   pszOID: LPCSTR; pwszDll: LPCWSTR; pszOverrideFuncName: LPCSTR): BOOL; stdcall;
  2008. {$EXTERNALSYM CryptRegisterOIDFunction}
  2009. //+-------------------------------------------------------------------------
  2010. //  Unregister the Dll containing the function to be called for the specified
  2011. //  encoding type, function name and OID.
  2012. //--------------------------------------------------------------------------
  2013. function CryptUnregisterOIDFunction(dwEncodingType: DWORD; pszFuncName: LPCSTR;
  2014.   pszOID: LPCSTR): BOOL; stdcall;
  2015. {$EXTERNALSYM CryptUnregisterOIDFunction}
  2016. //+-------------------------------------------------------------------------
  2017. //  Register the Dll containing the default function to be called for the
  2018. //  specified encoding type and function name.
  2019. //
  2020. //  Unlike CryptRegisterOIDFunction, you can't override the function name
  2021. //  needing to be exported by the Dll.
  2022. //
  2023. //  The Dll is inserted before the entry specified by dwIndex.
  2024. //    dwIndex == 0, inserts at the beginning.
  2025. //    dwIndex == CRYPT_REGISTER_LAST_INDEX, appends at the end.
  2026. //
  2027. //  pwszDll may contain environment-variable strings
  2028. //  which are ExpandEnvironmentStrings()'ed before loading the Dll.
  2029. //--------------------------------------------------------------------------
  2030. function CryptRegisterDefaultOIDFunction(dwEncodingType: DWORD; pszFuncName: LPCSTR;
  2031.   dwIndex: DWORD; pwszDll: LPCWSTR): BOOL; stdcall;
  2032. {$EXTERNALSYM CryptRegisterDefaultOIDFunction}
  2033. const
  2034.   CRYPT_REGISTER_FIRST_INDEX = 0;
  2035.   {$EXTERNALSYM CRYPT_REGISTER_FIRST_INDEX}
  2036.   CRYPT_REGISTER_LAST_INDEX  = DWORD($FFFFFFFF);
  2037.   {$EXTERNALSYM CRYPT_REGISTER_LAST_INDEX}
  2038. //+-------------------------------------------------------------------------
  2039. //  Unregister the Dll containing the default function to be called for
  2040. //  the specified encoding type and function name.
  2041. //--------------------------------------------------------------------------
  2042. function CryptUnregisterDefaultOIDFunction(dwEncodingType: DWORD;
  2043.   pszFuncName: LPCSTR; pwszDll: LPCWSTR): BOOL; stdcall;
  2044. {$EXTERNALSYM CryptUnregisterDefaultOIDFunction}
  2045. //+-------------------------------------------------------------------------
  2046. //  Set the value for the specified encoding type, function name, OID and
  2047. //  value name.
  2048. //
  2049. //  See RegSetValueEx for the possible value types.
  2050. //
  2051. //  String types are UNICODE.
  2052. //--------------------------------------------------------------------------
  2053. function CryptSetOIDFunctionValue(dwEncodingType: DWORD; pszFuncName: LPCSTR;
  2054.   pszOID: LPCSTR; pwszValueName: LPCWSTR; dwValueType: DWORD; pbValueData: LPBYTE;
  2055.   cbValueData: DWORD): BOOL; stdcall;
  2056. {$EXTERNALSYM CryptSetOIDFunctionValue}
  2057. //+-------------------------------------------------------------------------
  2058. //  Get the value for the specified encoding type, function name, OID and
  2059. //  value name.
  2060. //
  2061. //  See RegEnumValue for the possible value types.
  2062. //
  2063. //  String types are UNICODE.
  2064. //--------------------------------------------------------------------------
  2065. function CryptGetOIDFunctionValue(dwEncodingType: DWORD; pszFuncName: LPCSTR;
  2066.   pszOID: LPCSTR; pwszValueName: LPCWSTR; var pdwValueType: DWORD;
  2067.   pbValueData: LPBYTE; var pcbValueData: DWORD): BOOL; stdcall;
  2068. {$EXTERNALSYM CryptGetOIDFunctionValue}
  2069. type
  2070.   PFN_CRYPT_ENUM_OID_FUNC = function (dwEncodingType: DWORD; pszFuncName,
  2071.     pszOID: LPCSTR; cValue: DWORD; rgdwValueType: LPDWORD;
  2072.     rgpwszValueName: LPCWSTR; rgpbValueData: LPBYTE; rgcbValueData: LPDWORD;
  2073.     pvArg: Pointer): BOOL; stdcall;
  2074.   {$EXTERNALSYM PFN_CRYPT_ENUM_OID_FUNC}
  2075.   PFnCryptEnumOidFunc = PFN_CRYPT_ENUM_OID_FUNC;
  2076. //+-------------------------------------------------------------------------
  2077. //  Enumerate the OID functions identified by their encoding type,
  2078. //  function name and OID.
  2079. //
  2080. //  pfnEnumOIDFunc is called for each registry key matching the input
  2081. //  parameters. Setting dwEncodingType to CRYPT_MATCH_ANY_ENCODING_TYPE matches
  2082. //  any. Setting pszFuncName or pszOID to NULL matches any.
  2083. //
  2084. //  Set pszOID == CRYPT_DEFAULT_OID to restrict the enumeration to only the
  2085. //  DEFAULT functions
  2086. //
  2087. //  String types are UNICODE.
  2088. //--------------------------------------------------------------------------
  2089. function CryptEnumOIDFunction(dwEncodingType: DWORD; pszFuncName, pszOID: LPCSTR;
  2090.   dwFlags: DWORD; pvArg: Pointer; pfnEnumOIDFunc: PFN_CRYPT_ENUM_OID_FUNC): BOOL; stdcall;
  2091. {$EXTERNALSYM CryptEnumOIDFunction}
  2092. const
  2093.   CRYPT_MATCH_ANY_ENCODING_TYPE = DWORD($FFFFFFFF);
  2094.   {$EXTERNALSYM CRYPT_MATCH_ANY_ENCODING_TYPE}
  2095. //+=========================================================================
  2096. //  Object IDentifier (OID) Information:  Data Structures and APIs
  2097. //==========================================================================
  2098. //+-------------------------------------------------------------------------
  2099. //  OID Information
  2100. //--------------------------------------------------------------------------
  2101. type
  2102.   PCRYPT_OID_INFO = ^CRYPT_OID_INFO;
  2103.   {$EXTERNALSYM PCRYPT_OID_INFO}
  2104.   _CRYPT_OID_INFO = record
  2105.     cbSize: DWORD;
  2106.     pszOID: LPCSTR;
  2107.     pwszName: LPCWSTR;
  2108.     dwGroupId: DWORD;
  2109.     Union: record
  2110.     case Integer of
  2111.       0: (dwValue: DWORD);
  2112.       1: (Algid: ALG_ID);
  2113.       2: (dwLength: DWORD);
  2114.     end;
  2115.     ExtraInfo: CRYPT_DATA_BLOB;
  2116.   end;
  2117.   {$EXTERNALSYM _CRYPT_OID_INFO}
  2118.   CRYPT_OID_INFO = _CRYPT_OID_INFO;
  2119.   {$EXTERNALSYM CRYPT_OID_INFO}
  2120.   TCryptOidInfo = CRYPT_OID_INFO;
  2121.   PCryptOidInfo = PCRYPT_OID_INFO;
  2122.   CCRYPT_OID_INFO = CRYPT_OID_INFO;
  2123.   {$EXTERNALSYM CCRYPT_OID_INFO}
  2124.   PCCRYPT_OID_INFO = PCRYPT_OID_INFO;
  2125.   {$EXTERNALSYM PCCRYPT_OID_INFO}
  2126. //+-------------------------------------------------------------------------
  2127. //  OID Group IDs
  2128. //--------------------------------------------------------------------------
  2129. const
  2130.   CRYPT_HASH_ALG_OID_GROUP_ID     = 1;
  2131.   {$EXTERNALSYM CRYPT_HASH_ALG_OID_GROUP_ID}
  2132.   CRYPT_ENCRYPT_ALG_OID_GROUP_ID  = 2;
  2133.   {$EXTERNALSYM CRYPT_ENCRYPT_ALG_OID_GROUP_ID}
  2134.   CRYPT_PUBKEY_ALG_OID_GROUP_ID   = 3;
  2135.   {$EXTERNALSYM CRYPT_PUBKEY_ALG_OID_GROUP_ID}
  2136.   CRYPT_SIGN_ALG_OID_GROUP_ID     = 4;
  2137.   {$EXTERNALSYM CRYPT_SIGN_ALG_OID_GROUP_ID}
  2138.   CRYPT_RDN_ATTR_OID_GROUP_ID     = 5;
  2139.   {$EXTERNALSYM CRYPT_RDN_ATTR_OID_GROUP_ID}
  2140.   CRYPT_EXT_OR_ATTR_OID_GROUP_ID  = 6;
  2141.   {$EXTERNALSYM CRYPT_EXT_OR_ATTR_OID_GROUP_ID}
  2142.   CRYPT_ENHKEY_USAGE_OID_GROUP_ID = 7;
  2143.   {$EXTERNALSYM CRYPT_ENHKEY_USAGE_OID_GROUP_ID}
  2144.   CRYPT_POLICY_OID_GROUP_ID       = 8;
  2145.   {$EXTERNALSYM CRYPT_POLICY_OID_GROUP_ID}
  2146.   CRYPT_LAST_OID_GROUP_ID         = 8;
  2147.   {$EXTERNALSYM CRYPT_LAST_OID_GROUP_ID}
  2148.   CRYPT_FIRST_ALG_OID_GROUP_ID = CRYPT_HASH_ALG_OID_GROUP_ID;
  2149.   {$EXTERNALSYM CRYPT_FIRST_ALG_OID_GROUP_ID}
  2150.   CRYPT_LAST_ALG_OID_GROUP_ID  = CRYPT_SIGN_ALG_OID_GROUP_ID;
  2151.   {$EXTERNALSYM CRYPT_LAST_ALG_OID_GROUP_ID}
  2152. // The CRYPT_*_ALG_OID_GROUP_ID's have an Algid. The CRYPT_RDN_ATTR_OID_GROUP_ID
  2153. // has a dwLength. The CRYPT_EXT_OR_ATTR_OID_GROUP_ID,
  2154. // CRYPT_ENHKEY_USAGE_OID_GROUP_ID or CRYPT_POLICY_OID_GROUP_ID don't have a
  2155. // dwValue.
  2156. //
  2157. // CRYPT_PUBKEY_ALG_OID_GROUP_ID has the following optional ExtraInfo:
  2158. //  DWORD[0] - Flags. CRYPT_OID_INHIBIT_SIGNATURE_FORMAT_FLAG can be set to
  2159. //             inhibit the reformatting of the signature before
  2160. //             CryptVerifySignature is called or after CryptSignHash
  2161. //             is called. CRYPT_OID_USE_PUBKEY_PARA_FOR_PKCS7_FLAG can
  2162. //             be set to include the public key algorithm's parameters
  2163. //             in the PKCS7's digestEncryptionAlgorithm's parameters.
  2164. //             CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG can be set to omit
  2165. //             NULL parameters when encoding.
  2166.   CRYPT_OID_INHIBIT_SIGNATURE_FORMAT_FLAG  = $1;
  2167.   {$EXTERNALSYM CRYPT_OID_INHIBIT_SIGNATURE_FORMAT_FLAG}
  2168.   CRYPT_OID_USE_PUBKEY_PARA_FOR_PKCS7_FLAG = $2;
  2169.   {$EXTERNALSYM CRYPT_OID_USE_PUBKEY_PARA_FOR_PKCS7_FLAG}
  2170.   CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG    = $4;
  2171.   {$EXTERNALSYM CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG}
  2172. // CRYPT_SIGN_ALG_OID_GROUP_ID has the following optional ExtraInfo:
  2173. //  DWORD[0] - Public Key Algid.
  2174. //  DWORD[1] - Flags. Same as above for CRYPT_PUBKEY_ALG_OID_GROUP_ID.
  2175. //  DWORD[2] - Optional CryptAcquireContext(CRYPT_VERIFYCONTEXT)'s dwProvType.
  2176. //             If omitted or 0, uses Public Key Algid to select
  2177. //             appropriate dwProvType for signature verification.
  2178. // CRYPT_RDN_ATTR_OID_GROUP_ID has the following optional ExtraInfo:
  2179. //  Array of DWORDs:
  2180. //   [0 ..] - Null terminated list of acceptable RDN attribute
  2181. //            value types. An empty list implies CERT_RDN_PRINTABLE_STRING,
  2182. //            CERT_RDN_UNICODE_STRING, 0.
  2183. //+-------------------------------------------------------------------------
  2184. //  Find OID information. Returns NULL if unable to find any information
  2185. //  for the specified key and group. Note, returns a pointer to a constant
  2186. //  data structure. The returned pointer MUST NOT be freed.
  2187. //
  2188. //  dwKeyType's:
  2189. //    CRYPT_OID_INFO_OID_KEY, pvKey points to a szOID
  2190. //    CRYPT_OID_INFO_NAME_KEY, pvKey points to a wszName
  2191. //    CRYPT_OID_INFO_ALGID_KEY, pvKey points to an ALG_ID
  2192. //    CRYPT_OID_INFO_SIGN_KEY, pvKey points to an array of two ALG_ID's:
  2193. //      ALG_ID[0] - Hash Algid
  2194. //      ALG_ID[1] - PubKey Algid
  2195. //
  2196. //  Setting dwGroupId to 0, searches all groups according to the dwKeyType.
  2197. //  Otherwise, only the dwGroupId is searched.
  2198. //--------------------------------------------------------------------------
  2199. function CryptFindOIDInfo(dwKeyType: DWORD; pvKey: Pointer; dwGroupId: DWORD): PCCRYPT_OID_INFO; stdcall;
  2200. {$EXTERNALSYM CryptFindOIDInfo}
  2201. const
  2202.   CRYPT_OID_INFO_OID_KEY   = 1;
  2203.   {$EXTERNALSYM CRYPT_OID_INFO_OID_KEY}
  2204.   CRYPT_OID_INFO_NAME_KEY  = 2;
  2205.   {$EXTERNALSYM CRYPT_OID_INFO_NAME_KEY}
  2206.   CRYPT_OID_INFO_ALGID_KEY = 3;
  2207.   {$EXTERNALSYM CRYPT_OID_INFO_ALGID_KEY}
  2208.   CRYPT_OID_INFO_SIGN_KEY  = 4;
  2209.   {$EXTERNALSYM CRYPT_OID_INFO_SIGN_KEY}
  2210. //+-------------------------------------------------------------------------
  2211. //  Register OID information. The OID information specified in the
  2212. //  CCRYPT_OID_INFO structure is persisted to the registry.
  2213. //
  2214. //  crypt32.dll contains information for the commonly known OIDs. This function
  2215. //  allows applications to augment crypt32.dll's OID information. During
  2216. //  CryptFindOIDInfo's first call, the registered OID information is installed.
  2217. //
  2218. //  By default the registered OID information is installed after crypt32.dll's
  2219. //  OID entries. Set CRYPT_INSTALL_OID_INFO_BEFORE_FLAG to install before.
  2220. //--------------------------------------------------------------------------
  2221. function CryptRegisterOIDInfo(pInfo: PCCRYPT_OID_INFO; dwFlags: DWORD): BOOL; stdcall;
  2222. {$EXTERNALSYM CryptRegisterOIDInfo}
  2223. const
  2224.   CRYPT_INSTALL_OID_INFO_BEFORE_FLAG = 1;
  2225.   {$EXTERNALSYM CRYPT_INSTALL_OID_INFO_BEFORE_FLAG}
  2226. //+-------------------------------------------------------------------------
  2227. //  Unregister OID information. Only the pszOID and dwGroupId fields are
  2228. //  used to identify the OID information to be unregistered.
  2229. //--------------------------------------------------------------------------
  2230. function CryptUnregisterOIDInfo(pInfo: PCCRYPT_OID_INFO): BOOL; stdcall;
  2231. {$EXTERNALSYM CryptUnregisterOIDInfo}
  2232. // If the callback returns FALSE, stops the enumeration.
  2233. type
  2234.   PFN_CRYPT_ENUM_OID_INFO = function (pInfo: PCCRYPT_OID_INFO; pvArg: Pointer): BOOL; stdcall;
  2235.   {$EXTERNALSYM PFN_CRYPT_ENUM_OID_INFO}
  2236.   PFnCryptEnumOidInfo = PFN_CRYPT_ENUM_OID_INFO;
  2237. //+-------------------------------------------------------------------------
  2238. //  Enumerate the OID information.
  2239. //
  2240. //  pfnEnumOIDInfo is called for each OID information entry.
  2241. //
  2242. //  Setting dwGroupId to 0 matches all groups. Otherwise, only enumerates
  2243. //  entries in the specified group.
  2244. //
  2245. //  dwFlags currently isn't used and must be set to 0.
  2246. //--------------------------------------------------------------------------
  2247. function CryptEnumOIDInfo(dwGroupId: DWORD; dwFlags: DWORD; pvArg: Pointer;
  2248.   pfnEnumOIDInfo: PFN_CRYPT_ENUM_OID_INFO): BOOL; stdcall;
  2249. {$EXTERNALSYM CryptEnumOIDInfo}
  2250. //+-------------------------------------------------------------------------
  2251. //  Find the localized name for the specified name. For example, find the
  2252. //  localized name for the "Root" system store name. A case insensitive
  2253. //  string comparison is done.
  2254. //
  2255. //  Returns NULL if unable to find the the specified name.
  2256. //
  2257. //  Localized names for the predefined system stores ("Root", "My") and
  2258. //  predefined physical stores (".Default", ".LocalMachine") are pre-installed
  2259. //  as resource strings in crypt32.dll. CryptSetOIDFunctionValue can be called
  2260. //  as follows to register additional localized strings:
  2261. //      dwEncodingType = CRYPT_LOCALIZED_NAME_ENCODING_TYPE
  2262. //      pszFuncName = CRYPT_OID_FIND_LOCALIZED_NAME_FUNC
  2263. //      pszOID = CRYPT_LOCALIZED_NAME_OID
  2264. //      pwszValueName = Name to be localized, for example, L"ApplicationStore"
  2265. //      dwValueType = REG_SZ
  2266. //      pbValueData = pointer to the UNICODE localized string
  2267. //      cbValueData = (wcslen(UNICODE localized string) + 1) * sizeof(WCHAR)
  2268. //
  2269. //  To unregister, set pbValueData to NULL and cbValueData to 0.
  2270. //
  2271. //  The registered names are searched before the pre-installed names.
  2272. //--------------------------------------------------------------------------
  2273. function CryptFindLocalizedName(pwszCryptName: LPCWSTR): LPCWSTR; stdcall;
  2274. {$EXTERNALSYM CryptFindLocalizedName}
  2275. const
  2276.   CRYPT_LOCALIZED_NAME_ENCODING_TYPE = 0;
  2277.   {$EXTERNALSYM CRYPT_LOCALIZED_NAME_ENCODING_TYPE}
  2278.   CRYPT_LOCALIZED_NAME_OID           = 'LocalizedNames';
  2279.   {$EXTERNALSYM CRYPT_LOCALIZED_NAME_OID}
  2280. //+=========================================================================
  2281. //  Low Level Cryptographic Message Data Structures and APIs
  2282. //==========================================================================
  2283. type
  2284.   HCRYPTMSG = Pointer;
  2285.   {$EXTERNALSYM HCRYPTMSG}
  2286.   PHCRYPTMSG = ^HCRYPTMSG;
  2287.   {$NODEFINE PHCRYPTMSG}
  2288. const
  2289.   szOID_PKCS_7_DATA               = '1.2.840.113549.1.7.1';
  2290.   {$EXTERNALSYM szOID_PKCS_7_DATA}
  2291.   szOID_PKCS_7_SIGNED             = '1.2.840.113549.1.7.2';
  2292.   {$EXTERNALSYM szOID_PKCS_7_SIGNED}
  2293.   szOID_PKCS_7_ENVELOPED          = '1.2.840.113549.1.7.3';
  2294.   {$EXTERNALSYM szOID_PKCS_7_ENVELOPED}
  2295.   szOID_PKCS_7_SIGNEDANDENVELOPED = '1.2.840.113549.1.7.4';
  2296.   {$EXTERNALSYM szOID_PKCS_7_SIGNEDANDENVELOPED}
  2297.   szOID_PKCS_7_DIGESTED           = '1.2.840.113549.1.7.5';
  2298.   {$EXTERNALSYM szOID_PKCS_7_DIGESTED}
  2299.   szOID_PKCS_7_ENCRYPTED          = '1.2.840.113549.1.7.6';
  2300.   {$EXTERNALSYM szOID_PKCS_7_ENCRYPTED}
  2301.   szOID_PKCS_9_CONTENT_TYPE   = '1.2.840.113549.1.9.3';
  2302.   {$EXTERNALSYM szOID_PKCS_9_CONTENT_TYPE}
  2303.   szOID_PKCS_9_MESSAGE_DIGEST = '1.2.840.113549.1.9.4';
  2304.   {$EXTERNALSYM szOID_PKCS_9_MESSAGE_DIGEST}
  2305. //+-------------------------------------------------------------------------
  2306. //  Message types
  2307. //--------------------------------------------------------------------------
  2308.   CMSG_DATA                 = 1;
  2309.   {$EXTERNALSYM CMSG_DATA}
  2310.   CMSG_SIGNED               = 2;
  2311.   {$EXTERNALSYM CMSG_SIGNED}
  2312.   CMSG_ENVELOPED            = 3;
  2313.   {$EXTERNALSYM CMSG_ENVELOPED}
  2314.   CMSG_SIGNED_AND_ENVELOPED = 4;
  2315.   {$EXTERNALSYM CMSG_SIGNED_AND_ENVELOPED}
  2316.   CMSG_HASHED               = 5;
  2317.   {$EXTERNALSYM CMSG_HASHED}
  2318.   CMSG_ENCRYPTED            = 6;
  2319.   {$EXTERNALSYM CMSG_ENCRYPTED}
  2320. //+-------------------------------------------------------------------------
  2321. //  Message Type Bit Flags
  2322. //--------------------------------------------------------------------------
  2323.   CMSG_ALL_FLAGS                 = (not 0);
  2324.   {$EXTERNALSYM CMSG_ALL_FLAGS}
  2325.   CMSG_DATA_FLAG                 = (1 shl CMSG_DATA);
  2326.   {$EXTERNALSYM CMSG_DATA_FLAG}
  2327.   CMSG_SIGNED_FLAG               = (1 shl CMSG_SIGNED);
  2328.   {$EXTERNALSYM CMSG_SIGNED_FLAG}
  2329.   CMSG_ENVELOPED_FLAG            = (1 shl CMSG_ENVELOPED);
  2330.   {$EXTERNALSYM CMSG_ENVELOPED_FLAG}
  2331.   CMSG_SIGNED_AND_ENVELOPED_FLAG = (1 shl CMSG_SIGNED_AND_ENVELOPED);
  2332.   {$EXTERNALSYM CMSG_SIGNED_AND_ENVELOPED_FLAG}
  2333.   CMSG_HASHED_FLAG               = (1 shl CMSG_HASHED);
  2334.   {$EXTERNALSYM CMSG_HASHED_FLAG}
  2335.   CMSG_ENCRYPTED_FLAG            = (1 shl CMSG_ENCRYPTED);
  2336.   {$EXTERNALSYM CMSG_ENCRYPTED_FLAG}
  2337. //+-------------------------------------------------------------------------
  2338. //  Certificate Issuer and SerialNumber
  2339. //--------------------------------------------------------------------------
  2340. type
  2341.   PCERT_ISSUER_SERIAL_NUMBER = ^CERT_ISSUER_SERIAL_NUMBER;
  2342.   {$EXTERNALSYM PCERT_ISSUER_SERIAL_NUMBER}
  2343.   _CERT_ISSUER_SERIAL_NUMBER = record
  2344.     Issuer: CERT_NAME_BLOB;
  2345.     SerialNumber: CRYPT_INTEGER_BLOB;
  2346.   end;
  2347.   {$EXTERNALSYM _CERT_ISSUER_SERIAL_NUMBER}
  2348.   CERT_ISSUER_SERIAL_NUMBER = _CERT_ISSUER_SERIAL_NUMBER;
  2349.   {$EXTERNALSYM CERT_ISSUER_SERIAL_NUMBER}
  2350.   TCertIssuerSerialNumber = CERT_ISSUER_SERIAL_NUMBER;
  2351.   PCertIssuerSerialNumber = PCERT_ISSUER_SERIAL_NUMBER;
  2352. //+-------------------------------------------------------------------------
  2353. //  Certificate Identifier
  2354. //--------------------------------------------------------------------------
  2355.   PCERT_ID = ^CERT_ID;
  2356.   {$EXTERNALSYM PCERT_ID}
  2357.   _CERT_ID = record
  2358.     dwIdChoice: DWORD;
  2359.     case Integer of
  2360.       // CERT_ID_ISSUER_SERIAL_NUMBER
  2361.       0: (IssuerSerialNumber: CERT_ISSUER_SERIAL_NUMBER);
  2362.       // CERT_ID_KEY_IDENTIFIER
  2363.       1: (KeyId: CRYPT_HASH_BLOB);
  2364.       // CERT_ID_SHA1_HASH
  2365.       2: (HashId: CRYPT_HASH_BLOB);
  2366.   end;
  2367.   {$EXTERNALSYM _CERT_ID}
  2368.   CERT_ID = _CERT_ID;
  2369.   {$EXTERNALSYM CERT_ID}
  2370.   TCertId = CERT_ID;
  2371.   PCertId = PCERT_ID;
  2372. const
  2373.   CERT_ID_ISSUER_SERIAL_NUMBER = 1;
  2374.   {$EXTERNALSYM CERT_ID_ISSUER_SERIAL_NUMBER}
  2375.   CERT_ID_KEY_IDENTIFIER       = 2;
  2376.   {$EXTERNALSYM CERT_ID_KEY_IDENTIFIER}
  2377.   CERT_ID_SHA1_HASH            = 3;
  2378.   {$EXTERNALSYM CERT_ID_SHA1_HASH}
  2379. //+-------------------------------------------------------------------------
  2380. //  The message encode information (pvMsgEncodeInfo) is message type dependent
  2381. //--------------------------------------------------------------------------
  2382. //+-------------------------------------------------------------------------
  2383. //  CMSG_DATA: pvMsgEncodeInfo = NULL
  2384. //--------------------------------------------------------------------------
  2385. //+-------------------------------------------------------------------------
  2386. //  CMSG_SIGNED
  2387. //
  2388. //  The pCertInfo in the CMSG_SIGNER_ENCODE_INFO provides the Issuer, SerialNumber
  2389. //  and PublicKeyInfo.Algorithm. The PublicKeyInfo.Algorithm implicitly
  2390. //  specifies the HashEncryptionAlgorithm to be used.
  2391. //
  2392. //  If the SignerId is present with a nonzero dwIdChoice its used instead
  2393. //  of the Issuer and SerialNumber in pCertInfo.
  2394. //
  2395. //  CMS supports the KEY_IDENTIFIER and ISSUER_SERIAL_NUMBER CERT_IDs. PKCS #7
  2396. //  version 1.5 only supports the ISSUER_SERIAL_NUMBER CERT_ID choice.
  2397. //
  2398. //  If HashEncryptionAlgorithm is present and not NULL its used instead of
  2399. //  the PublicKeyInfo.Algorithm.
  2400. //
  2401. //  Note, for RSA, the hash encryption algorithm is normally the same as
  2402. //  the public key algorithm. For DSA, the hash encryption algorithm is
  2403. //  normally a DSS signature algorithm.
  2404. //
  2405. //  pvHashEncryptionAuxInfo currently isn't used and must be set to NULL if
  2406. //  present in the data structure.
  2407. //
  2408. //  The hCryptProv and dwKeySpec specify the private key to use. If dwKeySpec
  2409. //  == 0, then, defaults to AT_SIGNATURE.
  2410. //
  2411. //  If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  2412. //  passed to CryptMsgOpenToEncode(), the signer hCryptProv's are released.
  2413. //
  2414. //  pvHashAuxInfo currently isn't used and must be set to NULL.
  2415. //
  2416. //  CMS signed messages allow the inclusion of Attribute Certs.
  2417. //--------------------------------------------------------------------------
  2418. type
  2419.   PCMSG_SIGNER_ENCODE_INFO = ^CMSG_SIGNER_ENCODE_INFO;
  2420.   {$EXTERNALSYM PCMSG_SIGNER_ENCODE_INFO}
  2421.   _CMSG_SIGNER_ENCODE_INFO = record
  2422.     cbSize: DWORD;
  2423.     pCertInfo: PCERT_INFO;
  2424.     hCryptProv: HCRYPTPROV;
  2425.     dwKeySpec: DWORD;
  2426.     HashAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  2427.     pvHashAuxInfo: Pointer;
  2428.     cAuthAttr: DWORD;
  2429.     rgAuthAttr: PCRYPT_ATTRIBUTE;
  2430.     cUnauthAttr: DWORD;
  2431.     rgUnauthAttr: PCRYPT_ATTRIBUTE;
  2432.     {$IFDEF CMSG_SIGNER_ENCODE_INFO_HAS_CMS_FIELDS}
  2433.     SignerId: CERT_ID;
  2434.     HashEncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  2435.     pvHashEncryptionAuxInfo: Pointer;
  2436.     {$ENDIF}
  2437.   end;
  2438.   {$EXTERNALSYM _CMSG_SIGNER_ENCODE_INFO}
  2439.   CMSG_SIGNER_ENCODE_INFO = _CMSG_SIGNER_ENCODE_INFO;
  2440.   {$EXTERNALSYM CMSG_SIGNER_ENCODE_INFO}
  2441.   TCmsgSignerEncodeInfo = CMSG_SIGNER_ENCODE_INFO;
  2442.   PCmsgSignerEncodeInfo = PCMSG_SIGNER_ENCODE_INFO;
  2443.   PCMSG_SIGNED_ENCODE_INFO = ^CMSG_SIGNED_ENCODE_INFO;
  2444.   {$EXTERNALSYM PCMSG_SIGNED_ENCODE_INFO}
  2445.   _CMSG_SIGNED_ENCODE_INFO = record
  2446.     cbSize: DWORD;
  2447.     cSigners: DWORD;
  2448.     rgSigners: PCMSG_SIGNER_ENCODE_INFO;
  2449.     cCertEncoded: DWORD;
  2450.     rgCertEncoded: PCERT_BLOB;
  2451.     cCrlEncoded: DWORD;
  2452.     rgCrlEncoded: PCRL_BLOB;
  2453.     {$IFDEF CMSG_SIGNED_ENCODE_INFO_HAS_CMS_FIELDS}
  2454.     cAttrCertEncoded: DWORD;
  2455.     rgAttrCertEncoded: PCERT_BLOB;
  2456.     {$ENDIF}
  2457.   end;
  2458.   {$EXTERNALSYM _CMSG_SIGNED_ENCODE_INFO}
  2459.   CMSG_SIGNED_ENCODE_INFO = _CMSG_SIGNED_ENCODE_INFO;
  2460.   {$EXTERNALSYM CMSG_SIGNED_ENCODE_INFO}
  2461.   TCmsgSignedEncodeInfo = CMSG_SIGNED_ENCODE_INFO;
  2462.   PCmsgSignedEncodeInfo = PCMSG_SIGNED_ENCODE_INFO;
  2463. //+-------------------------------------------------------------------------
  2464. //  CMSG_ENVELOPED
  2465. //
  2466. //  The PCERT_INFO for the rgRecipients provides the Issuer, SerialNumber
  2467. //  and PublicKeyInfo. The PublicKeyInfo.Algorithm implicitly
  2468. //  specifies the KeyEncryptionAlgorithm to be used.
  2469. //
  2470. //  The PublicKeyInfo.PublicKey in PCERT_INFO is used to encrypt the content
  2471. //  encryption key for the recipient.
  2472. //
  2473. //  hCryptProv is used to do the content encryption, recipient key encryption
  2474. //  and export. The hCryptProv's private keys aren't used. If hCryptProv
  2475. //  is NULL, a default hCryptProv is chosen according to the
  2476. //  ContentEncryptionAlgorithm and the first recipient KeyEncryptionAlgorithm.
  2477. //
  2478. //  If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  2479. //  passed to CryptMsgOpenToEncode(), the envelope's hCryptProv is released.
  2480. //
  2481. //  Note: CAPI currently doesn't support more than one KeyEncryptionAlgorithm
  2482. //  per provider. This will need to be fixed.
  2483. //
  2484. //  Currently, pvEncryptionAuxInfo is only defined for RC2 or RC4 encryption
  2485. //  algorithms. Otherwise, its not used and must be set to NULL.
  2486. //  See CMSG_RC2_AUX_INFO for the RC2 encryption algorithms.
  2487. //  See CMSG_RC4_AUX_INFO for the RC4 encryption algorithms.
  2488. //
  2489. //  To enable SP3 compatible encryption, pvEncryptionAuxInfo should point to
  2490. //  a CMSG_SP3_COMPATIBLE_AUX_INFO data structure.
  2491. //
  2492. //  To enable the CMS envelope enhancements, rgpRecipients must be set to
  2493. //  NULL, and rgCmsRecipients updated to point to an array of
  2494. //  CMSG_RECIPIENT_ENCODE_INFO's.
  2495. //
  2496. //  Also, CMS envelope enhancements support the inclusion of a bag of
  2497. //  Certs, CRLs, Attribute Certs and/or Unprotected Attributes.
  2498. //--------------------------------------------------------------------------
  2499. type
  2500.   PCMSG_ENVELOPED_ENCODE_INFO = ^CMSG_ENVELOPED_ENCODE_INFO;
  2501.   {$EXTERNALSYM PCMSG_ENVELOPED_ENCODE_INFO}
  2502.   _CMSG_ENVELOPED_ENCODE_INFO = record
  2503.     cbSize: DWORD;
  2504.     hCryptProv: HCRYPTPROV;
  2505.     ContentEncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  2506.     pvEncryptionAuxInfo: Pointer;
  2507.     cRecipients: DWORD;
  2508.     // The following array may only be used for transport recipients identified
  2509.     // by their IssuereAndSerialNumber. If rgpRecipients != NULL, then,
  2510.     // the rgCmsRecipients must be NULL.
  2511.     rgpRecipients: PCERT_INFO;
  2512.     {$IFDEF CMSG_ENVELOPED_ENCODE_INFO_HAS_CMS_FIELDS}
  2513.     // If rgCmsRecipients != NULL, then, the above rgpRecipients must be
  2514.     // NULL.
  2515.     rgCmsRecipients: PCMSG_RECIPIENT_ENCODE_INFO;
  2516.     cCertEncoded: DWORD;
  2517.     rgCertEncoded: PCERT_BLOB;
  2518.     cCrlEncoded: DWORD;
  2519.     rgCrlEncoded: PCRL_BLOB;
  2520.     cAttrCertEncoded: DWORD;
  2521.     rgAttrCertEncoded: PCERT_BLOB;
  2522.     cUnprotectedAttr: DWORD;
  2523.     rgUnprotectedAttr: PCRYPT_ATTRIBUTE;
  2524.     {$ENDIF}
  2525.   end;
  2526.   {$EXTERNALSYM _CMSG_ENVELOPED_ENCODE_INFO}
  2527.   CMSG_ENVELOPED_ENCODE_INFO = _CMSG_ENVELOPED_ENCODE_INFO;
  2528.   {$EXTERNALSYM CMSG_ENVELOPED_ENCODE_INFO}
  2529.   TCmsgEnvelopedEncodeInfo = CMSG_ENVELOPED_ENCODE_INFO;
  2530.   PCmsgEnvelopedEncodeInfo = PCMSG_ENVELOPED_ENCODE_INFO;
  2531. //+-------------------------------------------------------------------------
  2532. //  Key Transport Recipient Encode Info
  2533. //
  2534. //  hCryptProv is used to do the recipient key encryption
  2535. //  and export. The hCryptProv's private keys aren't used.
  2536. //
  2537. //  If hCryptProv is NULL, then, the hCryptProv specified in
  2538. //  CMSG_ENVELOPED_ENCODE_INFO is used.
  2539. //
  2540. //  Note, even if CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  2541. //  passed to CryptMsgOpenToEncode(), this hCryptProv isn't released.
  2542. //
  2543. //  CMS supports the KEY_IDENTIFIER and ISSUER_SERIAL_NUMBER CERT_IDs. PKCS #7
  2544. //  version 1.5 only supports the ISSUER_SERIAL_NUMBER CERT_ID choice.
  2545. //--------------------------------------------------------------------------
  2546.   PCMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO = ^CMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO;
  2547.   {$EXTERNALSYM PCMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO}
  2548.   _CMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO = record
  2549.     cbSize: DWORD;
  2550.     KeyEncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  2551.     pvKeyEncryptionAuxInfo: Pointer;
  2552.     hCryptProv: HCRYPTPROV;
  2553.     RecipientPublicKey: CRYPT_BIT_BLOB;
  2554.     RecipientId: CERT_ID;
  2555.   end;
  2556.   {$EXTERNALSYM _CMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO}
  2557.   CMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO = _CMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO;
  2558.   {$EXTERNALSYM CMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO}
  2559.   TCmsgKeyTransRecipientEncodeInfo = CMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO;
  2560.   PCmsgKeyTransRecipientEncodeInfo = PCMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO;
  2561. //+-------------------------------------------------------------------------
  2562. //  Key Agreement Recipient Encode Info
  2563. //
  2564. //  If hCryptProv is NULL, then, the hCryptProv specified in
  2565. //  CMSG_ENVELOPED_ENCODE_INFO is used.
  2566. //
  2567. //  For the CMSG_KEY_AGREE_STATIC_KEY_CHOICE, both the hCryptProv and
  2568. //  dwKeySpec must be specified to select the sender's private key.
  2569. //
  2570. //  Note, even if CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  2571. //  passed to CryptMsgOpenToEncode(), this hCryptProv isn't released.
  2572. //
  2573. //  CMS supports the KEY_IDENTIFIER and ISSUER_SERIAL_NUMBER CERT_IDs.
  2574. //
  2575. //  There is 1 key choice, ephemeral originator. The originator's ephemeral
  2576. //  key is generated using the public key algorithm parameters shared
  2577. //  amongst all the recipients.
  2578. //
  2579. //  There are 2 key choices: ephemeral originator or static sender. The
  2580. //  originator's ephemeral key is generated using the public key algorithm
  2581. //  parameters shared amongst all the recipients. For the static sender its
  2582. //  private key is used. The hCryptProv and dwKeySpec specify the private key.
  2583. //  The pSenderId identifies the certificate containing the sender's public key.
  2584. //
  2585. //  Currently, pvKeyEncryptionAuxInfo isn't used and must be set to NULL. 
  2586. //
  2587. //  If KeyEncryptionAlgorithm.Parameters.cbData == 0, then, its Parameters
  2588. //  are updated with the encoded KeyWrapAlgorithm.
  2589. //
  2590. //  Currently, pvKeyWrapAuxInfo is only defined for algorithms with
  2591. //  RC2. Otherwise, its not used and must be set to NULL.
  2592. //  When set for RC2 algorithms, points to a CMSG_RC2_AUX_INFO containing
  2593. //  the RC2 effective key length.
  2594. //
  2595. //  Note, key agreement recipients are not supported in PKCS #7 version 1.5.
  2596. //--------------------------------------------------------------------------
  2597.   PCMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO = ^CMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO;
  2598.   {$EXTERNALSYM PCMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO}
  2599.   _CMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO = record
  2600.     cbSize: DWORD;
  2601.     RecipientPublicKey: CRYPT_BIT_BLOB;
  2602.     RecipientId: CERT_ID;
  2603.     // Following fields are optional and only applicable to KEY_IDENTIFIER
  2604.     // CERT_IDs.
  2605.     Date: FILETIME;
  2606.     pOtherAttr: PCRYPT_ATTRIBUTE_TYPE_VALUE;
  2607.   end;
  2608.   {$EXTERNALSYM _CMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO}