Mercurial > prosody-hg
comparison util/sasl.lua @ 595:08ed4fa2f89d
Latin1 support for SASL DIGEST-MD5 (initial commit)
| author | Waqas Hussain <waqas20@gmail.com> |
|---|---|
| date | Sun, 07 Dec 2008 23:43:08 +0500 |
| parents | 631e7d16d22b |
| children | 30655c5cc531 |
comparison
equal
deleted
inserted
replaced
| 592:c6e2c727d0cc | 595:08ed4fa2f89d |
|---|---|
| 79 if message["rspauth"] then data = data..[[rspauth=]]..message.rspauth.."," end | 79 if message["rspauth"] then data = data..[[rspauth=]]..message.rspauth.."," end |
| 80 data = data:gsub(",$", "") | 80 data = data:gsub(",$", "") |
| 81 return data | 81 return data |
| 82 end | 82 end |
| 83 | 83 |
| 84 local function utf8tolatin1ifpossible(passwd) | |
| 85 local i = 1; | |
| 86 while i <= #passwd do | |
| 87 local passwd_i = to_byte(passwd:sub(i, i)); | |
| 88 if passwd_i > 0x7F then | |
| 89 if passwd_i < 0xC0 or passwd_i > 0xC3 then | |
| 90 return passwd; | |
| 91 end | |
| 92 i = i + 1; | |
| 93 passwd_i = to_byte(passwd:sub(i, i)); | |
| 94 if passwd_i < 0x80 or passwd_i > 0xBF then | |
| 95 return passwd; | |
| 96 end | |
| 97 end | |
| 98 i = i + 1; | |
| 99 end | |
| 100 | |
| 101 local p = {}; | |
| 102 local j = 0; | |
| 103 i = 1; | |
| 104 while (i <= #passwd) do | |
| 105 local passwd_i = to_byte(passwd:sub(i, i)); | |
| 106 if passwd_i > 0x7F then | |
| 107 i = i + 1; | |
| 108 local passwd_i_1 = to_byte(passwd:sub(i, i)); | |
| 109 t_insert(p, to_char(passwd_i%4*64 + passwd_i_1%64)); -- I'm so clever | |
| 110 else | |
| 111 t_insert(p, to_char(passwd_i)); | |
| 112 end | |
| 113 i = i + 1; | |
| 114 end | |
| 115 return t_concat(p); | |
| 116 end | |
| 84 local function latin1toutf8(str) | 117 local function latin1toutf8(str) |
| 85 local p = {}; | 118 local p = {}; |
| 86 for ch in gmatch(str, ".") do | 119 for ch in gmatch(str, ".") do |
| 87 ch = to_byte(ch); | 120 ch = to_byte(ch); |
| 88 if (ch < 0x80) then | 121 if (ch < 0x80) then |
| 146 if response["realm"] == nil then response["realm"] = "" end | 179 if response["realm"] == nil then response["realm"] = "" end |
| 147 local raw_realm = response["realm"]; | 180 local raw_realm = response["realm"]; |
| 148 | 181 |
| 149 if response["charset"] == nil then | 182 if response["charset"] == nil then |
| 150 response["username"] = latin1toutf8(response["username"]) | 183 response["username"] = latin1toutf8(response["username"]) |
| 151 response["realm"] = latin1toutf8(response["realm"]) | 184 response["realm"] = utf8tolatin1ifpossible(response["realm"]) |
| 152 elseif response["charset"] ~= "utf-8" then | 185 elseif response["charset"] ~= "utf-8" then |
| 153 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." | 186 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." |
| 154 end | 187 end |
| 155 | 188 |
| 156 local domain = "" | 189 local domain = "" |
