diff options
author | David Whiteside <starboarder2001@gmail.com> | 2017-09-10 10:21:15 -0600 |
---|---|---|
committer | David Whiteside <starboarder2001@gmail.com> | 2017-09-10 16:13:15 -0600 |
commit | 52f2d8a7da2913339cb057426839d5959f6d50df (patch) | |
tree | b5a75cc0f78a44261ea4ebc995f3c0acb496bcc3 | |
parent | 8b168e9b92c0c650ecd3c0f7c0cb734c951808b0 (diff) | |
download | paramiko-52f2d8a7da2913339cb057426839d5959f6d50df.tar.gz |
pep8 cleanup
-rw-r--r-- | paramiko/auth_handler.py | 4 | ||||
-rw-r--r-- | paramiko/client.py | 9 | ||||
-rw-r--r-- | paramiko/pkcs11.py | 36 | ||||
-rw-r--r-- | paramiko/transport.py | 2 |
4 files changed, 27 insertions, 24 deletions
diff --git a/paramiko/auth_handler.py b/paramiko/auth_handler.py index 677b9310..919add77 100644 --- a/paramiko/auth_handler.py +++ b/paramiko/auth_handler.py @@ -57,8 +57,7 @@ from paramiko.rsakey import RSAKey from paramiko.ecdsakey import ECDSAKey from paramiko.ed25519key import Ed25519Key from paramiko.hostkeys import InvalidHostKey -from paramiko import pkcs11_open_session, pkcs11_close_session -from paramiko.pkcs11 import pkcs11_get_public_key +from paramiko.pkcs11 import PKCS11Exception class AuthHandler (object): @@ -292,7 +291,6 @@ class AuthHandler (object): % self.pkcs11session["provider"]) lib = cdll.LoadLibrary(self.pkcs11session["provider"]) session = self.pkcs11session["session"] - public_key = self._pkcs11_get_public_key() keyret = self.pkcs11session["keyret"] # Init Signing Data diff --git a/paramiko/client.py b/paramiko/client.py index 3f457b25..f4e6791f 100644 --- a/paramiko/client.py +++ b/paramiko/client.py @@ -294,10 +294,11 @@ class SSHClient (ClosingContextManager): The targets name in the kerberos database. default: hostname :param float banner_timeout: an optional timeout (in seconds) to wait for the SSH banner to be presented. - :param str pkcs11session: The pkcs11 session obtained by calling pkcs11_open_session. - If using PKCS11 in a multithreaded application you can share the session between threads. - You can make multiple calls to connect using the same pkcs11 session. - You must call pkcs11_close_session to cleanly close the session. + :param str pkcs11session: The pkcs11 session obtained by calling + pkcs11_open_session. If using PKCS11 in a multithreaded application + you can share the session between threads. You can make multiple + calls to connect using the same pkcs11 session. You must call + pkcs11_close_session to cleanly close the session. :param float auth_timeout: an optional timeout (in seconds) to wait for an authentication response. diff --git a/paramiko/pkcs11.py b/paramiko/pkcs11.py index 0f854336..40556163 100644 --- a/paramiko/pkcs11.py +++ b/paramiko/pkcs11.py @@ -3,12 +3,12 @@ from ctypes import (c_void_p, c_ulong, c_int, c_char_p, cast, addressof, import subprocess import os import errno -from paramiko.ssh_exception import AuthenticationException +from paramiko.ssh_exception import AuthenticationException, SSHException -class PKCS11Exception (Exception): +class PKCS11Exception (SSHException): """ - Exception raised by failures in PKCS11 protocol negotiation or logic errors. + Exception raised by failures in the PKCS11 api or logic errors. """ pass @@ -22,7 +22,7 @@ class PKCS11AuthenticationException (AuthenticationException): def pkcs11_get_public_key(keyid="01"): """ - :param str pkcs11keyid: The keyid to use for the pkcs11 session, the default is "01". + :param str pkcs11keyid: The keyid to use for the pkcs11 session. """ public_key = None try: @@ -45,17 +45,18 @@ def pkcs11_get_public_key(keyid="01"): return str(public_key) -def pkcs11_open_session(pkcs11provider, pkcs11pin, pkcs11keyid="01", pkcs11slot=0, pkcs11publickey=None): +def pkcs11_open_session(pkcs11provider, pkcs11pin, pkcs11keyid="01", + pkcs11slot=0, pkcs11publickey=None): """ :param str pkcs11provider: If using PKCS11, this will be the provider for the PKCS11 interface. Example: /usr/local/lib/opensc-pkcs11.so. :param str pkcs11pin: If using PKCS11, this will be the pin of your token or smartcard. - :param str pkcs11keyid: The keyid to use for the pkcs11 session, the default is "01". - :param int pkcs11slot: The slot id used for establishing the pkcs11 session. - :param str pkcs11publickey: If left the default (None), the public key will be - detected using OpenSC pkcs15-tool. Alternatively you can provide it manually - using this argument. + :param str pkcs11keyid: The keyid to use for the pkcs11 session. + :param int pkcs11slot: The slot id used for establishing the session. + :param str pkcs11publickey: If left the default (None), the public key + will be detected using OpenSC pkcs15-tool. Alternatively you can + provide it manually using this argument. """ public_key = "" session = None @@ -81,7 +82,7 @@ def pkcs11_open_session(pkcs11provider, pkcs11pin, pkcs11keyid="01", pkcs11slot= # Init if not os.path.isfile(pkcs11provider): raise PKCS11Exception("pkcs11provider path is not valid: %s" - % pkcs11provider) + % pkcs11provider) lib = cdll.LoadLibrary(pkcs11provider) res = lib.C_Initialize(byref(init_args)) if res != 0: @@ -136,19 +137,22 @@ def pkcs11_open_session(pkcs11provider, pkcs11pin, pkcs11keyid="01", pkcs11slot= if res != 0: raise PKCS11Exception("PKCS11 Failed to Find Objects Final") - return {"session": session, "public_key": public_key, "keyret": keyret, "provider": pkcs11provider} + return {"session": session, "public_key": public_key, + "keyret": keyret, "provider": pkcs11provider} def pkcs11_close_session(pkcs11session): """ - :param str pkcs11session: pkcs11 session obtained from calling pkcs11_open_session + :param str pkcs11session: pkcs11 session obtained + by calling pkcs11_open_session """ if "provider" not in pkcs11session: - raise PKCS11Exception("pkcs11 session is missing the provider, the session is not valid") - pkcs11provider=pkcs11session["provider"] + raise PKCS11Exception("pkcs11 session is missing the provider,\ + the session is not valid") + pkcs11provider = pkcs11session["provider"] if not os.path.isfile(pkcs11provider): raise PKCS11Exception("pkcs11provider path is not valid: %s" - % pkcs11provider) + % pkcs11provider) lib = cdll.LoadLibrary(pkcs11provider) # Wrap things up res = lib.C_Finalize(c_int(0)) diff --git a/paramiko/transport.py b/paramiko/transport.py index 54815ab4..db64b57b 100644 --- a/paramiko/transport.py +++ b/paramiko/transport.py @@ -1406,7 +1406,7 @@ class Transport(threading.Thread, ClosingContextManager): def auth_pkcs11(self, username, pkcs11session, event=None): """ :param str username: the username to authenticate as - :param str pkcs11session: pkcs11 session obtained from pkcs11_open_session + :param str pkcs11session: session obtained from pkcs11_open_session :param .threading.Event event: an event to trigger when the authentication attempt is complete (whether it was successful or not) |