36 #include "asterisk/options.h"
38 #include "include/sdp_crypto.h"
40 #define SRTP_MASTER_LEN 30
41 #define SRTP_MASTERKEY_LEN 16
42 #define SRTP_MASTERSALT_LEN ((SRTP_MASTER_LEN) - (SRTP_MASTERKEY_LEN))
43 #define SRTP_MASTER_LEN64 (((SRTP_MASTER_LEN) * 8 + 5) / 6 + 1)
115 const unsigned char *master_salt = NULL;
126 if (res_srtp_policy->
set_suite(policy, suite_val)) {
131 res_srtp_policy->
set_ssrc(policy, ssrc, inbound);
151 if (!(local_policy = res_srtp_policy->
alloc())) {
155 if (!(remote_policy = res_srtp_policy->
alloc())) {
177 ast_debug(1 ,
"SRTP policy activated\n");
182 res_srtp_policy->
destroy(local_policy);
186 res_srtp_policy->
destroy(remote_policy);
197 char *key_params = NULL;
198 char *key_param = NULL;
199 char *session_params = NULL;
200 char *key_salt = NULL;
201 char *lifetime = NULL;
215 suite =
strsep(&str,
" ");
216 key_params =
strsep(&str,
" ");
217 session_params =
strsep(&str,
" ");
219 if (!tag || !suite) {
224 if (session_params) {
229 if (!strcmp(suite,
"AES_CM_128_HMAC_SHA1_80")) {
231 }
else if (!strcmp(suite,
"AES_CM_128_HMAC_SHA1_32")) {
238 while ((key_param =
strsep(&key_params,
";"))) {
242 method =
strsep(&key_param,
":");
243 info =
strsep(&key_param,
";");
245 if (!strcmp(method,
"inline")) {
246 key_salt =
strsep(&info,
"|");
247 lifetime =
strsep(&info,
"|");
270 ast_debug(1,
"SRTP remote key unchanged; maintaining current policy\n");
283 ast_debug(1,
"Accepting crypto tag %s\n", tag);
299 strcpy(p->
suite,
"AES_CM_128_HMAC_SHA1_80");
struct ast_srtp_policy_res * res_srtp_policy
void(* set_ssrc)(struct ast_srtp_policy *policy, unsigned long ssrc, int inbound)
Asterisk main include file. File version handling, generic pbx functions.
char * strsep(char **str, const char *delims)
#define SRTP_MASTERKEY_LEN
unsigned char remote_key[SRTP_MASTER_LEN]
int ast_rtp_instance_get_stats(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat)
Retrieve statistics about an RTP instance.
unsigned char local_key[SRTP_MASTER_LEN]
struct sdp_crypto * sdp_crypto_setup(void)
#define SRTP_MASTERSALT_LEN
void(* destroy)(struct ast_srtp_policy *policy)
void sdp_crypto_destroy(struct sdp_crypto *crypto)
int ast_rtp_instance_add_srtp_policy(struct ast_rtp_instance *instance, struct ast_srtp_policy *remote_policy, struct ast_srtp_policy *local_policy)
Add or replace the SRTP policies for the given RTP instance.
#define SRTP_MASTER_LEN64
char local_key64[SRTP_MASTER_LEN64]
#define ast_asprintf(a, b, c...)
int ast_base64decode(unsigned char *dst, const char *src, int max)
Decode data from base64.
#define ast_debug(level,...)
Log a DEBUG message.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
struct ast_srtp_policy *(* alloc)(void)
int(* set_suite)(struct ast_srtp_policy *policy, enum ast_srtp_suite suite)
#define ast_strdupa(s)
duplicate a string in memory from the stack
const char * sdp_crypto_attrib(struct sdp_crypto *p)
static int set_crypto_policy(struct ast_srtp_policy *policy, int suite_val, const unsigned char *master_key, unsigned long ssrc, int inbound)
static int sdp_crypto_activate(struct sdp_crypto *p, int suite_val, unsigned char *remote_key, struct ast_rtp_instance *rtp)
int ast_base64encode(char *dst, const unsigned char *src, int srclen, int max)
Encode data in base64.
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
struct ast_srtp_res * res_srtp
int sdp_crypto_offer(struct sdp_crypto *p)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
int ast_rtp_engine_srtp_is_registered(void)
int(* get_random)(unsigned char *key, size_t len)
int sdp_crypto_process(struct sdp_crypto *p, const char *attr, struct ast_rtp_instance *rtp)
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
int(* set_master_key)(struct ast_srtp_policy *policy, const unsigned char *key, size_t key_len, const unsigned char *salt, size_t salt_len)
static struct sdp_crypto * sdp_crypto_alloc(void)