mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
Cleanup gnome-keyring code (still broken with introspection)
This commit is contained in:
parent
5df0a108f8
commit
cb512f61e7
@ -35,7 +35,6 @@ src/virtManager/network.py
|
|||||||
src/virtManager/packageutils.py
|
src/virtManager/packageutils.py
|
||||||
src/virtManager/preferences.py
|
src/virtManager/preferences.py
|
||||||
src/virtManager/remote.py
|
src/virtManager/remote.py
|
||||||
src/virtManager/secret.py
|
|
||||||
src/virtManager/serialcon.py
|
src/virtManager/serialcon.py
|
||||||
src/virtManager/storagebrowse.py
|
src/virtManager/storagebrowse.py
|
||||||
src/virtManager/storagepool.py
|
src/virtManager/storagepool.py
|
||||||
|
@ -25,8 +25,8 @@ from gi.repository import GConf
|
|||||||
|
|
||||||
import virtinst
|
import virtinst
|
||||||
|
|
||||||
from virtManager.keyring import vmmKeyring
|
from virtManager.keyring import vmmKeyring, vmmSecret
|
||||||
from virtManager.secret import vmmSecret
|
|
||||||
|
|
||||||
class vmmConfig(object):
|
class vmmConfig(object):
|
||||||
|
|
||||||
@ -735,47 +735,31 @@ class vmmConfig(object):
|
|||||||
|
|
||||||
def has_keyring(self):
|
def has_keyring(self):
|
||||||
if self.keyring is None:
|
if self.keyring is None:
|
||||||
logging.warning("Initializing keyring")
|
|
||||||
self.keyring = vmmKeyring()
|
self.keyring = vmmKeyring()
|
||||||
return self.keyring.is_available()
|
return self.keyring.is_available()
|
||||||
|
|
||||||
def clear_console_password(self, vm):
|
|
||||||
_id = self.conf.get_int(self.conf_dir + "/console/passwords/" + vm.get_uuid())
|
|
||||||
|
|
||||||
if _id is not None:
|
|
||||||
if not(self.has_keyring()):
|
|
||||||
return
|
|
||||||
|
|
||||||
if self.keyring.clear_secret(_id):
|
|
||||||
self.conf.unset(self.conf_dir + "/console/passwords/" + vm.get_uuid())
|
|
||||||
|
|
||||||
def get_console_password(self, vm):
|
def get_console_password(self, vm):
|
||||||
_id = self.conf.get_int(self.conf_dir + "/console/passwords/" + vm.get_uuid())
|
keyid = self.conf.get_int(self.conf_dir +
|
||||||
username = self.conf.get_string(self.conf_dir + "/console/usernames/" + vm.get_uuid())
|
"/console/passwords/" + vm.get_uuid())
|
||||||
|
username = self.conf.get_string(self.conf_dir +
|
||||||
|
"/console/usernames/" + vm.get_uuid())
|
||||||
|
|
||||||
if username is None:
|
if keyid is None or not self.has_keyring():
|
||||||
username = ""
|
return ("", "")
|
||||||
|
|
||||||
if _id is not None:
|
secret = self.keyring.get_secret(keyid)
|
||||||
if not(self.has_keyring()):
|
if secret is None or secret.get_name() != self.get_secret_name(vm):
|
||||||
return ("", "")
|
return ("", "")
|
||||||
|
|
||||||
secret = self.keyring.get_secret(_id)
|
if (secret.attributes.get("hvuri", None) != vm.conn.get_uri() or
|
||||||
if secret is not None and secret.get_name() == self.get_secret_name(vm):
|
secret.attributes.get("uuid", None) != vm.get_uuid()):
|
||||||
if not(secret.has_attribute("hvuri")):
|
return ("", "")
|
||||||
return ("", "")
|
|
||||||
if secret.get_attribute("hvuri") != vm.conn.get_uri():
|
|
||||||
return ("", "")
|
|
||||||
if not(secret.has_attribute("uuid")):
|
|
||||||
return ("", "")
|
|
||||||
if secret.get_attribute("uuid") != vm.get_uuid():
|
|
||||||
return ("", "")
|
|
||||||
|
|
||||||
return (secret.get_secret(), username)
|
return (secret.get_secret(), username or "")
|
||||||
return ("", username)
|
|
||||||
|
|
||||||
def set_console_password(self, vm, password, username=""):
|
def set_console_password(self, vm, password, username=""):
|
||||||
if not(self.has_keyring()):
|
if not self.has_keyring():
|
||||||
return
|
return
|
||||||
|
|
||||||
# Nb, we don't bother to check if there is an existing
|
# Nb, we don't bother to check if there is an existing
|
||||||
@ -786,7 +770,11 @@ class vmmConfig(object):
|
|||||||
secret = vmmSecret(self.get_secret_name(vm), password,
|
secret = vmmSecret(self.get_secret_name(vm), password,
|
||||||
{"uuid" : vm.get_uuid(),
|
{"uuid" : vm.get_uuid(),
|
||||||
"hvuri": vm.conn.get_uri()})
|
"hvuri": vm.conn.get_uri()})
|
||||||
_id = self.keyring.add_secret(secret)
|
keyid = self.keyring.add_secret(secret)
|
||||||
if _id is not None:
|
if keyid is None:
|
||||||
self.conf.set_int(self.conf_dir + "/console/passwords/" + vm.get_uuid(), _id)
|
return
|
||||||
self.conf.set_string(self.conf_dir + "/console/usernames/" + vm.get_uuid(), username)
|
|
||||||
|
self.conf.set_int(self.conf_dir +
|
||||||
|
"/console/passwords/" + vm.get_uuid(), keyid)
|
||||||
|
self.conf.set_string(self.conf_dir +
|
||||||
|
"/console/usernames/" + vm.get_uuid(), username)
|
||||||
|
@ -340,7 +340,12 @@ class VNCViewer(Viewer):
|
|||||||
return self.desktop_resolution
|
return self.desktop_resolution
|
||||||
|
|
||||||
def _auth_credential(self, src_ignore, credList):
|
def _auth_credential(self, src_ignore, credList):
|
||||||
for cred in credList:
|
# XXX shouldn't need this
|
||||||
|
values = []
|
||||||
|
for idx in range(int(credList.n_values)):
|
||||||
|
values.append(credList.get_nth(idx))
|
||||||
|
|
||||||
|
for cred in values:
|
||||||
if cred in [GtkVnc.DisplayCredential.PASSWORD,
|
if cred in [GtkVnc.DisplayCredential.PASSWORD,
|
||||||
GtkVnc.DisplayCredential.USERNAME,
|
GtkVnc.DisplayCredential.USERNAME,
|
||||||
GtkVnc.DisplayCredential.CLIENTNAME]:
|
GtkVnc.DisplayCredential.CLIENTNAME]:
|
||||||
@ -363,7 +368,7 @@ class VNCViewer(Viewer):
|
|||||||
|
|
||||||
withUsername = False
|
withUsername = False
|
||||||
withPassword = False
|
withPassword = False
|
||||||
for cred in credList:
|
for cred in values:
|
||||||
logging.debug("Got credential request %s", cred)
|
logging.debug("Got credential request %s", cred)
|
||||||
if cred == GtkVnc.DisplayCredential.PASSWORD:
|
if cred == GtkVnc.DisplayCredential.PASSWORD:
|
||||||
withPassword = True
|
withPassword = True
|
||||||
|
@ -18,33 +18,57 @@
|
|||||||
# MA 02110-1301 USA.
|
# MA 02110-1301 USA.
|
||||||
#
|
#
|
||||||
|
|
||||||
from virtManager.secret import vmmSecret
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
haveKeyring = False
|
|
||||||
try:
|
try:
|
||||||
import gnomekeyring
|
from gi.repository import GnomeKeyring
|
||||||
haveKeyring = True
|
|
||||||
except:
|
except:
|
||||||
logging.warning("gnomekeyring bindings not installed, no keyring support")
|
GnomeKeyring = None
|
||||||
|
logging.debug("GnomeKeyring bindings not installed, no keyring support")
|
||||||
|
|
||||||
|
|
||||||
|
class vmmSecret(object):
|
||||||
|
def __init__(self, name, secret=None, attributes=None):
|
||||||
|
self.name = name
|
||||||
|
self.secret = secret
|
||||||
|
|
||||||
|
self.attributes = {}
|
||||||
|
if isinstance(attributes, dict):
|
||||||
|
self.attributes = attributes
|
||||||
|
elif isinstance(attributes, list):
|
||||||
|
for attr in attributes:
|
||||||
|
self.attributes[attr.name] = attr.get_string()
|
||||||
|
|
||||||
|
def get_secret(self):
|
||||||
|
return self.secret
|
||||||
|
def get_name(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
def get_attributes_for_keyring(self):
|
||||||
|
attrs = GnomeKeyring.attribute_list_new()
|
||||||
|
for key, value in self.attributes.items():
|
||||||
|
GnomeKeyring.attribute_list_append_string(attrs, key, value)
|
||||||
|
return attrs
|
||||||
|
|
||||||
|
|
||||||
class vmmKeyring(object):
|
class vmmKeyring(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.keyring = None
|
self.keyring = None
|
||||||
if not haveKeyring:
|
if GnomeKeyring is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.keyring = gnomekeyring.get_default_keyring_sync()
|
result = GnomeKeyring.get_default_keyring_sync()
|
||||||
|
if result and result[0] == GnomeKeyring.Result.OK:
|
||||||
|
self.keyring = result[1]
|
||||||
|
|
||||||
if self.keyring is None:
|
if self.keyring is None:
|
||||||
# Code borrowed from
|
|
||||||
# http://trac.gajim.org/browser/src/common/passwords.py
|
|
||||||
self.keyring = 'default'
|
self.keyring = 'default'
|
||||||
|
logging.debug("No default keyring, creating '%s'",
|
||||||
|
self.keyring)
|
||||||
try:
|
try:
|
||||||
gnomekeyring.create_sync(self.keyring, None)
|
GnomeKeyring.create_sync(self.keyring, None)
|
||||||
except gnomekeyring.AlreadyExistsError:
|
except GnomeKeyring.AlreadyExistsError:
|
||||||
pass
|
pass
|
||||||
except:
|
except:
|
||||||
logging.exception("Error determining keyring")
|
logging.exception("Error determining keyring")
|
||||||
@ -56,32 +80,43 @@ class vmmKeyring(object):
|
|||||||
def add_secret(self, secret):
|
def add_secret(self, secret):
|
||||||
_id = None
|
_id = None
|
||||||
try:
|
try:
|
||||||
_id = gnomekeyring.item_create_sync(self.keyring,
|
result, _id = GnomeKeyring.item_create_sync(
|
||||||
gnomekeyring.ITEM_GENERIC_SECRET,
|
self.keyring,
|
||||||
secret.get_name(),
|
GnomeKeyring.ItemType.GENERIC_SECRET,
|
||||||
secret.get_attributes(),
|
secret.get_name(),
|
||||||
secret.get_secret(),
|
secret.get_attributes_for_keyring(),
|
||||||
True)
|
secret.get_secret(),
|
||||||
|
True)
|
||||||
|
|
||||||
|
if result != GnomeKeyring.Result.OK:
|
||||||
|
raise RuntimeError("Creating keyring item failed with: %s" %
|
||||||
|
repr(result))
|
||||||
except:
|
except:
|
||||||
logging.exception("Failed to add keyring secret")
|
logging.exception("Failed to add keyring secret")
|
||||||
|
|
||||||
return _id
|
return _id
|
||||||
|
|
||||||
def get_secret(self, _id):
|
def get_secret(self, _id):
|
||||||
|
"""
|
||||||
|
ignore, item = GnomeKeyring.item_get_info_sync(self.keyring, _id)
|
||||||
|
if item is None:
|
||||||
|
return
|
||||||
|
|
||||||
sec = None
|
sec = None
|
||||||
try:
|
try:
|
||||||
item = gnomekeyring.item_get_info_sync(self.keyring, _id)
|
result, attrs = GnomeKeyring.item_get_attributes_sync(
|
||||||
attrs = gnomekeyring.item_get_attributes_sync(self.keyring, _id)
|
self.keyring, _id)
|
||||||
|
if result != GnomeKeyring.Result.OK:
|
||||||
|
raise RuntimeError("Fetching keyring attributes failed "
|
||||||
|
"with %s" % result)
|
||||||
|
|
||||||
sec = vmmSecret(item.get_display_name(), item.get_secret(), attrs)
|
sec = vmmSecret(item.get_display_name(), item.get_secret(), attrs)
|
||||||
except:
|
except:
|
||||||
pass
|
logging.exception("Failed to lookup keyring item %s", item)
|
||||||
|
|
||||||
return sec
|
return sec
|
||||||
|
"""
|
||||||
def clear_secret(self, _id):
|
# FIXME: Uncomment this once gnome-keyring is fixed
|
||||||
try:
|
# https://bugzilla.gnome.org/show_bug.cgi?id=691638
|
||||||
gnomekeyring.item_delete_sync(self.keyring, _id)
|
ignore = _id
|
||||||
return True
|
return None
|
||||||
except:
|
|
||||||
return False
|
|
||||||
|
@ -1,55 +0,0 @@
|
|||||||
#
|
|
||||||
# Copyright (C) 2006 Red Hat, Inc.
|
|
||||||
# Copyright (C) 2006 Daniel P. Berrange <berrange@redhat.com>
|
|
||||||
#
|
|
||||||
# This program is free software; you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation; either version 2 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program; if not, write to the Free Software
|
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
||||||
# MA 02110-1301 USA.
|
|
||||||
#
|
|
||||||
|
|
||||||
class vmmSecret(object):
|
|
||||||
def __init__(self, name, secret=None, attributes=None):
|
|
||||||
|
|
||||||
self.name = name
|
|
||||||
self.secret = secret
|
|
||||||
if attributes is None:
|
|
||||||
attributes = {}
|
|
||||||
self.attributes = attributes
|
|
||||||
|
|
||||||
def set_secret(self, data):
|
|
||||||
self.secret = data
|
|
||||||
|
|
||||||
def get_secret(self):
|
|
||||||
return self.secret
|
|
||||||
|
|
||||||
def get_name(self):
|
|
||||||
return self.name
|
|
||||||
|
|
||||||
def get_attributes(self):
|
|
||||||
return self.attributes
|
|
||||||
|
|
||||||
def has_attribute(self, key):
|
|
||||||
return key in self.attributes
|
|
||||||
|
|
||||||
def add_attribute(self, key, value):
|
|
||||||
if type(value) != str:
|
|
||||||
value = str(value)
|
|
||||||
|
|
||||||
self.attributes[key] = value
|
|
||||||
|
|
||||||
def list_attributes(self):
|
|
||||||
return self.attributes.keys()
|
|
||||||
|
|
||||||
def get_attribute(self, key):
|
|
||||||
return self.attributes[key]
|
|
Loading…
Reference in New Issue
Block a user