Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
271c26e78a |
@@ -28,9 +28,10 @@ Bring the repo into policy compliance in one commit:
|
|||||||
- 2026-10-03: Key material is wiped on every exit: `Entry()` returns
|
- 2026-10-03: Key material is wiped on every exit: `Entry()` returns
|
||||||
the exit code after its deferred `memguard.Purge()` has run, and only
|
the exit code after its deferred `memguard.Purge()` has run, and only
|
||||||
`main` calls `os.Exit`. SIGINT and SIGTERM go through memguard's
|
`main` calls `os.Exit`. SIGINT and SIGTERM go through memguard's
|
||||||
handler, which wipes every buffer before exiting; on Ctrl-C it first
|
handler, which wipes every buffer before exiting; when the process is
|
||||||
restores the terminal settings from startup, so an interrupted
|
in the terminal's foreground process group it first restores the
|
||||||
passphrase prompt no longer leaves echo off.
|
terminal settings from startup, so an interrupted passphrase prompt no
|
||||||
|
longer leaves echo off.
|
||||||
- 2026-10-02: A plain `docker build .` builds again: the size tests
|
- 2026-10-02: A plain `docker build .` builds again: the size tests
|
||||||
skip a case that needs more locked memory than the process can
|
skip a case that needs more locked memory than the process can
|
||||||
lock, and run every case under `script/cibuild`. The image stamps the
|
lock, and run every case under `script/cibuild`. The image stamps the
|
||||||
|
|||||||
+10
-9
@@ -2,11 +2,11 @@ package cli
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"syscall"
|
|
||||||
|
|
||||||
"git.eeqj.de/sneak/secret/internal/secret"
|
"git.eeqj.de/sneak/secret/internal/secret"
|
||||||
"github.com/awnumar/memguard"
|
"github.com/awnumar/memguard"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
"golang.org/x/term"
|
"golang.org/x/term"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,16 +16,17 @@ import (
|
|||||||
func Entry() int {
|
func Entry() int {
|
||||||
// On SIGINT or SIGTERM memguard runs this function, wipes every buffer
|
// On SIGINT or SIGTERM memguard runs this function, wipes every buffer
|
||||||
// and exits with status 1. The passphrase prompt turns terminal echo
|
// and exits with status 1. The passphrase prompt turns terminal echo
|
||||||
// off until the read finishes, so Ctrl-C there would leave echo off.
|
// off until the read finishes, so a signal there would leave echo off.
|
||||||
// Ctrl-C means this process is in the terminal's foreground and may
|
// Only a process in the terminal's foreground process group may reset
|
||||||
// reset it; doing that from the background would stop the process.
|
// it: one in the background that tries is stopped instead of exiting.
|
||||||
terminalState, terminalErr := term.GetState(syscall.Stdin)
|
terminalState, terminalErr := term.GetState(unix.Stdin)
|
||||||
|
|
||||||
memguard.CatchSignal(func(sig os.Signal) {
|
memguard.CatchSignal(func(os.Signal) {
|
||||||
if sig == os.Interrupt && terminalErr == nil {
|
foreground, err := unix.IoctlGetInt(unix.Stdin, unix.TIOCGPGRP)
|
||||||
_ = term.Restore(syscall.Stdin, terminalState)
|
if terminalErr == nil && err == nil && foreground == unix.Getpgrp() {
|
||||||
|
_ = term.Restore(unix.Stdin, terminalState)
|
||||||
}
|
}
|
||||||
}, os.Interrupt, syscall.SIGTERM)
|
}, os.Interrupt, unix.SIGTERM)
|
||||||
|
|
||||||
defer memguard.Purge()
|
defer memguard.Purge()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user