Skip to content

Commit

Permalink
lib-ssl-iostream: Make DH parameters optional
Browse files Browse the repository at this point in the history
Since a lot of connections use elliptic curve
Diffie-Hellman these days, make it possible to
use dovecot without providing Diffie-Hellman
parameters. This reduces setup cost as the
parameters do not need to be generated, which
can be a time consuming task.
  • Loading branch information
cmouse committed Aug 7, 2018
1 parent 920369d commit a43b54f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
4 changes: 0 additions & 4 deletions src/lib-master/master-service-ssl-settings.c
Expand Up @@ -112,10 +112,6 @@ master_service_ssl_settings_check(void *_set, pool_t pool ATTR_UNUSED,
*error_r = "ssl enabled, but ssl_key not set";
return FALSE;
}
if (*set->ssl_dh == '\0') {
*error_r = "ssl enabled, but ssl_dh not set";
return FALSE;
}
#endif
if (set->ssl_verify_client_cert && *set->ssl_ca == '\0') {
*error_r = "ssl_verify_client_cert set, but ssl_ca not";
Expand Down
23 changes: 10 additions & 13 deletions src/lib-ssl-iostream/iostream-openssl-context.c
Expand Up @@ -47,17 +47,11 @@ static RSA *ssl_gen_rsa_key(SSL *ssl ATTR_UNUSED,
}

static DH *ssl_tmp_dh_callback(SSL *ssl ATTR_UNUSED,
int is_export, int keylength)
int is_export ATTR_UNUSED, int keylength ATTR_UNUSED)
{
struct ssl_iostream *ssl_io;

ssl_io = SSL_get_ex_data(ssl, dovecot_ssl_extdata_index);
/* Well, I'm not exactly sure why the logic in here is this.
It's the same as in Postfix, so it can't be too wrong. */
if (is_export != 0 && keylength == 512 && ssl_io->ctx->dh_512 != NULL)
return ssl_io->ctx->dh_512;
else
return ssl_io->ctx->dh_default;
i_error("Diffie-Hellman key exchange requested, "
"but no DH parameters provided. Set ssh_dh=</path/to/dh.pem");
return NULL;
}

static int
Expand Down Expand Up @@ -168,7 +162,9 @@ ssl_iostream_ctx_use_dh(struct ssl_iostream_context *ctx,
{
DH *dh;
int ret = 0;

if (*set->dh == '\0') {
return 0;
}
if (openssl_iostream_load_dh(set, &dh, error_r) < 0)
return -1;
if (SSL_CTX_set_tmp_dh(ctx->ssl_ctx, dh) == 0) {
Expand Down Expand Up @@ -506,7 +502,7 @@ ssl_proxy_ctx_get_pkey_ec_curve_name(const struct ssl_iostream_settings *set,

static int
ssl_proxy_ctx_set_crypto_params(SSL_CTX *ssl_ctx,
const struct ssl_iostream_settings *set ATTR_UNUSED,
const struct ssl_iostream_settings *set,
const char **error_r ATTR_UNUSED)
{
#if defined(HAVE_ECDH) && !defined(SSL_CTX_set_ecdh_auto)
Expand All @@ -516,7 +512,8 @@ ssl_proxy_ctx_set_crypto_params(SSL_CTX *ssl_ctx,
#endif
if (SSL_CTX_need_tmp_RSA(ssl_ctx) != 0)
SSL_CTX_set_tmp_rsa_callback(ssl_ctx, ssl_gen_rsa_key);
SSL_CTX_set_tmp_dh_callback(ssl_ctx, ssl_tmp_dh_callback);
if (set->dh == NULL || *set->dh == '\0')
SSL_CTX_set_tmp_dh_callback(ssl_ctx, ssl_tmp_dh_callback);
#ifdef HAVE_ECDH
/* In the non-recommended situation where ECDH cipher suites are being
used instead of ECDHE, do not reuse the same ECDH key pair for
Expand Down

0 comments on commit a43b54f

Please sign in to comment.