Ignore:
Timestamp:
Mar 15, 2018 3:00:59 AM (3 years ago)
Author:
nanang
Message:

Close #2100:

  • Added new APIs:
    • PJMEDIA: pjmedia_srtp_enum_crypto(), pjmedia_srtp_enum_keying()
    • PJSUA: pjsua_config.srtp_opt, pjsua_acc_config.srtp_opt, pjsua_srtp_opt_default()
    • PJSUA2: AccountMediaConfig::srtpOpt, Endpoint::srtpCryptoEnum()
  • Deprecated PJSUA callback on_create_media_transport_srtp() (not removed yet, just warnings).
  • Slightly refactored SRTP code:
    • Fixed potential issue with on_create_media_transport_srtp(), some PJSUA internal values in pjmedia_srtp_setting may be overridden by app.
    • Fixed few issues in SRTP and keying mechanism, e.g: premature local SDP modification (it should be done after verification).
    • Potential minor backward compatibility issue: default value of pjmedia_srtp_setting.crypto_count is now zero, previously it was initialized with all crypto via pjmedia_srtp_setting_default(), actually zero and all cryptos in this setting semantically are the same.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsua2/account.cpp

    r5649 r5755  
    2727 
    2828#define THIS_FILE               "account.cpp" 
     29 
     30/////////////////////////////////////////////////////////////////////////////// 
     31 
     32void SrtpCrypto::fromPj(const pjmedia_srtp_crypto &prm) 
     33{ 
     34    this->key       = pj2Str(prm.key); 
     35    this->name      = pj2Str(prm.name); 
     36    this->flags     = prm.flags; 
     37} 
     38 
     39pjmedia_srtp_crypto SrtpCrypto::toPj() const 
     40{ 
     41    pjmedia_srtp_crypto crypto; 
     42     
     43    crypto.key      = str2Pj(this->key); 
     44    crypto.name     = str2Pj(this->name); 
     45    crypto.flags    = this->flags; 
     46 
     47    return crypto; 
     48} 
     49 
     50/////////////////////////////////////////////////////////////////////////////// 
     51 
     52SrtpOpt::SrtpOpt() 
     53{ 
     54    pjsua_srtp_opt opt; 
     55    pjsua_srtp_opt_default(&opt); 
     56    fromPj(opt); 
     57} 
     58 
     59void SrtpOpt::fromPj(const pjsua_srtp_opt &prm) 
     60{ 
     61    this->cryptos.clear(); 
     62    for (unsigned i = 0; i < prm.crypto_count; ++i) { 
     63        SrtpCrypto crypto; 
     64        crypto.fromPj(prm.crypto[i]); 
     65        this->cryptos.push_back(crypto); 
     66    } 
     67 
     68    this->keyings.clear(); 
     69    for (unsigned i = 0; i < prm.keying_count; ++i) { 
     70        this->keyings.push_back(prm.keying[i]); 
     71    } 
     72} 
     73 
     74pjsua_srtp_opt SrtpOpt::toPj() const 
     75{ 
     76    pjsua_srtp_opt opt; 
     77 
     78    pj_bzero(&opt, sizeof(opt)); 
     79 
     80    opt.crypto_count = this->cryptos.size(); 
     81    for (unsigned i = 0; i < opt.crypto_count; ++i) { 
     82        opt.crypto[i] = this->cryptos[i].toPj(); 
     83    } 
     84 
     85    opt.keying_count = this->keyings.size(); 
     86    for (unsigned i = 0; i < opt.keying_count; ++i) { 
     87        opt.keying[i] = (pjmedia_srtp_keying_method)this->keyings[i]; 
     88    } 
     89 
     90    return opt; 
     91} 
     92 
     93void SrtpOpt::readObject(const ContainerNode &node) throw(Error) 
     94{ 
     95    ContainerNode this_node = node.readContainer("SrtpOpt"); 
     96 
     97    ContainerNode crypto_node = this_node.readArray("cryptos"); 
     98    this->cryptos.clear(); 
     99    while (crypto_node.hasUnread()) { 
     100        SrtpCrypto crypto; 
     101        NODE_READ_STRING        (crypto_node, crypto.key); 
     102        NODE_READ_STRING        (crypto_node, crypto.name); 
     103        NODE_READ_UNSIGNED      (crypto_node, crypto.flags); 
     104        this->cryptos.push_back(crypto); 
     105    } 
     106 
     107    ContainerNode keying_node = this_node.readArray("keyings"); 
     108    this->keyings.clear(); 
     109    while (keying_node.hasUnread()) { 
     110        unsigned keying; 
     111        NODE_READ_UNSIGNED      (keying_node, keying); 
     112        this->keyings.push_back(keying); 
     113    } 
     114} 
     115 
     116void SrtpOpt::writeObject(ContainerNode &node) const throw(Error) 
     117{ 
     118    ContainerNode this_node = node.writeNewContainer("SrtpOpt"); 
     119 
     120    ContainerNode crypto_node = this_node.writeNewArray("cryptos"); 
     121    for (unsigned i=0; i<this->cryptos.size(); ++i) { 
     122        NODE_WRITE_STRING       (crypto_node, this->cryptos[i].key); 
     123        NODE_WRITE_STRING       (crypto_node, this->cryptos[i].name); 
     124        NODE_WRITE_UNSIGNED     (crypto_node, this->cryptos[i].flags); 
     125    } 
     126 
     127    ContainerNode keying_node = this_node.writeNewArray("keyings"); 
     128    for (unsigned i=0; i<this->keyings.size(); ++i) { 
     129        NODE_WRITE_UNSIGNED     (keying_node, this->keyings[i]); 
     130    } 
     131} 
    29132 
    30133/////////////////////////////////////////////////////////////////////////////// 
     
    253356    NODE_READ_NUM_T   ( this_node, pjmedia_srtp_use, srtpUse); 
    254357    NODE_READ_INT     ( this_node, srtpSecureSignaling); 
     358    NODE_READ_OBJ     ( this_node, srtpOpt); 
    255359    NODE_READ_NUM_T   ( this_node, pjsua_ipv6_use, ipv6Use); 
    256360    NODE_READ_OBJ     ( this_node, transportConfig); 
     
    265369    NODE_WRITE_NUM_T   ( this_node, pjmedia_srtp_use, srtpUse); 
    266370    NODE_WRITE_INT     ( this_node, srtpSecureSignaling); 
     371    NODE_WRITE_OBJ     ( this_node, srtpOpt); 
    267372    NODE_WRITE_NUM_T   ( this_node, pjsua_ipv6_use, ipv6Use); 
    268373    NODE_WRITE_OBJ     ( this_node, transportConfig); 
     
    453558    ret.use_srtp                = mediaConfig.srtpUse; 
    454559    ret.srtp_secure_signaling   = mediaConfig.srtpSecureSignaling; 
     560    ret.srtp_opt                = mediaConfig.srtpOpt.toPj(); 
    455561    ret.ipv6_media_use          = mediaConfig.ipv6Use; 
    456562 
     
    627733    mediaConfig.srtpUse         = prm.use_srtp; 
    628734    mediaConfig.srtpSecureSignaling = prm.srtp_secure_signaling; 
     735    mediaConfig.srtpOpt.fromPj(prm.srtp_opt); 
    629736    mediaConfig.ipv6Use         = prm.ipv6_media_use; 
    630737 
Note: See TracChangeset for help on using the changeset viewer.