-
-
Notifications
You must be signed in to change notification settings - Fork 63
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
Gnome Search Provider for Ripasso #359
Open
Fingel
wants to merge
3
commits into
cortex:master
Choose a base branch
from
Fingel:gnome-search-provider
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "ripasso-gnome-search-provider" | ||
version = "0.1.0" | ||
edition = "2021" | ||
authors = ["Austin Riba <[email protected]>"] | ||
|
||
[dependencies] | ||
arboard = { version = "3.4.1", features = ["wayland-data-control"] } | ||
ripasso = { path = "../", version = "0.7.0-alpha" } | ||
search-provider = "0.10.0" | ||
tokio = { version = "1.40.0", features = ["macros"] } | ||
zbus = { version = "4.4.0", features = ["tokio"] } | ||
zeroize = "1.8.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Ripasso Gnome Search Provider | ||
|
||
WIP search provider for GNOME using ripasso. | ||
|
||
## Setting a custom PASSWORD_STORE_DIR | ||
|
||
Use `systemctl --user edit org.gnome.Ripasso.SearchProvider.service` | ||
to create an override file that contains the following: | ||
|
||
```ini | ||
[Service] | ||
Environment="PASSWORD_STORE_DIR=/path/to/password-store" | ||
``` |
9 changes: 9 additions & 0 deletions
9
gnome_search_provider/conf/org.gnome.Ripasso.SearchProvider.desktop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[Desktop Entry] | ||
Version=1.0 | ||
Categories=GNOME;Security; | ||
Icon=dialog-password | ||
Name=Ripasso | ||
Comment=GNOME Shell search provider for Ripasso | ||
Terminal=true | ||
Type=Application | ||
OnlyShowIn=GNOME; |
4 changes: 4 additions & 0 deletions
4
gnome_search_provider/conf/org.gnome.Ripasso.SearchProvider.service.dbus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[D-BUS Service] | ||
Name=org.gnome.Ripasso.SearchProvider | ||
Exec=/usr/lib/ripasso-search-provider/ripasso-gnome-search-provider | ||
SystemdService=org.gnome.Ripasso.SearchProvider.service |
7 changes: 7 additions & 0 deletions
7
gnome_search_provider/conf/org.gnome.Ripasso.SearchProvider.service.systemd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[Unit] | ||
Description=Ripasso Gnome Shell search provider for GNOME | ||
|
||
[Service] | ||
Type=dbus | ||
BusName=org.gnome.Ripasso.SearchProvider | ||
ExecStart=/usr/lib/ripasso-search-provider/ripasso-gnome-search-provider |
5 changes: 5 additions & 0 deletions
5
gnome_search_provider/conf/org.gnome.Ripasso.search-provider.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[Shell Search Provider] | ||
DesktopId=org.gnome.Ripasso.SearchProvider.desktop | ||
BusName=org.gnome.Ripasso.SearchProvider | ||
ObjectPath=/org/gnome/Ripasso/SearchProvider | ||
Version=2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env bash | ||
set -eu -o pipefail | ||
cd "$(dirname "$(realpath "${0}")")" | ||
|
||
DATADIR=${DATADIR:-/usr/share} | ||
LIBDIR=${LIBDIR:-/usr/lib} | ||
|
||
install -Dm 0755 ../target/release/ripasso-gnome-search-provider "${LIBDIR}"/ripasso-search-provider/ripasso-gnome-search-provider | ||
|
||
install -Dm 0644 conf/org.gnome.Ripasso.search-provider.ini "${DATADIR}"/gnome-shell/search-providers/org.gnome.Ripasso.search-provider.ini | ||
|
||
install -Dm 0644 conf/org.gnome.Ripasso.SearchProvider.desktop "${DATADIR}"/applications/org.gnome.Ripasso.SearchProvider.desktop | ||
|
||
install -Dm 0644 conf/org.gnome.Ripasso.SearchProvider.service.dbus "${DATADIR}"/dbus-1/services/org.gnome.Ripasso.SearchProvider.service | ||
|
||
install -Dm 0644 conf/org.gnome.Ripasso.SearchProvider.service.systemd "${LIBDIR}"/systemd/user/org.gnome.Ripasso.SearchProvider.service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
use arboard::Clipboard; | ||
use ripasso::pass::PasswordStore; | ||
use search_provider::{ResultID, ResultMeta, SearchProvider, SearchProviderImpl}; | ||
use std::{collections::HashMap, path::PathBuf, thread, time}; | ||
use zbus::{blocking::Connection, proxy, zvariant::Value}; | ||
use zeroize::Zeroize; | ||
|
||
#[proxy( | ||
default_service = "org.freedesktop.Notifications", | ||
default_path = "/org/freedesktop/Notifications" | ||
)] | ||
trait Notifications { | ||
fn notify( | ||
Fingel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
&self, | ||
app_name: &str, | ||
replaces_id: u32, | ||
app_icon: &str, | ||
summary: &str, | ||
body: &str, | ||
actions: &[&str], | ||
hints: HashMap<&str, &Value<'_>>, | ||
expire_timeout: i32, | ||
) -> zbus::Result<u32>; | ||
} | ||
|
||
fn copy_to_clipbard(content: &String) { | ||
let mut clipboard = Clipboard::new().unwrap(); | ||
clipboard.set_text(content).unwrap(); | ||
thread::spawn(|| { | ||
thread::sleep(time::Duration::from_secs(40)); | ||
let mut clipboard = Clipboard::new().unwrap(); | ||
clipboard.set_text(&String::new()).unwrap(); | ||
Fingel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
} | ||
|
||
fn send_notification(summary: String, body: String) { | ||
thread::spawn(move || { | ||
let connection = Connection::session().unwrap(); | ||
let proxy = NotificationsProxyBlocking::new(&connection).unwrap(); | ||
let _ = proxy.notify( | ||
"ripasso", | ||
0, | ||
"dialog-password", | ||
&summary, | ||
&body, | ||
&[], | ||
HashMap::from([("transient", &Value::Bool(true))]), | ||
4000, | ||
); | ||
}) | ||
.join() | ||
.unwrap(); | ||
} | ||
|
||
struct Application { | ||
password_store: PasswordStore, | ||
} | ||
|
||
impl SearchProviderImpl for Application { | ||
fn activate_result(&self, identifier: ResultID, terms: &[String], _timestamp: u32) { | ||
let passwords = self.password_store.all_passwords().unwrap_or_default(); | ||
if let Some(password) = passwords | ||
.iter() | ||
.find(|entry| entry.name == identifier.to_owned()) | ||
Fingel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
if terms[0] == "otp" { | ||
let mut otp = match password.mfa(&self.password_store) { | ||
Ok(otp) => otp, | ||
Err(err) => { | ||
send_notification("OTP Error".to_string(), err.to_string()); | ||
return; | ||
} | ||
}; | ||
copy_to_clipbard(&otp); | ||
otp.zeroize(); | ||
send_notification(identifier, "OTP copied to clipboard".to_string()); | ||
} else { | ||
let mut secret = match password.password(&self.password_store) { | ||
Ok(secret) => secret, | ||
Err(err) => { | ||
send_notification("Password Error".to_string(), err.to_string()); | ||
return; | ||
} | ||
}; | ||
copy_to_clipbard(&secret); | ||
secret.zeroize(); | ||
send_notification(identifier, "Password copied to clipboard".to_string()); | ||
} | ||
} else { | ||
send_notification("Error".to_string(), "Could Not Find Password".to_string()); | ||
} | ||
} | ||
|
||
fn initial_result_set(&self, terms: &[String]) -> Vec<ResultID> { | ||
let search_terms = if terms[0] == "otp" { | ||
&terms[1..] | ||
} else { | ||
terms | ||
}; | ||
|
||
self.password_store | ||
.all_passwords() | ||
.unwrap_or_default() | ||
.iter() | ||
.filter(|entry| { | ||
search_terms | ||
.iter() | ||
.any(|term| entry.name.to_lowercase().contains(&term.to_lowercase())) | ||
}) | ||
.map(|entry| entry.name.to_owned()) | ||
.collect() | ||
} | ||
|
||
fn result_metas(&self, identifiers: &[ResultID]) -> Vec<ResultMeta> { | ||
identifiers | ||
.iter() | ||
.map(|id| ResultMeta::builder(id.to_owned(), id).build()) | ||
.collect() | ||
} | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> zbus::Result<()> { | ||
let home = std::env::var("HOME").expect("Could not determine $HOME"); | ||
let home_path = PathBuf::from(home); | ||
let default_path = match std::env::var("PASSWORD_STORE_DIR") { | ||
Ok(val) => PathBuf::from(val), | ||
Err(_) => [home_path.to_str().unwrap(), ".password-store"] | ||
.iter() | ||
.collect(), | ||
}; | ||
let password_store = PasswordStore::new( | ||
"default", | ||
&Some(default_path), | ||
&None, | ||
&Some(home_path), | ||
&None, | ||
&ripasso::crypto::CryptoImpl::GpgMe, | ||
&None, | ||
) | ||
.unwrap(); | ||
let app = Application { password_store }; | ||
SearchProvider::new( | ||
app, | ||
"org.gnome.Ripasso.SearchProvider", | ||
"/org/gnome/Ripasso/SearchProvider", | ||
) | ||
.await?; | ||
Ok(()) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need some more instructions on how to use this.
What should a user do after they run the install.sh script, should they enable the systemd services, or is it a gnome setting somewhere to enable it?
A screenshot on how it looks to use the searchbar and get results from ripasso would maybe also be nice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the Readme with instructions and a screenshot.
Also thank you for making me realize I was working without Clippy enabled in my editor this entire time...
Ideally, the steps in the install.sh script would be baked into distribution packages. For example, I have a PKGBUILD for Arch that does the installation. Much better because they are cleaned up when the package is uninstalled.