示例#1
0
import sm_py

if __name__ == '__main__':
    aliceKeys = sm_py.key_init()["keys"]
    bobKeys = sm_py.key_init()["keys"]
    secret = "test"
    step1 = sm_py.step_1(secret, aliceKeys)
    aliceKeys = step1["keys"]
    print(step1["message"])
    step2 = sm_py.step_2(step1["message"], bobKeys)
    bobKeys = step2["keys"]
    step3 = sm_py.step_3("test", bobKeys)
    bobKeys = step3["keys"]
    print(step3["message"])
    step4 = sm_py.step_4(step3["message"], aliceKeys)
    aliceKeys = step4["keys"]
    print(step4["message"])
    step5 = sm_py.step_5(step4["message"], bobKeys)
    bobKeys = step5["keys"]
    print(step5["success"])
    print(step5["message"])
    step6 = sm_py.step_6(step5["message"], aliceKeys)
    print(step6["success"])
示例#2
0
 step = message["typeSMP"]
 payload = message["payload"]
 if step == 1:
     url = "https://lab3key.herokuapp.com/public_keys/details"
     headers = {"content-type": "application/json"}
     params = {"email": OTHER_NICK}
     response = requests.get(url, params=params, headers=headers)
     binary = response.content
     obj = json.loads(binary)
     secret = raw_input("Enter the secret message for " + OTHER_NICK + ": ")
     otherIdentity = obj["identity"].strip()
     myIdentity = binascii.b2a_base64(a.state["DHIs"]).strip("\n")
     secret = secret + myIdentity + otherIdentity
     secret = hashlib.sha224(secret).hexdigest().upper()
     smKeys = sm_py.key_init()["keys"]
     step1 = sm_py.step_1(secret, smKeys)
     smKeys = step1["keys"]
     smUrl = "https://lab3key.herokuapp.com/messages"
     smPayload = {
         "message": {
             "source": NICK,
             "destination": OTHER_NICK,
             "isSMP": True,
             "typeSMP": 2,
             "payload": step1["message"],
         }
     }
     smParams = json.dumps(smPayload)
     smReq = urllib2.Request(
         smUrl, data=smParams, headers={"content-type": "application/json"}
     )