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.

313 lines
7.4 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1997 - 1999
  3. Module Name:
  4. ScLogon
  5. Abstract:
  6. This header defines APIs for use by GINA and LSA during WinLogon via a
  7. smart card
  8. Author:
  9. Amanda Matlosz (amatlosz) 10/23/1997
  10. Environment:
  11. Win32
  12. Revision History:
  13. Notes:
  14. --*/
  15. #ifndef __SCLOGON_H__
  16. #define __SCLOGON_H__
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /////////////////////////////////////////////////////////////////////////////
  21. //
  22. // defines
  23. #ifndef NT_INCLUDED
  24. typedef LONG NTSTATUS;
  25. typedef NTSTATUS *PNTSTATUS;
  26. typedef struct _UNICODE_STRING {
  27. USHORT Length;
  28. USHORT MaximumLength;
  29. PWSTR Buffer;
  30. } UNICODE_STRING, *PUNICODE_STRING;
  31. #endif
  32. //////////////////////////////////////////////////////////////////////////////
  33. //
  34. // Structs
  35. // this entire struct is opaque, and is used by the helper APIs to contain
  36. // information about the card currently in use
  37. struct LogonInfo
  38. {
  39. DWORD dwLogonInfoLen;
  40. PVOID ContextInformation;
  41. ULONG nCardNameOffset;
  42. ULONG nReaderNameOffset;
  43. ULONG nContainerNameOffset;
  44. ULONG nCSPNameOffset;
  45. // LogonInfo may include further information, like:
  46. // crypt context, useful handles, pid...
  47. TCHAR bBuffer[sizeof(DWORD)]; // expandable place for strings
  48. };
  49. typedef struct _ScHelper_RandomCredBits
  50. {
  51. BYTE bR1[32]; // TBD: is 32 appropriate?
  52. BYTE bR2[32];
  53. } ScHelper_RandomCredBits;
  54. //////////////////////////////////////////////////////////////////////////////
  55. //
  56. // Functions
  57. //
  58. // helpers to access to items in opaque LogonInfo, such as:
  59. LPCTSTR WINAPI GetReaderName(PBYTE pbLogonInfo);
  60. LPCTSTR WINAPI GetCardName(PBYTE pbLogonInfo);
  61. LPCTSTR WINAPI GetContainerName(PBYTE pbLogonInfo);
  62. LPCTSTR WINAPI GetCSPName(PBYTE pbLogonInfo);
  63. //
  64. // Calls used by GINA to construct the blob that kerberos
  65. // and sclogon share.
  66. //
  67. PBYTE
  68. WINAPI
  69. ScBuildLogonInfo(
  70. LPCTSTR szCard,
  71. LPCTSTR szReader,
  72. LPCTSTR szContainer,
  73. LPCTSTR szCSP);
  74. //
  75. // Calls used by LSA
  76. //
  77. NTSTATUS WINAPI
  78. ScHelperInitializeContext(
  79. IN OUT PBYTE pbLogonInfo,
  80. IN ULONG cbLogonInfo
  81. );
  82. VOID WINAPI
  83. ScHelperRelease(
  84. IN PBYTE ppbLogonInfo
  85. );
  86. NTSTATUS WINAPI
  87. ScHelperGetProvParam(
  88. IN PUNICODE_STRING pucPIN,
  89. IN PBYTE pbLogonInfo,
  90. DWORD dwParam,
  91. BYTE*pbData,
  92. DWORD *pdwDataLen,
  93. DWORD dwFlags
  94. );
  95. // ScHelperGetCertFromLogonInfo may need the PIN to get a cert off certain SCs
  96. NTSTATUS WINAPI
  97. ScHelperGetCertFromLogonInfo(
  98. IN PBYTE pbLogonInfo,
  99. IN PUNICODE_STRING pucPIN,
  100. OUT PCCERT_CONTEXT * CertificateContext
  101. );
  102. // ScHelperVerifyCard uses SignMessage() and VerifyMessage() to verify the
  103. // card's integrity (that it has the keys it says it has)
  104. NTSTATUS WINAPI
  105. ScHelperVerifyCard(
  106. IN PUNICODE_STRING pucPIN,
  107. IN PCCERT_CONTEXT CertificateContext,
  108. IN HCERTSTORE hCertStore,
  109. IN PBYTE pbLogonInfo
  110. );
  111. // ScHelper*Cred* functions provide for a more secure offline experience
  112. NTSTATUS WINAPI
  113. ScHelperGenRandBits
  114. (
  115. IN PBYTE pbLogonInfo,
  116. IN ScHelper_RandomCredBits* psc_rcb
  117. );
  118. NTSTATUS WINAPI
  119. ScHelperCreateCredKeys
  120. (
  121. IN PUNICODE_STRING pucPIN,
  122. IN PBYTE pbLogonInfo,
  123. IN ScHelper_RandomCredBits* psc_rcb,
  124. IN OUT HCRYPTKEY* phHmacKey,
  125. IN OUT HCRYPTKEY* phRc4Key,
  126. IN OUT HCRYPTPROV* phProv
  127. );
  128. NTSTATUS WINAPI
  129. ScHelperCreateCredHMAC
  130. (
  131. IN HCRYPTPROV hProv,
  132. IN HCRYPTKEY hHmacKey,
  133. IN PBYTE CleartextData,
  134. IN ULONG CleartextDataSize,
  135. IN OUT PBYTE* ppbHmac,
  136. IN OUT DWORD* pdwHmacLen
  137. );
  138. NTSTATUS WINAPI
  139. ScHelperVerifyCardAndCreds(
  140. IN PUNICODE_STRING pucPIN,
  141. IN PCCERT_CONTEXT CertificateContext,
  142. IN HCERTSTORE hCertStore,
  143. IN PBYTE pbLogonInfo,
  144. IN PBYTE SignedEncryptedData,
  145. IN ULONG SignedEncryptedDataSize,
  146. OUT OPTIONAL PBYTE CleartextData,
  147. OUT PULONG CleartextDataSize
  148. );
  149. NTSTATUS WINAPI
  150. ScHelperEncryptCredentials(
  151. IN PUNICODE_STRING pucPIN,
  152. IN PCCERT_CONTEXT CertificateContext,
  153. IN HCERTSTORE hCertStore,
  154. IN ScHelper_RandomCredBits* psch_rcb,
  155. IN PBYTE pbLogonInfo,
  156. IN PBYTE CleartextData,
  157. IN ULONG CleartextDataSize,
  158. OUT OPTIONAL PBYTE EncryptedData,
  159. OUT PULONG EncryptedDataSize
  160. );
  161. NTSTATUS WINAPI
  162. ScHelperDecryptCredentials(
  163. IN PUNICODE_STRING pucPIN,
  164. IN PCCERT_CONTEXT CertificateContext,
  165. IN HCERTSTORE hCertStore,
  166. IN PBYTE pbLogonInfo,
  167. IN PBYTE EncryptedData,
  168. IN ULONG EncryptedDataSize,
  169. OUT OPTIONAL PBYTE CleartextData,
  170. OUT PULONG CleartextDataSize
  171. );
  172. //
  173. // The following two functions may be called in any order, and return a basic
  174. // "success" or "failure"
  175. //
  176. // ScHelperSignMessage() needs the logoninfo and PIN in order to find the card
  177. // that will do the signing...
  178. //
  179. NTSTATUS WINAPI
  180. ScHelperSignMessage(
  181. IN PUNICODE_STRING pucPIN,
  182. IN PBYTE pbLogonInfo,
  183. IN OPTIONAL HCRYPTPROV Provider,
  184. IN ULONG Algorithm,
  185. IN PBYTE Buffer,
  186. IN ULONG BufferLength,
  187. OUT PBYTE Signature,
  188. OUT PULONG SignatureLength
  189. );
  190. NTSTATUS WINAPI
  191. ScHelperSignPkcsMessage(
  192. IN OPTIONAL PUNICODE_STRING pucPIN,
  193. IN OPTIONAL PBYTE pbLogonInfo,
  194. IN OPTIONAL HCRYPTPROV Provider,
  195. IN PCCERT_CONTEXT Certificate,
  196. IN PCRYPT_ALGORITHM_IDENTIFIER Algorithm,
  197. IN OPTIONAL DWORD dwSignMessageFlags,
  198. IN PBYTE Buffer,
  199. IN ULONG BufferLength,
  200. OUT OPTIONAL PBYTE SignedBuffer,
  201. OUT OPTIONAL PULONG SignedBufferLength
  202. );
  203. //
  204. // ScHelperVerifyMessage() returns STATUS_SUCCESS if the signature provided is
  205. // the hash of the buffer encrypted by the owner of the cert.
  206. //
  207. NTSTATUS WINAPI
  208. ScHelperVerifyMessage(
  209. IN OPTIONAL PBYTE pbLogonInfo,
  210. IN OPTIONAL HCRYPTPROV Provider,
  211. IN PCCERT_CONTEXT CertificateContext,
  212. IN ULONG Algorithm,
  213. IN PBYTE Buffer,
  214. IN ULONG BufferLength,
  215. IN PBYTE Signature,
  216. IN ULONG SignatureLength
  217. );
  218. NTSTATUS WINAPI
  219. ScHelperVerifyPkcsMessage(
  220. IN OPTIONAL PBYTE pbLogonInfo,
  221. IN OPTIONAL HCRYPTPROV Provider,
  222. IN PBYTE Buffer,
  223. IN ULONG BufferLength,
  224. OUT OPTIONAL PBYTE DecodedBuffer,
  225. OUT OPTIONAL PULONG DecodedBufferLength,
  226. OUT OPTIONAL PCCERT_CONTEXT * CertificateContext
  227. );
  228. //
  229. // ScHelperEncryptMessage and ScHelperDecryptMessage
  230. // encrypt and decrypt buffer/cipher text using PKCS7 crypto stuff.
  231. //
  232. NTSTATUS WINAPI
  233. ScHelperEncryptMessage(
  234. IN OPTIONAL PBYTE pbLogonInfo,
  235. IN OPTIONAL HCRYPTPROV Provider,
  236. IN PCCERT_CONTEXT CertificateContext,
  237. IN PCRYPT_ALGORITHM_IDENTIFIER Algorithm,
  238. IN PBYTE Buffer, // The data to encrypt
  239. IN ULONG BufferLength, // The length of that data
  240. OUT PBYTE CipherText, // Receives the formatted CipherText
  241. IN PULONG pCipherLength // Supplies size of CipherText buffer
  242. ); // Receives length of actual CipherText
  243. NTSTATUS WINAPI
  244. ScHelperDecryptMessage(
  245. IN PUNICODE_STRING pucPIN,
  246. IN OPTIONAL PBYTE pbLogonInfo,
  247. IN OPTIONAL HCRYPTPROV Provider,
  248. IN PCCERT_CONTEXT CertificateContext,
  249. IN PBYTE CipherText, // Supplies formatted CipherText
  250. IN ULONG CipherLength, // Supplies the length of the CiperText
  251. OUT PBYTE ClearText, // Receives decrypted message
  252. IN OUT PULONG pClearLength // Supplies length of buffer, receives actual length
  253. );
  254. /////////////////////////////////////////////////////////////////////////////
  255. #ifdef __cplusplus
  256. }
  257. #endif
  258. #endif // __SCLOGON_H__