2005-05-13 17:44:47 +00:00
|
|
|
/* Copyright (C) 2005 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
|
2006-05-18 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-05-13 17:44:47 +00:00
|
|
|
*
|
|
|
|
* This file implements the schannel provider, or, the SSL/TLS implementations.
|
|
|
|
* FIXME: It should be rather obvious that this file is empty of any
|
|
|
|
* implementation.
|
|
|
|
*/
|
2008-09-22 20:13:19 +00:00
|
|
|
#include "config.h"
|
2008-09-22 20:14:04 +00:00
|
|
|
#include "wine/port.h"
|
2008-09-22 20:13:19 +00:00
|
|
|
|
2005-05-13 17:44:47 +00:00
|
|
|
#include <stdarg.h>
|
2008-09-22 20:14:04 +00:00
|
|
|
#ifdef SONAME_LIBGNUTLS
|
|
|
|
#include <gnutls/gnutls.h>
|
|
|
|
#endif
|
|
|
|
|
2005-05-13 17:44:47 +00:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "sspi.h"
|
|
|
|
#include "schannel.h"
|
|
|
|
#include "secur32_priv.h"
|
|
|
|
#include "wine/debug.h"
|
2008-09-22 20:14:04 +00:00
|
|
|
#include "wine/library.h"
|
2005-05-13 17:44:47 +00:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(secur32);
|
|
|
|
|
2008-09-22 20:13:19 +00:00
|
|
|
#ifdef SONAME_LIBGNUTLS
|
|
|
|
|
2008-09-22 20:14:04 +00:00
|
|
|
static void *libgnutls_handle;
|
|
|
|
#define MAKE_FUNCPTR(f) static typeof(f) * p##f
|
|
|
|
MAKE_FUNCPTR(gnutls_certificate_allocate_credentials);
|
|
|
|
MAKE_FUNCPTR(gnutls_certificate_free_credentials);
|
|
|
|
MAKE_FUNCPTR(gnutls_global_deinit);
|
|
|
|
MAKE_FUNCPTR(gnutls_global_init);
|
2008-09-22 20:14:04 +00:00
|
|
|
MAKE_FUNCPTR(gnutls_global_set_log_function);
|
|
|
|
MAKE_FUNCPTR(gnutls_global_set_log_level);
|
2008-09-22 20:14:04 +00:00
|
|
|
#undef MAKE_FUNCPTR
|
|
|
|
|
2008-10-06 17:08:36 +00:00
|
|
|
#define SCHAN_INVALID_HANDLE ~0UL
|
|
|
|
|
2008-09-22 20:14:04 +00:00
|
|
|
enum schan_handle_type
|
|
|
|
{
|
|
|
|
SCHAN_HANDLE_CRED,
|
|
|
|
SCHAN_HANDLE_FREE
|
|
|
|
};
|
|
|
|
|
|
|
|
struct schan_handle
|
|
|
|
{
|
|
|
|
void *object;
|
|
|
|
enum schan_handle_type type;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct schan_credentials
|
|
|
|
{
|
|
|
|
ULONG credential_use;
|
2008-09-24 10:24:01 +00:00
|
|
|
gnutls_certificate_credentials credentials;
|
2008-09-22 20:14:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct schan_handle *schan_handle_table;
|
|
|
|
static struct schan_handle *schan_free_handles;
|
|
|
|
static SIZE_T schan_handle_table_size;
|
|
|
|
static SIZE_T schan_handle_count;
|
|
|
|
|
|
|
|
static ULONG_PTR schan_alloc_handle(void *object, enum schan_handle_type type)
|
|
|
|
{
|
|
|
|
struct schan_handle *handle;
|
|
|
|
|
|
|
|
if (schan_free_handles)
|
|
|
|
{
|
|
|
|
/* Use a free handle */
|
|
|
|
handle = schan_free_handles;
|
|
|
|
if (handle->type != SCHAN_HANDLE_FREE)
|
|
|
|
{
|
|
|
|
ERR("Handle %d(%p) is in the free list, but has type %#x.\n", (handle-schan_handle_table), handle, handle->type);
|
2008-10-06 17:08:36 +00:00
|
|
|
return SCHAN_INVALID_HANDLE;
|
2008-09-22 20:14:04 +00:00
|
|
|
}
|
|
|
|
schan_free_handles = (struct schan_handle *)handle->object;
|
|
|
|
handle->object = object;
|
|
|
|
handle->type = type;
|
|
|
|
|
|
|
|
return handle - schan_handle_table;
|
|
|
|
}
|
|
|
|
if (!(schan_handle_count < schan_handle_table_size))
|
|
|
|
{
|
|
|
|
/* Grow the table */
|
|
|
|
SIZE_T new_size = schan_handle_table_size + (schan_handle_table_size >> 1);
|
|
|
|
struct schan_handle *new_table = HeapReAlloc(GetProcessHeap(), 0, schan_handle_table, new_size * sizeof(*schan_handle_table));
|
|
|
|
if (!new_table)
|
|
|
|
{
|
|
|
|
ERR("Failed to grow the handle table\n");
|
2008-10-06 17:08:36 +00:00
|
|
|
return SCHAN_INVALID_HANDLE;
|
2008-09-22 20:14:04 +00:00
|
|
|
}
|
|
|
|
schan_handle_table = new_table;
|
|
|
|
schan_handle_table_size = new_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
handle = &schan_handle_table[schan_handle_count++];
|
|
|
|
handle->object = object;
|
|
|
|
handle->type = type;
|
|
|
|
|
|
|
|
return handle - schan_handle_table;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *schan_free_handle(ULONG_PTR handle_idx, enum schan_handle_type type)
|
|
|
|
{
|
|
|
|
struct schan_handle *handle;
|
|
|
|
void *object;
|
|
|
|
|
2008-10-06 17:08:36 +00:00
|
|
|
if (handle_idx == SCHAN_INVALID_HANDLE) return NULL;
|
2008-09-22 20:14:04 +00:00
|
|
|
handle = &schan_handle_table[handle_idx];
|
|
|
|
if (handle->type != type)
|
|
|
|
{
|
|
|
|
ERR("Handle %ld(%p) is not of type %#x\n", handle_idx, handle, type);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
object = handle->object;
|
|
|
|
handle->object = schan_free_handles;
|
|
|
|
handle->type = SCHAN_HANDLE_FREE;
|
|
|
|
schan_free_handles = handle;
|
|
|
|
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
2005-05-13 17:44:47 +00:00
|
|
|
static SECURITY_STATUS schan_QueryCredentialsAttributes(
|
2007-08-25 21:21:07 +00:00
|
|
|
PCredHandle phCredential, ULONG ulAttribute, const VOID *pBuffer)
|
2005-05-13 17:44:47 +00:00
|
|
|
{
|
|
|
|
SECURITY_STATUS ret;
|
|
|
|
|
|
|
|
switch (ulAttribute)
|
|
|
|
{
|
|
|
|
case SECPKG_ATTR_SUPPORTED_ALGS:
|
|
|
|
if (pBuffer)
|
|
|
|
{
|
|
|
|
/* FIXME: get from CryptoAPI */
|
2008-03-12 17:35:10 +00:00
|
|
|
FIXME("SECPKG_ATTR_SUPPORTED_ALGS: stub\n");
|
2005-05-13 17:44:47 +00:00
|
|
|
ret = SEC_E_UNSUPPORTED_FUNCTION;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = SEC_E_INTERNAL_ERROR;
|
|
|
|
break;
|
|
|
|
case SECPKG_ATTR_CIPHER_STRENGTHS:
|
|
|
|
if (pBuffer)
|
|
|
|
{
|
2008-03-12 17:35:10 +00:00
|
|
|
SecPkgCred_CipherStrengths *r = (SecPkgCred_CipherStrengths*)pBuffer;
|
|
|
|
|
2005-05-13 17:44:47 +00:00
|
|
|
/* FIXME: get from CryptoAPI */
|
2008-03-12 17:35:10 +00:00
|
|
|
FIXME("SECPKG_ATTR_CIPHER_STRENGTHS: semi-stub\n");
|
|
|
|
r->dwMinimumCipherStrength = 40;
|
|
|
|
r->dwMaximumCipherStrength = 168;
|
|
|
|
ret = SEC_E_OK;
|
2005-05-13 17:44:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = SEC_E_INTERNAL_ERROR;
|
|
|
|
break;
|
|
|
|
case SECPKG_ATTR_SUPPORTED_PROTOCOLS:
|
|
|
|
if (pBuffer)
|
|
|
|
{
|
|
|
|
/* FIXME: get from OpenSSL? */
|
2008-03-12 17:35:10 +00:00
|
|
|
FIXME("SECPKG_ATTR_SUPPORTED_PROTOCOLS: stub\n");
|
2005-05-13 17:44:47 +00:00
|
|
|
ret = SEC_E_UNSUPPORTED_FUNCTION;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = SEC_E_INTERNAL_ERROR;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = SEC_E_UNSUPPORTED_FUNCTION;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SECURITY_STATUS SEC_ENTRY schan_QueryCredentialsAttributesA(
|
|
|
|
PCredHandle phCredential, ULONG ulAttribute, PVOID pBuffer)
|
|
|
|
{
|
|
|
|
SECURITY_STATUS ret;
|
|
|
|
|
2006-10-15 12:51:52 +00:00
|
|
|
TRACE("(%p, %d, %p)\n", phCredential, ulAttribute, pBuffer);
|
2005-05-13 17:44:47 +00:00
|
|
|
|
|
|
|
switch (ulAttribute)
|
|
|
|
{
|
|
|
|
case SECPKG_CRED_ATTR_NAMES:
|
|
|
|
FIXME("SECPKG_CRED_ATTR_NAMES: stub\n");
|
|
|
|
ret = SEC_E_UNSUPPORTED_FUNCTION;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = schan_QueryCredentialsAttributes(phCredential, ulAttribute,
|
|
|
|
pBuffer);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SECURITY_STATUS SEC_ENTRY schan_QueryCredentialsAttributesW(
|
|
|
|
PCredHandle phCredential, ULONG ulAttribute, PVOID pBuffer)
|
|
|
|
{
|
|
|
|
SECURITY_STATUS ret;
|
|
|
|
|
2006-10-15 12:51:52 +00:00
|
|
|
TRACE("(%p, %d, %p)\n", phCredential, ulAttribute, pBuffer);
|
2005-05-13 17:44:47 +00:00
|
|
|
|
|
|
|
switch (ulAttribute)
|
|
|
|
{
|
|
|
|
case SECPKG_CRED_ATTR_NAMES:
|
|
|
|
FIXME("SECPKG_CRED_ATTR_NAMES: stub\n");
|
|
|
|
ret = SEC_E_UNSUPPORTED_FUNCTION;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = schan_QueryCredentialsAttributes(phCredential, ulAttribute,
|
|
|
|
pBuffer);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-08-25 21:21:07 +00:00
|
|
|
static SECURITY_STATUS schan_CheckCreds(const SCHANNEL_CRED *schanCred)
|
2005-05-13 17:44:47 +00:00
|
|
|
{
|
2006-07-28 06:39:56 +00:00
|
|
|
SECURITY_STATUS st;
|
2005-05-13 17:44:47 +00:00
|
|
|
|
2006-07-28 06:39:56 +00:00
|
|
|
switch (schanCred->dwVersion)
|
|
|
|
{
|
|
|
|
case SCH_CRED_V3:
|
|
|
|
case SCHANNEL_CRED_VERSION:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return SEC_E_INTERNAL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (schanCred->cCreds == 0)
|
|
|
|
st = SEC_E_NO_CREDENTIALS;
|
|
|
|
else if (schanCred->cCreds > 1)
|
|
|
|
st = SEC_E_UNKNOWN_CREDENTIALS;
|
2005-05-13 17:44:47 +00:00
|
|
|
else
|
|
|
|
{
|
2006-07-28 06:39:56 +00:00
|
|
|
DWORD keySpec;
|
|
|
|
HCRYPTPROV csp;
|
|
|
|
BOOL ret, freeCSP;
|
|
|
|
|
|
|
|
ret = CryptAcquireCertificatePrivateKey(schanCred->paCred[0],
|
|
|
|
0, /* FIXME: what flags to use? */ NULL,
|
|
|
|
&csp, &keySpec, &freeCSP);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
st = SEC_E_OK;
|
|
|
|
if (freeCSP)
|
|
|
|
CryptReleaseContext(csp, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
st = SEC_E_UNKNOWN_CREDENTIALS;
|
|
|
|
}
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
2007-08-25 21:21:07 +00:00
|
|
|
static SECURITY_STATUS schan_AcquireClientCredentials(const SCHANNEL_CRED *schanCred,
|
2006-07-28 06:39:56 +00:00
|
|
|
PCredHandle phCredential, PTimeStamp ptsExpiry)
|
|
|
|
{
|
|
|
|
SECURITY_STATUS st = SEC_E_OK;
|
|
|
|
|
2008-09-22 20:14:04 +00:00
|
|
|
TRACE("schanCred %p, phCredential %p, ptsExpiry %p\n", schanCred, phCredential, ptsExpiry);
|
|
|
|
|
2006-07-28 06:39:56 +00:00
|
|
|
if (schanCred)
|
|
|
|
{
|
|
|
|
st = schan_CheckCreds(schanCred);
|
|
|
|
if (st == SEC_E_NO_CREDENTIALS)
|
|
|
|
st = SEC_E_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* For now, the only thing I'm interested in is the direction of the
|
|
|
|
* connection, so just store it.
|
|
|
|
*/
|
|
|
|
if (st == SEC_E_OK)
|
|
|
|
{
|
2008-09-22 20:14:04 +00:00
|
|
|
ULONG_PTR handle;
|
|
|
|
struct schan_credentials *creds;
|
|
|
|
|
|
|
|
creds = HeapAlloc(GetProcessHeap(), 0, sizeof(*creds));
|
|
|
|
if (!creds) return SEC_E_INSUFFICIENT_MEMORY;
|
|
|
|
|
|
|
|
handle = schan_alloc_handle(creds, SCHAN_HANDLE_CRED);
|
2008-10-06 17:08:36 +00:00
|
|
|
if (handle == SCHAN_INVALID_HANDLE)
|
2008-09-22 20:14:04 +00:00
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, creds);
|
|
|
|
return SEC_E_INTERNAL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
creds->credential_use = SECPKG_CRED_OUTBOUND;
|
2008-09-22 20:14:04 +00:00
|
|
|
pgnutls_certificate_allocate_credentials(&creds->credentials);
|
2008-09-22 20:14:04 +00:00
|
|
|
|
|
|
|
phCredential->dwLower = handle;
|
|
|
|
phCredential->dwUpper = 0;
|
|
|
|
|
2006-07-28 06:39:56 +00:00
|
|
|
/* Outbound credentials have no expiry */
|
2005-05-13 17:44:47 +00:00
|
|
|
if (ptsExpiry)
|
2006-06-19 10:09:56 +00:00
|
|
|
{
|
|
|
|
ptsExpiry->LowPart = 0;
|
|
|
|
ptsExpiry->HighPart = 0;
|
|
|
|
}
|
2005-05-13 17:44:47 +00:00
|
|
|
}
|
2006-07-28 06:39:56 +00:00
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
2007-08-25 21:21:07 +00:00
|
|
|
static SECURITY_STATUS schan_AcquireServerCredentials(const SCHANNEL_CRED *schanCred,
|
2006-07-28 06:39:56 +00:00
|
|
|
PCredHandle phCredential, PTimeStamp ptsExpiry)
|
|
|
|
{
|
|
|
|
SECURITY_STATUS st;
|
|
|
|
|
2008-09-22 20:14:04 +00:00
|
|
|
TRACE("schanCred %p, phCredential %p, ptsExpiry %p\n", schanCred, phCredential, ptsExpiry);
|
|
|
|
|
2006-07-28 06:39:56 +00:00
|
|
|
if (!schanCred) return SEC_E_NO_CREDENTIALS;
|
|
|
|
|
|
|
|
st = schan_CheckCreds(schanCred);
|
|
|
|
if (st == SEC_E_OK)
|
|
|
|
{
|
2008-09-22 20:14:04 +00:00
|
|
|
ULONG_PTR handle;
|
|
|
|
struct schan_credentials *creds;
|
|
|
|
|
|
|
|
creds = HeapAlloc(GetProcessHeap(), 0, sizeof(*creds));
|
|
|
|
if (!creds) return SEC_E_INSUFFICIENT_MEMORY;
|
|
|
|
creds->credential_use = SECPKG_CRED_INBOUND;
|
|
|
|
|
|
|
|
handle = schan_alloc_handle(creds, SCHAN_HANDLE_CRED);
|
2008-10-06 17:08:36 +00:00
|
|
|
if (handle == SCHAN_INVALID_HANDLE)
|
2008-09-22 20:14:04 +00:00
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, creds);
|
|
|
|
return SEC_E_INTERNAL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
phCredential->dwLower = handle;
|
|
|
|
phCredential->dwUpper = 0;
|
|
|
|
|
2006-07-28 06:39:56 +00:00
|
|
|
/* FIXME: get expiry from cert */
|
|
|
|
}
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SECURITY_STATUS schan_AcquireCredentialsHandle(ULONG fCredentialUse,
|
2007-08-25 21:21:07 +00:00
|
|
|
const SCHANNEL_CRED *schanCred, PCredHandle phCredential, PTimeStamp ptsExpiry)
|
2006-07-28 06:39:56 +00:00
|
|
|
{
|
|
|
|
SECURITY_STATUS ret;
|
|
|
|
|
|
|
|
if (fCredentialUse == SECPKG_CRED_OUTBOUND)
|
|
|
|
ret = schan_AcquireClientCredentials(schanCred, phCredential,
|
|
|
|
ptsExpiry);
|
|
|
|
else
|
|
|
|
ret = schan_AcquireServerCredentials(schanCred, phCredential,
|
|
|
|
ptsExpiry);
|
2005-05-13 17:44:47 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SECURITY_STATUS SEC_ENTRY schan_AcquireCredentialsHandleA(
|
|
|
|
SEC_CHAR *pszPrincipal, SEC_CHAR *pszPackage, ULONG fCredentialUse,
|
|
|
|
PLUID pLogonID, PVOID pAuthData, SEC_GET_KEY_FN pGetKeyFn,
|
|
|
|
PVOID pGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
|
|
|
|
{
|
2006-10-15 12:51:52 +00:00
|
|
|
TRACE("(%s, %s, 0x%08x, %p, %p, %p, %p, %p, %p)\n",
|
2005-05-13 17:44:47 +00:00
|
|
|
debugstr_a(pszPrincipal), debugstr_a(pszPackage), fCredentialUse,
|
|
|
|
pLogonID, pAuthData, pGetKeyFn, pGetKeyArgument, phCredential, ptsExpiry);
|
2006-07-28 06:39:56 +00:00
|
|
|
return schan_AcquireCredentialsHandle(fCredentialUse,
|
|
|
|
(PSCHANNEL_CRED)pAuthData, phCredential, ptsExpiry);
|
2005-05-13 17:44:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static SECURITY_STATUS SEC_ENTRY schan_AcquireCredentialsHandleW(
|
|
|
|
SEC_WCHAR *pszPrincipal, SEC_WCHAR *pszPackage, ULONG fCredentialUse,
|
|
|
|
PLUID pLogonID, PVOID pAuthData, SEC_GET_KEY_FN pGetKeyFn,
|
|
|
|
PVOID pGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
|
|
|
|
{
|
2006-10-15 12:51:52 +00:00
|
|
|
TRACE("(%s, %s, 0x%08x, %p, %p, %p, %p, %p, %p)\n",
|
2005-05-13 17:44:47 +00:00
|
|
|
debugstr_w(pszPrincipal), debugstr_w(pszPackage), fCredentialUse,
|
|
|
|
pLogonID, pAuthData, pGetKeyFn, pGetKeyArgument, phCredential, ptsExpiry);
|
2006-07-28 06:39:56 +00:00
|
|
|
return schan_AcquireCredentialsHandle(fCredentialUse,
|
|
|
|
(PSCHANNEL_CRED)pAuthData, phCredential, ptsExpiry);
|
|
|
|
}
|
|
|
|
|
|
|
|
static SECURITY_STATUS SEC_ENTRY schan_FreeCredentialsHandle(
|
|
|
|
PCredHandle phCredential)
|
|
|
|
{
|
2008-09-22 20:14:04 +00:00
|
|
|
struct schan_credentials *creds;
|
|
|
|
|
|
|
|
TRACE("phCredential %p\n", phCredential);
|
|
|
|
|
|
|
|
if (!phCredential) return SEC_E_INVALID_HANDLE;
|
|
|
|
|
|
|
|
creds = schan_free_handle(phCredential->dwLower, SCHAN_HANDLE_CRED);
|
|
|
|
if (!creds) return SEC_E_INVALID_HANDLE;
|
|
|
|
|
2008-09-22 20:14:04 +00:00
|
|
|
if (creds->credential_use == SECPKG_CRED_OUTBOUND)
|
|
|
|
pgnutls_certificate_free_credentials(creds->credentials);
|
2008-09-22 20:14:04 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, creds);
|
|
|
|
|
2006-07-28 06:39:56 +00:00
|
|
|
return SEC_E_OK;
|
2005-05-13 17:44:47 +00:00
|
|
|
}
|
|
|
|
|
2006-02-14 16:37:36 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* InitializeSecurityContextA
|
|
|
|
*/
|
|
|
|
static SECURITY_STATUS SEC_ENTRY schan_InitializeSecurityContextA(
|
|
|
|
PCredHandle phCredential, PCtxtHandle phContext, SEC_CHAR *pszTargetName,
|
|
|
|
ULONG fContextReq, ULONG Reserved1, ULONG TargetDataRep,
|
|
|
|
PSecBufferDesc pInput, ULONG Reserved2, PCtxtHandle phNewContext,
|
|
|
|
PSecBufferDesc pOutput, ULONG *pfContextAttr, PTimeStamp ptsExpiry)
|
|
|
|
{
|
|
|
|
SECURITY_STATUS ret;
|
|
|
|
|
2006-10-15 12:51:52 +00:00
|
|
|
TRACE("%p %p %s %d %d %d %p %d %p %p %p %p\n", phCredential, phContext,
|
2006-02-14 16:37:36 +00:00
|
|
|
debugstr_a(pszTargetName), fContextReq, Reserved1, TargetDataRep, pInput,
|
|
|
|
Reserved1, phNewContext, pOutput, pfContextAttr, ptsExpiry);
|
2006-07-28 06:39:56 +00:00
|
|
|
if(phCredential)
|
|
|
|
{
|
|
|
|
FIXME("stub\n");
|
2006-02-14 16:37:36 +00:00
|
|
|
ret = SEC_E_UNSUPPORTED_FUNCTION;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = SEC_E_INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* InitializeSecurityContextW
|
|
|
|
*/
|
|
|
|
static SECURITY_STATUS SEC_ENTRY schan_InitializeSecurityContextW(
|
|
|
|
PCredHandle phCredential, PCtxtHandle phContext, SEC_WCHAR *pszTargetName,
|
|
|
|
ULONG fContextReq, ULONG Reserved1, ULONG TargetDataRep,
|
|
|
|
PSecBufferDesc pInput,ULONG Reserved2, PCtxtHandle phNewContext,
|
|
|
|
PSecBufferDesc pOutput, ULONG *pfContextAttr, PTimeStamp ptsExpiry)
|
|
|
|
{
|
|
|
|
SECURITY_STATUS ret;
|
|
|
|
|
2006-10-15 12:51:52 +00:00
|
|
|
TRACE("%p %p %s %d %d %d %p %d %p %p %p %p\n", phCredential, phContext,
|
2006-02-14 16:37:36 +00:00
|
|
|
debugstr_w(pszTargetName), fContextReq, Reserved1, TargetDataRep, pInput,
|
|
|
|
Reserved1, phNewContext, pOutput, pfContextAttr, ptsExpiry);
|
|
|
|
if (phCredential)
|
|
|
|
{
|
2006-07-28 06:39:56 +00:00
|
|
|
FIXME("stub\n");
|
2006-02-14 16:37:36 +00:00
|
|
|
ret = SEC_E_UNSUPPORTED_FUNCTION;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = SEC_E_INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-09-22 20:14:04 +00:00
|
|
|
static void schan_gnutls_log(int level, const char *msg)
|
|
|
|
{
|
|
|
|
TRACE("<%d> %s", level, msg);
|
|
|
|
}
|
|
|
|
|
2006-12-14 14:47:50 +00:00
|
|
|
static const SecurityFunctionTableA schanTableA = {
|
2005-05-13 17:44:47 +00:00
|
|
|
1,
|
|
|
|
NULL, /* EnumerateSecurityPackagesA */
|
|
|
|
schan_QueryCredentialsAttributesA,
|
|
|
|
schan_AcquireCredentialsHandleA,
|
2006-07-28 06:39:56 +00:00
|
|
|
schan_FreeCredentialsHandle,
|
2005-05-13 17:44:47 +00:00
|
|
|
NULL, /* Reserved2 */
|
2006-02-14 16:37:36 +00:00
|
|
|
schan_InitializeSecurityContextA,
|
2005-05-13 17:44:47 +00:00
|
|
|
NULL, /* AcceptSecurityContext */
|
|
|
|
NULL, /* CompleteAuthToken */
|
|
|
|
NULL, /* DeleteSecurityContext */
|
|
|
|
NULL, /* ApplyControlToken */
|
|
|
|
NULL, /* QueryContextAttributesA */
|
|
|
|
NULL, /* ImpersonateSecurityContext */
|
|
|
|
NULL, /* RevertSecurityContext */
|
|
|
|
NULL, /* MakeSignature */
|
|
|
|
NULL, /* VerifySignature */
|
|
|
|
FreeContextBuffer,
|
|
|
|
NULL, /* QuerySecurityPackageInfoA */
|
|
|
|
NULL, /* Reserved3 */
|
|
|
|
NULL, /* Reserved4 */
|
|
|
|
NULL, /* ExportSecurityContext */
|
|
|
|
NULL, /* ImportSecurityContextA */
|
|
|
|
NULL, /* AddCredentialsA */
|
|
|
|
NULL, /* Reserved8 */
|
|
|
|
NULL, /* QuerySecurityContextToken */
|
|
|
|
NULL, /* EncryptMessage */
|
|
|
|
NULL, /* DecryptMessage */
|
|
|
|
NULL, /* SetContextAttributesA */
|
|
|
|
};
|
|
|
|
|
2006-12-14 14:47:50 +00:00
|
|
|
static const SecurityFunctionTableW schanTableW = {
|
2005-05-13 17:44:47 +00:00
|
|
|
1,
|
|
|
|
NULL, /* EnumerateSecurityPackagesW */
|
|
|
|
schan_QueryCredentialsAttributesW,
|
|
|
|
schan_AcquireCredentialsHandleW,
|
2006-07-28 06:39:56 +00:00
|
|
|
schan_FreeCredentialsHandle,
|
2005-05-13 17:44:47 +00:00
|
|
|
NULL, /* Reserved2 */
|
2006-02-14 16:37:36 +00:00
|
|
|
schan_InitializeSecurityContextW,
|
2005-05-13 17:44:47 +00:00
|
|
|
NULL, /* AcceptSecurityContext */
|
|
|
|
NULL, /* CompleteAuthToken */
|
|
|
|
NULL, /* DeleteSecurityContext */
|
|
|
|
NULL, /* ApplyControlToken */
|
|
|
|
NULL, /* QueryContextAttributesW */
|
|
|
|
NULL, /* ImpersonateSecurityContext */
|
|
|
|
NULL, /* RevertSecurityContext */
|
|
|
|
NULL, /* MakeSignature */
|
|
|
|
NULL, /* VerifySignature */
|
|
|
|
FreeContextBuffer,
|
|
|
|
NULL, /* QuerySecurityPackageInfoW */
|
|
|
|
NULL, /* Reserved3 */
|
|
|
|
NULL, /* Reserved4 */
|
|
|
|
NULL, /* ExportSecurityContext */
|
|
|
|
NULL, /* ImportSecurityContextW */
|
|
|
|
NULL, /* AddCredentialsW */
|
|
|
|
NULL, /* Reserved8 */
|
|
|
|
NULL, /* QuerySecurityContextToken */
|
|
|
|
NULL, /* EncryptMessage */
|
|
|
|
NULL, /* DecryptMessage */
|
|
|
|
NULL, /* SetContextAttributesW */
|
|
|
|
};
|
|
|
|
|
|
|
|
static const WCHAR schannelComment[] = { 'S','c','h','a','n','n','e','l',' ',
|
|
|
|
'S','e','c','u','r','i','t','y',' ','P','a','c','k','a','g','e',0 };
|
2008-07-02 15:18:49 +00:00
|
|
|
static const WCHAR schannelDllName[] = { 's','c','h','a','n','n','e','l','.','d','l','l',0 };
|
2005-05-13 17:44:47 +00:00
|
|
|
|
|
|
|
void SECUR32_initSchannelSP(void)
|
|
|
|
{
|
2008-09-22 20:14:04 +00:00
|
|
|
SecureProvider *provider;
|
|
|
|
|
|
|
|
|
|
|
|
libgnutls_handle = wine_dlopen(SONAME_LIBGNUTLS, RTLD_NOW, NULL, 0);
|
|
|
|
if (!libgnutls_handle)
|
|
|
|
{
|
|
|
|
WARN("Failed to load libgnutls.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define LOAD_FUNCPTR(f) \
|
|
|
|
if (!(p##f = wine_dlsym(libgnutls_handle, #f, NULL, 0))) \
|
|
|
|
{ \
|
|
|
|
ERR("Failed to load %s\n", #f); \
|
|
|
|
wine_dlclose(libgnutls_handle, NULL, 0); \
|
|
|
|
libgnutls_handle = NULL; \
|
|
|
|
return; \
|
|
|
|
}
|
|
|
|
|
|
|
|
LOAD_FUNCPTR(gnutls_certificate_allocate_credentials)
|
|
|
|
LOAD_FUNCPTR(gnutls_certificate_free_credentials)
|
|
|
|
LOAD_FUNCPTR(gnutls_global_deinit)
|
|
|
|
LOAD_FUNCPTR(gnutls_global_init)
|
2008-09-22 20:14:04 +00:00
|
|
|
LOAD_FUNCPTR(gnutls_global_set_log_function)
|
|
|
|
LOAD_FUNCPTR(gnutls_global_set_log_level)
|
2008-09-22 20:14:04 +00:00
|
|
|
#undef LOAD_FUNCPTR
|
|
|
|
|
|
|
|
provider = SECUR32_addProvider(&schanTableA, &schanTableW, schannelDllName);
|
2005-05-13 17:44:47 +00:00
|
|
|
|
|
|
|
if (provider)
|
|
|
|
{
|
|
|
|
/* This is what Windows reports. This shouldn't break any applications
|
|
|
|
* even though the functions are missing, because the wrapper will
|
|
|
|
* return SEC_E_UNSUPPORTED_FUNCTION if our function is NULL.
|
|
|
|
*/
|
|
|
|
static const long caps =
|
|
|
|
SECPKG_FLAG_INTEGRITY |
|
|
|
|
SECPKG_FLAG_PRIVACY |
|
|
|
|
SECPKG_FLAG_CONNECTION |
|
|
|
|
SECPKG_FLAG_MULTI_REQUIRED |
|
|
|
|
SECPKG_FLAG_EXTENDED_ERROR |
|
|
|
|
SECPKG_FLAG_IMPERSONATION |
|
|
|
|
SECPKG_FLAG_ACCEPT_WIN32_NAME |
|
|
|
|
SECPKG_FLAG_STREAM;
|
|
|
|
static const short version = 1;
|
|
|
|
static const long maxToken = 16384;
|
|
|
|
SEC_WCHAR *uniSPName = (SEC_WCHAR *)UNISP_NAME_W,
|
|
|
|
*schannel = (SEC_WCHAR *)SCHANNEL_NAME_W;
|
|
|
|
|
|
|
|
const SecPkgInfoW info[] = {
|
|
|
|
{ caps, version, UNISP_RPC_ID, maxToken, uniSPName, uniSPName },
|
|
|
|
{ caps, version, UNISP_RPC_ID, maxToken, schannel,
|
|
|
|
(SEC_WCHAR *)schannelComment },
|
|
|
|
};
|
|
|
|
|
|
|
|
SECUR32_addPackages(provider, sizeof(info) / sizeof(info[0]), NULL,
|
|
|
|
info);
|
2008-09-22 20:14:04 +00:00
|
|
|
|
|
|
|
schan_handle_table = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 64 * sizeof(*schan_handle_table));
|
|
|
|
schan_handle_table_size = 64;
|
2008-09-22 20:14:04 +00:00
|
|
|
|
|
|
|
pgnutls_global_init();
|
2008-09-22 20:14:04 +00:00
|
|
|
if (TRACE_ON(secur32))
|
|
|
|
{
|
|
|
|
pgnutls_global_set_log_level(4);
|
|
|
|
pgnutls_global_set_log_function(schan_gnutls_log);
|
|
|
|
}
|
2005-05-13 17:44:47 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-22 20:13:19 +00:00
|
|
|
|
2008-09-22 20:14:04 +00:00
|
|
|
void SECUR32_deinitSchannelSP(void)
|
|
|
|
{
|
|
|
|
pgnutls_global_deinit();
|
|
|
|
if (libgnutls_handle) wine_dlclose(libgnutls_handle, NULL, 0);
|
|
|
|
}
|
|
|
|
|
2008-09-22 20:13:19 +00:00
|
|
|
#else /* SONAME_LIBGNUTLS */
|
|
|
|
|
|
|
|
void SECUR32_initSchannelSP(void) {}
|
2008-09-22 20:14:04 +00:00
|
|
|
void SECUR32_deinitSchannelSP(void) {}
|
2008-09-22 20:13:19 +00:00
|
|
|
|
|
|
|
#endif /* SONAME_LIBGNUTLS */
|