Skip to content

Commit 64f3a6b

Browse files
committed
Return DER of public key from create_key
Signed-off-by: Marcel Guzik <marcel.guzik@cumulocity.com>
1 parent c1a1250 commit 64f3a6b

File tree

10 files changed

+243
-29
lines changed

10 files changed

+243
-29
lines changed

Cargo.lock

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

crates/core/tedge/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ mime_guess = { workspace = true }
3232
mqtt_channel = { workspace = true }
3333
nix = { workspace = true }
3434
pad = { workspace = true }
35-
pem = { workspace = true }
35+
pem.workspace = true
3636
rasn = { workspace = true }
3737
rasn-cms = { workspace = true }
3838
reqwest = { workspace = true, features = [

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,13 @@ impl Command for CreateKeyCmd {
3838
token: None,
3939
label: self.label.clone(),
4040
};
41-
pkcs11client.create_key(None, params)?;
41+
let pubkey_der = pkcs11client.create_key(None, params)?;
42+
let pubkey_pem = pem::Pem::new("PUBLIC KEY", pubkey_der);
43+
let pubkey_pem = pem::encode(&pubkey_pem);
44+
4245
eprintln!("New keypair was successfully created.");
46+
eprintln!("Public key:\n{pubkey_pem}\n");
47+
4348
Ok(())
4449
}
4550
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ oid-registry = "0.8.1"
2020
percent-encoding.workspace = true
2121
postcard.workspace = true
2222
rand = "0.9.1"
23+
rsa = "0.9.8"
2324
rustls.workspace = true
2425
sd-listen-fds.workspace = true
2526
serde.workspace = true

crates/extensions/tedge-p11-server/src/client.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ impl TedgeP11Client {
114114
Ok(response.0)
115115
}
116116

117-
pub fn create_key(&self, uri: Option<String>, params: CreateKeyParams) -> anyhow::Result<()> {
117+
pub fn create_key(
118+
&self,
119+
uri: Option<String>,
120+
params: CreateKeyParams,
121+
) -> anyhow::Result<Vec<u8>> {
118122
let stream = UnixStream::connect(&self.socket_path).with_context(|| {
119123
format!(
120124
"Failed to connect to tedge-p11-server UNIX socket at '{}'",
@@ -130,13 +134,13 @@ impl TedgeP11Client {
130134

131135
let response = connection.read_frame()?;
132136

133-
let Frame1::CreateKeyResponse = response else {
137+
let Frame1::CreateKeyResponse(pubkey_der) = response else {
134138
bail!("protocol error: bad response, expected create_key, received: {response:?}");
135139
};
136140

137141
debug!("Sign complete");
138142

139-
Ok(())
143+
Ok(pubkey_der)
140144
}
141145

142146
fn do_request(&self, request: Frame1) -> anyhow::Result<Frame1> {

crates/extensions/tedge-p11-server/src/connection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub enum Frame1 {
9191
ChooseSchemeResponse(ChooseSchemeResponse),
9292
SignResponse(SignResponse),
9393
CreateKeyRequest(CreateKeyRequest),
94-
CreateKeyResponse,
94+
CreateKeyResponse(Vec<u8>),
9595
}
9696

9797
/// An error that can be returned to the client by the server.

0 commit comments

Comments
 (0)