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

Implemented a test driver for opaque signatures without storage as defined in issue #3343. #3526

Closed
wants to merge 13 commits into from

Conversation

kjeir
Copy link

@kjeir kjeir commented Jul 29, 2020

Description

Implemented a test driver for opaque signatures without storage.
The test driver supports key import, key generation, public key export and sign/verify hash. A test suite validates the functionality.

Status

READY

Requires Backporting

NO

Migrations

NO

Todos

  • Tests
  • Documentation

Steps to test or reproduce

Added test suite test_suite_opaque_test_driver, all.sh updated with new component test_opaque_test_driver.

@kjeir
Copy link
Author

kjeir commented Jul 29, 2020

Requesting review from @gilles-peskine-arm @ronald-cron-arm

@danh-arm danh-arm requested a review from ronald-cron-arm July 30, 2020 10:07
Copy link
Contributor

@ronald-cron-arm ronald-cron-arm left a comment

Choose a reason for hiding this comment

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

Just a doubt to start with.

if( status != PSA_SUCCESS )
return( status );

status = psa_import_key( attributes,
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you test this when this driver is spliced to the PSA APIs? I haven't looked at it thoroughly but I would expect this call to fail as it imports a key that has already been imported. What am I missing?

Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

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

At one point I thought that the objective of this pull request was to write a driver that performs negative testing as well as positive testing on the driver dispatch code. Then I realized that it was too early for that and negative testing is out of scope for now. I indicated in those comments that I'm leaving them up only for future reference, not as requested changes here.

/** Convert an mbed TLS error code to a PSA error code
*
* \note This function is provided solely for the convenience of
* Mbed TLS and may be removed at any time without notice.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer to avoid cluttering a public header with functions that are only used in tests. Given that this is a preexisting issue, it's ok to add this function here. But we should make a follow-up that creates a separate header, possibly in library.

*/

/*
* Copyright (C) 2020, ARM Limited, All Rights Reserved
Copy link
Contributor

Choose a reason for hiding this comment

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

The copyright notice format has changed. Please copy from a file in the current development branch.

@@ -722,6 +722,11 @@ component_check_doxygen_warnings () {
#### Build and test many configurations and targets
################################################################

component_test_opaque_test_driver () {
msg "build+test: Opaque test driver test" # ~ 40s
make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_OPAQUE_TEST_DRIVER_C' test
Copy link
Contributor

Choose a reason for hiding this comment

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

We should build the sample programs as well, and enable ASan(+UBSan).

Suggested change
make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_OPAQUE_TEST_DRIVER_C' test
make CC=gcc CFLAGS="-Werror -Wall -Wextra -DMBEDTLS_OPAQUE_TEST_DRIVER_C $ASAN_CFLAGS "LDFLAGS="$ASAN_CFLAGS"
make test

#include "test/random.h"
#include "mbedtls/error.h"
#include <string.h>
#include <ctype.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

We currently don't use ctype.h and I'd prefer not to add a dependency on it. For this test, you could do something like ^ 42 on every byte.

char c;
while( len-- )
{
c = (char) *in;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is wrong on platforms where char is signed and uses sign-magnitude representation. Not that such platforms are likely, but in principle we do support them, and this might trip static analyzers.

Comment on lines +104 to +116
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
* The size of the \p out data buffer is too small.
Copy link
Contributor

Choose a reason for hiding this comment

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

A driver import entry point shouldn't return BUFFER_TOO_SMALL. If the context is smaller than expected, that indicates a bug in the core, and the driver should convey that.

/* Check validity of parameter set. */
TEST_ASSERT( PSA_SUCCESS == opaque_test_driver_export_public_key(
&attr,
(uint8_t *) "OPQTDKHEADERHello world 1234",
Copy link
Contributor

Choose a reason for hiding this comment

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

Why suddenly start to hard-code strings here? Please define and use a const uint8_t[], and use sizeof rather than hard-code its size.

27,
&out_key_len ) );

/* Check validity of parameter set. */
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand what this comment means.

}
/* END_CASE */

/* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
Copy link
Contributor

Choose a reason for hiding this comment

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

depends_on:MBEDTLS_CHECK_PARAMS has no effect on PSA APIs, only on traditional Mbed TLS APIs. (It was added because traditional APIs didn't perform certain checks, but the PSA code either performs those checks or has an interface that makes them moot.) This test function is not useful.

Comment on lines 603 to 605
TEST_ASSERT( sign_size != 0 );
TEST_ASSERT( sign_size <= PSA_SIGNATURE_MAX_SIZE );
TEST_ASSERT( sign_size <= OPQ_BUFSIZE );
Copy link
Contributor

Choose a reason for hiding this comment

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

This is testing the PSA_SIGN_OUTPUT_SIZE macro, which is not an objective of this test suite.

@stevew817
Copy link
Contributor

For reference, @kjeir is currently on vacation and moving to a different position, meaning I will take over the work. Thanks for the early feedback. Do you want to continue driving this PR to completion (meaning I need to wait for @kjeir to give me permission on his fork), or should this one be closed and followed up with a new PR from my fork?

@gilles-peskine-arm
Copy link
Contributor

@stevew817 It's usually more convenient to keep the same PR in order to keep track of what's been reviewed and what comments have been resolved, but that's not a blocker. And if you rebase the code, keeping the same PR loses most of its advantage. So feel free to close this PR and open a new one.

@ronald-cron-arm
Copy link
Contributor

With #3501, #3526 and #3605 PRs we have started developing two transparent test drivers and two opaque test drivers in parallel. As we go along in adding support for other driver APIs in psa_crypto.c and psa_crypto_driver_wrappers.c, it doesn't seem possible giving the time constraints to keep developing both. I see momentum in #3501 way of doing things with #3644 adding some support for ciphers. Furthermore, the testing in #3501 is the testing we definitely we need right now (exercising the test drivers and their interactions with psa_crypto.c through calls to the PSA APIs) whereas the testing in #3526 and #3605 (direct calls to the test driver APIs) is not something we need right now. For all those reasons, it would make sense to me to move the opaque test driver entry points provided by this PR to the way things are done in #3501 regarding code organization and testing. @stevew817 and @kjeir what do you think about that?

@carlaageamundsen
Copy link

@gilles-peskine-arm @ronald-cron-arm I updated this PR given your comments and now we see "Pre Test Checks failed" and "This commit cannot be built" but I am not able to see the Details on jenkins-internal.mbed.com. How should I go about to handle these issues?
NOTE: I have not rebased yet. I should probably do so

kjelleandersen and others added 8 commits September 9, 2020 14:18
The test driver supports key import, key generation, public key export and
sign/verify hash. A test suite validates the functionality.

Signed-off-by: Kjell Eirik Andersen <kjell.andersen@silabs.com>
Signed-off-by: Carl Aage Amundsen <Carl.Amundsen@silabs.com>
…order to avoid cluttering a public header.

Signed-off-by: Carl Aage Amundsen <Carl.Amundsen@silabs.com>
…ell, and enable ASan(+UBSan).

Signed-off-by: Carl Aage Amundsen <Carl.Amundsen@silabs.com>
Signed-off-by: Carl Aage Amundsen <Carl.Amundsen@silabs.com>
…elated macros. Replace TEST_ASSERT with PSA_ASSERT and TEST_EQUAL.

Signed-off-by: Carl Aage Amundsen <Carl.Amundsen@silabs.com>
Signed-off-by: Carl Aage Amundsen <Carl.Amundsen@silabs.com>
…e of PSA Crypto API in opaque_test_driver_sign_hash() and opaque_test_driver_verify_hash() which can not be used as is when lifetime support is added.

Signed-off-by: Carl Aage Amundsen <Carl.Amundsen@silabs.com>
Signed-off-by: Carl Aage Amundsen <Carl.Amundsen@silabs.com>
…tests.

Signed-off-by: Carl Aage Amundsen <Carl.Amundsen@silabs.com>
Signed-off-by: Carl Aage Amundsen <Carl.Amundsen@silabs.com>
…lace 'OPQ_BUFSIZE + ...' with sizeof().

Signed-off-by: Carl Aage Amundsen <Carl.Amundsen@silabs.com>
@gilles-peskine-arm
Copy link
Contributor

@carlaageamundsen The previous run of the pr-merge job failed due to the merge conflict. If “PR-NNNN-merge Pre Test Checks” fails, that's the most likely reason. Now that you've rebased, Jenkins is running. Note that Travis has reported a build failure, you need to tweak something because of the change of where mbedtls_to_psa_error is defined.

…and use the one in psa_crypto.c which has become global.

Signed-off-by: Carl Aage Amundsen <Carl.Amundsen@silabs.com>
@carlaageamundsen
Copy link

@gilles-peskine-arm I removed the local copy of mbedtls_to_psa_error() and use the one in psa_crypto.c which is now global. However there is still some error (see below) indicating issue in all.sh which I have not touched for a while. Do you have any ideas?

https://travis-ci.org/github/ARMmbed/mbedtls/jobs/725825258
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
FAILED: 1
check_generated_files: Check: freshness of generated source files: tests/scripts/check-generated-files.sh -> 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
The command "tests/scripts/all.sh -k 'check_*'" exited with 1.

@gilles-peskine-arm
Copy link
Contributor

Look through the logs for where that component failed:

^^^^check_generated_files: Check: freshness of generated source files: tests/scripts/check-generated-files.sh -> 1^^^^

And look backwards to see why it failed. Here it tells you:

'visualc/VS2010/mbedTLS.vcxproj' was either modified or deleted by 'scripts/generate_visualc_files.pl'

That's because you added a file in tests/src. But actually opaque_test_driver.c should go in tests/src/drivers and that doesn't require updating the VS project.

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

Successfully merging this pull request may close these issues.

Write a test driver for opaque signatures without storage
9 participants