authentication.c 18.7 KB
Newer Older
aymeric's avatar
aymeric committed
1 2 3 4
/***************************************************************************
 *            authentication.c
 *
 *  Fri Jul 16 12:08:34 2004
5
 *  Copyright  2004-2009  Simon MORLAT
aymeric's avatar
aymeric committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *  simon.morlat@linphone.org
 ****************************************************************************/

/*
 *  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 2 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 Library General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
24

25 26
#include "linphone/core.h"
#include "linphone/lpconfig.h"
27
#include "sal/sal.h"
aymeric's avatar
aymeric committed
28

29 30
#include "c-wrapper/c-wrapper.h"

31 32 33
// TODO: From coreapi. Remove me later.
#include "private.h"

34 35 36 37
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);
Ghislain MARY's avatar
Ghislain MARY committed
38
BELLE_SIP_DECLARE_VPTR_NO_EXPORT(LinphoneAuthInfo);
39 40 41 42 43 44 45 46
BELLE_SIP_INSTANCIATE_VPTR(
	LinphoneAuthInfo,
	belle_sip_object_t,
	_linphone_auth_info_uninit, // destroy
	_linphone_auth_info_copy, // clone
	NULL, // marshal
	FALSE
);
smorlat's avatar
smorlat committed
47

48
LinphoneAuthInfo *linphone_auth_info_new(const char *username, const char *userid, const char *passwd, const char *ha1, const char *realm, const char *domain){
49
	return linphone_auth_info_new_for_algorithm(username, userid, passwd, ha1, realm, domain, NULL);
aymeric's avatar
aymeric committed
50 51
}

52
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){
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
	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");

	if(algorithm && strcmp(algorithm, "MD5") && strcmp(algorithm, "SHA-256")){
		ms_error("Given algorithm %s is not correct.", algorithm);
		return NULL;
	}

	if(algorithm)
		obj->algorithm=ms_strdup(algorithm);
	return obj;
72 73
}

74 75 76 77 78 79 80 81 82 83 84
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);
85
	if (src->algorithm)     dst->algorithm = ms_strdup(src->algorithm);
86 87
}

88
LinphoneAuthInfo *linphone_auth_info_clone(const LinphoneAuthInfo *ai){
89 90 91 92 93 94 95 96 97
	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);
98 99
}

100
const char *linphone_auth_info_get_username(const LinphoneAuthInfo *i) {
101 102 103
	return i->username;
}

104
const char *linphone_auth_info_get_passwd(const LinphoneAuthInfo *i) {
105 106 107 108
	return linphone_auth_info_get_password(i);
}

const char *linphone_auth_info_get_password(const LinphoneAuthInfo *i) {
109 110 111
	return i->passwd;
}

112
const char *linphone_auth_info_get_userid(const LinphoneAuthInfo *i) {
113 114 115
	return i->userid;
}

116
const char *linphone_auth_info_get_realm(const LinphoneAuthInfo *i) {
117 118
	return i->realm;
}
119

120
const char *linphone_auth_info_get_domain(const LinphoneAuthInfo *i) {
121 122 123
	return i->domain;
}

124
const char *linphone_auth_info_get_ha1(const LinphoneAuthInfo *i) {
125 126 127
	return i->ha1;
}

128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
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) {
145 146 147 148
	linphone_auth_info_set_password(info, passwd);
}

void linphone_auth_info_set_password(LinphoneAuthInfo *info, const char *passwd) {
149
	if (info->passwd) {
aymeric's avatar
aymeric committed
150
		ms_free(info->passwd);
151
		info->passwd = NULL;
aymeric's avatar
aymeric committed
152
	}
153
	if (passwd && strlen(passwd) > 0) info->passwd = ms_strdup(passwd);
aymeric's avatar
aymeric committed
154 155
}

156 157
void linphone_auth_info_set_username(LinphoneAuthInfo *info, const char *username) {
	if (info->username) {
158
		ms_free(info->username);
159
		info->username = NULL;
160
	}
161
	if (username && strlen(username) > 0) info->username = ms_strdup(username);
162 163
}

164 165
void linphone_auth_info_set_userid(LinphoneAuthInfo *info, const char *userid) {
	if (info->userid) {
166
		ms_free(info->userid);
167
		info->userid = NULL;
168
	}
169
	if (userid && strlen(userid) > 0) info->userid = ms_strdup(userid);
170 171
}

172 173
void linphone_auth_info_set_realm(LinphoneAuthInfo *info, const char *realm) {
	if (info->realm) {
174
		ms_free(info->realm);
175
		info->realm = NULL;
176
	}
177
	if (realm && strlen(realm) > 0) info->realm = ms_strdup(realm);
178
}
179

180 181
void linphone_auth_info_set_domain(LinphoneAuthInfo *info, const char *domain) {
	if (info->domain) {
182
		ms_free(info->domain);
183
		info->domain = NULL;
184
	}
185
	if (domain && strlen(domain) > 0) info->domain = ms_strdup(domain);
186 187
}

188 189
void linphone_auth_info_set_ha1(LinphoneAuthInfo *info, const char *ha1) {
	if (info->ha1) {
190
		ms_free(info->ha1);
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
		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;
208
	}
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
	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);
226 227
}

228
static void _linphone_auth_info_uninit(LinphoneAuthInfo *obj) {
229 230 231 232 233 234 235 236 237 238
	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);
239
	if (obj->algorithm != NULL) ms_free(obj->algorithm);
240 241 242 243 244 245 246
}

/**
 * Destroys a LinphoneAuthInfo object.
**/
void linphone_auth_info_destroy(LinphoneAuthInfo *obj){
	belle_sip_object_unref(obj);
aymeric's avatar
aymeric committed
247 248
}

249
void linphone_auth_info_write_config(LpConfig *config, LinphoneAuthInfo *obj, int pos) {
aymeric's avatar
aymeric committed
250
	char key[50];
251
	bool_t store_ha1_passwd = !!lp_config_get_int(config, "sip", "store_ha1_passwd", 1);
252

253 254
	sprintf(key, "auth_info_%i", pos);
	lp_config_clean_section(config, key);
255

256
	if (obj == NULL || lp_config_get_int(config, "sip", "store_auth_info", 1) == 0) {
aymeric's avatar
aymeric committed
257
		return;
258
	}
259
	if (!obj->ha1 && obj->realm && obj->passwd && (obj->username || obj->userid) && store_ha1_passwd) {
260 261 262 263 264 265 266 267 268 269
		/* Default algorithm is MD5 if it's NULL */
		if((obj->algorithm==NULL)||(!(strcmp(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)&&(!(strcmp(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);
		}
270
	}
271 272
	if (obj->username != NULL) {
		lp_config_set_string(config, key, "username", obj->username);
aymeric's avatar
aymeric committed
273
	}
274 275
	if (obj->userid != NULL) {
		lp_config_set_string(config, key, "userid", obj->userid);
aymeric's avatar
aymeric committed
276
	}
277 278
	if (obj->ha1 != NULL) {
		lp_config_set_string(config, key, "ha1", obj->ha1);
279
	}
280 281
	if (obj->passwd != NULL) {
		if (store_ha1_passwd && obj->ha1) {
282 283
			/*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);
284
		} else {
285
			/*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*/
286
			lp_config_set_string(config, key, "passwd", obj->passwd);
287
		}
aymeric's avatar
aymeric committed
288
	}
289 290
	if (obj->realm != NULL) {
		lp_config_set_string(config, key, "realm", obj->realm);
aymeric's avatar
aymeric committed
291
	}
292 293 294 295 296 297 298 299
	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);
300
	}
301 302 303
	if (obj->algorithm != NULL) {
		lp_config_set_string(config, key, "algorithm", obj->algorithm);
	}
aymeric's avatar
aymeric committed
304 305 306 307 308
}

LinphoneAuthInfo *linphone_auth_info_new_from_config_file(LpConfig * config, int pos)
{
	char key[50];
309
	const char *username,*userid,*passwd,*ha1,*realm,*domain,*tls_cert_path,*tls_key_path;
310
	LinphoneAuthInfo *ret;
311

312 313
	sprintf(key, "auth_info_%i", pos);
	if (!lp_config_has_section(config, key)) {
aymeric's avatar
aymeric committed
314 315
		return NULL;
	}
316

317 318 319 320 321 322 323 324 325 326 327
	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);
328
	return ret;
aymeric's avatar
aymeric committed
329 330
}

smorlat's avatar
smorlat committed
331 332 333 334 335 336 337 338
static char * remove_quotes(char * input){
	char *tmp;
	if (*input=='"') input++;
	tmp=strchr(input,'"');
	if (tmp) *tmp='\0';
	return input;
}

339
static bool_t realm_match(const char *realm1, const char *realm2){
smorlat's avatar
smorlat committed
340 341 342 343 344 345 346 347
	if (realm1==NULL && realm2==NULL) return TRUE;
	if (realm1!=NULL && realm2!=NULL){
		if (strcmp(realm1,realm2)==0) return TRUE;
		else{
			char tmp1[128];
			char tmp2[128];
			char *p1,*p2;
			strncpy(tmp1,realm1,sizeof(tmp1)-1);
348
			strncpy(tmp2,realm2,sizeof(tmp2)-1);
smorlat's avatar
smorlat committed
349 350 351 352 353 354 355 356
			p1=remove_quotes(tmp1);
			p2=remove_quotes(tmp2);
			return strcmp(p1,p2)==0;
		}
	}
	return FALSE;
}

357
static const LinphoneAuthInfo *find_auth_info(LinphoneCore *lc, const char *username, const char *realm, const char *domain, bool_t ignore_realm){
358
	bctbx_list_t *elem;
359
	const LinphoneAuthInfo *ret=NULL;
360

361 362 363
	for (elem=lc->auth_info;elem!=NULL;elem=elem->next) {
		LinphoneAuthInfo *pinfo = (LinphoneAuthInfo*)elem->data;
		if (username && pinfo->username && strcmp(username,pinfo->username)==0) {
364
			if (realm && domain){
365
				if (pinfo->realm && realm_match(realm,pinfo->realm)
366
					&& pinfo->domain && strcmp(domain,pinfo->domain)==0) {
367
					return pinfo;
smorlat's avatar
smorlat committed
368
				}
369 370 371
			} else if (realm) {
				if (pinfo->realm && realm_match(realm,pinfo->realm)) {
					if (ret!=NULL) {
372 373 374
						ms_warning("Non unique realm found for %s",username);
						return NULL;
					}
smorlat's avatar
smorlat committed
375
					ret=pinfo;
376
				}
377
			} else if (domain && pinfo->domain && strcmp(domain,pinfo->domain)==0 && (pinfo->ha1==NULL || ignore_realm)) {
378
				return pinfo;
379
			} else if (!domain && (pinfo->ha1==NULL || ignore_realm)) {
380 381
				return pinfo;
			}
smorlat's avatar
smorlat committed
382
		}
383
	}
smorlat's avatar
smorlat committed
384
	return ret;
aymeric's avatar
aymeric committed
385 386
}

387 388 389 390 391 392 393 394 395 396 397 398
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) {
			return pinfo;
		} else if (pinfo->tls_cert_path && pinfo->tls_key_path) {
			return pinfo;
		}
	}
	return NULL;
}
399 400

const LinphoneAuthInfo *_linphone_core_find_auth_info(LinphoneCore *lc, const char *realm, const char *username, const char *domain, bool_t ignore_realm){
401
	const LinphoneAuthInfo *ai=NULL;
402
	if (realm){
403
		ai=find_auth_info(lc,username,realm,NULL, FALSE);
404
		if (ai==NULL && domain){
405
			ai=find_auth_info(lc,username,realm,domain, FALSE);
406
		}
407
	}
408
	if (ai == NULL && domain != NULL) {
409
		ai=find_auth_info(lc,username,NULL,domain, ignore_realm);
410
	}
411
	if (ai==NULL){
412
		ai=find_auth_info(lc,username,NULL,NULL, ignore_realm);
413
	}
414
	if (ai) ms_message("linphone_core_find_auth_info(): returning auth info username=%s, realm=%s", ai->username ? ai->username : "", ai->realm ? ai->realm : "");
415 416
	return ai;
}
417

418 419 420
const LinphoneAuthInfo *linphone_core_find_auth_info(LinphoneCore *lc, const char *realm, const char *username, const char *domain){
	return _linphone_core_find_auth_info(lc, realm, username, domain, TRUE);
}
421

422 423 424
/*the auth info is expected to be in the core's list*/
void linphone_core_write_auth_info(LinphoneCore *lc, LinphoneAuthInfo *ai){
	int i;
425
	bctbx_list_t *elem = lc->auth_info;
426

427
	if (!lc->sip_conf.save_auth_info) return;
428

429 430 431 432 433 434 435
	for (i=0; elem != NULL; elem = elem->next, i++){
		if (ai == elem->data){
			linphone_auth_info_write_config(lc->config, ai, i);
		}
	}
}

436
static void write_auth_infos(LinphoneCore *lc){
437
	bctbx_list_t *elem;
438 439 440
	int i;

	if (!linphone_core_ready(lc)) return;
441
	if (!lc->sip_conf.save_auth_info) return;
442
	for(elem=lc->auth_info,i=0;elem!=NULL;elem=bctbx_list_next(elem),i++){
443 444 445 446 447 448
		LinphoneAuthInfo *ai=(LinphoneAuthInfo*)(elem->data);
		linphone_auth_info_write_config(lc->config,ai,i);
	}
	linphone_auth_info_write_config(lc->config,NULL,i); /* mark the end */
}

449 450
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);
451 452
}

453
void linphone_core_add_auth_info(LinphoneCore *lc, const LinphoneAuthInfo *info){
454
	LinphoneAuthInfo *ai;
455 456
	bctbx_list_t *elem;
	bctbx_list_t *l;
457 458
	int restarted_op_count=0;
	bool_t updating=FALSE;
459

460 461 462 463
	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");
		return;
464
	}
aymeric's avatar
aymeric committed
465
	/* find if we are attempting to modify an existing auth info */
466
	ai=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,info->realm,info->username,info->domain);
Sylvain Berfini's avatar
Sylvain Berfini committed
467
	if (ai!=NULL && ai->domain && info->domain && strcmp(ai->domain, info->domain)==0){
468
		lc->auth_info=bctbx_list_remove(lc->auth_info,ai);
469
		linphone_auth_info_unref(ai);
470
		updating=TRUE;
aymeric's avatar
aymeric committed
471
	}
472
	lc->auth_info=bctbx_list_append(lc->auth_info,linphone_auth_info_clone(info));
473

Simon Morlat's avatar
Simon Morlat committed
474
	/* retry pending authentication operations */
475
	for(l=elem=lc->sal->get_pending_auths();elem!=NULL;elem=elem->next){
476
		LinphonePrivate::SalOp *op= static_cast<LinphonePrivate::SalOp*>(elem->data);
Simon Morlat's avatar
Simon Morlat committed
477
		LinphoneAuthInfo *ai;
478
		const SalAuthInfo *req_sai=op->get_auth_requested();
479
		ai=(LinphoneAuthInfo*)_linphone_core_find_auth_info(lc,req_sai->realm,req_sai->username,req_sai->domain, FALSE);
Simon Morlat's avatar
Simon Morlat committed
480 481
		if (ai){
			SalAuthInfo sai;
482
			bctbx_list_t* proxy;
Simon Morlat's avatar
Simon Morlat committed
483 484 485 486
			sai.username=ai->username;
			sai.userid=ai->userid;
			sai.realm=ai->realm;
			sai.password=ai->passwd;
487
			sai.ha1=ai->ha1;
488
			sai.algorithm=ai->algorithm;
489 490 491 492 493 494 495
			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, "");
			}
496
			/*proxy case*/
497
			for (proxy=(bctbx_list_t*)linphone_core_get_proxy_config_list(lc);proxy!=NULL;proxy=proxy->next) {
498
				if (proxy->data == op->get_user_pointer()) {
499 500 501 502
					linphone_proxy_config_set_state((LinphoneProxyConfig*)(proxy->data),LinphoneRegistrationProgress,"Authentication...");
					break;
				}
			}
503
			op->authenticate(&sai);
504
			restarted_op_count++;
Simon Morlat's avatar
Simon Morlat committed
505 506
		}
	}
507 508 509 510 511 512 513 514 515 516 517
	if (l){
		ms_message("linphone_core_add_auth_info(): restarted [%i] operation(s) after %s auth info for\n"
			"\tusername: [%s]\n"
			"\trealm [%s]\n"
			"\tdomain [%s]\n",
			restarted_op_count,
			updating ? "updating" : "adding",
			info->username ? info->username : "",
			info->realm ? info->realm : "",
			info->domain ? info->domain : "");
	}
518
	bctbx_list_free(l);
519
	write_auth_infos(lc);
aymeric's avatar
aymeric committed
520 521 522 523 524
}

void linphone_core_abort_authentication(LinphoneCore *lc,  LinphoneAuthInfo *info){
}

525 526
void linphone_core_remove_auth_info(LinphoneCore *lc, const LinphoneAuthInfo *info){
	LinphoneAuthInfo *r;
527
	r=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,info->realm,info->username,info->domain);
528
	if (r){
529
		lc->auth_info=bctbx_list_remove(lc->auth_info,r);
530
		linphone_auth_info_unref(r);
531
		write_auth_infos(lc);
aymeric's avatar
aymeric committed
532 533 534
	}
}

535
const bctbx_list_t *linphone_core_get_auth_info_list(const LinphoneCore *lc){
smorlat's avatar
smorlat committed
536 537 538
	return lc->auth_info;
}

aymeric's avatar
aymeric committed
539
void linphone_core_clear_all_auth_info(LinphoneCore *lc){
540
	bctbx_list_t *elem;
aymeric's avatar
aymeric committed
541
	int i;
542
	for(i=0,elem=lc->auth_info;elem!=NULL;elem=bctbx_list_next(elem),i++){
aymeric's avatar
aymeric committed
543
		LinphoneAuthInfo *info=(LinphoneAuthInfo*)elem->data;
544
		linphone_auth_info_unref(info);
aymeric's avatar
aymeric committed
545 546
		linphone_auth_info_write_config(lc->config,NULL,i);
	}
547
	bctbx_list_free(lc->auth_info);
aymeric's avatar
aymeric committed
548 549
	lc->auth_info=NULL;
}