From f144920ed555ae8da0c944cc4043f391f1fc0caf Mon Sep 17 00:00:00 2001 From: Jayson Wang Date: Mon, 30 May 2022 15:54:32 +0800 Subject: [PATCH 1/3] fix handling of maxKeys in SearchKey --- changelog/unreleased/pull-3776 | 10 ++++++++++ internal/repository/key.go | 1 + 2 files changed, 11 insertions(+) create mode 100644 changelog/unreleased/pull-3776 diff --git a/changelog/unreleased/pull-3776 b/changelog/unreleased/pull-3776 new file mode 100644 index 000000000..dd836c736 --- /dev/null +++ b/changelog/unreleased/pull-3776 @@ -0,0 +1,10 @@ +Bugfix: Limit number of key files tested while opening a repository + +Previously, restic tested the password against every key in the repository, when +there are more and more keys in the repository, opening the repository becomes +slower and slower. + +Now restic tests password up to 20 times on the key file in the repository, or +you can use `-key-hint=` to specify the key file to be used. + +https://github.com/restic/restic/pull/3776 diff --git a/internal/repository/key.go b/internal/repository/key.go index 8c62d7e36..67f27f204 100644 --- a/internal/repository/key.go +++ b/internal/repository/key.go @@ -137,6 +137,7 @@ func SearchKey(ctx context.Context, s *Repository, password string, maxKeys int, // try at most maxKeys keys in repo err = s.Backend().List(listCtx, restic.KeyFile, func(fi restic.FileInfo) error { + checked++ if maxKeys > 0 && checked > maxKeys { return ErrMaxKeysReached } From d08549f0aefa83c1a5241f960c325a1732c4ad2e Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 12 Jun 2022 14:18:02 +0200 Subject: [PATCH 2/3] fix flaky key test --- cmd/restic/integration_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/restic/integration_test.go b/cmd/restic/integration_test.go index 792b825c2..cefea852a 100644 --- a/cmd/restic/integration_test.go +++ b/cmd/restic/integration_test.go @@ -1040,7 +1040,7 @@ func testRunKeyAddNewKeyUserHost(t testing.TB, gopts GlobalOptions) { repo, err := OpenRepository(gopts) rtest.OK(t, err) - key, err := repository.SearchKey(gopts.ctx, repo, testKeyNewPassword, 1, "") + key, err := repository.SearchKey(gopts.ctx, repo, testKeyNewPassword, 2, "") rtest.OK(t, err) rtest.Equals(t, "john", key.Username) From c9ef873192b7ecf0ef399a028274011f1347bf0f Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 12 Jun 2022 15:39:06 +0200 Subject: [PATCH 3/3] tweak password test count changelog --- changelog/unreleased/pull-3776 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/changelog/unreleased/pull-3776 b/changelog/unreleased/pull-3776 index dd836c736..2fd203203 100644 --- a/changelog/unreleased/pull-3776 +++ b/changelog/unreleased/pull-3776 @@ -4,7 +4,7 @@ Previously, restic tested the password against every key in the repository, when there are more and more keys in the repository, opening the repository becomes slower and slower. -Now restic tests password up to 20 times on the key file in the repository, or -you can use `-key-hint=` to specify the key file to be used. +Now restic tests password against up to 20 key file in the repository. Alternatively, +you can use `--key-hint=` to specify the key file to be used. https://github.com/restic/restic/pull/3776