Skip to content

Commit 205c14f

Browse files
committed
crypto: Move to keylime library
Move the crypto module from keylime-agent to the keylime library. Signed-off-by: Anderson Toshiyuki Sasaki <[email protected]>
1 parent e282423 commit 205c14f

File tree

11 files changed

+106
-88
lines changed

11 files changed

+106
-88
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

keylime-agent/Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ keylime.workspace = true
2121
libc.workspace = true
2222
log.workspace = true
2323
openssl.workspace = true
24-
picky-asn1-der.workspace = true
25-
picky-asn1-x509.workspace = true
2624
pretty_env_logger.workspace = true
2725
reqwest.workspace = true
2826
serde.workspace = true

keylime-agent/src/common.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,19 @@
22
// Copyright 2021 Keylime Authors
33

44
use crate::{
5-
crypto::{AES_128_KEY_LEN, AES_256_KEY_LEN},
65
error::{Error, Result},
76
permissions,
87
};
98

109
use keylime::algorithms::{
1110
EncryptionAlgorithm, HashAlgorithm, SignAlgorithm,
1211
};
13-
use keylime::tpm;
14-
use log::*;
15-
use openssl::{
16-
hash::{hash, MessageDigest},
17-
pkey::PKey,
18-
x509::X509,
12+
use keylime::{
13+
crypto::{hash, tss_pubkey_to_pem, AES_128_KEY_LEN, AES_256_KEY_LEN},
14+
tpm,
1915
};
20-
use picky_asn1_x509::SubjectPublicKeyInfo;
16+
use log::*;
17+
use openssl::hash::MessageDigest;
2118
use serde::{Deserialize, Serialize};
2219
use serde_json::{json, Value};
2320
use std::{
@@ -255,8 +252,8 @@ impl AgentData {
255252
/// This is used as the agent UUID when the configuration option 'uuid' is set as 'hash_ek'
256253
pub(crate) fn hash_ek_pubkey(ek_pub: Public) -> Result<String> {
257254
// Calculate the SHA-256 hash of the public key in PEM format
258-
let pem = crate::crypto::tss_pubkey_to_pem(ek_pub)?;
259-
let hash = crate::crypto::hash(&pem, MessageDigest::sha256())?;
255+
let pem = tss_pubkey_to_pem(ek_pub)?;
256+
let hash = hash(&pem, MessageDigest::sha256())?;
260257
Ok(hex::encode(hash))
261258
}
262259

keylime-agent/src/error.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub(crate) enum Error {
6161
#[error("Number parsing error: {0}")]
6262
NumParse(#[from] std::num::ParseIntError),
6363
#[error("Crypto error: {0}")]
64-
Crypto(#[from] crate::crypto::CryptoError),
64+
Crypto(#[from] keylime::crypto::CryptoError),
6565
#[cfg(feature = "with-zmq")]
6666
#[error("ZMQ error: {0}")]
6767
Zmq(#[from] zmq::Error),
@@ -83,8 +83,6 @@ pub(crate) enum Error {
8383
Persist(#[from] tempfile::PersistError),
8484
#[error("Error joining threads: {0}")]
8585
Join(#[from] tokio::task::JoinError),
86-
#[error("Asn1DerError: {0}")]
87-
PickyAsn1(#[from] picky_asn1_der::Asn1DerError),
8886
#[error("Error sending internal message: {0}")]
8987
Sender(String),
9088
#[error("Error receiving internal message: {0}")]

keylime-agent/src/main.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
mod common;
3535
mod config;
36-
mod crypto;
3736
mod error;
3837
mod errors_handler;
3938
mod keys_handler;
@@ -56,7 +55,7 @@ use futures::{
5655
future::{ok, TryFutureExt},
5756
try_join,
5857
};
59-
use keylime::{ima::MeasurementList, list_parser::parse_list, tpm};
58+
use keylime::{crypto, ima::MeasurementList, list_parser::parse_list, tpm};
6059
use log::*;
6160
use openssl::{
6261
pkey::{PKey, Private, Public},

keylime/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ serde_derive.workspace = true
1919
static_assertions.workspace = true
2020
thiserror.workspace = true
2121
tss-esapi.workspace = true
22+
picky-asn1-der.workspace = true
23+
picky-asn1-x509.workspace = true
2224

2325
[dev-dependencies]
2426
tempfile.workspace = true

0 commit comments

Comments
 (0)