Commit 1ed30a4a authored by jehan's avatar jehan

add next-nonce support

parent 65513ccc
......@@ -32,6 +32,13 @@ BELLE_SIP_BEGIN_DECLS
*/
BELLESIP_EXPORT belle_sip_header_authorization_t* belle_sip_auth_helper_create_authorization(const belle_sip_header_www_authenticate_t* authentication);
/**
* Create an www_authenticate header from an authorization header, all common parameters are copyed.
* copy params: scheme, realm, nonce, algorithm, opaque
* @param authorization source to be used as input
* @return belle_sip_header_www_authenticate_t*
*/
BELLESIP_EXPORT belle_sip_header_www_authenticate_t* belle_sip_auth_helper_create_www_authenticate(const belle_sip_header_authorization_t* authorization);
/**
* Create an http authorization header from an www_authenticate header, all common parameters are copyed.
* copy params: scheme, realm, nonce, algorithm, opaque
......
......@@ -772,7 +772,7 @@ BELLESIP_EXPORT const char* belle_sip_header_reason_get_text(const belle_sip_hea
/******************************
* AuthenticationInfo header inherit from header
* Authentication-Info header inherit from header
*
******************************/
typedef struct _belle_sip_header_authentication_info belle_sip_header_authentication_info_t;
......
......@@ -39,11 +39,27 @@ static void belle_sip_auth_helper_clone_authorization(belle_sip_header_authoriza
CLONE_STRING_GENERIC(belle_sip_header_www_authenticate,belle_sip_header_authorization,algorithm,authorization,authentication)
CLONE_STRING_GENERIC(belle_sip_header_www_authenticate,belle_sip_header_authorization,opaque,authorization,authentication)
}
static void belle_sip_auth_helper_clone_www_authenticate(belle_sip_header_www_authenticate_t* authentication, const belle_sip_header_authorization_t* authorization) {
CLONE_STRING_GENERIC(belle_sip_header_authorization,belle_sip_header_www_authenticate,scheme, authentication, authorization)
CLONE_STRING_GENERIC(belle_sip_header_authorization,belle_sip_header_www_authenticate,realm, authentication, authorization)
CLONE_STRING_GENERIC(belle_sip_header_authorization,belle_sip_header_www_authenticate,nonce, authentication, authorization)
CLONE_STRING_GENERIC(belle_sip_header_authorization,belle_sip_header_www_authenticate,algorithm,authentication ,authorization)
CLONE_STRING_GENERIC(belle_sip_header_authorization,belle_sip_header_www_authenticate,opaque,authentication, authorization)
}
belle_sip_header_authorization_t* belle_sip_auth_helper_create_authorization(const belle_sip_header_www_authenticate_t* authentication) {
belle_sip_header_authorization_t* authorization = belle_sip_header_authorization_new();
belle_sip_auth_helper_clone_authorization(authorization,authentication);
return authorization;
}
belle_sip_header_www_authenticate_t* belle_sip_auth_helper_create_www_authenticate(const belle_sip_header_authorization_t* authorization) {
belle_sip_header_www_authenticate_t* www_authenticate = belle_sip_header_www_authenticate_new();
belle_sip_auth_helper_clone_www_authenticate(www_authenticate, authorization);
return www_authenticate;
}
belle_http_header_authorization_t* belle_http_auth_helper_create_authorization(const belle_sip_header_www_authenticate_t* authentication) {
belle_http_header_authorization_t* authorization = belle_http_header_authorization_new();
belle_sip_auth_helper_clone_authorization(BELLE_SIP_HEADER_AUTHORIZATION(authorization),authentication);
......
......@@ -2112,7 +2112,7 @@ static void belle_sip_header_authentication_info_clone( belle_sip_header_authent
}
belle_sip_error_code belle_sip_header_authentication_info_marshal(belle_sip_header_authentication_info_t* authentication_info, char* buff, size_t buff_size, size_t *offset) {
char* border=" ";
char* border="";
belle_sip_error_code error=belle_sip_header_marshal(BELLE_SIP_HEADER(authentication_info), buff, buff_size, offset);
if (error!=BELLE_SIP_OK) return error;
......
......@@ -1074,4 +1074,8 @@ void belle_sip_multipart_body_handler_progress_cb(belle_sip_body_handler_t *obj,
*/
belle_sip_list_t *belle_sip_parse_directory(const char *path, const char *file_type);
typedef struct authorization_context authorization_context_t;
void belle_sip_authorization_destroy(authorization_context_t* object);
#endif
......@@ -20,8 +20,8 @@
#include "listeningpoint_internal.h"
#include "md5.h"
#include "belle-sip/message.h"
typedef struct authorization_context {
static void belle_sip_provider_update_or_create_auth_context(belle_sip_provider_t *p,belle_sip_header_call_id_t* call_id,belle_sip_header_www_authenticate_t* authenticate,belle_sip_uri_t *from_uri,const char* realm) ;
struct authorization_context {
belle_sip_header_call_id_t* callid;
const char* scheme;
const char* realm;
......@@ -32,7 +32,7 @@ typedef struct authorization_context {
const char* algorithm;
int nonce_count;
int is_proxy;
}authorization_context_t;
};
GET_SET_STRING(authorization_context,realm)
GET_SET_STRING(authorization_context,nonce)
......@@ -49,7 +49,7 @@ static authorization_context_t* belle_sip_authorization_create(belle_sip_header_
belle_sip_object_ref(result->callid);
return result;
}
static void belle_sip_authorization_destroy(authorization_context_t* object) {
void belle_sip_authorization_destroy(authorization_context_t* object) {
DESTROY_STRING(object,scheme);
DESTROY_STRING(object,realm);
DESTROY_STRING(object,nonce);
......@@ -210,7 +210,39 @@ static void belle_sip_provider_dispatch_response(belle_sip_provider_t* p, belle_
}
}
}
break;
}
default:
if (t!=NULL){
belle_sip_message_t* req = BELLE_SIP_MESSAGE(belle_sip_transaction_get_request((belle_sip_transaction_t*)t));
belle_sip_header_authentication_info_t *authentication_info = belle_sip_message_get_header_by_type(msg,belle_sip_header_authentication_info_t);
belle_sip_list_t *authorization_lst = NULL;
belle_sip_header_call_id_t *call_id = belle_sip_message_get_header_by_type(msg,belle_sip_header_call_id_t);
belle_sip_header_from_t *from = belle_sip_message_get_header_by_type(req,belle_sip_header_from_t);
belle_sip_uri_t *from_uri=belle_sip_header_address_get_uri((belle_sip_header_address_t*)from);
/*searching for authentication headers*/
authorization_lst = belle_sip_list_copy(belle_sip_message_get_headers(BELLE_SIP_MESSAGE(req),BELLE_SIP_AUTHORIZATION));
/*search for proxy authenticate*/
authorization_lst=belle_sip_list_concat(authorization_lst,belle_sip_list_copy(belle_sip_message_get_headers(BELLE_SIP_MESSAGE(req),BELLE_SIP_PROXY_AUTHORIZATION)));
/*update auth contexts with authenticate headers from response*/
for (;authentication_info && authorization_lst!=NULL;authorization_lst=authorization_lst->next) {
belle_sip_header_authorization_t *authorization=BELLE_SIP_HEADER_AUTHORIZATION(authorization_lst->data);
belle_sip_header_www_authenticate_t *www_authenticate = belle_sip_auth_helper_create_www_authenticate(authorization);
belle_sip_header_www_authenticate_set_nonce(www_authenticate, belle_sip_header_authentication_info_get_next_nonce(authentication_info));
belle_sip_message( "Updating auth context for ream [%s] next nonce is going to be [%s]"
, belle_sip_header_www_authenticate_get_realm(www_authenticate)
, belle_sip_header_authentication_info_get_next_nonce(authentication_info));
belle_sip_provider_update_or_create_auth_context(p
, call_id
, www_authenticate
, from_uri
,belle_sip_header_www_authenticate_get_realm(www_authenticate));
belle_sip_object_unref(www_authenticate);
}
if (authorization_lst)
belle_sip_list_free(authorization_lst);
}
}
if (t){ /*In some re-connection case, specially over udp, transaction may be found, but without associated channel*/
if (t->base.channel == NULL) {
......@@ -1013,6 +1045,7 @@ static void authorization_context_fill_from_auth(authorization_context_t* auth_c
}
}
static belle_sip_list_t* belle_sip_provider_get_auth_context_by_realm_or_call_id(belle_sip_provider_t *p,belle_sip_header_call_id_t* call_id,belle_sip_uri_t *from_uri,const char* realm) {
belle_sip_list_t* auth_context_lst=NULL;
belle_sip_list_t* result=NULL;
......@@ -1089,6 +1122,7 @@ 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_uri_t *from_uri, belle_sip_list_t** auth_infos, const char* realm) {
belle_sip_header_call_id_t* call_id;
......
This diff is collapsed.
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