Skip to content

Commit fbe8cb5

Browse files
committed
Allow any in tls_allowed_domains.
1 parent 237f9f1 commit fbe8cb5

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ all: config/prod-sys.config config/prod-vm.args
1313
.PHONY: test
1414
test:
1515
$(REBAR3) xref
16-
$(REBAR3) eunit
17-
$(REBAR3) ct
18-
$(REBAR3) proper -n 50
16+
$(REBAR3) eunit -c
17+
$(REBAR3) ct -c
18+
$(REBAR3) proper -c -n 50
1919
$(REBAR3) dialyzer
20+
$(REBAR3) cover -v
2021

2122
config/prod-sys.config: config/sys.config.example
2223
[ -f $@ ] && diff $^ $@ || true

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ You should disable all protocols other than `mtp_secure` by providing `allowed_p
258258
Another censorship circumvention technique. MTPRoto proxy protocol pretends to be
259259
HTTPS web traffic (technically speaking, TLSv1.3 + HTTP/2).
260260
It's possible to only allow connections with this protocol by changing `allowed_protocols` to
261-
be list with only `mtp_fake_tls`:
261+
be list with only `mtp_fake_tls`. You may also want to check `tls_allowed_domains` option.
262262

263263
```erlang
264264
{mtproto_proxy,

src/mtp_handler.erl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,14 @@ maybe_check_replay(Packet) ->
359359
check_tls_access(_Listener, _Ip, #{sni_domain := Domain}) ->
360360
%% TODO validate timestamp!
361361
%% TODO some more scalable solution
362-
AllowedDomains = application:get_env(?APP, tls_allowed_domains, []),
363-
lists:member(Domain, AllowedDomains)
364-
orelse error({protocol_error, tls_sni_domain_not_allowed, Domain});
362+
case application:get_env(?APP, tls_allowed_domains, any) of
363+
any ->
364+
%% No limits
365+
true;
366+
AllowedDomains ->
367+
lists:member(Domain, AllowedDomains)
368+
orelse error({protocol_error, tls_sni_domain_not_allowed, Domain})
369+
end;
365370
check_tls_access(_, Ip, Meta) ->
366371
error({protocol_error, tls_no_sni, {Ip, Meta}}).
367372

src/mtproto_proxy.app.src

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@
6060

6161
%% Which domains to allow in TLS SNI
6262
%% XXX: this option is experimental and will be removed later!
63-
{tls_allowed_domains, [<<"en.wikipedia.org">>]},
63+
%% Can be set to `any' to allow any domains.
64+
%% {tls_allowed_domains, any},
65+
{tls_allowed_domains, [<<"en.wikipedia.org">>, <<"s3.amazonaws.com">>]},
6466

6567
{init_dc_connections, 2},
6668
{clients_per_dc_connection, 300},

src/mtproto_proxy_app.erl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,11 @@ build_urls(Host, Port, Secret, Protocols) ->
173173
lists:map(
174174
fun(mtp_fake_tls) ->
175175
%% Print just for 1st domain as example
176-
{ok, [Domain | _]} = application:get_env(?APP, tls_allowed_domains),
176+
Domain = case application:get_env(?APP, tls_allowed_domains) of
177+
{ok, [Domain0 | _]} -> Domain0;
178+
_ ->
179+
<<"en.wikipedia.org">>
180+
end,
177181
ProtoSecret = mtp_fake_tls:format_secret(Secret, Domain),
178182
MkUrl(ProtoSecret);
179183
(mtp_secure) ->

0 commit comments

Comments
 (0)