2012-10-07 09:34:29 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
// Original author: ekr@rtfm.com
|
|
|
|
|
|
|
|
#ifndef srtpflow_h__
|
|
|
|
#define srtpflow_h__
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2012-10-07 09:34:29 +04:00
|
|
|
#include "nsISupportsImpl.h"
|
2017-11-08 09:04:23 +03:00
|
|
|
#include "srtp.h"
|
2012-10-07 09:34:29 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2018-09-14 06:12:05 +03:00
|
|
|
#define SRTP_ICM_MASTER_KEY_LENGTH 16
|
|
|
|
#define SRTP_ICM_MASTER_SALT_LENGTH 14
|
2018-10-16 06:30:57 +03:00
|
|
|
#define SRTP_ICM_MAX_MASTER_LENGTH \
|
|
|
|
(SRTP_ICM_MASTER_KEY_LENGTH + SRTP_ICM_MASTER_SALT_LENGTH)
|
|
|
|
|
|
|
|
#define SRTP_GCM_MASTER_KEY_MIN_LENGTH 16
|
|
|
|
#define SRTP_GCM_MASTER_KEY_MAX_LENGTH 32
|
2018-09-14 06:12:05 +03:00
|
|
|
#define SRTP_GCM_MASTER_SALT_LENGTH 12
|
|
|
|
|
2018-10-16 06:30:57 +03:00
|
|
|
#define SRTP_GCM_MIN_MASTER_LENGTH \
|
|
|
|
(SRTP_GCM_MASTER_KEY_MIN_LENGTH + SRTP_GCM_MASTER_SALT_LENGTH)
|
|
|
|
#define SRTP_GCM_MAX_MASTER_LENGTH \
|
|
|
|
(SRTP_GCM_MASTER_KEY_MAX_LENGTH + SRTP_GCM_MASTER_SALT_LENGTH)
|
|
|
|
|
|
|
|
#define SRTP_MIN_KEY_LENGTH SRTP_GCM_MIN_MASTER_LENGTH
|
|
|
|
#define SRTP_MAX_KEY_LENGTH SRTP_GCM_MAX_MASTER_LENGTH
|
2012-10-07 09:34:29 +04:00
|
|
|
|
2015-06-05 22:16:45 +03:00
|
|
|
// SRTCP requires an auth tag *plus* a 4-byte index-plus-'E'-bit value (see
|
|
|
|
// RFC 3711)
|
|
|
|
#define SRTP_MAX_EXPANSION (SRTP_MAX_TRAILER_LEN + 4)
|
2012-10-07 09:34:29 +04:00
|
|
|
|
|
|
|
class SrtpFlow {
|
|
|
|
~SrtpFlow();
|
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
public:
|
2018-09-14 06:12:05 +03:00
|
|
|
static unsigned int KeySize(int cipher_suite);
|
|
|
|
static unsigned int SaltSize(int cipher_suite);
|
2012-10-07 09:34:29 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
static RefPtr<SrtpFlow> Create(int cipher_suite, bool inbound,
|
2012-10-07 09:34:29 +04:00
|
|
|
const void* key, size_t key_len);
|
|
|
|
|
|
|
|
nsresult ProtectRtp(void* in, int in_len, int max_len, int* out_len);
|
|
|
|
nsresult UnprotectRtp(void* in, int in_len, int max_len, int* out_len);
|
|
|
|
nsresult ProtectRtcp(void* in, int in_len, int max_len, int* out_len);
|
|
|
|
nsresult UnprotectRtcp(void* in, int in_len, int max_len, int* out_len);
|
|
|
|
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SrtpFlow)
|
|
|
|
|
|
|
|
static void srtp_event_handler(srtp_event_data_t* data);
|
|
|
|
|
|
|
|
private:
|
2013-11-25 23:05:03 +04:00
|
|
|
SrtpFlow() : session_(nullptr) {}
|
2012-10-07 09:34:29 +04:00
|
|
|
|
|
|
|
nsresult CheckInputs(bool protect, void* in, int in_len, int max_len,
|
|
|
|
int* out_len);
|
|
|
|
|
|
|
|
static nsresult Init();
|
2012-10-07 09:34:29 +04:00
|
|
|
static bool initialized; // Was libsrtp initialized? Only happens once.
|
2012-10-07 09:34:29 +04:00
|
|
|
|
|
|
|
srtp_t session_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
#endif
|