def do_process_challenge_prompt(self, packet, prompt="password"): authlog("do_process_challenge_prompt() use_tty=%s", use_tty()) if use_tty(): import getpass authlog("stdin isatty, using password prompt") password = getpass.getpass("%s :" % self.get_challenge_prompt(prompt)) authlog("password read from tty via getpass: %s", obsc(password)) self.send_challenge_reply(packet, password) return True else: from xpra.platform.paths import get_nodock_command cmd = get_nodock_command() + ["_pass", prompt] try: from subprocess import Popen, PIPE proc = Popen(cmd, stdout=PIPE) getChildReaper().add_process(proc, "password-prompt", cmd, True, True) out, err = proc.communicate(None, 60) authlog("err(%s)=%s", cmd, err) password = out.decode() self.send_challenge_reply(packet, password) return True except Exception: log("Error: failed to show GUi for password prompt", exc_info=True) return False
def do_process_challenge_prompt(self, packet, prompt="password"): authlog("do_process_challenge_prompt() use_tty=%s", use_tty()) if use_tty(): import getpass authlog("stdin isatty, using password prompt") password = getpass.getpass("%s :" % self.get_challenge_prompt(prompt)) authlog("password read from tty via getpass: %s", obsc(password)) self.send_challenge_reply(packet, password) return True return False
def confirm_key(info=()) -> bool: if SKIP_UI: return False from xpra.platform.paths import get_icon_filename from xpra.os_util import use_tty if not use_tty(): icon = get_icon_filename("authentication", "png") or "" prompt = "Are you sure you want to continue connecting?" code = dialog_confirm("Confirm Key", prompt, info, icon, buttons=[("yes", 200), ("NO", 201)]) log("dialog return code=%s", code) r = code == 200 log.info("host key %sconfirmed", ["not ", ""][r]) return r log("confirm_key(%s) will use stdin prompt", nonl(info)) prompt = "Are you sure you want to continue connecting (yes/NO)? " sys.stderr.write(os.linesep.join(info) + os.linesep + prompt) try: v = sys.stdin.readline().rstrip(os.linesep) except KeyboardInterrupt: sys.exit(128 + signal.SIGINT) return v and v.lower() in ("y", "yes")
def input_pass(prompt) -> str: if SKIP_UI: return None from xpra.platform.paths import get_icon_filename from xpra.os_util import use_tty if not use_tty(): icon = get_icon_filename("authentication", "png") or "" return dialog_pass("Password Input", prompt, icon) from getpass import getpass try: return getpass(prompt) except KeyboardInterrupt: sys.exit(128+signal.SIGINT)
def input_pass(prompt): if SKIP_UI: return None from xpra.platform.paths import get_icon_filename from xpra.os_util import use_tty if not use_tty(): icon = get_icon_filename("authentication", "png") code, out = dialog_pass("Password Input", prompt, icon) log.debug("pass dialog output return code=%s", code) if code != 0: return None return out from getpass import getpass return getpass(prompt)
def confirm_key(info=[]): if SKIP_UI: return False from xpra.platform.paths import get_icon_filename from xpra.os_util import use_tty if not use_tty(): icon = get_icon_filename("authentication", "png") or "" prompt = "Are you sure you want to continue connecting?" code, out = dialog_confirm("Confirm Key", prompt, info, icon, buttons=[("yes", 200), ("NO", 201)]) log.debug("dialog output: '%s', return code=%s", nonl(out), code) r = code==200 log.info("host key %sconfirmed", ["not ", ""][r]) return r prompt = "Are you sure you want to continue connecting (yes/NO)? " sys.stderr.write(os.linesep.join(info)+os.linesep+prompt) v = sys.stdin.readline().rstrip(os.linesep) return v and v.lower() in ("y", "yes")
def main(): from xpra.platform import program_context with program_context("U2F-Register", "Xpra U2F Registration Tool"): if not use_tty(): from xpra.gtk_common.gobject_compat import import_gtk, import_glib gtk = import_gtk() glib = import_glib() from xpra.gtk_common.gtk_util import MESSAGE_INFO, MESSAGE_ERROR, BUTTONS_CLOSE def show_dialog(mode, *msgs): dialog = gtk.MessageDialog(None, 0, mode, BUTTONS_CLOSE, "\n".join(msgs)) dialog.set_title("Xpra U2F Registration Tool") v = dialog.run() dialog.destroy() #run the main loop long enough to destroy the dialog: glib.idle_add(gtk.main_quit) gtk.main() return v def error(*msgs): return show_dialog(MESSAGE_ERROR, *msgs) def info(*msgs): return show_dialog(MESSAGE_INFO, *msgs) else: print("U2F Registration Tool") def printmsgs(*msgs): for x in msgs: print(x) error = info = printmsgs key_handle_filenames = [ os.path.join(d, "u2f-keyhandle.hex") for d in get_user_conf_dirs() ] assert len(key_handle_filenames) > 0 for filename in key_handle_filenames: p = osexpand(filename) key_handle_str = load_binary_file(p) if key_handle_str: error( " found an existing key handle in file '%s':" % p, #" %s" % key_handle_str, " skipping U2F registration", " delete this file if you want to register again") return 1 public_key_filenames = [] for d in get_user_conf_dirs(): public_key_filenames += glob.glob(os.path.join(d, "u2f*.pub")) if public_key_filenames: info( " found %i existing public key%s" % (len(public_key_filenames, engs(public_key_filenames))), *((" - %s" % x) for x in public_key_filenames)) #pick the first directory: conf_dir = osexpand(get_user_conf_dirs()[0]) if not os.path.exists(conf_dir): os.mkdir(conf_dir) from pyu2f.u2f import GetLocalU2FInterface #@UnresolvedImport try: dev = GetLocalU2FInterface() except Exception as e: error("Failed to open local U2F device:", "%s" % (str(e) or type(e))) return 1 info("Please activate your U2F device now to generate a new key") registered_keys = [] challenge = b'01234567890123456789012345678901' #unused rr = dev.Register(APP_ID, challenge, registered_keys) b = rr.registration_data assert b[0] == 5 pubkey = bytes(b[1:66]) khl = b[66] key_handle = bytes(b[67:67 + khl]) #save to files: key_handle_filename = osexpand(key_handle_filenames[0]) f = open(key_handle_filename, "wb") f.write(hexstr(key_handle).encode()) f.close #find a filename we can use for this public key: i = 1 while True: c = "" if i > 1: c = "-%i" public_key_filename = os.path.join(conf_dir, "u2f%s-pub.hex" % c) if not os.path.exists(public_key_filename): break f = open(public_key_filename, "wb") f.write(hexstr(pubkey).encode()) f.close #info("key handle: %s" % csv(hex40(key_handle)), # "saved to file '%s'" % key_handle_filename, # "public key: %s" % csv(hex40(pubkey)), # "saved to file '%s'" % public_key_filename, # ) info( "key handle saved to file:", "'%s'" % key_handle_filename, "public key saved to file:", "'%s'" % public_key_filename, ) return 0