DTLS: Only send alerts if we ever received a record from the peer
@@ -94,6 +94,7 @@ private static void sendDatagram(DatagramSender sender, byte[] record)
private volatile boolean failed = false;
// TODO[dtls13] Review the draft/RFC (legacy_record_version) to see if readVersion can be removed
private volatile ProtocolVersion readVersion = null, writeVersion = null;
+ private volatile boolean inConnection;
private volatile boolean inHandshake;
private volatile int plaintextLimit;
private DTLSEpoch currentEpoch, pendingEpoch;
@@ -135,6 +136,8 @@ void resetAfterHelloVerifyRequestClient()
void resetAfterHelloVerifyRequestServer(long writeRecordSeqNo)
{
+ this.inConnection = true;
+
currentEpoch.setSequenceNumber(writeRecordSeqNo);
/*
@@ -363,7 +366,7 @@ public void close()
{
if (!closed)
{
- if (inHandshake)
+ if (inHandshake && inConnection)
{
warn(AlertDescription.user_canceled, "User canceled handshake");
}
@@ -374,6 +377,8 @@ public void close()
void fail(short alertDescription)
{
if (!closed)
+ {
+ if (inConnection)
{
try
{
@@ -383,6 +388,7 @@ void fail(short alertDescription)
{
// Ignore
}
+ }
failed = true;
@@ -712,6 +718,8 @@ private int receiveRecord(byte[] buf, int off, int len, int waitMillis)
int received = receiveDatagram(buf, off, len, waitMillis);
if (received >= RECORD_HEADER_LENGTH)
{
+ this.inConnection = true;
+
int fragmentLength = TlsUtils.readUint16(buf, off + 11);
int recordLength = RECORD_HEADER_LENGTH + fragmentLength;
if (received > recordLength)
