Commit f56dbf86 authored by jehan's avatar jehan

start TLS transport debug

parent cacabcae
......@@ -199,7 +199,7 @@
</scannerInfoProvider>
</profile>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.macosx.base.557244179;cdt.managedbuild.toolchain.gnu.macosx.base.557244179.779699347;cdt.managedbuild.tool.gnu.c.compiler.macosx.base.1327025999;cdt.managedbuild.tool.gnu.c.compiler.input.1517483722">
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.macosx.base.557244179.959032290;cdt.managedbuild.toolchain.gnu.macosx.base.557244179.959032290.;cdt.managedbuild.tool.gnu.c.compiler.macosx.base.3940526;cdt.managedbuild.tool.gnu.c.compiler.input.2089521215">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"/>
<profile id="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile">
<buildOutputProvider>
......@@ -242,7 +242,7 @@
</scannerInfoProvider>
</profile>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.macosx.base.557244179.959032290;cdt.managedbuild.toolchain.gnu.macosx.base.557244179.959032290.;cdt.managedbuild.tool.gnu.c.compiler.macosx.base.3940526;cdt.managedbuild.tool.gnu.c.compiler.input.2089521215">
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.macosx.base.557244179;cdt.managedbuild.toolchain.gnu.macosx.base.557244179.779699347;cdt.managedbuild.tool.gnu.c.compiler.macosx.base.1327025999;cdt.managedbuild.tool.gnu.c.compiler.input.1517483722">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"/>
<profile id="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile">
<buildOutputProvider>
......
......@@ -96,6 +96,7 @@ PKG_CHECK_MODULES(GNUTLS, gnutls, [found_gnutls=yes],foo=bar)
AM_CONDITIONAL([BUILD_TLS], [test "x$found_gnutls" = "xyes"])
if test "x$found_gnutls" = "xyes" ; then
GNUTLS_LIBS+="$GNUTLS_LIBS -lgnutls-openssl "
AC_DEFINE(HAVE_TLS,1,[Defined when tls api is available])
fi
PKG_CHECK_MODULES(CUNIT, cunit, [found_cunit=yes],[found_cunit=no])
......
......@@ -53,12 +53,12 @@ libbellesip_la_SOURCES= \
transports/stream_listeningpoint.c \
transports/tls_listeningpoint.c
if BUILD_TLS
libbellesip_la_SOURCES+=transports/tls_channel.c
libbellesip_la_SOURCES+=transports/tls_channel.c
endif
libbellesip_la_CFLAGS=$(STRICT_OPTIONS) $(ANTLR_CFLAGS)
libbellesip_la_CFLAGS=$(STRICT_OPTIONS) $(ANTLR_CFLAGS) $(GNUTLS_CFLAGS)
libbellesip_la_LIBADD=libbellesip_generated.la $(ANTLR_LIBS)
libbellesip_la_LIBADD=libbellesip_generated.la $(ANTLR_LIBS) $(GNUTLS_LIBS)
INCLUDES=-I$(top_srcdir)/include
......@@ -69,4 +69,4 @@ CLEANFILES=$(generated_src) *.tokens generated_src_stamp
discovery:
touch specs.cpp
$(CC) $(CFLAGS) -include $(top_builddir)/config.h $(ANTLR_CFLAGS) $(CUNIT_CFLAGS) -E -P -v -dD specs.cpp
$(CC) $(CFLAGS) -include $(top_builddir)/config.h $(ANTLR_CFLAGS) $(CUNIT_CFLAGS) $(GNUTLS_CFLAGS) -E -P -v -dD specs.cpp
......@@ -16,10 +16,9 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "belle-sip/belle-sdp.h"
#include "belle_sip_internal.h"
#include "belle_sdpParser.h"
#include "belle_sdpLexer.h"
#include "belle_sip_internal.h"
/***************************************************************************************
* Attribute
*
......
......@@ -35,6 +35,32 @@
/* include all public headers*/
#include "belle-sip/belle-sip.h"
#ifdef PACKAGE
#undef PACKAGE
#endif
#ifdef PACKAGE_BUGREPORT
#undef PACKAGE_BUGREPORT
#endif
#ifdef PACKAGE_NAME
#undef PACKAGE_NAME
#endif
#ifdef PACKAGE_STRING
#undef PACKAGE_STRING
#endif
#ifdef PACKAGE_TARNAME
#undef PACKAGE_TARNAME
#endif
#ifdef PACKAGE_VERSION
#undef PACKAGE_VERSION
#endif
#ifdef VERSION
#undef VERSION
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
/*etc*/
#define BELLE_SIP_INTERFACE_GET_METHODS(obj,interface) \
......
......@@ -22,7 +22,26 @@ options {
language = C;
}
@header {
@header {
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2010 Belledonne Communications SARL
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/>.
*/
}
@includes {
#include "belle-sip/belle-sip.h"
#include "belle_sip_internal.h"
}
......
......@@ -90,13 +90,6 @@ struct belle_sip_channel{
#define BELLE_SIP_CHANNEL(obj) BELLE_SIP_CAST(obj,belle_sip_channel_t)
belle_sip_channel_t * belle_sip_channel_new_udp(belle_sip_stack_t *stack, int sock, const char *bindip, int localport, const char *peername, int peerport);
belle_sip_channel_t * belle_sip_channel_new_udp_with_addr(belle_sip_stack_t *stack, int sock, const char *bindip, int localport, const struct addrinfo *ai);
belle_sip_channel_t * belle_sip_channel_new_tcp(belle_sip_stack_t *stack, const char *bindip, int localport,const char *name, int port);
belle_sip_channel_t * belle_sip_channel_new_tls(belle_sip_stack_t *stack, const char *bindip, int localport,const char *name, int port);
void belle_sip_channel_add_listener(belle_sip_channel_t *chan, belle_sip_channel_listener_t *l);
......
......@@ -20,6 +20,9 @@
#define LISTENINGPOINT_INTERNAL_H_
#include "belle_sip_internal.h"
#ifdef HAVE_TLS
#include "gnutls/openssl.h"
#endif
/*
Listening points: base, udp
*/
......@@ -39,9 +42,12 @@ int belle_sip_listening_point_get_well_known_port(const char *transport);
belle_sip_channel_t *belle_sip_listening_point_get_channel(belle_sip_listening_point_t *lp,const char *peer_name, int peer_port);
void belle_sip_listening_point_add_channel(belle_sip_listening_point_t *lp, belle_sip_channel_t *chan);
/**udp*/
typedef struct belle_sip_udp_listening_point belle_sip_udp_listening_point_t;
belle_sip_channel_t * belle_sip_channel_new_udp(belle_sip_stack_t *stack, int sock, const char *bindip, int localport, const char *peername, int peerport);
belle_sip_channel_t * belle_sip_channel_new_udp_with_addr(belle_sip_stack_t *stack, int sock, const char *bindip, int localport, const struct addrinfo *ai);
belle_sip_listening_point_t * belle_sip_udp_listening_point_new(belle_sip_stack_t *s, const char *ipaddress, int port);
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_udp_listening_point_t,belle_sip_listening_point_t)
BELLE_SIP_DECLARE_CUSTOM_VPTR_END
......@@ -49,17 +55,26 @@ BELLE_SIP_DECLARE_CUSTOM_VPTR_END
/*stream*/
typedef struct belle_sip_stream_listening_point belle_sip_stream_listening_point_t;
belle_sip_channel_t * belle_sip_channel_new_tcp(belle_sip_stack_t *stack, const char *bindip, int localport,const char *name, int port);
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_stream_listening_point_t,belle_sip_listening_point_t)
BELLE_SIP_DECLARE_CUSTOM_VPTR_END
#define BELLE_SIP_STREAM_LISTENING_POINT(obj) BELLE_SIP_CAST(obj,belle_sip_stream_listening_point_t)
belle_sip_listening_point_t * belle_sip_stream_listening_point_new(belle_sip_stack_t *s, const char *ipaddress, int port);
/*tls*/
typedef struct belle_sip_tls_listening_point belle_sip_tls_listening_point_t;
#ifdef HAVE_TLS
struct belle_sip_tls_listening_point{
belle_sip_listening_point_t base;
SSL_CTX *ssl_context;
};
#endif
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_tls_listening_point_t,belle_sip_listening_point_t)
BELLE_SIP_DECLARE_CUSTOM_VPTR_END
#define BELLE_SIP_TLS_LISTENING_POINT(obj) BELLE_SIP_CAST(obj,belle_sip_tls_listening_point_t)
belle_sip_listening_point_t * belle_sip_tls_listening_point_new(belle_sip_stack_t *s, const char *ipaddress, int port);
belle_sip_channel_t * belle_sip_channel_new_tls(belle_sip_tls_listening_point_t* lp, const char *bindip, int localport,const char *name, int port);
#endif /* LISTENINGPOINT_INTERNAL_H_ */
......@@ -32,6 +32,12 @@ belle_sip_stack_t * belle_sip_stack_new(const char *properties){
stack->timer_config.T1=500;
stack->timer_config.T2=4000;
stack->timer_config.T4=5000;
#ifdef HAVE_TLS
SSL_library_init();
SSL_load_error_strings();
/*CRYPTO_set_id_callback(&threadid_cb);
CRYPTO_set_locking_callback(&locking_function);*/
#endif
return stack;
}
......
......@@ -19,15 +19,19 @@
#include <sys/socket.h>
#include <netinet/tcp.h>
#include "listeningpoint_internal.h"
#include "belle_sip_internal.h"
#include "belle-sip/mainloop.h"
#include "stream_channel.h"
#include "gnutls/openssl.h"
/*************tls********/
struct belle_sip_tls_channel{
belle_sip_channel_t base;
belle_sip_tls_listening_point_t* lp;
SSL *ssl;
struct sockaddr_storage ss;
};
......@@ -36,6 +40,7 @@ static void tls_channel_uninit(belle_sip_tls_channel_t *obj){
if (sock!=-1)
close_socket(sock);
belle_sip_main_loop_remove_source(obj->base.stack->ml,(belle_sip_source_t*)obj);
belle_sip_object_unref(obj->lp);
}
static int tls_channel_send(belle_sip_channel_t *obj, const void *buf, size_t buflen){
......@@ -87,37 +92,65 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR(belle_sip_tls_channel_t)=
};
static int process_data(belle_sip_channel_t *obj,unsigned int revents){
struct sockaddr_storage ss;
socklen_t addrlen=sizeof(ss);
belle_sip_fd_t fd=belle_sip_source_get_fd((belle_sip_source_t*)obj);
belle_sip_tls_channel_t* channel=(belle_sip_tls_channel_t*)obj;
socklen_t addrlen=sizeof(channel->ss);
char ssl_error_string[128];
int result;
belle_sip_fd_t fd=belle_sip_source_get_fd((belle_sip_source_t*)channel);
if (obj->state == BELLE_SIP_CHANNEL_CONNECTING && (revents&BELLE_SIP_EVENT_WRITE)) {
if (finalize_stream_connection(fd,(struct sockaddr*)&ss,&addrlen)) {
belle_sip_error("Cannot connect to [%s://%s:%s]",belle_sip_channel_get_transport_name(obj),obj->peer_name,obj->peer_port);
channel_set_state(obj,BELLE_SIP_CHANNEL_ERROR);
channel_process_queue(obj);
return BELLE_SIP_STOP;
if (finalize_stream_connection(fd,(struct sockaddr*)&channel->ss,&addrlen)) {
goto process_error;
}
/*connected, now etablishing TLS connection*/
belle_sip_source_set_events((belle_sip_source_t*)obj,BELLE_SIP_EVENT_READ|BELLE_SIP_EVENT_ERROR);
belle_sip_channel_set_ready(obj,(struct sockaddr*)&ss,addrlen);
return BELLE_SIP_CONTINUE;
if (!channel->ssl) {
channel->ssl=SSL_new(channel->lp->ssl_context);
if (!channel->ssl) {
belle_sip_error("Cannot create TLS channel context");
goto process_error;
}
}
belle_sip_source_set_events((belle_sip_source_t*)channel,BELLE_SIP_EVENT_READ|BELLE_SIP_EVENT_ERROR);
if (!SSL_set_fd(channel->ssl,fd)) {
;
belle_sip_error("TLS connection failed to set fd caused by [%s]",ERR_error_string(ERR_get_error(),ssl_error_string));
goto process_error;
}
result=SSL_connect(channel->ssl);
result = SSL_get_error(channel->ssl, result);
if (result == SSL_ERROR_NONE) {
belle_sip_channel_set_ready(obj,(struct sockaddr*)&channel->ss,addrlen);
return BELLE_SIP_CONTINUE;
} else if (result == SSL_ERROR_WANT_READ || result == SSL_ERROR_WANT_WRITE) {
belle_sip_message("TLS connection in progress for channel [%p]",channel);
return BELLE_SIP_CONTINUE;
} else {
belle_sip_error("TLS connection failed caused by [%s]",ERR_error_string(result,ssl_error_string));
goto process_error;
}
} else if ( obj->state == BELLE_SIP_CHANNEL_READY) {
belle_sip_channel_process_data(obj,revents);
} else {
belle_sip_warning("Unexpected event [%i], for channel [%p]",revents,obj);
belle_sip_warning("Unexpected event [%i], for channel [%p]",revents,channel);
}
return BELLE_SIP_CONTINUE;
process_error:
belle_sip_error("Cannot connect to [%s://%s:%s]",belle_sip_channel_get_transport_name(obj),obj->peer_name,obj->peer_port);
channel_set_state(obj,BELLE_SIP_CHANNEL_ERROR);
channel_process_queue(obj);
return BELLE_SIP_STOP;
}
belle_sip_channel_t * belle_sip_channel_new_tls(belle_sip_stack_t *stack,const char *bindip, int localport, const char *dest, int port){
belle_sip_channel_t * belle_sip_channel_new_tls(belle_sip_tls_listening_point_t *lp,const char *bindip, int localport, const char *dest, int port){
belle_sip_tls_channel_t *obj=belle_sip_object_new(belle_sip_tls_channel_t);
belle_sip_channel_init((belle_sip_channel_t*)obj
,stack
,((belle_sip_listening_point_t*)lp)->stack
,socket(AF_INET, SOCK_STREAM, 0)
,(belle_sip_source_func_t)process_data
,bindip,localport,dest,port);
belle_sip_object_ref(obj->lp=lp);
return (belle_sip_channel_t*)obj;
}
......
......@@ -19,16 +19,13 @@
#include "listeningpoint_internal.h"
#ifdef HAVE_TLS
struct belle_sip_tls_listening_point{
belle_sip_listening_point_t base;
};
#include "gnutls/openssl.h"
static void belle_sip_tls_listening_point_uninit(belle_sip_tls_listening_point_t *lp){
}
static belle_sip_channel_t *tls_create_channel(belle_sip_listening_point_t *lp, const char *dest_ip, int port){
belle_sip_channel_t *chan=belle_sip_channel_new_tls(lp->stack,lp->addr,lp->port,dest_ip,port);
belle_sip_channel_t *chan=belle_sip_channel_new_tls(BELLE_SIP_TLS_LISTENING_POINT(lp),lp->addr,lp->port,dest_ip,port);
return chan;
}
......@@ -52,6 +49,14 @@ belle_sip_listening_point_t * belle_sip_tls_listening_point_new(belle_sip_stack_
#ifdef HAVE_TLS
belle_sip_tls_listening_point_t *lp=belle_sip_object_new(belle_sip_tls_listening_point_t);
belle_sip_listening_point_init((belle_sip_listening_point_t*)lp,s,ipaddress,port);
char ssl_error_string[128]; /*see openssl doc for size*/
lp->ssl_context=SSL_CTX_new(TLSv1_client_method());
if (!lp->ssl_context) {
belle_sip_error("belle_sip_listening_point_t: SSL_CTX_new failed caused by [%s]",ERR_error_string(ERR_get_error(),ssl_error_string));
belle_sip_object_unref(lp);
return NULL;
}
/*SSL_CTX_set_cipher_list(lp->ssl_context,"LOW");*/
return BELLE_SIP_LISTENING_POINT(lp);
#else
belle_sip_error("Cannot create tls listening point because not compile with TLS support");
......
......@@ -137,6 +137,10 @@ static void stateless_register_udp(void){
register_test(NULL,0);
}
static void stateless_register_tls(void){
register_test("tls",0);
}
static void stateless_register_tcp(void){
register_test("tcp",0);
}
......@@ -165,6 +169,9 @@ int belle_sip_register_test_suite(){
if (NULL == CU_add_test(pSuite, "stateless tcp register", stateless_register_tcp)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "stateless tls register", stateless_register_tls)) {
return CU_get_error();
}
return 0;
}
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