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.

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