Bug 1230759: Part 3 - changes to signaling to work with libsrtp 2.2 draft
authorNils Ohlmeier [:drno] <drno@ohlmeier.org>
Tue, 07 Nov 2017 22:04:23 -0800
changeset 702422 3422f12cfb42ab7d96e9dfa285c0dffa8b9d19d2
parent 702421 a8ed8252fdce6f6a8ab1e3b97255ea0408f52c4d
child 702423 2dab6f228b116d6304dc47202103ae5c1eb4448f
push id90487
push userdrno@ohlmeier.org
push dateThu, 23 Nov 2017 07:07:55 +0000
bugs1230759
milestone59.0a1
Bug 1230759: Part 3 - changes to signaling to work with libsrtp 2.2 MozReview-Commit-ID: BHyoeIyQOJy
media/webrtc/signaling/gtest/moz.build
media/webrtc/signaling/src/mediapipeline/SrtpFlow.cpp
media/webrtc/signaling/src/mediapipeline/SrtpFlow.h
media/webrtc/signaling/src/peerconnection/moz.build
--- a/media/webrtc/signaling/gtest/moz.build
+++ b/media/webrtc/signaling/gtest/moz.build
@@ -15,16 +15,17 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'uiki
       '/media/mtransport/third_party/nrappkit/src/registry',
       '/media/webrtc/',
       '/media/webrtc/signaling/src/common',
       '/media/webrtc/signaling/src/common/time_profiling',
       '/media/webrtc/signaling/src/media-conduit',
       '/media/webrtc/signaling/src/mediapipeline',
       '/media/webrtc/signaling/src/peerconnection',
       '/media/webrtc/trunk',
+      '/netwerk/srtp/src/include',
     ]
 
     SOURCES += [
         'jsep_session_unittest.cpp',
         'jsep_track_unittest.cpp',
         'mediaconduit_unittests.cpp',
         'sdp_unittests.cpp',
         'videoconduit_unittests.cpp',
--- a/media/webrtc/signaling/src/mediapipeline/SrtpFlow.cpp
+++ b/media/webrtc/signaling/src/mediapipeline/SrtpFlow.cpp
@@ -55,24 +55,24 @@ RefPtr<SrtpFlow> SrtpFlow::Create(int ci
   memset(&policy, 0, sizeof(srtp_policy_t));
 
   // Note that we set the same cipher suite for RTP and RTCP
   // since any flow can only have one cipher suite with DTLS-SRTP
   switch (cipher_suite) {
     case SRTP_AES128_CM_HMAC_SHA1_80:
       CSFLogDebug(LOGTAG,
                   "Setting SRTP cipher suite SRTP_AES128_CM_HMAC_SHA1_80");
-      crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtp);
-      crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp);
+      srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtp);
+      srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp);
       break;
     case SRTP_AES128_CM_HMAC_SHA1_32:
       CSFLogDebug(LOGTAG,
                   "Setting SRTP cipher suite SRTP_AES128_CM_HMAC_SHA1_32");
-      crypto_policy_set_aes_cm_128_hmac_sha1_32(&policy.rtp);
-      crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp); // 80-bit per RFC 5764
+      srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32(&policy.rtp);
+      srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp); // 80-bit per RFC 5764
       break;                                                   // S 4.1.2.
     default:
       CSFLogError(LOGTAG, "Request to set unknown SRTP cipher suite");
       return nullptr;
   }
   // This key is copied into the srtp_t object, so we don't
   // need to keep it.
   policy.key = const_cast<unsigned char *>(
@@ -80,18 +80,18 @@ RefPtr<SrtpFlow> SrtpFlow::Create(int ci
   policy.ssrc.type = inbound ? ssrc_any_inbound : ssrc_any_outbound;
   policy.ssrc.value = 0;
   policy.ekt = nullptr;
   policy.window_size = 1024;   // Use the Chrome value.  Needs to be revisited.  Default is 128
   policy.allow_repeat_tx = 1;  // Use Chrome value; needed for NACK mode to work
   policy.next = nullptr;
 
   // Now make the session
-  err_status_t r = srtp_create(&flow->session_, &policy);
-  if (r != err_status_ok) {
+  srtp_err_status_t r = srtp_create(&flow->session_, &policy);
+  if (r != srtp_err_status_ok) {
     CSFLogError(LOGTAG, "Error creating srtp session");
     return nullptr;
   }
 
   return flow;
 }
 
 
@@ -132,19 +132,19 @@ nsresult SrtpFlow::CheckInputs(bool prot
 
 nsresult SrtpFlow::ProtectRtp(void *in, int in_len,
                               int max_len, int *out_len) {
   nsresult res = CheckInputs(true, in, in_len, max_len, out_len);
   if (NS_FAILED(res))
     return res;
 
   int len = in_len;
-  err_status_t r = srtp_protect(session_, in, &len);
+  srtp_err_status_t r = srtp_protect(session_, in, &len);
 
-  if (r != err_status_ok) {
+  if (r != srtp_err_status_ok) {
     CSFLogError(LOGTAG, "Error protecting SRTP packet");
     return NS_ERROR_FAILURE;
   }
 
   MOZ_ASSERT(len <= max_len);
   *out_len = len;
 
 
@@ -156,19 +156,19 @@ nsresult SrtpFlow::ProtectRtp(void *in, 
 
 nsresult SrtpFlow::UnprotectRtp(void *in, int in_len,
                                 int max_len, int *out_len) {
   nsresult res = CheckInputs(false, in, in_len, max_len, out_len);
   if (NS_FAILED(res))
     return res;
 
   int len = in_len;
-  err_status_t r = srtp_unprotect(session_, in, &len);
+  srtp_err_status_t r = srtp_unprotect(session_, in, &len);
 
-  if (r != err_status_ok) {
+  if (r != srtp_err_status_ok) {
     CSFLogError(LOGTAG, "Error unprotecting SRTP packet error=%d", (int)r);
     return NS_ERROR_FAILURE;
   }
 
   MOZ_ASSERT(len <= max_len);
   *out_len = len;
 
   CSFLogDebug(LOGTAG, "Successfully unprotected an SRTP packet of len %d",
@@ -179,19 +179,19 @@ nsresult SrtpFlow::UnprotectRtp(void *in
 
 nsresult SrtpFlow::ProtectRtcp(void *in, int in_len,
                                int max_len, int *out_len) {
   nsresult res = CheckInputs(true, in, in_len, max_len, out_len);
   if (NS_FAILED(res))
     return res;
 
   int len = in_len;
-  err_status_t r = srtp_protect_rtcp(session_, in, &len);
+  srtp_err_status_t r = srtp_protect_rtcp(session_, in, &len);
 
-  if (r != err_status_ok) {
+  if (r != srtp_err_status_ok) {
     CSFLogError(LOGTAG, "Error protecting SRTCP packet");
     return NS_ERROR_FAILURE;
   }
 
   MOZ_ASSERT(len <= max_len);
   *out_len = len;
 
   CSFLogDebug(LOGTAG, "Successfully protected an SRTCP packet of len %d",
@@ -202,19 +202,19 @@ nsresult SrtpFlow::ProtectRtcp(void *in,
 
 nsresult SrtpFlow::UnprotectRtcp(void *in, int in_len,
                                  int max_len, int *out_len) {
   nsresult res = CheckInputs(false, in, in_len, max_len, out_len);
   if (NS_FAILED(res))
     return res;
 
   int len = in_len;
-  err_status_t r = srtp_unprotect_rtcp(session_, in, &len);
+  srtp_err_status_t r = srtp_unprotect_rtcp(session_, in, &len);
 
-  if (r != err_status_ok) {
+  if (r != srtp_err_status_ok) {
     CSFLogError(LOGTAG, "Error unprotecting SRTCP packet error=%d", (int)r);
     return NS_ERROR_FAILURE;
   }
 
   MOZ_ASSERT(len <= max_len);
   *out_len = len;
 
   CSFLogDebug(LOGTAG, "Successfully unprotected an SRTCP packet of len %d",
@@ -226,25 +226,25 @@ nsresult SrtpFlow::UnprotectRtcp(void *i
 // Statics
 void SrtpFlow::srtp_event_handler(srtp_event_data_t *data) {
   // TODO(ekr@rtfm.com): Implement this
   MOZ_CRASH();
 }
 
 nsresult SrtpFlow::Init() {
   if (!initialized) {
-    err_status_t r = srtp_init();
-    if (r != err_status_ok) {
+    srtp_err_status_t r = srtp_init();
+    if (r != srtp_err_status_ok) {
       CSFLogError(LOGTAG, "Could not initialize SRTP");
       MOZ_ASSERT(PR_FALSE);
       return NS_ERROR_FAILURE;
     }
 
     r = srtp_install_event_handler(&SrtpFlow::srtp_event_handler);
-    if (r != err_status_ok) {
+    if (r != srtp_err_status_ok) {
       CSFLogError(LOGTAG, "Could not install SRTP event handler");
       MOZ_ASSERT(PR_FALSE);
       return NS_ERROR_FAILURE;
     }
 
     initialized = true;
   }
 
--- a/media/webrtc/signaling/src/mediapipeline/SrtpFlow.h
+++ b/media/webrtc/signaling/src/mediapipeline/SrtpFlow.h
@@ -6,20 +6,17 @@
 
 #ifndef srtpflow_h__
 #define srtpflow_h__
 
 #include "ssl.h"
 #include "sslproto.h"
 #include "mozilla/RefPtr.h"
 #include "nsISupportsImpl.h"
-
-typedef struct srtp_policy_t srtp_policy_t;
-typedef struct srtp_ctx_t *srtp_t;
-typedef struct srtp_event_data_t srtp_event_data_t;
+#include "srtp.h"
 
 namespace mozilla {
 
 #define SRTP_MASTER_KEY_LENGTH 16
 #define SRTP_MASTER_SALT_LENGTH 14
 #define SRTP_TOTAL_KEY_LENGTH (SRTP_MASTER_KEY_LENGTH + SRTP_MASTER_SALT_LENGTH)
 
 // SRTCP requires an auth tag *plus* a 4-byte index-plus-'E'-bit value (see
--- a/media/webrtc/signaling/src/peerconnection/moz.build
+++ b/media/webrtc/signaling/src/peerconnection/moz.build
@@ -13,16 +13,17 @@ LOCAL_INCLUDES += [
     '/media/mtransport',
     '/media/webrtc',
     '/media/webrtc/signaling/src/common',
     '/media/webrtc/signaling/src/common/browser_logging',
     '/media/webrtc/signaling/src/common/time_profiling',
     '/media/webrtc/signaling/src/media-conduit',
     '/media/webrtc/signaling/src/mediapipeline',
     '/media/webrtc/trunk',
+    '/netwerk/srtp/src/include',
 ]
 
 UNIFIED_SOURCES += [
     'MediaPipelineFactory.cpp',
     'MediaStreamList.cpp',
     'PacketDumper.cpp',
     'PeerConnectionCtx.cpp',
     'PeerConnectionImpl.cpp',