Update OpenSSL handshake error codepath

This commit is contained in:
Sergey Lyubka 2021-08-29 16:53:29 +01:00
parent 38beb4cbc0
commit e3589577ed
3 changed files with 22 additions and 20 deletions

View File

@ -14,7 +14,7 @@ CFLAGS += -L$(OPENSSL)/lib -lssl -lcrypto
endif endif
all: $(PROG) all: $(PROG)
$(DEBUGGER) ./$(PROG) $(ARGS) $(RUN) ./$(PROG) $(ARGS)
$(PROG): main.c $(PROG): main.c
$(CC) ../../mongoose.c -I../.. -W -Wall $(CFLAGS) -o $(PROG) main.c $(CC) ../../mongoose.c -I../.. -W -Wall $(CFLAGS) -o $(PROG) main.c
@ -22,7 +22,7 @@ $(PROG): main.c
linux: all linux: all
linux: CFLAGS += -O2 -g -fsanitize=address,undefined,shift,null,return,bounds,alignment,object-size,bool,enum -static-libasan linux: CFLAGS += -O2 -g -fsanitize=address,undefined,shift,null,return,bounds,alignment,object-size,bool,enum -static-libasan
linux: CC = $(LIN) cc linux: CC = $(LIN) cc
linux: DEBUGGER = $(LIN) linux: RUN = $(LIN)
clean: clean:
rm -rf $(PROG) *.o *.dSYM *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb rm -rf $(PROG) *.o *.dSYM *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb

View File

@ -3725,13 +3725,15 @@ static int rng_get(void *p_rng, unsigned char *buf, size_t len) {
void mg_tls_init(struct mg_connection *c, struct mg_tls_opts *opts) { void mg_tls_init(struct mg_connection *c, struct mg_tls_opts *opts) {
struct mg_tls *tls = (struct mg_tls *) calloc(1, sizeof(*tls)); struct mg_tls *tls = (struct mg_tls *) calloc(1, sizeof(*tls));
int rc = 0; int rc = 0;
const char *ca = const char *ca = opts->ca == NULL ? "-"
opts->ca == NULL ? "-" : opts->ca[0] == '-' ? "(emb)" : opts->ca; : opts->ca[0] == '-' ? "(emb)"
const char *cert = : opts->ca;
opts->cert == NULL ? "-" : opts->cert[0] == '-' ? "(emb)" : opts->cert; const char *cert = opts->cert == NULL ? "-"
const char *certkey = opts->certkey == NULL : opts->cert[0] == '-' ? "(emb)"
? "-" : opts->cert;
: opts->certkey[0] == '-' ? "(emb)" : opts->certkey; const char *certkey = opts->certkey == NULL ? "-"
: opts->certkey[0] == '-' ? "(emb)"
: opts->certkey;
if (tls == NULL) { if (tls == NULL) {
mg_error(c, "TLS OOM"); mg_error(c, "TLS OOM");
goto fail; goto fail;
@ -3979,9 +3981,8 @@ void mg_tls_handshake(struct mg_connection *c) {
LOG(LL_DEBUG, ("%lu success", c->id)); LOG(LL_DEBUG, ("%lu success", c->id));
c->is_tls_hs = 0; c->is_tls_hs = 0;
} else { } else {
int code; int code = mg_tls_err(tls, rc);
ERR_print_errors_fp(stderr); ERR_print_errors_fp(stderr);
code = mg_tls_err(tls, rc);
if (code != 0) mg_error(c, "tls hs: rc %d, err %d", rc, code); if (code != 0) mg_error(c, "tls hs: rc %d, err %d", rc, code);
} }
} }

View File

@ -77,13 +77,15 @@ static int rng_get(void *p_rng, unsigned char *buf, size_t len) {
void mg_tls_init(struct mg_connection *c, struct mg_tls_opts *opts) { void mg_tls_init(struct mg_connection *c, struct mg_tls_opts *opts) {
struct mg_tls *tls = (struct mg_tls *) calloc(1, sizeof(*tls)); struct mg_tls *tls = (struct mg_tls *) calloc(1, sizeof(*tls));
int rc = 0; int rc = 0;
const char *ca = const char *ca = opts->ca == NULL ? "-"
opts->ca == NULL ? "-" : opts->ca[0] == '-' ? "(emb)" : opts->ca; : opts->ca[0] == '-' ? "(emb)"
const char *cert = : opts->ca;
opts->cert == NULL ? "-" : opts->cert[0] == '-' ? "(emb)" : opts->cert; const char *cert = opts->cert == NULL ? "-"
const char *certkey = opts->certkey == NULL : opts->cert[0] == '-' ? "(emb)"
? "-" : opts->cert;
: opts->certkey[0] == '-' ? "(emb)" : opts->certkey; const char *certkey = opts->certkey == NULL ? "-"
: opts->certkey[0] == '-' ? "(emb)"
: opts->certkey;
if (tls == NULL) { if (tls == NULL) {
mg_error(c, "TLS OOM"); mg_error(c, "TLS OOM");
goto fail; goto fail;
@ -331,9 +333,8 @@ void mg_tls_handshake(struct mg_connection *c) {
LOG(LL_DEBUG, ("%lu success", c->id)); LOG(LL_DEBUG, ("%lu success", c->id));
c->is_tls_hs = 0; c->is_tls_hs = 0;
} else { } else {
int code; int code = mg_tls_err(tls, rc);
ERR_print_errors_fp(stderr); ERR_print_errors_fp(stderr);
code = mg_tls_err(tls, rc);
if (code != 0) mg_error(c, "tls hs: rc %d, err %d", rc, code); if (code != 0) mg_error(c, "tls hs: rc %d, err %d", rc, code);
} }
} }