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

Enable different key sizes and curves for EK and AK #846

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
51 changes: 12 additions & 39 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ static_assertions = "1"
tempfile = "3.4.0"
thiserror = "1.0"
tokio = {version = "1.24", features = ["rt", "sync", "macros"]}
tss-esapi = {version = "7.4.0", features = ["generate-bindings"]}
tss-esapi = {version = "7.6.0", features = ["generate-bindings"]}
uuid = {version = "1.3", features = ["v4"]}
zip = {version = "0.6", default-features = false, features= ["deflate"]}
2 changes: 1 addition & 1 deletion keylime-agent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ allow_payload_revocation_actions = true
#
# Currently accepted values include:
# - hashing: sha512, sha384, sha256 or sha1
# - encryption: ecc or rsa
# - encryption: rsa (alias for rsa2048), rsa1024, rsa2048, rsa3072, rsa4096, ecc (alias for ecc256), ecc192, ecc224, ecc256, ecc384, ecc521 or ecc_sm2.
# - signing: rsassa, rsapss, ecdsa, ecdaa or ecschnorr
#
# To override tpm_hash_alg, set KEYLIME_AGENT_TPM_HASH_ALG environment variable.
Expand Down
2 changes: 1 addition & 1 deletion keylime-agent/src/agent_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ mod tests {
async fn test_agent_info() {
let (mut quotedata, mutex) = QuoteData::fixture().await.unwrap(); //#[allow_ci]
quotedata.hash_alg = keylime::algorithms::HashAlgorithm::Sha256;
quotedata.enc_alg = keylime::algorithms::EncryptionAlgorithm::Rsa;
quotedata.enc_alg = keylime::algorithms::EncryptionAlgorithm::Rsa2048;
quotedata.sign_alg = keylime::algorithms::SignAlgorithm::RsaSsa;
quotedata.agent_uuid = "DEADBEEF".to_string();
let data = web::Data::new(quotedata);
Expand Down
1 change: 1 addition & 0 deletions keylime-agent/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ mod tests {
let ak = ctx.create_ak(
ek_result.key_handle,
tpm_hash_alg,
tpm_encryption_alg,
tpm_signing_alg,
)?;

Expand Down
5 changes: 4 additions & 1 deletion keylime-agent/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@
let new_ak = ctx.create_ak(
ek_result.key_handle,
tpm_hash_alg,
tpm_encryption_alg,
tpm_signing_alg,
)?;
let ak_handle = ctx.load_ak(ek_result.key_handle, &new_ak)?;
Expand Down Expand Up @@ -1029,6 +1030,7 @@
.create_ak(
ek_result.key_handle,
tpm_hash_alg,
tpm_encryption_alg,

Check warning on line 1033 in keylime-agent/src/main.rs

View check run for this annotation

Codecov / codecov/patch

keylime-agent/src/main.rs#L1033

Added line #L1033 was not covered by tests
tpm_signing_alg,
)
.unwrap(); //#[allow_ci]
Expand Down Expand Up @@ -1100,7 +1102,8 @@
payload_tx,
revocation_tx,
hash_alg: keylime::algorithms::HashAlgorithm::Sha256,
enc_alg: keylime::algorithms::EncryptionAlgorithm::Rsa,
enc_alg:

Check warning on line 1105 in keylime-agent/src/main.rs

View check run for this annotation

Codecov / codecov/patch

keylime-agent/src/main.rs#L1105

Added line #L1105 was not covered by tests
keylime::algorithms::EncryptionAlgorithm::Rsa2048,
sign_alg: keylime::algorithms::SignAlgorithm::RsaSsa,
agent_uuid: test_config.agent.uuid,
allow_payload_revocation_actions: test_config
Expand Down
111 changes: 99 additions & 12 deletions keylime/src/algorithms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
use std::fmt;
use thiserror::Error;
use tss_esapi::{
interface_types::algorithm::{
AsymmetricAlgorithm, HashingAlgorithm, SignatureSchemeAlgorithm,
abstraction::AsymmetricAlgorithmSelection,
interface_types::{
algorithm::{
AsymmetricAlgorithm, HashingAlgorithm, SignatureSchemeAlgorithm,
},
ecc::EccCurve,
key_bits::RsaKeyBits,
},
structures::{HashScheme, SignatureScheme},
};
Expand Down Expand Up @@ -89,15 +94,68 @@

#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum EncryptionAlgorithm {
Rsa,
Ecc,
Rsa1024,
Rsa2048,
Rsa3072,
Rsa4096,
Ecc192,
Ecc224,
Ecc256,
Ecc384,
Ecc521,
EccSm2,
}

impl From<EncryptionAlgorithm> for AsymmetricAlgorithm {
fn from(enc_alg: EncryptionAlgorithm) -> Self {
match enc_alg {
EncryptionAlgorithm::Rsa => AsymmetricAlgorithm::Rsa,
EncryptionAlgorithm::Ecc => AsymmetricAlgorithm::Ecc,
EncryptionAlgorithm::Rsa1024 => AsymmetricAlgorithm::Rsa,

Check warning on line 112 in keylime/src/algorithms.rs

View check run for this annotation

Codecov / codecov/patch

keylime/src/algorithms.rs#L112

Added line #L112 was not covered by tests
EncryptionAlgorithm::Rsa2048 => AsymmetricAlgorithm::Rsa,
EncryptionAlgorithm::Rsa3072 => AsymmetricAlgorithm::Rsa,
EncryptionAlgorithm::Rsa4096 => AsymmetricAlgorithm::Rsa,
EncryptionAlgorithm::Ecc192 => AsymmetricAlgorithm::Ecc,
EncryptionAlgorithm::Ecc224 => AsymmetricAlgorithm::Ecc,
EncryptionAlgorithm::Ecc256 => AsymmetricAlgorithm::Ecc,
EncryptionAlgorithm::Ecc384 => AsymmetricAlgorithm::Ecc,
EncryptionAlgorithm::Ecc521 => AsymmetricAlgorithm::Ecc,
EncryptionAlgorithm::EccSm2 => AsymmetricAlgorithm::Ecc,

Check warning on line 121 in keylime/src/algorithms.rs

View check run for this annotation

Codecov / codecov/patch

keylime/src/algorithms.rs#L114-L121

Added lines #L114 - L121 were not covered by tests
}
}

Check warning on line 123 in keylime/src/algorithms.rs

View check run for this annotation

Codecov / codecov/patch

keylime/src/algorithms.rs#L123

Added line #L123 was not covered by tests
}

impl From<EncryptionAlgorithm> for AsymmetricAlgorithmSelection {
fn from(enc_alg: EncryptionAlgorithm) -> Self {
match enc_alg {
EncryptionAlgorithm::Rsa1024 => {
AsymmetricAlgorithmSelection::Rsa(RsaKeyBits::Rsa1024)
}
EncryptionAlgorithm::Rsa2048 => {
AsymmetricAlgorithmSelection::Rsa(RsaKeyBits::Rsa2048)
}
EncryptionAlgorithm::Rsa3072 => {
AsymmetricAlgorithmSelection::Rsa(RsaKeyBits::Rsa3072)

Check warning on line 136 in keylime/src/algorithms.rs

View check run for this annotation

Codecov / codecov/patch

keylime/src/algorithms.rs#L136

Added line #L136 was not covered by tests
}
EncryptionAlgorithm::Rsa4096 => {
AsymmetricAlgorithmSelection::Rsa(RsaKeyBits::Rsa4096)

Check warning on line 139 in keylime/src/algorithms.rs

View check run for this annotation

Codecov / codecov/patch

keylime/src/algorithms.rs#L139

Added line #L139 was not covered by tests
}
EncryptionAlgorithm::Ecc192 => {
AsymmetricAlgorithmSelection::Ecc(EccCurve::NistP192)

Check warning on line 142 in keylime/src/algorithms.rs

View check run for this annotation

Codecov / codecov/patch

keylime/src/algorithms.rs#L142

Added line #L142 was not covered by tests
}
EncryptionAlgorithm::Ecc224 => {
AsymmetricAlgorithmSelection::Ecc(EccCurve::NistP224)

Check warning on line 145 in keylime/src/algorithms.rs

View check run for this annotation

Codecov / codecov/patch

keylime/src/algorithms.rs#L145

Added line #L145 was not covered by tests
}
EncryptionAlgorithm::Ecc256 => {
AsymmetricAlgorithmSelection::Ecc(EccCurve::NistP256)
}
EncryptionAlgorithm::Ecc384 => {
AsymmetricAlgorithmSelection::Ecc(EccCurve::NistP384)

Check warning on line 151 in keylime/src/algorithms.rs

View check run for this annotation

Codecov / codecov/patch

keylime/src/algorithms.rs#L151

Added line #L151 was not covered by tests
}
EncryptionAlgorithm::Ecc521 => {
AsymmetricAlgorithmSelection::Ecc(EccCurve::NistP521)

Check warning on line 154 in keylime/src/algorithms.rs

View check run for this annotation

Codecov / codecov/patch

keylime/src/algorithms.rs#L154

Added line #L154 was not covered by tests
}
EncryptionAlgorithm::EccSm2 => {
AsymmetricAlgorithmSelection::Ecc(EccCurve::Sm2P256)

Check warning on line 157 in keylime/src/algorithms.rs

View check run for this annotation

Codecov / codecov/patch

keylime/src/algorithms.rs#L157

Added line #L157 was not covered by tests
}
}
}
}
Expand All @@ -107,8 +165,25 @@

fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"rsa" => Ok(EncryptionAlgorithm::Rsa),
"ecc" => Ok(EncryptionAlgorithm::Ecc),
/* Use default key size and curve if not explicitly specified */
"rsa" => Ok(EncryptionAlgorithm::Rsa2048),
"ecc" => Ok(EncryptionAlgorithm::Ecc256),
"rsa1024" => Ok(EncryptionAlgorithm::Rsa1024),
"rsa2048" => Ok(EncryptionAlgorithm::Rsa2048),
"rsa3072" => Ok(EncryptionAlgorithm::Rsa3072),
"rsa4096" => Ok(EncryptionAlgorithm::Rsa4096),
"ecc192" => Ok(EncryptionAlgorithm::Ecc192),
"ecc_nist_p192" => Ok(EncryptionAlgorithm::Ecc192),
"ecc224" => Ok(EncryptionAlgorithm::Ecc224),
"ecc_nist_p224" => Ok(EncryptionAlgorithm::Ecc224),
"ecc256" => Ok(EncryptionAlgorithm::Ecc256),
"ecc_nist_p256" => Ok(EncryptionAlgorithm::Ecc256),
"ecc384" => Ok(EncryptionAlgorithm::Ecc384),
"ecc_nist_p384" => Ok(EncryptionAlgorithm::Ecc384),
"ecc521" => Ok(EncryptionAlgorithm::Ecc521),
"ecc_nist_p521" => Ok(EncryptionAlgorithm::Ecc521),
"ecc_sm2" => Ok(EncryptionAlgorithm::EccSm2),
"ecc_sm2_p256" => Ok(EncryptionAlgorithm::EccSm2),
_ => Err(AlgorithmError::UnsupportedEncryptionAlgorithm(
value.into(),
)),
Expand All @@ -119,8 +194,16 @@
impl fmt::Display for EncryptionAlgorithm {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let value = match self {
EncryptionAlgorithm::Rsa => "rsa",
EncryptionAlgorithm::Ecc => "ecc",
EncryptionAlgorithm::Rsa1024 => "rsa1024",

Check warning on line 197 in keylime/src/algorithms.rs

View check run for this annotation

Codecov / codecov/patch

keylime/src/algorithms.rs#L197

Added line #L197 was not covered by tests
EncryptionAlgorithm::Rsa2048 => "rsa", /* for backwards compatibility */
EncryptionAlgorithm::Rsa3072 => "rsa3072",
EncryptionAlgorithm::Rsa4096 => "rsa4096",
EncryptionAlgorithm::Ecc192 => "ecc192",
EncryptionAlgorithm::Ecc224 => "ecc224",
EncryptionAlgorithm::Ecc256 => "ecc", /* for backwards compatibility */
EncryptionAlgorithm::Ecc384 => "ecc384",
EncryptionAlgorithm::Ecc521 => "ecc521",
EncryptionAlgorithm::EccSm2 => "ecc_sm2",

Check warning on line 206 in keylime/src/algorithms.rs

View check run for this annotation

Codecov / codecov/patch

keylime/src/algorithms.rs#L199-L206

Added lines #L199 - L206 were not covered by tests
};
write!(f, "{value}")
}
Expand Down Expand Up @@ -219,9 +302,13 @@
#[test]
fn test_encrypt_try_from() {
let result = EncryptionAlgorithm::try_from("rsa");
assert!(result.is_ok());
assert!(result.is_ok_and(|r| r == EncryptionAlgorithm::Rsa2048));
let result = EncryptionAlgorithm::try_from("ecc");
assert!(result.is_ok());
assert!(result.is_ok_and(|r| r == EncryptionAlgorithm::Ecc256));
let result = EncryptionAlgorithm::try_from("rsa4096");
assert!(result.is_ok_and(|r| r == EncryptionAlgorithm::Rsa4096));
let result = EncryptionAlgorithm::try_from("ecc256");
assert!(result.is_ok_and(|r| r == EncryptionAlgorithm::Ecc256));
}
#[test]
fn test_unsupported_encrypt_try_from() {
Expand Down
Loading
Loading