Ejemplo n.º 1
0
 def startFactory(self):
     self.peers = {}
     self.clients = []
     self.knownBlocks = {}
     self.knownTxs = {}
     self.numProtocols = 0
     self.nodeid = cryptotools.generate_nodeid()[:10]
     _print(" [P2P] NODEID:", self.nodeid)
Ejemplo n.º 2
0
import hmac
import json
import cryptotools

# generate_nodeid() uses SHA256 so this will prevent replay-attacks,
# because every message will have a different nonce.
# It's not nessecary to compare the nonce, HMAC already gives message
# integrety.
nonce = lambda: cryptotools.generate_nodeid()
incr_nonce = lambda env: format(int(env["nonce"], 16) + 1, 'x')


class InvalidSignatureError(Exception):
    pass


class InvalidNonceError(Exception):
    pass


def make_envelope(msgtype, msg, nodeid):
    msg['nodeid'] = nodeid
    msg['nonce'] = nonce()
    data = json.dumps(msg)
    sign = hmac.new(nodeid, data)
    envelope = {'data': msg, 'sign': sign.hexdigest(), 'msgtype': msgtype}
    return json.dumps(envelope)


def envelope_decorator(nodeid, func):
    msgtype = func.__name__.split("_")[0]
Ejemplo n.º 3
0
 def __init__(self, host, port):
     self.host = host
     self.port = port
     self.peers = {}
     self.nodeid = cryptotools.generate_nodeid()[:10]
Ejemplo n.º 4
0
 def startFactory(self):
     self.peers = {}
     self.peers_protocol = {}
     self.numProtocols = 0
     self.nodeid = cryptotools.generate_nodeid()[:10]
     print(" [ ] NODEID:", self.nodeid)
Ejemplo n.º 5
0
import hmac
import json
import cryptotools

# generate_nodeid() uses SHA256 so this will prevent replay-attacks,
# because every message will have a different nonce.
# It's not nessecary to compare the nonce, HMAC already gives message
# integrety.
nonce = lambda: cryptotools.generate_nodeid()
incr_nonce = lambda env: format(int(env["nonce"], 16) + 1, "x")


class InvalidSignatureError(Exception):
    pass


class InvalidNonceError(Exception):
    pass


def make_envelope(msgtype, msg, nodeid):
    msg["nodeid"] = nodeid
    msg["nonce"] = nonce()
    data = json.dumps(msg)
    sign = hmac.new(nodeid, data)
    envelope = {"data": msg, "sign": sign.hexdigest(), "msgtype": msgtype}
    # print "make_envelope:", envelope
    return json.dumps(envelope)


def envelope_decorator(nodeid, func):
Ejemplo n.º 6
0
 def setUp(self):
     self.nodeid = cryptotools.generate_nodeid()
Ejemplo n.º 7
0
 def __init__(self):
     self.peers = {}
     self.nodeid = cryptotools.generate_nodeid()[:10]
Ejemplo n.º 8
0
 def __init__(self):
     self.peers = {}
     self.numProtocols = 0
     self.nodeid = cryptotools.generate_nodeid()[:10]
     self.status = None
     self.dialog = "n/a"
Ejemplo n.º 9
0
 def setUp(self):
     self.nodeid = cryptotools.generate_nodeid()