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.

202 lines
7.5 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 2001
  3. Module Name:
  4. pincache.h
  5. Abstract:
  6. Pin Caching Library for Smart Card CSP's
  7. Author:
  8. Dan Griffin
  9. --*/
  10. #ifndef __PINCACHE__H__
  11. #define __PINCACHE__H__
  12. #include <windows.h>
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. /*+-----------------------------------------------------------------------*\
  17. PINCACHE_HANDLE
  18. Handle to pin cache data. Should be initialized to NULL.
  19. CSP should keep one PINCACHE_HANDLE per available card. For instance, two
  20. HCRYPTPROV handles open for the same card should reference the same pin
  21. cache handle. If multiple cards are simultaneously available on the system,
  22. the CSP should have a separate cache handle for each.
  23. No thread synchronization is provided by functions in this module when accessing
  24. pin cache data.
  25. \*------------------------------------------------------------------------*/
  26. typedef LPVOID PINCACHE_HANDLE;
  27. /*+-----------------------------------------------------------------------*\
  28. PINCACHE_PINS
  29. Pin struct to be populated by the CSP and passed to PinCacheAdd.
  30. This struct is used in two different ways:
  31. 1) When simply caching a pin, such as in response to a CryptSetProvParam
  32. PP_KEYEXCHANGE_PIN call, the pin and its length should be set in the
  33. pbCurrentPin and cbCurrentPin parameters, respectively. In this case,
  34. cbNewPin must be zero and pbNewPin must be NULL.
  35. 2) When updating the cache in response to a user pin-change event,
  36. the new pin and its length should be set in the pbNewPin and cbNewPin
  37. parameters. The current pin and its length should be set in the
  38. pbCurrentPin and cbCurrentPin parameters.
  39. In cases when the PFN_VERIFYPIN_CALLBACK is called (see below), this struct
  40. will be passed to that function without modification (its members will not
  41. be changed by PinCacheAdd).
  42. \*------------------------------------------------------------------------*/
  43. typedef struct _PINCACHE_PINS
  44. {
  45. DWORD cbCurrentPin;
  46. PBYTE pbCurrentPin;
  47. DWORD cbNewPin;
  48. PBYTE pbNewPin;
  49. } PINCACHE_PINS, *PPINCACHE_PINS;
  50. /*+-----------------------------------------------------------------------*\
  51. PFN_VERIFYPIN_CALLBACK
  52. Signature for function used by PinCacheAdd in certain cases to verify that
  53. the supplied pin is correct.
  54. The callback is used any time the cached pin is to be updated.
  55. If pbNewPin is not NULL, this is a change-pin scenario. Otherwise, this
  56. is a verify-pin scenario.
  57. The pvCallbackCtx is always passed to the callback without modification.
  58. It is assumed to be context information required by the CSP.
  59. \*------------------------------------------------------------------------*/
  60. typedef DWORD (WINAPI *PFN_VERIFYPIN_CALLBACK)(
  61. IN PPINCACHE_PINS pPins,
  62. IN PVOID pvCallbackCtx);
  63. /*+-----------------------------------------------------------------------*\
  64. PinCacheFlush
  65. Cleanup and delete the cache.
  66. CSP should call this function in the following situations:
  67. 1) The card for which this PINCACHE_HANDLE applies has been removed.
  68. 2) The CSP detects that card data has been modified by another process. For
  69. example, the pin has been changed.
  70. \*------------------------------------------------------------------------*/
  71. void WINAPI PinCacheFlush(
  72. IN PINCACHE_HANDLE *phCache);
  73. /*+-----------------------------------------------------------------------*\
  74. PinCacheAdd
  75. Cache a pin.
  76. CSP should call PinCacheAdd in response to CryptSetProvParam
  77. PP_KEYEXCHANGE_PIN and within all pin-related UI from the CSP (including
  78. pin-change and verification).
  79. This function exhibits the following behavior in these scenarios. The flow
  80. of this description continues through each case until you encounter a
  81. "return" value.
  82. If a pin is currently cached (the cache has been initialized) and the
  83. currently cached pin does not match pPins->pbCurrentPin,
  84. SCARD_W_WRONG_CHV is returned. Otherwise, continue.
  85. "Pin Decision"
  86. If the pPins->pbNewPin parameter is non-NULL, that pin will be added to the cache
  87. in cases where the cache is modified, below. This case indicates
  88. a pin-change. Otherwise, the pPins->pbCurrentPin will be cached.
  89. If pPins->pbNewPin is non-NULL, or the cache has not been initialized,
  90. pfnVerifyPinCallback is called. If the callback fails, PinCacheAdd
  91. immediately returns with the value returned by the callback.
  92. "Uninitialized Cache"
  93. For uninitialized cache, the appropriate pin (per "Pin Decision," above)
  94. is cached with the current Logon ID. Return ERROR_SUCCESS.
  95. "Initialized Cache"
  96. If the current Logon ID is different from the cached Logon ID, then the new
  97. Logon ID is cached in place of the currently cached Logon ID. If the currently
  98. cached pin is different from the pin to be cached (per "Pin Decision," above),
  99. then the cached pin is replaced. Return ERROR_SUCCESS.
  100. \*------------------------------------------------------------------------*/
  101. DWORD WINAPI PinCacheAdd(
  102. IN PINCACHE_HANDLE *phCache,
  103. IN PPINCACHE_PINS pPins,
  104. IN PFN_VERIFYPIN_CALLBACK pfnVerifyPinCallback,
  105. IN PVOID pvCallbackCtx);
  106. /*+-----------------------------------------------------------------------*\
  107. PinCacheQuery
  108. Retrieve a cached pin.
  109. If the cache is not initialized, *pcbPin is set to zero and ERROR_EMPTY
  110. is returned.
  111. If the cache is initialized, PinCacheQuery implements the following behaviors:
  112. 1) If the current Logon ID is different from the cached Logon ID, *pcbPin is
  113. set to zero and ERROR_SUCCESS is returned.
  114. 2) If the current Logon ID is the same as the cached Logon ID, the following
  115. tests are made:
  116. If pbPin is NULL, *pcbPin is set to the size of the currently cached pin and
  117. ERROR_SUCCESS is returned.
  118. If pbPin is non-NULL and *pcbPin is smaller than the size of the currently
  119. cached pin, *pcbPin is set to the size of the currently cached pin and
  120. ERROR_MORE_DATA is returned.
  121. If pbPin is non-NULL and *pcbPin is at least the size of the currently cached
  122. pin, then *pcbPin is set to the size of the currently cached pin, the cached
  123. pin is copied into pbPin, and ERROR_SUCCESS is returned.
  124. \*------------------------------------------------------------------------*/
  125. DWORD WINAPI PinCacheQuery(
  126. IN PINCACHE_HANDLE hCache,
  127. IN OUT PBYTE pbPin,
  128. IN OUT PDWORD pcbPin);
  129. /*+-----------------------------------------------------------------------*\
  130. PinCachePresentPin
  131. Request a cached pin via a callback.
  132. If the cache is not initialized, ERROR_EMPTY is returned.
  133. If the cache is initialized, PinCachePresentPin implements the following
  134. behavior:
  135. 1) If the current Logon ID is different from the cached Logon ID,
  136. SCARD_W_CARD_NOT_AUTHENTICATED is returned and the callback is not invoked.
  137. 2) If the current Logon ID is the same as the cached Logon ID, then a PINCACHE_PINS
  138. structure is initialized as follows. The cbCurrentPin and pbCurrentPin members
  139. are set to the values of the currently cached pin. The pbNewPin and cbNewPin
  140. members are zero'd. The pfnVerifyPinCallback is then invoked with the PINCACHE_PINS
  141. structure and the pvCallbackCtx parameter as arguments.
  142. PinCachePresentPin returns the value returned by pfnVerifyPinCallback.
  143. \*------------------------------------------------------------------------*/
  144. DWORD WINAPI PinCachePresentPin(
  145. IN PINCACHE_HANDLE hCache,
  146. IN PFN_VERIFYPIN_CALLBACK pfnVerifyPinCallback,
  147. IN PVOID pvCallbackCtx);
  148. #ifdef __cplusplus
  149. } // Balance extern "C" above
  150. #endif
  151. #endif