Skip to content

Commit e4df717

Browse files
server: Handle keyrings aliases/labels properly
By supporting login alias to default as well as making things more consistent
1 parent 3c57ab6 commit e4df717

1 file changed

Lines changed: 22 additions & 15 deletions

File tree

server/src/service.rs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,17 @@ impl Service {
357357

358358
#[zbus(out_args("collection"))]
359359
pub async fn read_alias(&self, name: &str) -> Result<OwnedObjectPath, ServiceError> {
360+
// Map "login" alias to "default" for compatibility with gnome-keyring
361+
let alias_to_find = if name == Self::LOGIN_ALIAS {
362+
oo7::dbus::Service::DEFAULT_COLLECTION
363+
} else {
364+
name
365+
};
366+
360367
let collections = self.collections.lock().await;
361368

362369
for (path, collection) in collections.iter() {
363-
if collection.alias().await == name {
370+
if collection.alias().await == alias_to_find {
364371
tracing::debug!("Collection: {} found for alias: {}.", path, name);
365372
return Ok(path.to_owned());
366373
}
@@ -419,6 +426,8 @@ impl Service {
419426
}
420427

421428
impl Service {
429+
const LOGIN_ALIAS: &str = "login";
430+
422431
pub async fn run(secret: Option<Secret>, request_replacement: bool) -> Result<(), Error> {
423432
let service = Self::default();
424433

@@ -585,18 +594,14 @@ impl Service {
585594
name: &str,
586595
secret: Option<&Secret>,
587596
) -> Result<(String, String, Keyring), Error> {
588-
// "login" gets "default" alias, others use their own name
589-
let alias = if name == "login" {
597+
let alias = if name.eq_ignore_ascii_case(Self::LOGIN_ALIAS) {
590598
oo7::dbus::Service::DEFAULT_COLLECTION.to_owned()
591599
} else {
592-
name.to_owned()
600+
name.to_owned().to_lowercase()
593601
};
594602

595603
// Use name as label (capitalized for consistency with Login)
596-
let label = if name == "login" {
597-
"Login".to_owned()
598-
} else {
599-
// Capitalize first letter
604+
let label = {
600605
let mut chars = name.chars();
601606
match chars.next() {
602607
None => String::new(),
@@ -696,16 +701,18 @@ impl Service {
696701
let mut collections = self.collections.lock().await;
697702

698703
// Check if we have a default collection
699-
let has_default = discovered_keyrings
700-
.iter()
701-
.any(|(_, alias, _)| alias == oo7::dbus::Service::DEFAULT_COLLECTION);
704+
let has_default = discovered_keyrings.iter().any(|(_, alias, _)| {
705+
alias == oo7::dbus::Service::DEFAULT_COLLECTION || alias == Self::LOGIN_ALIAS
706+
});
702707

703708
if !has_default && auto_create_default {
704709
tracing::info!("No default collection found, creating 'Login' keyring");
705710

706-
let locked_keyring = LockedKeyring::open("login").await.inspect_err(|e| {
707-
tracing::error!("Failed to create default Login keyring: {}", e);
708-
})?;
711+
let locked_keyring = LockedKeyring::open(Self::LOGIN_ALIAS)
712+
.await
713+
.inspect_err(|e| {
714+
tracing::error!("Failed to create default Login keyring: {}", e);
715+
})?;
709716

710717
discovered_keyrings.push((
711718
"Login".to_owned(),
@@ -927,7 +934,7 @@ impl Service {
927934
};
928935

929936
// Create a persistent keyring with the provided secret
930-
let keyring = UnlockedKeyring::open(&label, secret)
937+
let keyring = UnlockedKeyring::open(&label.to_lowercase(), secret)
931938
.await
932939
.map_err(|err| custom_service_error(&format!("Failed to create keyring: {err}")))?;
933940

0 commit comments

Comments
 (0)