Re: DTLS patch

Haiyang Yin <[email protected]> Mon, 1 Jun 2015 21:31:15 -0400
Newsgroups gmane.comp.lang.erlang.patches
Message-ID <CAEVsv9XHbWHLhKSKELmt0NB-yEczzzysJXuTsqLcfjmW=kWK_w@mail.gmail.com>
--===============0183598584491916105==
Content-Type: multipart/alternative; boundary=f46d041825e2ff64c605177ee544

--f46d041825e2ff64c605177ee544
Content-Type: text/plain; charset=UTF-8

Hi Andreas/Ingela,

Thanks you very much for your comments and time. I very appreciate it. I
have some inline comments marked with [YHY]:

1.) Have you tested your changes with packet loss and reordering, especially
reordering around the the Change Cipher Spec message?

Keeping the correct cipher context for re-sending old flights and decoding
incoming re-sends across CCS messages is not trivial and from reading the
code I can't convince myself that it would work.

[YHY] No, the change we made was based on existing dtls code and minor
changes, e.g. fragmented handshake messages, retransmission of old flights
and etc. The existing code dealt with cases specified by RFC on the basis
of record sequence number and handshake message sequence number. I agree
reordering is much more complicated than current code as more information
needs to be cached in order to reorder/reconstruct handshake messages. As
we move on, certainly that part in dtls_handshake.erl would be enhanced.
Very good point to bring this up.

2.) I'm not happy with the way new clients are handled. You seem to
insert them into an ETS tables without waiting for the answer to an
HelloVerifyRequest. This opens a way for resource exhaustion and denial
of service attacks. The DTLS RFC is quite explicit that the verify
cookie should be generated stateless and that the server should expend
any memory resource until the Hello was verified successfully.

[YHY] Our purpose of designing dtls_transport module is to have a thin
protocol-agnostic layer to just pass the datagram packets. Cookie mechanism
makes it hard for spoofing DoS attack but no defense from valid IP
addresses. You are right the resource leak in ETS table in this case, to
overcome this, we can start a timer to wait for CLIENT HELLO and close the
socket (remove it from ETS table) for both DoS cases. This provides another
way of invalidating the Cookies if the attacker tries to collect a number
of cookies from different addresses (See discussion in DTLS RFC). Any
comments ?

3.) TLS is almost exclusively used in a pure form over TCP, the situation
is different with DTLS where some interesting deviations exist. The TCP
like socket handling is not help full with those.

For example CAPWAP (RFC 5415) multiplexes DTLS and non DTLS data over the
same UDP socket. Some mechanism to hook between the raw socket and the
DTLS logic is required for that.

[YHY] Sorry I am not familiar with CAPWAP, is it the service discovery
(clear text) and later DTLS session established to convey encrypted data ?
To me, this might be resolved in dtls_connection module. When raw datagram
packets passed to handle_info callback, it can check data based on session
state on which the data is encrypted or not. It is flexible but sacrifice
the performance in raw socket level. This is very important because it will
impact how application developers use the interface. I hope further
discussion required for this topic.

4.) You have certainly added lots of code, but you have still reused some
ideas and code from my earlier versions. A small attribution wouldn't hurt.

[YHY] The existing DTLS code is well-written. We guess it just you didn't
have enough time to polish it further. We actually didn't change too much
and it works well in sunny cases. Having said that our change is a patch
but not a new feature.

Regarding the test cases, we will follow ssl_to_openssl_SUITE to add
dtls_to_openssl_SUITE later, it is always a good idea to have test cases.

This is a start point toward complete DTLS implementation as Ingela
mentioned. We are sure more comments and ideas would come out when we dig
deep further.

We will continue follow up on this,

Cheers,

/Haiyang

On Mon, Jun 1, 2015 at 9:32 AM, Ingela Anderton Andin <
[email protected]> wrote:

> Hi!
>
> See inlined comments, to both Andreas and Haiyangs mails.
>
> On 05/31/2015 05:22 PM, Andreas Schultz wrote:
>
>> Hi Haiyang,
>>
>> I'm sure Ingela will have plenty to say, starting with "Unit Tests".
>>
>
> Yes you are absolutely correct we want tests, a good place to start
> could be a dtls_to_openssl_SUITE corresponding to ssl_to_openssl_SUITE.
>
>  A few comments from me:
>>
>> 1.) Have you tested your changes with packet loss and reordering,
>> especially
>> reordering around the the Change Cipher Spec message?
>>
>> Keeping the correct cipher context for re-sending old flights and decoding
>> incoming re-sends across CCS messages is not trivial and from reading the
>> code I can't convince myself that it would work.
>>
>> 2.) I'm not happy with the way new clients are handled. You seem to
>> insert them into an ETS tables without waiting for the answer to an
>> HelloVerifyRequest. This opens a way for resource exhaustion and denial
>> of service attacks. The DTLS RFC is quite explicit that the verify
>> cookie should be generated stateless and that the server should expend
>> any memory resource until the Hello was verified successfully.
>>
>> 3.) TLS is almost exclusively used in a pure form over TCP, the situation
>> is different with DTLS where some interesting deviations exist. The TCP
>> like socket handling is not help full with those.
>>
>> For example CAPWAP (RFC 5415) multiplexes DTLS and non DTLS data over the
>> same UDP socket. Some mechanism to hook between the raw socket and the
>> DTLS logic is required for that.
>>
>> 4.) You have certainly added lots of code, but you have still reused some
>> ideas and code from my earlier versions. A small attribution wouldn't
>> hurt.
>>
>
> I am sure these are all valid comments to consider. Andreas has made many
> valuable contributions to the ssl application in the past and has a good
> knowledge in the subject.
>
>  We have a server application needs DTLS protocol support. But the current
>>> OTP
>>> release still has an incomplete DTLS implementation. So we create this
>>> patch to
>>> include DTLS implementation based on current well-designed ssl
>>> architecture
>>> (which we don't consider this as a new feature, just a patch). What we
>>> have
>>> added are:
>>>
>>> 1. DTLS transport layer on top of gen_udp
>>> 2. DTLS flight retransmission and timeout mechanism
>>> 3. DTLS record fragmentation/defragmentation handling
>>>
>>> It looks good that the patch can work with OpenSSL 1.0.2a release. If no
>>> one is
>>> working on dtls now, we would like to have this patch to be reviewed.
>>>
>>> Following is the repository contains the patch:
>>>
>>> https://github.com/haiyang-yin/otp
>>>
>>> To fetch the patch, refer to following git commands:
>>>
>>> git clone https://github.com/haiyang-yin/otp.git
>>> git checkout dtls_patch
>>>
>> >>
>
>> Here is code review location:
>>>
>>> https://github.com/haiyang-yin/otp/compare/maint...haiyang-yin:dtls_patch
>>>
>>> There are two demo programs to show how dtls client/server works in the
>>> attachments.
>>>
>>> Feel free to let me know if further information is needed.
>>>
>>
> We would prefer if you could make it into a pull-request, or maybe several
> pull-requests. I think the first commit moving functions from
> tls_connection into ssl_connection could be one pull-request. That can be
> considered part of the refactoring work that I was doing in order to make
> our DTLS-implementation (that I alas have not  had time to finish due to
> other things being prioritized). So we could include that as a first step.
>
> The other parts I and the OTP team will need some more time to think about
> your implementation suggestion. But what ever the conclusion will
> be, it is a way to give this issue some more focus, and hopefully move it
> forward towards a functioning DLTS implementation.
>
> Regards Ingela Erlang/OTP Team Ericssson AB
>
>
>

--f46d041825e2ff64c605177ee544
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi Andreas/Ingela,<div><br></div><div>Thanks you very much=
 for your comments and time. I very appreciate it. I have some inline comme=
nts marked with [YHY]:</div><div><br></div><div><span style=3D"color:rgb(80=
,0,80);font-size:13px">1.) Have you tested your changes with packet loss an=
d reordering, especially</span><br style=3D"color:rgb(80,0,80);font-size:13=
px"><span style=3D"color:rgb(80,0,80);font-size:13px">reordering around the=
 the Change Cipher Spec message?</span><br style=3D"color:rgb(80,0,80);font=
-size:13px"><br style=3D"color:rgb(80,0,80);font-size:13px"><span style=3D"=
color:rgb(80,0,80);font-size:13px">Keeping the correct cipher context for r=
e-sending old flights and decoding</span><br style=3D"color:rgb(80,0,80);fo=
nt-size:13px"><span style=3D"color:rgb(80,0,80);font-size:13px">incoming re=
-sends across CCS messages is not trivial and from reading the</span><br st=
yle=3D"color:rgb(80,0,80);font-size:13px"><span style=3D"color:rgb(80,0,80)=
;font-size:13px">code I can&#39;t convince myself that it would work.</span=
></div><div><br></div><div>[YHY] No, the change we made was based on existi=
ng dtls code and minor changes, e.g. fragmented handshake messages, retrans=
mission of old flights and etc. The existing code dealt with cases specifie=
d by RFC on the basis of record sequence number and handshake message seque=
nce number. I agree reordering is much more complicated than current code a=
s more information needs to be cached in order to reorder/reconstruct hands=
hake messages. As we move on, certainly that part in dtls_handshake.erl wou=
ld be enhanced. Very good point to bring this up.<br style=3D"color:rgb(80,=
0,80);font-size:13px"><br style=3D"color:rgb(80,0,80);font-size:13px"><span=
 style=3D"color:rgb(80,0,80);font-size:13px">2.) I&#39;m not happy with the=
 way new clients are handled. You seem to</span><br style=3D"color:rgb(80,0=
,80);font-size:13px"><span style=3D"color:rgb(80,0,80);font-size:13px">inse=
rt them into an ETS tables without waiting for the answer to an</span><br s=
tyle=3D"color:rgb(80,0,80);font-size:13px"><span style=3D"color:rgb(80,0,80=
);font-size:13px">HelloVerifyRequest. This opens a way for resource exhaust=
ion and denial</span><br style=3D"color:rgb(80,0,80);font-size:13px"><span =
style=3D"color:rgb(80,0,80);font-size:13px">of service attacks. The DTLS RF=
C is quite explicit that the verify</span><br style=3D"color:rgb(80,0,80);f=
ont-size:13px"><span style=3D"color:rgb(80,0,80);font-size:13px">cookie sho=
uld be generated stateless and that the server should expend</span><br styl=
e=3D"color:rgb(80,0,80);font-size:13px"><span style=3D"color:rgb(80,0,80);f=
ont-size:13px">any memory resource until the Hello was verified successfull=
y.</span></div><div><br></div><div>[YHY] Our purpose of designing dtls_tran=
sport module is to have a thin protocol-agnostic layer to just pass the dat=
agram packets. Cookie mechanism makes it hard for spoofing DoS attack but n=
o defense from valid IP addresses. You are right the resource leak in ETS t=
able in this case, to overcome this, we can start a timer to wait for CLIEN=
T HELLO and close the socket (remove it from ETS table) for both DoS cases.=
 This provides another way of invalidating the Cookies if the attacker trie=
s to collect a number of cookies from different addresses (See discussion i=
n DTLS RFC). Any comments ?<br style=3D"color:rgb(80,0,80);font-size:13px">=
<br style=3D"color:rgb(80,0,80);font-size:13px"><span style=3D"color:rgb(80=
,0,80);font-size:13px">3.) TLS is almost exclusively used in a pure form ov=
er TCP, the situation</span><br style=3D"color:rgb(80,0,80);font-size:13px"=
><span style=3D"color:rgb(80,0,80);font-size:13px">is different with DTLS w=
here some interesting deviations exist. The TCP</span><br style=3D"color:rg=
b(80,0,80);font-size:13px"><span style=3D"color:rgb(80,0,80);font-size:13px=
">like socket handling is not help full with those.</span><br style=3D"colo=
r:rgb(80,0,80);font-size:13px"><br style=3D"color:rgb(80,0,80);font-size:13=
px"><span style=3D"color:rgb(80,0,80);font-size:13px">For example CAPWAP (R=
FC 5415) multiplexes DTLS and non DTLS data over the</span><br style=3D"col=
or:rgb(80,0,80);font-size:13px"><span style=3D"color:rgb(80,0,80);font-size=
:13px">same UDP socket. Some mechanism to hook between the raw socket and t=
he</span><br style=3D"color:rgb(80,0,80);font-size:13px"><span style=3D"col=
or:rgb(80,0,80);font-size:13px">DTLS logic is required for that.</span><br =
style=3D"color:rgb(80,0,80);font-size:13px"><br>[YHY] Sorry I am not famili=
ar with CAPWAP, is it the service discovery (clear text) and later DTLS ses=
sion established to convey encrypted data ? To me, this might be resolved i=
n dtls_connection module. When raw datagram packets passed to handle_info c=
allback, it can check data based on session state on which the data is encr=
ypted or not. It is flexible but sacrifice the performance in raw socket le=
vel. This is very important because it will impact how application develope=
rs use the interface. I hope further discussion required for this topic.=C2=
=A0</div><div><br><span style=3D"color:rgb(80,0,80);font-size:13px">4.) You=
 have certainly added lots of code, but you have still reused some</span><b=
r style=3D"color:rgb(80,0,80);font-size:13px"><span style=3D"color:rgb(80,0=
,80);font-size:13px">ideas and code from my earlier versions. A small attri=
bution wouldn&#39;t hurt.</span><br></div><div><span style=3D"color:rgb(80,=
0,80);font-size:13px"><br></span></div><div><span style=3D"color:rgb(80,0,8=
0);font-size:13px">[YHY] The existing DTLS code is well-written. We guess i=
t just you didn&#39;t have enough time to polish it further. We actually di=
dn&#39;t change too much and it works well in sunny cases. Having said that=
 our change is a patch but not a new feature.=C2=A0</span></div><div><span =
style=3D"color:rgb(80,0,80);font-size:13px"><br></span></div><div><font col=
or=3D"#500050">Regarding the test cases, we will follow ssl_to_openssl_SUIT=
E to add dtls_to_openssl_SUITE later, it is always a good idea to have test=
 cases.</font></div><div><font color=3D"#500050"><br></font></div><div><fon=
t color=3D"#500050">This is a start point toward complete DTLS implementati=
on as Ingela mentioned. We are sure more comments and ideas would come out =
when we dig deep further.</font></div><div><font color=3D"#500050"><br></fo=
nt></div><div><font color=3D"#500050">We will continue follow up on this,</=
font></div><div><font color=3D"#500050"><br></font></div><div><font color=
=3D"#500050">Cheers,</font></div><div><font color=3D"#500050"><br></font></=
div><div><font color=3D"#500050">/Haiyang</font></div></div><div class=3D"g=
mail_extra"><br><div class=3D"gmail_quote">On Mon, Jun 1, 2015 at 9:32 AM, =
Ingela Anderton Andin <span dir=3D"ltr">&lt;<a href=3D"mailto:Ingela.Andert=
[email protected]" target=3D"_blank">[email protected]=
</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin=
:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi!<br>
<br>
See inlined comments, to both Andreas and Haiyangs mails.<span class=3D""><=
br>
<br>
On 05/31/2015 05:22 PM, Andreas Schultz wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">
Hi Haiyang,<br>
<br>
I&#39;m sure Ingela will have plenty to say, starting with &quot;Unit Tests=
&quot;.<br>
</blockquote>
<br></span>
Yes you are absolutely correct we want tests, a good place to start<br>
could be a dtls_to_openssl_SUITE corresponding to ssl_to_openssl_SUITE.<spa=
n class=3D""><br>
<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">
A few comments from me:<br>
<br>
1.) Have you tested your changes with packet loss and reordering, especiall=
y<br>
reordering around the the Change Cipher Spec message?<br>
<br>
Keeping the correct cipher context for re-sending old flights and decoding<=
br>
incoming re-sends across CCS messages is not trivial and from reading the<b=
r>
code I can&#39;t convince myself that it would work.<br>
<br>
2.) I&#39;m not happy with the way new clients are handled. You seem to<br>
insert them into an ETS tables without waiting for the answer to an<br>
HelloVerifyRequest. This opens a way for resource exhaustion and denial<br>
of service attacks. The DTLS RFC is quite explicit that the verify<br>
cookie should be generated stateless and that the server should expend<br>
any memory resource until the Hello was verified successfully.<br>
<br>
3.) TLS is almost exclusively used in a pure form over TCP, the situation<b=
r>
is different with DTLS where some interesting deviations exist. The TCP<br>
like socket handling is not help full with those.<br>
<br>
For example CAPWAP (RFC 5415) multiplexes DTLS and non DTLS data over the<b=
r>
same UDP socket. Some mechanism to hook between the raw socket and the<br>
DTLS logic is required for that.<br>
<br>
4.) You have certainly added lots of code, but you have still reused some<b=
r>
ideas and code from my earlier versions. A small attribution wouldn&#39;t h=
urt.<br>
</blockquote>
<br></span>
I am sure these are all valid comments to consider. Andreas has made many v=
aluable contributions to the ssl application in the past and has a good kno=
wledge in the subject.<span class=3D""><br>
<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><blockquote class=3D"gmail_quote" style=3D"m=
argin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
We have a server application needs DTLS protocol support. But the current O=
TP<br>
release still has an incomplete DTLS implementation. So we create this patc=
h to<br>
include DTLS implementation based on current well-designed ssl architecture=
<br>
(which we don&#39;t consider this as a new feature, just a patch). What we =
have<br>
added are:<br>
<br>
1. DTLS transport layer on top of gen_udp<br>
2. DTLS flight retransmission and timeout mechanism<br>
3. DTLS record fragmentation/defragmentation handling<br>
<br>
It looks good that the patch can work with OpenSSL 1.0.2a release. If no on=
e is<br>
working on dtls now, we would like to have this patch to be reviewed.<br>
<br>
Following is the repository contains the patch:<br>
<br>
<a href=3D"https://github.com/haiyang-yin/otp" target=3D"_blank">https://gi=
thub.com/haiyang-yin/otp</a><br>
<br>
To fetch the patch, refer to following git commands:<br>
<br>
git clone <a href=3D"https://github.com/haiyang-yin/otp.git" target=3D"_bla=
nk">https://github.com/haiyang-yin/otp.git</a><br>
git checkout dtls_patch<br>
</blockquote></blockquote>
&gt;&gt;<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><blockquote class=3D"gmail_quote" style=3D"m=
argin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Here is code review location:<br>
<br>
<a href=3D"https://github.com/haiyang-yin/otp/compare/maint...haiyang-yin:d=
tls_patch" target=3D"_blank">https://github.com/haiyang-yin/otp/compare/mai=
nt...haiyang-yin:dtls_patch</a><br>
<br>
There are two demo programs to show how dtls client/server works in the<br>
attachments.<br>
<br>
Feel free to let me know if further information is needed.<br>
</blockquote></blockquote>
<br></span>
We would prefer if you could make it into a pull-request, or maybe several =
pull-requests. I think the first commit moving functions from tls_connectio=
n into ssl_connection could be one pull-request. That can be considered par=
t of the refactoring work that I was doing in order to make our DTLS-implem=
entation (that I alas have not=C2=A0 had time to finish due to other things=
 being prioritized). So we could include that as a first step.<br>
<br>
The other parts I and the OTP team will need some more time to think about =
your implementation suggestion. But what ever the conclusion will<br>
be, it is a way to give this issue some more focus, and hopefully move it f=
orward towards a functioning DLTS implementation.<br>
<br>
Regards Ingela Erlang/OTP Team Ericssson AB<br>
<br>
<br>
</blockquote></div><br></div>

--f46d041825e2ff64c605177ee544--

--===============0183598584491916105==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
erlang-patches mailing list
[email protected]
http://erlang.org/mailman/listinfo/erlang-patches

--===============0183598584491916105==--