Skip to content

Commit 1cb9581

Browse files
committed
Support SASL2 FAST authentication
FAST is a cookie-style authentication method that lets clients store and auth with an unguesseable token. It enables clients to forget the user's full password, which is especially important for web-based clients, that are prone to data leaks. Leaked tokens can be invalidated. - https://xmpp.org/extensions/xep-0484.html - https://xmpp.org/extensions/xep-0388.html Intended to fix conversejs/converse.js#3144 Some aside changes I needed for this: - I let handlers listen to the *opening* stanza - Set 'from' on the opening <stream> tag. (ref: https://github.com/xmppjs/xmpp.js/pull/1006/files#r1893267922) - Create a type of handler that can search *nested data*. This made setting up listeners a lot more convenient. - During connection, replace has_features with the direct XML <stream:features> more direct and defensive. - Moved Status.AUTHENTICATING before FAST/SASL Still TODO: - support the other HT- methods from the spec - rewrite the SASL code into sasl.js to look like sasl2.js ? - allow fallback from SASL2 to SASL (currently assumes only ONE login method will be tried per connect(), which could block login if one is failing) - pull SASL2 into sasl2.js and make it a plugin - Disentangle the circular dependency between index.js loading sasl2.js/sasl2_fast.js but them needing to talk to Strophe - Invalidate token on logout (and in the corresponding Converse.js branch, actually forget the token on logout)
1 parent 4b1b33b commit 1cb9581

File tree

12 files changed

+808
-167
lines changed

12 files changed

+808
-167
lines changed

src/bosh.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ class Bosh {
146146

147147
const body = this._buildBody().attrs({
148148
'to': this._conn.domain,
149+
...(this._conn.service.startsWith("https://") ? { 'from': this._conn.jid } : {}),
149150
'xml:lang': 'en',
150151
'wait': this.wait,
151152
'hold': this.hold,
@@ -424,7 +425,7 @@ class Bosh {
424425
const req = this._requests.pop();
425426
req.abort = true;
426427
req.xhr.abort();
427-
req.xhr.onreadystatechange = function () {};
428+
req.xhr.onreadystatechange = function () { };
428429
}
429430
}
430431

@@ -451,12 +452,13 @@ class Bosh {
451452
if (data[i] === 'restart') {
452453
body.attrs({
453454
'to': this._conn.domain,
455+
...(this._conn.service.startsWith("https://") ? { 'from': this._conn.jid } : {}),
454456
'xml:lang': 'en',
455457
'xmpp:restart': 'true',
456458
'xmlns:xmpp': NS.BOSH,
457459
});
458460
} else {
459-
body.cnode(/** @type {Element} */ (data[i])).up();
461+
body.cnode(/** @type {Element} */(data[i])).up();
460462
}
461463
}
462464
}
@@ -482,10 +484,10 @@ class Bosh {
482484
if (time_elapsed > Math.floor(timeoutMultiplier * this.wait)) {
483485
log.warn(
484486
'Request ' +
485-
this._requests[0].id +
486-
' timed out, over ' +
487-
Math.floor(timeoutMultiplier * this.wait) +
488-
' seconds since last activity'
487+
this._requests[0].id +
488+
' timed out, over ' +
489+
Math.floor(timeoutMultiplier * this.wait) +
490+
' seconds since last activity'
489491
);
490492
this._throttledRequestHandler();
491493
}
@@ -627,7 +629,7 @@ class Bosh {
627629
req.abort = true;
628630
req.xhr.abort();
629631
// setting to null fails on IE6, so set to empty function
630-
req.xhr.onreadystatechange = function () {};
632+
req.xhr.onreadystatechange = function () { };
631633
this._requests[i] = new Request(req.xmlData, req.origFunc, req.rid, req.sends);
632634
req = this._requests[i];
633635
}
@@ -694,9 +696,9 @@ class Bosh {
694696
} else {
695697
log.debug(
696698
'_processRequest: ' +
697-
(i === 0 ? 'first' : 'second') +
698-
' request has readyState of ' +
699-
req.xhr.readyState
699+
(i === 0 ? 'first' : 'second') +
700+
' request has readyState of ' +
701+
req.xhr.readyState
700702
);
701703
}
702704
}
@@ -714,7 +716,7 @@ class Bosh {
714716
}
715717
}
716718
// IE6 fails on setting to null, so set to empty function
717-
req.xhr.onreadystatechange = function () {};
719+
req.xhr.onreadystatechange = function () { };
718720
this._throttledRequestHandler();
719721
}
720722

0 commit comments

Comments
 (0)