Source code of Windows XP (NT5)
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.

584 lines
12 KiB

  1. #ifndef __LOGGING__H__
  2. #define __LOGGING__H__
  3. #include <windows.h>
  4. #include <ezlog.h>
  5. #include "cspstruc.h"
  6. #define STRING_TRUE L"True"
  7. #define STRING_FALSE L"False"
  8. #define TEST_CASE_SEPARATOR L"----------------------------------------"
  9. #define BUFFER_LENGTH 1024
  10. //
  11. // ------------
  12. // Error Levels
  13. // ------------
  14. //
  15. #define CSP_ERROR_NO_ERROR 0x00000000
  16. #define CSP_PASS 0x00000001
  17. #define CSP_ERROR_WARNING 0x00000002
  18. #define CSP_ERROR_CONTINUE 0x00000004
  19. #define CSP_ERROR_API 0x00000008
  20. #define CSP_ERROR_TEST_LEVEL 0x00000010
  21. #define CSP_ERROR_CSP_CLASS 0x00000020
  22. #define CSP_ERROR_TEST_SUITE 0x00000040
  23. #define LOG_API_NAME_CONSOLE 0x00000100
  24. #define LOG_API_PARAMETER_CONSOLE 0x00000200
  25. #define LOG_INFO_CONSOLE 0x00000400
  26. #define LOG_SEPARATOR_CONSOLE 0x00000800
  27. #define LOG_API_NAME 0x00010000
  28. #define LOG_API_PARAMETER 0x00020000
  29. #define LOG_INFO 0x00040000
  30. #define LOG_USER_OPTION 0x00080000
  31. #define LOG_SEPARATOR 0x00100000
  32. #define LOG_USER_PROTECTED_KEY 0x00200000
  33. //
  34. // This array is needed so that error levels can be indexed in order
  35. // of increasing severity.
  36. //
  37. static DWORD g_rgErrorLevels [] =
  38. {
  39. CSP_ERROR_WARNING, CSP_ERROR_CONTINUE,
  40. CSP_ERROR_API, CSP_ERROR_TEST_LEVEL,
  41. CSP_ERROR_CSP_CLASS, CSP_ERROR_TEST_SUITE
  42. };
  43. //
  44. // -----------------
  45. // Defines for EZLOG
  46. // -----------------
  47. //
  48. #define LOGFILE L"csptestsuite.log"
  49. //
  50. // The EZLog output settings
  51. //
  52. static EZLOG_LEVEL_INIT_DATA g_EzLogLevels [] =
  53. {
  54. { LOG_API_NAME_CONSOLE,
  55. L"API",
  56. 0,
  57. EZLOG_LFLAG_NONRESULTANT
  58. },
  59. { LOG_API_PARAMETER_CONSOLE,
  60. L"PARA",
  61. 0,
  62. EZLOG_LFLAG_NONRESULTANT
  63. },
  64. { LOG_INFO_CONSOLE,
  65. L"INFO",
  66. 0,
  67. EZLOG_LFLAG_NONRESULTANT
  68. },
  69. { LOG_SEPARATOR_CONSOLE,
  70. L"----",
  71. 0,
  72. EZLOG_LFLAG_NONRESULTANT
  73. },
  74. { LOG_API_NAME,
  75. L"API",
  76. 0,
  77. EZLOG_LFLAG_NONRESULTANT | EZLOG_LFLAG_NOT_CONSOLE
  78. },
  79. { LOG_API_PARAMETER,
  80. L"PARA",
  81. 0,
  82. EZLOG_LFLAG_NONRESULTANT | EZLOG_LFLAG_NOT_CONSOLE
  83. },
  84. { LOG_INFO,
  85. L"INFO",
  86. 0,
  87. EZLOG_LFLAG_NONRESULTANT | EZLOG_LFLAG_NOT_CONSOLE
  88. },
  89. { LOG_USER_OPTION,
  90. L"OPT",
  91. 0,
  92. EZLOG_LFLAG_NONRESULTANT
  93. },
  94. { LOG_SEPARATOR,
  95. L"----",
  96. 0,
  97. EZLOG_LFLAG_NONRESULTANT | EZLOG_LFLAG_NOT_CONSOLE
  98. },
  99. { LOG_USER_PROTECTED_KEY,
  100. L"KEY",
  101. 0,
  102. EZLOG_LFLAG_NONRESULTANT
  103. },
  104. { CSP_PASS,
  105. L"PASS",
  106. CSP_PASS,
  107. EZLOG_LFLAG_ATTEMPTED | EZLOG_LFLAG_SUCCESSFUL | EZLOG_LFLAG_NOT_CONSOLE
  108. },
  109. { CSP_ERROR_WARNING,
  110. L"WARN",
  111. CSP_ERROR_WARNING,
  112. EZLOG_LFLAG_ATTEMPTED | EZLOG_LFLAG_SUCCESSFUL | EZLOG_LFLAG_NOT_CONSOLE
  113. },
  114. { CSP_ERROR_CONTINUE,
  115. L"ERR1",
  116. CSP_ERROR_CONTINUE,
  117. EZLOG_LFLAG_ATTEMPTED
  118. },
  119. { CSP_ERROR_API,
  120. L"ERR2",
  121. CSP_ERROR_API,
  122. EZLOG_LFLAG_ATTEMPTED
  123. },
  124. { CSP_ERROR_TEST_LEVEL,
  125. L"ERR3",
  126. CSP_ERROR_TEST_LEVEL,
  127. EZLOG_LFLAG_NONRESULTANT
  128. },
  129. { CSP_ERROR_CSP_CLASS,
  130. L"ERR4",
  131. CSP_ERROR_CSP_CLASS,
  132. EZLOG_LFLAG_NONRESULTANT
  133. },
  134. { CSP_ERROR_TEST_SUITE,
  135. L"ERR5",
  136. CSP_ERROR_TEST_SUITE,
  137. EZLOG_LFLAG_NONRESULTANT
  138. },
  139. { 0, L"", 0, 0 }
  140. };
  141. //
  142. // Function: IncrementErrorLevel
  143. // Purpose: Increase the severity of the specified error level by
  144. // one step.
  145. //
  146. DWORD IncrementErrorLevel(DWORD dwErrorLevel);
  147. //
  148. // Defines for error results
  149. //
  150. #define ERROR_API_SUCCEEDED 1
  151. #define ERROR_API_FAILED 2
  152. #define ERROR_WRONG_ERROR_CODE 3
  153. #define ERROR_WIN32_FAILURE 4
  154. #define ERROR_WRONG_SIZE 5
  155. #define ERROR_BAD_DATA 6
  156. #define ERROR_LIST_TOO_SHORT 7
  157. #define ERROR_REQUIRED_ALG 8
  158. //
  159. // Defines for the types of test cases
  160. //
  161. #define TEST_CASES_POSITIVE 1
  162. #define TEST_CASES_NEGATIVE 2
  163. #define TEST_CASES_SCENARIO 3
  164. #define TEST_CASES_INTEROP 4
  165. //
  166. // Enum for identifying API's
  167. //
  168. typedef enum _API_NAME
  169. {
  170. API_CRYPTACQUIRECONTEXT = 1,
  171. API_CRYPTCREATEHASH,
  172. API_CRYPTDECRYPT,
  173. API_CRYPTDERIVEKEY,
  174. API_CRYPTDESTROYHASH,
  175. API_CRYPTDESTROYKEY,
  176. API_CRYPTENCRYPT,
  177. API_CRYPTEXPORTKEY,
  178. API_CRYPTGENKEY,
  179. API_CRYPTGENRANDOM,
  180. API_CRYPTGETHASHPARAM,
  181. API_CRYPTGETKEYPARAM,
  182. API_CRYPTGETPROVPARAM,
  183. API_CRYPTGETUSERKEY,
  184. API_CRYPTHASHDATA,
  185. API_CRYPTHASHSESSIONKEY,
  186. API_CRYPTIMPORTKEY,
  187. API_CRYPTRELEASECONTEXT,
  188. API_CRYPTSETHASHPARAM,
  189. API_CRYPTSETKEYPARAM,
  190. API_CRYPTSETPROVPARAM,
  191. API_CRYPTSIGNHASH,
  192. API_CRYPTVERIFYSIGNATURE,
  193. API_CRYPTDUPLICATEHASH,
  194. API_CRYPTDUPLICATEKEY,
  195. API_CRYPTCONTEXTADDREF,
  196. API_MEMORY,
  197. API_DATACOMPARE,
  198. API_GETDESKTOPWINDOW
  199. } API_NAME;
  200. //
  201. // ---------------------------
  202. // Defines for logging strings
  203. // ---------------------------
  204. //
  205. //
  206. // Struct: FLAGTOSTRING_ITEM
  207. // Purpose: Associate a key value with a string
  208. //
  209. typedef struct _FLAGTOSTRING_ITEM
  210. {
  211. DWORD dwKey;
  212. LPWSTR pwszString;
  213. } FLAGTOSTRING_ITEM, *PFLAGTOSTRING_ITEM;
  214. #define FLAGTOSTRING_SIZE(item) (sizeof(item) / sizeof(FLAGTOSTRING_ITEM))
  215. //
  216. // Logging API
  217. //
  218. typedef enum _FLAG_TYPE
  219. {
  220. Maskable = 1,
  221. ExactMatch
  222. } FLAG_TYPE;
  223. //
  224. // Struct: API_PARAM_INFO
  225. // Purpose: Store parameter data for logging each call to a CSP entry
  226. // point.
  227. //
  228. typedef enum _PARAM_TYPE
  229. {
  230. Handle = 1,
  231. Pointer,
  232. Dword,
  233. String,
  234. Boolean
  235. } PARAM_TYPE;
  236. typedef BOOL (*PFN_FLAGTOSTRING)(DWORD, LPWSTR);
  237. typedef struct _API_PARAM_INFO
  238. {
  239. LPWSTR pwszName;
  240. PARAM_TYPE Type;
  241. union Parameter
  242. {
  243. DWORD dwParam;
  244. ULONG_PTR pulParam;
  245. PBYTE pbParam;
  246. LPWSTR pwszParam;
  247. BOOL fParam;
  248. };
  249. PFN_FLAGTOSTRING pfnFlagToString;
  250. BOOL fPrintBytes;
  251. PDWORD pcbBytes;
  252. PBYTE pbSaved;
  253. } API_PARAM_INFO, *PAPI_PARAM_INFO;
  254. #define APIPARAMINFO_SIZE(X) (sizeof(X) / sizeof(API_PARAM_INFO))
  255. //
  256. // Function: FlagToString
  257. // Purpose: Lookup the one or more flag specified by dwFlag in
  258. // rgFlagToString and print the strings to the supplied string
  259. // buffer.
  260. //
  261. BOOL FlagToString(
  262. IN DWORD dwFlag,
  263. IN FLAGTOSTRING_ITEM rgFlagToString [],
  264. IN DWORD cFlagToString,
  265. OUT WCHAR rgwsz [],
  266. IN FLAG_TYPE FlagType);
  267. BOOL AcquireContextFlagToString(
  268. IN DWORD dwFlag,
  269. OUT WCHAR rgwsz []);
  270. BOOL GetProvParamToString(
  271. IN DWORD dwFlag,
  272. OUT WCHAR rgwsz []);
  273. BOOL SetProvParamToString(
  274. IN DWORD dwFlag,
  275. OUT WCHAR rgwsz []);
  276. BOOL AlgidToString(
  277. IN DWORD dwFlag,
  278. OUT WCHAR rgwsz []);
  279. BOOL DeriveKeyFlagToString(
  280. IN DWORD dwFlag,
  281. OUT WCHAR rgwsz []);
  282. BOOL EncryptFlagToString(
  283. IN DWORD dwFlag,
  284. OUT WCHAR rgwsz []);
  285. BOOL ExportKeyBlobTypeToString (
  286. IN DWORD dwFlag,
  287. OUT WCHAR rgwsz []);
  288. BOOL ExportKeyFlagToString (
  289. IN DWORD dwFlag,
  290. OUT WCHAR rgwsz []);
  291. BOOL GenKeyFlagToString(
  292. IN DWORD dwFlag,
  293. OUT WCHAR rgwsz []);
  294. BOOL HashParamToString(
  295. IN DWORD dwFlag,
  296. OUT WCHAR rgwsz []);
  297. BOOL KeyParamToString(
  298. IN DWORD dwFlag,
  299. OUT WCHAR rgwsz []);
  300. BOOL KeyParamModeToString(
  301. IN DWORD dwFlag,
  302. OUT WCHAR rgwsz []);
  303. BOOL KeyParamPermissionToString(
  304. IN DWORD dwFlag,
  305. OUT WCHAR rgwsz []);
  306. BOOL ProvParamEnumFlagToString(
  307. IN DWORD dwFlag,
  308. OUT WCHAR rgwsz []);
  309. BOOL ProvParamSecDescrFlagToString(
  310. IN DWORD dwFlag,
  311. OUT WCHAR rgwsz []);
  312. BOOL ProvParamImpTypeToString(
  313. IN DWORD dwFlag,
  314. OUT WCHAR rgwsz []);
  315. BOOL HashDataFlagToString(
  316. IN DWORD dwFlag,
  317. OUT WCHAR rgwsz []);
  318. BOOL HashSessionKeyFlagToString(
  319. IN DWORD dwFlag,
  320. OUT WCHAR rgwsz []);
  321. BOOL ImportKeyFlagToString(
  322. IN DWORD dwFlag,
  323. OUT WCHAR rgwsz []);
  324. BOOL SignHashFlagToString(
  325. IN DWORD dwFlag,
  326. OUT WCHAR rgwsz []);
  327. BOOL TestCaseTypeToString(
  328. IN DWORD dwTestCaseType,
  329. OUT WCHAR rgwsz []);
  330. BOOL ApiNameToString(
  331. API_NAME ApiName,
  332. OUT WCHAR rgwsz[]);
  333. //
  334. // Function: LogCleanupParamInfo
  335. // Purpose: Free any memory allocated by LogInitParamInfo in the
  336. // pParamInfo array.
  337. //
  338. void LogCleanupParamInfo(
  339. IN OUT PAPI_PARAM_INFO pParamInfo,
  340. IN DWORD cParamInfo);
  341. //
  342. // Function: LogInitParamInfo
  343. // Purpose: Search the pParamInfo array for entries with the
  344. // fPrintBytes flag set. For valid entries, the pbParam data member
  345. // is copied to the pbSaved member.
  346. //
  347. BOOL LogInitParamInfo(
  348. IN OUT PAPI_PARAM_INFO pParamInfo,
  349. IN DWORD cParamInfo,
  350. IN PTESTCASE ptc);
  351. //
  352. // Function: LogParamInfo
  353. // Purpose: Parse an array of type API_PARAM_INFO and write its contents
  354. // to the log file.
  355. //
  356. void LogParamInfo(
  357. PAPI_PARAM_INFO pParamInfo,
  358. DWORD cParamInfo,
  359. BOOL fLogToConsole);
  360. //
  361. // Function: LogInfo
  362. // Purpose: Write an informational message to the log.
  363. //
  364. void LogInfo(IN LPWSTR pwszInfo);
  365. //
  366. // Function: LogUserOption
  367. // Purpose: Report a test suite option as it has been
  368. // selected by the user (or defaulted) to the log.
  369. //
  370. void LogUserOption(IN LPWSTR pwszOption);
  371. //
  372. // Function: LogTestCaseSeparator
  373. // Purpose: Write a blank, separator line to the logfile.
  374. //
  375. BOOL LogTestCaseSeparator(BOOL fLogToConsole);
  376. //
  377. // Function: LogCreatingUserProtectedKey
  378. // Purpose: Write to the console (and log) that the next
  379. // Crypto API call will be CryptGenKey CRYPT_USER_PROTECTED
  380. // and that the operator should expected to see the user
  381. // protected UI.
  382. //
  383. void LogCreatingUserProtectedKey(void);
  384. //
  385. // Function: LogProvEnumalgsEx
  386. // Purpose: Log the contents of a PROV_ENUMALGS_EX struct
  387. //
  388. void LogProvEnumalgsEx(PROV_ENUMALGS_EX *pProvEnumalgsEx);
  389. //
  390. // Function: LogProvEnumalgs
  391. // Purpose: Log the contents of a PROV_ENUMALGS struct
  392. //
  393. void LogProvEnumalgs(PROV_ENUMALGS *pProvEnumalgs);
  394. //
  395. // Struct: LOGINIT_INFO
  396. // Purpose: This is data that is required by LogInit in order
  397. // to initialize the Test Suite logging routines.
  398. //
  399. typedef struct _LOGINIT_INFO
  400. {
  401. //
  402. // Data about the CSP under test
  403. //
  404. LPWSTR pwszCSPName;
  405. DWORD dwCSPExternalType;
  406. DWORD dwCSPInternalType;
  407. DWORD dwCSPInternalClass;
  408. //
  409. // Data about the CSP to be used for
  410. // interoperability testing, if applicable.
  411. //
  412. LPWSTR pwszInteropCSPName;
  413. DWORD dwInteropCSPExternalType;
  414. } LOGINIT_INFO, *PLOGINIT_INFO;
  415. BOOL LogInit(
  416. IN PLOGINIT_INFO pLogInitInfo);
  417. BOOL LogClose(void);
  418. BOOL LogBeginCSPClass(DWORD dwClass);
  419. BOOL LogEndCSPClass(DWORD dwClass);
  420. BOOL LogBeginTestLevel(DWORD dwLevel);
  421. BOOL LogEndTestLevel(DWORD dwLevel);
  422. BOOL LogBeginAPI(API_NAME ApiName, DWORD dwAPISubset);
  423. BOOL LogEndAPI(API_NAME ApiName, DWORD dwAPISubset);
  424. BOOL LogPass(DWORD dwTestCaseID);
  425. BOOL LogBeginScenarioTest(LPWSTR pwszDescription);
  426. BOOL LogEndScenarioTest(void);
  427. BOOL LogBeginInteropTest(LPWSTR pwszDescription);
  428. BOOL LogEndInteropTest(void);
  429. //
  430. // Struct: LOGTESTCASEINFO
  431. // Purpose: Data required to write information about a test case to the
  432. // log file.
  433. //
  434. typedef struct _LOGTESTCASEINFO
  435. {
  436. BOOL fPass;
  437. API_NAME ApiName;
  438. BOOL fReturnVal;
  439. DWORD dwErrorType;
  440. DWORD dwErrorLevel;
  441. DWORD dwTestCaseID;
  442. KNOWN_ERROR_ID KnownErrorID;
  443. DWORD dwWinError;
  444. DWORD dwExpectedErrorCode;
  445. LPWSTR pwszErrorHelp;
  446. PAPI_PARAM_INFO pParamInfo;
  447. DWORD cParamInfo;
  448. } LOGTESTCASEINFO, *PLOGTESTCASEINFO;
  449. //
  450. // Function: LogTestCase
  451. // Purpose: Parse the pLogTestCaseInfo struct and perform the appropriate actions:
  452. // - Log a Pass, Warning, or Error
  453. // - Format the test case information and print it to the log.
  454. //
  455. BOOL LogTestCase(PLOGTESTCASEINFO pLogTestCaseInfo);
  456. //
  457. // Function: LogApiFailure
  458. // Purpose: Create a LOGTESTCASEINFO struct based on the function
  459. // parameters and call LogTestCase.
  460. //
  461. BOOL LogApiFailure(
  462. IN API_NAME ApiName,
  463. IN DWORD dwErrorType,
  464. IN OUT PTESTCASE ptc);
  465. DWORD LogGetInteropProvType(void);
  466. LPWSTR LogGetInteropProvName(void);
  467. DWORD LogGetProvType(void);
  468. LPWSTR LogGetProvName(void);
  469. //
  470. // ----------------
  471. // Logging wrappers
  472. // ----------------
  473. //
  474. //
  475. // Function: CheckAndLogStatus
  476. // Purpose: Calls the appropriate logging routines based on the provided parameters.
  477. //
  478. BOOL CheckAndLogStatus(
  479. IN API_NAME ApiName,
  480. IN BOOL fCallSucceeded,
  481. IN OUT PTESTCASE ptc,
  482. IN PAPI_PARAM_INFO pParamInfo,
  483. IN DWORD cParamInfo);
  484. //
  485. // Function: InitFailInfo
  486. // Purpose: Populate the fields of the LOGTESTCASEINFO struct
  487. // from the corresponding fields of the TESTCASE struct.
  488. //
  489. void InitLogTestCaseInfo(
  490. IN PTESTCASE ptc,
  491. OUT PLOGTESTCASEINFO pLogTestCaseInfo);
  492. //
  493. // Function: LogBadParam
  494. // Purpose: Log the failure of a Key/Hash parameter test
  495. // case.
  496. //
  497. BOOL LogBadParam(
  498. API_NAME ApiName,
  499. LPWSTR pwszErrorHelp,
  500. PTESTCASE ptc);
  501. #endif