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.

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