Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
update_loop_task.cancel()
else:
wake_event.set()
logging.info("Woke up")
_, dbus_proto = await jeepney.integrate.asyncio.connect_and_authenticate('SYSTEM')
dbus_bus = jeepney.integrate.asyncio.Proxy(jeepney.bus_messages.message_bus, dbus_proto)
dbus_proto.router.subscribe_signal(
callback=lambda args: prepare_for_sleep(*args),
path='/org/freedesktop/login1',
interface='org.freedesktop.login1.Manager',
member='PrepareForSleep'
)
await dbus_bus.AddMatch(jeepney.bus_messages.MatchRule(
type='signal',
sender='org.freedesktop.login1',
interface='org.freedesktop.login1.Manager',
member='PrepareForSleep',
path='/org/freedesktop/login1'
))
while True:
logging.info("Waiting for wake event")
await wake_event.wait()
logging.info("Starting update loop")
update_loop_task = asyncio.ensure_future(update_loop(config, udev))
try:
await update_loop_task
except asyncio.CancelledError:
logging.info("Stopped update loop")
update_loop_task.cancel()
else:
wake_event.set()
logging.info("Woke up")
_, dbus_proto = await jeepney.integrate.asyncio.connect_and_authenticate('SYSTEM')
dbus_bus = jeepney.integrate.asyncio.Proxy(jeepney.bus_messages.message_bus, dbus_proto)
dbus_proto.router.subscribe_signal(
callback=lambda args: prepare_for_sleep(*args),
path='/org/freedesktop/login1',
interface='org.freedesktop.login1.Manager',
member='PrepareForSleep'
)
await dbus_bus.AddMatch(jeepney.bus_messages.MatchRule(
type='signal',
sender='org.freedesktop.login1',
interface='org.freedesktop.login1.Manager',
member='PrepareForSleep',
path='/org/freedesktop/login1'
))
while True:
logging.info("Waiting for wake event")
await wake_event.wait()
logging.info("Starting update loop")
update_loop_task = asyncio.ensure_future(update_loop(config, udev))
try:
await update_loop_task
except asyncio.CancelledError:
logging.info("Stopped update loop")
with closing(dbus_init()) as conn:
collection = secretstorage.get_default_collection(conn)
items = collection.search_items({'application': 'myapp'})
However, you will not be able to call any methods on the objects
created within the context after you leave it.
.. versionchanged:: 3.0
Before the port to Jeepney, this function returned an
instance of :class:`dbus.SessionBus` class.
.. versionchanged:: 3.1
This function no longer accepts any arguments.
"""
try:
connection = connect_and_authenticate()
add_match_rules(connection)
return connection
except KeyError as ex:
# os.environ['DBUS_SESSION_BUS_ADDRESS'] may raise it
reason = "Environment variable {} is unset".format(ex.args[0])
raise SecretServiceNotAvailableException(reason) from ex
except (ConnectionError, ValueError) as ex:
raise SecretServiceNotAvailableException(str(ex)) from ex
def add_match_rules(connection: DBusConnection) -> None:
"""Adds match rules for the given connection.
Currently it matches all messages from the Prompt interface, as the
mock service (unlike GNOME Keyring) does not specify the signal
destination.
.. versionadded:: 3.1
"""
rule = MatchRule(sender=BUS_NAME, interface=PROMPT_IFACE)
dbus = DBusAddressWrapper(path='/org/freedesktop/DBus',
interface='org.freedesktop.DBus',
connection=connection)
dbus.bus_name = 'org.freedesktop.DBus'
dbus.call('AddMatch', 's', rule.serialise())
wake_event.set()
update_loop_task = None
def prepare_for_sleep(sleep):
if sleep:
logging.info("Preparing for sleep")
wake_event.clear()
if update_loop_task:
update_loop_task.cancel()
else:
wake_event.set()
logging.info("Woke up")
_, dbus_proto = await jeepney.integrate.asyncio.connect_and_authenticate('SYSTEM')
dbus_bus = jeepney.integrate.asyncio.Proxy(jeepney.bus_messages.message_bus, dbus_proto)
dbus_proto.router.subscribe_signal(
callback=lambda args: prepare_for_sleep(*args),
path='/org/freedesktop/login1',
interface='org.freedesktop.login1.Manager',
member='PrepareForSleep'
)
await dbus_bus.AddMatch(jeepney.bus_messages.MatchRule(
type='signal',
sender='org.freedesktop.login1',
interface='org.freedesktop.login1.Manager',
member='PrepareForSleep',
path='/org/freedesktop/login1'
))
wake_event.set()
update_loop_task = None
def prepare_for_sleep(sleep):
if sleep:
logging.info("Preparing for sleep")
wake_event.clear()
if update_loop_task:
update_loop_task.cancel()
else:
wake_event.set()
logging.info("Woke up")
_, dbus_proto = await jeepney.integrate.asyncio.connect_and_authenticate('SYSTEM')
dbus_bus = jeepney.integrate.asyncio.Proxy(jeepney.bus_messages.message_bus, dbus_proto)
dbus_proto.router.subscribe_signal(
callback=lambda args: prepare_for_sleep(*args),
path='/org/freedesktop/login1',
interface='org.freedesktop.login1.Manager',
member='PrepareForSleep'
)
await dbus_bus.AddMatch(jeepney.bus_messages.MatchRule(
type='signal',
sender='org.freedesktop.login1',
interface='org.freedesktop.login1.Manager',
member='PrepareForSleep',
path='/org/freedesktop/login1'
))
wake_event = asyncio.Event()
wake_event.set()
update_loop_task = None
def prepare_for_sleep(sleep):
if sleep:
logging.info("Preparing for sleep")
wake_event.clear()
if update_loop_task:
update_loop_task.cancel()
else:
wake_event.set()
logging.info("Woke up")
_, dbus_proto = await jeepney.integrate.asyncio.connect_and_authenticate('SYSTEM')
dbus_bus = jeepney.integrate.asyncio.Proxy(jeepney.bus_messages.message_bus, dbus_proto)
dbus_proto.router.subscribe_signal(
callback=lambda args: prepare_for_sleep(*args),
path='/org/freedesktop/login1',
interface='org.freedesktop.login1.Manager',
member='PrepareForSleep'
)
await dbus_bus.AddMatch(jeepney.bus_messages.MatchRule(
type='signal',
sender='org.freedesktop.login1',
interface='org.freedesktop.login1.Manager',
member='PrepareForSleep',
path='/org/freedesktop/login1'
))
wake_event = asyncio.Event()
wake_event.set()
update_loop_task = None
def prepare_for_sleep(sleep):
if sleep:
logging.info("Preparing for sleep")
wake_event.clear()
if update_loop_task:
update_loop_task.cancel()
else:
wake_event.set()
logging.info("Woke up")
_, dbus_proto = await jeepney.integrate.asyncio.connect_and_authenticate('SYSTEM')
dbus_bus = jeepney.integrate.asyncio.Proxy(jeepney.bus_messages.message_bus, dbus_proto)
dbus_proto.router.subscribe_signal(
callback=lambda args: prepare_for_sleep(*args),
path='/org/freedesktop/login1',
interface='org.freedesktop.login1.Manager',
member='PrepareForSleep'
)
await dbus_bus.AddMatch(jeepney.bus_messages.MatchRule(
type='signal',
sender='org.freedesktop.login1',
interface='org.freedesktop.login1.Manager',
member='PrepareForSleep',
path='/org/freedesktop/login1'
))
from secretstorage.defines import DBUS_UNKNOWN_METHOD, DBUS_NO_SUCH_OBJECT, \
DBUS_SERVICE_UNKNOWN, DBUS_NO_REPLY, DBUS_NOT_SUPPORTED, DBUS_EXEC_FAILED, \
SS_PATH, SS_PREFIX, ALGORITHM_DH, ALGORITHM_PLAIN
from secretstorage.dhcrypto import Session, int_to_bytes
from secretstorage.exceptions import ItemNotFoundException, \
SecretServiceNotAvailableException
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.backends import default_backend
from cryptography.utils import int_from_bytes
BUS_NAME = 'org.freedesktop.secrets'
SERVICE_IFACE = SS_PREFIX + 'Service'
PROMPT_IFACE = SS_PREFIX + 'Prompt'
class DBusAddressWrapper(DBusAddress): # type: ignore
"""A wrapper class around :class:`jeepney.wrappers.DBusAddress`
that adds some additional methods for calling and working with
properties, and converts error responses to SecretStorage
exceptions.
.. versionadded:: 3.0
"""
def __init__(self, path: str, interface: str,
connection: DBusConnection) -> None:
DBusAddress.__init__(self, path, BUS_NAME, interface)
self._connection = connection
def send_and_get_reply(self, msg: Message) -> Any:
try:
return self._connection.send_and_get_reply(msg)
except DBusErrorResponse as resp:
def __init__(self, path: str, interface: str,
connection: DBusConnection) -> None:
DBusAddress.__init__(self, path, BUS_NAME, interface)
self._connection = connection