crypt32: Test decoding a big CRL.
[wine] / dlls / crypt32 / tests / sip.c
1 /*
2  * Subject Interface Package tests
3  *
4  * Copyright 2006 Paul Vriens
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include <stdio.h>
22 #include <stdarg.h>
23 #include <windef.h>
24 #include <winbase.h>
25 #include <winerror.h>
26 #include <wincrypt.h>
27 #include <mssip.h>
28
29 #include "wine/test.h"
30
31 static void test_AddRemoveProvider(void)
32 {
33     BOOL ret;
34     SIP_ADD_NEWPROVIDER newprov;
35     GUID actionid = { 0xdeadbe, 0xefde, 0xadbe, { 0xef,0xde,0xad,0xbe,0xef,0xde,0xad,0xbe }};
36     static WCHAR dummydll[]      = {'d','e','a','d','b','e','e','f','.','d','l','l',0 };
37     static WCHAR dummyfunction[] = {'d','u','m','m','y','f','u','n','c','t','i','o','n',0 };
38
39     /* NULL check */
40     SetLastError(0xdeadbeef);
41     ret = CryptSIPRemoveProvider(NULL);
42     ok (!ret, "Expected CryptSIPRemoveProvider to fail.\n");
43     ok (GetLastError() == ERROR_INVALID_PARAMETER,
44         "Expected ERROR_INVALID_PARAMETER, got %ld.\n", GetLastError());
45
46     /* nonexistent provider should result in a registry error */
47     SetLastError(0xdeadbeef);
48     ret = CryptSIPRemoveProvider(&actionid);
49     ok (!ret, "Expected CryptSIPRemoveProvider to fail.\n");
50     ok (GetLastError() == ERROR_FILE_NOT_FOUND,
51         "Expected ERROR_FILE_NOT_FOUND, got %ld.\n", GetLastError());
52
53     /* Everything OK, pwszIsFunctionName and pwszIsFunctionNameFmt2 are left NULL
54      * as allowed */
55
56     memset(&newprov, 0, sizeof(SIP_ADD_NEWPROVIDER));
57     newprov.cbStruct = sizeof(SIP_ADD_NEWPROVIDER);
58     newprov.pgSubject = &actionid;
59     newprov.pwszDLLFileName = dummydll;
60     newprov.pwszGetFuncName = dummyfunction;
61     newprov.pwszPutFuncName = dummyfunction;
62     newprov.pwszCreateFuncName = dummyfunction;
63     newprov.pwszVerifyFuncName = dummyfunction;
64     newprov.pwszRemoveFuncName = dummyfunction;
65     SetLastError(0xdeadbeef);
66     ret = CryptSIPAddProvider(&newprov);
67     ok ( ret, "CryptSIPAddProvider should have succeeded\n");
68     ok ( GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %ld\n",
69      GetLastError());
70
71     /* Dummy provider will be deleted, but the function still fails because
72      * pwszIsFunctionName and pwszIsFunctionNameFmt2 are not present in the
73      * registry.
74      */
75     SetLastError(0xdeadbeef);
76     ret = CryptSIPRemoveProvider(&actionid);
77     ok (!ret, "Expected CryptSIPRemoveProvider to fail.\n");
78     ok (GetLastError() == ERROR_FILE_NOT_FOUND,
79         "Expected ERROR_FILE_NOT_FOUND, got %ld.\n", GetLastError());
80
81     /* Everything OK */
82     memset(&newprov, 0, sizeof(SIP_ADD_NEWPROVIDER));
83     newprov.cbStruct = sizeof(SIP_ADD_NEWPROVIDER);
84     newprov.pgSubject = &actionid;
85     newprov.pwszDLLFileName = dummydll;
86     newprov.pwszGetFuncName = dummyfunction;
87     newprov.pwszPutFuncName = dummyfunction;
88     newprov.pwszCreateFuncName = dummyfunction;
89     newprov.pwszVerifyFuncName = dummyfunction;
90     newprov.pwszRemoveFuncName = dummyfunction;
91     newprov.pwszIsFunctionNameFmt2 = dummyfunction;
92     newprov.pwszIsFunctionName = dummyfunction;
93     SetLastError(0xdeadbeef);
94     ret = CryptSIPAddProvider(&newprov);
95     ok ( ret, "CryptSIPAddProvider should have succeeded\n");
96     ok ( GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %ld\n",
97      GetLastError());
98
99     /* Dummy provider should be deleted */
100     SetLastError(0xdeadbeef);
101     ret = CryptSIPRemoveProvider(&actionid);
102     ok ( ret, "CryptSIPRemoveProvider should have succeeded\n");
103     ok ( GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %ld\n",
104      GetLastError());
105 }
106
107 static void test_SIPLoad(void)
108 {
109     BOOL ret;
110     GUID subject;
111     static GUID dummySubject = { 0xdeadbeef, 0xdead, 0xbeef, { 0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef }};
112     static GUID unknown      = { 0xC689AABA, 0x8E78, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
113     SIP_DISPATCH_INFO sdi;
114
115     /* All NULL */
116     SetLastError(0xdeadbeef);
117     ret = CryptSIPLoad(NULL, 0, NULL);
118     ok ( !ret, "Expected CryptSIPLoad to fail\n");
119     todo_wine
120         ok ( GetLastError() == ERROR_INVALID_PARAMETER,
121             "Expected ERROR_INVALID_PARAMETER, got 0x%08lx\n", GetLastError());
122
123     /* Only pSipDispatch NULL */
124     SetLastError(0xdeadbeef);
125     ret = CryptSIPLoad(&subject, 0, NULL);
126     ok ( !ret, "Expected CryptSIPLoad to fail\n");
127     todo_wine
128         ok ( GetLastError() == ERROR_INVALID_PARAMETER,
129             "Expected ERROR_INVALID_PARAMETER, got 0x%08lx\n", GetLastError());
130
131     /* No NULLs, but nonexistent pgSubject */
132     SetLastError(0xdeadbeef);
133     memset(&sdi, 0, sizeof(SIP_DISPATCH_INFO));
134     sdi.cbSize = sizeof(SIP_DISPATCH_INFO);
135     ret = CryptSIPLoad(&dummySubject, 0, &sdi);
136     ok ( !ret, "Expected CryptSIPLoad to fail\n");
137     todo_wine
138         ok ( GetLastError() == TRUST_E_SUBJECT_FORM_UNKNOWN,
139             "Expected TRUST_E_SUBJECT_FORM_UNKNOWN, got 0x%08lx\n", GetLastError());
140
141     /* cbSize not initialized */
142     SetLastError(0xdeadbeef);
143     memset(&sdi, 0, sizeof(SIP_DISPATCH_INFO));
144     ret = CryptSIPLoad(&dummySubject, 0, &sdi);
145     ok ( !ret, "Expected CryptSIPLoad to fail\n");
146     todo_wine
147         ok ( GetLastError() == TRUST_E_SUBJECT_FORM_UNKNOWN,
148             "Expected TRUST_E_SUBJECT_FORM_UNKNOWN, got 0x%08lx\n", GetLastError());
149
150     /* cbSize not initialized, but valid subject (named unknown but registered by wintrust) */
151     SetLastError(0xdeadbeef);
152     memset(&sdi, 0, sizeof(SIP_DISPATCH_INFO));
153     ret = CryptSIPLoad(&unknown, 0, &sdi);
154     todo_wine
155     {
156         ok ( ret, "Expected CryptSIPLoad to succeed\n");
157         ok ( GetLastError() == ERROR_PROC_NOT_FOUND,
158             "Expected ERROR_PROC_NOT_FOUND, got 0x%08lx\n", GetLastError());
159     }
160
161     /* All OK */
162     SetLastError(0xdeadbeef);
163     memset(&sdi, 0, sizeof(SIP_DISPATCH_INFO));
164     sdi.cbSize = sizeof(SIP_DISPATCH_INFO);
165     ret = CryptSIPLoad(&unknown, 0, &sdi);
166     todo_wine
167         ok ( ret, "Expected CryptSIPLoad to succeed\n");
168     ok ( GetLastError() == 0xdeadbeef,
169         "Expected 0xdeadbeef, got 0x%08lx\n", GetLastError());
170
171     /* Reserved parameter not 0 */
172     SetLastError(0xdeadbeef);
173     memset(&sdi, 0, sizeof(SIP_DISPATCH_INFO));
174     sdi.cbSize = sizeof(SIP_DISPATCH_INFO);
175     ret = CryptSIPLoad(&unknown, 1, &sdi);
176     ok ( !ret, "Expected CryptSIPLoad to fail\n");
177     todo_wine
178         ok ( GetLastError() == ERROR_INVALID_PARAMETER,
179             "Expected ERROR_INVALID_PARAMETER, got 0x%08lx\n", GetLastError());
180 }
181
182 START_TEST(sip)
183 {
184     test_AddRemoveProvider();
185     test_SIPLoad();
186 }