Comparison

plugins/sasl.lua @ 315:3742107e2505

plugins/sasl: Use ANONYMOUS authentication when no username provided
author James Callahan <james@chatid.com>
date Mon, 10 Sep 2012 23:37:04 +1000
parent 302:0c83cb476246
child 354:58cd27b74ba5
comparison
equal deleted inserted replaced
314:ee5fc3ee9150 315:3742107e2505
3 3
4 function verse.plugins.sasl(stream) 4 function verse.plugins.sasl(stream)
5 local function handle_features(features_stanza) 5 local function handle_features(features_stanza)
6 if stream.authenticated then return; end 6 if stream.authenticated then return; end
7 stream:debug("Authenticating with SASL..."); 7 stream:debug("Authenticating with SASL...");
8 local initial_data = base64("\0"..stream.username.."\0"..stream.password);
9
10 --stream.sasl_state, initial_data = sasl_new({"PLAIN"}, stream.username, stream.password, stream.jid); 8 --stream.sasl_state, initial_data = sasl_new({"PLAIN"}, stream.username, stream.password, stream.jid);
11 9 local mechanism , initial_data
12 stream:debug("Selecting PLAIN mechanism..."); 10 if stream.username then
13 local auth_stanza = verse.stanza("auth", { xmlns = xmlns_sasl, mechanism = "PLAIN" }); 11 mechanism = "PLAIN"
12 initial_data = base64("\0"..stream.username.."\0"..stream.password);
13 else
14 mechanism = "ANONYMOUS"
15 end
16 stream:debug("Selecting %s mechanism...",mechanism);
17 local auth_stanza = verse.stanza("auth", { xmlns = xmlns_sasl, mechanism = mechanism });
14 if initial_data then 18 if initial_data then
15 auth_stanza:text(initial_data); 19 auth_stanza:text(initial_data);
16 end 20 end
17 stream:send(auth_stanza); 21 stream:send(auth_stanza);
18 return true; 22 return true;