Permalink
Browse files

Implement public key auth in the ssh synchronizer, this closes issue #…

  • Loading branch information...
1 parent b84e8e6 commit d057e00c94835ab7959a08f8a84ff2d0cd97419f @matburt committed Dec 8, 2012
View
@@ -106,8 +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 public key (requires a file explorer program to be installed)</string>
- <string name="ssh_choose_file_button">Select your public key file</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>
@@ -399,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("")) {
@@ -419,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;
@@ -587,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 d057e00

Please sign in to comment.