root / trunk / web / dojo / dojox / xmpp / sasl.js
History | View | Annotate | Download (4.18 KB)
1 |
/*
|
---|---|
2 |
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
3 |
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
4 |
see: http://dojotoolkit.org/license for details
|
5 |
*/
|
6 |
|
7 |
|
8 |
if(!dojo._hasResource["dojox.xmpp.sasl"]){ |
9 |
dojo._hasResource["dojox.xmpp.sasl"]=true; |
10 |
dojo.provide("dojox.xmpp.sasl");
|
11 |
dojo.require("dojox.xmpp.util");
|
12 |
dojo.require("dojo.AdapterRegistry");
|
13 |
dojo.require("dojox.encoding.digests.MD5");
|
14 |
dojox.xmpp.sasl.saslNS="urn:ietf:params:xml:ns:xmpp-sasl";
|
15 |
dojo.declare("dojox.xmpp.sasl._Base",null,{mechanism:null,closeAuthTag:true,constructor:function(_1){ |
16 |
this.session=_1;
|
17 |
this.startAuth();
|
18 |
},startAuth:function(){ |
19 |
var _2=new dojox.string.Builder(dojox.xmpp.util.createElement("auth",{xmlns:dojox.xmpp.sasl.saslNS,mechanism:this.mechanism},this.closeAuthTag)); |
20 |
this.appendToAuth(_2);
|
21 |
this.session.dispatchPacket(_2.toString());
|
22 |
},appendToAuth:function(_3){ |
23 |
},onChallenge:function(_4){ |
24 |
if(!this.first_challenge){ |
25 |
this.first_challenge=true; |
26 |
this.onFirstChallenge(_4);
|
27 |
}else{
|
28 |
this.onSecondChallenge(_4);
|
29 |
} |
30 |
},onFirstChallenge:function(){ |
31 |
},onSecondChallenge:function(){ |
32 |
},onSuccess:function(){ |
33 |
this.session.sendRestart();
|
34 |
}}); |
35 |
dojo.declare("dojox.xmpp.sasl.SunWebClientAuth",dojox.xmpp.sasl._Base,{mechanism:"SUN-COMMS-CLIENT-PROXY-AUTH"}); |
36 |
dojo.declare("dojox.xmpp.sasl.Plain",dojox.xmpp.sasl._Base,{mechanism:"PLAIN",closeAuthTag:false,appendToAuth:function(_5){ |
37 |
var id=this.session.jid; |
38 |
var _6=this.session.jid.indexOf("@"); |
39 |
if(_6!=-1){ |
40 |
id=this.session.jid.substring(0,_6); |
41 |
} |
42 |
var _7=this.session.jid+"\x00"+id+"\x00"+this.session.password; |
43 |
_7=dojox.xmpp.util.Base64.encode(_7); |
44 |
_5.append(_7); |
45 |
_5.append("</auth>");
|
46 |
delete this.session.password; |
47 |
}}); |
48 |
dojo.declare("dojox.xmpp.sasl.DigestMD5",dojox.xmpp.sasl._Base,{mechanism:"DIGEST-MD5",onFirstChallenge:function(_8){ |
49 |
var _9=dojox.encoding.digests;
|
50 |
var _a=dojox.encoding.digests.outputTypes;
|
51 |
var _b=function(n){ |
52 |
return _9.MD5(n,_a.Hex);
|
53 |
}; |
54 |
var H=function(s){ |
55 |
return _9.MD5(s,_a.String);
|
56 |
}; |
57 |
var _c=dojox.xmpp.util.Base64.decode(_8.firstChild.nodeValue);
|
58 |
var ch={realm:"",nonce:"",qop:"auth",maxbuf:65536}; |
59 |
_c.replace(/([a-z]+)=([^,]+)/g,function(t,k,v){ |
60 |
v=v.replace(/^"(.+)"$/,"$1"); |
61 |
ch[k]=v; |
62 |
}); |
63 |
var _d=""; |
64 |
switch(ch.qop){
|
65 |
case "auth-int": |
66 |
case "auth-conf": |
67 |
_d=":00000000000000000000000000000000";
|
68 |
case "auth": |
69 |
break;
|
70 |
default:
|
71 |
return false; |
72 |
} |
73 |
var _e=_9.MD5(Math.random()*1234567890,_a.Hex); |
74 |
var _f="xmpp/"+this.session.domain; |
75 |
var _10=this.session.jid; |
76 |
var _11=this.session.jid.indexOf("@"); |
77 |
if(_11!=-1){ |
78 |
_10=this.session.jid.substring(0,_11); |
79 |
} |
80 |
_10=dojox.xmpp.util.encodeJid(_10); |
81 |
var A1=new dojox.string.Builder(); |
82 |
A1.append(H(_10+":"+ch.realm+":"+this.session.password),":",ch.nonce+":"+_e); |
83 |
delete this.session.password; |
84 |
var _12=":"+_f+_d; |
85 |
var A2="AUTHENTICATE"+_12; |
86 |
var _13=new dojox.string.Builder(); |
87 |
_13.append(_b(A1.toString()),":",ch.nonce,":00000001:",_e,":",ch.qop,":"); |
88 |
var ret=new dojox.string.Builder(); |
89 |
ret.append("username=\"",_10,"\",","realm=\"",ch.realm,"\",","nonce=",ch.nonce,",","cnonce=\"",_e,"\",","nc=\"00000001\",qop=\"",ch.qop,"\",digest-uri=\"",_f,"\",","response=\"",_b(_13.toString()+_b(A2)),"\",charset=\"utf-8\""); |
90 |
var _14=new dojox.string.Builder(dojox.xmpp.util.createElement("response",{xmlns:dojox.xmpp.xmpp.SASL_NS},false)); |
91 |
_14.append(dojox.xmpp.util.Base64.encode(ret.toString())); |
92 |
_14.append("</response>");
|
93 |
this.rspauth=_b(_13.toString()+_b(_12));
|
94 |
this.session.dispatchPacket(_14.toString());
|
95 |
},onSecondChallenge:function(msg){ |
96 |
var _15=dojox.xmpp.util.Base64.decode(msg.firstChild.nodeValue);
|
97 |
if(this.rspauth==_15.substring(8)){ |
98 |
var _16=new dojox.string.Builder(dojox.xmpp.util.createElement("response",{xmlns:dojox.xmpp.xmpp.SASL_NS},true)); |
99 |
this.session.dispatchPacket(_16.toString());
|
100 |
}else{
|
101 |
} |
102 |
}}); |
103 |
dojox.xmpp.sasl.registry=new dojo.AdapterRegistry();
|
104 |
dojox.xmpp.sasl.registry.register("SUN-COMMS-CLIENT-PROXY-AUTH",function(_17){ |
105 |
return _17=="SUN-COMMS-CLIENT-PROXY-AUTH"; |
106 |
},function(_18,_19){
|
107 |
return new dojox.xmpp.sasl.SunWebClientAuth(_19); |
108 |
}); |
109 |
dojox.xmpp.sasl.registry.register("DIGEST-MD5",function(_1a){ |
110 |
return _1a=="DIGEST-MD5"; |
111 |
},function(_1b,_1c){
|
112 |
return new dojox.xmpp.sasl.DigestMD5(_1c); |
113 |
}); |
114 |
dojox.xmpp.sasl.registry.register("PLAIN",function(_1d){ |
115 |
return _1d=="PLAIN"; |
116 |
},function(_1e,_1f){
|
117 |
return new dojox.xmpp.sasl.Plain(_1f); |
118 |
}); |
119 |
} |