X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=mutt_ssl_gnutls.c;h=a7181bdf1cdfe7a5b901c88495ab4f0aab42cb23;hp=69833283d8f00cfd0cf1fa9a5f90f4c2cda81a1f;hb=73677f50e434a5c17a0d2c444dc2559c6540170b;hpb=df70e07e24add1869bcc9b7af2277d9d0c09a281 diff --git a/mutt_ssl_gnutls.c b/mutt_ssl_gnutls.c index 6983328..a7181bd 100644 --- a/mutt_ssl_gnutls.c +++ b/mutt_ssl_gnutls.c @@ -1,19 +1,11 @@ -/* Copyright (C) 2001 Marco d'Itri +/* + * Copyright notice from original mutt: + * Copyright (C) 2001 Marco d'Itri * Copyright (C) 2001-2004 Andrew McDonald * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * This file is part of mutt-ng, see http://www.muttng.org/. + * It's licensed under the GNU General Public License, + * please see the file GPL in the top level source directory. */ #if HAVE_CONFIG_H @@ -31,7 +23,11 @@ #include "mutt_curses.h" #include "mutt_menu.h" #include "mutt_ssl.h" -#include "mutt_regex.h" + +#include "lib/mem.h" +#include "lib/str.h" +#include "lib/intl.h" +#include "lib/rx.h" typedef struct _tlssockdata { gnutls_session state; @@ -60,7 +56,7 @@ static int tls_init (void) err = gnutls_global_init (); if (err < 0) { - mutt_error ("gnutls_global_init: %s", gnutls_strerror (err)); + mutt_error (_("gnutls_global_init: %s"), gnutls_strerror (err)); mutt_sleep (2); return -1; } @@ -88,14 +84,14 @@ static int tls_socket_read (CONNECTION * conn, char *buf, size_t len) int ret; if (!data) { - mutt_error ("Error: no TLS socket open"); + mutt_error (_("Error: no TLS socket open")); mutt_sleep (2); return -1; } ret = gnutls_record_recv (data->state, buf, len); if (gnutls_error_is_fatal (ret) == 1) { - mutt_error ("tls_socket_read (%s)", gnutls_strerror (ret)); + mutt_error (_("tls_socket_read (%s)"), gnutls_strerror (ret)); mutt_sleep (4); return -1; } @@ -108,14 +104,14 @@ static int tls_socket_write (CONNECTION * conn, const char *buf, size_t len) int ret; if (!data) { - mutt_error ("Error: no TLS socket open"); + mutt_error (_("Error: no TLS socket open")); mutt_sleep (2); return -1; } ret = gnutls_record_send (data->state, buf, len); if (gnutls_error_is_fatal (ret) == 1) { - mutt_error ("tls_socket_write (%s)", gnutls_strerror (ret)); + mutt_error (_("tls_socket_write (%s)"), gnutls_strerror (ret)); mutt_sleep (4); return -1; } @@ -159,12 +155,12 @@ static int tls_negotiate (CONNECTION * conn) tlssockdata *data; int err; - data = (tlssockdata *) safe_calloc (1, sizeof (tlssockdata)); + data = (tlssockdata *) mem_calloc (1, sizeof (tlssockdata)); conn->sockdata = data; err = gnutls_certificate_allocate_credentials (&data->xcred); if (err < 0) { - FREE (&conn->sockdata); - mutt_error ("gnutls_certificate_allocate_credentials: %s", + mem_free (&conn->sockdata); + mutt_error (_("gnutls_certificate_allocate_credentials: %s"), gnutls_strerror (err)); mutt_sleep (2); return -1; @@ -229,11 +225,11 @@ static int tls_negotiate (CONNECTION * conn) } if (err < 0) { if (err == GNUTLS_E_FATAL_ALERT_RECEIVED) { - mutt_error ("gnutls_handshake: %s(%s)", gnutls_strerror (err), + mutt_error (_("gnutls_handshake: %s(%s)"), gnutls_strerror (err), gnutls_alert_get_name (gnutls_alert_get (data->state))); } else { - mutt_error ("gnutls_handshake: %s", gnutls_strerror (err)); + mutt_error (_("gnutls_handshake: %s"), gnutls_strerror (err)); } mutt_sleep (2); goto fail; @@ -260,7 +256,7 @@ static int tls_negotiate (CONNECTION * conn) fail: gnutls_certificate_free_credentials (data->xcred); gnutls_deinit (data->state); - FREE (&conn->sockdata); + mem_free (&conn->sockdata); return -1; } @@ -273,7 +269,7 @@ static int tls_socket_close (CONNECTION * conn) gnutls_certificate_free_credentials (data->xcred); gnutls_deinit (data->state); - safe_free ((void **) &conn->sockdata); + mem_free(&conn->sockdata); } return raw_socket_close (conn); @@ -308,7 +304,7 @@ static int tls_compare_certificates (const gnutls_datum * peercert) return 0; b64_data.size = filestat.st_size + 1; - b64_data_data = (unsigned char *) safe_calloc (1, b64_data.size); + b64_data_data = (unsigned char *) mem_calloc (1, b64_data.size); b64_data_data[b64_data.size - 1] = '\0'; b64_data.data = b64_data_data; @@ -323,12 +319,12 @@ static int tls_compare_certificates (const gnutls_datum * peercert) do { ret = gnutls_pem_base64_decode_alloc (NULL, &b64_data, &cert); if (ret != 0) { - FREE (&b64_data_data); + mem_free (&b64_data_data); return 0; } - ptr = (unsigned char *) strstr (b64_data.data, CERT_SEP) + 1; - ptr = (unsigned char *) strstr (ptr, CERT_SEP); + ptr = (unsigned char *) strstr ((char*) b64_data.data, CERT_SEP) + 1; + ptr = (unsigned char *) strstr ((char*) ptr, CERT_SEP); b64_data.size = b64_data.size - (ptr - b64_data.data); b64_data.data = ptr; @@ -337,7 +333,7 @@ static int tls_compare_certificates (const gnutls_datum * peercert) if (memcmp (cert.data, peercert->data, cert.size) == 0) { /* match found */ gnutls_free (cert.data); - FREE (&b64_data_data); + mem_free (&b64_data_data); return 1; } } @@ -346,7 +342,7 @@ static int tls_compare_certificates (const gnutls_datum * peercert) } while (ptr != NULL); /* no match found */ - FREE (&b64_data_data); + mem_free (&b64_data_data); return 0; } @@ -416,10 +412,10 @@ static int tls_check_stored_hostname (const gnutls_datum * cert, if (regexec (&preg, linestr, 3, pmatch, 0) == 0) { linestr[pmatch[1].rm_eo] = '\0'; linestr[pmatch[2].rm_eo] = '\0'; - if (strcmp (linestr + pmatch[1].rm_so, hostname) == 0 && - strcmp (linestr + pmatch[2].rm_so, buf) == 0) { + if (str_cmp (linestr + pmatch[1].rm_so, hostname) == 0 && + str_cmp (linestr + pmatch[2].rm_so, buf) == 0) { regfree (&preg); - safe_free ((void **) &linestr); + mem_free(&linestr); fclose (fp); return 1; } @@ -453,10 +449,9 @@ static int tls_check_certificate (CONNECTION * conn) MUTTMENU *menu; int done, row, i, ret; FILE *fp; - gnutls_x509_dn dn; time_t t; const gnutls_datum *cert_list; - int cert_list_size = 0; + unsigned int cert_list_size = 0; gnutls_certificate_status certstat; char datestr[30]; gnutls_x509_crt cert; @@ -490,7 +485,7 @@ static int tls_check_certificate (CONNECTION * conn) /* We only support X.509 certificates (not OpenPGP) at the moment */ if (gnutls_certificate_type_get (state) != GNUTLS_CRT_X509) { - mutt_error (_("Error certificate is not X.509")); + mutt_error (_("Certificate is not X.509")); mutt_sleep (2); return 0; } @@ -588,9 +583,9 @@ static int tls_check_certificate (CONNECTION * conn) /* interactive check from user */ menu = mutt_new_menu (); menu->max = 25; - menu->dialog = (char **) safe_calloc (1, menu->max * sizeof (char *)); + menu->dialog = (char **) mem_calloc (1, menu->max * sizeof (char *)); for (i = 0; i < menu->max; i++) - menu->dialog[i] = (char *) safe_calloc (1, SHORT_STRING * sizeof (char)); + menu->dialog[i] = (char *) mem_calloc (1, SHORT_STRING * sizeof (char)); row = 0; strfcpy (menu->dialog[row], _("This certificate belongs to:"), @@ -752,6 +747,7 @@ static int tls_check_certificate (CONNECTION * conn) menu->help = helpstr; done = 0; + set_option (OPTUNBUFFEREDINPUT); while (!done) { switch (mutt_menuLoop (menu)) { case -1: /* abort */ @@ -794,6 +790,7 @@ static int tls_check_certificate (CONNECTION * conn) break; } } + unset_option (OPTUNBUFFEREDINPUT); mutt_menuDestroy (&menu); gnutls_x509_crt_deinit (cert); return (done == 2);