Skip to content

Commit f16b8c2

Browse files
committed
Add trace logging on method calls and exit
That would allow to make sure that Parsec is indeed useful :) Signed-off-by: Hugues de Valon <hugues.devalon@arm.com>
1 parent 478e312 commit f16b8c2

File tree

9 files changed

+69
-9
lines changed

9 files changed

+69
-9
lines changed

src/back/backend_handler.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use crate::authenticators::ApplicationName;
99
use crate::providers::Provide;
1010
use derivative::Derivative;
11+
use log::trace;
1112
use parsec_interface::operations::Convert;
1213
use parsec_interface::operations::{NativeOperation, NativeResult};
1314
use parsec_interface::requests::{
@@ -78,6 +79,7 @@ impl BackEndHandler {
7879
/// If any of the steps fails, a response containing an appropriate status code is
7980
/// returned.
8081
pub fn execute_request(&self, request: Request, app_name: Option<ApplicationName>) -> Response {
82+
trace!("execute_request ingress");
8183
let opcode = request.header.opcode;
8284
let header = request.header;
8385

@@ -94,14 +96,17 @@ impl BackEndHandler {
9496
NativeOperation::ListProviders(op_list_providers) => {
9597
let result =
9698
unwrap_or_else_return!(self.provider.list_providers(op_list_providers));
99+
trace!("list_providers egress");
97100
self.result_to_response(NativeResult::ListProviders(result), header)
98101
}
99102
NativeOperation::ListOpcodes(op_list_opcodes) => {
100103
let result = unwrap_or_else_return!(self.provider.list_opcodes(op_list_opcodes));
104+
trace!("list_opcodes egress");
101105
self.result_to_response(NativeResult::ListOpcodes(result), header)
102106
}
103107
NativeOperation::Ping(op_ping) => {
104108
let result = unwrap_or_else_return!(self.provider.ping(op_ping));
109+
trace!("ping egress");
105110
self.result_to_response(NativeResult::Ping(result), header)
106111
}
107112
NativeOperation::PsaGenerateKey(op_generate_key) => {
@@ -110,13 +115,15 @@ impl BackEndHandler {
110115
let result = unwrap_or_else_return!(self
111116
.provider
112117
.psa_generate_key(app_name, op_generate_key));
118+
trace!("psa_generate_key egress");
113119
self.result_to_response(NativeResult::PsaGenerateKey(result), header)
114120
}
115121
NativeOperation::PsaImportKey(op_import_key) => {
116122
let app_name =
117123
unwrap_or_else_return!(app_name.ok_or(ResponseStatus::NotAuthenticated));
118124
let result =
119125
unwrap_or_else_return!(self.provider.psa_import_key(app_name, op_import_key));
126+
trace!("psa_import_key egress");
120127
self.result_to_response(NativeResult::PsaImportKey(result), header)
121128
}
122129
NativeOperation::PsaExportPublicKey(op_export_public_key) => {
@@ -125,27 +132,31 @@ impl BackEndHandler {
125132
let result = unwrap_or_else_return!(self
126133
.provider
127134
.psa_export_public_key(app_name, op_export_public_key));
135+
trace!("psa_export_public_key egress");
128136
self.result_to_response(NativeResult::PsaExportPublicKey(result), header)
129137
}
130138
NativeOperation::PsaDestroyKey(op_destroy_key) => {
131139
let app_name =
132140
unwrap_or_else_return!(app_name.ok_or(ResponseStatus::NotAuthenticated));
133141
let result =
134142
unwrap_or_else_return!(self.provider.psa_destroy_key(app_name, op_destroy_key));
143+
trace!("psa_destroy_key egress");
135144
self.result_to_response(NativeResult::PsaDestroyKey(result), header)
136145
}
137146
NativeOperation::PsaSignHash(op_sign_hash) => {
138147
let app_name =
139148
unwrap_or_else_return!(app_name.ok_or(ResponseStatus::NotAuthenticated));
140149
let result =
141150
unwrap_or_else_return!(self.provider.psa_sign_hash(app_name, op_sign_hash));
151+
trace!("psa_sign_hash egress");
142152
self.result_to_response(NativeResult::PsaSignHash(result), header)
143153
}
144154
NativeOperation::PsaVerifyHash(op_verify_hash) => {
145155
let app_name =
146156
unwrap_or_else_return!(app_name.ok_or(ResponseStatus::NotAuthenticated));
147157
let result =
148158
unwrap_or_else_return!(self.provider.psa_verify_hash(app_name, op_verify_hash));
159+
trace!("psa_verify_hash egress");
149160
self.result_to_response(NativeResult::PsaVerifyHash(result), header)
150161
}
151162
}

src/back/dispatcher.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//! said provider is available on the system, thus acting as a multiplexer.
77
use super::backend_handler::BackEndHandler;
88
use crate::authenticators::ApplicationName;
9+
use log::trace;
910
use parsec_interface::requests::request::Request;
1011
use parsec_interface::requests::ProviderID;
1112
use parsec_interface::requests::{Response, ResponseStatus};
@@ -36,11 +37,16 @@ impl Dispatcher {
3637
request: Request,
3738
app_name: Option<ApplicationName>,
3839
) -> Response {
40+
trace!("dispatch_request ingress");
3941
if let Some(backend) = self.backends.get(&request.header.provider) {
4042
if let Err(status) = backend.is_capable(&request) {
4143
Response::from_request_header(request.header, status)
4244
} else {
43-
backend.execute_request(request, app_name)
45+
{
46+
let response = backend.execute_request(request, app_name);
47+
trace!("execute_request egress");
48+
response
49+
}
4450
}
4551
} else {
4652
Response::from_request_header(request.header, ResponseStatus::ProviderNotRegistered)

src/bin/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
// This one is hard to avoid.
3232
#![allow(clippy::multiple_crate_versions)]
3333

34-
use log::info;
34+
use log::{info, trace};
3535
use parsec_service::utils::{ServiceBuilder, ServiceConfig};
3636
use signal_hook::{flag, SIGHUP, SIGTERM};
3737
use std::io::{Error, ErrorKind, Result};
@@ -129,6 +129,7 @@ fn main() -> Result<()> {
129129
let front_end_handler = front_end_handler.clone();
130130
threadpool.execute(move || {
131131
front_end_handler.handle_request(stream);
132+
trace!("handle_request egress");
132133
});
133134
} else {
134135
::std::thread::sleep(Duration::from_millis(

src/front/front_end.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use crate::authenticators::Authenticate;
88
use crate::back::dispatcher::Dispatcher;
99
use derivative::Derivative;
10-
use log::{error, info};
10+
use log::{error, info, trace};
1111
use parsec_interface::requests::AuthType;
1212
use parsec_interface::requests::ResponseStatus;
1313
use parsec_interface::requests::{Request, Response};
@@ -41,6 +41,7 @@ impl FrontEndHandler {
4141
/// If an error occurs during (un)marshalling, no operation will be performed and the
4242
/// method will return.
4343
pub fn handle_request<T: Read + Write>(&self, mut stream: T) {
44+
trace!("handle_request ingress");
4445
// Read bytes from stream
4546
// De-Serialise bytes into a request
4647
let request = match Request::read_from_stream(&mut stream, self.body_len_limit) {
@@ -57,14 +58,20 @@ impl FrontEndHandler {
5758
};
5859
// Check if the request was sent without authentication
5960
let response = if AuthType::NoAuth == request.header.auth_type {
60-
self.dispatcher.dispatch_request(request, None)
61+
let response = self.dispatcher.dispatch_request(request, None);
62+
trace!("dispatch_request egress");
63+
response
6164
// Otherwise find an authenticator that is capable to authenticate the request
6265
} else if let Some(authenticator) = self.authenticators.get(&request.header.auth_type) {
6366
// Authenticate the request
6467
match authenticator.authenticate(&request.auth) {
6568
// Send the request to the dispatcher
6669
// Get a response back
67-
Ok(app_name) => self.dispatcher.dispatch_request(request, Some(app_name)),
70+
Ok(app_name) => {
71+
let response = self.dispatcher.dispatch_request(request, Some(app_name));
72+
trace!("dispatch_request egress");
73+
response
74+
}
6875
Err(status) => Response::from_request_header(request.header, status),
6976
}
7077
} else {

src/providers/core_provider/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//! aiding clients in discovering the capabilities offered by their underlying
77
//! platform.
88
use super::Provide;
9-
use log::error;
9+
use log::{error, trace};
1010
use parsec_interface::operations::list_providers::ProviderInfo;
1111
use parsec_interface::operations::{list_opcodes, list_providers, ping};
1212
use parsec_interface::requests::{Opcode, ProviderID, ResponseStatus, Result};
@@ -33,6 +33,7 @@ pub struct CoreProvider {
3333

3434
impl Provide for CoreProvider {
3535
fn list_opcodes(&self, op: list_opcodes::Operation) -> Result<list_opcodes::Result> {
36+
trace!("list_opcodes ingress");
3637
Ok(list_opcodes::Result {
3738
opcodes: self
3839
.provider_opcodes
@@ -43,12 +44,14 @@ impl Provide for CoreProvider {
4344
}
4445

4546
fn list_providers(&self, _op: list_providers::Operation) -> Result<list_providers::Result> {
47+
trace!("list_providers ingress");
4648
Ok(list_providers::Result {
4749
providers: self.provider_info.clone(),
4850
})
4951
}
5052

5153
fn ping(&self, _op: ping::Operation) -> Result<ping::Result> {
54+
trace!("ping ingress");
5255
let result = ping::Result {
5356
wire_protocol_version_maj: self.wire_protocol_version_maj,
5457
wire_protocol_version_min: self.wire_protocol_version_min,

src/providers/mbed_provider/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::authenticators::ApplicationName;
55
use crate::key_info_managers::{KeyTriple, ManageKeyInfo};
66
use constants::PSA_SUCCESS;
77
use derivative::Derivative;
8-
use log::error;
8+
use log::{error, trace};
99
use parsec_interface::operations::list_providers::ProviderInfo;
1010
use parsec_interface::operations::{
1111
psa_destroy_key, psa_export_public_key, psa_generate_key, psa_import_key, psa_sign_hash,
@@ -153,6 +153,7 @@ impl MbedProvider {
153153

154154
impl Provide for MbedProvider {
155155
fn describe(&self) -> Result<(ProviderInfo, HashSet<Opcode>)> {
156+
trace!("describe ingress");
156157
Ok((ProviderInfo {
157158
// Assigned UUID for this provider: 1c1139dc-ad7c-47dc-ad6b-db6fdb466552
158159
uuid: Uuid::parse_str("1c1139dc-ad7c-47dc-ad6b-db6fdb466552").or(Err(ResponseStatus::InvalidEncoding))?,
@@ -170,6 +171,7 @@ impl Provide for MbedProvider {
170171
app_name: ApplicationName,
171172
op: psa_generate_key::Operation,
172173
) -> Result<psa_generate_key::Result> {
174+
trace!("psa_generate_key ingress");
173175
self.psa_generate_key_internal(app_name, op)
174176
}
175177

@@ -178,6 +180,7 @@ impl Provide for MbedProvider {
178180
app_name: ApplicationName,
179181
op: psa_import_key::Operation,
180182
) -> Result<psa_import_key::Result> {
183+
trace!("psa_import_key ingress");
181184
self.psa_import_key_internal(app_name, op)
182185
}
183186

@@ -186,6 +189,7 @@ impl Provide for MbedProvider {
186189
app_name: ApplicationName,
187190
op: psa_export_public_key::Operation,
188191
) -> Result<psa_export_public_key::Result> {
192+
trace!("psa_export_public_key ingress");
189193
self.psa_export_public_key_internal(app_name, op)
190194
}
191195

@@ -194,6 +198,7 @@ impl Provide for MbedProvider {
194198
app_name: ApplicationName,
195199
op: psa_destroy_key::Operation,
196200
) -> Result<psa_destroy_key::Result> {
201+
trace!("psa_destroy_key ingress");
197202
self.psa_destroy_key_internal(app_name, op)
198203
}
199204

@@ -202,6 +207,7 @@ impl Provide for MbedProvider {
202207
app_name: ApplicationName,
203208
op: psa_sign_hash::Operation,
204209
) -> Result<psa_sign_hash::Result> {
210+
trace!("psa_sign_hash ingress");
205211
self.psa_sign_hash_internal(app_name, op)
206212
}
207213

@@ -210,6 +216,7 @@ impl Provide for MbedProvider {
210216
app_name: ApplicationName,
211217
op: psa_verify_hash::Operation,
212218
) -> Result<psa_verify_hash::Result> {
219+
trace!("psa_verify_hash ingress");
213220
self.psa_verify_hash_internal(app_name, op)
214221
}
215222
}

src/providers/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//! are the real implementors of the operations that Parsec claims to support. They map to
77
//! functionality in the underlying hardware which allows the PSA Crypto operations to be
88
//! backed by a hardware root of trust.
9+
use log::trace;
910
use parsec_interface::requests::{Opcode, ProviderID};
1011
use serde::Deserialize;
1112
use std::collections::HashSet;
@@ -88,16 +89,19 @@ pub trait Provide {
8889
///
8990
/// The descriptions are gathered in the Core Provider and returned for a ListProviders operation.
9091
fn describe(&self) -> Result<(list_providers::ProviderInfo, HashSet<Opcode>)> {
92+
trace!("describe ingress");
9193
Err(ResponseStatus::PsaErrorNotSupported)
9294
}
9395

9496
/// List the providers running in the service.
9597
fn list_providers(&self, _op: list_providers::Operation) -> Result<list_providers::Result> {
98+
trace!("list_providers ingress");
9699
Err(ResponseStatus::PsaErrorNotSupported)
97100
}
98101

99102
/// List the opcodes supported by the given provider.
100103
fn list_opcodes(&self, _op: list_opcodes::Operation) -> Result<list_opcodes::Result> {
104+
trace!("list_opcodes ingress");
101105
Err(ResponseStatus::PsaErrorNotSupported)
102106
}
103107

@@ -108,6 +112,7 @@ pub trait Provide {
108112
/// This operation will only fail if not implemented. It will never fail when being called on
109113
/// the `CoreProvider`.
110114
fn ping(&self, _op: ping::Operation) -> Result<ping::Result> {
115+
trace!("ping ingress");
111116
Err(ResponseStatus::PsaErrorNotSupported)
112117
}
113118

@@ -117,6 +122,7 @@ pub trait Provide {
117122
_app_name: ApplicationName,
118123
_op: psa_generate_key::Operation,
119124
) -> Result<psa_generate_key::Result> {
125+
trace!("psa_generate_key ingress");
120126
Err(ResponseStatus::PsaErrorNotSupported)
121127
}
122128

@@ -126,6 +132,7 @@ pub trait Provide {
126132
_app_name: ApplicationName,
127133
_op: psa_import_key::Operation,
128134
) -> Result<psa_import_key::Result> {
135+
trace!("psa_import_key ingress");
129136
Err(ResponseStatus::PsaErrorNotSupported)
130137
}
131138

@@ -135,6 +142,7 @@ pub trait Provide {
135142
_app_name: ApplicationName,
136143
_op: psa_export_public_key::Operation,
137144
) -> Result<psa_export_public_key::Result> {
145+
trace!("psa_export_public_key ingress");
138146
Err(ResponseStatus::PsaErrorNotSupported)
139147
}
140148

@@ -144,6 +152,7 @@ pub trait Provide {
144152
_app_name: ApplicationName,
145153
_op: psa_destroy_key::Operation,
146154
) -> Result<psa_destroy_key::Result> {
155+
trace!("psa_destroy_key ingress");
147156
Err(ResponseStatus::PsaErrorNotSupported)
148157
}
149158

@@ -154,6 +163,7 @@ pub trait Provide {
154163
_app_name: ApplicationName,
155164
_op: psa_sign_hash::Operation,
156165
) -> Result<psa_sign_hash::Result> {
166+
trace!("psa_sign_hash ingress");
157167
Err(ResponseStatus::PsaErrorNotSupported)
158168
}
159169

@@ -163,6 +173,7 @@ pub trait Provide {
163173
_app_name: ApplicationName,
164174
_op: psa_verify_hash::Operation,
165175
) -> Result<psa_verify_hash::Result> {
176+
trace!("psa_verify_hash ingress");
166177
Err(ResponseStatus::PsaErrorNotSupported)
167178
}
168179
}

0 commit comments

Comments
 (0)