Skip to content

Conversation

@gilles-peskine-arm
Copy link
Collaborator

@gilles-peskine-arm gilles-peskine-arm commented Feb 5, 2020

After some internal discussion (private link), here's a proposal for how to assign lifetimes.

This proposal is backward-compatible with the current values for volatile keys (0) and persistent keys (1). Platforms with a secure element (i.e. a cryptoprocessor that can process keys which are not accessible to the PSA crypto core) should use the lifetime 0x1ff (whether the key material is stored inside the secure element, or in generic PSA storage in a form wrapped by the secure element).

This pull request defines the lifetime structure, but does not yet implement any new feature. A future pull request will adapt the (currently experimental) secure element support code accordingly.

We intend to include the types and values defined in this pull request with the same semantics in an upcoming release of the PSA Cryptography API specification.

@athoelke @MarcusJGStreets

* Lower 8 bits: persistence level
    * 0: volatile
    * 1: persistent (default)
    * 2-127: persistent (reserved for future PSA specifications)
    * 128-254: persistent (reserved for vendors)
    * 255: read-only
* Upper 24 bits: location indicator
    * 0: built-in
    * 1: primary secure element
    * 2-0x7fffff: reserved for future PSA specifications
    * 0x800000-0xffffff: vendor-specific
@gilles-peskine-arm gilles-peskine-arm added enhancement New feature or request needs: review The pull request is ready for review. This generally means that it has no known issues. api-spec Issue or PR about the PSA specifications labels Feb 5, 2020
Copy link
Collaborator

@yanesca yanesca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a couple of suggestions for improvement and a question.

#define PSA_KEY_LIFETIME_PERSISTENT ((psa_key_lifetime_t)0x00000001)

#define PSA_KEY_LIFETIME_PERSISTENCE_VOLATILE ((psa_key_lifetime_persistence_t)0x00)
#define PSA_KEY_LIFETIME_PERSISTENCE_PRIMARY ((psa_key_lifetime_persistence_t)0x01)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a location with the same value that we describe as the "primary secure element". This made me confused at first about the purpose of this constant.

Suggested change
#define PSA_KEY_LIFETIME_PERSISTENCE_PRIMARY ((psa_key_lifetime_persistence_t)0x01)
#define PSA_KEY_LIFETIME_PERSISTENCE_PERSISTENT ((psa_key_lifetime_persistence_t)0x01)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I don't like PERSISTENCE_PRIMARY either. But PERSISTENCE_PERSISTENT is weird and misleading: other PERSISTENT_xxx values are also persistent. And I don't like PERSISTENCE_DEFAULT either (for example, when you create a key, the persistence defaults to VOLATILE, not to DEFAULT). Does anyone have a better suggestion?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well it might be a little bit overkill, but how about PSA_KEY_LIFETIME_PERSISTENCE_PERSISTENT_DEFAULT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another candidate perhaps: PSA_KEY_LIFETIME_PERSISTENCE_STANDARD?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Standard works for me

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like “standard”: which standard? I went with “default”.

* the application instance terminates. In particular, a volatile key
* is automatically on a power reset of the device.
*
* A key that is not volatile is persistent. Persistent keys are
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that there can't be a lifetime for keys that survives the termination of the application but not a power reset. I can hardly imagine a use case where that would be needed, I just would like to confirm that this is what we want?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seem sensible changes.
I am still thinking about "volatile" keys that last beyond the life of the calling partition.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lifetime that survives the instance of the calling application but not a power reset could exist, but:

  • This is an imprecise definition. If the application is running in a virtual machine, is the scope of the power reset the VM or its physical host?
  • How does another instance of the application refer to the same key? It would need to use a key identifier, so this would be more like a persistent key from the application's perspective.
  • Yes, it's possible. I've worked with a system that basically had this third intermediate scope (volatile-to-application-instance, volatile-to-device, persistent). But AFAIK this intermediate scope was never used outside of the test suite. So I'm with “can hardly imagine a use case”.
  • If an implementation really wants this feature, it can provide it through the vendor range for persistence levels.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that covers what I meant by "thinking".
In general PSA has been writtien for M-class with a fixed set of secure partitions all of which active - so there really is no concept of application life time except reboot.

However, when we extend to Cortex A we will need to deal with other life times - but I believe that can be left to the next release.

@yanesca yanesca added needs: work The pull request needs rework before it can be merged. and removed needs: review The pull request is ready for review. This generally means that it has no known issues. labels Feb 6, 2020
* interfaces operate on lifetimes (type ::psa_key_lifetime_t) which
* encode the persistence as the lower 8 bits of a 32-bit value.
*/
typedef uint8_t psa_key_lifetime_persistence_t;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the lifetime scoping in this identifier name required?

At present psa_key_persistence_t (and likewise for psa_key_location_t) would be clear and unambiguous - the only downside is that the name does not provide any hints that this is part of a psa_key_lifetime_t value.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to make the connection with lifetimes explicit.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thoughts I shortened the names.

* implementation-specific means such as a factory ROM engraving process.
* Note that keys that are read-only due to policy restrictions
* rather than due to physical limitations should not have this
* persistence levels.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhap just for internal clarity, if not for the public documentation: is this lifetime appropriate for keys that have the same lifetime as the device identifier? - Some devices might be designed to support a factory process that erases the device reprograms it as a new device identity with new "read-only" keys.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the device identifier is set in stone, that's the corresponding lifetime. If the device identifier is rewritten on a factory reset, this corresponds to a different lifetime (which may be 1 or something else depending on what levels of “factory reset” exist).

(PSA_KEY_LIFETIME_GET_PERSISTENCE(lifetime) == \
PSA_KEY_LIFETIME_PERSISTENCE_VOLATILE)

#define PSA_KEY_LOCATION_BUILT_IN ((psa_key_lifetime_location_t)0x000000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we also want a PSA defined symbol for the specification allocated location 0x000001? Maybe PSA_KEY_LOCATION_SECURE_ELEMENT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far I consider this an implementation-specific definition, but I don't have a strong opinion about it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, unlike other imp-specific parts of the API, this one has a specified value, but not a specified symbol? A bit unusual in the documentation, but we don't provide handy spec-defined symbols for all of the [vendor] ranges in other value types either.

It's a bit like persistence == 1, which we can't find an ideal name for either, but really have to name because it is effectively used by PSA_KEY_LIFETIME_PERSISTENT.

(PSA_KEY_LIFETIME_GET_PERSISTENCE(lifetime) == \
PSA_KEY_LIFETIME_PERSISTENCE_VOLATILE)

#define PSA_KEY_LOCATION_BUILT_IN ((psa_key_lifetime_location_t)0x000000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These definitions do not have LIFETIME scoping term in the identifier. This should be added for consistency, or the lifetime/LIFETIME scope term should be removed from all of them (as described above).

PSA_KEY_LIFETIME_PERSISTENCE_VOLATILE)

#define PSA_KEY_LOCATION_BUILT_IN ((psa_key_lifetime_location_t)0x000000)
#define PSA_KEY_LOCATION_VENDOR_FLAG ((psa_key_lifetime_location_t)0x800000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other ranged values no longer have VENDOR_FLAG defintions - this will not appear in the PSA specification.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Like the other helper macros, these macros have no Doxygen, so they aren't intended to be included in the PSA specification.

@gilles-peskine-arm
Copy link
Collaborator Author

Since Mbed Crypto is no longer updated, I've rebased this pull request on top of Mbed TLS. To be continued at Mbed-TLS/mbedtls#3302

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-spec Issue or PR about the PSA specifications enhancement New feature or request needs: review The pull request is ready for review. This generally means that it has no known issues.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants