Only use kitty's askpass if DISPLAY is set or OpenSSH is new enough to support SSH_ASKPASS_REQUIRE

This commit is contained in:
Kovid Goyal 2022-03-15 15:47:02 +05:30
parent f982e754e4
commit 5099dd6aa3
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -501,6 +501,15 @@ def dcs_to_kitty(payload: Union[bytes, str], type: str = 'ssh') -> bytes:
return b'\033P@kitty-' + type.encode('ascii') + b'|' + payload + b'\033\\'
@run_once
def ssh_version() -> Tuple[int, int]:
o = subprocess.check_output(['ssh', '-V'], stderr=subprocess.STDOUT).decode()
m = re.match(r'OpenSSH_(\d+).(\d+)', o)
if m is None:
raise ValueError(f'Invalid version string for OpenSSH: {o}')
return int(m.group(1)), int(m.group(2))
@contextmanager
def drain_potential_tty_garbage(p: 'subprocess.Popen[bytes]', data_request: str) -> Iterator[None]:
ssh_started_at = time.monotonic()
@ -562,10 +571,14 @@ def run_ssh(ssh_args: List[str], server_args: List[str], found_extra_args: Tuple
if use_control_master:
cmd[insertion_point:insertion_point] = connection_sharing_args(host_opts, int(os.environ['KITTY_PID']))
use_kitty_askpass = host_opts.askpass == 'native' or (host_opts.askpass == 'unless-set' and 'SSH_ASKPASS' not in os.environ)
need_to_request_data = not use_kitty_askpass
if use_kitty_askpass:
os.environ['SSH_ASKPASS_REQUIRE'] = 'force'
os.environ['SSH_ASKPASS'] = os.path.join(shell_integration_dir, 'ssh', 'askpass.py')
# SSH_ASKPASS_REQUIRE was introduced in 8.4 release on 2020-09-27
if os.environ.get('DISPLAY') or ssh_version() >= (8, 4):
os.environ['SSH_ASKPASS_REQUIRE'] = 'force'
os.environ['SSH_ASKPASS'] = os.path.join(shell_integration_dir, 'ssh', 'askpass.py')
else:
use_kitty_askpass = False
need_to_request_data = not use_kitty_askpass
with restore_terminal_state() as echo_on:
rcmd, replacements, shm_name = get_remote_command(
remote_args, host_opts, hostname, hostname_for_match, uname, echo_on, request_data=need_to_request_data)