2006-07-28 08:39:56 +02:00
|
|
|
/*
|
|
|
|
* Schannel tests
|
|
|
|
*
|
|
|
|
* Copyright 2006 Juan Lang
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <windef.h>
|
|
|
|
#include <winbase.h>
|
|
|
|
#define SECURITY_WIN32
|
|
|
|
#include <security.h>
|
|
|
|
#include <schannel.h>
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
2006-08-17 13:42:28 +02:00
|
|
|
static HMODULE secdll;
|
|
|
|
static SECURITY_STATUS (SEC_ENTRY * pAcquireCredentialsHandleA)(SEC_CHAR*, SEC_CHAR*,
|
|
|
|
ULONG, PLUID, PVOID, SEC_GET_KEY_FN, PVOID, PCredHandle, PTimeStamp);
|
|
|
|
static SECURITY_STATUS (SEC_ENTRY * pFreeCredentialsHandle)(PCredHandle);
|
|
|
|
|
2006-07-28 08:39:56 +02:00
|
|
|
static const BYTE bigCert[] = { 0x30, 0x7a, 0x02, 0x01, 0x01, 0x30, 0x02, 0x06,
|
|
|
|
0x00, 0x30, 0x15, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13,
|
|
|
|
0x0a, 0x4a, 0x75, 0x61, 0x6e, 0x20, 0x4c, 0x61, 0x6e, 0x67, 0x00, 0x30, 0x22,
|
|
|
|
0x18, 0x0f, 0x31, 0x36, 0x30, 0x31, 0x30, 0x31, 0x30, 0x31, 0x30, 0x30, 0x30,
|
|
|
|
0x30, 0x30, 0x30, 0x5a, 0x18, 0x0f, 0x31, 0x36, 0x30, 0x31, 0x30, 0x31, 0x30,
|
|
|
|
0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x5a, 0x30, 0x15, 0x31, 0x13, 0x30,
|
|
|
|
0x11, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x0a, 0x4a, 0x75, 0x61, 0x6e, 0x20,
|
|
|
|
0x4c, 0x61, 0x6e, 0x67, 0x00, 0x30, 0x07, 0x30, 0x02, 0x06, 0x00, 0x03, 0x01,
|
|
|
|
0x00, 0xa3, 0x16, 0x30, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01,
|
|
|
|
0x01, 0xff, 0x04, 0x08, 0x30, 0x06, 0x01, 0x01, 0xff, 0x02, 0x01, 0x01 };
|
2007-01-12 14:01:16 +01:00
|
|
|
static WCHAR cspNameW[] = { 'W','i','n','e','C','r','y','p','t','T','e',
|
2006-07-28 08:39:56 +02:00
|
|
|
'm','p',0 };
|
2007-01-12 14:01:16 +01:00
|
|
|
static BYTE privKey[] = {
|
2006-07-28 08:39:56 +02:00
|
|
|
0x07, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x52, 0x53, 0x41, 0x32, 0x00,
|
|
|
|
0x02, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x79, 0x10, 0x1c, 0xd0, 0x6b, 0x10,
|
|
|
|
0x18, 0x30, 0x94, 0x61, 0xdc, 0x0e, 0xcb, 0x96, 0x4e, 0x21, 0x3f, 0x79, 0xcd,
|
|
|
|
0xa9, 0x17, 0x62, 0xbc, 0xbb, 0x61, 0x4c, 0xe0, 0x75, 0x38, 0x6c, 0xf3, 0xde,
|
|
|
|
0x60, 0x86, 0x03, 0x97, 0x65, 0xeb, 0x1e, 0x6b, 0xdb, 0x53, 0x85, 0xad, 0x68,
|
|
|
|
0x21, 0xf1, 0x5d, 0xe7, 0x1f, 0xe6, 0x53, 0xb4, 0xbb, 0x59, 0x3e, 0x14, 0x27,
|
|
|
|
0xb1, 0x83, 0xa7, 0x3a, 0x54, 0xe2, 0x8f, 0x65, 0x8e, 0x6a, 0x4a, 0xcf, 0x3b,
|
|
|
|
0x1f, 0x65, 0xff, 0xfe, 0xf1, 0x31, 0x3a, 0x37, 0x7a, 0x8b, 0xcb, 0xc6, 0xd4,
|
|
|
|
0x98, 0x50, 0x36, 0x67, 0xe4, 0xa1, 0xe8, 0x7e, 0x8a, 0xc5, 0x23, 0xf2, 0x77,
|
|
|
|
0xf5, 0x37, 0x61, 0x49, 0x72, 0x59, 0xe8, 0x3d, 0xf7, 0x60, 0xb2, 0x77, 0xca,
|
|
|
|
0x78, 0x54, 0x6d, 0x65, 0x9e, 0x03, 0x97, 0x1b, 0x61, 0xbd, 0x0c, 0xd8, 0x06,
|
|
|
|
0x63, 0xe2, 0xc5, 0x48, 0xef, 0xb3, 0xe2, 0x6e, 0x98, 0x7d, 0xbd, 0x4e, 0x72,
|
|
|
|
0x91, 0xdb, 0x31, 0x57, 0xe3, 0x65, 0x3a, 0x49, 0xca, 0xec, 0xd2, 0x02, 0x4e,
|
|
|
|
0x22, 0x7e, 0x72, 0x8e, 0xf9, 0x79, 0x84, 0x82, 0xdf, 0x7b, 0x92, 0x2d, 0xaf,
|
|
|
|
0xc9, 0xe4, 0x33, 0xef, 0x89, 0x5c, 0x66, 0x99, 0xd8, 0x80, 0x81, 0x47, 0x2b,
|
|
|
|
0xb1, 0x66, 0x02, 0x84, 0x59, 0x7b, 0xc3, 0xbe, 0x98, 0x45, 0x4a, 0x3d, 0xdd,
|
|
|
|
0xea, 0x2b, 0xdf, 0x4e, 0xb4, 0x24, 0x6b, 0xec, 0xe7, 0xd9, 0x0c, 0x45, 0xb8,
|
|
|
|
0xbe, 0xca, 0x69, 0x37, 0x92, 0x4c, 0x38, 0x6b, 0x96, 0x6d, 0xcd, 0x86, 0x67,
|
|
|
|
0x5c, 0xea, 0x54, 0x94, 0xa4, 0xca, 0xa4, 0x02, 0xa5, 0x21, 0x4d, 0xae, 0x40,
|
|
|
|
0x8f, 0x9d, 0x51, 0x83, 0xf2, 0x3f, 0x33, 0xc1, 0x72, 0xb4, 0x1d, 0x94, 0x6e,
|
|
|
|
0x7d, 0xe4, 0x27, 0x3f, 0xea, 0xff, 0xe5, 0x9b, 0xa7, 0x5e, 0x55, 0x8e, 0x0d,
|
|
|
|
0x69, 0x1c, 0x7a, 0xff, 0x81, 0x9d, 0x53, 0x52, 0x97, 0x9a, 0x76, 0x79, 0xda,
|
|
|
|
0x93, 0x32, 0x16, 0xec, 0x69, 0x51, 0x1a, 0x4e, 0xc3, 0xf1, 0x72, 0x80, 0x78,
|
|
|
|
0x5e, 0x66, 0x4a, 0x8d, 0x85, 0x2f, 0x3f, 0xb2, 0xa7 };
|
|
|
|
|
|
|
|
static const BYTE selfSignedCert[] = {
|
|
|
|
0x30, 0x82, 0x01, 0x1f, 0x30, 0x81, 0xce, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02,
|
|
|
|
0x10, 0xeb, 0x0d, 0x57, 0x2a, 0x9c, 0x09, 0xba, 0xa4, 0x4a, 0xb7, 0x25, 0x49,
|
|
|
|
0xd9, 0x3e, 0xb5, 0x73, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1d,
|
|
|
|
0x05, 0x00, 0x30, 0x15, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x03,
|
|
|
|
0x13, 0x0a, 0x4a, 0x75, 0x61, 0x6e, 0x20, 0x4c, 0x61, 0x6e, 0x67, 0x00, 0x30,
|
|
|
|
0x1e, 0x17, 0x0d, 0x30, 0x36, 0x30, 0x36, 0x32, 0x39, 0x30, 0x35, 0x30, 0x30,
|
|
|
|
0x34, 0x36, 0x5a, 0x17, 0x0d, 0x30, 0x37, 0x30, 0x36, 0x32, 0x39, 0x31, 0x31,
|
|
|
|
0x30, 0x30, 0x34, 0x36, 0x5a, 0x30, 0x15, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03,
|
|
|
|
0x55, 0x04, 0x03, 0x13, 0x0a, 0x4a, 0x75, 0x61, 0x6e, 0x20, 0x4c, 0x61, 0x6e,
|
|
|
|
0x67, 0x00, 0x30, 0x5c, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
|
|
|
|
0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x4b, 0x00, 0x30, 0x48, 0x02, 0x41,
|
|
|
|
0x00, 0xe2, 0x54, 0x3a, 0xa7, 0x83, 0xb1, 0x27, 0x14, 0x3e, 0x59, 0xbb, 0xb4,
|
|
|
|
0x53, 0xe6, 0x1f, 0xe7, 0x5d, 0xf1, 0x21, 0x68, 0xad, 0x85, 0x53, 0xdb, 0x6b,
|
|
|
|
0x1e, 0xeb, 0x65, 0x97, 0x03, 0x86, 0x60, 0xde, 0xf3, 0x6c, 0x38, 0x75, 0xe0,
|
|
|
|
0x4c, 0x61, 0xbb, 0xbc, 0x62, 0x17, 0xa9, 0xcd, 0x79, 0x3f, 0x21, 0x4e, 0x96,
|
|
|
|
0xcb, 0x0e, 0xdc, 0x61, 0x94, 0x30, 0x18, 0x10, 0x6b, 0xd0, 0x1c, 0x10, 0x79,
|
|
|
|
0x02, 0x03, 0x01, 0x00, 0x01, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02,
|
|
|
|
0x1d, 0x05, 0x00, 0x03, 0x41, 0x00, 0x25, 0x90, 0x53, 0x34, 0xd9, 0x56, 0x41,
|
|
|
|
0x5e, 0xdb, 0x7e, 0x01, 0x36, 0xec, 0x27, 0x61, 0x5e, 0xb7, 0x4d, 0x90, 0x66,
|
|
|
|
0xa2, 0xe1, 0x9d, 0x58, 0x76, 0xd4, 0x9c, 0xba, 0x2c, 0x84, 0xc6, 0x83, 0x7a,
|
|
|
|
0x22, 0x0d, 0x03, 0x69, 0x32, 0x1a, 0x6d, 0xcb, 0x0c, 0x15, 0xb3, 0x6b, 0xc7,
|
|
|
|
0x0a, 0x8c, 0xb4, 0x5c, 0x34, 0x78, 0xe0, 0x3c, 0x9c, 0xe9, 0xf3, 0x30, 0x9f,
|
|
|
|
0xa8, 0x76, 0x57, 0x92, 0x36 };
|
|
|
|
|
2006-08-17 13:42:28 +02:00
|
|
|
static void InitFunctionPtrs(void)
|
|
|
|
{
|
|
|
|
secdll = LoadLibraryA("secur32.dll");
|
|
|
|
if(!secdll)
|
|
|
|
secdll = LoadLibraryA("security.dll");
|
|
|
|
if(secdll)
|
|
|
|
{
|
|
|
|
pAcquireCredentialsHandleA = (PVOID)GetProcAddress(secdll, "AcquireCredentialsHandleA");
|
|
|
|
pFreeCredentialsHandle = (PVOID)GetProcAddress(secdll, "FreeCredentialsHandle");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-28 08:39:56 +02:00
|
|
|
static void testAcquireSecurityContext(void)
|
|
|
|
{
|
|
|
|
SECURITY_STATUS st;
|
|
|
|
CredHandle cred;
|
|
|
|
TimeStamp exp;
|
|
|
|
SCHANNEL_CRED schanCred;
|
|
|
|
PCCERT_CONTEXT certs[2];
|
|
|
|
HCRYPTPROV csp;
|
2006-08-05 16:51:13 +02:00
|
|
|
static CHAR unisp_name_a[] = UNISP_NAME_A;
|
2007-01-13 16:08:55 +01:00
|
|
|
WCHAR ms_def_prov_w[MAX_PATH];
|
2006-07-28 08:39:56 +02:00
|
|
|
BOOL ret;
|
|
|
|
HCRYPTKEY key;
|
|
|
|
CRYPT_KEY_PROV_INFO keyProvInfo;
|
|
|
|
|
2007-01-13 16:08:55 +01:00
|
|
|
lstrcpyW(ms_def_prov_w, MS_DEF_PROV_W);
|
|
|
|
|
2007-01-12 14:01:16 +01:00
|
|
|
keyProvInfo.pwszContainerName = cspNameW;
|
|
|
|
keyProvInfo.pwszProvName = ms_def_prov_w;
|
2006-07-28 08:39:56 +02:00
|
|
|
keyProvInfo.dwProvType = PROV_RSA_FULL;
|
|
|
|
keyProvInfo.dwFlags = 0;
|
|
|
|
keyProvInfo.cProvParam = 0;
|
|
|
|
keyProvInfo.rgProvParam = NULL;
|
|
|
|
keyProvInfo.dwKeySpec = AT_SIGNATURE;
|
|
|
|
|
|
|
|
certs[0] = CertCreateCertificateContext(X509_ASN_ENCODING, bigCert,
|
|
|
|
sizeof(bigCert));
|
|
|
|
certs[1] = CertCreateCertificateContext(X509_ASN_ENCODING, selfSignedCert,
|
|
|
|
sizeof(selfSignedCert));
|
|
|
|
|
|
|
|
CryptAcquireContextW(&csp, cspNameW, MS_DEF_PROV_W, PROV_RSA_FULL,
|
|
|
|
CRYPT_DELETEKEYSET);
|
|
|
|
|
2006-08-17 13:42:28 +02:00
|
|
|
st = pAcquireCredentialsHandleA(NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL);
|
|
|
|
ok(st == SEC_E_SECPKG_NOT_FOUND,
|
2006-10-10 23:47:35 +02:00
|
|
|
"Expected SEC_E_SECPKG_NOT_FOUND, got %08x\n", st);
|
2006-10-31 09:28:31 +01:00
|
|
|
if (0)
|
|
|
|
{
|
|
|
|
/* Crashes on Win2K */
|
|
|
|
st = pAcquireCredentialsHandleA(NULL, unisp_name_a, 0, NULL, NULL, NULL,
|
|
|
|
NULL, NULL, NULL);
|
|
|
|
ok(st == SEC_E_NO_CREDENTIALS, "Expected SEC_E_NO_CREDENTIALS, got %08x\n",
|
|
|
|
st);
|
|
|
|
}
|
2006-08-17 13:42:28 +02:00
|
|
|
st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_BOTH, NULL,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, NULL, NULL, NULL, NULL);
|
2006-10-10 23:47:35 +02:00
|
|
|
ok(st == SEC_E_NO_CREDENTIALS, "Expected SEC_E_NO_CREDENTIALS, got %08x\n",
|
2006-07-28 08:39:56 +02:00
|
|
|
st);
|
2006-08-17 13:42:28 +02:00
|
|
|
st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL);
|
2006-10-10 23:47:35 +02:00
|
|
|
ok(st == SEC_E_NO_CREDENTIALS, "Expected SEC_E_NO_CREDENTIALS, got %08x\n",
|
2006-07-28 08:39:56 +02:00
|
|
|
st);
|
2006-10-31 09:28:31 +01:00
|
|
|
if (0)
|
|
|
|
{
|
|
|
|
/* Crashes */
|
|
|
|
st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
}
|
2006-08-17 13:42:28 +02:00
|
|
|
st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, NULL, NULL, NULL, &cred, NULL);
|
2006-10-10 23:47:35 +02:00
|
|
|
ok(st == SEC_E_OK, "AcquireCredentialsHandleA failed: %08x\n", st);
|
2006-08-17 13:42:28 +02:00
|
|
|
pFreeCredentialsHandle(&cred);
|
2006-07-28 08:39:56 +02:00
|
|
|
memset(&cred, 0, sizeof(cred));
|
2006-08-17 13:42:28 +02:00
|
|
|
st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, NULL, NULL, NULL, &cred, &exp);
|
2006-10-10 23:47:35 +02:00
|
|
|
ok(st == SEC_E_OK, "AcquireCredentialsHandleA failed: %08x\n", st);
|
2006-07-28 08:39:56 +02:00
|
|
|
ok(exp.HighPart == 0 && exp.LowPart == 0,
|
|
|
|
"Expected 0 expiry, got %08lx%08lx\n", exp.HighPart, exp.LowPart);
|
2006-08-17 13:42:28 +02:00
|
|
|
pFreeCredentialsHandle(&cred);
|
2006-07-28 08:39:56 +02:00
|
|
|
|
|
|
|
/* Bad version in SCHANNEL_CRED */
|
|
|
|
memset(&schanCred, 0, sizeof(schanCred));
|
2006-08-17 13:42:28 +02:00
|
|
|
st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, NULL, NULL);
|
2006-10-10 23:47:35 +02:00
|
|
|
ok(st == SEC_E_INTERNAL_ERROR, "Expected SEC_E_INTERNAL_ERROR, got %08x\n",
|
2006-07-28 08:39:56 +02:00
|
|
|
st);
|
2006-08-17 13:42:28 +02:00
|
|
|
st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, NULL, NULL);
|
2006-10-10 23:47:35 +02:00
|
|
|
ok(st == SEC_E_INTERNAL_ERROR, "Expected SEC_E_INTERNAL_ERROR, got %08x\n",
|
2006-07-28 08:39:56 +02:00
|
|
|
st);
|
|
|
|
|
|
|
|
/* No cert in SCHANNEL_CRED succeeds for outbound.. */
|
|
|
|
schanCred.dwVersion = SCHANNEL_CRED_VERSION;
|
2006-08-17 13:42:28 +02:00
|
|
|
st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, &cred, NULL);
|
2006-10-10 23:47:35 +02:00
|
|
|
ok(st == SEC_E_OK, "AcquireCredentialsHandleA failed: %08x\n", st);
|
2006-08-17 13:42:28 +02:00
|
|
|
pFreeCredentialsHandle(&cred);
|
2006-07-28 08:39:56 +02:00
|
|
|
/* but fails for inbound. */
|
2006-08-17 13:42:28 +02:00
|
|
|
st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, NULL, NULL);
|
2006-10-10 23:47:35 +02:00
|
|
|
ok(st == SEC_E_NO_CREDENTIALS, "Expected SEC_E_NO_CREDENTIALS, got %08x\n",
|
2006-07-28 08:39:56 +02:00
|
|
|
st);
|
|
|
|
|
2006-10-31 09:28:31 +01:00
|
|
|
if (0)
|
|
|
|
{
|
|
|
|
/* Crashes with bad paCred pointer */
|
|
|
|
schanCred.cCreds = 1;
|
|
|
|
st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
|
|
|
|
NULL, &schanCred, NULL, NULL, NULL, NULL);
|
|
|
|
}
|
2006-07-28 08:39:56 +02:00
|
|
|
|
|
|
|
/* Bogus cert in SCHANNEL_CRED. Windows fails with
|
|
|
|
* SEC_E_UNKNOWN_CREDENTIALS, but I'll accept SEC_E_NO_CREDENTIALS too.
|
|
|
|
*/
|
|
|
|
schanCred.cCreds = 1;
|
|
|
|
schanCred.paCred = &certs[0];
|
2006-08-17 13:42:28 +02:00
|
|
|
st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, NULL, NULL);
|
|
|
|
ok(st == SEC_E_UNKNOWN_CREDENTIALS || SEC_E_NO_CREDENTIALS,
|
2006-10-10 23:47:35 +02:00
|
|
|
"Expected SEC_E_UNKNOWN_CREDENTIALS or SEC_E_NO_CREDENTIALS, got %08x\n",
|
2006-07-28 08:39:56 +02:00
|
|
|
st);
|
2006-08-17 13:42:28 +02:00
|
|
|
st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, NULL, NULL);
|
|
|
|
ok(st == SEC_E_UNKNOWN_CREDENTIALS || SEC_E_NO_CREDENTIALS,
|
2006-10-10 23:47:35 +02:00
|
|
|
"Expected SEC_E_UNKNOWN_CREDENTIALS or SEC_E_NO_CREDENTIALS, got %08x\n",
|
2006-07-28 08:39:56 +02:00
|
|
|
st);
|
|
|
|
|
|
|
|
/* Good cert, but missing private key. Windows fails with
|
|
|
|
* SEC_E_NO_CREDENTIALS, but I'll accept SEC_E_UNKNOWN_CREDENTIALS too.
|
|
|
|
*/
|
|
|
|
schanCred.cCreds = 1;
|
|
|
|
schanCred.paCred = &certs[1];
|
2006-08-17 13:42:28 +02:00
|
|
|
st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, &cred, NULL);
|
|
|
|
ok(st == SEC_E_UNKNOWN_CREDENTIALS || SEC_E_NO_CREDENTIALS,
|
2006-10-10 23:47:35 +02:00
|
|
|
"Expected SEC_E_UNKNOWN_CREDENTIALS or SEC_E_NO_CREDENTIALS, got %08x\n",
|
2006-07-28 08:39:56 +02:00
|
|
|
st);
|
2006-08-17 13:42:28 +02:00
|
|
|
st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, NULL, NULL);
|
|
|
|
ok(st == SEC_E_UNKNOWN_CREDENTIALS || SEC_E_NO_CREDENTIALS,
|
2006-10-10 23:47:35 +02:00
|
|
|
"Expected SEC_E_UNKNOWN_CREDENTIALS or SEC_E_NO_CREDENTIALS, got %08x\n",
|
2006-07-28 08:39:56 +02:00
|
|
|
st);
|
|
|
|
|
|
|
|
/* Good cert, with CRYPT_KEY_PROV_INFO set before it's had a key loaded. */
|
|
|
|
ret = CertSetCertificateContextProperty(certs[1],
|
|
|
|
CERT_KEY_PROV_INFO_PROP_ID, 0, &keyProvInfo);
|
|
|
|
schanCred.dwVersion = SCH_CRED_V3;
|
2006-08-17 13:42:28 +02:00
|
|
|
st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, &cred, NULL);
|
|
|
|
ok(st == SEC_E_UNKNOWN_CREDENTIALS,
|
2006-10-10 23:47:35 +02:00
|
|
|
"Expected SEC_E_UNKNOWN_CREDENTIALS, got %08x\n", st);
|
2006-08-17 13:42:28 +02:00
|
|
|
st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, &cred, NULL);
|
|
|
|
ok(st == SEC_E_UNKNOWN_CREDENTIALS,
|
2006-10-10 23:47:35 +02:00
|
|
|
"Expected SEC_E_UNKNOWN_CREDENTIALS, got %08x\n", st);
|
2006-07-28 08:39:56 +02:00
|
|
|
|
|
|
|
ret = CryptAcquireContextW(&csp, cspNameW, MS_DEF_PROV_W, PROV_RSA_FULL,
|
|
|
|
CRYPT_NEWKEYSET);
|
2006-10-10 23:47:35 +02:00
|
|
|
ok(ret, "CryptAcquireContextW failed: %08x\n", GetLastError());
|
2007-01-12 14:01:16 +01:00
|
|
|
ret = CryptImportKey(csp, privKey, sizeof(privKey), 0, 0, &key);
|
2006-10-10 23:47:35 +02:00
|
|
|
ok(ret, "CryptImportKey failed: %08x\n", GetLastError());
|
2006-07-28 08:39:56 +02:00
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
PCCERT_CONTEXT tmp;
|
|
|
|
|
2006-10-31 09:28:31 +01:00
|
|
|
if (0)
|
|
|
|
{
|
|
|
|
/* Crashes */
|
|
|
|
st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
|
|
|
|
NULL, &schanCred, NULL, NULL, NULL, NULL);
|
|
|
|
}
|
2006-07-28 08:39:56 +02:00
|
|
|
/* Good cert with private key, bogus version */
|
|
|
|
schanCred.dwVersion = SCH_CRED_V1;
|
2006-08-17 13:42:28 +02:00
|
|
|
st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, &cred, NULL);
|
|
|
|
ok(st == SEC_E_INTERNAL_ERROR,
|
2006-10-10 23:47:35 +02:00
|
|
|
"Expected SEC_E_INTERNAL_ERROR, got %08x\n", st);
|
2006-08-17 13:42:28 +02:00
|
|
|
st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, &cred, NULL);
|
|
|
|
ok(st == SEC_E_INTERNAL_ERROR,
|
2006-10-10 23:47:35 +02:00
|
|
|
"Expected SEC_E_INTERNAL_ERROR, got %08x\n", st);
|
2006-07-28 08:39:56 +02:00
|
|
|
schanCred.dwVersion = SCH_CRED_V2;
|
2006-08-17 13:42:28 +02:00
|
|
|
st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, &cred, NULL);
|
|
|
|
ok(st == SEC_E_INTERNAL_ERROR,
|
2006-10-10 23:47:35 +02:00
|
|
|
"Expected SEC_E_INTERNAL_ERROR, got %08x\n", st);
|
2006-08-17 13:42:28 +02:00
|
|
|
st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, &cred, NULL);
|
|
|
|
ok(st == SEC_E_INTERNAL_ERROR,
|
2006-10-10 23:47:35 +02:00
|
|
|
"Expected SEC_E_INTERNAL_ERROR, got %08x\n", st);
|
2006-07-28 08:39:56 +02:00
|
|
|
|
|
|
|
/* Succeeds on V3 or higher */
|
|
|
|
schanCred.dwVersion = SCH_CRED_V3;
|
2006-08-17 13:42:28 +02:00
|
|
|
st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, &cred, NULL);
|
2006-10-10 23:47:35 +02:00
|
|
|
ok(st == SEC_E_OK, "AcquireCredentialsHandleA failed: %08x\n", st);
|
2006-08-17 13:42:28 +02:00
|
|
|
pFreeCredentialsHandle(&cred);
|
|
|
|
st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, &cred, NULL);
|
2006-10-10 23:47:35 +02:00
|
|
|
ok(st == SEC_E_OK, "AcquireCredentialsHandleA failed: %08x\n", st);
|
2006-08-17 13:42:28 +02:00
|
|
|
pFreeCredentialsHandle(&cred);
|
2006-07-28 08:39:56 +02:00
|
|
|
schanCred.dwVersion = SCHANNEL_CRED_VERSION;
|
2006-08-17 13:42:28 +02:00
|
|
|
st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, &cred, NULL);
|
2006-10-10 23:47:35 +02:00
|
|
|
ok(st == SEC_E_OK, "AcquireCredentialsHandleA failed: %08x\n", st);
|
2006-08-17 13:42:28 +02:00
|
|
|
pFreeCredentialsHandle(&cred);
|
|
|
|
st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, &cred, NULL);
|
2006-10-10 23:47:35 +02:00
|
|
|
ok(st == SEC_E_OK, "AcquireCredentialsHandleA failed: %08x\n", st);
|
2006-08-17 13:42:28 +02:00
|
|
|
pFreeCredentialsHandle(&cred);
|
2006-07-28 08:39:56 +02:00
|
|
|
|
|
|
|
/* How about more than one cert? */
|
|
|
|
schanCred.cCreds = 2;
|
|
|
|
schanCred.paCred = certs;
|
2006-08-17 13:42:28 +02:00
|
|
|
st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, &cred, NULL);
|
|
|
|
ok(st == SEC_E_UNKNOWN_CREDENTIALS,
|
2006-10-10 23:47:35 +02:00
|
|
|
"Expected SEC_E_UNKNOWN_CREDENTIALS, got %08x\n", st);
|
2006-08-17 13:42:28 +02:00
|
|
|
st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, &cred, NULL);
|
|
|
|
ok(st == SEC_E_UNKNOWN_CREDENTIALS,
|
2006-10-10 23:47:35 +02:00
|
|
|
"Expected SEC_E_UNKNOWN_CREDENTIALS, got %08x\n", st);
|
2006-07-28 08:39:56 +02:00
|
|
|
tmp = certs[0];
|
|
|
|
certs[0] = certs[1];
|
|
|
|
certs[1] = tmp;
|
2006-08-17 13:42:28 +02:00
|
|
|
st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, &cred, NULL);
|
|
|
|
ok(st == SEC_E_UNKNOWN_CREDENTIALS,
|
2006-10-10 23:47:35 +02:00
|
|
|
"Expected SEC_E_UNKNOWN_CREDENTIALS, got %08x\n", st);
|
2006-08-17 13:42:28 +02:00
|
|
|
st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, &cred, NULL);
|
|
|
|
ok(st == SEC_E_UNKNOWN_CREDENTIALS,
|
2006-10-10 23:47:35 +02:00
|
|
|
"Expected SEC_E_UNKNOWN_CREDENTIALS, got %08x\n", st);
|
2006-07-28 08:39:56 +02:00
|
|
|
/* FIXME: what about two valid certs? */
|
|
|
|
|
|
|
|
CryptDestroyKey(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
CryptReleaseContext(csp, 0);
|
|
|
|
CryptAcquireContextW(&csp, cspNameW, MS_DEF_PROV_W, PROV_RSA_FULL,
|
|
|
|
CRYPT_DELETEKEYSET);
|
|
|
|
|
|
|
|
CertFreeCertificateContext(certs[0]);
|
|
|
|
CertFreeCertificateContext(certs[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(schannel)
|
|
|
|
{
|
2006-08-17 13:42:28 +02:00
|
|
|
InitFunctionPtrs();
|
|
|
|
|
|
|
|
if (pAcquireCredentialsHandleA && pFreeCredentialsHandle)
|
|
|
|
testAcquireSecurityContext();
|
|
|
|
|
|
|
|
if(secdll)
|
|
|
|
FreeLibrary(secdll);
|
2006-07-28 08:39:56 +02:00
|
|
|
}
|