Browse Source

Added ECDSAKey and Ed25519Key for authentication

pull/4/head
Sheng 7 years ago
parent
commit
c9913a4108
  1. 32
      main.py

32
main.py

@ -118,20 +118,36 @@ class Worker(object):
class IndexHandler(tornado.web.RequestHandler): class IndexHandler(tornado.web.RequestHandler):
def get_privatekey(self): def get_privatekey(self):
try: try:
return self.request.files.get('privatekey')[0]['body'] data = self.request.files.get('privatekey')[0]['body']
except TypeError: except TypeError:
return
return data.decode('utf-8')
def get_specific_pkey(self, pkeycls, privatekey, password):
logging.info('Trying {}'.format(pkeycls.__name__))
try:
pkey = pkeycls.from_private_key(io.StringIO(privatekey),
password=password)
except paramiko.PasswordRequiredException:
raise ValueError('Need password to decrypt the private key.')
except paramiko.SSHException:
pass pass
else:
return pkey
def get_pkey(self, privatekey, password): def get_pkey(self, privatekey, password):
if not password: password = password.encode('utf-8') if password else None
password = None
spkey = io.StringIO(privatekey.decode('utf-8')) pkey = self.get_specific_pkey(paramiko.RSAKey, privatekey, password)\
or self.get_specific_pkey(paramiko.DSSKey, privatekey, password)\
or self.get_specific_pkey(paramiko.ECDSAKey, privatekey, password)\
or self.get_specific_pkey(paramiko.Ed25519Key, privatekey,
password)
if not pkey:
raise ValueError('Wrong password for decrypting the private key'
' or the private key is not valid.')
try:
pkey = paramiko.RSAKey.from_private_key(spkey, password=password)
except paramiko.SSHException:
pkey = paramiko.DSSKey.from_private_key(spkey, password=password)
return pkey return pkey
def get_port(self): def get_port(self):

Loading…
Cancel
Save