Skip to content

Commit afcf94c

Browse files
sarroutbiansasaki
authored andcommitted
Add registration for Push Model client
Signed-off-by: Sergio Arroutbi <[email protected]>
1 parent b0899f8 commit afcf94c

19 files changed

+762
-154
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

keylime-agent/src/common.rs

Lines changed: 10 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// Copyright 2021 Keylime Authors
33

4-
use keylime::error::{Error, Result};
4+
use keylime::keylime_error::{Error, Result};
55

66
use crate::permissions;
77

@@ -10,7 +10,7 @@ use keylime::algorithms::{
1010
};
1111
use keylime::{
1212
crypto::{hash, tss_pubkey_to_pem},
13-
tpm,
13+
hash_ek, tpm,
1414
};
1515
use log::*;
1616
use openssl::hash::MessageDigest;
@@ -77,83 +77,15 @@ where
7777
}
7878
}
7979

80-
// TPM data and agent related that can be persisted and loaded on agent startup.
81-
#[derive(Debug, Clone, Serialize, Deserialize)]
82-
pub(crate) struct AgentData {
83-
pub ak_hash_alg: HashAlgorithm,
84-
pub ak_sign_alg: SignAlgorithm,
85-
ak_public: Vec<u8>,
86-
ak_private: Vec<u8>,
87-
ek_hash: Vec<u8>,
88-
}
89-
90-
impl AgentData {
91-
pub(crate) fn create(
92-
ak_hash_alg: HashAlgorithm,
93-
ak_sign_alg: SignAlgorithm,
94-
ak: &tpm::AKResult,
95-
ek_hash: &[u8],
96-
) -> Result<Self> {
97-
let ak_public = ak.public.marshall()?;
98-
let ak_private: Vec<u8> = ak.private.to_vec();
99-
let ek_hash: Vec<u8> = ek_hash.to_vec();
100-
Ok(Self {
101-
ak_hash_alg,
102-
ak_sign_alg,
103-
ak_public,
104-
ak_private,
105-
ek_hash,
106-
})
107-
}
108-
109-
pub(crate) fn load(path: &Path) -> Result<Self> {
110-
let file = File::open(path)?;
111-
let data: Self = serde_json::from_reader(file)?;
112-
Ok(data)
113-
}
114-
115-
pub(crate) fn store(&self, path: &Path) -> Result<()> {
116-
let file = File::create(path)?;
117-
serde_json::to_writer_pretty(file, self)?;
118-
Ok(())
119-
}
120-
121-
pub(crate) fn get_ak(&self) -> Result<tpm::AKResult> {
122-
let public = Public::unmarshall(&self.ak_public)?;
123-
let private = Private::try_from(self.ak_private.clone())?;
124-
125-
Ok(tpm::AKResult { public, private })
126-
}
127-
128-
pub(crate) fn valid(
129-
&self,
130-
hash_alg: HashAlgorithm,
131-
sign_alg: SignAlgorithm,
132-
ek_hash: &[u8],
133-
) -> bool {
134-
hash_alg == self.ak_hash_alg
135-
&& sign_alg == self.ak_sign_alg
136-
&& ek_hash.to_vec() == self.ek_hash
137-
}
138-
}
139-
140-
/// Calculate the SHA-256 hash of the TPM public key in PEM format
141-
///
142-
/// This is used as the agent UUID when the configuration option 'uuid' is set as 'hash_ek'
143-
pub(crate) fn hash_ek_pubkey(ek_pub: Public) -> Result<String> {
144-
// Calculate the SHA-256 hash of the public key in PEM format
145-
let pem = tss_pubkey_to_pem(ek_pub)?;
146-
let hash = hash(&pem, MessageDigest::sha256())?;
147-
Ok(hex::encode(hash))
148-
}
149-
15080
#[cfg(test)]
15181
mod tests {
15282
use super::*;
15383
use crate::config::KeylimeConfig;
84+
use keylime::agent_data::AgentData;
15485
use keylime::algorithms::{
15586
EncryptionAlgorithm, HashAlgorithm, SignAlgorithm,
15687
};
88+
use keylime::hash_ek;
15789
use std::convert::TryFrom;
15890
use tss_esapi::{
15991
handles::KeyHandle,
@@ -188,8 +120,8 @@ mod tests {
188120
.create_ek(tpm_encryption_alg, None)
189121
.expect("Failed to create EK");
190122

191-
let ek_hash =
192-
hash_ek_pubkey(ek_result.public).expect("Failed to get pubkey");
123+
let ek_hash = hash_ek::hash_ek_pubkey(ek_result.public)
124+
.expect("Failed to get pubkey");
193125

194126
let ak = ctx.create_ak(
195127
ek_result.key_handle,
@@ -224,6 +156,9 @@ mod tests {
224156
#[tokio::test]
225157
#[cfg(feature = "testing")]
226158
async fn test_hash() -> Result<()> {
159+
use keylime::agent_data;
160+
use keylime::hash_ek;
161+
227162
let _mutex = tpm::testing::lock_tests().await;
228163
let mut config = KeylimeConfig::default();
229164

@@ -238,7 +173,7 @@ mod tests {
238173
.create_ek(tpm_encryption_alg, None)
239174
.expect("Failed to create EK");
240175

241-
let result = hash_ek_pubkey(ek_result.public);
176+
let result = hash_ek::hash_ek_pubkey(ek_result.public);
242177

243178
assert!(result.is_ok());
244179

keylime-agent/src/main.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,14 @@ use futures::{
5353
try_join,
5454
};
5555
use keylime::agent_registration::AgentRegistrationConfig;
56-
use keylime::error::{Error, Result};
5756
use keylime::global_config;
57+
use keylime::keylime_error::{Error, Result};
5858
use keylime::{
59+
agent_data::AgentData,
5960
agent_registration::AgentRegistration,
6061
crypto::{self, x509::CertificateBuilder},
6162
device_id::{DeviceID, DeviceIDBuilder},
63+
hash_ek,
6264
ima::MeasurementList,
6365
list_parser::parse_list,
6466
registrar_client::RegistrarClientBuilder,
@@ -343,7 +345,7 @@ async fn main() -> Result<()> {
343345
};
344346

345347
// Calculate the SHA-256 hash of the public key in PEM format
346-
let ek_hash = hash_ek_pubkey(ek_result.public.clone())?;
348+
let ek_hash = hash_ek::hash_ek_pubkey(ek_result.public.clone())?;
347349

348350
// Replace the uuid with the actual EK hash if the option was set.
349351
// We cannot do that when the configuration is loaded initially,
@@ -624,7 +626,7 @@ async fn main() -> Result<()> {
624626
ak,
625627
ek_result,
626628
api_versions: api_versions.clone(),
627-
agent: ac,
629+
agent_registration_config: ac,
628630
agent_uuid: agent_uuid.clone(),
629631
mtls_cert,
630632
device_id,

keylime-agent/src/permissions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// Copyright 2021 Keylime Authors
33

4-
use keylime::error::{Error, Result};
4+
use keylime::keylime_error::{Error, Result};
55
use libc::{c_char, c_int, gid_t, uid_t};
66
use log::*;
77
use std::os::unix::ffi::OsStrExt;

keylime-agent/src/revocation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use actix_web::rt;
66
use crate::config::{AgentConfig, KeylimeConfig};
77
use crate::crypto;
88
use crate::secure_mount;
9-
use keylime::error::*;
9+
use keylime::keylime_error::*;
1010
use keylime::list_parser::parse_list;
1111
use log::*;
1212
use serde::{Deserialize, Serialize};

keylime-agent/src/secure_mount.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use super::*;
55

6-
use keylime::error::{Error, Result};
6+
use keylime::keylime_error::{Error, Result};
77
use std::fs;
88
use std::io::BufRead;
99
use std::os::unix::fs::PermissionsExt;

0 commit comments

Comments
 (0)