summaryrefslogtreecommitdiff
path: root/core.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core.cpp')
-rw-r--r--core.cpp34
1 files changed, 21 insertions, 13 deletions
diff --git a/core.cpp b/core.cpp
index 71857d3..b67f0a2 100644
--- a/core.cpp
+++ b/core.cpp
@@ -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();