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

PSA storage format: exercise keys (2.26) #4444

Conversation

gilles-peskine-arm
Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm commented Apr 29, 2021

  • Generate storage test cases for keys with algorithm policies that cover all compatible algorithms.
  • Generate operation setup failure test cases for not-supported algorithms, algorithms that are invalid for the operation, and key types that are incompatible with the algorithm and operation.

Abandonned. The work goes on in #5635 and #5644.

@gilles-peskine-arm gilles-peskine-arm added enhancement mbed TLS team needs-ci Needs to pass CI tests needs-preceding-pr Requires another PR to be merged first component-psa PSA keystore/dispatch layer (storage, drivers, …) labels Apr 29, 2021
The new test suite psa_crypto_op_fail is intended for systematically
generated test cases that ensure that cryptographic operations with
invalid parameters fail as expected. I intend invalid parameters to
cover things like an invalid algorithm, an algorithm that is
incompatible with the operation, a key type that is incompatible with
the algorithm, etc.

This commit just creates the infrastructure. Subsequent commits will
add data generation and test code.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Test that hash operation functions fail when given a hash algorithm
that is not supported or an algorithm that is not a hash.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
When TEST_EQUAL fails, show the two numerical values in the test log (only
with host_test). The values are printed in hexa and signed decimal.

The arguments of TEST_EQUAL must now be integers, not pointers or floats.
The current implementation requires them to fit in unsigned long long
Signed values no larger than long long will work too. The implementation
uses unsigned long long rather than uintmax_t to reduce portability
concerns. The snprintf function must support "%llx" and "%lld".

For this purpose, add room for two lines of text to the mbedtls_test_info
structure. This adds 154 bytes of global data.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Determine the category of operations supported by an algorithm based
on its name.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Determine key types that are compatible with an algorithm based on
their names.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
@gilles-peskine-arm gilles-peskine-arm force-pushed the psa-storage-format-test-exercise branch from 761af30 to 55026d1 Compare April 29, 2021 22:07
@gilles-peskine-arm gilles-peskine-arm changed the base branch from development to dev/gilles-peskine-arm/psa-storage-format-test-algorithms April 29, 2021 22:08
The new test suite test_suite_psa_crypto_op_fail runs a large number
of automatically generated test cases which attempt to perform a
one-shot operation or to set up a multi-part operation with invalid
parameters. The following cases are fully covered (based on the
enumeration of valid algorithms and key types):
* An algorithm is not supported.
* The key type is not compatible with the algorithm (for operations
  that use a key).
* The algorithm is not compatible for the operation.

Some test functions allow the library to return
PSA_ERROR_NOT_SUPPORTED where the test code generator expects
PSA_ERROR_INVALID_ARGUMENT or vice versa.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
PSA_ALG_KEY_AGREEMENT(..., kdf) is a valid key derivation algorithm
when kdf is one.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
No behavior change.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Otherwise the systematically generated algorithm-not-supported tests
complain when they try to start an operation and succeed.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
…t supported

Otherwise the systematically generated algorithm-not-supported tests
complain when they try to start an operation and succeed.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
In the generated storage format test cases, cover all supported
algorithms for each key type. The test code already takes care of
exercising the key after loading if it has a nonzero algorithm policy.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
psa_verify_hash() on an RSA signature returns
PSA_ERROR_INVALID_SIGNATURE if the signature size does not match the
key size when RSA keys are supported, regardless of whether the
particular signature algorithm is supported. This is ok, but distracts
from the systematic testing of not-supported cases. So pass a
potential signature of the correct size.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>

If alg is not None, this key allows it.
"""
usage_flags = 'PSA_KEY_USAGE_EXPORT'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we're generating keys with only EXPORT allowed, TEST_FLAG_EXERCISE only causes keys to be exported, it doesn't cause cryptographic operations. I also need to determine which usage flags to allow here.

@gilles-peskine-arm gilles-peskine-arm added size-m Estimated task size: medium (~1w) and removed needs-preceding-pr Requires another PR to be merged first labels Oct 8, 2021
@gilles-peskine-arm gilles-peskine-arm self-assigned this Oct 8, 2021
self.private_type = re.sub(r'_PUBLIC_KEY\Z', r'_KEY_PAIR', self.name)
"""The key type macro name for the corresponding key pair type.

For everything other than a public key type, this is the same as
`self.name`.
"""

def is_public(self) -> bool:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Use it in NotSupported; see also #5037 (comment)

@daverodgman daverodgman deleted the branch Mbed-TLS:dev/gilles-peskine-arm/psa-storage-format-test-algorithms January 5, 2022 18:00
@daverodgman daverodgman closed this Jan 5, 2022
@gilles-peskine-arm
Copy link
Contributor Author

This is a follow-up of #4385. It got closed because the target branch was deleted. The target branch has now been merged. I'll make a new PR against development.

@gilles-peskine-arm gilles-peskine-arm changed the title PSA storage format: exercise keys PSA storage format: exercise keys (2.26) Mar 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component-psa PSA keystore/dispatch layer (storage, drivers, …) enhancement needs-ci Needs to pass CI tests needs-work size-m Estimated task size: medium (~1w)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants