def ssl_cert_gen(certfile, keyfile="", hostname="localhost", cwd=None, new=False, clientname=""): """Return fingerprint of self-signed server certficate, creating a new one, if need be""" params = { "certfile": certfile, "keyfile": keyfile or certfile, "hostname": hostname, "keysize": 1024, "expdays": 1024, "clientname": clientname, "clientprefix": "%s-%s" % (hostname, clientname), "clientpassword": "******", } cmd_list = server_cert_gen_cmds if new else server_cert_gen_cmds[-1:] for cmd in cmd_list: cmd_args = pyxshell.shlex_split_str(cmd % params) std_out, std_err = pyxshell.command_output(cmd_args, cwd=cwd, timeout=15) if std_err: logging.warning("pyxterm: SSL keygen %s %s", std_out, std_err) fingerprint = std_out if new and clientname: for cmd in client_cert_gen_cmds: cmd_args = pyxshell.shlex_split_str(cmd % params) std_out, std_err = pyxshell.command_output(cmd_args, cwd=cwd, timeout=15) if std_err: logging.warning("pyxterm: SSL client keygen %s %s", std_out, std_err) return fingerprint
def ssl_cert_gen(certfile, keyfile="", hostname="localhost", cwd=None, new=False, clientname=""): """Return fingerprint of self-signed server certficate, creating a new one, if need be""" params = {"certfile": certfile, "keyfile": keyfile or certfile, "hostname": hostname, "keysize": 1024, "expdays": 1024, "clientname": clientname, "clientprefix":"%s-%s" % (hostname, clientname), "clientpassword": "******",} cmd_list = server_cert_gen_cmds if new else server_cert_gen_cmds[-1:] for cmd in cmd_list: cmd_args = pyxshell.shlex_split_str(cmd % params) std_out, std_err = pyxshell.command_output(cmd_args, cwd=cwd, timeout=15) if std_err: logging.warning("pyxterm: SSL keygen %s %s", std_out, std_err) fingerprint = std_out if new and clientname: for cmd in client_cert_gen_cmds: cmd_args = pyxshell.shlex_split_str(cmd % params) std_out, std_err = pyxshell.command_output(cmd_args, cwd=cwd, timeout=15) if std_err: logging.warning("pyxterm: SSL client keygen %s %s", std_out, std_err) return fingerprint
def open_browser(url, browser=""): if sys.platform.startswith("linux"): command_args = ["xdg-open"] else: command_args = ["open"] if browser: command_args += ["-a", browser] command_args.append(url) return pyxshell.command_output(command_args, timeout=5)