Skip to content

Commit

Permalink
implement #21 remote access via onion server and orbot!
Browse files Browse the repository at this point in the history
The app allows you to now enable remote access through an HTTP web interface
that is available, in coordination with the Orbot Tor for Android app, as a
Tor Hidden or "onion" service.
  • Loading branch information
n8fr8 committed Jun 26, 2017
1 parent c944a86 commit dc22847
Show file tree
Hide file tree
Showing 21 changed files with 338 additions and 14 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.android.tools.build:gradle:2.3.3'
}

}
Expand Down Expand Up @@ -54,6 +54,6 @@ dependencies {
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'net.the4thdimension:audio-wife:1.0.3'
compile 'com.github.paolorotolo:appintro:4.1.0'
compile 'info.guardianproject.netcipher:netcipher:2.0.0-alpha1'


}
compile 'com.nanohttpd:nanohttpd-webserver:2.2.0'}
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Mar 17 12:27:46 EDT 2017
#Sat Jun 24 00:08:44 EDT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
20 changes: 20 additions & 0 deletions src/main/java/info/guardianproject/phoneypot/ListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import info.guardianproject.phoneypot.model.Event;
import info.guardianproject.phoneypot.model.EventTrigger;
import info.guardianproject.phoneypot.service.WebServer;
import info.guardianproject.phoneypot.ui.EventActivity;
import info.guardianproject.phoneypot.ui.EventAdapter;
import info.guardianproject.phoneypot.ui.PPAppIntro;
Expand All @@ -25,6 +26,8 @@
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import java.io.File;
Expand Down Expand Up @@ -265,4 +268,21 @@ private void showOnboarding()

}

/**
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected (MenuItem item) {
switch (item.getItemId()){
case R.id.menu_remote:
enableRemoteAccess();
break;
}
return true;
}**/

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,46 @@ public class PreferenceManager {
private static final String TIMER_DELAY="timer_delay";
private static final String DIR_PATH = "/secureit";

private Context context;
private static final String REMOTE_ACCESS_ACTIVE = "remote_access_active";
private static final String REMOTE_ACCESS_ONION = "remote_access_onion";
private static final String REMOTE_ACCESS_CRED = "remote_access_credential";

private Context context;

public PreferenceManager(Context context) {
this.context = context;
this.appSharedPrefs = context.getSharedPreferences(APP_SHARED_PREFS, Activity.MODE_PRIVATE);
this.prefsEditor = appSharedPrefs.edit();
}


public void activateRemoteAccess (boolean active) {
prefsEditor.putBoolean(REMOTE_ACCESS_ACTIVE,active);
prefsEditor.commit();
}

public boolean getRemoteAccessActive ()
{
return appSharedPrefs.getBoolean(REMOTE_ACCESS_ACTIVE,false);
}

public void setRemoteAccessOnion (String onionAddress) {
prefsEditor.putString(REMOTE_ACCESS_ONION,onionAddress);
prefsEditor.commit();
}

public String getRemoteAccessOnion () {
return appSharedPrefs.getString(REMOTE_ACCESS_ONION,"");
}

public void setRemoteAccessCredential (String remoteCredential) {
prefsEditor.putString(REMOTE_ACCESS_CRED,remoteCredential);
prefsEditor.commit();
}

public String getRemoteAccessCredential () {
return appSharedPrefs.getString(REMOTE_ACCESS_CRED,null);
}

public void activateAccelerometer(boolean active) {
prefsEditor.putBoolean(ACCELEROMETER_ACTIVE, active);
prefsEditor.commit();
Expand Down
63 changes: 60 additions & 3 deletions src/main/java/info/guardianproject/phoneypot/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
import java.io.File;

import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
Expand All @@ -28,6 +30,11 @@
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Spinner;

import org.w3c.dom.Text;

import info.guardianproject.netcipher.proxy.OrbotHelper;
import info.guardianproject.phoneypot.service.WebServer;

public class SettingsActivity extends AppCompatActivity {

private PreferenceManager preferences = null;
Expand All @@ -41,7 +48,6 @@ public void onCreate(Bundle savedInstanceState) {
Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(toolbar);


preferences = new PreferenceManager(this.getApplicationContext());

/*
Expand All @@ -54,7 +60,8 @@ public void onCreate(Bundle savedInstanceState) {
* Checkboxes for enabled app options
*/
final CheckBox smsCheck = (CheckBox) this.findViewById(R.id.sms_check);

final CheckBox remoteAccessCheck = (CheckBox) this.findViewById(R.id.remote_access_check);

/*
* Detecting if the device has a front camera
* and configuring the spinner of camera selection
Expand Down Expand Up @@ -85,6 +92,8 @@ public void onCreate(Bundle savedInstanceState) {
final EditText phoneNumber = (EditText)
this.findViewById(R.id.phone_number);

final EditText remoteAccessOnion = (EditText)
this.findViewById(R.id.remote_access_onion);

final EditText timerDelay = (EditText)
this.findViewById(R.id.timer_delay);
Expand All @@ -98,6 +107,15 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
}
});

remoteAccessCheck.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
if (isChecked) {
checkRemoteAccessOnion();
}
}
});

/**
* Loads preferences and sets view
*/
Expand Down Expand Up @@ -151,6 +169,13 @@ else if (sensitivity.equals(PreferenceManager.OFF))
phoneNumber.setText(preferences.getSmsNumber());
}

if (preferences.getRemoteAccessActive())
{
remoteAccessCheck.setChecked(true);
remoteAccessOnion.setText(preferences.getRemoteAccessOnion() + ":" + WebServer.LOCAL_PORT);

}

timerDelay.setText(preferences.getTimerDelay()+"");

askForPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, 1);
Expand Down Expand Up @@ -210,7 +235,7 @@ private void save ()

Spinner selectCameraSpinner = (Spinner) this.findViewById(R.id.camera_spinner);
CheckBox smsCheck = (CheckBox) this.findViewById(R.id.sms_check);

CheckBox remoteAccessCheck = (CheckBox) this.findViewById(R.id.remote_access_check);

preferences.activateAccelerometer(true);
preferences.setAccelerometerSensitivity(
Expand All @@ -236,6 +261,8 @@ private void save ()
preferences.activateSms(false);
}

preferences.activateRemoteAccess(remoteAccessCheck.isChecked());

preferences.setTimerDelay(Integer.parseInt(timerDelay.getText().toString()));

setResult(RESULT_OK);
Expand All @@ -259,4 +286,34 @@ public boolean onOptionsItemSelected (MenuItem item) {
return true;
}

private void checkRemoteAccessOnion ()
{
if (OrbotHelper.isOrbotInstalled(this))
{
OrbotHelper.requestStartTor(this);

if (TextUtils.isEmpty(preferences.getRemoteAccessOnion()))
OrbotHelper.requestHiddenServiceOnPort(this, WebServer.LOCAL_PORT);
}
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (resultCode == RESULT_OK && data != null)
{
String onionHost = data.getStringExtra("hs_host");

if (!TextUtils.isEmpty(onionHost)) {
preferences.setRemoteAccessOnion(onionHost);
final EditText remoteAccessOnion = (EditText)
this.findViewById(R.id.remote_access_onion);
remoteAccessOnion.setText(onionHost + ":" + WebServer.LOCAL_PORT);
}

}
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import android.os.PowerManager;
import android.support.v4.app.NotificationCompat;
import android.telephony.SmsManager;
import android.util.Log;

import java.io.IOException;
import java.util.Date;

import info.guardianproject.phoneypot.MonitorActivity;
Expand Down Expand Up @@ -90,6 +92,11 @@ public void handleMessage(Message msg) {
*/
PowerManager.WakeLock wakeLock;

/*
** Onion-available Web Server for optional remote access
*/
WebServer mOnionServer = null;

/**
* Called on service creation, sends a notification
*/
Expand All @@ -98,6 +105,9 @@ public void onCreate() {
manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
prefs = new PreferenceManager(this);

if (prefs.getRemoteAccessActive())
startServer();

startSensors();

showNotification();
Expand All @@ -117,6 +127,10 @@ public void onDestroy() {

wakeLock.release();
stopSensors();

if (mOnionServer != null)
mOnionServer.stop();

stopForeground(true);


Expand Down Expand Up @@ -235,5 +249,15 @@ private synchronized void alert(int alertType, String path) {

}

private void startServer ()
{
try {
mOnionServer = new WebServer();
}
catch (IOException ioe)
{
Log.e("OnioNServer","unable to start onion server",ioe);
}
}

}
Loading

0 comments on commit dc22847

Please sign in to comment.