Skip to content

Commit b1faaca

Browse files
committed
[rom_ext_e2e] Add an ownership transfer test
1. Create a library of helper functions for facilitating ownership transfer tests. 2. Create a basic ownership transfer test that transfers chip ownership from the default `fake` test owner to a `dummy` owner. Signed-off-by: Chris Frantz <[email protected]> (cherry picked from commit 0ad99c9) (cherry picked from commit 71cc612)
1 parent 23df5ef commit b1faaca

File tree

12 files changed

+318
-9
lines changed

12 files changed

+318
-9
lines changed

quality/BUILD.bazel

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,19 +173,21 @@ RUST_TARGETS = [
173173
"//sw/host/hsmtool:hsmlib",
174174
"//sw/host/hsmtool:hsmlib_test",
175175
"//sw/host/hsmtool/acorn:acorn",
176-
"//sw/host/ot_certs:ot_certs",
177-
"//sw/host/ot_certs:ot_certs_test",
178176
"//sw/host/opentitanlib:opentitanlib",
179177
"//sw/host/opentitanlib:opentitanlib_test",
180178
"//sw/host/opentitansession:opentitansession",
181179
"//sw/host/opentitantool:opentitantool",
180+
"//sw/host/ot_certs:ot_certs",
181+
"//sw/host/ot_certs:ot_certs_test",
182182
"//sw/host/tests/chip/gpio:gpio",
183183
"//sw/host/tests/chip/power_virus:power_virus",
184+
"//sw/host/tests/chip/spi_device:spi_passthru",
185+
"//sw/host/tests/ownership:transfer_lib",
186+
"//sw/host/tests/ownership:transfer_test",
184187
"//sw/host/tests/rom/e2e_bootstrap_disabled:e2e_bootstrap_disabled",
185188
"//sw/host/tests/rom/e2e_bootstrap_entry:e2e_bootstrap_entry",
186189
"//sw/host/tests/rom/e2e_chip_specific_startup:e2e_chip_specific_startup",
187190
"//sw/host/tests/rom/sw_strap_value:sw_strap_value",
188-
"//sw/host/tests/chip/spi_device:spi_passthru",
189191
"//sw/host/tests/xmodem:lrzsz_test",
190192
"//sw/host/tests/xmodem:xmodem",
191193
"//sw/host/sphincsplus:sphincsplus",
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright lowRISC contributors (OpenTitan project).
2+
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
load(
6+
"//rules/opentitan:defs.bzl",
7+
"fpga_params",
8+
"opentitan_test",
9+
)
10+
11+
package(default_visibility = ["//visibility:public"])
12+
13+
opentitan_test(
14+
name = "ownership_transfer_test",
15+
srcs = ["//sw/device/silicon_creator/rom_ext/e2e/verified_boot:boot_test"],
16+
exec_env = {
17+
"//hw/top_earlgrey:fpga_hyper310_rom_ext": None,
18+
},
19+
fpga = fpga_params(
20+
# This test doesn't change OTP, but it modifies the ownership INFO
21+
# pages, so we need to clear the bitstream after the test, which is
22+
# what the `changes_otp` parameter actually does.
23+
changes_otp = True,
24+
data = [
25+
"//sw/device/silicon_creator/lib/ownership/keys/dummy:activate_key",
26+
"//sw/device/silicon_creator/lib/ownership/keys/dummy:app_prod_pub",
27+
"//sw/device/silicon_creator/lib/ownership/keys/dummy:owner_key",
28+
"//sw/device/silicon_creator/lib/ownership/keys/dummy:unlock_key",
29+
"//sw/device/silicon_creator/lib/ownership/keys/fake:unlock_key",
30+
],
31+
test_cmd = """
32+
--clear-bitstream
33+
--bootstrap={firmware}
34+
--unlock-key=$(location //sw/device/silicon_creator/lib/ownership/keys/fake:unlock_key)
35+
--next-owner-key=$(location //sw/device/silicon_creator/lib/ownership/keys/dummy:owner_key)
36+
--next-unlock-key=$(location //sw/device/silicon_creator/lib/ownership/keys/dummy:unlock_key)
37+
--next-activate-key=$(location //sw/device/silicon_creator/lib/ownership/keys/dummy:activate_key)
38+
--next-application-key=$(location //sw/device/silicon_creator/lib/ownership/keys/dummy:app_prod_pub)
39+
""",
40+
test_harness = "//sw/host/tests/ownership:transfer_test",
41+
),
42+
rsa_key = {
43+
"//sw/device/silicon_creator/lib/ownership/keys/dummy:app_prod": "app_prod",
44+
},
45+
deps = [
46+
"//sw/device/lib/base:status",
47+
"//sw/device/lib/testing/test_framework:ottf_main",
48+
"//sw/device/silicon_creator/lib:boot_log",
49+
"//sw/device/silicon_creator/lib/drivers:retention_sram",
50+
],
51+
)

sw/device/silicon_creator/rom_ext/e2e/verified_boot/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright lowRISC contributors (OpenTitan project).
22
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
# SPDX-License-Identifier: Apache-2.0
4+
45
load(
56
"//rules/opentitan:defs.bzl",
67
"DEFAULT_TEST_FAILURE_MSG",

sw/host/opentitanlib/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ rust_library(
8282
"src/chip/boot_log.rs",
8383
"src/chip/boot_svc.rs",
8484
"src/chip/helper.rs",
85-
"src/chip/rom_error.rs",
8685
"src/chip/mod.rs",
86+
"src/chip/rom_error.rs",
8787
"src/console/mod.rs",
8888
"src/console/spi.rs",
8989
"src/crypto/ecdsa.rs",

sw/host/opentitanlib/src/chip/helper.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::fs::File;
1111
use std::io::Read;
1212
use std::path::PathBuf;
1313

14-
#[derive(Debug, Args)]
14+
#[derive(Debug, Default, Args)]
1515
pub struct OwnershipUnlockParams {
1616
#[arg(long, value_enum, help = "Requested unlock mode")]
1717
pub mode: Option<UnlockMode>,
@@ -63,7 +63,7 @@ impl OwnershipUnlockParams {
6363
}
6464
}
6565

66-
#[derive(Debug, Args)]
66+
#[derive(Debug, Default, Args)]
6767
pub struct OwnershipActivateParams {
6868
#[arg(long, value_parser = u64::from_str, help="Current ROM_EXT nonce")]
6969
pub nonce: Option<u64>,

sw/host/opentitanlib/src/crypto/ecdsa.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,13 @@ impl TryFrom<&EcdsaPublicKey> for EcdsaRawPublicKey {
226226
}
227227
}
228228

229+
impl TryFrom<EcdsaPublicKey> for EcdsaRawPublicKey {
230+
type Error = Error;
231+
fn try_from(v: EcdsaPublicKey) -> Result<Self, Self::Error> {
232+
EcdsaRawPublicKey::try_from(&v)
233+
}
234+
}
235+
229236
impl FromStr for EcdsaRawPublicKey {
230237
type Err = Error;
231238
fn from_str(s: &str) -> Result<Self, Self::Err> {

sw/host/opentitanlib/src/crypto/rsa.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,13 @@ impl TryFrom<&RsaPublicKey> for RsaRawPublicKey {
273273
}
274274
}
275275

276+
impl TryFrom<RsaPublicKey> for RsaRawPublicKey {
277+
type Error = Error;
278+
fn try_from(v: RsaPublicKey) -> Result<Self, Self::Error> {
279+
RsaRawPublicKey::try_from(&v)
280+
}
281+
}
282+
276283
impl FromStr for RsaRawPublicKey {
277284
type Err = Error;
278285
fn from_str(s: &str) -> Result<Self, Self::Err> {

sw/host/opentitanlib/src/ownership/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ mod rescue;
1212
pub use application_key::{ApplicationKeyDomain, OwnerApplicationKey};
1313
pub use flash::{FlashFlags, OwnerFlashConfig, OwnerFlashRegion};
1414
pub use flash_info::{OwnerFlashInfoConfig, OwnerInfoPage};
15-
pub use misc::{OwnershipKeyAlg, TlvHeader, TlvTag};
16-
pub use owner::{OwnerBlock, SramExecMode};
15+
pub use misc::{KeyMaterial, OwnershipKeyAlg, TlvHeader, TlvTag};
16+
pub use owner::{OwnerBlock, OwnerConfigItem, SramExecMode};
1717
pub use rescue::{OwnerRescueConfig, RescueType};

sw/host/opentitanlib/src/rescue/xmodem.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ impl Xmodem {
9797
}
9898
}
9999
_ => {
100-
log::info!("Unknown byte received while waiting for XMODEM start: {ch:#x?}");
100+
let p = ch as char;
101+
log::info!(
102+
"Unknown byte received while waiting for XMODEM start: {p:?} ({ch:#x?})"
103+
);
101104
}
102105
}
103106
}

sw/host/tests/ownership/BUILD

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright lowRISC contributors (OpenTitan project).
2+
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library")
6+
load("//rules:ujson.bzl", "ujson_rust")
7+
8+
package(default_visibility = ["//visibility:public"])
9+
10+
rust_library(
11+
name = "transfer_lib",
12+
srcs = ["transfer_lib.rs"],
13+
deps = [
14+
"//sw/host/opentitanlib",
15+
"@crate_index//:anyhow",
16+
"@crate_index//:log",
17+
],
18+
)
19+
20+
rust_binary(
21+
name = "transfer_test",
22+
srcs = [
23+
"transfer_test.rs",
24+
],
25+
deps = [
26+
":transfer_lib",
27+
"//sw/host/opentitanlib",
28+
"@crate_index//:anyhow",
29+
"@crate_index//:clap",
30+
"@crate_index//:humantime",
31+
"@crate_index//:log",
32+
],
33+
)

0 commit comments

Comments
 (0)