2012-03-06 02:03:49 +04:00
|
|
|
/**
|
2012-05-22 06:48:33 +04:00
|
|
|
* WinPR: Windows Portable Runtime
|
2012-03-06 02:03:49 +04:00
|
|
|
* Negotiate Security Package
|
|
|
|
*
|
2014-06-06 06:10:08 +04:00
|
|
|
* Copyright 2011-2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2017-05-11 19:51:45 +03:00
|
|
|
* Copyright 2017 Dorian Ducournau <dorian.ducournau@gmail.com>
|
2015-07-07 18:17:29 +03:00
|
|
|
*
|
2012-03-06 02:03:49 +04:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:20:53 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-05-06 06:39:00 +04:00
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/sspi.h>
|
2018-02-13 13:00:56 +03:00
|
|
|
#include <winpr/tchar.h>
|
2022-02-15 11:04:17 +03:00
|
|
|
#include <winpr/assert.h>
|
2022-02-15 11:41:39 +03:00
|
|
|
#include <winpr/registry.h>
|
|
|
|
#include <winpr/build-config.h>
|
2012-03-06 02:03:49 +04:00
|
|
|
|
|
|
|
#include "negotiate.h"
|
|
|
|
|
|
|
|
#include "../sspi.h"
|
2022-02-14 16:59:22 +03:00
|
|
|
#include "../../log.h"
|
2016-07-22 00:53:20 +03:00
|
|
|
#define TAG WINPR_TAG("negotiate")
|
2012-03-06 02:03:49 +04:00
|
|
|
|
2022-02-15 11:41:39 +03:00
|
|
|
static const char NEGO_REG_KEY[] =
|
|
|
|
"Software\\" WINPR_VENDOR_STRING "\\" WINPR_PRODUCT_STRING "\\SSPI\\Negotiate";
|
|
|
|
|
2014-06-08 00:26:57 +04:00
|
|
|
extern const SecurityFunctionTableA NTLM_SecurityFunctionTableA;
|
|
|
|
extern const SecurityFunctionTableW NTLM_SecurityFunctionTableW;
|
|
|
|
|
2017-05-11 19:51:45 +03:00
|
|
|
extern const SecurityFunctionTableA KERBEROS_SecurityFunctionTableA;
|
|
|
|
extern const SecurityFunctionTableW KERBEROS_SecurityFunctionTableW;
|
|
|
|
|
|
|
|
#ifdef WITH_GSSAPI
|
|
|
|
static BOOL ErrorInitContextKerberos = FALSE;
|
|
|
|
#else
|
|
|
|
static BOOL ErrorInitContextKerberos = TRUE;
|
|
|
|
#endif
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
const SecPkgInfoA NEGOTIATE_SecPkgInfoA = {
|
|
|
|
0x00083BB3, /* fCapabilities */
|
|
|
|
1, /* wVersion */
|
|
|
|
0x0009, /* wRPCID */
|
|
|
|
0x00002FE0, /* cbMaxToken */
|
|
|
|
"Negotiate", /* Name */
|
2017-07-03 13:47:56 +03:00
|
|
|
"Microsoft Package Negotiator" /* Comment */
|
|
|
|
};
|
|
|
|
|
2018-06-06 17:43:09 +03:00
|
|
|
static WCHAR NEGOTIATE_SecPkgInfoW_Name[] = { 'N', 'e', 'g', 'o', 't', 'i', 'a', 't', 'e', '\0' };
|
2017-07-03 13:47:56 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static WCHAR NEGOTIATE_SecPkgInfoW_Comment[] = { 'M', 'i', 'c', 'r', 'o', 's', 'o', 'f', 't', ' ',
|
|
|
|
'P', 'a', 'c', 'k', 'a', 'g', 'e', ' ', 'N', 'e',
|
|
|
|
'g', 'o', 't', 'i', 'a', 't', 'o', 'r', '\0' };
|
2017-07-03 13:47:56 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
const SecPkgInfoW NEGOTIATE_SecPkgInfoW = {
|
|
|
|
0x00083BB3, /* fCapabilities */
|
|
|
|
1, /* wVersion */
|
|
|
|
0x0009, /* wRPCID */
|
|
|
|
0x00002FE0, /* cbMaxToken */
|
|
|
|
NEGOTIATE_SecPkgInfoW_Name, /* Name */
|
2017-07-03 13:47:56 +03:00
|
|
|
NEGOTIATE_SecPkgInfoW_Comment /* Comment */
|
|
|
|
};
|
|
|
|
|
2018-02-13 13:00:56 +03:00
|
|
|
static void negotiate_SetSubPackage(NEGOTIATE_CONTEXT* context, const TCHAR* name)
|
2017-05-11 19:51:45 +03:00
|
|
|
{
|
2022-02-15 11:04:17 +03:00
|
|
|
WINPR_ASSERT(context);
|
|
|
|
WINPR_ASSERT(name);
|
|
|
|
|
2018-02-13 13:00:56 +03:00
|
|
|
if (_tcsnccmp(name, KERBEROS_SSP_NAME, ARRAYSIZE(KERBEROS_SSP_NAME)) == 0)
|
2017-05-11 19:51:45 +03:00
|
|
|
{
|
2022-02-15 11:04:17 +03:00
|
|
|
context->sspiA = &KERBEROS_SecurityFunctionTableA;
|
|
|
|
context->sspiW = &KERBEROS_SecurityFunctionTableW;
|
2017-05-11 19:51:45 +03:00
|
|
|
context->kerberos = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-15 11:04:17 +03:00
|
|
|
context->sspiA = &NTLM_SecurityFunctionTableA;
|
|
|
|
context->sspiW = &NTLM_SecurityFunctionTableW;
|
2017-05-11 19:51:45 +03:00
|
|
|
context->kerberos = FALSE;
|
|
|
|
}
|
|
|
|
}
|
2012-03-06 02:03:49 +04:00
|
|
|
|
2018-01-16 12:31:08 +03:00
|
|
|
static NEGOTIATE_CONTEXT* negotiate_ContextNew(void)
|
2014-06-08 00:26:57 +04:00
|
|
|
{
|
|
|
|
NEGOTIATE_CONTEXT* context;
|
2019-11-06 17:24:51 +03:00
|
|
|
context = (NEGOTIATE_CONTEXT*)calloc(1, sizeof(NEGOTIATE_CONTEXT));
|
2014-06-08 00:26:57 +04:00
|
|
|
|
|
|
|
if (!context)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
context->NegotiateFlags = 0;
|
|
|
|
context->state = NEGOTIATE_STATE_INITIAL;
|
2014-06-10 22:16:02 +04:00
|
|
|
SecInvalidateHandle(&(context->SubContext));
|
2018-01-17 11:09:58 +03:00
|
|
|
negotiate_SetSubPackage(context, KERBEROS_SSP_NAME);
|
2014-06-08 00:26:57 +04:00
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
2018-01-16 12:31:08 +03:00
|
|
|
static void negotiate_ContextFree(NEGOTIATE_CONTEXT* context)
|
2014-06-08 00:26:57 +04:00
|
|
|
{
|
|
|
|
free(context);
|
|
|
|
}
|
|
|
|
|
2022-02-15 11:41:39 +03:00
|
|
|
static BOOL negotaite_get_dword(HKEY hKey, const char* subkey, DWORD* pdwValue)
|
|
|
|
{
|
|
|
|
DWORD dwValue = 0, dwType = 0;
|
|
|
|
DWORD dwSize = sizeof(dwValue);
|
|
|
|
LONG rc = RegQueryValueExA(hKey, subkey, NULL, &dwType, (BYTE*)&dwValue, &dwSize);
|
|
|
|
|
|
|
|
if (rc != ERROR_SUCCESS)
|
|
|
|
return FALSE;
|
|
|
|
if (dwType != REG_DWORD)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
*pdwValue = dwValue;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL negotiate_get_config(BOOL* kerberos, BOOL* ntlm)
|
|
|
|
{
|
|
|
|
HKEY hKey = NULL;
|
|
|
|
LONG rc;
|
|
|
|
|
|
|
|
WINPR_ASSERT(kerberos);
|
|
|
|
WINPR_ASSERT(ntlm);
|
|
|
|
|
|
|
|
#if !defined(WITH_GSS_NO_NTLM_FALLBACK)
|
|
|
|
*ntlm = TRUE;
|
|
|
|
#else
|
|
|
|
*ntlm = FALSE;
|
|
|
|
#endif
|
|
|
|
*kerberos = TRUE;
|
|
|
|
|
|
|
|
rc = RegOpenKeyExA(HKEY_LOCAL_MACHINE, NEGO_REG_KEY, 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
|
|
|
|
if (rc == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
DWORD dwValue;
|
|
|
|
|
|
|
|
if (negotaite_get_dword(hKey, "kerberos", &dwValue))
|
|
|
|
*kerberos = (dwValue != 0) ? TRUE : FALSE;
|
|
|
|
|
|
|
|
#if !defined(WITH_GSS_NO_NTLM_FALLBACK)
|
|
|
|
if (negotaite_get_dword(hKey, "ntlm", &dwValue))
|
|
|
|
*ntlm = (dwValue != 0) ? TRUE : FALSE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY negotiate_InitializeSecurityContextW(
|
|
|
|
PCredHandle phCredential, PCtxtHandle phContext, SEC_WCHAR* pszTargetName, ULONG fContextReq,
|
|
|
|
ULONG Reserved1, ULONG TargetDataRep, PSecBufferDesc pInput, ULONG Reserved2,
|
|
|
|
PCtxtHandle phNewContext, PSecBufferDesc pOutput, PULONG pfContextAttr, PTimeStamp ptsExpiry)
|
2012-03-24 23:47:16 +04:00
|
|
|
{
|
2022-02-15 11:41:39 +03:00
|
|
|
BOOL ntlm = TRUE;
|
|
|
|
BOOL kerberos = TRUE;
|
|
|
|
SECURITY_STATUS status = SEC_E_INTERNAL_ERROR;
|
|
|
|
NEGOTIATE_CONTEXT* context = NULL;
|
|
|
|
|
|
|
|
if (!negotiate_get_config(&kerberos, &ntlm))
|
|
|
|
return status;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
context = (NEGOTIATE_CONTEXT*)sspi_SecureHandleGetLowerPointer(phContext);
|
2014-06-08 00:26:57 +04:00
|
|
|
|
|
|
|
if (!context)
|
|
|
|
{
|
|
|
|
context = negotiate_ContextNew();
|
|
|
|
|
|
|
|
if (!context)
|
|
|
|
return SEC_E_INTERNAL_ERROR;
|
|
|
|
|
|
|
|
sspi_SecureHandleSetLowerPointer(phNewContext, context);
|
2019-11-06 17:24:51 +03:00
|
|
|
sspi_SecureHandleSetUpperPointer(phNewContext, (void*)NEGO_SSP_NAME);
|
2014-06-08 00:26:57 +04:00
|
|
|
}
|
|
|
|
|
2017-05-11 19:51:45 +03:00
|
|
|
/* if Kerberos has previously failed or WITH_GSSAPI is not defined, we use NTLM directly */
|
2022-02-15 11:41:39 +03:00
|
|
|
if (kerberos && !ErrorInitContextKerberos)
|
2017-05-11 19:51:45 +03:00
|
|
|
{
|
|
|
|
if (!pInput)
|
|
|
|
{
|
2022-02-15 11:04:17 +03:00
|
|
|
context->sspiW->DeleteSecurityContext(&(context->SubContext));
|
|
|
|
SecInvalidateHandle(&context->SubContext);
|
2018-01-17 11:09:58 +03:00
|
|
|
negotiate_SetSubPackage(context, KERBEROS_SSP_NAME);
|
2017-05-11 19:51:45 +03:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
status = context->sspiW->InitializeSecurityContextW(
|
|
|
|
phCredential, &(context->SubContext), pszTargetName, fContextReq, Reserved1,
|
|
|
|
TargetDataRep, pInput, Reserved2, &(context->SubContext), pOutput, pfContextAttr,
|
|
|
|
ptsExpiry);
|
2017-05-11 19:51:45 +03:00
|
|
|
|
2022-02-15 11:04:17 +03:00
|
|
|
#if !defined(WITH_GSS_NO_NTLM_FALLBACK)
|
2022-02-15 11:41:39 +03:00
|
|
|
if (ntlm && (status == SEC_E_NO_CREDENTIALS))
|
2017-05-11 19:51:45 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "No Kerberos credentials. Retry with NTLM");
|
|
|
|
ErrorInitContextKerberos = TRUE;
|
2022-02-15 11:04:17 +03:00
|
|
|
context->sspiW->DeleteSecurityContext(&(context->SubContext));
|
|
|
|
SecInvalidateHandle(&context->SubContext);
|
2017-05-11 19:51:45 +03:00
|
|
|
}
|
2022-02-15 11:04:17 +03:00
|
|
|
#endif
|
2017-05-11 19:51:45 +03:00
|
|
|
}
|
2022-02-15 11:04:17 +03:00
|
|
|
|
2022-02-15 11:41:39 +03:00
|
|
|
if (ntlm && ErrorInitContextKerberos)
|
2017-05-11 19:51:45 +03:00
|
|
|
{
|
|
|
|
if (!pInput)
|
|
|
|
{
|
2022-02-15 11:04:17 +03:00
|
|
|
context->sspiW->DeleteSecurityContext(&(context->SubContext));
|
|
|
|
SecInvalidateHandle(&context->SubContext);
|
2018-02-13 13:00:56 +03:00
|
|
|
negotiate_SetSubPackage(context, NTLM_SSP_NAME);
|
2017-05-11 19:51:45 +03:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
status = context->sspiW->InitializeSecurityContextW(
|
|
|
|
phCredential, &(context->SubContext), pszTargetName, fContextReq, Reserved1,
|
|
|
|
TargetDataRep, pInput, Reserved2, &(context->SubContext), pOutput, pfContextAttr,
|
|
|
|
ptsExpiry);
|
2017-05-11 19:51:45 +03:00
|
|
|
}
|
2014-06-08 00:26:57 +04:00
|
|
|
|
|
|
|
return status;
|
2012-03-24 23:47:16 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY negotiate_InitializeSecurityContextA(
|
|
|
|
PCredHandle phCredential, PCtxtHandle phContext, SEC_CHAR* pszTargetName, ULONG fContextReq,
|
|
|
|
ULONG Reserved1, ULONG TargetDataRep, PSecBufferDesc pInput, ULONG Reserved2,
|
|
|
|
PCtxtHandle phNewContext, PSecBufferDesc pOutput, PULONG pfContextAttr, PTimeStamp ptsExpiry)
|
2012-03-06 02:03:49 +04:00
|
|
|
{
|
2022-02-15 11:41:39 +03:00
|
|
|
BOOL ntlm = TRUE;
|
|
|
|
BOOL kerberos = TRUE;
|
|
|
|
SECURITY_STATUS status = SEC_E_INTERNAL_ERROR;
|
|
|
|
NEGOTIATE_CONTEXT* context = NULL;
|
|
|
|
|
|
|
|
if (!negotiate_get_config(&kerberos, &ntlm))
|
|
|
|
return status;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
context = (NEGOTIATE_CONTEXT*)sspi_SecureHandleGetLowerPointer(phContext);
|
2012-03-06 02:03:49 +04:00
|
|
|
|
|
|
|
if (!context)
|
|
|
|
{
|
|
|
|
context = negotiate_ContextNew();
|
|
|
|
|
2014-06-08 00:26:57 +04:00
|
|
|
if (!context)
|
|
|
|
return SEC_E_INTERNAL_ERROR;
|
|
|
|
|
2012-03-06 02:03:49 +04:00
|
|
|
sspi_SecureHandleSetLowerPointer(phNewContext, context);
|
2019-11-06 17:24:51 +03:00
|
|
|
sspi_SecureHandleSetUpperPointer(phNewContext, (void*)NEGO_SSP_NAME);
|
2012-03-06 02:03:49 +04:00
|
|
|
}
|
|
|
|
|
2017-05-11 19:51:45 +03:00
|
|
|
/* if Kerberos has previously failed or WITH_GSSAPI is not defined, we use NTLM directly */
|
2022-02-15 11:41:39 +03:00
|
|
|
if (kerberos && !ErrorInitContextKerberos)
|
2017-05-11 19:51:45 +03:00
|
|
|
{
|
|
|
|
if (!pInput)
|
|
|
|
{
|
2022-02-15 11:04:17 +03:00
|
|
|
context->sspiA->DeleteSecurityContext(&(context->SubContext));
|
|
|
|
SecInvalidateHandle(&context->SubContext);
|
2018-01-17 11:09:58 +03:00
|
|
|
negotiate_SetSubPackage(context, KERBEROS_SSP_NAME);
|
2017-05-11 19:51:45 +03:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
status = context->sspiA->InitializeSecurityContextA(
|
|
|
|
phCredential, &(context->SubContext), pszTargetName, fContextReq, Reserved1,
|
|
|
|
TargetDataRep, pInput, Reserved2, &(context->SubContext), pOutput, pfContextAttr,
|
|
|
|
ptsExpiry);
|
2017-05-11 19:51:45 +03:00
|
|
|
|
2022-02-15 11:04:17 +03:00
|
|
|
#if !defined(WITH_GSS_NO_NTLM_FALLBACK)
|
2022-02-15 11:41:39 +03:00
|
|
|
if (ntlm && (status == SEC_E_NO_CREDENTIALS))
|
2017-05-11 19:51:45 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "No Kerberos credentials. Retry with NTLM");
|
|
|
|
ErrorInitContextKerberos = TRUE;
|
|
|
|
context->sspiA->DeleteSecurityContext(&(context->SubContext));
|
2022-02-15 11:04:17 +03:00
|
|
|
SecInvalidateHandle(&context->SubContext);
|
2017-05-11 19:51:45 +03:00
|
|
|
}
|
2022-02-15 11:04:17 +03:00
|
|
|
#endif
|
2017-05-11 19:51:45 +03:00
|
|
|
}
|
2022-02-15 11:04:17 +03:00
|
|
|
|
2022-02-15 11:41:39 +03:00
|
|
|
if (ntlm && ErrorInitContextKerberos)
|
2017-05-11 19:51:45 +03:00
|
|
|
{
|
|
|
|
if (!pInput)
|
|
|
|
{
|
|
|
|
context->sspiA->DeleteSecurityContext(&(context->SubContext));
|
2022-02-15 11:04:17 +03:00
|
|
|
SecInvalidateHandle(&context->SubContext);
|
2018-02-13 13:00:56 +03:00
|
|
|
negotiate_SetSubPackage(context, NTLM_SSP_NAME);
|
2017-05-11 19:51:45 +03:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
status = context->sspiA->InitializeSecurityContextA(
|
|
|
|
phCredential, &(context->SubContext), pszTargetName, fContextReq, Reserved1,
|
|
|
|
TargetDataRep, pInput, Reserved2, &(context->SubContext), pOutput, pfContextAttr,
|
|
|
|
ptsExpiry);
|
2017-05-11 19:51:45 +03:00
|
|
|
}
|
2014-06-08 00:26:57 +04:00
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY negotiate_AcceptSecurityContext(
|
|
|
|
PCredHandle phCredential, PCtxtHandle phContext, PSecBufferDesc pInput, ULONG fContextReq,
|
|
|
|
ULONG TargetDataRep, PCtxtHandle phNewContext, PSecBufferDesc pOutput, PULONG pfContextAttr,
|
|
|
|
PTimeStamp ptsTimeStamp)
|
2014-06-08 00:26:57 +04:00
|
|
|
{
|
|
|
|
SECURITY_STATUS status;
|
|
|
|
NEGOTIATE_CONTEXT* context;
|
2019-11-06 17:24:51 +03:00
|
|
|
context = (NEGOTIATE_CONTEXT*)sspi_SecureHandleGetLowerPointer(phContext);
|
2014-06-08 00:26:57 +04:00
|
|
|
|
|
|
|
if (!context)
|
2012-03-06 02:03:49 +04:00
|
|
|
{
|
2014-06-08 00:26:57 +04:00
|
|
|
context = negotiate_ContextNew();
|
2012-03-06 02:03:49 +04:00
|
|
|
|
2014-06-08 00:26:57 +04:00
|
|
|
if (!context)
|
|
|
|
return SEC_E_INTERNAL_ERROR;
|
2012-03-06 02:03:49 +04:00
|
|
|
|
2014-06-08 00:26:57 +04:00
|
|
|
sspi_SecureHandleSetLowerPointer(phNewContext, context);
|
2019-11-06 17:24:51 +03:00
|
|
|
sspi_SecureHandleSetUpperPointer(phNewContext, (void*)NEGO_SSP_NAME);
|
2014-06-08 00:26:57 +04:00
|
|
|
}
|
2012-03-06 02:03:49 +04:00
|
|
|
|
2018-02-13 13:00:56 +03:00
|
|
|
negotiate_SetSubPackage(context, NTLM_SSP_NAME); /* server-side Kerberos not yet implemented */
|
2019-11-06 17:24:51 +03:00
|
|
|
status = context->sspiA->AcceptSecurityContext(
|
|
|
|
phCredential, &(context->SubContext), pInput, fContextReq, TargetDataRep,
|
|
|
|
&(context->SubContext), pOutput, pfContextAttr, ptsTimeStamp);
|
2014-06-08 00:26:57 +04:00
|
|
|
|
2015-07-07 18:17:29 +03:00
|
|
|
if (status != SEC_E_OK)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "AcceptSecurityContext status %s [0x%08" PRIX32 "]",
|
2017-05-11 19:51:45 +03:00
|
|
|
GetSecurityStatusString(status), status);
|
2015-07-07 18:17:29 +03:00
|
|
|
}
|
2017-05-11 19:51:45 +03:00
|
|
|
|
2015-07-07 18:17:29 +03:00
|
|
|
return status;
|
2012-03-06 02:03:49 +04:00
|
|
|
}
|
|
|
|
|
2018-01-16 12:31:08 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY negotiate_CompleteAuthToken(PCtxtHandle phContext,
|
2019-11-06 17:24:51 +03:00
|
|
|
PSecBufferDesc pToken)
|
2012-03-06 02:03:49 +04:00
|
|
|
{
|
|
|
|
NEGOTIATE_CONTEXT* context;
|
2014-06-08 00:26:57 +04:00
|
|
|
SECURITY_STATUS status = SEC_E_OK;
|
2019-11-06 17:24:51 +03:00
|
|
|
context = (NEGOTIATE_CONTEXT*)sspi_SecureHandleGetLowerPointer(phContext);
|
2012-03-06 02:03:49 +04:00
|
|
|
|
2014-06-07 01:20:34 +04:00
|
|
|
if (!context)
|
2014-06-08 00:26:57 +04:00
|
|
|
return SEC_E_INVALID_HANDLE;
|
2014-06-07 01:20:34 +04:00
|
|
|
|
2014-06-08 00:26:57 +04:00
|
|
|
if (context->sspiW->CompleteAuthToken)
|
2015-05-15 14:02:40 +03:00
|
|
|
status = context->sspiW->CompleteAuthToken(&(context->SubContext), pToken);
|
2012-03-06 02:03:49 +04:00
|
|
|
|
2014-06-08 00:26:57 +04:00
|
|
|
return status;
|
2012-03-06 02:03:49 +04:00
|
|
|
}
|
|
|
|
|
2018-01-16 12:31:08 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY negotiate_DeleteSecurityContext(PCtxtHandle phContext)
|
2012-03-06 02:03:49 +04:00
|
|
|
{
|
2014-06-08 00:26:57 +04:00
|
|
|
NEGOTIATE_CONTEXT* context;
|
|
|
|
SECURITY_STATUS status = SEC_E_OK;
|
2019-11-06 17:24:51 +03:00
|
|
|
context = (NEGOTIATE_CONTEXT*)sspi_SecureHandleGetLowerPointer(phContext);
|
2014-06-08 00:26:57 +04:00
|
|
|
|
2012-03-06 02:03:49 +04:00
|
|
|
if (!context)
|
2014-06-08 00:26:57 +04:00
|
|
|
return SEC_E_INVALID_HANDLE;
|
2012-03-06 02:03:49 +04:00
|
|
|
|
2014-06-08 00:26:57 +04:00
|
|
|
if (context->sspiW->DeleteSecurityContext)
|
2014-06-10 22:16:02 +04:00
|
|
|
status = context->sspiW->DeleteSecurityContext(&(context->SubContext));
|
2014-06-08 00:26:57 +04:00
|
|
|
|
|
|
|
negotiate_ContextFree(context);
|
|
|
|
return status;
|
2012-03-06 02:03:49 +04:00
|
|
|
}
|
|
|
|
|
2018-01-16 12:31:08 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY negotiate_ImpersonateSecurityContext(PCtxtHandle phContext)
|
2014-06-11 00:38:16 +04:00
|
|
|
{
|
|
|
|
NEGOTIATE_CONTEXT* context;
|
|
|
|
SECURITY_STATUS status = SEC_E_OK;
|
2019-11-06 17:24:51 +03:00
|
|
|
context = (NEGOTIATE_CONTEXT*)sspi_SecureHandleGetLowerPointer(phContext);
|
2014-06-11 00:38:16 +04:00
|
|
|
|
|
|
|
if (!phContext)
|
|
|
|
return SEC_E_INVALID_HANDLE;
|
|
|
|
|
|
|
|
if (context->sspiW->ImpersonateSecurityContext)
|
|
|
|
status = context->sspiW->ImpersonateSecurityContext(&(context->SubContext));
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2018-01-16 12:31:08 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY negotiate_RevertSecurityContext(PCtxtHandle phContext)
|
2014-06-11 00:38:16 +04:00
|
|
|
{
|
|
|
|
NEGOTIATE_CONTEXT* context;
|
|
|
|
SECURITY_STATUS status = SEC_E_OK;
|
2019-11-06 17:24:51 +03:00
|
|
|
context = (NEGOTIATE_CONTEXT*)sspi_SecureHandleGetLowerPointer(phContext);
|
2014-06-11 00:38:16 +04:00
|
|
|
|
|
|
|
if (!phContext)
|
|
|
|
return SEC_E_INVALID_HANDLE;
|
|
|
|
|
|
|
|
if (context->sspiW->RevertSecurityContext)
|
|
|
|
status = context->sspiW->RevertSecurityContext(&(context->SubContext));
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2018-01-16 12:31:08 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY negotiate_QueryContextAttributesW(PCtxtHandle phContext,
|
2019-11-06 17:24:51 +03:00
|
|
|
ULONG ulAttribute, void* pBuffer)
|
2012-03-06 02:03:49 +04:00
|
|
|
{
|
2014-06-08 00:26:57 +04:00
|
|
|
NEGOTIATE_CONTEXT* context;
|
|
|
|
SECURITY_STATUS status = SEC_E_OK;
|
2019-11-06 17:24:51 +03:00
|
|
|
context = (NEGOTIATE_CONTEXT*)sspi_SecureHandleGetLowerPointer(phContext);
|
2014-06-08 00:26:57 +04:00
|
|
|
|
2012-03-06 02:03:49 +04:00
|
|
|
if (!phContext)
|
|
|
|
return SEC_E_INVALID_HANDLE;
|
|
|
|
|
|
|
|
if (!pBuffer)
|
|
|
|
return SEC_E_INSUFFICIENT_MEMORY;
|
|
|
|
|
2014-06-08 00:26:57 +04:00
|
|
|
if (context->sspiW->QueryContextAttributesW)
|
2019-11-06 17:24:51 +03:00
|
|
|
status =
|
|
|
|
context->sspiW->QueryContextAttributesW(&(context->SubContext), ulAttribute, pBuffer);
|
2014-06-08 00:26:57 +04:00
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2018-01-16 12:31:08 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY negotiate_QueryContextAttributesA(PCtxtHandle phContext,
|
2019-11-06 17:24:51 +03:00
|
|
|
ULONG ulAttribute, void* pBuffer)
|
2014-06-08 01:08:07 +04:00
|
|
|
{
|
|
|
|
NEGOTIATE_CONTEXT* context;
|
|
|
|
SECURITY_STATUS status = SEC_E_OK;
|
2019-11-06 17:24:51 +03:00
|
|
|
context = (NEGOTIATE_CONTEXT*)sspi_SecureHandleGetLowerPointer(phContext);
|
2014-06-08 01:08:07 +04:00
|
|
|
|
|
|
|
if (!phContext)
|
|
|
|
return SEC_E_INVALID_HANDLE;
|
|
|
|
|
2014-06-11 00:38:16 +04:00
|
|
|
if (!pBuffer)
|
|
|
|
return SEC_E_INSUFFICIENT_MEMORY;
|
|
|
|
|
|
|
|
if (context->sspiA->QueryContextAttributesA)
|
2019-11-06 17:24:51 +03:00
|
|
|
status =
|
|
|
|
context->sspiA->QueryContextAttributesA(&(context->SubContext), ulAttribute, pBuffer);
|
2014-06-08 01:08:07 +04:00
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2018-01-16 12:31:08 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY negotiate_SetContextAttributesW(PCtxtHandle phContext,
|
2019-11-06 17:24:51 +03:00
|
|
|
ULONG ulAttribute, void* pBuffer,
|
|
|
|
ULONG cbBuffer)
|
2014-06-08 01:08:07 +04:00
|
|
|
{
|
|
|
|
NEGOTIATE_CONTEXT* context;
|
|
|
|
SECURITY_STATUS status = SEC_E_OK;
|
2019-11-06 17:24:51 +03:00
|
|
|
context = (NEGOTIATE_CONTEXT*)sspi_SecureHandleGetLowerPointer(phContext);
|
2014-06-08 01:08:07 +04:00
|
|
|
|
|
|
|
if (!phContext)
|
|
|
|
return SEC_E_INVALID_HANDLE;
|
|
|
|
|
2014-06-11 00:38:16 +04:00
|
|
|
if (!pBuffer)
|
|
|
|
return SEC_E_INSUFFICIENT_MEMORY;
|
|
|
|
|
|
|
|
if (context->sspiW->SetContextAttributesW)
|
2017-05-11 19:51:45 +03:00
|
|
|
status = context->sspiW->SetContextAttributesW(&(context->SubContext), ulAttribute, pBuffer,
|
2019-11-06 17:24:51 +03:00
|
|
|
cbBuffer);
|
2014-06-08 01:08:07 +04:00
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2018-01-16 12:31:08 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY negotiate_SetContextAttributesA(PCtxtHandle phContext,
|
2019-11-06 17:24:51 +03:00
|
|
|
ULONG ulAttribute, void* pBuffer,
|
|
|
|
ULONG cbBuffer)
|
2014-06-08 00:26:57 +04:00
|
|
|
{
|
|
|
|
NEGOTIATE_CONTEXT* context;
|
|
|
|
SECURITY_STATUS status = SEC_E_OK;
|
2019-11-06 17:24:51 +03:00
|
|
|
context = (NEGOTIATE_CONTEXT*)sspi_SecureHandleGetLowerPointer(phContext);
|
2014-06-08 00:26:57 +04:00
|
|
|
|
|
|
|
if (!phContext)
|
|
|
|
return SEC_E_INVALID_HANDLE;
|
|
|
|
|
|
|
|
if (!pBuffer)
|
|
|
|
return SEC_E_INSUFFICIENT_MEMORY;
|
|
|
|
|
2014-06-11 00:38:16 +04:00
|
|
|
if (context->sspiA->SetContextAttributesA)
|
2017-05-11 19:51:45 +03:00
|
|
|
status = context->sspiA->SetContextAttributesA(&(context->SubContext), ulAttribute, pBuffer,
|
2019-11-06 17:24:51 +03:00
|
|
|
cbBuffer);
|
2014-06-08 00:26:57 +04:00
|
|
|
|
|
|
|
return status;
|
2012-03-06 02:03:49 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY negotiate_AcquireCredentialsHandleW(
|
|
|
|
SEC_WCHAR* pszPrincipal, SEC_WCHAR* pszPackage, ULONG fCredentialUse, void* pvLogonID,
|
|
|
|
void* pAuthData, SEC_GET_KEY_FN pGetKeyFn, void* pvGetKeyArgument, PCredHandle phCredential,
|
|
|
|
PTimeStamp ptsExpiry)
|
2012-03-24 23:47:16 +04:00
|
|
|
{
|
2014-06-09 23:25:00 +04:00
|
|
|
SSPI_CREDENTIALS* credentials;
|
2014-06-08 00:26:57 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if ((fCredentialUse != SECPKG_CRED_OUTBOUND) && (fCredentialUse != SECPKG_CRED_INBOUND) &&
|
2017-05-11 19:51:45 +03:00
|
|
|
(fCredentialUse != SECPKG_CRED_BOTH))
|
2014-06-08 00:26:57 +04:00
|
|
|
{
|
2014-06-09 23:25:00 +04:00
|
|
|
return SEC_E_INVALID_PARAMETER;
|
2014-06-08 01:08:07 +04:00
|
|
|
}
|
|
|
|
|
2014-06-09 23:25:00 +04:00
|
|
|
credentials = sspi_CredentialsNew();
|
|
|
|
if (!credentials)
|
|
|
|
return SEC_E_INTERNAL_ERROR;
|
2014-06-08 00:26:57 +04:00
|
|
|
|
2014-06-09 23:25:00 +04:00
|
|
|
credentials->fCredentialUse = fCredentialUse;
|
|
|
|
credentials->pGetKeyFn = pGetKeyFn;
|
|
|
|
credentials->pvGetKeyArgument = pvGetKeyArgument;
|
2014-06-08 00:26:57 +04:00
|
|
|
|
2022-02-02 01:23:34 +03:00
|
|
|
if (pAuthData)
|
|
|
|
{
|
|
|
|
SEC_WINNT_AUTH_IDENTITY_EXW* identityEx = (SEC_WINNT_AUTH_IDENTITY_EXW*)pAuthData;
|
|
|
|
BOOL treated = FALSE;
|
|
|
|
|
|
|
|
SEC_WINNT_AUTH_IDENTITY srcIdentity;
|
|
|
|
if (identityEx->Version == SEC_WINNT_AUTH_IDENTITY_VERSION)
|
|
|
|
{
|
|
|
|
if (identityEx->Length >= sizeof(*identityEx))
|
|
|
|
{
|
|
|
|
srcIdentity.User = (UINT16*)identityEx->User;
|
|
|
|
srcIdentity.UserLength = identityEx->UserLength;
|
|
|
|
srcIdentity.Domain = (UINT16*)identityEx->Domain;
|
|
|
|
srcIdentity.DomainLength = identityEx->DomainLength;
|
|
|
|
srcIdentity.Password = (UINT16*)identityEx->Password;
|
|
|
|
srcIdentity.PasswordLength = identityEx->PasswordLength;
|
|
|
|
srcIdentity.Flags = identityEx->Flags;
|
|
|
|
|
|
|
|
if (!sspi_CopyAuthIdentity(&credentials->identity, &srcIdentity))
|
|
|
|
return SEC_E_INSUFFICIENT_MEMORY;
|
|
|
|
|
|
|
|
if (identityEx->Length == sizeof(SEC_WINNT_AUTH_IDENTITY_WINPRA))
|
|
|
|
{
|
|
|
|
SEC_WINNT_AUTH_IDENTITY_WINPRW* identityWinpr =
|
|
|
|
(SEC_WINNT_AUTH_IDENTITY_WINPRW*)pAuthData;
|
|
|
|
credentials->kerbSettings = identityWinpr->kerberosSettings;
|
|
|
|
}
|
|
|
|
treated = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!treated)
|
|
|
|
{
|
|
|
|
SEC_WINNT_AUTH_IDENTITY* identity = (SEC_WINNT_AUTH_IDENTITY*)pAuthData;
|
|
|
|
sspi_CopyAuthIdentity(&(credentials->identity), identity);
|
|
|
|
}
|
|
|
|
}
|
2014-06-08 00:26:57 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
sspi_SecureHandleSetLowerPointer(phCredential, (void*)credentials);
|
|
|
|
sspi_SecureHandleSetUpperPointer(phCredential, (void*)NEGO_SSP_NAME);
|
2014-06-09 23:25:00 +04:00
|
|
|
return SEC_E_OK;
|
2012-03-24 23:47:16 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY negotiate_AcquireCredentialsHandleA(
|
|
|
|
SEC_CHAR* pszPrincipal, SEC_CHAR* pszPackage, ULONG fCredentialUse, void* pvLogonID,
|
|
|
|
void* pAuthData, SEC_GET_KEY_FN pGetKeyFn, void* pvGetKeyArgument, PCredHandle phCredential,
|
|
|
|
PTimeStamp ptsExpiry)
|
2012-03-06 02:03:49 +04:00
|
|
|
{
|
2014-06-09 23:25:00 +04:00
|
|
|
SSPI_CREDENTIALS* credentials;
|
2012-03-06 02:03:49 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if ((fCredentialUse != SECPKG_CRED_OUTBOUND) && (fCredentialUse != SECPKG_CRED_INBOUND) &&
|
2017-05-11 19:51:45 +03:00
|
|
|
(fCredentialUse != SECPKG_CRED_BOTH))
|
2012-03-06 02:03:49 +04:00
|
|
|
{
|
2014-06-09 23:25:00 +04:00
|
|
|
return SEC_E_INVALID_PARAMETER;
|
2014-06-08 01:08:07 +04:00
|
|
|
}
|
|
|
|
|
2014-06-09 23:25:00 +04:00
|
|
|
credentials = sspi_CredentialsNew();
|
2014-06-07 01:20:34 +04:00
|
|
|
|
2014-06-09 23:25:00 +04:00
|
|
|
if (!credentials)
|
|
|
|
return SEC_E_INTERNAL_ERROR;
|
2012-03-06 02:03:49 +04:00
|
|
|
|
2014-06-09 23:25:00 +04:00
|
|
|
credentials->fCredentialUse = fCredentialUse;
|
|
|
|
credentials->pGetKeyFn = pGetKeyFn;
|
|
|
|
credentials->pvGetKeyArgument = pvGetKeyArgument;
|
2012-03-06 02:03:49 +04:00
|
|
|
|
2022-02-02 01:23:34 +03:00
|
|
|
if (pAuthData)
|
|
|
|
{
|
|
|
|
SEC_WINNT_AUTH_IDENTITY_EXA* identityEx = (SEC_WINNT_AUTH_IDENTITY_EXA*)pAuthData;
|
|
|
|
BOOL treated = FALSE;
|
|
|
|
|
|
|
|
SEC_WINNT_AUTH_IDENTITY srcIdentity;
|
|
|
|
if (identityEx->Version == SEC_WINNT_AUTH_IDENTITY_VERSION)
|
|
|
|
{
|
|
|
|
if (identityEx->Length >= sizeof(*identityEx))
|
|
|
|
{
|
|
|
|
srcIdentity.User = (UINT16*)identityEx->User;
|
|
|
|
srcIdentity.UserLength = identityEx->UserLength;
|
|
|
|
srcIdentity.Domain = (UINT16*)identityEx->Domain;
|
|
|
|
srcIdentity.DomainLength = identityEx->DomainLength;
|
|
|
|
srcIdentity.Password = (UINT16*)identityEx->Password;
|
|
|
|
srcIdentity.PasswordLength = identityEx->PasswordLength;
|
|
|
|
srcIdentity.Flags = identityEx->Flags;
|
|
|
|
|
|
|
|
if (!sspi_CopyAuthIdentity(&credentials->identity, &srcIdentity))
|
|
|
|
return SEC_E_INSUFFICIENT_MEMORY;
|
|
|
|
|
|
|
|
if (identityEx->Length == sizeof(SEC_WINNT_AUTH_IDENTITY_WINPRA))
|
|
|
|
{
|
|
|
|
SEC_WINNT_AUTH_IDENTITY_WINPRA* identityWinpr =
|
|
|
|
(SEC_WINNT_AUTH_IDENTITY_WINPRA*)pAuthData;
|
|
|
|
credentials->kerbSettings = identityWinpr->kerberosSettings;
|
|
|
|
}
|
|
|
|
treated = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!treated)
|
|
|
|
{
|
|
|
|
SEC_WINNT_AUTH_IDENTITY* identity = (SEC_WINNT_AUTH_IDENTITY*)pAuthData;
|
|
|
|
sspi_CopyAuthIdentity(&(credentials->identity), identity);
|
|
|
|
}
|
|
|
|
}
|
2012-03-06 02:03:49 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
sspi_SecureHandleSetLowerPointer(phCredential, (void*)credentials);
|
|
|
|
sspi_SecureHandleSetUpperPointer(phCredential, (void*)NEGO_SSP_NAME);
|
2014-06-09 23:25:00 +04:00
|
|
|
return SEC_E_OK;
|
2012-03-06 02:03:49 +04:00
|
|
|
}
|
|
|
|
|
2018-01-16 12:31:08 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY negotiate_QueryCredentialsAttributesW(PCredHandle phCredential,
|
2019-11-06 17:24:51 +03:00
|
|
|
ULONG ulAttribute,
|
|
|
|
void* pBuffer)
|
2012-03-24 23:47:16 +04:00
|
|
|
{
|
2020-08-10 15:42:05 +03:00
|
|
|
WLog_ERR(TAG, "[%s]: TODO: Implement", __FUNCTION__);
|
2014-06-08 00:26:57 +04:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
2012-03-24 23:47:16 +04:00
|
|
|
}
|
|
|
|
|
2018-01-16 12:31:08 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY negotiate_QueryCredentialsAttributesA(PCredHandle phCredential,
|
2019-11-06 17:24:51 +03:00
|
|
|
ULONG ulAttribute,
|
|
|
|
void* pBuffer)
|
2012-03-06 02:03:49 +04:00
|
|
|
{
|
2020-08-10 15:42:05 +03:00
|
|
|
WLog_ERR(TAG, "[%s]: TODO: Implement", __FUNCTION__);
|
2012-03-06 02:03:49 +04:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
|
|
|
}
|
|
|
|
|
2018-01-16 12:31:08 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY negotiate_FreeCredentialsHandle(PCredHandle phCredential)
|
2012-03-06 02:03:49 +04:00
|
|
|
{
|
2014-06-09 23:25:00 +04:00
|
|
|
SSPI_CREDENTIALS* credentials;
|
2012-03-06 02:03:49 +04:00
|
|
|
|
|
|
|
if (!phCredential)
|
|
|
|
return SEC_E_INVALID_HANDLE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
credentials = (SSPI_CREDENTIALS*)sspi_SecureHandleGetLowerPointer(phCredential);
|
2012-03-06 02:03:49 +04:00
|
|
|
|
|
|
|
if (!credentials)
|
|
|
|
return SEC_E_INVALID_HANDLE;
|
|
|
|
|
|
|
|
sspi_CredentialsFree(credentials);
|
2017-07-18 14:23:22 +03:00
|
|
|
sspi_SecureHandleInvalidate(phCredential);
|
2012-03-06 02:03:49 +04:00
|
|
|
return SEC_E_OK;
|
|
|
|
}
|
|
|
|
|
2018-01-16 12:31:08 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY negotiate_EncryptMessage(PCtxtHandle phContext, ULONG fQOP,
|
2019-11-06 17:24:51 +03:00
|
|
|
PSecBufferDesc pMessage,
|
|
|
|
ULONG MessageSeqNo)
|
2012-03-06 02:03:49 +04:00
|
|
|
{
|
2014-06-08 00:26:57 +04:00
|
|
|
NEGOTIATE_CONTEXT* context;
|
|
|
|
SECURITY_STATUS status = SEC_E_UNSUPPORTED_FUNCTION;
|
2019-11-06 17:24:51 +03:00
|
|
|
context = (NEGOTIATE_CONTEXT*)sspi_SecureHandleGetLowerPointer(phContext);
|
2014-06-08 00:26:57 +04:00
|
|
|
|
|
|
|
if (context->sspiW->EncryptMessage)
|
2019-11-06 17:24:51 +03:00
|
|
|
status =
|
|
|
|
context->sspiW->EncryptMessage(&(context->SubContext), fQOP, pMessage, MessageSeqNo);
|
2020-08-10 15:42:05 +03:00
|
|
|
else
|
|
|
|
WLog_WARN(TAG, "[%s] SSPI implementation of function is missing", __FUNCTION__);
|
2014-06-08 00:26:57 +04:00
|
|
|
return status;
|
2012-03-06 02:03:49 +04:00
|
|
|
}
|
|
|
|
|
2018-01-16 12:31:08 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY negotiate_DecryptMessage(PCtxtHandle phContext,
|
2019-11-06 17:24:51 +03:00
|
|
|
PSecBufferDesc pMessage,
|
|
|
|
ULONG MessageSeqNo, ULONG* pfQOP)
|
2012-03-06 02:03:49 +04:00
|
|
|
{
|
2014-06-08 00:26:57 +04:00
|
|
|
NEGOTIATE_CONTEXT* context;
|
|
|
|
SECURITY_STATUS status = SEC_E_UNSUPPORTED_FUNCTION;
|
2019-11-06 17:24:51 +03:00
|
|
|
context = (NEGOTIATE_CONTEXT*)sspi_SecureHandleGetLowerPointer(phContext);
|
2014-06-08 00:26:57 +04:00
|
|
|
|
|
|
|
if (context->sspiW->DecryptMessage)
|
2019-11-06 17:24:51 +03:00
|
|
|
status =
|
|
|
|
context->sspiW->DecryptMessage(&(context->SubContext), pMessage, MessageSeqNo, pfQOP);
|
2020-08-10 15:42:05 +03:00
|
|
|
else
|
|
|
|
WLog_WARN(TAG, "[%s] SSPI implementation of function is missing", __FUNCTION__);
|
2014-06-08 00:26:57 +04:00
|
|
|
return status;
|
2012-03-06 02:03:49 +04:00
|
|
|
}
|
|
|
|
|
2018-01-16 12:31:08 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY negotiate_MakeSignature(PCtxtHandle phContext, ULONG fQOP,
|
2019-11-06 17:24:51 +03:00
|
|
|
PSecBufferDesc pMessage,
|
|
|
|
ULONG MessageSeqNo)
|
2012-03-06 02:03:49 +04:00
|
|
|
{
|
2014-06-08 00:26:57 +04:00
|
|
|
NEGOTIATE_CONTEXT* context;
|
|
|
|
SECURITY_STATUS status = SEC_E_UNSUPPORTED_FUNCTION;
|
2019-11-06 17:24:51 +03:00
|
|
|
context = (NEGOTIATE_CONTEXT*)sspi_SecureHandleGetLowerPointer(phContext);
|
2014-06-08 00:26:57 +04:00
|
|
|
|
|
|
|
if (context->sspiW->MakeSignature)
|
2019-11-06 17:24:51 +03:00
|
|
|
status =
|
|
|
|
context->sspiW->MakeSignature(&(context->SubContext), fQOP, pMessage, MessageSeqNo);
|
2020-08-10 15:42:05 +03:00
|
|
|
else
|
|
|
|
WLog_WARN(TAG, "[%s] SSPI implementation of function is missing", __FUNCTION__);
|
2014-06-08 00:26:57 +04:00
|
|
|
return status;
|
2012-03-06 02:03:49 +04:00
|
|
|
}
|
|
|
|
|
2018-01-16 12:31:08 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY negotiate_VerifySignature(PCtxtHandle phContext,
|
2019-11-06 17:24:51 +03:00
|
|
|
PSecBufferDesc pMessage,
|
|
|
|
ULONG MessageSeqNo, ULONG* pfQOP)
|
2012-03-06 02:03:49 +04:00
|
|
|
{
|
2014-06-08 00:26:57 +04:00
|
|
|
NEGOTIATE_CONTEXT* context;
|
|
|
|
SECURITY_STATUS status = SEC_E_UNSUPPORTED_FUNCTION;
|
2019-11-06 17:24:51 +03:00
|
|
|
context = (NEGOTIATE_CONTEXT*)sspi_SecureHandleGetLowerPointer(phContext);
|
2014-06-08 00:26:57 +04:00
|
|
|
|
|
|
|
if (context->sspiW->VerifySignature)
|
2019-11-06 17:24:51 +03:00
|
|
|
status =
|
|
|
|
context->sspiW->VerifySignature(&(context->SubContext), pMessage, MessageSeqNo, pfQOP);
|
2020-08-10 15:42:05 +03:00
|
|
|
else
|
|
|
|
WLog_WARN(TAG, "[%s] SSPI implementation of function is missing", __FUNCTION__);
|
2014-06-08 00:26:57 +04:00
|
|
|
return status;
|
2012-03-06 02:03:49 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
const SecurityFunctionTableA NEGOTIATE_SecurityFunctionTableA = {
|
|
|
|
1, /* dwVersion */
|
|
|
|
NULL, /* EnumerateSecurityPackages */
|
2012-03-24 09:01:28 +04:00
|
|
|
negotiate_QueryCredentialsAttributesA, /* QueryCredentialsAttributes */
|
2019-11-06 17:24:51 +03:00
|
|
|
negotiate_AcquireCredentialsHandleA, /* AcquireCredentialsHandle */
|
|
|
|
negotiate_FreeCredentialsHandle, /* FreeCredentialsHandle */
|
|
|
|
NULL, /* Reserved2 */
|
|
|
|
negotiate_InitializeSecurityContextA, /* InitializeSecurityContext */
|
|
|
|
negotiate_AcceptSecurityContext, /* AcceptSecurityContext */
|
|
|
|
negotiate_CompleteAuthToken, /* CompleteAuthToken */
|
|
|
|
negotiate_DeleteSecurityContext, /* DeleteSecurityContext */
|
|
|
|
NULL, /* ApplyControlToken */
|
|
|
|
negotiate_QueryContextAttributesA, /* QueryContextAttributes */
|
|
|
|
negotiate_ImpersonateSecurityContext, /* ImpersonateSecurityContext */
|
|
|
|
negotiate_RevertSecurityContext, /* RevertSecurityContext */
|
|
|
|
negotiate_MakeSignature, /* MakeSignature */
|
|
|
|
negotiate_VerifySignature, /* VerifySignature */
|
|
|
|
NULL, /* FreeContextBuffer */
|
|
|
|
NULL, /* QuerySecurityPackageInfo */
|
|
|
|
NULL, /* Reserved3 */
|
|
|
|
NULL, /* Reserved4 */
|
|
|
|
NULL, /* ExportSecurityContext */
|
|
|
|
NULL, /* ImportSecurityContext */
|
|
|
|
NULL, /* AddCredentials */
|
|
|
|
NULL, /* Reserved8 */
|
|
|
|
NULL, /* QuerySecurityContextToken */
|
|
|
|
negotiate_EncryptMessage, /* EncryptMessage */
|
|
|
|
negotiate_DecryptMessage, /* DecryptMessage */
|
|
|
|
negotiate_SetContextAttributesA, /* SetContextAttributes */
|
2012-03-24 23:47:16 +04:00
|
|
|
};
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
const SecurityFunctionTableW NEGOTIATE_SecurityFunctionTableW = {
|
|
|
|
1, /* dwVersion */
|
|
|
|
NULL, /* EnumerateSecurityPackages */
|
2012-03-24 23:47:16 +04:00
|
|
|
negotiate_QueryCredentialsAttributesW, /* QueryCredentialsAttributes */
|
2019-11-06 17:24:51 +03:00
|
|
|
negotiate_AcquireCredentialsHandleW, /* AcquireCredentialsHandle */
|
|
|
|
negotiate_FreeCredentialsHandle, /* FreeCredentialsHandle */
|
|
|
|
NULL, /* Reserved2 */
|
|
|
|
negotiate_InitializeSecurityContextW, /* InitializeSecurityContext */
|
|
|
|
negotiate_AcceptSecurityContext, /* AcceptSecurityContext */
|
|
|
|
negotiate_CompleteAuthToken, /* CompleteAuthToken */
|
|
|
|
negotiate_DeleteSecurityContext, /* DeleteSecurityContext */
|
|
|
|
NULL, /* ApplyControlToken */
|
|
|
|
negotiate_QueryContextAttributesW, /* QueryContextAttributes */
|
|
|
|
negotiate_ImpersonateSecurityContext, /* ImpersonateSecurityContext */
|
|
|
|
negotiate_RevertSecurityContext, /* RevertSecurityContext */
|
|
|
|
negotiate_MakeSignature, /* MakeSignature */
|
|
|
|
negotiate_VerifySignature, /* VerifySignature */
|
|
|
|
NULL, /* FreeContextBuffer */
|
|
|
|
NULL, /* QuerySecurityPackageInfo */
|
|
|
|
NULL, /* Reserved3 */
|
|
|
|
NULL, /* Reserved4 */
|
|
|
|
NULL, /* ExportSecurityContext */
|
|
|
|
NULL, /* ImportSecurityContext */
|
|
|
|
NULL, /* AddCredentials */
|
|
|
|
NULL, /* Reserved8 */
|
|
|
|
NULL, /* QuerySecurityContextToken */
|
|
|
|
negotiate_EncryptMessage, /* EncryptMessage */
|
|
|
|
negotiate_DecryptMessage, /* DecryptMessage */
|
|
|
|
negotiate_SetContextAttributesW, /* SetContextAttributes */
|
2012-03-06 02:03:49 +04:00
|
|
|
};
|