X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=src%2Ftlsproxy.c;h=1ccee20c22ab16b541f39e2adee26c65f5d6a30a;hb=f651ef2c2de363f834af1bfad7b240a9c73a602c;hp=b391b738e641d1314db5c8289fefa62e694379a9;hpb=1d65b2374b94b6191d7c3ca53632c9ea416b2b7b;p=tlsproxy%2Ftlsproxy.git diff --git a/src/tlsproxy.c b/src/tlsproxy.c index b391b73..1ccee20 100644 --- a/src/tlsproxy.c +++ b/src/tlsproxy.c @@ -24,6 +24,7 @@ #include "connection.h" #include +#include #include #include #include @@ -31,6 +32,7 @@ #include #include #include +#include #if GNUTLS_VERSION_NUMBER <= 0x020b00 /* Necessary for GnuTLS when used with threads. */ @@ -237,7 +239,7 @@ int main(int argc, char **argv) { free(global_proxy_host); free(global_proxy_port); - free(http_digest_authorization); + free(global_http_digest_authorization); return EXIT_FAILURE; } @@ -265,20 +267,20 @@ static void parse_arguments(int argc, char **argv) { while ((option = getopt(argc, argv, "a:d:p:t:uh?")) != -1) { switch (option) { case 'a': { - http_digest_authorization = slurp_text_file(optarg); - if (http_digest_authorization == NULL) { + global_http_digest_authorization = slurp_text_file(optarg); + if (global_http_digest_authorization == NULL) { fprintf(stderr, "failed to open authorization file '%s': ", optarg); perror(""); exit(EXIT_FAILURE); - } else if (strlen(http_digest_authorization) == 0) { + } else if (strlen(global_http_digest_authorization) == 0) { fprintf(stderr, "empty authorization file '%s'\n", optarg); exit(EXIT_FAILURE); } /* Just in case the file has a trailing newline. */ - strtok(http_digest_authorization, "\r\n"); + strtok(global_http_digest_authorization, "\r\n"); break; } @@ -375,7 +377,7 @@ static void initialize_gnutls(void) { gnutls_datum_t dh_parameters_datum; /* Recent versions of GnuTLS automatically initialize the cryptography layer - * in gnutls_global_init(). */ + * in gnutls_global_init(), including a thread-safe setup. */ #if GNUTLS_VERSION_NUMBER <= 0x020b00 gcry_error_t error; @@ -395,6 +397,12 @@ static void initialize_gnutls(void) { } #endif + if (gnutls_check_version(GNUTLS_VERSION) == NULL) { + fprintf(stderr, "gnutls_check_version(): version mismatch, " + "expected at least '" GNUTLS_VERSION "'\n"); + exit(EXIT_FAILURE); + } + /* Initialize GnuTLS. */ result = gnutls_global_init(); GNUTLS_ERROR_EXIT(result, "gnutls_global_init()"); @@ -416,7 +424,8 @@ static void initialize_gnutls(void) { exit(EXIT_FAILURE); } dh_parameters_datum.data = (unsigned char *)dh_parameters; - dh_parameters_datum.size = strlen(dh_parameters); + assert(strlen(dh_parameters) <= UINT_MAX); + dh_parameters_datum.size = (unsigned int)(strlen(dh_parameters)); result = gnutls_dh_params_init(&global_tls_dh_params); GNUTLS_ERROR_EXIT(result, "gnutls_dh_params_init()");