Skip to content

Commit 683095b

Browse files
committed
FIX: Handle TLS handshake record received in multiple chunks
see: Oldes/Rebol-TLS#2
1 parent 9aa8261 commit 683095b

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/mezz/prot-tls.reb

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
REBOL [
2-
version: 0.11.0
2+
version: 0.12.0
33
title: "TLS Protocol"
4-
name: tls
5-
date: 13-Nov-2025
4+
name: 'tls
5+
date: 30-Nov-2025
66
file: %tls.reb
77
author: "Oldes"
8-
Yype: module
8+
Yype: 'module
99
License: MIT
1010
Home: https://github.com/Oldes/Rebol-TLS
1111
]
@@ -968,12 +968,16 @@ get-transcript-hash: function [
968968
]
969969
TLS-parse-handshake-records: function [
970970
ctx [object!]
971-
data [binary!]
972971
] [
973-
bin: binary data
972+
bin: binary ctx/port-data
974973
while [4 <= length? bin/buffer] [
975974
start: bin/buffer
976-
binary/read bin [type: UI8 message: UI24BYTES]
975+
binary/read bin [type: UI8 len: UI24]
976+
if len > length? bin/buffer [
977+
bin/buffer: start
978+
break
979+
]
980+
message: binary/read bin len
977981
log-debug ["R[" ctx/seq-read "] length:" length? message "type:" type]
978982
change-state ctx *Handshake/name type
979983
TLS-update-messages-hash/part ctx start 4 + length? message
@@ -1033,6 +1037,7 @@ TLS-parse-handshake-records: function [
10331037
]
10341038
]
10351039
log-more ["DONE: handshake^[[1m" ctx/state] log-----
1040+
ctx/port-data: truncate bin/buffer
10361041
false
10371042
]
10381043
prepare-change-cipher-spec: function [
@@ -1410,6 +1415,7 @@ TLS-read-data: function [
14101415
log-debug ["Inner type:^[[1m" type]
14111416
]
14121417
]
1418+
append ctx/port-data data
14131419
]
14141420
*protocol-type/assert type
14151421
*protocol-version/assert server-version
@@ -1421,12 +1427,9 @@ TLS-read-data: function [
14211427
switch protocol [
14221428
APPLICATION [
14231429
assert-prev-state ctx [APPLICATION ALERT FINISHED NEW_SESSION_TICKET]
1424-
append ctx/port-data data
14251430
]
14261431
HANDSHAKE [
1427-
unless empty? data [
1428-
ctx/critical-error: TLS-parse-handshake-records ctx data
1429-
]
1432+
ctx/critical-error: TLS-parse-handshake-records ctx
14301433
ctx/reading?: any [ctx/server? not empty? inp/buffer]
14311434
]
14321435
CHANGE_CIPHER_SPEC [

0 commit comments

Comments
 (0)