diff options
author | Treeki <treeki@gmail.com> | 2014-01-20 09:26:38 +0100 |
---|---|---|
committer | Treeki <treeki@gmail.com> | 2014-01-20 09:26:38 +0100 |
commit | 3caa77e7dae8ece7564085968c06e5cb4e1a8181 (patch) | |
tree | a6bcbcee84435caedcd47e4fe154fbd4acc30929 | |
parent | 8ebc3d1d73c4c8c43457543859497590aa49e1d0 (diff) | |
download | bounce4-3caa77e7dae8ece7564085968c06e5cb4e1a8181.tar.gz bounce4-3caa77e7dae8ece7564085968c06e5cb4e1a8181.zip |
move global TLS init into a separate function
Diffstat (limited to '')
-rw-r--r-- | core.cpp | 34 |
1 files changed, 21 insertions, 13 deletions
@@ -700,20 +700,12 @@ void Server::close() { } -int main(int argc, char **argv) { - clientCount = 0; - for (int i = 0; i < CLIENT_LIMIT; i++) - clients[i] = NULL; - serverCount = 0; - for (int i = 0; i < SERVER_LIMIT; i++) - servers[i] = NULL; - - +bool initTLS() { int ret; ret = gnutls_global_init(); if (ret != GNUTLS_E_SUCCESS) { printf("gnutls_global_init failure: %s\n", gnutls_strerror(ret)); - return 1; + return false; } unsigned int bits = gnutls_sec_param_to_pk_bits(GNUTLS_PK_DH, GNUTLS_SEC_PARAM_LEGACY); @@ -721,25 +713,41 @@ int main(int argc, char **argv) { ret = gnutls_dh_params_init(&dh_params); if (ret != GNUTLS_E_SUCCESS) { printf("dh_params_init failure: %s\n", gnutls_strerror(ret)); - return 1; + 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 1; + return false; } gnutls_certificate_allocate_credentials(&clientCreds); ret = gnutls_certificate_set_x509_key_file(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 1; + return false; } gnutls_certificate_set_dh_params(clientCreds, dh_params); gnutls_certificate_allocate_credentials(&serverCreds); + return true; +} + + +int main(int argc, char **argv) { + clientCount = 0; + for (int i = 0; i < CLIENT_LIMIT; i++) + clients[i] = NULL; + serverCount = 0; + for (int i = 0; i < SERVER_LIMIT; i++) + servers[i] = NULL; + + + if (!initTLS()) + return 0; + DNS::start(); |