auth_event.c 4.16 KB
Newer Older
1 2 3 4 5 6
/*
	auth_info.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
7
    the Free Software Foundation, either version 2 of the License, or
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
    (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"


GET_SET_STRING(belle_sip_auth_event,username)

GET_SET_STRING(belle_sip_auth_event,userid)
GET_SET_STRING(belle_sip_auth_event,realm)
Simon Morlat's avatar
Simon Morlat committed
28
GET_SET_STRING(belle_sip_auth_event,domain)
29 30
GET_SET_STRING(belle_sip_auth_event,passwd)
GET_SET_STRING(belle_sip_auth_event,ha1)
jehan's avatar
jehan committed
31 32
GET_SET_STRING(belle_sip_auth_event,distinguished_name)

33
belle_sip_auth_event_t* belle_sip_auth_event_create(belle_sip_object_t *source, const char* realm, const belle_sip_uri_t *from_uri) {
jehan's avatar
jehan committed
34
	belle_sip_auth_event_t* result = belle_sip_new0(belle_sip_auth_event_t);
Simon Morlat's avatar
Simon Morlat committed
35
	result->source=source;
36
	belle_sip_auth_event_set_realm(result,realm);
37
	
38 39 40
	if (from_uri){
		belle_sip_auth_event_set_username(result,belle_sip_uri_get_user(from_uri));
		belle_sip_auth_event_set_domain(result,belle_sip_uri_get_host(from_uri));
41
	}
42 43
	return result;
}
Simon Morlat's avatar
Simon Morlat committed
44

45 46 47 48
void belle_sip_auth_event_destroy(belle_sip_auth_event_t* event) {
	DESTROY_STRING(event,username);
	DESTROY_STRING(event,userid);
	DESTROY_STRING(event,realm);
Simon Morlat's avatar
Simon Morlat committed
49
	DESTROY_STRING(event,domain);
50 51
	DESTROY_STRING(event,passwd);
	DESTROY_STRING(event,ha1);
jehan's avatar
jehan committed
52 53 54 55
	DESTROY_STRING(event,distinguished_name);
	if (event->cert) belle_sip_object_unref(event->cert);
	if (event->key) belle_sip_object_unref(event->key);

56 57
	belle_sip_free(event);
}
jehan's avatar
jehan committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72


belle_sip_certificates_chain_t* belle_sip_auth_event_get_client_certificates_chain(const belle_sip_auth_event_t* event) {
	return event->cert;
}

void belle_sip_auth_event_set_client_certificates_chain(belle_sip_auth_event_t* event, belle_sip_certificates_chain_t* value) {
	if (event->cert) belle_sip_object_unref(event->cert);
	event->cert=value;
	if (event->cert) belle_sip_object_ref(event->cert);
}

belle_sip_signing_key_t* belle_sip_auth_event_get_signing_key(const belle_sip_auth_event_t* event) {
	return event->key;
}
Simon Morlat's avatar
Simon Morlat committed
73

jehan's avatar
jehan committed
74
void belle_sip_auth_event_set_signing_key(belle_sip_auth_event_t* event, belle_sip_signing_key_t* value) {
75
	SET_OBJECT_PROPERTY(event,key,value);
jehan's avatar
jehan committed
76
}
Simon Morlat's avatar
Simon Morlat committed
77

jehan's avatar
jehan committed
78 79 80 81
belle_sip_auth_mode_t belle_sip_auth_event_get_mode(const belle_sip_auth_event_t* event) {
	return event->mode;
}

Simon Morlat's avatar
Simon Morlat committed
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97

static void verify_policy_uninit(belle_tls_verify_policy_t *obj){
	if (obj->root_ca) belle_sip_free(obj->root_ca);
}

BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_tls_verify_policy_t);
BELLE_SIP_INSTANCIATE_VPTR(belle_tls_verify_policy_t,belle_sip_object_t,verify_policy_uninit,NULL,NULL,FALSE);

belle_tls_verify_policy_t *belle_tls_verify_policy_new(){
	belle_tls_verify_policy_t *obj=belle_sip_object_new(belle_tls_verify_policy_t);
	
	/*default to "system" default root ca, wihtout warranty...*/
#ifdef __linux
	belle_tls_verify_policy_set_root_ca(obj,"/etc/ssl/certs");
#elif defined(__APPLE__)
	belle_tls_verify_policy_set_root_ca(obj,"/opt/local/share/curl/curl-ca-bundle.crt");
98 99
#elif __QNX__
	belle_tls_verify_policy_set_root_ca(obj,"/var/certs/web_trusted@personal@certmgr");
Simon Morlat's avatar
Simon Morlat committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
#endif
	return obj;
}

int belle_tls_verify_policy_set_root_ca(belle_tls_verify_policy_t *obj, const char *path){
	if (obj->root_ca){
		belle_sip_free(obj->root_ca);
		obj->root_ca=NULL;
	}
	if (path){
		obj->root_ca=belle_sip_strdup(path);
		belle_sip_message("Root ca path set to %s",obj->root_ca);
	} else {
		belle_sip_message("Root ca path disabled");
	}
	return 0;
}

void belle_tls_verify_policy_set_exceptions(belle_tls_verify_policy_t *obj, int flags){
	obj->exception_flags=flags;
}

Simon Morlat's avatar
Simon Morlat committed
122 123 124
unsigned int belle_tls_verify_policy_get_exceptions(const belle_tls_verify_policy_t *obj){
	return obj->exception_flags;
}
Simon Morlat's avatar
Simon Morlat committed
125