Skip to content

Commit 993fd82

Browse files
committed
[wip] 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 76e9e6f commit 993fd82

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
@@ -6,6 +6,7 @@ use super::show::ShowCertCmd;
66
use crate::certificate_is_self_signed;
77
use crate::cli::certificate::c8y;
88
use crate::cli::certificate::create_key::CreateKeyCmd;
9+
use crate::cli::certificate::create_key::KeyType;
910
use crate::cli::common::Cloud;
1011
use crate::cli::common::CloudArg;
1112
use crate::command::BuildCommand;
@@ -52,11 +53,17 @@ pub enum TEdgeCertCli {
5253

5354
/// Create a new keypair
5455
CreateKey {
56+
#[arg(long)]
57+
label: String,
58+
59+
#[arg(long)]
60+
r#type: KeyType,
61+
5562
#[arg(long, default_value = "2048")]
5663
bits: u16,
5764

58-
#[arg(long)]
59-
label: String,
65+
#[arg(long, default_value = "256")]
66+
curve: u16,
6067
},
6168

6269
/// Renew the device certificate
@@ -210,7 +217,18 @@ impl BuildCommand for TEdgeCertCli {
210217
cmd.into_boxed()
211218
}
212219

213-
TEdgeCertCli::CreateKey { bits, label } => CreateKeyCmd { bits, label }.into_boxed(),
220+
TEdgeCertCli::CreateKey {
221+
bits,
222+
label,
223+
r#type,
224+
curve,
225+
} => CreateKeyCmd {
226+
bits,
227+
label,
228+
r#type,
229+
curve,
230+
}
231+
.into_boxed(),
214232

215233
TEdgeCertCli::Show {
216234
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)