diff options
| author | jsing <> | 2016-12-26 16:20:58 +0000 |
|---|---|---|
| committer | jsing <> | 2016-12-26 16:20:58 +0000 |
| commit | e42acf6ea18cc05e621978c53dbbb294bdb059c7 (patch) | |
| tree | fbec04954e27c01c99531c149058fcede14efd69 /src | |
| parent | 14b2889eb360f84951861c14bd3a80c2fd701017 (diff) | |
| download | openbsd-e42acf6ea18cc05e621978c53dbbb294bdb059c7.tar.gz openbsd-e42acf6ea18cc05e621978c53dbbb294bdb059c7.tar.bz2 openbsd-e42acf6ea18cc05e621978c53dbbb294bdb059c7.zip | |
Hook up a certificate verify callback so that we can set user friendly
error messages, instead of libssl error strings. This gives us messages
like:
certificate verification failed: certificate has expired
Instead of:
14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
This also lets us always enable peer verification since the no verification
case is now handled via the callback.
Tested by tedu@
ok beck@
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libtls/tls.c | 33 | ||||
| -rw-r--r-- | src/lib/libtls/tls_client.c | 6 |
2 files changed, 31 insertions, 8 deletions
diff --git a/src/lib/libtls/tls.c b/src/lib/libtls/tls.c index 51717a79cb..6937afe3b8 100644 --- a/src/lib/libtls/tls.c +++ b/src/lib/libtls/tls.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: tls.c,v 1.52 2016/11/05 14:50:05 beck Exp $ */ | 1 | /* $OpenBSD: tls.c,v 1.53 2016/12/26 16:20:58 jsing Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -365,12 +365,37 @@ tls_configure_ssl(struct tls *ctx, SSL_CTX *ssl_ctx) | |||
| 365 | return (-1); | 365 | return (-1); |
| 366 | } | 366 | } |
| 367 | 367 | ||
| 368 | static int | ||
| 369 | tls_ssl_cert_verify_cb(X509_STORE_CTX *x509_ctx, void *arg) | ||
| 370 | { | ||
| 371 | struct tls *ctx = arg; | ||
| 372 | int x509_err; | ||
| 373 | |||
| 374 | if (ctx->config->verify_cert == 0) | ||
| 375 | return (1); | ||
| 376 | |||
| 377 | if ((X509_verify_cert(x509_ctx)) < 0) { | ||
| 378 | tls_set_errorx(ctx, "X509 verify cert failed"); | ||
| 379 | return (0); | ||
| 380 | } | ||
| 381 | |||
| 382 | x509_err = X509_STORE_CTX_get_error(x509_ctx); | ||
| 383 | if (x509_err == X509_V_OK) | ||
| 384 | return (1); | ||
| 385 | |||
| 386 | tls_set_errorx(ctx, "certificate verification failed: %s", | ||
| 387 | X509_verify_cert_error_string(x509_err)); | ||
| 388 | |||
| 389 | return (0); | ||
| 390 | } | ||
| 391 | |||
| 368 | int | 392 | int |
| 369 | tls_configure_ssl_verify(struct tls *ctx, SSL_CTX *ssl_ctx, int verify) | 393 | tls_configure_ssl_verify(struct tls *ctx, SSL_CTX *ssl_ctx, int verify) |
| 370 | { | 394 | { |
| 371 | size_t ca_len = ctx->config->ca_len; | 395 | size_t ca_len = ctx->config->ca_len; |
| 372 | char *ca_mem = ctx->config->ca_mem; | 396 | char *ca_mem = ctx->config->ca_mem; |
| 373 | char *ca_free = NULL; | 397 | char *ca_free = NULL; |
| 398 | int rv = -1; | ||
| 374 | 399 | ||
| 375 | SSL_CTX_set_verify(ssl_ctx, verify, NULL); | 400 | SSL_CTX_set_verify(ssl_ctx, verify, NULL); |
| 376 | 401 | ||
| @@ -399,14 +424,14 @@ tls_configure_ssl_verify(struct tls *ctx, SSL_CTX *ssl_ctx, int verify) | |||
| 399 | if (ctx->config->verify_depth >= 0) | 424 | if (ctx->config->verify_depth >= 0) |
| 400 | SSL_CTX_set_verify_depth(ssl_ctx, ctx->config->verify_depth); | 425 | SSL_CTX_set_verify_depth(ssl_ctx, ctx->config->verify_depth); |
| 401 | 426 | ||
| 402 | free(ca_free); | 427 | SSL_CTX_set_cert_verify_callback(ssl_ctx, tls_ssl_cert_verify_cb, ctx); |
| 403 | 428 | ||
| 404 | return (0); | 429 | rv = 0; |
| 405 | 430 | ||
| 406 | err: | 431 | err: |
| 407 | free(ca_free); | 432 | free(ca_free); |
| 408 | 433 | ||
| 409 | return (-1); | 434 | return (rv); |
| 410 | } | 435 | } |
| 411 | 436 | ||
| 412 | void | 437 | void |
diff --git a/src/lib/libtls/tls_client.c b/src/lib/libtls/tls_client.c index 84f4e91740..18e1667eed 100644 --- a/src/lib/libtls/tls_client.c +++ b/src/lib/libtls/tls_client.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: tls_client.c,v 1.37 2016/11/02 15:18:42 beck Exp $ */ | 1 | /* $OpenBSD: tls_client.c,v 1.38 2016/12/26 16:20:58 jsing Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -195,9 +195,7 @@ tls_connect_common(struct tls *ctx, const char *servername) | |||
| 195 | } | 195 | } |
| 196 | } | 196 | } |
| 197 | 197 | ||
| 198 | if (ctx->config->verify_cert && | 198 | if (tls_configure_ssl_verify(ctx, ctx->ssl_ctx, SSL_VERIFY_PEER) == -1) |
| 199 | (tls_configure_ssl_verify(ctx, ctx->ssl_ctx, | ||
| 200 | SSL_VERIFY_PEER) == -1)) | ||
| 201 | goto err; | 199 | goto err; |
| 202 | 200 | ||
| 203 | if (SSL_CTX_set_tlsext_status_cb(ctx->ssl_ctx, tls_ocsp_verify_cb) != 1) { | 201 | if (SSL_CTX_set_tlsext_status_cb(ctx->ssl_ctx, tls_ocsp_verify_cb) != 1) { |
