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.

371 lines
8.2 KiB

  1. // V2PubKey.cpp: implementation of the CV2PubKey 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 "cciCard.h"
  11. #include "TransactionWrap.h"
  12. #include "V2PubKey.h"
  13. #include "PubKeyInfoRecord.h"
  14. using namespace std;
  15. using namespace cci;
  16. /////////////////////////// LOCAL/HELPER /////////////////////////////////
  17. /////////////////////////// PUBLIC /////////////////////////////////
  18. // Types
  19. // C'tors/D'tors
  20. CV2PublicKey::CV2PublicKey(CV2Card const &rv2card,
  21. ObjectAccess oa)
  22. : CAbstractPublicKey(rv2card, oa),
  23. m_sidHandle(0),
  24. m_apcir()
  25. {
  26. m_sidHandle =
  27. rv2card.ObjectInfoFile(m_oa).AddObject(otPublicKeyObject,
  28. PublInfoRecordSize);
  29. Setup(rv2card);
  30. // write new public key object into info file
  31. m_apcir->Clear();
  32. m_apcir->Write();
  33. }
  34. CV2PublicKey::CV2PublicKey(CV2Card const &rv2card,
  35. SymbolID sidHandle,
  36. ObjectAccess oa)
  37. : CAbstractPublicKey(rv2card, oa),
  38. m_sidHandle(sidHandle),
  39. m_apcir()
  40. {
  41. Setup(rv2card);
  42. }
  43. CV2PublicKey::~CV2PublicKey()
  44. {}
  45. // Operators
  46. // Operations
  47. void
  48. CV2PublicKey::CKInvisible(bool flag)
  49. {
  50. m_apcir->Flag(PublCKInvisibleFlag, flag);
  51. }
  52. void
  53. CV2PublicKey::CredentialID(string const &rstrID)
  54. {
  55. m_apcir->Symbol(&m_apcir->m_bCredentialID, rstrID);
  56. }
  57. void
  58. CV2PublicKey::Derive(bool flag)
  59. {
  60. m_apcir->Flag(PublDeriveFlag, flag);
  61. }
  62. void
  63. CV2PublicKey::ID(string const &rstrID)
  64. {
  65. m_apcir->Symbol(&m_apcir->m_bID, rstrID);
  66. }
  67. void
  68. CV2PublicKey::EndDate(Date const &rdtEnd)
  69. {
  70. CTransactionWrap wrap(m_hcard);
  71. m_apcir->Read();
  72. m_apcir->m_dtEnd = rdtEnd;
  73. m_apcir->Write();
  74. }
  75. bool
  76. CV2PublicKey::Encrypt()
  77. {
  78. return m_apcir->Flag(PublEncryptFlag);
  79. }
  80. void
  81. CV2PublicKey::Exponent(string const &rstrExp)
  82. {
  83. m_apcir->Symbol(&m_apcir->m_bPublExponent, rstrExp);
  84. }
  85. void
  86. CV2PublicKey::Label(string const &rstrLabel)
  87. {
  88. m_apcir->Symbol(&m_apcir->m_bLabel, rstrLabel);
  89. }
  90. void
  91. CV2PublicKey::Local(bool flag)
  92. {
  93. m_apcir->Flag(PublLocalFlag, flag);
  94. }
  95. CV2PublicKey *
  96. CV2PublicKey::Make(CV2Card const &rv2card,
  97. SymbolID sidHandle,
  98. ObjectAccess oa)
  99. {
  100. return new CV2PublicKey(rv2card, sidHandle, oa);
  101. }
  102. void
  103. CV2PublicKey::Modifiable(bool flag)
  104. {
  105. m_apcir->Flag(PublModifiableFlag, flag);
  106. }
  107. void
  108. CV2PublicKey::Modulus(string const &rstrMod)
  109. {
  110. CTransactionWrap wrap(m_hcard);
  111. m_apcir->Read();
  112. m_apcir->Symbol(&m_apcir->m_bModulus, rstrMod);
  113. if (rstrMod.size() == 0x80)
  114. m_apcir->m_bKeyType = CardKeyTypeRSA1024;
  115. else if (rstrMod.size() == 0x60)
  116. m_apcir->m_bKeyType = CardKeyTypeRSA768;
  117. else if (rstrMod.size() == 0x40)
  118. m_apcir->m_bKeyType = CardKeyTypeRSA512;
  119. else
  120. m_apcir->m_bKeyType = CardKeyTypeNone;
  121. m_apcir->Write();
  122. }
  123. void
  124. CV2PublicKey::StartDate(Date const &rdtStart)
  125. {
  126. CTransactionWrap wrap(m_hcard);
  127. m_apcir->Read();
  128. m_apcir->m_dtStart = rdtStart;
  129. m_apcir->Write();
  130. }
  131. void
  132. CV2PublicKey::Subject(string const &rstrSubject)
  133. {
  134. m_apcir->Symbol(&m_apcir->m_bSubject, rstrSubject);
  135. }
  136. void
  137. CV2PublicKey::Verify(bool flag)
  138. {
  139. m_apcir->Flag(PublVerifyFlag, flag);
  140. }
  141. void
  142. CV2PublicKey::VerifyRecover(bool flag)
  143. {
  144. m_apcir->Flag(PublVerifyRecoverFlag, flag);
  145. }
  146. void
  147. CV2PublicKey::Wrap(bool flag)
  148. {
  149. m_apcir->Flag(PublWrapFlag, flag);
  150. }
  151. // Access
  152. bool
  153. CV2PublicKey::CKInvisible()
  154. {
  155. return m_apcir->Flag(PublCKInvisibleFlag);
  156. }
  157. string
  158. CV2PublicKey::CredentialID()
  159. {
  160. return m_apcir->Symbol(&m_apcir->m_bCredentialID);
  161. }
  162. bool
  163. CV2PublicKey::Derive()
  164. {
  165. return m_apcir->Flag(PublDeriveFlag);
  166. }
  167. void
  168. CV2PublicKey::Encrypt(bool flag)
  169. {
  170. m_apcir->Flag(PublEncryptFlag, flag);
  171. }
  172. Date
  173. CV2PublicKey::EndDate()
  174. {
  175. CTransactionWrap wrap(m_hcard);
  176. m_apcir->Read();
  177. return m_apcir->m_dtEnd;
  178. }
  179. string
  180. CV2PublicKey::Exponent()
  181. {
  182. return m_apcir->Symbol(&m_apcir->m_bPublExponent);
  183. }
  184. SymbolID
  185. CV2PublicKey::Handle() const
  186. {
  187. return m_sidHandle;
  188. }
  189. string
  190. CV2PublicKey::ID()
  191. {
  192. return m_apcir->Symbol(&m_apcir->m_bID);
  193. }
  194. string
  195. CV2PublicKey::Label()
  196. {
  197. return m_apcir->Symbol(&m_apcir->m_bLabel);
  198. }
  199. bool
  200. CV2PublicKey::Local()
  201. {
  202. return m_apcir->Flag(PublLocalFlag);
  203. }
  204. bool
  205. CV2PublicKey::Modifiable()
  206. {
  207. return m_apcir->Flag(PublModifiableFlag);
  208. }
  209. string
  210. CV2PublicKey::Modulus()
  211. {
  212. return m_apcir->Symbol(&m_apcir->m_bModulus);
  213. }
  214. bool
  215. CV2PublicKey::Private()
  216. {
  217. return m_apcir->Private();
  218. }
  219. Date
  220. CV2PublicKey::StartDate()
  221. {
  222. CTransactionWrap wrap(m_hcard);
  223. m_apcir->Read();
  224. return m_apcir->m_dtStart;
  225. }
  226. string
  227. CV2PublicKey::Subject()
  228. {
  229. return m_apcir->Symbol(&m_apcir->m_bSubject);
  230. }
  231. bool
  232. CV2PublicKey::Verify()
  233. {
  234. return m_apcir->Flag(PublVerifyFlag);
  235. }
  236. bool
  237. CV2PublicKey::VerifyRecover()
  238. {
  239. return m_apcir->Flag(PublVerifyRecoverFlag);
  240. }
  241. bool
  242. CV2PublicKey::Wrap()
  243. {
  244. return m_apcir->Flag(PublWrapFlag);
  245. }
  246. // Predicates
  247. // Static Variables
  248. /////////////////////////// PROTECTED /////////////////////////////////
  249. // C'tors/D'tors
  250. // Operators
  251. // Operations
  252. void
  253. CV2PublicKey::DoDelete()
  254. {
  255. CV2Card &rv2card = scu::DownCast<CV2Card &, CAbstractCard &>(*m_hcard);
  256. CObjectInfoFile &roif = rv2card.ObjectInfoFile(m_oa);
  257. m_apcir->Read();
  258. // Remove allocation of entry in private key file
  259. if (m_apcir->m_bLabel)
  260. roif.RemoveSymbol(m_apcir->m_bLabel);
  261. if (m_apcir->m_bID)
  262. roif.RemoveSymbol(m_apcir->m_bID);
  263. if (m_apcir->m_bCredentialID)
  264. roif.RemoveSymbol(m_apcir->m_bCredentialID);
  265. if (m_apcir->m_bSubject)
  266. roif.RemoveSymbol(m_apcir->m_bSubject);
  267. if (m_apcir->m_bModulus)
  268. roif.RemoveSymbol(m_apcir->m_bModulus);
  269. if (m_apcir->m_bPublExponent)
  270. roif.RemoveSymbol(m_apcir->m_bPublExponent);
  271. // Delete info record
  272. roif.RemoveObject(otPublicKeyObject, m_sidHandle);
  273. }
  274. // Access
  275. // Predicates
  276. bool
  277. CV2PublicKey::DoEquals(CAbstractPublicKey const &rhs) const
  278. {
  279. CV2PublicKey const &rv2rhs =
  280. scu::DownCast<CV2PublicKey const &, CAbstractPublicKey const &>(rhs);
  281. return (rv2rhs.m_sidHandle == m_sidHandle);
  282. }
  283. // Static Variables
  284. /////////////////////////// PRIVATE /////////////////////////////////
  285. // C'tors/D'tors
  286. // Operators
  287. // Operations
  288. void
  289. CV2PublicKey::Setup(CV2Card const &rv2card)
  290. {
  291. m_apcir =
  292. auto_ptr<CPubKeyInfoRecord>(new CPubKeyInfoRecord(rv2card,
  293. m_sidHandle,
  294. m_oa));
  295. }
  296. // Access
  297. // Predicates
  298. // Static Variables