mirror of
https://github.com/moparisthebest/SSLDroid
synced 2025-02-16 23:10:12 -05:00
Indentation fixes
Signed-off-by: Balint Kovacs <blint@blint.hu>
This commit is contained in:
parent
69c521c91e
commit
aad79a8e5a
@ -5,12 +5,12 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
public class BootStartupReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
|
||||
Intent i = new Intent();
|
||||
i.setAction("hu.blint.ssldroid.SSLDroid");
|
||||
context.startService(i);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
|
||||
Intent i = new Intent();
|
||||
i.setAction("hu.blint.ssldroid.SSLDroid");
|
||||
context.startService(i);
|
||||
}
|
||||
}
|
||||
}
|
@ -7,25 +7,25 @@ import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.util.Log;
|
||||
|
||||
public class NetworkChangeReceiver extends BroadcastReceiver{
|
||||
|
||||
public class NetworkChangeReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService( Context.CONNECTIVITY_SERVICE );
|
||||
NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
|
||||
if ( activeNetInfo == null ) {
|
||||
Intent i = new Intent();
|
||||
i.setAction("hu.blint.ssldroid.SSLDroid");
|
||||
context.stopService(i);
|
||||
return;
|
||||
}
|
||||
Log.d("SSLDroid", activeNetInfo.toString());
|
||||
if (activeNetInfo.isAvailable()) {
|
||||
Intent i = new Intent();
|
||||
i.setAction("hu.blint.ssldroid.SSLDroid");
|
||||
context.stopService(i);
|
||||
context.startService(i);
|
||||
}
|
||||
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService( Context.CONNECTIVITY_SERVICE );
|
||||
NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
|
||||
if ( activeNetInfo == null ) {
|
||||
Intent i = new Intent();
|
||||
i.setAction("hu.blint.ssldroid.SSLDroid");
|
||||
context.stopService(i);
|
||||
return;
|
||||
}
|
||||
Log.d("SSLDroid", activeNetInfo.toString());
|
||||
if (activeNetInfo.isAvailable()) {
|
||||
Intent i = new Intent();
|
||||
i.setAction("hu.blint.ssldroid.SSLDroid");
|
||||
context.stopService(i);
|
||||
context.startService(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,107 +10,107 @@ import hu.blint.ssldroid.db.SSLDroidDbAdapter;
|
||||
|
||||
public class SSLDroid extends Service {
|
||||
|
||||
final String TAG = "SSLDroid";
|
||||
TcpProxy tp[];
|
||||
private SSLDroidDbAdapter dbHelper;
|
||||
final String TAG = "SSLDroid";
|
||||
TcpProxy tp[];
|
||||
private SSLDroidDbAdapter dbHelper;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
|
||||
dbHelper = new SSLDroidDbAdapter(this);
|
||||
dbHelper.open();
|
||||
Cursor cursor = dbHelper.fetchAllTunnels();
|
||||
|
||||
int tunnelcount = cursor.getCount();
|
||||
|
||||
//skip start if the db is empty yet
|
||||
if (tunnelcount == 0)
|
||||
return;
|
||||
|
||||
tp = new TcpProxy[tunnelcount];
|
||||
|
||||
int i;
|
||||
for (i=0; i<tunnelcount; i++){
|
||||
cursor.moveToPosition(i);
|
||||
String tunnelName = cursor.getString(cursor
|
||||
.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_NAME));
|
||||
int listenPort = cursor.getInt(cursor
|
||||
.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_LOCALPORT));
|
||||
int targetPort = cursor.getInt(cursor
|
||||
.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_REMOTEPORT));
|
||||
String targetHost = cursor.getString(cursor
|
||||
.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_REMOTEHOST));
|
||||
String keyFile = cursor.getString(cursor
|
||||
.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_PKCSFILE));
|
||||
String keyPass = cursor.getString(cursor
|
||||
.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_PKCSPASS));
|
||||
try {
|
||||
tp[i] = new TcpProxy(tunnelName, listenPort, targetHost, targetPort, keyFile, keyPass);
|
||||
tp[i].serve();
|
||||
Log.d(TAG, "Tunnel: "+tunnelName+" "+listenPort+" "+targetHost+" "+targetPort+" "+keyFile);
|
||||
} catch (Exception e) {
|
||||
Log.d(TAG, "Error:" + e.toString());
|
||||
new AlertDialog.Builder(SSLDroid.this)
|
||||
@Override
|
||||
public void onCreate() {
|
||||
|
||||
dbHelper = new SSLDroidDbAdapter(this);
|
||||
dbHelper.open();
|
||||
Cursor cursor = dbHelper.fetchAllTunnels();
|
||||
|
||||
int tunnelcount = cursor.getCount();
|
||||
|
||||
//skip start if the db is empty yet
|
||||
if (tunnelcount == 0)
|
||||
return;
|
||||
|
||||
tp = new TcpProxy[tunnelcount];
|
||||
|
||||
int i;
|
||||
for (i=0; i<tunnelcount; i++) {
|
||||
cursor.moveToPosition(i);
|
||||
String tunnelName = cursor.getString(cursor
|
||||
.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_NAME));
|
||||
int listenPort = cursor.getInt(cursor
|
||||
.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_LOCALPORT));
|
||||
int targetPort = cursor.getInt(cursor
|
||||
.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_REMOTEPORT));
|
||||
String targetHost = cursor.getString(cursor
|
||||
.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_REMOTEHOST));
|
||||
String keyFile = cursor.getString(cursor
|
||||
.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_PKCSFILE));
|
||||
String keyPass = cursor.getString(cursor
|
||||
.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_PKCSPASS));
|
||||
try {
|
||||
tp[i] = new TcpProxy(tunnelName, listenPort, targetHost, targetPort, keyFile, keyPass);
|
||||
tp[i].serve();
|
||||
Log.d(TAG, "Tunnel: "+tunnelName+" "+listenPort+" "+targetHost+" "+targetPort+" "+keyFile);
|
||||
} catch (Exception e) {
|
||||
Log.d(TAG, "Error:" + e.toString());
|
||||
new AlertDialog.Builder(SSLDroid.this)
|
||||
.setTitle("SSLDroid encountered a fatal error: "+e.getMessage())
|
||||
.setPositiveButton(android.R.string.ok, null)
|
||||
.create();
|
||||
}
|
||||
}
|
||||
|
||||
cursor.deactivate();
|
||||
cursor.close();
|
||||
dbHelper.close();
|
||||
createNotification(0, true, "SSLDroid is running", "Started and serving "+tunnelcount+" tunnels");
|
||||
Log.d(TAG, "SSLDroid Service Started");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
return START_STICKY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
cursor.deactivate();
|
||||
cursor.close();
|
||||
dbHelper.close();
|
||||
createNotification(0, true, "SSLDroid is running", "Started and serving "+tunnelcount+" tunnels");
|
||||
Log.d(TAG, "SSLDroid Service Started");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
dbHelper.close();
|
||||
try {
|
||||
for (TcpProxy proxy : tp) {
|
||||
proxy.stop();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.d("SSLDroid", "Error stopping service: " + e.toString());
|
||||
}
|
||||
removeNotification(0);
|
||||
Log.d(TAG, "SSLDroid Service Stopped");
|
||||
}
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
public void removeNotification(int id){
|
||||
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
notificationManager.cancel(id);
|
||||
}
|
||||
|
||||
public void createNotification(int id, boolean persistent, String title, String text) {
|
||||
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
Notification notification = new Notification(R.drawable.icon,
|
||||
"SSLDroid startup", System.currentTimeMillis());
|
||||
// if requested, make the notification persistent, e.g. not clearable by the user at all,
|
||||
// automatically hide on displaying the main activity otherwise
|
||||
if (persistent == true)
|
||||
notification.flags |= Notification.FLAG_NO_CLEAR;
|
||||
else
|
||||
notification.flags |= Notification.FLAG_AUTO_CANCEL;
|
||||
|
||||
notification.flags |= Notification.FLAG_ONGOING_EVENT;
|
||||
notification.tickerText = null;
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(this, SSLDroidGui.class);
|
||||
PendingIntent activity = PendingIntent.getActivity(this, 0, intent, 0);
|
||||
notification.setLatestEventInfo(this, title, text, activity);
|
||||
notificationManager.notify(id, notification);
|
||||
}
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
dbHelper.close();
|
||||
try {
|
||||
for (TcpProxy proxy : tp) {
|
||||
proxy.stop();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.d("SSLDroid", "Error stopping service: " + e.toString());
|
||||
}
|
||||
removeNotification(0);
|
||||
Log.d(TAG, "SSLDroid Service Stopped");
|
||||
}
|
||||
|
||||
public void removeNotification(int id) {
|
||||
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
notificationManager.cancel(id);
|
||||
}
|
||||
|
||||
public void createNotification(int id, boolean persistent, String title, String text) {
|
||||
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
Notification notification = new Notification(R.drawable.icon,
|
||||
"SSLDroid startup", System.currentTimeMillis());
|
||||
// if requested, make the notification persistent, e.g. not clearable by the user at all,
|
||||
// automatically hide on displaying the main activity otherwise
|
||||
if (persistent == true)
|
||||
notification.flags |= Notification.FLAG_NO_CLEAR;
|
||||
else
|
||||
notification.flags |= Notification.FLAG_AUTO_CANCEL;
|
||||
|
||||
notification.flags |= Notification.FLAG_ONGOING_EVENT;
|
||||
notification.tickerText = null;
|
||||
|
||||
Intent intent = new Intent(this, SSLDroidGui.class);
|
||||
PendingIntent activity = PendingIntent.getActivity(this, 0, intent, 0);
|
||||
notification.setLatestEventInfo(this, title, text, activity);
|
||||
notificationManager.notify(id, notification);
|
||||
}
|
||||
}
|
||||
|
@ -17,138 +17,138 @@ import android.widget.SimpleCursorAdapter;
|
||||
import hu.blint.ssldroid.db.SSLDroidDbAdapter;
|
||||
|
||||
public class SSLDroidGui extends ListActivity {
|
||||
private SSLDroidDbAdapter dbHelper;
|
||||
private static final int ACTIVITY_CREATE = 0;
|
||||
private static final int ACTIVITY_EDIT = 1;
|
||||
private static final int DELETE_ID = Menu.FIRST + 1;
|
||||
private Cursor cursor;
|
||||
private SSLDroidDbAdapter dbHelper;
|
||||
private static final int ACTIVITY_CREATE = 0;
|
||||
private static final int ACTIVITY_EDIT = 1;
|
||||
private static final int DELETE_ID = Menu.FIRST + 1;
|
||||
private Cursor cursor;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.tunnel_list);
|
||||
this.getListView().setDividerHeight(2);
|
||||
dbHelper = new SSLDroidDbAdapter(this);
|
||||
dbHelper.open();
|
||||
fillData();
|
||||
registerForContextMenu(getListView());
|
||||
}
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.tunnel_list);
|
||||
this.getListView().setDividerHeight(2);
|
||||
dbHelper = new SSLDroidDbAdapter(this);
|
||||
dbHelper.open();
|
||||
fillData();
|
||||
registerForContextMenu(getListView());
|
||||
}
|
||||
|
||||
// Create the menu based on the XML defintion
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.main, menu);
|
||||
return true;
|
||||
}
|
||||
// Create the menu based on the XML defintion
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.main, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Reaction to the menu selection
|
||||
@Override
|
||||
public boolean onMenuItemSelected(int featureId, MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.addtunnel:
|
||||
createTunnel();
|
||||
return true;
|
||||
case R.id.stopservice:
|
||||
Log.d("SSLDroid", "Stopping service");
|
||||
stopService(new Intent(this, SSLDroid.class));
|
||||
return true;
|
||||
case R.id.startservice:
|
||||
Log.d("SSLDroid", "Starting service");
|
||||
startService(new Intent(this, SSLDroid.class));
|
||||
return true;
|
||||
case R.id.readlogs:
|
||||
readLogs();
|
||||
return true;
|
||||
}
|
||||
return super.onMenuItemSelected(featureId, item);
|
||||
}
|
||||
// Reaction to the menu selection
|
||||
@Override
|
||||
public boolean onMenuItemSelected(int featureId, MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.addtunnel:
|
||||
createTunnel();
|
||||
return true;
|
||||
case R.id.stopservice:
|
||||
Log.d("SSLDroid", "Stopping service");
|
||||
stopService(new Intent(this, SSLDroid.class));
|
||||
return true;
|
||||
case R.id.startservice:
|
||||
Log.d("SSLDroid", "Starting service");
|
||||
startService(new Intent(this, SSLDroid.class));
|
||||
return true;
|
||||
case R.id.readlogs:
|
||||
readLogs();
|
||||
return true;
|
||||
}
|
||||
return super.onMenuItemSelected(featureId, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.addtunnel:
|
||||
createTunnel();
|
||||
return true;
|
||||
case R.id.stopservice:
|
||||
Log.d("SSLDroid", "Stopping service");
|
||||
stopService(new Intent(this, SSLDroid.class));
|
||||
return true;
|
||||
case R.id.startservice:
|
||||
Log.d("SSLDroid", "Starting service");
|
||||
startService(new Intent(this, SSLDroid.class));
|
||||
return true;
|
||||
case R.id.readlogs:
|
||||
readLogs();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.addtunnel:
|
||||
createTunnel();
|
||||
return true;
|
||||
case R.id.stopservice:
|
||||
Log.d("SSLDroid", "Stopping service");
|
||||
stopService(new Intent(this, SSLDroid.class));
|
||||
return true;
|
||||
case R.id.startservice:
|
||||
Log.d("SSLDroid", "Starting service");
|
||||
startService(new Intent(this, SSLDroid.class));
|
||||
return true;
|
||||
case R.id.readlogs:
|
||||
readLogs();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case DELETE_ID:
|
||||
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
|
||||
.getMenuInfo();
|
||||
dbHelper.deleteTunnel(info.id);
|
||||
fillData();
|
||||
return true;
|
||||
}
|
||||
return super.onContextItemSelected(item);
|
||||
}
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case DELETE_ID:
|
||||
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
|
||||
.getMenuInfo();
|
||||
dbHelper.deleteTunnel(info.id);
|
||||
fillData();
|
||||
return true;
|
||||
}
|
||||
return super.onContextItemSelected(item);
|
||||
}
|
||||
|
||||
private void createTunnel() {
|
||||
Intent i = new Intent(this, SSLDroidTunnelDetails.class);
|
||||
startActivityForResult(i, ACTIVITY_CREATE);
|
||||
}
|
||||
private void createTunnel() {
|
||||
Intent i = new Intent(this, SSLDroidTunnelDetails.class);
|
||||
startActivityForResult(i, ACTIVITY_CREATE);
|
||||
}
|
||||
|
||||
private void readLogs() {
|
||||
Intent i = new Intent(this, SSLDroidReadLogs.class);
|
||||
startActivity(i);
|
||||
}
|
||||
|
||||
// ListView and view (row) on which was clicked, position and
|
||||
@Override
|
||||
protected void onListItemClick(ListView l, View v, int position, long id) {
|
||||
super.onListItemClick(l, v, position, id);
|
||||
Intent i = new Intent(this, SSLDroidTunnelDetails.class);
|
||||
i.putExtra(SSLDroidDbAdapter.KEY_ROWID, id);
|
||||
// Activity returns an result if called with startActivityForResult
|
||||
|
||||
startActivityForResult(i, ACTIVITY_EDIT);
|
||||
}
|
||||
private void readLogs() {
|
||||
Intent i = new Intent(this, SSLDroidReadLogs.class);
|
||||
startActivity(i);
|
||||
}
|
||||
|
||||
// Called with the result of the other activity
|
||||
// requestCode was the origin request code send to the activity
|
||||
// resultCode is the return code, 0 is everything is ok
|
||||
// intend can be use to get some data from the caller
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode,
|
||||
Intent intent) {
|
||||
super.onActivityResult(requestCode, resultCode, intent);
|
||||
fillData();
|
||||
// ListView and view (row) on which was clicked, position and
|
||||
@Override
|
||||
protected void onListItemClick(ListView l, View v, int position, long id) {
|
||||
super.onListItemClick(l, v, position, id);
|
||||
Intent i = new Intent(this, SSLDroidTunnelDetails.class);
|
||||
i.putExtra(SSLDroidDbAdapter.KEY_ROWID, id);
|
||||
// Activity returns an result if called with startActivityForResult
|
||||
|
||||
}
|
||||
startActivityForResult(i, ACTIVITY_EDIT);
|
||||
}
|
||||
|
||||
private void fillData() {
|
||||
cursor = dbHelper.fetchAllTunnels();
|
||||
startManagingCursor(cursor);
|
||||
// Called with the result of the other activity
|
||||
// requestCode was the origin request code send to the activity
|
||||
// resultCode is the return code, 0 is everything is ok
|
||||
// intend can be use to get some data from the caller
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode,
|
||||
Intent intent) {
|
||||
super.onActivityResult(requestCode, resultCode, intent);
|
||||
fillData();
|
||||
|
||||
String[] from = new String[] { SSLDroidDbAdapter.KEY_NAME };
|
||||
int[] to = new int[] { R.id.text1 };
|
||||
}
|
||||
|
||||
// Now create an array adapter and set it to display using our row
|
||||
SimpleCursorAdapter tunnels = new SimpleCursorAdapter(this,
|
||||
R.layout.tunnel_list_item, cursor, from, to);
|
||||
setListAdapter(tunnels);
|
||||
}
|
||||
private void fillData() {
|
||||
cursor = dbHelper.fetchAllTunnels();
|
||||
startManagingCursor(cursor);
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v,
|
||||
ContextMenuInfo menuInfo) {
|
||||
super.onCreateContextMenu(menu, v, menuInfo);
|
||||
menu.add(0, DELETE_ID, 0, R.string.menu_delete);
|
||||
}
|
||||
String[] from = new String[] { SSLDroidDbAdapter.KEY_NAME };
|
||||
int[] to = new int[] { R.id.text1 };
|
||||
|
||||
// Now create an array adapter and set it to display using our row
|
||||
SimpleCursorAdapter tunnels = new SimpleCursorAdapter(this,
|
||||
R.layout.tunnel_list_item, cursor, from, to);
|
||||
setListAdapter(tunnels);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v,
|
||||
ContextMenuInfo menuInfo) {
|
||||
super.onCreateContextMenu(menu, v, menuInfo);
|
||||
menu.add(0, DELETE_ID, 0, R.string.menu_delete);
|
||||
}
|
||||
}
|
||||
|
@ -11,56 +11,56 @@ import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class SSLDroidReadLogs extends Activity{
|
||||
public class SSLDroidReadLogs extends Activity {
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuItem refresh = menu.add(R.string.refresh);
|
||||
refresh.setIcon(android.R.drawable.ic_menu_rotate);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
refreshLogs();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.read_logs);
|
||||
refreshLogs();
|
||||
}
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuItem refresh = menu.add(R.string.refresh);
|
||||
refresh.setIcon(android.R.drawable.ic_menu_rotate);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void refreshLogs(){
|
||||
TextView logcontainer = (TextView) findViewById(R.id.logTextView);
|
||||
logcontainer.setText("");
|
||||
Process mLogcatProc = null;
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
mLogcatProc = Runtime.getRuntime().exec(new String[]
|
||||
{"logcat", "-d", "-v", "time", "-b", "main", "SSLDroid:D SSLDroidGui:D *:S" });
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
refreshLogs();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.read_logs);
|
||||
refreshLogs();
|
||||
}
|
||||
|
||||
public void refreshLogs() {
|
||||
TextView logcontainer = (TextView) findViewById(R.id.logTextView);
|
||||
logcontainer.setText("");
|
||||
Process mLogcatProc = null;
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
mLogcatProc = Runtime.getRuntime().exec(new String[]
|
||||
{"logcat", "-d", "-v", "time", "-b", "main", "SSLDroid:D SSLDroidGui:D *:S" });
|
||||
|
||||
reader = new BufferedReader(new InputStreamReader(mLogcatProc.getInputStream()));
|
||||
|
||||
String line;
|
||||
String separator = System.getProperty("line.separator");
|
||||
String separator = System.getProperty("line.separator");
|
||||
|
||||
while ((line = reader.readLine()) != null){
|
||||
logcontainer.append(line+separator);
|
||||
while ((line = reader.readLine()) != null) {
|
||||
logcontainer.append(line+separator);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.d("SSLDroid", "Logcat problem: "+e.toString());
|
||||
}
|
||||
finally {
|
||||
} catch (IOException e) {
|
||||
Log.d("SSLDroid", "Logcat problem: "+e.toString());
|
||||
}
|
||||
finally {
|
||||
if (reader != null)
|
||||
try {
|
||||
reader.close();
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
Log.d("SSLDroid", "Logcat problem: "+e.toString());
|
||||
Log.d("SSLDroid", "Logcat problem: "+e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -37,359 +37,359 @@ import hu.blint.ssldroid.db.SSLDroidDbAdapter;
|
||||
//TODO: test connection button
|
||||
|
||||
public class SSLDroidTunnelDetails extends Activity {
|
||||
private EditText name;
|
||||
private EditText localport;
|
||||
private EditText remotehost;
|
||||
private EditText remoteport;
|
||||
private EditText pkcsfile;
|
||||
private EditText pkcspass;
|
||||
private Long rowId;
|
||||
private SSLDroidDbAdapter dbHelper;
|
||||
private EditText name;
|
||||
private EditText localport;
|
||||
private EditText remotehost;
|
||||
private EditText remoteport;
|
||||
private EditText pkcsfile;
|
||||
private EditText pkcspass;
|
||||
private Long rowId;
|
||||
private SSLDroidDbAdapter dbHelper;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
dbHelper = new SSLDroidDbAdapter(this);
|
||||
dbHelper.open();
|
||||
setContentView(R.layout.tunnel_details);
|
||||
@Override
|
||||
protected void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
dbHelper = new SSLDroidDbAdapter(this);
|
||||
dbHelper.open();
|
||||
setContentView(R.layout.tunnel_details);
|
||||
|
||||
Button confirmButton = (Button) findViewById(R.id.tunnel_apply_button);
|
||||
name = (EditText) findViewById(R.id.name);
|
||||
localport = (EditText) findViewById(R.id.localport);
|
||||
remotehost = (EditText) findViewById(R.id.remotehost);
|
||||
remoteport = (EditText) findViewById(R.id.remoteport);
|
||||
pkcsfile = (EditText) findViewById(R.id.pkcsfile);
|
||||
pkcspass = (EditText) findViewById(R.id.pkcspass);
|
||||
Button pickFile = (Button) findViewById(R.id.pickFile);
|
||||
|
||||
pickFile.setOnClickListener(new View.OnClickListener() {
|
||||
Button confirmButton = (Button) findViewById(R.id.tunnel_apply_button);
|
||||
name = (EditText) findViewById(R.id.name);
|
||||
localport = (EditText) findViewById(R.id.localport);
|
||||
remotehost = (EditText) findViewById(R.id.remotehost);
|
||||
remoteport = (EditText) findViewById(R.id.remoteport);
|
||||
pkcsfile = (EditText) findViewById(R.id.pkcsfile);
|
||||
pkcspass = (EditText) findViewById(R.id.pkcspass);
|
||||
Button pickFile = (Button) findViewById(R.id.pickFile);
|
||||
|
||||
pickFile.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View view) {
|
||||
pickFileSimple();
|
||||
pickFileSimple();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
rowId = null;
|
||||
Bundle extras = getIntent().getExtras();
|
||||
rowId = (bundle == null) ? null : (Long) bundle
|
||||
.getSerializable(SSLDroidDbAdapter.KEY_ROWID);
|
||||
if (extras != null) {
|
||||
rowId = extras.getLong(SSLDroidDbAdapter.KEY_ROWID);
|
||||
}
|
||||
populateFields();
|
||||
confirmButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View view) {
|
||||
if (name.getText().length() == 0) {
|
||||
Toast.makeText(getBaseContext(), "Required tunnel name parameter not setup, skipping save", Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
//local port validation
|
||||
if (localport.getText().length() == 0) {
|
||||
Toast.makeText(getBaseContext(), "Required local port parameter not setup, skipping save", Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
else {
|
||||
//local port should be between 1025-65535
|
||||
int cPort = 0;
|
||||
try {
|
||||
cPort = Integer.parseInt(localport.getText().toString());
|
||||
} catch (NumberFormatException e){
|
||||
Toast.makeText(getBaseContext(), "Local port parameter has invalid number format", Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
if (cPort < 1025 || cPort > 65535) {
|
||||
Toast.makeText(getBaseContext(), "Local port parameter not in valid range (1025-65535)", Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
//check if the requested port is colliding with a port already configured for another tunnel
|
||||
SSLDroidDbAdapter dbHelper = new SSLDroidDbAdapter(getBaseContext());
|
||||
dbHelper.open();
|
||||
Cursor cursor = dbHelper.fetchAllLocalPorts();
|
||||
startManagingCursor(cursor);
|
||||
while (cursor.moveToNext()){
|
||||
String cDbName = cursor.getString(cursor.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_NAME));
|
||||
int cDbPort = cursor.getInt(cursor.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_LOCALPORT));
|
||||
if (cPort == cDbPort){
|
||||
Toast.makeText(getBaseContext(), "Local port already configured in tunnel '"+cDbName+"', please change...", Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
//remote host validation
|
||||
if (remotehost.getText().length() == 0){
|
||||
Toast.makeText(getBaseContext(), "Required remote host parameter not setup, skipping save", Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
else {
|
||||
//if we have interwebs access, the remote host should exist
|
||||
ConnectivityManager conMgr = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
rowId = null;
|
||||
Bundle extras = getIntent().getExtras();
|
||||
rowId = (bundle == null) ? null : (Long) bundle
|
||||
.getSerializable(SSLDroidDbAdapter.KEY_ROWID);
|
||||
if (extras != null) {
|
||||
rowId = extras.getLong(SSLDroidDbAdapter.KEY_ROWID);
|
||||
}
|
||||
populateFields();
|
||||
confirmButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View view) {
|
||||
if (name.getText().length() == 0) {
|
||||
Toast.makeText(getBaseContext(), "Required tunnel name parameter not setup, skipping save", Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
//local port validation
|
||||
if (localport.getText().length() == 0) {
|
||||
Toast.makeText(getBaseContext(), "Required local port parameter not setup, skipping save", Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
else {
|
||||
//local port should be between 1025-65535
|
||||
int cPort = 0;
|
||||
try {
|
||||
cPort = Integer.parseInt(localport.getText().toString());
|
||||
} catch (NumberFormatException e) {
|
||||
Toast.makeText(getBaseContext(), "Local port parameter has invalid number format", Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
if (cPort < 1025 || cPort > 65535) {
|
||||
Toast.makeText(getBaseContext(), "Local port parameter not in valid range (1025-65535)", Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
//check if the requested port is colliding with a port already configured for another tunnel
|
||||
SSLDroidDbAdapter dbHelper = new SSLDroidDbAdapter(getBaseContext());
|
||||
dbHelper.open();
|
||||
Cursor cursor = dbHelper.fetchAllLocalPorts();
|
||||
startManagingCursor(cursor);
|
||||
while (cursor.moveToNext()) {
|
||||
String cDbName = cursor.getString(cursor.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_NAME));
|
||||
int cDbPort = cursor.getInt(cursor.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_LOCALPORT));
|
||||
if (cPort == cDbPort) {
|
||||
Toast.makeText(getBaseContext(), "Local port already configured in tunnel '"+cDbName+"', please change...", Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
//remote host validation
|
||||
if (remotehost.getText().length() == 0) {
|
||||
Toast.makeText(getBaseContext(), "Required remote host parameter not setup, skipping save", Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
else {
|
||||
//if we have interwebs access, the remote host should exist
|
||||
ConnectivityManager conMgr = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
|
||||
if ( conMgr.getActiveNetworkInfo() != null || conMgr.getActiveNetworkInfo().isAvailable()) {
|
||||
try {
|
||||
InetAddress.getByName(remotehost.getText().toString());
|
||||
} catch (UnknownHostException e){
|
||||
Toast.makeText(getBaseContext(), "Remote host not found, please recheck...", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
//remote port validation
|
||||
if (remoteport.getText().length() == 0){
|
||||
Toast.makeText(getBaseContext(), "Required remote port parameter not setup, skipping save", Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
else {
|
||||
//remote port should be between 1025-65535
|
||||
int cPort = 0;
|
||||
try {
|
||||
cPort = Integer.parseInt(remoteport.getText().toString());
|
||||
} catch (NumberFormatException e){
|
||||
Toast.makeText(getBaseContext(), "Remote port parameter has invalid number format", Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
if (cPort < 1 || cPort > 65535) {
|
||||
Toast.makeText(getBaseContext(), "Remote port parameter not in valid range (1-65535)", Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (pkcsfile.getText().length() == 0){
|
||||
Toast.makeText(getBaseContext(), "Required PKCS12 file parameter not setup, skipping save", Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
else {
|
||||
// try to open pkcs12 file with password
|
||||
String cPkcsFile = pkcsfile.getText().toString();
|
||||
String cPkcsPass = pkcspass.getText().toString();
|
||||
try {
|
||||
if (checkKeys(cPkcsFile, cPkcsPass) == false){
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(getBaseContext(), "PKCS12 problem: "+e.getMessage(), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
saveState();
|
||||
setResult(RESULT_OK);
|
||||
finish();
|
||||
}
|
||||
if ( conMgr.getActiveNetworkInfo() != null || conMgr.getActiveNetworkInfo().isAvailable()) {
|
||||
try {
|
||||
InetAddress.getByName(remotehost.getText().toString());
|
||||
} catch (UnknownHostException e) {
|
||||
Toast.makeText(getBaseContext(), "Remote host not found, please recheck...", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
//remote port validation
|
||||
if (remoteport.getText().length() == 0) {
|
||||
Toast.makeText(getBaseContext(), "Required remote port parameter not setup, skipping save", Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
else {
|
||||
//remote port should be between 1025-65535
|
||||
int cPort = 0;
|
||||
try {
|
||||
cPort = Integer.parseInt(remoteport.getText().toString());
|
||||
} catch (NumberFormatException e) {
|
||||
Toast.makeText(getBaseContext(), "Remote port parameter has invalid number format", Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
if (cPort < 1 || cPort > 65535) {
|
||||
Toast.makeText(getBaseContext(), "Remote port parameter not in valid range (1-65535)", Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (pkcsfile.getText().length() == 0) {
|
||||
Toast.makeText(getBaseContext(), "Required PKCS12 file parameter not setup, skipping save", Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
else {
|
||||
// try to open pkcs12 file with password
|
||||
String cPkcsFile = pkcsfile.getText().toString();
|
||||
String cPkcsPass = pkcspass.getText().toString();
|
||||
try {
|
||||
if (checkKeys(cPkcsFile, cPkcsPass) == false) {
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(getBaseContext(), "PKCS12 problem: "+e.getMessage(), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
saveState();
|
||||
setResult(RESULT_OK);
|
||||
finish();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
final List<File> getFileNames(File url, File baseurl)
|
||||
{
|
||||
final List<File> names = new LinkedList<File>();
|
||||
File[] files = url.listFiles();
|
||||
if (files != null && files.length > 0) {
|
||||
for(File file : url.listFiles()) {
|
||||
if (file.getName().startsWith("."))
|
||||
continue;
|
||||
names.add(file);
|
||||
}
|
||||
}
|
||||
return names;
|
||||
}
|
||||
final List<File> getFileNames(File url, File baseurl)
|
||||
{
|
||||
final List<File> names = new LinkedList<File>();
|
||||
File[] files = url.listFiles();
|
||||
if (files != null && files.length > 0) {
|
||||
for (File file : url.listFiles()) {
|
||||
if (file.getName().startsWith("."))
|
||||
continue;
|
||||
names.add(file);
|
||||
}
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
private void showFiles(final List<File> names, final File baseurl){
|
||||
final String[] namesList = new String[names.size()]; // = names.toArray(new String[] {});
|
||||
ListIterator<File> filelist = names.listIterator();
|
||||
int i = 0;
|
||||
while (filelist.hasNext()){
|
||||
File file = filelist.next();
|
||||
if (file.isDirectory())
|
||||
namesList[i] = file.getAbsolutePath().replaceFirst(baseurl+"/", "")+" (...)";
|
||||
else
|
||||
namesList[i] = file.getAbsolutePath().replaceFirst(baseurl+"/", "");
|
||||
i++;
|
||||
}
|
||||
//Log.d("SSLDroid", "Gathered file names: "+namesList.toString());
|
||||
|
||||
// prompt user to select any file from the sdcard root
|
||||
new AlertDialog.Builder(SSLDroidTunnelDetails.this)
|
||||
.setTitle(R.string.pkcsfile_pick)
|
||||
.setItems(namesList, new OnClickListener() {
|
||||
public void onClick(DialogInterface arg0, int arg1) {
|
||||
File name = names.get(arg1);
|
||||
if (name.isDirectory()){
|
||||
List<File> names_ = getFileNames(name, baseurl);
|
||||
Collections.sort(names_);
|
||||
if (names_.size() > 0) {
|
||||
showFiles(names_, baseurl);
|
||||
}
|
||||
else
|
||||
Toast.makeText(getBaseContext(), "Empty directory", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
if (name.isFile()) {
|
||||
pkcsfile.setText(name.getAbsolutePath());
|
||||
pkcspass.requestFocus();
|
||||
}
|
||||
}
|
||||
})
|
||||
//create a Back button (shouldn't go above base URL)
|
||||
.setNeutralButton(R.string.back, new OnClickListener() {
|
||||
public void onClick(DialogInterface arg0, int arg1) {
|
||||
if (names.size() == 0)
|
||||
return;
|
||||
File name = names.get(0);
|
||||
if (!name.getParentFile().equals(baseurl)) {
|
||||
List<File> names_ = getFileNames(name.getParentFile().getParentFile(), baseurl);
|
||||
Collections.sort(names_);
|
||||
if (names_.size() > 0) {
|
||||
showFiles(names_, baseurl);
|
||||
}
|
||||
else
|
||||
return;
|
||||
}
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, null).create().show();
|
||||
}
|
||||
|
||||
//pick a file from /sdcard, courtesy of ConnectBot
|
||||
private void pickFileSimple() {
|
||||
// build list of all files in sdcard root
|
||||
final File sdcard = Environment.getExternalStorageDirectory();
|
||||
Log.d("SSLDroid", "SD Card location: "+sdcard.toString());
|
||||
private void showFiles(final List<File> names, final File baseurl) {
|
||||
final String[] namesList = new String[names.size()]; // = names.toArray(new String[] {});
|
||||
ListIterator<File> filelist = names.listIterator();
|
||||
int i = 0;
|
||||
while (filelist.hasNext()) {
|
||||
File file = filelist.next();
|
||||
if (file.isDirectory())
|
||||
namesList[i] = file.getAbsolutePath().replaceFirst(baseurl+"/", "")+" (...)";
|
||||
else
|
||||
namesList[i] = file.getAbsolutePath().replaceFirst(baseurl+"/", "");
|
||||
i++;
|
||||
}
|
||||
//Log.d("SSLDroid", "Gathered file names: "+namesList.toString());
|
||||
|
||||
// Don't show a dialog if the SD card is completely absent.
|
||||
final String state = Environment.getExternalStorageState();
|
||||
if (!Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)
|
||||
&& !Environment.MEDIA_MOUNTED.equals(state)) {
|
||||
new AlertDialog.Builder(SSLDroidTunnelDetails.this)
|
||||
.setMessage(R.string.alert_sdcard_absent)
|
||||
.setNegativeButton(android.R.string.cancel, null).create().show();
|
||||
return;
|
||||
}
|
||||
// prompt user to select any file from the sdcard root
|
||||
new AlertDialog.Builder(SSLDroidTunnelDetails.this)
|
||||
.setTitle(R.string.pkcsfile_pick)
|
||||
.setItems(namesList, new OnClickListener() {
|
||||
public void onClick(DialogInterface arg0, int arg1) {
|
||||
File name = names.get(arg1);
|
||||
if (name.isDirectory()) {
|
||||
List<File> names_ = getFileNames(name, baseurl);
|
||||
Collections.sort(names_);
|
||||
if (names_.size() > 0) {
|
||||
showFiles(names_, baseurl);
|
||||
}
|
||||
else
|
||||
Toast.makeText(getBaseContext(), "Empty directory", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
if (name.isFile()) {
|
||||
pkcsfile.setText(name.getAbsolutePath());
|
||||
pkcspass.requestFocus();
|
||||
}
|
||||
}
|
||||
})
|
||||
//create a Back button (shouldn't go above base URL)
|
||||
.setNeutralButton(R.string.back, new OnClickListener() {
|
||||
public void onClick(DialogInterface arg0, int arg1) {
|
||||
if (names.size() == 0)
|
||||
return;
|
||||
File name = names.get(0);
|
||||
if (!name.getParentFile().equals(baseurl)) {
|
||||
List<File> names_ = getFileNames(name.getParentFile().getParentFile(), baseurl);
|
||||
Collections.sort(names_);
|
||||
if (names_.size() > 0) {
|
||||
showFiles(names_, baseurl);
|
||||
}
|
||||
else
|
||||
return;
|
||||
}
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, null).create().show();
|
||||
}
|
||||
|
||||
List<File> names = new LinkedList<File>();
|
||||
names = getFileNames(sdcard, sdcard);
|
||||
Collections.sort(names);
|
||||
showFiles(names, sdcard);
|
||||
}
|
||||
//pick a file from /sdcard, courtesy of ConnectBot
|
||||
private void pickFileSimple() {
|
||||
// build list of all files in sdcard root
|
||||
final File sdcard = Environment.getExternalStorageDirectory();
|
||||
Log.d("SSLDroid", "SD Card location: "+sdcard.toString());
|
||||
|
||||
private void populateFields() {
|
||||
if (rowId != null) {
|
||||
Cursor Tunnel = dbHelper.fetchTunnel(rowId);
|
||||
startManagingCursor(Tunnel);
|
||||
|
||||
name.setText(Tunnel.getString(Tunnel
|
||||
.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_NAME)));
|
||||
localport.setText(Tunnel.getString(Tunnel
|
||||
.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_LOCALPORT)));
|
||||
remotehost.setText(Tunnel.getString(Tunnel
|
||||
.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_REMOTEHOST)));
|
||||
remoteport.setText(Tunnel.getString(Tunnel
|
||||
.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_REMOTEPORT)));
|
||||
pkcsfile.setText(Tunnel.getString(Tunnel
|
||||
.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_PKCSFILE)));
|
||||
pkcspass.setText(Tunnel.getString(Tunnel
|
||||
.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_PKCSPASS)));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean checkKeys(String inCertPath, String passw) throws Exception {
|
||||
try {
|
||||
FileInputStream in_cert = new FileInputStream(inCertPath);
|
||||
KeyStore myStore = KeyStore.getInstance("PKCS12");
|
||||
myStore.load(in_cert, passw.toCharArray());
|
||||
Enumeration<String> eAliases = myStore.aliases();
|
||||
while (eAliases.hasMoreElements()) {
|
||||
String strAlias = (String) eAliases.nextElement();
|
||||
if (myStore.isKeyEntry(strAlias)) {
|
||||
// try to retrieve the private key part from PKCS12 certificate
|
||||
myStore.getKey(strAlias, passw.toCharArray());
|
||||
// try to retrieve the certificate part from PKCS12 certificate
|
||||
myStore.getCertificate(strAlias);
|
||||
}
|
||||
}
|
||||
// Don't show a dialog if the SD card is completely absent.
|
||||
final String state = Environment.getExternalStorageState();
|
||||
if (!Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)
|
||||
&& !Environment.MEDIA_MOUNTED.equals(state)) {
|
||||
new AlertDialog.Builder(SSLDroidTunnelDetails.this)
|
||||
.setMessage(R.string.alert_sdcard_absent)
|
||||
.setNegativeButton(android.R.string.cancel, null).create().show();
|
||||
return;
|
||||
}
|
||||
|
||||
} catch (KeyStoreException e) {
|
||||
Toast.makeText(getBaseContext(), "PKCS12 problem: "+e.getMessage(), Toast.LENGTH_LONG).show();
|
||||
return false;
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
Toast.makeText(getBaseContext(), "PKCS12 problem: "+e.getMessage(), Toast.LENGTH_LONG).show();
|
||||
return false;
|
||||
} catch (CertificateException e) {
|
||||
Toast.makeText(getBaseContext(), "PKCS12 problem: "+e.getMessage(), Toast.LENGTH_LONG).show();
|
||||
return false;
|
||||
} catch (IOException e) {
|
||||
Toast.makeText(getBaseContext(), "PKCS12 problem: "+e.getMessage(), Toast.LENGTH_LONG).show();
|
||||
return false;
|
||||
} catch (UnrecoverableKeyException e) {
|
||||
Toast.makeText(getBaseContext(), "PKCS12 problem: "+e.getMessage(), Toast.LENGTH_LONG).show();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
List<File> names = new LinkedList<File>();
|
||||
names = getFileNames(sdcard, sdcard);
|
||||
Collections.sort(names);
|
||||
showFiles(names, sdcard);
|
||||
}
|
||||
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
saveState();
|
||||
outState.putSerializable(SSLDroidDbAdapter.KEY_ROWID, rowId);
|
||||
}
|
||||
private void populateFields() {
|
||||
if (rowId != null) {
|
||||
Cursor Tunnel = dbHelper.fetchTunnel(rowId);
|
||||
startManagingCursor(Tunnel);
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
//saveState();
|
||||
}
|
||||
name.setText(Tunnel.getString(Tunnel
|
||||
.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_NAME)));
|
||||
localport.setText(Tunnel.getString(Tunnel
|
||||
.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_LOCALPORT)));
|
||||
remotehost.setText(Tunnel.getString(Tunnel
|
||||
.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_REMOTEHOST)));
|
||||
remoteport.setText(Tunnel.getString(Tunnel
|
||||
.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_REMOTEPORT)));
|
||||
pkcsfile.setText(Tunnel.getString(Tunnel
|
||||
.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_PKCSFILE)));
|
||||
pkcspass.setText(Tunnel.getString(Tunnel
|
||||
.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_PKCSPASS)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
populateFields();
|
||||
}
|
||||
public boolean checkKeys(String inCertPath, String passw) throws Exception {
|
||||
try {
|
||||
FileInputStream in_cert = new FileInputStream(inCertPath);
|
||||
KeyStore myStore = KeyStore.getInstance("PKCS12");
|
||||
myStore.load(in_cert, passw.toCharArray());
|
||||
Enumeration<String> eAliases = myStore.aliases();
|
||||
while (eAliases.hasMoreElements()) {
|
||||
String strAlias = (String) eAliases.nextElement();
|
||||
if (myStore.isKeyEntry(strAlias)) {
|
||||
// try to retrieve the private key part from PKCS12 certificate
|
||||
myStore.getKey(strAlias, passw.toCharArray());
|
||||
// try to retrieve the certificate part from PKCS12 certificate
|
||||
myStore.getCertificate(strAlias);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveState() {
|
||||
String sName = name.getText().toString();
|
||||
int sLocalport = 0;
|
||||
try{
|
||||
sLocalport = Integer.parseInt(localport.getText().toString());
|
||||
} catch (NumberFormatException e){
|
||||
}
|
||||
String sRemotehost = remotehost.getText().toString();
|
||||
int sRemoteport = 0;
|
||||
try{
|
||||
sRemoteport = Integer.parseInt(remoteport.getText().toString());
|
||||
} catch (NumberFormatException e){
|
||||
}
|
||||
String sPkcsfile = pkcsfile.getText().toString();
|
||||
String sPkcspass = pkcspass.getText().toString();
|
||||
|
||||
//make sure that we have all of our values correctly set
|
||||
if (sName.length() == 0) {
|
||||
return;
|
||||
}
|
||||
if (sLocalport == 0) {
|
||||
return;
|
||||
}
|
||||
if (sRemotehost.length() == 0) {
|
||||
return;
|
||||
}
|
||||
if (sRemoteport == 0) {
|
||||
return;
|
||||
}
|
||||
if (sPkcsfile.length() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (rowId == null) {
|
||||
long id = dbHelper.createTunnel(sName, sLocalport, sRemotehost,
|
||||
sRemoteport, sPkcsfile, sPkcspass);
|
||||
if (id > 0) {
|
||||
rowId = id;
|
||||
}
|
||||
} else {
|
||||
dbHelper.updateTunnel(rowId, sName, sLocalport, sRemotehost, sRemoteport,
|
||||
sPkcsfile, sPkcspass);
|
||||
}
|
||||
Log.d("SSLDroid", "Saving settings...");
|
||||
|
||||
//restart the service
|
||||
stopService(new Intent(this, SSLDroid.class));
|
||||
startService(new Intent(this, SSLDroid.class));
|
||||
Log.d("SSLDroid", "Restarting service after settings save...");
|
||||
|
||||
}
|
||||
} catch (KeyStoreException e) {
|
||||
Toast.makeText(getBaseContext(), "PKCS12 problem: "+e.getMessage(), Toast.LENGTH_LONG).show();
|
||||
return false;
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
Toast.makeText(getBaseContext(), "PKCS12 problem: "+e.getMessage(), Toast.LENGTH_LONG).show();
|
||||
return false;
|
||||
} catch (CertificateException e) {
|
||||
Toast.makeText(getBaseContext(), "PKCS12 problem: "+e.getMessage(), Toast.LENGTH_LONG).show();
|
||||
return false;
|
||||
} catch (IOException e) {
|
||||
Toast.makeText(getBaseContext(), "PKCS12 problem: "+e.getMessage(), Toast.LENGTH_LONG).show();
|
||||
return false;
|
||||
} catch (UnrecoverableKeyException e) {
|
||||
Toast.makeText(getBaseContext(), "PKCS12 problem: "+e.getMessage(), Toast.LENGTH_LONG).show();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
saveState();
|
||||
outState.putSerializable(SSLDroidDbAdapter.KEY_ROWID, rowId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
//saveState();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
populateFields();
|
||||
}
|
||||
|
||||
private void saveState() {
|
||||
String sName = name.getText().toString();
|
||||
int sLocalport = 0;
|
||||
try {
|
||||
sLocalport = Integer.parseInt(localport.getText().toString());
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
String sRemotehost = remotehost.getText().toString();
|
||||
int sRemoteport = 0;
|
||||
try {
|
||||
sRemoteport = Integer.parseInt(remoteport.getText().toString());
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
String sPkcsfile = pkcsfile.getText().toString();
|
||||
String sPkcspass = pkcspass.getText().toString();
|
||||
|
||||
//make sure that we have all of our values correctly set
|
||||
if (sName.length() == 0) {
|
||||
return;
|
||||
}
|
||||
if (sLocalport == 0) {
|
||||
return;
|
||||
}
|
||||
if (sRemotehost.length() == 0) {
|
||||
return;
|
||||
}
|
||||
if (sRemoteport == 0) {
|
||||
return;
|
||||
}
|
||||
if (sPkcsfile.length() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (rowId == null) {
|
||||
long id = dbHelper.createTunnel(sName, sLocalport, sRemotehost,
|
||||
sRemoteport, sPkcsfile, sPkcspass);
|
||||
if (id > 0) {
|
||||
rowId = id;
|
||||
}
|
||||
} else {
|
||||
dbHelper.updateTunnel(rowId, sName, sLocalport, sRemotehost, sRemoteport,
|
||||
sPkcsfile, sPkcspass);
|
||||
}
|
||||
Log.d("SSLDroid", "Saving settings...");
|
||||
|
||||
//restart the service
|
||||
stopService(new Intent(this, SSLDroid.class));
|
||||
startService(new Intent(this, SSLDroid.class));
|
||||
Log.d("SSLDroid", "Restarting service after settings save...");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,53 +11,53 @@ import android.util.Log;
|
||||
* xml.apache.org project.
|
||||
*/
|
||||
public class TcpProxy {
|
||||
String tunnelName;
|
||||
int listenPort;
|
||||
String tunnelHost;
|
||||
int tunnelPort;
|
||||
String keyFile, keyPass;
|
||||
Thread server = null;
|
||||
ServerSocket ss = null;
|
||||
String tunnelName;
|
||||
int listenPort;
|
||||
String tunnelHost;
|
||||
int tunnelPort;
|
||||
String keyFile, keyPass;
|
||||
Thread server = null;
|
||||
ServerSocket ss = null;
|
||||
|
||||
public TcpProxy(String tunnelName, int listenPort, String targetHost, int targetPort, String keyFile, String keyPass) {
|
||||
this.tunnelName = tunnelName;
|
||||
this.listenPort = listenPort;
|
||||
this.tunnelHost = targetHost;
|
||||
this.tunnelPort = targetPort;
|
||||
this.keyFile = keyFile;
|
||||
this.keyPass = keyPass;
|
||||
}
|
||||
public TcpProxy(String tunnelName, int listenPort, String targetHost, int targetPort, String keyFile, String keyPass) {
|
||||
this.tunnelName = tunnelName;
|
||||
this.listenPort = listenPort;
|
||||
this.tunnelHost = targetHost;
|
||||
this.tunnelPort = targetPort;
|
||||
this.keyFile = keyFile;
|
||||
this.keyPass = keyPass;
|
||||
}
|
||||
|
||||
public void serve() throws IOException {
|
||||
try {
|
||||
ss = new ServerSocket(listenPort, 50, InetAddress.getLocalHost());
|
||||
Log.d("SSLDroid", "Listening for connections on port "
|
||||
+ this.listenPort + " ...");
|
||||
} catch (Exception e) {
|
||||
Log.d("SSLDroid", "Error setting up listening socket: " + e.toString());
|
||||
return;
|
||||
}
|
||||
server = new TcpProxyServerThread(this.ss, this.tunnelName, this.listenPort, this.tunnelHost,
|
||||
this.tunnelPort, this.keyFile, this.keyPass);
|
||||
server.start();
|
||||
}
|
||||
public void serve() throws IOException {
|
||||
try {
|
||||
ss = new ServerSocket(listenPort, 50, InetAddress.getLocalHost());
|
||||
Log.d("SSLDroid", "Listening for connections on port "
|
||||
+ this.listenPort + " ...");
|
||||
} catch (Exception e) {
|
||||
Log.d("SSLDroid", "Error setting up listening socket: " + e.toString());
|
||||
return;
|
||||
}
|
||||
server = new TcpProxyServerThread(this.ss, this.tunnelName, this.listenPort, this.tunnelHost,
|
||||
this.tunnelPort, this.keyFile, this.keyPass);
|
||||
server.start();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (server != null){
|
||||
try {
|
||||
//close the server socket and interrupt the server thread
|
||||
ss.close();
|
||||
server.interrupt();
|
||||
} catch (Exception e) {
|
||||
Log.d("SSLDroid", "Interrupt failure: " + e.toString());
|
||||
}
|
||||
}
|
||||
Log.d("SSLDroid", "Stopping tunnel "+this.listenPort+":"+this.tunnelHost+":"+this.tunnelPort);
|
||||
}
|
||||
public void stop() {
|
||||
if (server != null) {
|
||||
try {
|
||||
//close the server socket and interrupt the server thread
|
||||
ss.close();
|
||||
server.interrupt();
|
||||
} catch (Exception e) {
|
||||
Log.d("SSLDroid", "Interrupt failure: " + e.toString());
|
||||
}
|
||||
}
|
||||
Log.d("SSLDroid", "Stopping tunnel "+this.listenPort+":"+this.tunnelHost+":"+this.tunnelPort);
|
||||
}
|
||||
|
||||
//if the listening socket is still active, we're alive
|
||||
public boolean isAlive(){
|
||||
return ss.isBound();
|
||||
}
|
||||
//if the listening socket is still active, we're alive
|
||||
public boolean isAlive() {
|
||||
return ss.isBound();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,192 +25,192 @@ import javax.net.ssl.X509TrustManager;
|
||||
import android.util.Log;
|
||||
|
||||
public class TcpProxyServerThread extends Thread {
|
||||
|
||||
String tunnelName;
|
||||
int listenPort;
|
||||
String tunnelHost;
|
||||
int tunnelPort;
|
||||
String keyFile, keyPass;
|
||||
Relay inRelay, outRelay;
|
||||
ServerSocket ss = null;
|
||||
int sessionid = 0;
|
||||
|
||||
public TcpProxyServerThread(ServerSocket ss,String tunnelName, int listenPort, String tunnelHost, int tunnelPort, String keyFile, String keyPass) {
|
||||
this.tunnelName = tunnelName;
|
||||
this.listenPort = listenPort;
|
||||
this.tunnelHost = tunnelHost;
|
||||
this.tunnelPort = tunnelPort;
|
||||
this.keyFile = keyFile;
|
||||
this.keyPass = keyPass;
|
||||
this.ss = ss;
|
||||
}
|
||||
|
||||
// Create a trust manager that does not validate certificate chains
|
||||
// TODO: handle this somehow properly (popup if cert is untrusted?)
|
||||
// TODO: cacert + crl should be configurable
|
||||
TrustManager[] trustAllCerts = new TrustManager[]{
|
||||
new X509TrustManager() {
|
||||
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
|
||||
return null;
|
||||
}
|
||||
public void checkClientTrusted(
|
||||
java.security.cert.X509Certificate[] certs, String authType) {
|
||||
}
|
||||
public void checkServerTrusted(
|
||||
java.security.cert.X509Certificate[] certs, String authType) {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private static SSLSocketFactory sslSocketFactory;
|
||||
String tunnelName;
|
||||
int listenPort;
|
||||
String tunnelHost;
|
||||
int tunnelPort;
|
||||
String keyFile, keyPass;
|
||||
Relay inRelay, outRelay;
|
||||
ServerSocket ss = null;
|
||||
int sessionid = 0;
|
||||
|
||||
public final SSLSocketFactory getSocketFactory(String pkcsFile,
|
||||
String pwd, int sessionid) {
|
||||
if (sslSocketFactory == null) {
|
||||
try {
|
||||
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("X509");
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(new FileInputStream(pkcsFile), pwd.toCharArray());
|
||||
keyManagerFactory.init(keyStore, pwd.toCharArray());
|
||||
SSLContext context = SSLContext.getInstance("TLS");
|
||||
context.init(keyManagerFactory.getKeyManagers(), trustAllCerts,
|
||||
new SecureRandom());
|
||||
sslSocketFactory = (SSLSocketFactory) context.getSocketFactory();
|
||||
public TcpProxyServerThread(ServerSocket ss,String tunnelName, int listenPort, String tunnelHost, int tunnelPort, String keyFile, String keyPass) {
|
||||
this.tunnelName = tunnelName;
|
||||
this.listenPort = listenPort;
|
||||
this.tunnelHost = tunnelHost;
|
||||
this.tunnelPort = tunnelPort;
|
||||
this.keyFile = keyFile;
|
||||
this.keyPass = keyPass;
|
||||
this.ss = ss;
|
||||
}
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Error loading the client certificate file:"
|
||||
+ e.toString());
|
||||
} catch (KeyManagementException e) {
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": No SSL algorithm support: " + e.toString());
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": No common SSL algorithm found: " + e.toString());
|
||||
} catch (KeyStoreException e) {
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Error setting up keystore:" + e.toString());
|
||||
} catch (java.security.cert.CertificateException e) {
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Error loading the client certificate:" + e.toString());
|
||||
} catch (IOException e) {
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Error loading the client certificate file:" + e.toString());
|
||||
} catch (UnrecoverableKeyException e) {
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Error loading the client certificate:" + e.toString());
|
||||
}
|
||||
}
|
||||
return sslSocketFactory;
|
||||
}
|
||||
|
||||
public class Relay extends Thread {
|
||||
private InputStream in;
|
||||
private OutputStream out;
|
||||
private String side;
|
||||
private int sessionid;
|
||||
private final static int BUFSIZ = 4096;
|
||||
private byte buf[] = new byte[BUFSIZ];
|
||||
// Create a trust manager that does not validate certificate chains
|
||||
// TODO: handle this somehow properly (popup if cert is untrusted?)
|
||||
// TODO: cacert + crl should be configurable
|
||||
TrustManager[] trustAllCerts = new TrustManager[] {
|
||||
new X509TrustManager() {
|
||||
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
|
||||
return null;
|
||||
}
|
||||
public void checkClientTrusted(
|
||||
java.security.cert.X509Certificate[] certs, String authType) {
|
||||
}
|
||||
public void checkServerTrusted(
|
||||
java.security.cert.X509Certificate[] certs, String authType) {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public Relay(InputStream in, OutputStream out, String side, int sessionid) {
|
||||
this.in = in;
|
||||
this.out = out;
|
||||
this.side = side;
|
||||
this.sessionid = sessionid;
|
||||
}
|
||||
private static SSLSocketFactory sslSocketFactory;
|
||||
|
||||
public void run() {
|
||||
int n = 0;
|
||||
public final SSLSocketFactory getSocketFactory(String pkcsFile,
|
||||
String pwd, int sessionid) {
|
||||
if (sslSocketFactory == null) {
|
||||
try {
|
||||
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("X509");
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(new FileInputStream(pkcsFile), pwd.toCharArray());
|
||||
keyManagerFactory.init(keyStore, pwd.toCharArray());
|
||||
SSLContext context = SSLContext.getInstance("TLS");
|
||||
context.init(keyManagerFactory.getKeyManagers(), trustAllCerts,
|
||||
new SecureRandom());
|
||||
sslSocketFactory = (SSLSocketFactory) context.getSocketFactory();
|
||||
|
||||
try {
|
||||
while ((n = in.read(buf)) > 0) {
|
||||
if (Thread.interrupted()) {
|
||||
// We've been interrupted: no more relaying
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Interrupted "+side+" thread");
|
||||
try {
|
||||
in.close();
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": "+e.toString());
|
||||
}
|
||||
return;
|
||||
}
|
||||
out.write(buf, 0, n);
|
||||
out.flush();
|
||||
} catch (FileNotFoundException e) {
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Error loading the client certificate file:"
|
||||
+ e.toString());
|
||||
} catch (KeyManagementException e) {
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": No SSL algorithm support: " + e.toString());
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": No common SSL algorithm found: " + e.toString());
|
||||
} catch (KeyStoreException e) {
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Error setting up keystore:" + e.toString());
|
||||
} catch (java.security.cert.CertificateException e) {
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Error loading the client certificate:" + e.toString());
|
||||
} catch (IOException e) {
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Error loading the client certificate file:" + e.toString());
|
||||
} catch (UnrecoverableKeyException e) {
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Error loading the client certificate:" + e.toString());
|
||||
}
|
||||
}
|
||||
return sslSocketFactory;
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (buf[i] == 7)
|
||||
buf[i] = '#';
|
||||
}
|
||||
}
|
||||
} catch (SocketException e) {
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": "+e.toString());
|
||||
} catch (IOException e) {
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": "+e.toString());
|
||||
} finally {
|
||||
try {
|
||||
in.close();
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": "+e.toString());
|
||||
}
|
||||
}
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Quitting "+side+"-side stream proxy...");
|
||||
}
|
||||
}
|
||||
|
||||
public void run() {
|
||||
while (true) {
|
||||
try {
|
||||
Thread fromBrowserToServer = null;
|
||||
Thread fromServerToBrowser = null;
|
||||
|
||||
if (isInterrupted()){
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Interrupted server thread, closing sockets...");
|
||||
ss.close();
|
||||
if (fromBrowserToServer != null)
|
||||
fromBrowserToServer.notify();
|
||||
if (fromServerToBrowser != null)
|
||||
fromServerToBrowser.notify();
|
||||
return;
|
||||
}
|
||||
// accept the connection from my client
|
||||
Socket sc = null;
|
||||
try {
|
||||
sc = ss.accept();
|
||||
sessionid++;
|
||||
} catch (SocketException e){
|
||||
Log.d("SSLDroid", "Accept failure: " + e.toString());
|
||||
}
|
||||
|
||||
Socket st = null;
|
||||
try {
|
||||
st = (SSLSocket) getSocketFactory(this.keyFile, this.keyPass, this.sessionid).createSocket(this.tunnelHost, this.tunnelPort);
|
||||
((SSLSocket) st).startHandshake();
|
||||
} catch (IOException e){
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": SSL failure: " + e.toString());
|
||||
sc.close();
|
||||
return;
|
||||
}
|
||||
public class Relay extends Thread {
|
||||
private InputStream in;
|
||||
private OutputStream out;
|
||||
private String side;
|
||||
private int sessionid;
|
||||
private final static int BUFSIZ = 4096;
|
||||
private byte buf[] = new byte[BUFSIZ];
|
||||
|
||||
if (sc == null || st == null){
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Trying socket operation on a null socket, returning");
|
||||
return;
|
||||
}
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Tunnelling port "
|
||||
+ listenPort + " to port "
|
||||
+ tunnelPort + " on host "
|
||||
+ tunnelHost + " ...");
|
||||
|
||||
// relay the stuff through
|
||||
fromBrowserToServer = new Relay(
|
||||
sc.getInputStream(), st.getOutputStream(), "client", sessionid);
|
||||
fromServerToBrowser = new Relay(
|
||||
st.getInputStream(), sc.getOutputStream(), "server", sessionid);
|
||||
public Relay(InputStream in, OutputStream out, String side, int sessionid) {
|
||||
this.in = in;
|
||||
this.out = out;
|
||||
this.side = side;
|
||||
this.sessionid = sessionid;
|
||||
}
|
||||
|
||||
fromBrowserToServer.start();
|
||||
fromServerToBrowser.start();
|
||||
public void run() {
|
||||
int n = 0;
|
||||
|
||||
} catch (IOException ee) {
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Ouch: " + ee.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
while ((n = in.read(buf)) > 0) {
|
||||
if (Thread.interrupted()) {
|
||||
// We've been interrupted: no more relaying
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Interrupted "+side+" thread");
|
||||
try {
|
||||
in.close();
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": "+e.toString());
|
||||
}
|
||||
return;
|
||||
}
|
||||
out.write(buf, 0, n);
|
||||
out.flush();
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (buf[i] == 7)
|
||||
buf[i] = '#';
|
||||
}
|
||||
}
|
||||
} catch (SocketException e) {
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": "+e.toString());
|
||||
} catch (IOException e) {
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": "+e.toString());
|
||||
} finally {
|
||||
try {
|
||||
in.close();
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": "+e.toString());
|
||||
}
|
||||
}
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Quitting "+side+"-side stream proxy...");
|
||||
}
|
||||
}
|
||||
|
||||
public void run() {
|
||||
while (true) {
|
||||
try {
|
||||
Thread fromBrowserToServer = null;
|
||||
Thread fromServerToBrowser = null;
|
||||
|
||||
if (isInterrupted()) {
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Interrupted server thread, closing sockets...");
|
||||
ss.close();
|
||||
if (fromBrowserToServer != null)
|
||||
fromBrowserToServer.notify();
|
||||
if (fromServerToBrowser != null)
|
||||
fromServerToBrowser.notify();
|
||||
return;
|
||||
}
|
||||
// accept the connection from my client
|
||||
Socket sc = null;
|
||||
try {
|
||||
sc = ss.accept();
|
||||
sessionid++;
|
||||
} catch (SocketException e) {
|
||||
Log.d("SSLDroid", "Accept failure: " + e.toString());
|
||||
}
|
||||
|
||||
Socket st = null;
|
||||
try {
|
||||
st = (SSLSocket) getSocketFactory(this.keyFile, this.keyPass, this.sessionid).createSocket(this.tunnelHost, this.tunnelPort);
|
||||
((SSLSocket) st).startHandshake();
|
||||
} catch (IOException e) {
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": SSL failure: " + e.toString());
|
||||
sc.close();
|
||||
return;
|
||||
}
|
||||
|
||||
if (sc == null || st == null) {
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Trying socket operation on a null socket, returning");
|
||||
return;
|
||||
}
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Tunnelling port "
|
||||
+ listenPort + " to port "
|
||||
+ tunnelPort + " on host "
|
||||
+ tunnelHost + " ...");
|
||||
|
||||
// relay the stuff through
|
||||
fromBrowserToServer = new Relay(
|
||||
sc.getInputStream(), st.getOutputStream(), "client", sessionid);
|
||||
fromServerToBrowser = new Relay(
|
||||
st.getInputStream(), sc.getOutputStream(), "server", sessionid);
|
||||
|
||||
fromBrowserToServer.start();
|
||||
fromServerToBrowser.start();
|
||||
|
||||
} catch (IOException ee) {
|
||||
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Ouch: " + ee.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -8,112 +8,115 @@ import android.database.sqlite.SQLiteDatabase;
|
||||
|
||||
public class SSLDroidDbAdapter {
|
||||
|
||||
// Database fields
|
||||
public static final String KEY_ROWID = "_id";
|
||||
public static final String KEY_NAME = "name";
|
||||
public static final String KEY_LOCALPORT = "localport";
|
||||
public static final String KEY_REMOTEHOST = "remotehost";
|
||||
public static final String KEY_REMOTEPORT = "remoteport";
|
||||
public static final String KEY_PKCSFILE = "pkcsfile";
|
||||
public static final String KEY_PKCSPASS = "pkcspass";
|
||||
private static final String DATABASE_TABLE = "tunnels";
|
||||
private Context context;
|
||||
private SQLiteDatabase database;
|
||||
private SSLDroidDbHelper dbHelper;
|
||||
// Database fields
|
||||
public static final String KEY_ROWID = "_id";
|
||||
public static final String KEY_NAME = "name";
|
||||
public static final String KEY_LOCALPORT = "localport";
|
||||
public static final String KEY_REMOTEHOST = "remotehost";
|
||||
public static final String KEY_REMOTEPORT = "remoteport";
|
||||
public static final String KEY_PKCSFILE = "pkcsfile";
|
||||
public static final String KEY_PKCSPASS = "pkcspass";
|
||||
private static final String DATABASE_TABLE = "tunnels";
|
||||
private Context context;
|
||||
private SQLiteDatabase database;
|
||||
private SSLDroidDbHelper dbHelper;
|
||||
|
||||
public SSLDroidDbAdapter(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
public SSLDroidDbAdapter(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public SSLDroidDbAdapter open() throws SQLException {
|
||||
dbHelper = new SSLDroidDbHelper(context);
|
||||
database = dbHelper.getWritableDatabase();
|
||||
return this;
|
||||
}
|
||||
public SSLDroidDbAdapter open() throws SQLException {
|
||||
dbHelper = new SSLDroidDbHelper(context);
|
||||
database = dbHelper.getWritableDatabase();
|
||||
return this;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
dbHelper.close();
|
||||
database.close();
|
||||
}
|
||||
public void close() {
|
||||
dbHelper.close();
|
||||
database.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new tunnel If the tunnel is successfully created return the new
|
||||
* rowId for that note, otherwise return a -1 to indicate failure.
|
||||
*/
|
||||
public long createTunnel(String name, int localport, String remotehost, int remoteport,
|
||||
String pkcsfile, String pkcspass) {
|
||||
ContentValues initialValues = createContentValues(name, localport, remotehost,
|
||||
remoteport, pkcsfile, pkcspass);
|
||||
/**
|
||||
* Create a new tunnel If the tunnel is successfully created return the new
|
||||
* rowId for that note, otherwise return a -1 to indicate failure.
|
||||
*/
|
||||
public long createTunnel(String name, int localport, String remotehost, int remoteport,
|
||||
String pkcsfile, String pkcspass) {
|
||||
ContentValues initialValues = createContentValues(name, localport, remotehost,
|
||||
remoteport, pkcsfile, pkcspass);
|
||||
|
||||
return database.insert(DATABASE_TABLE, null, initialValues);
|
||||
}
|
||||
return database.insert(DATABASE_TABLE, null, initialValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the tunnel
|
||||
*/
|
||||
public boolean updateTunnel(long rowId, String name, int localport, String remotehost,
|
||||
int remoteport, String pkcsfile, String pkcspass) {
|
||||
ContentValues updateValues = createContentValues(name, localport, remotehost,
|
||||
remoteport, pkcsfile, pkcspass);
|
||||
/**
|
||||
* Update the tunnel
|
||||
*/
|
||||
public boolean updateTunnel(long rowId, String name, int localport, String remotehost,
|
||||
int remoteport, String pkcsfile, String pkcspass) {
|
||||
ContentValues updateValues = createContentValues(name, localport, remotehost,
|
||||
remoteport, pkcsfile, pkcspass);
|
||||
|
||||
return database.update(DATABASE_TABLE, updateValues, KEY_ROWID + "="
|
||||
+ rowId, null) > 0;
|
||||
}
|
||||
return database.update(DATABASE_TABLE, updateValues, KEY_ROWID + "="
|
||||
+ rowId, null) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes tunnel
|
||||
*/
|
||||
public boolean deleteTunnel(long rowId) {
|
||||
return database.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0;
|
||||
}
|
||||
/**
|
||||
* Deletes tunnel
|
||||
*/
|
||||
public boolean deleteTunnel(long rowId) {
|
||||
return database.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a Cursor over the list of all tunnels in the database
|
||||
*
|
||||
* @return Cursor over all notes
|
||||
*/
|
||||
public Cursor fetchAllTunnels() {
|
||||
return database.query(DATABASE_TABLE, new String[] { KEY_ROWID,
|
||||
KEY_NAME, KEY_LOCALPORT, KEY_REMOTEHOST, KEY_REMOTEPORT, KEY_PKCSFILE,
|
||||
KEY_PKCSPASS }, null, null, null, null, null);
|
||||
}
|
||||
/**
|
||||
* Return a Cursor over the list of all tunnels in the database
|
||||
*
|
||||
* @return Cursor over all notes
|
||||
*/
|
||||
public Cursor fetchAllTunnels() {
|
||||
return database.query(DATABASE_TABLE, new String[] { KEY_ROWID,
|
||||
KEY_NAME, KEY_LOCALPORT, KEY_REMOTEHOST, KEY_REMOTEPORT, KEY_PKCSFILE,
|
||||
KEY_PKCSPASS
|
||||
}, null, null, null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a Cursor over the list of all tunnels in the database
|
||||
*
|
||||
* @return Cursor over all notes
|
||||
*/
|
||||
public Cursor fetchAllLocalPorts() {
|
||||
return database.query(DATABASE_TABLE, new String[] { KEY_NAME,
|
||||
KEY_LOCALPORT }, null, null, null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a Cursor positioned at the defined tunnel
|
||||
*/
|
||||
public Cursor fetchTunnel(long rowId) throws SQLException {
|
||||
Cursor mCursor = database.query(true, DATABASE_TABLE, new String[] {
|
||||
KEY_ROWID, KEY_NAME, KEY_LOCALPORT, KEY_REMOTEHOST, KEY_REMOTEPORT,
|
||||
KEY_PKCSFILE, KEY_PKCSPASS },
|
||||
KEY_ROWID + "=" + rowId, null, null, null, null, null);
|
||||
if (mCursor != null) {
|
||||
mCursor.moveToFirst();
|
||||
}
|
||||
return mCursor;
|
||||
}
|
||||
/**
|
||||
* Return a Cursor over the list of all tunnels in the database
|
||||
*
|
||||
* @return Cursor over all notes
|
||||
*/
|
||||
public Cursor fetchAllLocalPorts() {
|
||||
return database.query(DATABASE_TABLE, new String[] { KEY_NAME,
|
||||
KEY_LOCALPORT
|
||||
}, null, null, null, null, null);
|
||||
}
|
||||
|
||||
private ContentValues createContentValues(String name, int localport, String remotehost, int remoteport,
|
||||
String pkcsfile, String pkcspass) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(KEY_NAME, name);
|
||||
values.put(KEY_LOCALPORT, localport);
|
||||
values.put(KEY_REMOTEHOST, remotehost);
|
||||
values.put(KEY_REMOTEPORT, remoteport);
|
||||
values.put(KEY_REMOTEPORT, remoteport);
|
||||
values.put(KEY_PKCSFILE, pkcsfile);
|
||||
values.put(KEY_PKCSPASS, pkcspass);
|
||||
return values;
|
||||
}
|
||||
/**
|
||||
* Return a Cursor positioned at the defined tunnel
|
||||
*/
|
||||
public Cursor fetchTunnel(long rowId) throws SQLException {
|
||||
Cursor mCursor = database.query(true, DATABASE_TABLE, new String[] {
|
||||
KEY_ROWID, KEY_NAME, KEY_LOCALPORT, KEY_REMOTEHOST, KEY_REMOTEPORT,
|
||||
KEY_PKCSFILE, KEY_PKCSPASS
|
||||
},
|
||||
KEY_ROWID + "=" + rowId, null, null, null, null, null);
|
||||
if (mCursor != null) {
|
||||
mCursor.moveToFirst();
|
||||
}
|
||||
return mCursor;
|
||||
}
|
||||
|
||||
private ContentValues createContentValues(String name, int localport, String remotehost, int remoteport,
|
||||
String pkcsfile, String pkcspass) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(KEY_NAME, name);
|
||||
values.put(KEY_LOCALPORT, localport);
|
||||
values.put(KEY_REMOTEHOST, remotehost);
|
||||
values.put(KEY_REMOTEPORT, remoteport);
|
||||
values.put(KEY_REMOTEPORT, remoteport);
|
||||
values.put(KEY_PKCSFILE, pkcsfile);
|
||||
values.put(KEY_PKCSPASS, pkcspass);
|
||||
return values;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -5,35 +5,35 @@ import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
|
||||
public class SSLDroidDbHelper extends SQLiteOpenHelper {
|
||||
private static final String DATABASE_NAME = "applicationdata";
|
||||
private static final String DATABASE_NAME = "applicationdata";
|
||||
|
||||
private static final int DATABASE_VERSION = 1;
|
||||
private static final int DATABASE_VERSION = 1;
|
||||
|
||||
// Database creation sql statement
|
||||
private static final String DATABASE_CREATE = "create table tunnels (_id integer primary key autoincrement, "
|
||||
+ "name text not null, localport integer not null, remotehost text not null, "
|
||||
+ "remoteport integer not null, pkcsfile text not null, pkcspass text );";
|
||||
// Database creation sql statement
|
||||
private static final String DATABASE_CREATE = "create table tunnels (_id integer primary key autoincrement, "
|
||||
+ "name text not null, localport integer not null, remotehost text not null, "
|
||||
+ "remoteport integer not null, pkcsfile text not null, pkcspass text );";
|
||||
|
||||
public SSLDroidDbHelper(Context context) {
|
||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||
}
|
||||
public SSLDroidDbHelper(Context context) {
|
||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||
}
|
||||
|
||||
// Method is called during creation of the database
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase database) {
|
||||
database.execSQL(DATABASE_CREATE);
|
||||
}
|
||||
// Method is called during creation of the database
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase database) {
|
||||
database.execSQL(DATABASE_CREATE);
|
||||
}
|
||||
|
||||
// Method is called during an update of the database, e.g. if you increase
|
||||
// the database version
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase database, int oldVersion,
|
||||
int newVersion) {
|
||||
/* Log.w(SSLDroidDbHelper.class.getName(),
|
||||
"Upgrading database from version " + oldVersion + " to "
|
||||
+ newVersion + ", which will destroy all old data");
|
||||
database.execSQL("DROP TABLE IF EXISTS todo");
|
||||
onCreate(database); */
|
||||
}
|
||||
// Method is called during an update of the database, e.g. if you increase
|
||||
// the database version
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase database, int oldVersion,
|
||||
int newVersion) {
|
||||
/* Log.w(SSLDroidDbHelper.class.getName(),
|
||||
"Upgrading database from version " + oldVersion + " to "
|
||||
+ newVersion + ", which will destroy all old data");
|
||||
database.execSQL("DROP TABLE IF EXISTS todo");
|
||||
onCreate(database); */
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user