secur32/tests: Win64 printf format warning fixes.
[wine] / dlls / secur32 / tests / schannel.c
1 /*
2  * Schannel tests
3  *
4  * Copyright 2006 Juan Lang
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 #include <stdio.h>
21 #include <stdarg.h>
22 #include <windef.h>
23 #include <winbase.h>
24 #define SECURITY_WIN32
25 #include <security.h>
26 #include <schannel.h>
27
28 #include "wine/test.h"
29
30 static HMODULE secdll;
31 static SECURITY_STATUS (SEC_ENTRY * pAcquireCredentialsHandleA)(SEC_CHAR*, SEC_CHAR*,
32                             ULONG, PLUID, PVOID, SEC_GET_KEY_FN, PVOID, PCredHandle, PTimeStamp);
33 static SECURITY_STATUS (SEC_ENTRY * pFreeCredentialsHandle)(PCredHandle);
34
35 static const BYTE bigCert[] = { 0x30, 0x7a, 0x02, 0x01, 0x01, 0x30, 0x02, 0x06,
36  0x00, 0x30, 0x15, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13,
37  0x0a, 0x4a, 0x75, 0x61, 0x6e, 0x20, 0x4c, 0x61, 0x6e, 0x67, 0x00, 0x30, 0x22,
38  0x18, 0x0f, 0x31, 0x36, 0x30, 0x31, 0x30, 0x31, 0x30, 0x31, 0x30, 0x30, 0x30,
39  0x30, 0x30, 0x30, 0x5a, 0x18, 0x0f, 0x31, 0x36, 0x30, 0x31, 0x30, 0x31, 0x30,
40  0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x5a, 0x30, 0x15, 0x31, 0x13, 0x30,
41  0x11, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x0a, 0x4a, 0x75, 0x61, 0x6e, 0x20,
42  0x4c, 0x61, 0x6e, 0x67, 0x00, 0x30, 0x07, 0x30, 0x02, 0x06, 0x00, 0x03, 0x01,
43  0x00, 0xa3, 0x16, 0x30, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01,
44  0x01, 0xff, 0x04, 0x08, 0x30, 0x06, 0x01, 0x01, 0xff, 0x02, 0x01, 0x01 };
45 static const WCHAR cspNameW[] = { 'W','i','n','e','C','r','y','p','t','T','e',
46  'm','p',0 };
47 static const BYTE privKey[] = {
48  0x07, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x52, 0x53, 0x41, 0x32, 0x00,
49  0x02, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x79, 0x10, 0x1c, 0xd0, 0x6b, 0x10,
50  0x18, 0x30, 0x94, 0x61, 0xdc, 0x0e, 0xcb, 0x96, 0x4e, 0x21, 0x3f, 0x79, 0xcd,
51  0xa9, 0x17, 0x62, 0xbc, 0xbb, 0x61, 0x4c, 0xe0, 0x75, 0x38, 0x6c, 0xf3, 0xde,
52  0x60, 0x86, 0x03, 0x97, 0x65, 0xeb, 0x1e, 0x6b, 0xdb, 0x53, 0x85, 0xad, 0x68,
53  0x21, 0xf1, 0x5d, 0xe7, 0x1f, 0xe6, 0x53, 0xb4, 0xbb, 0x59, 0x3e, 0x14, 0x27,
54  0xb1, 0x83, 0xa7, 0x3a, 0x54, 0xe2, 0x8f, 0x65, 0x8e, 0x6a, 0x4a, 0xcf, 0x3b,
55  0x1f, 0x65, 0xff, 0xfe, 0xf1, 0x31, 0x3a, 0x37, 0x7a, 0x8b, 0xcb, 0xc6, 0xd4,
56  0x98, 0x50, 0x36, 0x67, 0xe4, 0xa1, 0xe8, 0x7e, 0x8a, 0xc5, 0x23, 0xf2, 0x77,
57  0xf5, 0x37, 0x61, 0x49, 0x72, 0x59, 0xe8, 0x3d, 0xf7, 0x60, 0xb2, 0x77, 0xca,
58  0x78, 0x54, 0x6d, 0x65, 0x9e, 0x03, 0x97, 0x1b, 0x61, 0xbd, 0x0c, 0xd8, 0x06,
59  0x63, 0xe2, 0xc5, 0x48, 0xef, 0xb3, 0xe2, 0x6e, 0x98, 0x7d, 0xbd, 0x4e, 0x72,
60  0x91, 0xdb, 0x31, 0x57, 0xe3, 0x65, 0x3a, 0x49, 0xca, 0xec, 0xd2, 0x02, 0x4e,
61  0x22, 0x7e, 0x72, 0x8e, 0xf9, 0x79, 0x84, 0x82, 0xdf, 0x7b, 0x92, 0x2d, 0xaf,
62  0xc9, 0xe4, 0x33, 0xef, 0x89, 0x5c, 0x66, 0x99, 0xd8, 0x80, 0x81, 0x47, 0x2b,
63  0xb1, 0x66, 0x02, 0x84, 0x59, 0x7b, 0xc3, 0xbe, 0x98, 0x45, 0x4a, 0x3d, 0xdd,
64  0xea, 0x2b, 0xdf, 0x4e, 0xb4, 0x24, 0x6b, 0xec, 0xe7, 0xd9, 0x0c, 0x45, 0xb8,
65  0xbe, 0xca, 0x69, 0x37, 0x92, 0x4c, 0x38, 0x6b, 0x96, 0x6d, 0xcd, 0x86, 0x67,
66  0x5c, 0xea, 0x54, 0x94, 0xa4, 0xca, 0xa4, 0x02, 0xa5, 0x21, 0x4d, 0xae, 0x40,
67  0x8f, 0x9d, 0x51, 0x83, 0xf2, 0x3f, 0x33, 0xc1, 0x72, 0xb4, 0x1d, 0x94, 0x6e,
68  0x7d, 0xe4, 0x27, 0x3f, 0xea, 0xff, 0xe5, 0x9b, 0xa7, 0x5e, 0x55, 0x8e, 0x0d,
69  0x69, 0x1c, 0x7a, 0xff, 0x81, 0x9d, 0x53, 0x52, 0x97, 0x9a, 0x76, 0x79, 0xda,
70  0x93, 0x32, 0x16, 0xec, 0x69, 0x51, 0x1a, 0x4e, 0xc3, 0xf1, 0x72, 0x80, 0x78,
71  0x5e, 0x66, 0x4a, 0x8d, 0x85, 0x2f, 0x3f, 0xb2, 0xa7 };
72
73 static const BYTE selfSignedCert[] = {
74  0x30, 0x82, 0x01, 0x1f, 0x30, 0x81, 0xce, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02,
75  0x10, 0xeb, 0x0d, 0x57, 0x2a, 0x9c, 0x09, 0xba, 0xa4, 0x4a, 0xb7, 0x25, 0x49,
76  0xd9, 0x3e, 0xb5, 0x73, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1d,
77  0x05, 0x00, 0x30, 0x15, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x03,
78  0x13, 0x0a, 0x4a, 0x75, 0x61, 0x6e, 0x20, 0x4c, 0x61, 0x6e, 0x67, 0x00, 0x30,
79  0x1e, 0x17, 0x0d, 0x30, 0x36, 0x30, 0x36, 0x32, 0x39, 0x30, 0x35, 0x30, 0x30,
80  0x34, 0x36, 0x5a, 0x17, 0x0d, 0x30, 0x37, 0x30, 0x36, 0x32, 0x39, 0x31, 0x31,
81  0x30, 0x30, 0x34, 0x36, 0x5a, 0x30, 0x15, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03,
82  0x55, 0x04, 0x03, 0x13, 0x0a, 0x4a, 0x75, 0x61, 0x6e, 0x20, 0x4c, 0x61, 0x6e,
83  0x67, 0x00, 0x30, 0x5c, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
84  0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x4b, 0x00, 0x30, 0x48, 0x02, 0x41,
85  0x00, 0xe2, 0x54, 0x3a, 0xa7, 0x83, 0xb1, 0x27, 0x14, 0x3e, 0x59, 0xbb, 0xb4,
86  0x53, 0xe6, 0x1f, 0xe7, 0x5d, 0xf1, 0x21, 0x68, 0xad, 0x85, 0x53, 0xdb, 0x6b,
87  0x1e, 0xeb, 0x65, 0x97, 0x03, 0x86, 0x60, 0xde, 0xf3, 0x6c, 0x38, 0x75, 0xe0,
88  0x4c, 0x61, 0xbb, 0xbc, 0x62, 0x17, 0xa9, 0xcd, 0x79, 0x3f, 0x21, 0x4e, 0x96,
89  0xcb, 0x0e, 0xdc, 0x61, 0x94, 0x30, 0x18, 0x10, 0x6b, 0xd0, 0x1c, 0x10, 0x79,
90  0x02, 0x03, 0x01, 0x00, 0x01, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02,
91  0x1d, 0x05, 0x00, 0x03, 0x41, 0x00, 0x25, 0x90, 0x53, 0x34, 0xd9, 0x56, 0x41,
92  0x5e, 0xdb, 0x7e, 0x01, 0x36, 0xec, 0x27, 0x61, 0x5e, 0xb7, 0x4d, 0x90, 0x66,
93  0xa2, 0xe1, 0x9d, 0x58, 0x76, 0xd4, 0x9c, 0xba, 0x2c, 0x84, 0xc6, 0x83, 0x7a,
94  0x22, 0x0d, 0x03, 0x69, 0x32, 0x1a, 0x6d, 0xcb, 0x0c, 0x15, 0xb3, 0x6b, 0xc7,
95  0x0a, 0x8c, 0xb4, 0x5c, 0x34, 0x78, 0xe0, 0x3c, 0x9c, 0xe9, 0xf3, 0x30, 0x9f,
96  0xa8, 0x76, 0x57, 0x92, 0x36 };
97
98 static void InitFunctionPtrs(void)
99 {
100     secdll = LoadLibraryA("secur32.dll");
101     if(!secdll)
102         secdll = LoadLibraryA("security.dll");
103     if(secdll)
104     {
105         pAcquireCredentialsHandleA = (PVOID)GetProcAddress(secdll, "AcquireCredentialsHandleA");
106         pFreeCredentialsHandle = (PVOID)GetProcAddress(secdll, "FreeCredentialsHandle");
107     }
108 }
109
110 static void testAcquireSecurityContext(void)
111 {
112     SECURITY_STATUS st;
113     CredHandle cred;
114     TimeStamp exp;
115     SCHANNEL_CRED schanCred;
116     PCCERT_CONTEXT certs[2];
117     HCRYPTPROV csp;
118     static CHAR unisp_name_a[] = UNISP_NAME_A;
119     BOOL ret;
120     HCRYPTKEY key;
121     CRYPT_KEY_PROV_INFO keyProvInfo;
122
123     keyProvInfo.pwszContainerName = (LPWSTR)cspNameW;
124     keyProvInfo.pwszProvName = (LPWSTR)MS_DEF_PROV_W;
125     keyProvInfo.dwProvType = PROV_RSA_FULL;
126     keyProvInfo.dwFlags = 0;
127     keyProvInfo.cProvParam = 0;
128     keyProvInfo.rgProvParam = NULL;
129     keyProvInfo.dwKeySpec = AT_SIGNATURE;
130
131     certs[0] = CertCreateCertificateContext(X509_ASN_ENCODING, bigCert,
132      sizeof(bigCert));
133     certs[1] = CertCreateCertificateContext(X509_ASN_ENCODING, selfSignedCert,
134      sizeof(selfSignedCert));
135
136     CryptAcquireContextW(&csp, cspNameW, MS_DEF_PROV_W, PROV_RSA_FULL,
137      CRYPT_DELETEKEYSET);
138
139     st = pAcquireCredentialsHandleA(NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL,
140      NULL);
141     ok(st == SEC_E_SECPKG_NOT_FOUND,
142      "Expected SEC_E_SECPKG_NOT_FOUND, got %08x\n", st);
143     st = pAcquireCredentialsHandleA(NULL, unisp_name_a, 0, NULL, NULL, NULL,
144      NULL, NULL, NULL);
145     ok(st == SEC_E_NO_CREDENTIALS, "Expected SEC_E_NO_CREDENTIALS, got %08x\n",
146      st);
147     st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_BOTH, NULL,
148      NULL, NULL, NULL, NULL, NULL);
149     ok(st == SEC_E_NO_CREDENTIALS, "Expected SEC_E_NO_CREDENTIALS, got %08x\n",
150      st);
151     st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
152      NULL, NULL, NULL, NULL, NULL, NULL);
153     ok(st == SEC_E_NO_CREDENTIALS, "Expected SEC_E_NO_CREDENTIALS, got %08x\n",
154      st);
155     /* Crashes
156     st = pAcquireCredentialsHandleA(NULL, UNISP_NAME_A, SECPKG_CRED_OUTBOUND,
157      NULL, NULL, NULL, NULL, NULL, NULL);
158      */
159     st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
160      NULL, NULL, NULL, NULL, &cred, NULL);
161     ok(st == SEC_E_OK, "AcquireCredentialsHandleA failed: %08x\n", st);
162     pFreeCredentialsHandle(&cred);
163     memset(&cred, 0, sizeof(cred));
164     st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
165      NULL, NULL, NULL, NULL, &cred, &exp);
166     ok(st == SEC_E_OK, "AcquireCredentialsHandleA failed: %08x\n", st);
167     ok(exp.HighPart == 0 && exp.LowPart == 0,
168      "Expected 0 expiry, got %08lx%08lx\n", exp.HighPart, exp.LowPart);
169     pFreeCredentialsHandle(&cred);
170
171     /* Bad version in SCHANNEL_CRED */
172     memset(&schanCred, 0, sizeof(schanCred));
173     st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
174      NULL, &schanCred, NULL, NULL, NULL, NULL);
175     ok(st == SEC_E_INTERNAL_ERROR, "Expected SEC_E_INTERNAL_ERROR, got %08x\n",
176      st);
177     st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
178      NULL, &schanCred, NULL, NULL, NULL, NULL);
179     ok(st == SEC_E_INTERNAL_ERROR, "Expected SEC_E_INTERNAL_ERROR, got %08x\n",
180      st);
181
182     /* No cert in SCHANNEL_CRED succeeds for outbound.. */
183     schanCred.dwVersion = SCHANNEL_CRED_VERSION;
184     st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
185      NULL, &schanCred, NULL, NULL, &cred, NULL);
186     ok(st == SEC_E_OK, "AcquireCredentialsHandleA failed: %08x\n", st);
187     pFreeCredentialsHandle(&cred);
188     /* but fails for inbound. */
189     st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
190      NULL, &schanCred, NULL, NULL, NULL, NULL);
191     ok(st == SEC_E_NO_CREDENTIALS, "Expected SEC_E_NO_CREDENTIALS, got %08x\n",
192      st);
193
194     /* Crashes with bad paCred pointer
195     schanCred.cCreds = 1;
196     st = pAcquireCredentialsHandleA(NULL, UNISP_NAME_A, SECPKG_CRED_OUTBOUND,
197      NULL, &schanCred, NULL, NULL, NULL, NULL);
198      */
199
200     /* Bogus cert in SCHANNEL_CRED. Windows fails with
201      * SEC_E_UNKNOWN_CREDENTIALS, but I'll accept SEC_E_NO_CREDENTIALS too.
202      */
203     schanCred.cCreds = 1;
204     schanCred.paCred = &certs[0];
205     st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
206      NULL, &schanCred, NULL, NULL, NULL, NULL);
207     ok(st == SEC_E_UNKNOWN_CREDENTIALS || SEC_E_NO_CREDENTIALS,
208      "Expected SEC_E_UNKNOWN_CREDENTIALS or SEC_E_NO_CREDENTIALS, got %08x\n",
209      st);
210     st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
211      NULL, &schanCred, NULL, NULL, NULL, NULL);
212     ok(st == SEC_E_UNKNOWN_CREDENTIALS || SEC_E_NO_CREDENTIALS,
213      "Expected SEC_E_UNKNOWN_CREDENTIALS or SEC_E_NO_CREDENTIALS, got %08x\n",
214      st);
215
216     /* Good cert, but missing private key. Windows fails with
217      * SEC_E_NO_CREDENTIALS, but I'll accept SEC_E_UNKNOWN_CREDENTIALS too.
218      */
219     schanCred.cCreds = 1;
220     schanCred.paCred = &certs[1];
221     st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
222      NULL, &schanCred, NULL, NULL, &cred, NULL);
223     ok(st == SEC_E_UNKNOWN_CREDENTIALS || SEC_E_NO_CREDENTIALS,
224      "Expected SEC_E_UNKNOWN_CREDENTIALS or SEC_E_NO_CREDENTIALS, got %08x\n",
225      st);
226     st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
227      NULL, &schanCred, NULL, NULL, NULL, NULL);
228     ok(st == SEC_E_UNKNOWN_CREDENTIALS || SEC_E_NO_CREDENTIALS,
229      "Expected SEC_E_UNKNOWN_CREDENTIALS or SEC_E_NO_CREDENTIALS, got %08x\n",
230      st);
231
232     /* Good cert, with CRYPT_KEY_PROV_INFO set before it's had a key loaded. */
233     ret = CertSetCertificateContextProperty(certs[1],
234      CERT_KEY_PROV_INFO_PROP_ID, 0, &keyProvInfo);
235     schanCred.dwVersion = SCH_CRED_V3;
236     st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
237      NULL, &schanCred, NULL, NULL, &cred, NULL);
238     ok(st == SEC_E_UNKNOWN_CREDENTIALS,
239      "Expected SEC_E_UNKNOWN_CREDENTIALS, got %08x\n", st);
240     st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
241      NULL, &schanCred, NULL, NULL, &cred, NULL);
242     ok(st == SEC_E_UNKNOWN_CREDENTIALS,
243      "Expected SEC_E_UNKNOWN_CREDENTIALS, got %08x\n", st);
244
245     ret = CryptAcquireContextW(&csp, cspNameW, MS_DEF_PROV_W, PROV_RSA_FULL,
246      CRYPT_NEWKEYSET);
247     ok(ret, "CryptAcquireContextW failed: %08x\n", GetLastError());
248     ret = CryptImportKey(csp, (LPBYTE)privKey, sizeof(privKey), 0, 0, &key);
249     ok(ret, "CryptImportKey failed: %08x\n", GetLastError());
250     if (ret)
251     {
252         PCCERT_CONTEXT tmp;
253
254         /* Crashes
255         st = pAcquireCredentialsHandleA(NULL, UNISP_NAME_A, SECPKG_CRED_INBOUND,
256          NULL, &schanCred, NULL, NULL, NULL, NULL);
257          */
258         /* Good cert with private key, bogus version */
259         schanCred.dwVersion = SCH_CRED_V1;
260         st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
261          NULL, &schanCred, NULL, NULL, &cred, NULL);
262         ok(st == SEC_E_INTERNAL_ERROR,
263          "Expected SEC_E_INTERNAL_ERROR, got %08x\n", st);
264         st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
265          NULL, &schanCred, NULL, NULL, &cred, NULL);
266         ok(st == SEC_E_INTERNAL_ERROR,
267          "Expected SEC_E_INTERNAL_ERROR, got %08x\n", st);
268         schanCred.dwVersion = SCH_CRED_V2;
269         st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
270          NULL, &schanCred, NULL, NULL, &cred, NULL);
271         ok(st == SEC_E_INTERNAL_ERROR,
272          "Expected SEC_E_INTERNAL_ERROR, got %08x\n", st);
273         st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
274          NULL, &schanCred, NULL, NULL, &cred, NULL);
275         ok(st == SEC_E_INTERNAL_ERROR,
276          "Expected SEC_E_INTERNAL_ERROR, got %08x\n", st);
277
278         /* Succeeds on V3 or higher */
279         schanCred.dwVersion = SCH_CRED_V3;
280         st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
281          NULL, &schanCred, NULL, NULL, &cred, NULL);
282         ok(st == SEC_E_OK, "AcquireCredentialsHandleA failed: %08x\n", st);
283         pFreeCredentialsHandle(&cred);
284         st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
285          NULL, &schanCred, NULL, NULL, &cred, NULL);
286         ok(st == SEC_E_OK, "AcquireCredentialsHandleA failed: %08x\n", st);
287         pFreeCredentialsHandle(&cred);
288         schanCred.dwVersion = SCHANNEL_CRED_VERSION;
289         st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
290          NULL, &schanCred, NULL, NULL, &cred, NULL);
291         ok(st == SEC_E_OK, "AcquireCredentialsHandleA failed: %08x\n", st);
292         pFreeCredentialsHandle(&cred);
293         st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
294          NULL, &schanCred, NULL, NULL, &cred, NULL);
295         ok(st == SEC_E_OK, "AcquireCredentialsHandleA failed: %08x\n", st);
296         pFreeCredentialsHandle(&cred);
297
298         /* How about more than one cert? */
299         schanCred.cCreds = 2;
300         schanCred.paCred = certs;
301         st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
302          NULL, &schanCred, NULL, NULL, &cred, NULL);
303         ok(st == SEC_E_UNKNOWN_CREDENTIALS,
304          "Expected SEC_E_UNKNOWN_CREDENTIALS, got %08x\n", st);
305         st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
306          NULL, &schanCred, NULL, NULL, &cred, NULL);
307         ok(st == SEC_E_UNKNOWN_CREDENTIALS,
308          "Expected SEC_E_UNKNOWN_CREDENTIALS, got %08x\n", st);
309         tmp = certs[0];
310         certs[0] = certs[1];
311         certs[1] = tmp;
312         st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
313          NULL, &schanCred, NULL, NULL, &cred, NULL);
314         ok(st == SEC_E_UNKNOWN_CREDENTIALS,
315          "Expected SEC_E_UNKNOWN_CREDENTIALS, got %08x\n", st);
316         st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
317          NULL, &schanCred, NULL, NULL, &cred, NULL);
318         ok(st == SEC_E_UNKNOWN_CREDENTIALS,
319          "Expected SEC_E_UNKNOWN_CREDENTIALS, got %08x\n", st);
320         /* FIXME: what about two valid certs? */
321
322         CryptDestroyKey(key);
323     }
324
325     CryptReleaseContext(csp, 0);
326     CryptAcquireContextW(&csp, cspNameW, MS_DEF_PROV_W, PROV_RSA_FULL,
327      CRYPT_DELETEKEYSET);
328
329     CertFreeCertificateContext(certs[0]);
330     CertFreeCertificateContext(certs[1]);
331 }
332
333 START_TEST(schannel)
334 {
335     InitFunctionPtrs();
336
337     if (pAcquireCredentialsHandleA && pFreeCredentialsHandle)
338         testAcquireSecurityContext();
339
340     if(secdll)
341         FreeLibrary(secdll);
342 }