Commit eab273ad authored by jehan's avatar jehan

implement auth-helper api

parent bb7dcee8
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -30,6 +30,7 @@ config.h
*Parser.h
*Parser.c
*.tokens
src/specs.cpp
......@@ -5,19 +5,10 @@
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.dltk.core.scriptbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
<dictionary>
<key>?children?</key>
<value>?name?=outputEntries\|?children?=?name?=entry\\\\\\\|\\\|?name?=entry\\\\\\\|\\\|\||</value>
</dictionary>
<dictionary>
<key>?name?</key>
<value></value>
......@@ -38,10 +29,6 @@
<key>org.eclipse.cdt.make.core.buildCommand</key>
<value>make</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.buildLocation</key>
<value>${workspace_loc:/parser-antlr/Debug}</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.cleanBuildTarget</key>
<value>clean</value>
......@@ -78,15 +65,34 @@
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
<nature>org.deved.antlride.core.nature</nature>
</natures>
<filteredResources>
<filter>
<id>1329213830469</id>
<name></name>
<type>22</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-false-false-*.lo</arguments>
</matcher>
</filter>
<filter>
<id>1329213830473</id>
<name></name>
<type>22</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-false-false-*.o</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2010 Belledonne Communications SARL
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef AUTHENTICATION_HELPER_H_
#define AUTHENTICATION_HELPER_H_
#include "belle-sip/belle-sip.h"
/**
* Create an authorization header from an www_authenticate header, all common parameters are copyed.
* copy params: scheme, realm, nonce, algorithm, opaque
* @param authentication source to be used as input
* @return belle_sip_header_authorization_t*
*/
belle_sip_header_authorization_t* belle_sip_auth_helper_create_authorization(const belle_sip_header_www_authenticate_t* authentication);
/**
* Create an proxy_authorization header from an www_authenticate header, all common parameters are copyed.
* copy params: scheme, realm, nonce, algorithm, opaque
* @param authentication source to be used as input
* @return belle_sip_header_authorization_t*
*/
belle_sip_header_proxy_authorization_t* belle_sip_auth_helper_create_proxy_authorization(const belle_sip_header_proxy_authenticate_t* proxy_authentication);
/**
* compute and set response value according to parameters
* @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);
/**
* 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);
#endif /* AUTHENTICATION_HELPER_H_ */
......@@ -70,8 +70,9 @@ 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_www_authenticate_t),
BELLE_SIP_TYPE_ID(belle_sip_header_proxy_authorization_t),
BELLE_SIP_TYPE_ID(belle_sip_header_www_authenticate_t),
BELLE_SIP_TYPE_ID(belle_sip_header_proxy_authenticate_t),
BELLE_SIP_TYPE_ID(belle_sip_header_max_forwards_t),
BELLE_SIP_TYPE_ID(belle_sip_header_expires_t),
BELLE_SIP_TYPE_ID(belle_sip_header_allow_t),
......
......@@ -321,6 +321,7 @@ void belle_sip_header_authorization_set_nonce(belle_sip_header_authorization_t*
void belle_sip_header_authorization_set_nonce_count(belle_sip_header_authorization_t* authorization, int nonceCount);
void belle_sip_header_authorization_set_opaque(belle_sip_header_authorization_t* authorization, const char* opaque);
void belle_sip_header_authorization_set_qop(belle_sip_header_authorization_t* authorization, const char* qop);
void belle_sip_header_authorization_add_qop(belle_sip_header_authorization_t* authorization, const char* qop);
void belle_sip_header_authorization_set_realm(belle_sip_header_authorization_t* authorization, const char* realm);
void belle_sip_header_authorization_set_response(belle_sip_header_authorization_t* authorization, const char* response);
void belle_sip_header_authorization_set_scheme(belle_sip_header_authorization_t* authorization, const char* scheme);
......@@ -346,7 +347,7 @@ belle_sip_header_www_authenticate_t* belle_sip_header_www_authenticate_parse(con
const char* belle_sip_header_www_authenticate_get_algorithm(const belle_sip_header_www_authenticate_t* www_authenticate );
const char* belle_sip_header_www_authenticate_get_nonce(const belle_sip_header_www_authenticate_t* www_authenticate);
const char* belle_sip_header_www_authenticate_get_opaque(const belle_sip_header_www_authenticate_t* www_authenticate);
const char* belle_sip_header_www_authenticate_get_qop(const belle_sip_header_www_authenticate_t* www_authetication);
belle_sip_list_t* belle_sip_header_www_authenticate_get_qop(const belle_sip_header_www_authenticate_t* www_authetication);
const char* belle_sip_header_www_authenticate_get_realm(const belle_sip_header_www_authenticate_t* www_authenticate);
const char* belle_sip_header_www_authenticate_get_scheme(const belle_sip_header_www_authenticate_t* www_authenticate);
const char* belle_sip_header_www_authenticate_get_domain(const belle_sip_header_www_authenticate_t* www_authenticate);
......@@ -354,14 +355,22 @@ unsigned int belle_sip_header_www_authenticate_is_stale(const belle_sip_header_w
void belle_sip_header_www_authenticate_set_algorithm(belle_sip_header_www_authenticate_t* www_authenticate, const char* algorithm);
void belle_sip_header_www_authenticate_set_nonce(belle_sip_header_www_authenticate_t* www_authenticate, const char* nonce);
void belle_sip_header_www_authenticate_set_opaque(belle_sip_header_www_authenticate_t* www_authenticate, const char* opaque);
void belle_sip_header_www_authenticate_set_qop(belle_sip_header_www_authenticate_t* www_authentication, const char* qop);
void belle_sip_header_www_authenticate_set_qop(belle_sip_header_www_authenticate_t* www_authentication, belle_sip_list_t* qop);
void belle_sip_header_www_authenticate_add_qop(belle_sip_header_www_authenticate_t* www_authentication, const char* qop_param);
void belle_sip_header_www_authenticate_set_realm(belle_sip_header_www_authenticate_t* www_authenticate, const char* realm);
void belle_sip_header_www_authenticate_set_scheme(belle_sip_header_www_authenticate_t* www_authenticate, const char* scheme);
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)
/*******************************
* proxy_authenticate inherit from www_authenticate
*/
typedef struct _belle_sip_header_proxy_authenticate belle_sip_header_proxy_authenticate_t;
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)
/******************************
*
......
......@@ -42,7 +42,8 @@ libbellesip_la_SOURCES=clock_gettime.h \
provider.c \
channel.c channel.h \
message.c \
md5.c
md5.c \
auth_helper.c
libbellesip_la_CFLAGS=$(STRICT_OPTIONS) $(ANTLR_CFLAGS)
......@@ -54,3 +55,7 @@ INCLUDES=-I$(top_srcdir)/include
EXTRA_DIST=$(grammar_files)
CLEANFILES=$(generated_src) *.tokens generated_src_stamp
discovery:
touch specs.cpp
$(CC) $(CFLAGS) $(ANTLR_CFLAGS) $(CUNIT_CFLAGS) -E -P -v -dD specs.cpp
/*
auth_helper.c belle-sip - SIP (RFC3261) library.
Copyright (C) 2010 Belledonne Communications SARL
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "belle-sip/auth-helper.h"
#include "belle_sip_internal.h"
#include "md5.h"
#include <string.h>
#define CHECK_IS_PRESENT(obj,header_name,name) \
if (!belle_sip_header_##header_name##_get_##name(obj)) {\
belle_sip_error("parameter ["#name"]not found for header ["#header_name);\
return-1;\
}
static void belle_sip_auth_helper_clone_authorization(belle_sip_header_authorization_t* authorization, const belle_sip_header_www_authenticate_t* authentication) {
CLONE_STRING_GENERIC(belle_sip_header_www_authenticate,belle_sip_header_authorization,scheme,authorization,authentication)
CLONE_STRING_GENERIC(belle_sip_header_www_authenticate,belle_sip_header_authorization,realm,authorization,authentication)
CLONE_STRING_GENERIC(belle_sip_header_www_authenticate,belle_sip_header_authorization,nonce,authorization,authentication)
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)
}
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_proxy_authorization_t* belle_sip_auth_helper_create_proxy_authorization(const belle_sip_header_proxy_authenticate_t* proxy_authentication){
belle_sip_header_proxy_authorization_t* authorization = belle_sip_header_proxy_authorization_new();
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_fill_authorization(belle_sip_header_authorization_t* authorization
,const char* method
,const char* username
,const char* password) {
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];
int di;
if (belle_sip_header_authorization_get_scheme(authorization) != NULL &&
strcmp("Digest",belle_sip_header_authorization_get_scheme(authorization))!=0) {
belle_sip_error("belle_sip_fill_authorization_header, unsupported schema [%s]"
,belle_sip_header_authorization_get_scheme(authorization));
return -1;
}
if (belle_sip_header_authorization_get_qop(authorization)
&& 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;
}
CHECK_IS_PRESENT(authorization,authorization,realm)
CHECK_IS_PRESENT(authorization,authorization,nonce)
CHECK_IS_PRESENT(authorization,authorization,uri)
if (!method) {
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);
md5_append(&state,(const md5_byte_t *)method,strlen(method));
md5_append(&state,(const md5_byte_t *)":",1);
uri=belle_sip_uri_to_string(belle_sip_header_authorization_get_uri(authorization));
md5_append(&state,(const md5_byte_t *)uri,strlen(uri));
md5_finish(&state,out);
for (di = 0; di < 16; ++di)
sprintf(ha2 + di * 2, "%02x", out[di]);
/*response=MD5(HA1:nonce:HA2)*/
md5_init(&state);
md5_append(&state,(const md5_byte_t *)ha1,strlen(ha1));
md5_append(&state,(const md5_byte_t *)":",1);
md5_append(&state
,(const md5_byte_t *)belle_sip_header_authorization_get_nonce(authorization)
,strlen(belle_sip_header_authorization_get_nonce(authorization)));
md5_append(&state,(const md5_byte_t *)":",1);
md5_append(&state,(const md5_byte_t *)ha2,strlen(ha2));
md5_finish(&state,out);
/*copy values*/
for (di = 0; di < 16; ++di)
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) {
return belle_sip_auth_helper_fill_authorization(BELLE_SIP_HEADER_AUTHORIZATION(proxy_authorization)
,method
,username
,password);
}
......@@ -658,8 +658,10 @@ GET_SET_STRING(belle_sip_header_extension,value);
const char* realm; \
const char* nonce; \
const char* algorithm; \
const char* opaque; \
const char* qop; \
const char* opaque;
#define AUTH_BASE_DESTROY(obj) \
if (obj->scheme) belle_sip_free((void*)obj->scheme);\
......@@ -667,7 +669,7 @@ GET_SET_STRING(belle_sip_header_extension,value);
if (obj->nonce) belle_sip_free((void*)obj->nonce);\
if (obj->algorithm) belle_sip_free((void*)obj->algorithm);\
if (obj->opaque) belle_sip_free((void*)obj->opaque);\
if (obj->qop) belle_sip_free((void*)obj->qop);\
/*if (obj->params_list) FIXME free list*/
#define AUTH_BASE_CLONE(object_type,dest,src) \
......@@ -675,8 +677,8 @@ GET_SET_STRING(belle_sip_header_extension,value);
CLONE_STRING(object_type,realm,dest,src)\
CLONE_STRING(object_type,nonce,dest,src)\
CLONE_STRING(object_type,algorithm,dest,src)\
CLONE_STRING(object_type,opaque,dest,src)\
CLONE_STRING(object_type,qop,dest,src)
CLONE_STRING(object_type,opaque,dest,src) \
#define AUTH_BASE_MARSHAL(header) \
unsigned int current_offset=offset;\
......@@ -710,9 +712,6 @@ GET_SET_STRING(belle_sip_header_extension,value);
border=", ";\
}
struct _belle_sip_header_authorization {
AUTH_BASE
const char* username;
......@@ -720,6 +719,7 @@ GET_SET_STRING(belle_sip_header_extension,value);
const char* response;
const char* cnonce;
int nonce_count;
const char* qop;
};
......@@ -743,6 +743,7 @@ static void belle_sip_header_authorization_clone(belle_sip_header_authorization_
CLONE_STRING(belle_sip_header_authorization,response,authorization,orig)
CLONE_STRING(belle_sip_header_authorization,cnonce,authorization,orig)
authorization->nonce_count=orig->nonce_count;
CLONE_STRING(belle_sip_header_authorization,qop,authorization,orig)
}
static void belle_sip_header_authorization_init(belle_sip_header_authorization_t* authorization) {
}
......@@ -787,7 +788,7 @@ int belle_sip_header_authorization_marshal(belle_sip_header_authorization_t* aut
border=", ";
}
if (authorization->qop) {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%sqop=%s",border,authorization->qop);
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%sqop=%s",border,authorization->qop);
}
return current_offset-offset;
}
......@@ -803,7 +804,6 @@ GET_SET_STRING(belle_sip_header_authorization,cnonce);
GET_SET_STRING(belle_sip_header_authorization,opaque);
GET_SET_STRING(belle_sip_header_authorization,qop);
GET_SET_INT(belle_sip_header_authorization,nonce_count,int)
/**************************
*Proxy-Authorization header object inherent from parameters
****************************
......@@ -825,29 +825,36 @@ int belle_sip_header_proxy_authorization_marshal(belle_sip_header_proxy_authoriz
BELLE_SIP_NEW_HEADER(header_proxy_authorization,header_authorization,"Proxy-Authorization")
BELLE_SIP_PARSE(header_proxy_authorization)
/**************************
*WWW-Authorization header object inherent from parameters
*WWW-Authenticate header object inherent from parameters
****************************
*/
struct _belle_sip_header_www_authenticate {
AUTH_BASE
const char* domain;
unsigned int stale;
belle_sip_list_t* qop;
};
static void belle_sip_header_www_authenticate_destroy(belle_sip_header_www_authenticate_t* www_authenticate) {
if (www_authenticate->domain) belle_sip_free((void*)www_authenticate->domain);
if (www_authenticate->qop) belle_sip_list_free(www_authenticate->qop);\
}
void belle_sip_header_www_authenticate_init(belle_sip_header_www_authenticate_t* www_authenticate) {
www_authenticate->stale=-1;
}
static void* str_copyfunc(void* value){
return strdup((const char*)value);
}
static void belle_sip_header_www_authenticate_clone(belle_sip_header_www_authenticate_t* www_authenticate,
const belle_sip_header_www_authenticate_t *orig ) {
AUTH_BASE_CLONE(belle_sip_header_www_authenticate,www_authenticate,orig)
CLONE_STRING(belle_sip_header_www_authenticate,domain,www_authenticate,orig)
www_authenticate->stale=orig->stale;
www_authenticate->qop=belle_sip_list_copy_with_data(orig->qop,str_copyfunc);
}
int belle_sip_header_www_authenticate_marshal(belle_sip_header_www_authenticate_t* www_authenticate, char* buff,unsigned int offset,unsigned int buff_size) {
belle_sip_list_t* qops=www_authenticate->qop;
AUTH_BASE_MARSHAL(www_authenticate)
if (www_authenticate->domain) {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%sdomain=\"%s\"",border,www_authenticate->domain);\
......@@ -856,12 +863,29 @@ int belle_sip_header_www_authenticate_marshal(belle_sip_header_www_authenticate_
if (www_authenticate->stale>=0) {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%sstale=%s",border,www_authenticate->stale?"true":"false");
}
if (www_authenticate->qop) {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%sqop=\"%s\"",border,www_authenticate->qop);
if (qops!=NULL && qops->data!=NULL) {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%sqop=\"",border);
border="";
for(;qops!=NULL;qops=qops->next){
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s%s",border, (const char*)qops->data);
border=",";
}\
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"\"");
border=", ";
}
return current_offset-offset;
}
#define SET_ADD_STRING_LIST(header,name) \
void header##_set_##name(header##_t* obj, belle_sip_list_t* value) {\
if (obj->name) {\
belle_sip_list_free_with_data(obj->name,belle_sip_free);\
} \
obj->name=value;\
}\
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_PARSE(header_www_authenticate)
GET_SET_STRING(belle_sip_header_www_authenticate,scheme);
......@@ -869,9 +893,35 @@ GET_SET_STRING(belle_sip_header_www_authenticate,realm);
GET_SET_STRING(belle_sip_header_www_authenticate,nonce);
GET_SET_STRING(belle_sip_header_www_authenticate,algorithm);
GET_SET_STRING(belle_sip_header_www_authenticate,opaque);
GET_SET_STRING(belle_sip_header_www_authenticate,qop);
/*GET_SET_STRING(belle_sip_header_www_authenticate,qop);*/
SET_ADD_STRING_LIST(belle_sip_header_www_authenticate,qop)
GET_SET_STRING(belle_sip_header_www_authenticate,domain)
GET_SET_BOOL(belle_sip_header_www_authenticate,stale,is)
belle_sip_list_t* belle_sip_header_www_authenticate_get_qop(const belle_sip_header_www_authenticate_t* www_authetication) {
return www_authetication->qop;
}
/**************************
*Proxy-authenticate header object inherent from www_authenticate
****************************
*/
struct _belle_sip_header_proxy_authenticate {
belle_sip_header_www_authenticate_t www_authenticate;
};
static void belle_sip_header_proxy_authenticate_destroy(belle_sip_header_proxy_authenticate_t* proxy_authenticate) {
}
static void belle_sip_header_proxy_authenticate_clone(belle_sip_header_proxy_authenticate_t* proxy_authenticate,
const belle_sip_header_proxy_authenticate_t *orig ) {
}
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_PARSE(header_proxy_authenticate)
/**************************
* max forwards header object inherent from header
****************************
......
......@@ -209,6 +209,7 @@ BELLE_SIP_DECLARE_VPTR(belle_sip_header_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_extension_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_authorization_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_www_authenticate_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_proxy_authenticate_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_proxy_authorization_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_max_forwards_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_expires_t);
......@@ -404,11 +405,13 @@ char *belle_sip_strdup_printf(const char *fmt,...);
#define DESTROY_STRING(object,attribute) if (object->attribute) belle_sip_free((void*)object->attribute);
#define CLONE_STRING(object_type,attribute,dest,src) \
if ( object_type##_get_##attribute (src)) {\
object_type##_set_##attribute(dest,object_type##_get_##attribute(src));\
#define CLONE_STRING_GENERIC(object_type_src,object_type_dest,attribute,dest,src) \
if ( object_type_src##_get_##attribute (src)) {\
object_type_dest##_set_##attribute(dest,object_type_src##_get_##attribute(src));\
}
#define CLONE_STRING(object_type,attribute,dest,src) CLONE_STRING_GENERIC(object_type,object_type,attribute,dest,src)
#define GET_SET_INT(object_type,attribute,type) GET_SET_INT_PRIVATE(object_type,attribute,type,)
#define GET_SET_INT_PRIVATE(object_type,attribute,type,set_prefix) \
......
......@@ -264,7 +264,7 @@ dig_resp [belle_sip_header_authorization_t* header_authorization_base]
belle_sip_free($opaque.ret);
}
| message_qop{
belle_sip_header_authorization_set_qop(header_authorization_base,(char*)$message_qop.ret);
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((char*)$nonce_count.ret));
......@@ -291,10 +291,10 @@ rquest_uri
*/
// Equal to request-uri as specified by HTTP/1.1
message_qop returns [const char* ret]
: {IS_TOKEN(qop)}? token/*'qop'*/ equal qop_value{$ret = (const char*)$qop_value.text->chars;};
: {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;
: token;
cnonce returns [char* ret]
: {IS_TOKEN(cnonce)}? token /*'cnonce'*/ equal cnonce_value {
......@@ -577,10 +577,13 @@ priority_value
| 'non-urgent' | other_priority;
other_priority
: token;
proxy_authenticate
: 'Proxy-Authenticate' HCOLON challenge;
*/
header_proxy_authenticate returns [belle_sip_header_proxy_authenticate_t* ret]
scope { belle_sip_header_proxy_authenticate_t* current; }
@init { $header_proxy_authenticate::current = belle_sip_header_proxy_authenticate_new();$ret = $header_proxy_authenticate::current; }
: {IS_TOKEN(Proxy-Authenticate)}? token /*'Proxy-Authenticate'*/
hcolon challenge[BELLE_SIP_HEADER_WWW_AUTHENTICATE($header_proxy_authenticate::current)];
challenge [belle_sip_header_www_authenticate_t* www_authenticate]
: ({IS_TOKEN(Digest)}? token /*'Digest'*/ {belle_sip_header_www_authenticate_set_scheme(www_authenticate,"Digest");}
LWS digest_cln[www_authenticate] (comma digest_cln[www_authenticate])*)
......@@ -599,7 +602,7 @@ digest_cln [belle_sip_header_www_authenticate_t* www_authenticate]
| opaque {belle_sip_header_www_authenticate_set_opaque(www_authenticate,$opaque.ret);
belle_sip_free($opaque.ret);}
| qop_opts {belle_sip_header_www_authenticate_set_qop(www_authenticate,$qop_opts.ret);
belle_sip_free($qop_opts.ret);}
/*belle_sip_free($qop_opts.ret);*/}
| domain {belle_sip_header_www_authenticate_set_domain(www_authenticate,$domain.ret);
belle_sip_free($domain.ret);}
| stale { if (strcmp("true",$stale.ret)==0) {
......@@ -643,14 +646,18 @@ algorithm returns [const char* ret]
|*/ alg_value=token {$ret=(char*)$alg_value.text->chars;}/*)*/
;
qop_opts returns [char* ret]
: {IS_TOKEN(qop)}? token /*'qop'*/ equal quoted_string {
$ret = _belle_sip_str_dup_and_unquote_string((char*)$quoted_string.text->chars);
};/*LDQUOT qop_value
(COMMA qop_value)* RDQUOT:*/
/*qop_value
: 'auth' | 'auth-int' | token;
*/
qop_opts returns [belle_sip_list_t* ret]
scope { belle_sip_list_t* list; }
@init{$qop_opts::list=NULL;}
: {IS_TOKEN(qop)}? token /*'qop'*/ equal
ldquot
qop_opts_value
(COMMA qop_opts_value)*
rdquot {$ret=$qop_opts::list;} ;
qop_opts_value
: token {$qop_opts::list=belle_sip_list_append($qop_opts::list,strdup((const char*)$token.text->chars));};
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; }
......@@ -994,8 +1001,8 @@ HTAB : ' ';
ldquot : LWS? DQUOTE ;
rdquot : DQUOTE LWS?;
DQUOTE : '"';
// open double quotation mark
......
This diff is collapsed.
/*
Copyright (C) 1999, 2002 Aladdin Enterprises. All rights reserved.
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
L. Peter Deutsch
ghost@aladdin.com
*/
/* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */
/*
Independent implementation of MD5 (RFC 1321).
This code implements the MD5 Algorithm defined in RFC 1321, whose
text is available at
http://www.ietf.org/rfc/rfc1321.txt
The code is derived from the text of the RFC, including the test suite
(section A.5) but excluding the rest of Appendix A. It does not include
any code or documentation that is identified in the RFC as being
copyrighted.
The original and principal author of md5.h is L. Peter Deutsch
<ghost@aladdin.com>. Other authors are noted in the change history
that follows (in reverse chronological order):
2002-04-13 lpd Removed support for non-ANSI compilers; removed
references to Ghostscript; clarified derivation from RFC 1321;
now handles byte order either statically or dynamically.
1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
added conditionalization for C++ compilation from Martin
Purschke <purschke@bnl.gov>.
1999-05-03 lpd Original version.
*/
#ifndef md5_INCLUDED
# define md5_INCLUDED
/*
* This package supports both compile-time and run-time determination of CPU
* byte order. If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be
* compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is
* defined as non-zero, the code will be compiled to run only on big-endian
* CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to
* run on either big- or little-endian CPUs, but will run slightly less
* efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined.
*/
typedef unsigned char md5_byte_t; /* 8-bit byte */
typedef unsigned int md5_word_t; /* 32-bit word */
/* Define the state of the MD5 Algorithm. */
typedef struct md5_state_s {
md5_word_t count[2]; /* message length in bits, lsw first */
md5_word_t abcd[4]; /* digest buffer */
md5_byte_t buf[64]; /* accumulate block */
} md5_state_t;
#ifdef __cplusplus
extern "C"
{
#endif
/* Initialize the algorithm. */
void md5_init(md5_state_t *pms);
/* Append a string to the message. */
void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes);
/* Finish the message and return the digest. */
void md5_finish(md5_state_t *pms, md5_byte_t digest[16]);
#ifdef __cplusplus
} /* end extern "C" */
#endif
#endif /* md5_INCLUDED */
......@@ -6,7 +6,8 @@ belle_sip_tester_SOURCES= belle_sip_tester.c \
belle_sdp_tester.c \
belle_sip_uri_tester.c \
belle_sip_headers_tester.c \
belle_sip_message_tester.c
belle_sip_message_tester.c \
auth_helper_tester.c
belle_sip_tester_CFLAGS=$(CUNIT_CFLAGS)
belle_sip_tester_LDFLAGS=$(CUNIT_LIBS)
......@@ -25,4 +26,8 @@ AM_LDFLAGS=-export-dynamic
AM_CFLAGS=$(STRICT_OPTIONS)
test: belle_sip_tester
./belle_sip_tester
endif