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.

180 lines
4.8 KiB

  1. // Pkcs11Attr.cpp -- Implementation of PKCS #11 Attributes class for
  2. // interoperability with Netscape and Entrust using the SLB PKCS#11
  3. // package.
  4. // (c) Copyright Schlumberger Technology Corp., unpublished work, created
  5. // 1999. This computer program includes Confidential, Proprietary
  6. // Information and is a Trade Secret of Schlumberger Technology Corp. All
  7. // use, disclosure, and/or reproduction is prohibited unless authorized
  8. // in writing. All Rights Reserved.
  9. #include "NoWarning.h"
  10. #include "ForceLib.h"
  11. // Don't allow the min & max methods in <limits> to be superceded by
  12. // the min/max macros in <windef.h>
  13. #define NOMINMAX
  14. #include <limits>
  15. #include <functional>
  16. #include <numeric>
  17. #include <iterator>
  18. #include <algorithm>
  19. #include <sstream>
  20. #include <cciCard.h>
  21. #include <cciCont.h>
  22. #include "Pkcs11Attr.h"
  23. #include "AuxHash.h"
  24. using namespace std;
  25. using namespace pki;
  26. /////////////////////////// HELPER /////////////////////////////////
  27. namespace
  28. {
  29. class JoinWith
  30. : public binary_function<string, string, string>
  31. {
  32. public:
  33. explicit
  34. JoinWith(second_argument_type const &rGlue)
  35. : m_Glue(rGlue)
  36. {}
  37. result_type
  38. operator()(string const &rFirst,
  39. string const &rSecond) const
  40. {
  41. return rFirst + m_Glue + rSecond;
  42. }
  43. private:
  44. second_argument_type const m_Glue;
  45. };
  46. string
  47. Combine(vector<string> const &rvsNames)
  48. {
  49. static string::value_type const cBlank = ' ';
  50. static string const sBlank(1, cBlank);
  51. return accumulate(rvsNames.begin() + 1, rvsNames.end(),
  52. *rvsNames.begin(), JoinWith(sBlank));
  53. }
  54. } // namespace
  55. /////////////////////////// PUBLIC /////////////////////////////////
  56. // Types
  57. // C'tors/D'tors
  58. Pkcs11Attributes::Pkcs11Attributes(Blob const &rCertificate,
  59. HCRYPTPROV hprovContext)
  60. : m_x509cert(AsString(rCertificate)),
  61. m_hprovContext(hprovContext)
  62. {
  63. }
  64. // Operators
  65. // Operations
  66. // Access
  67. Blob
  68. Pkcs11Attributes::ContainerId()
  69. {
  70. AuxHash ah(AuxContext(m_hprovContext), CALG_MD5);
  71. return ah.Value(AsBlob(Subject()));
  72. }
  73. Blob
  74. Pkcs11Attributes::EndDate() const
  75. {
  76. return Blob(3, 0); // TO DO: Set date
  77. }
  78. Blob
  79. Pkcs11Attributes::Issuer()
  80. {
  81. return AsBlob(m_x509cert.Issuer());
  82. }
  83. string
  84. Pkcs11Attributes::Label()
  85. {
  86. string sFullName(Combine(m_x509cert.SubjectCommonName()));
  87. string sLabel(sFullName);
  88. static string const sNameSuffix = "'s ";
  89. sLabel.append(sNameSuffix);
  90. string sOrganizationName(Combine(m_x509cert.IssuerOrg()));
  91. sLabel.append(sOrganizationName);
  92. static string const sLabelSuffix = " ID";
  93. sLabel.append(sLabelSuffix);
  94. return sLabel;
  95. }
  96. Blob
  97. Pkcs11Attributes::Modulus()
  98. {
  99. return AsBlob(m_x509cert.Modulus());
  100. }
  101. Blob
  102. Pkcs11Attributes::RawModulus()
  103. {
  104. return AsBlob(m_x509cert.RawModulus());
  105. }
  106. Blob
  107. Pkcs11Attributes::SerialNumber()
  108. {
  109. return AsBlob(m_x509cert.SerialNumber());
  110. }
  111. Blob
  112. Pkcs11Attributes::StartDate() const
  113. {
  114. return Blob(3, 0); // TO DO: Set date
  115. }
  116. string
  117. Pkcs11Attributes::Subject()
  118. {
  119. return m_x509cert.Subject();
  120. }
  121. // Predicates
  122. // Static Variables
  123. /////////////////////////// PROTECTED /////////////////////////////////
  124. // Types
  125. // C'tors/D'tors
  126. // Operators
  127. // Operations
  128. // Access
  129. // Predicates
  130. // Static Variables
  131. /////////////////////////// PRIVATE /////////////////////////////////
  132. // Types
  133. // C'tors/D'tors
  134. // Operators
  135. // Operations
  136. // Access
  137. // Predicates
  138. // Static Variables