From 485fe73af6561b9666b902e04f6789a1ba12fb4e Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 11 Nov 2026 13:03:17 +0000 Subject: [PATCH] Serve SSL 2.0 and 3.0 clients through retrossl CONNECT's handshake now looks at the client's first bytes: SSL 2.0-format hellos and SSL 3.0-only hellos go to retrossl, everything else to Go's TLS. Ssl2 and Ssl3 in SslProtocols turn them on (SSL 3.0 is on by default), SslCipherSuites accepts retrossl's suite names, and the program allows the export suites' 512-bit keys. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01B82eRRH4kntyPfrY1bFWC3 --- README.md | 53 ++++++++++++++++++------- cmd/webone/main.go | 5 +++ go.mod | 2 + go.sum | 2 + internal/config/config.go | 2 +- internal/config/loader.go | 10 ++++- internal/proxy/connect.go | 26 ++++++------ internal/proxy/oldssl.go | 77 ++++++++++++++++++++++++++++++++++++ internal/proxy/proxy_test.go | 61 ++++++++++++++++++++++++++++ internal/proxy/server.go | 33 ++++++++++++---- webone.conf | 5 ++- 11 files changed, 235 insertions(+), 41 deletions(-) create mode 100644 internal/proxy/oldssl.go diff --git a/README.md b/README.md index c5db361..543edb8 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ own and are kept as upstream has them, except where noted: is changed, and about the security problems that brings.** * `webone.conf`, `codepage.conf`, `escargot.conf`: WebOne's configuration and sets of edits. `webone.conf` has the Go port's options added as - comments, and `SslProtocols` no longer lists SSL 2.0 and 3.0 (see below). + comments. * `html/` (internal and error pages, icons) and `logo.webp`. * `webone.service`, `webone.logrotate`. The service file drops the .NET-only `OPENSSL_CONF` line and gains a note about running as the BBS's user. @@ -69,8 +69,10 @@ What works: DOS, Mac, ISO and KOI8 code pages are included, as are UTF-16 and the CJK ones. * The HTTPS proxy (CONNECT): man-in-the-middle with a per-site - certificate, pass-through (`[ConnectPassThrough]`), non-HTTP tunnels - (`[NonHttpSslServers]`, `[NonHttpConnectRedirect]`) and `[NonHttpSslDecrypt]`. + certificate, for clients from SSL 2.0 to TLS 1.3 (see *Old SSL + clients*), pass-through (`[ConnectPassThrough]`), non-HTTP tunnels + (`[NonHttpSslServers]`, `[NonHttpConnectRedirect]`) and + `[NonHttpSslDecrypt]`. * The CA: made on first start, or `--rebuild-ca`. MD5, SHA-1 or SHA-2 signatures. External generators (`SslSiteCerts`, `SslSiteCertGenerator`). `/!ca` and `/weboneca.pem` serve the CA certificate. @@ -124,22 +126,40 @@ by the user in its `[general]` section. Either run the proxy as that user shared group), plus search access to `ca/`. The proxy says plainly when it cannot read them. +SSL 2.0 sends only the site's own certificate, not the sub-CA after it. So +callers whose browsers speak only SSL 2.0 must install `ca/proxy-ca.crt` as +well as the root. + `SslTrustOwnCA=yes` makes the proxy also trust that CA when it fetches pages itself. Use it for sites the BBS serves under its own CA. +## Old SSL clients + +Go's own TLS starts at TLS 1.0 and does not accept an SSL 2.0-format hello. +For those clients, the CONNECT/MITM mode uses +[retrossl](https://github.com/D-Modem/retrossl), D-Modem's SSL 2.0, SSL 3.0 +and TLS 1.0 server. The proxy looks at each client's first bytes: + +* An SSL 2.0-format hello (Netscape 1 to 4, IE 2 to 6, AIM, early Opera), or + a hello that offers SSL 3.0 at best, goes to retrossl. +* Everything else goes to Go's TLS, as before. + +`SslProtocols` decides what is served: `Ssl2` and `Ssl3` turn on SSL 2.0 and +3.0, and `Tls` turns on TLS 1.0, for both servers. Without `SslProtocols`, +SSL 3.0 and TLS 1.0 to 1.3 are on, and SSL 2.0 is off. `SslCipherSuites` +also accepts retrossl's suite names, such as `TLS_RSA_EXPORT_WITH_RC4_40_MD5`. + +retrossl offers AES, 3DES, RC4 and DES, and the 40- and 56-bit export suites +for export builds of old browsers. Site certificates must have RSA keys, +which the proxy's do. These protocols are easy to break, so the traffic +between an old browser and the proxy should be treated as readable. Clients +that use the plain HTTP proxy instead are not affected: the browser asks for +`http://`, and the proxy fetches over modern HTTPS. + ## Differences from WebOne ### Not available in Go -* **No SSL 2.0 or 3.0, and no SSLv2-format hello.** Go's TLS starts at - TLS 1.0. Browsers that only speak SSL (Netscape 1 to 4, IE 2 to 5 with its - defaults) cannot use the CONNECT/MITM mode. They work fine through the - plain HTTP proxy, which is WebOne's main mode anyway: the browser asks for - `http://`, and the proxy does the HTTPS. `Ssl2` and `Ssl3` in - `SslProtocols` are ignored with a warning. Clients that need TLS 1.0 with - old ciphers (IE 6 to 8 on XP) do work: all of Go's suites, the weak ones - included, are offered unless `SslCipherSuites` says otherwise. Supporting - SSL 3.0 is a possible follow-up. * `UseMsHttpApi` (Windows' HTTP.sys server) does not exist here. It is ignored with a warning, and the proxy always uses its own server, as WebOne does by default. @@ -196,6 +216,9 @@ These are bugs or rough edges in WebOne 0.19.0 that the port does not copy: | `SslTrustOwnCA` | `[SecureProxy]` | trust the proxy's CA for fetched sites too | | `DnsServer` | `[Server]` | look sites up through this DNS server (`host` or `host:port`) | +`SslProtocols` and `SslCipherSuites` work as in WebOne, with SSL 2.0 and 3.0 +served by retrossl (above). + The version is reported as `0.19.0-go`. ## Layout @@ -203,7 +226,7 @@ The version is reported as `0.19.0-go`. ``` cmd/webone the program: command line, CA loading, start-up internal/config webone.conf: loading, [Include:], variables, sets of edits -internal/proxy the server, request handling, CONNECT, internal pages, FTP, video +internal/proxy the server, request handling, CONNECT (old SSL through retrossl), internal pages, FTP, video internal/certs the CA, site certificates (MD5/SHA-1 signing), the BBS's CA internal/textenc code pages internal/rx .NET-style regular expressions, cached @@ -213,8 +236,8 @@ internal/logx the log, in WebOne's format `go test ./...` covers configuration parsing, edit sets, code pages, the certificates (including a BBS-style sub-CA chain), and the proxy end to end: HTTP/1.0 with edits and a code page, HTTPS fetching, alternate mode, -keep-alive with chunked replies, internal pages, CONNECT with MITM, and -pass-through. +keep-alive with chunked replies, internal pages, CONNECT with MITM (SSL +2.0 and 3.0 clients included), and pass-through. retrossl has its own tests. ## Licence diff --git a/cmd/webone/main.go b/cmd/webone/main.go index 6d6e292..b5e6a73 100644 --- a/cmd/webone/main.go +++ b/cmd/webone/main.go @@ -4,6 +4,11 @@ // webone [config file] [port] [-cfg file] [-l logfile|no] [-p port] // [-h hostname] [-t tempdir] [-a user:pass] [--dump [file]] // [--rebuild-ca] [--daemon] [--help] +// +// The export cipher suites that old SSL clients use need 512-bit RSA keys, +// which Go allows only with the setting below. +// +//go:debug rsa1024min=0 package main import ( diff --git a/go.mod b/go.mod index f83c563..57c4464 100644 --- a/go.mod +++ b/go.mod @@ -6,3 +6,5 @@ require ( github.com/dlclark/regexp2 v1.12.0 golang.org/x/text v0.44.0 ) + +require github.com/D-Modem/retrossl v0.0.0-20261111130219-1b844ee3e801 diff --git a/go.sum b/go.sum index 452339f..9c98fdb 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/D-Modem/retrossl v0.0.0-20261111130219-1b844ee3e801 h1:QsbvUo6CAawdQTChTwd5wFMS7g2bYMoVL6d1OxnLFdI= +github.com/D-Modem/retrossl v0.0.0-20261111130219-1b844ee3e801/go.mod h1:+/qpHsaYk4DslA351ZMumscq9/Iwl/K5vS4PhUVLOR8= github.com/dlclark/regexp2 v1.12.0 h1:0j4c5qQmnC6XOWNjP3PIXURXN2gWx76rd3KvgdPkCz8= github.com/dlclark/regexp2 v1.12.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= golang.org/x/text v0.44.0 h1:YItdp/mQNGnsmrgpcdA5yQ3bnRxCfo/Tj/iByGW9GGo= diff --git a/internal/config/config.go b/internal/config/config.go index 5626dbf..234037f 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -106,7 +106,7 @@ type Config struct { SslEnable bool SslCertificate string SslPrivateKey string - SslProtocols []uint16 // TLS versions for clients + SslProtocols []uint16 // versions for clients; SSL 2.0 and 3.0 are retrossl's SslProtocolsSet bool SslCipherSuites []uint16 SslHashAlgorithm string // MD5, SHA1, SHA256, SHA384, SHA512 diff --git a/internal/config/loader.go b/internal/config/loader.go index 2f8f368..944645c 100644 --- a/internal/config/loader.go +++ b/internal/config/loader.go @@ -13,6 +13,7 @@ import ( "strings" "time" + "github.com/D-Modem/retrossl" "github.com/D-Modem/webone-go/internal/logx" "github.com/D-Modem/webone-go/internal/rx" "github.com/D-Modem/webone-go/internal/textenc" @@ -539,8 +540,10 @@ func (c *Config) secureOption(o Option) { switch p { case "", "none", "default": c.SslProtocolsSet = p == "" && c.SslProtocolsSet - case "ssl2", "ssl3": - c.warn("%s is not available in this version (Go's TLS has no SSL 2.0/3.0), at %s.", p, o.Location) + case "ssl2": // served by retrossl + c.SslProtocols = append(c.SslProtocols, retrossl.VersionSSL20) + case "ssl3": + c.SslProtocols = append(c.SslProtocols, retrossl.VersionSSL30) default: if v, ok := tlsVersionNames[p]; ok { c.SslProtocols = append(c.SslProtocols, v) @@ -560,6 +563,9 @@ func (c *Config) secureOption(o Option) { for _, cs := range tls.InsecureCipherSuites() { names[cs.Name] = cs.ID } + for _, cs := range retrossl.CipherSuites() { // SSL 3.0's DES and export suites + names[cs.Name] = cs.ID + } // .NET's names for the TLS 1.3 suites and others are the IANA ones for _, n := range strings.Split(o.Value, ",") { n = strings.TrimSpace(n) diff --git a/internal/proxy/connect.go b/internal/proxy/connect.go index 380140a..2bcabe9 100644 --- a/internal/proxy/connect.go +++ b/internal/proxy/connect.go @@ -10,8 +10,8 @@ import ( "strconv" "strings" "sync" - "time" + "github.com/D-Modem/retrossl" "github.com/D-Modem/webone-go/internal/logx" "github.com/D-Modem/webone-go/internal/rx" ) @@ -96,24 +96,21 @@ func (t *transit) connectSecure() { return } host := t.req.RawURL[:strings.LastIndexByte(t.req.RawURL, ':')] - cfg, err := t.s.tlsFor(host) + cfg, rc, err := t.s.tlsFor(host) if err != nil { t.log.Printf(" Cannot made SSL connection: %v", err) t.sendError(501, "Sorry, an error occured on creating client SSL tunnel: "+err.Error()) return } c := t.established(true) - tc := tls.Server(c, cfg) - tc.SetDeadline(time.Now().Add(time.Minute)) - if err := tc.Handshake(); err != nil { + tc, agreed, err := t.s.serveSecure(c, cfg, rc) + if err != nil { t.log.Printf("!SSL Handshake failed: %s", handshakeError(err)) c.Close() return } - tc.SetDeadline(time.Time{}) - st := tc.ConnectionState() log := logx.New() - log.Printf(">SSL %s: %s with %s", host, tls.VersionName(st.Version), tls.CipherSuiteName(st.CipherSuite)) + log.Printf(">SSL %s: %s", host, agreed) t.s.handleConn(tc, bufio.NewReaderSize(tc, 16*1024), true, host, log) tc.Close() log.Printf(" 0 { + rc.CipherSuites = []uint16{} + for _, cs := range retrossl.CipherSuites() { + if slices.Contains(s.cfg.SslCipherSuites, cs.ID) { + rc.CipherSuites = append(rc.CipherSuites, cs.ID) + } + } + } + return rc +} + +// serveSecure runs the handshake with a client that CONNECTed, by Go's TLS +// or, for old clients, retrossl. It gives the secure connection and what +// was agreed, for the log. +func (s *Server) serveSecure(c net.Conn, tc *tls.Config, rc *retrossl.Config) (net.Conn, string, error) { + c.SetDeadline(time.Now().Add(time.Minute)) + var sc net.Conn + switch { + case rc == nil: + sc = tls.Server(c, tc) + case s.noGoTLS: + sc = retrossl.Server(c, rc) + default: + var err error + if sc, err = retrossl.Frontend(c, tc, rc); err != nil { + return nil, "", err + } + } + var desc string + switch sc := sc.(type) { + case *tls.Conn: + if err := sc.Handshake(); err != nil { + return nil, "", err + } + st := sc.ConnectionState() + desc = tls.VersionName(st.Version) + " with " + tls.CipherSuiteName(st.CipherSuite) + case *retrossl.Conn: + if err := sc.Handshake(); err != nil { + return nil, "", err + } + st := sc.ConnectionState() + desc = retrossl.VersionName(st.Version) + " with " + st.CipherName + } + c.SetDeadline(time.Time{}) + return sc, desc, nil +} diff --git a/internal/proxy/proxy_test.go b/internal/proxy/proxy_test.go index 9f1acf4..febd112 100644 --- a/internal/proxy/proxy_test.go +++ b/internal/proxy/proxy_test.go @@ -2,6 +2,7 @@ package proxy import ( "bufio" + "bytes" "crypto/tls" "crypto/x509" "fmt" @@ -301,3 +302,63 @@ func TestActivexVersions(t *testing.T) { t.Error("one-part version accepted") } } + +// connectTunnel CONNECTs to site.invalid:443 through the proxy. +func connectTunnel(t *testing.T, addr string) (net.Conn, *bufio.Reader) { + t.Helper() + c, err := net.Dial("tcp", addr) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { c.Close() }) + c.SetDeadline(time.Now().Add(20 * time.Second)) + fmt.Fprint(c, "CONNECT site.invalid:443 HTTP/1.0\r\n\r\n") + br := bufio.NewReader(c) + if line, _ := br.ReadString('\n'); !strings.HasPrefix(line, "HTTP/1.1 200") { + t.Fatalf("CONNECT reply: %q", line) + } + for { + if l, err := br.ReadString('\n'); err != nil || l == "\r\n" { + break + } + } + return c, br +} + +// TestConnectOldSSL: SSL 3.0 and SSL 2.0 clients reach retrossl. +func TestConnectOldSSL(t *testing.T) { + ssl3Hello := func() []byte { + body := append([]byte{3, 0}, make([]byte, 32)...) + body = append(body, 0, 0, 2, 0x00, 0x2f, 1, 0) + m := append([]byte{1, 0, byte(len(body) >> 8), byte(len(body))}, body...) + return append([]byte{0x16, 3, 0, byte(len(m) >> 8), byte(len(m))}, m...) + }() + ssl2Hello := func() []byte { + m := []byte{1, 0, 2, 0, 3, 0, 0, 0, 16, 0x01, 0x00, 0x80} + m = append(m, make([]byte, 16)...) + return append([]byte{0x80, byte(len(m))}, m...) + }() + for _, c := range []struct { + name, conf string + hello []byte + want []byte // the reply's first bytes, after any record header + header int + }{ + {"SSL3", "", ssl3Hello, []byte{0x16, 3, 0}, 0}, + {"SSL2", "SslProtocols=Ssl2, Ssl3, Tls, Tls11, Tls12\n", ssl2Hello, []byte{4, 0, 1, 0, 2}, 2}, + {"SSL2off", "", ssl2Hello, []byte{0, 0, 1}, 2}, // NO-CIPHER-ERROR + } { + t.Run(c.name, func(t *testing.T) { + addr, _ := startProxy(t, "[SecureProxy]\nSslHashAlgorithm=SHA1\n"+c.conf) + conn, br := connectTunnel(t, addr) + conn.Write(c.hello) + got := make([]byte, c.header+len(c.want)) + if _, err := io.ReadFull(br, got); err != nil { + t.Fatal(err) + } + if !bytes.Equal(got[c.header:], c.want) { + t.Errorf("reply %x", got) + } + }) + } +} diff --git a/internal/proxy/server.go b/internal/proxy/server.go index a727cda..4c91eba 100644 --- a/internal/proxy/server.go +++ b/internal/proxy/server.go @@ -22,6 +22,7 @@ import ( "sync/atomic" "time" + "github.com/D-Modem/retrossl" "github.com/D-Modem/webone-go/internal/certs" "github.com/D-Modem/webone-go/internal/config" "github.com/D-Modem/webone-go/internal/logx" @@ -58,8 +59,10 @@ type Server struct { lastCode int lastContentType string - clientTLS *tls.Config - started time.Time + clientTLS *tls.Config + clientRetro *retrossl.Config // nil: no SSL 2.0, SSL 3.0 or SSLv2-format hellos + noGoTLS bool // SslProtocols has only SSL 2.0 and 3.0 + started time.Time } // New makes a server for a loaded configuration. ca may be nil (HTTPS off). @@ -93,6 +96,7 @@ func New(cfg *config.Config, ca, root *certs.CA) (*Server, error) { Log: func(f string, a ...any) { logx.Std.Printf(f, a...) }, } s.clientTLS = s.makeClientTLS() + s.clientRetro = s.makeClientRetro() } var extraRoots []*x509.Certificate if cfg.SslTrustOwnCA && s.RootCA != nil { @@ -125,9 +129,15 @@ func (s *Server) makeClientTLS() *tls.Config { if s.cfg.SslProtocolsSet && len(s.cfg.SslProtocols) > 0 { lo, hi := uint16(0xffff), uint16(0) for _, v := range s.cfg.SslProtocols { - lo, hi = min(lo, v), max(hi, v) + if v >= tls.VersionTLS10 { // SSL 2.0 and 3.0 are retrossl's + lo, hi = min(lo, v), max(hi, v) + } + } + if hi != 0 { + c.MinVersion, c.MaxVersion = lo, hi + } else { + s.noGoTLS = true } - c.MinVersion, c.MaxVersion = lo, hi } if len(s.cfg.SslCipherSuites) > 0 { c.CipherSuites = s.cfg.SslCipherSuites @@ -144,16 +154,23 @@ func (s *Server) makeClientTLS() *tls.Config { return c } -// tlsFor is the TLS configuration that presents host's certificate. -func (s *Server) tlsFor(host string) (*tls.Config, error) { +// tlsFor is the TLS configuration that presents host's certificate, +// with retrossl's for old clients (nil when they are off). +func (s *Server) tlsFor(host string) (*tls.Config, *retrossl.Config, error) { cert, err := s.issuer.Get(host) if err != nil { - return nil, err + return nil, nil, err } c := s.clientTLS.Clone() c.GetCertificate = nil c.Certificates = []tls.Certificate{*cert} - return c, nil + var rc *retrossl.Config + if s.clientRetro != nil { + r := *s.clientRetro + r.GetCertificate = func(*tls.ClientHelloInfo) (*tls.Certificate, error) { return cert, nil } + rc = &r + } + return c, rc, nil } // ListenAndServe listens on the configured address and serves until Stop. diff --git a/webone.conf b/webone.conf index eb504b8..07d794f 100644 --- a/webone.conf +++ b/webone.conf @@ -83,11 +83,12 @@ ContentDirectory=/html ; AllowNonHttpsCONNECT=Allow use HTTPS proxy tunnel (CONNECT method) with non-HTTPS protocols ; SslCaDirectory=(Go port) Sign with the D-Modem BBS's CA: its ca/ directory (proxy-ca.crt/.key from "bbs ca subca proxy") ; SslTrustOwnCA=(Go port) Also trust the proxy's CA for sites it fetches (the BBS's own HTTPS servers) -; (The Go port has no SSL 2.0 or 3.0: Go's TLS starts at TLS 1.0.) +; (In the Go port, SSL 2.0, SSL 3.0 and SSL 2.0-format hellos are served by +; retrossl, with the export cipher suites. Leave Ssl2 out to turn SSL 2.0 off.) SslEnable=yes SslCertificate=%WOConfigDir%/ssl.crt SslPrivateKey=%WOConfigDir%/ssl.key -SslProtocols=Tls, Tls11, Tls12 +SslProtocols=Ssl2, Ssl3, Tls, Tls11, Tls12 ;SslCipherSuites=TLS_RSA_WITH_NULL_MD5, TLS_RSA_WITH_RC4_128_MD5, TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_3DES_EDE_CBC_SHA SslRootValidAfter=2019-05-20 00:00:00+0 SslRootValidBefore=2037-12-31 23:59:59+0