annotate plugins/ANONYMOUS.js @ 98:6ec16b3e9cfc

improvements on the websocket transport
author Sonny Piers <sonny.piers@gmail.com>
date Tue, 12 Jun 2012 19:42:49 +0200
parents e1ccfb580228
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
65
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
1 'use strict';
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
2
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
3 /**
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
4 Copyright (c) 2012, Sonny Piers <sonny at fastmail dot net>
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
5
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
6 Permission to use, copy, modify, and/or distribute this software for any
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
7 purpose with or without fee is hereby granted, provided that the above
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
8 copyright notice and this permission notice appear in all copies.
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
9
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
17 */
2e8fbf3bce7f ANONYMOUS auth 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 Anonymous 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/rfc4505
fa184759fc41 Adds references to ANONYMOUS/DIGEST-MD5/PLAIN plugins.
Sonny Piers <sonny.piers@gmail.com>
parents: 65
diff changeset
27 Best Practices for Use of SASL ANONYMOUS
fa184759fc41 Adds references to ANONYMOUS/DIGEST-MD5/PLAIN plugins.
Sonny Piers <sonny.piers@gmail.com>
parents: 65
diff changeset
28 http://xmpp.org/extensions/xep-0175.html
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
65
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
31 Lightstring.plugins['ANONYMOUS'] = {
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
32 handlers: {
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
33 'mechanisms': function (stanza) {
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
34 if(stanza.mechanisms.indexOf('ANONYMOUS') === -1)
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
35 return;
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
36
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
37 this.send(
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
38 "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl'" +
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
39 " mechanism='ANONYMOUS'/>"
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
40 );
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
41 },
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
42 'success': function (stanza) {
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
43 this.send(
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
44 "<stream:stream to='" + this.jid.domain + "'" +
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
45 " xmlns='jabber:client'" +
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
46 " xmlns:stream='http://etherx.jabber.org/streams'" +
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
47 " version='1.0'/>"
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
48 );
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
49 },
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
50 'features': function (stanza) {
68
e1ccfb580228 Replaces that by Conn.
Sonny Piers <sonny.piers@gmail.com>
parents: 66
diff changeset
51 var Conn = this;
65
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
52 //TODO check if bind supported
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
53 var bind =
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
54 "<iq type='set' id='"+Lightstring.newId('sendiq:')+"'>" +
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
55 "<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>" +
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
56 "</iq>";
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
57
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
58 this.send(
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
59 bind,
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
60 //Success
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
61 function(stanza) {
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
62 //Session http://xmpp.org/rfcs/rfc3921.html#session
68
e1ccfb580228 Replaces that by Conn.
Sonny Piers <sonny.piers@gmail.com>
parents: 66
diff changeset
63 Conn.jid = new Lightstring.JID(stanza.DOM.textContent);
65
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
64
68
e1ccfb580228 Replaces that by Conn.
Sonny Piers <sonny.piers@gmail.com>
parents: 66
diff changeset
65 Conn.send(
65
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
66 "<iq type='set' id='"+Lightstring.newId('sendiq:')+"'>" +
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
67 "<session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>" +
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
68 "</iq>",
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
69 function() {
68
e1ccfb580228 Replaces that by Conn.
Sonny Piers <sonny.piers@gmail.com>
parents: 66
diff changeset
70 Conn.emit('connected');
65
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
71 }
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
72 );
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
73 },
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
74 //Error
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
75 function(stanza) {
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
76 //TODO: Error?
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
77 }
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
78 );
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
79 }
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
80 }
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
81 };