commit cb5c712

mooff  ·  2023-07-17 21:11:41 +0000 UTC
parent c9274aa
Support "ircs+insecure://" scheme for connection addr

This creates a TLS connection which will accept any remote certificate.

Which is dangerous, but can be handy in a pinch.

Besides, who am I, your mom?! 🙂
3 files changed,  +23, -11
M app.go
M app.go
+3, -2
 1@@ -405,8 +405,9 @@ func (app *App) tryConnect() (conn net.Conn, err error) {
 2 	if app.cfg.TLS {
 3 		host, _, _ := net.SplitHostPort(addr) // should succeed since net.Dial did.
 4 		conn = tls.Client(conn, &tls.Config{
 5-			ServerName: host,
 6-			NextProtos: []string{"irc"},
 7+			ServerName:         host,
 8+			InsecureSkipVerify: app.cfg.TLSSkipVerify,
 9+			NextProtos:         []string{"irc"},
10 		})
11 		err = conn.(*tls.Conn).HandshakeContext(ctx)
12 		if err != nil {
+12, -6
 1@@ -48,12 +48,14 @@ func parseColor(s string, c *tcell.Color) error {
 2 }
 3 
 4 type Config struct {
 5-	Addr     string
 6-	Nick     string
 7-	Real     string
 8-	User     string
 9-	Password *string
10-	TLS      bool
11+	Addr          string
12+	Nick          string
13+	Real          string
14+	User          string
15+	Password      *string
16+	TLS           bool
17+	TLSSkipVerify bool
18+
19 	Channels []string
20 
21 	Typings bool
22@@ -91,6 +93,7 @@ func Defaults() Config {
23 		User:             "",
24 		Password:         nil,
25 		TLS:              true,
26+		TLSSkipVerify:    false,
27 		Channels:         nil,
28 		Typings:          true,
29 		Mouse:            true,
30@@ -135,6 +138,9 @@ func LoadConfigFile(filename string) (cfg Config, err error) {
31 	}
32 	if u, err := url.Parse(cfg.Addr); err == nil && u.Scheme != "" {
33 		switch u.Scheme {
34+		case "ircs+insecure":
35+			cfg.TLS = true
36+			cfg.TLSSkipVerify = true
37 		case "ircs":
38 			cfg.TLS = true
39 		case "irc+insecure":
+8, -3
 1@@ -18,9 +18,14 @@ Some settings are required, the others are optional.
 2 	by default unless you specify *tls* option to be *false*. TLS connections
 3 	default to port 6697, plain-text use port 6667.
 4 
 5-	ircs:// & irc:// & irc+insecure:// URLs are supported, in which case only
 6-	the hostname and port parts will be used. If the scheme is
 7-	ircs/irc+insecure, tls will be overriden and set to true/false accordingly.
 8+	An optional scheme can be specified (scheme://_host[:port]_):
 9+
10+	- irc:// is the implicit default, TLS is enabled or disabled according to
11+	  the *tls* configuration value.
12+	- ircs:// enables TLS.
13+	- irc+insecure:// disables TLS (plain-text IRC).
14+	- ircs+insecure:// enables TLS but skips TLS certificate verification. This
15+	  protects against passive MITM attacks but not against active MITM attacks.
16 
17 *nickname* (required)
18 	Your nickname, sent with a _NICK_ IRC message. It mustn't contain spaces or