From 8577ec00e6f81737d686cb48b376c196832388b8 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 25 Nov 2026 23:36:19 +0000 Subject: [PATCH] feature/upki, net/tlsdial: reject certs revoked per local upki cache upki (github.com/rustls/upki, shipping in Ubuntu 26.10+) keeps a local CRLite revocation cache that "upki fetch" refreshes on a timer. Add an omittable "upki" feature that, after tlsdial's x509 verification succeeds, checks the leaf against that cache if one is present and rejects it if revoked. Missing caches, uncovered certs, and cache read errors all fail open. The cache is read with github.com/cpu/go-upki, the prototype for the built-in crypto/tls support proposed in golang/go#82402. That built-in check wouldn't cover us even once it ships, because crypto/tls skips it when InsecureSkipVerify is set, and tlsdial always sets that so it can do its own verification in VerifyConnection. Updates #22680 Signed-off-by: Brad Fitzpatrick Change-Id: Idfa75794cbba9c90039355ffaeb21b5d5824a5fe --- cmd/tailscaled/depaware.txt | 4 + cmd/tailscaled/deps_test.go | 13 ++ .../buildfeatures/feature_upki_disabled.go | 13 ++ feature/buildfeatures/feature_upki_enabled.go | 13 ++ feature/condregister/maybe_upki.go | 8 + feature/featuretags/featuretags.go | 4 + feature/upki/upki.go | 140 ++++++++++++++++++ feature/upki/upki_test.go | 62 ++++++++ flake.nix | 2 +- flakehashes.json | 4 +- go.mod | 1 + go.sum | 2 + net/tlsdial/revocation_test.go | 123 +++++++++++++++ net/tlsdial/tlsdial.go | 47 ++++-- shell.nix | 2 +- 15 files changed, 421 insertions(+), 17 deletions(-) create mode 100644 feature/buildfeatures/feature_upki_disabled.go create mode 100644 feature/buildfeatures/feature_upki_enabled.go create mode 100644 feature/condregister/maybe_upki.go create mode 100644 feature/upki/upki.go create mode 100644 feature/upki/upki_test.go create mode 100644 net/tlsdial/revocation_test.go diff --git a/cmd/tailscaled/depaware.txt b/cmd/tailscaled/depaware.txt index e1cba0bd0..3788cabaa 100644 --- a/cmd/tailscaled/depaware.txt +++ b/cmd/tailscaled/depaware.txt @@ -99,6 +99,9 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de github.com/coder/websocket/internal/errd from github.com/coder/websocket github.com/coder/websocket/internal/util from github.com/coder/websocket L github.com/coreos/go-iptables/iptables from tailscale.com/util/linuxfw + L github.com/cpu/go-upki/crlite from github.com/cpu/go-upki/upki + L github.com/cpu/go-upki/internal from github.com/cpu/go-upki/crlite+ + L github.com/cpu/go-upki/upki from tailscale.com/feature/upki github.com/creachadair/msync/trigger from tailscale.com/logtail LD 💣 github.com/creack/pty from tailscale.com/ssh/tailssh W 💣 github.com/dblohm7/wingoes from github.com/dblohm7/wingoes/com+ @@ -340,6 +343,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de L tailscale.com/feature/tap from tailscale.com/feature/condregister tailscale.com/feature/tpm from tailscale.com/feature/condregister L 💣 tailscale.com/feature/tundevstats from tailscale.com/feature/condregister + L tailscale.com/feature/upki from tailscale.com/feature/condregister tailscale.com/feature/useproxy from tailscale.com/feature/condregister/useproxy tailscale.com/feature/wakeonlan from tailscale.com/feature/condregister tailscale.com/health from tailscale.com/control/controlclient+ diff --git a/cmd/tailscaled/deps_test.go b/cmd/tailscaled/deps_test.go index 622eee7d3..3e4fbbf29 100644 --- a/cmd/tailscaled/deps_test.go +++ b/cmd/tailscaled/deps_test.go @@ -35,6 +35,19 @@ func TestOmitFavorites(t *testing.T) { }.Check(t) } +func TestOmitUPKI(t *testing.T) { + const msg = "unexpected with ts_omit_upki" + deptest.DepChecker{ + GOOS: "linux", + GOARCH: "amd64", + Tags: "ts_omit_upki,ts_include_cli", + BadDeps: map[string]string{ + "tailscale.com/feature/upki": msg, + "github.com/cpu/go-upki/upki": msg, + }, + }.Check(t) +} + func TestOmitSSH(t *testing.T) { const msg = "unexpected with ts_omit_ssh" deptest.DepChecker{ diff --git a/feature/buildfeatures/feature_upki_disabled.go b/feature/buildfeatures/feature_upki_disabled.go new file mode 100644 index 000000000..4e8ab70b4 --- /dev/null +++ b/feature/buildfeatures/feature_upki_disabled.go @@ -0,0 +1,13 @@ +// Copyright (c) Tailscale Inc & contributors +// SPDX-License-Identifier: BSD-3-Clause + +// Code generated by gen.go; DO NOT EDIT. + +//go:build ts_omit_upki + +package buildfeatures + +// HasUPKI is whether the binary was built with support for modular feature "Reject TLS server certs revoked according to a local upki (CRLite) revocation cache, if present". +// Specifically, it's whether the binary was NOT built with the "ts_omit_upki" build tag. +// It's a const so it can be used for dead code elimination. +const HasUPKI = false diff --git a/feature/buildfeatures/feature_upki_enabled.go b/feature/buildfeatures/feature_upki_enabled.go new file mode 100644 index 000000000..3c4e47f87 --- /dev/null +++ b/feature/buildfeatures/feature_upki_enabled.go @@ -0,0 +1,13 @@ +// Copyright (c) Tailscale Inc & contributors +// SPDX-License-Identifier: BSD-3-Clause + +// Code generated by gen.go; DO NOT EDIT. + +//go:build !ts_omit_upki + +package buildfeatures + +// HasUPKI is whether the binary was built with support for modular feature "Reject TLS server certs revoked according to a local upki (CRLite) revocation cache, if present". +// Specifically, it's whether the binary was NOT built with the "ts_omit_upki" build tag. +// It's a const so it can be used for dead code elimination. +const HasUPKI = true diff --git a/feature/condregister/maybe_upki.go b/feature/condregister/maybe_upki.go new file mode 100644 index 000000000..385af1d86 --- /dev/null +++ b/feature/condregister/maybe_upki.go @@ -0,0 +1,8 @@ +// Copyright (c) Tailscale Inc & contributors +// SPDX-License-Identifier: BSD-3-Clause + +//go:build ((linux && !android) || freebsd || openbsd) && !ts_omit_upki + +package condregister + +import _ "tailscale.com/feature/upki" diff --git a/feature/featuretags/featuretags.go b/feature/featuretags/featuretags.go index 6f41ef7d0..8b7494013 100644 --- a/feature/featuretags/featuretags.go +++ b/feature/featuretags/featuretags.go @@ -355,6 +355,10 @@ var Features = map[FeatureTag]FeatureMeta{ Sym: "UnixSocketIdentity", Desc: "differentiate between users accessing the LocalAPI over unix sockets (if omitted, all users have full access)", }, + "upki": { + Sym: "UPKI", + Desc: "Reject TLS server certs revoked according to a local upki (CRLite) revocation cache, if present", + }, "useroutes": { Sym: "UseRoutes", Desc: "Use routes advertised by other nodes", diff --git a/feature/upki/upki.go b/feature/upki/upki.go new file mode 100644 index 000000000..76848f1a0 --- /dev/null +++ b/feature/upki/upki.go @@ -0,0 +1,140 @@ +// Copyright (c) Tailscale Inc & contributors +// SPDX-License-Identifier: BSD-3-Clause + +// Package upki rejects TLS server certificates that are revoked according to +// a local upki revocation cache, if one is present. +// +// upki (https://github.com/rustls/upki) keeps CRLite revocation filters in a +// local cache directory (see https://c2sp.org/upki-revocation), refreshed in +// the background by "upki fetch". This package only reads that cache; it +// never downloads anything. If no cache is found, or the cache doesn't cover +// a certificate, connections proceed as they would without this package. +package upki + +import ( + "crypto/x509" + "errors" + "fmt" + "io/fs" + "log" + "os" + "path/filepath" + "runtime" + "sync" + "time" + + "github.com/cpu/go-upki/upki" + "tailscale.com/feature" + "tailscale.com/net/tlsdial" +) + +func init() { + if !feature.Register("upki") { + return + } + tlsdial.HookCheckRevocation.Set(checkRevocation) +} + +// indexFile is the name of the index file that upki publishes atomically +// into a revocation cache directory once the filters it names are in place. +const indexFile = "index.bin" + +// cacheDirs returns the candidate upki revocation cache directories, in +// order of preference: the user cache first, then the system cache. It's a +// variable for tests. +var cacheDirs = func() []string { + var dirs []string + userCache, _ := os.UserCacheDir() + switch runtime.GOOS { + case "windows": + if userCache != "" { + dirs = append(dirs, filepath.Join(userCache, "rustls", "upki", "cache", "revocation")) + } + if pd := os.Getenv("ProgramData"); pd != "" { + dirs = append(dirs, filepath.Join(pd, "rustls", "upki", "cache", "revocation")) + } + case "darwin", "ios": + if userCache != "" { + dirs = append(dirs, filepath.Join(userCache, "dev.rustls.upki", "revocation")) + } + dirs = append(dirs, "/Library/Caches/dev.rustls.upki/revocation") + default: + if userCache != "" { + dirs = append(dirs, filepath.Join(userCache, "upki", "revocation")) + } + dirs = append(dirs, "/var/cache/upki/revocation") + } + return dirs +} + +// findCacheDir returns the first directory from [cacheDirs] that contains a +// published index, or "" if there is none. +// +// A directory without an index is skipped rather than selected, so a cache +// that has been created but not yet populated by its first fetch doesn't +// shadow a populated one, and isn't treated as an error. +func findCacheDir() string { + for _, dir := range cacheDirs() { + if fi, err := os.Stat(filepath.Join(dir, indexFile)); err == nil && fi.Mode().IsRegular() { + return dir + } + } + return "" +} + +// checkRevocation implements [tlsdial.HookCheckRevocation]. +// +// It rejects only certificates that the cache says are revoked. Certificates +// the cache doesn't cover (private CAs, certificates without embedded SCTs, +// or logs not yet in the filters) are allowed, and so is everything if no +// cache is present. Errors reading the cache are logged and the connection +// is allowed: a local user able to corrupt the cache could equally delete +// it, and failing closed would cut a node off from its control server +// because of a bad local file. +func checkRevocation(dnsName string, chain []*x509.Certificate) error { + dir := findCacheDir() + if dir == "" { + return nil + } + // The checker is cheap to open (it reads only the index header and log + // table), and opening it fresh each time picks up new data from upki's + // periodic fetches without needing to watch the directory. + opener := upki.DirOpener{Dir: dir} + checker, err := upki.NewCheckerWith(opener, opener) + if err != nil { + if !errors.Is(err, fs.ErrNotExist) { // lost a race with a cache update + logError(dir, err) + } + return nil + } + defer checker.Close() + + status, err := checker.Check(chain) + if err != nil { + logError(dir, err) + return nil + } + if status == upki.StatusRevoked { + leaf := chain[0] + log.Printf("upki: certificate for %q (serial %x, issuer %q) is revoked according to %s", dnsName, leaf.SerialNumber, leaf.Issuer, dir) + return fmt.Errorf("certificate for %q is revoked according to upki cache %s", dnsName, dir) + } + return nil +} + +var ( + logMu sync.Mutex + lastLogged time.Time // last time logError wrote a log line +) + +// logError logs an error reading the upki cache at dir, at most once per +// hour. +func logError(dir string, err error) { + logMu.Lock() + defer logMu.Unlock() + if !lastLogged.IsZero() && time.Since(lastLogged) < time.Hour { + return + } + lastLogged = time.Now() + log.Printf("upki: ignoring error checking revocation using %s: %v", dir, err) +} diff --git a/feature/upki/upki_test.go b/feature/upki/upki_test.go new file mode 100644 index 000000000..75d540373 --- /dev/null +++ b/feature/upki/upki_test.go @@ -0,0 +1,62 @@ +// Copyright (c) Tailscale Inc & contributors +// SPDX-License-Identifier: BSD-3-Clause + +package upki + +import ( + "crypto/x509" + "os" + "path/filepath" + "testing" +) + +func setCacheDirsForTest(t *testing.T, dirs ...string) { + old := cacheDirs + cacheDirs = func() []string { return dirs } + t.Cleanup(func() { cacheDirs = old }) +} + +func TestFindCacheDir(t *testing.T) { + tmp := t.TempDir() + missing := filepath.Join(tmp, "missing") + empty := filepath.Join(tmp, "empty") // created but never fetched into + populated := filepath.Join(tmp, "populated") + for _, d := range []string{empty, populated} { + if err := os.Mkdir(d, 0o755); err != nil { + t.Fatal(err) + } + } + if err := os.WriteFile(filepath.Join(populated, indexFile), nil, 0o644); err != nil { + t.Fatal(err) + } + + setCacheDirsForTest(t, missing, empty) + if got := findCacheDir(); got != "" { + t.Errorf("findCacheDir with no index = %q; want empty", got) + } + + setCacheDirsForTest(t, missing, empty, populated) + if got := findCacheDir(); got != populated { + t.Errorf("findCacheDir = %q; want %q", got, populated) + } +} + +func TestCheckRevocationFailsOpen(t *testing.T) { + // The certificates are never parsed when there's no usable cache, so + // empty ones suffice. + chain := []*x509.Certificate{{}, {}} + + setCacheDirsForTest(t, filepath.Join(t.TempDir(), "missing")) + if err := checkRevocation("example.com", chain); err != nil { + t.Errorf("no cache: got %v; want nil", err) + } + + corrupt := t.TempDir() + if err := os.WriteFile(filepath.Join(corrupt, indexFile), []byte("not an index"), 0o644); err != nil { + t.Fatal(err) + } + setCacheDirsForTest(t, corrupt) + if err := checkRevocation("example.com", chain); err != nil { + t.Errorf("corrupt index: got %v; want nil", err) + } +} diff --git a/flake.nix b/flake.nix index 57b5f6fd0..0822706c7 100644 --- a/flake.nix +++ b/flake.nix @@ -172,4 +172,4 @@ }); }; } -# nix-direnv cache busting line: sha256-CEZxW9kZUIjI3frTZOEKssYJz3Uo58+YdLm8iEjTeMo= +# nix-direnv cache busting line: sha256-EUjRAWRCI6FfXRis4AyX4+9EPDrWPpVk6eYQKAwJ+H8= diff --git a/flakehashes.json b/flakehashes.json index e10451e2b..d4a911972 100644 --- a/flakehashes.json +++ b/flakehashes.json @@ -4,7 +4,7 @@ "sri": "sha256-Qmy06FkeFkjqCo1FLSD9dO7hTvdo/gC2VACJniuiQBU=" }, "vendor": { - "goModSum": "sha256-BxqNT0K8QLic7/KKqLBjZIRre3sTzzm/4CUCuNgBMaw=", - "sri": "sha256-CEZxW9kZUIjI3frTZOEKssYJz3Uo58+YdLm8iEjTeMo=" + "goModSum": "sha256-v8gQjz+FrrPgj56rsF/MNBZ8omppcGcPyA4gDRhzph0=", + "sri": "sha256-EUjRAWRCI6FfXRis4AyX4+9EPDrWPpVk6eYQKAwJ+H8=" } } diff --git a/go.mod b/go.mod index be33615d6..98d8c290d 100644 --- a/go.mod +++ b/go.mod @@ -31,6 +31,7 @@ require ( github.com/coder/websocket v1.8.15 github.com/coreos/go-iptables v0.8.0 github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf + github.com/cpu/go-upki v0.0.0-20261112150031-bc582dfec684 github.com/creachadair/mds v0.31.0 github.com/creachadair/msync v0.10.1 github.com/creachadair/taskgroup v0.14.4 diff --git a/go.sum b/go.sum index 011ecbfc2..8f2808734 100644 --- a/go.sum +++ b/go.sum @@ -282,6 +282,8 @@ github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf/go.mod h1:F5haX7 github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/coreos/go-systemd/v22 v22.7.0 h1:LAEzFkke61DFROc7zNLX/WA2i5J8gYqe0rSj9KI28KA= github.com/coreos/go-systemd/v22 v22.7.0/go.mod h1:xNUYtjHu2EDXbsxz1i41wouACIwT7Ybq9o0BQhMwD0w= +github.com/cpu/go-upki v0.0.0-20261112150031-bc582dfec684 h1:FvlMD2jjjJewrxHbN6OLzWi2OA2j6HMRvCf3Onu39ok= +github.com/cpu/go-upki v0.0.0-20261112150031-bc582dfec684/go.mod h1:uu3MXXGHcOU/jX7TmhuC/k1Z6elot0ECZJAABAodcQU= github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/creachadair/mds v0.31.0 h1:h4SXXgallvZfD8CFQnQNAOtBkUGpZjPwNBRQpHpHM/g= github.com/creachadair/mds v0.31.0/go.mod h1:IZ3oLffgVNZ4O5WXTPxx7EX5ilSl1ypdv5FekYyynyI= diff --git a/net/tlsdial/revocation_test.go b/net/tlsdial/revocation_test.go new file mode 100644 index 000000000..c4bf90ac0 --- /dev/null +++ b/net/tlsdial/revocation_test.go @@ -0,0 +1,123 @@ +// Copyright (c) Tailscale Inc & contributors +// SPDX-License-Identifier: BSD-3-Clause + +package tlsdial + +import ( + "crypto/ecdsa" + "crypto/elliptic" + "crypto/rand" + "crypto/tls" + "crypto/x509" + "crypto/x509/pkix" + "errors" + "math/big" + "testing" + "time" +) + +// newTestChain returns a leaf certificate for dnsName and a pool holding the +// self-signed root that issued it. +func newTestChain(t *testing.T, dnsName string) (leaf *x509.Certificate, roots *x509.CertPool) { + t.Helper() + rootKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + if err != nil { + t.Fatal(err) + } + rootTmpl := &x509.Certificate{ + SerialNumber: big.NewInt(1), + Subject: pkix.Name{CommonName: "tlsdial test root"}, + NotBefore: time.Now().Add(-time.Hour), + NotAfter: time.Now().Add(time.Hour), + IsCA: true, + BasicConstraintsValid: true, + KeyUsage: x509.KeyUsageCertSign, + } + rootDER, err := x509.CreateCertificate(rand.Reader, rootTmpl, rootTmpl, &rootKey.PublicKey, rootKey) + if err != nil { + t.Fatal(err) + } + root, err := x509.ParseCertificate(rootDER) + if err != nil { + t.Fatal(err) + } + + leafKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + if err != nil { + t.Fatal(err) + } + leafTmpl := &x509.Certificate{ + SerialNumber: big.NewInt(2), + Subject: pkix.Name{CommonName: dnsName}, + DNSNames: []string{dnsName}, + NotBefore: time.Now().Add(-time.Hour), + NotAfter: time.Now().Add(time.Hour), + ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}, + } + leafDER, err := x509.CreateCertificate(rand.Reader, leafTmpl, root, &leafKey.PublicKey, rootKey) + if err != nil { + t.Fatal(err) + } + leaf, err = x509.ParseCertificate(leafDER) + if err != nil { + t.Fatal(err) + } + roots = x509.NewCertPool() + roots.AddCert(root) + return leaf, roots +} + +func TestHookCheckRevocation(t *testing.T) { + const host = "revoked.test" + leaf, roots := newTestChain(t, host) + + errRevoked := errors.New("revoked") + var gotName string + var gotChain []*x509.Certificate + var revoked bool + defer HookCheckRevocation.SetForTest(func(dnsName string, chain []*x509.Certificate) error { + gotName, gotChain = dnsName, chain + if revoked { + return errRevoked + } + return nil + })() + + tests := []struct { + name string + verify func() error + }{ + {"Config", func() error { + conf := Config(nil, &tls.Config{RootCAs: roots}) + return conf.VerifyConnection(tls.ConnectionState{ + ServerName: host, + PeerCertificates: []*x509.Certificate{leaf}, + }) + }}, + {"SetConfigExpectedCert", func() error { + conf := &tls.Config{ServerName: "front.test", RootCAs: roots} + SetConfigExpectedCert(conf, host) + return conf.VerifyPeerCertificate([][]byte{leaf.Raw}, nil) + }}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + for _, revoked = range []bool{false, true} { + gotName, gotChain = "", nil + err := tt.verify() + if revoked && !errors.Is(err, errRevoked) { + t.Errorf("revoked: got err %v; want %v", err, errRevoked) + } + if !revoked && err != nil { + t.Errorf("not revoked: got err %v; want nil", err) + } + if gotName != host { + t.Errorf("hook got name %q; want %q", gotName, host) + } + if len(gotChain) != 2 || !gotChain[0].Equal(leaf) { + t.Errorf("hook got chain of len %d; want leaf + root", len(gotChain)) + } + } + }) + } +} diff --git a/net/tlsdial/tlsdial.go b/net/tlsdial/tlsdial.go index 417c925b7..4d5587f1e 100644 --- a/net/tlsdial/tlsdial.go +++ b/net/tlsdial/tlsdial.go @@ -28,6 +28,7 @@ import ( "tailscale.com/derp/derpconst" "tailscale.com/envknob" + "tailscale.com/feature" "tailscale.com/feature/buildfeatures" "tailscale.com/health" "tailscale.com/hostinfo" @@ -54,6 +55,26 @@ var mitmBlockWarnable = health.Register(&health.Warnable{ ImpactsConnectivity: true, }) +// HookCheckRevocation, if set, is called after a server's certificate chain +// has passed x509 verification in [Config] or [SetConfigExpectedCert]. +// chain is the verified chain, leaf first, and dnsName is the name the leaf +// was verified for. A non-nil error rejects the connection. +// +// It is set by the "upki" feature. +var HookCheckRevocation feature.Hook[func(dnsName string, chain []*x509.Certificate) error] + +// checkRevocation runs [HookCheckRevocation], if set, against the first of +// the verified chains returned by [x509.Certificate.Verify]. +func checkRevocation(dnsName string, chains [][]*x509.Certificate) error { + if !buildfeatures.HasUPKI || len(chains) == 0 { + return nil + } + if f, ok := HookCheckRevocation.GetOk(); ok { + return f(dnsName, chains[0]) + } + return nil +} + // Config returns a tls.Config for connecting to a server that // uses system roots for validation but, if those fail, also tries // the baked-in LetsEncrypt roots as a fallback validation method. @@ -172,25 +193,25 @@ func Config(ht *health.Tracker, base *tls.Config) *tls.Config { for _, cert := range cs.PeerCertificates[1:] { opts.Intermediates.AddCert(cert) } - _, errSys := cs.PeerCertificates[0].Verify(opts) + chainsSys, errSys := cs.PeerCertificates[0].Verify(opts) if debug() { log.Printf("tlsdial(sys %q): %v", dialedHost, errSys) } if errSys == nil && !debug() { - return nil + return checkRevocation(dialedHost, chainsSys) } // If extra roots were provided (e.g. user-installed CAs on // Android), try those next. if extraRoots != nil { opts.Roots = extraRoots - _, errExtra := cs.PeerCertificates[0].Verify(opts) + chainsExtra, errExtra := cs.PeerCertificates[0].Verify(opts) if debug() { log.Printf("tlsdial(extra %q): %v", dialedHost, errExtra) } if errExtra == nil { atomic.AddInt32(&counterFallbackOK, 1) - return nil + return checkRevocation(dialedHost, chainsExtra) } opts.Roots = nil // reset for baked roots check } @@ -202,7 +223,7 @@ func Config(ht *health.Tracker, base *tls.Config) *tls.Config { // If we have baked-in LetsEncrypt roots and we either failed above, or // debug logging is enabled, also verify with LetsEncrypt. opts.Roots = bakedroots.Get() - _, bakedErr := cs.PeerCertificates[0].Verify(opts) + chainsBaked, bakedErr := cs.PeerCertificates[0].Verify(opts) if debug() { log.Printf("tlsdial(bake %q): %v", dialedHost, bakedErr) } else if bakedErr != nil { @@ -218,10 +239,10 @@ func Config(ht *health.Tracker, base *tls.Config) *tls.Config { } if errSys == nil { - return nil + return checkRevocation(dialedHost, chainsSys) } else if bakedErr == nil { atomic.AddInt32(&counterFallbackOK, 1) - return nil + return checkRevocation(dialedHost, chainsBaked) } return errSys } @@ -276,21 +297,21 @@ func SetConfigExpectedCert(c *tls.Config, certDNSName string) { for _, cert := range certs[1:] { opts.Intermediates.AddCert(cert) } - _, errSys := certs[0].Verify(opts) + chainsSys, errSys := certs[0].Verify(opts) if debug() { log.Printf("tlsdial(sys %q/%q): %v", c.ServerName, certDNSName, errSys) } if errSys == nil { - return nil + return checkRevocation(certDNSName, chainsSys) } if extraRoots != nil { opts.Roots = extraRoots - _, errExtra := certs[0].Verify(opts) + chainsExtra, errExtra := certs[0].Verify(opts) if debug() { log.Printf("tlsdial(extra %q/%q): %v", c.ServerName, certDNSName, errExtra) } if errExtra == nil { - return nil + return checkRevocation(certDNSName, chainsExtra) } opts.Roots = nil } @@ -298,12 +319,12 @@ func SetConfigExpectedCert(c *tls.Config, certDNSName string) { return errSys } opts.Roots = bakedroots.Get() - _, err := certs[0].Verify(opts) + chainsBaked, err := certs[0].Verify(opts) if debug() { log.Printf("tlsdial(bake %q/%q): %v", c.ServerName, certDNSName, err) } if err == nil { - return nil + return checkRevocation(certDNSName, chainsBaked) } return errSys } diff --git a/shell.nix b/shell.nix index 54f950073..eb463b95c 100644 --- a/shell.nix +++ b/shell.nix @@ -16,4 +16,4 @@ ) { src = ./.; }).shellNix -# nix-direnv cache busting line: sha256-CEZxW9kZUIjI3frTZOEKssYJz3Uo58+YdLm8iEjTeMo= +# nix-direnv cache busting line: sha256-EUjRAWRCI6FfXRis4AyX4+9EPDrWPpVk6eYQKAwJ+H8=