gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [libeufin] branch master updated: continue with /customer/k


From: gnunet
Subject: [GNUnet-SVN] [libeufin] branch master updated: continue with /customer/keyletter testing utility
Date: Wed, 02 Oct 2019 12:46:03 +0200

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 9e8835f  continue with /customer/keyletter testing utility
9e8835f is described below

commit 9e8835f70406108f81f6378db69a9c0d4257938e
Author: Marcello Stanisci <address@hidden>
AuthorDate: Wed Oct 2 12:45:39 2019 +0200

    continue with /customer/keyletter testing utility
---
 src/main/python/libeufin-cli | 92 +++++++++++++++++++++++++++++++++++++-------
 1 file changed, 78 insertions(+), 14 deletions(-)

diff --git a/src/main/python/libeufin-cli b/src/main/python/libeufin-cli
index f06c7db..721fd63 100755
--- a/src/main/python/libeufin-cli
+++ b/src/main/python/libeufin-cli
@@ -2,12 +2,18 @@
 
 import os
 import click
+import hashlib
+from datetime import datetime
 from requests import post, get
 from Crypto.PublicKey import RSA 
 from urllib.parse import urljoin
 
-
 CUSTOMERS_PATH = "/tmp/libeufindata/customers"
+RECIPIENT_BANK = "LibEuBank"
+RSA_LENGTH = 2048 # is length for both exponent and modulus?
+IA_VERSION = "X002"
+ENC_VERSION = "E002"
+ES_VERSION = "A005"
 
 @click.group()
 @click.option(
@@ -49,8 +55,7 @@ def customers(obj):
 
     # Generate keys for new user.
     for keytype in ("eskey", "iakey", "enckey"):
-
-        key = RSA.generate(2048)
+        key = RSA.generate(RSA_LENGTH)
         pem = key.exportKey("PEM").decode("ascii")
         keyfile = open("{}/{}.pem".format(customer_path, keytype), "w")
         keyfile.write(pem)
@@ -71,16 +76,22 @@ def customer_info(obj):
     "--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):
+@click.pass_obj
+def keyletter(obj, customer_id):
 
-    #
-    # Missing:
-    #
-    # 1) all the fields to put in the request
-    # 2) hashing the key
-    # 3) actual send
-    #
+    # Get userId.
+    url = urljoin(obj["base_url"], "/admin/customers/{}".format(customer_id))
+    resp = get(url)
+    assert(resp.status_code == 200)
+    user_id = resp.json().get("ebicsInfo", {}).get("userId")
+    name = resp.json().get("name")
+    assert(user_id)
+    assert(name)
 
+    # Take timestamp.
+    ts = datetime.now()
+
+    # Get keys from disk.
     try:
         eskey = RSA.importKey(
             open("{}/{}/eskey.pem".format(
@@ -99,10 +110,63 @@ def keyletter(enc_key, es_key, ia_key):
 
     except FileNotFoundError:
         print("Could not find all the keys")
+        assert(False)
+
+    es_exponent = format(eskey.e, "x")
+    es_modulus = format(eskey.n, "x")
+
+    ia_exponent = format(iakey.e, "x")
+    ia_modulus = format(iakey.n, "x")
+
+    enc_exponent = format(enckey.e, "x")
+    enc_modulus = format(enckey.n, "x")
+
+    # Make the request body.
+    body = dict(
+
+        INI=dict(
+            userId=user_id,
+            customerId=customer_id,
+            name=name,
+            date=ts.strftime("%d.%m.%Y"),
+            time=ts.strftime("%H.%M.%S"),
+            recipient=RECIPIENT_BANK,
+            version=ES_VERSION,
+            exponent_length=RSA_LENGTH,
+            exponent=es_exponent,
+            modulus_length=RSA_LENGTH,
+            modulus=es_modulus,
+            hash=hashlib.sha256("{} {}".format(es_exponent, 
es_modulus).encode()).hexdigest()
+        ),
+
+        HIA=dict(
+            userId=user_id,
+            customerId=customer_id,
+            name=name,
+            date=ts.strftime("%d.%m.%Y"),
+            time=ts.strftime("%H.%M.%S"),
+            recipient=RECIPIENT_BANK,
+            ia_version=IA_VERSION,
+            ia_exponent_length=RSA_LENGTH,
+            ia_exponent=ia_exponent,
+            ia_modulus_length=RSA_LENGTH,
+            ia_modulus=ia_modulus,
+            ia_hash=hashlib.sha256("{} {}".format(ia_exponent, 
ia_modulus).encode()).hexdigest(),
+            enc_version=ENC_VERSION,
+            enc_exponent_length=RSA_LENGTH,
+            enc_exponent=enc_exponent,
+            enc_modulus_length=RSA_LENGTH,
+            enc_modulus=enc_modulus,
+            enc_hash=hashlib.sha256("{} {}".format(enc_exponent, 
enc_modulus).encode()).hexdigest()
+        )
+    )
+
+    resp = post(url, json=body)
 
-    # hex exponent = format(key.e, "x")
-    # hex modulus = format(key.n, "x")
+    if resp.status_code != 200:
+        print("Bank did not accept this letter.")
+        return
 
-    # post(url, json=body)
+    print("Letter accepted by the bank!")
 
 cli()

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]