Permalink
Browse files

Merge branch 'ssh_add_pubkey'

* ssh_add_pubkey:
  Implement public key auth in the ssh synchronizer, this closes issue #163
  Implement the file explorer dialog to select the SSH Public Key file for the SSH/SCP File Synchronizer
  • Loading branch information...
matburt committed Dec 8, 2012
2 parents 85375f6 + d057e00 commit d780997988dff1ee231f8f3d0063b19cce06d4c1
View
@@ -49,6 +49,26 @@
android:inputType="textPassword"
android:password="true"
android:singleLine="true"/>
+ <TextView
+ android:paddingTop="10dp"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/ssh_inform_choose_pub_file"
+ android:textSize="20dp"/>
+ <Button
+ android:layout_marginTop="20dp"
+ android:id="@+id/wizard_ssh_choose_pub_file"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/ssh_choose_file_button"
+ android:textSize="20dp"/>
+ <TextView
+ android:id="@+id/wizard_ssh_pub_file_actual"
+ android:paddingTop="10dp"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text=""
+ android:textSize="20dp"/>
<TextView
android:paddingTop="10dp"
android:layout_width="wrap_content"
@@ -103,4 +123,4 @@
/>
<include layout="@layout/wizard_navbar_last"/>
</LinearLayout>
-</ScrollView>
+</ScrollView>
View
@@ -106,6 +106,8 @@
<string name="log_in_to_ubuntuone">Log in to Ubuntu One</string>
<string name="log_in_to_webdav">Log in to your WebDAV server</string>
<string name="log_in_to_ssh">Log in to your SSH server</string>
+ <string name="ssh_inform_choose_pub_file">OR select a file containing your *private* key (requires a file explorer program to be installed)</string>
+ <string name="ssh_choose_file_button">Select your *private* key file</string>
<string name="null_sync_description">This is a capture only synchronizer. It will not attempt to synchronize to any source.</string>
<string name="dropbox_login_info">This will redirect you to a login form. After logging in it will return you to this screen to continue.</string>
<string name="url">URL</string>
@@ -194,4 +196,4 @@
<string name="title_index_file_path">Full local path to index.org</string>
<string name="summary_web_url">Full URL path to your index.org file</string>
-</resources>
+</resources>
@@ -5,6 +5,7 @@
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
+import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Resources;
@@ -124,6 +125,8 @@ public void handleMessage(Message msg)
EditText sshPath;
EditText sshHost;
EditText sshPort;
+ TextView sshPubFileActual;
+ Button sshPubFileSelect;
Button sshLoginButton;
//page 3 variables
ListView folderList;
@@ -247,6 +250,16 @@ void createNullConfig() {
wizard.setDoneButtonOnClickListener(new FinishWizardButtonListener());
wizard.enablePage(1);
}
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode == 1) {
+ if(resultCode==RESULT_OK){
+ String filePath = data.getData().getPath();
+ sshPubFileActual.setText(filePath);
+ }
+ }
+ }
void createSSHConfig() {
wizard.removePagesAfter(1);
@@ -256,6 +269,18 @@ void createSSHConfig() {
sshPath = (EditText) wizard.findViewById(R.id.wizard_ssh_path);
sshHost = (EditText) wizard.findViewById(R.id.wizard_ssh_host);
sshPort = (EditText) wizard.findViewById(R.id.wizard_ssh_port);
+ sshPubFileActual = (TextView) wizard.findViewById(R.id.wizard_ssh_pub_file_actual);
+ sshPubFileSelect = (Button)wizard.findViewById(R.id.wizard_ssh_choose_pub_file);
+ sshPubFileSelect.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ try {
+ Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
+ intent.setType("file/*");
+ startActivityForResult(intent,1);
+ } catch (Exception e) { }
+ }
+ });
webdavLoginButton = (Button) wizard.findViewById(R.id.wizard_ssh_login_button);
doneButton = (Button) findViewById(R.id.wizard_done_button);
webdavLoginButton.setOnClickListener(new OnClickListener() {
@@ -374,6 +399,7 @@ void loginSSH() {
final String passActual = sshPass.getText().toString();
final String userActual = sshUser.getText().toString();
final String hostActual = sshHost.getText().toString();
+ final String pubFileActual = sshPubFileActual.getText().toString();
String portNumGiven = sshPort.getText().toString();
int portNum;
if (portNumGiven.trim().equals("")) {
@@ -394,7 +420,8 @@ void loginSSH() {
Thread loginThread = new Thread() {
public void run() {
SSHSynchronizer sds = new SSHSynchronizer(ctxt);
- String extra = sds.testConnection(pathActual, userActual, passActual, hostActual, portActual);
+ String extra = sds.testConnection(pathActual, userActual, passActual,
+ hostActual, portActual, pubFileActual);
if (extra != null) {
showToastRemote("Login failed: " + extra);
return;
@@ -562,6 +589,7 @@ else if ( syncSource.equals("scp") ) {
editor.putString("scpUser", sshUser.getText().toString());
editor.putString("scpPass", sshPass.getText().toString());
editor.putString("scpHost", sshHost.getText().toString());
+ editor.putString("scpPubFile", sshPubFileActual.getText().toString());
if (sshPort.getText().toString().trim().equals("")) {
editor.putString("scpPort", "22");
}
@@ -26,6 +26,7 @@
private String path;
private String pass;
private int port;
+ private String pubFile;
private Session session;
@@ -37,6 +38,7 @@ public SSHSynchronizer(Context context) {
path = appSettings.getString("scpPath", "");
user = appSettings.getString("scpUser", "");
host = appSettings.getString("scpHost", "");
+ pubFile = appSettings.getString("scpPubFile", "");
String tmpPort = appSettings.getString("scpPort", "");
if (tmpPort.equals("")) {
port = 22;
@@ -53,12 +55,13 @@ public SSHSynchronizer(Context context) {
}
}
- public String testConnection(String path, String user, String pass, String host, int port) {
+ public String testConnection(String path, String user, String pass, String host, int port, String pubFile) {
this.path = path;
this.user = user;
this.pass = pass;
this.host = host;
this.port = port;
+ this.pubFile = pubFile;
if (this.path.indexOf("index.org") < 0) {
Log.i("MobileOrg", "Invalid ssh path, must point to index.org");
@@ -68,7 +71,7 @@ public String testConnection(String path, String user, String pass, String host,
if (this.path.equals("") ||
this.user.equals("") ||
this.host.equals("") ||
- this.pass.equals("")) {
+ (this.pass.equals("") && this.pubFile.equals(""))) {
Log.i("MobileOrg", "Test Connection Failed for not being configured");
return "Missing configuration values";
}
@@ -112,7 +115,8 @@ public boolean isConfigured() {
if (this.appSettings.getString("scpPath", "").equals("") ||
this.appSettings.getString("scpUser", "").equals("") ||
this.appSettings.getString("scpHost", "").equals("") ||
- this.appSettings.getString("scpPass", "").equals(""))
+ (this.appSettings.getString("scpPass", "").equals("") &&
+ this.appSettings.getString("scpPubFile", "").equals("")))
return false;
return true;
}
@@ -121,7 +125,12 @@ public void connect() throws JSchException {
JSch jsch = new JSch();
try {
session = jsch.getSession(user, host, port);
- session.setPassword(pass);
+ if (!pubFile.equals("")) {
+ jsch.addIdentity(pubFile);
+ }
+ else {
+ session.setPassword(pass);
+ }
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");

0 comments on commit d780997

Please sign in to comment.