21#include <winpr/config.h>
24#include <winpr/wtypes.h>
25#include <winpr/assert.h>
26#include <winpr/sspi.h>
27#include <winpr/tchar.h>
28#if !defined(WITHOUT_WINPR_3x_DEPRECATED)
29#include <winpr/registry.h>
31#include <winpr/build-config.h>
32#include <winpr/asn1.h>
33#include <winpr/path.h>
34#include <winpr/config-readers.h>
38#include "../NTLM/ntlm.h"
39#include "../NTLM/ntlm_export.h"
40#include "../Kerberos/kerberos.h"
42#include "../../utils.h"
44#define TAG WINPR_TAG("negotiate")
46#if !defined(WITHOUT_WINPR_3x_DEPRECATED)
47#define NEGO_REG_KEY "Software\\%s\\SSPI\\Negotiate"
50static const char PACKAGE_NAME_DISABLE_ALL[] =
"none";
51static const char PACKAGE_NAME_NTLM[] =
"ntlm";
52static const char PACKAGE_NAME_KERBEROS[] =
"kerberos";
53static const char PACKAGE_NAME_KERBEROS_U2U[] =
"u2u";
83 "Microsoft Package Negotiator"
86static WCHAR NEGOTIATE_SecPkgInfoW_NameBuffer[32] = WINPR_C_ARRAY_INIT;
87static WCHAR NEGOTIATE_SecPkgInfoW_CommentBuffer[32] = WINPR_C_ARRAY_INIT;
94 NEGOTIATE_SecPkgInfoW_NameBuffer,
95 NEGOTIATE_SecPkgInfoW_CommentBuffer
98static const WinPrAsn1_OID spnego_OID = { 6, (BYTE*)
"\x2b\x06\x01\x05\x05\x02" };
100 (BYTE*)
"\x2a\x86\x48\x86\xf7\x12\x01\x02\x02\x03" };
101static const WinPrAsn1_OID kerberos_OID = { 9, (BYTE*)
"\x2a\x86\x48\x86\xf7\x12\x01\x02\x02" };
103 (BYTE*)
"\x2a\x86\x48\x82\xf7\x12\x01\x02\x02" };
104static const WinPrAsn1_OID ntlm_OID = { 10, (BYTE*)
"\x2b\x06\x01\x04\x01\x82\x37\x02\x02\x0a" };
106static const WinPrAsn1_OID negoex_OID = { 10, (BYTE*)
"\x2b\x06\x01\x04\x01\x82\x37\x02\x02\x1e" };
109static const SecPkg SecPkgTable[] = {
110 { KERBEROS_SSP_NAME, &KERBEROS_SecurityFunctionTableA, &KERBEROS_SecurityFunctionTableW },
111 { KERBEROS_SSP_NAME, &KERBEROS_SecurityFunctionTableA, &KERBEROS_SecurityFunctionTableW },
112 { NTLM_SSP_NAME, &NTLM_SecurityFunctionTableA, &NTLM_SecurityFunctionTableW }
115static const Mech MechTable[] = {
116 { &kerberos_u2u_OID, &SecPkgTable[0], ISC_REQ_INTEGRITY | ISC_REQ_USE_SESSION_KEY, TRUE },
117 { &kerberos_OID, &SecPkgTable[1], ISC_REQ_INTEGRITY, TRUE },
118 { &ntlm_OID, &SecPkgTable[2], 0, FALSE },
121static const SecPkg SecPkgTable[] = { { NTLM_SSP_NAME, &NTLM_SecurityFunctionTableA,
122 &NTLM_SecurityFunctionTableW } };
124static const Mech MechTable[] = {
125 { &ntlm_OID, &SecPkgTable[0], 0, FALSE },
129static const size_t MECH_COUNT = ARRAYSIZE(MechTable);
142 enum NegState negState;
150static const NegToken empty_neg_token = { NOSTATE, FALSE,
151 { 0,
nullptr }, { 0, 0,
nullptr },
152 { 0, 0,
nullptr }, { 0, 0,
nullptr } };
158 WINPR_ASSERT(init_context);
164 if (init_context->spnego)
166 init_context->mechTypes.pvBuffer = malloc(init_context->mechTypes.cbBuffer);
167 if (!init_context->mechTypes.pvBuffer)
174 *context = *init_context;
181 WINPR_ASSERT(context);
183 if (context->mechTypes.pvBuffer)
184 free(context->mechTypes.pvBuffer);
188static const char* negotiate_mech_name(
const WinPrAsn1_OID* oid)
190 if (sspi_gss_oid_compare(oid, &spnego_OID))
191 return "SPNEGO (1.3.6.1.5.5.2)";
192 else if (sspi_gss_oid_compare(oid, &kerberos_u2u_OID))
193 return "Kerberos user to user (1.2.840.113554.1.2.2.3)";
194 else if (sspi_gss_oid_compare(oid, &kerberos_OID))
195 return "Kerberos (1.2.840.113554.1.2.2)";
196 else if (sspi_gss_oid_compare(oid, &kerberos_wrong_OID))
197 return "Kerberos [wrong OID] (1.2.840.48018.1.2.2)";
198 else if (sspi_gss_oid_compare(oid, &ntlm_OID))
199 return "NTLM (1.3.6.1.4.1.311.2.2.10)";
200 else if (sspi_gss_oid_compare(oid, &negoex_OID))
201 return "NegoEx (1.3.6.1.4.1.311.2.2.30)";
203 return "Unknown mechanism";
206static const Mech* negotiate_GetMechByOID(
const WinPrAsn1_OID* oid)
212 if (sspi_gss_oid_compare(&testOid, &kerberos_wrong_OID))
214 testOid.len = kerberos_OID.len;
215 testOid.data = kerberos_OID.data;
218 for (
size_t i = 0; i < MECH_COUNT; i++)
220 if (sspi_gss_oid_compare(&testOid, MechTable[i].oid))
221 return &MechTable[i];
226static PSecHandle negotiate_FindCredential(MechCred* creds,
const Mech* mech)
233 for (
size_t i = 0; i < MECH_COUNT; i++)
235 MechCred* cred = &creds[i];
237 if (cred->mech == mech)
248#if !defined(WITHOUT_WINPR_3x_DEPRECATED)
249static BOOL negotiate_get_dword(HKEY hKey,
const char* subkey, DWORD* pdwValue)
253 DWORD dwSize =
sizeof(dwValue);
254 LONG rc = RegQueryValueExA(hKey, subkey,
nullptr, &dwType, (BYTE*)&dwValue, &dwSize);
256 if (rc != ERROR_SUCCESS)
258 if (dwType != REG_DWORD)
266static BOOL negotiate_get_config_from_auth_package_list(
void* pAuthData, BOOL* kerberos, BOOL* ntlm,
270 char* tok_ctx =
nullptr;
271 char* PackageList =
nullptr;
276 char* tok_ptr = strtok_s(PackageList,
",", &tok_ctx);
280 const char* PackageName = tok_ptr;
281 BOOL PackageInclude = TRUE;
283 if (PackageName[0] ==
'!')
285 PackageName = &PackageName[1];
286 PackageInclude = FALSE;
289 if (_stricmp(PackageName, PACKAGE_NAME_NTLM) == 0)
291 *ntlm = PackageInclude;
293 else if (_stricmp(PackageName, PACKAGE_NAME_KERBEROS) == 0)
295 *kerberos = PackageInclude;
297 else if (_stricmp(PackageName, PACKAGE_NAME_KERBEROS_U2U) == 0)
299 *u2u = PackageInclude;
301 else if (_stricmp(PackageName, PACKAGE_NAME_DISABLE_ALL) == 0)
307 if (PackageName != PackageList)
309 WLog_WARN(TAG,
"Special keyword '%s' not first in list, aborting", PackageName);
315 WLog_WARN(TAG,
"Unknown authentication package name: %s, ignoring", PackageName);
318 tok_ptr = strtok_s(
nullptr,
",", &tok_ctx);
327static BOOL negotiate_get_config(
void* pAuthData, BOOL* kerberos, BOOL* ntlm, BOOL* u2u)
329 WINPR_ASSERT(kerberos);
333#if !defined(WITH_KRB5_NO_NTLM_FALLBACK)
338#if defined(WITH_KRB5)
346 if (negotiate_get_config_from_auth_package_list(pAuthData, kerberos, ntlm, u2u))
351 const char config[] =
"negotiate.json";
353#if !defined(WITHOUT_WINPR_3x_DEPRECATED)
355 char* key = winpr_getApplicatonDetailsRegKey(NEGO_REG_KEY);
360 RegOpenKeyExA(HKEY_LOCAL_MACHINE, key, 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
362 if (rc == ERROR_SUCCESS)
364 WLog_WARN(TAG,
"HKLM.reg is deprecated since 3.33.0. ATTENTION: Use %s instead!",
369 if (negotiate_get_dword(hKey, PACKAGE_NAME_KERBEROS, &dwValue))
370 *kerberos = (dwValue != 0);
372 if (negotiate_get_dword(hKey, PACKAGE_NAME_KERBEROS_U2U, &dwValue))
373 *u2u = (dwValue != 0);
375#if !defined(WITH_KRB5_NO_NTLM_FALLBACK)
376 if (negotiate_get_dword(hKey, PACKAGE_NAME_NTLM, &dwValue))
377 *ntlm = (dwValue != 0);
386 WINPR_JSON* json = winpr_GetJSONConfigFile(TRUE, config);
389 winpr_config_apply_bool(config, json, PACKAGE_NAME_KERBEROS, kerberos);
390 winpr_config_apply_bool(config, json, PACKAGE_NAME_KERBEROS_U2U, u2u);
391#if !defined(WITH_KRB5_NO_NTLM_FALLBACK)
392 winpr_config_apply_bool(config, json, PACKAGE_NAME_NTLM, ntlm);
400static BOOL negotiate_write_neg_token(
PSecBuffer output_buffer, NegToken* token)
402 WINPR_ASSERT(output_buffer);
406 WinPrAsn1Encoder* enc =
nullptr;
413 enc = WinPrAsn1Encoder_New(WINPR_ASN1_DER);
421 if (!WinPrAsn1EncAppContainer(enc, 0))
425 if (!WinPrAsn1EncOID(enc, &spnego_OID))
430 if (!WinPrAsn1EncContextualSeqContainer(enc, token->init ? 0 : 1))
433 WLog_DBG(TAG, token->init ?
"Writing negTokenInit..." :
"Writing negTokenResp...");
438 if (!WinPrAsn1EncContextualRawContent(enc, 0, &mechTypes))
440 WLog_DBG(TAG,
"\tmechTypes [0] (%" PRIu32
" bytes)", token->mechTypes.cbBuffer);
443 else if (token->negState != NOSTATE)
445 if (!WinPrAsn1EncContextualEnumerated(enc, 0, token->negState))
447 WLog_DBG(TAG,
"\tnegState [0] (%d)", token->negState);
451 if (token->supportedMech.len)
453 if (!WinPrAsn1EncContextualOID(enc, 1, &token->supportedMech))
455 WLog_DBG(TAG,
"\tsupportedMech [1] (%s)", negotiate_mech_name(&token->supportedMech));
459 if (token->mechToken.cbBuffer)
461 if (WinPrAsn1EncContextualOctetString(enc, 2, &mechToken) == 0)
463 WLog_DBG(TAG,
"\tmechToken [2] (%" PRIu32
" bytes)", token->mechToken.cbBuffer);
467 if (token->mic.cbBuffer)
469 if (WinPrAsn1EncContextualOctetString(enc, 3, &mechListMic) == 0)
471 WLog_DBG(TAG,
"\tmechListMIC [3] (%" PRIu32
" bytes)", token->mic.cbBuffer);
475 if (!WinPrAsn1EncEndContainer(enc))
481 if (!WinPrAsn1EncEndContainer(enc))
485 if (!WinPrAsn1EncStreamSize(enc, &len) || len > output_buffer->cbBuffer)
488 if (len > UINT32_MAX)
491 Stream_StaticInit(&s, output_buffer->pvBuffer, len);
493 if (WinPrAsn1EncToStream(enc, &s))
495 output_buffer->cbBuffer = (UINT32)len;
500 WinPrAsn1Encoder_Free(&enc);
504static BOOL negotiate_read_neg_token(
PSecBuffer input, NegToken* token)
509 WinPrAsn1_tagId contextual = 0;
510 WinPrAsn1_tag tag = 0;
519 if (!input->pvBuffer || (input->cbBuffer == 0))
522 WinPrAsn1Decoder_InitMem(&dec, WINPR_ASN1_DER, input->pvBuffer, input->cbBuffer);
524 if (!WinPrAsn1DecPeekTag(&dec, &tag))
530 if (!WinPrAsn1DecReadApp(&dec, &tag, &dec2) || tag != 0)
535 if (!WinPrAsn1DecReadOID(&dec, &oid, FALSE))
538 if (!sspi_gss_oid_compare(&spnego_OID, &oid))
542 if (!WinPrAsn1DecReadContextualSequence(&dec, 0, &err, &dec2))
548 else if (!WinPrAsn1DecReadContextualSequence(&dec, 1, &err, &dec2))
552 WLog_DBG(TAG, token->init ?
"Reading negTokenInit..." :
"Reading negTokenResp...");
557 if (!WinPrAsn1DecReadContextualTag(&dec, &contextual, &dec2))
566 wStream s = WinPrAsn1DecGetStream(&dec2);
567 token->mechTypes.BufferType = SECBUFFER_TOKEN;
568 const size_t mlen = Stream_Length(&s);
569 if (mlen > UINT32_MAX)
571 token->mechTypes.cbBuffer = (UINT32)mlen;
572 token->mechTypes.pvBuffer = Stream_Buffer(&s);
573 WLog_DBG(TAG,
"\tmechTypes [0] (%" PRIu32
" bytes)", token->mechTypes.cbBuffer);
578 WinPrAsn1_ENUMERATED rd = 0;
579 if (!WinPrAsn1DecReadEnumerated(&dec2, &rd))
584 case ACCEPT_COMPLETED:
585 case ACCEPT_INCOMPLETE:
590 WLog_ERR(TAG,
"Invalid negState enumeration value %d", rd);
594 token->negState = WINPR_ASSERTING_INT_CAST(
enum NegState, rd);
595 WLog_DBG(TAG,
"\tnegState [0] (%d)", rd);
602 if (!WinPrAsn1DecPeekTagAndLen(&dec2, &tag, &len) || (tag != ER_TAG_BIT_STRING))
604 WLog_DBG(TAG,
"\treqFlags [1] (%" PRIuz
" bytes)", len);
609 if (!WinPrAsn1DecReadOID(&dec2, &token->supportedMech, FALSE))
611 WLog_DBG(TAG,
"\tsupportedMech [1] (%s)",
612 negotiate_mech_name(&token->supportedMech));
617 if (!WinPrAsn1DecReadOctetString(&dec2, &octet_string, FALSE))
619 if (octet_string.len > UINT32_MAX)
621 token->mechToken.cbBuffer = (UINT32)octet_string.len;
622 token->mechToken.pvBuffer = octet_string.data;
623 token->mechToken.BufferType = SECBUFFER_TOKEN;
624 WLog_DBG(TAG,
"\tmechToken [2] (%" PRIuz
" bytes)", octet_string.len);
628 if (!WinPrAsn1DecReadOctetString(&dec2, &octet_string, FALSE))
630 if (octet_string.len > UINT32_MAX)
632 token->mic.cbBuffer = (UINT32)octet_string.len;
633 token->mic.pvBuffer = octet_string.data;
634 token->mic.BufferType = SECBUFFER_TOKEN;
635 WLog_DBG(TAG,
"\tmechListMIC [3] (%" PRIuz
" bytes)", octet_string.len);
638 WLog_ERR(TAG,
"unknown contextual item %d", contextual);
641 }
while (WinPrAsn1DecPeekTag(&dec, &tag));
646static SECURITY_STATUS negotiate_mic_exchange(
NEGOTIATE_CONTEXT* context, NegToken* input_token,
647 NegToken* output_token,
PSecBuffer output_buffer)
649 SecBuffer mic_buffers[2] = WINPR_C_ARRAY_INIT;
650 SecBufferDesc mic_buffer_desc = { SECBUFFER_VERSION, 2, mic_buffers };
651 SECURITY_STATUS status = 0;
653 WINPR_ASSERT(context);
654 WINPR_ASSERT(input_token);
655 WINPR_ASSERT(output_token);
656 WINPR_ASSERT(context->mech);
657 WINPR_ASSERT(context->mech->pkg);
662 mic_buffers[0] = context->mechTypes;
665 if (input_token->mic.cbBuffer > 0)
667 mic_buffers[1] = input_token->mic;
669 status = table->VerifySignature(&context->sub_context, &mic_buffer_desc, 0,
nullptr);
670 if (status != SEC_E_OK)
673 output_token->negState = ACCEPT_COMPLETED;
677 if (input_token->negState != ACCEPT_COMPLETED)
680 output_token->mic.BufferType = SECBUFFER_TOKEN;
683 output_token->mic.cbBuffer = output_buffer->cbBuffer - output_token->mechToken.cbBuffer;
684 output_token->mic.pvBuffer =
685 (BYTE*)output_buffer->pvBuffer + output_token->mechToken.cbBuffer;
687 mic_buffers[1] = output_token->mic;
689 status = table->MakeSignature(&context->sub_context, 0, &mic_buffer_desc, 0);
690 if (status != SEC_E_OK)
693 output_token->mic = mic_buffers[1];
697 const SSPI_PACKAGE_ID sub_id = sspi_SecureHandleGetPackageId(&context->sub_context);
699 return SEC_E_INTERNAL_ERROR;
701 if (sub_id == SSPI_PACKAGE_NTLM)
703 if (!ntlm_reset_cipher_state(&context->sub_context))
704 return SEC_E_INTERNAL_ERROR;
710static SECURITY_STATUS SEC_ENTRY negotiate_InitializeSecurityContextW(
712 ULONG Reserved1, ULONG TargetDataRep,
PSecBufferDesc pInput, ULONG Reserved2,
717 MechCred* creds =
nullptr;
720 NegToken input_token = empty_neg_token;
721 NegToken output_token = empty_neg_token;
725 SecBuffer mech_input_buffers[2] = WINPR_C_ARRAY_INIT;
726 SecBufferDesc mech_input = { SECBUFFER_VERSION, 2, mech_input_buffers };
727 SecBufferDesc mech_output = { SECBUFFER_VERSION, 1, &output_token.mechToken };
728 SECURITY_STATUS status = SEC_E_INTERNAL_ERROR;
729 SECURITY_STATUS sub_status = SEC_E_INTERNAL_ERROR;
730 WinPrAsn1Encoder* enc =
nullptr;
732 const Mech* mech =
nullptr;
734 if (!phCredential || !SecIsValidHandle(phCredential))
735 return SEC_E_NO_CREDENTIALS;
737 creds = sspi_SecureHandleGetLowerPointer(phCredential);
740 if (phContext && !phContext->dwLower && !phContext->dwUpper)
741 return SEC_E_INVALID_HANDLE;
743 context = sspi_SecureHandleGetLowerPointer(phContext);
747 input_buffer = sspi_FindSecBuffer(pInput, SECBUFFER_TOKEN);
748 bindings_buffer = sspi_FindSecBuffer(pInput, SECBUFFER_CHANNEL_BINDINGS);
751 output_buffer = sspi_FindSecBuffer(pOutput, SECBUFFER_TOKEN);
755 enc = WinPrAsn1Encoder_New(WINPR_ASN1_DER);
757 return SEC_E_INSUFFICIENT_MEMORY;
759 if (!WinPrAsn1EncSeqContainer(enc))
762 for (
size_t i = 0; i < MECH_COUNT; i++)
764 MechCred* cred = &creds[i];
765 const SecPkg* pkg = MechTable[i].pkg;
767 WINPR_ASSERT(pkg->table_w);
771 WLog_DBG(TAG,
"Unavailable mechanism: %s", negotiate_mech_name(cred->mech->oid));
776 if (!init_context.mech)
782 CopyMemory(&output_token.mechToken, output_buffer,
sizeof(
SecBuffer));
785 mech_input_buffers[0] = *bindings_buffer;
787 WINPR_ASSERT(pkg->table_w->InitializeSecurityContextW);
788 sub_status = pkg->table_w->InitializeSecurityContextW(
789 &cred->cred,
nullptr, pszTargetName, fContextReq | cred->mech->flags, Reserved1,
790 TargetDataRep, &mech_input, Reserved2, &init_context.sub_context, &mech_output,
791 pfContextAttr, ptsExpiry);
794 if (IsSecurityStatusError(sub_status))
796 if (SecIsValidHandle(&init_context.sub_context))
798 WINPR_ASSERT(pkg->table_w->DeleteSecurityContext);
799 pkg->table_w->DeleteSecurityContext(&init_context.sub_context);
805 init_context.mech = cred->mech;
808 if (!WinPrAsn1EncOID(enc, cred->mech->oid))
810 WLog_DBG(TAG,
"Available mechanism: %s", negotiate_mech_name(cred->mech->oid));
814 if (!init_context.mech)
818 if (init_context.mech->oid == &ntlm_OID)
820 init_context.spnego = FALSE;
821 output_buffer->cbBuffer = output_token.mechToken.cbBuffer;
822 WLog_DBG(TAG,
"Using direct NTLM");
826 init_context.spnego = TRUE;
827 init_context.mechTypes.BufferType = SECBUFFER_DATA;
828 const size_t cb = WinPrAsn1EncEndContainer(enc);
829 WINPR_ASSERT(cb <= UINT32_MAX);
830 init_context.mechTypes.cbBuffer = (UINT32)cb;
834 context = negotiate_ContextNew(&init_context);
837 init_context.mech->pkg->table->DeleteSecurityContext(&init_context.sub_context);
838 WinPrAsn1Encoder_Free(&enc);
839 return SEC_E_INSUFFICIENT_MEMORY;
842 sspi_SecureHandleSetPackageId(phNewContext, SSPI_PACKAGE_NEGOTIATE);
843 sspi_SecureHandleSetLowerPointer(phNewContext, context);
845 if (!context->spnego)
852 Stream_StaticInit(&s, context->mechTypes.pvBuffer, context->mechTypes.cbBuffer);
853 if (!WinPrAsn1EncToStream(enc, &s))
856 output_token.mechTypes.cbBuffer = context->mechTypes.cbBuffer;
857 output_token.mechTypes.pvBuffer = context->mechTypes.pvBuffer;
858 output_token.init = TRUE;
860 if (sub_status == SEC_E_OK)
861 context->state = NEGOTIATE_STATE_FINAL_OPTIMISTIC;
866 return SEC_E_INVALID_TOKEN;
868 sub_context = &context->sub_context;
869 sub_cred = negotiate_FindCredential(creds, context->mech);
871 if (!context->spnego)
873 return context->mech->pkg->table_w->InitializeSecurityContextW(
874 sub_cred, sub_context, pszTargetName, fContextReq | context->mech->flags, Reserved1,
875 TargetDataRep, pInput, Reserved2, sub_context, pOutput, pfContextAttr, ptsExpiry);
878 if (!negotiate_read_neg_token(input_buffer, &input_token))
879 return SEC_E_INVALID_TOKEN;
882 if (context->state < NEGOTIATE_STATE_NEGORESP && input_token.supportedMech.len &&
883 !sspi_gss_oid_compare(&input_token.supportedMech, context->mech->oid))
885 mech = negotiate_GetMechByOID(&input_token.supportedMech);
887 return SEC_E_INVALID_TOKEN;
890 sub_cred = negotiate_FindCredential(creds, mech);
892 return SEC_E_INVALID_TOKEN;
895 context->mech->pkg->table_w->DeleteSecurityContext(&context->sub_context);
896 sub_context =
nullptr;
898 context->mech = mech;
903 if (context->state < NEGOTIATE_STATE_NEGORESP)
905 switch (input_token.negState)
908 return SEC_E_INVALID_TOKEN;
910 return SEC_E_LOGON_DENIED;
915 case ACCEPT_INCOMPLETE:
916 context->state = NEGOTIATE_STATE_NEGORESP;
918 case ACCEPT_COMPLETED:
919 if (context->state == NEGOTIATE_STATE_INITIAL)
920 context->state = NEGOTIATE_STATE_NEGORESP;
922 context->state = NEGOTIATE_STATE_FINAL;
928 WLog_DBG(TAG,
"Negotiated mechanism: %s", negotiate_mech_name(context->mech->oid));
931 if (context->state == NEGOTIATE_STATE_NEGORESP)
936 CopyMemory(&output_token.mechToken, output_buffer,
sizeof(
SecBuffer));
938 mech_input_buffers[0] = input_token.mechToken;
940 mech_input_buffers[1] = *bindings_buffer;
942 status = context->mech->pkg->table_w->InitializeSecurityContextW(
943 sub_cred, sub_context, pszTargetName, fContextReq | context->mech->flags, Reserved1,
944 TargetDataRep, input_token.mechToken.cbBuffer ? &mech_input : nullptr, Reserved2,
945 &context->sub_context, &mech_output, pfContextAttr, ptsExpiry);
947 if (IsSecurityStatusError(status))
951 if (status == SEC_E_OK)
953 if (output_token.mechToken.cbBuffer > 0)
954 context->state = NEGOTIATE_STATE_MIC;
956 context->state = NEGOTIATE_STATE_FINAL;
960 if (context->state == NEGOTIATE_STATE_FINAL && input_token.mic.cbBuffer == 0)
962 if (context->mic || input_token.negState != ACCEPT_COMPLETED)
963 return SEC_E_INVALID_TOKEN;
966 output_buffer->cbBuffer = 0;
970 if ((context->state == NEGOTIATE_STATE_MIC && context->mic) ||
971 context->state == NEGOTIATE_STATE_FINAL)
973 status = negotiate_mic_exchange(context, &input_token, &output_token, output_buffer);
974 if (status != SEC_E_OK)
979 if (input_token.negState == ACCEPT_COMPLETED)
982 output_buffer->cbBuffer = 0;
986 if (output_token.negState == ACCEPT_COMPLETED)
989 status = SEC_I_CONTINUE_NEEDED;
991 if (!negotiate_write_neg_token(output_buffer, &output_token))
992 status = SEC_E_INTERNAL_ERROR;
995 WinPrAsn1Encoder_Free(&enc);
999static SECURITY_STATUS SEC_ENTRY negotiate_InitializeSecurityContextA(
1001 ULONG Reserved1, ULONG TargetDataRep,
PSecBufferDesc pInput, ULONG Reserved2,
1004 SECURITY_STATUS status = 0;
1005 SEC_WCHAR* pszTargetNameW =
nullptr;
1009 pszTargetNameW = ConvertUtf8ToWCharAlloc(pszTargetName,
nullptr);
1010 if (!pszTargetNameW)
1011 return SEC_E_INTERNAL_ERROR;
1014 status = negotiate_InitializeSecurityContextW(
1015 phCredential, phContext, pszTargetNameW, fContextReq, Reserved1, TargetDataRep, pInput,
1016 Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry);
1017 free(pszTargetNameW);
1026 WinPrAsn1_tagId tag = 0;
1027 const char ssp[] =
"NTLMSSP";
1029 if (!input_buffer || !input_buffer->pvBuffer || (input_buffer->cbBuffer == 0))
1035 if (input_buffer->cbBuffer >= 8 && strncmp(input_buffer->pvBuffer, ssp,
sizeof(ssp)) == 0)
1038 return negotiate_GetMechByOID(&ntlm_OID);
1042 WinPrAsn1Decoder_InitMem(&decoder, WINPR_ASN1_DER, input_buffer->pvBuffer,
1043 input_buffer->cbBuffer);
1045 if (!WinPrAsn1DecReadApp(&decoder, &tag, &appDecoder) || tag != 0)
1048 if (!WinPrAsn1DecReadOID(&appDecoder, oid, FALSE))
1051 if (sspi_gss_oid_compare(oid, &spnego_OID))
1057 return negotiate_GetMechByOID(oid);
1060static SECURITY_STATUS SEC_ENTRY negotiate_AcceptSecurityContext(
1067 MechCred* creds =
nullptr;
1069 NegToken input_token = empty_neg_token;
1070 NegToken output_token = empty_neg_token;
1073 SecBufferDesc mech_input = { SECBUFFER_VERSION, 1, &input_token.mechToken };
1074 SecBufferDesc mech_output = { SECBUFFER_VERSION, 1, &output_token.mechToken };
1075 SECURITY_STATUS status = SEC_E_INTERNAL_ERROR;
1078 WinPrAsn1_tagId tag = 0;
1080 const Mech* first_mech =
nullptr;
1082 if (!phCredential || !SecIsValidHandle(phCredential))
1083 return SEC_E_NO_CREDENTIALS;
1085 creds = sspi_SecureHandleGetLowerPointer(phCredential);
1088 return SEC_E_INVALID_TOKEN;
1091 if (phContext && !phContext->dwLower && !phContext->dwUpper)
1092 return SEC_E_INVALID_HANDLE;
1094 context = sspi_SecureHandleGetLowerPointer(phContext);
1096 input_buffer = sspi_FindSecBuffer(pInput, SECBUFFER_TOKEN);
1098 output_buffer = sspi_FindSecBuffer(pOutput, SECBUFFER_TOKEN);
1102 init_context.mech = guessMech(input_buffer, &init_context.spnego, &oid);
1103 if (!init_context.mech && !init_context.spnego)
1104 return SEC_E_INVALID_TOKEN;
1106 WLog_DBG(TAG,
"Mechanism: %s", negotiate_mech_name(&oid));
1108 if (init_context.spnego)
1111 if (!negotiate_read_neg_token(input_buffer, &input_token))
1112 return SEC_E_INVALID_TOKEN;
1115 if (!input_token.init || input_token.mechTypes.cbBuffer == 0)
1116 return SEC_E_INVALID_TOKEN;
1118 init_context.mechTypes.BufferType = SECBUFFER_DATA;
1119 init_context.mechTypes.cbBuffer = input_token.mechTypes.cbBuffer;
1122 WinPrAsn1Decoder_InitMem(&dec, WINPR_ASN1_DER, input_token.mechTypes.pvBuffer,
1123 input_token.mechTypes.cbBuffer);
1125 if (!WinPrAsn1DecReadSequence(&dec, &dec2))
1126 return SEC_E_INVALID_TOKEN;
1130 if (input_token.mechToken.cbBuffer)
1132 if (!WinPrAsn1DecReadOID(&dec, &oid, FALSE))
1133 return SEC_E_INVALID_TOKEN;
1135 init_context.mech = negotiate_GetMechByOID(&oid);
1137 if (init_context.mech)
1140 output_token.mechToken = *output_buffer;
1141 WLog_DBG(TAG,
"Requested mechanism: %s",
1142 negotiate_mech_name(init_context.mech->oid));
1147 if (init_context.mech)
1149 sub_cred = negotiate_FindCredential(creds, init_context.mech);
1153 status = init_context.mech->pkg->table->AcceptSecurityContext(
1154 sub_cred,
nullptr, init_context.spnego ? &mech_input : pInput, fContextReq,
1155 TargetDataRep, &init_context.sub_context,
1156 init_context.spnego ? &mech_output : pOutput, pfContextAttr, ptsTimeStamp);
1160 if (IsSecurityStatusError(status))
1162 if (!init_context.spnego)
1168 if (init_context.mech)
1169 init_context.mech->pkg->table->DeleteSecurityContext(&init_context.sub_context);
1171 init_context.mic = TRUE;
1172 first_mech = init_context.mech;
1173 init_context.mech =
nullptr;
1174 output_token.mechToken.cbBuffer = 0;
1177 while (!init_context.mech && WinPrAsn1DecPeekTag(&dec, &tag))
1180 if (!WinPrAsn1DecReadOID(&dec, &oid, FALSE))
1181 return SEC_E_INVALID_TOKEN;
1183 init_context.mech = negotiate_GetMechByOID(&oid);
1184 WLog_DBG(TAG,
"Requested mechanism: %s", negotiate_mech_name(&oid));
1187 if (init_context.mech == first_mech)
1188 init_context.mech =
nullptr;
1190 if (init_context.mech && !negotiate_FindCredential(creds, init_context.mech))
1191 init_context.mech =
nullptr;
1194 if (!init_context.mech)
1195 return SEC_E_INTERNAL_ERROR;
1197 context = negotiate_ContextNew(&init_context);
1200 if (!IsSecurityStatusError(status))
1201 init_context.mech->pkg->table->DeleteSecurityContext(&init_context.sub_context);
1202 return SEC_E_INSUFFICIENT_MEMORY;
1205 sspi_SecureHandleSetPackageId(phNewContext, SSPI_PACKAGE_NEGOTIATE);
1206 sspi_SecureHandleSetLowerPointer(phNewContext, context);
1208 if (!init_context.spnego)
1211 CopyMemory(init_context.mechTypes.pvBuffer, input_token.mechTypes.pvBuffer,
1212 input_token.mechTypes.cbBuffer);
1214 if (!context->mech->preferred)
1216 output_token.negState = REQUEST_MIC;
1217 context->mic = TRUE;
1221 output_token.negState = ACCEPT_INCOMPLETE;
1224 if (status == SEC_E_OK)
1225 context->state = NEGOTIATE_STATE_FINAL;
1227 context->state = NEGOTIATE_STATE_NEGORESP;
1229 output_token.supportedMech = oid;
1230 WLog_DBG(TAG,
"Accepted mechanism: %s", negotiate_mech_name(&output_token.supportedMech));
1234 sub_cred = negotiate_FindCredential(creds, context->mech);
1236 return SEC_E_NO_CREDENTIALS;
1238 if (!context->spnego)
1240 return context->mech->pkg->table->AcceptSecurityContext(
1241 sub_cred, &context->sub_context, pInput, fContextReq, TargetDataRep,
1242 &context->sub_context, pOutput, pfContextAttr, ptsTimeStamp);
1245 if (!negotiate_read_neg_token(input_buffer, &input_token))
1246 return SEC_E_INVALID_TOKEN;
1249 if (input_token.mechToken.cbBuffer > 0)
1251 if (context->state != NEGOTIATE_STATE_NEGORESP)
1252 return SEC_E_INVALID_TOKEN;
1256 CopyMemory(&output_token.mechToken, output_buffer,
sizeof(
SecBuffer));
1262 PCtxtHandle sub_context = sspi_SecureHandleGetLowerPointer(&context->sub_context)
1263 ? &context->sub_context
1265 status = context->mech->pkg->table->AcceptSecurityContext(
1266 sub_cred, sub_context, &mech_input, fContextReq | context->mech->flags,
1267 TargetDataRep, &context->sub_context, &mech_output, pfContextAttr, ptsTimeStamp);
1269 if (IsSecurityStatusError(status))
1272 if (status == SEC_E_OK)
1273 context->state = NEGOTIATE_STATE_FINAL;
1275 else if (context->state == NEGOTIATE_STATE_NEGORESP)
1276 return SEC_E_INVALID_TOKEN;
1279 if (context->state == NEGOTIATE_STATE_FINAL)
1282 if (context->mic && output_token.mechToken.cbBuffer == 0 && input_token.mic.cbBuffer == 0)
1283 return SEC_E_INVALID_TOKEN;
1285 if (context->mic || input_token.mic.cbBuffer > 0)
1287 status = negotiate_mic_exchange(context, &input_token, &output_token, output_buffer);
1288 if (status != SEC_E_OK)
1292 output_token.negState = ACCEPT_COMPLETED;
1295 if (input_token.negState == ACCEPT_COMPLETED)
1298 output_buffer->cbBuffer = 0;
1302 if (output_token.negState == ACCEPT_COMPLETED)
1305 status = SEC_I_CONTINUE_NEEDED;
1307 if (!negotiate_write_neg_token(output_buffer, &output_token))
1308 return SEC_E_INTERNAL_ERROR;
1313static SECURITY_STATUS SEC_ENTRY negotiate_CompleteAuthToken(
PCtxtHandle phContext,
1317 SECURITY_STATUS status = SEC_E_OK;
1321 return SEC_E_INVALID_HANDLE;
1323 WINPR_ASSERT(context->mech);
1324 WINPR_ASSERT(context->mech->pkg);
1325 WINPR_ASSERT(context->mech->pkg->table);
1326 if (context->mech->pkg->table->CompleteAuthToken)
1327 status = context->mech->pkg->table->CompleteAuthToken(&context->sub_context, pToken);
1332static SECURITY_STATUS SEC_ENTRY negotiate_DeleteSecurityContext(
PCtxtHandle phContext)
1334 SECURITY_STATUS status = SEC_E_OK;
1336 sspi_SecureHandleInvalidate(phContext);
1337 const SecPkg* pkg =
nullptr;
1340 return SEC_E_INVALID_HANDLE;
1342 WINPR_ASSERT(context->mech);
1343 WINPR_ASSERT(context->mech->pkg);
1344 WINPR_ASSERT(context->mech->pkg->table);
1345 pkg = context->mech->pkg;
1347 if (pkg->table->DeleteSecurityContext)
1348 status = pkg->table->DeleteSecurityContext(&context->sub_context);
1350 negotiate_ContextFree(context);
1354static SECURITY_STATUS SEC_ENTRY
1355negotiate_ImpersonateSecurityContext(WINPR_ATTR_UNUSED
PCtxtHandle phContext)
1360static SECURITY_STATUS SEC_ENTRY
1361negotiate_RevertSecurityContext(WINPR_ATTR_UNUSED
PCtxtHandle phContext)
1366static SECURITY_STATUS SEC_ENTRY negotiate_QueryContextAttributesW(
PCtxtHandle phContext,
1367 ULONG ulAttribute,
void* pBuffer)
1372 return SEC_E_INVALID_HANDLE;
1374 WINPR_ASSERT(context->mech);
1375 WINPR_ASSERT(context->mech->pkg);
1376 WINPR_ASSERT(context->mech->pkg->table_w);
1377 if (context->mech->pkg->table_w->QueryContextAttributesW)
1378 return context->mech->pkg->table_w->QueryContextAttributesW(&context->sub_context,
1379 ulAttribute, pBuffer);
1381 return SEC_E_UNSUPPORTED_FUNCTION;
1384static SECURITY_STATUS SEC_ENTRY negotiate_QueryContextAttributesA(
PCtxtHandle phContext,
1385 ULONG ulAttribute,
void* pBuffer)
1390 return SEC_E_INVALID_HANDLE;
1392 WINPR_ASSERT(context->mech);
1393 WINPR_ASSERT(context->mech->pkg);
1394 WINPR_ASSERT(context->mech->pkg->table);
1395 if (context->mech->pkg->table->QueryContextAttributesA)
1396 return context->mech->pkg->table->QueryContextAttributesA(&context->sub_context,
1397 ulAttribute, pBuffer);
1399 return SEC_E_UNSUPPORTED_FUNCTION;
1402static SECURITY_STATUS SEC_ENTRY negotiate_SetContextAttributesW(
PCtxtHandle phContext,
1403 ULONG ulAttribute,
void* pBuffer,
1409 return SEC_E_INVALID_HANDLE;
1411 WINPR_ASSERT(context->mech);
1412 WINPR_ASSERT(context->mech->pkg);
1413 WINPR_ASSERT(context->mech->pkg->table_w);
1414 if (context->mech->pkg->table_w->SetContextAttributesW)
1415 return context->mech->pkg->table_w->SetContextAttributesW(&context->sub_context,
1416 ulAttribute, pBuffer, cbBuffer);
1418 return SEC_E_UNSUPPORTED_FUNCTION;
1421static SECURITY_STATUS SEC_ENTRY negotiate_SetContextAttributesA(
PCtxtHandle phContext,
1422 ULONG ulAttribute,
void* pBuffer,
1428 return SEC_E_INVALID_HANDLE;
1430 WINPR_ASSERT(context->mech);
1431 WINPR_ASSERT(context->mech->pkg);
1432 WINPR_ASSERT(context->mech->pkg->table);
1433 if (context->mech->pkg->table->SetContextAttributesA)
1434 return context->mech->pkg->table->SetContextAttributesA(&context->sub_context, ulAttribute,
1437 return SEC_E_UNSUPPORTED_FUNCTION;
1440static SECURITY_STATUS SEC_ENTRY negotiate_SetCredentialsAttributesW(
PCredHandle phCredential,
1442 void* pBuffer, ULONG cbBuffer)
1444 BOOL success = FALSE;
1445 MechCred* creds = sspi_SecureHandleGetLowerPointer(phCredential);
1448 return SEC_E_INVALID_HANDLE;
1450 for (
size_t i = 0; i < MECH_COUNT; i++)
1452 MechCred* cred = &creds[i];
1454 WINPR_ASSERT(cred->mech);
1455 WINPR_ASSERT(cred->mech->pkg);
1456 WINPR_ASSERT(cred->mech->pkg->table);
1457 WINPR_ASSERT(cred->mech->pkg->table_w->SetCredentialsAttributesW);
1458 const SECURITY_STATUS secStatus = cred->mech->pkg->table_w->SetCredentialsAttributesW(
1459 &cred->cred, ulAttribute, pBuffer, cbBuffer);
1461 if (secStatus == SEC_E_OK)
1464 WLog_WARN(TAG,
"SetCredentialsAttributesW returned %s",
1465 GetSecurityStatusString(secStatus));
1469 return (success ? SEC_E_OK : SEC_E_UNSUPPORTED_FUNCTION);
1472static SECURITY_STATUS SEC_ENTRY negotiate_SetCredentialsAttributesA(
PCredHandle phCredential,
1474 void* pBuffer, ULONG cbBuffer)
1476 BOOL success = FALSE;
1478 MechCred* creds = sspi_SecureHandleGetLowerPointer(phCredential);
1481 return SEC_E_INVALID_HANDLE;
1483 for (
size_t i = 0; i < MECH_COUNT; i++)
1485 MechCred* cred = &creds[i];
1490 WINPR_ASSERT(cred->mech);
1491 WINPR_ASSERT(cred->mech->pkg);
1492 WINPR_ASSERT(cred->mech->pkg->table);
1493 WINPR_ASSERT(cred->mech->pkg->table->SetCredentialsAttributesA);
1494 const SECURITY_STATUS secStatus = cred->mech->pkg->table->SetCredentialsAttributesA(
1495 &cred->cred, ulAttribute, pBuffer, cbBuffer);
1497 if (secStatus == SEC_E_OK)
1502 WLog_WARN(TAG,
"SetCredentialsAttributesA returned %s",
1503 GetSecurityStatusString(secStatus));
1507 return (success ? SEC_E_OK : SEC_E_UNSUPPORTED_FUNCTION);
1511static BOOL checkMechCredValid(
void* pAuthData, MechCred* cred)
1514 WINPR_ASSERT(cred->mech);
1515 WINPR_ASSERT(cred->mech->pkg);
1517 BOOL kerberos = FALSE;
1520 if (!negotiate_get_config(pAuthData, &kerberos, &ntlm, &u2u))
1522 WLog_DBG(TAG,
"Failed to get negotiate configuration");
1526 if (!kerberos && sspi_gss_oid_compare(cred->mech->oid, &kerberos_OID))
1528 WLog_DBG(TAG,
"Kerberos disabled, skipping");
1532 if (!u2u && sspi_gss_oid_compare(cred->mech->oid, &kerberos_u2u_OID))
1534 WLog_DBG(TAG,
"Kerberos U2U disabled, skipping");
1538 if (!ntlm && _tcsncmp(cred->mech->pkg->name, NTLM_SSP_NAME, ARRAYSIZE(NTLM_SSP_NAME)) == 0)
1540 WLog_DBG(TAG,
"NTLM disabled, skipping");
1546static SECURITY_STATUS SEC_ENTRY negotiate_AcquireCredentialsHandleW(
1547 SEC_WCHAR* pszPrincipal, SEC_WCHAR* pszPackage, ULONG fCredentialUse,
void* pvLogonID,
1548 void* pAuthData, SEC_GET_KEY_FN pGetKeyFn,
void* pvGetKeyArgument,
PCredHandle phCredential,
1551 MechCred* creds = calloc(MECH_COUNT,
sizeof(MechCred));
1554 return SEC_E_INTERNAL_ERROR;
1556 for (
size_t i = 0; i < MECH_COUNT; i++)
1558 MechCred* cred = &creds[i];
1559 const SecPkg* pkg = MechTable[i].pkg;
1560 cred->mech = &MechTable[i];
1562 if (!checkMechCredValid(pAuthData, cred))
1565 WINPR_ASSERT(pkg->table_w);
1566 WINPR_ASSERT(pkg->table_w->AcquireCredentialsHandleW);
1567 const SECURITY_STATUS rc = pkg->table_w->AcquireCredentialsHandleW(
1568 pszPrincipal, pszPackage, fCredentialUse, pvLogonID, pAuthData, pGetKeyFn,
1569 pvGetKeyArgument, &cred->cred, ptsExpiry);
1572 WLog_DBG(TAG,
"AcquireCredentialsHandleW returned %s", GetSecurityStatusString(rc));
1579 sspi_SecureHandleSetLowerPointer(phCredential, (
void*)creds);
1580 sspi_SecureHandleSetPackageId(phCredential, SSPI_PACKAGE_NEGOTIATE);
1584static SECURITY_STATUS SEC_ENTRY negotiate_AcquireCredentialsHandleA(
1585 SEC_CHAR* pszPrincipal, SEC_CHAR* pszPackage, ULONG fCredentialUse,
void* pvLogonID,
1586 void* pAuthData, SEC_GET_KEY_FN pGetKeyFn,
void* pvGetKeyArgument,
PCredHandle phCredential,
1589 MechCred* creds = calloc(MECH_COUNT,
sizeof(MechCred));
1592 return SEC_E_INTERNAL_ERROR;
1594 for (
size_t i = 0; i < MECH_COUNT; i++)
1596 const SecPkg* pkg = MechTable[i].pkg;
1597 MechCred* cred = &creds[i];
1599 cred->mech = &MechTable[i];
1601 if (!checkMechCredValid(pAuthData, cred))
1604 WINPR_ASSERT(pkg->table);
1605 WINPR_ASSERT(pkg->table->AcquireCredentialsHandleA);
1606 const SECURITY_STATUS rc = pkg->table->AcquireCredentialsHandleA(
1607 pszPrincipal, pszPackage, fCredentialUse, pvLogonID, pAuthData, pGetKeyFn,
1608 pvGetKeyArgument, &cred->cred, ptsExpiry);
1611 WLog_DBG(TAG,
"AcquireCredentialsHandleA returned %s", GetSecurityStatusString(rc));
1618 sspi_SecureHandleSetLowerPointer(phCredential, (
void*)creds);
1619 sspi_SecureHandleSetPackageId(phCredential, SSPI_PACKAGE_NEGOTIATE);
1623static SECURITY_STATUS SEC_ENTRY negotiate_QueryCredentialsAttributesW(
1624 WINPR_ATTR_UNUSED
PCredHandle phCredential, WINPR_ATTR_UNUSED ULONG ulAttribute,
1625 WINPR_ATTR_UNUSED
void* pBuffer)
1627 WLog_ERR(TAG,
"TODO: Implement");
1628 return SEC_E_UNSUPPORTED_FUNCTION;
1631static SECURITY_STATUS SEC_ENTRY negotiate_QueryCredentialsAttributesA(
1632 WINPR_ATTR_UNUSED
PCredHandle phCredential, WINPR_ATTR_UNUSED ULONG ulAttribute,
1633 WINPR_ATTR_UNUSED
void* pBuffer)
1635 WLog_ERR(TAG,
"TODO: Implement");
1636 return SEC_E_UNSUPPORTED_FUNCTION;
1639static SECURITY_STATUS SEC_ENTRY negotiate_FreeCredentialsHandle(
PCredHandle phCredential)
1641 MechCred* creds = sspi_SecureHandleGetLowerPointer(phCredential);
1642 sspi_SecureHandleInvalidate(phCredential);
1644 return SEC_E_INVALID_HANDLE;
1646 for (
size_t i = 0; i < MECH_COUNT; i++)
1648 MechCred* cred = &creds[i];
1650 WINPR_ASSERT(cred->mech);
1651 WINPR_ASSERT(cred->mech->pkg);
1652 WINPR_ASSERT(cred->mech->pkg->table);
1653 WINPR_ASSERT(cred->mech->pkg->table->FreeCredentialsHandle);
1654 const SECURITY_STATUS rc = cred->mech->pkg->table->FreeCredentialsHandle(&cred->cred);
1656 WLog_DBG(TAG,
"FreeCredentialsHandle returned %s", GetSecurityStatusString(rc));
1663static SECURITY_STATUS SEC_ENTRY negotiate_EncryptMessage(
PCtxtHandle phContext, ULONG fQOP,
1670 return SEC_E_INVALID_HANDLE;
1675 WINPR_ASSERT(context->mech);
1676 WINPR_ASSERT(context->mech->pkg);
1677 WINPR_ASSERT(context->mech->pkg->table);
1678 if (context->mech->pkg->table->EncryptMessage)
1679 return context->mech->pkg->table->EncryptMessage(&context->sub_context, fQOP, pMessage,
1682 return SEC_E_UNSUPPORTED_FUNCTION;
1685static SECURITY_STATUS SEC_ENTRY negotiate_DecryptMessage(
PCtxtHandle phContext,
1687 ULONG MessageSeqNo, ULONG* pfQOP)
1692 return SEC_E_INVALID_HANDLE;
1697 WINPR_ASSERT(context->mech);
1698 WINPR_ASSERT(context->mech->pkg);
1699 WINPR_ASSERT(context->mech->pkg->table);
1700 if (context->mech->pkg->table->DecryptMessage)
1701 return context->mech->pkg->table->DecryptMessage(&context->sub_context, pMessage,
1702 MessageSeqNo, pfQOP);
1704 return SEC_E_UNSUPPORTED_FUNCTION;
1707static SECURITY_STATUS SEC_ENTRY negotiate_MakeSignature(
PCtxtHandle phContext, ULONG fQOP,
1714 return SEC_E_INVALID_HANDLE;
1719 WINPR_ASSERT(context->mech);
1720 WINPR_ASSERT(context->mech->pkg);
1721 WINPR_ASSERT(context->mech->pkg->table);
1722 if (context->mech->pkg->table->MakeSignature)
1723 return context->mech->pkg->table->MakeSignature(&context->sub_context, fQOP, pMessage,
1726 return SEC_E_UNSUPPORTED_FUNCTION;
1729static SECURITY_STATUS SEC_ENTRY negotiate_VerifySignature(
PCtxtHandle phContext,
1731 ULONG MessageSeqNo, ULONG* pfQOP)
1736 return SEC_E_INVALID_HANDLE;
1741 WINPR_ASSERT(context->mech);
1742 WINPR_ASSERT(context->mech->pkg);
1743 WINPR_ASSERT(context->mech->pkg->table);
1744 if (context->mech->pkg->table->VerifySignature)
1745 return context->mech->pkg->table->VerifySignature(&context->sub_context, pMessage,
1746 MessageSeqNo, pfQOP);
1748 return SEC_E_UNSUPPORTED_FUNCTION;
1754 negotiate_QueryCredentialsAttributesA,
1755 negotiate_AcquireCredentialsHandleA,
1756 negotiate_FreeCredentialsHandle,
1758 negotiate_InitializeSecurityContextA,
1759 negotiate_AcceptSecurityContext,
1760 negotiate_CompleteAuthToken,
1761 negotiate_DeleteSecurityContext,
1763 negotiate_QueryContextAttributesA,
1764 negotiate_ImpersonateSecurityContext,
1765 negotiate_RevertSecurityContext,
1766 negotiate_MakeSignature,
1767 negotiate_VerifySignature,
1777 negotiate_EncryptMessage,
1778 negotiate_DecryptMessage,
1779 negotiate_SetContextAttributesA,
1780 negotiate_SetCredentialsAttributesA,
1786 negotiate_QueryCredentialsAttributesW,
1787 negotiate_AcquireCredentialsHandleW,
1788 negotiate_FreeCredentialsHandle,
1790 negotiate_InitializeSecurityContextW,
1791 negotiate_AcceptSecurityContext,
1792 negotiate_CompleteAuthToken,
1793 negotiate_DeleteSecurityContext,
1795 negotiate_QueryContextAttributesW,
1796 negotiate_ImpersonateSecurityContext,
1797 negotiate_RevertSecurityContext,
1798 negotiate_MakeSignature,
1799 negotiate_VerifySignature,
1809 negotiate_EncryptMessage,
1810 negotiate_DecryptMessage,
1811 negotiate_SetContextAttributesW,
1812 negotiate_SetCredentialsAttributesW,
1815BOOL NEGOTIATE_init(
void)
1817 InitializeConstWCharFromUtf8(NEGOTIATE_SecPkgInfoA.Name, NEGOTIATE_SecPkgInfoW_NameBuffer,
1818 ARRAYSIZE(NEGOTIATE_SecPkgInfoW_NameBuffer));
1819 InitializeConstWCharFromUtf8(NEGOTIATE_SecPkgInfoA.Comment, NEGOTIATE_SecPkgInfoW_CommentBuffer,
1820 ARRAYSIZE(NEGOTIATE_SecPkgInfoW_CommentBuffer));
WINPR_API void WINPR_JSON_Delete(WINPR_JSON *item)
Delete a WinPR JSON wrapper object.