Start work on SSH askpass implementation

This commit is contained in:
Kovid Goyal
2022-03-10 17:26:47 +05:30
parent 910565aa7c
commit 3b724c8415
6 changed files with 72 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
#!/usr/bin/env -S kitty +launch
# License: GPLv3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
import json
import os
import struct
import sys
from kitty.shm import SharedMemory
msg = sys.argv[-1]
prompt = os.environ.get('SSH_ASKPASS_PROMPT', '')
is_confirm = prompt == 'confirm'
ask_cmdline = ['-m', msg, '--type', 'yesno' if is_confirm else 'password']
if is_confirm:
ask_cmdline += ['--default', 'y']
data = json.dumps(ask_cmdline).encode('utf-8')
sz = struct.pack('>I', len(data))
with SharedMemory(size=len(data) + len(sz) + 1, unlink_on_exit=True, prefix=f'askpass-{os.getpid()}-') as shm, open(os.ctermid(), 'wb') as tty:
shm.write(b'\0')
shm.write(sz)
shm.write(data)
shm.flush()
print(f'\x1bP@kitty-ask|{shm.name}\x1b\\', flush=True)