Skip to content

Commit

Permalink
Improve passage support
Browse files Browse the repository at this point in the history
This commit adds parsing of unencrypted passage identities and
automatically mounts an existing passage store under the mount
point passage/ if it's detected during setup (not later).

Fixes gopasspw#2059

RELEASE_NOTES=[ENHANCEMENT] Improve passage support

Signed-off-by: Dominik Schulz <[email protected]>
  • Loading branch information
dominikschulz committed Sep 25, 2022
1 parent ce745ca commit 19ebfe5
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
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 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

0 comments on commit 19ebfe5

Please sign in to comment.