Skip to content

Commit eac6e03

Browse files
author
goebbert1
committed
switch to using unix-sockets
1 parent 13ddd96 commit eac6e03

File tree

3 files changed

+15
-60
lines changed

3 files changed

+15
-60
lines changed

jupyter_xprahtml5_proxy/__init__.py

Lines changed: 8 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,7 @@ def get_xpra_executable(prog):
3333

3434

3535
def _xprahtml5_urlparams():
36-
from getpass import getuser
37-
38-
url_params = '?' + '&'.join([
39-
'username=' + getuser(),
40-
'password=' + _xprahtml5_passwd,
41-
'encryption=AES',
42-
'key=' + _xprahtml5_aeskey,
43-
'sharing=true',
44-
])
36+
url_params = '?sharing=true'
4537

4638
return url_params
4739

@@ -60,48 +52,12 @@ def setup_xprahtml5():
6052
""" Setup commands and and return a dictionary compatible
6153
with jupyter-server-proxy.
6254
"""
63-
from pathlib import Path
64-
from tempfile import gettempdir, mkstemp, mkdtemp
65-
from random import choice
66-
from string import ascii_letters, digits
67-
68-
global _xprahtml5_passwd, _xprahtml5_aeskey
69-
70-
# password generator
71-
def _get_random_alphanumeric_string(length):
72-
letters_and_digits = ascii_letters + digits
73-
return (''.join((choice(letters_and_digits) for i in range(length))))
55+
from tempfile import mkdtemp
7456

7557
# ensure a known secure sockets directory exists, as /run/user/$UID might not be available
76-
socket_path = mkdtemp(prefix='xpra_sockets_' + str(os.getuid()))
58+
socket_path = mkdtemp(prefix='xpra_sockets_' + str(os.getuid()) + '_')
7759
logger.info('Created secure socket directory for Xpra: ' + socket_path)
7860

79-
# generate file with random one-time-password
80-
_xprahtml5_passwd = _get_random_alphanumeric_string(16)
81-
try:
82-
fd_passwd, fpath_passwd = mkstemp()
83-
logger.info('Created secure password file for Xpra: ' + fpath_passwd)
84-
85-
with open(fd_passwd, 'w') as f:
86-
f.write(_xprahtml5_passwd)
87-
88-
except Exception:
89-
logger.error("Passwd generation in temp file FAILED")
90-
raise FileNotFoundError("Passwd generation in temp file FAILED")
91-
92-
# generate file with random encryption key
93-
_xprahtml5_aeskey = _get_random_alphanumeric_string(16)
94-
try:
95-
fd_aeskey, fpath_aeskey = mkstemp()
96-
logger.info('Created secure encryption key file for Xpra: ' + fpath_aeskey)
97-
98-
with open(fd_aeskey, 'w') as f:
99-
f.write(_xprahtml5_aeskey)
100-
101-
except Exception:
102-
logger.error("Encryption key generation in temp file FAILED")
103-
raise FileNotFoundError("Encryption key generation in temp file FAILED")
104-
10561
# launchers url file including url parameters
10662
path_info = 'xprahtml5/index.html' + _xprahtml5_urlparams()
10763

@@ -110,15 +66,9 @@ def _get_random_alphanumeric_string(length):
11066
get_xpra_executable('xpra'),
11167
'start',
11268
'--html=on',
113-
'--bind-tcp=0.0.0.0:{port}',
114-
# '--socket-dir="' + socket_path + '/"', # fixme: socket_dir not recognized
115-
# '--server-idle-timeout=86400', # stop server after 24h with no client connection
116-
# '--exit-with-client=yes', # stop Xpra when the browser disconnects
69+
'--bind={unix_socket},auth=none', # using sockets + jupyter-server-proxy => auth is not needed here
70+
'--socket-dir=' + socket_path,
11771
'--start=xterm -fa "DejaVu Sans Mono" -fs 14',
118-
# '--start-child=xterm', '--exit-with-children',
119-
'--tcp-auth=file:filename=' + fpath_passwd,
120-
'--tcp-encryption=AES',
121-
'--tcp-encryption-keyfile=' + fpath_aeskey,
12272
'--clipboard-direction=both',
12373
'--no-keyboard-sync', # prevent keys from repeating unexpectedly on high latency
12474
'--no-mdns', # do not advertise the xpra session on the local network
@@ -127,18 +77,19 @@ def _get_random_alphanumeric_string(length):
12777
'--no-printing',
12878
'--no-microphone',
12979
'--no-notifications',
80+
# '--dbus-control=no',
13081
'--no-systemd-run', # do not delegated start-cmd to the system wide proxy server instance
131-
# '--dpi=96', # only needed if Xserver does not support dynamic dpi change
13282
'--sharing', # this allows to open the desktop in multiple browsers at the same time
13383
'--no-daemon', # mandatory
13484
]
13585
logger.info('Xpra command: ' + ' '.join(cmd))
13686

13787
return {
138-
'environment': { # as '--socket-dir' does not work as expected, we set this
88+
'environment': {
13989
'XDG_RUNTIME_DIR': socket_path,
14090
},
14191
'command': cmd,
92+
'unix_socket': socket_path + '/xpra-server',
14293
'mappath': _xprahtml5_mappath,
14394
'absolute_url': False,
14495
'timeout': 90,

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
jupyter-server-proxy>=1.4
1+
jupyter-server-proxy>=4.0
2+
tornado>=6.3

setup.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
with open(path.join(HERE, 'README.md'), 'r', encoding = 'utf-8') as fh:
66
long_description = fh.read()
77

8-
version='0.3.5'
8+
version='0.4.0'
99
setup(
1010
name = 'jupyter-xprahtml5-proxy',
1111
version = version,
@@ -35,7 +35,10 @@
3535
]
3636
},
3737
python_requires = '>=3.6',
38-
install_requires = ['jupyter-server-proxy>=3.1.0'],
38+
install_requires=[
39+
'jupyter-server-proxy>=4.0.0',
40+
'tornado>=6.3'
41+
],
3942
include_package_data = True,
4043
zip_safe = False
4144
)

0 commit comments

Comments
 (0)