-
Notifications
You must be signed in to change notification settings - Fork 28
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
Importing and exporting keys that are in non-default formats #149
Comments
Initial work drafting an API to support the first use case - "import keys in other formats" - has been carried out in the Mbed TLS project, here: Mbed-TLS/mbedtls#7910. I plan to extend that design to support key export, and implementation-defined formats, in order to support the other use cases. |
Key formats to supportKey format related requirements:
The API design in Mbed-TLS/mbedtls#7910 only addresses key import, and the definition of key formats in the Proposal: Split the format specifier into separate 'format structure' and 'data encoding' fields, so that it is possible to use a relaxed specifier on import (expecting the implementation to detect PEM or DER encoding), but use a precise specifier on export. This seems like a reasonable approach - it permits additional encoding mechanisms for the same structural data layout, but also permits implementation-specific formats to reuse one or both of the fields independently. Question: how much future space do we need for the structure and encoding fields in the format specifier? API proposalThe key data formats are defined as 16-bit integer values. The format value zero is special, indicating the Crypto API default format and encoding for all key types. For other values, the top bit (bit 15) is reserved for use by implementation-specific formats, eleven bits (bits [14:4]) define the structure, and four bits ([3:0]) the encoding. An encoding value of zero, indicates 'any' encoding, permitted for use in key import. Key export must specify an encoding, if the structure support multiple types of data encoding.
The extended import and export APIs are just like the current functions, but take a format specifier. Note that if
When importing a key where the key data includes some of the key attributes, such as the key type or key policy, any values supplied in the key attributes object much match the values in the imported key data. Specific rules for combining the key policy attributes from the provided attributes and the key data will be defined for each supported key format. |
With only two encodings (plus the 'any' one), the API might be easier to use by just explicitly defining all of the formats (but retaining the field structure)? E.g.:
|
@athoelke , when do you plant/expect to get this merged ? |
I would be happy to include this in a 1.3 update (along with integration of the PAKE API). However, I was hoping for some feedback on the proposed draft API (above), in particular regarding some of the perhaps-arbitrary choices relating to the design of the format specifier, and the balance between flexible and rigid interpretation of the format value on import and export. I'd prefer to have a somewhat-agreed draft to base the specification text on, in order to reduce the risk that significant rewriting is needed if a reason to redesign the API only comes to light after creating the specification text. |
Do we also require a variant of |
In light of the API naming conclusion with the custom key production parameters, should this API also be named |
We'll definitely need a way to export a public key with a custom format. This might be a separate function or distinct format specifiers. This is not related to custom production parameters. And in terms of naming, I'd like to find something more specific than “ext” or “custom”. |
A request for PKCS8-encrypted PEM keys: Mbed-TLS/mbedtls#1372 (comment) |
I would like to suggest naming these functions |
I now plan to progress this to a draft PR, given interest in finalizing this API for some implementors. I am not confident about the proposed sizing of the key format encoding. There does not seem to be a strong case for optimizing the size of the key format specifier in the specification, so I am inclined to define the format specifier For export, I am also debating an alternative parameter ordering:
The format specifier is an operational parameter (controlling what the function does), while the key is a data input. Or is it better to place the format closer to the output data buffer parameters? |
Revisiting the public key export question...
As However, the proposal above doesn't enable us to use this API to export an EC public key in the Crypto API default format from a EC key pair:
Proposal
As a general follow-up - ensure that for any key type where we introduce additional key formats, the default key format has an explicit format specifier. |
Following discussion with the MbedTLS team, it might be useful to include an additional parameter when exporting. Many key formats have different ways of including elements of the key, or have optional content. For example:
Such options are not necessary to specify when importing a key, as they are unambiguously determined by the key data. Using the format specifier for such options becomes cumbersome for key import: should the implementation ignore them, or reject inputs that fail to match the specifier? These options are, in general, specific to a particular key format (e.g. the compressed/uncompressed point). However, formats that embed other formats (SubjectPublicKeyInfo can include an EC curve point), may benefit from reusing some options. So this might result in an export API like this:
Now a couple of further questions arise:
|
DER encodings always begin with
I'm weakly in favor: it's one less API function and doesn't really add implementation complexity. The main argument I see against it is that it can make it harder to see where you might be exporting a private key (but then if applications that want to ensure they don't export private keys can do it by not setting the EXPORT usage flag). |
This issue is a broader set of use cases than the one defined in #44, which only considers the import of a key from a data format that specifies the key type and/or policy.
There are a number of uses cases where built-in support for additional key data formats are valuable for applications using the Crypto API:
For more general key-wrapping support, where the application can select the algorithm and key-wrapping key, see #50.
The text was updated successfully, but these errors were encountered: