From 67435a0104e4ec366d044a449cfb88c90ad8357f Mon Sep 17 00:00:00 2001 From: Peter Rowlands Date: Tue, 25 Jul 2023 16:56:37 +0900 Subject: [PATCH] dulwich: try default keys when no identity is set in asyncssh vendor --- src/scmrepo/git/backend/dulwich/asyncssh_vendor.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/scmrepo/git/backend/dulwich/asyncssh_vendor.py b/src/scmrepo/git/backend/dulwich/asyncssh_vendor.py index d532cab0..978905ce 100644 --- a/src/scmrepo/git/backend/dulwich/asyncssh_vendor.py +++ b/src/scmrepo/git/backend/dulwich/asyncssh_vendor.py @@ -154,6 +154,7 @@ async def public_key_auth_requested( # pylint: disable=invalid-overridden-metho self, ) -> Optional["KeyPairListArg"]: from asyncssh.public_key import ( + _DEFAULT_KEY_FILES, KeyImportError, SSHLocalKeyPair, read_private_key, @@ -169,12 +170,20 @@ async def public_key_auth_requested( # pylint: disable=invalid-overridden-metho options = self._conn._options # pylint: disable=protected-access config = options.config client_keys = cast(Sequence["FilePath"], config.get("IdentityFile", ())) + if not client_keys: + client_keys = [ + os.path.expanduser(os.path.join("~", ".ssh", path)) + for path, cond in _DEFAULT_KEY_FILES + if cond + ] for key_to_load in client_keys: try: read_private_key(key_to_load, passphrase=options.passphrase) except KeyImportError as exc: if str(exc).startswith("Passphrase"): self._keys_to_try.append(key_to_load) + except OSError: + pass while self._keys_to_try: key_to_load = self._keys_to_try.pop()