Skip to content

Commit

Permalink
crypto: Move to keylime library
Browse files Browse the repository at this point in the history
Move the crypto module from keylime-agent to the keylime library.

Signed-off-by: Anderson Toshiyuki Sasaki <[email protected]>
  • Loading branch information
ansasaki committed Feb 8, 2024
1 parent e282423 commit 6610d39
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 88 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions keylime-agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ keylime.workspace = true
libc.workspace = true
log.workspace = true
openssl.workspace = true
picky-asn1-der.workspace = true
picky-asn1-x509.workspace = true
pretty_env_logger.workspace = true
reqwest.workspace = true
serde.workspace = true
Expand Down
17 changes: 7 additions & 10 deletions keylime-agent/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@
// Copyright 2021 Keylime Authors

use crate::{
crypto::{AES_128_KEY_LEN, AES_256_KEY_LEN},
error::{Error, Result},
permissions,
};

use keylime::algorithms::{
EncryptionAlgorithm, HashAlgorithm, SignAlgorithm,
};
use keylime::tpm;
use log::*;
use openssl::{
hash::{hash, MessageDigest},
pkey::PKey,
x509::X509,
use keylime::{
crypto::{hash, tss_pubkey_to_pem, AES_128_KEY_LEN, AES_256_KEY_LEN},
tpm,
};
use picky_asn1_x509::SubjectPublicKeyInfo;
use log::*;
use openssl::hash::MessageDigest;
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use std::{
Expand Down Expand Up @@ -255,8 +252,8 @@ impl AgentData {
/// This is used as the agent UUID when the configuration option 'uuid' is set as 'hash_ek'
pub(crate) fn hash_ek_pubkey(ek_pub: Public) -> Result<String> {
// Calculate the SHA-256 hash of the public key in PEM format
let pem = crate::crypto::tss_pubkey_to_pem(ek_pub)?;
let hash = crate::crypto::hash(&pem, MessageDigest::sha256())?;
let pem = tss_pubkey_to_pem(ek_pub)?;
let hash = hash(&pem, MessageDigest::sha256())?;
Ok(hex::encode(hash))
}

Expand Down
4 changes: 1 addition & 3 deletions keylime-agent/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub(crate) enum Error {
#[error("Number parsing error: {0}")]
NumParse(#[from] std::num::ParseIntError),
#[error("Crypto error: {0}")]
Crypto(#[from] crate::crypto::CryptoError),
Crypto(#[from] keylime::crypto::CryptoError),
#[cfg(feature = "with-zmq")]
#[error("ZMQ error: {0}")]
Zmq(#[from] zmq::Error),
Expand All @@ -83,8 +83,6 @@ pub(crate) enum Error {
Persist(#[from] tempfile::PersistError),
#[error("Error joining threads: {0}")]
Join(#[from] tokio::task::JoinError),
#[error("Asn1DerError: {0}")]
PickyAsn1(#[from] picky_asn1_der::Asn1DerError),
#[error("Error sending internal message: {0}")]
Sender(String),
#[error("Error receiving internal message: {0}")]
Expand Down
3 changes: 1 addition & 2 deletions keylime-agent/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

mod common;
mod config;
mod crypto;
mod error;
mod errors_handler;
mod keys_handler;
Expand All @@ -56,7 +55,7 @@ use futures::{
future::{ok, TryFutureExt},
try_join,
};
use keylime::{ima::MeasurementList, list_parser::parse_list, tpm};
use keylime::{crypto, ima::MeasurementList, list_parser::parse_list, tpm};
use log::*;
use openssl::{
pkey::{PKey, Private, Public},
Expand Down
2 changes: 2 additions & 0 deletions keylime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ serde_derive.workspace = true
static_assertions.workspace = true
thiserror.workspace = true
tss-esapi.workspace = true
picky-asn1-der.workspace = true
picky-asn1-x509.workspace = true

[dev-dependencies]
tempfile.workspace = true
Loading

0 comments on commit 6610d39

Please sign in to comment.