diff options
author | Waqas Hussain <waqas20@gmail.com> | 2008-12-07 23:43:08 +0500 |
---|---|---|
committer | Waqas Hussain <waqas20@gmail.com> | 2008-12-07 23:43:08 +0500 |
commit | 0595c7a86c4ebbdab236b9f3cf2de4be84f0b90d (patch) | |
tree | 636ba7789cbeb170fdd10f902ee79d2708c3466e /util | |
parent | 2395f6511aa68766d74d8292d7360e4d295b7197 (diff) | |
download | prosody-0595c7a86c4ebbdab236b9f3cf2de4be84f0b90d.tar.gz prosody-0595c7a86c4ebbdab236b9f3cf2de4be84f0b90d.zip |
Latin1 support for SASL DIGEST-MD5 (initial commit)
Diffstat (limited to 'util')
-rw-r--r-- | util/sasl.lua | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/util/sasl.lua b/util/sasl.lua index ab8b814b..75f1da96 100644 --- a/util/sasl.lua +++ b/util/sasl.lua @@ -81,6 +81,39 @@ local function new_digest_md5(realm, password_handler) return data end + local function utf8tolatin1ifpossible(passwd) + local i = 1; + while i <= #passwd do + local passwd_i = to_byte(passwd:sub(i, i)); + if passwd_i > 0x7F then + if passwd_i < 0xC0 or passwd_i > 0xC3 then + return passwd; + end + i = i + 1; + passwd_i = to_byte(passwd:sub(i, i)); + if passwd_i < 0x80 or passwd_i > 0xBF then + return passwd; + end + end + i = i + 1; + end + + local p = {}; + local j = 0; + i = 1; + while (i <= #passwd) do + local passwd_i = to_byte(passwd:sub(i, i)); + if passwd_i > 0x7F then + i = i + 1; + local passwd_i_1 = to_byte(passwd:sub(i, i)); + t_insert(p, to_char(passwd_i%4*64 + passwd_i_1%64)); -- I'm so clever + else + t_insert(p, to_char(passwd_i)); + end + i = i + 1; + end + return t_concat(p); + end local function latin1toutf8(str) local p = {}; for ch in gmatch(str, ".") do @@ -148,7 +181,7 @@ local function new_digest_md5(realm, password_handler) if response["charset"] == nil then response["username"] = latin1toutf8(response["username"]) - response["realm"] = latin1toutf8(response["realm"]) + response["realm"] = utf8tolatin1ifpossible(response["realm"]) elseif response["charset"] ~= "utf-8" then return "failure", "incorrect-encoding", "The client's response uses "..response["charset"].." for encoding with isn't supported by sasl.lua. Supported encodings are latin or utf-8." end |