Debian Codegraph @

winpr/libwinpr/sspi/NTLM/ntlm_compute.c

raw symbols SCIP
1 /**
2 * WinPR: Windows Portable Runtime
3 * NTLM Security Package (Compute)
4 *
5 * Copyright 2011-2014 Marc-Andre Moreau <[email protected]>
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20 #include <winpr/config.h>cxx . . $ `<file>/build/winpr/include/winpr/config.h`/
21
22 #include <winpr/assert.h>cxx . . $ `<file>/winpr/include/winpr/assert.h`/
23
24 #include "ntlm.h"cxx . . $ `<file>/winpr/libwinpr/sspi/NTLM/ntlm.h`/
25 #include "../sspi.h"cxx . . $ `<file>/winpr/libwinpr/sspi/sspi.h`/
26
27 #include <winpr/crt.h>cxx . . $ `<file>/winpr/include/winpr/crt.h`/
28 #include <winpr/sam.h>cxx . . $ `<file>/winpr/include/winpr/sam.h`/
29 #include <winpr/ntlm.h>cxx . . $ `<file>/winpr/include/winpr/ntlm.h`/
30 #include <winpr/print.h>cxx . . $ `<file>/winpr/include/winpr/print.h`/
31 #include <winpr/crypto.h>cxx . . $ `<file>/winpr/include/winpr/crypto.h`/
32 #include <winpr/sysinfo.h>cxx . . $ `<file>/winpr/include/winpr/sysinfo.h`/
33
34 #include "ntlm_compute.h"cxx . . $ `<file>/winpr/libwinpr/sspi/NTLM/ntlm_compute.h`/
35
36 #include "../../log.h"cxx . . $ `<file>/winpr/libwinpr/log.h`/
37 #define TAGcxx . . $ `winpr/libwinpr/sspi/NTLM/ntlm_compute.c:37:9`! WINPR_TAGcxx . . $ `winpr/libwinpr/log.h:25:9`!("sspi.NTLM")
38
39 #define NTLM_CheckAndLogRequiredCapacitycxx . . $ `winpr/libwinpr/sspi/NTLM/ntlm_compute.c:39:9`!(tag, s, nmemb, what) \
40 Stream_CheckAndLogRequiredCapacityEx(tag, WLOG_WARN, s, nmemb, 1, "%s(%s:%" PRIuzcxx . . $ `winpr/include/winpr/wtypes.h:485:9`! ") " what, \
41 __func__, __FILE__, (size_t)__LINE__)
42
43 static char NTLM_CLIENT_SIGN_MAGICcxx . . $ NTLM_CLIENT_SIGN_MAGIC.[] = "session key to client-to-server signing key magic constant";
44 static char NTLM_SERVER_SIGN_MAGICcxx . . $ NTLM_SERVER_SIGN_MAGIC.[] = "session key to server-to-client signing key magic constant";
45 static char NTLM_CLIENT_SEAL_MAGICcxx . . $ NTLM_CLIENT_SEAL_MAGIC.[] = "session key to client-to-server sealing key magic constant";
46 static char NTLM_SERVER_SEAL_MAGICcxx . . $ NTLM_SERVER_SEAL_MAGIC.[] = "session key to server-to-client sealing key magic constant";
47
48 static const BYTEcxx . . $ BYTE# NTLM_NULL_BUFFERcxx . . $ NTLM_NULL_BUFFER.[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
49 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
50
51 /**
52 * Populate VERSION structure msdn{cc236654}
53 * @param versionInfo A pointer to the version struct
54 *
55 * @return \b TRUE for success, \b FALSE for failure
56 */
57
58 BOOLcxx . . $ BOOL# ntlm_get_version_infocxx . . $ ntlm_get_version_info(5320d1dd0e5e9254).(NTLM_VERSION_INFOcxx . . $ NTLM_VERSION_INFO#* versionInfo)
59 {
60 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(versionInfo);
61
62 #if defined(WITH_WINPR_DEPRECATED)
63 OSVERSIONINFOA osVersionInfo = WINPR_C_ARRAY_INIT;
64 osVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
65 if (!GetVersionExA(&osVersionInfo))
66 return FALSE;
67 versionInfo->ProductMajorVersion = (UINT8)osVersionInfo.dwMajorVersion;
68 versionInfo->ProductMinorVersion = (UINT8)osVersionInfo.dwMinorVersion;
69 versionInfo->ProductBuild = (UINT16)osVersionInfo.dwBuildNumber;
70 #else
71 /* Always return fixed version number.
72 *
73 * ProductVersion is fixed since windows 10 to Major 10, Minor 0
74 * ProductBuild taken from https://en.wikipedia.org/wiki/Windows_11_version_history
75 * with most recent (pre) release build number
76 */
77 versionInfo->ProductMajorVersioncxx . . $ $anonymous_type_544b217a83a6fa2a_3#ProductMajorVersion. = 10;
78 versionInfo->ProductMinorVersioncxx . . $ $anonymous_type_544b217a83a6fa2a_3#ProductMinorVersion. = 0;
79 versionInfo->ProductBuildcxx . . $ $anonymous_type_544b217a83a6fa2a_3#ProductBuild. = 22631;
80 #endif
81 ZeroMemorycxx . . $ `winpr/include/winpr/crt.h:126:9`!(versionInfo->Reserved, sizeof(versionInfo->Reserved));
82 versionInfo->NTLMRevisionCurrentcxx . . $ $anonymous_type_544b217a83a6fa2a_3#NTLMRevisionCurrent. = NTLMSSP_REVISION_W2K3cxx . . $ `winpr/libwinpr/sspi/NTLM/ntlm.h:128:9`!;
83 return TRUEcxx . . $ `winpr/include/winpr/wtypes.h:126:9`!;
84 }
85
86 /**
87 * Read VERSION structure. msdn{cc236654}
88 * @param s A pointer to a stream to read
89 * @param versionInfo A pointer to the struct to read data to
90 *
91 * @return \b TRUE for success, \b FALSE for failure
92 */
93
94 BOOLcxx . . $ BOOL# ntlm_read_version_infocxx . . $ ntlm_read_version_info(aa78f8ddf5d7b69e).(wStreamcxx . . $ wStream#* s, NTLM_VERSION_INFOcxx . . $ NTLM_VERSION_INFO#* versionInfo)
95 {
96 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(s);
97 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(versionInfo);
98
99 if (!Stream_CheckAndLogRequiredLengthcxx . . $ `winpr/include/winpr/stream.h:127:9`!(TAGcxx . . $ `winpr/libwinpr/sspi/NTLM/ntlm_compute.c:37:9`!, s, 8))
100 return FALSEcxx . . $ `winpr/include/winpr/wtypes.h:122:9`!;
101
102 Stream_Read_UINT8cxx . . $ `winpr/include/winpr/stream.h:647:9`!(s, versionInfo->ProductMajorVersion); /* ProductMajorVersion (1 byte) */
103 Stream_Read_UINT8cxx . . $ `winpr/include/winpr/stream.h:647:9`!(s, versionInfo->ProductMinorVersion); /* ProductMinorVersion (1 byte) */
104 Stream_Read_UINT16cxx . . $ `winpr/include/winpr/stream.h:659:9`!(s, versionInfo->ProductBuild); /* ProductBuild (2 bytes) */
105 Stream_Readcxx . . $ Stream_Read(ac143672e71ef382).(s, versionInfo->Reservedcxx . . $ $anonymous_type_544b217a83a6fa2a_3#Reserved., sizeof(versionInfo->Reservedcxx . . $ $anonymous_type_544b217a83a6fa2a_3#Reserved.)); /* Reserved (3 bytes) */
106 Stream_Read_UINT8cxx . . $ `winpr/include/winpr/stream.h:647:9`!(s, versionInfo->NTLMRevisionCurrent); /* NTLMRevisionCurrent (1 byte) */
107 return TRUEcxx . . $ `winpr/include/winpr/wtypes.h:126:9`!;
108 }
109
110 /**
111 * Write VERSION structure. msdn{cc236654}
112 * @param s A pointer to the stream to write to
113 * @param versionInfo A pointer to the buffer to read the data from
114 *
115 * @return \b TRUE for success, \b FALSE for failure
116 */
117
118 BOOLcxx . . $ BOOL# ntlm_write_version_infocxx . . $ ntlm_write_version_info(a7a6ce77347291b5).(wStreamcxx . . $ wStream#* s, const NTLM_VERSION_INFOcxx . . $ NTLM_VERSION_INFO#* versionInfo)
119 {
120 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(s);
121 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(versionInfo);
122
123 if (!Stream_CheckAndLogRequiredCapacityExcxx . . $ Stream_CheckAndLogRequiredCapacityEx(6a8415acd562e16a).(
124 TAGcxx . . $ `winpr/libwinpr/sspi/NTLM/ntlm_compute.c:37:9`!, WLOG_WARNcxx . . $ WLOG_WARN., s, 5ull + sizeof(versionInfo->Reservedcxx . . $ $anonymous_type_544b217a83a6fa2a_3#Reserved.), 1ull,
125 "%s(%s:%" PRIuzcxx . . $ `winpr/include/winpr/wtypes.h:485:9`! ") NTLM_VERSION_INFO", __func__, __FILE__, (size_t)__LINE__))
126 return FALSEcxx . . $ `winpr/include/winpr/wtypes.h:122:9`!;
127
128 Stream_Write_UINT8cxx . . $ `winpr/include/winpr/stream.h:857:9`!(s, versionInfo->ProductMajorVersion); /* ProductMajorVersion (1 byte) */
129 Stream_Write_UINT8cxx . . $ `winpr/include/winpr/stream.h:857:9`!(s, versionInfo->ProductMinorVersion); /* ProductMinorVersion (1 byte) */
130 Stream_Write_UINT16cxx . . $ `winpr/include/winpr/stream.h:908:9`!(s, versionInfo->ProductBuild); /* ProductBuild (2 bytes) */
131 Stream_Writecxx . . $ Stream_Write(6afa9478ce9fa6e6).(s, versionInfo->Reservedcxx . . $ $anonymous_type_544b217a83a6fa2a_3#Reserved., sizeof(versionInfo->Reservedcxx . . $ $anonymous_type_544b217a83a6fa2a_3#Reserved.)); /* Reserved (3 bytes) */
132 Stream_Write_UINT8cxx . . $ `winpr/include/winpr/stream.h:857:9`!(s, versionInfo->NTLMRevisionCurrent); /* NTLMRevisionCurrent (1 byte) */
133 return TRUEcxx . . $ `winpr/include/winpr/wtypes.h:126:9`!;
134 }
135
136 /**
137 * Print VERSION structure. msdn{cc236654}
138 * @param versionInfo A pointer to the struct containing the data to print
139 */
140 #ifdef WITH_DEBUG_NTLM
141 void ntlm_print_version_info(const NTLM_VERSION_INFO* versionInfo)
142 {
143 WINPR_ASSERT(versionInfo);
144
145 WLog_VRB(TAG, "VERSION ={");
146 WLog_VRB(TAG, "\tProductMajorVersion: %" PRIu8 "", versionInfo->ProductMajorVersion);
147 WLog_VRB(TAG, "\tProductMinorVersion: %" PRIu8 "", versionInfo->ProductMinorVersion);
148 WLog_VRB(TAG, "\tProductBuild: %" PRIu16 "", versionInfo->ProductBuild);
149 WLog_VRB(TAG, "\tReserved: 0x%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "", versionInfo->Reserved[0],
150 versionInfo->Reserved[1], versionInfo->Reserved[2]);
151 WLog_VRB(TAG, "\tNTLMRevisionCurrent: 0x%02" PRIX8 "", versionInfo->NTLMRevisionCurrent);
152 }
153 #endif
154
155 static BOOLcxx . . $ BOOL# ntlm_read_ntlm_v2_client_challengecxx . . $ ntlm_read_ntlm_v2_client_challenge(268007e6006a12aa).(wStreamcxx . . $ wStream#* s, NTLMv2_CLIENT_CHALLENGEcxx . . $ NTLMv2_CLIENT_CHALLENGE#* challenge)
156 {
157 size_t size = 0;
158 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(s);
159 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(challenge);
160
161 if (!Stream_CheckAndLogRequiredLengthcxx . . $ `winpr/include/winpr/stream.h:127:9`!(TAGcxx . . $ `winpr/libwinpr/sspi/NTLM/ntlm_compute.c:37:9`!, s, 28))
162 return FALSEcxx . . $ `winpr/include/winpr/wtypes.h:122:9`!;
163
164 Stream_Read_UINT8cxx . . $ `winpr/include/winpr/stream.h:647:9`!(s, challenge->RespType);
165 Stream_Read_UINT8cxx . . $ `winpr/include/winpr/stream.h:647:9`!(s, challenge->HiRespType);
166 Stream_Read_UINT16cxx . . $ `winpr/include/winpr/stream.h:659:9`!(s, challenge->Reserved1);
167 Stream_Read_UINT32cxx . . $ `winpr/include/winpr/stream.h:683:9`!(s, challenge->Reserved2);
168 Stream_Readcxx . . $ Stream_Read(ac143672e71ef382).(s, challenge->Timestampcxx . . $ $anonymous_type_544b217a83a6fa2a_6#Timestamp., 8);
169 Stream_Readcxx . . $ Stream_Read(ac143672e71ef382).(s, challenge->ClientChallengecxx . . $ $anonymous_type_544b217a83a6fa2a_6#ClientChallenge., 8);
170 Stream_Read_UINT32cxx . . $ `winpr/include/winpr/stream.h:683:9`!(s, challenge->Reserved3);
171 size = Stream_Lengthcxx . . $ Stream_Length(ebc7f695a8644dc0).(s) - Stream_GetPositioncxx . . $ Stream_GetPosition(ebc7f695a8644dc0).(s);
172
173 if (size > UINT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:124:10`!)
174 {
175 WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `winpr/libwinpr/sspi/NTLM/ntlm_compute.c:37:9`!, "NTLMv2_CLIENT_CHALLENGE::cbAvPairs too large, got %" PRIuzcxx . . $ `winpr/include/winpr/wtypes.h:485:9`! "bytes", size);
176 return FALSEcxx . . $ `winpr/include/winpr/wtypes.h:122:9`!;
177 }
178
179 challenge->cbAvPairscxx . . $ $anonymous_type_544b217a83a6fa2a_6#cbAvPairs. = (UINT32cxx . . $ UINT32#)size;
180 challenge->AvPairscxx . . $ $anonymous_type_544b217a83a6fa2a_6#AvPairs. = (NTLM_AV_PAIRcxx . . $ NTLM_AV_PAIR#*)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(challenge->cbAvPairscxx . . $ $anonymous_type_544b217a83a6fa2a_6#cbAvPairs.);
181
182 if (!challenge->AvPairscxx . . $ $anonymous_type_544b217a83a6fa2a_6#AvPairs.)
183 {
184 WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `winpr/libwinpr/sspi/NTLM/ntlm_compute.c:37:9`!, "NTLMv2_CLIENT_CHALLENGE::AvPairs failed to allocate %" PRIu32cxx . . $ `<external>/15933738808807975373/inttypes.h:109:10`! "bytes",
185 challenge->cbAvPairs);
186 return FALSEcxx . . $ `winpr/include/winpr/wtypes.h:122:9`!;
187 }
188
189 Stream_Readcxx . . $ Stream_Read(ac143672e71ef382).(s, challenge->AvPairscxx . . $ $anonymous_type_544b217a83a6fa2a_6#AvPairs., size);
190 return TRUEcxx . . $ `winpr/include/winpr/wtypes.h:126:9`!;
191 }
192
193 static BOOLcxx . . $ BOOL# ntlm_write_ntlm_v2_client_challengecxx . . $ ntlm_write_ntlm_v2_client_challenge(b1b441db292c1610).(wStreamcxx . . $ wStream#* s,
194 const NTLMv2_CLIENT_CHALLENGEcxx . . $ NTLMv2_CLIENT_CHALLENGE#* challenge)
195 {
196 ULONGcxx . . $ ULONG# length = 0;
197
198 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(s);
199 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(challenge);
200
201 if (!NTLM_CheckAndLogRequiredCapacitycxx . . $ `winpr/libwinpr/sspi/NTLM/ntlm_compute.c:39:9`!(TAGcxx . . $ `winpr/libwinpr/sspi/NTLM/ntlm_compute.c:37:9`!, s, 28, "NTLMv2_CLIENT_CHALLENGE"))
202 return FALSEcxx . . $ `winpr/include/winpr/wtypes.h:122:9`!;
203
204 Stream_Write_UINT8cxx . . $ `winpr/include/winpr/stream.h:857:9`!(s, challenge->RespType);
205 Stream_Write_UINT8cxx . . $ `winpr/include/winpr/stream.h:857:9`!(s, challenge->HiRespType);
206 Stream_Write_UINT16cxx . . $ `winpr/include/winpr/stream.h:908:9`!(s, challenge->Reserved1);
207 Stream_Write_UINT32cxx . . $ `winpr/include/winpr/stream.h:1070:9`!(s, challenge->Reserved2);
208 Stream_Writecxx . . $ Stream_Write(6afa9478ce9fa6e6).(s, challenge->Timestampcxx . . $ $anonymous_type_544b217a83a6fa2a_6#Timestamp., 8);
209 Stream_Writecxx . . $ Stream_Write(6afa9478ce9fa6e6).(s, challenge->ClientChallengecxx . . $ $anonymous_type_544b217a83a6fa2a_6#ClientChallenge., 8);
210 Stream_Write_UINT32cxx . . $ `winpr/include/winpr/stream.h:1070:9`!(s, challenge->Reserved3);
211 length = ntlm_av_pair_list_lengthcxx . . $ ntlm_av_pair_list_length(76ab0f3cfe324ee8).(challenge->AvPairscxx . . $ $anonymous_type_544b217a83a6fa2a_6#AvPairs., challenge->cbAvPairscxx . . $ $anonymous_type_544b217a83a6fa2a_6#cbAvPairs.);
212
213 if (!Stream_CheckAndLogRequiredLengthcxx . . $ `winpr/include/winpr/stream.h:127:9`!(TAGcxx . . $ `winpr/libwinpr/sspi/NTLM/ntlm_compute.c:37:9`!, s, length))
214 return FALSEcxx . . $ `winpr/include/winpr/wtypes.h:122:9`!;
215
216 Stream_Writecxx . . $ Stream_Write(6afa9478ce9fa6e6).(s, challenge->AvPairscxx . . $ $anonymous_type_544b217a83a6fa2a_6#AvPairs., length);
217 return TRUEcxx . . $ `winpr/include/winpr/wtypes.h:126:9`!;
218 }
219
220 BOOLcxx . . $ BOOL# ntlm_read_ntlm_v2_responsecxx . . $ ntlm_read_ntlm_v2_response(dbb201d1f5e8c215).(wStreamcxx . . $ wStream#* s, NTLMv2_RESPONSEcxx . . $ NTLMv2_RESPONSE#* response)
221 {
222 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(s);
223 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(response);
224
225 if (!Stream_CheckAndLogRequiredLengthcxx . . $ `winpr/include/winpr/stream.h:127:9`!(TAGcxx . . $ `winpr/libwinpr/sspi/NTLM/ntlm_compute.c:37:9`!, s, 16))
226 return FALSEcxx . . $ `winpr/include/winpr/wtypes.h:122:9`!;
227
228 Stream_Readcxx . . $ Stream_Read(ac143672e71ef382).(s, response->Responsecxx . . $ $anonymous_type_544b217a83a6fa2a_7#Response., 16);
229 return ntlm_read_ntlm_v2_client_challengecxx . . $ ntlm_read_ntlm_v2_client_challenge(268007e6006a12aa).(s, &(response->Challengecxx . . $ $anonymous_type_544b217a83a6fa2a_7#Challenge.));
230 }
231
232 BOOLcxx . . $ BOOL# ntlm_write_ntlm_v2_responsecxx . . $ ntlm_write_ntlm_v2_response(f72ea34d8ea9db43).(wStreamcxx . . $ wStream#* s, const NTLMv2_RESPONSEcxx . . $ NTLMv2_RESPONSE#* response)
233 {
234 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(s);
235 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(response);
236
237 if (!NTLM_CheckAndLogRequiredCapacitycxx . . $ `winpr/libwinpr/sspi/NTLM/ntlm_compute.c:39:9`!(TAGcxx . . $ `winpr/libwinpr/sspi/NTLM/ntlm_compute.c:37:9`!, s, 16ull, "NTLMv2_RESPONSE"))
238 return FALSEcxx . . $ `winpr/include/winpr/wtypes.h:122:9`!;
239
240 Stream_Writecxx . . $ Stream_Write(6afa9478ce9fa6e6).(s, response->Responsecxx . . $ $anonymous_type_544b217a83a6fa2a_7#Response., 16);
241 return ntlm_write_ntlm_v2_client_challengecxx . . $ ntlm_write_ntlm_v2_client_challenge(b1b441db292c1610).(s, &(response->Challengecxx . . $ $anonymous_type_544b217a83a6fa2a_7#Challenge.));
242 }
243
244 /**
245 * Get current time, in tenths of microseconds since midnight of January 1, 1601.
246 * @param[out] timestamp 64-bit little-endian timestamp
247 */
248
249 static void ntlm_current_timecxx . . $ ntlm_current_time(6165b45f45ef689c).(BYTEcxx . . $ BYTE#* timestamp, WINPR_ATTR_UNUSEDcxx . . $ `winpr/include/winpr/platform.h:713:9`! size_t size)
250 {
251 FILETIMEcxx . . $ FILETIME# ft = WINPR_C_ARRAY_INITcxx . . $ `winpr/include/winpr/platform.h:87:9`!;
252
253 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(timestamp);
254 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(size >= sizeof(ft));
255
256 GetSystemTimeAsFileTimecxx . . $ GetSystemTimeAsFileTime(7450dd622063a9f3).(&ft);
257 CopyMemorycxx . . $ `winpr/include/winpr/crt.h:123:9`!(timestamp, &(ft), sizeof(ft));
258 }
259
260 /**
261 * Generate timestamp for AUTHENTICATE_MESSAGE.
262 *
263 * @param context A pointer to the NTLM context
264 */
265
266 void ntlm_generate_timestampcxx . . $ ntlm_generate_timestamp(bf41894d596f52ba).(NTLM_CONTEXTcxx . . $ NTLM_CONTEXT#* context)
267 {
268 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(context);
269
270 if (memcmpcxx . . $ memcmp(36f949851efa3055).(context->ChallengeTimestampcxx . . $ $anonymous_type_544b217a83a6fa2a_13#ChallengeTimestamp., NTLM_NULL_BUFFERcxx . . $ NTLM_NULL_BUFFER., 8) != 0)
271 CopyMemorycxx . . $ `winpr/include/winpr/crt.h:123:9`!(context->Timestamp, context->ChallengeTimestamp, 8);
272 else
273 ntlm_current_timecxx . . $ ntlm_current_time(6165b45f45ef689c).(context->Timestampcxx . . $ $anonymous_type_544b217a83a6fa2a_13#Timestamp., sizeof(context->Timestampcxx . . $ $anonymous_type_544b217a83a6fa2a_13#Timestamp.));
274 }
275
276 static BOOLcxx . . $ BOOL# ntlm_fetch_ntlm_v2_hashcxx . . $ ntlm_fetch_ntlm_v2_hash(5ad8f0ae590c67d4).(NTLM_CONTEXTcxx . . $ NTLM_CONTEXT#* context, BYTEcxx . . $ BYTE#* hash)
277 {
278 BOOLcxx . . $ BOOL# rc = FALSEcxx . . $ `winpr/include/winpr/wtypes.h:122:9`!;
279 WINPR_SAM_ENTRYcxx . . $ WINPR_SAM_ENTRY#* entry = nullptrcxx . . $ `winpr/include/winpr/platform.h:88:9`!;
280
281 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(context);
282 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(hash);
283
284 SSPI_CREDENTIALScxx . . $ SSPI_CREDENTIALS#* credentials = context->credentialscxx . . $ $anonymous_type_544b217a83a6fa2a_13#credentials.;
285 WINPR_SAMcxx . . $ WINPR_SAM#* sam = SamOpencxx . . $ SamOpen(d73bae069b9494d).(context->SamFilecxx . . $ $anonymous_type_544b217a83a6fa2a_13#SamFile., TRUEcxx . . $ `winpr/include/winpr/wtypes.h:126:9`!);
286
287 if (!sam)
288 goto fail;
289
290 if ((credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..Flagscxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#Flags. & SEC_WINNT_AUTH_IDENTITY_UNICODEcxx . . $ `winpr/include/winpr/sspi.h:687:9`!) != 0)
291 {
292 entry = SamLookupUserWcxx . . $ SamLookupUserW(fc42597dc409ea1e).(sam, (LPWSTRcxx . . $ LPWSTR#)credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..Usercxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#User.,
293 credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..UserLengthcxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#UserLength. * sizeof(WCHARcxx . . $ WCHAR#),
294 (LPWSTRcxx . . $ LPWSTR#)credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..Domaincxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#Domain.,
295 credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..DomainLengthcxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#DomainLength. * sizeof(WCHARcxx . . $ WCHAR#));
296
297 if (!entry)
298 {
299 entry = SamLookupUserWcxx . . $ SamLookupUserW(fc42597dc409ea1e).(sam, (LPWSTRcxx . . $ LPWSTR#)credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..Usercxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#User.,
300 credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..UserLengthcxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#UserLength. * sizeof(WCHARcxx . . $ WCHAR#), nullptrcxx . . $ `winpr/include/winpr/platform.h:88:9`!, 0);
301 }
302 }
303 else if ((credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..Flagscxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#Flags. & SEC_WINNT_AUTH_IDENTITY_ANSIcxx . . $ `winpr/include/winpr/sspi.h:686:9`!) != 0)
304 {
305 entry = SamLookupUserAcxx . . $ SamLookupUserA(ef85e8ff99164f1d).(
306 sam, (char*)credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..Usercxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#User., credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..UserLengthcxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#UserLength. * sizeof(CHARcxx . . $ CHAR#),
307 (char*)credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..Domaincxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#Domain., credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..DomainLengthcxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#DomainLength. * sizeof(CHARcxx . . $ CHAR#));
308
309 if (!entry)
310 {
311 entry = SamLookupUserAcxx . . $ SamLookupUserA(ef85e8ff99164f1d).(sam, (char*)credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..Usercxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#User.,
312 credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..UserLengthcxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#UserLength. * sizeof(CHARcxx . . $ CHAR#), nullptrcxx . . $ `winpr/include/winpr/platform.h:88:9`!, 0);
313 }
314 }
315 else
316 goto fail;
317
318 if (!entry)
319 goto fail;
320
321 #ifdef WITH_DEBUG_NTLM
322 WLog_VRB(TAG, "NTLM Hash:");
323 winpr_HexDump(TAG, WLOG_DEBUG, entry->NtHash, 16);
324 #endif
325 rc = NTOWFv2FromHashWcxx . . $ NTOWFv2FromHashW(5d1ca2c9a57d4495).(entry->NtHashcxx . . $ winpr_sam_entry#NtHash., (LPWSTRcxx . . $ LPWSTR#)credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..Usercxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#User.,
326 credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..UserLengthcxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#UserLength. * sizeof(WCHARcxx . . $ WCHAR#),
327 (LPWSTRcxx . . $ LPWSTR#)credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..Domaincxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#Domain.,
328 credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..DomainLengthcxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#DomainLength. * sizeof(WCHARcxx . . $ WCHAR#), hash);
329
330 fail:
331 SamFreeEntrycxx . . $ SamFreeEntry(fc426042e700c731).(sam, entry);
332 SamClosecxx . . $ SamClose(ab27445391df943d).(sam);
333 if (!rc)
334 WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `winpr/libwinpr/sspi/NTLM/ntlm_compute.c:37:9`!, "Error: Could not find user in SAM database");
335
336 return rc;
337 }
338
339 static int hexchar2nibblecxx . . $ hexchar2nibble(377f6a3136964dac).(WCHARcxx . . $ WCHAR# wc)
340 {
341 #if defined(__BIG_ENDIAN__)
342 union
343 {
344 BYTE b[2];
345 WCHAR w;
346 } cnv;
347 cnv.w = wc;
348 const BYTE b = cnv.b[0];
349 cnv.b[0] = cnv.b[1];
350 cnv.b[1] = b;
351 wc = cnv.w;
352 #endif
353
354 switch (wc)
355 {
356 case L'0':
357 case L'1':
358 case L'2':
359 case L'3':
360 case L'4':
361 case L'5':
362 case L'6':
363 case L'7':
364 case L'8':
365 case L'9':
366 return wc - L'0';
367 case L'a':
368 case L'b':
369 case L'c':
370 case L'd':
371 case L'e':
372 case L'f':
373 return wc - L'a' + 10;
374 case L'A':
375 case L'B':
376 case L'C':
377 case L'D':
378 case L'E':
379 case L'F':
380 return wc - L'A' + 10;
381 default:
382 return -1;
383 }
384 }
385 static int ntlm_convert_password_hashcxx . . $ ntlm_convert_password_hash(e331f041739b9679).(NTLM_CONTEXTcxx . . $ NTLM_CONTEXT#* context, BYTEcxx . . $ BYTE#* hash, size_t hashlen)
386 {
387 const size_t required_len = 2ull * hashlen;
388
389 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(context);
390 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(hash);
391
392 SSPI_CREDENTIALScxx . . $ SSPI_CREDENTIALS#* credentials = context->credentialscxx . . $ $anonymous_type_544b217a83a6fa2a_13#credentials.;
393 const ULONGcxx . . $ ULONG# PasswordHashLength = credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..PasswordLengthcxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#PasswordLength.;
394
395 if (PasswordHashLength != required_len)
396 {
397 WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `winpr/libwinpr/sspi/NTLM/ntlm_compute.c:37:9`!,
398 "PasswordHash has invalid length %" PRIu32cxx . . $ `<external>/15933738808807975373/inttypes.h:109:10`! " must be exactly %" PRIuzcxx . . $ `winpr/include/winpr/wtypes.h:485:9`! " bytes",
399 PasswordHashLength, required_len);
400 return -1;
401 }
402
403 const WCHARcxx . . $ WCHAR#* PasswordHash = credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..Passwordcxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#Password.;
404 for (size_t x = 0; x < hashlen; x++)
405 {
406 const int hi = hexchar2nibblecxx . . $ hexchar2nibble(377f6a3136964dac).(PasswordHash[2 * x]);
407 if (hi < 0)
408 {
409 WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `winpr/libwinpr/sspi/NTLM/ntlm_compute.c:37:9`!, "PasswordHash has an invalid value at position %" PRIuzcxx . . $ `winpr/include/winpr/wtypes.h:485:9`!, 2 * x);
410 return -1;
411 }
412 const int lo = hexchar2nibblecxx . . $ hexchar2nibble(377f6a3136964dac).(PasswordHash[2 * x + 1]);
413 if (lo < 0)
414 {
415 WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `winpr/libwinpr/sspi/NTLM/ntlm_compute.c:37:9`!, "PasswordHash has an invalid value at position %" PRIuzcxx . . $ `winpr/include/winpr/wtypes.h:485:9`!, 2 * x + 1);
416 return -1;
417 }
418 const BYTEcxx . . $ BYTE# val = (BYTEcxx . . $ BYTE#)((hi << 4) | lo);
419 hash[x] = val;
420 }
421
422 return 1;
423 }
424
425 static BOOLcxx . . $ BOOL# ntlm_compute_ntlm_v2_hashcxx . . $ ntlm_compute_ntlm_v2_hash(5ad8f0ae590c67d4).(NTLM_CONTEXTcxx . . $ NTLM_CONTEXT#* context, BYTEcxx . . $ BYTE#* hash)
426 {
427 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(context);
428 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(hash);
429
430 SSPI_CREDENTIALScxx . . $ SSPI_CREDENTIALS#* credentials = context->credentialscxx . . $ $anonymous_type_544b217a83a6fa2a_13#credentials.;
431 #ifdef WITH_DEBUG_NTLM
432
433 if (credentials)
434 {
435 WLog_VRB(TAG, "Password (length = %" PRIu32 ")", credentials->identity.PasswordLength * 2);
436 winpr_HexDump(TAG, WLOG_TRACE, (BYTE*)credentials->identity.Password,
437 credentials->identity.PasswordLength * 2);
438 WLog_VRB(TAG, "Username (length = %" PRIu32 ")", credentials->identity.UserLength * 2);
439 winpr_HexDump(TAG, WLOG_TRACE, (BYTE*)credentials->identity.User,
440 credentials->identity.UserLength * 2);
441 WLog_VRB(TAG, "Domain (length = %" PRIu32 ")", credentials->identity.DomainLength * 2);
442 winpr_HexDump(TAG, WLOG_TRACE, (BYTE*)credentials->identity.Domain,
443 credentials->identity.DomainLength * 2);
444 }
445 else
446 WLog_VRB(TAG, "Strange, NTLM_CONTEXT is missing valid credentials...");
447
448 WLog_VRB(TAG, "Workstation (length = %" PRIu16 ")", context->Workstation.Length);
449 winpr_HexDump(TAG, WLOG_TRACE, (BYTE*)context->Workstation.Buffer, context->Workstation.Length);
450 WLog_VRB(TAG, "NTOWFv2, NTLMv2 Hash");
451 winpr_HexDump(TAG, WLOG_TRACE, context->NtlmV2Hash, WINPR_MD5_DIGEST_LENGTH);
452 #endif
453
454 if (memcmpcxx . . $ memcmp(36f949851efa3055).(context->NtlmV2Hashcxx . . $ $anonymous_type_544b217a83a6fa2a_13#NtlmV2Hash., NTLM_NULL_BUFFERcxx . . $ NTLM_NULL_BUFFER., 16) != 0)
455 return TRUEcxx . . $ `winpr/include/winpr/wtypes.h:126:9`!;
456
457 if (!credentials)
458 return FALSEcxx . . $ `winpr/include/winpr/wtypes.h:122:9`!;
459 else if (memcmpcxx . . $ memcmp(36f949851efa3055).(context->NtlmHashcxx . . $ $anonymous_type_544b217a83a6fa2a_13#NtlmHash., NTLM_NULL_BUFFERcxx . . $ NTLM_NULL_BUFFER., 16) != 0)
460 {
461 if ((credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..Flagscxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#Flags. & SEC_WINNT_AUTH_IDENTITY_UNICODEcxx . . $ `winpr/include/winpr/sspi.h:687:9`!) != 0)
462 {
463 return NTOWFv2FromHashWcxx . . $ NTOWFv2FromHashW(5d1ca2c9a57d4495).(context->NtlmHashcxx . . $ $anonymous_type_544b217a83a6fa2a_13#NtlmHash., (LPWSTRcxx . . $ LPWSTR#)credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..Usercxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#User.,
464 credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..UserLengthcxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#UserLength. * 2,
465 (LPWSTRcxx . . $ LPWSTR#)credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..Domaincxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#Domain.,
466 credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..DomainLengthcxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#DomainLength. * 2, hash);
467 }
468 else if ((credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..Flagscxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#Flags. & SEC_WINNT_AUTH_IDENTITY_ANSIcxx . . $ `winpr/include/winpr/sspi.h:686:9`!) != 0)
469 {
470 return NTOWFv2FromHashAcxx . . $ NTOWFv2FromHashA(e550fac7087cd298).(context->NtlmHashcxx . . $ $anonymous_type_544b217a83a6fa2a_13#NtlmHash., (char*)credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..Usercxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#User.,
471 credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..UserLengthcxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#UserLength.,
472 (char*)credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..Domaincxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#Domain.,
473 credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..DomainLengthcxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#DomainLength., hash);
474 }
475 else
476 return FALSEcxx . . $ `winpr/include/winpr/wtypes.h:122:9`!;
477 }
478 else if (credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..Flagscxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#Flags. & SEC_WINPR_AUTH_IDENTITY_PASSWORD_HASHcxx . . $ `winpr/include/winpr/sspi.h:700:9`!)
479 {
480 /* Special case for WinPR: password hash */
481 if (ntlm_convert_password_hashcxx . . $ ntlm_convert_password_hash(e331f041739b9679).(context, context->NtlmHashcxx . . $ $anonymous_type_544b217a83a6fa2a_13#NtlmHash., sizeof(context->NtlmHashcxx . . $ $anonymous_type_544b217a83a6fa2a_13#NtlmHash.)) < 0)
482 return FALSEcxx . . $ `winpr/include/winpr/wtypes.h:122:9`!;
483
484 return NTOWFv2FromHashWcxx . . $ NTOWFv2FromHashW(5d1ca2c9a57d4495).(context->NtlmHashcxx . . $ $anonymous_type_544b217a83a6fa2a_13#NtlmHash., (LPWSTRcxx . . $ LPWSTR#)credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..Usercxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#User.,
485 credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..UserLengthcxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#UserLength. * 2,
486 (LPWSTRcxx . . $ LPWSTR#)credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..Domaincxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#Domain.,
487 credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..DomainLengthcxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#DomainLength. * 2, hash);
488 }
489 else if (credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..Passwordcxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#Password.)
490 {
491 return NTOWFv2Wcxx . . $ NTOWFv2W(eb3ae89c6349d859).(
492 (LPWSTRcxx . . $ LPWSTR#)credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..Passwordcxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#Password., credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..PasswordLengthcxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#PasswordLength. * 2,
493 (LPWSTRcxx . . $ LPWSTR#)credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..Usercxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#User., credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..UserLengthcxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#UserLength. * 2,
494 (LPWSTRcxx . . $ LPWSTR#)credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..Domaincxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#Domain., credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity..DomainLengthcxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_37#DomainLength. * 2, hash);
495 }
496 else if (context->HashCallbackcxx . . $ $anonymous_type_544b217a83a6fa2a_13#HashCallback.)
497 {
498 SecBuffercxx . . $ SecBuffer# proofValue = WINPR_C_ARRAY_INITcxx . . $ `winpr/include/winpr/platform.h:87:9`!;
499 SecBuffercxx . . $ SecBuffer# micValue = WINPR_C_ARRAY_INITcxx . . $ `winpr/include/winpr/platform.h:87:9`!;
500
501 if (ntlm_computeProofValuecxx . . $ ntlm_computeProofValue(cc5b7ad649ddaba1).(context, &proofValue) != SEC_E_OKcxx . . $ `winpr/include/winpr/sspi.h:133:9`!)
502 return FALSEcxx . . $ `winpr/include/winpr/wtypes.h:122:9`!;
503
504 if (ntlm_computeMicValuecxx . . $ ntlm_computeMicValue(cc5b7ad649ddaba1).(context, &micValue) != SEC_E_OKcxx . . $ `winpr/include/winpr/sspi.h:133:9`!)
505 {
506 sspi_SecBufferFreecxx . . $ sspi_SecBufferFree(32b3ea3b65e8fed4).(&proofValue);
507 return FALSEcxx . . $ `winpr/include/winpr/wtypes.h:122:9`!;
508 }
509
510 const SECURITY_STATUScxx . . $ SECURITY_STATUS# ret = context->HashCallbackcxx . . $ $anonymous_type_544b217a83a6fa2a_13#HashCallback.(
511 context->HashCallbackArgcxx . . $ $anonymous_type_544b217a83a6fa2a_13#HashCallbackArg., &credentials->identitycxx . . $ $anonymous_type_5960768699aeeb84_0#identity., &proofValue,
512 context->EncryptedRandomSessionKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#EncryptedRandomSessionKey., context->AUTHENTICATE_MESSAGEcxx . . $ $anonymous_type_544b217a83a6fa2a_13#AUTHENTICATE_MESSAGE..MessageIntegrityCheckcxx . . $ $anonymous_type_544b217a83a6fa2a_12#MessageIntegrityCheck.,
513 &micValue, hash);
514 sspi_SecBufferFreecxx . . $ sspi_SecBufferFree(32b3ea3b65e8fed4).(&proofValue);
515 sspi_SecBufferFreecxx . . $ sspi_SecBufferFree(32b3ea3b65e8fed4).(&micValue);
516 return ret == SEC_E_OKcxx . . $ `winpr/include/winpr/sspi.h:133:9`!;
517 }
518 else if (context->UseSamFileDatabasecxx . . $ $anonymous_type_544b217a83a6fa2a_13#UseSamFileDatabase.)
519 {
520 return ntlm_fetch_ntlm_v2_hashcxx . . $ ntlm_fetch_ntlm_v2_hash(5ad8f0ae590c67d4).(context, hash);
521 }
522
523 return TRUEcxx . . $ `winpr/include/winpr/wtypes.h:126:9`!;
524 }
525
526 SECURITY_STATUScxx . . $ SECURITY_STATUS# ntlm_compute_lm_v2_responsecxx . . $ ntlm_compute_lm_v2_response(62159e91f0a821e).(NTLM_CONTEXTcxx . . $ NTLM_CONTEXT#* context)
527 {
528 BYTEcxx . . $ BYTE#* response = nullptrcxx . . $ `winpr/include/winpr/platform.h:88:9`!;
529 BYTEcxx . . $ BYTE# value[WINPR_MD5_DIGEST_LENGTHcxx . . $ `winpr/include/winpr/custom-crypto.h:34:9`!] = WINPR_C_ARRAY_INITcxx . . $ `winpr/include/winpr/platform.h:87:9`!;
530
531 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(context);
532
533 if (context->LmCompatibilityLevelcxx . . $ $anonymous_type_544b217a83a6fa2a_13#LmCompatibilityLevel. < 2)
534 {
535 if (!sspi_SecBufferAlloccxx . . $ sspi_SecBufferAlloc(390a1ca73a7a932d).(&context->LmChallengeResponsecxx . . $ $anonymous_type_544b217a83a6fa2a_13#LmChallengeResponse., 24))
536 return SEC_E_INSUFFICIENT_MEMORYcxx . . $ `winpr/include/winpr/sspi.h:134:9`!;
537
538 ZeroMemorycxx . . $ `winpr/include/winpr/crt.h:126:9`!(context->LmChallengeResponse.pvBuffer, 24);
539 return SEC_E_OKcxx . . $ `winpr/include/winpr/sspi.h:133:9`!;
540 }
541
542 /* Compute the NTLMv2 hash */
543
544 if (!ntlm_compute_ntlm_v2_hashcxx . . $ ntlm_compute_ntlm_v2_hash(5ad8f0ae590c67d4).(context, context->NtlmV2Hashcxx . . $ $anonymous_type_544b217a83a6fa2a_13#NtlmV2Hash.))
545 return SEC_E_NO_CREDENTIALScxx . . $ `winpr/include/winpr/sspi.h:148:9`!;
546
547 /* Concatenate the server and client challenges */
548 CopyMemorycxx . . $ `winpr/include/winpr/crt.h:123:9`!(value, context->ServerChallenge, 8);
549 CopyMemorycxx . . $ `winpr/include/winpr/crt.h:123:9`!(&value[8], context->ClientChallenge, 8);
550
551 if (!ntlm_SecBufferRealloccxx . . $ ntlm_SecBufferRealloc(c43574e4947ec252).(&context->LmChallengeResponsecxx . . $ $anonymous_type_544b217a83a6fa2a_13#LmChallengeResponse., 24))
552 return SEC_E_INSUFFICIENT_MEMORYcxx . . $ `winpr/include/winpr/sspi.h:134:9`!;
553
554 response = (BYTEcxx . . $ BYTE#*)context->LmChallengeResponsecxx . . $ $anonymous_type_544b217a83a6fa2a_13#LmChallengeResponse..pvBuffercxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_44#pvBuffer.;
555 /* Compute the HMAC-MD5 hash of the resulting value using the NTLMv2 hash as the key */
556 if (!winpr_HMACcxx . . $ winpr_HMAC(762c37cc53019c45).(WINPR_MD_MD5cxx . . $ WINPR_MD_MD5., (void*)context->NtlmV2Hashcxx . . $ $anonymous_type_544b217a83a6fa2a_13#NtlmV2Hash., WINPR_MD5_DIGEST_LENGTHcxx . . $ `winpr/include/winpr/custom-crypto.h:34:9`!, (BYTEcxx . . $ BYTE#*)value,
557 WINPR_MD5_DIGEST_LENGTHcxx . . $ `winpr/include/winpr/custom-crypto.h:34:9`!, response, WINPR_MD5_DIGEST_LENGTHcxx . . $ `winpr/include/winpr/custom-crypto.h:34:9`!))
558 return SEC_E_ALGORITHM_MISMATCHcxx . . $ `winpr/include/winpr/sspi.h:165:9`!;
559
560 /* Concatenate the resulting HMAC-MD5 hash and the client challenge, giving us the LMv2 response
561 * (24 bytes) */
562 CopyMemorycxx . . $ `winpr/include/winpr/crt.h:123:9`!(&response[16], context->ClientChallenge, 8);
563 return SEC_E_OKcxx . . $ `winpr/include/winpr/sspi.h:133:9`!;
564 }
565
566 /**
567 * Compute NTLMv2 Response.
568 *
569 * NTLMv2_RESPONSE msdn{cc236653}
570 * NTLMv2 Authentication msdn{cc236700}
571 *
572 * @param context A pointer to the NTLM context
573 * @return \b TRUE for success, \b FALSE for failure
574 */
575
576 SECURITY_STATUScxx . . $ SECURITY_STATUS# ntlm_compute_ntlm_v2_responsecxx . . $ ntlm_compute_ntlm_v2_response(62159e91f0a821e).(NTLM_CONTEXTcxx . . $ NTLM_CONTEXT#* context)
577 {
578 SecBuffercxx . . $ SecBuffer# ntlm_v2_temp = WINPR_C_ARRAY_INITcxx . . $ `winpr/include/winpr/platform.h:87:9`!;
579 SecBuffercxx . . $ SecBuffer# ntlm_v2_temp_chal = WINPR_C_ARRAY_INITcxx . . $ `winpr/include/winpr/platform.h:87:9`!;
580
581 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(context);
582
583 PSecBuffercxx . . $ PSecBuffer# TargetInfo = &context->ChallengeTargetInfocxx . . $ $anonymous_type_544b217a83a6fa2a_13#ChallengeTargetInfo.;
584 SECURITY_STATUScxx . . $ SECURITY_STATUS# ret = SEC_E_INSUFFICIENT_MEMORYcxx . . $ `winpr/include/winpr/sspi.h:134:9`!;
585
586 if (!sspi_SecBufferAlloccxx . . $ sspi_SecBufferAlloc(390a1ca73a7a932d).(&ntlm_v2_temp, TargetInfo->cbBuffercxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_44#cbBuffer. + 28))
587 goto exit;
588
589 ZeroMemorycxx . . $ `winpr/include/winpr/crt.h:126:9`!(ntlm_v2_temp.pvBuffer, ntlm_v2_temp.cbBuffer);
590 {
591 BYTEcxx . . $ BYTE#* blob = (BYTEcxx . . $ BYTE#*)ntlm_v2_temp.pvBuffercxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_44#pvBuffer.;
592
593 /* Compute the NTLMv2 hash */
594 ret = SEC_E_NO_CREDENTIALScxx . . $ `winpr/include/winpr/sspi.h:148:9`!;
595 if (!ntlm_compute_ntlm_v2_hashcxx . . $ ntlm_compute_ntlm_v2_hash(5ad8f0ae590c67d4).(context, (BYTEcxx . . $ BYTE#*)context->NtlmV2Hashcxx . . $ $anonymous_type_544b217a83a6fa2a_13#NtlmV2Hash.))
596 goto exit;
597
598 /* Construct temp */
599 blob[0] = 1; /* RespType (1 byte) */
600 blob[1] = 1; /* HighRespType (1 byte) */
601 /* Reserved1 (2 bytes) */
602 /* Reserved2 (4 bytes) */
603 CopyMemorycxx . . $ `winpr/include/winpr/crt.h:123:9`!(&blob[8], context->Timestamp, 8); /* Timestamp (8 bytes) */
604 CopyMemorycxx . . $ `winpr/include/winpr/crt.h:123:9`!(&blob[16], context->ClientChallenge, 8); /* ClientChallenge (8 bytes) */
605 /* Reserved3 (4 bytes) */
606 CopyMemorycxx . . $ `winpr/include/winpr/crt.h:123:9`!(&blob[28], TargetInfo->pvBuffer, TargetInfo->cbBuffer);
607 #ifdef WITH_DEBUG_NTLM
608 WLog_VRB(TAG, "NTLMv2 Response Temp Blob");
609 winpr_HexDump(TAG, WLOG_TRACE, ntlm_v2_temp.pvBuffer, ntlm_v2_temp.cbBuffer);
610 #endif
611 }
612 /* Concatenate server challenge with temp */
613 ret = SEC_E_INSUFFICIENT_MEMORYcxx . . $ `winpr/include/winpr/sspi.h:134:9`!;
614 if (!sspi_SecBufferAlloccxx . . $ sspi_SecBufferAlloc(390a1ca73a7a932d).(&ntlm_v2_temp_chal, ntlm_v2_temp.cbBuffercxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_44#cbBuffer. + 8))
615 goto exit;
616
617 {
618 BYTEcxx . . $ BYTE#* blob = (BYTEcxx . . $ BYTE#*)ntlm_v2_temp_chal.pvBuffercxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_44#pvBuffer.;
619 CopyMemorycxx . . $ `winpr/include/winpr/crt.h:123:9`!(blob, context->ServerChallenge, 8);
620 CopyMemorycxx . . $ `winpr/include/winpr/crt.h:123:9`!(&blob[8], ntlm_v2_temp.pvBuffer, ntlm_v2_temp.cbBuffer);
621 if (!winpr_HMACcxx . . $ winpr_HMAC(762c37cc53019c45).(WINPR_MD_MD5cxx . . $ WINPR_MD_MD5., (BYTEcxx . . $ BYTE#*)context->NtlmV2Hashcxx . . $ $anonymous_type_544b217a83a6fa2a_13#NtlmV2Hash., WINPR_MD5_DIGEST_LENGTHcxx . . $ `winpr/include/winpr/custom-crypto.h:34:9`!,
622 (BYTEcxx . . $ BYTE#*)ntlm_v2_temp_chal.pvBuffercxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_44#pvBuffer., ntlm_v2_temp_chal.cbBuffercxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_44#cbBuffer.,
623 context->NtProofStringcxx . . $ $anonymous_type_544b217a83a6fa2a_13#NtProofString., WINPR_MD5_DIGEST_LENGTHcxx . . $ `winpr/include/winpr/custom-crypto.h:34:9`!))
624 goto exit;
625 }
626
627 /* NtChallengeResponse, Concatenate NTProofStr with temp */
628 if (!ntlm_SecBufferRealloccxx . . $ ntlm_SecBufferRealloc(c43574e4947ec252).(&context->NtChallengeResponsecxx . . $ $anonymous_type_544b217a83a6fa2a_13#NtChallengeResponse., ntlm_v2_temp.cbBuffercxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_44#cbBuffer. + 16))
629 goto exit;
630
631 {
632 BYTEcxx . . $ BYTE#* blob = (BYTEcxx . . $ BYTE#*)context->NtChallengeResponsecxx . . $ $anonymous_type_544b217a83a6fa2a_13#NtChallengeResponse..pvBuffercxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_44#pvBuffer.;
633 CopyMemorycxx . . $ `winpr/include/winpr/crt.h:123:9`!(blob, context->NtProofString, WINPR_MD5_DIGEST_LENGTHcxx . . $ `winpr/include/winpr/custom-crypto.h:34:9`!);
634 CopyMemorycxx . . $ `winpr/include/winpr/crt.h:123:9`!(&blob[16], ntlm_v2_temp.pvBuffer, ntlm_v2_temp.cbBuffer);
635 }
636 /* Compute SessionBaseKey, the HMAC-MD5 hash of NTProofStr using the NTLMv2 hash as the key */
637 if (!winpr_HMACcxx . . $ winpr_HMAC(762c37cc53019c45).(WINPR_MD_MD5cxx . . $ WINPR_MD_MD5., (BYTEcxx . . $ BYTE#*)context->NtlmV2Hashcxx . . $ $anonymous_type_544b217a83a6fa2a_13#NtlmV2Hash., WINPR_MD5_DIGEST_LENGTHcxx . . $ `winpr/include/winpr/custom-crypto.h:34:9`!,
638 context->NtProofStringcxx . . $ $anonymous_type_544b217a83a6fa2a_13#NtProofString., WINPR_MD5_DIGEST_LENGTHcxx . . $ `winpr/include/winpr/custom-crypto.h:34:9`!, context->SessionBaseKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#SessionBaseKey.,
639 WINPR_MD5_DIGEST_LENGTHcxx . . $ `winpr/include/winpr/custom-crypto.h:34:9`!))
640 goto exit;
641 ret = SEC_E_OKcxx . . $ `winpr/include/winpr/sspi.h:133:9`!;
642 exit:
643 sspi_SecBufferFreecxx . . $ sspi_SecBufferFree(32b3ea3b65e8fed4).(&ntlm_v2_temp);
644 sspi_SecBufferFreecxx . . $ sspi_SecBufferFree(32b3ea3b65e8fed4).(&ntlm_v2_temp_chal);
645 return ret;
646 }
647
648 /**
649 * Encrypt the given plain text using RC4 and the given key.
650 * @param key RC4 key
651 * @param length text length
652 * @param plaintext plain text
653 * @param ciphertext cipher text
654 */
655
656 BOOLcxx . . $ BOOL# ntlm_rc4kcxx . . $ ntlm_rc4k(af53d2325d4537ff).(BYTEcxx . . $ BYTE#* key, size_t length, BYTEcxx . . $ BYTE#* plaintext, BYTEcxx . . $ BYTE#* ciphertext)
657 {
658 WINPR_RC4_CTXcxx . . $ WINPR_RC4_CTX#* rc4 = winpr_RC4_Newcxx . . $ winpr_RC4_New(13d3dba6f4565a89).(key, 16);
659
660 if (!rc4)
661 return FALSEcxx . . $ `winpr/include/winpr/wtypes.h:122:9`!;
662
663 const BOOLcxx . . $ BOOL# rc = winpr_RC4_Updatecxx . . $ winpr_RC4_Update(ed5b6f42ccfe68a5).(rc4, length, plaintext, ciphertext);
664 winpr_RC4_Freecxx . . $ winpr_RC4_Free(d93f1f27970c8599).(rc4);
665 return rc;
666 }
667
668 /**
669 * Generate client challenge (8-byte nonce).
670 * @param context A pointer to the NTLM context
671 */
672
673 BOOLcxx . . $ BOOL# ntlm_generate_client_challengecxx . . $ ntlm_generate_client_challenge(62159e91f0a821e).(NTLM_CONTEXTcxx . . $ NTLM_CONTEXT#* context)
674 {
675 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(context);
676
677 /* ClientChallenge is used in computation of LMv2 and NTLMv2 responses */
678 if (memcmpcxx . . $ memcmp(36f949851efa3055).(context->ClientChallengecxx . . $ $anonymous_type_544b217a83a6fa2a_13#ClientChallenge., NTLM_NULL_BUFFERcxx . . $ NTLM_NULL_BUFFER., sizeof(context->ClientChallengecxx . . $ $anonymous_type_544b217a83a6fa2a_13#ClientChallenge.)) != 0)
679 return TRUEcxx . . $ `winpr/include/winpr/wtypes.h:126:9`!;
680
681 return winpr_RANDcxx . . $ winpr_RAND(c0a5f96701d3f89).(context->ClientChallengecxx . . $ $anonymous_type_544b217a83a6fa2a_13#ClientChallenge., sizeof(context->ClientChallengecxx . . $ $anonymous_type_544b217a83a6fa2a_13#ClientChallenge.)) >= 0;
682 }
683
684 /**
685 * Generate server challenge (8-byte nonce).
686 * @param context A pointer to the NTLM context
687 */
688
689 BOOLcxx . . $ BOOL# ntlm_generate_server_challengecxx . . $ ntlm_generate_server_challenge(62159e91f0a821e).(NTLM_CONTEXTcxx . . $ NTLM_CONTEXT#* context)
690 {
691 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(context);
692
693 if (memcmpcxx . . $ memcmp(36f949851efa3055).(context->ServerChallengecxx . . $ $anonymous_type_544b217a83a6fa2a_13#ServerChallenge., NTLM_NULL_BUFFERcxx . . $ NTLM_NULL_BUFFER., sizeof(context->ServerChallengecxx . . $ $anonymous_type_544b217a83a6fa2a_13#ServerChallenge.)) != 0)
694 return TRUEcxx . . $ `winpr/include/winpr/wtypes.h:126:9`!;
695
696 return winpr_RANDcxx . . $ winpr_RAND(c0a5f96701d3f89).(context->ServerChallengecxx . . $ $anonymous_type_544b217a83a6fa2a_13#ServerChallenge., sizeof(context->ServerChallengecxx . . $ $anonymous_type_544b217a83a6fa2a_13#ServerChallenge.)) >= 0;
697 }
698
699 /**
700 * Generate KeyExchangeKey (the 128-bit SessionBaseKey). msdn{cc236710}
701 * @param context A pointer to the NTLM context
702 */
703
704 BOOLcxx . . $ BOOL# ntlm_generate_key_exchange_keycxx . . $ ntlm_generate_key_exchange_key(62159e91f0a821e).(NTLM_CONTEXTcxx . . $ NTLM_CONTEXT#* context)
705 {
706 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(context);
707 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(sizeof(context->KeyExchangeKey) == sizeof(context->SessionBaseKey));
708
709 /* In NTLMv2, KeyExchangeKey is the 128-bit SessionBaseKey */
710 CopyMemorycxx . . $ `winpr/include/winpr/crt.h:123:9`!(context->KeyExchangeKey, context->SessionBaseKey, sizeof(context->KeyExchangeKey));
711 return TRUEcxx . . $ `winpr/include/winpr/wtypes.h:126:9`!;
712 }
713
714 /**
715 * Generate RandomSessionKey (16-byte nonce).
716 * @param context A pointer to the NTLM context
717 */
718
719 BOOLcxx . . $ BOOL# ntlm_generate_random_session_keycxx . . $ ntlm_generate_random_session_key(62159e91f0a821e).(NTLM_CONTEXTcxx . . $ NTLM_CONTEXT#* context)
720 {
721 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(context);
722 return winpr_RANDcxx . . $ winpr_RAND(c0a5f96701d3f89).(context->RandomSessionKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#RandomSessionKey., sizeof(context->RandomSessionKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#RandomSessionKey.)) >= 0;
723 }
724
725 /**
726 * Generate ExportedSessionKey (the RandomSessionKey, exported)
727 * @param context A pointer to the NTLM context
728 */
729
730 BOOLcxx . . $ BOOL# ntlm_generate_exported_session_keycxx . . $ ntlm_generate_exported_session_key(62159e91f0a821e).(NTLM_CONTEXTcxx . . $ NTLM_CONTEXT#* context)
731 {
732 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(context);
733 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(sizeof(context->ExportedSessionKey) >= sizeof(context->RandomSessionKey));
734
735 CopyMemorycxx . . $ `winpr/include/winpr/crt.h:123:9`!(context->ExportedSessionKey, context->RandomSessionKey,
736 sizeof(context->ExportedSessionKey));
737 return TRUEcxx . . $ `winpr/include/winpr/wtypes.h:126:9`!;
738 }
739
740 /**
741 * Encrypt RandomSessionKey (RC4-encrypted RandomSessionKey, using KeyExchangeKey as the key).
742 * @param context A pointer to the NTLM context
743 */
744
745 BOOLcxx . . $ BOOL# ntlm_encrypt_random_session_keycxx . . $ ntlm_encrypt_random_session_key(62159e91f0a821e).(NTLM_CONTEXTcxx . . $ NTLM_CONTEXT#* context)
746 {
747 /* In NTLMv2, EncryptedRandomSessionKey is the ExportedSessionKey RC4-encrypted with the
748 * KeyExchangeKey */
749 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(context);
750 return ntlm_rc4kcxx . . $ ntlm_rc4k(af53d2325d4537ff).(context->KeyExchangeKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#KeyExchangeKey., 16, context->RandomSessionKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#RandomSessionKey.,
751 context->EncryptedRandomSessionKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#EncryptedRandomSessionKey.);
752 }
753
754 /**
755 * Decrypt RandomSessionKey (RC4-encrypted RandomSessionKey, using KeyExchangeKey as the key).
756 * @param context A pointer to the NTLM context
757 */
758
759 BOOLcxx . . $ BOOL# ntlm_decrypt_random_session_keycxx . . $ ntlm_decrypt_random_session_key(62159e91f0a821e).(NTLM_CONTEXTcxx . . $ NTLM_CONTEXT#* context)
760 {
761 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(context);
762
763 /* In NTLMv2, EncryptedRandomSessionKey is the ExportedSessionKey RC4-encrypted with the
764 * KeyExchangeKey */
765
766 /**
767 * if (NegotiateFlags & NTLMSSP_NEGOTIATE_KEY_EXCH)
768 * Set RandomSessionKey to RC4K(KeyExchangeKey,
769 * AUTHENTICATE_MESSAGE.EncryptedRandomSessionKey) else Set RandomSessionKey to KeyExchangeKey
770 */
771 if (context->NegotiateKeyExchangecxx . . $ $anonymous_type_544b217a83a6fa2a_13#NegotiateKeyExchange.)
772 {
773 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(sizeof(context->EncryptedRandomSessionKey) ==
774 sizeof(context->RandomSessionKey));
775 return ntlm_rc4kcxx . . $ ntlm_rc4k(af53d2325d4537ff).(context->KeyExchangeKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#KeyExchangeKey., sizeof(context->EncryptedRandomSessionKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#EncryptedRandomSessionKey.),
776 context->EncryptedRandomSessionKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#EncryptedRandomSessionKey., context->RandomSessionKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#RandomSessionKey.);
777 }
778 else
779 {
780 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(sizeof(context->RandomSessionKey) == sizeof(context->KeyExchangeKey));
781 CopyMemorycxx . . $ `winpr/include/winpr/crt.h:123:9`!(context->RandomSessionKey, context->KeyExchangeKey,
782 sizeof(context->RandomSessionKey));
783 }
784 return TRUEcxx . . $ `winpr/include/winpr/wtypes.h:126:9`!;
785 }
786
787 /**
788 * Generate signing key msdn{cc236711}
789 *
790 * @param exported_session_key ExportedSessionKey
791 * @param sign_magic Sign magic string
792 * @param signing_key Destination signing key
793 *
794 * @return \b TRUE for success, \b FALSE for failure
795 */
796
797 static BOOLcxx . . $ BOOL# ntlm_generate_signing_keycxx . . $ ntlm_generate_signing_key(f5cc95e101109881).(BYTEcxx . . $ BYTE#* exported_session_key, const SecBuffercxx . . $ SecBuffer#* sign_magic,
798 BYTEcxx . . $ BYTE#* signing_key)
799 {
800 BOOLcxx . . $ BOOL# rc = FALSEcxx . . $ `winpr/include/winpr/wtypes.h:122:9`!;
801
802 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(exported_session_key);
803 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(sign_magic);
804 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(signing_key);
805
806 const size_t length = WINPR_MD5_DIGEST_LENGTHcxx . . $ `winpr/include/winpr/custom-crypto.h:34:9`! + sign_magic->cbBuffercxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_44#cbBuffer.;
807 BYTEcxx . . $ BYTE#* value = (BYTEcxx . . $ BYTE#*)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(length);
808
809 if (!value)
810 goto out;
811
812 /* Concatenate ExportedSessionKey with sign magic */
813 CopyMemorycxx . . $ `winpr/include/winpr/crt.h:123:9`!(value, exported_session_key, WINPR_MD5_DIGEST_LENGTHcxx . . $ `winpr/include/winpr/custom-crypto.h:34:9`!);
814 CopyMemorycxx . . $ `winpr/include/winpr/crt.h:123:9`!(&value[WINPR_MD5_DIGEST_LENGTHcxx . . $ `winpr/include/winpr/custom-crypto.h:34:9`!], sign_magic->pvBuffer, sign_magic->cbBuffer);
815
816 rc = winpr_Digestcxx . . $ winpr_Digest(5bb0455f21b325be).(WINPR_MD_MD5cxx . . $ WINPR_MD_MD5., value, length, signing_key, WINPR_MD5_DIGEST_LENGTHcxx . . $ `winpr/include/winpr/custom-crypto.h:34:9`!);
817
818 out:
819 freecxx . . $ free(5d22bdacc48458e8).(value);
820 return rc;
821 }
822
823 /**
824 * Generate client signing key (ClientSigningKey). msdn{cc236711}
825 * @param context A pointer to the NTLM context
826 *
827 * @return \b TRUE for success, \b FALSE for failure
828 */
829
830 BOOLcxx . . $ BOOL# ntlm_generate_client_signing_keycxx . . $ ntlm_generate_client_signing_key(62159e91f0a821e).(NTLM_CONTEXTcxx . . $ NTLM_CONTEXT#* context)
831 {
832 const SecBuffercxx . . $ SecBuffer# signMagic = { sizeof(NTLM_CLIENT_SIGN_MAGICcxx . . $ NTLM_CLIENT_SIGN_MAGIC.), 0, NTLM_CLIENT_SIGN_MAGICcxx . . $ NTLM_CLIENT_SIGN_MAGIC. };
833
834 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(context);
835 return ntlm_generate_signing_keycxx . . $ ntlm_generate_signing_key(f5cc95e101109881).(context->ExportedSessionKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#ExportedSessionKey., &signMagic,
836 context->ClientSigningKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#ClientSigningKey.);
837 }
838
839 /**
840 * Generate server signing key (ServerSigningKey). msdn{cc236711}
841 * @param context A pointer to the NTLM context
842 *
843 * @return \b TRUE for success, \b FALSE for failure
844 */
845
846 BOOLcxx . . $ BOOL# ntlm_generate_server_signing_keycxx . . $ ntlm_generate_server_signing_key(62159e91f0a821e).(NTLM_CONTEXTcxx . . $ NTLM_CONTEXT#* context)
847 {
848 const SecBuffercxx . . $ SecBuffer# signMagic = { sizeof(NTLM_SERVER_SIGN_MAGICcxx . . $ NTLM_SERVER_SIGN_MAGIC.), 0, NTLM_SERVER_SIGN_MAGICcxx . . $ NTLM_SERVER_SIGN_MAGIC. };
849
850 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(context);
851 return ntlm_generate_signing_keycxx . . $ ntlm_generate_signing_key(f5cc95e101109881).(context->ExportedSessionKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#ExportedSessionKey., &signMagic,
852 context->ServerSigningKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#ServerSigningKey.);
853 }
854
855 /**
856 * Generate client sealing key (ClientSealingKey). msdn{cc236712}
857 * @param context A pointer to the NTLM context
858 *
859 * @return \b TRUE for success, \b FALSE for failure
860 */
861
862 BOOLcxx . . $ BOOL# ntlm_generate_client_sealing_keycxx . . $ ntlm_generate_client_sealing_key(62159e91f0a821e).(NTLM_CONTEXTcxx . . $ NTLM_CONTEXT#* context)
863 {
864 const SecBuffercxx . . $ SecBuffer# sealMagic = { sizeof(NTLM_CLIENT_SEAL_MAGICcxx . . $ NTLM_CLIENT_SEAL_MAGIC.), 0, NTLM_CLIENT_SEAL_MAGICcxx . . $ NTLM_CLIENT_SEAL_MAGIC. };
865
866 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(context);
867 return ntlm_generate_signing_keycxx . . $ ntlm_generate_signing_key(f5cc95e101109881).(context->ExportedSessionKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#ExportedSessionKey., &sealMagic,
868 context->ClientSealingKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#ClientSealingKey.);
869 }
870
871 /**
872 * Generate server sealing key (ServerSealingKey). msdn{cc236712}
873 * @param context A pointer to the NTLM context
874 *
875 * @return \b TRUE for success, \b FALSE for failure
876 */
877
878 BOOLcxx . . $ BOOL# ntlm_generate_server_sealing_keycxx . . $ ntlm_generate_server_sealing_key(62159e91f0a821e).(NTLM_CONTEXTcxx . . $ NTLM_CONTEXT#* context)
879 {
880 const SecBuffercxx . . $ SecBuffer# sealMagic = { sizeof(NTLM_SERVER_SEAL_MAGICcxx . . $ NTLM_SERVER_SEAL_MAGIC.), 0, NTLM_SERVER_SEAL_MAGICcxx . . $ NTLM_SERVER_SEAL_MAGIC. };
881
882 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(context);
883 return ntlm_generate_signing_keycxx . . $ ntlm_generate_signing_key(f5cc95e101109881).(context->ExportedSessionKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#ExportedSessionKey., &sealMagic,
884 context->ServerSealingKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#ServerSealingKey.);
885 }
886
887 /**
888 * Initialize RC4 stream cipher states for sealing.
889 * @param context A pointer to the NTLM context
890 */
891
892 BOOLcxx . . $ BOOL# ntlm_init_rc4_seal_statescxx . . $ ntlm_init_rc4_seal_states(62159e91f0a821e).(NTLM_CONTEXTcxx . . $ NTLM_CONTEXT#* context)
893 {
894 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(context);
895 if (context->servercxx . . $ $anonymous_type_544b217a83a6fa2a_13#server.)
896 {
897 context->SendSigningKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#SendSigningKey. = context->ServerSigningKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#ServerSigningKey.;
898 context->RecvSigningKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#RecvSigningKey. = context->ClientSigningKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#ClientSigningKey.;
899 context->SendSealingKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#SendSealingKey. = context->ClientSealingKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#ClientSealingKey.;
900 context->RecvSealingKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#RecvSealingKey. = context->ServerSealingKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#ServerSealingKey.;
901 context->SendRc4Sealcxx . . $ $anonymous_type_544b217a83a6fa2a_13#SendRc4Seal. =
902 winpr_RC4_Newcxx . . $ winpr_RC4_New(13d3dba6f4565a89).(context->ServerSealingKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#ServerSealingKey., sizeof(context->ServerSealingKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#ServerSealingKey.));
903 context->RecvRc4Sealcxx . . $ $anonymous_type_544b217a83a6fa2a_13#RecvRc4Seal. =
904 winpr_RC4_Newcxx . . $ winpr_RC4_New(13d3dba6f4565a89).(context->ClientSealingKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#ClientSealingKey., sizeof(context->ClientSealingKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#ClientSealingKey.));
905 }
906 else
907 {
908 context->SendSigningKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#SendSigningKey. = context->ClientSigningKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#ClientSigningKey.;
909 context->RecvSigningKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#RecvSigningKey. = context->ServerSigningKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#ServerSigningKey.;
910 context->SendSealingKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#SendSealingKey. = context->ServerSealingKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#ServerSealingKey.;
911 context->RecvSealingKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#RecvSealingKey. = context->ClientSealingKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#ClientSealingKey.;
912 context->SendRc4Sealcxx . . $ $anonymous_type_544b217a83a6fa2a_13#SendRc4Seal. =
913 winpr_RC4_Newcxx . . $ winpr_RC4_New(13d3dba6f4565a89).(context->ClientSealingKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#ClientSealingKey., sizeof(context->ClientSealingKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#ClientSealingKey.));
914 context->RecvRc4Sealcxx . . $ $anonymous_type_544b217a83a6fa2a_13#RecvRc4Seal. =
915 winpr_RC4_Newcxx . . $ winpr_RC4_New(13d3dba6f4565a89).(context->ServerSealingKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#ServerSealingKey., sizeof(context->ServerSealingKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#ServerSealingKey.));
916 }
917 if (!context->SendRc4Sealcxx . . $ $anonymous_type_544b217a83a6fa2a_13#SendRc4Seal.)
918 {
919 WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `winpr/libwinpr/sspi/NTLM/ntlm_compute.c:37:9`!, "Failed to allocate context->SendRc4Seal");
920 return FALSEcxx . . $ `winpr/include/winpr/wtypes.h:122:9`!;
921 }
922 if (!context->RecvRc4Sealcxx . . $ $anonymous_type_544b217a83a6fa2a_13#RecvRc4Seal.)
923 {
924 WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `winpr/libwinpr/sspi/NTLM/ntlm_compute.c:37:9`!, "Failed to allocate context->RecvRc4Seal");
925 return FALSEcxx . . $ `winpr/include/winpr/wtypes.h:122:9`!;
926 }
927 return TRUEcxx . . $ `winpr/include/winpr/wtypes.h:126:9`!;
928 }
929
930 BOOLcxx . . $ BOOL# ntlm_compute_message_integrity_checkcxx . . $ ntlm_compute_message_integrity_check(3f6efc372de5e33a).(NTLM_CONTEXTcxx . . $ NTLM_CONTEXT#* context, BYTEcxx . . $ BYTE#* mic, UINT32cxx . . $ UINT32# size)
931 {
932 BOOLcxx . . $ BOOL# rc = FALSEcxx . . $ `winpr/include/winpr/wtypes.h:122:9`!;
933 /*
934 * Compute the HMAC-MD5 hash of ConcatenationOf(NEGOTIATE_MESSAGE,
935 * CHALLENGE_MESSAGE, AUTHENTICATE_MESSAGE) using the ExportedSessionKey
936 */
937 WINPR_HMAC_CTXcxx . . $ WINPR_HMAC_CTX#* hmac = winpr_HMAC_Newcxx . . $ winpr_HMAC_New(eda14d31e92aac8e).();
938
939 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(context);
940 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(mic);
941 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(size >= WINPR_MD5_DIGEST_LENGTHcxx . . $ `winpr/include/winpr/custom-crypto.h:34:9`!);
942
943 memsetcxx . . $ memset(d1de1e4fb215f1c6).(mic, 0, size);
944 if (!hmac)
945 return FALSEcxx . . $ `winpr/include/winpr/wtypes.h:122:9`!;
946
947 if (!winpr_HMAC_Initcxx . . $ winpr_HMAC_Init(92c13b0dd6fbb09a).(hmac, WINPR_MD_MD5cxx . . $ WINPR_MD_MD5., context->ExportedSessionKeycxx . . $ $anonymous_type_544b217a83a6fa2a_13#ExportedSessionKey., WINPR_MD5_DIGEST_LENGTHcxx . . $ `winpr/include/winpr/custom-crypto.h:34:9`!))
948 goto fail;
949
950 if (!winpr_HMAC_Updatecxx . . $ winpr_HMAC_Update(269662ae430c6e94).(hmac, (BYTEcxx . . $ BYTE#*)context->NegotiateMessagecxx . . $ $anonymous_type_544b217a83a6fa2a_13#NegotiateMessage..pvBuffercxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_44#pvBuffer.,
951 context->NegotiateMessagecxx . . $ $anonymous_type_544b217a83a6fa2a_13#NegotiateMessage..cbBuffercxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_44#cbBuffer.))
952 goto fail;
953 if (!winpr_HMAC_Updatecxx . . $ winpr_HMAC_Update(269662ae430c6e94).(hmac, (BYTEcxx . . $ BYTE#*)context->ChallengeMessagecxx . . $ $anonymous_type_544b217a83a6fa2a_13#ChallengeMessage..pvBuffercxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_44#pvBuffer.,
954 context->ChallengeMessagecxx . . $ $anonymous_type_544b217a83a6fa2a_13#ChallengeMessage..cbBuffercxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_44#cbBuffer.))
955 goto fail;
956
957 if (context->MessageIntegrityCheckOffsetcxx . . $ $anonymous_type_544b217a83a6fa2a_13#MessageIntegrityCheckOffset. > 0)
958 {
959 const BYTEcxx . . $ BYTE#* auth = (BYTEcxx . . $ BYTE#*)context->AuthenticateMessagecxx . . $ $anonymous_type_544b217a83a6fa2a_13#AuthenticateMessage..pvBuffercxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_44#pvBuffer.;
960 const BYTEcxx . . $ BYTE# data[WINPR_MD5_DIGEST_LENGTHcxx . . $ `winpr/include/winpr/custom-crypto.h:34:9`!] = WINPR_C_ARRAY_INITcxx . . $ `winpr/include/winpr/platform.h:87:9`!;
961 const size_t rest = context->MessageIntegrityCheckOffsetcxx . . $ $anonymous_type_544b217a83a6fa2a_13#MessageIntegrityCheckOffset. + sizeof(data);
962
963 if (rest > context->AuthenticateMessagecxx . . $ $anonymous_type_544b217a83a6fa2a_13#AuthenticateMessage..cbBuffercxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_44#cbBuffer.)
964 goto fail;
965 if (!winpr_HMAC_Updatecxx . . $ winpr_HMAC_Update(269662ae430c6e94).(hmac, &auth[0], context->MessageIntegrityCheckOffsetcxx . . $ $anonymous_type_544b217a83a6fa2a_13#MessageIntegrityCheckOffset.))
966 goto fail;
967 if (!winpr_HMAC_Updatecxx . . $ winpr_HMAC_Update(269662ae430c6e94).(hmac, data, sizeof(data)))
968 goto fail;
969 if (!winpr_HMAC_Updatecxx . . $ winpr_HMAC_Update(269662ae430c6e94).(hmac, &auth[rest], context->AuthenticateMessagecxx . . $ $anonymous_type_544b217a83a6fa2a_13#AuthenticateMessage..cbBuffercxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_44#cbBuffer. - rest))
970 goto fail;
971 }
972 else
973 {
974 if (!winpr_HMAC_Updatecxx . . $ winpr_HMAC_Update(269662ae430c6e94).(hmac, (BYTEcxx . . $ BYTE#*)context->AuthenticateMessagecxx . . $ $anonymous_type_544b217a83a6fa2a_13#AuthenticateMessage..pvBuffercxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_44#pvBuffer.,
975 context->AuthenticateMessagecxx . . $ $anonymous_type_544b217a83a6fa2a_13#AuthenticateMessage..cbBuffercxx . . $ $anonymous_type_13c8ac8e1b4cb2c0_44#cbBuffer.))
976 goto fail;
977 }
978 rc = winpr_HMAC_Finalcxx . . $ winpr_HMAC_Final(78a9addfb34fddf4).(hmac, mic, WINPR_MD5_DIGEST_LENGTHcxx . . $ `winpr/include/winpr/custom-crypto.h:34:9`!);
979
980 fail:
981 winpr_HMAC_Freecxx . . $ winpr_HMAC_Free(f305f1c2ab229823).(hmac);
982 return rc;
983 }