Skip to content

DeviceKey Root of Trust generation refactored. #12385

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

Merged
merged 1 commit into from
Feb 26, 2020

Conversation

tymoteuszblochmobica
Copy link
Contributor

@tymoteuszblochmobica tymoteuszblochmobica commented Feb 6, 2020

Root of Trust is no longer automatically and silently created.

Summary of changes

Removed automatic creation of the Root Of Trust when DeviceKey::generate_derived_key(...) API is used.
User must generate or inject the key before first use of DeviceKey API.

Impact of changes

DeviceKey is not automatically generated anymore. This might impact test application which expect the key to be present, but do not explicitly generate it.

Migration actions required

Application developers must be aware that if their device does not have Root of Trust permanently injected, which is usually true in development phase, they must generate a key before first use of DeviceKey API. Two options exist for key generation:

  • Generate a key using TRNG sources by calling DeviceKey::device_generate_root_of_trust()
  • Inject a secure key by calling DeviceKey::device_inject_root_of_trust(...) in case the device does not have a TRNG available.

Documentation

ARMmbed/mbed-os-5-docs#1244

Release notes


Pull request type

[] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[x] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[] Covered by existing mbed-os tests (Greentea or Unittest)
[x] Tests / results supplied as part of this PR

Reviewers

@SeppoTakalo
@michalpasztamobica
@Jammu Kekkonen
@teetak01
@janne Kiiskila

@ciarmcom
Copy link
Member

ciarmcom commented Feb 6, 2020

@tymoteuszblochmobica, thank you for your changes.
@SeppoTakalo @michalpasztamobica @ARMmbed/mbed-os-storage @ARMmbed/mbed-os-maintainers please review.

@Teemu
Copy link

Teemu commented Feb 6, 2020

Uhh I guess you meant @teetak01

@SeppoTakalo SeppoTakalo added the release-version: 6.0.0-alpha-1 First pre-release version of 6.0.0 label Feb 7, 2020
@SeppoTakalo
Copy link
Contributor

@yogpan01 and @JammuKekkonen This is now the change we talked about. This basically breaks existing client test applications which assume RoT to be autogenerated, and therefore should only be pushed to Mbed OS 6.0.

Please review and comment. To properly get this working, the new API has to be adopted in client test applications.

@@ -259,22 +246,22 @@ int DeviceKey::get_derived_key(uint32_t *ikey_buff, size_t ikey_size, const unsi
return DEVICEKEY_SUCCESS;
}

int DeviceKey::generate_key_by_random(uint32_t *output, size_t size)
int DeviceKey::device_generate_root_of_trust()
Copy link
Contributor

Choose a reason for hiding this comment

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

I know I proposed this name, but I'm starting to wonder.. is there and extra "device" in the DeviceKey::device_do_something...

Maybe the DeviceKey::generate_root_of_trust() should be enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed

Copy link
Contributor

@SeppoTakalo SeppoTakalo left a comment

Choose a reason for hiding this comment

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

Change looks good. Just minor change requested.

This need OK from client team before merge.

@@ -283,7 +270,7 @@ int DeviceKey::generate_key_by_random(uint32_t *output, size_t size)

mbedtls_entropy_free(entropy);
delete entropy;

device_inject_root_of_trust(key_buff, actual_size);
Copy link
Contributor

Choose a reason for hiding this comment

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

Error code needs to be recorded from here as well. The injection phase can fail as rell, so

ret = device_inject_root_of_trust(key_buff, actual_size);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed

Copy link
Contributor

@VeijoPesonen VeijoPesonen left a comment

Choose a reason for hiding this comment

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

Once the issues mentioned by Seppo have been addressed this looks ok from my point of view.

SeppoTakalo
SeppoTakalo previously approved these changes Feb 7, 2020
Copy link
Contributor

@SeppoTakalo SeppoTakalo left a comment

Choose a reason for hiding this comment

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

Looks OK.

This now needs Client teams to approve, so once @teetak01 and @yogpan01 say OK, this is good to go in.

CI tests can be started already.

*/
int generate_key_by_random(uint32_t *output, size_t size);
int generate_root_of_trust();
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be changed to public api. Seems like it could/should also be static.

Copy link
Contributor

Choose a reason for hiding this comment

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

Writing a unit test for this wouldn't hurt.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is now changed to public.

static DeviceKey &get_instance()
{
// Use this implementation of singleton (Meyer's) rather than the one that allocates
// the instance on the heap, as it ensures destruction at program end (preventing warnings
// from memory checking tools, such as valgrind).
static DeviceKey instance;
return instance;
}

@mergify mergify bot removed the needs: review label Feb 7, 2020
@0xc0170
Copy link
Contributor

0xc0170 commented Feb 7, 2020

CI started

@mbed-ci
Copy link

mbed-ci commented Feb 7, 2020

Test run: FAILED

Summary: 1 of 11 test jobs failed
Build number : 1
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_greentea-test

@mergify mergify bot added needs: work and removed needs: CI labels Feb 7, 2020
@tymoteuszblochmobica
Copy link
Contributor Author

tymoteuszblochmobica commented Feb 18, 2020

Rest of failing tests updated.
@0xc0170 could You restart ?

@mergify mergify bot added needs: CI and removed needs: work labels Feb 26, 2020
@mbed-ci
Copy link

mbed-ci commented Feb 26, 2020

Test run: FAILED

Summary: 1 of 4 test jobs failed
Build number : 4
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_build-IAR

@mergify mergify bot added needs: work and removed needs: CI labels Feb 26, 2020
@mbed-ci
Copy link

mbed-ci commented Feb 26, 2020

Test run: SUCCESS

Summary: 8 of 8 test jobs passed
Build number : 5
Build artifacts

@0xc0170
Copy link
Contributor

0xc0170 commented Feb 26, 2020

@tymoteuszblochmobica I added breaking change label. Can you update the release notes (no migration needed ?) ?

Also:

Possible Cloud Client.
Tests for CC will be added separately.

Is not saying much to a user, what real impact is there?

@SeppoTakalo
Copy link
Contributor

@0xc0170 I updated the PR header, that should be now OK for release notes. Or do we need to add a separate title for that?

LDong-Arm added a commit to LDong-Arm/mbed-os-example-devicekey that referenced this pull request Apr 15, 2021
Since ARMmbed/mbed-os#12385:

    0e7a53c DeviceKey Root of Trust generation refactored.

the Root of Trust is not automatically generated anymore. We need to
generate or inject one explicitly.

This commit also improves the readability of the existing code for the
injection of Root of Trust.
LDong-Arm added a commit to LDong-Arm/mbed-os-example-devicekey that referenced this pull request Apr 15, 2021
Since ARMmbed/mbed-os#12385:

    0e7a53c DeviceKey Root of Trust generation refactored.

the Root of Trust is not automatically generated anymore. We need to
generate or inject one explicitly.

This commit also improves the readability of the existing code for the
injection of Root of Trust.

Fixes ARMmbed#71
LDong-Arm added a commit to LDong-Arm/mbed-os-example-devicekey that referenced this pull request Apr 15, 2021
Since ARMmbed/mbed-os#12385:

    0e7a53c DeviceKey Root of Trust generation refactored.

the Root of Trust is not automatically generated anymore. We need to
generate or inject one explicitly.

This commit also improves the readability of the existing code for the
injection of Root of Trust.

Fixes ARMmbed#71
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BREAKING-CHANGE release-version: 6.0.0-alpha-1 First pre-release version of 6.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.