]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
2nd pass to add secure RTP
authorBrian West <brian@freeswitch.org>
Mon, 10 Apr 2006 17:14:53 +0000 (17:14 +0000)
committerBrian West <brian@freeswitch.org>
Mon, 10 Apr 2006 17:14:53 +0000 (17:14 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1104 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_types.h
src/switch_rtp.c

index 20935c1f269a30eeeca177590bb3f4d21b7f8bf2..373751af2375c93a73dbfda5d36298d3ff17e139 100644 (file)
@@ -101,12 +101,14 @@ SWITCH_DECLARE_DATA extern switch_directories SWITCH_GLOBAL_dirs;
     SWITCH_RTP_FLAG_NOBLOCK      - Do not block
     SWITCH_RTP_FLAG_IO           - IO is ready
        SWITCH_RTP_FLAG_USE_TIMER    - Timeout Reads and replace with a CNG Frame
+       SWITCH_RTP_FLAG_SECURE       - Secure RTP
 </pre>
  */
 typedef enum {
        SWITCH_RTP_FLAG_NOBLOCK = ( 1 << 0),
        SWITCH_RTP_FLAG_IO = (1 << 1),
-       SWITCH_RTP_FLAG_USE_TIMER = (1 << 2)
+       SWITCH_RTP_FLAG_USE_TIMER = (1 << 2),
+       SWITCH_RTP_FLAG_SECURE = (1 << 3)
 } switch_rtp_flag_t;
 
 /*!
index d2973bd10251ad8bcc29c923dcb57bb7fc269d03..2801a411689d51b318fefdad16a2c47531b89ef7 100644 (file)
@@ -276,6 +276,7 @@ SWITCH_DECLARE(switch_status) switch_rtp_create(switch_rtp **new_rtp_session,
        if (crypto_key) {
                int len;
 
+               switch_set_flag(rtp_session, SWITCH_RTP_FLAG_SECURE);
                crypto_policy_set_rtp_default(&policy.rtp);
                crypto_policy_set_rtcp_default(&policy.rtcp);
                policy.ssrc.type  = ssrc_specific;
@@ -463,6 +464,11 @@ static int rtp_common_read(switch_rtp *rtp_session, void *data, int *payload_typ
        for(;;) {
                bytes = sizeof(rtp_msg_t);      
                status = switch_socket_recvfrom(rtp_session->from_addr, rtp_session->sock, 0, (void *)&rtp_session->recv_msg, &bytes);
+               if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_SECURE)) {
+                       int sbytes = (int)bytes;
+                       srtp_unprotect(rtp_session->recv_ctx, &rtp_session->send_msg, &sbytes);
+                       bytes = sbytes;
+               }
 
                if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_USE_TIMER)) {
                        if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_IO)) {
@@ -562,6 +568,12 @@ static int rtp_common_write(switch_rtp *rtp_session, void *data, uint32_t datale
        }
        
        bytes = datalen + rtp_header_len;
+       if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_SECURE)) {
+               int sbytes = (int)bytes;
+               srtp_protect(rtp_session->send_ctx, &rtp_session->send_msg, &sbytes);
+               bytes = sbytes;
+       }
+
        switch_socket_sendto(rtp_session->sock, rtp_session->remote_addr, 0, (void*)&rtp_session->send_msg, &bytes);
 
        if (rtp_session->ice_user) {