Commit acae6ddf authored by jehan's avatar jehan

implements belle_sip_uri_equals

remove qop from default authorization
parent b20fe2fc
......@@ -38,20 +38,24 @@ belle_sip_header_proxy_authorization_t* belle_sip_auth_helper_create_proxy_autho
/**
* compute and set response value according to parameters
* HA1=MD5(username:realm:passwd)
* @return 0 if succeed
*/
int belle_sip_auth_helper_fill_authorization(belle_sip_header_authorization_t* authorization
,const char* method
,const char* username
,const char* password);
,const char* ha1);
/**
* compute and set response value according to parameters
* @return 0 if succeed
*/
int belle_sip_auth_helper_fill_proxy_authorization(belle_sip_header_proxy_authorization_t* proxy_authorization
,const char* method
,const char* username
,const char* password);
,const char* ha1);
/*
* compute HA1 (NULL terminated)
* HA1=MD5(userid:realm:passwd)
* return 0 in case of success
* */
int belle_sip_auth_helper_compute_ha1(const char* userid,const char* realm,const char* password, char ha1[33]);
#endif /* AUTHENTICATION_HELPER_H_ */
......@@ -148,6 +148,7 @@ typedef struct _belle_sip_response belle_sip_response_t;
#include "belle-sip/sipstack.h"
#include "belle-sip/listeningpoint.h"
#include "belle-sip/provider.h"
#include "belle-sip/auth-helper.h"
#undef TRUE
......
......@@ -124,7 +124,7 @@ belle_sip_header_contact_t* belle_sip_header_contact_parse (const char* contact)
void belle_sip_header_contact_set_wildcard(belle_sip_header_contact_t* contact,unsigned int is_wildcard);
#define BELLE_SIP_HEADER_CONTACT(t) BELLE_SIP_CAST(t,belle_sip_header_contact_t)
#define BELLE_SIP_CONTACT "Contact"
/******************************
* From header object inherent from header_address
*
......@@ -144,6 +144,7 @@ belle_sip_header_contact_t* belle_sip_header_contact_parse (const char* contact)
void belle_sip_header_from_set_random_tag(belle_sip_header_from_t *obj);
#define BELLE_SIP_HEADER_FROM(t) BELLE_SIP_CAST(t,belle_sip_header_from_t)
#define BELLE_SIP_FROM "From"
/******************************
* To header object inherent from header_address
*
......@@ -195,6 +196,7 @@ int belle_sip_header_via_set_rport(belle_sip_header_via_t* via,int rport);
void belle_sip_header_via_set_transport(belle_sip_header_via_t* via,const char* transport);
int belle_sip_header_via_set_ttl(belle_sip_header_via_t* via, int ttl);
#define BELLE_SIP_HEADER_VIA(t) BELLE_SIP_CAST(t,belle_sip_header_via_t)
#define BELLE_SIP_VIA "Via"
/******************************
* Call id object inherent from object
......@@ -369,6 +371,7 @@ void belle_sip_header_www_authenticate_set_scheme(belle_sip_header_www_authentic
void belle_sip_header_www_authenticate_set_domain(belle_sip_header_www_authenticate_t* www_authenticate,const char* domain);
void belle_sip_header_www_authenticate_set_stale(belle_sip_header_www_authenticate_t* www_authenticate, unsigned int enable);
#define BELLE_SIP_HEADER_WWW_AUTHENTICATE(t) BELLE_SIP_CAST(t,belle_sip_header_www_authenticate_t)
#define BELLE_SIP_WWW_AUTHENTICATE "WWW-Authenticate"
/*******************************
* proxy_authenticate inherit from www_authenticate
......@@ -377,7 +380,7 @@ typedef struct _belle_sip_header_proxy_authenticate belle_sip_header_proxy_authe
belle_sip_header_proxy_authenticate_t* belle_sip_header_proxy_authenticate_new();
belle_sip_header_proxy_authenticate_t* belle_sip_header_proxy_authenticate_parse(const char* proxy_authenticate);
#define BELLE_SIP_HEADER_PROXY_AUTHENTICATE(t) BELLE_SIP_CAST(t,belle_sip_header_proxy_authenticate_t)
#define BELLE_SIP_PROXY_AUTHENTICATE "Proxy-Authenticate"
/******************************
*
......
......@@ -29,21 +29,21 @@ typedef struct _belle_sip_parameters belle_sip_parameters_t;
belle_sip_parameters_t* belle_sip_parameters_new();
const char* belle_sip_parameters_get_parameter(belle_sip_parameters_t* obj,const char* name);
const char* belle_sip_parameters_get_parameter(const belle_sip_parameters_t* obj,const char* name);
/**
* returns 0 if not found
*/
unsigned int belle_sip_parameters_is_parameter(belle_sip_parameters_t* obj,const char* name);
unsigned int belle_sip_parameters_is_parameter(const belle_sip_parameters_t* obj,const char* name);
void belle_sip_parameters_set_parameter(belle_sip_parameters_t* obj,const char* name,const char* value);
const belle_sip_list_t * belle_sip_parameters_get_parameter_names(belle_sip_parameters_t* obj);
const belle_sip_list_t * belle_sip_parameters_get_parameter_names(const belle_sip_parameters_t* obj);
const belle_sip_list_t * belle_sip_parameters_get_parameters(belle_sip_parameters_t* obj);
const belle_sip_list_t * belle_sip_parameters_get_parameters(const belle_sip_parameters_t* obj);
void belle_sip_parameters_remove_parameter(belle_sip_parameters_t* obj,const char* name);
int belle_sip_parameters_marshal(belle_sip_parameters_t* obj, char* buff,unsigned int offset,unsigned int buff_size);
int belle_sip_parameters_marshal(const belle_sip_parameters_t* obj, char* buff,unsigned int offset,unsigned int buff_size);
#define BELLE_SIP_PARAMETERS(obj) BELLE_SIP_CAST(obj,belle_sip_parameters_t)
......
......@@ -167,9 +167,17 @@ typedef struct _belle_sip_uri belle_sip_uri_t;
*/
char* belle_sip_uri_to_string(belle_sip_uri_t* uri) ;
int belle_sip_uri_marshal(belle_sip_uri_t* uri, char* buff,unsigned int offset,unsigned int buff_size);
int belle_sip_uri_marshal(const belle_sip_uri_t* uri, char* buff,unsigned int offset,unsigned int buff_size);
#define BELLE_SIP_URI(obj) BELLE_SIP_CAST(obj,belle_sip_uri_t)
/**define URI equality as using comparison rules from RFC3261 section 19.1.4
* @param belle_sip_uri_t* uri_a
* @param belle_sip_uri_t* uri_a
* @return 0 if not matched.
*
* */
int belle_sip_uri_equals(const belle_sip_uri_t* uri_a,const belle_sip_uri_t* uri_b);
#endif /*BELLE_SIP_URI_H_*/
......@@ -45,17 +45,46 @@ belle_sip_header_proxy_authorization_t* belle_sip_auth_helper_create_proxy_autho
belle_sip_auth_helper_clone_authorization(BELLE_SIP_HEADER_AUTHORIZATION(authorization),BELLE_SIP_HEADER_WWW_AUTHENTICATE(proxy_authentication));
return authorization;
}
int belle_sip_auth_helper_compute_ha1(const char* userid,const char* realm,const char* password, char ha1[33]) {
md5_byte_t out[16];
md5_state_t state;
int di;
if (!userid) {
belle_sip_error("belle_sip_fill_authorization_header, username not found ");
return -1;
}
if (!password) {
belle_sip_error("belle_sip_fill_authorization_header, password not found ");
return -1;
}
if (!realm) {
belle_sip_error("belle_sip_fill_authorization_header, password not found ");
return -1;
}
md5_init(&state);
md5_append(&state,(const md5_byte_t *)userid,strlen(userid));
md5_append(&state,(const md5_byte_t *)":",1);
md5_append(&state,(const md5_byte_t *)realm,strlen(realm));
md5_append(&state,(const md5_byte_t *)":",1);
md5_append(&state,(const md5_byte_t *)password,strlen(password));
md5_finish(&state,out);
for (di = 0; di < 16; ++di)
sprintf(ha1 + di * 2, "%02x", out[di]);
ha1[33]='\0';
return 0;
}
int belle_sip_auth_helper_fill_authorization(belle_sip_header_authorization_t* authorization
,const char* method
,const char* username
,const char* password) {
,const char* method
,const char* ha1) {
md5_byte_t out[16];
md5_state_t state;
char* uri;
char ha1[16*2 + 1];
char ha2[16*2 + 1];
char response[16*2 + 1];
response[33]=ha2[33]='\0';
int di;
if (belle_sip_header_authorization_get_scheme(authorization) != NULL &&
strcmp("Digest",belle_sip_header_authorization_get_scheme(authorization))!=0) {
......@@ -64,7 +93,7 @@ int belle_sip_auth_helper_fill_authorization(belle_sip_header_authorization_t* a
return -1;
}
if (belle_sip_header_authorization_get_qop(authorization)
&& strcmp("auth",belle_sip_header_authorization_get_qop(authorization))!=0) {
/*&& strcmp("auth",belle_sip_header_authorization_get_qop(authorization))!=0*/) {
belle_sip_error("belle_sip_fill_authorization_header, unsupported qop [%s], use auth instead"
,belle_sip_header_authorization_get_qop(authorization));
return -1;
......@@ -76,27 +105,7 @@ int belle_sip_auth_helper_fill_authorization(belle_sip_header_authorization_t* a
belle_sip_error("belle_sip_fill_authorization_header, method not found ");
return -1;
}
if (!username) {
belle_sip_error("belle_sip_fill_authorization_header, username not found ");
return -1;
}
if (!password) {
belle_sip_error("belle_sip_fill_authorization_header, password not found ");
return -1;
}
/*HA1=MD5(username:realm:passwd)*/
md5_init(&state);
md5_append(&state,(const md5_byte_t *)username,strlen(username));
md5_append(&state,(const md5_byte_t *)":",1);
md5_append(&state
,(const md5_byte_t *)belle_sip_header_authorization_get_realm(authorization)
,strlen(belle_sip_header_authorization_get_realm(authorization)));
md5_append(&state,(const md5_byte_t *)":",1);
md5_append(&state,(const md5_byte_t *)password,strlen(password));
md5_finish(&state,out);
for (di = 0; di < 16; ++di)
sprintf(ha1 + di * 2, "%02x", out[di]);
/*HA2=MD5(method:uri)*/
md5_init(&state);
......@@ -123,18 +132,14 @@ int belle_sip_auth_helper_fill_authorization(belle_sip_header_authorization_t* a
sprintf(response + di * 2, "%02x", out[di]);
belle_sip_header_authorization_set_response(authorization,(const char*)response);
belle_sip_header_authorization_set_qop(authorization,"auth");
return 0;
}
int belle_sip_auth_helper_fill_proxy_authorization(belle_sip_header_proxy_authorization_t* proxy_authorization
,const char* method
,const char* username
,const char* password) {
,const char* ha1) {
return belle_sip_auth_helper_fill_authorization(BELLE_SIP_HEADER_AUTHORIZATION(proxy_authorization)
,method
,username
,password);
,method, ha1);
}
......
......@@ -189,7 +189,7 @@ int belle_sip_header_contact_marshal(belle_sip_header_contact_t* contact, char*
}
return current_offset-offset;
}
BELLE_SIP_NEW_HEADER(header_contact,header_address,"Contact")
BELLE_SIP_NEW_HEADER(header_contact,header_address,BELLE_SIP_CONTACT)
BELLE_SIP_PARSE(header_contact)
GET_SET_INT_PARAM_PRIVATE(belle_sip_header_contact,expires,int,_)
......@@ -247,7 +247,7 @@ belle_sip_header_from_t* belle_sip_header_from_create(const char *address, const
return from;
}
BELLE_SIP_NEW_HEADER(header_from,header_address,"From")
BELLE_SIP_NEW_HEADER(header_from,header_address,BELLE_SIP_FROM)
BELLE_SIP_PARSE(header_from)
GET_SET_STRING_PARAM(belle_sip_header_from,tag);
......@@ -391,7 +391,7 @@ belle_sip_header_via_t* belle_sip_header_via_create(const char *host, int port,
return via;
}
BELLE_SIP_NEW_HEADER(header_via,parameters,"Via")
BELLE_SIP_NEW_HEADER(header_via,parameters,BELLE_SIP_VIA)
BELLE_SIP_PARSE(header_via)
GET_SET_STRING(belle_sip_header_via,protocol);
GET_SET_STRING(belle_sip_header_via,transport);
......@@ -918,7 +918,7 @@ void header##_add_name(header##_t* obj, const char* value) {\
obj->name=belle_sip_list_append(obj->name,strdup(value));\
}
BELLE_SIP_NEW_HEADER_INIT(header_www_authenticate,parameters,"WWW-Authenticate",header_www_authenticate)
BELLE_SIP_NEW_HEADER_INIT(header_www_authenticate,parameters,BELLE_SIP_WWW_AUTHENTICATE,header_www_authenticate)
BELLE_SIP_PARSE(header_www_authenticate)
GET_SET_STRING(belle_sip_header_www_authenticate,scheme);
GET_SET_STRING(belle_sip_header_www_authenticate,realm);
......@@ -951,7 +951,7 @@ static void belle_sip_header_proxy_authenticate_clone(belle_sip_header_proxy_aut
int belle_sip_header_proxy_authenticate_marshal(belle_sip_header_proxy_authenticate_t* proxy_authenticate, char* buff,unsigned int offset,unsigned int buff_size) {
return belle_sip_header_www_authenticate_marshal(&proxy_authenticate->www_authenticate,buff,offset,buff_size);
}
BELLE_SIP_NEW_HEADER(header_proxy_authenticate,header_www_authenticate,"Proxy-Authenticate")
BELLE_SIP_NEW_HEADER(header_proxy_authenticate,header_www_authenticate,BELLE_SIP_PROXY_AUTHENTICATE)
BELLE_SIP_PARSE(header_proxy_authenticate)
/**************************
......
......@@ -35,7 +35,7 @@ static void belle_sip_parameters_clone(belle_sip_parameters_t *params, const bel
belle_sip_parameters_set_parameter( params,container->name,container->value);
}
}
int belle_sip_parameters_marshal(belle_sip_parameters_t* params, char* buff,unsigned int offset,unsigned int buff_size) {
int belle_sip_parameters_marshal(const belle_sip_parameters_t* params, char* buff,unsigned int offset,unsigned int buff_size) {
belle_sip_list_t* list=params->param_list;
unsigned int curent_offset=offset;
for(;list!=NULL;list=list->next){
......@@ -49,10 +49,10 @@ int belle_sip_parameters_marshal(belle_sip_parameters_t* params, char* buff,unsi
return curent_offset-offset;
}
BELLE_SIP_NEW_HEADER(parameters,header,"parameters")
const belle_sip_list_t * belle_sip_parameters_get_parameters(belle_sip_parameters_t* obj) {
const belle_sip_list_t * belle_sip_parameters_get_parameters(const belle_sip_parameters_t* obj) {
return obj->param_list;
}
const char* belle_sip_parameters_get_parameter(belle_sip_parameters_t* params,const char* name) {
const char* belle_sip_parameters_get_parameter(const belle_sip_parameters_t* params,const char* name) {
belle_sip_list_t * lResult = belle_sip_list_find_custom(params->param_list, (belle_sip_compare_func)belle_sip_param_pair_comp_func, name);
if (lResult) {
return ((belle_sip_param_pair_t*)(lResult->data))->value;
......@@ -61,7 +61,7 @@ const char* belle_sip_parameters_get_parameter(belle_sip_parameters_t* params,co
return NULL;
}
}
unsigned int belle_sip_parameters_is_parameter(belle_sip_parameters_t* params,const char* name) {
unsigned int belle_sip_parameters_is_parameter(const belle_sip_parameters_t* params,const char* name) {
return belle_sip_list_find_custom(params->param_list, (belle_sip_compare_func)belle_sip_param_pair_comp_func, name) != NULL;
}
void belle_sip_parameters_set_parameter(belle_sip_parameters_t* params,const char* name,const char* value) {
......@@ -83,7 +83,7 @@ void belle_sip_parameters_set_parameter(belle_sip_parameters_t* params,const cha
params->paramnames_list=belle_sip_list_append(params->paramnames_list,lNewpair->name);
}
const belle_sip_list_t* belle_sip_parameters_get_parameter_names(belle_sip_parameters_t* params) {
const belle_sip_list_t* belle_sip_parameters_get_parameter_names(const belle_sip_parameters_t* params) {
return params?params->paramnames_list:NULL;
}
void belle_sip_parameters_remove_parameter(belle_sip_parameters_t* params,const char* name) {
......
......@@ -65,7 +65,7 @@ static void belle_sip_uri_clone(belle_sip_uri_t* uri, const belle_sip_uri_t *ori
uri->header_list=orig->header_list?(belle_sip_parameters_t*)belle_sip_object_clone(BELLE_SIP_OBJECT(orig->header_list)):NULL;
}
int belle_sip_uri_marshal(belle_sip_uri_t* uri, char* buff,unsigned int offset,unsigned int buff_size) {
int belle_sip_uri_marshal(const belle_sip_uri_t* uri, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset;
const belle_sip_list_t* list=belle_sip_parameters_get_parameters(uri->header_list);
......@@ -146,3 +146,162 @@ SIP_URI_GET_SET_STRING_PARAM(method)
SIP_URI_GET_SET_STRING_PARAM(maddr)
SIP_URI_GET_SET_INT_PARAM(ttl)
SIP_URI_HAS_SET_BOOL_PARAM(lr)
static int get_char (char*a,int n,char*out) {
char result;
char tmp;
if (*a=='%' && n>2) {
tmp=a[3];
a[3]='\0';
*out=(char)((atoi(a+1)*16)/10); /*convert to hexa*/;
a[3]=tmp;
return 3;
} else {
*out=*a;
return 1;
}
return result;
}
static int uri_strncmp_common(const char*a,const char*b,size_t n,int case_sensitive) {
int result=0;
int index_a=0,index_b=0;
char char_a,char_b;
while (a[index_a]!='\0'&&b[index_b]!='\0'&&index_a<n&&index_b<n) {
index_a+=get_char((char*)a+index_a,n-index_a,&char_a);
index_b+=get_char((char*)b+index_b,n-index_b,&char_b);
if (!case_sensitive && char_a<0x7B && char_a>0x60) char_a-=0x20;
if (!case_sensitive && char_b<0x7B && char_b>0x60) char_b-=0x20;
result+=(char_a!=char_b);
}
return result;
}
static int uri_strncmp(const char*a,const char*b,size_t n) {
return uri_strncmp_common(a,b,n,1);
}
static int uri_strncasecmp(const char*a,const char*b,size_t n) {
return uri_strncmp_common(a,b,n,0);
}
#define IS_EQUAL(a,b) uri_strncmp(a,b,MIN(strlen(a),strlen(b)))!=0
#define IS_EQUAL_CASE(a,b) uri_strncasecmp(a,b,MIN(strlen(a),strlen(b)))!=0
#define PARAM_CASE_CMP(uri_a,uri_b,param) \
a_param=belle_sip_parameters_get_parameter((belle_sip_parameters_t*) uri_a,param); \
b_param=belle_sip_parameters_get_parameter((belle_sip_parameters_t*) uri_b,param);\
if (a_param && b_param) { \
if (IS_EQUAL_CASE(a_param,b_param)) return 0; \
} else if (a_param != b_param) {\
return 0;\
}
/*
* RFC 3261 SIP: Session Initiation Protocol June 2002
* 19.1.4 URI Comparison
Some operations in this specification require determining whether two
SIP or SIPS URIs are equivalent. In this specification, registrars
need to compare bindings in Contact URIs in REGISTER requests (see
Section 10.3.). SIP and SIPS URIs are compared for equality
according to the following rules:
*/
int belle_sip_uri_equals(const belle_sip_uri_t* uri_a,const belle_sip_uri_t* uri_b) {
const belle_sip_list_t * params;
const char* b_param;
const char* a_param;
/*
o A SIP and SIPS URI are never equivalent.
*/
if (belle_sip_uri_is_secure(uri_a)!=belle_sip_uri_is_secure(uri_b)) {
return 0;
}
/*
o Comparison of the userinfo of SIP and SIPS URIs is case-
sensitive. This includes userinfo containing passwords or
formatted as telephone-subscribers. Comparison of all other
components of the URI is case-insensitive unless explicitly
defined otherwise.
*/
if (uri_a->user && uri_b->user) {
if (IS_EQUAL(uri_a->user,uri_b->user)) return 0;
} else if (uri_a->user != uri_a->user) {
return 0;
}
/*
o The ordering of parameters and header fields is not significant
in comparing SIP and SIPS URIs.
o Characters other than those in the "reserved" set (see RFC 2396
[5]) are equivalent to their ""%" HEX HEX" encoding.
o An IP address that is the result of a DNS lookup of a host name
does not match that host name.
o For two URIs to be equal, the user, password, host, and port
components must match.
*/
if (!uri_a->host || !uri_b->host) {
return 0;
} else if (IS_EQUAL_CASE(uri_a->host,uri_b->host)) {
return 0;
}
if (uri_a->port !=uri_b->port) return 0;
/*
A URI omitting the user component will not match a URI that
includes one. A URI omitting the password component will not
match a URI that includes one.
A URI omitting any component with a default value will not
match a URI explicitly containing that component with its
default value. For instance, a URI omitting the optional port
component will not match a URI explicitly declaring port 5060.
The same is true for the transport-parameter, ttl-parameter,
user-parameter, and method components.
Defining sip:user@host to not be equivalent to
sip:user@host:5060 is a change from RFC 2543. When deriving
addresses from URIs, equivalent addresses are expected from
equivalent URIs. The URI sip:user@host:5060 will always
resolve to port 5060. The URI sip:user@host may resolve to
other ports through the DNS SRV mechanisms detailed in [4].
o URI uri-parameter components are compared as follows:
- Any uri-parameter appearing in both URIs must match.
*/
/*
* - A user, ttl, or method uri-parameter appearing in only one
URI never matches, even if it contains the default value.
- A URI that includes an maddr parameter will not match a URI
that contains no maddr parameter.
* */
PARAM_CASE_CMP(uri_a,uri_b,"transport")
PARAM_CASE_CMP(uri_a,uri_b,"user")
PARAM_CASE_CMP(uri_a,uri_b,"ttl")
PARAM_CASE_CMP(uri_a,uri_b,"method")
PARAM_CASE_CMP(uri_a,uri_b,"maddr")
for(params=belle_sip_parameters_get_parameters((belle_sip_parameters_t*) uri_a);params!=NULL;params=params->next) {
if ((b_param=belle_sip_parameters_get_parameter((belle_sip_parameters_t*) uri_b,(const char*)params->data)) !=NULL) {
if (IS_EQUAL_CASE(b_param,(const char*)params->data)) return 0;
}
}
/*
- All other uri-parameters appearing in only one URI are
ignored when comparing the URIs.
*/
/* *fixme ignored for now*/
/*
o URI header components are never ignored. Any present header
component MUST be present in both URIs and match for the URIs
to match. The matching rules are defined for each header field
in Section 20.
*/
return 1;
}
......@@ -24,12 +24,13 @@ static void test_authentication(void) {
const char* l_raw_header = "WWW-Authenticate: Digest "
"algorithm=MD5, realm=\"sip.linphone.org\", opaque=\"1bc7f9097684320\","
" qop=\"auth,auth-int\", nonce=\"cz3h0gAAAAC06TKKAABmTz1V9OcAAAAA\"";
char ha1[33];
belle_sip_header_www_authenticate_t* www_authenticate=belle_sip_header_www_authenticate_parse(l_raw_header);
belle_sip_header_authorization_t* authorization = belle_sip_auth_helper_create_authorization(www_authenticate);
belle_sip_header_authorization_set_uri(authorization,belle_sip_uri_parse("sip:sip.linphone.org"));
belle_sip_header_authorization_set_qop(authorization,"auth");
CU_ASSERT_EQUAL_FATAL(0,belle_sip_auth_helper_fill_authorization(authorization,"REGISTER","jehan-mac","toto"));
//belle_sip_header_authorization_set_qop(authorization,"auth");
CU_ASSERT_EQUAL_FATAL(0,belle_sip_auth_helper_compute_ha1("jehan-mac","sip.linphone.org","toto",ha1));
CU_ASSERT_EQUAL_FATAL(0,belle_sip_auth_helper_fill_authorization(authorization,"REGISTER",ha1));
CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_response(authorization),"77ebf3de72e41934d806175586086508");
belle_sip_object_unref(www_authenticate);
belle_sip_object_unref(authorization);
......@@ -38,12 +39,13 @@ static void test_proxy_authentication(void) {
const char* l_raw_header = "Proxy-Authenticate: Digest "
"algorithm=MD5, realm=\"sip.linphone.org\", opaque=\"1bc7f9097684320\","
" qop=\"auth,auth-int\", nonce=\"cz3h0gAAAAC06TKKAABmTz1V9OcAAAAA\"";
char ha1[33];
belle_sip_header_proxy_authenticate_t* proxy_authenticate=belle_sip_header_proxy_authenticate_parse(l_raw_header);
belle_sip_header_proxy_authorization_t* proxy_authorization = belle_sip_auth_helper_create_proxy_authorization(proxy_authenticate);
belle_sip_header_authorization_set_uri(BELLE_SIP_HEADER_AUTHORIZATION(proxy_authorization),belle_sip_uri_parse("sip:sip.linphone.org"));
belle_sip_header_authorization_set_qop(BELLE_SIP_HEADER_AUTHORIZATION(proxy_authorization),"auth");
CU_ASSERT_EQUAL_FATAL(0,belle_sip_auth_helper_fill_proxy_authorization(proxy_authorization,"REGISTER","jehan-mac","toto"));
//belle_sip_header_authorization_set_qop(BELLE_SIP_HEADER_AUTHORIZATION(proxy_authorization),"auth");
CU_ASSERT_EQUAL_FATAL(0,belle_sip_auth_helper_compute_ha1("jehan-mac","sip.linphone.org","toto",ha1));
CU_ASSERT_EQUAL_FATAL(0,belle_sip_auth_helper_fill_proxy_authorization(proxy_authorization,"REGISTER",ha1));
CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_response(BELLE_SIP_HEADER_AUTHORIZATION(proxy_authorization))
,"77ebf3de72e41934d806175586086508");
belle_sip_object_unref(proxy_authenticate);
......
......@@ -153,6 +153,119 @@ static void testSIMPLEURI_error(void) {
}
static void test_uri_equals(void) {
belle_sip_uri_t* a;
belle_sip_uri_t* b;
/*
* The URIs within each of the following sets are equivalent:
sip:%61lice@atlanta.com;transport=TCP
sip:alice@AtLanTa.CoM;Transport=tcp
*/
a = belle_sip_uri_parse("sip:%61lice@atlanta.com;transport=TCP");
CU_ASSERT_PTR_NOT_NULL_FATAL(a);
b = belle_sip_uri_parse("sip:alice@AtLanTa.CoM;Transport=tcp");
CU_ASSERT_PTR_NOT_NULL_FATAL(b);
CU_ASSERT_TRUE(belle_sip_uri_equals(a,b));
belle_sip_object_unref(a);
belle_sip_object_unref(b);
/*
sip:carol@chicago.com
sip:carol@chicago.com;newparam=5
sip:carol@chicago.com;security=on
*/
a = belle_sip_uri_parse("sip:carol@chicago.com");
CU_ASSERT_PTR_NOT_NULL_FATAL(a);
b = belle_sip_uri_parse("sip:carol@chicago.com;newparam=5");
CU_ASSERT_PTR_NOT_NULL_FATAL(b);
CU_ASSERT_TRUE(belle_sip_uri_equals(a,b));
belle_sip_object_unref(a);
belle_sip_object_unref(b);
/*
sip:biloxi.com;transport=tcp;method=REGISTER?to=sip:bob%40biloxi.com
sip:biloxi.com;method=REGISTER;transport=tcp?to=sip:bob%40biloxi.com
*/
a = belle_sip_uri_parse("sip:biloxi.com;transport=tcp;method=REGISTER?to=sip:bob%40biloxi.com");
CU_ASSERT_PTR_NOT_NULL_FATAL(a);
b = belle_sip_uri_parse("sip:biloxi.com;method=REGISTER;transport=tcp?to=sip:bob%40biloxi.com");
CU_ASSERT_PTR_NOT_NULL_FATAL(b);
CU_ASSERT_TRUE(belle_sip_uri_equals(a,b));
belle_sip_object_unref(a);
belle_sip_object_unref(b);
/*
sip:alice@atlanta.com?subject=project%20x&priority=urgent
sip:alice@atlanta.com?priority=urgent&subject=project%20x
The URIs within each of the following sets are not equivalent:
SIP:ALICE@AtLanTa.CoM;Transport=udp (different usernames)
sip:alice@AtLanTa.CoM;Transport=UDP
*/
a = belle_sip_uri_parse("sip:ALICE@AtLanTa.CoM;Transport=udp");
CU_ASSERT_PTR_NOT_NULL_FATAL(a);
b = belle_sip_uri_parse("sip:alice@AtLanTa.CoM;Transport=UDP");
CU_ASSERT_PTR_NOT_NULL_FATAL(b);
CU_ASSERT_FALSE(belle_sip_uri_equals(a,b));
belle_sip_object_unref(a);
belle_sip_object_unref(b);
/*
sip:bob@biloxi.com (can resolve to different ports)
sip:bob@biloxi.com:5060
*/
a = belle_sip_uri_parse("sip:ALICE@AtLanTa.CoM;Transport=udp");
CU_ASSERT_PTR_NOT_NULL_FATAL(a);
b = belle_sip_uri_parse("sip:alice@AtLanTa.CoM;Transport=UDP");
CU_ASSERT_PTR_NOT_NULL_FATAL(b);
CU_ASSERT_FALSE(belle_sip_uri_equals(a,b));
belle_sip_object_unref(a);
belle_sip_object_unref(b);
/*
sip:bob@biloxi.com (can resolve to different transports)
sip:bob@biloxi.com;transport=udp
*/
a = belle_sip_uri_parse("sip:bob@biloxi.com");
CU_ASSERT_PTR_NOT_NULL_FATAL(a);
b = belle_sip_uri_parse("sip:bob@biloxi.com;transport=udp");
CU_ASSERT_PTR_NOT_NULL_FATAL(b);
CU_ASSERT_FALSE(belle_sip_uri_equals(a,b));
belle_sip_object_unref(a);
belle_sip_object_unref(b);
/* sip:bob@biloxi.com (can resolve to different port and transports)
sip:bob@biloxi.com:6000;transport=tcp
*/
a = belle_sip_uri_parse("sip:bob@biloxi.com");
CU_ASSERT_PTR_NOT_NULL_FATAL(a);
b = belle_sip_uri_parse("sip:bob@biloxi.com:6000;transport=tcp");
CU_ASSERT_PTR_NOT_NULL_FATAL(b);
CU_ASSERT_FALSE(belle_sip_uri_equals(a,b));
belle_sip_object_unref(a);
belle_sip_object_unref(b);
/* sip:carol@chicago.com (different header component)
sip:carol@chicago.com?Subject=next%20meeting
sip:bob@phone21.boxesbybob.com (even though that's what
sip:bob@192.0.2.4 phone21.boxesbybob.com resolves to)
Note that equality is not transitive:
o sip:carol@chicago.com and sip:carol@chicago.com;security=on are
equivalent
o sip:carol@chicago.com and sip:carol@chicago.com;security=off
are equivalent
o sip:carol@chicago.com;security=on and
sip:carol@chicago.com;security=off are not equivalent
Rosenberg, et. al. Standards Track [Page 155]
RFC 3261 SIP: Session Initiation Protocol June 2002
*/
}
int belle_sip_uri_test_suite () {
CU_pSuite pSuite = NULL;
......@@ -174,6 +287,7 @@ int belle_sip_uri_test_suite () {
|| (NULL == CU_add_test(pSuite, "test of headers", test_headers))
|| (NULL == CU_add_test(pSuite, "test of uri parameters", test_uri_parameters))
|| (NULL == CU_add_test(pSuite, "test of sips uri", testSIPSURI))
|| (NULL == CU_add_test(pSuite, "test of uri equal", test_uri_equals))
|| (NULL == CU_add_test(pSuite, "test of error uri", testSIMPLEURI_error)))
{
return CU_get_error();
......
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