Skip to content

Commit 577afb3

Browse files
committed
Creating EC keys
Added options to create EC keys, however there remains a problem that p11tool doesn't display curve names as it does with keys generated with `p11tool --generate-privkey`. Signed-off-by: Marcel Guzik <marcel.guzik@cumulocity.com>
1 parent fd56a3a commit 577afb3

File tree

5 files changed

+155
-49
lines changed

5 files changed

+155
-49
lines changed

Cargo.lock

Lines changed: 57 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/core/tedge/src/cli/certificate/cli.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::certificate_is_self_signed;
77
use crate::cli::certificate::c8y;
88
use crate::cli::certificate::create_csr::Key;
99
use crate::cli::certificate::create_key::CreateKeyCmd;
10+
use crate::cli::certificate::create_key::KeyType;
1011
use crate::cli::common::Cloud;
1112
use crate::cli::common::CloudArg;
1213
use crate::command::BuildCommand;
@@ -54,11 +55,17 @@ pub enum TEdgeCertCli {
5455

5556
/// Create a new keypair
5657
CreateKey {
58+
#[arg(long)]
59+
label: String,
60+
61+
#[arg(long)]
62+
r#type: KeyType,
63+
5764
#[arg(long, default_value = "2048")]
5865
bits: u16,
5966

60-
#[arg(long)]
61-
label: String,
67+
#[arg(long, default_value = "256")]
68+
curve: u16,
6269
},
6370

6471
/// Renew the device certificate
@@ -230,7 +237,18 @@ impl BuildCommand for TEdgeCertCli {
230237
cmd.into_boxed()
231238
}
232239

233-
TEdgeCertCli::CreateKey { bits, label } => CreateKeyCmd { bits, label }.into_boxed(),
240+
TEdgeCertCli::CreateKey {
241+
bits,
242+
label,
243+
r#type,
244+
curve,
245+
} => CreateKeyCmd {
246+
bits,
247+
label,
248+
r#type,
249+
curve,
250+
}
251+
.into_boxed(),
234252

235253
TEdgeCertCli::Show {
236254
cloud,

crates/core/tedge/src/cli/certificate/create_key.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use clap::ValueEnum;
12
use tedge_config::TEdgeConfig;
23
use tedge_p11_server::pkcs11::{CreateKeyParams, KeyTypeParams};
34

@@ -6,7 +7,15 @@ use crate::log::MaybeFancy;
67

78
pub struct CreateKeyCmd {
89
pub bits: u16,
10+
pub curve: u16,
911
pub label: String,
12+
pub r#type: KeyType,
13+
}
14+
15+
#[derive(Debug, Clone, PartialEq, Eq, ValueEnum)]
16+
pub enum KeyType {
17+
Rsa,
18+
Ec,
1019
}
1120

1221
#[async_trait::async_trait]
@@ -20,8 +29,12 @@ impl Command for CreateKeyCmd {
2029
let pkcs11client = tedge_p11_server::client::TedgeP11Client::with_ready_check(
2130
socket_path.as_std_path().into(),
2231
);
32+
let key = match self.r#type {
33+
KeyType::Rsa => KeyTypeParams::Rsa { bits: self.bits },
34+
KeyType::Ec => KeyTypeParams::Ec { curve: self.curve },
35+
};
2336
let params = CreateKeyParams {
24-
key: KeyTypeParams::Rsa { bits: self.bits },
37+
key,
2538
token: None,
2639
label: self.label.clone(),
2740
};

crates/extensions/tedge-p11-server/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ camino.features = ["serde1"]
1616
camino.workspace = true
1717
clap.workspace = true
1818
cryptoki.workspace = true
19+
oid-registry = "0.8.1"
1920
percent-encoding.workspace = true
2021
postcard.workspace = true
22+
rand = "0.9.1"
2123
rustls.workspace = true
2224
sd-listen-fds.workspace = true
2325
serde.workspace = true

0 commit comments

Comments
 (0)