Tcl Library Source Code

View Ticket
Login
Ticket UUID: 66b79317f3081be1e04bd8e7fb7fa9687c216e56
Title: SMTP - SASL::NTLM authentication fails
Type: Bug Version: 1.20
Submitter: aboeggi Created on: 2021-04-29 12:48:11
Subsystem: sasl Assigned To: nobody
Priority: 5 Medium Severity: Important
Status: Open Last Modified: 2026-11-16 00:06:15
Resolution: None Closed By: nobody
    Closed on:
Description:
In tcllib 1.19 and 1.20 seems to be a bug in tcllib/sasl/ntlm.tcl in every procedure using the DES::des command. If parameter value for "nonce" begins with a "-" it is interpreted as another key for the DES::des command. Please extend every command invocation of DES::des with -- at the end of parameters (after -key $key). See FIXES.


Error message:
==============

bad option "-òʽ””ÿ": must be one of -chunksize, -dir, -hex, -in, -iv, -key, -mode, -out, -weak

    while executing

"DES::des -dir encrypt -weak -mode ecb -key $key $nonce"

    (procedure "LMhash" line 12)

    invoked from within

"LMhash $passwd $nonce"

    (procedure "CreateResponse" line 2)

    invoked from within

"CreateResponse  $ctx(realm) $ctx(hostname)  $user $pass $params(nonce) $params(flags)"

    (procedure "::SASL::NTLM::NTLM" line 20)

    invoked from within

"::SASL::NTLM::NTLM ::SASL::6 NTLMSSP"



FIXES:
======

proc ::SASL::NTLM::LMhash {password nonce} {
    set magic "\x4b\x47\x53\x21\x40\x23\x24\x25"
    set hash ""
    set password [string range [string toupper $password][string repeat \0 14] 0 13]
    foreach key [CreateDesKeys $password] {
        append hash [DES::des -dir encrypt -weak -mode ecb -key $key -- $magic]
    }

    append hash [string repeat \0 5]
    set res ""
    foreach key [CreateDesKeys $hash] {
        append res [DES::des -dir encrypt -weak -mode ecb -key $key -- $nonce]
    }

    return $res
}

proc ::SASL::NTLM::NThash {password nonce} {
    set pass [to_unicode_le $password]
    set hash [md4::md4 $pass]
    append hash [string repeat \x00 5]

    set res ""
    foreach key [CreateDesKeys $hash] {
        append res [DES::des -dir encrypt -weak -mode ecb -key $key -- $nonce]
    }

    return $res
}
User Comments: serhiy.storchaka added on 2026-11-16 00:06:15:

Proposed fix in branch sasl-ntlm-nonce-dash: as the ticket suggests, -- is added to the DES::des calls, so a nonce starting with "-" isn't taken as an option. Test SASL-NTLM-1.2.