Mercurial > eldonilo > lightstring
annotate plugins/DIGEST-MD5.js @ 88:595be4a8584f
fix the roster plugin
author | Sonny Piers <sonny.piers@gmail.com> |
---|---|
date | Thu, 23 Feb 2012 17:07:22 +0100 |
parents | e4899c122d7b |
children |
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 |
66
fa184759fc41
Adds references to ANONYMOUS/DIGEST-MD5/PLAIN plugins.
Sonny Piers <sonny.piers@gmail.com>
parents:
65
diff
changeset
|
19 /* |
fa184759fc41
Adds references to ANONYMOUS/DIGEST-MD5/PLAIN plugins.
Sonny Piers <sonny.piers@gmail.com>
parents:
65
diff
changeset
|
20 References: |
fa184759fc41
Adds references to ANONYMOUS/DIGEST-MD5/PLAIN plugins.
Sonny Piers <sonny.piers@gmail.com>
parents:
65
diff
changeset
|
21 Extensible Messaging and Presence Protocol (XMPP): Core - SASL Negotiation |
fa184759fc41
Adds references to ANONYMOUS/DIGEST-MD5/PLAIN plugins.
Sonny Piers <sonny.piers@gmail.com>
parents:
65
diff
changeset
|
22 http://xmpp.org/rfcs/rfc6120.html#sasl |
fa184759fc41
Adds references to ANONYMOUS/DIGEST-MD5/PLAIN plugins.
Sonny Piers <sonny.piers@gmail.com>
parents:
65
diff
changeset
|
23 Simple Authentication and Security Layer (SASL) |
fa184759fc41
Adds references to ANONYMOUS/DIGEST-MD5/PLAIN plugins.
Sonny Piers <sonny.piers@gmail.com>
parents:
65
diff
changeset
|
24 http://tools.ietf.org/html/rfc4422 |
fa184759fc41
Adds references to ANONYMOUS/DIGEST-MD5/PLAIN plugins.
Sonny Piers <sonny.piers@gmail.com>
parents:
65
diff
changeset
|
25 HTTP Authentication: Basic and Digest Access Authentication |
fa184759fc41
Adds references to ANONYMOUS/DIGEST-MD5/PLAIN plugins.
Sonny Piers <sonny.piers@gmail.com>
parents:
65
diff
changeset
|
26 http://tools.ietf.org/html/rfc2617 |
fa184759fc41
Adds references to ANONYMOUS/DIGEST-MD5/PLAIN plugins.
Sonny Piers <sonny.piers@gmail.com>
parents:
65
diff
changeset
|
27 Using Digest Authentication as a SASL Mechanism |
fa184759fc41
Adds references to ANONYMOUS/DIGEST-MD5/PLAIN plugins.
Sonny Piers <sonny.piers@gmail.com>
parents:
65
diff
changeset
|
28 http://tools.ietf.org/html/rfc2831 |
fa184759fc41
Adds references to ANONYMOUS/DIGEST-MD5/PLAIN plugins.
Sonny Piers <sonny.piers@gmail.com>
parents:
65
diff
changeset
|
29 */ |
fa184759fc41
Adds references to ANONYMOUS/DIGEST-MD5/PLAIN plugins.
Sonny Piers <sonny.piers@gmail.com>
parents:
65
diff
changeset
|
30 |
64
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
31 Lightstring.plugins['DIGEST-MD5'] = { |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
32 handlers: { |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
33 'mechanisms': function (stanza) { |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
34 if(stanza.mechanisms.indexOf('DIGEST-MD5') === -1) |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
35 return; |
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 this.send( |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
38 "<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
|
39 " mechanism='DIGEST-MD5'/>" |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
40 ); |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
41 }, |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
42 'success': function (stanza) { |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
43 this.send( |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
44 "<stream:stream to='" + this.jid.domain + "'" + |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
45 " xmlns='jabber:client'" + |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
46 " xmlns:stream='http://etherx.jabber.org/streams'" + |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
47 " version='1.0'/>" |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
48 ); |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
49 }, |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
50 'features': function (stanza) { |
68 | 51 var Conn = this; |
64
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
52 //TODO check if bind supported |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
53 var bind = |
65 | 54 "<iq type='set' id='"+Lightstring.newId('sendiq:')+"'>" + |
64
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
55 "<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
|
56 (this.jid.resource? "<resource>" + this.jid.resource + "</resource>": "") + |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
57 "</bind>" + |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
58 "</iq>"; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
59 this.send( |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
60 bind, |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
61 //Success |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
62 function(stanza) { |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
63 //Session http://xmpp.org/rfcs/rfc3921.html#session |
68 | 64 Conn.jid = new Lightstring.JID(stanza.DOM.textContent); |
65 Conn.send( | |
65 | 66 "<iq type='set' id='"+Lightstring.newId('sendiq:')+"'>" + |
64
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
67 "<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
|
68 "</iq>", |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
69 function() { |
68 | 70 Conn.emit('connected'); |
64
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
71 } |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
72 ); |
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 //Error |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
75 function(stanza) { |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
76 //TODO: Error? |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
77 } |
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 }, |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
80 'challenge': function (stanza) { |
73
e4899c122d7b
Fix the comment about Strophe.js code.
Sonny Piers <sonny.piers@gmail.com>
parents:
68
diff
changeset
|
81 //FIXME: this is Strophe.js code |
64
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
82 |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
83 function _quote(str) { |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
84 return '"' + str.replace(/\\/g, '\\\\').replace(/"/g, '\\"') + '"'; |
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 |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
87 var challenge = atob(stanza.DOM.textContent); |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
88 |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
89 var attribMatch = /([a-z]+)=("[^"]+"|[^,"]+)(?:,|$)/; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
90 |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
91 var cnonce = MD5.hexdigest(Math.random() * 1234567890); |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
92 var realm = ''; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
93 var host = null; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
94 var nonce = ''; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
95 var qop = ''; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
96 var matches; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
97 |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
98 while (challenge.match(attribMatch)) { |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
99 matches = challenge.match(attribMatch); |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
100 challenge = challenge.replace(matches[0], ''); |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
101 matches[2] = matches[2].replace(/^"(.+)"$/, '$1'); |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
102 switch (matches[1]) { |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
103 case 'realm': |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
104 realm = matches[2]; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
105 break; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
106 case 'nonce': |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
107 nonce = matches[2]; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
108 break; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
109 case 'qop': |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
110 qop = matches[2]; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
111 break; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
112 case 'host': |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
113 host = matches[2]; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
114 break; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
115 } |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
116 } |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
117 |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
118 var digest_uri = 'xmpp/' + this.jid.domain; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
119 if (host !== null) |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
120 digest_uri = digest_uri + '/' + host; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
121 var A1 = MD5.hash(this.jid.node + |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
122 ':' + realm + ':' + this.password) + |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
123 ':' + nonce + ':' + cnonce; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
124 var A2 = 'AUTHENTICATE:' + digest_uri; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
125 |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
126 var responseText = ''; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
127 responseText += 'username=' + _quote(this.jid.node) + ','; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
128 responseText += 'realm=' + _quote(realm) + ','; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
129 responseText += 'nonce=' + _quote(nonce) + ','; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
130 responseText += 'cnonce=' + _quote(cnonce) + ','; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
131 responseText += 'nc="00000001",'; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
132 responseText += 'qop="auth",'; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
133 responseText += 'digest-uri=' + _quote(digest_uri) + ','; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
134 responseText += 'response=' + _quote( |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
135 MD5.hexdigest(MD5.hexdigest(A1) + ':' + |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
136 nonce + ':00000001:' + |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
137 cnonce + ':auth:' + |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
138 MD5.hexdigest(A2))) + ','; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
139 responseText += 'charset="utf-8"'; |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
140 this.send( |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
141 "<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
|
142 btoa(responseText) + |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
143 "</response>"); |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
144 }, |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
145 'failure': function (stanza) { |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
146 //TODO: throw an error? |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
147 } |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
148 } |
d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
149 }; |