Skip to content

Commit

Permalink
proper error handling in tls_process_record
Browse files Browse the repository at this point in the history
  • Loading branch information
gh2o committed Nov 3, 2023
1 parent 5af2615 commit 9015f27
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions bash_tls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -652,11 +652,13 @@ tls_send_record() {
}

tls_process_record() {
local type=$(read_from_fd $sockfd 1)
local version=$(read_from_fd $sockfd 2)
local dlen=$(read_from_fd $sockfd 2)
local length=$(hex_int $dlen)
local fragment=$(read_from_fd $sockfd $length)
local type version dlen length fragment
type=$(read_from_fd $sockfd 1)
version=$(read_from_fd $sockfd 2)
dlen=$(read_from_fd $sockfd 2)
length=$(hex_int $dlen)
fragment=$(read_from_fd $sockfd $length)

if (( $tls_read_encrypted )); then
# decrypted length is 24 bytes shorter (8 from nonce, 16 from GCM tag)
local nonce
Expand All @@ -665,6 +667,7 @@ tls_process_record() {
fragment=$(aes_gcm_do_decrypt tls_read_gcm $nonce $header $fragment)
(( tls_read_seq += 1 ))
fi

case $type in
14) # change cipher spec
tls_changecipherspec_buffer+=$fragment
Expand Down

0 comments on commit 9015f27

Please sign in to comment.