diff options
| author | jsing <> | 2017-07-06 17:12:22 +0000 |
|---|---|---|
| committer | jsing <> | 2017-07-06 17:12:22 +0000 |
| commit | 40916534e3bc6be103b1cf19f2f976ccbed2b4ed (patch) | |
| tree | b0d09612d5975b84d46270853c8da03a6d034575 /src/lib | |
| parent | a21f0c405df345f9ac6e331f71f09db8e340ca31 (diff) | |
| download | openbsd-40916534e3bc6be103b1cf19f2f976ccbed2b4ed.tar.gz openbsd-40916534e3bc6be103b1cf19f2f976ccbed2b4ed.tar.bz2 openbsd-40916534e3bc6be103b1cf19f2f976ccbed2b4ed.zip | |
Add support for providing CRLs to libtls - once a CRL is provided we
enable CRL checking for the full certificate chain.
Based on a diff from Jack Burton <jack at saosce dot com dot au>, thanks!
Discussed with beck@
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/libtls/Symbols.list | 2 | ||||
| -rw-r--r-- | src/lib/libtls/tls.c | 42 | ||||
| -rw-r--r-- | src/lib/libtls/tls.h | 5 | ||||
| -rw-r--r-- | src/lib/libtls/tls_config.c | 18 | ||||
| -rw-r--r-- | src/lib/libtls/tls_internal.h | 4 |
5 files changed, 67 insertions, 4 deletions
diff --git a/src/lib/libtls/Symbols.list b/src/lib/libtls/Symbols.list index 3124c64211..6d174bc83a 100644 --- a/src/lib/libtls/Symbols.list +++ b/src/lib/libtls/Symbols.list | |||
| @@ -26,6 +26,8 @@ tls_config_set_ca_path | |||
| 26 | tls_config_set_cert_file | 26 | tls_config_set_cert_file |
| 27 | tls_config_set_cert_mem | 27 | tls_config_set_cert_mem |
| 28 | tls_config_set_ciphers | 28 | tls_config_set_ciphers |
| 29 | tls_config_set_crl_file | ||
| 30 | tls_config_set_crl_mem | ||
| 29 | tls_config_set_dheparams | 31 | tls_config_set_dheparams |
| 30 | tls_config_set_ecdhecurve | 32 | tls_config_set_ecdhecurve |
| 31 | tls_config_set_key_file | 33 | tls_config_set_key_file |
diff --git a/src/lib/libtls/tls.c b/src/lib/libtls/tls.c index f64f6d7632..ed857272c4 100644 --- a/src/lib/libtls/tls.c +++ b/src/lib/libtls/tls.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: tls.c,v 1.67 2017/06/22 18:03:57 jsing Exp $ */ | 1 | /* $OpenBSD: tls.c,v 1.68 2017/07/06 17:12:22 jsing Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -26,6 +26,8 @@ | |||
| 26 | #include <openssl/err.h> | 26 | #include <openssl/err.h> |
| 27 | #include <openssl/evp.h> | 27 | #include <openssl/evp.h> |
| 28 | #include <openssl/pem.h> | 28 | #include <openssl/pem.h> |
| 29 | #include <openssl/safestack.h> | ||
| 30 | #include <openssl/ssl.h> | ||
| 29 | #include <openssl/x509.h> | 31 | #include <openssl/x509.h> |
| 30 | 32 | ||
| 31 | #include <tls.h> | 33 | #include <tls.h> |
| @@ -464,8 +466,15 @@ tls_configure_ssl_verify(struct tls *ctx, SSL_CTX *ssl_ctx, int verify) | |||
| 464 | { | 466 | { |
| 465 | size_t ca_len = ctx->config->ca_len; | 467 | size_t ca_len = ctx->config->ca_len; |
| 466 | char *ca_mem = ctx->config->ca_mem; | 468 | char *ca_mem = ctx->config->ca_mem; |
| 469 | char *crl_mem = ctx->config->crl_mem; | ||
| 470 | size_t crl_len = ctx->config->crl_len; | ||
| 467 | char *ca_free = NULL; | 471 | char *ca_free = NULL; |
| 472 | STACK_OF(X509_INFO) *xis = NULL; | ||
| 473 | X509_STORE *store; | ||
| 474 | X509_INFO *xi; | ||
| 475 | BIO *bio = NULL; | ||
| 468 | int rv = -1; | 476 | int rv = -1; |
| 477 | int i; | ||
| 469 | 478 | ||
| 470 | SSL_CTX_set_verify(ssl_ctx, verify, NULL); | 479 | SSL_CTX_set_verify(ssl_ctx, verify, NULL); |
| 471 | SSL_CTX_set_cert_verify_callback(ssl_ctx, tls_ssl_cert_verify_cb, ctx); | 480 | SSL_CTX_set_cert_verify_callback(ssl_ctx, tls_ssl_cert_verify_cb, ctx); |
| @@ -499,10 +508,41 @@ tls_configure_ssl_verify(struct tls *ctx, SSL_CTX *ssl_ctx, int verify) | |||
| 499 | goto err; | 508 | goto err; |
| 500 | } | 509 | } |
| 501 | 510 | ||
| 511 | if (crl_mem != NULL) { | ||
| 512 | if (crl_len > INT_MAX) { | ||
| 513 | tls_set_errorx(ctx, "crl too long"); | ||
| 514 | goto err; | ||
| 515 | } | ||
| 516 | if ((bio = BIO_new_mem_buf(crl_mem, crl_len)) == NULL) { | ||
| 517 | tls_set_errorx(ctx, "failed to create buffer"); | ||
| 518 | goto err; | ||
| 519 | } | ||
| 520 | if ((xis = PEM_X509_INFO_read_bio(bio, NULL, tls_password_cb, | ||
| 521 | NULL)) == NULL) { | ||
| 522 | tls_set_errorx(ctx, "failed to parse crl"); | ||
| 523 | goto err; | ||
| 524 | } | ||
| 525 | store = SSL_CTX_get_cert_store(ssl_ctx); | ||
| 526 | for (i = 0; i < sk_X509_INFO_num(xis); i++) { | ||
| 527 | xi = sk_X509_INFO_value(xis, i); | ||
| 528 | if (xi->crl == NULL) | ||
| 529 | continue; | ||
| 530 | if (!X509_STORE_add_crl(store, xi->crl)) { | ||
| 531 | tls_set_error(ctx, "failed to add crl"); | ||
| 532 | goto err; | ||
| 533 | } | ||
| 534 | xi->crl = NULL; | ||
| 535 | } | ||
| 536 | X509_VERIFY_PARAM_set_flags(store->param, | ||
| 537 | X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL); | ||
| 538 | } | ||
| 539 | |||
| 502 | done: | 540 | done: |
| 503 | rv = 0; | 541 | rv = 0; |
| 504 | 542 | ||
| 505 | err: | 543 | err: |
| 544 | sk_X509_INFO_pop_free(xis, X509_INFO_free); | ||
| 545 | BIO_free(bio); | ||
| 506 | free(ca_free); | 546 | free(ca_free); |
| 507 | 547 | ||
| 508 | return (rv); | 548 | return (rv); |
diff --git a/src/lib/libtls/tls.h b/src/lib/libtls/tls.h index 4fad4518f2..1a6701b581 100644 --- a/src/lib/libtls/tls.h +++ b/src/lib/libtls/tls.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: tls.h,v 1.49 2017/05/06 20:57:45 jsing Exp $ */ | 1 | /* $OpenBSD: tls.h,v 1.50 2017/07/06 17:12:22 jsing Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -105,6 +105,9 @@ int tls_config_set_cert_file(struct tls_config *_config, | |||
| 105 | int tls_config_set_cert_mem(struct tls_config *_config, const uint8_t *_cert, | 105 | int tls_config_set_cert_mem(struct tls_config *_config, const uint8_t *_cert, |
| 106 | size_t _len); | 106 | size_t _len); |
| 107 | int tls_config_set_ciphers(struct tls_config *_config, const char *_ciphers); | 107 | int tls_config_set_ciphers(struct tls_config *_config, const char *_ciphers); |
| 108 | int tls_config_set_crl_file(struct tls_config *_config, const char *_crl_file); | ||
| 109 | int tls_config_set_crl_mem(struct tls_config *_config, const uint8_t *_crl, | ||
| 110 | size_t _len); | ||
| 108 | int tls_config_set_dheparams(struct tls_config *_config, const char *_params); | 111 | int tls_config_set_dheparams(struct tls_config *_config, const char *_params); |
| 109 | int tls_config_set_ecdhecurve(struct tls_config *_config, const char *_name); | 112 | int tls_config_set_ecdhecurve(struct tls_config *_config, const char *_name); |
| 110 | int tls_config_set_key_file(struct tls_config *_config, const char *_key_file); | 113 | int tls_config_set_key_file(struct tls_config *_config, const char *_key_file); |
diff --git a/src/lib/libtls/tls_config.c b/src/lib/libtls/tls_config.c index 8f0bd70508..fe049d1e4e 100644 --- a/src/lib/libtls/tls_config.c +++ b/src/lib/libtls/tls_config.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: tls_config.c,v 1.40 2017/05/06 20:59:28 jsing Exp $ */ | 1 | /* $OpenBSD: tls_config.c,v 1.41 2017/07/06 17:12:22 jsing Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -268,6 +268,7 @@ tls_config_free(struct tls_config *config) | |||
| 268 | free((char *)config->ca_mem); | 268 | free((char *)config->ca_mem); |
| 269 | free((char *)config->ca_path); | 269 | free((char *)config->ca_path); |
| 270 | free((char *)config->ciphers); | 270 | free((char *)config->ciphers); |
| 271 | free((char *)config->crl_mem); | ||
| 271 | 272 | ||
| 272 | free(config); | 273 | free(config); |
| 273 | } | 274 | } |
| @@ -299,6 +300,7 @@ tls_config_clear_keys(struct tls_config *config) | |||
| 299 | tls_keypair_clear(kp); | 300 | tls_keypair_clear(kp); |
| 300 | 301 | ||
| 301 | tls_config_set_ca_mem(config, NULL, 0); | 302 | tls_config_set_ca_mem(config, NULL, 0); |
| 303 | tls_config_set_crl_mem(config, NULL, 0); | ||
| 302 | } | 304 | } |
| 303 | 305 | ||
| 304 | int | 306 | int |
| @@ -579,6 +581,20 @@ tls_config_set_ciphers(struct tls_config *config, const char *ciphers) | |||
| 579 | } | 581 | } |
| 580 | 582 | ||
| 581 | int | 583 | int |
| 584 | tls_config_set_crl_file(struct tls_config *config, const char *crl_file) | ||
| 585 | { | ||
| 586 | return tls_config_load_file(&config->error, "CRL", crl_file, | ||
| 587 | &config->crl_mem, &config->crl_len); | ||
| 588 | } | ||
| 589 | |||
| 590 | int | ||
| 591 | tls_config_set_crl_mem(struct tls_config *config, const uint8_t *crl, | ||
| 592 | size_t len) | ||
| 593 | { | ||
| 594 | return set_mem(&config->crl_mem, &config->crl_len, crl, len); | ||
| 595 | } | ||
| 596 | |||
| 597 | int | ||
| 582 | tls_config_set_dheparams(struct tls_config *config, const char *params) | 598 | tls_config_set_dheparams(struct tls_config *config, const char *params) |
| 583 | { | 599 | { |
| 584 | int keylen; | 600 | int keylen; |
diff --git a/src/lib/libtls/tls_internal.h b/src/lib/libtls/tls_internal.h index c0c55216df..bed9d6e7f4 100644 --- a/src/lib/libtls/tls_internal.h +++ b/src/lib/libtls/tls_internal.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: tls_internal.h,v 1.61 2017/06/22 18:03:57 jsing Exp $ */ | 1 | /* $OpenBSD: tls_internal.h,v 1.62 2017/07/06 17:12:22 jsing Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2014 Jeremie Courreges-Anglas <jca@openbsd.org> | 3 | * Copyright (c) 2014 Jeremie Courreges-Anglas <jca@openbsd.org> |
| 4 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 4 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
| @@ -84,6 +84,8 @@ struct tls_config { | |||
| 84 | size_t ca_len; | 84 | size_t ca_len; |
| 85 | const char *ciphers; | 85 | const char *ciphers; |
| 86 | int ciphers_server; | 86 | int ciphers_server; |
| 87 | char *crl_mem; | ||
| 88 | size_t crl_len; | ||
| 87 | int dheparams; | 89 | int dheparams; |
| 88 | int ecdhecurve; | 90 | int ecdhecurve; |
| 89 | struct tls_keypair *keypair; | 91 | struct tls_keypair *keypair; |
