Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jdk/src/share/classes/sun/security/ssl/InputRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void changeReadCiphers(SSLReadCipher readCipher) {
* Since MAC's doFinal() is called for every SSL/TLS packet, it's
* not necessary to do the same with MAC's.
*/
readCipher.dispose();
this.readCipher.dispose();

this.readCipher = readCipher;
}
Expand Down
9 changes: 7 additions & 2 deletions jdk/src/share/classes/sun/security/ssl/OutputRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ abstract void encodeHandshake(byte[] buffer,
// SSLEngine and SSLSocket
abstract void encodeChangeCipherSpec() throws IOException;

// SSLEngine and SSLSocket
void disposeWriteCipher() {
throw new UnsupportedOperationException();
}

// apply to SSLEngine only
Ciphertext encode(
ByteBuffer[] srcs, int srcsOffset, int srcsLength,
Expand Down Expand Up @@ -170,7 +175,7 @@ synchronized void changeWriteCiphers(SSLWriteCipher writeCipher,
* Since MAC's doFinal() is called for every SSL/TLS packet, it's
* not necessary to do the same with MAC's.
*/
writeCipher.dispose();
disposeWriteCipher();

this.writeCipher = writeCipher;
this.isFirstAppOutputRecord = true;
Expand All @@ -194,7 +199,7 @@ synchronized void changeWriteCiphers(SSLWriteCipher writeCipher,
flush();

// Dispose of any intermediate state in the underlying cipher.
writeCipher.dispose();
disposeWriteCipher();

this.writeCipher = writeCipher;
this.isFirstAppOutputRecord = true;
Expand Down
22 changes: 22 additions & 0 deletions jdk/src/share/classes/sun/security/ssl/SSLEngineOutputRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ void encodeChangeCipherSpec() throws IOException {
fragmenter.queueUpChangeCipherSpec();
}

@Override
void disposeWriteCipher() {
if (fragmenter == null) {
writeCipher.dispose();
} else {
fragmenter.queueUpCipherDispose();
}
}

@Override
void encodeV2NoCipher() throws IOException {
isTalkingToV2 = true;
Expand Down Expand Up @@ -356,6 +365,7 @@ private static class RecordMemo {
byte majorVersion;
byte minorVersion;
SSLWriteCipher encodeCipher;
boolean disposeCipher;

byte[] fragment;
}
Expand Down Expand Up @@ -416,6 +426,15 @@ void queueUpAlert(byte level, byte description) {
handshakeMemos.add(memo);
}

void queueUpCipherDispose() {
RecordMemo lastMemo = handshakeMemos.peekLast();
if (lastMemo != null) {
lastMemo.disposeCipher = true;
} else {
writeCipher.dispose();
}
}

Ciphertext acquireCiphertext(ByteBuffer dstBuf) throws IOException {
if (isEmpty()) {
return null;
Expand Down Expand Up @@ -515,6 +534,9 @@ Ciphertext acquireCiphertext(ByteBuffer dstBuf) throws IOException {
dstPos, dstLim, headerSize,
ProtocolVersion.valueOf(memo.majorVersion,
memo.minorVersion));
if (memo.disposeCipher) {
memo.encodeCipher.dispose();
}

if (SSLLogger.isOn && SSLLogger.isOn("packet")) {
ByteBuffer temporary = dstBuf.duplicate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ synchronized void encodeChangeCipherSpec() throws IOException {
count = 0;
}

@Override
void disposeWriteCipher() {
writeCipher.dispose();
}

@Override
public synchronized void flush() throws IOException {
int position = headerSize + writeCipher.getExplicitNonceSize();
Expand Down