Skip to content

Commit 337b920

Browse files
committed
Fix for CreateNTPassword() calling missing function BuildUnicode() when STRING_IS_UNICODE is not defined.
1 parent 9b9f4fc commit 337b920

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

IdNTLMOpenSSL.pas

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,25 @@ function CreateNTPassword(const APassword: String; const ANonce: TIdBytes): TIdB
129129
nt_hpw128: TIdBytes;
130130
nt_resp: array [1..24] of Byte;
131131
LMD4: TIdHashMessageDigest4;
132+
{$IFNDEF STRING_IS_UNICODE}
133+
i: integer;
134+
lPwUnicode: TIdBytes;
135+
{$ENDIF}
132136
begin
133137
CheckMD4Permitted;
134138
LMD4 := TIdHashMessageDigest4.Create;
135139
try
136140
{$IFDEF STRING_IS_UNICODE}
137141
nt_hpw128 := LMD4.HashString(APassword, IndyTextEncoding_UTF16LE);
138142
{$ELSE}
139-
nt_hpw128 := LMD4.HashBytes(BuildUnicode(APassword));
143+
// RLebeau: TODO - should this use UTF-16 as well? This logic will
144+
// not produce a valid Unicode string if non-ASCII characters are present!
145+
SetLength(lPwUnicode, Length(S) * SizeOf(WideChar));
146+
for i := 0 to Length(S)-1 do begin
147+
lPwUnicode[i*2] := Byte(S[i+1]);
148+
lPwUnicode[(i*2)+1] := Byte(#0);
149+
end;
150+
nt_hpw128 := LMD4.HashBytes(lPwUnicode);
140151
{$ENDIF}
141152
finally
142153
LMD4.Free;

0 commit comments

Comments
 (0)