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
+5 -2
View File
@@ -36,6 +36,7 @@ The following features are already (fully or partially) supported in BFG.
* In-page text search
* Ini-based customization of the current Ttk theme, content fonts and colors
* Non-TLS mode for systems without TclTLS support
* Automatic TLS upgrade support for Gopher and other protocols (configurable in the `bfg.ini` file)
* Opening links in Torified windows (for the systems with torsocks installed)
## Non-supported features
@@ -117,7 +118,7 @@ You don't need to do any special combinations to open links in Tor once the pare
BFG ships with a `bfg.ini` file that holds your configuration values and bookmarks.
The main configuration sections are:
* `[net]`: network-related configs, currently has "timeout" parameter and an optional "tls" parameter
* `[net]`: network-related configs, currently has "timeout" parameter and an optional "tls" parameter (`auto` by default)
* `[widget]`: general UI widget appearance (ttkTheme, font (button font), entryfont, statusfont)
* `[style.general]`: general content area appearance (textfont, monofont\*, foreground color, background color)
* `[style.link.normal]`: normal link colors (foreground, background)
@@ -184,7 +185,9 @@ The [Scroll protocol](gemini://scrollprotocol.us.to/) is essentially advertised
### Why does a Gopher-over-TLS (`gophers://` URL) resource still show plain `gopher://` links?
Due to a purely technical limitation of the Gopher protocol (or rather the Gophermap format) itself, we cannot determine if a particular Gophermap entry points to a plain Gopher or a Gopher-over-TLS resource. Hence, only the links belonging to the same host/port pair that was already opened with a `gophers://` link are displayed as `gophers://` links. Everything else needs to be adjusted manually for now. Sorry for the inconvenience.
Due to a purely technical limitation of the Gopher protocol (or rather the Gophermap format) itself, we cannot determine if a particular Gophermap entry points to a plain Gopher or a Gopher-over-TLS resource. Hence, only the links belonging to the same host/port pair that was already opened with a `gophers://` link are displayed as `gophers://` links.
If the `tls` parameter in the `[net]` section of the `bfg.ini` file is set to `auto`, the client will try opening the TLS connection first regardless of the link type, so you don't have to worry about the URL scheme anymore..
### My system (or Tclkit) doesn't have TclTLS available, can I still use BFG for plaintext protocols?
+1 -1
View File
@@ -43,5 +43,5 @@ foreground=#111
[net]
timeout=5000
tls=on
tls=auto
+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"}