Skip to content

Commit

Permalink
dulwich: try default keys when no identity is set in asyncssh vendor
Browse files Browse the repository at this point in the history
  • Loading branch information
pmrowla committed Jul 25, 2023
1 parent 2f9c281 commit 67435a0
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/scmrepo/git/backend/dulwich/asyncssh_vendor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand Down

0 comments on commit 67435a0

Please sign in to comment.