zygo

ncurses gopher client
Log | Files | Refs

commit bc4a6634b54d62d5a460f22a4e81564358f74794
parent ed4c95b06a32a8e05dd595952691554d8fff8603
Author: hhvn <dev@hhvn.uk>
Date:   Sun, 16 Jan 2022 19:09:14 +0000

tls.c zygo.c config.h: try again in cleartext

Diffstat:
Mconfig.h | 2++
Mtls.c | 10++++++++--
Mzygo.c | 23+++++++++++++++++++++--
3 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/config.h b/config.h @@ -6,6 +6,8 @@ static short cmd_pair[2] = {7, 0}; static short arg_pair[2] = {-1, 0}; static short err_pair[2] = {160, 0}; +static int stimeout = 5; + static Scheme scheme[] = { {'i', " ", -1 }, {'0', "Text", -1 }, diff --git a/tls.c b/tls.c @@ -10,8 +10,8 @@ static int tls; #define net_free() \ if (ai) freeaddrinfo(ai); \ - if (ctx) tls_free(ctx); \ - if (conf) tls_config_free(conf) + if (ctx) { tls_free(ctx); ctx = NULL; } \ + if (conf) { tls_config_free(conf); conf = NULL; } int net_connect(Elem *e) { @@ -23,6 +23,8 @@ net_connect(Elem *e) { if (tls) { if (conf) tls_config_free(conf); + if (ctx) + tls_free(ctx); if ((conf = tls_config_new()) == NULL) { error("tls_config_new(): %s", tls_config_error(conf)); @@ -61,6 +63,10 @@ net_connect(Elem *e) { error("could not tls-ify connection to %s:%s", e->server, e->port); goto fail; } + if (tls_handshake(ctx) == -1) { + error("could not perform tls handshake with %s:%s", e->server, e->port); + goto fail; + } } freeaddrinfo(ai); diff --git a/zygo.c b/zygo.c @@ -372,14 +372,33 @@ int go(Elem *e) { char line[BUFLEN]; Elem *elem; + int ret; if (e->type != '1' && e->type != '7' && e->type != '+') { /* TODO: call plumber */ return -1; } - if (net_connect(e) == -1) - return -1; + if ((ret = net_connect(e)) == -1) { + if (e->tls) { + printw("| "); + attron(A_BOLD); + printw("Try again in cleartext? "); + attroff(A_BOLD); + refresh(); + timeout(stimeout * 1000); + if (tolower(getch()) == 'y') { + elem = elem_dup(e); + elem->tls = 0; + ret = go(elem); + elem_free(elem); + } + } + + timeout(-1); + candraw = 1; + return ret; + } net_write(e->selector, strlen(e->selector)); net_write("\r\n", 2);