Skip to content

Commit

Permalink
Add support for XEP-0484 Fast Authentication Streamlining Tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
prefiks committed Dec 16, 2024
1 parent 3e883c3 commit 66444c7
Show file tree
Hide file tree
Showing 12 changed files with 732 additions and 134 deletions.
146 changes: 81 additions & 65 deletions include/xmpp_codec.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,6 @@
-record(legacy_auth_feature, {}).
-type legacy_auth_feature() :: #legacy_auth_feature{}.

-record(bind, {jid :: undefined | jid:jid(),
resource = <<>> :: binary()}).
-type bind() :: #bind{}.

-record(rosterver_feature, {}).
-type rosterver_feature() :: #rosterver_feature{}.

Expand Down Expand Up @@ -441,6 +437,12 @@
xmlns = <<>> :: binary()}).
-type sm_enable() :: #sm_enable{}.

-record(fast, {zero_rtt :: 'false' | 'true' | 'undefined',
count :: 'undefined' | integer(),
invalidate :: 'false' | 'true' | 'undefined',
mechs = [] :: [binary()]}).
-type fast() :: #fast{}.

-record(feature_sm, {xmlns = <<>> :: binary()}).
-type feature_sm() :: #feature_sm{}.

Expand All @@ -464,6 +466,10 @@
retract :: 'undefined' | binary()}).
-type ps_items() :: #ps_items{}.

-record(fast_token, {expiry :: undefined | erlang:timestamp(),
token = <<>> :: binary()}).
-type fast_token() :: #fast_token{}.

-record(idle, {since :: erlang:timestamp()}).
-type idle() :: #idle{}.

Expand Down Expand Up @@ -600,6 +606,9 @@
node = <<>> :: binary()}).
-type push_disable() :: #push_disable{}.

-record(fast_request_token, {mech = <<>> :: binary()}).
-type fast_request_token() :: #fast_request_token{}.

-record(mark_displayed, {id = <<>> :: binary()}).
-type mark_displayed() :: #mark_displayed{}.

Expand All @@ -608,24 +617,6 @@
device :: 'undefined' | binary()}).
-type sasl2_user_agent() :: #sasl2_user_agent{}.

-record(jingle_ft_file, {date :: undefined | erlang:timestamp(),
desc = [] :: [#text{}],
hash = [] :: [#hash{}],
'hash-used' :: 'undefined' | #hash_used{},
'media-type' :: 'undefined' | binary(),
name :: 'undefined' | binary(),
size :: 'undefined' | non_neg_integer(),
range :: 'undefined' | #jingle_ft_range{}}).
-type jingle_ft_file() :: #jingle_ft_file{}.

-record(jingle_ft_checksum, {creator :: 'initiator' | 'responder' | 'undefined',
name = <<>> :: binary(),
file :: #jingle_ft_file{}}).
-type jingle_ft_checksum() :: #jingle_ft_checksum{}.

-record(jingle_ft_description, {file :: 'undefined' | #jingle_ft_file{}}).
-type jingle_ft_description() :: #jingle_ft_description{}.

-record(upload_request, {filename :: binary(),
size :: non_neg_integer(),
'content-type' = <<>> :: binary(),
Expand Down Expand Up @@ -850,14 +841,6 @@
xdata :: 'undefined' | #xdata{}}).
-type ps_options() :: #ps_options{}.

-record(ps_event, {items :: 'undefined' | #ps_items{},
purge :: 'undefined' | binary(),
subscription :: 'undefined' | #ps_subscription{},
delete :: 'undefined' | {binary(),binary()},
create :: 'undefined' | binary(),
configuration :: 'undefined' | {binary(),'undefined' | #xdata{}}}).
-type ps_event() :: #ps_event{}.

-record(message_thread, {parent = <<>> :: binary(),
data = <<>> :: binary()}).
-type message_thread() :: #message_thread{}.
Expand Down Expand Up @@ -962,14 +945,6 @@
sub_els = [] :: [xmpp_element() | fxml:xmlel()]}).
-type oob_x() :: #oob_x{}.

-record(pubsub_owner, {affiliations :: 'undefined' | {binary(),[#ps_affiliation{}]},
configure :: 'undefined' | {binary(),'undefined' | #xdata{}},
default :: 'undefined' | {binary(),'undefined' | #xdata{}},
delete :: 'undefined' | {binary(),binary()},
purge :: 'undefined' | binary(),
subscriptions :: 'undefined' | {binary(),[#ps_subscription{}]}}).
-type pubsub_owner() :: #pubsub_owner{}.

-record(x509_ca_list, {certs = [] :: [binary()]}).
-type x509_ca_list() :: #x509_ca_list{}.

Expand Down Expand Up @@ -1069,24 +1044,6 @@
ctry :: 'undefined' | binary()}).
-type vcard_adr() :: #vcard_adr{}.

-record(pubsub, {subscriptions :: 'undefined' | {binary(),[#ps_subscription{}]},
subscription :: 'undefined' | #ps_subscription{},
affiliations :: 'undefined' | {binary(),[#ps_affiliation{}]},
publish :: 'undefined' | #ps_publish{},
publish_options :: 'undefined' | #xdata{},
subscribe :: 'undefined' | #ps_subscribe{},
unsubscribe :: 'undefined' | #ps_unsubscribe{},
options :: 'undefined' | #ps_options{},
items :: 'undefined' | #ps_items{},
retract :: 'undefined' | #ps_retract{},
create :: 'undefined' | binary(),
configure :: 'undefined' | {binary(),'undefined' | #xdata{}},
default :: 'undefined' | {binary(),'undefined' | #xdata{}},
delete :: 'undefined' | {binary(),binary()},
purge :: 'undefined' | binary(),
rsm :: 'undefined' | #rsm_set{}}).
-type pubsub() :: #pubsub{}.

-record(vcard_tel, {home = false :: boolean(),
work = false :: boolean(),
voice = false :: boolean(),
Expand Down Expand Up @@ -1370,15 +1327,6 @@
-record(sasl_challenge, {text = <<>> :: binary()}).
-type sasl_challenge() :: #sasl_challenge{}.

-record(sasl2_failure, {reason :: 'aborted' | 'account-disabled' | 'bad-protocol' | 'credentials-expired' | 'encryption-required' | 'incorrect-encoding' | 'invalid-authzid' | 'invalid-mechanism' | 'malformed-request' | 'mechanism-too-weak' | 'not-authorized' | 'temporary-auth-failure' | 'undefined',
text :: 'undefined' | binary(),
sub_els = [] :: [xmpp_element() | fxml:xmlel()]}).
-type sasl2_failure() :: #sasl2_failure{}.

-record(sasl_failure, {reason :: 'aborted' | 'account-disabled' | 'bad-protocol' | 'credentials-expired' | 'encryption-required' | 'incorrect-encoding' | 'invalid-authzid' | 'invalid-mechanism' | 'malformed-request' | 'mechanism-too-weak' | 'not-authorized' | 'temporary-auth-failure' | 'undefined',
text = [] :: [#text{}]}).
-type sasl_failure() :: #sasl_failure{}.

-record(roster_query, {items = [] :: [#roster_item{}],
ver :: 'undefined' | binary(),
mix_annotate = false :: boolean()}).
Expand All @@ -1399,6 +1347,71 @@
-record(addresses, {list = [] :: [#address{}]}).
-type addresses() :: #addresses{}.

-record(sasl2_failure, {reason :: 'aborted' | 'account-disabled' | 'bad-protocol' | 'credentials-expired' | 'encryption-required' | 'incorrect-encoding' | 'invalid-authzid' | 'invalid-mechanism' | 'malformed-request' | 'mechanism-too-weak' | 'not-authorized' | 'temporary-auth-failure' | 'undefined',
text :: 'undefined' | binary(),
sub_els = [] :: [xmpp_element() | fxml:xmlel()]}).
-type sasl2_failure() :: #sasl2_failure{}.

-record(sasl_failure, {reason :: 'aborted' | 'account-disabled' | 'bad-protocol' | 'credentials-expired' | 'encryption-required' | 'incorrect-encoding' | 'invalid-authzid' | 'invalid-mechanism' | 'malformed-request' | 'mechanism-too-weak' | 'not-authorized' | 'temporary-auth-failure' | 'undefined',
text = [] :: [#text{}]}).
-type sasl_failure() :: #sasl_failure{}.

-record(bind, {jid :: undefined | jid:jid(),
resource = <<>> :: binary()}).
-type bind() :: #bind{}.

-record(jingle_ft_file, {date :: undefined | erlang:timestamp(),
desc = [] :: [#text{}],
hash = [] :: [#hash{}],
'hash-used' :: 'undefined' | #hash_used{},
'media-type' :: 'undefined' | binary(),
name :: 'undefined' | binary(),
size :: 'undefined' | non_neg_integer(),
range :: 'undefined' | #jingle_ft_range{}}).
-type jingle_ft_file() :: #jingle_ft_file{}.

-record(jingle_ft_checksum, {creator :: 'initiator' | 'responder' | 'undefined',
name = <<>> :: binary(),
file :: #jingle_ft_file{}}).
-type jingle_ft_checksum() :: #jingle_ft_checksum{}.

-record(jingle_ft_description, {file :: 'undefined' | #jingle_ft_file{}}).
-type jingle_ft_description() :: #jingle_ft_description{}.

-record(pubsub_owner, {affiliations :: 'undefined' | {binary(),[#ps_affiliation{}]},
configure :: 'undefined' | {binary(),'undefined' | #xdata{}},
default :: 'undefined' | {binary(),'undefined' | #xdata{}},
delete :: 'undefined' | {binary(),binary()},
purge :: 'undefined' | binary(),
subscriptions :: 'undefined' | {binary(),[#ps_subscription{}]}}).
-type pubsub_owner() :: #pubsub_owner{}.

-record(pubsub, {subscriptions :: 'undefined' | {binary(),[#ps_subscription{}]},
subscription :: 'undefined' | #ps_subscription{},
affiliations :: 'undefined' | {binary(),[#ps_affiliation{}]},
publish :: 'undefined' | #ps_publish{},
publish_options :: 'undefined' | #xdata{},
subscribe :: 'undefined' | #ps_subscribe{},
unsubscribe :: 'undefined' | #ps_unsubscribe{},
options :: 'undefined' | #ps_options{},
items :: 'undefined' | #ps_items{},
retract :: 'undefined' | #ps_retract{},
create :: 'undefined' | binary(),
configure :: 'undefined' | {binary(),'undefined' | #xdata{}},
default :: 'undefined' | {binary(),'undefined' | #xdata{}},
delete :: 'undefined' | {binary(),binary()},
purge :: 'undefined' | binary(),
rsm :: 'undefined' | #rsm_set{}}).
-type pubsub() :: #pubsub{}.

-record(ps_event, {items :: 'undefined' | #ps_items{},
purge :: 'undefined' | binary(),
subscription :: 'undefined' | #ps_subscription{},
delete :: 'undefined' | {binary(),binary()},
create :: 'undefined' | binary(),
configuration :: 'undefined' | {binary(),'undefined' | #xdata{}}}).
-type ps_event() :: #ps_event{}.

-type xmpp_element() :: address() |
addresses() |
adhoc_actions() |
Expand Down Expand Up @@ -1444,6 +1457,9 @@
disco_item() |
disco_items() |
expire() |
fast() |
fast_request_token() |
fast_token() |
fasten_apply_to() |
fasten_external() |
feature_csi() |
Expand Down
58 changes: 54 additions & 4 deletions specs/xmpp_codec.spec
Original file line number Diff line number Diff line change
Expand Up @@ -5485,14 +5485,14 @@
xmlns = <<"urn:xmpp:sasl:2">>,
module = 'xep0388',
result = {sasl2_task_data, '$_els'}}).

-xml(sasl2_next,
#elem{name = <<"next">>,
xmlns = <<"urn:xmpp:sasl:2">>,
attrs = [#attr{name = <<"task">>}],
module = 'xep0388',
result = {sasl2_next, '$task', '$_els'}}).

-xml(sasl2_abort,
#elem{name = <<"abort">>,
xmlns = <<"urn:xmpp:sasl:2">>,
Expand Down Expand Up @@ -5542,7 +5542,7 @@
label = '$var',
required = true}],
result = {bind2_feature, '$var'}}).

-xml(s2s_bidi,
#elem{name = <<"bidi">>,
xmlns = <<"urn:xmpp:features:bidi">>,
Expand Down Expand Up @@ -5581,7 +5581,57 @@
enc = {base64, encode, []},
dec = {base64, decode, []}},
result = {scram_upgrade_hash, '$data'}}).


-xml(fast,
#elem{name = <<"fast">>,
xmlns = <<"urn:xmpp:fast:0">>,
module = 'xep0484',
attrs = [#attr{name = <<"tls-0rtt">>,
label = '$zero_rtt',
enc = {enc_bool, []},
dec = {dec_bool, []}},
#attr{name = <<"count">>,
label = '$count',
enc = {enc_int, []},
dec = {dec_int, []}},
#attr{name = <<"invalidate">>,
label = '$invalidate',
enc = {enc_bool, []},
dec = {dec_bool, []}}],
refs = [#ref{name = fast_mech,
label = '$mechs',
min = 0}],
result = {fast, '$zero_rtt', '$count', '$invalidate', '$mechs'}}).

-xml(fast_mech,
#elem{name = <<"mechanism">>,
xmlns = <<"urn:xmpp:fast:0">>,
module = 'xep0484',
result = '$cdata'}).

-xml(fast_request_token,
#elem{name = <<"request-token">>,
xmlns = <<"urn:xmpp:fast:0">>,
module = 'xep0484',
attrs = [#attr{name = <<"mechanism">>,
label = '$mech',
required = true}],
result = {fast_request_token, '$mech'}
}).

-xml(fast_token,
#elem{name = <<"token">>,
xmlns = <<"urn:xmpp:fast:0">>,
module = 'xep0484',
attrs = [#attr{name = <<"expiry">>,
label = '$expiry',
enc = {enc_utc, []},
dec = {dec_utc, []}},
#attr{name = <<"token">>,
label = '$token'}],
result = {fast_token, '$expiry', '$token'}
}).

-spec dec_tzo(_) -> {integer(), integer()}.
dec_tzo(Val) ->
[H1, M1] = binary:split(Val, <<":">>),
Expand Down
Loading

0 comments on commit 66444c7

Please sign in to comment.