[pbs-devel] [PATCH proxmox-backup 09/13] paperkey: add short key ID to subject

Fabian Grünbichler f.gruenbichler at proxmox.com
Fri Nov 20 17:38:39 CET 2020


and strip fingerprint from keyfile data, since it's rather long and only
informational anyway.

Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
---
 src/bin/proxmox_backup_client/key.rs | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/bin/proxmox_backup_client/key.rs b/src/bin/proxmox_backup_client/key.rs
index e56308b7..baae8726 100644
--- a/src/bin/proxmox_backup_client/key.rs
+++ b/src/bin/proxmox_backup_client/key.rs
@@ -387,7 +387,7 @@ fn paper_key(
     let data = file_get_contents(&path)?;
     let data = String::from_utf8(data)?;
 
-    let (data, is_private_key) = if data.starts_with("-----BEGIN ENCRYPTED PRIVATE KEY-----\n") {
+    let (data, subject, is_private_key) = if data.starts_with("-----BEGIN ENCRYPTED PRIVATE KEY-----\n") {
         let lines: Vec<String> = data
             .lines()
             .map(|s| s.trim_end())
@@ -403,16 +403,26 @@ fn paper_key(
             bail!("unexpected key format");
         }
 
-        (lines, true)
+        (lines, subject, true)
     } else {
         match serde_json::from_str::<KeyConfig>(&data) {
-            Ok(key_config) => {
+            Ok(mut key_config) => {
+                // add display version of fingerprint to subject and strip from key data
+                let subject = match (subject, key_config.fingerprint.take()) {
+                    (Some(mut subject), Some(fingerprint)) => {
+                        subject.push_str(&format!(" ({})", fingerprint));
+                        Some(subject)
+                    },
+                    (None, Some(fingerprint)) => Some(format!("Fingerprint: {}", fingerprint)),
+                    (subject, _) => subject,
+                };
+
                 let lines = serde_json::to_string_pretty(&key_config)?
                     .lines()
                     .map(String::from)
                     .collect();
 
-                (lines, false)
+                (lines, subject, false)
             },
             Err(err) => {
                 eprintln!("Couldn't parse '{:?}' as KeyConfig - {}", path, err);
-- 
2.20.1






More information about the pbs-devel mailing list