[21311] | 1 | /*
|
---|
| 2 | * Subject Interface Package tests
|
---|
| 3 | *
|
---|
| 4 | * Copyright 2006 Paul Vriens
|
---|
| 5 | * Copyright 2008 Juan Lang
|
---|
| 6 | *
|
---|
| 7 | * This library is free software; you can redistribute it and/or
|
---|
| 8 | * modify it under the terms of the GNU Lesser General Public
|
---|
| 9 | * License as published by the Free Software Foundation; either
|
---|
| 10 | * version 2.1 of the License, or (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * This library is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 15 | * Lesser General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU Lesser General Public
|
---|
| 18 | * License along with this library; if not, write to the Free Software
|
---|
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
---|
| 20 | */
|
---|
| 21 |
|
---|
| 22 | #include <stdio.h>
|
---|
| 23 | #include <stdarg.h>
|
---|
| 24 | #include <windef.h>
|
---|
| 25 | #include <winbase.h>
|
---|
| 26 | #include <winerror.h>
|
---|
| 27 | #include <winnls.h>
|
---|
| 28 | #include <wincrypt.h>
|
---|
| 29 | #include <mssip.h>
|
---|
| 30 |
|
---|
| 31 | #include "wine/test.h"
|
---|
| 32 |
|
---|
| 33 | static BOOL (WINAPI * funcCryptSIPGetSignedDataMsg)(SIP_SUBJECTINFO *,DWORD *,DWORD,DWORD *,BYTE *);
|
---|
| 34 | static BOOL (WINAPI * funcCryptSIPPutSignedDataMsg)(SIP_SUBJECTINFO *,DWORD,DWORD *,DWORD,BYTE *);
|
---|
| 35 | static BOOL (WINAPI * funcCryptSIPCreateIndirectData)(SIP_SUBJECTINFO *,DWORD *,SIP_INDIRECT_DATA *);
|
---|
| 36 | static BOOL (WINAPI * funcCryptSIPVerifyIndirectData)(SIP_SUBJECTINFO *,SIP_INDIRECT_DATA *);
|
---|
| 37 | static BOOL (WINAPI * funcCryptSIPRemoveSignedDataMsg)(SIP_SUBJECTINFO *,DWORD);
|
---|
| 38 |
|
---|
| 39 | static char *show_guid(const GUID *guid, char *buf)
|
---|
| 40 | {
|
---|
| 41 | sprintf(buf,
|
---|
| 42 | "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
|
---|
| 43 | guid->Data1, guid->Data2, guid->Data3,
|
---|
| 44 | guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
|
---|
| 45 | guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7] );
|
---|
| 46 |
|
---|
| 47 | return buf;
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | static void test_AddRemoveProvider(void)
|
---|
| 51 | {
|
---|
| 52 | BOOL ret;
|
---|
| 53 | SIP_ADD_NEWPROVIDER newprov;
|
---|
| 54 | GUID actionid = { 0xdeadbe, 0xefde, 0xadbe, { 0xef,0xde,0xad,0xbe,0xef,0xde,0xad,0xbe }};
|
---|
| 55 | static WCHAR dummydll[] = {'d','e','a','d','b','e','e','f','.','d','l','l',0 };
|
---|
| 56 | static WCHAR dummyfunction[] = {'d','u','m','m','y','f','u','n','c','t','i','o','n',0 };
|
---|
| 57 |
|
---|
| 58 | /* NULL check */
|
---|
| 59 | SetLastError(0xdeadbeef);
|
---|
| 60 | ret = CryptSIPRemoveProvider(NULL);
|
---|
| 61 | ok (!ret, "Expected CryptSIPRemoveProvider to fail.\n");
|
---|
| 62 | ok (GetLastError() == ERROR_INVALID_PARAMETER,
|
---|
| 63 | "Expected ERROR_INVALID_PARAMETER, got %d.\n", GetLastError());
|
---|
| 64 |
|
---|
| 65 | /* nonexistent provider should result in a registry error */
|
---|
| 66 | SetLastError(0xdeadbeef);
|
---|
| 67 | ret = CryptSIPRemoveProvider(&actionid);
|
---|
| 68 | if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
|
---|
| 69 | {
|
---|
| 70 | /* Apparently the needed rights are checked before the existence of the provider */
|
---|
| 71 | skip("Need admin rights\n");
|
---|
| 72 | }
|
---|
| 73 | else
|
---|
| 74 | {
|
---|
| 75 | ok (!ret, "Expected CryptSIPRemoveProvider to fail.\n");
|
---|
| 76 | ok (GetLastError() == ERROR_FILE_NOT_FOUND,
|
---|
| 77 | "Expected ERROR_FILE_NOT_FOUND, got %d.\n", GetLastError());
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | /* Everything OK, pwszIsFunctionName and pwszIsFunctionNameFmt2 are left NULL
|
---|
| 81 | * as allowed */
|
---|
| 82 |
|
---|
| 83 | memset(&newprov, 0, sizeof(SIP_ADD_NEWPROVIDER));
|
---|
| 84 | newprov.cbStruct = sizeof(SIP_ADD_NEWPROVIDER);
|
---|
| 85 | newprov.pgSubject = &actionid;
|
---|
| 86 | newprov.pwszDLLFileName = dummydll;
|
---|
| 87 | newprov.pwszGetFuncName = dummyfunction;
|
---|
| 88 | newprov.pwszPutFuncName = dummyfunction;
|
---|
| 89 | newprov.pwszCreateFuncName = dummyfunction;
|
---|
| 90 | newprov.pwszVerifyFuncName = dummyfunction;
|
---|
| 91 | newprov.pwszRemoveFuncName = dummyfunction;
|
---|
| 92 | SetLastError(0xdeadbeef);
|
---|
| 93 | ret = CryptSIPAddProvider(&newprov);
|
---|
| 94 | if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
|
---|
| 95 | {
|
---|
| 96 | skip("Need admin rights\n");
|
---|
| 97 | return;
|
---|
| 98 | }
|
---|
| 99 | ok ( ret, "CryptSIPAddProvider should have succeeded\n");
|
---|
| 100 |
|
---|
| 101 | /* Dummy provider will be deleted, but the function still fails because
|
---|
| 102 | * pwszIsFunctionName and pwszIsFunctionNameFmt2 are not present in the
|
---|
| 103 | * registry.
|
---|
| 104 | */
|
---|
| 105 | SetLastError(0xdeadbeef);
|
---|
| 106 | ret = CryptSIPRemoveProvider(&actionid);
|
---|
| 107 | ok (!ret, "Expected CryptSIPRemoveProvider to fail.\n");
|
---|
| 108 | ok (GetLastError() == ERROR_FILE_NOT_FOUND,
|
---|
| 109 | "Expected ERROR_FILE_NOT_FOUND, got %d.\n", GetLastError());
|
---|
| 110 |
|
---|
| 111 | /* Everything OK */
|
---|
| 112 | memset(&newprov, 0, sizeof(SIP_ADD_NEWPROVIDER));
|
---|
| 113 | newprov.cbStruct = sizeof(SIP_ADD_NEWPROVIDER);
|
---|
| 114 | newprov.pgSubject = &actionid;
|
---|
| 115 | newprov.pwszDLLFileName = dummydll;
|
---|
| 116 | newprov.pwszGetFuncName = dummyfunction;
|
---|
| 117 | newprov.pwszPutFuncName = dummyfunction;
|
---|
| 118 | newprov.pwszCreateFuncName = dummyfunction;
|
---|
| 119 | newprov.pwszVerifyFuncName = dummyfunction;
|
---|
| 120 | newprov.pwszRemoveFuncName = dummyfunction;
|
---|
| 121 | newprov.pwszIsFunctionNameFmt2 = dummyfunction;
|
---|
| 122 | newprov.pwszIsFunctionName = dummyfunction;
|
---|
| 123 | SetLastError(0xdeadbeef);
|
---|
| 124 | ret = CryptSIPAddProvider(&newprov);
|
---|
| 125 | ok ( ret, "CryptSIPAddProvider should have succeeded\n");
|
---|
| 126 |
|
---|
| 127 | /* Dummy provider should be deleted */
|
---|
| 128 | SetLastError(0xdeadbeef);
|
---|
| 129 | ret = CryptSIPRemoveProvider(&actionid);
|
---|
| 130 | ok ( ret, "CryptSIPRemoveProvider should have succeeded\n");
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | static const BYTE cabFileData[] = {
|
---|
| 134 | 0x4d,0x53,0x43,0x46,0x00,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
---|
| 135 | 0x2c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x01,0x01,0x00,0x01,0x00,0x00,0x00,
|
---|
| 136 | 0xef,0xbe,0xff,0xff,0x42,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x06,0x00,0x00,0x00,
|
---|
| 137 | 0x00,0x00,0x00,0x00,0x00,0x00,0xf7,0x38,0x4b,0xac,0x00,0x00,0x61,0x2e,0x74,0x78,
|
---|
| 138 | 0x74,0x00,0x6d,0x5a,0x72,0x78,0x06,0x00,0x06,0x00,0x61,0x2e,0x74,0x78,0x74,0x0a,
|
---|
| 139 | };
|
---|
| 140 |
|
---|
| 141 | static void test_SIPRetrieveSubjectGUID(void)
|
---|
| 142 | {
|
---|
| 143 | BOOL ret;
|
---|
| 144 | GUID subject;
|
---|
| 145 | HANDLE file;
|
---|
| 146 | static const CHAR windir[] = "windir";
|
---|
| 147 | static const CHAR regeditExe[] = "regedit.exe";
|
---|
| 148 | static const GUID nullSubject = { 0x0, 0x0, 0x0, { 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0 }};
|
---|
| 149 | static const WCHAR deadbeef[] = { 'c',':','\\','d','e','a','d','b','e','e','f','.','d','b','f',0 };
|
---|
| 150 | /* Couldn't find a name for this GUID, it's the one used for 95% of the files */
|
---|
| 151 | static const GUID unknownGUID = { 0xC689AAB8, 0x8E78, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
|
---|
| 152 | static const GUID cabGUID = { 0xc689aaba, 0x8e78, 0x11d0, {0x8c,0x47,0x00,0xc0,0x4f,0xc2,0x95,0xee }};
|
---|
| 153 | static CHAR regeditPath[MAX_PATH];
|
---|
| 154 | static WCHAR regeditPathW[MAX_PATH];
|
---|
| 155 | static CHAR path[MAX_PATH];
|
---|
| 156 | static CHAR tempfile[MAX_PATH];
|
---|
| 157 | static WCHAR tempfileW[MAX_PATH];
|
---|
| 158 | static char guid1[39], guid2[39];
|
---|
| 159 | DWORD written;
|
---|
| 160 |
|
---|
| 161 | /* NULL check */
|
---|
| 162 | SetLastError(0xdeadbeef);
|
---|
| 163 | ret = CryptSIPRetrieveSubjectGuid(NULL, NULL, NULL);
|
---|
| 164 | ok ( !ret, "Expected CryptSIPRetrieveSubjectGuid to fail\n");
|
---|
| 165 | ok (GetLastError() == ERROR_INVALID_PARAMETER,
|
---|
| 166 | "Expected ERROR_INVALID_PARAMETER, got %d.\n", GetLastError());
|
---|
| 167 |
|
---|
| 168 | /* Test with a nonexistent file (hopefully) */
|
---|
| 169 | SetLastError(0xdeadbeef);
|
---|
| 170 | /* Set subject to something other than zeros */
|
---|
| 171 | memset(&subject, 1, sizeof(GUID));
|
---|
| 172 | ret = CryptSIPRetrieveSubjectGuid(deadbeef, NULL, &subject);
|
---|
| 173 | ok ( !ret, "Expected CryptSIPRetrieveSubjectGuid to fail\n");
|
---|
| 174 | ok (GetLastError() == ERROR_FILE_NOT_FOUND,
|
---|
| 175 | "Expected ERROR_FILE_NOT_FOUND, got %d.\n", GetLastError());
|
---|
| 176 | ok ( !memcmp(&subject, &nullSubject, sizeof(GUID)),
|
---|
| 177 | "Expected a NULL GUID for c:\\deadbeef.dbf, not %s\n", show_guid(&subject, guid1));
|
---|
| 178 |
|
---|
| 179 | /* Now with an executable that should exist
|
---|
| 180 | *
|
---|
| 181 | * Use A-functions where possible as that should be available on all platforms
|
---|
| 182 | */
|
---|
| 183 | ret = GetEnvironmentVariableA(windir, regeditPath, MAX_PATH);
|
---|
| 184 | ok (ret > 0, "expected GEVA(windir) to succeed, last error %d\n", GetLastError());
|
---|
| 185 | strcat(regeditPath, "\\");
|
---|
| 186 | strcat(regeditPath, regeditExe);
|
---|
| 187 | MultiByteToWideChar( CP_ACP, 0, regeditPath,
|
---|
| 188 | strlen(regeditPath)+1, regeditPathW,
|
---|
| 189 | sizeof(regeditPathW)/sizeof(regeditPathW[0]) );
|
---|
| 190 |
|
---|
| 191 | SetLastError(0xdeadbeef);
|
---|
| 192 | memset(&subject, 1, sizeof(GUID));
|
---|
| 193 | ret = CryptSIPRetrieveSubjectGuid(regeditPathW, NULL, &subject);
|
---|
| 194 | ok ( ret, "Expected CryptSIPRetrieveSubjectGuid to succeed\n");
|
---|
| 195 | ok ( !memcmp(&subject, &unknownGUID, sizeof(GUID)),
|
---|
| 196 | "Expected (%s), got (%s).\n", show_guid(&unknownGUID, guid1), show_guid(&subject, guid2));
|
---|
| 197 |
|
---|
| 198 | /* The same thing but now with a handle instead of a filename */
|
---|
| 199 | file = CreateFileA(regeditPath, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
|
---|
| 200 | SetLastError(0xdeadbeef);
|
---|
| 201 | memset(&subject, 1, sizeof(GUID));
|
---|
| 202 | ret = CryptSIPRetrieveSubjectGuid(NULL, file, &subject);
|
---|
| 203 | ok ( ret, "Expected CryptSIPRetrieveSubjectGuid to succeed\n");
|
---|
| 204 | ok ( !memcmp(&subject, &unknownGUID, sizeof(GUID)),
|
---|
| 205 | "Expected (%s), got (%s).\n", show_guid(&unknownGUID, guid1), show_guid(&subject, guid2));
|
---|
| 206 | CloseHandle(file);
|
---|
| 207 |
|
---|
| 208 | /* And both */
|
---|
| 209 | file = CreateFileA(regeditPath, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
|
---|
| 210 | SetLastError(0xdeadbeef);
|
---|
| 211 | memset(&subject, 1, sizeof(GUID));
|
---|
| 212 | ret = CryptSIPRetrieveSubjectGuid(regeditPathW, file, &subject);
|
---|
| 213 | ok ( ret, "Expected CryptSIPRetrieveSubjectGuid to succeed\n");
|
---|
| 214 | ok ( !memcmp(&subject, &unknownGUID, sizeof(GUID)),
|
---|
| 215 | "Expected (%s), got (%s).\n", show_guid(&unknownGUID, guid1), show_guid(&subject, guid2));
|
---|
| 216 | CloseHandle(file);
|
---|
| 217 |
|
---|
| 218 | /* Now with an empty file */
|
---|
| 219 | GetTempPathA(sizeof(path), path);
|
---|
| 220 | GetTempFileNameA(path, "sip", 0 , tempfile);
|
---|
| 221 | MultiByteToWideChar( CP_ACP, 0, tempfile,
|
---|
| 222 | strlen(tempfile)+1, tempfileW,
|
---|
| 223 | sizeof(tempfileW)/sizeof(tempfileW[0]) );
|
---|
| 224 |
|
---|
| 225 | SetLastError(0xdeadbeef);
|
---|
| 226 | memset(&subject, 1, sizeof(GUID));
|
---|
| 227 | ret = CryptSIPRetrieveSubjectGuid(tempfileW, NULL, &subject);
|
---|
| 228 | ok ( !ret, "Expected CryptSIPRetrieveSubjectGuid to fail\n");
|
---|
| 229 | ok ( GetLastError() == ERROR_FILE_INVALID ||
|
---|
| 230 | GetLastError() == ERROR_INVALID_PARAMETER /* Vista */ ||
|
---|
| 231 | GetLastError() == ERROR_SUCCESS /* Win98 */,
|
---|
| 232 | "Expected ERROR_FILE_INVALID, ERROR_INVALID_PARAMETER or ERROR_SUCCESS, got 0x%08x\n", GetLastError());
|
---|
| 233 | ok ( !memcmp(&subject, &nullSubject, sizeof(GUID)),
|
---|
| 234 | "Expected a NULL GUID for empty file %s, not %s\n", tempfile, show_guid(&subject, guid1));
|
---|
| 235 |
|
---|
| 236 | /* Use a file with a size of 3 (at least < 4) */
|
---|
| 237 | file = CreateFileA(tempfile, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
|
---|
| 238 | WriteFile(file, "123", 3, &written, NULL);
|
---|
| 239 | CloseHandle(file);
|
---|
| 240 |
|
---|
| 241 | SetLastError(0xdeadbeef);
|
---|
| 242 | memset(&subject, 1, sizeof(GUID));
|
---|
| 243 | ret = CryptSIPRetrieveSubjectGuid(tempfileW, NULL, &subject);
|
---|
| 244 | ok ( !ret, "Expected CryptSIPRetrieveSubjectGuid to fail\n");
|
---|
| 245 | ok ( GetLastError() == ERROR_INVALID_PARAMETER ||
|
---|
| 246 | GetLastError() == ERROR_SUCCESS /* Win98 */,
|
---|
| 247 | "Expected ERROR_INVALID_PARAMETER or ERROR_SUCCESS, got 0x%08x\n", GetLastError());
|
---|
| 248 | ok ( !memcmp(&subject, &nullSubject, sizeof(GUID)),
|
---|
| 249 | "Expected a NULL GUID for empty file %s, not %s\n", tempfile, show_guid(&subject, guid1));
|
---|
| 250 |
|
---|
| 251 | /* And now >= 4 */
|
---|
| 252 | file = CreateFileA(tempfile, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
|
---|
| 253 | WriteFile(file, "1234", 4, &written, NULL);
|
---|
| 254 | CloseHandle(file);
|
---|
| 255 |
|
---|
| 256 | SetLastError(0xdeadbeef);
|
---|
| 257 | memset(&subject, 1, sizeof(GUID));
|
---|
| 258 | ret = CryptSIPRetrieveSubjectGuid(tempfileW, NULL, &subject);
|
---|
| 259 | ok ( !ret, "Expected CryptSIPRetrieveSubjectGuid to fail\n");
|
---|
| 260 | ok ( GetLastError() == TRUST_E_SUBJECT_FORM_UNKNOWN ||
|
---|
| 261 | GetLastError() == ERROR_SUCCESS /* Win98 */,
|
---|
| 262 | "Expected TRUST_E_SUBJECT_FORM_UNKNOWN or ERROR_SUCCESS, got 0x%08x\n", GetLastError());
|
---|
| 263 | ok ( !memcmp(&subject, &nullSubject, sizeof(GUID)),
|
---|
| 264 | "Expected a NULL GUID for empty file %s, not %s\n", tempfile, show_guid(&subject, guid1));
|
---|
| 265 |
|
---|
| 266 | /* Clean up */
|
---|
| 267 | DeleteFileA(tempfile);
|
---|
| 268 |
|
---|
| 269 | /* Create a file with just the .cab header 'MSCF' */
|
---|
| 270 | SetLastError(0xdeadbeef);
|
---|
| 271 | file = CreateFileA(tempfile, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
|
---|
| 272 | ok(file != INVALID_HANDLE_VALUE, "failed with %u\n", GetLastError());
|
---|
| 273 | WriteFile(file, cabFileData, 4, &written, NULL);
|
---|
| 274 | CloseHandle(file);
|
---|
| 275 |
|
---|
| 276 | SetLastError(0xdeadbeef);
|
---|
| 277 | memset(&subject, 1, sizeof(GUID));
|
---|
| 278 | ret = CryptSIPRetrieveSubjectGuid(tempfileW, NULL, &subject);
|
---|
| 279 | ok( ret, "CryptSIPRetrieveSubjectGuid failed: %d (0x%08x)\n",
|
---|
| 280 | GetLastError(), GetLastError() );
|
---|
| 281 | ok ( !memcmp(&subject, &cabGUID, sizeof(GUID)),
|
---|
| 282 | "Expected GUID %s for cabinet file, not %s\n", show_guid(&cabGUID, guid1), show_guid(&subject, guid2));
|
---|
| 283 |
|
---|
| 284 | /* Clean up */
|
---|
| 285 | DeleteFileA(tempfile);
|
---|
| 286 |
|
---|
| 287 | /* Create a .cab file */
|
---|
| 288 | SetLastError(0xdeadbeef);
|
---|
| 289 | file = CreateFileA(tempfile, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
|
---|
| 290 | ok(file != INVALID_HANDLE_VALUE, "failed with %u\n", GetLastError());
|
---|
| 291 | WriteFile(file, cabFileData, sizeof(cabFileData), &written, NULL);
|
---|
| 292 | CloseHandle(file);
|
---|
| 293 |
|
---|
| 294 | SetLastError(0xdeadbeef);
|
---|
| 295 | memset(&subject, 1, sizeof(GUID));
|
---|
| 296 | ret = CryptSIPRetrieveSubjectGuid(tempfileW, NULL, &subject);
|
---|
| 297 | ok( ret, "CryptSIPRetrieveSubjectGuid failed: %d (0x%08x)\n",
|
---|
| 298 | GetLastError(), GetLastError() );
|
---|
| 299 | ok ( !memcmp(&subject, &cabGUID, sizeof(GUID)),
|
---|
| 300 | "Expected GUID %s for cabinet file, not %s\n", show_guid(&cabGUID, guid1), show_guid(&subject, guid2));
|
---|
| 301 |
|
---|
| 302 | /* Clean up */
|
---|
| 303 | DeleteFileA(tempfile);
|
---|
| 304 | }
|
---|
| 305 |
|
---|
| 306 | static void test_SIPLoad(void)
|
---|
| 307 | {
|
---|
| 308 | BOOL ret;
|
---|
| 309 | GUID subject;
|
---|
| 310 | static GUID dummySubject = { 0xdeadbeef, 0xdead, 0xbeef, { 0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef }};
|
---|
| 311 | static GUID unknown = { 0xC689AABA, 0x8E78, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }}; /* WINTRUST.DLL */
|
---|
| 312 | static GUID unknown2 = { 0xDE351A43, 0x8E59, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }}; /* WINTRUST.DLL */
|
---|
| 313 | /* The next SIP is available on Windows and on Wine */
|
---|
| 314 | static GUID unknown3 = { 0x000C10F1, 0x0000, 0x0000, { 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46 }}; /* MSISIP.DLL */
|
---|
| 315 | SIP_DISPATCH_INFO sdi;
|
---|
| 316 | HMODULE hCrypt;
|
---|
| 317 |
|
---|
| 318 | /* All NULL */
|
---|
| 319 | SetLastError(0xdeadbeef);
|
---|
| 320 | ret = CryptSIPLoad(NULL, 0, NULL);
|
---|
| 321 | ok ( !ret, "Expected CryptSIPLoad to fail\n");
|
---|
| 322 | ok ( GetLastError() == ERROR_INVALID_PARAMETER,
|
---|
| 323 | "Expected ERROR_INVALID_PARAMETER, got 0x%08x\n", GetLastError());
|
---|
| 324 |
|
---|
| 325 | /* Only pSipDispatch NULL */
|
---|
| 326 | SetLastError(0xdeadbeef);
|
---|
| 327 | ret = CryptSIPLoad(&subject, 0, NULL);
|
---|
| 328 | ok ( !ret, "Expected CryptSIPLoad to fail\n");
|
---|
| 329 | ok ( GetLastError() == ERROR_INVALID_PARAMETER,
|
---|
| 330 | "Expected ERROR_INVALID_PARAMETER, got 0x%08x\n", GetLastError());
|
---|
| 331 |
|
---|
| 332 | /* No NULLs, but nonexistent pgSubject */
|
---|
| 333 | SetLastError(0xdeadbeef);
|
---|
| 334 | memset(&sdi, 0, sizeof(SIP_DISPATCH_INFO));
|
---|
| 335 | sdi.cbSize = sizeof(SIP_DISPATCH_INFO);
|
---|
| 336 | sdi.pfGet = (pCryptSIPGetSignedDataMsg)0xdeadbeef;
|
---|
| 337 | ret = CryptSIPLoad(&dummySubject, 0, &sdi);
|
---|
| 338 | ok ( !ret, "Expected CryptSIPLoad to fail\n");
|
---|
| 339 | ok ( GetLastError() == TRUST_E_SUBJECT_FORM_UNKNOWN,
|
---|
| 340 | "Expected TRUST_E_SUBJECT_FORM_UNKNOWN, got 0x%08x\n", GetLastError());
|
---|
| 341 | ok( sdi.pfGet == (pCryptSIPGetSignedDataMsg)0xdeadbeef, "Expected no change to the function pointer\n");
|
---|
| 342 |
|
---|
| 343 | hCrypt = GetModuleHandleA("crypt32.dll");
|
---|
| 344 | funcCryptSIPGetSignedDataMsg = (void*)GetProcAddress(hCrypt, "CryptSIPGetSignedDataMsg");
|
---|
| 345 | funcCryptSIPPutSignedDataMsg = (void*)GetProcAddress(hCrypt, "CryptSIPPutSignedDataMsg");
|
---|
| 346 | funcCryptSIPCreateIndirectData = (void*)GetProcAddress(hCrypt, "CryptSIPCreateIndirectData");
|
---|
| 347 | funcCryptSIPVerifyIndirectData = (void*)GetProcAddress(hCrypt, "CryptSIPVerifyIndirectData");
|
---|
| 348 | funcCryptSIPRemoveSignedDataMsg = (void*)GetProcAddress(hCrypt, "CryptSIPRemoveSignedDataMsg");
|
---|
| 349 |
|
---|
| 350 | /* All OK */
|
---|
| 351 | SetLastError(0xdeadbeef);
|
---|
| 352 | memset(&sdi, 0, sizeof(SIP_DISPATCH_INFO));
|
---|
| 353 | sdi.cbSize = sizeof(SIP_DISPATCH_INFO);
|
---|
| 354 | sdi.pfGet = (pCryptSIPGetSignedDataMsg)0xdeadbeef;
|
---|
| 355 | ret = CryptSIPLoad(&unknown, 0, &sdi);
|
---|
| 356 | ok ( ret, "Expected CryptSIPLoad to succeed\n");
|
---|
| 357 | /* On native the last error will always be ERROR_PROC_NOT_FOUND as native searches for the function DllCanUnloadNow
|
---|
| 358 | * in WINTRUST.DLL (in this case). This function is not available in WINTRUST.DLL.
|
---|
| 359 | * For now there's no need to implement this is Wine as I doubt any program will rely on
|
---|
| 360 | * this last error when the call succeeded.
|
---|
| 361 | */
|
---|
| 362 | ok( sdi.pfGet != (pCryptSIPGetSignedDataMsg)0xdeadbeef, "Expected a function pointer to be loaded.\n");
|
---|
| 363 |
|
---|
| 364 | /* The function addresses returned by CryptSIPLoad are actually the addresses of
|
---|
| 365 | * crypt32's own functions. A function calling these addresses will end up first
|
---|
| 366 | * calling crypt32 functions which in its turn call the equivalent in the SIP
|
---|
| 367 | * as dictated by the given GUID.
|
---|
| 368 | */
|
---|
| 369 | if (funcCryptSIPGetSignedDataMsg && funcCryptSIPPutSignedDataMsg && funcCryptSIPCreateIndirectData &&
|
---|
| 370 | funcCryptSIPVerifyIndirectData && funcCryptSIPRemoveSignedDataMsg)
|
---|
| 371 | ok (sdi.pfGet == funcCryptSIPGetSignedDataMsg &&
|
---|
| 372 | sdi.pfPut == funcCryptSIPPutSignedDataMsg &&
|
---|
| 373 | sdi.pfCreate == funcCryptSIPCreateIndirectData &&
|
---|
| 374 | sdi.pfVerify == funcCryptSIPVerifyIndirectData &&
|
---|
| 375 | sdi.pfRemove == funcCryptSIPRemoveSignedDataMsg,
|
---|
| 376 | "Expected function addresses to be from crypt32\n");
|
---|
| 377 | else
|
---|
| 378 | trace("Couldn't load function pointers\n");
|
---|
| 379 |
|
---|
| 380 | /* All OK, but different GUID (same SIP though) */
|
---|
| 381 | SetLastError(0xdeadbeef);
|
---|
| 382 | memset(&sdi, 0, sizeof(SIP_DISPATCH_INFO));
|
---|
| 383 | sdi.cbSize = sizeof(SIP_DISPATCH_INFO);
|
---|
| 384 | sdi.pfGet = (pCryptSIPGetSignedDataMsg)0xdeadbeef;
|
---|
| 385 | ret = CryptSIPLoad(&unknown2, 0, &sdi);
|
---|
| 386 | ok ( ret, "Expected CryptSIPLoad to succeed\n");
|
---|
| 387 | /* This call on its own would have resulted in an ERROR_PROC_NOT_FOUND, but the previous
|
---|
| 388 | * call to CryptSIPLoad already loaded wintrust.dll. As this information is cached,
|
---|
| 389 | * CryptSIPLoad will not try to search for the already mentioned DllCanUnloadNow.
|
---|
| 390 | */
|
---|
| 391 | ok( sdi.pfGet != (pCryptSIPGetSignedDataMsg)0xdeadbeef, "Expected a function pointer to be loaded.\n");
|
---|
| 392 |
|
---|
| 393 | /* All OK, but other SIP */
|
---|
| 394 | SetLastError(0xdeadbeef);
|
---|
| 395 | memset(&sdi, 0, sizeof(SIP_DISPATCH_INFO));
|
---|
| 396 | sdi.cbSize = sizeof(SIP_DISPATCH_INFO);
|
---|
| 397 | sdi.pfGet = (pCryptSIPGetSignedDataMsg)0xdeadbeef;
|
---|
| 398 | ret = CryptSIPLoad(&unknown3, 0, &sdi);
|
---|
| 399 | if (ret)
|
---|
| 400 | {
|
---|
| 401 | /* The SIP is known so we can safely assume that the next tests can be done */
|
---|
| 402 |
|
---|
| 403 | /* As msisip.dll is not checked yet by any of the previous calls, the
|
---|
| 404 | * function DllCanUnloadNow will be checked again in msisip.dll (it's not present)
|
---|
| 405 | */
|
---|
| 406 | ok( sdi.pfGet != (pCryptSIPGetSignedDataMsg)0xdeadbeef, "Expected a function pointer to be loaded.\n");
|
---|
| 407 |
|
---|
| 408 | /* This is another SIP but this test proves the function addresses are the same as
|
---|
| 409 | * in the previous test.
|
---|
| 410 | */
|
---|
| 411 | if (funcCryptSIPGetSignedDataMsg && funcCryptSIPPutSignedDataMsg && funcCryptSIPCreateIndirectData &&
|
---|
| 412 | funcCryptSIPVerifyIndirectData && funcCryptSIPRemoveSignedDataMsg)
|
---|
| 413 | ok (sdi.pfGet == funcCryptSIPGetSignedDataMsg &&
|
---|
| 414 | sdi.pfPut == funcCryptSIPPutSignedDataMsg &&
|
---|
| 415 | sdi.pfCreate == funcCryptSIPCreateIndirectData &&
|
---|
| 416 | sdi.pfVerify == funcCryptSIPVerifyIndirectData &&
|
---|
| 417 | sdi.pfRemove == funcCryptSIPRemoveSignedDataMsg,
|
---|
| 418 | "Expected function addresses to be from crypt32\n");
|
---|
| 419 | else
|
---|
| 420 | trace("Couldn't load function pointers\n");
|
---|
| 421 | }
|
---|
| 422 |
|
---|
| 423 | /* Reserved parameter not 0 */
|
---|
| 424 | SetLastError(0xdeadbeef);
|
---|
| 425 | memset(&sdi, 0, sizeof(SIP_DISPATCH_INFO));
|
---|
| 426 | sdi.cbSize = sizeof(SIP_DISPATCH_INFO);
|
---|
| 427 | sdi.pfGet = (pCryptSIPGetSignedDataMsg)0xdeadbeef;
|
---|
| 428 | ret = CryptSIPLoad(&unknown, 1, &sdi);
|
---|
| 429 | ok ( !ret, "Expected CryptSIPLoad to fail\n");
|
---|
| 430 | ok ( GetLastError() == ERROR_INVALID_PARAMETER,
|
---|
| 431 | "Expected ERROR_INVALID_PARAMETER, got 0x%08x\n", GetLastError());
|
---|
| 432 | ok( sdi.pfGet == (pCryptSIPGetSignedDataMsg)0xdeadbeef, "Expected no change to the function pointer\n");
|
---|
| 433 | }
|
---|
| 434 |
|
---|
| 435 | START_TEST(sip)
|
---|
| 436 | {
|
---|
| 437 | test_AddRemoveProvider();
|
---|
| 438 | /* It seems that the caching for loaded dlls is shared between CryptSIPRetrieveSubjectGUID
|
---|
| 439 | * and CryptSIPLoad. The tests have to be in this order to succeed. This is because in the last
|
---|
| 440 | * test for CryptSIPRetrieveSubjectGUID, several SIPs will be loaded (on Windows).
|
---|
| 441 | */
|
---|
| 442 | test_SIPLoad();
|
---|
| 443 | test_SIPRetrieveSubjectGUID();
|
---|
| 444 | }
|
---|