From c16c6cb97265b11a8bacb55ee95c2ed7ed29602d Mon Sep 17 00:00:00 2001 From: Kushal Das Date: Aug 18 2015 15:36:45 +0000 Subject: Test client code. --- diff --git a/brumeclient/brume.py b/brumeclient/brume.py new file mode 100755 index 0000000..4555809 --- /dev/null +++ b/brumeclient/brume.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3.4 + +import json +import base64 +import requests + +def tobase64(s): + return base64.b64encode(s.encode('utf-8')) + +def frombase64(b): + return base64.b64decode(b).decode('utf-8') + +def tobase64_b(s): + return base64.b64encode(s) + + +myusername = 'kdas' + + +from cryptography.hazmat.primitives import hashes, hmac +from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC +from cryptography.hazmat.backends import default_backend +digest = hashes.Hash(hashes.SHA512(), backend=default_backend()) + +digest.update(myusername.encode('utf-8')) + +salt = digest.finalize() +kdf = PBKDF2HMAC(algorithm=hashes.SHA512(), + length=32, + salt=salt, + iterations=100000, + backend=default_backend() + ) +key = kdf.derive(b"password") + + + +if __name__ == '__main__': + data = {'command': 'create_instance'} + data = json.dumps(data) + + h = hmac.HMAC(key, hashes.SHA512(), backend=default_backend()) + h.update(data.encode('utf-8')) + sig = h.finalize() + + headers = {'x-username' : myusername, + 'x-signature': tobase64_b(sig)} + res = requests.post(url="http://127.0.0.1:5000/api/", headers=headers, data=data) + print(res.text) +