Skip to content

Commit addb97d

Browse files
flihpFawazTirmizi
authored andcommitted
minimum self-signed DICE (oxidecomputer#698)
* Update lpc55_support for compatibility with latest zeroize crate. * lib-dice: Add new library with types for DICE artifacts and certs. The current cert implementation is limited to the creation of a self signed cert for the DeviceId & the Alias cert. Cert creation is as simple as possible with a template for each cert (DER) that is populated with fixed length data like the platform serial number, certificate serial number, public key & signature. Future work will address programatic generation of these templates at build time to replace the currently static ones. * lpc55/chip.toml: Add memory regions for DICE artifact handoff. The memory used in this commit is SRAM intended for use by USB. The choice of using this memory region was mostly driven by convenience and pivoting to a different range should be straight forward. The size of this region was chosen based on the estimated size of the data passed. The DeviceId and Alias cert are each ~600 bytes and the seed required to reconstruct the Alias key is 32 bytes. All of this fits comfortably in 2k. * stage0: Use the dice library to implement minimal self-signed credentials. This commit collects the DICE CDI from the NXP ROM, creates an ed25519 key pair from it (effectively the DeviceId) and uses this key to create a self-signed DeviceId cert. The hash of the hubris image that will be launched by stage0 is then hashed and the output used to generate the Alias credentials (used for attestation). Finally the keying material used to create the Alias key, and the cert chain from the Alias back to the DeviceId are written to memory for use in an attestation exchange by a future hubris task. If run on an lpc55 with DICE disabled (the default config) none of the DICE artifacts will be created and hubris will be booted as usual.
1 parent 38fdedf commit addb97d

File tree

14 files changed

+1180
-58
lines changed

14 files changed

+1180
-58
lines changed

Cargo.lock

+172-52
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/lpc55xpresso/stage0.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ name = "lpc55xpresso"
22
target = "thumbv8m.main-none-eabihf"
33
board = "lpcxpresso55s69"
44
chip = "../../chips/lpc55"
5-
stacksize = 1024
65
secure-separation = true
76
image-names = ["stage0"]
87
external-images = ["a", "b"]
98

109
[kernel]
1110
name = "stage0"
12-
requires = {flash = 0x4000, ram = 4096}
13-
features = ["tz_support"]
11+
requires = {flash = 0x7000, ram = 8192}
12+
features = ["tz_support", "dice"]
13+
stacksize = 8000
1414

1515
[tasks.idle]
1616
name = "task-idle"

build/xtask/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ zerocopy = "0.6.1"
4040
# For NXP signing
4141
[dependencies.lpc55_sign]
4242
git = "https://github.com/oxidecomputer/lpc55_support"
43-
rev = "edbc00749b708d5bc48c5fe0f1df0d1ed6f054c2"
43+
rev = "f7ccf6d607b1a51fcb5f93a9f53d6c2f8366cc5a"

chips/lpc55/chip.toml

+6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ size = 4096
4646
address = 0x4003A000
4747
size = 4096
4848

49+
# this is the start of the USB SRAM AHB peripheral (0x4000 bytes total)
50+
# we appropriate this SRAM for passing DICE artifacts
51+
[dice_alias]
52+
address = 0x40100000
53+
size = 0x800
54+
4955
[flash]
5056
address = 0x50034000
5157
size = 0x1000

lib/dice/Cargo.toml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "dice"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
hkdf = { version = "0.12", default-features = false }
8+
hubpack = "0.1"
9+
lpc55-pac = "0.3"
10+
salty = "0.2"
11+
serde = { version = "1", default-features = false, features = ["derive"] }
12+
serde-big-array = "0.4"
13+
sha3 = { version = "0.10", default-features = false }
14+
unwrap-lite = { path = "../unwrap-lite" }
15+
zeroize = { version = "1.5.7", default-features = false, features = ["zeroize_derive"] }
16+
17+
[dev-dependencies]
18+
chrono = "0.4"

lib/dice/src/alias_cert_tmpl.rs

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
5+
// NOTE: This DER blob, offsets & lengths is mostly generated code. This was
6+
// accomplished by creating a certificate with the desired structure (including
7+
// DICE specific extensions and policy) using the openssl ca tools. The fields
8+
// that we need to operate on were identified and their offsets recorded. The
9+
// values in these regions (signatureValue, serialNumber, issuer, subject,
10+
// validity etc) are then removed.
11+
//
12+
// TODO: generate cert template DER from ASN.1 & text config
13+
#[allow(dead_code)]
14+
pub const SIZE: usize = 608;
15+
#[allow(dead_code)]
16+
pub const SERIAL_NUMBER_START: usize = 15;
17+
#[allow(dead_code)]
18+
pub const SERIAL_NUMBER_END: usize = 16;
19+
#[allow(dead_code)]
20+
pub const ISSUER_SN_START: usize = 169;
21+
#[allow(dead_code)]
22+
pub const ISSUER_SN_END: usize = 181;
23+
#[allow(dead_code)]
24+
pub const SN_LENGTH: usize = 12;
25+
#[allow(dead_code)]
26+
pub const NOTBEFORE_START: usize = 185;
27+
#[allow(dead_code)]
28+
pub const NOTBEFORE_END: usize = 198;
29+
#[allow(dead_code)]
30+
pub const NOTBEFORE_LENGTH: usize = 13;
31+
#[allow(dead_code)]
32+
pub const SUBJECT_SN_START: usize = 357;
33+
#[allow(dead_code)]
34+
pub const SUBJECT_SN_END: usize = 369;
35+
#[allow(dead_code)]
36+
pub const PUB_START: usize = 381;
37+
#[allow(dead_code)]
38+
pub const PUB_END: usize = 413;
39+
#[allow(dead_code)]
40+
pub const SIG_START: usize = 544;
41+
#[allow(dead_code)]
42+
pub const SIG_END: usize = 608;
43+
#[allow(dead_code)]
44+
pub const SIGNDATA_START: usize = 4;
45+
#[allow(dead_code)]
46+
pub const SIGNDATA_END: usize = 534;
47+
#[allow(dead_code)]
48+
pub const SIGNDATA_LENGTH: usize = 530;
49+
#[allow(dead_code)]
50+
pub const FWID_START: usize = 502;
51+
#[allow(dead_code)]
52+
pub const FWID_END: usize = 534;
53+
#[allow(dead_code)]
54+
pub const FWID_LENGTH: usize = 32;
55+
pub const CERT_TMPL: [u8; 608] = [
56+
0x30, 0x82, 0x02, 0x5c, 0x30, 0x82, 0x02, 0x0e, 0xa0, 0x03, 0x02, 0x01,
57+
0x02, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x70, 0x30,
58+
0x81, 0x9b, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13,
59+
0x02, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08,
60+
0x0c, 0x0a, 0x43, 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e, 0x69, 0x61,
61+
0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x0a, 0x45,
62+
0x6d, 0x65, 0x72, 0x79, 0x76, 0x69, 0x6c, 0x6c, 0x65, 0x31, 0x1f, 0x30,
63+
0x1d, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x16, 0x4f, 0x78, 0x69, 0x64,
64+
0x65, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x75, 0x74, 0x65, 0x72, 0x20, 0x43,
65+
0x6f, 0x6d, 0x70, 0x61, 0x6e, 0x79, 0x31, 0x16, 0x30, 0x14, 0x06, 0x03,
66+
0x55, 0x04, 0x0b, 0x0c, 0x0d, 0x4d, 0x61, 0x6e, 0x75, 0x66, 0x61, 0x63,
67+
0x74, 0x75, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03,
68+
0x55, 0x04, 0x03, 0x0c, 0x09, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x2d,
69+
0x69, 0x64, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x05, 0x13,
70+
0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
71+
0x00, 0x30, 0x20, 0x17, 0x0d, 0x32, 0x32, 0x30, 0x37, 0x33, 0x31, 0x31,
72+
0x37, 0x30, 0x30, 0x34, 0x34, 0x5a, 0x18, 0x0f, 0x39, 0x39, 0x39, 0x39,
73+
0x31, 0x32, 0x33, 0x31, 0x32, 0x33, 0x35, 0x39, 0x35, 0x39, 0x5a, 0x30,
74+
0x81, 0x97, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13,
75+
0x02, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08,
76+
0x0c, 0x0a, 0x43, 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e, 0x69, 0x61,
77+
0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x0a, 0x45,
78+
0x6d, 0x65, 0x72, 0x79, 0x76, 0x69, 0x6c, 0x6c, 0x65, 0x31, 0x1f, 0x30,
79+
0x1d, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x16, 0x4f, 0x78, 0x69, 0x64,
80+
0x65, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x75, 0x74, 0x65, 0x72, 0x20, 0x43,
81+
0x6f, 0x6d, 0x70, 0x61, 0x6e, 0x79, 0x31, 0x16, 0x30, 0x14, 0x06, 0x03,
82+
0x55, 0x04, 0x0b, 0x0c, 0x0d, 0x4d, 0x61, 0x6e, 0x75, 0x66, 0x61, 0x63,
83+
0x74, 0x75, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x0e, 0x30, 0x0c, 0x06, 0x03,
84+
0x55, 0x04, 0x03, 0x0c, 0x05, 0x61, 0x6c, 0x69, 0x61, 0x73, 0x31, 0x15,
85+
0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x05, 0x13, 0x0c, 0x00, 0x00, 0x00,
86+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x2a, 0x30,
87+
0x05, 0x06, 0x03, 0x2b, 0x65, 0x70, 0x03, 0x21, 0x00, 0x00, 0x00, 0x00,
88+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
89+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
90+
0x00, 0x00, 0x00, 0x00, 0x00, 0xa3, 0x77, 0x30, 0x75, 0x30, 0x09, 0x06,
91+
0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, 0x0e, 0x06, 0x03,
92+
0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x03, 0xa8,
93+
0x30, 0x17, 0x06, 0x03, 0x55, 0x1d, 0x20, 0x01, 0x01, 0xff, 0x04, 0x0d,
94+
0x30, 0x0b, 0x30, 0x09, 0x06, 0x07, 0x67, 0x81, 0x05, 0x05, 0x04, 0x64,
95+
0x08, 0x30, 0x3f, 0x06, 0x05, 0x67, 0x81, 0x05, 0x05, 0x04, 0x01, 0x01,
96+
0xff, 0x04, 0x33, 0x30, 0x31, 0xa6, 0x2f, 0x30, 0x2d, 0x06, 0x09, 0x60,
97+
0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x08, 0x04, 0x20, 0x00, 0x00,
98+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
99+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
100+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65,
101+
0x70, 0x03, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
102+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
103+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
104+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
105+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
106+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
107+
];

0 commit comments

Comments
 (0)