aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/theb/ssh/ShellView.java
blob: 15d783bfcb2c713a25b80c909ac7dd62069decba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package org.theb.ssh;

import java.io.IOException;

import com.trilead.ssh2.Connection;
import com.trilead.ssh2.Session;

import android.content.Context;
import android.graphics.Canvas;
import android.util.Log;
import android.widget.EditText;
import android.widget.TextView;

public class ShellView extends EditText {

	private Connection mConn;
	private Session mSess;
	
	private String mHostname;
	private String mUsername;
	private String mPassword;

	public ShellView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		
		mPassword = "OEfmP07-";
	}
	
	@Override
	public void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		
		append("Connecting... ");
		mConn = new Connection(mHostname);
		
        try {
			mConn.connect(new InteractiveHostKeyVerifier());
			append("OK\n");
		} catch (IOException e) {
			append("Failed.\n");
			Log.e("SSH", e.getMessage());
			append("\nWhoops: " + e.getCause().getMessage() + "\n");
		}
			
		boolean enableKeyboardInteractive = true;
		boolean enableDSA = true;
		boolean enableRSA = true;
		
		try {
			while (true) {
				/*
				if ((enableDSA || enableRSA ) &&
						mConn.isAuthMethodAvailable(username, "publickey");
						*/
				
				if (mConn.isAuthMethodAvailable(mUsername, "password")) {
					boolean res = mConn.authenticateWithPassword(mUsername, mPassword);
					if (res == true)
						break;
					
					append("Login failed.\n");
					continue;
				}
				
				throw new IOException("No supported authentication methods available.");
			}
			
			mSess = mConn.openSession();
			append("Logged in as " + mUsername + ".\n");
		} catch (IOException e) {
			Log.e("SSH", e.getMessage());
		}
		append("Exiting\n");
	}

}