libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit bf1313913a632d5ab757c4d053e98370ba83c0cc
parent 6d540d721fc60c03aea8487ea9e1a7cdd1f5215d
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date:   Tue,  1 Oct 2019 18:17:28 +0200

Test utility.

Upon submitting a new customer to the bank, a set of three keys
is created and stored temporarily on disk.  That way, the set can
be retrieved by the "keyletter" functionality and sent to the
bank for confirmation.

Diffstat:
Msrc/main/python/libeufin-cli | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------
1 file changed, 58 insertions(+), 18 deletions(-)

diff --git a/src/main/python/libeufin-cli b/src/main/python/libeufin-cli @@ -2,10 +2,15 @@ import click from requests import post, get +from Crypto.PublicKey import RSA +from urllib.parse import urljoin + + +CUSTOMERS_PATH = "/tmp/libeufindata/customers" @click.group() @click.option( - "--base-url", default="http://host.name", + "--base-url", default="http://localhost:5000/", help="Base URL of the bank (defaults to http://localhost:5000/)") @click.pass_context def cli(ctx, base_url): @@ -15,10 +20,43 @@ def cli(ctx, base_url): def admin(): pass -@admin.command(help="Create a new customer") +@admin.command(help="Create a new customer (generating name)") @click.pass_obj def customers(obj): - pass + + from faker import Faker + name = Faker().name() + + url = urljoin(obj["base_url"], "/admin/customers") + print("Sending request for: {} to {}".format(name, url)) + try: + resp = post(url, json=dict(name=name)) + except Exception: + print("Could not reach the bank") + + # use the customer id contained in the response to + # query for your details. + print(resp) + customer_id = resp.get("id") + assert(customer_id != None) + + customer_path = "{}/{}".format(CUSTOMERS_PATH, customer_id) + try: + os.makedirs(customer_path) + except OSError as e: + # For now, just overwrite all is found under existing directory. + assert(e.errno == errno.EEXIST) + + # Generate keys for new user. + for keytype in ("eskey", "iakey", "enckey"): + + key = RSA.generate(2048) + pem = key.exportKey("PEM").decode("ascii") + keyfile = open("{}/{}.pem".format(customer_path, keytype), "w") + keyfile.write(pem) + keyfile.write("\n") + keyfile.close() + print("{} saved".format(keytype)) @admin.command(help="Ask details about a customer") @click.option("--customer-id", help="bank non-EBICS identifier of the customer") @@ -30,25 +68,27 @@ def customer_info(obj): help="Confirm INI and HIA messages via JSON API" ) @click.option( - "--enc-key", required=True, default="./enc.pem", - help="Path of encryption RSA public key in PEM format" -) -@click.option( - "--es-key", required=True, default="./es.pem", - help="Path of signature RSA public key in PEM format" -) -@click.option( - "--ia-key", required=True, default="./ia.pem", - help="Path of identification and authentication RSA public key in PEM format" + "--customer-id", required=True, + help="id of the customer at the bank (used to pick keyset on disk)" ) def keyletter(enc_key, es_key, ia_key): - from Crypto.PublicKey import RSA - try: - enckey = RSA.importKey(open(enc_key, "r").read()) - eskey = RSA.importKey(open(enc_key, "r").read()) - iakey = RSA.importKey(open(enc_key, "r").read()) + eskey = RSA.importKey( + open("{}/{}/eskey.pem".format( + CUSTOMERS_PATH, customer_id), "r").read() + ) + + enckey = RSA.importKey( + open("{}/{}/enckey.pem".format( + CUSTOMERS_PATH, customer_id), "r").read() + ) + + iakey = RSA.importKey( + open("{}/{}/iakey.pem".format( + CUSTOMERS_PATH, customer_id), "r").read() + ) + except FileNotFoundError: print("Could not find all the keys")