Skip to content

Commit

Permalink
Propagate OpenSSL initialization errors
Browse files Browse the repository at this point in the history
  • Loading branch information
wferi authored and fabbione committed Jan 30, 2018
1 parent c7e1f81 commit 598fa5d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libknet/crypto.c
Expand Up @@ -141,7 +141,7 @@ int crypto_init(
*/
knet_h->crypto_instance->model = model;
if (crypto_modules_cmds[knet_h->crypto_instance->model].ops->init(knet_h, knet_handle_crypto_cfg)) {
savederrno = EPIPE;
savederrno = errno;
goto out_err;
}

Expand Down
7 changes: 7 additions & 0 deletions libknet/crypto_openssl.c
Expand Up @@ -489,6 +489,7 @@ static int opensslcrypto_init(
{
static int openssl_is_init = 0;
struct opensslcrypto_instance *opensslcrypto_instance = NULL;
int savederrno;

log_debug(knet_h, KNET_SUB_OPENSSLCRYPTO,
"Initizializing openssl crypto module [%s/%s]",
Expand Down Expand Up @@ -522,6 +523,7 @@ static int opensslcrypto_init(
knet_h->crypto_instance->model_instance = malloc(sizeof(struct opensslcrypto_instance));
if (!knet_h->crypto_instance->model_instance) {
log_err(knet_h, KNET_SUB_OPENSSLCRYPTO, "Unable to allocate memory for openssl model instance");
errno = ENOMEM;
return -1;
}

Expand All @@ -535,6 +537,7 @@ static int opensslcrypto_init(
opensslcrypto_instance->crypto_cipher_type = EVP_get_cipherbyname(knet_handle_crypto_cfg->crypto_cipher_type);
if (!opensslcrypto_instance->crypto_cipher_type) {
log_err(knet_h, KNET_SUB_OPENSSLCRYPTO, "unknown crypto cipher type requested");
savederrno = ENXIO;
goto out_err;
}
}
Expand All @@ -545,19 +548,22 @@ static int opensslcrypto_init(
opensslcrypto_instance->crypto_hash_type = EVP_get_digestbyname(knet_handle_crypto_cfg->crypto_hash_type);
if (!opensslcrypto_instance->crypto_hash_type) {
log_err(knet_h, KNET_SUB_OPENSSLCRYPTO, "unknown crypto hash type requested");
savederrno = ENXIO;
goto out_err;
}
}

if ((opensslcrypto_instance->crypto_cipher_type) &&
(!opensslcrypto_instance->crypto_hash_type)) {
log_err(knet_h, KNET_SUB_OPENSSLCRYPTO, "crypto communication requires hash specified");
savederrno = EINVAL;
goto out_err;
}

opensslcrypto_instance->private_key = malloc(knet_handle_crypto_cfg->private_key_len);
if (!opensslcrypto_instance->private_key) {
log_err(knet_h, KNET_SUB_OPENSSLCRYPTO, "Unable to allocate memory for openssl private key");
savederrno = ENOMEM;
goto out_err;
}
memmove(opensslcrypto_instance->private_key, knet_handle_crypto_cfg->private_key, knet_handle_crypto_cfg->private_key_len);
Expand Down Expand Up @@ -589,6 +595,7 @@ static int opensslcrypto_init(
out_err:
opensslcrypto_fini(knet_h);

errno = savederrno;
return -1;
}

Expand Down

0 comments on commit 598fa5d

Please sign in to comment.