Skip to content

Commit 5aa15d5

Browse files
committed
Fix for Bug#93590 (29054329), javax.net.ssl.SSLException: closing inbound before receiving peer's close_notify.
1 parent 1fecc2b commit 5aa15d5

File tree

4 files changed

+53
-44
lines changed

4 files changed

+53
-44
lines changed

CHANGES

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
Version 8.0.16
55

6+
- Fix for Bug#93590 (29054329), javax.net.ssl.SSLException: closing inbound before receiving peer's close_notify.
7+
68
- Fix for Bug#94414 (29384853), Connector/J RPM package have version number in path.
79

810
- Fix for Bug#27786499, REDUNDANT FILES IN DEBIAN PACKAGE FOR DEBIAN9(COMMUNITY PACKAGE) FOR CJAVA.

src/main/core-api/java/com/mysql/cj/protocol/NetworkResources.java

+31-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program is free software; you can redistribute it and/or modify it under
55
* the terms of the GNU General Public License, version 2.0, as published by the
@@ -50,47 +50,51 @@ public NetworkResources(Socket mysqlConnection, InputStream mysqlInput, OutputSt
5050
*/
5151
public final void forceClose() {
5252
try {
53-
try {
54-
if (this.mysqlInput != null) {
55-
this.mysqlInput.close();
56-
}
57-
} finally {
58-
if (this.mysqlConnection != null && !this.mysqlConnection.isClosed() && !this.mysqlConnection.isInputShutdown()) {
59-
try {
60-
this.mysqlConnection.shutdownInput();
61-
} catch (UnsupportedOperationException ex) {
62-
// ignore, some sockets do not support this method
53+
if (!ExportControlled.isSSLEstablished(this.mysqlConnection)) { // Fix for Bug#56979 does not apply to secure sockets.
54+
try {
55+
if (this.mysqlInput != null) {
56+
this.mysqlInput.close();
57+
}
58+
} finally {
59+
if (this.mysqlConnection != null && !this.mysqlConnection.isClosed() && !this.mysqlConnection.isInputShutdown()) {
60+
try {
61+
this.mysqlConnection.shutdownInput();
62+
} catch (UnsupportedOperationException e) {
63+
// Ignore, some sockets do not support this method.
64+
}
6365
}
6466
}
6567
}
66-
} catch (IOException ioEx) {
67-
// we can't do anything constructive about this
68+
} catch (IOException e) {
69+
// Can't do anything constructive about this.
6870
}
6971

7072
try {
71-
try {
72-
if (this.mysqlOutput != null) {
73-
this.mysqlOutput.close();
74-
}
75-
} finally {
76-
if (this.mysqlConnection != null && !this.mysqlConnection.isClosed() && !this.mysqlConnection.isOutputShutdown()) {
77-
try {
78-
this.mysqlConnection.shutdownOutput();
79-
} catch (UnsupportedOperationException ex) {
80-
// ignore, some sockets do not support this method
73+
if (!ExportControlled.isSSLEstablished(this.mysqlConnection)) { // Fix for Bug#56979 does not apply to secure sockets.
74+
try {
75+
if (this.mysqlOutput != null) {
76+
this.mysqlOutput.close();
77+
}
78+
} finally {
79+
if (this.mysqlConnection != null && !this.mysqlConnection.isClosed() && !this.mysqlConnection.isOutputShutdown()) {
80+
try {
81+
this.mysqlConnection.shutdownOutput();
82+
} catch (UnsupportedOperationException e) {
83+
// Ignore, some sockets do not support this method.
84+
}
8185
}
8286
}
8387
}
84-
} catch (IOException ioEx) {
85-
// we can't do anything constructive about this
88+
} catch (IOException e) {
89+
// Can't do anything constructive about this.
8690
}
8791

8892
try {
8993
if (this.mysqlConnection != null) {
9094
this.mysqlConnection.close();
9195
}
92-
} catch (IOException ioEx) {
93-
// we can't do anything constructive about this
96+
} catch (IOException e) {
97+
// Can't do anything constructive about this.
9498
}
9599
}
96100
}

src/main/core-impl/java/com/mysql/cj/protocol/ExportControlled.java

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program is free software; you can redistribute it and/or modify it under
55
* the terms of the GNU General Public License, version 2.0, as published by the
@@ -289,11 +289,12 @@ public static Socket performTlsHandshake(Socket rawSocket, SocketConnection sock
289289

290290
PropertySet pset = socketConnection.getPropertySet();
291291

292-
SslMode sslMode = pset.<SslMode> getEnumProperty(PropertyKey.sslMode).getValue();
292+
SslMode sslMode = pset.<SslMode>getEnumProperty(PropertyKey.sslMode).getValue();
293293
boolean verifyServerCert = sslMode == SslMode.VERIFY_CA || sslMode == SslMode.VERIFY_IDENTITY;
294294

295-
KeyStoreConf trustStore = !verifyServerCert ? new KeyStoreConf() : getTrustStoreConf(pset, PropertyKey.trustCertificateKeyStoreUrl,
296-
PropertyKey.trustCertificateKeyStorePassword, PropertyKey.trustCertificateKeyStoreType, verifyServerCert && serverVersion == null);
295+
KeyStoreConf trustStore = !verifyServerCert ? new KeyStoreConf()
296+
: getTrustStoreConf(pset, PropertyKey.trustCertificateKeyStoreUrl, PropertyKey.trustCertificateKeyStorePassword,
297+
PropertyKey.trustCertificateKeyStoreType, verifyServerCert && serverVersion == null);
297298

298299
KeyStoreConf keyStore = getKeyStoreConf(pset, PropertyKey.clientCertificateKeyStoreUrl, PropertyKey.clientCertificateKeyStorePassword,
299300
PropertyKey.clientCertificateKeyStoreType);
@@ -573,7 +574,7 @@ public static SSLContext getSSLContext(String clientCertificateKeyStoreUrl, Stri
573574
}
574575

575576
public static boolean isSSLEstablished(Socket socket) {
576-
return SSLSocket.class.isAssignableFrom(socket.getClass());
577+
return socket == null ? false : SSLSocket.class.isAssignableFrom(socket.getClass());
577578
}
578579

579580
public static RSAPublicKey decodeRSAPublicKey(String key) throws RSAException {
@@ -616,11 +617,12 @@ public static AsynchronousSocketChannel startTlsOnAsynchronousChannel(Asynchrono
616617

617618
PropertySet propertySet = socketConnection.getPropertySet();
618619

619-
SslMode sslMode = propertySet.<SslMode> getEnumProperty(PropertyKey.sslMode).getValue();
620+
SslMode sslMode = propertySet.<SslMode>getEnumProperty(PropertyKey.sslMode).getValue();
620621

621622
boolean verifyServerCert = sslMode == SslMode.VERIFY_CA || sslMode == SslMode.VERIFY_IDENTITY;
622-
KeyStoreConf trustStore = !verifyServerCert ? new KeyStoreConf() : getTrustStoreConf(propertySet, PropertyKey.trustCertificateKeyStoreUrl,
623-
PropertyKey.trustCertificateKeyStorePassword, PropertyKey.trustCertificateKeyStoreType, true);
623+
KeyStoreConf trustStore = !verifyServerCert ? new KeyStoreConf()
624+
: getTrustStoreConf(propertySet, PropertyKey.trustCertificateKeyStoreUrl, PropertyKey.trustCertificateKeyStorePassword,
625+
PropertyKey.trustCertificateKeyStoreType, true);
624626

625627
KeyStoreConf keyStore = getKeyStoreConf(propertySet, PropertyKey.clientCertificateKeyStoreUrl, PropertyKey.clientCertificateKeyStorePassword,
626628
PropertyKey.clientCertificateKeyStoreType);

src/main/protocol-impl/java/com/mysql/cj/protocol/a/NativeProtocol.java

+10-9
Original file line numberDiff line numberDiff line change
@@ -1311,18 +1311,19 @@ public final void skipPacket() {
13111311
*/
13121312
public final void quit() {
13131313
try {
1314-
// we're not going to read the response, fixes BUG#56979 Improper connection closing logic leads to TIME_WAIT sockets on server
1315-
13161314
try {
1317-
if (!this.socketConnection.getMysqlSocket().isClosed()) {
1318-
try {
1319-
this.socketConnection.getMysqlSocket().shutdownInput();
1320-
} catch (UnsupportedOperationException ex) {
1321-
// ignore, some sockets do not support this method
1315+
if (!ExportControlled.isSSLEstablished(this.socketConnection.getMysqlSocket())) { // Fix for Bug#56979 does not apply to secure sockets.
1316+
if (!this.socketConnection.getMysqlSocket().isClosed()) {
1317+
try {
1318+
// The response won't be read, this fixes BUG#56979 [Improper connection closing logic leads to TIME_WAIT sockets on server].
1319+
this.socketConnection.getMysqlSocket().shutdownInput();
1320+
} catch (UnsupportedOperationException e) {
1321+
// Ignore, some sockets do not support this method.
1322+
}
13221323
}
13231324
}
1324-
} catch (IOException ioEx) {
1325-
this.log.logWarn("Caught while disconnecting...", ioEx);
1325+
} catch (IOException e) {
1326+
// Can't do anything constructive about this.
13261327
}
13271328

13281329
this.packetSequence = -1;

0 commit comments

Comments
 (0)