Skip to content

Commit 4b49135

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

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
@@ -121,7 +121,11 @@ impl TedgeP11Client {
121121
Ok(response.0)
122122
}
123123

124-
pub fn create_key(&self, uri: Option<String>, params: CreateKeyParams) -> anyhow::Result<()> {
124+
pub fn create_key(
125+
&self,
126+
uri: Option<String>,
127+
params: CreateKeyParams,
128+
) -> anyhow::Result<Vec<u8>> {
125129
let stream = UnixStream::connect(&self.socket_path).with_context(|| {
126130
format!(
127131
"Failed to connect to tedge-p11-server UNIX socket at '{}'",
@@ -137,13 +141,13 @@ impl TedgeP11Client {
137141

138142
let response = connection.read_frame()?;
139143

140-
let Frame1::CreateKeyResponse = response else {
144+
let Frame1::CreateKeyResponse(pubkey_der) = response else {
141145
bail!("protocol error: bad response, expected create_key, received: {response:?}");
142146
};
143147

144148
debug!("Sign complete");
145149

146-
Ok(())
150+
Ok(pubkey_der)
147151
}
148152

149153
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)