/*********************************************************************** * DllRegisterServer (MSISIP.@) */ HRESULT WINAPI DllRegisterServer(void) { static WCHAR msisip[] = { 'M','S','I','S','I','P','.','D','L','L',0 }; static WCHAR getSignedDataMsg[] = { 'M','s','i','S','I','P','G','e','t', 'S','i','g','n','e','d','D','a','t','a','M','s','g',0 }; static WCHAR putSignedDataMsg[] = { 'M','s','i','S','I','P','P','u','t', 'S','i','g','n','e','d','D','a','t','a','M','s','g',0 }; static WCHAR createIndirectData[] = { 'M','s','i','S','I','P', 'C','r','e','a','t','e','I','n','d','i','r','e','c','t','D','a','t','a', 0 }; static WCHAR verifyIndirectData[] = { 'M','s','i','S','I','P', 'V','e','r','i','f','y','I','n','d','i','r','e','c','t','D','a','t','a', 0 }; static WCHAR removeSignedDataMsg[] = { 'M','s','i','S','I','P','R','e','m', 'o','v','e','S','i','g','n','e','d','D','a','t','a','M','s','g', 0 }; static WCHAR isMyTypeOfFile[] = { 'M','s','i','S','I','P', 'I','s','M','y','T','y','p','e','O','f','F','i','l','e',0 }; SIP_ADD_NEWPROVIDER prov; memset(&prov, 0, sizeof(prov)); prov.cbStruct = sizeof(prov); prov.pwszDLLFileName = msisip; prov.pgSubject = &mySubject; prov.pwszGetFuncName = getSignedDataMsg; prov.pwszPutFuncName = putSignedDataMsg; prov.pwszCreateFuncName = createIndirectData; prov.pwszVerifyFuncName = verifyIndirectData; prov.pwszRemoveFuncName = removeSignedDataMsg; prov.pwszIsFunctionNameFmt2 = isMyTypeOfFile; return CryptSIPAddProvider(&prov) ? S_OK : S_FALSE; }
/*********************************************************************** * WINTRUST_SIPPAddProvider * * Helper for DllRegisterServer. */ static BOOL WINTRUST_SIPPAddProvider(GUID* Subject, WCHAR* MagicNumber) { static WCHAR CryptSIPGetSignedDataMsg[] = {'C','r','y','p','t','S','I','P','G','e','t','S','i','g','n','e','d','D','a','t','a','M','s','g', 0}; static WCHAR CryptSIPPutSignedDataMsg[] = {'C','r','y','p','t','S','I','P','P','u','t','S','i','g','n','e','d','D','a','t','a','M','s','g', 0}; static WCHAR CryptSIPCreateIndirectData[] = {'C','r','y','p','t','S','I','P','C','r','e','a','t','e','I','n','d','i','r','e','c','t','D','a','t','a', 0}; static WCHAR CryptSIPVerifyIndirectData[] = {'C','r','y','p','t','S','I','P','V','e','r','i','f','y','I','n','d','i','r','e','c','t','D','a','t','a', 0}; static WCHAR CryptSIPRemoveSignedDataMsg[] = {'C','r','y','p','t','S','I','P','R','e','m','o','v','e','S','i','g','n','e','d','D','a','t','a','M','s','g', 0}; SIP_ADD_NEWPROVIDER NewProv; BOOL Ret; /* Clear and initialize the structure */ memset(&NewProv, 0, sizeof(SIP_ADD_NEWPROVIDER)); NewProv.cbStruct = sizeof(SIP_ADD_NEWPROVIDER); NewProv.pwszDLLFileName = WINTRUST_Alloc(sizeof(SP_POLICY_PROVIDER_DLL_NAME)); /* Fill the structure */ NewProv.pgSubject = Subject; lstrcpyW(NewProv.pwszDLLFileName, SP_POLICY_PROVIDER_DLL_NAME); NewProv.pwszMagicNumber = MagicNumber; NewProv.pwszIsFunctionName = NULL; NewProv.pwszGetFuncName = CryptSIPGetSignedDataMsg; NewProv.pwszPutFuncName = CryptSIPPutSignedDataMsg; NewProv.pwszCreateFuncName = CryptSIPCreateIndirectData; NewProv.pwszVerifyFuncName = CryptSIPVerifyIndirectData; NewProv.pwszRemoveFuncName = CryptSIPRemoveSignedDataMsg; NewProv.pwszIsFunctionNameFmt2 = NULL; NewProv.pwszGetCapFuncName = NULL; Ret = CryptSIPAddProvider(&NewProv); WINTRUST_Free(NewProv.pwszDLLFileName); return Ret; }
static void test_AddRemoveProvider(void) { BOOL ret; SIP_ADD_NEWPROVIDER newprov; GUID actionid = { 0xdeadbe, 0xefde, 0xadbe, { 0xef,0xde,0xad,0xbe,0xef,0xde,0xad,0xbe }}; static WCHAR dummydll[] = {'d','e','a','d','b','e','e','f','.','d','l','l',0 }; static WCHAR dummyfunction[] = {'d','u','m','m','y','f','u','n','c','t','i','o','n',0 }; /* NULL check */ SetLastError(0xdeadbeef); ret = CryptSIPRemoveProvider(NULL); ok (!ret, "Expected CryptSIPRemoveProvider to fail.\n"); ok (GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d.\n", GetLastError()); /* nonexistent provider should result in a registry error */ SetLastError(0xdeadbeef); ret = CryptSIPRemoveProvider(&actionid); if (!ret && GetLastError() == ERROR_ACCESS_DENIED) { /* Apparently the needed rights are checked before the existence of the provider */ skip("Need admin rights\n"); } else { /* On some Win98 systems, CryptSIPRemoveProvider always succeeds if * the arguments are correct, whether or not the registry key is * present, so don't test ret, just check the last error if it does * return FALSE. */ if (!ret) ok (GetLastError() == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d.\n", GetLastError()); } /* Everything OK, pwszIsFunctionName and pwszIsFunctionNameFmt2 are left NULL * as allowed */ memset(&newprov, 0, sizeof(SIP_ADD_NEWPROVIDER)); newprov.cbStruct = sizeof(SIP_ADD_NEWPROVIDER); newprov.pgSubject = &actionid; newprov.pwszDLLFileName = dummydll; newprov.pwszGetFuncName = dummyfunction; newprov.pwszPutFuncName = dummyfunction; newprov.pwszCreateFuncName = dummyfunction; newprov.pwszVerifyFuncName = dummyfunction; newprov.pwszRemoveFuncName = dummyfunction; SetLastError(0xdeadbeef); ret = CryptSIPAddProvider(&newprov); if (!ret && GetLastError() == ERROR_ACCESS_DENIED) { skip("Need admin rights\n"); return; } ok ( ret, "CryptSIPAddProvider should have succeeded, last error %d\n", GetLastError()); /* Dummy provider will be deleted, but the function still fails because * pwszIsFunctionName and pwszIsFunctionNameFmt2 are not present in the * registry. */ SetLastError(0xdeadbeef); ret = CryptSIPRemoveProvider(&actionid); /* On some Win98 systems, CryptSIPRemoveProvider always succeeds if * the arguments are correct, whether or not the registry key is * present, so don't test ret, just check the last error if it does * return FALSE. */ if (!ret) ok (GetLastError() == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d.\n", GetLastError()); /* Everything OK */ memset(&newprov, 0, sizeof(SIP_ADD_NEWPROVIDER)); newprov.cbStruct = sizeof(SIP_ADD_NEWPROVIDER); newprov.pgSubject = &actionid; newprov.pwszDLLFileName = dummydll; newprov.pwszGetFuncName = dummyfunction; newprov.pwszPutFuncName = dummyfunction; newprov.pwszCreateFuncName = dummyfunction; newprov.pwszVerifyFuncName = dummyfunction; newprov.pwszRemoveFuncName = dummyfunction; newprov.pwszIsFunctionNameFmt2 = dummyfunction; newprov.pwszIsFunctionName = dummyfunction; /* If GetCapFuncName set to NULL, then CryptSIPRemoveProvider fails on win 8 */ newprov.pwszGetCapFuncName = dummyfunction; SetLastError(0xdeadbeef); ret = CryptSIPAddProvider(&newprov); ok ( ret, "CryptSIPAddProvider should have succeeded, last error %d\n", GetLastError()); /* Dummy provider should be deleted */ SetLastError(0xdeadbeef); ret = CryptSIPRemoveProvider(&actionid); ok ( ret, "CryptSIPRemoveProvider should have succeeded, last error %d\n", GetLastError()); }