-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial support for XEP-0484 (FAST) (#1042)
--- Co-authored-by: Stephen Paul Weber [email protected]
- Loading branch information
Showing
14 changed files
with
490 additions
and
774 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# fast | ||
|
||
fast for `@xmpp/client`. | ||
|
||
Included and enabled in `@xmpp/client`. | ||
|
||
## Usage | ||
|
||
Resource is optional and will be chosen by the server if omitted. | ||
|
||
### string | ||
|
||
```js | ||
import { xmpp } from "@xmpp/client"; | ||
|
||
const client = xmpp({ resource: "laptop" }); | ||
``` | ||
|
||
### function | ||
|
||
Instead, you can provide a function that will be called every time resource binding occurs (every (re)connect). | ||
|
||
```js | ||
import { xmpp } from "@xmpp/client"; | ||
|
||
const client = xmpp({ resource: onBind }); | ||
|
||
async function onBind(bind) { | ||
const resource = await fetchResource(); | ||
return resource; | ||
} | ||
``` | ||
|
||
## References | ||
|
||
[XEP-0484: Fast Authentication Streamlining Tokens](https://xmpp.org/extensions/xep-0484.html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { getAvailableMechanisms } from "@xmpp/sasl"; | ||
import xml from "@xmpp/xml"; | ||
import SASLFactory from "saslmechanisms"; | ||
|
||
const NS = "urn:xmpp:fast:0"; | ||
|
||
export default function fast({ sasl2 }) { | ||
const saslFactory = new SASLFactory(); | ||
|
||
const fast = { | ||
token: null, | ||
expiry: null, | ||
saslFactory, | ||
mechanisms: [], | ||
mechanism: null, | ||
available() { | ||
return !!(this.token && this.mechanism); | ||
}, | ||
}; | ||
|
||
sasl2.use( | ||
NS, | ||
async (element) => { | ||
if (!element.is("fast", NS)) return; | ||
fast.mechanisms = getAvailableMechanisms(element, NS, saslFactory); | ||
fast.mechanism = fast.mechanisms[0]; | ||
|
||
if (!fast.mechanism) return; | ||
|
||
if (!fast.token) { | ||
return xml("request-token", { | ||
xmlns: NS, | ||
mechanism: fast.mechanism, | ||
}); | ||
} | ||
|
||
return xml("fast", { xmlns: NS }); | ||
}, | ||
async (element) => { | ||
if (element.is("token", NS)) { | ||
const { token, expiry } = element.attrs; | ||
fast.token = token; | ||
fast.expiry = expiry; | ||
} | ||
}, | ||
); | ||
|
||
return fast; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// https://datatracker.ietf.org/doc/draft-schmaus-kitten-sasl-ht/ | ||
import createHmac from "create-hmac"; | ||
|
||
export function Mechanism() {} | ||
|
||
Mechanism.prototype.Mechanism = Mechanism; | ||
Mechanism.prototype.name = "HT-SHA-256-NONE"; | ||
Mechanism.prototype.clientFirst = true; | ||
|
||
Mechanism.prototype.response = function response(cred) { | ||
this.password = cred.password; | ||
const hmac = createHmac("sha256", this.password); | ||
hmac.update("Initiator"); | ||
return cred.username + "\0" + hmac.digest("latin1"); | ||
}; | ||
|
||
Mechanism.prototype.final = function final(data) { | ||
const hmac = createHmac("sha256", this.password); | ||
hmac.update("Responder"); | ||
if (hmac.digest("latin1") !== data) { | ||
throw new Error("Responder message from server was wrong"); | ||
} | ||
}; | ||
|
||
export default function saslHashedToken(sasl) { | ||
sasl.use(Mechanism); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "@xmpp/sasl-ht-sha-256-none", | ||
"description": "XMPP SASL HT-SHA-256-NONE for JavaScript", | ||
"repository": "github:xmppjs/xmpp.js", | ||
"homepage": "https://github.com/xmppjs/xmpp.js/tree/main/packages/sasl-ht-sha-256-none", | ||
"bugs": "http://github.com/xmppjs/xmpp.js/issues", | ||
"version": "0.14.0", | ||
"license": "ISC", | ||
"type": "module", | ||
"main": "index.js", | ||
"keywords": [ | ||
"XMPP", | ||
"sasl" | ||
], | ||
"dependencies": { | ||
"create-hmac": "^1.1.7" | ||
}, | ||
"engines": { | ||
"node": ">= 20" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.