Skip to content

Commit

Permalink
Fixing #34
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-rabet committed Sep 7, 2022
1 parent 81a750f commit f4f17fe
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion code/core/security/crypto_disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,23 @@ EVP_PKEY *load_rsa_keypair_from_disk(const char *public_key_path,
FILE *public_key_file = fopen(public_key_path, "r");
FILE *private_key_file = fopen(private_key_path, "r");

if (!public_key_file || !private_key_file)
if (!public_key_file)
return NULL;

if (!private_key_file)
{
fclose(public_key_file);
return NULL;
}

if (PEM_read_PUBKEY(public_key_file, &rsa_keypair, NULL, NULL) == NULL)
internal_error_exit("Failed to load public key\n", EXIT_FAILURE);
if (PEM_read_PrivateKey(private_key_file, &rsa_keypair, NULL, passphrase)
== NULL)
internal_error_exit("Failed to load private key\n", EXIT_FAILURE);

close(public_key_file);
close(private_key_file);

return rsa_keypair;
}

0 comments on commit f4f17fe

Please sign in to comment.