Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 13b1317

Browse files
committed
kernel: create AcceptedCredential type
1 parent d7272ef commit 13b1317

File tree

5 files changed

+37
-20
lines changed

5 files changed

+37
-20
lines changed

kernel/src/process.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ use crate::storage_permissions;
2020
use crate::syscall::{self, Syscall, SyscallReturn};
2121
use crate::upcall::UpcallId;
2222
use tock_tbf::types::CommandPermissions;
23-
use tock_tbf::types::TbfFooterV2Credentials;
2423

2524
// Export all process related types via `kernel::process::`.
2625
pub use crate::process_binary::ProcessBinary;
26+
pub use crate::process_checker::AcceptedCredential;
2727
pub use crate::process_checker::{ProcessCheckerMachine, ProcessCheckerMachineClient};
2828
pub use crate::process_loading::load_processes;
2929
pub use crate::process_loading::ProcessLoadError;
@@ -340,7 +340,7 @@ pub trait Process {
340340
/// Return the credential which the credential checker approved if the
341341
/// credential checker approved a credential. If the process was allowed to
342342
/// run without credentials, return `None`.
343-
fn get_credential(&self) -> Option<(TbfFooterV2Credentials, Option<core::num::NonZeroUsize>)>;
343+
fn get_credential(&self) -> Option<AcceptedCredential>;
344344

345345
/// Returns how many times this process has been restarted.
346346
fn get_restart_count(&self) -> usize;

kernel/src/process_binary.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use core::fmt;
1111

1212
use crate::config;
1313
use crate::debug;
14+
use crate::process_checker::AcceptedCredential;
1415
use crate::utilities::cells::OptionalCell;
15-
use tock_tbf::types::TbfFooterV2Credentials;
1616

1717
/// Errors resulting from trying to load a process binary structure from flash.
1818
pub enum ProcessBinaryError {
@@ -129,7 +129,7 @@ pub struct ProcessBinary {
129129
/// Optional credential that was used to approve this application. This is
130130
/// set if the process is checked by a credential checker and a specific
131131
/// credential was used to approve this process. Otherwise this is `None`.
132-
pub credential: OptionalCell<(TbfFooterV2Credentials, Option<core::num::NonZeroUsize>)>,
132+
pub credential: OptionalCell<AcceptedCredential>,
133133
}
134134

135135
impl ProcessBinary {
@@ -249,9 +249,7 @@ impl ProcessBinary {
249249
})
250250
}
251251

252-
pub fn get_credential(
253-
&self,
254-
) -> Option<(TbfFooterV2Credentials, Option<core::num::NonZeroUsize>)> {
252+
pub fn get_credential(&self) -> Option<AcceptedCredential> {
255253
self.credential.get()
256254
}
257255

kernel/src/process_checker.rs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,25 @@ pub trait AppCredentialsPolicyClient<'a> {
8383
);
8484
}
8585

86+
/// The accepted credential from the credential checker.
87+
///
88+
/// This combines both the credential as stored in the TBF footer with an
89+
/// optional opaque value provided by the checker when it accepted the
90+
/// credential. This value can be used when assigning an AppID to the
91+
/// application based on the how the credential was approved. For example, if
92+
/// the credential checker has a list of valid public keys used to verify
93+
/// signatures, it might set the optional value to the index of the public key
94+
/// in this list.
95+
#[derive(Copy, Clone)]
96+
pub struct AcceptedCredential {
97+
/// The credential stored in the footer that the credential checker
98+
/// accepted.
99+
pub credential: TbfFooterV2Credentials,
100+
/// An optional opaque value set by the credential checker to store metadata
101+
/// about the accepted credential. This is credential checker specific.
102+
pub metadata: Option<core::num::NonZeroUsize>,
103+
}
104+
86105
/// Implements a Credentials Checking Policy.
87106
pub trait AppCredentialsPolicy<'a> {
88107
/// Set the client which gets notified after the credential check completes.
@@ -187,10 +206,7 @@ pub trait ProcessCheckerMachineClient {
187206
fn done(
188207
&self,
189208
process_binary: ProcessBinary,
190-
result: Result<
191-
Option<(TbfFooterV2Credentials, Option<core::num::NonZeroUsize>)>,
192-
ProcessCheckError,
193-
>,
209+
result: Result<Option<AcceptedCredential>, ProcessCheckError>,
194210
);
195211
}
196212

@@ -441,7 +457,13 @@ impl AppCredentialsPolicyClient<'static> for ProcessCheckerMachine {
441457
Ok(CheckResult::Accept(opaque)) => {
442458
self.client.map(|client| {
443459
if let Some(pb) = self.process_binary.take() {
444-
client.done(pb, Ok(Some((credentials, opaque))))
460+
client.done(
461+
pb,
462+
Ok(Some(AcceptedCredential {
463+
credential: credentials,
464+
metadata: opaque,
465+
})),
466+
)
445467
}
446468
});
447469
false

kernel/src/process_loading.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ use crate::kernel::Kernel;
2323
use crate::platform::chip::Chip;
2424
use crate::process::{Process, ShortId};
2525
use crate::process_binary::{ProcessBinary, ProcessBinaryError};
26+
use crate::process_checker::AcceptedCredential;
2627
use crate::process_checker::{AppIdPolicy, ProcessCheckError, ProcessCheckerMachine};
2728
use crate::process_policies::ProcessFaultPolicy;
2829
use crate::process_standard::ProcessStandard;
2930
use crate::utilities::cells::{MapCell, OptionalCell};
30-
use tock_tbf::types::TbfFooterV2Credentials;
3131

3232
/// Errors that can occur when trying to load and create processes.
3333
pub enum ProcessLoadError {
@@ -906,10 +906,7 @@ impl<'a, C: Chip> crate::process_checker::ProcessCheckerMachineClient
906906
fn done(
907907
&self,
908908
process_binary: ProcessBinary,
909-
result: Result<
910-
Option<(TbfFooterV2Credentials, Option<core::num::NonZeroUsize>)>,
911-
crate::process_checker::ProcessCheckError,
912-
>,
909+
result: Result<Option<AcceptedCredential>, crate::process_checker::ProcessCheckError>,
913910
) {
914911
// Check if this process was approved by the checker.
915912
match result {

kernel/src/process_standard.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use crate::process::{Error, FunctionCall, FunctionCallSource, Process, Task};
2828
use crate::process::{FaultAction, ProcessCustomGrantIdentifier, ProcessId};
2929
use crate::process::{ProcessAddresses, ProcessSizes, ShortId};
3030
use crate::process::{State, StoppedState};
31+
use crate::process_checker::AcceptedCredential;
3132
use crate::process_loading::ProcessLoadError;
3233
use crate::process_policies::ProcessFaultPolicy;
3334
use crate::processbuffer::{ReadOnlyProcessBuffer, ReadWriteProcessBuffer};
@@ -37,7 +38,6 @@ use crate::upcall::UpcallId;
3738
use crate::utilities::cells::{MapCell, NumericCellExt, OptionalCell};
3839

3940
use tock_tbf::types::CommandPermissions;
40-
use tock_tbf::types::TbfFooterV2Credentials;
4141

4242
/// State for helping with debugging apps.
4343
///
@@ -189,7 +189,7 @@ pub struct ProcessStandard<'a, C: 'static + Chip> {
189189

190190
/// Credential that was approved for this process, or `None` if the
191191
/// credential was permitted to run without an accepted credential.
192-
credential: Option<(TbfFooterV2Credentials, Option<core::num::NonZeroUsize>)>,
192+
credential: Option<AcceptedCredential>,
193193

194194
/// State saved on behalf of the process each time the app switches to the
195195
/// kernel.
@@ -259,7 +259,7 @@ impl<C: Chip> Process for ProcessStandard<'_, C> {
259259
}
260260
}
261261

262-
fn get_credential(&self) -> Option<(TbfFooterV2Credentials, Option<core::num::NonZeroUsize>)> {
262+
fn get_credential(&self) -> Option<AcceptedCredential> {
263263
self.credential
264264
}
265265

0 commit comments

Comments
 (0)