Add RSA key importing functionality for OpenSSL private keys #223
Labels
No labels
bug
duplicate
enhancement
feature
help wanted
improve API
invalid
needs documentation
not-planned
rtfm
stale
support
wishlist
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-libtom/libtomcrypt#223
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
TomCrypt currently supports importing OpenSSL RSA public keys. However, OpenSSL private keys cannot be imported currently. Adding this feature would expand this library's usability.
Could you please post a sample key that you cannot import? Or even better an openssl command used for "unimportable" key generation e.g.
openssl genrsa ...?If you're talking about password-protected RSA private keys you're right. If you remove the password from the key you should be able to import it.
But providing am example-key would be best.
If you generate an RSA key like this:
libtomcrypt should be able to load
test_rsa_private.derandtest_rsa_public.der(if not then it's a bug).Here is the OpenSSL private key I am trying to open. It is not password-protected:
https://pastebin.com/nSZM1Gpt
Some things that I noticed:
For public keys, OpenSSL DER-encodes them differently from TomCrypt keys. A TomCrypt public key has the following structure:
OpenSSL keys have a different structure:
In rsa_import.c, I can find the code that converts the OpenSSL public key structure to the TomCrypt public key structure.
OpenSSL private keys are also encoded differently from TomCrypt private keys. Here's a TomCrypt private key structure:
And here's an OpenSSL private key structure:
However, I don't see any code in rsa_import.c to convert this OpenSSL structure to a TomCrypt structure. It looks like rsa_import.c first tries to decode the key like an OpenSSL public key, then tries to decode the key like a TomCrypt public key, and finally tries to decode the like like a TomCrypt private key.
Your keys has PKCS#8 format.
The function
rsa_import_pkcs8from #157 is able to load it.That function is only provided in dev, correct? Not in the latest release, 1.17?
Unfortunately it is not even in
developit's currently a pull request.Just take this file
github.com/libtom/libtomcrypt@fbcad861e4/src/pk/rsa/rsa_import_pkcs8.cThank you, I may have gotten that code working a bit, it's very helpful.
I have a question about some parts. The code has rsaoid which is an oid_st datatype. The code also uses corresponding functions pk_get_oid(...). This datatype and function are not in the latest release, 1.17. It looks like this variable is only used to compare with something else. What would be the consequences of removing this check from my implementation?
Is there any similar code to convert OpenSSL ECC private and public keys to be TomCrypt compliant?
PR #65 has that, but it's also not merged yet as it's dependant on #187 which isn't merged yet
I'm closing this one as it's a duplicate of #157