Prevent attempts at KeyUpdate in TLS 1.2
see
@@ -145,6 +145,7 @@ protected boolean isTLSv13ConnectionState()
private volatile boolean failedWithError = false;
private volatile boolean appDataReady = false;
private volatile boolean appDataSplitEnabled = true;
+ private volatile boolean keyUpdateEnabled = false;
// private volatile boolean keyUpdatePendingReceive = false;
private volatile boolean keyUpdatePendingSend = false;
private volatile boolean resumableHandshake = false;
@@ -439,9 +440,13 @@ protected void completeHandshake()
this.alertQueue.shrink();
this.handshakeQueue.shrink();
- this.appDataSplitEnabled = !TlsUtils.isTLSv11(context);
+ ProtocolVersion negotiatedVersion = securityParameters.getNegotiatedVersion();
+
+ this.appDataSplitEnabled = !TlsUtils.isTLSv11(negotiatedVersion);
this.appDataReady = true;
+ this.keyUpdateEnabled = TlsUtils.isTLSv13(negotiatedVersion);
+
if (blocking)
{
this.tlsInputStream = new TlsInputStream(this);
@@ -941,7 +946,9 @@ public void writeApplicationData(byte[] buf, int offset, int len)
}
}
}
- else if (keyUpdatePendingSend)
+ else if (keyUpdateEnabled)
+ {
+ if (keyUpdatePendingSend)
{
send13KeyUpdate(false);
}
@@ -949,6 +956,7 @@ else if (recordStream.needsKeyUpdate())
{
send13KeyUpdate(true);
}
+ }
// Fragment data according to the current fragment limit.
int toWrite = Math.min(len, recordStream.getPlaintextLimit());
@@ -1148,7 +1156,7 @@ public RecordPreview previewOutputRecord(int applicationDataSize) throws IOExcep
else
{
RecordPreview a = recordStream.previewOutputRecord(applicationDataSize);
- if (keyUpdatePendingSend || recordStream.needsKeyUpdate())
+ if (keyUpdateEnabled && (keyUpdatePendingSend || recordStream.needsKeyUpdate()))
{
int keyUpdateLength = HandshakeMessageOutput.getLength(1);
int recordSize = recordStream.previewOutputRecordSize(keyUpdateLength);
@@ -1495,7 +1503,7 @@ protected void receive13KeyUpdate(ByteArrayInputStream buf) throws IOException
{
// TODO[tls13] This is interesting enough to notify the TlsPeer for possible logging/vetting
- if (!appDataReady)
+ if (!(appDataReady && keyUpdateEnabled))
{
throw new TlsFatalAlert(AlertDescription.unexpected_message);
}
@@ -1632,7 +1640,7 @@ protected void send13KeyUpdate(boolean updateRequested) throws IOException
{
// TODO[tls13] This is interesting enough to notify the TlsPeer for possible logging/vetting
- if (!appDataReady)
+ if (!(appDataReady && keyUpdateEnabled))
{
throw new TlsFatalAlert(AlertDescription.internal_error);
}
