def verify_data(self, data):
     sent_hash = utils.hex_decode(data[-40:])
     message = data[:-41]
     h = hmac.new(self.session_key, message, hashlib.sha1)
     if sent_hash != h.digest():
         return False
     return message
 def lineReceived(self, data):
     print "Client: got data %s" % data
     if data[0:6] == "HELLO\t":
         self.session_key = utils.hex_decode(data.split("\t")[1])
     message = self.verify_data(data)
     #print "Client: Got message %s\n" % message
     #print "Client: self.session_key=%s" % utils.hex_encode(self.session_key)
     if message == False:
         self.factory.deferred.callback("ERROR Hash mismatch")
         return
     
     self.factory.deferred.callback(message)
Пример #3
0
    def lineReceived(self, data):
        print "Client: got data %s" % data
        # Check for HELLO first as it defines our session key....
        if data[0:6] == "HELLO\t":
            self.session_key = utils.hex_decode(data.split("\t")[1])
            self.hmac_wrapper = utils.hmac_wrapper(self.session_key + self.config.get('auth', 'shared_secret'))
        message = self.verify_data(data)
        #print "Client: Got message %s\n" % message
        #print "Client: self.session_key=%s" % utils.hex_encode(self.session_key)
        if message == False:
            print "ERROR Hash mismatch"
            return

        self.parse_message(message)
Пример #4
0
from hashlib import md5
from os import urandom

from Curve import Curve
from utils import public_key, private_key, hex_decode, bytes_to_long, mod_invert, long_to_bytes

MODE_SIZE = 32

CURVE = (
    hex_decode(
        "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD97"),
    hex_decode(
        "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6C611070995AD10045841B09B761B893"),
    hex_decode(
        "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD94"),
    hex_decode(
        "00000000000000000000000000000000000000000000000000000000000000a6"),
    hex_decode(
        "0000000000000000000000000000000000000000000000000000000000000001"),
    hex_decode(
        "8D91E471E0989CDA27DF505A453F2B7635294F2DDF23E3B122ACC99C9E9F1E14"),
)


def sign(curve, private_key, digest):
    q = curve.q
    e = bytes_to_long(digest) % q
    if e == 0:
        e = 1
    while True:
        k = bytes_to_long(urandom(MODE_SIZE)) % q