Commit Graph

488 Commits

Author SHA1 Message Date
Aaro Altonen c5b68d9280 Merge branch 'zrtp' into develop 2020-02-04 07:20:27 +02:00
Aaro Altonen 038dd09165 Add ZRTP Error messages 2020-02-04 07:10:28 +02:00
Aaro Altonen 25f647da5c Fix ZRTP version negotiation 2020-02-02 09:37:02 +02:00
Aaro Altonen 992d486d02 Modify the way capabilities are resolved
Because kvzRTP only supports the mandatory algorithms required by the
spec, we don't even need to parse the remote's Hello message because
by assuming it supports all the mandatory too, we can just fill the
capabilities struct with those algorithms and proceeds with the session
initialization.
2020-02-02 09:16:56 +02:00
Aaro Altonen b5873fbc3c Clean the zrtp_session_t struct
Split different session variables into separate structures
and make the naming of variables more logical
2020-02-02 09:05:25 +02:00
Aaro Altonen ca669fc1b5 Add CRC32 checksums to all message
Calculate CRC32 checksum of the whole ZRTP packet and add it at the
end of packet and verify the checksum when a packet is received.
If the verification fails, the packet is simply discarded
2020-02-02 08:22:58 +02:00
Aaro Altonen f62784cf27 Validate all messages using the MACs and H0-H3 hashes
Recalculate all session hashes using H0 received in the ConfirmN
Message, calculate MACs for all received messages and compare them
against the MACs that were received in the messages to see if the
session is valid
2020-02-01 07:56:39 +02:00
Aaro Altonen 1b0d3ed585 Verify confirm_mac when parsing ConfirmN message
Because the confirm_mac is computed over the encrypted portion of
the message and because ConfirmN's parse_msg() decrypts the message,
the obvious place to verify the MAC is parse_msg()
2020-01-31 12:18:01 +02:00
Aaro Altonen 5d42b7d7ea Fix Conf2ACK message
Now all the message related to DH key exchange are supported and
all that is left is creating a public API and verifying messages
before the ZRTP is ended.
2020-01-31 12:02:16 +02:00
Aaro Altonen 426da0f962 Fix Confirm1/Confirm2 messages
The Confirm messages now contains all info required by the spec.
Encryption/decryption works using ZRTP session keys
2020-01-31 11:46:39 +02:00
Aaro Altonen 3a6d165698 Generate shared secrets after DH key exchange 2020-01-31 11:28:25 +02:00
Aaro Altonen 407344cf0a Store all sent and received messages to zrtp_session_t
This way we can calculate the hash checksums when at once instead
of updating it in different places.
2020-01-29 12:10:53 +02:00
Aaro Altonen caebde67c4 Fix DHPart1/DHPart2 messages
Now kvzRTP creates a private/public key pair and sends the public
key in the DHPartN message to remote.

kvzRTP does not support Preshared mode so the retained secrets just
contain random values and are going to be ignore when the shared
secrets are established.

DHResult is already calculated successfully though the architecture
is really starting show its limitations because the sha256 values
of various messages are calculated everywhere in the code which is
pretty ugly. Maybe create getters for various messages and calculate
all hashes at once.
2020-01-29 11:19:46 +02:00
Aaro Altonen 6d6bfd505e Fix Commit message
Commit message partially depends on DHPart2 and Hello messages to
construct the hvi value. The architecture of ZRTP is going to change
a tiny bit in the near future to construct the DHPart2 and create
the actual public/private key pairs before anything else
2020-01-28 12:25:57 +02:00
Aaro Altonen 8a761bdee2 Fix Hello/HelloACK messages
Now they should work on both Linux and Windows and Hello messages
contain all the information required by the specification.

The parsing of algorithms is still missing but because kvzRTP's
implementation is only going to provide the mandatory algorithms,
the lists can be omitted and as long as we're only communicating with
ourselves, the parsing can be omitted too.

At some point in the future I'll add proper parsing and remove the GNU
extension from ZRTP to make it truly cross-platform and compatible with
other RTP libraries supporting ZRTP
2020-01-28 10:56:31 +02:00
Aaro Altonen 6a53bb92b2 Generate H0-H3 as defined in Section 9 of RFC 6189 2020-01-28 08:34:56 +02:00
Aaro Altonen 08fb0a51ad Generate 96-bit long random sequence for ZID 2020-01-28 08:14:22 +02:00
Aaro Altonen 5d9cb58f8a Add kvzrtp style interface for the crypto library 2020-01-28 08:14:16 +02:00
Aaro Altonen 9f2969b7c1 Add initial Confirm{1,2} and Conf2ACK functionality 2020-01-24 10:49:44 +02:00
Aaro Altonen 93216ba0bb Add initial DHPart1/DHPart2 functionality
The actual data in the payloads is not correct but this provides
a skeleton for the whole messages exchanges which can be refined
later on easily
2020-01-24 10:13:43 +02:00
Aaro Altonen 6b68addac3 Add initial Commit functionality
Commit messages are exchanged and roles for both parties are selected
as defined in RFC 6189. Lots of details are omitted and they will be
implemented later on when crypto functionality is added to the project
2020-01-24 08:38:11 +02:00
Aaro Altonen ea0978ef02 Add Hello/HelloACK functionality
kvzRTP's ZRTP implementation shall support only the mandatory algorithms
defined in the specification. There are several things missing from Hello
but those are somewhat minor details and will be fixed when the ZRTP is
starting to be ready
2020-01-22 11:02:39 +02:00
Aaro Altonen 911a86f3b9 Add initial SRTP initialization
Current architecture is not optimal for ZRTP negotiations will require
some rethinking but it'll have to do for now.
2020-01-22 10:57:40 +02:00
Aaro Altonen 89f31a16e0 Remove warnigns and enable LOG_DEBUG 2020-01-20 08:57:08 +02:00
Aaro Altonen 8ebadad579 Move definition of socket_t to util.hh
It's used in multiple places so dedicated place for its definition
is necessary
2020-01-17 13:41:52 +02:00
Aaro Altonen 4370119140 Document frame.hh better 2020-01-17 10:33:28 +02:00
Aaro Altonen aeb3382421 Remove unused code from frame.cc
The media header pointer getters are not used anymore
2020-01-17 10:28:03 +02:00
Aaro Altonen 8fae92b4e1 Rename frame types more logically 2020-01-17 10:18:11 +02:00
Aaro Altonen 84715a77a6 Remove warnings 2020-01-16 10:10:26 +02:00
Aaro Altonen eeae6981e3 Update README
Remove all unnecessary information about kvzRTP's internal workings
and leave only the compiling/linking/usage information
2020-01-16 10:10:19 +02:00
Aaro Altonen 751ab6983d Merge branch 'dynamic-config' into develop 2020-01-13 10:07:26 +02:00
Aaro Altonen 84441b39c4 Add examples of new dynamic configuration 2020-01-13 10:06:51 +02:00
Aaro Altonen 7cf1c4d36d Make dynamic configuration connection-based
Making configuration global was moronic considering there are
different types of media streams per session (f.ex Opus and HEVC)
which have very different types of needs. For example, setting
receiver's UDP buffer size to 40 MB would make no sense for Opus.

Now each connection can be configured individually which is also
a needed feature for SRTP

This change reverted the changes made earlier to global API
2020-01-13 10:02:34 +02:00
Aaro Altonen d0f18d4864 Prepare kvzRTP for SRTP/SRTCP support
The security layer is injected between reading a datagram from OS and
RTP/RTCP payload processing so the obvious place for that layer is socket.

Make all recv/send function calls go through socket API so the security
layer function calls doesn't have to be copied everywhere
2020-01-10 10:30:47 +02:00
Aaro Altonen 730bd3ab78 Update README 2020-01-09 10:24:57 +02:00
Aaro Altonen 66f6acd0eb Add Windows support for the latest changes 2020-01-09 10:10:58 +02:00
Aaro Altonen 4b5efed3fc Make read datagram count dynamic based on the state of frame
To prevent excess relocations but to minimize the nubmer of system
calls done, OFR reads 15 datagrams from OS using one system call if
more than 2% or less than 98% of the frame has been read.

These values are a result of experimentation and they lowered the CPU
utilization most. Compared to simple receiver, OFR, with dynamic datagram
read size, uses 14% less CPU than.

These numbers could be improved even further if media-specific
optimizations would be done such as keeping track of intra or VPS
period to adjust max datagram read size or the legal interval for
max read.

This optimizations are, however, probably not going to yield a lot
of benefit compared to the current state of OFR and are thus not
implemented. As it is, OFR is already able to receive HEVC at
580 MB/s and uses 14% less CPU than simple so for high-quality video
conferencing situations with multiple participants this is a good
choice.
2020-01-09 09:30:22 +02:00
Aaro Altonen 3e981ec4ae Switch from compile-time to runtime configuration of kvzRTP 2020-01-08 10:56:09 +02:00
Aaro Altonen 9472c4142c Fix example code
Some of the code used the old API, now fixed
2020-01-07 10:20:20 +02:00
Aaro Altonen 729db0c928 Update kvzRTP
Miscellaneous changes to various files
2020-01-07 09:54:33 +02:00
Aaro Altonen e5bdd39ce4 add latency testing programs for kvzrtp and ffmpeg 2019-12-09 18:25:59 +02:00
Aaro Altonen 3e127885e0 improve ffmpeg and kvzrtp sending 2019-12-09 18:25:18 +02:00
Aaro Altonen ab9ae93124 Fix the normal way of sending for HEVC
The version that does not use sendmmsg(2) didn't return proper status
codes for __push_hevc_frame() when it had sent the smaller NAL units.

This caused it to send far less data than it should have
2019-11-27 08:39:56 +02:00
Aaro Altonen ce7aebf97a Add windows support 2019-11-13 08:08:52 +02:00
Aaro Altonen 3053f1b4bf Give memory advice for Linux about the HEVC file
This removes yet a little more lantecy from the setup to get better
theoretical maximum. Both kvzRTP and FFmpeg benefit from this.
2019-11-06 08:58:42 +02:00
Aaro Altonen b9b0cdc4b7 Rewrite FFmpeg send bechmark code 2019-11-01 08:47:24 +02:00
Aaro Altonen 6210c37dbc Use C++'s high-resolution clock to calculate RTP timestamps
The NTP millisecond diff calculation seems to be incorrect (it gives
very weird results) but miraculously it still produced playable video
stream.

I'll need to figure out what's wrong with the calculation at some point
but for now switch to use HRC.
2019-11-01 08:41:41 +02:00
Aaro Altonen 4ce0eecec9 Rewrite kvzRTP sender/receiver benchmarking code
Instead of both files containing both receiver and sender,
separate them into their own files
2019-11-01 08:37:51 +02:00
Aaro Altonen c7e37b9b06 Add FFmpeg receiver code 2019-10-31 11:15:02 +02:00
Aaro Altonen da88aeadfd Fix dispatcher
Compiler flag had disabled it masking the compile errors, now fixex
2019-10-30 11:40:54 +02:00