Modify PSA related error codes and types #55
No reviewers
Labels
No labels
api-spec
bug
CLA requested
CLA valid
compliance
DO NOT MERGE
duplicate
enhancement
feature branch
good first issue
HEADER FORMATTING ISSUE
help wanted
Information
invalid
Jira status: AWAITING REVIEW
Jira status: CLOSED
Jira status: DONE
Jira status: IN PROGRESS
Jira status: IN REVIEW
Jira status: OPEN
Jira status: REOPENED
Jira status: RESOLVED
mirrored
mirror internally
needs: backports
needs: ci
needs: design review
needs: preceding PR
needs: review
needs: work
notabug
open for community contribution
Product Backlog
question
ready for merge
security
stale
type: bug
type: enhancement
type: question
web pages
wontfix
writing
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-ARMmbed/mbed-crypto!55
Loading…
Reference in a new issue
No description provided.
Delete branch "david_its_ps_err_codes"
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?
PSA error codes and storage related types were changed in the PSA spec. So this PR:
psa_storage_*), as defined in the PSA spec.@ -70,3 +62,3 @@#define PSA_ERROR_NOT_SUPPORTED ((psa_status_t)2)#define PSA_ERROR_NOT_SUPPORTED ((psa_status_t)-134)/** The requested action is denied by a policy.The allocated_errors.h header file says this error is defined in error.h. Should we move it to a new error.h file? The header seems to expect certain errors coming from headers with a certain name.
CC @gilles-peskine-arm Are you aware of the expectations on PSA implementations here?
@ -150,3 +113,3 @@ret = psa_its_get_info( data_identifier, &data_identifier_info );if( ret == PSA_ITS_ERROR_UID_NOT_FOUND )if( ret == PSA_ERROR_DOES_NOT_EXIST )This commit appears to be mixing ITS type updates with error status updates. Could you please make the identifier update changes in a separate commit?
@ -70,3 +62,3 @@#define PSA_ERROR_NOT_SUPPORTED ((psa_status_t)2)#define PSA_ERROR_NOT_SUPPORTED ((psa_status_t)-134)/** The requested action is denied by a policy.We're standardizing
psa_status_tand a common set of status codes across PSA services, to be defined in a header filepsa/error.hthat all services provide and which Arm will manage centrally (so if you end up with several copies ofpsa/error.h, there's always a total order between versions and you can pick the most recent one). The publishing strategy is thaterror.hwill be distributed by every service that uses it. See internal discussions at https://github.com/ARMmbed/PSA-IPC-doc/issues/133 and https://github.com/ARMmbed/PSA-IPC-doc/pull/177@ -70,3 +62,3 @@#define PSA_ERROR_NOT_SUPPORTED ((psa_status_t)2)#define PSA_ERROR_NOT_SUPPORTED ((psa_status_t)-134)/** The requested action is denied by a policy.I'm wondering if this commit should then grab and add that error.h file instead, leaving only crypto.h specified errors in crypto.h.
The second commit in this PR can update the ITS types.
This is failing the psa_constant_names test and either this PR attempts to introduce a bug, or we need to adapt the psa_constant_names test to accommodate this PR's changes.
psa_status_tis defined twice).psa_constant_namesandtest_psa_constant_names.py: they don't fully support negative constants. This is signalled by CI, so we need to fix it. Fix available in https://github.com/ARMmbed/mbed-crypto/pull/56@ -40,25 +40,17 @@* @{This is a private link. Please do not include private links in published code or documentation.
@ -27,6 +27,7 @@#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_ITS_C)#include "psa/error.h"As long as
psa/crypto_types.h(included viapsa/crypto.h) definespsa_status_t, includingpsa/error.has well will cause a compilation error due to the duplicate definition ofpsa_status_t. We either need to make the definition ofpsa_status_tconditional inpsa/crypto_types.hor to start distributing an official version ofpsa/error.h.Will do (will also remove the private link). It's still not clear whether I should move all error codes to a new
error.hfile or keep them undercrypto_values.h@ -27,6 +27,7 @@#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_ITS_C)#include "psa/error.h"Not sure why this would fail the build. Type definitions in both files are the same, meaning that the compiler should not fail this duplication. I build it this way in mbed-os without issues.
Is this an empirical or a theoretical problem? I ask because I only added
psa/error.hto my current mbed-os PR, so if this is empirical, than where do you takepsa/error.hfrom?@ -27,6 +27,7 @@#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_ITS_C)#include "psa/error.h"Theoretical in this instance, but empirical from a previous version. We had to add guards around the definition of
psa_status_tso that it would only be defined in one place. You can have multiple#definefor the same macro as long as they expand to the same token sequence, but some compilers warn about it. You can't have multipletypedefstatements defining the same type name, even if the definitions are identical.In your build, what exactly does
psa/error.hcontain? Who's definingpsa_status_tand how do you avoid defining it twice?@Patater @gilles-peskine-arm Commits are now split to two: one for error codes, one for the change of ITS types to the generic types.
Error codes are still in
crypto_values.h, as it seems you're not sure whether you want to keep them there or move them into a new error.h file. It can be done later on I guess.All comments addressed except for the
psa_status_tduplication.@ -27,6 +27,7 @@#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_ITS_C)#include "psa/error.h"psa/error.his part of the PSA include directory. I'm adding it now to the parallel PR in mbed-os. Please note thatpsa_status_tis not a define but a typedef. As opposed to defines, compilers will not warn about duplicate typedefs as long as the referenced type is identical. In addition, as it's a typedef and not a define, one can't ask whether it's defined using#ifdef.@ -27,6 +27,7 @@#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_ITS_C)#include "psa/error.h"Duplicate definitions of a typedef are forbidden in C89 and C99. From N1256 (C99 TC3), §6.7 “Declarations”:
Clang does warn about it if you ask it to use C89 or C99.
Neither Clang nor GCC warn about it in non-picky mode, but I remember we've hard this error in at least one of the CC+CFLAGS combination we test in our CI, and we do aim to stick to standard C in Mbed TLS and Mbed Crypto.
@ -27,6 +27,7 @@#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_ITS_C)#include "psa/error.h"OK, understood (didn't go that far).
How do you suggest to resolve this? It's a bit of a pickle, as there's no
#ifdeffor typedefs. I could ask whetherPSA_SUCCESSis defined, assuming thatPSA_SUCCESSandpsa_status_tare both defined inpsa/error.h, but that just seems pretty awkward to me.@ -27,6 +27,7 @@#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_ITS_C)#include "psa/error.h"That's the hack we had for a long time, and getting rid of that hack was my motivation for requesting a unified
psa/error.h(https://github.com/ARMmbed/PSA-IPC-doc/issues/133) as the only place wherepsa_status_tis defined. Crypto is planning to switch from definingpsa_status_tincrypto_types.hto includingerror.has soon as version 1 oferror.hhas stabilized.@ -27,6 +27,7 @@#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_ITS_C)#include "psa/error.h"OK, will add this hack.
Added the handling of
psa_status_tduplication. All comments are addressed now.Code LGTM
I think the commit message for "Change ITS specific types to the more generic ones (defined in PSA spec)" needs some work, though.
How about the following, but after you fill in xxx with the version of the ITS spec this PR updates to?
Cool. Commit message modified in the spirit of your recommendation. Didn't see any change to the PSA spec version though, so left this one out.
Sorry for the nitpicking, but it looks like you forgot to mention
Also, please don't end commit messages with a
:or., as per our git commit style guideThanks
This ain't nitpicking, it was a mistake I made there. Fixed now.
@Patater Thanks for approving. Can you also approve PR #9708 in the mbed-os repo? It's the corresponding PR in mbed-os, including the same mbed-crypto changes.
The numerical values and double-definition guards are ok. Validated with a checkout of the private repository containing the PSA internal allocte error list at
../../PSA-IPC-docand runningThis pull request keeps some old names and gives them values that don't seem to come from anywhere. Having not-yet-renamed error codes is ok, but some errors are duplicated instead of renamed (
EMPTY_SLOTandDOES_NOT_EXIST,OCCUPIED_SLOTandALREADY_EXISTS), and some errors have values that may clash with values that others are using. Both problems aren't problems for the crypto library itself but they are problems for users of the crypto library.@ -92,23 +84,19 @@* buffer would succeed. However implementations may return thisPSA_ERROR_OCCUPIED_SLOTis to be renamed toPSA_ERROR_ALREADY_EXISTSfrom the base list.PSA_ERROR_EMPTY_SLOTis to be renamed toPSA_ERROR_DOES_NOT_EXISTfrom the base list.@ -285,3 +270,4 @@#define PSA_ERROR_INSUFFICIENT_DATA ((psa_status_t)-143)/** The key handle is not valid.*/PSA_ERROR_INSUFFICIENT_CAPACITYis to be renamed toPSA_ERROR_INSUFFICIENT_DATAfrom the base list.Thanks @gilles-peskine-arm. Wasn't sure about these error codes myself. Replaced them according to your suggestion.
Blocker: please update
psa_its_status_tandPSA_ITS_xxxintests/suites/test_suite_psa_crypto_entropy.functionas well. Make sure it's tested before merging this PR.While you're at it, please update the comment in
test_suite_psa_crypto.function.@ -155,3 +142,4 @@#define PSA_ERROR_INSUFFICIENT_STORAGE ((psa_status_t)-142)/** There was a communication failure inside the implementation.*The descriptions of
PSA_ERROR_ALREADY_EXISTS,PSA_ERROR_DOES_NOT_EXISTandPSA_ERROR_INSUFFICIENT_DATAneed work (grammaticality, specific meaning for crypto) but this is not a blocker, I can fix it later.@ -420,3 +420,3 @@uint8_t *public_key = NULL;size_t public_key_length;/* Return UNKNOWN_ERROR if something other than the final call to/* Return GENERIC_ERROR if something other than the final call toComment needs updating
@gilles-peskine-arm Pushed a fix according to your comments. Left the descriptions for the new error codes out (thought it would be better if an mbed crypto specialist would do that).
Looks fine.
Approved provided that this has been tested (including running
test_suite_psa_crypto_entropy) on Mbed OS in configurations with ITS with and without entropy injection. @Patater Is this tested on CI at the moment?Thanks for the approval.
As for the tests - I currently test it locally, but regarding CI, changes aren't currently tested yet. There's a pending PR in mbed-os, which includes these changes as well. This PR awaits your approval in order to start CI.
I'll copy the latest changes from here to there and then will appreciate your quick approval for it.Changes from here copied there - again temporarily, just in order to start moving the CI chains.No, otherwise we'd have seen a failure in CI.
@gilles-peskine-arm @Patater Sorry for nagging, but can you approve PR #9708 in mbed-os? The mbed-crypto part changes there are identical to the ones in this PR (they are all concentrated in the second commit). They will be discarded before that PR is merged.
Travis failure is DTLS 3d Proxy. Jenkins failure is FreeBSD timing test. Both are known issues.
Pre-merge test failed because this PR is not based on a version of development recent enough to have psa_constant_names that handles signed error codes (https://github.com/ARMmbed/mbed-crypto/pull/56).