1 /* 2 mediastreamer2 library - modular sound and video processing and streaming 3 Copyright (C) 2014 Belledonne Communications 4 5 This library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Lesser General Public 7 License as published by the Free Software Foundation; either 8 version 2.1 of the License, or (at your option) any later version. 9 10 This library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Lesser General Public License for more details. 14 15 You should have received a copy of the GNU Lesser General Public 16 License along with this library; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 */ 19 20 #ifndef ms_dtls_srtp_h 21 #define ms_dtls_srtp_h 22 23 #include <ortp/rtpsession.h> 24 #include "mediastreamer2/mscommon.h" 25 26 #ifdef __cplusplus 27 extern "C"{ 28 #endif 29 30 /* defined in mediastream.h */ 31 struct _MSMediaStreamSessions; 32 33 typedef enum { 34 MSDtlsSrtpRoleInvalid, 35 MSDtlsSrtpRoleIsServer, 36 MSDtlsSrtpRoleIsClient, 37 MSDtlsSrtpRoleUnset 38 } MSDtlsSrtpRole; 39 40 typedef struct MSDtlsSrtpParams { 41 const char *pem_certificate; /**< Self certificate in pem format */ 42 const char *pem_pkey; /**< Private key associated to self certificate */ 43 MSDtlsSrtpRole role; /**< Unset(at caller init, role is then choosen by responder but we must still be able to receive packets) */ 44 } MSDtlsSrtpParams; 45 46 /* an opaque structure containing all context data needed by DTLS-SRTP */ 47 typedef struct _MSDtlsSrtpContext MSDtlsSrtpContext; 48 49 /** 50 * check if DTLS-SRTP is available 51 * @return TRUE if it is available, FALSE if not 52 */ 53 MS2_PUBLIC bool_t ms_dtls_srtp_available(void); 54 55 /** 56 * Create an initialise a DTLS-SRTP context 57 * @param[in] sessions A link to the stream sessions structures, used to get rtp session to add transport modifier and needed to set SRTP sessions when keys are ready 58 * @param[in] params Self certificate and private key to be used for this session. Role (client/server) may be given but can be set later 59 * @return a pointer to the opaque context structure needed by DTLS-SRTP 60 */ 61 MS2_PUBLIC MSDtlsSrtpContext* ms_dtls_srtp_context_new(struct _MSMediaStreamSessions *sessions, MSDtlsSrtpParams *params); 62 63 /** 64 * Start the DTLS-SRTP channel: send DTLS ClientHello if we are client 65 * @param[in/out] context the DTLS-SRTP context 66 */ 67 MS2_PUBLIC void ms_dtls_srtp_start(MSDtlsSrtpContext* context); 68 69 /** 70 * Free ressources used by DTLS-SRTP context 71 * @param[in/out] context the DTLS-SRTP context 72 */ 73 MS2_PUBLIC void ms_dtls_srtp_context_destroy(MSDtlsSrtpContext *ctx); 74 75 /** 76 * Set DTLS role: server or client, called when SDP exchange reach the point where we can determine self role 77 * @param[in/out] context the DTLS-SRTP context 78 * @param[in] role Client/Server/Invalid/Unset according to SDP INVITE processing 79 */ 80 MS2_PUBLIC void ms_dtls_srtp_set_role(MSDtlsSrtpContext *context, MSDtlsSrtpRole role); 81 82 /** 83 * Give to the DTLS-SRTP context the peer certificate fingerprint extracted from trusted SDP INVITE, 84 * it will be compared(case insensitive) with locally computed one after DTLS handshake is completed successfully and peer certicate retrieved 85 * @param[in/out] context the DTLS-SRTP context 86 * @param[in] peer_fingerprint a null terminated string containing the peer certificate as found in the SDP INVITE(including the heading hash algorithm name) 87 */ 88 MS2_PUBLIC void ms_dtls_srtp_set_peer_fingerprint(MSDtlsSrtpContext *context, const char *peer_fingerprint); 89 90 #ifdef __cplusplus 91 } 92 #endif 93 94 #endif /* ms_dtls_srtp_h */ 95