*/
if (conf->psk_query && !*conf->psk_query) {
ERROR("Invalid PSK Configuration: psk_query cannot be empty");
+ error:
+ SSL_CTX_free(ctx);
return NULL;
}
} else if (conf->psk_query) {
ERROR("Invalid PSK Configuration: psk_query cannot be used for outgoing connections");
- return NULL;
+ goto error;
}
/*
(conf->psk_identity && !*conf->psk_identity) ||
(conf->psk_password && !*conf->psk_password)) {
ERROR("Invalid PSK Configuration: psk_identity or psk_password are empty");
- return NULL;
+ goto error;
}
if (conf->psk_identity) {
if (conf->chains || conf->ca_file || conf->ca_path) {
ERROR("When PSKs are used, No certificate configuration is permitted");
- return NULL;
+ goto error;
}
if (client) {
psk_len = strlen(conf->psk_password);
if (strlen(conf->psk_password) > (2 * PSK_MAX_PSK_LEN)) {
ERROR("psk_hexphrase is too long (max %d)", PSK_MAX_PSK_LEN);
- return NULL;
+ goto error;
}
/*
hex_len = fr_hex2bin(buffer, sizeof(buffer), conf->psk_password, psk_len);
if (psk_len != (2 * hex_len)) {
ERROR("psk_hexphrase is not all hex");
- return NULL;
+ goto error;
}
goto post_ca;
if (!SSL_CTX_load_verify_locations(ctx, conf->ca_file, conf->ca_path)) {
tls_log_error(NULL, "Failed reading Trusted root CA list \"%s\"",
conf->ca_file);
- return NULL;
+ goto error;
}
}
size_t i;
for (i = 0; i < chains_conf; i++) {
- if (tls_ctx_load_cert_chain(ctx, conf->chains[i]) < 0) return NULL;
+ if (tls_ctx_load_cert_chain(ctx, conf->chains[i]) < 0) goto error;
}
}
DEBUG3("%s chain", tls_utils_x509_pkey_type(our_cert));
if (!SSL_CTX_get0_chain_certs(ctx, &our_chain)) {
tls_log_error(NULL, "Failed retrieving chain certificates");
- return NULL;
+ goto error;
}
for (i = sk_X509_num(our_chain); i > 0 ; i--) {
if (conf->tls_min_version > conf->tls_max_version) {
ERROR("tls_min_version (%f) must be <= tls_max_version (%f)",
conf->tls_min_version, conf->tls_max_version);
- return NULL;
+ goto error;
}
if (conf->tls_max_version < (float) 1.0) {
ERROR("tls_max_version must be >= 1.0 as SSLv2 and SSLv3 are permanently disabled");
- return NULL;
+ goto error;
}
# ifdef TLS1_4_VERSION
if (!SSL_CTX_set_max_proto_version(ctx, max_version)) {
tls_log_error(NULL, "Failed setting TLS maximum version");
- return NULL;
+ goto error;
}
}
if (conf->tls_min_version < (float) 1.0) {
ERROR("tls_min_version must be >= 1.0 as SSLv2 and SSLv3 are permanently disabled");
- return NULL;
+ goto error;
}
# ifdef TLS1_4_VERSION
else if (conf->tls_min_version >= (float) 1.4) min_version = TLS1_4_VERSION;
if (!SSL_CTX_set_min_proto_version(ctx, min_version)) {
tls_log_error(NULL, "Failed setting TLS minimum version");
- return NULL;
+ goto error;
}
}
#else
if (conf->tls_min_version < (float) 1.0) {
ERROR("SSLv2 and SSLv3 are permanently disabled due to critical security issues");
- return NULL;
+ goto error;
}
/*
if ((ctx_options & ctx_tls_versions) == ctx_tls_versions) {
ERROR("You have disabled all available TLS versions. EAP will not work");
- return NULL;
+ goto error;
}
}
#endif
#if OPENSSL_VERSION_NUMBER >= 0x0090800fL
#ifndef OPENSSL_NO_ECDH
if (ctx_ecdh_curve_set(ctx, conf->ecdh_curve, conf->disable_single_dh_use) < 0) {
- return NULL;
+ goto error;
}
#endif
#endif
cert_vpstore = SSL_CTX_get_cert_store(ctx);
if (cert_vpstore == NULL) {
tls_log_error(NULL, "Error reading Certificate Store");
- return NULL;
+ goto error;
}
X509_STORE_set_flags(cert_vpstore, X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL);
}
if (conf->random_file) {
if (!(RAND_load_file(conf->random_file, 1024 * 10))) {
tls_log_error(NULL, "Failed loading randomness");
- return NULL;
+ goto error;
}
}
if (conf->cipher_list) {
if (!SSL_CTX_set_cipher_list(ctx, conf->cipher_list)) {
tls_log_error(NULL, "Failed setting cipher list");
- return NULL;
+ goto error;
}
}
ssl = SSL_new(ctx);
if (!ssl) {
tls_log_error(NULL, "Failed creating temporary SSL session");
- return NULL;
+ goto error;
}
DEBUG3("Configured ciphers (by priority)");
char *dh_file;
memcpy(&dh_file, &conf->dh_file, sizeof(dh_file));
- if (ctx_dh_params_load(ctx, dh_file) < 0) return NULL;
+ if (ctx_dh_params_load(ctx, dh_file) < 0) goto error;
}
return ctx;