exscript
exscript copied to clipboard
Rewrite auth mechanism proposal
- Try auth_password first (it should be the most common for network equipments and some of them don't like auth_none as first method, requiring reconnection
- Use correct display names
- Remove redundant code (error handling)
- Allow some partial auth support (might not work)
- Banner is retrieved and tested at each auth attempt, because some equipments send it only once even is the method failed
- Some Python3 compatibility "hack" (get_banner), there's a lot to change to be fully Python3 compatible I think (
unicode_literals
from__future__
everywhere, as str in Py2 is basically bytes)
Coverage decreased (-0.07%) to 76.718% when pulling ef2ae013b182b4b74a1aefca4ef449fff2abec04 on Alex131089:rewrite-auth-mechanism into 5c7c6251a5b0c5140c738418b6bca34ed35e942d on knipknap:master.
As a workaround I landed up extending the SSH protocol class.
` class SSH2(PSSH2):
def _paramiko_auth(self, username, password):
"""Override Exscript's default behaviour since we only use
one auth type (password).
"""
method = self._paramiko_auth_password
self._dbg(1, 'Authenticating with %s' % method.__name__)
try:
method(username, password)
return
except BadHostKeyException as e:
msg = '%s: Bad host key: %s' % (method.__name__, str(e))
self._dbg(1, msg)
except AuthenticationException as e:
msg = 'Authentication with %s failed' % method.__name__
msg += ': ' + str(e)
self._dbg(1, msg)
except SSHException as e:
msg = '%s: SSHException: %s' % (method.__name__, str(e))
self._dbg(1, msg)
raise LoginFailure('Login failed: ' + msg)
`