Skip to content

Commit

Permalink
93: added support for reading asymmetric keys from the /transit/keys …
Browse files Browse the repository at this point in the history
…route

Previously the route assumed a symmetric key's creation unix timestamp would be returned.
For asymmetric keys the response differs; it returns the creation RFC3339 timestamp, public key, and key type.

Mentions jmgilman#93.

Signed-off-by: Matt Davis <[email protected]>
  • Loading branch information
MattDavis00 committed May 13, 2024
1 parent a824255 commit 253523b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ native-tls-vendored = [ "reqwest/native-tls-vendored", "rustify/default" ]
[dependencies]
async-trait = "0.1.68"
bytes = "1.4.0"
chrono = { version = "0.4.38", features = ["serde"] }
derive_builder = "0.12.0"
http = "0.2.9"
reqwest = { version = "0.11.15", default-features = false }
Expand Down
4 changes: 4 additions & 0 deletions src/api/transit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ pub enum KeyType {
/// ECDSA using the P-521 elliptic curve (asymmetric)
EcdsaP521,
/// RSA with bit size of 2048 (asymmetric)
// kebab-case conversion doesn't work for words starting with a digit.
#[serde(rename = "rsa-2048")]
Rsa2048,
/// RSA with bit size of 3072 (asymmetric)
#[serde(rename = "rsa-3072")]
Rsa3072,
/// RSA with bit size of 4096 (asymmetric)
#[serde(rename = "rsa-4096")]
Rsa4096,
}

Expand Down
20 changes: 19 additions & 1 deletion src/api/transit/responses.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::KeyType;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

Expand All @@ -12,7 +13,8 @@ pub struct ReadKeyResponse {
pub derived: bool,
pub exportable: bool,
pub allow_plaintext_backup: bool,
pub keys: HashMap<String, u64>,
/// If the key is asymmetric, the API returns the public keys
pub keys: ReadKeyData,
pub min_decryption_version: u64,
pub min_encryption_version: u64,
pub name: String,
Expand All @@ -23,6 +25,22 @@ pub struct ReadKeyResponse {
pub imported: Option<bool>,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ReadKeyData {
/// A key ID integer (string) to unix timestamp.
Symmetric(HashMap<String, u64>),
/// A key ID integer (string) to public key mapping.
Asymmetric(HashMap<String, ReadPublicKeyEntry>),
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ReadPublicKeyEntry {
creation_time: DateTime<Utc>,
name: String,
public_key: String,
}

/// Response from executing
/// [ListKeysRequest][crate::api::transit::requests::ListKeysRequest]
#[derive(Deserialize, Debug, Serialize)]
Expand Down

0 comments on commit 253523b

Please sign in to comment.