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
|
|
|
|
*/
|
2014-07-24 19:51:52 +02:00
|
|
|
|
2006-07-28 08:39:56 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <windef.h>
|
2014-07-24 19:51:52 +02:00
|
|
|
#include <winsock2.h>
|
|
|
|
#include <ws2tcpip.h>
|
2015-07-02 17:50:00 +02:00
|
|
|
#include <stdio.h>
|
2006-07-28 08:39:56 +02:00
|
|
|
#define SECURITY_WIN32
|
|
|
|
#include <security.h>
|
|
|
|
#include <schannel.h>
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
2010-09-07 17:36:36 +02:00
|
|
|
static QUERY_CONTEXT_ATTRIBUTES_FN_A pQueryContextAttributesA;
|
2008-03-12 18:34:55 +01:00
|
|
|
|
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 };
|
|
|
|
|
2015-07-02 17:50:00 +02:00
|
|
|
static CHAR unisp_name_a[] = UNISP_NAME_A;
|
|
|
|
|
|
|
|
static const char *algid_to_str(ALG_ID alg)
|
|
|
|
{
|
|
|
|
static char buf[12];
|
|
|
|
switch(alg) {
|
|
|
|
#define X(x) case x: return #x
|
|
|
|
X(CALG_MD2);
|
|
|
|
X(CALG_MD4);
|
|
|
|
X(CALG_MD5);
|
|
|
|
X(CALG_SHA1); /* same as CALG_SHA */
|
|
|
|
X(CALG_MAC);
|
|
|
|
X(CALG_RSA_SIGN);
|
|
|
|
X(CALG_DSS_SIGN);
|
|
|
|
X(CALG_NO_SIGN);
|
|
|
|
X(CALG_RSA_KEYX);
|
|
|
|
X(CALG_DES);
|
|
|
|
X(CALG_3DES_112);
|
|
|
|
X(CALG_3DES);
|
|
|
|
X(CALG_DESX);
|
|
|
|
X(CALG_RC2);
|
|
|
|
X(CALG_RC4);
|
|
|
|
X(CALG_SEAL);
|
|
|
|
X(CALG_DH_SF);
|
|
|
|
X(CALG_DH_EPHEM);
|
|
|
|
X(CALG_AGREEDKEY_ANY);
|
|
|
|
X(CALG_KEA_KEYX);
|
|
|
|
X(CALG_HUGHES_MD5);
|
|
|
|
X(CALG_SKIPJACK);
|
|
|
|
X(CALG_TEK);
|
|
|
|
X(CALG_CYLINK_MEK);
|
|
|
|
X(CALG_SSL3_SHAMD5);
|
|
|
|
X(CALG_SSL3_MASTER);
|
|
|
|
X(CALG_SCHANNEL_MASTER_HASH);
|
|
|
|
X(CALG_SCHANNEL_MAC_KEY);
|
|
|
|
X(CALG_SCHANNEL_ENC_KEY);
|
|
|
|
X(CALG_PCT1_MASTER);
|
|
|
|
X(CALG_SSL2_MASTER);
|
|
|
|
X(CALG_TLS1_MASTER);
|
|
|
|
X(CALG_RC5);
|
|
|
|
X(CALG_HMAC);
|
|
|
|
X(CALG_TLS1PRF);
|
|
|
|
X(CALG_HASH_REPLACE_OWF);
|
|
|
|
X(CALG_AES_128);
|
|
|
|
X(CALG_AES_192);
|
|
|
|
X(CALG_AES_256);
|
|
|
|
X(CALG_AES);
|
|
|
|
X(CALG_SHA_256);
|
|
|
|
X(CALG_SHA_384);
|
|
|
|
X(CALG_SHA_512);
|
|
|
|
X(CALG_ECDH);
|
|
|
|
X(CALG_ECMQV);
|
|
|
|
X(CALG_ECDSA);
|
|
|
|
#undef X
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf(buf, "%x", alg);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void init_cred(SCHANNEL_CRED *cred)
|
|
|
|
{
|
|
|
|
cred->dwVersion = SCHANNEL_CRED_VERSION;
|
|
|
|
cred->cCreds = 0;
|
|
|
|
cred->paCred = 0;
|
|
|
|
cred->hRootStore = NULL;
|
|
|
|
cred->cMappers = 0;
|
|
|
|
cred->aphMappers = NULL;
|
|
|
|
cred->cSupportedAlgs = 0;
|
|
|
|
cred->palgSupportedAlgs = NULL;
|
|
|
|
cred->grbitEnabledProtocols = 0;
|
|
|
|
cred->dwMinimumCipherStrength = 0;
|
|
|
|
cred->dwMaximumCipherStrength = 0;
|
|
|
|
cred->dwSessionLifespan = 0;
|
|
|
|
cred->dwFlags = 0;
|
|
|
|
}
|
|
|
|
|
2008-03-12 18:35:10 +01:00
|
|
|
static void test_strength(PCredHandle handle)
|
|
|
|
{
|
|
|
|
SecPkgCred_CipherStrengths strength = {-1,-1};
|
|
|
|
SECURITY_STATUS st;
|
|
|
|
|
2017-01-13 19:54:22 +01:00
|
|
|
st = QueryCredentialsAttributesA(handle, SECPKG_ATTR_CIPHER_STRENGTHS, &strength);
|
2008-03-12 18:35:10 +01:00
|
|
|
ok(st == SEC_E_OK, "QueryCredentialsAttributesA failed: %u\n", GetLastError());
|
|
|
|
ok(strength.dwMinimumCipherStrength, "dwMinimumCipherStrength not changed\n");
|
|
|
|
ok(strength.dwMaximumCipherStrength, "dwMaximumCipherStrength not changed\n");
|
|
|
|
trace("strength %d - %d\n", strength.dwMinimumCipherStrength, strength.dwMaximumCipherStrength);
|
|
|
|
}
|
|
|
|
|
2013-03-27 12:22:48 +01:00
|
|
|
static void test_supported_protocols(CredHandle *handle, unsigned exprots)
|
|
|
|
{
|
|
|
|
SecPkgCred_SupportedProtocols protocols;
|
|
|
|
SECURITY_STATUS status;
|
|
|
|
|
2017-01-13 19:54:22 +01:00
|
|
|
status = QueryCredentialsAttributesA(handle, SECPKG_ATTR_SUPPORTED_PROTOCOLS, &protocols);
|
2013-03-27 12:22:48 +01:00
|
|
|
ok(status == SEC_E_OK, "QueryCredentialsAttributes failed: %08x\n", status);
|
|
|
|
|
|
|
|
if(exprots)
|
|
|
|
ok(protocols.grbitProtocol == exprots, "protocols.grbitProtocol = %x, expected %x\n", protocols.grbitProtocol, exprots);
|
|
|
|
|
|
|
|
trace("Supported protocols:\n");
|
|
|
|
|
|
|
|
#define X(flag, name) do { if(protocols.grbitProtocol & flag) { trace(name "\n"); protocols.grbitProtocol &= ~flag; } }while(0)
|
|
|
|
X(SP_PROT_SSL2_CLIENT, "SSL 2 client");
|
|
|
|
X(SP_PROT_SSL3_CLIENT, "SSL 3 client");
|
|
|
|
X(SP_PROT_TLS1_0_CLIENT, "TLS 1.0 client");
|
|
|
|
X(SP_PROT_TLS1_1_CLIENT, "TLS 1.1 client");
|
|
|
|
X(SP_PROT_TLS1_2_CLIENT, "TLS 1.2 client");
|
|
|
|
#undef X
|
|
|
|
|
|
|
|
if(protocols.grbitProtocol)
|
|
|
|
trace("Unknown flags: %x\n", protocols.grbitProtocol);
|
|
|
|
}
|
|
|
|
|
2015-07-02 17:50:00 +02:00
|
|
|
static void test_supported_algs(CredHandle *handle)
|
|
|
|
{
|
|
|
|
SecPkgCred_SupportedAlgs algs;
|
|
|
|
SECURITY_STATUS status;
|
|
|
|
unsigned i;
|
|
|
|
|
2017-01-13 19:54:22 +01:00
|
|
|
status = QueryCredentialsAttributesA(handle, SECPKG_ATTR_SUPPORTED_ALGS, &algs);
|
2015-07-02 17:50:00 +02:00
|
|
|
todo_wine ok(status == SEC_E_OK, "QueryCredentialsAttributes failed: %08x\n", status);
|
|
|
|
if(status != SEC_E_OK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
trace("Supported algorithms (%d):\n", algs.cSupportedAlgs);
|
|
|
|
for(i=0; i < algs.cSupportedAlgs; i++)
|
|
|
|
trace(" %s\n", algid_to_str(algs.palgSupportedAlgs[i]));
|
|
|
|
|
2017-01-13 19:54:22 +01:00
|
|
|
FreeContextBuffer(algs.palgSupportedAlgs);
|
2015-07-02 17:50:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_cread_attrs(void)
|
|
|
|
{
|
|
|
|
SCHANNEL_CRED schannel_cred;
|
|
|
|
SECURITY_STATUS status;
|
|
|
|
CredHandle cred;
|
|
|
|
|
2017-01-13 19:54:22 +01:00
|
|
|
status = AcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
|
2015-07-02 17:50:00 +02:00
|
|
|
NULL, NULL, NULL, NULL, &cred, NULL);
|
|
|
|
ok(status == SEC_E_OK, "AcquireCredentialsHandleA failed: %x\n", status);
|
|
|
|
|
|
|
|
test_supported_protocols(&cred, 0);
|
|
|
|
test_supported_algs(&cred);
|
|
|
|
|
2017-01-13 19:54:22 +01:00
|
|
|
status = QueryCredentialsAttributesA(&cred, SECPKG_ATTR_SUPPORTED_PROTOCOLS, NULL);
|
2015-07-02 17:50:00 +02:00
|
|
|
ok(status == SEC_E_INTERNAL_ERROR, "QueryCredentialsAttributes failed: %08x, expected SEC_E_INTERNAL_ERROR\n", status);
|
|
|
|
|
2017-01-13 19:54:22 +01:00
|
|
|
status = QueryCredentialsAttributesA(&cred, SECPKG_ATTR_SUPPORTED_ALGS, NULL);
|
2015-07-02 17:50:00 +02:00
|
|
|
ok(status == SEC_E_INTERNAL_ERROR, "QueryCredentialsAttributes failed: %08x, expected SEC_E_INTERNAL_ERROR\n", status);
|
|
|
|
|
2017-01-13 19:54:22 +01:00
|
|
|
FreeCredentialsHandle(&cred);
|
2015-07-02 17:50:00 +02:00
|
|
|
|
|
|
|
init_cred(&schannel_cred);
|
|
|
|
schannel_cred.grbitEnabledProtocols = SP_PROT_TLS1_CLIENT;
|
2017-01-13 19:54:22 +01:00
|
|
|
status = AcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
|
2015-07-02 17:50:00 +02:00
|
|
|
NULL, &schannel_cred, NULL, NULL, &cred, NULL);
|
|
|
|
ok(status == SEC_E_OK, "AcquireCredentialsHandleA failed: %x\n", status);
|
|
|
|
|
|
|
|
test_supported_protocols(&cred, SP_PROT_TLS1_CLIENT);
|
|
|
|
test_supported_algs(&cred);
|
|
|
|
|
2017-01-13 19:54:22 +01:00
|
|
|
FreeCredentialsHandle(&cred);
|
2015-07-02 17:50:00 +02:00
|
|
|
}
|
|
|
|
|
2006-07-28 08:39:56 +02:00
|
|
|
static void testAcquireSecurityContext(void)
|
|
|
|
{
|
2008-09-22 22:13:18 +02:00
|
|
|
BOOL has_schannel = FALSE;
|
|
|
|
SecPkgInfoA *package_info;
|
|
|
|
ULONG i;
|
2006-07-28 08:39:56 +02:00
|
|
|
SECURITY_STATUS st;
|
|
|
|
CredHandle cred;
|
2013-12-12 06:13:01 +01:00
|
|
|
SecPkgCredentials_NamesA names;
|
2006-07-28 08:39:56 +02:00
|
|
|
TimeStamp exp;
|
|
|
|
SCHANNEL_CRED schanCred;
|
|
|
|
PCCERT_CONTEXT certs[2];
|
|
|
|
HCRYPTPROV csp;
|
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-12-18 10:00:10 +01:00
|
|
|
|
2017-01-13 19:54:22 +01:00
|
|
|
if (SUCCEEDED(EnumerateSecurityPackagesA(&i, &package_info)))
|
2008-09-22 22:13:18 +02:00
|
|
|
{
|
|
|
|
while(i--)
|
|
|
|
{
|
|
|
|
if (!strcmp(package_info[i].Name, unisp_name_a))
|
|
|
|
{
|
|
|
|
has_schannel = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-01-13 19:54:22 +01:00
|
|
|
FreeContextBuffer(package_info);
|
2008-09-22 22:13:18 +02:00
|
|
|
}
|
|
|
|
if (!has_schannel)
|
|
|
|
{
|
|
|
|
skip("Schannel not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2016-06-14 18:29:24 +02:00
|
|
|
certs[0] = CertCreateCertificateContext(X509_ASN_ENCODING, bigCert, sizeof(bigCert));
|
|
|
|
certs[1] = CertCreateCertificateContext(X509_ASN_ENCODING, selfSignedCert, sizeof(selfSignedCert));
|
2006-07-28 08:39:56 +02:00
|
|
|
|
2009-10-02 11:09:31 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2016-06-10 18:53:17 +02:00
|
|
|
ret = CryptAcquireContextW(&csp, cspNameW, MS_DEF_PROV_W, PROV_RSA_FULL,
|
2006-07-28 08:39:56 +02:00
|
|
|
CRYPT_DELETEKEYSET);
|
2009-10-02 11:09:31 +02:00
|
|
|
if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
|
|
|
|
{
|
|
|
|
/* WinMe would crash on some tests */
|
|
|
|
win_skip("CryptAcquireContextW is not implemented\n");
|
|
|
|
return;
|
|
|
|
}
|
2006-07-28 08:39:56 +02:00
|
|
|
|
2017-01-13 19:54:22 +01:00
|
|
|
st = AcquireCredentialsHandleA(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 */
|
2017-01-13 19:54:22 +01:00
|
|
|
st = AcquireCredentialsHandleA(NULL, unisp_name_a, 0, NULL, NULL, NULL,
|
2006-10-31 09:28:31 +01:00
|
|
|
NULL, NULL, NULL);
|
2010-09-17 23:58:19 +02:00
|
|
|
ok(st == SEC_E_NO_CREDENTIALS, "Expected SEC_E_NO_CREDENTIALS, got %08x\n", st);
|
|
|
|
|
|
|
|
/* Crashes on WinNT */
|
2017-01-13 19:54:22 +01:00
|
|
|
st = AcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_BOTH, NULL,
|
2010-09-17 23:58:19 +02:00
|
|
|
NULL, NULL, NULL, NULL, NULL);
|
|
|
|
ok(st == SEC_E_NO_CREDENTIALS, "Expected SEC_E_NO_CREDENTIALS, got %08x\n", st);
|
|
|
|
|
2017-01-13 19:54:22 +01:00
|
|
|
st = AcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
|
2010-09-17 23:58:19 +02:00
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
ok(st == SEC_E_NO_CREDENTIALS, "Expected SEC_E_NO_CREDENTIALS, got %08x\n", st);
|
|
|
|
|
2006-10-31 09:28:31 +01:00
|
|
|
/* Crashes */
|
2017-01-13 19:54:22 +01:00
|
|
|
AcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
|
2006-10-31 09:28:31 +01:00
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
}
|
2017-01-13 19:54:22 +01:00
|
|
|
st = AcquireCredentialsHandleA(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);
|
2015-07-02 17:50:00 +02:00
|
|
|
if(st == SEC_E_OK)
|
2017-01-13 19:54:22 +01:00
|
|
|
FreeCredentialsHandle(&cred);
|
2006-07-28 08:39:56 +02:00
|
|
|
memset(&cred, 0, sizeof(cred));
|
2017-01-13 19:54:22 +01:00
|
|
|
st = AcquireCredentialsHandleA(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);
|
2008-05-22 00:39:17 +02:00
|
|
|
/* expriy is indeterminate in win2k3 */
|
2009-01-06 00:09:12 +01:00
|
|
|
trace("expiry: %08x%08x\n", exp.HighPart, exp.LowPart);
|
2013-12-12 06:13:01 +01:00
|
|
|
|
2017-01-13 19:54:22 +01:00
|
|
|
st = QueryCredentialsAttributesA(&cred, SECPKG_CRED_ATTR_NAMES, &names);
|
2013-12-12 06:13:01 +01:00
|
|
|
ok(st == SEC_E_NO_CREDENTIALS || st == SEC_E_UNSUPPORTED_FUNCTION /* before Vista */, "expected SEC_E_NO_CREDENTIALS, got %08x\n", st);
|
|
|
|
|
2017-01-13 19:54:22 +01:00
|
|
|
FreeCredentialsHandle(&cred);
|
2006-07-28 08:39:56 +02:00
|
|
|
|
|
|
|
/* Bad version in SCHANNEL_CRED */
|
|
|
|
memset(&schanCred, 0, sizeof(schanCred));
|
2017-01-13 19:54:22 +01:00
|
|
|
st = AcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, NULL, NULL);
|
2008-09-07 12:25:56 +02:00
|
|
|
ok(st == SEC_E_INTERNAL_ERROR ||
|
2010-09-17 23:58:19 +02:00
|
|
|
st == SEC_E_UNKNOWN_CREDENTIALS /* Vista/win2k8 */ ||
|
|
|
|
st == SEC_E_INVALID_TOKEN /* WinNT */, "st = %08x\n", st);
|
2017-01-13 19:54:22 +01:00
|
|
|
st = AcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, NULL, NULL);
|
2008-09-07 12:25:56 +02:00
|
|
|
ok(st == SEC_E_INTERNAL_ERROR ||
|
2010-09-17 23:58:19 +02:00
|
|
|
st == SEC_E_UNKNOWN_CREDENTIALS /* Vista/win2k8 */ ||
|
|
|
|
st == SEC_E_INVALID_TOKEN /* WinNT */, "st = %08x\n", st);
|
2006-07-28 08:39:56 +02:00
|
|
|
|
|
|
|
/* No cert in SCHANNEL_CRED succeeds for outbound.. */
|
|
|
|
schanCred.dwVersion = SCHANNEL_CRED_VERSION;
|
2017-01-13 19:54:22 +01:00
|
|
|
st = AcquireCredentialsHandleA(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);
|
2017-01-13 19:54:22 +01:00
|
|
|
FreeCredentialsHandle(&cred);
|
2006-07-28 08:39:56 +02:00
|
|
|
/* but fails for inbound. */
|
2017-01-13 19:54:22 +01:00
|
|
|
st = AcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
|
2008-07-30 22:50:46 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, &cred, NULL);
|
2008-09-07 12:25:56 +02:00
|
|
|
ok(st == SEC_E_NO_CREDENTIALS ||
|
|
|
|
st == SEC_E_OK /* Vista/win2k8 */,
|
|
|
|
"Expected SEC_E_NO_CREDENTIALS or SEC_E_OK, got %08x\n", st);
|
2006-07-28 08:39:56 +02:00
|
|
|
|
2006-10-31 09:28:31 +01:00
|
|
|
if (0)
|
|
|
|
{
|
|
|
|
/* Crashes with bad paCred pointer */
|
|
|
|
schanCred.cCreds = 1;
|
2017-01-13 19:54:22 +01:00
|
|
|
AcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
|
2006-10-31 09:28:31 +01:00
|
|
|
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];
|
2017-01-13 19:54:22 +01:00
|
|
|
st = AcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, NULL, NULL);
|
2010-09-17 23:58:19 +02:00
|
|
|
ok(st == SEC_E_UNKNOWN_CREDENTIALS ||
|
|
|
|
st == SEC_E_NO_CREDENTIALS ||
|
|
|
|
st == SEC_E_INVALID_TOKEN /* WinNT */, "st = %08x\n", st);
|
2017-01-13 19:54:22 +01:00
|
|
|
st = AcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, NULL, NULL);
|
2010-09-17 23:58:19 +02:00
|
|
|
ok(st == SEC_E_UNKNOWN_CREDENTIALS ||
|
|
|
|
st == SEC_E_NO_CREDENTIALS ||
|
|
|
|
st == SEC_E_INVALID_TOKEN /* WinNT */, "st = %08x\n", st);
|
2006-07-28 08:39:56 +02:00
|
|
|
|
|
|
|
/* 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];
|
2017-01-13 19:54:22 +01:00
|
|
|
st = AcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, &cred, NULL);
|
2008-09-11 09:34:01 +02:00
|
|
|
ok(st == SEC_E_UNKNOWN_CREDENTIALS || st == SEC_E_NO_CREDENTIALS ||
|
|
|
|
st == SEC_E_INTERNAL_ERROR, /* win2k */
|
|
|
|
"Expected SEC_E_UNKNOWN_CREDENTIALS, SEC_E_NO_CREDENTIALS "
|
|
|
|
"or SEC_E_INTERNAL_ERROR, got %08x\n", st);
|
2017-01-13 19:54:22 +01:00
|
|
|
st = AcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, NULL, NULL);
|
2008-09-11 09:34:01 +02:00
|
|
|
ok(st == SEC_E_UNKNOWN_CREDENTIALS || st == SEC_E_NO_CREDENTIALS ||
|
|
|
|
st == SEC_E_INTERNAL_ERROR, /* win2k */
|
|
|
|
"Expected SEC_E_UNKNOWN_CREDENTIALS, SEC_E_NO_CREDENTIALS "
|
|
|
|
"or SEC_E_INTERNAL_ERROR, got %08x\n", st);
|
2006-07-28 08:39:56 +02:00
|
|
|
|
|
|
|
/* Good cert, with CRYPT_KEY_PROV_INFO set before it's had a key loaded. */
|
2016-06-14 18:29:24 +02:00
|
|
|
ret = CertSetCertificateContextProperty(certs[1],
|
|
|
|
CERT_KEY_PROV_INFO_PROP_ID, 0, &keyProvInfo);
|
|
|
|
schanCred.dwVersion = SCH_CRED_V3;
|
|
|
|
ok(ret, "CertSetCertificateContextProperty failed: %08x\n", GetLastError());
|
2017-01-13 19:54:22 +01:00
|
|
|
st = AcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
|
2016-06-14 18:29:24 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, &cred, NULL);
|
|
|
|
ok(st == SEC_E_UNKNOWN_CREDENTIALS || st == SEC_E_INTERNAL_ERROR /* WinNT */,
|
|
|
|
"Expected SEC_E_UNKNOWN_CREDENTIALS or SEC_E_INTERNAL_ERROR, got %08x\n", st);
|
2017-01-13 19:54:22 +01:00
|
|
|
st = AcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
|
2016-06-14 18:29:24 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, &cred, NULL);
|
|
|
|
ok(st == SEC_E_UNKNOWN_CREDENTIALS || st == SEC_E_INTERNAL_ERROR /* WinNT */,
|
|
|
|
"Expected SEC_E_UNKNOWN_CREDENTIALS or SEC_E_INTERNAL_ERROR, got %08x\n", st);
|
2006-07-28 08:39:56 +02:00
|
|
|
|
2016-06-10 18:53:17 +02:00
|
|
|
ret = CryptAcquireContextW(&csp, cspNameW, MS_DEF_PROV_W, PROV_RSA_FULL,
|
2006-07-28 08:39:56 +02:00
|
|
|
CRYPT_NEWKEYSET);
|
2006-10-10 23:47:35 +02:00
|
|
|
ok(ret, "CryptAcquireContextW failed: %08x\n", GetLastError());
|
2007-12-18 10:00:10 +01:00
|
|
|
ret = 0;
|
2016-06-10 18:53:17 +02:00
|
|
|
|
|
|
|
ret = CryptImportKey(csp, privKey, sizeof(privKey), 0, 0, &key);
|
|
|
|
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 */
|
2017-01-13 19:54:22 +01:00
|
|
|
AcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
|
2006-10-31 09:28:31 +01:00
|
|
|
NULL, &schanCred, NULL, NULL, NULL, NULL);
|
2010-09-17 23:58:19 +02:00
|
|
|
|
|
|
|
/* Crashes on WinNT */
|
|
|
|
/* Good cert with private key, bogus version */
|
|
|
|
schanCred.dwVersion = SCH_CRED_V1;
|
2017-01-13 19:54:22 +01:00
|
|
|
st = AcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
|
2010-09-17 23:58:19 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, &cred, NULL);
|
|
|
|
ok(st == SEC_E_INTERNAL_ERROR ||
|
|
|
|
st == SEC_E_UNKNOWN_CREDENTIALS /* Vista/win2k8 */,
|
|
|
|
"Expected SEC_E_INTERNAL_ERROR or SEC_E_UNKNOWN_CREDENTIALS, got %08x\n", st);
|
2017-01-13 19:54:22 +01:00
|
|
|
st = AcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
|
2010-09-17 23:58:19 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, &cred, NULL);
|
|
|
|
ok(st == SEC_E_INTERNAL_ERROR ||
|
|
|
|
st == SEC_E_UNKNOWN_CREDENTIALS /* Vista/win2k8 */,
|
|
|
|
"Expected SEC_E_INTERNAL_ERROR or SEC_E_UNKNOWN_CREDENTIALS, got %08x\n", st);
|
|
|
|
schanCred.dwVersion = SCH_CRED_V2;
|
2017-01-13 19:54:22 +01:00
|
|
|
st = AcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
|
2010-09-17 23:58:19 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, &cred, NULL);
|
|
|
|
ok(st == SEC_E_INTERNAL_ERROR ||
|
|
|
|
st == SEC_E_UNKNOWN_CREDENTIALS /* Vista/win2k8 */,
|
|
|
|
"Expected SEC_E_INTERNAL_ERROR or SEC_E_UNKNOWN_CREDENTIALS, got %08x\n", st);
|
2017-01-13 19:54:22 +01:00
|
|
|
st = AcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
|
2010-09-17 23:58:19 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, &cred, NULL);
|
|
|
|
ok(st == SEC_E_INTERNAL_ERROR ||
|
|
|
|
st == SEC_E_UNKNOWN_CREDENTIALS /* Vista/win2k8 */,
|
|
|
|
"Expected SEC_E_INTERNAL_ERROR or SEC_E_UNKNOWN_CREDENTIALS, got %08x\n", st);
|
2006-10-31 09:28:31 +01:00
|
|
|
}
|
2006-07-28 08:39:56 +02:00
|
|
|
|
|
|
|
/* Succeeds on V3 or higher */
|
|
|
|
schanCred.dwVersion = SCH_CRED_V3;
|
2017-01-13 19:54:22 +01:00
|
|
|
st = AcquireCredentialsHandleA(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);
|
2017-01-13 19:54:22 +01:00
|
|
|
FreeCredentialsHandle(&cred);
|
|
|
|
st = AcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, &cred, NULL);
|
2008-05-22 00:39:17 +02:00
|
|
|
ok(st == SEC_E_OK ||
|
|
|
|
st == SEC_E_UNKNOWN_CREDENTIALS, /* win2k3 */
|
|
|
|
"AcquireCredentialsHandleA failed: %08x\n", st);
|
2017-01-13 19:54:22 +01:00
|
|
|
FreeCredentialsHandle(&cred);
|
2006-07-28 08:39:56 +02:00
|
|
|
schanCred.dwVersion = SCHANNEL_CRED_VERSION;
|
2017-01-13 19:54:22 +01:00
|
|
|
st = AcquireCredentialsHandleA(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);
|
2017-01-13 19:54:22 +01:00
|
|
|
FreeCredentialsHandle(&cred);
|
|
|
|
st = AcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, &cred, NULL);
|
2008-05-22 00:39:17 +02:00
|
|
|
ok(st == SEC_E_OK ||
|
|
|
|
st == SEC_E_UNKNOWN_CREDENTIALS, /* win2k3 */
|
|
|
|
"AcquireCredentialsHandleA failed: %08x\n", st);
|
|
|
|
if (st == SEC_E_OK) test_strength(&cred);
|
2017-01-13 19:54:22 +01:00
|
|
|
FreeCredentialsHandle(&cred);
|
2006-07-28 08:39:56 +02:00
|
|
|
|
|
|
|
/* How about more than one cert? */
|
|
|
|
schanCred.cCreds = 2;
|
|
|
|
schanCred.paCred = certs;
|
2017-01-13 19:54:22 +01:00
|
|
|
st = AcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, &cred, NULL);
|
2008-09-07 12:25:56 +02:00
|
|
|
ok(st == SEC_E_UNKNOWN_CREDENTIALS ||
|
2010-09-17 23:58:19 +02:00
|
|
|
st == SEC_E_NO_CREDENTIALS /* Vista/win2k8 */ ||
|
|
|
|
st == SEC_E_INVALID_TOKEN /* WinNT */, "st = %08x\n", st);
|
2017-01-13 19:54:22 +01:00
|
|
|
st = AcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, &cred, NULL);
|
2008-09-07 12:25:56 +02:00
|
|
|
ok(st == SEC_E_UNKNOWN_CREDENTIALS ||
|
2010-09-17 23:58:19 +02:00
|
|
|
st == SEC_E_NO_CREDENTIALS ||
|
|
|
|
st == SEC_E_INVALID_TOKEN /* WinNT */, "st = %08x\n", st);
|
2006-07-28 08:39:56 +02:00
|
|
|
tmp = certs[0];
|
|
|
|
certs[0] = certs[1];
|
|
|
|
certs[1] = tmp;
|
2017-01-13 19:54:22 +01:00
|
|
|
st = AcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND,
|
2006-07-28 08:39:56 +02:00
|
|
|
NULL, &schanCred, NULL, NULL, &cred, NULL);
|
2008-09-07 12:25:56 +02:00
|
|
|
ok(st == SEC_E_UNKNOWN_CREDENTIALS ||
|
2010-09-17 23:58:19 +02:00
|
|
|
st == SEC_E_NO_CREDENTIALS ||
|
|
|
|
st == SEC_E_INVALID_TOKEN /* WinNT */, "st = %08x\n", st);
|
2017-01-13 19:54:22 +01:00
|
|
|
st = AcquireCredentialsHandleA(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? */
|
|
|
|
|
2016-06-10 18:53:17 +02:00
|
|
|
CryptDestroyKey(key);
|
2006-07-28 08:39:56 +02:00
|
|
|
}
|
|
|
|
|
2016-06-10 18:53:17 +02:00
|
|
|
CryptReleaseContext(csp, 0);
|
|
|
|
CryptAcquireContextW(&csp, cspNameW, MS_DEF_PROV_W, PROV_RSA_FULL, CRYPT_DELETEKEYSET);
|
2006-07-28 08:39:56 +02:00
|
|
|
|
2016-06-14 18:29:24 +02:00
|
|
|
CertFreeCertificateContext(certs[0]);
|
|
|
|
CertFreeCertificateContext(certs[1]);
|
2006-07-28 08:39:56 +02:00
|
|
|
}
|
|
|
|
|
2013-01-21 15:04:05 +01:00
|
|
|
static void test_remote_cert(PCCERT_CONTEXT remote_cert)
|
|
|
|
{
|
|
|
|
PCCERT_CONTEXT iter = NULL;
|
|
|
|
BOOL incl_remote = FALSE;
|
|
|
|
unsigned cert_cnt = 0;
|
|
|
|
|
|
|
|
ok(remote_cert->hCertStore != NULL, "hCertStore == NULL\n");
|
|
|
|
|
2016-06-14 18:29:24 +02:00
|
|
|
while((iter = CertEnumCertificatesInStore(remote_cert->hCertStore, iter))) {
|
2013-01-21 15:04:05 +01:00
|
|
|
if(iter == remote_cert)
|
|
|
|
incl_remote = TRUE;
|
|
|
|
cert_cnt++;
|
|
|
|
}
|
|
|
|
|
2016-05-24 16:11:08 +02:00
|
|
|
ok(cert_cnt == 2 || cert_cnt == 3, "cert_cnt = %u\n", cert_cnt);
|
2013-01-21 15:04:05 +01:00
|
|
|
ok(incl_remote, "context does not contain cert itself\n");
|
|
|
|
}
|
|
|
|
|
2013-07-30 13:01:11 +02:00
|
|
|
static const char http_request[] = "HEAD /test.html HTTP/1.1\r\nHost: www.winehq.org\r\nConnection: close\r\n\r\n";
|
2010-09-07 17:36:36 +02:00
|
|
|
|
|
|
|
static void init_buffers(SecBufferDesc *desc, unsigned count, unsigned size)
|
|
|
|
{
|
|
|
|
desc->ulVersion = SECBUFFER_VERSION;
|
|
|
|
desc->cBuffers = count;
|
|
|
|
desc->pBuffers = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, count*sizeof(SecBuffer));
|
|
|
|
|
|
|
|
desc->pBuffers[0].cbBuffer = size;
|
|
|
|
desc->pBuffers[0].pvBuffer = HeapAlloc(GetProcessHeap(), 0, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void reset_buffers(SecBufferDesc *desc)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for (i = 0; i < desc->cBuffers; ++i)
|
|
|
|
{
|
|
|
|
desc->pBuffers[i].BufferType = SECBUFFER_EMPTY;
|
|
|
|
if (i > 0)
|
|
|
|
{
|
|
|
|
desc->pBuffers[i].cbBuffer = 0;
|
|
|
|
desc->pBuffers[i].pvBuffer = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_buffers(SecBufferDesc *desc)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, desc->pBuffers[0].pvBuffer);
|
|
|
|
HeapFree(GetProcessHeap(), 0, desc->pBuffers);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int receive_data(SOCKET sock, SecBuffer *buf)
|
|
|
|
{
|
|
|
|
unsigned received = 0;
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
unsigned char *data = buf->pvBuffer;
|
|
|
|
unsigned expected = 0;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = recv(sock, (char *)data+received, buf->cbBuffer-received, 0);
|
|
|
|
if (ret == -1)
|
|
|
|
{
|
|
|
|
skip("recv failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else if(ret == 0)
|
|
|
|
{
|
|
|
|
skip("connection closed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
received += ret;
|
|
|
|
|
|
|
|
while (expected < received)
|
|
|
|
{
|
|
|
|
unsigned frame_size = 5 + ((data[3]<<8) | data[4]);
|
|
|
|
expected += frame_size;
|
|
|
|
data += frame_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (expected == received)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf->cbBuffer = received;
|
|
|
|
|
|
|
|
return received;
|
|
|
|
}
|
|
|
|
|
2017-01-13 19:57:48 +01:00
|
|
|
static void test_InitializeSecurityContext(void)
|
|
|
|
{
|
|
|
|
SCHANNEL_CRED cred;
|
|
|
|
CredHandle cred_handle;
|
|
|
|
CtxtHandle context;
|
|
|
|
SECURITY_STATUS status;
|
|
|
|
SecBuffer out_buffer = {1000, SECBUFFER_TOKEN, NULL};
|
|
|
|
SecBuffer in_buffer = {0, SECBUFFER_EMPTY, NULL};
|
|
|
|
SecBufferDesc out_buffers = {SECBUFFER_VERSION, 1, &out_buffer};
|
|
|
|
SecBufferDesc in_buffers = {SECBUFFER_VERSION, 1, &in_buffer};
|
|
|
|
ULONG attrs;
|
|
|
|
|
|
|
|
init_cred(&cred);
|
|
|
|
cred.grbitEnabledProtocols = SP_PROT_TLS1_CLIENT;
|
|
|
|
cred.dwFlags = SCH_CRED_NO_DEFAULT_CREDS|SCH_CRED_MANUAL_CRED_VALIDATION;
|
|
|
|
status = AcquireCredentialsHandleA(NULL, (SEC_CHAR *)UNISP_NAME_A, SECPKG_CRED_OUTBOUND, NULL,
|
|
|
|
&cred, NULL, NULL, &cred_handle, NULL);
|
|
|
|
ok(status == SEC_E_OK, "AcquireCredentialsHandleA failed: %08x\n", status);
|
|
|
|
if (status != SEC_E_OK) return;
|
|
|
|
|
|
|
|
status = InitializeSecurityContextA(&cred_handle, NULL, (SEC_CHAR *)"localhost",
|
|
|
|
ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM|ISC_REQ_ALLOCATE_MEMORY,
|
|
|
|
0, 0, &in_buffers, 0, &context, &out_buffers, &attrs, NULL);
|
|
|
|
ok(status == SEC_I_CONTINUE_NEEDED, "Expected SEC_I_CONTINUE_NEEDED, got %08x\n", status);
|
|
|
|
|
|
|
|
FreeContextBuffer(out_buffer.pvBuffer);
|
|
|
|
DeleteSecurityContext(&context);
|
|
|
|
FreeCredentialsHandle(&cred_handle);
|
|
|
|
}
|
|
|
|
|
2010-09-07 17:36:36 +02:00
|
|
|
static void test_communication(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
WSADATA wsa_data;
|
|
|
|
SOCKET sock;
|
|
|
|
struct hostent *host;
|
|
|
|
struct sockaddr_in addr;
|
|
|
|
|
|
|
|
SECURITY_STATUS status;
|
|
|
|
ULONG attrs;
|
|
|
|
|
|
|
|
SCHANNEL_CRED cred;
|
|
|
|
CredHandle cred_handle;
|
|
|
|
CtxtHandle context;
|
2013-12-12 06:13:01 +01:00
|
|
|
SecPkgCredentials_NamesA names;
|
2010-09-07 17:36:36 +02:00
|
|
|
SecPkgContext_StreamSizes sizes;
|
2013-02-27 15:36:18 +01:00
|
|
|
SecPkgContext_ConnectionInfo conn_info;
|
2017-04-20 13:58:37 +02:00
|
|
|
SecPkgContext_KeyInfoA key_info;
|
2013-01-21 15:04:05 +01:00
|
|
|
CERT_CONTEXT *cert;
|
2017-12-14 10:19:06 +01:00
|
|
|
SecPkgContext_NegotiationInfoA info;
|
2010-09-07 17:36:36 +02:00
|
|
|
|
|
|
|
SecBufferDesc buffers[2];
|
|
|
|
SecBuffer *buf;
|
|
|
|
unsigned buf_size = 4000;
|
|
|
|
unsigned char *data;
|
|
|
|
unsigned data_size;
|
|
|
|
|
2017-01-13 19:54:22 +01:00
|
|
|
if (!pQueryContextAttributesA)
|
2010-09-07 17:36:36 +02:00
|
|
|
{
|
2017-01-13 19:54:22 +01:00
|
|
|
win_skip("Required secur32 functions not available\n");
|
2010-09-07 17:36:36 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-30 13:01:11 +02:00
|
|
|
/* Create a socket and connect to www.winehq.org */
|
2010-09-07 17:36:36 +02:00
|
|
|
ret = WSAStartup(0x0202, &wsa_data);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
skip("Can't init winsock 2.2\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-30 13:01:11 +02:00
|
|
|
host = gethostbyname("www.winehq.org");
|
2010-09-07 17:36:36 +02:00
|
|
|
if (!host)
|
|
|
|
{
|
2013-07-30 13:01:11 +02:00
|
|
|
skip("Can't resolve www.winehq.org\n");
|
2010-09-07 17:36:36 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
addr.sin_family = host->h_addrtype;
|
|
|
|
addr.sin_addr = *(struct in_addr *)host->h_addr_list[0];
|
|
|
|
addr.sin_port = htons(443);
|
|
|
|
sock = socket(host->h_addrtype, SOCK_STREAM, 0);
|
|
|
|
if (sock == SOCKET_ERROR)
|
|
|
|
{
|
|
|
|
skip("Can't create socket\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = connect(sock, (struct sockaddr *)&addr, sizeof(addr));
|
|
|
|
if (ret == SOCKET_ERROR)
|
|
|
|
{
|
2013-07-30 13:01:11 +02:00
|
|
|
skip("Can't connect to www.winehq.org\n");
|
2010-09-07 17:36:36 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create client credentials */
|
|
|
|
init_cred(&cred);
|
2015-07-02 17:50:00 +02:00
|
|
|
cred.grbitEnabledProtocols = SP_PROT_TLS1_CLIENT;
|
2010-09-07 17:36:36 +02:00
|
|
|
cred.dwFlags = SCH_CRED_NO_DEFAULT_CREDS|SCH_CRED_MANUAL_CRED_VALIDATION;
|
|
|
|
|
2017-01-13 19:54:22 +01:00
|
|
|
status = AcquireCredentialsHandleA(NULL, (SEC_CHAR *)UNISP_NAME_A, SECPKG_CRED_OUTBOUND, NULL,
|
2010-09-07 17:36:36 +02:00
|
|
|
&cred, NULL, NULL, &cred_handle, NULL);
|
|
|
|
ok(status == SEC_E_OK, "AcquireCredentialsHandleA failed: %08x\n", status);
|
2010-12-02 03:28:50 +01:00
|
|
|
if (status != SEC_E_OK) return;
|
2010-09-07 17:36:36 +02:00
|
|
|
|
|
|
|
/* Initialize the connection */
|
|
|
|
init_buffers(&buffers[0], 4, buf_size);
|
|
|
|
init_buffers(&buffers[1], 4, buf_size);
|
|
|
|
|
|
|
|
buffers[0].pBuffers[0].BufferType = SECBUFFER_TOKEN;
|
2017-01-13 19:54:22 +01:00
|
|
|
status = InitializeSecurityContextA(&cred_handle, NULL, (SEC_CHAR *)"localhost",
|
2010-09-07 17:36:36 +02:00
|
|
|
ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM,
|
|
|
|
0, 0, NULL, 0, &context, &buffers[0], &attrs, NULL);
|
|
|
|
ok(status == SEC_I_CONTINUE_NEEDED, "Expected SEC_I_CONTINUE_NEEDED, got %08x\n", status);
|
|
|
|
|
2010-09-17 10:18:41 +02:00
|
|
|
buffers[1].cBuffers = 1;
|
|
|
|
buffers[1].pBuffers[0].BufferType = SECBUFFER_TOKEN;
|
2013-08-27 22:17:35 +02:00
|
|
|
buffers[0].pBuffers[0].cbBuffer = 1;
|
2015-01-22 14:23:38 +01:00
|
|
|
memset(buffers[1].pBuffers[0].pvBuffer, 0xfa, buf_size);
|
2017-01-13 19:54:22 +01:00
|
|
|
status = InitializeSecurityContextA(&cred_handle, &context, (SEC_CHAR *)"localhost",
|
2015-01-22 14:23:38 +01:00
|
|
|
ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM,
|
|
|
|
0, 0, &buffers[1], 0, NULL, &buffers[0], &attrs, NULL);
|
|
|
|
todo_wine
|
|
|
|
ok(status == SEC_E_INVALID_TOKEN, "Expected SEC_E_INVALID_TOKEN, got %08x\n", status);
|
|
|
|
todo_wine
|
|
|
|
ok(buffers[0].pBuffers[0].cbBuffer == 0, "Output buffer size was not set to 0.\n");
|
|
|
|
|
|
|
|
buffers[1].cBuffers = 1;
|
|
|
|
buffers[1].pBuffers[0].BufferType = SECBUFFER_TOKEN;
|
|
|
|
buffers[0].pBuffers[0].cbBuffer = 1;
|
|
|
|
memset(buffers[1].pBuffers[0].pvBuffer, 0, buf_size);
|
2017-01-13 19:54:22 +01:00
|
|
|
status = InitializeSecurityContextA(&cred_handle, &context, (SEC_CHAR *)"localhost",
|
2010-09-17 10:18:41 +02:00
|
|
|
ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM,
|
|
|
|
0, 0, &buffers[1], 0, NULL, &buffers[0], &attrs, NULL);
|
|
|
|
ok(status == SEC_E_INVALID_TOKEN, "Expected SEC_E_INVALID_TOKEN, got %08x\n", status);
|
2013-08-27 22:17:35 +02:00
|
|
|
todo_wine
|
|
|
|
ok(buffers[0].pBuffers[0].cbBuffer == 0, "Output buffer size was not set to 0.\n");
|
|
|
|
|
2015-01-22 14:23:38 +01:00
|
|
|
buffers[0].pBuffers[0].cbBuffer = 0;
|
2017-01-13 19:54:22 +01:00
|
|
|
status = InitializeSecurityContextA(&cred_handle, &context, (SEC_CHAR *)"localhost",
|
2013-08-27 22:17:35 +02:00
|
|
|
ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM,
|
|
|
|
0, 0, &buffers[1], 0, NULL, &buffers[0], &attrs, NULL);
|
|
|
|
todo_wine
|
|
|
|
ok(status == SEC_E_INSUFFICIENT_MEMORY || status == SEC_E_INVALID_TOKEN,
|
|
|
|
"Expected SEC_E_INSUFFICIENT_MEMORY or SEC_E_INVALID_TOKEN, got %08x\n", status);
|
2010-09-17 10:18:41 +02:00
|
|
|
|
|
|
|
buffers[0].pBuffers[0].cbBuffer = buf_size;
|
|
|
|
|
2017-01-13 19:54:22 +01:00
|
|
|
status = InitializeSecurityContextA(&cred_handle, NULL, (SEC_CHAR *)"localhost",
|
2010-09-17 10:18:41 +02:00
|
|
|
ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM,
|
|
|
|
0, 0, NULL, 0, &context, &buffers[0], &attrs, NULL);
|
|
|
|
ok(status == SEC_I_CONTINUE_NEEDED, "Expected SEC_I_CONTINUE_NEEDED, got %08x\n", status);
|
|
|
|
|
2012-06-26 16:03:49 +02:00
|
|
|
buf = &buffers[0].pBuffers[0];
|
|
|
|
send(sock, buf->pvBuffer, buf->cbBuffer, 0);
|
|
|
|
buf->cbBuffer = buf_size;
|
|
|
|
|
2017-01-13 19:54:22 +01:00
|
|
|
status = InitializeSecurityContextA(&cred_handle, &context, (SEC_CHAR *)"localhost",
|
2012-06-26 16:03:49 +02:00
|
|
|
ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM,
|
|
|
|
0, 0, NULL, 0, NULL, &buffers[0], &attrs, NULL);
|
|
|
|
ok(status == SEC_E_INCOMPLETE_MESSAGE, "Got unexpected status %#x.\n", status);
|
|
|
|
ok(buffers[0].pBuffers[0].cbBuffer == buf_size, "Output buffer size changed.\n");
|
|
|
|
ok(buffers[0].pBuffers[0].BufferType == SECBUFFER_TOKEN, "Output buffer type changed.\n");
|
|
|
|
|
|
|
|
buffers[1].cBuffers = 4;
|
|
|
|
buffers[1].pBuffers[0].cbBuffer = 0;
|
|
|
|
|
2017-01-13 19:54:22 +01:00
|
|
|
status = InitializeSecurityContextA(&cred_handle, &context, (SEC_CHAR *)"localhost",
|
2012-06-26 16:03:49 +02:00
|
|
|
ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM,
|
|
|
|
0, 0, &buffers[1], 0, NULL, &buffers[0], &attrs, NULL);
|
|
|
|
ok(status == SEC_E_INCOMPLETE_MESSAGE, "Got unexpected status %#x.\n", status);
|
|
|
|
ok(buffers[0].pBuffers[0].cbBuffer == buf_size, "Output buffer size changed.\n");
|
|
|
|
ok(buffers[0].pBuffers[0].BufferType == SECBUFFER_TOKEN, "Output buffer type changed.\n");
|
|
|
|
|
|
|
|
buf = &buffers[1].pBuffers[0];
|
|
|
|
buf->cbBuffer = buf_size;
|
|
|
|
ret = receive_data(sock, buf);
|
|
|
|
if (ret == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
buffers[1].pBuffers[0].cbBuffer = 4;
|
2017-01-13 19:54:22 +01:00
|
|
|
status = InitializeSecurityContextA(&cred_handle, &context, (SEC_CHAR *)"localhost",
|
2012-06-26 16:03:49 +02:00
|
|
|
ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM,
|
|
|
|
0, 0, &buffers[1], 0, NULL, &buffers[0], &attrs, NULL);
|
2017-01-16 16:11:16 +01:00
|
|
|
ok(status == SEC_E_INCOMPLETE_MESSAGE || status == SEC_E_INVALID_TOKEN,
|
|
|
|
"Got unexpected status %#x.\n", status);
|
2012-06-26 16:03:49 +02:00
|
|
|
ok(buffers[0].pBuffers[0].cbBuffer == buf_size, "Output buffer size changed.\n");
|
|
|
|
ok(buffers[0].pBuffers[0].BufferType == SECBUFFER_TOKEN, "Output buffer type changed.\n");
|
|
|
|
|
|
|
|
buffers[1].pBuffers[0].cbBuffer = 5;
|
2017-01-13 19:54:22 +01:00
|
|
|
status = InitializeSecurityContextA(&cred_handle, &context, (SEC_CHAR *)"localhost",
|
2012-06-26 16:03:49 +02:00
|
|
|
ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM,
|
|
|
|
0, 0, &buffers[1], 0, NULL, &buffers[0], &attrs, NULL);
|
2017-01-16 16:11:16 +01:00
|
|
|
ok(status == SEC_E_INCOMPLETE_MESSAGE || status == SEC_E_INVALID_TOKEN,
|
|
|
|
"Got unexpected status %#x.\n", status);
|
2012-06-26 16:03:49 +02:00
|
|
|
ok(buffers[0].pBuffers[0].cbBuffer == buf_size, "Output buffer size changed.\n");
|
|
|
|
ok(buffers[0].pBuffers[0].BufferType == SECBUFFER_TOKEN, "Output buffer type changed.\n");
|
|
|
|
|
|
|
|
buffers[1].pBuffers[0].cbBuffer = ret;
|
2017-01-13 19:54:22 +01:00
|
|
|
status = InitializeSecurityContextA(&cred_handle, &context, (SEC_CHAR *)"localhost",
|
2012-06-26 16:03:49 +02:00
|
|
|
ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM,
|
|
|
|
0, 0, &buffers[1], 0, NULL, &buffers[0], &attrs, NULL);
|
|
|
|
buffers[1].pBuffers[0].cbBuffer = buf_size;
|
2010-09-07 17:36:36 +02:00
|
|
|
while (status == SEC_I_CONTINUE_NEEDED)
|
|
|
|
{
|
|
|
|
buf = &buffers[0].pBuffers[0];
|
|
|
|
send(sock, buf->pvBuffer, buf->cbBuffer, 0);
|
|
|
|
buf->cbBuffer = buf_size;
|
|
|
|
|
|
|
|
buf = &buffers[1].pBuffers[0];
|
|
|
|
ret = receive_data(sock, buf);
|
|
|
|
if (ret == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
buf->BufferType = SECBUFFER_TOKEN;
|
|
|
|
|
2017-01-13 19:54:22 +01:00
|
|
|
status = InitializeSecurityContextA(&cred_handle, &context, (SEC_CHAR *)"localhost",
|
2010-09-07 17:36:36 +02:00
|
|
|
ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM,
|
|
|
|
0, 0, &buffers[1], 0, NULL, &buffers[0], &attrs, NULL);
|
|
|
|
buffers[1].pBuffers[0].cbBuffer = buf_size;
|
|
|
|
}
|
|
|
|
|
2010-09-17 23:58:19 +02:00
|
|
|
ok(status == SEC_E_OK || broken(status == SEC_E_INVALID_TOKEN) /* WinNT */,
|
|
|
|
"InitializeSecurityContext failed: %08x\n", status);
|
|
|
|
if(status != SEC_E_OK) {
|
|
|
|
win_skip("Handshake failed\n");
|
|
|
|
return;
|
|
|
|
}
|
2010-09-07 17:36:36 +02:00
|
|
|
|
2017-01-13 19:54:22 +01:00
|
|
|
status = QueryCredentialsAttributesA(&cred_handle, SECPKG_CRED_ATTR_NAMES, &names);
|
2013-12-12 06:13:01 +01:00
|
|
|
ok(status == SEC_E_NO_CREDENTIALS || status == SEC_E_UNSUPPORTED_FUNCTION /* before Vista */, "expected SEC_E_NO_CREDENTIALS, got %08x\n", status);
|
|
|
|
|
2013-01-21 15:04:05 +01:00
|
|
|
status = pQueryContextAttributesA(&context, SECPKG_ATTR_REMOTE_CERT_CONTEXT, (void*)&cert);
|
|
|
|
ok(status == SEC_E_OK, "QueryContextAttributesW(SECPKG_ATTR_REMOTE_CERT_CONTEXT) failed: %08x\n", status);
|
|
|
|
if(status == SEC_E_OK) {
|
2017-03-02 13:45:53 +01:00
|
|
|
SecPkgContext_Bindings bindings = {0xdeadbeef, (void*)0xdeadbeef};
|
|
|
|
|
2013-01-21 15:04:05 +01:00
|
|
|
test_remote_cert(cert);
|
2017-03-02 13:45:53 +01:00
|
|
|
|
|
|
|
status = pQueryContextAttributesA(&context, SECPKG_ATTR_ENDPOINT_BINDINGS, &bindings);
|
|
|
|
ok(status == SEC_E_OK || broken(status == SEC_E_UNSUPPORTED_FUNCTION),
|
|
|
|
"QueryContextAttributesW(SECPKG_ATTR_ENDPOINT_BINDINGS) failed: %08x\n", status);
|
|
|
|
if(status == SEC_E_OK) {
|
|
|
|
static const char prefix[] = "tls-server-end-point:";
|
|
|
|
const char *p;
|
|
|
|
BYTE hash[64];
|
|
|
|
DWORD hash_size;
|
|
|
|
|
|
|
|
ok(bindings.BindingsLength == sizeof(*bindings.Bindings) + sizeof(prefix)-1 + 32 /* hash size */,
|
|
|
|
"bindings.BindingsLength = %u\n", bindings.BindingsLength);
|
|
|
|
ok(!bindings.Bindings->dwInitiatorAddrType, "dwInitiatorAddrType = %x\n", bindings.Bindings->dwInitiatorAddrType);
|
|
|
|
ok(!bindings.Bindings->cbInitiatorLength, "cbInitiatorLength = %x\n", bindings.Bindings->cbInitiatorLength);
|
|
|
|
ok(!bindings.Bindings->dwInitiatorOffset, "dwInitiatorOffset = %x\n", bindings.Bindings->dwInitiatorOffset);
|
|
|
|
ok(!bindings.Bindings->dwAcceptorAddrType, "dwAcceptorAddrType = %x\n", bindings.Bindings->dwAcceptorAddrType);
|
|
|
|
ok(!bindings.Bindings->cbAcceptorLength, "cbAcceptorLength = %x\n", bindings.Bindings->cbAcceptorLength);
|
|
|
|
ok(!bindings.Bindings->dwAcceptorOffset, "dwAcceptorOffset = %x\n", bindings.Bindings->dwAcceptorOffset);
|
|
|
|
ok(sizeof(*bindings.Bindings) + bindings.Bindings->cbApplicationDataLength == bindings.BindingsLength,
|
|
|
|
"cbApplicationDataLength = %x\n", bindings.Bindings->cbApplicationDataLength);
|
|
|
|
ok(bindings.Bindings->dwApplicationDataOffset == sizeof(*bindings.Bindings),
|
|
|
|
"dwApplicationDataOffset = %x\n", bindings.Bindings->dwApplicationDataOffset);
|
|
|
|
p = (const char*)(bindings.Bindings+1);
|
|
|
|
ok(!memcmp(p, prefix, sizeof(prefix)-1), "missing prefix\n");
|
|
|
|
p += sizeof(prefix)-1;
|
|
|
|
|
|
|
|
hash_size = sizeof(hash);
|
|
|
|
ret = CryptHashCertificate(0, CALG_SHA_256, 0, cert->pbCertEncoded, cert->cbCertEncoded, hash, &hash_size);
|
|
|
|
if(ret) {
|
|
|
|
ok(hash_size == 32, "hash_size = %u\n", hash_size);
|
|
|
|
ok(!memcmp(hash, p, hash_size), "unexpected hash part\n");
|
|
|
|
}else {
|
|
|
|
win_skip("SHA 256 hash not supported.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
FreeContextBuffer(bindings.Bindings);
|
|
|
|
}else {
|
|
|
|
win_skip("SECPKG_ATTR_ENDPOINT_BINDINGS not supported\n");
|
|
|
|
}
|
|
|
|
|
2016-06-14 18:29:24 +02:00
|
|
|
CertFreeCertificateContext(cert);
|
2013-01-21 15:04:05 +01:00
|
|
|
}
|
|
|
|
|
2013-02-27 15:36:18 +01:00
|
|
|
status = pQueryContextAttributesA(&context, SECPKG_ATTR_CONNECTION_INFO, (void*)&conn_info);
|
|
|
|
ok(status == SEC_E_OK, "QueryContextAttributesW(SECPKG_ATTR_CONNECTION_INFO) failed: %08x\n", status);
|
|
|
|
if(status == SEC_E_OK) {
|
2015-12-21 18:20:29 +01:00
|
|
|
ok(conn_info.dwCipherStrength >= 128, "conn_info.dwCipherStrength = %d\n", conn_info.dwCipherStrength);
|
2013-02-27 15:36:18 +01:00
|
|
|
ok(conn_info.dwHashStrength >= 128, "conn_info.dwHashStrength = %d\n", conn_info.dwHashStrength);
|
|
|
|
}
|
|
|
|
|
2017-04-20 13:58:37 +02:00
|
|
|
status = pQueryContextAttributesA(&context, SECPKG_ATTR_KEY_INFO, &key_info);
|
2017-04-24 17:31:44 +02:00
|
|
|
ok(status == SEC_E_OK, "QueryContextAttributesW(SECPKG_ATTR_KEY_INFO) failed: %08x\n", status);
|
2017-04-20 13:58:37 +02:00
|
|
|
if(status == SEC_E_OK) {
|
|
|
|
ok(broken(key_info.SignatureAlgorithm == 0 /* WinXP,2003 */) ||
|
|
|
|
key_info.SignatureAlgorithm == CALG_RSA_SIGN,
|
|
|
|
"key_info.SignatureAlgorithm = %04x\n", key_info.SignatureAlgorithm);
|
|
|
|
ok(broken(key_info.SignatureAlgorithm == 0 /* WinXP,2003 */) ||
|
|
|
|
!strcmp(key_info.sSignatureAlgorithmName, "RSA"),
|
|
|
|
"key_info.sSignatureAlgorithmName = %s\n", key_info.sSignatureAlgorithmName);
|
|
|
|
ok(key_info.KeySize >= 128, "key_info.KeySize = %d\n", key_info.KeySize);
|
|
|
|
}
|
|
|
|
|
2013-12-12 06:12:13 +01:00
|
|
|
status = pQueryContextAttributesA(&context, SECPKG_ATTR_STREAM_SIZES, &sizes);
|
|
|
|
ok(status == SEC_E_OK, "QueryContextAttributesW(SECPKG_ATTR_STREAM_SIZES) failed: %08x\n", status);
|
2010-09-07 17:36:36 +02:00
|
|
|
|
2017-12-14 10:19:06 +01:00
|
|
|
status = QueryContextAttributesA(&context, SECPKG_ATTR_NEGOTIATION_INFO, &info);
|
|
|
|
ok(status == SEC_E_UNSUPPORTED_FUNCTION, "QueryContextAttributesA returned %08x\n", status);
|
|
|
|
|
2010-09-07 17:36:36 +02:00
|
|
|
reset_buffers(&buffers[0]);
|
|
|
|
|
|
|
|
/* Send a simple request so we get data for testing DecryptMessage */
|
|
|
|
buf = &buffers[0].pBuffers[0];
|
|
|
|
data = buf->pvBuffer;
|
|
|
|
buf->BufferType = SECBUFFER_STREAM_HEADER;
|
|
|
|
buf->cbBuffer = sizes.cbHeader;
|
|
|
|
++buf;
|
|
|
|
buf->BufferType = SECBUFFER_DATA;
|
|
|
|
buf->pvBuffer = data + sizes.cbHeader;
|
|
|
|
buf->cbBuffer = sizeof(http_request) - 1;
|
|
|
|
memcpy(buf->pvBuffer, http_request, sizeof(http_request) - 1);
|
|
|
|
++buf;
|
|
|
|
buf->BufferType = SECBUFFER_STREAM_TRAILER;
|
|
|
|
buf->pvBuffer = data + sizes.cbHeader + sizeof(http_request) -1;
|
|
|
|
buf->cbBuffer = sizes.cbTrailer;
|
|
|
|
|
2017-01-13 19:54:22 +01:00
|
|
|
status = EncryptMessage(&context, 0, &buffers[0], 0);
|
2010-09-07 17:36:36 +02:00
|
|
|
ok(status == SEC_E_OK, "EncryptMessage failed: %08x\n", status);
|
|
|
|
if (status != SEC_E_OK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
buf = &buffers[0].pBuffers[0];
|
|
|
|
send(sock, buf->pvBuffer, buffers[0].pBuffers[0].cbBuffer + buffers[0].pBuffers[1].cbBuffer + buffers[0].pBuffers[2].cbBuffer, 0);
|
|
|
|
|
|
|
|
reset_buffers(&buffers[0]);
|
|
|
|
buf->cbBuffer = buf_size;
|
|
|
|
data_size = receive_data(sock, buf);
|
|
|
|
|
|
|
|
/* Too few buffers */
|
|
|
|
--buffers[0].cBuffers;
|
2017-01-13 19:54:22 +01:00
|
|
|
status = DecryptMessage(&context, &buffers[0], 0, NULL);
|
2010-09-07 17:36:36 +02:00
|
|
|
ok(status == SEC_E_INVALID_TOKEN, "Expected SEC_E_INVALID_TOKEN, got %08x\n", status);
|
|
|
|
|
|
|
|
/* No data buffer */
|
|
|
|
++buffers[0].cBuffers;
|
2017-01-13 19:54:22 +01:00
|
|
|
status = DecryptMessage(&context, &buffers[0], 0, NULL);
|
2010-09-07 17:36:36 +02:00
|
|
|
ok(status == SEC_E_INVALID_TOKEN, "Expected SEC_E_INVALID_TOKEN, got %08x\n", status);
|
|
|
|
|
|
|
|
/* Two data buffers */
|
|
|
|
buffers[0].pBuffers[0].BufferType = SECBUFFER_DATA;
|
|
|
|
buffers[0].pBuffers[1].BufferType = SECBUFFER_DATA;
|
2017-01-13 19:54:22 +01:00
|
|
|
status = DecryptMessage(&context, &buffers[0], 0, NULL);
|
2010-09-07 17:36:36 +02:00
|
|
|
ok(status == SEC_E_INVALID_TOKEN, "Expected SEC_E_INVALID_TOKEN, got %08x\n", status);
|
|
|
|
|
|
|
|
/* Too few empty buffers */
|
|
|
|
buffers[0].pBuffers[1].BufferType = SECBUFFER_EXTRA;
|
2017-01-13 19:54:22 +01:00
|
|
|
status = DecryptMessage(&context, &buffers[0], 0, NULL);
|
2010-09-07 17:36:36 +02:00
|
|
|
ok(status == SEC_E_INVALID_TOKEN, "Expected SEC_E_INVALID_TOKEN, got %08x\n", status);
|
|
|
|
|
|
|
|
/* Incomplete data */
|
|
|
|
buffers[0].pBuffers[1].BufferType = SECBUFFER_EMPTY;
|
|
|
|
buffers[0].pBuffers[0].cbBuffer = (data[3]<<8) | data[4];
|
2017-01-13 19:54:22 +01:00
|
|
|
status = DecryptMessage(&context, &buffers[0], 0, NULL);
|
2010-09-07 17:36:36 +02:00
|
|
|
ok(status == SEC_E_INCOMPLETE_MESSAGE, "Expected SEC_E_INCOMPLETE_MESSAGE, got %08x\n", status);
|
|
|
|
ok(buffers[0].pBuffers[0].BufferType == SECBUFFER_MISSING, "Expected first buffer to be SECBUFFER_MISSING\n");
|
|
|
|
ok(buffers[0].pBuffers[0].cbBuffer == 5, "Expected first buffer to be a five bytes\n");
|
|
|
|
|
|
|
|
buffers[0].pBuffers[0].cbBuffer = data_size;
|
|
|
|
buffers[0].pBuffers[0].BufferType = SECBUFFER_DATA;
|
|
|
|
buffers[0].pBuffers[1].BufferType = SECBUFFER_EMPTY;
|
2017-01-13 19:54:22 +01:00
|
|
|
status = DecryptMessage(&context, &buffers[0], 0, NULL);
|
2010-09-07 17:36:36 +02:00
|
|
|
ok(status == SEC_E_OK, "DecryptMessage failed: %08x\n", status);
|
2011-09-09 15:53:49 +02:00
|
|
|
if (status == SEC_E_OK)
|
|
|
|
{
|
|
|
|
ok(buffers[0].pBuffers[0].BufferType == SECBUFFER_STREAM_HEADER, "Expected first buffer to be SECBUFFER_STREAM_HEADER\n");
|
|
|
|
ok(buffers[0].pBuffers[1].BufferType == SECBUFFER_DATA, "Expected second buffer to be SECBUFFER_DATA\n");
|
|
|
|
ok(buffers[0].pBuffers[2].BufferType == SECBUFFER_STREAM_TRAILER, "Expected third buffer to be SECBUFFER_STREAM_TRAILER\n");
|
2010-09-07 17:36:36 +02:00
|
|
|
|
2011-09-09 15:53:49 +02:00
|
|
|
data = buffers[0].pBuffers[1].pvBuffer;
|
|
|
|
data[buffers[0].pBuffers[1].cbBuffer] = 0;
|
|
|
|
}
|
2010-09-07 17:36:36 +02:00
|
|
|
|
2017-01-13 19:54:22 +01:00
|
|
|
DeleteSecurityContext(&context);
|
|
|
|
FreeCredentialsHandle(&cred_handle);
|
2010-09-07 17:36:36 +02:00
|
|
|
|
|
|
|
free_buffers(&buffers[0]);
|
|
|
|
free_buffers(&buffers[1]);
|
|
|
|
|
|
|
|
closesocket(sock);
|
|
|
|
}
|
|
|
|
|
2006-07-28 08:39:56 +02:00
|
|
|
START_TEST(schannel)
|
|
|
|
{
|
2017-01-13 19:54:22 +01:00
|
|
|
pQueryContextAttributesA = (void*)GetProcAddress(GetModuleHandleA("secur32.dll"), "QueryContextAttributesA");
|
2006-08-17 13:42:28 +02:00
|
|
|
|
2015-07-02 17:50:00 +02:00
|
|
|
test_cread_attrs();
|
2007-12-18 10:00:10 +01:00
|
|
|
testAcquireSecurityContext();
|
2017-01-13 19:57:48 +01:00
|
|
|
test_InitializeSecurityContext();
|
2010-09-07 17:36:36 +02:00
|
|
|
test_communication();
|
2006-07-28 08:39:56 +02:00
|
|
|
}
|