remove useless log
add openssl rand_bytes
This commit is contained in:
parent
3c64e849b0
commit
ce189ecd85
4 changed files with 20 additions and 18 deletions
|
@ -51,6 +51,10 @@ def load_openssl():
|
|||
|
||||
libcrypto.EVP_CIPHER_CTX_cleanup.argtypes = (c_void_p,)
|
||||
libcrypto.EVP_CIPHER_CTX_free.argtypes = (c_void_p,)
|
||||
|
||||
libcrypto.RAND_bytes.restype = c_int
|
||||
libcrypto.RAND_bytes.argtypes = (c_void_p, c_int)
|
||||
|
||||
if hasattr(libcrypto, 'OpenSSL_add_all_ciphers'):
|
||||
libcrypto.OpenSSL_add_all_ciphers()
|
||||
|
||||
|
@ -68,6 +72,14 @@ def load_cipher(cipher_name):
|
|||
return cipher()
|
||||
return None
|
||||
|
||||
def rand_bytes(length):
|
||||
if not loaded:
|
||||
load_openssl()
|
||||
buf = create_string_buffer(length)
|
||||
r = libcrypto.RAND_bytes(buf, length)
|
||||
if r <= 0:
|
||||
raise Exception('RAND_bytes return error')
|
||||
return buf.raw
|
||||
|
||||
class OpenSSLCrypto(object):
|
||||
def __init__(self, cipher_name, key, iv, op):
|
||||
|
|
|
@ -34,8 +34,10 @@ method_supported.update(table.ciphers)
|
|||
|
||||
|
||||
def random_string(length):
|
||||
return os.urandom(length)
|
||||
|
||||
try:
|
||||
return os.urandom(length)
|
||||
except NotImplementedError as e:
|
||||
return openssl.rand_bytes(length)
|
||||
|
||||
cached_keys = {}
|
||||
|
||||
|
|
|
@ -216,11 +216,6 @@ class EventLoop(object):
|
|||
handler.handle_event(sock, fd, event)
|
||||
except (OSError, IOError) as e:
|
||||
shell.print_exception(e)
|
||||
try:
|
||||
addr = sock.getpeername()[:2]
|
||||
logging.error('exception peer name %s:%d' % (addr[0], addr[1]))
|
||||
except:
|
||||
logging.error('no peer name')
|
||||
now = time.time()
|
||||
if asap or now - self._last_time >= TIMEOUT_PRECISION:
|
||||
for callback in self._periodic_callbacks:
|
||||
|
|
|
@ -769,23 +769,16 @@ class TCPRelayHandler(object):
|
|||
if self._local_sock:
|
||||
logging.error(eventloop.get_sock_error(self._local_sock))
|
||||
logging.error("exception from %s:%d" % (self._client_address[0], self._client_address[1]))
|
||||
try:
|
||||
addr = self._local_sock.getpeername()
|
||||
logging.error('local exception peer name %s:%d' % (addr[0], addr[1]))
|
||||
except:
|
||||
logging.error('no peer name')
|
||||
self.destroy()
|
||||
|
||||
def _on_remote_error(self):
|
||||
logging.debug('got remote error')
|
||||
if self._remote_sock:
|
||||
logging.error(eventloop.get_sock_error(self._remote_sock))
|
||||
logging.error("exception from %s:%d" % (self._client_address[0], self._client_address[1]))
|
||||
try:
|
||||
addr = self._remote_sock.getpeername()
|
||||
logging.error('remote exception peer name %s:%d' % (addr[0], addr[1]))
|
||||
except:
|
||||
logging.error('no peer name')
|
||||
if self._remote_address:
|
||||
logging.error("when connect to %s:%d from %s:%d" % (self._remote_address[0], self._remote_address[1], self._client_address[0], self._client_address[1]))
|
||||
else:
|
||||
logging.error("exception from %s:%d" % (self._client_address[0], self._client_address[1]))
|
||||
self.destroy()
|
||||
|
||||
def handle_event(self, sock, event):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue