chenqiyang
2021-08-27 6a63c4281fbe7e17103115320cd276397d733081
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
 * Copyright (c) 2010-2019 Belledonne Communications SARL.
 *
 * This file is part of mediastreamer2.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
 
#ifndef ms_srtp_h
#define ms_srtp_h
 
#include <ortp/rtpsession.h>
#include "mediastreamer2/mscommon.h"
 
#ifdef __cplusplus
extern "C"{
#endif
/* defined in mediastream.h */
#ifndef MS_MEDIA_STREAM_SESSIONS_DEFINED
typedef struct _MSMediaStreamSessions MSMediaStreamSessions;
#define MS_MEDIA_STREAM_SESSIONS_DEFINED 1
#endif
 
/*
 * Crypto suite used configure encrypted stream*/
typedef enum _MSCryptoSuite{
        MS_CRYPTO_SUITE_INVALID=0,
        MS_AES_128_SHA1_80,
        MS_AES_128_SHA1_32,
        MS_AES_128_NO_AUTH,
        MS_NO_CIPHER_SHA1_80,
        MS_AES_256_SHA1_80,
        MS_AES_CM_256_SHA1_80,
        MS_AES_256_SHA1_32
} MSCryptoSuite;
 
typedef struct _MSCryptoSuiteNameParams{
        const char *name;
        const char *params;
}MSCryptoSuiteNameParams;
 
MS2_PUBLIC MSCryptoSuite ms_crypto_suite_build_from_name_params(const MSCryptoSuiteNameParams *nameparams);
MS2_PUBLIC int ms_crypto_suite_to_name_params(MSCryptoSuite cs, MSCryptoSuiteNameParams *nameparams);
 
 
/* defined in srtp.h*/
typedef struct _MSSrtpCtx MSSrtpCtx;
 
typedef enum {
    MSSRTP_RTP_STREAM,
    MSSRTP_RTCP_STREAM,
    MSSRTP_ALL_STREAMS
} MSSrtpStreamType;
/**
 * return humanly readable string
 * @param[in]    type
 * @return
 *
 * */
MS2_PUBLIC const char * ms_srtp_stream_type_to_string(const MSSrtpStreamType type);
/**
 * Check if SRTP is supported
 * @return true if SRTP is supported
 */
MS2_PUBLIC bool_t ms_srtp_supported(void);
 
/**
 * Set encryption requirements.
 * srtp session might be created/deleted depending on requirement parameter and already set keys
 * @param[in/out]    sessions    The sessions associated to the current media stream
 * @param[in]        yesno        If yes, any incoming/outgoing rtp packets are silently discarded.
 * until keys are provided using functions #media_stream_set_srtp_recv_key_b64 or #media_stream_set_srtp_recv_key
 * @return    0 on success, error code otherwise
 */
 
MS2_PUBLIC int ms_media_stream_sessions_set_encryption_mandatory(MSMediaStreamSessions *sessions, bool_t yesno);
 
/**
 * Get encryption requirements.
 * @param[in/out]    sessions    The sessions associated to the current media stream
 * @return    TRUE if only encrypted rtp packet shall be sent/received
 */
 
MS2_PUBLIC bool_t ms_media_stream_sessions_get_encryption_mandatory(const MSMediaStreamSessions *sessions);
 
/**
 * Set srtp receiver key for the given media stream.
 * If no srtp session exists on the stream it is created, if it already exists srtp policy is created/modified for the receiver side of the stream.
 *
 * @param[in/out]    sessions    The sessions associated to the current media stream
 * @param[in]        suite        The srtp crypto suite to use
 * @param[in]        key        Srtp master key and master salt in a base 64 NULL terminated string
 * @return    0 on success, error code otherwise
 */
MS2_PUBLIC int ms_media_stream_sessions_set_srtp_recv_key_b64(MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* key);
 
/**
 * Set srtp receiver key for the given media stream.
 * If no srtp session exists on the stream it is created, if it already exists srtp policy is created/modified for the receiver side of the stream.
 *
 * @param[in/out]    sessions    The sessions associated to the current media stream
 * @param[in]        suite        The srtp crypto suite to use
 * @param[in]        key        Srtp master key and master salt
 * @param[in]        key_length    key buffer length
 * @param[in]        stream_type    Srtp suite is applied to RTP stream, RTCP stream or both
 * @return    0 on success, error code otherwise
 */
MS2_PUBLIC int ms_media_stream_sessions_set_srtp_recv_key(MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* key, size_t key_length, MSSrtpStreamType stream_type);
 
/**
 * Set srtp sender key for the given media stream.
 * If no srtp session exists on the stream it is created, if it already exists srtp policy is created/modified for the sender side of the stream.
 *
 * @param[in/out]    sessions    The sessions associated to the current media stream
 * @param[in]        suite    The srtp crypto suite to use
 * @param[in]        key    Srtp master key and master salt in a base 64 NULL terminated string
 * @return    0 on success, error code otherwise
 */
MS2_PUBLIC int ms_media_stream_sessions_set_srtp_send_key_b64(MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* key);
 
/**
 * Set srtp sender key for the given media stream.
 * If no srtp session exists on the stream it is created, if it already exists srtp policy is created/modified for the sender side of the stream.
 *
 * @param[in/out]    stream    The mediastream to operate on
 * @param[in]        suite        The srtp crypto suite to use
 * @param[in]        key        Srtp master key and master salt
 * @param[in]        key_length    key buffer length
 * @param[in]        stream_type    Srtp suite is applied to RTP stream, RTCP stream or both
 * @return    0 on success, error code otherwise
 */
MS2_PUBLIC int ms_media_stream_sessions_set_srtp_send_key(MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* key, size_t key_length, MSSrtpStreamType stream_type);
 
 
#ifdef __cplusplus
}
#endif
 
#endif /* ms_srtp_h */