bugfix
This commit is contained in:
parent
a451a976e1
commit
45f3603592
@ -81,7 +81,7 @@ class AcrossNat(object):
|
|||||||
def is_port_mapped(self, external_port, protocol='TCP'):
|
def is_port_mapped(self, external_port, protocol='TCP'):
|
||||||
protocol = protocol.upper()
|
protocol = protocol.upper()
|
||||||
if self.upnp_supported:
|
if self.upnp_supported:
|
||||||
return self.upnp_map_port_check(external_port,
|
return self.upnp_check_external_port(external_port,
|
||||||
protocol=protocol)
|
protocol=protocol)
|
||||||
raise Exception('not implemented')
|
raise Exception('not implemented')
|
||||||
|
|
||||||
|
@ -62,11 +62,12 @@ class RC4:
|
|||||||
return r.decode(self.dcoding)
|
return r.decode(self.dcoding)
|
||||||
|
|
||||||
class KeyChain(object):
|
class KeyChain(object):
|
||||||
def __init__(self, seed_str, crypter=None, keylen=23, period=600, threshold=60):
|
def __init__(self, seed_str, crypter=None, keylen=23, period=600, threshold=60, time_delta=0):
|
||||||
self.seed_str = seed_str
|
self.seed_str = seed_str
|
||||||
self.period = int(period)
|
self.period = int(period)
|
||||||
self.threshold = int(threshold)
|
self.threshold = int(threshold)
|
||||||
self.crypter = crypter
|
self.crypter = crypter
|
||||||
|
self.time_delta = time_delta
|
||||||
if crypter is None:
|
if crypter is None:
|
||||||
self.crypter = RC4()
|
self.crypter = RC4()
|
||||||
self.keylen = keylen
|
self.keylen = keylen
|
||||||
@ -75,8 +76,12 @@ class KeyChain(object):
|
|||||||
delta = datetime.timedelta(0)
|
delta = datetime.timedelta(0)
|
||||||
self.timezone = datetime.timezone(delta, name='gmt')
|
self.timezone = datetime.timezone(delta, name='gmt')
|
||||||
|
|
||||||
|
def get_timestamp(self):
|
||||||
|
ts = int(time.time()) - self.time_delta
|
||||||
|
return ts
|
||||||
|
|
||||||
def is_near_bottom(self, indicator=None):
|
def is_near_bottom(self, indicator=None):
|
||||||
ts = time.time()
|
ts = self.get_timestamp()
|
||||||
i = indicator
|
i = indicator
|
||||||
if i is None:
|
if i is None:
|
||||||
i = self.get_indicator(ts)
|
i = self.get_indicator(ts)
|
||||||
@ -85,7 +90,7 @@ class KeyChain(object):
|
|||||||
return FalseTrue
|
return FalseTrue
|
||||||
|
|
||||||
def is_near_top(self, indicator=None):
|
def is_near_top(self, indicator=None):
|
||||||
ts = time.time()
|
ts = self.get_timestamp()
|
||||||
i = indicator
|
i = indicator
|
||||||
if i is None:
|
if i is None:
|
||||||
i = self.get_indicator(ts)
|
i = self.get_indicator(ts)
|
||||||
@ -95,7 +100,7 @@ class KeyChain(object):
|
|||||||
|
|
||||||
def get_indicator(self, ts=None):
|
def get_indicator(self, ts=None):
|
||||||
if ts is None:
|
if ts is None:
|
||||||
ts = time.time()
|
ts = self.get_timestamp()
|
||||||
return int(ts / self.period) * self.period
|
return int(ts / self.period) * self.period
|
||||||
|
|
||||||
def genKey(self, indicator):
|
def genKey(self, indicator):
|
||||||
|
@ -66,10 +66,10 @@ class RSA:
|
|||||||
text = f.read()
|
text = f.read()
|
||||||
return self.publickeyFromText(text)
|
return self.publickeyFromText(text)
|
||||||
|
|
||||||
def create_privatekey(self):
|
def create_privatekey(self, keylength=2048):
|
||||||
return rsa.generate_private_key(
|
return rsa.generate_private_key(
|
||||||
public_exponent=65537,
|
public_exponent=65537,
|
||||||
key_size=2048,
|
key_size=keylength,
|
||||||
backend=default_backend()
|
backend=default_backend()
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -154,19 +154,23 @@ if __name__ == '__main__':
|
|||||||
import os
|
import os
|
||||||
prikey1_file = os.path.join(os.path.dirname(__file__),'..','test', 'prikey1.rsa')
|
prikey1_file = os.path.join(os.path.dirname(__file__),'..','test', 'prikey1.rsa')
|
||||||
r = RSA()
|
r = RSA()
|
||||||
mpri = r.create_privatekey()
|
mpri = r.create_privatekey(4096)
|
||||||
mpub = r.create_publickey(mpri)
|
mpub = r.create_publickey(mpri)
|
||||||
|
|
||||||
zpri = r.create_privatekey()
|
zpri = r.create_privatekey(4096)
|
||||||
zpub = r.create_publickey(zpri)
|
zpub = r.create_publickey(zpri)
|
||||||
|
|
||||||
text = 'this is a test data, aaa'
|
l = 100
|
||||||
|
while True:
|
||||||
|
text = 'h' * l
|
||||||
cipher = r.encode(mpub,text)
|
cipher = r.encode(mpub,text)
|
||||||
ntext = r.decode(mpri,cipher)
|
ntext = r.decode(mpri,cipher)
|
||||||
print('encode text=', text, \
|
print('textlen=', l, 'encode text=', text, \
|
||||||
'decode result=', ntext,
|
'decode result=', ntext,
|
||||||
'cyber size=', len(cipher),
|
'cyber size=', len(cipher),
|
||||||
'check if equal=', text==ntext)
|
'check if equal=', text==ntext)
|
||||||
signature = r.sign(zpri,text)
|
signature = r.sign(zpri,text)
|
||||||
check = r.check_sign(zpub,text,signature)
|
check = r.check_sign(zpub,text,signature)
|
||||||
print('sign and verify=',len(signature),check)
|
print('sign and verify=',len(signature),check)
|
||||||
|
l += 1
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user