Skip to content

Commit 6acae7b

Browse files
authored
Merge pull request #4379 from esl/XEP-0484
XEP-0484 Fast Token Auth
2 parents 83eb36a + a48bb51 commit 6acae7b

34 files changed

+1740
-46
lines changed

big_tests/default.spec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
{suites, "tests", amp_big_SUITE}.
1818
{suites, "tests", anonymous_SUITE}.
1919
{suites, "tests", bind2_SUITE}.
20+
{suites, "tests", fast_auth_token_SUITE}.
2021
{suites, "tests", bosh_SUITE}.
2122
{suites, "tests", carboncopy_SUITE}.
2223
{suites, "tests", connect_SUITE}.

big_tests/dynamic_domains.spec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
{suites, "tests", amp_big_SUITE}.
1717
{suites, "tests", anonymous_SUITE}.
1818
{suites, "tests", bind2_SUITE}.
19+
{suites, "tests", fast_auth_token_SUITE}.
1920
{suites, "tests", bosh_SUITE}.
2021
{suites, "tests", carboncopy_SUITE}.
2122
{suites, "tests", connect_SUITE}.

big_tests/src/time_helper.erl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-module(time_helper).
2+
-export([validate_datetime/1]).
3+
4+
%% @doc Validates that string is in ISO 8601 format
5+
-spec validate_datetime(string()) -> boolean().
6+
validate_datetime(TimeStr) ->
7+
[Date, Time] = string:tokens(TimeStr, "T"),
8+
validate_date(Date) and validate_time(Time).
9+
10+
validate_date(Date) ->
11+
[Y, M, D] = string:tokens(Date, "-"),
12+
Date1 = {list_to_integer(Y), list_to_integer(M), list_to_integer(D)},
13+
calendar:valid_date(Date1).
14+
15+
validate_time(Time) ->
16+
[T | _] = string:tokens(Time, "Z"),
17+
validate_time1(T).
18+
19+
validate_time1(Time) ->
20+
[H, M, S] = string:tokens(Time, ":"),
21+
check_list([{H, 24}, {M, 60}, {S, 60}]).
22+
23+
check_list(List) ->
24+
lists:all(fun({V, L}) -> I = list_to_integer(V), I >= 0 andalso I < L end, List).

big_tests/tests/fast_auth_token_SUITE.erl

Lines changed: 512 additions & 0 deletions
Large diffs are not rendered by default.

big_tests/tests/gdpr_SUITE.erl

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ retrieve_offline(Config) ->
963963
#{ "packet" => [{contains, Body}],
964964
"from" => binary_to_list(From),
965965
"to" => binary_to_list(To),
966-
"timestamp" => [{validate, fun validate_datetime/1}]}
966+
"timestamp" => [{validate, fun time_helper:validate_datetime/1}]}
967967
end, Expected),
968968

969969
retrieve_and_validate_personal_data(
@@ -1777,28 +1777,6 @@ send_and_assert_is_chat_message(UserFrom, UserTo, Body) ->
17771777
Msg = escalus:wait_for_stanza(UserTo),
17781778
escalus:assert(is_chat_message, [Body], Msg).
17791779

1780-
validate_datetime(TimeStr) ->
1781-
[Date, Time] = string:tokens(TimeStr, "T"),
1782-
validate_date(Date),
1783-
validate_time(Time).
1784-
1785-
validate_date(Date) ->
1786-
[Y, M, D] = string:tokens(Date, "-"),
1787-
Date1 = {list_to_integer(Y), list_to_integer(M), list_to_integer(D)},
1788-
calendar:valid_date(Date1).
1789-
1790-
validate_time(Time) ->
1791-
[T | _] = string:tokens(Time, "Z"),
1792-
validate_time1(T).
1793-
1794-
1795-
validate_time1(Time) ->
1796-
[H, M, S] = string:tokens(Time, ":"),
1797-
check_list([{H, 24}, {M, 60}, {S, 60}]).
1798-
1799-
check_list(List) ->
1800-
lists:all(fun({V, L}) -> I = list_to_integer(V), I >= 0 andalso I < L end, List).
1801-
18021780
expected_header(mod_roster) -> ["jid", "name", "subscription",
18031781
"ask", "groups", "askmessage", "xs"].
18041782

big_tests/tests/sasl2_helper.erl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,18 @@ load_all_sasl2_modules(HostType) ->
2121
{mod_sasl2, default_mod_config(mod_sasl2)},
2222
{mod_csi, default_mod_config(mod_csi)},
2323
{mod_carboncopy, default_mod_config(mod_carboncopy)},
24-
{mod_stream_management, mod_config(mod_stream_management, SMOpts)}],
24+
{mod_stream_management, mod_config(mod_stream_management, SMOpts)}]
25+
++ rdbms_mods(),
2526
dynamic_modules:ensure_modules(HostType, Modules).
2627

28+
rdbms_mods() ->
29+
case mongoose_helper:is_rdbms_enabled(domain_helper:host_type()) of
30+
true ->
31+
[{mod_fast_auth_token, mod_config(mod_fast_auth_token, #{backend => rdbms})}];
32+
false ->
33+
[]
34+
end.
35+
2736
apply_steps(Steps, Config) ->
2837
apply_steps(Steps, Config, undefined, #{}).
2938

doc/configuration/Modules.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ This applies to situations such as sending messages or presences to mobile/SMS/e
9999
Implements [XEP-0215: External Service Discovery](http://xmpp.org/extensions/xep-0215.html) for discovering information about services external to the XMPP network.
100100
The main use-case is to help discover STUN/TURN servers to allow for negotiating media exchanges.
101101

102+
### [mod_fast_auth_token](../modules/mod_fast_auth_token.md)
103+
A module that implements [XEP-0484: Fast Authentication Streamlining Tokens](https://xmpp.org/extensions/xep-0484.html)..
104+
102105
### [mod_http_upload](../modules/mod_http_upload.md)
103106
Implements [XEP-0363: HTTP File Upload](https://xmpp.org/extensions/xep-0363.html) for coordinating with an XMPP server to upload files via HTTP and receive URLs that can be shared in messages.
104107

doc/modules/mod_fast_auth_token.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
## Module Description
2+
3+
This module implements [XEP-0484: Fast Authentication Streamlining Tokens](https://xmpp.org/extensions/xep-0484.html).
4+
It provides services necessary to:
5+
6+
* issue auth tokens for authenticated users;
7+
* reconnect to the server using the tokens instead of the original auth method.
8+
9+
Tokens are stored in RDBMS.
10+
11+
It is not related to another similar module `mod_auth_token`.
12+
13+
## Options
14+
15+
### `modules.mod_fast_auth_token.backend`
16+
* **Syntax:** non-empty string
17+
* **Default:** `"rdbms"`
18+
* **Example:** `backend = "rdbms"`
19+
20+
Token storage backend. Currently only `"rdbms"` is supported.
21+
22+
### `modules.mod_fast_auth_token.validity_period`
23+
* **Syntax:** TOML table. Each key is either `access` or `rotate_before_expire`.Each value is a nested TOML table with the following mandatory keys: `value` (non-negative integer) and `unit` (`"days"`, `"hours"`, `"minutes"` or `"seconds"`).
24+
* **Default:** `{access = {value = 3, unit = "days"}, rotate_before_expire = {value = 6, unit = "hours"}}`
25+
* **Example:** `validity_period.access = {value = 30, unit = "minutes"}`
26+
27+
The user can use each token for `access` period of time before it expired.
28+
29+
The server would [send](https://xmpp.org/extensions/xep-0484.html#token-rotation)
30+
a new token at the login time `rotate_before_expire` time before it expires.
31+
Set it to 0 to disable automatic rotation.
32+
33+
## Example configuration
34+
35+
```toml
36+
[modules.mod_fast_auth_token]
37+
validity_period.access = {value = 1, unit = "days"}
38+
validity_period.rotate_before_expire = {value = 0, unit = "days"}
39+
```

include/mongoose_ns.hrl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
-define(NS_SESSION, <<"urn:ietf:params:xml:ns:xmpp-session">>).
8686
-define(NS_BIND, <<"urn:ietf:params:xml:ns:xmpp-bind">>).
8787
-define(NS_BIND_2, <<"urn:xmpp:bind:0">>).
88+
-define(NS_FAST, <<"urn:xmpp:fast:0">>).
8889

8990
-define(NS_FEATURE_IQAUTH, <<"http://jabber.org/features/iq-auth">>).
9091
-define(NS_FEATURE_IQREGISTER, <<"http://jabber.org/features/iq-register">>).

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ nav:
133133
- 'RabbitMQ backend': 'modules/mod_event_pusher_rabbit.md'
134134
- 'SNS backend': 'modules/mod_event_pusher_sns.md'
135135
- 'mod_extdisco': 'modules/mod_extdisco.md'
136+
- 'mod_fast_auth_token': 'modules/mod_fast_auth_token.md'
136137
- 'mod_global_distrib': 'modules/mod_global_distrib.md'
137138
- 'mod_http_upload': 'modules/mod_http_upload.md'
138139
- 'mod_inbox': 'modules/mod_inbox.md'

0 commit comments

Comments
 (0)