1 /* Unit test suite for wintrust API functions
3 * Copyright 2006 Paul Vriens
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "wine/test.h"
31 static BOOL (WINAPI * pWintrustAddActionID)(GUID*, DWORD, CRYPT_REGISTER_ACTIONID*);
32 static BOOL (WINAPI * pWintrustAddDefaultForUsage)(const CHAR*,CRYPT_PROVIDER_REGDEFUSAGE*);
33 static BOOL (WINAPI * pWintrustRemoveActionID)(GUID*);
35 static HMODULE hWintrust = 0;
37 #define WINTRUST_GET_PROC(func) \
38 p ## func = (void*)GetProcAddress(hWintrust, #func); \
40 trace("GetProcAddress(%s) failed\n", #func); \
41 FreeLibrary(hWintrust); \
45 static BOOL InitFunctionPtrs(void)
47 hWintrust = LoadLibraryA("wintrust.dll");
51 trace("Could not load wintrust.dll\n");
55 WINTRUST_GET_PROC(WintrustAddActionID)
56 WINTRUST_GET_PROC(WintrustAddDefaultForUsage)
57 WINTRUST_GET_PROC(WintrustRemoveActionID)
62 static void test_AddRem_ActionID(void)
64 static WCHAR DummyDllW[] = {'d','e','a','d','b','e','e','f','.','d','l','l',0 };
65 static WCHAR DummyFunctionW[] = {'d','u','m','m','y','f','u','n','c','t','i','o','n',0 };
66 GUID ActionID = { 0xdeadbeef, 0xdead, 0xbeef, { 0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef }};
67 CRYPT_REGISTER_ACTIONID ActionIDFunctions;
68 CRYPT_TRUST_REG_ENTRY EmptyProvider = { 0, NULL, NULL };
69 CRYPT_TRUST_REG_ENTRY DummyProvider = { sizeof(CRYPT_TRUST_REG_ENTRY), DummyDllW, DummyFunctionW };
73 SetLastError(0xdeadbeef);
74 ret = pWintrustAddActionID(NULL, 0, NULL);
75 ok (!ret, "Expected WintrustAddActionID to fail.\n");
76 ok (GetLastError() == ERROR_INVALID_PARAMETER /* XP/W2K3 */ ||
77 GetLastError() == 0xdeadbeef /* Win98/NT4/W2K */,
78 "Expected ERROR_INVALID_PARAMETER(W2K3) or 0xdeadbeef(Win98/NT4/W2K), got %ld.\n", GetLastError());
81 SetLastError(0xdeadbeef);
82 ret = pWintrustAddActionID(&ActionID, 0, NULL);
83 ok (!ret, "Expected WintrustAddActionID to fail.\n");
84 ok (GetLastError() == ERROR_INVALID_PARAMETER /* XP/W2K3 */ ||
85 GetLastError() == 0xdeadbeef /* Win98/NT4/W2K */,
86 "Expected ERROR_INVALID_PARAMETER(W2K3) or 0xdeadbeef(Win98/NT4/W2K), got %ld.\n", GetLastError());
88 /* All OK (although no functions defined), except cbStruct is not set in ActionIDFunctions */
89 SetLastError(0xdeadbeef);
90 memset(&ActionIDFunctions, 0, sizeof(CRYPT_REGISTER_ACTIONID));
91 ret = pWintrustAddActionID(&ActionID, 0, &ActionIDFunctions);
92 ok (!ret, "Expected WintrustAddActionID to fail.\n");
93 ok (GetLastError() == ERROR_INVALID_PARAMETER /* XP/W2K3 */ ||
94 GetLastError() == 0xdeadbeef /* Win98/NT4/W2K */,
95 "Expected ERROR_INVALID_PARAMETER(W2K3) or 0xdeadbeef(Win98/NT4/W2K), got %ld.\n", GetLastError());
97 /* All OK (although no functions defined) and cbStruct is set now */
98 SetLastError(0xdeadbeef);
99 memset(&ActionIDFunctions, 0, sizeof(CRYPT_REGISTER_ACTIONID));
100 ActionIDFunctions.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
101 ret = pWintrustAddActionID(&ActionID, 0, &ActionIDFunctions);
102 ok (ret, "Expected WintrustAddActionID to succeed.\n");
103 ok (GetLastError() == ERROR_INVALID_PARAMETER,
104 "Expected ERROR_INVALID_PARAMETER, got %ld.\n", GetLastError());
106 /* All OK and all (but 1) functions are correctly defined. The DLL and entrypoints
109 memset(&ActionIDFunctions, 0, sizeof(CRYPT_REGISTER_ACTIONID));
110 ActionIDFunctions.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
111 ActionIDFunctions.sInitProvider = DummyProvider;
112 ActionIDFunctions.sObjectProvider = DummyProvider;
113 ActionIDFunctions.sSignatureProvider = EmptyProvider;
114 ActionIDFunctions.sCertificateProvider = DummyProvider;
115 ActionIDFunctions.sCertificatePolicyProvider = DummyProvider;
116 ActionIDFunctions.sFinalPolicyProvider = DummyProvider;
117 ActionIDFunctions.sTestPolicyProvider = DummyProvider;
118 ActionIDFunctions.sCleanupProvider = DummyProvider;
119 SetLastError(0xdeadbeef);
120 ret = pWintrustAddActionID(&ActionID, 0, &ActionIDFunctions);
121 ok (ret, "Expected WintrustAddActionID to succeed.\n");
122 ok (GetLastError() == ERROR_INVALID_PARAMETER,
123 "Expected ERROR_INVALID_PARAMETER, got %ld.\n", GetLastError());
125 /* All OK and all functions are correctly defined. The DLL and entrypoints
128 memset(&ActionIDFunctions, 0, sizeof(CRYPT_REGISTER_ACTIONID));
129 ActionIDFunctions.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
130 ActionIDFunctions.sInitProvider = DummyProvider;
131 ActionIDFunctions.sObjectProvider = DummyProvider;
132 ActionIDFunctions.sSignatureProvider = DummyProvider;
133 ActionIDFunctions.sCertificateProvider = DummyProvider;
134 ActionIDFunctions.sCertificatePolicyProvider = DummyProvider;
135 ActionIDFunctions.sFinalPolicyProvider = DummyProvider;
136 ActionIDFunctions.sTestPolicyProvider = DummyProvider;
137 ActionIDFunctions.sCleanupProvider = DummyProvider;
138 SetLastError(0xdeadbeef);
139 ret = pWintrustAddActionID(&ActionID, 0, &ActionIDFunctions);
140 ok (ret, "Expected WintrustAddActionID to succeed.\n");
141 ok (GetLastError() == 0xdeadbeef,
142 "Expected 0xdeadbeef, got %ld.\n", GetLastError());
144 SetLastError(0xdeadbeef);
145 ret = pWintrustRemoveActionID(&ActionID);
146 ok ( ret, "WintrustRemoveActionID failed : 0x%08lx\n", GetLastError());
147 ok ( GetLastError() == 0xdeadbeef, "Last error should not have been changed: 0x%08lx\n", GetLastError());
150 SetLastError(0xdeadbeef);
151 ret = pWintrustRemoveActionID(NULL);
152 ok (ret, "Expected WintrustRemoveActionID to succeed.\n");
153 ok (GetLastError() == ERROR_INVALID_PARAMETER,
154 "Expected ERROR_INVALID_PARAMETER, got %ld.\n", GetLastError());
156 /* The passed GUID is removed by a previous call, so it's basically a test with a nonexistent Trust provider */
157 SetLastError(0xdeadbeef);
158 ret = pWintrustRemoveActionID(&ActionID);
159 ok (ret, "Expected WintrustRemoveActionID to succeed.\n");
160 ok (GetLastError() == 0xdeadbeef,
161 "Expected 0xdeadbeef, got %ld.\n", GetLastError());
164 static void test_AddDefaultForUsage(void)
168 static GUID ActionID = { 0xdeadbeef, 0xdead, 0xbeef, { 0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef }};
169 static WCHAR DummyDllW[] = {'d','e','a','d','b','e','e','f','.','d','l','l',0 };
170 static CHAR DummyFunction[] = "dummyfunction";
171 static const CHAR oid[] = "1.2.3.4.5.6.7.8.9.10";
172 static const CHAR Usages[] = "SOFTWARE\\Microsoft\\Cryptography\\Providers\\Trust\\Usages\\1.2.3.4.5.6.7.8.9.10";
173 static CRYPT_PROVIDER_REGDEFUSAGE DefUsage;
176 SetLastError(0xdeadbeef);
177 ret = pWintrustAddDefaultForUsage(NULL, NULL);
178 ok (!ret, "Expected WintrustAddDefaultForUsage to fail.\n");
179 ok (GetLastError() == ERROR_INVALID_PARAMETER,
180 "Expected ERROR_INVALID_PARAMETER, got %ld.\n", GetLastError());
183 SetLastError(0xdeadbeef);
184 ret = pWintrustAddDefaultForUsage(oid, NULL);
185 ok (!ret, "Expected WintrustAddDefaultForUsage to fail.\n");
186 ok (GetLastError() == ERROR_INVALID_PARAMETER,
187 "Expected ERROR_INVALID_PARAMETER, got %ld.\n", GetLastError());
189 /* NULL oid and proper defusage */
190 memset(&DefUsage, 0 , sizeof(CRYPT_PROVIDER_REGDEFUSAGE));
191 DefUsage.cbStruct = sizeof(CRYPT_PROVIDER_REGDEFUSAGE);
192 DefUsage.pgActionID = &ActionID;
193 DefUsage.pwszDllName = DummyDllW;
194 DefUsage.pwszLoadCallbackDataFunctionName = DummyFunction;
195 DefUsage.pwszFreeCallbackDataFunctionName = DummyFunction;
196 SetLastError(0xdeadbeef);
197 ret = pWintrustAddDefaultForUsage(NULL, &DefUsage);
198 ok (!ret, "Expected WintrustAddDefaultForUsage to fail.\n");
199 ok (GetLastError() == ERROR_INVALID_PARAMETER,
200 "Expected ERROR_INVALID_PARAMETER, got %ld.\n", GetLastError());
202 /* Just the ActionID */
203 memset(&DefUsage, 0 , sizeof(CRYPT_PROVIDER_REGDEFUSAGE));
204 DefUsage.cbStruct = sizeof(CRYPT_PROVIDER_REGDEFUSAGE);
205 DefUsage.pgActionID = &ActionID;
206 SetLastError(0xdeadbeef);
207 ret = pWintrustAddDefaultForUsage(oid, &DefUsage);
208 ok ( ret, "Expected WintrustAddDefaultForUsage to succeed\n");
209 ok (GetLastError() == 0xdeadbeef,
210 "Last error should not have been changed: 0x%08lx\n", GetLastError());
213 memset(&DefUsage, 0 , sizeof(CRYPT_PROVIDER_REGDEFUSAGE));
214 DefUsage.cbStruct = sizeof(CRYPT_PROVIDER_REGDEFUSAGE);
215 DefUsage.pwszDllName = DummyDllW;
216 DefUsage.pwszLoadCallbackDataFunctionName = DummyFunction;
217 DefUsage.pwszFreeCallbackDataFunctionName = DummyFunction;
218 ret = pWintrustAddDefaultForUsage(oid, &DefUsage);
219 ok (!ret, "Expected WintrustAddDefaultForUsage to fail.\n");
220 ok (GetLastError() == ERROR_INVALID_PARAMETER,
221 "Expected ERROR_INVALID_PARAMETER, got %ld.\n", GetLastError());
223 /* cbStruct set to 0 */
224 memset(&DefUsage, 0 , sizeof(CRYPT_PROVIDER_REGDEFUSAGE));
225 DefUsage.cbStruct = 0;
226 DefUsage.pgActionID = &ActionID;
227 DefUsage.pwszDllName = DummyDllW;
228 DefUsage.pwszLoadCallbackDataFunctionName = DummyFunction;
229 DefUsage.pwszFreeCallbackDataFunctionName = DummyFunction;
230 SetLastError(0xdeadbeef);
231 ret = pWintrustAddDefaultForUsage(oid, &DefUsage);
232 ok (!ret, "Expected WintrustAddDefaultForUsage to fail.\n");
233 ok (GetLastError() == ERROR_INVALID_PARAMETER,
234 "Expected ERROR_INVALID_PARAMETER, got %ld.\n", GetLastError());
237 memset(&DefUsage, 0 , sizeof(CRYPT_PROVIDER_REGDEFUSAGE));
238 DefUsage.cbStruct = sizeof(CRYPT_PROVIDER_REGDEFUSAGE);
239 DefUsage.pgActionID = &ActionID;
240 DefUsage.pwszDllName = DummyDllW;
241 DefUsage.pwszLoadCallbackDataFunctionName = DummyFunction;
242 DefUsage.pwszFreeCallbackDataFunctionName = DummyFunction;
243 SetLastError(0xdeadbeef);
244 ret = pWintrustAddDefaultForUsage(oid, &DefUsage);
245 ok ( ret, "Expected WintrustAddDefaultForUsage to succeed\n");
246 ok (GetLastError() == 0xdeadbeef,
247 "Last error should not have been changed: 0x%08lx\n", GetLastError());
249 /* There is no corresponding remove for WintrustAddDefaultForUsage
250 * so we delete the registry key manually.
254 res = RegDeleteKeyA(HKEY_LOCAL_MACHINE, Usages);
255 ok (res == ERROR_SUCCESS, "Key delete failed : 0x%08lx\n", res);
261 if(!InitFunctionPtrs())
264 test_AddRem_ActionID();
265 test_AddDefaultForUsage();
267 FreeLibrary(hWintrust);