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.

138 lines
3.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1996 - 1999
  6. //
  7. // File: wvtcert.cpp
  8. //
  9. // Contents: performance suite
  10. //
  11. // History: 04-Dec-1997 pberkman created
  12. //
  13. //--------------------------------------------------------------------------
  14. #include "global.hxx"
  15. void _LoadCerts(PCERT_CONTEXT *ppCerts);
  16. #define _MAX_CERTS 4
  17. DWORD WINAPI TestWVTCert(ThreadData *psData)
  18. {
  19. COleDateTime tStart;
  20. COleDateTime tEnd;
  21. DWORD i;
  22. DWORD iCert;
  23. HRESULT hr;
  24. PCCERT_CONTEXT pcCerts[_MAX_CERTS];
  25. WINTRUST_DATA sWTD;
  26. WINTRUST_CERT_INFO sWTCC;
  27. printf("\n WVT_CERT");
  28. psData->dwTotalProcessed = 0;
  29. _LoadCerts((PCERT_CONTEXT *)&pcCerts[0]);
  30. memset(&sWTD, 0x00, sizeof(WINTRUST_DATA));
  31. memset(&sWTCC, 0x00, sizeof(WINTRUST_CERT_INFO));
  32. sWTD.cbStruct = sizeof(WINTRUST_DATA);
  33. sWTD.dwUIChoice = WTD_UI_NONE;
  34. sWTD.dwUnionChoice = WTD_CHOICE_CERT;
  35. sWTD.pCert = &sWTCC;
  36. sWTCC.cbStruct = sizeof(WINTRUST_CERT_INFO);
  37. sWTCC.pcwszDisplayName = L"WVTCERT";
  38. tStart = COleDateTime::GetCurrentTime();
  39. for (i = 0; i < cPasses; i++)
  40. {
  41. for (iCert = 0; iCert < _MAX_CERTS; iCert++)
  42. {
  43. if (pcCerts[iCert])
  44. {
  45. sWTCC.psCertContext = (CERT_CONTEXT *)pcCerts[iCert];
  46. hr = WinVerifyTrust(NULL, &gCertProvider, &sWTD);
  47. psData->dwTotalProcessed++;
  48. if (fVerbose)
  49. {
  50. printf("\n cert check returned: 0x%08.8lX", hr);
  51. }
  52. }
  53. }
  54. }
  55. tEnd = COleDateTime::GetCurrentTime();
  56. psData->tsTotal = tEnd - tStart;
  57. for (i = 0; i < _MAX_CERTS; i++)
  58. {
  59. if (pcCerts[i])
  60. {
  61. CertFreeCertificateContext(pcCerts[i]);
  62. }
  63. }
  64. return(0);
  65. }
  66. void _LoadCerts(PCERT_CONTEXT *ppCerts)
  67. {
  68. HRSRC hrsrc;
  69. int i;
  70. CRYPT_DATA_BLOB sBlob;
  71. PCCERT_CONTEXT pCert;
  72. HGLOBAL hglobRes;
  73. HCERTSTORE hResStore;
  74. for (i = 0; i < (_MAX_CERTS); i++)
  75. {
  76. ppCerts[i] = NULL;
  77. }
  78. if (hrsrc = FindResource(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_CERTS), TEXT("CERTS")))
  79. {
  80. if (hglobRes = LoadResource(GetModuleHandle(NULL), hrsrc))
  81. {
  82. sBlob.cbData = SizeofResource(GetModuleHandle(NULL), hrsrc);
  83. sBlob.pbData = (BYTE *)LockResource(hglobRes);
  84. hResStore = CertOpenStore(CERT_STORE_PROV_SERIALIZED,
  85. X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
  86. NULL,
  87. CERT_STORE_NO_CRYPT_RELEASE_FLAG,
  88. &sBlob);
  89. if (!(hResStore))
  90. {
  91. UnlockResource(hglobRes);
  92. FreeResource(hglobRes);
  93. return;
  94. }
  95. i = 0;
  96. pCert = NULL;
  97. while (((pCert = CertEnumCertificatesInStore(hResStore, pCert)) !=NULL) &&
  98. (i < _MAX_CERTS))
  99. {
  100. ppCerts[i] = (PCERT_CONTEXT)CertDuplicateCertificateContext(pCert);
  101. i++;
  102. }
  103. CertCloseStore(hResStore, 0);
  104. UnlockResource(hglobRes);
  105. FreeResource(hglobRes);
  106. }
  107. }
  108. }