2010-06-08 05:29:08 +00:00
|
|
|
/*
|
|
|
|
* Asterisk -- An open source telephony toolkit.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 - 2007, Mikael Magnusson
|
|
|
|
*
|
|
|
|
* Mikael Magnusson <mikma@users.sourceforge.net>
|
|
|
|
*
|
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
2015-05-17 12:15:15 +00:00
|
|
|
/*! \file
|
2010-06-08 05:29:08 +00:00
|
|
|
*
|
2013-06-22 14:03:22 +00:00
|
|
|
* \brief SRTP and SDP Security descriptions
|
2010-06-08 05:29:08 +00:00
|
|
|
*
|
2013-06-22 14:03:22 +00:00
|
|
|
* Specified in RFC 3711
|
2010-06-08 05:29:08 +00:00
|
|
|
* Specified in RFC 4568
|
|
|
|
*
|
|
|
|
* \author Mikael Magnusson <mikma@users.sourceforge.net>
|
|
|
|
*/
|
|
|
|
|
2012-06-15 16:20:16 +00:00
|
|
|
/*** MODULEINFO
|
|
|
|
<support_level>core</support_level>
|
|
|
|
***/
|
|
|
|
|
2010-06-08 05:29:08 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
git migration: Refactor the ASTERISK_FILE_VERSION macro
Git does not support the ability to replace a token with a version
string during check-in. While it does have support for replacing a
token on clone, this is somewhat sub-optimal: the token is replaced
with the object hash, which is not particularly easy for human
consumption. What's more, in practice, the source file version was often
not terribly useful. Generally, when triaging bugs, the overall version
of Asterisk is far more useful than an individual SVN version of a file. As a
result, this patch removes Asterisk's support for showing source file
versions.
Specifically, it does the following:
* Rename ASTERISK_FILE_VERSION macro to ASTERISK_REGISTER_FILE, and
remove passing the version in with the macro. Other facilities
than 'core show file version' make use of the file names, such as
setting a debug level only on a specific file. As such, the act of
registering source files with the Asterisk core still has use. The
macro rename now reflects the new macro purpose.
* main/asterisk:
- Refactor the file_version structure to reflect that it no longer
tracks a version field.
- Remove the "core show file version" CLI command. Without the file
version, it is no longer useful.
- Remove the ast_file_version_find function. The file version is no
longer tracked.
- Rename ast_register_file_version/ast_unregister_file_version to
ast_register_file/ast_unregister_file, respectively.
* main/manager: Remove value from the Version key of the ModuleCheck
Action. The actual key itself has not been removed, as doing so would
absolutely constitute a backwards incompatible change. However, since
the file version is no longer tracked, there is no need to attempt to
include it in the Version key.
* UPGRADE: Add notes for:
- Modification to the ModuleCheck AMI Action
- Removal of the "core show file version" CLI command
Change-Id: I6cf0ff280e1668bf4957dc21f32a5ff43444a40e
2015-04-12 02:38:22 +00:00
|
|
|
ASTERISK_REGISTER_FILE()
|
2010-06-08 05:29:08 +00:00
|
|
|
|
2015-02-25 21:42:39 +00:00
|
|
|
#include <math.h>
|
2010-06-08 05:29:08 +00:00
|
|
|
#include "asterisk/options.h"
|
|
|
|
#include "asterisk/utils.h"
|
2013-06-22 14:03:22 +00:00
|
|
|
#include "asterisk/sdp_srtp.h"
|
2010-06-08 05:29:08 +00:00
|
|
|
|
|
|
|
#define SRTP_MASTER_LEN 30
|
|
|
|
#define SRTP_MASTERKEY_LEN 16
|
|
|
|
#define SRTP_MASTERSALT_LEN ((SRTP_MASTER_LEN) - (SRTP_MASTERKEY_LEN))
|
|
|
|
#define SRTP_MASTER_LEN64 (((SRTP_MASTER_LEN) * 8 + 5) / 6 + 1)
|
|
|
|
|
|
|
|
extern struct ast_srtp_res *res_srtp;
|
|
|
|
extern struct ast_srtp_policy_res *res_srtp_policy;
|
|
|
|
|
2013-06-22 14:03:22 +00:00
|
|
|
struct ast_sdp_srtp *ast_sdp_srtp_alloc(void)
|
|
|
|
{
|
|
|
|
if (!ast_rtp_engine_srtp_is_registered()) {
|
|
|
|
ast_debug(1, "No SRTP module loaded, can't setup SRTP session.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ast_calloc(1, sizeof(struct ast_sdp_srtp));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ast_sdp_srtp_destroy(struct ast_sdp_srtp *srtp)
|
|
|
|
{
|
|
|
|
if (srtp->crypto) {
|
|
|
|
ast_sdp_crypto_destroy(srtp->crypto);
|
|
|
|
}
|
|
|
|
srtp->crypto = NULL;
|
|
|
|
ast_free(srtp);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ast_sdp_crypto {
|
2010-06-08 05:29:08 +00:00
|
|
|
char *a_crypto;
|
|
|
|
unsigned char local_key[SRTP_MASTER_LEN];
|
2015-02-25 21:42:39 +00:00
|
|
|
int tag;
|
2010-06-08 05:29:08 +00:00
|
|
|
char local_key64[SRTP_MASTER_LEN64];
|
2012-09-09 01:28:31 +00:00
|
|
|
unsigned char remote_key[SRTP_MASTER_LEN];
|
2010-06-08 05:29:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int set_crypto_policy(struct ast_srtp_policy *policy, int suite_val, const unsigned char *master_key, unsigned long ssrc, int inbound);
|
|
|
|
|
2013-06-22 14:03:22 +00:00
|
|
|
void ast_sdp_crypto_destroy(struct ast_sdp_crypto *crypto)
|
2010-06-08 05:29:08 +00:00
|
|
|
{
|
|
|
|
ast_free(crypto->a_crypto);
|
|
|
|
crypto->a_crypto = NULL;
|
|
|
|
ast_free(crypto);
|
|
|
|
}
|
|
|
|
|
2013-06-22 14:03:22 +00:00
|
|
|
struct ast_sdp_crypto *ast_sdp_crypto_alloc(void)
|
2010-06-08 05:29:08 +00:00
|
|
|
{
|
2013-06-22 14:03:22 +00:00
|
|
|
struct ast_sdp_crypto *p;
|
2010-06-08 05:29:08 +00:00
|
|
|
int key_len;
|
|
|
|
unsigned char remote_key[SRTP_MASTER_LEN];
|
|
|
|
|
|
|
|
if (!ast_rtp_engine_srtp_is_registered()) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-06-22 14:03:22 +00:00
|
|
|
if (!(p = ast_calloc(1, sizeof(*p)))) {
|
2010-06-08 05:29:08 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2015-02-25 21:42:39 +00:00
|
|
|
p->tag = 1;
|
2010-06-08 05:29:08 +00:00
|
|
|
|
|
|
|
if (res_srtp->get_random(p->local_key, sizeof(p->local_key)) < 0) {
|
2013-06-22 14:03:22 +00:00
|
|
|
ast_sdp_crypto_destroy(p);
|
2010-06-08 05:29:08 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_base64encode(p->local_key64, p->local_key, SRTP_MASTER_LEN, sizeof(p->local_key64));
|
|
|
|
|
|
|
|
key_len = ast_base64decode(remote_key, p->local_key64, sizeof(remote_key));
|
|
|
|
|
|
|
|
if (key_len != SRTP_MASTER_LEN) {
|
|
|
|
ast_log(LOG_ERROR, "base64 encode/decode bad len %d != %d\n", key_len, SRTP_MASTER_LEN);
|
2015-02-25 21:42:39 +00:00
|
|
|
ast_sdp_crypto_destroy(p);
|
2010-06-08 05:29:08 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (memcmp(remote_key, p->local_key, SRTP_MASTER_LEN)) {
|
|
|
|
ast_log(LOG_ERROR, "base64 encode/decode bad key\n");
|
2015-02-25 21:42:39 +00:00
|
|
|
ast_sdp_crypto_destroy(p);
|
2010-06-08 05:29:08 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_debug(1 , "local_key64 %s len %zu\n", p->local_key64, strlen(p->local_key64));
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int set_crypto_policy(struct ast_srtp_policy *policy, int suite_val, const unsigned char *master_key, unsigned long ssrc, int inbound)
|
|
|
|
{
|
|
|
|
const unsigned char *master_salt = NULL;
|
|
|
|
|
|
|
|
if (!ast_rtp_engine_srtp_is_registered()) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
master_salt = master_key + SRTP_MASTERKEY_LEN;
|
|
|
|
if (res_srtp_policy->set_master_key(policy, master_key, SRTP_MASTERKEY_LEN, master_salt, SRTP_MASTERSALT_LEN) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (res_srtp_policy->set_suite(policy, suite_val)) {
|
|
|
|
ast_log(LOG_WARNING, "Could not set remote SRTP suite\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
res_srtp_policy->set_ssrc(policy, ssrc, inbound);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-22 14:03:22 +00:00
|
|
|
static int crypto_activate(struct ast_sdp_crypto *p, int suite_val, unsigned char *remote_key, struct ast_rtp_instance *rtp)
|
2010-06-08 05:29:08 +00:00
|
|
|
{
|
|
|
|
struct ast_srtp_policy *local_policy = NULL;
|
|
|
|
struct ast_srtp_policy *remote_policy = NULL;
|
|
|
|
struct ast_rtp_instance_stats stats = {0,};
|
|
|
|
int res = -1;
|
|
|
|
|
|
|
|
if (!ast_rtp_engine_srtp_is_registered()) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!p) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(local_policy = res_srtp_policy->alloc())) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(remote_policy = res_srtp_policy->alloc())) {
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ast_rtp_instance_get_stats(rtp, &stats, AST_RTP_INSTANCE_STAT_LOCAL_SSRC)) {
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (set_crypto_policy(local_policy, suite_val, p->local_key, stats.local_ssrc, 0) < 0) {
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (set_crypto_policy(remote_policy, suite_val, remote_key, 0, 1) < 0) {
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2012-02-24 15:10:35 +00:00
|
|
|
/* Add the SRTP policies */
|
|
|
|
if (ast_rtp_instance_add_srtp_policy(rtp, remote_policy, local_policy)) {
|
|
|
|
ast_log(LOG_WARNING, "Could not set SRTP policies\n");
|
2010-06-08 05:29:08 +00:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_debug(1 , "SRTP policy activated\n");
|
|
|
|
res = 0;
|
|
|
|
|
|
|
|
err:
|
|
|
|
if (local_policy) {
|
|
|
|
res_srtp_policy->destroy(local_policy);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (remote_policy) {
|
|
|
|
res_srtp_policy->destroy(remote_policy);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2013-06-22 14:03:22 +00:00
|
|
|
int ast_sdp_crypto_process(struct ast_rtp_instance *rtp, struct ast_sdp_srtp *srtp, const char *attr)
|
2010-06-08 05:29:08 +00:00
|
|
|
{
|
|
|
|
char *str = NULL;
|
|
|
|
char *tag = NULL;
|
|
|
|
char *suite = NULL;
|
|
|
|
char *key_params = NULL;
|
|
|
|
char *key_param = NULL;
|
|
|
|
char *session_params = NULL;
|
2015-02-25 21:42:39 +00:00
|
|
|
char *key_salt = NULL; /* The actual master key and key salt */
|
|
|
|
char *lifetime = NULL; /* Key lifetime (# of RTP packets) */
|
|
|
|
char *mki = NULL; /* Master Key Index */
|
2010-06-08 05:29:08 +00:00
|
|
|
int found = 0;
|
|
|
|
int key_len = 0;
|
|
|
|
int suite_val = 0;
|
|
|
|
unsigned char remote_key[SRTP_MASTER_LEN];
|
2013-01-29 17:46:30 +00:00
|
|
|
int taglen = 0;
|
2015-02-25 21:42:39 +00:00
|
|
|
double sdes_lifetime;
|
2013-06-22 14:03:22 +00:00
|
|
|
struct ast_sdp_crypto *crypto = srtp->crypto;
|
2010-06-08 05:29:08 +00:00
|
|
|
|
|
|
|
if (!ast_rtp_engine_srtp_is_registered()) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
str = ast_strdupa(attr);
|
|
|
|
|
|
|
|
tag = strsep(&str, " ");
|
|
|
|
suite = strsep(&str, " ");
|
|
|
|
key_params = strsep(&str, " ");
|
|
|
|
session_params = strsep(&str, " ");
|
|
|
|
|
|
|
|
if (!tag || !suite) {
|
2014-10-06 12:39:03 +00:00
|
|
|
ast_log(LOG_WARNING, "Unrecognized crypto attribute a=%s\n", attr);
|
2010-06-08 05:29:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-05-19 18:01:36 +00:00
|
|
|
/* RFC4568 9.1 - tag is 1-9 digits, greater than zero */
|
|
|
|
if (sscanf(tag, "%30d", &crypto->tag) != 1 || crypto->tag <= 0 || crypto->tag > 999999999) {
|
2015-02-25 21:42:39 +00:00
|
|
|
ast_log(LOG_WARNING, "Unacceptable a=crypto tag: %s\n", tag);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-07-16 12:35:04 +00:00
|
|
|
if (!ast_strlen_zero(session_params)) {
|
2014-10-06 12:39:03 +00:00
|
|
|
ast_log(LOG_WARNING, "Unsupported crypto parameters: %s\n", session_params);
|
2010-06-08 05:29:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(suite, "AES_CM_128_HMAC_SHA1_80")) {
|
|
|
|
suite_val = AST_AES_CM_128_HMAC_SHA1_80;
|
2013-06-22 14:03:22 +00:00
|
|
|
ast_set_flag(srtp, AST_SRTP_CRYPTO_TAG_80);
|
2013-01-29 17:46:30 +00:00
|
|
|
taglen = 80;
|
2010-06-08 05:29:08 +00:00
|
|
|
} else if (!strcmp(suite, "AES_CM_128_HMAC_SHA1_32")) {
|
|
|
|
suite_val = AST_AES_CM_128_HMAC_SHA1_32;
|
2013-06-22 14:03:22 +00:00
|
|
|
ast_set_flag(srtp, AST_SRTP_CRYPTO_TAG_32);
|
2013-01-29 17:46:30 +00:00
|
|
|
taglen = 32;
|
2010-06-08 05:29:08 +00:00
|
|
|
} else {
|
|
|
|
ast_log(LOG_WARNING, "Unsupported crypto suite: %s\n", suite);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((key_param = strsep(&key_params, ";"))) {
|
2015-02-25 21:42:39 +00:00
|
|
|
unsigned int n_lifetime;
|
2010-06-08 05:29:08 +00:00
|
|
|
char *method = NULL;
|
|
|
|
char *info = NULL;
|
|
|
|
|
|
|
|
method = strsep(&key_param, ":");
|
|
|
|
info = strsep(&key_param, ";");
|
2015-02-25 21:42:39 +00:00
|
|
|
sdes_lifetime = 0;
|
2010-06-08 05:29:08 +00:00
|
|
|
|
2015-02-25 21:42:39 +00:00
|
|
|
if (strcmp(method, "inline")) {
|
|
|
|
continue;
|
|
|
|
}
|
2010-06-08 05:29:08 +00:00
|
|
|
|
2015-02-25 21:42:39 +00:00
|
|
|
key_salt = strsep(&info, "|");
|
2010-06-08 05:29:08 +00:00
|
|
|
|
2015-02-25 21:42:39 +00:00
|
|
|
/* The next parameter can be either lifetime or MKI */
|
|
|
|
lifetime = strsep(&info, "|");
|
|
|
|
if (!lifetime) {
|
2010-06-08 05:29:08 +00:00
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
2015-02-25 21:42:39 +00:00
|
|
|
|
|
|
|
mki = strchr(lifetime, ':');
|
|
|
|
if (mki) {
|
|
|
|
mki = lifetime;
|
|
|
|
lifetime = NULL;
|
|
|
|
} else {
|
|
|
|
mki = strsep(&info, "|");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mki && *mki != '1') {
|
|
|
|
ast_log(LOG_NOTICE, "Crypto MKI handling is not supported: ignoring attribute %s\n", attr);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lifetime) {
|
|
|
|
if (!strncmp(lifetime, "2^", 2)) {
|
|
|
|
char *lifetime_val = lifetime + 2;
|
|
|
|
|
|
|
|
/* Exponential lifetime */
|
|
|
|
if (sscanf(lifetime_val, "%30u", &n_lifetime) != 1) {
|
|
|
|
ast_log(LOG_NOTICE, "Failed to parse lifetime value in crypto attribute: %s\n", attr);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n_lifetime > 48) {
|
|
|
|
/* Yeah... that's a bit big. */
|
|
|
|
ast_log(LOG_NOTICE, "Crypto lifetime exponent of '%u' is a bit large; using 48\n", n_lifetime);
|
|
|
|
n_lifetime = 48;
|
|
|
|
}
|
|
|
|
sdes_lifetime = pow(2, n_lifetime);
|
|
|
|
} else {
|
|
|
|
/* Decimal lifetime */
|
|
|
|
if (sscanf(lifetime, "%30u", &n_lifetime) != 1) {
|
|
|
|
ast_log(LOG_NOTICE, "Failed to parse lifetime value in crypto attribute: %s\n", attr);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
sdes_lifetime = n_lifetime;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Accept anything above 10 hours. Less than 10; reject. */
|
|
|
|
if (sdes_lifetime < 1800000) {
|
|
|
|
ast_log(LOG_NOTICE, "Rejecting crypto attribute '%s': lifetime '%f' too short\n", attr, sdes_lifetime);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_debug(2, "Crypto attribute '%s' accepted with lifetime '%f', MKI '%s'\n",
|
|
|
|
attr, sdes_lifetime, mki ? mki : "-");
|
|
|
|
|
|
|
|
found = 1;
|
|
|
|
break;
|
2010-06-08 05:29:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
2015-02-25 21:42:39 +00:00
|
|
|
ast_log(LOG_NOTICE, "SRTP crypto offer not acceptable: '%s'\n", attr);
|
2010-06-08 05:29:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-02-25 21:42:39 +00:00
|
|
|
key_len = ast_base64decode(remote_key, key_salt, sizeof(remote_key));
|
|
|
|
if (key_len != SRTP_MASTER_LEN) {
|
|
|
|
ast_log(LOG_WARNING, "SRTP descriptions key length '%d' != master length '%d'\n",
|
|
|
|
key_len, SRTP_MASTER_LEN);
|
2010-06-08 05:29:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-06-22 14:03:22 +00:00
|
|
|
if (!memcmp(crypto->remote_key, remote_key, sizeof(crypto->remote_key))) {
|
2012-09-09 01:28:31 +00:00
|
|
|
ast_debug(1, "SRTP remote key unchanged; maintaining current policy\n");
|
2013-06-22 14:03:22 +00:00
|
|
|
ast_set_flag(srtp, AST_SRTP_CRYPTO_OFFER_OK);
|
2012-09-09 01:28:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2013-06-22 14:03:22 +00:00
|
|
|
memcpy(crypto->remote_key, remote_key, sizeof(crypto->remote_key));
|
2012-09-09 01:28:31 +00:00
|
|
|
|
2013-06-22 14:03:22 +00:00
|
|
|
if (crypto_activate(crypto, suite_val, remote_key, rtp) < 0) {
|
2010-06-08 05:29:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-01-29 17:46:30 +00:00
|
|
|
/* Finally, rebuild the crypto line */
|
2013-06-22 14:03:22 +00:00
|
|
|
if (ast_sdp_crypto_build_offer(crypto, taglen)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_set_flag(srtp, AST_SRTP_CRYPTO_OFFER_OK);
|
|
|
|
return 0;
|
2010-06-08 05:29:08 +00:00
|
|
|
}
|
|
|
|
|
2013-06-22 14:03:22 +00:00
|
|
|
int ast_sdp_crypto_build_offer(struct ast_sdp_crypto *p, int taglen)
|
2010-06-08 05:29:08 +00:00
|
|
|
{
|
2013-01-29 17:46:30 +00:00
|
|
|
/* Rebuild the crypto line */
|
2010-06-08 05:29:08 +00:00
|
|
|
if (p->a_crypto) {
|
2013-01-29 17:46:30 +00:00
|
|
|
ast_free(p->a_crypto);
|
2010-06-08 05:29:08 +00:00
|
|
|
}
|
|
|
|
|
2015-02-25 21:42:39 +00:00
|
|
|
if (ast_asprintf(&p->a_crypto, "%d AES_CM_128_HMAC_SHA1_%i inline:%s",
|
|
|
|
p->tag, taglen, p->local_key64) == -1) {
|
2013-01-29 17:46:30 +00:00
|
|
|
ast_log(LOG_ERROR, "Could not allocate memory for crypto line\n");
|
2010-06-08 05:29:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-06-22 14:03:22 +00:00
|
|
|
ast_debug(1, "Crypto line: a=crypto:%s\n", p->a_crypto);
|
2010-06-08 05:29:08 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-22 14:03:22 +00:00
|
|
|
const char *ast_sdp_srtp_get_attrib(struct ast_sdp_srtp *srtp, int dtls_enabled, int default_taglen_32)
|
|
|
|
{
|
|
|
|
int taglen = default_taglen_32 ? 32 : 80;
|
|
|
|
|
|
|
|
if (!srtp) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set encryption properties */
|
|
|
|
if (!srtp->crypto) {
|
|
|
|
srtp->crypto = ast_sdp_crypto_alloc();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dtls_enabled) {
|
|
|
|
/* If DTLS-SRTP is enabled the key details will be pulled from TLS */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set the key length based on INVITE or settings */
|
|
|
|
if (ast_test_flag(srtp, AST_SRTP_CRYPTO_TAG_80)) {
|
|
|
|
taglen = 80;
|
|
|
|
} else if (ast_test_flag(srtp, AST_SRTP_CRYPTO_TAG_32)) {
|
|
|
|
taglen = 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (srtp->crypto && (ast_sdp_crypto_build_offer(srtp->crypto, taglen) >= 0)) {
|
|
|
|
return srtp->crypto->a_crypto;
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_log(LOG_WARNING, "No SRTP key management enabled\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-06-30 19:51:28 +00:00
|
|
|
char *ast_sdp_get_rtp_profile(unsigned int sdes_active, struct ast_rtp_instance *instance, unsigned int using_avpf,
|
|
|
|
unsigned int force_avp)
|
2010-06-08 05:29:08 +00:00
|
|
|
{
|
2013-06-22 14:03:22 +00:00
|
|
|
struct ast_rtp_engine_dtls *dtls;
|
|
|
|
|
|
|
|
if ((dtls = ast_rtp_instance_get_dtls(instance)) && dtls->active(instance)) {
|
2014-06-30 19:51:28 +00:00
|
|
|
if (force_avp) {
|
|
|
|
return using_avpf ? "RTP/SAVPF" : "RTP/SAVP";
|
|
|
|
} else {
|
|
|
|
return using_avpf ? "UDP/TLS/RTP/SAVPF" : "UDP/TLS/RTP/SAVP";
|
|
|
|
}
|
2013-06-22 14:03:22 +00:00
|
|
|
} else {
|
|
|
|
if (using_avpf) {
|
|
|
|
return sdes_active ? "RTP/SAVPF" : "RTP/AVPF";
|
|
|
|
} else {
|
|
|
|
return sdes_active ? "RTP/SAVP" : "RTP/AVP";
|
|
|
|
}
|
|
|
|
}
|
2010-06-08 05:29:08 +00:00
|
|
|
}
|
2013-06-22 14:03:22 +00:00
|
|
|
|