Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: theseal/ssh-askpass
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: alexreg/ssh-askpass
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on May 21, 2017

  1. Now handles user input prompts (e.g. username/password) as well as bi…

    …nary prompts.
    
    Resolves issue #14.
    Rewrote script in JXA (JavaScript for automation).
    alexreg committed May 21, 2017
    Copy the full SHA
    e61d24a View commit details
Showing with 67 additions and 26 deletions.
  1. +67 −26 ssh-askpass
93 changes: 67 additions & 26 deletions ssh-askpass
Original file line number Diff line number Diff line change
@@ -1,27 +1,68 @@
#!/usr/bin/env osascript
# Copyright (c) 2014-, Johan Carlquist <johan@rymdvarel.se>
# Copyright (c) 2011-, Simon Lundström <simmel@soy.se>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
#!/usr/bin/env osascript -l JavaScript
/*
Copyright (c) 2017-, Alexander Regueiro <alex@noldorin.com>
Copyright (c) 2014-, Johan Carlquist <johan@rymdvarel.se>
Copyright (c) 2011-, Simon Lundström <simmel@soy.se>

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

on run argv
set args to argv as text
set frontmost_application to name of (info for (path to frontmost application))
tell application frontmost_application
display dialog args with icon caution default button "Cancel"
if result = {button returned:"OK"} then
return
end if
return false
end tell
end run
ObjC.import('stdlib');
ObjC.import('stdio');
ObjC.import('unistd');
ObjC.import('Foundation');

function getParentApp() {
var app;
try {
app = Application($.getppid());
} catch(e) {
app = null;
}
return app;
}

function run(argv) {
var prompt = argv[0] || "Authentication password:";

var query = prompt.split('\n')[0].trimRight();
var is_query_binary = query.endsWith('?');
var is_query_sensitive = /password|passphrase|pin/i.test(query);

var app = getParentApp() || Application("SystemUIServer");
app.includeStandardAdditions = true;
try {
var dialogOpts = {
withTitle: "ssh-askpass",
subtitle: app.name(),
withIcon: "caution",
buttons: ["Cancel", "OK"],
defaultButton: "Cancel",
givingUpAfter: 30,
};
if (!is_query_binary) {
dialogOpts.defaultAnswer = "";
dialogOpts.hiddenAnswer = is_query_sensitive;
}
var result = app.displayDialog(prompt, dialogOpts);
if (result.gaveUp) {
$.exit(1);
}

switch (result.buttonReturned) {
case "OK":
var entry = result.textReturned;
$.puts(entry);
$.exit(0);
case "Cancel":
default:
$.exit(1);
}
} catch (e) {
$.exit(1);
}
}