diff --git a/src/share/classes/sun/security/ssl/BaseSSLSocketImpl.java b/src/share/classes/sun/security/ssl/BaseSSLSocketImpl.java index 8ca8e76ac68260ac2ee99e57aa67fffcb07485c6..a918b1479984963e27ee7538175687d05cd21c18 100644 --- a/src/share/classes/sun/security/ssl/BaseSSLSocketImpl.java +++ b/src/share/classes/sun/security/ssl/BaseSSLSocketImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2002-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -256,10 +256,12 @@ abstract class BaseSSLSocketImpl extends SSLSocket { // ignore } } finally { - // we call close on the underlying socket anyway, but be - // doubly sure all resources get released. - // note that we don't need to worry about self, the GC - // will finalize that separately + // We called close on the underlying socket above to + // make doubly sure all resources got released. We + // don't finalize self in the case of overlain sockets, + // that's a different object which the GC will finalize + // separately. + super.finalize(); } } diff --git a/src/share/classes/sun/security/ssl/SSLServerSocketImpl.java b/src/share/classes/sun/security/ssl/SSLServerSocketImpl.java index 88bab016175d6dcbfcdf063eec91f10c33d3145f..68037ca5d7347ecfada1f4f56261ee44048d593f 100644 --- a/src/share/classes/sun/security/ssl/SSLServerSocketImpl.java +++ b/src/share/classes/sun/security/ssl/SSLServerSocketImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 1996-2007 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1996-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -304,14 +304,18 @@ class SSLServerSocketImpl extends SSLServerSocket enabledCipherSuites, doClientAuth, enableSessionCreation, enabledProtocols); - ServerHandshaker handshaker = tmp.getServerHandshaker(); + try { + ServerHandshaker handshaker = tmp.getServerHandshaker(); - for (Iterator t = enabledCipherSuites.iterator(); t.hasNext(); ) { - CipherSuite suite = (CipherSuite)t.next(); - if (handshaker.trySetCipherSuite(suite)) { - checkedEnabled = true; - return; + for (Iterator t = enabledCipherSuites.iterator(); t.hasNext(); ) { + CipherSuite suite = (CipherSuite)t.next(); + if (handshaker.trySetCipherSuite(suite)) { + checkedEnabled = true; + return; + } } + } finally { + tmp.closeSocket(); } // diff --git a/src/share/classes/sun/security/ssl/SSLSocketImpl.java b/src/share/classes/sun/security/ssl/SSLSocketImpl.java index 66b6e6d112c0b7cf5856457bb37d17a951cbcc37..a270cdc5fcdbe12ae626604af985c94d19875ae3 100644 --- a/src/share/classes/sun/security/ssl/SSLSocketImpl.java +++ b/src/share/classes/sun/security/ssl/SSLSocketImpl.java @@ -1012,6 +1012,22 @@ final public class SSLSocketImpl extends BaseSSLSocketImpl { */ ServerHandshaker getServerHandshaker() throws SSLException { initHandshaker(); + + // The connection state would have been set to cs_HANDSHAKE during the + // handshaking initializing, however the caller may not have the + // the low level connection's established, which is not consistent with + // the HANDSHAKE state. As if it is unconnected, we need to reset the + // connection state to cs_START. + if (!isConnected()) { + connectionState = cs_START; + } + + // Make sure that we get a ServerHandshaker. + // This should never happen. + if (!(handshaker instanceof ServerHandshaker)) { + throw new SSLProtocolException("unexpected handshaker instance"); + } + return (ServerHandshaker)handshaker; } @@ -1273,7 +1289,8 @@ final public class SSLSocketImpl extends BaseSSLSocketImpl { } } - private void closeSocket() throws IOException { + protected void closeSocket() throws IOException { + if ((debug != null) && Debug.isOn("ssl")) { System.out.println(threadName() + ", called closeSocket()"); }