Implemented auto TLS upgrade support

This commit is contained in:
Luxferre
2024-10-16 21:03:06 +03:00
parent f0cd4aadf6
commit 638333b62c
3 changed files with 18 additions and 12 deletions
+12 -9
View File
@@ -111,12 +111,10 @@ if {$confini ne ""} {
# load TLS support
if {($bfg_tls_support eq "off") || ($bfg_tls_support eq "false" || ($bfg_tls_support eq "none"))} {
set bfg_tls_support 0
} else {
set bfg_tls_support 1
}
if {$bfg_tls_support eq 1} {
package require tls
}
} elseif {$bfg_tls_support eq "auto"} {
set bfg_tls_support 2
} else {set bfg_tls_support 1}
if {$bfg_tls_support ne 0} {package require tls}
# generate fonts
foreach fid {widget entry status text mono} {
@@ -157,11 +155,16 @@ proc trunc {s} {
# 4) close the connection
proc reqresp {host port reqline is_tls encoding} {
global bfg_response bfg_net_timeout
set sock 0
if {$is_tls eq 1} {
set sock [::tls::socket -autoservername true -async $host $port]
catch {set sock [::tls::socket -autoservername true -async $host $port]}
} elseif {$is_tls eq 2} {
catch {set sock [::tls::socket -autoservername true -async $host $port]}
if {$sock eq 0} {catch {set sock [socket -async $host $port]}}
} else {
set sock [socket -async $host $port]
catch {set sock [socket -async $host $port]}
}
if {$sock eq 0} {set bfg_response "Connection error"; return}
global rcv_end_$sock
unset -nocomplain rcv_end_$sock
if {$encoding eq ""} {set encoding utf-8}
@@ -426,7 +429,7 @@ proc urldl {inputurl isbinary} {
set bfg_response [string cat "3" $errmsg "\t-\t-\t-\r\n"]
}
return $scheme
} else {set is_tls 1}
} else {set is_tls $bfg_tls_support}
}
set encoding "utf-8"
if {$isbinary eq 1} {set encoding "binary"}