mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 01:16:10 +00:00
fix(instances): a VNC password the browser console can send, kept as set
The console settings accepted any password of at most 8 bytes, so "éééé" was saved, but noVNC derives its key from the characters while QEMU compares the UTF-8 bytes: the browser console could not log in. A new password now takes up to 8 printable ASCII characters, which also keeps control characters out of the definition. The .vv file wrote the password and the VM name as they are; virt-viewer reads it as a GLib key file, so a backslash or a leading space changed the password. Both are escaped as a key file expects. A new or removed password also drops a passwdValidTo set elsewhere: an expired one left the new password unusable.
This commit is contained in:
parent
275bf11aed
commit
cd3edf4dff
11 changed files with 257 additions and 222 deletions
|
|
@ -1706,8 +1706,9 @@ class wvmInstance(wvmConnect):
|
|||
if passwd:
|
||||
graphic.set("passwd", passwd)
|
||||
else:
|
||||
with contextlib.suppress(Exception):
|
||||
graphic.attrib.pop("passwd")
|
||||
graphic.attrib.pop("passwd", None)
|
||||
# an expiry set elsewhere would leave the new password unusable
|
||||
graphic.attrib.pop("passwdValidTo", None)
|
||||
|
||||
newxml = etree.tostring(root).decode()
|
||||
return self._defineXML(newxml)
|
||||
|
|
@ -2521,6 +2522,7 @@ class wvmInstance(wvmConnect):
|
|||
# the clone's console gets a password of its own: one copied from the source would open both
|
||||
for graphics in tree.findall("devices/graphics[@type='vnc']"):
|
||||
graphics.set("passwd", util.randomPasswd(8)) # the length VNC allows
|
||||
graphics.attrib.pop("passwdValidTo", None) # an expired source's would leave it unusable
|
||||
|
||||
nvram = tree.find("os/nvram")
|
||||
if nvram is not None and nvram.get("type", "file") != "file":
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ Its NIC filters keep no address of the source's."""
|
|||
|
||||
import unittest
|
||||
|
||||
from lxml import etree
|
||||
|
||||
from vrtManager.instance import wvmInstance
|
||||
|
||||
|
||||
|
|
@ -23,6 +25,10 @@ class CloneConsoleTestCase(unittest.TestCase):
|
|||
self.assertEqual(len(passwords), 5)
|
||||
self.assertTrue(all(len(p) == 8 for p in passwords)) # the length VNC allows
|
||||
|
||||
def test_a_clone_keeps_no_password_expiry_of_its_source(self):
|
||||
graphics = clone_graphics("passwd='shared12' passwdValidTo='2000-01-01T00:00:00'")
|
||||
self.assertIsNone(graphics.get("passwdValidTo"))
|
||||
|
||||
def test_a_source_without_a_password_gives_a_clone_with_one(self):
|
||||
self.assertEqual(len(clone_graphics("").get("passwd")), 8)
|
||||
|
||||
|
|
@ -48,3 +54,18 @@ class CloneConsoleTestCase(unittest.TestCase):
|
|||
tree, _ = p._clone_definition({"name": "copy", "clone-net-mac-0": "52:54:00:00:00:02"},
|
||||
"abababab-0000-1111-2222-333333333333")
|
||||
self.assertEqual(tree.xpath("devices/interface/filterref/parameter/@name"), ["IP", "IPV6", "CTRL_IP_LEARNING"])
|
||||
|
||||
|
||||
class ConsolePasswordTestCase(unittest.TestCase):
|
||||
def test_a_new_password_drops_an_expiry_set_elsewhere(self):
|
||||
# an expired passwdValidTo would leave the new password unusable
|
||||
p = wvmInstance.__new__(wvmInstance)
|
||||
p._XMLDesc = lambda flags: """<domain><devices><graphics type='vnc' passwd='old12345'
|
||||
passwdValidTo='2000-01-01T00:00:00'/></devices></domain>"""
|
||||
for password in ("new12345", ""):
|
||||
with self.subTest(password=password):
|
||||
defined = []
|
||||
p._defineXML = defined.append
|
||||
p.set_console_passwd(password)
|
||||
graphic = etree.fromstring(defined[0]).find("devices/graphics")
|
||||
self.assertEqual((graphic.get("passwd"), graphic.get("passwdValidTo")), (password or None, None))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue