@@ -189,15 +189,19 @@ def verify_callback(self, connection, x509, errnum, errdepth, ok):
189189
190190 @staticmethod
191191 def info_callback (connection , where , ret ):
192- if where & SSL .SSL_CB_HANDSHAKE_DONE :
193- tls_protocol = connection .get_app_data ()
194- app_data = getattr (tls_protocol , _TLS_APP_DATA_ATTR , None )
195- if app_data and app_data .check_hostname :
196- try :
197- _validate_pyopenssl_hostname (connection .get_peer_certificate (), app_data .expected_name )
198- except ssl .CertificateError as exc :
199- tls_protocol .failVerification (
200- Failure (ConnectionException (str (exc ), app_data .endpoint )))
192+ if not where & SSL .SSL_CB_HANDSHAKE_DONE :
193+ return
194+ tls_protocol = connection .get_app_data ()
195+ app_data = getattr (tls_protocol , _TLS_APP_DATA_ATTR , None )
196+ if not (app_data and app_data .check_hostname ):
197+ return
198+ try :
199+ _validate_pyopenssl_hostname (
200+ connection .get_peer_certificate (), app_data .expected_name )
201+ except Exception as exc :
202+ tls_protocol .failVerification (
203+ Failure (ConnectionException (
204+ "Hostname verification failed: %s" % (exc ,), app_data .endpoint )))
201205
202206 def clientConnectionForTLS (self , tlsProtocol ):
203207 connection = SSL .Connection (self .context , None )
0 commit comments