Esempio n. 1
0
def open_session(connection: DBusConnection) -> Session:
    """Returns a new Secret Service session."""
    service = DBusAddressWrapper(SS_PATH, SERVICE_IFACE, connection)
    session = Session()
    try:
        output, result = service.call(
            'OpenSession', 'sv', ALGORITHM_DH,
            ('ay', int_to_bytes(session.my_public_key)))
    except DBusErrorResponse as resp:
        if resp.name != DBUS_NOT_SUPPORTED:
            raise
        output, result = service.call('OpenSession', 'sv', ALGORITHM_PLAIN,
                                      ('s', ''))
        session.encrypted = False
    else:
        signature, value = output
        assert signature == 'ay'
        key = int.from_bytes(value, 'big')
        session.set_server_public_key(key)
    session.object_path = result
    return session
Esempio n. 2
0
def open_session(bus):
    """Returns a new Secret Service session."""
    service_obj = bus_get_object(bus, SS_PATH)
    service_iface = dbus.Interface(service_obj, SS_PREFIX + 'Service')
    session = Session()
    try:
        output, result = service_iface.OpenSession(
            ALGORITHM_DH,
            dbus.ByteArray(int_to_bytes(session.my_public_key)),
            signature='sv')
    except dbus.exceptions.DBusException as e:
        if e.get_dbus_name() != DBUS_NOT_SUPPORTED:
            raise
        output, result = service_iface.OpenSession(ALGORITHM_PLAIN,
                                                   '',
                                                   signature='sv')
        session.encrypted = False
    else:
        output = int_from_bytes(bytearray(output), 'big')
        session.set_server_public_key(output)
    session.object_path = result
    return session
Esempio n. 3
0
	def test_int_to_bytes(self) -> None:
		self.assertEqual(int_to_bytes(1), b'\x01')
		self.assertEqual(int_to_bytes(258), b'\x01\x02')
		self.assertEqual(int_to_bytes(1 << 64), b'\x01' + b'\x00' * 8)