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.

216 lines
5.7 KiB

  1. // CardFinder.h -- CardFinder class header
  2. // (c) Copyright Schlumberger Technology Corp., unpublished work, created
  3. // 1999. This computer program includes Confidential, Proprietary
  4. // Information and is a Trade Secret of Schlumberger Technology Corp. All
  5. // use, disclosure, and/or reproduction is prohibited unless authorized
  6. // in writing. All Rights Reserved.
  7. #if !defined(SLBCSP_CARDFINDER_H)
  8. #define SLBCSP_CARDFINDER_H
  9. #if defined(_UNICODE)
  10. #if !defined(UNICODE)
  11. #define UNICODE
  12. #endif //!UNICODE
  13. #endif //_UNICODE
  14. #if defined(UNICODE)
  15. #if !defined(_UNICODE)
  16. #define _UNICODE
  17. #endif //!_UNICODE
  18. #endif //UNICODE
  19. #include <string>
  20. #include <memory> // for auto_ptr
  21. #include <windef.h>
  22. #include <scuOsVersion.h>
  23. #include "StResource.h"
  24. #include "HSCardCtx.h"
  25. #include "cspec.h"
  26. #include "HCardCtx.h"
  27. #include "Secured.h"
  28. #include "MultiStrZ.h"
  29. #include "ExceptionContext.h"
  30. #if defined(SLB_NOWIN2K_BUILD)
  31. #define SLBCSP_USE_SCARDUIDLGSELECTCARD 0
  32. #else
  33. #define SLBCSP_USE_SCARDUIDLGSELECTCARD 1
  34. #endif
  35. class CardFinder
  36. : protected ExceptionContext
  37. {
  38. friend class OpenCardCallbackContext; // for Do* routines
  39. public:
  40. // Types
  41. enum DialogDisplayMode
  42. {
  43. ddmNever,
  44. ddmIfNecessary,
  45. ddmAlways
  46. };
  47. // C'tors/D'tors
  48. CardFinder(DialogDisplayMode ddm,
  49. HWND hwnd = 0,
  50. CString const &rsDialogTitle = StringResource(IDS_SEL_SLB_CRYPTO_CARD).AsCString());
  51. virtual
  52. ~CardFinder();
  53. // Operators
  54. // Operations
  55. Secured<HCardContext>
  56. Find(CSpec const &rsReader);
  57. // Access
  58. DialogDisplayMode
  59. DisplayMode() const;
  60. HWND
  61. Window() const;
  62. // Predicates
  63. // Static Variables
  64. protected:
  65. // Note: CardFinder uses GetOpenCardName/SCardUIDlgSelect to find
  66. // the card. These routines do not propagate exception thrown by
  67. // the callback routines. To throw these exceptions from
  68. // CardFinder and its derived classes, a set of wrapper callback
  69. // routines Connect, Disconnect and IsValid are defined for
  70. // DoConnect, DoDisconnect, and DoIsValid (repectively) which catch
  71. // exceptions thrown by these Do routines and set the
  72. // CallbackException attribute. When control is returned from
  73. // GetOpenCardName/SCardUIDlgSelect, the DoOnError routine is
  74. // called. If a callback exception still exists, then the
  75. // exception is propagated to the caller of CardFinder class.
  76. // Types
  77. #if !SLBCSP_USE_SCARDUIDLGSELECTCARD
  78. typedef OPENCARDNAME OpenCardNameType;
  79. #else
  80. typedef OPENCARDNAME_EX OpenCardNameType;
  81. #endif
  82. // C'tors/D'tors
  83. // Operators
  84. // Operations
  85. void
  86. CardFound(Secured<HCardContext> const &rshcardctx);
  87. virtual SCARDHANDLE
  88. DoConnect(std::string const &rsSelectedReader);
  89. virtual void
  90. DoDisconnect();
  91. void
  92. DoFind(CSpec const &rcspec);
  93. virtual void
  94. DoOnError();
  95. virtual void
  96. DoProcessSelection(DWORD dwStatus,
  97. OpenCardNameType &ropencardname,
  98. bool &rfContinue);
  99. void
  100. YNPrompt(UINT uID) const;
  101. // Access
  102. CSpec const &
  103. CardSpec() const;
  104. Secured<HCardContext>
  105. CardFound() const;
  106. // Predicates
  107. virtual bool
  108. DoIsValid();
  109. // Variables
  110. private:
  111. // Types
  112. // C'tors/D'tors
  113. // Operators
  114. // Operations
  115. void
  116. CheckFn(LPOCNCHKPROC lpfnCheck);
  117. static SCARDHANDLE __stdcall
  118. Connect(SCARDCONTEXT scardctx,
  119. LPTSTR szReader,
  120. LPTSTR mszCards,
  121. LPVOID lpvUserData);
  122. void
  123. ConnectFn(LPOCNCONNPROC lpfnConnect);
  124. static void __stdcall
  125. Disconnect(SCARDCONTEXT scardctx,
  126. SCARDHANDLE hSCard,
  127. LPVOID lpvUserData);
  128. void
  129. DisconnectFn(LPOCNDSCPROC lpfnDisconnect);
  130. void
  131. OnError();
  132. DWORD
  133. SelectCard(OpenCardNameType &ropcn);
  134. void
  135. UserData(void *pvUserData);
  136. void
  137. WorkaroundOpenCardDefect(OpenCardNameType const &ropcnDlgCtrl,
  138. DWORD &rdwStatus);
  139. // Access
  140. LPOCNCHKPROC
  141. CheckFn() const;
  142. LPOCNDSCPROC
  143. DisconnectFn() const;
  144. // Predicates
  145. static BOOL __stdcall
  146. IsValid(SCARDCONTEXT scardctx,
  147. SCARDHANDLE hSCard,
  148. LPVOID lpvUserData);
  149. // Variables
  150. CString const m_sDialogTitle;
  151. DialogDisplayMode const m_ddm;
  152. HWND const m_hwnd;
  153. std::auto_ptr<MultiStringZ> m_apmszSupportedCards;
  154. OpenCardNameType m_opcnDlgCtrl;
  155. #if SLBCSP_USE_SCARDUIDLGSELECTCARD
  156. OPENCARD_SEARCH_CRITERIA m_opcnCriteria;
  157. CString m_sInsertPrompt;
  158. #endif
  159. CSpec m_cspec;
  160. HSCardContext m_hscardctx;
  161. Secured<HCardContext> m_shcardctx;
  162. };
  163. #endif // SLBCSP_CARDFINDER_H