mirror of http://galexander.org/git/simplesshd.git
to delete the authorized_keys file and revert to single-use passwordssigsegv_dump
parent
4d888fdd81
commit
0523529968
@ -1,133 +0,0 @@
|
|||||||
package org.galexander.sshd;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.text.InputType;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Message;
|
|
||||||
import android.os.Messenger;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
public class AuthKeys extends Activity {
|
|
||||||
private EditText authtext;
|
|
||||||
private String authtext_orig;
|
|
||||||
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setContentView(R.layout.authkeys);
|
|
||||||
authtext = (EditText)findViewById(R.id.authtext);
|
|
||||||
authtext_orig = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
AuthKeysLoad.go(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPause() {
|
|
||||||
save_authtext();
|
|
||||||
super.onPause();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void fetch_clicked(View v) {
|
|
||||||
AlertDialog.Builder ab = new AlertDialog.Builder(this);
|
|
||||||
ab.setTitle("Fetch authorized_keys");
|
|
||||||
final EditText url = new EditText(this);
|
|
||||||
url.setInputType(InputType.TYPE_CLASS_TEXT |
|
|
||||||
InputType.TYPE_TEXT_VARIATION_URI);
|
|
||||||
ab.setView(url);
|
|
||||||
ab.setPositiveButton("OK",
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface d, int which) {
|
|
||||||
start_fetch(url.getText().toString());
|
|
||||||
} });
|
|
||||||
ab.setNegativeButton("Cancel",
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface d, int which) {
|
|
||||||
d.cancel();
|
|
||||||
} });
|
|
||||||
ab.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void cancel_clicked(View v) {
|
|
||||||
authtext_orig = null;
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save_clicked(View v) {
|
|
||||||
save_authtext();
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void save_authtext() {
|
|
||||||
String s = get_authtext();
|
|
||||||
if ((s != null) && ((authtext_orig != null) ||
|
|
||||||
!s.equals(authtext_orig))) {
|
|
||||||
Intent i = new Intent(this, AuthKeysSave.class);
|
|
||||||
i.putExtra("s", s);
|
|
||||||
startService(i);
|
|
||||||
}
|
|
||||||
/* so that we won't save it again */
|
|
||||||
authtext_orig = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String get_authtext() {
|
|
||||||
if (authtext != null) {
|
|
||||||
return authtext.getText().toString();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* called from AuthKeysLoad, which puts it on the UI thread */
|
|
||||||
public void set_authtext(String s) {
|
|
||||||
if (authtext != null) {
|
|
||||||
authtext.setText(s);
|
|
||||||
authtext_orig = s;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* called from AuthKeysFetch, from its own thread */
|
|
||||||
public void append_authtext(String s) {
|
|
||||||
if (authtext != null) {
|
|
||||||
String t = get_authtext();
|
|
||||||
if (t == null) {
|
|
||||||
t = "";
|
|
||||||
}
|
|
||||||
if (!t.endsWith("\n")) {
|
|
||||||
t += "\n";
|
|
||||||
}
|
|
||||||
t += s;
|
|
||||||
authtext.setText(t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void start_fetch(String url) {
|
|
||||||
Intent i = new Intent(this, AuthKeysFetch.class);
|
|
||||||
final Context ctx = this;
|
|
||||||
i.putExtra("url", url);
|
|
||||||
i.putExtra("m", new Messenger(new Handler() {
|
|
||||||
public void handleMessage(Message msg) {
|
|
||||||
Object o = msg.obj;
|
|
||||||
if (o == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String s = (String)o;
|
|
||||||
int n = msg.arg1;
|
|
||||||
if (n == 0) {
|
|
||||||
/* s is data read from the url */
|
|
||||||
append_authtext(s);
|
|
||||||
} else {
|
|
||||||
/* s must be an error message */
|
|
||||||
Toast.makeText(ctx, s,
|
|
||||||
Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
} } ));
|
|
||||||
startService(i);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
package org.galexander.sshd;
|
|
||||||
|
|
||||||
import android.app.IntentService;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Message;
|
|
||||||
import android.os.Messenger;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
|
|
||||||
|
|
||||||
public class AuthKeysFetch extends IntentService {
|
|
||||||
public AuthKeysFetch() {
|
|
||||||
super("SimpleSSHDAuthKeysFetch");
|
|
||||||
}
|
|
||||||
protected void onHandleIntent(Intent i) {
|
|
||||||
Messenger m = (Messenger)i.getParcelableExtra("m");
|
|
||||||
Message msg = Message.obtain();
|
|
||||||
String url = i.getStringExtra("url");
|
|
||||||
|
|
||||||
String result = "";
|
|
||||||
byte[] b = new byte[1024];
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (url == null) {
|
|
||||||
throw new Exception("no url");
|
|
||||||
}
|
|
||||||
URL u = new URL(url);
|
|
||||||
HttpURLConnection conn = (HttpURLConnection)
|
|
||||||
u.openConnection();
|
|
||||||
try {
|
|
||||||
InputStream in = conn.getInputStream();
|
|
||||||
try {
|
|
||||||
while (result.length() < 65536) {
|
|
||||||
int r = in.read(b);
|
|
||||||
if (r <= 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
result += new String(b, 0, r);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
in.close();
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
conn.disconnect();
|
|
||||||
}
|
|
||||||
if (result.equals("")) {
|
|
||||||
throw new Exception("empty file");
|
|
||||||
}
|
|
||||||
msg.arg1 = 0;
|
|
||||||
msg.obj = result;
|
|
||||||
} catch (Exception e) {
|
|
||||||
msg.arg1 = 1;
|
|
||||||
msg.obj = "HTTP fetch: " + e.getMessage();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
m.send(msg);
|
|
||||||
} catch (Exception e) { }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,58 +0,0 @@
|
|||||||
package org.galexander.sshd;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.os.AsyncTask;
|
|
||||||
import android.widget.Toast;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
|
|
||||||
|
|
||||||
public class AuthKeysLoad extends AsyncTask<Void,Void,Void> {
|
|
||||||
private AuthKeys act = null;
|
|
||||||
private String result = null;
|
|
||||||
private String error = null;
|
|
||||||
|
|
||||||
public static void go(AuthKeys act_) {
|
|
||||||
(new AuthKeysLoad(act_)).execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
AuthKeysLoad(AuthKeys act_) {
|
|
||||||
super();
|
|
||||||
act = act_;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Void doInBackground(Void... v) {
|
|
||||||
try {
|
|
||||||
File f = new File(Prefs.get_path(), "authorized_keys");
|
|
||||||
FileInputStream fis = new FileInputStream(f);
|
|
||||||
|
|
||||||
byte b[] = new byte[1024];
|
|
||||||
|
|
||||||
result = "";
|
|
||||||
try {
|
|
||||||
while (true) {
|
|
||||||
int r = fis.read(b);
|
|
||||||
if (r <= 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
result += new String(b, 0, r);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
fis.close();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
error = e.getMessage();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void onPostExecute(Void v) {
|
|
||||||
if (result != null) {
|
|
||||||
act.set_authtext(result);
|
|
||||||
} else if (error != null) {
|
|
||||||
Toast.makeText(act,
|
|
||||||
"failed to load authorized_keys: " + error,
|
|
||||||
Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
package org.galexander.sshd;
|
|
||||||
|
|
||||||
import android.app.IntentService;
|
|
||||||
import android.content.Intent;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
|
|
||||||
public class AuthKeysSave extends IntentService {
|
|
||||||
public AuthKeysSave() {
|
|
||||||
super("SimpleSSHDAuthKeysSave");
|
|
||||||
}
|
|
||||||
protected void onHandleIntent(Intent i) {
|
|
||||||
String s = i.getStringExtra("s");
|
|
||||||
if (s == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
File p = new File(Prefs.get_path());
|
|
||||||
if (!p.exists()) {
|
|
||||||
p.mkdirs();
|
|
||||||
}
|
|
||||||
File f = new File(p, "authorized_keys");
|
|
||||||
FileOutputStream fos = new FileOutputStream(f);
|
|
||||||
int ofs = 0;
|
|
||||||
|
|
||||||
try {
|
|
||||||
fos.write(s.getBytes());
|
|
||||||
} finally {
|
|
||||||
fos.close();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
SimpleSSHD.toast(
|
|
||||||
"authorized_keys save failed: "+e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in new issue