Mercurial > eldonilo > lightstring
annotate plugins/DIGEST-MD5.js @ 64:d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
author | Sonny Piers <sonny.piers@gmail.com> |
---|---|
date | Wed, 01 Feb 2012 19:47:49 +0100 |
parents | |
children | 2e8fbf3bce7f |
rev | line source |
---|---|
64
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
1 'use strict'; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
2 |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
3 /** |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
4 Copyright (c) 2012, Sonny Piers <sonny at fastmail dot net> |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
5 |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
6 Permission to use, copy, modify, and/or distribute this software for any |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
7 purpose with or without fee is hereby granted, provided that the above |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
8 copyright notice and this permission notice appear in all copies. |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
9 |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
17 */ |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
18 |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
19 Lightstring.plugins['DIGEST-MD5'] = { |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
20 handlers: { |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
21 'mechanisms': function (stanza) { |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
22 if(stanza.mechanisms.indexOf('DIGEST-MD5') === -1) |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
23 return; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
24 |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
25 this.send( |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
26 "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl'" + |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
27 " mechanism='DIGEST-MD5'/>" |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
28 ); |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
29 }, |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
30 'success': function (stanza) { |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
31 this.send( |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
32 "<stream:stream to='" + this.jid.domain + "'" + |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
33 " xmlns='jabber:client'" + |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
34 " xmlns:stream='http://etherx.jabber.org/streams'" + |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
35 " version='1.0'/>" |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
36 ); |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
37 }, |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
38 'features': function (stanza) { |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
39 var that = this; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
40 //TODO check if bind supported |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
41 var bind = |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
42 "<iq type='set' id='"+Lightstring.newId('sendiq:')+"' xmlns='jabber:client'>" + |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
43 "<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'>" + |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
44 (this.jid.resource? "<resource>" + this.jid.resource + "</resource>": "") + |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
45 "</bind>" + |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
46 "</iq>"; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
47 this.send( |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
48 bind, |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
49 //Success |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
50 function(stanza) { |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
51 //Session http://xmpp.org/rfcs/rfc3921.html#session |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
52 that.jid = new Lightstring.JID(stanza.DOM.textContent); |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
53 that.send( |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
54 "<iq type='set' id='"+Lightstring.newId('sendiq:')+"' xmlns='jabber:client'>" + |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
55 "<session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>" + |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
56 "</iq>", |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
57 function() { |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
58 that.emit('connected'); |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
59 } |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
60 ); |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
61 }, |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
62 //Error |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
63 function(stanza) { |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
64 //TODO: Error? |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
65 } |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
66 ); |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
67 }, |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
68 'challenge': function (stanza) { |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
69 //FIXME this is mostly Strophe code |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
70 |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
71 function _quote(str) { |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
72 return '"' + str.replace(/\\/g, '\\\\').replace(/"/g, '\\"') + '"'; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
73 }; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
74 |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
75 var challenge = atob(stanza.DOM.textContent); |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
76 |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
77 var attribMatch = /([a-z]+)=("[^"]+"|[^,"]+)(?:,|$)/; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
78 |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
79 var cnonce = MD5.hexdigest(Math.random() * 1234567890); |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
80 var realm = ''; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
81 var host = null; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
82 var nonce = ''; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
83 var qop = ''; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
84 var matches; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
85 |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
86 while (challenge.match(attribMatch)) { |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
87 matches = challenge.match(attribMatch); |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
88 challenge = challenge.replace(matches[0], ''); |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
89 matches[2] = matches[2].replace(/^"(.+)"$/, '$1'); |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
90 switch (matches[1]) { |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
91 case 'realm': |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
92 realm = matches[2]; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
93 break; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
94 case 'nonce': |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
95 nonce = matches[2]; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
96 break; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
97 case 'qop': |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
98 qop = matches[2]; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
99 break; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
100 case 'host': |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
101 host = matches[2]; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
102 break; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
103 } |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
104 } |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
105 |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
106 var digest_uri = 'xmpp/' + this.jid.domain; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
107 if (host !== null) |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
108 digest_uri = digest_uri + '/' + host; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
109 var A1 = MD5.hash(this.jid.node + |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
110 ':' + realm + ':' + this.password) + |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
111 ':' + nonce + ':' + cnonce; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
112 var A2 = 'AUTHENTICATE:' + digest_uri; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
113 |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
114 var responseText = ''; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
115 responseText += 'username=' + _quote(this.jid.node) + ','; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
116 responseText += 'realm=' + _quote(realm) + ','; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
117 responseText += 'nonce=' + _quote(nonce) + ','; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
118 responseText += 'cnonce=' + _quote(cnonce) + ','; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
119 responseText += 'nc="00000001",'; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
120 responseText += 'qop="auth",'; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
121 responseText += 'digest-uri=' + _quote(digest_uri) + ','; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
122 responseText += 'response=' + _quote( |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
123 MD5.hexdigest(MD5.hexdigest(A1) + ':' + |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
124 nonce + ':00000001:' + |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
125 cnonce + ':auth:' + |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
126 MD5.hexdigest(A2))) + ','; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
127 responseText += 'charset="utf-8"'; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
128 this.send( |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
129 "<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>" + |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
130 btoa(responseText) + |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
131 "</response>"); |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
132 }, |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
133 'failure': function (stanza) { |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
134 //TODO: throw an error? |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
135 } |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
136 } |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
137 }; |