diff --git a/client/src/crypto/native.rs b/client/src/crypto/native.rs index 672a5e94e..f802688cc 100644 --- a/client/src/crypto/native.rs +++ b/client/src/crypto/native.rs @@ -16,7 +16,7 @@ use sha2::Sha256; use subtle::ConstantTimeEq; use zeroize::{Zeroize, Zeroizing}; -use crate::{portal, Key}; +use crate::{file, Key}; type EncAlg = cbc::Encryptor; type DecAlg = cbc::Decryptor; @@ -138,7 +138,7 @@ pub(crate) fn verify_checksum_md5(digest: impl AsRef<[u8]>, content: impl AsRef< pub(crate) fn derive_key( secret: impl AsRef<[u8]>, - key_strength: Result<(), portal::WeakKeyError>, + key_strength: Result<(), file::WeakKeyError>, salt: impl AsRef<[u8]>, iteration_count: usize, ) -> Key { @@ -157,7 +157,7 @@ pub(crate) fn derive_key( pub(crate) fn legacy_derive_key_and_iv( secret: impl AsRef<[u8]>, - key_strength: Result<(), portal::WeakKeyError>, + key_strength: Result<(), file::WeakKeyError>, salt: impl AsRef<[u8]>, iteration_count: usize, ) -> (Key, Vec) { diff --git a/client/src/error.rs b/client/src/error.rs index 1b584d152..bbfbbf46f 100644 --- a/client/src/error.rs +++ b/client/src/error.rs @@ -7,14 +7,14 @@ pub type Result = std::result::Result; #[derive(Debug)] pub enum Error { /// File backend error. - Portal(crate::portal::Error), + File(crate::file::Error), /// Secret Service error. DBus(crate::dbus::Error), } -impl From for Error { - fn from(e: crate::portal::Error) -> Self { - Self::Portal(e) +impl From for Error { + fn from(e: crate::file::Error) -> Self { + Self::File(e) } } @@ -29,7 +29,7 @@ impl std::error::Error for Error {} impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Self::Portal(e) => write!(f, "Portal error {e}"), + Self::File(e) => write!(f, "File backend error {e}"), Self::DBus(e) => write!(f, "DBus error {e}"), } } diff --git a/client/src/portal/api/attribute_value.rs b/client/src/file/api/attribute_value.rs similarity index 100% rename from client/src/portal/api/attribute_value.rs rename to client/src/file/api/attribute_value.rs diff --git a/client/src/portal/api/encrypted_item.rs b/client/src/file/api/encrypted_item.rs similarity index 100% rename from client/src/portal/api/encrypted_item.rs rename to client/src/file/api/encrypted_item.rs diff --git a/client/src/portal/api/legacy_keyring.rs b/client/src/file/api/legacy_keyring.rs similarity index 99% rename from client/src/portal/api/legacy_keyring.rs rename to client/src/file/api/legacy_keyring.rs index a0b15f603..a8c973a88 100644 --- a/client/src/portal/api/legacy_keyring.rs +++ b/client/src/file/api/legacy_keyring.rs @@ -10,7 +10,7 @@ use endi::{Endian, ReadBytes}; use super::{Item, Secret}; use crate::{ crypto, - portal::{AttributeValue, Error, WeakKeyError}, + file::{AttributeValue, Error, WeakKeyError}, AsAttributes, }; diff --git a/client/src/portal/api/mod.rs b/client/src/file/api/mod.rs similarity index 99% rename from client/src/portal/api/mod.rs rename to client/src/file/api/mod.rs index fcaa05030..01d549b5d 100644 --- a/client/src/portal/api/mod.rs +++ b/client/src/file/api/mod.rs @@ -51,7 +51,7 @@ pub(super) use legacy_keyring::{Keyring as LegacyKeyring, MAJOR_VERSION as LEGAC use super::{Item, Secret}; use crate::{ crypto, - portal::{Error, WeakKeyError}, + file::{Error, WeakKeyError}, AsAttributes, Key, }; @@ -79,7 +79,7 @@ pub struct Keyring { iteration_count: u32, modified_time: u64, usage_count: u32, - pub(in crate::portal) items: Vec, + pub(in crate::file) items: Vec, } impl Keyring { diff --git a/client/src/portal/error.rs b/client/src/file/error.rs similarity index 100% rename from client/src/portal/error.rs rename to client/src/file/error.rs diff --git a/client/src/portal/item.rs b/client/src/file/item.rs similarity index 100% rename from client/src/portal/item.rs rename to client/src/file/item.rs diff --git a/client/src/portal/mod.rs b/client/src/file/mod.rs similarity index 99% rename from client/src/portal/mod.rs rename to client/src/file/mod.rs index 25f6faba1..c0363813c 100644 --- a/client/src/portal/mod.rs +++ b/client/src/file/mod.rs @@ -1,9 +1,9 @@ -//! File backend implementation backed by the [Secret portal](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Secret.html). +//! File backend implementation that can be backed by the [Secret portal](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Secret.html). //! //! ```no_run //! use std::collections::HashMap; //! -//! use oo7::portal::Keyring; +//! use oo7::file::Keyring; //! //! # async fn run() -> oo7::Result<()> { //! let keyring = Keyring::load_default().await?; diff --git a/client/src/portal/secret.rs b/client/src/file/secret.rs similarity index 100% rename from client/src/portal/secret.rs rename to client/src/file/secret.rs diff --git a/client/src/key.rs b/client/src/key.rs index e64aebde4..db87cff1e 100644 --- a/client/src/key.rs +++ b/client/src/key.rs @@ -1,14 +1,14 @@ use zeroize::{Zeroize, ZeroizeOnDrop}; use zvariant::Type; -use crate::{crypto, portal}; +use crate::{crypto, file}; /// A key. #[derive(Debug, Zeroize, ZeroizeOnDrop)] pub struct Key { key: Vec, #[zeroize(skip)] - strength: Result<(), portal::WeakKeyError>, + strength: Result<(), file::WeakKeyError>, } impl AsRef<[u8]> for Key { @@ -25,16 +25,16 @@ impl AsMut<[u8]> for Key { impl Key { pub fn new(key: Vec) -> Self { - Self::new_with_strength(key, Err(portal::WeakKeyError::StrengthUnknown)) + Self::new_with_strength(key, Err(file::WeakKeyError::StrengthUnknown)) } - pub(crate) fn check_strength(&self) -> Result<(), portal::WeakKeyError> { + pub(crate) fn check_strength(&self) -> Result<(), file::WeakKeyError> { self.strength } pub(crate) fn new_with_strength( key: Vec, - strength: Result<(), portal::WeakKeyError>, + strength: Result<(), file::WeakKeyError>, ) -> Self { Self { key, strength } } diff --git a/client/src/keyring.rs b/client/src/keyring.rs index f51f089f2..78af0cd82 100644 --- a/client/src/keyring.rs +++ b/client/src/keyring.rs @@ -6,9 +6,9 @@ use async_lock::RwLock; use tokio::sync::RwLock; use zeroize::Zeroizing; -use crate::{dbus, portal, AsAttributes, Result}; +use crate::{dbus, file, AsAttributes, Result}; -/// A [Secret Service](crate::dbus) or [file](crate::portal) backed keyring +/// A [Secret Service](crate::dbus) or [file](crate::file) backed keyring /// implementation. /// /// It will automatically use the file backend if the application is sandboxed @@ -20,7 +20,7 @@ use crate::{dbus, portal, AsAttributes, Result}; #[derive(Debug)] pub enum Keyring { #[doc(hidden)] - File(Arc), + File(Arc), #[doc(hidden)] DBus(dbus::Collection<'static>), } @@ -33,16 +33,16 @@ impl Keyring { #[cfg(feature = "tracing")] tracing::debug!("Application is sandboxed, using the file backend"); - match portal::Keyring::load_default().await { - Ok(portal) => return Ok(Self::File(Arc::new(portal))), + match file::Keyring::load_default().await { + Ok(file) => return Ok(Self::File(Arc::new(file))), // Do nothing in this case, we are supposed to fallback to the host keyring - Err(super::portal::Error::Portal(ashpd::Error::PortalNotFound(_))) => { + Err(super::file::Error::Portal(ashpd::Error::PortalNotFound(_))) => { #[cfg(feature = "tracing")] tracing::debug!( "org.freedesktop.portal.Secrets is not available, falling back to the Secret Service backend" ); } - Err(e) => return Err(crate::Error::Portal(e)), + Err(e) => return Err(crate::Error::File(e)), }; } else { #[cfg(feature = "tracing")] @@ -159,13 +159,13 @@ impl Keyring { #[derive(Debug)] pub enum Item { #[doc(hidden)] - File(RwLock, Arc), + File(RwLock, Arc), #[doc(hidden)] DBus(dbus::Item<'static>), } impl Item { - fn for_file(item: portal::Item, backend: Arc) -> Self { + fn for_file(item: file::Item, backend: Arc) -> Self { Self::File(RwLock::new(item), backend) } @@ -353,8 +353,8 @@ mod tests { let path = dir.join("default.keyring"); let password = b"test"; - let secret = portal::Secret::from(password.to_vec()); - let keyring = Keyring::File(portal::Keyring::load(&path, secret).await?.into()); + let secret = file::Secret::from(password.to_vec()); + let keyring = Keyring::File(file::Keyring::load(&path, secret).await?.into()); let items = keyring.items().await?; assert_eq!(items.len(), 0); diff --git a/client/src/lib.rs b/client/src/lib.rs index 9774c6b97..a4159246e 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -32,7 +32,7 @@ mod crypto; #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] pub mod crypto; pub mod dbus; -pub mod portal; +pub mod file; mod keyring; @@ -55,7 +55,7 @@ pub trait AsAttributes { fn hash<'a>(&'a self, key: &Key) -> Vec<(&'a str, zeroize::Zeroizing>)> { self.as_attributes() .into_iter() - .map(|(k, v)| (k, crate::portal::AttributeValue::from(v).mac(key))) + .map(|(k, v)| (k, crate::file::AttributeValue::from(v).mac(key))) .collect() } } diff --git a/client/src/migration.rs b/client/src/migration.rs index 8c2d9a838..8e52e999f 100644 --- a/client/src/migration.rs +++ b/client/src/migration.rs @@ -1,4 +1,4 @@ -use crate::{dbus::Service, portal::Keyring, AsAttributes, Result}; +use crate::{dbus::Service, file::Keyring, AsAttributes, Result}; /// Helper to migrate your secrets from the host Secret Service /// to the sandboxed file backend. @@ -8,8 +8,8 @@ use crate::{dbus::Service, portal::Keyring, AsAttributes, Result}; pub async fn migrate(attributes: Vec, replace: bool) -> Result<()> { let service = Service::new().await?; let file_backend = match Keyring::load_default().await { - Ok(portal) => Ok(portal), - Err(super::portal::Error::Portal(ashpd::Error::PortalNotFound(_))) => { + Ok(file) => Ok(file), + Err(super::file::Error::Portal(ashpd::Error::PortalNotFound(_))) => { #[cfg(feature = "tracing")] tracing::debug!("Portal not available, no migration to do"); return Ok(()); diff --git a/portal/src/error.rs b/portal/src/error.rs index caf61d278..c6a91ea0c 100644 --- a/portal/src/error.rs +++ b/portal/src/error.rs @@ -9,10 +9,10 @@ pub enum Error { impl std::fmt::Display for Error { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Error::Rand(e) => f.write_fmt(format_args!("Rand error {e}")), - Error::Oo7(e) => f.write_fmt(format_args!("DBus error: {e}")), - Error::Io(e) => f.write_fmt(format_args!("IO error: {e}")), - Error::Portal(e) => f.write_fmt(format_args!("Portal error: {e}")), + Self::Rand(e) => f.write_fmt(format_args!("Rand error {e}")), + Self::Oo7(e) => f.write_fmt(format_args!("DBus error: {e}")), + Self::Io(e) => f.write_fmt(format_args!("IO error: {e}")), + Self::Portal(e) => f.write_fmt(format_args!("Portal error: {e}")), } } } diff --git a/server/src/collection.rs b/server/src/collection.rs index bd0cd312a..922bc597f 100644 --- a/server/src/collection.rs +++ b/server/src/collection.rs @@ -11,7 +11,7 @@ use oo7::{ api::{Properties, SecretInner}, ServiceError, }, - portal::Keyring, + file::Keyring, }; use tokio::sync::{Mutex, RwLock}; use zbus::{interface, object_server::SignalEmitter, proxy::Defaults, zvariant}; diff --git a/server/src/error.rs b/server/src/error.rs index 07143cb0c..adc5fb7f9 100644 --- a/server/src/error.rs +++ b/server/src/error.rs @@ -3,7 +3,7 @@ use std::fmt; #[derive(Debug)] pub enum Error { // File backend error - Portal(oo7::portal::Error), + File(oo7::file::Error), // Zbus error Zbus(zbus::Error), // IO error @@ -11,7 +11,7 @@ pub enum Error { // Empty password error EmptyPassword, // Invalid item error - InvalidItem(oo7::portal::InvalidItemError), + InvalidItem(oo7::file::InvalidItemError), } impl From for Error { @@ -20,9 +20,9 @@ impl From for Error { } } -impl From for Error { - fn from(err: oo7::portal::Error) -> Self { - Self::Portal(err) +impl From for Error { + fn from(err: oo7::file::Error) -> Self { + Self::File(err) } } @@ -35,7 +35,7 @@ impl From for Error { impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Self::Portal(err) => write!(f, "Portal error {err}"), + Self::File(err) => write!(f, "Portal error {err}"), Self::Zbus(err) => write!(f, "Zbus error {err}"), Self::IO(err) => write!(f, "IO error {err}"), Self::EmptyPassword => write!(f, "Login password can't be empty"), diff --git a/server/src/item.rs b/server/src/item.rs index cd2023ccc..e42cf1fa0 100644 --- a/server/src/item.rs +++ b/server/src/item.rs @@ -7,7 +7,7 @@ use std::{ use oo7::{ dbus::{api::SecretInner, ServiceError}, - portal, + file, }; use tokio::sync::Mutex; use zbus::zvariant::OwnedObjectPath; @@ -18,7 +18,7 @@ use crate::{collection::Collection, Service}; pub struct Item { // Properties locked: Arc, - inner: Arc>, + inner: Arc>, // Other attributes service: Service, collection_path: OwnedObjectPath, @@ -171,7 +171,7 @@ impl Item { impl Item { pub fn new( - item: portal::Item, + item: file::Item, locked: bool, service: Service, collection_path: &OwnedObjectPath, diff --git a/server/src/main.rs b/server/src/main.rs index 2c772753f..76ce325d4 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -6,7 +6,7 @@ mod service; mod session; use clap::Parser; -use oo7::portal::Secret; +use oo7::file::Secret; use service::Service; use crate::error::Error; diff --git a/server/src/service.rs b/server/src/service.rs index fe86e10cc..921c07e68 100644 --- a/server/src/service.rs +++ b/server/src/service.rs @@ -8,7 +8,7 @@ use oo7::{ api::{Properties, SecretInner}, Algorithm, ServiceError, }, - portal::{Keyring, Secret}, + file::{Keyring, Secret}, Key, }; use tokio::sync::{Mutex, RwLock};