Ignore:
Timestamp:
Jul 4, 2017 5:22:51 AM (7 years ago)
Author:
nanang
Message:

Close #1993: Updated bundled libSRTP version to 2.1.0.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia/transport_srtp.c

    r5602 r5614  
    7575static const pj_str_t ID_CRYPTO   = { "crypto", 6 }; 
    7676 
    77 typedef void (*crypto_method_t)(crypto_policy_t *policy); 
     77typedef void (*crypto_method_t)(srtp_crypto_policy_t *policy); 
    7878 
    7979typedef struct crypto_suite 
    8080{ 
    8181    char                *name; 
    82     cipher_type_id_t    cipher_type; 
     82    srtp_cipher_type_id_t cipher_type; 
    8383    unsigned             cipher_key_len;    /* key + salt length    */ 
    8484    unsigned             cipher_salt_len;   /* salt only length     */ 
    85     auth_type_id_t       auth_type; 
     85    srtp_auth_type_id_t  auth_type; 
    8686    unsigned             auth_key_len; 
    8787    unsigned             srtp_auth_tag_len; 
    8888    unsigned             srtcp_auth_tag_len; 
    89     sec_serv_t           service; 
     89    srtp_sec_serv_t      service; 
    9090    /* This is an attempt to validate crypto support by libsrtp, i.e: it should 
    9191     * raise linking error if the libsrtp does not support the crypto.  
    9292     */ 
    93     cipher_type_t       *ext_cipher_type; 
     93    srtp_cipher_type_t  *ext_cipher_type; 
    9494    crypto_method_t      ext_crypto_method; 
    9595} crypto_suite; 
    9696 
    97 extern cipher_type_t aes_gcm_256_openssl; 
    98 extern cipher_type_t aes_gcm_128_openssl; 
    99 extern cipher_type_t aes_icm_192; 
     97extern srtp_cipher_type_t srtp_aes_gcm_256_openssl; 
     98extern srtp_cipher_type_t srtp_aes_gcm_128_openssl; 
     99extern srtp_cipher_type_t srtp_aes_icm_192; 
    100100 
    101101/* https://www.iana.org/assignments/sdp-security-descriptions/sdp-security-descriptions.xhtml */ 
    102102static crypto_suite crypto_suites[] = { 
    103103    /* plain RTP/RTCP (no cipher & no auth) */ 
    104     {"NULL", NULL_CIPHER, 0, NULL_AUTH, 0, 0, 0, sec_serv_none}, 
     104    {"NULL", SRTP_NULL_CIPHER, 0, SRTP_NULL_AUTH, 0, 0, 0, sec_serv_none}, 
    105105 
    106106#if defined(PJMEDIA_SRTP_HAS_AES_GCM_256)&&(PJMEDIA_SRTP_HAS_AES_GCM_256!=0) 
    107107 
    108108    /* cipher AES_GCM, NULL auth, auth tag len = 16 octets */ 
    109     {"AEAD_AES_256_GCM", AES_256_GCM, 44, 12, 
    110         NULL_AUTH, 0, 16, 16, sec_serv_conf_and_auth, &aes_gcm_256_openssl}, 
     109    {"AEAD_AES_256_GCM", SRTP_AES_GCM_256, 44, 12, 
     110        SRTP_NULL_AUTH, 0, 16, 16, sec_serv_conf_and_auth, 
     111        &srtp_aes_gcm_256_openssl}, 
    111112 
    112113    /* cipher AES_GCM, NULL auth, auth tag len = 8 octets */ 
    113     {"AEAD_AES_256_GCM_8", AES_256_GCM, 44, 12, 
    114         NULL_AUTH, 0, 8, 8, sec_serv_conf_and_auth, &aes_gcm_256_openssl}, 
     114    {"AEAD_AES_256_GCM_8", SRTP_AES_GCM_256, 44, 12, 
     115        SRTP_NULL_AUTH, 0, 8, 8, sec_serv_conf_and_auth, 
     116        &srtp_aes_gcm_256_openssl}, 
    115117#endif 
    116118#if defined(PJMEDIA_SRTP_HAS_AES_CM_256)&&(PJMEDIA_SRTP_HAS_AES_CM_256!=0) 
    117119 
    118     /* cipher AES_CM_256, auth HMAC_SHA1, auth tag len = 10 octets */ 
    119     {"AES_256_CM_HMAC_SHA1_80", AES_ICM, 46, 14, HMAC_SHA1, 20, 10, 10, 
    120         sec_serv_conf_and_auth, NULL,  
    121         &crypto_policy_set_aes_cm_256_hmac_sha1_80}, 
    122  
    123     /* cipher AES_CM_256, auth HMAC_SHA1, auth tag len = 10 octets */ 
    124     {"AES_256_CM_HMAC_SHA1_32", AES_ICM, 46, 14, HMAC_SHA1, 20, 4, 10, 
    125         sec_serv_conf_and_auth, NULL, 
    126         &crypto_policy_set_aes_cm_256_hmac_sha1_32}, 
     120    /* cipher AES_CM_256, auth SRTP_HMAC_SHA1, auth tag len = 10 octets */ 
     121    {"AES_256_CM_HMAC_SHA1_80", SRTP_AES_ICM_256, 46, 14, 
     122        SRTP_HMAC_SHA1, 20, 10, 10, sec_serv_conf_and_auth, 
     123        NULL, &srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80}, 
     124 
     125    /* cipher AES_CM_256, auth SRTP_HMAC_SHA1, auth tag len = 10 octets */ 
     126    {"AES_256_CM_HMAC_SHA1_32", SRTP_AES_ICM_256, 46, 14, 
     127        SRTP_HMAC_SHA1, 20, 4, 10, sec_serv_conf_and_auth, 
     128        NULL, &srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32}, 
    127129#endif 
    128130#if defined(PJMEDIA_SRTP_HAS_AES_CM_192)&&(PJMEDIA_SRTP_HAS_AES_CM_192!=0) 
    129131 
    130     /* cipher AES_CM_192, auth HMAC_SHA1, auth tag len = 10 octets */ 
    131     {"AES_192_CM_HMAC_SHA1_80", AES_ICM, 38, 14, HMAC_SHA1, 20, 10, 10, 
    132         sec_serv_conf_and_auth, &aes_icm_192}, 
    133  
    134     /* cipher AES_CM_192, auth HMAC_SHA1, auth tag len = 4 octets */ 
    135     {"AES_192_CM_HMAC_SHA1_32", AES_ICM, 38, 14, HMAC_SHA1, 20, 4, 10, 
    136         sec_serv_conf_and_auth, &aes_icm_192}, 
     132    /* cipher AES_CM_192, auth SRTP_HMAC_SHA1, auth tag len = 10 octets */ 
     133    {"AES_192_CM_HMAC_SHA1_80", SRTP_AES_ICM_192, 38, 14, 
     134        SRTP_HMAC_SHA1, 20, 10, 10, sec_serv_conf_and_auth, 
     135        &srtp_aes_icm_192}, 
     136 
     137    /* cipher AES_CM_192, auth SRTP_HMAC_SHA1, auth tag len = 4 octets */ 
     138    {"AES_192_CM_HMAC_SHA1_32", SRTP_AES_ICM_192, 38, 14, 
     139        SRTP_HMAC_SHA1, 20, 4, 10, sec_serv_conf_and_auth, 
     140        &srtp_aes_icm_192}, 
    137141#endif 
    138142#if defined(PJMEDIA_SRTP_HAS_AES_GCM_128)&&(PJMEDIA_SRTP_HAS_AES_GCM_128!=0) 
    139143 
    140144    /* cipher AES_GCM, NULL auth, auth tag len = 16 octets */ 
    141     {"AEAD_AES_128_GCM", AES_128_GCM, 28, 12, 
    142         NULL_AUTH, 0, 16, 16, sec_serv_conf_and_auth, &aes_gcm_128_openssl}, 
     145    {"AEAD_AES_128_GCM", SRTP_AES_GCM_128, 28, 12, 
     146        SRTP_NULL_AUTH, 0, 16, 16, sec_serv_conf_and_auth, 
     147        &srtp_aes_gcm_128_openssl}, 
    143148 
    144149    /* cipher AES_GCM, NULL auth, auth tag len = 8 octets */ 
    145     {"AEAD_AES_128_GCM_8", AES_128_GCM, 28, 12, 
    146         NULL_AUTH, 0, 8, 8, sec_serv_conf_and_auth, &aes_gcm_128_openssl}, 
     150    {"AEAD_AES_128_GCM_8", SRTP_AES_GCM_128, 28, 12, 
     151        SRTP_NULL_AUTH, 0, 8, 8, sec_serv_conf_and_auth, 
     152        &srtp_aes_gcm_128_openssl}, 
    147153#endif 
    148154#if defined(PJMEDIA_SRTP_HAS_AES_CM_128)&&(PJMEDIA_SRTP_HAS_AES_CM_128!=0) 
    149155 
    150     /* cipher AES_CM_128, auth HMAC_SHA1, auth tag len = 10 octets */ 
    151     {"AES_CM_128_HMAC_SHA1_80", AES_ICM, 30, 14, HMAC_SHA1, 20, 10, 10, 
    152         sec_serv_conf_and_auth}, 
    153  
    154     /* cipher AES_CM_128, auth HMAC_SHA1, auth tag len = 4 octets */ 
    155     {"AES_CM_128_HMAC_SHA1_32", AES_ICM, 30, 14, HMAC_SHA1, 20, 4, 10, 
    156         sec_serv_conf_and_auth}, 
     156    /* cipher AES_CM_128, auth SRTP_HMAC_SHA1, auth tag len = 10 octets */ 
     157    {"AES_CM_128_HMAC_SHA1_80", SRTP_AES_ICM_128, 30, 14, 
     158        SRTP_HMAC_SHA1, 20, 10, 10, sec_serv_conf_and_auth}, 
     159 
     160    /* cipher AES_CM_128, auth SRTP_HMAC_SHA1, auth tag len = 4 octets */ 
     161    {"AES_CM_128_HMAC_SHA1_32", SRTP_AES_ICM_128, 30, 14, 
     162        SRTP_HMAC_SHA1, 20, 4, 10, sec_serv_conf_and_auth}, 
    157163#endif 
    158164 
     
    346352#if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING != 0) 
    347353    static char *liberr[] = { 
    348         "ok",                               /* err_status_ok            = 0  */ 
     354        "ok",                               /* srtp_err_status_ok       = 0  */ 
    349355        "unspecified failure",              /* err_status_fail          = 1  */ 
    350356        "unsupported parameter",            /* err_status_bad_param     = 2  */ 
     
    413419    /* Init libsrtp */ 
    414420    { 
    415         err_status_t err; 
     421        srtp_err_status_t err; 
    416422 
    417423        err = srtp_init(); 
    418         if (err != err_status_ok) { 
     424        if (err != srtp_err_status_ok) { 
    419425            PJ_LOG(4, (THIS_FILE, "Failed to initialize libsrtp: %s", 
    420426                       get_libsrtp_errstr(err))); 
     
    445451static void pjmedia_srtp_deinit_lib(pjmedia_endpt *endpt) 
    446452{ 
    447     err_status_t err; 
     453    srtp_err_status_t err; 
    448454 
    449455    /* Note that currently this SRTP init/deinit is not equipped with 
     
    467473    err = srtp_shutdown(); 
    468474# else 
    469     err = err_status_ok; 
     475    err = srtp_err_status_ok; 
    470476# endif 
    471     if (err != err_status_ok) { 
     477    if (err != srtp_err_status_ok) { 
    472478        PJ_LOG(4, (THIS_FILE, "Failed to deinitialize libsrtp: %s", 
    473479                   get_libsrtp_errstr(err))); 
     
    680686    srtp_policy_t    tx_; 
    681687    srtp_policy_t    rx_; 
    682     err_status_t    err; 
     688    srtp_err_status_t err; 
    683689    int              cr_tx_idx = 0; 
    684690    int              au_tx_idx = 0; 
     
    753759    tx_.next                = NULL; 
    754760    err = srtp_create(&srtp->srtp_tx_ctx, &tx_); 
    755     if (err != err_status_ok) { 
     761    if (err != srtp_err_status_ok) { 
    756762        status = PJMEDIA_ERRNO_FROM_LIBSRTP(err); 
    757763        goto on_return; 
     
    786792    rx_.next                = NULL; 
    787793    err = srtp_create(&srtp->srtp_rx_ctx, &rx_); 
    788     if (err != err_status_ok) { 
     794    if (err != srtp_err_status_ok) { 
    789795        srtp_dealloc(srtp->srtp_tx_ctx); 
    790796        status = PJMEDIA_ERRNO_FROM_LIBSRTP(err); 
     
    851857{ 
    852858    transport_srtp *p_srtp = (transport_srtp*) srtp; 
    853     err_status_t err; 
     859    srtp_err_status_t err; 
    854860 
    855861    PJ_ASSERT_RETURN(srtp, PJ_EINVAL); 
     
    863869 
    864870    err = srtp_dealloc(p_srtp->srtp_rx_ctx); 
    865     if (err != err_status_ok) { 
     871    if (err != srtp_err_status_ok) { 
    866872        PJ_LOG(4, (p_srtp->pool->obj_name, 
    867873                   "Failed to dealloc RX SRTP context: %s", 
     
    869875    } 
    870876    err = srtp_dealloc(p_srtp->srtp_tx_ctx); 
    871     if (err != err_status_ok) { 
     877    if (err != srtp_err_status_ok) { 
    872878        PJ_LOG(4, (p_srtp->pool->obj_name, 
    873879                   "Failed to dealloc TX SRTP context: %s", 
     
    10321038    transport_srtp *srtp = (transport_srtp*) tp; 
    10331039    int len = (int)size; 
    1034     err_status_t err; 
     1040    srtp_err_status_t err; 
    10351041 
    10361042    if (srtp->bypass_srtp) 
     
    10501056    pj_lock_release(srtp->mutex); 
    10511057 
    1052     if (err == err_status_ok) { 
     1058    if (err == srtp_err_status_ok) { 
    10531059        status = pjmedia_transport_send_rtp(srtp->member_tp, 
    10541060                                            srtp->rtp_tx_buffer, len); 
     
    10761082    transport_srtp *srtp = (transport_srtp*) tp; 
    10771083    int len = (int)size; 
    1078     err_status_t err; 
     1084    srtp_err_status_t err; 
    10791085 
    10801086    if (srtp->bypass_srtp) { 
     
    10961102    pj_lock_release(srtp->mutex); 
    10971103 
    1098     if (err == err_status_ok) { 
     1104    if (err == srtp_err_status_ok) { 
    10991105        status = pjmedia_transport_send_rtcp2(srtp->member_tp, addr, addr_len, 
    11001106                                              srtp->rtcp_tx_buffer, len); 
     
    11541160    transport_srtp *srtp = (transport_srtp *) user_data; 
    11551161    int len = size; 
    1156     err_status_t err; 
     1162    srtp_err_status_t err; 
    11571163    void (*cb)(void*, void*, pj_ssize_t) = NULL; 
    11581164    void *cb_data = NULL; 
     
    12011207    err = srtp_unprotect(srtp->srtp_rx_ctx, (pj_uint8_t*)pkt, &len); 
    12021208    if (srtp->probation_cnt > 0 && 
    1203         (err == err_status_replay_old || err == err_status_replay_fail)) 
     1209        (err == srtp_err_status_replay_old || 
     1210         err == srtp_err_status_replay_fail)) 
    12041211    { 
    12051212        /* Handle such condition that stream is updated (RTP seq is reinited 
     
    12241231    } 
    12251232 
    1226     if (err != err_status_ok) { 
     1233    if (err != srtp_err_status_ok) { 
    12271234        PJ_LOG(5,(srtp->pool->obj_name, 
    12281235                  "Failed to unprotect SRTP, pkt size=%d, err=%s", 
     
    12471254    transport_srtp *srtp = (transport_srtp *) user_data; 
    12481255    int len = size; 
    1249     err_status_t err; 
     1256    srtp_err_status_t err; 
    12501257    void (*cb)(void*, void*, pj_ssize_t) = NULL; 
    12511258    void *cb_data = NULL; 
     
    12701277    } 
    12711278    err = srtp_unprotect_rtcp(srtp->srtp_rx_ctx, (pj_uint8_t*)pkt, &len); 
    1272     if (err != err_status_ok) { 
     1279    if (err != srtp_err_status_ok) { 
    12731280        PJ_LOG(5,(srtp->pool->obj_name, 
    12741281                  "Failed to unprotect SRTCP, pkt size=%d, err=%s", 
     
    15111518{ 
    15121519    transport_srtp *srtp = (transport_srtp *)tp; 
    1513     err_status_t err; 
     1520    srtp_err_status_t err; 
    15141521 
    15151522    if (srtp->bypass_srtp) 
     
    15341541        err = srtp_unprotect_rtcp(srtp->srtp_rx_ctx, pkt, pkt_len); 
    15351542 
    1536     if (err != err_status_ok) { 
     1543    if (err != srtp_err_status_ok) { 
    15371544        PJ_LOG(5,(srtp->pool->obj_name, 
    15381545                  "Failed to unprotect SRTP, pkt size=%d, err=%s", 
     
    15421549    pj_lock_release(srtp->mutex); 
    15431550 
    1544     return (err==err_status_ok) ? PJ_SUCCESS : PJMEDIA_ERRNO_FROM_LIBSRTP(err); 
    1545 } 
    1546  
    1547 #endif 
    1548  
    1549  
     1551    return (err==srtp_err_status_ok) ? PJ_SUCCESS : 
     1552                                       PJMEDIA_ERRNO_FROM_LIBSRTP(err); 
     1553} 
     1554 
     1555#endif 
     1556 
     1557 
Note: See TracChangeset for help on using the changeset viewer.