Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Improve Mbed TLS debugging #505

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions runtime-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ name = "runtime_manager_enclave"
path = "src/main.rs"

[features]
debug = [
"session-manager/debug",
]
default = []
icecap = [
"bincode",
Expand Down
1 change: 1 addition & 0 deletions session-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ name = "session-manager"
version = "0.3.0"

[features]
debug = []
icecap = [
"policy-utils/icecap",
]
Expand Down
12 changes: 12 additions & 0 deletions session-manager/src/session_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ use mbedtls::{
};
use platform_services::getrandom;
use policy_utils::policy::Policy;
#[cfg(feature = "debug")]
use std::borrow::Cow;
use std::{string::String, sync::Arc, vec::Vec};

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -152,6 +154,16 @@ impl SessionContext {
config::Transport::Stream,
config::Preset::Default,
);
#[cfg(feature = "debug")]
{
let dbg_callback =
|level: i32, file: Cow<'_, str>, line: i32, message: Cow<'_, str>| {
print!("{} {}:{} {}", level, file, line, message);
};
config.set_dbg_callback(dbg_callback);
// TODO: waiting for https://github.com/veracruz-project/rust-mbedtls/issues/1 to be fixed
//unsafe { mbedtls::set_global_debug_threshold(3); }
}
config.set_ciphersuites(Arc::new(self.cipher_suites.clone()));
let entropy = Arc::new(mbedtls::rng::OsEntropy::new());
let rng = Arc::new(mbedtls::rng::CtrDrbg::new(entropy, None)?);
Expand Down
7 changes: 7 additions & 0 deletions veracruz-client/src/veracruz_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use log::{error, info};
use mbedtls::{alloc::List, pk::Pk, ssl::Context, x509::Certificate};
use policy_utils::{parsers::enforce_leading_backslash, policy::Policy, Platform};
use std::{
borrow::Cow,
io::{Read, Write},
path::Path,
sync::{
Expand Down Expand Up @@ -246,6 +247,12 @@ impl VeracruzClient {

use mbedtls::ssl::config::{Config, Endpoint, Preset, Transport, Version};
let mut config = Config::new(Endpoint::Client, Transport::Stream, Preset::Default);
let dbg_callback = |level: i32, file: Cow<'_, str>, line: i32, message: Cow<'_, str>| {
print!("{} {}:{} {}", level, file, line, message);
};
config.set_dbg_callback(dbg_callback);
// TODO: waiting for https://github.com/veracruz-project/rust-mbedtls/issues/1 to be fixed
//unsafe { mbedtls::set_global_debug_threshold(3); }
config.set_min_version(Version::Tls1_3)?;
config.set_max_version(Version::Tls1_3)?;
let policy_ciphersuite = veracruz_utils::lookup_ciphersuite(policy.ciphersuite().as_str())
Expand Down