-
Notifications
You must be signed in to change notification settings - Fork 15
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
provisioning: Prevent re-provisioning #94
Open
david-hazi-arm
wants to merge
1
commit into
FreeRTOS:main
Choose a base branch
from
david-hazi-arm:dev/davhaz01/provisioning_fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,9 @@ | |
#include "mbedtls/entropy.h" | ||
#include "mbedtls/ctr_drbg.h" | ||
|
||
/* TF-M ITS include */ | ||
#include "psa/internal_trusted_storage.h" | ||
|
||
/* Default FreeRTOS API for console logging. */ | ||
#define DEV_MODE_KEY_PROVISIONING_PRINT( X ) printf | ||
|
||
|
@@ -91,6 +94,9 @@ extern void vLoggingPrint( const char * pcFormat ); | |
|
||
#define DER_FORMAT_BUFFER_LENGTH 512 | ||
|
||
#define FIRST_BOOT_ITS_UID ( 1U ) | ||
#define BOOT_PATTERN ( 0x55 ) | ||
|
||
/* Adding one to all of the lengths because ASN1 may pad a leading 0 byte | ||
* to numbers that could be interpreted as negative */ | ||
typedef struct RsaParams_t | ||
|
@@ -1443,4 +1449,39 @@ int xOtaProvisionCodeSigningKey( psa_key_handle_t * pxKeyHandle, | |
return result; | ||
} | ||
|
||
UBaseType_t uxIsDeviceProvisioned( void ) | ||
{ | ||
psa_status_t status = PSA_ERROR_GENERIC_ERROR; | ||
const psa_storage_uid_t uid = FIRST_BOOT_ITS_UID; | ||
uint8_t boot_pattern_in_its = 0; | ||
size_t read_data_length = 0; | ||
|
||
status = psa_its_get( uid, 0, 1, &boot_pattern_in_its, | ||
&read_data_length ); | ||
|
||
if( status != PSA_SUCCESS ) | ||
{ | ||
return 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor comment - I notice in calls to this function you check if it returns "false" and not 0. Should this function return "false" and "true" ? |
||
} | ||
|
||
if( boot_pattern_in_its == BOOT_PATTERN ) | ||
{ | ||
return 1; | ||
} | ||
else | ||
{ | ||
return 0; | ||
} | ||
} | ||
|
||
psa_status_t xWriteDeviceProvisioned( void ) | ||
{ | ||
const psa_storage_uid_t uid = FIRST_BOOT_ITS_UID; | ||
const psa_storage_create_flags_t flags = PSA_STORAGE_FLAG_WRITE_ONCE; | ||
uint8_t first_boot_pattern = BOOT_PATTERN; | ||
|
||
/* Write the pattern to ITS */ | ||
return psa_its_set( uid, 1, &first_boot_pattern, flags ); | ||
} | ||
|
||
/*-----------------------------------------------------------*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
provisioning: Prevent re-provisioning |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comment going to be addressed? I see it in each main.c.