Skip to content

Commit

Permalink
JUNK more tls debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
elliefm committed Nov 1, 2024
1 parent 59846de commit f3450f3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
13 changes: 0 additions & 13 deletions cunit/backend.testc
Original file line number Diff line number Diff line change
Expand Up @@ -733,19 +733,6 @@ static void test_starttls(void)
/*
* ALPN tests
*/
static void dump_alpn_map(const char *desc, const struct tls_alpn_t *map)
{
const struct tls_alpn_t *p;
const char *sep = "";

fprintf(stderr, "%s: ", desc);
for (p = map; p && p->id[0]; p++) {
fprintf(stderr, "%sid=\"%s\"", sep, p->id);
sep = ", ";
}
fputs("\n", stderr);
}

static void alpn_common(const struct tls_alpn_t *client_alpn_map,
unsigned n_client_protocols,
const struct tls_alpn_t *server_alpn_map,
Expand Down
20 changes: 19 additions & 1 deletion imap/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,19 @@ static void dump_errors(const char *context)
}
}

EXPORTED void dump_alpn_map(const char *desc, const struct tls_alpn_t *map)
{
const struct tls_alpn_t *p;
const char *sep = "";

fprintf(stderr, "%s: ", desc);
for (p = map; p && p->id[0]; p++) {
fprintf(stderr, "%sid=\"%s\"", sep, p->id);
sep = ", ";
}
fputs("\n", stderr);
}

EXPORTED int tls_enabled(void)
{
const char *val;
Expand Down Expand Up @@ -1203,8 +1216,10 @@ EXPORTED int tls_start_servertls(int readfd, int writefd, int timeout,
saslprops_reset(saslprops);

#ifdef HAVE_TLS_ALPN
if (alpn_map && alpn_map->id[0])
if (alpn_map && alpn_map->id[0]) {
dump_alpn_map(__func__, alpn_map);
SSL_CTX_set_alpn_select_cb(s_ctx, alpn_select_cb, (void *) alpn_map);
}
else
SSL_CTX_set_alpn_select_cb(s_ctx, NULL, NULL);
#endif
Expand Down Expand Up @@ -1726,10 +1741,12 @@ HIDDEN int tls_start_clienttls(int readfd, int writefd,
unsigned char *protos = NULL;
unsigned int protos_len;

dump_alpn_map(__func__, alpn_map);
alpn_get_protos(alpn_map, &protos, &protos_len);

if (SSL_CTX_set_alpn_protos(c_ctx, protos, protos_len)) {
syslog(LOG_ERR, "TLS client engine: failed to set ALPN protos");
dump_errors("SSL_CTX_set_alpn_protos");
}

free(protos);
Expand Down Expand Up @@ -1849,6 +1866,7 @@ HIDDEN int tls_start_clienttls(int readfd, int writefd,
done:
if (r && tls_conn) {
/* error; clean up */
dump_errors("clean up");
SSL_free(tls_conn);
tls_conn = NULL;
}
Expand Down
2 changes: 2 additions & 0 deletions imap/tls.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ struct tls_alpn_t {

#include "global.h" /* for saslprops_t */

void dump_alpn_map(const char *desc, const struct tls_alpn_t *map);

/* init tls */
int tls_init_serverengine(const char *ident,
int verifydepth, /* depth to verify */
Expand Down

0 comments on commit f3450f3

Please sign in to comment.