|
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 // For some reason libsrtp increases packet size by > 12 for RTCP even though |
|
26 // the doc claims otherwise. |
|
27 #define SRTP_MAX_EXPANSION 20 |
|
28 |
|
29 |
|
30 class SrtpFlow { |
|
31 public: |
|
32 ~SrtpFlow(); |
|
33 |
|
34 |
|
35 static mozilla::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 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SrtpFlow) |
|
50 |
|
51 static void srtp_event_handler(srtp_event_data_t *data); |
|
52 |
|
53 |
|
54 private: |
|
55 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 |