Giter VIP home page Giter VIP logo

asio_dtls's Introduction

DTLS support for ASIO using C++11

Introduction

ASIO::DTLS is an extension to ASIO(think-async.com). It provides encryption for Datagram based transports. The encryption is based on DTLS(rfc6347) using the OpenSSL(openssl.org) libraries.

ASIO::DTLS offers dtls_listen functionality which can be used to prevent certain DOS attacks against the Server side (see https://tools.ietf.org/html/rfc4347#section-4.2.1).

Differences between Datagram and Stream based Communication

There are three main differences from a programmer's standpoint between the Stream based and Datagram based Communication approaches:

  • With Stream based communication all data is treated as a Stream so the data of multiple send operations is concatenated and can be received with a single receive operation, as if it was sent by one operation. With Datagram based communication a send operation sends exactly one Datagram and the receiving side a receive operation receives exactly one Datagram, if the Buffer Size on the receiving side was too small to hold the complete Datagram the rest of the Datagram is typically discarded.

  • Streams guarantee that the Data is received in order where Datagrams might be received in a different order than they were sent.

  • Typically, stream based approaches try to make sure the data is delivered and have strategies for retransmission, ... to make sure no data is lost. Datagram based communication generally does not have such a guarantee.

DTLS offers encryption for Datagram based communication and must therefore allow Datagrams to be lost or received in wrong order. It provides the same Datagram semantics, so lost Datagrams will not be resend and out of order Datagrams are still out of order after decryption.

With Stream based protocols the connection establishment does validate (indirectly) that the other end is listening on the sender endpoint. Which as a side effect reduces the possibilities for spoofing attacks, which might be used for Denial-Of-Service/amplifier attacks against DTLS servers (see rfc6347 4.2.1 for details).

Differences between asio::ssl::stream and asio_dtls

To account for the Datagram semantic several changes had to be made:

  • To reflect the Datagram semantic the interface uses the same semantic for sending and receiving as udp i.e.

    • send instead of write_some
    • async_send instead of async_write_some
    • ...
  • set_mtu While the datagram semantics would simply try to send all data provided to a send call in one Datagram and fail if the Datagram is too big there is one exception during the Handshake, where DTLS will split the handshake data akkording to the mtu set here. Please note, that split handshakes do not work together with the stateless Cookie exchange so for udp it makes sense to set this value high and let the ip layer handle the splitting. (The default value is set to do this).

  • Cookies asio_dtls supports dtls Cookies through setting a Cookie generate and verify callback on the server side. These are called whenever the Implementation needs to generate or verify a Cookie. A Cookie should be specific to a client endpoint to fulfill it's purpose.

  • dtls_context instead of a ssl::context A dtls_context allows to use methods like dtls_client which a normal ssl::context does not. A dtls_context does not allow stream based methods like tlsv12_server.

Dependencies

  • Asio (tested with 1.13.0) or Boost (tested with 1.70)
  • OpenSSL > 1.0.2 or
  • OpenSSL > 1.1.0 for correct dtls_listen support
  • cmake >= 3.2

Usage with Boost

Define ASIO_DTLS_USE_BOOST to use the Boost version. The Boost version uses the boost namespaces. So asio::ssl::dtls::context becomes boost::asio::ssl::dtls::context.

Work in Progress

This library is not finished and parts of the Code are copies from Files of ASIO. The structure and some of the files might still change.

asio_dtls's People

Contributors

sdamm avatar wegylexy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

asio_dtls's Issues

Problems with asynchronous model

NIce work, but this code has some defects. In particular, handler helpers passed to initiating functions lose the associated executor and associated allocator. For example, this code is wrong:

template <typename AcceptHandler>

There are also other places which violate Asio preconditions. I suggest reading this composed operation tutorial:
https://www.boost.org/doc/libs/1_68_0/libs/beast/doc/html/beast/using_io/writing_composed_operations.html

Fail to Compile in to DTLS library

Hi All,
I tried to integrate the Boost DTLS in to 1.72 Boost Library. i write own make file to compile. i getting below error. Please guide to write make file properly
CMakeLists.txt

c:\kodiak\releases\lmr-gw-r9.1.1\3rdparty\boost\boost\asio\detail\win_static_mutex.hpp(55): error C2039: 'CRITICAL_SECTION': is not a member of 'global namespace'' [C:\Kodiak\Releases\LMR-GW-R9.1.1\build\3rdparty\boost\boost\asio\ssl\dtls\boost_dtls.vcxproj] c:\kodiak\releases\lmr-gw-r9.1.1\3rdparty\boost\boost\asio\detail\win_static_mutex.hpp(55): error C3646: 'crit_section_': unknown override specifier [C:\Kodiak\Releases\LMR-GW-R9.1.1\build\3rdparty\boost\boost\asio\ssl\dtls\boost_dtls.vcxproj] c:\kodiak\releases\lmr-gw-r9.1.1\3rdparty\boost\boost\asio\detail\win_static_mutex.hpp(55): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int [C:\Kodiak\Releases\LMR-GW-R9.1.1\build\3rdparty\boost\boost\asio\ssl\dtls\boost_dtls.vcxproj] c:\kodiak\releases\lmr-gw-r9.1.1\3rdparty\boost\boost\asio\detail\win_static_mutex.hpp(45): error C2039: 'EnterCriticalSection': is not a member of 'global namespace'' [C:\Kodiak\Releases\LMR-GW-R9.1.1\build\3rdparty\boost\boost\asio\ssl\dtls\boost_dtls.vcxproj]
c:\kodiak\releases\lmr-gw-r9.1.1\3rdparty\boost\boost\asio\detail\win_static_mutex.hpp(45): error C2065: 'crit_section_': undeclared identifier [C:\Kodiak\Releases\LMR-GW-R9.1.1\build\3rdparty\boost\boost\asio\ssl\dtls\boost_dtls.vcxproj]
c:\kodiak\releases\lmr-gw-r9.1.1\3rdparty\boost\boost\asio\detail\win_static_mutex.hpp(45): error C3861: 'EnterCriticalSection': identifier not found [C:\Kodiak\Releases\LMR-GW-R9.1.1\build\3rdparty\boost\boost\asio\ssl\dtls\boost_dtls.vcxproj]

Issue with retransmission during handshake

Hi,
I observe incorrect retransmission behaviors during handshake.

  1. The first case is sending a retransmission when it is not needed because the server response comes in less than 1 second.
    image
    Additionally, the retransmission is sent at a completely unanticipated moment of the handshake.

  2. The second case is not sending the retransmission at the right moment when the server needs more than 1 second to respond.
    image
    Here too, the retransmission is sent at unanticipated moment.

  3. The third case also contains a issue with retransmission but additionally Client dose not respond to the Server Hello Done message.
    image

In my application I use your DTLS code only for DTLS Clients. Server part is an independent application that uses plain OpenSSL in version 1.1.1d.
In the cases described above I use 5 such Clients that try to connect to the server.

I did quite detailed review of your code in search of the issue but failed to find the cause.
Do you have any idea what the issue might be or what I am doing wrong?

Accumulating multiple packets into a single datagram before writing into network.

Hi
I have attached the screenshot of the DTLS Handshake pcap. Here my client certificate of length 3100+ bytes is fragmented to smaller chunks of 1500 bytes(MTU size) and written into the socket. While writing into the network, all packets(fragmented chunks) are accumulated into a single datagram.

And Handshake is failing with error new fragment overlaps the older data.

Please let me know to how to disable the accumulation of multiple packets in to single datagram. i couldn't find the UDP_CORK option here.
Capture

Capture

no cmake install target

When I want to use asio_dtls as a dependency (with hunter) the cmake fails on install target, because it doesn't exist.

DTLS client before server up

Hi All,

I'm into a scenario, where the DTLS client starts and tries handshake before the server comes up. In this handshake fails, I used a timer to call handshake API after the timer expiry. As client tries handshake before the server up, earlier client hello is missed and after timer expiry, it is not starting from the "client hello". Due to this handshake is failing.

Below the flow diagram
3920-06-29 12:27:21.168000] [19936] FRMWRK DtlsClient::doDtlsHandshake called
DEBUG: [3920-06-29 12:27:21.168000] [19936] FRMWRK BaseSslContext::sslInfoCallback(): SSL_connect: before/connect initialization
DEBUG: [3920-06-29 12:27:21.168000] [19936] FRMWRK BaseSslContext::sslInfoCallback(): SSL_connect: SSLv3 write client hello A
DEBUG: [3920-06-29 12:27:21.168000] [19936] FRMWRK BaseSslContext::sslInfoCallback(): SSL_connect: ERROR: SSLv3 read server hello A (-1)
DEBUG: [3920-06-29 12:27:21.168000] [19936] FRMWRK BaseSslContext::sslInfoCallback(): SSL_connect: ERROR: SSLv3 read server hello A (-1)
DEBUG: [3920-06-29 12:27:21.168000] [19936] FRMWRK DtlsClient::Handshak failed with error message 10054 retrying..

after timer expiry of 500msec, by the time DTLS server running called async_handshake, but it is not starting with "client hello"
[3920-06-29 12:27:21.668000] [19936] FRMWRK DtlsClient::doDtlsHandshake called
DEBUG: [3920-06-29 12:27:21.668000] [19936] FRMWRK BaseSslContext::sslInfoCallback(): SSL_connect: ERROR: SSLv3 read server hello A (-1)

How to handle a scenario like this. is there any way to reset the socket before calling the async_handshake once again

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.