Skip to content

Commit 2d3bde9

Browse files
committed
Use SASL2 from client
1 parent 36f543f commit 2d3bde9

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

packages/client/browser.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,20 @@ const _iqCallee = require("@xmpp/iq/callee");
1212
const _resolve = require("@xmpp/resolve");
1313

1414
// Stream features - order matters and define priority
15+
const _sasl2 = require("@xmpp/sasl2");
1516
const _sasl = require("@xmpp/sasl");
1617
const _resourceBinding = require("@xmpp/resource-binding");
1718
const _sessionEstablishment = require("@xmpp/session-establishment");
1819
const _streamManagement = require("@xmpp/stream-management");
1920

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

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

2730
const { domain, service } = params;
2831
if (!domain && service) {
@@ -40,6 +43,11 @@ function client(options = {}) {
4043
const iqCallee = _iqCallee({ middleware, entity });
4144
const resolve = _resolve({ entity });
4245
// Stream features - order matters and define priority
46+
const sasl2 = _sasl2(
47+
{ streamFeatures },
48+
credentials || { username, password },
49+
{ clientId, software, device },
50+
);
4351
const sasl = _sasl({ streamFeatures }, credentials || { username, password });
4452
const streamManagement = _streamManagement({
4553
streamFeatures,
@@ -55,9 +63,11 @@ function client(options = {}) {
5563
streamFeatures,
5664
});
5765
// SASL mechanisms - order matters and define priority
58-
const mechanisms = Object.entries({ plain, anonymous }).map(([k, v]) => ({
59-
[k]: v(sasl),
60-
}));
66+
const mechanisms = Object.entries({
67+
htsha256,
68+
plain,
69+
anonymous,
70+
}).map(([k, v]) => ({ [k]: [v(sasl2), v(sasl)] }));
6171

6272
return Object.assign(entity, {
6373
entity,
@@ -68,6 +78,7 @@ function client(options = {}) {
6878
iqCaller,
6979
iqCallee,
7080
resolve,
81+
sasl2,
7182
sasl,
7283
resourceBinding,
7384
sessionEstablishment,

packages/client/index.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,21 @@ const _resolve = require("@xmpp/resolve");
1515

1616
// Stream features - order matters and define priority
1717
const _starttls = require("@xmpp/starttls/client");
18+
const _sasl2 = require("@xmpp/sasl2");
1819
const _sasl = require("@xmpp/sasl");
1920
const _resourceBinding = require("@xmpp/resource-binding");
2021
const _sessionEstablishment = require("@xmpp/session-establishment");
2122
const _streamManagement = require("@xmpp/stream-management");
2223

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

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

3134
const { domain, service } = params;
3235
if (!domain && service) {
@@ -47,6 +50,11 @@ function client(options = {}) {
4750
const resolve = _resolve({ entity });
4851
// Stream features - order matters and define priority
4952
const starttls = _starttls({ streamFeatures });
53+
const sasl2 = _sasl2(
54+
{ streamFeatures },
55+
credentials || { username, password },
56+
{ clientId, software, device },
57+
);
5058
const sasl = _sasl({ streamFeatures }, credentials || { username, password });
5159
const streamManagement = _streamManagement({
5260
streamFeatures,
@@ -64,9 +72,10 @@ function client(options = {}) {
6472
// SASL mechanisms - order matters and define priority
6573
const mechanisms = Object.entries({
6674
scramsha1,
75+
htsha256,
6776
plain,
6877
anonymous,
69-
}).map(([k, v]) => ({ [k]: v(sasl) }));
78+
}).map(([k, v]) => ({ [k]: [v(sasl2), v(sasl)] }));
7079

7180
return Object.assign(entity, {
7281
entity,
@@ -80,6 +89,7 @@ function client(options = {}) {
8089
iqCallee,
8190
resolve,
8291
starttls,
92+
sasl2,
8393
sasl,
8494
resourceBinding,
8595
sessionEstablishment,

packages/client/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
"@xmpp/reconnect": "^0.13.0",
1717
"@xmpp/resolve": "^0.13.1",
1818
"@xmpp/resource-binding": "^0.13.0",
19+
"@xmpp/sasl2": "^0.13.0",
1920
"@xmpp/sasl": "^0.13.0",
2021
"@xmpp/sasl-anonymous": "^0.13.0",
2122
"@xmpp/sasl-plain": "^0.13.0",
2223
"@xmpp/sasl-scram-sha-1": "^0.13.0",
24+
"@xmpp/sasl-ht-sha-256-none": "^0.13.0",
2325
"@xmpp/session-establishment": "^0.13.0",
2426
"@xmpp/starttls": "^0.13.1",
2527
"@xmpp/stream-features": "^0.13.0",

0 commit comments

Comments
 (0)