#!/usr/bin/env python
import requests
import json
import os,binascii
def sending(message):
url = 'http://127.0.0.1:6613/'
response = requests.post(url, data=message)
print response.content
return response.content
def dh(data_js):
req=json.loads(data_js)
print "Send gen parameters (A): \n " + json.dumps(req) +"\n"
data_js_n=sending(json.dumps(req))
answ=json.loads(data_js_n)
print "Recived gen parameters donde (A): \n" + (json.dumps(answ)) +"\n\n\n"
data_js_n=sending(json.dumps(req))
print "Send gen parameters (B): \n " + json.dumps(req) +"\n"
answ_1=json.loads(data_js_n)
print "Recived gen parameters donde (B): \n" + (json.dumps(answ_1)) +"\n\n\n"
gen='{ "version":1 , "algorithm":"DH","family": "", "privkey":"","sharedpub":"", "operation":"a_rfc"}'
req=json.loads(gen)
req["family"]=answ["family"]
req["privkey"]=answ["privkey"]
req["sharedpub"]=answ_1["pubkey"]
print "Send agreetment (A): \n " + json.dumps(req) +"\n"
data_js_n=sending(json.dumps(req))
answ_2=json.loads(data_js_n)
print "Recived agreetment donde (A): \n" + (json.dumps(answ_2)) +"\n\n\n"
req["privkey"]=answ_1["privkey"]
req["sharedpub"]=answ["pubkey"]
print "Send agreetment (B): \n " + json.dumps(req) +"\n"
data_js_n=sending(json.dumps(req))
answ_3=json.loads(data_js_n)
print "Recived agreetment donde (B): \n" + (json.dumps(answ_3)) +"\n\n\n"
dh_gen='{ "version": 1 , "algorithm":"DH", "family": "modp256", "operation":"gen_rfc"}'
dh(dh_gen)
In this example we generate keys for A and B, and we make a key exchange between A and B.
{ "version": 1 , "algorithm":"DH", "family": "mod flavor", "operation":"gen_rfc"}
{ "version":1 , "algorithm":"DH","family": "mod flavor", "privkey":" your hex privkey",
"sharedpub":"your partnert hex pubkey", "operation":"a_rfc"}