Commit e4616ba4 authored by Simon Morlat's avatar Simon Morlat

modify authentication mechanism to allow to authenticate request with privacy (from is anonymous)

parent b7ffd596
......@@ -3,7 +3,16 @@
AC_PREREQ([2.63])
AC_INIT([belle-sip],[1.3.1],[jehan.monnier@linphone.org])
AC_INIT([belle-sip],[1.3.2],[jehan.monnier@linphone.org])
BELLESIP_SO_CURRENT=0 dnl increment this number when you add/change/remove an interface
BELLESIP_SO_REVISION=0 dnl increment this number when you change source code, without changing interfaces; set to 0 when incrementing CURRENT
BELLESIP_SO_AGE=0 dnl increment this number when you add an interface, set to 0 if you remove an interface
BELLESIP_SO_VERSION=$BELLESIP_SO_CURRENT:$BELLESIP_SO_REVISION:$BELLESIP_SO_AGE
AC_SUBST(BELLESIP_SO_CURRENT, $BELLESIP_SO_CURRENT)
AC_SUBST(BELLESIP_SO_VERSION)
AC_CONFIG_SRCDIR([src/belle_sip_utils.c])
......
......@@ -61,11 +61,12 @@ BELLESIP_EXPORT void belle_sip_provider_clean_channels(belle_sip_provider_t *p);
* @param p object
* @param request to be updated
* @param resp response to take authentication values from, might be NULL
* @param from_uri optional - an uri to use instead of the from of the request, which can be anonymous.
* @param auth_infos A newly allocated belle_sip_auth_info_t object is added to this list. These object contains useful information like realm and username.
* @returns 0 in case of success,
*
**/
BELLESIP_EXPORT int belle_sip_provider_add_authorization(belle_sip_provider_t *p, belle_sip_request_t* request,belle_sip_response_t *resp,belle_sip_list_t** auth_infos);
BELLESIP_EXPORT int belle_sip_provider_add_authorization(belle_sip_provider_t *p, belle_sip_request_t* request,belle_sip_response_t *resp, belle_sip_uri_t *from_uri, belle_sip_list_t** auth_infos);
/**
* Can be used to simulate network recv error, for tests.
......
......@@ -64,7 +64,7 @@ libbellesip_la_CXXFLAGS=$(STRICT_OPTIONS) $(TLS_CFLAGS) $(TUNNEL_CFLAGS) $(LIBBE
libbellesip_la_LIBADD=grammars/libbellesip_generated.la libbellesip_tls.la $(ANTLR_LIBS) $(TLS_LIBS) $(TUNNEL_LIBS)
libbellesip_la_LDFLAGS=-no-undefined $(LDFLAGS)
libbellesip_la_LDFLAGS=-no-undefined -version-info $(BELLESIP_SO_VERSION) $(LDFLAGS)
AM_CPPFLAGS=-I$(top_srcdir)/include -I$(builddir)/grammars
......
......@@ -30,15 +30,14 @@ GET_SET_STRING(belle_sip_auth_event,passwd)
GET_SET_STRING(belle_sip_auth_event,ha1)
GET_SET_STRING(belle_sip_auth_event,distinguished_name)
belle_sip_auth_event_t* belle_sip_auth_event_create(belle_sip_object_t *source, const char* realm, const belle_sip_header_from_t *from) {
belle_sip_auth_event_t* belle_sip_auth_event_create(belle_sip_object_t *source, const char* realm, const belle_sip_uri_t *from_uri) {
belle_sip_auth_event_t* result = belle_sip_new0(belle_sip_auth_event_t);
result->source=source;
belle_sip_auth_event_set_realm(result,realm);
if (from){
belle_sip_uri_t *uri=belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(from));
belle_sip_auth_event_set_username(result,belle_sip_uri_get_user(uri));
belle_sip_auth_event_set_domain(result,belle_sip_uri_get_host(uri));
if (from_uri){
belle_sip_auth_event_set_username(result,belle_sip_uri_get_user(from_uri));
belle_sip_auth_event_set_domain(result,belle_sip_uri_get_host(from_uri));
}
return result;
}
......
......@@ -912,7 +912,7 @@ struct belle_sip_auth_event {
belle_sip_signing_key_t* key;
};
belle_sip_auth_event_t* belle_sip_auth_event_create(belle_sip_object_t *source, const char* realm,const belle_sip_header_from_t * from);
belle_sip_auth_event_t* belle_sip_auth_event_create(belle_sip_object_t *source, const char* realm,const belle_sip_uri_t * from_uri);
void belle_sip_auth_event_set_distinguished_name(belle_sip_auth_event_t* event,const char* value);
......
......@@ -941,7 +941,8 @@ static void belle_sip_provider_update_or_create_auth_context(belle_sip_provider
return;
}
int belle_sip_provider_add_authorization(belle_sip_provider_t *p, belle_sip_request_t* request,belle_sip_response_t *resp,belle_sip_list_t** auth_infos) {
int belle_sip_provider_add_authorization(belle_sip_provider_t *p, belle_sip_request_t* request, belle_sip_response_t *resp,
belle_sip_uri_t *from_uri, belle_sip_list_t** auth_infos) {
belle_sip_header_call_id_t* call_id;
belle_sip_list_t* auth_context_iterator;
belle_sip_list_t* authenticate_lst;
......@@ -1005,13 +1006,16 @@ int belle_sip_provider_add_authorization(belle_sip_provider_t *p, belle_sip_requ
/*put authorization header if passwd found*/
call_id = belle_sip_message_get_header_by_type(BELLE_SIP_MESSAGE(request),belle_sip_header_call_id_t);
from = belle_sip_message_get_header_by_type(request,belle_sip_header_from_t);
if (from_uri==NULL){
from = belle_sip_message_get_header_by_type(request,belle_sip_header_from_t);
from_uri=belle_sip_header_address_get_uri((belle_sip_header_address_t*)from);
}
head=belle_sip_provider_get_auth_context_by_call_id(p,call_id);
/*we assume there no existing auth headers*/
for (auth_context_iterator=head;auth_context_iterator!=NULL;auth_context_iterator=auth_context_iterator->next) {
/*clear auth info*/
auth_context=(authorization_context_t*)auth_context_iterator->data;
auth_event = belle_sip_auth_event_create((belle_sip_object_t*)p,auth_context->realm,from);
auth_event = belle_sip_auth_event_create((belle_sip_object_t*)p,auth_context->realm,from_uri);
/*put data*/
/*call listener*/
BELLE_SIP_PROVIDER_INVOKE_LISTENERS(p->listeners,process_auth_requested,auth_event);
......
......@@ -390,7 +390,7 @@ static int belle_sip_refresher_refresh_internal(belle_sip_refresher_t* refresher
belle_sip_message_add_header(BELLE_SIP_MESSAGE(request),BELLE_SIP_HEADER(expires_header));
}
}
belle_sip_provider_add_authorization(prov,request,old_response,auth_infos);
belle_sip_provider_add_authorization(prov,request,old_response,NULL,auth_infos);
} else {
belle_sip_error("Unexpected dialog state [%s] for dialog [%p], cannot refresh [%s]"
,belle_sip_dialog_state_to_string(belle_sip_dialog_get_state(dialog))
......
......@@ -562,7 +562,7 @@ belle_sip_request_t* belle_sip_client_transaction_create_authenticated_request(b
belle_sip_message_remove_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_PROXY_AUTHORIZATION);
/*put auth header*/
belle_sip_provider_add_authorization(t->base.provider,req,t->base.last_response,auth_infos);
belle_sip_provider_add_authorization(t->base.provider,req,t->base.last_response,NULL,auth_infos);
return req;
}
......@@ -86,7 +86,7 @@ static void process_response_event(void *user_ctx, const belle_sip_response_even
request=belle_sip_transaction_get_request(BELLE_SIP_TRANSACTION(belle_sip_response_event_get_client_transaction(event)));
cseq=(belle_sip_header_cseq_t*)belle_sip_message_get_header(BELLE_SIP_MESSAGE(request),BELLE_SIP_CSEQ);
belle_sip_header_cseq_set_seq_number(cseq,belle_sip_header_cseq_get_seq_number(cseq)+1);
CU_ASSERT_TRUE_FATAL(belle_sip_provider_add_authorization(prov,request,belle_sip_response_event_get_response(event),NULL));
CU_ASSERT_TRUE_FATAL(belle_sip_provider_add_authorization(prov,request,belle_sip_response_event_get_response(event),NULL,NULL));
t=belle_sip_provider_create_client_transaction(prov,request);
belle_sip_client_transaction_send_request_to(t,dest);
number_of_challenge++;
......@@ -235,7 +235,7 @@ void unregister_user(belle_sip_stack_t * stack
belle_sip_client_transaction_t *t;
belle_sip_message_remove_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_AUTHORIZATION);
belle_sip_message_remove_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_PROXY_AUTHORIZATION);
belle_sip_provider_add_authorization(prov,req,NULL,NULL); /*just in case*/
belle_sip_provider_add_authorization(prov,req,NULL,NULL,NULL); /*just in case*/
t=belle_sip_provider_create_client_transaction(prov,req);
belle_sip_client_transaction_send_request(t);
}else belle_sip_provider_send_request(prov,req);
......
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