| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  *  Copyright 2009 The WebRTC project authors. All Rights Reserved. | 2  *  Copyright 2009 The WebRTC project authors. All Rights Reserved. | 
| 3  * | 3  * | 
| 4  *  Use of this source code is governed by a BSD-style license | 4  *  Use of this source code is governed by a BSD-style license | 
| 5  *  that can be found in the LICENSE file in the root of the source | 5  *  that can be found in the LICENSE file in the root of the source | 
| 6  *  tree. An additional intellectual property rights grant can be found | 6  *  tree. An additional intellectual property rights grant can be found | 
| 7  *  in the file PATENTS.  All contributing project authors may | 7  *  in the file PATENTS.  All contributing project authors may | 
| 8  *  be found in the AUTHORS file in the root of the source tree. | 8  *  be found in the AUTHORS file in the root of the source tree. | 
| 9  */ | 9  */ | 
| 10 | 10 | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 26 #include "webrtc/media/base/cryptoparams.h" | 26 #include "webrtc/media/base/cryptoparams.h" | 
| 27 #include "webrtc/p2p/base/sessiondescription.h" | 27 #include "webrtc/p2p/base/sessiondescription.h" | 
| 28 | 28 | 
| 29 // Forward declaration to avoid pulling in libsrtp headers here | 29 // Forward declaration to avoid pulling in libsrtp headers here | 
| 30 struct srtp_event_data_t; | 30 struct srtp_event_data_t; | 
| 31 struct srtp_ctx_t; | 31 struct srtp_ctx_t; | 
| 32 struct srtp_policy_t; | 32 struct srtp_policy_t; | 
| 33 | 33 | 
| 34 namespace cricket { | 34 namespace cricket { | 
| 35 | 35 | 
| 36 // Key is 128 bits and salt is 112 bits == 30 bytes. B64 bloat => 40 bytes. |  | 
| 37 extern const int SRTP_MASTER_KEY_BASE64_LEN; |  | 
| 38 |  | 
| 39 // Needed for DTLS-SRTP |  | 
| 40 extern const int SRTP_MASTER_KEY_KEY_LEN; |  | 
| 41 extern const int SRTP_MASTER_KEY_SALT_LEN; |  | 
| 42 |  | 
| 43 class SrtpSession; | 36 class SrtpSession; | 
| 44 class SrtpStat; | 37 class SrtpStat; | 
| 45 | 38 | 
| 46 void EnableSrtpDebugging(); | 39 void EnableSrtpDebugging(); | 
| 47 void ShutdownSrtp(); | 40 void ShutdownSrtp(); | 
| 48 | 41 | 
| 49 // Class to transform SRTP to/from RTP. | 42 // Class to transform SRTP to/from RTP. | 
| 50 // Initialize by calling SetSend with the local security params, then call | 43 // Initialize by calling SetSend with the local security params, then call | 
| 51 // SetRecv once the remote security params are received. At that point | 44 // SetRecv once the remote security params are received. At that point | 
| 52 // Protect/UnprotectRt(c)p can be called to encrypt/decrypt data. | 45 // Protect/UnprotectRt(c)p can be called to encrypt/decrypt data. | 
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 133                    ContentSource source); | 126                    ContentSource source); | 
| 134   bool ExpectAnswer(ContentSource source); | 127   bool ExpectAnswer(ContentSource source); | 
| 135   bool DoSetAnswer(const std::vector<CryptoParams>& answer_params, | 128   bool DoSetAnswer(const std::vector<CryptoParams>& answer_params, | 
| 136                      ContentSource source, | 129                      ContentSource source, | 
| 137                      bool final); | 130                      bool final); | 
| 138   void CreateSrtpSessions(); | 131   void CreateSrtpSessions(); | 
| 139   bool NegotiateParams(const std::vector<CryptoParams>& answer_params, | 132   bool NegotiateParams(const std::vector<CryptoParams>& answer_params, | 
| 140                        CryptoParams* selected_params); | 133                        CryptoParams* selected_params); | 
| 141   bool ApplyParams(const CryptoParams& send_params, | 134   bool ApplyParams(const CryptoParams& send_params, | 
| 142                    const CryptoParams& recv_params); | 135                    const CryptoParams& recv_params); | 
| 143   static bool ParseKeyParams(const std::string& params, uint8_t* key, int len); | 136   static bool ParseKeyParams(const std::string& params, | 
|  | 137                              uint8_t* key, | 
|  | 138                              size_t len); | 
| 144 | 139 | 
| 145  private: | 140  private: | 
| 146   enum State { | 141   enum State { | 
| 147     ST_INIT,           // SRTP filter unused. | 142     ST_INIT,           // SRTP filter unused. | 
| 148     ST_SENTOFFER,      // Offer with SRTP parameters sent. | 143     ST_SENTOFFER,      // Offer with SRTP parameters sent. | 
| 149     ST_RECEIVEDOFFER,  // Offer with SRTP parameters received. | 144     ST_RECEIVEDOFFER,  // Offer with SRTP parameters received. | 
| 150     ST_SENTPRANSWER_NO_CRYPTO,  // Sent provisional answer without crypto. | 145     ST_SENTPRANSWER_NO_CRYPTO,  // Sent provisional answer without crypto. | 
| 151     // Received provisional answer without crypto. | 146     // Received provisional answer without crypto. | 
| 152     ST_RECEIVEDPRANSWER_NO_CRYPTO, | 147     ST_RECEIVEDPRANSWER_NO_CRYPTO, | 
| 153     ST_ACTIVE,         // Offer and answer set. | 148     ST_ACTIVE,         // Offer and answer set. | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
| 178 }; | 173 }; | 
| 179 | 174 | 
| 180 // Class that wraps a libSRTP session. | 175 // Class that wraps a libSRTP session. | 
| 181 class SrtpSession { | 176 class SrtpSession { | 
| 182  public: | 177  public: | 
| 183   SrtpSession(); | 178   SrtpSession(); | 
| 184   ~SrtpSession(); | 179   ~SrtpSession(); | 
| 185 | 180 | 
| 186   // Configures the session for sending data using the specified | 181   // Configures the session for sending data using the specified | 
| 187   // cipher-suite and key. Receiving must be done by a separate session. | 182   // cipher-suite and key. Receiving must be done by a separate session. | 
| 188   bool SetSend(int cs, const uint8_t* key, int len); | 183   bool SetSend(int cs, const uint8_t* key, size_t len); | 
| 189   // Configures the session for receiving data using the specified | 184   // Configures the session for receiving data using the specified | 
| 190   // cipher-suite and key. Sending must be done by a separate session. | 185   // cipher-suite and key. Sending must be done by a separate session. | 
| 191   bool SetRecv(int cs, const uint8_t* key, int len); | 186   bool SetRecv(int cs, const uint8_t* key, size_t len); | 
| 192 | 187 | 
| 193   // Encrypts/signs an individual RTP/RTCP packet, in-place. | 188   // Encrypts/signs an individual RTP/RTCP packet, in-place. | 
| 194   // If an HMAC is used, this will increase the packet size. | 189   // If an HMAC is used, this will increase the packet size. | 
| 195   bool ProtectRtp(void* data, int in_len, int max_len, int* out_len); | 190   bool ProtectRtp(void* data, int in_len, int max_len, int* out_len); | 
| 196   // Overloaded version, outputs packet index. | 191   // Overloaded version, outputs packet index. | 
| 197   bool ProtectRtp(void* data, | 192   bool ProtectRtp(void* data, | 
| 198                   int in_len, | 193                   int in_len, | 
| 199                   int max_len, | 194                   int max_len, | 
| 200                   int* out_len, | 195                   int* out_len, | 
| 201                   int64_t* index); | 196                   int64_t* index); | 
| 202   bool ProtectRtcp(void* data, int in_len, int max_len, int* out_len); | 197   bool ProtectRtcp(void* data, int in_len, int max_len, int* out_len); | 
| 203   // Decrypts/verifies an invidiual RTP/RTCP packet. | 198   // Decrypts/verifies an invidiual RTP/RTCP packet. | 
| 204   // If an HMAC is used, this will decrease the packet size. | 199   // If an HMAC is used, this will decrease the packet size. | 
| 205   bool UnprotectRtp(void* data, int in_len, int* out_len); | 200   bool UnprotectRtp(void* data, int in_len, int* out_len); | 
| 206   bool UnprotectRtcp(void* data, int in_len, int* out_len); | 201   bool UnprotectRtcp(void* data, int in_len, int* out_len); | 
| 207 | 202 | 
| 208   // Helper method to get authentication params. | 203   // Helper method to get authentication params. | 
| 209   bool GetRtpAuthParams(uint8_t** key, int* key_len, int* tag_len); | 204   bool GetRtpAuthParams(uint8_t** key, int* key_len, int* tag_len); | 
| 210 | 205 | 
| 211   // Update the silent threshold (in ms) for signaling errors. | 206   // Update the silent threshold (in ms) for signaling errors. | 
| 212   void set_signal_silent_time(int signal_silent_time_in_ms); | 207   void set_signal_silent_time(int signal_silent_time_in_ms); | 
| 213 | 208 | 
| 214   // Calls srtp_shutdown if it's initialized. | 209   // Calls srtp_shutdown if it's initialized. | 
| 215   static void Terminate(); | 210   static void Terminate(); | 
| 216 | 211 | 
| 217   sigslot::repeater3<uint32_t, SrtpFilter::Mode, SrtpFilter::Error> | 212   sigslot::repeater3<uint32_t, SrtpFilter::Mode, SrtpFilter::Error> | 
| 218       SignalSrtpError; | 213       SignalSrtpError; | 
| 219 | 214 | 
| 220  private: | 215  private: | 
| 221   bool SetKey(int type, int cs, const uint8_t* key, int len); | 216   bool SetKey(int type, int cs, const uint8_t* key, size_t len); | 
| 222     // Returns send stream current packet index from srtp db. | 217     // Returns send stream current packet index from srtp db. | 
| 223   bool GetSendStreamPacketIndex(void* data, int in_len, int64_t* index); | 218   bool GetSendStreamPacketIndex(void* data, int in_len, int64_t* index); | 
| 224 | 219 | 
| 225   static bool Init(); | 220   static bool Init(); | 
| 226   void HandleEvent(const srtp_event_data_t* ev); | 221   void HandleEvent(const srtp_event_data_t* ev); | 
| 227   static void HandleEventThunk(srtp_event_data_t* ev); | 222   static void HandleEventThunk(srtp_event_data_t* ev); | 
| 228 | 223 | 
| 229   rtc::ThreadChecker thread_checker_; | 224   rtc::ThreadChecker thread_checker_; | 
| 230   srtp_ctx_t* session_; | 225   srtp_ctx_t* session_; | 
| 231   int rtp_auth_tag_len_; | 226   int rtp_auth_tag_len_; | 
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 305   std::map<FailureKey, FailureStat> failures_; | 300   std::map<FailureKey, FailureStat> failures_; | 
| 306   // Threshold in ms to silent the signaling errors. | 301   // Threshold in ms to silent the signaling errors. | 
| 307   int signal_silent_time_; | 302   int signal_silent_time_; | 
| 308 | 303 | 
| 309   RTC_DISALLOW_COPY_AND_ASSIGN(SrtpStat); | 304   RTC_DISALLOW_COPY_AND_ASSIGN(SrtpStat); | 
| 310 }; | 305 }; | 
| 311 | 306 | 
| 312 }  // namespace cricket | 307 }  // namespace cricket | 
| 313 | 308 | 
| 314 #endif  // WEBRTC_PC_SRTPFILTER_H_ | 309 #endif  // WEBRTC_PC_SRTPFILTER_H_ | 
| OLD | NEW | 
|---|