DDvO contrib: private key protection using OpenSSL's PEM password callback #40
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This implements password-based protection for PEM encoded private keys using OpenSSL's PEM password callback function. The changes made essentially affect only the example applications.
estclient.c and estserver.c now implement an extra option, "--keypass", used to specify a password source for en-/decrypting the PEM file contents used to store the respective private keys. According to the simple password callback function I implemented/used, the password may be either typed in on-the fly on the console or passed on the command line. As the key encryption algorithm I decided to use AES-128-CBC:
#define EST_PRIVATE_KEY_ENC EVP_aes_128_cbc() // The key wrap algorithm optionally used to protect private keys
I had to extend the est_load_key function, as well as the PEM write function and the RSA/EC key generation functions, to make use of the password callback. I moved all these helper functions:
to est_ossl_util.c (where their implementation makes most sense to me, while they could also be defined, e.g., in est.c, example/util/utils.c, or test/util/test_utils.c) and declared them in est.h, such that they can be used easily by all applications and unit tests.
BTW, I managed to avoid adaptations to the code of the unit tests simply by employing the following macros:
The only action needed for the unit tests is to fully re-compile them once, which may be triggered simply by a "make clean".