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.

250 lines
6.7 KiB

  1. // ACard.h: interface for the CAbstractCard class.
  2. //
  3. // (c) Copyright Schlumberger Technology Corp., unpublished work, created
  4. // 1999. This computer program includes Confidential, Proprietary
  5. // Information and is a Trade Secret of Schlumberger Technology Corp. All
  6. // use, disclosure, and/or reproduction is prohibited unless authorized
  7. // in writing. All Rights Reserved.
  8. //////////////////////////////////////////////////////////////////////
  9. // Note: This file should only be included by the CCI, not directly
  10. // by the client.
  11. #if !defined(SLBCCI_ACARD_H)
  12. #define SLBCCI_ACARD_H
  13. #include <functional>
  14. #include <string>
  15. #include <memory> // for auto_ptr
  16. #include <vector>
  17. #include <utility> // for pair
  18. #include <stddef.h> // for size_t
  19. #include <iop.h>
  20. #include <slbRCObj.h>
  21. #include "slbCci.h"
  22. #include "CryptFctry.h"
  23. #include "Marker.h"
  24. namespace cci
  25. {
  26. class CCard;
  27. class CCertificate;
  28. class CContainer;
  29. class CDataObject;
  30. class CPrivateKey;
  31. class CPublicKey;
  32. class CAbstractCard
  33. : public slbRefCnt::RCObject,
  34. protected CCryptFactory
  35. {
  36. // To access factory methods
  37. friend class CContainer;
  38. friend class CCertificate;
  39. friend class CDataObject;
  40. friend class CKeyPair;
  41. friend class CPrivateKey;
  42. friend class CPublicKey;
  43. public:
  44. // Types
  45. // C'tors/D'tors
  46. virtual
  47. ~CAbstractCard() throw();
  48. // Operators
  49. virtual bool
  50. operator==(CAbstractCard const &rhs) const;
  51. // TO DO: this should be superceded by implementing singletons
  52. virtual bool
  53. operator!=(CAbstractCard const &rhs) const;
  54. // TO DO: this should be superceded by implementing singletons
  55. // Operations
  56. void
  57. AuthenticateUser(std::string const &rstrPIN);
  58. virtual void
  59. ChangePIN(std::string const &rstrOldPIN,
  60. std::string const &rstrNewPIN);
  61. virtual void
  62. DefaultContainer(CContainer const &rcont) = 0;
  63. virtual std::pair<std::string, // interpreted as the public modulus
  64. cci::CPrivateKey>
  65. GenerateKeyPair(KeyType kt,
  66. std::string const &rsExponent,
  67. ObjectAccess oaPrivateKey = oaPrivateAccess) = 0;
  68. virtual void
  69. InitCard() = 0;
  70. virtual void
  71. InvalidateCache() = 0;
  72. virtual void
  73. Label(std::string const &rstrLabel) = 0;
  74. void
  75. Logout();
  76. static CAbstractCard *
  77. Make(std::string const &rstrReader);
  78. virtual void
  79. SetUserPIN(std::string const &rstrPin);
  80. virtual void
  81. VerifyKey(std::string const &rstrKey,
  82. BYTE bKeyNum);
  83. virtual void
  84. VerifyTransportKey(std::string const &rstrKey);
  85. void
  86. GenRandom(DWORD dwNumBytes, BYTE *bpRand);
  87. // Access
  88. virtual size_t
  89. AvailableStringSpace(ObjectAccess oa) const = 0;
  90. SCardType
  91. CardType();
  92. virtual CContainer
  93. DefaultContainer() const = 0;
  94. std::vector<CCertificate>
  95. EnumCertificates() const;
  96. virtual std::vector<CContainer>
  97. EnumContainers() const = 0;
  98. std::vector<CDataObject>
  99. EnumDataObjects() const;
  100. std::vector<CPrivateKey>
  101. EnumPrivateKeys() const;
  102. std::vector<CPublicKey>
  103. EnumPublicKeys() const;
  104. virtual std::vector<CCertificate>
  105. EnumCertificates(ObjectAccess access) const = 0;
  106. virtual std::vector<CPublicKey>
  107. EnumPublicKeys(ObjectAccess access) const = 0;
  108. virtual std::vector<CPrivateKey>
  109. EnumPrivateKeys(ObjectAccess access) const = 0;
  110. virtual std::vector<CDataObject>
  111. EnumDataObjects(ObjectAccess access) const = 0;
  112. virtual std::string
  113. Label() const = 0;
  114. iop::CMarker
  115. Marker(iop::CMarker::MarkerType const &Type) const;
  116. virtual BYTE
  117. MaxKeys(KeyType kt) const = 0;
  118. virtual size_t
  119. MaxStringSpace(ObjectAccess oa) const = 0;
  120. std::string
  121. ReaderName() const;
  122. iop::CSmartCard &
  123. SmartCard() const; // this should be protected
  124. virtual bool
  125. SupportedKeyFunction(KeyType kt,
  126. CardOperation oper) const = 0;
  127. // Predicates
  128. virtual bool
  129. IsCAPIEnabled() const = 0;
  130. bool
  131. IsAvailable() const;
  132. virtual bool
  133. IsPKCS11Enabled() const = 0;
  134. virtual bool
  135. IsEntrustEnabled() const = 0;
  136. virtual bool
  137. IsProtectedMode() const = 0;
  138. virtual bool
  139. IsKeyGenEnabled() const = 0;
  140. virtual BYTE
  141. MajorVersion() const = 0;
  142. protected:
  143. // Types
  144. // C'tors/D'tors
  145. CAbstractCard(std::string const &rstrReaderName,
  146. std::auto_ptr<iop::CIOP> &rapiop,
  147. std::auto_ptr<iop::CSmartCard> &rapSmartCard);
  148. // Note: To avoid memory leaks in the event of an exception,
  149. // CIOP and CSmartCard are passed as a reference to a
  150. // non-const auto_ptr so the constructed object can take
  151. // ownership responsibilities of the resource.
  152. // Operators
  153. // Operations
  154. virtual void
  155. DoSetup();
  156. static std::auto_ptr<CAbstractCard>
  157. DoMake(std::string const &rstrReaderName,
  158. std::auto_ptr<iop::CIOP> &rapiop,
  159. std::auto_ptr<iop::CSmartCard> &rapSmartCard);
  160. // not defined, should be defined by specializations
  161. // See note on constructor regarding rapiop and rapSmartCard.
  162. // Access
  163. // Predicates
  164. // Variables
  165. private:
  166. // Types
  167. // C'tors/D'tors
  168. CAbstractCard(CAbstractCard const &rhs);
  169. // not defined, copy not allowed.
  170. // Operators
  171. CAbstractCard &
  172. operator=(CAbstractCard const &rhs);
  173. // not defined, initialization not allowed.
  174. // Operations
  175. void
  176. Setup();
  177. // Access
  178. // Predicates
  179. // Variables
  180. std::string m_strReaderName;
  181. std::auto_ptr<iop::CIOP> m_apiop;
  182. std::auto_ptr<iop::CSmartCard> m_apSmartCard;
  183. };
  184. }
  185. #endif // !defined(SLBCCI_ACARD_H)