Skip to content
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

Openless PSA crypto APIs implementation #3547

Merged
merged 55 commits into from
Nov 20, 2020

Commits on Nov 9, 2020

  1. Split persistence and key id validation

    With key usage based on key identifiers and not
    key handles (openless APIs), volatile keys will
    also have a key identifier. Thus, isolate key
    identifier validation from key persistence
    validation to clarify that key identifiers
    are not specific to persistent keys.
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 9, 2020
    Configuration menu
    Copy the full SHA
    d2ed481 View commit details
    Browse the repository at this point in the history

Commits on Nov 10, 2020

  1. Add volatile key identifiers

    Volatile key identifiers are introduced in
    PSA Crypto API v1.0.0. They are returned by the APIs
    when importing or generating or deriving a volatile key.
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    2a99315 View commit details
    Browse the repository at this point in the history
  2. psa: slot mgmt: Don't use handles to loop through slot array

    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    98a54dd View commit details
    Browse the repository at this point in the history
  3. Introduce PSA_KEY_HANDLE_INIT macro

    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    91e9515 View commit details
    Browse the repository at this point in the history
  4. Introduce psa_key_handle_is_null inline function

    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    c26f8d4 View commit details
    Browse the repository at this point in the history
  5. Introduce psa_key_handle_equal inline function

    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    47a8561 View commit details
    Browse the repository at this point in the history
  6. Define handles as key identifiers

    Define psa_key_handle_t to be equal to
    mbedtls_svc_key_id_t. Make the handle of a persistent
    key be equal to its key identifier. For volatile keys,
    make the key handle equal to the volatile key
    identifier of the created volatile key.
    
    The unit tests are modified just to make them compile
    not to make them run successfully. They are fixed in
    the subsequent commits.
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    c4d1b51 View commit details
    Browse the repository at this point in the history
  7. tests: Fix invalid key identifier error code

    PSA Crypto API spec defines the error code for
    an invalid key identifier as PSA_ERROR_INVALID_HANDLE.
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    2d52eb2 View commit details
    Browse the repository at this point in the history
  8. tests: Fix error codes when using "invalid" handles

    As handles are now key identifiers, a handle may be
    valid now even if it does not refer to any key
    known to the library.
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    432e19c View commit details
    Browse the repository at this point in the history
  9. tests: Fix checks of volatile key identifier

    Volatile keys have now a volatile non-null key
    identifier.
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    4184107 View commit details
    Browse the repository at this point in the history
  10. tests: Fix persistent slot lifecycle tests

    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    e4f6d5c View commit details
    Browse the repository at this point in the history
  11. psa: Move from key handle to key identifier

    Move all the PSA crypto APIs using key handles
    to use key identifiers but psa_key_open() and
    psa_key_close(). This is done without modifying
    any test as key handles and key identifiers are
    now the same.
    
    Update the library modules using PSA crypto APIs
    to get rid of key handles.
    
    Programs and unit tests are updated to not use
    key handles in subsequent commits, not in this
    one.
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    cf56a0a View commit details
    Browse the repository at this point in the history
  12. Add psa_purge_key API

    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    277a85f View commit details
    Browse the repository at this point in the history
  13. State PSA_CRYPTO_KEY_ID_ENCODES_OWNER and USE_PSA_CRYPTO incompatibility

    Code under MBEDTLS_USE_PSA_CRYPTO define is PSA client
    code intended to use key identifiers of type psa_key_id_t.
    Thus the MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
    configuration option is incompatible with
    MBEDTLS_USE_PSA_CRYPTO.
    
    State this in config.h and check_config.h.
    
    As a consequence:
    . remove MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER from
      the full configuration, as MBEDTLS_USE_PSA_CRYPTO is
      part of it.
    
    . add a new component in all.sh to keep testing the
      library when MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
      is set.
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    c3623db View commit details
    Browse the repository at this point in the history
  14. Adapt programs to PSA openless APIs

    PSA and SSL programs are PSA clients thus should use
    psa_key_id_t as the type for key identifiers, not
    mbedtls_svc_key_id_t.
    
    As a consequence, PSA, ssl_server2 and ssl_client2
    programs cannot compile and must not be compiled if
    MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER is defined.
    Thus, add MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
    compilation guard to those programs.
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    adc2ff2 View commit details
    Browse the repository at this point in the history
  15. tests: Adapt PSA tests to openless APIs

    psa_key_handle_equal() is removed as not used
    anymore.
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    5425a21 View commit details
    Browse the repository at this point in the history
  16. tests: slot mgmt: Add purge checks in volatile key lifecycle test

    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    3930997 View commit details
    Browse the repository at this point in the history
  17. tests: slot mgmt: Rename ways of invalidating keys

    Rename ways of invalidating keys before introducing
    key purging tests because the "CLOSE_BY" prefix doesn't
    get on well with the purge operation.
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    e7e86cf View commit details
    Browse the repository at this point in the history
  18. tests: slot mgmt: Fix test data

    For persistent keys there were two successive
    INVALIDATE_BY_(CLOSING/DESTROYING) identical tests
    where the comments of the second test rather
    indicated that it should had been an
    INVALIDATE_BY_(CLOSING/DESTROYING)_WITH_SHUTDOWN test.
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    994b805 View commit details
    Browse the repository at this point in the history
  19. tests: slot mgmt: Add psa_purge_key testing

    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    f67aefe View commit details
    Browse the repository at this point in the history
  20. Forbid volatile key identifiers for non volatile keys

    Volatile key identifiers in the vendor range are
    reserved to volatile keys thus don't allow them
    for persistent keys when creating a key.
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    fc9c556 View commit details
    Browse the repository at this point in the history
  21. Merge search of loaded volatile and persistent keys

    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    97c8ad5 View commit details
    Browse the repository at this point in the history
  22. Fix close/purge of a key

    In case of persistent keys, do not load the key
    in a slot before to close/purge it.
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    5134519 View commit details
    Browse the repository at this point in the history
  23. Improve psa_key_start_creation description

    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    3c76a42 View commit details
    Browse the repository at this point in the history
  24. Add mbedtls_set_key_owner_id API

    Add the mbedtls_set_key_owner_id API,
    API specific to the MbedTLS PSA implementation.
    The API allows to define the owner of
    volatile keys.
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    6b5ff53 View commit details
    Browse the repository at this point in the history
  25. Add tests checking owner of volatile keys

    When key identifiers encode key owner, add tests
    checking that:
    . the key owner of an imported volatile key is
      the one specified.
    . a key identifier of a volatile key with a valid
      PSA key identifier but the wrong owner is
      rejected.
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    390f607 View commit details
    Browse the repository at this point in the history
  26. tests: psa: Use PSA_KEY_LIFETIME_IS_VOLATILE where it should

    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    f1ff9a8 View commit details
    Browse the repository at this point in the history
  27. psa: Fix references to macros in comments

    This commit tries to fix the usage of #MACRO_NAME
    to reference macros in comments.
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    9678355 View commit details
    Browse the repository at this point in the history
  28. psa: Improve key creation documentation

    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    4067d1c View commit details
    Browse the repository at this point in the history
  29. psa: Fix tests/handling of lifetime incompatible with location

    The lifetime of key attributes now encodes whether a key is
    volatile/persistent or not AND its location.
    Fix PSA code where the fact that the lifetime encodes
    the key location was not taken into account properly.
    
    Fix the impacted tests and add two non regression tests.
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    d98059d View commit details
    Browse the repository at this point in the history
  30. Add key id check when creating a volatile key

    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    65f38a3 View commit details
    Browse the repository at this point in the history
  31. psa: Forbid creation/registration of keys in vendor range

    The identifier of keys created/registred should be in
    the application range.
    
    This is by spec for key creation.
    This may change for registered key.
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    54b9008 View commit details
    Browse the repository at this point in the history
  32. psa: mgmt: Add key slot access counter

    Add key slot access counter to be able to
    state if a key slot containing the description
    of a permanent key can be reset or reset
    and re-used.
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    f95a2b1 View commit details
    Browse the repository at this point in the history
  33. psa: slot mgmt: Add unaccessed slots counter in stats

    Add a counter of unaccessed slots and use it
    in tests to check that at the end of PSA tests
    all key slot are unaccessed.
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    0c3752a View commit details
    Browse the repository at this point in the history
  34. psa: Add access counter check in slot wipe

    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    ddd3d05 View commit details
    Browse the repository at this point in the history
  35. psa: Do not reset a key slot under access

    When psa_close/destroy/purge_key is called, do not
    reset a key slot containing the description
    of a persistent key if it is currently accessed.
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    f291111 View commit details
    Browse the repository at this point in the history
  36. psa: mgmt: Add key slot reuse

    When looking for an empty key slot to store
    the description of a key, if all key slots
    are in use, reuse the first encountered
    and unaccessed key slot containing the
    description of a permanent key.
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    a5b894f View commit details
    Browse the repository at this point in the history

Commits on Nov 11, 2020

  1. Fix several typos

    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 11, 2020
    Configuration menu
    Copy the full SHA
    77c89f5 View commit details
    Browse the repository at this point in the history
  2. Prefer persistent over permanent

    For consistency across the code base, prefer
    persistent over permanent to qualify a key
    stored in persistent storage.
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 11, 2020
    Configuration menu
    Copy the full SHA
    19daca9 View commit details
    Browse the repository at this point in the history

Commits on Nov 13, 2020

  1. Miscellaneous documentation improvements

    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 13, 2020
    Configuration menu
    Copy the full SHA
    7587ae4 View commit details
    Browse the repository at this point in the history
  2. Miscellaneous coding style fixes

    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 13, 2020
    Configuration menu
    Copy the full SHA
    7d54f66 View commit details
    Browse the repository at this point in the history

Commits on Nov 19, 2020

  1. psa: slot mgmt: Improve psa_search_key_in_slots implementation

    In case of a volatile key identifier, no need to check first
    the validity of the key identifier, a volatile key identifier
    is valid.
    
    Move to a forward search for non-volatile key identifiers as
    now key slots with small index are allocated first by
    psa_get_empty_key_slot().
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 19, 2020
    Configuration menu
    Copy the full SHA
    f473d8b View commit details
    Browse the repository at this point in the history
  2. psa: slot mgmt: Simplify psa_validate_key_id

    Special handling of volatile key identifiers is not
    needed eventually, they can be handled just as
    key identifier in the vendor range.
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 19, 2020
    Configuration menu
    Copy the full SHA
    cbd7bea View commit details
    Browse the repository at this point in the history
  3. tests: psa crypto: Fix lifetime_is_secure_element()

    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 19, 2020
    Configuration menu
    Copy the full SHA
    9e12f8f View commit details
    Browse the repository at this point in the history
  4. programs: ssl: Fix printf parameter type cast

    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 19, 2020
    Configuration menu
    Copy the full SHA
    c985114 View commit details
    Browse the repository at this point in the history
  5. psa: Remove error message output

    Remove error message output in case of
    unexpected access counter as
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 19, 2020
    Configuration menu
    Copy the full SHA
    4640c15 View commit details
    Browse the repository at this point in the history
  6. psa: slot mgmt: Add access counter overflow check

    It adds a bit a code for not much but that way we
    are such that a count overflow cannot occur.
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 19, 2020
    Configuration menu
    Copy the full SHA
    cbf6a1d View commit details
    Browse the repository at this point in the history
  7. psa: Decrement slot access count when finalizing key creation

    Decrement the slot access count in psa_finish_key_creation()
    when the finalization succeeds instead of in functions calling
    psa_finish_key_creation(). That way the decrementation cannot
    be forgotten and it reduces the code size.
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 19, 2020
    Configuration menu
    Copy the full SHA
    5097294 View commit details
    Browse the repository at this point in the history
  8. psa: Move key identifier return to psa_finish_key_creation()

    Move the return of the identifier of a created key from
    psa_start_key_creation() to psa_finish_key_creation().
    That way in case of creation error, it is less likely to
    return the identifier that was temporarily assigned to
    the key while trying to create it.
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 19, 2020
    Configuration menu
    Copy the full SHA
    81709fc View commit details
    Browse the repository at this point in the history
  9. tests: slot mgmt: Improve key_slot_eviction_to_import_new_key test

    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 19, 2020
    Configuration menu
    Copy the full SHA
    ab79bd2 View commit details
    Browse the repository at this point in the history
  10. psa: Rename functions to get a key slot

    Rename functions to get a key slot:
    . to make their naming more consistent
    . to emphasize that those functions set a lock on the
      key slot they return to protect it from being wiped
      out and re-used while some part of the library
      is accessing it.
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 19, 2020
    Configuration menu
    Copy the full SHA
    5c52292 View commit details
    Browse the repository at this point in the history
  11. psa stats: Count locked slots instead of unlocked ones

    Count locked slots and not unlocked ones to
    align with the other statistics counters.
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 19, 2020
    Configuration menu
    Copy the full SHA
    1ad1eee View commit details
    Browse the repository at this point in the history
  12. Add change log

    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 19, 2020
    Configuration menu
    Copy the full SHA
    a3d9dac View commit details
    Browse the repository at this point in the history

Commits on Nov 20, 2020

  1. Improve/fix documentation

    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 20, 2020
    Configuration menu
    Copy the full SHA
    1d12d87 View commit details
    Browse the repository at this point in the history
  2. tests: psa: Reset key attributes where needed

    After a call to psa_get_key_attributes() to retrieve
    the attributes of a key into a psa_key_attributes_t
    structure, a call to psa_reset_key_attributes() is
    mandated to free the resources that may be
    referenced by the psa_key_attributes_t structure.
    Not calling psa_reset_key_attributes() may result in
    a memory leak.
    
    When a test function calls psa_get_key_parameters()
    the associated key attributes are systematically
    reset in the clean-up part of the function with a
    comment to emphasize the need for the reset and make
    it more visible.
    
    Signed-off-by: Ronald Cron <ronald.cron@arm.com>
    ronald-cron-arm committed Nov 20, 2020
    Configuration menu
    Copy the full SHA
    3a4f0e3 View commit details
    Browse the repository at this point in the history