From da750b77bdb8125b6cf6cd84c9bc440baf5ec135 Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Tue, 1 Aug 2023 15:01:53 +0200 Subject: [PATCH] msv1_0: Implement SECPKG_ATTR_SESSION_KEY. --- dlls/msv1_0/main.c | 14 +++++++++++++- dlls/secur32/tests/ntlm.c | 10 ++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/dlls/msv1_0/main.c b/dlls/msv1_0/main.c index a877d974486..53d8f1b6415 100644 --- a/dlls/msv1_0/main.c +++ b/dlls/msv1_0/main.c @@ -1138,7 +1138,6 @@ static NTSTATUS NTAPI ntlm_SpQueryContextAttributes( LSA_SEC_HANDLE handle, ULON X(SECPKG_ATTR_NATIVE_NAMES); X(SECPKG_ATTR_PACKAGE_INFO); X(SECPKG_ATTR_PASSWORD_EXPIRY); - X(SECPKG_ATTR_SESSION_KEY); X(SECPKG_ATTR_STREAM_SIZES); X(SECPKG_ATTR_TARGET_INFORMATION); case SECPKG_ATTR_FLAGS: @@ -1167,6 +1166,19 @@ static NTSTATUS NTAPI ntlm_SpQueryContextAttributes( LSA_SEC_HANDLE handle, ULON info->NegotiationState = SECPKG_NEGOTIATION_COMPLETE; return SEC_E_OK; } + case SECPKG_ATTR_SESSION_KEY: + { + struct ntlm_ctx *ctx = (struct ntlm_ctx *)handle; + SecPkgContext_SessionKey *key = (SecPkgContext_SessionKey *)buf; + unsigned char *session_key; + + if (!(session_key = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(ctx->session_key) ))) + return SEC_E_INSUFFICIENT_MEMORY; + memcpy( session_key, ctx->session_key, sizeof(ctx->session_key) ); + key->SessionKey = session_key; + key->SessionKeyLength = sizeof(ctx->session_key); + return SEC_E_OK; + } case SECPKG_ATTR_KEY_INFO: { struct ntlm_ctx *ctx = (struct ntlm_ctx *)handle; diff --git a/dlls/secur32/tests/ntlm.c b/dlls/secur32/tests/ntlm.c index 4accf4b2d79..42d9b580d71 100644 --- a/dlls/secur32/tests/ntlm.c +++ b/dlls/secur32/tests/ntlm.c @@ -824,6 +824,7 @@ static void testAuth(ULONG data_rep, BOOL fake) SecPkgContext_StreamSizes stream_sizes; SecPkgContext_NegotiationInfoA info; SecPkgContext_KeyInfoA key; + SecPkgContext_SessionKey session_key; SecPkgInfoA *pi; if(pQuerySecurityPackageInfoA( sec_pkg_name, &pkg_info)!= SEC_E_OK) @@ -927,6 +928,15 @@ static void testAuth(ULONG data_rep, BOOL fake) } ok( key.KeySize == 128, "got %lu\n", key.KeySize ); ok( key.EncryptAlgorithm == CALG_RC4, "got %#lx\n", key.EncryptAlgorithm ); + FreeContextBuffer( key.sSignatureAlgorithmName ); + FreeContextBuffer( key.sEncryptAlgorithmName ); + + memset( &session_key, 0, sizeof(session_key) ); + sec_status = QueryContextAttributesA( &client.ctxt, SECPKG_ATTR_SESSION_KEY, &session_key ); + ok( sec_status == SEC_E_OK, "pQueryContextAttributesA returned %08lx\n", sec_status ); + ok( session_key.SessionKeyLength, "got 0 key length\n" ); + ok( session_key.SessionKey != NULL, "got NULL session key\n" ); + FreeContextBuffer( session_key.SessionKey ); memset(&info, 0, sizeof(info)); sec_status = QueryContextAttributesA(&client.ctxt, SECPKG_ATTR_NEGOTIATION_INFO, &info);