From: Dietmar Maurer <dietmar@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup] proxmox_backup_client key: add new paper-key command
Date: Mon, 28 Sep 2020 18:27:12 +0200 [thread overview]
Message-ID: <20200928162712.13867-1-dietmar@proxmox.com> (raw)
---
debian/control.in | 2 +-
src/bin/proxmox_backup_client/key.rs | 67 ++++++++++++++++++++++++++++
2 files changed, 68 insertions(+), 1 deletion(-)
diff --git a/debian/control.in b/debian/control.in
index 8e2312d..2e6d82f 100644
--- a/debian/control.in
+++ b/debian/control.in
@@ -19,7 +19,7 @@ Description: Proxmox Backup Server daemon with tools and GUI
Package: proxmox-backup-client
Architecture: any
-Depends: ${misc:Depends}, ${shlibs:Depends}
+Depends: qrencode ${misc:Depends}, ${shlibs:Depends}
Description: Proxmox Backup Client tools
This package contains the Proxmox Backup client, which provides a
simple command line tool to create and restore backups.
diff --git a/src/bin/proxmox_backup_client/key.rs b/src/bin/proxmox_backup_client/key.rs
index f60687e..e87f048 100644
--- a/src/bin/proxmox_backup_client/key.rs
+++ b/src/bin/proxmox_backup_client/key.rs
@@ -1,4 +1,6 @@
use std::path::PathBuf;
+use std::io::Write;
+use std::process::{Stdio, Command};
use anyhow::{bail, format_err, Error};
use serde::{Deserialize, Serialize};
@@ -261,6 +263,66 @@ fn create_master_key() -> Result<(), Error> {
Ok(())
}
+#[api(
+ input: {
+ properties: {
+ path: {
+ description: "Key file. Without this the default key's will be used.",
+ optional: true,
+ },
+ subject: {
+ description: "Include the specified subject as titel text.",
+ optional: true,
+ },
+ },
+ },
+)]
+/// Generate a printable, human readable text file containing the encryption key.
+///
+/// This also includes a scanable QR code for fast key restore.
+fn paper_key(path: Option<String>, subject: Option<String>) -> Result<(), Error> {
+ let path = match path {
+ Some(path) => PathBuf::from(path),
+ None => {
+ let path = find_default_encryption_key()?
+ .ok_or_else(|| {
+ format_err!("no encryption file provided and no default file found")
+ })?;
+ path
+ }
+ };
+
+ let data = file_get_contents(&path)?;
+ let key_config: KeyConfig = serde_json::from_slice(&data)?;
+ let key_text = serde_json::to_string_pretty(&key_config)?;
+
+ if let Some(subject) = subject {
+ println!("Subject: {}\n", subject);
+ }
+
+ println!("-----BEGIN PROXMOX BACKUP KEY-----");
+ println!("{}", key_text);
+ println!("-----END PROXMOX BACKUP KEY-----");
+
+ let mut child = Command::new("qrencode")
+ .args(&["-t", "utf8i", "-lm"])
+ .stdin(Stdio::piped())
+ .stdout(Stdio::piped())
+ .spawn()?;
+
+ {
+ let stdin = child.stdin.as_mut().expect("Failed to open stdin");
+ stdin.write_all(key_text.as_bytes()).expect("Failed to write to stdin");
+ }
+
+ let output = child.wait_with_output().expect("Failed to read stdout");
+
+ println!("{}", String::from_utf8_lossy(&output.stdout));
+
+ Ok(())
+}
+
+
pub fn cli() -> CliCommandMap {
let key_create_cmd_def = CliCommand::new(&API_METHOD_CREATE)
.arg_param(&["path"])
@@ -275,9 +337,14 @@ pub fn cli() -> CliCommandMap {
.arg_param(&["path"])
.completion_cb("path", tools::complete_file_name);
+ let paper_key_cmd_def = CliCommand::new(&API_METHOD_PAPER_KEY)
+ .arg_param(&["path"])
+ .completion_cb("path", tools::complete_file_name);
+
CliCommandMap::new()
.insert("create", key_create_cmd_def)
.insert("create-master-key", key_create_master_key_cmd_def)
.insert("import-master-pubkey", key_import_master_pubkey_cmd_def)
.insert("change-passphrase", key_change_passphrase_cmd_def)
+ .insert("paper-key", paper_key_cmd_def)
}
--
2.20.1
reply other threads:[~2020-09-28 16:27 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200928162712.13867-1-dietmar@proxmox.com \
--to=dietmar@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox