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.

235 lines
7.3 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1996 - 1999
  6. //
  7. // File: dllmain.cpp
  8. //
  9. // Contents: Microsoft Internet Security Authenticode Policy Provider
  10. //
  11. // Functions: DllMain
  12. // DllRegisterServer
  13. // DllUnregisterServer
  14. // OpenTrustedPublisherStore
  15. // OpenDisallowedStore
  16. //
  17. // *** local functions ***
  18. // SPNew
  19. //
  20. // History: 28-May-1997 pberkman created
  21. //
  22. //--------------------------------------------------------------------------
  23. #include "global.hxx"
  24. HINSTANCE hinst;
  25. HCERTSTORE g_hStoreTrustedPublisher;
  26. HCERTSTORE g_hStoreDisallowed;
  27. //////////////////////////////////////////////////////////////////////////////////////
  28. //
  29. // standard DLL exports ...
  30. //
  31. //
  32. BOOL WINAPI SoftpubDllMain(HANDLE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
  33. {
  34. switch (fdwReason) {
  35. case DLL_PROCESS_ATTACH:
  36. hinst = (HINSTANCE)hInstDLL;
  37. break;
  38. case DLL_PROCESS_DETACH:
  39. if (g_hStoreTrustedPublisher)
  40. CertCloseStore(g_hStoreTrustedPublisher, 0);
  41. if (g_hStoreDisallowed)
  42. CertCloseStore(g_hStoreDisallowed, 0);
  43. break;
  44. case DLL_THREAD_DETACH:
  45. default:
  46. break;
  47. }
  48. return(TRUE);
  49. }
  50. HCERTSTORE
  51. WINAPI
  52. _OpenCachedHKCUStore(
  53. IN OUT HCERTSTORE *phStoreCache,
  54. IN LPCWSTR pwszStore
  55. )
  56. {
  57. HCERTSTORE hStore;
  58. hStore = *phStoreCache;
  59. if (NULL == hStore) {
  60. hStore = CertOpenStore(
  61. CERT_STORE_PROV_SYSTEM_W,
  62. 0,
  63. NULL,
  64. CERT_SYSTEM_STORE_CURRENT_USER |
  65. CERT_STORE_MAXIMUM_ALLOWED_FLAG |
  66. CERT_STORE_SHARE_CONTEXT_FLAG,
  67. (const void *) pwszStore
  68. );
  69. if (hStore) {
  70. HCERTSTORE hPrevStore;
  71. CertControlStore(
  72. hStore,
  73. 0, // dwFlags
  74. CERT_STORE_CTRL_AUTO_RESYNC,
  75. NULL // pvCtrlPara
  76. );
  77. hPrevStore = InterlockedCompareExchangePointer(
  78. phStoreCache, hStore, NULL);
  79. if (hPrevStore) {
  80. CertCloseStore(hStore, 0);
  81. hStore = hPrevStore;
  82. }
  83. }
  84. }
  85. if (hStore)
  86. hStore = CertDuplicateStore(hStore);
  87. return hStore;
  88. }
  89. HCERTSTORE
  90. WINAPI
  91. OpenTrustedPublisherStore()
  92. {
  93. return _OpenCachedHKCUStore(&g_hStoreTrustedPublisher,
  94. L"TrustedPublisher");
  95. }
  96. HCERTSTORE
  97. WINAPI
  98. OpenDisallowedStore()
  99. {
  100. return _OpenCachedHKCUStore(&g_hStoreDisallowed, L"Disallowed");
  101. }
  102. #include "wvtver1.h"
  103. STDAPI SoftpubDllRegisterServer(void)
  104. {
  105. GUID gV1UISup = V1_WIN_SPUB_ACTION_PUBLISHED_SOFTWARE;
  106. GUID gV1UINoBad = V1_WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI;
  107. GUID gV2 = WINTRUST_ACTION_GENERIC_VERIFY_V2;
  108. GUID gV2TrstTest = WINTRUST_ACTION_TRUSTPROVIDER_TEST;
  109. GUID gCert = WINTRUST_ACTION_GENERIC_CERT_VERIFY;
  110. CRYPT_REGISTER_ACTIONID sRegAID;
  111. CRYPT_PROVIDER_REGDEFUSAGE sDefUsage;
  112. BOOL fRet;
  113. fRet = TRUE;
  114. memset(&sDefUsage, 0x00, sizeof(CRYPT_PROVIDER_REGDEFUSAGE));
  115. sDefUsage.cbStruct = sizeof(CRYPT_PROVIDER_REGDEFUSAGE);
  116. sDefUsage.pgActionID = &gV2;
  117. fRet &= WintrustAddDefaultForUsage(szOID_PKIX_KP_CODE_SIGNING, &sDefUsage);
  118. memset(&sRegAID, 0x00, sizeof(CRYPT_REGISTER_ACTIONID));
  119. sRegAID.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
  120. sRegAID.sInitProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  121. sRegAID.sInitProvider.pwszDLLName = SP_POLICY_PROVIDER_DLL_NAME;
  122. sRegAID.sInitProvider.pwszFunctionName = SP_INIT_FUNCTION;
  123. sRegAID.sObjectProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  124. sRegAID.sObjectProvider.pwszDLLName = SP_POLICY_PROVIDER_DLL_NAME;
  125. sRegAID.sObjectProvider.pwszFunctionName = SP_OBJTRUST_FUNCTION;
  126. sRegAID.sSignatureProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  127. sRegAID.sSignatureProvider.pwszDLLName = SP_POLICY_PROVIDER_DLL_NAME;
  128. sRegAID.sSignatureProvider.pwszFunctionName = SP_SIGTRUST_FUNCTION;
  129. sRegAID.sCertificateProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  130. sRegAID.sCertificateProvider.pwszDLLName = WT_PROVIDER_DLL_NAME;
  131. sRegAID.sCertificateProvider.pwszFunctionName = WT_PROVIDER_CERTTRUST_FUNCTION;
  132. sRegAID.sCertificatePolicyProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  133. sRegAID.sCertificatePolicyProvider.pwszDLLName = SP_POLICY_PROVIDER_DLL_NAME;
  134. sRegAID.sCertificatePolicyProvider.pwszFunctionName = SP_CHKCERT_FUNCTION;
  135. sRegAID.sFinalPolicyProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  136. sRegAID.sFinalPolicyProvider.pwszDLLName = SP_POLICY_PROVIDER_DLL_NAME;
  137. sRegAID.sFinalPolicyProvider.pwszFunctionName = SP_FINALPOLICY_FUNCTION;
  138. sRegAID.sCleanupProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  139. sRegAID.sCleanupProvider.pwszDLLName = SP_POLICY_PROVIDER_DLL_NAME;
  140. sRegAID.sCleanupProvider.pwszFunctionName = SP_CLEANUPPOLICY_FUNCTION;
  141. //
  142. // V2
  143. //
  144. fRet &= WintrustAddActionID(&gV2, 0, &sRegAID);
  145. //
  146. // support for V1
  147. //
  148. fRet &= WintrustAddActionID(&gV1UISup, 0, &sRegAID);
  149. fRet &= WintrustAddActionID(&gV1UINoBad, 0, &sRegAID);
  150. sRegAID.sInitProvider.pwszFunctionName = SP_GENERIC_CERT_INIT_FUNCTION;
  151. fRet &= WintrustAddActionID(&gCert, 0, &sRegAID);
  152. sRegAID.sInitProvider.pwszFunctionName = SP_INIT_FUNCTION;
  153. //
  154. // testing support
  155. //
  156. sRegAID.sTestPolicyProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  157. sRegAID.sTestPolicyProvider.pwszDLLName = SP_POLICY_PROVIDER_DLL_NAME;
  158. sRegAID.sTestPolicyProvider.pwszFunctionName = SP_TESTDUMPPOLICY_FUNCTION_TEST;
  159. fRet &= WintrustAddActionID(&gV2TrstTest, 0, &sRegAID);
  160. memset(&sRegAID.sTestPolicyProvider, 0x00, sizeof(CRYPT_TRUST_REG_ENTRY));
  161. if (fRet)
  162. {
  163. HTTPSRegisterServer();
  164. OfficeRegisterServer();
  165. DriverRegisterServer();
  166. GenericChainRegisterServer();
  167. return(S_OK);
  168. }
  169. return(S_FALSE);
  170. }
  171. STDAPI SoftpubDllUnregisterServer(void)
  172. {
  173. GUID gV1UISup = V1_WIN_SPUB_ACTION_PUBLISHED_SOFTWARE;
  174. GUID gV1UINoBad = V1_WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI;
  175. GUID gV2 = WINTRUST_ACTION_GENERIC_VERIFY_V2;
  176. GUID gV2TrstTest = WINTRUST_ACTION_TRUSTPROVIDER_TEST;
  177. GUID gCert = WINTRUST_ACTION_GENERIC_CERT_VERIFY;
  178. WintrustRemoveActionID(&gV1UISup);
  179. WintrustRemoveActionID(&gV1UINoBad);
  180. WintrustRemoveActionID(&gV2);
  181. WintrustRemoveActionID(&gV2TrstTest);
  182. WintrustRemoveActionID(&gCert);
  183. HTTPSUnregisterServer();
  184. OfficeUnregisterServer();
  185. DriverUnregisterServer();
  186. GenericChainUnregisterServer();
  187. return(S_OK);
  188. }