#include <sys/types.h>
#include <unistd.h>
+#if GNUTLS_VERSION_NUMBER <= 0x020b00
/* Necessary for GnuTLS when used with threads. */
#include <gcrypt.h>
GCRY_THREAD_OPTION_PTHREAD_IMPL;
+#endif
/* Size of ringbuffer. */
/* Server should shut down. Set by SIGINT handler. */
-static volatile int done = 0;
+static volatile int done; /* = 0 */
/* Number of threads. */
static size_t thread_count;
static void parse_arguments(int argc, char **argv);
static void print_usage(const char *argv);
-static char *slurp_file(const char *path);
+static char *slurp_text_file(const char *path);
static void initialize_gnutls(void);
static void deinitialize_gnutls(void);
}
/* Fast rebinding for debug mode, could cause invalid packets. */
- if (global_log_level >= LOG_DEBUG_LEVEL) {
+ if (global_log_level >= LOG_DEBUG1_LEVEL) {
int socket_option = 1;
setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR,
&socket_option, sizeof(socket_option));
return EXIT_FAILURE;
}
- if (global_log_level >= LOG_DEBUG_LEVEL) {
+ if (global_log_level >= LOG_DEBUG1_LEVEL) {
printf("tlsproxy %s\n", VERSION);
printf("Listening for connections on port %d.\n", port);
/* Default values. */
thread_count = 10;
#ifdef DEBUG
- global_log_level = LOG_DEBUG_LEVEL;
+ global_log_level = LOG_DEBUG1_LEVEL;
#else
global_log_level = LOG_WARNING_LEVEL;
#endif
while ((option = getopt(argc, argv, "a:d:p:t:uh?")) != -1) {
switch (option) {
case 'a': {
- http_digest_authorization = slurp_file(optarg);
+ http_digest_authorization = slurp_text_file(optarg);
if (http_digest_authorization == NULL) {
fprintf(stderr, "failed to open authorization file '%s': ",
optarg);
fprintf(stderr, " WARNING: might be a security problem!\n");
}
+#if 0
+static void log_function_gnutls(int level, const char *string) {
+ (void)level;
+ fprintf(stderr, " => %s", string);
+}
+#endif
+
static void initialize_gnutls(void) {
int result;
+/* Recent versions of GnuTLS automatically initialize the cryptography layer
+ * in gnutls_global_init(). */
+#if GNUTLS_VERSION_NUMBER <= 0x020b00
gcry_error_t error;
/* Thread safe setup. Must be called before gnutls_global_init(). */
gcry_strerror(error));
exit(EXIT_FAILURE);
}
+#endif
/* Initialize GnuTLS. */
result = gnutls_global_init();
GNUTLS_ERROR_EXIT(result, "gnutls_global_init()");
+#if 0
+ gnutls_global_set_log_level(10);
+ gnutls_global_set_log_function(log_function_gnutls);
+#endif
+
/* Setup GnuTLS cipher suites. */
result = gnutls_priority_init(&global_tls_priority_cache, "NORMAL", NULL);
GNUTLS_ERROR_EXIT(result, "gnutls_priority_init()");
return NULL;
}
-static char *slurp_file(const char *path) {
+static char *slurp_text_file(const char *path) {
struct stat stat;
size_t size_read;
char *content = NULL;