o !`r @sndZddlZddlmZmZmZddlmZmZm Z m Z m Z m Z m Z ddlmZddlmZmZmZmZmZmZmZmZmZmZddlmZmZddlmZm Z dd l!m"Z"m#Z#m$Z$dd l%m&Z&d Z'ed Z(ed Z)GdddeZ*dedefddZ+dede,de-dee-e,e,e-ffddZ.dede-dee/ee-ffddZ0dedee-de/fddZ1deddfdd Z2dS)!zkThis module provides some utility functions, but these shouldn't normally be used by external applications.N)AnyListTuple) DBusAddressDBusErrorResponse MatchRuleMessage MessageTypenew_method_call Properties)DBusConnection) DBUS_UNKNOWN_METHODDBUS_NO_SUCH_OBJECTDBUS_SERVICE_UNKNOWN DBUS_NO_REPLYDBUS_NOT_SUPPORTEDDBUS_EXEC_FAILEDSS_PATH SS_PREFIX ALGORITHM_DHALGORITHM_PLAIN)Session int_to_bytes)ItemNotFoundException"SecretServiceNotAvailableException)Cipher algorithmsmodes)default_backendzorg.freedesktop.secretsServicePromptc@seZdZdZdedededdfddZd edefd d Z d ed ededefddZ dedefddZ ded ededdfddZ dS)DBusAddressWrapperzA 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 path interface connectionreturnNcCst||t|||_dSN)r__init__BUS_NAME _connection)selfr"r#r$r+4/usr/lib/python3/dist-packages/secretstorage/util.pyr''s zDBusAddressWrapper.__init__msgc Csxz |jj|ddWSty;}z&|jttfvrtd||jttt fvr6|j }t |t r1|d}t ||d}~ww)NT)unwrapzItem does not exist!r)r)send_and_get_replyrnamer rrrrrdata isinstancetupler)r*r-respr1r+r+r,r/,s   z%DBusAddressWrapper.send_and_get_replymethod signaturebodycGst||||}||Sr&)r r/)r*r5r6r7r-r+r+r,call:s zDBusAddressWrapper.callr0cCs"t||}||\\}}|Sr&)r getr/)r*r0r-r6valuer+r+r, get_property>szDBusAddressWrapper.get_propertyr:cCs t||||}||dSr&)r setr/)r*r0r6r:r-r+r+r, set_propertyCszDBusAddressWrapper.set_property) __name__ __module__ __qualname____doc__strr r'rrr/r8r;r=r+r+r+r,r!s  r!r$r%c Csttt|}t}z|ddtdt|jf\}}Wn%ty?}z|j t kr(|ddt d\}}d|_ WYd}~nd}~ww|\}}|dksJJt |d}||||_|S)z%Returns a new Secret Service session. OpenSessionsvay)sFNbig)r!r SERVICE_IFACErr8rr my_public_keyrr0rr encryptedint from_bytesset_server_public_key object_path) r$servicesessionoutputresultr4r6r:keyr+r+r, open_sessionHs.       rUrQsecret content_typecCst|tr |d}n t|tstd|jdusJ|js%|jd||fS|jdus,Jdt|d@}|t|f|7}t d}t |j}t |t|t}|||}|j|||fS)zHFormats `secret` to make possible to pass it to the Secret Service API.zutf-8zsecret must be bytesN)r2rBencodebytes TypeErrorrOrKaes_keylenosurandomrAESrrCBCr encryptorupdatefinalize)rQrVrWpaddingaes_ivaesrdencrypted_secretr+r+r, format_secret_s&     rk prompt_pathcCst|t|}t|tdtjd}||}|ddd||j\}}Wdn1s.wY|dus9J|dus?J||fS)zExecutes the prompt in a blocking mode. :returns: a tuple; the first element is a boolean value showing whether the operation was dismissed, the second element is a list of unlocked object paths Completed)r"r#membertyper rFrGN) r! PROMPT_IFACErr signalfilterr8recv_until_filteredr7)r$rlpromptrulesignals dismissedrSr+r+r, exec_promptzs    rxpathscCsPttt|}|dd|\}}t|dkr&t||\}\}}|dks$J|SdS)zRequests unlocking objects specified in `paths`. Returns a boolean representing whether the operation was dismissed. .. versionadded:: 2.1.2UnlockaoF)r!rrIr8r_rx)r$ryrPunlocked_pathsrtrwr6unlockedr+r+r,unlock_objectss   rcCs6tttd}tdd|d}d|_|dd|dS)zAdds 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 )senderr#z/org/freedesktop/DBuszorg.freedesktop.DBus)r"r#r$AddMatchrFN)rr(rpr!bus_namer8 serialise)r$rudbusr+r+r,add_match_ruless r)3rAr`typingrrrjeepneyrrrrr r r jeepney.io.blockingr secretstorage.definesr rrrrrrrrrsecretstorage.dhcryptorrsecretstorage.exceptionsrr&cryptography.hazmat.primitives.ciphersrrrcryptography.hazmat.backendsrr(rIrpr!rUr\rBrkboolrxrrr+r+r+r,s6$ 0 )