[Pkg-javascript-commits] [ltx] 148/469: added support for facebook chat via X-FACEBOOK-PLATFORM authentication

Jonas Smedegaard dr at jones.dk
Wed Aug 31 13:01:17 UTC 2016


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository ltx.

commit 7b3bfb4fc84e7a19f9387c328e738e1df26e41e6
Author: Michael Geers <michael.geers at neuland-bfi.de>
Date:   Mon Oct 11 16:45:44 2010 +0200

    added support for facebook chat via X-FACEBOOK-PLATFORM authentication
---
 lib/xmpp/client.js |  6 ++++++
 lib/xmpp/sasl.js   | 44 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/lib/xmpp/client.js b/lib/xmpp/client.js
index 437fc5b..8f34bf4 100644
--- a/lib/xmpp/client.js
+++ b/lib/xmpp/client.js
@@ -35,6 +35,9 @@ function Client(params) {
     else
         this.jid = params.jid;
     this.password = params.password;
+	this.api_key = params.api_key;
+	this.secret_key = params.secret_key;
+	this.session_key = params.session_key;
     this.xmlns[''] = NS_CLIENT;
     this.xmppVersion = "1.0";
     this.streamTo = this.jid.domain;
@@ -146,6 +149,9 @@ Client.prototype.useFeatures = function() {
             this.mech.authzid = this.jid.bare().toString();
             this.mech.authcid = this.jid.user;
             this.mech.password = this.password;
+			this.mech.api_key = this.api_key;
+			this.mech.secret_key = this.secret_key;
+			this.mech.session_key = this.session_key;
             this.mech.realm = this.jid.domain;  // anything?
             this.mech.digest_uri = "xmpp/" + this.jid.domain;
             var authMsg = encode64(this.mech.auth());
diff --git a/lib/xmpp/sasl.js b/lib/xmpp/sasl.js
index cf533e4..afad90a 100644
--- a/lib/xmpp/sasl.js
+++ b/lib/xmpp/sasl.js
@@ -1,7 +1,9 @@
 var crypto = require('crypto');
 
 function selectMechanism(mechs) {
-    if (mechs.indexOf("DIGEST-MD5") >= 0)
+    if (mechs.indexOf("X-FACEBOOK-PLATFORM") >= 0)
+        return new XFacebookPlatform();
+    else if (mechs.indexOf("DIGEST-MD5") >= 0)
         return new DigestMD5();
     else if (mechs.indexOf("PLAIN") >= 0)
         return new Plain();
@@ -21,6 +23,46 @@ function Plain() {
     };
 }
 
+function XFacebookPlatform() {
+    this.name = "X-FACEBOOK-PLATFORM";
+    this.auth = function() {
+        return this.secret_key + "\0" +
+            this.api_key + "\0" +
+            this.session_key;
+    };
+
+    this.nonce_count = 0;
+    this.getNC = function() {
+        return rjust(this.nonce_count.toString(), 8, '0');
+    };
+
+    this.cnonce = generateNonce();
+
+    this.challenge = function(s) {
+		dict = require('querystring').parse(s);
+
+        this.nonce_count++;
+
+        var response = {
+			api_key: this.api_key,
+			call_id: new Date().getTime(),
+			method: dict.method,
+            nonce: dict.nonce,
+			session_key: this.session_key,
+			v: "1.0"
+        };
+
+		var message = '';
+		['api_key','call_id','method','nonce','session_key','v'].forEach(function(v) {
+			message += v + "=" + response[v];
+		});
+
+		response.sig = md5(message + this.secret_key, 'hex');
+		
+        return require('querystring').stringify(response);
+    };	
+}
+
 function Anonymous() {
     this.name = "ANONYMOUS";
     this.auth = function() {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/ltx.git



More information about the Pkg-javascript-commits mailing list