Kaynağa Gözat

allow WEBIRC to set the TLS flag over local plaintext connections

tags/v0.11.0-beta
Shivaram Lingamneni 6 yıl önce
ebeveyn
işleme
b7f66fb1de
2 değiştirilmiş dosya ile 16 ekleme ve 3 silme
  1. 5
    3
      irc/gateways.go
  2. 11
    0
      irc/utils/net.go

+ 5
- 3
irc/gateways.go Dosyayı Görüntüle

@@ -58,9 +58,11 @@ func webircHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
58 58
 				key = x
59 59
 			}
60 60
 
61
-			// only accept "tls" flag if the gateway's connection to us is secure as well
62
-			if strings.ToLower(key) == "tls" && client.flags[TLS] {
63
-				secure = true
61
+			if strings.ToLower(key) == "tls" {
62
+				// only accept "tls" flag if the gateway's connection to us is secure as well
63
+				if client.flags[TLS] || utils.AddrIsLocal(client.socket.conn.RemoteAddr()) {
64
+					secure = true
65
+				}
64 66
 			}
65 67
 		}
66 68
 	}

+ 11
- 0
irc/utils/net.go Dosyayı Görüntüle

@@ -25,6 +25,17 @@ func AddrLookupHostname(addr net.Addr) string {
25 25
 	return LookupHostname(IPString(addr))
26 26
 }
27 27
 
28
+// AddrIsLocal returns whether the address is from a trusted local connection (loopback or unix).
29
+func AddrIsLocal(addr net.Addr) bool {
30
+	if tcpaddr, ok := addr.(*net.TCPAddr); ok {
31
+		return tcpaddr.IP.IsLoopback()
32
+	}
33
+	if _, ok := addr.(*net.UnixAddr); ok {
34
+		return true
35
+	}
36
+	return false
37
+}
38
+
28 39
 // LookupHostname returns the hostname for `addr` if it has one. Otherwise, just returns `addr`.
29 40
 func LookupHostname(addr string) string {
30 41
 	names, err := net.LookupAddr(addr)

Loading…
İptal
Kaydet