3535
3636#define DTLS_SIGN_ONCE
3737#define DTLS_MTU_SIZE 1500
38+ // #define DUMP_DTLS_KEY
3839
3940#define BREAK_ON_FAIL (ret ) \
4041 if (ret != 0) { \
@@ -55,6 +56,7 @@ static bool already_signed = false;
5556static mbedtls_ctr_drbg_context signed_ctr_drbg ;
5657static mbedtls_x509_crt signed_cert ;
5758static mbedtls_pk_context signed_pkey ;
59+ static mbedtls_entropy_context signed_entropy ;
5860#endif
5961
6062static void dtls_srtp_x509_digest (const mbedtls_x509_crt * crt , char * buf )
@@ -158,6 +160,7 @@ static int dtls_srtp_try_gen_cert(dtls_srtp_t *dtls_srtp)
158160 dtls_srtp -> ctr_drbg = signed_ctr_drbg ;
159161 dtls_srtp -> cert = signed_cert ;
160162 dtls_srtp -> pkey = signed_pkey ;
163+ dtls_srtp -> entropy = signed_entropy ;
161164 return 0 ;
162165 }
163166#endif
@@ -174,6 +177,7 @@ static int dtls_srtp_try_gen_cert(dtls_srtp_t *dtls_srtp)
174177 signed_ctr_drbg = dtls_srtp -> ctr_drbg ;
175178 signed_cert = dtls_srtp -> cert ;
176179 signed_pkey = dtls_srtp -> pkey ;
180+ signed_entropy = dtls_srtp -> entropy ;
177181#endif
178182 return 0 ;
179183}
@@ -269,8 +273,9 @@ void dtls_srtp_deinit(dtls_srtp_t *dtls_srtp)
269273 }
270274 mbedtls_ssl_free (& dtls_srtp -> ssl );
271275 mbedtls_ssl_config_free (& dtls_srtp -> conf );
272- mbedtls_entropy_free ( & dtls_srtp -> entropy );
276+
273277 if (already_signed == false) {
278+ mbedtls_entropy_free (& dtls_srtp -> entropy );
274279 mbedtls_x509_crt_free (& dtls_srtp -> cert );
275280 mbedtls_pk_free (& dtls_srtp -> pkey );
276281 mbedtls_ctr_drbg_free (& dtls_srtp -> ctr_drbg );
@@ -307,7 +312,16 @@ static void dtls_srtp_key_derivation(void *context, mbedtls_ssl_key_export_type
307312
308313 memcpy (randbytes , client_random , 32 );
309314 memcpy (randbytes + 32 , server_random , 32 );
310-
315+ // Debug key for wireshark
316+ #ifdef DUMP_DTLS_KEY
317+ printf ("CLIENT_RANDOM " );
318+ for (int i = 0 ; i < 32 ; i ++ )
319+ printf ("%02x" , client_random [i ]);
320+ printf (" " );
321+ for (int i = 0 ; i < secret_len ; i ++ )
322+ printf ("%02x" , secret [i ]);
323+ printf ("\n\n" );
324+ #endif
311325 // Export keying material
312326 if ((ret = mbedtls_ssl_tls_prf (tls_prf_type , secret , secret_len , dtls_srtp_label , randbytes , sizeof (randbytes ),
313327 key_material , sizeof (key_material )))
0 commit comments