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.

1357 lines
40 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1996 - 1999
  6. //
  7. // File: drvprov.cpp
  8. //
  9. // Contents: Microsoft Internet Security Authenticode Policy Provider
  10. //
  11. // Functions: DriverInitializePolicy
  12. // DriverCleanupPolicy
  13. // DriverFinalPolicy
  14. // DriverRegisterServer
  15. // DriverUnregisterServer
  16. //
  17. // *** local functions ***
  18. // _ValidCatAttr
  19. // _CheckVersionAttributeNEW
  20. // _CheckVersionNEW
  21. // _GetVersionNumbers
  22. //
  23. // History: 29-Sep-1997 pberkman created
  24. //
  25. //--------------------------------------------------------------------------
  26. #include "global.hxx"
  27. BOOL _GetVersionNumbers(
  28. WCHAR *pwszMM,
  29. DWORD *pdwMajor,
  30. DWORD *pdwMinor,
  31. DWORD *pdwBuild,
  32. WCHAR *pwcFlagMinor,
  33. WCHAR *pwcFlagBuild);
  34. BOOL _ValidCatAttr(CRYPTCATATTRIBUTE *pAttr);
  35. BOOL _CheckVersionAttributeNEW(DRIVER_VER_INFO *pVerInfo, CRYPTCATATTRIBUTE *pAttr);
  36. DWORD _CheckVersionNEW(OSVERSIONINFO *pVersion, WCHAR *pwszAttr, BOOL fUseBuildNumber);
  37. static LPSTR rgDriverUsages[] = {szOID_WHQL_CRYPTO, szOID_NT5_CRYPTO, szOID_OEM_WHQL_CRYPTO};
  38. static CERT_USAGE_MATCH RequestUsage = {USAGE_MATCH_TYPE_OR, {sizeof(rgDriverUsages)/sizeof(LPSTR), rgDriverUsages}};
  39. typedef struct _DRVPROV_PRIVATE_DATA
  40. {
  41. DWORD cbStruct;
  42. CRYPT_PROVIDER_FUNCTIONS sAuthenticodePfns;
  43. } DRVPROV_PRIVATE_DATA, *PDRVPROV_PRIVATE_DATA;
  44. #define VER_CHECK_EQ 1
  45. #define VER_CHECK_GT 2
  46. #define VER_CHECK_LT 3
  47. #define VER_CHECK_FAIL 4
  48. HRESULT WINAPI DriverInitializePolicy(CRYPT_PROVIDER_DATA *pProvData)
  49. {
  50. if (!(pProvData->padwTrustStepErrors) ||
  51. (pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_WVTINIT] != ERROR_SUCCESS))
  52. {
  53. return (S_FALSE);
  54. }
  55. if (!(_ISINSTRUCT(CRYPT_PROVIDER_DATA, pProvData->cbStruct, pRequestUsage)))
  56. {
  57. pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_INITPROV] = ERROR_INVALID_PARAMETER;
  58. return (S_FALSE);
  59. }
  60. GUID gAuthenticode = WINTRUST_ACTION_GENERIC_VERIFY_V2;
  61. GUID gDriverProv = DRIVER_ACTION_VERIFY;
  62. CRYPT_PROVIDER_PRIVDATA sPrivData;
  63. CRYPT_PROVIDER_PRIVDATA *pPrivData;
  64. DRVPROV_PRIVATE_DATA *pDriverData;
  65. HRESULT hr;
  66. hr = S_OK;
  67. pPrivData = WTHelperGetProvPrivateDataFromChain(pProvData, &gDriverProv);
  68. if (!(pPrivData))
  69. {
  70. memset(&sPrivData, 0x00, sizeof(CRYPT_PROVIDER_PRIVDATA));
  71. sPrivData.cbStruct = sizeof(CRYPT_PROVIDER_PRIVDATA);
  72. memcpy(&sPrivData.gProviderID, &gDriverProv, sizeof(GUID));
  73. //
  74. // add my data to the chain!
  75. //
  76. if (!pProvData->psPfns->pfnAddPrivData2Chain(pProvData, &sPrivData))
  77. {
  78. return (S_FALSE);
  79. }
  80. //
  81. // get the new reference
  82. //
  83. pPrivData = WTHelperGetProvPrivateDataFromChain(pProvData, &gDriverProv);
  84. }
  85. //
  86. // allocate space for my struct
  87. //
  88. if (!(pPrivData->pvProvData = pProvData->psPfns->pfnAlloc(sizeof(DRVPROV_PRIVATE_DATA))))
  89. {
  90. pProvData->dwError = GetLastError();
  91. pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_INITPROV] = TRUST_E_SYSTEM_ERROR;
  92. return (S_FALSE);
  93. }
  94. memset(pPrivData->pvProvData, 0x00, sizeof(DRVPROV_PRIVATE_DATA));
  95. pPrivData->cbProvData = sizeof(DRVPROV_PRIVATE_DATA);
  96. pDriverData = (DRVPROV_PRIVATE_DATA *)pPrivData->pvProvData;
  97. pDriverData->cbStruct = sizeof(DRVPROV_PRIVATE_DATA);
  98. //
  99. // fill in the Authenticode Functions
  100. //
  101. pDriverData->sAuthenticodePfns.cbStruct = sizeof(CRYPT_PROVIDER_FUNCTIONS);
  102. if (!(WintrustLoadFunctionPointers(&gAuthenticode, &pDriverData->sAuthenticodePfns)))
  103. {
  104. pProvData->psPfns->pfnFree(sPrivData.pvProvData);
  105. pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_INITPROV] = TRUST_E_PROVIDER_UNKNOWN;
  106. return (S_FALSE);
  107. }
  108. if (pDriverData->sAuthenticodePfns.pfnInitialize)
  109. {
  110. hr = pDriverData->sAuthenticodePfns.pfnInitialize(pProvData);
  111. }
  112. //
  113. // assign our usage
  114. //
  115. pProvData->pRequestUsage = &RequestUsage;
  116. // for backwards compatibility
  117. pProvData->pszUsageOID = szOID_WHQL_CRYPTO;
  118. //
  119. // do NOT allow test certs EVER!
  120. //
  121. // changed July 27, 2000
  122. //
  123. pProvData->dwRegPolicySettings &= ~(WTPF_TRUSTTEST | WTPF_TESTCANBEVALID);
  124. //
  125. // do NOT require the publisher to be in the trusted database
  126. //
  127. // (changed July 27, 2000)
  128. //
  129. pProvData->dwRegPolicySettings &= ~WTPF_ALLOWONLYPERTRUST;
  130. //
  131. // Always ignore offline errors.
  132. //
  133. // (Added 28 March, 2002)
  134. //
  135. pProvData->dwRegPolicySettings |=
  136. WTPF_OFFLINEOK_IND |
  137. WTPF_OFFLINEOK_COM |
  138. WTPF_OFFLINEOKNBU_IND |
  139. WTPF_OFFLINEOKNBU_COM;
  140. return (hr);
  141. }
  142. HRESULT WINAPI DriverCleanupPolicy(CRYPT_PROVIDER_DATA *pProvData)
  143. {
  144. GUID gDriverProv = DRIVER_ACTION_VERIFY;
  145. CRYPT_PROVIDER_PRIVDATA *pMyData;
  146. DRVPROV_PRIVATE_DATA *pDriverData;
  147. HRESULT hr;
  148. if (!(pProvData->padwTrustStepErrors) ||
  149. (pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_WVTINIT] != ERROR_SUCCESS))
  150. {
  151. return (S_FALSE);
  152. }
  153. hr = S_OK;
  154. pMyData = WTHelperGetProvPrivateDataFromChain(pProvData, &gDriverProv);
  155. if (pMyData)
  156. {
  157. pDriverData = (DRVPROV_PRIVATE_DATA *)pMyData->pvProvData;
  158. if (pDriverData != NULL)
  159. {
  160. //
  161. // remove the data we allocated except for the "MyData"
  162. // which WVT will clean up for us!
  163. //
  164. if (pDriverData->sAuthenticodePfns.pfnCleanupPolicy)
  165. {
  166. hr = pDriverData->sAuthenticodePfns.pfnCleanupPolicy(pProvData);
  167. }
  168. }
  169. pProvData->psPfns->pfnFree(pMyData->pvProvData);
  170. pMyData->pvProvData = NULL;
  171. pMyData->cbProvData = 0;
  172. }
  173. return (hr);
  174. }
  175. //+-------------------------------------------------------------------------
  176. // Allocates and returns the specified cryptographic message parameter.
  177. //--------------------------------------------------------------------------
  178. static void *AllocAndGetMsgParam(
  179. IN HCRYPTMSG hMsg,
  180. IN DWORD dwParamType,
  181. IN DWORD dwIndex,
  182. OUT DWORD *pcbData
  183. )
  184. {
  185. void *pvData;
  186. DWORD cbData;
  187. if (!CryptMsgGetParam(
  188. hMsg,
  189. dwParamType,
  190. dwIndex,
  191. NULL, // pvData
  192. &cbData) || 0 == cbData)
  193. goto GetParamError;
  194. if (NULL == (pvData = malloc(cbData)))
  195. goto OutOfMemory;
  196. if (!CryptMsgGetParam(
  197. hMsg,
  198. dwParamType,
  199. dwIndex,
  200. pvData,
  201. &cbData)) {
  202. free(pvData);
  203. goto GetParamError;
  204. }
  205. CommonReturn:
  206. *pcbData = cbData;
  207. return pvData;
  208. ErrorReturn:
  209. pvData = NULL;
  210. cbData = 0;
  211. goto CommonReturn;
  212. TRACE_ERROR(OutOfMemory)
  213. TRACE_ERROR(GetParamError)
  214. }
  215. //+-------------------------------------------------------------------------
  216. // Alloc and NOCOPY Decode
  217. //--------------------------------------------------------------------------
  218. static void *AllocAndDecodeObject(
  219. IN LPCSTR lpszStructType,
  220. IN const BYTE *pbEncoded,
  221. IN DWORD cbEncoded
  222. )
  223. {
  224. DWORD cbStructInfo;
  225. void *pvStructInfo;
  226. CryptDecodeObject(
  227. X509_ASN_ENCODING,
  228. lpszStructType,
  229. pbEncoded,
  230. cbEncoded,
  231. CRYPT_DECODE_NOCOPY_FLAG,
  232. NULL, // pvStructInfo
  233. &cbStructInfo
  234. );
  235. if (cbStructInfo == 0)
  236. goto ErrorReturn;
  237. if (NULL == (pvStructInfo = malloc(cbStructInfo)))
  238. goto ErrorReturn;
  239. if (!CryptDecodeObject(
  240. X509_ASN_ENCODING,
  241. lpszStructType,
  242. pbEncoded,
  243. cbEncoded,
  244. CRYPT_DECODE_NOCOPY_FLAG,
  245. pvStructInfo,
  246. &cbStructInfo
  247. )) {
  248. free(pvStructInfo);
  249. goto ErrorReturn;
  250. }
  251. CommonReturn:
  252. return pvStructInfo;
  253. ErrorReturn:
  254. pvStructInfo = NULL;
  255. goto CommonReturn;
  256. }
  257. static void CopyBytesToMaxPathString(
  258. IN const BYTE *pbData,
  259. IN DWORD cbData,
  260. OUT WCHAR wszDst[MAX_PATH]
  261. )
  262. {
  263. DWORD cchDst;
  264. if (pbData) {
  265. cchDst = cbData / sizeof(WCHAR);
  266. if (cchDst > MAX_PATH - 1)
  267. cchDst = MAX_PATH - 1;
  268. } else
  269. cchDst = 0;
  270. if (cchDst)
  271. memcpy(wszDst, pbData, cchDst * sizeof(WCHAR));
  272. wszDst[cchDst] = L'\0';
  273. }
  274. void UpdateDriverVersion(
  275. IN CRYPT_PROVIDER_DATA *pProvData,
  276. OUT WCHAR wszVersion[MAX_PATH]
  277. )
  278. {
  279. HCRYPTMSG hMsg = pProvData->hMsg;
  280. BYTE *pbContent = NULL;
  281. DWORD cbContent;
  282. PCTL_INFO pCtlInfo = NULL;
  283. PCERT_EXTENSION pExt; // not allocated
  284. PCAT_NAMEVALUE pNameValue = NULL;
  285. if (NULL == hMsg)
  286. goto NoMessage;
  287. // Get the inner content.
  288. if (NULL == (pbContent = (BYTE *) AllocAndGetMsgParam(
  289. hMsg,
  290. CMSG_CONTENT_PARAM,
  291. 0, // dwIndex
  292. &cbContent))) goto GetContentError;
  293. if (NULL == (pCtlInfo = (PCTL_INFO) AllocAndDecodeObject(
  294. PKCS_CTL,
  295. pbContent,
  296. cbContent
  297. )))
  298. goto DecodeCtlError;
  299. if (NULL == (pExt = CertFindExtension(
  300. CAT_NAMEVALUE_OBJID,
  301. pCtlInfo->cExtension,
  302. pCtlInfo->rgExtension
  303. )))
  304. goto NoVersionExt;
  305. if (NULL == (pNameValue = (PCAT_NAMEVALUE) AllocAndDecodeObject(
  306. CAT_NAMEVALUE_STRUCT,
  307. pExt->Value.pbData,
  308. pExt->Value.cbData
  309. )))
  310. goto DecodeNameValueError;
  311. CopyBytesToMaxPathString(pNameValue->Value.pbData,
  312. pNameValue->Value.cbData, wszVersion);
  313. CommonReturn:
  314. if (pNameValue)
  315. free(pNameValue);
  316. if (pCtlInfo)
  317. free(pCtlInfo);
  318. if (pbContent)
  319. free(pbContent);
  320. return;
  321. ErrorReturn:
  322. wszVersion[0] = L'\0';
  323. goto CommonReturn;
  324. TRACE_ERROR(NoMessage)
  325. TRACE_ERROR(GetContentError)
  326. TRACE_ERROR(DecodeCtlError)
  327. TRACE_ERROR(NoVersionExt)
  328. TRACE_ERROR(DecodeNameValueError)
  329. }
  330. BOOL _ValidCatAttr(CRYPTCATATTRIBUTE *pAttr)
  331. {
  332. if (!(pAttr) || (pAttr->cbValue < 1) || !(pAttr->pbValue))
  333. {
  334. return(FALSE);
  335. }
  336. return TRUE;
  337. }
  338. HRESULT WINAPI DriverFinalPolicy(CRYPT_PROVIDER_DATA *pProvData)
  339. {
  340. GUID gDriverProv = DRIVER_ACTION_VERIFY;
  341. HRESULT hr;
  342. CRYPT_PROVIDER_PRIVDATA *pMyData;
  343. CRYPT_PROVIDER_SGNR *pSigner;
  344. CERT_CHAIN_POLICY_STATUS CertChainStatus;
  345. CERT_CHAIN_POLICY_PARA CertChainPolicyPara;
  346. CRYPTCATATTRIBUTE *pCatAttr;
  347. CRYPTCATATTRIBUTE *pMemAttr;
  348. DRIVER_VER_INFO *pVerInfo;
  349. DWORD dwExceptionCode;
  350. BOOL fUseCurrentOSVer = FALSE;
  351. hr = ERROR_SUCCESS;
  352. if (!(_ISINSTRUCT(CRYPT_PROVIDER_DATA, pProvData->cbStruct, pszUsageOID)) ||
  353. !(pProvData->pWintrustData) ||
  354. !(_ISINSTRUCT(WINTRUST_DATA, pProvData->pWintrustData->cbStruct, hWVTStateData)))
  355. {
  356. goto ErrorInvalidParam;
  357. }
  358. //
  359. // First things first, make sure the signing cert chains up to a MS root
  360. //
  361. pSigner = WTHelperGetProvSignerFromChain(pProvData, 0, FALSE, 0);
  362. if (pSigner == NULL)
  363. {
  364. goto ErrorInvalidParam;
  365. }
  366. //
  367. // The chain context may be NULL if another error was previously encountered
  368. //
  369. if (pSigner->pChainContext != NULL)
  370. {
  371. memset(&CertChainStatus, 0, sizeof(CertChainStatus));
  372. CertChainStatus.cbSize = sizeof(CertChainStatus);
  373. memset(&(CertChainPolicyPara), 0, sizeof(CertChainPolicyPara));
  374. CertChainPolicyPara.cbSize = sizeof(CertChainPolicyPara);
  375. CertChainPolicyPara.dwFlags = MICROSOFT_ROOT_CERT_CHAIN_POLICY_ENABLE_TEST_ROOT_FLAG;
  376. if (!CertVerifyCertificateChainPolicy(
  377. CERT_CHAIN_POLICY_MICROSOFT_ROOT,
  378. pSigner->pChainContext,
  379. &CertChainPolicyPara,
  380. &CertChainStatus))
  381. {
  382. goto ErrorInvalidRoot;
  383. }
  384. if (CertChainStatus.dwError != ERROR_SUCCESS)
  385. {
  386. goto ErrorInvalidRoot;
  387. }
  388. }
  389. //
  390. // Initialize the fUseCurrentOSVer variable
  391. //
  392. if (_ISINSTRUCT(WINTRUST_DATA, pProvData->pWintrustData->cbStruct, dwProvFlags))
  393. {
  394. fUseCurrentOSVer =
  395. (pProvData->pWintrustData->dwProvFlags & WTD_USE_DEFAULT_OSVER_CHECK) != 0;
  396. }
  397. //
  398. //
  399. //
  400. pVerInfo = (DRIVER_VER_INFO *)pProvData->pWintrustData->pPolicyCallbackData;
  401. if (pVerInfo)
  402. {
  403. CRYPT_PROVIDER_SGNR *pSgnr;
  404. CRYPT_PROVIDER_CERT *pCert;
  405. // KeithV
  406. // Today we do not support ranges of versions, so the version
  407. // number must be the same. Also must be none zero
  408. // Removed this check so that ranges can now be used - 9-10-99 (reidk)
  409. /*if ((_ISINSTRUCT(DRIVER_VER_INFO, pVerInfo->cbStruct, sOSVersionLow)) &&
  410. (_ISINSTRUCT(DRIVER_VER_INFO, pVerInfo->cbStruct, sOSVersionHigh)))
  411. {
  412. if(memcmp(&pVerInfo->sOSVersionLow,
  413. &pVerInfo->sOSVersionHigh,
  414. sizeof(DRIVER_VER_MAJORMINOR)) )
  415. {
  416. goto ErrorInvalidParam;
  417. }
  418. }*/
  419. if (!(_ISINSTRUCT(DRIVER_VER_INFO, pVerInfo->cbStruct, pcSignerCertContext)))
  420. {
  421. goto ErrorInvalidParam;
  422. }
  423. pVerInfo->wszVersion[0] = NULL;
  424. if (!(pSgnr = WTHelperGetProvSignerFromChain(pProvData, 0, FALSE, 0)))
  425. {
  426. goto ErrorNoSigner;
  427. }
  428. if (!(pCert = WTHelperGetProvCertFromChain(pSgnr, 0)))
  429. {
  430. goto ErrorNoCert;
  431. }
  432. if (pCert->pCert)
  433. {
  434. CertGetNameStringW(
  435. pCert->pCert,
  436. CERT_NAME_SIMPLE_DISPLAY_TYPE,
  437. 0, // dwFlags
  438. NULL, // pvTypePara
  439. pVerInfo->wszSignedBy,
  440. MAX_PATH
  441. );
  442. pVerInfo->pcSignerCertContext = CertDuplicateCertificateContext(pCert->pCert);
  443. if (pVerInfo->dwReserved1 == 0x1 && pVerInfo->dwReserved2 == 0) {
  444. HCRYPTMSG hMsg = pProvData->hMsg;
  445. // Return the message's store
  446. if (hMsg) {
  447. HCERTSTORE hStore;
  448. hStore = CertOpenStore(
  449. CERT_STORE_PROV_MSG,
  450. X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
  451. 0, // hCryptProv
  452. 0, // dwFlags
  453. (const void *) hMsg
  454. );
  455. pVerInfo->dwReserved2 = (ULONG_PTR) hStore;
  456. }
  457. }
  458. }
  459. }
  460. if (pProvData->padwTrustStepErrors)
  461. {
  462. pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_POLICYPROV] = ERROR_SUCCESS;
  463. }
  464. if ((hr = checkGetErrorBasedOnStepErrors(pProvData)) != ERROR_SUCCESS)
  465. {
  466. goto StepError;
  467. }
  468. pCatAttr = NULL;
  469. pMemAttr = NULL;
  470. if ((pProvData->pPDSip) &&
  471. (_ISINSTRUCT(PROVDATA_SIP, pProvData->pPDSip->cbStruct, psIndirectData)) &&
  472. (pProvData->pPDSip->psSipSubjectInfo) &&
  473. (pProvData->pPDSip->psSipSubjectInfo->dwUnionChoice == MSSIP_ADDINFO_CATMEMBER) &&
  474. (pProvData->pPDSip->psSipSubjectInfo->psCatMember) &&
  475. (pProvData->pPDSip->psSipSubjectInfo->psCatMember->pStore) &&
  476. (pProvData->pPDSip->psSipSubjectInfo->psCatMember->pMember) &&
  477. (pProvData->pWintrustData->dwUnionChoice == WTD_CHOICE_CATALOG))
  478. {
  479. // The following APIs are in DELAYLOAD'ed mscat32.dll. If the
  480. // DELAYLOAD fails an exception is raised.
  481. __try {
  482. HANDLE hCatStore;
  483. hCatStore = CryptCATHandleFromStore(pProvData->pPDSip->psSipSubjectInfo->psCatMember->pStore);
  484. //
  485. // first look at the members attr
  486. //
  487. pMemAttr = CryptCATGetAttrInfo(hCatStore,
  488. pProvData->pPDSip->psSipSubjectInfo->psCatMember->pMember,
  489. L"OSAttr");
  490. pCatAttr = CryptCATGetCatAttrInfo(hCatStore, L"OSAttr");
  491. //
  492. // This statement is to honor old _weird_ semantics where if there is a
  493. // pointer to a pVerInfo struct and both the dwPlatformId/dwVersion fields
  494. // of it are zero then don't do a version check. (probably for sigverif, or maybe
  495. // even un-intentional, but keep old semantics regardless)
  496. //
  497. if ((pVerInfo == NULL) ||
  498. (pVerInfo->dwPlatform != 0) ||
  499. (pVerInfo->dwVersion != 0) ||
  500. fUseCurrentOSVer)
  501. {
  502. if (_ValidCatAttr(pMemAttr))
  503. {
  504. if (!(_CheckVersionAttributeNEW(
  505. fUseCurrentOSVer ? NULL : pVerInfo,
  506. pMemAttr)))
  507. {
  508. goto OSAttrVersionError;
  509. }
  510. }
  511. else
  512. {
  513. if (!_ValidCatAttr(pCatAttr) && !_ValidCatAttr(pMemAttr))
  514. {
  515. goto ValidOSAttrNotFound;
  516. }
  517. if (!(_CheckVersionAttributeNEW(
  518. fUseCurrentOSVer ? NULL : pVerInfo,
  519. pCatAttr)))
  520. {
  521. goto OSAttrVersionError;
  522. }
  523. }
  524. }
  525. } __except(EXCEPTION_EXECUTE_HANDLER) {
  526. dwExceptionCode = GetExceptionCode();
  527. goto CryptCATException;
  528. }
  529. }
  530. else if ((pProvData->pWintrustData) &&
  531. (pProvData->pWintrustData->dwUnionChoice == WTD_CHOICE_CATALOG))
  532. {
  533. goto ErrorInvalidParam;
  534. }
  535. //
  536. // fill our name for SigVerif...
  537. //
  538. if (pVerInfo)
  539. {
  540. if (!(pVerInfo->wszVersion[0]))
  541. {
  542. if ((pMemAttr) && (pMemAttr->cbValue > 0) && (pMemAttr->pbValue))
  543. {
  544. CopyBytesToMaxPathString(pMemAttr->pbValue, pMemAttr->cbValue,
  545. pVerInfo->wszVersion);
  546. }
  547. else if ((pCatAttr) && (pCatAttr->cbValue > 0) && (pCatAttr->pbValue))
  548. {
  549. CopyBytesToMaxPathString(pCatAttr->pbValue, pCatAttr->cbValue,
  550. pVerInfo->wszVersion);
  551. }
  552. else
  553. {
  554. UpdateDriverVersion(pProvData, pVerInfo->wszVersion);
  555. }
  556. }
  557. }
  558. //
  559. // retrieve my data from the provider struct
  560. //
  561. pMyData = WTHelperGetProvPrivateDataFromChain(pProvData, &gDriverProv);
  562. if (pMyData)
  563. {
  564. DRVPROV_PRIVATE_DATA *pDriverData;
  565. pDriverData = (DRVPROV_PRIVATE_DATA *)pMyData->pvProvData;
  566. //
  567. // call the standard final policy
  568. //
  569. if (pDriverData)
  570. {
  571. if (pDriverData->sAuthenticodePfns.pfnFinalPolicy)
  572. {
  573. DWORD dwOldUIFlags;
  574. dwOldUIFlags = pProvData->pWintrustData->dwUIChoice;
  575. pProvData->pWintrustData->dwUIChoice = WTD_UI_NONE;
  576. hr = pDriverData->sAuthenticodePfns.pfnFinalPolicy(pProvData);
  577. pProvData->pWintrustData->dwUIChoice = dwOldUIFlags;
  578. }
  579. }
  580. }
  581. CommonReturn:
  582. if (hr != ERROR_INVALID_PARAMETER)
  583. {
  584. pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_POLICYPROV] = hr;
  585. }
  586. return (hr);
  587. ErrorReturn:
  588. hr = GetLastError();
  589. goto CommonReturn;
  590. SET_ERROR_VAR_EX(DBG_SS, ErrorInvalidParam, ERROR_INVALID_PARAMETER);
  591. SET_ERROR_VAR_EX(DBG_SS, ErrorNoSigner, TRUST_E_NOSIGNATURE);
  592. SET_ERROR_VAR_EX(DBG_SS, ErrorNoCert, TRUST_E_NO_SIGNER_CERT);
  593. SET_ERROR_VAR_EX(DBG_SS, ValidOSAttrNotFound,ERROR_APP_WRONG_OS);
  594. SET_ERROR_VAR_EX(DBG_SS, OSAttrVersionError,ERROR_APP_WRONG_OS);
  595. SET_ERROR_VAR_EX(DBG_SS, StepError, hr);
  596. SET_ERROR_VAR_EX(DBG_SS, CryptCATException, dwExceptionCode);
  597. SET_ERROR_VAR_EX(DBG_SS, ErrorInvalidRoot, CERT_E_UNTRUSTEDROOT);
  598. }
  599. #define OSATTR_ALL L'X'
  600. #define OSATTR_GTEQ L'>'
  601. #define OSATTR_LTEQ L'-'
  602. #define OSATTR_LTEQ2 L'<'
  603. #define OSATTR_OSSEP L':'
  604. #define OSATTR_VERSEP L'.'
  605. #define OSATTR_SEP L','
  606. #define OSATTR_RANGE_SEP L';'
  607. //
  608. // NEW
  609. //
  610. BOOL _CheckVersionAttributeNEW(DRIVER_VER_INFO *pVerInfo, CRYPTCATATTRIBUTE *pAttr)
  611. {
  612. OSVERSIONINFO sVersion;
  613. OSVERSIONINFO sVersionSave;
  614. WCHAR *pwszCurrent;
  615. WCHAR *pwszEnd = NULL;
  616. WCHAR *pwszRangeSeperator = NULL;
  617. BOOL fCheckRange = FALSE;
  618. BOOL fUseBuildNumber = FALSE;
  619. DWORD dwLowCheck;
  620. DWORD dwHighCheck;
  621. //
  622. // If no version info was passed in, get the current
  623. // OS version to that verification can be done against it
  624. //
  625. memset(&sVersion, 0x00, sizeof(OSVERSIONINFO));
  626. if ((NULL == pVerInfo) || (pVerInfo->dwPlatform == 0))
  627. {
  628. sVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  629. if (!GetVersionEx(&sVersion))
  630. {
  631. return FALSE;
  632. }
  633. fUseBuildNumber = TRUE;
  634. }
  635. else
  636. {
  637. //
  638. // Analyze the pVerInfo struct and deduce whether we are checking a range,
  639. // and/or whether the dwBuildNumber* fields exist and are being used.
  640. //
  641. if (_ISINSTRUCT(DRIVER_VER_INFO, pVerInfo->cbStruct, sOSVersionHigh))
  642. {
  643. //
  644. // If version are different then a range is being used
  645. //
  646. if (memcmp( &(pVerInfo->sOSVersionLow),
  647. &(pVerInfo->sOSVersionHigh),
  648. sizeof(DRIVER_VER_MAJORMINOR)) != 0)
  649. {
  650. fCheckRange = TRUE;
  651. }
  652. //
  653. // Just set these here since the first check is the same regardless
  654. // of whetther we are doing range checking or not.
  655. //
  656. sVersion.dwPlatformId = pVerInfo->dwPlatform;
  657. sVersion.dwMajorVersion = pVerInfo->sOSVersionLow.dwMajor;
  658. sVersion.dwMinorVersion = pVerInfo->sOSVersionLow.dwMinor;
  659. //
  660. // Check to see if the dwBuildNumber* members exists, and
  661. // if they are being used (not 0).
  662. //
  663. if ((_ISINSTRUCT(DRIVER_VER_INFO, pVerInfo->cbStruct, dwBuildNumberHigh)) &&
  664. pVerInfo->dwBuildNumberLow != 0)
  665. {
  666. fUseBuildNumber = TRUE;
  667. fCheckRange |= (pVerInfo->dwBuildNumberLow == pVerInfo->dwBuildNumberHigh) ?
  668. FALSE : TRUE;
  669. //
  670. // Just set this in case we aren't doing range checking
  671. //
  672. sVersion.dwBuildNumber = pVerInfo->dwBuildNumberLow;
  673. }
  674. }
  675. else
  676. {
  677. sVersion.dwPlatformId = pVerInfo->dwPlatform;
  678. sVersion.dwMajorVersion = pVerInfo->dwVersion;
  679. sVersion.dwMinorVersion = 0;
  680. }
  681. }
  682. //
  683. // Save this in case multiple OSAttr elements need to be checked against
  684. // a range
  685. //
  686. memcpy(&sVersionSave, &sVersion, sizeof(OSVERSIONINFO));
  687. //
  688. // Loop for each version in the attribute, and check to see if
  689. // it satifies our criteria
  690. //
  691. pwszCurrent = (WCHAR *)pAttr->pbValue;
  692. while ((pwszCurrent != NULL) && (*pwszCurrent))
  693. {
  694. //
  695. // Find version seperator, insert '/0' if needed, and keep
  696. // track of location for next time through the loop
  697. //
  698. pwszEnd = wcschr(pwszCurrent, OSATTR_SEP);
  699. if (pwszEnd)
  700. {
  701. *pwszEnd = L'\0';
  702. }
  703. //
  704. // Check to see if this version string is a range
  705. //
  706. pwszRangeSeperator = wcschr(pwszCurrent, OSATTR_RANGE_SEP);
  707. if (pwszRangeSeperator != NULL)
  708. {
  709. //
  710. // The version string in the cat file is a range
  711. //
  712. *pwszRangeSeperator = L'\0';
  713. pwszRangeSeperator++;
  714. dwLowCheck = _CheckVersionNEW(&sVersion, pwszCurrent, fUseBuildNumber);
  715. //
  716. // The only difference between checking a single OS version against a range,
  717. // and checking a range of OS versions agains a range is the value used for the
  718. // upper limit.
  719. //
  720. if (fCheckRange)
  721. {
  722. sVersion.dwPlatformId = pVerInfo->dwPlatform;
  723. sVersion.dwMajorVersion = pVerInfo->sOSVersionHigh.dwMajor;
  724. sVersion.dwMinorVersion = pVerInfo->sOSVersionHigh.dwMinor;
  725. sVersion.dwBuildNumber = (fUseBuildNumber) ? pVerInfo->dwBuildNumberHigh : 0;
  726. }
  727. dwHighCheck = _CheckVersionNEW(&sVersion, pwszRangeSeperator, fUseBuildNumber);
  728. if (((dwLowCheck == VER_CHECK_EQ) || (dwLowCheck == VER_CHECK_GT)) &&
  729. ((dwHighCheck == VER_CHECK_EQ) || (dwHighCheck == VER_CHECK_LT)))
  730. {
  731. if (pVerInfo)
  732. {
  733. CopyBytesToMaxPathString(
  734. pAttr->pbValue,
  735. pAttr->cbValue,
  736. pVerInfo->wszVersion);
  737. }
  738. *(--pwszRangeSeperator) = OSATTR_RANGE_SEP;
  739. if (pwszEnd != NULL)
  740. {
  741. *pwszEnd = OSATTR_SEP;
  742. }
  743. return (TRUE);
  744. }
  745. *(--pwszRangeSeperator) = OSATTR_RANGE_SEP;
  746. //
  747. // copy back the low OSVER to get ready for the next pass
  748. //
  749. memcpy(&sVersion, &sVersionSave, sizeof(OSVERSIONINFO));
  750. }
  751. else
  752. {
  753. if (!fCheckRange)
  754. {
  755. if (_CheckVersionNEW(&sVersion, pwszCurrent, fUseBuildNumber) == VER_CHECK_EQ)
  756. {
  757. if (pVerInfo)
  758. {
  759. CopyBytesToMaxPathString(
  760. pAttr->pbValue,
  761. pAttr->cbValue,
  762. pVerInfo->wszVersion);
  763. }
  764. if (pwszEnd != NULL)
  765. {
  766. *pwszEnd = OSATTR_SEP;
  767. }
  768. return (TRUE);
  769. }
  770. }
  771. else
  772. {
  773. dwLowCheck = _CheckVersionNEW(&sVersion, pwszCurrent, fUseBuildNumber);
  774. sVersion.dwPlatformId = pVerInfo->dwPlatform;
  775. sVersion.dwMajorVersion = pVerInfo->sOSVersionHigh.dwMajor;
  776. sVersion.dwMinorVersion = pVerInfo->sOSVersionHigh.dwMinor;
  777. sVersion.dwBuildNumber = (fUseBuildNumber) ? pVerInfo->dwBuildNumberHigh : 0;
  778. dwHighCheck = _CheckVersionNEW(&sVersion, pwszCurrent, fUseBuildNumber);
  779. if (((dwLowCheck == VER_CHECK_EQ) || (dwLowCheck == VER_CHECK_LT)) &&
  780. ((dwHighCheck == VER_CHECK_EQ) || (dwHighCheck == VER_CHECK_GT)))
  781. {
  782. if (pVerInfo)
  783. {
  784. CopyBytesToMaxPathString(
  785. pAttr->pbValue,
  786. pAttr->cbValue,
  787. pVerInfo->wszVersion);
  788. }
  789. if (pwszEnd != NULL)
  790. {
  791. *pwszEnd = OSATTR_SEP;
  792. }
  793. return (TRUE);
  794. }
  795. //
  796. // copy back the low OSVER to get ready for the next pass
  797. //
  798. memcpy(&sVersion, &sVersionSave, sizeof(OSVERSIONINFO));
  799. }
  800. }
  801. //
  802. // If there aren't anymore version in the attribute, then break,
  803. // which means the version check failed
  804. //
  805. if (!(pwszEnd))
  806. {
  807. break;
  808. }
  809. //
  810. // Set up for next iteration
  811. //
  812. *pwszEnd = OSATTR_SEP;
  813. pwszCurrent = pwszEnd;
  814. pwszCurrent++;
  815. }
  816. return (FALSE);
  817. }
  818. //
  819. // Comparison is done such that pVersion is VER_CHECK_LT, VER_CHECK_GT, or
  820. // VER_CHECK_EQ to pwszAttr
  821. //
  822. DWORD _CheckVersionNEW(OSVERSIONINFO *pVersion, WCHAR *pwszAttr, BOOL fUseBuildNumber)
  823. {
  824. WCHAR *pwszCurrent;
  825. WCHAR *pwszEnd;
  826. DWORD dwPlatform;
  827. DWORD dwMajor;
  828. DWORD dwMinor;
  829. DWORD dwBuild;
  830. WCHAR wcFlagMinor;
  831. WCHAR wcFlagBuild;
  832. pwszCurrent = pwszAttr;
  833. //
  834. // format: os:major.minor, os:major.minor, ...
  835. // 2:4.x = NT 4 (all)
  836. // 2:4.> = NT 4 (all) and beyond
  837. // 2:4.- = NT 4 (all) and before
  838. // 2:4.< = NT 4 (all) and before
  839. // 2:4.1.x = NT 4.1 (all)
  840. // 2:4.1.> = NT 4.1 (all) and beyond
  841. // 2:4.1.- = NT 4.1 (all) and before
  842. // 2:4.1.< = NT 4.1 (all) and before
  843. // 2:4.1 = NT 4.1 only
  844. // 2:4.1.1 = NT 4.1 build # 1 only
  845. //
  846. if (!(pwszEnd = wcschr(pwszAttr, OSATTR_OSSEP)))
  847. {
  848. return(VER_CHECK_FAIL);
  849. }
  850. *pwszEnd = NULL;
  851. //
  852. // Check platform first
  853. //
  854. dwPlatform = (DWORD) _wtol(pwszCurrent);
  855. *pwszEnd = OSATTR_OSSEP;
  856. //
  857. // MUST be same platform
  858. //
  859. if (dwPlatform != pVersion->dwPlatformId)
  860. {
  861. return(VER_CHECK_FAIL);
  862. }
  863. pwszCurrent = pwszEnd;
  864. pwszCurrent++;
  865. if (!(_GetVersionNumbers(pwszCurrent, &dwMajor, &dwMinor, &dwBuild, &wcFlagMinor, &wcFlagBuild)))
  866. {
  867. return(VER_CHECK_FAIL);
  868. }
  869. //
  870. // The only way we can check against a build# is if the OSAttr has some build# node...
  871. // which is not the case for an OSAttr like 2.4.x
  872. //
  873. if ((fUseBuildNumber && (dwBuild != 0)) ||
  874. (wcFlagBuild != L'\0'))
  875. {
  876. switch (wcFlagBuild)
  877. {
  878. case OSATTR_ALL:
  879. // 2:4.1.x = NT 4.1 (all)
  880. if ((pVersion->dwMajorVersion == dwMajor) && (pVersion->dwMinorVersion == dwMinor))
  881. {
  882. return(VER_CHECK_EQ);
  883. }
  884. else if ((pVersion->dwMajorVersion < dwMajor) ||
  885. ((pVersion->dwMajorVersion == dwMajor) && (pVersion->dwMinorVersion < dwMinor)))
  886. {
  887. return(VER_CHECK_LT);
  888. }
  889. else
  890. {
  891. return(VER_CHECK_GT);
  892. }
  893. break;
  894. case OSATTR_GTEQ:
  895. // 2:4.1.> = NT 4.1 (all) and beyond
  896. if ((pVersion->dwMajorVersion > dwMajor) ||
  897. ((pVersion->dwMajorVersion == dwMajor) && (pVersion->dwMinorVersion >= dwMinor)))
  898. {
  899. return(VER_CHECK_EQ);
  900. }
  901. else
  902. {
  903. return(VER_CHECK_LT);
  904. }
  905. break;
  906. case OSATTR_LTEQ:
  907. case OSATTR_LTEQ2:
  908. // 2:4.1.- = NT 4.1 (all) and before
  909. // 2:4.1.< = NT 4.1 (all) and before
  910. if ((pVersion->dwMajorVersion < dwMajor) ||
  911. ((pVersion->dwMajorVersion == dwMajor) && (pVersion->dwMinorVersion <= dwMinor)))
  912. {
  913. return(VER_CHECK_EQ);
  914. }
  915. else
  916. {
  917. return(VER_CHECK_GT);
  918. }
  919. break;
  920. default:
  921. // 2:4.1.1 = NT 4.1 build # 1 only
  922. if (pVersion->dwMajorVersion < dwMajor)
  923. {
  924. return(VER_CHECK_LT);
  925. }
  926. else if (pVersion->dwMajorVersion > dwMajor)
  927. {
  928. return(VER_CHECK_GT);
  929. }
  930. else
  931. {
  932. if (pVersion->dwMinorVersion < dwMinor)
  933. {
  934. return(VER_CHECK_LT);
  935. }
  936. else if (pVersion->dwMinorVersion > dwMinor)
  937. {
  938. return(VER_CHECK_GT);
  939. }
  940. else
  941. {
  942. if (pVersion->dwBuildNumber == dwBuild)
  943. {
  944. return(VER_CHECK_EQ);
  945. }
  946. else if (pVersion->dwBuildNumber < dwBuild)
  947. {
  948. return(VER_CHECK_LT);
  949. }
  950. else
  951. {
  952. return(VER_CHECK_GT);
  953. }
  954. }
  955. }
  956. break;
  957. }
  958. }
  959. switch (wcFlagMinor)
  960. {
  961. case OSATTR_ALL:
  962. // 2:4.x = NT 4 (all)
  963. if (pVersion->dwMajorVersion == dwMajor)
  964. {
  965. return(VER_CHECK_EQ);
  966. }
  967. else if (pVersion->dwMajorVersion < dwMajor)
  968. {
  969. return(VER_CHECK_LT);
  970. }
  971. else
  972. {
  973. return(VER_CHECK_GT);
  974. }
  975. break;
  976. case OSATTR_GTEQ:
  977. // 2:4.> = NT 4 (all) and beyond
  978. if (pVersion->dwMajorVersion >= dwMajor)
  979. {
  980. return(VER_CHECK_EQ);
  981. }
  982. else
  983. {
  984. return(VER_CHECK_LT);
  985. }
  986. break;
  987. case OSATTR_LTEQ:
  988. case OSATTR_LTEQ2:
  989. // 2:4.- = NT 4 (all) and before
  990. // 2:4.< = NT 4 (all) and before
  991. if (pVersion->dwMajorVersion <= dwMajor)
  992. {
  993. return(VER_CHECK_EQ);
  994. }
  995. else
  996. {
  997. return(VER_CHECK_GT);
  998. }
  999. break;
  1000. default:
  1001. // 2:4.1 = NT 4.1 only
  1002. if ((pVersion->dwMajorVersion == dwMajor) && (pVersion->dwMinorVersion == dwMinor))
  1003. {
  1004. return(VER_CHECK_EQ);
  1005. }
  1006. else if (pVersion->dwMajorVersion == dwMajor)
  1007. {
  1008. if (pVersion->dwMinorVersion < dwMinor)
  1009. {
  1010. return(VER_CHECK_LT);
  1011. }
  1012. else
  1013. {
  1014. return(VER_CHECK_GT);
  1015. }
  1016. }
  1017. else if (pVersion->dwMajorVersion < dwMajor)
  1018. {
  1019. return(VER_CHECK_LT);
  1020. }
  1021. else
  1022. {
  1023. return(VER_CHECK_GT);
  1024. }
  1025. break;
  1026. }
  1027. return(VER_CHECK_FAIL);
  1028. }
  1029. BOOL _GetVersionNumbers(
  1030. WCHAR *pwszMM,
  1031. DWORD *pdwMajor,
  1032. DWORD *pdwMinor,
  1033. DWORD *pdwBuild,
  1034. WCHAR *pwcFlagMinor,
  1035. WCHAR *pwcFlagBuild)
  1036. {
  1037. //
  1038. // special characters:
  1039. // - = all versions less than or equal to
  1040. // < = all versions less than or equal to
  1041. // > = all versions greater than or equal to
  1042. // X = all sub-versions.
  1043. //
  1044. WCHAR *pwszEnd;
  1045. *pdwMajor = 0;
  1046. *pdwMinor = 0;
  1047. *pdwBuild = 0;
  1048. *pwcFlagMinor = L'\0';
  1049. *pwcFlagBuild = L'\0';
  1050. if (pwszEnd = wcschr(pwszMM, OSATTR_VERSEP))
  1051. {
  1052. *pwszEnd = NULL;
  1053. }
  1054. *pdwMajor = (DWORD) _wtol(pwszMM);
  1055. //
  1056. // If there is only a major ver then return now, otherwise,
  1057. // continue processiing
  1058. //
  1059. if (pwszEnd == NULL)
  1060. {
  1061. return (TRUE);
  1062. }
  1063. *pwszEnd = OSATTR_VERSEP;
  1064. pwszMM = pwszEnd;
  1065. pwszMM++;
  1066. if (*pwszMM == '/0')
  1067. {
  1068. return (TRUE);
  1069. }
  1070. //
  1071. // Get the minor ver/wildcard
  1072. //
  1073. if ((*pwszMM == OSATTR_GTEQ) ||
  1074. (*pwszMM == OSATTR_LTEQ) ||
  1075. (*pwszMM == OSATTR_LTEQ2) ||
  1076. (towupper(*pwszMM) == OSATTR_ALL))
  1077. {
  1078. *pwcFlagMinor = towupper(*pwszMM);
  1079. return(TRUE);
  1080. }
  1081. if (!(pwszEnd = wcschr(pwszMM, OSATTR_VERSEP)))
  1082. {
  1083. *pdwMinor = (DWORD) _wtol(pwszMM);
  1084. //
  1085. // This grandfathers all catalog files that had an OSAttr string of
  1086. // 2:4.1 to be 2:4.1.*
  1087. //
  1088. *pwcFlagBuild = OSATTR_ALL;
  1089. return(TRUE);
  1090. }
  1091. *pwszEnd = NULL;
  1092. *pdwMinor = (DWORD) _wtol(pwszMM);
  1093. *pwszEnd = OSATTR_VERSEP;
  1094. pwszMM = pwszEnd;
  1095. pwszMM++;
  1096. //
  1097. // Get the build#/wildcard
  1098. //
  1099. if ((*pwszMM == OSATTR_GTEQ) ||
  1100. (*pwszMM == OSATTR_LTEQ) ||
  1101. (*pwszMM == OSATTR_LTEQ2) ||
  1102. (towupper(*pwszMM) == OSATTR_ALL))
  1103. {
  1104. *pwcFlagBuild = towupper(*pwszMM);
  1105. return(TRUE);
  1106. }
  1107. *pdwBuild = (DWORD) _wtol(pwszMM);
  1108. *pwcFlagBuild = L'\0';
  1109. return(TRUE);
  1110. }
  1111. STDAPI DriverRegisterServer(void)
  1112. {
  1113. GUID gDriver = DRIVER_ACTION_VERIFY;
  1114. CRYPT_REGISTER_ACTIONID sRegAID;
  1115. memset(&sRegAID, 0x00, sizeof(CRYPT_REGISTER_ACTIONID));
  1116. sRegAID.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
  1117. // use our init policy
  1118. sRegAID.sInitProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  1119. sRegAID.sInitProvider.pwszDLLName = SP_POLICY_PROVIDER_DLL_NAME;
  1120. sRegAID.sInitProvider.pwszFunctionName = DRIVER_INITPROV_FUNCTION;
  1121. // use standard object policy
  1122. sRegAID.sObjectProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  1123. sRegAID.sObjectProvider.pwszDLLName = SP_POLICY_PROVIDER_DLL_NAME;
  1124. sRegAID.sObjectProvider.pwszFunctionName = SP_OBJTRUST_FUNCTION;
  1125. // use standard signature policy
  1126. sRegAID.sSignatureProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  1127. sRegAID.sSignatureProvider.pwszDLLName = SP_POLICY_PROVIDER_DLL_NAME;
  1128. sRegAID.sSignatureProvider.pwszFunctionName = SP_SIGTRUST_FUNCTION;
  1129. // use standard cert builder
  1130. sRegAID.sCertificateProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  1131. sRegAID.sCertificateProvider.pwszDLLName = WT_PROVIDER_DLL_NAME;
  1132. sRegAID.sCertificateProvider.pwszFunctionName = WT_PROVIDER_CERTTRUST_FUNCTION;
  1133. // use standard cert policy
  1134. sRegAID.sCertificatePolicyProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  1135. sRegAID.sCertificatePolicyProvider.pwszDLLName = SP_POLICY_PROVIDER_DLL_NAME;
  1136. sRegAID.sCertificatePolicyProvider.pwszFunctionName = SP_CHKCERT_FUNCTION;
  1137. // use our final policy
  1138. sRegAID.sFinalPolicyProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  1139. sRegAID.sFinalPolicyProvider.pwszDLLName = SP_POLICY_PROVIDER_DLL_NAME;
  1140. sRegAID.sFinalPolicyProvider.pwszFunctionName = DRIVER_FINALPOLPROV_FUNCTION;
  1141. // use our cleanup policy
  1142. sRegAID.sCleanupProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  1143. sRegAID.sCleanupProvider.pwszDLLName = SP_POLICY_PROVIDER_DLL_NAME;
  1144. sRegAID.sCleanupProvider.pwszFunctionName = DRIVER_CLEANUPPOLICY_FUNCTION;
  1145. //
  1146. // Register our provider GUID...
  1147. //
  1148. if (!(WintrustAddActionID(&gDriver, 0, &sRegAID)))
  1149. {
  1150. return (S_FALSE);
  1151. }
  1152. return (S_OK);
  1153. }
  1154. STDAPI DriverUnregisterServer(void)
  1155. {
  1156. GUID gDriver = DRIVER_ACTION_VERIFY;
  1157. if (!(WintrustRemoveActionID(&gDriver)))
  1158. {
  1159. return (S_FALSE);
  1160. }
  1161. return (S_OK);
  1162. }