mirror of https://github.com/huashengdun/webssh
Merge pull request #305 from klarose/more-secure-worker-id
use secrets to generate worker idpull/296/merge
commit
7b18eac7a6
|
@ -1,4 +1,5 @@
|
|||
import logging
|
||||
import secrets
|
||||
import tornado.websocket
|
||||
|
||||
from tornado.ioloop import IOLoop
|
||||
|
@ -36,7 +37,7 @@ class Worker(object):
|
|||
self.chan = chan
|
||||
self.dst_addr = dst_addr
|
||||
self.fd = chan.fileno()
|
||||
self.id = str(id(self))
|
||||
self.id = self.gen_id()
|
||||
self.data_to_dst = []
|
||||
self.handler = None
|
||||
self.mode = IOLoop.READ
|
||||
|
@ -50,6 +51,10 @@ class Worker(object):
|
|||
if events & IOLoop.ERROR:
|
||||
self.close(reason='error event occurred')
|
||||
|
||||
@classmethod
|
||||
def gen_id(cls):
|
||||
return secrets.token_urlsafe(nbytes=32)
|
||||
|
||||
def set_handler(self, handler):
|
||||
if not self.handler:
|
||||
self.handler = handler
|
||||
|
|
Loading…
Reference in New Issue