sdp: gstmikey: gst_mikey_message_to_caps: extract ROC from first crypto session
authorBart Van Severen <bart.vanseveren@barco.com>
Wed, 14 Dec 2022 09:29:27 +0000 (10:29 +0100)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Fri, 27 Jan 2023 01:58:48 +0000 (01:58 +0000)
We need the ROC to decrypt a SRTP stream as the ROC is part of the AES IV.
So look for first crypto session, from which we can get the ROC and find corresponding
crypto policy.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3818>

subprojects/gst-plugins-base/gst-libs/gst/sdp/gstmikey.c

index ea362c8..00a2b68 100644 (file)
@@ -2377,6 +2377,7 @@ gboolean
 gst_mikey_message_to_caps (const GstMIKEYMessage * msg, GstCaps * caps)
 {
   gboolean res = FALSE;
+  const GstMIKEYMapSRTP *srtp;
   const GstMIKEYPayload *payload;
   const gchar *srtp_cipher;
   const gchar *srtp_auth;
@@ -2384,8 +2385,16 @@ gst_mikey_message_to_caps (const GstMIKEYMessage * msg, GstCaps * caps)
   srtp_cipher = "aes-128-icm";
   srtp_auth = "hmac-sha1-80";
 
-  /* check the Security policy if any */
-  if ((payload = gst_mikey_message_find_payload (msg, GST_MIKEY_PT_SP, 0))) {
+  /* Look for first crypto session */
+  if (!(srtp = gst_mikey_message_get_cs_srtp (msg, 0))) {
+    GST_ERROR ("No crypto session found at index 0");
+    goto done;
+  }
+
+  /* Look for crypto policy corresponding to first crypto session */
+  if ((payload =
+          gst_mikey_message_find_payload (msg, GST_MIKEY_PT_SP,
+              (unsigned int) srtp->policy))) {
     GstMIKEYPayloadSP *p = (GstMIKEYPayloadSP *) payload;
     guint len, i;
     guint enc_alg = GST_MIKEY_ENC_NULL;
@@ -2493,6 +2502,8 @@ gst_mikey_message_to_caps (const GstMIKEYMessage * msg, GstCaps * caps)
     buf = gst_buffer_new_memdup (pkd->key_data, pkd->key_len);
     gst_caps_set_simple (caps, "srtp-key", GST_TYPE_BUFFER, buf, NULL);
     gst_buffer_unref (buf);
+
+    gst_caps_set_simple (caps, "roc", G_TYPE_UINT, srtp->roc, NULL);
   }
 
   gst_caps_set_simple (caps,