Skip to content

Commit d66f53a

Browse files
committed
allow reading 0 bytes from socket
since to trigger and finish PHA the client and server needs to read from socket, allow reading 0 bytes, just to trigger buffer processing
1 parent 4113029 commit d66f53a

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

tests/tlstest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def testConnClient(conn):
7777
conn.write(b1)
7878
conn.write(b10)
7979
conn.write(b100)
80+
conn.write(b1000)
8081
r1 = conn.read(min=1, max=1)
8182
assert len(r1) == 1
8283
assert r1 == b1
@@ -86,7 +87,6 @@ def testConnClient(conn):
8687
r100 = conn.read(min=100, max=100)
8788
assert len(r100) == 100
8889
assert r100 == b100
89-
conn.write(b1000)
9090
r1000 = conn.read(min=1000, max=1000)
9191
assert len(r1000) == 1000
9292
assert r1000 == b1000
@@ -715,6 +715,8 @@ def connect():
715715
settings.maxVersion = (3, 4)
716716
connection.handshakeClientCert(x509Chain, x509Key, settings=settings)
717717
synchro.recv(1)
718+
b = connection.read(0, 0)
719+
assert b == b''
718720
testConnClient(connection)
719721
assert(isinstance(connection.session.serverCertChain, X509CertChain))
720722
connection.close()

tlslite/tlsrecordlayer.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,14 @@ def readAsync(self, max=None, min=1):
328328
allowedTypes = ContentType.application_data
329329
allowedHsTypes = None
330330
try:
331-
while len(self._readBuffer) < min and not self.closed:
331+
try_once = True
332+
# perform a read even if we were asked to read 0 bytes, but only
333+
# if the buffer is empty; this is used to trigger
334+
# processing of NST, KeyUpdate and PHA
335+
while (len(self._readBuffer) < min or
336+
(not self._readBuffer and try_once)) \
337+
and not self.closed:
338+
try_once = False
332339
try:
333340
for result in self._getMsg(allowedTypes,
334341
allowedHsTypes,
@@ -338,21 +345,19 @@ def readAsync(self, max=None, min=1):
338345
if isinstance(result, NewSessionTicket):
339346
result.time = time.time()
340347
self.tickets.append(result)
341-
continue
342348
elif isinstance(result, KeyUpdate):
343349
for result in self._handle_keyupdate_request(result):
344350
yield result
345-
continue
346351
elif isinstance(result, Certificate):
347352
for result in self._handle_srv_pha(result):
348353
yield result
349-
continue
350354
elif isinstance(result, CertificateRequest):
351355
for result in self._handle_pha(result):
352356
yield result
353-
continue
354-
applicationData = result
355-
self._readBuffer += applicationData.write()
357+
else:
358+
assert isinstance(result, ApplicationData)
359+
applicationData = result
360+
self._readBuffer += applicationData.write()
356361
except TLSRemoteAlert as alert:
357362
if alert.description != AlertDescription.close_notify:
358363
raise

0 commit comments

Comments
 (0)