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.

197 lines
5.7 KiB

  1. #pragma once
  2. #include "fusionbuffer.h"
  3. #include "fusionarray.h"
  4. #include "fusionsha1.h"
  5. /*++
  6. Hashfile.h - Inclusions for file-hashing and verification testing functionality.
  7. --*/
  8. #define SHA1_HASH_SIZE_BYTES ( 160 / 8 )
  9. #define HASHFLAG_AUTODETECT ( 0x00000001 )
  10. #define HASHFLAG_STRAIGHT_HASH ( 0x00000002 )
  11. #define HASHFLAG_PROCESS_IMAGE ( 0x00000004 )
  12. #define HASHFLAG_VALID_PARAMS ( HASHFLAG_AUTODETECT | HASHFLAG_STRAIGHT_HASH | \
  13. HASHFLAG_PROCESS_IMAGE )
  14. //
  15. // If someone invents a hash with more than 512 bytes, I'll eat my socks.
  16. //
  17. #define MAX_HASH_BYTES ( 512 )
  18. BOOL
  19. SxspEnumKnownHashTypes(
  20. DWORD dwIndex,
  21. OUT CBaseStringBuffer &rbuffHashTypeName,
  22. OUT BOOL &rbNoMoreItems
  23. );
  24. BOOL
  25. SxspCreateFileHash(
  26. DWORD dwFlags,
  27. ALG_ID PreferredAlgorithm,
  28. const CBaseStringBuffer &pwsFileName,
  29. CFusionArray<BYTE> &bHashDestination
  30. );
  31. bool
  32. SxspIsFullHexString(
  33. PCWSTR wsString,
  34. SIZE_T Cch
  35. );
  36. typedef enum {
  37. HashValidate_Matches, // Hashes are identical
  38. HashValidate_InvalidPassedHash, // The hash passed in was somehow invalid
  39. HashValidate_InvalidAlgorithm, // The hash algorithm is invalid
  40. HashValidate_HashesCantBeMatched, // No match for another reason
  41. HashValidate_HashNotMatched, // Hashes are not identical (ie: not matched)
  42. HashValidate_OtherProblems // There was some other problem along the way
  43. } HashValidateResult;
  44. //
  45. // Do the normal validation process - single retry
  46. //
  47. #define SVFH_DEFAULT_ACTION (0x00000000)
  48. //
  49. // Retry this file N times until either (a) the file was unable to be
  50. // opened or (b) the file has other errors or (c) the file was checked
  51. // and it was ok / bad / etc.
  52. //
  53. #define SVFH_RETRY_LOGIC_SIMPLE (0x00000001)
  54. //
  55. // Wait until the file was able to be verified - spin in a backoff loop
  56. // until the file open didn't fail with ERROR_SHARING_VIOLATION
  57. //
  58. #define SVFH_RETRY_WAIT_UNTIL (0x00000002)
  59. BOOL
  60. SxspVerifyFileHash(
  61. const DWORD dwFlags,
  62. const CBaseStringBuffer &rhsFullFilePath,
  63. const CFusionArray<BYTE> &baTheorheticalHash,
  64. ALG_ID whichAlg,
  65. HashValidateResult &rHashResult
  66. );
  67. BOOL
  68. SxspHashAlgFromString(
  69. const CBaseStringBuffer &strAlgName,
  70. ALG_ID &algId
  71. );
  72. BOOL
  73. SxspHashStringFromAlg(
  74. ALG_ID algId,
  75. CBaseStringBuffer &rstrAlgName
  76. );
  77. typedef enum
  78. {
  79. ManifestValidate_Unknown = 0,
  80. ManifestValidate_IsIntact = 1,
  81. ManifestValidate_CatalogMissing = 2,
  82. ManifestValidate_ManifestMissing = 3,
  83. ManifestValidate_InvalidHash = 4,
  84. ManifestValidate_NotCertified = 5,
  85. ManifestValidate_StrongNameMismatch = 6,
  86. ManifestValidate_OtherProblems = 7
  87. } ManifestValidationResult;
  88. class CMetaDataFileElement;
  89. BOOL
  90. SxspValidateAllFileHashes(
  91. IN const CMetaDataFileElement &rmdfeElement,
  92. IN const CBaseStringBuffer &rbuffFileName,
  93. OUT HashValidateResult &rResult
  94. );
  95. #define ENUM_TO_STRING( x ) case x: return (L#x)
  96. #if DBG
  97. inline PCWSTR SxspManifestValidationResultToString( ManifestValidationResult r )
  98. {
  99. switch ( r )
  100. {
  101. ENUM_TO_STRING( ManifestValidate_Unknown );
  102. ENUM_TO_STRING( ManifestValidate_IsIntact );
  103. ENUM_TO_STRING( ManifestValidate_CatalogMissing );
  104. ENUM_TO_STRING( ManifestValidate_ManifestMissing );
  105. ENUM_TO_STRING( ManifestValidate_InvalidHash );
  106. ENUM_TO_STRING( ManifestValidate_NotCertified );
  107. ENUM_TO_STRING( ManifestValidate_OtherProblems );
  108. }
  109. return L"Bad manifest validation value";
  110. }
  111. inline PCWSTR SxspHashValidateResultToString( HashValidateResult r )
  112. {
  113. switch ( r )
  114. {
  115. ENUM_TO_STRING( HashValidate_Matches );
  116. ENUM_TO_STRING( HashValidate_InvalidPassedHash );
  117. ENUM_TO_STRING( HashValidate_InvalidAlgorithm );
  118. ENUM_TO_STRING( HashValidate_HashesCantBeMatched );
  119. ENUM_TO_STRING( HashValidate_HashNotMatched );
  120. ENUM_TO_STRING( HashValidate_OtherProblems );
  121. }
  122. return L"Bad hash validation value";
  123. }
  124. #endif
  125. // Default mode
  126. #define MANIFESTVALIDATE_OPTION_MASK ( 0x000000FF )
  127. #define MANIFESTVALIDATE_MODE_MASK ( 0x0000FF00 )
  128. #define MANIFESTVALIDATE_MODE_COMPLETE ( 0x00000100 )
  129. #define MANIFESTVALIDATE_MODE_NO_STRONGNAME ( 0x00000200 )
  130. // The manifest has to validate against a trusted root CA to be valid.
  131. #define MANIFESTVALIDATE_OPTION_NEEDS_ROOT_CA ( 0x00000001 )
  132. // The catalog gets validated first before the manifest is checked.
  133. #define MANIFESTVALIDATE_OPTION_VALIDATE_CATALOG ( 0x00000002 )
  134. // If the manifest or catalog are invalid, attempt to retrieve it
  135. #define MANIFESTVALIDATE_OPTION_ATTEMPT_RETRIEVAL ( 0x00000004 )
  136. #define MANIFESTVALIDATE_MOST_COMMON ( MANIFESTVALIDATE_MODE_COMPLETE + \
  137. ( MANIFESTVALIDATE_OPTION_NEEDS_ROOT_CA | \
  138. MANIFESTVALIDATE_OPTION_VALIDATE_CATALOG ) )
  139. BOOL
  140. SxspValidateManifestAgainstCatalog(
  141. const CBaseStringBuffer &rbuffManifestPath,
  142. ManifestValidationResult &rResult,
  143. DWORD dwOptionsFlags
  144. );
  145. BOOL
  146. SxspValidateManifestAgainstCatalog(
  147. const CBaseStringBuffer &rbuffManifestPath,
  148. const CBaseStringBuffer &rbuffCatalogPath,
  149. ManifestValidationResult &rResult,
  150. DWORD dwOptionsFlags
  151. );
  152. BOOL
  153. SxspCheckHashDuringInstall(
  154. BOOL bHasHashData,
  155. const CBaseStringBuffer &rbuffFile,
  156. const CBaseStringBuffer &rbuffHashDataString,
  157. ALG_ID HashAlgId,
  158. HashValidateResult &hvr
  159. );