2020-03-06 15:01:48 +00:00
|
|
|
/**
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2013-2020 Winlin
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
* this software and associated documentation files (the "Software"), to deal in
|
|
|
|
* the Software without restriction, including without limitation the rights to
|
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
|
* subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2020-05-11 04:07:55 +00:00
|
|
|
#ifndef SRS_APP_RTC_DTLS_HPP
|
|
|
|
#define SRS_APP_RTC_DTLS_HPP
|
2020-03-06 15:01:48 +00:00
|
|
|
|
|
|
|
#include <srs_core.hpp>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2020-04-03 07:03:09 +00:00
|
|
|
class SrsRequest;
|
|
|
|
|
2020-03-06 15:01:48 +00:00
|
|
|
#include <openssl/ssl.h>
|
|
|
|
|
2020-06-24 12:03:21 +00:00
|
|
|
class SrsDtlsCertificate
|
2020-03-06 15:01:48 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
std::string fingerprint;
|
2020-06-24 12:03:21 +00:00
|
|
|
bool ecdsa_mode;
|
2020-06-24 09:09:26 +00:00
|
|
|
X509* dtls_cert;
|
|
|
|
EVP_PKEY* dtls_pkey;
|
|
|
|
EC_KEY* eckey;
|
2020-06-24 12:03:21 +00:00
|
|
|
public:
|
|
|
|
SrsDtlsCertificate();
|
|
|
|
virtual ~SrsDtlsCertificate();
|
|
|
|
public:
|
|
|
|
// Initialize DTLS certificate.
|
|
|
|
srs_error_t initialize();
|
|
|
|
// dtls_cert
|
|
|
|
X509* get_cert();
|
|
|
|
// public key
|
|
|
|
EVP_PKEY* get_public_key();
|
|
|
|
// ECDSA key
|
|
|
|
EC_KEY* get_ecdsa_key();
|
|
|
|
// certificate fingerprint
|
|
|
|
std::string get_fingerprint();
|
|
|
|
// whether is ecdsa
|
|
|
|
bool is_ecdsa();
|
|
|
|
};
|
|
|
|
|
2020-06-24 12:21:36 +00:00
|
|
|
// @global config object.
|
|
|
|
extern SrsDtlsCertificate* _srs_rtc_dtls_certificate;
|
2020-06-24 12:03:21 +00:00
|
|
|
|
2020-06-25 04:03:21 +00:00
|
|
|
class ISrsDtlsCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ISrsDtlsCallback();
|
|
|
|
virtual ~ISrsDtlsCallback();
|
|
|
|
public:
|
|
|
|
// DTLS handshake done callback.
|
|
|
|
virtual srs_error_t on_dtls_handshake_done() = 0;
|
|
|
|
// DTLS receive application data callback.
|
|
|
|
virtual srs_error_t on_dtls_application_data(const char* data, const int len) = 0;
|
|
|
|
// DTLS write dtls data.
|
|
|
|
virtual srs_error_t write_dtls_data(void* data, int size) = 0;
|
|
|
|
};
|
|
|
|
|
2020-06-24 12:03:21 +00:00
|
|
|
class SrsDtls
|
|
|
|
{
|
2020-06-25 04:03:21 +00:00
|
|
|
private:
|
|
|
|
SSL_CTX* dtls_ctx;
|
|
|
|
SSL* dtls;
|
|
|
|
BIO* bio_in;
|
|
|
|
BIO* bio_out;
|
|
|
|
|
|
|
|
ISrsDtlsCallback* callback;
|
|
|
|
|
|
|
|
bool handshake_done;
|
2020-06-24 12:21:36 +00:00
|
|
|
public:
|
2020-06-25 04:03:21 +00:00
|
|
|
SrsDtls(ISrsDtlsCallback* callback);
|
2020-03-06 15:01:48 +00:00
|
|
|
virtual ~SrsDtls();
|
|
|
|
public:
|
2020-06-25 04:03:21 +00:00
|
|
|
srs_error_t initialize(SrsRequest* r);
|
|
|
|
srs_error_t do_handshake();
|
|
|
|
srs_error_t on_dtls(char* data, int nb_data);
|
|
|
|
srs_error_t export_keying_material(unsigned char *out, size_t olen, const char *label, size_t llen, const unsigned char *p, size_t plen, int use_context);
|
|
|
|
private:
|
|
|
|
SSL_CTX* build_dtls_ctx();
|
|
|
|
srs_error_t handshake();
|
2020-03-06 15:01:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|