@@ -120,6 +120,8 @@ srtp_err_status_t srtp_test_set_sender_roc(void);
120120
121121srtp_err_status_t srtp_test_cryptex_csrc_but_no_extension_header (void );
122122
123+ srtp_err_status_t srtp_test_cryptex_disable (void );
124+
123125double srtp_bits_per_second (size_t msg_len_octets , const srtp_policy_t * policy );
124126
125127double srtp_rejections_per_second (size_t msg_len_octets ,
@@ -927,6 +929,14 @@ int main(int argc, char *argv[])
927929 printf ("failed\n" );
928930 exit (1 );
929931 }
932+
933+ printf ("testing cryptex_disable()..." );
934+ if (srtp_test_cryptex_disable () == srtp_err_status_ok ) {
935+ printf ("passed\n" );
936+ } else {
937+ printf ("failed\n" );
938+ exit (1 );
939+ }
930940 }
931941
932942 if (do_stream_list ) {
@@ -1130,6 +1140,20 @@ uint8_t *create_rtcp_test_packet(size_t payload_len,
11301140 return buffer - * rtcp_len ;
11311141}
11321142
1143+ static uint16_t get_xtn_profile (const uint8_t * packet )
1144+ {
1145+ const srtp_hdr_t * hdr = (const srtp_hdr_t * )packet ;
1146+ const srtp_hdr_xtnd_t * xtn_hdr ;
1147+
1148+ if (!hdr -> x ) {
1149+ return 0 ;
1150+ }
1151+
1152+ xtn_hdr = (const srtp_hdr_xtnd_t * )(packet + sizeof (srtp_hdr_t ) +
1153+ (hdr -> cc * sizeof (uint32_t )));
1154+ return ntohs (xtn_hdr -> profile_specific );
1155+ }
1156+
11331157void srtp_do_timing (const srtp_policy_t * policy )
11341158{
11351159 int len ;
@@ -3286,6 +3310,74 @@ srtp_err_status_t srtp_test_cryptex_csrc_but_no_extension_header(void)
32863310 return srtp_err_status_ok ;
32873311}
32883312
3313+ srtp_err_status_t srtp_test_cryptex_disable (void )
3314+ {
3315+ srtp_policy_t policy ;
3316+ memset (& policy , 0 , sizeof (policy ));
3317+ srtp_crypto_policy_set_rtp_default (& policy .rtp );
3318+ srtp_crypto_policy_set_rtcp_default (& policy .rtcp );
3319+ policy .ssrc .type = ssrc_specific ;
3320+ policy .ssrc .value = 0xcafebabe ;
3321+ policy .key = test_key ;
3322+ policy .window_size = 128 ;
3323+ policy .allow_repeat_tx = 0 ;
3324+ policy .use_cryptex = true;
3325+ policy .next = NULL ;
3326+
3327+ srtp_t srtp_snd , srtp_recv ;
3328+ CHECK_OK (srtp_create (& srtp_snd , & policy ));
3329+ CHECK_OK (srtp_create (& srtp_recv , & policy ));
3330+
3331+ size_t packet_len ;
3332+ uint8_t * packet = create_rtp_test_packet (100 , policy .ssrc .value , 1 , 1000 ,
3333+ true, & packet_len , NULL );
3334+ uint8_t clear_text [1400 ];
3335+ memcpy (clear_text , packet , packet_len );
3336+ size_t clear_text_len = packet_len ;
3337+
3338+ CHECK_OK (call_srtp_protect (srtp_snd , packet , & packet_len , 0 ));
3339+ CHECK (packet_len > clear_text_len );
3340+ CHECK (memcmp (packet , clear_text , clear_text_len ) != 0 );
3341+
3342+ // clear text uses original one byte header extension profile
3343+ CHECK (get_xtn_profile (clear_text ) == 0xbede );
3344+ // packet uses cryptex one byte header extension profile
3345+ CHECK (get_xtn_profile (packet ) == 0xc0de );
3346+
3347+ CHECK_OK (call_srtp_unprotect (srtp_recv , packet , & packet_len ));
3348+ CHECK (packet_len == clear_text_len );
3349+ CHECK_BUFFER_EQUAL (packet , clear_text , clear_text_len );
3350+
3351+ // update squence number for next packet
3352+ srtp_hdr_t * hdr = (srtp_hdr_t * )packet ;
3353+ hdr -> seq = htons (ntohs (hdr -> seq ) + 1 );
3354+ memcpy (clear_text , packet , packet_len );
3355+
3356+ // disbale cryptex at sender only
3357+ policy .use_cryptex = false;
3358+ CHECK_OK (srtp_update (srtp_snd , & policy ));
3359+
3360+ CHECK_OK (call_srtp_protect (srtp_snd , packet , & packet_len , 0 ));
3361+ CHECK (packet_len > clear_text_len );
3362+ CHECK (memcmp (packet , clear_text , clear_text_len ) != 0 );
3363+
3364+ // both use original one byte header extension profile as cryptex is
3365+ // disabled
3366+ CHECK (get_xtn_profile (clear_text ) == 0xbede );
3367+ CHECK (get_xtn_profile (packet ) == 0xbede );
3368+
3369+ // unprotect should work as cryptex is detected dynamically
3370+ CHECK_OK (call_srtp_unprotect (srtp_recv , packet , & packet_len ));
3371+ CHECK (packet_len == clear_text_len );
3372+ CHECK_BUFFER_EQUAL (packet , clear_text , clear_text_len );
3373+
3374+ free (packet );
3375+ CHECK_OK (srtp_dealloc (srtp_snd ));
3376+ CHECK_OK (srtp_dealloc (srtp_recv ));
3377+
3378+ return srtp_err_status_ok ;
3379+ }
3380+
32893381#ifdef GCM
32903382/*
32913383 * srtp_validate_gcm() verifies the correctness of libsrtp by comparing
0 commit comments