Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: Add service method Lock and Unlock implementation #150

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

warusadura
Copy link
Collaborator

@warusadura warusadura commented Oct 31, 2024

This change adds Secret Service method Lock and Unlock implementation.

@warusadura warusadura marked this pull request as draft October 31, 2024 16:56
@warusadura
Copy link
Collaborator Author

Service method Lock should emit PropertiesChanged signal for each Locked item and collection. Currently oo7_daemon can't do this with this change. Can you help me figure out how to do this. So far I have tried moving set methods (set_locked) inside the Service impl (inside interface attribute) and also marking them with zbus properties attribute. None of these approaches worked so far. @bilelmoussaoui

server/src/collection.rs Outdated Show resolved Hide resolved
server/src/collection.rs Outdated Show resolved Hide resolved
) -> Result<(Vec<OwnedObjectPath>, ObjectPath), ServiceError> {
todo!()
let mut locked: Vec<OwnedObjectPath> = Vec::new();
let prompt = ObjectPath::default();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Prompt::default() so we can remove the Default impl later and track all the mis-usages left.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree. But, a prompt isn't required here, like at all. So, returning an empty objectpath: '/' is enough. And we don't have to worry about cleaning up later :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did you got this information from ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on three things:

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gnome-keyring-daemon is the least respectful for the secrets spec, i wouldn't follow it "blindly"

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is nothing on the spec about keeping track of the objects that are locked with a prompt and a way to return them. This can be consider as a hint there is nothing related to actually prompting a system prompt here.

There is, the prompt has a details return variable that is a zvariant::Value, it can contain anything, even a list of object paths ;)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, there is no way to pass a list of items to unlock into prompt & then get the result of what got locked and what wasn't. But there should definitely be a prompt used here otherwise the spec is wrong which I don't think it is...

server/src/service.rs Outdated Show resolved Hide resolved
server/src/service.rs Outdated Show resolved Hide resolved
server/src/service.rs Outdated Show resolved Hide resolved
server/src/service.rs Outdated Show resolved Hide resolved
server/src/service.rs Outdated Show resolved Hide resolved
@bilelmoussaoui
Copy link
Owner

Service method Lock should emit PropertiesChanged signal for each Locked item and collection

That is normal, because you have to make use of the auto-generated method called $property_changed. Which you should call after you updated the value of locked in the set_locked method...

@warusadura
Copy link
Collaborator Author

Service method Lock should emit PropertiesChanged signal for each Locked item and collection

That is normal, because you have to make use of the auto-generated method called $property_changed. Which you should call after you updated the value of locked in the set_locked method...

Understood, thanks!

@warusadura warusadura force-pushed the some_service_methods branch 2 times, most recently from b414c91 to ef6929c Compare November 3, 2024 03:12
@warusadura warusadura marked this pull request as ready for review November 3, 2024 03:24
@warusadura warusadura force-pushed the some_service_methods branch 3 times, most recently from 0f2313a to 13e500c Compare November 3, 2024 16:01
server/src/collection.rs Outdated Show resolved Hide resolved
server/src/service_manager.rs Outdated Show resolved Hide resolved
server/src/collection.rs Outdated Show resolved Hide resolved
server/src/collection.rs Outdated Show resolved Hide resolved
server/src/collection.rs Outdated Show resolved Hide resolved
server/src/service.rs Outdated Show resolved Hide resolved
server/src/service.rs Outdated Show resolved Hide resolved
server/src/service.rs Outdated Show resolved Hide resolved
@warusadura warusadura force-pushed the some_service_methods branch 2 times, most recently from 374bd6d to 0d7b53b Compare November 17, 2024 15:12
@warusadura warusadura force-pushed the some_service_methods branch 2 times, most recently from a7d8efc to 4dc75dd Compare November 18, 2024 14:44
server/src/collection.rs Outdated Show resolved Hide resolved
server/src/collection.rs Show resolved Hide resolved
server/src/collection.rs Outdated Show resolved Hide resolved
server/src/item.rs Outdated Show resolved Hide resolved
server/src/service.rs Outdated Show resolved Hide resolved
server/src/collection.rs Show resolved Hide resolved
server/src/service.rs Outdated Show resolved Hide resolved
@bilelmoussaoui
Copy link
Owner

Can you add the unlock implementation as well? Without the prompt bits obviously. Given that it will just be calling the same functions added here

@warusadura
Copy link
Collaborator Author

Can you add the unlock implementation as well? Without the prompt bits obviously. Given that it will just be calling the same functions added here

Yeah, of course. Will do.

@warusadura warusadura changed the title server: Add service method Lock implementation server: Add service method Lock and Unlock implementation Nov 19, 2024
) -> Result<(Vec<OwnedObjectPath>, ObjectPath), ServiceError> {
todo!()
let mut locked = Vec::new();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the exact same implementation, with only difference being the state of locked, put the common code in a function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I have thought about this. But, will this function get messy when adding the Prompt related things during Unlock?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I still follow this and move this to a new function?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basically share what is common between both :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do, thanks!

for object in &objects {
for collection in collections.iter() {
if object == collection.path() {
collection.set_locked(true).await?;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this not doing the same check as unlock? See above for fixing that

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For unlock we need a way to identify when to issue a Prompt. But, for Lock we don't need a prompt at all. This I'm sure :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For unlock we need a way to identify when to issue a Prompt. But, for Lock we #150 (comment) need a prompt at all. This I'm sure :)

The spec disagree with you.

image

The current implementations don't use a prompt here, we might not need it if we agree with both the KDE/GNOME implementors, then it can easily be disabled. But for now, let us assume it is required to be fully compatible with the published specification.

But anyways, the lock/unlock DBus functions would call the "inner" one, so the Unlock could grow some functionality around it and the Lock one won't.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood, thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey, sorry for the delay.

I just realized that my implementation is wrong :) I think we shouldn't do the actual Lock/Unlock (calling collection.set_locked() and item.set_locked()) here. The Lock implementation used to be correct. But, since now both calls should have a prompt, the actual Lock/Unlock should happen inside Prompt. Specifically inside prompt_ready() call. Not inside the service methods. The purpose of service methods (Lock & Unlock) are to filter the objects locked/unlocked without prompt and send them out or send out a prompt without the objects.

question: how do we filter out which objects that we lock/unlock without a prompt?

Unlock:

  • if the objects are already unlocked, then thses object are unlocked without a prompt. So, we return the unlocked objecpaths here and no prompt.
  • if the objects are locked we return a prompt here and no unlocked objecpaths.

Lock:

  • Shoud we do the same for lock?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the reply.

Yeah it's incomplete. But,

The purpose of service methods (Lock & Unlock) are to filter the objects locked/unlocked without prompt and send them out or send out a prompt without the objects.

And currently we're setting the locked status inside service methods. We shouldn't do this here. All we need to do this return objectspaths (locked/unlocked objects list or a prompt).

Since I can't get a feel of Lock with a prompt, I'm not sure when to issue a prompt and when to return locked objectpaths.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who is supposed to modify the collection/item state then? It is supposed to be done once the prompt is finished successfully but still part of the code in Lock/Unlock.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who is supposed to modify the collection/item state then?

org.gnome.keyring.internal.Prompter.Callback PromptReady

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will execute a task, the task will be created inside Lock and Unlock.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the implementation.

Signed-off-by: Dhanuka Warusadura <dhanuka@gnome.org>
@@ -205,6 +205,34 @@ impl Collection {
None
}

#[allow(unused)]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this for?

@@ -28,6 +29,7 @@ pub struct Service {
collections: Arc<Mutex<Vec<Collection>>>,
// Other attributes
manager: Arc<Mutex<ServiceManager>>,
prompt_index: Arc<RwLock<u32>>,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would put this in the ServiceManager instead and would pass that to newly created prompts as well

pub async fn set_locked(
&self,
locked: bool,
objects: &Vec<OwnedObjectPath>,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
objects: &Vec<OwnedObjectPath>,
objects: &[OwnedObjectPath],

for object in objects {
for collection in collections.iter() {
if object == collection.path() {
if !collection.is_locked().await {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this compare it to the value of locked passed to it?

}
break;
} else if let Some(item) = collection.item_from_path(object).await {
if !item.is_locked().await {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

}
break;
}
tracing::info!("Object: {} does not exist.", object);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe warn here instead

#[zbus(object_server)] object_server: &zbus::ObjectServer,
) -> Result<(Vec<OwnedObjectPath>, OwnedObjectPath), ServiceError> {
let unlocked = self.set_locked(false, &objects).await?;
if unlocked.is_empty() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition here seems wrong, you would use a prompt only if there are items which don't have the expected state.

Comment on lines +145 to +147
let n_prompt = *self.prompt_index.read().await + 1;
let prompt = Prompt::new(n_prompt);
*self.prompt_index.write().await = n_prompt;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you pass the service manager when creating the prompt, you could deal with incrementing the prompt index there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants