Commit ff7f866d authored by Pierre-Eric's avatar Pierre-Eric
Browse files

Add TLS support to Linphone

parent ce132604
......@@ -487,6 +487,11 @@ static void sip_config_read(LinphoneCore *lc)
} else {
tr.tcp_port=lp_config_get_int(lc->config,"sip","sip_tcp_port",0);
}
if (lp_config_get_int(lc->config,"sip","sip_tls_random_port",0)) {
tr.tls_port=(0xDFF&+random())+1024;
} else {
tr.tls_port=lp_config_get_int(lc->config,"sip","sip_tls_port",0);
}
/*start listening on ports*/
linphone_core_set_sip_transports(lc,&tr);
......@@ -1358,7 +1363,7 @@ void linphone_core_set_use_rfc2833_for_dtmf(LinphoneCore *lc,bool_t use_rfc2833)
int linphone_core_get_sip_port(LinphoneCore *lc)
{
LCSipTransports *tr=&lc->sip_conf.transports;
return tr->udp_port>0 ? tr->udp_port : tr->tcp_port;
return tr->udp_port>0 ? tr->udp_port : (tr->tcp_port > 0 ? tr->tcp_port : tr->tls_port);
}
static char _ua_name[64]="Linphone";
......@@ -1419,13 +1424,18 @@ static int apply_transports(LinphoneCore *lc){
sal_unlisten_ports (sal);
if (tr->udp_port>0){
if (sal_listen_port (sal,anyaddr,tr->udp_port,SalTransportUDP,FALSE)!=0){
transport_error(lc,"UDP",tr->udp_port);
transport_error(lc,"udp",tr->udp_port);
return -1;
}
}
if (tr->tcp_port>0){
if (sal_listen_port (sal,anyaddr,tr->tcp_port,SalTransportTCP,FALSE)!=0){
transport_error(lc,"TCP",tr->tcp_port);
transport_error(lc,"tcp",tr->tcp_port);
}
}
if (tr->tls_port>0){
if (sal_listen_port (sal,anyaddr,tr->tls_port,SalTransportTLS,TRUE)!=0){
transport_error(lc,"tls",tr->tls_port);
}
}
apply_user_agent(lc);
......@@ -3746,6 +3756,7 @@ void sip_config_uninit(LinphoneCore *lc)
sip_config_t *config=&lc->sip_conf;
lp_config_set_int(lc->config,"sip","sip_port",config->transports.udp_port);
lp_config_set_int(lc->config,"sip","sip_tcp_port",config->transports.tcp_port);
lp_config_set_int(lc->config,"sip","sip_tls_port",config->transports.tls_port);
lp_config_set_int(lc->config,"sip","guess_hostname",config->guess_hostname);
lp_config_set_string(lc->config,"sip","contact",config->contact);
lp_config_set_int(lc->config,"sip","inc_timeout",config->inc_timeout);
......
......@@ -258,8 +258,12 @@ static char *guess_contact_for_register(LinphoneProxyConfig *obj){
linphone_address_set_display_name(contact,NULL);
linphone_core_get_sip_transports(obj->lc,&tr);
if (tr.udp_port <= 0 && tr.tcp_port>0) {
sal_address_set_param(contact,"transport","TCP");
if (tr.udp_port <= 0) {
if (tr.tcp_port>0) {
sal_address_set_param(contact,"transport","tcp");
} else if (tr.tls_port>0) {
sal_address_set_param(contact,"transport","tls");
}
}
ret=linphone_address_as_string(contact);
linphone_address_destroy(contact);
......
......@@ -26,10 +26,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "sal.h"
const char* sal_transport_to_string(SalTransport transport) {
switch (transport) {
case SalTransportUDP:return "UDP";
case SalTransportTCP: return "TCP";
case SalTransportTLS:return "TLS";
case SalTransportDTLS:return "DTLS";
case SalTransportUDP:return "udp";
case SalTransportTCP: return "tcp";
case SalTransportTLS:return "tls";
case SalTransportDTLS:return "dtls";
default: {
ms_fatal("Unexpected transport [%i]",transport);
return NULL;
......@@ -38,10 +38,10 @@ const char* sal_transport_to_string(SalTransport transport) {
}
}
SalTransport sal_transport_parse(const char* param) {
if (strcasecmp("UDP",param)==0) return SalTransportUDP;
if (strcasecmp("TCP",param)==0) return SalTransportTCP;
if (strcasecmp("TLS",param)==0) return SalTransportTLS;
if (strcasecmp("DTLS",param)==0) return SalTransportDTLS;
if (strcasecmp("udp",param)==0) return SalTransportUDP;
if (strcasecmp("tcp",param)==0) return SalTransportTCP;
if (strcasecmp("tls",param)==0) return SalTransportTLS;
if (strcasecmp("dtls",param)==0) return SalTransportDTLS;
ms_error("Unkown transport type[%s], returning UDP", param);
return SalTransportUDP;
}
......
......@@ -362,6 +362,7 @@ int sal_listen_port(Sal *ctx, const char *addr, int port, SalTransport tr, int i
eXosip_set_option (EXOSIP_OPT_UDP_KEEP_ALIVE, &keepalive);
break;
case SalTransportTCP:
case SalTransportTLS:
proto= IPPROTO_TCP;
keepalive=-1;
eXosip_set_option (EXOSIP_OPT_UDP_KEEP_ALIVE,&keepalive);
......@@ -382,11 +383,11 @@ int sal_listen_port(Sal *ctx, const char *addr, int port, SalTransport tr, int i
ipv6=strchr(addr,':')!=NULL;
eXosip_enable_ipv6(ipv6);
if (is_secure){
ms_fatal("SIP over TLS or DTLS is not supported yet.");
if (is_secure && tr == SalTransportUDP){
ms_fatal("SIP over DTLS is not supported yet.");
return -1;
}
err=eXosip_listen_addr(proto, addr, port, ipv6 ? PF_INET6 : PF_INET, 0);
err=eXosip_listen_addr(proto, addr, port, ipv6 ? PF_INET6 : PF_INET, is_secure);
#ifdef HAVE_EXOSIP_GET_SOCKET
ms_message("Exosip has socket number %i",eXosip_get_socket(proto));
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment