Skip to content

Commit 78801af

Browse files
committed
config: Move config to keylime library
The following changes were made: - Moved keylime/src/global_config.rs to keylime/src/config/errors.rs - Moved keylime-agent/src/config.rs to keylime/src/config/base.rs - Moved the EnvConfig structure to the dedicated file keylime/src/config/env.rs - Moved the SUPPORTED_API_VERSIONS value from keylime-agent/src/api.rs to keylime/src/config/base.rs - Added temporary values for DEFAULT_PUSH_API_VERSIONS and DEFAULT_PUSH_EK_HANDLE in keylme/src/config/push_model.rs - Modified other files as necessary Signed-off-by: Anderson Toshiyuki Sasaki <[email protected]>
1 parent 4b81ff5 commit 78801af

File tree

10 files changed

+371
-355
lines changed

10 files changed

+371
-355
lines changed

keylime-agent/src/api.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ use crate::{
33
notifications_handler, quotes_handler, QuoteData,
44
};
55
use actix_web::{http, web, HttpRequest, HttpResponse, Responder, Scope};
6-
use keylime::{list_parser::parse_list, version::KeylimeVersion};
6+
use keylime::{
7+
config::SUPPORTED_API_VERSIONS, list_parser::parse_list,
8+
version::KeylimeVersion,
9+
};
710
use log::*;
811
use serde::{Deserialize, Serialize};
912
use thiserror::Error;
1013

11-
pub static SUPPORTED_API_VERSIONS: &[&str] = &["2.1", "2.2"];
12-
1314
#[derive(Error, Debug, PartialEq)]
1415
pub enum APIError {
1516
#[error("API version \"{0}\" not supported")]

keylime-agent/src/main.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
mod agent_handler;
3535
mod api;
3636
mod common;
37-
mod config;
3837
mod errors_handler;
3938
mod keys_handler;
4039
mod notifications_handler;
@@ -54,9 +53,10 @@ use futures::{
5453
use keylime::{
5554
agent_data::AgentData,
5655
agent_registration::{AgentRegistration, AgentRegistrationConfig},
56+
config,
5757
crypto::{self, x509::CertificateBuilder},
5858
device_id::{DeviceID, DeviceIDBuilder},
59-
global_config, hash_ek,
59+
hash_ek,
6060
ima::MeasurementList,
6161
keylime_error::{Error, Result},
6262
list_parser::parse_list,
@@ -236,7 +236,7 @@ async fn main() -> Result<()> {
236236

237237
error!("Configuration error: {}", &message);
238238
return Err(Error::Configuration(
239-
global_config::KeylimeConfigError::Generic(message),
239+
config::KeylimeConfigError::Generic(message),
240240
));
241241
}
242242

@@ -266,7 +266,7 @@ async fn main() -> Result<()> {
266266

267267
error!("Configuration error: {}", &message);
268268
return Err(Error::Configuration(
269-
global_config::KeylimeConfigError::Generic(message),
269+
config::KeylimeConfigError::Generic(message),
270270
));
271271
}
272272
info!("Running the service as {}...", user_group);
@@ -295,7 +295,7 @@ async fn main() -> Result<()> {
295295
if !python_shim.exists() {
296296
error!("Could not find python shim at {}", python_shim.display());
297297
return Err(Error::Configuration(
298-
global_config::KeylimeConfigError::Generic(format!(
298+
config::KeylimeConfigError::Generic(format!(
299299
"Could not find python shim at {}",
300300
python_shim.display()
301301
))));
@@ -319,7 +319,7 @@ async fn main() -> Result<()> {
319319
};
320320
ctx.tr_set_auth(Hierarchy::Endorsement.into(), auth)
321321
.map_err(|e| {
322-
Error::Configuration(global_config::KeylimeConfigError::Generic(format!(
322+
Error::Configuration(config::KeylimeConfigError::Generic(format!(
323323
"Failed to set TPM context password for Endorsement Hierarchy: {e}"
324324
)))
325325
})?;
@@ -574,7 +574,7 @@ async fn main() -> Result<()> {
574574
{
575575
"" => {
576576
error!("Agent mTLS is enabled, but trusted_client_ca option was not provided");
577-
return Err(Error::Configuration(global_config::KeylimeConfigError::Generic("Agent mTLS is enabled, but trusted_client_ca option was not provided".to_string())));
577+
return Err(Error::Configuration(config::KeylimeConfigError::Generic("Agent mTLS is enabled, but trusted_client_ca option was not provided".to_string())));
578578
}
579579
l => l,
580580
};
@@ -585,7 +585,7 @@ async fn main() -> Result<()> {
585585
error!(
586586
"Trusted client CA certificate list is empty: could not load any certificate"
587587
);
588-
return Err(Error::Configuration(global_config::KeylimeConfigError::Generic(
588+
return Err(Error::Configuration(config::KeylimeConfigError::Generic(
589589
"Trusted client CA certificate list is empty: could not load any certificate".to_string()
590590
)));
591591
}
@@ -657,7 +657,7 @@ async fn main() -> Result<()> {
657657
error!(
658658
"No revocation certificate set in 'revocation_cert' option"
659659
);
660-
return Err(Error::Configuration(global_config::KeylimeConfigError::Generic(
660+
return Err(Error::Configuration(config::KeylimeConfigError::Generic(
661661
"No revocation certificate set in 'revocation_cert' option"
662662
.to_string(),
663663
)));
@@ -1041,7 +1041,7 @@ mod testing {
10411041
Err(err) => None,
10421042
};
10431043

1044-
let api_versions = api::SUPPORTED_API_VERSIONS
1044+
let api_versions = config::SUPPORTED_API_VERSIONS
10451045
.iter()
10461046
.map(|&s| s.to_string())
10471047
.collect::<Vec<String>>();

keylime-agent/src/payloads.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
// Copyright 2021 Keylime Authors
33

44
use crate::{
5-
config,
65
revocation::{Revocation, RevocationMessage},
76
Error, Result,
87
};
98

109
#[cfg(feature = "with-zmq")]
1110
use crate::revocation::ZmqMessage;
1211

13-
use keylime::global_config;
1412
use keylime::{
13+
config,
1514
crypto::{
1615
self,
1716
encrypted_data::EncryptedData,
@@ -84,14 +83,14 @@ fn setup_unzipped(
8483
}
8584

8685
match config.agent.dec_payload_file.as_ref() {
87-
"" => Err(global_config::KeylimeConfigError::RequiredOption(
86+
"" => Err(config::KeylimeConfigError::RequiredOption(
8887
"dec_payload_path".to_string(),
8988
)
9089
.into()),
9190
p => {
9291
let dec_payload_path = unzipped.join(p);
9392
match config.agent.enc_keyname.as_ref() {
94-
"" => Err(global_config::KeylimeConfigError::RequiredOption(
93+
"" => Err(config::KeylimeConfigError::RequiredOption(
9594
"enc_keyname".to_string(),
9695
)
9796
.into()),

0 commit comments

Comments
 (0)