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.

149 lines
4.3 KiB

  1. // MsKeyBlob.cpp -- MicroSoft Key Blob class implementation
  2. // (c) Copyright Schlumberger Technology Corp., unpublished work, created
  3. // 1999. This computer program includes Confidential, Proprietary
  4. // Information and is a Trade Secret of Schlumberger Technology Corp. All
  5. // use, disclosure, and/or reproduction is prohibited unless authorized
  6. // in writing. All Rights Reserved.
  7. #include "NoWarning.h"
  8. #include "ForceLib.h"
  9. #include <windows.h>
  10. #include <scuOsExc.h>
  11. #include "MsKeyBlob.h"
  12. using namespace scu;
  13. /////////////////////////// LOCAL/HELPER /////////////////////////////////
  14. /////////////////////////// PUBLIC /////////////////////////////////
  15. // Types
  16. // C'tors/D'tors
  17. // Operators
  18. // Operations
  19. // Access
  20. ALG_ID
  21. MsKeyBlob::AlgId() const
  22. {
  23. return reinterpret_cast<ValueType const *>(m_aapBlob.data())->aiKeyAlg;
  24. }
  25. SecureArray<MsKeyBlob::KeyBlobType>
  26. MsKeyBlob::AsAlignedBlob() const
  27. {
  28. return SecureArray<BlobElemType>(m_aapBlob.data(),m_cLength);
  29. }
  30. MsKeyBlob::ValueType const *
  31. MsKeyBlob::Data() const
  32. {
  33. return reinterpret_cast<ValueType const *>(m_aapBlob.data());
  34. }
  35. MsKeyBlob::SizeType
  36. MsKeyBlob::Length() const
  37. {
  38. return m_cLength;
  39. }
  40. // Predicates
  41. // Static Variables
  42. /////////////////////////// PROTECTED /////////////////////////////////
  43. // C'tors/D'tors
  44. MsKeyBlob::MsKeyBlob(KeyBlobType kbt,
  45. ALG_ID ai,
  46. SizeType cReserve)
  47. : m_aapBlob(0),
  48. m_cLength(0),
  49. m_cMaxSize(0)
  50. {
  51. Setup(sizeof HeaderElementType + cReserve);
  52. ValueType bhTemplate =
  53. {
  54. kbt,
  55. CUR_BLOB_VERSION,
  56. 0, // must be zero per MS
  57. ai
  58. };
  59. Append(reinterpret_cast<BlobElemType const *>(&bhTemplate),
  60. sizeof bhTemplate);
  61. }
  62. MsKeyBlob::MsKeyBlob(BYTE const *pbData,
  63. DWORD dwDataLength)
  64. : m_aapBlob(0),
  65. m_cLength(0),
  66. m_cMaxSize(0)
  67. {
  68. Setup(dwDataLength);
  69. ValueType const *pvt = reinterpret_cast<ValueType const *>(pbData);
  70. if (!((PUBLICKEYBLOB == pvt->bType) ||
  71. (PRIVATEKEYBLOB == pvt->bType) ||
  72. (SIMPLEBLOB == pvt->bType)))
  73. throw scu::OsException(NTE_BAD_TYPE);
  74. if (CUR_BLOB_VERSION != pvt->bVersion)
  75. throw scu::OsException(NTE_BAD_TYPE);
  76. if (0 != pvt->reserved)
  77. throw scu::OsException(NTE_BAD_TYPE);
  78. Append(pbData, dwDataLength);
  79. }
  80. MsKeyBlob::~MsKeyBlob()
  81. {}
  82. // Operators
  83. // Operations
  84. void
  85. MsKeyBlob::Append(BlobElemType const *pvt,
  86. SizeType cLength)
  87. {
  88. if ((m_cLength + cLength) > m_cMaxSize)
  89. {
  90. m_aapBlob.append(cLength, 0);
  91. m_cMaxSize += cLength;
  92. }
  93. memcpy(m_aapBlob.data() + m_cLength, pvt, cLength);
  94. m_cLength += cLength;
  95. }
  96. // Access
  97. // Predicates
  98. // Static Variables
  99. /////////////////////////// PRIVATE /////////////////////////////////
  100. // C'tors/D'tors
  101. // Operators
  102. // Operations
  103. SecureArray<MsKeyBlob::BlobElemType>
  104. MsKeyBlob::AllocBlob(MsKeyBlob::SizeType cInitialMaxLength)
  105. {
  106. return SecureArray<BlobElemType>(cInitialMaxLength);
  107. }
  108. void
  109. MsKeyBlob::Setup(MsKeyBlob::SizeType cMaxLength)
  110. {
  111. m_aapBlob = AllocBlob(cMaxLength);
  112. m_cLength = 0;
  113. m_cMaxSize = cMaxLength;
  114. }
  115. // Access
  116. // Predicates
  117. // Static Variables