From 12658c47562c4038aeeae90c2ac851792e4050ea Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 26 Feb 2022 15:20:48 +0530 Subject: [PATCH] Make ssh data start request transmission more robust --- kittens/ssh/main.py | 7 ++++++- shell-integration/ssh/bootstrap.sh | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/kittens/ssh/main.py b/kittens/ssh/main.py index f5c66c8f5..73c38197a 100644 --- a/kittens/ssh/main.py +++ b/kittens/ssh/main.py @@ -10,6 +10,7 @@ import sys import tarfile import tempfile import time +from base64 import standard_b64decode from contextlib import suppress from typing import ( Any, Dict, Iterator, List, NoReturn, Optional, Set, Tuple, Union @@ -62,7 +63,11 @@ def get_ssh_data(msg: str, shell_integration_dest: str = DEFAULT_SHELL_INTEGRATI return f'\036{msg}:'.encode('ascii') try: - hostname, pwfilename, pw = msg.split(':', 2) + msg = standard_b64decode(msg).decode('utf-8') + md = dict(x.split('=', 1) for x in msg.split(':')) + hostname = md['hostname'] + pw = md['pw'] + pwfilename = md['pwfile'] except Exception: yield fmt_prefix('!invalid ssh data request message') try: diff --git a/shell-integration/ssh/bootstrap.sh b/shell-integration/ssh/bootstrap.sh index 44890a0d9..3f4065a64 100644 --- a/shell-integration/ssh/bootstrap.sh +++ b/shell-integration/ssh/bootstrap.sh @@ -8,7 +8,7 @@ cleanup_on_bootstrap_exit() { } die() { printf "\033[31m%s\033[m\n" "$*" > /dev/stderr; cleanup_on_bootstrap_exit; exit 1; } -dsc_to_kitty() { printf "\033P@kitty-$1|%s\033\\" "$(printf "%s" "$2" | base64)" > /dev/tty; } +dsc_to_kitty() { printf "\033P@kitty-$1|%s\033\\" "$(printf "%s" "$2" | base64 | tr -d \\n)" > /dev/tty; } debug() { dsc_to_kitty "print" "debug $1"; } echo_via_kitty() { dsc_to_kitty "echo" "$1"; } saved_tty_settings=$(command stty -g) @@ -34,7 +34,7 @@ password_filename="PASSWORD_FILENAME" data_complete="n" leading_data="" -printf "\033P@kitty-ssh|%s:%s:%s\033\\" "$hostname" "$password_filename" "$data_password" +dsc_to_kitty "ssh" "hostname=$hostname:pwfile=$password_filename:pw=$data_password" size="" untar() {