/*
	Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
	Available via Academic Free License >= 2.1 OR the modified BSD license.
	see: http://dojotoolkit.org/license for details
*/


window[esri._dojoScopeName||"dojo"]._xdResourceLoaded(function(_1,_2,_3){return {depends:[["provide","dojox.xmpp.sasl"],["require","dojox.xmpp.util"],["require","dojo.AdapterRegistry"],["require","dojox.encoding.digests.MD5"]],defineResource:function(_4,_5,_6){if(!_4._hasResource["dojox.xmpp.sasl"]){_4._hasResource["dojox.xmpp.sasl"]=true;_4.provide("dojox.xmpp.sasl");_4.require("dojox.xmpp.util");_4.require("dojo.AdapterRegistry");_4.require("dojox.encoding.digests.MD5");_6.xmpp.sasl.saslNS="urn:ietf:params:xml:ns:xmpp-sasl";_4.declare("dojox.xmpp.sasl._Base",null,{mechanism:null,closeAuthTag:true,constructor:function(_7){this.session=_7;this.startAuth();},startAuth:function(){var _8=new _6.string.Builder(_6.xmpp.util.createElement("auth",{xmlns:_6.xmpp.sasl.saslNS,mechanism:this.mechanism},this.closeAuthTag));this.appendToAuth(_8);this.session.dispatchPacket(_8.toString());},appendToAuth:function(_9){},onChallenge:function(_a){if(!this.first_challenge){this.first_challenge=true;this.onFirstChallenge(_a);}else{this.onSecondChallenge(_a);}},onFirstChallenge:function(){},onSecondChallenge:function(){},onSuccess:function(){this.session.sendRestart();}});_4.declare("dojox.xmpp.sasl.SunWebClientAuth",_6.xmpp.sasl._Base,{mechanism:"SUN-COMMS-CLIENT-PROXY-AUTH"});_4.declare("dojox.xmpp.sasl.Plain",_6.xmpp.sasl._Base,{mechanism:"PLAIN",closeAuthTag:false,appendToAuth:function(_b){var id=this.session.jid;var _c=this.session.jid.indexOf("@");if(_c!=-1){id=this.session.jid.substring(0,_c);}var _d=this.session.jid+"\x00"+id+"\x00"+this.session.password;_d=_6.xmpp.util.Base64.encode(_d);_b.append(_d);_b.append("</auth>");delete this.session.password;}});_4.declare("dojox.xmpp.sasl.DigestMD5",_6.xmpp.sasl._Base,{mechanism:"DIGEST-MD5",onFirstChallenge:function(_e){var _f=_6.encoding.digests;var _10=_6.encoding.digests.outputTypes;var HEX=function(n){return _f.MD5(n,_10.Hex);};var H=function(s){return _f.MD5(s,_10.String);};var _11=_6.xmpp.util.Base64.decode(_e.firstChild.nodeValue);var ch={realm:"",nonce:"",qop:"auth",maxbuf:65536};_11.replace(/([a-z]+)=([^,]+)/g,function(t,k,v){v=v.replace(/^"(.+)"$/,"$1");ch[k]=v;});var _12="";switch(ch.qop){case "auth-int":case "auth-conf":_12=":00000000000000000000000000000000";case "auth":break;default:return false;}var _13=_f.MD5(Math.random()*1234567890,_10.Hex);var _14="xmpp/"+this.session.domain;var _15=this.session.jid;var _16=this.session.jid.indexOf("@");if(_16!=-1){_15=this.session.jid.substring(0,_16);}_15=_6.xmpp.util.encodeJid(_15);var A1=new _6.string.Builder();A1.append(H(_15+":"+ch.realm+":"+this.session.password),":",ch.nonce+":"+_13);delete this.session.password;var _17=":"+_14+_12;var A2="AUTHENTICATE"+_17;var _18=new _6.string.Builder();_18.append(HEX(A1.toString()),":",ch.nonce,":00000001:",_13,":",ch.qop,":");var ret=new _6.string.Builder();ret.append("username=\"",_15,"\",","realm=\"",ch.realm,"\",","nonce=",ch.nonce,",","cnonce=\"",_13,"\",","nc=\"00000001\",qop=\"",ch.qop,"\",digest-uri=\"",_14,"\",","response=\"",HEX(_18.toString()+HEX(A2)),"\",charset=\"utf-8\"");var _19=new _6.string.Builder(_6.xmpp.util.createElement("response",{xmlns:_6.xmpp.xmpp.SASL_NS},false));_19.append(_6.xmpp.util.Base64.encode(ret.toString()));_19.append("</response>");this.rspauth=HEX(_18.toString()+HEX(_17));this.session.dispatchPacket(_19.toString());},onSecondChallenge:function(msg){var _1a=_6.xmpp.util.Base64.decode(msg.firstChild.nodeValue);if(this.rspauth==_1a.substring(8)){var _1b=new _6.string.Builder(_6.xmpp.util.createElement("response",{xmlns:_6.xmpp.xmpp.SASL_NS},true));this.session.dispatchPacket(_1b.toString());}else{}}});_6.xmpp.sasl.registry=new _4.AdapterRegistry();_6.xmpp.sasl.registry.register("SUN-COMMS-CLIENT-PROXY-AUTH",function(_1c){return _1c=="SUN-COMMS-CLIENT-PROXY-AUTH";},function(_1d,_1e){return new _6.xmpp.sasl.SunWebClientAuth(_1e);});_6.xmpp.sasl.registry.register("DIGEST-MD5",function(_1f){return _1f=="DIGEST-MD5";},function(_20,_21){return new _6.xmpp.sasl.DigestMD5(_21);});_6.xmpp.sasl.registry.register("PLAIN",function(_22){return _22=="PLAIN";},function(_23,_24){return new _6.xmpp.sasl.Plain(_24);});}}};});