Skip to content

Commit

Permalink
Use SASL2 from client
Browse files Browse the repository at this point in the history
  • Loading branch information
singpolyma committed Nov 22, 2023
1 parent 656d551 commit 2d9d312
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
17 changes: 14 additions & 3 deletions packages/client/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@ const _iqCallee = require("@xmpp/iq/callee");
const _resolve = require("@xmpp/resolve");

// Stream features - order matters and define priority
const _sasl2 = require("@xmpp/sasl2");
const _sasl = require("@xmpp/sasl");
const _resourceBinding = require("@xmpp/resource-binding");
const _sessionEstablishment = require("@xmpp/session-establishment");
const _streamManagement = require("@xmpp/stream-management");

// SASL mechanisms - order matters and define priority
const anonymous = require("@xmpp/sasl-anonymous");
const htsha256 = require("@xmpp/sasl-ht-sha-256-none");
const plain = require("@xmpp/sasl-plain");

function client(options = {}) {
const { resource, credentials, username, password, ...params } = options;
const { clientId, software, device } = params;

const { domain, service } = params;
if (!domain && service) {
Expand All @@ -40,6 +43,11 @@ function client(options = {}) {
const iqCallee = _iqCallee({ middleware, entity });
const resolve = _resolve({ entity });
// Stream features - order matters and define priority
const sasl2 = _sasl2(
{ streamFeatures },
credentials || { username, password },
{ clientId, software, device },
);
const sasl = _sasl({ streamFeatures }, credentials || { username, password });
const streamManagement = _streamManagement({
streamFeatures,
Expand All @@ -55,9 +63,11 @@ function client(options = {}) {
streamFeatures,
});
// SASL mechanisms - order matters and define priority
const mechanisms = Object.entries({ plain, anonymous }).map(([k, v]) => ({
[k]: v(sasl),
}));
const mechanisms = Object.entries({
htsha256,
plain,
anonymous,
}).map(([k, v]) => ({ [k]: [v(sasl2), v(sasl)] }));

return Object.assign(entity, {
entity,
Expand All @@ -68,6 +78,7 @@ function client(options = {}) {
iqCaller,
iqCallee,
resolve,
sasl2,
sasl,
resourceBinding,
sessionEstablishment,
Expand Down
12 changes: 11 additions & 1 deletion packages/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@ const _resolve = require("@xmpp/resolve");

// Stream features - order matters and define priority
const _starttls = require("@xmpp/starttls/client");
const _sasl2 = require("@xmpp/sasl2");
const _sasl = require("@xmpp/sasl");
const _resourceBinding = require("@xmpp/resource-binding");
const _sessionEstablishment = require("@xmpp/session-establishment");
const _streamManagement = require("@xmpp/stream-management");

// SASL mechanisms - order matters and define priority
const scramsha1 = require("@xmpp/sasl-scram-sha-1");
const htsha256 = require("@xmpp/sasl-ht-sha-256-none");
const plain = require("@xmpp/sasl-plain");
const anonymous = require("@xmpp/sasl-anonymous");

function client(options = {}) {
const { resource, credentials, username, password, ...params } = options;
const { clientId, software, device } = params;

const { domain, service } = params;
if (!domain && service) {
Expand All @@ -47,6 +50,11 @@ function client(options = {}) {
const resolve = _resolve({ entity });
// Stream features - order matters and define priority
const starttls = _starttls({ streamFeatures });
const sasl2 = _sasl2(
{ streamFeatures },
credentials || { username, password },
{ clientId, software, device },
);
const sasl = _sasl({ streamFeatures }, credentials || { username, password });
const streamManagement = _streamManagement({
streamFeatures,
Expand All @@ -64,9 +72,10 @@ function client(options = {}) {
// SASL mechanisms - order matters and define priority
const mechanisms = Object.entries({
scramsha1,
htsha256,
plain,
anonymous,
}).map(([k, v]) => ({ [k]: v(sasl) }));
}).map(([k, v]) => ({ [k]: [v(sasl2), v(sasl)] }));

return Object.assign(entity, {
entity,
Expand All @@ -80,6 +89,7 @@ function client(options = {}) {
iqCallee,
resolve,
starttls,
sasl2,
sasl,
resourceBinding,
sessionEstablishment,
Expand Down
2 changes: 2 additions & 0 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
"@xmpp/reconnect": "^0.13.0",
"@xmpp/resolve": "^0.13.1",
"@xmpp/resource-binding": "^0.13.0",
"@xmpp/sasl2": "^0.13.0",
"@xmpp/sasl": "^0.13.0",
"@xmpp/sasl-anonymous": "^0.13.0",
"@xmpp/sasl-plain": "^0.13.0",
"@xmpp/sasl-scram-sha-1": "^0.13.0",
"@xmpp/sasl-ht-sha-256-none": "^0.13.0",
"@xmpp/session-establishment": "^0.13.0",
"@xmpp/starttls": "^0.13.1",
"@xmpp/stream-features": "^0.13.0",
Expand Down

0 comments on commit 2d9d312

Please sign in to comment.