--- channels/chan_sip.c 2014-06-30 22:42:18.000000000 +0300 +++ channels/chan_sip.c_dtls_patch 2014-07-27 16:58:41.944973540 +0300 @@ -2283,6 +2283,9 @@ static struct ast_tls_config sip_tls_cfg /*! \brief Default TLS connection configuration */ static struct ast_tls_config default_tls_cfg; +/*! \brief Default DTLS connection configuration */ +static struct ast_rtp_dtls_cfg default_dtls_cfg; + /*! \brief The TCP server definition */ static struct ast_tcptls_session_args sip_tcp_desc = { .accept_fd = -1, @@ -30784,6 +30787,12 @@ static struct sip_peer *build_peer(const peer->named_callgroups = ast_unref_namedgroups(peer->named_callgroups); peer->named_pickupgroups = ast_unref_namedgroups(peer->named_pickupgroups); + /*Set some of default DTLS parameters */ + peer->dtls_cfg.rekey = default_dtls_cfg.rekey; + peer->dtls_cfg.default_setup = default_dtls_cfg.default_setup; + peer->dtls_cfg.hash = default_dtls_cfg.hash; + peer->dtls_cfg.verify = default_dtls_cfg.verify; + for (; v || ((v = alt) && !(alt=NULL)); v = v->next) { if (!devstate_only) { if (handle_common_options(&peerflags[0], &mask[0], v)) { @@ -31138,6 +31147,30 @@ static struct sip_peer *build_peer(const ast_rtp_dtls_cfg_parse(&peer->dtls_cfg, v->name, v->value); } } + + /* If we are missing DTLS config settings and it is enabled, try to load from default ones */ + if (peer->dtls_cfg.enabled) { + if (ast_strlen_zero(peer->dtls_cfg.certfile) && !ast_strlen_zero(default_dtls_cfg.certfile)) { + ast_free(peer->dtls_cfg.certfile); + peer->dtls_cfg.certfile = ast_strdup(default_dtls_cfg.certfile); + } + if (ast_strlen_zero(peer->dtls_cfg.pvtfile) && !ast_strlen_zero(default_dtls_cfg.pvtfile)) { + ast_free(peer->dtls_cfg.pvtfile); + peer->dtls_cfg.pvtfile = ast_strdup(default_dtls_cfg.pvtfile); + } + if (ast_strlen_zero(peer->dtls_cfg.cipher) && !ast_strlen_zero(default_dtls_cfg.cipher)) { + ast_free(peer->dtls_cfg.cipher); + peer->dtls_cfg.cipher = ast_strdup(default_dtls_cfg.cipher); + } + if (ast_strlen_zero(peer->dtls_cfg.cafile) && !ast_strlen_zero(default_dtls_cfg.cafile)) { + ast_free(peer->dtls_cfg.cafile); + peer->dtls_cfg.cafile = ast_strdup(default_dtls_cfg.cafile); + } + if (ast_strlen_zero(peer->dtls_cfg.capath) && !ast_strlen_zero(default_dtls_cfg.capath)) { + ast_free(peer->dtls_cfg.capath); + peer->dtls_cfg.capath = ast_strdup(default_dtls_cfg.capath); + } + } /* Apply the encryption tag length to the DTLS configuration, in case DTLS is in use */ peer->dtls_cfg.suite = (ast_test_flag(&peer->flags[2], SIP_PAGE3_SRTP_TAG_32) ? AST_AES_CM_128_HMAC_SHA1_32 : AST_AES_CM_128_HMAC_SHA1_80); @@ -31539,6 +31572,7 @@ static int reload_config(enum channelrel sip_cfg.contact_acl = ast_free_acl_list(sip_cfg.contact_acl); default_tls_cfg.enabled = FALSE; /* Default: Disable TLS */ + default_dtls_cfg.enabled = FALSE; /* As well disable dtls by default */ if (reason != CHANNEL_MODULE_LOAD) { ast_debug(4, "--------------- SIP reload started\n"); @@ -31566,12 +31600,22 @@ static int reload_config(enum channelrel ast_free(default_tls_cfg.cipher); ast_free(default_tls_cfg.cafile); ast_free(default_tls_cfg.capath); + ast_free(default_dtls_cfg.certfile); + ast_free(default_dtls_cfg.pvtfile); + ast_free(default_dtls_cfg.cipher); + ast_free(default_dtls_cfg.cafile); + ast_free(default_dtls_cfg.capath); } default_tls_cfg.certfile = ast_strdup(AST_CERTFILE); /*XXX Not sure if this is useful */ default_tls_cfg.pvtfile = ast_strdup(""); default_tls_cfg.cipher = ast_strdup(""); default_tls_cfg.cafile = ast_strdup(""); default_tls_cfg.capath = ast_strdup(""); + default_dtls_cfg.certfile = ast_strdup(""); + default_dtls_cfg.pvtfile = ast_strdup(""); + default_dtls_cfg.cipher = ast_strdup(""); + default_dtls_cfg.cafile = ast_strdup(""); + default_dtls_cfg.capath = ast_strdup(""); /* Initialize copy of current sip_cfg.regcontext for later use in removing stale contexts */ ast_copy_string(oldcontexts, sip_cfg.regcontext, sizeof(oldcontexts)); @@ -31751,6 +31795,9 @@ static int reload_config(enum channelrel continue; } + /* Load default dtls configuration */ + ast_rtp_dtls_cfg_parse(&default_dtls_cfg, v->name, v->value); + if (!strcasecmp(v->name, "context")) { ast_copy_string(sip_cfg.default_context, v->value, sizeof(sip_cfg.default_context)); } else if (!strcasecmp(v->name, "recordonfeature")) { @@ -34957,6 +35004,12 @@ static int unload_module(void) ast_free(default_tls_cfg.cafile); ast_free(default_tls_cfg.capath); + ast_free(default_dtls_cfg.certfile); + ast_free(default_dtls_cfg.pvtfile); + ast_free(default_dtls_cfg.cipher); + ast_free(default_dtls_cfg.cafile); + ast_free(default_dtls_cfg.capath); + cleanup_all_regs(); ASTOBJ_CONTAINER_DESTROYALL(®l, sip_registry_destroy); ASTOBJ_CONTAINER_DESTROY(®l);