Commit 2d3494d3 authored by jehan's avatar jehan

implements both Authorization and Proxy-Autorization headers

parent 93914c45
......@@ -66,6 +66,7 @@ typedef enum belle_sip_type_id{
BELLE_SIP_TYPE_ID(belle_sip_header_t),
BELLE_SIP_TYPE_ID(belle_sip_header_extension_t),
BELLE_SIP_TYPE_ID(belle_sip_header_authorization_t),
BELLE_SIP_TYPE_ID(belle_sip_header_proxy_authorization_t),
belle_sip_type_id_end
}belle_sip_type_id_t;
......
......@@ -251,7 +251,7 @@ void belle_sip_header_content_length_set_content_length(belle_sip_header_content
#define BELLE_SIP_HEADER_CONTENT_LENGTH(t) BELLE_SIP_CAST(t,belle_sip_header_content_length_t)
/******************************
* authorization header inherit from header
* authorization header inherit from parameters
*
******************************/
typedef struct _belle_sip_header_authorization belle_sip_header_authorization_t;
......@@ -283,7 +283,16 @@ void belle_sip_header_authorization_set_username(belle_sip_header_authorization_
#define BELLE_SIP_HEADER_AUTHORIZATION(t) BELLE_SIP_CAST(t,belle_sip_header_authorization_t)
/*******************************
* proxy_authorization inherit from Authorization
*/
typedef struct _belle_sip_header_proxy_authorization belle_sip_header_proxy_authorization_t;
belle_sip_header_proxy_authorization_t* belle_sip_header_proxy_authorization_new();
belle_sip_header_proxy_authorization_t* belle_sip_header_proxy_authorization_parse(const char* proxy_authorization);
#define BELLE_SIP_HEADER_PROXY_AUTHORIZATION(t) BELLE_SIP_CAST(t,belle_sip_header_proxy_authorization_t)
/******************************
*
* Extension header inherit from header
*
******************************/
......@@ -296,4 +305,5 @@ const char* belle_sip_header_extension_get_value(const belle_sip_header_extensio
void belle_sip_header_extension_set_value(belle_sip_header_extension_t* extension,const char* value);
#define BELLE_SIP_HEADER_EXTENSION(t) BELLE_SIP_CAST(t,belle_sip_header_extension_t)
#endif /* HEADERS_H_ */
......@@ -388,18 +388,21 @@ belle_sip_header_extension_t* belle_sip_header_extension_parse (const char* valu
}
GET_SET_STRING(belle_sip_header_extension,value);
/**************************
* content length header object inherent from object
*Authorization header object inherent from parameters
****************************
*/
struct _belle_sip_header_authorization {
belle_sip_header_t header;
belle_sip_parameters_t params_list;
const char* username;
const char* realm;
const char* nonce;
belle_sip_uri_t* uri;
const char* dresponse;
const char* algorithm;
const char* cnonce;
const char* opaque;
const char* message_qop;
int nonce_count;
};
......@@ -412,11 +415,16 @@ static void belle_sip_header_authorization_destroy(belle_sip_header_authorizatio
belle_sip_object_unref(BELLE_SIP_OBJECT(authorization->uri));
}
if (authorization->algorithm) belle_sip_free((void*)authorization->algorithm);
if (authorization->cnonce) belle_sip_free((void*)authorization->cnonce);
if (authorization->opaque) belle_sip_free((void*)authorization->opaque);
if (authorization->message_qop) belle_sip_free((void*)authorization->message_qop);
}
static void belle_sip_header_authorization_clone(belle_sip_header_authorization_t* authorization,
const belle_sip_header_authorization_t *orig ) {
}
static void belle_sip_header_authorization_init(belle_sip_header_authorization_t* authorization) {
}
belle_sip_uri_t* belle_sip_header_authorization_get_uri(const belle_sip_header_authorization_t* authorization) {
return authorization->uri;
......@@ -429,7 +437,7 @@ void belle_sip_header_authorization_set_uri(belle_sip_header_authorization_t* au
authorization->uri=uri;
if (authorization->uri) belle_sip_object_ref(authorization->uri);
}
BELLE_SIP_NEW_HEADER(header_authorization,header,"Authorization")
BELLE_SIP_NEW_HEADER(header_authorization,parameters,"Authorization")
BELLE_SIP_PARSE(header_authorization)
GET_SET_STRING(belle_sip_header_authorization,username);
GET_SET_STRING(belle_sip_header_authorization,realm);
......@@ -442,3 +450,31 @@ void belle_sip_header_authorization_set_response(belle_sip_header_authorization_
belle_sip_header_authorization_set_dresponse(authorization,response);
}
GET_SET_STRING(belle_sip_header_authorization,algorithm);
GET_SET_STRING(belle_sip_header_authorization,cnonce);
GET_SET_STRING(belle_sip_header_authorization,opaque);
GET_SET_STRING(belle_sip_header_authorization,message_qop);
const char* belle_sip_header_authorization_get_qop(const belle_sip_header_authorization_t* authorization) {
return belle_sip_header_authorization_get_message_qop(authorization);
}
void belle_sip_header_authorization_set_qop(belle_sip_header_authorization_t* authorization, const char* qop) {
belle_sip_header_authorization_set_message_qop(authorization,qop);
}
GET_SET_INT(belle_sip_header_authorization,nonce_count,int)
/**************************
*Proxy-Authorization header object inherent from parameters
****************************
*/
struct _belle_sip_header_proxy_authorization {
belle_sip_header_authorization_t authorization;
};
static void belle_sip_header_proxy_authorization_destroy(belle_sip_header_proxy_authorization_t* proxy_authorization) {
}
static void belle_sip_header_proxy_authorization_clone(belle_sip_header_proxy_authorization_t* proxy_authorization,
const belle_sip_header_proxy_authorization_t *orig ) {
}
BELLE_SIP_NEW_HEADER(header_proxy_authorization,header_authorization,"Proxy-Authorization")
BELLE_SIP_PARSE(header_proxy_authorization)
......@@ -219,32 +219,45 @@ digest_token: {IS_TOKEN(Digest)}? token;
header_authorization returns [belle_sip_header_authorization_t* ret]
scope { belle_sip_header_authorization_t* current; }
@init {$header_authorization::current = belle_sip_header_authorization_new(); $ret=$header_authorization::current; }
: authorization_token /*'Authorization'*/ hcolon credentials;
credentials
: (digest_token /*'Digest'*/ LWS digest_response)
: authorization_token /*'Authorization'*/ hcolon credentials[$header_authorization::current];
credentials [belle_sip_header_authorization_t* header_authorization_base]
: (digest_token /*'Digest'*/ LWS digest_response[header_authorization_base])
/*| other_response*/;
digest_response
: dig_resp (comma dig_resp)*;
dig_resp
: username { belle_sip_header_authorization_set_username($header_authorization::current,$username.ret);
digest_response [belle_sip_header_authorization_t* header_authorization_base]
: dig_resp[header_authorization_base] (comma dig_resp[header_authorization_base])*;
dig_resp [belle_sip_header_authorization_t* header_authorization_base]
: username { belle_sip_header_authorization_set_username(header_authorization_base,$username.ret);
belle_sip_free($username.ret);
}
| realm { belle_sip_header_authorization_set_realm($header_authorization::current,$realm.ret);
| realm { belle_sip_header_authorization_set_realm(header_authorization_base,$realm.ret);
belle_sip_free($realm.ret);
}
| nonce { belle_sip_header_authorization_set_nonce($header_authorization::current,$nonce.ret);
| nonce { belle_sip_header_authorization_set_nonce(header_authorization_base,$nonce.ret);
belle_sip_free($nonce.ret);
}
| digest_uri
| dresponse { belle_sip_header_authorization_set_response($header_authorization::current,$dresponse.ret);
| digest_uri[header_authorization_base]
| dresponse { belle_sip_header_authorization_set_response(header_authorization_base,$dresponse.ret);
belle_sip_free($dresponse.ret);
}
/*| algorithm {
belle_sip_header_authorization_set_algoritm($header_authorization::current,$algorithm.ret);
| algorithm {
belle_sip_header_authorization_set_algorithm(header_authorization_base,$algorithm.ret);
}
| cnonce
| opaque | message_qop
| nonce_count | auth_param*/ | (token equal (quoted_string |token)) ;
| cnonce{
belle_sip_header_authorization_set_cnonce(header_authorization_base,$cnonce.ret);
belle_sip_free($cnonce.ret);
}
| opaque {
belle_sip_header_authorization_set_opaque(header_authorization_base,$opaque.ret);
belle_sip_free($opaque.ret);
}
| message_qop{
belle_sip_header_authorization_set_qop(header_authorization_base,$message_qop.ret);
}
| nonce_count{
belle_sip_header_authorization_set_nonce_count(header_authorization_base,atoi($nonce_count.ret));
}
| auth_param[header_authorization_base]
;
username_token: {IS_TOKEN(username)}? token;
username returns [char* ret]
: username_token /*'username'*/ equal username_value {
......@@ -254,9 +267,9 @@ username returns [char* ret]
username_value : quoted_string;
uri_token: {IS_TOKEN(uri)}? token;
digest_uri
digest_uri [belle_sip_header_authorization_t* header_authorization_base]
: uri_token /*'uri'*/ equal DQUOTE uri DQUOTE
{belle_sip_header_authorization_set_uri($header_authorization::current,$uri.ret);
{belle_sip_header_authorization_set_uri(header_authorization_base,$uri.ret);
belle_sip_object_unref(BELLE_SIP_OBJECT($uri.ret));
};
/*
......@@ -265,18 +278,20 @@ rquest_uri
: uri;
*/
// Equal to request-uri as specified by HTTP/1.1
message_qop
: {IS_TOKEN(qop)}? token/*'qop'*/ equal qop_value;
message_qop returns [const char* ret]
: {IS_TOKEN(qop)}? token/*'qop'*/ equal qop_value{$ret = (const char*)$qop_value.text->chars;};
qop_value
: {IS_TOKEN(auth)}? token /*'auth'*/ | {IS_TOKEN(auth-int)}? token /*'auth-int'*/ | token;
cnonce
: {IS_TOKEN(cnonce)}? token /*'cnonce'*/ equal cnonce_value;
cnonce returns [char* ret]
: {IS_TOKEN(cnonce)}? token /*'cnonce'*/ equal cnonce_value {
$ret = _belle_sip_str_dup_and_unquote_string($cnonce_value.text->chars);
};
cnonce_value
: nonce_value;
nonce_count
: {IS_TOKEN(nc)}? token /*'nc'*/ equal nc_value;
nonce_count returns [const char* ret]
: {IS_TOKEN(nc)}? token /*'nc'*/ equal nc_value {$ret=$nc_value.text->chars;};
nc_value
: huit_lhex;
dresponse returns [char* ret]
......@@ -289,17 +304,22 @@ request_digest
huit_lhex
: hexdigit+;
auth_param
auth_param [belle_sip_header_authorization_t* header_authorization_base]
: auth_param_name equal
( token | quoted_string );
auth_param_value {belle_sip_parameters_set_parameter(BELLE_SIP_PARAMETERS(header_authorization_base)
,$auth_param_name.text->chars
,$auth_param_value.text->chars);
}
;
auth_param_value : token | quoted_string ;
auth_param_name
: token;
other_response
/*other_response
: auth_scheme LWS auth_param
(COMMA auth_param)*;
auth_scheme
: token;
/*
authentication_info : 'Authentication-Info' HCOLON ainfo
(COMMA ainfo)*;
ainfo
......@@ -557,26 +577,30 @@ nonce returns [char* ret]
: {IS_TOKEN(nonce)}? token /*'nonce'*/ equal nonce_value{
$ret = _belle_sip_str_dup_and_unquote_string($nonce_value.text->chars);
};
opaque returns [char* ret]
: {IS_TOKEN(opaque)}? token /*'opaque'*/ equal quoted_string{
$ret = _belle_sip_str_dup_and_unquote_string($quoted_string.text->chars);
};
/*
opaque
: 'opaque' EQUAL quoted_string;
stale
: 'stale' EQUAL ( 'true' | 'false' );
*/
algorithm returns [const char* ret]
: {IS_TOKEN(algorithm)}? token 'algorithm' equal ( 'MD5' | 'MD5-sess'
| token {$ret=$token.text->chars;})
: {IS_TOKEN(algorithm)}? token /*'algorithm'*/ equal /* ( 'MD5' | 'MD5-sess'
|*/ alg_value=token {$ret=$alg_value.text->chars;}/*)*/
;
/*
qop_options
: 'qop' EQUAL LDQUOT qop_value
(',' qop_value)* RDQUOT:
qop_value
: 'auth' | 'auth-int' | token;
proxy_authorization
: 'Proxy-Authorization' HCOLON credentials;
*/
header_proxy_authorization returns [belle_sip_header_proxy_authorization_t* ret]
scope { belle_sip_header_proxy_authorization_t* current; }
@init { $header_proxy_authorization::current = belle_sip_header_proxy_authorization_new();$ret = $header_proxy_authorization::current; }
: {IS_TOKEN(Proxy-Authorization)}? token /*'Proxy-Authorization'*/ hcolon credentials[$header_proxy_authorization::current];
/*
proxy_require
: 'Proxy-Require' HCOLON option_tag
(COMMA option_tag)*;
......
......@@ -160,7 +160,8 @@ void test_header_extention(void) {
void test_header_authorization(void) {
const char* l_raw_header = "Authorization: Digest username=\"0033482532176\", "\
"realm=\"sip.ovh.net\", nonce=\"1bcdcb194b30df5f43973d4c69bdf54f\", uri=\"sip:sip.ovh.net\", response=\"eb36c8d5c8642c1c5f44ec3404613c81\","\
"algorithm=MD5, opaque=\"1bc7f9097684320\"";
"algorithm=MD5, opaque=\"1bc7f9097684320\","
"\r\n qop=auth, nc=00000001,cnonce=\"0a4f113b\", blabla=\"toto\"";
belle_sip_header_authorization_t* L_authorization = belle_sip_header_authorization_parse(l_raw_header);
CU_ASSERT_PTR_NOT_NULL(L_authorization);
CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_username(L_authorization), "0033482532176");
......@@ -168,9 +169,27 @@ void test_header_authorization(void) {
CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_nonce(L_authorization), "1bcdcb194b30df5f43973d4c69bdf54f");
CU_ASSERT_PTR_NOT_NULL(belle_sip_header_authorization_get_uri(L_authorization));
CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_response(L_authorization), "eb36c8d5c8642c1c5f44ec3404613c81");
CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_algorithm(L_authorization), "MD5");
CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_opaque(L_authorization), "1bc7f9097684320");
CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_qop(L_authorization), "auth");
CU_ASSERT_EQUAL(belle_sip_header_authorization_get_nonce_count(L_authorization), 1);
CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_cnonce(L_authorization), "0a4f113b");
CU_ASSERT_STRING_EQUAL(belle_sip_parameters_get_parameter(BELLE_SIP_PARAMETERS(L_authorization), "blabla"),"\"toto\"");
belle_sip_object_unref(BELLE_SIP_OBJECT(L_authorization));
}
void test_header_proxy_authorization(void) {
const char* l_raw_header = "Proxy-Authorization: Digest username=\"Alice\""
", realm=\"atlanta.com\", nonce=\"c60f3082ee1212b402a21831ae\""
", response=\"245f23415f11432b3434341c022\"";
belle_sip_header_proxy_authorization_t* L_authorization = belle_sip_header_proxy_authorization_parse(l_raw_header);
CU_ASSERT_PTR_NOT_NULL(L_authorization);
CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_username(BELLE_SIP_HEADER_AUTHORIZATION(L_authorization)), "Alice");
CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_realm(BELLE_SIP_HEADER_AUTHORIZATION(L_authorization)), "atlanta.com");
CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_nonce(BELLE_SIP_HEADER_AUTHORIZATION(L_authorization)), "c60f3082ee1212b402a21831ae");
CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_response(BELLE_SIP_HEADER_AUTHORIZATION(L_authorization)), "245f23415f11432b3434341c022");
belle_sip_object_unref(BELLE_SIP_OBJECT(L_authorization));
}
int belle_sip_headers_test_suite() {
CU_pSuite pSuite = NULL;
......@@ -218,5 +237,8 @@ int belle_sip_headers_test_suite() {
if (NULL == CU_add_test(pSuite, "test of authorization", test_header_authorization)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test of proxy authorization", test_header_proxy_authorization)) {
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