Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wipe output on failure: key generation (#586)
* Refactor error handling: key generation Current code is hard to follow and has complicated management for key generation contexts. However, this is not essential complexity. The core insight here is that while the context is shared, exporting private and public key are two independent operations. Therefore we can try exporting both keys, free the context, and only then deal with the results. It then becomes really natural to introduce a helper function to combine two results into one. While we're here, make sure that all local variables are initialized. This too makes error handling path easier to write and understand. * Wipe output on failure: key generation Now, let's make sure that we don't leak any information if key generation fails. For example, if the private key has been extracted just fine but extracting public key fails then the private key has already been written out into the user buffer. This is not nice. We can easily insert soter_wipe() calls to remove results from output buffers if key generation is not succesful. Note that we *do not* wipe the buffer if it is reported to be too small. In this case the length is now equal to the desired buffer length, not actual one provided by the caller. We'd probably overrun the buffer if we touch it. Instead, we can simply not wipe it because in this case we have not written anything into it yet. Symmetric key generation simply calls soter_rand() which wipes after itself like an adult. We leave a comment just in case the code gets more complex in the future, so that the developers don't forget to add a soter_wipe() call if necessary. This covers Themis code for key generation API: - themis_gen_sym_key - themis_gen_rsa_key_pair - themis_gen_ec_key_pair * Fix clang-tidy warnings for OpenSSL In OpenSSL EVP_PKEY_CTX_ctrl() penultimate argument "p1" has "int" type. We use this function to set RSA key length in bits, and we incorrectly use "unsigned" type when interfacing with EVP_PKEY_CTX_ctrl(). Update the type to just "int" to avoid warnings by clang-tidy about narrowing casts. We can use "int" in rsa_key_length() because it's wide enough for current maximum length of 4096 bits.
- Loading branch information