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.

414 lines
7.2 KiB

  1. // V1PriKey.cpp: implementation of the CV1PriKey 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 <scuCast.h>
  10. #include <iopPriBlob.h>
  11. #include "cciExc.h"
  12. #include "cciCard.h"
  13. #include "TransactionWrap.h"
  14. #include "V1Cont.h"
  15. #include "V1ContRec.h"
  16. #include "V1PriKey.h"
  17. using namespace std;
  18. using namespace cci;
  19. /////////////////////////// LOCAL/HELPER /////////////////////////////////
  20. /////////////////////////// PUBLIC /////////////////////////////////
  21. // Types
  22. // C'tors/D'tors
  23. CV1PrivateKey::CV1PrivateKey(CV1Card const &rv1card,
  24. KeySpec ks)
  25. : CAbstractPrivateKey(rv1card, oaPrivateAccess),
  26. m_ks(ks),
  27. m_apKeyBlob()
  28. {}
  29. CV1PrivateKey::~CV1PrivateKey()
  30. {}
  31. // Operators
  32. // Operations
  33. void
  34. CV1PrivateKey::AssociateWith(KeySpec ks)
  35. {
  36. CTransactionWrap wrap(m_hcard);
  37. m_ks = ks;
  38. Store();
  39. }
  40. void
  41. CV1PrivateKey::CredentialID(string const &rstrID)
  42. {
  43. throw Exception(ccNotImplemented);
  44. }
  45. void
  46. CV1PrivateKey::Decrypt(bool flag)
  47. {
  48. throw Exception(ccNotImplemented);
  49. }
  50. void
  51. CV1PrivateKey::Derive(bool flag)
  52. {
  53. throw Exception(ccNotImplemented);
  54. }
  55. void
  56. CV1PrivateKey::EndDate(Date const &rEndDate)
  57. {
  58. throw Exception(ccNotImplemented);
  59. }
  60. void
  61. CV1PrivateKey::Exportable(bool flag)
  62. {
  63. throw Exception(ccNotImplemented);
  64. }
  65. void
  66. CV1PrivateKey::ID(string const &rstrID)
  67. {
  68. throw Exception(ccNotImplemented);
  69. }
  70. string
  71. CV1PrivateKey::InternalAuth(string const &rstrOld)
  72. {
  73. CTransactionWrap wrap(m_hcard);
  74. CV1Card &rv1card =
  75. scu::DownCast<CV1Card &, CAbstractCard &>(*m_hcard);
  76. CV1ContainerRecord CntrRec(rv1card,
  77. CV1ContainerRecord::DefaultName(),
  78. CV1ContainerRecord::cmNever);
  79. return CntrRec.ComputeSignature(m_ks, rstrOld);
  80. }
  81. void
  82. CV1PrivateKey::Label(string const &rstrLabel)
  83. {
  84. throw Exception(ccNotImplemented);
  85. }
  86. void
  87. CV1PrivateKey::Local(bool flag)
  88. {
  89. throw Exception(ccNotImplemented);
  90. }
  91. CV1PrivateKey *
  92. CV1PrivateKey::Make(CV1Card const &rv1card,
  93. KeySpec ks)
  94. {
  95. CTransactionWrap wrap(rv1card);
  96. return new CV1PrivateKey(rv1card, ks);
  97. }
  98. void
  99. CV1PrivateKey::Modifiable(bool flag)
  100. {
  101. throw Exception(ccNotImplemented);
  102. }
  103. void
  104. CV1PrivateKey::Modulus(string const &rstrModulus)
  105. {
  106. throw Exception(ccNotImplemented);
  107. }
  108. void
  109. CV1PrivateKey::NeverExportable(bool flag)
  110. {
  111. throw Exception(ccNotImplemented);
  112. }
  113. void
  114. CV1PrivateKey::NeverRead(bool flag)
  115. {
  116. throw Exception(ccNotImplemented);
  117. }
  118. void
  119. CV1PrivateKey::PublicExponent(string const &rstrExponent)
  120. {
  121. throw Exception(ccNotImplemented);
  122. }
  123. void
  124. CV1PrivateKey::Read(bool flag)
  125. {
  126. throw Exception(ccNotImplemented);
  127. }
  128. void
  129. CV1PrivateKey::Sign(bool flag)
  130. {
  131. throw Exception(ccNotImplemented);
  132. }
  133. void
  134. CV1PrivateKey::SignRecover(bool flag)
  135. {
  136. throw Exception(ccNotImplemented);
  137. }
  138. void
  139. CV1PrivateKey::StartDate(Date &rdtStart)
  140. {
  141. throw Exception(ccNotImplemented);
  142. }
  143. void
  144. CV1PrivateKey::Subject(string const &rstrSubject)
  145. {
  146. throw Exception(ccNotImplemented);
  147. }
  148. void
  149. CV1PrivateKey::Unwrap(bool flag)
  150. {
  151. throw Exception(ccNotImplemented);
  152. }
  153. // Access
  154. string
  155. CV1PrivateKey::CredentialID()
  156. {
  157. throw Exception(ccNotImplemented);
  158. return string();
  159. }
  160. bool
  161. CV1PrivateKey::Decrypt()
  162. {
  163. return true;
  164. }
  165. bool
  166. CV1PrivateKey::Derive()
  167. {
  168. return true;
  169. }
  170. Date
  171. CV1PrivateKey::EndDate()
  172. {
  173. throw Exception(ccNotImplemented);
  174. return Date();
  175. }
  176. bool
  177. CV1PrivateKey::Exportable()
  178. {
  179. return false;
  180. }
  181. string
  182. CV1PrivateKey::ID()
  183. {
  184. throw Exception(ccNotImplemented);
  185. return string();
  186. }
  187. string
  188. CV1PrivateKey::Label()
  189. {
  190. throw Exception(ccNotImplemented);
  191. return string();
  192. }
  193. bool
  194. CV1PrivateKey::Local()
  195. {
  196. throw Exception(ccNotImplemented);
  197. return false;
  198. }
  199. bool
  200. CV1PrivateKey::Modifiable()
  201. {
  202. return true;
  203. }
  204. string
  205. CV1PrivateKey::Modulus()
  206. {
  207. throw Exception(ccNotImplemented);
  208. return string();
  209. }
  210. bool
  211. CV1PrivateKey::NeverExportable()
  212. {
  213. return true;
  214. }
  215. bool
  216. CV1PrivateKey::NeverRead()
  217. {
  218. return true;
  219. }
  220. bool
  221. CV1PrivateKey::Private()
  222. {
  223. return true;
  224. }
  225. string
  226. CV1PrivateKey::PublicExponent()
  227. {
  228. throw Exception(ccNotImplemented);
  229. }
  230. bool
  231. CV1PrivateKey::Read()
  232. {
  233. return false;
  234. }
  235. bool
  236. CV1PrivateKey::Sign()
  237. {
  238. return true;
  239. }
  240. bool
  241. CV1PrivateKey::SignRecover()
  242. {
  243. return true;
  244. }
  245. Date
  246. CV1PrivateKey::StartDate()
  247. {
  248. throw Exception(ccNotImplemented);
  249. return Date();
  250. }
  251. string
  252. CV1PrivateKey::Subject()
  253. {
  254. throw Exception(ccNotImplemented);
  255. return string();
  256. }
  257. bool
  258. CV1PrivateKey::Unwrap()
  259. {
  260. return true;
  261. }
  262. // Predicates
  263. // Static Variables
  264. /////////////////////////// PROTECTED /////////////////////////////////
  265. // C'tors/D'tors
  266. // Operators
  267. bool
  268. CV1PrivateKey::DoEquals(CAbstractPrivateKey const &rhs) const
  269. {
  270. CV1PrivateKey const &rv1rhs =
  271. scu::DownCast<CV1PrivateKey const &, CAbstractPrivateKey const &>(rhs);
  272. return rv1rhs.m_ks == m_ks;
  273. }
  274. // Operations
  275. void
  276. CV1PrivateKey::DoDelete()
  277. {
  278. // nothing to do.
  279. }
  280. void
  281. CV1PrivateKey::DoWriteKey(CPrivateKeyBlob const &rblob)
  282. {
  283. // cache to potentially store later
  284. m_apKeyBlob =
  285. auto_ptr<CPrivateKeyBlob>(new CPrivateKeyBlob(rblob));
  286. if (ksNone != m_ks)
  287. Store();
  288. }
  289. // Access
  290. // Predicates
  291. // Static Variables
  292. /////////////////////////// PRIVATE /////////////////////////////////
  293. // C'tors/D'tors
  294. // Operators
  295. // Operations
  296. void
  297. CV1PrivateKey::Store()
  298. {
  299. if (ksNone != m_ks)
  300. {
  301. if (m_apKeyBlob.get())
  302. {
  303. CV1Card &rv1card =
  304. scu::DownCast<CV1Card &, CAbstractCard &>(*m_hcard);
  305. CV1ContainerRecord CntrRec(rv1card,
  306. CV1ContainerRecord::DefaultName(),
  307. CV1ContainerRecord::cmNever);
  308. CntrRec.Write(m_ks, *m_apKeyBlob.get());
  309. // forget the private key
  310. m_apKeyBlob = auto_ptr<CPrivateKeyBlob>(0);
  311. }
  312. }
  313. else
  314. throw Exception(ccInvalidParameter);
  315. }
  316. // Access
  317. // Predicates
  318. // Static Variables