Skip to content

Commit c4fd895

Browse files
committed
refactoring
1 parent 07e728b commit c4fd895

2 files changed

Lines changed: 5 additions & 10 deletions

File tree

rlib-network/src/main/java/com/ss/rlib/network/packet/impl/AbstractSSLPacketReader.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ protected int doHandshake(@NotNull ByteBuffer receivedBuffer, int receivedBytes)
112112
}
113113

114114
sslEngine.closeOutbound();
115-
// After closeOutbound the engine will be set to WRAP state,
116-
// in order to try to send a close message to the client.
117115
handshakeStatus = sslEngine.getHandshakeStatus();
118116
break;
119117

@@ -129,7 +127,6 @@ protected int doHandshake(@NotNull ByteBuffer receivedBuffer, int receivedBytes)
129127
} catch (SSLException sslException) {
130128
LOGGER.error("A problem was encountered while processing the data that caused the " +
131129
"SSLEngine to abort. Will try to properly close connection...");
132-
LOGGER.error(sslException);
133130
sslEngine.closeOutbound();
134131
handshakeStatus = sslEngine.getHandshakeStatus();
135132
break;
@@ -139,7 +136,7 @@ protected int doHandshake(@NotNull ByteBuffer receivedBuffer, int receivedBytes)
139136
case OK:
140137
break;
141138
case BUFFER_OVERFLOW:
142-
throw new IllegalStateException("Unexpected state");
139+
throw new IllegalStateException("Unexpected ssl engine result");
143140
case BUFFER_UNDERFLOW:
144141
LOGGER.debug("Increase ssl network buffer");
145142
increaseNetworkBuffer();
@@ -194,6 +191,7 @@ protected int decryptAndRead(@NotNull ByteBuffer receivedBuffer) {
194191

195192
SSLEngineResult result;
196193
try {
194+
LOGGER.debug(receivedBuffer, buf -> "Try to decrypt data:\n" + hexDump(buf));
197195
result = sslEngine.unwrap(receivedBuffer, sslDataBuffer.clear());
198196
} catch (SSLException e) {
199197
if (e.getCause() instanceof BadPaddingException) {

rlib-network/src/main/java/com/ss/rlib/network/packet/impl/AbstractSSLPacketWriter.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public AbstractSSLPacketWriter(
8080
increaseNetworkBuffer();
8181
break;
8282
case BUFFER_OVERFLOW:
83-
throw new IllegalStateException("Unexpected state");
83+
throw new IllegalStateException("Unexpected ssl engine result");
8484
case OK:
8585
return sslNetworkBuffer.flip();
8686
case CLOSED:
@@ -149,14 +149,10 @@ public AbstractSSLPacketWriter(
149149
sslNetworkBuffer = NetworkUtils.enlargePacketBuffer(bufferAllocator, sslEngine);
150150
break;
151151
case BUFFER_UNDERFLOW:
152-
throw new SSLException(
153-
"Buffer underflow occured after a wrap. I don't think we should ever get here."
154-
);
152+
throw new IllegalStateException("Unexpected ssl engine result");
155153
case CLOSED:
156154
try {
157155
return EMPTY_BUFFER;
158-
// At this point the handshake status will probably be NEED_UNWRAP so we make sure that peerNetData is clear to read.
159-
//peerNetData.clear();
160156
} catch (Exception e) {
161157
LOGGER.error("Failed to send server's CLOSE message due to socket channel's failure.");
162158
handshakeStatus = sslEngine.getHandshakeStatus();
@@ -169,6 +165,7 @@ public AbstractSSLPacketWriter(
169165
case NEED_TASK:
170166
Runnable task;
171167
while ((task = sslEngine.getDelegatedTask()) != null) {
168+
LOGGER.debug(task, t -> "Execute SSL Engine's task: " + t.getClass());
172169
task.run();
173170
}
174171
handshakeStatus = sslEngine.getHandshakeStatus();

0 commit comments

Comments
 (0)