Skip to content

Commit ac8c5a9

Browse files
sarroutbiclaude
andcommitted
Add default ECC P-256 support for mTLS keys
This change updates the default key generation algorithm for mTLS keys from RSA 2048 to ECC P-256 (secp256r1) for improved security and performance characteristics. Key changes: - Updated keylime-agent/src/main.rs to use Ecc256 instead of Rsa2048 for mTLS key generation via load_or_generate_key() - Updated keylime/src/cert.rs cert_from_server_key() function to generate ECC P-256 keys instead of RSA 2048 when creating new keys Benefits: - Smaller key sizes (256-bit vs 2048-bit) with equivalent security - Faster key generation and cryptographic operations - Lower memory and storage footprint - Better performance in embedded and resource-constrained environments Backward compatibility: - Existing RSA keys will continue to work due to load_or_generate_key logic that loads existing keys regardless of algorithm - Algorithm validation is disabled for mTLS keys to maintain compatibility - Only affects new key generation when no existing key file is found The ECC P-256 curve (X9_62_PRIME256V1/secp256r1) is widely supported, FIPS 186-4 approved, and provides 128-bit security level equivalent to RSA 3072. Co-Authored-By: Claude <[email protected]> Signed-off-by: Sergio Arroutbi <[email protected]>
1 parent 6f533fa commit ac8c5a9

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

keylime-agent/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,11 +515,12 @@ async fn main() -> Result<()> {
515515

516516
// Load or generate mTLS key pair (separate from payload keys)
517517
// The mTLS key is always persistent, stored at the configured path.
518+
// Uses ECC P-256 by default for better security and performance
518519
let key_path = Path::new(&config.server_key);
519520
let (mtls_pub, mtls_priv) = crypto::load_or_generate_key(
520521
key_path,
521522
Some(config.server_key_password.as_ref()),
522-
keylime::algorithms::EncryptionAlgorithm::Rsa2048,
523+
keylime::algorithms::EncryptionAlgorithm::Ecc256,
523524
false, // Don't validate algorithm for mTLS keys (for backward compatibility)
524525
)?;
525526

keylime/src/cert.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@ pub struct CertificateConfig {
1616
pub fn cert_from_server_key(
1717
config: &CertificateConfig,
1818
) -> Result<(X509, PKey<Public>)> {
19+
use openssl::ec::EcGroup;
20+
use openssl::nid::Nid;
21+
1922
let cert: X509;
2023
let (mtls_pub, mtls_priv) = match config.server_key.as_ref() {
2124
"" => {
2225
debug!(
2326
"The server_key option was not set in the configuration file"
2427
);
25-
debug!("Generating new key pair");
26-
crypto::rsa_generate_pair(2048)?
28+
debug!("Generating new ECC P-256 key pair");
29+
let group = EcGroup::from_curve_name(Nid::X9_62_PRIME256V1)
30+
.map_err(crypto::CryptoError::ECGroupFromNidError)?;
31+
crypto::ecc_generate_pair(&group)?
2732
}
2833
path => {
2934
let key_path = Path::new(&path);
@@ -37,8 +42,11 @@ pub fn cert_from_server_key(
3742
Some(&config.server_key_password),
3843
)?
3944
} else {
40-
debug!("Generating new key pair");
41-
let (public, private) = crypto::rsa_generate_pair(2048)?;
45+
debug!("Generating new ECC P-256 key pair");
46+
let group =
47+
EcGroup::from_curve_name(Nid::X9_62_PRIME256V1)
48+
.map_err(crypto::CryptoError::ECGroupFromNidError)?;
49+
let (public, private) = crypto::ecc_generate_pair(&group)?;
4250
// Write the generated key to the file
4351
crypto::write_key_pair(
4452
&private,

0 commit comments

Comments
 (0)