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.

324 lines
5.1 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. exchange.cxx
  5. Abstract:
  6. This module implements the IIS_CRYPTO_EXCHANGE_BASE class.
  7. Author:
  8. Keith Moore (keithmo) 02-Dec-1996
  9. Revision History:
  10. --*/
  11. #include "precomp.hxx"
  12. #pragma hdrstop
  13. //
  14. // Private constants.
  15. //
  16. //
  17. // Private types.
  18. //
  19. //
  20. // Private globals.
  21. //
  22. //
  23. // Private prototypes.
  24. //
  25. //
  26. // Public functions.
  27. //
  28. IIS_CRYPTO_EXCHANGE_BASE::IIS_CRYPTO_EXCHANGE_BASE()
  29. /*++
  30. Routine Description:
  31. IIS_CRYPTO_EXCHANGE_BASE class constructor.
  32. Arguments:
  33. None.
  34. Return Value:
  35. None.
  36. --*/
  37. {
  38. //
  39. // Just put the member variables into known states.
  40. //
  41. m_hServerSessionKey = CRYPT_NULL;
  42. m_hClientSessionKey = CRYPT_NULL;
  43. } // IIS_CRYPTO_EXCHANGE_BASE::IIS_CRYPTO_EXCHANGE_BASE
  44. IIS_CRYPTO_EXCHANGE_BASE::~IIS_CRYPTO_EXCHANGE_BASE()
  45. /*++
  46. Routine Description:
  47. IIS_CRYPTO_EXCHANGE_BASE class destructor.
  48. Arguments:
  49. None.
  50. Return Value:
  51. None.
  52. --*/
  53. {
  54. //
  55. // Close any open keys.
  56. //
  57. CLOSE_KEY( m_hServerSessionKey );
  58. CLOSE_KEY( m_hClientSessionKey );
  59. } // IIS_CRYPTO_EXCHANGE_BASE::~IIS_CRYPTO_EXCHANGE_BASE
  60. HRESULT
  61. IIS_CRYPTO_EXCHANGE_BASE::CreatePhase3Hash(
  62. OUT PIIS_CRYPTO_BLOB * ppHashBlob
  63. )
  64. /*++
  65. Routine Description:
  66. Creates the hash value used by phase 3 of the exchange protocol.
  67. Arguments:
  68. ppHashBlob - Receives a pointer to the hash blob if successful.
  69. Return Value:
  70. HRESULT - Completion status, 0 if successful, !0 otherwise.
  71. --*/
  72. {
  73. //
  74. // Let the worker function do the dirty work.
  75. //
  76. return CreateHashWorker(
  77. ppHashBlob,
  78. TRUE // fPhase3
  79. );
  80. } // IIS_CRYPTO_EXCHANGE_BASE::CreatePhase3Hash
  81. HRESULT
  82. IIS_CRYPTO_EXCHANGE_BASE::CreatePhase4Hash(
  83. OUT PIIS_CRYPTO_BLOB * ppHashBlob
  84. )
  85. /*++
  86. Routine Description:
  87. Creates the hash value used by phase 4 of the exchange protocol.
  88. Arguments:
  89. ppHashBlob - Receives a pointer to the hash blob if successful.
  90. Return Value:
  91. HRESULT - Completion status, 0 if successful, !0
  92. otherwise.
  93. --*/
  94. {
  95. //
  96. // Let the worker function do the dirty work.
  97. //
  98. return CreateHashWorker(
  99. ppHashBlob,
  100. FALSE // fPhase3
  101. );
  102. } // IIS_CRYPTO_EXCHANGE_BASE::CreatePhase4Hash
  103. //
  104. // Private functions.
  105. //
  106. HRESULT
  107. IIS_CRYPTO_EXCHANGE_BASE::CreateHashWorker(
  108. OUT PIIS_CRYPTO_BLOB * ppHashBlob,
  109. IN BOOL fPhase3
  110. )
  111. /*++
  112. Routine Description:
  113. Creates the hash value used by the exchange protocol.
  114. Arguments:
  115. ppHashBlob - Receives a pointer to the hash blob if successful.
  116. fPhase3 - TRUE if this is the phase 3 hash.
  117. Return Value:
  118. HRESULT - Completion status, 0 if successful, !0
  119. otherwise.
  120. --*/
  121. {
  122. HRESULT result;
  123. HCRYPTHASH hash;
  124. PIIS_CRYPTO_BLOB hashBlob;
  125. PVOID hashData;
  126. DWORD hashDataLength;
  127. //
  128. // Sanity check.
  129. //
  130. DBG_ASSERT( ValidateState() );
  131. DBG_ASSERT( m_hServerSessionKey != CRYPT_NULL );
  132. DBG_ASSERT( m_hClientSessionKey != CRYPT_NULL );
  133. DBG_ASSERT( ppHashBlob != NULL );
  134. //
  135. // Setup our locals so we know how to cleanup on exit.
  136. //
  137. hash = CRYPT_NULL;
  138. hashBlob = NULL;
  139. //
  140. // Create the hash object.
  141. //
  142. result = ::IISCryptoCreateHash(
  143. &hash,
  144. m_hProv
  145. );
  146. if( FAILED(result) ) {
  147. goto fatal;
  148. }
  149. //
  150. // Hash in the session keys and the constant string.
  151. //
  152. result = ::IISCryptoHashSessionKey(
  153. hash,
  154. m_hClientSessionKey
  155. );
  156. if( FAILED(result) ) {
  157. goto fatal;
  158. }
  159. if( fPhase3 ) {
  160. result = ::IISCryptoHashSessionKey(
  161. hash,
  162. m_hServerSessionKey
  163. );
  164. if( FAILED(result) ) {
  165. goto fatal;
  166. }
  167. hashData = (PVOID)HASH_TEXT_STRING_1;
  168. hashDataLength = sizeof(HASH_TEXT_STRING_1);
  169. } else {
  170. hashData = (PVOID)HASH_TEXT_STRING_2;
  171. hashDataLength = sizeof(HASH_TEXT_STRING_2);
  172. }
  173. result = ::IISCryptoHashData(
  174. hash,
  175. hashData,
  176. hashDataLength
  177. );
  178. if( FAILED(result) ) {
  179. goto fatal;
  180. }
  181. //
  182. // Create the blob.
  183. //
  184. result = ::IISCryptoExportHashBlob(
  185. &hashBlob,
  186. hash
  187. );
  188. if( FAILED(result) ) {
  189. goto fatal;
  190. }
  191. //
  192. // Success!
  193. //
  194. DESTROY_HASH(hash);
  195. *ppHashBlob = hashBlob;
  196. return NO_ERROR;
  197. fatal:
  198. FREE_BLOB(hashBlob);
  199. DESTROY_HASH(hash);
  200. DBG_ASSERT( FAILED(result) );
  201. return result;
  202. } // IIS_CRYPTO_EXCHANGE_BASE::CreatePhase4Hash