Merge pull request #3776 from wjiec/bugfix/maxkeys-in-search

Limit number of key files tested while opening a repository
This commit is contained in:
MichaelEischer 2022-06-12 15:51:10 +02:00 committed by GitHub
commit 0c0e7b6957
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 1 deletions

View File

@ -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 against up to 20 key file in the repository. Alternatively,
you can use `--key-hint=<Key ID>` to specify the key file to be used.
https://github.com/restic/restic/pull/3776

View File

@ -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)

View File

@ -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
}