Mercurial > eldonilo > lightstring
annotate plugins/PLAIN.js @ 109:cd1f57661439 default tip
Fix files permissions.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Wed, 01 Aug 2012 23:18:03 +0200 |
parents | 5cb4733c5189 |
children |
rev | line source |
---|---|
63
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
1 'use strict'; |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
2 |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
3 /** |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
4 Copyright (c) 2012, Sonny Piers <sonny at fastmail dot net> |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
5 |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
6 Permission to use, copy, modify, and/or distribute this software for any |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
7 purpose with or without fee is hereby granted, provided that the above |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
8 copyright notice and this permission notice appear in all copies. |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
9 |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
17 */ |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
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 The PLAIN Simple Authentication and Security Layer (SASL) Mechanism |
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/rfc4616 |
fa184759fc41
Adds references to ANONYMOUS/DIGEST-MD5/PLAIN plugins.
Sonny Piers <sonny.piers@gmail.com>
parents:
65
diff
changeset
|
27 */ |
fa184759fc41
Adds references to ANONYMOUS/DIGEST-MD5/PLAIN plugins.
Sonny Piers <sonny.piers@gmail.com>
parents:
65
diff
changeset
|
28 |
63
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
29 Lightstring.plugins['PLAIN'] = { |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
30 handlers: { |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
31 'mechanisms': function (stanza) { |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
32 if(stanza.mechanisms.indexOf('PLAIN') === -1) |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
33 return; |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
34 |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
35 var token = btoa( |
108 | 36 this.jid.bare + |
63
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
37 '\u0000' + |
108 | 38 this.jid.local + |
63
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
39 '\u0000' + |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
40 this.password |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
41 ); |
108 | 42 |
63
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
43 this.send( |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
44 "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl'" + |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
45 " mechanism='PLAIN'>" + token + "</auth>" |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
46 ); |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
47 }, |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
48 'success': function (stanza) { |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
49 this.send( |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
50 "<stream:stream to='" + this.jid.domain + "'" + |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
51 " xmlns='jabber:client'" + |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
52 " xmlns:stream='http://etherx.jabber.org/streams'" + |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
53 " version='1.0'/>" |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
54 ); |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
55 }, |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
56 'features': function (stanza) { |
68 | 57 var Conn = this; |
63
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
58 //TODO check if bind supported |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
59 var bind = |
108 | 60 "<iq type='set' id='" + Lightstring.id() + "'>" + |
63
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
61 "<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'>" + |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
62 (this.jid.resource? "<resource>" + this.jid.resource + "</resource>": "") + |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
63 "</bind>" + |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
64 "</iq>"; |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
65 this.send( |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
66 bind, |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
67 //Success |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
68 function(stanza) { |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
69 //Session http://xmpp.org/rfcs/rfc3921.html#session |
106 | 70 Conn.jid = new Lightstring.JID(stanza.el.textContent); |
68 | 71 Conn.send( |
108 | 72 "<iq type='set' id='" + Lightstring.id() + "'>" + |
63
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
73 "<session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>" + |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
74 "</iq>", |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
75 function() { |
68 | 76 Conn.emit('connected'); |
63
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
77 } |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
78 ); |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
79 }, |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
80 //Error |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
81 function(stanza) { |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
82 //TODO: Error? |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
83 } |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
84 ); |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
85 } |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
86 } |
20da4fb67977
Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff
changeset
|
87 }; |