Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve passage support #2352

Merged
merged 2 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions internal/action/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"path/filepath"

"github.com/fatih/color"
"github.com/gopasspw/gopass/internal/action/exit"
Expand All @@ -15,6 +16,7 @@ import (
"github.com/gopasspw/gopass/internal/store/root"
"github.com/gopasspw/gopass/pkg/ctxutil"
"github.com/gopasspw/gopass/pkg/debug"
"github.com/gopasspw/gopass/pkg/fsutil"
"github.com/gopasspw/gopass/pkg/pwgen/xkcdgen"
"github.com/gopasspw/gopass/pkg/termio"
"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -285,6 +287,11 @@ func (s *Action) initLocal(ctx context.Context) error {
}
// TODO remotes for fossil, etc.

// detect and add mount a for passage
if err := s.initDetectPassage(ctx); err != nil {
out.Warningf(ctx, "Failed to add passage mount: %s", err)
}

// save config.
if err := s.cfg.Save(); err != nil {
return fmt.Errorf("failed to save config: %w", err)
Expand All @@ -295,6 +302,25 @@ func (s *Action) initLocal(ctx context.Context) error {
return nil
}

func (s *Action) initDetectPassage(ctx context.Context) error {
pIds := age.PassageIdFile()
if !fsutil.IsFile(pIds) {
debug.Log("no passage identities found at %s", pIds)

return nil
}

pDir := filepath.Dir(pIds)

if err := s.Store.AddMount(ctx, "passage", pDir); err != nil {
return fmt.Errorf("failed to mount passage dir: %w", err)
}

out.OKf(ctx, "Detected passage store at %s. Mounted below passage/.", pDir)

return nil
}

// initCreateTeam will create a local root store and a shared team store.
func (s *Action) initCreateTeam(ctx context.Context, team, remote string) error {
var err error
Expand Down
35 changes: 33 additions & 2 deletions internal/backend/crypto/age/identities.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"

"filippo.io/age"
"github.com/gopasspw/gopass/pkg/appdir"
"github.com/gopasspw/gopass/pkg/ctxutil"
"github.com/gopasspw/gopass/pkg/debug"
)
Expand Down Expand Up @@ -250,12 +251,42 @@ func (a *Age) getAllIdentities(ctx context.Context) (map[string]age.Identity, er
}
debug.Log("got %d merged identities", len(native))

// TODO(gh/2059) add passage identities from
// $HOME/.passage/identities
ps, err := a.getPassageIdentities(ctx)
if err != nil {
debug.Log("unable to load passage identities: %s", err)
}

// merge
for k, v := range ps {
native[k] = v
}

return native, nil
}

func (a *Age) getPassageIdentities(ctx context.Context) (map[string]age.Identity, error) {
fn := PassageIdFile()
fh, err := os.Open(fn)
if err != nil {
return nil, fmt.Errorf("failed to open %s: %w", fn, err)
}
defer func() { _ = fh.Close() }()

ids, err := age.ParseIdentities(fh)
if err != nil {
return nil, err
}

// TODO(gh/2059) support encrypted passage identities

return idMap(ids), nil
}

// PassageIdFile returns the location of the passage identities file.
func PassageIdFile() string {
return filepath.Join(appdir.UserHome(), ".passage", "identities")
}

func (a *Age) getNativeIdentities(ctx context.Context) (map[string]age.Identity, error) {
ids, err := a.Identities(ctx)
if err != nil {
Expand Down