@@ -191,20 +191,26 @@ public void failed(final Throwable throwable) {
191
191
}
192
192
193
193
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 ();
199
203
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 ;
206
210
}
207
- } else if (delegateCompletionHandler != null ) {
211
+ }
212
+
213
+ if (delegateCompletionHandler != null ) {
208
214
delegateCompletionHandler .completed (connection );
209
215
}
210
216
}
0 commit comments