-
Notifications
You must be signed in to change notification settings - Fork 3k
Crypto Service - keys access control #9638
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
Changes from all commits
0ecd2c5
99032f6
672712c
0c231b0
37cc257
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright (c) 2019, Arm Limited and affiliates | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <string.h> | ||
|
||
#include "psa_crypto_access_control.h" | ||
#include "psa_crypto_core.h" | ||
#include "psa_crypto_slot_management.h" | ||
|
||
#if defined(TARGET_TFM) | ||
#define SPM_PANIC(format, ...) \ | ||
{ \ | ||
while(1){}; \ | ||
} | ||
#else | ||
#include "spm_panic.h" | ||
#endif | ||
|
||
typedef struct psa_crypto_access_control_s { | ||
psa_key_handle_t key_handle; | ||
int32_t partition_id; | ||
} psa_crypto_access_control_t; | ||
|
||
static psa_crypto_access_control_t crypto_access_control_arr[PSA_KEY_SLOT_COUNT]; | ||
|
||
static inline void psa_crypto_access_control_reset() | ||
{ | ||
memset(crypto_access_control_arr, 0, sizeof(crypto_access_control_arr)); | ||
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. isn't it 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. The macro was removed in 6475bc65d818fc9ff4fc6c2c02de3d1b7ecde24a in favor of the static inline function. |
||
} | ||
|
||
void psa_crypto_access_control_init(void) | ||
{ | ||
psa_crypto_access_control_reset(); | ||
} | ||
|
||
void psa_crypto_access_control_destroy(void) | ||
{ | ||
psa_crypto_access_control_reset(); | ||
} | ||
|
||
void psa_crypto_access_control_register_handle(psa_key_handle_t key_handle, int32_t partition_id) | ||
{ | ||
for (size_t i = 0; i < PSA_KEY_SLOT_COUNT; i++) { | ||
if (crypto_access_control_arr[i].key_handle == 0 && | ||
crypto_access_control_arr[i].partition_id == 0) { | ||
itayzafrir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
crypto_access_control_arr[i].key_handle = key_handle; | ||
itayzafrir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
crypto_access_control_arr[i].partition_id = partition_id; | ||
return; | ||
} | ||
} | ||
|
||
SPM_PANIC("psa_crypto_access_control_register_handle failed"); | ||
} | ||
|
||
void psa_crypto_access_control_unregister_handle(psa_key_handle_t key_handle) | ||
{ | ||
for (size_t i = 0; i < PSA_KEY_SLOT_COUNT; i++) { | ||
if (crypto_access_control_arr[i].key_handle == key_handle) { | ||
crypto_access_control_arr[i].key_handle = 0; | ||
itayzafrir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
crypto_access_control_arr[i].partition_id = 0; | ||
return; | ||
} | ||
} | ||
|
||
SPM_PANIC("psa_crypto_access_control_unregister_handle failed"); | ||
} | ||
|
||
uint8_t psa_crypto_access_control_is_handle_permitted(psa_key_handle_t key_handle, int32_t partition_id) | ||
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. why not bool? |
||
{ | ||
for (size_t i = 0; i < PSA_KEY_SLOT_COUNT; i++) { | ||
if (crypto_access_control_arr[i].key_handle == key_handle && | ||
crypto_access_control_arr[i].partition_id == partition_id) { | ||
itayzafrir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return 1; | ||
} | ||
} | ||
|
||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (c) 2019, Arm Limited and affiliates | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef PSA_CRYPTO_ACCESS_CONTROL_H | ||
#define PSA_CRYPTO_ACCESS_CONTROL_H | ||
|
||
#include <stdint.h> | ||
|
||
#include "crypto_platform.h" | ||
|
||
/* initialize the module, resets all tracked information */ | ||
void psa_crypto_access_control_init(void); | ||
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. these functions should contain documentation? 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. I don't think so, this is internal only. These could have been implemented as static functions in psa_crypto_partition.c... 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. we could use Even internal functions should have documentation, hidden from public (using 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. Added in 5ac58b84dfa06f1c6cd76293dd4f01a5511124a0 |
||
|
||
/* deinitialize the module, resets all tracked information */ | ||
void psa_crypto_access_control_destroy(void); | ||
|
||
/* tracks and associates the key_handle with partition_id */ | ||
void psa_crypto_access_control_register_handle(psa_key_handle_t key_handle, int32_t partition_id); | ||
|
||
/* removes tracking of the key_handle */ | ||
void psa_crypto_access_control_unregister_handle(psa_key_handle_t key_handle); | ||
|
||
/* checks if the key_handle is associated with the partition_id, returns 0 is false otherwise 1 */ | ||
uint8_t psa_crypto_access_control_is_handle_permitted(psa_key_handle_t key_handle, int32_t partition_id); | ||
|
||
#endif /* PSA_CRYPTO_ACCESS_CONTROL_H */ |
Uh oh!
There was an error while loading. Please reload this page.