Skip to content
Snippets Groups Projects
Select Git revision
  • 0369159e8e007b4dbef98a78d21a9cf9a38b14ed
  • master default protected
  • release/202005
  • release/202001
  • release/201912
  • release/201911
  • release/releaseWindowsTestOne
  • release/windowsReleaseTest
  • release/releaseTest
  • release/releaseWindowsTest
  • release/201910
  • release/qt/201910
  • release/windows-test/201910
  • release/201908
  • release/201906
  • release/201905
  • release/201904
  • release/201903
  • release/201902
  • release/201901
  • release/201812
  • 4.0.0
  • 2.2.0
  • 2.1.0
  • 2.0.1
  • 2.0.0
  • 1.4.1
  • 1.4.0
  • 1.3.0
  • 1.2.0
  • 1.1.0
31 results

fileutils.h

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    tls_session.cpp 27.18 KiB
    /*
     *  Copyright (C) 2004-2016 Savoir-faire Linux Inc.
     *
     *  Author: Adrien Béraud <adrien.beraud@savoirfairelinux.com>
     *  Author: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
     *
     *  This program is free software; you can redistribute it and/or modify
     *  it under the terms of the GNU General Public License as published by
     *  the Free Software Foundation; either version 3 of the License, or
     *  (at your option) any later version.
     *
     *  This program is distributed in the hope that it will be useful,
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     *  GNU General Public License for more details.
     *
     *  You should have received a copy of the GNU General Public License
     *  along with this program; if not, write to the Free Software
     *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
     */
    
    #include <ip_utils.h>       // DO NOT CHANGE ORDER OF THIS INCLUDE
    #include <opendht/crypto.h> // OR MINGWIN FAILS TO BUILD
    
    #include "tls_session.h"
    
    #include "ice_socket.h"
    #include "ice_transport.h"
    #include "logger.h"
    #include "noncopyable.h"
    #include "compiler_intrinsics.h"
    
    #include <gnutls/dtls.h>
    #include <gnutls/abstract.h>
    
    #include <algorithm>
    #include <cstring> // std::memset
    
    namespace ring { namespace tls {
    
    static constexpr const char* TLS_CERT_PRIORITY_STRING {"SECURE192:-VERS-TLS-ALL:+VERS-DTLS-ALL:-RSA:%SERVER_PRECEDENCE:%SAFE_RENEGOTIATION"};
    static constexpr const char* TLS_FULL_PRIORITY_STRING {"SECURE192:-KX-ALL:+ANON-ECDH:+ANON-DH:+SECURE192:-VERS-TLS-ALL:+VERS-DTLS-ALL:-RSA:%SERVER_PRECEDENCE:%SAFE_RENEGOTIATION"};
    static constexpr int DTLS_MTU {1232}; // (1280 from IPv6 minimum MTU - 40 IPv6 header - 8 UDP header)
    static constexpr std::size_t INPUT_MAX_SIZE {1000}; // Maximum packet to store before dropping (pkt size = DTLS_MTU)
    static constexpr ssize_t FLOOD_THRESHOLD {4*1024};
    static constexpr auto FLOOD_PAUSE = std::chrono::milliseconds(100); // Time to wait after an invalid cookie packet (anti flood attack)
    static constexpr auto DTLS_RETRANSMIT_TIMEOUT = std::chrono::milliseconds(1000); // Delay between two handshake request on DTLS
    static constexpr auto COOKIE_TIMEOUT = std::chrono::seconds(10); // Time to wait for a cookie packet from client
    
    // Helper to cast any duration into an integer number of milliseconds
    template <class Rep, class Period>
    static std::chrono::milliseconds::rep
    duration2ms(std::chrono::duration<Rep, Period> d)
    {
        return std::chrono::duration_cast<std::chrono::milliseconds>(d).count();
    }
    
    DhParams::DhParams(const std::vector<uint8_t>& data)
    {
        gnutls_dh_params_t new_params_;
        int ret = gnutls_dh_params_init(&new_params_);
        if (ret)
            throw std::runtime_error(std::string("Error initializing DH params: ") + gnutls_strerror(ret));
        params_.reset(new_params_);
        const gnutls_datum_t dat {(uint8_t*)data.data(), (unsigned)data.size()};
        if (int ret_pem = gnutls_dh_params_import_pkcs3(params_.get(), &dat, GNUTLS_X509_FMT_PEM))
            if (int ret_der = gnutls_dh_params_import_pkcs3(params_.get(), &dat, GNUTLS_X509_FMT_DER))
                throw std::runtime_error(std::string("Error importing DH params: ") + gnutls_strerror(ret_pem) + " " + gnutls_strerror(ret_der));
    }