Pascal Buhler | 988ce21 | 2017-11-12 12:48:08 +0100 | [diff] [blame] | 1 | [](https://travis-ci.org/cisco/libsrtp) |
| 2 | [](https://scan.coverity.com/projects/cisco-libsrtp) |
| 3 | |
Geir Istad | bf486d3 | 2017-02-08 07:18:10 +0100 | [diff] [blame] | 4 | <a name="introduction-to-libsrtp"></a> |
| 5 | # Introduction to libSRTP |
Geir Istad | 200d3bc | 2017-02-03 06:56:37 +0100 | [diff] [blame] | 6 | |
Geir Istad | de51ff4 | 2017-02-06 06:53:16 +0100 | [diff] [blame] | 7 | This package provides an implementation of the Secure Real-time |
| 8 | Transport Protocol (SRTP), the Universal Security Transform (UST), and |
Geir Istad | ffe210a | 2017-02-06 20:02:30 +0100 | [diff] [blame] | 9 | a supporting cryptographic kernel. The SRTP API is documented in include/srtp.h, |
| 10 | and the library is in libsrtp2.a (after compilation). |
| 11 | |
| 12 | This document describes libSRTP, the Open Source Secure RTP library |
| 13 | from Cisco Systems, Inc. RTP is the Real-time Transport Protocol, an |
| 14 | IETF standard for the transport of real-time data such as telephony, |
| 15 | audio, and video, defined by [RFC 3550](https://www.ietf.org/rfc/rfc3550.txt). |
| 16 | Secure RTP (SRTP) is an RTP profile for providing confidentiality to RTP data |
| 17 | and authentication to the RTP header and payload. SRTP is an IETF Standard, |
| 18 | defined in [RFC 3711](https://www.ietf.org/rfc/rfc3711.txt), and was developed |
| 19 | in the IETF Audio/Video Transport (AVT) Working Group. This library supports |
| 20 | all of the mandatory features of SRTP, but not all of the optional features. See |
Geir Istad | 4268d21 | 2017-02-16 08:13:40 +0100 | [diff] [blame] | 21 | the [Supported Features](#supported-features) section for more detailed information. |
Geir Istad | ffe210a | 2017-02-06 20:02:30 +0100 | [diff] [blame] | 22 | |
Geir Istad | bf486d3 | 2017-02-08 07:18:10 +0100 | [diff] [blame] | 23 | This document is also used to generate the documentation files in the /doc/ |
Geir Istad | ffe210a | 2017-02-06 20:02:30 +0100 | [diff] [blame] | 24 | folder where a more detailed reference to the libSRTP API and related functions |
| 25 | can be created (requires installing doxygen.). The reference material is created |
| 26 | automatically from comments embedded in some of the C header files. The |
| 27 | documentation is organized into modules in order to improve its clarity. These |
| 28 | modules do not directly correspond to files. An underlying cryptographic kernel |
| 29 | provides much of the basic functionality of libSRTP but is mostly undocumented |
| 30 | because it does its work behind the scenes. |
Geir Istad | de51ff4 | 2017-02-06 06:53:16 +0100 | [diff] [blame] | 31 | |
| 32 | -------------------------------------------------------------------------------- |
| 33 | |
Johan 't Hart | 23a3ce1 | 2019-06-13 10:18:49 +0200 | [diff] [blame] | 34 | <a name="contact-us"></a> |
Geir Istad | d188ab0 | 2017-02-16 07:00:31 +0100 | [diff] [blame] | 35 | # Contact Us |
| 36 | |
| 37 | - [libsrtp@lists.packetizer.com](mailto:libsrtp@lists.packetizer.com) general mailing list for news / announcements / discussions. This is an open list, see |
| 38 | [https://lists.packetizer.com/mailman/listinfo/libsrtp](https://lists.packetizer.com/mailman/listinfo/libsrtp) for singing up. |
| 39 | |
| 40 | - [libsrtp-security@lists.packetizer.com](mailto:libsrtp-security@lists.packetizer.com) for disclosing security issues to the libsrtp maintenance team. This is a closed list but anyone can send to it. |
| 41 | |
| 42 | |
| 43 | -------------------------------------------------------------------------------- |
| 44 | |
Geir Istad | bf486d3 | 2017-02-08 07:18:10 +0100 | [diff] [blame] | 45 | <a name="contents"></a> |
| 46 | ## Contents |
| 47 | |
| 48 | - [Introduction to libSRTP](#introduction-to-libsrtp) |
Johan 't Hart | 23a3ce1 | 2019-06-13 10:18:49 +0200 | [diff] [blame] | 49 | - [Contact Us](#contact-us) |
Geir Istad | d188ab0 | 2017-02-16 07:00:31 +0100 | [diff] [blame] | 50 | - [Contents](#contents) |
Geir Istad | bf486d3 | 2017-02-08 07:18:10 +0100 | [diff] [blame] | 51 | - [License and Disclaimer](#license-and-disclaimer) |
Geir Istad | b48849a | 2017-02-08 07:24:22 +0100 | [diff] [blame] | 52 | - [libSRTP Overview](#libsrtp-overview) |
Geir Istad | bf486d3 | 2017-02-08 07:18:10 +0100 | [diff] [blame] | 53 | - [Secure RTP Background](#secure-rtp-background) |
Geir Istad | b48849a | 2017-02-08 07:24:22 +0100 | [diff] [blame] | 54 | - [Supported Features](#supported-features) |
| 55 | - [Implementation Notes](#implementation-notes) |
Geir Istad | bf486d3 | 2017-02-08 07:18:10 +0100 | [diff] [blame] | 56 | - [Installing and Building libSRTP](#installing-and-building-libsrtp) |
Richard Barnes | b1108b5 | 2017-08-14 09:19:53 -0400 | [diff] [blame] | 57 | - [Changing Build Configuration](#changing-build-configuration) |
Johan 't Hart | 23a3ce1 | 2019-06-13 10:18:49 +0200 | [diff] [blame] | 58 | - [Using Visual Studio](#using-visual-studio) |
Geir Istad | bf486d3 | 2017-02-08 07:18:10 +0100 | [diff] [blame] | 59 | - [Applications](#applications) |
| 60 | - [Example Code](#example-code) |
Geir Istad | bf486d3 | 2017-02-08 07:18:10 +0100 | [diff] [blame] | 61 | - [Credits](#credits) |
| 62 | - [References](#references) |
| 63 | |
| 64 | -------------------------------------------------------------------------------- |
| 65 | |
| 66 | <a name="license-and-disclaimer"></a> |
| 67 | # License and Disclaimer |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 68 | |
| 69 | libSRTP is distributed under the following license, which is included |
Geir Istad | ffe210a | 2017-02-06 20:02:30 +0100 | [diff] [blame] | 70 | in the source code distribution. It is reproduced in the manual in |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 71 | case you got the library from another source. |
Geir Istad | 200d3bc | 2017-02-03 06:56:37 +0100 | [diff] [blame] | 72 | |
Geir Istad | 445c1c9 | 2017-03-27 08:13:49 +0200 | [diff] [blame] | 73 | > Copyright (c) 2001-2017 Cisco Systems, Inc. All rights reserved. |
Geir Istad | d1bef50 | 2017-02-03 08:25:54 +0100 | [diff] [blame] | 74 | > |
| 75 | > Redistribution and use in source and binary forms, with or without |
| 76 | > modification, are permitted provided that the following conditions |
| 77 | > are met: |
| 78 | > |
| 79 | > - Redistributions of source code must retain the above copyright |
| 80 | > notice, this list of conditions and the following disclaimer. |
| 81 | > - Redistributions in binary form must reproduce the above copyright |
| 82 | > notice, this list of conditions and the following disclaimer in |
| 83 | > the documentation and/or other materials provided with the distribution. |
| 84 | > - Neither the name of the Cisco Systems, Inc. nor the names of its |
| 85 | > contributors may be used to endorse or promote products derived |
| 86 | > from this software without specific prior written permission. |
| 87 | > |
| 88 | > THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 89 | > "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 90 | > LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 91 | > FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 92 | > COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
| 93 | > INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 94 | > (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 95 | > SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 96 | > HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 97 | > STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 98 | > ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 99 | > OF THE POSSIBILITY OF SUCH DAMAGE. |
Geir Istad | 200d3bc | 2017-02-03 06:56:37 +0100 | [diff] [blame] | 100 | |
| 101 | -------------------------------------------------------------------------------- |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 102 | |
Geir Istad | bf486d3 | 2017-02-08 07:18:10 +0100 | [diff] [blame] | 103 | <a name="libsrtp-overview"></a> |
Geir Istad | b48849a | 2017-02-08 07:24:22 +0100 | [diff] [blame] | 104 | # libSRTP Overview |
Geir Istad | ffe210a | 2017-02-06 20:02:30 +0100 | [diff] [blame] | 105 | |
| 106 | libSRTP provides functions for protecting RTP and RTCP. RTP packets |
Geir Istad | 1195df6 | 2017-02-16 06:17:56 +0100 | [diff] [blame] | 107 | can be encrypted and authenticated (using the `srtp_protect()` |
Geir Istad | ffe210a | 2017-02-06 20:02:30 +0100 | [diff] [blame] | 108 | function), turning them into SRTP packets. Similarly, SRTP packets |
| 109 | can be decrypted and have their authentication verified (using the |
Geir Istad | 1195df6 | 2017-02-16 06:17:56 +0100 | [diff] [blame] | 110 | `srtp_unprotect()` function), turning them into RTP packets. Similar |
Geir Istad | ffe210a | 2017-02-06 20:02:30 +0100 | [diff] [blame] | 111 | functions apply security to RTCP packets. |
| 112 | |
| 113 | The typedef `srtp_stream_t` points to a structure holding all of the |
| 114 | state associated with an SRTP stream, including the keys and |
| 115 | parameters for cipher and message authentication functions and the |
| 116 | anti-replay data. A particular `srtp_stream_t` holds the information |
| 117 | needed to protect a particular RTP and RTCP stream. This datatype |
| 118 | is intentionally opaque in order to better seperate the libSRTP |
| 119 | API from its implementation. |
| 120 | |
| 121 | Within an SRTP session, there can be multiple streams, each |
| 122 | originating from a particular sender. Each source uses a distinct |
| 123 | stream context to protect the RTP and RTCP stream that it is |
| 124 | originating. The typedef `srtp_t` points to a structure holding all of |
| 125 | the state associated with an SRTP session. There can be multiple |
| 126 | stream contexts associated with a single `srtp_t`. A stream context |
| 127 | cannot exist indepent from an `srtp_t`, though of course an `srtp_t` can |
| 128 | be created that contains only a single stream context. A device |
| 129 | participating in an SRTP session must have a stream context for each |
| 130 | source in that session, so that it can process the data that it |
| 131 | receives from each sender. |
| 132 | |
| 133 | In libSRTP, a session is created using the function `srtp_create()`. |
| 134 | The policy to be implemented in the session is passed into this |
| 135 | function as an `srtp_policy_t` structure. A single one of these |
| 136 | structures describes the policy of a single stream. These structures |
| 137 | can also be linked together to form an entire session policy. A linked |
| 138 | list of `srtp_policy_t` structures is equivalent to a session policy. |
Geir Istad | 1195df6 | 2017-02-16 06:17:56 +0100 | [diff] [blame] | 139 | In such a policy, we refer to a single `srtp_policy_t` as an *element*. |
Geir Istad | ffe210a | 2017-02-06 20:02:30 +0100 | [diff] [blame] | 140 | |
Sean DuBois | b173a64 | 2019-07-11 08:24:41 +0100 | [diff] [blame] | 141 | An `srtp_policy_t` structure contains two `srtp_crypto_policy_t` structures |
Geir Istad | ffe210a | 2017-02-06 20:02:30 +0100 | [diff] [blame] | 142 | that describe the cryptograhic policies for RTP and RTCP, as well as |
| 143 | the SRTP master key and the SSRC value. The SSRC describes what to |
Sean DuBois | b173a64 | 2019-07-11 08:24:41 +0100 | [diff] [blame] | 144 | protect (e.g. which stream), and the `srtp_crypto_policy_t` structures |
Geir Istad | ffe210a | 2017-02-06 20:02:30 +0100 | [diff] [blame] | 145 | describe how to protect it. The key is contained in a policy element |
| 146 | because it simplifies the interface to the library. In many cases, it |
| 147 | is desirable to use the same cryptographic policies across all of the |
| 148 | streams in a session, but to use a distinct key for each stream. A |
Sean DuBois | b173a64 | 2019-07-11 08:24:41 +0100 | [diff] [blame] | 149 | `srtp_crypto_policy_t` structure can be initialized by using either the |
| 150 | `srtp_crypto_policy_set_rtp_default()` or `srtp_crypto_policy_set_rtcp_default()` |
Geir Istad | ffe210a | 2017-02-06 20:02:30 +0100 | [diff] [blame] | 151 | functions, which set a crypto policy structure to the default policies |
| 152 | for RTP and RTCP protection, respectively. |
| 153 | |
| 154 | -------------------------------------------------------------------------------- |
| 155 | |
Geir Istad | b48849a | 2017-02-08 07:24:22 +0100 | [diff] [blame] | 156 | <a name="secure-rtp-background"></a> |
| 157 | ## Secure RTP Background |
| 158 | |
| 159 | In this section we review SRTP and introduce some terms that are used |
| 160 | in libSRTP. An RTP session is defined by a pair of destination |
| 161 | transport addresses, that is, a network address plus a pair of UDP |
| 162 | ports for RTP and RTCP. RTCP, the RTP control protocol, is used to |
| 163 | coordinate between the participants in an RTP session, e.g. to provide |
| 164 | feedback from receivers to senders. An *SRTP session* is |
| 165 | similarly defined; it is just an RTP session for which the SRTP |
| 166 | profile is being used. An SRTP session consists of the traffic sent |
| 167 | to the SRTP or SRTCP destination transport addresses. Each |
| 168 | participant in a session is identified by a synchronization source |
| 169 | (SSRC) identifier. Some participants may not send any SRTP traffic; |
| 170 | they are called receivers, even though they send out SRTCP traffic, |
| 171 | such as receiver reports. |
| 172 | |
| 173 | RTP allows multiple sources to send RTP and RTCP traffic during the |
| 174 | same session. The synchronization source identifier (SSRC) is used to |
| 175 | distinguish these sources. In libSRTP, we call the SRTP and SRTCP |
| 176 | traffic from a particular source a *stream*. Each stream has its own |
| 177 | SSRC, sequence number, rollover counter, and other data. A particular |
| 178 | choice of options, cryptographic mechanisms, and keys is called a |
| 179 | *policy*. Each stream within a session can have a distinct policy |
| 180 | applied to it. A session policy is a collection of stream policies. |
| 181 | |
| 182 | A single policy can be used for all of the streams in a given session, |
| 183 | though the case in which a single *key* is shared across multiple |
| 184 | streams requires care. When key sharing is used, the SSRC values that |
| 185 | identify the streams **must** be distinct. This requirement can be |
| 186 | enforced by using the convention that each SRTP and SRTCP key is used |
| 187 | for encryption by only a single sender. In other words, the key is |
| 188 | shared only across streams that originate from a particular device (of |
| 189 | course, other SRTP participants will need to use the key for |
| 190 | decryption). libSRTP supports this enforcement by detecting the case |
| 191 | in which a key is used for both inbound and outbound data. |
| 192 | |
| 193 | -------------------------------------------------------------------------------- |
| 194 | |
| 195 | <a name="supported-features"></a> |
| 196 | ## Supported Features |
| 197 | |
| 198 | This library supports all of the mandatory-to-implement features of |
Geir Istad | 6367867 | 2017-03-27 06:41:30 +0200 | [diff] [blame] | 199 | SRTP (as defined in [RFC 3711](https://www.ietf.org/rfc/rfc3711.txt)). Some of these |
Geir Istad | b48849a | 2017-02-08 07:24:22 +0100 | [diff] [blame] | 200 | features can be selected (or de-selected) at run time by setting an |
| 201 | appropriate policy; this is done using the structure `srtp_policy_t`. |
| 202 | Some other behaviors of the protocol can be adapted by defining an |
| 203 | approriate event handler for the exceptional events; see the SRTPevents |
| 204 | section in the generated documentation. |
| 205 | |
Geir Istad | b48849a | 2017-02-08 07:24:22 +0100 | [diff] [blame] | 206 | Some options that are described in the SRTP specification are not |
| 207 | supported. This includes |
| 208 | |
Geir Istad | b48849a | 2017-02-08 07:24:22 +0100 | [diff] [blame] | 209 | - key derivation rates other than zero, |
| 210 | - the cipher F8, |
Geir Istad | b48849a | 2017-02-08 07:24:22 +0100 | [diff] [blame] | 211 | - the use of the packet index to select between master keys. |
| 212 | |
| 213 | The user should be aware that it is possible to misuse this libary, |
| 214 | and that the result may be that the security level it provides is |
| 215 | inadequate. If you are implementing a feature using this library, you |
Geir Istad | 6367867 | 2017-03-27 06:41:30 +0200 | [diff] [blame] | 216 | will want to read the Security Considerations section of [RFC 3711](https://www.ietf.org/rfc/rfc3711.txt). |
| 217 | In addition, it is important that you read and understand the |
Geir Istad | b48849a | 2017-02-08 07:24:22 +0100 | [diff] [blame] | 218 | terms outlined in the [License and Disclaimer](#license-and-disclaimer) section. |
| 219 | |
| 220 | -------------------------------------------------------------------------------- |
| 221 | |
| 222 | <a name="implementation-notes"></a> |
| 223 | ## Implementation Notes |
| 224 | |
| 225 | * The `srtp_protect()` function assumes that the buffer holding the |
| 226 | rtp packet has enough storage allocated that the authentication |
| 227 | tag can be written to the end of that packet. If this assumption |
| 228 | is not valid, memory corruption will ensue. |
| 229 | |
| 230 | * Automated tests for the crypto functions are provided through |
| 231 | the `cipher_type_self_test()` and `auth_type_self_test()` functions. |
| 232 | These functions should be used to test each port of this code |
| 233 | to a new platform. |
| 234 | |
| 235 | * Replay protection is contained in the crypto engine, and |
| 236 | tests for it are provided. |
| 237 | |
| 238 | * This implementation provides calls to initialize, protect, and |
| 239 | unprotect RTP packets, and makes as few as possible assumptions |
| 240 | about how these functions will be called. For example, the |
| 241 | caller is not expected to provide packets in order (though if |
| 242 | they're called more than 65k out of sequence, synchronization |
| 243 | will be lost). |
| 244 | |
| 245 | * The sequence number in the rtp packet is used as the low 16 bits |
| 246 | of the sender's local packet index. Note that RTP will start its |
| 247 | sequence number in a random place, and the SRTP layer just jumps |
| 248 | forward to that number at its first invocation. An earlier |
| 249 | version of this library used initial sequence numbers that are |
| 250 | less than 32,768; this trick is no longer required as the |
| 251 | `rdbx_estimate_index(...)` function has been made smarter. |
| 252 | |
Geir Istad | 2165755 | 2017-03-23 06:50:00 +0100 | [diff] [blame] | 253 | * The replay window for (S)RTCP is hardcoded to 128 bits in length. |
Geir Istad | b48849a | 2017-02-08 07:24:22 +0100 | [diff] [blame] | 254 | |
| 255 | -------------------------------------------------------------------------------- |
| 256 | |
Geir Istad | bf486d3 | 2017-02-08 07:18:10 +0100 | [diff] [blame] | 257 | <a name="installing-and-building-libsrtp"></a> |
| 258 | # Installing and Building libSRTP |
Geir Istad | de51ff4 | 2017-02-06 06:53:16 +0100 | [diff] [blame] | 259 | |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 260 | To install libSRTP, download the latest release of the distribution |
Geir Istad | 1195df6 | 2017-02-16 06:17:56 +0100 | [diff] [blame] | 261 | from [https://github.com/cisco/libsrtp/releases](https://github.com/cisco/libsrtp/releases). |
| 262 | You probably want to get the most recent release. Unpack the distribution and |
Jonathan Lennox | d942596 | 2010-06-01 18:26:12 +0000 | [diff] [blame] | 263 | extract the source files; the directory into which the source files |
Geir Istad | ffe210a | 2017-02-06 20:02:30 +0100 | [diff] [blame] | 264 | will go is named `libsrtp-A-B-C` where `A` is the version number, `B` is the |
| 265 | major release number and `C` is the minor release number. |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 266 | |
Geir Istad | ffe210a | 2017-02-06 20:02:30 +0100 | [diff] [blame] | 267 | libSRTP uses the GNU `autoconf` and `make` utilities (BSD make will not work; if |
| 268 | both versions of make are on your platform, you can invoke GNU make as |
| 269 | `gmake`.). In the `libsrtp` directory, run the configure script and then |
Geir Istad | d1bef50 | 2017-02-03 08:25:54 +0100 | [diff] [blame] | 270 | make: |
Geir Istad | 200d3bc | 2017-02-03 06:56:37 +0100 | [diff] [blame] | 271 | |
Geir Istad | d1bef50 | 2017-02-03 08:25:54 +0100 | [diff] [blame] | 272 | ~~~.txt |
| 273 | ./configure [ options ] |
| 274 | make |
Geir Istad | 200d3bc | 2017-02-03 06:56:37 +0100 | [diff] [blame] | 275 | ~~~ |
| 276 | |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 277 | The configure script accepts the following options: |
Geir Istad | 200d3bc | 2017-02-03 06:56:37 +0100 | [diff] [blame] | 278 | |
Geir Istad | 8b51b3f | 2017-03-22 19:02:44 +0100 | [diff] [blame] | 279 | Option | Description |
| 280 | -------------------------------|-------------------- |
| 281 | \-\-help \-h | Display help |
| 282 | \-\-enable-debug-logging | Enable debug logging in all modules |
| 283 | \-\-enable-log-stdout | Enable logging to stdout |
| 284 | \-\-enable-openssl | Enable OpenSSL crypto engine |
| 285 | \-\-enable-openssl-kdf | Enable OpenSSL KDF algorithm |
| 286 | \-\-with-log-file | Use file for logging |
| 287 | \-\-with-openssl-dir | Location of OpenSSL installation |
Geir Istad | 200d3bc | 2017-02-03 06:56:37 +0100 | [diff] [blame] | 288 | |
Paul E. Jones | c448087 | 2017-02-21 16:42:32 -0500 | [diff] [blame] | 289 | By default there is no log output, logging can be enabled to be output to stdout |
Pascal Bühler | 1b333ec | 2017-02-16 08:50:59 +0100 | [diff] [blame] | 290 | or a given file using the configure options. |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 291 | |
| 292 | This package has been tested on the following platforms: Mac OS X |
| 293 | (powerpc-apple-darwin1.4), Cygwin (i686-pc-cygwin), Solaris |
| 294 | (sparc-sun-solaris2.6), RedHat Linux 7.1 and 9 (i686-pc-linux), and |
| 295 | OpenBSD (sparc-unknown-openbsd2.7). |
| 296 | |
Geir Istad | 200d3bc | 2017-02-03 06:56:37 +0100 | [diff] [blame] | 297 | -------------------------------------------------------------------------------- |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 298 | |
Richard Barnes | b1108b5 | 2017-08-14 09:19:53 -0400 | [diff] [blame] | 299 | <a name="changing-build-configuration"></a> |
| 300 | ## Changing Build Configuration |
| 301 | |
| 302 | To build the `./configure` script mentioned above, libSRTP relies on the |
| 303 | [automake](https://www.gnu.org/software/automake/) toolchain. Since |
| 304 | `./configure` is built from `configure.in` by automake, if you make changes in |
| 305 | how `./configure` works (e.g., to add a new library dependency), you will need |
| 306 | to rebuild `./configure` and commit the updated version. In addition to |
| 307 | automake itself, you will need to have the `pkgconfig` tools installed as well. |
| 308 | |
| 309 | For example, on macOS: |
| 310 | |
| 311 | ``` |
| 312 | brew install automake pkgconfig |
| 313 | # Edit configure.in |
| 314 | autoremake -ivf |
| 315 | ``` |
| 316 | |
| 317 | -------------------------------------------------------------------------------- |
Johan 't Hart | 23a3ce1 | 2019-06-13 10:18:49 +0200 | [diff] [blame] | 318 | <a name="using-visual-studio"></a> |
| 319 | ## Using Visual Studio |
| 320 | |
| 321 | On Windows one can use Visual Studio via CMake. CMake can be downloaded here: |
| 322 | https://cmake.org/ . To create Visual Studio build files, for example run the |
| 323 | following commands: |
| 324 | |
| 325 | ``` |
| 326 | # Create build subdirectory |
| 327 | mkdir build |
| 328 | cd build |
| 329 | |
| 330 | # Make project files |
| 331 | cmake .. -G "Visual Studio 15 2017" |
| 332 | |
| 333 | # Or for 64 bit project files |
| 334 | cmake .. -G "Visual Studio 15 2017 Win64" |
| 335 | ``` |
| 336 | |
| 337 | -------------------------------------------------------------------------------- |
Richard Barnes | b1108b5 | 2017-08-14 09:19:53 -0400 | [diff] [blame] | 338 | |
Geir Istad | bf486d3 | 2017-02-08 07:18:10 +0100 | [diff] [blame] | 339 | <a name="applications"></a> |
| 340 | # Applications |
Geir Istad | de51ff4 | 2017-02-06 06:53:16 +0100 | [diff] [blame] | 341 | |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 342 | Several test drivers and a simple and portable srtp application are |
Geir Istad | 200d3bc | 2017-02-03 06:56:37 +0100 | [diff] [blame] | 343 | included in the `test/` subdirectory. |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 344 | |
Geir Istad | d1bef50 | 2017-02-03 08:25:54 +0100 | [diff] [blame] | 345 | Test driver | Function tested |
| 346 | --------- | ------- |
| 347 | kernel_driver | crypto kernel (ciphers, auth funcs, rng) |
| 348 | srtp_driver | srtp in-memory tests (does not use the network) |
| 349 | rdbx_driver | rdbx (extended replay database) |
| 350 | roc_driver | extended sequence number functions |
| 351 | replay_driver | replay database |
| 352 | cipher_driver | ciphers |
| 353 | auth_driver | hash functions |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 354 | |
Geir Istad | ffe210a | 2017-02-06 20:02:30 +0100 | [diff] [blame] | 355 | The app `rtpw` is a simple rtp application which reads words from |
Geir Istad | d1bef50 | 2017-02-03 08:25:54 +0100 | [diff] [blame] | 356 | `/usr/dict/words` and then sends them out one at a time using [s]rtp. |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 357 | Manual srtp keying uses the -k option; automated key management |
| 358 | using gdoi will be added later. |
| 359 | |
Geir Istad | ffe210a | 2017-02-06 20:02:30 +0100 | [diff] [blame] | 360 | usage: |
Geir Istad | d1bef50 | 2017-02-03 08:25:54 +0100 | [diff] [blame] | 361 | ~~~.txt |
Geir Istad | ffe210a | 2017-02-06 20:02:30 +0100 | [diff] [blame] | 362 | rtpw [[-d <debug>]* [-k|b <key> [-a][-e <key size>][-g]] [-s | -r] dest_ip dest_port] | [-l] |
Geir Istad | d1bef50 | 2017-02-03 08:25:54 +0100 | [diff] [blame] | 363 | ~~~ |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 364 | |
| 365 | Either the -s (sender) or -r (receiver) option must be chosen. The |
Geir Istad | d1bef50 | 2017-02-03 08:25:54 +0100 | [diff] [blame] | 366 | values `dest_ip`, `dest_port` are the IP address and UDP port to which |
Geir Istad | ffe210a | 2017-02-06 20:02:30 +0100 | [diff] [blame] | 367 | the dictionary will be sent, respectively. |
Geir Istad | 200d3bc | 2017-02-03 06:56:37 +0100 | [diff] [blame] | 368 | |
Geir Istad | ffe210a | 2017-02-06 20:02:30 +0100 | [diff] [blame] | 369 | The options are: |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 370 | |
Geir Istad | ffe210a | 2017-02-06 20:02:30 +0100 | [diff] [blame] | 371 | Option | Description |
| 372 | --------- | ------- |
| 373 | -s | (S)RTP sender - causes app to send words |
| 374 | -r | (S)RTP receive - causes app to receive words |
| 375 | -k <key> | use SRTP master key <key>, where the key is a hexadecimal (without the leading "0x") |
| 376 | -b <key> | same as -k but with base64 encoded key |
| 377 | -e <keysize> | encrypt/decrypt (for data confidentiality) (requires use of -k option as well) (use 128, 192, or 256 for keysize) |
| 378 | -g | use AES-GCM mode (must be used with -e) |
| 379 | -a | message authentication (requires use of -k option as well) |
| 380 | -l | list the available debug modules |
| 381 | -d <debug> | turn on debugging for module <debug> |
| 382 | |
| 383 | In order to get random 30-byte values for use as key/salt pairs , you |
| 384 | can use the following bash function to format the output of |
| 385 | `/dev/random` (where that device is available). |
| 386 | |
| 387 | ~~~.txt |
| 388 | function randhex() { |
| 389 | cat /dev/random | od --read-bytes=32 --width=32 -x | awk '{ print $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14 $15 $16 }' |
| 390 | } |
| 391 | ~~~ |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 392 | |
| 393 | An example of an SRTP session using two rtpw programs follows: |
| 394 | |
Geir Istad | d1bef50 | 2017-02-03 08:25:54 +0100 | [diff] [blame] | 395 | ~~~.txt |
Geir Istad | de51ff4 | 2017-02-06 06:53:16 +0100 | [diff] [blame] | 396 | set k=c1eec3717da76195bb878578790af71c4ee9f859e197a414a78d5abc7451 |
| 397 | |
| 398 | [sh1]$ test/rtpw -s -k $k -e 128 -a 0.0.0.0 9999 |
| 399 | Security services: confidentiality message authentication |
| 400 | set master key/salt to C1EEC3717DA76195BB878578790AF71C/4EE9F859E197A414A78D5ABC7451 |
| 401 | setting SSRC to 2078917053 |
| 402 | sending word: A |
| 403 | sending word: a |
| 404 | sending word: aa |
| 405 | sending word: aal |
| 406 | ... |
| 407 | |
| 408 | [sh2]$ test/rtpw -r -k $k -e 128 -a 0.0.0.0 9999 |
| 409 | security services: confidentiality message authentication |
| 410 | set master key/salt to C1EEC3717DA76195BB878578790AF71C/4EE9F859E197A414A78D5ABC7451 |
| 411 | 19 octets received from SSRC 2078917053 word: A |
| 412 | 19 octets received from SSRC 2078917053 word: a |
| 413 | 20 octets received from SSRC 2078917053 word: aa |
| 414 | 21 octets received from SSRC 2078917053 word: aal |
| 415 | ... |
Geir Istad | ffe210a | 2017-02-06 20:02:30 +0100 | [diff] [blame] | 416 | ~~~ |
Geir Istad | 200d3bc | 2017-02-03 06:56:37 +0100 | [diff] [blame] | 417 | |
| 418 | -------------------------------------------------------------------------------- |
| 419 | |
Geir Istad | bf486d3 | 2017-02-08 07:18:10 +0100 | [diff] [blame] | 420 | <a name="example-code"></a> |
| 421 | ## Example Code |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 422 | |
Geir Istad | ffe210a | 2017-02-06 20:02:30 +0100 | [diff] [blame] | 423 | This section provides a simple example of how to use libSRTP. The |
| 424 | example code lacks error checking, but is functional. Here we assume |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 425 | that the value ssrc is already set to describe the SSRC of the stream |
Geir Istad | ffe210a | 2017-02-06 20:02:30 +0100 | [diff] [blame] | 426 | that we are sending, and that the functions `get_rtp_packet()` and |
| 427 | `send_srtp_packet()` are available to us. The former puts an RTP packet |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 428 | into the buffer and returns the number of octets written to that |
Geir Istad | ffe210a | 2017-02-06 20:02:30 +0100 | [diff] [blame] | 429 | buffer. The latter sends the RTP packet in the buffer, given the |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 430 | length as its second argument. |
| 431 | |
Geir Istad | d1bef50 | 2017-02-03 08:25:54 +0100 | [diff] [blame] | 432 | ~~~.c |
Geir Istad | ffe210a | 2017-02-06 20:02:30 +0100 | [diff] [blame] | 433 | srtp_t session; |
| 434 | srtp_policy_t policy; |
Geir Istad | d397c77 | 2017-02-16 06:47:44 +0100 | [diff] [blame] | 435 | |
| 436 | // Set key to predetermined value |
| 437 | uint8_t key[30] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 438 | 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
| 439 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 440 | 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D}; |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 441 | |
Geir Istad | ffe210a | 2017-02-06 20:02:30 +0100 | [diff] [blame] | 442 | // initialize libSRTP |
| 443 | srtp_init(); |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 444 | |
escrichov | 3e7812c | 2017-05-30 19:27:19 +0200 | [diff] [blame] | 445 | // default policy values |
| 446 | memset(&policy, 0x0, sizeof(srtp_policy_t)); |
| 447 | |
Geir Istad | ffe210a | 2017-02-06 20:02:30 +0100 | [diff] [blame] | 448 | // set policy to describe a policy for an SRTP stream |
Sean DuBois | b173a64 | 2019-07-11 08:24:41 +0100 | [diff] [blame] | 449 | srtp_crypto_policy_set_rtp_default(&policy.rtp); |
| 450 | srtp_crypto_policy_set_rtcp_default(&policy.rtcp); |
Geir Istad | ffe210a | 2017-02-06 20:02:30 +0100 | [diff] [blame] | 451 | policy.ssrc = ssrc; |
| 452 | policy.key = key; |
| 453 | policy.next = NULL; |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 454 | |
Geir Istad | ffe210a | 2017-02-06 20:02:30 +0100 | [diff] [blame] | 455 | // allocate and initialize the SRTP session |
| 456 | srtp_create(&session, &policy); |
Geir Istad | 200d3bc | 2017-02-03 06:56:37 +0100 | [diff] [blame] | 457 | |
Geir Istad | ffe210a | 2017-02-06 20:02:30 +0100 | [diff] [blame] | 458 | // main loop: get rtp packets, send srtp packets |
| 459 | while (1) { |
| 460 | char rtp_buffer[2048]; |
| 461 | unsigned len; |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 462 | |
Geir Istad | ffe210a | 2017-02-06 20:02:30 +0100 | [diff] [blame] | 463 | len = get_rtp_packet(rtp_buffer); |
| 464 | srtp_protect(session, rtp_buffer, &len); |
| 465 | send_srtp_packet(rtp_buffer, len); |
| 466 | } |
Geir Istad | d1bef50 | 2017-02-03 08:25:54 +0100 | [diff] [blame] | 467 | ~~~ |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 468 | |
Geir Istad | 200d3bc | 2017-02-03 06:56:37 +0100 | [diff] [blame] | 469 | -------------------------------------------------------------------------------- |
| 470 | |
Geir Istad | bf486d3 | 2017-02-08 07:18:10 +0100 | [diff] [blame] | 471 | <a name="credits"></a> |
| 472 | # Credits |
Geir Istad | 820ef80 | 2017-02-07 07:22:11 +0100 | [diff] [blame] | 473 | |
| 474 | The original implementation and documentation of libSRTP was written |
| 475 | by David McGrew of Cisco Systems, Inc. in order to promote the use, |
| 476 | understanding, and interoperability of Secure RTP. Michael Jerris |
| 477 | contributed support for building under MSVC. Andris Pavenis |
| 478 | contributed many important fixes. Brian West contributed changes to |
| 479 | enable dynamic linking. Yves Shumann reported documentation bugs. |
| 480 | Randell Jesup contributed a working SRTCP implementation and other |
Pascal Bühler | 5b19fce | 2017-02-16 09:22:43 +0100 | [diff] [blame] | 481 | fixes. Steve Underwood contributed x86_64 portability changes. We also give |
Geir Istad | 820ef80 | 2017-02-07 07:22:11 +0100 | [diff] [blame] | 482 | thanks to Fredrik Thulin, Brian Weis, Mark Baugher, Jeff Chan, Bill |
| 483 | Simon, Douglas Smith, Bill May, Richard Preistley, Joe Tardo and |
| 484 | others for contributions, comments, and corrections. |
| 485 | |
| 486 | This reference material, when applicable, in this documenation was generated |
| 487 | using the doxygen utility for automatic documentation of source code. |
| 488 | |
| 489 | Copyright 2001-2005 by David A. McGrew, Cisco Systems, Inc. |
Geir Istad | a7c5daf | 2017-02-07 07:33:59 +0100 | [diff] [blame] | 490 | |
| 491 | -------------------------------------------------------------------------------- |
| 492 | |
Geir Istad | bf486d3 | 2017-02-08 07:18:10 +0100 | [diff] [blame] | 493 | <a name="references"></a> |
| 494 | # References |
Geir Istad | a7c5daf | 2017-02-07 07:33:59 +0100 | [diff] [blame] | 495 | |
| 496 | SRTP and ICM References |
| 497 | September, 2005 |
| 498 | |
| 499 | Secure RTP is defined in [RFC 3711](https://www.ietf.org/rfc/rfc3711.txt). |
| 500 | The counter mode definition is in Section 4.1.1. |
| 501 | |
Geir Istad | 96d462f | 2017-03-22 19:29:53 +0100 | [diff] [blame] | 502 | SHA-1 is defined in [FIPS PUB 180-4](http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf). |
Geir Istad | a7c5daf | 2017-02-07 07:33:59 +0100 | [diff] [blame] | 503 | |
Geir Istad | 66c48ff | 2017-03-21 06:38:34 +0100 | [diff] [blame] | 504 | HMAC is defined in [RFC 2104](https://www.ietf.org/rfc/rfc2104.txt) |
Geir Istad | a7c5daf | 2017-02-07 07:33:59 +0100 | [diff] [blame] | 505 | and HMAC-SHA1 test vectors are available |
Geir Istad | 66c48ff | 2017-03-21 06:38:34 +0100 | [diff] [blame] | 506 | in [RFC 2202](https://www.ietf.org/rfc/rfc2202.txt). |
| 507 | |
| 508 | AES-GCM usage in SRTP is defined in [RFC 7714](https://www.ietf.org/html/rfc7714) |