Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stack scope alloc cleanup, build cleanups #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/belle-sip/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#include <errno.h>
#include "belle-sip/defs.h"

#include "bctoolbox/logging.h"
#include "bctoolbox/vconnect.h"
#include <bctoolbox/logging.h>
#include <bctoolbox/vconnect.h>

#define BELLE_SIP_LOG_DOMAIN "belle-sip"

Expand Down
46 changes: 19 additions & 27 deletions src/auth_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,14 @@ int belle_sip_auth_define_size(const char* algo) {
}

int belle_sip_auth_helper_compute_ha1_for_algorithm(const char* userid,const char* realm,const char* password, char *ha1, size_t size, const char* algo) {
size_t compared_size;
size_t di, compared_size, length_byte = (size-1)/2;
uint8_t out[length_byte];
char *ask;
compared_size = belle_sip_auth_define_size(algo);
if (compared_size!= size) {
belle_sip_error("belle_sip_fill_authorization_header, size of ha1 must be 33 when MD5 or 65 when SHA-256 ");
return -1;
}
size_t length_byte = (size-1)/2;
uint8_t out[length_byte];
size_t di;
char *ask;
if (!userid) {
belle_sip_error("belle_sip_fill_authorization_header, username not found ");
return -1;
Expand Down Expand Up @@ -133,16 +131,14 @@ int belle_sip_auth_helper_compute_ha1(const char* userid,const char* realm,const
}

int belle_sip_auth_helper_compute_ha2_for_algorithm(const char* method,const char* uri, char *ha2, size_t size, const char* algo) {
size_t compared_size;
size_t compared_size, length_byte = (size-1)/2, di;
uint8_t out[length_byte];
char *ask;
compared_size = belle_sip_auth_define_size(algo);
if (compared_size!= size) {
belle_sip_error("belle_sip_fill_authorization_header, size of ha1 must be 33 when MD5 or 65 when SHA-256 ");
return -1;
}
size_t length_byte = (size-1)/2;
uint8_t out[length_byte];
size_t di;
char *ask;
ha2[length_byte*2]='\0';
/*HA2=MD5(method:uri)*/

Expand All @@ -160,16 +156,14 @@ int belle_sip_auth_helper_compute_ha2(const char* method,const char* uri, char h
}

int belle_sip_auth_helper_compute_response_for_algorithm(const char* ha1,const char* nonce, const char* ha2, char *response, size_t size, const char* algo) {
size_t compared_size;
size_t di, compared_size, length_byte = (size-1)/2;
uint8_t out[length_byte];
char *ask;
compared_size = belle_sip_auth_define_size(algo);
if (compared_size!= size) {
belle_sip_error("belle_sip_fill_authorization_header, size of ha1 must be 33 when MD5 or 65 when SHA-256 ");
return -1;
}
size_t length_byte = (size-1)/2;
uint8_t out[length_byte];
size_t di;
char *ask;
response[length_byte*2]='\0';

ask = bctbx_strdup_printf("%s:%s:%s", ha1, nonce, ha2);
Expand All @@ -195,17 +189,15 @@ int belle_sip_auth_helper_compute_response_qop_auth_for_algorithm(const char* ha
, const char* ha2
, char *response
, size_t size, const char* algo) {
size_t compared_size;
size_t di, compared_size, length_byte = (size-1)/2;
uint8_t out[length_byte];
char *ask;
char nounce_count_as_string[9];
compared_size = belle_sip_auth_define_size(algo);
if (compared_size!= size) {
belle_sip_error("belle_sip_fill_authorization_header, size of ha1 must be 33 when MD5 or 65 when SHA-256 ");
return -1;
}
size_t length_byte = (size-1)/2;
uint8_t out[length_byte];
size_t di;
char *ask;
char nounce_count_as_string[9];

response[length_byte*2]='\0';

Expand Down Expand Up @@ -234,19 +226,18 @@ int belle_sip_auth_helper_compute_response_qop_auth(const char* ha1
int belle_sip_auth_helper_fill_authorization(belle_sip_header_authorization_t* authorization
,const char* method
,const char* ha1) {
size_t size;
int auth_mode=0;
char* uri;
char cnonce[BELLE_SIP_CNONCE_LENGTH + 1];
const char *algo = belle_sip_header_authorization_get_algorithm(authorization);
size = belle_sip_auth_define_size(algo);
size_t size = belle_sip_auth_define_size(algo);
if(!size) {
belle_sip_error("Algorithm [%s] is not correct ", algo);
return -1;
}
}else{

int auth_mode=0;
char* uri;
char ha2[size];
char response[size];
char cnonce[BELLE_SIP_CNONCE_LENGTH + 1];

response[size-1]=ha2[size-1]='\0';

Expand Down Expand Up @@ -310,6 +301,7 @@ int belle_sip_auth_helper_fill_authorization(belle_sip_header_authorization_t* a
}
belle_sip_header_authorization_set_response(authorization,(const char*)response);
return 0;
}
}


Expand Down
3 changes: 2 additions & 1 deletion src/provider.c
Original file line number Diff line number Diff line change
Expand Up @@ -1313,8 +1313,9 @@ int belle_sip_provider_add_authorization(belle_sip_provider_t *p, belle_sip_requ
/*provides auth info in any cases, usefull even if found because auth info can contain wrong password*/
if (auth_infos) {
/*stored to give user information on realm/username which requires authentications*/
belle_sip_list_t* elem;
*auth_infos=belle_sip_list_append(*auth_infos,auth_event);
belle_sip_list_t* elem=belle_sip_list_find_double_events(*auth_infos,auth_event);
elem=belle_sip_list_find_double_events(*auth_infos,auth_event);
if(elem!=NULL)
*auth_infos=belle_sip_list_delete_link(*auth_infos,elem);
} else {
Expand Down
2 changes: 1 addition & 1 deletion tester/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ AM_LDFLAGS=-no-undefined -export-dynamic
#AM_LDFLAGS+=-Wl,-rpath -Wl,$(libdir)


AM_CFLAGS=$(STRICT_OPTIONS) $(STRICT_OPTIONS_CC)
AM_CFLAGS=$(STRICT_OPTIONS) $(STRICT_OPTIONS_CC) $(BCTOOLBOX_CFLAGS)


test: belle_sip_tester
Expand Down
2 changes: 2 additions & 0 deletions tester/auth_helper_tester.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ static void test_authentication_sha256(void) {
belle_sip_header_authorization_set_nonce_count(authorization,1);
belle_sip_header_authorization_set_qop(authorization,"auth");
belle_sip_header_authorization_set_cnonce(authorization,"8302210f"); /*for testing purpose*/
{
const char *algo = belle_sip_header_authorization_get_algorithm(authorization);
BC_ASSERT_EQUAL(0,belle_sip_auth_helper_compute_ha1_for_algorithm("Mufasa","[email protected]","Circle of Life",ha1,size,algo), int, "%d");
BC_ASSERT_EQUAL(0,belle_sip_auth_helper_fill_authorization(authorization,"REGISTER",ha1), int, "%d");
Expand All @@ -60,6 +61,7 @@ static void test_authentication_sha256(void) {
BC_ASSERT_EQUAL(belle_sip_header_authorization_get_nonce_count(authorization),1, int, "%d");
belle_sip_object_unref(www_authenticate);
belle_sip_object_unref(authorization);
}
}


Expand Down
55 changes: 29 additions & 26 deletions tester/belle_sip_refresher_tester.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ static void server_process_request_event(void *obj, const belle_sip_request_even
belle_sip_error("Algorithm of server must be MD5, SHA-256 or MD_SHA, can not be %s", endpoint->algo);
return;
}
{ /* stack-allocation scope */

belle_sip_header_www_authenticate_t* www_authenticate=NULL;
belle_sip_header_www_authenticate_t* two_www_authenticate=NULL;
Expand Down Expand Up @@ -207,7 +208,7 @@ static void server_process_request_event(void *obj, const belle_sip_request_even
if (!size) {
belle_sip_error("Algorithm [%s] is not correct ", algo);
return;
}
}else{
char local_resp[size];
if (qop && strcmp(qop,"auth")==0) {
compute_response_auth_qop( belle_sip_header_authorization_get_username(authorization)
Expand Down Expand Up @@ -237,6 +238,7 @@ static void server_process_request_event(void *obj, const belle_sip_request_even
}
belle_sip_free((void*)auth_uri);
auth_ok=strcmp(belle_sip_header_authorization_get_response(authorization),local_resp)==0;
}
}
if (auth_ok && endpoint->nonce_count < endpoint->max_nc_count ) {/*revoke nonce after MAX_NC_COUNT uses*/
if (endpoint->auth == digest || endpoint->auth == digest_with_next_nonce || endpoint->auth == digest_auth_with_next_nonce) {
Expand Down Expand Up @@ -286,9 +288,9 @@ static void server_process_request_event(void *obj, const belle_sip_request_even
authentication_info = BELLE_SIP_HEADER(belle_sip_header_authentication_info_new());
belle_sip_header_authentication_info_set_next_nonce(BELLE_SIP_HEADER_AUTHENTICATION_INFO(authentication_info), endpoint->nonce);
} else {
authentication_info = BELLE_SIP_HEADER(belle_sip_header_extension_create(BELLE_SIP_AUTHENTICATION_INFO,"nonce=\"nimporte quoi\" nc="));
authentication_info = BELLE_SIP_HEADER(belle_sip_header_extension_create(BELLE_SIP_AUTHENTICATION_INFO,"nonce=\"nimporte quoi\" nc="));
}

belle_sip_message_add_header(BELLE_SIP_MESSAGE(resp), BELLE_SIP_HEADER(authentication_info));
}
belle_sip_message_add_header(BELLE_SIP_MESSAGE(resp),BELLE_SIP_HEADER(contact));
Expand Down Expand Up @@ -338,6 +340,7 @@ static void server_process_request_event(void *obj, const belle_sip_request_even
endpoint->number_of_body_found++;
}
belle_sip_server_transaction_send_response(server_transaction,resp);
}
}

static void client_process_dialog_terminated(void *obj, const belle_sip_dialog_terminated_event_t *event){
Expand Down Expand Up @@ -479,8 +482,8 @@ static belle_sip_refresher_t* refresher_base_with_body2( endpoint_t* client
uint64_t begin;
uint64_t end;
if (client->expire_in_contact) belle_sip_header_contact_set_expires(contact,1);


dest_uri=(belle_sip_uri_t*)belle_sip_object_clone((belle_sip_object_t*)belle_sip_listening_point_get_uri(server->lp));
if (client->connection_family==AF_INET6)
belle_sip_uri_set_host(dest_uri,"::1");
Expand Down Expand Up @@ -512,10 +515,10 @@ static belle_sip_refresher_t* refresher_base_with_body2( endpoint_t* client
if (client->realm
&&
belle_sip_provider_add_authorization(client->provider, req, NULL, NULL,NULL, client->realm)) {

}
trans=belle_sip_provider_create_client_transaction(client->provider,req);

belle_sip_object_ref(trans);/*to avoid trans from being deleted before refresher can use it*/
belle_sip_client_transaction_send_request(trans);
if (client->early_refresher) {
Expand All @@ -539,12 +542,12 @@ static belle_sip_refresher_t* refresher_base_with_body2( endpoint_t* client
belle_sip_client_transaction_send_request(trans);
BC_ASSERT_TRUE(wait_for(server->stack,client->stack,&client->stat.twoHundredOk,1,1000));
}
client->refresher= refresher = belle_sip_client_transaction_create_refresher(trans);
client->refresher= refresher = belle_sip_client_transaction_create_refresher(trans);
}
if (BC_ASSERT_PTR_NOT_NULL(refresher)) {
belle_sip_object_unref(trans);
belle_sip_refresher_set_listener(refresher,belle_sip_refresher_listener,client);

begin = belle_sip_time_ms();
BC_ASSERT_TRUE(wait_for(server->stack,client->stack,&client->stat.refreshOk,client->register_count+(client->early_refresher?1:0),client->register_count*1000 + 1000));
end = belle_sip_time_ms();
Expand All @@ -567,7 +570,7 @@ static void refresher_base_with_body(endpoint_t* client
BC_ASSERT_EQUAL(client->stat.refreshOk,client->register_count+1,int,"%d");
belle_sip_refresher_stop(refresher);
belle_sip_object_unref(refresher);


}
static void refresher_base(endpoint_t* client,endpoint_t *server, const char* method) {
Expand Down Expand Up @@ -734,7 +737,7 @@ static void subscribe_base(int with_resource_lists) {
/*let the transaction timeout*/
wait_for(server->stack,client->stack, &dummy, 1, 32000);
belle_sip_stack_set_send_error(client->stack, 0);


BC_ASSERT_TRUE(wait_for(server->stack,client->stack,&client->stat.refreshOk,4,4000));
BC_ASSERT_EQUAL(client->stat.dialogTerminated, 0, int, "%i");
Expand All @@ -744,23 +747,23 @@ static void subscribe_base(int with_resource_lists) {
BC_ASSERT_STRING_NOT_EQUAL(call_id, belle_sip_header_call_id_get_call_id(belle_sip_dialog_get_call_id(belle_sip_transaction_get_dialog(BELLE_SIP_TRANSACTION(belle_sip_refresher_get_transaction(refresher))))));
belle_sip_free(call_id);
belle_sip_object_unref(client_dialog);

belle_sip_message("simulating dialog terminated server side and recovery");

client_dialog = belle_sip_transaction_get_dialog(BELLE_SIP_TRANSACTION(belle_sip_refresher_get_transaction(refresher)));
call_id = belle_sip_strdup(belle_sip_header_call_id_get_call_id(belle_sip_dialog_get_call_id(client_dialog)));
belle_sip_object_ref(client_dialog);

belle_sip_provider_enable_unconditional_answer(server->provider,TRUE);
belle_sip_provider_set_unconditional_answer(server->provider,481);
belle_sip_refresher_refresh(refresher, 10);

BC_ASSERT_TRUE(wait_for(server->stack,client->stack,&client->stat.fourHundredEightyOne,2,4000));
belle_sip_provider_enable_unconditional_answer(server->provider,FALSE);

BC_ASSERT_TRUE(wait_for(server->stack,client->stack,&client->stat.refreshOk,5,4000));
BC_ASSERT_EQUAL(client->stat.dialogTerminated, 0, int, "%i");

/*make sure dialog has changed*/
BC_ASSERT_PTR_NOT_EQUAL(client_dialog, belle_sip_transaction_get_dialog(BELLE_SIP_TRANSACTION(belle_sip_refresher_get_transaction(refresher))));
BC_ASSERT_STRING_NOT_EQUAL(call_id, belle_sip_header_call_id_get_call_id(belle_sip_dialog_get_call_id(belle_sip_transaction_get_dialog(BELLE_SIP_TRANSACTION(belle_sip_refresher_get_transaction(refresher))))));
Expand All @@ -771,14 +774,14 @@ static void subscribe_base(int with_resource_lists) {

belle_sip_refresher_stop(refresher);
BC_ASSERT_TRUE(wait_for(server->stack,client->stack,&server->stat.dialogTerminated,3,4000));

belle_sip_object_unref(refresher);

if (with_resource_lists) {
BC_ASSERT_EQUAL(server->number_of_body_found, (server->auth == none ?1:2), int, "%i");
}


destroy_endpoint(client);
destroy_endpoint(server);
}
Expand Down Expand Up @@ -1042,7 +1045,7 @@ static void register_and_publish(void) {
belle_sip_refresher_t *register_refresher;
belle_sip_refresher_t *publish_refresher;
belle_sip_header_content_type_t* content_type=belle_sip_header_content_type_create("application","pidf+xml");

memset(&client_callbacks,0,sizeof(belle_sip_listener_callbacks_t));
memset(&server_callbacks,0,sizeof(belle_sip_listener_callbacks_t));
client_callbacks.process_response_event=client_process_response_event;
Expand All @@ -1055,27 +1058,27 @@ static void register_and_publish(void) {
client->early_refresher=TRUE;
client->realm = SIPDOMAIN;
register_refresher = refresher_base_with_body2(client,server,"REGISTER",NULL,NULL,1);

client->register_count = 2 * client->register_count;
client->stat.refreshOk = 0;
/*to make sure we can still use same nonce*/
client->nonce_count -=2;

publish_refresher = refresher_base_with_body2(client,server,"PUBLISH",content_type,publish_body,2);

belle_sip_refresher_refresh(register_refresher,0);
BC_ASSERT_TRUE(wait_for(server->stack,client->stack,&client->stat.refreshOk,client->register_count+1,1000));
BC_ASSERT_EQUAL(client->stat.refreshOk,client->register_count+1,int,"%d");
belle_sip_refresher_stop(register_refresher);
belle_sip_object_unref(register_refresher);


belle_sip_refresher_refresh(publish_refresher,0);
BC_ASSERT_TRUE(wait_for(server->stack,client->stack,&client->stat.refreshOk,client->register_count+1,1000));
BC_ASSERT_EQUAL(client->stat.refreshOk,client->register_count+1,int,"%d");
belle_sip_refresher_stop(publish_refresher);
belle_sip_object_unref(publish_refresher);

destroy_endpoint(client);
destroy_endpoint(server);
}
Expand Down Expand Up @@ -1141,7 +1144,7 @@ test_t refresher_tests[] = {
TEST_NO_TAG("REGISTER, digest with next nonce", register_digest_with_next_nonce),
TEST_NO_TAG("REGISTER, digest auth with next nonce", register_digest_auth_with_next_nonce),
TEST_NO_TAG("REGISTER, digest auth with bad next nonce", register_digest_auth_with_bad_next_nonce)

};

test_suite_t refresher_test_suite = {"Refresher", NULL, NULL, belle_sip_tester_before_each, belle_sip_tester_after_each,
Expand Down
Loading