diff --git a/scripts/tls.py b/scripts/tls.py index 05476561..130bc56f 100755 --- a/scripts/tls.py +++ b/scripts/tls.py @@ -493,7 +493,8 @@ def serverCmd(argv): settings = HandshakeSettings() settings.useExperimentalTackExtension=True settings.dhParams = dhparam - settings.ticket_count = tickets or settings.ticket_count + if tickets is not None: + settings.ticket_count = tickets if psk: settings.pskConfigs = [(psk_ident, psk, psk_hash)] settings.ticketKeys = [getRandomBytes(32)] diff --git a/tlslite/handshakesettings.py b/tlslite/handshakesettings.py index a8cbd369..028a8d02 100644 --- a/tlslite/handshakesettings.py +++ b/tlslite/handshakesettings.py @@ -483,7 +483,7 @@ def _sanityCheckTicketSettings(other): if not 0 < other.max_early_data <= 2**64: raise ValueError("max_early_data must be between 0 and 2GiB") - if not 0 < other.ticket_count < 2**16: + if not 0 <= other.ticket_count < 2**16: raise ValueError("Incorrect amount for number of new session " "tickets to send") diff --git a/unit_tests/test_tlslite_handshakesettings.py b/unit_tests/test_tlslite_handshakesettings.py index 29ad3a50..c1fec402 100644 --- a/unit_tests/test_tlslite_handshakesettings.py +++ b/unit_tests/test_tlslite_handshakesettings.py @@ -436,6 +436,31 @@ def test_none_as_record_size_limit(self): self.assertIsNone(hs.record_size_limit) + def test_ticket_count_zero(self): + hs = HandshakeSettings() + hs.ticket_count = 0 + + hs = hs.validate() + + self.assertIsNotNone(hs.ticket_count, 0) + + def test_ticket_count_200(self): + hs = HandshakeSettings() + hs.ticket_count = 200 + + hs = hs.validate() + + self.assertIsNotNone(hs.ticket_count, 200) + + def test_ticket_count_negative(self): + hs = HandshakeSettings() + hs.ticket_count = -1 + + with self.assertRaises(ValueError) as e: + hs.validate() + + self.assertIn("new session tickets", str(e.exception)) + if __name__ == '__main__': unittest.main()