Пример #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)
Пример #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]
Пример #3
0
 def __init__(self, host, port):
     self.host = host
     self.port = port
     self.peers = {}
     self.nodeid = cryptotools.generate_nodeid()[:10]
Пример #4
0
 def startFactory(self):
     self.peers = {}
     self.peers_protocol = {}
     self.numProtocols = 0
     self.nodeid = cryptotools.generate_nodeid()[:10]
     print(" [ ] NODEID:", self.nodeid)
Пример #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):
Пример #6
0
 def setUp(self):
     self.nodeid = cryptotools.generate_nodeid()
Пример #7
0
 def __init__(self):
     self.peers = {}
     self.nodeid = cryptotools.generate_nodeid()[:10]
Пример #8
0
 def __init__(self):
     self.peers = {}
     self.numProtocols = 0
     self.nodeid = cryptotools.generate_nodeid()[:10]
     self.status = None
     self.dialog = "n/a"
Пример #9
0
 def setUp(self):
     self.nodeid = cryptotools.generate_nodeid()