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.

517 lines
23 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1996 - 1999
  6. //
  7. // File: test.cpp
  8. //
  9. // Contents: Microsoft Internet Security Authenticode Policy Provider
  10. //
  11. // Functions: SoftpubDumpStructure
  12. //
  13. // History: 05-Jun-1997 pberkman created
  14. //
  15. //--------------------------------------------------------------------------
  16. #include "global.hxx"
  17. #define TEST_POLICY_DUMP_FILE L"C:\\TRUSTPOL.TXT"
  18. void _cdecl FPrintfU(HANDLE hFile, WCHAR *pwszFmt, ...);
  19. void PrintfPFNs(HANDLE hFile, CRYPT_PROVIDER_DATA *pProvData);
  20. void PrintfSignerStruct(HANDLE hFile, CRYPT_PROVIDER_SGNR *pS, int idxSigner, BOOL fCounter, int idxCounter);
  21. void PrintfCertStruct(HANDLE hFile, int cCert, CRYPT_PROVIDER_CERT *pC, int idxCert);
  22. void GetStringDateTime(FILETIME *pFTime, WCHAR *pwszRetTime, WCHAR *pwszRetDate);
  23. WCHAR *GetNameFromBlob(CERT_NAME_BLOB *psNameBlob);
  24. HRESULT WINAPI SoftpubDumpStructure(CRYPT_PROVIDER_DATA *pProvData)
  25. {
  26. HANDLE hFile;
  27. if ((hFile = CreateFileU(TEST_POLICY_DUMP_FILE,
  28. GENERIC_WRITE | GENERIC_READ,
  29. 0, // no sharing!!
  30. NULL,
  31. CREATE_ALWAYS,
  32. FILE_ATTRIBUTE_NORMAL,
  33. NULL)) == INVALID_HANDLE_VALUE)
  34. {
  35. return(S_FALSE);
  36. }
  37. WCHAR wszTime[64];
  38. WCHAR wszDate[128];
  39. WCHAR wszGuid[64];
  40. int i, i2, i3;
  41. //
  42. // CRYPT_PROVIDER_DATA
  43. //
  44. FPrintfU(hFile, L"CRYPT_PROVIDER_DATA:\r\n");
  45. //
  46. // WINTRUST_DATA
  47. //
  48. WINTRUST_DATA *pWT;
  49. pWT = pProvData->pWintrustData;
  50. FPrintfU(hFile, L"+======================================================\r\n");
  51. FPrintfU(hFile, L"+-- pWintrustData:\r\n");
  52. FPrintfU(hFile, L"| |.. cbStruct: %ld\r\n", pWT->cbStruct);
  53. FPrintfU(hFile, L"| |.. pPolicyCallbackData: %p\r\n", pWT->pPolicyCallbackData);
  54. FPrintfU(hFile, L"| |.. dwUIChoice: %ld\r\n", pWT->dwUIChoice);
  55. FPrintfU(hFile, L"| |.. fdRevocationChecks: %ld\r\n", pWT->fdwRevocationChecks);
  56. FPrintfU(hFile, L"| |.. dwUnionChoice: %ld\r\n", pWT->dwUnionChoice);
  57. switch (pWT->dwUnionChoice)
  58. {
  59. case WTD_CHOICE_FILE:
  60. if (!(pWT->pFile) ||
  61. !(WVT_IS_CBSTRUCT_GT_MEMBEROFFSET(WINTRUST_FILE_INFO, pWT->pFile->cbStruct, hFile)))
  62. {
  63. FPrintfU(hFile, L"| +-- pFile: <<< bad parameter! >>>\r\n");
  64. break;
  65. }
  66. FPrintfU(hFile, L"| +-- pFile:\r\n");
  67. FPrintfU(hFile, L"| |.. cbStruct: %ld\r\n", pWT->pFile->cbStruct);
  68. FPrintfU(hFile, L"| |.. pcwszFilePath: %s\r\n", pWT->pFile->pcwszFilePath);
  69. FPrintfU(hFile, L"| |.. hFile: 0x%p\r\n", pWT->pFile->hFile);
  70. wszGuid[0] = NULL;
  71. if (WVT_IS_CBSTRUCT_GT_MEMBEROFFSET(WINTRUST_FILE_INFO,
  72. pWT->pFile->cbStruct, pgKnownSubject) &&
  73. pWT->pFile->pgKnownSubject)
  74. {
  75. guid2wstr(pWT->pFile->pgKnownSubject, &wszGuid[0]);
  76. }
  77. FPrintfU(hFile, L"| +-- pgKnownSubject: %s\r\n", &wszGuid[0]);
  78. break;
  79. case WTD_CHOICE_CATALOG:
  80. if (!(pWT->pCatalog) ||
  81. !(WVT_IS_CBSTRUCT_GT_MEMBEROFFSET(WINTRUST_CATALOG_INFO, pWT->pCatalog->cbStruct, hMemberFile)))
  82. {
  83. FPrintfU(hFile, L"| +-- pCatalog: <<< bad parameter! >>>\r\n");
  84. break;
  85. }
  86. FPrintfU(hFile, L"| +-- pCatalog:\r\n");
  87. FPrintfU(hFile, L"| |.. cbStruct: %ld\r\n", pWT->pCatalog->cbStruct);
  88. FPrintfU(hFile, L"| |.. dwCatalogVersion: 0x%lx\r\n", pWT->pCatalog->dwCatalogVersion);
  89. FPrintfU(hFile, L"| |.. pcwszCatalogFilePath: %s\r\n", pWT->pCatalog->pcwszCatalogFilePath);
  90. FPrintfU(hFile, L"| |.. pcwszMemberTag: %s\r\n", pWT->pCatalog->pcwszMemberTag);
  91. FPrintfU(hFile, L"| |.. pcwszMemberFilePath: %s\r\n", pWT->pCatalog->pcwszMemberFilePath);
  92. FPrintfU(hFile, L"| |.. hMemberFile: 0x%p\r\n", pWT->pCatalog->hMemberFile);
  93. FPrintfU(hFile, L"| |.. pbCaclulatedFileHash: ");
  94. for (i = 0; i < (int)pWT->pCatalog->cbCalculatedFileHash; i++)
  95. {
  96. FPrintfU(hFile, L"%02.2X", pWT->pCatalog->pbCalculatedFileHash[i]);
  97. }
  98. FPrintfU(hFile, L"\r\n");
  99. FPrintfU(hFile, L"| +-- cbCaclulatedFileHash: %ld\r\n", pWT->pCatalog->cbCalculatedFileHash);
  100. break;
  101. case WTD_CHOICE_BLOB:
  102. if (!(pWT->pBlob) ||
  103. !(WVT_IS_CBSTRUCT_GT_MEMBEROFFSET(WINTRUST_BLOB_INFO, pWT->pBlob->cbStruct, pbMemSignedMsg)))
  104. {
  105. FPrintfU(hFile, L"| +-- pBlob: <<< bad parameter! >>>\r\n");
  106. break;
  107. }
  108. FPrintfU(hFile, L"| +-- pBlob:\r\n");
  109. FPrintfU(hFile, L"| |.. cbStruct: %ld\r\n", pWT->pBlob->cbStruct);
  110. wszGuid[0] = NULL;
  111. guid2wstr(&pWT->pBlob->gSubject, &wszGuid[0]);
  112. FPrintfU(hFile, L" |.. gSubject: %s\r\n", &wszGuid[0]);
  113. FPrintfU(hFile, L"| |.. pcwszDisplayName: %s\r\n", pWT->pBlob->pcwszDisplayName);
  114. FPrintfU(hFile, L"| |.. cbMemObject: %ld\r\n", pWT->pBlob->cbMemObject);
  115. FPrintfU(hFile, L"| |.. pbMemObject: 0x%p\r\n", pWT->pBlob->pbMemObject);
  116. FPrintfU(hFile, L"| |.. cbMemSignedMsg: %ld\r\n", pWT->pBlob->cbMemSignedMsg);
  117. FPrintfU(hFile, L"| +.. pbMemSignedMsg: 0x%p\r\n", pWT->pBlob->pbMemSignedMsg);
  118. break;
  119. case WTD_CHOICE_SIGNER:
  120. if (!(pWT->pSgnr) ||
  121. !(WVT_IS_CBSTRUCT_GT_MEMBEROFFSET(WINTRUST_SGNR_INFO, pWT->pSgnr->cbStruct, pahStores)))
  122. {
  123. FPrintfU(hFile, L"| +-- pSgnr: <<< bad parameter! >>>\r\n");
  124. break;
  125. }
  126. FPrintfU(hFile, L"| +-- pSgnr:\r\n");
  127. FPrintfU(hFile, L"| |.. cbStruct: %ld\r\n", pWT->pSgnr->cbStruct);
  128. FPrintfU(hFile, L"| |.. pcwszDisplayName: %s\r\n", pWT->pSgnr->pcwszDisplayName);
  129. FPrintfU(hFile, L"| |.. psSignerInfo: 0x%p\r\n", pWT->pSgnr->psSignerInfo);
  130. FPrintfU(hFile, L"| |.. chStores: %ld\r\n", pWT->pSgnr->chStores);
  131. for (i = 0; i < (int)pWT->pSgnr->chStores; i++)
  132. {
  133. if (i == (int)(pWT->pSgnr->chStores - 1))
  134. {
  135. FPrintfU(hFile, L"| +.. pahStores[%02.2d]: 0x%p\r\n", i, pWT->pSgnr->pahStores[i]);
  136. }
  137. else
  138. {
  139. FPrintfU(hFile, L"| |.. pahStores[%02.2d]: 0x%p\r\n", i, pWT->pSgnr->pahStores[i]);
  140. }
  141. }
  142. break;
  143. case WTD_CHOICE_CERT:
  144. if (!(pWT->pCert) ||
  145. !(WVT_IS_CBSTRUCT_GT_MEMBEROFFSET(WINTRUST_CERT_INFO, pWT->pCert->cbStruct, psftVerifyAsOf)))
  146. {
  147. FPrintfU(hFile, L"| +-- pCert: <<< bad parameter! >>>\r\n");
  148. break;
  149. }
  150. FPrintfU(hFile, L"| +-- pCert:\r\n");
  151. FPrintfU(hFile, L"| |.. cbStruct: %ld\r\n", pWT->pCert->cbStruct);
  152. FPrintfU(hFile, L"| |.. pcwszDisplayName: %s\r\n", pWT->pCert->pcwszDisplayName);
  153. FPrintfU(hFile, L"| |.. psCertContext: 0x%p\r\n", pWT->pCert->psCertContext);
  154. FPrintfU(hFile, L"| |.. chStores: %ld\r\n", pWT->pCert->chStores);
  155. for (i = 0; i < (int)pWT->pCert->chStores; i++)
  156. {
  157. FPrintfU(hFile, L"| |.. pahStores[%02.2d]: 0x%p\r\n", i, pWT->pCert->pahStores[i]);
  158. }
  159. FPrintfU(hFile, L"| |.. dwFlags: 0x%08.8lX\r\n", pWT->pCert->dwFlags);
  160. wszTime[0] = NULL;
  161. wszDate[0] = NULL;
  162. if (pWT->pCert->psftVerifyAsOf)
  163. {
  164. GetStringDateTime(pWT->pCert->psftVerifyAsOf, &wszTime[0], &wszDate[0]);
  165. }
  166. FPrintfU(hFile, L"| |-- psftVerifyAsOf: %s - %s\r\n", &wszDate[0], &wszTime[0]);
  167. break;
  168. default:
  169. FPrintfU(hFile, L"| +.. ***Unknown structure type***\r\n");
  170. break;
  171. }
  172. FPrintfU(hFile, L"|.. WndParent: 0x%p\r\n", pProvData->hWndParent);
  173. wszGuid[0] = NULL;
  174. guid2wstr(pProvData->pgActionID, &wszGuid[0]);
  175. FPrintfU(hFile, L"|.. pgActionID: %s\r\n", &wszGuid[0]);
  176. FPrintfU(hFile, L"|.. hProv: 0x%p\r\n", pProvData->hProv);
  177. FPrintfU(hFile, L"|.. dwError: 0x%08.8lx\r\n", pProvData->dwError);
  178. FPrintfU(hFile, L"|.. dwRegSecuritySettings: 0x%08.8lx\r\n", pProvData->dwRegSecuritySettings);
  179. FPrintfU(hFile, L"|.. dwRegPolicySettings: 0x%08.8lx\r\n", pProvData->dwRegPolicySettings);
  180. FPrintfU(hFile, L"|.. dwEncoding: 0x%08.8lx\r\n", pProvData->dwEncoding);
  181. PrintfPFNs(hFile, pProvData);
  182. FPrintfU(hFile, L"|.. padwTrustStepErrors:\r\n");
  183. for (i = 0; i < (int)pProvData->cdwTrustStepErrors; i++)
  184. {
  185. if (i == (int)(pProvData->cdwTrustStepErrors - 1))
  186. {
  187. FPrintfU(hFile, L"| +.. Step[%02.2d]: 0x%08.8lx\r\n", i, pProvData->padwTrustStepErrors[i]);
  188. }
  189. else
  190. {
  191. FPrintfU(hFile, L"| |.. Step[%02.2d]: 0x%08.8lx\r\n", i, pProvData->padwTrustStepErrors[i]);
  192. }
  193. }
  194. FPrintfU(hFile, L"|.. pahStores:\r\n");
  195. for (i = 0; i < (int)pProvData->chStores; i++)
  196. {
  197. if (i == (int)(pProvData->chStores - 1))
  198. {
  199. FPrintfU(hFile, L"| +.. Store[%02.2d]: 0x%lx\r\n", i, pProvData->pahStores[i]);
  200. }
  201. else
  202. {
  203. FPrintfU(hFile, L"| |.. Store[%02.2d]: 0x%lx\r\n", i, pProvData->pahStores[i]);
  204. }
  205. }
  206. FPrintfU(hFile, L"|.. hMsg: 0x%p\r\n", pProvData->hMsg);
  207. if (pProvData->dwSubjectChoice == CPD_CHOICE_SIP)
  208. {
  209. wszGuid[0] = NULL;
  210. guid2wstr(&pProvData->pPDSip->gSubject, &wszGuid[0]);
  211. FPrintfU(hFile, L"|.. pPDSip:\r\n");
  212. FPrintfU(hFile, L"| |.. gSubject: %s\r\n", &wszGuid[0]);
  213. FPrintfU(hFile, L"| |.. pSip: 0x%p\r\n", pProvData->pPDSip->pSip);
  214. FPrintfU(hFile, L"| |.. pCATSip: 0x%p\r\n", pProvData->pPDSip->pCATSip);
  215. // TBDTBD: break it out!
  216. FPrintfU(hFile, L"| |.. psSipSubjectInfo: 0x%p\r\n", pProvData->pPDSip->psSipSubjectInfo);
  217. // TBDTBD: break it out!
  218. FPrintfU(hFile, L"| |.. psSipCATSubjectInfo: 0x%p\r\n", pProvData->pPDSip->psSipCATSubjectInfo);
  219. // TBDTBD: break it out!
  220. FPrintfU(hFile, L"| +.. psIndirectData: 0x%p\r\n", pProvData->pPDSip->psIndirectData);
  221. }
  222. FPrintfU(hFile, L"|.. csSigners: %lu\r\n", pProvData->csSigners);
  223. CRYPT_PROVIDER_SGNR *pSgnr;
  224. CRYPT_PROVIDER_SGNR *pCounterSgnr;
  225. for (i = 0; i < (int)pProvData->csSigners; i++)
  226. {
  227. pSgnr = WTHelperGetProvSignerFromChain(pProvData, i, FALSE, 0);
  228. PrintfSignerStruct(hFile, pSgnr, i, FALSE, 0);
  229. if (pSgnr->csCounterSigners > 0)
  230. {
  231. for (i2 = 0; i2 < (int)pSgnr->csCounterSigners; i2++)
  232. {
  233. pCounterSgnr = WTHelperGetProvSignerFromChain(pProvData, i, TRUE, i2);
  234. PrintfSignerStruct(hFile, pCounterSgnr, i, TRUE, i2);
  235. }
  236. }
  237. }
  238. FPrintfU(hFile, L"|.. pszUsageOID: %p\r\n", pProvData->pszUsageOID);
  239. FPrintfU(hFile, L"|.. fRecallWithState: %s\r\n", (pProvData->fRecallWithState) ? "TRUE" : "FALSE");
  240. GetStringDateTime(&pProvData->sftSystemTime, &wszTime[0], &wszDate[0]);
  241. FPrintfU(hFile, L"|.. sftSystemTime: %s - %s\r\n", &wszDate[0], &wszTime[0]);
  242. FPrintfU(hFile, L"+======================================================\r\n");
  243. CloseHandle(hFile);
  244. return(S_OK);
  245. }
  246. void PrintfPFNs(HANDLE hFile, CRYPT_PROVIDER_DATA *pPD)
  247. {
  248. FPrintfU(hFile, L"|.. psPfns:\r\n");
  249. if (!(pPD->psPfns) ||
  250. !(WVT_IS_CBSTRUCT_GT_MEMBEROFFSET(CRYPT_PROVIDER_FUNCTIONS, pPD->psPfns->cbStruct, pfnTestFinalPolicy)))
  251. {
  252. FPrintfU(hFile, L"| +.. *** invalid parameter ***\r\n");
  253. return;
  254. }
  255. FPrintfU(hFile, L"| |.. cbStruct: %lu\r\n", pPD->psPfns->cbStruct);
  256. FPrintfU(hFile, L"| |.. pfnAlloc: 0x%p\r\n", pPD->psPfns->pfnAlloc);
  257. FPrintfU(hFile, L"| |.. pfnFree: 0x%p\r\n", pPD->psPfns->pfnFree);
  258. FPrintfU(hFile, L"| |.. pfnAddStore2Chain: 0x%p\r\n", pPD->psPfns->pfnAddStore2Chain);
  259. FPrintfU(hFile, L"| |.. pfnAddSgnr2Chain: 0x%p\r\n", pPD->psPfns->pfnAddSgnr2Chain);
  260. FPrintfU(hFile, L"| |.. pfnAddCert2Chain: 0x%p\r\n", pPD->psPfns->pfnAddCert2Chain);
  261. FPrintfU(hFile, L"| |.. pfnAddPrivData2Chain: 0x%p\r\n", pPD->psPfns->pfnAddPrivData2Chain);
  262. FPrintfU(hFile, L"| |.. pfnInitialize: 0x%p\r\n", pPD->psPfns->pfnInitialize);
  263. FPrintfU(hFile, L"| |.. pfnObjectTrust: 0x%p\r\n", pPD->psPfns->pfnObjectTrust);
  264. FPrintfU(hFile, L"| |.. pfnSignatureTrust: 0x%p\r\n", pPD->psPfns->pfnSignatureTrust);
  265. FPrintfU(hFile, L"| |.. pfnCertificateTrust: 0x%p\r\n", pPD->psPfns->pfnCertificateTrust);
  266. FPrintfU(hFile, L"| |.. pfnFinalPolicy: 0x%p\r\n", pPD->psPfns->pfnFinalPolicy);
  267. FPrintfU(hFile, L"| |.. pfnCertCheckPolicy: 0x%p\r\n", pPD->psPfns->pfnCertCheckPolicy);
  268. FPrintfU(hFile, L"| |.. pfnTestFinalPolicy: 0x%p\r\n", pPD->psPfns->pfnTestFinalPolicy);
  269. if (WVT_IS_CBSTRUCT_GT_MEMBEROFFSET(CRYPT_PROVIDER_FUNCTIONS, pPD->psPfns->cbStruct, pfnCleanupPolicy))
  270. {
  271. FPrintfU(hFile, L"| |.. pfnCleanupPolicy: 0x%p\r\n", pPD->psPfns->pfnCleanupPolicy);
  272. }
  273. FPrintfU(hFile, L"| +.. psUIpfns:\r\n");
  274. if (!(pPD->psPfns->psUIpfns) ||
  275. !(WVT_IS_CBSTRUCT_GT_MEMBEROFFSET(CRYPT_PROVUI_FUNCS, pPD->psPfns->psUIpfns->cbStruct, pfnOnAdvancedClickDefault)))
  276. {
  277. FPrintfU(hFile, L"| +.. *** invalid parameter ***\r\n");
  278. return;
  279. }
  280. FPrintfU(hFile, L"| |.. cbStruct: %lu\r\n", pPD->psPfns->psUIpfns->cbStruct);
  281. FPrintfU(hFile, L"| |.. psUIData:\r\n");
  282. if (!(pPD->psPfns->psUIpfns->psUIData) ||
  283. !(WVT_IS_CBSTRUCT_GT_MEMBEROFFSET(CRYPT_PROVUI_DATA, pPD->psPfns->psUIpfns->psUIData->cbStruct, pCopyActionTextNotSigned)))
  284. {
  285. FPrintfU(hFile, L"| | +.. *** invalid parameter ***\r\n");
  286. }
  287. else
  288. {
  289. FPrintfU(hFile, L"| | |.. cbStruct: %lu\r\n", pPD->psPfns->psUIpfns->psUIData->cbStruct);
  290. FPrintfU(hFile, L"| | |.. dwFinalError: 0x%08.8lx\r\n", pPD->psPfns->psUIpfns->psUIData->dwFinalError);
  291. FPrintfU(hFile, L"| | |.. pYesButtonText: %s\r\n", pPD->psPfns->psUIpfns->psUIData->pYesButtonText);
  292. FPrintfU(hFile, L"| | |.. pNoButtonText: %s\r\n", pPD->psPfns->psUIpfns->psUIData->pNoButtonText);
  293. FPrintfU(hFile, L"| | |.. pMoreInfoButtonText: %s\r\n", pPD->psPfns->psUIpfns->psUIData->pMoreInfoButtonText);
  294. FPrintfU(hFile, L"| | |.. pAdvancedLinkText: %s\r\n", pPD->psPfns->psUIpfns->psUIData->pAdvancedLinkText);
  295. FPrintfU(hFile, L"| | |.. pCopyActionText: %s\r\n", pPD->psPfns->psUIpfns->psUIData->pCopyActionText);
  296. FPrintfU(hFile, L"| | |.. pCopyActionTextNoTS: %s\r\n", pPD->psPfns->psUIpfns->psUIData->pCopyActionTextNoTS);
  297. FPrintfU(hFile, L"| | |.. pCopyActionTextNotSigned: %s\r\n", pPD->psPfns->psUIpfns->psUIData->pCopyActionTextNotSigned);
  298. }
  299. FPrintfU(hFile, L"| |.. pfnOnMoreInfoClick: 0x%p\r\n", pPD->psPfns->psUIpfns->pfnOnMoreInfoClick);
  300. FPrintfU(hFile, L"| |.. pfnOnMoreInfoClickDefault:0x%p\r\n", pPD->psPfns->psUIpfns->pfnOnMoreInfoClickDefault);
  301. FPrintfU(hFile, L"| |.. pfnOnAdvancedClick: 0x%p\r\n", pPD->psPfns->psUIpfns->pfnOnAdvancedClick);
  302. FPrintfU(hFile, L"| +.. pfnOnAdvancedClickDefault:0x%p\r\n", pPD->psPfns->psUIpfns->pfnOnAdvancedClickDefault);
  303. }
  304. void PrintfSignerStruct(HANDLE hFile, CRYPT_PROVIDER_SGNR *pS, int idxSigner, BOOL fCounter, int idxCounter)
  305. {
  306. if (!(fCounter))
  307. {
  308. FPrintfU(hFile, L"|.. pasSigners[%d]:\r\n", idxSigner);
  309. }
  310. else
  311. {
  312. FPrintfU(hFile, L"|.. pasSigners[%d] - CounterSigner[%d]:\r\n", idxSigner, idxCounter);
  313. }
  314. FPrintfU(hFile, L"| |.. cbStruct: %lu\r\n", pS->cbStruct);
  315. WCHAR wszTime[64];
  316. WCHAR wszDate[128];
  317. GetStringDateTime(&pS->sftVerifyAsOf, &wszTime[0], &wszDate[0]);
  318. FPrintfU(hFile, L"| |.. sftVerifyAsOf: %s - %s\r\n", &wszDate[0], &wszTime[0]);
  319. FPrintfU(hFile, L"| |.. dwSignerType: 0x%08.8lX\r\n", pS->dwSignerType);
  320. FPrintfU(hFile, L"| |.. csCertChain: %lu\r\n", pS->csCertChain);
  321. CRYPT_PROVIDER_CERT *pCert;
  322. for (int i = 0; i < (int)pS->csCertChain; i++)
  323. {
  324. pCert = WTHelperGetProvCertFromChain(pS, i);
  325. PrintfCertStruct(hFile, pS->csCertChain, pCert, i);
  326. }
  327. FPrintfU(hFile, L"| |.. psSigner: 0x%p\r\n", pS->psSigner);
  328. FPrintfU(hFile, L"| |.. dwError: 0x%08.8lx\r\n", pS->dwError);
  329. FPrintfU(hFile, L"| +.. csCounterSigners: %ld\r\n", pS->csCounterSigners);
  330. }
  331. void PrintfCertStruct(HANDLE hFile, int cCert, CRYPT_PROVIDER_CERT *pC, int idxCert)
  332. {
  333. WCHAR wszTime[64];
  334. WCHAR wszDate[128];
  335. if (idxCert < (cCert - 1))
  336. {
  337. FPrintfU(hFile, L"| | |.. casCertChain[%d]:\r\n", idxCert);
  338. }
  339. else
  340. {
  341. FPrintfU(hFile, L"| | +.. casCertChain[%d]:\r\n", idxCert);
  342. }
  343. FPrintfU(hFile, L"| | | |.. cbStruct: %ld\r\n", pC->cbStruct);
  344. FPrintfU(hFile, L"| | | |.. pCert: 0x%p\r\n", pC->pCert);
  345. FPrintfU(hFile, L"| | | | |.. dwCertEncoding: 0x%08.8lx\r\n", pC->pCert->dwCertEncodingType);
  346. FPrintfU(hFile, L"| | | | |.. pCertInfo:\r\n");
  347. FPrintfU(hFile, L"| | | | | |.. Issuer: %s\r\n", GetNameFromBlob(&pC->pCert->pCertInfo->Issuer));
  348. GetStringDateTime(&pC->pCert->pCertInfo->NotBefore, &wszTime[0], &wszDate[0]);
  349. FPrintfU(hFile, L"| | | | | |.. NotBefore: %s - %s\r\n", &wszDate[0], &wszTime[0]);
  350. GetStringDateTime(&pC->pCert->pCertInfo->NotAfter, &wszTime[0], &wszDate[0]);
  351. FPrintfU(hFile, L"| | | | | |.. NotAfter: %s - %s\r\n", &wszDate[0], &wszTime[0]);
  352. FPrintfU(hFile, L"| | | | | +.. Subject: %s\r\n", GetNameFromBlob(&pC->pCert->pCertInfo->Subject));
  353. FPrintfU(hFile, L"| | | | +.. hCertStore: 0x%p\r\n", pC->pCert->hCertStore);
  354. FPrintfU(hFile, L"| | | |.. fCommercial: %s\r\n", (pC->fCommercial) ? L"True" : L"False");
  355. FPrintfU(hFile, L"| | | |.. fTrustedRoot: %s\r\n", (pC->fTrustedRoot) ? L"True" : L"False");
  356. FPrintfU(hFile, L"| | | |.. fSelfSigned: %s\r\n", (pC->fSelfSigned) ? L"True" : L"False");
  357. FPrintfU(hFile, L"| | | |.. fTestCert: %s\r\n", (pC->fTestCert) ? L"True" : L"False");
  358. FPrintfU(hFile, L"| | | |.. dwRevokedReason: 0x%08.8lx\r\n", pC->dwRevokedReason);
  359. FPrintfU(hFile, L"| | | |.. dwConfidence: 0x%08.8lx\r\n", pC->dwConfidence);
  360. FPrintfU(hFile, L"| | | |.. pTrustListContext: 0x%p\r\n", pC->pTrustListContext);
  361. if (idxCert == (cCert - 1))
  362. {
  363. FPrintfU(hFile, L"| | +-- +.. dwError: 0x%08.8lx\r\n", pC->dwError);
  364. }
  365. else
  366. {
  367. FPrintfU(hFile, L"| | | +.. dwError: 0x%08.8lx\r\n", pC->dwError);
  368. }
  369. }
  370. void _cdecl FPrintfU(HANDLE hFile, WCHAR *pwszFmt, ...)
  371. {
  372. va_list vaArgs;
  373. WCHAR wsz[2048];
  374. char sz[2048];
  375. DWORD cbWritten;
  376. DWORD cbConv;
  377. va_start(vaArgs, pwszFmt);
  378. vswprintf(&wsz[0], pwszFmt, vaArgs);
  379. va_end(vaArgs);
  380. cbConv = 2048;
  381. cbConv = WideCharToMultiByte(0, 0,
  382. &wsz[0], wcslen(&wsz[0]) + 1,
  383. &sz[0], cbConv, NULL, NULL);
  384. sz[cbConv] = NULL;
  385. cbWritten = 0;
  386. WriteFile(hFile, &sz[0], cbConv, &cbWritten, NULL);
  387. }
  388. void GetStringDateTime(FILETIME *pFTime, WCHAR *pwszRetTime, WCHAR *pwszRetDate)
  389. {
  390. SYSTEMTIME sSysTime;
  391. char szTime[128];
  392. char szDate[128];
  393. memset(&sSysTime, 0x00, sizeof(SYSTEMTIME));
  394. FileTimeToSystemTime(pFTime, &sSysTime);
  395. szTime[0] = 0;
  396. GetTimeFormat(LOCALE_USER_DEFAULT, TIME_FORCE24HOURFORMAT, &sSysTime, NULL, &szTime[0], 64);
  397. MultiByteToWideChar(CP_ACP, 0, (const char *)&szTime[0], -1, pwszRetTime, 64);
  398. szDate[0] = 0;
  399. GetDateFormat(LOCALE_USER_DEFAULT, 0, &sSysTime, TEXT("dd'-'MMM'-'yyyy"), &szDate[0], 128);
  400. MultiByteToWideChar(CP_ACP, 0, (const char *)&szDate[0], -1, pwszRetDate, 128);
  401. }
  402. WCHAR *GetNameFromBlob(CERT_NAME_BLOB *psNameBlob)
  403. {
  404. static WCHAR wsz[256];
  405. PCERT_NAME_INFO pNameInfo;
  406. PCERT_RDN_ATTR pRDNAttr;
  407. DWORD cbInfo;
  408. cbInfo = 0;
  409. wsz[0] = NULL;
  410. CryptDecodeObject(X509_ASN_ENCODING, X509_NAME, psNameBlob->pbData, psNameBlob->cbData,
  411. 0, NULL, &cbInfo);
  412. if (cbInfo > 0)
  413. {
  414. if (pNameInfo = (PCERT_NAME_INFO)new BYTE[cbInfo])
  415. {
  416. if (CryptDecodeObject(X509_ASN_ENCODING, X509_NAME, psNameBlob->pbData, psNameBlob->cbData,
  417. 0, pNameInfo, &cbInfo))
  418. {
  419. if (pRDNAttr = CertFindRDNAttr(szOID_COMMON_NAME, pNameInfo))
  420. {
  421. CertRDNValueToStrW(pRDNAttr->dwValueType, &pRDNAttr->Value, wsz, 256);;
  422. }
  423. }
  424. delete pNameInfo;
  425. }
  426. }
  427. return(&wsz[0]);
  428. }