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.

1870 lines
39 KiB

  1. /*
  2. Logging.c
  3. 4/23/00 dangriff created
  4. This is the output/logging code used by the CSP Test Suite. Expect that this
  5. set of wrappers will be modified as the Test Suite evolves.
  6. */
  7. #include <windows.h>
  8. #include <stdio.h>
  9. #include <stdarg.h>
  10. #include "cspstruc.h"
  11. #include "logging.h"
  12. #include "csptestsuite.h"
  13. //
  14. // Logging state variables
  15. //
  16. static BOOL g_fTestSuiteError = FALSE;
  17. static BOOL g_fCSPClassError = FALSE;
  18. static BOOL g_fTestLevelError = FALSE;
  19. static BOOL g_fAPIError = FALSE;
  20. static BOOL g_fCurrentAPIUnexpected = FALSE;
  21. static DWORD g_dwCurrentCSPClass = 0;
  22. static DWORD g_dwCurrentTestLevel = 0;
  23. static API_NAME g_CurrentAPI;
  24. static DWORD g_dwCurrentAPISubset = 0; // TEST_CASES_POSITIVE or TEST_CASES_NEGATIVE
  25. // Test case set counter
  26. static DWORD g_dwTestCaseIDMajor = 0;
  27. //
  28. // User-specified settings
  29. //
  30. //static LOG_VERBOSE g_Verbose = Terse;
  31. static LPWSTR g_pwszProvName = NULL;
  32. static DWORD g_dwExternalProvType = 0;
  33. static LPWSTR g_pwszInteropProvName = NULL;
  34. static DWORD g_dwInteropProvType = 0;
  35. //
  36. // Function: LogInfo
  37. //
  38. void LogInfo(IN LPWSTR pwszInfo)
  39. {
  40. ezLogMsg(LOG_INFO, NULL, NULL, __LINE__, L"%s", pwszInfo);
  41. }
  42. //
  43. // Function: LogUserOption
  44. //
  45. void LogUserOption(IN LPWSTR pwszOption)
  46. {
  47. ezLogMsg(LOG_USER_OPTION, NULL, NULL, __LINE__, L"%s", pwszOption);
  48. }
  49. //
  50. // Function: LogCreatingUserProtectedKey
  51. //
  52. void LogCreatingUserProtectedKey(void)
  53. {
  54. LogTestCaseSeparator(TRUE);
  55. ezLogMsg(
  56. LOG_USER_PROTECTED_KEY,
  57. NULL,
  58. NULL,
  59. __LINE__,
  60. L"Creating user protected key. You should see UI.");
  61. }
  62. //
  63. // Function: FlagToString
  64. //
  65. BOOL FlagToString(
  66. IN DWORD dwFlag,
  67. IN FLAGTOSTRING_ITEM rgFlagToString [],
  68. IN DWORD cFlagToString,
  69. OUT WCHAR rgwsz [],
  70. IN FLAG_TYPE FlagType)
  71. {
  72. BOOL fFound = FALSE;
  73. unsigned iString = 0;
  74. for (iString = 0; iString < cFlagToString; iString++)
  75. {
  76. if ( ((ExactMatch == FlagType) &&
  77. (dwFlag == rgFlagToString[iString].dwKey)) ||
  78. ((Maskable == FlagType) &&
  79. (dwFlag & rgFlagToString[iString].dwKey)))
  80. {
  81. if (fFound)
  82. {
  83. //
  84. // One or more flags have already been found,
  85. // so print a "|" to delimit multiple strings.
  86. //
  87. wsprintf(
  88. rgwsz += wcslen(rgwsz),
  89. L" | %s",
  90. rgFlagToString[iString].pwszString);
  91. }
  92. else
  93. {
  94. fFound = TRUE;
  95. wcscpy(
  96. rgwsz,
  97. rgFlagToString[iString].pwszString);
  98. }
  99. if (ExactMatch == FlagType)
  100. {
  101. break;
  102. }
  103. }
  104. }
  105. return fFound;
  106. }
  107. //
  108. // Function: AcquireContextFlagToString
  109. //
  110. BOOL AcquireContextFlagToString(
  111. IN DWORD dwFlag,
  112. OUT WCHAR rgwsz [])
  113. {
  114. FLAGTOSTRING_ITEM AcquireContextFlagStrings [] = {
  115. { CRYPT_VERIFYCONTEXT, L"CRYPT_VERIFYCONTEXT" },
  116. { CRYPT_NEWKEYSET, L"CRYPT_NEWKEYSET" },
  117. { CRYPT_MACHINE_KEYSET, L"CRYPT_MACHINE_KEYSET" },
  118. { CRYPT_DELETEKEYSET, L"CRYPT_DELETEKEYSET" },
  119. { CRYPT_SILENT, L"CRYPT_SILENT" }
  120. };
  121. return FlagToString(
  122. dwFlag,
  123. AcquireContextFlagStrings,
  124. FLAGTOSTRING_SIZE(AcquireContextFlagStrings),
  125. rgwsz,
  126. Maskable);
  127. }
  128. //
  129. // Function: GetProvParamToString
  130. //
  131. BOOL GetProvParamToString(
  132. IN DWORD dwFlag,
  133. OUT WCHAR rgwsz [])
  134. {
  135. FLAGTOSTRING_ITEM GetProvParamStrings [] = {
  136. { PP_CONTAINER, L"PP_CONTAINER" },
  137. { PP_ENUMALGS, L"PP_ENUMALGS" },
  138. { PP_ENUMALGS_EX, L"PP_ENUMALGS_EX" },
  139. { PP_ENUMCONTAINERS, L"PP_ENUMCONTAINERS" },
  140. { PP_IMPTYPE, L"PP_IMPTYPE" },
  141. { PP_NAME, L"PP_NAME" },
  142. { PP_VERSION, L"PP_VERSION" },
  143. { PP_SIG_KEYSIZE_INC, L"PP_SIG_KEYSIZE_INC" },
  144. { PP_KEYX_KEYSIZE_INC, L"PP_KEYX_KEYSIZE_INC" },
  145. { PP_KEYSET_SEC_DESCR, L"PP_KEYSET_SEC_DESCR" },
  146. { PP_UNIQUE_CONTAINER, L"PP_UNIQUE_CONTAINER" },
  147. { PP_PROVTYPE, L"PP_PROVTYPE" },
  148. { PP_USE_HARDWARE_RNG, L"PP_USE_HARDWARE_RNG" },
  149. { PP_KEYSPEC, L"PP_KEYSPEC" }
  150. };
  151. return FlagToString(
  152. dwFlag,
  153. GetProvParamStrings,
  154. FLAGTOSTRING_SIZE(GetProvParamStrings),
  155. rgwsz,
  156. ExactMatch);
  157. }
  158. //
  159. // Function: SetProvParamToString
  160. //
  161. BOOL SetProvParamToString(
  162. IN DWORD dwFlag,
  163. OUT WCHAR rgwsz [])
  164. {
  165. FLAGTOSTRING_ITEM SetProvParamStrings [] = {
  166. { PP_CLIENT_HWND, L"PP_CLIENT_HWND" },
  167. { PP_KEYSET_SEC_DESCR, L"PP_KEYSET_SEC_DESCR" },
  168. { PP_USE_HARDWARE_RNG, L"PP_USE_HARDWARE_RNG" }
  169. };
  170. return FlagToString(
  171. dwFlag,
  172. SetProvParamStrings,
  173. FLAGTOSTRING_SIZE(SetProvParamStrings),
  174. rgwsz,
  175. ExactMatch);
  176. }
  177. //
  178. // Function: AlgidToString
  179. //
  180. BOOL AlgidToString(
  181. IN DWORD dwFlag,
  182. OUT WCHAR rgwsz [])
  183. {
  184. FLAGTOSTRING_ITEM AlgidStrings [] = {
  185. { AT_SIGNATURE, L"AT_SIGNATURE" },
  186. { AT_KEYEXCHANGE, L"AT_KEYEXCHANGE" },
  187. { CALG_MD2, L"CALG_MD2" },
  188. { CALG_MD4, L"CALG_MD4" },
  189. { CALG_MD5, L"CALG_MD5" },
  190. { CALG_SHA, L"CALG_SHA" },
  191. { CALG_SHA1, L"CALG_SHA1" },
  192. { CALG_MAC, L"CALG_MAC" },
  193. { CALG_RSA_SIGN, L"CALG_RSA_SIGN" },
  194. { CALG_DSS_SIGN, L"CALG_DSS_SIGN" },
  195. { CALG_RSA_KEYX, L"CALG_RSA_KEYX" },
  196. { CALG_DES, L"CALG_DES" },
  197. { CALG_3DES_112, L"CALG_3DES_112" },
  198. { CALG_3DES, L"CALG_3DES" },
  199. { CALG_DESX, L"CALG_DESX" },
  200. { CALG_RC2, L"CALG_RC2" },
  201. { CALG_RC4, L"CALG_RC4" },
  202. { CALG_SEAL, L"CALG_SEAL" },
  203. { CALG_DH_SF, L"CALG_DH_SF" },
  204. { CALG_DH_EPHEM, L"CALG_DH_EPHEM" },
  205. { CALG_AGREEDKEY_ANY, L"CALG_AGREEDKEY_ANY" },
  206. { CALG_KEA_KEYX, L"CALG_KEA_KEYX" },
  207. { CALG_HUGHES_MD5, L"CALG_HUGHES_MD5" },
  208. { CALG_SKIPJACK, L"CALG_SKIPJACK" },
  209. { CALG_TEK, L"CALG_TEK" },
  210. { CALG_CYLINK_MEK, L"CALG_CYLINK_MEK" },
  211. { CALG_SSL3_SHAMD5, L"CALG_SSL3_SHAMD5" },
  212. { CALG_SSL3_MASTER, L"CALG_SSL3_MASTER" },
  213. { CALG_SCHANNEL_MASTER_HASH, L"CALG_SCHANNEL_MASTER_HASH" },
  214. { CALG_SCHANNEL_MAC_KEY, L"CALG_SCHANNEL_MAC_KEY" },
  215. { CALG_SCHANNEL_ENC_KEY, L"CALG_SCHANNEL_ENC_KEY" },
  216. { CALG_PCT1_MASTER, L"CALG_PCT1_MASTER" },
  217. { CALG_SSL2_MASTER, L"CALG_SSL2_MASTER" },
  218. { CALG_TLS1_MASTER, L"CALG_TLS1_MASTER" },
  219. { CALG_RC5, L"CALG_RC5" },
  220. { CALG_HMAC, L"CALG_HMAC" },
  221. { CALG_TLS1PRF, L"CALG_TLS1PRF" },
  222. { CALG_HASH_REPLACE_OWF, L"CALG_HASH_REPLACE_OWF" }
  223. };
  224. return FlagToString(
  225. dwFlag,
  226. AlgidStrings,
  227. FLAGTOSTRING_SIZE(AlgidStrings),
  228. rgwsz,
  229. ExactMatch);
  230. }
  231. //
  232. // Function: DeriveKeyFlagToString
  233. //
  234. BOOL DeriveKeyFlagToString(
  235. IN DWORD dwFlag,
  236. OUT WCHAR rgwsz [])
  237. {
  238. FLAGTOSTRING_ITEM DeriveKeyFlagStrings [] = {
  239. { CRYPT_CREATE_SALT, L"CRYPT_CREATE_SALT" },
  240. { CRYPT_EXPORTABLE, L"CRYPT_EXPORTABLE" },
  241. { CRYPT_NO_SALT, L"CRYPT_NO_SALT" },
  242. { CRYPT_UPDATE_KEY, L"CRYPT_UPDATE_KEY" }
  243. };
  244. return FlagToString(
  245. dwFlag,
  246. DeriveKeyFlagStrings,
  247. FLAGTOSTRING_SIZE(DeriveKeyFlagStrings),
  248. rgwsz,
  249. Maskable);
  250. }
  251. //
  252. // Function: EncryptFlagToString
  253. //
  254. BOOL EncryptFlagToString(
  255. IN DWORD dwFlag,
  256. OUT WCHAR rgwsz [])
  257. {
  258. FLAGTOSTRING_ITEM EncryptFlagStrings [] = {
  259. { CRYPT_OAEP, L"CRYPT_OAEP" }
  260. };
  261. return FlagToString(
  262. dwFlag,
  263. EncryptFlagStrings,
  264. FLAGTOSTRING_SIZE(EncryptFlagStrings),
  265. rgwsz,
  266. Maskable);
  267. }
  268. //
  269. // Function: ExportKeyBlobTypeToString
  270. //
  271. BOOL ExportKeyBlobTypeToString (
  272. IN DWORD dwFlag,
  273. OUT WCHAR rgwsz [])
  274. {
  275. FLAGTOSTRING_ITEM ExportKeyBlobTypeStrings [] = {
  276. { OPAQUEKEYBLOB, L"OPAQUEKEYBLOB" },
  277. { PRIVATEKEYBLOB, L"PRIVATEKEYBLOB" },
  278. { PUBLICKEYBLOB, L"PUBLICKEYBLOB" },
  279. { SIMPLEBLOB, L"SIMPLEBLOB" },
  280. { SYMMETRICWRAPKEYBLOB, L"SYMMETRICWRAPKEYBLOB" }
  281. };
  282. return FlagToString(
  283. dwFlag,
  284. ExportKeyBlobTypeStrings,
  285. FLAGTOSTRING_SIZE(ExportKeyBlobTypeStrings),
  286. rgwsz,
  287. ExactMatch);
  288. }
  289. //
  290. // Function: ExportKeyFlagToString
  291. //
  292. BOOL ExportKeyFlagToString (
  293. IN DWORD dwFlag,
  294. OUT WCHAR rgwsz [])
  295. {
  296. FLAGTOSTRING_ITEM ExportKeyFlagStrings [] = {
  297. { CRYPT_DESTROYKEY, L"CRYPT_DESTROYKEY" },
  298. { CRYPT_SSL2_FALLBACK, L"CRYPT_SSL2_FALLBACK" },
  299. { CRYPT_OAEP, L"CRYPT_OAEP" }
  300. };
  301. return FlagToString(
  302. dwFlag,
  303. ExportKeyFlagStrings,
  304. FLAGTOSTRING_SIZE(ExportKeyFlagStrings),
  305. rgwsz,
  306. Maskable);
  307. }
  308. //
  309. // Function: GenKeyFlagToString
  310. //
  311. BOOL GenKeyFlagToString(
  312. IN DWORD dwFlag,
  313. OUT WCHAR rgwsz [])
  314. {
  315. FLAGTOSTRING_ITEM GenKeyFlagStrings [] = {
  316. { CRYPT_CREATE_SALT, L"CRYPT_CREATE_SALT" },
  317. { CRYPT_EXPORTABLE, L"CRYPT_EXPORTABLE" },
  318. { CRYPT_NO_SALT, L"CRYPT_NO_SALT" },
  319. { CRYPT_PREGEN, L"CRYPT_PREGEN" },
  320. { CRYPT_USER_PROTECTED, L"CRYPT_USER_PROTECTED" }
  321. };
  322. return FlagToString(
  323. dwFlag,
  324. GenKeyFlagStrings,
  325. FLAGTOSTRING_SIZE(GenKeyFlagStrings),
  326. rgwsz,
  327. Maskable);
  328. }
  329. //
  330. // Function: HashParamToString
  331. //
  332. BOOL HashParamToString(
  333. IN DWORD dwFlag,
  334. OUT WCHAR rgwsz [])
  335. {
  336. FLAGTOSTRING_ITEM HashParamStrings [] = {
  337. { HP_ALGID, L"HP_ALGID" },
  338. { HP_HASHSIZE, L"HP_HASHSIZE" },
  339. { HP_HASHVAL, L"HP_HASHVAL" },
  340. { HP_HMAC_INFO, L"HP_HMAC_INFO" }
  341. };
  342. return FlagToString(
  343. dwFlag,
  344. HashParamStrings,
  345. FLAGTOSTRING_SIZE(HashParamStrings),
  346. rgwsz,
  347. ExactMatch);
  348. }
  349. //
  350. // Function: KeyParamToString
  351. //
  352. BOOL KeyParamToString(
  353. IN DWORD dwFlag,
  354. OUT WCHAR rgwsz [])
  355. {
  356. FLAGTOSTRING_ITEM KeyParamStrings [] = {
  357. { KP_ALGID, L"KP_ALGID" },
  358. { KP_BLOCKLEN, L"KP_BLOCKLEN" },
  359. { KP_KEYLEN, L"KP_KEYLEN" },
  360. { KP_SALT, L"KP_SALT" },
  361. { KP_SALT_EX, L"KP_SALT_EX" },
  362. { KP_PERMISSIONS, L"KP_PERMISSIONS" },
  363. { KP_P, L"KP_P" },
  364. { KP_Q, L"KP_Q" },
  365. { KP_G, L"KP_G" },
  366. { KP_X, L"KP_X" },
  367. { KP_EFFECTIVE_KEYLEN, L"KP_EFFECTIVE_KEYLEN" },
  368. { KP_IV, L"KP_IV" },
  369. { KP_PADDING, L"KP_PADDING" },
  370. { KP_MODE, L"KP_MODE" },
  371. { KP_MODE_BITS, L"KP_MODE_BITS" },
  372. { KP_PUB_PARAMS, L"KP_PUB_PARAMS" }
  373. };
  374. return FlagToString(
  375. dwFlag,
  376. KeyParamStrings,
  377. FLAGTOSTRING_SIZE(KeyParamStrings),
  378. rgwsz,
  379. ExactMatch);
  380. }
  381. //
  382. // Function: KeyParamModeToString
  383. //
  384. BOOL KeyParamModeToString(
  385. IN DWORD dwFlag,
  386. OUT WCHAR rgwsz [])
  387. {
  388. FLAGTOSTRING_ITEM KeyParamModeStrings[] = {
  389. { CRYPT_MODE_CBC, L"CRYPT_MODE_CBC" },
  390. { CRYPT_MODE_CFB, L"CRYPT_MODE_CFB" },
  391. { CRYPT_MODE_ECB, L"CRYPT_MODE_ECB" },
  392. { CRYPT_MODE_OFB, L"CRYPT_MODE_OFB" }
  393. };
  394. return FlagToString(
  395. dwFlag,
  396. KeyParamModeStrings,
  397. FLAGTOSTRING_SIZE(KeyParamModeStrings),
  398. rgwsz,
  399. ExactMatch);
  400. }
  401. //
  402. // Function: KeyParamPermissionToString
  403. //
  404. BOOL KeyParamPermissionToString(
  405. IN DWORD dwFlag,
  406. OUT WCHAR rgwsz [])
  407. {
  408. FLAGTOSTRING_ITEM KeyParamPermissionStrings[] = {
  409. { CRYPT_DECRYPT, L"CRYPT_DECRYPT" },
  410. { CRYPT_ENCRYPT, L"CRYPT_ENCRYPT" },
  411. { CRYPT_EXPORT, L"CRYPT_EXPORT" },
  412. { CRYPT_MAC, L"CRYPT_MAC" },
  413. { CRYPT_READ, L"CRYPT_READ" },
  414. { CRYPT_WRITE, L"CRYPT_WRITE" }
  415. };
  416. return FlagToString(
  417. dwFlag,
  418. KeyParamPermissionStrings,
  419. FLAGTOSTRING_SIZE(KeyParamPermissionStrings),
  420. rgwsz,
  421. Maskable);
  422. }
  423. //
  424. // Function: ProvParamEnumFlagToString
  425. //
  426. BOOL ProvParamEnumFlagToString(
  427. IN DWORD dwFlag,
  428. OUT WCHAR rgwsz [])
  429. {
  430. FLAGTOSTRING_ITEM ProvParamEnumFlagStrings[] = {
  431. { CRYPT_FIRST, L"CRYPT_FIRST" },
  432. { CRYPT_MACHINE_KEYSET, L"CRYPT_MACHINE_KEYSET" }
  433. };
  434. return FlagToString(
  435. dwFlag,
  436. ProvParamEnumFlagStrings,
  437. FLAGTOSTRING_SIZE(ProvParamEnumFlagStrings),
  438. rgwsz,
  439. Maskable);
  440. }
  441. //
  442. // Function: ProvParamSecDescrFlagToString
  443. //
  444. BOOL ProvParamSecDescrFlagToString(
  445. IN DWORD dwFlag,
  446. OUT WCHAR rgwsz [])
  447. {
  448. FLAGTOSTRING_ITEM ProvParamSecDescrFlagStrings[] = {
  449. { OWNER_SECURITY_INFORMATION, L"OWNER_SECURITY_INFORMATION" },
  450. { GROUP_SECURITY_INFORMATION, L"GROUP_SECURITY_INFORMATION" },
  451. { DACL_SECURITY_INFORMATION, L"DACL_SECURITY_INFORMATION" },
  452. { SACL_SECURITY_INFORMATION, L"SACL_SECURITY_INFORMATION" }
  453. };
  454. return FlagToString(
  455. dwFlag,
  456. ProvParamSecDescrFlagStrings,
  457. FLAGTOSTRING_SIZE(ProvParamSecDescrFlagStrings),
  458. rgwsz,
  459. Maskable);
  460. }
  461. //
  462. // Function: ProvParamImpTypeToString
  463. //
  464. BOOL ProvParamImpTypeToString(
  465. IN DWORD dwFlag,
  466. OUT WCHAR rgwsz [])
  467. {
  468. FLAGTOSTRING_ITEM ProvParamImpTypeStrings[] = {
  469. { CRYPT_IMPL_HARDWARE, L"CRYPT_IMPL_HARDWARE" },
  470. { CRYPT_IMPL_SOFTWARE, L"CRYPT_IMPL_SOFTWARE" },
  471. { CRYPT_IMPL_MIXED, L"CRYPT_IMPL_MIXED" },
  472. { CRYPT_IMPL_UNKNOWN, L"CRYPT_IMPL_UNKNOWN" }
  473. };
  474. return FlagToString(
  475. dwFlag,
  476. ProvParamImpTypeStrings,
  477. FLAGTOSTRING_SIZE(ProvParamImpTypeStrings),
  478. rgwsz,
  479. ExactMatch);
  480. }
  481. //
  482. // Function: HashDataFlagToString
  483. //
  484. BOOL HashDataFlagToString(
  485. IN DWORD dwFlag,
  486. OUT WCHAR rgwsz [])
  487. {
  488. FLAGTOSTRING_ITEM HashDataFlagStrings[] = {
  489. { CRYPT_USERDATA, L"CRYPT_USERDATA" }
  490. };
  491. return FlagToString(
  492. dwFlag,
  493. HashDataFlagStrings,
  494. FLAGTOSTRING_SIZE(HashDataFlagStrings),
  495. rgwsz,
  496. Maskable);
  497. }
  498. //
  499. // Function: HashSessionKeyFlagToString
  500. //
  501. BOOL HashSessionKeyFlagToString(
  502. IN DWORD dwFlag,
  503. OUT WCHAR rgwsz [])
  504. {
  505. FLAGTOSTRING_ITEM HashSessionKeyFlagStrings[] = {
  506. { CRYPT_LITTLE_ENDIAN, L"CRYPT_LITTLE_ENDIAN" }
  507. };
  508. return FlagToString(
  509. dwFlag,
  510. HashSessionKeyFlagStrings,
  511. FLAGTOSTRING_SIZE(HashSessionKeyFlagStrings),
  512. rgwsz,
  513. Maskable);
  514. }
  515. //
  516. // Function: ImportKeyFlagToString
  517. //
  518. BOOL ImportKeyFlagToString(
  519. IN DWORD dwFlag,
  520. OUT WCHAR rgwsz [])
  521. {
  522. FLAGTOSTRING_ITEM ImportKeyFlagStrings[] = {
  523. { CRYPT_EXPORTABLE, L"CRYPT_EXPORTABLE" },
  524. { CRYPT_OAEP, L"CRYPT_OAEP" },
  525. { CRYPT_NO_SALT, L"CRYPT_NO_SALT" }
  526. };
  527. return FlagToString(
  528. dwFlag,
  529. ImportKeyFlagStrings,
  530. FLAGTOSTRING_SIZE(ImportKeyFlagStrings),
  531. rgwsz,
  532. Maskable);
  533. }
  534. //
  535. // Function: SignHashFlagToString
  536. //
  537. BOOL SignHashFlagToString(
  538. IN DWORD dwFlag,
  539. OUT WCHAR rgwsz [])
  540. {
  541. FLAGTOSTRING_ITEM SignHashFlagStrings[] = {
  542. { CRYPT_NOHASHOID, L"CRYPT_NOHASHOID" }
  543. };
  544. return FlagToString(
  545. dwFlag,
  546. SignHashFlagStrings,
  547. FLAGTOSTRING_SIZE(SignHashFlagStrings),
  548. rgwsz,
  549. Maskable);
  550. }
  551. //
  552. // Function: TestCaseTypeToString
  553. //
  554. BOOL TestCaseTypeToString(
  555. IN DWORD dwTestCaseType,
  556. OUT WCHAR rgwsz [])
  557. {
  558. FLAGTOSTRING_ITEM TestCaseTypeStrings[] = {
  559. { TEST_CASES_POSITIVE, L"Positive test cases. API's should return TRUE" },
  560. { TEST_CASES_NEGATIVE, L"Negative test cases. API's should return FALSE" },
  561. { TEST_CASES_SCENARIO, L"Scenario test cases. Tests using multiple API's" },
  562. { TEST_CASES_INTEROP, L"Interoperability test cases. Tests using multiple API's and two CSP's" }
  563. };
  564. return FlagToString(
  565. dwTestCaseType,
  566. TestCaseTypeStrings,
  567. FLAGTOSTRING_SIZE(TestCaseTypeStrings),
  568. rgwsz,
  569. ExactMatch);
  570. };
  571. //
  572. // Function:
  573. //
  574. BOOL ApiNameToString(
  575. API_NAME ApiName,
  576. OUT WCHAR rgwsz[])
  577. {
  578. FLAGTOSTRING_ITEM ApiNameStrings [] = {
  579. { API_CRYPTACQUIRECONTEXT, L"CryptAcquireContext" },
  580. { API_CRYPTCREATEHASH, L"CryptCreateHash" },
  581. { API_CRYPTDECRYPT, L"CryptDecrypt" },
  582. { API_CRYPTDERIVEKEY, L"CryptDeriveKey" },
  583. { API_CRYPTDESTROYHASH, L"CryptDestroyHash" },
  584. { API_CRYPTDESTROYKEY, L"CryptDestroyKey" },
  585. { API_CRYPTENCRYPT, L"CryptEncrypt" },
  586. { API_CRYPTEXPORTKEY, L"CryptExportKey" },
  587. { API_CRYPTGENKEY, L"CryptGenKey" },
  588. { API_CRYPTGENRANDOM, L"CryptGenRandom" },
  589. { API_CRYPTGETHASHPARAM, L"CryptGetHashParam" },
  590. { API_CRYPTGETKEYPARAM, L"CryptGetKeyParam" },
  591. { API_CRYPTGETPROVPARAM, L"CryptGetProvParam" },
  592. { API_CRYPTGETUSERKEY, L"CryptGetUserKey" },
  593. { API_CRYPTHASHDATA, L"CryptHashData" },
  594. { API_CRYPTHASHSESSIONKEY, L"CryptHashSessionKey" },
  595. { API_CRYPTIMPORTKEY, L"CryptImportKey" },
  596. { API_CRYPTRELEASECONTEXT, L"CryptReleaseContext" },
  597. { API_CRYPTSETHASHPARAM, L"CryptSetHashParam" },
  598. { API_CRYPTSETKEYPARAM, L"CryptSetKeyParam" },
  599. { API_CRYPTSETPROVPARAM, L"CryptSetProvParam" },
  600. { API_CRYPTSIGNHASH, L"CryptSignHash" },
  601. { API_CRYPTVERIFYSIGNATURE, L"CryptVerifySignature" },
  602. { API_CRYPTDUPLICATEHASH, L"CryptDuplicateHash" },
  603. { API_CRYPTDUPLICATEKEY, L"CryptDuplicateKey" },
  604. //
  605. // Advapi32 entry point
  606. //
  607. { API_CRYPTCONTEXTADDREF, L"CryptContextAddRef" },
  608. //
  609. // Non-Crypto API functions
  610. //
  611. { API_MEMORY, L"Memory allocation" },
  612. { API_DATACOMPARE, L"Data comparision (see previous API)" },
  613. { API_GETDESKTOPWINDOW, L"GetDesktopWindow" }
  614. };
  615. return FlagToString(
  616. ApiName,
  617. ApiNameStrings,
  618. FLAGTOSTRING_SIZE(ApiNameStrings),
  619. rgwsz,
  620. ExactMatch);
  621. }
  622. //
  623. // Function: LogCleanupParamInfo
  624. //
  625. void LogCleanupParamInfo(
  626. IN OUT PAPI_PARAM_INFO pParamInfo,
  627. IN DWORD cParamInfo)
  628. {
  629. unsigned iParam;
  630. for (iParam = 0; iParam < cParamInfo; iParam++)
  631. {
  632. if (pParamInfo[iParam].pbSaved)
  633. free(pParamInfo[iParam].pbSaved);
  634. }
  635. }
  636. //
  637. // Function: LogInitParamInfo
  638. //
  639. BOOL LogInitParamInfo(
  640. IN OUT PAPI_PARAM_INFO pParamInfo,
  641. IN DWORD cParamInfo,
  642. IN PTESTCASE ptc)
  643. {
  644. unsigned iParam;
  645. for (iParam = 0; iParam < cParamInfo; iParam++)
  646. {
  647. if (pParamInfo[iParam].fPrintBytes)
  648. {
  649. if ( NULL != pParamInfo[iParam].pbParam &&
  650. ((PBYTE) TEST_INVALID_POINTER) != pParamInfo[iParam].pbParam &&
  651. NULL != pParamInfo[iParam].pcbBytes &&
  652. ((PDWORD) TEST_INVALID_POINTER) != pParamInfo[iParam].pcbBytes)
  653. {
  654. // Save bytes to a second buffer
  655. if (! TestAlloc(
  656. &pParamInfo[iParam].pbSaved,
  657. *pParamInfo[iParam].pcbBytes,
  658. ptc))
  659. {
  660. return FALSE;
  661. }
  662. memcpy(
  663. pParamInfo[iParam].pbSaved,
  664. pParamInfo[iParam].pbParam,
  665. *pParamInfo[iParam].pcbBytes);
  666. }
  667. }
  668. }
  669. return TRUE;
  670. }
  671. //
  672. // Function: LogParamInfo
  673. //
  674. void LogParamInfo(
  675. PAPI_PARAM_INFO pParamInfo,
  676. DWORD cParamInfo,
  677. BOOL fLogToConsole)
  678. {
  679. DWORD dwLogApiParameter = LOG_API_PARAMETER;
  680. WCHAR rgwsz [ BUFFER_LENGTH ];
  681. unsigned iParam;
  682. if (fLogToConsole)
  683. {
  684. // Feedback has been to not display parameters with the console
  685. // output. To change this, uncomment the next line.
  686. //dwLogApiParameter = LOG_API_PARAMETER_CONSOLE;
  687. }
  688. memset(rgwsz, 0, sizeof(rgwsz));
  689. for (iParam = 0; iParam < cParamInfo; iParam++)
  690. {
  691. switch( pParamInfo[iParam].Type )
  692. {
  693. case Handle:
  694. {
  695. ezLogMsg(
  696. dwLogApiParameter,
  697. NULL,
  698. NULL,
  699. __LINE__,
  700. L" %s: 0x%x",
  701. pParamInfo[iParam].pwszName,
  702. pParamInfo[iParam].pulParam);
  703. break;
  704. }
  705. case Pointer:
  706. {
  707. ezLogMsg(
  708. dwLogApiParameter,
  709. NULL,
  710. NULL,
  711. __LINE__,
  712. L" %s: 0x%x",
  713. pParamInfo[iParam].pwszName,
  714. pParamInfo[iParam].pbParam);
  715. if ( pParamInfo[iParam].fPrintBytes &&
  716. pParamInfo[iParam].pbSaved)
  717. {
  718. wsprintf(rgwsz, L"INPUT value", pParamInfo[iParam].pwszName);
  719. PrintBytes(
  720. rgwsz,
  721. pParamInfo[iParam].pbSaved,
  722. *pParamInfo[iParam].pcbBytes);
  723. *rgwsz = L'\0';
  724. }
  725. if ( pParamInfo[iParam].fPrintBytes &&
  726. NULL != pParamInfo[iParam].pbParam &&
  727. (PBYTE) TEST_INVALID_POINTER != pParamInfo[iParam].pbParam &&
  728. NULL != pParamInfo[iParam].pcbBytes &&
  729. (PDWORD) TEST_INVALID_POINTER != pParamInfo[iParam].pcbBytes)
  730. {
  731. wsprintf(rgwsz, L"OUTPUT value", pParamInfo[iParam].pwszName);
  732. PrintBytes(
  733. rgwsz,
  734. pParamInfo[iParam].pbParam,
  735. *(pParamInfo[iParam].pcbBytes));
  736. *rgwsz = L'\0';
  737. }
  738. break;
  739. }
  740. case Dword:
  741. {
  742. //
  743. // If a pfnFlagToString function has been specified,
  744. // attempt to translate the flag(s).
  745. //
  746. if (pParamInfo[iParam].pfnFlagToString)
  747. {
  748. pParamInfo[iParam].pfnFlagToString(
  749. pParamInfo[iParam].dwParam,
  750. rgwsz);
  751. ezLogMsg(
  752. dwLogApiParameter,
  753. NULL,
  754. NULL,
  755. __LINE__,
  756. L" %s: 0x%x (%s)",
  757. pParamInfo[iParam].pwszName,
  758. pParamInfo[iParam].dwParam,
  759. rgwsz);
  760. rgwsz[0] = L'\0';
  761. }
  762. else
  763. {
  764. ezLogMsg(
  765. dwLogApiParameter,
  766. NULL,
  767. NULL,
  768. __LINE__,
  769. L" %s: 0x%x",
  770. pParamInfo[iParam].pwszName,
  771. pParamInfo[iParam].dwParam);
  772. }
  773. break;
  774. }
  775. case String:
  776. {
  777. ezLogMsg(
  778. dwLogApiParameter,
  779. NULL,
  780. NULL,
  781. __LINE__,
  782. L" %s: %s",
  783. pParamInfo[iParam].pwszName,
  784. pParamInfo[iParam].pwszParam);
  785. break;
  786. }
  787. case Boolean:
  788. {
  789. ezLogMsg(
  790. dwLogApiParameter,
  791. NULL,
  792. NULL,
  793. __LINE__,
  794. L" %s: %s",
  795. pParamInfo[iParam].pwszName,
  796. pParamInfo[iParam].fParam ? STRING_TRUE : STRING_FALSE);
  797. break;
  798. }
  799. }
  800. }
  801. }
  802. //
  803. // Function: IncrementErrorLevel
  804. //
  805. DWORD IncrementErrorLevel(DWORD dwErrorLevel)
  806. {
  807. int iLevel;
  808. for (
  809. iLevel = 0;
  810. iLevel < (sizeof(g_rgErrorLevels) / sizeof(DWORD) - 1);
  811. iLevel++)
  812. {
  813. if (dwErrorLevel == g_rgErrorLevels[iLevel])
  814. {
  815. return g_rgErrorLevels[iLevel + 1];
  816. }
  817. }
  818. return g_rgErrorLevels[iLevel];
  819. }
  820. //
  821. // Function: LogInit
  822. //
  823. BOOL LogInit(
  824. IN PLOGINIT_INFO pLogInitInfo)
  825. {
  826. EZLOG_OPENLOG_DATA EzLogOpenData;
  827. g_pwszProvName = pLogInitInfo->pwszCSPName;
  828. g_dwExternalProvType = pLogInitInfo->dwCSPExternalType;
  829. g_pwszInteropProvName = pLogInitInfo->pwszInteropCSPName;
  830. g_dwInteropProvType = pLogInitInfo->dwInteropCSPExternalType;
  831. //
  832. // Initialize EZLOG
  833. //
  834. memset(&EzLogOpenData, 0, sizeof(EzLogOpenData));
  835. EzLogOpenData.Version = EZLOG_OPENLOG_DATA_VERSION;
  836. EzLogOpenData.Flags = EZLOG_OUTPUT_STDOUT | EZLOG_USE_INDENTATION |
  837. EZLOG_REPORT_BLOCKCLOSE | EZLOG_USE_ONLY_MY_LEVELS | EZLOG_LEVELS_ARE_MASKABLE;
  838. EzLogOpenData.LogFileName = LOGFILE;
  839. //
  840. // Don't output the block summary table
  841. //
  842. EzLogOpenData.cReportBlockThresh = EZLOG_REPORT_NO_BLOCKS;
  843. EzLogOpenData.cLevels = sizeof(g_EzLogLevels) / sizeof(EZLOG_LEVEL_INIT_DATA);
  844. EzLogOpenData.pLevels = g_EzLogLevels;
  845. if (! ezOpenLogEx(&EzLogOpenData))
  846. {
  847. return FALSE;
  848. }
  849. return TRUE;
  850. }
  851. //
  852. // Function: LogClose
  853. // Purpose: Close and cleanup logging
  854. //
  855. BOOL LogClose(void)
  856. {
  857. //
  858. // Check for a Test Suite-level error
  859. //
  860. if (g_fTestSuiteError)
  861. {
  862. ezLogMsg(
  863. CSP_ERROR_TEST_SUITE,
  864. NULL,
  865. NULL,
  866. __LINE__,
  867. L"CSP Test Suite is ending prematurely");
  868. }
  869. return ezCloseLog(0);
  870. }
  871. //
  872. // Function: LogBeginCSPClass
  873. // Purpose: Log the beginning of a new class, or major group, of tests.
  874. //
  875. BOOL LogBeginCSPClass(DWORD dwClass)
  876. {
  877. LPWSTR pwsz = NULL;
  878. switch (dwClass)
  879. {
  880. case CLASS_INVALID:
  881. {
  882. pwsz = L"CLASS_INVALID";
  883. break;
  884. }
  885. case CLASS_SIG_ONLY:
  886. {
  887. pwsz = L"CLASS_SIG_ONLY";
  888. break;
  889. }
  890. case CLASS_SIG_KEYX:
  891. {
  892. pwsz = L"CLASS_SIG_KEYX";
  893. break;
  894. }
  895. case CLASS_FULL:
  896. {
  897. pwsz = L"CLASS_FULL";
  898. break;
  899. }
  900. }
  901. //
  902. // If there has been a Test Suite-level error, don't allow
  903. // a new CSP Class set of tests to begin.
  904. //
  905. if (g_fTestSuiteError)
  906. {
  907. return FALSE;
  908. }
  909. else
  910. {
  911. g_dwCurrentCSPClass = dwClass;
  912. return ezStartBlock(
  913. NULL,
  914. NULL,
  915. EZBLOCK_OUTCOME_INDEPENDENT /*EZBLOCK_TRACK_SUBBLOCKS*/,
  916. CSP_PASS,
  917. L"CSP %s", pwsz);
  918. }
  919. }
  920. //
  921. // Function: LogEndCSPClass
  922. // Purpose: Log the completion of the current class of tests.
  923. //
  924. BOOL LogEndCSPClass(DWORD dwClass)
  925. {
  926. if (g_dwCurrentCSPClass != dwClass)
  927. {
  928. return FALSE;
  929. }
  930. //
  931. // Clear CSP Class-level error flag
  932. //
  933. if (g_fCSPClassError)
  934. {
  935. ezLogMsg(
  936. CSP_ERROR_CSP_CLASS,
  937. NULL,
  938. NULL,
  939. __LINE__,
  940. L"CSP Class is ending prematurely");
  941. g_fCSPClassError = FALSE;
  942. }
  943. return ezFinishBlock(0);
  944. }
  945. //
  946. // Function: LogBeginTestLevel
  947. // Purpose: Log the beginning of a new level, or minor group, of tests.
  948. //
  949. BOOL LogBeginTestLevel(DWORD dwLevel)
  950. {
  951. LPWSTR pwsz = NULL;
  952. switch (dwLevel)
  953. {
  954. case TEST_LEVEL_CSP:
  955. {
  956. pwsz = L"TEST_LEVEL_CSP";
  957. break;
  958. }
  959. case TEST_LEVEL_PROV:
  960. {
  961. pwsz = L"TEST_LEVEL_PROV";
  962. break;
  963. }
  964. case TEST_LEVEL_HASH:
  965. {
  966. pwsz = L"TEST_LEVEL_HASH";
  967. break;
  968. }
  969. case TEST_LEVEL_KEY:
  970. {
  971. pwsz = L"TEST_LEVEL_KEY";
  972. break;
  973. }
  974. case TEST_LEVEL_CONTAINER:
  975. {
  976. pwsz = L"TEST_LEVEL_CONTAINER";
  977. break;
  978. }
  979. }
  980. //
  981. // If there has been a CSP Class-level error, don't start
  982. // a new test level until the error has been cleared.
  983. //
  984. if (g_fCSPClassError)
  985. {
  986. return FALSE;
  987. }
  988. else
  989. {
  990. g_dwCurrentTestLevel = dwLevel;
  991. return ezStartBlock(
  992. NULL,
  993. NULL,
  994. EZBLOCK_OUTCOME_INDEPENDENT /*EZBLOCK_TRACK_SUBBLOCKS*/,
  995. CSP_PASS,
  996. L"%s", pwsz);
  997. }
  998. }
  999. //
  1000. // Function: LogEndTestLevel
  1001. // Purpose: Log the completion of the current test level.
  1002. //
  1003. BOOL LogEndTestLevel(DWORD dwLevel)
  1004. {
  1005. if (g_dwCurrentTestLevel != dwLevel)
  1006. {
  1007. return FALSE;
  1008. }
  1009. //
  1010. // Clear Test Level error flag
  1011. //
  1012. if (g_fTestLevelError)
  1013. {
  1014. ezLogMsg(
  1015. CSP_ERROR_TEST_LEVEL,
  1016. NULL,
  1017. NULL,
  1018. __LINE__,
  1019. L"Test Level is ending prematurely");
  1020. g_fTestLevelError = FALSE;
  1021. }
  1022. return ezFinishBlock(0);
  1023. }
  1024. //
  1025. // Function: LogBeginAPI
  1026. // Purpose: Log the beginning of a set of API test cases
  1027. //
  1028. BOOL LogBeginAPI(API_NAME ApiName, DWORD dwAPISubset)
  1029. {
  1030. WCHAR rgwsz[BUFFER_SIZE];
  1031. //
  1032. // If there has been a Test Level error, don't start a new
  1033. // API set until the error has been cleared.
  1034. //
  1035. if (g_fTestLevelError)
  1036. {
  1037. return FALSE;
  1038. }
  1039. else
  1040. {
  1041. g_dwTestCaseIDMajor++;
  1042. g_CurrentAPI = ApiName;
  1043. g_dwCurrentAPISubset = dwAPISubset;
  1044. ApiNameToString(ApiName, rgwsz);
  1045. wcscpy(rgwsz + wcslen(rgwsz), L", ");
  1046. TestCaseTypeToString(
  1047. dwAPISubset,
  1048. rgwsz + wcslen(rgwsz));
  1049. return ezStartBlock(
  1050. NULL,
  1051. NULL,
  1052. EZBLOCK_OUTCOME_INDEPENDENT /*EZBLOCK_TRACK_SUBBLOCKS*/,
  1053. CSP_PASS,
  1054. L"API %s",
  1055. rgwsz);
  1056. }
  1057. }
  1058. //
  1059. // Function: LogEndAPI
  1060. // Purpose: Log the completion of a set of API test cases
  1061. //
  1062. BOOL LogEndAPI(API_NAME ApiName, DWORD dwAPISubset)
  1063. {
  1064. if ( (g_CurrentAPI != ApiName) ||
  1065. (g_dwCurrentAPISubset != dwAPISubset))
  1066. {
  1067. return FALSE;
  1068. }
  1069. //
  1070. // Clear API-level error flag
  1071. //
  1072. g_fAPIError = FALSE;
  1073. return ezFinishBlock(0);
  1074. }
  1075. //
  1076. // Function: LogPass
  1077. // Purpose: Log a successful test case
  1078. //
  1079. BOOL LogPass(DWORD dwTestCaseID)
  1080. {
  1081. return ezLogMsg(
  1082. CSP_PASS,
  1083. NULL,
  1084. NULL,
  1085. __LINE__,
  1086. L"Test case %d.%d: PASS",
  1087. g_dwTestCaseIDMajor,
  1088. dwTestCaseID);
  1089. }
  1090. //
  1091. // Function: LogBeginScenarioTest
  1092. // Purpose: Log the beginning of a Scenario Test.
  1093. //
  1094. BOOL LogBeginScenarioTest(LPWSTR pwszDescription)
  1095. {
  1096. g_dwTestCaseIDMajor++;
  1097. return ezStartBlock(
  1098. NULL,
  1099. NULL,
  1100. EZBLOCK_OUTCOME_INDEPENDENT,
  1101. CSP_PASS,
  1102. L"Scenario test case - %s",
  1103. pwszDescription);
  1104. }
  1105. //
  1106. // Function: LogEndScenarioTest
  1107. // Purpose: Log the end of a Scenario Test
  1108. //
  1109. BOOL LogEndScenarioTest(void)
  1110. {
  1111. //
  1112. // Clear API-level error flag
  1113. //
  1114. g_fAPIError = FALSE;
  1115. return ezFinishBlock(0);
  1116. }
  1117. //
  1118. // Function: LogBeginInteropTest
  1119. // Purpose: Log the beginning of an Interoperability Test.
  1120. //
  1121. BOOL LogBeginInteropTest(LPWSTR pwszDescription)
  1122. {
  1123. g_dwTestCaseIDMajor++;
  1124. return ezStartBlock(
  1125. NULL,
  1126. NULL,
  1127. EZBLOCK_OUTCOME_INDEPENDENT,
  1128. CSP_PASS,
  1129. L"Interoperability test case - %s",
  1130. pwszDescription);
  1131. }
  1132. //
  1133. // Function: LogEndInteropTest
  1134. // Purpose: Log the end of an Interoperability Test
  1135. //
  1136. BOOL LogEndInteropTest(void)
  1137. {
  1138. //
  1139. // Clear API-level error flag
  1140. //
  1141. g_fAPIError = FALSE;
  1142. return ezFinishBlock(0);
  1143. }
  1144. //
  1145. // Function: DoError
  1146. // Purpose: Perform the operations for handling a test case error
  1147. //
  1148. BOOL DoError(DWORD dwTestCaseID, DWORD dwReportedErrorLevel)
  1149. {
  1150. LPWSTR pwszErrorLevel = NULL;
  1151. DWORD dwErrorLevel = dwReportedErrorLevel & (CSP_ERROR_CONTINUE | CSP_ERROR_API);
  1152. switch (dwErrorLevel)
  1153. {
  1154. case CSP_ERROR_CONTINUE:
  1155. pwszErrorLevel = L"ERROR_CONTINUE";
  1156. break;
  1157. case CSP_ERROR_API:
  1158. pwszErrorLevel = L"ERROR_API";
  1159. break;
  1160. }
  1161. //
  1162. // The dwErrorLevel is being masked to limit the scope of the
  1163. // error being reported at this point. If a test case fails,
  1164. // only ERROR_CONTINUE and ERROR_API (and ERROR_WARNING) errors
  1165. // will be reported. If a more severe error has been flagged,
  1166. // it will be reported when the appropriate Test Level or CSP Class
  1167. // block ends.
  1168. //
  1169. return ezLogMsg(
  1170. dwErrorLevel,
  1171. NULL,
  1172. NULL,
  1173. __LINE__,
  1174. L"Test case %d.%d: %s",
  1175. g_dwTestCaseIDMajor,
  1176. dwTestCaseID,
  1177. pwszErrorLevel);
  1178. }
  1179. //
  1180. // Function: DoWarning
  1181. // Purpose: Perform the operations for handling a test case warning
  1182. //
  1183. BOOL DoWarning(DWORD dwTestCaseID)
  1184. {
  1185. return ezLogMsg(
  1186. CSP_ERROR_WARNING,
  1187. NULL,
  1188. NULL,
  1189. __LINE__,
  1190. L"Test case %d.%d: WARNING",
  1191. g_dwTestCaseIDMajor,
  1192. dwTestCaseID);
  1193. }
  1194. //
  1195. // Function: LogTestCaseSeparator
  1196. //
  1197. BOOL LogTestCaseSeparator(BOOL fLogToConsole)
  1198. {
  1199. if (fLogToConsole)
  1200. {
  1201. return ezLogMsg(
  1202. LOG_SEPARATOR_CONSOLE,
  1203. NULL,
  1204. NULL,
  1205. __LINE__,
  1206. TEST_CASE_SEPARATOR);
  1207. }
  1208. else
  1209. {
  1210. return ezLogMsg(
  1211. LOG_SEPARATOR,
  1212. NULL,
  1213. NULL,
  1214. __LINE__,
  1215. TEST_CASE_SEPARATOR);
  1216. }
  1217. }
  1218. //
  1219. // Function: LogTestCase
  1220. //
  1221. BOOL LogTestCase(PLOGTESTCASEINFO pLogTestCaseInfo)
  1222. {
  1223. BOOL fReturn = TRUE;
  1224. DWORD dwActualErrorLevel = pLogTestCaseInfo->dwErrorLevel;
  1225. //LPWSTR pwszExpected = NULL;
  1226. //LPWSTR pwszActual = NULL;
  1227. LPWSTR pwsz = NULL;
  1228. BOOL fLogToConsole = FALSE;
  1229. DWORD dwLogApiName = LOG_API_NAME;
  1230. DWORD dwLogInfo = LOG_INFO;
  1231. WCHAR rgwsz[BUFFER_SIZE];
  1232. if (pLogTestCaseInfo->fPass)
  1233. {
  1234. LogTestCaseSeparator(FALSE);
  1235. LogPass(pLogTestCaseInfo->dwTestCaseID);
  1236. goto Return;
  1237. }
  1238. if (KNOWN_ERROR_UNKNOWN != pLogTestCaseInfo->KnownErrorID)
  1239. {
  1240. dwActualErrorLevel = GetKnownErrorValue(
  1241. pLogTestCaseInfo->KnownErrorID,
  1242. dwActualErrorLevel);
  1243. }
  1244. if (dwActualErrorLevel & CSP_ERROR_WARNING)
  1245. {
  1246. //
  1247. // Don't look for other error flags if a warning has been flagged,
  1248. // just handle the warning and return.
  1249. //
  1250. //fLogToConsole = TRUE;
  1251. LogTestCaseSeparator(fLogToConsole);
  1252. DoWarning(pLogTestCaseInfo->dwTestCaseID);
  1253. goto Return;
  1254. }
  1255. if (dwActualErrorLevel &
  1256. (CSP_ERROR_CONTINUE | CSP_ERROR_API |
  1257. CSP_ERROR_TEST_LEVEL | CSP_ERROR_CSP_CLASS |
  1258. CSP_ERROR_TEST_SUITE))
  1259. {
  1260. fLogToConsole = TRUE;
  1261. LogTestCaseSeparator(fLogToConsole);
  1262. DoError(pLogTestCaseInfo->dwTestCaseID, dwActualErrorLevel);
  1263. }
  1264. if (dwActualErrorLevel & CSP_ERROR_API)
  1265. {
  1266. g_fAPIError = TRUE;
  1267. fReturn = FALSE;
  1268. }
  1269. if (dwActualErrorLevel & CSP_ERROR_TEST_LEVEL)
  1270. {
  1271. g_fTestLevelError = TRUE;
  1272. }
  1273. if (dwActualErrorLevel & CSP_ERROR_CSP_CLASS)
  1274. {
  1275. g_fCSPClassError = TRUE;
  1276. }
  1277. if (dwActualErrorLevel & CSP_ERROR_TEST_SUITE)
  1278. {
  1279. g_fTestSuiteError = TRUE;
  1280. }
  1281. Return:
  1282. if (fLogToConsole)
  1283. {
  1284. dwLogApiName = LOG_API_NAME_CONSOLE;
  1285. dwLogInfo = LOG_INFO_CONSOLE;
  1286. }
  1287. ApiNameToString(pLogTestCaseInfo->ApiName, rgwsz);
  1288. ezLogMsg(
  1289. dwLogApiName,
  1290. NULL,
  1291. NULL,
  1292. __LINE__,
  1293. L"%s", rgwsz);
  1294. ezLogMsg(
  1295. dwLogInfo,
  1296. NULL,
  1297. NULL,
  1298. __LINE__,
  1299. L"Returned: %s",
  1300. pLogTestCaseInfo->fReturnVal ? STRING_TRUE : STRING_FALSE);
  1301. if (! pLogTestCaseInfo->fPass)
  1302. {
  1303. switch (pLogTestCaseInfo->dwErrorType)
  1304. {
  1305. case ERROR_API_SUCCEEDED:
  1306. pwsz = L"API succeeded unexpectedly";
  1307. break;
  1308. case ERROR_API_FAILED:
  1309. pwsz = L"API failed unexpectedly";
  1310. break;
  1311. case ERROR_WRONG_ERROR_CODE:
  1312. pwsz = L"API returned an incorrect error code";
  1313. break;
  1314. case ERROR_WIN32_FAILURE:
  1315. pwsz = L"A WIN32 (non-CSP) API failed";
  1316. break;
  1317. case ERROR_WRONG_SIZE:
  1318. pwsz = L"The API returned an incorrect data size";
  1319. break;
  1320. case ERROR_BAD_DATA:
  1321. pwsz = L"The API returned bad data";
  1322. break;
  1323. case ERROR_LIST_TOO_SHORT:
  1324. pwsz = L"The list of algorithms is too short";
  1325. break;
  1326. case ERROR_REQUIRED_ALG:
  1327. pwsz = L"A required algorithm is missing";
  1328. break;
  1329. }
  1330. ezLogMsg(
  1331. dwLogInfo,
  1332. NULL,
  1333. NULL,
  1334. __LINE__,
  1335. L"Error type: %s", pwsz);
  1336. //
  1337. // Display details about the known error status here,
  1338. // after the Error/Warning has been processed above.
  1339. //
  1340. ezLogMsg(
  1341. dwLogInfo,
  1342. NULL,
  1343. NULL,
  1344. __LINE__,
  1345. L"Known error: %s",
  1346. (KNOWN_ERROR_UNKNOWN == pLogTestCaseInfo->KnownErrorID) ? L"No" : L"Yes");
  1347. if (ERROR_WRONG_ERROR_CODE == pLogTestCaseInfo->dwErrorType)
  1348. {
  1349. FormatMessage(
  1350. FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_MAX_WIDTH_MASK,
  1351. NULL,
  1352. pLogTestCaseInfo->dwExpectedErrorCode,
  1353. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  1354. rgwsz,
  1355. BUFFER_SIZE,
  1356. NULL);
  1357. ezLogMsg(
  1358. dwLogInfo,
  1359. NULL,
  1360. NULL,
  1361. __LINE__,
  1362. L"Expected error code: 0x%x (%s)",
  1363. pLogTestCaseInfo->dwExpectedErrorCode,
  1364. rgwsz);
  1365. *rgwsz = L'\0';
  1366. }
  1367. if ( FALSE == pLogTestCaseInfo->fReturnVal ||
  1368. ERROR_API_FAILED == pLogTestCaseInfo->dwErrorType ||
  1369. ERROR_WRONG_ERROR_CODE == pLogTestCaseInfo->dwErrorType ||
  1370. ERROR_WIN32_FAILURE == pLogTestCaseInfo->dwErrorType)
  1371. {
  1372. // Don't get the error string if the error code is 0
  1373. *rgwsz = L'\0';
  1374. if (0 != pLogTestCaseInfo->dwWinError)
  1375. {
  1376. FormatMessage(
  1377. FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_MAX_WIDTH_MASK,
  1378. NULL,
  1379. pLogTestCaseInfo->dwWinError,
  1380. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  1381. rgwsz,
  1382. BUFFER_SIZE,
  1383. NULL);
  1384. }
  1385. ezLogMsg(
  1386. dwLogInfo,
  1387. NULL,
  1388. NULL,
  1389. __LINE__,
  1390. L"Actual error code: 0x%x (%s)",
  1391. pLogTestCaseInfo->dwWinError,
  1392. rgwsz);
  1393. *rgwsz = L'\0';
  1394. }
  1395. //
  1396. // Log details about this failure
  1397. //
  1398. if (NULL != pLogTestCaseInfo->pwszErrorHelp)
  1399. {
  1400. ezLogMsg(
  1401. dwLogInfo,
  1402. NULL,
  1403. NULL,
  1404. __LINE__,
  1405. L"Test case description: %s",
  1406. pLogTestCaseInfo->pwszErrorHelp);
  1407. }
  1408. }
  1409. LogParamInfo(
  1410. pLogTestCaseInfo->pParamInfo,
  1411. pLogTestCaseInfo->cParamInfo,
  1412. fLogToConsole);
  1413. return fReturn;
  1414. }
  1415. //
  1416. // Function: LogGetInteropProvType
  1417. //
  1418. DWORD LogGetInteropProvType(void)
  1419. {
  1420. return g_dwInteropProvType;
  1421. }
  1422. //
  1423. // Function: LogGetInteropProvName
  1424. //
  1425. LPWSTR LogGetInteropProvName(void)
  1426. {
  1427. return g_pwszInteropProvName;
  1428. }
  1429. //
  1430. // Function: LogGetProvType
  1431. // Purpose: Return the provider type for which the CSP under
  1432. // test is registered (in the system registry).
  1433. //
  1434. DWORD LogGetProvType(void)
  1435. {
  1436. return g_dwExternalProvType;
  1437. }
  1438. //
  1439. // Function: LogGetProvName
  1440. // Purpose: Return the provider name for which the CSP under
  1441. // test is registered (in the system registry).
  1442. //
  1443. LPWSTR LogGetProvName(void)
  1444. {
  1445. return g_pwszProvName;
  1446. }
  1447. //
  1448. // Function: LogApiFailure
  1449. //
  1450. BOOL LogApiFailure(
  1451. IN API_NAME ApiName,
  1452. IN DWORD dwErrorType,
  1453. IN OUT PTESTCASE ptc)
  1454. {
  1455. LOGTESTCASEINFO LogTestCaseInfo;
  1456. InitLogTestCaseInfo(ptc, &LogTestCaseInfo);
  1457. LogTestCaseInfo.ApiName = ApiName;
  1458. LogTestCaseInfo.dwErrorType = dwErrorType;
  1459. LogTestCaseInfo.fPass = FALSE;
  1460. return LogTestCase(&LogTestCaseInfo);
  1461. }
  1462. //
  1463. // Function: CheckAndLogStatus
  1464. //
  1465. BOOL CheckAndLogStatus(
  1466. IN API_NAME ApiName,
  1467. IN BOOL fCallSucceeded,
  1468. IN OUT PTESTCASE ptc,
  1469. IN PAPI_PARAM_INFO pParamInfo,
  1470. IN DWORD cParamInfo)
  1471. {
  1472. DWORD dwWinError = 0;
  1473. //DWORD dwTestCaseID = 0;
  1474. LOGTESTCASEINFO LogTestCaseInfo;
  1475. InitLogTestCaseInfo(ptc, &LogTestCaseInfo);
  1476. LogTestCaseInfo.fReturnVal = fCallSucceeded;
  1477. if (! fCallSucceeded)
  1478. {
  1479. dwWinError = GetLastError();
  1480. if (ptc->fExpectSuccess)
  1481. {
  1482. //
  1483. // Test was expected to succeed, but it failed
  1484. //
  1485. LogTestCaseInfo.dwErrorType = ERROR_API_FAILED;
  1486. LogTestCaseInfo.dwWinError = dwWinError;
  1487. }
  1488. else
  1489. {
  1490. if (dwWinError != ptc->dwErrorCode)
  1491. {
  1492. //
  1493. // Test failed as expected, but returned the wrong
  1494. // error code.
  1495. //
  1496. LogTestCaseInfo.dwWinError = dwWinError;
  1497. LogTestCaseInfo.dwErrorType = ERROR_WRONG_ERROR_CODE;
  1498. }
  1499. //
  1500. // Otherwise, the test failed as expected, and it
  1501. // returned the correct error code.
  1502. //
  1503. else
  1504. {
  1505. LogTestCaseInfo.fPass = TRUE;
  1506. }
  1507. }
  1508. }
  1509. else
  1510. {
  1511. if (! ptc->fExpectSuccess)
  1512. {
  1513. //
  1514. // The test was expected to fail, but it succeeded.
  1515. //
  1516. LogTestCaseInfo.dwErrorType = ERROR_API_SUCCEEDED;
  1517. }
  1518. //
  1519. // Otherwise, the test succeeded as expected.
  1520. //
  1521. else
  1522. {
  1523. LogTestCaseInfo.fPass = TRUE;
  1524. }
  1525. }
  1526. //
  1527. // Now dwErrorType will be non-zero in any of three cases:
  1528. // 1) The API should have succeeded, but failed
  1529. // 2) The API should have failed, but succeeded
  1530. // 3) The API failed as expected, but returned the wrong error code
  1531. //
  1532. if (0 != LogTestCaseInfo.dwErrorType)
  1533. {
  1534. LogTestCaseInfo.dwErrorLevel = ptc->dwErrorLevel;
  1535. LogTestCaseInfo.dwExpectedErrorCode = ptc->dwErrorCode;
  1536. //
  1537. // The Microsoft RSA CSP's in Win2K do not return
  1538. // ERROR_INVALID_HANDLE for most, if not all, of the test cases
  1539. // involving that error code in this test suite. Therefore,
  1540. // intercept those error here, and flag them as known for that
  1541. // platform.
  1542. //
  1543. if ( (ERROR_WRONG_ERROR_CODE == LogTestCaseInfo.dwErrorType) &&
  1544. (ERROR_INVALID_HANDLE == LogTestCaseInfo.dwExpectedErrorCode))
  1545. {
  1546. LogTestCaseInfo.KnownErrorID = KNOWN_ERRORINVALIDHANDLE;
  1547. }
  1548. //
  1549. // The Microsoft RSA CSP's in Win2K do not return
  1550. // NTE_BAD_KEY for the negative test cases involving that
  1551. // error code. Intercept those errors here and flag them as
  1552. // known for that platform.
  1553. //
  1554. if ( (ERROR_WRONG_ERROR_CODE == LogTestCaseInfo.dwErrorType) &&
  1555. (NTE_BAD_KEY == LogTestCaseInfo.dwExpectedErrorCode))
  1556. {
  1557. LogTestCaseInfo.KnownErrorID = KNOWN_NTEBADKEY;
  1558. }
  1559. //
  1560. // The Microsoft RSA CSP's in Win2K do not return NTE_BAD_HASH
  1561. // for the negative test cases involving that error code. Intercept
  1562. // those errors here and flag them as known for that platform.
  1563. //
  1564. if ( (ERROR_WRONG_ERROR_CODE == LogTestCaseInfo.dwErrorType) &&
  1565. (NTE_BAD_HASH == LogTestCaseInfo.dwExpectedErrorCode))
  1566. {
  1567. LogTestCaseInfo.KnownErrorID = KNOWN_NTEBADHASH;
  1568. }
  1569. }
  1570. // Finally, increment the current test case ID
  1571. ++ptc->dwTestCaseID;
  1572. LogTestCaseInfo.dwTestCaseID = ptc->dwTestCaseID;
  1573. LogTestCaseInfo.pParamInfo = pParamInfo;
  1574. LogTestCaseInfo.cParamInfo = cParamInfo;
  1575. LogTestCaseInfo.ApiName = ApiName;
  1576. return LogTestCase(&LogTestCaseInfo);
  1577. }
  1578. //
  1579. // Function: InitFailInfo
  1580. //
  1581. void InitLogTestCaseInfo(
  1582. IN PTESTCASE ptc,
  1583. OUT PLOGTESTCASEINFO pLogTestCaseInfo)
  1584. {
  1585. memset(pLogTestCaseInfo, 0, sizeof(LOGTESTCASEINFO));
  1586. pLogTestCaseInfo->dwErrorLevel = ptc->dwErrorLevel;
  1587. pLogTestCaseInfo->dwExpectedErrorCode = ptc->dwErrorCode;
  1588. pLogTestCaseInfo->dwTestCaseID = ptc->dwTestCaseID;
  1589. pLogTestCaseInfo->KnownErrorID = ptc->KnownErrorID;
  1590. pLogTestCaseInfo->pwszErrorHelp = ptc->pwszErrorHelp;
  1591. }
  1592. //
  1593. // Function: LogBadParam
  1594. //
  1595. BOOL LogBadParam(
  1596. API_NAME ApiName,
  1597. LPWSTR pwszErrorHelp,
  1598. PTESTCASE ptc)
  1599. {
  1600. LOGTESTCASEINFO LogTestCaseInfo;
  1601. ++ptc->dwTestCaseID;
  1602. InitLogTestCaseInfo(ptc, &LogTestCaseInfo);
  1603. LogTestCaseInfo.ApiName = ApiName;
  1604. LogTestCaseInfo.dwErrorType = ERROR_BAD_DATA;
  1605. LogTestCaseInfo.pwszErrorHelp = pwszErrorHelp;
  1606. LogTestCaseInfo.fPass = FALSE;
  1607. return LogTestCase(&LogTestCaseInfo);
  1608. }
  1609. //
  1610. // Function: LogProvEnumalgsEx
  1611. //
  1612. void LogProvEnumalgsEx(PROV_ENUMALGS_EX *pData)
  1613. {
  1614. LPWSTR pwszAlgType = NULL;
  1615. LPWSTR pwszName = MkWStr(pData->szName);
  1616. LPWSTR pwszLongName = MkWStr(pData->szLongName);
  1617. // Determine the algorithm type.
  1618. switch(GET_ALG_CLASS(pData->aiAlgid))
  1619. {
  1620. case ALG_CLASS_DATA_ENCRYPT: pwszAlgType = L"Encrypt ";
  1621. break;
  1622. case ALG_CLASS_HASH: pwszAlgType = L"Hash ";
  1623. break;
  1624. case ALG_CLASS_KEY_EXCHANGE: pwszAlgType = L"Exchange ";
  1625. break;
  1626. case ALG_CLASS_SIGNATURE: pwszAlgType = L"Signature";
  1627. break;
  1628. default: pwszAlgType = L"Unknown ";
  1629. }
  1630. // Print information about the algorithm.
  1631. ezLogMsg(
  1632. LOG_INFO,
  1633. NULL,
  1634. NULL,
  1635. __LINE__,
  1636. L"Algid:%8.8xh, Bits:%-4d, %-4d - %-4d, Type:%s",
  1637. pData->aiAlgid,
  1638. pData->dwDefaultLen,
  1639. pData->dwMinLen,
  1640. pData->dwMaxLen,
  1641. pwszAlgType);
  1642. ezLogMsg(
  1643. LOG_INFO,
  1644. NULL,
  1645. NULL,
  1646. __LINE__,
  1647. L" Name: %s LongName: %s Protocols: 0x%x",
  1648. pwszName,
  1649. pwszLongName,
  1650. pData->dwProtocols);
  1651. free(pwszName);
  1652. free(pwszLongName);
  1653. }
  1654. //
  1655. // Function: LogProvEnumalgs
  1656. // Purpose: Log the contents of a PROV_ENUMALGS struct
  1657. //
  1658. void LogProvEnumalgs(PROV_ENUMALGS *pData)
  1659. {
  1660. LPWSTR pwszAlgType = NULL;
  1661. LPWSTR pwszName = MkWStr(pData->szName);
  1662. // Determine the algorithm type.
  1663. switch(GET_ALG_CLASS(pData->aiAlgid))
  1664. {
  1665. case ALG_CLASS_DATA_ENCRYPT: pwszAlgType = L"Encrypt ";
  1666. break;
  1667. case ALG_CLASS_HASH: pwszAlgType = L"Hash ";
  1668. break;
  1669. case ALG_CLASS_KEY_EXCHANGE: pwszAlgType = L"Exchange ";
  1670. break;
  1671. case ALG_CLASS_SIGNATURE: pwszAlgType = L"Signature";
  1672. break;
  1673. default: pwszAlgType = L"Unknown ";
  1674. }
  1675. // Print information about the algorithm.
  1676. ezLogMsg(
  1677. LOG_INFO,
  1678. NULL,
  1679. NULL,
  1680. __LINE__,
  1681. L"Algid:%8.8xh, Bits:%-4d, Type:%s, NameLen:%-2d, Name:%s",
  1682. pData->aiAlgid,
  1683. pData->dwBitLen,
  1684. pwszAlgType,
  1685. pData->dwNameLen,
  1686. pwszName);
  1687. free(pwszName);
  1688. }