summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--TODO.md24
-rw-r--r--scripts/python_client.py111
2 files changed, 123 insertions, 12 deletions
diff --git a/TODO.md b/TODO.md
index b429097..15c317a 100644
--- a/TODO.md
+++ b/TODO.md
@@ -1,5 +1,29 @@
1# TODO 1# TODO
2 2
3## Office Hour/Recitation
4- [ ] Should give a little pointers but not too much, I think at first this is going to seem hard to many students but it should become fairly easy after some little pointers
5## Docs
6- [ ] Make a better explanation of authorization schema
7- [ ] register: give the register message schema(passwd is missing)
8- [ ] gradecoin: give narrative explanation
9- [ ] how to bank works
10- [ ] bank public key
11- [ ] how to start(possibly some pointers and links -- blockchain, rest, jwt, rsa, public key)
12- [ ] delete CONSTANTS
13- [ ] register should have AuthRequest in the explanation
14- [ ] link all types in schema.rs to the docs, they need to understand why we have them
15- [ ] explain hash type(MD5 is missing in Claims)
16- [ ] Initial auth request needs more explanation
17- [ ] Explain JSON Wrapped
18- [ ] Give links to the functions, their docs are very good. For example, it seems impossible to understand authentication from the first page, but when you go to handlers::authenticate_user many things are clarified.
19- [ ] There is todo at handlers::authorized_propose_transaction, fix that
20- [ ] authorized_propose_transaction and authorized_propose_block may have more explanation as in the case of
21
22
23### Authorization
24- [ ] Pointer to JWT
25- [ ] Pointer to Public Key Sign
26
3## Tests 27## Tests
4- [ ] User Authentication/Authentication Tests 28- [ ] User Authentication/Authentication Tests
5- [ ] Route Tests 29- [ ] Route Tests
diff --git a/scripts/python_client.py b/scripts/python_client.py
index fe96cc2..2713f47 100644
--- a/scripts/python_client.py
+++ b/scripts/python_client.py
@@ -20,6 +20,92 @@ hash = "SHA-256"
20# return priv_key.publickey() 20# return priv_key.publickey()
21 21
22 22
23import requests
24from jwt import (
25 JWT,
26 jwk_from_dict,
27 jwk_from_pem,
28)
29from jwt.utils import get_int_from_datetime
30from datetime import datetime, timedelta, timezone
31
32
33def create_hashed_transaction():
34
35 pass
36
37def create_jwt():
38 instance = JWT()
39 message = {
40 'tha': create_hashed_transaction(),
41 'iat': get_int_from_datetime(datetime.now(timezone.utc)),
42 'exp': get_int_from_datetime(
43 datetime.now(timezone.utc) + timedelta(hours=1)),
44 }
45
46 with open('rsa_private_key.pem', 'rb') as fh:
47 signing_key = jwk_from_pem(fh.read())
48
49 compact_jws = instance.encode(message, signing_key, alg='RS256')
50
51 return compact_jws
52
53
54def post_register():
55 credentials = {
56 "c": "",
57 "iv": "",
58 "key": ""
59 }
60 response = requests.post("localhost:8080/register", data=credentials)
61
62
63def post_transaction_from_bank():
64 body = {
65 "by": "{my_public_key}",
66 "source": "{bank_public_key}",
67 "target": "{my_public_key}",
68 "amount": 0,
69 "timestamp": get_int_from_datetime(datetime.now(timezone.utc)),
70 }
71 header = {'Content-Type': 'application/json', 'Authorization': f'Bearer {create_jwt()}'}
72
73 response = requests.post("localhost:8080/transaction", headers=header, data=body)
74 print(response.headers)
75 print(response.content)
76
77def post_transaction_to_user():
78 body = {
79 "by": "{my_public_key}",
80 "source": "{my_public_key}",
81 "target": "{user_public_key}",
82 "amount": 0,
83 "timestamp": get_int_from_datetime(datetime.now(timezone.utc)),
84 }
85 header = {'Content-Type': 'application/json', 'Authorization': f'Bearer {create_jwt()}'}
86
87 response = requests.post("localhost:8080/transaction", headers=header, data=body)
88
89
90def post_block():
91 credentials = {
92 "c": "",
93 "iv": "",
94 "key": ""
95 }
96 response = requests.post("localhost:8080/register", params=credentials)
97
98
99def get_transaction():
100 response = requests.get("http://localhost:8080/transaction")
101 print(response.headers)
102
103
104def get_block():
105 response = requests.get("http://localhost:8080/block")
106 print(response.headers)
107
108
23def encrypt(message, pub_key): 109def encrypt(message, pub_key):
24 cipher = PKCS1_OAEP.new(pub_key) 110 cipher = PKCS1_OAEP.new(pub_key)
25 return cipher.encrypt(message) 111 return cipher.encrypt(message)
@@ -39,18 +125,19 @@ AUd927qkxgg/nyyFqwxIbTxebxzpNX8IHMT8PgNdMxVMqnhBWxiw1nborY+pwGVL
39MwIDAQAB 125MwIDAQAB
40-----END PUBLIC KEY-----""" 126-----END PUBLIC KEY-----"""
41 } 127 }
42 with open("../secrets/gradecoin.pub", "r") as fs: 128 # with open("../secrets/gradecoin.pub", "r") as fs:
43 data = fs.read() 129 # data = fs.read()
44 pubkeyobj = RSA.importKey(data) 130 # pubkeyobj = RSA.importKey(data)
45 131 #
46 cipher = PKCS1_OAEP.new(pubkeyobj) 132 # cipher = PKCS1_OAEP.new(pubkeyobj)
47 133 #
48 ser = json.dumps(myself, separators=(',', ':')) 134 # ser = json.dumps(myself, separators=(',', ':'))
49 135 #
50 a = cipher.encrypt(ser) 136 # a = cipher.encrypt(ser)
51 137 #
52 print(f"{a}") 138 # print(f"{a}")
53 139 get_block()
140 get_transaction()
54 141
55 142
56 143