Commit 2c2462c4 authored by rosset claire's avatar rosset claire

Wrapped auth info in C++

parent 9bc9717b
......@@ -25,333 +25,22 @@
#include "linphone/core.h"
#include "linphone/lpconfig.h"
#include "sal/sal.h"
#include "linphone/api/c-auth-info.h"
#include "c-wrapper/c-wrapper.h"
#include "auth-info/auth-info.h"
// TODO: From coreapi. Remove me later.
#include "private.h"
static void _linphone_auth_info_uninit(LinphoneAuthInfo *obj);
static void _linphone_auth_info_copy(LinphoneAuthInfo *dst, const LinphoneAuthInfo *src);
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneAuthInfo);
BELLE_SIP_DECLARE_VPTR_NO_EXPORT(LinphoneAuthInfo);
BELLE_SIP_INSTANCIATE_VPTR(
LinphoneAuthInfo,
belle_sip_object_t,
_linphone_auth_info_uninit, // destroy
_linphone_auth_info_copy, // clone
NULL, // marshal
FALSE
);
LinphoneAuthInfo *linphone_auth_info_new(const char *username, const char *userid, const char *passwd, const char *ha1, const char *realm, const char *domain){
return linphone_auth_info_new_for_algorithm(username, userid, passwd, ha1, realm, domain, NULL);
}
LinphoneAuthInfo *linphone_auth_info_new_for_algorithm(const char *username, const char *userid, const char *passwd, const char *ha1, const char *realm, const char *domain, const char *algorithm){
LinphoneAuthInfo *obj=belle_sip_object_new(LinphoneAuthInfo);
if (username!=NULL && (strlen(username)>0) ) obj->username=ms_strdup(username);
if (userid!=NULL && (strlen(userid)>0)) obj->userid=ms_strdup(userid);
if (passwd!=NULL && (strlen(passwd)>0)) obj->passwd=ms_strdup(passwd);
if (ha1!=NULL && (strlen(ha1)>0)) obj->ha1=ms_strdup(ha1);
if (realm!=NULL && (strlen(realm)>0)) obj->realm=ms_strdup(realm);
if (domain!=NULL && (strlen(domain)>0)) obj->domain=ms_strdup(domain);
if (!algorithm) {
obj->algorithm = ms_strdup("MD5");
return obj;
}
if(algorithm && strcasecmp(algorithm, "MD5") && strcasecmp(algorithm, "SHA-256")){
ms_error("Given algorithm %s is not correct.", algorithm);
return NULL;
}
obj->algorithm=ms_strdup(algorithm);
return obj;
}
static void _linphone_auth_info_copy(LinphoneAuthInfo *dst, const LinphoneAuthInfo *src) {
if (src->username) dst->username = ms_strdup(src->username);
if (src->userid) dst->userid = ms_strdup(src->userid);
if (src->passwd) dst->passwd = ms_strdup(src->passwd);
if (src->ha1) dst->ha1 = ms_strdup(src->ha1);
if (src->realm) dst->realm = ms_strdup(src->realm);
if (src->domain) dst->domain = ms_strdup(src->domain);
if (src->tls_cert) dst->tls_cert = ms_strdup(src->tls_cert);
if (src->tls_key) dst->tls_key = ms_strdup(src->tls_key);
if (src->tls_cert_path) dst->tls_cert_path = ms_strdup(src->tls_cert_path);
if (src->tls_key_path) dst->tls_key_path = ms_strdup(src->tls_key_path);
if (src->algorithm) dst->algorithm = ms_strdup(src->algorithm);
}
LinphoneAuthInfo *linphone_auth_info_clone(const LinphoneAuthInfo *ai){
return LINPHONE_AUTH_INFO(belle_sip_object_clone(BELLE_SIP_OBJECT(ai)));
}
LinphoneAuthInfo *linphone_auth_info_ref(LinphoneAuthInfo *obj) {
return LINPHONE_AUTH_INFO(belle_sip_object_ref(obj));
}
void linphone_auth_info_unref(LinphoneAuthInfo *obj) {
belle_sip_object_unref(obj);
}
const char *linphone_auth_info_get_username(const LinphoneAuthInfo *i) {
return i->username;
}
const char *linphone_auth_info_get_algorithm(const LinphoneAuthInfo *i) {
return i->algorithm;
}
const char *linphone_auth_info_get_passwd(const LinphoneAuthInfo *i) {
return linphone_auth_info_get_password(i);
}
const char *linphone_auth_info_get_password(const LinphoneAuthInfo *i) {
return i->passwd;
}
const char *linphone_auth_info_get_userid(const LinphoneAuthInfo *i) {
return i->userid;
}
const char *linphone_auth_info_get_realm(const LinphoneAuthInfo *i) {
return i->realm;
}
const char *linphone_auth_info_get_domain(const LinphoneAuthInfo *i) {
return i->domain;
}
const char *linphone_auth_info_get_ha1(const LinphoneAuthInfo *i) {
return i->ha1;
}
const char *linphone_auth_info_get_tls_cert(const LinphoneAuthInfo *i) {
return i->tls_cert;
}
const char *linphone_auth_info_get_tls_key(const LinphoneAuthInfo *i) {
return i->tls_key;
}
const char *linphone_auth_info_get_tls_cert_path(const LinphoneAuthInfo *i) {
return i->tls_cert_path;
}
const char *linphone_auth_info_get_tls_key_path(const LinphoneAuthInfo *i) {
return i->tls_key_path;
}
void linphone_auth_info_set_passwd(LinphoneAuthInfo *info, const char *passwd) {
linphone_auth_info_set_password(info, passwd);
}
void linphone_auth_info_set_password(LinphoneAuthInfo *info, const char *passwd) {
if (info->passwd) {
ms_free(info->passwd);
info->passwd = NULL;
}
if (passwd && strlen(passwd) > 0) info->passwd = ms_strdup(passwd);
}
void linphone_auth_info_set_username(LinphoneAuthInfo *info, const char *username) {
if (info->username) {
ms_free(info->username);
info->username = NULL;
}
if (username && strlen(username) > 0) info->username = ms_strdup(username);
}
void linphone_auth_info_set_algorithm(LinphoneAuthInfo *info, const char *algorithm) {
if (info->algorithm) {
ms_free(info->algorithm);
info->algorithm = NULL;
}
if (!algorithm) {
info->algorithm = ms_strdup("MD5");
return;
}
if(algorithm && strcasecmp(algorithm, "MD5") && strcasecmp(algorithm, "SHA-256")){
ms_error("Given algorithm %s is not correct. Set algorithm failed", algorithm);
return;
}
info->algorithm = ms_strdup(algorithm);
}
void linphone_auth_info_set_userid(LinphoneAuthInfo *info, const char *userid) {
if (info->userid) {
ms_free(info->userid);
info->userid = NULL;
}
if (userid && strlen(userid) > 0) info->userid = ms_strdup(userid);
}
void linphone_auth_info_set_realm(LinphoneAuthInfo *info, const char *realm) {
if (info->realm) {
ms_free(info->realm);
info->realm = NULL;
}
if (realm && strlen(realm) > 0) info->realm = ms_strdup(realm);
}
void linphone_auth_info_set_domain(LinphoneAuthInfo *info, const char *domain) {
if (info->domain) {
ms_free(info->domain);
info->domain = NULL;
}
if (domain && strlen(domain) > 0) info->domain = ms_strdup(domain);
}
void linphone_auth_info_set_ha1(LinphoneAuthInfo *info, const char *ha1) {
if (info->ha1) {
ms_free(info->ha1);
info->ha1 = NULL;
}
if (ha1 && strlen(ha1) > 0) info->ha1 = ms_strdup(ha1);
}
void linphone_auth_info_set_tls_cert(LinphoneAuthInfo *info, const char *tls_cert) {
if (info->tls_cert) {
ms_free(info->tls_cert);
info->tls_cert = NULL;
}
if (tls_cert && strlen(tls_cert) > 0) info->tls_cert = ms_strdup(tls_cert);
}
void linphone_auth_info_set_tls_key(LinphoneAuthInfo *info, const char *tls_key) {
if (info->tls_key) {
ms_free(info->tls_key);
info->tls_key = NULL;
}
if (tls_key && strlen(tls_key) > 0) info->tls_key = ms_strdup(tls_key);
}
void linphone_auth_info_set_tls_cert_path(LinphoneAuthInfo *info, const char *tls_cert_path) {
if (info->tls_cert_path) {
ms_free(info->tls_cert_path);
info->tls_cert_path = NULL;
}
if (tls_cert_path && strlen(tls_cert_path) > 0) info->tls_cert_path = ms_strdup(tls_cert_path);
}
void linphone_auth_info_set_tls_key_path(LinphoneAuthInfo *info, const char *tls_key_path) {
if (info->tls_key_path) {
ms_free(info->tls_key_path);
info->tls_key_path = NULL;
}
if (tls_key_path && strlen(tls_key_path) > 0) info->tls_key_path = ms_strdup(tls_key_path);
}
static void _linphone_auth_info_uninit(LinphoneAuthInfo *obj) {
if (obj->username != NULL) ms_free(obj->username);
if (obj->userid != NULL) ms_free(obj->userid);
if (obj->passwd != NULL) ms_free(obj->passwd);
if (obj->ha1 != NULL) ms_free(obj->ha1);
if (obj->realm != NULL) ms_free(obj->realm);
if (obj->domain != NULL) ms_free(obj->domain);
if (obj->tls_cert != NULL) ms_free(obj->tls_cert);
if (obj->tls_key != NULL) ms_free(obj->tls_key);
if (obj->tls_cert_path != NULL) ms_free(obj->tls_cert_path);
if (obj->tls_key_path != NULL) ms_free(obj->tls_key_path);
if (obj->algorithm != NULL) ms_free(obj->algorithm);
}
/**
* Destroys a LinphoneAuthInfo object.
**/
void linphone_auth_info_destroy(LinphoneAuthInfo *obj){
belle_sip_object_unref(obj);
}
void linphone_auth_info_write_config(LpConfig *config, LinphoneAuthInfo *obj, int pos) {
char key[50];
bool_t store_ha1_passwd = !!lp_config_get_int(config, "sip", "store_ha1_passwd", 1);
sprintf(key, "auth_info_%i", pos);
lp_config_clean_section(config, key);
if (obj == NULL || lp_config_get_int(config, "sip", "store_auth_info", 1) == 0) {
return;
}
if (!obj->ha1 && obj->realm && obj->passwd && (obj->username || obj->userid) && store_ha1_passwd) {
/* Default algorithm is MD5 if it's NULL */
if((obj->algorithm==NULL)||(!(strcasecmp(obj->algorithm, "MD5")))){
obj->ha1 = reinterpret_cast<char *>(ms_malloc(33));
sal_auth_compute_ha1(obj->userid ? obj->userid : obj->username, obj->realm, obj->passwd, obj->ha1);
}
/* If algorithm is SHA-256, calcul ha1 by sha256*/
if((obj->algorithm)&&(!(strcasecmp(obj->algorithm, "SHA-256")))){
obj->ha1 = reinterpret_cast<char *>(ms_malloc(65));
sal_auth_compute_ha1_for_algorithm(obj->userid ? obj->userid : obj->username, obj->realm, obj->passwd, obj->ha1,65, obj->algorithm);
}
}
if (obj->username != NULL) {
lp_config_set_string(config, key, "username", obj->username);
}
if (obj->userid != NULL) {
lp_config_set_string(config, key, "userid", obj->userid);
}
if (obj->ha1 != NULL) {
lp_config_set_string(config, key, "ha1", obj->ha1);
}
if (obj->passwd != NULL) {
if (store_ha1_passwd && obj->ha1) {
/*if we have our ha1 and store_ha1_passwd set to TRUE, then drop the clear text password for security*/
linphone_auth_info_set_passwd(obj, NULL);
} else {
/*we store clear text password only if store_ha1_passwd is FALSE AND we have an ha1 to store. Otherwise, passwd would simply be removed, which might bring major auth issue*/
lp_config_set_string(config, key, "passwd", obj->passwd);
}
}
if (obj->realm != NULL) {
lp_config_set_string(config, key, "realm", obj->realm);
}
if (obj->domain != NULL) {
lp_config_set_string(config, key, "domain", obj->domain);
}
if (obj->tls_cert_path != NULL) {
lp_config_set_string(config, key, "client_cert_chain", obj->tls_cert_path);
}
if (obj->tls_key_path != NULL) {
lp_config_set_string(config, key, "client_cert_key", obj->tls_key_path);
}
if (obj->algorithm != NULL) {
lp_config_set_string(config, key, "algorithm", obj->algorithm);
}
}
LinphoneAuthInfo *linphone_auth_info_new_from_config_file(LpConfig * config, int pos)
{
char key[50];
const char *username,*userid,*passwd,*ha1,*realm,*domain,*tls_cert_path,*tls_key_path;
LinphoneAuthInfo *ret;
sprintf(key, "auth_info_%i", pos);
if (!lp_config_has_section(config, key)) {
return NULL;
}
username = lp_config_get_string(config, key, "username", NULL);
userid = lp_config_get_string(config, key, "userid", NULL);
passwd = lp_config_get_string(config, key, "passwd", NULL);
ha1 = lp_config_get_string(config, key, "ha1", NULL);
realm = lp_config_get_string(config, key, "realm", NULL);
domain = lp_config_get_string(config, key, "domain", NULL);
tls_cert_path = lp_config_get_string(config, key, "client_cert_chain", NULL);
tls_key_path = lp_config_get_string(config, key, "client_cert_key", NULL);
ret = linphone_auth_info_new(username, userid, passwd, ha1, realm, domain);
linphone_auth_info_set_tls_cert_path(ret, tls_cert_path);
linphone_auth_info_set_tls_key_path(ret, tls_key_path);
linphone_auth_info_set_algorithm(ret, lp_config_get_string(config, key, "algorithm", "MD5"));
return ret;
}
static char * remove_quotes(char * input){
char *tmp;
if (*input=='"') input++;
......@@ -384,23 +73,25 @@ static const LinphoneAuthInfo *find_auth_info(LinphoneCore *lc, const char *user
for (elem=lc->auth_info;elem!=NULL;elem=elem->next) {
LinphoneAuthInfo *pinfo = (LinphoneAuthInfo*)elem->data;
if (username && pinfo->username && strcmp(username,pinfo->username)==0) {
if (username && linphone_auth_info_get_username(pinfo) && strcmp(username, linphone_auth_info_get_username(pinfo))==0)
{
if (realm && domain){
if (pinfo->realm && realm_match(realm,pinfo->realm)
&& pinfo->domain && strcmp(domain,pinfo->domain)==0) {
if (linphone_auth_info_get_realm(pinfo) && realm_match(realm, linphone_auth_info_get_realm(pinfo))
&& linphone_auth_info_get_domain(pinfo) && strcmp(domain, linphone_auth_info_get_domain(pinfo))==0) {
return pinfo;
}
} else if (realm) {
if (pinfo->realm && realm_match(realm,pinfo->realm)) {
if (linphone_auth_info_get_realm(pinfo) && realm_match(realm, linphone_auth_info_get_realm(pinfo))) {
if (ret!=NULL) {
ms_warning("Non unique realm found for %s",username);
return NULL;
}
ret=pinfo;
}
} else if (domain && pinfo->domain && strcmp(domain,pinfo->domain)==0 && (pinfo->ha1==NULL || ignore_realm)) {
} else if (domain && linphone_auth_info_get_domain(pinfo) && strcmp(domain,linphone_auth_info_get_domain(pinfo))==0 && (linphone_auth_info_get_ha1(pinfo)==NULL || ignore_realm)) {
return pinfo;
} else if (!domain && (pinfo->ha1==NULL || ignore_realm)) {
} else if (!domain && (linphone_auth_info_get_ha1(pinfo)==NULL || ignore_realm)) {
return pinfo;
}
}
......@@ -412,9 +103,9 @@ const LinphoneAuthInfo *_linphone_core_find_tls_auth_info(LinphoneCore *lc) {
bctbx_list_t *elem;
for (elem=lc->auth_info;elem!=NULL;elem=elem->next) {
LinphoneAuthInfo *pinfo = (LinphoneAuthInfo*)elem->data;
if (pinfo->tls_cert && pinfo->tls_key) {
if (linphone_auth_info_get_tls_cert(pinfo) && linphone_auth_info_get_tls_key(pinfo)) {
return pinfo;
} else if (pinfo->tls_cert_path && pinfo->tls_key_path) {
} else if (linphone_auth_info_get_tls_cert_path(pinfo) && linphone_auth_info_get_tls_key_path(pinfo)) {
return pinfo;
}
}
......@@ -435,7 +126,8 @@ const LinphoneAuthInfo *_linphone_core_find_auth_info(LinphoneCore *lc, const ch
if (ai==NULL){
ai=find_auth_info(lc,username,NULL,NULL, ignore_realm);
}
if (ai) ms_message("linphone_core_find_auth_info(): returning auth info username=%s, realm=%s", ai->username ? ai->username : "", ai->realm ? ai->realm : "");
if (ai) ms_message("linphone_core_find_auth_info(): returning auth info username=%s, realm=%s", linphone_auth_info_get_username(ai) ? linphone_auth_info_get_username(ai) : "", linphone_auth_info_get_realm(ai) ? linphone_auth_info_get_realm(ai) : "");
return ai;
}
......@@ -470,23 +162,22 @@ static void write_auth_infos(LinphoneCore *lc){
linphone_auth_info_write_config(lc->config,NULL,i); /* mark the end */
}
LinphoneAuthInfo * linphone_core_create_auth_info(LinphoneCore *lc, const char *username, const char *userid, const char *passwd, const char *ha1, const char *realm, const char *domain) {
return linphone_auth_info_new(username, userid, passwd, ha1, realm, domain);
LinphoneAuthInfo *linphone_core_create_auth_info(LinphoneCore *lc, const char *username, const char *userid, const char *passwd, const char *ha1, const char *realm, const char *domain) {
return linphone_auth_info_new(username, userid, passwd, ha1, realm, domain);
}
void linphone_core_add_auth_info(LinphoneCore *lc, const LinphoneAuthInfo *info){
LinphoneAuthInfo *ai;
LinphoneAuthInfo *ai=NULL;
int restarted_op_count=0;
bool_t updating=FALSE;
if (info->tls_key == NULL && info->tls_key_path == NULL
&& info->ha1==NULL && info->passwd==NULL){
ms_error("linphone_core_add_auth_info(): info supplied with empty password, ha1 or TLS client/key");
if (!linphone_auth_info_get_tls_key(info) && !linphone_auth_info_get_tls_key_path(info) && !linphone_auth_info_get_ha1(info) && !linphone_auth_info_get_password(info) ){
ms_fatal("linphone_core_add_auth_info(): info supplied with empty password, ha1 or TLS client/key");
return;
}
/* find if we are attempting to modify an existing auth info */
ai=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,info->realm,info->username,info->domain);
if (ai!=NULL && ai->domain && info->domain && strcmp(ai->domain, info->domain)==0){
ai=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,linphone_auth_info_get_realm(info),linphone_auth_info_get_username(info),linphone_auth_info_get_domain(info));
if (ai!=NULL && linphone_auth_info_get_domain(ai) && linphone_auth_info_get_domain(info) && strcmp(linphone_auth_info_get_domain(ai), linphone_auth_info_get_domain(info))==0){
lc->auth_info=bctbx_list_remove(lc->auth_info,ai);
linphone_auth_info_unref(ai);
updating=TRUE;
......@@ -498,22 +189,22 @@ void linphone_core_add_auth_info(LinphoneCore *lc, const LinphoneAuthInfo *info)
for (const auto &op : pendingAuths) {
LinphoneAuthInfo *ai;
const SalAuthInfo *req_sai=op->getAuthRequested();
ai=(LinphoneAuthInfo*)_linphone_core_find_auth_info(lc,req_sai->realm,req_sai->username,req_sai->domain, FALSE);
ai=(LinphoneAuthInfo*)_linphone_core_find_auth_info(lc, req_sai->realm, req_sai->username, req_sai->domain, FALSE);
if (ai){
SalAuthInfo sai;
bctbx_list_t* proxy;
sai.username=ai->username;
sai.userid=ai->userid;
sai.realm=ai->realm;
sai.password=ai->passwd;
sai.ha1=ai->ha1;
sai.algorithm=ai->algorithm;
if (ai->tls_cert && ai->tls_key) {
sal_certificates_chain_parse(&sai, ai->tls_cert, SAL_CERTIFICATE_RAW_FORMAT_PEM);
sal_signing_key_parse(&sai, ai->tls_key, "");
} else if (ai->tls_cert_path && ai->tls_key_path) {
sal_certificates_chain_parse_file(&sai, ai->tls_cert_path, SAL_CERTIFICATE_RAW_FORMAT_PEM);
sal_signing_key_parse_file(&sai, ai->tls_key_path, "");
sai.username = (char *) linphone_auth_info_get_username(ai);
sai.userid = (char *)linphone_auth_info_get_userid(ai);
sai.realm = (char *) linphone_auth_info_get_realm(ai);
sai.password = (char *) linphone_auth_info_get_passwd(ai);
sai.ha1 = (char *)linphone_auth_info_get_ha1(ai);
sai.algorithm = (char *)linphone_auth_info_get_algorithm(ai);
if (linphone_auth_info_get_tls_cert(ai) && linphone_auth_info_get_tls_key(ai)) {
sal_certificates_chain_parse(&sai, linphone_auth_info_get_tls_cert(ai), SAL_CERTIFICATE_RAW_FORMAT_PEM);
sal_signing_key_parse(&sai, linphone_auth_info_get_tls_key(ai), "");
} else if (linphone_auth_info_get_tls_cert_path(ai) && linphone_auth_info_get_tls_key_path(ai)) {
sal_certificates_chain_parse_file(&sai, linphone_auth_info_get_tls_cert_path(ai), SAL_CERTIFICATE_RAW_FORMAT_PEM);
sal_signing_key_parse_file(&sai, linphone_auth_info_get_tls_key_path(ai), "");
}
/*proxy case*/
for (proxy=(bctbx_list_t*)linphone_core_get_proxy_config_list(lc);proxy!=NULL;proxy=proxy->next) {
......@@ -533,9 +224,9 @@ void linphone_core_add_auth_info(LinphoneCore *lc, const LinphoneAuthInfo *info)
"\tdomain [%s]\n",
restarted_op_count,
updating ? "updating" : "adding",
info->username ? info->username : "",
info->realm ? info->realm : "",
info->domain ? info->domain : "");
linphone_auth_info_get_username(info) ? linphone_auth_info_get_username(info) : "",
linphone_auth_info_get_realm(info) ? linphone_auth_info_get_realm(info) : "",
linphone_auth_info_get_domain(info) ? linphone_auth_info_get_domain(info) : "");
}
write_auth_infos(lc);
}
......@@ -545,7 +236,7 @@ void linphone_core_abort_authentication(LinphoneCore *lc, LinphoneAuthInfo *inf
void linphone_core_remove_auth_info(LinphoneCore *lc, const LinphoneAuthInfo *info){
LinphoneAuthInfo *r;
r=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,info->realm,info->username,info->domain);
r=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc, linphone_auth_info_get_realm(info), linphone_auth_info_get_username(info), linphone_auth_info_get_domain(info));
if (r){
lc->auth_info=bctbx_list_remove(lc->auth_info,r);
linphone_auth_info_unref(r);
......
......@@ -86,10 +86,13 @@ static void call_received(SalCallOp *h) {
if (pAssertedIdAddr) {
ms_message("Using P-Asserted-Identity [%s] instead of from [%s] for op [%p]", pAssertedId, h->getFrom().c_str(), h);
fromAddr = pAssertedIdAddr;
} else
} else{
ms_warning("Unsupported P-Asserted-Identity header for op [%p] ", h);
} else
}
} else{
ms_warning("No P-Asserted-Identity header found so cannot use it for op [%p] instead of from", h);
}
}
if (!fromAddr)
......@@ -538,31 +541,31 @@ static bool_t fill_auth_info(LinphoneCore *lc, SalAuthInfo* sai) {
* Compare algorithm of server(sai) with algorithm of client(ai), if they are not correspondant,
* exit. The default algorithm is MD5 if it's NULL.
*/
if (sai->algorithm && ai->algorithm) {
if (strcasecmp(ai->algorithm, sai->algorithm))
return TRUE;
if (sai->algorithm && linphone_auth_info_get_algorithm(ai)) {
if (strcasecmp(linphone_auth_info_get_algorithm(ai), sai->algorithm))
return TRUE;
} else if (
(ai->algorithm && strcasecmp(ai->algorithm, "MD5")) ||
(linphone_auth_info_get_algorithm(ai) && strcasecmp(linphone_auth_info_get_algorithm(ai), "MD5")) ||
(sai->algorithm && strcasecmp(sai->algorithm, "MD5"))
)
return TRUE;
sai->userid = ms_strdup(ai->userid ? ai->userid : ai->username);
sai->password = ai->passwd?ms_strdup(ai->passwd) : NULL;
sai->ha1 = ai->ha1 ? ms_strdup(ai->ha1) : NULL;
sai->userid = ms_strdup(linphone_auth_info_get_userid(ai) ? linphone_auth_info_get_userid(ai) : linphone_auth_info_get_username(ai));
sai->password = linphone_auth_info_get_passwd(ai)?ms_strdup(linphone_auth_info_get_passwd(ai)) : NULL;
sai->ha1 = linphone_auth_info_get_ha1(ai) ? ms_strdup(linphone_auth_info_get_ha1(ai)) : NULL;
} else if (sai->mode == SalAuthModeTls) {
if (ai->tls_cert && ai->tls_key) {
sal_certificates_chain_parse(sai, ai->tls_cert, SAL_CERTIFICATE_RAW_FORMAT_PEM);
sal_signing_key_parse(sai, ai->tls_key, "");
} else if (ai->tls_cert_path && ai->tls_key_path) {
sal_certificates_chain_parse_file(sai, ai->tls_cert_path, SAL_CERTIFICATE_RAW_FORMAT_PEM);
sal_signing_key_parse_file(sai, ai->tls_key_path, "");
if (linphone_auth_info_get_tls_cert(ai) && linphone_auth_info_get_tls_key(ai)) {
sal_certificates_chain_parse(sai, linphone_auth_info_get_tls_cert(ai), SAL_CERTIFICATE_RAW_FORMAT_PEM);
sal_signing_key_parse(sai, linphone_auth_info_get_tls_key(ai), "");
} else if (linphone_auth_info_get_tls_cert_path(ai) && linphone_auth_info_get_tls_key_path(ai)) {
sal_certificates_chain_parse_file(sai, linphone_auth_info_get_tls_cert_path(ai), SAL_CERTIFICATE_RAW_FORMAT_PEM);
sal_signing_key_parse_file(sai, linphone_auth_info_get_tls_key_path(ai), "");
} else {
fill_auth_info_with_client_certificate(lc, sai);
}
}
if (sai->realm && !ai->realm){
if (sai->realm && !linphone_auth_info_get_realm(ai)){
/*if realm was not known, then set it so that ha1 may eventually be calculated and clear text password dropped*/
linphone_auth_info_set_realm(ai, sai->realm);
linphone_core_write_auth_info(lc, ai);
......
......@@ -19,6 +19,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "linphone/core.h"
#include "private.h"
#include "linphone/api/c-auth-info.h"
LinphoneCardDavContext* linphone_carddav_context_new(LinphoneFriendList *lfl) {
LinphoneCardDavContext *carddav_context = NULL;
......@@ -471,9 +475,9 @@ static void process_auth_requested_from_carddav_request(void *data, belle_sip_au
const char *domain = belle_generic_uri_get_host(uri);
if (cdc->auth_info) {
belle_sip_auth_event_set_username(event, cdc->auth_info->username);
belle_sip_auth_event_set_passwd(event, cdc->auth_info->passwd);
belle_sip_auth_event_set_ha1(event, cdc->auth_info->ha1);
belle_sip_auth_event_set_username(event, linphone_auth_info_get_username(cdc->auth_info));
belle_sip_auth_event_set_passwd(event, linphone_auth_info_get_passwd(cdc->auth_info));
belle_sip_auth_event_set_ha1(event, linphone_auth_info_get_ha1(cdc->auth_info));
} else {
LinphoneCore *lc = cdc->friend_list->lc;
const bctbx_list_t *auth_infos = linphone_core_get_auth_info_list(lc);
......@@ -481,11 +485,11 @@ static void process_auth_requested_from_carddav_request(void *data, belle_sip_au
ms_debug("Looking for auth info for domain %s and realm %s", domain, realm);
while (auth_infos) {
LinphoneAuthInfo *auth_info = (LinphoneAuthInfo *)auth_infos->data;
if (auth_info->domain && strcmp(domain, auth_info->domain) == 0) {
if (!auth_info->realm || strcmp(realm, auth_info->realm) == 0) {
belle_sip_auth_event_set_username(event, auth_info->username);
belle_sip_auth_event_set_passwd(event, auth_info->passwd);
belle_sip_auth_event_set_ha1(event, auth_info->ha1);
if (linphone_auth_info_get_domain(auth_info) && strcmp(domain, linphone_auth_info_get_domain(auth_info)) == 0) {
if (!linphone_auth_info_get_realm(auth_info) || strcmp(realm, linphone_auth_info_get_realm(auth_info)) == 0) {
belle_sip_auth_event_set_username(event, linphone_auth_info_get_username(auth_info));
belle_sip_auth_event_set_passwd(event, linphone_auth_info_get_passwd(auth_info));
belle_sip_auth_event_set_ha1(event, linphone_auth_info_get_ha1(auth_info));
cdc->auth_info = linphone_auth_info_clone(auth_info);
break;
}
......
......@@ -123,8 +123,6 @@ bool_t linphone_call_params_get_no_user_consent(const LinphoneCallParams *params
// FIXME: Remove this declaration, use LINPHONE_PUBLIC as ugly workaround, already defined in tester_utils.h
LINPHONE_PUBLIC void linphone_call_params_set_no_user_consent(LinphoneCallParams *params, bool_t value);
void linphone_auth_info_write_config(LinphoneConfig *config, LinphoneAuthInfo *obj, int pos);
LinphoneAuthInfo * linphone_auth_info_new_from_config_file(LpConfig *config, int pos);
void _linphone_core_uninit(LinphoneCore *lc);
void linphone_core_write_auth_info(LinphoneCore *lc, LinphoneAuthInfo *ai);
const LinphoneAuthInfo *_linphone_core_find_tls_auth_info(LinphoneCore *lc);
......
......@@ -146,22 +146,6 @@ struct _LinphoneProxyConfig
BELLE_SIP_DECLARE_VPTR_NO_EXPORT(LinphoneProxyConfig);
struct _LinphoneAuthInfo
{
belle_sip_object_t base;
char *username;
char *realm;
char *userid;
char *passwd;
char *ha1;
char *domain;
char *tls_cert;
char *tls_key;
char *tls_cert_path;
char *tls_key_path;
char *algorithm;
};
struct _LinphoneFriendPresence {
char *uri_or_tel;
LinphonePresenceModel *presence;
......
......@@ -24,6 +24,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "linphone/core.h"
#include "c-wrapper/c-wrapper.h"
#include "linphone/api/c-auth-info.h"
// TODO: From coreapi. Remove me later.
#include "private.h"
......
......@@ -23,7 +23,6 @@
set(ROOT_HEADER_FILES
account_creator_service.h
account_creator.h
auth_info.h
buffer.h
call_log.h
call_params.h
......@@ -75,6 +74,7 @@ set(ROOT_HEADER_FILES
set(C_API_HEADER_FILES
c-address.h
c-auth-info.h
c-api.h
c-call-cbs.h
c-call-stats.h
......
......@@ -22,6 +22,7 @@
#include "linphone/utils/general.h"
#include "linphone/api/c-auth-info.h"
#include "linphone/api/c-address.h"
#include "linphone/api/c-call-cbs.h"
#include "linphone/api/c-call-stats.h"
......
......@@ -20,8 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#ifndef LINPHONE_AUTH_INFO_H
#define LINPHONE_AUTH_INFO_H
#include <mediastreamer2/mscommon.h>
#include "linphone/types.h"
#include "linphone/api/c-types.h"
/**
* @addtogroup authentication
......@@ -31,34 +30,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
/**
* Safely cast a belle_sip_object_t into #LinphoneAuthInfo
*/
#define LINPHONE_AUTH_INFO(obj) BELLE_SIP_CAST(obj, LinphoneAuthInfo)
#ifdef __cplusplus
extern "C" {
#endif
/**
* Creates a #LinphoneAuthInfo object with supplied information.
* The object can be created empty, that is with all arguments set to NULL.
* Username, userid, password, realm and domain can be set later using specific methods.
* At the end, username and passwd (or ha1) are required.
* @param username The username that needs to be authenticated
* @param userid The userid used for authenticating (use NULL if you don't know what it is)
* @param passwd The password in clear text
* @param ha1 The ha1-encrypted password if password is not given in clear text.
* @param realm The authentication domain (which can be larger than the sip domain. Unfortunately many SIP servers don't use this parameter.
* @param domain The SIP domain for which this authentication information is valid, if it has to be restricted for a single SIP domain.
* @return A #LinphoneAuthInfo object. linphone_auth_info_destroy() must be used to destroy it when no longer needed. The #LinphoneCore makes a copy of #LinphoneAuthInfo
* passed through linphone_core_add_auth_info().
**/
LINPHONE_PUBLIC LinphoneAuthInfo *linphone_auth_info_new(
const char *username,
const char *userid,