Skip to content

Commit

Permalink
Add support for XEP-0480 SASL Upgrade Tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
prefiks committed Oct 28, 2024
1 parent 940f48b commit 85d4cb6
Show file tree
Hide file tree
Showing 6 changed files with 678 additions and 97 deletions.
31 changes: 27 additions & 4 deletions include/xmpp_codec.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@
-record(starttls_proceed, {}).
-type starttls_proceed() :: #starttls_proceed{}.

-record(sasl2_next, {task = <<>> :: binary(),
sub_els = [] :: [xmpp_element() | fxml:xmlel()]}).
-type sasl2_next() :: #sasl2_next{}.

-record(upload_file_too_large, {'max-file-size' :: 'undefined' | integer(),
xmlns = <<>> :: binary()}).
-type upload_file_too_large() :: #upload_file_too_large{}.
Expand All @@ -179,6 +183,10 @@
exts = [] :: [binary()]}).
-type caps() :: #caps{}.

-record(scram_upgrade_salt, {iterations :: pos_integer(),
cdata = <<>> :: binary()}).
-type scram_upgrade_salt() :: #scram_upgrade_salt{}.

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

Expand Down Expand Up @@ -287,9 +295,6 @@
sub_els = [] :: [xmpp_element() | fxml:xmlel()]}).
-type address() :: #address{}.

-record(addresses, {list = [] :: [#address{}]}).
-type addresses() :: #addresses{}.

-record(sasl_success, {text = <<>> :: binary()}).
-type sasl_success() :: #sasl_success{}.

Expand Down Expand Up @@ -332,6 +337,9 @@
-record(private, {sub_els = [] :: [xmpp_element() | fxml:xmlel()]}).
-type private() :: #private{}.

-record(scram_upgrade_hash, {data = <<>> :: binary()}).
-type scram_upgrade_hash() :: #scram_upgrade_hash{}.

-record(message_retracted, {id = <<>> :: binary(),
by :: undefined | jid:jid(),
from = <<>> :: binary(),
Expand Down Expand Up @@ -647,6 +655,9 @@
-record(message_retract_30, {}).
-type message_retract_30() :: #message_retract_30{}.

-record(sasl2_task_data, {sub_els = [] :: [xmpp_element() | fxml:xmlel()]}).
-type sasl2_task_data() :: #sasl2_task_data{}.

-record(muc_subscriptions, {list = [] :: [#muc_subscription{}]}).
-type muc_subscriptions() :: #muc_subscriptions{}.

Expand Down Expand Up @@ -735,6 +746,9 @@
-record(mark_acknowledged, {id = <<>> :: binary()}).
-type mark_acknowledged() :: #mark_acknowledged{}.

-record(sasl_upgrade, {cdata = <<>> :: binary()}).
-type sasl_upgrade() :: #sasl_upgrade{}.

-record(bind2_bind, {tag :: 'undefined' | binary(),
inline :: 'undefined' | [xmpp_element() | fxml:xmlel()],
sub_els = [] :: [xmpp_element() | fxml:xmlel()]}).
Expand Down Expand Up @@ -935,7 +949,8 @@
-type block() :: #block{}.

-record(sasl2_authenticaton, {mechanisms = [] :: [binary()],
inline :: 'undefined' | [xmpp_element() | fxml:xmlel()]}).
inline :: 'undefined' | [xmpp_element() | fxml:xmlel()],
sub_els = [] :: [xmpp_element() | fxml:xmlel()]}).
-type sasl2_authenticaton() :: #sasl2_authenticaton{}.

-record(muc_hats, {hats = [] :: [#muc_hat{}]}).
Expand Down Expand Up @@ -1381,6 +1396,9 @@
text = [] :: [#text{}]}).
-type stream_error() :: #stream_error{}.

-record(addresses, {list = [] :: [#address{}]}).
-type addresses() :: #addresses{}.

-type xmpp_element() :: address() |
addresses() |
adhoc_actions() |
Expand Down Expand Up @@ -1563,8 +1581,10 @@
sasl2_challenge() |
sasl2_continue() |
sasl2_failure() |
sasl2_next() |
sasl2_response() |
sasl2_success() |
sasl2_task_data() |
sasl2_user_agent() |
sasl_abort() |
sasl_auth() |
Expand All @@ -1574,6 +1594,9 @@
sasl_mechanisms() |
sasl_response() |
sasl_success() |
sasl_upgrade() |
scram_upgrade_hash() |
scram_upgrade_salt() |
search() |
search_item() |
'see-other-host'() |
Expand Down
48 changes: 42 additions & 6 deletions specs/xmpp_codec.spec
Original file line number Diff line number Diff line change
Expand Up @@ -5301,7 +5301,7 @@
#ref{name = sasl2_inline,
label = '$inline',
min = 0, max = 1}],
result = {sasl2_authenticaton, '$mechanisms', '$inline'}}).
result = {sasl2_authenticaton, '$mechanisms', '$inline', '$_els'}}).

-xml(sasl2_mechanism,
#elem{name = <<"mechanism">>,
Expand Down Expand Up @@ -5477,12 +5477,22 @@
-xml(sasl2_task,
#elem{name = <<"task">>,
xmlns = <<"urn:xmpp:sasl:2">>,
module = 'xep0388',
cdata = #cdata{label = '$text',
dec = {base64, mime_decode, []},
enc = {base64, encode, []}},
result = '$text'}).
module = 'xep0388',
result = '$cdata'}).

-xml(sasl2_task_data,
#elem{name = <<"task-data">>,
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 @@ -5539,6 +5549,32 @@
module = 'xep0288',
result = {s2s_bidi}}).

-xml(sasl_upgrade,
#elem{name = <<"upgrade">>,
xmlns = <<"urn:xmpp:sasl:upgrade:0">>,
module = 'xep0480',
result = {sasl_upgrade, '$cdata'}}).

-xml(scram_upgrade_salt,
#elem{name = <<"salt">>,
xmlns = <<"urn:xmpp:scram-upgrade:0">>,
module = 'xep0480',
attrs = [#attr{name = <<"iterations">>,
label = '$iterations',
enc = {enc_int, []},
dec = {dec_int, [1, infinity]},
required = true}],
result = {scram_upgrade_salt, '$iterations', '$cdata'}}).

-xml(scram_upgrade_hash,
#elem{name = <<"hash">>,
xmlns = <<"urn:xmpp:scram-upgrade:0">>,
module = 'xep0480',
cdata = #cdata{label = '$data',
enc = {base64, encode, []},
dec = {base64, decode, []}},
result = {scram_upgrade_hash, '$data'}}).

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

0 comments on commit 85d4cb6

Please sign in to comment.