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.

300 lines
10 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1996 - 1999
  6. //
  7. // File: offprov.cpp
  8. //
  9. // Contents: Microsoft Internet Security Authenticode Policy Provider
  10. //
  11. // Functions: OfficeRegisterServer
  12. // OfficeUnregisterServer
  13. // OfficeInitializePolicy
  14. // OfficeCleanupPolicy
  15. //
  16. // *** local functions ***
  17. // _SetOverrideText
  18. //
  19. // History: 18-Aug-1997 pberkman created
  20. //
  21. //--------------------------------------------------------------------------
  22. #include "global.hxx"
  23. void _SetOverrideText(CRYPT_PROVIDER_DATA *pProvData, WCHAR **ppwszRet, DWORD dwStringId);
  24. //////////////////////////////////////////////////////////////////////////////
  25. //
  26. // OfficeRegisterServer
  27. //----------------------------------------------------------------------------
  28. // Register the office provider
  29. //
  30. STDAPI OfficeRegisterServer(void)
  31. {
  32. GUID gOfficeProv = OFFICESIGN_ACTION_VERIFY;
  33. CRYPT_REGISTER_ACTIONID sRegAID;
  34. memset(&sRegAID, 0x00, sizeof(CRYPT_REGISTER_ACTIONID));
  35. sRegAID.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
  36. // my initialization provider
  37. sRegAID.sInitProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  38. sRegAID.sInitProvider.pwszDLLName = OFFICE_POLICY_PROVIDER_DLL_NAME;
  39. sRegAID.sInitProvider.pwszFunctionName = OFFICE_INITPROV_FUNCTION;
  40. // Authenticode object provider
  41. sRegAID.sObjectProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  42. sRegAID.sObjectProvider.pwszDLLName = SP_POLICY_PROVIDER_DLL_NAME;
  43. sRegAID.sObjectProvider.pwszFunctionName = SP_OBJTRUST_FUNCTION;
  44. // Authenticode signature provider
  45. sRegAID.sSignatureProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  46. sRegAID.sSignatureProvider.pwszDLLName = SP_POLICY_PROVIDER_DLL_NAME;
  47. sRegAID.sSignatureProvider.pwszFunctionName = SP_SIGTRUST_FUNCTION;
  48. // wintrust's certificate provider
  49. sRegAID.sCertificateProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  50. sRegAID.sCertificateProvider.pwszDLLName = WT_PROVIDER_DLL_NAME; // set to wintrust.dll
  51. sRegAID.sCertificateProvider.pwszFunctionName = WT_PROVIDER_CERTTRUST_FUNCTION; // use wintrust's standard!
  52. // Authenticode certificate checker
  53. sRegAID.sCertificatePolicyProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  54. sRegAID.sCertificatePolicyProvider.pwszDLLName = SP_POLICY_PROVIDER_DLL_NAME;
  55. sRegAID.sCertificatePolicyProvider.pwszFunctionName = SP_CHKCERT_FUNCTION;
  56. // Authenticode final
  57. sRegAID.sFinalPolicyProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  58. sRegAID.sFinalPolicyProvider.pwszDLLName = SP_POLICY_PROVIDER_DLL_NAME;
  59. sRegAID.sFinalPolicyProvider.pwszFunctionName = SP_FINALPOLICY_FUNCTION;
  60. // Authenticode cleanup
  61. sRegAID.sCleanupProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  62. sRegAID.sCleanupProvider.pwszDLLName = OFFICE_POLICY_PROVIDER_DLL_NAME;
  63. sRegAID.sCleanupProvider.pwszFunctionName = OFFICE_CLEANUPPOLICY_FUNCTION;
  64. if (WintrustAddActionID(&gOfficeProv, 0, &sRegAID))
  65. {
  66. return(S_OK);
  67. }
  68. return(S_FALSE);
  69. }
  70. //////////////////////////////////////////////////////////////////////////////
  71. //
  72. // DllUnregisterServer
  73. //----------------------------------------------------------------------------
  74. // unregisters office provider
  75. //
  76. STDAPI OfficeUnregisterServer(void)
  77. {
  78. GUID gOfficeProv = OFFICESIGN_ACTION_VERIFY;
  79. WintrustRemoveActionID(&gOfficeProv);
  80. return(S_OK);
  81. }
  82. typedef struct _OFFPROV_PRIVATE_DATA
  83. {
  84. DWORD cbStruct;
  85. CRYPT_PROVIDER_FUNCTIONS sAuthenticodePfns;
  86. } OFFPROV_PRIVATE_DATA, *POFFPROV_PRIVATE_DATA;
  87. //////////////////////////////////////////////////////////////////////////////
  88. //
  89. // Initialize Policy Provider function: OfficeInitializePolicy
  90. //----------------------------------------------------------------------------
  91. // change the OID to the email OID for Usage....
  92. //
  93. static char *pszOfficeUsage = szOID_PKIX_KP_CODE_SIGNING;
  94. HRESULT WINAPI OfficeInitializePolicy(CRYPT_PROVIDER_DATA *pProvData)
  95. {
  96. if (!(pProvData->padwTrustStepErrors) ||
  97. (pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_WVTINIT] != ERROR_SUCCESS))
  98. {
  99. return(S_FALSE);
  100. }
  101. if (!(_ISINSTRUCT(CRYPT_PROVIDER_DATA, pProvData->cbStruct, pszUsageOID)))
  102. {
  103. pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_INITPROV] = ERROR_INVALID_PARAMETER;
  104. return(S_FALSE);
  105. }
  106. GUID gAuthenticode = WINTRUST_ACTION_GENERIC_VERIFY_V2;
  107. GUID gOfficeProv = OFFICESIGN_ACTION_VERIFY;
  108. CRYPT_PROVIDER_PRIVDATA sPrivData;
  109. CRYPT_PROVIDER_PRIVDATA *pPrivData;
  110. OFFPROV_PRIVATE_DATA *pOfficeData;
  111. HRESULT hr;
  112. memset(&sPrivData, 0x00, sizeof(CRYPT_PROVIDER_PRIVDATA));
  113. sPrivData.cbStruct = sizeof(CRYPT_PROVIDER_PRIVDATA);
  114. memcpy(&sPrivData.gProviderID, &gOfficeProv, sizeof(GUID));
  115. //
  116. // add my data to the chain!
  117. //
  118. if (!pProvData->psPfns->pfnAddPrivData2Chain(pProvData, &sPrivData))
  119. {
  120. return(S_FALSE);
  121. }
  122. //
  123. // get the new reference
  124. //
  125. pPrivData = WTHelperGetProvPrivateDataFromChain(pProvData, &gOfficeProv);
  126. //
  127. // allocate space for my struct
  128. //
  129. if (!(pPrivData->pvProvData = pProvData->psPfns->pfnAlloc(sizeof(OFFPROV_PRIVATE_DATA))))
  130. {
  131. pProvData->dwError = GetLastError();
  132. pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_INITPROV] = TRUST_E_SYSTEM_ERROR;
  133. return(S_FALSE);
  134. }
  135. memset(pPrivData->pvProvData, 0x00, sizeof(OFFPROV_PRIVATE_DATA));
  136. pPrivData->cbProvData = sizeof(OFFPROV_PRIVATE_DATA);
  137. pOfficeData = (OFFPROV_PRIVATE_DATA *)pPrivData->pvProvData;
  138. pOfficeData->cbStruct = sizeof(OFFPROV_PRIVATE_DATA);
  139. //
  140. // fill in the Authenticode Functions
  141. //
  142. pOfficeData->sAuthenticodePfns.cbStruct = sizeof(CRYPT_PROVIDER_FUNCTIONS);
  143. if (!(WintrustLoadFunctionPointers(&gAuthenticode, &pOfficeData->sAuthenticodePfns)))
  144. {
  145. pProvData->psPfns->pfnFree(sPrivData.pvProvData);
  146. pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_INITPROV] = TRUST_E_PROVIDER_UNKNOWN;
  147. return(S_FALSE);
  148. }
  149. if (pOfficeData->sAuthenticodePfns.pfnInitialize)
  150. {
  151. hr = pOfficeData->sAuthenticodePfns.pfnInitialize(pProvData);
  152. }
  153. //
  154. // assign our usage
  155. //
  156. pProvData->pszUsageOID = pszOfficeUsage;
  157. //
  158. // change the text on the dialog buttons
  159. //
  160. if (pProvData->psPfns->psUIpfns)
  161. {
  162. if (pProvData->psPfns->psUIpfns->psUIData)
  163. {
  164. if (!(_ISINSTRUCT(CRYPT_PROVUI_DATA, pProvData->psPfns->psUIpfns->psUIData->cbStruct, pCopyActionTextNotSigned)))
  165. {
  166. return(hr);
  167. }
  168. _SetOverrideText(pProvData, &pProvData->psPfns->psUIpfns->psUIData->pYesButtonText,
  169. IDS_OFFICE_YES_BUTTON_TEXT);
  170. _SetOverrideText(pProvData, &pProvData->psPfns->psUIpfns->psUIData->pNoButtonText,
  171. IDS_OFFICE_NO_BUTTON_TEXT);
  172. _SetOverrideText(pProvData, &pProvData->psPfns->psUIpfns->psUIData->pCopyActionText,
  173. IDS_OFFICE_COPYACTION_TEXT);
  174. _SetOverrideText(pProvData, &pProvData->psPfns->psUIpfns->psUIData->pCopyActionTextNoTS,
  175. IDS_OFFICE_COPYACTION_NOTS_TEXT);
  176. _SetOverrideText(pProvData, &pProvData->psPfns->psUIpfns->psUIData->pCopyActionTextNotSigned,
  177. IDS_OFFICE_COPYACTION_NOSIGN_TEXT);
  178. }
  179. }
  180. return(hr);
  181. }
  182. void _SetOverrideText(CRYPT_PROVIDER_DATA *pProvData, WCHAR **ppwszRet, DWORD dwStringId)
  183. {
  184. WCHAR wsz[MAX_PATH];
  185. if (*ppwszRet)
  186. {
  187. pProvData->psPfns->pfnFree(*ppwszRet);
  188. *ppwszRet = NULL;
  189. }
  190. wsz[0] = NULL;
  191. LoadStringU(hinst, dwStringId, &wsz[0], MAX_PATH);
  192. if (wsz[0])
  193. {
  194. if (*ppwszRet = (WCHAR *)pProvData->psPfns->pfnAlloc((wcslen(&wsz[0]) + 1) * sizeof(WCHAR)))
  195. {
  196. wcscpy(*ppwszRet, &wsz[0]);
  197. }
  198. }
  199. }
  200. HRESULT WINAPI OfficeCleanupPolicy(CRYPT_PROVIDER_DATA *pProvData)
  201. {
  202. GUID gOfficeProv = OFFICESIGN_ACTION_VERIFY;
  203. CRYPT_PROVIDER_PRIVDATA *pMyData;
  204. OFFPROV_PRIVATE_DATA *pOfficeData;
  205. HRESULT hr = S_OK;
  206. if (!(pProvData->padwTrustStepErrors) ||
  207. (pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_WVTINIT] != ERROR_SUCCESS))
  208. {
  209. return(S_FALSE);
  210. }
  211. pMyData = WTHelperGetProvPrivateDataFromChain(pProvData, &gOfficeProv);
  212. if (pMyData)
  213. {
  214. pOfficeData = (OFFPROV_PRIVATE_DATA *)pMyData->pvProvData;
  215. //
  216. // remove the data we allocated except for the "MyData" which WVT will clean up for us!
  217. //
  218. if (pOfficeData->sAuthenticodePfns.pfnCleanupPolicy)
  219. {
  220. hr = pOfficeData->sAuthenticodePfns.pfnCleanupPolicy(pProvData);
  221. }
  222. pProvData->psPfns->pfnFree(pMyData->pvProvData);
  223. pMyData->pvProvData = NULL;
  224. }
  225. if (pProvData->psPfns->psUIpfns)
  226. {
  227. if (pProvData->psPfns->psUIpfns->psUIData)
  228. {
  229. if (_ISINSTRUCT(CRYPT_PROVUI_DATA, pProvData->psPfns->psUIpfns->psUIData->cbStruct, pCopyActionText))
  230. {
  231. pProvData->psPfns->pfnFree(pProvData->psPfns->psUIpfns->psUIData->pYesButtonText);
  232. pProvData->psPfns->psUIpfns->psUIData->pYesButtonText = NULL;
  233. pProvData->psPfns->pfnFree(pProvData->psPfns->psUIpfns->psUIData->pNoButtonText);
  234. pProvData->psPfns->psUIpfns->psUIData->pNoButtonText = NULL;
  235. pProvData->psPfns->pfnFree(pProvData->psPfns->psUIpfns->psUIData->pCopyActionText);
  236. pProvData->psPfns->psUIpfns->psUIData->pCopyActionText = NULL;
  237. }
  238. }
  239. }
  240. return(hr);
  241. }