From 36e70228f233c81a12a7247ef1a4e4f950b804bf Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 10 Sep 2017 10:55:01 +0200 Subject: [PATCH] Handle invalid key file --- cmd/restic/global.go | 2 +- internal/repository/key.go | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/restic/global.go b/cmd/restic/global.go index d45b21abc..ccfe1b9c0 100644 --- a/cmd/restic/global.go +++ b/cmd/restic/global.go @@ -319,7 +319,7 @@ func OpenRepository(opts GlobalOptions) (*repository.Repository, error) { err = s.SearchKey(context.TODO(), opts.password, maxKeys) if err != nil { - return nil, errors.Fatalf("unable to open repo: %v", err) + return nil, err } return s, nil diff --git a/internal/repository/key.go b/internal/repository/key.go index 2d2235af5..8a9355265 100644 --- a/internal/repository/key.go +++ b/internal/repository/key.go @@ -19,10 +19,10 @@ import ( var ( // ErrNoKeyFound is returned when no key for the repository could be decrypted. - ErrNoKeyFound = errors.New("wrong password or no key found") + ErrNoKeyFound = errors.Fatal("wrong password or no key found") // ErrMaxKeysReached is returned when the maximum number of keys was checked and no key could be found. - ErrMaxKeysReached = errors.New("maximum number of keys reached") + ErrMaxKeysReached = errors.Fatal("maximum number of keys reached") ) // Key represents an encrypted master key for a repository. @@ -133,7 +133,10 @@ func SearchKey(ctx context.Context, s *Repository, password string, maxKeys int) continue } - return nil, err + if err != nil { + debug.Log("unable to open key %v: %v\n", err) + continue + } } debug.Log("successfully opened key %v", name[:12])