Skip to content

Commit

Permalink
Updated z-bus
Browse files Browse the repository at this point in the history
  • Loading branch information
tmuntaner committed Jan 4, 2022
1 parent 7d9a400 commit 594d75e
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 29 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ security-framework = "2.3"
[target.'cfg(target_os = "linux")'.dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0" }
zbus = "1.9"
zvariant = "^2.9"
zvariant_derive = "^2.9"
zbus = "2.0"
zvariant = "3.0"
zvariant_derive = "3.0"
openssl = "0.10"
hkdf = "^0.12"
aes = "0.7"
Expand Down
12 changes: 7 additions & 5 deletions src/secret_service/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@

use crate::secret_service::item::Item;
use crate::secret_service::proxy::secrets::Secret;
use crate::secret_service::proxy::secrets_collection::CollectionProxy;
use crate::secret_service::proxy::secrets_collection::CollectionProxyBlocking;
use crate::secret_service::session::SERVICE_NAME;
use anyhow::Result;
use std::collections::HashMap;
use zbus::Connection;
use zbus::blocking::Connection;
use zvariant::{Dict, OwnedObjectPath, Value};

pub const ITEM_LABEL: &str = "org.freedesktop.Secret.Item.Label";
pub const ITEM_ATTRIBUTES: &str = "org.freedesktop.Secret.Item.Attributes";

pub struct Collection<'a> {
proxy: CollectionProxy<'a>,
proxy: CollectionProxyBlocking<'a>,
connection: Connection,
session_path: OwnedObjectPath,
aes_key: Vec<u8>,
Expand All @@ -30,8 +30,10 @@ impl Collection<'_> {
aes_key: Vec<u8>,
path: String,
) -> Result<Collection<'a>> {
let proxy =
CollectionProxy::new_for_owned(connection.clone(), SERVICE_NAME.to_string(), path)?;
let proxy = CollectionProxyBlocking::builder(&connection)
.destination(SERVICE_NAME.to_string())?
.path(path)?
.build()?;

Ok(Collection {
proxy,
Expand Down
11 changes: 7 additions & 4 deletions src/secret_service/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
*/

use crate::secret_service::proxy::secrets::Secret;
use crate::secret_service::proxy::secrets_item::ItemProxy;
use crate::secret_service::proxy::secrets_item::ItemProxyBlocking;
use crate::secret_service::session::SERVICE_NAME;
use anyhow::{anyhow, Result};
use zbus::Connection;
use zbus::blocking::Connection;
use zvariant::OwnedObjectPath;

pub struct Item<'a> {
proxy: ItemProxy<'a>,
proxy: ItemProxyBlocking<'a>,
session_path: OwnedObjectPath,
}

Expand All @@ -22,7 +22,10 @@ impl Item<'_> {
session_path: OwnedObjectPath,
path: String,
) -> Result<Item<'a>> {
let proxy = ItemProxy::new_for_owned(connection, SERVICE_NAME.to_string(), path)?;
let proxy = ItemProxyBlocking::builder(&connection)
.destination(SERVICE_NAME.to_string())?
.path(path)?
.build()?;

Ok(Item {
proxy,
Expand Down
14 changes: 7 additions & 7 deletions src/secret_service/proxy/secrets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,31 @@ type Aes = Cbc<Aes128, Pkcs7>;
default_path = "/org/freedesktop/secrets"
)]
pub trait Secrets {
fn open_session(&self, algorithm: &str, input: Value) -> zbus::Result<OpenSessionResult>;
fn open_session(&self, algorithm: &str, input: Value<'_>) -> zbus::Result<OpenSessionResult>;

fn create_collection(
&self,
properties: HashMap<&str, Value>,
properties: HashMap<&str, Value<'_>>,
alias: &str,
) -> zbus::Result<CreateCollectionResult>;

fn search_items(&self, attributes: HashMap<&str, &str>) -> zbus::Result<SearchItemsResult>;

fn unlock(&self, objects: Vec<&ObjectPath>) -> zbus::Result<UnlockResult>;
fn unlock(&self, objects: Vec<&ObjectPath<'_>>) -> zbus::Result<UnlockResult>;

fn lock(&self, objects: Vec<&ObjectPath>) -> zbus::Result<LockResult>;
fn lock(&self, objects: Vec<&ObjectPath<'_>>) -> zbus::Result<LockResult>;

fn get_secrets(
&self,
objects: Vec<ObjectPath>,
objects: Vec<ObjectPath<'_>>,
) -> zbus::Result<HashMap<OwnedObjectPath, Secret>>;

fn read_alias(&self, name: &str) -> zbus::Result<OwnedObjectPath>;

fn set_alias(&self, name: &str, collection: ObjectPath) -> zbus::Result<()>;
fn set_alias(&self, name: &str, collection: ObjectPath<'_>) -> zbus::Result<()>;

#[dbus_proxy(property)]
fn collections(&self) -> zbus::fdo::Result<Vec<ObjectPath>>;
fn collections(&self) -> zbus::fdo::Result<Vec<ObjectPath<'_>>>;
}

#[derive(Deserialize, Serialize, Type)]
Expand Down
4 changes: 2 additions & 2 deletions src/secret_service/proxy/secrets_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ trait Collection {

fn create_item(
&self,
properties: HashMap<&str, Value>,
properties: HashMap<&str, Value<'_>>,
secret: Secret,
replace: bool,
) -> zbus::Result<CreateItemResult>;

#[dbus_proxy(property)]
fn items(&self) -> zbus::fdo::Result<Vec<ObjectPath>>;
fn items(&self) -> zbus::fdo::Result<Vec<ObjectPath<'_>>>;

#[dbus_proxy(property)]
fn label(&self) -> zbus::fdo::Result<String>;
Expand Down
2 changes: 1 addition & 1 deletion src/secret_service/proxy/secrets_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use zvariant_derive::Type;
trait Item {
fn delete(&self) -> zbus::Result<OwnedObjectPath>;

fn get_secret(&self, session: &ObjectPath) -> zbus::Result<Secret>;
fn get_secret(&self, session: &ObjectPath<'_>) -> zbus::Result<Secret>;

fn set_secret(&self, secret: SecretInput) -> zbus::Result<()>;

Expand Down
2 changes: 1 addition & 1 deletion src/secret_service/proxy/secrets_prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ trait Prompt {
fn dismiss(&self) -> zbus::Result<()>;

#[dbus_proxy(signal)]
fn completed(&self, dismissed: bool, result: Value) -> zbus::Result<()>;
fn completed(&self, dismissed: bool, result: Value<'_>) -> zbus::Result<()>;
}
12 changes: 6 additions & 6 deletions src/secret_service/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

use crate::secret_service::proxy::secrets::{OpenSessionResult, SecretsProxy};
use crate::secret_service::proxy::secrets::{OpenSessionResult, SecretsProxyBlocking};
use anyhow::Result;
use hkdf::Hkdf;
use openssl::bn::BigNum;
use sha2::Sha256;
use std::borrow::Borrow;
use zbus::Connection;
use zbus::blocking::Connection;
use zvariant::OwnedObjectPath;

pub const SERVICE_NAME: &str = "org.freedesktop.secrets";

pub struct Session<'a> {
secrets: SecretsProxy<'a>,
secrets: SecretsProxyBlocking<'a>,
connection: Connection,
session_path: OwnedObjectPath,
aes_key: Vec<u8>,
Expand All @@ -32,8 +32,8 @@ impl Session<'_> {
let key = dh.generate_key()?;
let public_key = key.public_key();

let connection = zbus::Connection::new_session()?;
let secrets: SecretsProxy = SecretsProxy::new(&connection)?;
let connection = zbus::blocking::Connection::session()?;
let secrets: SecretsProxyBlocking = SecretsProxyBlocking::new(&connection)?;
let session: OpenSessionResult =
secrets.open_session(DH_ALGORITHM, public_key.to_vec().as_slice().into())?;

Expand All @@ -57,7 +57,7 @@ impl Session<'_> {
})
}

pub fn secrets_proxy(&self) -> &SecretsProxy {
pub fn secrets_proxy(&self) -> &SecretsProxyBlocking {
&self.secrets
}

Expand Down

0 comments on commit 594d75e

Please sign in to comment.