Beispiel #1
0
/**
 * @short Set new certificate elements
 * @memberof onion_https_t
 * 
 * @param ol Listen point
 * @param type Type of certificate to add
 * @param filename File where this data is.
 * @returns If the operation was sucesful
 */
int onion_https_set_certificate(onion_listen_point *ol, onion_ssl_certificate_type type, const char *filename, ...){
	va_list va;
	va_start(va, filename);
	int r=onion_https_set_certificate_argv(ol, type, filename, va);
	va_end(va);

	return r;
}
Beispiel #2
0
/// Set a certificate for use in the connection
int onion_set_certificate(onion *onion, onion_ssl_certificate_type type, const char *filename,...){
#ifdef HAVE_GNUTLS
	if (!onion->listen_points){
		onion_add_listen_point(onion,NULL,NULL,onion_https_new());
	}
	else{
		onion_listen_point *first_listen_point=onion->listen_points[0];
		if (first_listen_point->write!=onion_https_write){
			if (first_listen_point->write!=onion_http_write){
				ONION_ERROR("First listen point is not HTTP not HTTPS. Refusing to promote it to HTTPS. Use proper onion_https_new.");
				return -1;
			}
			ONION_DEBUG("Promoting from HTTP to HTTPS");
			char *port=first_listen_point->port ? strdup(first_listen_point->port) : NULL;
			char *hostname=first_listen_point->hostname ? strdup(first_listen_point->hostname) : NULL;
			onion_listen_point_free(first_listen_point);
			onion_listen_point *https=onion_https_new();
			if (NULL==https){
				ONION_ERROR("Could not promote from HTTP to HTTPS. Certificate not set.");
			}
			https->port=port;
			https->hostname=hostname;
			onion->listen_points[0]=https;
			first_listen_point=https;
		}
	}
	va_list va;
	va_start(va, filename);
	int r=onion_https_set_certificate_argv(onion->listen_points[0], type, filename,va);
	va_end(va);

	return r;
#else
	ONION_ERROR("GNUTLS is not enabled. Recompile onion with GNUTLS support");
	return -1;
#endif
}