Unsupported feature support #162
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!162
Loading…
Reference in a new issue
No description provided.
Delete branch "unsupported_feature"
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?
This PR adds support for
MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTEDin tests and applications.This supersedes the crypto part of https://github.com/ARMmbed/mbedtls/pull/2124
The CI failure is because the changes in
platform.hand inhelpers.functionrelated to inclusion ofplatform.hshould be merged to the TLs repository as well. (This is done in https://github.com/ARMmbed/mbedtls/pull/2124)I have rebased to resolved conflicts, fixed a bug in the tests, and added support to new tests
@ -960,15 +959,21 @@ int mbedtls_aria_self_test( int verbose )/* test ECB encryption */This seems a bit funny. What's the point of an ARIA self-test if even ECB isn't supported? I understand that mechanically we want to check for this error and skip, but I can't imagine a valid use case. No change requested here, just an odd observation.
I guess some hardware might not expose ECB, but may expose other modes.
We are adding a lot of branches to handle FEATURE_UNSUPPORTED from many places. How will we test this? Our code coverage is going to suffer a lot unless we come up with and write tests to hit each of these new branches. This can also help us find bugs if we don't properly handle FEATURE_UNSUPPORTED errors somewhere.
Suggest to put ASSERT on a new line and to enclose with {} explicitly, in case the macro ever goes multi-line this is easier to maintain
@ -550,1 +559,4 @@}return( ret );}Can these be or'd together like this? Do users use them as bitfields?
Should this be
(ret & MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED)ifretis a bitfield now?@ -107,15 +108,68 @@ typedef enum*Don't add this newline
@ -119,0 +139,4 @@** In case the returned error code is MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED,* the test is skipped.*Why not keep using
test_fail()andtest_skip()?Instead of deleting
test_fail, we could have it be a static function that callsset_test_result()Why does this need to change as part of "Unsupported feature support"
@ -960,15 +959,21 @@ int mbedtls_aria_self_test( int verbose )/* test ECB encryption */I agree, but we can't predict when a platform will return this error, and we allow returning this error for any crypto operation
ok
Probably. But I f remember correct, when I tested this, in this specific branch, it was always
MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED. But better to check the low leverl error@ -550,1 +559,4 @@}return( ret );}The Or here is basically the high level and the low level. If I remember correct, the
MBEDTLS_ERR_PK_INVALID_PUBKEYis still used in caller functions@ -107,15 +108,68 @@ typedef enum*ok
@ -119,0 +139,4 @@** In case the returned error code is MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED,* the test is skipped.*in order not to duplicate code.
I believe this came from this comment
It doesn't but this bug fix was discovered as part of this PR, so I put it as a seperate commit.
@ -960,15 +959,21 @@ int mbedtls_aria_self_test( int verbose )/* test ECB encryption */I agree, but as mentioned, since we allow this eror to be returned in every function, I don't see another option.
My suggestion was to have "dummy targets" that will return this error in different functions
OK
initially
set_test_result()was static, but this caused compilation warnings, as declared functions that are not used, in modules that are configured out. The linker probably doesn't remove static functions.In addition, since I thought putting one single function would make it cleaner
@ -960,15 +959,21 @@ int mbedtls_aria_self_test( int verbose )/* test ECB encryption */Yes, we need dummy targets (more commonly known as test mocks) in order to complete this feature.
Needs to pass CI
I am not sure this is needed. The low level driver could return
MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED, which in this case it is returned frompk_get_ecpubkey(). In this check, if it is unsupported, we modify the code toMBEDTLS_ERR_PK_KEY_INVALID_FORMAT | MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTEDThis needs some documentation to explain how to write an alternative implementation that doesn't implement everything. Preferably in Mbed Crypto and not in a knowledge base article that languishes unpublished for countless months.
There are incompatible changes: some functions now return different error codes. This needs to be clearly explained in release notes. We currently don't have a changelog for Mbed Crypto, which is a pity.
I haven't reviewed the self-test changes (commit "Skip self tests if feature unsupported"). That's a lot of new boilerplate code. Strongly consider defining at least a helper macro in
platform.h.@ -960,15 +959,21 @@ int mbedtls_aria_self_test( int verbose )/* test ECB encryption */A platform could support a cipher in only one direction. This is most common in the encrypt direction, which is all you need for many modern AEAD modes (e.g. CCM, GCM). This could also be in the decrypt direction only for an accelerator that's only ever meant for CBC decryption, but that's a lot rarer.
@ -550,0 +556,4 @@else{ret = MBEDTLS_ERR_PK_INVALID_PUBKEY;}This block of code is repeated. Please make an auxiliary function.
I'm a bit lost. When would a function from the
rsamodule returnMBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTEDvsMBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED | MBEDTLS_ERR_RSA_xxx?@ -550,1 +559,4 @@}return( ret );}In principle, yes: an error code from a “high-level” module of Mbed TLS can be either a high-level error code, or a bitwise-or of a high-level error code and a low-level error code. See
error.h.In practice, I've seen bugs before from code expecting a high-level error code and getting one bitwise-ored with a low-level error code. So I wouldn't be surprised if this broke some existing code. We need to document this change clearly and in a way that people will find. This used to be reasonable code (abbreviated), but no longer is:
Cosmetic: “Feature not supported. Skipping.”
@ -420,9 +475,26 @@ int main( int argc, char *argv[] ){mbedtls_des_context des;mbedtls_des_init( &des );There's a lot of boilerplate here. Please make an auxiliary function, maybe with some wrapper macros.
Breaking here leaves
ecdsaunfreed. I think it's high time to split this code into auxiliary functions, and react to errors withgoto exit.@ -107,15 +108,68 @@ typedef enum*Grammar is mistake and I'm not even sure what you were trying to say.
Please document when this function jumps (as is done for
TEST_ASSERT).The function would have to be non-
static.This has nothing to do with the linker. It's because we compile with
-Wunused-function.We should think of putting such functions into a separate
.cfile — https://github.com/ARMmbed/mbed-crypto/issues/250.There can be reasons to skip a test other than “Feature not supported by the platform”.
@ -205,7 +211,8 @@ void aes_crypt_xts_size( int size, int retval )/* Valid pointers are passed for builds with MBEDTLS_CHECK_PARAMS, as* otherwise we wouldn't get to the size check we're interested in. */Minor:
exit: return;is not necessary in test functions (the test code generator script adds it) and we traditionally don't include it.The commit "Adjust symmetric tests to TEST_ASSERT_RET" does not do that at all. Please fix the commit description. Furthermore that commit does several unrelated things, so it should be split.
@ -1062,3 +1057,1 @@TEST_ASSERT( mbedtls_ecp_check_pubkey( &key.grp, &key.Q ) == 0 );TEST_ASSERT( mbedtls_ecp_check_privkey( &key.grp, &key.d ) == 0 );TEST_ASSERT_RET( mbedtls_ecp_gen_key( id, &key, &rnd_pseudo_rand,Why have these two lines been removed? It doesn't seem to have anything to do with "Adjust pk tests to TEST_ASSERT_RET".
Valid/invalid parameter tests should never reach an alt implementation, should they? The rejection should happen in the pk layer. So they should never return
FEATURE_UNSUPPORTED, so the code should keep usingTEST_ASSERTand notTEST_ASSERT_RET.All the failed CI tests are in the tls testing
Which means if we merge this, TLS tests will start failing when they update their submodule. The TLS tests should be passing before merge, or we need to understand how to make them pass again when the submodule is updated.
@Patater
I guess https://github.com/ARMmbed/mbedtls/pull/2124 should be merged before this PR then, updating the TLS PR with this branch as the submodule
@ -420,9 +475,26 @@ int main( int argc, char *argv[] ){mbedtls_des_context des;mbedtls_des_init( &des );It's done in https://github.com/ARMmbed/mbedtls/pull/2124 . Should I cherry-pick the changes there, or will it be merged to this repository?
@ -1062,3 +1057,1 @@TEST_ASSERT( mbedtls_ecp_check_pubkey( &key.grp, &key.Q ) == 0 );TEST_ASSERT( mbedtls_ecp_check_privkey( &key.grp, &key.d ) == 0 );TEST_ASSERT_RET( mbedtls_ecp_gen_key( id, &key, &rnd_pseudo_rand,Probably rebase error. I'll add them
Since now the CI in https://github.com/ARMmbed/mbedtls/pull/2124 pass, I believe that once that PR will be merged, the TLS tests owuld pass here as well
@ -420,9 +475,26 @@ int main( int argc, char *argv[] ){mbedtls_des_context des;mbedtls_des_init( &des );Please don't introduce new code that would change when https://github.com/ARMmbed/mbedtls/pull/2124 finds its way into Mbed Crypto. Make the same changes to
helpers.functionhere.I agree that for the PK layer the rejection should be in the pk layer, so perhaps no need for
TEST_ASSERT_REThere, but in general, valid\invalid parameter tests should reach an alt implementation.@ -550,0 +556,4 @@else{ret = MBEDTLS_ERR_PK_INVALID_PUBKEY;}Why would there be two low level errors? I don't see a place where
MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED | MBEDTLS_ERR_RSA_xxxis returned.The previous behavior was returning
MBEDTLS_ERR_PK_INVALID_PUBKEYfor any failure, now, in case ofMBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTEDreturned by the rsa module, we still returnMBEDTLS_ERR_PK_INVALID_PUBKEYbut we also add the low levelMBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTEDNo it won't. THe break is done within the loop inside
TIME_PUBLICmacro., going to next line in this code, which frees the context@ -107,15 +108,68 @@ typedef enum*Actually it's a rebase error, I'll fix
Relabeling as "needs: work" because there are merge conflicts. Let's arrange a time when we're available for review soon after this has been rebased, or agree to include a merge commit.
Rebase please, early and often. Each rebase individually will be easier than a giant rebase later. Yes, we don't have a way to view diffs between previous versions of your patchset easily, but that's a GitHub limitation and only an inconvenience during review. History is easier to work with when we don't have upstream to downstream merge commits in short-term branches, the sorts PRs are from, as that e.g. breaks
--first-parentfrom being useful, among other things. Let's not inconvenience folks using the permanent record for the short term sake of review convenience.All the failed tests are due to missing declaration of
MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED. only on Mbed builds, probably because this definition is in a header file that wasn't imported yet to Mbed OSMbed Crypto has been merged back into Mbed TLS. Due to the nature of this pull request, it does not make sense to apply it to Mbed Crypto separately. Please bring these changes back into https://github.com/ARMmbed/mbedtls/pull/2124 .
Pull request closed