Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mtproto_proxy
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
mtproto_proxy
Commits
3786e263
Unverified
Commit
3786e263
authored
Aug 21, 2019
by
Sergey Prokhorov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean-up README; add some helper functions
parent
08fc61de
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
12 deletions
+25
-12
README.md
README.md
+12
-9
sys.config.example
config/sys.config.example
+1
-1
mtproto_proxy.app.src
src/mtproto_proxy.app.src
+1
-1
mtproto_proxy_app.erl
src/mtproto_proxy_app.erl
+11
-1
No files found.
README.md
View file @
3786e263
...
@@ -232,7 +232,7 @@ To change default settings, change `mtproto_proxy` section of `prod-sys.config`
...
@@ -232,7 +232,7 @@ To change default settings, change `mtproto_proxy` section of `prod-sys.config`
%% see src/mtproto_proxy.app.src for examples.
%% see src/mtproto_proxy.app.src for examples.
[
[
{
ports
,
{
ports
,
[
#
{
name
=>
mtp_handler1
,
[
#
{
name
=>
mtp_handler
_
1
,
listen_ip
=>
"0.0.0.0"
,
listen_ip
=>
"0.0.0.0"
,
port
=>
1443
,
port
=>
1443
,
secret
=>
<<
"d0d6e111bada5511fcce9584deadbeef"
>>
,
secret
=>
<<
"d0d6e111bada5511fcce9584deadbeef"
>>
,
...
@@ -321,7 +321,9 @@ Following policies are supported:
...
@@ -321,7 +321,9 @@ Following policies are supported:
*
`{in_table, KEY, TABLE_NAME}`
- only allow connections if KEY is present in TABLE_NAME (whitelist)
*
`{in_table, KEY, TABLE_NAME}`
- only allow connections if KEY is present in TABLE_NAME (whitelist)
*
`{not_in_table, KEY, TABLE_NAME}`
- only allow connections if KEY is
*not*
present in TABLE_NAME (blacklist)
*
`{not_in_table, KEY, TABLE_NAME}`
- only allow connections if KEY is
*not*
present in TABLE_NAME (blacklist)
*
`{max_connections, KEYS, NUMBER}`
- EXPERIMENTAL! if there are more than NUMBER connections with
*
`{max_connections, KEYS, NUMBER}`
- EXPERIMENTAL! if there are more than NUMBER connections with
KEYS to the proxy, new connections with those KEYS will be rejected.
KEYS to the proxy, new connections with those KEYS will be rejected. Note: number of connections is not the
same as number of unique "users". When someone connects to proxy with telegram client, Telegram
opens from 3 to 8 connections! So, you need to set this at least 8
*
number of unique users.
Where:
Where:
...
@@ -344,7 +346,8 @@ Some policy recipes / examples below
...
@@ -344,7 +346,8 @@ Some policy recipes / examples below
#### Limit max connections to proxy port from single IP
#### Limit max connections to proxy port from single IP
Here we allow maximum 100 concurrent connections from single IP to proxy port:
Here we allow maximum 100 concurrent connections from single IP to proxy port (as it was said earlier, it's not
the same as 100 unique "users"! Each telegram client opens up to 8 connections; usually 3):
```
erlang
```
erlang
{
mtproto_proxy
,
{
mtproto_proxy
,
...
@@ -371,17 +374,17 @@ others:
...
@@ -371,17 +374,17 @@ others:
<
..
>
<
..
>
```
```
After that we can create unique fake-TLS secret for each customer using co
de
like this:
After that we can create unique fake-TLS secret for each customer using co
mmand
like this:
```
erlang
```
bash
/opt/mtp_proxy/bin/mtp_proxy
eval
'
/opt/mtp_proxy/bin/mtp_proxy
eval
'
ProxySecret
=
mtp_handler
:
unhex
(
maps
:
get
(
secret
,
hd
(
application
:
get_env
(
mtproto_proxy
,
ports
,
[])))),
PortName = mtp_handler_1,
{ok, ProxySecret} = mtproto_proxy_app:get_port_secret(PortName),
NumRecords = mtp_policy_table:table_size(customer_domains),
NumRecords = mtp_policy_table:table_size(customer_domains),
Rand
=
crypto
:
rand_bytes
(
2
),
SubDomain = mtp_handler:hex(<<NumRecords:16, (crypto:strong_rand_bytes(2))/binary>>),
SubDomain
=
mtp_handler
:
hex
(
<<
NumRecords
:
16
,
Rand
/
binary
>>
),
Domain = <<SubDomain/binary, ".google.com">>,
Domain = <<SubDomain/binary, ".google.com">>,
mtp_policy_table:add(customer_domains, tls_domain, Domain),
mtp_policy_table:add(customer_domains, tls_domain, Domain),
Secret
=
mtp_
handler
:
hex
(
<<
16#ee
,
ProxySecret
/
binary
,
Domain
/
binary
>>
),
Secret = mtp_
fake_tls:format_secret_hex(ProxySecret, Domain
),
io:format("Secret: ~s;\nDomain: ~s\n", [Secret, Domain]).'
io:format("Secret: ~s;\nDomain: ~s\n", [Secret, Domain]).'
```
```
...
...
config/sys.config.example
View file @
3786e263
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
%% DO NOT EDIT src/mtproto_proxy.app.src!!!
%% DO NOT EDIT src/mtproto_proxy.app.src!!!
[
[
%% {ports,
%% {ports,
%% [#{name => mtp_handler1,
%% [#{name => mtp_handler
_
1,
%% listen_ip => "0.0.0.0",
%% listen_ip => "0.0.0.0",
%% port => 1443,
%% port => 1443,
%% secret => <<"d0d6e111bada5511fcce9584deadbeef">>,
%% secret => <<"d0d6e111bada5511fcce9584deadbeef">>,
...
...
src/mtproto_proxy.app.src
View file @
3786e263
...
@@ -39,7 +39,7 @@
...
@@ -39,7 +39,7 @@
%% If not set, 0.0.0.0 will be used
%% If not set, 0.0.0.0 will be used
{listen_ip, "0.0.0.0"},
{listen_ip, "0.0.0.0"},
%% You can add as much as you want. Names and ports should be unique
%% You can add as much as you want. Names and ports should be unique
{ports, [#{name => mtp_handler,
{ports, [#{name => mtp_handler
_1
,
port => 1443,
port => 1443,
%% You can tell it to listen on specific IP.
%% You can tell it to listen on specific IP.
%% If not set, top-level listen_ip will be used.
%% If not set, top-level listen_ip will be used.
...
...
src/mtproto_proxy_app.erl
View file @
3786e263
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
%% Application callbacks
%% Application callbacks
-
export
([
start
/
2
,
prep_stop
/
1
,
stop
/
1
,
config_change
/
3
]).
-
export
([
start
/
2
,
prep_stop
/
1
,
stop
/
1
,
config_change
/
3
]).
-
export
([
mtp_listeners
/
0
,
running_ports
/
0
,
start_proxy
/
1
,
build_urls
/
4
]).
-
export
([
mtp_listeners
/
0
,
running_ports
/
0
,
start_proxy
/
1
,
build_urls
/
4
,
get_port_secret
/
1
]).
-
define
(
APP
,
mtproto_proxy
).
-
define
(
APP
,
mtproto_proxy
).
...
@@ -81,6 +81,16 @@ running_ports() ->
...
@@ -81,6 +81,16 @@ running_ports() ->
end
end
end
,
mtp_listeners
()).
end
,
mtp_listeners
()).
-
spec
get_port_secret
(
atom
())
->
{
ok
,
binary
()}
|
not_found
.
get_port_secret
(
Name
)
->
case
[
Secret
||
#
{
name
:
=
PortName
,
secret
:
=
Secret
}
<-
application
:
get_env
(
?
APP
,
ports
,
[]),
PortName
==
Name
]
of
[
Secret
]
->
{
ok
,
Secret
};
_
->
not_found
end
.
%%====================================================================
%%====================================================================
%% Internal functions
%% Internal functions
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment