diff options
Diffstat (limited to 'src/lib/libtls/tls.c')
-rw-r--r-- | src/lib/libtls/tls.c | 33 |
1 files changed, 29 insertions, 4 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 |