X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fsrc%2Ftlscert-gnu.c;h=8ea7023541fd9f29a44177383166f3eb5e886cc0;hb=8f0d0a3138e138ffa6bcc94c8378f5eb22573f0e;hp=45135814ca912542af69e3bd39c67858f58ce290;hpb=f3ebb786e451da973560f1c9d8cdb151d25108b5;p=user%2Fhenk%2Fcode%2Fexim.git diff --git a/src/src/tlscert-gnu.c b/src/src/tlscert-gnu.c index 45135814c..8ea702354 100644 --- a/src/src/tlscert-gnu.c +++ b/src/src/tlscert-gnu.c @@ -20,13 +20,16 @@ tls.c when USE_GNUTLS has been set. /***************************************************** * Export/import a certificate, binary/printable -*****************************************************/ -int +****************************************************** +Return: boolean success +*/ + +BOOL tls_export_cert(uschar * buf, size_t buflen, void * cert) { size_t sz = buflen; rmark reset_point = store_mark(); -int fail; +BOOL fail; const uschar * cp; if ((fail = gnutls_x509_crt_export((gnutls_x509_crt_t)cert, @@ -34,7 +37,7 @@ if ((fail = gnutls_x509_crt_export((gnutls_x509_crt_t)cert, { log_write(0, LOG_MAIN, "TLS error in certificate export: %s", gnutls_strerror(fail)); - return 1; + return FALSE; } if ((cp = string_printing(buf)) != buf) { @@ -43,16 +46,17 @@ if ((cp = string_printing(buf)) != buf) fail = 1; } store_reset(reset_point); -return fail; +return !fail; } -int +/* On error, NULL out the destination */ +BOOL tls_import_cert(const uschar * buf, void ** cert) { rmark reset_point = store_mark(); gnutls_datum_t datum; gnutls_x509_crt_t crt = *(gnutls_x509_crt_t *)cert; -int fail = 0; +int rc; if (crt) gnutls_x509_crt_deinit(crt); @@ -63,17 +67,15 @@ gnutls_x509_crt_init(&crt); datum.data = string_unprinting(US buf); datum.size = Ustrlen(datum.data); -if ((fail = gnutls_x509_crt_import(crt, &datum, GNUTLS_X509_FMT_PEM))) +if ((rc = gnutls_x509_crt_import(crt, &datum, GNUTLS_X509_FMT_PEM))) { log_write(0, LOG_MAIN, "TLS error in certificate import: %s", - gnutls_strerror(fail)); - fail = 1; + gnutls_strerror(rc)); + crt = NULL; } -else - *cert = (void *)crt; - +*cert = (void *)crt; store_reset(reset_point); -return fail; +return rc != 0; } void @@ -286,13 +288,13 @@ uschar * tag = US""; uschar * ele; int match = -1; -while (mod) +if (mod) while (*mod) { if (*mod == '>' && *++mod) sep = *mod++; - else if (Ustrcmp(mod, "dns")==0) { match = GNUTLS_SAN_DNSNAME; mod += 3; } - else if (Ustrcmp(mod, "uri")==0) { match = GNUTLS_SAN_URI; mod += 3; } - else if (Ustrcmp(mod, "mail")==0) { match = GNUTLS_SAN_RFC822NAME; mod += 4; } - else continue; + else if (Ustrncmp(mod, "dns", 3)==0) { match = GNUTLS_SAN_DNSNAME; mod += 3; } + else if (Ustrncmp(mod, "uri", 3)==0) { match = GNUTLS_SAN_URI; mod += 3; } + else if (Ustrncmp(mod, "mail", 4)==0) { match = GNUTLS_SAN_RFC822NAME; mod += 4; } + else break; if (*mod++ != ',') break;