aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorTeddy Wing2016-11-14 01:56:15 -0500
committerTeddy Wing2016-11-14 01:56:15 -0500
commit5f24d24ab4054dbcaf47b40736604abdabb32d10 (patch)
tree182ad49ad84d3bb5ce5db6b3206f9068ff5730bc /src/main.rs
parent8ca74dd4517a5c8e10238aea5cf1de7a36870240 (diff)
downloadPassextract-5f24d24ab4054dbcaf47b40736604abdabb32d10.tar.bz2
Clear clipboard on quit
The last thing copied from Passextract will stick around in your clipboard, potentially opening up your password to accidental pasting or a clipboard exploit. Pass deals with this in a nice way, by restoring your clipboard back to what was copied before after a set time delay. Here that same functionality is more difficult to achieve because the Clipboard crate can only deal with strings. So if for example you've copied a file, an image, a program's proprietary type, or some other binary data, it can't be restored with the Clipboard crate. Pass is able to do this because it uses the OS X `pbcopy`/`pbpaste` commands under the hood, which do support binary data. We could do that here I suppose, but it's easier and cross-platform to leverage a library. My heavy-handed solution to the problem of clipboard insecurity is to just overwrite the clipboard with an empty string when Passextract quits. The solution is not ideal because it doesn't preserve your past clipboard entry, and it forces you to keep the Passextract menu open until you paste the copied entry, but it's better than nothing when it comes to keeping the clipboard secure. If there's an error writing to the clipboard, Passextract will refuse to quit.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 8e497c7..2a196d3 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -117,7 +117,11 @@ fn main() {
if let Some(Event::Key(ch)) = evt {
match ch {
'q' | '\x03' => {
- break;
+ // Clear the clipboard on quit
+ match clipboard_ctx.set_contents("".to_owned()) {
+ Ok(_) => break,
+ Err(_) => continue,
+ }
}
'j' => {
if selection.y < options.len() + 1 {