Line data Source code
1 : /* This Source Code Form is subject to the terms of the Mozilla Public
2 : * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 : * You can obtain one at http://mozilla.org/MPL/2.0/. */
4 :
5 : // Original author: ekr@rtfm.com
6 :
7 : #ifndef srtpflow_h__
8 : #define srtpflow_h__
9 :
10 : #include "ssl.h"
11 : #include "sslproto.h"
12 : #include "mozilla/RefPtr.h"
13 : #include "nsISupportsImpl.h"
14 :
15 : typedef struct srtp_policy_t srtp_policy_t;
16 : typedef struct srtp_ctx_t *srtp_t;
17 : typedef struct srtp_event_data_t srtp_event_data_t;
18 :
19 : namespace mozilla {
20 :
21 : #define SRTP_MASTER_KEY_LENGTH 16
22 : #define SRTP_MASTER_SALT_LENGTH 14
23 : #define SRTP_TOTAL_KEY_LENGTH (SRTP_MASTER_KEY_LENGTH + SRTP_MASTER_SALT_LENGTH)
24 :
25 : // SRTCP requires an auth tag *plus* a 4-byte index-plus-'E'-bit value (see
26 : // RFC 3711)
27 : #define SRTP_MAX_EXPANSION (SRTP_MAX_TRAILER_LEN+4)
28 :
29 :
30 : class SrtpFlow {
31 : ~SrtpFlow();
32 : public:
33 :
34 :
35 : static RefPtr<SrtpFlow> Create(int cipher_suite,
36 : bool inbound,
37 : const void *key,
38 : size_t key_len);
39 :
40 : nsresult ProtectRtp(void *in, int in_len,
41 : int max_len, int *out_len);
42 : nsresult UnprotectRtp(void *in, int in_len,
43 : int max_len, int *out_len);
44 : nsresult ProtectRtcp(void *in, int in_len,
45 : int max_len, int *out_len);
46 : nsresult UnprotectRtcp(void *in, int in_len,
47 : int max_len, int *out_len);
48 :
49 0 : NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SrtpFlow)
50 :
51 : static void srtp_event_handler(srtp_event_data_t *data);
52 :
53 :
54 : private:
55 0 : SrtpFlow() : session_(nullptr) {}
56 :
57 : nsresult CheckInputs(bool protect, void *in, int in_len,
58 : int max_len, int *out_len);
59 :
60 : static nsresult Init();
61 : static bool initialized; // Was libsrtp initialized? Only happens once.
62 :
63 : srtp_t session_;
64 : };
65 :
66 : } // End of namespace
67 : #endif
68 :
|