Store private seed as the secret for newly generated keys #2472
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.
Today the private/public keypair that orlp/ed25519 generates and that we store in the Keychain is "incompatible" with other cryptography libraries/tools. In particular the private key this library generates (which includes a variation of the hashed seed) cannot be used with other libraries for signing (without modification).
For newly generated keys, this change instead stores the base64-encoded
seed
as the private key we store in Keychain and we use for exporting/importing keys. We still keep compatibility with older generated keys whose format more resembles a base64-encoding ofhash(seed) + public_key
.Base64 encoding/decoding was kept around to allowing copying the secret from Keychain Access. I also did not want to use a different format when exporting/importing keys for consistency.
The private
seed
was picked because it's the minimal/defacto info needed to be able to construct the private/public keypair using any library or tool even if they may prefer a different internal representation. For instance, orlp/ed25519 internally prefershash(seed) + public_key
, CryptoKit prefersseed
, golang & libsodium preferseed + public_key
, openssl prefers anOID + seed
for DER files, etc. This representation we now store does not give any preference to any particular tool or internal representation. I am also not worried about performance of not using a precomputed public key or hashed seed.As part of this change, I am also disabling command line flags that allow passing the private key as a command line argument. This option was already deprecated and should not be supported for new keys.
Fixes #2470
An example for exporting to DER file (assuming we have a newly generated key):
For other libraries/tools you just need to pass
exported_key_binary
as theseed
to construct the key-pair.Importing from a DER file is easier:
Past related discussions:
#2467
#2160
#2298
Misc Checklist
Testing
I tested and verified my change by using one or multiple of these methods:
Things to test:
macOS version tested: 14.1.1 (23B81)