Skip to content
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

Use git tss-esapi and add tpm vendor check #139

Merged
merged 3 commits into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ serde_json = "1.0"
tempfile = "3.0.4"
tokio = {version = "0.2", features = ["full"]}
tokio-io = "0.1"
tss-esapi = "4.0.9-alpha.1"
# While functions are being added, we use the git repo version for now
# tss-esapi = "4.0.9-alpha.1"
tss-esapi = { git = "https://github.com/parallaxsecond/rust-tss-esapi", rev = "743b3a63385dd9960013e26f6a35d34d64b16498" }
7 changes: 7 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ static NOTFOUND: &[u8] = b"Not Found";
async fn main() -> Result<()> {
pretty_env_logger::init();
let mut ctx = tpm::get_tpm2_ctx()?;
// Retreive the TPM Vendor, this allows us to warn if someone is using a
// Software TPM ("SW")
if tss_esapi::utils::get_tpm_vendor(&mut ctx)?.contains("SW") {
warn!("INSECURE: Keylime is using a software TPM emulator rather than a real hardware TPM.");
warn!("INSECURE: The security of Keylime is NOT linked to a hardware root of trust.");
warn!("INSECURE: Only use Keylime in this mode for testing or debugging purposes.");
}
let cloudagent_ip =
config_get("/etc/keylime.conf", "cloud_agent", "cloudagent_ip")?;
let cloudagent_port =
Expand Down
15 changes: 8 additions & 7 deletions src/tpm.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::str::FromStr;

use tss_esapi::constants::algorithm::HashingAlgorithm;
use tss_esapi::constants::tss as tss_constants;
use tss_esapi::tss2_esys::{ESYS_TR, ESYS_TR_NONE, ESYS_TR_RH_OWNER};
use tss_esapi::Context;
use tss_esapi::Tcti;
use crate::Result;

use tss_esapi::{
constants::{algorithm::HashingAlgorithm, tss::*},
Context, Tcti,
};

/*
* Input: None
Expand All @@ -13,13 +14,13 @@ use tss_esapi::Tcti;
* Example call:
* let mut ctx = tpm::get_tpm2_ctx();
*/
pub(crate) fn get_tpm2_ctx() -> Result<tss_esapi::Context, tss_esapi::Error> {
pub(crate) fn get_tpm2_ctx() -> Result<tss_esapi::Context> {
let tcti_path = if std::path::Path::new("/dev/tpmrm0").exists() {
"device:/dev/tpmrm0"
} else {
"device:/dev/tpm0"
};

let tcti = Tcti::from_str(tcti_path)?;
unsafe { Context::new(tcti) }
unsafe { Context::new(tcti) }.map_err(|e| e.into())
}