Skip to content

Commit

Permalink
sprot: Expose log & log_len from the Attest task.
Browse files Browse the repository at this point in the history
  • Loading branch information
flihp committed Sep 27, 2023
1 parent 04457d3 commit 11faed8
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/oxide-rot-1/app-dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ task-slots = ["syscon_driver"]
[tasks.sprot]
name = "drv-lpc55-sprot-server"
priority = 6
max-sizes = {flash = 45792, ram = 32768}
max-sizes = {flash = 46300, ram = 32768}
uses = ["flexcomm8", "bootrom"]
features = ["spi0"]
start = true
Expand Down
2 changes: 1 addition & 1 deletion app/oxide-rot-1/app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ task-slots = ["syscon_driver"]
[tasks.sprot]
name = "drv-lpc55-sprot-server"
priority = 6
max-sizes = {flash = 45792, ram = 32768}
max-sizes = {flash = 46300, ram = 32768}
uses = ["flexcomm8", "bootrom"]
features = ["spi0"]
start = true
Expand Down
2 changes: 1 addition & 1 deletion app/rot-carrier/app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ task-slots = ["syscon_driver"]
[tasks.sprot]
name = "drv-lpc55-sprot-server"
priority = 6
max-sizes = {flash = 45792, ram = 32768}
max-sizes = {flash = 46300, ram = 32768}
uses = ["flexcomm8", "bootrom"]
features = ["spi0"]
start = true
Expand Down
39 changes: 36 additions & 3 deletions drv/lpc55-sprot-server/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ pub struct StartupState {
/// Marker for data which should be copied after the packet is encoded
pub enum TrailingData {
Caboose { slot: SlotId, start: u32, size: u32 },
Attest { index: u32, offset: u32, size: u32 },
AttestCert { index: u32, offset: u32, size: u32 },
AttestLog { offset: u32, size: u32 },
RotPage { page: RotPage },
}

Expand Down Expand Up @@ -135,7 +136,7 @@ impl Handler {
}
}
}
Some(TrailingData::Attest {
Some(TrailingData::AttestCert {
index,
offset,
size,
Expand Down Expand Up @@ -176,6 +177,27 @@ impl Handler {
Err(e) => Response::pack(&Ok(e), tx_buf),
}
}
Some(TrailingData::AttestLog { offset, size }) => {
let size: usize = usize::try_from(size).unwrap_lite();
if size > drv_sprot_api::MAX_BLOB_SIZE {
Response::pack(
&Err(SprotError::Protocol(
SprotProtocolError::BadMessageLength,
)),
tx_buf,
)
} else {
match Response::pack_with_cb(&rsp_body, tx_buf, |buf| {
self.attest
.log(offset, &mut buf[..size])
.map_err(|e| RspBody::Attest(Err(e)))?;
Ok(size)
}) {
Ok(size) => size,
Err(e) => Response::pack(&Ok(e), tx_buf),
}
}
}
_ => Response::pack(&rsp_body, tx_buf),
}
}
Expand Down Expand Up @@ -296,7 +318,7 @@ impl Handler {
// the work can be done elsewhere.
Ok((
RspBody::Attest(Ok(AttestRsp::Cert)),
Some(TrailingData::Attest {
Some(TrailingData::AttestCert {
index,
offset,
size,
Expand Down Expand Up @@ -334,6 +356,17 @@ impl Handler {
Some(TrailingData::RotPage { page }),
))
}
ReqBody::Attest(AttestReq::Log { offset, size }) => Ok((
RspBody::Attest(Ok(AttestRsp::Log)),
Some(TrailingData::AttestLog { offset, size }),
)),
ReqBody::Attest(AttestReq::LogLen) => {
let rsp = match self.attest.log_len() {
Ok(l) => Ok(AttestRsp::LogLen(l)),
Err(e) => Err(e),
};
Ok((RspBody::Attest(rsp), None))
}
}
}
}
4 changes: 4 additions & 0 deletions drv/sprot-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ pub enum AttestReq {
CertLen(u32),
Cert { index: u32, offset: u32, size: u32 },
Record { algorithm: HashAlgorithm },
Log { offset: u32, size: u32 },
LogLen,
}

/// A response used for RoT updates
Expand All @@ -410,6 +412,8 @@ pub enum AttestRsp {
CertLen(u32),
Cert,
Record,
Log,
LogLen(u32),
}

/// The body of a sprot response.
Expand Down
61 changes: 61 additions & 0 deletions drv/stm32h7-sprot-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,67 @@ impl<S: SpiServer> idl::InOrderSpRotImpl for ServerImpl<S> {
Err(e) => Err(e.into()),
}
}

fn log(
&mut self,
_msg: &userlib::RecvMessage,
offset: u32,
data: idol_runtime::Leased<idol_runtime::W, [u8]>,
) -> Result<(), idol_runtime::RequestError<AttestOrSprotError>> {
let body = ReqBody::Attest(AttestReq::Log {
offset,
size: data.len() as u32,
});
let tx_size = Request::pack(&body, &mut self.tx_buf);
let rsp =
self.do_send_recv_retries(tx_size, DUMP_TIMEOUT, DEFAULT_ATTEMPTS)?;

match rsp.body {
Ok(RspBody::Attest(Ok(AttestRsp::Log))) => {
// Copy from the trailing data into the lease
if rsp.blob.len() < data.len() {
return Err(idol_runtime::RequestError::Fail(
idol_runtime::ClientError::BadLease,
));
}
data.write_range(0..data.len(), &rsp.blob[..data.len()])
.map_err(|()| {
idol_runtime::RequestError::Fail(
idol_runtime::ClientError::WentAway,
)
})?;
Ok(())
}
Ok(RspBody::Attest(Err(e))) => {
Err(AttestOrSprotError::Attest(e).into())
}
Ok(RspBody::Attest(_)) | Ok(_) => Err(AttestOrSprotError::Sprot(
SprotError::Protocol(SprotProtocolError::UnexpectedResponse),
)
.into()),
Err(e) => Err(AttestOrSprotError::Sprot(e).into()),
}
}

fn log_len(
&mut self,
_msg: &userlib::RecvMessage,
) -> Result<u32, idol_runtime::RequestError<AttestOrSprotError>> {
let body = ReqBody::Attest(AttestReq::LogLen);
let tx_size = Request::pack(&body, &mut self.tx_buf);
let rsp = self.do_send_recv_retries(tx_size, TIMEOUT_QUICK, 1)?;
match rsp.body {
Ok(RspBody::Attest(Ok(AttestRsp::LogLen(s)))) => Ok(s),
Ok(RspBody::Attest(Err(e))) => {
Err(AttestOrSprotError::Attest(e).into())
}
Ok(RspBody::Attest(_)) | Ok(_) => Err(AttestOrSprotError::Sprot(
SprotError::Protocol(SprotProtocolError::UnexpectedResponse),
)
.into()),
Err(e) => Err(AttestOrSprotError::Sprot(e).into()),
}
}
}

mod idl {
Expand Down
26 changes: 24 additions & 2 deletions idl/sprot.idol
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,28 @@ Interface(
encoding: Hubpack,
idempotent: true,
),

}
"log": (
doc: "Get the measurement log",
args: {
"offset" : "u32",
},
leases: {
"dest": (type: "[u8]", write: true),
},
reply: Result(
ok: "()",
err: Complex("AttestOrSprotError"),
),
encoding: Hubpack,
),
"log_len": (
doc: "Get length of the serialized measurement log",
reply: Result(
ok: "u32",
err: Complex("AttestOrSprotError"),
),
encoding: Hubpack,
idempotent: true,
),
}
)

0 comments on commit 11faed8

Please sign in to comment.