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
d43152e9
Unverified
Commit
d43152e9
authored
Jun 06, 2020
by
Sergey Prokhorov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests: handle situation when ServerHello is split to multiple packets
parent
5ad7c536
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
11 deletions
+26
-11
mtp_fake_tls.erl
src/mtp_fake_tls.erl
+7
-2
mtp_test_client.erl
test/mtp_test_client.erl
+19
-9
No files found.
src/mtp_fake_tls.erl
View file @
d43152e9
...
...
@@ -298,9 +298,14 @@ add_padding_ext(RealExtensions, ExtLen) ->
%% Parses "ServerHello" (the one produced by from_client_hello/2). Used for tests only.
parse_server_hello
(
<<?
TLS_REC_HANDSHAKE
,
?
TLS_12_VERSION
,
HSLen
:
?
u16
,
Handshake
:
HSLen
/
binary
,
?
TLS_REC_CHANGE_CIPHER
,
?
TLS_12_VERSION
,
CCLen
:
?
u16
,
ChangeCipher
:
CCLen
/
binary
,
?
TLS_REC_DATA
,
?
TLS_12_VERSION
,
DLen
:
?
u16
,
Data
:
DLen
/
binary
,
?
TLS_REC_DATA
,
?
TLS_12_VERSION
,
DLen
:
?
u16
,
Tail
/
binary
>>
)
->
{
Handshake
,
ChangeCipher
,
Data
,
Tail
};
case
Tail
of
<<
Data
:
DLen
/
binary
,
Tail2
/
binary
>>
->
{
Handshake
,
ChangeCipher
,
Data
,
Tail2
};
_
->
incomplete
end
;
parse_server_hello
(
B
)
when
byte_size
(
B
)
<
(
512
+
5
)
->
incomplete
.
...
...
test/mtp_test_client.erl
View file @
d43152e9
...
...
@@ -35,31 +35,31 @@ connect(Host, Port, Secret, DcId, Protocol) ->
binary
(),
binary
(),
integer
(),
mtp_codec
:
packet_codec
()
|
{
mtp_fake_tls
,
binary
()})
->
client
().
connect
(
Host
,
Port
,
Seed
,
Secret
,
DcId
,
Protocol0
)
->
Timeout
=
5000
,
Opts
=
[{
packet
,
raw
},
{
mode
,
binary
},
{
active
,
false
},
{
buffer
,
1024
},
{
send_timeout
,
5000
}],
{
ok
,
Sock
}
=
gen_tcp
:
connect
(
Host
,
Port
,
Opts
,
1000
),
{
Protocol
,
TlsEnabled
,
TlsSt
}
=
{
send_timeout
,
Timeout
}],
{
ok
,
Sock
}
=
gen_tcp
:
connect
(
Host
,
Port
,
Opts
,
Timeout
),
{
Protocol
,
TlsEnabled
,
TlsSt
,
Tail
}
=
case
Protocol0
of
{
mtp_fake_tls
,
Domain
}
->
ClientHello
=
mtp_fake_tls
:
make_client_hello
(
Secret
,
Domain
),
ok
=
gen_tcp
:
send
(
Sock
,
ClientHello
),
%% Let's hope whole server hello will arrive in a single chunk
{
ok
,
ServerHello
}
=
gen_tcp
:
recv
(
Sock
,
0
,
5000
),
%% TODO: if Tail is not empty, use codec:push_back(first, ..)
{_
HS
,
_
CC
,
_
D
,
<<>>
}
=
mtp_fake_tls
:
parse_server_hello
(
ServerHello
),
{
mtp_secure
,
true
,
mtp_fake_tls
:
new
()};
_
->
{
Protocol0
,
false
,
undefined
}
Tail_
=
recv_server_hello
(
Sock
,
Timeout
,
<<>>
),
{
mtp_secure
,
true
,
mtp_fake_tls
:
new
(),
Tail_
};
_
->
{
Protocol0
,
false
,
undefined
,
<<>>
}
end
,
{
Header0
,
_,
_,
CryptoLayer
}
=
mtp_obfuscated
:
client_create
(
Seed
,
Secret
,
Protocol
,
DcId
),
NoopSt
=
mtp_noop_codec
:
new
(),
%% First, create codec with just TLS (which might be noop as well) to encode "obfuscated" header
Codec0
=
mtp_codec
:
new
(
mtp_noop_codec
,
NoopSt
,
Codec0
0
=
mtp_codec
:
new
(
mtp_noop_codec
,
NoopSt
,
mtp_noop_codec
,
NoopSt
,
TlsEnabled
,
TlsSt
,
25
*
1024
*
1024
),
Codec0
=
mtp_codec
:
push_back
(
first
,
Tail
,
Codec00
),
{
Header
,
Codec1
}
=
mtp_codec
:
encode_packet
(
Header0
,
Codec0
),
ok
=
gen_tcp
:
send
(
Sock
,
Header
),
PacketLayer
=
Protocol
:
new
(),
...
...
@@ -68,6 +68,16 @@ connect(Host, Port, Seed, Secret, DcId, Protocol0) ->
#client
{
sock
=
Sock
,
codec
=
Codec3
}.
recv_server_hello
(
Sock
,
Timeout
,
Acc
)
->
{
ok
,
ServerHelloPart
}
=
gen_tcp
:
recv
(
Sock
,
0
,
Timeout
),
ServerHello
=
<<
Acc
/
binary
,
ServerHelloPart
/
binary
>>
,
case
mtp_fake_tls
:
parse_server_hello
(
ServerHello
)
of
{_
HS
,
_
CC
,
_
D
,
Tail
}
->
Tail
;
incomplete
->
recv_server_hello
(
Sock
,
Timeout
,
ServerHello
)
end
.
send
(
Data
,
#client
{
sock
=
Sock
,
codec
=
Codec
}
=
Client
)
->
{
Enc
,
Codec1
}
=
mtp_codec
:
encode_packet
(
Data
,
Codec
),
ok
=
gen_tcp
:
send
(
Sock
,
Enc
),
...
...
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