-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for writing encrypted private keys #1372
Comments
Hi @Dmitry-Frantsev I am not sure what your request is. |
Hi. MBEDTLS library can load encrypted RSA keys (PEM format). Could you add encryption support for mbedtls_pk_write_key_pem( ). |
Bump! |
Mbed TLS supports key wrapping. See https://github.com/ARMmbed/mbedtls/blob/development/include/mbedtls/nist_kw.h Does this work in your use case? If not, why not? |
It can work but a solution that will export in PEM format a passphrase-protected key will be appreciated. Like said before, a function |
Is there a solution for this? I really need to take use this. There really isn't any other solution for me. |
This feature would make sense, but Arm isn't likely to work on it in the foreseeable future. Pull requests welcome. |
Some preview of this is available at fork https://github.com/loafer-mka/mbedtls, branch ‘dev_clean’. This is an attempt to add enhanced support for load/store encrypted and plain keys in different formats... there are not tests at all (added/changed functions were tested together with other project which uses mbedtls... so they are working ... it seems to me ;) ) Over time, I hope to add tests and refine the pull request, but it will take time. If you can check and suggest a better API, then that would be great. Questions and wishes are welcome. |
What is missing in MBed TLS is support (in the form of utility functions) for writing PKCS#8 formatted private keys. I think this is what most people colloquially refer to as "PEM formatted" private keys. A better title for this issue would be "Add support for writing encrypted PKCS#8 keys". Note that MBed TLS already has features for converting ASN.1 DER data to PEM ( Currently the only way to (somewhat easily) create encrypted private keys in MBed TLS is using the PKCS#5 format, with However, this has some downsides:
So it should be possible to create a "PEM PKCS#8 encrypted private key" in MBedTLS, which is the default private key format for tools like OpenSSL, but it's far from convenient, requiring the following steps:
This is in stark contrast to the easy of use of the private key parsing function |
@seppestas Thanks for the feedback! Work on features such as this one is unfortunately paused while we prepare the next major version of Mbed TLS, and we'll need to expand the API to cover encrypted key formats which will likely land after 4.0. So this is on our radar, but won't happen soon. |
I eventually settled on using a plain AES cypher to encrypt private keys iof.
Either way, my application has fairly little benefit from thing like PBKDF. I still think it should be possible to use
Can be overcome by reserving space (at least one block size) for the padding and calculating the expected padding size (and thus cyphertext size) based on the cypher block size. Though I never got it working fully and lost interest in getting it working when I realised |
Wanted to note that @seppestas workaround seems do-able in version 3.6.0. I have verified it by modifying the https://github.com/morningstarcorp/mbedtls-morningstar/tree/experimental/gen_pkcs5_enc_key The resulting key can be parsed by (please note that in my example I hard-code the salt and IV for ease of debugging, it's intended only as an example of constructing the ASN.1 structure properly) |
Description
Enhancement\Feature Request
Add support a cipher for storing private keys please.
I use mbedtls library for RSA key pair generation.
It is very important to store a private key with cipher.
The text was updated successfully, but these errors were encountered: