Skip to content
Permalink
Browse files
8253635: Implement toString() for SSLEngineImpl
Reviewed-by: coffeys, wetmore
  • Loading branch information
XueleiFan committed Jan 13, 2021
1 parent c6d798c commit 65bed6470c104074ca4c742b0db302683b7f948e
Showing with 30 additions and 24 deletions.
  1. +10 −1 src/java.base/share/classes/sun/security/ssl/SSLEngineImpl.java
  2. +20 −23 src/java.base/share/classes/sun/security/ssl/SSLSocketImpl.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. 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
@@ -1089,6 +1089,15 @@ public boolean useDelegatedTask() {
return true;
}

@Override
public String toString() {
return "SSLEngine[" +
"hostname=" + getPeerHost() +
", port=" + getPeerPort() +
", " + conContext.conSession + // SSLSessionImpl.toString()
"]";
}

/*
* Depending on whether the error was just a warning and the
* handshaker wasn't closed, or fatal and the handshaker is now
@@ -35,7 +35,6 @@
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -135,7 +134,7 @@
* if appropriate.
*/
SSLSocketImpl(SSLContextImpl sslContext, String peerHost,
int peerPort) throws IOException, UnknownHostException {
int peerPort) throws IOException {
super();
this.sslContext = sslContext;
HandshakeHash handshakeHash = new HandshakeHash();
@@ -179,7 +178,7 @@
*/
SSLSocketImpl(SSLContextImpl sslContext,
String peerHost, int peerPort, InetAddress localAddr,
int localPort) throws IOException, UnknownHostException {
int localPort) throws IOException {
super();
this.sslContext = sslContext;
HandshakeHash handshakeHash = new HandshakeHash();
@@ -1406,11 +1405,9 @@ private int readHandshakeRecord() throws IOException {
conContext.isNegotiated) {
return 0;
}
} catch (SSLException ssle) {
throw ssle;
} catch (InterruptedIOException iioe) {
} catch (SSLException | InterruptedIOException ssle) {
// don't change exception in case of timeouts or interrupts
throw iioe;
throw ssle;
} catch (IOException ioe) {
throw new SSLException("readHandshakeRecord", ioe);
}
@@ -1471,17 +1468,11 @@ private ByteBuffer readApplicationRecord(
buffer.position() > 0) {
return buffer;
}
} catch (SSLException ssle) {
throw ssle;
} catch (InterruptedIOException iioe) {
} catch (SSLException | InterruptedIOException ssle) {
// don't change exception in case of timeouts or interrupts
throw iioe;
throw ssle;
} catch (IOException ioe) {
if (!(ioe instanceof SSLException)) {
throw new SSLException("readApplicationRecord", ioe);
} else {
throw ioe;
}
throw new SSLException("readApplicationRecord", ioe);
}
}

@@ -1738,19 +1729,25 @@ public void shutdown() throws IOException {
}

try {
if (conContext.isInputCloseNotified) {
// Close the connection, no wait for more peer response.
closeSocket(false);
} else {
// Close the connection, may wait for peer close_notify.
closeSocket(true);
}
// If conContext.isInputCloseNotified is false, close the
// connection, no wait for more peer response. Otherwise,
// may wait for peer close_notify.
closeSocket(!conContext.isInputCloseNotified);
} finally {
tlsIsClosed = true;
}
}
}

@Override
public String toString() {
return "SSLSocket[" +
"hostname=" + getPeerHost() +
", port=" + getPeerPort() +
", " + conContext.conSession + // SSLSessionImpl.toString()
"]";
}

private void closeSocket(boolean selfInitiated) throws IOException {
if (SSLLogger.isOn && SSLLogger.isOn("ssl")) {
SSLLogger.fine("close the SSL connection " +

1 comment on commit 65bed64

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 65bed64 Jan 13, 2021

Please sign in to comment.