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.

246 lines
7.0 KiB

  1. // V2KeyPair.cpp: implementation of the CV2KeyPair 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. #include "NoWarning.h"
  10. #include <scuCast.h>
  11. #include "slbCci.h"
  12. #include "cciCard.h"
  13. #include "TransactionWrap.h"
  14. #include "V2Cert.h"
  15. #include "V2PriKey.h"
  16. #include "V2PubKey.h"
  17. #include "V2Cont.h"
  18. #include "V2KeyPair.h"
  19. #include "ContainerInfoRecord.h"
  20. using namespace std;
  21. using namespace cci;
  22. /////////////////////////// LOCAL/HELPER /////////////////////////////////
  23. /////////////////////////// PUBLIC /////////////////////////////////
  24. // Types
  25. // C'tors/D'tors
  26. CV2KeyPair::CV2KeyPair(CV2Card const &rv2card,
  27. CContainer const &rhcont,
  28. KeySpec ks)
  29. : CAbstractKeyPair(rv2card, rhcont, ks),
  30. m_bPubKeyAccess(oaNoAccess),
  31. m_bPriKeyAccess(oaNoAccess),
  32. m_bCertificateAccess(oaNoAccess),
  33. m_bPubKeyHandle(0),
  34. m_bPriKeyHandle(0),
  35. m_bCertificateHandle(0)
  36. {
  37. CContainerInfoRecord &rcir =
  38. (scu::DownCast<CV2Container &,
  39. CAbstractContainer &>(*m_hcont)).CIR();
  40. rcir.Read();
  41. m_bPubKeyHandle = rcir.GetKeyPair(ks).bPubKeyHandle;
  42. m_bPriKeyHandle = rcir.GetKeyPair(ks).bPriKeyHandle;
  43. m_bCertificateHandle = rcir.GetKeyPair(ks).bCertificateHandle;
  44. m_bPubKeyAccess = rcir.GetKeyPair(ks).bPubKeyAccess;
  45. m_bPriKeyAccess = rcir.GetKeyPair(ks).bPriKeyAccess;
  46. m_bCertificateAccess = rcir.GetKeyPair(ks).bCertificateAccess;
  47. }
  48. CV2KeyPair::~CV2KeyPair() throw()
  49. {}
  50. // Operators
  51. // Operations
  52. // After I update any of these, I'd better be sure that the
  53. // key pair is marked as valid and that the indices in the
  54. // container are updated.
  55. void
  56. CV2KeyPair::Certificate(CCertificate const &rcert)
  57. {
  58. CTransactionWrap wrap(m_hcard);
  59. if (!rcert)
  60. {
  61. m_bCertificateAccess = oaNoAccess;
  62. m_bCertificateHandle = 0;
  63. }
  64. else
  65. {
  66. CV2Certificate const &rv2cert =
  67. scu::DownCast<CV2Certificate const &, CAbstractCertificate const &>(*rcert);
  68. m_bCertificateAccess = rv2cert.Access();
  69. m_bCertificateHandle = rv2cert.Handle();
  70. }
  71. Update();
  72. }
  73. void
  74. CV2KeyPair::PrivateKey(CPrivateKey const &rprikey)
  75. {
  76. CTransactionWrap wrap(m_hcard);
  77. if (!rprikey)
  78. {
  79. m_bPriKeyAccess = oaNoAccess;
  80. m_bPriKeyHandle = 0;
  81. }
  82. else
  83. {
  84. CV2PrivateKey const &rv2prikey =
  85. scu::DownCast<CV2PrivateKey const &, CAbstractPrivateKey const &>(*rprikey);
  86. m_bPriKeyAccess = rv2prikey.Access();
  87. m_bPriKeyHandle = rv2prikey.Handle();
  88. }
  89. Update();
  90. }
  91. void
  92. CV2KeyPair::PublicKey(CPublicKey const &rpubkey)
  93. {
  94. CTransactionWrap wrap(m_hcard);
  95. if (!rpubkey)
  96. {
  97. m_bPubKeyAccess = oaNoAccess;
  98. m_bPubKeyHandle = 0;
  99. }
  100. else
  101. {
  102. CV2PublicKey const &rv2pubkey =
  103. scu::DownCast<CV2PublicKey const &, CAbstractPublicKey const &>(*rpubkey);
  104. m_bPubKeyAccess = rv2pubkey.Access();
  105. m_bPubKeyHandle = rv2pubkey.Handle();
  106. }
  107. Update();
  108. }
  109. // Access
  110. CCertificate
  111. CV2KeyPair::Certificate() const
  112. {
  113. CTransactionWrap wrap(m_hcard);
  114. CCertificate aCert;
  115. if (m_bCertificateHandle)
  116. {
  117. CV2Card const &rv2card =
  118. scu::DownCast<CV2Card &, CAbstractCard &>(*m_hcard);
  119. aCert = CCertificate(CV2Certificate::Make(rv2card,
  120. m_bCertificateHandle,
  121. m_bCertificateAccess));
  122. }
  123. else
  124. aCert = CCertificate();
  125. return aCert;
  126. }
  127. CPrivateKey
  128. CV2KeyPair::PrivateKey() const
  129. {
  130. CTransactionWrap wrap(m_hcard);
  131. CPrivateKey aKey;
  132. if (m_bPriKeyHandle)
  133. {
  134. CV2Card const &rv2card =
  135. scu::DownCast<CV2Card &, CAbstractCard &>(*m_hcard);
  136. aKey = CPrivateKey(CV2PrivateKey::Make(rv2card, m_bPriKeyHandle,
  137. m_bPriKeyAccess));
  138. }
  139. else
  140. aKey = CPrivateKey();
  141. return aKey;
  142. }
  143. CPublicKey
  144. CV2KeyPair::PublicKey() const
  145. {
  146. CTransactionWrap wrap(m_hcard);
  147. CPublicKey aKey;
  148. if (m_bPubKeyHandle)
  149. {
  150. CV2Card const &rv2card =
  151. scu::DownCast<CV2Card &, CAbstractCard &>(*m_hcard);
  152. aKey = CPublicKey(CV2PublicKey::Make(rv2card, m_bPubKeyHandle,
  153. m_bPubKeyAccess));
  154. }
  155. else
  156. aKey = CPublicKey();
  157. return aKey;
  158. }
  159. // Predicates
  160. bool
  161. CV2KeyPair::DoEquals(CAbstractKeyPair const &rhs) const
  162. {
  163. CV2KeyPair const &rv2rhs =
  164. scu::DownCast<CV2KeyPair const &, CAbstractKeyPair const &>(rhs);
  165. return (rv2rhs.m_bPubKeyAccess == m_bPubKeyAccess) &&
  166. (rv2rhs.m_bPriKeyAccess == m_bPriKeyAccess) &&
  167. (rv2rhs.m_bCertificateAccess == m_bCertificateAccess) &&
  168. (rv2rhs.m_bPubKeyHandle == m_bPubKeyHandle) &&
  169. (rv2rhs.m_bPriKeyHandle == m_bPriKeyHandle) &&
  170. (rv2rhs.m_bCertificateHandle == m_bCertificateHandle);
  171. }
  172. // Static Variables
  173. /////////////////////////// PROTECTED /////////////////////////////////
  174. // C'tors/D'tors
  175. // Operators
  176. // Operations
  177. // Access
  178. // Predicates
  179. // Static Variables
  180. /////////////////////////// PRIVATE /////////////////////////////////
  181. // C'tors/D'tors
  182. // Operators
  183. // Operations
  184. void
  185. CV2KeyPair::Update()
  186. {
  187. KPItems kp;
  188. kp.bPubKeyAccess = m_bPubKeyAccess;
  189. kp.bPriKeyAccess = m_bPriKeyAccess;
  190. kp.bCertificateAccess = m_bCertificateAccess;
  191. kp.bPubKeyHandle = m_bPubKeyHandle;
  192. kp.bPriKeyHandle = m_bPriKeyHandle;
  193. kp.bCertificateHandle = m_bCertificateHandle;
  194. CContainerInfoRecord &rcir =
  195. (scu::DownCast<CV2Container &,
  196. CAbstractContainer &>(*m_hcont)).CIR();
  197. rcir.SetKeyPair(m_ks, kp);
  198. }
  199. // Access
  200. // Predicates
  201. // Static Variables