]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Do not succeed if no MKI was received.
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Tue, 6 Nov 2012 22:19:50 +0000 (23:19 +0100)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Tue, 6 Nov 2012 22:19:58 +0000 (23:19 +0100)
The gnutls_srtp_get_mki() function succeeds only when the MKI was received by the peer.
Also store the received MKI -if any- in the session resumption data.

lib/ext/srtp.c
lib/ext/srtp.h

index 0dc7cf18eb268266eab03e0f5f401411af5aa130..f4e86810d9707269020280d7ec9653d4d75d4dba 100644 (file)
@@ -234,6 +234,7 @@ _gnutls_srtp_recv_params (gnutls_session_t session,
     {
       DECR_LEN (data_size, priv->mki_size);
       memcpy(priv->mki, p, priv->mki_size);
+      priv->mki_received = 1;
     }
 
   return 0;
@@ -343,8 +344,8 @@ gnutls_srtp_get_selected_profile (gnutls_session_t session,
  * @mki: will hold the MKI
  *
  * This function exports the negotiated Master Key Identifier,
- * if any. The returned value in @mki should be treated as
- * constant and valid only during the session's lifetime.
+ * received by the peer if any. The returned value in @mki should be 
+ * treated as constant and valid only during the session's lifetime.
  *
  * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned,
  *   otherwise a negative error code is returned.
@@ -363,12 +364,12 @@ gnutls_srtp_get_mki (gnutls_session_t session,
     _gnutls_ext_get_session_data (session, GNUTLS_EXTENSION_SRTP,
                                   &epriv);
   if (ret < 0)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE;
-    }
+    return gnutls_assert_val(GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE);
 
   priv = epriv.ptr;
+
+  if (priv->mki_received == 0)
+    return gnutls_assert_val(GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE);
   
   mki->data = priv->mki;
   mki->size = priv->mki_size;
@@ -647,7 +648,13 @@ _gnutls_srtp_pack (extension_priv_data_t epriv, gnutls_buffer_st * ps)
     {
       BUFFER_APPEND_NUM (ps, priv->profiles[i]);
     }
-  BUFFER_APPEND_NUM (ps, priv->selected_profile);
+
+  BUFFER_APPEND_NUM (ps, priv->mki_received);
+  if (priv->mki_received)
+    {
+      BUFFER_APPEND_NUM (ps, priv->selected_profile);
+      BUFFER_APPEND_PFX4 (ps, priv->mki, priv->mki_size);
+    }
   return 0;
 }
 
@@ -674,6 +681,13 @@ _gnutls_srtp_unpack (gnutls_buffer_st * ps,
     }
   BUFFER_POP_NUM (ps, priv->selected_profile);
 
+  BUFFER_POP_NUM (ps, priv->mki_received);
+  if (priv->mki_received)
+    {
+      BUFFER_POP_NUM (ps, priv->mki_size);
+      BUFFER_POP (ps, priv->mki, priv->mki_size);
+    }
+
   epriv.ptr = priv;
   *_priv = epriv;
 
index 73552f716bb9d40319b6b0653d687093cec717e6..bb565b7df4ca09993f2022cd98a137363a3714f3 100644 (file)
@@ -33,6 +33,7 @@ typedef struct
   gnutls_srtp_profile_t selected_profile;
   uint8_t mki[256];
   unsigned mki_size;
+  unsigned int mki_received;
 } srtp_ext_st;
 
 extern extension_entry_st ext_mod_srtp;