-
Notifications
You must be signed in to change notification settings - Fork 72
Implement mitigation 4 of TM #189
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,35 +56,65 @@ impl FrontEndHandler { | |
return; | ||
} | ||
}; | ||
|
||
// Check if the request was sent without authentication | ||
let response = if AuthType::NoAuth == request.header.auth_type { | ||
let response = self.dispatcher.dispatch_request(request, None); | ||
trace!("dispatch_request egress"); | ||
response | ||
let (app_name, err_response) = if AuthType::NoAuth == request.header.auth_type { | ||
(None, None) | ||
// Otherwise find an authenticator that is capable to authenticate the request | ||
} else if let Some(authenticator) = self.authenticators.get(&request.header.auth_type) { | ||
// Authenticate the request | ||
match authenticator.authenticate(&request.auth) { | ||
// Send the request to the dispatcher | ||
// Get a response back | ||
Ok(app_name) => { | ||
let response = self.dispatcher.dispatch_request(request, Some(app_name)); | ||
trace!("dispatch_request egress"); | ||
response | ||
} | ||
Err(status) => Response::from_request_header(request.header, status), | ||
Ok(app_name) => (Some(app_name), None), | ||
Err(status) => ( | ||
None, | ||
Some(Response::from_request_header(request.header, status)), | ||
), | ||
} | ||
} else { | ||
Response::from_request_header( | ||
request.header, | ||
ResponseStatus::AuthenticatorNotRegistered, | ||
( | ||
None, | ||
Some(Response::from_request_header( | ||
request.header, | ||
ResponseStatus::AuthenticatorNotRegistered, | ||
)), | ||
) | ||
}; | ||
|
||
// Serialise the responso into bytes | ||
let response = if let Some(err_response) = err_response { | ||
err_response | ||
} else { | ||
if crate::utils::GlobalConfig::log_error_details() { | ||
if let Some(app_name_string) = app_name.clone() { | ||
info!( | ||
"New request received from application name \"{}\"", | ||
app_name_string | ||
) | ||
} else { | ||
info!("New request received without authentication") | ||
} | ||
}; | ||
let response = self.dispatcher.dispatch_request(request, app_name.clone()); | ||
trace!("dispatch_request egress"); | ||
response | ||
}; | ||
|
||
// Serialise the response into bytes | ||
// Write bytes to stream | ||
match response.write_to_stream(&mut stream) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apologies for not asking this earlier, but why not just put a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes so that it is only written when the |
||
Ok(_) => info!("Request handled successfully"), | ||
Ok(_) => { | ||
if crate::utils::GlobalConfig::log_error_details() { | ||
if let Some(app_name_string) = app_name { | ||
info!( | ||
"Response from application name \"{}\" sent back", | ||
app_name_string | ||
); | ||
} else { | ||
info!("Response sent back from request without authentication"); | ||
} | ||
} | ||
} | ||
Err(err) => format_error!("Failed to send response", err), | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
//! For security reasons, only the PARSEC service should have the ability to modify these files. | ||
use super::{KeyInfo, KeyTriple, ManageKeyInfo}; | ||
use crate::authenticators::ApplicationName; | ||
use log::{error, info}; | ||
use log::{error, info, warn}; | ||
use parsec_interface::requests::ProviderID; | ||
use std::collections::HashMap; | ||
use std::convert::TryFrom; | ||
|
@@ -187,9 +187,6 @@ impl OnDiskKeyInfoManager { | |
for app_name_dir_path in list_dirs(&mappings_dir_path)?.iter() { | ||
for provider_dir_path in list_dirs(&app_name_dir_path)?.iter() { | ||
for key_name_file_path in list_files(&provider_dir_path)?.iter() { | ||
if crate::utils::GlobalConfig::log_error_details() { | ||
info!("Found mapping file: {:?}.", key_name_file_path); | ||
} | ||
let mut key_info = Vec::new(); | ||
let mut key_info_file = File::open(&key_name_file_path)?; | ||
let _ = key_info_file.read_to_end(&mut key_info)?; | ||
|
@@ -209,6 +206,12 @@ impl OnDiskKeyInfoManager { | |
))?, | ||
) { | ||
Ok(key_triple) => { | ||
if crate::utils::GlobalConfig::log_error_details() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should rename the flag to |
||
warn!( | ||
"Inserting Key Triple ({}) mapping read from disk.", | ||
key_triple.clone() | ||
); | ||
} | ||
let _ = key_store.insert(key_triple, key_info); | ||
} | ||
Err(string) => { | ||
|
@@ -236,6 +239,12 @@ impl OnDiskKeyInfoManager { | |
/// The filename will be `mappings/[APP_NAME]/[PROVIDER_NAME]/[KEY_NAME]` under the same path as the | ||
/// on-disk manager. It will contain the Key info data. | ||
fn save_mapping(&self, key_triple: &KeyTriple, key_info: &KeyInfo) -> std::io::Result<()> { | ||
if crate::utils::GlobalConfig::log_error_details() { | ||
warn!( | ||
"Saving Key Triple ({}) mapping to disk.", | ||
key_triple.clone() | ||
); | ||
} | ||
// Create the directories with base64 names. | ||
let (app_name, prov, key_name) = key_triple_to_base64_filenames(key_triple); | ||
let provider_dir_path = self.mappings_dir_path.join(app_name).join(prov); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👌