-/* $OpenBSD: tls_config.c,v 1.19 2016/07/06 16:16:36 jsing Exp $ */
+/* $OpenBSD: tls_config.c,v 1.20 2016/07/06 16:47:18 jsing Exp $ */
/*
* Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
*
int
tls_config_set_ciphers(struct tls_config *config, const char *ciphers)
{
+ SSL_CTX *ssl_ctx = NULL;
+
if (ciphers == NULL ||
strcasecmp(ciphers, "default") == 0 ||
strcasecmp(ciphers, "secure") == 0)
strcasecmp(ciphers, "legacy") == 0)
ciphers = TLS_CIPHERS_COMPAT;
+ if ((ssl_ctx = SSL_CTX_new(SSLv23_method())) == NULL) {
+ tls_config_set_errorx(config, "out of memory");
+ goto fail;
+ }
+ if (SSL_CTX_set_cipher_list(ssl_ctx, ciphers) != 1) {
+ tls_config_set_errorx(config, "no ciphers for '%s'", ciphers);
+ goto fail;
+ }
+
+ SSL_CTX_free(ssl_ctx);
return set_string(&config->ciphers, ciphers);
+
+ fail:
+ SSL_CTX_free(ssl_ctx);
+ return -1;
}
int