Blame SOURCES/nss-post-handshake-auth-with-tickets.patch

3d912a
# HG changeset patch
3d912a
# User Daiki Ueno <dueno@redhat.com>
3d912a
# Date 1559121620 -7200
3d912a
#      Wed May 29 11:20:20 2019 +0200
3d912a
# Node ID 29a48b604602a523defd6f9322a5adeca7e284a5
3d912a
# Parent  43a7fb4f994a31222c308113b0fccdd5480d5b8e
3d912a
Bug 1553443, send session ticket only after handshake is marked as finished
3d912a
3d912a
Reviewers: mt
3d912a
3d912a
Reviewed By: mt
3d912a
3d912a
Bug #: 1553443
3d912a
3d912a
Differential Revision: https://phabricator.services.mozilla.com/D32128
3d912a
3d912a
diff --git a/gtests/ssl_gtest/ssl_auth_unittest.cc b/gtests/ssl_gtest/ssl_auth_unittest.cc
3d912a
--- a/gtests/ssl_gtest/ssl_auth_unittest.cc
3d912a
+++ b/gtests/ssl_gtest/ssl_auth_unittest.cc
3d912a
@@ -537,6 +537,40 @@ TEST_F(TlsConnectStreamTls13, PostHandsh
3d912a
                       capture_cert_req->buffer().len()));
3d912a
 }
3d912a
 
3d912a
+// Check if post-handshake auth still works when session tickets are enabled:
3d912a
+// https://bugzilla.mozilla.org/show_bug.cgi?id=1553443
3d912a
+TEST_F(TlsConnectStreamTls13, PostHandshakeAuthWithSessionTicketsEnabled) {
3d912a
+  EnsureTlsSetup();
3d912a
+  client_->SetupClientAuth();
3d912a
+  EXPECT_EQ(SECSuccess, SSL_OptionSet(client_->ssl_fd(),
3d912a
+                                      SSL_ENABLE_POST_HANDSHAKE_AUTH, PR_TRUE));
3d912a
+  EXPECT_EQ(SECSuccess, SSL_OptionSet(client_->ssl_fd(),
3d912a
+                                      SSL_ENABLE_SESSION_TICKETS, PR_TRUE));
3d912a
+  EXPECT_EQ(SECSuccess, SSL_OptionSet(server_->ssl_fd(),
3d912a
+                                      SSL_ENABLE_SESSION_TICKETS, PR_TRUE));
3d912a
+  size_t called = 0;
3d912a
+  server_->SetAuthCertificateCallback(
3d912a
+      [&called](TlsAgent*, PRBool, PRBool) -> SECStatus {
3d912a
+        called++;
3d912a
+        return SECSuccess;
3d912a
+      });
3d912a
+  Connect();
3d912a
+  EXPECT_EQ(0U, called);
3d912a
+  // Send CertificateRequest.
3d912a
+  EXPECT_EQ(SECSuccess, SSL_GetClientAuthDataHook(
3d912a
+                            client_->ssl_fd(), GetClientAuthDataHook, nullptr));
3d912a
+  EXPECT_EQ(SECSuccess, SSL_SendCertificateRequest(server_->ssl_fd()))
3d912a
+      << "Unexpected error: " << PORT_ErrorToName(PORT_GetError());
3d912a
+  server_->SendData(50);
3d912a
+  client_->ReadBytes(50);
3d912a
+  client_->SendData(50);
3d912a
+  server_->ReadBytes(50);
3d912a
+  EXPECT_EQ(1U, called);
3d912a
+  ScopedCERTCertificate cert1(SSL_PeerCertificate(server_->ssl_fd()));
3d912a
+  ScopedCERTCertificate cert2(SSL_LocalCertificate(client_->ssl_fd()));
3d912a
+  EXPECT_TRUE(SECITEM_ItemsAreEqual(&cert1->derCert, &cert2->derCert));
3d912a
+}
3d912a
+
3d912a
 // In TLS 1.3, the client sends its cert rejection on the
3d912a
 // second flight, and since it has already received the
3d912a
 // server's Finished, it transitions to complete and
3d912a
diff --git a/lib/ssl/tls13con.c b/lib/ssl/tls13con.c
3d912a
--- a/lib/ssl/tls13con.c
3d912a
+++ b/lib/ssl/tls13con.c
3d912a
@@ -4561,6 +4561,11 @@ tls13_ServerHandleFinished(sslSocket *ss
3d912a
         return SECFailure;
3d912a
     }
3d912a
 
3d912a
+    rv = tls13_FinishHandshake(ss);
3d912a
+    if (rv != SECSuccess) {
3d912a
+        return SECFailure;
3d912a
+    }
3d912a
+
3d912a
     ssl_GetXmitBufLock(ss);
3d912a
     if (ss->opt.enableSessionTickets) {
3d912a
         rv = tls13_SendNewSessionTicket(ss, NULL, 0);
3d912a
@@ -4573,8 +4578,7 @@ tls13_ServerHandleFinished(sslSocket *ss
3d912a
         }
3d912a
     }
3d912a
     ssl_ReleaseXmitBufLock(ss);
3d912a
-
3d912a
-    return tls13_FinishHandshake(ss);
3d912a
+    return SECSuccess;
3d912a
 
3d912a
 loser:
3d912a
     ssl_ReleaseXmitBufLock(ss);
3d912a
diff --git a/tests/ssl/sslauth.txt b/tests/ssl/sslauth.txt
3d912a
--- a/tests/ssl/sslauth.txt
3d912a
+++ b/tests/ssl/sslauth.txt
3d912a
@@ -42,6 +42,7 @@
3d912a
   noECC     0       -r_-r_-r_-r_-E  -V_tls1.3:tls1.3_-E_-n_TestUser_-w_nss TLS 1.3 Require client auth on post hs (client auth)
3d912a
   noECC     0       -r_-r_-r_-E  -V_tls1.3:tls1.3_-E_-n_none_-w_nss TLS 1.3 Request don't require client auth on post hs (client does not provide auth)
3d912a
   noECC     1       -r_-r_-r_-r_-E  -V_tls1.3:tls1.3_-E_-n_none_-w_nss TLS 1.3 Require client auth on post hs (client does not provide auth)
3d912a
+  noECC     0       -r_-r_-r_-E_-u  -V_tls1.3:tls1.3_-E_-n_TestUser_-w_nss TLS 1.3 Request don't require client auth on post hs with session ticket (client auth)
3d912a
 #
3d912a
 # Use EC cert for client authentication
3d912a
 #