Beispiel #1
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
}
Beispiel #2
0
int main(int argc, char **argv){
	o=onion_new(O_THREADED);
	signal(SIGINT, free_onion);

	onion_set_root_handler(o, onion_handler_export_local_new("."));
	onion_add_listen_point(o, "localhost", "8080", onion_http_new());
	onion_add_listen_point(o, "localhost", "8081", onion_http_new());
	
	onion_add_listen_point(o, "localhost", "4443", onion_https_new(O_SSL_CERTIFICATE_KEY, "cert.pem", "cert.key"));
	
	
	
	/**
	onion_set_port(o, "localhost", "6121", onion_protocol_spdy());
	*/
	onion_listen(o);
	onion_free(o);
	return 0;
}
Beispiel #3
0
int main(int argc, char **argv){
	o=onion_new(O_THREADED);
	signal(SIGINT, free_onion);

	onion_set_root_handler(o, onion_handler_export_local_new("."));
	onion_add_listen_point(o, "localhost", "8080", onion_http_new());
	onion_add_listen_point(o, "localhost", "8081", onion_http_new());
#ifdef HAVE_GNUTLS
	onion_add_listen_point(o, "localhost", "4443", onion_https_new(O_SSL_CERTIFICATE_KEY, "cert.pem", "cert.key"));
#else
	ONION_WARNING("HTTPS support is not enabled. Recompile with gnutls");
#endif
	
	
	
	/**
	onion_set_port(o, "localhost", "6121", onion_protocol_spdy());
	*/
	onion_listen(o);
	onion_free(o);
	return 0;
}