Skip to content

ssh client: implement password_auth_requested #403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions src/scmrepo/git/backend/dulwich/asyncssh_vendor.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ async def _read_all(read: Callable[[int], Coroutine], n: Optional[int] = None) -
return b"".join(result)


async def _getpass(*args, **kwargs) -> str:
from getpass import getpass

return await asyncio.to_thread(getpass, *args, **kwargs)


class _StderrWrapper:
def __init__(self, stderr: "SSHReader", loop: asyncio.AbstractEventLoop) -> None:
self.stderr = stderr
Expand Down Expand Up @@ -202,8 +208,6 @@ async def public_key_auth_requested( # noqa: C901
return None

async def _read_private_key_interactive(self, path: "FilePath") -> "SSHKey":
from getpass import getpass

from asyncssh.public_key import (
KeyEncryptionError,
KeyImportError,
Expand All @@ -215,11 +219,8 @@ async def _read_private_key_interactive(self, path: "FilePath") -> "SSHKey":
if passphrase:
return read_private_key(path, passphrase=passphrase)

loop = asyncio.get_running_loop()
for _ in range(3):
passphrase = await loop.run_in_executor(
None, getpass, f"Enter passphrase for key '{path}': "
)
passphrase = await _getpass(f"Enter passphrase for key {path!r}: ")
if passphrase:
try:
key = read_private_key(path, passphrase=passphrase)
Expand All @@ -239,23 +240,20 @@ async def kbdint_challenge_received( # pylint: disable=invalid-overridden-metho
lang: str,
prompts: "KbdIntPrompts",
) -> Optional["KbdIntResponse"]:
from getpass import getpass

if os.environ.get("GIT_TERMINAL_PROMPT") == "0":
return None

def _getpass(prompt: str) -> str:
return getpass(prompt=prompt).rstrip()

if instructions:
pass
loop = asyncio.get_running_loop()
return [
await loop.run_in_executor(
None, _getpass, f"({name}) {prompt}" if name else prompt
)
for prompt, _ in prompts
]

response: list[str] = []
for prompt, _echo in prompts:
p = await _getpass(f"({name}) {prompt}" if name else prompt)
response.append(p.rstrip())
return response

async def password_auth_requested(self) -> str:
return await _getpass()


class AsyncSSHVendor(BaseAsyncObject, SSHVendor):
Expand Down
2 changes: 1 addition & 1 deletion tests/vendor/test_paramiko_vendor.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def check_channel_request(self, kind, chanid):
return paramiko.OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED

def get_allowed_auths(self, username):
return "password,publickey"
return "publickey"


USER = "testuser"
Expand Down
Loading