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.

186 lines
7.0 KiB

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