From 26af5ad760e455c32e651364a883962b7f041d97 Mon Sep 17 00:00:00 2001 From: Oleksii Shevchuk Date: Fri, 2 Dec 2016 17:51:02 +0200 Subject: [PATCH] Delete-then-raise for tmp certs --- pupy/network/lib/clients.py | 8 ++++++++ pupy/network/transports/ssl/conf.py | 7 +++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pupy/network/lib/clients.py b/pupy/network/lib/clients.py index 0fb5fcf1..2cbeb17e 100644 --- a/pupy/network/lib/clients.py +++ b/pupy/network/lib/clients.py @@ -121,6 +121,8 @@ class PupySSLClient(PupyTCPClient): os.write(fd_ca_path, self.SSL_CA_CERT) os.close(fd_ca_path) + exception = None + try: wrapped_socket = ssl.wrap_socket( socket, @@ -132,11 +134,17 @@ class PupySSLClient(PupyTCPClient): ssl_version=self.ssl_version, ciphers=self.ciphers ) + except Exception as e: + exception = e + finally: os.unlink(tmp_cert_path) os.unlink(tmp_key_path) os.unlink(tmp_ca_path) + if exception: + raise e + peer = wrapped_socket.getpeercert() peer_role = '' diff --git a/pupy/network/transports/ssl/conf.py b/pupy/network/transports/ssl/conf.py index f1a14186..3bed3fc7 100644 --- a/pupy/network/transports/ssl/conf.py +++ b/pupy/network/transports/ssl/conf.py @@ -40,6 +40,8 @@ class PupySSLAuthenticator(object): os.write(fd_ca_path, self.castr) os.close(fd_ca_path) + exception = None + try: wrapped_socket = ssl.wrap_socket( sock, @@ -52,14 +54,15 @@ class PupySSLAuthenticator(object): ciphers=self.ciphers ) except ssl.SSLError: - ex = sys.exc_info()[1] - raise AuthenticationError(str(ex)) + exception = sys.exc_info()[1] finally: os.unlink(tmp_cert_path) os.unlink(tmp_key_path) os.unlink(tmp_ca_path) + if exception: + raise AuthenticationError(str(exception)) peer = wrapped_socket.getpeercert() peer_role = ''