* [JGIT RFC PATCH] Add a stdio prompt for SSH connection information.
@ 2008-06-22 21:06 Robin Rosenberg
2008-06-22 23:13 ` Shawn O. Pearce
0 siblings, 1 reply; 4+ messages in thread
From: Robin Rosenberg @ 2008-06-22 21:06 UTC (permalink / raw)
To: Shawn O. Pearce; +Cc: Marek Zawirski, git
With Java6 there is support for echo-less input of information
like passwords from the console.
Windows users must set the system headless promperty java.awt.headless
to true (-Djava.awt.headless=true) manually. Only unix system headless
operation is detected automatically via the DISPLAY environment variable.
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
Starting a command line utility like jgit and getting a graphical prompt is almost
an insult. The problem here is that Java 5, which we support, does not have a
portable way of disabling echoing of characters. Java 6 (and anythung newr)
does. There are several solutions involving non-portable tricks. Should we
support an insecure practice of echoing passwords, or as I do here, only support
it if one is using Java 6. A downside of supporting it at all is that one needs a
JavaSE 6 compiler to build the thing.
btw, does anyone know if console() yields null when runnings as a Windows
service? I tentatively assume that it does without explicily setting the headless
property.
I'm also a little unsure about how to invoke the promptKeyboardInteractive method.
.../jgit/transport/DefaultSshSessionFactory.java | 86 +++++++++++++++++++-
1 files changed, 84 insertions(+), 2 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/DefaultSshSessionFactory.java b/org.spearce.jgit/src/org/spearce/jgit/transport/DefaultSshSessionFactory.java
index 8a59904..c895988 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/DefaultSshSessionFactory.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/DefaultSshSessionFactory.java
@@ -39,6 +39,7 @@
package org.spearce.jgit.transport;
import java.awt.Container;
+import java.awt.GraphicsEnvironment;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
@@ -90,8 +91,18 @@ class DefaultSshSessionFactory extends SshSessionFactory {
final Session session = getUserJSch().getSession(user, host, port);
if (pass != null)
session.setPassword(pass);
- else
- session.setUserInfo(new AWT_UserInfo());
+ UserInfo userInfo = null;
+ try {
+ System.class.getMethod("console");
+ if (GraphicsEnvironment.isHeadless() || System.console() == null)
+ userInfo = new StdioUserInfo();
+ } catch (NoSuchMethodException e) {
+ throw new IllegalStateException(
+ "You will need JavaSE 6 for stdio based password prompts");
+ }
+ if (userInfo == null)
+ userInfo = new AWT_UserInfo();
+ session.setUserInfo(userInfo);
return session;
}
@@ -249,4 +260,75 @@ class DefaultSshSessionFactory extends SshSessionFactory {
return null; // cancel
}
}
+
+ static class StdioUserInfo implements UserInfo, UIKeyboardInteractive {
+
+ String password;
+
+ String passphrase;
+
+ public String getPassphrase() {
+ return passphrase;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public boolean promptPassphrase(String msg) {
+ passphrase = null;
+ char[] readPassword = System.console().readPassword("Passphrase: ");
+ if (readPassword == null)
+ return false;
+ passphrase = new String(readPassword);
+ return true;
+ }
+
+ public boolean promptPassword(String msg) {
+ password = null;
+ char[] readPassword = System.console().readPassword("Password: ");
+ if (readPassword == null)
+ return false;
+ password = new String(readPassword);
+ return true;
+ }
+
+ public boolean promptYesNo(String msg) {
+ String readLine = System.console().readLine("%s [Y/n]: ", msg);
+ if (readLine == null)
+ return false;
+ if (readLine.indexOf("yY") > 0)
+ return true;
+ return false;
+ }
+
+ public void showMessage(String msg) {
+ System.console().format("%s\n", msg);
+ }
+
+ public String[] promptKeyboardInteractive(final String destination,
+ final String name, final String instruction,
+ final String[] prompt, final boolean[] echo) {
+ System.console().printf("%s\n", instruction);
+ System.console().printf("Information for %s@%s required.\n", name,
+ destination);
+ String[] ret = new String[prompt.length];
+ for (int i = 0; i < ret.length; ++i) {
+ String s;
+ if (echo[i])
+ s = System.console().readLine("%s :", prompt[i]);
+ else {
+ char[] cha = System.console().readPassword("%s :",
+ prompt[i]);
+ if (cha == null)
+ s = null;
+ else
+ s = new String(cha);
+ }
+ ret[i] = s;
+ }
+ return ret;
+ }
+
+ }
}
--
1.5.5.1.178.g1f811
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [JGIT RFC PATCH] Add a stdio prompt for SSH connection information.
2008-06-22 21:06 [JGIT RFC PATCH] Add a stdio prompt for SSH connection information Robin Rosenberg
@ 2008-06-22 23:13 ` Shawn O. Pearce
2008-06-23 6:23 ` Robin Rosenberg
0 siblings, 1 reply; 4+ messages in thread
From: Shawn O. Pearce @ 2008-06-22 23:13 UTC (permalink / raw)
To: Robin Rosenberg; +Cc: Marek Zawirski, git
Robin Rosenberg <robin.rosenberg.lists@dewire.com> wrote:
> Starting a command line utility like jgit and getting a graphical prompt is almost
> an insult. The problem here is that Java 5, which we support, does not have a
> portable way of disabling echoing of characters. Java 6 (and anythung newr)
> does. There are several solutions involving non-portable tricks. Should we
> support an insecure practice of echoing passwords, or as I do here, only support
> it if one is using Java 6. A downside of supporting it at all is that one needs a
> JavaSE 6 compiler to build the thing.
We really shouldn't support insecure entry of the password. But I'm
also not ready to give up on Java 5 support either. I wonder if
we shouldn't hide the console reading/writing into a class in our
util package and use reflection to access it, like we do for the
executable flag of java.io.File.
> btw, does anyone know if console() yields null when runnings as a Windows
> service? I tentatively assume that it does without explicily setting the headless
> property.
I think that services on Windows have no console, and also can't
talk to the desktop UI, so its both headless and without a console.
> I'm also a little unsure about how to invoke the promptKeyboardInteractive method.
I think you implemented this method correctly. Its a confusing API,
but it does seem to make sense.
--
Shawn.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [JGIT RFC PATCH] Add a stdio prompt for SSH connection information.
2008-06-22 23:13 ` Shawn O. Pearce
@ 2008-06-23 6:23 ` Robin Rosenberg
2008-06-23 6:34 ` Shawn O. Pearce
0 siblings, 1 reply; 4+ messages in thread
From: Robin Rosenberg @ 2008-06-23 6:23 UTC (permalink / raw)
To: Shawn O. Pearce; +Cc: Marek Zawirski, git
måndagen den 23 juni 2008 01.13.55 skrev Shawn O. Pearce:
> I think that services on Windows have no console, and also can't
> talk to the desktop UI, so its both headless and without a console.
On Windows a service in Java throws up dialogs in void. Your programs will just hang. You have to tell awt that you are headless or your services may just hang. There is an option on services that makes it show windows on the console, but it's not the default and seems to have no effect on the headless property. As for the console() returning null or not I haven't tried it yet.
> > I'm also a little unsure about how to invoke the promptKeyboardInteractive method.
>
> I think you implemented this method correctly. Its a confusing API,
> but it does seem to make sense.
No idea on how to make JSch inoke it?
-- robin
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [JGIT RFC PATCH] Add a stdio prompt for SSH connection information.
2008-06-23 6:23 ` Robin Rosenberg
@ 2008-06-23 6:34 ` Shawn O. Pearce
0 siblings, 0 replies; 4+ messages in thread
From: Shawn O. Pearce @ 2008-06-23 6:34 UTC (permalink / raw)
To: Robin Rosenberg; +Cc: Marek Zawirski, git
Robin Rosenberg <robin.rosenberg.lists@dewire.com> wrote:
>
> > > I'm also a little unsure about how to invoke the promptKeyboardInteractive method.
> >
> > I think you implemented this method correctly. Its a confusing API,
> > but it does seem to make sense.
>
> No idea on how to make JSch inoke it?
Might require a server that has a token cards for authentication.
Server can ask for a user password and also give you a code to
enter into the card, which gives you the response to enter back in.
I have never worked with such a configuration so I have never seen
that sort of multi-input prompt come up in any SSH client before.
--
Shawn.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-06-23 6:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-22 21:06 [JGIT RFC PATCH] Add a stdio prompt for SSH connection information Robin Rosenberg
2008-06-22 23:13 ` Shawn O. Pearce
2008-06-23 6:23 ` Robin Rosenberg
2008-06-23 6:34 ` Shawn O. Pearce
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.