Commit Graph

791 Commits

Author SHA1 Message Date
Aaro Altonen 2a4e45032a Implement Secure RTCP for Sender Reports 2020-09-03 12:03:50 +03:00
Aaro Altonen cc9438da40 Implement RTCP authentication routines 2020-09-03 11:34:55 +03:00
Aaro Altonen 4858efe063 Do not set bytes_read in src/poll.cc 2020-09-03 11:22:10 +03:00
Aaro Altonen 8a02c40fd8 Initialize RTCP hooks to nullptr 2020-09-03 11:03:30 +03:00
Aaro Altonen ffa7ed5770 Fix RTP/RTCP authentication tag length
The tag is truncated from 20 bytes to 4 bytes
2020-09-03 10:59:26 +03:00
Aaro Altonen c10169873b Fix return values of SRTP packet handler
The handler should never return RTP_OK because the packet should
be dispatched to lower layers after authenticity has been verified/
payload has been decrypted.
2020-09-03 09:23:33 +03:00
Aaro Altonen 7236c5caa4 Verify authentication tag even if NULL cipher is used
Even if NULL cipher is used for RTP it does not mean that RTP packet
authentication could not be used.
2020-09-03 09:18:48 +03:00
Aaro Altonen 35fe7776fe Fix RTP packet authentication 2020-09-03 09:02:41 +03:00
Aaro Altonen 1efc8b6049 Store pointer to the datagram in the rtp_frame structure
Auxiliary handlers may need access to the original block of memory
(such as SRTP) so instead of relaying that parameter to every handler,
store pointer to the block inside the RTP frame. The pointer is valid
as long as the packet is being processed and the last handler should
set it to nullptr.

Some changes to the public frame should be made because a lot of
the fields in the frames used by uvgRTP are not important outside
the library.
2020-09-03 08:34:58 +03:00
Aaro Altonen 7105da93e4 Add field for RTP authentication tag at the end of the packet 2020-09-02 12:55:35 +03:00
Aaro Altonen de3e72e97f Implement RCE_SRTP_INPLACE_ENCRYPTION
By default uvgRTP assumes that the memory it gets from user is not
writable and if user doesn't explictly specify that the memory
is writable (RCE_SRTP_INPLACE_ENCRYPTION) or that encryption is
not necessary (RCE_SRTP_NULL_CIPHER), a copy of the memory block is
made before it is pushed into the frame queue.
2020-09-02 12:30:30 +03:00
Aaro Altonen f3efcfde96 Install SRTP handler to socket when SRTP has been enabled 2020-09-02 11:55:38 +03:00
Aaro Altonen 8f5df75c50 Warn if security flags are provided when they are not supported
If uvgRTP has not been compiled with crypto support but one
of the SRTP flags is provided, warn the user and exit
2020-09-02 11:55:38 +03:00
Aaro Altonen ff35c9e1b6 Fix memory leaks in MediaStream initialization 2020-09-02 11:55:38 +03:00
Aaro Altonen 85bb4c6eef Create separate SRTP and SRTCP objects for each MediaStream 2020-09-02 11:55:34 +03:00
Aaro Altonen 9cb5b9fe45 Add SRTP files for the install target 2020-09-02 10:07:23 +03:00
Aaro Altonen bb826570ef Separate Secure RTP code into SRTP and SRTCP
Create separate classes for SRTP and SRTCP because even though
they are quite similar, they require some different actions when
en/decrypting the packets and create a whole bunch of if-elses
is ugly
2020-09-02 10:07:20 +03:00
Aaro Altonen 1aa6a17348 Fix RTCP version mask in Sender/Receiver Report code 2020-09-01 13:32:21 +03:00
Aaro Altonen 7627513216 Remove old SRTP code from src/socket.cc 2020-08-27 04:12:58 +03:00
Aaro Altonen be74a58ab1 Remove terminate_self()
This function no longer serves any purpose
2020-08-26 15:54:47 +03:00
Aaro Altonen b1168d8175 Remove unused code from src/frame.cc
Remove all unused (de)allocation code from src/frame.cc and remove
the RTCP-related PACKED_STRUCT definitions from include/frame.hh
2020-08-26 15:53:41 +03:00
Aaro Altonen 8f55079e62 Fix RTCP BYE generation/reception code
Operate on a raw block of memory and remove all participants from
the active session that are indicated in the BYE packet by their SSRCs
2020-08-26 15:52:19 +03:00
Aaro Altonen e586a007be Fix RTCP APP generation/reception code
Operate on a raw block of memory, extract interesting fields from the
packet and create user-friendly struct for the APP packet that
can be queried using SSRC

Caller must remember to free the memory occupied by the APP payload
2020-08-26 15:36:56 +03:00
Aaro Altonen 2807ccc83b Fix RTCP SDES generation/reception code
Operate on a raw block of memory, extract interesting fields from the
packet and create user-friendly struct for the SDES packet that
can be queried using SSRC

Caller must remember to free the memory occupied by the SDES items
2020-08-26 15:34:06 +03:00
Aaro Altonen 29f959d6ad Sender RTCP Receiver Report to senders only 2020-08-26 15:34:03 +03:00
Aaro Altonen 4081766cac Suppress warning message for RTCP Sender Report generation 2020-08-26 15:34:03 +03:00
Aaro Altonen c90fdd8d5c Call vectored packet handlers in sendtov() 2020-08-26 15:34:03 +03:00
Aaro Altonen 49575ed1ca Fix RTCP Sender Report generation/reception code
Operate on a raw block of memory, extract interesting fields from the
packet and create user-friendly struct for the Sender Report that
can be queried using SSRC
2020-08-26 15:33:59 +03:00
Aaro Altonen 7992224325 Move SET_NEXT_FIELD_32 to include/util.hh 2020-08-26 15:33:57 +03:00
Aaro Altonen fc117e6eba Fix RTCP Receiver Report reception code
Craft user-friendly rtcp_receiver_report struct from the raw
message which can be fetched using SSRC
2020-08-26 15:33:52 +03:00
Aaro Altonen ea8f1d2039 Fix calculation for estimate of dropped packets
Sometimes "expected" seems to fall behind which gives negative
values for the estimate.
2020-08-26 10:56:50 +03:00
Aaro Altonen 6d9a2c1df3 Fix packet offsets for RTCP Receiver Report 2020-08-26 10:55:33 +03:00
Aaro Altonen 47b17bb1d1 Handle incoming RTCP reports as raw memory blocks
PACKED_STRUCT is quite an ugly hack if it must be cross-platform
so better to process the incoming (and soon outgoing) RTCP data
as raw memory and craft user-friendly RTCP packets from those
memory blocks which do not including strict padding or truncated fields.
2020-08-26 07:33:02 +03:00
Aaro Altonen 35174d142c Remove double loop from __sendtov()
The loop accidentally processed the pkt_vec twice which in turn
sent twice as large RTP packets
2020-08-26 07:30:18 +03:00
Aaro Altonen 65affa16a5 Do not deinitialize the transaction twice
flush_queue() deinitializes the transaction before it returns
2020-08-26 07:28:06 +03:00
Aaro Altonen 7d7aac0c18 Remove packets from the transaction when it's completed 2020-08-26 07:18:55 +03:00
Aaro Altonen b832db00c3 Make sure the active transaction is not empty 2020-08-25 12:05:59 +03:00
Aaro Altonen 19ba6e1c5c Deprecate RTCP Receive Report support from src/frame.cc
The frame (de)allocation is handled internally by each message
handler and include/frame.hh shall only provide the structure
format for RTCP Receive Report.
2020-08-25 12:05:59 +03:00
Aaro Altonen 43cbc0bef3 Create RTCP Receiver Report manually
This makes it a little simpler to add support Secure RTCP later on,
enables us to deprecate the Receiver Report interface from src/frame.cc
and makes it automatically cross-platform (previously PACKED_STRUCT
was a GCC-only feature)
2020-08-25 12:05:56 +03:00
Aaro Altonen 09caee904f Relay RTP context flags to RTCP object 2020-08-25 09:14:34 +03:00
Aaro Altonen 5d680d454b Add example code for custom timestamping 2020-08-20 11:36:33 +03:00
Aaro Altonen b51fef61ee Merge branch 'security-fixes' into develop 2020-08-18 10:11:19 +03:00
Aaro Altonen 5dcb9e68ec Implement RTP packet authentication using the frame queue
The authentication tag for each packet is stored inside the active
transaction and they are destroyed when the transaction is deallocated.

This way neither Socket nor SRTP needs to worry about (de)allocation
of those tags.

The authentication tag occupies the last slot in the pkt_vec structure
of each packet so it's easily accessible for the security layer when
calculating the checksum and guaranteed to be there if
RCE_SRTP_AUTHENTICATE_RTP has been provided.
2020-08-18 09:38:16 +03:00
Aaro Altonen 12ac580290 Deprecate the single buffer based sendto(2) for RTP packets
All RTP packets use buf_vec/pkt_vec style I/O and thus the old
single buffer based approach is no longer needed.
2020-08-18 09:38:16 +03:00
Aaro Altonen 1a36eebc99 Use frame queue with all media formats
Move frame queue to Media object and implement the generic push API
using a frame queue

This change temporarily disable the fragmentation of generic frames
2020-08-18 09:38:16 +03:00
Aaro Altonen 079c3ab23c Implement cross-platform frame queue
Introduce buf_vec and pkt_vec structures which enable cross-platform
scatter/gather I/O. This supersedes the previous Linux-only mmsghdr
hack. Buf_vec contains buffers of a single RTP frame
whereas pkt_vec contains multiple buf_vec structures that are sent
all at once when flush_queue() is called.

From now on all media formats should use frame queue to implement
RTP frame sending. This is because internally the frame queue
updates RTP header information and it can inject additional fields
to the RTP frame such as an authentication tag.
2020-08-18 09:38:16 +03:00
Aaro Altonen bfc6283f91 Pass RTP context flags to frame queue 2020-08-18 09:38:16 +03:00
Aaro Altonen ef2a27e3b6 Remove all SRTP-related code from src/socket.cc
SRTP functionality is provided to packet handlers
2020-08-18 09:38:16 +03:00
Aaro Altonen b6595822cb Fix warnings 2020-08-18 09:38:16 +03:00
Aaro Altonen e1a28d095a Stop RTCP runner in MediaStream destructor 2020-08-18 09:38:16 +03:00