From 30c2e387fa9edb03b16ce7f205d61d0babd8caaa Mon Sep 17 00:00:00 2001 From: Stuart Ryan Date: Thu, 14 Jan 2016 11:45:12 +1100 Subject: [PATCH 1/2] Updated for v 1.4.2 NOTE: This version *requires* the LastPass CLI v 0.7.1 or higher due to this new feature --> Login process completely changed over to use AppleScript (cleaner and nicer). This was thanks to work between myself and Bob from LastPass who maintains the official LastPass CLI to add a feature allowing an external login prompt to be used. Login password prompt now uses an AppleScript password prompt. Fix to allow you to search for words in any order. Vault item's which now require re-authentication will pop up the AppleScript login prompt. Has now been tested with a Vault with over 30,000 items for performance tweaks. (I have since been told by LastPass support their soft limit is significantly lower than this at ~2500 items explains why I was having some issues in testing). More resilient escaping of text in the XML to ensure that special characters should not cause any issues. Fixed missing quotes in some areas that could cause issues with spaces. Squashed a little regex bug and wiped up the goo. Fixed issues with spaces in certain paths we referenced Fixed how the initial login process is run after a reboot. This required the changes made to how we manage the login process and it has subsequently been cleaned up significantly. Other minor general tweaks. Signed-off-by: Stuart Ryan --- workflow/applescript.scpt | Bin 0 -> 9484 bytes workflow/info.plist | 126 ++++++++++++++++++------------- workflow/passwordInput.osascript | 13 ++++ 3 files changed, 85 insertions(+), 54 deletions(-) create mode 100644 workflow/applescript.scpt create mode 100755 workflow/passwordInput.osascript diff --git a/workflow/applescript.scpt b/workflow/applescript.scpt new file mode 100644 index 0000000000000000000000000000000000000000..0dcf4a517a256ba3e48e7856a2dbf1e3a647be62 GIT binary patch literal 9484 zcmeHNd6bmZvHyKN1o7*+4K1L=X#6s=Dl-EHH;hIE6cj{Z05yrw%=9oVJ>6}055s6w z6c<$76*t^>aaY{;eMLc0T)`}mXp#wO_I zF+(LwGw|nzL@twzwFRkkKGB${kL45TR8Vz5G9JstgVtCgUsF>PWU}#0ESpHp43g=Y zi4^PU`gktKuBxClk#7p}iF`61RE>+}@(09nxnP{4RdIbp&<)=0*ffewaW5K>Kn@us z5kngSq>x6QZH-LzY}0a@tpTcV0I}k1%Mk`>Whue_8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IEG)pf5bulXggGIZqr@Jm#2%q!y|3T{etgwNkW=rCX&)fy?Hd|OB@TO0T)RKp5f52B&^gH!#*wm>Pr**HI5Y~Yc>*<3X@|Syykr} z&pF9HS-5czGEC-b*tNZtV?p{|Oi3B6GHk+zIpF%>;++b5r{ z`E2dym8hK1)LpyR+3wX-;oI&nN3Wg`LyyhSa}YbCF>E$ChMxULPe-rG6Q-e847~@l zvN@5qVBUxMucx6;Kb?i;E!&lUv$WXC>GmHK!&WhDT}#B@ZjH(qw&C#LVC?8Repl|O zavfW_j%~{weO*UI(`2sHFNXg8bhQ`;Fb|jy?DrJmph9gsyLxwMe2xx=`C;|yoBs_y Cpp^#z literal 0 HcmV?d00001 diff --git a/workflow/info.plist b/workflow/info.plist index 7334ebf..4539d64 100644 --- a/workflow/info.plist +++ b/workflow/info.plist @@ -12,7 +12,7 @@ destinationuid - D05CE8AC-DFE8-46FC-A600-3163BAF7AD23 + D21298B3-763D-48F9-A804-C3B06D3B70E7 modifiers 0 modifiersubtext @@ -56,11 +56,11 @@ destinationuid - D05CE8AC-DFE8-46FC-A600-3163BAF7AD23 + D21298B3-763D-48F9-A804-C3B06D3B70E7 modifiers 262144 modifiersubtext - Initiate LP Command Line Client Login + Login to LastPass Vault destinationuid @@ -153,7 +153,7 @@ - D05CE8AC-DFE8-46FC-A600-3163BAF7AD23 + D21298B3-763D-48F9-A804-C3B06D3B70E7 DE8D285B-733F-4B2D-91DA-4613717E2005 @@ -188,6 +188,31 @@ LastPass CLI objects + + config + + concurrently + + escaping + 0 + script + --display notification "Please wait... preparing login process..." with title "LastPass Login" --Kill any previous login process as sometimes they hang or a user may interrupt them, if there are none (which there often are...) we will get an error response which we ignore. try do shell script "killall -9 lpass > /dev/null 2>&1" end try try set login_email to do shell script "`perl -e 'use strict; use warnings; my $emailAddress =`security find-generic-password -w -s \"alfred-lastpass-email-address\"`; chomp $emailAddress; print $emailAddress;'`" on error display alert "Email address not set" message "It appears that no email address has been set. Please run 'lpsetemail your_email@example.com' and try again." as critical return end try --Try to get a login timeout if a custom one has been set, if not we set to default try set login_timeout to do shell script "`perl -e 'use strict; use warnings; my $loginTimeout =`security find-generic-password -w -s \"alfred-lastpass-login-timeout\"`; chomp $loginTimeout; print $loginTimeout;'`" on error set login_timeout to 28800 end try tell application "Finder" set current_path to container of (path to me) as alias end tell set current_unix_path to POSIX path of current_path --set osascript to current_unix_path & "passwordInput.osascript" set osascript to (system attribute "alfred_preferences") & "/workflows/" & (system attribute "alfred_workflow_uid") & "/passwordInput.osascript" do shell script "export LPASS_ASKPASS=\"" & osascript & "\"" do shell script "launchctl setenv LPASS_ASKPASS \"" & osascript & "\"" do shell script "launchctl setenv LPASS_AGENT_TIMEOUT " & login_timeout tell application "Finder" if exists POSIX file "/usr/bin/lpass" then set lpass_binary to "/usr/bin/lpass" else if exists POSIX file "/usr/local/bin/lpass" then set lpass_binary to "/usr/local/bin/lpass" else if exists POSIX file "/opt/local/bin/lpass" then set lpass_binary to "/opt/local/bin/lpass" end if end tell --improvement required here, test if we actually HAVE an lpass_binary and if not error out if ("{query}" = "scriptlocationnotset") then +display notification "Please wait... the alfred search will be presented once login is complete." with title "LastPass Login" +end if do shell script "/bin/bash -c '" & "export TERM=\"xterm-256color\" && export LPASS_ASKPASS=\"" & osascript & "\" && export LPASS_AGENT_TIMEOUT=" & login_timeout & " && " & lpass_binary & " login --trust \"" & login_email & "\" && clear && " & lpass_binary & " ls --sync=now > /dev/null 2>&1 && exit 0'" + +if ("{query}" = "scriptlocationnotset") then +tell application "Alfred 2" to search "lp " +end if + type + 6 + + type + alfred.workflow.action.script + uid + D21298B3-763D-48F9-A804-C3B06D3B70E7 + version + 0 + config @@ -234,40 +259,6 @@ version 0 - - config - - escaping - 0 - script - killall -9 lpass > /dev/null 2>&1 -clear -login_email=`perl -e 'use strict; use warnings; my $emailAddress =\`security find-generic-password -w -s "alfred-lastpass-email-address"\`; chomp $emailAddress; print $emailAddress;'` -login_timeout=`perl -e 'use strict; use warnings; my $loginTimeout =\`security find-generic-password -w -s "alfred-lastpass-login-timeout"\`; chomp $loginTimeout; print $loginTimeout;'` -if [[ -z $login_timeout ]]; then -login_timeout="28800" -fi -clear -if [[ -z $login_email ]]; then -echo "It appears that no email address has been set"; -echo "Please run 'lpsetemail your_email@example.com'"; -fi -launchctl setenv LPASS_AGENT_TIMEOUT $login_timeout && export LPASS_AGENT_TIMEOUT=$login_timeout -for f in lpass /usr/local/bin/lpass /opt/local/bin/lpass /usr/bin/lpass; do -if test -x $f; then -lpass_exec=$f -fi -done -clear -$lpass_exec login --trust "$login_email" && clear && echo 'Forcing vault synchronisation... Please wait... (this window will close when complete)' && $lpass_exec ls --sync=now > /dev/null 2>&1 && exit 0 - - type - alfred.workflow.action.terminalcommand - uid - D05CE8AC-DFE8-46FC-A600-3163BAF7AD23 - version - 0 - config @@ -332,7 +323,7 @@ print $details[0]; argumenttype 0 escaping - 127 + 126 keyword lp queuedelaycustom @@ -359,6 +350,22 @@ $search=~ s/\'/\\'/g; # exit 0; #} +my $loginScriptLocation = `launchctl getenv LPASS_ASKPASS`; + +chomp($loginScriptLocation); + +#check if getenv LPASS_ASKPASS is not set... if it isn't a login definitely +#hasn't been completed by the flow and needs to be. + +if ($loginScriptLocation eq "") +{ +print qq{<?xml version="1.0"?>\n<items>\n}; +print qq{<item uid="error-login"><arg>scriptlocationnotset</arg><title>It appears you are not logged in to LastPass.</title><subtitle>Please login using the 'lplogin' command or press 'ctrl' + enter to login now.</subtitle><icon>icon.png</icon></item>\n}; + +print "</items>\n"; +exit 1; +} + my ($agent, $agentErr, $agentErrCode) = capture { system('ps -ef | grep "lpass \[agent\]" | grep -v grep | grep -v "perl"'); }; @@ -369,8 +376,13 @@ foreach my $f (qw@lpass /usr/local/bin/lpass /opt/local/bin/lpass /usr/bin/lpass if (-x $f); } +#add multiple grep statements to deal with multiple words as AWK on OSx +#does not allow for case insensitive searches + +$search=~ s/ /" | grep -i "/g; + my ($results, $err, $errorCode) = capture { - system($lpass_exec . ' ls --sync=no | grep -i ' . $search); + system($lpass_exec . ' ls --sync=no | grep -i "' . $search . '"'); }; print qq{<?xml version="1.0"?>\n<items>\n}; @@ -393,24 +405,25 @@ exit 2; }else { my @resultsArray = split /\n/, $results; + foreach my $result (@resultsArray) { my $id; my $name; -if ($result =~ '^(.*) \[id: ([0-9]*)\]$'){ -$name = $1; -$id = $2; +if ($result =~ '^(.*) +\[id: ([0-9]*)\]'){ +$name = "$1"; +$id = "$2"; } -print qq{<item uid="$id"><arg>'$name', '$id'</arg><title>$name</title><subtitle></subtitle><icon>icon.png</icon></item>\n}; +print qq{<item uid="$id"><arg><![CDATA['$name', '$id']]></arg><title><![CDATA[$name]]></title><subtitle></subtitle><icon>icon.png</icon></item>\n}; } print "</items>\n"; } exit 0; subtext - Search Laspass Vault + Search Lastpass Vault title - Search Laspass Vault + Search Lastpass Vault type 4 withspace @@ -539,7 +552,7 @@ print $details[0]; escaping 127 script - + #!/bin/bash for f in lpass /usr/local/bin/lpass /opt/local/bin/lpass /usr/bin/lpass; do if test -x $f; then lpass_exec=$f @@ -657,7 +670,9 @@ exit 0; escaping 102 script - security add-generic-password -a "alfred-lastpass-email-address" -s "alfred-lastpass-email-address" -w "{query}" -C "note" -U + #!/bin/bash + +security add-generic-password -a "alfred-lastpass-email-address" -s "alfred-lastpass-email-address" -w "{query}" -C "note" -U echo "{query}" type @@ -747,7 +762,9 @@ echo "{query}" escaping 102 script - security add-generic-password -a "alfred-lastpass-login-timeout" -s "alfred-lastpass-login-timeout" -w "{query}" -C "note" -U + #!/bin/bash + +security add-generic-password -a "alfred-lastpass-login-timeout" -s "alfred-lastpass-login-timeout" -w "{query}" -C "note" -U echo "{query}" type @@ -781,13 +798,14 @@ echo "{query}" readme - See installation instructions at http://technicalnotebook.com/wiki/display/ALFREDWORKFLOWS/Installation+Instructions+-+LastPass+Workflow+for+Alfred - -For support please log a ticket on my JIRA BugTracker —> http://technicalnotebook.com/jira/browse/LPALFRED/ + See installation instructions at https://github.com/stuartcryan/lastpass-alfred-workflow +For support please log a ticket on https://github.com/stuartcryan/lastpass-alfred-workflow NOTE: This Alfred Workflow is not affiliated in any way with LastPass. The LastPass trademark and logo are owned by LastPass.com. The LastPass logo and product name have been used with permission of the LastPass team. -My thanks go out to LastPass for their awesome product and the new CLI! +My thanks go out to LastPass for their awesome product and the new CLI! + +Version: 1.4.2 uidata 01DFFE0F-13AB-4E19-AC39-8E2177548224 @@ -870,7 +888,7 @@ My thanks go out to LastPass for their awesome product and the new CLI! ypos 380 - D05CE8AC-DFE8-46FC-A600-3163BAF7AD23 + D21298B3-763D-48F9-A804-C3B06D3B70E7 ypos 160 diff --git a/workflow/passwordInput.osascript b/workflow/passwordInput.osascript new file mode 100755 index 0000000..a0ec2b1 --- /dev/null +++ b/workflow/passwordInput.osascript @@ -0,0 +1,13 @@ +#!/usr/bin/osascript +set my_password to display dialog ¬ + "Please enter your LastPass Vault password:" with title ¬ + "Password" with icon caution ¬ + default answer ¬ + "" buttons {"Cancel", "OK"} default button 2 ¬ + giving up after 295 ¬ + with hidden answer +if length of (text returned of my_password) is not 0 then + return (text returned of my_password) +else + display dialog "You didn't enter a password!" buttons ["OK"] default button 1 +end if From a3b869955e419dffa9280b783fdb4998b60087a5 Mon Sep 17 00:00:00 2001 From: Stuart Ryan Date: Thu, 14 Jan 2016 11:49:35 +1100 Subject: [PATCH 2/2] Updated Readme Signed-off-by: Stuart Ryan --- README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 929e742..0b68fa0 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,16 @@ Simple yet powerful integration with the Lastpass CLI so you can now get your passwords out of your Lastpass vault and straight into the clipboard from within Alfred. +## Important note for v.1.4.2 +Please note, v1.4.2 and higer of the workflow require v0.7.1 or higher of the LastPass CLI to operate, if you do not have this then it will not work. Therefore please ensure you update to the latest version of the CLI. + ## How to use the workflow Check out the official YouTube video, it will give you a quick two and a half minute rundown (updated for v1.2 and above). [![ScreenShot](http://akamai.technicalnotebook.com/alfred-workflow-images/lastpass-cli-for-alfred/demonstration_of_lastpass_workflow_for_alfred_v1_2.png)](https://www.youtube.com/watch?v=DJvtjBs2r6E) ## Donations -This workflow represents many many hours effort of development, testing and rework. So if you love the workflow, and get use out of it every day, if you would like to donate as a thank you to buy me more caffeine giving Diet Coke, some Cake, or to put towards a shiny new gadget you can [donate to me via Paypal](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=JM6E65M2GLXHE). +This workflow (and the 1.4.2 update especially) represents many many hours effort of development, testing and rework. So if you love the workflow, and get use out of it every day, if you would like to donate as a thank you to buy me more caffeine giving Diet Coke, some Cake, or to put towards a shiny new gadget you can [donate to me via Paypal](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=JM6E65M2GLXHE). PayPal — The safer, easier way to pay online. @@ -49,6 +52,18 @@ This workflow represents many many hours effort of development, testing and rewo ## History +* Version 1.4.2 + 1. NOTE: This version *requires* the LastPass CLI v 0.7.1 or higher due to this new feature --> Login process completely changed over to use AppleScript (cleaner and nicer). This was thanks to work between myself and Bob from LastPass who maintains the official LastPass CLI to add a feature allowing an external login prompt to be used. + 2. Login password prompt now uses an AppleScript password prompt. + 3. Fix to allow you to search for words in any order. + 4. Vault item's which now require re-authentication will pop up the AppleScript login prompt. + 5. Has now been tested with a Vault with over 30,000 items for performance tweaks. (I have since been told by LastPass support their soft limit is significantly lower than this at ~2500 items explains why I was having some issues in testing). + 6. More resilient escaping of text in the XML to ensure that special characters should not cause any issues. + 7. Fixed missing quotes in some areas that could cause issues with spaces. + 8. Squashed a little regex bug and wiped up the goo. + 9. Fixed issues with spaces in certain paths we referenced + 10. Fixed how the initial login process is run after a reboot. This required the changes made to how we manage the login process and it has subsequently been cleaned up significantly. + 11. Other minor general tweaks. * Version 1.2 1. Bug - Removed deprecated framework code 2. Bug - Merged [pull request #4](https://github.com/stuartcryan/lastpass-alfred-workflow/pull/4) from [jsquyres](https://github.com/jsquyres) "we-love-macports-too" to support macports installs of the lastpass-CLI