Define an additional object validation method is_junk(),
checking curve number and key length in encrypted payload.
This commit is contained in:
parent
644a09ba0b
commit
46ea5e0744
|
@ -16,6 +16,8 @@ ip_enabled = True
|
||||||
|
|
||||||
log_level = logging.INFO
|
log_level = logging.INFO
|
||||||
|
|
||||||
|
curve = 714 # secp256k1
|
||||||
|
key_length = 32
|
||||||
magic_bytes = b'\xe9\xbe\xb4\xd9'
|
magic_bytes = b'\xe9\xbe\xb4\xd9'
|
||||||
protocol_version = 3
|
protocol_version = 3
|
||||||
services = 3 # NODE_NETWORK, NODE_SSL
|
services = 3 # NODE_NETWORK, NODE_SSL
|
||||||
|
|
|
@ -132,6 +132,31 @@ class Object():
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def is_junk(self):
|
||||||
|
"""
|
||||||
|
Returns True if an object with encrypted payload has
|
||||||
|
curve number or key length different from those defined in shared.
|
||||||
|
"""
|
||||||
|
if self.object_type not in (1, 2, 3):
|
||||||
|
return False
|
||||||
|
if self.object_type == 2:
|
||||||
|
sp = 0
|
||||||
|
elif self.object_type == 1 and self.version != 4:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
sp = 32
|
||||||
|
sp += 16
|
||||||
|
curve = struct.unpack('!H', self.object_payload[sp:sp + 2])[0]
|
||||||
|
if curve != shared.curve:
|
||||||
|
return True
|
||||||
|
length = struct.unpack('!H', self.object_payload[sp + 2:sp + 4])[0]
|
||||||
|
if length > shared.key_length:
|
||||||
|
return True
|
||||||
|
length = struct.unpack('!H', self.object_payload[sp + 36:sp + 38])[0]
|
||||||
|
if length > shared.key_length:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def pow_target(self):
|
def pow_target(self):
|
||||||
"""Compute PoW target"""
|
"""Compute PoW target"""
|
||||||
data = self.to_bytes()[8:]
|
data = self.to_bytes()[8:]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user