diff --git a/README.md b/README.md index 0cf2e8a..a06b7dc 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ embarass pip index versions pip --index-url=https://pypi.org/simple --no-cache-d embarass docker manifest inspect docker.io/library/alpine:latest embarass crane manifest registry.k8s.io/pause:3.10 -# Test the direct eMudhra trust path instead of the default Sectigo path +# Test one trust path for fewer runs with narrower coverage embarass --chain emsign -- curl https://example.com/ # Allow a command to run without the default 30-second deadline @@ -94,7 +94,9 @@ embarass --headless -- curl https://example.com/ embarass batch ``` -The default test uses the weak `emSign DV TLS CA - G3B` key in its cross-certificate issued by `AAA Certificate Services`. Run a second, explicit test with `--chain emsign` to exercise the direct eMudhra path. `emBarrass` never runs a command twice automatically because the command may have side effects. +By default (`--chain all`), the command tests both trust paths for the weak `emSign DV TLS CA - G3B` key: first the direct eMudhra path to `emSign ECC Root CA - G3`, then the cross-certificate issued by `AAA Certificate Services`. Testing stops with a **vulnerable** result as soon as any path is accepted. The result is **rejected** only if every path is rejected; otherwise it is **inconclusive**. + +Testing one path can miss a vulnerable client. Mozilla-derived trust stores trust `AAA Certificate Services` for e-mail only, so a client can reject the Sectigo path but accept the direct path. If both paths run, the command's side effects happen twice. Use `--chain emsign` or `--chain sectigo` to test one path. `--timeout` applies per path. The default output is an interactive, human-readable terminal report with distinct vulnerable, rejected, inconclusive, and harness-error panels. Use `--headless` to retain the compact one-line log format for automation and captured logs. Both modes use the same exit codes. @@ -114,9 +116,9 @@ current image: cgr.dev/chainguard/git@sha256:06119871a608d163eac2daddd0745582e457a29ee8402bd351c13f294ede30e1 ``` -Use `embarass batch --chain emsign` to exercise the vulnerable direct eMudhra -trust path in this historical fixture. The default `sectigo` run tests the -separate cross-signed path, which this image's CA bundle need not trust. +By default, `batch` tests both trust paths per probe unless the first is accepted. +The historical `docker/git` fixture is vulnerable through the direct eMudhra +path; its CA bundle need not trust the cross-signed path. Before anything runs, the terminal UI shows the exact read-only command selected for each installed tool and marks missing tools as skipped. The prompt @@ -150,7 +152,7 @@ For automation, make consent explicit and select compact output: ```console embarass batch --yes --headless -embarass batch --yes --headless --chain emsign +embarass batch --yes --headless --chain emsign # one trust path per probe ``` The batch exits `1` if any tool is vulnerable, `2` if none are vulnerable but @@ -168,10 +170,10 @@ Git can use `url.*.insteadOf` configuration to silently rewrite an explicit HTTP | Exit | Result | Meaning | |---:|---|---| | `1` | **Vulnerable** | The child accepted the forged chain and sent application data. `emBarrass` immediately terminated the child. | -| `0` | **Not confirmed / rejected** | The child reached `emBarrass` but rejected or otherwise failed the forged TLS handshake. | +| `0` | **Not confirmed / rejected** | On every tested trust path, the child reached `emBarrass` but rejected or otherwise failed the forged TLS handshake. | | `2` | **Inconclusive or harness error** | No HTTPS proxy traffic was observed, no TLS decision was reached, the deadline expired, or the harness failed. | -A zero exit is evidence about the tested executable, machine, trust state, and selected chain—not a permanent verdict about a product family. Use both trust paths for broader coverage. +A zero exit is evidence about the tested executable, machine, trust state, and trust paths—not a permanent verdict about a product family. ## How it works diff --git a/cmd/embarass/batch.go b/cmd/embarass/batch.go index 628f635..695f906 100644 --- a/cmd/embarass/batch.go +++ b/cmd/embarass/batch.go @@ -40,8 +40,8 @@ immutable, digest-pinned image.`, }, } command.Flags().BoolVarP(&app.batchYes, "yes", "y", false, "run the displayed probes without prompting") - command.Flags().DurationVar(&app.timeout, "timeout", defaultTimeout, "maximum runtime per tool; 0 disables the deadline") - command.Flags().StringVar(&app.chain, "chain", string(certforge.ChainSectigo), "trust path to test: sectigo or emsign") + command.Flags().DurationVar(&app.timeout, "timeout", defaultTimeout, "maximum runtime per tool and trust path; 0 disables the deadline") + command.Flags().StringVar(&app.chain, "chain", chainAll, chainFlagUsage) command.Flags().BoolVar(&app.headless, "headless", false, "emit compact log lines without the terminal UI") command.Flags().BoolVarP(&app.verbose, "verbose", "v", false, "enable debug logging") return command @@ -51,7 +51,7 @@ func (app *application) runBatch(cmd *cobra.Command) error { if app.timeout < 0 { return fmt.Errorf("timeout must not be negative: %s", app.timeout) } - chain, err := parseChain(app.chain) + chains, err := parseChains(app.chain) if err != nil { return err } @@ -79,9 +79,9 @@ func (app *application) runBatch(cmd *cobra.Command) error { var summary batchSummary if app.headless || !interactive { - summary = app.runBatchHeadless(cmd.Context(), plan, chain) + summary = app.runBatchHeadless(cmd.Context(), plan, chains) } else { - summary, err = app.runBatchTerminal(cmd, plan, chain) + summary, err = app.runBatchTerminal(cmd, plan, chains) } cleanupErr := plan.Cleanup() if err != nil || cleanupErr != nil { @@ -94,7 +94,7 @@ func (app *application) runBatch(cmd *cobra.Command) error { func (app *application) runBatchTerminal( cmd *cobra.Command, plan batchtest.Plan, - chain certforge.Chain, + chains []certforge.Chain, ) (batchSummary, error) { ctx, cancel := context.WithCancel(cmd.Context()) defer cancel() @@ -104,8 +104,7 @@ func (app *application) runBatchTerminal( cancel, newTerminalUI(cmd.ErrOrStderr()).styles, plan, - app.run, - chain, + acrossChains(app.run, chains), app.timeout, app.batchYes, ) @@ -129,7 +128,7 @@ func (app *application) runBatchTerminal( func (app *application) runBatchHeadless( ctx context.Context, plan batchtest.Plan, - chain certforge.Chain, + chains []certforge.Chain, ) batchSummary { log := zerolog.Ctx(ctx) available := make([]string, 0, len(plan.Probes)) @@ -147,9 +146,9 @@ func (app *application) runBatchHeadless( summary := batchSummary{skipped: len(plan.Unavailable)} for _, probe := range plan.Probes { log.Info().Str("tool", probe.Name).Str("command", probe.Preview).Msg("testing TLS trust") - result, err := app.run(ctx, batchRunnerOptions(plan, probe, chain, app.timeout)) + result, reportedChains, err := runChains(ctx, app.run, batchRunnerOptions(plan, probe, app.timeout), chains, nil) summary.record(result, err) - logBatchResult(log, probe.Name, result, err) + logBatchResult(log, probe.Name, result, reportedChains, err) } log.Info(). Int("embarrassed", summary.vulnerable). @@ -173,7 +172,6 @@ func planMayPullImage(plan batchtest.Plan) bool { func batchRunnerOptions( plan batchtest.Plan, probe batchtest.Probe, - chain certforge.Chain, timeout time.Duration, ) runner.Options { proxyTarget := runner.ProxyTargetHost @@ -185,22 +183,22 @@ func batchRunnerOptions( Timeout: timeout, Stdout: io.Discard, Stderr: io.Discard, - Chain: chain, WorkingDirectory: plan.WorkingDirectory(), EnvironmentOverrides: probe.EnvironmentOverrides, ProxyTarget: proxyTarget, } } -func logBatchResult(log *zerolog.Logger, tool string, result runner.Result, err error) { +func logBatchResult(log *zerolog.Logger, tool string, result runner.Result, chains []certforge.Chain, err error) { if err != nil { log.Error().Err(err).Str("tool", tool).Msg("HARNESS ERROR") return } - event := log.Info().Str("tool", tool).Str("host", result.Host).Dur("duration", result.Duration) + chain := chainNames(chains, ",") + event := log.Info().Str("tool", tool).Str("host", result.Host).Str("chain", chain).Dur("duration", result.Duration) switch result.Outcome { case runner.OutcomeVulnerable: - event = log.Error().Str("tool", tool).Str("host", result.Host).Dur("duration", result.Duration) + event = log.Error().Str("tool", tool).Str("host", result.Host).Str("chain", chain).Dur("duration", result.Duration) event.Msg("COMPLETELY EMBARRASSED: forged certificate accepted") case runner.OutcomeRejected: event.Msg("TRUST HELD: forged certificate rejected") @@ -208,6 +206,7 @@ func logBatchResult(log *zerolog.Logger, tool string, result runner.Result, err log.Warn(). Str("tool", tool). Str("reason", string(result.Reason)). + Str("chain", chain). Dur("duration", result.Duration). Msg("NO SIGNAL: result inconclusive") } diff --git a/cmd/embarass/batch_terminal.go b/cmd/embarass/batch_terminal.go index 837c1b9..719bb9a 100644 --- a/cmd/embarass/batch_terminal.go +++ b/cmd/embarass/batch_terminal.go @@ -10,7 +10,6 @@ import ( "time" "github.com/boostsecurityio/emBarrass/pkg/batchtest" - "github.com/boostsecurityio/emBarrass/pkg/certforge" "github.com/boostsecurityio/emBarrass/pkg/runner" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" @@ -46,7 +45,6 @@ type batchModel struct { styles terminalStyles plan batchtest.Plan run runFunc - chain certforge.Chain timeout time.Duration items []batchItem current int @@ -72,7 +70,6 @@ func newBatchModel( styles terminalStyles, plan batchtest.Plan, run runFunc, - chain certforge.Chain, timeout time.Duration, autoStart bool, ) batchModel { @@ -86,7 +83,6 @@ func newBatchModel( styles: styles, plan: plan, run: run, - chain: chain, timeout: timeout, items: items, width: 80, @@ -171,7 +167,7 @@ func (model batchModel) runCurrent() tea.Cmd { return func() tea.Msg { result, err := model.run( model.ctx, - batchRunnerOptions(model.plan, probe, model.chain, model.timeout), + batchRunnerOptions(model.plan, probe, model.timeout), ) return batchResultMsg{index: index, result: result, err: err} } diff --git a/cmd/embarass/batch_test.go b/cmd/embarass/batch_test.go index 1c8ff20..70f1b64 100644 --- a/cmd/embarass/batch_test.go +++ b/cmd/embarass/batch_test.go @@ -12,7 +12,6 @@ import ( "time" "github.com/boostsecurityio/emBarrass/pkg/batchtest" - "github.com/boostsecurityio/emBarrass/pkg/certforge" "github.com/boostsecurityio/emBarrass/pkg/runner" tea "github.com/charmbracelet/bubbletea" "github.com/stretchr/testify/require" @@ -50,7 +49,6 @@ func TestBatchModelPreviewsThenRunsConfirmedProbe(t *testing.T) { ui.styles, plan, run, - certforge.ChainSectigo, 30*time.Second, false, ) @@ -91,7 +89,6 @@ func TestBatchModelDefaultsToCancel(t *testing.T) { t.Fatal("probe must not run before confirmation") return runner.Result{}, errors.New("unreachable") }, - certforge.ChainSectigo, 30*time.Second, false, ) @@ -121,12 +118,11 @@ func TestBatchRunnerOptionsIsolateWritesAndDiscardOutput(t *testing.T) { "GOCACHE": filepath.Join(workspace, "go-build"), }, } - options := batchRunnerOptions(plan, probe, certforge.ChainEMSign, 5*time.Second) + options := batchRunnerOptions(plan, probe, 5*time.Second) require.Equal(t, probe.Command(), options.Command) require.Equal(t, probe.EnvironmentOverrides, options.EnvironmentOverrides) require.Equal(t, plan.WorkingDirectory(), options.WorkingDirectory) - require.Equal(t, certforge.ChainEMSign, options.Chain) require.Equal(t, 5*time.Second, options.Timeout) require.Equal(t, runner.ProxyTargetDockerContainer, options.ProxyTarget) } @@ -137,7 +133,6 @@ func TestBatchRunnerOptionsDefaultToHostProxy(t *testing.T) { options := batchRunnerOptions( batchtest.Plan{}, batchtest.Probe{Name: "curl", Executable: "/usr/bin/curl"}, - certforge.ChainSectigo, time.Second, ) diff --git a/cmd/embarass/chains.go b/cmd/embarass/chains.go new file mode 100644 index 0000000..35627b9 --- /dev/null +++ b/cmd/embarass/chains.go @@ -0,0 +1,102 @@ +// Copyright (C) 2026 boostsecurity.io +// SPDX-License-Identifier: GPL-3.0-or-later + +package main + +import ( + "context" + "fmt" + "strings" + "time" + + "github.com/boostsecurityio/emBarrass/pkg/certforge" + "github.com/boostsecurityio/emBarrass/pkg/runner" + "github.com/rs/zerolog" +) + +// Testing one path can miss clients that trust the compromised key through another. +const chainAll = "all" + +// emSign runs first because current Mozilla-derived stores trust it for TLS, +// allowing vulnerable clients to stop after one run. +var allChains = []certforge.Chain{certforge.ChainEMSign, certforge.ChainSectigo} + +const chainFlagUsage = "trust path to test: all, sectigo, or emsign" + +func parseChains(value string) ([]certforge.Chain, error) { + switch chain := certforge.Chain(strings.ToLower(value)); chain { + case chainAll: + return allChains, nil + case certforge.ChainSectigo, certforge.ChainEMSign: + return []certforge.Chain{chain}, nil + default: + return nil, fmt.Errorf("unsupported chain %q: use all, sectigo, or emsign", value) + } +} + +// runChains stops at the first accepted path. It reports rejection only if all +// paths reject, and inconclusive otherwise. The returned paths identify the +// result; an inconclusive result names only the path its reason and child exit +// came from. beforePath, if set, runs before each path so callers can separate +// the child output of consecutive runs. +func runChains( + ctx context.Context, + run runFunc, + options runner.Options, + chains []certforge.Chain, + beforePath func(certforge.Chain), +) (runner.Result, []certforge.Chain, error) { + var ( + reported runner.Result + reportedChain certforge.Chain + elapsed time.Duration + ) + for _, chain := range chains { + // Do not start another child, and repeat its side effects, after cancellation. + if ctx.Err() != nil { + return runner.Result{}, nil, fmt.Errorf("test %s trust path: %w", chain, context.Cause(ctx)) + } + zerolog.Ctx(ctx).Debug().Str("chain", string(chain)).Msg("Testing trust path") + if beforePath != nil { + beforePath(chain) + } + options.Chain = chain + result, err := run(ctx, options) + if err != nil { + return runner.Result{}, nil, fmt.Errorf("test %s trust path: %w", chain, err) + } + elapsed += result.Duration + switch result.Outcome { + case runner.OutcomeVulnerable: + result.Duration = elapsed + return result, []certforge.Chain{chain}, nil + case runner.OutcomeRejected, runner.OutcomeInconclusive: + if reported.Outcome != runner.OutcomeInconclusive { + reported, reportedChain = result, chain + } + default: + return result, []certforge.Chain{chain}, nil + } + } + reported.Duration = elapsed + if reported.Outcome == runner.OutcomeInconclusive { + return reported, []certforge.Chain{reportedChain}, nil + } + return reported, chains, nil +} + +// acrossChains overrides Options.Chain to give batch probes the same path coverage. +func acrossChains(run runFunc, chains []certforge.Chain) runFunc { + return func(ctx context.Context, options runner.Options) (runner.Result, error) { + result, _, err := runChains(ctx, run, options, chains, nil) + return result, err + } +} + +func chainNames(chains []certforge.Chain, separator string) string { + names := make([]string, 0, len(chains)) + for _, chain := range chains { + names = append(names, string(chain)) + } + return strings.Join(names, separator) +} diff --git a/cmd/embarass/chains_test.go b/cmd/embarass/chains_test.go new file mode 100644 index 0000000..7201b45 --- /dev/null +++ b/cmd/embarass/chains_test.go @@ -0,0 +1,169 @@ +// Copyright (C) 2026 boostsecurity.io +// SPDX-License-Identifier: GPL-3.0-or-later + +package main + +import ( + "context" + "errors" + "testing" + "time" + + "github.com/boostsecurityio/emBarrass/pkg/certforge" + "github.com/boostsecurityio/emBarrass/pkg/runner" + "github.com/stretchr/testify/require" +) + +func TestRunChainsCombinesTrustPaths(t *testing.T) { + t.Parallel() + + rejected := runner.Result{Outcome: runner.OutcomeRejected, Duration: time.Second} + vulnerable := runner.Result{Outcome: runner.OutcomeVulnerable, Duration: time.Second} + noTraffic := runner.Result{ + Outcome: runner.OutcomeInconclusive, + Reason: runner.ReasonNoTraffic, + ChildExitCode: 7, + Duration: time.Second, + } + timedOut := runner.Result{ + Outcome: runner.OutcomeInconclusive, + Reason: runner.ReasonTimeout, + ChildExitCode: 9, + Duration: time.Second, + } + + testCases := []struct { + name string + outcomes map[certforge.Chain]runner.Result + wantOutcome runner.Outcome + wantReason runner.Reason + wantChildExit int + wantChains []certforge.Chain + wantRan []certforge.Chain + wantDuration time.Duration + }{ + { + name: "accepted on the first path stops the sweep", + outcomes: map[certforge.Chain]runner.Result{ + certforge.ChainEMSign: vulnerable, + }, + wantOutcome: runner.OutcomeVulnerable, + wantChains: []certforge.Chain{certforge.ChainEMSign}, + wantRan: []certforge.Chain{certforge.ChainEMSign}, + wantDuration: time.Second, + }, + { + name: "accepted on a later path is vulnerable despite an earlier rejection", + outcomes: map[certforge.Chain]runner.Result{ + certforge.ChainEMSign: rejected, + certforge.ChainSectigo: vulnerable, + }, + wantOutcome: runner.OutcomeVulnerable, + wantChains: []certforge.Chain{certforge.ChainSectigo}, + wantRan: allChains, + wantDuration: 2 * time.Second, + }, + { + name: "rejected only when every path rejects", + outcomes: map[certforge.Chain]runner.Result{ + certforge.ChainEMSign: rejected, + certforge.ChainSectigo: rejected, + }, + wantOutcome: runner.OutcomeRejected, + wantChains: allChains, + wantRan: allChains, + wantDuration: 2 * time.Second, + }, + { + name: "an inconclusive path outweighs an earlier rejection", + outcomes: map[certforge.Chain]runner.Result{ + certforge.ChainEMSign: rejected, + certforge.ChainSectigo: timedOut, + }, + wantOutcome: runner.OutcomeInconclusive, + wantReason: runner.ReasonTimeout, + wantChildExit: 9, + wantChains: []certforge.Chain{certforge.ChainSectigo}, + wantRan: allChains, + wantDuration: 2 * time.Second, + }, + { + name: "an inconclusive path outweighs a later rejection", + outcomes: map[certforge.Chain]runner.Result{ + certforge.ChainEMSign: noTraffic, + certforge.ChainSectigo: rejected, + }, + wantOutcome: runner.OutcomeInconclusive, + wantReason: runner.ReasonNoTraffic, + wantChildExit: 7, + wantChains: []certforge.Chain{certforge.ChainEMSign}, + wantRan: allChains, + wantDuration: 2 * time.Second, + }, + { + name: "the reported path is the one the reason and child exit came from", + outcomes: map[certforge.Chain]runner.Result{ + certforge.ChainEMSign: noTraffic, + certforge.ChainSectigo: timedOut, + }, + wantOutcome: runner.OutcomeInconclusive, + wantReason: runner.ReasonNoTraffic, + wantChildExit: 7, + wantChains: []certforge.Chain{certforge.ChainEMSign}, + wantRan: allChains, + wantDuration: 2 * time.Second, + }, + } + + for _, testCase := range testCases { + t.Run(testCase.name, func(t *testing.T) { + t.Parallel() + + var ran []certforge.Chain + run := func(_ context.Context, options runner.Options) (runner.Result, error) { + ran = append(ran, options.Chain) + return testCase.outcomes[options.Chain], nil + } + + result, chains, err := runChains(context.Background(), run, runner.Options{}, allChains, nil) + require.NoError(t, err) + require.Equal(t, testCase.wantOutcome, result.Outcome) + require.Equal(t, testCase.wantReason, result.Reason) + require.Equal(t, testCase.wantChildExit, result.ChildExitCode) + require.Equal(t, testCase.wantChains, chains) + require.Equal(t, testCase.wantRan, ran) + require.Equal(t, testCase.wantDuration, result.Duration) + }) + } +} + +func TestRunChainsStopsOnHarnessError(t *testing.T) { + t.Parallel() + + calls := 0 + run := func(context.Context, runner.Options) (runner.Result, error) { + calls++ + return runner.Result{}, errors.New("interceptor failed") + } + + _, _, err := runChains(context.Background(), run, runner.Options{}, allChains, nil) + require.ErrorContains(t, err, "test emsign trust path: interceptor failed") + require.Equal(t, 1, calls) +} + +func TestRunChainsDoesNotStartAnotherPathAfterCancellation(t *testing.T) { + t.Parallel() + + ctx, cancel := context.WithCancel(context.Background()) + t.Cleanup(cancel) + var ran []certforge.Chain + run := func(_ context.Context, options runner.Options) (runner.Result, error) { + ran = append(ran, options.Chain) + cancel() + return runner.Result{Outcome: runner.OutcomeRejected}, nil + } + + _, _, err := runChains(ctx, run, runner.Options{}, allChains, nil) + require.ErrorIs(t, err, context.Canceled) + require.Equal(t, []certforge.Chain{certforge.ChainEMSign}, ran) +} diff --git a/cmd/embarass/root.go b/cmd/embarass/root.go index 0834f15..6c49162 100644 --- a/cmd/embarass/root.go +++ b/cmd/embarass/root.go @@ -112,8 +112,8 @@ forward intercepted traffic, or change the host trust store.`, }, } command.Flags().SetInterspersed(false) - command.Flags().DurationVar(&app.timeout, "timeout", defaultTimeout, "maximum runtime; 0 disables the deadline") - command.Flags().StringVar(&app.chain, "chain", string(certforge.ChainSectigo), "trust path to test: sectigo or emsign") + command.Flags().DurationVar(&app.timeout, "timeout", defaultTimeout, "maximum runtime per trust path; 0 disables the deadline") + command.Flags().StringVar(&app.chain, "chain", chainAll, chainFlagUsage) command.Flags().BoolVar(&app.headless, "headless", false, "emit compact log lines without the terminal UI") command.Flags().BoolVarP(&app.verbose, "verbose", "v", false, "enable debug logging") command.AddCommand(newBatchCommand(app), newVersionCommand()) @@ -148,14 +148,14 @@ func (app *application) runCheck(cmd *cobra.Command, args []string) error { if app.timeout < 0 { return fmt.Errorf("timeout must not be negative: %s", app.timeout) } - chain, err := parseChain(app.chain) + chains, err := parseChains(app.chain) if err != nil { return err } preparedCommand, adjustments := runner.PrepareCommand(args) ui := newTerminalUI(cmd.ErrOrStderr()) if !app.headless { - if err := ui.start(args, chain, app.timeout, adjustments); err != nil { + if err := ui.start(args, chains, app.timeout, adjustments); err != nil { return err } app.terminalStarted = true @@ -163,13 +163,22 @@ func (app *application) runCheck(cmd *cobra.Command, args []string) error { logHeadlessAdjustments(zerolog.Ctx(cmd.Context()), adjustments) } - result, err := app.run(cmd.Context(), runner.Options{ + var beforePath func(certforge.Chain) + if len(chains) > 1 { + beforePath = func(chain certforge.Chain) { + if app.headless { + zerolog.Ctx(cmd.Context()).Info().Str("chain", string(chain)).Msg("Testing trust path") + return + } + ui.pathHeader(chain) + } + } + result, reportedChains, err := runChains(cmd.Context(), app.run, runner.Options{ Command: preparedCommand, Timeout: app.timeout, Stdout: cmd.OutOrStdout(), Stderr: cmd.ErrOrStderr(), - Chain: chain, - }) + }, chains, beforePath) if err != nil { return err } @@ -185,9 +194,9 @@ func (app *application) runCheck(cmd *cobra.Command, args []string) error { return fmt.Errorf("unknown runner outcome %q", result.Outcome) } if !app.headless { - return ui.result(result, chain, app.exitCode) + return ui.result(result, reportedChains, app.exitCode) } - logHeadlessResult(zerolog.Ctx(cmd.Context()), result, chain) + logHeadlessResult(zerolog.Ctx(cmd.Context()), result, reportedChains) return nil } @@ -204,31 +213,24 @@ func logHeadlessAdjustments(log *zerolog.Logger, adjustments []runner.CommandAdj } } -func parseChain(value string) (certforge.Chain, error) { - chain := certforge.Chain(strings.ToLower(value)) - if chain != certforge.ChainSectigo && chain != certforge.ChainEMSign { - return "", fmt.Errorf("unsupported chain %q: use sectigo or emsign", value) - } - return chain, nil -} - -func logHeadlessResult(log *zerolog.Logger, result runner.Result, chain certforge.Chain) { +func logHeadlessResult(log *zerolog.Logger, result runner.Result, chains []certforge.Chain) { switch result.Outcome { case runner.OutcomeVulnerable: log.Error(). Str("host", result.Host). - Str("chain", string(chain)). + Str("chain", chainNames(chains, ",")). Dur("duration", result.Duration). Msg("VULNERABLE: the command accepted a forged certificate signed by the compromised eMudhra key") case runner.OutcomeRejected: log.Info(). Str("host", result.Host). - Str("chain", string(chain)). + Str("chain", chainNames(chains, ",")). Dur("duration", result.Duration). Msg("NOT CONFIRMED: the command reached emBarrass but rejected the forged TLS connection") case runner.OutcomeInconclusive: log.Warn(). Str("reason", string(result.Reason)). + Str("chain", chainNames(chains, ",")). Int("child_exit_code", result.ChildExitCode). Dur("duration", result.Duration). Msg("INCONCLUSIVE: emBarrass could not confirm whether the command is vulnerable") diff --git a/cmd/embarass/root_test.go b/cmd/embarass/root_test.go index ce4f63a..9c43495 100644 --- a/cmd/embarass/root_test.go +++ b/cmd/embarass/root_test.go @@ -175,6 +175,36 @@ func TestRootCommandRejectsInvalidChain(t *testing.T) { require.ErrorContains(t, err, "unsupported chain") } +func TestRootCommandDefaultReportsVulnerableWhenOnlyOnePathIsAccepted(t *testing.T) { + t.Parallel() + + // A Mozilla-derived store trusts AAA Certificate Services for e-mail only, + // so the client rejects the Sectigo path but accepts the emSign path. + var ran []certforge.Chain + app := &application{ + exitCode: exitInconclusive, + run: func(_ context.Context, options runner.Options) (runner.Result, error) { + ran = append(ran, options.Chain) + if options.Chain == certforge.ChainEMSign { + return runner.Result{Outcome: runner.OutcomeVulnerable, Host: "example.com"}, nil + } + return runner.Result{Outcome: runner.OutcomeRejected, Host: "example.com"}, nil + }, + } + command := newRootCommand(app) + output := &bytes.Buffer{} + command.SetOut(output) + command.SetErr(output) + command.SetArgs([]string{"curl", "https://example.com/"}) + + require.NoError(t, command.Execute()) + require.Equal(t, exitVulnerable, app.exitCode) + require.Contains(t, output.String(), "COMPLETELY EMBARRASSED") + require.Contains(t, output.String(), "emsign (direct eMudhra chain)") + require.Contains(t, output.String(), "PATH emsign (direct eMudhra chain)") + require.Equal(t, []certforge.Chain{certforge.ChainEMSign}, ran) +} + func TestRootCommandHelpIncludesSupportedToolExamples(t *testing.T) { t.Parallel() diff --git a/cmd/embarass/terminal.go b/cmd/embarass/terminal.go index 296179a..c5ab38b 100644 --- a/cmd/embarass/terminal.go +++ b/cmd/embarass/terminal.go @@ -100,11 +100,11 @@ func isTerminal(output io.Writer) bool { func (ui terminalUI) start( command []string, - chain certforge.Chain, + chains []certforge.Chain, timeout time.Duration, adjustments []runner.CommandAdjustment, ) error { - model := newCeremonyModel(ui.styles, command, chain, timeout, adjustments) + model := newCeremonyModel(ui.styles, command, chains, timeout, adjustments) if ui.interactive { program := tea.NewProgram( model, @@ -131,15 +131,15 @@ func (ui terminalUI) start( return nil } -func (ui terminalUI) result(result runner.Result, chain certforge.Chain, exitCode int) error { +func (ui terminalUI) result(result runner.Result, chains []certforge.Chain, exitCode int) error { var rendered string switch result.Outcome { case runner.OutcomeVulnerable: - rendered = ui.vulnerableResult(result, chain, exitCode) + rendered = ui.vulnerableResult(result, chains, exitCode) case runner.OutcomeRejected: - rendered = ui.rejectedResult(result, chain, exitCode) + rendered = ui.rejectedResult(result, chains, exitCode) case runner.OutcomeInconclusive: - rendered = ui.inconclusiveResult(result, chain, exitCode) + rendered = ui.inconclusiveResult(result, chains, exitCode) default: return fmt.Errorf("render unknown runner outcome %q", result.Outcome) } @@ -150,9 +150,15 @@ func (ui terminalUI) result(result runner.Result, chain certforge.Chain, exitCod return nil } +// pathHeader marks where one trust path's child output starts. A failed write +// is not fatal here; the result write that follows reports it. +func (ui terminalUI) pathHeader(chain certforge.Chain) { + _, _ = fmt.Fprintln(ui.output, " "+ui.styles.cyanBold.Render("PATH")+" "+ui.styles.muted.Render(chainDescription(chain))) +} + func (ui terminalUI) vulnerableResult( result runner.Result, - chain certforge.Chain, + chains []certforge.Chain, exitCode int, ) string { lines := make([]string, 0, 9) @@ -164,13 +170,13 @@ func (ui terminalUI) vulnerableResult( ui.detail(ui.styles.redBold, "CAUSE", "eMudhra signing key had just 255 possible values"), "", ) - lines = append(lines, ui.resultMetadata(result, chain, exitCode)...) + lines = append(lines, ui.resultMetadata(result, chains, exitCode)...) return strings.Join(lines, "\n") } func (ui terminalUI) rejectedResult( result runner.Result, - chain certforge.Chain, + chains []certforge.Chain, exitCode int, ) string { lines := make([]string, 0, 7) @@ -180,13 +186,13 @@ func (ui terminalUI) rejectedResult( " The command reached the interceptor and rejected the forgery.", "", ) - lines = append(lines, ui.resultMetadata(result, chain, exitCode)...) + lines = append(lines, ui.resultMetadata(result, chains, exitCode)...) return strings.Join(lines, "\n") } func (ui terminalUI) inconclusiveResult( result runner.Result, - chain certforge.Chain, + chains []certforge.Chain, exitCode int, ) string { lines := []string{ @@ -203,13 +209,13 @@ func (ui terminalUI) inconclusiveResult( )) } lines = append(lines, "") - lines = append(lines, ui.resultMetadata(result, chain, exitCode)...) + lines = append(lines, ui.resultMetadata(result, chains, exitCode)...) return strings.Join(lines, "\n") } func (ui terminalUI) resultMetadata( result runner.Result, - chain certforge.Chain, + chains []certforge.Chain, exitCode int, ) []string { lines := make([]string, 0, 3) @@ -217,7 +223,7 @@ func (ui terminalUI) resultMetadata( lines = append(lines, ui.detail(ui.styles.cyanBold, "HOST", result.Host)) } lines = append(lines, - ui.detail(ui.styles.cyanBold, "CHAIN", chainDescription(chain)), + ui.detail(ui.styles.cyanBold, "CHAIN", chainsDescription(chains)), ui.detail( ui.styles.bold, "EXIT", @@ -300,7 +306,7 @@ type ceremonyTickMsg struct{} type ceremonyModel struct { styles terminalStyles command string - chain certforge.Chain + chains []certforge.Chain timeout time.Duration adjustments []runner.CommandAdjustment stage int @@ -310,7 +316,7 @@ type ceremonyModel struct { func newCeremonyModel( styles terminalStyles, command []string, - chain certforge.Chain, + chains []certforge.Chain, timeout time.Duration, adjustments []runner.CommandAdjustment, ) ceremonyModel { @@ -321,7 +327,7 @@ func newCeremonyModel( return ceremonyModel{ styles: styles, command: truncate(commandName, 16), - chain: chain, + chains: chains, timeout: timeout, adjustments: adjustments, width: 80, @@ -370,8 +376,8 @@ func (model ceremonyModel) View() string { "", " " + model.styles.cyanBold.Render("COMMAND") + " " + model.command + model.styles.muted.Render(" · arguments hidden"), - " " + model.styles.cyanBold.Render("CHAIN") + " " + chainShortDescription(model.chain) + - " " + model.styles.cyanBold.Render("LIMIT") + " " + timeoutDescription(model.timeout), + " " + model.styles.cyanBold.Render("CHAIN") + " " + chainsShortDescription(model.chains) + + " " + model.styles.cyanBold.Render("LIMIT") + " " + timeoutDescription(model.timeout, len(model.chains)), " " + model.styles.cyanBold.Render("MODE") + " local-only · upstream severed", "", " " + model.styles.cyan.Render("CONNECT") + " " + @@ -436,10 +442,13 @@ func (model ceremonyModel) progressLine() string { "\n Waiting for one application byte—the client’s confession." } -func timeoutDescription(timeout time.Duration) string { +func timeoutDescription(timeout time.Duration, paths int) string { if timeout == 0 { return "disabled" } + if paths > 1 { + return timeout.String() + " per path" + } return timeout.String() } @@ -454,6 +463,14 @@ func chainShortDescription(chain certforge.Chain) string { } } +func chainsShortDescription(chains []certforge.Chain) string { + descriptions := make([]string, 0, len(chains)) + for _, chain := range chains { + descriptions = append(descriptions, chainShortDescription(chain)) + } + return strings.Join(descriptions, " + ") +} + func truncate(value string, maximum int) string { runes := []rune(value) if len(runes) <= maximum { @@ -476,6 +493,13 @@ func chainDescription(chain certforge.Chain) string { } } +func chainsDescription(chains []certforge.Chain) string { + if len(chains) == 1 { + return chainDescription(chains[0]) + } + return chainNames(chains, " + ") + " (every tested trust path)" +} + func inconclusiveDescription(reason runner.Reason) string { switch reason { case runner.ReasonNoTraffic: diff --git a/cmd/embarass/terminal_test.go b/cmd/embarass/terminal_test.go index 7482406..c5c7b37 100644 --- a/cmd/embarass/terminal_test.go +++ b/cmd/embarass/terminal_test.go @@ -53,7 +53,7 @@ func TestTerminalUIResultStates(t *testing.T) { output := &bytes.Buffer{} ui := newTerminalUI(output) - require.NoError(t, ui.result(testCase.result, certforge.ChainSectigo, testCase.exitCode)) + require.NoError(t, ui.result(testCase.result, []certforge.Chain{certforge.ChainSectigo}, testCase.exitCode)) require.Contains(t, output.String(), testCase.want) require.Contains(t, output.String(), "EXIT") require.NotContains(t, output.String(), "\x1b[") @@ -68,7 +68,7 @@ func TestTerminalUIStartRendersCeremonyWithoutArguments(t *testing.T) { ui := newTerminalUI(output) require.NoError(t, ui.start( []string{"curl", "https://user:do-not-print@example.com/"}, - certforge.ChainSectigo, + allChains, 30*time.Second, nil, )) @@ -82,6 +82,8 @@ func TestTerminalUIStartRendersCeremonyWithoutArguments(t *testing.T) { require.Contains(t, rendered, "P-384: STILL SECURE") require.Contains(t, rendered, "KEYGEN: GOLD STAR FOR TRYING") require.Contains(t, rendered, "COMMAND curl · arguments hidden") + require.Contains(t, rendered, "CHAIN direct eMudhra + Sectigo / AAA") + require.Contains(t, rendered, "LIMIT 30s per path") require.Contains(t, rendered, "CHILD OUTPUT") require.NotContains(t, rendered, "do-not-print") } @@ -93,7 +95,7 @@ func TestTerminalUIStartDisclosesGHCredentialIsolation(t *testing.T) { ui := newTerminalUI(output) require.NoError(t, ui.start( []string{"gh", "api", "meta", "--silent"}, - certforge.ChainSectigo, + []certforge.Chain{certforge.ChainSectigo}, 30*time.Second, []runner.CommandAdjustment{runner.AdjustmentGHCredentialsIsolated}, )) @@ -109,7 +111,7 @@ func TestCeremonyModelUsesCompactBrandOnNarrowTerminals(t *testing.T) { model := newCeremonyModel( ui.styles, []string{"curl"}, - certforge.ChainSectigo, + []certforge.Chain{certforge.ChainSectigo}, 30*time.Second, nil, ) diff --git a/docs/research/emudhra-ca-incident.md b/docs/research/emudhra-ca-incident.md index f8b4e6b..e520488 100644 --- a/docs/research/emudhra-ca-incident.md +++ b/docs/research/emudhra-ca-incident.md @@ -99,6 +99,8 @@ At startup: Test the eMudhra-direct and Sectigo-cross-signed variants separately. A TLS Certificate message should not be treated as a bag containing arbitrary alternative paths; path construction differs between stores and verifiers. A `--chain=emsign|sectigo` option is predictable. Automatically executing an arbitrary user command twice is unsafe because commands can have side effects, so the default should perform one documented chain test and ask for an explicit second run for the alternative. +> **Superseded:** the default is now `--chain all`, which runs the command once per path (stopping early once one is accepted). A single-path default reported clients as protected when their store anchored only the other path; for example, Mozilla-derived stores trust `AAA Certificate Services` for e-mail only, so the Sectigo path alone misses clients that accept the direct path. `--chain emsign|sectigo` still limits a run to one path, so the command's side effects happen once. + ### Proof and outcome states TCP connection or `CONNECT` receipt does not demonstrate vulnerability. Even completion of the TLS handshake can precede an application's custom pinning or post-handshake policy. The strongest generic proof is that, after receiving the forged chain, the target sends an HTTP request (or other authenticated application bytes) over that TLS session.