Implements support for external autotipe #10
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.
Autotype
This patch adds support for performing autotype in an external utility, reference tickets #3 and #8
I've been using this for the past week or so, fixing behaviors and bugs and improving the autotype program; the main changes have been stable for about a week, and I added the main sequence parsing code a couple of days ago and have updated that code today. The sequence parsing code is shared with
quasiautothrough copy/paste.At a high level, this consists of four changes:
clientserver.go,config.go,kpmenulib.go)prompt.go)prompt.go)sequence.go,sequence_test.go)The new flags are:
Autotyping is handled externally, which avoids bringing in more code dependencies but introduces external dependencies (for the feature; not necessary if the feature is not used). By default, the window ID program is xdotool, and the autotype program is quasiauto. The former is a common tool and will be available in (probably) any Linux distribution package manager; the latter can be installed either by downloading a pre-compiled executable, or compiling it with Go.
When triggered by the client, the server launches the
customAutotypeWindowIDprogram (default:xdotool) to identify the currently active window. It then scans the database for a matching entry, usingAutoType.Associationor theTitleif no association is set. If it finds a matching entry, it launchescustomAutotypeTyper(default:quasiauto) and writes the key sequence and the requested fields to the process' STDIN.To get access to the key sequences, tobischo/gokeepasslib#68 needed to be fixed. @tobischo pushed the fixes, and this patch consequently updates the version of gokeepasslib.
prompt.gohas a controversial refactoring. Much of the code to generate the Exec() command (~44 LOC) was duplicated almost identically across 5 functions. I added two newPrompt...()functions, which would have duplicated this code even more, so I factored that code out into a helper functiongetCommand(). This changed code that would not necessarily change just for this patch.Limitations
Only Linux is currently supported. This is due to the dependency on
xdotool, which is necessitated by a bug inrobotgothat prevents using that library to get window titles. While it is possible that external tools for Darwin and Windows exist that perform the same function asxdotool, I have access to neither systems and so can't test it. The current code does not prevent such a solution, and those tools could be configured with--customAutotypeWindowID. If or when therobotgobug is fixed, I can add window title ID toquasiauto, and it should be a cross-platform solution and reduce the external dependencies.Testing
The most basic test is to create a dummy database with an entry containing an autotype window match of
Window*. Runkpmenuusing/usr/bin/printfand/usr/bin/xselto match the entry and dump the output. For example, assuming you've created atestdata.kdbxwith the entry:and in a second terminal:
Then running
xsel -bin the second terminal should print out the username and password (and OTP, if configured) of the entry.Note the funny printf is because the code splits the custom command arguments on spaces, so no single argument can contain spaces. \040 is the ASCII control sequence for space.
A more full test uses
zenity(the GUI dialog command-line runner) and hasquasiautoin the path:Shell 1:
Shell 2:
Shell 3 (be prepared to switch back to the
zenitywindow):and watch with delight and amazement as the dialog is filled in. If you add OTP to the entry, a
zenitydialog that demonstrates TOTP is:Of course, the design intends the
--autotypecall to be bound to a window manager hot-key.Future
The code works, and is an minimum-viable solution given the limitations imposed by dependency bugs. It's useful as is, so I'm submitting a PR.
Despite my design desires, it is turning out to be more challenging to implement a user-controlled quasitype, so the first version implements only autotype. I have no doubt I can resolve the issues, and it should be easy to do a mouse-event driven process; these -- like the sequence bug work-around -- can evolve by changing
quasiautoand will not require changes tokpmenu.sequence.gowill probably change, s.t. instead of hard-coding the KeePass values it'll be parsed out of a CVS -- switches will become loops. It'll shorten the code significantly at the cost of speed, but it's not in a critical path section so it should be fine.