425c299359
v1: discover → migrate → expiry tracking → sealed export/import. - vault: memguard mlock/DONTDUMP arena, handle indirection, zeroize-on-drop - discover: registry + 8 read-only scanners (aws, env, netrc, ssh, docker, kube, git) and a file/dir harvester (--path) - sink: gopass streaming insert; length-prefixed bundle framing; Sealer interface with three impls — age (default, authenticated), hmac (authenticated, openssl-only encrypt-then-MAC), openssl (CBC fallback, unauthenticated; OpenSSL 3.x enc refuses AEAD) - policy: local expiry engine, 60d/8w threshold parser - audit: redacted append-only JSONL, injectable clock - export/import: passphrase from no-echo prompt or $INCREDIGO_PASSPHRASE into locked memory; secrets stream gopass<->Sealer as bytes, never Go strings - tests: scanner leak-checks, vault zeroize, bundle round-trip via fake gopass; go test ./... green, -race clean Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
72 lines
1.4 KiB
Go
72 lines
1.4 KiB
Go
package discover
|
|
|
|
import (
|
|
"bufio"
|
|
"context"
|
|
"net/url"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"incredigo/internal/vault"
|
|
)
|
|
|
|
func init() { Register(&gitScanner{}) }
|
|
|
|
// gitScanner reads ~/.git-credentials, whose lines are URLs with embedded
|
|
// credentials, e.g. https://user:ghp_xxx@github.com. The userinfo password is the
|
|
// secret. Read-only.
|
|
type gitScanner struct{}
|
|
|
|
func (g *gitScanner) Name() string { return "git" }
|
|
|
|
func (g *gitScanner) path() string {
|
|
home, _ := os.UserHomeDir()
|
|
return filepath.Join(home, ".git-credentials")
|
|
}
|
|
|
|
func (g *gitScanner) Available() bool {
|
|
_, err := os.Stat(g.path())
|
|
return err == nil
|
|
}
|
|
|
|
func (g *gitScanner) Scan(ctx context.Context, v *vault.Vault) ([]Credential, error) {
|
|
p := g.path()
|
|
f, err := os.Open(p) // read-only
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer f.Close()
|
|
fi, _ := f.Stat()
|
|
|
|
var creds []Credential
|
|
sc := bufio.NewScanner(f)
|
|
for sc.Scan() {
|
|
line := strings.TrimSpace(sc.Text())
|
|
if line == "" || strings.HasPrefix(line, "#") {
|
|
continue
|
|
}
|
|
u, err := url.Parse(line)
|
|
if err != nil || u.User == nil {
|
|
continue
|
|
}
|
|
pass, ok := u.User.Password()
|
|
if !ok || pass == "" {
|
|
continue
|
|
}
|
|
id := u.Host
|
|
if user := u.User.Username(); user != "" {
|
|
id = user + " @ " + u.Host
|
|
}
|
|
creds = append(creds, Credential{
|
|
Source: g.Name(),
|
|
Kind: KindToken,
|
|
Identity: id,
|
|
Location: p,
|
|
Modified: fi.ModTime(),
|
|
Secret: v.Store([]byte(pass)),
|
|
})
|
|
}
|
|
return creds, sc.Err()
|
|
}
|