本文整理汇总了Python中gi.repository.GnomeKeyring.unlock_sync方法的典型用法代码示例。如果您正苦于以下问题:Python GnomeKeyring.unlock_sync方法的具体用法?Python GnomeKeyring.unlock_sync怎么用?Python GnomeKeyring.unlock_sync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gi.repository.GnomeKeyring
的用法示例。
在下文中一共展示了GnomeKeyring.unlock_sync方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_lock
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import unlock_sync [as 别名]
def test_create_lock(self):
'''create_sync() and locking/unlocking'''
# create
self.assertEqual(GnomeKeyring.create_sync(TEST_KEYRING, TEST_PWD),
GnomeKeyring.Result.OK)
(result, info) = GnomeKeyring.get_info_sync(TEST_KEYRING)
self.assertEqual(result, GnomeKeyring.Result.OK)
self.assertFalse(info.get_is_locked())
# try to create already existing ring
self.assertEqual(GnomeKeyring.create_sync(TEST_KEYRING, TEST_PWD),
GnomeKeyring.Result.KEYRING_ALREADY_EXISTS)
# lock
self.assertEqual(GnomeKeyring.lock_sync(TEST_KEYRING),
GnomeKeyring.Result.OK)
self.assertTrue(GnomeKeyring.get_info_sync(TEST_KEYRING)[1].get_is_locked())
# unlock with wrong password
self.assertEqual(GnomeKeyring.unlock_sync(TEST_KEYRING, 'h4ck'),
GnomeKeyring.Result.IO_ERROR)
# unlock with correct password
self.assertEqual(GnomeKeyring.unlock_sync(TEST_KEYRING, TEST_PWD),
GnomeKeyring.Result.OK)
示例2: get_keyring_password
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import unlock_sync [as 别名]
def get_keyring_password():
GnomeKeyring.unlock_sync("login", None)
attrs = GnomeKeyring.Attribute.list_new()
GnomeKeyring.Attribute.list_append_string(attrs, "id", "resnet")
result, value = GnomeKeyring.find_items_sync(GnomeKeyring.ItemType.GENERIC_SECRET, attrs)
if result == GnomeKeyring.Result.OK:
return value[0].secret
elif result == GnomeKeyring.Result.NO_MATCH:
# Password not found, prompt to add new one
print("Password not found in keyring")
password = getpass.getpass("OSU Login Password: ")
GnomeKeyring.item_create_sync("login", GnomeKeyring.ItemType.GENERIC_SECRET, "resnet", attrs, password, True)
return password
elif result != GnomeKeyring.Result.OK:
return None
示例3: __init__
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import unlock_sync [as 别名]
def __init__(self):
Gtk.Application.__init__(self,
application_id="org.gnome.TwoFactorAuth",
flags=Gio.ApplicationFlags.FLAGS_NONE)
GLib.set_application_name(_("TwoFactorAuth"))
GLib.set_prgname("Gnome-TwoFactorAuth")
self.menu = Gio.Menu()
self.db = Database()
self.cfg = SettingsReader()
self.locked = self.cfg.read("state", "login")
result = GK.unlock_sync("Gnome-TwoFactorAuth", None)
if result == GK.Result.CANCELLED:
self.quit()
cssProviderFile = Gio.File.new_for_uri('resource:///org/gnome/TwoFactorAuth/style.css')
cssProvider = Gtk.CssProvider()
screen = Gdk.Screen.get_default()
styleContext = Gtk.StyleContext()
try:
cssProvider.load_from_file(cssProviderFile)
styleContext.add_provider_for_screen(screen, cssProvider,
Gtk.STYLE_PROVIDER_PRIORITY_USER)
logging.debug("Loading css file ")
except Exception as e:
logging.error("Error message %s" % str(e))
示例4: setup_gnome_keyring
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import unlock_sync [as 别名]
def setup_gnome_keyring():
"""
Provide clean login Gnome keyring (removes the previous one
beforehand, if there is a one).
"""
try:
# Delete originally stored password
(response, keyring) = GnomeKeyring.get_default_keyring_sync()
log.debug('get_info default: %s, %s' % (response, keyring))
if response == GnomeKeyring.Result.OK:
if keyring is not None:
delete_response = GnomeKeyring.delete_sync(keyring)
log.debug('delete default: %s' % delete_response)
assert delete_response == GnomeKeyring.Result.OK, \
"Delete failed: %s" % delete_response
response, keyring = GnomeKeyring.get_info_sync('login')
if response == GnomeKeyring.Result.OK:
if keyring is not None:
delete_response = GnomeKeyring.delete_sync('login')
log.debug('delete login: %s' % delete_response)
assert delete_response == GnomeKeyring.Result.OK, \
"Delete failed: %s" % delete_response
elif response != GnomeKeyring.Result.NO_SUCH_KEYRING:
raise IOError(
'Unexpected error when manipulating login keyring')
# This is result of the underlying DBus error:
# CKR_WRAPPED_KEY_INVALID, CKR_WRAPPED_KEY_LEN_RANGE,
# CKR_MECHANISM_PARAM_INVALID
# So, failed either
# * egg_padding_pkcs7_unpad
# (gnome-keyring/egg/egg-padding.c)
# * gkm_aes_mechanism_unwrap
# (gnome-keyring/pkcs11/gkm/gkm-aes-mechanism.c)
# * gkm_dh_mechanism_derive
# (gnome-keyring/pkcs11/gkm/gkm-dh-mechanism.c)
# * gkm_null_mechanism_unwrap or gkm_null_mechanism_wrap
# (gnome-keyring/pkcs11/gkm/gkm-null-mechanism.c)
create_response = GnomeKeyring.create_sync('login', 'redhat')
log.debug('create login: %s' % create_response)
if create_response != GnomeKeyring.Result.OK:
raise IOError(
'Create failed: %s\n%s' %
(create_response,
GnomeKeyring.result_to_message(create_response)))
set_default_response = \
GnomeKeyring.set_default_keyring_sync('login')
assert set_default_response == GnomeKeyring.Result.OK, \
"Set default failed: %s" % set_default_response
unlock_response = GnomeKeyring.unlock_sync("login", 'redhat')
assert unlock_response == GnomeKeyring.Result.OK, \
"Unlock failed: %s" % unlock_response
except Exception as e:
log.error("Exception while unlocking a keyring: %s", e.message)
raise # We shouldn’t let this exception evaporate
示例5: __init__
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import unlock_sync [as 别名]
def __init__(self):
(result, kr_name) = GnomeKeyring.get_default_keyring_sync()
self._defaultKeyring = kr_name
if self._defaultKeyring == None:
self._defaultKeyring = 'login'
result = GnomeKeyring.unlock_sync(self._defaultKeyring, None)
if result != GnomeKeyring.Result.OK:
raise KeyringUnlockException('Failed to unlock default keyring')
self._migrate_keyring()
示例6: __init__
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import unlock_sync [as 别名]
def __init__(self):
self.KEYRING_ITEM_NAME = 'Mailnag password for %s://%[email protected]%s'
(result, kr_name) = GnomeKeyring.get_default_keyring_sync()
self._defaultKeyring = kr_name
if self._defaultKeyring == None:
self._defaultKeyring = 'login'
result = GnomeKeyring.unlock_sync(self._defaultKeyring, None)
if (result != GnomeKeyring.Result.OK):
raise Exception('Failed to unlock default keyring')
示例7: before_all
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import unlock_sync [as 别名]
def before_all(context):
"""Setup evolution stuff
Being executed before all features
"""
# Reset GSettings
schemas = [x for x in Gio.Settings.list_schemas() if 'evolution' in x.lower()]
for schema in schemas:
os.system("gsettings reset-recursively %s" % schema)
# Skip warning dialog
os.system("gsettings set org.gnome.evolution.shell skip-warning-dialog true")
# Show switcher buttons as icons (to minimize tree scrolling)
os.system("gsettings set org.gnome.evolution.shell buttons-style icons")
# Wait for things to settle
sleep(0.5)
# Skip dogtail actions to print to stdout
config.logDebugToStdOut = False
config.typingDelay = 0.2
# Include assertion object
context.assertion = dummy()
# Kill initial setup
os.system("killall /usr/libexec/gnome-initial-setup")
# Delete existing ABRT problems
if problem.list():
[x.delete() for x in problem.list()]
try:
from gi.repository import GnomeKeyring
# Delete originally stored password
(response, keyring) = GnomeKeyring.get_default_keyring_sync()
if response == GnomeKeyring.Result.OK:
if keyring is not None:
delete_response = GnomeKeyring.delete_sync(keyring)
assert delete_response == GnomeKeyring.Result.OK, "Delete failed: %s" % delete_response
create_response = GnomeKeyring.create_sync("login", 'gnome')
assert create_response == GnomeKeyring.Result.OK, "Create failed: %s" % create_response
set_default_response = GnomeKeyring.set_default_keyring_sync('login')
assert set_default_response == GnomeKeyring.Result.OK, "Set default failed: %s" % set_default_response
unlock_response = GnomeKeyring.unlock_sync("login", 'gnome')
assert unlock_response == GnomeKeyring.Result.OK, "Unlock failed: %s" % unlock_response
except Exception as e:
print("Exception while unlocking a keyring: %s" % e.message)
context.app = App('evolution')
示例8: do_activate
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import unlock_sync [as 别名]
def do_activate(self):
GnomeKeyring.unlock_sync("liferea", None)
示例9: do_activate
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import unlock_sync [as 别名]
def do_activate(self):
result = GnomeKeyring.unlock_sync("liferea", None)
if GnomeKeyring.Result.OK != result:
print("There doesn't seem to be a keyring yet.")
示例10: print
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import unlock_sync [as 别名]
from utils import APP_NAME, LOCALE_DIR
import gettext
gettext.bindtextdomain(APP_NAME, LOCALE_DIR)
gettext.textdomain(APP_NAME)
_ = gettext.gettext
try:
from gi.repository import GnomeKeyring
USE_GNOME_KEYRING = GnomeKeyring.is_available()
KEYRING_NAME = 'login' # default keyring that gets unlocked normally when the user starts the session
GUIFINETLOGINKEYNAME = 'guifinetlogin'
print(_('Use GNOME Keyring: {}').format(USE_GNOME_KEYRING))
GnomeKeyring.unlock_sync(KEYRING_NAME, None)
except ImportError:
print(_('GNOME Keyring dependency not available'))
print(_('Using plain text configuration files instead'))
USE_GNOME_KEYRING = False
class GuifinetStudioConfig:
CONFIG_DIR = os.path.expanduser('~/.config/guifinetstudio')
CACHE_DIR = os.path.expanduser('~/.cache/guifinetstudio')
CONFIG_FILENAME = os.path.join(CONFIG_DIR, 'config')
def __init__(self):
#create config folder and default file if they don't exist
self.initConfig()
示例11: unlock
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import unlock_sync [as 别名]
def unlock(self,password):
result = GnomeKeyring.unlock_sync(self.keyring,password)
print(result)
if result == GnomeKeyring.Result.OK:
return True
return False
示例12: do_activate
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import unlock_sync [as 别名]
def do_activate(self):
result = GnomeKeyring.unlock_sync("liferea", None)
if GnomeKeyring.Result.OK != result:
raise ValueError("Failed to unlock GnomeKeyring, error "+result)
示例13: len
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import unlock_sync [as 别名]
import sys
from gi.repository import GnomeKeyring as gk
if len(sys.argv) < 3:
print >> sys.stderr, "invalid arguments\n python gnomekeyring.py keyring itemname"
exit(1)
ringname = sys.argv[1]
keyname = sys.argv[2]
(result, keyrings) = gk.list_keyring_names_sync()
if not ringname in keyrings:
print >> sys.stderr, "keyring '%s' not found" % ringname
exit(2)
result = gk.unlock_sync(ringname, None)
if not result == gk.Result.OK:
print >> sys.stderr, "keyring '%s' is locked" % ringname
exit(3)
(result, ids) = gk.list_item_ids_sync(ringname)
for id in ids:
(result, info) = gk.item_get_info_sync(ringname, id)
if info.get_display_name() == keyname:
print info.get_secret()
exit(0)
print >> sys.stderr, "keyname '%s' in '%s' not found" % (keyname, ringname)
exit(4)
示例14: compile
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import unlock_sync [as 别名]
screen.addstr('Press any key to continue ...')
screen.getch()
if __name__ == '__main__':
gi.require_version('GnomeKeyring', '1.0')
gi.require_version('Secret', '1')
from gi.repository import GnomeKeyring as gkr, Secret
# Unlock the login keyring, if necessary
was_locked = False
if gkr.get_info_sync(KEYRING)[1].get_is_locked():
was_locked = True
import getpass
result = gkr.unlock_sync('login',
getpass.getpass(prompt='Enter password for '
'login keyring: '))
if result == gkr.Result.IO_ERROR: # Incorrect password
sys.exit(1)
# Connect to libsecret
service = Secret.Service.get_sync(Secret.ServiceFlags.OPEN_SESSION |
Secret.ServiceFlags.LOAD_COLLECTIONS)
collections = service.get_collections()
# Search the default keyring
items = service.unlock_sync(collections, None)[1][0].get_items()
# Match the item's name using the search string as a regular expression
found = [i for i in items if compile(sys.argv[1]).search(i.get_label())]