Leaked source code of windows server 2003
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.

317 lines
7.8 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. // Helper for error translations
  64. NTSTATUS ScNtStatusTranslation(NTSTATUS NtErr, DWORD *pdwErr);
  65. //
  66. // Calls used by GINA to construct the blob that kerberos
  67. // and sclogon share.
  68. //
  69. PBYTE
  70. WINAPI
  71. ScBuildLogonInfo(
  72. LPCTSTR szCard,
  73. LPCTSTR szReader,
  74. LPCTSTR szContainer,
  75. LPCTSTR szCSP);
  76. //
  77. // Calls used by LSA
  78. //
  79. NTSTATUS WINAPI
  80. ScHelperInitializeContext(
  81. IN OUT PBYTE pbLogonInfo,
  82. IN ULONG cbLogonInfo
  83. );
  84. VOID WINAPI
  85. ScHelperRelease(
  86. IN PBYTE ppbLogonInfo
  87. );
  88. NTSTATUS WINAPI
  89. ScHelperGetProvParam(
  90. IN PUNICODE_STRING pucPIN,
  91. IN PBYTE pbLogonInfo,
  92. IN HCRYPTPROV hProv,
  93. DWORD dwParam,
  94. BYTE*pbData,
  95. DWORD *pdwDataLen,
  96. DWORD dwFlags
  97. );
  98. // ScHelperGetCertFromLogonInfo may need the PIN to get a cert off certain SCs
  99. NTSTATUS WINAPI
  100. ScHelperGetCertFromLogonInfo(
  101. IN PBYTE pbLogonInfo,
  102. IN PUNICODE_STRING pucPIN,
  103. OUT PCCERT_CONTEXT * CertificateContext
  104. );
  105. // ScHelperVerifyCard uses SignMessage() and VerifyMessage() to verify the
  106. // card's integrity (that it has the keys it says it has)
  107. NTSTATUS WINAPI
  108. ScHelperVerifyCard(
  109. IN PUNICODE_STRING pucPIN,
  110. IN PCCERT_CONTEXT CertificateContext,
  111. IN HCERTSTORE hCertStore,
  112. IN PBYTE pbLogonInfo
  113. );
  114. // ScHelper*Cred* functions provide for a more secure offline experience
  115. NTSTATUS WINAPI
  116. ScHelperGenRandBits
  117. (
  118. IN PBYTE pbLogonInfo,
  119. IN ScHelper_RandomCredBits* psc_rcb
  120. );
  121. NTSTATUS WINAPI
  122. ScHelperCreateCredKeys
  123. (
  124. IN PUNICODE_STRING pucPIN,
  125. IN PBYTE pbLogonInfo,
  126. IN ScHelper_RandomCredBits* psc_rcb,
  127. IN OUT HCRYPTKEY* phHmacKey,
  128. IN OUT HCRYPTKEY* phRc4Key,
  129. IN OUT HCRYPTPROV* phProv
  130. );
  131. NTSTATUS WINAPI
  132. ScHelperCreateCredHMAC
  133. (
  134. IN HCRYPTPROV hProv,
  135. IN HCRYPTKEY hHmacKey,
  136. IN PBYTE CleartextData,
  137. IN ULONG CleartextDataSize,
  138. IN OUT PBYTE* ppbHmac,
  139. IN OUT DWORD* pdwHmacLen
  140. );
  141. NTSTATUS WINAPI
  142. ScHelperVerifyCardAndCreds(
  143. IN PUNICODE_STRING pucPIN,
  144. IN PCCERT_CONTEXT CertificateContext,
  145. IN HCERTSTORE hCertStore,
  146. IN PBYTE pbLogonInfo,
  147. IN PBYTE SignedEncryptedData,
  148. IN ULONG SignedEncryptedDataSize,
  149. OUT OPTIONAL PBYTE CleartextData,
  150. OUT PULONG CleartextDataSize
  151. );
  152. NTSTATUS WINAPI
  153. ScHelperEncryptCredentials(
  154. IN PUNICODE_STRING pucPIN,
  155. IN PCCERT_CONTEXT CertificateContext,
  156. IN HCERTSTORE hCertStore,
  157. IN ScHelper_RandomCredBits* psch_rcb,
  158. IN PBYTE pbLogonInfo,
  159. IN PBYTE CleartextData,
  160. IN ULONG CleartextDataSize,
  161. OUT OPTIONAL PBYTE EncryptedData,
  162. OUT PULONG EncryptedDataSize
  163. );
  164. NTSTATUS WINAPI
  165. ScHelperDecryptCredentials(
  166. IN PUNICODE_STRING pucPIN,
  167. IN PCCERT_CONTEXT CertificateContext,
  168. IN HCERTSTORE hCertStore,
  169. IN PBYTE pbLogonInfo,
  170. IN PBYTE EncryptedData,
  171. IN ULONG EncryptedDataSize,
  172. OUT OPTIONAL PBYTE CleartextData,
  173. OUT PULONG CleartextDataSize
  174. );
  175. //
  176. // The following two functions may be called in any order, and return a basic
  177. // "success" or "failure"
  178. //
  179. // ScHelperSignMessage() needs the logoninfo and PIN in order to find the card
  180. // that will do the signing...
  181. //
  182. NTSTATUS WINAPI
  183. ScHelperSignMessage(
  184. IN PUNICODE_STRING pucPIN,
  185. IN PBYTE pbLogonInfo,
  186. IN OPTIONAL HCRYPTPROV Provider,
  187. IN ULONG Algorithm,
  188. IN PBYTE Buffer,
  189. IN ULONG BufferLength,
  190. OUT PBYTE Signature,
  191. OUT PULONG SignatureLength
  192. );
  193. NTSTATUS WINAPI
  194. ScHelperSignPkcsMessage(
  195. IN OPTIONAL PUNICODE_STRING pucPIN,
  196. IN OPTIONAL PBYTE pbLogonInfo,
  197. IN OPTIONAL HCRYPTPROV Provider,
  198. IN PCCERT_CONTEXT Certificate,
  199. IN PCRYPT_ALGORITHM_IDENTIFIER Algorithm,
  200. IN OPTIONAL DWORD dwSignMessageFlags,
  201. IN PBYTE Buffer,
  202. IN ULONG BufferLength,
  203. OUT OPTIONAL PBYTE SignedBuffer,
  204. OUT OPTIONAL PULONG SignedBufferLength
  205. );
  206. //
  207. // ScHelperVerifyMessage() returns STATUS_SUCCESS if the signature provided is
  208. // the hash of the buffer encrypted by the owner of the cert.
  209. //
  210. NTSTATUS WINAPI
  211. ScHelperVerifyMessage(
  212. IN OPTIONAL PBYTE pbLogonInfo,
  213. IN OPTIONAL HCRYPTPROV Provider,
  214. IN PCCERT_CONTEXT CertificateContext,
  215. IN ULONG Algorithm,
  216. IN PBYTE Buffer,
  217. IN ULONG BufferLength,
  218. IN PBYTE Signature,
  219. IN ULONG SignatureLength
  220. );
  221. NTSTATUS WINAPI
  222. ScHelperVerifyPkcsMessage(
  223. IN OPTIONAL PBYTE pbLogonInfo,
  224. IN OPTIONAL HCRYPTPROV Provider,
  225. IN PBYTE Buffer,
  226. IN ULONG BufferLength,
  227. OUT OPTIONAL PBYTE DecodedBuffer,
  228. OUT OPTIONAL PULONG DecodedBufferLength,
  229. OUT OPTIONAL PCCERT_CONTEXT * CertificateContext
  230. );
  231. //
  232. // ScHelperEncryptMessage and ScHelperDecryptMessage
  233. // encrypt and decrypt buffer/cipher text using PKCS7 crypto stuff.
  234. //
  235. NTSTATUS WINAPI
  236. ScHelperEncryptMessage(
  237. IN OPTIONAL PBYTE pbLogonInfo,
  238. IN OPTIONAL HCRYPTPROV Provider,
  239. IN PCCERT_CONTEXT CertificateContext,
  240. IN PCRYPT_ALGORITHM_IDENTIFIER Algorithm,
  241. IN PBYTE Buffer, // The data to encrypt
  242. IN ULONG BufferLength, // The length of that data
  243. OUT PBYTE CipherText, // Receives the formatted CipherText
  244. IN PULONG pCipherLength // Supplies size of CipherText buffer
  245. ); // Receives length of actual CipherText
  246. NTSTATUS WINAPI
  247. ScHelperDecryptMessage(
  248. IN PUNICODE_STRING pucPIN,
  249. IN OPTIONAL PBYTE pbLogonInfo,
  250. IN OPTIONAL HCRYPTPROV Provider,
  251. IN PCCERT_CONTEXT CertificateContext,
  252. IN PBYTE CipherText, // Supplies formatted CipherText
  253. IN ULONG CipherLength, // Supplies the length of the CiperText
  254. OUT PBYTE ClearText, // Receives decrypted message
  255. IN OUT PULONG pClearLength // Supplies length of buffer, receives actual length
  256. );
  257. /////////////////////////////////////////////////////////////////////////////
  258. #ifdef __cplusplus
  259. }
  260. #endif
  261. #endif // __SCLOGON_H__