Skip to content

Commit

Permalink
Bug 1672703, always tolerate the first CCS in TLS 1.3, r=mt
Browse files Browse the repository at this point in the history
Summary:
This flips the meaning of the flag for checking excessive CCS
messages, so it only rejects multiple CCS messages while the first CCS
message is always accepted.

Reviewers: mt

Reviewed By: mt

Bug #: 1672703

Differential Revision: https://phabricator.services.mozilla.com/D94603

--HG--
extra : rebase_source : dde5b59dff690e622f211c326dc8244ed652f764
extra : amend_source : 3f0506ed64befe5b531339101b655c622151ea47
  • Loading branch information
ueno committed Oct 26, 2020
1 parent 4c88c8e commit be57537
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 26 deletions.
18 changes: 9 additions & 9 deletions gtests/ssl_gtest/ssl_tls13compat_unittest.cc
Expand Up @@ -348,8 +348,8 @@ TEST_F(TlsConnectStreamTls13, ChangeCipherSpecBeforeClientHelloTwice) {
client_->CheckErrorCode(SSL_ERROR_HANDSHAKE_UNEXPECTED_ALERT);
}

// The server rejects a ChangeCipherSpec if the client advertises an
// empty session ID.
// The server accepts a ChangeCipherSpec even if the client advertises
// an empty session ID.
TEST_F(TlsConnectStreamTls13, ChangeCipherSpecAfterClientHelloEmptySid) {
EnsureTlsSetup();
ConfigureVersion(SSL_LIBRARY_VERSION_TLS_1_3);
Expand All @@ -358,9 +358,8 @@ TEST_F(TlsConnectStreamTls13, ChangeCipherSpecAfterClientHelloEmptySid) {
client_->Handshake(); // Send ClientHello
client_->SendDirect(DataBuffer(kCannedCcs, sizeof(kCannedCcs))); // Send CCS

server_->ExpectSendAlert(kTlsAlertUnexpectedMessage);
server_->Handshake(); // Consume ClientHello and CCS
server_->CheckErrorCode(SSL_ERROR_RX_MALFORMED_CHANGE_CIPHER);
Handshake();
CheckConnected();
}

// The server rejects multiple ChangeCipherSpec even if the client
Expand All @@ -381,7 +380,7 @@ TEST_F(Tls13CompatTest, ChangeCipherSpecAfterClientHelloTwice) {
server_->CheckErrorCode(SSL_ERROR_RX_MALFORMED_CHANGE_CIPHER);
}

// The client rejects a ChangeCipherSpec if it advertises an empty
// The client accepts a ChangeCipherSpec even if it advertises an empty
// session ID.
TEST_F(TlsConnectStreamTls13, ChangeCipherSpecAfterServerHelloEmptySid) {
EnsureTlsSetup();
Expand All @@ -398,9 +397,10 @@ TEST_F(TlsConnectStreamTls13, ChangeCipherSpecAfterServerHelloEmptySid) {
// send ServerHello..CertificateVerify
// Send CCS
server_->SendDirect(DataBuffer(kCannedCcs, sizeof(kCannedCcs)));
client_->ExpectSendAlert(kTlsAlertUnexpectedMessage);
client_->Handshake(); // Consume ClientHello and CCS
client_->CheckErrorCode(SSL_ERROR_RX_MALFORMED_CHANGE_CIPHER);

// No alert is sent from the client. As Finished is dropped, we
// can't use Handshake() and CheckConnected().
client_->Handshake();
}

// The client rejects multiple ChangeCipherSpec in a row even if the
Expand Down
20 changes: 7 additions & 13 deletions lib/ssl/ssl3con.c
Expand Up @@ -6645,11 +6645,7 @@ ssl_CheckServerSessionIdCorrectness(sslSocket *ss, SECItem *sidBytes)

/* TLS 1.3: We sent a session ID. The server's should match. */
if (!IS_DTLS(ss) && (sentRealSid || sentFakeSid)) {
if (sidMatch) {
ss->ssl3.hs.allowCcs = PR_TRUE;
return PR_TRUE;
}
return PR_FALSE;
return sidMatch;
}

/* TLS 1.3 (no SID)/DTLS 1.3: The server shouldn't send a session ID. */
Expand Down Expand Up @@ -8696,7 +8692,6 @@ ssl3_HandleClientHello(sslSocket *ss, PRUint8 *b, PRUint32 length)
errCode = PORT_GetError();
goto alert_loser;
}
ss->ssl3.hs.allowCcs = PR_TRUE;
}

/* TLS 1.3 requires that compression include only null. */
Expand Down Expand Up @@ -13066,15 +13061,14 @@ ssl3_HandleRecord(sslSocket *ss, SSL3Ciphertext *cText)
ss->ssl3.hs.ws != idle_handshake &&
cText->buf->len == 1 &&
cText->buf->buf[0] == change_cipher_spec_choice) {
if (ss->ssl3.hs.allowCcs) {
/* Ignore the first CCS. */
ss->ssl3.hs.allowCcs = PR_FALSE;
if (!ss->ssl3.hs.rejectCcs) {
/* Allow only the first CCS. */
ss->ssl3.hs.rejectCcs = PR_TRUE;
return SECSuccess;
} else {
alert = unexpected_message;
PORT_SetError(SSL_ERROR_RX_MALFORMED_CHANGE_CIPHER);
}

/* Compatibility mode is not negotiated. */
alert = unexpected_message;
PORT_SetError(SSL_ERROR_RX_MALFORMED_CHANGE_CIPHER);
}

if ((IS_DTLS(ss) && !dtls13_AeadLimitReached(spec)) ||
Expand Down
5 changes: 1 addition & 4 deletions lib/ssl/sslimpl.h
Expand Up @@ -710,10 +710,7 @@ typedef struct SSL3HandshakeStateStr {
* or received. */
PRBool receivedCcs; /* A server received ChangeCipherSpec
* before the handshake started. */
PRBool allowCcs; /* A server allows ChangeCipherSpec
* as the middlebox compatibility mode
* is explicitly indicarted by
* legacy_session_id in TLS 1.3 ClientHello. */
PRBool rejectCcs; /* Excessive ChangeCipherSpecs are rejected. */
PRBool clientCertRequested; /* True if CertificateRequest received. */
PRBool endOfFlight; /* Processed a full flight (DTLS 1.3). */
ssl3KEADef kea_def_mutable; /* Used to hold the writable kea_def
Expand Down

0 comments on commit be57537

Please sign in to comment.