From c82c6f3671206a945d4a40227246ec5df4460232 Mon Sep 17 00:00:00 2001 From: Treeki Date: Mon, 20 Jan 2014 10:24:36 +0100 Subject: split every class up into a separate file --- main.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 main.cpp (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..d772d6c --- /dev/null +++ b/main.cpp @@ -0,0 +1,58 @@ +#include "core.h" +#include "dns.h" + +static gnutls_dh_params_t dh_params; +gnutls_certificate_credentials_t g_serverCreds, g_clientCreds; + + +bool initTLS() { + int ret; + ret = gnutls_global_init(); + if (ret != GNUTLS_E_SUCCESS) { + printf("gnutls_global_init failure: %s\n", gnutls_strerror(ret)); + return false; + } + + unsigned int bits = gnutls_sec_param_to_pk_bits(GNUTLS_PK_DH, GNUTLS_SEC_PARAM_LEGACY); + + ret = gnutls_dh_params_init(&dh_params); + if (ret != GNUTLS_E_SUCCESS) { + printf("dh_params_init failure: %s\n", gnutls_strerror(ret)); + return false; + } + + ret = gnutls_dh_params_generate2(dh_params, bits); + if (ret != GNUTLS_E_SUCCESS) { + printf("dh_params_generate2 failure: %s\n", gnutls_strerror(ret)); + return false; + } + + gnutls_certificate_allocate_credentials(&g_clientCreds); + ret = gnutls_certificate_set_x509_key_file(g_clientCreds, "ssl_test.crt", "ssl_test.key", GNUTLS_X509_FMT_PEM); + if (ret != GNUTLS_E_SUCCESS) { + printf("set_x509_key_file failure: %s\n", gnutls_strerror(ret)); + return false; + } + gnutls_certificate_set_dh_params(g_clientCreds, dh_params); + + gnutls_certificate_allocate_credentials(&g_serverCreds); + + return true; +} + +int main(int argc, char **argv) { + if (!initTLS()) + return EXIT_FAILURE; + + DNS::start(); + + Bouncer bounce; + + int errcode = bounce.execute(); + if (errcode < 0) { + printf("(Bouncer::execute failed with %d)\n", errcode); + return EXIT_FAILURE; + } else { + return EXIT_SUCCESS; + } +} \ No newline at end of file -- cgit v1.2.3