Skip to content

Commit

Permalink
allow setting 0 tickets to disable sending tickets
Browse files Browse the repository at this point in the history
  • Loading branch information
tomato42 committed Jan 30, 2019
1 parent 0294251 commit a5e89aa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
3 changes: 2 additions & 1 deletion scripts/tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion tlslite/handshakesettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
25 changes: 25 additions & 0 deletions unit_tests/test_tlslite_handshakesettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit a5e89aa

Please sign in to comment.