common: SCP03 control (enable and provision of keys)
Subsystems (2)
PATCH v2 1/3 common: SCP03 control (enable and provision of keys)
This Trusted Application allows enabling and provisioning SCP03 keys on TEE controlled secure element (ie, NXP SE050)
For information on SCP03, check the Global Platform HomePage[1]
[1] globalplatform.org
--- common/Kconfig | 8 ++++++ common/Makefile | 1 + common/scp03.c | 52 ++++++++++++++++++++++++++++++++++++ include/scp03.h | 19 +++++++++++++ include/tee/optee_ta_scp03.h | 21 +++++++++++++++ 5 files changed, 101 insertions(+) create mode 100644 common/scp03.c create mode 100644 include/scp03.h create mode 100644 include/tee/optee_ta_scp03.h
common/Kconfig +8 -0
@@ -588,6 +588,14 @@ config AVB_BUF_SIZE endif # AVB_VERIFY +config SCP03 + bool "Build SCP03 - Secure Channel Protocol O3 - controls" + depends on OPTEE || SANDBOX + depends on TEE + help + This option allows U-Boot to enable and or provision SCP03 on an OPTEE + controlled Secured Element. + config SPL_HASH bool # "Support hashing API (SHA1, SHA256, etc.)" help
common/Makefile +1 -0
@@ -137,3 +137,4 @@ obj-$(CONFIG_CMD_LOADB) += xyzModem.o obj-$(CONFIG_$(SPL_TPL_)YMODEM_SUPPORT) += xyzModem.o obj-$(CONFIG_AVB_VERIFY) += avb_verify.o +obj-$(CONFIG_SCP03) += scp03.o
common/scp03.c new file +52 -0
52 lines not on this page · raw message
include/scp03.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* (C) Copyright 2021, Foundries.IO +* +*/ + +#ifndef _SCP03_H +#define _SCP03_H + +/* +* Requests to OPTEE to enable or provision the Secure Channel Protocol on its +* Secure Element +* +* If key provisioning is requested, OPTEE shall generate new SCP03 keys and +* write them to the Secure Element. +*/ +int tee_enable_scp03 (void ); +int tee_provision_scp03 (void ); +#endif /* _SCP03_H */
include/tee/optee_ta_scp03.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* +* (C) Copyright 2021, Foundries.IO +* +*/ +#ifndef __TA_SCP03_H +#define __TA_SCP03_H + +#define PTA_SCP03_UUID { 0xbe0e5821, 0xe718, 0x4f77, \ + { 0xab, 0x3e, 0x8e, 0x6c, 0x73, 0xa9, 0xc7, 0x35 } } + +/* +* Enable Secure Channel Protocol functionality (SCP03) on the Secure Element. +* Setting the operation value to something different than NULL will trigger +* the SCP03 provisioning request. +* +* in params[0].a = operation +*/ +#define PTA_CMD_ENABLE_SCP03 0 + +#endif /*__TA_SCP03_H*/
Signature · 1 line
2.30.0
PATCH v2 2/3 cmd: SCP03: enable and provision command
Enable and provision the SCP03 keys on a TEE controlled secured elemt from the U-Boot shell.
--- cmd/Kconfig | 9 ++++++++ cmd/Makefile | 3 +++ cmd/scp03.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 cmd/scp03.c
cmd/Kconfig +9 -0
@@ -2021,6 +2021,15 @@ config HASH_VERIFY help Add -v option to verify data against a hash. +config CMD_SCP03 + bool "scp03 - SCP03 enable and rotate/provision operations" + depends on SCP03 + help + Enables the SCP03 commands to activate I2C channel encryption and + provision the SCP03 keys. + scp03 enable + scp03 provision + config CMD_TPM_V1 bool
cmd/Makefile +3 -0
@@ -193,6 +193,9 @@ obj-$(CONFIG_CMD_BLOB) += blob.o # Android Verified Boot 2.0 obj-$(CONFIG_CMD_AVB) += avb.o +# Foundries.IO SCP03 +obj-$(CONFIG_CMD_SCP03) += scp03.o + obj-$(CONFIG_ARM) += arm/ obj-$(CONFIG_RISCV) += riscv/ obj-$(CONFIG_SANDBOX) += sandbox/
cmd/scp03.c new file +64 -0
64 lines not on this page · raw message
Signature · 1 line
2.30.0
PATCH v2 2/3 cmd: SCP03: enable and provision command
Hi Jorge,
Quoted 11 lines · Jorge Ramirez-Ortiz
Enable and provision the SCP03 keys on a TEE controlled secured elemt from the U-Boot shell.
Signed-off-by Jorge Ramirez-Ortiz <[email protected]>--- cmd/Kconfig | 9 ++++++++ cmd/Makefile | 3 +++ cmd/scp03.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 cmd/scp03.c
Same comments on this one.
Regards,
Simon
PATCH v2 3/3 drivers: tee: sandbox: secure channel protocol control
In reply to Jorge Ramirez-OrtizAdds support for SCP03 emulation.
--- drivers/tee/optee/Kconfig | 6 ++++ drivers/tee/sandbox.c | 60 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 2 deletions(-)
drivers/tee/optee/Kconfig +6 -0
@@ -22,6 +22,12 @@ config OPTEE_TA_AVB The TA can support the "avb" subcommands "read_rb", "write"rb" and "is_unlocked". +config OPTEE_TA_SCP03 + bool "Support SCP03 TA" + default y + help + Enables support for the SCP03 Trusted Application (TA) in OP-TEE. + endmenu endif
drivers/tee/sandbox.c +58 -2
90 lines not on this page · raw message
Signature · 1 line
2.30.0
PATCH v2 3/3 drivers: tee: sandbox: secure channel protocol control
Hi Jorge,
Quoted 8 lines · Jorge Ramirez-Ortiz
Adds support for SCP03 emulation.
Signed-off-by Jorge Ramirez-Ortiz <[email protected]>--- drivers/tee/optee/Kconfig | 6 ++++ drivers/tee/sandbox.c | 60 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 2 deletions(-)
No change log, so this seems to be a resend? Anyway, see earlier comments.
Regards,
Simon
PATCH v2 1/3 common: SCP03 control (enable and provision of keys)
In reply to Jorge Ramirez-OrtizHi Jorge,
Quoted 8 lines · Jorge Ramirez-Ortiz
This Trusted Application allows enabling and provisioning SCP03 keys on TEE controlled secure element (ie, NXP SE050)
For information on SCP03, check the Global Platform HomePage[1]
[1] globalplatform.orgSigned-off-by Jorge Ramirez-Ortiz <[email protected]>
Quoted 10 lines
--- common/Kconfig | 8 ++++++ common/Makefile | 1 + common/scp03.c | 52 ++++++++++++++++++++++++++++++++++++ include/scp03.h | 19 +++++++++++++ include/tee/optee_ta_scp03.h | 21 +++++++++++++++ 5 files changed, 101 insertions(+) create mode 100644 common/scp03.c create mode 100644 include/scp03.h create mode 100644 include/tee/optee_ta_scp03.h
But please see below
Quoted 6 lines
common/Kconfig +0
-0
common/Kconfig config AVB_BUF_SIZE · line 597
Quoted 10 lines
common/Kconfig +7
-0@@ -588,6 +588,14 @@ config AVB_BUF_SIZE endif # AVB_VERIFY +config SCP03 + bool "Build SCP03 - Secure Channel Protocol O3 - controls" + depends on OPTEE || SANDBOX + depends on TEE + help + This option allows U-Boot to enable and or provision SCP03 on an OPTEE + controlled Secured Element.
Why would you want to do that? Please expand this a bit
Quoted 19 lines
common/Kconfig +1
-0+ config SPL_HASH bool # "Support hashing API (SHA1, SHA256, etc.)" helpcommon/Makefile +1
-0@@ -137,3 +137,4 @@ obj-$(CONFIG_CMD_LOADB) += xyzModem.o obj-$(CONFIG_$(SPL_TPL_)YMODEM_SUPPORT) += xyzModem.o obj-$(CONFIG_AVB_VERIFY) += avb_verify.o +obj-$(CONFIG_SCP03) += scp03.ocommon/scp03.c new file +0
-0
common/scp03.c line 6
Quoted 6 lines
common/scp03.c new file +6
-0@@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* (C) Copyright 2021, Foundries.IO +* +*/ +
common.h
Quoted 10 lines
common/scp03.c new file +10
-0+#include <scp03.h> +#include <tee.h> +#include <tee/optee_ta_scp03.h> + +static int scp03_enable (bool provision) +{ +const struct tee_optee_ta_uuid uuid =PTA_SCP03_UUID ; +struct tee_open_session_arg session; +struct tee_invoke_arg invoke; +struct tee_param param;
common/scp03.c line 26
Quoted 10 lines
common/scp03.c new file +10
-0+struct udevice *tee =NULL ; + + tee =tee_find_device (tee,NULL ,NULL ,NULL ); +if (!tee) +return -ENODEV ; + +memset (&session,0 ,sizeof (session)); +tee_optee_ta_uuid_to_octets (session.uuid, &uuid); +if (tee_open_session (tee, &session,0 ,NULL )) +return -ENODEV ;
Should return the actual error from tee_open_session(). You can't return -ENODEV as there is a device.
common/scp03.c line 37
Quoted 11 lines
common/scp03.c new file +11
-0+ +memset (¶m,0 ,sizeof (param)); + param.attr =TEE_PARAM_ATTR_TYPE_VALUE_INPUT ; + param.u.value.a = provision; + +memset (&invoke,0 ,sizeof (invoke)); + invoke.func =PTA_CMD_ENABLE_SCP03 ; + invoke.session = session.session; + +if (tee_invoke_func (tee, &invoke,1 , ¶m)) +return -EIO ;
Please return the actual error
Quoted 26 lines
common/scp03.c new file +15
-0+ +tee_close_session (tee, session.session); + +return 0 ; +} + +int tee_enable_scp03 (void ) +{ +return scp03_enable (false); +} + +int tee_provision_scp03 (void ) +{ +return scp03_enable (true); +}include/scp03.h new file +5
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* (C) Copyright 2021, Foundries.IO +* +*/
include/scp03.h line 15
Quoted 10 lines
include/scp03.h new file +10
-0+ +#ifndef _SCP03_H +#define _SCP03_H + +/* +* Requests to OPTEE to enable or provision the Secure Channel Protocol on its +* Secure Element +* +* If key provisioning is requested, OPTEE shall generate new SCP03 keys and +* write them to the Secure Element.
@return
include/scp03.h line 19
Quoted 4 lines
include/scp03.h new file +4
-0+*/ +int tee_enable_scp03 (void ); +int tee_provision_scp03 (void ); +#endif /* _SCP03_H */
Regards,
Simon
Jorge Ramirez-Ortiz
PATCH v2 1/3 common: SCP03 control (enable and provision of keys)
Quoted 35 lines · Simon Glass
Hi Jorge,
Quoted 8 lines · Jorge Ramirez-Ortiz
This Trusted Application allows enabling and provisioning SCP03 keys on TEE controlled secure element (ie, NXP SE050)
For information on SCP03, check the Global Platform HomePage[1]
[1] globalplatform.orgSigned-off-by Jorge Ramirez-Ortiz <[email protected]>Quoted 10 lines
--- common/Kconfig | 8 ++++++ common/Makefile | 1 + common/scp03.c | 52 ++++++++++++++++++++++++++++++++++++ include/scp03.h | 19 +++++++++++++ include/tee/optee_ta_scp03.h | 21 +++++++++++++++ 5 files changed, 101 insertions(+) create mode 100644 common/scp03.c create mode 100644 include/scp03.h create mode 100644 include/tee/optee_ta_scp03.hReviewed-by Simon Glass <[email protected]>But please see below
Quoted 9 lines
common/Kconfig +0
-0@@ -588,6 +588,14 @@ config AVB_BUF_SIZE endif # AVB_VERIFY
Quoted 9 lines
common/Kconfig config AVB_BUF_SIZE · line 597
Quoted 7 lines
common/Kconfig +7
-0+config SCP03 + bool "Build SCP03 - Secure Channel Protocol O3 - controls" + depends on OPTEE || SANDBOX + depends on TEE + help + This option allows U-Boot to enable and or provision SCP03 on an OPTEE + controlled Secured Element.Why would you want to do that? Please expand this a bit
sure
Quoted 44 lines
Quoted 20 lines
common/Kconfig +1
-0+ config SPL_HASH bool # "Support hashing API (SHA1, SHA256, etc.)" helpcommon/Makefile +1
-0@@ -137,3 +137,4 @@ obj-$(CONFIG_CMD_LOADB) += xyzModem.o obj-$(CONFIG_$(SPL_TPL_)YMODEM_SUPPORT) += xyzModem.o obj-$(CONFIG_AVB_VERIFY) += avb_verify.o +obj-$(CONFIG_SCP03) += scp03.ocommon/scp03.c new file +0
-0common/scp03.c line 6
Quoted 6 lines
common/scp03.c new file +6
-0@@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* (C) Copyright 2021, Foundries.IO +* +*/ +
common.hQuoted 15 lines
common/scp03.c new file +15
-0+#include <scp03.h> +#include <tee.h> +#include <tee/optee_ta_scp03.h> + +static int scp03_enable (bool provision) +{ +const struct tee_optee_ta_uuid uuid =PTA_SCP03_UUID ; +struct tee_open_session_arg session; +struct tee_invoke_arg invoke; +struct tee_param param; +struct udevice *tee =NULL ; + + tee =tee_find_device (tee,NULL ,NULL ,NULL ); +if (!tee) +return -ENODEV ;
Quoted 8 lines
common/scp03.c line 26
Quoted 5 lines
common/scp03.c new file +5
-0+ +memset (&session,0 ,sizeof (session)); +tee_optee_ta_uuid_to_octets (session.uuid, &uuid); +if (tee_open_session (tee, &session,0 ,NULL )) +return -ENODEV ;Should return the actual error from
tee_open_session(). You can't return-ENODEVas there is a device.
Right but there is not a TA responding to the requests (the actual handler for the TEE). But ok, will use EINVAL
Quoted 14 lines
common/scp03.c line 37
Quoted 12 lines
common/scp03.c new file +11
-0+ +memset (¶m,0 ,sizeof (param)); + param.attr =TEE_PARAM_ATTR_TYPE_VALUE_INPUT ; + param.u.value.a = provision; + +memset (&invoke,0 ,sizeof (invoke)); + invoke.func =PTA_CMD_ENABLE_SCP03 ; + invoke.session = session.session; + +if (tee_invoke_func (tee, &invoke,1 , ¶m)) +return -EIO ;Please return the actual error
These functions done return a valid error (just <0 on error)
Having said that this is probably the most likely error - the i2c chip (the secure element) not being accessible but I can return something more generic like EFAULT?
Notice that if this fails 99% of the times will mean that the secure element has been bricked in the process.
Quoted 31 lines
Quoted 31 lines
common/scp03.c new file +15
-0+ +tee_close_session (tee, session.session); + +return 0 ; +} + +int tee_enable_scp03 (void ) +{ +return scp03_enable (false); +} + +int tee_provision_scp03 (void ) +{ +return scp03_enable (true); +}include/scp03.h new file +9
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* (C) Copyright 2021, Foundries.IO +* +*/ + +#ifndef _SCP03_H +#define _SCP03_H +
Quoted 8 lines
include/scp03.h line 15
Quoted 6 lines
include/scp03.h new file +6
-0+/* +* Requests to OPTEE to enable or provision the Secure Channel Protocol on its +* Secure Element +* +* If key provisioning is requested, OPTEE shall generate new SCP03 keys and +* write them to the Secure Element. @return
ok
Quoted 8 lines
include/scp03.h line 19
Quoted 5 lines
include/scp03.h new file +4
-0+*/ +int tee_enable_scp03 (void ); +int tee_provision_scp03 (void ); +#endif /* _SCP03_H */ Regards,
Simon
PATCH v2 1/3 common: SCP03 control (enable and provision of keys)
Hi Jorge,
Quoted 102 lines · Foundries
Quoted 35 lines · Simon Glass
Hi Jorge,
Quoted 8 lines · Jorge Ramirez-Ortiz
This Trusted Application allows enabling and provisioning SCP03 keys on TEE controlled secure element (ie, NXP SE050)
For information on SCP03, check the Global Platform HomePage[1]
[1] globalplatform.orgSigned-off-by Jorge Ramirez-Ortiz <[email protected]>Quoted 10 lines
--- common/Kconfig | 8 ++++++ common/Makefile | 1 + common/scp03.c | 52 ++++++++++++++++++++++++++++++++++++ include/scp03.h | 19 +++++++++++++ include/tee/optee_ta_scp03.h | 21 +++++++++++++++ 5 files changed, 101 insertions(+) create mode 100644 common/scp03.c create mode 100644 include/scp03.h create mode 100644 include/tee/optee_ta_scp03.hReviewed-by Simon Glass <[email protected]>But please see below
Quoted 9 lines
common/Kconfig +0
-0@@ -588,6 +588,14 @@ config AVB_BUF_SIZE endif # AVB_VERIFYQuoted 9 lines
common/Kconfig config AVB_BUF_SIZE · line 597
Quoted 7 lines
common/Kconfig +7
-0+config SCP03 + bool "Build SCP03 - Secure Channel Protocol O3 - controls" + depends on OPTEE || SANDBOX + depends on TEE + help + This option allows U-Boot to enable and or provision SCP03 on an OPTEE + controlled Secured Element.Why would you want to do that? Please expand this a bit
sure
Quoted 44 lines
Quoted 20 lines
common/Kconfig +1
-0+ config SPL_HASH bool # "Support hashing API (SHA1, SHA256, etc.)" helpcommon/Makefile +1
-0@@ -137,3 +137,4 @@ obj-$(CONFIG_CMD_LOADB) += xyzModem.o obj-$(CONFIG_$(SPL_TPL_)YMODEM_SUPPORT) += xyzModem.o obj-$(CONFIG_AVB_VERIFY) += avb_verify.o +obj-$(CONFIG_SCP03) += scp03.ocommon/scp03.c new file +0
-0common/scp03.c line 6
Quoted 6 lines
common/scp03.c new file +6
-0@@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* (C) Copyright 2021, Foundries.IO +* +*/ +
common.hQuoted 15 lines
common/scp03.c new file +15
-0+#include <scp03.h> +#include <tee.h> +#include <tee/optee_ta_scp03.h> + +static int scp03_enable (bool provision) +{ +const struct tee_optee_ta_uuid uuid =PTA_SCP03_UUID ; +struct tee_open_session_arg session; +struct tee_invoke_arg invoke; +struct tee_param param; +struct udevice *tee =NULL ; + + tee =tee_find_device (tee,NULL ,NULL ,NULL ); +if (!tee) +return -ENODEV ;Quoted 8 lines
common/scp03.c line 26
Quoted 5 lines
common/scp03.c new file +5
-0+ +memset (&session,0 ,sizeof (session)); +tee_optee_ta_uuid_to_octets (session.uuid, &uuid); +if (tee_open_session (tee, &session,0 ,NULL )) +return -ENODEV ;Should return the actual error from
tee_open_session(). You can't return-ENODEVas there is a device.
Quoted 2 lines
Right but there is not a TA responding to the requests (the actual handler for the TEE). But ok, will use EINVAL
Then perhaps -ENXIO ?
Quoted 17 lines
Quoted 16 lines
Quoted 4 lines
common/scp03.c new file +1
-0+common/scp03.c line 37
Quoted 10 lines
common/scp03.c new file +10
-0+memset (¶m,0 ,sizeof (param)); + param.attr =TEE_PARAM_ATTR_TYPE_VALUE_INPUT ; + param.u.value.a = provision; + +memset (&invoke,0 ,sizeof (invoke)); + invoke.func =PTA_CMD_ENABLE_SCP03 ; + invoke.session = session.session; + +if (tee_invoke_func (tee, &invoke,1 , ¶m)) +return -EIO ;Please return the actual error
Quoted 1 line
These functions done return a valid error (just <0 on error)
Oh that should probably be fixed@some point.
Quoted 4 lines
Having said that this is probably the most likely error - the i2c chip (the secure element) not being accessible but I can return something more generic like EFAULT?
In that case -EIO is fine for now. I think of -EFAULT as a memory fault, although I don't know that we use it much in U-Boot.
Quoted 3 lines
Notice that if this fails 99% of the times will mean that the secure element has been bricked in the process.
OK.
[...]
Regards,
Simon