aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKenny Root <kenny@the-b.org>2008-10-25 06:48:35 +0000
committerKenny Root <kenny@the-b.org>2008-10-25 06:48:35 +0000
commitcb3b1910bf0fd9aa369573610069e540a1d89b68 (patch)
treefe523ad51cc6e5ad4e4da5176ec2f556abc50b58 /src
parent821c2d61959e5212f86f74730d6fe4c07f631779 (diff)
downloadconnectbot-cb3b1910bf0fd9aa369573610069e540a1d89b68.tar.gz
connectbot-cb3b1910bf0fd9aa369573610069e540a1d89b68.tar.bz2
connectbot-cb3b1910bf0fd9aa369573610069e540a1d89b68.zip
First pass at keyboard-interactive
Diffstat (limited to 'src')
-rw-r--r--src/org/connectbot/service/TerminalBridge.java54
1 files changed, 45 insertions, 9 deletions
diff --git a/src/org/connectbot/service/TerminalBridge.java b/src/org/connectbot/service/TerminalBridge.java
index 2b846aa..ab24528 100644
--- a/src/org/connectbot/service/TerminalBridge.java
+++ b/src/org/connectbot/service/TerminalBridge.java
@@ -21,6 +21,7 @@ package org.connectbot.service;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.concurrent.Semaphore;
import org.connectbot.TerminalView;
@@ -40,6 +41,7 @@ import android.view.View;
import android.view.View.OnKeyListener;
import com.trilead.ssh2.Connection;
+import com.trilead.ssh2.InteractiveCallback;
import com.trilead.ssh2.KnownHosts;
import com.trilead.ssh2.ServerHostKeyVerifier;
import com.trilead.ssh2.Session;
@@ -58,7 +60,7 @@ import de.mud.terminal.vt320;
* This class also provides SSH hostkey verification prompting, and password
* prompting.
*/
-public class TerminalBridge implements VDUDisplay, OnKeyListener {
+public class TerminalBridge implements VDUDisplay, OnKeyListener, InteractiveCallback {
public final static String TAG = TerminalBridge.class.toString();
@@ -68,7 +70,8 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener {
public final static String ENCODING = "ASCII";
public static final String AUTH_PUBLICKEY = "publickey",
- AUTH_PASSWORD = "password";
+ AUTH_PASSWORD = "password",
+ AUTH_KEYBOARDINTERACTIVE = "keyboard-interactive";
private int darken(int color) {
return Color.argb(0xFF,
@@ -110,6 +113,10 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener {
private boolean ctrlPressed = false;
+ private String currentMethod = null;
+ private Semaphore waitChallengeResponse;
+ private String currentChallengeResponse = null;
+
public class HostKeyVerifier implements ServerHostKeyVerifier {
@@ -200,9 +207,17 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener {
connection.connect(new HostKeyVerifier());
outputLine("Trying to authenticate");
if(connection.isAuthMethodAvailable(username, AUTH_PASSWORD)) {
+ currentMethod = AUTH_PASSWORD;
// show auth prompt in window
requestPasswordVisible(true, "Password");
//promptPassword();
+ } else if (connection.isAuthMethodAvailable(username, AUTH_KEYBOARDINTERACTIVE)) {
+ currentMethod = AUTH_KEYBOARDINTERACTIVE;
+ if (connection.authenticateWithKeyboardInteractive(username, TerminalBridge.this)) {
+ TerminalBridge.this.buffer.deleteArea(0, 0, TerminalBridge.this.buffer.getColumns(), TerminalBridge.this.buffer.getRows());
+ requestPasswordVisible(false, null);
+ finishConnection();
+ }
} else {
outputLine("Looks like your host doesn't support 'password' authentication.");
outputLine("Other auth methods, such as interactive and publickey, are still being written.");
@@ -247,13 +262,19 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener {
*/
public void incomingPassword(String password) {
try {
- // try authenticating with given password
- Log.d(TAG, "Attempting to try password authentication");
- if(this.connection.authenticateWithPassword(this.username, password)) {
- this.buffer.deleteArea(0, 0, this.buffer.getColumns(), this.buffer.getRows());
- requestPasswordVisible(false, null);
- finishConnection();
- return;
+ if (currentMethod == AUTH_PASSWORD) {
+ // try authenticating with given password
+ Log.d(TAG, "Attempting to try password authentication");
+ if (this.connection.authenticateWithPassword(this.username, password)) {
+ this.buffer.deleteArea(0, 0, this.buffer.getColumns(), this.buffer.getRows());
+ requestPasswordVisible(false, null);
+ finishConnection();
+ return;
+ }
+ } else if (currentMethod == AUTH_KEYBOARDINTERACTIVE) {
+ Log.d(TAG, "Attempting to try keyboard-interactive authentication");
+ currentChallengeResponse = password;
+ waitChallengeResponse.release();
}
} catch (IOException e) {
Log.e(TAG, "Problem while trying to authenticate with password", e);
@@ -603,6 +624,21 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener {
public void updateScrollBar() {
}
+ public String[] replyToChallenge(String name, String instruction,
+ int numPrompts, String[] prompt, boolean[] echo) throws Exception {
+ String[] responses = new String[numPrompts];
+
+ waitChallengeResponse = new Semaphore(0);
+
+ for (int i = 0; i < numPrompts; i++) {
+ requestPasswordVisible(true, prompt[i]);
+ waitChallengeResponse.acquire();
+ responses[i] = currentChallengeResponse;
+ }
+
+ return responses;
+ }
+
}