From 7b35757bac05e14661cea03cf866812b0a6b1546 Mon Sep 17 00:00:00 2001 From: delthas Date: Mon, 27 Apr 2020 18:05:28 +0200 Subject: [PATCH] Add support for the irc+insecure address scheme Some servers do not support TLS, or have invalid, expired or self-signed TLS certificates. While the right fix would be toi contact each server owner to add support for valid TLS, supporting plaintext upstream connections is sometimes necessary. This adds support for the irc+insecure address scheme, which connects to a network in plain-text over TCP. --- doc/soju.1.scd | 1 + service.go | 4 ++-- upstream.go | 7 +++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/doc/soju.1.scd b/doc/soju.1.scd index 411266f..5f05429 100644 --- a/doc/soju.1.scd +++ b/doc/soju.1.scd @@ -97,6 +97,7 @@ abbreviated form, for instance *network* can be abbreviated as *net* or just _addr_ supports several connection types: - _[ircs://]host[:port]_ connects with TLS over TCP + - _irc+insecure://host[:port]_ connects with plain-text TCP Other options are: diff --git a/service.go b/service.go index 6df9fa9..fabec76 100644 --- a/service.go +++ b/service.go @@ -206,9 +206,9 @@ func handleServiceCreateNetwork(dc *downstreamConn, params []string) error { if addrParts := strings.SplitN(*addr, "://", 2); len(addrParts) == 2 { scheme := addrParts[0] switch scheme { - case "ircs": + case "ircs", "irc+insecure": default: - return fmt.Errorf("unknown scheme %q (supported schemes: ircs)", scheme) + return fmt.Errorf("unknown scheme %q (supported schemes: ircs, irc+insecure)", scheme) } } diff --git a/upstream.go b/upstream.go index 97c77fa..1020a99 100644 --- a/upstream.go +++ b/upstream.go @@ -90,6 +90,13 @@ func connectToUpstream(network *network) (*upstreamConn, error) { logger.Printf("connecting to TLS server at address %q", addr) netConn, err = tls.DialWithDialer(&dialer, "tcp", addr, nil) + case "irc+insecure": + if !strings.ContainsRune(addr, ':') { + addr = addr + ":6667" + } + + logger.Printf("connecting to plain-text server at address %q", addr) + netConn, err = dialer.Dial("tcp", addr) default: return nil, fmt.Errorf("failed to dial %q: unknown scheme: %v", addr, scheme) }