From 56781517996fc54f217cee69925addb837643ae0 Mon Sep 17 00:00:00 2001 From: Bart Van Severen Date: Wed, 14 Dec 2022 10:29:27 +0100 Subject: [PATCH] sdp: gstmikey: gst_mikey_message_to_caps: extract ROC from first crypto session 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: --- .../gst-plugins-base/gst-libs/gst/sdp/gstmikey.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/subprojects/gst-plugins-base/gst-libs/gst/sdp/gstmikey.c b/subprojects/gst-plugins-base/gst-libs/gst/sdp/gstmikey.c index e6d97ca10a..b0c3a2b89f 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/sdp/gstmikey.c +++ b/subprojects/gst-plugins-base/gst-libs/gst/sdp/gstmikey.c @@ -2379,6 +2379,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; @@ -2386,8 +2387,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; @@ -2495,6 +2504,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,