@@ -191,20 +191,26 @@ public void failed(final Throwable throwable) {
191191 }
192192
193193 public void completed (final Connection connection ) {
194- final SSLSession session = SSLUtils .getSSLEngine (connection ).getSession ();
195- if (LOGGER .isDebugEnabled ()) {
196- LOGGER .debug ("SSL Handshake onComplete: session = {}, id = {}, isValid = {}, host = {}" ,
197- session .toString (), Base64 .encode (session .getId ()), session .isValid (), host );
198- }
194+ if (getHandshakeError (connection ) == null ) {
195+ final SSLSession session = SSLUtils .getSSLEngine (connection ).getSession ();
196+ if (LOGGER .isDebugEnabled ()) {
197+ LOGGER .debug ("SSL Handshake onComplete: session = {}, id = {}, isValid = {}, host = {}" ,
198+ session .toString (), Base64 .encode (session .getId ()), session .isValid (), host );
199+ }
200+
201+ if (!verifier .verify (host , session )) {
202+ connection .terminateSilently ();
199203
200- if (! verifier . verify ( host , session ) ) {
201- connection . terminateSilently ( );
202-
203- if ( delegateCompletionHandler != null ) {
204- IOException e = new ConnectException ( "Host name verification failed for host " + host );
205- delegateCompletionHandler . failed ( e ) ;
204+ if (delegateCompletionHandler != null ) {
205+ IOException e = new ConnectException ( "Host name verification failed for host " + host );
206+ delegateCompletionHandler . failed ( e );
207+ }
208+
209+ return ;
206210 }
207- } else if (delegateCompletionHandler != null ) {
211+ }
212+
213+ if (delegateCompletionHandler != null ) {
208214 delegateCompletionHandler .completed (connection );
209215 }
210216 }
0 commit comments