From c1e59a02f4889054b185088cb6ed79db9641251c Mon Sep 17 00:00:00 2001 From: Liam Stanley Date: Wed, 2 Jan 2019 10:33:29 -0500 Subject: [PATCH] add WebIRC support; closes #33 and #34 --- README.md | 2 ++ client.go | 37 +++++++++++++++++++++++++++++++++++++ conn.go | 5 +++++ constants.go | 1 + 4 files changed, 45 insertions(+) diff --git a/README.md b/README.md index ddc1193..35f3d81 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,8 @@ girc artwork licensed under [CC 3.0](http://creativecommons.org/licenses/by/3.0/ * [IRCv3: Specification Docs](http://ircv3.net/irc/) * [IRCv3: Specification Repo](https://github.com/ircv3/ircv3-specifications) * [IRCv3 Capability Registry](http://ircv3.net/registry.html) + * [IRCv3: WEBIRC](https://ircv3.net/specs/extensions/webirc.html) + * [KiwiIRC: WEBIRC](https://kiwiirc.com/docs/webirc) * [ISUPPORT Specification Docs](http://www.irc.org/tech_docs/005.html) ([alternative 1](http://defs.ircdocs.horse/defs/isupport.html), [alternative 2](https://github.com/grawity/irc-docs/blob/master/client/RPL_ISUPPORT/draft-hardy-irc-isupport-00.txt), [relevant draft](http://www.irc.org/tech_docs/draft-brocklesby-irc-isupport-03.txt)) * [IRC Numerics List](http://defs.ircdocs.horse/defs/numerics.html) * [Extended WHO (also known as WHOX)](https://github.com/quakenet/snircd/blob/master/doc/readme.who) diff --git a/client.go b/client.go index b526aeb..b8abb64 100644 --- a/client.go +++ b/client.go @@ -81,6 +81,10 @@ type Config struct { // supported. Capability tracking must be enabled for this to work, as // this requires IRCv3 CAP handling. SASL SASLMech + // WebIRC allows forwarding source user hostname/ip information to the server + // (if supported by the server) to ensure the source machine doesn't show as + // the source. See the WebIRC type for more information. + WebIRC WebIRC // Bind is used to bind to a specific host or ip during the dial process // when connecting to the server. This can be a hostname, however it must // resolve to an IPv4/IPv6 address bindable on your system. Otherwise, @@ -154,6 +158,39 @@ type Config struct { HandleNickCollide func(oldNick string) (newNick string) } +// WebIRC is useful when a user connects through an indirect method, such web +// clients, the indirect client sends its own IP address instead of sending the +// user's IP address unless WebIRC is implemented by both the client and the +// server. +// +// Client expectations: +// - Perform any proxy resolution. +// - Check the reverse DNS and forward DNS match. +// - Check the IP against suitable access controls (ipaccess, dnsbl, etc). +// +// More information: +// - https://ircv3.net/specs/extensions/webirc.html +// - https://kiwiirc.com/docs/webirc +type WebIRC struct { + // Password that authenticates the WEBIRC command from this client. + Password string + // Gateway or client type requesting spoof (cgiirc defaults to cgiirc, as an + // example). + Gateway string + // Hostname of user. + Hostname string + // Address either in IPv4 dotted quad notation (e.g. 192.0.0.2) or IPv6 + // notation (e.g. 1234:5678:9abc::def). IPv4-in-IPv6 addresses + // (e.g. ::ffff:192.0.0.2) should not be sent. + Address string +} + +// Params returns the arguments for the WEBIRC command that can be passed to the +// server. +func (w WebIRC) Params() []string { + return []string{w.Password, w.Gateway, w.Hostname, w.Address} +} + // ErrInvalidConfig is returned when the configuration passed to the client // is invalid. type ErrInvalidConfig struct { diff --git a/conn.go b/conn.go index 640a0b4..d057981 100644 --- a/conn.go +++ b/conn.go @@ -284,6 +284,11 @@ func (c *Client) internalConnect(mock net.Conn, dialer Dialer) error { go c.pingLoop(ctx, errs, &wg) // Passwords first. + + if c.Config.WebIRC.Password != "" { + c.write(&Event{Command: WEBIRC, Params: c.Config.WebIRC.Params(), Sensitive: true}) + } + if c.Config.ServerPass != "" { c.write(&Event{Command: PASS, Params: []string{c.Config.ServerPass}, Sensitive: true}) } diff --git a/constants.go b/constants.go index ddb48ea..ddea7d0 100644 --- a/constants.go +++ b/constants.go @@ -118,6 +118,7 @@ const ( USERS = "USERS" VERSION = "VERSION" WALLOPS = "WALLOPS" + WEBIRC = "WEBIRC" WHO = "WHO" WHOIS = "WHOIS" WHOWAS = "WHOWAS"