Skip to contentSkip to conversation

common: SCP03 control (enable and provision of keys)

PATCH Superseded Jorge Ramirez-Ortiz 3 participants 9 messages Feb 6, 2021 – Feb 8, 2021

Subsystems (2)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 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
index 2bb3798f80..482f123534 100644
@@ -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
index daeea67cf2..215b8b26fd 100644
@@ -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
new file mode 100644
index 0000000000..034796ada3
@@ -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
new file mode 100644
index 0000000000..13f9956d98
@@ -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
#1 lore raw

PATCH 1/1 drivers: tee: sandbox: secure channel protocol control

Adds support for SCP03 emulation.

---
 drivers/tee/optee/Kconfig |  6 ++++
 drivers/tee/sandbox.c     | 59 +++++++++++++++++++++++++++++++++++++--
 2 files changed, 63 insertions(+), 2 deletions(-)
drivers/tee/optee/Kconfig +6 -0
index d489834df9..b7f704a5e6 100644
@@ -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 +57 -2

89 lines not on this page · raw message

Signature · 1 line
2.30.0
#2 lore raw

PATCH 2/3 cmd: SCP03: enable and provision command

In reply to Jorge Ramirez-Ortiz

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
index 928a2a0a2d..4f990249b4 100644
@@ -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
index 176bf925fd..a7017e8452 100644
@@ -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
#3 lore raw

PATCH 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.

---
 cmd/Kconfig  |  9 ++++++++
 cmd/Makefile |  3 +++
 cmd/scp03.c  | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+)
 create mode 100644 cmd/scp03.c

Can we have a test for this please? See mem_search.c for an example.

Quoted 6 lines
cmd/Kconfig +0 -0
index 928a2a0a2d..4f990249b4 100644

cmd/Kconfig config HASH_VERIFY · line 2028

Quoted 8 lines
cmd/Kconfig +5 -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

I2C-channel ?

cmd/Kconfig config HASH_VERIFY · line 2031

Quoted 3 lines
cmd/Kconfig +3 -0
+         provision the SCP03 keys.
+           scp03 enable
+           scp03 provision

Also add this to doc/usage (see 'make htmldocs')

Quoted 32 lines
cmd/Kconfig +1 -0
+
 config CMD_TPM_V1
        bool
 
cmd/Makefile +3 -0
index 176bf925fd..a7017e8452 100644
@@ -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 +8 -0
new file mode 100644
index 0000000000..07913dbd3e
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2021, Foundries.IO
+ *
+ */
+
+#include <common.h>
+#include <command.h>

cmd/scp03.c line 18

Quoted 10 lines
cmd/scp03.c new file +10 -0
+#include <env.h>
+#include <scp03.h>
+
+int do_scp03_enable(struct cmd_tbl *cmdtp, int flag, int argc,
+                   char *const argv[])
+{
+       if (argc != 1)
+               return CMD_RET_USAGE;
+
+       if (tee_enable_scp03())

Do you want to report the failure with a message?

Quoted 14 lines
cmd/scp03.c new file +14 -0
+               return CMD_RET_FAILURE;
+
+       return CMD_RET_SUCCESS;
+}
+
+int do_scp03_provision(struct cmd_tbl *cmdtp, int flag, int argc,
+                      char *const argv[])
+{
+       if (argc != 1)
+               return CMD_RET_USAGE;
+
+       if (tee_provision_scp03())
+               return CMD_RET_FAILURE;
+

cmd/scp03.c line 42

Quoted 10 lines
cmd/scp03.c new file +10 -0
+       return CMD_RET_SUCCESS;
+}
+
+static struct cmd_tbl cmd_scp03[] = {
+       U_BOOT_CMD_MKENT(enable, 1, 0, do_scp03_enable, "", ""),
+       U_BOOT_CMD_MKENT(provision, 1, 0, do_scp03_provision, "", ""),
+};
+
+static int do_scp03(struct cmd_tbl *cmdtp, int flag, int argc,
+                   char * const argv[])

You could use U_BOOT_CMD_WITH_SUBCMDS() which might save some hassle here.

Quoted 23 lines
cmd/scp03.c new file +22 -1
+{
+       struct cmd_tbl *cp;
+
+       cp = find_cmd_tbl(argv[1], cmd_scp03, ARRAY_SIZE(cmd_scp03));
+
+       argc--;
+       argv++;
+
+       if (!cp || argc > cp->maxargs)
+               return CMD_RET_USAGE;
+
+       if (flag == CMD_FLAG_REPEAT)
+               return CMD_RET_FAILURE;
+
+       return cp->cmd(cmdtp, flag, argc, argv);
+}
+
+U_BOOT_CMD(scp03, 2, 0, do_scp03,
+          "Provides a command to enable SCP03 and provision the SCP03 keys\n",
+          "\tenable    - enable SCP03\n"
+          "\tprovision - provision SCP03\n"
+);
--
Quoted 2 lines

2.30.0

Regards,
Simon

#4 lore raw

PATCH 2/3 cmd: SCP03: enable and provision command

Quoted 15 lines · Simon Glass

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.

---
 cmd/Kconfig  |  9 ++++++++
 cmd/Makefile |  3 +++
 cmd/scp03.c  | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+)
 create mode 100644 cmd/scp03.c
Quoted 1 line

Can we have a test for this please? See mem_search.c for an example.

you mean other than what I posted already (the sandbox test using the TEE emulator)?

I am not really sure what else can it do: this command sends a request to a TEE and waits to a response (and both are emulated on the sandbox).

Quoted 10 lines
Quoted 10 lines
cmd/Kconfig +0 -0
index 928a2a0a2d..4f990249b4 100644
@@ -2021,6 +2021,15 @@ config HASH_VERIFY
        help
          Add -v option to verify data against a hash.
 
Quoted 7 lines

cmd/Kconfig config HASH_VERIFY · line 2028

Quoted 5 lines
cmd/Kconfig +5 -0
+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

I2C-channel ?

sure

Quoted 6 lines

cmd/Kconfig config HASH_VERIFY · line 2031

Quoted 4 lines
cmd/Kconfig +3 -0
+         provision the SCP03 keys.
+           scp03 enable
+           scp03 provision

Also add this to doc/usage (see 'make htmldocs')

ok

Quoted 37 lines
Quoted 37 lines
cmd/Kconfig +1 -0
+
 config CMD_TPM_V1
        bool
 
cmd/Makefile +3 -0
index 176bf925fd..a7017e8452 100644
@@ -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 +12 -0
new file mode 100644
index 0000000000..07913dbd3e
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2021, Foundries.IO
+ *
+ */
+
+#include <common.h>
+#include <command.h>
+#include <env.h>
+#include <scp03.h>
+
+int do_scp03_enable(struct cmd_tbl *cmdtp, int flag, int argc,
Quoted 8 lines

cmd/scp03.c line 18

Quoted 6 lines
cmd/scp03.c new file +6 -0
+                   char *const argv[])
+{
+       if (argc != 1)
+               return CMD_RET_USAGE;
+
+       if (tee_enable_scp03())

Do you want to report the failure with a message?

ok

Quoted 20 lines
Quoted 20 lines
cmd/scp03.c new file +19 -0
+               return CMD_RET_FAILURE;
+
+       return CMD_RET_SUCCESS;
+}
+
+int do_scp03_provision(struct cmd_tbl *cmdtp, int flag, int argc,
+                      char *const argv[])
+{
+       if (argc != 1)
+               return CMD_RET_USAGE;
+
+       if (tee_provision_scp03())
+               return CMD_RET_FAILURE;
+
+       return CMD_RET_SUCCESS;
+}
+
+static struct cmd_tbl cmd_scp03[] = {
+       U_BOOT_CMD_MKENT(enable, 1, 0, do_scp03_enable, "", ""),
Quoted 8 lines

cmd/scp03.c line 42

Quoted 5 lines
cmd/scp03.c new file +5 -0
+       U_BOOT_CMD_MKENT(provision, 1, 0, do_scp03_provision, "", ""),
+};
+
+static int do_scp03(struct cmd_tbl *cmdtp, int flag, int argc,
+                   char * const argv[])

You could use U_BOOT_CMD_WITH_SUBCMDS() which might save some hassle here.

yes, much nicer. thanks

Quoted 29 lines
Quoted 24 lines
cmd/scp03.c new file +22 -1
+{
+       struct cmd_tbl *cp;
+
+       cp = find_cmd_tbl(argv[1], cmd_scp03, ARRAY_SIZE(cmd_scp03));
+
+       argc--;
+       argv++;
+
+       if (!cp || argc > cp->maxargs)
+               return CMD_RET_USAGE;
+
+       if (flag == CMD_FLAG_REPEAT)
+               return CMD_RET_FAILURE;
+
+       return cp->cmd(cmdtp, flag, argc, argv);
+}
+
+U_BOOT_CMD(scp03, 2, 0, do_scp03,
+          "Provides a command to enable SCP03 and provision the SCP03 keys\n",
+          "\tenable    - enable SCP03\n"
+          "\tprovision - provision SCP03\n"
+);
--
Quoted 2 lines

2.30.0

Regards,
Simon

#5 lore raw

PATCH 2/3 cmd: SCP03: enable and provision command

Hi Jorge,

Quoted 17 lines · Foundries
Quoted 15 lines · Simon Glass

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.

---
 cmd/Kconfig  |  9 ++++++++
 cmd/Makefile |  3 +++
 cmd/scp03.c  | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+)
 create mode 100644 cmd/scp03.c
Quoted 7 lines
Quoted 1 line

Can we have a test for this please? See mem_search.c for an example.

you mean other than what I posted already (the sandbox test using the TEE emulator)?

I am not really sure what else can it do: this command sends a request to a TEE and waits to a response (and both are emulated on the sandbox).

It should just be a few lines of code to test the basics. E.g.:

https://github.com/u-boot/u-boot/blob/3936fd998668846f77468d8f6a662e906920969c/test/cmd/test_echo.c#L42

Regards,
Simon

#6 lore raw

PATCH 2/3 cmd: SCP03: enable and provision command

Quoted 26 lines · Simon Glass

Hi Jorge,

Quoted 22 lines · Foundries
Quoted 15 lines · Simon Glass

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.

---
 cmd/Kconfig  |  9 ++++++++
 cmd/Makefile |  3 +++
 cmd/scp03.c  | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+)
 create mode 100644 cmd/scp03.c
Quoted 1 line

Can we have a test for this please? See mem_search.c for an example.

you mean other than what I posted already (the sandbox test using the TEE emulator)?

Quoted 6 lines
Quoted 2 lines

I am not really sure what else can it do: this command sends a request to a TEE and waits to a response (and both are emulated on the sandbox).

It should just be a few lines of code to test the basics. E.g.:

https://github.com/u-boot/u-boot/blob/3936fd998668846f77468d8f6a662e906920969c/test/cmd/test_echo.c#L42

ah ok I see what you mean.
I'll have a look

Quoted 3 lines

Regards,
Simon

#7 lore raw

PATCH 3/3 drivers: tee: sandbox: secure channel protocol control

In reply to Jorge Ramirez-Ortiz

Adds 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
index d489834df9..b7f704a5e6 100644
@@ -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
#8 lore raw

PATCH 3/3 drivers: tee: sandbox: secure channel protocol control

Hi Jorge,

Quoted 9 lines · Jorge Ramirez-Ortiz

Adds 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 config OPTEE_TA_AVB · line 29

Quoted 13 lines
drivers/tee/optee/Kconfig +5 -0
index d489834df9..b7f704a5e6 100644
@@ -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.

What is SCP03? Can you add a link and write it out in full if it is an abbreviation?

Quoted 4 lines
drivers/tee/optee/Kconfig +1 -0
+
 endmenu
 
 endif

[..]