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.

273 lines
12 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1995 - 1999
  6. //
  7. // File: pvkhlpr.h
  8. //
  9. // Contents: Private Key Helper API Prototypes and Definitions
  10. //
  11. // Note: Base CSP also exports/imports the public key with the
  12. // private key.
  13. //
  14. // APIs: PrivateKeyLoad
  15. // PrivateKeySave
  16. // PrivateKeyLoadFromMemory
  17. // PrivateKeySaveToMemory
  18. // PrivateKeyAcquireContext
  19. // PrivateKeyAcquireContextFromMemory
  20. // PrivateKeyReleaseContext
  21. // PrivateKeyLoadA
  22. // PrivateKeySaveA
  23. // PrivateKeyLoadFromMemoryA
  24. // PrivateKeySaveToMemoryA
  25. // PrivateKeyAcquireContextA
  26. // PrivateKeyAcquireContextFromMemoryA
  27. // PrivateKeyReleaseContextA
  28. //
  29. // History: 10-May-96 philh created
  30. //--------------------------------------------------------------------------
  31. #ifndef __PVKHLPR_H__
  32. #define __PVKHLPR_H__
  33. #include "wincrypt.h"
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. #ifndef PRIVATEKEYBLOB
  38. #define PRIVATEKEYBLOB 0x7
  39. #endif
  40. //+-------------------------------------------------------------------------
  41. // Load the AT_SIGNATURE or AT_KEYEXCHANGE private key (and its public key)
  42. // from the file into the cryptographic provider.
  43. //
  44. // If the private key was password encrypted, then, the user is first
  45. // presented with a dialog box to enter the password.
  46. //
  47. // If pdwKeySpec is non-Null, then, if *pdwKeySpec is nonzero, verifies the
  48. // key type before loading. Sets LastError to PVK_HELPER_WRONG_KEY_TYPE for
  49. // a mismatch. *pdwKeySpec is updated with the key type.
  50. //
  51. // dwFlags is passed through to CryptImportKey.
  52. //--------------------------------------------------------------------------
  53. BOOL WINAPI
  54. PvkPrivateKeyLoad(IN HCRYPTPROV hCryptProv,
  55. IN HANDLE hFile,
  56. IN HWND hwndOwner,
  57. IN LPCWSTR pwszKeyName, // name used in dialog
  58. IN DWORD dwFlags,
  59. IN OUT OPTIONAL DWORD *pdwKeySpec);
  60. BOOL WINAPI
  61. PvkPrivateKeyLoadA(IN HCRYPTPROV hCryptProv,
  62. IN HANDLE hFile,
  63. IN HWND hwndOwner,
  64. IN LPCTSTR pwszKeyName, // name used in dialog
  65. IN DWORD dwFlags,
  66. IN OUT OPTIONAL DWORD *pdwKeySpec);
  67. //+-------------------------------------------------------------------------
  68. // Save the AT_SIGNATURE or AT_KEYEXCHANGE private key (and its public key)
  69. // to the specified file.
  70. //
  71. // The user is presented with a dialog box to enter an optional password to
  72. // encrypt the private key.
  73. //
  74. // dwFlags is passed through to CryptExportKey.
  75. //--------------------------------------------------------------------------
  76. BOOL WINAPI
  77. PvkPrivateKeySave(IN HCRYPTPROV hCryptProv,
  78. IN HANDLE hFile,
  79. IN DWORD dwKeySpec, // either AT_SIGNATURE or AT_KEYEXCHANGE
  80. IN HWND hwndOwner,
  81. IN LPCWSTR pwszKeyName, // name used in dialog
  82. IN DWORD dwFlags);
  83. BOOL WINAPI
  84. PvkPrivateKeySaveA(IN HCRYPTPROV hCryptProv,
  85. IN HANDLE hFile,
  86. IN DWORD dwKeySpec, // either AT_SIGNATURE or AT_KEYEXCHANGE
  87. IN HWND hwndOwner,
  88. IN LPCTSTR pwszKeyName, // name used in dialog
  89. IN DWORD dwFlags);
  90. //+-------------------------------------------------------------------------
  91. // Load the AT_SIGNATURE or AT_KEYEXCHANGE private key (and its public key)
  92. // from memory into the cryptographic provider.
  93. //
  94. // Except for the key being loaded from memory, identical to PrivateKeyLoad.
  95. //--------------------------------------------------------------------------
  96. BOOL WINAPI
  97. PvkPrivateKeyLoadFromMemory(IN HCRYPTPROV hCryptProv,
  98. IN BYTE *pbData,
  99. IN DWORD cbData,
  100. IN HWND hwndOwner,
  101. IN LPCWSTR pwszKeyName, // name used in dialog
  102. IN DWORD dwFlags,
  103. IN OUT OPTIONAL DWORD *pdwKeySpec);
  104. BOOL WINAPI
  105. PvkPrivateKeyLoadFromMemoryA(IN HCRYPTPROV hCryptProv,
  106. IN BYTE *pbData,
  107. IN DWORD cbData,
  108. IN HWND hwndOwner,
  109. IN LPCTSTR pwszKeyName, // name used in dialog
  110. IN DWORD dwFlags,
  111. IN OUT OPTIONAL DWORD *pdwKeySpec);
  112. //+-------------------------------------------------------------------------
  113. // Save the AT_SIGNATURE or AT_KEYEXCHANGE private key (and its public key)
  114. // to memory.
  115. //
  116. // If pbData == NULL || *pcbData == 0, calculates the length and doesn't
  117. // return an error (also, the user isn't prompted for a password).
  118. //
  119. // Except for the key being saved to memory, identical to PrivateKeySave.
  120. //--------------------------------------------------------------------------
  121. BOOL WINAPI
  122. PvkPrivateKeySaveToMemory(IN HCRYPTPROV hCryptProv,
  123. IN DWORD dwKeySpec, // either AT_SIGNATURE or AT_KEYEXCHANGE
  124. IN HWND hwndOwner,
  125. IN LPCWSTR pwszKeyName, // name used in dialog
  126. IN DWORD dwFlags,
  127. OUT BYTE *pbData,
  128. IN OUT DWORD *pcbData);
  129. BOOL WINAPI
  130. PvkPrivateKeySaveToMemoryA(IN HCRYPTPROV hCryptProv,
  131. IN DWORD dwKeySpec, // either AT_SIGNATURE or AT_KEYEXCHANGE
  132. IN HWND hwndOwner,
  133. IN LPCTSTR pwszKeyName, // name used in dialog
  134. IN DWORD dwFlags,
  135. OUT BYTE *pbData,
  136. IN OUT DWORD *pcbData);
  137. //+-------------------------------------------------------------------------
  138. // Creates a temporary container in the provider and loads the private key
  139. // from the specified file.
  140. // For success, returns a handle to a cryptographic provider for the private
  141. // key and the name of the temporary container. PrivateKeyReleaseContext must
  142. // be called to release the hCryptProv and delete the temporary container.
  143. //
  144. // PrivateKeyLoad is called to load the private key into the temporary
  145. // container.
  146. //--------------------------------------------------------------------------
  147. BOOL WINAPI
  148. PvkPrivateKeyAcquireContext(IN LPCWSTR pwszProvName,
  149. IN DWORD dwProvType,
  150. IN HANDLE hFile,
  151. IN HWND hwndOwner,
  152. IN LPCWSTR pwszKeyName, // name used in dialog
  153. IN OUT OPTIONAL DWORD *pdwKeySpec,
  154. OUT HCRYPTPROV *phCryptProv,
  155. OUT LPWSTR *ppwszTmpContainer
  156. );
  157. BOOL WINAPI
  158. PvkPrivateKeyAcquireContextA(IN LPCTSTR pwszProvName,
  159. IN DWORD dwProvType,
  160. IN HANDLE hFile,
  161. IN HWND hwndOwner,
  162. IN LPCTSTR pwszKeyName, // name used in dialog
  163. IN OUT OPTIONAL DWORD *pdwKeySpec,
  164. OUT HCRYPTPROV *phCryptProv,
  165. OUT LPTSTR *ppwszTmpContainer);
  166. //+-------------------------------------------------------------------------
  167. // Creates a temporary container in the provider and loads the private key
  168. // from memory.
  169. // For success, returns a handle to a cryptographic provider for the private
  170. // key and the name of the temporary container. PrivateKeyReleaseContext must
  171. // be called to release the hCryptProv and delete the temporary container.
  172. //
  173. // PrivateKeyLoadFromMemory is called to load the private key into the
  174. // temporary container.
  175. //--------------------------------------------------------------------------
  176. BOOL WINAPI
  177. PvkPrivateKeyAcquireContextFromMemory(IN LPCWSTR pwszProvName,
  178. IN DWORD dwProvType,
  179. IN BYTE *pbData,
  180. IN DWORD cbData,
  181. IN HWND hwndOwner,
  182. IN LPCWSTR pwszKeyName, // name used in dialog
  183. IN OUT OPTIONAL DWORD *pdwKeySpec,
  184. OUT HCRYPTPROV *phCryptProv,
  185. OUT LPWSTR *ppwszTmpContainer);
  186. BOOL WINAPI
  187. PvkPrivateKeyAcquireContextFromMemoryA(IN LPCTSTR pwszProvName,
  188. IN DWORD dwProvType,
  189. IN BYTE *pbData,
  190. IN DWORD cbData,
  191. IN HWND hwndOwner,
  192. IN LPCTSTR pwszKeyName, // name used in dialog
  193. IN OUT OPTIONAL DWORD *pdwKeySpec,
  194. OUT HCRYPTPROV *phCryptProv,
  195. OUT LPTSTR *ppwszTmpContainer);
  196. //+-------------------------------------------------------------------------
  197. // Releases the cryptographic provider and deletes the temporary container
  198. // created by PrivateKeyAcquireContext or PrivateKeyAcquireContextFromMemory.
  199. //--------------------------------------------------------------------------
  200. BOOL WINAPI
  201. PvkPrivateKeyReleaseContext(IN HCRYPTPROV hCryptProv,
  202. IN LPCWSTR pwszProvName,
  203. IN DWORD dwProvType,
  204. IN LPWSTR pwszTmpContainer);
  205. BOOL WINAPI
  206. PvkPrivateKeyReleaseContextA(IN HCRYPTPROV hCryptProv,
  207. IN LPCTSTR pwszProvName,
  208. IN DWORD dwProvType,
  209. IN LPTSTR pwszTmpContainer);
  210. //+-------------------------------------------------------------------------
  211. // Acquiring hprovs, Trys the file first and then the KeyContainer. Use
  212. // PvkFreeCryptProv to release HCRYPTPROV and resources.
  213. //--------------------------------------------------------------------------
  214. HCRYPTPROV WINAPI
  215. PvkGetCryptProvA(IN HWND hwnd,
  216. IN LPCSTR pszCaption,
  217. IN LPCSTR pszCapiProvider,
  218. IN DWORD dwProviderType,
  219. IN LPCSTR pszPrivKey,
  220. OUT LPSTR *ppszTmpContainer);
  221. void WINAPI
  222. PvkFreeCryptProvA(IN HCRYPTPROV hProv,
  223. IN LPCSTR pszCapiProvider,
  224. IN DWORD dwProviderType,
  225. IN LPSTR pszTmpContainer);
  226. HCRYPTPROV WINAPI
  227. PvkGetCryptProvU(IN HWND hwnd,
  228. IN LPCWSTR pwszCaption,
  229. IN LPCWSTR pwszCapiProvider,
  230. IN DWORD dwProviderType,
  231. IN LPCWSTR pwszPrivKey,
  232. OUT LPWSTR *ppwszTmpContainer);
  233. void WINAPI
  234. PvkFreeCryptProvU(IN HCRYPTPROV hProv,
  235. IN LPCWSTR pwszCapiProvider,
  236. IN DWORD dwProviderType,
  237. IN LPWSTR pwszTmpContainer);
  238. //+-------------------------------------------------------------------------
  239. // Private Key helper error codes
  240. //--------------------------------------------------------------------------
  241. #define PVK_HELPER_BAD_PARAMETER 0x80097001
  242. #define PVK_HELPER_BAD_PVK_FILE 0x80097002
  243. #define PVK_HELPER_WRONG_KEY_TYPE 0x80097003
  244. #define PVK_HELPER_PASSWORD_CANCEL 0x80097004
  245. #ifdef __cplusplus
  246. } // Balance extern "C" above
  247. #endif
  248. #endif