[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] branch master updated: Extend python CLI to ask and restore k
From: |
gnunet |
Subject: |
[libeufin] branch master updated: Extend python CLI to ask and restore keys backup. |
Date: |
Fri, 22 Nov 2019 03:32:23 +0100 |
This is an automated email from the git hooks/post-receive script.
marcello pushed a commit to branch master
in repository libeufin.
The following commit(s) were added to refs/heads/master by this push:
new e4efa2e Extend python CLI to ask and restore keys backup.
e4efa2e is described below
commit e4efa2e778a29c2534589820a51d866e5ad5f0a6
Author: Marcello Stanisci <address@hidden>
AuthorDate: Fri Nov 22 03:31:46 2019 +0100
Extend python CLI to ask and restore keys backup.
---
sandbox/src/main/python/libeufin-cli | 82 +++++++++++++++++++++++++++++++++++-
1 file changed, 81 insertions(+), 1 deletion(-)
diff --git a/sandbox/src/main/python/libeufin-cli
b/sandbox/src/main/python/libeufin-cli
index 5c7404b..af9d1f1 100755
--- a/sandbox/src/main/python/libeufin-cli
+++ b/sandbox/src/main/python/libeufin-cli
@@ -2,12 +2,14 @@
import os
import click
+import json
import hashlib
import errno
from datetime import datetime
-from requests import post, get
+from requests import post, get, put
from Crypto.PublicKey import RSA
from urllib.parse import urljoin
+from getpass import getpass
@click.group()
@click.option(
@@ -21,6 +23,84 @@ def cli(ctx, base_url):
def ebics():
pass
+
+@ebics.command(help="Restore private keys backup.")
+@click.pass_obj
+@click.option(
+ "--customer-id",
+ help="numerical ID of the customer at the Nexus",
+ required=False,
+ default=1)
+@click.option(
+ "--backup-file",
+ help="File where the backup is stored",
+ required=False,
+ default="/tmp/backup.json")
+def restore(obj, customer_id, backup_file):
+ try:
+ backup = open(backup_file, "r")
+ except Exception:
+ print("Could not open the backup at {}".format(backup_file))
+ return
+
+ backup_json = json.loads(backup.read())
+ backup.close()
+ passphrase = getpass("Passphrase: ")
+ backup_json["passphrase"] = passphrase
+
+ url = urljoin(obj["base_url"],
"/ebics/subscribers/{}/restoreBackup".format(customer_id))
+
+ try:
+ response = post(url, json=backup_json)
+ except Exception:
+ print("Could not reach the bank")
+ return
+
+ if response.status_code != 200:
+ print("Unsuccessful status code gotten:
{}".format(response.status_code))
+ return
+
+ print("Keys successfully restored")
+
+
+@ebics.command(help="Obtain passphrase-protected private keys")
+@click.pass_obj
+@click.option(
+ "--customer-id",
+ help="numerical ID of the customer at the Nexus",
+ required=False,
+ default=1)
+@click.option(
+ "--output-file",
+ help="File that will store the backup",
+ required=False,
+ default="/tmp/backup.json")
+def backup(obj, customer_id, output_file):
+ passphrase = getpass("Passphrase: ")
+ passphrase_again = getpass("Passphrase (again): ")
+
+ if passphrase != passphrase_again:
+ print("Passphrase differs, exiting.")
+ return
+
+ url = urljoin(obj["base_url"],
"/ebics/subscribers/{}/backup".format(customer_id))
+
+ try:
+ response = put(url, json=dict(passphrase=passphrase))
+ except Exception:
+ print("Could not reach the bank")
+ return
+
+ if response.status_code != 200:
+ print("Unsuccessful status code gotten:
{}".format(response.status_code))
+ return
+
+ output = open(output_file, "w+")
+ output.write(response.text)
+ output.close()
+
+ print("Backup stored in {}".format(output_file))
+
@ebics.command(help="send INI message")
@click.pass_obj
@click.option(
--
To stop receiving notification emails like this one, please contact
address@hidden.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libeufin] branch master updated: Extend python CLI to ask and restore keys backup.,
gnunet <=