Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

156 lines
6.3 KiB

  1. #ifndef _PFXHELP_H
  2. #define _PFXHELP_H
  3. //+---------------------------------------------------------------------------
  4. //
  5. // Microsoft Windows
  6. // Copyright (C) Microsoft Corporation, 1992 - 1999
  7. //
  8. // File: pfxhelp.h
  9. //
  10. // Contents: PFX helper function defintions and types
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "pfx.h"
  14. //+-------------------------------------------------------------------------
  15. // Safe Bag Type Object Identifiers
  16. //--------------------------------------------------------------------------
  17. #define szOID_PKCS_12_VERSION1 szOID_PKCS_12 ".10"
  18. #define szOID_PKCS_12_BAG_IDS szOID_PKCS_12_VERSION1 ".1"
  19. #define szOID_PKCS_12_KEY_BAG szOID_PKCS_12_BAG_IDS ".1"
  20. #define szOID_PKCS_12_SHROUDEDKEY_BAG szOID_PKCS_12_BAG_IDS ".2"
  21. #define szOID_PKCS_12_CERT_BAG szOID_PKCS_12_BAG_IDS ".3"
  22. #define szOID_PKCS_12_CRL_BAG szOID_PKCS_12_BAG_IDS ".4"
  23. #define szOID_PKCS_12_SECRET_BAG szOID_PKCS_12_BAG_IDS ".5"
  24. #define szOID_PKCS_12_SAFECONTENTS_BAG szOID_PKCS_12_BAG_IDS ".6"
  25. #define PBE_SALT_LENGTH 8
  26. typedef struct _SAFE_BAG{
  27. LPSTR pszBagTypeOID;
  28. CRYPT_DER_BLOB BagContents;
  29. CRYPT_ATTRIBUTES Attributes;
  30. } SAFE_BAG, *PSAFE_BAG;
  31. typedef struct _SAFE_CONTENTS{
  32. DWORD cSafeBags;
  33. SAFE_BAG *pSafeBags;
  34. } SAFE_CONTENTS, *PSAFE_CONTENTS;
  35. typedef struct _EXPORT_SAFE_CALLBACK_STRUCT {
  36. PCRYPT_ENCRYPT_PRIVATE_KEY_FUNC pEncryptPrivateKeyFunc;
  37. LPVOID pVoidEncryptFunc;
  38. } EXPORT_SAFE_CALLBACK_STRUCT, *PEXPORT_SAFE_CALLBACK_STRUCT;
  39. //+-------------------------------------------------------------------------
  40. // hCertStore - handle to the cert store that contains the certs whose
  41. // corresponding private keys are to be exported
  42. // pSafeContents - pointer to a buffer to receive the SAFE_CONTENTS structure
  43. // and supporting data
  44. // pcbSafeContents - (in) specifies the length, in bytes, of the pSafeContents
  45. // buffer. (out) gets filled in with the number of bytes
  46. // used by the operation. If this is set to 0, the
  47. // required length of pSafeContents is filled in, and
  48. // pSafeContents is ignored.
  49. // ExportSafeCallbackStruct - pointer to callbacks to handle PKCS8 encryption. If NULL,
  50. // no encryption is performed.
  51. // dwFlags - the current available flags are:
  52. // EXPORT_PRIVATE_KEYS
  53. // if this flag is set then the private keys are exported as well
  54. // as the certificates
  55. // REPORT_NO_PRIVATE_KEY
  56. // if this flag is set and a certificate is encountered that has no
  57. // no associated private key, the function will return immediately
  58. // with ppCertContext filled in with a pointer to the cert context
  59. // in question. the caller is responsible for freeing the cert
  60. // context which is passed back.
  61. // REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY
  62. // if this flag is set and a certificate is encountered that has a
  63. // non-exportable private key, the function will return immediately
  64. // with ppCertContext filled in with a pointer to the cert context
  65. // in question. the caller is responsible for freeing the cert
  66. // context which is passed back.
  67. // ppCertContext - a pointer to a pointer to a cert context. this is used
  68. // if REPORT_NO_PRIVATE_KEY or REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY
  69. // flags are set. the caller is responsible for freeing the
  70. // cert context.
  71. // pvAuxInfo - reserved for future use, must be set to NULL
  72. //+-------------------------------------------------------------------------
  73. BOOL WINAPI CertExportSafeContents(
  74. HCERTSTORE hCertStore, // in
  75. SAFE_CONTENTS *pSafeContents, // out
  76. DWORD *pcbSafeContents, // in, out
  77. EXPORT_SAFE_CALLBACK_STRUCT* ExportSafeCallbackStruct, // in
  78. DWORD dwFlags, // in
  79. PCCERT_CONTEXT *ppCertContext, // out
  80. void *pvAuxInfo // in
  81. );
  82. // this callback is called when a private key is going to be imported,
  83. // this gives the caller a chance specify which provider to import the
  84. // key to.
  85. // the parameters are:
  86. // pPrivateKeyInfo - a PRIVATE_KEY_INFO structure which contains all
  87. // the information about the private key being imported
  88. // dwSafeBagIndex - the idex into the safe bag array so the caller can
  89. // identify which SAFE_BAG this key cam out of
  90. // phCryptProvInfo - a pointer to a HCRYPTPROV that is to be filled in
  91. // with the handle of the provider to import to
  92. // ppVoidhCryptProvQueryVoid - the LPVOID that was passed in when
  93. // CertImportSafeContents called, this is
  94. // preserved and passed back to the caller for
  95. // context
  96. typedef BOOL (CALLBACK *PHCRYPTPROV_QUERY_FUNC)(
  97. CRYPT_PRIVATE_KEY_INFO *pPrivateKeyInfo,
  98. DWORD dwSafeBagIndex,
  99. HCRYPTPROV *phCryptProv,
  100. LPVOID pVoidhCryptProvQuery,
  101. DWORD dwPFXImportFlags);
  102. typedef struct _IMPORT_SAFE_CALLBACK_STRUCT {
  103. PHCRYPTPROV_QUERY_FUNC phCryptProvQueryFunc;
  104. LPVOID pVoidhCryptProvQuery;
  105. PCRYPT_DECRYPT_PRIVATE_KEY_FUNC pDecryptPrivateKeyFunc;
  106. LPVOID pVoidDecryptFunc;
  107. } IMPORT_SAFE_CALLBACK_STRUCT, *PIMPORT_SAFE_CALLBACK_STRUCT;
  108. //+-------------------------------------------------------------------------
  109. // hCertStore - handle of the cert store to import the safe contents to
  110. // pSafeContents - pointer to the safe contents to import to the store
  111. // dwCertAddDisposition - used when importing certificate to the store.
  112. // for a full explanation of the possible values
  113. // and their meanings see documentation for
  114. // CertAddEncodedCertificateToStore
  115. // ImportSafeCallbackStruct - structure that contains pointers to functions
  116. // which are callled to get a HCRYPTPROV for import
  117. // and to decrypt the key if a EncryptPrivateKeyInfo
  118. // is encountered during import
  119. // dwFlags - The available flags are:
  120. // CRYPT_EXPORTABLE
  121. // this flag is used when importing private keys, for a full
  122. // explanation please see the documentation for CryptImportKey.
  123. // pvAuxInfo - reserved for future use, must be set to NULL
  124. //+-------------------------------------------------------------------------
  125. BOOL WINAPI CertImportSafeContents(
  126. HCERTSTORE hCertStore, // in
  127. SAFE_CONTENTS *pSafeContents, // in
  128. DWORD dwCertAddDisposition, // in
  129. IMPORT_SAFE_CALLBACK_STRUCT* ImportSafeCallbackStruct, // in
  130. DWORD dwFlags, // in
  131. void *pvAuxInfo // in
  132. );
  133. #endif