mikey: allow passing srtp or srtcp to create mikey message

Current implementation requires all srtp and srtcp parameters to be
given in the caps. MIKEY uses only one algorithm for encryption and one
for authentication so we now allow passing srtp or srtcp parameters. If
both are given srtp parametres will be preferred.

https://bugzilla.gnome.org/show_bug.cgi?id=765027
This commit is contained in:
Aleix Conchillo Flaqué 2016-04-14 17:26:54 -07:00 committed by Josep Torra
parent cf63a900a9
commit 62e0e74759

View file

@ -2204,6 +2204,7 @@ gst_mikey_message_new_from_caps (GstCaps * caps)
GstMapInfo info; GstMapInfo info;
GstBuffer *srtpkey; GstBuffer *srtpkey;
const GValue *val; const GValue *val;
const gchar *cipher, *auth;
const gchar *srtpcipher, *srtpauth, *srtcpcipher, *srtcpauth; const gchar *srtpcipher, *srtpauth, *srtcpcipher, *srtcpauth;
g_return_val_if_fail (caps != NULL && GST_IS_CAPS (caps), NULL); g_return_val_if_fail (caps != NULL && GST_IS_CAPS (caps), NULL);
@ -2224,12 +2225,23 @@ gst_mikey_message_new_from_caps (GstCaps * caps)
srtcpcipher = gst_structure_get_string (s, "srtcp-cipher"); srtcpcipher = gst_structure_get_string (s, "srtcp-cipher");
srtcpauth = gst_structure_get_string (s, "srtcp-auth"); srtcpauth = gst_structure_get_string (s, "srtcp-auth");
if (srtpcipher == NULL || srtpauth == NULL || srtcpcipher == NULL || /* we need srtp cipher/auth or srtcp cipher/auth */
srtcpauth == NULL) { if ((srtpcipher == NULL || srtpauth == NULL)
&& (srtcpcipher == NULL || srtcpauth == NULL)) {
GST_WARNING ("could not find the right SRTP parameters in caps"); GST_WARNING ("could not find the right SRTP parameters in caps");
return NULL; return NULL;
} }
/* prefer srtp cipher over srtcp */
cipher = srtpcipher;
if (cipher == NULL)
cipher = srtcpcipher;
/* prefer srtp auth over srtcp */
auth = srtpauth;
if (auth == NULL)
auth = srtcpauth;
msg = gst_mikey_message_new (); msg = gst_mikey_message_new ();
/* unencrypted MIKEY message, we send this over TLS so this is allowed */ /* unencrypted MIKEY message, we send this over TLS so this is allowed */
gst_mikey_message_set_info (msg, GST_MIKEY_VERSION, GST_MIKEY_TYPE_PSK_INIT, gst_mikey_message_set_info (msg, GST_MIKEY_VERSION, GST_MIKEY_TYPE_PSK_INIT,
@ -2248,14 +2260,14 @@ gst_mikey_message_new_from_caps (GstCaps * caps)
byte = 1; byte = 1;
gst_mikey_payload_sp_add_param (payload, GST_MIKEY_SP_SRTP_ENC_ALG, 1, &byte); gst_mikey_payload_sp_add_param (payload, GST_MIKEY_SP_SRTP_ENC_ALG, 1, &byte);
/* encryption key length */ /* encryption key length */
byte = enc_key_length_from_cipher_name (srtpcipher); byte = enc_key_length_from_cipher_name (cipher);
gst_mikey_payload_sp_add_param (payload, GST_MIKEY_SP_SRTP_ENC_KEY_LEN, 1, gst_mikey_payload_sp_add_param (payload, GST_MIKEY_SP_SRTP_ENC_KEY_LEN, 1,
&byte); &byte);
/* only HMAC-SHA1 */ /* only HMAC-SHA1 */
gst_mikey_payload_sp_add_param (payload, GST_MIKEY_SP_SRTP_AUTH_ALG, 1, gst_mikey_payload_sp_add_param (payload, GST_MIKEY_SP_SRTP_AUTH_ALG, 1,
&byte); &byte);
/* authentication key length */ /* authentication key length */
byte = auth_key_length_from_auth_name (srtpauth); byte = auth_key_length_from_auth_name (auth);
gst_mikey_payload_sp_add_param (payload, GST_MIKEY_SP_SRTP_AUTH_KEY_LEN, 1, gst_mikey_payload_sp_add_param (payload, GST_MIKEY_SP_SRTP_AUTH_KEY_LEN, 1,
&byte); &byte);
/* we enable encryption on RTP and RTCP */ /* we enable encryption on RTP and RTCP */